improve error messages -- avoid "Error 0" syndrome
authorEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 11 Dec 1993 09:30:18 +0000 (01:30 -0800)
committerEric Allman <eric@ucbvax.Berkeley.EDU>
Sat, 11 Dec 1993 09:30:18 +0000 (01:30 -0800)
SCCS-vsn: usr.sbin/sendmail/src/recipient.c 8.28
SCCS-vsn: usr.sbin/sendmail/src/err.c 8.16

usr/src/usr.sbin/sendmail/src/err.c
usr/src/usr.sbin/sendmail/src/recipient.c

index 0eb94dd..f5a22f0 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)err.c      8.15 (Berkeley) %G%";
+static char sccsid[] = "@(#)err.c      8.16 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -430,8 +430,6 @@ errstring(errno)
        extern char *SmtpPhase;
 # endif /* SMTP */
 
        extern char *SmtpPhase;
 # endif /* SMTP */
 
-# ifdef DAEMON
-# ifdef ETIMEDOUT
        /*
        **  Handle special network error codes.
        **
        /*
        **  Handle special network error codes.
        **
@@ -440,6 +438,7 @@ errstring(errno)
 
        switch (errno)
        {
 
        switch (errno)
        {
+# if defined(DAEMON) && defined(ETIMEDOUT)
          case ETIMEDOUT:
          case ECONNRESET:
                (void) strcpy(buf, sys_errlist[errno]);
          case ETIMEDOUT:
          case ECONNRESET:
                (void) strcpy(buf, sys_errlist[errno]);
@@ -466,6 +465,7 @@ errstring(errno)
                        break;
                (void) sprintf(buf, "Connection refused by %s", CurHostName);
                return (buf);
                        break;
                (void) sprintf(buf, "Connection refused by %s", CurHostName);
                return (buf);
+# endif
 
          case EOPENTIMEOUT:
                return "Timeout on file open";
 
          case EOPENTIMEOUT:
                return "Timeout on file open";
@@ -483,9 +483,11 @@ errstring(errno)
          case NO_DATA + E_DNSBASE:
                return ("Name server: no data known for name");
 # endif
          case NO_DATA + E_DNSBASE:
                return ("Name server: no data known for name");
 # endif
+
+         case EPERM:
+               /* SunOS gives "Not owner" -- this is the POSIX message */
+               return "Operation not permitted";
        }
        }
-# endif
-# endif
 
        if (errno > 0 && errno < sys_nerr)
                return (sys_errlist[errno]);
 
        if (errno > 0 && errno < sys_nerr)
                return (sys_errlist[errno]);
index 6fc0268..77eb62f 100644 (file)
@@ -7,7 +7,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)recipient.c        8.27 (Berkeley) %G%";
+static char sccsid[] = "@(#)recipient.c        8.28 (Berkeley) %G%";
 #endif /* not lint */
 
 # include "sendmail.h"
 #endif /* not lint */
 
 # include "sendmail.h"
@@ -647,16 +647,15 @@ writable(filename, flags)
                /* file does not exist -- see if directory is safe */
                p = strrchr(filename, '/');
                if (p == NULL)
                /* file does not exist -- see if directory is safe */
                p = strrchr(filename, '/');
                if (p == NULL)
-                       return FALSE;
-               *p = '\0';
-               if (safefile(filename, RealUid, RealGid, RealUserName,
-                            SFF_MUSTOWN, S_IWRITE|S_IEXEC) != 0)
                {
                {
-                       *p = '/';
+                       errno = ENOTDIR;
                        return FALSE;
                }
                        return FALSE;
                }
+               *p = '\0';
+               errno = safefile(filename, RealUid, RealGid, RealUserName,
+                                SFF_MUSTOWN, S_IWRITE|S_IEXEC);
                *p = '/';
                *p = '/';
-               return TRUE;
+               return errno == 0;
        }
 
        /*
        }
 
        /*
@@ -667,6 +666,7 @@ writable(filename, flags)
        {
                if (tTd(29, 5))
                        printf("failed (mode %o: x bits)\n", stb.st_mode);
        {
                if (tTd(29, 5))
                        printf("failed (mode %o: x bits)\n", stb.st_mode);
+               errno = EPERM;
                return (FALSE);
        }
 
                return (FALSE);
        }
 
@@ -695,7 +695,8 @@ writable(filename, flags)
                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, flags, S_IWRITE) == 0;
+       errno = safefile(filename, euid, egid, uname, flags, S_IWRITE);
+       return errno == 0;
 }
 \f/*
 **  INCLUDE -- handle :include: specification.
 }
 \f/*
 **  INCLUDE -- handle :include: specification.