diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-02-12 13:15:51 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2017-02-12 13:15:51 +0000 |
commit | b1f4da57980d4b1a93867c6163fe2551e76f8bfa (patch) | |
tree | c30e4bae372115d51d747f289feff089644f8271 /sbin | |
parent | 8fa79650edfb6d1227033653a68a29d232c58f22 (diff) |
Switch from 'legacy' errwarn.c to standard daemon logging functions.
No objections heard. Feedback from millert@ guenther@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/Makefile | 4 | ||||
-rw-r--r-- | sbin/dhclient/bpf.c | 33 | ||||
-rw-r--r-- | sbin/dhclient/clparse.c | 13 | ||||
-rw-r--r-- | sbin/dhclient/conflex.c | 3 | ||||
-rw-r--r-- | sbin/dhclient/dhclient.c | 249 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 12 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 29 | ||||
-rw-r--r-- | sbin/dhclient/kroute.c | 57 | ||||
-rw-r--r-- | sbin/dhclient/log.c | 199 | ||||
-rw-r--r-- | sbin/dhclient/log.h | 46 | ||||
-rw-r--r-- | sbin/dhclient/options.c | 55 | ||||
-rw-r--r-- | sbin/dhclient/packet.c | 13 | ||||
-rw-r--r-- | sbin/dhclient/parse.c | 9 | ||||
-rw-r--r-- | sbin/dhclient/privsep.c | 19 |
14 files changed, 493 insertions, 248 deletions
diff --git a/sbin/dhclient/Makefile b/sbin/dhclient/Makefile index 4a0ed0189c8..274f9c83671 100644 --- a/sbin/dhclient/Makefile +++ b/sbin/dhclient/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.16 2014/11/01 16:51:20 krw Exp $ +# $OpenBSD: Makefile,v 1.17 2017/02/12 13:15:50 krw Exp $ # # Copyright (c) 1996, 1997 The Internet Software Consortium. # All rights reserved. @@ -33,7 +33,7 @@ .include <bsd.own.mk> SRCS= dhclient.c clparse.c dispatch.c bpf.c options.c \ - conflex.c errwarn.c packet.c tables.c \ + conflex.c log.c packet.c tables.c \ parse.c privsep.c kroute.c PROG= dhclient diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index 9d1f6051cad..12278f6256f 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.44 2016/08/31 12:57:31 mpi Exp $ */ +/* $OpenBSD: bpf.c,v 1.45 2017/02/12 13:15:50 krw Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -63,6 +63,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" int if_register_bpf(struct interface_info *ifi); @@ -78,12 +79,12 @@ if_register_bpf(struct interface_info *ifi) int sock; if ((sock = open("/dev/bpf0", O_RDWR | O_CLOEXEC)) == -1) - error("Can't open bpf: %s", strerror(errno)); + fatalx("Can't open bpf: %s", strerror(errno)); /* Set the BPF device to point at this interface. */ strlcpy(ifr.ifr_name, ifi->name, IFNAMSIZ); if (ioctl(sock, BIOCSETIF, &ifr) < 0) - error("Can't attach interface %s to /dev/bpf0: %s", + fatalx("Can't attach interface %s to /dev/bpf0: %s", ifi->name, strerror(errno)); return (sock); @@ -98,13 +99,13 @@ if_register_send(struct interface_info *ifi) * Use raw socket for unicast send. */ if ((sock = socket(AF_INET, SOCK_RAW, IPPROTO_UDP)) == -1) - error("socket(SOCK_RAW): %s", strerror(errno)); + fatalx("socket(SOCK_RAW): %s", strerror(errno)); if (setsockopt(sock, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on)) == -1) - error("setsockopt(IP_HDRINCL): %s", strerror(errno)); + fatalx("setsockopt(IP_HDRINCL): %s", strerror(errno)); if (setsockopt(sock, IPPROTO_IP, SO_RTABLE, &ifi->rdomain, sizeof(ifi->rdomain)) == -1) - error("setsockopt(SO_RTABLE): %s", strerror(errno)); + fatalx("setsockopt(SO_RTABLE): %s", strerror(errno)); ifi->ufdesc = sock; } @@ -196,11 +197,11 @@ if_register_receive(struct interface_info *ifi) /* Make sure the BPF version is in range. */ if (ioctl(ifi->bfdesc, BIOCVERSION, &v) < 0) - error("Can't get BPF version: %s", strerror(errno)); + fatalx("Can't get BPF version: %s", strerror(errno)); if (v.bv_major != BPF_MAJOR_VERSION || v.bv_minor < BPF_MINOR_VERSION) - error("Kernel BPF version out of range - recompile dhclient!"); + fatalx("Kernel BPF version out of range - recompile dhclient!"); /* * Set immediate mode so that reads return as soon as a packet @@ -208,20 +209,20 @@ if_register_receive(struct interface_info *ifi) * with packets. */ if (ioctl(ifi->bfdesc, BIOCIMMEDIATE, &flag) < 0) - error("Can't set immediate mode on bpf device: %s", + fatalx("Can't set immediate mode on bpf device: %s", strerror(errno)); if (ioctl(ifi->bfdesc, BIOCSFILDROP, &flag) < 0) - error("Can't set filter-drop mode on bpf device: %s", + fatalx("Can't set filter-drop mode on bpf device: %s", strerror(errno)); /* Get the required BPF buffer length from the kernel. */ if (ioctl(ifi->bfdesc, BIOCGBLEN, &sz) < 0) - error("Can't get bpf buffer length: %s", strerror(errno)); + fatalx("Can't get bpf buffer length: %s", strerror(errno)); ifi->rbuf_max = sz; ifi->rbuf = malloc(ifi->rbuf_max); if (!ifi->rbuf) - error("Can't allocate %lu bytes for bpf input buffer.", + fatalx("Can't allocate %lu bytes for bpf input buffer.", (unsigned long)ifi->rbuf_max); ifi->rbuf_offset = 0; ifi->rbuf_len = 0; @@ -238,7 +239,7 @@ if_register_receive(struct interface_info *ifi) dhcp_bpf_filter[8].k = LOCAL_PORT; if (ioctl(ifi->bfdesc, BIOCSETF, &p) < 0) - error("Can't install packet filter program: %s", + fatalx("Can't install packet filter program: %s", strerror(errno)); /* Set up the bpf write filter program structure. */ @@ -249,11 +250,11 @@ if_register_receive(struct interface_info *ifi) dhcp_bpf_wfilter[7].k = htons(IP_MF|IP_OFFMASK); if (ioctl(ifi->bfdesc, BIOCSETWF, &p) < 0) - error("Can't install write filter program: %s", + fatalx("Can't install write filter program: %s", strerror(errno)); if (ioctl(ifi->bfdesc, BIOCLOCK, NULL) < 0) - error("Cannot lock bpf"); + fatalx("Cannot lock bpf"); } ssize_t @@ -329,7 +330,7 @@ send_packet(struct interface_info *ifi, struct in_addr from, struct in_addr to) } if (result == -1) - warning("send_packet: %s", strerror(errno)); + log_warnx("send_packet: %s", strerror(errno)); return (result); } diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index f427eafcb4c..443adeed079 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.103 2016/10/06 16:29:17 krw Exp $ */ +/* $OpenBSD: clparse.c,v 1.104 2017/02/12 13:15:50 krw Exp $ */ /* Parser for dhclient config and lease files. */ @@ -58,6 +58,7 @@ #include "dhcp.h" #include "dhcpd.h" #include "dhctoken.h" +#include "log.h" void parse_client_statement(FILE *, struct interface_info *); int parse_X(FILE *, u_int8_t *, int); @@ -150,7 +151,7 @@ read_client_leases(struct interface_info *ifi) if (token == EOF) break; if (token != TOK_LEASE) { - warning("Corrupt lease file - possible data loss!"); + log_warnx("Corrupt lease file - possible data loss!"); break; } parse_client_lease_statement(cfile, 0, ifi); @@ -478,7 +479,7 @@ parse_client_lease_statement(FILE *cfile, int is_static, struct interface_info * lease = calloc(1, sizeof(struct client_lease)); if (!lease) - error("no memory for lease."); + fatalx("no memory for lease."); do { token = peek_token(NULL, cfile); @@ -766,7 +767,7 @@ bad_flag: dp = cidr; goto alloc; default: - warning("Bad format %c in parse_option_param.", + log_warnx("Bad format %c in parse_option_param.", *fmt); skip_to_semi(cfile); return (-1); @@ -782,7 +783,7 @@ bad_flag: options[code].data = malloc(hunkix + nul_term); if (!options[code].data) - error("out of memory allocating option data."); + fatalx("out of memory allocating option data."); memcpy(options[code].data, hunkbuf, hunkix + nul_term); options[code].len = hunkix; return (code); @@ -801,7 +802,7 @@ parse_reject_statement(FILE *cfile) elem = malloc(sizeof(struct reject_elem)); if (!elem) - error("no memory for reject address!"); + fatalx("no memory for reject address!"); elem->addr = addr; TAILQ_INSERT_TAIL(&config->reject_list, elem, next); diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index 4cf3c1440da..58b46ac5ac4 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conflex.c,v 1.34 2016/08/16 21:57:51 krw Exp $ */ +/* $OpenBSD: conflex.c,v 1.35 2017/02/12 13:15:50 krw Exp $ */ /* Lexical scanner for dhclient config file. */ @@ -60,6 +60,7 @@ #include "dhcp.h" #include "dhcpd.h" #include "dhctoken.h" +#include "log.h" int lexline; int lexchar; diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index d4b2cd2b63e..090f55e550d 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.394 2017/01/23 04:45:59 deraadt Exp $ */ +/* $OpenBSD: dhclient.c,v 1.395 2017/02/12 13:15:50 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -90,6 +90,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" #include "privsep.h" char *path_dhclient_conf = _PATH_DHCLIENT_CONF; @@ -248,7 +249,7 @@ routehandler(struct interface_info *ifi) rtmmsg = calloc(1, 2048); if (rtmmsg == NULL) - error("No memory for rtmmsg"); + fatalx("No memory for rtmmsg"); do { n = read(routefd, rtmmsg, 2048); @@ -261,7 +262,7 @@ routehandler(struct interface_info *ifi) switch (rtm->rtm_type) { case RTM_DESYNC: - warning("route socket buffer overflow"); + log_warnx("route socket buffer overflow"); break; case RTM_NEWADDR: ifam = (struct ifa_msghdr *)rtm; @@ -285,7 +286,7 @@ routehandler(struct interface_info *ifi) */ if (a.s_addr == adding.s_addr) { adding.s_addr = INADDR_ANY; - note("bound to %s -- renewal in %lld seconds.", + log_info("bound to %s -- renewal in %lld seconds.", inet_ntoa(client->active->address), (long long)(client->active->renewal - time(NULL))); @@ -334,7 +335,7 @@ routehandler(struct interface_info *ifi) if (adding.s_addr == INADDR_ANY && client->active && a.s_addr == client->active->address.s_addr) { /* Tell the priv process active_addr is gone. */ - warning("Active address (%s) deleted; exiting", + log_warnx("Active address (%s) deleted; exiting", inet_ntoa(client->active->address)); memset(&b, 0, sizeof(b)); add_address(b, b); @@ -364,7 +365,7 @@ routehandler(struct interface_info *ifi) memcpy(&hw, &ifi->hw_address, sizeof(hw)); get_hw_address(ifi); if (memcmp(&hw, &ifi->hw_address, sizeof(hw))) { - warning("LLADDR changed; restarting"); + log_warnx("LLADDR changed; restarting"); ifi->flags |= IFI_NEW_LLADDR; quit = SIGHUP; goto done; @@ -374,7 +375,7 @@ routehandler(struct interface_info *ifi) linkstat = interface_status(ifi); if (linkstat != ifi->linkstat) { #ifdef DEBUG - debug("link state %s -> %s", + log_debug("link state %s -> %s", ifi->linkstat ? "up" : "down", linkstat ? "up" : "down"); #endif @@ -420,8 +421,8 @@ done: die: if (rslt == -1) - error("no memory for errmsg"); - error("%s; exiting", errmsg); + fatalx("no memory for errmsg"); + fatalx("%s; exiting", errmsg); } char **saved_argv; @@ -437,7 +438,6 @@ main(int argc, char *argv[]) struct ieee80211_nwid nwid; struct stat sb; int ch, fd, socket_fd[2]; - extern char *__progname; struct passwd *pw; char *ignore_list = NULL; ssize_t tailn; @@ -445,13 +445,8 @@ main(int argc, char *argv[]) saved_argv = argv; - /* Initially, log errors to stderr as well as to syslogd. */ - openlog(__progname, LOG_PID | LOG_NDELAY, LOG_DAEMON); -#ifdef DEBUG - setlogmask(LOG_UPTO(LOG_DEBUG)); -#else - setlogmask(LOG_UPTO(LOG_INFO)); -#endif + log_init(1, LOG_DAEMON); /* log to stderr until daemonized */ + log_setverbose(1); while ((ch = getopt(argc, argv, "c:di:l:L:qu")) != -1) switch (ch) { @@ -471,7 +466,7 @@ main(int argc, char *argv[]) path_dhclient_db = optarg; if (lstat(path_dhclient_db, &sb) != -1) { if (!S_ISREG(sb.st_mode)) - error("'%s' is not a regular file", + fatalx("'%s' is not a regular file", path_dhclient_db); } break; @@ -479,7 +474,7 @@ main(int argc, char *argv[]) strlcat(path_option_db, optarg, PATH_MAX); if (lstat(path_option_db, &sb) != -1) { if (!S_ISREG(sb.st_mode)) - error("'%s' is not a regular file", + fatalx("'%s' is not a regular file", path_option_db); } break; @@ -504,18 +499,18 @@ main(int argc, char *argv[]) ifi = calloc(1, sizeof(struct interface_info)); if (ifi == NULL) - error("ifi calloc"); + fatalx("ifi calloc"); get_ifname(ifi, argv[0]); ifi->index = if_nametoindex(ifi->name); if (ifi->index == 0) - error("%s: no such interface", ifi->name); + fatalx("%s: no such interface", ifi->name); get_hw_address(ifi); tzset(); /* Get the ssid if present. */ if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - error("Can't create socket to get ssid"); + fatalx("Can't create socket to get ssid"); memset(&ifr, 0, sizeof(ifr)); memset(&nwid, 0, sizeof(nwid)); ifr.ifr_data = (caddr_t)&nwid; @@ -528,31 +523,31 @@ main(int argc, char *argv[]) /* Put us into the correct rdomain */ ifi->rdomain = get_rdomain(ifi->name); if (setrtable(ifi->rdomain) == -1) - error("setting routing table to %u: '%s'", ifi->rdomain, + fatalx("setting routing table to %u: '%s'", ifi->rdomain, strerror(errno)); if (socketpair(AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK | SOCK_CLOEXEC, PF_UNSPEC, socket_fd) == -1) - error("socketpair: %s", strerror(errno)); + fatalx("socketpair: %s", strerror(errno)); if ((nullfd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) - error("cannot open %s: %s", _PATH_DEVNULL, strerror(errno)); + fatalx("cannot open %s: %s", _PATH_DEVNULL, strerror(errno)); fork_privchld(ifi, socket_fd[0], socket_fd[1]); close(socket_fd[0]); if ((unpriv_ibuf = malloc(sizeof(struct imsgbuf))) == NULL) - error("no memory for unpriv_ibuf"); + fatalx("no memory for unpriv_ibuf"); imsg_init(unpriv_ibuf, socket_fd[1]); config = calloc(1, sizeof(struct client_config)); if (config == NULL) - error("config calloc"); + fatalx("config calloc"); TAILQ_INIT(&config->reject_list); ifi->client = calloc(1, sizeof(struct client_state)); if (ifi->client == NULL) - error("client calloc"); + fatalx("client calloc"); TAILQ_INIT(&ifi->client->leases); TAILQ_INIT(&ifi->client->offered_leases); @@ -574,7 +569,7 @@ main(int argc, char *argv[]) if (opt->len == 0 && opt->data == NULL) { opt->data = calloc(1, ETHER_ADDR_LEN + 1); if (opt->data == NULL) - error("no memory for default client identifier"); + fatalx("no memory for default client identifier"); opt->data[0] = HTYPE_ETHER; memcpy(&opt->data[1], ifi->hw_address.ether_addr_octet, ETHER_ADDR_LEN); @@ -582,11 +577,11 @@ main(int argc, char *argv[]) } if ((pw = getpwnam("_dhcp")) == NULL) - error("no such user: _dhcp"); + fatalx("no such user: _dhcp"); if (path_dhclient_db == NULL && asprintf(&path_dhclient_db, "%s.%s", _PATH_DHCLIENT_DB, ifi->name) == -1) - error("asprintf"); + fatalx("asprintf"); /* 2nd stage (post fork) config setup. */ if (ignore_list) @@ -595,37 +590,37 @@ main(int argc, char *argv[]) tailfd = open("/etc/resolv.conf.tail", O_RDONLY); if (tailfd == -1) { if (errno != ENOENT) - error("Cannot open /etc/resolv.conf.tail: %s", + fatalx("Cannot open /etc/resolv.conf.tail: %s", strerror(errno)); } else if (fstat(tailfd, &sb) == -1) { - error("Cannot stat /etc/resolv.conf.tail: %s", + fatalx("Cannot stat /etc/resolv.conf.tail: %s", strerror(errno)); } else { if (sb.st_size > 0 && sb.st_size < SIZE_MAX) { config->resolv_tail = calloc(1, sb.st_size + 1); if (config->resolv_tail == NULL) { - error("no memory for resolv.conf.tail " + fatalx("no memory for resolv.conf.tail " "contents: %s", strerror(errno)); } tailn = read(tailfd, config->resolv_tail, sb.st_size); if (tailn == -1) - error("Couldn't read resolv.conf.tail: %s", + fatalx("Couldn't read resolv.conf.tail: %s", strerror(errno)); else if (tailn == 0) - error("Got no data from resolv.conf.tail"); + fatalx("Got no data from resolv.conf.tail"); else if (tailn != sb.st_size) - error("Short read of resolv.conf.tail"); + fatalx("Short read of resolv.conf.tail"); } close(tailfd); } if ((fd = open(path_dhclient_db, O_RDONLY|O_EXLOCK|O_CREAT|O_NOFOLLOW, 0640)) == -1) - error("can't open and lock %s: %s", path_dhclient_db, + fatalx("can't open and lock %s: %s", path_dhclient_db, strerror(errno)); read_client_leases(ifi); if ((leaseFile = fopen(path_dhclient_db, "w")) == NULL) - error("can't open %s: %s", path_dhclient_db, strerror(errno)); + fatalx("can't open %s: %s", path_dhclient_db, strerror(errno)); rewrite_client_leases(ifi); close(fd); @@ -640,42 +635,42 @@ main(int argc, char *argv[]) interface_link_forceup(ifi->name); if ((routefd = socket(PF_ROUTE, SOCK_RAW, 0)) == -1) - error("socket(PF_ROUTE, SOCK_RAW): %s", strerror(errno)); + fatalx("socket(PF_ROUTE, SOCK_RAW): %s", strerror(errno)); rtfilter = ROUTE_FILTER(RTM_NEWADDR) | ROUTE_FILTER(RTM_DELADDR) | ROUTE_FILTER(RTM_IFINFO) | ROUTE_FILTER(RTM_IFANNOUNCE); if (setsockopt(routefd, PF_ROUTE, ROUTE_MSGFILTER, &rtfilter, sizeof(rtfilter)) == -1) - error("setsockopt(ROUTE_MSGFILTER): %s", strerror(errno)); + fatalx("setsockopt(ROUTE_MSGFILTER): %s", strerror(errno)); if (setsockopt(routefd, AF_ROUTE, ROUTE_TABLEFILTER, &ifi->rdomain, sizeof(ifi->rdomain)) == -1) - error("setsockopt(ROUTE_TABLEFILTER): %s", strerror(errno)); + fatalx("setsockopt(ROUTE_TABLEFILTER): %s", strerror(errno)); /* Register the interface. */ if_register_receive(ifi); if_register_send(ifi); if (chroot(_PATH_VAREMPTY) == -1) - error("chroot"); + fatalx("chroot"); if (chdir("/") == -1) - error("chdir(\"/\")"); + fatalx("chdir(\"/\")"); if (setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) == -1) - error("setresgid"); + fatalx("setresgid"); if (setgroups(1, &pw->pw_gid) == -1) - error("setgroups"); + fatalx("setgroups"); if (setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid) == -1) - error("setresuid"); + fatalx("setresuid"); endpwent(); if (daemonize) { if (pledge("stdio inet dns route proc", NULL) == -1) - error("pledge"); + fatalx("pledge"); } else { if (pledge("stdio inet dns route", NULL) == -1) - error("pledge"); + fatalx("pledge"); } setproctitle("%s", ifi->name); @@ -938,16 +933,16 @@ dhcpack(struct interface_info *ifi, struct in_addr client_addr, client->state != S_RENEWING && client->state != S_REBINDING) { #ifdef DEBUG - debug("Unexpected %s. State #%d", info, client->state); + log_debug("Unexpected %s. State #%d", info, client->state); #endif return; } - note("%s", info); + log_info("%s", info); lease = packet_to_lease(ifi, client_addr, options); if (lease->is_invalid) { - note("Unsatisfactory %s", info); + log_info("Unsatisfactory %s", info); make_decline(ifi, lease); send_decline(ifi); free_client_lease(lease); @@ -1001,7 +996,7 @@ bind_lease(struct interface_info *ifi) client->active->resolv_conf = NULL; client->active = client->new; client->new = NULL; - note("bound to %s -- renewal in %lld seconds.", + log_info("bound to %s -- renewal in %lld seconds.", inet_ntoa(client->active->address), (long long)(client->active->renewal - time(NULL))); goto newlease; @@ -1026,7 +1021,7 @@ bind_lease(struct interface_info *ifi) mtu = ntohs(mtu); /* "The minimum legal value for the MTU is 68." */ if (mtu < 68) - warning("mtu size %u < 68: ignored", mtu); + log_warnx("mtu size %u < 68: ignored", mtu); else set_interface_mtu(mtu); } @@ -1150,19 +1145,19 @@ dhcpoffer(struct interface_info *ifi, struct in_addr client_addr, if (client->state != S_SELECTING) { #ifdef DEBUG - debug("Unexpected %s. State #%d.", info, client->state); + log_debug("Unexpected %s. State #%d.", info, client->state); #endif return; } - note("%s", info); + log_info("%s", info); /* If we've already seen this lease, don't record it again. */ TAILQ_FOREACH(lp, &client->offered_leases, next) { if (!memcmp(&lp->address.s_addr, &client->packet.yiaddr, sizeof(in_addr_t))) { #ifdef DEBUG - debug("Duplicate %s.", info); + log_debug("Duplicate %s.", info); #endif return; } @@ -1204,7 +1199,7 @@ addressinuse(struct interface_info *ifi, struct in_addr address, char *ifname) int used = 0; if (getifaddrs(&ifap) != 0) { - warning("addressinuse: getifaddrs: %s", strerror(errno)); + log_warnx("addressinuse: getifaddrs: %s", strerror(errno)); return (0); } @@ -1242,7 +1237,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, lease = calloc(1, sizeof(struct client_lease)); if (!lease) { - warning("dhcpoffer: no memory to create lease."); + log_warnx("dhcpoffer: no memory to create lease."); return (NULL); } @@ -1252,7 +1247,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, continue; if (!unknown_ok && strncmp("option-", dhcp_options[i].name, 7) != 0) { - warning("dhcpoffer: unknown option %d", i); + log_warnx("dhcpoffer: unknown option %d", i); lease->is_invalid = 1; } pretty = pretty_print_option(i, &options[i], 0); @@ -1263,14 +1258,14 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, /* Must decode the option into text to check names. */ buf = calloc(1, DHCP_DOMAIN_SEARCH_LEN); if (buf == NULL) - error("No memory to decode domain search"); + fatalx("No memory to decode domain search"); sz = pretty_print_domain_search(buf, DHCP_DOMAIN_SEARCH_LEN, options[i].data, options[i].len); if (strlen(buf) == 0) continue; if (sz == -1 || !res_hnok_list(buf)) - warning("Bogus data for option %s", + log_warnx("Bogus data for option %s", dhcp_options[i].name); free(buf); break; @@ -1282,7 +1277,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, * entries in the resolv.conf 'search' statement. */ if (!res_hnok_list(pretty)) { - warning("Bogus data for option %s", + log_warnx("Bogus data for option %s", dhcp_options[i].name); continue; } @@ -1290,7 +1285,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, case DHO_HOST_NAME: case DHO_NIS_DOMAIN: if (!res_hnok(pretty)) { - warning("Bogus data for option %s", + log_warnx("Bogus data for option %s", dhcp_options[i].name); continue; } @@ -1308,7 +1303,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, */ for (i = 0; i < config->required_option_count; i++) { if (!lease->options[config->required_options[i]].len) { - warning("Missing required parameter %s", + log_warnx("Missing required parameter %s", dhcp_options[i].name); lease->is_invalid = 1; } @@ -1322,7 +1317,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, memset(ifname, 0, sizeof(ifname)); if (addressinuse(ifi, lease->address, ifname) && strncmp(ifname, ifi->name, IF_NAMESIZE) != 0) { - warning("%s already configured on %s", + log_warnx("%s already configured on %s", inet_ntoa(lease->address), ifname); lease->is_invalid = 1; } @@ -1336,14 +1331,14 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, client->packet.sname[0]) { lease->server_name = malloc(DHCP_SNAME_LEN + 1); if (!lease->server_name) { - warning("dhcpoffer: no memory for server name."); + log_warnx("dhcpoffer: no memory for server name."); lease->is_invalid = 1; } memcpy(lease->server_name, client->packet.sname, DHCP_SNAME_LEN); lease->server_name[DHCP_SNAME_LEN] = '\0'; if (!res_hnok(lease->server_name)) { - warning("Bogus server name %s", lease->server_name); + log_warnx("Bogus server name %s", lease->server_name); lease->is_invalid = 1; } } @@ -1355,7 +1350,7 @@ packet_to_lease(struct interface_info *ifi, struct in_addr client_addr, /* Don't count on the NUL terminator. */ lease->filename = malloc(DHCP_FILE_LEN + 1); if (!lease->filename) { - warning("dhcpoffer: no memory for filename."); + log_warnx("dhcpoffer: no memory for filename."); lease->is_invalid = 1; } memcpy(lease->filename, client->packet.file, DHCP_FILE_LEN); @@ -1375,19 +1370,19 @@ dhcpnak(struct interface_info *ifi, struct in_addr client_addr, client->state != S_RENEWING && client->state != S_REBINDING) { #ifdef DEBUG - debug("Unexpected %s. State #%d", info, client->state); + log_debug("Unexpected %s. State #%d", info, client->state); #endif return; } if (!client->active) { #ifdef DEBUG - debug("Unexpected %s. No active lease.", info); + log_debug("Unexpected %s. No active lease.", info); #endif return; } - note("%s", info); + log_info("%s", info); /* XXX Do we really want to remove a NAK'd lease from the database? */ if (!client->active->is_static) { @@ -1459,12 +1454,12 @@ send_discover(void *xifi) client->bootrequest_packet.secs = htons(UINT16_MAX); client->secs = client->bootrequest_packet.secs; - note("DHCPDISCOVER on %s - interval %lld", ifi->name, + log_info("DHCPDISCOVER on %s - interval %lld", ifi->name, (long long)client->interval); rslt = send_packet(ifi, inaddr_any, inaddr_broadcast); if (rslt == -1 && errno == EAFNOSUPPORT) { - warning("dhclient cannot be used on %s", ifi->name); + log_warnx("dhclient cannot be used on %s", ifi->name); quit = INTERNALSIG; } else set_timeout_interval(client->interval, send_discover, ifi); @@ -1484,7 +1479,7 @@ state_panic(void *xifi) time_t cur_time; time(&cur_time); - note("No acceptable DHCPOFFERS received."); + log_info("No acceptable DHCPOFFERS received."); /* Run through the list of leases and see if one can be used. */ time(&cur_time); @@ -1496,11 +1491,11 @@ state_panic(void *xifi) continue; if (lp->is_static) { set_lease_times(lp); - note("Trying static lease %s", inet_ntoa(lp->address)); + log_info("Trying static lease %s", inet_ntoa(lp->address)); } else if (lp->expiry <= cur_time) { continue; } else - note("Trying recorded lease %s", + log_info("Trying recorded lease %s", inet_ntoa(lp->address)); client->new = lp; @@ -1513,7 +1508,7 @@ state_panic(void *xifi) /* * No leases were available, or what was available didn't work */ - note("No working leases in persistent database - sleeping."); + log_info("No working leases in persistent database - sleeping."); client->state = S_INIT; set_timeout_interval(config->retry_interval, state_init, ifi); go_daemon(); @@ -1616,7 +1611,7 @@ send_request(void *xifi) client->bootrequest_packet.secs = htons(UINT16_MAX); } - note("DHCPREQUEST on %s to %s", ifi->name, + log_info("DHCPREQUEST on %s to %s", ifi->name, inet_ntoa(destination.sin_addr)); send_packet(ifi, from, destination.sin_addr); @@ -1629,7 +1624,7 @@ send_decline(void *xifi) { struct interface_info *ifi = xifi; - note("DHCPDECLINE on %s", ifi->name); + log_info("DHCPDECLINE on %s", ifi->name); send_packet(ifi, inaddr_any, inaddr_broadcast); } @@ -1676,7 +1671,7 @@ make_discover(struct interface_info *ifi, struct client_lease *lease) /* Set up the option buffer to fit in a minimal UDP packet. */ i = cons_options(ifi, options); if (i == -1 || packet->options[i] != DHO_END) - error("options do not fit in DHCPDISCOVER packet."); + fatalx("options do not fit in DHCPDISCOVER packet."); client->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1; if (client->bootrequest_packet_length < BOOTP_MIN_LEN) client->bootrequest_packet_length = BOOTP_MIN_LEN; @@ -1748,7 +1743,7 @@ make_request(struct interface_info *ifi, struct client_lease * lease) /* Set up the option buffer to fit in a minimal UDP packet. */ i = cons_options(ifi, options); if (i == -1 || packet->options[i] != DHO_END) - error("options do not fit in DHCPREQUEST packet."); + fatalx("options do not fit in DHCPREQUEST packet."); client->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1; if (client->bootrequest_packet_length < BOOTP_MIN_LEN) client->bootrequest_packet_length = BOOTP_MIN_LEN; @@ -1817,7 +1812,7 @@ make_decline(struct interface_info *ifi, struct client_lease *lease) /* Set up the option buffer to fit in a minimal UDP packet. */ i = cons_options(ifi, options); if (i == -1 || packet->options[i] != DHO_END) - error("options do not fit in DHCPDECLINE packet."); + fatalx("options do not fit in DHCPDECLINE packet."); client->bootrequest_packet_length = DHCP_FIXED_NON_UDP+i+1; if (client->bootrequest_packet_length < BOOTP_MIN_LEN) client->bootrequest_packet_length = BOOTP_MIN_LEN; @@ -1867,7 +1862,7 @@ rewrite_client_leases(struct interface_info *ifi) time_t cur_time; if (!leaseFile) /* XXX */ - error("lease file not open"); + fatalx("lease file not open"); fflush(leaseFile); rewind(leaseFile); @@ -1891,7 +1886,7 @@ rewrite_client_leases(struct interface_info *ifi) if (leasestr) fprintf(leaseFile, "%s", leasestr); else - warning("cannot make lease into string"); + log_warnx("cannot make lease into string"); } fflush(leaseFile); @@ -1916,17 +1911,17 @@ rewrite_option_db(struct interface_info *ifi, struct client_lease *offered, if (leasestr) { n = strlcat(db, leasestr, sizeof(db)); if (n >= sizeof(db)) - warning("cannot fit offered lease into option db"); + log_warnx("cannot fit offered lease into option db"); } else - warning("cannot make offered lease into string"); + log_warnx("cannot make offered lease into string"); leasestr = lease_as_string(ifi, "effective", effective); if (leasestr) { n = strlcat(db, leasestr, sizeof(db)); if (n >= sizeof(db)) - warning("cannot fit effective lease into option db"); + log_warnx("cannot fit effective lease into option db"); } else - warning("cannot make effective lease into string"); + log_warnx("cannot make effective lease into string"); write_option_db(db, strlen(db)); } @@ -2066,9 +2061,11 @@ go_daemon(void) /* Stop logging to stderr. */ log_perror = 0; + log_init(0, LOG_DAEMON); + log_setverbose(0); if (rdaemon(nullfd) == -1) - error("Cannot daemonize: %s", strerror(errno)); + fatalx("Cannot daemonize: %s", strerror(errno)); /* Catch stuff that might be trying to terminate the program. */ signal(SIGHUP, sighdlr); @@ -2129,7 +2126,7 @@ res_hnok(const char *name) } else if (!isalnum(ch) && ch != '-' && ch != '_') return (0); else if (ch == '_' && warn == 0) { - warning("warning: hostname %s contains an " + log_warnx("warning: hostname %s contains an " "underscore which violates RFC 952", name); warn++; } @@ -2154,7 +2151,7 @@ res_hnok_list(const char *names) dupnames = inputstring = strdup(names); if (inputstring == NULL) - error("Cannot copy domain name list"); + fatalx("Cannot copy domain name list"); count = 0; while ((hn = strsep(&inputstring, " \t")) != NULL) { @@ -2183,7 +2180,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) switch (fork()) { case -1: - error("cannot fork"); + fatalx("cannot fork"); break; case 0: break; @@ -2192,7 +2189,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) } if (chdir("/") == -1) - error("chdir(\"/\")"); + fatalx("chdir(\"/\")"); setproctitle("%s [priv]", ifi->name); @@ -2201,7 +2198,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) close(fd2); if ((priv_ibuf = malloc(sizeof(struct imsgbuf))) == NULL) - error("no memory for priv_ibuf"); + fatalx("no memory for priv_ibuf"); imsg_init(priv_ibuf, fd); @@ -2210,7 +2207,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) pfd[0].events = POLLIN; if ((nfds = poll(pfd, 1, INFTIM)) == -1) { if (errno != EINTR) { - warning("poll error: %s", strerror(errno)); + log_warnx("poll error: %s", strerror(errno)); quit = INTERNALSIG; } continue; @@ -2220,7 +2217,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) continue; if ((n = imsg_read(priv_ibuf)) == -1 && errno != EAGAIN) { - warning("imsg_read(priv_ibuf): %s", strerror(errno)); + log_warnx("imsg_read(priv_ibuf): %s", strerror(errno)); quit = INTERNALSIG; continue; } @@ -2241,7 +2238,7 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) /* Truncate the file so monitoring process see exit. */ rslt = truncate(path_option_db, 0); if (rslt == -1) - warning("Unable to truncate '%s': %s", path_option_db, + log_warnx("Unable to truncate '%s': %s", path_option_db, strerror(errno)); } @@ -2258,15 +2255,15 @@ fork_privchld(struct interface_info *ifi, int fd, int fd2) if (quit == SIGHUP) { if (!(ifi->flags & IFI_HUP) && (!(ifi->flags & IFI_NEW_LLADDR))) - warning("%s; restarting.", strsignal(quit)); + log_warnx("%s; restarting.", strsignal(quit)); signal(SIGHUP, SIG_IGN); /* will be restored after exec */ execvp(saved_argv[0], saved_argv); - error("RESTART FAILED: '%s': %s", saved_argv[0], + fatalx("RESTART FAILED: '%s': %s", saved_argv[0], strerror(errno)); } if (quit != INTERNALSIG) - warning("%s; exiting", strsignal(quit)); + log_warnx("%s; exiting", strsignal(quit)); exit(1); } @@ -2281,36 +2278,36 @@ get_ifname(struct interface_info *ifi, char *arg) if (strcmp(arg, "egress") == 0) { s = socket(AF_INET, SOCK_DGRAM, 0); if (s == -1) - error("socket error"); + fatalx("socket error"); memset(&ifgr, 0, sizeof(ifgr)); strlcpy(ifgr.ifgr_name, "egress", sizeof(ifgr.ifgr_name)); if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) { if (errno == ENOENT) - error("no interface in group egress found"); - error("ioctl SIOCGIFGMEMB: %s", strerror(errno)); + fatalx("no interface in group egress found"); + fatalx("ioctl SIOCGIFGMEMB: %s", strerror(errno)); } len = ifgr.ifgr_len; if ((ifgr.ifgr_groups = calloc(1, len)) == NULL) - error("get_ifname"); + fatalx("get_ifname"); if (ioctl(s, SIOCGIFGMEMB, (caddr_t)&ifgr) == -1) - error("ioctl SIOCGIFGMEMB: %s", strerror(errno)); + fatalx("ioctl SIOCGIFGMEMB: %s", strerror(errno)); arg = NULL; for (ifg = ifgr.ifgr_groups; ifg && len >= sizeof(struct ifg_req); ifg++) { len -= sizeof(struct ifg_req); if (arg) - error("too many interfaces in group egress"); + fatalx("too many interfaces in group egress"); arg = ifg->ifgrq_member; } if (strlcpy(ifi->name, arg, IFNAMSIZ) >= IFNAMSIZ) - error("Interface name too long: %s", strerror(errno)); + fatalx("Interface name too long: %s", strerror(errno)); free(ifgr.ifgr_groups); close(s); } else if (strlcpy(ifi->name, arg, IFNAMSIZ) >= IFNAMSIZ) - error("Interface name too long"); + fatalx("Interface name too long"); } /* @@ -2329,7 +2326,7 @@ resolv_conf_contents(struct interface_info *ifi, struct option_data *domainname, if (domainsearch->len) { buf = calloc(1, DHCP_DOMAIN_SEARCH_LEN); if (buf == NULL) - error("No memory to decode domain search"); + fatalx("No memory to decode domain search"); sz = pretty_print_domain_search(buf, DHCP_DOMAIN_SEARCH_LEN, domainsearch->data, domainsearch->len); if (sz == -1) @@ -2348,7 +2345,7 @@ resolv_conf_contents(struct interface_info *ifi, struct option_data *domainname, } else dn = strdup(""); if (dn == NULL) - error("no memory for domainname"); + fatalx("no memory for domainname"); if (nameservers->len) { ns = pretty_print_option(DHO_DOMAIN_NAME_SERVERS, nameservers, @@ -2361,7 +2358,7 @@ resolv_conf_contents(struct interface_info *ifi, struct option_data *domainname, continue; rslt = asprintf(&nss[i], "nameserver %s\n", p); if (rslt == -1) - error("no memory for nameserver"); + fatalx("no memory for nameserver"); } } @@ -2380,13 +2377,13 @@ resolv_conf_contents(struct interface_info *ifi, struct option_data *domainname, rslt = asprintf(&courtesy, "# Generated by %s dhclient\n", ifi->name); if (rslt == -1) - error("no memory for courtesy line"); + fatalx("no memory for courtesy line"); len += strlen(courtesy); len++; /* Need room for terminating NUL. */ contents = calloc(1, len); if (contents == NULL) - error("no memory for resolv.conf contents"); + fatalx("no memory for resolv.conf contents"); strlcat(contents, courtesy, len); free(courtesy); @@ -2415,7 +2412,7 @@ apply_defaults(struct client_lease *lease) newlease = clone_lease(lease); if (newlease == NULL) - error("Unable to clone lease"); + fatalx("Unable to clone lease"); if (config->filename) { free(newlease->filename); @@ -2531,7 +2528,7 @@ cleanup: free_client_lease(newlease); } - error("Unable to apply defaults"); + fatalx("Unable to apply defaults"); /* NOTREACHED */ return (NULL); @@ -2619,7 +2616,7 @@ apply_ignore_list(char *ignore_list) break; if (i == DHO_END) { - note("Invalid option name: '%s'", p); + log_info("Invalid option name: '%s'", p); return; } @@ -2642,7 +2639,7 @@ write_resolv_conf(u_int8_t *contents, size_t sz) rslt = imsg_compose(unpriv_ibuf, IMSG_WRITE_RESOLV_CONF, 0, 0, -1, contents, sz); if (rslt == -1) - warning("write_resolv_conf: imsg_compose: %s", strerror(errno)); + log_warnx("write_resolv_conf: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("write_resolv_conf"); } @@ -2655,7 +2652,7 @@ write_option_db(u_int8_t *contents, size_t sz) rslt = imsg_compose(unpriv_ibuf, IMSG_WRITE_OPTION_DB, 0, 0, -1, contents, sz); if (rslt == -1) - warning("write_option_db: imsg_compose: %s", strerror(errno)); + log_warnx("write_option_db: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("write_option_db"); } @@ -2667,7 +2664,7 @@ priv_write_resolv_conf(struct interface_info *ifi, struct imsg *imsg) size_t sz; if (imsg->hdr.len < IMSG_HEADER_SIZE) { - warning("short IMSG_WRITE_RESOLV_CONF"); + log_warnx("short IMSG_WRITE_RESOLV_CONF"); return; } @@ -2689,7 +2686,7 @@ priv_write_option_db(struct imsg *imsg) size_t sz; if (imsg->hdr.len < IMSG_HEADER_SIZE) { - warning("short IMSG_WRITE_OPTION_DB"); + log_warnx("short IMSG_WRITE_OPTION_DB"); return; } @@ -2710,23 +2707,23 @@ priv_write_file(char *path, int flags, mode_t mode, fd = open(path, flags, mode); if (fd == -1) { - note("Couldn't open '%s': %s", path, strerror(errno)); + log_info("Couldn't open '%s': %s", path, strerror(errno)); return; } n = write(fd, contents, sz); if (n == -1) - note("Couldn't write contents to '%s': %s", path, + log_info("Couldn't write contents to '%s': %s", path, strerror(errno)); else if (n < sz) - note("Short contents write to '%s' (%zd vs %zu)", path, + log_info("Short contents write to '%s' (%zd vs %zu)", path, n, sz); if (fchown(fd, 0, 0) == -1) - note("fchown(fd, %d, %d) of '%s' failed (%s)", + log_info("fchown(fd, %d, %d) of '%s' failed (%s)", 0, 0, path, strerror(errno)); if (fchmod(fd, mode) == -1) - note("fchmod(fd, 0x%x) of '%s' failed (%s)", mode, + log_info("fchmod(fd, 0x%x) of '%s' failed (%s)", mode, path, strerror(errno)); close(fd); diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index f63d8830017..c70e06c7e76 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.159 2017/02/11 16:12:36 krw Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.160 2017/02/12 13:15:50 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -192,15 +192,6 @@ int pretty_print_domain_search(unsigned char *, size_t, unsigned char *, void do_packet(struct interface_info *, unsigned int, struct in_addr, struct ether_addr *); -/* errwarn.c */ -extern int warnings_occurred; -void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -void warning(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -void note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -#ifdef DEBUG -void debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -#endif - /* conflex.c */ extern int lexline, lexchar; extern char *token_line, *tlname; @@ -209,6 +200,7 @@ int next_token(char **, FILE *); int peek_token(char **, FILE *); /* parse.c */ +extern int warnings_occurred; void skip_to_semi(FILE *); int parse_semi(FILE *); char *parse_string(FILE *); diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index ee6d83a0765..c6a0981eb6f 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.112 2017/01/23 04:45:59 deraadt Exp $ */ +/* $OpenBSD: dispatch.c,v 1.113 2017/02/12 13:15:50 krw Exp $ */ /* * Copyright 2004 Henning Brauer <henning@openbsd.org> @@ -66,6 +66,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" #include "privsep.h" @@ -81,7 +82,7 @@ get_hw_address(struct interface_info *ifi) int found; if (getifaddrs(&ifap) != 0) - error("getifaddrs failed"); + fatalx("getifaddrs failed"); found = 0; for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { @@ -107,7 +108,7 @@ get_hw_address(struct interface_info *ifi) } if (!found) - error("%s: no such interface", ifi->name); + fatalx("%s: no such interface", ifi->name); freeifaddrs(ifap); } @@ -168,7 +169,7 @@ dispatch(struct interface_info *ifi) if (errno == EAGAIN || errno == EINTR) { continue; } else { - warning("poll: %s", strerror(errno)); + log_warnx("poll: %s", strerror(errno)); quit = INTERNALSIG; continue; } @@ -189,10 +190,10 @@ dispatch(struct interface_info *ifi) if (quit == SIGHUP) { /* Tell [priv] process that HUP has occurred. */ sendhup(client->active); - warning("%s; restarting", strsignal(quit)); + log_warnx("%s; restarting", strsignal(quit)); exit (0); } else if (quit != INTERNALSIG) { - warning("%s; exiting", strsignal(quit)); + log_warnx("%s; exiting", strsignal(quit)); exit(1); } } @@ -206,11 +207,11 @@ packethandler(struct interface_info *ifi) ssize_t result; if ((result = receive_packet(ifi, &from, &hfrom)) == -1) { - warning("%s receive_packet failed: %s", ifi->name, + log_warnx("%s receive_packet failed: %s", ifi->name, strerror(errno)); ifi->errors++; if (ifi->errors > 20) { - error("%s too many receive_packet failures; exiting", + fatalx("%s too many receive_packet failures; exiting", ifi->name); } return; @@ -234,7 +235,7 @@ interface_link_forceup(char *ifname) memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sock, SIOCGIFFLAGS, (caddr_t)&ifr) == -1) { - note("interface_link_forceup: SIOCGIFFLAGS failed (%s)", + log_info("interface_link_forceup: SIOCGIFFLAGS failed (%s)", strerror(errno)); return; } @@ -242,14 +243,14 @@ interface_link_forceup(char *ifname) /* Force it down and up so others notice link state change. */ ifr.ifr_flags &= ~IFF_UP; if (ioctl(sock, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) { - note("interface_link_forceup: SIOCSIFFLAGS DOWN failed (%s)", + log_info("interface_link_forceup: SIOCSIFFLAGS DOWN failed (%s)", strerror(errno)); return; } ifr.ifr_flags |= IFF_UP; if (ioctl(sock, SIOCSIFFLAGS, (caddr_t)&ifr) == -1) { - note("interface_link_forceup: SIOCSIFFLAGS UP failed (%s)", + log_info("interface_link_forceup: SIOCSIFFLAGS UP failed (%s)", strerror(errno)); return; } @@ -266,7 +267,7 @@ interface_status(struct interface_info *ifi) memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifi->name, sizeof(ifr.ifr_name)); if (ioctl(sock, SIOCGIFFLAGS, &ifr) == -1) { - error("ioctl(SIOCGIFFLAGS) on %s: %s", ifi->name, + fatalx("ioctl(SIOCGIFFLAGS) on %s: %s", ifi->name, strerror(errno)); } @@ -285,7 +286,7 @@ interface_status(struct interface_info *ifi) */ #ifdef DEBUG if (errno != EINVAL && errno != ENOTTY) - debug("ioctl(SIOCGIFMEDIA) on %s: %s", ifi->name, + log_debug("ioctl(SIOCGIFMEDIA) on %s: %s", ifi->name, strerror(errno)); #endif @@ -338,7 +339,7 @@ get_rdomain(char *name) struct ifreq ifr; if ((s = socket(AF_INET, SOCK_DGRAM, 0)) == -1) - error("get_rdomain socket: %s", strerror(errno)); + fatalx("get_rdomain socket: %s", strerror(errno)); memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name)); diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c index ad93a6cd0e6..53dee2b7129 100644 --- a/sbin/dhclient/kroute.c +++ b/sbin/dhclient/kroute.c @@ -1,4 +1,4 @@ -/* $OpenBSD: kroute.c,v 1.81 2016/08/23 09:26:02 mpi Exp $ */ +/* $OpenBSD: kroute.c,v 1.82 2017/02/12 13:15:50 krw Exp $ */ /* * Copyright 2012 Kenneth R Westerback <krw@openbsd.org> @@ -41,6 +41,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" #include "privsep.h" struct in_addr active_addr; @@ -74,7 +75,7 @@ flush_routes(void) rslt = imsg_compose(unpriv_ibuf, IMSG_FLUSH_ROUTES, 0, 0, -1, &imsg, sizeof(imsg)); if (rslt == -1) - warning("flush_routes: imsg_compose: %s", strerror(errno)); + log_warnx("flush_routes: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("flush_routes"); } @@ -124,14 +125,14 @@ priv_flush_routes(struct interface_info *ifi, struct imsg_flush_routes *imsg) } if (errmsg) { - warning("route cleanup failed - %s %s (msize=%zu)", + log_warnx("route cleanup failed - %s %s (msize=%zu)", errmsg, strerror(errno), needed); free(buf); return; } if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) - error("opening socket to flush routes: %s", strerror(errno)); + fatalx("opening socket to flush routes: %s", strerror(errno)); lim = buf + needed; for (next = buf; next < lim; next += rtm->rtm_msglen) { @@ -193,7 +194,7 @@ add_route(struct in_addr dest, struct in_addr netmask, rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ROUTE, 0, 0, -1, &imsg, sizeof(imsg)); if (rslt == -1) - warning("add_route: imsg_compose: %s", strerror(errno)); + log_warnx("add_route: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("add_route"); } @@ -210,7 +211,7 @@ priv_add_route(struct interface_info *ifi, struct imsg_add_route *imsg) int s, i, iovcnt = 0; if ((s = socket(AF_ROUTE, SOCK_RAW, 0)) == -1) - error("Routing Socket open failed: %s", strerror(errno)); + fatalx("Routing Socket open failed: %s", strerror(errno)); memset(destbuf, 0, sizeof(destbuf)); memset(maskbuf, 0, sizeof(maskbuf)); @@ -302,7 +303,7 @@ priv_add_route(struct interface_info *ifi, struct imsg_add_route *imsg) if (writev(s, iov, iovcnt) != -1) break; if (i == 4) - warning("failed to add route (%s/%s via %s/%s): %s", + log_warnx("failed to add route (%s/%s via %s/%s): %s", destbuf, maskbuf, gatewaybuf, ifabuf, strerror(errno)); else if (errno == EEXIST || errno == ENETUNREACH) @@ -322,7 +323,7 @@ delete_addresses(struct interface_info *ifi) struct ifaddrs *ifap, *ifa; if (getifaddrs(&ifap) != 0) - error("delete_addresses getifaddrs: %s", strerror(errno)); + fatalx("delete_addresses getifaddrs: %s", strerror(errno)); for (ifa = ifap; ifa; ifa = ifa->ifa_next) { if ((ifa->ifa_flags & IFF_LOOPBACK) || @@ -360,7 +361,7 @@ delete_address(struct in_addr addr) rslt = imsg_compose(unpriv_ibuf, IMSG_DELETE_ADDRESS, 0, 0 , -1, &imsg, sizeof(imsg)); if (rslt == -1) - warning("delete_address: imsg_compose: %s", strerror(errno)); + log_warnx("delete_address: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("delete_address"); } @@ -378,7 +379,7 @@ priv_delete_address(struct interface_info *ifi, */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) - error("socket open failed: %s", strerror(errno)); + fatalx("socket open failed: %s", strerror(errno)); memset(&ifaliasreq, 0, sizeof(ifaliasreq)); strncpy(ifaliasreq.ifra_name, ifi->name, sizeof(ifaliasreq.ifra_name)); @@ -391,7 +392,7 @@ priv_delete_address(struct interface_info *ifi, /* SIOCDIFADDR will result in a RTM_DELADDR message we must catch! */ if (ioctl(s, SIOCDIFADDR, &ifaliasreq) == -1) { if (errno != EADDRNOTAVAIL) - warning("SIOCDIFADDR failed (%s): %s", + log_warnx("SIOCDIFADDR failed (%s): %s", inet_ntoa(imsg->addr), strerror(errno)); } @@ -414,7 +415,7 @@ set_interface_mtu(int mtu) rslt = imsg_compose(unpriv_ibuf, IMSG_SET_INTERFACE_MTU, 0, 0, -1, &imsg, sizeof(imsg)); if (rslt == -1) - warning("set_interface_mtu: imsg_compose: %s", strerror(errno)); + log_warnx("set_interface_mtu: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("set_interface_mtu"); } @@ -432,9 +433,9 @@ priv_set_interface_mtu(struct interface_info *ifi, ifr.ifr_mtu = imsg->mtu; if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) - error("socket open failed: %s", strerror(errno)); + fatalx("socket open failed: %s", strerror(errno)); if (ioctl(s, SIOCSIFMTU, &ifr) == -1) - warning("SIOCSIFMTU failed (%d): %s", imsg->mtu, + log_warnx("SIOCSIFMTU failed (%d): %s", imsg->mtu, strerror(errno)); close(s); } @@ -459,7 +460,7 @@ add_address(struct in_addr addr, struct in_addr mask) rslt = imsg_compose(unpriv_ibuf, IMSG_ADD_ADDRESS, 0, 0, -1, &imsg, sizeof(imsg)); if (rslt == -1) - warning("add_address: imsg_compose: %s", strerror(errno)); + log_warnx("add_address: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("add_address"); } @@ -483,7 +484,7 @@ priv_add_address(struct interface_info *ifi, struct imsg_add_address *imsg) */ if ((s = socket(AF_INET, SOCK_STREAM, 0)) == -1) - error("socket open failed: %s", strerror(errno)); + fatalx("socket open failed: %s", strerror(errno)); memset(&ifaliasreq, 0, sizeof(ifaliasreq)); strncpy(ifaliasreq.ifra_name, ifi->name, sizeof(ifaliasreq.ifra_name)); @@ -503,7 +504,7 @@ priv_add_address(struct interface_info *ifi, struct imsg_add_address *imsg) /* No need to set broadcast address. Kernel can figure it out. */ if (ioctl(s, SIOCAIFADDR, &ifaliasreq) == -1) - warning("SIOCAIFADDR failed (%s): %s", inet_ntoa(imsg->addr), + log_warnx("SIOCAIFADDR failed (%s): %s", inet_ntoa(imsg->addr), strerror(errno)); close(s); @@ -528,7 +529,7 @@ sendhup(struct client_lease *active) rslt = imsg_compose(unpriv_ibuf, IMSG_HUP, 0, 0, -1, &imsg, sizeof(imsg)); if (rslt == -1) - warning("sendhup: imsg_compose: %s", strerror(errno)); + log_warnx("sendhup: imsg_compose: %s", strerror(errno)); flush_unpriv_ibuf("sendhup"); } @@ -572,7 +573,7 @@ resolv_conf_priority(struct interface_info *ifi) s = socket(PF_ROUTE, SOCK_RAW, AF_INET); if (s == -1) { - warning("default route socket: %s", strerror(errno)); + log_warnx("default route socket: %s", strerror(errno)); return (0); } @@ -607,7 +608,7 @@ resolv_conf_priority(struct interface_info *ifi) if (writev(s, iov, iovcnt) == -1) { if (errno != ESRCH) - warning("RTM_GET of default route: %s", + log_warnx("RTM_GET of default route: %s", strerror(errno)); goto done; } @@ -617,10 +618,10 @@ resolv_conf_priority(struct interface_info *ifi) do { len = read(s, &m_rtmsg, sizeof(m_rtmsg)); if (len == -1) { - warning("get default route read: %s", strerror(errno)); + log_warnx("get default route read: %s", strerror(errno)); break; } else if (len == 0) { - warning("no data from default route read"); + log_warnx("no data from default route read"); break; } if (m_rtmsg.m_rtm.rtm_version != RTM_VERSION) @@ -629,7 +630,7 @@ resolv_conf_priority(struct interface_info *ifi) m_rtmsg.m_rtm.rtm_pid == pid && m_rtmsg.m_rtm.rtm_seq == seq) { if (m_rtmsg.m_rtm.rtm_errno) { - warning("default route read rtm: %s", + log_warnx("default route read rtm: %s", strerror(m_rtmsg.m_rtm.rtm_errno)); goto done; } @@ -662,12 +663,12 @@ create_route_label(struct sockaddr_rtlabel *label) (int)getpid()); if (len == -1) { - warning("creating route label: %s", strerror(errno)); + log_warnx("creating route label: %s", strerror(errno)); return (1); } if (len >= sizeof(label->sr_label)) { - warning("creating route label: label too long (%d vs %zu)", len, + log_warnx("creating route label: label too long (%d vs %zu)", len, sizeof(label->sr_label)); return (1); } @@ -737,9 +738,9 @@ delete_route(struct interface_info *ifi, int s, struct rt_msghdr *rtm) rlen = write(s, (char *)rtm, rtm->rtm_msglen); if (rlen == -1) { if (errno != ESRCH) - error("RTM_DELETE write: %s", strerror(errno)); + fatalx("RTM_DELETE write: %s", strerror(errno)); } else if (rlen < (int)rtm->rtm_msglen) - error("short RTM_DELETE write (%zd)\n", rlen); + fatalx("short RTM_DELETE write (%zd)\n", rlen); } void @@ -752,7 +753,7 @@ flush_unpriv_ibuf(const char *who) if (quit == 0) quit = INTERNALSIG; if (errno != EPIPE && errno != 0) - warning("%s: msgbuf_write: %s", who, + log_warnx("%s: msgbuf_write: %s", who, strerror(errno)); break; } diff --git a/sbin/dhclient/log.c b/sbin/dhclient/log.c new file mode 100644 index 00000000000..100c052951b --- /dev/null +++ b/sbin/dhclient/log.c @@ -0,0 +1,199 @@ +/* $OpenBSD: log.c,v 1.1 2017/02/12 13:15:50 krw Exp $ */ + +/* + * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include <stdio.h> +#include <stdlib.h> +#include <stdarg.h> +#include <string.h> +#include <syslog.h> +#include <errno.h> +#include <time.h> + +#include "log.h" + +static int debug; +static int verbose; +static const char *log_procname; + +void +log_init(int n_debug, int facility) +{ + extern char *__progname; + + debug = n_debug; + verbose = n_debug; + log_procinit(__progname); + + if (!debug) + openlog(__progname, LOG_PID | LOG_NDELAY, facility); + + tzset(); +} + +void +log_procinit(const char *procname) +{ + if (procname != NULL) + log_procname = procname; +} + +void +log_setverbose(int v) +{ + verbose = v; +} + +int +log_getverbose(void) +{ + return (verbose); +} + +void +logit(int pri, const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + vlog(pri, fmt, ap); + va_end(ap); +} + +void +vlog(int pri, const char *fmt, va_list ap) +{ + char *nfmt; + int saved_errno = errno; + + if (debug) { + /* best effort in out of mem situations */ + if (asprintf(&nfmt, "%s\n", fmt) == -1) { + vfprintf(stderr, fmt, ap); + fprintf(stderr, "\n"); + } else { + vfprintf(stderr, nfmt, ap); + free(nfmt); + } + fflush(stderr); + } else + vsyslog(pri, fmt, ap); + + errno = saved_errno; +} + +void +log_warn(const char *emsg, ...) +{ + char *nfmt; + va_list ap; + int saved_errno = errno; + + /* best effort to even work in out of memory situations */ + if (emsg == NULL) + logit(LOG_CRIT, "%s", strerror(saved_errno)); + else { + va_start(ap, emsg); + + if (asprintf(&nfmt, "%s: %s", emsg, + strerror(saved_errno)) == -1) { + /* we tried it... */ + vlog(LOG_CRIT, emsg, ap); + logit(LOG_CRIT, "%s", strerror(saved_errno)); + } else { + vlog(LOG_CRIT, nfmt, ap); + free(nfmt); + } + va_end(ap); + } + + errno = saved_errno; +} + +void +log_warnx(const char *emsg, ...) +{ + va_list ap; + + va_start(ap, emsg); + vlog(LOG_CRIT, emsg, ap); + va_end(ap); +} + +void +log_info(const char *emsg, ...) +{ + va_list ap; + + va_start(ap, emsg); + vlog(LOG_INFO, emsg, ap); + va_end(ap); +} + +void +log_debug(const char *emsg, ...) +{ + va_list ap; + + if (verbose) { + va_start(ap, emsg); + vlog(LOG_DEBUG, emsg, ap); + va_end(ap); + } +} + +static void +vfatalc(int code, const char *emsg, va_list ap) +{ + static char s[BUFSIZ]; + const char *sep; + + if (emsg != NULL) { + (void)vsnprintf(s, sizeof(s), emsg, ap); + sep = ": "; + } else { + s[0] = '\0'; + sep = ""; + } + if (code) + logit(LOG_CRIT, "fatal in %s: %s%s%s", + log_procname, s, sep, strerror(code)); + else + logit(LOG_CRIT, "fatal in %s%s%s", log_procname, sep, s); +} + +void +fatal(const char *emsg, ...) +{ + va_list ap; + + va_start(ap, emsg); + vfatalc(errno, emsg, ap); + va_end(ap); + exit(1); +} + +void +fatalx(const char *emsg, ...) +{ + va_list ap; + + va_start(ap, emsg); + vfatalc(0, emsg, ap); + va_end(ap); + exit(1); +} diff --git a/sbin/dhclient/log.h b/sbin/dhclient/log.h new file mode 100644 index 00000000000..62365de8d0c --- /dev/null +++ b/sbin/dhclient/log.h @@ -0,0 +1,46 @@ +/* $OpenBSD: log.h,v 1.1 2017/02/12 13:15:50 krw Exp $ */ + +/* + * Copyright (c) 2003, 2004 Henning Brauer <henning@openbsd.org> + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef LOG_H +#define LOG_H + +#include <stdarg.h> +#include <sys/cdefs.h> + +void log_init(int, int); +void log_procinit(const char *); +void log_setverbose(int); +int log_getverbose(void); +void log_warn(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_warnx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_info(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void log_debug(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +void logit(int, const char *, ...) + __attribute__((__format__ (printf, 2, 3))); +void vlog(int, const char *, va_list) + __attribute__((__format__ (printf, 2, 0))); +__dead void fatal(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); +__dead void fatalx(const char *, ...) + __attribute__((__format__ (printf, 1, 2))); + +#endif /* LOG_H */ diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 93aa1f2b3b0..af2bef35651 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.79 2016/10/06 16:29:17 krw Exp $ */ +/* $OpenBSD: options.c,v 1.80 2017/02/12 13:15:50 krw Exp $ */ /* DHCP options parsing and reassembly. */ @@ -59,6 +59,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" int parse_option_buffer(struct option_data *, unsigned char *, int); int expand_search_domain_name(unsigned char *, size_t, int *, unsigned char *); @@ -93,12 +94,12 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer, if (s + 1 + len < end) { ; /* option data is all there. */ } else { - warning("option %s (%d) larger than buffer.", + log_warnx("option %s (%d) larger than buffer.", dhcp_options[code].name, len); return (0); } } else { - warning("option %s has no length field.", + log_warnx("option %s has no length field.", dhcp_options[code].name); return (0); } @@ -121,7 +122,7 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer, */ if (!options[code].data) { if (!(t = calloc(1, len + 1))) - error("Can't allocate storage for option %s.", + fatalx("Can't allocate storage for option %s.", dhcp_options[code].name); /* * Copy and NUL-terminate the option (in case @@ -138,7 +139,7 @@ parse_option_buffer(struct option_data *options, unsigned char *buffer, */ t = calloc(1, len + options[code].len + 1); if (!t) - error("Can't expand storage for option %s.", + fatalx("Can't expand storage for option %s.", dhcp_options[code].name); memcpy(t, options[code].data, options[code].len); memcpy(t + options[code].len, &s[2], len); @@ -331,7 +332,7 @@ expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, /* This is a pointer to another list of labels. */ if (i + 1 >= srclen) { /* The pointer is truncated. */ - warning("Truncated pointer in DHCP Domain " + log_warnx("Truncated pointer in DHCP Domain " "Search option."); return (-1); } @@ -342,7 +343,7 @@ expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, * The pointer must indicates a prior * occurance. */ - warning("Invalid forward pointer in DHCP " + log_warnx("Invalid forward pointer in DHCP " "Domain Search option compression."); return (-1); } @@ -355,7 +356,7 @@ expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, return (domain_name_len); } if (i + label_len + 1 > srclen) { - warning("Truncated label in DHCP Domain Search " + log_warnx("Truncated label in DHCP Domain Search " "option."); return (-1); } @@ -367,7 +368,7 @@ expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, if (strlen(domain_search) + domain_name_len >= DHCP_DOMAIN_SEARCH_LEN) { - warning("Domain search list too long."); + log_warnx("Domain search list too long."); return (-1); } @@ -380,7 +381,7 @@ expand_search_domain_name(unsigned char *src, size_t srclen, int *offset, cursor += label_len + 1; } - warning("Truncated DHCP Domain Search option."); + log_warnx("Truncated DHCP Domain Search option."); return (-1); } @@ -398,7 +399,7 @@ pretty_print_domain_search(unsigned char *dst, size_t dstlen, domain_search = calloc(1, DHCP_DOMAIN_SEARCH_LEN); if (domain_search == NULL) - error("Can't allocate storage for expanded domain-search\n"); + fatalx("Can't allocate storage for expanded domain-search\n"); /* Compute expanded length. */ expanded_len = len = 0; @@ -455,7 +456,7 @@ pretty_print_option(unsigned int code, struct option_data *option, /* Code should be between 0 and 255. */ if (code > 255) { - warning("pretty_print_option: bad code %d", code); + log_warnx("pretty_print_option: bad code %d", code); goto done; } @@ -479,7 +480,7 @@ pretty_print_option(unsigned int code, struct option_data *option, /* Figure out the size of the data. */ for (i = 0; dhcp_options[code].format[i]; i++) { if (!numhunk) { - warning("%s: Excess information in format string: %s", + log_warnx("%s: Excess information in format string: %s", dhcp_options[code].name, &(dhcp_options[code].format[i])); goto done; @@ -492,7 +493,7 @@ pretty_print_option(unsigned int code, struct option_data *option, fmtbuf[i] = 0; numhunk = 0; if (hunksize == 0) { - warning("%s: no size indicator before A" + log_warnx("%s: no size indicator before A" " in format string: %s", dhcp_options[code].name, dhcp_options[code].format); @@ -533,7 +534,7 @@ pretty_print_option(unsigned int code, struct option_data *option, case 'e': break; default: - warning("%s: garbage in format string: %s", + log_warnx("%s: garbage in format string: %s", dhcp_options[code].name, &(dhcp_options[code].format[i])); goto done; @@ -542,13 +543,13 @@ pretty_print_option(unsigned int code, struct option_data *option, /* Check for too few bytes. */ if (hunksize > len) { - warning("%s: expecting at least %d bytes; got %d", + log_warnx("%s: expecting at least %d bytes; got %d", dhcp_options[code].name, hunksize, len); goto done; } /* Check for too many bytes. */ if (numhunk == -1 && hunksize < len) { - warning("%s: expecting only %d bytes: got %d", + log_warnx("%s: expecting only %d bytes: got %d", dhcp_options[code].name, hunksize, len); goto done; } @@ -558,7 +559,7 @@ pretty_print_option(unsigned int code, struct option_data *option, numhunk = len / hunksize; /* See if we got an exact number of hunks. */ if (numhunk > 0 && numhunk * hunksize != len) { - warning("%s: expecting %d bytes: got %d", + log_warnx("%s: expecting %d bytes: got %d", dhcp_options[code].name, numhunk * hunksize, len); goto done; } @@ -613,7 +614,7 @@ pretty_print_option(unsigned int code, struct option_data *option, dp++; break; default: - warning("Unexpected format code %c", fmtbuf[j]); + log_warnx("Unexpected format code %c", fmtbuf[j]); goto toobig; } if (opcount >= opleft || opcount == -1) @@ -660,14 +661,14 @@ do_packet(struct interface_info *ifi, unsigned int from_port, if (packet->hlen != ETHER_ADDR_LEN) { #ifdef DEBUG - debug("Discarding packet with hlen != %s (%u)", + log_debug("Discarding packet with hlen != %s (%u)", ifi->name, packet->hlen); #endif return; } else if (memcmp(&ifi->hw_address, packet->chaddr, sizeof(ifi->hw_address))) { #ifdef DEBUG - debug("Discarding packet with chaddr != %s (%s)", ifi->name, + log_debug("Discarding packet with chaddr != %s (%s)", ifi->name, ether_ntoa((struct ether_addr *)packet->chaddr)); #endif return; @@ -675,7 +676,7 @@ do_packet(struct interface_info *ifi, unsigned int from_port, if (client->xid != client->packet.xid) { #ifdef DEBUG - debug("Discarding packet with XID != %u (%u)", client->xid, + log_debug("Discarding packet with XID != %u (%u)", client->xid, client->packet.xid); #endif return; @@ -684,7 +685,7 @@ do_packet(struct interface_info *ifi, unsigned int from_port, TAILQ_FOREACH(ap, &config->reject_list, next) if (from.s_addr == ap->addr.s_addr) { #ifdef DEBUG - debug("Discarding packet from address on reject list " + log_debug("Discarding packet from address on reject list " "(%s)", inet_ntoa(from)); #endif return; @@ -722,7 +723,7 @@ do_packet(struct interface_info *ifi, unsigned int from_port, memcmp(options[i].data, config->send_options[i].data, options[i].len) != 0)) { #ifdef DEBUG - debug("Discarding packet with client-identifier '%s'", + log_debug("Discarding packet with client-identifier '%s'", pretty_print_option(i, &options[i], 0)); #endif goto done; @@ -749,7 +750,7 @@ do_packet(struct interface_info *ifi, unsigned int from_port, break; default: #ifdef DEBUG - debug("Discarding DHCP packet of unknown type (%d)", + log_debug("Discarding DHCP packet of unknown type (%d)", options[DHO_DHCP_MESSAGE_TYPE].data[0]); #endif break; @@ -759,14 +760,14 @@ do_packet(struct interface_info *ifi, unsigned int from_port, type = "BOOTREPLY"; } else { #ifdef DEBUG - debug("Discarding packet which is neither DHCP nor BOOTP"); + log_debug("Discarding packet which is neither DHCP nor BOOTP"); #endif } rslt = asprintf(&info, "%s from %s (%s)", type, inet_ntoa(from), ether_ntoa(hfrom)); if (rslt == -1) - error("no memory for info string"); + fatalx("no memory for info string"); if (handler) (*handler)(ifi, from, options, info); diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c index 418583585fb..7fb19fa6e8a 100644 --- a/sbin/dhclient/packet.c +++ b/sbin/dhclient/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.31 2016/08/23 09:26:02 mpi Exp $ */ +/* $OpenBSD: packet.c,v 1.32 2017/02/12 13:15:50 krw Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -57,6 +57,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" u_int32_t checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum) @@ -145,7 +146,7 @@ decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, ip_packets_bad_checksum++; if (ip_packets_seen > 4 && ip_packets_bad_checksum != 0 && (ip_packets_seen / ip_packets_bad_checksum) < 2) { - note("%d bad IP checksums seen in %d packets", + log_info("%d bad IP checksums seen in %d packets", ip_packets_bad_checksum, ip_packets_seen); ip_packets_seen = ip_packets_bad_checksum = 0; } @@ -156,7 +157,7 @@ decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, #ifdef DEBUG if (ntohs(ip->ip_len) != buflen) - debug("ip length %hu disagrees with bytes received %d.", + log_debug("ip length %hu disagrees with bytes received %d.", ntohs(ip->ip_len), buflen); #endif @@ -188,7 +189,7 @@ decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, udp_packets_length_overflow != 0 && (udp_packets_length_checked / udp_packets_length_overflow) < 2) { - note("%d udp packets in %d too long - dropped", + log_info("%d udp packets in %d too long - dropped", udp_packets_length_overflow, udp_packets_length_checked); udp_packets_length_overflow = @@ -198,7 +199,7 @@ decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, } #ifdef DEBUG if (len + data != buf + bufix + buflen) - debug("accepting packet with data after udp payload."); + log_debug("accepting packet with data after udp payload."); #endif usum = udp->uh_sum; @@ -214,7 +215,7 @@ decode_udp_ip_header(unsigned char *buf, int bufix, struct sockaddr_in *from, udp_packets_bad_checksum++; if (udp_packets_seen > 4 && udp_packets_bad_checksum != 0 && (udp_packets_seen / udp_packets_bad_checksum) < 2) { - note("%d bad udp checksums in %d packets", + log_info("%d bad udp checksums in %d packets", udp_packets_bad_checksum, udp_packets_seen); udp_packets_seen = udp_packets_bad_checksum = 0; } diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index d71242596e9..8de21943414 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.41 2017/02/11 16:12:36 krw Exp $ */ +/* $OpenBSD: parse.c,v 1.42 2017/02/12 13:15:50 krw Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -61,6 +61,7 @@ #include "dhcp.h" #include "dhcpd.h" #include "dhctoken.h" +#include "log.h" /* * Skip to the semicolon ending the current statement. If we encounter @@ -144,7 +145,7 @@ parse_string(FILE *cfile) } s = strdup(val); if (!s) - error("no memory for string %s.", val); + fatalx("no memory for string %s.", val); if (!parse_semi(cfile)) { free(s); @@ -413,11 +414,13 @@ parse_date(FILE *cfile) return (guess); } +int warnings_occurred; + void parse_warn(char *msg) { static char spaces[81]; - extern char mbuf[1024]; + static char mbuf[1024]; struct iovec iov[6]; size_t iovcnt; int i; diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c index 6493c5d7f55..e48a5d5c485 100644 --- a/sbin/dhclient/privsep.c +++ b/sbin/dhclient/privsep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: privsep.c,v 1.42 2016/09/02 15:44:26 mpi Exp $ */ +/* $OpenBSD: privsep.c,v 1.43 2017/02/12 13:15:50 krw Exp $ */ /* * Copyright (c) 2004 Henning Brauer <henning@openbsd.org> @@ -32,6 +32,7 @@ #include "dhcp.h" #include "dhcpd.h" +#include "log.h" #include "privsep.h" void @@ -42,7 +43,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) for (;;) { if ((n = imsg_get(ibuf, &imsg)) == -1) - error("dispatch_imsg: imsg_get failure: %s", + fatalx("dispatch_imsg: imsg_get failure: %s", strerror(errno)); if (n == 0) @@ -52,7 +53,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) case IMSG_DELETE_ADDRESS: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_delete_address)) - warning("bad IMSG_DELETE_ADDRESS"); + log_warnx("bad IMSG_DELETE_ADDRESS"); else priv_delete_address(ifi, imsg.data); break; @@ -60,7 +61,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) case IMSG_ADD_ADDRESS: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_add_address)) - warning("bad IMSG_ADD_ADDRESS"); + log_warnx("bad IMSG_ADD_ADDRESS"); else priv_add_address(ifi, imsg.data); break; @@ -68,7 +69,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) case IMSG_FLUSH_ROUTES: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_flush_routes)) - warning("bad IMSG_FLUSH_ROUTES"); + log_warnx("bad IMSG_FLUSH_ROUTES"); else priv_flush_routes(ifi, imsg.data); break; @@ -76,7 +77,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) case IMSG_ADD_ROUTE: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_add_route)) - warning("bad IMSG_ADD_ROUTE"); + log_warnx("bad IMSG_ADD_ROUTE"); else priv_add_route(ifi, imsg.data); break; @@ -84,7 +85,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) case IMSG_SET_INTERFACE_MTU: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_set_interface_mtu)) - warning("bad IMSG_SET_INTERFACE_MTU"); + log_warnx("bad IMSG_SET_INTERFACE_MTU"); else priv_set_interface_mtu(ifi, imsg.data); break; @@ -92,7 +93,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) case IMSG_HUP: if (imsg.hdr.len != IMSG_HEADER_SIZE + sizeof(struct imsg_hup)) - warning("bad IMSG_HUP"); + log_warnx("bad IMSG_HUP"); else { ifi->flags |= IFI_HUP; quit = SIGHUP; @@ -107,7 +108,7 @@ dispatch_imsg(struct interface_info *ifi, struct imsgbuf *ibuf) break; default: - warning("received unknown message, code %u", + log_warnx("received unknown message, code %u", imsg.hdr.type); } |