]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/support/pop/RCS/popwrd.c,v
sbr/mts.c: Delete mmdlm2; use same-valued mmdlm1 instead.
[nmh] / docs / historical / mh-6.8.5 / support / pop / RCS / popwrd.c,v
1 head 1.7;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.7
9 date 92.12.15.00.20.22; author jromine; state Exp;
10 branches;
11 next 1.6;
12
13 1.6
14 date 92.02.03.17.53.37; author jromine; state Exp;
15 branches;
16 next 1.5;
17
18 1.5
19 date 90.04.05.15.34.47; author sources; state Exp;
20 branches;
21 next 1.4;
22
23 1.4
24 date 90.04.05.14.54.09; author sources; state Exp;
25 branches;
26 next 1.3;
27
28 1.3
29 date 90.02.05.14.08.37; author sources; state Exp;
30 branches;
31 next 1.2;
32
33 1.2
34 date 90.02.05.13.59.17; author sources; state Exp;
35 branches;
36 next 1.1;
37
38 1.1
39 date 90.02.05.13.59.09; author sources; state Exp;
40 branches;
41 next ;
42
43
44 desc
45 @@
46
47
48 1.7
49 log
50 @endif sugar
51 @
52 text
53 @/* popwrd.c - set password for a POP subscriber */
54 #ifndef lint
55 static char ident[] = "@@(#)$Id: popwrd.c,v 1.6 1992/02/03 17:53:37 jromine Exp jromine $";
56 #endif /* lint */
57
58 #include "../h/strings.h"
59 #include "../zotnet/bboards.h"
60 #include <errno.h>
61 #include <pwd.h>
62 #include <signal.h>
63 #include <stdio.h>
64 #include <sys/types.h>
65 #include <sys/file.h>
66 #ifdef SYS5
67 #include <fcntl.h>
68 #endif /* SYS5 */
69
70 #ifndef __STDC__
71 #ifdef SYS5
72 struct passwd *getpwnam();
73 #endif
74 #endif
75
76 static char temp[] = "ptmp";
77 static char home[BUFSIZ];
78
79 extern int errno;
80
81 char *crypt (), *getpass (), *tail ();
82 long time ();
83
84 #define compar(s,t) (strcmp (s, t) ? s : "")
85
86 /* \f */
87
88 /* ARGSUSED */
89
90 main (argc, argv)
91 int argc;
92 char **argv;
93 {
94 int i,
95 fd,
96 flags,
97 insist;
98 long salt;
99 char c,
100 *cp,
101 buffer[BUFSIZ],
102 saltc[2],
103 **ap;
104 struct bboard *bb,
105 *bp;
106 struct passwd *pw;
107 FILE * fp;
108
109 if ((pw = getpwnam (POPUID)) == NULL) {
110 fprintf (stderr, "no entry for ~%s.\n", POPUID);
111 exit (1);
112 }
113 if (chdir (strcpy (home, pw -> pw_dir)) < 0) {
114 fprintf (stderr, "no home directory for ~%s.\n", POPUID);
115 exit (1);
116 }
117 if (!setpwinfo (pw, POPDB, 0)) {
118 fprintf (stderr, "setbbinfo(%s, %s, 0) failed -- %s.\n",
119 pw -> pw_name, POPDB, getbberr ());
120 exit (1);
121 }
122
123 if (argc != 2) {
124 fprintf (stderr, "usage: %s pop-subscriber\n", *argv);
125 exit (1);
126 }
127 if ((bb = getbbnam (argv[1])) == NULL
128 && (bb = getbbaka (argv[1])) == NULL) {
129 fprintf (stderr, "Permission denied.\n");
130 exit (1);
131 }
132
133 if (!ldrbb (bb) && getuid () && !ldrchk (bb))
134 exit (1);
135
136 if ((bp = getbbcpy (bb)) == NULL) {
137 fprintf (stderr, "getbbcpy loses.\n");
138 exit (1);
139 }
140
141 (void) endbbent ();
142
143 #ifdef lint
144 flags = 0;
145 #endif /* lint */
146 for (insist = 0; insist < 2; insist++) {
147 if (insist)
148 printf ("Please use %s.\n",
149 flags == 1 ? "at least one non-numeric character"
150 : "a longer password");
151
152 if ((i = strlen (strcpy (buffer, getpass ("New password:")))) == 0) {
153 fprintf (stderr, "Password unchanged.\n");
154 exit (1);
155 }
156
157 flags = 0;
158 for (cp = buffer; c = *cp++;)
159 if (c >= 'a' && c <= 'z')
160 flags |= 2;
161 else
162 if (c >= 'A' && c <= 'Z')
163 flags |= 4;
164 else
165 if (c >= '0' && c <= '9')
166 flags |= 1;
167 else
168 flags |= 8;
169
170 if ((flags >= 7 && i >= 4)
171 || ((flags == 2 || flags == 4) && i >= 6)
172 || ((flags == 3 || flags == 5 || flags == 6) && i >= 5))
173 break;
174 }
175
176 if (strcmp (buffer, getpass ("Retype new password:"))) {
177 fprintf (stderr, "Mismatch - password unchanged.\n");
178 exit (1);
179 }
180
181 (void) time (&salt);
182 salt ^= 9 * getpid ();
183 saltc[0] = salt & 077;
184 saltc[1] = (salt >> 6) & 077;
185 for (i = 0; i < 2; i++) {
186 c = saltc[i] + '.';
187 if (c > '9')
188 c += 7;
189 if (c > 'Z')
190 c += 6;
191 saltc[i] = c;
192 }
193 cp = crypt (buffer, saltc);
194
195 (void) signal (SIGHUP, SIG_IGN);
196 (void) signal (SIGINT, SIG_IGN);
197 (void) signal (SIGQUIT, SIG_IGN);
198
199 (void) umask (0);
200 if ((fd = open (temp, O_WRONLY | O_CREAT | O_EXCL, 0644)) < 0) {
201 switch (errno) {
202 case EEXIST:
203 fprintf (stderr, "POP file busy - try again later.\n");
204 break;
205
206 default:
207 perror (temp);
208 break;
209 }
210 exit (1);
211 }
212
213 #ifdef SIGTSTP
214 (void) signal (SIGTSTP, SIG_IGN);
215 #endif /* SIGTSTP */
216 if ((fp = fdopen (fd, "w")) == NULL) {
217 fprintf (stderr, "fdopen loses.\n");
218 (void) unlink (temp);
219 exit (1);
220 }
221
222 (void) setbbent (SB_STAY | SB_FAST);
223 while (bb = getbbent ()) {
224 if (strcmp (bb -> bb_name, bp -> bb_name) == 0)
225 bb -> bb_passwd = cp;
226 fprintf (fp, "%s:", bb -> bb_name);
227 if (ap = bb -> bb_aka)
228 for (; *ap; ap++)
229 fprintf (fp, "%s%s", ap != bb -> bb_aka ? "," : "", *ap);
230 fprintf (fp, ":%s:%s:", tail (bb -> bb_file), bb -> bb_passwd);
231 if ((ap = bb -> bb_leader) != NULL
232 && (strcmp (*ap, POPUID) != 0 || ap[1] != NULL))
233 for (; *ap; ap++)
234 fprintf (fp, "%s%s", ap != bb -> bb_leader ? "," : "", *ap);
235 fprintf (fp, ":%s:%s:%s:",
236 compar (bb -> bb_addr, bb -> bb_name),
237 compar (bb -> bb_request, POPUID),
238 bb -> bb_relay);
239 if (ap = bb -> bb_dist)
240 for (; *ap; ap++)
241 fprintf (fp, "%s%s", ap != bb -> bb_dist ? "," : "", *ap);
242 fprintf (fp, ":%o\n", bb -> bb_flags);
243 }
244 (void) endbbent ();
245
246 if (rename (temp, POPDB) < 0) {
247 perror ("rename");
248 (void) unlink (temp);
249 exit (1);
250 }
251 (void) fclose (fp);
252
253 exit (0);
254 }
255
256 /* \f */
257
258 char *tail (s)
259 char *s;
260 {
261 int i;
262 char *cp;
263
264 if (strncmp (s, home, i = strlen (home)) == 0
265 && *(cp = s + i) == '/'
266 && *++cp)
267 return cp;
268
269 return s;
270 }
271 @
272
273
274 1.6
275 log
276 @getpw
277 SYS56
278 STDC
279 @
280 text
281 @d3 2
282 a4 2
283 static char ident[] = "@@(#)$Id: popwrd.c,v 1.5 1990/04/05 15:34:47 sources Exp jromine $";
284 #endif lint
285 d16 1
286 a16 1
287 #endif SYS5
288 d93 1
289 a93 1
290 #endif lint
291 d163 1
292 a163 1
293 #endif SIGTSTP
294 @
295
296
297 1.5
298 log
299 @add ID
300 @
301 text
302 @d3 1
303 a3 1
304 static char ident[] = "@@(#)$Id:$";
305 d18 5
306 @
307
308
309 1.4
310 log
311 @add ID
312 @
313 text
314 @d3 1
315 a3 1
316 static char ident[] = "@@(#)$Id:";
317 @
318
319
320 1.3
321 log
322 @*** empty log message ***
323 @
324 text
325 @d2 3
326 @
327
328
329 1.2
330 log
331 @*** empty log message ***
332 @
333 text
334 @d153 1
335 d155 1
336 @
337
338
339 1.1
340 log
341 @Initial revision
342 @
343 text
344 @d11 3
345 @