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