9 static char *rcsid_userreg_c = "$Header$";
25 struct user user, db_user;
27 char typed_mit_id[100];
33 int user_is_valid = 0;
34 int user_has_login = 0;
35 int already_registered = 0;
39 signal(sig, SIG_IGN); /* let us clean up, please */
51 register int reencrypt;
54 char tmpfirst[100], tmplast[100], tmpmid[100];
58 com_err(argv[0], status, "while trying to initialize");
64 signal(SIGINT, fix_display);
65 signal(SIGQUIT, fix_display);
66 signal(SIGHUP, fix_display);
74 display_text(WELCOME);
79 strcpy(tmpfirst, user.u_first);
80 strcpy(tmplast, user.u_last);
81 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
89 display_text_line("Sorry, you still cannot be found in the database.");
90 display_text_line(" ");
91 display_text_line("Please call the account administrator at x1325 for help.");
95 display_text_line(0); /* clear the window */
96 display_text_line("I'm afraid I was unable to find you in the database.");
97 display_text_line("Do you want to change some input (for example, the spelling");
98 display_text_line("of part of your name) and try again?");
99 if (askyn("Do you want to try again ? ") == YES) {
101 display_text_line(0);
103 "You entered your first name as \"%s\"", user.u_first);
104 display_text_line(line);
105 if (askyn("Do you want to change it? ") == YES) {
107 strcpy(tmpfirst, user.u_first);
108 strcpy(tmplast, user.u_last);
109 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
113 display_text_line(0);
115 "You entered your middle initial as \"%s\"", user.u_mid_init);
116 display_text_line(line);
117 if (askyn("Do you want to change it? ") == YES)
119 display_text_line(0);
121 "You entered your family name as \"%s\"", user.u_last);
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 MIT id number as \"%s\"", typed_mit_id);
134 display_text_line(line);
135 if (askyn("Do you want to change it? ") == YES) {
145 if (!user_is_valid || already_registered) {
150 if (!user_has_login) {
151 if (negotiate_login() == -1) {
156 if (negotiate_passwd() == -1) {
161 display_text_line(0);
162 display_text_line("You are now registered to get an Athena account.");
163 sprintf(line, "Please remember your username of \"%s\" and the password",
165 display_text_line(line);
166 display_text_line("you typed in earlier.");
167 display_text_line("");
168 display_text_line("Your account should be created within about 12 hours\n");
170 display_text_line("");
171 display_text_line("You are now finished. Thank you!");
174 } while (getuid() == 0);/* Loop forever if we're root */
182 bzero(&user, sizeof(user));
184 already_registered = 0;
190 /* do the database lookup */
198 display_text_line(0);
200 "Looking you up in the database.... This may take a few minutes.");
203 result = verify_user(user.u_first, user.u_last,
204 typed_mit_id, user.u_mit_id, db_user.u_login);
208 display_text_line("You have been located in the user registration database.");
213 case UREG_NO_PASSWD_YET:
216 display_text_line ("You have chosen a login name, but you have not yet chosen a password.");
217 sprintf(line, "Remember: the username you chose was '%s'",
219 strcpy(user.u_login, db_user.u_login);
220 display_text_line(line);
225 case UREG_ALREADY_REGISTERED:
226 already_registered = 1;
228 * we have to reset this so we dont ask for a
232 display_text_line("You are already registered. An account for you probably already exists");
233 display_text_line("(if not, it will appear within 12 hours).");
234 display_text_line("");
235 display_text_line("Refer to the documents 'Essential Athena' and 'Essential Unix'");
236 strcpy(user.u_login, db_user.u_login);
237 sprintf(line, "for help logging in. Remember, the username you chose was '%s'",
239 display_text_line(line);
243 case UREG_USER_NOT_FOUND:
248 display_text(NETWORK_DOWN);
252 display_text_line("An unexpected error occurred while trying to access the database");
253 display_text_line(error_message(result));
262 register int result, result2;
265 char old_login[LOGIN_SIZE];
266 char old_password[PASSWORD_SIZE];
267 char realm[REALM_SZ];
271 display_text(USERNAME_BLURB);
273 if (isalpha(user.u_first[0]))
274 *cp++ = user.u_first[0];
275 if (isalpha(user.u_mid_init[0]))
276 *cp++ = user.u_mid_init[0];
278 for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++) {
279 if (isalpha(user.u_last[i])) *cp++ = user.u_last[i];
282 for (i=0; user.u_login[i]; i++)
283 if (isupper(user.u_login[i]))
284 user.u_login[i]=tolower(user.u_login[i]);
286 strcpy(old_login, user.u_login);
287 sprintf(line, "We suggest the username '%s'.", user.u_login);
288 display_text_line(line);
290 "If you are sure you would prefer another username, feel free to enter");
292 "a different one, but remember that it will remain with you for all the ");
293 display_text_line("time you are at MIT.");
298 display_text_line(0);
299 display_text_line("Looking up that username in the database... This may take a few minutes.");
302 * Rather than bother SMS with a bunch of different
303 * usernames, all in use, we first try and see if this
304 * guy is known to Kerberos.
306 if ((result = get_krbrlm(realm, 1)) != KSUCCESS) {
307 display_text_line("Can't get kerberos realm, giving up");
310 result = get_in_tkt(user.u_login, "", realm, "krbtgt", realm, "");
312 if (result != KDC_PR_UNKNOWN) {
314 strcpy(user.u_login, old_login);
316 display_text_line("I'm sorry, but that username is already taken. Please try again with a different username");
321 * If he isn't, let's try through SMS.
324 result = grab_login(user.u_first, user.u_last,
325 typed_mit_id, user.u_mit_id,
329 if (result == UREG_LOGIN_USED) goto in_use;
330 display_text(NETWORK_DOWN);
334 /* at this point we have successfully negotiated a username */
336 sprintf(line, "O.K. your username will be \"%s\".", user.u_login);
337 display_text_line(0);
338 display_text_line(line);
345 display_text_line(0);
346 display_text(PASSWORD_BLURB);
349 display_text_line("Storing password in the database... This may take a few minutes.");
353 display_text_line("done.");
359 /* input the first name */
362 signal(SIGALRM, restart);
363 input("Enter first Name:", buf, 100, FIRSTNAME_TIMEOUT);
364 strncpy(user.u_first, buf, FIRST_NAME_SIZE);
365 user.u_first[FIRST_NAME_SIZE - 1] = '\0';
366 canon_name(user.u_first);
372 /* input the last name */
375 signal(SIGALRM, restart);
376 input("Enter family Name:", buf, 100, LASTNAME_TIMEOUT);
377 strncpy(user.u_last, buf, LAST_NAME_SIZE);
378 user.u_last[LAST_NAME_SIZE - 1] = '\0';
379 canon_name(user.u_last);
386 char old_password[PASSWORD_SIZE];
387 char new_password[PASSWORD_SIZE];
388 char new_password_again[PASSWORD_SIZE];
391 signal(SIGALRM, restart);
392 input_no_echo("Enter password:", new_password,
393 PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT);
394 if (strlen(new_password) < 4) {
395 display_text_line("Please use a password of at least 4 characters.");
398 signal(SIGALRM, restart);
399 input_no_echo("Enter password again:", new_password_again,
400 PASSWORD_SIZE, REENTER_PASSWORD_TIMEOUT);
401 if (strcmp(new_password, new_password_again)) {
402 display_text_line("Sorry, the two passwords you just typed in don't match.");
403 display_text_line("Please try again.");
407 strcpy(user.u_password, new_password);
416 register char *nbuf = buf;
420 user.u_login[0] = '\0';
422 signal(SIGALRM, restart);
423 input("Enter username:", buf, 100, USERNAME_TIMEOUT);
424 while (*nbuf != '\0') {
425 if (!islower(*nbuf) && !isdigit(*nbuf)
426 && (*nbuf != '_') && (*nbuf != '.')) {
427 display_text_line("Your username must be all lowercase alphabetic characters.");
430 user.u_login[i] = *nbuf++;
432 if (i > LOGIN_SIZE - 1) {
433 display_text_line("Your username must be no more than 8 characters long.");
438 user.u_login[i] = '\0';
440 if (strlen(user.u_login) < 3) {
441 display_text_line("Your username must be 3 or more characters long.\n");
452 register char *nbuf = buf;
455 signal(SIGALRM, restart);
456 input("Enter MIT Id:", buf, 100, MITID_TIMEOUT);
459 while (*nbuf != '\0') {
460 if (*nbuf == ' ' || *nbuf == '-') {
464 if (!isdigit(*nbuf)) {
468 typed_mit_id[i] = *nbuf;
474 "Your MIT id must be a nine-digit number. Please try again.");
477 typed_mit_id[9] = '\0';
486 make_salt(salt, user.u_first, user.u_last);
487 strcpy(user.u_mit_id, crypt(&typed_mit_id[2], salt));
491 #define _tolower(c) ((c)|0x60)
493 make_salt(salt, first, last)
494 char *salt, *first, *last;
496 salt[0] = _tolower(last[0]);
497 salt[1] = _tolower(first[0]);
503 /* get middle initial */
506 signal(SIGALRM, restart);
507 input("Enter Middle Initial:", buf, 100, MI_TIMEOUT);
508 strncpy(user.u_mid_init, buf, MID_INIT_SIZE);
509 user.u_mid_init[MID_INIT_SIZE - 1] = '\0';
510 canon_name(user.u_mid_init);
516 /* exit quickly, not saving anything in the database */
517 bzero(&user, sizeof(user));
518 typed_mit_id[0] = '\0';
520 already_registered = 0;
521 sleep(6); /* give the user a chance to see the screen */
522 display_text_line(0);
532 * replaces a user in the database. If there is an error, it informs
533 * the user and calls qexit(); It returns only if is is successful
536 status = set_password(user.u_first, user.u_last, typed_mit_id,
537 user.u_mit_id, user.u_password);
540 display_text (NETWORK_DOWN);
545 #define _toupper(c) ((c) & ~0x20)
547 lenient_strcmp(string1, string2)
548 register char *string1, *string2;
551 * a primitive case insensitive string comparison. It returns only 0
552 * if the strings are equal (ignoring case) and 1 if they are
553 * different. Also ignores spaces.
557 if (*string1 == '\0' && *string2 == '\0') {
560 if (*string1 == ' ' || *string1 == '.' || *string1 == '-' || *string1 == '\'') {
564 if (*string2 == ' ' || *string2 == '.' || *string2 == '-' || *string2 == '\'') {
568 if (_toupper(*string1) != _toupper(*string2)) {
577 * Input timeout handler. Loop back to asking for the first name.
581 /* Go to asking for first name. */
590 register char *p2 = cp;
592 /* Trim whitespace off both ends. */
593 for (; *p2 && isspace(*p2); p2++) ;
596 p2 = cp + strlen(cp);
598 while (p2 >= cp && isspace(*p2)) *(--p2) = '\0';
600 /* Make it capitalized */
601 for (p2=cp; *p2; p2++) {
602 if (isupper(*p2)) *p2 = tolower(*p2);
604 if (islower(*cp)) *cp=toupper(*cp);