initial prep to put in Daemon mode
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 18 Oct 1981 08:58:24 +0000 (00:58 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sun, 18 Oct 1981 08:58:24 +0000 (00:58 -0800)
SCCS-vsn: usr.sbin/sendmail/src/alias.c 3.25
SCCS-vsn: usr.sbin/sendmail/src/conf.c 3.34
SCCS-vsn: usr.sbin/sendmail/src/sendmail.h 3.47
SCCS-vsn: usr.sbin/sendmail/src/util.c 3.10
SCCS-vsn: usr.sbin/sendmail/src/version.c 3.50
SCCS-vsn: usr.sbin/sendmail/src/main.c 3.42
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 3.25

usr/src/usr.sbin/sendmail/src/alias.c
usr/src/usr.sbin/sendmail/src/conf.c
usr/src/usr.sbin/sendmail/src/main.c
usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/sendmail.h
usr/src/usr.sbin/sendmail/src/util.c
usr/src/usr.sbin/sendmail/src/version.c

index 3f3ec06..22743b3 100644 (file)
@@ -4,9 +4,9 @@
 # include "sendmail.h"
 
 # ifdef DBM
 # include "sendmail.h"
 
 # ifdef DBM
-static char SccsId[] = "@(#)alias.c    3.24    %G%     (with DBM)";
+static char SccsId[] = "@(#)alias.c    3.25    %G%     (with DBM)";
 # else DBM
 # else DBM
-static char SccsId[] = "@(#)alias.c    3.24    %G%     (without DBM)";
+static char SccsId[] = "@(#)alias.c    3.25    %G%     (without DBM)";
 # endif DBM
 
 /*
 # endif DBM
 
 /*
@@ -427,7 +427,7 @@ forward(user)
        ADDRESS *user;
 {
        char buf[60];
        ADDRESS *user;
 {
        char buf[60];
-       struct stat stbuf;
+       extern bool safefile();
 
 # ifdef DEBUG
        if (Debug)
 
 # ifdef DEBUG
        if (Debug)
@@ -444,8 +444,7 @@ forward(user)
        /* good address -- look for .forward file in home */
        define('z', user->q_home);
        (void) expand("$z/.forward", buf, &buf[sizeof buf - 1]);
        /* good address -- look for .forward file in home */
        define('z', user->q_home);
        (void) expand("$z/.forward", buf, &buf[sizeof buf - 1]);
-       if (stat(buf, &stbuf) < 0 || stbuf.st_uid != user->q_uid ||
-           !bitset(S_IREAD, stbuf.st_mode))
+       if (!safefile(buf, user->q_uid, S_IREAD))
                return;
 
        /* we do have an address to forward to -- do it */
                return;
 
        /* we do have an address to forward to -- do it */
index 8476027..55cc3ce 100644 (file)
@@ -36,7 +36,7 @@
 
 
 
 
 
 
-static char SccsId[] = "@(#)conf.c     3.33    %G%";
+static char SccsId[] = "@(#)conf.c     3.34    %G%";
 \f/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
 \f/*
 **  Header info table
 **     Final (null) entry contains the flags used for any other field.
@@ -286,7 +286,10 @@ getegid()
 
 getruid()
 {
 
 getruid()
 {
-       return (getuid());
+       if (Daemon)
+               return (RealUid);
+       else
+               return (getuid());
 }
 
 
 }
 
 
@@ -296,7 +299,10 @@ getruid()
 
 getrgid()
 {
 
 getrgid()
 {
-       return (getgid());
+       if (Daemon)
+               return (RealGid);
+       else
+               return (getgid());
 }
 
 # endif V6
 }
 
 # endif V6
index 6e13e04..f30ba99 100644 (file)
@@ -1,12 +1,14 @@
 # include <signal.h>
 # include <pwd.h>
 # include <signal.h>
 # include <pwd.h>
+# include <sys/types.h>
+# include <sys/stat.h>
 # define  _DEFINE
 # include "sendmail.h"
 # ifdef LOG
 # include <syslog.h>
 # endif LOG
 
 # define  _DEFINE
 # include "sendmail.h"
 # ifdef LOG
 # include <syslog.h>
 # endif LOG
 
-static char    SccsId[] = "@(#)main.c  3.41    %G%";
+static char    SccsId[] = "@(#)main.c  3.42    %G%";
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
 
 /*
 **  SENDMAIL -- Post mail to a set of destinations.
@@ -138,6 +140,8 @@ main(argc, argv)
        char ybuf[10];                  /* holds tty id */
        bool aliasinit = FALSE;
        extern char *ttyname();
        char ybuf[10];                  /* holds tty id */
        bool aliasinit = FALSE;
        extern char *ttyname();
+       char cfbuf[60];                 /* holds .cf filename */
+       extern bool safefile();
        bool canrename;
 
        argv[argc] = NULL;
        bool canrename;
 
        argv[argc] = NULL;
@@ -303,7 +307,7 @@ main(argc, argv)
                        printf("Version %s Debug %d\n", Version, Debug);
                        break;
 
                        printf("Version %s Debug %d\n", Version, Debug);
                        break;
 
-                 case 'D':     /* redefine internal macro */
+                 case 'M':     /* redefine internal macro */
                        define(p[2], &p[3]);
                        break;
 # endif DEBUG
                        define(p[2], &p[3]);
                        break;
 # endif DEBUG
@@ -375,6 +379,11 @@ main(argc, argv)
                        GrabTo = TRUE;
                        break;
 
                        GrabTo = TRUE;
                        break;
 
+                 case 'D':     /* run as a daemon */
+                       Daemon = TRUE;
+                       MailBack = TRUE;
+                       break;
+
                  default:
                        /* at Eric Schmidt's suggestion, this will not be an error....
                        syserr("Unknown flag %s", p);
                  default:
                        /* at Eric Schmidt's suggestion, this will not be an error....
                        syserr("Unknown flag %s", p);
@@ -384,23 +393,14 @@ main(argc, argv)
        }
 
        /*
        }
 
        /*
-       **  Read control file.
+       **  Read system control file.
        */
 
        readcf(ConfFile, safecf);
 
        */
 
        readcf(ConfFile, safecf);
 
-# ifndef V6
-       p = getenv("HOME");
-       if (p != NULL)
-       {
-               char cfbuf[60];
-
-               define('z', p);
-               (void) expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1]);
-               if (access(cfbuf, 2) == 0)
-                       readcf(cfbuf, FALSE);
-       }
-# endif V6
+       /*
+       **  Initialize aliases.
+       */
 
        initaliases(AliasFile, aliasinit);
 # ifdef DBM
 
        initaliases(AliasFile, aliasinit);
 # ifdef DBM
