7 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
12 #include <mit-copyright.h>
31 void fix_display(int sig);
34 int negotiate_login(void);
35 int negotiate_passwd(void);
44 int kinit(char *user, char *passwd);
45 int lenient_strcmp(char *string1, char *string2);
46 int strpasscmp(char *s1, char *s2);
48 void canon_name(char *cp);
52 struct user user, db_user;
57 int user_is_valid = 0;
58 int user_has_login = 0;
59 int already_registered = 0;
61 char typed_mit_id[100];
63 void fix_display(int sig)
67 sigemptyset(&act.sa_mask);
69 act.sa_handler = SIG_IGN;
70 sigaction(sig, &act, NULL);
77 int main(int argc, char **argv)
81 char line[100], *when, *msg;
83 char tmpfirst[100], tmplast[100], tmpmid[100];
89 com_err(argv[0], status, "while trying to initialize");
93 if ((when = disabled(&msg)))
95 printf("We're sorry, the registration service is unavailable right now\n");
97 printf("because %s\n", msg);
98 printf("You should be able to register after %s", when);
99 printf("\nPress ENTER or RETURN to continue ");
105 /* stash the realm for later use */
106 if ((status = krb_get_lrealm(realm, 1)) != KSUCCESS)
108 printf("System error; please try another workstation.");
114 sigemptyset(&act.sa_mask);
116 act.sa_handler = fix_display;
117 sigaction(SIGINT, &act, NULL);
118 sigaction(SIGQUIT, &act, NULL);
119 sigaction(SIGHUP, &act, NULL);
127 display_text(WELCOME, "");
132 strcpy(tmpfirst, user.u_first);
133 strcpy(tmplast, user.u_last);
134 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
144 display_text_line(0);
145 display_text_line("Sorry, you still cannot be found in the database.");
146 display_text_line(" ");
147 display_text_line("Please call an accounts consultant at x3-1325 for help.");
151 display_text_line(0); /* clear the window */
152 display_text_line("You could not be found in the database.");
153 display_text_line("Do you want to change some input "
154 "(for example, the spelling");
155 display_text_line("of part of your name) and try again?");
156 if (askyn("Do you want to try again ? ") == YES)
159 display_text_line(0);
160 sprintf(line, "You entered your first name as \"%s\"",
162 display_text_line(line);
163 if (askyn("Do you want to change it? ") == YES)
166 strcpy(tmpfirst, user.u_first);
167 strcpy(tmplast, user.u_last);
168 FixName(tmplast, tmpfirst, user.u_last, user.u_first,
173 display_text_line(0);
174 sprintf(line, "You entered your middle initial as \"%s\"",
176 display_text_line(line);
177 if (askyn("Do you want to change it? ") == YES)
179 display_text_line(0);
180 sprintf(line, "You entered your family name as \"%s\"",
182 display_text_line(line);
183 if (askyn("Do you want to change it? ") == YES)
186 strcpy(tmpfirst, user.u_first);
187 strcpy(tmplast, user.u_last);
188 FixName(tmplast, tmpfirst, user.u_last, user.u_first,
193 display_text_line(0);
194 sprintf(line, "You entered your MIT id number as \"%s\"",
196 display_text_line(line);
197 if (askyn("Do you want to change it? ") == YES)
204 EncryptID(user.u_mit_id, typed_mit_id,
205 user.u_first, user.u_last);
211 if (!user_is_valid || already_registered)
219 if (negotiate_login() == -1)
225 if (negotiate_passwd() == -1)
232 display_text(FINISHED, user.u_login);
235 display_text(FINISHEDE, user.u_login);
236 if (askyn("Do you wish to set your mailbox now? (Yes or No) "))
242 kinit(user.u_login, user.u_password);
243 system(NAMESPACE_PROG);
260 memset(&user, 0, sizeof(user));
262 already_registered = 0;
269 /* do the database lookup */
279 display_text_line(0);
280 display_text_line("Looking you up in the database.... "
281 "This may take from a few seconds to a few");
282 display_text_line("minutes, depending on how busy the system is "
286 result = verify_user(user.u_first, user.u_last, typed_mit_id,
287 user.u_mit_id, db_user.u_login);
289 display_text_line(0);
295 display_text_line("You have been located in the user registration database.");
300 case UREG_HALF_ENROLLED:
302 /* fall through to: */
303 case UREG_NO_PASSWD_YET:
306 display_text_line ("You have chosen a login name, but you have not yet chosen a password.");
307 sprintf(line, "Remember: the username you chose was '%s'",
309 strcpy(user.u_login, db_user.u_login);
310 display_text_line(line);
315 case UREG_ALREADY_REGISTERED:
316 already_registered = 1;
318 * we have to reset this so we dont ask for a
322 display_text_line("You are already registered. "
323 "An account for you probably already exists");
324 display_text_line("(if not, it will appear within 24 hours).");
325 display_text_line("");
326 display_text_line("Refer to the document 'Working on Athena' "
327 "for help logging in.");
328 strcpy(user.u_login, db_user.u_login);
329 sprintf(line, "Remember, the username you chose was '%s'",
331 display_text_line(line);
336 display_text(DELETED_ACCT, db_user.u_login);
340 case UREG_NOT_ALLOWED:
341 display_text(OFFER_ENROLL, db_user.u_login);
343 if (!askyn("Continue choosing a name and password (Y/N)? "))
345 already_registered = 1;
352 case UREG_ENROLL_NOT_ALLOWED:
353 display_text(NOT_ALLOWED, db_user.u_login);
358 display_text(IMPROPER_LOGIN, db_user.u_login);
361 case UREG_USER_NOT_FOUND:
366 case UREG_MISC_ERROR:
367 display_text(NETWORK_DOWN, db_user.u_login);
368 display_text_line(" ");
369 sprintf(line, "The specific error was: %s", error_message(result));
370 display_text_line(line);
375 display_text_line("An unexpected error occurred while trying to "
376 "access the database");
377 display_text_line(error_message(result));
385 /* Get a login name from the user and register it. There are several steps
386 * to this: display help message, get name, check name, display confirmation
387 * message, get confirmation, register name.
390 int negotiate_login(void)
393 char line[100], old_login[LOGIN_SIZE + 2];
396 /* build suggested username */
398 if (isalpha(user.u_first[0]))
399 *cp++ = user.u_first[0];
400 if (isalpha(user.u_mid_init[0]))
401 *cp++ = user.u_mid_init[0];
402 for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++)
404 if (isalpha(user.u_last[i]))
405 *cp++ = user.u_last[i];
407 for (i = 0; user.u_login[i]; i++)
409 if (isupper(user.u_login[i]))
410 user.u_login[i] = tolower(user.u_login[i]);
412 strcpy(old_login, user.u_login);
415 display_text(USERNAME_BLURB, user.u_login);
418 /* get name from user */
421 display_text_line(0);
422 display_text_line("Testing that username...");
424 if (strlen(user.u_login) < 3)
425 error = "Your username must be at least 3 characters long.";
426 else if (strlen(user.u_login) > 8)
427 error = "Your username cannot be longer than 8 characters.";
428 else if (!isalpha(user.u_login[0]) || !islower(user.u_login[0]))
429 error = "Your username must start with a lowercase letter.";
431 for (i = 1; i < strlen(user.u_login); i++)
433 if (!islower(user.u_login[i]) &&
434 !isdigit(user.u_login[i]) &&
435 user.u_login[i] != '_')
436 error = "Your username must contain only lower case letters, "
437 "numbers, and underscore";
440 result = krb_get_pw_in_tkt(user.u_login, "", realm, "krbtgt", realm, 1, "");
442 if (*error == 0 && result != KDC_PR_UNKNOWN)
443 error = "That username is already taken.";
445 /* if it's bad, get another name from user */
448 strcpy(user.u_login, old_login);
450 display_text_line(error);
451 display_text_line("Please choose another username.");
455 /* name is OK, make sure */
456 display_text(USERNAME_BLURB2, user.u_login);
457 if (!askyn("Do you want to register this username? (Yes or No) "))
460 display_text_line(0);
461 display_text_line("Trying to assign that username... "
462 "This may take a few minutes.");
468 result = grab_login(user.u_first, user.u_last, typed_mit_id,
469 user.u_mit_id, user.u_login);
473 result = enroll_login(user.u_first, user.u_last, typed_mit_id,
474 user.u_mit_id, user.u_login);
482 if (result == UREG_LOGIN_USED)
484 /* name was in moira but not kerberos */
485 error = "Sorry, that username really was in use after all.";
486 strcpy(user.u_login, old_login);
488 display_text_line(error);
489 display_text_line("Please choose another username.");
493 display_text(NETWORK_DOWN, "");
494 display_text_line(" ");
495 sprintf(buf, "The specific error was: %s", error_message(result));
496 display_text_line(buf);
501 /* at this point we have successfully negotiated a username */
502 sprintf(line, "O.K. your username will be \"%s\".", user.u_login);
503 display_text_line(0);
504 display_text_line(line);
511 int negotiate_passwd(void)
513 char *passwd, *error;
514 char old_passwd[256], fullname[256], tktstring[256], inst[INST_SZ];
515 char login[ANAME_SZ], lpassword[PASSWORD_SIZE];
521 display_text(PASSWORD_BLURB, "");
524 /* validate password */
526 passwd = user.u_password;
527 sprintf(fullname, "%s%s", user.u_first, user.u_last);
528 if (strlen(passwd) < 6)
529 error = "Please choose a longer password.";
530 if (!strpasscmp(passwd, user.u_first) ||
531 !strpasscmp(passwd, user.u_last) ||
532 !strpasscmp(passwd, user.u_login) ||
533 !strpasscmp(passwd, fullname) ||
534 !strpasscmp(passwd, typed_mit_id))
535 error = "Please do not use your name or ID number for your password.";
538 in = fopen(LOGIN_INFO, "r");
541 fgets(login, sizeof(login), in);
542 /* trim trailing newline */
544 login[strlen(login) - 1] = '\0';
545 fgets(lpassword, sizeof(lpassword), in);
546 /* trim trailing newline */
547 if (strlen(lpassword))
548 lpassword[strlen(lpassword) - 1] = '\0';
553 strcpy(login, "moira");
554 strcpy(lpassword, "moira");
557 sprintf(tktstring, "/tmp/tkt_cpw_%ld", (long)getpid());
558 krb_set_tkt_string(tktstring);
559 des_string_to_key(passwd, key);
562 result = krb_get_pw_in_tkt(login, inst, realm, PWSERV_NAME,
563 KADM_SINST, 1, lpassword);
564 if (result == KSUCCESS)
565 result = kadm_init_link(PWSERV_NAME, KRB_MASTER, realm);
566 if (result == KSUCCESS)
567 result = kadm_check_pw(key, passwd, &error);
569 if (result == KADM_INSECURE_PW)
571 error = "You have chosen a passsword that is in the dictionary "
572 "of commonly\nselected user passwords. You will have to choose "
573 "a better password.";
575 else if (result != KSUCCESS)
577 display_text(NETWORK_DOWN, "");
578 display_text_line(" ");
579 sprintf(fullname, "%s while verifying password",
580 error_message(result));
581 display_text_line(fullname);
589 display_text_line(0);
590 display_text_line(error);
595 display_text(PASSWORD_BLURB2, "");
596 strcpy(old_passwd, user.u_password);
598 if (strcmp(old_passwd, user.u_password))
600 display_text_line(0);
601 display_text_line("What you just typed did not match the password "
602 "you gave the first time.");
607 display_text_line("Storing password in the database... This may take "
611 display_text_line("done.");
617 /* input the first name */
618 char buf[FIRST_NAME_SIZE + 2];
619 struct sigaction act;
621 sigemptyset(&act.sa_mask);
623 act.sa_handler = fix_display;
624 sigaction(SIGALRM, &act, NULL);
625 input("Enter first Name:", buf, FIRST_NAME_SIZE + 1,
626 FIRSTNAME_TIMEOUT, TRUE);
627 strncpy(user.u_first, buf, FIRST_NAME_SIZE);
628 user.u_first[FIRST_NAME_SIZE - 1] = '\0';
629 canon_name(user.u_first);
635 /* input the last name */
636 char buf[LAST_NAME_SIZE + 2];
637 struct sigaction act;
639 sigemptyset(&act.sa_mask);
641 act.sa_handler = fix_display;
642 sigaction(SIGALRM, &act, NULL);
643 input("Enter family Name:", buf, LAST_NAME_SIZE + 1,
644 LASTNAME_TIMEOUT, FALSE);
645 strncpy(user.u_last, buf, LAST_NAME_SIZE);
646 user.u_last[LAST_NAME_SIZE - 1] = '\0';
647 canon_name(user.u_last);
654 char new_password[PASSWORD_SIZE + 1];
655 struct sigaction act;
657 sigemptyset(&act.sa_mask);
659 act.sa_handler = fix_display;
660 sigaction(SIGALRM, &act, NULL);
661 input_no_echo("Enter password:", new_password,
662 PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT);
663 strcpy(user.u_password, new_password);
672 char buf[LOGIN_SIZE + 2];
673 struct sigaction act;
675 sigemptyset(&act.sa_mask);
677 act.sa_handler = fix_display;
678 sigaction(SIGALRM, &act, NULL);
679 user.u_login[0] = '\0';
680 input("Enter username:", buf, LOGIN_SIZE, USERNAME_TIMEOUT, FALSE);
681 strcpy(user.u_login, buf);
691 struct sigaction act;
694 sigemptyset(&act.sa_mask);
696 act.sa_handler = fix_display;
697 sigaction(SIGALRM, &act, NULL);
698 input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE);
703 if (*nbuf == ' ' || *nbuf == '-')
713 typed_mit_id[i] = *nbuf;
719 display_text_line("Your MIT id must be a nine-digit number. "
720 "Please try again.");
723 typed_mit_id[9] = '\0';
725 EncryptID(user.u_mit_id, typed_mit_id, user.u_first, user.u_last);
730 /* get middle initial */
731 char buf[MID_INIT_SIZE + 2];
732 struct sigaction act;
734 sigemptyset(&act.sa_mask);
736 act.sa_handler = fix_display;
737 sigaction(SIGALRM, &act, NULL);
738 input("Enter Middle Initial:", buf, MID_INIT_SIZE + 1, MI_TIMEOUT, TRUE);
739 strncpy(user.u_mid_init, buf, MID_INIT_SIZE);
740 user.u_mid_init[MID_INIT_SIZE - 1] = '\0';
741 canon_name(user.u_mid_init);
747 /* exit quickly, not saving anything in the database */
748 memset(&user, 0, sizeof(user));
749 typed_mit_id[0] = '\0';
751 already_registered = 0;
753 sleep(2); /* give the user a chance to see the screen */
754 display_text_line(0);
765 * replaces a user in the database. If there is an error, it informs
766 * the user and calls qexit(); It returns only if is is successful
771 status = set_password(user.u_first, user.u_last, typed_mit_id,
772 user.u_mit_id, user.u_password);
776 status = get_krb(user.u_first, user.u_last, typed_mit_id,
777 user.u_mit_id, user.u_password);
783 display_text(NETWORK_DOWN, "");
784 display_text_line(" ");
785 sprintf(buf, "The specific error was: %s", error_message(status));
786 display_text_line(buf);
795 int kinit(char *user, char *passwd)
801 status = krb_get_pw_in_tkt(user, inst, realm, "krbtgt",
802 realm, DEFAULT_TKT_LIFE, 0);
807 int lenient_strcmp(char *string1, char *string2)
810 * a primitive case insensitive string comparison. It returns only 0
811 * if the strings are equal (ignoring case) and 1 if they are
812 * different. Also ignores spaces.
817 if (*string1 == '\0' && *string2 == '\0')
819 if (*string1 == ' ' || *string1 == '.' || *string1 == '-' ||
820 *string1 == '\'' || *string1 == '_')
825 if (*string2 == ' ' || *string2 == '.' || *string2 == '-' ||
826 *string2 == '\'' || *string2 == '_')
831 if (_toupper(*string1) != _toupper(*string2))
839 /* See if the strings match in forward & reverse direction, ignoring
840 * case and spaces/punctuation.
843 int strpasscmp(char *s1, char *s2)
845 char buf[256], *from, *to;
847 if (!lenient_strcmp(s1, s2))
849 /* if s2 is empty, say OK */
853 from = &s2[strlen(s2)];
855 for (to = &buf[0]; from >= s2; from--)
858 return lenient_strcmp(s1, buf);
863 * Input timeout handler. Loop back to asking for the first name.
866 /* Go to asking for first name. */
873 void canon_name(char *cp)
877 /* Trim whitespace off both ends. */
878 for (; *p2 && isspace(*p2); p2++)
883 p2 = cp + strlen(cp);
885 while (p2 >= cp && isspace(*p2))
888 /* Make it capitalized */