xref: /illumos-gate/usr/src/cmd/sendmail/src/stab.c (revision 2a8bcb4efb45d99ac41c94a75c396b362c414f7f)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * Copyright (c) 1998-2001, 2003 Sendmail, Inc. and its suppliers.
37c478bd9Sstevel@tonic-gate  *	All rights reserved.
47c478bd9Sstevel@tonic-gate  * Copyright (c) 1983, 1995-1997 Eric P. Allman.  All rights reserved.
57c478bd9Sstevel@tonic-gate  * Copyright (c) 1988, 1993
67c478bd9Sstevel@tonic-gate  *	The Regents of the University of California.  All rights reserved.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * By using this file, you agree to the terms and conditions set
97c478bd9Sstevel@tonic-gate  * forth in the LICENSE file which can be found at the top level of
107c478bd9Sstevel@tonic-gate  * the sendmail distribution.
117c478bd9Sstevel@tonic-gate  *
127c478bd9Sstevel@tonic-gate  */
137c478bd9Sstevel@tonic-gate 
147c478bd9Sstevel@tonic-gate #include <sendmail.h>
157c478bd9Sstevel@tonic-gate 
16*058561cbSjbeck SM_RCSID("@(#)$Id: stab.c,v 8.89 2006/08/15 23:24:58 ca Exp $")
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate /*
197c478bd9Sstevel@tonic-gate **  STAB -- manage the symbol table
207c478bd9Sstevel@tonic-gate **
217c478bd9Sstevel@tonic-gate **	Parameters:
227c478bd9Sstevel@tonic-gate **		name -- the name to be looked up or inserted.
237c478bd9Sstevel@tonic-gate **		type -- the type of symbol.
247c478bd9Sstevel@tonic-gate **		op -- what to do:
257c478bd9Sstevel@tonic-gate **			ST_ENTER -- enter the name if not already present.
267c478bd9Sstevel@tonic-gate **			ST_FIND -- find it only.
277c478bd9Sstevel@tonic-gate **
287c478bd9Sstevel@tonic-gate **	Returns:
297c478bd9Sstevel@tonic-gate **		pointer to a STAB entry for this name.
307c478bd9Sstevel@tonic-gate **		NULL if not found and not entered.
317c478bd9Sstevel@tonic-gate **
327c478bd9Sstevel@tonic-gate **	Side Effects:
337c478bd9Sstevel@tonic-gate **		can update the symbol table.
347c478bd9Sstevel@tonic-gate */
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #define STABSIZE	2003
377c478bd9Sstevel@tonic-gate #define SM_LOWER(c)	((isascii(c) && isupper(c)) ? tolower(c) : (c))
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate static STAB	*SymTab[STABSIZE];
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate STAB *
stab(name,type,op)427c478bd9Sstevel@tonic-gate stab(name, type, op)
437c478bd9Sstevel@tonic-gate 	char *name;
447c478bd9Sstevel@tonic-gate 	int type;
457c478bd9Sstevel@tonic-gate 	int op;
467c478bd9Sstevel@tonic-gate {
477c478bd9Sstevel@tonic-gate 	register STAB *s;
487c478bd9Sstevel@tonic-gate 	register STAB **ps;
497c478bd9Sstevel@tonic-gate 	register int hfunc;
507c478bd9Sstevel@tonic-gate 	register char *p;
517c478bd9Sstevel@tonic-gate 	int len;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate 	if (tTd(36, 5))
547c478bd9Sstevel@tonic-gate 		sm_dprintf("STAB: %s %d ", name, type);
557c478bd9Sstevel@tonic-gate 
567c478bd9Sstevel@tonic-gate 	/*
577c478bd9Sstevel@tonic-gate 	**  Compute the hashing function
587c478bd9Sstevel@tonic-gate 	*/
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate 	hfunc = type;
617c478bd9Sstevel@tonic-gate 	for (p = name; *p != '\0'; p++)
627c478bd9Sstevel@tonic-gate 		hfunc = ((hfunc << 1) ^ (SM_LOWER(*p) & 0377)) % STABSIZE;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate 	if (tTd(36, 9))
657c478bd9Sstevel@tonic-gate 		sm_dprintf("(hfunc=%d) ", hfunc);
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate 	ps = &SymTab[hfunc];
687c478bd9Sstevel@tonic-gate 	if (type == ST_MACRO || type == ST_RULESET)
697c478bd9Sstevel@tonic-gate 	{
707c478bd9Sstevel@tonic-gate 		while ((s = *ps) != NULL &&
717c478bd9Sstevel@tonic-gate 		       (s->s_symtype != type || strcmp(name, s->s_name)))
727c478bd9Sstevel@tonic-gate 			ps = &s->s_next;
737c478bd9Sstevel@tonic-gate 	}
747c478bd9Sstevel@tonic-gate 	else
757c478bd9Sstevel@tonic-gate 	{
767c478bd9Sstevel@tonic-gate 		while ((s = *ps) != NULL &&
777c478bd9Sstevel@tonic-gate 		       (s->s_symtype != type || sm_strcasecmp(name, s->s_name)))
787c478bd9Sstevel@tonic-gate 			ps = &s->s_next;
797c478bd9Sstevel@tonic-gate 	}
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	/*
827c478bd9Sstevel@tonic-gate 	**  Dispose of the entry.
837c478bd9Sstevel@tonic-gate 	*/
847c478bd9Sstevel@tonic-gate 
857c478bd9Sstevel@tonic-gate 	if (s != NULL || op == ST_FIND)
867c478bd9Sstevel@tonic-gate 	{
877c478bd9Sstevel@tonic-gate 		if (tTd(36, 5))
887c478bd9Sstevel@tonic-gate 		{
897c478bd9Sstevel@tonic-gate 			if (s == NULL)
907c478bd9Sstevel@tonic-gate 				sm_dprintf("not found\n");
917c478bd9Sstevel@tonic-gate 			else
927c478bd9Sstevel@tonic-gate 			{
937c478bd9Sstevel@tonic-gate 				long *lp = (long *) s->s_class;
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 				sm_dprintf("type %d val %lx %lx %lx %lx\n",
967c478bd9Sstevel@tonic-gate 					s->s_symtype, lp[0], lp[1], lp[2], lp[3]);
977c478bd9Sstevel@tonic-gate 			}
987c478bd9Sstevel@tonic-gate 		}
997c478bd9Sstevel@tonic-gate 		return s;
1007c478bd9Sstevel@tonic-gate 	}
1017c478bd9Sstevel@tonic-gate 
1027c478bd9Sstevel@tonic-gate 	/*
1037c478bd9Sstevel@tonic-gate 	**  Make a new entry and link it in.
1047c478bd9Sstevel@tonic-gate 	*/
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate 	if (tTd(36, 5))
1077c478bd9Sstevel@tonic-gate 		sm_dprintf("entered\n");
1087c478bd9Sstevel@tonic-gate 
1097c478bd9Sstevel@tonic-gate 	/* determine size of new entry */
1107c478bd9Sstevel@tonic-gate 	switch (type)
1117c478bd9Sstevel@tonic-gate 	{
1127c478bd9Sstevel@tonic-gate 	  case ST_CLASS:
113*058561cbSjbeck 		len = sizeof(s->s_class);
1147c478bd9Sstevel@tonic-gate 		break;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	  case ST_ADDRESS:
117*058561cbSjbeck 		len = sizeof(s->s_address);
1187c478bd9Sstevel@tonic-gate 		break;
1197c478bd9Sstevel@tonic-gate 
1207c478bd9Sstevel@tonic-gate 	  case ST_MAILER:
121*058561cbSjbeck 		len = sizeof(s->s_mailer);
1227c478bd9Sstevel@tonic-gate 		break;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 	  case ST_ALIAS:
125*058561cbSjbeck 		len = sizeof(s->s_alias);
1267c478bd9Sstevel@tonic-gate 		break;
1277c478bd9Sstevel@tonic-gate 
1287c478bd9Sstevel@tonic-gate 	  case ST_MAPCLASS:
129*058561cbSjbeck 		len = sizeof(s->s_mapclass);
1307c478bd9Sstevel@tonic-gate 		break;
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	  case ST_MAP:
133*058561cbSjbeck 		len = sizeof(s->s_map);
1347c478bd9Sstevel@tonic-gate 		break;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate 	  case ST_HOSTSIG:
137*058561cbSjbeck 		len = sizeof(s->s_hostsig);
1387c478bd9Sstevel@tonic-gate 		break;
1397c478bd9Sstevel@tonic-gate 
1407c478bd9Sstevel@tonic-gate 	  case ST_NAMECANON:
141*058561cbSjbeck 		len = sizeof(s->s_namecanon);
1427c478bd9Sstevel@tonic-gate 		break;
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	  case ST_MACRO:
145*058561cbSjbeck 		len = sizeof(s->s_macro);
1467c478bd9Sstevel@tonic-gate 		break;
1477c478bd9Sstevel@tonic-gate 
1487c478bd9Sstevel@tonic-gate 	  case ST_RULESET:
149*058561cbSjbeck 		len = sizeof(s->s_ruleset);
1507c478bd9Sstevel@tonic-gate 		break;
1517c478bd9Sstevel@tonic-gate 
1527c478bd9Sstevel@tonic-gate 	  case ST_HEADER:
153*058561cbSjbeck 		len = sizeof(s->s_header);
1547c478bd9Sstevel@tonic-gate 		break;
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	  case ST_SERVICE:
157*058561cbSjbeck 		len = sizeof(s->s_service);
1587c478bd9Sstevel@tonic-gate 		break;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate #if LDAPMAP
1617c478bd9Sstevel@tonic-gate 	  case ST_LMAP:
162*058561cbSjbeck 		len = sizeof(s->s_lmap);
1637c478bd9Sstevel@tonic-gate 		break;
1647c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */
1657c478bd9Sstevel@tonic-gate 
1667c478bd9Sstevel@tonic-gate #if MILTER
1677c478bd9Sstevel@tonic-gate 	  case ST_MILTER:
168*058561cbSjbeck 		len = sizeof(s->s_milter);
1697c478bd9Sstevel@tonic-gate 		break;
1707c478bd9Sstevel@tonic-gate #endif /* MILTER */
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	  case ST_QUEUE:
173*058561cbSjbeck 		len = sizeof(s->s_quegrp);
1747c478bd9Sstevel@tonic-gate 		break;
1757c478bd9Sstevel@tonic-gate 
1767c478bd9Sstevel@tonic-gate #if SOCKETMAP
1777c478bd9Sstevel@tonic-gate 	  case ST_SOCKETMAP:
178*058561cbSjbeck 		len = sizeof(s->s_socketmap);
1797c478bd9Sstevel@tonic-gate 		break;
1807c478bd9Sstevel@tonic-gate #endif /* SOCKETMAP */
1817c478bd9Sstevel@tonic-gate 
1827c478bd9Sstevel@tonic-gate 	  default:
1837c478bd9Sstevel@tonic-gate 		/*
1847c478bd9Sstevel@tonic-gate 		**  Each mailer has its own MCI stab entry:
1857c478bd9Sstevel@tonic-gate 		**
1867c478bd9Sstevel@tonic-gate 		**  s = stab(host, ST_MCI + m->m_mno, ST_ENTER);
1877c478bd9Sstevel@tonic-gate 		**
1887c478bd9Sstevel@tonic-gate 		**  Therefore, anything ST_MCI or larger is an s_mci.
1897c478bd9Sstevel@tonic-gate 		*/
1907c478bd9Sstevel@tonic-gate 
1917c478bd9Sstevel@tonic-gate 		if (type >= ST_MCI)
192*058561cbSjbeck 			len = sizeof(s->s_mci);
1937c478bd9Sstevel@tonic-gate 		else
1947c478bd9Sstevel@tonic-gate 		{
1957c478bd9Sstevel@tonic-gate 			syserr("stab: unknown symbol type %d", type);
196*058561cbSjbeck 			len = sizeof(s->s_value);
1977c478bd9Sstevel@tonic-gate 		}
1987c478bd9Sstevel@tonic-gate 		break;
1997c478bd9Sstevel@tonic-gate 	}
200*058561cbSjbeck 	len += sizeof(*s) - sizeof(s->s_value);
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	if (tTd(36, 15))
2037c478bd9Sstevel@tonic-gate 		sm_dprintf("size of stab entry: %d\n", len);
2047c478bd9Sstevel@tonic-gate 
2057c478bd9Sstevel@tonic-gate 	/* make new entry */
2067c478bd9Sstevel@tonic-gate 	s = (STAB *) sm_pmalloc_x(len);
2077c478bd9Sstevel@tonic-gate 	memset((char *) s, '\0', len);
2087c478bd9Sstevel@tonic-gate 	s->s_name = sm_pstrdup_x(name);
2097c478bd9Sstevel@tonic-gate 	s->s_symtype = type;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	/* link it in */
2127c478bd9Sstevel@tonic-gate 	*ps = s;
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 	/* set a default value for rulesets */
2157c478bd9Sstevel@tonic-gate 	if (type == ST_RULESET)
2167c478bd9Sstevel@tonic-gate 		s->s_ruleset = -1;
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate 	return s;
2197c478bd9Sstevel@tonic-gate }
2207c478bd9Sstevel@tonic-gate /*
2217c478bd9Sstevel@tonic-gate **  STABAPPLY -- apply function to all stab entries
2227c478bd9Sstevel@tonic-gate **
2237c478bd9Sstevel@tonic-gate **	Parameters:
2247c478bd9Sstevel@tonic-gate **		func -- the function to apply.  It will be given two
2257c478bd9Sstevel@tonic-gate **			parameters (the stab entry and the arg).
2267c478bd9Sstevel@tonic-gate **		arg -- an arbitrary argument, passed to func.
2277c478bd9Sstevel@tonic-gate **
2287c478bd9Sstevel@tonic-gate **	Returns:
2297c478bd9Sstevel@tonic-gate **		none.
2307c478bd9Sstevel@tonic-gate */
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate void
2337c478bd9Sstevel@tonic-gate stabapply(func, arg)
2347c478bd9Sstevel@tonic-gate 	void (*func)__P((STAB *, int));
2357c478bd9Sstevel@tonic-gate 	int arg;
2367c478bd9Sstevel@tonic-gate {
2377c478bd9Sstevel@tonic-gate 	register STAB **shead;
2387c478bd9Sstevel@tonic-gate 	register STAB *s;
2397c478bd9Sstevel@tonic-gate 
2407c478bd9Sstevel@tonic-gate 	for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++)
2417c478bd9Sstevel@tonic-gate 	{
2427c478bd9Sstevel@tonic-gate 		for (s = *shead; s != NULL; s = s->s_next)
2437c478bd9Sstevel@tonic-gate 		{
2447c478bd9Sstevel@tonic-gate 			if (tTd(36, 90))
2457c478bd9Sstevel@tonic-gate 				sm_dprintf("stabapply: trying %d/%s\n",
2467c478bd9Sstevel@tonic-gate 					s->s_symtype, s->s_name);
2477c478bd9Sstevel@tonic-gate 			func(s, arg);
2487c478bd9Sstevel@tonic-gate 		}
2497c478bd9Sstevel@tonic-gate 	}
2507c478bd9Sstevel@tonic-gate }
2517c478bd9Sstevel@tonic-gate /*
2527c478bd9Sstevel@tonic-gate **  QUEUEUP_MACROS -- queueup the macros in a class
2537c478bd9Sstevel@tonic-gate **
2547c478bd9Sstevel@tonic-gate **	Write the macros listed in the specified class into the
2557c478bd9Sstevel@tonic-gate **	file referenced by qfp.
2567c478bd9Sstevel@tonic-gate **
2577c478bd9Sstevel@tonic-gate **	Parameters:
2587c478bd9Sstevel@tonic-gate **		class -- class ID.
2597c478bd9Sstevel@tonic-gate **		qfp -- file pointer to the queue file.
2607c478bd9Sstevel@tonic-gate **		e -- the envelope.
2617c478bd9Sstevel@tonic-gate **
2627c478bd9Sstevel@tonic-gate **	Returns:
2637c478bd9Sstevel@tonic-gate **		none.
2647c478bd9Sstevel@tonic-gate */
2657c478bd9Sstevel@tonic-gate 
2667c478bd9Sstevel@tonic-gate void
queueup_macros(class,qfp,e)2677c478bd9Sstevel@tonic-gate queueup_macros(class, qfp, e)
2687c478bd9Sstevel@tonic-gate 	int class;
2697c478bd9Sstevel@tonic-gate 	SM_FILE_T *qfp;
2707c478bd9Sstevel@tonic-gate 	ENVELOPE *e;
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate 	register STAB **shead;
2737c478bd9Sstevel@tonic-gate 	register STAB *s;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	if (e == NULL)
2767c478bd9Sstevel@tonic-gate 		return;
2777c478bd9Sstevel@tonic-gate 
2787c478bd9Sstevel@tonic-gate 	class = bitidx(class);
2797c478bd9Sstevel@tonic-gate 	for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++)
2807c478bd9Sstevel@tonic-gate 	{
2817c478bd9Sstevel@tonic-gate 		for (s = *shead; s != NULL; s = s->s_next)
2827c478bd9Sstevel@tonic-gate 		{
2837c478bd9Sstevel@tonic-gate 			int m;
2847c478bd9Sstevel@tonic-gate 			char *p;
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate 			if (s->s_symtype == ST_CLASS &&
2877c478bd9Sstevel@tonic-gate 			    bitnset(bitidx(class), s->s_class) &&
2887c478bd9Sstevel@tonic-gate 			    (m = macid(s->s_name)) != 0 &&
2897c478bd9Sstevel@tonic-gate 			    (p = macvalue(m, e)) != NULL)
2907c478bd9Sstevel@tonic-gate 			{
2917c478bd9Sstevel@tonic-gate 				(void) sm_io_fprintf(qfp, SM_TIME_DEFAULT,
2927c478bd9Sstevel@tonic-gate 						      "$%s%s\n",
2937c478bd9Sstevel@tonic-gate 						      s->s_name,
2947c478bd9Sstevel@tonic-gate 						      denlstring(p, true,
2957c478bd9Sstevel@tonic-gate 								 false));
2967c478bd9Sstevel@tonic-gate 			}
2977c478bd9Sstevel@tonic-gate 		}
2987c478bd9Sstevel@tonic-gate 	}
2997c478bd9Sstevel@tonic-gate }
3007c478bd9Sstevel@tonic-gate /*
3017c478bd9Sstevel@tonic-gate **  COPY_CLASS -- copy class members from one class to another
3027c478bd9Sstevel@tonic-gate **
3037c478bd9Sstevel@tonic-gate **	Parameters:
3047c478bd9Sstevel@tonic-gate **		src -- source class.
3057c478bd9Sstevel@tonic-gate **		dst -- destination class.
3067c478bd9Sstevel@tonic-gate **
3077c478bd9Sstevel@tonic-gate **	Returns:
3087c478bd9Sstevel@tonic-gate **		none.
3097c478bd9Sstevel@tonic-gate */
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate void
copy_class(src,dst)3127c478bd9Sstevel@tonic-gate copy_class(src, dst)
3137c478bd9Sstevel@tonic-gate 	int src;
3147c478bd9Sstevel@tonic-gate 	int dst;
3157c478bd9Sstevel@tonic-gate {
3167c478bd9Sstevel@tonic-gate 	register STAB **shead;
3177c478bd9Sstevel@tonic-gate 	register STAB *s;
3187c478bd9Sstevel@tonic-gate 
3197c478bd9Sstevel@tonic-gate 	src = bitidx(src);
3207c478bd9Sstevel@tonic-gate 	dst = bitidx(dst);
3217c478bd9Sstevel@tonic-gate 	for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++)
3227c478bd9Sstevel@tonic-gate 	{
3237c478bd9Sstevel@tonic-gate 		for (s = *shead; s != NULL; s = s->s_next)
3247c478bd9Sstevel@tonic-gate 		{
3257c478bd9Sstevel@tonic-gate 			if (s->s_symtype == ST_CLASS &&
3267c478bd9Sstevel@tonic-gate 			    bitnset(src, s->s_class))
3277c478bd9Sstevel@tonic-gate 				setbitn(dst, s->s_class);
3287c478bd9Sstevel@tonic-gate 		}
3297c478bd9Sstevel@tonic-gate 	}
3307c478bd9Sstevel@tonic-gate }
3317c478bd9Sstevel@tonic-gate 
3327c478bd9Sstevel@tonic-gate /*
3337c478bd9Sstevel@tonic-gate **  RMEXPSTAB -- remove expired entries from SymTab.
3347c478bd9Sstevel@tonic-gate **
3357c478bd9Sstevel@tonic-gate **	These entries need to be removed in long-running processes,
3367c478bd9Sstevel@tonic-gate **	e.g., persistent queue runners, to avoid consuming memory.
3377c478bd9Sstevel@tonic-gate **
3387c478bd9Sstevel@tonic-gate **	XXX It might be useful to restrict the maximum TTL to avoid
3397c478bd9Sstevel@tonic-gate **		caching data very long.
3407c478bd9Sstevel@tonic-gate **
3417c478bd9Sstevel@tonic-gate **	Parameters:
3427c478bd9Sstevel@tonic-gate **		none.
3437c478bd9Sstevel@tonic-gate **
3447c478bd9Sstevel@tonic-gate **	Returns:
3457c478bd9Sstevel@tonic-gate **		none.
3467c478bd9Sstevel@tonic-gate **
3477c478bd9Sstevel@tonic-gate **	Side Effects:
3487c478bd9Sstevel@tonic-gate **		can remove entries from the symbol table.
3497c478bd9Sstevel@tonic-gate */
3507c478bd9Sstevel@tonic-gate 
3517c478bd9Sstevel@tonic-gate #define SM_STAB_FREE(x)	\
3527c478bd9Sstevel@tonic-gate 	do \
3537c478bd9Sstevel@tonic-gate 	{ \
3547c478bd9Sstevel@tonic-gate 		char *o = (x); \
3557c478bd9Sstevel@tonic-gate 		(x) = NULL; \
3567c478bd9Sstevel@tonic-gate 		if (o != NULL) \
3577c478bd9Sstevel@tonic-gate 			sm_free(o); \
3587c478bd9Sstevel@tonic-gate 	} while (0)
3597c478bd9Sstevel@tonic-gate 
3607c478bd9Sstevel@tonic-gate void
rmexpstab()3617c478bd9Sstevel@tonic-gate rmexpstab()
3627c478bd9Sstevel@tonic-gate {
3637c478bd9Sstevel@tonic-gate 	int i;
3647c478bd9Sstevel@tonic-gate 	STAB *s, *p, *f;
3657c478bd9Sstevel@tonic-gate 	time_t now;
3667c478bd9Sstevel@tonic-gate 
3677c478bd9Sstevel@tonic-gate 	now = curtime();
3687c478bd9Sstevel@tonic-gate 	for (i = 0; i < STABSIZE; i++)
3697c478bd9Sstevel@tonic-gate 	{
3707c478bd9Sstevel@tonic-gate 		p = NULL;
3717c478bd9Sstevel@tonic-gate 		s = SymTab[i];
3727c478bd9Sstevel@tonic-gate 		while (s != NULL)
3737c478bd9Sstevel@tonic-gate 		{
3747c478bd9Sstevel@tonic-gate 			switch (s->s_symtype)
3757c478bd9Sstevel@tonic-gate 			{
3767c478bd9Sstevel@tonic-gate 			  case ST_HOSTSIG:
3777c478bd9Sstevel@tonic-gate 				if (s->s_hostsig.hs_exp >= now)
3787c478bd9Sstevel@tonic-gate 					goto next;	/* not expired */
3797c478bd9Sstevel@tonic-gate 				SM_STAB_FREE(s->s_hostsig.hs_sig); /* XXX */
3807c478bd9Sstevel@tonic-gate 				break;
3817c478bd9Sstevel@tonic-gate 
3827c478bd9Sstevel@tonic-gate 			  case ST_NAMECANON:
3837c478bd9Sstevel@tonic-gate 				if (s->s_namecanon.nc_exp >= now)
3847c478bd9Sstevel@tonic-gate 					goto next;	/* not expired */
3857c478bd9Sstevel@tonic-gate 				SM_STAB_FREE(s->s_namecanon.nc_cname); /* XXX */
3867c478bd9Sstevel@tonic-gate 				break;
3877c478bd9Sstevel@tonic-gate 
3887c478bd9Sstevel@tonic-gate 			  default:
3897c478bd9Sstevel@tonic-gate 				if (s->s_symtype >= ST_MCI)
3907c478bd9Sstevel@tonic-gate 				{
3917c478bd9Sstevel@tonic-gate 					/* call mci_uncache? */
3927c478bd9Sstevel@tonic-gate 					SM_STAB_FREE(s->s_mci.mci_status);
3937c478bd9Sstevel@tonic-gate 					SM_STAB_FREE(s->s_mci.mci_rstatus);
3947c478bd9Sstevel@tonic-gate 					SM_STAB_FREE(s->s_mci.mci_heloname);
3957c478bd9Sstevel@tonic-gate #if 0
3967c478bd9Sstevel@tonic-gate 					/* not dynamically allocated */
3977c478bd9Sstevel@tonic-gate 					SM_STAB_FREE(s->s_mci.mci_host);
3987c478bd9Sstevel@tonic-gate 					SM_STAB_FREE(s->s_mci.mci_tolist);
3997c478bd9Sstevel@tonic-gate #endif /* 0 */
4007c478bd9Sstevel@tonic-gate #if SASL
4017c478bd9Sstevel@tonic-gate 					/* should always by NULL */
4027c478bd9Sstevel@tonic-gate 					SM_STAB_FREE(s->s_mci.mci_sasl_string);
4037c478bd9Sstevel@tonic-gate #endif /* SASL */
4047c478bd9Sstevel@tonic-gate 					if (s->s_mci.mci_rpool != NULL)
4057c478bd9Sstevel@tonic-gate 					{
4067c478bd9Sstevel@tonic-gate 						sm_rpool_free(s->s_mci.mci_rpool);
4077c478bd9Sstevel@tonic-gate 						s->s_mci.mci_macro.mac_rpool = NULL;
4087c478bd9Sstevel@tonic-gate 						s->s_mci.mci_rpool = NULL;
4097c478bd9Sstevel@tonic-gate 					}
4107c478bd9Sstevel@tonic-gate 					break;
4117c478bd9Sstevel@tonic-gate 				}
4127c478bd9Sstevel@tonic-gate   next:
4137c478bd9Sstevel@tonic-gate 				p = s;
4147c478bd9Sstevel@tonic-gate 				s = s->s_next;
4157c478bd9Sstevel@tonic-gate 				continue;
4167c478bd9Sstevel@tonic-gate 			}
4177c478bd9Sstevel@tonic-gate 
4187c478bd9Sstevel@tonic-gate 			/* remove entry */
4197c478bd9Sstevel@tonic-gate 			SM_STAB_FREE(s->s_name); /* XXX */
4207c478bd9Sstevel@tonic-gate 			f = s;
4217c478bd9Sstevel@tonic-gate 			s = s->s_next;
4227c478bd9Sstevel@tonic-gate 			sm_free(f);	/* XXX */
4237c478bd9Sstevel@tonic-gate 			if (p == NULL)
4247c478bd9Sstevel@tonic-gate 				SymTab[i] = s;
4257c478bd9Sstevel@tonic-gate 			else
4267c478bd9Sstevel@tonic-gate 				p->s_next = s;
4277c478bd9Sstevel@tonic-gate 		}
4287c478bd9Sstevel@tonic-gate 	}
4297c478bd9Sstevel@tonic-gate }
4307c478bd9Sstevel@tonic-gate 
4317c478bd9Sstevel@tonic-gate #if SM_HEAP_CHECK
4327c478bd9Sstevel@tonic-gate /*
4337c478bd9Sstevel@tonic-gate **  DUMPSTAB -- dump symbol table.
4347c478bd9Sstevel@tonic-gate **
4357c478bd9Sstevel@tonic-gate **	For debugging.
4367c478bd9Sstevel@tonic-gate */
4377c478bd9Sstevel@tonic-gate 
4387c478bd9Sstevel@tonic-gate #define MAXSTTYPES	(ST_MCI + 1)
4397c478bd9Sstevel@tonic-gate 
4407c478bd9Sstevel@tonic-gate void
dumpstab()4417c478bd9Sstevel@tonic-gate dumpstab()
4427c478bd9Sstevel@tonic-gate {
4437c478bd9Sstevel@tonic-gate 	int i, t, total, types[MAXSTTYPES];
4447c478bd9Sstevel@tonic-gate 	STAB *s;
4457c478bd9Sstevel@tonic-gate 	static int prevt[MAXSTTYPES], prev = 0;
4467c478bd9Sstevel@tonic-gate 
4477c478bd9Sstevel@tonic-gate 	total = 0;
4487c478bd9Sstevel@tonic-gate 	for (i = 0; i < MAXSTTYPES; i++)
4497c478bd9Sstevel@tonic-gate 		types[i] = 0;
4507c478bd9Sstevel@tonic-gate 	for (i = 0; i < STABSIZE; i++)
4517c478bd9Sstevel@tonic-gate 	{
4527c478bd9Sstevel@tonic-gate 		s = SymTab[i];
4537c478bd9Sstevel@tonic-gate 		while (s != NULL)
4547c478bd9Sstevel@tonic-gate 		{
4557c478bd9Sstevel@tonic-gate 			++total;
4567c478bd9Sstevel@tonic-gate 			t = s->s_symtype;
4577c478bd9Sstevel@tonic-gate 			if (t > MAXSTTYPES - 1)
4587c478bd9Sstevel@tonic-gate 				t = MAXSTTYPES - 1;
4597c478bd9Sstevel@tonic-gate 			types[t]++;
4607c478bd9Sstevel@tonic-gate 			s = s->s_next;
4617c478bd9Sstevel@tonic-gate 		}
4627c478bd9Sstevel@tonic-gate 	}
4637c478bd9Sstevel@tonic-gate 	sm_syslog(LOG_INFO, NOQID, "stab: total=%d (%d)", total, total - prev);
4647c478bd9Sstevel@tonic-gate 	prev = total;
4657c478bd9Sstevel@tonic-gate 	for (i = 0; i < MAXSTTYPES; i++)
4667c478bd9Sstevel@tonic-gate 	{
4677c478bd9Sstevel@tonic-gate 		if (types[i] != 0)
4687c478bd9Sstevel@tonic-gate 		{
4697c478bd9Sstevel@tonic-gate 			sm_syslog(LOG_INFO, NOQID, "stab: type[%2d]=%2d (%d)",
4707c478bd9Sstevel@tonic-gate 				i, types[i], types[i] - prevt[i]);
4717c478bd9Sstevel@tonic-gate 		}
4727c478bd9Sstevel@tonic-gate 		prevt[i] = types[i];
4737c478bd9Sstevel@tonic-gate 	}
4747c478bd9Sstevel@tonic-gate }
4757c478bd9Sstevel@tonic-gate #endif /* SM_HEAP_CHECK */
476