diff options
author | gshapiro <gshapiro@FreeBSD.org> | 2002-02-17 21:56:45 +0000 |
---|---|---|
committer | gshapiro <gshapiro@FreeBSD.org> | 2002-02-17 21:56:45 +0000 |
commit | 8449595fe97f4474b9b9a7e4edee1ef35dcff393 (patch) | |
tree | e7a33b132264d449a512ddf4a8685df097669c1d /contrib/sendmail/libsmutil | |
parent | 289b381b31415647269c7520d881017e2dcb27f1 (diff) | |
download | FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.zip FreeBSD-src-8449595fe97f4474b9b9a7e4edee1ef35dcff393.tar.gz |
Import sendmail 8.12.2
Diffstat (limited to 'contrib/sendmail/libsmutil')
-rw-r--r-- | contrib/sendmail/libsmutil/Makefile.m4 | 3 | ||||
-rw-r--r-- | contrib/sendmail/libsmutil/cf.c | 71 | ||||
-rw-r--r-- | contrib/sendmail/libsmutil/debug.c | 31 | ||||
-rw-r--r-- | contrib/sendmail/libsmutil/err.c | 63 | ||||
-rw-r--r-- | contrib/sendmail/libsmutil/lockfile.c | 23 | ||||
-rw-r--r-- | contrib/sendmail/libsmutil/safefile.c | 245 | ||||
-rw-r--r-- | contrib/sendmail/libsmutil/snprintf.c | 386 |
7 files changed, 319 insertions, 503 deletions
diff --git a/contrib/sendmail/libsmutil/Makefile.m4 b/contrib/sendmail/libsmutil/Makefile.m4 index 93a344c..5348e33 100644 --- a/contrib/sendmail/libsmutil/Makefile.m4 +++ b/contrib/sendmail/libsmutil/Makefile.m4 @@ -1,12 +1,13 @@ include(confBUILDTOOLSDIR`/M4/switch.m4') +define(`confREQUIRE_LIBSM', `true') # sendmail dir SMSRCDIR= ifdef(`confSMSRCDIR', `confSMSRCDIR', `${SRCDIR}/sendmail') PREPENDDEF(`confENVDEF', `confMAPDEF') PREPENDDEF(`confINCDIRS', `-I${SMSRCDIR} ') bldPRODUCT_START(`library', `libsmutil') -define(`bldSOURCES', `debug.c errstring.c lockfile.c safefile.c snprintf.c strl.c ') +define(`bldSOURCES', `debug.c err.c lockfile.c safefile.c snprintf.c cf.c ') APPENDDEF(`confENVDEF', `-DNOT_SENDMAIL') bldPRODUCT_END diff --git a/contrib/sendmail/libsmutil/cf.c b/contrib/sendmail/libsmutil/cf.c new file mode 100644 index 0000000..a1f6ba4 --- /dev/null +++ b/contrib/sendmail/libsmutil/cf.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2000-2001 Sendmail, Inc. and its suppliers. + * All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + * + */ + +#include <sendmail.h> +SM_RCSID("@(#)$Id: cf.c,v 8.16 2001/09/11 04:04:55 gshapiro Exp $") +#include <sendmail/pathnames.h> + +/* +** GETCFNAME -- return the name of the .cf file to use. +** +** Some systems (e.g., NeXT) determine this dynamically. +** +** For others: returns submit.cf or sendmail.cf depending +** on the modes. +** +** Parameters: +** opmode -- operation mode. +** submitmode -- submit mode. +** cftype -- may request a certain cf file. +** conffile -- if set, return it. +** +** Returns: +** name of .cf file. +*/ + +char * +getcfname(opmode, submitmode, cftype, conffile) + int opmode; + int submitmode; + int cftype; + char *conffile; +{ + + if (conffile != NULL) + return conffile; + +#if NETINFO + { + char *cflocation; + + cflocation = ni_propval("/locations", NULL, "sendmail", + "sendmail.cf", '\0'); + if (cflocation != NULL) + return cflocation; + } +#endif /* NETINFO */ + + if (cftype == SM_GET_SUBMIT_CF || + ((submitmode != SUBMIT_UNKNOWN || + opmode == MD_DELIVER || + opmode == MD_ARPAFTP || + opmode == MD_SMTP) && + cftype != SM_GET_SENDMAIL_CF)) + { + struct stat sbuf; + static char cf[PATH_MAX]; + + (void) sm_strlcpyn(cf, sizeof cf, 2, _DIR_SENDMAILCF, + "submit.cf"); + if (cftype == SM_GET_SUBMIT_CF || stat(cf, &sbuf) == 0) + return cf; + } + return _PATH_SENDMAILCF; +} diff --git a/contrib/sendmail/libsmutil/debug.c b/contrib/sendmail/libsmutil/debug.c index bc32b66..2c3b328 100644 --- a/contrib/sendmail/libsmutil/debug.c +++ b/contrib/sendmail/libsmutil/debug.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1999 Sendmail, Inc. and its suppliers. + * Copyright (c) 1999-2001 Sendmail, Inc. and its suppliers. * All rights reserved. * * By using this file, you agree to the terms and conditions set @@ -8,33 +8,8 @@ * */ -#ifndef lint -static char id[] = "@(#)$Id: debug.c,v 8.2 1999/07/26 04:04:09 gshapiro Exp $"; -#endif /* ! lint */ - #include <sendmail.h> -u_char tTdvect[100]; /* trace vector */ - -#if _FFR_DPRINTF_ -void -/*VARARGS1*/ -#ifdef __STDC__ -dprintf(const char *fmt, ...) -#else /* __STDC__ */ -dprintf(fmt, va_alist) - const char *fmt; - va_dcl -#endif /* __STDC__ */ -{ - VA_LOCAL_DECL; - - (void) vfprintf(stdout, fmt, ap); -} +SM_RCSID("@(#)$Id: debug.c,v 8.9 2001/09/11 04:04:55 gshapiro Exp $") -int -dflush() -{ - return fflush(stdout); -} -#endif /* _FFR_DPRINTF_ */ +unsigned char tTdvect[100]; /* trace vector */ diff --git a/contrib/sendmail/libsmutil/err.c b/contrib/sendmail/libsmutil/err.c new file mode 100644 index 0000000..0ad52a4 --- /dev/null +++ b/contrib/sendmail/libsmutil/err.c @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2001 Sendmail, Inc. and its suppliers. + * All rights reserved. + * + * By using this file, you agree to the terms and conditions set + * forth in the LICENSE file which can be found at the top level of + * the sendmail distribution. + * + */ + +#include <sendmail.h> + +SM_RCSID("@(#)$Id: err.c,v 8.5 2001/09/11 04:04:55 gshapiro Exp $") + +#include <ctype.h> + +/*VARARGS1*/ +void +#ifdef __STDC__ +message(const char *msg, ...) +#else /* __STDC__ */ +message(msg, va_alist) + const char *msg; + va_dcl +#endif /* __STDC__ */ +{ + const char *m; + SM_VA_LOCAL_DECL + + m = msg; + if (isascii(m[0]) && isdigit(m[0]) && + isascii(m[1]) && isdigit(m[1]) && + isascii(m[2]) && isdigit(m[2]) && m[3] == ' ') + m += 4; + SM_VA_START(ap, msg); + (void) vfprintf(stderr, m, ap); + SM_VA_END(ap); + (void) fprintf(stderr, "\n"); +} + +/*VARARGS1*/ +void +#ifdef __STDC__ +syserr(const char *msg, ...) +#else /* __STDC__ */ +syserr(msg, va_alist) + const char *msg; + va_dcl +#endif /* __STDC__ */ +{ + const char *m; + SM_VA_LOCAL_DECL + + m = msg; + if (isascii(m[0]) && isdigit(m[0]) && + isascii(m[1]) && isdigit(m[1]) && + isascii(m[2]) && isdigit(m[2]) && m[3] == ' ') + m += 4; + SM_VA_START(ap, msg); + (void) vfprintf(stderr, m, ap); + SM_VA_END(ap); + (void) fprintf(stderr, "\n"); +} diff --git a/contrib/sendmail/libsmutil/lockfile.c b/contrib/sendmail/libsmutil/lockfile.c index 8c2dc6e..5eca360 100644 --- a/contrib/sendmail/libsmutil/lockfile.c +++ b/contrib/sendmail/libsmutil/lockfile.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1998-2000 Sendmail, Inc. and its suppliers. + * Copyright (c) 1998-2001 Sendmail, Inc. and its suppliers. * All rights reserved. * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. * Copyright (c) 1988, 1993 @@ -11,13 +11,12 @@ * */ -#ifndef lint -static char id[] = "@(#)$Id: lockfile.c,v 8.3.16.11 2000/11/16 02:54:28 geir Exp $"; -#endif /* ! lint */ - #include <sendmail.h> -/* +SM_RCSID("@(#)$Id: lockfile.c,v 8.19 2001/09/11 04:04:55 gshapiro Exp $") + + +/* ** LOCKFILE -- lock a file using flock or (shudder) fcntl locking ** ** Parameters: @@ -30,8 +29,8 @@ static char id[] = "@(#)$Id: lockfile.c,v 8.3.16.11 2000/11/16 02:54:28 geir Exp ** LOCK_UN -- unlock. ** ** Returns: -** TRUE if the lock was acquired. -** FALSE otherwise. +** true if the lock was acquired. +** false otherwise. */ bool @@ -59,7 +58,7 @@ lockfile(fd, filename, ext, type) action = F_SETLKW; if (fcntl(fd, action, &lfd) >= 0) - return TRUE; + return true; /* ** On SunOS, if you are testing using -oQ/tmp/mqueue or @@ -71,14 +70,14 @@ lockfile(fd, filename, ext, type) */ if (errno == EINVAL) - return TRUE; + return true; #else /* !HASFLOCK */ if (flock(fd, type) >= 0) - return TRUE; + return true; #endif /* !HASFLOCK */ - return FALSE; + return false; } diff --git a/contrib/sendmail/libsmutil/safefile.c b/contrib/sendmail/libsmutil/safefile.c index 3a757f3..c2e2102 100644 --- a/contrib/sendmail/libsmutil/safefile.c +++ b/contrib/sendmail/libsmutil/safefile.c @@ -11,14 +11,14 @@ * */ -#ifndef lint -static char id[] = "@(#)$Id: safefile.c,v 8.81.4.10 2001/07/20 04:19:36 gshapiro Exp $"; -#endif /* ! lint */ - #include <sendmail.h> +#include <sm/io.h> +#include <sm/errstring.h> + +SM_RCSID("@(#)$Id: safefile.c,v 8.121 2001/10/11 21:46:13 gshapiro Exp $") -/* +/* ** SAFEFILE -- return 0 if a file exists and is safe for a user. ** ** Parameters: @@ -61,18 +61,18 @@ safefile(fn, uid, gid, user, flags, mode, st) char fbuf[MAXPATHLEN + 1]; if (tTd(44, 4)) - dprintf("safefile(%s, uid=%d, gid=%d, flags=%lx, mode=%o):\n", + sm_dprintf("safefile(%s, uid=%d, gid=%d, flags=%lx, mode=%o):\n", fn, (int) uid, (int) gid, flags, mode); errno = 0; - if (st == NULL) - st = &fstbuf; - if (strlcpy(fbuf, fn, sizeof fbuf) >= sizeof fbuf) + if (sm_strlcpy(fbuf, fn, sizeof fbuf) >= sizeof fbuf) { if (tTd(44, 4)) - dprintf("\tpathname too long\n"); + sm_dprintf("\tpathname too long\n"); return ENAMETOOLONG; } fn = fbuf; + if (st == NULL) + st = &fstbuf; /* ignore SFF_SAFEDIRPATH if we are debugging */ if (RealUid != 0 && RunAsUid == RealUid) @@ -93,7 +93,7 @@ safefile(fn, uid, gid, user, flags, mode, st) S_ISREG(st->st_mode)) { /* - ** If final file is setuid, run as the owner of that + ** If final file is set-user-ID, run as the owner of that ** file. Gotta be careful not to reveal anything too ** soon here! */ @@ -139,7 +139,7 @@ safefile(fn, uid, gid, user, flags, mode, st) if (ret == 0) { /* directory is safe */ - checkpath = FALSE; + checkpath = false; } else { @@ -149,7 +149,7 @@ safefile(fn, uid, gid, user, flags, mode, st) { ret = errno; if (tTd(44, 4)) - dprintf("\t%s\n", errstring(ret)); + sm_dprintf("\t%s\n", sm_errstring(ret)); return ret; } # endif /* HASLSTAT */ @@ -188,7 +188,7 @@ safefile(fn, uid, gid, user, flags, mode, st) char *dir = fn; if (tTd(44, 4)) - dprintf("\t%s\n", errstring(ret)); + sm_dprintf("\t%s\n", sm_errstring(ret)); errno = 0; if (!bitset(SFF_CREAT, flags) || file_errno != ENOENT) @@ -206,6 +206,7 @@ safefile(fn, uid, gid, user, flags, mode, st) { int md = S_IWRITE|S_IEXEC; + ret = 0; if (stbuf.st_uid == uid) /* EMPTY */ ; @@ -237,13 +238,15 @@ safefile(fn, uid, gid, user, flags, mode, st) md >>= 3; } if ((stbuf.st_mode & md) != md) - errno = EACCES; + ret = errno = EACCES; } - ret = errno; + else + ret = errno; if (tTd(44, 4)) - dprintf("\t[final dir %s uid %d mode %lo] %s\n", - dir, (int) stbuf.st_uid, (u_long) stbuf.st_mode, - errstring(ret)); + sm_dprintf("\t[final dir %s uid %d mode %lo] %s\n", + dir, (int) stbuf.st_uid, + (unsigned long) stbuf.st_mode, + sm_errstring(ret)); if (p != NULL) *p = '/'; st->st_mode = ST_MODE_NOFILE; @@ -254,46 +257,46 @@ safefile(fn, uid, gid, user, flags, mode, st) if (bitset(SFF_NOSLINK, flags) && S_ISLNK(st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[slink mode %lo]\tE_SM_NOSLINK\n", - (u_long) st->st_mode); + sm_dprintf("\t[slink mode %lo]\tE_SM_NOSLINK\n", + (unsigned long) st->st_mode); return E_SM_NOSLINK; } # endif /* S_ISLNK */ if (bitset(SFF_REGONLY, flags) && !S_ISREG(st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[non-reg mode %lo]\tE_SM_REGONLY\n", - (u_long) st->st_mode); + sm_dprintf("\t[non-reg mode %lo]\tE_SM_REGONLY\n", + (unsigned long) st->st_mode); return E_SM_REGONLY; } if (bitset(SFF_NOGWFILES, flags) && bitset(S_IWGRP, st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[write bits %lo]\tE_SM_GWFILE\n", - (u_long) st->st_mode); + sm_dprintf("\t[write bits %lo]\tE_SM_GWFILE\n", + (unsigned long) st->st_mode); return E_SM_GWFILE; } if (bitset(SFF_NOWWFILES, flags) && bitset(S_IWOTH, st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[write bits %lo]\tE_SM_WWFILE\n", - (u_long) st->st_mode); + sm_dprintf("\t[write bits %lo]\tE_SM_WWFILE\n", + (unsigned long) st->st_mode); return E_SM_WWFILE; } if (bitset(SFF_NOGRFILES, flags) && bitset(S_IRGRP, st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[read bits %lo]\tE_SM_GRFILE\n", - (u_long) st->st_mode); + sm_dprintf("\t[read bits %lo]\tE_SM_GRFILE\n", + (unsigned long) st->st_mode); return E_SM_GRFILE; } if (bitset(SFF_NOWRFILES, flags) && bitset(S_IROTH, st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[read bits %lo]\tE_SM_WRFILE\n", - (u_long) st->st_mode); + sm_dprintf("\t[read bits %lo]\tE_SM_WRFILE\n", + (unsigned long) st->st_mode); return E_SM_WRFILE; } if (!bitset(SFF_EXECOK, flags) && @@ -301,14 +304,14 @@ safefile(fn, uid, gid, user, flags, mode, st) bitset(S_IXUSR|S_IXGRP|S_IXOTH, st->st_mode)) { if (tTd(44, 4)) - dprintf("\t[exec bits %lo]\tE_SM_ISEXEC]\n", - (u_long) st->st_mode); + sm_dprintf("\t[exec bits %lo]\tE_SM_ISEXEC]\n", + (unsigned long) st->st_mode); return E_SM_ISEXEC; } if (bitset(SFF_NOHLINK, flags) && st->st_nlink != 1) { if (tTd(44, 4)) - dprintf("\t[link count %d]\tE_SM_NOHLINK\n", + sm_dprintf("\t[link count %d]\tE_SM_NOHLINK\n", (int) st->st_nlink); return E_SM_NOHLINK; } @@ -348,23 +351,23 @@ safefile(fn, uid, gid, user, flags, mode, st) mode >>= 3; } if (tTd(44, 4)) - dprintf("\t[uid %d, nlink %d, stat %lo, mode %lo] ", + sm_dprintf("\t[uid %d, nlink %d, stat %lo, mode %lo] ", (int) st->st_uid, (int) st->st_nlink, - (u_long) st->st_mode, (u_long) mode); + (unsigned long) st->st_mode, (unsigned long) mode); if ((st->st_uid == uid || st->st_uid == 0 || st->st_uid == TrustedUid || !bitset(SFF_MUSTOWN, flags)) && (st->st_mode & mode) == mode) { if (tTd(44, 4)) - dprintf("\tOK\n"); + sm_dprintf("\tOK\n"); return 0; } if (tTd(44, 4)) - dprintf("\tEACCES\n"); + sm_dprintf("\tEACCES\n"); return EACCES; } -/* +/* ** SAFEDIRPATH -- check to make sure a path to a directory is safe ** ** Safe means not writable and owned by the right folks. @@ -410,19 +413,22 @@ safedirpath(fn, uid, gid, user, flags, level, offset) if (level > MAXSYMLINKS) return ELOOP; + if (level < 0 || offset < 0 || offset > strlen(fn)) + return EINVAL; + /* special case root directory */ if (*fn == '\0') fn = "/"; if (tTd(44, 4)) - dprintf("safedirpath(%s, uid=%ld, gid=%ld, flags=%lx, level=%d, offset=%d):\n", + sm_dprintf("safedirpath(%s, uid=%ld, gid=%ld, flags=%lx, level=%d, offset=%d):\n", fn, (long) uid, (long) gid, flags, level, offset); if (!bitnset(DBS_GROUPWRITABLEDIRPATHSAFE, DontBlameSendmail)) mode |= S_IWGRP; /* Make a modifiable copy of the filename */ - if (strlcpy(s, fn, sizeof s) >= sizeof s) + if (sm_strlcpy(s, fn, sizeof s) >= sizeof s) return EINVAL; p = s + offset; @@ -463,7 +469,7 @@ safedirpath(fn, uid, gid, user, flags, level, offset) continue; if (tTd(44, 20)) - dprintf("\t[dir %s]\n", s); + sm_dprintf("\t[dir %s]\n", s); # if HASLSTAT ret = lstat(s, &stbuf); @@ -537,25 +543,28 @@ safedirpath(fn, uid, gid, user, flags, level, offset) { *sptr = '\0'; offset = sptr + 1 - s; - if ((strlen(s) + 1 + - strlen(buf) + 1) > sizeof fullbuf) + if (sm_strlcpyn(fullbuf, + sizeof fullbuf, 2, + s, "/") >= + sizeof fullbuf || + sm_strlcat(fullbuf, buf, + sizeof fullbuf) >= + sizeof fullbuf) { ret = EINVAL; break; } - snprintf(fullbuf, sizeof fullbuf, - "%s/%s", s, buf); *sptr = '/'; } else { - if (strlen(buf) + 1 > sizeof fullbuf) + if (sm_strlcpy(fullbuf, buf, + sizeof fullbuf) >= + sizeof fullbuf) { ret = EINVAL; break; } - (void) strlcpy(fullbuf, buf, - sizeof fullbuf); } target = fullbuf; } @@ -577,8 +586,8 @@ safedirpath(fn, uid, gid, user, flags, level, offset) bitset(mode, stbuf.st_mode)) { if (tTd(44, 4)) - dprintf("\t[dir %s] mode %lo ", - s, (u_long) stbuf.st_mode); + sm_dprintf("\t[dir %s] mode %lo ", + s, (unsigned long) stbuf.st_mode); if (bitset(SFF_SAFEDIRPATH, flags)) { if (bitset(S_IWOTH, stbuf.st_mode)) @@ -586,11 +595,11 @@ safedirpath(fn, uid, gid, user, flags, level, offset) else ret = E_SM_GWDIR; if (tTd(44, 4)) - dprintf("FATAL\n"); + sm_dprintf("FATAL\n"); break; } if (tTd(44, 4)) - dprintf("WARNING\n"); + sm_dprintf("WARNING\n"); if (Verbose > 1) message("051 WARNING: %s writable directory %s", bitset(S_IWOTH, stbuf.st_mode) @@ -643,11 +652,11 @@ safedirpath(fn, uid, gid, user, flags, level, offset) } } if (tTd(44, 4)) - dprintf("\t[dir %s] %s\n", fn, - ret == 0 ? "OK" : errstring(ret)); + sm_dprintf("\t[dir %s] %s\n", fn, + ret == 0 ? "OK" : sm_errstring(ret)); return ret; } -/* +/* ** SAFEOPEN -- do a file open with extra checking ** ** Parameters: @@ -673,8 +682,8 @@ safeopen(fn, omode, cmode, sff) struct stat stb; if (tTd(44, 10)) - printf("safeopen: fn=%s, omode=%x, cmode=%x, sff=%lx\n", - fn, omode, cmode, sff); + sm_dprintf("safeopen: fn=%s, omode=%x, cmode=%x, sff=%lx\n", + fn, omode, cmode, sff); if (bitset(O_CREAT, omode)) sff |= SFF_CREAT; @@ -730,7 +739,83 @@ safeopen(fn, omode, cmode, sff) } return fd; } -/* +/* +** SAFEFOPEN -- do a file open with extra checking +** +** Parameters: +** fn -- the file name to open. +** omode -- the open-style mode flags. +** cmode -- the create-style mode flags. +** sff -- safefile flags. +** +** Returns: +** Same as fopen. +*/ + +SM_FILE_T * +safefopen(fn, omode, cmode, sff) + char *fn; + int omode; + int cmode; + long sff; +{ + int fd; + int save_errno; + SM_FILE_T *fp; + int fmode; + + switch (omode & O_ACCMODE) + { + case O_RDONLY: + fmode = SM_IO_RDONLY; + break; + + case O_WRONLY: + if (bitset(O_APPEND, omode)) + fmode = SM_IO_APPEND; + else + fmode = SM_IO_WRONLY; + break; + + case O_RDWR: + if (bitset(O_TRUNC, omode)) + fmode = SM_IO_RDWRTR; + else if (bitset(O_APPEND, omode)) + fmode = SM_IO_APPENDRW; + else + fmode = SM_IO_RDWR; + break; + + default: + syserr("554 5.3.5 safefopen: unknown omode %o", omode); + fmode = 0; + } + fd = safeopen(fn, omode, cmode, sff); + if (fd < 0) + { + save_errno = errno; + if (tTd(44, 10)) + sm_dprintf("safefopen: safeopen failed: %s\n", + sm_errstring(errno)); + errno = save_errno; + return NULL; + } + fp = sm_io_open(SmFtStdiofd, SM_TIME_DEFAULT, + (void *) &fd, fmode, NULL); + if (fp != NULL) + return fp; + + save_errno = errno; + if (tTd(44, 10)) + { + sm_dprintf("safefopen: fdopen(%s, %d) failed: omode=%x, sff=%lx, err=%s\n", + fn, fmode, omode, sff, sm_errstring(errno)); + } + (void) close(fd); + errno = save_errno; + return NULL; +} +/* ** FILECHANGED -- check to see if file changed after being opened ** ** Parameters: @@ -739,8 +824,8 @@ safeopen(fn, omode, cmode, sff) ** stb -- stat structure from before open. ** ** Returns: -** TRUE -- if a problem was detected. -** FALSE -- if this file is still the same. +** true -- if a problem was detected. +** false -- if this file is still the same. */ bool @@ -756,13 +841,13 @@ filechanged(fn, fd, stb) # if HASLSTAT && BOGUS_O_EXCL /* only necessary if exclusive open follows symbolic links */ if (lstat(fn, stb) < 0 || stb->st_nlink != 1) - return TRUE; + return true; # else /* HASLSTAT && BOGUS_O_EXCL */ - return FALSE; + return false; # endif /* HASLSTAT && BOGUS_O_EXCL */ } if (fstat(fd, &sta) < 0) - return TRUE; + return true; if (sta.st_nlink != stb->st_nlink || sta.st_dev != stb->st_dev || @@ -775,37 +860,29 @@ filechanged(fn, fd, stb) { if (tTd(44, 8)) { - dprintf("File changed after opening:\n"); - dprintf(" nlink = %ld/%ld\n", + sm_dprintf("File changed after opening:\n"); + sm_dprintf(" nlink = %ld/%ld\n", (long) stb->st_nlink, (long) sta.st_nlink); - dprintf(" dev = %ld/%ld\n", + sm_dprintf(" dev = %ld/%ld\n", (long) stb->st_dev, (long) sta.st_dev); - if (sizeof sta.st_ino > sizeof (long)) - { - dprintf(" ino = %s/", - quad_to_string(stb->st_ino)); - dprintf("%s\n", - quad_to_string(sta.st_ino)); - } - else - dprintf(" ino = %lu/%lu\n", - (unsigned long) stb->st_ino, - (unsigned long) sta.st_ino); + sm_dprintf(" ino = %llu/%llu\n", + (ULONGLONG_T) stb->st_ino, + (ULONGLONG_T) sta.st_ino); # if HAS_ST_GEN - dprintf(" gen = %ld/%ld\n", + sm_dprintf(" gen = %ld/%ld\n", (long) stb->st_gen, (long) sta.st_gen); # endif /* HAS_ST_GEN */ - dprintf(" uid = %ld/%ld\n", + sm_dprintf(" uid = %ld/%ld\n", (long) stb->st_uid, (long) sta.st_uid); - dprintf(" gid = %ld/%ld\n", + sm_dprintf(" gid = %ld/%ld\n", (long) stb->st_gid, (long) sta.st_gid); } - return TRUE; + return true; } - return FALSE; + return false; } -/* +/* ** DFOPEN -- determined file open ** ** This routine has the semantics of open, except that it will diff --git a/contrib/sendmail/libsmutil/snprintf.c b/contrib/sendmail/libsmutil/snprintf.c index 7a2aabc..ff3aa3b 100644 --- a/contrib/sendmail/libsmutil/snprintf.c +++ b/contrib/sendmail/libsmutil/snprintf.c @@ -11,380 +11,11 @@ * */ -#ifndef lint -static char id[] = "@(#)$Id: snprintf.c,v 8.27.16.4 2001/07/20 04:19:37 gshapiro Exp $"; -#endif /* ! lint */ - #include <sendmail.h> -/* -** SNPRINTF, VSNPRINT -- counted versions of printf -** -** These versions have been grabbed off the net. They have been -** cleaned up to compile properly and support for .precision and -** %lx has been added. -*/ - -/************************************************************** - * Original: - * Patrick Powell Tue Apr 11 09:48:21 PDT 1995 - * A bombproof version of doprnt (sm_dopr) included. - * Sigh. This sort of thing is always nasty do deal with. Note that - * the version here does not include floating point... - * - * snprintf() is used instead of sprintf() as it does limit checks - * for string length. This covers a nasty loophole. - * - * The other functions are there to prevent NULL pointers from - * causing nast effects. - **************************************************************/ - -/*static char _id[] = "$OrigId: snprintf.c,v 1.2 1995/10/09 11:19:47 roberto Exp $";*/ -void sm_dopr(); -char *DoprEnd; -int SnprfOverflow; - -#if !HASSNPRINTF && !SNPRINTF_IS_BROKEN -# define sm_snprintf snprintf -# ifndef luna2 -# define sm_vsnprintf vsnprintf -extern int vsnprintf __P((char *, size_t, const char *, va_list)); -# endif /* ! luna2 */ -#endif /* !HASSNPRINTF && !SNPRINTF_IS_BROKEN */ - -/* VARARGS3 */ -int -# ifdef __STDC__ -sm_snprintf(char *str, size_t count, const char *fmt, ...) -# else /* __STDC__ */ -sm_snprintf(str, count, fmt, va_alist) - char *str; - size_t count; - const char *fmt; - va_dcl -# endif /* __STDC__ */ -{ - int len; - VA_LOCAL_DECL - - VA_START(fmt); - len = sm_vsnprintf(str, count, fmt, ap); - VA_END; - return len; -} - -int -sm_vsnprintf(str, count, fmt, args) - char *str; - size_t count; - const char *fmt; - va_list args; -{ - str[0] = 0; - DoprEnd = str + count - 1; - SnprfOverflow = 0; - sm_dopr( str, fmt, args ); - if (count > 0) - DoprEnd[0] = 0; - if (SnprfOverflow > 0 && tTd(57, 2)) - dprintf("\nvsnprintf overflow, len = %ld, str = %s", - (long) count, shortenstring(str, MAXSHORTSTR)); - return strlen(str) + SnprfOverflow; -} +SM_RCSID("@(#)$Id: snprintf.c,v 8.44 2001/09/11 04:04:56 gshapiro Exp $") /* - * sm_dopr(): poor man's version of doprintf - */ - -void fmtstr __P((char *value, int ljust, int len, int zpad, int maxwidth)); -void fmtnum __P((long value, int base, int dosign, int ljust, int len, int zpad)); -void dostr __P(( char * , int )); -char *output; -void dopr_outch __P(( int c )); -int SyslogErrno; - -void -sm_dopr( buffer, format, args ) - char *buffer; - const char *format; - va_list args; -{ - int ch; - long value; - int longflag = 0; - int pointflag = 0; - int maxwidth = 0; - char *strvalue; - int ljust; - int len; - int zpad; -#if !HASSTRERROR && !defined(ERRLIST_PREDEFINED) - extern char *sys_errlist[]; - extern int sys_nerr; -#endif /* !HASSTRERROR && !defined(ERRLIST_PREDEFINED) */ - - - output = buffer; - while( (ch = *format++) != '\0' ){ - switch( ch ){ - case '%': - ljust = len = zpad = maxwidth = 0; - longflag = pointflag = 0; - nextch: - ch = *format++; - switch( ch ){ - case 0: - dostr( "**end of format**" , 0); - return; - case '-': ljust = 1; goto nextch; - case '0': /* set zero padding if len not set */ - if(len==0 && !pointflag) zpad = '0'; - /* FALLTHROUGH */ - case '1': case '2': case '3': - case '4': case '5': case '6': - case '7': case '8': case '9': - if (pointflag) - maxwidth = maxwidth*10 + ch - '0'; - else - len = len*10 + ch - '0'; - goto nextch; - case '*': - if (pointflag) - maxwidth = va_arg( args, int ); - else - len = va_arg( args, int ); - goto nextch; - case '.': pointflag = 1; goto nextch; - case 'l': longflag = 1; goto nextch; - case 'u': case 'U': - /*fmtnum(value,base,dosign,ljust,len,zpad) */ - if( longflag ){ - value = va_arg( args, long ); - } else { - value = va_arg( args, int ); - } - fmtnum( value, 10,0, ljust, len, zpad ); break; - case 'o': case 'O': - /*fmtnum(value,base,dosign,ljust,len,zpad) */ - if( longflag ){ - value = va_arg( args, long ); - } else { - value = va_arg( args, int ); - } - fmtnum( value, 8,0, ljust, len, zpad ); break; - case 'd': case 'D': - if( longflag ){ - value = va_arg( args, long ); - } else { - value = va_arg( args, int ); - } - fmtnum( value, 10,1, ljust, len, zpad ); break; - case 'x': - if( longflag ){ - value = va_arg( args, long ); - } else { - value = va_arg( args, int ); - } - fmtnum( value, 16,0, ljust, len, zpad ); break; - case 'X': - if( longflag ){ - value = va_arg( args, long ); - } else { - value = va_arg( args, int ); - } - fmtnum( value,-16,0, ljust, len, zpad ); break; - case 's': - strvalue = va_arg( args, char *); - if (maxwidth > 0 || !pointflag) { - if (pointflag && len > maxwidth) - len = maxwidth; /* Adjust padding */ - fmtstr( strvalue,ljust,len,zpad, maxwidth); - } - break; - case 'c': - ch = va_arg( args, int ); - dopr_outch( ch ); break; - case 'm': -#if HASSTRERROR - dostr(strerror(SyslogErrno), 0); -#else /* HASSTRERROR */ - if (SyslogErrno < 0 || SyslogErrno >= sys_nerr) - { - dostr("Error ", 0); - fmtnum(SyslogErrno, 10, 0, 0, 0, 0); - } - else - dostr((char *)sys_errlist[SyslogErrno], 0); -#endif /* HASSTRERROR */ - break; - - case '%': dopr_outch( ch ); continue; - default: - dostr( "???????" , 0); - } - break; - default: - dopr_outch( ch ); - break; - } - } - *output = 0; -} - -void -fmtstr( value, ljust, len, zpad, maxwidth ) - char *value; - int ljust, len, zpad, maxwidth; -{ - int padlen, strleng; /* amount to pad */ - - if( value == 0 ){ - value = "<NULL>"; - } - for( strleng = 0; value[strleng]; ++ strleng ); /* strlen */ - if (strleng > maxwidth && maxwidth) - strleng = maxwidth; - padlen = len - strleng; - if( padlen < 0 ) padlen = 0; - if( ljust ) padlen = -padlen; - while( padlen > 0 ) { - dopr_outch( ' ' ); - --padlen; - } - dostr( value, maxwidth ); - while( padlen < 0 ) { - dopr_outch( ' ' ); - ++padlen; - } -} - -void -fmtnum( value, base, dosign, ljust, len, zpad ) - long value; - int base, dosign, ljust, len, zpad; -{ - int signvalue = 0; - unsigned long uvalue; - char convert[20]; - int place = 0; - int padlen = 0; /* amount to pad */ - int caps = 0; - - /* DEBUGP(("value 0x%x, base %d, dosign %d, ljust %d, len %d, zpad %d\n", - value, base, dosign, ljust, len, zpad )); */ - uvalue = value; - if( dosign ){ - if( value < 0 ) { - signvalue = '-'; - uvalue = -value; - } - } - if( base < 0 ){ - caps = 1; - base = -base; - } - do{ - convert[place++] = - (caps? "0123456789ABCDEF":"0123456789abcdef") - [uvalue % (unsigned)base ]; - uvalue = (uvalue / (unsigned)base ); - }while(uvalue); - convert[place] = 0; - padlen = len - place; - if( padlen < 0 ) padlen = 0; - if( ljust ) padlen = -padlen; - /* DEBUGP(( "str '%s', place %d, sign %c, padlen %d\n", - convert,place,signvalue,padlen)); */ - if( zpad && padlen > 0 ){ - if( signvalue ){ - dopr_outch( signvalue ); - --padlen; - signvalue = 0; - } - while( padlen > 0 ){ - dopr_outch( zpad ); - --padlen; - } - } - while( padlen > 0 ) { - dopr_outch( ' ' ); - --padlen; - } - if( signvalue ) dopr_outch( signvalue ); - while( place > 0 ) dopr_outch( convert[--place] ); - while( padlen < 0 ){ - dopr_outch( ' ' ); - ++padlen; - } -} - -void -dostr( str , cut) - char *str; - int cut; -{ - if (cut) { - while(*str && cut-- > 0) dopr_outch(*str++); - } else { - while(*str) dopr_outch(*str++); - } -} - -void -dopr_outch( c ) - int c; -{ -#if 0 - if( iscntrl(c) && c != '\n' && c != '\t' ){ - c = '@' + (c & 0x1F); - if( DoprEnd == 0 || output < DoprEnd ) - *output++ = '^'; - } -#endif /* 0 */ - if( DoprEnd == 0 || output < DoprEnd ) - *output++ = c; - else - SnprfOverflow++; -} - -/* -** QUAD_TO_STRING -- Convert a quad type to a string. -** -** Convert a quad type to a string. This must be done -** separately as %lld/%qd are not supported by snprint() -** and adding support would slow down systems which only -** emulate the data type. -** -** Parameters: -** value -- number to convert to a string. -** -** Returns: -** pointer to a string. -*/ - -char * -quad_to_string(value) - QUAD_T value; -{ - char *formatstr; - static char buf[64]; - - /* - ** Use sprintf() instead of snprintf() since snprintf() - ** does not support %qu or %llu. The buffer is large enough - ** to hold the string so there is no danger of buffer - ** overflow. - */ - -#if NEED_PERCENTQ - formatstr = "%qu"; -#else /* NEED_PERCENTQ */ - formatstr = "%llu"; -#endif /* NEED_PERCENTQ */ - sprintf(buf, formatstr, value); - return buf; -} -/* ** SHORTENSTRING -- return short version of a string ** ** If the string is already short, just return it. If it is too @@ -401,9 +32,9 @@ quad_to_string(value) char * shortenstring(s, m) register const char *s; - int m; + size_t m; { - int l; + size_t l; static char buf[MAXSHORTSTR + 1]; l = strlen(s); @@ -415,16 +46,15 @@ shortenstring(s, m) { if (m < 5) { - (void) strlcpy(buf, s, m + 1); + (void) sm_strlcpy(buf, s, m + 1); return buf; } - (void) strlcpy(buf, s, m - 2); - (void) strlcat(buf, "...", sizeof buf); + (void) sm_strlcpy(buf, s, m - 2); + (void) sm_strlcat(buf, "...", sizeof buf); return buf; } m = (m - 3) / 2; - (void) strlcpy(buf, s, m + 1); - (void) strlcat(buf, "...", sizeof buf); - (void) strlcat(buf, s + l - m, sizeof buf); + (void) sm_strlcpy(buf, s, m + 1); + (void) sm_strlcat2(buf, "...", s + l - m, sizeof buf); return buf; } |