aboutsummaryrefslogtreecommitdiff
path: root/sbin/dhclient
diff options
context:
space:
mode:
authorBrooks Davis <brooks@FreeBSD.org>2005-09-10 17:01:16 +0000
committerBrooks Davis <brooks@FreeBSD.org>2005-09-10 17:01:16 +0000
commitc6fdfded4bc5fc589cfec0f841cd0e55d36ddcf0 (patch)
treedb4f3ddac84c903f3623e29d2dfb7885f5695c38 /sbin/dhclient
parentb0d4cfb03ff6ba02c6bb8476302e8388d87b1c82 (diff)
Notes
Diffstat (limited to 'sbin/dhclient')
-rw-r--r--sbin/dhclient/alloc.c3
-rw-r--r--sbin/dhclient/bpf.c4
-rw-r--r--sbin/dhclient/clparse.c3
-rw-r--r--sbin/dhclient/conflex.c6
-rw-r--r--sbin/dhclient/convert.c3
-rw-r--r--sbin/dhclient/dhclient-script34
-rw-r--r--sbin/dhclient/dhclient.c84
-rw-r--r--sbin/dhclient/dispatch.c3
-rw-r--r--sbin/dhclient/errwarn.c3
-rw-r--r--sbin/dhclient/hash.c3
-rw-r--r--sbin/dhclient/inet.c3
-rw-r--r--sbin/dhclient/options.c3
-rw-r--r--sbin/dhclient/packet.c3
-rw-r--r--sbin/dhclient/parse.c4
-rw-r--r--sbin/dhclient/privsep.c3
-rw-r--r--sbin/dhclient/tables.c4
-rw-r--r--sbin/dhclient/tree.c3
17 files changed, 142 insertions, 27 deletions
diff --git a/sbin/dhclient/alloc.c b/sbin/dhclient/alloc.c
index cabb76d42989..cd60ceca7d83 100644
--- a/sbin/dhclient/alloc.c
+++ b/sbin/dhclient/alloc.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
struct string_list *
diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c
index 911acb49407f..53e2afde6c16 100644
--- a/sbin/dhclient/bpf.c
+++ b/sbin/dhclient/bpf.c
@@ -1,5 +1,4 @@
/* $OpenBSD: bpf.c,v 1.13 2004/05/05 14:28:58 deraadt Exp $ */
-/* $FreeBSD$ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -41,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include <sys/ioctl.h>
#include <sys/uio.h>
diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c
index 2777902c7767..e43a876e0310 100644
--- a/sbin/dhclient/clparse.c
+++ b/sbin/dhclient/clparse.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include "dhctoken.h"
diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c
index ee96bfeb9ca0..3c8932dbd5b2 100644
--- a/sbin/dhclient/conflex.c
+++ b/sbin/dhclient/conflex.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <ctype.h>
#include "dhcpd.h"
@@ -101,7 +104,7 @@ get_char(FILE *cfile)
lpos = 1;
cur_line[0] = 0;
} else if (c != EOF) {
- if (lpos <= 81) {
+ if (lpos < sizeof(line1)) {
cur_line[lpos - 1] = c;
cur_line[lpos] = 0;
}
@@ -233,6 +236,7 @@ read_string(FILE *cfile)
}
if (bs) {
bs = 0;
+ i--;
tokbuf[i] = c;
} else if (c == '\\')
bs = 1;
diff --git a/sbin/dhclient/convert.c b/sbin/dhclient/convert.c
index 0626dc4b3a8e..adca0929a07c 100644
--- a/sbin/dhclient/convert.c
+++ b/sbin/dhclient/convert.c
@@ -43,6 +43,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
u_int32_t
diff --git a/sbin/dhclient/dhclient-script b/sbin/dhclient/dhclient-script
index 0e446b4aef62..fbf6e39a63b1 100644
--- a/sbin/dhclient/dhclient-script
+++ b/sbin/dhclient/dhclient-script
@@ -20,7 +20,6 @@
#
NETSTAT=/usr/bin/netstat
-GREP=/usr/bin/grep
AWK=/usr/bin/awk
HOSTNAME=/bin/hostname
@@ -55,15 +54,15 @@ arp_flush() {
}
delete_old_address() {
- ifconfig $interface inet -alias $old_ip_address $medium
+ eval "ifconfig $interface inet -alias $old_ip_address $medium"
}
add_new_address() {
- ifconfig $interface \
+ eval "ifconfig $interface \
inet $new_ip_address \
netmask $new_subnet_mask \
broadcast $new_broadcast_address \
- $medium
+ $medium"
$LOGGER "New IP Address ($interface): $new_ip_address"
$LOGGER "New Subnet Mask ($interface): $new_subnet_mask"
@@ -74,7 +73,7 @@ add_new_address() {
delete_old_alias() {
if [ -n "$alias_ip_address" ]; then
ifconfig $interface inet -alias $alias_ip_address > /dev/null 2>&1
- route delete $alias_ip_address $LOCALHOST > /dev/null 2>&1
+ #route delete $alias_ip_address $LOCALHOST > /dev/null 2>&1
fi
}
@@ -82,12 +81,12 @@ add_new_alias() {
if [ -n "$alias_ip_address" ]; then
ifconfig $interface inet alias $alias_ip_address netmask \
$alias_subnet_mask
- route add $alias_ip_address $LOCALHOST
+ #route add $alias_ip_address $LOCALHOST
fi
}
delete_old_routes() {
- route delete "$old_ip_address" $LOCALHOST >/dev/null 2>&1
+ #route delete "$old_ip_address" $LOCALHOST >/dev/null 2>&1
for router in $old_routers; do
if [ $if_defaultroute = x -o $if_defaultroute = $interface ]; then
route delete default $route >/dev/null 2>&1
@@ -106,7 +105,7 @@ delete_old_routes() {
}
add_new_routes() {
- route add $new_ip_address $LOCALHOST >/dev/null 2>&1
+ #route add $new_ip_address $LOCALHOST >/dev/null 2>&1
for router in $new_routers; do
if [ "$new_ip_address" = "$router" ]; then
route add default -iface $router >/dev/null 2>&1
@@ -152,6 +151,16 @@ add_new_resolv_conf() {
cat /etc/resolv.conf.tail >>/etc/resolv.conf.std
fi
+ # When resolv.conf is not changed actually, we don't
+ # need to update it.
+ # If /usr is not mounted yet, we cannot use cmp, then
+ # the following test fails. In such case, we simply
+ # ignore an error and do update resolv.conf.
+ if cmp -s /etc/resolv.conf.std /etc/resolv.conf; then
+ rm -f /etc/resolv.conf.std
+ return 0
+ fi 2>/dev/null
+
# In case (e.g. during OpenBSD installs) /etc/resolv.conf
# is a symbolic link, take care to preserve the link and write
# the new data in the correct location.
@@ -198,15 +207,15 @@ if [ -f /etc/dhclient-enter-hooks ]; then
fi
if [ -x $NETSTAT ]; then
- if_defaultroute=`$NETSTAT -rn | $GREP "^default" | $AWK '{print $6}'`
+ if_defaultroute=`$NETSTAT -rnf inet | $AWK '{if ($1=="default") printf $6}'`
else
if_defaultroute="x"
fi
case $reason in
MEDIUM)
- ifconfig $interface $medium
- ifconfig $interface inet -alias 0.0.0.0 $medium >/dev/null 2>&1
+ eval "ifconfig $interface $medium"
+ eval "ifconfig $interface inet -alias 0.0.0.0 $medium" >/dev/null 2>&1
sleep 1
;;
@@ -248,6 +257,7 @@ EXPIRE|FAIL)
delete_old_address
delete_old_routes
fi
+ ifconfig $interface delete
# XXX Why add alias we just deleted above?
add_new_alias
if [ -f /etc/resolv.conf.save ]; then
@@ -272,7 +282,7 @@ TIMEOUT)
fi
fi
fi
- ifconfig $interface inet -alias $new_ip_address $medium
+ eval "ifconfig $interface inet -alias $new_ip_address $medium"
delete_old_routes
exit_with_hooks 1
;;
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c
index 9f2b2690b34a..36a64788188d 100644
--- a/sbin/dhclient/dhclient.c
+++ b/sbin/dhclient/dhclient.c
@@ -1,5 +1,4 @@
/* $OpenBSD: dhclient.c,v 1.63 2005/02/06 17:10:13 krw Exp $ */
-/* $FreeBSD$ */
/*
* Copyright 2004 Henning Brauer <henning@openbsd.org>
@@ -54,6 +53,9 @@
* purpose.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include "privsep.h"
@@ -71,6 +73,7 @@
#define alphachar(c) (((c) >= 0x41 && (c) <= 0x5a) || \
((c) >= 0x61 && (c) <= 0x7a))
#define digitchar(c) ((c) >= 0x30 && (c) <= 0x39)
+#define whitechar(c) ((c) == ' ' || (c) == '\t')
#define borderchar(c) (alphachar(c) || digitchar(c))
#define middlechar(c) (borderchar(c) || hyphenchar(c))
@@ -114,6 +117,7 @@ void usage(void);
int check_option(struct client_lease *l, int option);
int ipv4addrs(char * buf);
int res_hnok(const char *dn);
+int check_search(const char *srch);
char *option_as_string(unsigned int code, unsigned char *data, int len);
int fork_privchld(int, int);
@@ -1831,22 +1835,26 @@ void
priv_script_write_params(char *prefix, struct client_lease *lease)
{
struct interface_info *ip = ifi;
- u_int8_t dbuf[1500];
- int i, len = 0;
+ u_int8_t dbuf[1500], *dp = NULL;
+ int i, len;
char tbuf[128];
script_set_env(ip->client, prefix, "ip_address",
piaddr(lease->address));
- if (lease->options[DHO_SUBNET_MASK].len &&
- (lease->options[DHO_SUBNET_MASK].len <
- sizeof(lease->address.iabuf))) {
+ if (ip->client->config->default_actions[DHO_SUBNET_MASK] ==
+ ACTION_SUPERSEDE) {
+ dp = ip->client->config->defaults[DHO_SUBNET_MASK].data;
+ len = ip->client->config->defaults[DHO_SUBNET_MASK].len;
+ } else {
+ dp = lease->options[DHO_SUBNET_MASK].data;
+ len = lease->options[DHO_SUBNET_MASK].len;
+ }
+ if (len && (len < sizeof(lease->address.iabuf))) {
struct iaddr netmask, subnet, broadcast;
- memcpy(netmask.iabuf, lease->options[DHO_SUBNET_MASK].data,
- lease->options[DHO_SUBNET_MASK].len);
- netmask.len = lease->options[DHO_SUBNET_MASK].len;
-
+ memcpy(netmask.iabuf, dp, len);
+ netmask.len = len;
subnet = subnet_number(lease->address, netmask);
if (subnet.len) {
script_set_env(ip->client, prefix, "network_number",
@@ -1867,7 +1875,7 @@ priv_script_write_params(char *prefix, struct client_lease *lease)
script_set_env(ip->client, prefix, "server_name",
lease->server_name);
for (i = 0; i < 256; i++) {
- u_int8_t *dp = NULL;
+ len = 0;
if (ip->client->config->defaults[i].len) {
if (lease->options[i].len) {
@@ -2248,6 +2256,14 @@ check_option(struct client_lease *l, int option)
}
return (1);
case DHO_DOMAIN_NAME:
+ if (!res_hnok(sbuf)) {
+ if (!check_search(sbuf)) {
+ warning("Bogus domain search list %d: %s (%s)",
+ option, sbuf, opbuf);
+ return (0);
+ }
+ }
+ return (1);
case DHO_PAD:
case DHO_TIME_OFFSET:
case DHO_BOOT_SIZE:
@@ -2323,6 +2339,52 @@ res_hnok(const char *dn)
return (1);
}
+int
+check_search(const char *srch)
+{
+ int pch = PERIOD, ch = *srch++;
+ int domains = 1;
+
+ /* 256 char limit re resolv.conf(5) */
+ if (strlen(srch) > 256)
+ return (0);
+
+ while (whitechar(ch))
+ ch = *srch++;
+
+ while (ch != '\0') {
+ int nch = *srch++;
+
+ if (periodchar(ch) || whitechar(ch)) {
+ ;
+ } else if (periodchar(pch)) {
+ if (!borderchar(ch))
+ return (0);
+ } else if (periodchar(nch) || nch == '\0') {
+ if (!borderchar(ch))
+ return (0);
+ } else {
+ if (!middlechar(ch))
+ return (0);
+ }
+ if (!whitechar(ch)) {
+ pch = ch;
+ } else {
+ while (whitechar(nch)) {
+ nch = *srch++;
+ }
+ if (nch != '\0')
+ domains++;
+ pch = PERIOD;
+ }
+ ch = nch;
+ }
+ /* 6 domain limit re resolv.conf(5) */
+ if (domains > 6)
+ return (0);
+ return (1);
+}
+
/* Does buf consist only of dotted decimal ipv4 addrs?
* return how many if so,
* otherwise, return 0
diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c
index a0d7e90e865a..2fec9136986d 100644
--- a/sbin/dhclient/dispatch.c
+++ b/sbin/dhclient/dispatch.c
@@ -39,6 +39,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include <sys/ioctl.h>
diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c
index 03b75478457c..de3458322fda 100644
--- a/sbin/dhclient/errwarn.c
+++ b/sbin/dhclient/errwarn.c
@@ -40,6 +40,9 @@
* with Vixie Laboratories.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <errno.h>
#include "dhcpd.h"
diff --git a/sbin/dhclient/hash.c b/sbin/dhclient/hash.c
index 4f1795b24351..040236ab735b 100644
--- a/sbin/dhclient/hash.c
+++ b/sbin/dhclient/hash.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
static int do_hash(unsigned char *, int, int);
diff --git a/sbin/dhclient/inet.c b/sbin/dhclient/inet.c
index a52847596e12..4b7b1cef1bad 100644
--- a/sbin/dhclient/inet.c
+++ b/sbin/dhclient/inet.c
@@ -42,6 +42,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
/*
diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c
index 9c8e8fc743f1..09aa4d8ffb64 100644
--- a/sbin/dhclient/options.c
+++ b/sbin/dhclient/options.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include <ctype.h>
#define DHCP_OPTION_DATA
diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c
index 1a22044d40a1..484953ca2d98 100644
--- a/sbin/dhclient/packet.c
+++ b/sbin/dhclient/packet.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include <netinet/in_systm.h>
diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c
index 36eaf7f3bce1..6a54fd0a4c88 100644
--- a/sbin/dhclient/parse.c
+++ b/sbin/dhclient/parse.c
@@ -1,5 +1,4 @@
/* $OpenBSD: parse.c,v 1.11 2004/05/05 23:07:47 deraadt Exp $ */
-/* $FreeBSD$ */
/* Common parser code for dhcpd and dhclient. */
@@ -41,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include "dhctoken.h"
diff --git a/sbin/dhclient/privsep.c b/sbin/dhclient/privsep.c
index cf47e56ceb6e..b42572f2895b 100644
--- a/sbin/dhclient/privsep.c
+++ b/sbin/dhclient/privsep.c
@@ -16,6 +16,9 @@
* OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
#include "privsep.h"
diff --git a/sbin/dhclient/tables.c b/sbin/dhclient/tables.c
index 93ff6acce3df..2c3add2a27c8 100644
--- a/sbin/dhclient/tables.c
+++ b/sbin/dhclient/tables.c
@@ -1,5 +1,4 @@
/* $OpenBSD: tables.c,v 1.4 2004/05/04 20:28:40 deraadt Exp $ */
-/* $FreeBSD$ */
/* Tables of information... */
@@ -41,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
/*
diff --git a/sbin/dhclient/tree.c b/sbin/dhclient/tree.c
index 89ac450ac5ba..0ed2919bb314 100644
--- a/sbin/dhclient/tree.c
+++ b/sbin/dhclient/tree.c
@@ -40,6 +40,9 @@
* Enterprises, see ``http://www.vix.com''.
*/
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
#include "dhcpd.h"
extern int h_errno;