]>
Commit | Line | Data |
---|---|---|
989a2c2c | 1 | /* |
569ee3f8 | 2 | * $Source$ |
3 | * $Author$ | |
4 | * $Locker$ | |
5 | * $Header$ | |
7189310c | 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>. | |
989a2c2c | 10 | */ |
11 | ||
12 | #ifndef lint | |
569ee3f8 | 13 | static char *rcsid_userreg_c = "$Header$"; |
7ff930df | 14 | #endif |
989a2c2c | 15 | |
7189310c | 16 | #include <mit-copyright.h> |
ae13ad53 | 17 | #include <string.h> |
989a2c2c | 18 | #include <curses.h> |
989a2c2c | 19 | #include <signal.h> |
20 | #include <sys/time.h> | |
21 | #include <setjmp.h> | |
6f742fd0 | 22 | #include <ctype.h> |
86a2af4e | 23 | #include <kadm.h> |
24 | #include <kadm_err.h> | |
37e83580 | 25 | #include <krb.h> |
26 | #include <des.h> | |
6f742fd0 | 27 | #include <errno.h> |
f05412e4 | 28 | #include "userreg.h" |
29 | #include "ureg_err.h" | |
30 | ||
86a2af4e | 31 | /* 7.2 release compatibility */ |
32 | #ifndef KADM_INSECURE_PW | |
33 | #define KADM_INSECURE_PW (-1783126240L) | |
34 | #endif | |
35 | ||
989a2c2c | 36 | #define EXIT -1 |
37 | ||
38 | ||
569ee3f8 | 39 | struct user user, db_user; |
40 | struct alias alias; | |
86a2af4e | 41 | char realm[REALM_SZ]; |
569ee3f8 | 42 | jmp_buf redo; |
43 | int restart(); | |
989a2c2c | 44 | |
569ee3f8 | 45 | extern int errno; |
46 | int user_is_valid = 0; | |
6f742fd0 | 47 | int user_has_login = 0; |
569ee3f8 | 48 | int already_registered = 0; |
e0f744aa | 49 | int enrollment = 0; |
b92a6895 | 50 | extern char *disabled(); |
7ff930df | 51 | char typed_mit_id[100]; |
989a2c2c | 52 | |
569ee3f8 | 53 | fix_display(sig) |
989a2c2c | 54 | { |
f071d8a7 | 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 | |
569ee3f8 | 63 | signal(sig, SIG_IGN); /* let us clean up, please */ |
f071d8a7 | 64 | #endif |
989a2c2c | 65 | noraw(); |
66 | echo(); | |
67 | endwin(); | |
569ee3f8 | 68 | exit(1); |
989a2c2c | 69 | } |
70 | ||
569ee3f8 | 71 | main(argc, argv) |
72 | int argc; | |
73 | char **argv; | |
989a2c2c | 74 | { |
569ee3f8 | 75 | register int ntimes; |
76 | register int reencrypt; | |
b92a6895 | 77 | char line[100], *when, *msg; |
6f742fd0 | 78 | int status; |
c16914a2 | 79 | char tmpfirst[100], tmplast[100], tmpmid[100]; |
f071d8a7 | 80 | #ifdef POSIX |
81 | struct sigaction act; | |
82 | #endif | |
83 | ||
6f742fd0 | 84 | status = ureg_init(); |
85 | if (status) { | |
86 | com_err(argv[0], status, "while trying to initialize"); | |
87 | exit(1); | |
88 | } | |
569ee3f8 | 89 | |
b92a6895 | 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); | |
ce36e992 | 95 | printf("\nPress ENTER or RETURN to continue "); |
96 | fflush(stdout); | |
97 | getchar(); | |
b92a6895 | 98 | exit(0); |
99 | } | |
100 | ||
86a2af4e | 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 | ||
569ee3f8 | 107 | setup_display(); |
108 | ||
f071d8a7 | 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 | |
569ee3f8 | 117 | signal(SIGINT, fix_display); |
118 | signal(SIGQUIT, fix_display); | |
119 | signal(SIGHUP, fix_display); | |
f071d8a7 | 120 | #endif |
569ee3f8 | 121 | |
8556c987 | 122 | while (1) { |
569ee3f8 | 123 | setjmp(redo); |
124 | reset(); | |
125 | ntimes = 0; | |
126 | ||
86a2af4e | 127 | display_text(WELCOME, ""); |
569ee3f8 | 128 | |
129 | gfirst(); | |
130 | gmi(); | |
131 | glast(); | |
c16914a2 | 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 | ||
569ee3f8 | 137 | gmitid(); |
c16914a2 | 138 | |
569ee3f8 | 139 | while (dolook()) { |
140 | ntimes++; | |
141 | if (ntimes > 3) { | |
ce36e992 | 142 | display_text_line(0); |
569ee3f8 | 143 | display_text_line("Sorry, you still cannot be found in the database."); |
144 | display_text_line(" "); | |
82530f70 | 145 | display_text_line("Please call an accounts consultant at x3-1325 for help."); |
ce36e992 | 146 | wait_for_user(); |
569ee3f8 | 147 | break; |
148 | } | |
149 | display_text_line(0); /* clear the window */ | |
ce36e992 | 150 | display_text_line("You could not be found in the database."); |
569ee3f8 | 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(); | |
c16914a2 | 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(); | |
569ee3f8 | 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, | |
f05412e4 | 175 | "You entered your family name as \"%s\"", user.u_last); |
569ee3f8 | 176 | display_text_line(line); |
177 | if (askyn("Do you want to change it? ") == YES) { | |
178 | glast(); | |
c16914a2 | 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(); | |
569ee3f8 | 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) { | |
e0f744aa | 194 | EncryptID(user.u_mit_id, typed_mit_id, |
195 | user.u_first, user.u_last); | |
569ee3f8 | 196 | } |
197 | } else | |
198 | break; | |
199 | } | |
200 | if (!user_is_valid || already_registered) { | |
201 | qexit(); | |
202 | continue; | |
203 | } | |
204 | redisp(); | |
6f742fd0 | 205 | if (!user_has_login) { |
206 | if (negotiate_login() == -1) { | |
207 | qexit(); | |
208 | continue; | |
209 | } | |
210 | } | |
211 | if (negotiate_passwd() == -1) { | |
569ee3f8 | 212 | qexit(); |
213 | continue; | |
214 | } | |
215 | sleep(1); | |
e0f744aa | 216 | if (!enrollment) |
86a2af4e | 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 | } | |
ce36e992 | 232 | wait_for_user(); |
569ee3f8 | 233 | qexit(); |
8556c987 | 234 | break; |
235 | } | |
569ee3f8 | 236 | restore_display(); |
237 | exit(0); | |
989a2c2c | 238 | } |
239 | ||
569ee3f8 | 240 | reset() |
241 | { | |
242 | reset_display(); | |
f071d8a7 | 243 | memset(&user, 0, sizeof(user)); |
569ee3f8 | 244 | user_is_valid = 0; |
245 | already_registered = 0; | |
e0f744aa | 246 | enrollment = 0; |
569ee3f8 | 247 | redisp(); |
989a2c2c | 248 | } |
249 | ||
569ee3f8 | 250 | dolook() |
251 | { | |
252 | /* do the database lookup */ | |
989a2c2c | 253 | |
569ee3f8 | 254 | char line[100]; |
255 | register int result; | |
256 | if (user_is_valid) { | |
257 | /* !! */ | |
258 | return (0); | |
259 | } | |
260 | display_text_line(0); | |
ce36e992 | 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."); | |
6f742fd0 | 263 | |
c16914a2 | 264 | timer_off(); |
6f742fd0 | 265 | result = verify_user(user.u_first, user.u_last, |
266 | typed_mit_id, user.u_mit_id, db_user.u_login); | |
ce36e992 | 267 | wfeep(); |
268 | display_text_line(0); | |
c16914a2 | 269 | timer_on(); |
6f742fd0 | 270 | switch(result) { |
271 | case 0: | |
5615ce71 | 272 | case UREG_ENROLLED: |
6f742fd0 | 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; | |
e0f744aa | 278 | case UREG_HALF_ENROLLED: |
95ea3260 | 279 | enrollment = 1; |
280 | /* fall through to: */ | |
281 | case UREG_NO_PASSWD_YET: | |
6f742fd0 | 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(""); | |
30bf96f6 | 303 | display_text_line("Refer to the document 'Working on Athena' for help logging in."); |
6f742fd0 | 304 | strcpy(user.u_login, db_user.u_login); |
5615ce71 | 305 | sprintf(line, "Remember, the username you chose was '%s'", |
6f742fd0 | 306 | db_user.u_login); |
307 | display_text_line(line); | |
308 | redisp(); | |
ce36e992 | 309 | wait_for_user(); |
6f742fd0 | 310 | return (0); |
b92a6895 | 311 | case UREG_DELETED: |
86a2af4e | 312 | display_text(DELETED_ACCT, db_user.u_login); |
ce36e992 | 313 | wait_for_user(); |
b92a6895 | 314 | restore_display(); |
315 | exit(0); | |
316 | case UREG_NOT_ALLOWED: | |
86a2af4e | 317 | display_text(OFFER_ENROLL, db_user.u_login); |
e0f744aa | 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); | |
5615ce71 | 327 | case UREG_ENROLL_NOT_ALLOWED: |
86a2af4e | 328 | display_text(NOT_ALLOWED, db_user.u_login); |
ce36e992 | 329 | wait_for_user(); |
b92a6895 | 330 | restore_display(); |
331 | exit(0); | |
332 | case UREG_KRB_TAKEN: | |
86a2af4e | 333 | display_text(IMPROPER_LOGIN, db_user.u_login); |
ce36e992 | 334 | wait_for_user(); |
b92a6895 | 335 | return(0); |
6f742fd0 | 336 | case UREG_USER_NOT_FOUND: |
337 | return (1); | |
c16914a2 | 338 | |
6f742fd0 | 339 | case ECONNREFUSED: |
c16914a2 | 340 | case ETIMEDOUT: |
b92a6895 | 341 | case UREG_MISC_ERROR: |
86a2af4e | 342 | display_text(NETWORK_DOWN, db_user.u_login); |
8476ce53 | 343 | display_text_line(" "); |
344 | sprintf(line, "The specific error was: %s", | |
345 | error_message(result)); | |
346 | display_text_line(line); | |
ce36e992 | 347 | wait_for_user(); |
6f742fd0 | 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(); | |
ce36e992 | 354 | wait_for_user(); |
6f742fd0 | 355 | return(1); |
989a2c2c | 356 | } |
989a2c2c | 357 | } |
358 | ||
86a2af4e | 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 | ||
6f742fd0 | 365 | negotiate_login() |
569ee3f8 | 366 | { |
86a2af4e | 367 | int result, i; |
368 | char line[100], old_login[LOGIN_SIZE+2]; | |
369 | char *error, *cp; | |
6f742fd0 | 370 | |
86a2af4e | 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); | |
c16914a2 | 384 | |
86a2af4e | 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; | |
c16914a2 | 453 | } |
454 | ||
86a2af4e | 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 | } | |
569ee3f8 | 471 | |
6f742fd0 | 472 | |
86a2af4e | 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 | } | |
c16914a2 | 514 | |
86a2af4e | 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(); | |
d04cb0cb | 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) { | |
86a2af4e | 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); | |
569ee3f8 | 537 | } |
86a2af4e | 538 | } |
569ee3f8 | 539 | |
86a2af4e | 540 | if (error) { |
569ee3f8 | 541 | display_text_line(0); |
86a2af4e | 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)) { | |
569ee3f8 | 551 | display_text_line(0); |
86a2af4e | 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); | |
989a2c2c | 563 | } |
564 | ||
569ee3f8 | 565 | gfirst() |
566 | { | |
567 | /* input the first name */ | |
ce36e992 | 568 | char buf[FIRST_NAME_SIZE+2]; |
f071d8a7 | 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 | |
4a54a6e5 | 577 | signal(SIGALRM, fix_display); |
f071d8a7 | 578 | #endif |
ce36e992 | 579 | input("Enter first Name:", buf, FIRST_NAME_SIZE+1, |
580 | FIRSTNAME_TIMEOUT, TRUE); | |
569ee3f8 | 581 | strncpy(user.u_first, buf, FIRST_NAME_SIZE); |
582 | user.u_first[FIRST_NAME_SIZE - 1] = '\0'; | |
6f742fd0 | 583 | canon_name(user.u_first); |
569ee3f8 | 584 | redisp(); |
585 | } | |
989a2c2c | 586 | |
569ee3f8 | 587 | glast() |
588 | { | |
589 | /* input the last name */ | |
ce36e992 | 590 | char buf[LAST_NAME_SIZE+2]; |
f071d8a7 | 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 | |
569ee3f8 | 599 | signal(SIGALRM, restart); |
f071d8a7 | 600 | #endif |
ce36e992 | 601 | input("Enter family Name:", buf, LAST_NAME_SIZE+1, |
602 | LASTNAME_TIMEOUT, FALSE); | |
569ee3f8 | 603 | strncpy(user.u_last, buf, LAST_NAME_SIZE); |
604 | user.u_last[LAST_NAME_SIZE - 1] = '\0'; | |
6f742fd0 | 605 | canon_name(user.u_last); |
569ee3f8 | 606 | redisp(); |
989a2c2c | 607 | } |
608 | ||
569ee3f8 | 609 | gpass() |
610 | { | |
611 | /* input password */ | |
86a2af4e | 612 | char new_password[PASSWORD_SIZE + 1]; |
f071d8a7 | 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 | |
569ee3f8 | 621 | signal(SIGALRM, restart); |
f071d8a7 | 622 | #endif |
569ee3f8 | 623 | input_no_echo("Enter password:", new_password, |
86a2af4e | 624 | PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT); |
6f742fd0 | 625 | strcpy(user.u_password, new_password); |
569ee3f8 | 626 | redisp(); |
989a2c2c | 627 | } |
628 | ||
86a2af4e | 629 | |
630 | /* get login name */ | |
631 | ||
569ee3f8 | 632 | glogin() |
633 | { | |
86a2af4e | 634 | char buf[LOGIN_SIZE+2]; |
f071d8a7 | 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 | |
569ee3f8 | 643 | signal(SIGALRM, restart); |
f071d8a7 | 644 | #endif |
645 | user.u_login[0] = '\0'; | |
5615ce71 | 646 | input("Enter username:", buf, LOGIN_SIZE, USERNAME_TIMEOUT, FALSE); |
86a2af4e | 647 | strcpy(user.u_login, buf); |
569ee3f8 | 648 | redisp(); |
989a2c2c | 649 | } |
650 | ||
569ee3f8 | 651 | gmitid() |
652 | { | |
653 | /* get mid id */ | |
654 | register int i; | |
ce36e992 | 655 | char buf[15]; |
569ee3f8 | 656 | register char *nbuf = buf; |
f071d8a7 | 657 | #ifdef POSIX |
658 | struct sigaction act; | |
659 | #endif | |
660 | ||
569ee3f8 | 661 | |
662 | input_mit_id: | |
f071d8a7 | 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 | |
569ee3f8 | 669 | signal(SIGALRM, restart); |
f071d8a7 | 670 | #endif |
ce36e992 | 671 | input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE); |
569ee3f8 | 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(); | |
e0f744aa | 694 | EncryptID(user.u_mit_id, typed_mit_id, user.u_first, user.u_last); |
989a2c2c | 695 | } |
696 | ||
569ee3f8 | 697 | gmi() |
698 | { | |
699 | /* get middle initial */ | |
ce36e992 | 700 | char buf[MID_INIT_SIZE+2]; |
f071d8a7 | 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 | |
569ee3f8 | 709 | signal(SIGALRM, restart); |
f071d8a7 | 710 | #endif |
ce36e992 | 711 | input("Enter Middle Initial:", buf, MID_INIT_SIZE+1, MI_TIMEOUT, TRUE); |
569ee3f8 | 712 | strncpy(user.u_mid_init, buf, MID_INIT_SIZE); |
713 | user.u_mid_init[MID_INIT_SIZE - 1] = '\0'; | |
6f742fd0 | 714 | canon_name(user.u_mid_init); |
569ee3f8 | 715 | redisp(); |
989a2c2c | 716 | } |
717 | ||
569ee3f8 | 718 | qexit() |
719 | { | |
720 | /* exit quickly, not saving anything in the database */ | |
f071d8a7 | 721 | memset(&user, 0, sizeof(user)); |
569ee3f8 | 722 | typed_mit_id[0] = '\0'; |
723 | user_is_valid = 0; | |
724 | already_registered = 0; | |
e0f744aa | 725 | enrollment = 0; |
ce36e992 | 726 | sleep(2); /* give the user a chance to see the screen */ |
569ee3f8 | 727 | display_text_line(0); |
728 | return (EXIT); | |
989a2c2c | 729 | } |
730 | ||
731 | ||
569ee3f8 | 732 | do_replace() |
733 | { | |
6f742fd0 | 734 | int status; |
8476ce53 | 735 | char buf[100]; |
6f742fd0 | 736 | |
569ee3f8 | 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 | */ | |
c16914a2 | 741 | timer_off(); |
e0f744aa | 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); | |
ce36e992 | 748 | wfeep(); |
c16914a2 | 749 | timer_on(); |
6f742fd0 | 750 | if (status) { |
751 | display_text (NETWORK_DOWN); | |
8476ce53 | 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(); | |
569ee3f8 | 757 | return (-1); |
6f742fd0 | 758 | } else return 0; |
989a2c2c | 759 | } |
760 | ||
86a2af4e | 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 | ||
dd3dc6d5 | 775 | #ifndef _toupper |
989a2c2c | 776 | #define _toupper(c) ((c) & ~0x20) |
dd3dc6d5 | 777 | #endif |
989a2c2c | 778 | |
569ee3f8 | 779 | lenient_strcmp(string1, string2) |
780 | register char *string1, *string2; | |
989a2c2c | 781 | { |
569ee3f8 | 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 | } | |
86a2af4e | 792 | if (*string1 == ' ' || *string1 == '.' || *string1 == '-' || |
793 | *string1 == '\'' || *string1 == '_') { | |
569ee3f8 | 794 | string1++; |
795 | continue; | |
796 | } | |
86a2af4e | 797 | if (*string2 == ' ' || *string2 == '.' || *string2 == '-' || |
798 | *string2 == '\'' || *string2 == '_') { | |
569ee3f8 | 799 | string2++; |
800 | continue; | |
801 | } | |
802 | if (_toupper(*string1) != _toupper(*string2)) { | |
803 | return (1); | |
804 | } | |
805 | string1++; | |
806 | string2++; | |
807 | } | |
989a2c2c | 808 | } |
809 | ||
86a2af4e | 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 | ||
569ee3f8 | 835 | /* |
836 | * Input timeout handler. Loop back to asking for the first name. | |
989a2c2c | 837 | */ |
838 | ||
839 | restart() | |
840 | /* Go to asking for first name. */ | |
841 | { | |
569ee3f8 | 842 | qexit(); |
77cbb4e2 | 843 | longjmp(redo, 1); |
989a2c2c | 844 | } |
6f742fd0 | 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 */ | |
e0ef9c76 | 860 | FixCase(cp); |
6f742fd0 | 861 | } |