]> andersk Git - moira.git/blame - clients/userreg/userreg.c
re-order fields in filsys forms
[moira.git] / clients / userreg / userreg.c
CommitLineData
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 13static char *rcsid_userreg_c = "$Header$";
989a2c2c 14#endif lint
15
7189310c 16#include <mit-copyright.h>
989a2c2c 17#include <curses.h>
989a2c2c 18#include <signal.h>
19#include <sys/time.h>
20#include <setjmp.h>
6f742fd0 21#include <ctype.h>
6f742fd0 22#include <krb.h>
86a2af4e 23#include <des.h>
24#include <kadm.h>
25#include <kadm_err.h>
6f742fd0 26#include <errno.h>
f05412e4 27#include "userreg.h"
28#include "ureg_err.h"
29
86a2af4e 30/* 7.2 release compatibility */
31#ifndef KADM_INSECURE_PW
32#define KADM_INSECURE_PW (-1783126240L)
33#endif
34
989a2c2c 35#define EXIT -1
36
37
569ee3f8 38struct user user, db_user;
39struct alias alias;
40char typed_mit_id[100];
86a2af4e 41char realm[REALM_SZ];
569ee3f8 42jmp_buf redo;
43int restart();
989a2c2c 44
569ee3f8 45extern int errno;
46int user_is_valid = 0;
6f742fd0 47int user_has_login = 0;
569ee3f8 48int already_registered = 0;
e0f744aa 49int enrollment = 0;
b92a6895 50extern char *disabled();
989a2c2c 51
569ee3f8 52fix_display(sig)
989a2c2c 53{
569ee3f8 54 signal(sig, SIG_IGN); /* let us clean up, please */
989a2c2c 55 noraw();
56 echo();
57 endwin();
569ee3f8 58 exit(1);
989a2c2c 59}
60
569ee3f8 61main(argc, argv)
62 int argc;
63 char **argv;
989a2c2c 64{
569ee3f8 65 register int ntimes;
66 register int reencrypt;
b92a6895 67 char line[100], *when, *msg;
6f742fd0 68 int status;
c16914a2 69 char tmpfirst[100], tmplast[100], tmpmid[100];
6f742fd0 70
71 status = ureg_init();
72 if (status) {
73 com_err(argv[0], status, "while trying to initialize");
74 exit(1);
75 }
569ee3f8 76
b92a6895 77 if (when = disabled(&msg)) {
78 printf("We're sorry, the registration service is unavailable right now\n");
79 if (msg)
80 printf("because %s\n", msg);
81 printf("You should be able to register after %s", when);
ce36e992 82 printf("\nPress ENTER or RETURN to continue ");
83 fflush(stdout);
84 getchar();
b92a6895 85 exit(0);
86 }
87
86a2af4e 88 /* stash the realm for later use */
89 if ((status = krb_get_lrealm(realm, 1)) != KSUCCESS) {
90 printf("System error; please try another workstation.");
91 exit(1);
92 }
93
569ee3f8 94 setup_display();
95
96 signal(SIGINT, fix_display);
97 signal(SIGQUIT, fix_display);
98 signal(SIGHUP, fix_display);
99
8556c987 100 while (1) {
569ee3f8 101 setjmp(redo);
102 reset();
103 ntimes = 0;
104
86a2af4e 105 display_text(WELCOME, "");
569ee3f8 106
107 gfirst();
108 gmi();
109 glast();
c16914a2 110 strcpy(tmpfirst, user.u_first);
111 strcpy(tmplast, user.u_last);
112 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
113 redisp();
114
569ee3f8 115 gmitid();
c16914a2 116
569ee3f8 117 while (dolook()) {
118 ntimes++;
119 if (ntimes > 3) {
ce36e992 120 display_text_line(0);
569ee3f8 121 display_text_line("Sorry, you still cannot be found in the database.");
122 display_text_line(" ");
82530f70 123 display_text_line("Please call an accounts consultant at x3-1325 for help.");
ce36e992 124 wait_for_user();
569ee3f8 125 break;
126 }
127 display_text_line(0); /* clear the window */
ce36e992 128 display_text_line("You could not be found in the database.");
569ee3f8 129 display_text_line("Do you want to change some input (for example, the spelling");
130 display_text_line("of part of your name) and try again?");
131 if (askyn("Do you want to try again ? ") == YES) {
132 reencrypt = 0;
133 display_text_line(0);
134 sprintf(line,
135 "You entered your first name as \"%s\"", user.u_first);
136 display_text_line(line);
137 if (askyn("Do you want to change it? ") == YES) {
138 gfirst();
c16914a2 139 strcpy(tmpfirst, user.u_first);
140 strcpy(tmplast, user.u_last);
141 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
142 redisp();
569ee3f8 143 reencrypt = 1;
144 }
145 display_text_line(0);
146 sprintf(line,
147 "You entered your middle initial as \"%s\"", user.u_mid_init);
148 display_text_line(line);
149 if (askyn("Do you want to change it? ") == YES)
150 gmi();
151 display_text_line(0);
152 sprintf(line,
f05412e4 153 "You entered your family name as \"%s\"", user.u_last);
569ee3f8 154 display_text_line(line);
155 if (askyn("Do you want to change it? ") == YES) {
156 glast();
c16914a2 157 strcpy(tmpfirst, user.u_first);
158 strcpy(tmplast, user.u_last);
159 FixName(tmplast, tmpfirst, user.u_last, user.u_first, tmpmid);
160 redisp();
569ee3f8 161 reencrypt = 1;
162 }
163 display_text_line(0);
164 sprintf(line,
165 "You entered your MIT id number as \"%s\"", typed_mit_id);
166 display_text_line(line);
167 if (askyn("Do you want to change it? ") == YES) {
168 gmitid();
169 reencrypt = 0;
170 }
171 if (reencrypt) {
e0f744aa 172 EncryptID(user.u_mit_id, typed_mit_id,
173 user.u_first, user.u_last);
569ee3f8 174 }
175 } else
176 break;
177 }
178 if (!user_is_valid || already_registered) {
179 qexit();
180 continue;
181 }
182 redisp();
6f742fd0 183 if (!user_has_login) {
184 if (negotiate_login() == -1) {
185 qexit();
186 continue;
187 }
188 }
189 if (negotiate_passwd() == -1) {
569ee3f8 190 qexit();
191 continue;
192 }
193 sleep(1);
e0f744aa 194 if (!enrollment)
86a2af4e 195 display_text(FINISHED, user.u_login);
196 else {
197 display_text(FINISHEDE, user.u_login);
198 if (askyn("Do you wish to set your mailbox now? (Yes or No) ")) {
199 clear();
200 refresh();
201 noraw();
202 echo();
203 kinit(user.u_login, user.u_password);
204 system(NAMESPACE_PROG);
205 dest_tkt();
206 qexit();
207 exit(0);
208 }
209 }
ce36e992 210 wait_for_user();
569ee3f8 211 qexit();
8556c987 212 break;
213 }
569ee3f8 214 restore_display();
215 exit(0);
989a2c2c 216}
217
569ee3f8 218reset()
219{
220 reset_display();
221 bzero(&user, sizeof(user));
222 user_is_valid = 0;
223 already_registered = 0;
e0f744aa 224 enrollment = 0;
569ee3f8 225 redisp();
989a2c2c 226}
227
569ee3f8 228dolook()
229{
230 /* do the database lookup */
989a2c2c 231
569ee3f8 232 char line[100];
233 register int result;
234 if (user_is_valid) {
235 /* !! */
236 return (0);
237 }
238 display_text_line(0);
ce36e992 239 display_text_line("Looking you up in the database.... This may take from 30 seconds to 10");
240 display_text_line("minutes, depending on how busy the system is at the moment.");
6f742fd0 241
c16914a2 242 timer_off();
6f742fd0 243 result = verify_user(user.u_first, user.u_last,
244 typed_mit_id, user.u_mit_id, db_user.u_login);
ce36e992 245 wfeep();
246 display_text_line(0);
c16914a2 247 timer_on();
6f742fd0 248 switch(result) {
249 case 0:
5615ce71 250 case UREG_ENROLLED:
6f742fd0 251 display_text_line("You have been located in the user registration database.");
252 user_is_valid = 1;
253 user_has_login = 0;
254 sleep(1);
255 return 0;
e0f744aa 256 case UREG_HALF_ENROLLED:
95ea3260 257 enrollment = 1;
258 /* fall through to: */
259 case UREG_NO_PASSWD_YET:
6f742fd0 260 user_is_valid = 1;
261 user_has_login = 1;
262 display_text_line ("You have chosen a login name, but you have not yet chosen a password.");
263 sprintf(line, "Remember: the username you chose was '%s'",
264 db_user.u_login);
265 strcpy(user.u_login, db_user.u_login);
266 display_text_line(line);
267 redisp();
268 sleep(5);
269 return (0);
270
271 case UREG_ALREADY_REGISTERED:
272 already_registered = 1;
273 /*
274 * we have to reset this so we dont ask for a
275 * new username
276 */
277 user_is_valid = 0;
278 display_text_line("You are already registered. An account for you probably already exists");
279 display_text_line("(if not, it will appear within 12 hours).");
280 display_text_line("");
5615ce71 281 display_text_line("Refer to the document 'Getting Started on Athena' for help logging in.");
6f742fd0 282 strcpy(user.u_login, db_user.u_login);
5615ce71 283 sprintf(line, "Remember, the username you chose was '%s'",
6f742fd0 284 db_user.u_login);
285 display_text_line(line);
286 redisp();
ce36e992 287 wait_for_user();
6f742fd0 288 return (0);
b92a6895 289 case UREG_DELETED:
86a2af4e 290 display_text(DELETED_ACCT, db_user.u_login);
ce36e992 291 wait_for_user();
b92a6895 292 restore_display();
293 exit(0);
294 case UREG_NOT_ALLOWED:
86a2af4e 295 display_text(OFFER_ENROLL, db_user.u_login);
e0f744aa 296 redisp();
297 if (!askyn("Continue choosing a name and password (Y/N)? ")) {
298 already_registered = 1;
299 return(0);
300 }
301 user_has_login = 0;
302 user_is_valid = 1;
303 enrollment = 1;
304 return(0);
5615ce71 305 case UREG_ENROLL_NOT_ALLOWED:
86a2af4e 306 display_text(NOT_ALLOWED, db_user.u_login);
ce36e992 307 wait_for_user();
b92a6895 308 restore_display();
309 exit(0);
310 case UREG_KRB_TAKEN:
86a2af4e 311 display_text(IMPROPER_LOGIN, db_user.u_login);
ce36e992 312 wait_for_user();
b92a6895 313 return(0);
6f742fd0 314 case UREG_USER_NOT_FOUND:
315 return (1);
c16914a2 316
6f742fd0 317 case ECONNREFUSED:
c16914a2 318 case ETIMEDOUT:
b92a6895 319 case UREG_MISC_ERROR:
86a2af4e 320 display_text(NETWORK_DOWN, db_user.u_login);
8476ce53 321 display_text_line(" ");
322 sprintf(line, "The specific error was: %s",
323 error_message(result));
324 display_text_line(line);
ce36e992 325 wait_for_user();
6f742fd0 326 return (0);
327
328 default:
329 display_text_line("An unexpected error occurred while trying to access the database");
330 display_text_line(error_message(result));
331 redisp();
ce36e992 332 wait_for_user();
6f742fd0 333 return(1);
989a2c2c 334 }
989a2c2c 335}
336
86a2af4e 337
338/* Get a login name from the user and register it. There are several steps
339 * to this: display help message, get name, check name, display confirmation
340 * message, get confirmation, register name.
341 */
342
6f742fd0 343negotiate_login()
569ee3f8 344{
86a2af4e 345 int result, i;
346 char line[100], old_login[LOGIN_SIZE+2];
347 char *error, *cp;
6f742fd0 348
86a2af4e 349 /* build suggested username */
350 cp = user.u_login;
351 if (isalpha(user.u_first[0]))
352 *cp++ = user.u_first[0];
353 if (isalpha(user.u_mid_init[0]))
354 *cp++ = user.u_mid_init[0];
355 for (i = 0; user.u_last[i] && cp - user.u_login < 8; i++)
356 if (isalpha(user.u_last[i]))
357 *cp++ = user.u_last[i];
358 for (i=0; user.u_login[i]; i++)
359 if (isupper(user.u_login[i]))
360 user.u_login[i]=tolower(user.u_login[i]);
361 strcpy(old_login, user.u_login);
c16914a2 362
86a2af4e 363 /* print message */
364 display_text(USERNAME_BLURB, user.u_login);
365
366 again:
367 /* get name from user */
368 glogin();
369
370 display_text_line(0);
371 display_text_line("Testing that username...");
372 error = "";
373 if (strlen(user.u_login) < 3)
374 error = "Your username must be at least 3 characters long.";
375 else if (strlen(user.u_login) > 8)
376 error = "Your username cannot be longer than 8 characters.";
377 else if (!isalpha(user.u_login[0]) || !islower(user.u_login[0]))
378 error = "Your username must start with a lowercase letter.";
379 else for (i = 1; i < strlen(user.u_login); i++)
380 if (!islower(user.u_login[i]) &&
381 !isdigit(user.u_login[i]) &&
382 user.u_login[i] != '_')
383 error = "Your username must contain only lower case letters, numbers, and underscore";
384 timer_off();
385 result = krb_get_pw_in_tkt(user.u_login, "", realm,
386 "krbtgt", realm, 1, "");
387 timer_on();
388 if (*error == 0 && result != KDC_PR_UNKNOWN)
389 error = "That username is already taken.";
390
391 /* if it's bad, get another name from user */
392 if (*error) {
393 strcpy(user.u_login, old_login);
394 redisp();
395 display_text_line(error);
396 display_text_line("Please choose another username.");
397 goto again;
398 }
399
400 /* name is OK, make sure */
401 display_text(USERNAME_BLURB2, user.u_login);
402 if (!askyn("Do you want to register this username? (Yes or No) "))
403 goto again;
404
405 display_text_line(0);
406 display_text_line("Trying to assign that username... This may take a few minutes.");
407
408 /* Do It! */
409 timer_off();
410 if (!enrollment)
411 result = grab_login(user.u_first, user.u_last,
412 typed_mit_id, user.u_mit_id,
413 user.u_login);
414 else
415 result = enroll_login(user.u_first, user.u_last,
416 typed_mit_id, user.u_mit_id,
417 user.u_login);
418 wfeep();
419 timer_on();
420 if (result != 0) {
421 char buf[BUFSIZ];
422
423 if (result == UREG_LOGIN_USED) {
424 /* name was in moira but not kerberos */
425 error = "Sorry, that username really was in use after all.";
426 strcpy(user.u_login, old_login);
427 redisp();
428 display_text_line(error);
429 display_text_line("Please choose another username.");
430 goto again;
c16914a2 431 }
432
86a2af4e 433 display_text(NETWORK_DOWN, "");
434 display_text_line(" ");
435 sprintf(buf, "The specific error was: %s", error_message(result));
436 display_text_line(buf);
437 wait_for_user();
438 return (qexit());
439 }
440
441 /* at this point we have successfully negotiated a username */
442 sprintf(line, "O.K. your username will be \"%s\".", user.u_login);
443 display_text_line(0);
444 display_text_line(line);
445 redisp();
446 sleep(3);
447 return 0;
448}
569ee3f8 449
6f742fd0 450
86a2af4e 451negotiate_passwd()
452{
453 char *passwd, *error;
454 char old_passwd[256], fullname[256], tktstring[256], inst[INST_SZ];
455 char login[ANAME_SZ], lpassword[PASSWORD_SIZE];
456 int result;
457 des_cblock key;
458 FILE *in;
459
460 again:
461 display_text(PASSWORD_BLURB, "");
462 gpass();
463
464 /* validate password */
465 error = NULL;
466 passwd = user.u_password;
467 sprintf(fullname, "%s%s", user.u_first, user.u_last);
468 if (strlen(passwd) < 6)
469 error = "Please choose a longer password.";
470 if (!strpasscmp(passwd, user.u_first) ||
471 !strpasscmp(passwd, user.u_last) ||
472 !strpasscmp(passwd, user.u_login) ||
473 !strpasscmp(passwd, fullname) ||
474 !strpasscmp(passwd, typed_mit_id))
475 error = "Please do not use your name or ID number for your password.";
476 if (!error) {
477 in = fopen(LOGIN_INFO, "r");
478 if (in != NULL) {
479 fgets(login, sizeof(login), in);
480 /* trim trailing newline */
481 if (strlen(login))
482 login[strlen(login) - 1] = 0;
483 fgets(lpassword, sizeof(lpassword), in);
484 /* trim trailing newline */
485 if (strlen(lpassword))
486 lpassword[strlen(lpassword) - 1] = 0;
487 fclose(in);
488 } else {
489 strcpy(login, "moira");
490 strcpy(lpassword, "moira");
491 }
c16914a2 492
86a2af4e 493 sprintf(tktstring, "/tmp/tkt_cpw_%d", getpid());
494 krb_set_tkt_string(tktstring);
495 des_string_to_key(passwd, key);
496 inst[0] = 0;
497
498 result = krb_get_pw_in_tkt(login, inst, realm, PWSERV_NAME,
499 KADM_SINST, 1, lpassword);
500 if (result == KSUCCESS)
501 result = kadm_init_link(PWSERV_NAME, KRB_MASTER, realm);
502 if (result == KSUCCESS)
503 result = kadm_check_pw(key, passwd, &error);
504 dest_tkt();
d04cb0cb 505 if (result == KADM_INSECURE_PW) {
506 error = "You have chosen a passsword that is in the dictionary of commonly\nselected user passwords. You will have to choose a better password.";
507 } else if (result != KSUCCESS) {
86a2af4e 508 display_text(NETWORK_DOWN);
509 display_text_line(" ");
510 sprintf(fullname, "%s while verifying password",
511 error_message(result));
512 display_text_line(fullname);
513 wait_for_user();
514 return(-1);
569ee3f8 515 }
86a2af4e 516 }
569ee3f8 517
86a2af4e 518 if (error) {
569ee3f8 519 display_text_line(0);
86a2af4e 520 display_text_line(error);
521 wait_for_user();
522 goto again;
523 }
524
525 display_text(PASSWORD_BLURB2, "");
526 strcpy(old_passwd, user.u_password);
527 gpass();
528 if (strcmp(old_passwd, user.u_password)) {
569ee3f8 529 display_text_line(0);
86a2af4e 530 display_text_line("What you just typed did not match the password you gave the first time.");
531 sleep(8);
532 goto again;
533 }
534
535 display_text_line("Storing password in the database... This may take a few minutes.");
536 if (do_replace()) {
537 return (-1);
538 }
539 display_text_line("done.");
540 return(0);
989a2c2c 541}
542
569ee3f8 543gfirst()
544{
545 /* input the first name */
ce36e992 546 char buf[FIRST_NAME_SIZE+2];
569ee3f8 547
4a54a6e5 548 signal(SIGALRM, fix_display);
ce36e992 549 input("Enter first Name:", buf, FIRST_NAME_SIZE+1,
550 FIRSTNAME_TIMEOUT, TRUE);
569ee3f8 551 strncpy(user.u_first, buf, FIRST_NAME_SIZE);
552 user.u_first[FIRST_NAME_SIZE - 1] = '\0';
6f742fd0 553 canon_name(user.u_first);
569ee3f8 554 redisp();
555}
989a2c2c 556
569ee3f8 557glast()
558{
559 /* input the last name */
ce36e992 560 char buf[LAST_NAME_SIZE+2];
569ee3f8 561
562 signal(SIGALRM, restart);
ce36e992 563 input("Enter family Name:", buf, LAST_NAME_SIZE+1,
564 LASTNAME_TIMEOUT, FALSE);
569ee3f8 565 strncpy(user.u_last, buf, LAST_NAME_SIZE);
566 user.u_last[LAST_NAME_SIZE - 1] = '\0';
6f742fd0 567 canon_name(user.u_last);
569ee3f8 568 redisp();
989a2c2c 569}
570
569ee3f8 571gpass()
572{
573 /* input password */
86a2af4e 574 char new_password[PASSWORD_SIZE + 1];
569ee3f8 575
569ee3f8 576 signal(SIGALRM, restart);
577 input_no_echo("Enter password:", new_password,
86a2af4e 578 PASSWORD_SIZE, NEW_PASSWORD_TIMEOUT);
6f742fd0 579 strcpy(user.u_password, new_password);
569ee3f8 580 redisp();
989a2c2c 581}
582
86a2af4e 583
584/* get login name */
585
569ee3f8 586glogin()
587{
86a2af4e 588 char buf[LOGIN_SIZE+2];
569ee3f8 589
569ee3f8 590 user.u_login[0] = '\0';
569ee3f8 591 signal(SIGALRM, restart);
5615ce71 592 input("Enter username:", buf, LOGIN_SIZE, USERNAME_TIMEOUT, FALSE);
86a2af4e 593 strcpy(user.u_login, buf);
569ee3f8 594 redisp();
989a2c2c 595}
596
569ee3f8 597gmitid()
598{
599 /* get mid id */
600 register int i;
ce36e992 601 char buf[15];
569ee3f8 602 register char *nbuf = buf;
603
604input_mit_id:
605 signal(SIGALRM, restart);
ce36e992 606 input("Enter MIT Id:", buf, 14, MITID_TIMEOUT, FALSE);
569ee3f8 607 i = 0;
608 nbuf = &buf[0];
609 while (*nbuf != '\0') {
610 if (*nbuf == ' ' || *nbuf == '-') {
611 nbuf++;
612 continue;
613 }
614 if (!isdigit(*nbuf)) {
615 i = 0;
616 break;
617 }
618 typed_mit_id[i] = *nbuf;
619 nbuf++;
620 i++;
621 }
622 if (i != 9) {
623 display_text_line(
624 "Your MIT id must be a nine-digit number. Please try again.");
625 goto input_mit_id;
626 }
627 typed_mit_id[9] = '\0';
628 redisp();
e0f744aa 629 EncryptID(user.u_mit_id, typed_mit_id, user.u_first, user.u_last);
989a2c2c 630}
631
569ee3f8 632gmi()
633{
634 /* get middle initial */
ce36e992 635 char buf[MID_INIT_SIZE+2];
569ee3f8 636
637 signal(SIGALRM, restart);
ce36e992 638 input("Enter Middle Initial:", buf, MID_INIT_SIZE+1, MI_TIMEOUT, TRUE);
569ee3f8 639 strncpy(user.u_mid_init, buf, MID_INIT_SIZE);
640 user.u_mid_init[MID_INIT_SIZE - 1] = '\0';
6f742fd0 641 canon_name(user.u_mid_init);
569ee3f8 642 redisp();
989a2c2c 643}
644
569ee3f8 645qexit()
646{
647 /* exit quickly, not saving anything in the database */
648 bzero(&user, sizeof(user));
649 typed_mit_id[0] = '\0';
650 user_is_valid = 0;
651 already_registered = 0;
e0f744aa 652 enrollment = 0;
ce36e992 653 sleep(2); /* give the user a chance to see the screen */
569ee3f8 654 display_text_line(0);
655 return (EXIT);
989a2c2c 656}
657
658
569ee3f8 659do_replace()
660{
6f742fd0 661 int status;
8476ce53 662 char buf[100];
6f742fd0 663
569ee3f8 664 /*
665 * replaces a user in the database. If there is an error, it informs
666 * the user and calls qexit(); It returns only if is is successful
667 */
c16914a2 668 timer_off();
e0f744aa 669 if (!enrollment)
670 status = set_password(user.u_first, user.u_last, typed_mit_id,
671 user.u_mit_id, user.u_password);
672 else
673 status = get_krb(user.u_first, user.u_last, typed_mit_id,
674 user.u_mit_id, user.u_password);
ce36e992 675 wfeep();
c16914a2 676 timer_on();
6f742fd0 677 if (status) {
678 display_text (NETWORK_DOWN);
8476ce53 679 display_text_line(" ");
680 sprintf(buf, "The specific error was: %s",
681 error_message(status));
682 display_text_line(buf);
683 wait_for_user();
569ee3f8 684 return (-1);
6f742fd0 685 } else return 0;
989a2c2c 686}
687
86a2af4e 688
689kinit(user, passwd)
690char *user, *passwd;
691{
692 int status;
693 char inst[INST_SZ];
694
695 inst[0] = 0;
696 status = krb_get_pw_in_tkt(user, inst, realm, "krbtgt",
697 realm, DEFAULT_TKT_LIFE, 0);
698 return(status);
699}
700
701
dd3dc6d5 702#ifndef _toupper
989a2c2c 703#define _toupper(c) ((c) & ~0x20)
dd3dc6d5 704#endif
989a2c2c 705
569ee3f8 706lenient_strcmp(string1, string2)
707 register char *string1, *string2;
989a2c2c 708{
569ee3f8 709 /*
710 * a primitive case insensitive string comparison. It returns only 0
711 * if the strings are equal (ignoring case) and 1 if they are
712 * different. Also ignores spaces.
713 */
714
715 while (1) {
716 if (*string1 == '\0' && *string2 == '\0') {
717 return (0);
718 }
86a2af4e 719 if (*string1 == ' ' || *string1 == '.' || *string1 == '-' ||
720 *string1 == '\'' || *string1 == '_') {
569ee3f8 721 string1++;
722 continue;
723 }
86a2af4e 724 if (*string2 == ' ' || *string2 == '.' || *string2 == '-' ||
725 *string2 == '\'' || *string2 == '_') {
569ee3f8 726 string2++;
727 continue;
728 }
729 if (_toupper(*string1) != _toupper(*string2)) {
730 return (1);
731 }
732 string1++;
733 string2++;
734 }
989a2c2c 735}
736
86a2af4e 737
738/* See if the strings match in forward & reverse direction, ignoring
739 * case and spaces/punctuation.
740 */
741
742strpasscmp(s1, s2)
743char *s1, *s2;
744{
745 char buf[256], *from, *to;
746
747 if (!lenient_strcmp(s1, s2))
748 return(0);
749 /* if s2 is empty, say OK */
750 if (!*s2)
751 return(1);
752
753 from = &s2[strlen(s2)];
754 from--;
755 for (to = &buf[0]; from >= s2; from--)
756 *to++ = *from;
757
758 return(lenient_strcmp(s1, buf));
759}
760
761
569ee3f8 762/*
763 * Input timeout handler. Loop back to asking for the first name.
989a2c2c 764 */
765
766restart()
767/* Go to asking for first name. */
768{
569ee3f8 769 qexit();
77cbb4e2 770 longjmp(redo, 1);
989a2c2c 771}
6f742fd0 772
773canon_name(cp)
774 register char *cp;
775{
776 register char *p2 = cp;
777
778 /* Trim whitespace off both ends. */
779 for (; *p2 && isspace(*p2); p2++) ;
780 if (*p2) {
781 strcpy(cp, p2);
782 p2 = cp + strlen(cp);
783 --p2;
784 while (p2 >= cp && isspace(*p2)) *(--p2) = '\0';
785 }
786 /* Make it capitalized */
e0ef9c76 787 FixCase(cp);
6f742fd0 788}
This page took 0.214525 seconds and 5 git commands to generate.