head 1.8; access; symbols; locks; strict; comment @ * @; 1.8 date 93.09.03.17.38.51; author jromine; state Exp; branches; next 1.7; 1.7 date 93.08.25.17.20.41; author jromine; state Exp; branches; next 1.6; 1.6 date 92.12.15.00.20.22; author jromine; state Exp; branches; next 1.5; 1.5 date 92.11.04.00.33.19; author jromine; state Exp; branches; next 1.4; 1.4 date 92.02.03.17.50.47; author jromine; state Exp; branches; next 1.3; 1.3 date 92.02.03.16.34.55; author jromine; state Exp; branches; next 1.2; 1.2 date 92.01.31.21.52.45; author jromine; state Exp; branches; next 1.1; 1.1 date 92.01.31.21.52.30; author jromine; state Exp; branches; next ; desc @@ 1.8 log @declare FOpen,FClose static #ifdef OVERHEAD @ text @/* m_getdefs.c - read the user's MH environment */ #ifndef lint static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.7 1993/08/25 17:20:41 jromine Exp jromine $"; #endif /* lint */ #include "../h/mh.h" #include #include #include #include #include extern int errno; #ifndef __STDC__ #ifdef SYS5 struct passwd *getpwuid (); #endif #endif /* !__STDC__ */ #ifndef OVERHEAD #define FOpen(f,m,e,c) fopen (f, m) #define FClose(f) fclose (f) #else /* OVERHEAD */ static FILE *FOpen (); static int FClose (); off_t lseek (); #endif /* OVERHEAD */ void m_getdefs() { int pid; register char *cp, *pp; #if defined (notdef) || defined (COMPAT) register char *ctx; #endif /* notdef or COMPAT */ char buf[BUFSIZ]; struct stat st; register struct passwd *pw; register FILE *ib; if (defpath) return; if (mypath == NULL) { if (mypath = getenv ("HOME")) mypath = getcpy (mypath); else if ((pw = getpwuid (getuid ())) == NULL || pw -> pw_dir == NULL || *pw -> pw_dir == 0) adios (NULLCP, "no HOME envariable"); else mypath = getcpy (pw -> pw_dir); if ((cp = mypath + strlen (mypath) - 1) > mypath && *cp == '/') *cp = 0; } if ((cp = getenv ("MH")) && *cp) { defpath = path (cp, TFILE); if ((ib = FOpen (defpath, "r", "MHFD", 0)) == NULL) adios (defpath, "unable to read"); if (*cp != '/') (void) m_putenv ("MH", defpath); } else { defpath = concat (mypath, "/", mh_profile, NULLCP); if ((ib = FOpen (defpath, "r", "MHFD", 0)) == NULL) switch (pid = vfork ()) { case NOTOK: adios ("fork", "unable to"); case OK: (void) setgid (getgid ()); (void) setuid (getuid ()); execlp (installproc, "install-mh", "-auto", NULLCP); fprintf (stderr, "unable to exec "); perror (installproc); _exit (-1); default: if (pidwait (pid, OK) || (ib = fopen (defpath, "r")) == NULL) adios (NULLCP, "[install-mh aborted]"); } } #if defined (notdef) || defined (COMPAT) ctx = context; #endif /* notdef or COMPAT */ m_readefs (&m_defs, ib, mh_profile, 0); (void) FClose (ib); if ((pp = m_find ("path")) != NULL && *pp) { if (*pp != '/') (void) sprintf (buf, "%s/%s", mypath, pp); else (void) strcpy (buf, pp); if (stat(buf, &st) == NOTOK) { if (errno != ENOENT) adios (buf, "error opening"); cp = concat ("Your MH-directory \"", buf, "\" doesn't exist; Create it? ", NULLCP); if (!getanswer(cp)) adios (NULLCP, "unable to access MH-directory \"%s\"", buf); free (cp); if (!makedir (buf)) adios (NULLCP, "unable to create", buf); } } #ifdef COMPAT if (strcmp (ctx, "/dev/null") == 0) return; /* called by install-mh */ if (access (ctxpath = getcpy (m_maildir (ctx)), 0) == NOTOK) switch (pid = fork ()) { case NOTOK: adios ("fork", "unable to"); case OK: (void) setgid (getgid ()); (void) setuid (getuid ()); fprintf (stderr, "install-mh -compat\n"); execlp (installproc, "install-mh", "-compat", NULLCP); fprintf (stderr, "unable to exec "); perror (installproc); _exit (-1); default: if (pidwait (pid, OK) || access (ctxpath, 0) == NOTOK) adios (NULLCP, "[install-mh aborted]"); if ((ib = fopen (defpath, "r")) == NULL) adios (defpath, "unable to read"); m_readefs (&m_defs, ib, mh_profile, 0); (void) FClose (ib); } free (ctxpath); #endif /* COMPAT */ if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == 0) cp = context; if ((ib = FOpen (ctxpath = getcpy (m_maildir (cp)), "r", "MHCONTEXTFD", 1)) == NULL) { #ifdef notdef /* XXX */ if (cp != ctx) adios (ctxpath, "unable to read"); #endif /* notdef */ } else { m_readefs ((struct node **) 0, ib, cp, 1); (void) FClose (ib); } } /* */ #ifdef OVERHEAD int fd_def = NOTOK; int fd_ctx = NOTOK; static FILE *FOpen (filename, mode, envariable, ctx) register char *filename, *mode, *envariable; register int ctx; { register int fd; register char *cp; char buffer[10]; struct stat st1; register FILE * fp; if ((cp = getenv (envariable)) == NULL || *cp == 0) goto not_open; if ((fd = atoi (cp)) <= fileno (stderr)) { advise (NULLCP, "bad value for $%s: %s", envariable, cp); (void) unputenv (envariable); return fopen (filename, mode); } if (ctx) fd_ctx = fd; else fd_def = fd; if (fstat (fd, &st1) == NOTOK) { not_open: ; if ((fp = fopen (filename, mode)) && !strcmp (mode, "r") && fileno (fp) > fileno (stderr)) { (void) sprintf (buffer, "%d", fileno (fp)); if (!m_putenv (envariable, buffer)) if (ctx) fd_ctx = fileno (fp); else fd_def = fileno (fp); } if ((cp = getenv ("MHFDEBUG")) && *cp) fprintf (stderr, "FOpen of %s sets %d\n", filename, fileno (fp)); return fp; } (void) lseek (fd, (off_t)0, 0); return fdopen (fd, mode); } static int FClose (f) register FILE *f; { register int d1, d2, i; register char *cp; if (f == NULL) return OK; if ((d1 = fileno (f)) != fd_def && d1 != fd_ctx) return fclose (f); d2 = dup (d1); i = fclose (f); if (d2 != NOTOK) { (void) dup2 (d2, d1); (void) close (d2); } else if (d1 == fd_def) fd_def = NOTOK; else fd_ctx = NOTOK; if ((cp = getenv ("MHFDEBUG")) && *cp) fprintf (stderr, "FClose emulating close of %d (%d)\n", d1, d2); return i; } #endif /* OVERHEAD */ @ 1.7 log @off_t fixes for BSD44 @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.6 1992/12/15 00:20:22 jromine Exp jromine $"; d27 2 a28 2 FILE *FOpen (); int FClose (); @ 1.6 log @endif sugar @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.5 1992/11/04 00:33:19 jromine Exp jromine $"; d30 1 a30 1 long lseek (); d213 1 a213 1 (void) lseek (fd, 0L, 0); @ 1.5 log @putenv -> m_putenv @ text @d3 2 a4 2 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.4 1992/02/03 17:50:47 jromine Exp jromine $"; #endif lint d26 1 a26 1 #else OVERHEAD d31 1 a31 1 #endif OVERHEAD d40 1 a40 1 #endif notdef or COMPAT d95 1 a95 1 #endif notdef or COMPAT d146 1 a146 1 #endif COMPAT d155 1 a155 1 #endif notdef d249 1 a249 1 #endif OVERHEAD @ 1.4 log @SYS5 @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.3 1992/02/03 16:34:55 jromine Exp jromine $"; d67 1 a67 1 (void) putenv ("MH", defpath); d201 1 a201 1 if (!putenv (envariable, buffer)) @ 1.3 log @fix @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: m_getdefs.c,v 1.2 1992/01/31 21:52:45 jromine Exp jromine $"; d17 1 d19 1 @ 1.2 log @kerberos @ text @d3 1 a3 1 static char ident[] = "@@(#)$Id: m_getfld.c,v 1.9 1992/01/24 18:03:41 jromine Exp $"; d16 1 d18 1 @ 1.1 log @Initial revision @ text @d2 3 d50 1 a50 1 || *pw -> pw_dir == NULL) d55 1 a55 1 *cp = NULL; d144 1 a144 1 if ((cp = getenv ("MHCONTEXT")) == NULL || *cp == NULL) d178 1 a178 1 if ((cp = getenv (envariable)) == NULL || *cp == NULL) @