]> andersk Git - moira.git/blob - clients/userreg/userreg.c
re-order includes, so kadm.h and kadm_err.h set things up so krb.h
[moira.git] / clients / userreg / userreg.c
1 /*
2  * $Source$
3  * $Author$
4  * $Locker$
5  * $Header$ 
6  *
7  *  (c) Copyright 1988 by the Massachusetts Institute of Technology.
8  *  For copying and distribution information, please see the file
9  *  <mit-copyright.h>.
10  */
11
12 #ifndef lint
13 static char    *rcsid_userreg_c = "$Header$";
14 #endif  lint
15
16 #include <mit-copyright.h>
17 #include <string.h>
18 #include <curses.h>
19 #include <signal.h>
20 #include <sys/time.h>
21 #include <setjmp.h>
22 #include <ctype.h>
23 #include <kadm.h>
24 #include <kadm_err.h>
25 #include <krb.h>
26 #include <des.h>
27 #include <errno.h>
28 #include "userreg.h"
29 #include "ureg_err.h"
30
31 /* 7.2 release compatibility */
32 #ifndef KADM_INSECURE_PW
33 #define KADM_INSECURE_PW        (-1783126240L)
34 #endif
35
36 #define EXIT -1
37
38
39 struct user     user, db_user;
40 struct alias    alias;
41 char            typed_mit_id[100];
42 char            realm[REALM_SZ];
43 jmp_buf         redo;
44 int             restart();
45
46 extern int      errno;
47 int             user_is_valid = 0;
48 int             user_has_login = 0;
49 int             already_registered = 0;
50 int             enrollment = 0;
51 extern char *disabled();
52
53 fix_display(sig)
54 {
55 #ifdef POSIX
56         struct sigaction act;
57
58         sigemptyset(&act.sa_mask);
59         act.sa_flags = 0;
60         act.sa_handler= (void (*)()) SIG_IGN;
61         sigaction(sig, &act, NULL);
62 #else
63         signal(sig, SIG_IGN);   /* let us clean up, please */
64 #endif
65         noraw();
66         echo();
67         endwin();
68         exit(1);
69 }
70
71 main(argc, argv)
72         int             argc;
73         char          **argv;
74 {
75         register int    ntimes;
76         register int    reencrypt;
77         char            line[100], *when, *msg;
78         int status;
79         char tmpfirst[100], tmplast[100], tmpmid[100];
80 #ifdef POSIX
81         struct sigaction act;
82 #endif
83
84         status = ureg_init();
85         if (status) {
86                 com_err(argv[0], status, "while trying to initialize");
87                 exit(1);
88         }
89
90         if (when = disabled(&msg)) {
91             printf("We're sorry, the registration service is unavailable right now\n");
92             if (msg)
93               printf("because %s\n", msg);
94             printf("You should be able to register after %s", when);
95             printf("\nPress ENTER or RETURN to continue ");
96             fflush(stdout);
97             getchar();
98             exit(0);
99         }
100
101         /* stash the realm for later use */
102         if ((status = krb_get_lrealm(realm, 1)) != KSUCCESS) {
103             printf("System error; please try another workstation.");
104             exit(1);
105         }
106
107         setup_display();
108
109 #ifdef POSIX
110         sigemptyset(&act.sa_mask);
111         act.sa_flags = 0;       
112         act.sa_handler= (void (*)()) fix_display;
113         sigaction(SIGINT, &act, NULL);
114         sigaction(SIGQUIT, &act, NULL);
115         sigaction(SIGHUP, &act, NULL);
116 #else
117         signal(SIGINT, fix_display);
118         signal(SIGQUIT, fix_display);
119         signal(SIGHUP, fix_display);
120 #endif
121
122         while (1) {
123                 setjmp(redo);
124                 reset();
125                 ntimes = 0;
126
127                 display_text(WELCOME, "");
128
129                 gfirst();
130                 gmi();
131                 glast();
132                 strcpy(tmpfirst, user.u_first);
133                 strcpy(tmplast, user.u_last);
134                 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
135                 redisp();
136                 
137                 gmitid();
138                 
139                 while (dolook()) {
140                         ntimes++;
141                         if (ntimes > 3) {
142                                 display_text_line(0);
143                                 display_text_line("Sorry, you still cannot be found in the database.");
144                                 display_text_line(" ");
145                                 display_text_line("Please call an accounts consultant at x3-1325 for help.");
146                                 wait_for_user();
147                                 break;
148                         }
149                         display_text_line(0);   /* clear the window */
150                         display_text_line("You could not be found in the database.");
151                         display_text_line("Do you want to change some input (for example, the spelling");
152                         display_text_line("of part of your name) and try again?");
153                         if (askyn("Do you want to try again ? ") == YES) {
154                                 reencrypt = 0;
155                                 display_text_line(0);
156                                 sprintf(line,
157                                         "You entered your first name as \"%s\"", user.u_first);
158                                 display_text_line(line);
159                                 if (askyn("Do you want to change it? ") == YES) {
160                                         gfirst();
161                                         strcpy(tmpfirst, user.u_first);
162                                         strcpy(tmplast, user.u_last);
163                                         FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
164                                         redisp();
165                                         reencrypt = 1;
166                                 }
167                                 display_text_line(0);
168                                 sprintf(line,
169                                         "You entered your middle initial as \"%s\"", user.u_mid_init);
170                                 display_text_line(line);
171                                 if (askyn("Do you want to change it? ") == YES)
172                                         gmi();
173                                 display_text_line(0);
174                                 sprintf(line,
175                                         "You entered your family name as \"%s\"", user.u_last);
176                                 display_text_line(line);
177                                 if (askyn("Do you want to change it? ") == YES) {
178                                         glast();
179                                         strcpy(tmpfirst, user.u_first);
180                                         strcpy(tmplast, user.u_last);
181                                         FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
182                                         redisp();
183                                         reencrypt = 1;
184                                 }
185                                 display_text_line(0);
186                                 sprintf(line,
187                                         "You entered your MIT id number as \"%s\"", typed_mit_id);
188                                 display_text_line(line);
189                                 if (askyn("Do you want to change it? ") == YES) {
190                                         gmitid();
191                                         reencrypt = 0;
192                                 }
193                                 if (reencrypt) {
194                                     EncryptID(user.u_mit_id, typed_mit_id,
195                                               user.u_first, user.u_last);
196                                 }
197                         } else
198                                 break;
199                 }
200                 if (!user_is_valid || already_registered) {
201                         qexit();
202                         continue;
203                 }
204                 redisp();
205                 if (!user_has_login) {
206                         if (negotiate_login() == -1) {
207                                 qexit();
208                                 continue;
209                         }
210                 }
211                 if (negotiate_passwd() == -1) {
212                         qexit();
213                         continue;
214                 }
215                 sleep(1);
216                 if (!enrollment)
217                   display_text(FINISHED, user.u_login);
218                 else {
219                     display_text(FINISHEDE, user.u_login);
220                     if (askyn("Do you wish to set your mailbox now? (Yes or No) ")) {
221                         clear();
222                         refresh();
223                         noraw();
224                         echo();
225                         kinit(user.u_login, user.u_password);
226                         system(NAMESPACE_PROG);
227                         dest_tkt();
228                         qexit();
229                         exit(0);
230                     }
231                 }
232                 wait_for_user();
233                 qexit();
234                 break;
235         }
236         restore_display();
237         exit(0);
238 }
239
240 reset()
241 {
242         reset_display();
243         memset(&user, 0, sizeof(user));
244         user_is_valid = 0;
245         already_registered = 0;
246         enrollment = 0;
247         redisp();
248 }
249
250 dolook()
251 {
252         /* do the database lookup */
253
254         char            line[100];
255         register int    result;
256         if (user_is_valid) {
257                 /* !! */
258                 return (0);
259         }
260         display_text_line(0);
261         display_text_line("Looking you up in the database.... This may take from 30 seconds to 10");
262         display_text_line("minutes, depending on how busy the system is at the moment.");
263
264         timer_off();
265         result = verify_user(user.u_first, user.u_last,
266                              typed_mit_id, user.u_mit_id, db_user.u_login);
267         wfeep();
268         display_text_line(0);
269         timer_on();
270         switch(result) {
271         case 0:
272         case UREG_ENROLLED:
273                 display_text_line("You have been located in the user registration database.");
274                 user_is_valid = 1;
275                 user_has_login = 0;
276                 sleep(1);
277                 return 0;
278         case UREG_HALF_ENROLLED:
279                 enrollment = 1;
280                 /* fall through to: */
281         case UREG_NO_PASSWD_YET:
282                 user_is_valid = 1;
283                 user_has_login = 1;
284                 display_text_line ("You have chosen a login name, but you have not yet chosen a password.");
285                 sprintf(line, "Remember: the username you chose was '%s'",
286                         db_user.u_login);
287                 strcpy(user.u_login, db_user.u_login);
288                 display_text_line(line);
289                 redisp();
290                 sleep(5);
291                 return (0);
292                 
293         case UREG_ALREADY_REGISTERED:
294                 already_registered = 1;
295                 /*
296                  * we have to reset this so we dont ask for a
297                  * new username 
298                  */     
299                 user_is_valid = 0;
300                 display_text_line("You are already registered.  An account for you probably already exists");
301                 display_text_line("(if not, it will appear within 12 hours).");
302                 display_text_line("");
303                 display_text_line("Refer to the document 'Getting Started on Athena' for help logging in.");
304                 strcpy(user.u_login, db_user.u_login);
305                 sprintf(line, "Remember, the username you chose was '%s'",
306                         db_user.u_login);
307                 display_text_line(line);
308                 redisp();
309                 wait_for_user();
310                 return (0);
311         case UREG_DELETED:
312                 display_text(DELETED_ACCT, db_user.u_login);
313                 wait_for_user();
314                 restore_display();
315                 exit(0);
316         case UREG_NOT_ALLOWED:
317                 display_text(OFFER_ENROLL, db_user.u_login);
318                 redisp();
319                 if (!askyn("Continue choosing a name and password (Y/N)? ")) {
320                     already_registered = 1;
321                     return(0);
322                 }
323                 user_has_login = 0;
324                 user_is_valid = 1;
325                 enrollment = 1;
326                 return(0);
327         case UREG_ENROLL_NOT_ALLOWED:
328                 display_text(NOT_ALLOWED, db_user.u_login);
329                 wait_for_user();
330                 restore_display();
331                 exit(0);
332         case UREG_KRB_TAKEN:
333                 display_text(IMPROPER_LOGIN, db_user.u_login);
334                 wait_for_user();
335                 return(0);
336         case UREG_USER_NOT_FOUND:
337                 return (1);
338
339         case ECONNREFUSED:
340         case ETIMEDOUT:
341         case UREG_MISC_ERROR:
342                 display_text(NETWORK_DOWN, db_user.u_login);
343                 display_text_line(" ");
344                 sprintf(line, "The specific error was: %s",
345                         error_message(result));
346                 display_text_line(line);
347                 wait_for_user();
348                 return (0);
349                 
350         default:
351                 display_text_line("An unexpected error occurred while trying to access the database");
352                 display_text_line(error_message(result));
353                 redisp();
354                 wait_for_user();
355                 return(1);
356         }
357 }
358
359
360 /* Get a login name from the user and register it.  There are several steps
361  * to this: display help message, get name, check name, display confirmation
362  * message, get confirmation, register name.
363  */
364
365 negotiate_login()
366 {
367     int result, i;
368     char line[100], old_login[LOGIN_SIZE+2];
369     char *error, *cp;
370         
371     /* build suggested username */
372     cp = user.u_login;
373     if (isalpha(user.u_first[0]))
374       *cp++ = user.u_first[0];
375     if (isalpha(user.u_mid_init[0]))
376       *cp++ = user.u_mid_init[0];
377     for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++)
378       if (isalpha(user.u_last[i]))
379         *cp++ = user.u_last[i];
380     for (i=0; user.u_login[i]; i++)
381       if (isupper(user.u_login[i]))
382         user.u_login[i]=tolower(user.u_login[i]);
383     strcpy(old_login, user.u_login);
384         
385     /* print message */
386     display_text(USERNAME_BLURB, user.u_login);
387
388  again:
389     /* get name from user */
390     glogin();
391
392     display_text_line(0);
393     display_text_line("Testing that username...");
394     error = "";
395     if (strlen(user.u_login) < 3)
396       error = "Your username must be at least 3 characters long.";
397     else if (strlen(user.u_login) > 8)
398       error = "Your username cannot be longer than 8 characters.";
399     else if (!isalpha(user.u_login[0]) || !islower(user.u_login[0]))
400       error = "Your username must start with a lowercase letter.";
401     else for (i = 1; i < strlen(user.u_login); i++)
402       if (!islower(user.u_login[i]) &&
403           !isdigit(user.u_login[i]) &&
404           user.u_login[i] != '_')
405         error = "Your username must contain only lower case letters, numbers, and underscore";
406     timer_off();
407     result = krb_get_pw_in_tkt(user.u_login, "", realm, 
408                                "krbtgt", realm, 1, "");
409     timer_on();
410     if (*error == 0 && result != KDC_PR_UNKNOWN)
411       error = "That username is already taken.";
412
413     /* if it's bad, get another name from user */
414     if (*error) {
415         strcpy(user.u_login, old_login);
416         redisp();
417         display_text_line(error);
418         display_text_line("Please choose another username.");
419         goto again;
420     }
421
422     /* name is OK, make sure */
423     display_text(USERNAME_BLURB2, user.u_login);
424     if (!askyn("Do you want to register this username? (Yes or No) "))
425       goto again;
426
427     display_text_line(0);
428     display_text_line("Trying to assign that username...  This may take a few minutes.");
429
430     /* Do It! */
431     timer_off();
432     if (!enrollment)
433       result = grab_login(user.u_first, user.u_last,
434                           typed_mit_id, user.u_mit_id,
435                           user.u_login);
436     else
437       result = enroll_login(user.u_first, user.u_last,
438                             typed_mit_id, user.u_mit_id,
439                             user.u_login);
440     wfeep();
441     timer_on();
442     if (result != 0) {
443         char buf[BUFSIZ];
444
445         if (result == UREG_LOGIN_USED) {
446             /* name was in moira but not kerberos */
447             error = "Sorry, that username really was in use after all.";
448             strcpy(user.u_login, old_login);
449             redisp();
450             display_text_line(error);
451             display_text_line("Please choose another username.");
452             goto again;
453         }
454
455         display_text(NETWORK_DOWN, "");
456         display_text_line(" ");
457         sprintf(buf, "The specific error was: %s", error_message(result));
458         display_text_line(buf);
459         wait_for_user();
460         return (qexit());
461     }
462
463     /* at this point we have successfully negotiated a username */
464     sprintf(line, "O.K. your username will be \"%s\".", user.u_login);
465     display_text_line(0);
466     display_text_line(line);
467     redisp();
468     sleep(3);
469     return 0;
470 }
471
472
473 negotiate_passwd()
474 {
475     char *passwd, *error;
476     char old_passwd[256], fullname[256], tktstring[256], inst[INST_SZ];
477     char login[ANAME_SZ], lpassword[PASSWORD_SIZE];
478     int result;
479     des_cblock key;
480     FILE *in;
481
482  again:
483     display_text(PASSWORD_BLURB, "");
484     gpass();
485
486     /* validate password */
487     error = NULL;
488     passwd = user.u_password;
489     sprintf(fullname, "%s%s", user.u_first, user.u_last);
490     if (strlen(passwd) < 6)
491       error = "Please choose a longer password.";
492     if (!strpasscmp(passwd, user.u_first) ||
493         !strpasscmp(passwd, user.u_last) ||
494         !strpasscmp(passwd, user.u_login) ||
495         !strpasscmp(passwd, fullname) ||
496         !strpasscmp(passwd, typed_mit_id))
497       error = "Please do not use your name or ID number for your password.";
498     if (!error) {
499         in = fopen(LOGIN_INFO, "r");
500         if (in != NULL) {
501             fgets(login, sizeof(login), in);
502             /* trim trailing newline */
503             if (strlen(login))
504               login[strlen(login) - 1] = 0;
505             fgets(lpassword, sizeof(lpassword), in);
506             /* trim trailing newline */
507             if (strlen(lpassword))
508               lpassword[strlen(lpassword) - 1] = 0;
509             fclose(in);
510         } else {
511             strcpy(login, "moira");
512             strcpy(lpassword, "moira");
513         }
514
515         sprintf(tktstring, "/tmp/tkt_cpw_%d", getpid());
516         krb_set_tkt_string(tktstring);  
517         des_string_to_key(passwd, key);
518         inst[0] = 0;
519
520         result = krb_get_pw_in_tkt(login, inst, realm, PWSERV_NAME,
521                                    KADM_SINST, 1, lpassword);
522         if (result == KSUCCESS)
523           result = kadm_init_link(PWSERV_NAME, KRB_MASTER, realm);
524         if (result == KSUCCESS)
525           result = kadm_check_pw(key, passwd, &error);
526         dest_tkt();
527         if (result == KADM_INSECURE_PW) {
528             error = "You have chosen a passsword that is in the dictionary of commonly\nselected user passwords.  You will have to choose a better password.";
529         } else if (result != KSUCCESS) {
530             display_text(NETWORK_DOWN);
531             display_text_line(" ");
532             sprintf(fullname, "%s while verifying password",
533                     error_message(result));
534             display_text_line(fullname);
535             wait_for_user();
536             return(-1);
537         }
538     }
539
540     if (error) {
541         display_text_line(0);
542         display_text_line(error);
543         wait_for_user();
544         goto again;
545     }
546
547     display_text(PASSWORD_BLURB2, "");
548     strcpy(old_passwd, user.u_password);
549     gpass();
550     if (strcmp(old_passwd, user.u_password)) {
551         display_text_line(0);
552         display_text_line("What you just typed did not match the password you gave the first time.");
553         sleep(8);
554         goto again;
555     }
556
557     display_text_line("Storing password in the database...  This may take a few minutes.");
558     if (do_replace()) {
559         return (-1);
560     }
561     display_text_line("done.");
562     return(0);
563 }
564
565 gfirst()
566 {
567         /* input the first name */
568         char            buf[FIRST_NAME_SIZE+2];
569 #ifdef POSIX
570         struct sigaction act;
571
572         sigemptyset(&act.sa_mask);
573         act.sa_flags = 0;
574         act.sa_handler= (void (*)()) fix_display;
575         sigaction(SIGALRM, &act, NULL);
576 #else
577         signal(SIGALRM, fix_display);
578 #endif
579         input("Enter first Name:", buf, FIRST_NAME_SIZE+1,
580               FIRSTNAME_TIMEOUT, TRUE);
581         strncpy(user.u_first, buf, FIRST_NAME_SIZE);
582         user.u_first[FIRST_NAME_SIZE - 1] = '\0';
583         canon_name(user.u_first);
584         redisp();
585 }
586
587 glast()
588 {
589         /* input the last name */
590         char            buf[LAST_NAME_SIZE+2];
591 #ifdef POSIX
592         struct sigaction act;
593
594         sigemptyset(&act.sa_mask);
595         act.sa_flags = 0;
596         act.sa_handler= (void (*)()) fix_display;
597         sigaction(SIGALRM, &act, NULL);
598 #else
599         signal(SIGALRM, restart);
600 #endif
601         input("Enter family Name:", buf, LAST_NAME_SIZE+1,
602               LASTNAME_TIMEOUT, FALSE);
603         strncpy(user.u_last, buf, LAST_NAME_SIZE);
604         user.u_last[LAST_NAME_SIZE - 1] = '\0';
605         canon_name(user.u_last);
606         redisp();
607 }
608
609 gpass()
610 {
611         /* input password */
612         char            new_password[PASSWORD_SIZE + 1];
613 #ifdef POSIX
614         struct sigaction act;
615
616         sigemptyset(&act.sa_mask);
617         act.sa_flags = 0;
618         act.sa_handler= (void (*)()) fix_display;
619         sigaction(SIGALRM, &act, NULL);
620 #else
621         signal(SIGALRM, restart);
622 #endif
623         input_no_echo("Enter password:", new_password,
624                       PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT);
625         strcpy(user.u_password, new_password);
626         redisp();
627 }
628
629
630 /* get login name */
631
632 glogin()
633 {
634         char buf[LOGIN_SIZE+2];
635 #ifdef POSIX
636         struct sigaction act;
637
638         sigemptyset(&act.sa_mask);
639         act.sa_flags = 0;
640         act.sa_handler= (void (*)()) fix_display;
641         sigaction(SIGALRM, &act, NULL);
642 #else
643         signal(SIGALRM, restart);
644 #endif
645         user.u_login[0] = '\0';
646         input("Enter username:", buf, LOGIN_SIZE, USERNAME_TIMEOUT, FALSE);
647         strcpy(user.u_login, buf);
648         redisp();
649 }
650
651 gmitid()
652 {
653         /* get mid id */
654         register int    i;
655         char            buf[15];
656         register char  *nbuf = buf;
657 #ifdef POSIX
658         struct sigaction act;
659 #endif
660
661
662 input_mit_id:
663 #ifdef POSIX
664         sigemptyset(&act.sa_mask);
665         act.sa_flags = 0;
666         act.sa_handler= (void (*)()) fix_display;
667         sigaction(SIGALRM, &act, NULL);
668 #else
669         signal(SIGALRM, restart);
670 #endif
671         input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE);
672         i = 0;
673         nbuf = &buf[0];
674         while (*nbuf != '\0') {
675                 if (*nbuf == ' ' || *nbuf == '-') {
676                         nbuf++;
677                         continue;
678                 }
679                 if (!isdigit(*nbuf)) {
680                         i = 0;
681                         break;
682                 }
683                 typed_mit_id[i] = *nbuf;
684                 nbuf++;
685                 i++;
686         }
687         if (i != 9) {
688                 display_text_line(
689                                   "Your MIT id must be a nine-digit number.  Please try again.");
690                 goto input_mit_id;
691         }
692         typed_mit_id[9] = '\0';
693         redisp();
694         EncryptID(user.u_mit_id, typed_mit_id, user.u_first, user.u_last);
695 }
696
697 gmi()
698 {
699         /* get middle initial */
700         char            buf[MID_INIT_SIZE+2];
701 #ifdef POSIX
702         struct sigaction act;
703
704         sigemptyset(&act.sa_mask);
705         act.sa_flags = 0;
706         act.sa_handler= (void (*)()) fix_display;
707         sigaction(SIGALRM, &act, NULL);
708 #else
709         signal(SIGALRM, restart);
710 #endif
711         input("Enter Middle Initial:", buf, MID_INIT_SIZE+1, MI_TIMEOUT, TRUE);
712         strncpy(user.u_mid_init, buf, MID_INIT_SIZE);
713         user.u_mid_init[MID_INIT_SIZE - 1] = '\0';
714         canon_name(user.u_mid_init);
715         redisp();
716 }
717
718 qexit()
719 {
720         /* exit quickly, not saving anything in the database */
721         memset(&user, 0, sizeof(user));
722         typed_mit_id[0] = '\0';
723         user_is_valid = 0;
724         already_registered = 0;
725         enrollment = 0;
726         sleep(2);               /* give the user a chance to see the screen */
727         display_text_line(0);
728         return (EXIT);
729 }
730
731
732 do_replace()
733 {
734         int status;
735         char buf[100];
736         
737         /*
738          * replaces a user in the database. If there is an error, it informs
739          * the user and calls qexit(); It returns only if is is successful 
740          */
741         timer_off();
742         if (!enrollment)
743           status = set_password(user.u_first, user.u_last, typed_mit_id,
744                                 user.u_mit_id, user.u_password);
745         else
746           status = get_krb(user.u_first, user.u_last, typed_mit_id,
747                                 user.u_mit_id, user.u_password);
748         wfeep();
749         timer_on();
750         if (status) {
751                 display_text (NETWORK_DOWN);
752                 display_text_line(" ");
753                 sprintf(buf, "The specific error was: %s",
754                         error_message(status));
755                 display_text_line(buf);
756                 wait_for_user();
757                 return (-1);
758         } else return 0;
759 }
760
761
762 kinit(user, passwd)
763 char *user, *passwd;
764 {
765     int status;
766     char inst[INST_SZ];
767
768     inst[0] = 0;
769     status = krb_get_pw_in_tkt(user, inst, realm, "krbtgt",
770                                realm, DEFAULT_TKT_LIFE, 0);
771     return(status);
772 }
773
774
775 #ifndef _toupper
776 #define _toupper(c) ((c) & ~0x20)
777 #endif
778
779 lenient_strcmp(string1, string2)
780         register char  *string1, *string2;
781 {
782         /*
783          * a primitive case insensitive string comparison. It returns only 0
784          * if the strings are equal (ignoring case) and 1 if they are
785          * different. Also ignores spaces. 
786          */
787
788         while (1) {
789                 if (*string1 == '\0' && *string2 == '\0') {
790                         return (0);
791                 }
792                 if (*string1 == ' ' || *string1 == '.' || *string1 == '-' ||
793                     *string1 == '\'' || *string1 == '_') {
794                         string1++;
795                         continue;
796                 }
797                 if (*string2 == ' ' || *string2 == '.' || *string2 == '-' ||
798                     *string2 == '\'' || *string2 == '_') {
799                         string2++;
800                         continue;
801                 }
802                 if (_toupper(*string1) != _toupper(*string2)) {
803                         return (1);
804                 }
805                 string1++;
806                 string2++;
807         }
808 }
809
810
811 /* See if the strings match in forward & reverse direction, ignoring
812  * case and spaces/punctuation.
813  */
814
815 strpasscmp(s1, s2)
816 char *s1, *s2;
817 {
818     char buf[256], *from, *to;
819
820     if (!lenient_strcmp(s1, s2))
821       return(0);
822     /* if s2 is empty, say OK */
823     if (!*s2)
824       return(1);
825
826     from = &s2[strlen(s2)];
827     from--;
828     for (to = &buf[0]; from >= s2; from--)
829       *to++ = *from;
830
831     return(lenient_strcmp(s1, buf));
832 }
833
834
835 /*
836  * Input timeout handler.  Loop back to asking for the first name. 
837  */
838
839 restart()
840 /* Go to asking for first name. */
841 {
842         qexit();
843         longjmp(redo, 1);
844 }
845
846 canon_name(cp)
847         register char *cp;
848 {
849         register char *p2 = cp;
850       
851         /* Trim whitespace off both ends. */
852         for (; *p2 && isspace(*p2); p2++) ;
853         if (*p2) {
854                 strcpy(cp, p2);
855                 p2 = cp + strlen(cp);
856                 --p2;
857                 while (p2 >= cp && isspace(*p2)) *(--p2) = '\0';
858         }
859         /* Make it capitalized */
860         FixCase(cp);
861 }
This page took 0.148303 seconds and 5 git commands to generate.