9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.05.19.20.59.48; author jromine; state Exp;
19 date 92.02.08.05.39.47; author jromine; state Exp;
24 date 92.02.08.00.09.16; author jromine; state Exp;
29 date 92.02.05.17.56.15; author jromine; state Exp;
34 date 92.02.04.21.48.55; author jromine; state Exp;
39 date 92.02.04.21.48.15; author jromine; state Exp;
54 @/* popauth.c - manipulate POP authorization DB */
56 static char ident[] = "@@(#)$Id: popauth.c,v 1.6 1992/05/19 20:59:48 jromine Exp jromine $";
61 #undef DBM /* used by mts.c and ndbm.h */
65 #include <sys/types.h>
71 #include "../zotnet/bboards.h"
72 #include "../zotnet/mts.h"
76 static struct swit switches[] = {
118 struct authinfo auth;
120 invo_name = r1bindex (argv[0], '/');
122 if ((cp = m_find (invo_name)) != NULL) {
123 ap = brkstring (cp = getcpy (cp), " ", "\n");
124 ap = copyip (ap, arguments);
128 (void) copyip (argv + 1, ap);
133 while (cp = *argp++) {
135 switch (smatch (++cp, switches)) {
137 ambigsw (cp, switches);
140 adios (NULLCP, "-%s unknown", cp);
142 (void) sprintf (buf, "%s [switches]", invo_name);
143 help (buf, switches);
147 initsw = 1, listsw = 0;
150 listsw = 1, initsw = 0;
153 if (!(usersw = *argp++) || *usersw == '-')
154 adios (NULLCP, "missing argument to %s", argp[-2]);
157 adios (NULLCP, "usage: %s [switches]", invo_name);
163 adios (NULLCP, "not compiled with APOP option");
166 initsw = listsw = 0, usersw = NULL;
172 if ((pw = getpwnam (POPUID)) == NULL)
173 adios (NULLCP, "POP user-id unknown");
175 (void) sprintf (buf, "%s.dir", APOP);
176 if (stat (buf, &st) != NOTOK) {
177 if (!getanswer ("Really initialize POP authorization DB? "))
180 (void) sprintf (buf, "%s.pag", APOP);
183 if ((db = dbm_open (APOP, O_RDWR | O_CREAT, 0600)) == NULL)
184 adios (APOP, "unable to create POP authorization DB");
185 if (fchown (dbm_dirfno (db), pw -> pw_uid, pw -> pw_gid) == NOTOK
186 || fchown (dbm_pagfno (db), pw -> pw_uid, pw -> pw_gid)
188 advise (" ", "error setting ownership of POP authorization DB");
193 if ((db = dbm_open (APOP, O_RDONLY, 0)) == NULL)
194 adios (APOP, "unable to open POP authorization DB");
196 if (flock (dbm_pagfno (db), LOCK_SH) == NOTOK)
197 adios (APOP, "unable to lock POP authorization DB");
201 key.dsize = strlen (key.dptr = usersw) + 1;
202 value = dbm_fetch (db, key);
203 if (value.dptr == NULL)
204 adios (NULLCP, "no such entry in POP authorization DB");
205 bcopy (value.dptr, (char *) &auth, sizeof auth);
206 printf ("%s\n", key.dptr);
209 for (key = dbm_firstkey (db); key.dptr; key = dbm_nextkey (db)) {
210 printf ("%s", key.dptr);
211 value = dbm_fetch (db, key);
212 if (value.dptr == NULL)
213 printf (" - no information?!?\n");
215 bcopy (value.dptr, (char *) &auth, sizeof auth);
228 fprintf (stderr, "Changing POP password for %s.\n", usersw);
230 key.dsize = strlen (key.dptr = usersw) + 1;
231 value = dbm_fetch (db, key);
232 if (value.dptr != NULL) {
233 bcopy (value.dptr, (char *) &auth, sizeof auth);
236 if ((i = strlen (strcpy (buf, getpass ("Old password:")))) == 0
237 || auth.auth_secretlen != i
238 || bcmp (buf, auth.auth_secret, i))
239 fprintf (stderr, "Sorry.\n"), exit (1);
247 for (insist = 0; insist < 2; insist++) {
252 printf ("Please use %s.\n",
253 flags == 1 ? "at least one non-numeric character"
254 : "a longer password");
256 if ((i = strlen (strcpy (buf, getpass ("New password:")))) == 0) {
257 fprintf (stderr, "Password unchanged.\n");
262 for (cp = buf; c = *cp++;)
263 if (c >= 'a' && c <= 'z')
266 if (c >= 'A' && c <= 'Z')
269 if (c >= '0' && c <= '9')
274 if ((flags >= 7 && i >= 4)
275 || ((flags == 2 || flags == 4) && i >= 6)
276 || ((flags == 3 || flags == 5 || flags == 6) && i >= 5))
280 if (strcmp (buf, getpass ("Retype new password:"))) {
281 fprintf (stderr, "Mismatch - password unchanged.\n");
285 if ((db = dbm_open (APOP, O_RDWR, 0)) == NULL)
286 adios (APOP, "unable to open POP authorization DB");
288 if (flock (dbm_pagfno (db), LOCK_EX) == NOTOK)
289 adios (APOP, "unable to lock POP authorization DB");
291 key.dsize = strlen (key.dptr = usersw) + 1;
293 buf[sizeof auth.auth_secret] = NULL;
294 bcopy (buf, auth.auth_secret, auth.auth_secretlen = strlen (buf));
295 value.dptr = (char *) &auth, value.dsize = sizeof auth;
297 if (dbm_store (db, key, value, DBM_REPLACE))
298 adios (NULLCP, "POP authorization DB may be corrupt?!?");
315 static char ident[] = "@@(#)$Id: popauth.c,v 1.5 1992/02/08 05:39:47 jromine Exp jromine $";
330 static char ident[] = "@@(#)$Id: popauth.c,v 1.4 1992/02/08 00:09:16 jromine Exp jromine $";
344 static char ident[] = "@@(#)$Id: popauth.c,v 1.3 1992/02/05 17:56:15 jromine Exp jromine $";
358 static char ident[] = "@@(#)$Id: popauth.c,v 1.2 1992/02/04 21:48:55 jromine Exp jromine $";
361 if ((db = dbm_open (APOP, listsw ? O_RDONLY : O_RDWR, 0))
363 adios (APOP, "unable to open POP authorization DB");
379 static char ident[] = "@@(#)$Id: scan.c,v 1.11 1992/02/03 22:45:20 jromine Exp $";
394 char auth_secret[16];
401 (void) fchown (dbm_dirfno (db), pw -> pw_uid, pw -> pw_gid);
402 (void) fchown (dbm_pagfno (db), pw -> pw_uid, pw -> pw_gid);
405 printf ("%s %ld\n", key.dptr, auth.auth_clock);
408 printf ("%s ", key.dptr);
411 printf ("- no information?!?\n");
414 printf ("%ld\n", auth.auth_clock);
416 (void) time (&auth.auth_clock);