7 * (c) Copyright 1988 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
13 static char *rcsid_userreg_c = "$Header$";
16 #include <mit-copyright.h>
30 struct user user, db_user;
32 char typed_mit_id[100];
38 int user_is_valid = 0;
39 int user_has_login = 0;
40 int already_registered = 0;
41 extern char *disabled();
45 signal(sig, SIG_IGN); /* let us clean up, please */
57 register int reencrypt;
58 char line[100], *when, *msg;
60 char tmpfirst[100], tmplast[100], tmpmid[100];
64 com_err(argv[0], status, "while trying to initialize");
68 if (when = disabled(&msg)) {
69 printf("We're sorry, the registration service is unavailable right now\n");
71 printf("because %s\n", msg);
72 printf("You should be able to register after %s", when);
73 printf("\nPress ENTER or RETURN to continue ");
81 signal(SIGINT, fix_display);
82 signal(SIGQUIT, fix_display);
83 signal(SIGHUP, fix_display);
91 display_text(WELCOME);
96 strcpy(tmpfirst, user.u_first);
97 strcpy(tmplast, user.u_last);
98 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
106 display_text_line(0);
107 display_text_line("Sorry, you still cannot be found in the database.");
108 display_text_line(" ");
109 display_text_line("Please call the account administrator at x3-1325 for help.");
113 display_text_line(0); /* clear the window */
114 display_text_line("You could not be found in the database.");
115 display_text_line("Do you want to change some input (for example, the spelling");
116 display_text_line("of part of your name) and try again?");
117 if (askyn("Do you want to try again ? ") == YES) {
119 display_text_line(0);
121 "You entered your first name as \"%s\"", user.u_first);
122 display_text_line(line);
123 if (askyn("Do you want to change it? ") == YES) {
125 strcpy(tmpfirst, user.u_first);
126 strcpy(tmplast, user.u_last);
127 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
131 display_text_line(0);
133 "You entered your middle initial as \"%s\"", user.u_mid_init);
134 display_text_line(line);
135 if (askyn("Do you want to change it? ") == YES)
137 display_text_line(0);
139 "You entered your family name as \"%s\"", user.u_last);
140 display_text_line(line);
141 if (askyn("Do you want to change it? ") == YES) {
143 strcpy(tmpfirst, user.u_first);
144 strcpy(tmplast, user.u_last);
145 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
149 display_text_line(0);
151 "You entered your MIT id number as \"%s\"", typed_mit_id);
152 display_text_line(line);
153 if (askyn("Do you want to change it? ") == YES) {
163 if (!user_is_valid || already_registered) {
168 if (!user_has_login) {
169 if (negotiate_login() == -1) {
174 if (negotiate_passwd() == -1) {
179 display_text_line(0);
180 display_text_line("You are now registered to get an Athena account.");
181 sprintf(line, "Please remember your username of \"%s\" and the password",
183 display_text_line(line);
184 display_text_line("you typed in earlier.");
185 display_text_line("");
186 display_text_line("Your account should be created within about 12 hours\n");
188 display_text_line("");
189 display_text_line("You are now finished. Thank you!");
192 } while (getuid() == 0);/* Loop forever if we're root */
200 bzero(&user, sizeof(user));
202 already_registered = 0;
208 /* do the database lookup */
216 display_text_line(0);
217 display_text_line("Looking you up in the database.... This may take from 30 seconds to 10");
218 display_text_line("minutes, depending on how busy the system is at the moment.");
221 result = verify_user(user.u_first, user.u_last,
222 typed_mit_id, user.u_mit_id, db_user.u_login);
224 display_text_line(0);
228 display_text_line("You have been located in the user registration database.");
233 case UREG_NO_PASSWD_YET:
236 display_text_line ("You have chosen a login name, but you have not yet chosen a password.");
237 sprintf(line, "Remember: the username you chose was '%s'",
239 strcpy(user.u_login, db_user.u_login);
240 display_text_line(line);
245 case UREG_ALREADY_REGISTERED:
246 already_registered = 1;
248 * we have to reset this so we dont ask for a
252 display_text_line("You are already registered. An account for you probably already exists");
253 display_text_line("(if not, it will appear within 12 hours).");
254 display_text_line("");
255 display_text_line("Refer to the documents 'Essential Athena' and 'Essential Unix'");
256 strcpy(user.u_login, db_user.u_login);
257 sprintf(line, "for help logging in. Remember, the username you chose was '%s'",
259 display_text_line(line);
264 display_text(DELETED_ACCT);
268 case UREG_NOT_ALLOWED:
269 display_text(NOT_ALLOWED);
274 display_text(IMPROPER_LOGIN);
277 case UREG_USER_NOT_FOUND:
282 case UREG_MISC_ERROR:
283 display_text(NETWORK_DOWN);
288 display_text_line("An unexpected error occurred while trying to access the database");
289 display_text_line(error_message(result));
300 char old_login[LOGIN_SIZE];
301 char realm[REALM_SZ];
305 display_text(USERNAME_BLURB);
307 if (isalpha(user.u_first[0]))
308 *cp++ = user.u_first[0];
309 if (isalpha(user.u_mid_init[0]))
310 *cp++ = user.u_mid_init[0];
312 for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++) {
313 if (isalpha(user.u_last[i])) *cp++ = user.u_last[i];
316 for (i=0; user.u_login[i]; i++)
317 if (isupper(user.u_login[i]))
318 user.u_login[i]=tolower(user.u_login[i]);
320 strcpy(old_login, user.u_login);
321 sprintf(line, "We suggest the username '%s'.", user.u_login);
322 display_text_line(line);
324 "If you are sure you would prefer another username, feel free to enter");
326 "a different one, but keep in mind that it will remain with you for all the ");
327 display_text_line("time you are at MIT.");
332 display_text_line(0);
333 display_text_line("Trying to assign that username... This may take a few minutes.");
336 * Rather than bother SMS with a bunch of different
337 * usernames, all in use, we first try and see if this
338 * guy is known to Kerberos.
340 if ((result = get_krbrlm(realm, 1)) != KSUCCESS) {
341 display_text_line("System error, please try another workstation.");
344 result = get_in_tkt(user.u_login, "", realm, "krbtgt", realm, 1, "");
346 if (result != KDC_PR_UNKNOWN) {
348 strcpy(user.u_login, old_login);
350 display_text_line("That username is already taken. Please try again with a different username");
355 * If he isn't, let's try through SMS.
358 result = grab_login(user.u_first, user.u_last,
359 typed_mit_id, user.u_mit_id,
366 if (result == UREG_LOGIN_USED) goto in_use;
367 display_text(NETWORK_DOWN);
368 display_text_line(" ");
369 sprintf(buf, "The specific error was: %s",
370 error_message(result));
371 display_text_line(buf);
376 /* at this point we have successfully negotiated a username */
378 sprintf(line, "O.K. your username will be \"%s\".", user.u_login);
379 display_text_line(0);
380 display_text_line(line);
387 display_text_line(0);
388 display_text(PASSWORD_BLURB);
391 display_text_line("Storing password in the database... This may take a few minutes.");
395 display_text_line("done.");
401 /* input the first name */
402 char buf[FIRST_NAME_SIZE+2];
404 signal(SIGALRM, restart);
405 input("Enter first Name:", buf, FIRST_NAME_SIZE+1,
406 FIRSTNAME_TIMEOUT, TRUE);
407 strncpy(user.u_first, buf, FIRST_NAME_SIZE);
408 user.u_first[FIRST_NAME_SIZE - 1] = '\0';
409 canon_name(user.u_first);
415 /* input the last name */
416 char buf[LAST_NAME_SIZE+2];
418 signal(SIGALRM, restart);
419 input("Enter family Name:", buf, LAST_NAME_SIZE+1,
420 LASTNAME_TIMEOUT, FALSE);
421 strncpy(user.u_last, buf, LAST_NAME_SIZE);
422 user.u_last[LAST_NAME_SIZE - 1] = '\0';
423 canon_name(user.u_last);
430 char new_password[PASSWORD_SIZE];
431 char new_password_again[PASSWORD_SIZE];
434 signal(SIGALRM, restart);
435 input_no_echo("Enter password:", new_password,
436 PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT);
437 if (strlen(new_password) < 4) {
438 display_text_line("Please use a password of at least 4 characters.");
441 signal(SIGALRM, restart);
442 input_no_echo("Enter password again:", new_password_again,
443 PASSWORD_SIZE, REENTER_PASSWORD_TIMEOUT);
444 if (strcmp(new_password, new_password_again)) {
445 display_text_line("Sorry, the two passwords you just typed in don't match.");
446 display_text_line("Please try again.");
450 strcpy(user.u_password, new_password);
458 char buf[LOGIN_SIZE+2];
459 register char *nbuf = buf;
463 user.u_login[0] = '\0';
465 signal(SIGALRM, restart);
466 input("Enter username:", buf, LOGIN_SIZE+1, USERNAME_TIMEOUT, FALSE);
467 if (!islower(*nbuf) && !isdigit(*nbuf)) {
468 display_text_line("Your username must start with a letter or number.");
471 while (*nbuf != '\0') {
472 if (!islower(*nbuf) && !isdigit(*nbuf)
473 && (*nbuf != '_') && (*nbuf != '.')) {
474 display_text_line("Your username must be all lowercase alphabetic characters.");
477 user.u_login[i] = *nbuf++;
479 if (i > LOGIN_SIZE - 1) {
480 display_text_line("Your username must be no more than 8 characters long.");
485 user.u_login[i] = '\0';
487 if (strlen(user.u_login) < 3) {
488 display_text_line("Your username must be 3 or more characters long.\n");
499 register char *nbuf = buf;
502 signal(SIGALRM, restart);
503 input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE);
506 while (*nbuf != '\0') {
507 if (*nbuf == ' ' || *nbuf == '-') {
511 if (!isdigit(*nbuf)) {
515 typed_mit_id[i] = *nbuf;
521 "Your MIT id must be a nine-digit number. Please try again.");
524 typed_mit_id[9] = '\0';
533 make_salt(salt, user.u_first, user.u_last);
534 strcpy(user.u_mit_id, crypt(&typed_mit_id[2], salt));
538 #define _tolower(c) ((c)|0x60)
540 make_salt(salt, first, last)
541 char *salt, *first, *last;
543 salt[0] = _tolower(last[0]);
544 salt[1] = _tolower(first[0]);
550 /* get middle initial */
551 char buf[MID_INIT_SIZE+2];
553 signal(SIGALRM, restart);
554 input("Enter Middle Initial:", buf, MID_INIT_SIZE+1, MI_TIMEOUT, TRUE);
555 strncpy(user.u_mid_init, buf, MID_INIT_SIZE);
556 user.u_mid_init[MID_INIT_SIZE - 1] = '\0';
557 canon_name(user.u_mid_init);
563 /* exit quickly, not saving anything in the database */
564 bzero(&user, sizeof(user));
565 typed_mit_id[0] = '\0';
567 already_registered = 0;
568 sleep(2); /* give the user a chance to see the screen */
569 display_text_line(0);
579 * replaces a user in the database. If there is an error, it informs
580 * the user and calls qexit(); It returns only if is is successful
583 status = set_password(user.u_first, user.u_last, typed_mit_id,
584 user.u_mit_id, user.u_password);
588 display_text (NETWORK_DOWN);
593 #define _toupper(c) ((c) & ~0x20)
595 lenient_strcmp(string1, string2)
596 register char *string1, *string2;
599 * a primitive case insensitive string comparison. It returns only 0
600 * if the strings are equal (ignoring case) and 1 if they are
601 * different. Also ignores spaces.
605 if (*string1 == '\0' && *string2 == '\0') {
608 if (*string1 == ' ' || *string1 == '.' || *string1 == '-' || *string1 == '\'') {
612 if (*string2 == ' ' || *string2 == '.' || *string2 == '-' || *string2 == '\'') {
616 if (_toupper(*string1) != _toupper(*string2)) {
625 * Input timeout handler. Loop back to asking for the first name.
629 /* Go to asking for first name. */
638 register char *p2 = cp;
640 /* Trim whitespace off both ends. */
641 for (; *p2 && isspace(*p2); p2++) ;
644 p2 = cp + strlen(cp);
646 while (p2 >= cp && isspace(*p2)) *(--p2) = '\0';
648 /* Make it capitalized */
649 for (p2=cp; *p2; p2++) {
650 if (isupper(*p2)) *p2 = tolower(*p2);
652 if (islower(*cp)) *cp=toupper(*cp);