1 /* popwrd.c - set password for a POP subscriber */
3 static char ident[] = "@(#)$Id: popwrd.c,v 1.7 1992/12/15 00:20:22 jromine Exp $";
6 #include "../h/strings.h"
7 #include "../zotnet/bboards.h"
12 #include <sys/types.h>
20 struct passwd *getpwnam();
24 static char temp[] = "ptmp";
25 static char home[BUFSIZ];
29 char *crypt (), *getpass (), *tail ();
32 #define compar(s,t) (strcmp (s, t) ? s : "")
57 if ((pw = getpwnam (POPUID)) == NULL) {
58 fprintf (stderr, "no entry for ~%s.\n", POPUID);
61 if (chdir (strcpy (home, pw -> pw_dir)) < 0) {
62 fprintf (stderr, "no home directory for ~%s.\n", POPUID);
65 if (!setpwinfo (pw, POPDB, 0)) {
66 fprintf (stderr, "setbbinfo(%s, %s, 0) failed -- %s.\n",
67 pw -> pw_name, POPDB, getbberr ());
72 fprintf (stderr, "usage: %s pop-subscriber\n", *argv);
75 if ((bb = getbbnam (argv[1])) == NULL
76 && (bb = getbbaka (argv[1])) == NULL) {
77 fprintf (stderr, "Permission denied.\n");
81 if (!ldrbb (bb) && getuid () && !ldrchk (bb))
84 if ((bp = getbbcpy (bb)) == NULL) {
85 fprintf (stderr, "getbbcpy loses.\n");
94 for (insist = 0; insist < 2; insist++) {
96 printf ("Please use %s.\n",
97 flags == 1 ? "at least one non-numeric character"
98 : "a longer password");
100 if ((i = strlen (strcpy (buffer, getpass ("New password:")))) == 0) {
101 fprintf (stderr, "Password unchanged.\n");
106 for (cp = buffer; c = *cp++;)
107 if (c >= 'a' && c <= 'z')
110 if (c >= 'A' && c <= 'Z')
113 if (c >= '0' && c <= '9')
118 if ((flags >= 7 && i >= 4)
119 || ((flags == 2 || flags == 4) && i >= 6)
120 || ((flags == 3 || flags == 5 || flags == 6) && i >= 5))
124 if (strcmp (buffer, getpass ("Retype new password:"))) {
125 fprintf (stderr, "Mismatch - password unchanged.\n");
130 salt ^= 9 * getpid ();
131 saltc[0] = salt & 077;
132 saltc[1] = (salt >> 6) & 077;
133 for (i = 0; i < 2; i++) {
141 cp = crypt (buffer, saltc);
143 (void) signal (SIGHUP, SIG_IGN);
144 (void) signal (SIGINT, SIG_IGN);
145 (void) signal (SIGQUIT, SIG_IGN);
148 if ((fd = open (temp, O_WRONLY | O_CREAT | O_EXCL, 0644)) < 0) {
151 fprintf (stderr, "POP file busy - try again later.\n");
162 (void) signal (SIGTSTP, SIG_IGN);
164 if ((fp = fdopen (fd, "w")) == NULL) {
165 fprintf (stderr, "fdopen loses.\n");
166 (void) unlink (temp);
170 (void) setbbent (SB_STAY | SB_FAST);
171 while (bb = getbbent ()) {
172 if (strcmp (bb -> bb_name, bp -> bb_name) == 0)
173 bb -> bb_passwd = cp;
174 fprintf (fp, "%s:", bb -> bb_name);
175 if (ap = bb -> bb_aka)
177 fprintf (fp, "%s%s", ap != bb -> bb_aka ? "," : "", *ap);
178 fprintf (fp, ":%s:%s:", tail (bb -> bb_file), bb -> bb_passwd);
179 if ((ap = bb -> bb_leader) != NULL
180 && (strcmp (*ap, POPUID) != 0 || ap[1] != NULL))
182 fprintf (fp, "%s%s", ap != bb -> bb_leader ? "," : "", *ap);
183 fprintf (fp, ":%s:%s:%s:",
184 compar (bb -> bb_addr, bb -> bb_name),
185 compar (bb -> bb_request, POPUID),
187 if (ap = bb -> bb_dist)
189 fprintf (fp, "%s%s", ap != bb -> bb_dist ? "," : "", *ap);
190 fprintf (fp, ":%o\n", bb -> bb_flags);
194 if (rename (temp, POPDB) < 0) {
196 (void) unlink (temp);
212 if (strncmp (s, home, i = strlen (home)) == 0
213 && *(cp = s + i) == '/'