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.394 2006/05/03 23:55:29 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 all leading backslashes from a string, provided
97 ** the following character is alpha-numerical.
99 ** This is done in place.
102 ** s -- the string to strip.
114 if (s == NULL || *s == '\0')
117 while (*p == '\\' && (p[1] == '\\' || (isascii(p[1]) && isalnum(p[1]))))
126 ** RFC822_STRING -- Checks string for proper RFC822 string quoting.
128 ** Runs through a string and verifies RFC822 special characters
129 ** are only found inside comments, quoted strings, or backslash
130 ** escaped. Also verified balanced quotes and parenthesis.
133 ** s -- the string to modify.
136 ** true iff the string is RFC822 compliant, false otherwise.
152 /* escaped character */
159 else if (commentlev == 0 && *c == '"')
173 else if (commentlev == 0 &&
174 strchr(MustQuoteChars, *c) != NULL)
180 /* unbalanced '"' or '(' */
181 return !quoted && commentlev == 0;
184 ** SHORTEN_RFC822_STRING -- Truncate and rebalance an RFC822 string
186 ** Arbitrarily shorten (in place) an RFC822 string and rebalance
187 ** comments and quotes.
190 ** string -- the string to shorten
191 ** length -- the maximum size, 0 if no maximum
194 ** true if string is changed, false otherwise
197 ** Changes string in place, possibly resulting
198 ** in a shorter string.
202 shorten_rfc822_string(string, length)
206 bool backslash = false;
207 bool modified = false;
214 ** If have to rebalance an already short enough string,
215 ** need to do it within allocated space.
218 slen = strlen(string);
219 if (length == 0 || slen < length)
232 else if (*ptr == '(')
237 else if (*ptr == ')')
239 if (--parencount < 0)
243 /* Inside a comment, quotes don't matter */
244 if (parencount <= 0 && *ptr == '"')
248 /* Check for sufficient space for next character */
249 if (length - (ptr - string) <= (size_t) ((backslash ? 1 : 0) +
253 /* Not enough, backtrack */
256 else if (*ptr == '(' && !quoted)
258 else if (*ptr == '"' && parencount == 0)
266 while (parencount-- > 0)
292 ** FIND_CHARACTER -- find an unquoted character in an RFC822 string
294 ** Find an unquoted, non-commented character in an RFC822
295 ** string and return a pointer to its location in the
299 ** string -- the string to search
300 ** character -- the character to find
303 ** pointer to the character, or
304 ** a pointer to the end of the line if character is not found
308 find_character(string, character)
312 bool backslash = false;
316 while (string != NULL && *string != '\0')
321 if (!quoted && character == '\\' && *string == '\\')
338 if (--parencount < 0)
343 /* Inside a comment, nothing matters */
352 else if (*string == character && !quoted)
357 /* Return pointer to the character */
362 ** CHECK_BODYTYPE -- check bodytype parameter
365 ** bodytype -- bodytype parameter
368 ** BODYTYPE_* according to parameter
373 check_bodytype(bodytype)
376 /* check body type for legality */
377 if (bodytype == NULL)
378 return BODYTYPE_NONE;
379 if (sm_strcasecmp(bodytype, "7BIT") == 0)
380 return BODYTYPE_7BIT;
381 if (sm_strcasecmp(bodytype, "8BITMIME") == 0)
382 return BODYTYPE_8BITMIME;
383 return BODYTYPE_ILLEGAL;
386 #if _FFR_BESTMX_BETTER_TRUNCATION || _FFR_DNSMAP_MULTI
388 ** TRUNCATE_AT_DELIM -- truncate string at a delimiter and append "..."
391 ** str -- string to truncate
392 ** len -- maximum length (including '\0') (0 for unlimited)
393 ** delim -- delimiter character
400 truncate_at_delim(str, len, delim)
407 if (str == NULL || len == 0 || strlen(str) < len)
410 *(str + len - 1) = '\0';
411 while ((p = strrchr(str, delim)) != NULL)
414 if (p - str + 4 < len)
418 (void) sm_strlcat(str, "...", len);
423 /* Couldn't find a place to append "..." */
425 (void) sm_strlcpy(str, "...", len);
429 #endif /* _FFR_BESTMX_BETTER_TRUNCATION || _FFR_DNSMAP_MULTI */
431 ** XALLOC -- Allocate memory, raise an exception on error
434 ** sz -- size of area to allocate.
437 ** pointer to data region.
440 ** SmHeapOutOfMemory (F:sm.heap) -- cannot allocate memory
443 ** Memory is allocated.
448 xalloc_tagged(sz, file, line)
452 #else /* SM_HEAP_CHECK */
455 #endif /* SM_HEAP_CHECK */
461 /* some systems can't handle size zero mallocs */
465 /* scaffolding for testing error handling code */
466 sm_xtrap_raise_x(&SmHeapOutOfMemory);
468 p = sm_malloc_tagged((unsigned) sz, file, line, sm_heap_group());
471 sm_exc_raise_x(&SmHeapOutOfMemory);
476 ** COPYPLIST -- copy list of pointers.
478 ** This routine is the equivalent of strdup for lists of
482 ** list -- list of pointers to copy.
483 ** Must be NULL terminated.
484 ** copycont -- if true, copy the contents of the vector
485 ** (which must be a string) also.
486 ** rpool -- resource pool from which to allocate storage,
494 copyplist(list, copycont, rpool)
500 register char **newvp;
502 for (vp = list; *vp != NULL; vp++)
507 newvp = (char **) sm_rpool_malloc_x(rpool, (vp - list) * sizeof *vp);
508 memmove((char *) newvp, (char *) list, (int) (vp - list) * sizeof *vp);
512 for (vp = newvp; *vp != NULL; vp++)
513 *vp = sm_rpool_strdup_x(rpool, *vp);
519 ** COPYQUEUE -- copy address queue.
521 ** This routine is the equivalent of strdup for address queues;
522 ** addresses marked as QS_IS_DEAD() aren't copied
525 ** addr -- list of address structures to copy.
526 ** rpool -- resource pool from which to allocate storage
533 copyqueue(addr, rpool)
537 register ADDRESS *newaddr;
539 register ADDRESS **tail = &ret;
543 if (!QS_IS_DEAD(addr->q_state))
545 newaddr = (ADDRESS *) sm_rpool_malloc_x(rpool,
547 STRUCTCOPY(*addr, *newaddr);
549 tail = &newaddr->q_next;
558 ** LOG_SENDMAIL_PID -- record sendmail pid and command line.
561 ** e -- the current envelope.
567 ** writes pidfile, logs command line.
568 ** keeps file open and locked to prevent overwrite of active file
571 static SM_FILE_T *Pidf = NULL;
578 char pidpath[MAXPATHLEN];
579 extern char *CommandLineArgs;
581 /* write the pid to the log file for posterity */
582 sff = SFF_NOLINK|SFF_ROOTOK|SFF_REGONLY|SFF_CREAT|SFF_NBLOCK;
583 if (TrustedUid != 0 && RealUid == TrustedUid)
584 sff |= SFF_OPENASROOT;
585 expand(PidFile, pidpath, sizeof pidpath, e);
586 Pidf = safefopen(pidpath, O_WRONLY|O_TRUNC, FileMode, sff);
589 if (errno == EWOULDBLOCK)
590 sm_syslog(LOG_ERR, NOQID,
591 "unable to write pid to %s: file in use by another process",
594 sm_syslog(LOG_ERR, NOQID,
595 "unable to write pid to %s: %s",
596 pidpath, sm_errstring(errno));
600 PidFilePid = getpid();
602 /* write the process id on line 1 */
603 (void) sm_io_fprintf(Pidf, SM_TIME_DEFAULT, "%ld\n",
606 /* line 2 contains all command line flags */
607 (void) sm_io_fprintf(Pidf, SM_TIME_DEFAULT, "%s\n",
611 (void) sm_io_flush(Pidf, SM_TIME_DEFAULT);
614 ** Leave pid file open until process ends
615 ** so it's not overwritten by another
620 sm_syslog(LOG_INFO, NOQID, "started as: %s", CommandLineArgs);
624 ** CLOSE_SENDMAIL_PID -- close sendmail pid file
639 (void) sm_io_close(Pidf, SM_TIME_DEFAULT);
644 ** SET_DELIVERY_MODE -- set and record the delivery mode
647 ** mode -- delivery mode
648 ** e -- the current envelope.
654 ** sets {deliveryMode} macro
658 set_delivery_mode(mode, e)
664 e->e_sendmode = (char) mode;
665 buf[0] = (char) mode;
667 macdefine(&e->e_macro, A_TEMP, macid("{deliveryMode}"), buf);
670 ** SET_OP_MODE -- set and record the op mode
674 ** e -- the current envelope.
680 ** sets {opMode} macro
688 extern ENVELOPE BlankEnvelope;
690 OpMode = (char) mode;
691 buf[0] = (char) mode;
693 macdefine(&BlankEnvelope.e_macro, A_TEMP, MID_OPMODE, buf);
696 ** PRINTAV -- print argument vector.
699 ** fp -- output file pointer.
700 ** av -- argument vector.
717 sm_dprintf("\n\t%08lx=", (unsigned long) *av);
719 (void) sm_io_putc(fp, SM_TIME_DEFAULT, ' ');
722 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '\n');
725 ** XPUTS -- put string doing control escapes.
728 ** fp -- output file pointer.
729 ** s -- string to put.
741 register const char *s;
744 register struct metamac *mp;
745 bool shiftout = false;
746 extern struct metamac MetaMacros[];
747 static SM_DEBUG_T DebugANSI = SM_DEBUG_INITIALIZER("ANSI",
748 "@(#)$Debug: ANSI - enable reverse video in debug output $");
751 ** TermEscape is set here, rather than in main(),
752 ** because ANSI mode can be turned on or off at any time
753 ** if we are in -bt rule testing mode.
756 if (sm_debug_unknown(&DebugANSI))
758 if (sm_debug_active(&DebugANSI, 1))
760 TermEscape.te_rv_on = "\033[7m";
761 TermEscape.te_rv_off = "\033[0m";
765 TermEscape.te_rv_on = "";
766 TermEscape.te_rv_off = "";
772 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s<null>%s",
773 TermEscape.te_rv_on, TermEscape.te_rv_off);
776 while ((c = (*s++ & 0377)) != '\0')
780 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
781 TermEscape.te_rv_off);
788 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
790 TermEscape.te_rv_on);
797 if (c == MACROEXPAND || c == MACRODEXPAND)
799 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT,
801 TermEscape.te_rv_on);
802 if (c == MACRODEXPAND)
803 (void) sm_io_putc(fp,
804 SM_TIME_DEFAULT, '&');
808 if (strchr("=~&?", *s) != NULL)
809 (void) sm_io_putc(fp,
812 if (bitset(0200, *s))
813 (void) sm_io_fprintf(fp,
816 macname(bitidx(*s++)));
818 (void) sm_io_fprintf(fp,
824 for (mp = MetaMacros; mp->metaname != '\0'; mp++)
826 if (bitidx(mp->metaval) == c)
828 (void) sm_io_fprintf(fp,
837 if (c == MATCHCLASS || c == MATCHNCLASS)
839 if (bitset(0200, *s))
840 (void) sm_io_fprintf(fp,
843 macname(bitidx(*s++)));
845 (void) sm_io_fprintf(fp,
850 if (mp->metaname != '\0')
853 /* unrecognized meta character */
854 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%sM-",
855 TermEscape.te_rv_on);
862 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c);
866 /* wasn't a meta-macro -- find another way to print it */
883 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
884 TermEscape.te_rv_on);
889 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '\\');
890 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c);
894 (void) sm_io_putc(fp, SM_TIME_DEFAULT, '^');
895 (void) sm_io_putc(fp, SM_TIME_DEFAULT, c ^ 0100);
899 (void) sm_io_fprintf(fp, SM_TIME_DEFAULT, "%s",
900 TermEscape.te_rv_off);
901 (void) sm_io_flush(fp, SM_TIME_DEFAULT);
904 ** MAKELOWER -- Translate a line into lower case
907 ** p -- the string to translate. If NULL, return is
914 ** String pointed to by p is translated to lower case.
925 for (; (c = *p) != '\0'; p++)
926 if (isascii(c) && isupper(c))
930 ** FIXCRLF -- fix <CR><LF> in line.
932 ** Looks for the <CR><LF> combination and turns it into the
933 ** UNIX canonical <NL> character. It only takes one line,
934 ** i.e., it is assumed that the first <NL> found is the end
938 ** line -- the line to fix.
939 ** stripnl -- if true, strip the newline also.
945 ** line is changed in place.
949 fixcrlf(line, stripnl)
955 p = strchr(line, '\n');
958 if (p > line && p[-1] == '\r')
965 ** PUTLINE -- put a line like fputs obeying SMTP conventions
967 ** This routine always guarantees outputing a newline (or CRLF,
968 ** as appropriate) at the end of the string.
972 ** mci -- the mailer connection information.
975 ** true iff line was written successfully
978 ** output of l to mci->mci_out.
986 return putxline(l, strlen(l), mci, PXLF_MAPFROM);
989 ** PUTXLINE -- putline with flags bits.
991 ** This routine always guarantees outputing a newline (or CRLF,
992 ** as appropriate) at the end of the string.
996 ** len -- the length of the line.
997 ** mci -- the mailer connection information.
998 ** pxflags -- flag bits:
999 ** PXLF_MAPFROM -- map From_ to >From_.
1000 ** PXLF_STRIP8BIT -- strip 8th bit.
1001 ** PXLF_HEADER -- map bare newline in header to newline space.
1002 ** PXLF_NOADDEOL -- don't add an EOL if one wasn't present.
1005 ** true iff line was written successfully
1008 ** output of l to mci->mci_out.
1012 putxline(l, len, mci, pxflags)
1019 register char *p, *end;
1022 /* strip out 0200 bits -- these can look like TELNET protocol */
1023 if (bitset(MCIF_7BIT, mci->mci_flags) ||
1024 bitset(PXLF_STRIP8BIT, pxflags))
1026 register char svchar;
1028 for (p = l; (svchar = *p) != '\0'; ++p)
1029 if (bitset(0200, svchar))
1030 *p = svchar &~ 0200;
1038 /* find the end of the line */
1039 p = memchr(l, '\n', end - l);
1046 if (TrafficLogFile != NULL)
1047 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1048 "%05d >>> ", (int) CurrentPid);
1050 /* check for line overflow */
1051 while (mci->mci_mailer->m_linelimit > 0 &&
1052 (p - l + slop) > mci->mci_mailer->m_linelimit)
1055 register char *q = &l[mci->mci_mailer->m_linelimit - slop - 1];
1057 if (l[0] == '.' && slop == 0 &&
1058 bitnset(M_XDOT, mci->mci_mailer->m_flags))
1060 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1063 if (TrafficLogFile != NULL)
1064 (void) sm_io_putc(TrafficLogFile,
1065 SM_TIME_DEFAULT, '.');
1067 else if (l[0] == 'F' && slop == 0 &&
1068 bitset(PXLF_MAPFROM, pxflags) &&
1069 strncmp(l, "From ", 5) == 0 &&
1070 bitnset(M_ESCFROM, mci->mci_mailer->m_flags))
1072 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1075 if (TrafficLogFile != NULL)
1076 (void) sm_io_putc(TrafficLogFile,
1085 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1086 (unsigned char) *l++) == SM_IO_EOF)
1095 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '!') ==
1097 sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
1098 mci->mci_mailer->m_eol) ==
1100 sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, ' ') ==
1106 if (TrafficLogFile != NULL)
1108 for (l = l_base; l < q; l++)
1109 (void) sm_io_putc(TrafficLogFile,
1112 (void) sm_io_fprintf(TrafficLogFile,
1123 /* output last part */
1124 if (l[0] == '.' && slop == 0 &&
1125 bitnset(M_XDOT, mci->mci_mailer->m_flags))
1127 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '.') ==
1133 if (TrafficLogFile != NULL)
1134 (void) sm_io_putc(TrafficLogFile,
1135 SM_TIME_DEFAULT, '.');
1137 else if (l[0] == 'F' && slop == 0 &&
1138 bitset(PXLF_MAPFROM, pxflags) &&
1139 strncmp(l, "From ", 5) == 0 &&
1140 bitnset(M_ESCFROM, mci->mci_mailer->m_flags))
1142 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT, '>') ==
1148 if (TrafficLogFile != NULL)
1149 (void) sm_io_putc(TrafficLogFile,
1150 SM_TIME_DEFAULT, '>');
1154 if (TrafficLogFile != NULL)
1155 (void) sm_io_putc(TrafficLogFile,
1158 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1159 (unsigned char) *l) == SM_IO_EOF)
1168 if (TrafficLogFile != NULL)
1169 (void) sm_io_putc(TrafficLogFile, SM_TIME_DEFAULT,
1171 if ((!bitset(PXLF_NOADDEOL, pxflags) || !noeol) &&
1172 sm_io_fputs(mci->mci_out, SM_TIME_DEFAULT,
1173 mci->mci_mailer->m_eol) == SM_IO_EOF)
1178 if (l < end && *l == '\n')
1180 if (*++l != ' ' && *l != '\t' && *l != '\0' &&
1181 bitset(PXLF_HEADER, pxflags))
1183 if (sm_io_putc(mci->mci_out, SM_TIME_DEFAULT,
1190 if (TrafficLogFile != NULL)
1191 (void) sm_io_putc(TrafficLogFile,
1192 SM_TIME_DEFAULT, ' ');
1201 ** XUNLINK -- unlink a file, doing logging as appropriate.
1204 ** f -- name of file to unlink.
1207 ** return value of unlink()
1221 sm_syslog(LOG_DEBUG, CurEnv->e_id, "unlink %s", f);
1225 if (i < 0 && LogLevel > 97)
1226 sm_syslog(LOG_DEBUG, CurEnv->e_id, "%s: unlink-fail %d",
1234 ** SFGETS -- "safe" fgets -- times out and ignores random interrupts.
1237 ** buf -- place to put the input line.
1238 ** siz -- size of buf.
1239 ** fp -- file to read from.
1240 ** timeout -- the timeout before error occurs.
1241 ** during -- what we are trying to read (for error messages).
1244 ** NULL on error (including timeout). This may also leave
1245 ** buf containing a null string.
1251 sfgets(buf, siz, fp, timeout, during)
1262 SM_REQUIRE(siz > 0);
1263 SM_REQUIRE(buf != NULL);
1276 /* convert the timeout to sm_io notation */
1277 io_timeout = (timeout <= 0) ? SM_TIME_DEFAULT : timeout * 1000;
1278 while (!sm_io_eof(fp) && !sm_io_error(fp))
1281 p = sm_io_fgets(fp, io_timeout, buf, siz);
1282 if (p == NULL && errno == EAGAIN)
1284 /* The sm_io_fgets() call timedout */
1286 sm_syslog(LOG_NOTICE, CurEnv->e_id,
1287 "timeout waiting for input from %.100s during %s",
1294 if (TrafficLogFile != NULL)
1295 (void) sm_io_fprintf(TrafficLogFile,
1297 "%05d <<< [TIMEOUT]\n",
1302 if (p != NULL || errno != EINTR)
1304 (void) sm_io_clearerr(fp);
1308 /* clean up the books and exit */
1313 if (TrafficLogFile != NULL)
1314 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1320 if (TrafficLogFile != NULL)
1321 (void) sm_io_fprintf(TrafficLogFile, SM_TIME_DEFAULT,
1322 "%05d <<< %s", (int) CurrentPid, buf);
1325 for (p = buf; *p != '\0'; p++)
1328 else if (!HasEightBits)
1330 for (p = buf; *p != '\0'; p++)
1332 if (bitset(0200, *p))
1334 HasEightBits = true;
1342 ** FGETFOLDED -- like fgets, but knows about folded lines.
1345 ** buf -- place to put result.
1346 ** n -- bytes available.
1347 ** f -- file to read from.
1350 ** input line(s) on success, NULL on error or SM_IO_EOF.
1351 ** This will normally be buf -- unless the line is too
1352 ** long, when it will be sm_malloc_x()ed.
1355 ** buf gets lines from f, with continuation lines (lines
1356 ** with leading white space) appended. CRLF's are mapped
1357 ** into single newlines. Any trailing NL is stripped.
1361 fgetfolded(buf, n, f)
1366 register char *p = buf;
1371 SM_REQUIRE(buf != NULL);
1380 while ((i = sm_io_getc(f, SM_TIME_DEFAULT)) != SM_IO_EOF)
1384 i = sm_io_getc(f, SM_TIME_DEFAULT);
1388 (void) sm_io_ungetc(f, SM_TIME_DEFAULT,
1395 /* allocate new space */
1400 if (nn < MEMCHUNKSIZE)
1404 nbp = sm_malloc_x(nn);
1405 memmove(nbp, bp, p - bp);
1416 i = sm_io_getc(f, SM_TIME_DEFAULT);
1418 (void) sm_io_ungetc(f, SM_TIME_DEFAULT, i);
1419 if (i != ' ' && i != '\t')
1431 ** CURTIME -- return current time.
1437 ** the current time.
1449 ** ATOBOOL -- convert a string representation to boolean.
1451 ** Defaults to false
1454 ** s -- string to convert. Takes "tTyY", empty, and NULL as true,
1458 ** A boolean representation of the string.
1465 if (s == NULL || *s == '\0' || strchr("tTyY", *s) != NULL)
1470 ** ATOOCT -- convert a string representation to octal.
1473 ** s -- string to convert.
1476 ** An integer representing the string interpreted as an
1486 while (*s >= '0' && *s <= '7')
1487 i = (i << 3) | (*s++ - '0');
1491 ** BITINTERSECT -- tell if two bitmaps intersect
1494 ** a, b -- the bitmaps in question
1497 ** true if they have a non-null intersection
1508 for (i = BITMAPBYTES / sizeof (int); --i >= 0; )
1510 if ((a[i] & b[i]) != 0)
1516 ** BITZEROP -- tell if a bitmap is all zero
1519 ** map -- the bit map to check
1522 ** true if map is all zero.
1523 ** false if there are any bits set in map.
1532 for (i = BITMAPBYTES / sizeof (int); --i >= 0; )
1540 ** STRCONTAINEDIN -- tell if one string is contained in another
1543 ** icase -- ignore case?
1544 ** a -- possible substring.
1545 ** b -- possible superstring.
1548 ** true if a is contained in b (case insensitive).
1553 strcontainedin(icase, a, b)
1565 if (icase && isascii(c) && isupper(c))
1567 for (; lb-- >= la; b++)
1572 isascii(*b) && isupper(*b) && tolower(*b) != c)
1574 if (sm_strncasecmp(a, b, la) == 0)
1581 if (strncmp(a, b, la) == 0)
1588 ** CHECKFD012 -- check low numbered file descriptors
1590 ** File descriptors 0, 1, and 2 should be open at all times.
1591 ** This routine verifies that, and fixes it if not true.
1594 ** where -- a tag printed if the assertion failed
1607 for (i = 0; i < 3; i++)
1612 ** CHECKFDOPEN -- make sure file descriptor is open -- for extended debugging
1615 ** fd -- file descriptor to check.
1616 ** where -- tag to print on failure.
1623 checkfdopen(fd, where)
1630 if (fstat(fd, &st) < 0 && errno == EBADF)
1632 syserr("checkfdopen(%d): %s not open as expected!", fd, where);
1638 ** CHECKFDS -- check for new or missing file descriptors
1641 ** where -- tag for printing. If null, take a base line.
1647 ** If where is set, shows changes since the last call.
1656 bool printhdr = true;
1657 int save_errno = errno;
1658 static BITMAP256 baseline;
1659 extern int DtableSize;
1661 if (DtableSize > BITMAPBITS)
1666 clrbitmap(baseline);
1668 for (fd = 0; fd < maxfd; fd++)
1672 if (fstat(fd, &stbuf) < 0 && errno != EOPNOTSUPP)
1674 if (!bitnset(fd, baseline))
1676 clrbitn(fd, baseline);
1678 else if (!bitnset(fd, baseline))
1679 setbitn(fd, baseline);
1683 /* file state has changed */
1688 sm_syslog(LOG_DEBUG, CurEnv->e_id,
1693 dumpfd(fd, true, true);
1698 ** PRINTOPENFDS -- print the open file descriptors (for debugging)
1701 ** logit -- if set, send output to syslog; otherwise
1702 ** print for debugging.
1708 #if NETINET || NETINET6
1709 # include <arpa/inet.h>
1710 #endif /* NETINET || NETINET6 */
1717 extern int DtableSize;
1719 for (fd = 0; fd < DtableSize; fd++)
1720 dumpfd(fd, false, logit);
1723 ** DUMPFD -- dump a file descriptor
1726 ** fd -- the file descriptor to dump.
1727 ** printclosed -- if set, print a notification even if
1728 ** it is closed; otherwise print nothing.
1729 ** logit -- if set, use sm_syslog instead of sm_dprintf()
1736 dumpfd(fd, printclosed, logit)
1745 #endif /* S_IFSOCK */
1746 auto SOCKADDR_LEN_T slen;
1750 #else /* STAT64 > 0 */
1752 #endif /* STAT64 > 0 */
1756 (void) sm_snprintf(p, SPACELEFT(buf, p), "%3d: ", fd);
1762 #else /* STAT64 > 0 */
1764 #endif /* STAT64 > 0 */
1769 (void) sm_snprintf(p, SPACELEFT(buf, p),
1771 sm_errstring(errno));
1774 else if (printclosed)
1776 (void) sm_snprintf(p, SPACELEFT(buf, p), "CLOSED");
1782 i = fcntl(fd, F_GETFL, 0);
1785 (void) sm_snprintf(p, SPACELEFT(buf, p), "fl=0x%x, ", i);
1789 (void) sm_snprintf(p, SPACELEFT(buf, p), "mode=%o: ",
1792 switch (st.st_mode & S_IFMT)
1796 (void) sm_snprintf(p, SPACELEFT(buf, p), "SOCK ");
1798 memset(&sa, '\0', sizeof sa);
1800 if (getsockname(fd, &sa.sa, &slen) < 0)
1801 (void) sm_snprintf(p, SPACELEFT(buf, p), "(%s)",
1802 sm_errstring(errno));
1805 hp = hostnamebyanyaddr(&sa);
1812 else if (sa.sa.sa_family == AF_INET)
1813 (void) sm_snprintf(p, SPACELEFT(buf, p),
1814 "%s/%d", hp, ntohs(sa.sin.sin_port));
1815 # endif /* NETINET */
1817 else if (sa.sa.sa_family == AF_INET6)
1818 (void) sm_snprintf(p, SPACELEFT(buf, p),
1819 "%s/%d", hp, ntohs(sa.sin6.sin6_port));
1820 # endif /* NETINET6 */
1822 (void) sm_snprintf(p, SPACELEFT(buf, p),
1826 (void) sm_snprintf(p, SPACELEFT(buf, p), "->");
1829 if (getpeername(fd, &sa.sa, &slen) < 0)
1830 (void) sm_snprintf(p, SPACELEFT(buf, p), "(%s)",
1831 sm_errstring(errno));
1834 hp = hostnamebyanyaddr(&sa);
1841 else if (sa.sa.sa_family == AF_INET)
1842 (void) sm_snprintf(p, SPACELEFT(buf, p),
1843 "%s/%d", hp, ntohs(sa.sin.sin_port));
1844 # endif /* NETINET */
1846 else if (sa.sa.sa_family == AF_INET6)
1847 (void) sm_snprintf(p, SPACELEFT(buf, p),
1848 "%s/%d", hp, ntohs(sa.sin6.sin6_port));
1849 # endif /* NETINET6 */
1851 (void) sm_snprintf(p, SPACELEFT(buf, p),
1855 #endif /* S_IFSOCK */
1858 (void) sm_snprintf(p, SPACELEFT(buf, p), "CHR: ");
1864 (void) sm_snprintf(p, SPACELEFT(buf, p), "BLK: ");
1867 #endif /* S_IFBLK */
1869 #if defined(S_IFIFO) && (!defined(S_IFSOCK) || S_IFIFO != S_IFSOCK)
1871 (void) sm_snprintf(p, SPACELEFT(buf, p), "FIFO: ");
1874 #endif /* defined(S_IFIFO) && (!defined(S_IFSOCK) || S_IFIFO != S_IFSOCK) */
1878 (void) sm_snprintf(p, SPACELEFT(buf, p), "DIR: ");
1881 #endif /* S_IFDIR */
1885 (void) sm_snprintf(p, SPACELEFT(buf, p), "LNK: ");
1888 #endif /* S_IFLNK */
1892 (void) sm_snprintf(p, SPACELEFT(buf, p),
1893 "dev=%d/%d, ino=%llu, nlink=%d, u/gid=%d/%d, ",
1894 major(st.st_dev), minor(st.st_dev),
1895 (ULONGLONG_T) st.st_ino,
1896 (int) st.st_nlink, (int) st.st_uid,
1899 (void) sm_snprintf(p, SPACELEFT(buf, p), "size=%llu",
1900 (ULONGLONG_T) st.st_size);
1906 sm_syslog(LOG_DEBUG, CurEnv ? CurEnv->e_id : NULL,
1909 sm_dprintf("%s\n", buf);
1912 ** SHORTEN_HOSTNAME -- strip local domain information off of hostname.
1915 ** host -- the host to shorten (stripped in place).
1918 ** place where string was truncated, NULL if not truncated.
1922 shorten_hostname(host)
1930 /* strip off final dot */
1932 p = &host[(i == 0) ? 0 : i - 1];
1939 /* see if there is any domain at all -- if not, we are done */
1940 p = strchr(host, '.');
1944 /* yes, we have a domain -- see if it looks like us */
1945 mydom = macvalue('m', CurEnv);
1949 if ((canon ? sm_strcasecmp(p, mydom)
1950 : sm_strncasecmp(p, mydom, i)) == 0 &&
1951 (mydom[i] == '.' || mydom[i] == '\0'))
1959 ** PROG_OPEN -- open a program for reading
1962 ** argv -- the argument list.
1963 ** pfd -- pointer to a place to store the file descriptor.
1964 ** e -- the current envelope.
1967 ** pid of the process -- -1 if it failed.
1971 prog_open(argv, pfd, e)
1982 char buf[MAXPATHLEN];
1983 extern int DtableSize;
1987 syserr("%s: cannot create pipe for stdout", argv[0]);
1993 syserr("%s: cannot fork", argv[0]);
1994 (void) close(fdv[0]);
1995 (void) close(fdv[1]);
2001 (void) close(fdv[1]);
2006 /* Reset global flags */
2007 RestartRequest = NULL;
2008 RestartWorkGroup = false;
2009 ShutdownRequest = NULL;
2011 CurrentPid = getpid();
2014 ** Initialize exception stack and default exception
2015 ** handler for child process.
2018 sm_exc_newthread(fatal_error);
2020 /* child -- close stdin */
2023 /* stdout goes back to parent */
2024 (void) close(fdv[0]);
2025 if (dup2(fdv[1], 1) < 0)
2027 syserr("%s: cannot dup2 for stdout", argv[0]);
2030 (void) close(fdv[1]);
2032 /* stderr goes to transcript if available */
2033 if (e->e_xfp != NULL)
2037 xfd = sm_io_getinfo(e->e_xfp, SM_IO_WHAT_FD, NULL);
2038 if (xfd >= 0 && dup2(xfd, 2) < 0)
2040 syserr("%s: cannot dup2 for stderr", argv[0]);
2045 /* this process has no right to the queue file */
2046 if (e->e_lockfp != NULL)
2050 fd = sm_io_getinfo(e->e_lockfp, SM_IO_WHAT_FD, NULL);
2054 syserr("%s: lockfp does not have a fd", argv[0]);
2057 /* chroot to the program mailer directory, if defined */
2058 if (ProgMailer != NULL && ProgMailer->m_rootdir != NULL)
2060 expand(ProgMailer->m_rootdir, buf, sizeof buf, e);
2061 if (chroot(buf) < 0)
2063 syserr("prog_open: cannot chroot(%s)", buf);
2068 syserr("prog_open: cannot chdir(/)");
2073 /* run as default user */
2075 sm_mbdb_terminate();
2077 (void) sm_memstat_close();
2078 #endif /* _FFR_MEMSTAT */
2079 if (setgid(DefGid) < 0 && geteuid() == 0)
2081 syserr("prog_open: setgid(%ld) failed", (long) DefGid);
2084 if (setuid(DefUid) < 0 && geteuid() == 0)
2086 syserr("prog_open: setuid(%ld) failed", (long) DefUid);
2090 /* run in some directory */
2091 if (ProgMailer != NULL)
2092 p = ProgMailer->m_execdir;
2095 for (; p != NULL; p = q)
2100 expand(p, buf, sizeof buf, e);
2103 if (buf[0] != '\0' && chdir(buf) >= 0)
2108 /* backup directories */
2109 if (chdir("/tmp") < 0)
2113 /* Check safety of program to be run */
2114 sff = SFF_ROOTOK|SFF_EXECOK;
2115 if (!bitnset(DBS_RUNWRITABLEPROGRAM, DontBlameSendmail))
2116 sff |= SFF_NOGWFILES|SFF_NOWWFILES;
2117 if (bitnset(DBS_RUNPROGRAMINUNSAFEDIRPATH, DontBlameSendmail))
2118 sff |= SFF_NOPATHCHECK;
2120 sff |= SFF_SAFEDIRPATH;
2121 ret = safefile(argv[0], DefUid, DefGid, DefUser, sff, 0, NULL);
2123 sm_syslog(LOG_INFO, e->e_id,
2124 "Warning: prog_open: program %s unsafe: %s",
2125 argv[0], sm_errstring(ret));
2127 /* arrange for all the files to be closed */
2128 sm_close_on_exec(STDERR_FILENO + 1, DtableSize);
2130 /* now exec the process */
2131 (void) execve(argv[0], (ARGV_T) argv, (ARGV_T) UserEnviron);
2135 syserr("%s: cannot exec", argv[0]);
2136 if (transienterror(save_errno))
2139 return -1; /* avoid compiler warning on IRIX */
2142 ** GET_COLUMN -- look up a Column in a line buffer
2145 ** line -- the raw text line to search.
2146 ** col -- the column number to fetch.
2147 ** delim -- the delimiter between columns. If null,
2149 ** buf -- the output buffer.
2150 ** buflen -- the length of buf.
2153 ** buf if successful.
2158 get_column(line, col, delim, buf, buflen)
2170 if ((char) delim == '\0')
2171 (void) sm_strlcpy(delimbuf, "\n\t ", sizeof delimbuf);
2174 delimbuf[0] = (char) delim;
2180 return NULL; /* line empty */
2181 if (*p == (char) delim && col == 0)
2182 return NULL; /* first column empty */
2186 if (col == 0 && (char) delim == '\0')
2188 while (*begin != '\0' && isascii(*begin) && isspace(*begin))
2192 for (i = 0; i < col; i++)
2194 if ((begin = strpbrk(begin, delimbuf)) == NULL)
2195 return NULL; /* no such column */
2197 if ((char) delim == '\0')
2199 while (*begin != '\0' && isascii(*begin) && isspace(*begin))
2204 end = strpbrk(begin, delimbuf);
2211 (void) sm_strlcpy(buf, begin, i + 1);
2215 ** CLEANSTRCPY -- copy string keeping out bogus characters
2218 ** t -- "to" string.
2219 ** f -- "from" string.
2220 ** l -- length of space available in "to" string.
2227 cleanstrcpy(t, f, l)
2232 /* check for newlines and log if necessary */
2233 (void) denlstring(f, true, true);
2236 syserr("!cleanstrcpy: length == 0");
2239 while (l > 0 && *f != '\0')
2242 (isalnum(*f) || strchr("!#$%&'*+-./^_`{|}~", *f) != NULL))
2252 ** DENLSTRING -- convert newlines in a string to spaces
2255 ** s -- the input string
2256 ** strict -- if set, don't permit continuation lines.
2257 ** logattacks -- if set, log attempted attacks.
2260 ** A pointer to a version of the string with newlines
2261 ** mapped to spaces. This should be copied.
2265 denlstring(s, strict, logattacks)
2272 static char *bp = NULL;
2276 while ((p = strchr(p, '\n')) != NULL)
2277 if (strict || (*++p != ' ' && *p != '\t'))
2285 /* allocate more space */
2286 char *nbp = sm_pmalloc_x(l);
2293 (void) sm_strlcpy(bp, s, l);
2294 for (p = bp; (p = strchr(p, '\n')) != NULL; )
2299 sm_syslog(LOG_NOTICE, CurEnv->e_id,
2300 "POSSIBLE ATTACK from %.100s: newline in string \"%s\"",
2301 RealHostName == NULL ? "[UNKNOWN]" : RealHostName,
2302 shortenstring(bp, MAXSHORTSTR));
2309 ** STRREPLNONPRT -- replace "unprintable" characters in a string with subst
2312 ** s -- string to manipulate (in place)
2313 ** subst -- character to use as replacement
2316 ** true iff string did not contain "unprintable" characters
2331 if (!(isascii(*s) && isprint(*s)))
2342 ** STR2PRT -- convert "unprintable" characters in a string to \oct
2345 ** s -- string to convert
2348 ** converted string.
2349 ** This is a static local buffer, string must be copied
2350 ** before this function is called again!
2361 static char *buf = NULL;
2366 for (h = s, l = 1; *h != '\0'; h++, l++)
2373 else if (!(isascii(*h) && isprint(*h)))
2383 char *nbuf = sm_pmalloc_x(l);
2390 for (h = buf; *s != '\0' && l > 0; s++, l--)
2393 if (isascii(c) && isprint(c) && c != '\\')
2417 (void) sm_snprintf(h, l, "%03o",
2418 (unsigned int)((unsigned char) c));
2421 ** XXX since l is unsigned this may
2422 ** wrap around if the calculation is screwed
2433 buf[len - 1] = '\0';
2437 ** PATH_IS_DIR -- check to see if file exists and is a directory.
2439 ** There are some additional checks for security violations in
2440 ** here. This routine is intended to be used for the host status
2444 ** pathname -- pathname to check for directory-ness.
2445 ** createflag -- if set, create directory if needed.
2448 ** true -- if the indicated pathname is a directory
2449 ** false -- otherwise
2453 path_is_dir(pathname, createflag)
2457 struct stat statbuf;
2460 if (lstat(pathname, &statbuf) < 0)
2461 #else /* HASLSTAT */
2462 if (stat(pathname, &statbuf) < 0)
2463 #endif /* HASLSTAT */
2465 if (errno != ENOENT || !createflag)
2467 if (mkdir(pathname, 0755) < 0)
2471 if (!S_ISDIR(statbuf.st_mode))
2477 /* security: don't allow writable directories */
2478 if (bitset(S_IWGRP|S_IWOTH, statbuf.st_mode))
2486 ** PROC_LIST_ADD -- add process id to list of our children
2489 ** pid -- pid to add to list.
2490 ** task -- task of pid.
2491 ** type -- type of process.
2492 ** count -- number of processes.
2493 ** other -- other information for this type.
2499 ** May increase CurChildren. May grow ProcList.
2502 typedef struct procs PROCS_T;
2511 SOCKADDR proc_hostaddr;
2514 static PROCS_T *volatile ProcListVec = NULL;
2515 static int ProcListSize = 0;
2518 proc_list_add(pid, task, type, count, other, hostaddr)
2528 for (i = 0; i < ProcListSize; i++)
2530 if (ProcListVec[i].proc_pid == NO_PID)
2533 if (i >= ProcListSize)
2535 /* probe the existing vector to avoid growing infinitely */
2538 /* now scan again */
2539 for (i = 0; i < ProcListSize; i++)
2541 if (ProcListVec[i].proc_pid == NO_PID)
2545 if (i >= ProcListSize)
2547 /* grow process list */
2550 SM_ASSERT(ProcListSize < INT_MAX - PROC_LIST_SEG);
2551 npv = (PROCS_T *) sm_pmalloc_x((sizeof *npv) *
2552 (ProcListSize + PROC_LIST_SEG));
2553 if (ProcListSize > 0)
2555 memmove(npv, ProcListVec,
2556 ProcListSize * sizeof (PROCS_T));
2557 sm_free(ProcListVec);
2560 /* XXX just use memset() to initialize this part? */
2561 for (i = ProcListSize; i < ProcListSize + PROC_LIST_SEG; i++)
2563 npv[i].proc_pid = NO_PID;
2564 npv[i].proc_task = NULL;
2565 npv[i].proc_type = PROC_NONE;
2568 ProcListSize += PROC_LIST_SEG;
2571 ProcListVec[i].proc_pid = pid;
2572 PSTRSET(ProcListVec[i].proc_task, task);
2573 ProcListVec[i].proc_type = type;
2574 ProcListVec[i].proc_count = count;
2575 ProcListVec[i].proc_other = other;
2576 if (hostaddr != NULL)
2577 ProcListVec[i].proc_hostaddr = *hostaddr;
2579 memset(&ProcListVec[i].proc_hostaddr, 0,
2580 sizeof(ProcListVec[i].proc_hostaddr));
2582 /* if process adding itself, it's not a child */
2583 if (pid != CurrentPid)
2585 SM_ASSERT(CurChildren < INT_MAX);
2590 ** PROC_LIST_SET -- set pid task in process list
2593 ** pid -- pid to set
2594 ** task -- task of pid
2601 proc_list_set(pid, task)
2607 for (i = 0; i < ProcListSize; i++)
2609 if (ProcListVec[i].proc_pid == pid)
2611 PSTRSET(ProcListVec[i].proc_task, task);
2617 ** PROC_LIST_DROP -- drop pid from process list
2620 ** pid -- pid to drop
2621 ** st -- process status
2622 ** other -- storage for proc_other (return).
2628 ** May decrease CurChildren, CurRunners, or
2629 ** set RestartRequest or ShutdownRequest.
2631 ** NOTE: THIS CAN BE CALLED FROM A SIGNAL HANDLER. DO NOT ADD
2632 ** ANYTHING TO THIS ROUTINE UNLESS YOU KNOW WHAT YOU ARE
2637 proc_list_drop(pid, st, other)
2643 int type = PROC_NONE;
2645 for (i = 0; i < ProcListSize; i++)
2647 if (ProcListVec[i].proc_pid == pid)
2649 ProcListVec[i].proc_pid = NO_PID;
2650 type = ProcListVec[i].proc_type;
2652 *other = ProcListVec[i].proc_other;
2653 if (CurChildren > 0)
2660 if (type == PROC_CONTROL && WIFEXITED(st))
2662 /* if so, see if we need to restart or shutdown */
2663 if (WEXITSTATUS(st) == EX_RESTART)
2664 RestartRequest = "control socket";
2665 else if (WEXITSTATUS(st) == EX_SHUTDOWN)
2666 ShutdownRequest = "control socket";
2668 else if (type == PROC_QUEUE_CHILD && !WIFSTOPPED(st) &&
2669 ProcListVec[i].proc_other > -1)
2671 /* restart this persistent runner */
2672 mark_work_group_restart(ProcListVec[i].proc_other, st);
2674 else if (type == PROC_QUEUE)
2675 CurRunners -= ProcListVec[i].proc_count;
2678 ** PROC_LIST_CLEAR -- clear the process list
2687 ** Sets CurChildren to zero.
2695 /* start from 1 since 0 is the daemon itself */
2696 for (i = 1; i < ProcListSize; i++)
2697 ProcListVec[i].proc_pid = NO_PID;
2701 ** PROC_LIST_PROBE -- probe processes in the list to see if they still exist
2710 ** May decrease CurChildren.
2721 chldwasblocked = sm_blocksignal(SIGCHLD);
2723 /* start from 1 since 0 is the daemon itself */
2724 for (i = 1; i < ProcListSize; i++)
2726 pid = ProcListVec[i].proc_pid;
2727 if (pid == NO_PID || pid == CurrentPid)
2729 if (kill(pid, 0) < 0)
2732 sm_syslog(LOG_DEBUG, CurEnv->e_id,
2733 "proc_list_probe: lost pid %d",
2734 (int) ProcListVec[i].proc_pid);
2735 ProcListVec[i].proc_pid = NO_PID;
2736 SM_FREE_CLR(ProcListVec[i].proc_task);
2744 if (CurChildren < 0)
2746 if (chldwasblocked == 0)
2747 (void) sm_releasesignal(SIGCHLD);
2748 if (LogLevel > 10 && children != CurChildren && CurrentPid == DaemonPid)
2750 sm_syslog(LOG_ERR, NOQID,
2751 "proc_list_probe: found %d children, expected %d",
2752 children, CurChildren);
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)
2861 if (hostaddr->sa.sa_family !=
2862 ProcListVec[i].proc_hostaddr.sa.sa_family)
2865 if (hostaddr->sa.sa_family == AF_INET &&
2866 (hostaddr->sin.sin_addr.s_addr ==
2867 ProcListVec[i].proc_hostaddr.sin.sin_addr.s_addr))
2869 #endif /* NETINET */
2871 if (hostaddr->sa.sa_family == AF_INET6 &&
2872 IN6_ARE_ADDR_EQUAL(&(hostaddr->sin6.sin6_addr),
2873 &(ProcListVec[i].proc_hostaddr.sin6.sin6_addr)))
2875 #endif /* NETINET6 */