xref: /original-bsd/usr.sbin/sendmail/src/conf.c (revision 58b1b499)
1 /*
2  * Copyright (c) 1983 Eric P. Allman
3  * Copyright (c) 1988, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * %sccs.include.redist.c%
7  */
8 
9 #ifndef lint
10 static char sccsid[] = "@(#)conf.c	8.150 (Berkeley) 04/07/95";
11 #endif /* not lint */
12 
13 # include "sendmail.h"
14 # include "pathnames.h"
15 # include <sys/ioctl.h>
16 # include <sys/param.h>
17 
18 /*
19 **  CONF.C -- Sendmail Configuration Tables.
20 **
21 **	Defines the configuration of this installation.
22 **
23 **	Configuration Variables:
24 **		HdrInfo -- a table describing well-known header fields.
25 **			Each entry has the field name and some flags,
26 **			which are described in sendmail.h.
27 **
28 **	Notes:
29 **		I have tried to put almost all the reasonable
30 **		configuration information into the configuration
31 **		file read at runtime.  My intent is that anything
32 **		here is a function of the version of UNIX you
33 **		are running, or is really static -- for example
34 **		the headers are a superset of widely used
35 **		protocols.  If you find yourself playing with
36 **		this file too much, you may be making a mistake!
37 */
38 
39 
40 
41 
42 /*
43 **  Header info table
44 **	Final (null) entry contains the flags used for any other field.
45 **
46 **	Not all of these are actually handled specially by sendmail
47 **	at this time.  They are included as placeholders, to let
48 **	you know that "someday" I intend to have sendmail do
49 **	something with them.
50 */
51 
52 struct hdrinfo	HdrInfo[] =
53 {
54 		/* originator fields, most to least significant  */
55 	"resent-sender",		H_FROM|H_RESENT,
56 	"resent-from",			H_FROM|H_RESENT,
57 	"resent-reply-to",		H_FROM|H_RESENT,
58 	"sender",			H_FROM,
59 	"from",				H_FROM,
60 	"reply-to",			H_FROM,
61 	"full-name",			H_ACHECK,
62 	"return-receipt-to",		H_FROM|H_RECEIPTTO,
63 	"errors-to",			H_FROM|H_ERRORSTO,
64 
65 		/* destination fields */
66 	"to",				H_RCPT,
67 	"resent-to",			H_RCPT|H_RESENT,
68 	"cc",				H_RCPT,
69 	"resent-cc",			H_RCPT|H_RESENT,
70 	"bcc",				H_RCPT|H_STRIPVAL,
71 	"resent-bcc",			H_RCPT|H_STRIPVAL|H_RESENT,
72 	"apparently-to",		H_RCPT,
73 
74 		/* message identification and control */
75 	"message-id",			0,
76 	"resent-message-id",		H_RESENT,
77 	"message",			H_EOH,
78 	"text",				H_EOH,
79 
80 		/* date fields */
81 	"date",				0,
82 	"resent-date",			H_RESENT,
83 
84 		/* trace fields */
85 	"received",			H_TRACE|H_FORCE,
86 	"x400-received",		H_TRACE|H_FORCE,
87 	"via",				H_TRACE|H_FORCE,
88 	"mail-from",			H_TRACE|H_FORCE,
89 
90 		/* miscellaneous fields */
91 	"comments",			H_FORCE,
92 	"return-path",			H_FORCE|H_ACHECK,
93 	"content-transfer-encoding",	H_CTE,
94 	"content-type",			H_CTYPE,
95 	"content-length",		H_ACHECK,
96 
97 	NULL,			0,
98 };
99 
100 
101 
102 /*
103 **  Location of system files/databases/etc.
104 */
105 
106 char	*PidFile =	_PATH_SENDMAILPID;	/* stores daemon proc id */
107 
108 
109 
110 /*
111 **  Privacy values
112 */
113 
114 struct prival PrivacyValues[] =
115 {
116 	"public",		PRIV_PUBLIC,
117 	"needmailhelo",		PRIV_NEEDMAILHELO,
118 	"needexpnhelo",		PRIV_NEEDEXPNHELO,
119 	"needvrfyhelo",		PRIV_NEEDVRFYHELO,
120 	"noexpn",		PRIV_NOEXPN,
121 	"novrfy",		PRIV_NOVRFY,
122 	"restrictmailq",	PRIV_RESTRICTMAILQ,
123 	"restrictqrun",		PRIV_RESTRICTQRUN,
124 	"authwarnings",		PRIV_AUTHWARNINGS,
125 	"noreceipts",		PRIV_NORECEIPTS,
126 	"goaway",		PRIV_GOAWAY,
127 	NULL,			0,
128 };
129 
130 
131 
132 /*
133 **  Miscellaneous stuff.
134 */
135 
136 int	DtableSize =	50;		/* max open files; reset in 4.2bsd */
137 /*
138 **  SETDEFAULTS -- set default values
139 **
140 **	Because of the way freezing is done, these must be initialized
141 **	using direct code.
142 **
143 **	Parameters:
144 **		e -- the default envelope.
145 **
146 **	Returns:
147 **		none.
148 **
149 **	Side Effects:
150 **		Initializes a bunch of global variables to their
151 **		default values.
152 */
153 
154 #define DAYS		* 24 * 60 * 60
155 
156 void
157 setdefaults(e)
158 	register ENVELOPE *e;
159 {
160 	int i;
161 	extern void inittimeouts();
162 	extern void setdefuser();
163 	extern void setupmaps();
164 	extern void setupmailers();
165 
166 	SpaceSub = ' ';				/* option B */
167 	QueueLA = 8;				/* option x */
168 	RefuseLA = 12;				/* option X */
169 	WkRecipFact = 30000L;			/* option y */
170 	WkClassFact = 1800L;			/* option z */
171 	WkTimeFact = 90000L;			/* option Z */
172 	QueueFactor = WkRecipFact * 20;		/* option q */
173 	FileMode = (RealUid != geteuid()) ? 0644 : 0600;
174 						/* option F */
175 	DefUid = 1;				/* option u */
176 	DefGid = 1;				/* option g */
177 	CheckpointInterval = 10;		/* option C */
178 	MaxHopCount = 25;			/* option h */
179 	e->e_sendmode = SM_FORK;		/* option d */
180 	e->e_errormode = EM_PRINT;		/* option e */
181 	SevenBitInput = FALSE;			/* option 7 */
182 	MaxMciCache = 1;			/* option k */
183 	MciCacheTimeout = 300;			/* option K */
184 	LogLevel = 9;				/* option L */
185 	inittimeouts(NULL);			/* option r */
186 	PrivacyFlags = 0;			/* option p */
187 	MimeMode = MM_CVTMIME|MM_PASS8BIT;	/* option 8 */
188 	for (i = 0; i < MAXTOCLASS; i++)
189 	{
190 		TimeOuts.to_q_return[i] = 5 DAYS;	/* option T */
191 		TimeOuts.to_q_warning[i] = 0;		/* option T */
192 	}
193 	ServiceSwitchFile = "/etc/service.switch";
194 	setdefuser();
195 	setupmaps();
196 	setupmailers();
197 }
198 
199 
200 /*
201 **  SETDEFUSER -- set/reset DefUser using DefUid (for initgroups())
202 */
203 
204 void
205 setdefuser()
206 {
207 	struct passwd *defpwent;
208 	static char defuserbuf[40];
209 
210 	DefUser = defuserbuf;
211 	if ((defpwent = sm_getpwuid(DefUid)) != NULL)
212 		strcpy(defuserbuf, defpwent->pw_name);
213 	else
214 		strcpy(defuserbuf, "nobody");
215 }
216 /*
217 **  HOST_MAP_INIT -- initialize host class structures
218 */
219 
220 bool	host_map_init __P((MAP *map, char *args));
221 
222 bool
223 host_map_init(map, args)
224 	MAP *map;
225 	char *args;
226 {
227 	register char *p = args;
228 
229 	for (;;)
230 	{
231 		while (isascii(*p) && isspace(*p))
232 			p++;
233 		if (*p != '-')
234 			break;
235 		switch (*++p)
236 		{
237 		  case 'a':
238 			map->map_app = ++p;
239 			break;
240 		}
241 		while (*p != '\0' && !(isascii(*p) && isspace(*p)))
242 			p++;
243 		if (*p != '\0')
244 			*p++ = '\0';
245 	}
246 	if (map->map_app != NULL)
247 		map->map_app = newstr(map->map_app);
248 	return TRUE;
249 }
250 /*
251 **  SETUPMAILERS -- initialize default mailers
252 */
253 
254 void
255 setupmailers()
256 {
257 	char buf[100];
258 	extern void makemailer();
259 
260 	strcpy(buf, "prog, P=/bin/sh, F=lsoD, A=sh -c $u");
261 	makemailer(buf);
262 
263 	strcpy(buf, "*file*, P=/dev/null, F=lsDFMPEou, A=FILE");
264 	makemailer(buf);
265 
266 	strcpy(buf, "*include*, P=/dev/null, F=su, A=INCLUDE");
267 	makemailer(buf);
268 }
269 /*
270 **  SETUPMAPS -- set up map classes
271 */
272 
273 #define MAPDEF(name, ext, flags, parse, open, close, lookup, store) \
274 	{ \
275 		extern bool parse __P((MAP *, char *)); \
276 		extern bool open __P((MAP *, int)); \
277 		extern void close __P((MAP *)); \
278 		extern char *lookup __P((MAP *, char *, char **, int *)); \
279 		extern void store __P((MAP *, char *, char *)); \
280 		s = stab(name, ST_MAPCLASS, ST_ENTER); \
281 		s->s_mapclass.map_cname = name; \
282 		s->s_mapclass.map_ext = ext; \
283 		s->s_mapclass.map_cflags = flags; \
284 		s->s_mapclass.map_parse = parse; \
285 		s->s_mapclass.map_open = open; \
286 		s->s_mapclass.map_close = close; \
287 		s->s_mapclass.map_lookup = lookup; \
288 		s->s_mapclass.map_store = store; \
289 	}
290 
291 void
292 setupmaps()
293 {
294 	register STAB *s;
295 
296 #ifdef NEWDB
297 	MAPDEF("hash", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
298 		map_parseargs, hash_map_open, db_map_close,
299 		db_map_lookup, db_map_store);
300 
301 	MAPDEF("btree", ".db", MCF_ALIASOK|MCF_REBUILDABLE,
302 		map_parseargs, bt_map_open, db_map_close,
303 		db_map_lookup, db_map_store);
304 #endif
305 
306 #ifdef NDBM
307 	MAPDEF("dbm", ".dir", MCF_ALIASOK|MCF_REBUILDABLE,
308 		map_parseargs, ndbm_map_open, ndbm_map_close,
309 		ndbm_map_lookup, ndbm_map_store);
310 #endif
311 
312 #ifdef NIS
313 	MAPDEF("nis", NULL, MCF_ALIASOK,
314 		map_parseargs, nis_map_open, null_map_close,
315 		nis_map_lookup, null_map_store);
316 #endif
317 
318 #ifdef NISPLUS
319 	MAPDEF("nisplus", NULL, MCF_ALIASOK,
320 		map_parseargs, nisplus_map_open, null_map_close,
321 		nisplus_map_lookup, null_map_store);
322 #endif
323 
324 #ifdef HESIOD
325 	MAPDEF("hesiod", NULL, MCF_ALIASOK|MCF_ALIASONLY,
326 		map_parseargs, null_map_open, null_map_close,
327 		hes_map_lookup, null_map_store);
328 #endif
329 
330 #ifdef NETINFO
331 	MAPDEF("netinfo", NULL, MCF_ALIASOK,
332 		map_parseargs, ni_map_open, null_map_close,
333 		ni_map_lookup, null_map_store);
334 #endif
335 
336 #if 0
337 	MAPDEF("dns", NULL, 0,
338 		dns_map_init, null_map_open, null_map_close,
339 		dns_map_lookup, null_map_store);
340 #endif
341 
342 #if NAMED_BIND
343 	/* best MX DNS lookup */
344 	MAPDEF("bestmx", NULL, MCF_OPTFILE,
345 		map_parseargs, null_map_open, null_map_close,
346 		bestmx_map_lookup, null_map_store);
347 #endif
348 
349 	MAPDEF("host", NULL, 0,
350 		host_map_init, null_map_open, null_map_close,
351 		host_map_lookup, null_map_store);
352 
353 	MAPDEF("text", NULL, MCF_ALIASOK,
354 		map_parseargs, text_map_open, null_map_close,
355 		text_map_lookup, null_map_store);
356 
357 	MAPDEF("stab", NULL, MCF_ALIASOK|MCF_ALIASONLY,
358 		map_parseargs, stab_map_open, null_map_close,
359 		stab_map_lookup, stab_map_store);
360 
361 	MAPDEF("implicit", NULL, MCF_ALIASOK|MCF_ALIASONLY|MCF_REBUILDABLE,
362 		map_parseargs, impl_map_open, impl_map_close,
363 		impl_map_lookup, impl_map_store);
364 
365 	/* access to system passwd file */
366 	MAPDEF("user", NULL, MCF_OPTFILE,
367 		map_parseargs, user_map_open, null_map_close,
368 		user_map_lookup, null_map_store);
369 
370 	/* dequote map */
371 	MAPDEF("dequote", NULL, 0,
372 		dequote_init, null_map_open, null_map_close,
373 		dequote_map, null_map_store);
374 
375 #ifdef USERDB
376 	/* user database */
377 	MAPDEF("userdb", ".db", 0,
378 		map_parseargs, null_map_open, null_map_close,
379 		udb_map_lookup, null_map_store);
380 #endif
381 
382 	/* sequenced maps */
383 	MAPDEF("sequence", NULL, MCF_ALIASOK,
384 		seq_map_parse, null_map_open, null_map_close,
385 		seq_map_lookup, seq_map_store);
386 
387 	/* switched interface to sequenced maps */
388 	MAPDEF("switch", NULL, MCF_ALIASOK,
389 		map_parseargs, switch_map_open, null_map_close,
390 		seq_map_lookup, seq_map_store);
391 }
392 
393 #undef MAPDEF
394 /*
395 **  INITHOSTMAPS -- initial host-dependent maps
396 **
397 **	This should act as an interface to any local service switch
398 **	provided by the host operating system.
399 **
400 **	Parameters:
401 **		none
402 **
403 **	Returns:
404 **		none
405 **
406 **	Side Effects:
407 **		Should define maps "host" and "users" as necessary
408 **		for this OS.  If they are not defined, they will get
409 **		a default value later.  It should check to make sure
410 **		they are not defined first, since it's possible that
411 **		the config file has provided an override.
412 */
413 
414 void
415 inithostmaps()
416 {
417 	register int i;
418 	int nmaps;
419 	char *maptype[MAXMAPSTACK];
420 	short mapreturn[MAXMAPACTIONS];
421 	char buf[MAXLINE];
422 
423 	/*
424 	**  Set up default hosts maps.
425 	*/
426 
427 #if 0
428 	nmaps = switch_map_find("hosts", maptype, mapreturn);
429 	for (i = 0; i < nmaps; i++)
430 	{
431 		if (strcmp(maptype[i], "files") == 0 &&
432 		    stab("hosts.files", ST_MAP, ST_FIND) == NULL)
433 		{
434 			strcpy(buf, "hosts.files text -k 0 -v 1 /etc/hosts");
435 			makemapentry(buf);
436 		}
437 #if NAMED_BIND
438 		else if (strcmp(maptype[i], "dns") == 0 &&
439 		    stab("hosts.dns", ST_MAP, ST_FIND) == NULL)
440 		{
441 			strcpy(buf, "hosts.dns dns A");
442 			makemapentry(buf);
443 		}
444 #endif
445 #ifdef NISPLUS
446 		else if (strcmp(maptype[i], "nisplus") == 0 &&
447 		    stab("hosts.nisplus", ST_MAP, ST_FIND) == NULL)
448 		{
449 			strcpy(buf, "hosts.nisplus nisplus -k name -v address -d hosts.org_dir");
450 			makemapentry(buf);
451 		}
452 #endif
453 #ifdef NIS
454 		else if (strcmp(maptype[i], "nis") == 0 &&
455 		    stab("hosts.nis", ST_MAP, ST_FIND) == NULL)
456 		{
457 			strcpy(buf, "hosts.nis nis -d -k 0 -v 1 hosts.byname");
458 			makemapentry(buf);
459 		}
460 #endif
461 	}
462 #endif
463 
464 	/*
465 	**  Make sure we have a host map.
466 	*/
467 
468 	if (stab("host", ST_MAP, ST_FIND) == NULL)
469 	{
470 		/* user didn't initialize: set up host map */
471 		strcpy(buf, "host host");
472 #if NAMED_BIND
473 		if (ConfigLevel >= 2)
474 			strcat(buf, " -a.");
475 #endif
476 		makemapentry(buf);
477 	}
478 
479 	/*
480 	**  Set up default aliases maps
481 	*/
482 
483 	nmaps = switch_map_find("aliases", maptype, mapreturn);
484 	for (i = 0; i < nmaps; i++)
485 	{
486 		if (strcmp(maptype[i], "files") == 0 &&
487 		    stab("aliases.files", ST_MAP, ST_FIND) == NULL)
488 		{
489 			strcpy(buf, "aliases.files implicit /etc/aliases");
490 			makemapentry(buf);
491 		}
492 #ifdef NISPLUS
493 		else if (strcmp(maptype[i], "nisplus") == 0 &&
494 		    stab("aliases.nisplus", ST_MAP, ST_FIND) == NULL)
495 		{
496 			strcpy(buf, "aliases.nisplus nisplus -kalias -vexpansion -d mail_aliases.org_dir");
497 			makemapentry(buf);
498 		}
499 #endif
500 #ifdef NIS
501 		else if (strcmp(maptype[i], "nis") == 0 &&
502 		    stab("aliases.nis", ST_MAP, ST_FIND) == NULL)
503 		{
504 			strcpy(buf, "aliases.nis nis -d mail.aliases");
505 			makemapentry(buf);
506 		}
507 #endif
508 	}
509 	if (stab("aliases", ST_MAP, ST_FIND) == NULL)
510 	{
511 		strcpy(buf, "aliases switch aliases");
512 		makemapentry(buf);
513 	}
514 	strcpy(buf, "switch:aliases");
515 	setalias(buf);
516 
517 #if 0		/* "user" map class is a better choice */
518 	/*
519 	**  Set up default users maps.
520 	*/
521 
522 	nmaps = switch_map_find("passwd", maptype, mapreturn);
523 	for (i = 0; i < nmaps; i++)
524 	{
525 		if (strcmp(maptype[i], "files") == 0 &&
526 		    stab("users.files", ST_MAP, ST_FIND) == NULL)
527 		{
528 			strcpy(buf, "users.files text -m -z: -k0 -v6 /etc/passwd");
529 			makemapentry(buf);
530 		}
531 #ifdef NISPLUS
532 		else if (strcmp(maptype[i], "nisplus") == 0 &&
533 		    stab("users.nisplus", ST_MAP, ST_FIND) == NULL)
534 		{
535 			strcpy(buf, "users.nisplus nisplus -m -kname -vhome -d passwd.org_dir");
536 			makemapentry(buf);
537 		}
538 #endif
539 #ifdef NIS
540 		else if (strcmp(maptype[i], "nis") == 0 &&
541 		    stab("users.nis", ST_MAP, ST_FIND) == NULL)
542 		{
543 			strcpy(buf, "users.nis nis -m -d passwd.byname");
544 			makemapentry(buf);
545 		}
546 #endif
547 #ifdef HESIOD
548 		else if (strcmp(maptype[i], "hesiod") == 0) &&
549 		    stab("users.hesiod", ST_MAP, ST_FIND) == NULL)
550 		{
551 			strcpy(buf, "users.hesiod hesiod");
552 			makemapentry(buf);
553 		}
554 #endif
555 	}
556 	if (stab("users", ST_MAP, ST_FIND) == NULL)
557 	{
558 		strcpy(buf, "users switch -m passwd");
559 		makemapentry(buf);
560 	}
561 #endif
562 }
563 /*
564 **  SWITCH_MAP_FIND -- find the list of types associated with a map
565 **
566 **	This is the system-dependent interface to the service switch.
567 **
568 **	Parameters:
569 **		service -- the name of the service of interest.
570 **		maptype -- an out-array of strings containing the types
571 **			of access to use for this service.  There can
572 **			be at most MAXMAPSTACK types for a single service.
573 **		mapreturn -- an out-array of return information bitmaps
574 **			for the map.
575 **
576 **	Returns:
577 **		The number of map types filled in, or -1 for failure.
578 */
579 
580 #ifdef SOLARIS
581 # include <nsswitch.h>
582 #endif
583 
584 #if defined(ultrix) || defined(__osf__)
585 # include <sys/svcinfo.h>
586 #endif
587 
588 int
589 switch_map_find(service, maptype, mapreturn)
590 	char *service;
591 	char *maptype[MAXMAPSTACK];
592 	short mapreturn[MAXMAPACTIONS];
593 {
594 	register FILE *fp;
595 	int svcno;
596 	static char buf[MAXLINE];
597 
598 #ifdef SOLARIS
599 	struct __nsw_switchconfig *nsw_conf;
600 	enum __nsw_parse_err pserr;
601 	struct __nsw_lookup *lk;
602 	int nsw_rc;
603 	static struct __nsw_lookup lkp0 =
604 		{ "files", {1, 0, 0, 0}, NULL, NULL };
605 	static struct __nsw_switchconfig lkp_default =
606 		{ 0, "sendmail", 3, &lkp0 };
607 
608 	if ((nsw_conf = __nsw_getconfig(service, &pserr)) == NULL)
609 		lk = lkp_default.lookups;
610 	else
611 		lk = nsw_conf->lookups;
612 	svcno = 0;
613 	while (lk != NULL)
614 	{
615 		maptype[svcno] = lk->service_name;
616 		if (lk->actions[__NSW_NOTFOUND] == __NSW_RETURN)
617 			mapreturn[MA_NOTFOUND] |= 1 << svcno;
618 		if (lk->actions[__NSW_TRYAGAIN] == __NSW_RETURN)
619 			mapreturn[MA_TRYAGAIN] |= 1 << svcno;
620 		if (lk->actions[__NSW_UNAVAIL] == __NSW_RETURN)
621 			mapreturn[MA_TRYAGAIN] |= 1 << svcno;
622 		svcno++;
623 		lk = lk->next;
624 	}
625 	return svcno;
626 #endif
627 
628 #if defined(ultrix) || defined(__osf__)
629 	struct svcinfo *svcinfo;
630 	int svc;
631 
632 	svcinfo = getsvc();
633 	if (svcinfo == NULL)
634 		goto punt;
635 	if (strcmp(service, "hosts") == 0)
636 		svc = SVC_HOSTS;
637 	else if (strcmp(service, "aliases") == 0)
638 		svc = SVC_ALIASES;
639 	else if (strcmp(service, "passwd") == 0)
640 		svc = SVC_PASSWD;
641 	else
642 		return -1;
643 	for (svcno = 0; svcno < SVC_PATHSIZE; svcno++)
644 	{
645 		switch (svcinfo->svcpath[svc][svcno])
646 		{
647 		  case SVC_LOCAL:
648 			maptype[svcno] = "files";
649 			break;
650 
651 		  case SVC_YP:
652 			maptype[svcno] = "nis";
653 			break;
654 
655 		  case SVC_BIND:
656 			maptype[svcno] = "dns";
657 			break;
658 
659 #ifdef SVC_HESIOD
660 		  case SVC_HESIOD:
661 			maptype[svcno] = "hesiod";
662 			break;
663 #endif
664 
665 		  case SVC_LAST:
666 			return svcno;
667 		}
668 	}
669 	return svcno;
670 #endif
671 
672 #if !defined(SOLARIS) && !defined(ultrix) && !defined(__osf__)
673 	/*
674 	**  Fall-back mechanism.
675 	*/
676 
677 	svcno = 0;
678 	fp = fopen(ServiceSwitchFile, "r");
679 	if (fp != NULL)
680 	{
681 		while (fgets(buf, sizeof buf, fp) != NULL)
682 		{
683 			register char *p;
684 
685 			p = strpbrk(buf, "#\n");
686 			if (p != NULL)
687 				*p = '\0';
688 			p = strpbrk(buf, " \t");
689 			if (p != NULL)
690 				*p++ = '\0';
691 			if (strcmp(buf, service) != 0)
692 				continue;
693 
694 			/* got the right service -- extract data */
695 			do
696 			{
697 				while (isspace(*p))
698 					p++;
699 				if (*p == '\0')
700 					break;
701 				maptype[svcno++] = p;
702 				p = strpbrk(p, " \t");
703 				if (p != NULL)
704 					*p++ = '\0';
705 			} while (p != NULL);
706 			break;
707 		}
708 		fclose(fp);
709 		return svcno;
710 	}
711 #endif
712 
713 	/* if the service file doesn't work, use an absolute fallback */
714   punt:
715 	if (strcmp(service, "aliases") == 0)
716 	{
717 		maptype[svcno++] = "files";
718 #ifdef AUTO_NIS_ALIASES
719 # ifdef NISPLUS
720 		maptype[svcno++] = "nisplus";
721 # endif
722 # ifdef NIS
723 		maptype[svcno++] = "nis";
724 # endif
725 #endif
726 		return svcno;
727 	}
728 	if (strcmp(service, "hosts") == 0)
729 	{
730 # if NAMED_BIND
731 		maptype[svcno++] = "dns";
732 # else
733 #  if defined(sun) && !defined(BSD) && !defined(SOLARIS)
734 		/* SunOS */
735 		maptype[svcno++] = "nis";
736 #  endif
737 # endif
738 		maptype[svcno++] = "files";
739 		return svcno;
740 	}
741 	return -1;
742 }
743 /*
744 **  USERNAME -- return the user id of the logged in user.
745 **
746 **	Parameters:
747 **		none.
748 **
749 **	Returns:
750 **		The login name of the logged in user.
751 **
752 **	Side Effects:
753 **		none.
754 **
755 **	Notes:
756 **		The return value is statically allocated.
757 */
758 
759 char *
760 username()
761 {
762 	static char *myname = NULL;
763 	extern char *getlogin();
764 	register struct passwd *pw;
765 
766 	/* cache the result */
767 	if (myname == NULL)
768 	{
769 		myname = getlogin();
770 		if (myname == NULL || myname[0] == '\0')
771 		{
772 			pw = sm_getpwuid(RealUid);
773 			if (pw != NULL)
774 				myname = newstr(pw->pw_name);
775 		}
776 		else
777 		{
778 			uid_t uid = RealUid;
779 
780 			myname = newstr(myname);
781 			if ((pw = sm_getpwnam(myname)) == NULL ||
782 			      (uid != 0 && uid != pw->pw_uid))
783 			{
784 				pw = sm_getpwuid(uid);
785 				if (pw != NULL)
786 					myname = newstr(pw->pw_name);
787 			}
788 		}
789 		if (myname == NULL || myname[0] == '\0')
790 		{
791 			syserr("554 Who are you?");
792 			myname = "postmaster";
793 		}
794 	}
795 
796 	return (myname);
797 }
798 /*
799 **  TTYPATH -- Get the path of the user's tty
800 **
801 **	Returns the pathname of the user's tty.  Returns NULL if
802 **	the user is not logged in or if s/he has write permission
803 **	denied.
804 **
805 **	Parameters:
806 **		none
807 **
808 **	Returns:
809 **		pathname of the user's tty.
810 **		NULL if not logged in or write permission denied.
811 **
812 **	Side Effects:
813 **		none.
814 **
815 **	WARNING:
816 **		Return value is in a local buffer.
817 **
818 **	Called By:
819 **		savemail
820 */
821 
822 char *
823 ttypath()
824 {
825 	struct stat stbuf;
826 	register char *pathn;
827 	extern char *ttyname();
828 	extern char *getlogin();
829 
830 	/* compute the pathname of the controlling tty */
831 	if ((pathn = ttyname(2)) == NULL && (pathn = ttyname(1)) == NULL &&
832 	    (pathn = ttyname(0)) == NULL)
833 	{
834 		errno = 0;
835 		return (NULL);
836 	}
837 
838 	/* see if we have write permission */
839 	if (stat(pathn, &stbuf) < 0 || !bitset(02, stbuf.st_mode))
840 	{
841 		errno = 0;
842 		return (NULL);
843 	}
844 
845 	/* see if the user is logged in */
846 	if (getlogin() == NULL)
847 		return (NULL);
848 
849 	/* looks good */
850 	return (pathn);
851 }
852 /*
853 **  CHECKCOMPAT -- check for From and To person compatible.
854 **
855 **	This routine can be supplied on a per-installation basis
856 **	to determine whether a person is allowed to send a message.
857 **	This allows restriction of certain types of internet
858 **	forwarding or registration of users.
859 **
860 **	If the hosts are found to be incompatible, an error
861 **	message should be given using "usrerr" and 0 should
862 **	be returned.
863 **
864 **	EF_NO_BODY_RETN can be set in e->e_flags to suppress the
865 **	body during the return-to-sender function; this should be done
866 **	on huge messages.  This bit may already be set by the ESMTP
867 **	protocol.
868 **
869 **	Parameters:
870 **		to -- the person being sent to.
871 **
872 **	Returns:
873 **		an exit status
874 **
875 **	Side Effects:
876 **		none (unless you include the usrerr stuff)
877 */
878 
879 int
880 checkcompat(to, e)
881 	register ADDRESS *to;
882 	register ENVELOPE *e;
883 {
884 # ifdef lint
885 	if (to == NULL)
886 		to++;
887 # endif /* lint */
888 
889 	if (tTd(49, 1))
890 		printf("checkcompat(to=%s, from=%s)\n",
891 			to->q_paddr, e->e_from.q_paddr);
892 
893 # ifdef EXAMPLE_CODE
894 	/* this code is intended as an example only */
895 	register STAB *s;
896 
897 	s = stab("arpa", ST_MAILER, ST_FIND);
898 	if (s != NULL && strcmp(e->e_from.q_mailer->m_name, "local") != 0 &&
899 	    to->q_mailer == s->s_mailer)
900 	{
901 		usrerr("553 No ARPA mail through this machine: see your system administration");
902 		/* e->e_flags |= EF_NO_BODY_RETN; to supress body on return */
903 		return (EX_UNAVAILABLE);
904 	}
905 # endif /* EXAMPLE_CODE */
906 	return (EX_OK);
907 }
908 /*
909 **  SETSIGNAL -- set a signal handler
910 **
911 **	This is essentially old BSD "signal(3)".
912 */
913 
914 sigfunc_t
915 setsignal(sig, handler)
916 	int sig;
917 	sigfunc_t handler;
918 {
919 #if defined(SYS5SIGNALS) || defined(BSD4_3) || defined(_AUX_SOURCE)
920 	return signal(sig, handler);
921 #else
922 	struct sigaction n, o;
923 
924 	bzero(&n, sizeof n);
925 	n.sa_handler = handler;
926 # ifdef SA_RESTART
927 	n.sa_flags = SA_RESTART;
928 # endif
929 	if (sigaction(sig, &n, &o) < 0)
930 		return SIG_ERR;
931 	return o.sa_handler;
932 #endif
933 }
934 /*
935 **  HOLDSIGS -- arrange to hold all signals
936 **
937 **	Parameters:
938 **		none.
939 **
940 **	Returns:
941 **		none.
942 **
943 **	Side Effects:
944 **		Arranges that signals are held.
945 */
946 
947 void
948 holdsigs()
949 {
950 }
951 /*
952 **  RLSESIGS -- arrange to release all signals
953 **
954 **	This undoes the effect of holdsigs.
955 **
956 **	Parameters:
957 **		none.
958 **
959 **	Returns:
960 **		none.
961 **
962 **	Side Effects:
963 **		Arranges that signals are released.
964 */
965 
966 void
967 rlsesigs()
968 {
969 }
970 /*
971 **  INIT_MD -- do machine dependent initializations
972 **
973 **	Systems that have global modes that should be set should do
974 **	them here rather than in main.
975 */
976 
977 #ifdef _AUX_SOURCE
978 # include	<compat.h>
979 #endif
980 
981 void
982 init_md(argc, argv)
983 	int argc;
984 	char **argv;
985 {
986 #ifdef _AUX_SOURCE
987 	setcompat(getcompat() | COMPAT_BSDPROT);
988 #endif
989 
990 #ifdef VENDOR_DEFAULT
991 	VendorCode = VENDOR_DEFAULT;
992 #else
993 	VendorCode = VENDOR_BERKELEY;
994 #endif
995 }
996 /*
997 **  INIT_VENDOR_MACROS -- vendor-dependent macro initializations
998 **
999 **	Called once, on startup.
1000 **
1001 **	Parameters:
1002 **		e -- the global envelope.
1003 **
1004 **	Returns:
1005 **		none.
1006 **
1007 **	Side Effects:
1008 **		vendor-dependent.
1009 */
1010 
1011 void
1012 init_vendor_macros(e)
1013 	register ENVELOPE *e;
1014 {
1015 }
1016 /*
1017 **  GETLA -- get the current load average
1018 **
1019 **	This code stolen from la.c.
1020 **
1021 **	Parameters:
1022 **		none.
1023 **
1024 **	Returns:
1025 **		The current load average as an integer.
1026 **
1027 **	Side Effects:
1028 **		none.
1029 */
1030 
1031 /* try to guess what style of load average we have */
1032 #define LA_ZERO		1	/* always return load average as zero */
1033 #define LA_INT		2	/* read kmem for avenrun; interpret as long */
1034 #define LA_FLOAT	3	/* read kmem for avenrun; interpret as float */
1035 #define LA_SUBR		4	/* call getloadavg */
1036 #define LA_MACH		5	/* MACH load averages (as on NeXT boxes) */
1037 #define LA_SHORT	6	/* read kmem for avenrun; interpret as short */
1038 #define LA_PROCSTR	7	/* read string ("1.17") from /proc/loadavg */
1039 
1040 /* do guesses based on general OS type */
1041 #ifndef LA_TYPE
1042 # define LA_TYPE	LA_ZERO
1043 #endif
1044 
1045 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_FLOAT) || (LA_TYPE == LA_SHORT)
1046 
1047 #include <nlist.h>
1048 
1049 #ifdef IRIX64
1050 # define nlist		nlist64
1051 #endif
1052 
1053 #ifndef LA_AVENRUN
1054 # ifdef SYSTEM5
1055 #  define LA_AVENRUN	"avenrun"
1056 # else
1057 #  define LA_AVENRUN	"_avenrun"
1058 # endif
1059 #endif
1060 
1061 /* _PATH_UNIX should be defined in <paths.h> */
1062 #ifndef _PATH_UNIX
1063 # if defined(SYSTEM5)
1064 #  define _PATH_UNIX	"/unix"
1065 # else
1066 #  define _PATH_UNIX	"/vmunix"
1067 # endif
1068 #endif
1069 
1070 struct	nlist Nl[] =
1071 {
1072 	{ LA_AVENRUN },
1073 #define	X_AVENRUN	0
1074 	{ 0 },
1075 };
1076 
1077 #ifndef FSHIFT
1078 # if defined(unixpc)
1079 #  define FSHIFT	5
1080 # endif
1081 
1082 # if defined(__alpha) || defined(IRIX)
1083 #  define FSHIFT	10
1084 # endif
1085 
1086 # if defined(_AIX3)
1087 #  define FSHIFT	16
1088 # endif
1089 #endif
1090 
1091 #ifndef FSHIFT
1092 # define FSHIFT		8
1093 #endif
1094 
1095 #ifndef FSCALE
1096 # define FSCALE		(1 << FSHIFT)
1097 #endif
1098 
1099 getla()
1100 {
1101 	static int kmem = -1;
1102 #if LA_TYPE == LA_INT
1103 	long avenrun[3];
1104 #else
1105 # if LA_TYPE == LA_SHORT
1106 	short avenrun[3];
1107 # else
1108 	double avenrun[3];
1109 # endif
1110 #endif
1111 	extern off_t lseek();
1112 	extern int errno;
1113 
1114 	if (kmem < 0)
1115 	{
1116 		kmem = open("/dev/kmem", 0, 0);
1117 		if (kmem < 0)
1118 		{
1119 			if (tTd(3, 1))
1120 				printf("getla: open(/dev/kmem): %s\n",
1121 					errstring(errno));
1122 			return (-1);
1123 		}
1124 		(void) fcntl(kmem, F_SETFD, 1);
1125 #ifdef _AIX3
1126 		if (knlist(Nl, 1, sizeof Nl[0]) < 0)
1127 #else
1128 		if (nlist(_PATH_UNIX, Nl) < 0)
1129 #endif
1130 		{
1131 			if (tTd(3, 1))
1132 				printf("getla: nlist(%s): %s\n", _PATH_UNIX,
1133 					errstring(errno));
1134 			return (-1);
1135 		}
1136 		if (Nl[X_AVENRUN].n_value == 0)
1137 		{
1138 			if (tTd(3, 1))
1139 				printf("getla: nlist(%s, %s) ==> 0\n",
1140 					_PATH_UNIX, LA_AVENRUN);
1141 			return (-1);
1142 		}
1143 #ifdef NAMELISTMASK
1144 		Nl[X_AVENRUN].n_value &= NAMELISTMASK;
1145 #endif
1146 	}
1147 	if (tTd(3, 20))
1148 		printf("getla: symbol address = %#x\n", Nl[X_AVENRUN].n_value);
1149 	if (lseek(kmem, (off_t) Nl[X_AVENRUN].n_value, SEEK_SET) == -1 ||
1150 	    read(kmem, (char *) avenrun, sizeof(avenrun)) < sizeof(avenrun))
1151 	{
1152 		/* thank you Ian */
1153 		if (tTd(3, 1))
1154 			printf("getla: lseek or read: %s\n", errstring(errno));
1155 		return (-1);
1156 	}
1157 #if (LA_TYPE == LA_INT) || (LA_TYPE == LA_SHORT)
1158 	if (tTd(3, 5))
1159 	{
1160 		printf("getla: avenrun = %d", avenrun[0]);
1161 		if (tTd(3, 15))
1162 			printf(", %d, %d", avenrun[1], avenrun[2]);
1163 		printf("\n");
1164 	}
1165 	if (tTd(3, 1))
1166 		printf("getla: %d\n", (int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1167 	return ((int) (avenrun[0] + FSCALE/2) >> FSHIFT);
1168 #else
1169 	if (tTd(3, 5))
1170 	{
1171 		printf("getla: avenrun = %g", avenrun[0]);
1172 		if (tTd(3, 15))
1173 			printf(", %g, %g", avenrun[1], avenrun[2]);
1174 		printf("\n");
1175 	}
1176 	if (tTd(3, 1))
1177 		printf("getla: %d\n", (int) (avenrun[0] +0.5));
1178 	return ((int) (avenrun[0] + 0.5));
1179 #endif
1180 }
1181 
1182 #else
1183 #if LA_TYPE == LA_SUBR
1184 
1185 #ifdef DGUX
1186 
1187 #include <sys/dg_sys_info.h>
1188 
1189 int
1190 getla()
1191 {
1192 	struct dg_sys_info_load_info load_info;
1193 
1194 	dg_sys_info((long *)&load_info,
1195 		DG_SYS_INFO_LOAD_INFO_TYPE, DG_SYS_INFO_LOAD_VERSION_0);
1196 
1197         if (tTd(3, 1))
1198                 printf("getla: %d\n", (int) (load_info.one_minute + 0.5));
1199 
1200 	return((int) (load_info.one_minute + 0.5));
1201 }
1202 
1203 #else
1204 # ifdef __hpux
1205 
1206 #  include <sys/param.h>
1207 #  include <sys/pstat.h>
1208 
1209 int
1210 getla()
1211 {
1212 	struct pst_dynamic pstd;
1213 
1214 	if (pstat_getdynamic(&pstd, sizeof(struct pst_dynamic),
1215 			     (size_t) 1 ,0) == -1)
1216 		return 0;
1217 
1218         if (tTd(3, 1))
1219                 printf("getla: %d\n", (int) (pstd.psd_avg_1_min + 0.5));
1220 
1221 	return (int) (pstd.psd_avg_1_min + 0.5);
1222 }
1223 
1224 # else
1225 
1226 int
1227 getla()
1228 {
1229 	double avenrun[3];
1230 
1231 	if (getloadavg(avenrun, sizeof(avenrun) / sizeof(avenrun[0])) < 0)
1232 	{
1233 		if (tTd(3, 1))
1234 			perror("getla: getloadavg failed:");
1235 		return (-1);
1236 	}
1237 	if (tTd(3, 1))
1238 		printf("getla: %d\n", (int) (avenrun[0] +0.5));
1239 	return ((int) (avenrun[0] + 0.5));
1240 }
1241 
1242 # endif /* __hpux */
1243 #endif /* DGUX */
1244 #else
1245 #if LA_TYPE == LA_MACH
1246 
1247 /*
1248 **  This has been tested on NEXTSTEP release 2.1/3.X.
1249 */
1250 
1251 #if defined(NX_CURRENT_COMPILER_RELEASE) && NX_CURRENT_COMPILER_RELEASE > NX_COMPILER_RELEASE_3_0
1252 # include <mach/mach.h>
1253 #else
1254 # include <mach.h>
1255 #endif
1256 
1257 getla()
1258 {
1259 	processor_set_t default_set;
1260 	kern_return_t error;
1261 	unsigned int info_count;
1262 	struct processor_set_basic_info info;
1263 	host_t host;
1264 
1265 	error = processor_set_default(host_self(), &default_set);
1266 	if (error != KERN_SUCCESS)
1267 		return -1;
1268 	info_count = PROCESSOR_SET_BASIC_INFO_COUNT;
1269 	if (processor_set_info(default_set, PROCESSOR_SET_BASIC_INFO,
1270 			       &host, (processor_set_info_t)&info,
1271 			       &info_count) != KERN_SUCCESS)
1272 	{
1273 		return -1;
1274 	}
1275 	return (int) (info.load_average + (LOAD_SCALE / 2)) / LOAD_SCALE;
1276 }
1277 
1278 
1279 #else
1280 #if LA_TYPE == LA_PROCSTR
1281 
1282 /*
1283 **  Read /proc/loadavg for the load average.  This is assumed to be
1284 **  in a format like "0.15 0.12 0.06".
1285 **
1286 **	Initially intended for Linux.  This has been in the kernel
1287 **	since at least 0.99.15.
1288 */
1289 
1290 # ifndef _PATH_LOADAVG
1291 #  define _PATH_LOADAVG	"/proc/loadavg"
1292 # endif
1293 
1294 int
1295 getla()
1296 {
1297 	double avenrun;
1298 	register int result;
1299 	FILE *fp;
1300 
1301 	fp = fopen(_PATH_LOADAVG, "r");
1302 	if (fp == NULL)
1303 	{
1304 		if (tTd(3, 1))
1305 			printf("getla: fopen(%s): %s\n",
1306 				_PATH_LOADAVG, errstring(errno));
1307 		return -1;
1308 	}
1309 	result = fscanf(fp, "%lf", &avenrun);
1310 	fclose(fp);
1311 	if (result != 1)
1312 	{
1313 		if (tTd(3, 1))
1314 			printf("getla: fscanf() = %d: %s\n",
1315 				result, errstring(errno));
1316 		return -1;
1317 	}
1318 
1319 	if (tTd(3, 1))
1320 		printf("getla(): %.2f\n", avenrun);
1321 
1322 	return ((int) (avenrun + 0.5));
1323 }
1324 
1325 #else
1326 
1327 getla()
1328 {
1329 	if (tTd(3, 1))
1330 		printf("getla: ZERO\n");
1331 	return (0);
1332 }
1333 
1334 #endif
1335 #endif
1336 #endif
1337 #endif
1338 
1339 
1340 /*
1341  * Copyright 1989 Massachusetts Institute of Technology
1342  *
1343  * Permission to use, copy, modify, distribute, and sell this software and its
1344  * documentation for any purpose is hereby granted without fee, provided that
1345  * the above copyright notice appear in all copies and that both that
1346  * copyright notice and this permission notice appear in supporting
1347  * documentation, and that the name of M.I.T. not be used in advertising or
1348  * publicity pertaining to distribution of the software without specific,
1349  * written prior permission.  M.I.T. makes no representations about the
1350  * suitability of this software for any purpose.  It is provided "as is"
1351  * without express or implied warranty.
1352  *
1353  * M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
1354  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL M.I.T.
1355  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1356  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
1357  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
1358  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1359  *
1360  * Authors:  Many and varied...
1361  */
1362 
1363 /* Non Apollo stuff removed by Don Lewis 11/15/93 */
1364 #ifndef lint
1365 static char  rcsid[] = "@(#)$Id: getloadavg.c,v 1.16 1991/06/21 12:51:15 paul Exp $";
1366 #endif /* !lint */
1367 
1368 #ifdef apollo
1369 # undef volatile
1370 #    include <apollo/base.h>
1371 
1372 /* ARGSUSED */
1373 int getloadavg( call_data )
1374      caddr_t	call_data;	/* pointer to (double) return value */
1375 {
1376      double *avenrun = (double *) call_data;
1377      int i;
1378      status_$t      st;
1379      long loadav[3];
1380      proc1_$get_loadav(loadav, &st);
1381      *avenrun = loadav[0] / (double) (1 << 16);
1382      return(0);
1383 }
1384 #   endif /* apollo */
1385 /*
1386 **  SHOULDQUEUE -- should this message be queued or sent?
1387 **
1388 **	Compares the message cost to the load average to decide.
1389 **
1390 **	Parameters:
1391 **		pri -- the priority of the message in question.
1392 **		ctime -- the message creation time.
1393 **
1394 **	Returns:
1395 **		TRUE -- if this message should be queued up for the
1396 **			time being.
1397 **		FALSE -- if the load is low enough to send this message.
1398 **
1399 **	Side Effects:
1400 **		none.
1401 */
1402 
1403 bool
1404 shouldqueue(pri, ctime)
1405 	long pri;
1406 	time_t ctime;
1407 {
1408 	bool rval;
1409 
1410 	if (tTd(3, 30))
1411 		printf("shouldqueue: CurrentLA=%d, pri=%d: ", CurrentLA, pri);
1412 	if (CurrentLA < QueueLA)
1413 	{
1414 		if (tTd(3, 30))
1415 			printf("FALSE (CurrentLA < QueueLA)\n");
1416 		return (FALSE);
1417 	}
1418 	if (CurrentLA >= RefuseLA)
1419 	{
1420 		if (tTd(3, 30))
1421 			printf("TRUE (CurrentLA >= RefuseLA)\n");
1422 		return (TRUE);
1423 	}
1424 	rval = pri > (QueueFactor / (CurrentLA - QueueLA + 1));
1425 	if (tTd(3, 30))
1426 		printf("%s (by calculation)\n", rval ? "TRUE" : "FALSE");
1427 	return rval;
1428 }
1429 /*
1430 **  REFUSECONNECTIONS -- decide if connections should be refused
1431 **
1432 **	Parameters:
1433 **		none.
1434 **
1435 **	Returns:
1436 **		TRUE if incoming SMTP connections should be refused
1437 **			(for now).
1438 **		FALSE if we should accept new work.
1439 **
1440 **	Side Effects:
1441 **		none.
1442 */
1443 
1444 bool
1445 refuseconnections()
1446 {
1447 	extern bool enoughspace();
1448 
1449 #ifdef XLA
1450 	if (!xla_smtp_ok())
1451 		return TRUE;
1452 #endif
1453 
1454 	/* this is probably too simplistic */
1455 	return CurrentLA >= RefuseLA || !enoughspace(MinBlocksFree + 1);
1456 }
1457 /*
1458 **  SETPROCTITLE -- set process title for ps
1459 **
1460 **	Parameters:
1461 **		fmt -- a printf style format string.
1462 **		a, b, c -- possible parameters to fmt.
1463 **
1464 **	Returns:
1465 **		none.
1466 **
1467 **	Side Effects:
1468 **		Clobbers argv of our main procedure so ps(1) will
1469 **		display the title.
1470 */
1471 
1472 #define SPT_NONE	0	/* don't use it at all */
1473 #define SPT_REUSEARGV	1	/* cover argv with title information */
1474 #define SPT_BUILTIN	2	/* use libc builtin */
1475 #define SPT_PSTAT	3	/* use pstat(PSTAT_SETCMD, ...) */
1476 #define SPT_PSSTRINGS	4	/* use PS_STRINGS->... */
1477 #define SPT_WRITEUDOT	5	/* write u. area in kmem */
1478 
1479 #ifndef SPT_TYPE
1480 # define SPT_TYPE	SPT_REUSEARGV
1481 #endif
1482 
1483 #if SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN
1484 
1485 # if SPT_TYPE == SPT_PSTAT
1486 #  include <sys/pstat.h>
1487 # endif
1488 # if SPT_TYPE == SPT_PSSTRINGS
1489 #  include <machine/vmparam.h>
1490 #  include <sys/exec.h>
1491 #  ifndef PS_STRINGS	/* hmmmm....  apparently not available after all */
1492 #   undef SPT_TYPE
1493 #   define SPT_TYPE	SPT_REUSEARGV
1494 #  else
1495 #   ifndef NKPDE			/* FreeBSD 2.0 */
1496 #    define NKPDE 63
1497 typedef unsigned int	*pt_entry_t;
1498 #   endif
1499 #  endif
1500 # endif
1501 
1502 # if SPT_TYPE == SPT_PSSTRINGS
1503 #  define SETPROC_STATIC	static
1504 # else
1505 #  define SETPROC_STATIC
1506 # endif
1507 
1508 # ifndef SPT_PADCHAR
1509 #  define SPT_PADCHAR	' '
1510 # endif
1511 
1512 #endif /* SPT_TYPE != SPT_NONE && SPT_TYPE != SPT_BUILTIN */
1513 
1514 #if SPT_TYPE != SPT_BUILTIN
1515 
1516 /*VARARGS1*/
1517 void
1518 # ifdef __STDC__
1519 setproctitle(char *fmt, ...)
1520 # else
1521 setproctitle(fmt, va_alist)
1522 	char *fmt;
1523 	va_dcl
1524 # endif
1525 {
1526 # if SPT_TYPE != SPT_NONE
1527 	register char *p;
1528 	register int i;
1529 	SETPROC_STATIC char buf[MAXLINE];
1530 	VA_LOCAL_DECL
1531 #  if SPT_TYPE == SPT_PSTAT
1532 	union pstun pst;
1533 #  endif
1534 	extern char **Argv;
1535 	extern char *LastArgv;
1536 
1537 	p = buf;
1538 
1539 	/* print sendmail: heading for grep */
1540 	(void) strcpy(p, "sendmail: ");
1541 	p += strlen(p);
1542 
1543 	/* print the argument string */
1544 	VA_START(fmt);
1545 	(void) vsprintf(p, fmt, ap);
1546 	VA_END;
1547 
1548 	i = strlen(buf);
1549 
1550 #  if SPT_TYPE == SPT_PSTAT
1551 	pst.pst_command = buf;
1552 	pstat(PSTAT_SETCMD, pst, i, 0, 0);
1553 #  else
1554 #   if SPT_TYPE == SPT_PSSTRINGS
1555 	PS_STRINGS->ps_nargvstr = 1;
1556 	PS_STRINGS->ps_argvstr = buf;
1557 #   else
1558 	if (i > LastArgv - Argv[0] - 2)
1559 	{
1560 		i = LastArgv - Argv[0] - 2;
1561 		buf[i] = '\0';
1562 	}
1563 	(void) strcpy(Argv[0], buf);
1564 	p = &Argv[0][i];
1565 	while (p < LastArgv)
1566 		*p++ = SPT_PADCHAR;
1567 	Argv[1] = NULL;
1568 #   endif /* SPT_TYPE == SPT_PSSTRINGS */
1569 #  endif /* SPT_TYPE == SPT_PSTAT */
1570 # endif /* SPT_TYPE != SPT_NONE */
1571 }
1572 
1573 #endif /* SPT_TYPE != SPT_BUILTIN */
1574 /*
1575 **  REAPCHILD -- pick up the body of my child, lest it become a zombie
1576 **
1577 **	Parameters:
1578 **		sig -- the signal that got us here (unused).
1579 **
1580 **	Returns:
1581 **		none.
1582 **
1583 **	Side Effects:
1584 **		Picks up extant zombies.
1585 */
1586 
1587 void
1588 reapchild(sig)
1589 	int sig;
1590 {
1591 	int olderrno = errno;
1592 # ifdef HASWAITPID
1593 	auto int status;
1594 	int count;
1595 	int pid;
1596 
1597 	count = 0;
1598 	while ((pid = waitpid(-1, &status, WNOHANG)) > 0)
1599 	{
1600 		if (count++ > 1000)
1601 		{
1602 #ifdef LOG
1603 			syslog(LOG_ALERT, "reapchild: waitpid loop: pid=%d, status=%x",
1604 				pid, status);
1605 #endif
1606 			break;
1607 		}
1608 	}
1609 # else
1610 # ifdef WNOHANG
1611 	union wait status;
1612 
1613 	while (wait3(&status, WNOHANG, (struct rusage *) NULL) > 0)
1614 		continue;
1615 # else /* WNOHANG */
1616 	auto int status;
1617 
1618 	while (wait(&status) > 0)
1619 		continue;
1620 # endif /* WNOHANG */
1621 # endif
1622 # ifdef SYS5SIGNALS
1623 	(void) setsignal(SIGCHLD, reapchild);
1624 # endif
1625 	errno = olderrno;
1626 }
1627 /*
1628 **  UNSETENV -- remove a variable from the environment
1629 **
1630 **	Not needed on newer systems.
1631 **
1632 **	Parameters:
1633 **		name -- the string name of the environment variable to be
1634 **			deleted from the current environment.
1635 **
1636 **	Returns:
1637 **		none.
1638 **
1639 **	Globals:
1640 **		environ -- a pointer to the current environment.
1641 **
1642 **	Side Effects:
1643 **		Modifies environ.
1644 */
1645 
1646 #ifndef HASUNSETENV
1647 
1648 void
1649 unsetenv(name)
1650 	char *name;
1651 {
1652 	extern char **environ;
1653 	register char **pp;
1654 	int len = strlen(name);
1655 
1656 	for (pp = environ; *pp != NULL; pp++)
1657 	{
1658 		if (strncmp(name, *pp, len) == 0 &&
1659 		    ((*pp)[len] == '=' || (*pp)[len] == '\0'))
1660 			break;
1661 	}
1662 
1663 	for (; *pp != NULL; pp++)
1664 		*pp = pp[1];
1665 }
1666 
1667 #endif
1668 /*
1669 **  GETDTABLESIZE -- return number of file descriptors
1670 **
1671 **	Only on non-BSD systems
1672 **
1673 **	Parameters:
1674 **		none
1675 **
1676 **	Returns:
1677 **		size of file descriptor table
1678 **
1679 **	Side Effects:
1680 **		none
1681 */
1682 
1683 #ifdef SOLARIS
1684 # include <sys/resource.h>
1685 #endif
1686 
1687 int
1688 getdtsize()
1689 {
1690 #ifdef RLIMIT_NOFILE
1691 	struct rlimit rl;
1692 
1693 	if (getrlimit(RLIMIT_NOFILE, &rl) >= 0)
1694 		return rl.rlim_cur;
1695 #endif
1696 
1697 # ifdef HASGETDTABLESIZE
1698 	return getdtablesize();
1699 # else
1700 #  ifdef _SC_OPEN_MAX
1701 	return sysconf(_SC_OPEN_MAX);
1702 #  else
1703 	return NOFILE;
1704 #  endif
1705 # endif
1706 }
1707 /*
1708 **  UNAME -- get the UUCP name of this system.
1709 */
1710 
1711 #ifndef HASUNAME
1712 
1713 int
1714 uname(name)
1715 	struct utsname *name;
1716 {
1717 	FILE *file;
1718 	char *n;
1719 
1720 	name->nodename[0] = '\0';
1721 
1722 	/* try /etc/whoami -- one line with the node name */
1723 	if ((file = fopen("/etc/whoami", "r")) != NULL)
1724 	{
1725 		(void) fgets(name->nodename, NODE_LENGTH + 1, file);
1726 		(void) fclose(file);
1727 		n = strchr(name->nodename, '\n');
1728 		if (n != NULL)
1729 			*n = '\0';
1730 		if (name->nodename[0] != '\0')
1731 			return (0);
1732 	}
1733 
1734 	/* try /usr/include/whoami.h -- has a #define somewhere */
1735 	if ((file = fopen("/usr/include/whoami.h", "r")) != NULL)
1736 	{
1737 		char buf[MAXLINE];
1738 
1739 		while (fgets(buf, MAXLINE, file) != NULL)
1740 			if (sscanf(buf, "#define sysname \"%*[^\"]\"",
1741 					NODE_LENGTH, name->nodename) > 0)
1742 				break;
1743 		(void) fclose(file);
1744 		if (name->nodename[0] != '\0')
1745 			return (0);
1746 	}
1747 
1748 #ifdef TRUST_POPEN
1749 	/*
1750 	**  Popen is known to have security holes.
1751 	*/
1752 
1753 	/* try uuname -l to return local name */
1754 	if ((file = popen("uuname -l", "r")) != NULL)
1755 	{
1756 		(void) fgets(name, NODE_LENGTH + 1, file);
1757 		(void) pclose(file);
1758 		n = strchr(name, '\n');
1759 		if (n != NULL)
1760 			*n = '\0';
1761 		if (name->nodename[0] != '\0')
1762 			return (0);
1763 	}
1764 #endif
1765 
1766 	return (-1);
1767 }
1768 #endif /* HASUNAME */
1769 /*
1770 **  INITGROUPS -- initialize groups
1771 **
1772 **	Stub implementation for System V style systems
1773 */
1774 
1775 #ifndef HASINITGROUPS
1776 
1777 initgroups(name, basegid)
1778 	char *name;
1779 	int basegid;
1780 {
1781 	return 0;
1782 }
1783 
1784 #endif
1785 /*
1786 **  SETSID -- set session id (for non-POSIX systems)
1787 */
1788 
1789 #ifndef HASSETSID
1790 
1791 pid_t
1792 setsid __P ((void))
1793 {
1794 #ifdef TIOCNOTTY
1795 	int fd;
1796 
1797 	fd = open("/dev/tty", O_RDWR, 0);
1798 	if (fd >= 0)
1799 	{
1800 		(void) ioctl(fd, (int) TIOCNOTTY, (char *) 0);
1801 		(void) close(fd);
1802 	}
1803 #endif /* TIOCNOTTY */
1804 # ifdef SYS5SETPGRP
1805 	return setpgrp();
1806 # else
1807 	return setpgid(0, getpid());
1808 # endif
1809 }
1810 
1811 #endif
1812 /*
1813 **  FSYNC -- dummy fsync
1814 */
1815 
1816 #ifdef NEEDFSYNC
1817 
1818 fsync(fd)
1819 	int fd;
1820 {
1821 # ifdef O_SYNC
1822 	return fcntl(fd, F_SETFL, O_SYNC);
1823 # else
1824 	/* nothing we can do */
1825 	return 0;
1826 # endif
1827 }
1828 
1829 #endif
1830 /*
1831 **  DGUX_INET_ADDR -- inet_addr for DG/UX
1832 **
1833 **	Data General DG/UX version of inet_addr returns a struct in_addr
1834 **	instead of a long.  This patches things.  Only needed on versions
1835 **	prior to 5.4.3.
1836 */
1837 
1838 #ifdef DGUX_5_4_2
1839 
1840 #undef inet_addr
1841 
1842 long
1843 dgux_inet_addr(host)
1844 	char *host;
1845 {
1846 	struct in_addr haddr;
1847 
1848 	haddr = inet_addr(host);
1849 	return haddr.s_addr;
1850 }
1851 
1852 #endif
1853 /*
1854 **  GETOPT -- for old systems or systems with bogus implementations
1855 */
1856 
1857 #ifdef NEEDGETOPT
1858 
1859 /*
1860  * Copyright (c) 1985 Regents of the University of California.
1861  * All rights reserved.  The Berkeley software License Agreement
1862  * specifies the terms and conditions for redistribution.
1863  */
1864 
1865 
1866 /*
1867 ** this version hacked to add `atend' flag to allow state machine
1868 ** to reset if invoked by the program to scan args for a 2nd time
1869 */
1870 
1871 #if defined(LIBC_SCCS) && !defined(lint)
1872 static char sccsid[] = "@(#)getopt.c	4.3 (Berkeley) 3/9/86";
1873 #endif /* LIBC_SCCS and not lint */
1874 
1875 #include <stdio.h>
1876 
1877 /*
1878  * get option letter from argument vector
1879  */
1880 #ifdef _CONVEX_SOURCE
1881 extern int	optind, opterr, optopt;
1882 extern char	*optarg;
1883 #else
1884 int	opterr = 1;		/* if error message should be printed */
1885 int	optind = 1;		/* index into parent argv vector */
1886 int	optopt = 0;		/* character checked for validity */
1887 char	*optarg = NULL;		/* argument associated with option */
1888 #endif
1889 
1890 #define BADCH	(int)'?'
1891 #define EMSG	""
1892 #define tell(s)	if (opterr) {fputs(*nargv,stderr);fputs(s,stderr); \
1893 		fputc(optopt,stderr);fputc('\n',stderr);return(BADCH);}
1894 
1895 getopt(nargc,nargv,ostr)
1896 	int		nargc;
1897 	char *const	*nargv;
1898 	const char	*ostr;
1899 {
1900 	static char	*place = EMSG;	/* option letter processing */
1901 	static char	atend = 0;
1902 	register char	*oli;		/* option letter list index */
1903 
1904 	if (atend) {
1905 		atend = 0;
1906 		place = EMSG;
1907 	}
1908 	if(!*place) {			/* update scanning pointer */
1909 		if (optind >= nargc || *(place = nargv[optind]) != '-' || !*++place) {
1910 			atend++;
1911 			return(EOF);
1912 		}
1913 		if (*place == '-') {	/* found "--" */
1914 			++optind;
1915 			atend++;
1916 			return(EOF);
1917 		}
1918 	}				/* option letter okay? */
1919 	if ((optopt = (int)*place++) == (int)':' || !(oli = strchr(ostr,optopt))) {
1920 		if (!*place) ++optind;
1921 		tell(": illegal option -- ");
1922 	}
1923 	if (*++oli != ':') {		/* don't need argument */
1924 		optarg = NULL;
1925 		if (!*place) ++optind;
1926 	}
1927 	else {				/* need an argument */
1928 		if (*place) optarg = place;	/* no white space */
1929 		else if (nargc <= ++optind) {	/* no arg */
1930 			place = EMSG;
1931 			tell(": option requires an argument -- ");
1932 		}
1933 	 	else optarg = nargv[optind];	/* white space */
1934 		place = EMSG;
1935 		++optind;
1936 	}
1937 	return(optopt);			/* dump back option letter */
1938 }
1939 
1940 #endif
1941 /*
1942 **  VFPRINTF, VSPRINTF -- for old 4.3 BSD systems missing a real version
1943 */
1944 
1945 #ifdef NEEDVPRINTF
1946 
1947 #define MAXARG	16
1948 
1949 vfprintf(fp, fmt, ap)
1950 	FILE *	fp;
1951 	char *	fmt;
1952 	char **	ap;
1953 {
1954 	char *	bp[MAXARG];
1955 	int	i = 0;
1956 
1957 	while (*ap && i < MAXARG)
1958 		bp[i++] = *ap++;
1959 	fprintf(fp, fmt, bp[0], bp[1], bp[2], bp[3],
1960 			 bp[4], bp[5], bp[6], bp[7],
1961 			 bp[8], bp[9], bp[10], bp[11],
1962 			 bp[12], bp[13], bp[14], bp[15]);
1963 }
1964 
1965 vsprintf(s, fmt, ap)
1966 	char *	s;
1967 	char *	fmt;
1968 	char **	ap;
1969 {
1970 	char *	bp[MAXARG];
1971 	int	i = 0;
1972 
1973 	while (*ap && i < MAXARG)
1974 		bp[i++] = *ap++;
1975 	sprintf(s, fmt, bp[0], bp[1], bp[2], bp[3],
1976 			bp[4], bp[5], bp[6], bp[7],
1977 			bp[8], bp[9], bp[10], bp[11],
1978 			bp[12], bp[13], bp[14], bp[15]);
1979 }
1980 
1981 #endif
1982 /*
1983 **  USERSHELLOK -- tell if a user's shell is ok for unrestricted use
1984 **
1985 **	Parameters:
1986 **		shell -- the user's shell from /etc/passwd
1987 **
1988 **	Returns:
1989 **		TRUE -- if it is ok to use this for unrestricted access.
1990 **		FALSE -- if the shell is restricted.
1991 */
1992 
1993 #if !HASGETUSERSHELL
1994 
1995 # ifndef _PATH_SHELLS
1996 #  define _PATH_SHELLS	"/etc/shells"
1997 # endif
1998 
1999 char	*DefaultUserShells[] =
2000 {
2001 	"/bin/sh",		/* standard shell */
2002 	"/usr/bin/sh",
2003 	"/bin/csh",		/* C shell */
2004 	"/usr/bin/csh",
2005 #ifdef __hpux
2006 	"/bin/rsh",		/* restricted Bourne shell */
2007 	"/bin/ksh",		/* Korn shell */
2008 	"/bin/rksh",		/* restricted Korn shell */
2009 	"/bin/pam",
2010 	"/usr/bin/keysh",	/* key shell (extended Korn shell) */
2011 	"/bin/posix/sh",
2012 #endif
2013 #ifdef _AIX3
2014 	"/bin/ksh",		/* Korn shell */
2015 	"/usr/bin/ksh",
2016 	"/bin/tsh",		/* trusted shell */
2017 	"/usr/bin/tsh",
2018 	"/bin/bsh",		/* Bourne shell */
2019 	"/usr/bin/bsh",
2020 #endif
2021 	NULL
2022 };
2023 
2024 #endif
2025 
2026 #define WILDCARD_SHELL	"/SENDMAIL/ANY/SHELL/"
2027 
2028 bool
2029 usershellok(shell)
2030 	char *shell;
2031 {
2032 #if HASGETUSERSHELL
2033 	register char *p;
2034 	extern char *getusershell();
2035 
2036 	if (shell == NULL || shell[0] == '\0')
2037 		return TRUE;
2038 
2039 	setusershell();
2040 	while ((p = getusershell()) != NULL)
2041 		if (strcmp(p, shell) == 0 || strcmp(p, WILDCARD_SHELL) == 0)
2042 			break;
2043 	endusershell();
2044 	return p != NULL;
2045 #else
2046 	register FILE *shellf;
2047 	char buf[MAXLINE];
2048 
2049 	if (shell == NULL || shell[0] == '\0')
2050 		return TRUE;
2051 
2052 	shellf = fopen(_PATH_SHELLS, "r");
2053 	if (shellf == NULL)
2054 	{
2055 		/* no /etc/shells; see if it is one of the std shells */
2056 		char **d;
2057 
2058 		for (d = DefaultUserShells; *d != NULL; d++)
2059 		{
2060 			if (strcmp(shell, *d) == 0)
2061 				return TRUE;
2062 		}
2063 		return FALSE;
2064 	}
2065 
2066 	while (fgets(buf, sizeof buf, shellf) != NULL)
2067 	{
2068 		register char *p, *q;
2069 
2070 		p = buf;
2071 		while (*p != '\0' && *p != '#' && *p != '/')
2072 			p++;
2073 		if (*p == '#' || *p == '\0')
2074 			continue;
2075 		q = p;
2076 		while (*p != '\0' && *p != '#' && !isspace(*p))
2077 			p++;
2078 		*p = '\0';
2079 		if (strcmp(shell, q) == 0 || strcmp(WILDCARD_SHELL, q) == 0)
2080 		{
2081 			fclose(shellf);
2082 			return TRUE;
2083 		}
2084 	}
2085 	fclose(shellf);
2086 	return FALSE;
2087 #endif
2088 }
2089 /*
2090 **  FREESPACE -- see how much free space is on the queue filesystem
2091 **
2092 **	Only implemented if you have statfs.
2093 **
2094 **	Parameters:
2095 **		dir -- the directory in question.
2096 **		bsize -- a variable into which the filesystem
2097 **			block size is stored.
2098 **
2099 **	Returns:
2100 **		The number of bytes free on the queue filesystem.
2101 **		-1 if the statfs call fails.
2102 **
2103 **	Side effects:
2104 **		Puts the filesystem block size into bsize.
2105 */
2106 
2107 /* statfs types */
2108 #define SFS_NONE	0	/* no statfs implementation */
2109 #define SFS_USTAT	1	/* use ustat */
2110 #define SFS_4ARGS	2	/* use four-argument statfs call */
2111 #define SFS_VFS		3	/* use <sys/vfs.h> implementation */
2112 #define SFS_MOUNT	4	/* use <sys/mount.h> implementation */
2113 #define SFS_STATFS	5	/* use <sys/statfs.h> implementation */
2114 #define SFS_STATVFS	6	/* use <sys/statvfs.h> implementation */
2115 
2116 #ifndef SFS_TYPE
2117 # define SFS_TYPE	SFS_NONE
2118 #endif
2119 
2120 #if SFS_TYPE == SFS_USTAT
2121 # include <ustat.h>
2122 #endif
2123 #if SFS_TYPE == SFS_4ARGS || SFS_TYPE == SFS_STATFS
2124 # include <sys/statfs.h>
2125 #endif
2126 #if SFS_TYPE == SFS_VFS
2127 # include <sys/vfs.h>
2128 #endif
2129 #if SFS_TYPE == SFS_MOUNT
2130 # include <sys/mount.h>
2131 #endif
2132 #if SFS_TYPE == SFS_STATVFS
2133 # include <sys/statvfs.h>
2134 #endif
2135 
2136 long
2137 freespace(dir, bsize)
2138 	char *dir;
2139 	long *bsize;
2140 {
2141 #if SFS_TYPE != SFS_NONE
2142 # if SFS_TYPE == SFS_USTAT
2143 	struct ustat fs;
2144 	struct stat statbuf;
2145 #  define FSBLOCKSIZE	DEV_BSIZE
2146 #  define SFS_BAVAIL	f_tfree
2147 # else
2148 #  if defined(ultrix)
2149 	struct fs_data fs;
2150 #   define SFS_BAVAIL	fd_bfreen
2151 #   define FSBLOCKSIZE	1024L
2152 #  else
2153 #   if SFS_TYPE == SFS_STATVFS
2154 	struct statvfs fs;
2155 #    define FSBLOCKSIZE	fs.f_frsize
2156 #   else
2157 	struct statfs fs;
2158 #    define FSBLOCKSIZE	fs.f_bsize
2159 #   endif
2160 #  endif
2161 # endif
2162 # ifndef SFS_BAVAIL
2163 #  define SFS_BAVAIL f_bavail
2164 # endif
2165 
2166 # if SFS_TYPE == SFS_USTAT
2167 	if (stat(dir, &statbuf) == 0 && ustat(statbuf.st_dev, &fs) == 0)
2168 # else
2169 #  if SFS_TYPE == SFS_4ARGS
2170 	if (statfs(dir, &fs, sizeof fs, 0) == 0)
2171 #  else
2172 #   if SFS_TYPE == SFS_STATVFS
2173 	if (statvfs(dir, &fs) == 0)
2174 #   else
2175 #    if defined(ultrix)
2176 	if (statfs(dir, &fs) > 0)
2177 #    else
2178 	if (statfs(dir, &fs) == 0)
2179 #    endif
2180 #   endif
2181 #  endif
2182 # endif
2183 	{
2184 		if (bsize != NULL)
2185 			*bsize = FSBLOCKSIZE;
2186 		return (fs.SFS_BAVAIL);
2187 	}
2188 #endif
2189 	return (-1);
2190 }
2191 /*
2192 **  ENOUGHSPACE -- check to see if there is enough free space on the queue fs
2193 **
2194 **	Only implemented if you have statfs.
2195 **
2196 **	Parameters:
2197 **		msize -- the size to check against.  If zero, we don't yet
2198 **		know how big the message will be, so just check for
2199 **		a "reasonable" amount.
2200 **
2201 **	Returns:
2202 **		TRUE if there is enough space.
2203 **		FALSE otherwise.
2204 */
2205 
2206 bool
2207 enoughspace(msize)
2208 	long msize;
2209 {
2210 	long bfree, bsize;
2211 
2212 	if (MinBlocksFree <= 0 && msize <= 0)
2213 	{
2214 		if (tTd(4, 80))
2215 			printf("enoughspace: no threshold\n");
2216 		return TRUE;
2217 	}
2218 
2219 	if ((bfree = freespace(QueueDir, &bsize)) >= 0)
2220 	{
2221 		if (tTd(4, 80))
2222 			printf("enoughspace: bavail=%ld, need=%ld\n",
2223 				bfree, msize);
2224 
2225 		/* convert msize to block count */
2226 		msize = msize / bsize + 1;
2227 		if (MinBlocksFree >= 0)
2228 			msize += MinBlocksFree;
2229 
2230 		if (bfree < msize)
2231 		{
2232 #ifdef LOG
2233 			if (LogLevel > 0)
2234 				syslog(LOG_ALERT,
2235 					"%s: low on space (have %ld, %s needs %ld in %s)",
2236 					CurEnv->e_id == NULL ? "[NOQUEUE]" : CurEnv->e_id,
2237 					bfree,
2238 					CurHostName == NULL ? "SMTP-DAEMON" : CurHostName,
2239 					msize, QueueDir);
2240 #endif
2241 			return FALSE;
2242 		}
2243 	}
2244 	else if (tTd(4, 80))
2245 		printf("enoughspace failure: min=%ld, need=%ld: %s\n",
2246 			MinBlocksFree, msize, errstring(errno));
2247 	return TRUE;
2248 }
2249 /*
2250 **  TRANSIENTERROR -- tell if an error code indicates a transient failure
2251 **
2252 **	This looks at an errno value and tells if this is likely to
2253 **	go away if retried later.
2254 **
2255 **	Parameters:
2256 **		err -- the errno code to classify.
2257 **
2258 **	Returns:
2259 **		TRUE if this is probably transient.
2260 **		FALSE otherwise.
2261 */
2262 
2263 bool
2264 transienterror(err)
2265 	int err;
2266 {
2267 	switch (err)
2268 	{
2269 	  case EIO:			/* I/O error */
2270 	  case ENXIO:			/* Device not configured */
2271 	  case EAGAIN:			/* Resource temporarily unavailable */
2272 	  case ENOMEM:			/* Cannot allocate memory */
2273 	  case ENODEV:			/* Operation not supported by device */
2274 	  case ENFILE:			/* Too many open files in system */
2275 	  case EMFILE:			/* Too many open files */
2276 	  case ENOSPC:			/* No space left on device */
2277 #ifdef ETIMEDOUT
2278 	  case ETIMEDOUT:		/* Connection timed out */
2279 #endif
2280 #ifdef ESTALE
2281 	  case ESTALE:			/* Stale NFS file handle */
2282 #endif
2283 #ifdef ENETDOWN
2284 	  case ENETDOWN:		/* Network is down */
2285 #endif
2286 #ifdef ENETUNREACH
2287 	  case ENETUNREACH:		/* Network is unreachable */
2288 #endif
2289 #ifdef ENETRESET
2290 	  case ENETRESET:		/* Network dropped connection on reset */
2291 #endif
2292 #ifdef ECONNABORTED
2293 	  case ECONNABORTED:		/* Software caused connection abort */
2294 #endif
2295 #ifdef ECONNRESET
2296 	  case ECONNRESET:		/* Connection reset by peer */
2297 #endif
2298 #ifdef ENOBUFS
2299 	  case ENOBUFS:			/* No buffer space available */
2300 #endif
2301 #ifdef ESHUTDOWN
2302 	  case ESHUTDOWN:		/* Can't send after socket shutdown */
2303 #endif
2304 #ifdef ECONNREFUSED
2305 	  case ECONNREFUSED:		/* Connection refused */
2306 #endif
2307 #ifdef EHOSTDOWN
2308 	  case EHOSTDOWN:		/* Host is down */
2309 #endif
2310 #ifdef EHOSTUNREACH
2311 	  case EHOSTUNREACH:		/* No route to host */
2312 #endif
2313 #ifdef EDQUOT
2314 	  case EDQUOT:			/* Disc quota exceeded */
2315 #endif
2316 #ifdef EPROCLIM
2317 	  case EPROCLIM:		/* Too many processes */
2318 #endif
2319 #ifdef EUSERS
2320 	  case EUSERS:			/* Too many users */
2321 #endif
2322 #ifdef EDEADLK
2323 	  case EDEADLK:			/* Resource deadlock avoided */
2324 #endif
2325 #ifdef EISCONN
2326 	  case EISCONN:			/* Socket already connected */
2327 #endif
2328 #ifdef EINPROGRESS
2329 	  case EINPROGRESS:		/* Operation now in progress */
2330 #endif
2331 #ifdef EALREADY
2332 	  case EALREADY:		/* Operation already in progress */
2333 #endif
2334 #ifdef EADDRINUSE
2335 	  case EADDRINUSE:		/* Address already in use */
2336 #endif
2337 #ifdef EADDRNOTAVAIL
2338 	  case EADDRNOTAVAIL:		/* Can't assign requested address */
2339 #endif
2340 #ifdef ETXTBSY
2341 	  case ETXTBSY:			/* (Apollo) file locked */
2342 #endif
2343 #if defined(ENOSR) && (!defined(ENOBUFS) || (ENOBUFS != ENOSR))
2344 	  case ENOSR:			/* Out of streams resources */
2345 #endif
2346 		return TRUE;
2347 	}
2348 
2349 	/* nope, must be permanent */
2350 	return FALSE;
2351 }
2352 /*
2353 **  LOCKFILE -- lock a file using flock or (shudder) fcntl locking
2354 **
2355 **	Parameters:
2356 **		fd -- the file descriptor of the file.
2357 **		filename -- the file name (for error messages).
2358 **		ext -- the filename extension.
2359 **		type -- type of the lock.  Bits can be:
2360 **			LOCK_EX -- exclusive lock.
2361 **			LOCK_NB -- non-blocking.
2362 **
2363 **	Returns:
2364 **		TRUE if the lock was acquired.
2365 **		FALSE otherwise.
2366 */
2367 
2368 bool
2369 lockfile(fd, filename, ext, type)
2370 	int fd;
2371 	char *filename;
2372 	char *ext;
2373 	int type;
2374 {
2375 # if !HASFLOCK
2376 	int action;
2377 	struct flock lfd;
2378 
2379 	if (ext == NULL)
2380 		ext = "";
2381 
2382 	bzero(&lfd, sizeof lfd);
2383 	if (bitset(LOCK_UN, type))
2384 		lfd.l_type = F_UNLCK;
2385 	else if (bitset(LOCK_EX, type))
2386 		lfd.l_type = F_WRLCK;
2387 	else
2388 		lfd.l_type = F_RDLCK;
2389 
2390 	if (bitset(LOCK_NB, type))
2391 		action = F_SETLK;
2392 	else
2393 		action = F_SETLKW;
2394 
2395 	if (tTd(55, 60))
2396 		printf("lockfile(%s%s, action=%d, type=%d): ",
2397 			filename, ext, action, lfd.l_type);
2398 
2399 	if (fcntl(fd, action, &lfd) >= 0)
2400 	{
2401 		if (tTd(55, 60))
2402 			printf("SUCCESS\n");
2403 		return TRUE;
2404 	}
2405 
2406 	if (tTd(55, 60))
2407 		printf("(%s) ", errstring(errno));
2408 
2409 	/*
2410 	**  On SunOS, if you are testing using -oQ/tmp/mqueue or
2411 	**  -oA/tmp/aliases or anything like that, and /tmp is mounted
2412 	**  as type "tmp" (that is, served from swap space), the
2413 	**  previous fcntl will fail with "Invalid argument" errors.
2414 	**  Since this is fairly common during testing, we will assume
2415 	**  that this indicates that the lock is successfully grabbed.
2416 	*/
2417 
2418 	if (errno == EINVAL)
2419 	{
2420 		if (tTd(55, 60))
2421 			printf("SUCCESS\n");
2422 		return TRUE;
2423 	}
2424 
2425 	if (!bitset(LOCK_NB, type) || (errno != EACCES && errno != EAGAIN))
2426 	{
2427 		int omode = -1;
2428 #  ifdef F_GETFL
2429 		int oerrno = errno;
2430 
2431 		(void) fcntl(fd, F_GETFL, &omode);
2432 		errno = oerrno;
2433 #  endif
2434 		syserr("cannot lockf(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
2435 			filename, ext, fd, type, omode, geteuid());
2436 	}
2437 # else
2438 	if (ext == NULL)
2439 		ext = "";
2440 
2441 	if (tTd(55, 60))
2442 		printf("lockfile(%s%s, type=%o): ", filename, ext, type);
2443 
2444 	if (flock(fd, type) >= 0)
2445 	{
2446 		if (tTd(55, 60))
2447 			printf("SUCCESS\n");
2448 		return TRUE;
2449 	}
2450 
2451 	if (tTd(55, 60))
2452 		printf("(%s) ", errstring(errno));
2453 
2454 	if (!bitset(LOCK_NB, type) || errno != EWOULDBLOCK)
2455 	{
2456 		int omode = -1;
2457 #  ifdef F_GETFL
2458 		int oerrno = errno;
2459 
2460 		(void) fcntl(fd, F_GETFL, &omode);
2461 		errno = oerrno;
2462 #  endif
2463 		syserr("cannot flock(%s%s, fd=%d, type=%o, omode=%o, euid=%d)",
2464 			filename, ext, fd, type, omode, geteuid());
2465 	}
2466 # endif
2467 	if (tTd(55, 60))
2468 		printf("FAIL\n");
2469 	return FALSE;
2470 }
2471 /*
2472 **  CHOWNSAFE -- tell if chown is "safe" (executable only by root)
2473 **
2474 **	Parameters:
2475 **		fd -- the file descriptor to check.
2476 **
2477 **	Returns:
2478 **		TRUE -- if only root can chown the file to an arbitrary
2479 **			user.
2480 **		FALSE -- if an arbitrary user can give away a file.
2481 */
2482 
2483 bool
2484 chownsafe(fd)
2485 	int fd;
2486 {
2487 #ifdef __hpux
2488 	char *s;
2489 	int tfd;
2490 	uid_t o_uid, o_euid;
2491 	gid_t o_gid, o_egid;
2492 	bool rval;
2493 	struct stat stbuf;
2494 
2495 	o_uid = getuid();
2496 	o_euid = geteuid();
2497 	o_gid = getgid();
2498 	o_egid = getegid();
2499 	fstat(fd, &stbuf);
2500 	setresuid(stbuf.st_uid, stbuf.st_uid, -1);
2501 	setresgid(stbuf.st_gid, stbuf.st_gid, -1);
2502 	s = tmpnam(NULL);
2503 	tfd = open(s, O_RDONLY|O_CREAT, 0600);
2504 	rval = fchown(tfd, DefUid, DefGid) != 0;
2505 	close(tfd);
2506 	unlink(s);
2507 	setreuid(o_uid, o_euid);
2508 	setresgid(o_gid, o_egid, -1);
2509 	return rval;
2510 #else
2511 # ifdef _POSIX_CHOWN_RESTRICTED
2512 #  if _POSIX_CHOWN_RESTRICTED == -1
2513 	return FALSE;
2514 #  else
2515 	return TRUE;
2516 #  endif
2517 # else
2518 #  ifdef _PC_CHOWN_RESTRICTED
2519 	int rval;
2520 
2521 	/*
2522 	**  Some systems (e.g., SunOS) seem to have the call and the
2523 	**  #define _PC_CHOWN_RESTRICTED, but don't actually implement
2524 	**  the call.  This heuristic checks for that.
2525 	*/
2526 
2527 	errno = 0;
2528 	rval = fpathconf(fd, _PC_CHOWN_RESTRICTED);
2529 	if (errno == 0)
2530 		return rval > 0;
2531 #  endif
2532 #  ifdef BSD
2533 	return TRUE;
2534 #  else
2535 	return FALSE;
2536 #  endif
2537 # endif
2538 #endif
2539 }
2540 /*
2541 **  RESETLIMITS -- reset system controlled resource limits
2542 **
2543 **	This is to avoid denial-of-service attacks
2544 **
2545 **	Parameters:
2546 **		none
2547 **
2548 **	Returns:
2549 **		none
2550 */
2551 
2552 #if HASSETRLIMIT
2553 # include <sys/resource.h>
2554 #endif
2555 
2556 void
2557 resetlimits()
2558 {
2559 #if HASSETRLIMIT
2560 	struct rlimit lim;
2561 
2562 	lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
2563 	(void) setrlimit(RLIMIT_CPU, &lim);
2564 	(void) setrlimit(RLIMIT_FSIZE, &lim);
2565 #else
2566 # if HASULIMIT
2567 	(void) ulimit(2, 0x3fffff);
2568 # endif
2569 #endif
2570 }
2571 /*
2572 **  GETCFNAME -- return the name of the .cf file.
2573 **
2574 **	Some systems (e.g., NeXT) determine this dynamically.
2575 */
2576 
2577 char *
2578 getcfname()
2579 {
2580 	if (ConfFile != NULL)
2581 		return ConfFile;
2582 #ifdef NETINFO
2583 	{
2584 		extern char *ni_propval();
2585 		char *cflocation;
2586 
2587 		cflocation = ni_propval("/locations", NULL, "sendmail",
2588 					"sendmail.cf", '\0');
2589 		if (cflocation != NULL)
2590 			return cflocation;
2591 	}
2592 #endif
2593 	return _PATH_SENDMAILCF;
2594 }
2595 /*
2596 **  SETVENDOR -- process vendor code from V configuration line
2597 **
2598 **	Parameters:
2599 **		vendor -- string representation of vendor.
2600 **
2601 **	Returns:
2602 **		TRUE -- if ok.
2603 **		FALSE -- if vendor code could not be processed.
2604 **
2605 **	Side Effects:
2606 **		It is reasonable to set mode flags here to tweak
2607 **		processing in other parts of the code if necessary.
2608 **		For example, if you are a vendor that uses $%y to
2609 **		indicate YP lookups, you could enable that here.
2610 */
2611 
2612 bool
2613 setvendor(vendor)
2614 	char *vendor;
2615 {
2616 	if (strcasecmp(vendor, "Berkeley") == 0)
2617 	{
2618 		VendorCode = VENDOR_BERKELEY;
2619 		return TRUE;
2620 	}
2621 
2622 	/* add vendor extensions here */
2623 
2624 #ifdef SUN_EXTENSIONS
2625 	if (strcasecmp(vendor, "Sun") == 0)
2626 	{
2627 		VendorCode = VENDOR_SUN;
2628 		return TRUE;
2629 	}
2630 #endif
2631 
2632 	return FALSE;
2633 }
2634 /*
2635 **  STRTOL -- convert string to long integer
2636 **
2637 **	For systems that don't have it in the C library.
2638 **
2639 **	This is taken verbatim from the 4.4-Lite C library.
2640 */
2641 
2642 #ifdef NEEDSTRTOL
2643 
2644 #if defined(LIBC_SCCS) && !defined(lint)
2645 static char sccsid[] = "@(#)strtol.c	8.1 (Berkeley) 6/4/93";
2646 #endif /* LIBC_SCCS and not lint */
2647 
2648 #include <limits.h>
2649 
2650 /*
2651  * Convert a string to a long integer.
2652  *
2653  * Ignores `locale' stuff.  Assumes that the upper and lower case
2654  * alphabets and digits are each contiguous.
2655  */
2656 
2657 long
2658 strtol(nptr, endptr, base)
2659 	const char *nptr;
2660 	char **endptr;
2661 	register int base;
2662 {
2663 	register const char *s = nptr;
2664 	register unsigned long acc;
2665 	register int c;
2666 	register unsigned long cutoff;
2667 	register int neg = 0, any, cutlim;
2668 
2669 	/*
2670 	 * Skip white space and pick up leading +/- sign if any.
2671 	 * If base is 0, allow 0x for hex and 0 for octal, else
2672 	 * assume decimal; if base is already 16, allow 0x.
2673 	 */
2674 	do {
2675 		c = *s++;
2676 	} while (isspace(c));
2677 	if (c == '-') {
2678 		neg = 1;
2679 		c = *s++;
2680 	} else if (c == '+')
2681 		c = *s++;
2682 	if ((base == 0 || base == 16) &&
2683 	    c == '0' && (*s == 'x' || *s == 'X')) {
2684 		c = s[1];
2685 		s += 2;
2686 		base = 16;
2687 	}
2688 	if (base == 0)
2689 		base = c == '0' ? 8 : 10;
2690 
2691 	/*
2692 	 * Compute the cutoff value between legal numbers and illegal
2693 	 * numbers.  That is the largest legal value, divided by the
2694 	 * base.  An input number that is greater than this value, if
2695 	 * followed by a legal input character, is too big.  One that
2696 	 * is equal to this value may be valid or not; the limit
2697 	 * between valid and invalid numbers is then based on the last
2698 	 * digit.  For instance, if the range for longs is
2699 	 * [-2147483648..2147483647] and the input base is 10,
2700 	 * cutoff will be set to 214748364 and cutlim to either
2701 	 * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
2702 	 * a value > 214748364, or equal but the next digit is > 7 (or 8),
2703 	 * the number is too big, and we will return a range error.
2704 	 *
2705 	 * Set any if any `digits' consumed; make it negative to indicate
2706 	 * overflow.
2707 	 */
2708 	cutoff = neg ? -(unsigned long)LONG_MIN : LONG_MAX;
2709 	cutlim = cutoff % (unsigned long)base;
2710 	cutoff /= (unsigned long)base;
2711 	for (acc = 0, any = 0;; c = *s++) {
2712 		if (isdigit(c))
2713 			c -= '0';
2714 		else if (isalpha(c))
2715 			c -= isupper(c) ? 'A' - 10 : 'a' - 10;
2716 		else
2717 			break;
2718 		if (c >= base)
2719 			break;
2720 		if (any < 0 || acc > cutoff || acc == cutoff && c > cutlim)
2721 			any = -1;
2722 		else {
2723 			any = 1;
2724 			acc *= base;
2725 			acc += c;
2726 		}
2727 	}
2728 	if (any < 0) {
2729 		acc = neg ? LONG_MIN : LONG_MAX;
2730 		errno = ERANGE;
2731 	} else if (neg)
2732 		acc = -acc;
2733 	if (endptr != 0)
2734 		*endptr = (char *)(any ? s - 1 : nptr);
2735 	return (acc);
2736 }
2737 
2738 #endif
2739 /*
2740 **  SM_GETHOSTBY{NAME,ADDR} -- compatibility routines for gethostbyXXX
2741 **
2742 **	Some operating systems have wierd problems with the gethostbyXXX
2743 **	routines.  For example, Solaris versions at least through 2.3
2744 **	don't properly deliver a canonical h_name field.  This tries to
2745 **	work around these problems.
2746 */
2747 
2748 struct hostent *
2749 sm_gethostbyname(name)
2750 	char *name;
2751 {
2752 #if defined(SOLARIS) && SOLARIS < 204
2753 	extern int h_errno;
2754 
2755 # if SOLARIS == 203
2756 	static struct hostent hp;
2757 	static char buf[1000];
2758 	extern struct hostent *_switch_gethostbyname_r();
2759 
2760 	return _switch_gethostbyname_r(name, &hp, buf, sizeof(buf), &h_errno);
2761 # else
2762 	extern struct hostent *__switch_gethostbyname();
2763 
2764 	return __switch_gethostbyname(name);
2765 # endif
2766 #else
2767 	return gethostbyname(name);
2768 #endif
2769 }
2770 
2771 struct hostent *
2772 sm_gethostbyaddr(addr, len, type)
2773 	char *addr;
2774 	int len;
2775 	int type;
2776 {
2777 #if defined(SOLARIS) && SOLARIS < 204
2778 	extern int h_errno;
2779 
2780 # if SOLARIS == 203
2781 	static struct hostent hp;
2782 	static char buf[1000];
2783 	extern struct hostent *_switch_gethostbyaddr_r();
2784 
2785 	return _switch_gethostbyaddr_r(addr, len, type, &hp, buf, sizeof(buf), &h_errno);
2786 # else
2787 	extern struct hostent *__switch_gethostbyaddr();
2788 
2789 	return __switch_gethostbyaddr(addr, len, type);
2790 # endif
2791 #else
2792 	return gethostbyaddr(addr, len, type);
2793 #endif
2794 }
2795 /*
2796 **  SM_GETPW{NAM,UID} -- wrapper for getpwnam and getpwuid
2797 */
2798 
2799 struct passwd *
2800 sm_getpwnam(user)
2801 	char *user;
2802 {
2803 	return getpwnam(user);
2804 }
2805 
2806 struct passwd *
2807 sm_getpwuid(uid)
2808 	uid_t uid;
2809 {
2810 	return getpwuid(uid);
2811 }
2812 /*
2813 **  NI_PROPVAL -- netinfo property value lookup routine
2814 **
2815 **	Parameters:
2816 **		keydir -- the Netinfo directory name in which to search
2817 **			for the key.
2818 **		keyprop -- the name of the property in which to find the
2819 **			property we are interested.  Defaults to "name".
2820 **		keyval -- the value for which we are really searching.
2821 **		valprop -- the property name for the value in which we
2822 **			are interested.
2823 **		sepchar -- if non-nil, this can be multiple-valued, and
2824 **			we should return a string separated by this
2825 **			character.
2826 **
2827 **	Returns:
2828 **		NULL -- if:
2829 **			1. the directory is not found
2830 **			2. the property name is not found
2831 **			3. the property contains multiple values
2832 **			4. some error occured
2833 **		else -- the location of the config file.
2834 **
2835 **	Example:
2836 **		To search for an alias value, use:
2837 **		  ni_propval("/aliases", "name", aliasname, "members", ',')
2838 **
2839 **	Notes:
2840 **      	Caller should free the return value of ni_proval
2841 */
2842 
2843 #ifdef NETINFO
2844 
2845 # include <netinfo/ni.h>
2846 
2847 # define LOCAL_NETINFO_DOMAIN    "."
2848 # define PARENT_NETINFO_DOMAIN   ".."
2849 # define MAX_NI_LEVELS           256
2850 
2851 char *
2852 ni_propval(keydir, keyprop, keyval, valprop, sepchar)
2853 	char *keydir;
2854 	char *keyprop;
2855 	char *keyval;
2856 	char *valprop;
2857 	char sepchar;
2858 {
2859 	char *propval = NULL;
2860 	int i;
2861 	int j, alen;
2862 	void *ni = NULL;
2863 	void *lastni = NULL;
2864 	ni_status nis;
2865 	ni_id nid;
2866 	ni_namelist ninl;
2867 	register char *p;
2868 	char keybuf[1024];
2869 
2870 	/*
2871 	**  Create the full key from the two parts.
2872 	**
2873 	**	Note that directory can end with, e.g., "name=" to specify
2874 	**	an alternate search property.
2875 	*/
2876 
2877 	i = strlen(keydir) + strlen(keyval) + 2;
2878 	if (keyprop != NULL)
2879 		i += strlen(keyprop) + 1;
2880 	if (i > sizeof keybuf)
2881 		return NULL;
2882 	strcpy(keybuf, keydir);
2883 	strcat(keybuf, "/");
2884 	if (keyprop != NULL)
2885 	{
2886 		strcat(keybuf, keyprop);
2887 		strcat(keybuf, "=");
2888 	}
2889 	strcat(keybuf, keyval);
2890 
2891 	/*
2892 	**  If the passed directory and property name are found
2893 	**  in one of netinfo domains we need to search (starting
2894 	**  from the local domain moving all the way back to the
2895 	**  root domain) set propval to the property's value
2896 	**  and return it.
2897 	*/
2898 
2899 	for (i = 0; i < MAX_NI_LEVELS; ++i)
2900 	{
2901 		if (i == 0)
2902 		{
2903 			nis = ni_open(NULL, LOCAL_NETINFO_DOMAIN, &ni);
2904 		}
2905 		else
2906 		{
2907 			if (lastni != NULL)
2908 				ni_free(lastni);
2909 			lastni = ni;
2910 			nis = ni_open(lastni, PARENT_NETINFO_DOMAIN, &ni);
2911 		}
2912 
2913 		/*
2914 		**  Don't bother if we didn't get a handle on a
2915 		**  proper domain.  This is not necessarily an error.
2916 		**  We would get a positive ni_status if, for instance
2917 		**  we never found the directory or property and tried
2918 		**  to open the parent of the root domain!
2919 		*/
2920 
2921 		if (nis != 0)
2922 			break;
2923 
2924 		/*
2925 		**  Find the path to the server information.
2926 		*/
2927 
2928 		if (ni_pathsearch(ni, &nid, keybuf) != 0)
2929 			continue;
2930 
2931 		/*
2932 		**  Find associated value information.
2933 		*/
2934 
2935 		if (ni_lookupprop(ni, &nid, valprop, &ninl) != 0)
2936 			continue;
2937 
2938 		/*
2939 		**  See if we have an acceptable number of values.
2940 		*/
2941 
2942 		if (ninl.ni_namelist_len <= 0)
2943 			continue;
2944 
2945 		if (sepchar == '\0' && ninl.ni_namelist_len > 1)
2946 		{
2947 			ni_namelist_free(&ninl);
2948 			continue;
2949 		}
2950 
2951 		/*
2952 		**  Calculate number of bytes needed and build result
2953 		*/
2954 
2955 		alen = 1;
2956 		for (j = 0; j < ninl.ni_namelist_len; j++)
2957 			alen += strlen(ninl.ni_namelist_val[j]) + 1;
2958 		propval = p = xalloc(alen);
2959 		for (j = 0; j < ninl.ni_namelist_len; j++)
2960 		{
2961 			strcpy(p, ninl.ni_namelist_val[j]);
2962 			p += strlen(p);
2963 			*p++ = sepchar;
2964 		}
2965 		*--p = '\0';
2966 
2967 		ni_namelist_free(&ninl);
2968 	}
2969 
2970 	/*
2971 	**  Clean up.
2972 	*/
2973 
2974 	if (ni != NULL)
2975 		ni_free(ni);
2976 	if (lastni != NULL && ni != lastni)
2977 		ni_free(lastni);
2978 
2979 	return propval;
2980 }
2981 
2982 #endif /* NETINFO */
2983 /*
2984 **  HARD_SYSLOG -- call syslog repeatedly until it works
2985 **
2986 **	Needed on HP-UX, which apparently doesn't guarantee that
2987 **	syslog succeeds during interrupt handlers.
2988 */
2989 
2990 #ifdef __hpux
2991 
2992 # define MAXSYSLOGTRIES	100
2993 # undef syslog
2994 
2995 # ifdef __STDC__
2996 hard_syslog(int pri, char *msg, ...)
2997 # else
2998 hard_syslog(pri, msg, va_alist)
2999 	int pri;
3000 	char *msg;
3001 	va_dcl
3002 # endif
3003 {
3004 	int i;
3005 	char buf[SYSLOG_BUFSIZE * 2];
3006 	VA_LOCAL_DECL;
3007 
3008 	VA_START(msg);
3009 	vsprintf(buf, msg, ap);
3010 	VA_END;
3011 
3012 	for (i = MAXSYSLOGTRIES; --i >= 0 && syslog(pri, "%s", buf) < 0; )
3013 		continue;
3014 }
3015 
3016 #endif
3017 /*
3018 **  LOCAL_HOSTNAME_LENGTH
3019 **
3020 **	This is required to get sendmail to compile against BIND 4.9.x
3021 **	on Ultrix.
3022 */
3023 
3024 #if defined(ultrix) && NAMED_BIND
3025 
3026 # include <resolv.h>
3027 # if __RES >= 19931104
3028 
3029 int
3030 local_hostname_length(hostname)
3031 	char *hostname;
3032 {
3033 	int len_host, len_domain;
3034 
3035 	if (!*_res.defdname)
3036 		res_init();
3037 	len_host = strlen(hostname);
3038 	len_domain = strlen(_res.defdname);
3039 	if (len_host > len_domain &&
3040 	    (strcasecmp(hostname + len_host - len_domain,_res.defdname) == 0) &&
3041 	    hostname[len_host - len_domain - 1] == '.')
3042 		return len_host - len_domain - 1;
3043 	else
3044 		return 0;
3045 }
3046 
3047 # endif
3048 #endif
3049 /*
3050 **  Compile-Time options
3051 */
3052 
3053 char	*CompileOptions[] =
3054 {
3055 #if HESIOD
3056 	"HESIOD",
3057 #endif
3058 #if LOG
3059 	"LOG",
3060 #endif
3061 #if MATCHGECOS
3062 	"MATCHGECOS",
3063 #endif
3064 #if NAMED_BIND
3065 	"NAMED_BIND",
3066 #endif
3067 #if NDBM
3068 	"NDBM",
3069 #endif
3070 #if NETINET
3071 	"NETINET",
3072 #endif
3073 #if NETINFO
3074 	"NETINFO",
3075 #endif
3076 #if NETISO
3077 	"NETISO",
3078 #endif
3079 #if NETNS
3080 	"NETNS",
3081 #endif
3082 #if NETUNIX
3083 	"NETUNIX",
3084 #endif
3085 #if NETX25
3086 	"NETX25",
3087 #endif
3088 #if NEWDB
3089 	"NEWDB",
3090 #endif
3091 #if NIS
3092 	"NIS",
3093 #endif
3094 #if SCANF
3095 	"SCANF",
3096 #endif
3097 #if SUID_ROOT_FILES_OK
3098 	"SUID_ROOT_FILES_OK",
3099 #endif
3100 #if USERDB
3101 	"USERDB",
3102 #endif
3103 #if XDEBUG
3104 	"XDEBUG",
3105 #endif
3106 #if XLA
3107 	"XLA",
3108 #endif
3109 	NULL
3110 };
3111