@@ -411,6 +411,7 @@ main(argc, argv)
 # ifdef DEBUG
        if (Debug > 15)
        {
 # ifdef DEBUG
        if (Debug > 15)
        {
+               /* print configuration table (or at least part of it) */
                printrules();
                for (i = 0; i < MAXMAILERS; i++)
                {
                printrules();
                for (i = 0; i < MAXMAILERS; i++)
                {
@@ -424,9 +425,23 @@ main(argc, argv)
        }
 # endif DEBUG
 
        }
 # endif DEBUG
 
+       /*
+       **  If a daemon, wait for a request.
+       **      getrequests will always return in a child.
+       */
+
+       if (Daemon)
+               getrequests();
+
        /*
        locname = getname();
        if (locname == NULL || locname[0] == '\0')
        /*
        locname = getname();
        if (locname == NULL || locname[0] == '\0')
+       {
+               errno = 0;
+               p = getlogin();
+               errno = 0;
+       }
+       if (Daemon || p == NULL)
        {
                extern struct passwd *getpwuid();
                int uid;
        {
                extern struct passwd *getpwuid();
                int uid;
@@ -451,6 +466,16 @@ main(argc, argv)
 
        realname = p;
 
 
        realname = p;
 
+       /*
+       **  Process passwd file entry.
+       */
+
+       /* run user's .mailcf file */
+       define('z', pw->pw_dir);
+       (void) expand("$z/.mailcf", cfbuf, &cfbuf[sizeof cfbuf - 1]);
+       if (safefile(cfbuf, getruid(), S_IREAD))
+               readcf(cfbuf, FALSE);
+
        /* extract full name from passwd file */
        if ((fullname == NULL || fullname[0] == '\0') &&
            pw != NULL && pw->pw_gecos != NULL)
        /* extract full name from passwd file */
        if ((fullname == NULL || fullname[0] == '\0') &&
            pw != NULL && pw->pw_gecos != NULL)
@@ -466,7 +491,7 @@ main(argc, argv)
 
        setfrom(from, realname);
 
 
        setfrom(from, realname);
 
-       if (argc <= 0 && !GrabTo)
+       if (!Daemon && argc <= 0 && !GrabTo)
                usrerr("Usage: /etc/sendmail [flags] addr...");
 
        /*
                usrerr("Usage: /etc/sendmail [flags] addr...");
 
        /*
@@ -488,7 +513,10 @@ main(argc, argv)
 
        if (GrabTo)
                DontSend = TRUE;
 
        if (GrabTo)
                DontSend = TRUE;
-       sendtoargv(argv);
+       if (Daemon)
+               getrecipients();
+       else
+               sendtoargv(argv);
 
        /* if we have had errors sofar, drop out now */
        if (Errors > 0 && ExitStat == EX_OK)
 
        /* if we have had errors sofar, drop out now */
        if (Errors > 0 && ExitStat == EX_OK)
index 495f42a..916a8cd 100644 (file)
@@ -3,7 +3,7 @@
 # include <sys/stat.h>
 # include "sendmail.h"
 
 # include <sys/stat.h>
 # include "sendmail.h"
 
-static char SccsId[] = "@(#)recipient.c        3.24    %G%";
+static char SccsId[] = "@(#)recipient.c        3.25    %G%";
 
 /*
 **  SENDTO -- Designate a send list.
 
 /*
 **  SENDTO -- Designate a send list.
@@ -252,7 +252,7 @@ recipient(a)
                                a->q_flags |= QDONTSEND;
                        }
                        else if ((stat(buf, &stb) >= 0) ? (!writable(&stb)) :
                                a->q_flags |= QDONTSEND;
                        }
                        else if ((stat(buf, &stb) >= 0) ? (!writable(&stb)) :
-                           (*p = '\0', access(buf, 3) < 0))
+                           (*p = '\0', !safefile(buf, getruid(), S_IWRITE|S_IEXEC)))
                        {
                                a->q_flags |= QBADADDR;
                                giveresponse(EX_CANTCREAT, TRUE, m);
                        {
                                a->q_flags |= QBADADDR;
                                giveresponse(EX_CANTCREAT, TRUE, m);
index 2007e39..0c2b0ed 100644 (file)
@@ -1,13 +1,12 @@
 /*
 **  SENDMAIL.H -- Global definitions for sendmail.
 /*
 **  SENDMAIL.H -- Global definitions for sendmail.
-**
-**     @(#)sendmail.h  3.46    %G%
 */
 
 
 
 # ifdef _DEFINE
 # define EXTERN
 */
 
 
 
 # ifdef _DEFINE
 # define EXTERN
+static char SmailSccsId[] =    "@(#)sendmail.h 3.47    %G%";
 # else  _DEFINE
 # define EXTERN extern
 # endif _DEFINE
 # else  _DEFINE
 # define EXTERN extern
 # endif _DEFINE
@@ -279,6 +278,9 @@ EXTERN bool Verbose;        /* set if blow-by-blow desired */
 EXTERN bool    GrabTo;         /* if set, get recipients from msg */
 EXTERN bool    DontSend;       /* mark recipients as QDONTSEND */
 EXTERN bool    NoReturn;       /* don't return letter to sender */
 EXTERN bool    GrabTo;         /* if set, get recipients from msg */
 EXTERN bool    DontSend;       /* mark recipients as QDONTSEND */
 EXTERN bool    NoReturn;       /* don't return letter to sender */
+EXTERN bool    Daemon;         /* running as a daemon */
+EXTERN int     RealUid;        /* when Daemon, real uid of caller */
+EXTERN int     RealGid;        /* when Daemon, real gid of caller */
 EXTERN int     OldUmask;       /* umask when sendmail starts up */
 EXTERN int     Debug;          /* debugging level */
 EXTERN int     Errors;         /* set if errors */
 EXTERN int     OldUmask;       /* umask when sendmail starts up */
 EXTERN int     Debug;          /* debugging level */
 EXTERN int     Errors;         /* set if errors */
index 12c5967..34b361d 100644 (file)
@@ -1,10 +1,12 @@
 # include <stdio.h>
 # include <stdio.h>
+# include <sys/types.h>
+# include <sys/stat.h>
 # include <sysexits.h>
 # include "useful.h"
 # include <ctype.h>
 # include "conf.h"
 
 # include <sysexits.h>
 # include "useful.h"
 # include <ctype.h>
 # include "conf.h"
 
-static char    SccsId[] = "@(#)util.c  3.    %G%";
+static char    SccsId[] = "@(#)util.c  3.10    %G%";
 
 /*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
 
 /*
 **  STRIPQUOTES -- Strip quotes & quote bits from a string.
@@ -382,6 +384,35 @@ buildfname(p, login, buf)
        *bp = '\0';
 }
 \f/*
        *bp = '\0';
 }
 \f/*
+**  SAFEFILE -- return true if a file exists and is safe for a user.
+**
+**     Parameters:
+**             fn -- filename to check.
+**             uid -- uid to compare against.
+**             mode -- mode bits that must match.
+**
+**     Returns:
+**             TRUE if fn exists, is owned by uid, and matches mode.
+**             FALSE otherwise.
+**
+**     Side Effects:
+**             none.
+*/
+
+bool
+safefile(fn, uid, mode)
+       char *fn;
+       int uid;
+       int mode;
+{
+       struct stat stbuf;
+
+       if (stat(fn, &stbuf) >= 0 && stbuf.st_uid == uid &&
+           (stbuf.st_mode & mode) == mode)
+               return (TRUE);
+       return (FALSE);
+}
+\f/*
 **  SYSLOG -- fake entry to fool lint
 */
 
 **  SYSLOG -- fake entry to fool lint
 */
 
index 7cf4007..472832f 100644 (file)
@@ -1,3 +1,3 @@
-static char    SccsId[] = "@(#)SendMail version 3.49 of %G%";
+static char    SccsId[] = "@(#)SendMail version 3.50 of %G%";
 
 
-char   Version[] = "3.49 [%G%]";
+char   Version[] = "3.50 [%G%]";