diff options
Diffstat (limited to 'usr.sbin/sendmail/src/util.c')
-rw-r--r-- | usr.sbin/sendmail/src/util.c | 742 |
1 files changed, 146 insertions, 596 deletions
diff --git a/usr.sbin/sendmail/src/util.c b/usr.sbin/sendmail/src/util.c index 0685bf4..b7e1d14 100644 --- a/usr.sbin/sendmail/src/util.c +++ b/usr.sbin/sendmail/src/util.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1983, 1995 Eric P. Allman + * Copyright (c) 1983 Eric P. Allman * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * @@ -33,7 +33,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)util.c 8.84 (Berkeley) 11/18/95"; +static char sccsid[] = "@(#)util.c 8.39.1.5 (Berkeley) 3/5/95"; #endif /* not lint */ # include "sendmail.h" @@ -57,7 +57,6 @@ static char sccsid[] = "@(#)util.c 8.84 (Berkeley) 11/18/95"; ** deliver */ -void stripquotes(s) char *s; { @@ -108,7 +107,8 @@ xalloc(sz) p = malloc((unsigned) sz); if (p == NULL) { - syserr("!Out of memory!!"); + syserr("Out of memory!!"); + abort(); /* exit(EX_UNAVAILABLE); */ } return (p); @@ -192,7 +192,7 @@ copyqueue(addr) addr = addr->q_next; } *tail = NULL; - + return ret; } /* @@ -208,7 +208,6 @@ copyqueue(addr) ** prints av. */ -void printav(av) register char **av; { @@ -254,9 +253,8 @@ lower(c) ** output to stdout */ -void xputs(s) - register const char *s; + register char *s; { register int c; register struct metamac *mp; @@ -271,18 +269,9 @@ xputs(s) { if (!isascii(c)) { - if (c == MATCHREPL) - { - putchar('$'); - continue; - } - if (c == MACROEXPAND) + if (c == MATCHREPL || c == MACROEXPAND) { putchar('$'); - if (strchr("=~&?", *s) != NULL) - putchar(*s++); - if (bitset(0200, *s)) - printf("{%s}", macname(*s++ & 0377)); continue; } for (mp = MetaMacros; mp->metaname != '\0'; mp++) @@ -293,12 +282,6 @@ xputs(s) break; } } - if (c == MATCHCLASS || c == MATCHNCLASS) - { - if (!bitset(0200, *s)) - continue; - printf("{%s}", macname(*s++ & 0377)); - } if (mp->metaname != '\0') continue; (void) putchar('\\'); @@ -313,6 +296,9 @@ xputs(s) /* wasn't a meta-macro -- find another way to print it */ switch (c) { + case '\0': + continue; + case '\n': c = 'n'; break; @@ -330,8 +316,6 @@ xputs(s) (void) putchar(c ^ 0100); continue; } - (void) putchar('\\'); - (void) putchar(c); } (void) fflush(stdout); } @@ -352,7 +336,6 @@ xputs(s) ** parse */ -void makelower(p) register char *p; { @@ -382,7 +365,6 @@ makelower(p) ** none. */ -void buildfname(gecos, login, buf) register char *gecos; char *login; @@ -433,8 +415,6 @@ buildfname(gecos, login, buf) ** SFF_MUSTOWN -- "uid" must own this file. ** SFF_NOSLINK -- file cannot be a symbolic link. ** mode -- mode bits that must match. -** st -- if set, points to a stat structure that will -** get the stat info for the file. ** ** Returns: ** 0 if fn exists, is owned by uid, and matches mode. @@ -458,195 +438,104 @@ buildfname(gecos, login, buf) # define S_IXUSR (S_IEXEC) #endif -#define ST_MODE_NOFILE 0171147 /* unlikely to occur */ - int -safefile(fn, uid, gid, uname, flags, mode, st) +safefile(fn, uid, gid, uname, flags, mode) char *fn; uid_t uid; gid_t gid; char *uname; int flags; int mode; - struct stat *st; { register char *p; register struct group *gr = NULL; - int file_errno = 0; struct stat stbuf; - struct stat fstbuf; - if (tTd(44, 4)) + if (tTd(54, 4)) printf("safefile(%s, uid=%d, gid=%d, flags=%x, mode=%o):\n", fn, uid, gid, flags, mode); errno = 0; - if (st == NULL) - st = &fstbuf; - /* first check to see if the file exists at all */ -#ifdef HASLSTAT - if ((bitset(SFF_NOSLINK, flags) ? lstat(fn, st) - : stat(fn, st)) < 0) -#else - if (stat(fn, st) < 0) -#endif - { - file_errno = errno; - } - else if (bitset(SFF_SETUIDOK, flags) && - !bitset(S_IXUSR|S_IXGRP|S_IXOTH, st->st_mode) && - S_ISREG(st->st_mode)) + for (p = fn; (p = strchr(++p, '/')) != NULL; *p = '/') { - /* - ** If final file is setuid, run as the owner of that - ** file. Gotta be careful not to reveal anything too - ** soon here! - */ - -#ifdef SUID_ROOT_FILES_OK - if (bitset(S_ISUID, st->st_mode)) -#else - if (bitset(S_ISUID, st->st_mode) && st->st_uid != 0) -#endif - { - uid = st->st_uid; - uname = NULL; - } -#ifdef SUID_ROOT_FILES_OK - if (bitset(S_ISGID, st->st_mode)) -#else - if (bitset(S_ISGID, st->st_mode) && st->st_gid != 0) -#endif - gid = st->st_gid; - } - - if (!bitset(SFF_NOPATHCHECK, flags) || - (uid == 0 && !bitset(SFF_ROOTOK, flags))) - { - /* check the path to the file for acceptability */ - for (p = fn; (p = strchr(++p, '/')) != NULL; *p = '/') + *p = '\0'; + if (stat(fn, &stbuf) < 0) + break; + if (uid == 0 && !bitset(SFF_ROOTOK, flags)) { - *p = '\0'; - if (stat(fn, &stbuf) < 0) - break; - if (uid == 0 && bitset(S_IWGRP|S_IWOTH, stbuf.st_mode)) - message("051 WARNING: writable directory %s", - fn); - if (uid == 0 && !bitset(SFF_ROOTOK, flags)) - { - if (bitset(S_IXOTH, stbuf.st_mode)) - continue; - break; - } - if (stbuf.st_uid == uid && - bitset(S_IXUSR, stbuf.st_mode)) - continue; - if (stbuf.st_gid == gid && - bitset(S_IXGRP, stbuf.st_mode)) + if (bitset(S_IXOTH, stbuf.st_mode)) continue; -#ifndef NO_GROUP_SET - if (uname != NULL && - ((gr != NULL && gr->gr_gid == stbuf.st_gid) || - (gr = getgrgid(stbuf.st_gid)) != NULL)) - { - register char **gp; - - for (gp = gr->gr_mem; gp != NULL && *gp != NULL; gp++) - if (strcmp(*gp, uname) == 0) - break; - if (gp != NULL && *gp != NULL && - bitset(S_IXGRP, stbuf.st_mode)) - continue; - } -#endif - if (!bitset(S_IXOTH, stbuf.st_mode)) - break; + break; } - if (p != NULL) + if (stbuf.st_uid == uid && bitset(S_IXUSR, stbuf.st_mode)) + continue; + if (stbuf.st_gid == gid && bitset(S_IXGRP, stbuf.st_mode)) + continue; +#ifndef NO_GROUP_SET + if (uname != NULL && + ((gr != NULL && gr->gr_gid == stbuf.st_gid) || + (gr = getgrgid(stbuf.st_gid)) != NULL)) { - int ret = errno; - - if (ret == 0) - ret = EACCES; - if (tTd(44, 4)) - printf("\t[dir %s] %s\n", fn, errstring(ret)); - *p = '/'; - return ret; + register char **gp; + + for (gp = gr->gr_mem; *gp != NULL; gp++) + if (strcmp(*gp, uname) == 0) + break; + if (*gp != NULL && bitset(S_IXGRP, stbuf.st_mode)) + continue; } +#endif + if (!bitset(S_IXOTH, stbuf.st_mode)) + break; } + if (p != NULL) + { + int ret = errno; - /* - ** If the target file doesn't exist, check the directory to - ** ensure that it is writable by this user. - */ + if (ret == 0) + ret = EACCES; + if (tTd(54, 4)) + printf("\t[dir %s] %s\n", fn, errstring(ret)); + *p = '/'; + return ret; + } - if (file_errno != 0) +#ifdef HASLSTAT + if ((bitset(SFF_NOSLINK, flags) ? lstat(fn, &stbuf) + : stat(fn, &stbuf)) < 0) +#else + if (stat(fn, &stbuf) < 0) +#endif { - int ret = file_errno; + int ret = errno; - if (tTd(44, 4)) + if (tTd(54, 4)) printf("\t%s\n", errstring(ret)); errno = 0; - if (!bitset(SFF_CREAT, flags)) - return ret; - - /* check to see if legal to create the file */ - p = strrchr(fn, '/'); - if (p == NULL) - return ENOTDIR; - *p = '\0'; - if (stat(fn, &stbuf) >= 0) - { - int md = S_IWRITE|S_IEXEC; - if (stbuf.st_uid != uid) - md >>= 6; - if ((stbuf.st_mode & md) != md) - errno = EACCES; - } - ret = errno; - if (tTd(44, 4)) - printf("\t[final dir %s uid %d mode %o] %s\n", - fn, stbuf.st_uid, stbuf.st_mode, - errstring(ret)); - *p = '/'; - st->st_mode = ST_MODE_NOFILE; return ret; } #ifdef S_ISLNK - if (bitset(SFF_NOSLINK, flags) && S_ISLNK(st->st_mode)) + if (bitset(SFF_NOSLINK, flags) && S_ISLNK(stbuf.st_mode)) { - if (tTd(44, 4)) - printf("\t[slink mode %o]\tEPERM\n", st->st_mode); + if (tTd(54, 4)) + printf("\t[slink mode %o]\tEPERM\n", stbuf.st_mode); return EPERM; } #endif - if (bitset(SFF_REGONLY, flags) && !S_ISREG(st->st_mode)) - { - if (tTd(44, 4)) - printf("\t[non-reg mode %o]\tEPERM\n", st->st_mode); - return EPERM; - } - if (bitset(S_IWUSR|S_IWGRP|S_IWOTH, mode) && - bitset(S_IXUSR|S_IXGRP|S_IXOTH, st->st_mode)) - { - if (tTd(44, 4)) - printf("\t[exec bits %o]\tEPERM]\n", st->st_mode); - return EPERM; - } if (uid == 0 && !bitset(SFF_ROOTOK, flags)) mode >>= 6; - else if (st->st_uid != uid) + else if (stbuf.st_uid != uid) { mode >>= 3; - if (st->st_gid == gid) + if (stbuf.st_gid == gid) ; #ifndef NO_GROUP_SET else if (uname != NULL && - ((gr != NULL && gr->gr_gid == st->st_gid) || - (gr = getgrgid(st->st_gid)) != NULL)) + ((gr != NULL && gr->gr_gid == stbuf.st_gid) || + (gr = getgrgid(stbuf.st_gid)) != NULL)) { register char **gp; @@ -660,104 +549,22 @@ safefile(fn, uid, gid, uname, flags, mode, st) else mode >>= 3; } - if (tTd(44, 4)) + if (tTd(54, 4)) printf("\t[uid %d, stat %o, mode %o] ", - st->st_uid, st->st_mode, mode); - if ((st->st_uid == uid || st->st_uid == 0 || + stbuf.st_uid, stbuf.st_mode, mode); + if ((stbuf.st_uid == uid || stbuf.st_uid == 0 || !bitset(SFF_MUSTOWN, flags)) && - (st->st_mode & mode) == mode) + (stbuf.st_mode & mode) == mode) { - if (tTd(44, 4)) + if (tTd(54, 4)) printf("\tOK\n"); return 0; } - if (tTd(44, 4)) + if (tTd(54, 4)) printf("\tEACCES\n"); return EACCES; } /* -** 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. -*/ - -#ifndef O_ACCMODE -# define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) -#endif - -FILE * -safefopen(fn, omode, cmode, sff) - char *fn; - int omode; - int cmode; - int sff; -{ - int rval; - FILE *fp; - int smode; - struct stat stb, sta; - - if (bitset(O_CREAT, omode)) - sff |= SFF_CREAT; - smode = 0; - switch (omode & O_ACCMODE) - { - case O_RDONLY: - smode = S_IREAD; - break; - - case O_WRONLY: - smode = S_IWRITE; - break; - - case O_RDWR: - smode = S_IREAD|S_IWRITE; - break; - - default: - smode = 0; - break; - } - if (bitset(SFF_OPENASROOT, sff)) - rval = safefile(fn, 0, 0, NULL, sff, smode, &stb); - else - rval = safefile(fn, RealUid, RealGid, RealUserName, - sff, smode, &stb); - if (rval != 0) - { - errno = rval; - return NULL; - } - if (stb.st_mode == ST_MODE_NOFILE) - omode |= O_EXCL; - - fp = dfopen(fn, omode, cmode); - if (fp == NULL) - return NULL; - if (bitset(O_EXCL, omode)) - return fp; - if (fstat(fileno(fp), &sta) < 0 || - sta.st_nlink != stb.st_nlink || - sta.st_dev != stb.st_dev || - sta.st_ino != stb.st_ino || - sta.st_uid != stb.st_uid || - sta.st_gid != stb.st_gid) - { - syserr("554 cannot open: file %s changed after open", fn); - fclose(fp); - errno = EPERM; - return NULL; - } - return fp; -} -/* ** FIXCRLF -- fix <CR><LF> in line. ** ** Looks for the <CR><LF> combination and turns it into the @@ -776,7 +583,6 @@ safefopen(fn, omode, cmode, sff) ** line is changed in place. */ -void fixcrlf(line, stripnl) char *line; bool stripnl; @@ -801,6 +607,10 @@ fixcrlf(line, stripnl) ** whatever), so this tries to get around it. */ +#ifndef O_ACCMODE +# define O_ACCMODE (O_RDONLY|O_WRONLY|O_RDWR) +#endif + struct omodes { int mask; @@ -883,46 +693,16 @@ dfopen(filename, omode, cmode) ** output of l to fp. */ -void putline(l, mci) register char *l; register MCI *mci; { - putxline(l, mci, PXLF_MAPFROM); -} -/* -** PUTXLINE -- putline with flags bits. -** -** This routine always guarantees outputing a newline (or CRLF, -** as appropriate) at the end of the string. -** -** Parameters: -** l -- line to put. -** mci -- the mailer connection information. -** pxflags -- flag bits: -** PXLF_MAPFROM -- map From_ to >From_. -** PXLF_STRIP8BIT -- strip 8th bit. -** -** Returns: -** none -** -** Side Effects: -** output of l to fp. -*/ - -void -putxline(l, mci, pxflags) - register char *l; - register MCI *mci; - int pxflags; -{ register char *p; register char svchar; int slop = 0; /* strip out 0200 bits -- these can look like TELNET protocol */ - if (bitset(MCIF_7BIT, mci->mci_flags) || - bitset(PXLF_STRIP8BIT, pxflags)) + if (bitset(MCIF_7BIT, mci->mci_flags)) { for (p = l; (svchar = *p) != '\0'; ++p) if (bitset(0200, svchar)) @@ -954,15 +734,6 @@ putxline(l, mci, pxflags) if (TrafficLogFile != NULL) (void) putc('.', TrafficLogFile); } - else if (l[0] == 'F' && slop == 0 && - bitset(PXLF_MAPFROM, pxflags) && - strncmp(l, "From ", 5) == 0 && - bitnset(M_ESCFROM, mci->mci_mailer->m_flags)) - { - (void) putc('>', mci->mci_out); - if (TrafficLogFile != NULL) - (void) putc('>', TrafficLogFile); - } fputs(l, mci->mci_out); (void) putc('!', mci->mci_out); fputs(mci->mci_mailer->m_eol, mci->mci_out); @@ -1005,7 +776,6 @@ putxline(l, mci, pxflags) ** f is unlinked. */ -void xunlink(f) char *f; { @@ -1036,14 +806,13 @@ xunlink(f) ** fp is closed. */ -void xfclose(fp, a, b) FILE *fp; char *a, *b; { if (tTd(53, 99)) printf("xfclose(%x) %s %s\n", fp, a, b); -#if XDEBUG +#ifdef XDEBUG if (fileno(fp) == 1) syserr("xfclose(%s %s): fd = 1", a, b); #endif @@ -1070,7 +839,10 @@ xfclose(fp, a, b) */ static jmp_buf CtxReadTimeout; -static void readtimeout(); +static int readtimeout(); +static EVENT *GlobalTimeout = NULL; +static bool EnableTimeout = FALSE; +static int ReadProgress; char * sfgets(buf, siz, fp, timeout, during) @@ -1096,19 +868,22 @@ sfgets(buf, siz, fp, timeout, during) { # ifdef LOG syslog(LOG_NOTICE, - "timeout waiting for input from %.100s during %s", + "timeout waiting for input from %s during %s\n", CurHostName? CurHostName: "local", during); # endif errno = 0; usrerr("451 timeout waiting for input during %s", during); buf[0] = '\0'; -#if XDEBUG +#ifdef XDEBUG checkfd012(during); #endif return (NULL); } - ev = setevent(timeout, readtimeout, 0); + if (GlobalTimeout == NULL) + ev = setevent(timeout, readtimeout, 0); + else + EnableTimeout = TRUE; } /* try to read */ @@ -1123,7 +898,10 @@ sfgets(buf, siz, fp, timeout, during) } /* clear the event if it has not sprung */ - clrevent(ev); + if (GlobalTimeout == NULL) + clrevent(ev); + else + EnableTimeout = FALSE; /* clean up the books and exit */ LineNumber++; @@ -1136,30 +914,50 @@ sfgets(buf, siz, fp, timeout, during) } if (TrafficLogFile != NULL) fprintf(TrafficLogFile, "%05d <<< %s", getpid(), buf); - if (SevenBitInput) - { + if (SevenBit) for (p = buf; *p != '\0'; p++) *p &= ~0200; + return (buf); +} + +void +sfgetset(timeout) + time_t timeout; +{ + /* cancel pending timer */ + if (GlobalTimeout != NULL) + { + clrevent(GlobalTimeout); + GlobalTimeout = NULL; } - else if (!HasEightBits) + + /* schedule fresh one if so requested */ + if (timeout != 0) { - for (p = buf; *p != '\0'; p++) - { - if (bitset(0200, *p)) - { - HasEightBits = TRUE; - break; - } - } + ReadProgress = LineNumber; + GlobalTimeout = setevent(timeout, readtimeout, timeout); } - return (buf); } -static void +static readtimeout(timeout) time_t timeout; { - longjmp(CtxReadTimeout, 1); + /* terminate if ordinary timeout */ + if (GlobalTimeout == NULL) + longjmp(CtxReadTimeout, 1); + + /* terminate if no progress was made -- reset state */ + if (EnableTimeout && (LineNumber <= ReadProgress)) + { + EnableTimeout = FALSE; + GlobalTimeout = NULL; + longjmp(CtxReadTimeout, 2); + } + + /* schedule a new timeout */ + GlobalTimeout = NULL; + sfgetset(timeout); } /* ** FGETFOLDED -- like fgets, but know about folded lines. @@ -1235,9 +1033,7 @@ fgetfolded(buf, n, f) } if (p == bp) return (NULL); - if (p[-1] == '\n') - p--; - *p = '\0'; + *--p = '\0'; return (bp); } /* @@ -1299,7 +1095,6 @@ atobool(s) ** none. */ -int atooct(s) register char *s; { @@ -1446,11 +1241,10 @@ strcontainedin(a, b) ** none */ -void checkfd012(where) char *where; { -#if XDEBUG +#ifdef XDEBUG register int i; struct stat stbuf; @@ -1483,9 +1277,9 @@ checkfd012(where) ** none. */ +#include <netdb.h> #include <arpa/inet.h> -void printopenfds(logit) bool logit; { @@ -1505,22 +1299,18 @@ printopenfds(logit) ** logit -- if set, send output to syslog instead of stdout. */ -void dumpfd(fd, printclosed, logit) int fd; bool printclosed; bool logit; { + register struct hostent *hp; register char *p; - char *hp; char *fmtstr; -#ifdef S_IFSOCK - SOCKADDR sa; -#endif + struct sockaddr_in sin; auto int slen; struct stat st; char buf[200]; - extern char *hostnamebyanyaddr(); p = buf; sprintf(p, "%3d: ", fd); @@ -1551,30 +1341,26 @@ dumpfd(fd, printclosed, logit) case S_IFSOCK: sprintf(p, "SOCK "); p += strlen(p); - slen = sizeof sa; - if (getsockname(fd, &sa.sa, &slen) < 0) - sprintf(p, "(%s)", errstring(errno)); + slen = sizeof sin; + if (getsockname(fd, (struct sockaddr *) &sin, &slen) < 0) + sprintf(p, "(badsock)"); else { - hp = hostnamebyanyaddr(&sa); - if (sa.sa.sa_family == AF_INET) - sprintf(p, "%s/%d", hp, ntohs(sa.sin.sin_port)); - else - sprintf(p, "%s", hp); + hp = gethostbyaddr((char *) &sin.sin_addr, slen, AF_INET); + sprintf(p, "%s/%d", hp == NULL ? inet_ntoa(sin.sin_addr) + : hp->h_name, ntohs(sin.sin_port)); } p += strlen(p); sprintf(p, "->"); p += strlen(p); - slen = sizeof sa; - if (getpeername(fd, &sa.sa, &slen) < 0) - sprintf(p, "(%s)", errstring(errno)); + slen = sizeof sin; + if (getpeername(fd, (struct sockaddr *) &sin, &slen) < 0) + sprintf(p, "(badsock)"); else { - hp = hostnamebyanyaddr(&sa); - if (sa.sa.sa_family == AF_INET) - sprintf(p, "%s/%d", hp, ntohs(sa.sin.sin_port)); - else - sprintf(p, "%s", hp); + hp = gethostbyaddr((char *) &sin.sin_addr, slen, AF_INET); + sprintf(p, "%s/%d", hp == NULL ? inet_ntoa(sin.sin_addr) + : hp->h_name, ntohs(sin.sin_port)); } break; #endif @@ -1625,7 +1411,7 @@ defprint: printit: #ifdef LOG if (logit) - syslog(LOG_DEBUG, "%.800s", buf); + syslog(LOG_DEBUG, "%s", buf); else #endif printf("%s\n", buf); @@ -1650,7 +1436,7 @@ printit: char * shortenstring(s, m) - register const char *s; + register char *s; int m; { int l; @@ -1658,7 +1444,7 @@ shortenstring(s, m) l = strlen(s); if (l < m) - return (char *) s; + return s; if (m > MAXSHORTSTR) m = MAXSHORTSTR; else if (m < 10) @@ -1680,240 +1466,6 @@ shortenstring(s, m) return buf; } /* -** SHORTEN_HOSTNAME -- strip local domain information off of hostname. -** -** Parameters: -** host -- the host to shorten (stripped in place). -** -** Returns: -** none. -*/ - -void -shorten_hostname(host) - char host[]; -{ - register char *p; - char *mydom; - int i; - bool canon = FALSE; - - /* strip off final dot */ - p = &host[strlen(host) - 1]; - if (*p == '.') - { - *p = '\0'; - canon = TRUE; - } - - /* see if there is any domain at all -- if not, we are done */ - p = strchr(host, '.'); - if (p == NULL) - return; - - /* yes, we have a domain -- see if it looks like us */ - mydom = macvalue('m', CurEnv); - if (mydom == NULL) - mydom = ""; - i = strlen(++p); - if ((canon ? strcasecmp(p, mydom) : strncasecmp(p, mydom, i)) == 0 && - (mydom[i] == '.' || mydom[i] == '\0')) - *--p = '\0'; -} -/* -** PROG_OPEN -- open a program for reading -** -** Parameters: -** argv -- the argument list. -** pfd -- pointer to a place to store the file descriptor. -** e -- the current envelope. -** -** Returns: -** pid of the process -- -1 if it failed. -*/ - -int -prog_open(argv, pfd, e) - char **argv; - int *pfd; - ENVELOPE *e; -{ - int pid; - int i; - int saveerrno; - int fdv[2]; - char *p, *q; - char buf[MAXLINE + 1]; - extern int DtableSize; - - if (pipe(fdv) < 0) - { - syserr("%s: cannot create pipe for stdout", argv[0]); - return -1; - } - pid = fork(); - if (pid < 0) - { - syserr("%s: cannot fork", argv[0]); - close(fdv[0]); - close(fdv[1]); - return -1; - } - if (pid > 0) - { - /* parent */ - close(fdv[1]); - *pfd = fdv[0]; - return pid; - } - - /* child -- close stdin */ - close(0); - - /* stdout goes back to parent */ - close(fdv[0]); - if (dup2(fdv[1], 1) < 0) - { - syserr("%s: cannot dup2 for stdout", argv[0]); - _exit(EX_OSERR); - } - close(fdv[1]); - - /* stderr goes to transcript if available */ - if (e->e_xfp != NULL) - { - if (dup2(fileno(e->e_xfp), 2) < 0) - { - syserr("%s: cannot dup2 for stderr", argv[0]); - _exit(EX_OSERR); - } - } - - /* this process has no right to the queue file */ - if (e->e_lockfp != NULL) - close(fileno(e->e_lockfp)); - - /* run as default user */ - endpwent(); - setgid(DefGid); - setuid(DefUid); - - /* run in some directory */ - if (ProgMailer != NULL) - p = ProgMailer->m_execdir; - else - p = NULL; - for (; p != NULL; p = q) - { - q = strchr(p, ':'); - if (q != NULL) - *q = '\0'; - expand(p, buf, sizeof buf, e); - if (q != NULL) - *q++ = ':'; - if (buf[0] != '\0' && chdir(buf) >= 0) - break; - } - if (p == NULL) - { - /* backup directories */ - if (chdir("/tmp") < 0) - (void) chdir("/"); - } - - /* arrange for all the files to be closed */ - for (i = 3; i < DtableSize; i++) - { - register int j; - - if ((j = fcntl(i, F_GETFD, 0)) != -1) - (void) fcntl(i, F_SETFD, j | 1); - } - - /* now exec the process */ - execve(argv[0], (ARGV_T) argv, (ARGV_T) UserEnviron); - - /* woops! failed */ - saveerrno = errno; - syserr("%s: cannot exec", argv[0]); - if (transienterror(saveerrno)) - _exit(EX_OSERR); - _exit(EX_CONFIG); -} -/* -** GET_COLUMN -- look up a Column in a line buffer -** -** Parameters: -** line -- the raw text line to search. -** col -- the column number to fetch. -** delim -- the delimiter between columns. If null, -** use white space. -** buf -- the output buffer. -** -** Returns: -** buf if successful. -** NULL otherwise. -*/ - -char * -get_column(line, col, delim, buf) - char line[]; - int col; - char delim; - char buf[]; -{ - char *p; - char *begin, *end; - int i; - char delimbuf[3]; - - if (delim == '\0') - strcpy(delimbuf, "\n\t "); - else - { - delimbuf[0] = delim; - delimbuf[1] = '\0'; - } - - p = line; - if (*p == '\0') - return NULL; /* line empty */ - if (*p == delim && col == 0) - return NULL; /* first column empty */ - - begin = line; - - if (col == 0 && delim == '\0') - { - while (*begin && isspace(*begin)) - begin++; - } - - for (i = 0; i < col; i++) - { - if ((begin = strpbrk(begin, delimbuf)) == NULL) - return NULL; /* no such column */ - begin++; - if (delim == '\0') - { - while (*begin && isspace(*begin)) - begin++; - } - } - - end = strpbrk(begin, delimbuf); - if (end == NULL) - { - strcpy(buf, begin); - } - else - { - strncpy(buf, begin, end - begin); - buf[end - begin] = '\0'; - } - return buf; -} -/* ** CLEANSTRCPY -- copy string keeping out bogus characters ** ** Parameters: @@ -1965,8 +1517,8 @@ cleanstrcpy(t, f, l) char * denlstring(s, strict, logattacks) char *s; - bool strict; - bool logattacks; + int strict; + int logattacks; { register char *p; int l; @@ -1993,16 +1545,14 @@ denlstring(s, strict, logattacks) for (p = bp; (p = strchr(p, '\n')) != NULL; ) *p++ = ' '; -/* #ifdef LOG if (logattacks) { - syslog(LOG_NOTICE, "POSSIBLE ATTACK from %.100s: newline in string \"%s\"", + syslog(LOG_NOTICE, "POSSIBLE ATTACK from %s: newline in string \"%s\"", RealHostName == NULL ? "[UNKNOWN]" : RealHostName, - shortenstring(bp, 203)); + shortenstring(bp, 80)); } #endif -*/ return bp; } |