Lines Matching +full:un +full:- +full:approved
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
31 /*-
32 * SPDX-License-Identifier: BSD-2-Clause
34 * Copyright (c) 2018 Prodrive Technologies, https://prodrive-technologies.com/
60 * syslogd -- log system messages
75 * -u and -v by Harlan Stenn.
97 #include <sys/un.h>
150 (((d)->s6_addr32[0] ^ (a)->s6_addr32[0]) & (m)->s6_addr32[0]) == 0 && \
151 (((d)->s6_addr32[1] ^ (a)->s6_addr32[1]) & (m)->s6_addr32[1]) == 0 && \
152 (((d)->s6_addr32[2] ^ (a)->s6_addr32[2]) & (m)->s6_addr32[2]) == 0 && \
153 (((d)->s6_addr32[3] ^ (a)->s6_addr32[3]) & (m)->s6_addr32[3]) == 0 )
209 * Queue of about-to-be dead processes we should watch out for.
253 #define MAXREPEAT (nitems(repeatinterval) - 1)
254 #define REPEATTIME(f) ((f)->f_time + repeatinterval[(f)->f_repeatcount])
256 if (++(f)->f_repeatcount > MAXREPEAT) \
257 (f)->f_repeatcount = MAXREPEAT; \
308 static int mask_C1 = 1; /* mask characters from 0x80 - 0x9F */
373 switch (f->f_type) { in close_filed()
375 if (f->f_addr_fds != NULL) { in close_filed()
376 free(f->f_addrs); in close_filed()
377 for (size_t i = 0; i < f->f_num_addr_fds; ++i) in close_filed()
378 close(f->f_addr_fds[i]); in close_filed()
379 free(f->f_addr_fds); in close_filed()
380 f->f_addr_fds = NULL; in close_filed()
381 f->f_num_addr_fds = 0; in close_filed()
387 f->f_type = F_UNUSED; in close_filed()
390 if (f->f_procdesc != -1) { in close_filed()
395 (void)close(f->f_procdesc); in close_filed()
396 f->f_procdesc = -1; in close_filed()
401 if (f->f_dq != NULL) { in close_filed()
402 deadq_remove(f->f_dq); in close_filed()
403 f->f_dq = NULL; in close_filed()
410 if (f->f_file != -1) in close_filed()
411 (void)close(f->f_file); in close_filed()
412 f->f_file = -1; in close_filed()
421 pe->pe_name = name; in addpeer()
422 pe->pe_serv = serv; in addpeer()
423 pe->pe_mode = mode; in addpeer()
490 for (res = res0; res != NULL; res = res->ai_next) { in addsock()
505 sl->sl_socket = fd; in addfile()
506 sl->sl_recv = socklist_recv_file; in addfile()
517 int ch, ppipe_w = -1, s; in main()
525 != -1) in main()
649 else if (strcmp(optarg, "rfc3164-strict") == 0) in main()
678 if ((argc -= optind) != 0) in main()
698 addsock(pe->pe_name, pe->pe_serv, pe->pe_mode); in main()
708 /* Listen by default: *:514 if no -b flag. */ in main()
711 /* Listen by default: /var/run/log if no -p flag. */ in main()
714 /* Listen by default: /var/run/logpriv if no -S flag. */ in main()
719 consfile.f_file = -1; in main()
720 (void)strlcpy(consfile.f_fname, _PATH_CONSOLE + sizeof(_PATH_DEV) - 1, in main()
724 if (nulldesc == -1) { in main()
738 if (kq == -1) { in main()
744 if (sl->sl_recv == NULL) in main()
746 EV_SET(&ev, sl->sl_socket, EVFILT_READ, EV_ADD, 0, 0, sl); in main()
747 if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1) { in main()
763 if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1) { in main()
768 if (sigaction(sigcatch[i], &act, NULL) == -1) { in main()
784 if (ppipe_w != -1) { in main()
791 ppipe_w = -1; in main()
794 if (kevent(kq, NULL, 0, &ev, 1, NULL) == -1) { in main()
802 if (sl->sl_socket != -1 && sl->sl_recv != NULL) in main()
803 sl->sl_recv(sl); in main()
842 len = recvfrom(sl->sl_socket, line, sizeof(line) - 1, 0, sa, &sslen); in socklist_recv_sock()
845 return (-1); in socklist_recv_sock()
849 return (-1); in socklist_recv_sock()
853 if (sl->sl_sa != NULL && sl->sl_family == AF_LOCAL) in socklist_recv_sock()
860 return (-1); in socklist_recv_sock()
876 sa->sa_family != AF_INET6 || in unmapped()
877 sa->sa_len != sizeof(*sin6)) in unmapped()
880 if (!IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) in unmapped()
885 .sin_port = sin6->sin6_port in unmapped()
887 memcpy(&sin.sin_addr, &sin6->sin6_addr.s6_addr[12], in unmapped()
901 "usage: syslogd [-468ACcdFHknosTuv] [-a allowed_peer]\n" in usage()
902 " [-b bind_address] [-f config_file]\n" in usage()
903 " [-l [mode:]path] [-M fwd_length]\n" in usage()
904 " [-m mark_interval] [-O format] [-P pid_file]\n" in usage()
905 " [-p log_socket] [-S logpriv_socket]\n"); in usage()
911 * TODO: Permit UTF-8 strings that include a BOM per RFC 5424?
920 while ((c = (unsigned char)*in++) != '\0' && q < out + outlen - 4) { in parsemsg_remove_unsafe_characters()
924 *q++ = '-'; in parsemsg_remove_unsafe_characters()
968 if (msg[0] == '-' && msg[1] == ' ') { \ in parsemsg_rfc5424()
971 } else if (msg[0] == '-' && msg[1] == '\0') { \ in parsemsg_rfc5424()
978 /* Parse RFC 3339-like timestamp. */ in parsemsg_rfc5424()
985 v = v * 10 + *msg++ - '0'; \ in parsemsg_rfc5424()
993 timestamp_remote.tm.tm_year -= 1900; in parsemsg_rfc5424()
994 PARSE_CHAR("TIMESTAMP", '-'); in parsemsg_rfc5424()
996 --timestamp_remote.tm.tm_mon; in parsemsg_rfc5424()
997 PARSE_CHAR("TIMESTAMP", '-'); in parsemsg_rfc5424()
1015 timestamp_remote.usec += (*msg++ - '0') * i; in parsemsg_rfc5424()
1026 FAIL_IF("TIMESTAMP", *msg != '-' && *msg != '+'); in parsemsg_rfc5424()
1027 sign = *msg++ == '-' ? -1 : 1; in parsemsg_rfc5424()
1047 msg[-1] = '\0'; \ in parsemsg_rfc5424()
1052 PARSE_STRING("APP-NAME", app_name); in parsemsg_rfc5424()
1065 FAIL_IF("STRUCTURED-NAME", start == msg); \ in parsemsg_rfc5424()
1069 /* SD-ELEMENT. */ in parsemsg_rfc5424()
1072 /* SD-ID. */ in parsemsg_rfc5424()
1074 /* SD-PARAM. */ in parsemsg_rfc5424()
1077 /* PARAM-NAME. */ in parsemsg_rfc5424()
1079 PARSE_CHAR("STRUCTURED-NAME", '='); in parsemsg_rfc5424()
1080 PARSE_CHAR("STRUCTURED-NAME", '"'); in parsemsg_rfc5424()
1082 FAIL_IF("STRUCTURED-NAME", in parsemsg_rfc5424()
1085 FAIL_IF("STRUCTURED-NAME", in parsemsg_rfc5424()
1092 PARSE_CHAR("STRUCTURED-NAME", ']'); in parsemsg_rfc5424()
1094 PARSE_CHAR("STRUCTURED-NAME", ' '); in parsemsg_rfc5424()
1095 msg[-1] = '\0'; in parsemsg_rfc5424()
1126 "_-/"); in parsemsg_rfc3164_get_app_name_procid()
1152 procid_begin == NULL ? 0 : procid_begin - msg; in parsemsg_rfc3164_get_app_name_procid()
1246 for (year = tm_now.tm_year + 1;; --year) { in parsemsg_rfc3164()
1247 assert(year >= tm_now.tm_year - 1); in parsemsg_rfc3164()
1250 timestamp_remote.tm.tm_isdst = -1; in parsemsg_rfc3164()
1304 i = -1; in parsemsg()
1352 i = read(sl->sl_socket, line + len, MAXLINE - 1 - len); in socklist_recv_file()
1358 close(sl->sl_socket); in socklist_recv_file()
1359 sl->sl_socket = -1; in socklist_recv_file()
1369 if (len >= MAXLINE - 1) { in socklist_recv_file()
1420 * Return a non-0 value if the message must be ignored
1434 case '-': in skip_message()
1449 prev = (s == spec ? ',' : *(s - 1)); in skip_message()
1465 * Return a non-0 value if the message must be ignored
1472 const int exclude = ((filter->cmp_flags & FILT_FLAG_EXCLUDE) > 0); in evaluate_prop_filter()
1476 return (-1); in evaluate_prop_filter()
1478 if (filter->cmp_type == FILT_CMP_REGEX) { in evaluate_prop_filter()
1479 if (regexec(filter->pflt_re, value, 0, NULL, 0) == 0) in evaluate_prop_filter()
1488 if (filter->cmp_type == FILT_CMP_EQUAL && in evaluate_prop_filter()
1489 valuelen != strlen(filter->pflt_strval)) in evaluate_prop_filter()
1492 if (filter->cmp_flags & FILT_FLAG_ICASE) in evaluate_prop_filter()
1493 s = strcasestr(value, filter->pflt_strval); in evaluate_prop_filter()
1495 s = strstr(value, filter->pflt_strval); in evaluate_prop_filter()
1501 * valuelen == filter->pflt_strlen in evaluate_prop_filter()
1506 switch (filter->cmp_type) { in evaluate_prop_filter()
1523 return (-1); in evaluate_prop_filter()
1600 app_name == NULL ? "-" : app_name, procid == NULL ? "-" : procid, in logmsg()
1601 msgid == NULL ? "-" : msgid, in logmsg()
1602 structured_data == NULL ? "-" : structured_data, msg); in logmsg()
1606 if (!(((f->f_pcmp[fac] & PRI_EQ) && (f->f_pmask[fac] == prilev)) in logmsg()
1607 ||((f->f_pcmp[fac] & PRI_LT) && (f->f_pmask[fac] < prilev)) in logmsg()
1608 ||((f->f_pcmp[fac] & PRI_GT) && (f->f_pmask[fac] > prilev)) in logmsg()
1610 || f->f_pmask[fac] == INTERNAL_NOPRI) in logmsg()
1614 if (skip_message(hostname, f->f_host, 0)) in logmsg()
1619 if (skip_message(kernel_app_name, f->f_program, 1)) in logmsg()
1622 f->f_program, 1)) in logmsg()
1626 if (f->f_prop_filter != NULL && in logmsg()
1627 f->f_prop_filter->prop_type != FILT_PROP_NOOP) { in logmsg()
1628 switch (f->f_prop_filter->prop_type) { in logmsg()
1630 if (evaluate_prop_filter(f->f_prop_filter, in logmsg()
1635 if (evaluate_prop_filter(f->f_prop_filter, in logmsg()
1640 if (evaluate_prop_filter(f->f_prop_filter, in logmsg()
1650 if (f->f_type == F_CONSOLE && (flags & IGN_CONS)) in logmsg()
1654 if ((flags & MARK) && (now - f->f_time) < MarkInterval / 2) in logmsg()
1660 if (no_compress - (f->f_type != F_PIPE) < 1 && in logmsg()
1661 (flags & MARK) == 0 && savedlen == f->f_prevlen && in logmsg()
1662 strcmp(saved, f->f_prevline) == 0) { in logmsg()
1663 f->f_lasttime = *timestamp; in logmsg()
1664 f->f_prevcount++; in logmsg()
1666 f->f_prevcount, (long)(now - f->f_time), in logmsg()
1667 repeatinterval[f->f_repeatcount]); in logmsg()
1680 if (f->f_prevcount) in logmsg()
1682 f->f_repeatcount = 0; in logmsg()
1683 f->f_prevpri = pri; in logmsg()
1684 f->f_lasttime = *timestamp; in logmsg()
1685 static_assert(sizeof(f->f_prevline) == sizeof(saved), in logmsg()
1687 (void)strcpy(f->f_prevline, saved); in logmsg()
1688 f->f_prevlen = savedlen; in logmsg()
1701 if (f->f_type == F_FILE && in dofsync()
1702 (f->f_flags & FFLAG_NEEDSYNC) != 0) { in dofsync()
1703 f->f_flags &= ~FFLAG_NEEDSYNC; in dofsync()
1704 (void)fsync(f->f_file); in dofsync()
1714 il->iovcnt = 0; in iovlist_init()
1715 il->totalsize = 0; in iovlist_init()
1724 if (il->iovcnt < nitems(il->iov)) { in iovlist_append()
1726 il->iov[il->iovcnt++] = (struct iovec){ in iovlist_append()
1730 il->totalsize += size; in iovlist_append()
1741 while (il->totalsize > size) { in iovlist_truncate()
1742 diff = il->totalsize - size; in iovlist_truncate()
1743 last = &il->iov[il->iovcnt - 1]; in iovlist_truncate()
1744 if (diff >= last->iov_len) { in iovlist_truncate()
1746 --il->iovcnt; in iovlist_truncate()
1747 il->totalsize -= last->iov_len; in iovlist_truncate()
1750 last->iov_len -= diff; in iovlist_truncate()
1751 il->totalsize -= diff; in iovlist_truncate()
1762 switch (f->f_type) { in fprintlog_write()
1767 int domain, sockfd = f->f_addr_fds[0]; in fprintlog_write()
1774 printf(" %s", f->f_hname); in fprintlog_write()
1811 for (size_t i = 0; i < f->f_num_addr_fds; ++i) { in fprintlog_write()
1813 .msg_iov = il->iov, in fprintlog_write()
1814 .msg_iovlen = il->iovcnt, in fprintlog_write()
1817 lsent = sendmsg(f->f_addr_fds[i], &msg, 0); in fprintlog_write()
1818 if (lsent == (ssize_t)il->totalsize && !send_to_all) in fprintlog_write()
1821 dprintf("lsent/totalsize: %zd/%zu\n", lsent, il->totalsize); in fprintlog_write()
1822 if (lsent != (ssize_t)il->totalsize) { in fprintlog_write()
1844 f->f_type = F_UNUSED; in fprintlog_write()
1852 dprintf(" %s\n", f->f_fname); in fprintlog_write()
1854 if (writev(f->f_file, il->iov, il->iovcnt) < 0) { in fprintlog_write()
1864 logerror(f->f_fname); in fprintlog_write()
1866 } else if ((flags & SYNC_FILE) && (f->f_flags & FFLAG_SYNC)) { in fprintlog_write()
1867 f->f_flags |= FFLAG_NEEDSYNC; in fprintlog_write()
1873 dprintf(" %s\n", f->f_pname); in fprintlog_write()
1875 if (f->f_procdesc == -1) { in fprintlog_write()
1885 f->f_file = cap_p_open(cap_syslogd, i, f->f_pname, in fprintlog_write()
1886 &f->f_procdesc); in fprintlog_write()
1887 if (f->f_file < 0) { in fprintlog_write()
1888 logerror(f->f_pname); in fprintlog_write()
1891 EV_SET(&ev, f->f_procdesc, EVFILT_PROCDESC, EV_ADD, in fprintlog_write()
1893 if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1) { in fprintlog_write()
1898 if (writev(f->f_file, il->iov, il->iovcnt) < 0) { in fprintlog_write()
1899 logerror(f->f_pname); in fprintlog_write()
1900 f->f_dq = deadq_enter(f->f_procdesc); in fprintlog_write()
1912 dprintf(" %s%s\n", _PATH_DEV, f->f_fname); in fprintlog_write()
1915 if ((msgret = cap_ttymsg(cap_syslogd, il->iov, il->iovcnt, in fprintlog_write()
1916 f->f_fname, 10))) { in fprintlog_write()
1917 f->f_type = F_UNUSED; in fprintlog_write()
1926 cap_wallmsg(cap_syslogd, f, il->iov, il->iovcnt); in fprintlog_write()
1944 if (f->f_type == F_WALL) in fprintlog_rfc5424()
1947 snprintf(priority_number, sizeof(priority_number), "%d", f->f_prevpri); in fprintlog_rfc5424()
1951 &f->f_lasttime.tm) == sizeof(timebuf) - 2) { in fprintlog_rfc5424()
1959 usec = f->f_lasttime.usec; in fprintlog_rfc5424()
1960 for (i = 25; i >= 20; --i) { in fprintlog_rfc5424()
1966 iovlist_append(&il, "-"); in fprintlog_rfc5424()
1970 iovlist_append(&il, app_name == NULL ? "-" : app_name); in fprintlog_rfc5424()
1972 iovlist_append(&il, procid == NULL ? "-" : procid); in fprintlog_rfc5424()
1974 iovlist_append(&il, msgid == NULL ? "-" : msgid); in fprintlog_rfc5424()
1976 iovlist_append(&il, structured_data == NULL ? "-" : structured_data); in fprintlog_rfc5424()
1995 &f->f_lasttime.tm) == 0) in fprintlog_rfc3164()
1999 switch (f->f_type) { in fprintlog_rfc3164()
2004 f->f_prevpri); in fprintlog_rfc3164()
2036 facility = f->f_prevpri & LOG_FACMASK; in fprintlog_rfc3164()
2039 for (c = facilitynames; c->c_name; c++) { in fprintlog_rfc3164()
2040 if (c->c_val == facility) { in fprintlog_rfc3164()
2041 iovlist_append(&il, c->c_name); in fprintlog_rfc3164()
2056 priority = LOG_PRI(f->f_prevpri); in fprintlog_rfc3164()
2059 for (c = prioritynames; c->c_name; c++) { in fprintlog_rfc3164()
2060 if (c->c_val == priority) { in fprintlog_rfc3164()
2061 iovlist_append(&il, c->c_name); in fprintlog_rfc3164()
2102 dprintf("Logging to %s", TypeNames[f->f_type]); in fprintlog_first()
2103 f->f_time = now; in fprintlog_first()
2104 f->f_prevcount = 0; in fprintlog_first()
2105 if (f->f_type == F_UNUSED) { in fprintlog_first()
2126 assert(f->f_prevcount > 0); in fprintlog_successive()
2128 f->f_prevcount); in fprintlog_successive()
2134 * WALLMSG -- Write a message to the world at large
2137 * world, or a list of approved users.
2155 if (ut->ut_type != USER_PROCESS) in wallmsg()
2157 if (f->f_type == F_WALL) { in wallmsg()
2158 if ((p = ttymsg(iov, iovlen, ut->ut_line, in wallmsg()
2165 if (!f->f_uname[i][0]) in wallmsg()
2167 if (!strcmp(f->f_uname[i], ut->ut_user)) { in wallmsg()
2168 if ((p = ttymsg_check(iov, iovlen, ut->ut_line, in wallmsg()
2211 dprintf("cvthname(%d) len = %d\n", f->sa_family, f->sa_len); in cvthname()
2212 error = cap_getnameinfo(cap_net, f, f->sa_len, ip, sizeof(ip), NULL, 0, in cvthname()
2223 error = cap_getnameinfo(cap_net, f, f->sa_len, hname, sizeof(hname), in cvthname()
2230 if (hl > 0 && hname[hl-1] == '.') in cvthname()
2231 hname[--hl] = '\0'; in cvthname()
2260 recursed--; in logerror()
2272 if (f->f_prevcount) in die()
2275 if (f->f_type == F_PIPE) in die()
2285 if (sl->sl_sa != NULL && sl->sl_family == AF_LOCAL) { in die()
2286 if (unlinkat(sl->sl_dirfd, sl->sl_name, 0) == -1) { in die()
2287 dprintf("Failed to unlink %s: %s", sl->sl_name, in die()
2303 if (dp->d_name[0] == '.') in configfiles()
2306 ext_len = sizeof(include_ext) -1; in configfiles()
2308 if (dp->d_namlen <= ext_len) in configfiles()
2311 p = &dp->d_name[dp->d_namlen - ext_len]; in configfiles()
2335 include_len = sizeof(include_str) - 1; in parseconfigfile()
2341 * check for end-of-section, comments, strip off trailing in parseconfigfile()
2361 if (nents == -1) { in parseconfigfile()
2368 ent[i]->d_name) >= (int)sizeof(file)) { in parseconfigfile()
2370 "'%s/%s'\n", p, ent[i]->d_name); in parseconfigfile()
2387 if (*p == '\0' || strchr("!+-:", *p) == NULL) in parseconfigfile()
2390 if (*p == '+' || *p == '-') { in parseconfigfile()
2400 for (i = 1; i < MAXHOSTNAMELEN - 1; i++) { in parseconfigfile()
2401 if (!isalnum(*p) && *p != '.' && *p != '-' in parseconfigfile()
2417 for (i = 0; i < LINE_MAX - 1; i++) { in parseconfigfile()
2439 if (*(p - 1) == '\\') { in parseconfigfile()
2440 strcpy(p - 1, p); in parseconfigfile()
2441 p--; in parseconfigfile()
2447 for (i = strlen(cline) - 1; i >= 0 && isspace(cline[i]); i--) in parseconfigfile()
2511 if (f->f_prevcount) in closelogfiles()
2514 switch (f->f_type) { in closelogfiles()
2522 if (f->f_procdesc != -1) { in closelogfiles()
2528 EV_SET(&ev, f->f_procdesc, EVFILT_PROCDESC, in closelogfiles()
2530 if (kevent(kq, &ev, 1, NULL, 0, NULL) == -1) { in closelogfiles()
2542 if (f->f_prop_filter) { in closelogfiles()
2543 switch (f->f_prop_filter->cmp_type) { in closelogfiles()
2545 regfree(f->f_prop_filter->pflt_re); in closelogfiles()
2546 free(f->f_prop_filter->pflt_re); in closelogfiles()
2551 free(f->f_prop_filter->pflt_strval); in closelogfiles()
2554 free(f->f_prop_filter); in closelogfiles()
2581 if (cap_net_limit(limit) == -1) in syslogd_cap_enter()
2585 if (caph_enter_casper() == -1) in syslogd_cap_enter()
2591 * INIT -- Initialize syslogd from configuration table
2663 if (f->f_pmask[i] == INTERNAL_NOPRI) in init()
2666 printf("%d ", f->f_pmask[i]); in init()
2667 printf("%s: ", TypeNames[f->f_type]); in init()
2668 switch (f->f_type) { in init()
2670 printf("%s", f->f_fname); in init()
2675 printf("%s%s", _PATH_DEV, f->f_fname); in init()
2679 int domain, sockfd = f->f_addr_fds[0]; in init()
2713 printf("%s:%d", f->f_hname, port); in init()
2715 printf("%s", f->f_hname); in init()
2721 printf("%s", f->f_pname); in init()
2725 for (i = 0; i < MAXUNAMES && *f->f_uname[i]; i++) in init()
2726 printf("%s, ", f->f_uname[i]); in init()
2731 if (*f->f_program != '\0') in init()
2732 printf(" (%s)", f->f_program); in init()
2765 * Compile property-based filter.
2785 * 'hostname, icase_ereregex, "^server-(dcA|podB)-rack1[0-9]{2}\\..*"' in prop_filter_compile()
2822 if (strncasecmp(argv[1], "icase_", (sizeof("icase_") - 1)) == 0) { in prop_filter_compile()
2824 argv[1] += sizeof("icase_") - 1; in prop_filter_compile()
2951 for (i = strlen(buf) - 1; i >= 0 && buf[i] == ' '; i--) in parse_selector()
2973 f->f_pmask[i] = pri; in parse_selector()
2974 f->f_pcmp[i] = pri_cmp; in parse_selector()
2982 f->f_pmask[i >> 3] = pri; in parse_selector()
2983 f->f_pcmp[i >> 3] = pri_cmp; in parse_selector()
2999 return (-1); in maybe_dup_forw_socket()
3013 if (memcmp(&forw[j].raddr, rsa, rsa->sa_len) != 0 || in maybe_dup_forw_socket()
3014 memcmp(&forw[j].laddr, lsa, lsa->sa_len) != 0) in maybe_dup_forw_socket()
3024 return (-1); in maybe_dup_forw_socket()
3037 s = socket(ai->ai_family, ai->ai_socktype, 0); in make_forw_socket()
3044 if (bind(s, lai->ai_addr, lai->ai_addrlen) < 0) in make_forw_socket()
3047 if (connect(s, ai->ai_addr, ai->ai_addrlen) < 0) { in make_forw_socket()
3051 s1 = maybe_dup_forw_socket(nvl, ai->ai_addr, in make_forw_socket()
3052 lai->ai_addr); in make_forw_socket()
3061 /* Make it a write-only socket. */ in make_forw_socket()
3075 f->f_num_addr_fds = 0; in make_forw_socket_array()
3078 for (ai = res; ai != NULL; ai = ai->ai_next) { in make_forw_socket_array()
3084 if (boundsock->sl_ai.ai_family == ai->ai_family) in make_forw_socket_array()
3089 f->f_num_addr_fds += count; in make_forw_socket_array()
3092 f->f_addr_fds = calloc(f->f_num_addr_fds, sizeof(*f->f_addr_fds)); in make_forw_socket_array()
3093 f->f_addrs = calloc(f->f_num_addr_fds, sizeof(*f->f_addrs)); in make_forw_socket_array()
3094 if (f->f_addr_fds == NULL || f->f_addrs == NULL) in make_forw_socket_array()
3104 for (ai = res; ai != NULL; ai = ai->ai_next) { in make_forw_socket_array()
3110 if (boundsock->sl_ai.ai_family == in make_forw_socket_array()
3111 ai->ai_family) { in make_forw_socket_array()
3112 memcpy(&f->f_addrs[i].raddr, ai->ai_addr, in make_forw_socket_array()
3113 ai->ai_addrlen); in make_forw_socket_array()
3114 memcpy(&f->f_addrs[i].laddr, in make_forw_socket_array()
3115 boundsock->sl_ai.ai_addr, in make_forw_socket_array()
3116 boundsock->sl_ai.ai_addrlen); in make_forw_socket_array()
3117 f->f_addr_fds[i++] = make_forw_socket(nvl, ai, in make_forw_socket_array()
3118 &boundsock->sl_ai); in make_forw_socket_array()
3123 memcpy(&f->f_addrs[i].raddr, ai->ai_addr, in make_forw_socket_array()
3124 ai->ai_addrlen); in make_forw_socket_array()
3125 f->f_addr_fds[i++] = make_forw_socket(nvl, ai, NULL); in make_forw_socket_array()
3128 assert(i == f->f_num_addr_fds); in make_forw_socket_array()
3140 if (*p == '-') { in parse_action()
3146 f->f_file = -1; in parse_action()
3156 i = sizeof(f->f_hname); in parse_action()
3157 tp = f->f_hname; in parse_action()
3168 while (*p && (*p != endkey) && (i-- > 0)) { in parse_action()
3185 error = getaddrinfo(f->f_hname, p ? p : "syslog", &hints, &res); in parse_action()
3192 f->f_type = F_FORW; in parse_action()
3196 if ((f->f_file = open(p, logflags, 0600)) < 0) { in parse_action()
3197 f->f_type = F_UNUSED; in parse_action()
3202 f->f_flags |= FFLAG_SYNC; in parse_action()
3203 if (isatty(f->f_file)) { in parse_action()
3205 f->f_type = F_CONSOLE; in parse_action()
3207 f->f_type = F_TTY; in parse_action()
3208 (void)strlcpy(f->f_fname, p + sizeof(_PATH_DEV) - 1, in parse_action()
3209 sizeof(f->f_fname)); in parse_action()
3211 (void)strlcpy(f->f_fname, p, sizeof(f->f_fname)); in parse_action()
3212 f->f_type = F_FILE; in parse_action()
3217 f->f_procdesc = -1; in parse_action()
3218 (void)strlcpy(f->f_pname, p + 1, sizeof(f->f_pname)); in parse_action()
3219 f->f_type = F_PIPE; in parse_action()
3223 f->f_type = F_WALL; in parse_action()
3230 (void)strncpy(f->f_uname[i], p, MAXLOGNAME - 1); in parse_action()
3231 if ((q - p) >= MAXLOGNAME) in parse_action()
3232 f->f_uname[i][MAXLOGNAME - 1] = '\0'; in parse_action()
3234 f->f_uname[i][q - p] = '\0'; in parse_action()
3239 f->f_type = F_USERS; in parse_action()
3268 if (hl > 0 && f.f_host[hl-1] == '.') in cfline()
3269 f.f_host[--hl] = '\0'; in cfline()
3317 for (p = buf; *name && p < &buf[sizeof(buf) - 1]; p++, name++) { in decode()
3324 for (c = codetab; c->c_name; c++) in decode()
3325 if (!strcmp(buf, c->c_name)) in decode()
3326 return (c->c_val); in decode()
3328 return (-1); in decode()
3341 "-- MARK --", MARK); in markit()
3346 if (f->f_prevcount && now >= REPEATTIME(f)) { in markit()
3348 TypeNames[f->f_type], f->f_prevcount, in markit()
3349 repeatinterval[f->f_repeatcount]); in markit()
3357 switch (dq->dq_timeout) { in markit()
3360 (void)pdkill(dq->dq_procdesc, SIGKILL); in markit()
3364 (void)pdkill(dq->dq_procdesc, SIGTERM); in markit()
3367 dq->dq_timeout--; in markit()
3384 if (pipe(pipefd) == -1) { in waitdaemon()
3389 if (pid == -1) { in waitdaemon()
3397 if (events == -1) in waitdaemon()
3413 if (setsid() == -1) { in waitdaemon()
3449 int masklen = -1; in allowaddr()
3472 ap->port = 0; in allowaddr()
3474 ap->port = ntohs(se->s_port); in allowaddr()
3476 ap->port = strtol(cp1, &cp2, 0); in allowaddr()
3483 ap->port = ntohs(se->s_port); in allowaddr()
3486 ap->port = 514; in allowaddr()
3497 cp2 = s + strlen(s) - 1; in allowaddr()
3514 ap->isnumeric = true; in allowaddr()
3515 memcpy(&ap->a_addr, res->ai_addr, res->ai_addrlen); in allowaddr()
3516 ap->a_mask = (struct sockaddr_storage){ in allowaddr()
3517 .ss_family = res->ai_family, in allowaddr()
3518 .ss_len = res->ai_addrlen in allowaddr()
3520 switch (res->ai_family) { in allowaddr()
3523 maskp = &sstosin(&ap->a_mask)->sin_addr.s_addr; in allowaddr()
3524 addrp = &sstosin(&ap->a_addr)->sin_addr.s_addr; in allowaddr()
3537 *maskp = htonl(~((1 << (32 - masklen)) - 1)); in allowaddr()
3552 mask6p = (uint32_t *)&sstosin6(&ap->a_mask)->sin6_addr.s6_addr32[0]; in allowaddr()
3553 addr6p = (uint32_t *)&sstosin6(&ap->a_addr)->sin6_addr.s6_addr32[0]; in allowaddr()
3564 masklen -= 32; in allowaddr()
3575 ap->isnumeric = false; in allowaddr()
3576 ap->a_name = s; in allowaddr()
3582 --s; in allowaddr()
3590 if (ap->isnumeric) { in allowaddr()
3592 getnameinfo(sstosa(&ap->a_addr), in allowaddr()
3593 (sstosa(&ap->a_addr))->sa_len, in allowaddr()
3596 getnameinfo(sstosa(&ap->a_mask), in allowaddr()
3597 (sstosa(&ap->a_mask))->sa_len, in allowaddr()
3601 printf("domainname = %s; ", ap->a_name); in allowaddr()
3603 printf("port = %d\n", ap->port); in allowaddr()
3649 if (cap_getnameinfo(cap_net, sa, sa->sa_len, ip, sizeof(ip), port, in validate()
3660 if (ap->port != 0 && ap->port != sport) { in validate()
3666 if (ap->isnumeric) { in validate()
3667 if (ap->a_addr.ss_family != sa->sa_family) { in validate()
3672 else if (ap->a_addr.ss_family == AF_INET) { in validate()
3674 a4p = satosin(&ap->a_addr); in validate()
3675 m4p = satosin(&ap->a_mask); in validate()
3676 if ((sin4->sin_addr.s_addr & m4p->sin_addr.s_addr) in validate()
3677 != a4p->sin_addr.s_addr) { in validate()
3684 else if (ap->a_addr.ss_family == AF_INET6) { in validate()
3686 a6p = satosin6(&ap->a_addr); in validate()
3687 m6p = satosin6(&ap->a_mask); in validate()
3688 if (a6p->sin6_scope_id != 0 && in validate()
3689 sin6->sin6_scope_id != a6p->sin6_scope_id) { in validate()
3693 if (!IN6_ARE_MASKED_ADDR_EQUAL(&sin6->sin6_addr, in validate()
3694 &a6p->sin6_addr, &m6p->sin6_addr)) { in validate()
3703 if (fnmatch(ap->a_name, name, FNM_NOESCAPE) == in validate()
3730 char *argv[4]; /* sh -c cmd NULL */ in p_open()
3732 if (pipe(pfd) == -1) in p_open()
3733 return (-1); in p_open()
3736 case -1: in p_open()
3737 return (-1); in p_open()
3742 argv[1] = strdup("-c"); in p_open()
3751 if (sigaction(sigcatch[i], &act, NULL) == -1) in p_open()
3773 if (fcntl(pfd[1], F_SETFL, O_NONBLOCK) == -1) { in p_open()
3775 dprintf("Warning: cannot change pipe to PID %d to non-blocking" in p_open()
3787 if (pd == -1) in deadq_enter()
3796 dq->dq_procdesc = pd; in deadq_enter()
3797 dq->dq_timeout = DQ_TIMO_INIT; in deadq_enter()
3827 if (pdgetpid(pd, &pid) == -1) in log_deadchild()
3831 pid, f->f_pname, reason, code); in log_deadchild()
3842 if (ai->ai_family != AF_LOCAL && SecureMode > 1) { in socksetup()
3846 if (family != AF_UNSPEC && ai->ai_family != AF_LOCAL && in socksetup()
3847 ai->ai_family != family) in socksetup()
3850 s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); in socksetup()
3856 if (ai->ai_family == AF_INET6) { in socksetup()
3873 * Bind INET and UNIX-domain sockets. in socksetup()
3875 * A UNIX-domain socket is always bound to a pathname in socksetup()
3876 * regardless of -N flag. in socksetup()
3885 if (ai->ai_family == AF_LOCAL) in socksetup()
3887 if (ai->ai_family == AF_LOCAL || NoBind == 0 || name != NULL) { in socksetup()
3891 if (ai->ai_family == AF_LOCAL && fchmod(s, mode) < 0) { in socksetup()
3910 error = bind(s, ai->ai_addr, ai->ai_addrlen); in socksetup()
3917 if (ai->ai_family == AF_LOCAL || SecureMode == 0) in socksetup()
3923 if (SecureMode && (ai->ai_family == AF_INET || in socksetup()
3924 ai->ai_family == AF_INET6)) { in socksetup()
3937 /* Copy *ai->ai_addr to the tail of struct socklist if any. */ in socksetup()
3938 sl = calloc(1, sizeof(*sl) + ai->ai_addrlen); in socksetup()
3941 sl->sl_socket = s; in socksetup()
3942 if (ai->ai_family == AF_LOCAL) { in socksetup()
3946 sl->sl_name = strdup(basename(name2)); in socksetup()
3947 sl->sl_dirfd = open(dirname(name2), O_DIRECTORY); in socksetup()
3948 if (sl->sl_name == NULL || sl->sl_dirfd == -1) in socksetup()
3952 sl->sl_recv = sl_recv; in socksetup()
3953 (void)memcpy(&sl->sl_ai, ai, sizeof(*ai)); in socksetup()
3954 if (ai->ai_addrlen > 0) { in socksetup()
3955 (void)memcpy((sl + 1), ai->ai_addr, ai->ai_addrlen); in socksetup()
3956 sl->sl_sa = (struct sockaddr *)(sl + 1); in socksetup()
3958 sl->sl_sa = NULL; in socksetup()