# include # include # include # define BUFSIZE 8192 # define NILSTR ((char *) 0) # define tfprintf if (isatty(0)&&isatty(1)&&isatty(2)) fprintf # define TXTFILE "/var2/nserve/db/user.dat.new" static char *usage = "Usage: (without arguments)\n"; void lowerstr (); main (argc, argv) int argc; char **argv; { char *me; register char *l, /* ptr to current character in current line */ *s, /* ptr to current character in search string */ *sl; /* ptr to start of matched search string */ char *starg; char *token; char *mail; char *id; char *alias; char *passwd; char match, linematch; FILE *sf, *mp; char sstring [BUFSIZE]; char line [BUFSIZE]; char mcmd [BUFSIZE]; char outb [4 * BUFSIZE]; int length; /* get my basename */ me = strrchr (argv [0], '/'); me = (me)? me + 1 : argv [0]; setuid (geteuid ()); if (argc != 1) { tfprintf (stderr, usage, me); exit (1); } if (!(sf = fopen (TXTFILE, "r"))) { exit (2); } match = '\0'; while (1) { fgets (sstring, BUFSIZE, stdin); if (feof (stdin)) { exit (6); } if (match) { break; } else if (!strcmp (sstring, "\n")) { match = '\1'; } } length = strlen (sstring); if (!length) { exit (6); } else { sstring [length - 1] = '\0'; } if (strlen (sstring) != strcspn (sstring, "0123456789")) { tfprintf (stderr, "%s: cannot lookup numbers.\n", me); exit (3); } lowerstr (sstring); linematch = '\0'; while (1) { fgets (line, BUFSIZE - 1, sf); length = strlen (line); if (length) { line [length - 1] = '\0'; } if (feof (sf)) { break; } lowerstr (line); starg = &line [0]; match = '\0'; mail = id = alias = passwd = NILSTR; while (token = strtok (starg, "\t")) { starg = NILSTR; /* for next call to strtok */ for (l = token, s = &sstring[0] ; *l; l++) { /* search for a match in search string */ if (*s == *l) { /* if characters match... */ if (s == &sstring[0] && !match) { /* save cur. pos. */ sl = l; } if (! *(++s)) { /* and search string is over... */ match ='\1'; } } else { s = &sstring[0]; /* otherwise, re-initialize ptr to search */ } /* search for a match in 2: and 5: fields */ if (l == token + 2) { if (*(l - 2) == '2' && *(l - 1) == ':') { mail = l; } if (*(l - 2) == '5' && *(l - 1) == ':') { id = l; } if (*(l - 2) == '6' && *(l - 1) == ':') { alias = l; } if (*(l - 2) == '7' && *(l - 1) == ':') { passwd = l; } } } /* for */ } /* while */ /* check for a duplicate match */ if (linematch && match) { tfprintf (stderr, "multiple matches\n"); exit (4); } else if (match) { linematch = match; sprintf (mcmd, "/usr/ucb/mail -s \"Your name server id\" %s", mail); if (passwd) { sprintf (mcmd, "/usr/ucb/mail -s \"Illegal request\" avarvit@cc.ece.ntua.gr",mail); sprintf (outb, "\nA request was made for disclosure of the name server identity code\nfor the entries matching the search string \"%s\".\n\nA single match was found, which corresponds to the e-mail address below.\n\n\t %s\n\nSince this entry already has a password, this request is illegal.\nPlease investigate this by contacting \"%s\" personally.\n\nThank you.\n", sstring, mail, alias); } else if (mail) { sprintf (outb, "\nA request was made for disclosure of the name server identity code\nfor the entries matching the search string \"%s\".\n\nA single match was found, which corresponds to your e-mail address.\n\nYour id code is: %s\n\nPlease use this id string as soon as possible as a password for logging\ninto the name server and setup an initial \"real\" password. As soon as\nyou do so, your id cannot serve as a password anymore. In order to do\nthis, connect to the name server via \"ph\", issue the command\n\n\tlogin %s\n\nand supply your id code as a password. Afterwads, issue the command\n\n\tpassword\n\nto setup a new password.\n\nPlease contact staff@cc.ece.ntua.gr for any problems you may have.\n\nThank you.\n", sstring, id, alias); } else { tfprintf (stderr, "This user does not have an e-mail registered.\n"); exit (5); } /* matched: %s, mail=%s, id=%s\n", sl, mail, id); */ } } /* while */ if (linematch) { if (!(mp = popen (mcmd, "w"))) { exit (7); } fprintf (mp, outb); pclose (mp); close (sf); exit (0); } else { tfprintf (stderr, "Not found.\n"); exit (6); } } void lowerstr (s) register char *s; { while (*s) { if (isupper (*s)) { *s = tolower (*s); } s++; } }