cleanup of symbolic link checking -- make it less picky
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 11 Dec 1993 08:40:15 +0000 (00:40 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 11 Dec 1993 08:40:15 +0000 (00:40 -0800)
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 8.27
SCCS-vsn: usr.sbin/sendmail/src/savemail.c 8.22
SCCS-vsn: usr.sbin/sendmail/src/util.c 8.22

usr/src/usr.sbin/sendmail/src/recipient.c
usr/src/usr.sbin/sendmail/src/savemail.c
usr/src/usr.sbin/sendmail/src/util.c

index 6b1ac8c..6fc0268 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        8.26 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        8.27 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -364,7 +364,7 @@ recipient(a, sendq, e)
                        a->q_flags |= QBADADDR;
                        usrerr("550 Cannot mail directly to files");
                }
                        a->q_flags |= QBADADDR;
                        usrerr("550 Cannot mail directly to files");
                }
-               else if (!writable(buf))
+               else if (!writable(buf, SFF_ANYFILE))
                {
                        a->q_flags |= QBADADDR;
                        giveresponse(EX_CANTCREAT, m, NULL, a->q_alias, e);
                {
                        a->q_flags |= QBADADDR;
                        giveresponse(EX_CANTCREAT, m, NULL, a->q_alias, e);
@@ -610,7 +610,8 @@ finduser(name, fuzzyp)
 **     not writable.  This is also enforced by mailfile.
 **
 **     Parameters:
 **     not writable.  This is also enforced by mailfile.
 **
 **     Parameters:
-**             s -- pointer to a stat struct for the file.
+**             filename -- the file name to check.
+**             flags -- SFF_* flags to control the function.
 **
 **     Returns:
 **             TRUE -- if we will be able to write this file.
 **
 **     Returns:
 **             TRUE -- if we will be able to write this file.
@@ -621,8 +622,9 @@ finduser(name, fuzzyp)
 */
 
 bool
 */
 
 bool
-writable(filename)
+writable(filename, flags)
        char *filename;
        char *filename;
+       int flags;
 {
        uid_t euid;
        gid_t egid;
 {
        uid_t euid;
        gid_t egid;
@@ -633,10 +635,11 @@ writable(filename)
        extern char RealUserName[];
 
        if (tTd(29, 5))
        extern char RealUserName[];
 
        if (tTd(29, 5))
-               printf("writable(%s)\n", filename);
+               printf("writable(%s, %x)\n", filename, flags);
 
 #ifdef HASLSTAT
 
 #ifdef HASLSTAT
-       if (lstat(filename, &stb) < 0)
+       if ((bitset(SFF_NOSLINK, flags) ? lstat(filename, &stb)
+                                       : stat(filename, &stb)) < 0)
 #else
        if (stat(filename, &stb) < 0)
 #endif
 #else
        if (stat(filename, &stb) < 0)
 #endif
@@ -647,7 +650,7 @@ writable(filename)
                        return FALSE;
                *p = '\0';
                if (safefile(filename, RealUid, RealGid, RealUserName,
                        return FALSE;
                *p = '\0';
                if (safefile(filename, RealUid, RealGid, RealUserName,
-                            SF_MUSTOWN, S_IWRITE|S_IEXEC) != 0)
+                            SFF_MUSTOWN, S_IWRITE|S_IEXEC) != 0)
                {
                        *p = '/';
                        return FALSE;
                {
                        *p = '/';
                        return FALSE;
@@ -692,7 +695,7 @@ writable(filename)
                printf("\teu/gid=%d/%d, st_u/gid=%d/%d\n",
                        euid, egid, stb.st_uid, stb.st_gid);
 
                printf("\teu/gid=%d/%d, st_u/gid=%d/%d\n",
                        euid, egid, stb.st_uid, stb.st_gid);
 
-       return safefile(filename, euid, egid, uname, SF_NOSLINK, S_IWRITE) == 0;
+       return safefile(filename, euid, egid, uname, flags, S_IWRITE) == 0;
 }
 \f/*
 **  INCLUDE -- handle :include: specification.
 }
 \f/*
 **  INCLUDE -- handle :include: specification.
@@ -737,7 +740,7 @@ include(fname, forwarding, ctladdr, sendq, e)
        gid_t savedgid, gid;
        char *uname;
        int rval = 0;
        gid_t savedgid, gid;
        char *uname;
        int rval = 0;
-       int sfflags = forwarding ? SF_MUSTOWN : 0;
+       int sfflags = forwarding ? SFF_MUSTOWN : SFF_ANYFILE;
        char buf[MAXLINE];
 
        if (tTd(27, 2))
        char buf[MAXLINE];
 
        if (tTd(27, 2))
index 23c4619..8ea892e 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)savemail.c 8.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)savemail.c 8.22 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -349,7 +349,7 @@ savemail(e)
                        }
 
                        strcpy(buf, "/usr/tmp/dead.letter");
                        }
 
                        strcpy(buf, "/usr/tmp/dead.letter");
-                       if (!writable(buf))
+                       if (!writable(buf, SFF_NOSLINK))
                        {
                                state = ESM_PANIC;
                                break;
                        {
                                state = ESM_PANIC;
                                break;
index cf0c5e2..1e7b59c 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)util.c     8.21 (Berkeley) %G%";
+static char sccsid[] = "@(#)util.c     8.22 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -439,8 +439,8 @@ int
 **             uname -- user name to compare against (used for group
 **                     sets).
 **             flags -- modifiers:
 **             uname -- user name to compare against (used for group
 **                     sets).
 **             flags -- modifiers:
-**                     SF_MUSTOWN -- "uid" must own this file.
-**                     SF_NOSLINK -- file cannot be a symbolic link.
+**                     SFF_MUSTOWN -- "uid" must own this file.
+**                     SFF_NOSLINK -- file cannot be a symbolic link.
 **             mode -- mode bits that must match.
 **
 **     Returns:
 **             mode -- mode bits that must match.
 **
 **     Returns:
@@ -522,8 +522,8 @@ safefile(fn, uid, gid, uname, flags, mode)
        }
 
 #ifdef HASLSTAT
        }
 
 #ifdef HASLSTAT
-       if ((bitset(SF_NOSLINK, flags) ? lstat(fn, &stbuf)
-                                      : stat(fn, &stbuf)) < 0)
+       if ((bitset(SFF_NOSLINK, flags) ? lstat(fn, &stbuf)
+                                       : stat(fn, &stbuf)) < 0)
 #else
        if (stat(fn, &stbuf) < 0)
 #endif
 #else
        if (stat(fn, &stbuf) < 0)
 #endif
@@ -538,7 +538,7 @@ safefile(fn, uid, gid, uname, flags, mode)
        }
 
 #ifdef S_ISLNK
        }
 
 #ifdef S_ISLNK
-       if (bitset(SF_NOSLINK, flags) && S_ISLNK(stbuf.st_mode))
+       if (bitset(SFF_NOSLINK, flags) && S_ISLNK(stbuf.st_mode))
        {
                if (tTd(54, 4))
                        printf("\t[mode %o]\tEPERM\n");
        {
                if (tTd(54, 4))
                        printf("\t[mode %o]\tEPERM\n");
@@ -574,7 +574,7 @@ safefile(fn, uid, gid, uname, flags, mode)
                printf("\t[uid %d, stat %o, mode %o] ",
                        stbuf.st_uid, stbuf.st_mode, mode);
        if ((stbuf.st_uid == uid || stbuf.st_uid == 0 ||
                printf("\t[uid %d, stat %o, mode %o] ",
                        stbuf.st_uid, stbuf.st_mode, mode);
        if ((stbuf.st_uid == uid || stbuf.st_uid == 0 ||
-            !bitset(SF_MUSTOWN, flags)) &&
+            !bitset(SFF_MUSTOWN, flags)) &&
            (stbuf.st_mode & mode) == mode)
        {
                if (tTd(54, 4))
            (stbuf.st_mode & mode) == mode)
        {
                if (tTd(54, 4))