2 * Copyright (c) 1998-2004 Sendmail, Inc. and its suppliers.
4 * Copyright (c) 1983, 1995-1997 Eric P. Allman. All rights reserved.
5 * Copyright (c) 1988, 1993
6 * The Regents of the University of California. All rights reserved.
8 * By using this file, you agree to the terms and conditions set
9 * forth in the LICENSE file which can be found at the top level of
10 * the sendmail distribution.
16 SM_RCSID("@(#)$Id: util.c,v 8.382 2004/03/26 19:01:10 ca Exp $")
22 ** NEWSTR -- Create a copy of a C string
25 ** s -- the string to copy.
28 ** pointer to newly allocated string.
41 sm_strlcpy(n, s, l + 1);
46 ** ADDQUOTES -- Adds quotes & quote bits to a string.
48 ** Runs through a string and adds backslashes and quote bits.
51 ** s -- the string to modify.
52 ** rpool -- resource pool from which to allocate result
55 ** pointer to quoted string.
70 /* Find length of quoted string */
71 while ((c = *p++) != '\0')
74 if (c == '\\' || c == '"')
78 q = r = sm_rpool_malloc_x(rpool, len + 3);
81 /* add leading quote */
83 while ((c = *p++) != '\0')
86 if (c == '\\' || c == '"')
96 ** STRIPBACKSLASH -- Strip leading backslash from a string.
98 ** This is done in place.
101 ** s -- the string to strip.
113 if (s == NULL || *s == '\0')
116 while (*p == '\\' && (p[1] == '\\' || (isascii(p[1]) && isalnum(p[1]))))
125 ** RFC822_STRING -- Checks string for proper RFC822 string quoting.
127 ** Runs through a string and verifies RFC822 special characters
128 ** are only found inside comments, quoted strings, or backslash
129 ** escaped. Also verified balanced quotes and parenthesis.
132 ** s -- the string to modify.
135 ** true iff the string is RFC822 compliant, false otherwise.
151 /* escaped character */
158 else if (commentlev == 0 && *c == '"')
172 else if (commentlev == 0 &&
173 strchr(MustQuoteChars, *c) != NULL)
179 /* unbalanced '"' or '(' */
180 return !quoted && commentlev == 0;
183 ** SHORTEN_RFC822_STRING -- Truncate and rebalance an RFC822 string
185 ** Arbitrarily shorten (in place) an RFC822 string and rebalance
186 ** comments and quotes.
189 ** string -- the string to shorten
190 ** length -- the maximum size, 0 if no maximum
193 ** true if string is changed, false otherwise
196 ** Changes string in place, possibly resulting
197 ** in a shorter string.
201 shorten_rfc822_string(string, length)
205 bool backslash = false;
206 bool modified = false;
213 ** If have to rebalance an already short enough string,
214 ** need to do it within allocated space.
217 slen = strlen(string);
218 if (length == 0 || slen < length)
231 else if (*ptr == '(')
236 else if (*ptr == ')')
238 if (--parencount < 0)
242 /* Inside a comment, quotes don't matter */
243 if (parencount <= 0 && *ptr == '"')
247 /* Check for sufficient space for next character */
248 if (length - (ptr - string) <= (size_t) ((backslash ? 1 : 0) +
252 /* Not enough, backtrack */
255 else if (*ptr == '(' && !quoted)
257 else if (*ptr == '"' && parencount == 0)
265 while (parencount-- > 0)
291 ** FIND_CHARACTER -- find an unquoted character in an RFC822 string
293 ** Find an unquoted, non-commented character in an RFC822
294 ** string and return a pointer to its location in the
298 ** string -- the string to search
299 ** character -- the character to find
302 ** pointer to the character, or
303 ** a pointer to the end of the line if character is not found
307 find_character(string, character)
311 bool backslash = false;
315 while (string != NULL && *string != '\0')
320 if (!quoted && character == '\\' && *string == '\\')
337 if (--parencount < 0)
342 /* Inside a comment, nothing matters */
351 else if (*string == character && !quoted)
356 /* Return pointer to the character */
361 ** CHECK_BODYTYPE -- check bodytype parameter
364 ** bodytype -- bodytype parameter
367 ** BODYTYPE_* according to parameter
372 check_bodytype(bodytype)
375 /* check body type for legality */
376 if (bodytype == NULL)
377 return BODYTYPE_NONE;
378 if (sm_strcasecmp(bodytype, "7BIT") == 0)
379 return BODYTYPE_7BIT;
380 if (sm_strcasecmp(bodytype, "8BITMIME") == 0)
381 return BODYTYPE_8BITMIME;
382 return BODYTYPE_ILLEGAL;
385 #if _FFR_BESTMX_BETTER_TRUNCATION || _FFR_DNSMAP_MULTI
387 ** TRUNCATE_AT_DELIM -- truncate string at a delimiter and append "..."
390 ** str -- string to truncate
391 ** len -- maximum length (including '\0') (0 for unlimited)
392 ** delim -- delimiter character
399 truncate_at_delim(str, len, delim)
406 if (str == NULL || len == 0 || strlen(str) < len)
409 *(str + len - 1) = '\0';
410 while ((p = strrchr(str, delim)) != NULL)
413 if (p - str + 4 < len)
417 (void) sm_strlcat(str, "...", len);
422 /* Couldn't find a place to append "..." */
424 (void) sm_strlcpy(str, "...", len);
428 #endif /* _FFR_BESTMX_BETTER_TRUNCATION || _FFR_DNSMAP_MULTI */
430 ** XALLOC -- Allocate memory, raise an exception on error
433 ** sz -- size of area to allocate.
436 ** pointer to data region.
439 ** SmHeapOutOfMemory (F:sm.heap) -- cannot allocate memory
442 ** Memory is allocated.
447 xalloc_tagged(sz, file, line)
451 #else /* SM_HEAP_CHECK */
454 #endif /* SM_HEAP_CHECK */
458 /* some systems can't handle size zero mallocs */
462 /* scaffolding for testing error handling code */
463 sm_xtrap_raise_x(&SmHeapOutOfMemory);
465 p = sm_malloc_tagged((unsigned) sz, file, line, sm_heap_group());
468 sm_exc_raise_x(&SmHeapOutOfMemory);
473 ** COPYPLIST -- copy list of pointers.
475 ** This routine is the equivalent of strdup for lists of
479 ** list -- list of pointers to copy.
480 ** Must be NULL terminated.
481 ** copycont -- if true, copy the contents of the vector
482 ** (which must be a string) also.
483 ** rpool -- resource pool from which to allocate storage,
491 copyplist(list, copycont, rpool)
497 register char **newvp;
499 for (vp = list; *vp != NULL; vp++)
504 newvp = (char **) sm_rpool_malloc_x(rpool, (vp - list) * sizeof *vp);
505 memmove((char *) newvp, (char *) list, (int) (vp - list) * sizeof *vp);
509 for (vp = newvp; *vp != NULL; vp++)
510 *vp = sm_rpool_strdup_x(rpool, *vp);
516 ** COPYQUEUE -- copy address queue.
518 ** This routine is the equivalent of strdup for address queues;
519 ** addresses marked as QS_IS_DEAD() aren't copied
522 ** addr -- list of address structures to copy.
523 ** rpool -- resource pool from which to allocate storage
530 copyqueue(addr, rpool)
534 register ADDRESS *newaddr;
536 register ADDRESS **tail = &ret;
540 if (!QS_IS_DEAD(addr->q_state))
542 newaddr = (ADDRESS *) sm_rpool_malloc_x(rpool,
544 STRUCTCOPY(*addr, *newaddr);
546 tail = &newaddr->q_next;
555 ** LOG_SENDMAIL_PID -- record sendmail pid and command line.
558 ** e -- the current envelope.
564 ** writes pidfile, logs command line.
565 ** keeps file open and locked to prevent overwrite of active file
568 static SM_FILE_T *Pidf = NULL;
575 char pidpath[MAXPATHLEN];
576 extern char *CommandLineArgs;
578 /* write the pid to the log file for posterity */
579 sff = SFF_NOLINK|SFF_ROOTOK|SFF_REGONLY|SFF_CREAT|SFF_NBLOCK;
580 if (TrustedUid != 0 && RealUid == TrustedUid)
581 sff |= SFF_OPENASROOT;
582 expand(PidFile, pidpath, sizeof pidpath, e);
583 Pidf = safefopen(pidpath, O_WRONLY|O_TRUNC, FileMode, sff);
586 if (errno == EWOULDBLOCK)
587 sm_syslog(LOG_ERR, NOQID,
588 "unable to write pid to %s: file in use by another process",
591 sm_syslog(LOG_ERR, NOQID,
592 "unable to write pid to %s: %s",
593 pidpath, sm_errstring(errno));
597 PidFilePid = getpid();
599 /* write the process id on line 1 */
600 (void) sm_io_fprintf(Pidf, SM_TIME_DEFAULT, "%ld\n",
603 /* line 2 contains all command line flags */
604 (void) sm_io_fprintf(Pidf, SM_TIME_DEFAULT, "%s\n",
608 (void) sm_io_flush(Pidf, SM_TIME_DEFAULT);
611 ** Leave pid file open until process ends
612 ** so it's not overwritten by another
617 sm_syslog(LOG_INFO, NOQID, "started as: %s", CommandLineArgs);
621 ** CLOSE_SENDMAIL_PID -- close sendmail pid file
636 (void) sm_io_close(Pidf, SM_TIME_DEFAULT);
641 ** SET_DELIVERY_MODE -- set and record the delivery mode
644 ** mode -- delivery mode
645 ** e -- the current envelope.
651 ** sets {deliveryMode} macro
655 set_delivery_mode(mode, e)
661 e->e_sendmode = (char) mode;
662 buf[0] = (char) mode;
664 macdefine(&e->e_macro, A_TEMP, macid("{deliveryMode}"), buf);
667 ** SET_OP_MODE -- set and record the op mode
671 ** e -- the current envelope.
677 ** sets {opMode} macro
685 extern ENVELOPE BlankEnvelope;
687 OpMode = (char) mode;
688 buf[0] = (char) mode;
690 macdefine(&BlankEnvelope.e_macro, A_TEMP, MID_OPMODE, buf);
693 ** PRINTAV -- print argument vector.
696 ** fp -- output file pointer.
697 ** av -- argument vector.
714 sm_dprintf("\n\t%08lx=", (unsigned long) *av);
716 (void) sm_io_putc(fp, SM_TIME_DEFAULT, ' ');
719 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '\n');
722 ** XPUTS -- put string doing control escapes.
725 ** fp -- output file pointer.
726 ** s -- string to put.
738 register const char *s;
741 register struct metamac *mp;
742 bool shiftout = false;
743 extern struct metamac MetaMacros[];
744 static SM_DEBUG_T DebugANSI = SM_DEBUG_INITIALIZER("ANSI",
745 "@(#)$Debug: ANSI - enable reverse video in debug output $");
748 ** TermEscape is set here, rather than in main(),
749 ** because ANSI mode can be turned on or off at any time
750 ** if we are in -bt rule testing mode.
753 if (sm_debug_unknown(&DebugANSI))
755 if (sm_debug_active(&DebugANSI, 1))
757 TermEscape.te_rv_on = "\033[7m";
758 TermEscape.te_rv_off = "\033[0m";
762 TermEscape.te_rv_on = "";
763 TermEscape.te_rv_off = "";
769 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s<null>%s",
770 TermEscape.te_rv_on, TermEscape.te_rv_off);
773 while ((c = (*s++ & 0377)) != '\0')
777 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
778 TermEscape.te_rv_off);
785 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
787 TermEscape.te_rv_on);
794 if (c == MACROEXPAND || c == MACRODEXPAND)
796 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
798 TermEscape.te_rv_on);
799 if (c == MACRODEXPAND)
800 (void) sm_io_putc(fp,
801 SM_TIME_DEFAULT, '&');
805 if (strchr("=~&?", *s) != NULL)
806 (void) sm_io_putc(fp,
809 if (bitset(0200, *s))
810 (void) sm_io_fprintf(fp,
813 macname(bitidx(*s++)));
815 (void) sm_io_fprintf(fp,
821 for (mp = MetaMacros; mp->metaname != '\0'; mp++)
823 if (bitidx(mp->metaval) == c)
825 (void) sm_io_fprintf(fp,
834 if (c == MATCHCLASS || c == MATCHNCLASS)
836 if (bitset(0200, *s))
837 (void) sm_io_fprintf(fp,
840 macname(bitidx(*s++)));
842 (void) sm_io_fprintf(fp,
847 if (mp->metaname != '\0')
850 /* unrecognized meta character */
851 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%sM-",
852 TermEscape.te_rv_on);
859 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c);
863 /* wasn't a meta-macro -- find another way to print it */
880 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
881 TermEscape.te_rv_on);
886 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '\\');
887 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c);
891 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '^');
892 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c ^ 0100);
896 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
897 TermEscape.te_rv_off);
898 (void) sm_io_flush(fp, SM_TIME_DEFAULT);
901 ** MAKELOWER -- Translate a line into lower case
904 ** p -- the string to translate. If NULL, return is
911 ** String pointed to by p is translated to lower case.
922 for (; (c = *p) != '\0'; p++)
923 if (isascii(c) && isupper(c))
927 ** FIXCRLF -- fix <CR><LF> in line.
929 ** Looks for the <CR><LF> combination and turns it into the
930 ** UNIX canonical <NL> character. It only takes one line,
931 ** i.e., it is assumed that the first <NL> found is the end
935 ** line -- the line to fix.
936 ** stripnl -- if true, strip the newline also.
942 ** line is changed in place.
946 fixcrlf(line, stripnl)
952 p = strchr(line, '\n');
955 if (p > line && p[-1] == '\r')
962 ** PUTLINE -- put a line like fputs obeying SMTP conventions
964 ** This routine always guarantees outputing a newline (or CRLF,
965 ** as appropriate) at the end of the string.
969 ** mci -- the mailer connection information.
975 ** output of l to mci->mci_out.
983 putxline(l, strlen(l), mci, PXLF_MAPFROM);
986 ** PUTXLINE -- putline with flags bits.
988 ** This routine always guarantees outputing a newline (or CRLF,
989 ** as appropriate) at the end of the string.
993 ** len -- the length of the line.
994 ** mci -- the mailer connection information.
995 ** pxflags -- flag bits:
996 ** PXLF_MAPFROM -- map From_ to >From_.
997 ** PXLF_STRIP8BIT -- strip 8th bit.
998 ** PXLF_HEADER -- map bare newline in header to newline space.
999 ** PXLF_NOADDEOL -- don't add an EOL if one wasn't present.
1005 ** output of l to mci->mci_out.
1009 putxline(l, len, mci, pxflags)
1016 register char *p, *end;
1019 /* strip out 0200 bits -- these can look like TELNET protocol */
1020 if (bitset(MCIF_7BIT, mci->mci_flags) ||
1021 bitset(PXLF_STRIP8BIT, pxflags))
1023 register char svchar;
1025 for (p = l; (svchar = *p) != '\0'; ++p)
1026 if (bitset(0200, svchar))
1027 *p = svchar &~ 0200;
1035 /* find the end of the line */
1036 p = memchr(l, '\n', end - l);
1043 if (TrafficLogFile != NULL)
1044 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1045 "%05d >>> ", (int) CurrentPid);
1047 /* check for line overflow */
1048 while (mci->mci_mailer->m_linelimit > 0 &&
1049 (p - l + slop) > mci->mci_mailer->m_linelimit)
1052 register char *q = &l[mci->mci_mailer->m_linelimit - slop - 1];
1054 if (l[0] == '.' && slop == 0 &&
1055 bitnset(M_XDOT, mci->mci_mailer->m_flags))
1057 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1062 /* record progress for DATA timeout */
1063 DataProgress = true;
1065 if (TrafficLogFile != NULL)
1066 (void) sm_io_putc(TrafficLogFile,
1067 SM_TIME_DEFAULT, '.');
1069 else if (l[0] == 'F' && slop == 0 &&
1070 bitset(PXLF_MAPFROM, pxflags) &&
1071 strncmp(l, "From ", 5) == 0 &&
1072 bitnset(M_ESCFROM, mci->mci_mailer->m_flags))
1074 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1079 /* record progress for DATA timeout */
1080 DataProgress = true;
1082 if (TrafficLogFile != NULL)
1083 (void) sm_io_putc(TrafficLogFile,
1092 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1093 (unsigned char) *l++) == SM_IO_EOF)
1100 /* record progress for DATA timeout */
1101 DataProgress = true;
1107 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '!') ==
1109 sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
1110 mci->mci_mailer->m_eol) ==
1112 sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, ' ') ==
1120 /* record progress for DATA timeout */
1121 DataProgress = true;
1123 if (TrafficLogFile != NULL)
1125 for (l = l_base; l < q; l++)
1126 (void) sm_io_putc(TrafficLogFile,
1129 (void) sm_io_fprintf(TrafficLogFile,
1140 /* output last part */
1141 if (l[0] == '.' && slop == 0 &&
1142 bitnset(M_XDOT, mci->mci_mailer->m_flags))
1144 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '.') ==
1149 /* record progress for DATA timeout */
1150 DataProgress = true;
1152 if (TrafficLogFile != NULL)
1153 (void) sm_io_putc(TrafficLogFile,
1154 SM_TIME_DEFAULT, '.');
1156 else if (l[0] == 'F' && slop == 0 &&
1157 bitset(PXLF_MAPFROM, pxflags) &&
1158 strncmp(l, "From ", 5) == 0 &&
1159 bitnset(M_ESCFROM, mci->mci_mailer->m_flags))
1161 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '>') ==
1166 /* record progress for DATA timeout */
1167 DataProgress = true;
1169 if (TrafficLogFile != NULL)
1170 (void) sm_io_putc(TrafficLogFile,
1171 SM_TIME_DEFAULT, '>');
1175 if (TrafficLogFile != NULL)
1176 (void) sm_io_putc(TrafficLogFile,
1179 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1180 (unsigned char) *l) == SM_IO_EOF)
1187 /* record progress for DATA timeout */
1188 DataProgress = true;
1194 if (TrafficLogFile != NULL)
1195 (void) sm_io_putc(TrafficLogFile, SM_TIME_DEFAULT,
1197 if ((!bitset(PXLF_NOADDEOL, pxflags) || !noeol) &&
1198 sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
1199 mci->mci_mailer->m_eol) == SM_IO_EOF)
1203 /* record progress for DATA timeout */
1204 DataProgress = true;
1206 if (l < end && *l == '\n')
1208 if (*++l != ' ' && *l != '\t' && *l != '\0' &&
1209 bitset(PXLF_HEADER, pxflags))
1211 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1216 /* record progress for DATA timeout */
1217 DataProgress = true;
1220 if (TrafficLogFile != NULL)
1221 (void) sm_io_putc(TrafficLogFile,
1222 SM_TIME_DEFAULT, ' ');
1226 /* record progress for DATA timeout */
1227 DataProgress = true;
1231 ** XUNLINK -- unlink a file, doing logging as appropriate.
1234 ** f -- name of file to unlink.
1237 ** return value of unlink()
1251 sm_syslog(LOG_DEBUG, CurEnv->e_id, "unlink %s", f);
1255 if (i < 0 && LogLevel > 97)
1256 sm_syslog(LOG_DEBUG, CurEnv->e_id, "%s: unlink-fail %d",
1264 ** SFGETS -- "safe" fgets -- times out and ignores random interrupts.
1267 ** buf -- place to put the input line.
1268 ** siz -- size of buf.
1269 ** fp -- file to read from.
1270 ** timeout -- the timeout before error occurs.
1271 ** during -- what we are trying to read (for error messages).
1274 ** NULL on error (including timeout). This may also leave
1275 ** buf containing a null string.
1281 sfgets(buf, siz, fp, timeout, during)
1292 SM_REQUIRE(siz > 0);
1293 SM_REQUIRE(buf != NULL);
1306 /* convert the timeout to sm_io notation */
1307 io_timeout = (timeout <= 0) ? SM_TIME_DEFAULT : timeout * 1000;
1308 while (!sm_io_eof(fp) && !sm_io_error(fp))
1311 p = sm_io_fgets(fp, io_timeout, buf, siz);
1312 if (p == NULL && errno == EAGAIN)
1314 /* The sm_io_fgets() call timedout */
1316 sm_syslog(LOG_NOTICE, CurEnv->e_id,
1317 "timeout waiting for input from %.100s during %s",
1324 if (TrafficLogFile != NULL)
1325 (void) sm_io_fprintf(TrafficLogFile,
1327 "%05d <<< [TIMEOUT]\n",
1332 if (p != NULL || errno != EINTR)
1334 (void) sm_io_clearerr(fp);
1338 /* clean up the books and exit */
1343 if (TrafficLogFile != NULL)
1344 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1350 if (TrafficLogFile != NULL)
1351 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1352 "%05d <<< %s", (int) CurrentPid, buf);
1355 for (p = buf; *p != '\0'; p++)
1358 else if (!HasEightBits)
1360 for (p = buf; *p != '\0'; p++)
1362 if (bitset(0200, *p))
1364 HasEightBits = true;
1372 ** FGETFOLDED -- like fgets, but knows about folded lines.
1375 ** buf -- place to put result.
1376 ** n -- bytes available.
1377 ** f -- file to read from.
1380 ** input line(s) on success, NULL on error or SM_IO_EOF.
1381 ** This will normally be buf -- unless the line is too
1382 ** long, when it will be sm_malloc_x()ed.
1385 ** buf gets lines from f, with continuation lines (lines
1386 ** with leading white space) appended. CRLF's are mapped
1387 ** into single newlines. Any trailing NL is stripped.
1391 fgetfolded(buf, n, f)
1396 register char *p = buf;
1401 SM_REQUIRE(buf != NULL);
1410 while ((i = sm_io_getc(f, SM_TIME_DEFAULT)) != SM_IO_EOF)
1414 i = sm_io_getc(f, SM_TIME_DEFAULT);
1418 (void) sm_io_ungetc(f, SM_TIME_DEFAULT,
1425 /* allocate new space */
1430 if (nn < MEMCHUNKSIZE)
1434 nbp = sm_malloc_x(nn);
1435 memmove(nbp, bp, p - bp);
1446 i = sm_io_getc(f, SM_TIME_DEFAULT);
1448 (void) sm_io_ungetc(f, SM_TIME_DEFAULT, i);
1449 if (i != ' ' && i != '\t')
1461 ** CURTIME -- return current time.
1467 ** the current time.
1479 ** ATOBOOL -- convert a string representation to boolean.
1481 ** Defaults to false
1484 ** s -- string to convert. Takes "tTyY", empty, and NULL as true,
1488 ** A boolean representation of the string.
1495 if (s == NULL || *s == '\0' || strchr("tTyY", *s) != NULL)
1500 ** ATOOCT -- convert a string representation to octal.
1503 ** s -- string to convert.
1506 ** An integer representing the string interpreted as an
1516 while (*s >= '0' && *s <= '7')
1517 i = (i << 3) | (*s++ - '0');
1521 ** BITINTERSECT -- tell if two bitmaps intersect
1524 ** a, b -- the bitmaps in question
1527 ** true if they have a non-null intersection
1538 for (i = BITMAPBYTES / sizeof (int); --i >= 0; )
1540 if ((a[i] & b[i]) != 0)
1546 ** BITZEROP -- tell if a bitmap is all zero
1549 ** map -- the bit map to check
1552 ** true if map is all zero.
1553 ** false if there are any bits set in map.
1562 for (i = BITMAPBYTES / sizeof (int); --i >= 0; )
1570 ** STRCONTAINEDIN -- tell if one string is contained in another
1573 ** icase -- ignore case?
1574 ** a -- possible substring.
1575 ** b -- possible superstring.
1578 ** true if a is contained in b (case insensitive).
1583 strcontainedin(icase, a, b)
1595 if (icase && isascii(c) && isupper(c))
1597 for (; lb-- >= la; b++)
1602 isascii(*b) && isupper(*b) && tolower(*b) != c)
1604 if (sm_strncasecmp(a, b, la) == 0)
1611 if (strncmp(a, b, la) == 0)
1618 ** CHECKFD012 -- check low numbered file descriptors
1620 ** File descriptors 0, 1, and 2 should be open at all times.
1621 ** This routine verifies that, and fixes it if not true.
1624 ** where -- a tag printed if the assertion failed
1637 for (i = 0; i < 3; i++)
1642 ** CHECKFDOPEN -- make sure file descriptor is open -- for extended debugging
1645 ** fd -- file descriptor to check.
1646 ** where -- tag to print on failure.
1653 checkfdopen(fd, where)
1660 if (fstat(fd, &st) < 0 && errno == EBADF)
1662 syserr("checkfdopen(%d): %s not open as expected!", fd, where);
1668 ** CHECKFDS -- check for new or missing file descriptors
1671 ** where -- tag for printing. If null, take a base line.
1677 ** If where is set, shows changes since the last call.
1686 bool printhdr = true;
1687 int save_errno = errno;
1688 static BITMAP256 baseline;
1689 extern int DtableSize;
1691 if (DtableSize > BITMAPBITS)
1696 clrbitmap(baseline);
1698 for (fd = 0; fd < maxfd; fd++)
1702 if (fstat(fd, &stbuf) < 0 && errno != EOPNOTSUPP)
1704 if (!bitnset(fd, baseline))
1706 clrbitn(fd, baseline);
1708 else if (!bitnset(fd, baseline))
1709 setbitn(fd, baseline);
1713 /* file state has changed */
1718 sm_syslog(LOG_DEBUG, CurEnv->e_id,
1723 dumpfd(fd, true, true);
1728 ** PRINTOPENFDS -- print the open file descriptors (for debugging)
1731 ** logit -- if set, send output to syslog; otherwise
1732 ** print for debugging.
1738 #if NETINET || NETINET6
1739 # include <arpa/inet.h>
1740 #endif /* NETINET || NETINET6 */
1747 extern int DtableSize;
1749 for (fd = 0; fd < DtableSize; fd++)
1750 dumpfd(fd, false, logit);
1753 ** DUMPFD -- dump a file descriptor
1756 ** fd -- the file descriptor to dump.
1757 ** printclosed -- if set, print a notification even if
1758 ** it is closed; otherwise print nothing.
1759 ** logit -- if set, use sm_syslog instead of sm_dprintf()
1766 dumpfd(fd, printclosed, logit)
1775 #endif /* S_IFSOCK */
1776 auto SOCKADDR_LEN_T slen;
1780 #else /* STAT64 > 0 */
1782 #endif /* STAT64 > 0 */
1786 (void) sm_snprintf(p, SPACELEFT(buf, p), "%3d: ", fd);
1792 #else /* STAT64 > 0 */
1794 #endif /* STAT64 > 0 */
1799 (void) sm_snprintf(p, SPACELEFT(buf, p),
1801 sm_errstring(errno));
1804 else if (printclosed)
1806 (void) sm_snprintf(p, SPACELEFT(buf, p), "CLOSED");
1812 i = fcntl(fd, F_GETFL, 0);
1815 (void) sm_snprintf(p, SPACELEFT(buf, p), "fl=0x%x, ", i);
1819 (void) sm_snprintf(p, SPACELEFT(buf, p), "mode=%o: ",
1822 switch (st.st_mode & S_IFMT)
1826 (void) sm_snprintf(p, SPACELEFT(buf, p), "SOCK ");
1828 memset(&sa, '\0', sizeof sa);
1830 if (getsockname(fd, &sa.sa, &slen) < 0)
1831 (void) sm_snprintf(p, SPACELEFT(buf, p), "(%s)",
1832 sm_errstring(errno));
1835 hp = hostnamebyanyaddr(&sa);
1842 else if (sa.sa.sa_family == AF_INET)
1843 (void) sm_snprintf(p, SPACELEFT(buf, p),
1844 "%s/%d", hp, ntohs(sa.sin.sin_port));
1845 # endif /* NETINET */
1847 else if (sa.sa.sa_family == AF_INET6)
1848 (void) sm_snprintf(p, SPACELEFT(buf, p),
1849 "%s/%d", hp, ntohs(sa.sin6.sin6_port));
1850 # endif /* NETINET6 */
1852 (void) sm_snprintf(p, SPACELEFT(buf, p),
1856 (void) sm_snprintf(p, SPACELEFT(buf, p), "->");
1859 if (getpeername(fd, &sa.sa, &slen) < 0)
1860 (void) sm_snprintf(p, SPACELEFT(buf, p), "(%s)",
1861 sm_errstring(errno));
1864 hp = hostnamebyanyaddr(&sa);
1871 else if (sa.sa.sa_family == AF_INET)
1872 (void) sm_snprintf(p, SPACELEFT(buf, p),
1873 "%s/%d", hp, ntohs(sa.sin.sin_port));
1874 # endif /* NETINET */
1876 else if (sa.sa.sa_family == AF_INET6)
1877 (void) sm_snprintf(p, SPACELEFT(buf, p),
1878 "%s/%d", hp, ntohs(sa.sin6.sin6_port));
1879 # endif /* NETINET6 */
1881 (void) sm_snprintf(p, SPACELEFT(buf, p),
1885 #endif /* S_IFSOCK */
1888 (void) sm_snprintf(p, SPACELEFT(buf, p), "CHR: ");
1894 (void) sm_snprintf(p, SPACELEFT(buf, p), "BLK: ");
1897 #endif /* S_IFBLK */
1899 #if defined(S_IFIFO) && (!defined(S_IFSOCK) || S_IFIFO != S_IFSOCK)
1901 (void) sm_snprintf(p, SPACELEFT(buf, p), "FIFO: ");
1904 #endif /* defined(S_IFIFO) && (!defined(S_IFSOCK) || S_IFIFO != S_IFSOCK) */
1908 (void) sm_snprintf(p, SPACELEFT(buf, p), "DIR: ");
1911 #endif /* S_IFDIR */
1915 (void) sm_snprintf(p, SPACELEFT(buf, p), "LNK: ");
1918 #endif /* S_IFLNK */
1922 (void) sm_snprintf(p, SPACELEFT(buf, p),
1923 "dev=%d/%d, ino=%llu, nlink=%d, u/gid=%d/%d, ",
1924 major(st.st_dev), minor(st.st_dev),
1925 (ULONGLONG_T) st.st_ino,
1926 (int) st.st_nlink, (int) st.st_uid,
1929 (void) sm_snprintf(p, SPACELEFT(buf, p), "size=%llu",
1930 (ULONGLONG_T) st.st_size);
1936 sm_syslog(LOG_DEBUG, CurEnv ? CurEnv->e_id : NULL,
1939 sm_dprintf("%s\n", buf);
1942 ** SHORTEN_HOSTNAME -- strip local domain information off of hostname.
1945 ** host -- the host to shorten (stripped in place).
1948 ** place where string was truncated, NULL if not truncated.
1952 shorten_hostname(host)
1960 /* strip off final dot */
1962 p = &host[(i == 0) ? 0 : i - 1];
1969 /* see if there is any domain at all -- if not, we are done */
1970 p = strchr(host, '.');
1974 /* yes, we have a domain -- see if it looks like us */
1975 mydom = macvalue('m', CurEnv);
1979 if ((canon ? sm_strcasecmp(p, mydom)
1980 : sm_strncasecmp(p, mydom, i)) == 0 &&
1981 (mydom[i] == '.' || mydom[i] == '\0'))
1989 ** PROG_OPEN -- open a program for reading
1992 ** argv -- the argument list.
1993 ** pfd -- pointer to a place to store the file descriptor.
1994 ** e -- the current envelope.
1997 ** pid of the process -- -1 if it failed.
2001 prog_open(argv, pfd, e)
2012 char buf[MAXPATHLEN];
2013 extern int DtableSize;
2017 syserr("%s: cannot create pipe for stdout", argv[0]);
2023 syserr("%s: cannot fork", argv[0]);
2024 (void) close(fdv[0]);
2025 (void) close(fdv[1]);
2031 (void) close(fdv[1]);
2036 /* Reset global flags */
2037 RestartRequest = NULL;
2038 RestartWorkGroup = false;
2039 ShutdownRequest = NULL;
2041 CurrentPid = getpid();
2044 ** Initialize exception stack and default exception
2045 ** handler for child process.
2048 sm_exc_newthread(fatal_error);
2050 /* child -- close stdin */
2053 /* stdout goes back to parent */
2054 (void) close(fdv[0]);
2055 if (dup2(fdv[1], 1) < 0)
2057 syserr("%s: cannot dup2 for stdout", argv[0]);
2060 (void) close(fdv[1]);
2062 /* stderr goes to transcript if available */
2063 if (e->e_xfp != NULL)
2067 xfd = sm_io_getinfo(e->e_xfp, SM_IO_WHAT_FD, NULL);
2068 if (xfd >= 0 && dup2(xfd, 2) < 0)
2070 syserr("%s: cannot dup2 for stderr", argv[0]);
2075 /* this process has no right to the queue file */
2076 if (e->e_lockfp != NULL)
2077 (void) close(sm_io_getinfo(e->e_lockfp, SM_IO_WHAT_FD, NULL));
2079 /* chroot to the program mailer directory, if defined */
2080 if (ProgMailer != NULL && ProgMailer->m_rootdir != NULL)
2082 expand(ProgMailer->m_rootdir, buf, sizeof buf, e);
2083 if (chroot(buf) < 0)
2085 syserr("prog_open: cannot chroot(%s)", buf);
2090 syserr("prog_open: cannot chdir(/)");
2095 /* run as default user */
2097 sm_mbdb_terminate();
2098 if (setgid(DefGid) < 0 && geteuid() == 0)
2100 syserr("prog_open: setgid(%ld) failed", (long) DefGid);
2103 if (setuid(DefUid) < 0 && geteuid() == 0)
2105 syserr("prog_open: setuid(%ld) failed", (long) DefUid);
2109 /* run in some directory */
2110 if (ProgMailer != NULL)
2111 p = ProgMailer->m_execdir;
2114 for (; p != NULL; p = q)
2119 expand(p, buf, sizeof buf, e);
2122 if (buf[0] != '\0' && chdir(buf) >= 0)
2127 /* backup directories */
2128 if (chdir("/tmp") < 0)
2132 /* Check safety of program to be run */
2133 sff = SFF_ROOTOK|SFF_EXECOK;
2134 if (!bitnset(DBS_RUNWRITABLEPROGRAM, DontBlameSendmail))
2135 sff |= SFF_NOGWFILES|SFF_NOWWFILES;
2136 if (bitnset(DBS_RUNPROGRAMINUNSAFEDIRPATH, DontBlameSendmail))
2137 sff |= SFF_NOPATHCHECK;
2139 sff |= SFF_SAFEDIRPATH;
2140 ret = safefile(argv[0], DefUid, DefGid, DefUser, sff, 0, NULL);
2142 sm_syslog(LOG_INFO, e->e_id,
2143 "Warning: prog_open: program %s unsafe: %s",
2144 argv[0], sm_errstring(ret));
2146 /* arrange for all the files to be closed */
2147 sm_close_on_exec(STDERR_FILENO + 1, DtableSize);
2149 /* now exec the process */
2150 (void) execve(argv[0], (ARGV_T) argv, (ARGV_T) UserEnviron);
2154 syserr("%s: cannot exec", argv[0]);
2155 if (transienterror(save_errno))
2158 return -1; /* avoid compiler warning on IRIX */
2161 ** GET_COLUMN -- look up a Column in a line buffer
2164 ** line -- the raw text line to search.
2165 ** col -- the column number to fetch.
2166 ** delim -- the delimiter between columns. If null,
2168 ** buf -- the output buffer.
2169 ** buflen -- the length of buf.
2172 ** buf if successful.
2177 get_column(line, col, delim, buf, buflen)
2189 if ((char) delim == '\0')
2190 (void) sm_strlcpy(delimbuf, "\n\t ", sizeof delimbuf);
2193 delimbuf[0] = (char) delim;
2199 return NULL; /* line empty */
2200 if (*p == (char) delim && col == 0)
2201 return NULL; /* first column empty */
2205 if (col == 0 && (char) delim == '\0')
2207 while (*begin != '\0' && isascii(*begin) && isspace(*begin))
2211 for (i = 0; i < col; i++)
2213 if ((begin = strpbrk(begin, delimbuf)) == NULL)
2214 return NULL; /* no such column */
2216 if ((char) delim == '\0')
2218 while (*begin != '\0' && isascii(*begin) && isspace(*begin))
2223 end = strpbrk(begin, delimbuf);
2230 (void) sm_strlcpy(buf, begin, i + 1);
2234 ** CLEANSTRCPY -- copy string keeping out bogus characters
2237 ** t -- "to" string.
2238 ** f -- "from" string.
2239 ** l -- length of space available in "to" string.
2246 cleanstrcpy(t, f, l)
2251 /* check for newlines and log if necessary */
2252 (void) denlstring(f, true, true);
2255 syserr("!cleanstrcpy: length == 0");
2258 while (l > 0 && *f != '\0')
2261 (isalnum(*f) || strchr("!#$%&'*+-./^_`{|}~", *f) != NULL))
2271 ** DENLSTRING -- convert newlines in a string to spaces
2274 ** s -- the input string
2275 ** strict -- if set, don't permit continuation lines.
2276 ** logattacks -- if set, log attempted attacks.
2279 ** A pointer to a version of the string with newlines
2280 ** mapped to spaces. This should be copied.
2284 denlstring(s, strict, logattacks)
2291 static char *bp = NULL;
2295 while ((p = strchr(p, '\n')) != NULL)
2296 if (strict || (*++p != ' ' && *p != '\t'))
2304 /* allocate more space */
2305 char *nbp = sm_pmalloc_x(l);
2312 (void) sm_strlcpy(bp, s, l);
2313 for (p = bp; (p = strchr(p, '\n')) != NULL; )
2318 sm_syslog(LOG_NOTICE, CurEnv->e_id,
2319 "POSSIBLE ATTACK from %.100s: newline in string \"%s\"",
2320 RealHostName == NULL ? "[UNKNOWN]" : RealHostName,
2321 shortenstring(bp, MAXSHORTSTR));
2328 ** STRREPLNONPRT -- replace "unprintable" characters in a string with subst
2331 ** s -- string to manipulate (in place)
2332 ** subst -- character to use as replacement
2335 ** true iff string did not contain "unprintable" characters
2350 if (!(isascii(*s) && isprint(*s)))
2361 ** STR2PRT -- convert "unprintable" characters in a string to \oct
2364 ** s -- string to convert
2367 ** converted string.
2368 ** This is a static local buffer, string must be copied
2369 ** before this function is called again!
2380 static char *buf = NULL;
2385 for (h = s, l = 1; *h != '\0'; h++, l++)
2392 else if (!(isascii(*h) && isprint(*h)))
2402 char *nbuf = sm_pmalloc_x(l);
2409 for (h = buf; *s != '\0' && l > 0; s++, l--)
2412 if (isascii(c) && isprint(c) && c != '\\')
2435 (void) sm_snprintf(h, l, "%03o",
2436 (unsigned int)((unsigned char) c));
2439 ** XXX since l is unsigned this may
2440 ** wrap around if the calculation is screwed
2451 buf[len - 1] = '\0';
2455 ** PATH_IS_DIR -- check to see if file exists and is a directory.
2457 ** There are some additional checks for security violations in
2458 ** here. This routine is intended to be used for the host status
2462 ** pathname -- pathname to check for directory-ness.
2463 ** createflag -- if set, create directory if needed.
2466 ** true -- if the indicated pathname is a directory
2467 ** false -- otherwise
2471 path_is_dir(pathname, createflag)
2475 struct stat statbuf;
2478 if (lstat(pathname, &statbuf) < 0)
2479 #else /* HASLSTAT */
2480 if (stat(pathname, &statbuf) < 0)
2481 #endif /* HASLSTAT */
2483 if (errno != ENOENT || !createflag)
2485 if (mkdir(pathname, 0755) < 0)
2489 if (!S_ISDIR(statbuf.st_mode))
2495 /* security: don't allow writable directories */
2496 if (bitset(S_IWGRP|S_IWOTH, statbuf.st_mode))
2504 ** PROC_LIST_ADD -- add process id to list of our children
2507 ** pid -- pid to add to list.
2508 ** task -- task of pid.
2509 ** type -- type of process.
2510 ** count -- number of processes.
2511 ** other -- other information for this type.
2517 ** May increase CurChildren. May grow ProcList.
2520 typedef struct procs PROCS_T;
2529 SOCKADDR proc_hostaddr;
2532 static PROCS_T *volatile ProcListVec = NULL;
2533 static int ProcListSize = 0;
2536 proc_list_add(pid, task, type, count, other, hostaddr)
2546 for (i = 0; i < ProcListSize; i++)
2548 if (ProcListVec[i].proc_pid == NO_PID)
2551 if (i >= ProcListSize)
2553 /* probe the existing vector to avoid growing infinitely */
2556 /* now scan again */
2557 for (i = 0; i < ProcListSize; i++)
2559 if (ProcListVec[i].proc_pid == NO_PID)
2563 if (i >= ProcListSize)
2565 /* grow process list */
2568 SM_ASSERT(ProcListSize < INT_MAX - PROC_LIST_SEG);
2569 npv = (PROCS_T *) sm_pmalloc_x((sizeof *npv) *
2570 (ProcListSize + PROC_LIST_SEG));
2571 if (ProcListSize > 0)
2573 memmove(npv, ProcListVec,
2574 ProcListSize * sizeof (PROCS_T));
2575 sm_free(ProcListVec);
2578 /* XXX just use memset() to initialize this part? */
2579 for (i = ProcListSize; i < ProcListSize + PROC_LIST_SEG; i++)
2581 npv[i].proc_pid = NO_PID;
2582 npv[i].proc_task = NULL;
2583 npv[i].proc_type = PROC_NONE;
2586 ProcListSize += PROC_LIST_SEG;
2589 ProcListVec[i].proc_pid = pid;
2590 PSTRSET(ProcListVec[i].proc_task, task);
2591 ProcListVec[i].proc_type = type;
2592 ProcListVec[i].proc_count = count;
2593 ProcListVec[i].proc_other = other;
2594 if (hostaddr != NULL)
2595 ProcListVec[i].proc_hostaddr = *hostaddr;
2597 memset(&ProcListVec[i].proc_hostaddr, 0,
2598 sizeof(ProcListVec[i].proc_hostaddr));
2600 /* if process adding itself, it's not a child */
2601 if (pid != CurrentPid)
2603 SM_ASSERT(CurChildren < INT_MAX);
2608 ** PROC_LIST_SET -- set pid task in process list
2611 ** pid -- pid to set
2612 ** task -- task of pid
2619 proc_list_set(pid, task)
2625 for (i = 0; i < ProcListSize; i++)
2627 if (ProcListVec[i].proc_pid == pid)
2629 PSTRSET(ProcListVec[i].proc_task, task);
2635 ** PROC_LIST_DROP -- drop pid from process list
2638 ** pid -- pid to drop
2639 ** st -- process status
2640 ** other -- storage for proc_other (return).
2646 ** May decrease CurChildren, CurRunners, or
2647 ** set RestartRequest or ShutdownRequest.
2649 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2650 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2655 proc_list_drop(pid, st, other)
2661 int type = PROC_NONE;
2663 for (i = 0; i < ProcListSize; i++)
2665 if (ProcListVec[i].proc_pid == pid)
2667 ProcListVec[i].proc_pid = NO_PID;
2668 type = ProcListVec[i].proc_type;
2670 *other = ProcListVec[i].proc_other;
2674 if (CurChildren > 0)
2678 if (type == PROC_CONTROL && WIFEXITED(st))
2680 /* if so, see if we need to restart or shutdown */
2681 if (WEXITSTATUS(st) == EX_RESTART)
2682 RestartRequest = "control socket";
2683 else if (WEXITSTATUS(st) == EX_SHUTDOWN)
2684 ShutdownRequest = "control socket";
2686 else if (type == PROC_QUEUE_CHILD && !WIFSTOPPED(st) &&
2687 ProcListVec[i].proc_other > -1)
2689 /* restart this persistent runner */
2690 mark_work_group_restart(ProcListVec[i].proc_other, st);
2692 else if (type == PROC_QUEUE)
2693 CurRunners -= ProcListVec[i].proc_count;
2696 ** PROC_LIST_CLEAR -- clear the process list
2705 ** Sets CurChildren to zero.
2713 /* start from 1 since 0 is the daemon itself */
2714 for (i = 1; i < ProcListSize; i++)
2715 ProcListVec[i].proc_pid = NO_PID;
2719 ** PROC_LIST_PROBE -- probe processes in the list to see if they still exist
2728 ** May decrease CurChildren.
2736 /* start from 1 since 0 is the daemon itself */
2737 for (i = 1; i < ProcListSize; i++)
2739 if (ProcListVec[i].proc_pid == NO_PID)
2741 if (kill(ProcListVec[i].proc_pid, 0) < 0)
2744 sm_syslog(LOG_DEBUG, CurEnv->e_id,
2745 "proc_list_probe: lost pid %d",
2746 (int) ProcListVec[i].proc_pid);
2747 ProcListVec[i].proc_pid = NO_PID;
2748 SM_FREE_CLR(ProcListVec[i].proc_task);
2752 if (CurChildren < 0)
2757 ** PROC_LIST_DISPLAY -- display the process list
2760 ** out -- output file pointer
2761 ** prefix -- string to output in front of each line.
2768 proc_list_display(out, prefix)
2774 for (i = 0; i < ProcListSize; i++)
2776 if (ProcListVec[i].proc_pid == NO_PID)
2779 (void) sm_io_fprintf(out, SM_TIME_DEFAULT, "%s%d %s%s\n",
2781 (int) ProcListVec[i].proc_pid,
2782 ProcListVec[i].proc_task != NULL ?
2783 ProcListVec[i].proc_task : "(unknown)",
2784 (OpMode == MD_SMTP ||
2785 OpMode == MD_DAEMON ||
2786 OpMode == MD_ARPAFTP) ? "\r" : "");
2791 ** PROC_LIST_SIGNAL -- send a signal to a type of process in the list
2794 ** type -- type of process to signal
2795 ** signal -- the type of signal to send
2800 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2801 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2806 proc_list_signal(type, signal)
2813 pid_t mypid = getpid();
2815 /* block these signals so that we may signal cleanly */
2816 chldwasblocked = sm_blocksignal(SIGCHLD);
2817 alrmwasblocked = sm_blocksignal(SIGALRM);
2819 /* Find all processes of type and send signal */
2820 for (i = 0; i < ProcListSize; i++)
2822 if (ProcListVec[i].proc_pid == NO_PID ||
2823 ProcListVec[i].proc_pid == mypid)
2825 if (ProcListVec[i].proc_type != type)
2827 (void) kill(ProcListVec[i].proc_pid, signal);
2830 /* restore the signals */
2831 if (alrmwasblocked == 0)
2832 (void) sm_releasesignal(SIGALRM);
2833 if (chldwasblocked == 0)
2834 (void) sm_releasesignal(SIGCHLD);
2838 ** COUNT_OPEN_CONNECTIONS
2841 ** hostaddr - ClientAddress
2844 ** the number of open connections for this client
2849 count_open_connections(hostaddr)
2854 if (hostaddr == NULL)
2857 for (i = 0; i < ProcListSize; i++)
2859 if (ProcListVec[i].proc_pid == NO_PID)
2862 if (hostaddr->sa.sa_family !=
2863 ProcListVec[i].proc_hostaddr.sa.sa_family)
2866 if (hostaddr->sa.sa_family == AF_INET &&
2867 (hostaddr->sin.sin_addr.s_addr ==
2868 ProcListVec[i].proc_hostaddr.sin.sin_addr.s_addr))
2870 #endif /* NETINET */
2872 if (hostaddr->sa.sa_family == AF_INET6 &&
2873 IN6_ARE_ADDR_EQUAL(&(hostaddr->sin6.sin6_addr),
2874 &(ProcListVec[i].proc_hostaddr.sin6.sin6_addr)))
2876 #endif /* NETINET6 */