diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2004-08-01 01:04:57 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2004-08-01 01:04:57 +0000 |
commit | 1fc446a819a244515d9461fa50d34ee191414d6f (patch) | |
tree | f6477ae85b00ee6d58b086b0d1d597dd9a403391 /contrib/sendmail/libsmutil/safefile.c | |
parent | 238623a0204c90e8d61dbde7b3b499a5036f2e5d (diff) | |
download | FreeBSD-src-1fc446a819a244515d9461fa50d34ee191414d6f.zip FreeBSD-src-1fc446a819a244515d9461fa50d34ee191414d6f.tar.gz |
Import sendmail 8.13.1
Diffstat (limited to 'contrib/sendmail/libsmutil/safefile.c')
-rw-r--r-- | contrib/sendmail/libsmutil/safefile.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/contrib/sendmail/libsmutil/safefile.c b/contrib/sendmail/libsmutil/safefile.c index aed40a0..c6cfb53 100644 --- a/contrib/sendmail/libsmutil/safefile.c +++ b/contrib/sendmail/libsmutil/safefile.c @@ -15,7 +15,7 @@ #include <sm/io.h> #include <sm/errstring.h> -SM_RCSID("@(#)$Id: safefile.c,v 8.124 2002/05/24 20:50:15 gshapiro Exp $") +SM_RCSID("@(#)$Id: safefile.c,v 8.127 2004/05/27 22:37:51 msk Exp $") /* @@ -304,7 +304,7 @@ safefile(fn, uid, gid, user, flags, mode, st) bitset(S_IXUSR|S_IXGRP|S_IXOTH, st->st_mode)) { if (tTd(44, 4)) - sm_dprintf("\t[exec bits %lo]\tE_SM_ISEXEC]\n", + sm_dprintf("\t[exec bits %lo]\tE_SM_ISEXEC\n", (unsigned long) st->st_mode); return E_SM_ISEXEC; } @@ -684,6 +684,9 @@ safeopen(fn, omode, cmode, sff) int cmode; long sff; { +#if !NOFTRUNCATE + bool truncate; +#endif /* !NOFTRUNCATE */ int rval; int fd; int smode; @@ -735,6 +738,12 @@ safeopen(fn, omode, cmode, sff) return -1; } +#if !NOFTRUNCATE + truncate = bitset(O_TRUNC, omode); + if (truncate) + omode &= ~O_TRUNC; +#endif /* !NOFTRUNCATE */ + fd = dfopen(fn, omode, cmode, sff); if (fd < 0) return fd; @@ -745,6 +754,22 @@ safeopen(fn, omode, cmode, sff) errno = E_SM_FILECHANGE; return -1; } + +#if !NOFTRUNCATE + if (truncate && + ftruncate(fd, (off_t) 0) < 0) + { + int save_errno; + + save_errno = errno; + syserr("554 5.3.0 cannot open: file %s could not be truncated", + fn); + (void) close(fd); + errno = save_errno; + return -1; + } +#endif /* !NOFTRUNCATE */ + return fd; } /* @@ -940,6 +965,9 @@ dfopen(filename, omode, cmode, sff) locktype = LOCK_EX; else locktype = LOCK_SH; + if (bitset(SFF_NBLOCK, sff)) + locktype |= LOCK_NB; + if (!lockfile(fd, filename, NULL, locktype)) { int save_errno = errno; |