summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2017-07-30 15:26:47 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2017-07-30 15:26:47 +0000
commit40e3361169e7c28fedda8515ec69fa48e26aeff0 (patch)
tree7595ed744daa61327e02ac1093a8e73dad7f6507 /sbin
parentca70287c1ec603f2c7d27d272688c33a668b52c5 (diff)
Use effective_proposal data to build resolv.conf contents.
Fix a missing != NULL, and add a comment on why no search path and no dns servers means resolv.conf.tail is ignored.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/dhclient/dhclient.c18
-rw-r--r--sbin/dhclient/kroute.c66
-rw-r--r--sbin/dhclient/privsep.h6
3 files changed, 42 insertions, 48 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 1f67531e9cf..eb394d5b590 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dhclient.c,v 1.488 2017/07/30 14:05:41 krw Exp $ */
+/* $OpenBSD: dhclient.c,v 1.489 2017/07/30 15:26:46 krw Exp $ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -982,7 +982,6 @@ dhcpnak(struct interface_info *ifi, struct option_data *options, char *info)
void
bind_lease(struct interface_info *ifi)
{
- struct option_data *options;
struct client_lease *lease, *pl;
struct proposal *active_proposal = NULL;
struct proposal *offered_proposal = NULL;
@@ -998,7 +997,6 @@ bind_lease(struct interface_info *ifi)
ifi->offer->resolv_conf = NULL;
lease = apply_defaults(ifi->offer);
- options = lease->options;
set_lease_times(lease);
@@ -1023,15 +1021,17 @@ bind_lease(struct interface_info *ifi)
}
}
- ifi->offer->resolv_conf = resolv_conf_contents(ifi->name,
- &options[DHO_DOMAIN_NAME], &options[DHO_DOMAIN_NAME_SERVERS],
- &options[DHO_DOMAIN_SEARCH]);
-
/* Replace the old active lease with the accepted offer. */
ifi->active = ifi->offer;
ifi->offer = NULL;
effective_proposal = lease_as_proposal(lease);
+ ifi->active->resolv_conf = resolv_conf_contents(ifi->name,
+ effective_proposal->rtsearch,
+ effective_proposal->rtsearch_len,
+ effective_proposal->rtdns,
+ effective_proposal->rtdns_len);
+
set_mtu(effective_proposal->inits, effective_proposal->mtu);
set_address(ifi->name, effective_proposal->ifa,
@@ -1887,8 +1887,8 @@ lease_as_proposal(struct client_lease *lease)
servers = MAXNS;
if (servers > 0) {
proposal->addrs |= RTA_DNS;
- proposal->rtdns_len = opt->len;
- memcpy(proposal->rtdns, opt->data, opt->len);
+ proposal->rtdns_len = servers * sizeof(struct in_addr);
+ memcpy(proposal->rtdns, opt->data, proposal->rtdns_len);
}
}
diff --git a/sbin/dhclient/kroute.c b/sbin/dhclient/kroute.c
index a042b9661cf..704af6f88f8 100644
--- a/sbin/dhclient/kroute.c
+++ b/sbin/dhclient/kroute.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kroute.c,v 1.123 2017/07/30 14:05:41 krw Exp $ */
+/* $OpenBSD: kroute.c,v 1.124 2017/07/30 15:26:46 krw Exp $ */
/*
* Copyright 2012 Kenneth R Westerback <krw@openbsd.org>
@@ -820,56 +820,50 @@ done:
*/
char *
resolv_conf_contents(char *name,
- struct option_data *domainname, struct option_data *nameservers,
- struct option_data *domainsearch)
+ uint8_t *rtsearch, unsigned int rtsearch_len,
+ uint8_t *rtdns, unsigned int rtdns_len)
{
- char *dn, *ns, *nss[MAXNS], *contents, *courtesy, *p, *buf;
+ char *dn, *nss[MAXNS], *contents, *courtesy;
+ struct in_addr *addr;
size_t len;
- int i, rslt;
+ unsigned int i, servers;
+ int rslt;
memset(nss, 0, sizeof(nss));
+ len = 0;
- if (domainsearch->len != 0) {
- buf = pretty_print_domain_search(domainsearch->data,
- domainsearch->len);
- if (buf == NULL)
- dn = strdup("");
- else {
- rslt = asprintf(&dn, "search %s\n", buf);
- if (rslt == -1)
- dn = NULL;
- }
- } else if (domainname->len != 0) {
- rslt = asprintf(&dn, "search %s\n",
- pretty_print_option(DHO_DOMAIN_NAME, domainname, 0));
+ if (rtsearch_len != 0) {
+ rslt = asprintf(&dn, "search %.*s\n", rtsearch_len,
+ rtsearch);
if (rslt == -1)
dn = NULL;
} else
dn = strdup("");
if (dn == NULL)
fatalx("no memory for domainname");
-
- if (nameservers->len != 0) {
- ns = pretty_print_option(DHO_DOMAIN_NAME_SERVERS, nameservers,
- 0);
- for (i = 0; i < MAXNS; i++) {
- p = strsep(&ns, " ");
- if (p == NULL)
- break;
- if (*p == '\0')
- continue;
- rslt = asprintf(&nss[i], "nameserver %s\n", p);
+ len += strlen(dn);
+
+ if (rtdns_len != 0) {
+ addr = (struct in_addr *)rtdns;
+ servers = rtdns_len / sizeof(struct in_addr);
+ if (servers > MAXNS)
+ servers = MAXNS;
+ for (i = 0; i < servers; i++) {
+ rslt = asprintf(&nss[i], "nameserver %s\n",
+ inet_ntoa(*addr));
if (rslt == -1)
fatalx("no memory for nameserver");
+ len += strlen(nss[i]);
+ addr++;
}
}
- len = strlen(dn);
- for (i = 0; i < MAXNS; i++)
- if (nss[i] != NULL)
- len += strlen(nss[i]);
-
- if (len > 0 && config->resolv_tail)
+ /*
+ * XXX historically dhclient-script did not overwrite
+ * resolv.conf when neither search nor dns info
+ * was provided. Is that really what we want?
+ */
+ if (len > 0 && config->resolv_tail != NULL)
len += strlen(config->resolv_tail);
if (len == 0) {
@@ -900,7 +894,7 @@ resolv_conf_contents(char *name,
}
}
- if (config->resolv_tail)
+ if (config->resolv_tail != NULL)
strlcat(contents, config->resolv_tail, len);
return contents;
diff --git a/sbin/dhclient/privsep.h b/sbin/dhclient/privsep.h
index 07ada0d8262..63d88148dd2 100644
--- a/sbin/dhclient/privsep.h
+++ b/sbin/dhclient/privsep.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: privsep.h,v 1.49 2017/07/27 12:45:06 krw Exp $ */
+/* $OpenBSD: privsep.h,v 1.50 2017/07/30 15:26:46 krw Exp $ */
/*
* Copyright (c) 2004 Henning Brauer <henning@openbsd.org>
@@ -54,8 +54,8 @@ int dispatch_imsg(char *, int, int, int, struct imsgbuf *);
void priv_add_route(int, int, struct imsg_add_route *);
void priv_flush_routes(char *, int, int);
-char *resolv_conf_contents(char *, struct option_data *,
- struct option_data *, struct option_data *);
+char *resolv_conf_contents(char *, uint8_t *, unsigned int, uint8_t *,
+ unsigned int);
int resolv_conf_priority(int, int);
void priv_write_resolv_conf(uint8_t *, size_t);