X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/f47c29e776ef6b5564bd673056a8ddbdddc90809..fd88f5c5678c80ff5e338adc372d28a52ad20530:/usr/src/usr.sbin/sendmail/src/conf.c diff --git a/usr/src/usr.sbin/sendmail/src/conf.c b/usr/src/usr.sbin/sendmail/src/conf.c index d15a885971..8467caabe1 100644 --- a/usr/src/usr.sbin/sendmail/src/conf.c +++ b/usr/src/usr.sbin/sendmail/src/conf.c @@ -3,11 +3,37 @@ * Copyright (c) 1988, 1993 * The Regents of the University of California. All rights reserved. * - * %sccs.include.redist.c% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. */ #ifndef lint -static char sccsid[] = "@(#)conf.c 8.184 (Berkeley) %G%"; +static char sccsid[] = "@(#)conf.c 8.203 (Berkeley) 6/20/95"; #endif /* not lint */ # include "sendmail.h" @@ -39,7 +65,7 @@ static char sccsid[] = "@(#)conf.c 8.184 (Berkeley) %G%"; - /* +/* ** Header info table ** Final (null) entry contains the flags used for any other field. ** @@ -262,7 +288,7 @@ setupmailers() char buf[100]; extern void makemailer(); - strcpy(buf, "prog, P=/bin/sh, F=lsoD, T=DNS/RFC822/X-Unix, A=sh -c $u"); + strcpy(buf, "prog, P=/bin/sh, F=lsoD, T=DNS/RFC822/X-Unix, A=sh -c \201u"); makemailer(buf); strcpy(buf, "*file*, P=[FILE], F=lsDFMPEou, T=DNS/RFC822/X-Unix, A=FILE"); @@ -332,7 +358,7 @@ setupmaps() hes_map_lookup, null_map_store); #endif -#ifdef NETINFO +#if NETINFO MAPDEF("netinfo", NULL, MCF_ALIASOK, map_parseargs, ni_map_open, null_map_close, ni_map_lookup, null_map_store); @@ -597,7 +623,11 @@ inithostmaps() # include #endif -#if defined(ultrix) || defined(__osf__) +#if defined(ultrix) || (defined(__osf__) && defined(__alpha)) +# define _USE_DEC_SVC_CONF_ +#endif + +#ifdef _USE_DEC_SVC_CONF_ # include #endif @@ -641,7 +671,7 @@ switch_map_find(service, maptype, mapreturn) return svcno; #endif -#if defined(ultrix) || defined(__osf__) +#ifdef _USE_DEC_SVC_CONF_ struct svcinfo *svcinfo; int svc; @@ -688,7 +718,7 @@ switch_map_find(service, maptype, mapreturn) return svcno; #endif -#if !defined(SOLARIS) && !defined(ultrix) && !defined(__osf__) +#if !defined(SOLARIS) && !defined(_USE_DEC_SVC_CONF_) /* ** Fall-back mechanism. */ @@ -725,10 +755,12 @@ switch_map_find(service, maptype, mapreturn) if (p != NULL) *p++ = '\0'; } while (p != NULL); - break; + fclose(fp); + return svcno; } + + /* service was not found -- use compiled in default */ fclose(fp); - return svcno; } #endif @@ -943,7 +975,7 @@ setsignal(sig, handler) int sig; sigfunc_t handler; { -#if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE) +#if defined(SYS5SIGNALS) || defined(BSD4_3) return signal(sig, handler); #else struct sigaction n, o; @@ -959,6 +991,31 @@ setsignal(sig, handler) #endif } /* +** RELEASESIGNAL -- release a held signal +** +** Parameters: +** sig -- the signal to release. +** +** Returns: +** 0 on success. +** -1 on failure. +*/ + +int +releasesignal(sig) + int sig; +{ +#ifdef BSD4_3 + return sigsetmask(sigblock(0) & ~(1 << sig)); +#else + sigset_t sset; + + sigemptyset(&sset); + sigaddset(&sset, sig); + return sigprocmask(SIG_UNBLOCK, &sset, NULL); +#endif +} + /* ** HOLDSIGS -- arrange to hold all signals ** ** Parameters: @@ -1119,12 +1176,16 @@ init_vendor_macros(e) # endif #endif +#ifdef _AUX_SOURCE +struct nlist Nl[2]; +#else struct nlist Nl[] = { { LA_AVENRUN }, -#define X_AVENRUN 0 { 0 }, }; +#endif +#define X_AVENRUN 0 getla() { @@ -1153,6 +1214,10 @@ getla() } (void) fcntl(kmem, F_SETFD, 1); +#ifdef _AUX_SOURCE + strcpy(Nl[X_AVENRUN].n_name, LA_AVENRUN); +#endif + #ifdef _AIX3 if (knlist(Nl, 1, sizeof Nl[0]) < 0) #else @@ -1526,30 +1591,45 @@ shouldqueue(pri, ctime) ** FALSE if we should accept new work. ** ** Side Effects: -** none. +** Sets process title when it is rejecting connections. */ bool refuseconnections() { - extern bool enoughspace(); + extern bool enoughdiskspace(); + extern void setproctitle __P((char *, ...)); #ifdef XLA if (!xla_smtp_ok()) return TRUE; #endif - /* this is probably too simplistic */ - return CurrentLA >= RefuseLA || !enoughspace(MinBlocksFree + 1); + if (CurrentLA >= RefuseLA) + { + setproctitle("rejecting connections: load average: %d", + CurrentLA); + } + else if (!enoughdiskspace(MinBlocksFree + 1)) + { + setproctitle("rejecting connections: min free: %d", + MinBlocksFree); + } + else if (MaxChildren > 0 && CurChildren >= MaxChildren) + { + setproctitle("rejecting connections: maximum children: %d", + CurChildren); + } + else + return FALSE; + return TRUE; } /* ** SETPROCTITLE -- set process title for ps ** ** Parameters: -** fmt -- a printf style format string. If NULL, the first -** parameter is a literal proctitle previously -** returned by getproctitle. -** va_alist -- possible parameters to fmt. +** fmt -- a printf style format string. +** a, b, c -- possible parameters to fmt. ** ** Returns: ** none. @@ -1608,8 +1688,6 @@ typedef unsigned int *pt_entry_t; #if SPT_TYPE != SPT_BUILTIN -char ProcTitleBuf[MAXLINE]; - /*VARARGS1*/ void # ifdef __STDC__ @@ -1623,6 +1701,7 @@ setproctitle(fmt, va_alist) # if SPT_TYPE != SPT_NONE register char *p; register int i; + SETPROC_STATIC char buf[MAXLINE]; VA_LOCAL_DECL # if SPT_TYPE == SPT_PSTAT union pstun pst; @@ -1632,32 +1711,37 @@ setproctitle(fmt, va_alist) extern char *LastArgv; # endif - VA_START(fmt); - if (fmt == NULL) - { - /* restore old proctitle */ - (void) strcpy(ProcTitleBuf, va_arg(ap, char *)); - } - else - { - p = ProcTitleBuf; + p = buf; - /* print sendmail: heading for grep */ - (void) strcpy(p, "sendmail: "); - p += strlen(p); + /* print sendmail: heading for grep */ + (void) strcpy(p, "sendmail: "); + p += strlen(p); - /* print the argument string */ - (void) vsprintf(p, fmt, ap); - } + /* print the argument string */ + VA_START(fmt); + (void) vsprintf(p, fmt, ap); VA_END; - i = strlen(ProcTitleBuf); + i = strlen(buf); + +# if SPT_TYPE == SPT_PSTAT + pst.pst_command = buf; + pstat(PSTAT_SETCMD, pst, i, 0, 0); +# endif +# if SPT_TYPE == SPT_PSSTRINGS + PS_STRINGS->ps_nargvstr = 1; + PS_STRINGS->ps_argvstr = buf; +# endif +# if SPT_TYPE == SPT_SYSMIPS + sysmips(SONY_SYSNEWS, NEWS_SETPSARGS, buf); +# endif +# if SPT_TYPE == SPT_REUSEARGV if (i > LastArgv - Argv[0] - 2) { i = LastArgv - Argv[0] - 2; - ProcTitleBuf[i] = '\0'; + buf[i] = '\0'; } - (void) strcpy(Argv[0], ProcTitleBuf); + (void) strcpy(Argv[0], buf); p = &Argv[0][i]; while (p < LastArgv) *p++ = SPT_PADCHAR; @@ -1701,18 +1785,19 @@ reapchild(sig) #endif break; } + CurChildren--; } # else # ifdef WNOHANG union wait status; while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0) - continue; + CurChildren--; # else /* WNOHANG */ auto int status; while (wait(&status) > 0) - continue; + CurChildren--; # endif /* WNOHANG */ # endif # ifdef SYS5SIGNALS @@ -2180,6 +2265,7 @@ vsprintf(s, fmt, ap) ** USERSHELLOK -- tell if a user's shell is ok for unrestricted use ** ** Parameters: +** user -- the name of the user we are checking. ** shell -- the user's shell from /etc/passwd ** ** Returns: @@ -2237,14 +2323,16 @@ char *DefaultUserShells[] = #define WILDCARD_SHELL "/SENDMAIL/ANY/SHELL/" bool -usershellok(shell) +usershellok(user, shell) + char *user; char *shell; { #if HASGETUSERSHELL register char *p; extern char *getusershell(); - if (shell == NULL || shell[0] == '\0' || ConfigLevel <= 1) + if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't') || + ConfigLevel <= 1) return TRUE; setusershell(); @@ -2260,7 +2348,7 @@ usershellok(shell) register FILE *shellf; char buf[MAXLINE]; - if (shell == NULL || shell[0] == '\0') + if (shell == NULL || shell[0] == '\0' || wordinclass(user, 't')) return TRUE; # if USEGETCONFATTR @@ -2327,7 +2415,7 @@ usershellok(shell) #endif } /* -** FREESPACE -- see how much free space is on the queue filesystem +** FREEDISKSPACE -- see how much free space is on the queue filesystem ** ** Only implemented if you have statfs. ** @@ -2374,7 +2462,7 @@ usershellok(shell) #endif long -freespace(dir, bsize) +freediskspace(dir, bsize) char *dir; long *bsize; { @@ -2429,7 +2517,7 @@ freespace(dir, bsize) return (-1); } /* -** ENOUGHSPACE -- check to see if there is enough free space on the queue fs +** ENOUGHDISKSPACE -- is there enough free space on the queue fs? ** ** Only implemented if you have statfs. ** @@ -2444,7 +2532,7 @@ freespace(dir, bsize) */ bool -enoughspace(msize) +enoughdiskspace(msize) long msize; { long bfree, bsize; @@ -2452,14 +2540,14 @@ enoughspace(msize) if (MinBlocksFree <= 0 && msize <= 0) { if (tTd(4, 80)) - printf("enoughspace: no threshold\n"); + printf("enoughdiskspace: no threshold\n"); return TRUE; } - if ((bfree = freespace(QueueDir, &bsize)) >= 0) + if ((bfree = freediskspace(QueueDir, &bsize)) >= 0) { if (tTd(4, 80)) - printf("enoughspace: bavail=%ld, need=%ld\n", + printf("enoughdiskspace: bavail=%ld, need=%ld\n", bfree, msize); /* convert msize to block count */ @@ -2482,7 +2570,7 @@ enoughspace(msize) } } else if (tTd(4, 80)) - printf("enoughspace failure: min=%ld, need=%ld: %s\n", + printf("enoughdiskspace failure: min=%ld, need=%ld: %s\n", MinBlocksFree, msize, errstring(errno)); return TRUE; } @@ -2817,14 +2905,10 @@ resetlimits() char * getcfname() { -#ifdef TRY_VERSIONED_CF_NAME - int i; - static char cbuf[200]; -#endif if (ConfFile != NULL) return ConfFile; -#ifdef NETINFO +#if NETINFO { extern char *ni_propval(); char *cflocation; @@ -2836,42 +2920,6 @@ getcfname() } #endif -#ifdef TRY_VERSIONED_CF_NAME - /* - ** Try sendmail.8.6.12.cf, then sendmail.8.6.cf, then - ** sendmail.8.cf, and finally sendmail.cf. - ** - ** I suppose it should really try a search path here -- - ** e.g., /etc/sendmail.cf, /etc/mail/sendmail.cf, - ** /usr/lib/sendmail.cf, and so forth. - */ - - strcpy(cbuf, _PATH_SENDMAILCF); - i = strlen(cbuf); - if (strcmp(&cbuf[i - 3], ".cf") == 0) - { - char *p; - extern char Version[]; - - strcpy(&cbuf[i - 2], Version); - p = strchr(&cbuf[i - 2], '/'); - if (p != NULL) - *p = '\0'; - p = &cbuf[strlen(cbuf)]; - do - { - int fd; - - strcpy(p, ".cf"); - if ((fd = open(cbuf, O_RDONLY, 0)) >= 0) - { - close(fd); - return cbuf; - } - *p = '\0'; - } while ((p = strrchr(&cbuf[i - 2], '.')) != NULL); - } -#endif return _PATH_SENDMAILCF; } /* @@ -3089,56 +3137,72 @@ strstr(big, little) ** work around these problems. */ -extern int h_errno; - struct hostent * sm_gethostbyname(name) char *name; { + struct hostent *h; #if defined(SOLARIS) && SOLARIS < 204 || defined(sony_news) && defined(__svr4) - extern int h_errno; - # if SOLARIS == 203 static struct hostent hp; static char buf[1000]; extern struct hostent *_switch_gethostbyname_r(); - return _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); + if (tTd(61, 10)) + printf("_switch_gethostbyname_r(%s)... ", name); + h = _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno); # else extern struct hostent *__switch_gethostbyname(); - return __switch_gethostbyname(name); + if (tTd(61, 10)) + printf("__switch_gethostbyname(%s)... ", name); + h = __switch_gethostbyname(name); # endif #else - struct hostent *h; int nmaps; char *maptype[MAXMAPSTACK]; short mapreturn[MAXMAPACTIONS]; char hbuf[MAXNAME]; + if (tTd(61, 10)) + printf("gethostbyname(%s)... ", name); h = gethostbyname(name); -# if defined(NIS) - if (h != NULL) - return h; - nmaps = switch_map_find("hosts", maptype, mapreturn); - while (--nmaps >= 0) - if (strcmp(maptype[nmaps], "nis") == 0) - break; - if (nmaps >= 0) + if (h == NULL) { - /* try short name */ - if (strlen(name) > sizeof hbuf - 1) - return NULL; - strcpy(hbuf, name); - shorten_hostname(hbuf); + if (tTd(61, 10)) + printf("failure\n"); - /* if it hasn't been shortened, there's no point */ - if (strcmp(hbuf, name) != 0) - return gethostbyname(hbuf); + nmaps = switch_map_find("hosts", maptype, mapreturn); + while (--nmaps >= 0) + if (strcmp(maptype[nmaps], "nis") == 0 || + strcmp(maptype[nmaps], "files") == 0) + break; + if (nmaps >= 0) + { + /* try short name */ + if (strlen(name) > sizeof hbuf - 1) + return NULL; + strcpy(hbuf, name); + shorten_hostname(hbuf); + + /* if it hasn't been shortened, there's no point */ + if (strcmp(hbuf, name) != 0) + { + if (tTd(61, 10)) + printf("gethostbyname(%s)... ", hbuf); + h = gethostbyname(hbuf); + } + } } -# endif - return h; #endif + if (tTd(61, 10)) + { + if (h == NULL) + printf("failure\n"); + else + printf("%s\n", h->h_name); + } + return h; } struct hostent * @@ -3148,8 +3212,6 @@ sm_gethostbyaddr(addr, len, type) int type; { #if defined(SOLARIS) && SOLARIS < 204 - extern int h_errno; - # if SOLARIS == 203 static struct hostent hp; static char buf[1000]; @@ -3178,7 +3240,7 @@ sm_getpwnam(user) struct passwd * sm_getpwuid(uid) - uid_t uid; + UID_T uid; { return getpwuid(uid); } @@ -3229,7 +3291,7 @@ load_if_names() close(s); /* scan the list of IP address */ - if (tTd(0, 4)) + if (tTd(0, 40)) printf("scanning for interface specific names, ifc_len=%d\n", ifc.ifc_len); @@ -3335,7 +3397,7 @@ load_if_names() ** Caller should free the return value of ni_proval */ -#ifdef NETINFO +#if NETINFO # include @@ -3551,7 +3613,7 @@ char *CompileOptions[] = #if HESIOD "HESIOD", #endif -#if LOG +#ifdef LOG "LOG", #endif #if MATCHGECOS @@ -3607,3 +3669,52 @@ char *CompileOptions[] = #endif NULL }; + + +/* +** OS compile options. +*/ + +char *OsCompileOptions[] = +{ +#if HASFLOCK + "HASFLOCK", +#endif +#if HASGETUSERSHELL + "HASGETUSERSHELL", +#endif +#if HASINITGROUPS + "HASINITGROUPS", +#endif +#if HASLSTAT + "HASLSTAT", +#endif +#if HASSETREUID + "HASSETREUID", +#endif +#if HASSETSID + "HASSETSID", +#endif +#if HASSETVBUF + "HASSETVBUF", +#endif +#if HASUNAME + "HASUNAME", +#endif +#if IDENTPROTO + "IDENTPROTO", +#endif +#if IP_SRCROUTE + "IP_SRCROUTE", +#endif +#if SYS5SETPGRP + "SYS5SETPGRP", +#endif +#if SYSTEM5 + "SYSTEM5", +#endif +#if USESETEUID + "USESETEUID", +#endif + NULL +};