9 static char *rcsid_userreg_c = "$Header$";
24 struct user user, db_user;
26 char typed_mit_id[100];
32 int user_is_valid = 0;
33 int user_has_login = 0;
34 int already_registered = 0;
38 signal(sig, SIG_IGN); /* let us clean up, please */
50 register int reencrypt;
53 char tmpfirst[100], tmplast[100], tmpmid[100];
57 com_err(argv[0], status, "while trying to initialize");
63 signal(SIGINT, fix_display);
64 signal(SIGQUIT, fix_display);
65 signal(SIGHUP, fix_display);
73 display_text(WELCOME);
78 strcpy(tmpfirst, user.u_first);
79 strcpy(tmplast, user.u_last);
80 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
88 display_text_line("Sorry, you still cannot be found in the database.");
89 display_text_line(" ");
90 display_text_line("Please call the account administrator at x1325 for help.");
94 display_text_line(0); /* clear the window */
95 display_text_line("I'm afraid I was unable to find you in the database.");
96 display_text_line("Do you want to change some input (for example, the spelling");
97 display_text_line("of part of your name) and try again?");
98 if (askyn("Do you want to try again ? ") == YES) {
100 display_text_line(0);
102 "You entered your first name as \"%s\"", user.u_first);
103 display_text_line(line);
104 if (askyn("Do you want to change it? ") == YES) {
106 strcpy(tmpfirst, user.u_first);
107 strcpy(tmplast, user.u_last);
108 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
112 display_text_line(0);
114 "You entered your middle initial as \"%s\"", user.u_mid_init);
115 display_text_line(line);
116 if (askyn("Do you want to change it? ") == YES)
118 display_text_line(0);
120 "You entered your last name as \"%s\"", user.u_last);
121 display_text_line(line);
122 if (askyn("Do you want to change it? ") == YES) {
124 strcpy(tmpfirst, user.u_first);
125 strcpy(tmplast, user.u_last);
126 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
130 display_text_line(0);
132 "You entered your MIT id number as \"%s\"", typed_mit_id);
133 display_text_line(line);
134 if (askyn("Do you want to change it? ") == YES) {
144 if (!user_is_valid || already_registered) {
149 if (!user_has_login) {
150 if (negotiate_login() == -1) {
155 if (negotiate_passwd() == -1) {
160 display_text_line(0);
161 display_text_line("You are now registered to get an Athena account.");
162 sprintf(line, "Please remember your username of \"%s\" and the password",
164 display_text_line(line);
165 display_text_line("you typed in earlier.");
166 display_text_line("");
167 display_text_line("Your account should be created within about 12 hours\n");
169 display_text_line("");
170 display_text_line("You are now finished. Thank you!");
173 } while (getuid() == 0);/* Loop forever if we're root */
181 bzero(&user, sizeof(user));
183 already_registered = 0;
189 /* do the database lookup */
197 display_text_line(0);
199 "Looking you up in the database.... This may take a few minutes.");
202 result = verify_user(user.u_first, user.u_last,
203 typed_mit_id, user.u_mit_id, db_user.u_login);
207 display_text_line("You have been located in the user registration database.");
212 case UREG_NO_PASSWD_YET:
215 display_text_line ("You have chosen a login name, but you have not yet chosen a password.");
216 sprintf(line, "Remember: the username you chose was '%s'",
218 strcpy(user.u_login, db_user.u_login);
219 display_text_line(line);
224 case UREG_ALREADY_REGISTERED:
225 already_registered = 1;
227 * we have to reset this so we dont ask for a
231 display_text_line("You are already registered. An account for you probably already exists");
232 display_text_line("(if not, it will appear within 12 hours).");
233 display_text_line("");
234 display_text_line("Refer to the documents 'Essential Athena' and 'Essential Unix'");
235 strcpy(user.u_login, db_user.u_login);
236 sprintf(line, "for help logging in. Remember, the username you chose was '%s'",
238 display_text_line(line);
242 case UREG_USER_NOT_FOUND:
247 display_text(NETWORK_DOWN);
251 display_text_line("An unexpected error occurred while trying to access the database");
252 display_text_line(error_message(result));
261 register int result, result2;
264 char old_login[LOGIN_SIZE];
265 char old_password[PASSWORD_SIZE];
269 display_text(USERNAME_BLURB);
271 if (isalpha(user.u_first[0]))
272 *cp++ = user.u_first[0];
273 if (isalpha(user.u_mid_init[0]))
274 *cp++ = user.u_mid_init[0];
276 for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++) {
277 if (isalpha(user.u_last[i])) *cp++ = user.u_last[i];
280 for (i=0; user.u_login[i]; i++)
281 if (isupper(user.u_login[i]))
282 user.u_login[i]=tolower(user.u_login[i]);
284 strcpy(old_login, user.u_login);
285 sprintf(line, "We suggest the username '%s'.", user.u_login);
286 display_text_line(line);
288 "If you are sure you would prefer another username, feel free to enter");
290 "a different one, but remember that it will remain with you for all the ");
291 display_text_line("time you are at MIT.");
296 display_text_line(0);
297 display_text_line("Looking up that username in the database... This may take a few minutes.");
300 * Rather than bother SMS with a bunch of different
301 * usernames, all in use, we first try and see if this
302 * guy is known to Kerberos.
304 result = get_in_tkt(user.u_login, "", "ATHENA.MIT.EDU", "krbtgt", "ATHENA.MIT.EDU", "");
306 if (result != KDC_PR_UNKNOWN) {
308 strcpy(user.u_login, old_login);
310 display_text_line("I'm sorry, but that username is already taken. Please try again with a different username");
315 * If he isn't, let's try through SMS.
318 result = grab_login(user.u_first, user.u_last,
319 typed_mit_id, user.u_mit_id,
323 if (result == UREG_LOGIN_USED) goto in_use;
324 display_text(NETWORK_DOWN);
328 /* at this point we have successfully negotiated a username */
330 sprintf(line, "O.K. your username will be \"%s\".", user.u_login);
331 display_text_line(0);
332 display_text_line(line);
339 display_text_line(0);
340 display_text(PASSWORD_BLURB);
343 display_text_line("Storing password in the database... This may take a few minutes.");
347 display_text_line("done.");
353 /* input the first name */
356 signal(SIGALRM, restart);
357 input("Enter first Name:", buf, 100, FIRSTNAME_TIMEOUT);
358 strncpy(user.u_first, buf, FIRST_NAME_SIZE);
359 user.u_first[FIRST_NAME_SIZE - 1] = '\0';
360 canon_name(user.u_first);
366 /* input the last name */
369 signal(SIGALRM, restart);
370 input("Enter last Name:", buf, 100, LASTNAME_TIMEOUT);
371 strncpy(user.u_last, buf, LAST_NAME_SIZE);
372 user.u_last[LAST_NAME_SIZE - 1] = '\0';
373 canon_name(user.u_last);
380 char old_password[PASSWORD_SIZE];
381 char new_password[PASSWORD_SIZE];
382 char new_password_again[PASSWORD_SIZE];
385 signal(SIGALRM, restart);
386 input_no_echo("Enter password:", new_password,
387 PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT);
388 if (strlen(new_password) < 4) {
389 display_text_line("Please use a password of at least 4 characters.");
392 signal(SIGALRM, restart);
393 input_no_echo("Enter password again:", new_password_again,
394 PASSWORD_SIZE, REENTER_PASSWORD_TIMEOUT);
395 if (strcmp(new_password, new_password_again)) {
396 display_text_line("Sorry, the two passwords you just typed in don't match.");
397 display_text_line("Please try again.");
401 strcpy(user.u_password, new_password);
410 register char *nbuf = buf;
414 user.u_login[0] = '\0';
416 signal(SIGALRM, restart);
417 input("Enter username:", buf, 100, USERNAME_TIMEOUT);
418 while (*nbuf != '\0') {
419 if (!islower(*nbuf)) {
420 display_text_line("Your username must be all lowercase alphabetic characters.");
423 user.u_login[i] = *nbuf++;
425 if (i > LOGIN_SIZE - 1) {
426 display_text_line("Your username must be no more than 8 characters long.");
431 user.u_login[i] = '\0';
433 if (strlen(user.u_login) < 3) {
434 display_text_line("Your username must be 3 or more characters long.\n");
438 /* This part added to fix home directories -- asp */
439 strcpy(user.u_home_dir, "/mit/");
440 user.u_home_dir[5] = user.u_login[0];
441 user.u_home_dir[6] = '/';
442 user.u_home_dir[7] = user.u_login[1];
443 user.u_home_dir[8] = '/';
444 strcpy(user.u_home_dir + 9, user.u_login);
454 register char *nbuf = buf;
457 signal(SIGALRM, restart);
458 input("Enter MIT Id:", buf, 100, MITID_TIMEOUT);
461 while (*nbuf != '\0') {
462 if (*nbuf == ' ' || *nbuf == '-') {
466 if (!isdigit(*nbuf)) {
470 typed_mit_id[i] = *nbuf;
476 "Your MIT id must be a nine-digit number. Please try again.");
479 typed_mit_id[9] = '\0';
488 make_salt(salt, user.u_first, user.u_last);
489 strcpy(user.u_mit_id, crypt(&typed_mit_id[2], salt));
493 #define _tolower(c) ((c)|0x60)
495 make_salt(salt, first, last)
496 char *salt, *first, *last;
498 salt[0] = _tolower(last[0]);
499 salt[1] = _tolower(first[0]);
505 /* get middle initial */
508 signal(SIGALRM, restart);
509 input("Enter Middle Initial:", buf, 100, MI_TIMEOUT);
510 strncpy(user.u_mid_init, buf, MID_INIT_SIZE);
511 user.u_mid_init[MID_INIT_SIZE - 1] = '\0';
512 canon_name(user.u_mid_init);
518 /* exit quickly, not saving anything in the database */
519 bzero(&user, sizeof(user));
520 typed_mit_id[0] = '\0';
522 already_registered = 0;
523 sleep(6); /* give the user a chance to see the screen */
524 display_text_line(0);
534 * replaces a user in the database. If there is an error, it informs
535 * the user and calls qexit(); It returns only if is is successful
538 status = set_password(user.u_first, user.u_last, typed_mit_id,
539 user.u_mit_id, user.u_password);
542 display_text (NETWORK_DOWN);
547 #define _toupper(c) ((c) & ~0x20)
549 lenient_strcmp(string1, string2)
550 register char *string1, *string2;
553 * a primitive case insensitive string comparison. It returns only 0
554 * if the strings are equal (ignoring case) and 1 if they are
555 * different. Also ignores spaces.
559 if (*string1 == '\0' && *string2 == '\0') {
562 if (*string1 == ' ' || *string1 == '.' || *string1 == '-' || *string1 == '\'') {
566 if (*string2 == ' ' || *string2 == '.' || *string2 == '-' || *string2 == '\'') {
570 if (_toupper(*string1) != _toupper(*string2)) {
579 * Input timeout handler. Loop back to asking for the first name.
583 /* Go to asking for first name. */
592 register char *p2 = cp;
594 /* Trim whitespace off both ends. */
595 for (; *p2 && isspace(*p2); p2++) ;
598 p2 = cp + strlen(cp);
600 while (p2 >= cp && isspace(*p2)) *(--p2) = '\0';
602 /* Make it capitalized */
603 for (p2=cp; *p2; p2++) {
604 if (isupper(*p2)) *p2 = tolower(*p2);
606 if (islower(*cp)) *cp=toupper(*cp);