2 * Copyright (c) 1998-2006 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.410 2006/12/18 18:36:44 ca Exp $")
18 #include <sm/sendmail.h>
23 ** NEWSTR -- Create a copy of a C string
26 ** s -- the string to copy.
29 ** pointer to newly allocated string.
42 sm_strlcpy(n, s, l + 1);
47 ** ADDQUOTES -- Adds quotes & quote bits to a string.
49 ** Runs through a string and adds backslashes and quote bits.
52 ** s -- the string to modify.
53 ** rpool -- resource pool from which to allocate result
56 ** pointer to quoted string.
71 /* Find length of quoted string */
72 while ((c = *p++) != '\0')
75 if (c == '\\' || c == '"')
79 q = r = sm_rpool_malloc_x(rpool, len + 3);
82 /* add leading quote */
84 while ((c = *p++) != '\0')
87 if (c == '\\' || c == '"')
97 ** STRIPBACKSLASH -- Strip all leading backslashes from a string, provided
98 ** the following character is alpha-numerical.
100 ** This is done in place.
103 ** s -- the string to strip.
115 if (s == NULL || *s == '\0')
118 while (*p == '\\' && (p[1] == '\\' || (isascii(p[1]) && isalnum(p[1]))))
127 ** RFC822_STRING -- Checks string for proper RFC822 string quoting.
129 ** Runs through a string and verifies RFC822 special characters
130 ** are only found inside comments, quoted strings, or backslash
131 ** escaped. Also verified balanced quotes and parenthesis.
134 ** s -- the string to modify.
137 ** true iff the string is RFC822 compliant, false otherwise.
153 /* escaped character */
160 else if (commentlev == 0 && *c == '"')
174 else if (commentlev == 0 &&
175 strchr(MustQuoteChars, *c) != NULL)
181 /* unbalanced '"' or '(' */
182 return !quoted && commentlev == 0;
186 ** SHORTEN_RFC822_STRING -- Truncate and rebalance an RFC822 string
188 ** Arbitrarily shorten (in place) an RFC822 string and rebalance
189 ** comments and quotes.
192 ** string -- the string to shorten
193 ** length -- the maximum size, 0 if no maximum
196 ** true if string is changed, false otherwise
199 ** Changes string in place, possibly resulting
200 ** in a shorter string.
204 shorten_rfc822_string(string, length)
208 bool backslash = false;
209 bool modified = false;
216 ** If have to rebalance an already short enough string,
217 ** need to do it within allocated space.
220 slen = strlen(string);
221 if (length == 0 || slen < length)
234 else if (*ptr == '(')
239 else if (*ptr == ')')
241 if (--parencount < 0)
245 /* Inside a comment, quotes don't matter */
246 if (parencount <= 0 && *ptr == '"')
250 /* Check for sufficient space for next character */
251 if (length - (ptr - string) <= (size_t) ((backslash ? 1 : 0) +
255 /* Not enough, backtrack */
258 else if (*ptr == '(' && !quoted)
260 else if (*ptr == '"' && parencount == 0)
268 while (parencount-- > 0)
295 ** FIND_CHARACTER -- find an unquoted character in an RFC822 string
297 ** Find an unquoted, non-commented character in an RFC822
298 ** string and return a pointer to its location in the
302 ** string -- the string to search
303 ** character -- the character to find
306 ** pointer to the character, or
307 ** a pointer to the end of the line if character is not found
311 find_character(string, character)
315 bool backslash = false;
319 while (string != NULL && *string != '\0')
324 if (!quoted && character == '\\' && *string == '\\')
341 if (--parencount < 0)
346 /* Inside a comment, nothing matters */
355 else if (*string == character && !quoted)
360 /* Return pointer to the character */
365 ** CHECK_BODYTYPE -- check bodytype parameter
368 ** bodytype -- bodytype parameter
371 ** BODYTYPE_* according to parameter
376 check_bodytype(bodytype)
379 /* check body type for legality */
380 if (bodytype == NULL)
381 return BODYTYPE_NONE;
382 if (sm_strcasecmp(bodytype, "7BIT") == 0)
383 return BODYTYPE_7BIT;
384 if (sm_strcasecmp(bodytype, "8BITMIME") == 0)
385 return BODYTYPE_8BITMIME;
386 return BODYTYPE_ILLEGAL;
390 ** TRUNCATE_AT_DELIM -- truncate string at a delimiter and append "..."
393 ** str -- string to truncate
394 ** len -- maximum length (including '\0') (0 for unlimited)
395 ** delim -- delimiter character
402 truncate_at_delim(str, len, delim)
409 if (str == NULL || len == 0 || strlen(str) < len)
412 *(str + len - 1) = '\0';
413 while ((p = strrchr(str, delim)) != NULL)
416 if (p - str + 4 < len)
420 (void) sm_strlcat(str, "...", len);
425 /* Couldn't find a place to append "..." */
427 (void) sm_strlcpy(str, "...", len);
433 ** XALLOC -- Allocate memory, raise an exception on error
436 ** sz -- size of area to allocate.
439 ** pointer to data region.
442 ** SmHeapOutOfMemory (F:sm.heap) -- cannot allocate memory
445 ** Memory is allocated.
450 xalloc_tagged(sz, file, line)
454 #else /* SM_HEAP_CHECK */
457 #endif /* SM_HEAP_CHECK */
463 /* some systems can't handle size zero mallocs */
467 /* scaffolding for testing error handling code */
468 sm_xtrap_raise_x(&SmHeapOutOfMemory);
470 p = sm_malloc_tagged((unsigned) sz, file, line, sm_heap_group());
473 sm_exc_raise_x(&SmHeapOutOfMemory);
479 ** COPYPLIST -- copy list of pointers.
481 ** This routine is the equivalent of strdup for lists of
485 ** list -- list of pointers to copy.
486 ** Must be NULL terminated.
487 ** copycont -- if true, copy the contents of the vector
488 ** (which must be a string) also.
489 ** rpool -- resource pool from which to allocate storage,
497 copyplist(list, copycont, rpool)
503 register char **newvp;
505 for (vp = list; *vp != NULL; vp++)
510 newvp = (char **) sm_rpool_malloc_x(rpool, (vp - list) * sizeof(*vp));
511 memmove((char *) newvp, (char *) list, (int) (vp - list) * sizeof(*vp));
515 for (vp = newvp; *vp != NULL; vp++)
516 *vp = sm_rpool_strdup_x(rpool, *vp);
523 ** COPYQUEUE -- copy address queue.
525 ** This routine is the equivalent of strdup for address queues;
526 ** addresses marked as QS_IS_DEAD() aren't copied
529 ** addr -- list of address structures to copy.
530 ** rpool -- resource pool from which to allocate storage
537 copyqueue(addr, rpool)
541 register ADDRESS *newaddr;
543 register ADDRESS **tail = &ret;
547 if (!QS_IS_DEAD(addr->q_state))
549 newaddr = (ADDRESS *) sm_rpool_malloc_x(rpool,
551 STRUCTCOPY(*addr, *newaddr);
553 tail = &newaddr->q_next;
563 ** LOG_SENDMAIL_PID -- record sendmail pid and command line.
566 ** e -- the current envelope.
572 ** writes pidfile, logs command line.
573 ** keeps file open and locked to prevent overwrite of active file
576 static SM_FILE_T *Pidf = NULL;
583 char pidpath[MAXPATHLEN];
584 extern char *CommandLineArgs;
586 /* write the pid to the log file for posterity */
587 sff = SFF_NOLINK|SFF_ROOTOK|SFF_REGONLY|SFF_CREAT|SFF_NBLOCK;
588 if (TrustedUid != 0 && RealUid == TrustedUid)
589 sff |= SFF_OPENASROOT;
590 expand(PidFile, pidpath, sizeof(pidpath), e);
591 Pidf = safefopen(pidpath, O_WRONLY|O_TRUNC, FileMode, sff);
594 if (errno == EWOULDBLOCK)
595 sm_syslog(LOG_ERR, NOQID,
596 "unable to write pid to %s: file in use by another process",
599 sm_syslog(LOG_ERR, NOQID,
600 "unable to write pid to %s: %s",
601 pidpath, sm_errstring(errno));
605 PidFilePid = getpid();
607 /* write the process id on line 1 */
608 (void) sm_io_fprintf(Pidf, SM_TIME_DEFAULT, "%ld\n",
611 /* line 2 contains all command line flags */
612 (void) sm_io_fprintf(Pidf, SM_TIME_DEFAULT, "%s\n",
616 (void) sm_io_flush(Pidf, SM_TIME_DEFAULT);
619 ** Leave pid file open until process ends
620 ** so it's not overwritten by another
625 sm_syslog(LOG_INFO, NOQID, "started as: %s", CommandLineArgs);
629 ** CLOSE_SENDMAIL_PID -- close sendmail pid file
644 (void) sm_io_close(Pidf, SM_TIME_DEFAULT);
649 ** SET_DELIVERY_MODE -- set and record the delivery mode
652 ** mode -- delivery mode
653 ** e -- the current envelope.
659 ** sets {deliveryMode} macro
663 set_delivery_mode(mode, e)
669 e->e_sendmode = (char) mode;
670 buf[0] = (char) mode;
672 macdefine(&e->e_macro, A_TEMP, macid("{deliveryMode}"), buf);
676 ** SET_OP_MODE -- set and record the op mode
680 ** e -- the current envelope.
686 ** sets {opMode} macro
694 extern ENVELOPE BlankEnvelope;
696 OpMode = (char) mode;
697 buf[0] = (char) mode;
699 macdefine(&BlankEnvelope.e_macro, A_TEMP, MID_OPMODE, buf);
703 ** PRINTAV -- print argument vector.
706 ** fp -- output file pointer.
707 ** av -- argument vector.
724 sm_dprintf("\n\t%08lx=", (unsigned long) *av);
726 (void) sm_io_putc(fp, SM_TIME_DEFAULT, ' ');
728 sm_dprintf("%s", str2prt(*av++));
732 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '\n');
736 ** XPUTS -- put string doing control escapes.
739 ** fp -- output file pointer.
740 ** s -- string to put.
756 bool shiftout = false;
757 extern struct metamac MetaMacros[];
758 static SM_DEBUG_T DebugANSI = SM_DEBUG_INITIALIZER("ANSI",
759 "@(#)$Debug: ANSI - enable reverse video in debug output $");
762 ** TermEscape is set here, rather than in main(),
763 ** because ANSI mode can be turned on or off at any time
764 ** if we are in -bt rule testing mode.
767 if (sm_debug_unknown(&DebugANSI))
769 if (sm_debug_active(&DebugANSI, 1))
771 TermEscape.te_rv_on = "\033[7m";
772 TermEscape.te_normal = "\033[0m";
776 TermEscape.te_rv_on = "";
777 TermEscape.te_normal = "";
783 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s<null>%s",
784 TermEscape.te_rv_on, TermEscape.te_normal);
787 while ((c = (*s++ & 0377)) != '\0')
791 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
792 TermEscape.te_normal);
795 if (!isascii(c) && !tTd(84, 1))
799 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
801 TermEscape.te_rv_on);
808 if (c == MACROEXPAND || c == MACRODEXPAND)
810 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
812 TermEscape.te_rv_on);
813 if (c == MACRODEXPAND)
814 (void) sm_io_putc(fp,
815 SM_TIME_DEFAULT, '&');
819 if (strchr("=~&?", *s) != NULL)
820 (void) sm_io_putc(fp,
823 if (bitset(0200, *s))
824 (void) sm_io_fprintf(fp,
827 macname(bitidx(*s++)));
829 (void) sm_io_fprintf(fp,
835 for (mp = MetaMacros; mp->metaname != '\0'; mp++)
837 if (bitidx(mp->metaval) == c)
839 (void) sm_io_fprintf(fp,
848 if (c == MATCHCLASS || c == MATCHNCLASS)
850 if (bitset(0200, *s))
851 (void) sm_io_fprintf(fp,
854 macname(bitidx(*s++)));
856 (void) sm_io_fprintf(fp,
861 if (mp->metaname != '\0')
864 /* unrecognized meta character */
865 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%sM-",
866 TermEscape.te_rv_on);
873 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c);
877 /* wasn't a meta-macro -- find another way to print it */
894 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
895 TermEscape.te_rv_on);
900 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '\\');
901 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c);
904 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " %o ", c);
906 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, " %#x ", c);
907 else if (!isascii(c) && !tTd(84, 1))
909 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '^');
910 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c ^ 0100);
914 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
915 TermEscape.te_normal);
916 (void) sm_io_flush(fp, SM_TIME_DEFAULT);
920 ** MAKELOWER -- Translate a line into lower case
923 ** p -- the string to translate. If NULL, return is
930 ** String pointed to by p is translated to lower case.
941 for (; (c = *p) != '\0'; p++)
942 if (isascii(c) && isupper(c))
947 ** FIXCRLF -- fix <CR><LF> in line.
949 ** Looks for the <CR><LF> combination and turns it into the
950 ** UNIX canonical <NL> character. It only takes one line,
951 ** i.e., it is assumed that the first <NL> found is the end
955 ** line -- the line to fix.
956 ** stripnl -- if true, strip the newline also.
962 ** line is changed in place.
966 fixcrlf(line, stripnl)
972 p = strchr(line, '\n');
975 if (p > line && p[-1] == '\r')
983 ** PUTLINE -- put a line like fputs obeying SMTP conventions
985 ** This routine always guarantees outputing a newline (or CRLF,
986 ** as appropriate) at the end of the string.
990 ** mci -- the mailer connection information.
993 ** true iff line was written successfully
996 ** output of l to mci->mci_out.
1004 return putxline(l, strlen(l), mci, PXLF_MAPFROM);
1008 ** PUTXLINE -- putline with flags bits.
1010 ** This routine always guarantees outputing a newline (or CRLF,
1011 ** as appropriate) at the end of the string.
1014 ** l -- line to put.
1015 ** len -- the length of the line.
1016 ** mci -- the mailer connection information.
1017 ** pxflags -- flag bits:
1018 ** PXLF_MAPFROM -- map From_ to >From_.
1019 ** PXLF_STRIP8BIT -- strip 8th bit.
1020 ** PXLF_HEADER -- map bare newline in header to newline space.
1021 ** PXLF_NOADDEOL -- don't add an EOL if one wasn't present.
1022 ** PXLF_STRIPMQUOTE -- strip METAQUOTE bytes.
1025 ** true iff line was written successfully
1028 ** output of l to mci->mci_out.
1032 #define PUTX(limit) \
1035 quotenext = false; \
1038 unsigned char c = (unsigned char) *l++; \
1040 if (bitset(PXLF_STRIPMQUOTE, pxflags) && \
1041 !quotenext && c == METAQUOTE) \
1046 quotenext = false; \
1049 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, \
1055 if (TrafficLogFile != NULL) \
1056 (void) sm_io_putc(TrafficLogFile, \
1063 putxline(l, len, mci, pxflags)
1069 register char *p, *end;
1071 bool dead, quotenext, strip8bit;
1073 /* strip out 0200 bits -- these can look like TELNET protocol */
1074 strip8bit = bitset(MCIF_7BIT, mci->mci_flags) ||
1075 bitset(PXLF_STRIP8BIT, pxflags);
1084 /* find the end of the line */
1085 p = memchr(l, '\n', end - l);
1092 if (TrafficLogFile != NULL)
1093 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1094 "%05d >>> ", (int) CurrentPid);
1096 /* check for line overflow */
1097 while (mci->mci_mailer->m_linelimit > 0 &&
1098 (p - l + slop) > mci->mci_mailer->m_linelimit)
1100 register char *q = &l[mci->mci_mailer->m_linelimit - slop - 1];
1102 if (l[0] == '.' && slop == 0 &&
1103 bitnset(M_XDOT, mci->mci_mailer->m_flags))
1105 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1108 if (TrafficLogFile != NULL)
1109 (void) sm_io_putc(TrafficLogFile,
1110 SM_TIME_DEFAULT, '.');
1112 else if (l[0] == 'F' && slop == 0 &&
1113 bitset(PXLF_MAPFROM, pxflags) &&
1114 strncmp(l, "From ", 5) == 0 &&
1115 bitnset(M_ESCFROM, mci->mci_mailer->m_flags))
1117 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1120 if (TrafficLogFile != NULL)
1121 (void) sm_io_putc(TrafficLogFile,
1132 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1133 '!') == SM_IO_EOF ||
1134 sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
1135 mci->mci_mailer->m_eol) == SM_IO_EOF ||
1136 sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1142 if (TrafficLogFile != NULL)
1144 (void) sm_io_fprintf(TrafficLogFile,
1155 /* output last part */
1156 if (l[0] == '.' && slop == 0 &&
1157 bitnset(M_XDOT, mci->mci_mailer->m_flags))
1159 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '.') ==
1165 if (TrafficLogFile != NULL)
1166 (void) sm_io_putc(TrafficLogFile,
1167 SM_TIME_DEFAULT, '.');
1169 else if (l[0] == 'F' && slop == 0 &&
1170 bitset(PXLF_MAPFROM, pxflags) &&
1171 strncmp(l, "From ", 5) == 0 &&
1172 bitnset(M_ESCFROM, mci->mci_mailer->m_flags))
1174 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '>') ==
1180 if (TrafficLogFile != NULL)
1181 (void) sm_io_putc(TrafficLogFile,
1182 SM_TIME_DEFAULT, '>');
1188 if (TrafficLogFile != NULL)
1189 (void) sm_io_putc(TrafficLogFile, SM_TIME_DEFAULT,
1191 if ((!bitset(PXLF_NOADDEOL, pxflags) || !noeol) &&
1192 sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
1193 mci->mci_mailer->m_eol) == SM_IO_EOF)
1198 if (l < end && *l == '\n')
1200 if (*++l != ' ' && *l != '\t' && *l != '\0' &&
1201 bitset(PXLF_HEADER, pxflags))
1203 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1210 if (TrafficLogFile != NULL)
1211 (void) sm_io_putc(TrafficLogFile,
1212 SM_TIME_DEFAULT, ' ');
1221 ** XUNLINK -- unlink a file, doing logging as appropriate.
1224 ** f -- name of file to unlink.
1227 ** return value of unlink()
1241 sm_syslog(LOG_DEBUG, CurEnv->e_id, "unlink %s", f);
1245 if (i < 0 && LogLevel > 97)
1246 sm_syslog(LOG_DEBUG, CurEnv->e_id, "%s: unlink-fail %d",
1255 ** SFGETS -- "safe" fgets -- times out and ignores random interrupts.
1258 ** buf -- place to put the input line.
1259 ** siz -- size of buf.
1260 ** fp -- file to read from.
1261 ** timeout -- the timeout before error occurs.
1262 ** during -- what we are trying to read (for error messages).
1265 ** NULL on error (including timeout). This may also leave
1266 ** buf containing a null string.
1272 sfgets(buf, siz, fp, timeout, during)
1283 SM_REQUIRE(siz > 0);
1284 SM_REQUIRE(buf != NULL);
1297 /* convert the timeout to sm_io notation */
1298 io_timeout = (timeout <= 0) ? SM_TIME_DEFAULT : timeout * 1000;
1299 while (!sm_io_eof(fp) && !sm_io_error(fp))
1302 p = sm_io_fgets(fp, io_timeout, buf, siz);
1303 if (p == NULL && errno == EAGAIN)
1305 /* The sm_io_fgets() call timedout */
1307 sm_syslog(LOG_NOTICE, CurEnv->e_id,
1308 "timeout waiting for input from %.100s during %s",
1315 if (TrafficLogFile != NULL)
1316 (void) sm_io_fprintf(TrafficLogFile,
1318 "%05d <<< [TIMEOUT]\n",
1323 if (p != NULL || errno != EINTR)
1325 (void) sm_io_clearerr(fp);
1329 /* clean up the books and exit */
1334 if (TrafficLogFile != NULL)
1335 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1341 if (TrafficLogFile != NULL)
1342 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1343 "%05d <<< %s", (int) CurrentPid, buf);
1346 for (p = buf; *p != '\0'; p++)
1349 else if (!HasEightBits)
1351 for (p = buf; *p != '\0'; p++)
1353 if (bitset(0200, *p))
1355 HasEightBits = true;
1364 ** FGETFOLDED -- like fgets, but knows about folded lines.
1367 ** buf -- place to put result.
1368 ** np -- pointer to bytes available; will be updated with
1369 ** the actual buffer size (not number of bytes filled)
1371 ** f -- file to read from.
1374 ** input line(s) on success, NULL on error or SM_IO_EOF.
1375 ** This will normally be buf -- unless the line is too
1376 ** long, when it will be sm_malloc_x()ed.
1379 ** buf gets lines from f, with continuation lines (lines
1380 ** with leading white space) appended. CRLF's are mapped
1381 ** into single newlines. Any trailing NL is stripped.
1385 fgetfolded(buf, np, f)
1390 register char *p = buf;
1395 SM_REQUIRE(np != NULL);
1398 SM_REQUIRE(buf != NULL);
1407 while ((i = sm_io_getc(f, SM_TIME_DEFAULT)) != SM_IO_EOF)
1411 i = sm_io_getc(f, SM_TIME_DEFAULT);
1415 (void) sm_io_ungetc(f, SM_TIME_DEFAULT,
1422 /* allocate new space */
1427 if (nn < MEMCHUNKSIZE)
1431 nbp = sm_malloc_x(nn);
1432 memmove(nbp, bp, p - bp);
1444 i = sm_io_getc(f, SM_TIME_DEFAULT);
1446 (void) sm_io_ungetc(f, SM_TIME_DEFAULT, i);
1447 if (i != ' ' && i != '\t')
1460 ** CURTIME -- return current time.
1466 ** 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)
1501 ** ATOOCT -- convert a string representation to octal.
1504 ** s -- string to convert.
1507 ** An integer representing the string interpreted as an
1517 while (*s >= '0' && *s <= '7')
1518 i = (i << 3) | (*s++ - '0');
1523 ** BITINTERSECT -- tell if two bitmaps intersect
1526 ** a, b -- the bitmaps in question
1529 ** true if they have a non-null intersection
1540 for (i = BITMAPBYTES / sizeof(int); --i >= 0; )
1542 if ((a[i] & b[i]) != 0)
1549 ** BITZEROP -- tell if a bitmap is all zero
1552 ** map -- the bit map to check
1555 ** true if map is all zero.
1556 ** false if there are any bits set in map.
1565 for (i = BITMAPBYTES / sizeof(int); --i >= 0; )
1574 ** STRCONTAINEDIN -- tell if one string is contained in another
1577 ** icase -- ignore case?
1578 ** a -- possible substring.
1579 ** b -- possible superstring.
1582 ** true if a is contained in b (case insensitive).
1587 strcontainedin(icase, a, b)
1599 if (icase && isascii(c) && isupper(c))
1601 for (; lb-- >= la; b++)
1606 isascii(*b) && isupper(*b) && tolower(*b) != c)
1608 if (sm_strncasecmp(a, b, la) == 0)
1615 if (strncmp(a, b, la) == 0)
1623 ** CHECKFD012 -- check low numbered file descriptors
1625 ** File descriptors 0, 1, and 2 should be open at all times.
1626 ** This routine verifies that, and fixes it if not true.
1629 ** where -- a tag printed if the assertion failed
1642 for (i = 0; i < 3; i++)
1648 ** CHECKFDOPEN -- make sure file descriptor is open -- for extended debugging
1651 ** fd -- file descriptor to check.
1652 ** where -- tag to print on failure.
1659 checkfdopen(fd, where)
1666 if (fstat(fd, &st) < 0 && errno == EBADF)
1668 syserr("checkfdopen(%d): %s not open as expected!", fd, where);
1675 ** CHECKFDS -- check for new or missing file descriptors
1678 ** where -- tag for printing. If null, take a base line.
1684 ** If where is set, shows changes since the last call.
1693 bool printhdr = true;
1694 int save_errno = errno;
1695 static BITMAP256 baseline;
1696 extern int DtableSize;
1698 if (DtableSize > BITMAPBITS)
1703 clrbitmap(baseline);
1705 for (fd = 0; fd < maxfd; fd++)
1709 if (fstat(fd, &stbuf) < 0 && errno != EOPNOTSUPP)
1711 if (!bitnset(fd, baseline))
1713 clrbitn(fd, baseline);
1715 else if (!bitnset(fd, baseline))
1716 setbitn(fd, baseline);
1720 /* file state has changed */
1725 sm_syslog(LOG_DEBUG, CurEnv->e_id,
1730 dumpfd(fd, true, true);
1736 ** PRINTOPENFDS -- print the open file descriptors (for debugging)
1739 ** logit -- if set, send output to syslog; otherwise
1740 ** print for debugging.
1746 #if NETINET || NETINET6
1747 # include <arpa/inet.h>
1748 #endif /* NETINET || NETINET6 */
1755 extern int DtableSize;
1757 for (fd = 0; fd < DtableSize; fd++)
1758 dumpfd(fd, false, logit);
1762 ** DUMPFD -- dump a file descriptor
1765 ** fd -- the file descriptor to dump.
1766 ** printclosed -- if set, print a notification even if
1767 ** it is closed; otherwise print nothing.
1768 ** logit -- if set, use sm_syslog instead of sm_dprintf()
1775 dumpfd(fd, printclosed, logit)
1784 #endif /* S_IFSOCK */
1785 auto SOCKADDR_LEN_T slen;
1789 #else /* STAT64 > 0 */
1791 #endif /* STAT64 > 0 */
1795 (void) sm_snprintf(p, SPACELEFT(buf, p), "%3d: ", fd);
1801 #else /* STAT64 > 0 */
1803 #endif /* STAT64 > 0 */
1808 (void) sm_snprintf(p, SPACELEFT(buf, p),
1810 sm_errstring(errno));
1813 else if (printclosed)
1815 (void) sm_snprintf(p, SPACELEFT(buf, p), "CLOSED");
1821 i = fcntl(fd, F_GETFL, 0);
1824 (void) sm_snprintf(p, SPACELEFT(buf, p), "fl=0x%x, ", i);
1828 (void) sm_snprintf(p, SPACELEFT(buf, p), "mode=%o: ",
1831 switch (st.st_mode & S_IFMT)
1835 (void) sm_snprintf(p, SPACELEFT(buf, p), "SOCK ");
1837 memset(&sa, '\0', sizeof(sa));
1839 if (getsockname(fd, &sa.sa, &slen) < 0)
1840 (void) sm_snprintf(p, SPACELEFT(buf, p), "(%s)",
1841 sm_errstring(errno));
1844 hp = hostnamebyanyaddr(&sa);
1851 else if (sa.sa.sa_family == AF_INET)
1852 (void) sm_snprintf(p, SPACELEFT(buf, p),
1853 "%s/%d", hp, ntohs(sa.sin.sin_port));
1854 # endif /* NETINET */
1856 else if (sa.sa.sa_family == AF_INET6)
1857 (void) sm_snprintf(p, SPACELEFT(buf, p),
1858 "%s/%d", hp, ntohs(sa.sin6.sin6_port));
1859 # endif /* NETINET6 */
1861 (void) sm_snprintf(p, SPACELEFT(buf, p),
1865 (void) sm_snprintf(p, SPACELEFT(buf, p), "->");
1868 if (getpeername(fd, &sa.sa, &slen) < 0)
1869 (void) sm_snprintf(p, SPACELEFT(buf, p), "(%s)",
1870 sm_errstring(errno));
1873 hp = hostnamebyanyaddr(&sa);
1880 else if (sa.sa.sa_family == AF_INET)
1881 (void) sm_snprintf(p, SPACELEFT(buf, p),
1882 "%s/%d", hp, ntohs(sa.sin.sin_port));
1883 # endif /* NETINET */
1885 else if (sa.sa.sa_family == AF_INET6)
1886 (void) sm_snprintf(p, SPACELEFT(buf, p),
1887 "%s/%d", hp, ntohs(sa.sin6.sin6_port));
1888 # endif /* NETINET6 */
1890 (void) sm_snprintf(p, SPACELEFT(buf, p),
1894 #endif /* S_IFSOCK */
1897 (void) sm_snprintf(p, SPACELEFT(buf, p), "CHR: ");
1903 (void) sm_snprintf(p, SPACELEFT(buf, p), "BLK: ");
1906 #endif /* S_IFBLK */
1908 #if defined(S_IFIFO) && (!defined(S_IFSOCK) || S_IFIFO != S_IFSOCK)
1910 (void) sm_snprintf(p, SPACELEFT(buf, p), "FIFO: ");
1913 #endif /* defined(S_IFIFO) && (!defined(S_IFSOCK) || S_IFIFO != S_IFSOCK) */
1917 (void) sm_snprintf(p, SPACELEFT(buf, p), "DIR: ");
1920 #endif /* S_IFDIR */
1924 (void) sm_snprintf(p, SPACELEFT(buf, p), "LNK: ");
1927 #endif /* S_IFLNK */
1931 (void) sm_snprintf(p, SPACELEFT(buf, p),
1932 "dev=%d/%d, ino=%llu, nlink=%d, u/gid=%d/%d, ",
1933 major(st.st_dev), minor(st.st_dev),
1934 (ULONGLONG_T) st.st_ino,
1935 (int) st.st_nlink, (int) st.st_uid,
1938 (void) sm_snprintf(p, SPACELEFT(buf, p), "size=%llu",
1939 (ULONGLONG_T) st.st_size);
1945 sm_syslog(LOG_DEBUG, CurEnv ? CurEnv->e_id : NULL,
1948 sm_dprintf("%s\n", buf);
1952 ** SHORTEN_HOSTNAME -- strip local domain information off of hostname.
1955 ** host -- the host to shorten (stripped in place).
1958 ** place where string was truncated, NULL if not truncated.
1962 shorten_hostname(host)
1970 /* strip off final dot */
1972 p = &host[(i == 0) ? 0 : i - 1];
1979 /* see if there is any domain at all -- if not, we are done */
1980 p = strchr(host, '.');
1984 /* yes, we have a domain -- see if it looks like us */
1985 mydom = macvalue('m', CurEnv);
1989 if ((canon ? sm_strcasecmp(p, mydom)
1990 : sm_strncasecmp(p, mydom, i)) == 0 &&
1991 (mydom[i] == '.' || mydom[i] == '\0'))
2000 ** PROG_OPEN -- open a program for reading
2003 ** argv -- the argument list.
2004 ** pfd -- pointer to a place to store the file descriptor.
2005 ** e -- the current envelope.
2008 ** pid of the process -- -1 if it failed.
2012 prog_open(argv, pfd, e)
2023 char buf[MAXPATHLEN];
2024 extern int DtableSize;
2028 syserr("%s: cannot create pipe for stdout", argv[0]);
2034 syserr("%s: cannot fork", argv[0]);
2035 (void) close(fdv[0]);
2036 (void) close(fdv[1]);
2042 (void) close(fdv[1]);
2047 /* Reset global flags */
2048 RestartRequest = NULL;
2049 RestartWorkGroup = false;
2050 ShutdownRequest = NULL;
2052 CurrentPid = getpid();
2055 ** Initialize exception stack and default exception
2056 ** handler for child process.
2059 sm_exc_newthread(fatal_error);
2061 /* child -- close stdin */
2064 /* stdout goes back to parent */
2065 (void) close(fdv[0]);
2066 if (dup2(fdv[1], 1) < 0)
2068 syserr("%s: cannot dup2 for stdout", argv[0]);
2071 (void) close(fdv[1]);
2073 /* stderr goes to transcript if available */
2074 if (e->e_xfp != NULL)
2078 xfd = sm_io_getinfo(e->e_xfp, SM_IO_WHAT_FD, NULL);
2079 if (xfd >= 0 && dup2(xfd, 2) < 0)
2081 syserr("%s: cannot dup2 for stderr", argv[0]);
2086 /* this process has no right to the queue file */
2087 if (e->e_lockfp != NULL)
2091 fd = sm_io_getinfo(e->e_lockfp, SM_IO_WHAT_FD, NULL);
2095 syserr("%s: lockfp does not have a fd", argv[0]);
2098 /* chroot to the program mailer directory, if defined */
2099 if (ProgMailer != NULL && ProgMailer->m_rootdir != NULL)
2101 expand(ProgMailer->m_rootdir, buf, sizeof(buf), e);
2102 if (chroot(buf) < 0)
2104 syserr("prog_open: cannot chroot(%s)", buf);
2109 syserr("prog_open: cannot chdir(/)");
2114 /* run as default user */
2116 sm_mbdb_terminate();
2118 (void) sm_memstat_close();
2119 #endif /* _FFR_MEMSTAT */
2120 if (setgid(DefGid) < 0 && geteuid() == 0)
2122 syserr("prog_open: setgid(%ld) failed", (long) DefGid);
2125 if (setuid(DefUid) < 0 && geteuid() == 0)
2127 syserr("prog_open: setuid(%ld) failed", (long) DefUid);
2131 /* run in some directory */
2132 if (ProgMailer != NULL)
2133 p = ProgMailer->m_execdir;
2136 for (; p != NULL; p = q)
2141 expand(p, buf, sizeof(buf), e);
2144 if (buf[0] != '\0' && chdir(buf) >= 0)
2149 /* backup directories */
2150 if (chdir("/tmp") < 0)
2154 /* Check safety of program to be run */
2155 sff = SFF_ROOTOK|SFF_EXECOK;
2156 if (!bitnset(DBS_RUNWRITABLEPROGRAM, DontBlameSendmail))
2157 sff |= SFF_NOGWFILES|SFF_NOWWFILES;
2158 if (bitnset(DBS_RUNPROGRAMINUNSAFEDIRPATH, DontBlameSendmail))
2159 sff |= SFF_NOPATHCHECK;
2161 sff |= SFF_SAFEDIRPATH;
2162 ret = safefile(argv[0], DefUid, DefGid, DefUser, sff, 0, NULL);
2164 sm_syslog(LOG_INFO, e->e_id,
2165 "Warning: prog_open: program %s unsafe: %s",
2166 argv[0], sm_errstring(ret));
2168 /* arrange for all the files to be closed */
2169 sm_close_on_exec(STDERR_FILENO + 1, DtableSize);
2171 /* now exec the process */
2172 (void) execve(argv[0], (ARGV_T) argv, (ARGV_T) UserEnviron);
2176 syserr("%s: cannot exec", argv[0]);
2177 if (transienterror(save_errno))
2180 return -1; /* avoid compiler warning on IRIX */
2184 ** GET_COLUMN -- look up a Column in a line buffer
2187 ** line -- the raw text line to search.
2188 ** col -- the column number to fetch.
2189 ** delim -- the delimiter between columns. If null,
2191 ** buf -- the output buffer.
2192 ** buflen -- the length of buf.
2195 ** buf if successful.
2200 get_column(line, col, delim, buf, buflen)
2212 if ((char) delim == '\0')
2213 (void) sm_strlcpy(delimbuf, "\n\t ", sizeof(delimbuf));
2216 delimbuf[0] = (char) delim;
2222 return NULL; /* line empty */
2223 if (*p == (char) delim && col == 0)
2224 return NULL; /* first column empty */
2228 if (col == 0 && (char) delim == '\0')
2230 while (*begin != '\0' && isascii(*begin) && isspace(*begin))
2234 for (i = 0; i < col; i++)
2236 if ((begin = strpbrk(begin, delimbuf)) == NULL)
2237 return NULL; /* no such column */
2239 if ((char) delim == '\0')
2241 while (*begin != '\0' && isascii(*begin) && isspace(*begin))
2246 end = strpbrk(begin, delimbuf);
2253 (void) sm_strlcpy(buf, begin, i + 1);
2258 ** CLEANSTRCPY -- copy string keeping out bogus characters
2261 ** t -- "to" string.
2262 ** f -- "from" string.
2263 ** l -- length of space available in "to" string.
2270 cleanstrcpy(t, f, l)
2275 /* check for newlines and log if necessary */
2276 (void) denlstring(f, true, true);
2279 syserr("!cleanstrcpy: length == 0");
2282 while (l > 0 && *f != '\0')
2285 (isalnum(*f) || strchr("!#$%&'*+-./^_`{|}~", *f) != NULL))
2296 ** DENLSTRING -- convert newlines in a string to spaces
2299 ** s -- the input string
2300 ** strict -- if set, don't permit continuation lines.
2301 ** logattacks -- if set, log attempted attacks.
2304 ** A pointer to a version of the string with newlines
2305 ** mapped to spaces. This should be copied.
2309 denlstring(s, strict, logattacks)
2316 static char *bp = NULL;
2320 while ((p = strchr(p, '\n')) != NULL)
2321 if (strict || (*++p != ' ' && *p != '\t'))
2329 /* allocate more space */
2330 char *nbp = sm_pmalloc_x(l);
2337 (void) sm_strlcpy(bp, s, l);
2338 for (p = bp; (p = strchr(p, '\n')) != NULL; )
2343 sm_syslog(LOG_NOTICE, CurEnv ? CurEnv->e_id : NULL,
2344 "POSSIBLE ATTACK from %.100s: newline in string \"%s\"",
2345 RealHostName == NULL ? "[UNKNOWN]" : RealHostName,
2346 shortenstring(bp, MAXSHORTSTR));
2353 ** STRREPLNONPRT -- replace "unprintable" characters in a string with subst
2356 ** s -- string to manipulate (in place)
2357 ** subst -- character to use as replacement
2360 ** true iff string did not contain "unprintable" characters
2375 if (!(isascii(*s) && isprint(*s)))
2386 ** PATH_IS_DIR -- check to see if file exists and is a directory.
2388 ** There are some additional checks for security violations in
2389 ** here. This routine is intended to be used for the host status
2393 ** pathname -- pathname to check for directory-ness.
2394 ** createflag -- if set, create directory if needed.
2397 ** true -- if the indicated pathname is a directory
2398 ** false -- otherwise
2402 path_is_dir(pathname, createflag)
2406 struct stat statbuf;
2409 if (lstat(pathname, &statbuf) < 0)
2410 #else /* HASLSTAT */
2411 if (stat(pathname, &statbuf) < 0)
2412 #endif /* HASLSTAT */
2414 if (errno != ENOENT || !createflag)
2416 if (mkdir(pathname, 0755) < 0)
2420 if (!S_ISDIR(statbuf.st_mode))
2426 /* security: don't allow writable directories */
2427 if (bitset(S_IWGRP|S_IWOTH, statbuf.st_mode))
2436 ** PROC_LIST_ADD -- add process id to list of our children
2439 ** pid -- pid to add to list.
2440 ** task -- task of pid.
2441 ** type -- type of process.
2442 ** count -- number of processes.
2443 ** other -- other information for this type.
2449 ** May increase CurChildren. May grow ProcList.
2452 typedef struct procs PROCS_T;
2461 SOCKADDR proc_hostaddr;
2464 static PROCS_T *volatile ProcListVec = NULL;
2465 static int ProcListSize = 0;
2468 proc_list_add(pid, task, type, count, other, hostaddr)
2478 for (i = 0; i < ProcListSize; i++)
2480 if (ProcListVec[i].proc_pid == NO_PID)
2483 if (i >= ProcListSize)
2485 /* probe the existing vector to avoid growing infinitely */
2488 /* now scan again */
2489 for (i = 0; i < ProcListSize; i++)
2491 if (ProcListVec[i].proc_pid == NO_PID)
2495 if (i >= ProcListSize)
2497 /* grow process list */
2501 SM_ASSERT(ProcListSize < INT_MAX - PROC_LIST_SEG);
2502 npv = (PROCS_T *) sm_pmalloc_x((sizeof(*npv)) *
2503 (ProcListSize + PROC_LIST_SEG));
2505 /* Block SIGCHLD so reapchild() doesn't mess with us */
2506 chldwasblocked = sm_blocksignal(SIGCHLD);
2507 if (ProcListSize > 0)
2509 memmove(npv, ProcListVec,
2510 ProcListSize * sizeof(PROCS_T));
2511 sm_free(ProcListVec);
2514 /* XXX just use memset() to initialize this part? */
2515 for (i = ProcListSize; i < ProcListSize + PROC_LIST_SEG; i++)
2517 npv[i].proc_pid = NO_PID;
2518 npv[i].proc_task = NULL;
2519 npv[i].proc_type = PROC_NONE;
2522 ProcListSize += PROC_LIST_SEG;
2524 if (chldwasblocked == 0)
2525 (void) sm_releasesignal(SIGCHLD);
2527 ProcListVec[i].proc_pid = pid;
2528 PSTRSET(ProcListVec[i].proc_task, task);
2529 ProcListVec[i].proc_type = type;
2530 ProcListVec[i].proc_count = count;
2531 ProcListVec[i].proc_other = other;
2532 if (hostaddr != NULL)
2533 ProcListVec[i].proc_hostaddr = *hostaddr;
2535 memset(&ProcListVec[i].proc_hostaddr, 0,
2536 sizeof(ProcListVec[i].proc_hostaddr));
2538 /* if process adding itself, it's not a child */
2539 if (pid != CurrentPid)
2541 SM_ASSERT(CurChildren < INT_MAX);
2547 ** PROC_LIST_SET -- set pid task in process list
2550 ** pid -- pid to set
2551 ** task -- task of pid
2558 proc_list_set(pid, task)
2564 for (i = 0; i < ProcListSize; i++)
2566 if (ProcListVec[i].proc_pid == pid)
2568 PSTRSET(ProcListVec[i].proc_task, task);
2575 ** PROC_LIST_DROP -- drop pid from process list
2578 ** pid -- pid to drop
2579 ** st -- process status
2580 ** other -- storage for proc_other (return).
2586 ** May decrease CurChildren, CurRunners, or
2587 ** set RestartRequest or ShutdownRequest.
2589 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2590 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2595 proc_list_drop(pid, st, other)
2601 int type = PROC_NONE;
2603 for (i = 0; i < ProcListSize; i++)
2605 if (ProcListVec[i].proc_pid == pid)
2607 ProcListVec[i].proc_pid = NO_PID;
2608 type = ProcListVec[i].proc_type;
2610 *other = ProcListVec[i].proc_other;
2611 if (CurChildren > 0)
2618 if (type == PROC_CONTROL && WIFEXITED(st))
2620 /* if so, see if we need to restart or shutdown */
2621 if (WEXITSTATUS(st) == EX_RESTART)
2622 RestartRequest = "control socket";
2623 else if (WEXITSTATUS(st) == EX_SHUTDOWN)
2624 ShutdownRequest = "control socket";
2626 else if (type == PROC_QUEUE_CHILD && !WIFSTOPPED(st) &&
2627 ProcListVec[i].proc_other > -1)
2629 /* restart this persistent runner */
2630 mark_work_group_restart(ProcListVec[i].proc_other, st);
2632 else if (type == PROC_QUEUE)
2633 CurRunners -= ProcListVec[i].proc_count;
2637 ** PROC_LIST_CLEAR -- clear the process list
2646 ** Sets CurChildren to zero.
2654 /* start from 1 since 0 is the daemon itself */
2655 for (i = 1; i < ProcListSize; i++)
2656 ProcListVec[i].proc_pid = NO_PID;
2661 ** PROC_LIST_PROBE -- probe processes in the list to see if they still exist
2670 ** May decrease CurChildren.
2681 chldwasblocked = sm_blocksignal(SIGCHLD);
2683 /* start from 1 since 0 is the daemon itself */
2684 for (i = 1; i < ProcListSize; i++)
2686 pid = ProcListVec[i].proc_pid;
2687 if (pid == NO_PID || pid == CurrentPid)
2689 if (kill(pid, 0) < 0)
2692 sm_syslog(LOG_DEBUG, CurEnv->e_id,
2693 "proc_list_probe: lost pid %d",
2694 (int) ProcListVec[i].proc_pid);
2695 ProcListVec[i].proc_pid = NO_PID;
2696 SM_FREE_CLR(ProcListVec[i].proc_task);
2704 if (CurChildren < 0)
2706 if (chldwasblocked == 0)
2707 (void) sm_releasesignal(SIGCHLD);
2708 if (LogLevel > 10 && children != CurChildren && CurrentPid == DaemonPid)
2710 sm_syslog(LOG_ERR, NOQID,
2711 "proc_list_probe: found %d children, expected %d",
2712 children, CurChildren);
2717 ** PROC_LIST_DISPLAY -- display the process list
2720 ** out -- output file pointer
2721 ** prefix -- string to output in front of each line.
2728 proc_list_display(out, prefix)
2734 for (i = 0; i < ProcListSize; i++)
2736 if (ProcListVec[i].proc_pid == NO_PID)
2739 (void) sm_io_fprintf(out, SM_TIME_DEFAULT, "%s%d %s%s\n",
2741 (int) ProcListVec[i].proc_pid,
2742 ProcListVec[i].proc_task != NULL ?
2743 ProcListVec[i].proc_task : "(unknown)",
2744 (OpMode == MD_SMTP ||
2745 OpMode == MD_DAEMON ||
2746 OpMode == MD_ARPAFTP) ? "\r" : "");
2751 ** PROC_LIST_SIGNAL -- send a signal to a type of process in the list
2754 ** type -- type of process to signal
2755 ** signal -- the type of signal to send
2760 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2761 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2766 proc_list_signal(type, signal)
2773 pid_t mypid = getpid();
2775 /* block these signals so that we may signal cleanly */
2776 chldwasblocked = sm_blocksignal(SIGCHLD);
2777 alrmwasblocked = sm_blocksignal(SIGALRM);
2779 /* Find all processes of type and send signal */
2780 for (i = 0; i < ProcListSize; i++)
2782 if (ProcListVec[i].proc_pid == NO_PID ||
2783 ProcListVec[i].proc_pid == mypid)
2785 if (ProcListVec[i].proc_type != type)
2787 (void) kill(ProcListVec[i].proc_pid, signal);
2790 /* restore the signals */
2791 if (alrmwasblocked == 0)
2792 (void) sm_releasesignal(SIGALRM);
2793 if (chldwasblocked == 0)
2794 (void) sm_releasesignal(SIGCHLD);
2798 ** COUNT_OPEN_CONNECTIONS
2801 ** hostaddr - ClientAddress
2804 ** the number of open connections for this client
2809 count_open_connections(hostaddr)
2814 if (hostaddr == NULL)
2817 for (i = 0; i < ProcListSize; i++)
2819 if (ProcListVec[i].proc_pid == NO_PID)
2821 if (hostaddr->sa.sa_family !=
2822 ProcListVec[i].proc_hostaddr.sa.sa_family)
2825 if (hostaddr->sa.sa_family == AF_INET &&
2826 (hostaddr->sin.sin_addr.s_addr ==
2827 ProcListVec[i].proc_hostaddr.sin.sin_addr.s_addr))
2829 #endif /* NETINET */
2831 if (hostaddr->sa.sa_family == AF_INET6 &&
2832 IN6_ARE_ADDR_EQUAL(&(hostaddr->sin6.sin6_addr),
2833 &(ProcListVec[i].proc_hostaddr.sin6.sin6_addr)))
2835 #endif /* NETINET6 */