1*7c478bd9Sstevel@tonic-gate /* 2*7c478bd9Sstevel@tonic-gate * Copyright (c) 1998-2001, 2003 Sendmail, Inc. and its suppliers. 3*7c478bd9Sstevel@tonic-gate * All rights reserved. 4*7c478bd9Sstevel@tonic-gate * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved. 5*7c478bd9Sstevel@tonic-gate * Copyright (c) 1988, 1993 6*7c478bd9Sstevel@tonic-gate * The Regents of the University of California. All rights reserved. 7*7c478bd9Sstevel@tonic-gate * 8*7c478bd9Sstevel@tonic-gate * By using this file, you agree to the terms and conditions set 9*7c478bd9Sstevel@tonic-gate * forth in the LICENSE file which can be found at the top level of 10*7c478bd9Sstevel@tonic-gate * the sendmail distribution. 11*7c478bd9Sstevel@tonic-gate * 12*7c478bd9Sstevel@tonic-gate */ 13*7c478bd9Sstevel@tonic-gate 14*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 15*7c478bd9Sstevel@tonic-gate 16*7c478bd9Sstevel@tonic-gate #include <sendmail.h> 17*7c478bd9Sstevel@tonic-gate 18*7c478bd9Sstevel@tonic-gate SM_RCSID("@(#)$Id: stab.c,v 8.88 2003/05/21 15:36:30 ca Exp $") 19*7c478bd9Sstevel@tonic-gate 20*7c478bd9Sstevel@tonic-gate /* 21*7c478bd9Sstevel@tonic-gate ** STAB -- manage the symbol table 22*7c478bd9Sstevel@tonic-gate ** 23*7c478bd9Sstevel@tonic-gate ** Parameters: 24*7c478bd9Sstevel@tonic-gate ** name -- the name to be looked up or inserted. 25*7c478bd9Sstevel@tonic-gate ** type -- the type of symbol. 26*7c478bd9Sstevel@tonic-gate ** op -- what to do: 27*7c478bd9Sstevel@tonic-gate ** ST_ENTER -- enter the name if not already present. 28*7c478bd9Sstevel@tonic-gate ** ST_FIND -- find it only. 29*7c478bd9Sstevel@tonic-gate ** 30*7c478bd9Sstevel@tonic-gate ** Returns: 31*7c478bd9Sstevel@tonic-gate ** pointer to a STAB entry for this name. 32*7c478bd9Sstevel@tonic-gate ** NULL if not found and not entered. 33*7c478bd9Sstevel@tonic-gate ** 34*7c478bd9Sstevel@tonic-gate ** Side Effects: 35*7c478bd9Sstevel@tonic-gate ** can update the symbol table. 36*7c478bd9Sstevel@tonic-gate */ 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate #define STABSIZE 2003 39*7c478bd9Sstevel@tonic-gate #define SM_LOWER(c) ((isascii(c) && isupper(c)) ? tolower(c) : (c)) 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate static STAB *SymTab[STABSIZE]; 42*7c478bd9Sstevel@tonic-gate 43*7c478bd9Sstevel@tonic-gate STAB * 44*7c478bd9Sstevel@tonic-gate stab(name, type, op) 45*7c478bd9Sstevel@tonic-gate char *name; 46*7c478bd9Sstevel@tonic-gate int type; 47*7c478bd9Sstevel@tonic-gate int op; 48*7c478bd9Sstevel@tonic-gate { 49*7c478bd9Sstevel@tonic-gate register STAB *s; 50*7c478bd9Sstevel@tonic-gate register STAB **ps; 51*7c478bd9Sstevel@tonic-gate register int hfunc; 52*7c478bd9Sstevel@tonic-gate register char *p; 53*7c478bd9Sstevel@tonic-gate int len; 54*7c478bd9Sstevel@tonic-gate 55*7c478bd9Sstevel@tonic-gate if (tTd(36, 5)) 56*7c478bd9Sstevel@tonic-gate sm_dprintf("STAB: %s %d ", name, type); 57*7c478bd9Sstevel@tonic-gate 58*7c478bd9Sstevel@tonic-gate /* 59*7c478bd9Sstevel@tonic-gate ** Compute the hashing function 60*7c478bd9Sstevel@tonic-gate */ 61*7c478bd9Sstevel@tonic-gate 62*7c478bd9Sstevel@tonic-gate hfunc = type; 63*7c478bd9Sstevel@tonic-gate for (p = name; *p != '\0'; p++) 64*7c478bd9Sstevel@tonic-gate hfunc = ((hfunc << 1) ^ (SM_LOWER(*p) & 0377)) % STABSIZE; 65*7c478bd9Sstevel@tonic-gate 66*7c478bd9Sstevel@tonic-gate if (tTd(36, 9)) 67*7c478bd9Sstevel@tonic-gate sm_dprintf("(hfunc=%d) ", hfunc); 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate ps = &SymTab[hfunc]; 70*7c478bd9Sstevel@tonic-gate if (type == ST_MACRO || type == ST_RULESET) 71*7c478bd9Sstevel@tonic-gate { 72*7c478bd9Sstevel@tonic-gate while ((s = *ps) != NULL && 73*7c478bd9Sstevel@tonic-gate (s->s_symtype != type || strcmp(name, s->s_name))) 74*7c478bd9Sstevel@tonic-gate ps = &s->s_next; 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate else 77*7c478bd9Sstevel@tonic-gate { 78*7c478bd9Sstevel@tonic-gate while ((s = *ps) != NULL && 79*7c478bd9Sstevel@tonic-gate (s->s_symtype != type || sm_strcasecmp(name, s->s_name))) 80*7c478bd9Sstevel@tonic-gate ps = &s->s_next; 81*7c478bd9Sstevel@tonic-gate } 82*7c478bd9Sstevel@tonic-gate 83*7c478bd9Sstevel@tonic-gate /* 84*7c478bd9Sstevel@tonic-gate ** Dispose of the entry. 85*7c478bd9Sstevel@tonic-gate */ 86*7c478bd9Sstevel@tonic-gate 87*7c478bd9Sstevel@tonic-gate if (s != NULL || op == ST_FIND) 88*7c478bd9Sstevel@tonic-gate { 89*7c478bd9Sstevel@tonic-gate if (tTd(36, 5)) 90*7c478bd9Sstevel@tonic-gate { 91*7c478bd9Sstevel@tonic-gate if (s == NULL) 92*7c478bd9Sstevel@tonic-gate sm_dprintf("not found\n"); 93*7c478bd9Sstevel@tonic-gate else 94*7c478bd9Sstevel@tonic-gate { 95*7c478bd9Sstevel@tonic-gate long *lp = (long *) s->s_class; 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate sm_dprintf("type %d val %lx %lx %lx %lx\n", 98*7c478bd9Sstevel@tonic-gate s->s_symtype, lp[0], lp[1], lp[2], lp[3]); 99*7c478bd9Sstevel@tonic-gate } 100*7c478bd9Sstevel@tonic-gate } 101*7c478bd9Sstevel@tonic-gate return s; 102*7c478bd9Sstevel@tonic-gate } 103*7c478bd9Sstevel@tonic-gate 104*7c478bd9Sstevel@tonic-gate /* 105*7c478bd9Sstevel@tonic-gate ** Make a new entry and link it in. 106*7c478bd9Sstevel@tonic-gate */ 107*7c478bd9Sstevel@tonic-gate 108*7c478bd9Sstevel@tonic-gate if (tTd(36, 5)) 109*7c478bd9Sstevel@tonic-gate sm_dprintf("entered\n"); 110*7c478bd9Sstevel@tonic-gate 111*7c478bd9Sstevel@tonic-gate /* determine size of new entry */ 112*7c478bd9Sstevel@tonic-gate switch (type) 113*7c478bd9Sstevel@tonic-gate { 114*7c478bd9Sstevel@tonic-gate case ST_CLASS: 115*7c478bd9Sstevel@tonic-gate len = sizeof s->s_class; 116*7c478bd9Sstevel@tonic-gate break; 117*7c478bd9Sstevel@tonic-gate 118*7c478bd9Sstevel@tonic-gate case ST_ADDRESS: 119*7c478bd9Sstevel@tonic-gate len = sizeof s->s_address; 120*7c478bd9Sstevel@tonic-gate break; 121*7c478bd9Sstevel@tonic-gate 122*7c478bd9Sstevel@tonic-gate case ST_MAILER: 123*7c478bd9Sstevel@tonic-gate len = sizeof s->s_mailer; 124*7c478bd9Sstevel@tonic-gate break; 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate case ST_ALIAS: 127*7c478bd9Sstevel@tonic-gate len = sizeof s->s_alias; 128*7c478bd9Sstevel@tonic-gate break; 129*7c478bd9Sstevel@tonic-gate 130*7c478bd9Sstevel@tonic-gate case ST_MAPCLASS: 131*7c478bd9Sstevel@tonic-gate len = sizeof s->s_mapclass; 132*7c478bd9Sstevel@tonic-gate break; 133*7c478bd9Sstevel@tonic-gate 134*7c478bd9Sstevel@tonic-gate case ST_MAP: 135*7c478bd9Sstevel@tonic-gate len = sizeof s->s_map; 136*7c478bd9Sstevel@tonic-gate break; 137*7c478bd9Sstevel@tonic-gate 138*7c478bd9Sstevel@tonic-gate case ST_HOSTSIG: 139*7c478bd9Sstevel@tonic-gate len = sizeof s->s_hostsig; 140*7c478bd9Sstevel@tonic-gate break; 141*7c478bd9Sstevel@tonic-gate 142*7c478bd9Sstevel@tonic-gate case ST_NAMECANON: 143*7c478bd9Sstevel@tonic-gate len = sizeof s->s_namecanon; 144*7c478bd9Sstevel@tonic-gate break; 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate case ST_MACRO: 147*7c478bd9Sstevel@tonic-gate len = sizeof s->s_macro; 148*7c478bd9Sstevel@tonic-gate break; 149*7c478bd9Sstevel@tonic-gate 150*7c478bd9Sstevel@tonic-gate case ST_RULESET: 151*7c478bd9Sstevel@tonic-gate len = sizeof s->s_ruleset; 152*7c478bd9Sstevel@tonic-gate break; 153*7c478bd9Sstevel@tonic-gate 154*7c478bd9Sstevel@tonic-gate case ST_HEADER: 155*7c478bd9Sstevel@tonic-gate len = sizeof s->s_header; 156*7c478bd9Sstevel@tonic-gate break; 157*7c478bd9Sstevel@tonic-gate 158*7c478bd9Sstevel@tonic-gate case ST_SERVICE: 159*7c478bd9Sstevel@tonic-gate len = sizeof s->s_service; 160*7c478bd9Sstevel@tonic-gate break; 161*7c478bd9Sstevel@tonic-gate 162*7c478bd9Sstevel@tonic-gate #if LDAPMAP 163*7c478bd9Sstevel@tonic-gate case ST_LMAP: 164*7c478bd9Sstevel@tonic-gate len = sizeof s->s_lmap; 165*7c478bd9Sstevel@tonic-gate break; 166*7c478bd9Sstevel@tonic-gate #endif /* LDAPMAP */ 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate #if MILTER 169*7c478bd9Sstevel@tonic-gate case ST_MILTER: 170*7c478bd9Sstevel@tonic-gate len = sizeof s->s_milter; 171*7c478bd9Sstevel@tonic-gate break; 172*7c478bd9Sstevel@tonic-gate #endif /* MILTER */ 173*7c478bd9Sstevel@tonic-gate 174*7c478bd9Sstevel@tonic-gate case ST_QUEUE: 175*7c478bd9Sstevel@tonic-gate len = sizeof s->s_quegrp; 176*7c478bd9Sstevel@tonic-gate break; 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate #if SOCKETMAP 179*7c478bd9Sstevel@tonic-gate case ST_SOCKETMAP: 180*7c478bd9Sstevel@tonic-gate len = sizeof s->s_socketmap; 181*7c478bd9Sstevel@tonic-gate break; 182*7c478bd9Sstevel@tonic-gate #endif /* SOCKETMAP */ 183*7c478bd9Sstevel@tonic-gate 184*7c478bd9Sstevel@tonic-gate default: 185*7c478bd9Sstevel@tonic-gate /* 186*7c478bd9Sstevel@tonic-gate ** Each mailer has its own MCI stab entry: 187*7c478bd9Sstevel@tonic-gate ** 188*7c478bd9Sstevel@tonic-gate ** s = stab(host, ST_MCI + m->m_mno, ST_ENTER); 189*7c478bd9Sstevel@tonic-gate ** 190*7c478bd9Sstevel@tonic-gate ** Therefore, anything ST_MCI or larger is an s_mci. 191*7c478bd9Sstevel@tonic-gate */ 192*7c478bd9Sstevel@tonic-gate 193*7c478bd9Sstevel@tonic-gate if (type >= ST_MCI) 194*7c478bd9Sstevel@tonic-gate len = sizeof s->s_mci; 195*7c478bd9Sstevel@tonic-gate else 196*7c478bd9Sstevel@tonic-gate { 197*7c478bd9Sstevel@tonic-gate syserr("stab: unknown symbol type %d", type); 198*7c478bd9Sstevel@tonic-gate len = sizeof s->s_value; 199*7c478bd9Sstevel@tonic-gate } 200*7c478bd9Sstevel@tonic-gate break; 201*7c478bd9Sstevel@tonic-gate } 202*7c478bd9Sstevel@tonic-gate len += sizeof *s - sizeof s->s_value; 203*7c478bd9Sstevel@tonic-gate 204*7c478bd9Sstevel@tonic-gate if (tTd(36, 15)) 205*7c478bd9Sstevel@tonic-gate sm_dprintf("size of stab entry: %d\n", len); 206*7c478bd9Sstevel@tonic-gate 207*7c478bd9Sstevel@tonic-gate /* make new entry */ 208*7c478bd9Sstevel@tonic-gate s = (STAB *) sm_pmalloc_x(len); 209*7c478bd9Sstevel@tonic-gate memset((char *) s, '\0', len); 210*7c478bd9Sstevel@tonic-gate s->s_name = sm_pstrdup_x(name); 211*7c478bd9Sstevel@tonic-gate s->s_symtype = type; 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gate /* link it in */ 214*7c478bd9Sstevel@tonic-gate *ps = s; 215*7c478bd9Sstevel@tonic-gate 216*7c478bd9Sstevel@tonic-gate /* set a default value for rulesets */ 217*7c478bd9Sstevel@tonic-gate if (type == ST_RULESET) 218*7c478bd9Sstevel@tonic-gate s->s_ruleset = -1; 219*7c478bd9Sstevel@tonic-gate 220*7c478bd9Sstevel@tonic-gate return s; 221*7c478bd9Sstevel@tonic-gate } 222*7c478bd9Sstevel@tonic-gate /* 223*7c478bd9Sstevel@tonic-gate ** STABAPPLY -- apply function to all stab entries 224*7c478bd9Sstevel@tonic-gate ** 225*7c478bd9Sstevel@tonic-gate ** Parameters: 226*7c478bd9Sstevel@tonic-gate ** func -- the function to apply. It will be given two 227*7c478bd9Sstevel@tonic-gate ** parameters (the stab entry and the arg). 228*7c478bd9Sstevel@tonic-gate ** arg -- an arbitrary argument, passed to func. 229*7c478bd9Sstevel@tonic-gate ** 230*7c478bd9Sstevel@tonic-gate ** Returns: 231*7c478bd9Sstevel@tonic-gate ** none. 232*7c478bd9Sstevel@tonic-gate */ 233*7c478bd9Sstevel@tonic-gate 234*7c478bd9Sstevel@tonic-gate void 235*7c478bd9Sstevel@tonic-gate stabapply(func, arg) 236*7c478bd9Sstevel@tonic-gate void (*func)__P((STAB *, int)); 237*7c478bd9Sstevel@tonic-gate int arg; 238*7c478bd9Sstevel@tonic-gate { 239*7c478bd9Sstevel@tonic-gate register STAB **shead; 240*7c478bd9Sstevel@tonic-gate register STAB *s; 241*7c478bd9Sstevel@tonic-gate 242*7c478bd9Sstevel@tonic-gate for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++) 243*7c478bd9Sstevel@tonic-gate { 244*7c478bd9Sstevel@tonic-gate for (s = *shead; s != NULL; s = s->s_next) 245*7c478bd9Sstevel@tonic-gate { 246*7c478bd9Sstevel@tonic-gate if (tTd(36, 90)) 247*7c478bd9Sstevel@tonic-gate sm_dprintf("stabapply: trying %d/%s\n", 248*7c478bd9Sstevel@tonic-gate s->s_symtype, s->s_name); 249*7c478bd9Sstevel@tonic-gate func(s, arg); 250*7c478bd9Sstevel@tonic-gate } 251*7c478bd9Sstevel@tonic-gate } 252*7c478bd9Sstevel@tonic-gate } 253*7c478bd9Sstevel@tonic-gate /* 254*7c478bd9Sstevel@tonic-gate ** QUEUEUP_MACROS -- queueup the macros in a class 255*7c478bd9Sstevel@tonic-gate ** 256*7c478bd9Sstevel@tonic-gate ** Write the macros listed in the specified class into the 257*7c478bd9Sstevel@tonic-gate ** file referenced by qfp. 258*7c478bd9Sstevel@tonic-gate ** 259*7c478bd9Sstevel@tonic-gate ** Parameters: 260*7c478bd9Sstevel@tonic-gate ** class -- class ID. 261*7c478bd9Sstevel@tonic-gate ** qfp -- file pointer to the queue file. 262*7c478bd9Sstevel@tonic-gate ** e -- the envelope. 263*7c478bd9Sstevel@tonic-gate ** 264*7c478bd9Sstevel@tonic-gate ** Returns: 265*7c478bd9Sstevel@tonic-gate ** none. 266*7c478bd9Sstevel@tonic-gate */ 267*7c478bd9Sstevel@tonic-gate 268*7c478bd9Sstevel@tonic-gate void 269*7c478bd9Sstevel@tonic-gate queueup_macros(class, qfp, e) 270*7c478bd9Sstevel@tonic-gate int class; 271*7c478bd9Sstevel@tonic-gate SM_FILE_T *qfp; 272*7c478bd9Sstevel@tonic-gate ENVELOPE *e; 273*7c478bd9Sstevel@tonic-gate { 274*7c478bd9Sstevel@tonic-gate register STAB **shead; 275*7c478bd9Sstevel@tonic-gate register STAB *s; 276*7c478bd9Sstevel@tonic-gate 277*7c478bd9Sstevel@tonic-gate if (e == NULL) 278*7c478bd9Sstevel@tonic-gate return; 279*7c478bd9Sstevel@tonic-gate 280*7c478bd9Sstevel@tonic-gate class = bitidx(class); 281*7c478bd9Sstevel@tonic-gate for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++) 282*7c478bd9Sstevel@tonic-gate { 283*7c478bd9Sstevel@tonic-gate for (s = *shead; s != NULL; s = s->s_next) 284*7c478bd9Sstevel@tonic-gate { 285*7c478bd9Sstevel@tonic-gate int m; 286*7c478bd9Sstevel@tonic-gate char *p; 287*7c478bd9Sstevel@tonic-gate 288*7c478bd9Sstevel@tonic-gate if (s->s_symtype == ST_CLASS && 289*7c478bd9Sstevel@tonic-gate bitnset(bitidx(class), s->s_class) && 290*7c478bd9Sstevel@tonic-gate (m = macid(s->s_name)) != 0 && 291*7c478bd9Sstevel@tonic-gate (p = macvalue(m, e)) != NULL) 292*7c478bd9Sstevel@tonic-gate { 293*7c478bd9Sstevel@tonic-gate (void) sm_io_fprintf(qfp, SM_TIME_DEFAULT, 294*7c478bd9Sstevel@tonic-gate "$%s%s\n", 295*7c478bd9Sstevel@tonic-gate s->s_name, 296*7c478bd9Sstevel@tonic-gate denlstring(p, true, 297*7c478bd9Sstevel@tonic-gate false)); 298*7c478bd9Sstevel@tonic-gate } 299*7c478bd9Sstevel@tonic-gate } 300*7c478bd9Sstevel@tonic-gate } 301*7c478bd9Sstevel@tonic-gate } 302*7c478bd9Sstevel@tonic-gate /* 303*7c478bd9Sstevel@tonic-gate ** COPY_CLASS -- copy class members from one class to another 304*7c478bd9Sstevel@tonic-gate ** 305*7c478bd9Sstevel@tonic-gate ** Parameters: 306*7c478bd9Sstevel@tonic-gate ** src -- source class. 307*7c478bd9Sstevel@tonic-gate ** dst -- destination class. 308*7c478bd9Sstevel@tonic-gate ** 309*7c478bd9Sstevel@tonic-gate ** Returns: 310*7c478bd9Sstevel@tonic-gate ** none. 311*7c478bd9Sstevel@tonic-gate */ 312*7c478bd9Sstevel@tonic-gate 313*7c478bd9Sstevel@tonic-gate void 314*7c478bd9Sstevel@tonic-gate copy_class(src, dst) 315*7c478bd9Sstevel@tonic-gate int src; 316*7c478bd9Sstevel@tonic-gate int dst; 317*7c478bd9Sstevel@tonic-gate { 318*7c478bd9Sstevel@tonic-gate register STAB **shead; 319*7c478bd9Sstevel@tonic-gate register STAB *s; 320*7c478bd9Sstevel@tonic-gate 321*7c478bd9Sstevel@tonic-gate src = bitidx(src); 322*7c478bd9Sstevel@tonic-gate dst = bitidx(dst); 323*7c478bd9Sstevel@tonic-gate for (shead = SymTab; shead < &SymTab[STABSIZE]; shead++) 324*7c478bd9Sstevel@tonic-gate { 325*7c478bd9Sstevel@tonic-gate for (s = *shead; s != NULL; s = s->s_next) 326*7c478bd9Sstevel@tonic-gate { 327*7c478bd9Sstevel@tonic-gate if (s->s_symtype == ST_CLASS && 328*7c478bd9Sstevel@tonic-gate bitnset(src, s->s_class)) 329*7c478bd9Sstevel@tonic-gate setbitn(dst, s->s_class); 330*7c478bd9Sstevel@tonic-gate } 331*7c478bd9Sstevel@tonic-gate } 332*7c478bd9Sstevel@tonic-gate } 333*7c478bd9Sstevel@tonic-gate 334*7c478bd9Sstevel@tonic-gate /* 335*7c478bd9Sstevel@tonic-gate ** RMEXPSTAB -- remove expired entries from SymTab. 336*7c478bd9Sstevel@tonic-gate ** 337*7c478bd9Sstevel@tonic-gate ** These entries need to be removed in long-running processes, 338*7c478bd9Sstevel@tonic-gate ** e.g., persistent queue runners, to avoid consuming memory. 339*7c478bd9Sstevel@tonic-gate ** 340*7c478bd9Sstevel@tonic-gate ** XXX It might be useful to restrict the maximum TTL to avoid 341*7c478bd9Sstevel@tonic-gate ** caching data very long. 342*7c478bd9Sstevel@tonic-gate ** 343*7c478bd9Sstevel@tonic-gate ** Parameters: 344*7c478bd9Sstevel@tonic-gate ** none. 345*7c478bd9Sstevel@tonic-gate ** 346*7c478bd9Sstevel@tonic-gate ** Returns: 347*7c478bd9Sstevel@tonic-gate ** none. 348*7c478bd9Sstevel@tonic-gate ** 349*7c478bd9Sstevel@tonic-gate ** Side Effects: 350*7c478bd9Sstevel@tonic-gate ** can remove entries from the symbol table. 351*7c478bd9Sstevel@tonic-gate */ 352*7c478bd9Sstevel@tonic-gate 353*7c478bd9Sstevel@tonic-gate #define SM_STAB_FREE(x) \ 354*7c478bd9Sstevel@tonic-gate do \ 355*7c478bd9Sstevel@tonic-gate { \ 356*7c478bd9Sstevel@tonic-gate char *o = (x); \ 357*7c478bd9Sstevel@tonic-gate (x) = NULL; \ 358*7c478bd9Sstevel@tonic-gate if (o != NULL) \ 359*7c478bd9Sstevel@tonic-gate sm_free(o); \ 360*7c478bd9Sstevel@tonic-gate } while (0) 361*7c478bd9Sstevel@tonic-gate 362*7c478bd9Sstevel@tonic-gate void 363*7c478bd9Sstevel@tonic-gate rmexpstab() 364*7c478bd9Sstevel@tonic-gate { 365*7c478bd9Sstevel@tonic-gate int i; 366*7c478bd9Sstevel@tonic-gate STAB *s, *p, *f; 367*7c478bd9Sstevel@tonic-gate time_t now; 368*7c478bd9Sstevel@tonic-gate 369*7c478bd9Sstevel@tonic-gate now = curtime(); 370*7c478bd9Sstevel@tonic-gate for (i = 0; i < STABSIZE; i++) 371*7c478bd9Sstevel@tonic-gate { 372*7c478bd9Sstevel@tonic-gate p = NULL; 373*7c478bd9Sstevel@tonic-gate s = SymTab[i]; 374*7c478bd9Sstevel@tonic-gate while (s != NULL) 375*7c478bd9Sstevel@tonic-gate { 376*7c478bd9Sstevel@tonic-gate switch (s->s_symtype) 377*7c478bd9Sstevel@tonic-gate { 378*7c478bd9Sstevel@tonic-gate case ST_HOSTSIG: 379*7c478bd9Sstevel@tonic-gate if (s->s_hostsig.hs_exp >= now) 380*7c478bd9Sstevel@tonic-gate goto next; /* not expired */ 381*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_hostsig.hs_sig); /* XXX */ 382*7c478bd9Sstevel@tonic-gate break; 383*7c478bd9Sstevel@tonic-gate 384*7c478bd9Sstevel@tonic-gate case ST_NAMECANON: 385*7c478bd9Sstevel@tonic-gate if (s->s_namecanon.nc_exp >= now) 386*7c478bd9Sstevel@tonic-gate goto next; /* not expired */ 387*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_namecanon.nc_cname); /* XXX */ 388*7c478bd9Sstevel@tonic-gate break; 389*7c478bd9Sstevel@tonic-gate 390*7c478bd9Sstevel@tonic-gate default: 391*7c478bd9Sstevel@tonic-gate if (s->s_symtype >= ST_MCI) 392*7c478bd9Sstevel@tonic-gate { 393*7c478bd9Sstevel@tonic-gate /* call mci_uncache? */ 394*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_mci.mci_status); 395*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_mci.mci_rstatus); 396*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_mci.mci_heloname); 397*7c478bd9Sstevel@tonic-gate #if 0 398*7c478bd9Sstevel@tonic-gate /* not dynamically allocated */ 399*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_mci.mci_host); 400*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_mci.mci_tolist); 401*7c478bd9Sstevel@tonic-gate #endif /* 0 */ 402*7c478bd9Sstevel@tonic-gate #if SASL 403*7c478bd9Sstevel@tonic-gate /* should always by NULL */ 404*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_mci.mci_sasl_string); 405*7c478bd9Sstevel@tonic-gate #endif /* SASL */ 406*7c478bd9Sstevel@tonic-gate if (s->s_mci.mci_rpool != NULL) 407*7c478bd9Sstevel@tonic-gate { 408*7c478bd9Sstevel@tonic-gate sm_rpool_free(s->s_mci.mci_rpool); 409*7c478bd9Sstevel@tonic-gate s->s_mci.mci_macro.mac_rpool = NULL; 410*7c478bd9Sstevel@tonic-gate s->s_mci.mci_rpool = NULL; 411*7c478bd9Sstevel@tonic-gate } 412*7c478bd9Sstevel@tonic-gate break; 413*7c478bd9Sstevel@tonic-gate } 414*7c478bd9Sstevel@tonic-gate next: 415*7c478bd9Sstevel@tonic-gate p = s; 416*7c478bd9Sstevel@tonic-gate s = s->s_next; 417*7c478bd9Sstevel@tonic-gate continue; 418*7c478bd9Sstevel@tonic-gate } 419*7c478bd9Sstevel@tonic-gate 420*7c478bd9Sstevel@tonic-gate /* remove entry */ 421*7c478bd9Sstevel@tonic-gate SM_STAB_FREE(s->s_name); /* XXX */ 422*7c478bd9Sstevel@tonic-gate f = s; 423*7c478bd9Sstevel@tonic-gate s = s->s_next; 424*7c478bd9Sstevel@tonic-gate sm_free(f); /* XXX */ 425*7c478bd9Sstevel@tonic-gate if (p == NULL) 426*7c478bd9Sstevel@tonic-gate SymTab[i] = s; 427*7c478bd9Sstevel@tonic-gate else 428*7c478bd9Sstevel@tonic-gate p->s_next = s; 429*7c478bd9Sstevel@tonic-gate } 430*7c478bd9Sstevel@tonic-gate } 431*7c478bd9Sstevel@tonic-gate } 432*7c478bd9Sstevel@tonic-gate 433*7c478bd9Sstevel@tonic-gate #if SM_HEAP_CHECK 434*7c478bd9Sstevel@tonic-gate /* 435*7c478bd9Sstevel@tonic-gate ** DUMPSTAB -- dump symbol table. 436*7c478bd9Sstevel@tonic-gate ** 437*7c478bd9Sstevel@tonic-gate ** For debugging. 438*7c478bd9Sstevel@tonic-gate */ 439*7c478bd9Sstevel@tonic-gate 440*7c478bd9Sstevel@tonic-gate #define MAXSTTYPES (ST_MCI + 1) 441*7c478bd9Sstevel@tonic-gate 442*7c478bd9Sstevel@tonic-gate void 443*7c478bd9Sstevel@tonic-gate dumpstab() 444*7c478bd9Sstevel@tonic-gate { 445*7c478bd9Sstevel@tonic-gate int i, t, total, types[MAXSTTYPES]; 446*7c478bd9Sstevel@tonic-gate STAB *s; 447*7c478bd9Sstevel@tonic-gate static int prevt[MAXSTTYPES], prev = 0; 448*7c478bd9Sstevel@tonic-gate 449*7c478bd9Sstevel@tonic-gate total = 0; 450*7c478bd9Sstevel@tonic-gate for (i = 0; i < MAXSTTYPES; i++) 451*7c478bd9Sstevel@tonic-gate types[i] = 0; 452*7c478bd9Sstevel@tonic-gate for (i = 0; i < STABSIZE; i++) 453*7c478bd9Sstevel@tonic-gate { 454*7c478bd9Sstevel@tonic-gate s = SymTab[i]; 455*7c478bd9Sstevel@tonic-gate while (s != NULL) 456*7c478bd9Sstevel@tonic-gate { 457*7c478bd9Sstevel@tonic-gate ++total; 458*7c478bd9Sstevel@tonic-gate t = s->s_symtype; 459*7c478bd9Sstevel@tonic-gate if (t > MAXSTTYPES - 1) 460*7c478bd9Sstevel@tonic-gate t = MAXSTTYPES - 1; 461*7c478bd9Sstevel@tonic-gate types[t]++; 462*7c478bd9Sstevel@tonic-gate s = s->s_next; 463*7c478bd9Sstevel@tonic-gate } 464*7c478bd9Sstevel@tonic-gate } 465*7c478bd9Sstevel@tonic-gate sm_syslog(LOG_INFO, NOQID, "stab: total=%d (%d)", total, total - prev); 466*7c478bd9Sstevel@tonic-gate prev = total; 467*7c478bd9Sstevel@tonic-gate for (i = 0; i < MAXSTTYPES; i++) 468*7c478bd9Sstevel@tonic-gate { 469*7c478bd9Sstevel@tonic-gate if (types[i] != 0) 470*7c478bd9Sstevel@tonic-gate { 471*7c478bd9Sstevel@tonic-gate sm_syslog(LOG_INFO, NOQID, "stab: type[%2d]=%2d (%d)", 472*7c478bd9Sstevel@tonic-gate i, types[i], types[i] - prevt[i]); 473*7c478bd9Sstevel@tonic-gate } 474*7c478bd9Sstevel@tonic-gate prevt[i] = types[i]; 475*7c478bd9Sstevel@tonic-gate } 476*7c478bd9Sstevel@tonic-gate } 477*7c478bd9Sstevel@tonic-gate #endif /* SM_HEAP_CHECK */ 478