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