[Midnightbsd-cvs] src [11231] trunk/sbin/dhclient: update dhclient
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Jul 1 17:13:01 EDT 2018
Revision: 11231
http://svnweb.midnightbsd.org/src/?rev=11231
Author: laffer1
Date: 2018-07-01 17:13:00 -0400 (Sun, 01 Jul 2018)
Log Message:
-----------
update dhclient
Modified Paths:
--------------
trunk/sbin/dhclient/Makefile
trunk/sbin/dhclient/alloc.c
trunk/sbin/dhclient/bpf.c
trunk/sbin/dhclient/clparse.c
trunk/sbin/dhclient/conflex.c
trunk/sbin/dhclient/convert.c
trunk/sbin/dhclient/dhclient-script
trunk/sbin/dhclient/dhclient-script.8
trunk/sbin/dhclient/dhclient.8
trunk/sbin/dhclient/dhclient.c
trunk/sbin/dhclient/dhclient.conf
trunk/sbin/dhclient/dhclient.conf.5
trunk/sbin/dhclient/dhclient.leases.5
trunk/sbin/dhclient/dhcp-options.5
trunk/sbin/dhclient/dhcp.h
trunk/sbin/dhclient/dhcpd.h
trunk/sbin/dhclient/dhctoken.h
trunk/sbin/dhclient/dispatch.c
trunk/sbin/dhclient/errwarn.c
trunk/sbin/dhclient/hash.c
trunk/sbin/dhclient/inet.c
trunk/sbin/dhclient/options.c
trunk/sbin/dhclient/packet.c
trunk/sbin/dhclient/parse.c
trunk/sbin/dhclient/privsep.c
trunk/sbin/dhclient/privsep.h
trunk/sbin/dhclient/tables.c
trunk/sbin/dhclient/tree.c
trunk/sbin/dhclient/tree.h
Added Paths:
-----------
trunk/sbin/dhclient/tests/
trunk/sbin/dhclient/tests/Makefile
trunk/sbin/dhclient/tests/fake.c
trunk/sbin/dhclient/tests/option-domain-search.c
Property Changed:
----------------
trunk/sbin/dhclient/dhclient-script
trunk/sbin/dhclient/dhclient-script.8
trunk/sbin/dhclient/dhclient.8
trunk/sbin/dhclient/dhclient.conf
trunk/sbin/dhclient/dhclient.conf.5
trunk/sbin/dhclient/dhclient.leases.5
trunk/sbin/dhclient/dhcp-options.5
Modified: trunk/sbin/dhclient/Makefile
===================================================================
--- trunk/sbin/dhclient/Makefile 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/Makefile 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,5 +1,6 @@
+# $MidnightBSD$
# $OpenBSD: Makefile,v 1.9 2004/05/04 12:52:05 henning Exp $
-# $MidnightBSD$
+# $FreeBSD: stable/10/sbin/dhclient/Makefile 264996 2014-04-27 01:15:10Z jmmv $
#
# Copyright (c) 1996, 1997 The Internet Software Consortium.
# All rights reserved.
@@ -31,6 +32,8 @@
# OF THE POSSIBILITY OF SUCH DAMAGE.
#
+.include <bsd.own.mk>
+
SRCS= dhclient.c clparse.c alloc.c dispatch.c hash.c bpf.c options.c \
tree.c conflex.c errwarn.c inet.c packet.c convert.c tables.c \
parse.c privsep.c
@@ -44,4 +47,8 @@
WARNS?= 2
+.if ${MK_TESTS} != "no"
+SUBDIR+= tests
+.endif
+
.include <bsd.prog.mk>
Modified: trunk/sbin/dhclient/alloc.c
===================================================================
--- trunk/sbin/dhclient/alloc.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/alloc.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: alloc.c,v 1.9 2004/05/04 20:28:40 deraadt Exp $ */
/* Memory allocation... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/alloc.c 149399 2005-08-23 23:59:55Z brooks $");
#include "dhcpd.h"
Modified: trunk/sbin/dhclient/bpf.c
===================================================================
--- trunk/sbin/dhclient/bpf.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/bpf.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: bpf.c,v 1.13 2004/05/05 14:28:58 deraadt Exp $ */
/* BPF socket interface code, originally contributed by Archie Cobbs. */
@@ -41,9 +42,13 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/bpf.c 280250 2015-03-19 12:32:48Z rwatson $");
+#include <sys/capsicum.h>
+
#include "dhcpd.h"
+#include "privsep.h"
+#include <sys/capsicum.h>
#include <sys/ioctl.h>
#include <sys/uio.h>
@@ -61,15 +66,15 @@
* mask.
*/
int
-if_register_bpf(struct interface_info *info)
+if_register_bpf(struct interface_info *info, int flags)
{
char filename[50];
int sock, b;
/* Open a BPF device */
- for (b = 0; 1; b++) {
+ for (b = 0;; b++) {
snprintf(filename, sizeof(filename), BPF_FORMAT, b);
- sock = open(filename, O_RDWR, 0);
+ sock = open(filename, flags);
if (sock < 0) {
if (errno == EBUSY)
continue;
@@ -87,17 +92,82 @@
return (sock);
}
+/*
+ * Packet write filter program:
+ * 'ip and udp and src port bootps and dst port (bootps or bootpc)'
+ */
+struct bpf_insn dhcp_bpf_wfilter[] = {
+ BPF_STMT(BPF_LD + BPF_B + BPF_IND, 14),
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (IPVERSION << 4) + 5, 0, 12),
+
+ /* Make sure this is an IP packet... */
+ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12),
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 10),
+
+ /* Make sure it's a UDP packet... */
+ BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23),
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 8),
+
+ /* Make sure this isn't a fragment... */
+ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20),
+ BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 6, 0), /* patched */
+
+ /* Get the IP header length... */
+ BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14),
+
+ /* Make sure it's from the right port... */
+ BPF_STMT(BPF_LD + BPF_H + BPF_IND, 14),
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 68, 0, 3),
+
+ /* Make sure it is to the right ports ... */
+ BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16),
+ BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
+
+ /* If we passed all the tests, ask for the whole packet. */
+ BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
+
+ /* Otherwise, drop it. */
+ BPF_STMT(BPF_RET+BPF_K, 0),
+};
+
+int dhcp_bpf_wfilter_len = sizeof(dhcp_bpf_wfilter) / sizeof(struct bpf_insn);
+
void
if_register_send(struct interface_info *info)
{
+ cap_rights_t rights;
+ struct bpf_version v;
+ struct bpf_program p;
int sock, on = 1;
- /*
- * If we're using the bpf API for sending and receiving, we
- * don't need to register this interface twice.
- */
- info->wfdesc = info->rfdesc;
+ /* Open a BPF device and hang it on this interface... */
+ info->wfdesc = if_register_bpf(info, O_WRONLY);
+ /* Make sure the BPF version is in range... */
+ if (ioctl(info->wfdesc, BIOCVERSION, &v) < 0)
+ error("Can't get BPF version: %m");
+
+ if (v.bv_major != BPF_MAJOR_VERSION ||
+ v.bv_minor < BPF_MINOR_VERSION)
+ error("Kernel BPF version out of range - recompile dhcpd!");
+
+ /* Set up the bpf write filter program structure. */
+ p.bf_len = dhcp_bpf_wfilter_len;
+ p.bf_insns = dhcp_bpf_wfilter;
+
+ if (dhcp_bpf_wfilter[7].k == 0x1fff)
+ dhcp_bpf_wfilter[7].k = htons(IP_MF|IP_OFFMASK);
+
+ if (ioctl(info->wfdesc, BIOCSETWF, &p) < 0)
+ error("Can't install write filter program: %m");
+
+ if (ioctl(info->wfdesc, BIOCLOCK, NULL) < 0)
+ error("Cannot lock bpf");
+
+ cap_rights_init(&rights, CAP_WRITE);
+ if (cap_rights_limit(info->wfdesc, &rights) < 0 && errno != ENOSYS)
+ error("Can't limit bpf descriptor: %m");
+
/*
* Use raw socket for unicast send.
*/
@@ -144,55 +214,17 @@
int dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(struct bpf_insn);
-/*
- * Packet write filter program:
- * 'ip and udp and src port bootps and dst port (bootps or bootpc)'
- */
-struct bpf_insn dhcp_bpf_wfilter[] = {
- BPF_STMT(BPF_LD + BPF_B + BPF_IND, 14),
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, (IPVERSION << 4) + 5, 0, 12),
-
- /* Make sure this is an IP packet... */
- BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12),
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 10),
-
- /* Make sure it's a UDP packet... */
- BPF_STMT(BPF_LD + BPF_B + BPF_ABS, 23),
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, IPPROTO_UDP, 0, 8),
-
- /* Make sure this isn't a fragment... */
- BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 20),
- BPF_JUMP(BPF_JMP + BPF_JSET + BPF_K, 0x1fff, 6, 0), /* patched */
-
- /* Get the IP header length... */
- BPF_STMT(BPF_LDX + BPF_B + BPF_MSH, 14),
-
- /* Make sure it's from the right port... */
- BPF_STMT(BPF_LD + BPF_H + BPF_IND, 14),
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 68, 0, 3),
-
- /* Make sure it is to the right ports ... */
- BPF_STMT(BPF_LD + BPF_H + BPF_IND, 16),
- BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, 67, 0, 1),
-
- /* If we passed all the tests, ask for the whole packet. */
- BPF_STMT(BPF_RET+BPF_K, (u_int)-1),
-
- /* Otherwise, drop it. */
- BPF_STMT(BPF_RET+BPF_K, 0),
-};
-
-int dhcp_bpf_wfilter_len = sizeof(dhcp_bpf_wfilter) / sizeof(struct bpf_insn);
-
void
if_register_receive(struct interface_info *info)
{
+ static const unsigned long cmds[2] = { SIOCGIFFLAGS, SIOCGIFMEDIA };
+ cap_rights_t rights;
struct bpf_version v;
struct bpf_program p;
int flag = 1, sz;
/* Open a BPF device and hang it on this interface... */
- info->rfdesc = if_register_bpf(info);
+ info->rfdesc = if_register_bpf(info, O_RDONLY);
/* Make sure the BPF version is in range... */
if (ioctl(info->rfdesc, BIOCVERSION, &v) < 0)
@@ -235,48 +267,94 @@
if (ioctl(info->rfdesc, BIOCSETF, &p) < 0)
error("Can't install packet filter program: %m");
- /* Set up the bpf write filter program structure. */
- p.bf_len = dhcp_bpf_wfilter_len;
- p.bf_insns = dhcp_bpf_wfilter;
+ if (ioctl(info->rfdesc, BIOCLOCK, NULL) < 0)
+ error("Cannot lock bpf");
- if (dhcp_bpf_wfilter[7].k == 0x1fff)
- dhcp_bpf_wfilter[7].k = htons(IP_MF|IP_OFFMASK);
+ cap_rights_init(&rights, CAP_IOCTL, CAP_EVENT, CAP_READ);
+ if (cap_rights_limit(info->rfdesc, &rights) < 0 && errno != ENOSYS)
+ error("Can't limit bpf descriptor: %m");
+ if (cap_ioctls_limit(info->rfdesc, cmds, 2) < 0 && errno != ENOSYS)
+ error("Can't limit ioctls for bpf descriptor: %m");
+}
- if (ioctl(info->rfdesc, BIOCSETWF, &p) < 0)
- error("Can't install write filter program: %m");
+void
+send_packet_unpriv(int privfd, struct dhcp_packet *raw, size_t len,
+ struct in_addr from, struct in_addr to)
+{
+ struct imsg_hdr hdr;
+ struct buf *buf;
+ int errs;
- if (ioctl(info->rfdesc, BIOCLOCK, NULL) < 0)
- error("Cannot lock bpf");
+ hdr.code = IMSG_SEND_PACKET;
+ hdr.len = sizeof(hdr) +
+ sizeof(size_t) + len +
+ sizeof(from) + sizeof(to);
+
+ if ((buf = buf_open(hdr.len)) == NULL)
+ error("buf_open: %m");
+
+ errs = 0;
+ errs += buf_add(buf, &hdr, sizeof(hdr));
+ errs += buf_add(buf, &len, sizeof(len));
+ errs += buf_add(buf, raw, len);
+ errs += buf_add(buf, &from, sizeof(from));
+ errs += buf_add(buf, &to, sizeof(to));
+ if (errs)
+ error("buf_add: %m");
+
+ if (buf_close(privfd, buf) == -1)
+ error("buf_close: %m");
}
-ssize_t
-send_packet(struct interface_info *interface, struct dhcp_packet *raw,
- size_t len, struct in_addr from, struct sockaddr_in *to,
- struct hardware *hto)
+void
+send_packet_priv(struct interface_info *interface, struct imsg_hdr *hdr, int fd)
{
unsigned char buf[256];
struct iovec iov[2];
struct msghdr msg;
+ struct dhcp_packet raw;
+ size_t len;
+ struct in_addr from, to;
int result, bufp = 0;
+ if (hdr->len < sizeof(*hdr) + sizeof(size_t))
+ error("corrupted message received");
+ buf_read(fd, &len, sizeof(len));
+ if (hdr->len != sizeof(*hdr) + sizeof(size_t) + len +
+ sizeof(from) + sizeof(to)) {
+ error("corrupted message received");
+ }
+ if (len > sizeof(raw))
+ error("corrupted message received");
+ buf_read(fd, &raw, len);
+ buf_read(fd, &from, sizeof(from));
+ buf_read(fd, &to, sizeof(to));
+
/* Assemble the headers... */
- if (to->sin_addr.s_addr == INADDR_BROADCAST)
- assemble_hw_header(interface, buf, &bufp, hto);
- assemble_udp_ip_header(buf, &bufp, from.s_addr,
- to->sin_addr.s_addr, to->sin_port, (unsigned char *)raw, len);
+ if (to.s_addr == INADDR_BROADCAST)
+ assemble_hw_header(interface, buf, &bufp);
+ assemble_udp_ip_header(buf, &bufp, from.s_addr, to.s_addr,
+ htons(REMOTE_PORT), (unsigned char *)&raw, len);
- iov[0].iov_base = (char *)buf;
+ iov[0].iov_base = buf;
iov[0].iov_len = bufp;
- iov[1].iov_base = (char *)raw;
+ iov[1].iov_base = &raw;
iov[1].iov_len = len;
/* Fire it off */
- if (to->sin_addr.s_addr == INADDR_BROADCAST)
+ if (to.s_addr == INADDR_BROADCAST)
result = writev(interface->wfdesc, iov, 2);
else {
+ struct sockaddr_in sato;
+
+ sato.sin_addr = to;
+ sato.sin_port = htons(REMOTE_PORT);
+ sato.sin_family = AF_INET;
+ sato.sin_len = sizeof(sato);
+
memset(&msg, 0, sizeof(msg));
- msg.msg_name = (struct sockaddr *)to;
- msg.msg_namelen = sizeof(*to);
+ msg.msg_name = (struct sockaddr *)&sato;
+ msg.msg_namelen = sizeof(sato);
msg.msg_iov = iov;
msg.msg_iovlen = 2;
result = sendmsg(interface->ufdesc, &msg, 0);
@@ -284,7 +362,6 @@
if (result < 0)
warning("send_packet: %m");
- return (result);
}
ssize_t
Modified: trunk/sbin/dhclient/clparse.c
===================================================================
--- trunk/sbin/dhclient/clparse.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/clparse.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: clparse.c,v 1.18 2004/09/15 18:15:18 henning Exp $ */
/* Parser for dhclient config and lease files... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/clparse.c 315610 2017-03-20 03:06:41Z ngie $");
#include "dhcpd.h"
#include "dhctoken.h"
@@ -510,6 +511,7 @@
token = peek_token(&val, cfile);
if (token == EOF) {
parse_warn("unterminated lease declaration.");
+ free_client_lease(lease);
return;
}
if (token == RBRACE)
@@ -642,6 +644,10 @@
case FILENAME:
lease->filename = parse_string(cfile);
return;
+ case NEXT_SERVER:
+ if (!parse_ip_addr(cfile, &lease->nextserver))
+ return;
+ break;
case SERVER_NAME:
lease->server_name = parse_string(cfile);
return;
@@ -707,6 +713,7 @@
parse_warn("expecting identifier after '.'");
if (token != SEMI)
skip_to_semi(cfile);
+ free(vendor);
return (NULL);
}
@@ -719,6 +726,7 @@
if (!universe) {
parse_warn("no vendor named %s.", vendor);
skip_to_semi(cfile);
+ free(vendor);
return (NULL);
}
} else {
@@ -740,6 +748,7 @@
parse_warn("no option named %s for vendor %s",
val, vendor);
skip_to_semi(cfile);
+ free(vendor);
return (NULL);
}
Modified: trunk/sbin/dhclient/conflex.c
===================================================================
--- trunk/sbin/dhclient/conflex.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/conflex.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: conflex.c,v 1.7 2004/09/15 19:02:38 deraadt Exp $ */
/* Lexical scanner for dhcpd config file... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/conflex.c 301506 2016-06-06 13:31:28Z pfg $");
#include <ctype.h>
@@ -97,8 +98,8 @@
cur_line = line2;
prev_line = line1;
} else {
- cur_line = line2;
- prev_line = line1;
+ cur_line = line1;
+ prev_line = line2;
}
line++;
lpos = 1;
Modified: trunk/sbin/dhclient/convert.c
===================================================================
--- trunk/sbin/dhclient/convert.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/convert.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: convert.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */
/*
@@ -44,7 +45,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/convert.c 149399 2005-08-23 23:59:55Z brooks $");
#include "dhcpd.h"
Modified: trunk/sbin/dhclient/dhclient-script
===================================================================
--- trunk/sbin/dhclient/dhclient-script 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient-script 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,6 +1,7 @@
#!/bin/sh
#
# $OpenBSD: dhclient-script,v 1.6 2004/05/06 18:22:41 claudio Exp $
+# $FreeBSD: stable/10/sbin/dhclient/dhclient-script 229002 2011-12-30 14:46:53Z dumbbell $
# $MidnightBSD$
#
# Copyright (c) 2003 Kenneth R Westerback <krw at openbsd.org>
Property changes on: trunk/sbin/dhclient/dhclient-script
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhclient-script.8
===================================================================
--- trunk/sbin/dhclient/dhclient-script.8 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient-script.8 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $OpenBSD: dhclient-script.8,v 1.2 2004/04/09 18:30:15 jmc Exp $
.\"
.\" Copyright (c) 1997 The Internet Software Consortium.
@@ -36,7 +37,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/dhclient/dhclient-script.8 307403 2016-10-16 22:02:50Z sevan $
.\"
.Dd September 6, 2010
.Dt DHCLIENT-SCRIPT 8
@@ -232,7 +233,7 @@
.Pa /etc/dhclient-exit-hooks .
If found, it will be sourced
.Pq see Xr sh 1 .
-These hooks scripts can be used to dynamically modify the enviornment at
+These hooks scripts can be used to dynamically modify the environment at
appropriate times during the DHCP negotiations.
For example, if the administrator wishes to disable alias IP numbers on
the DHCP interface, they might want to put the following in
@@ -273,7 +274,7 @@
The original version of
.Nm
was written for the Internet Software Consortium by
-.An Ted Lemon Aq mellon at fugue.com
+.An Ted Lemon Aq Mt mellon at fugue.com
in cooperation with Vixie Enterprises.
.Pp
The
@@ -281,7 +282,7 @@
implementation of
.Nm
was written by
-.An Kenneth R. Westerback Aq krw at openbsd.org .
+.An Kenneth R. Westerback Aq Mt krw at openbsd.org .
.Sh BUGS
If more than one interface is being used, there is no obvious way to
avoid clashes between server-supplied configuration parameters - for
Property changes on: trunk/sbin/dhclient/dhclient-script.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhclient.8
===================================================================
--- trunk/sbin/dhclient/dhclient.8 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient.8 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $OpenBSD: dhclient.8,v 1.3 2004/04/09 18:30:15 jmc Exp $
.\"
.\" Copyright (c) 1997 The Internet Software Consortium.
@@ -36,7 +37,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/dhclient/dhclient.8 307403 2016-10-16 22:02:50Z sevan $
.\"
.Dd October 13, 2011
.Dt DHCLIENT 8
@@ -188,9 +189,9 @@
.Nm
utility
was written by
-.An Ted Lemon Aq mellon at fugue.com
+.An Ted Lemon Aq Mt mellon at fugue.com
and
-.An Elliot Poger Aq elliot at poger.com .
+.An Elliot Poger Aq Mt elliot at poger.com .
.Pp
The current implementation was reworked by
-.An Henning Brauer Aq henning at openbsd.org .
+.An Henning Brauer Aq Mt henning at openbsd.org .
Property changes on: trunk/sbin/dhclient/dhclient.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhclient.c
===================================================================
--- trunk/sbin/dhclient/dhclient.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: dhclient.c,v 1.63 2005/02/06 17:10:13 krw Exp $ */
/*
@@ -54,11 +55,15 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/dhclient.c 330693 2018-03-09 14:39:28Z dab $");
+#include <sys/capsicum.h>
+
#include "dhcpd.h"
#include "privsep.h"
+#include <sys/capsicum.h>
+
#include <net80211/ieee80211_freebsd.h>
#ifndef _PATH_VAREMPTY
@@ -91,9 +96,10 @@
int privfd;
int nullfd = -1;
+char hostname[_POSIX_HOST_NAME_MAX + 1];
+
struct iaddr iaddr_broadcast = { 4, { 255, 255, 255, 255 } };
-struct in_addr inaddr_any;
-struct sockaddr_in sockaddr_broadcast;
+struct in_addr inaddr_any, inaddr_broadcast;
char *path_dhclient_pidfile;
struct pidfh *pidfile;
@@ -343,6 +349,7 @@
int immediate_daemon = 0;
struct passwd *pw;
pid_t otherpid;
+ cap_rights_t rights;
/* Initially, log errors to stderr as well as to syslogd. */
openlog(__progname, LOG_PID | LOG_NDELAY, DHCPD_LOG_FACILITY);
@@ -410,11 +417,7 @@
tzset();
time(&cur_time);
- memset(&sockaddr_broadcast, 0, sizeof(sockaddr_broadcast));
- sockaddr_broadcast.sin_family = AF_INET;
- sockaddr_broadcast.sin_port = htons(REMOTE_PORT);
- sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST;
- sockaddr_broadcast.sin_len = sizeof(sockaddr_broadcast);
+ inaddr_broadcast.s_addr = INADDR_BROADCAST;
inaddr_any.s_addr = INADDR_ANY;
read_client_conf();
@@ -451,13 +454,36 @@
error("no such user: nobody");
}
+ /*
+ * Obtain hostname before entering capability mode - it won't be
+ * possible then, as reading kern.hostname is not permitted.
+ */
+ if (gethostname(hostname, sizeof(hostname)) < 0)
+ hostname[0] = '\0';
+
+ priv_script_init("PREINIT", NULL);
+ if (ifi->client->alias)
+ priv_script_write_params("alias_", ifi->client->alias);
+ priv_script_go();
+
+ /* set up the interface */
+ discover_interfaces(ifi);
+
if (pipe(pipe_fd) == -1)
error("pipe");
fork_privchld(pipe_fd[0], pipe_fd[1]);
+ close(ifi->ufdesc);
+ ifi->ufdesc = -1;
+ close(ifi->wfdesc);
+ ifi->wfdesc = -1;
+
close(pipe_fd[0]);
privfd = pipe_fd[1];
+ cap_rights_init(&rights, CAP_READ, CAP_WRITE);
+ if (cap_rights_limit(privfd, &rights) < 0 && errno != ENOSYS)
+ error("can't limit private descriptor: %m");
if ((fd = open(path_dhclient_db, O_RDONLY|O_EXLOCK|O_CREAT, 0)) == -1)
error("can't open and lock %s: %m", path_dhclient_db);
@@ -465,17 +491,14 @@
rewrite_client_leases();
close(fd);
- priv_script_init("PREINIT", NULL);
- if (ifi->client->alias)
- priv_script_write_params("alias_", ifi->client->alias);
- priv_script_go();
-
if ((routefd = socket(PF_ROUTE, SOCK_RAW, 0)) != -1)
add_protocol("AF_ROUTE", routefd, routehandler, ifi);
+ if (shutdown(routefd, SHUT_WR) < 0)
+ error("can't shutdown route socket: %m");
+ cap_rights_init(&rights, CAP_EVENT, CAP_READ);
+ if (cap_rights_limit(routefd, &rights) < 0 && errno != ENOSYS)
+ error("can't limit route socket: %m");
- /* set up the interface */
- discover_interfaces(ifi);
-
if (chroot(_PATH_VAREMPTY) == -1)
error("chroot");
if (chdir("/") == -1)
@@ -490,6 +513,9 @@
setproctitle("%s", ifi->name);
+ if (cap_enter() < 0 && errno != ENOSYS)
+ error("can't enter capability mode: %m");
+
if (immediate_daemon)
go_daemon();
@@ -1063,6 +1089,9 @@
lease->address.len = sizeof(packet->raw->yiaddr);
memcpy(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len);
+ lease->nextserver.len = sizeof(packet->raw->siaddr);
+ memcpy(lease->nextserver.iabuf, &packet->raw->siaddr, lease->nextserver.len);
+
/* If the server name was filled out, copy it.
Do not attempt to validate the server name as a host name.
RFC 2131 merely states that sname is NUL-terminated (which do
@@ -1223,13 +1252,12 @@
ip->client->secs = ip->client->packet.secs;
note("DHCPDISCOVER on %s to %s port %d interval %d",
- ip->name, inet_ntoa(sockaddr_broadcast.sin_addr),
- ntohs(sockaddr_broadcast.sin_port),
+ ip->name, inet_ntoa(inaddr_broadcast), REMOTE_PORT,
(int)ip->client->interval);
/* Send out a packet. */
- (void)send_packet(ip, &ip->client->packet, ip->client->packet_length,
- inaddr_any, &sockaddr_broadcast, NULL);
+ send_packet_unpriv(privfd, &ip->client->packet,
+ ip->client->packet_length, inaddr_any, inaddr_broadcast);
add_timeout(cur_time + ip->client->interval, send_discover, ip);
}
@@ -1337,8 +1365,7 @@
send_request(void *ipp)
{
struct interface_info *ip = ipp;
- struct sockaddr_in destination;
- struct in_addr from;
+ struct in_addr from, to;
int interval;
/* Figure out how long it's been since we started transmitting. */
@@ -1426,20 +1453,16 @@
/* If the lease T2 time has elapsed, or if we're not yet bound,
broadcast the DHCPREQUEST rather than unicasting. */
- memset(&destination, 0, sizeof(destination));
if (ip->client->state == S_REQUESTING ||
ip->client->state == S_REBOOTING ||
cur_time > ip->client->active->rebind)
- destination.sin_addr.s_addr = INADDR_BROADCAST;
+ to.s_addr = INADDR_BROADCAST;
else
- memcpy(&destination.sin_addr.s_addr,
- ip->client->destination.iabuf,
- sizeof(destination.sin_addr.s_addr));
- destination.sin_port = htons(REMOTE_PORT);
- destination.sin_family = AF_INET;
- destination.sin_len = sizeof(destination);
+ memcpy(&to.s_addr, ip->client->destination.iabuf,
+ sizeof(to.s_addr));
- if (ip->client->state != S_REQUESTING)
+ if (ip->client->state != S_REQUESTING &&
+ ip->client->state != S_REBOOTING)
memcpy(&from, ip->client->active->address.iabuf,
sizeof(from));
else
@@ -1455,12 +1478,12 @@
ip->client->packet.secs = htons(65535);
}
- note("DHCPREQUEST on %s to %s port %d", ip->name,
- inet_ntoa(destination.sin_addr), ntohs(destination.sin_port));
+ note("DHCPREQUEST on %s to %s port %d", ip->name, inet_ntoa(to),
+ REMOTE_PORT);
/* Send out a packet. */
- (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
- from, &destination, NULL);
+ send_packet_unpriv(privfd, &ip->client->packet,
+ ip->client->packet_length, from, to);
add_timeout(cur_time + ip->client->interval, send_request, ip);
}
@@ -1471,12 +1494,11 @@
struct interface_info *ip = ipp;
note("DHCPDECLINE on %s to %s port %d", ip->name,
- inet_ntoa(sockaddr_broadcast.sin_addr),
- ntohs(sockaddr_broadcast.sin_port));
+ inet_ntoa(inaddr_broadcast), REMOTE_PORT);
/* Send out a packet. */
- (void) send_packet(ip, &ip->client->packet, ip->client->packet_length,
- inaddr_any, &sockaddr_broadcast, NULL);
+ send_packet_unpriv(privfd, &ip->client->packet,
+ ip->client->packet_length, inaddr_any, inaddr_broadcast);
}
void
@@ -1533,11 +1555,10 @@
ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
}
-
+
/* send host name if not set via config file. */
- char hostname[_POSIX_HOST_NAME_MAX+1];
if (!options[DHO_HOST_NAME]) {
- if (gethostname(hostname, sizeof(hostname)) == 0) {
+ if (hostname[0] != '\0') {
size_t len;
char* posDot = strchr(hostname, '.');
if (posDot != NULL)
@@ -1558,7 +1579,7 @@
int hwlen = (ip->hw_address.hlen < sizeof(client_ident)-1) ?
ip->hw_address.hlen : sizeof(client_ident)-1;
client_ident[0] = ip->hw_address.htype;
- memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
+ memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
options[DHO_DHCP_CLIENT_IDENTIFIER] = &option_elements[DHO_DHCP_CLIENT_IDENTIFIER];
options[DHO_DHCP_CLIENT_IDENTIFIER]->value = client_ident;
options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen+1;
@@ -1657,11 +1678,10 @@
ip->client->config->send_options[i].len;
options[i]->timeout = 0xFFFFFFFF;
}
-
+
/* send host name if not set via config file. */
- char hostname[_POSIX_HOST_NAME_MAX+1];
if (!options[DHO_HOST_NAME]) {
- if (gethostname(hostname, sizeof(hostname)) == 0) {
+ if (hostname[0] != '\0') {
size_t len;
char* posDot = strchr(hostname, '.');
if (posDot != NULL)
@@ -1682,7 +1702,7 @@
int hwlen = (ip->hw_address.hlen < sizeof(client_ident)-1) ?
ip->hw_address.hlen : sizeof(client_ident)-1;
client_ident[0] = ip->hw_address.htype;
- memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
+ memcpy(&client_ident[1], ip->hw_address.haddr, hwlen);
options[DHO_DHCP_CLIENT_IDENTIFIER] = &option_elements[DHO_DHCP_CLIENT_IDENTIFIER];
options[DHO_DHCP_CLIENT_IDENTIFIER]->value = client_ident;
options[DHO_DHCP_CLIENT_IDENTIFIER]->len = hwlen+1;
@@ -1823,11 +1843,22 @@
rewrite_client_leases(void)
{
struct client_lease *lp;
+ cap_rights_t rights;
if (!leaseFile) {
leaseFile = fopen(path_dhclient_db, "w");
if (!leaseFile)
error("can't create %s: %m", path_dhclient_db);
+ cap_rights_init(&rights, CAP_FCNTL, CAP_FSTAT, CAP_FSYNC,
+ CAP_FTRUNCATE, CAP_SEEK, CAP_WRITE);
+ if (cap_rights_limit(fileno(leaseFile), &rights) < 0 &&
+ errno != ENOSYS) {
+ error("can't limit lease descriptor: %m");
+ }
+ if (cap_fcntls_limit(fileno(leaseFile), CAP_FCNTL_GETFL) < 0 &&
+ errno != ENOSYS) {
+ error("can't limit lease descriptor fcntls: %m");
+ }
} else {
fflush(leaseFile);
rewind(leaseFile);
@@ -1874,6 +1905,11 @@
fprintf(leaseFile, " bootp;\n");
fprintf(leaseFile, " interface \"%s\";\n", ip->name);
fprintf(leaseFile, " fixed-address %s;\n", piaddr(lease->address));
+ if (lease->nextserver.len == sizeof(inaddr_any) &&
+ 0 != memcmp(lease->nextserver.iabuf, &inaddr_any,
+ sizeof(inaddr_any)))
+ fprintf(leaseFile, " next-server %s;\n",
+ piaddr(lease->nextserver));
if (lease->filename)
fprintf(leaseFile, " filename \"%s\";\n", lease->filename);
if (lease->server_name)
@@ -2243,6 +2279,17 @@
{
int i, j, namelen;
+ /* No `` or $() command substitution allowed in environment values! */
+ for (j=0; j < strlen(value); j++)
+ switch (value[j]) {
+ case '`':
+ case '$':
+ warning("illegal character (%c) in value '%s'",
+ value[j], value);
+ /* Ignore this option */
+ return;
+ }
+
namelen = strlen(name);
for (i = 0; client->scriptEnv[i]; i++)
@@ -2279,16 +2326,6 @@
strlen(value) + 1);
if (client->scriptEnv[i] == NULL)
error("script_set_env: no memory for variable assignment");
-
- /* No `` or $() command substitution allowed in environment values! */
- for (j=0; j < strlen(value); j++)
- switch (value[j]) {
- case '`':
- case '$':
- error("illegal character (%c) in value '%s'", value[j],
- value);
- /* not reached */
- }
snprintf(client->scriptEnv[i], strlen(prefix) + strlen(name) +
1 + strlen(value) + 1, "%s%s=%s", prefix, name, value);
}
@@ -2327,6 +2364,7 @@
go_daemon(void)
{
static int state = 0;
+ cap_rights_t rights;
if (no_daemon || state)
return;
@@ -2339,8 +2377,15 @@
if (daemon(1, 0) == -1)
error("daemon");
- if (pidfile != NULL)
+ cap_rights_init(&rights);
+
+ if (pidfile != NULL) {
pidfile_write(pidfile);
+ if (cap_rights_limit(pidfile_fileno(pidfile), &rights) < 0 &&
+ errno != ENOSYS) {
+ error("can't limit pidfile descriptor: %m");
+ }
+ }
/* we are chrooted, daemon(3) fails to open /dev/null */
if (nullfd != -1) {
@@ -2350,6 +2395,14 @@
close(nullfd);
nullfd = -1;
}
+
+ if (cap_rights_limit(STDIN_FILENO, &rights) < 0 && errno != ENOSYS)
+ error("can't limit stdin: %m");
+ cap_rights_init(&rights, CAP_WRITE);
+ if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS)
+ error("can't limit stdout: %m");
+ if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS)
+ error("can't limit stderr: %m");
}
int
@@ -2494,19 +2547,19 @@
i += 4;
continue;
} else if (width < 9) {
- addr = (in_addr_t)(data[i] << 24);
+ addr = (in_addr_t)(data[i] << 24);
i += 1;
} else if (width < 17) {
- addr = (in_addr_t)(data[i] << 24) +
+ addr = (in_addr_t)(data[i] << 24) +
(in_addr_t)(data[i + 1] << 16);
i += 2;
} else if (width < 25) {
- addr = (in_addr_t)(data[i] << 24) +
+ addr = (in_addr_t)(data[i] << 24) +
(in_addr_t)(data[i + 1] << 16) +
(in_addr_t)(data[i + 2] << 8);
i += 3;
} else if (width < 33) {
- addr = (in_addr_t)(data[i] << 24) +
+ addr = (in_addr_t)(data[i] << 24) +
(in_addr_t)(data[i + 1] << 16) +
(in_addr_t)(data[i + 2] << 8) +
data[i + 3];
@@ -2530,7 +2583,7 @@
addr &= mask;
data[i - 1] = (unsigned char)(
(addr >> (((32 - width)/8)*8)) & 0xFF);
- }
+ }
i += 4;
}
if (i > len) {
@@ -2694,6 +2747,8 @@
dup2(nullfd, STDERR_FILENO);
close(nullfd);
close(fd2);
+ close(ifi->rfdesc);
+ ifi->rfdesc = -1;
for (;;) {
pfd[0].fd = fd;
@@ -2705,6 +2760,6 @@
if (nfds == 0 || !(pfd[0].revents & POLLIN))
continue;
- dispatch_imsg(fd);
+ dispatch_imsg(ifi, fd);
}
}
Modified: trunk/sbin/dhclient/dhclient.conf
===================================================================
--- trunk/sbin/dhclient/dhclient.conf 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient.conf 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,4 +1,5 @@
# $MidnightBSD$
+# $FreeBSD: stable/10/sbin/dhclient/dhclient.conf 166602 2007-02-09 17:50:26Z emaste $
send host-name "andare.fugue.com";
send dhcp-client-identifier 1:0:a0:24:ab:fb:9c;
Property changes on: trunk/sbin/dhclient/dhclient.conf
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhclient.conf.5
===================================================================
--- trunk/sbin/dhclient/dhclient.conf.5 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient.conf.5 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $OpenBSD: dhclient.conf.5,v 1.5 2004/11/01 23:10:18 henning Exp $
.\"
.\" Copyright (c) 1997 The Internet Software Consortium.
@@ -36,7 +37,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/dhclient/dhclient.conf.5 307403 2016-10-16 22:02:50Z sevan $
.\"
.Dd January 1, 1997
.Dt DHCLIENT.CONF 5
@@ -537,8 +538,8 @@
.Xr dhclient 8
utility
was written by
-.An Ted Lemon Aq mellon at vix.com
+.An Ted Lemon Aq Mt mellon at vix.com
under a contract with Vixie Labs.
.Pp
The current implementation was reworked by
-.An Henning Brauer Aq henning at openbsd.org .
+.An Henning Brauer Aq Mt henning at openbsd.org .
Property changes on: trunk/sbin/dhclient/dhclient.conf.5
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhclient.leases.5
===================================================================
--- trunk/sbin/dhclient/dhclient.leases.5 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhclient.leases.5 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $OpenBSD: dhclient.leases.5,v 1.4 2004/04/15 08:59:47 jmc Exp $
.\"
.\" Copyright (c) 1997 The Internet Software Consortium.
@@ -36,7 +37,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/dhclient/dhclient.leases.5 307403 2016-10-16 22:02:50Z sevan $
.\"
.Dd January 1, 1997
.Dt DHCLIENT.LEASES 5
@@ -88,8 +89,8 @@
.Xr dhclient 8
utility
was written by
-.An Ted Lemon Aq mellon at vix.com
+.An Ted Lemon Aq Mt mellon at vix.com
under a contract with Vixie Labs.
.Pp
The current implementation was reworked by
-.An Henning Brauer Aq henning at openbsd.org .
+.An Henning Brauer Aq Mt henning at openbsd.org .
Property changes on: trunk/sbin/dhclient/dhclient.leases.5
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhcp-options.5
===================================================================
--- trunk/sbin/dhclient/dhcp-options.5 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhcp-options.5 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+.\" $MidnightBSD$
.\" $OpenBSD: dhcp-options.5,v 1.5 2005/03/02 15:30:42 jmc Exp $
.\"
.\" Copyright (c) 1995, 1996, 1997, 1998 The Internet Software Consortium.
@@ -36,7 +37,7 @@
.\" see ``http://www.isc.org/isc''. To learn more about Vixie
.\" Enterprises, see ``http://www.vix.com''.
.\"
-.\" $MidnightBSD$
+.\" $FreeBSD: stable/10/sbin/dhclient/dhcp-options.5 307403 2016-10-16 22:02:50Z sevan $
.\"
.Dd January 1, 1995
.Dt DHCP-OPTIONS 5
@@ -603,8 +604,8 @@
.Xr dhcpd 8
utility
was written by
-.An Ted Lemon Aq mellon at vix.com
+.An Ted Lemon Aq Mt mellon at vix.com
under a contract with Vixie Labs.
.Pp
The current implementation was reworked by
-.An Henning Brauer Aq henning at openbsd.org .
+.An Henning Brauer Aq Mt henning at openbsd.org .
Property changes on: trunk/sbin/dhclient/dhcp-options.5
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/sbin/dhclient/dhcp.h
===================================================================
--- trunk/sbin/dhclient/dhcp.h 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhcp.h 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,5 +1,6 @@
+/* $MidnightBSD$ */
/* $OpenBSD: dhcp.h,v 1.5 2004/05/04 15:49:49 deraadt Exp $ */
-/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sbin/dhclient/dhcp.h 228259 2011-12-04 14:44:31Z dumbbell $ */
/* Protocol structures... */
Modified: trunk/sbin/dhclient/dhcpd.h
===================================================================
--- trunk/sbin/dhclient/dhcpd.h 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhcpd.h 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: dhcpd.h,v 1.33 2004/05/06 22:29:15 deraadt Exp $ */
/*
@@ -38,7 +39,7 @@
* see ``http://www.vix.com/isc''. To learn more about Vixie
* Enterprises, see ``http://www.vix.com''.
*
- * $MidnightBSD$
+ * $FreeBSD: stable/10/sbin/dhclient/dhcpd.h 252626 2013-07-03 22:12:54Z pjd $
*/
#include <sys/param.h>
@@ -121,6 +122,7 @@
struct client_lease *next;
time_t expiry, renewal, rebind;
struct iaddr address;
+ struct iaddr nextserver;
char *server_name;
char *filename;
struct string_list *medium;
@@ -296,11 +298,13 @@
struct hash_bucket *new_hash_bucket(void);
/* bpf.c */
-int if_register_bpf(struct interface_info *);
+int if_register_bpf(struct interface_info *, int);
void if_register_send(struct interface_info *);
void if_register_receive(struct interface_info *);
-ssize_t send_packet(struct interface_info *, struct dhcp_packet *, size_t,
- struct in_addr, struct sockaddr_in *, struct hardware *);
+void send_packet_unpriv(int, struct dhcp_packet *, size_t, struct in_addr,
+ struct in_addr);
+struct imsg_hdr;
+void send_packet_priv(struct interface_info *, struct imsg_hdr *, int);
ssize_t receive_packet(struct interface_info *, unsigned char *, size_t,
struct sockaddr_in *, struct hardware *);
@@ -404,8 +408,7 @@
void dhcp(struct packet *);
/* packet.c */
-void assemble_hw_header(struct interface_info *, unsigned char *,
- int *, struct hardware *);
+void assemble_hw_header(struct interface_info *, unsigned char *, int *);
void assemble_udp_ip_header(unsigned char *, int *, u_int32_t, u_int32_t,
unsigned int, unsigned char *, int);
ssize_t decode_hw_header(unsigned char *, int, struct hardware *);
@@ -412,12 +415,6 @@
ssize_t decode_udp_ip_header(unsigned char *, int, struct sockaddr_in *,
unsigned char *, int);
-/* ethernet.c */
-void assemble_ethernet_header(struct interface_info *, unsigned char *,
- int *, struct hardware *);
-ssize_t decode_ethernet_header(struct interface_info *, unsigned char *,
- int, struct hardware *);
-
/* clparse.c */
int read_client_conf(void);
void read_client_leases(void);
@@ -441,4 +438,4 @@
int buf_add(struct buf *, void *, size_t);
int buf_close(int, struct buf *);
ssize_t buf_read(int, void *, size_t);
-void dispatch_imsg(int);
+void dispatch_imsg(struct interface_info *, int);
Modified: trunk/sbin/dhclient/dhctoken.h
===================================================================
--- trunk/sbin/dhclient/dhctoken.h 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dhctoken.h 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: dhctoken.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */
/* Tokens for config file lexer and parser. */
Modified: trunk/sbin/dhclient/dispatch.c
===================================================================
--- trunk/sbin/dhclient/dispatch.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/dispatch.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: dispatch.c,v 1.31 2004/09/21 04:07:03 david Exp $ */
/*
@@ -40,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/dispatch.c 313103 2017-02-02 19:50:28Z asomers $");
#include "dhcpd.h"
@@ -105,8 +106,8 @@
if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK))
continue;
if (!iface->ifp) {
- int len = IFNAMSIZ + ifa->ifa_addr->sa_len;
- if ((tif = malloc(len)) == NULL)
+ if ((tif = calloc(1, sizeof(struct ifreq)))
+ == NULL)
error("no space to remember ifp");
strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ);
memcpy(&tif->ifr_addr, ifa->ifa_addr,
@@ -453,16 +454,12 @@
void
remove_protocol(struct protocol *proto)
{
- struct protocol *p, *next, *prev;
+ struct protocol *p, *next;
- prev = NULL;
for (p = protocols; p; p = next) {
next = p->next;
if (p == proto) {
- if (prev)
- prev->next = p->next;
- else
- protocols = p->next;
+ protocols = p->next;
free(p);
}
}
Modified: trunk/sbin/dhclient/errwarn.c
===================================================================
--- trunk/sbin/dhclient/errwarn.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/errwarn.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: errwarn.c,v 1.7 2004/05/04 22:23:01 mickey Exp $ */
/* Errors and warnings... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/errwarn.c 226345 2011-10-13 17:20:45Z des $");
#include <errno.h>
Modified: trunk/sbin/dhclient/hash.c
===================================================================
--- trunk/sbin/dhclient/hash.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/hash.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: hash.c,v 1.9 2004/05/10 15:30:47 deraadt Exp $ */
/* Routines for manipulating hash tables... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/hash.c 149399 2005-08-23 23:59:55Z brooks $");
#include "dhcpd.h"
Modified: trunk/sbin/dhclient/inet.c
===================================================================
--- trunk/sbin/dhclient/inet.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/inet.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: inet.c,v 1.7 2004/05/04 21:48:16 deraadt Exp $ */
/*
@@ -43,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/inet.c 149399 2005-08-23 23:59:55Z brooks $");
#include "dhcpd.h"
Modified: trunk/sbin/dhclient/options.c
===================================================================
--- trunk/sbin/dhclient/options.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/options.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: options.c,v 1.15 2004/12/26 03:17:07 deraadt Exp $ */
/* DHCP options parsing and reassembly. */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/options.c 229778 2012-01-07 16:09:33Z uqs $");
#include <ctype.h>
@@ -284,8 +285,8 @@
option->data[i + 1];
if (pointer >= *offset) {
/*
- * The pointer must indicates a prior
- * occurance.
+ * The pointer must indicate a prior
+ * occurrence.
*/
warning("Invalid forward pointer in DHCP "
"Domain Search option compression.");
Modified: trunk/sbin/dhclient/packet.c
===================================================================
--- trunk/sbin/dhclient/packet.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/packet.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: packet.c,v 1.9 2004/05/04 18:58:50 deraadt Exp $ */
/* Packet assembly code, originally contributed by Archie Cobbs. */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/packet.c 252615 2013-07-03 21:49:10Z pjd $");
#include "dhcpd.h"
@@ -55,11 +56,6 @@
u_int32_t checksum(unsigned char *, unsigned, u_int32_t);
u_int32_t wrapsum(u_int32_t);
-void assemble_ethernet_header(struct interface_info *, unsigned char *,
- int *, struct hardware *);
-ssize_t decode_ethernet_header(struct interface_info *, unsigned char *,
- int bufix, struct hardware *);
-
u_int32_t
checksum(unsigned char *buf, unsigned nbytes, u_int32_t sum)
{
@@ -95,14 +91,11 @@
void
assemble_hw_header(struct interface_info *interface, unsigned char *buf,
- int *bufix, struct hardware *to)
+ int *bufix)
{
struct ether_header eh;
- if (to != NULL && to->hlen == 6) /* XXX */
- memcpy(eh.ether_dhost, to->haddr, sizeof(eh.ether_dhost));
- else
- memset(eh.ether_dhost, 0xff, sizeof(eh.ether_dhost));
+ memset(eh.ether_dhost, 0xff, sizeof(eh.ether_dhost));
if (interface->hw_address.hlen == sizeof(eh.ether_shost))
memcpy(eh.ether_shost, interface->hw_address.haddr,
sizeof(eh.ether_shost));
@@ -128,7 +121,7 @@
ip.ip_len = htons(sizeof(ip) + sizeof(udp) + len);
ip.ip_id = 0;
ip.ip_off = 0;
- ip.ip_ttl = 16;
+ ip.ip_ttl = 128;
ip.ip_p = IPPROTO_UDP;
ip.ip_sum = 0;
ip.ip_src.s_addr = from;
Modified: trunk/sbin/dhclient/parse.c
===================================================================
--- trunk/sbin/dhclient/parse.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/parse.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: parse.c,v 1.11 2004/05/05 23:07:47 deraadt Exp $ */
/* Common parser code for dhcpd and dhclient. */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/parse.c 228615 2011-12-17 01:29:46Z dim $");
#include "dhcpd.h"
#include "dhctoken.h"
Modified: trunk/sbin/dhclient/privsep.c
===================================================================
--- trunk/sbin/dhclient/privsep.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/privsep.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: privsep.c,v 1.7 2004/05/10 18:34:42 deraadt Exp $ */
/*
@@ -17,7 +18,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/privsep.c 252626 2013-07-03 22:12:54Z pjd $");
#include "dhcpd.h"
#include "privsep.h"
@@ -101,7 +102,7 @@
}
void
-dispatch_imsg(int fd)
+dispatch_imsg(struct interface_info *ifi, int fd)
{
struct imsg_hdr hdr;
char *medium, *reason, *filename,
@@ -232,6 +233,9 @@
if (buf_close(fd, buf) == -1)
error("buf_close: %m");
break;
+ case IMSG_SEND_PACKET:
+ send_packet_priv(ifi, &hdr, fd);
+ break;
default:
error("received unknown message, code %d", hdr.code);
}
Modified: trunk/sbin/dhclient/privsep.h
===================================================================
--- trunk/sbin/dhclient/privsep.h 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/privsep.h 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: privsep.h,v 1.2 2004/05/04 18:51:18 henning Exp $ */
/*
@@ -14,6 +15,8 @@
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER IN
* AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE, ABUSE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * $FreeBSD: stable/10/sbin/dhclient/privsep.h 252624 2013-07-03 22:07:55Z pjd $
*/
#include <sys/types.h>
@@ -33,7 +36,8 @@
IMSG_SCRIPT_INIT,
IMSG_SCRIPT_WRITE_PARAMS,
IMSG_SCRIPT_GO,
- IMSG_SCRIPT_GO_RET
+ IMSG_SCRIPT_GO_RET,
+ IMSG_SEND_PACKET
};
struct imsg_hdr {
Modified: trunk/sbin/dhclient/tables.c
===================================================================
--- trunk/sbin/dhclient/tables.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/tables.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: tables.c,v 1.4 2004/05/04 20:28:40 deraadt Exp $ */
/* Tables of information... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/tables.c 228259 2011-12-04 14:44:31Z dumbbell $");
#include "dhcpd.h"
Added: trunk/sbin/dhclient/tests/Makefile
===================================================================
--- trunk/sbin/dhclient/tests/Makefile (rev 0)
+++ trunk/sbin/dhclient/tests/Makefile 2018-07-01 21:13:00 UTC (rev 11231)
@@ -0,0 +1,15 @@
+# $MidnightBSD$
+# $FreeBSD: stable/10/sbin/dhclient/tests/Makefile 313488 2017-02-09 22:49:48Z ngie $
+
+.PATH: ${.CURDIR}/..
+
+PLAIN_TESTS_C= option-domain-search_test
+SRCS.option-domain-search_test= alloc.c convert.c hash.c options.c \
+ tables.c fake.c option-domain-search.c
+CFLAGS.option-domain-search_test+= -I${.CURDIR}/..
+DPADD.option-domain-search_test= ${LIBUTIL}
+LDADD.option-domain-search_test= -lutil
+
+WARNS?= 2
+
+.include <bsd.test.mk>
Property changes on: trunk/sbin/dhclient/tests/Makefile
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sbin/dhclient/tests/fake.c
===================================================================
--- trunk/sbin/dhclient/tests/fake.c (rev 0)
+++ trunk/sbin/dhclient/tests/fake.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -0,0 +1,64 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sbin/dhclient/tests/fake.c 315610 2017-03-20 03:06:41Z ngie $ */
+
+#include <setjmp.h>
+#include <stdarg.h>
+#include <stdio.h>
+
+#include "dhcpd.h"
+
+extern jmp_buf env;
+
+void
+error(char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void)vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+
+ longjmp(env, 1);
+}
+
+int
+warning(char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ (void)vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+
+ /*
+ * The original warning() would return "ret" here. We do this to
+ * check warnings explicitely.
+ */
+ longjmp(env, 1);
+}
+
+int
+note(char *fmt, ...)
+{
+ int ret;
+ va_list ap;
+
+ va_start(ap, fmt);
+ ret = vfprintf(stderr, fmt, ap);
+ va_end(ap);
+ fprintf(stderr, "\n");
+
+ return ret;
+}
+
+void
+bootp(struct packet *packet)
+{
+}
+
+void
+dhcp(struct packet *packet)
+{
+}
Property changes on: trunk/sbin/dhclient/tests/fake.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Added: trunk/sbin/dhclient/tests/option-domain-search.c
===================================================================
--- trunk/sbin/dhclient/tests/option-domain-search.c (rev 0)
+++ trunk/sbin/dhclient/tests/option-domain-search.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -0,0 +1,329 @@
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/sbin/dhclient/tests/option-domain-search.c 228259 2011-12-04 14:44:31Z dumbbell $ */
+
+#include <setjmp.h>
+#include <stdlib.h>
+
+#include "dhcpd.h"
+
+jmp_buf env;
+
+void expand_domain_search(struct packet *packet);
+
+void
+no_option_present()
+{
+ int ret;
+ struct option_data option;
+ struct packet p;
+
+ option.data = NULL;
+ option.len = 0;
+ p.options[DHO_DOMAIN_SEARCH] = option;
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (p.options[DHO_DOMAIN_SEARCH].len != 0 ||
+ p.options[DHO_DOMAIN_SEARCH].data != NULL)
+ abort();
+}
+
+void
+one_domain_valid()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data = "\007example\003org\0";
+ char *expected = "example.org.";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 13;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (option->len != strlen(expected) ||
+ strcmp(option->data, expected) != 0)
+ abort();
+
+ free(option->data);
+}
+
+void
+one_domain_truncated1()
+{
+ int ret;
+ struct option_data *option;
+ struct packet p;
+
+ char *data = "\007example\003org";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 12;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+one_domain_truncated2()
+{
+ int ret;
+ struct option_data *option;
+ struct packet p;
+
+ char *data = "\007ex";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 3;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_valid()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data = "\007example\003org\0\007example\003com\0";
+ char *expected = "example.org. example.com.";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 26;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (option->len != strlen(expected) ||
+ strcmp(option->data, expected) != 0)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_truncated1()
+{
+ int ret;
+ struct option_data *option;
+ struct packet p;
+
+ char *data = "\007example\003org\0\007example\003com";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 25;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_truncated2()
+{
+ int ret;
+ struct option_data *option;
+ struct packet p;
+
+ char *data = "\007example\003org\0\007ex";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 16;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_compressed()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data = "\007example\003org\0\006foobar\xc0\x08";
+ char *expected = "example.org. foobar.org.";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 22;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (option->len != strlen(expected) ||
+ strcmp(option->data, expected) != 0)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_infloop()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data = "\007example\003org\0\006foobar\xc0\x0d";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 22;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_forwardptr()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data = "\007example\003org\xc0\x0d\006foobar\0";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 22;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+two_domains_truncatedptr()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data = "\007example\003org\0\006foobar\xc0";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 21;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (ret != 1)
+ abort();
+
+ free(option->data);
+}
+
+void
+multiple_domains_valid()
+{
+ int ret;
+ struct packet p;
+ struct option_data *option;
+
+ char *data =
+ "\007example\003org\0\002cl\006foobar\003com\0\002fr\xc0\x10";
+
+ char *expected = "example.org. cl.foobar.com. fr.foobar.com.";
+
+ option = &p.options[DHO_DOMAIN_SEARCH];
+ option->len = 33;
+ option->data = malloc(option->len);
+ memcpy(option->data, data, option->len);
+
+ ret = setjmp(env);
+ if (ret == 0)
+ expand_domain_search(&p);
+
+ if (option->len != strlen(expected) ||
+ strcmp(option->data, expected) != 0)
+ abort();
+
+ free(option->data);
+}
+
+int
+main(int argc, char *argv[])
+{
+
+ no_option_present();
+
+ one_domain_valid();
+ one_domain_truncated1();
+ one_domain_truncated2();
+
+ two_domains_valid();
+ two_domains_truncated1();
+ two_domains_truncated2();
+
+ two_domains_compressed();
+ two_domains_infloop();
+ two_domains_forwardptr();
+ two_domains_truncatedptr();
+
+ multiple_domains_valid();
+
+ return (0);
+}
Property changes on: trunk/sbin/dhclient/tests/option-domain-search.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/sbin/dhclient/tree.c
===================================================================
--- trunk/sbin/dhclient/tree.c 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/tree.c 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: tree.c,v 1.13 2004/05/06 22:29:15 deraadt Exp $ */
/* Routines for manipulating parse trees... */
@@ -41,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__MBSDID("$MidnightBSD$");
+__FBSDID("$FreeBSD: stable/10/sbin/dhclient/tree.c 149399 2005-08-23 23:59:55Z brooks $");
#include "dhcpd.h"
Modified: trunk/sbin/dhclient/tree.h
===================================================================
--- trunk/sbin/dhclient/tree.h 2018-07-01 21:11:09 UTC (rev 11230)
+++ trunk/sbin/dhclient/tree.h 2018-07-01 21:13:00 UTC (rev 11231)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/* $OpenBSD: tree.h,v 1.5 2004/05/06 22:29:15 deraadt Exp $ */
/* Definitions for address trees... */
More information about the Midnightbsd-cvs
mailing list