Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / sbr / RCS / m_getdefs.c,v
1 head    1.8;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.8
9 date    93.09.03.17.38.51;      author jromine; state Exp;
10 branches;
11 next    1.7;
12
13 1.7
14 date    93.08.25.17.20.41;      author jromine; state Exp;
15 branches;
16 next    1.6;
17
18 1.6
19 date    92.12.15.00.20.22;      author jromine; state Exp;
20 branches;
21 next    1.5;
22
23 1.5
24 date    92.11.04.00.33.19;      author jromine; state Exp;
25 branches;
26 next    1.4;
27
28 1.4
29 date    92.02.03.17.50.47;      author jromine; state Exp;
30 branches;
31 next    1.3;
32
33 1.3
34 date    92.02.03.16.34.55;      author jromine; state Exp;
35 branches;
36 next    1.2;
37
38 1.2
39 date    92.01.31.21.52.45;      author jromine; state Exp;
40 branches;
41 next    1.1;
42
43 1.1
44 date    92.01.31.21.52.30;      author jromine; state Exp;
45 branches;
46 next    ;
47
48
49 desc
50 @@
51
52
53 1.8
54 log
55 @declare FOpen,FClose static #ifdef OVERHEAD
56 @
57 text
58 @/* m_getdefs.c - read the user's MH environment */
59 #ifndef lint
60 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.7 1993/08/25 17:20:41 jromine Exp jromine $";
61 #endif  /* lint */
62
63 #include "../h/mh.h"
64 #include <stdio.h>
65 #include <errno.h>
66 #include <sys/types.h>
67 #include <sys/stat.h>
68 #include <pwd.h>
69
70
71 extern int errno;
72
73 #ifndef __STDC__
74 #ifdef  SYS5
75 struct  passwd  *getpwuid ();
76 #endif
77 #endif /* !__STDC__ */
78
79
80 #ifndef OVERHEAD
81 #define FOpen(f,m,e,c)  fopen (f, m)
82 #define FClose(f)       fclose (f)
83 #else   /* OVERHEAD */
84 static FILE    *FOpen ();
85 static int      FClose ();
86
87 off_t   lseek ();
88 #endif  /* OVERHEAD */
89
90
91 void m_getdefs() {
92     int     pid;
93     register char  *cp,
94                    *pp;
95 #if     defined (notdef) || defined (COMPAT)
96     register char  *ctx;
97 #endif  /* notdef or COMPAT */
98     char    buf[BUFSIZ];
99     struct stat st;
100     register struct passwd *pw;
101     register    FILE *ib;
102
103     if (defpath)
104         return;
105     if (mypath == NULL) {
106         if (mypath = getenv ("HOME"))
107             mypath = getcpy (mypath);
108         else
109             if ((pw = getpwuid (getuid ())) == NULL
110                     || pw -> pw_dir == NULL
111                     || *pw -> pw_dir == 0)
112                 adios (NULLCP, "no HOME envariable");
113             else
114                 mypath = getcpy (pw -> pw_dir);
115         if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/')
116             *cp = 0;
117     }
118
119     if ((cp = getenv ("MH")) && *cp) {
120         defpath = path (cp, TFILE);
121         if ((ib = FOpen (defpath, "r", "MHFD", 0)) == NULL)
122             adios (defpath, "unable to read");
123         if (*cp != '/')
124             (void) m_putenv ("MH", defpath);
125     }
126     else {
127         defpath = concat (mypath, "/", mh_profile, NULLCP);
128
129         if ((ib = FOpen (defpath, "r", "MHFD", 0)) == NULL)
130             switch (pid = vfork ()) {
131                 case NOTOK:
132                     adios ("fork", "unable to");
133
134                 case OK:
135                     (void) setgid (getgid ());
136                     (void) setuid (getuid ());
137
138                     execlp (installproc, "install-mh", "-auto", NULLCP);
139                     fprintf (stderr, "unable to exec ");
140                     perror (installproc);
141                     _exit (-1);
142
143                 default:
144                     if (pidwait (pid, OK)
145                             || (ib = fopen (defpath, "r")) == NULL)
146                         adios (NULLCP, "[install-mh aborted]");
147             }
148     }
149
150 #if     defined (notdef) || defined (COMPAT)
151     ctx = context;
152 #endif  /* notdef or COMPAT */
153     m_readefs (&m_defs, ib, mh_profile, 0);
154     (void) FClose (ib);
155
156     if ((pp = m_find ("path")) != NULL && *pp) {
157         if (*pp != '/')
158             (void) sprintf (buf, "%s/%s", mypath, pp);
159         else
160             (void) strcpy (buf, pp);
161         if (stat(buf, &st) == NOTOK) {
162             if (errno != ENOENT)
163                 adios (buf, "error opening");
164             cp = concat ("Your MH-directory \"", buf,
165                 "\" doesn't exist; Create it? ", NULLCP);
166             if (!getanswer(cp))
167                 adios (NULLCP, "unable to access MH-directory \"%s\"", buf);
168             free (cp);
169             if (!makedir (buf))
170                 adios (NULLCP, "unable to create", buf);
171         }
172     }
173
174 #ifdef  COMPAT
175     if (strcmp (ctx, "/dev/null") == 0)
176         return;                 /* called by install-mh */
177
178     if (access (ctxpath = getcpy (m_maildir (ctx)), 0) == NOTOK)
179         switch (pid = fork ()) {
180             case NOTOK:
181                 adios ("fork", "unable to");
182
183             case OK:
184                 (void) setgid (getgid ());
185                 (void) setuid (getuid ());
186                 fprintf (stderr, "install-mh -compat\n");
187
188                 execlp (installproc, "install-mh", "-compat", NULLCP);
189                 fprintf (stderr, "unable to exec ");
190                 perror (installproc);
191                 _exit (-1);
192
193             default:
194                 if (pidwait (pid, OK) || access (ctxpath, 0) == NOTOK)
195                     adios (NULLCP, "[install-mh aborted]");
196
197                 if ((ib = fopen (defpath, "r")) == NULL)
198                     adios (defpath, "unable to read");
199                 m_readefs (&m_defs, ib, mh_profile, 0);
200                 (void) FClose (ib);
201         }
202     free (ctxpath);
203 #endif  /* COMPAT */
204
205     if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == 0)
206         cp = context;
207     if ((ib = FOpen (ctxpath = getcpy (m_maildir (cp)), "r", "MHCONTEXTFD", 1))
208                 == NULL) {
209 #ifdef  notdef                  /* XXX */
210         if (cp != ctx)
211             adios (ctxpath, "unable to read");
212 #endif  /* notdef */
213     }
214     else {
215         m_readefs ((struct node **) 0, ib, cp, 1);
216         (void) FClose (ib);
217     }
218 }
219
220 /* \f */
221
222 #ifdef  OVERHEAD
223 int     fd_def = NOTOK;
224 int     fd_ctx = NOTOK;
225
226
227 static FILE *FOpen (filename, mode, envariable, ctx)
228 register char   *filename,
229                 *mode,
230                 *envariable;
231 register int     ctx;
232 {
233     register int    fd;
234     register char  *cp;
235     char    buffer[10];
236     struct stat st1;
237     register    FILE * fp;
238
239     if ((cp = getenv (envariable)) == NULL || *cp == 0)
240         goto not_open;
241
242     if ((fd = atoi (cp)) <= fileno (stderr)) {
243         advise (NULLCP, "bad value for $%s: %s", envariable, cp);
244         (void) unputenv (envariable);
245         return fopen (filename, mode);
246     }
247     if (ctx)
248         fd_ctx = fd;
249     else
250         fd_def = fd;
251
252     if (fstat (fd, &st1) == NOTOK) {
253 not_open: ;
254         if ((fp = fopen (filename, mode))
255                 && !strcmp (mode, "r")
256                 && fileno (fp) > fileno (stderr)) {
257             (void) sprintf (buffer, "%d", fileno (fp));
258             if (!m_putenv (envariable, buffer))
259                 if (ctx)
260                     fd_ctx = fileno (fp);
261                 else
262                     fd_def = fileno (fp);
263         }
264
265         if ((cp = getenv ("MHFDEBUG")) && *cp)
266             fprintf (stderr, "FOpen of %s sets %d\n", filename, fileno (fp));
267         return fp;
268     }
269
270     (void) lseek (fd, (off_t)0, 0);
271     return fdopen (fd, mode);
272 }
273
274
275 static int  FClose (f)
276 register FILE   *f;
277 {
278     register int    d1,
279                     d2,
280                     i;
281     register char  *cp;
282
283     if (f == NULL)
284         return OK;
285
286     if ((d1 = fileno (f)) != fd_def && d1 != fd_ctx)
287         return fclose (f);
288
289     d2 = dup (d1);
290     i = fclose (f);
291
292     if (d2 != NOTOK) {
293         (void) dup2 (d2, d1);
294         (void) close (d2);
295     }
296     else
297         if (d1 == fd_def)
298             fd_def = NOTOK;
299         else
300             fd_ctx = NOTOK;
301
302     if ((cp = getenv ("MHFDEBUG")) && *cp)
303         fprintf (stderr, "FClose emulating close of %d (%d)\n", d1, d2);
304     return i;
305 }
306 #endif  /* OVERHEAD */
307 @
308
309
310 1.7
311 log
312 @off_t fixes for BSD44
313 @
314 text
315 @d3 1
316 a3 1
317 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.6 1992/12/15 00:20:22 jromine Exp jromine $";
318 d27 2
319 a28 2
320 FILE   *FOpen ();
321 int     FClose ();
322 @
323
324
325 1.6
326 log
327 @endif sugar
328 @
329 text
330 @d3 1
331 a3 1
332 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.5 1992/11/04 00:33:19 jromine Exp jromine $";
333 d30 1
334 a30 1
335 long    lseek ();
336 d213 1
337 a213 1
338     (void) lseek (fd, 0L, 0);
339 @
340
341
342 1.5
343 log
344 @putenv -> m_putenv
345 @
346 text
347 @d3 2
348 a4 2
349 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.4 1992/02/03 17:50:47 jromine Exp jromine $";
350 #endif  lint
351 d26 1
352 a26 1
353 #else   OVERHEAD
354 d31 1
355 a31 1
356 #endif  OVERHEAD
357 d40 1
358 a40 1
359 #endif  notdef or COMPAT
360 d95 1
361 a95 1
362 #endif  notdef or COMPAT
363 d146 1
364 a146 1
365 #endif  COMPAT
366 d155 1
367 a155 1
368 #endif  notdef
369 d249 1
370 a249 1
371 #endif  OVERHEAD
372 @
373
374
375 1.4
376 log
377 @SYS5
378 @
379 text
380 @d3 1
381 a3 1
382 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.3 1992/02/03 16:34:55 jromine Exp jromine $";
383 d67 1
384 a67 1
385             (void) putenv ("MH", defpath);
386 d201 1
387 a201 1
388             if (!putenv (envariable, buffer))
389 @
390
391
392 1.3
393 log
394 @fix
395 @
396 text
397 @d3 1
398 a3 1
399 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.2 1992/01/31 21:52:45 jromine Exp jromine $";
400 d17 1
401 d19 1
402 @
403
404
405 1.2
406 log
407 @kerberos
408 @
409 text
410 @d3 1
411 a3 1
412 static char ident[] = "@@(#)$Id: m_getfld.c,v 1.9 1992/01/24 18:03:41 jromine Exp $";
413 d16 1
414 d18 1
415 @
416
417
418 1.1
419 log
420 @Initial revision
421 @
422 text
423 @d2 3
424 d50 1
425 a50 1
426                     || *pw -> pw_dir == NULL)
427 d55 1
428 a55 1
429             *cp = NULL;
430 d144 1
431 a144 1
432     if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == NULL)
433 d178 1
434 a178 1
435     if ((cp = getenv (envariable)) == NULL || *cp == NULL)
436 @