Import dhcpcd-10.0.2 with the following changes:
* BSD: When we get RTM_NEWADDR the interface must have IFF_UP * BSD: Fix non INET6 builds * DHCP: Don't enforce the message came port 67 * privsep: Allow zero length messages through * dhcpcd: deal with HANGUP and EPIPE better * dhcpcd: Fix waitip address family * privsep: Check if we have a root process before sending it stuff * privsep: Only unlink control sockets if we created them * common: Improve valid_domain and check correct return * common: Allow hwaddr_ntoa to print an empty string * privsep: Send only what we have put in the buffer to script env
This commit is contained in:
parent
9404ac3866
commit
f3ce8585ec
|
@ -92,5 +92,5 @@ dhcpcd-9 defaults the run directory to `/var/run/dhcpcd` instead of
|
|||
## ChangeLog
|
||||
We no longer supply a ChangeLog.
|
||||
However, you're more than welcome to read the
|
||||
[commit log](https://roy.marples.name/git/dhcpcd/log) and
|
||||
[archived release announcements](https://roy.marples.name/archives/dhcpcd-discuss/).
|
||||
[commit log](https://github.com/NetworkConfiguration/dhcpcd/commits) and
|
||||
[release announcements](https://github.com/NetworkConfiguration/dhcpcd/releases).
|
||||
|
|
|
@ -46,10 +46,15 @@ hwaddr_ntoa(const void *hwaddr, size_t hwlen, char *buf, size_t buflen)
|
|||
const unsigned char *hp, *ep;
|
||||
char *p;
|
||||
|
||||
if (buf == NULL || hwlen == 0)
|
||||
/* Allow a hwlen of 0 to be an empty string. */
|
||||
if (buf == NULL || buflen == 0) {
|
||||
errno = ENOBUFS;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (hwlen * 3 > buflen) {
|
||||
/* We should still terminate the string just in case. */
|
||||
buf[0] = '\0';
|
||||
errno = ENOBUFS;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -57,7 +62,6 @@ hwaddr_ntoa(const void *hwaddr, size_t hwlen, char *buf, size_t buflen)
|
|||
hp = hwaddr;
|
||||
ep = hp + hwlen;
|
||||
p = buf;
|
||||
|
||||
while (hp < ep) {
|
||||
if (hp != hwaddr)
|
||||
*p ++= ':';
|
||||
|
|
|
@ -93,6 +93,19 @@ control_free(struct fd_list *fd)
|
|||
free(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
control_hangup(struct fd_list *fd)
|
||||
{
|
||||
|
||||
#ifdef PRIVSEP
|
||||
if (IN_PRIVSEP(fd->ctx)) {
|
||||
if (ps_ctl_sendeof(fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
#endif
|
||||
control_free(fd);
|
||||
}
|
||||
|
||||
static void
|
||||
control_handle_read(struct fd_list *fd)
|
||||
{
|
||||
|
@ -100,16 +113,9 @@ control_handle_read(struct fd_list *fd)
|
|||
ssize_t bytes;
|
||||
|
||||
bytes = read(fd->fd, buffer, sizeof(buffer) - 1);
|
||||
if (bytes == -1)
|
||||
if (bytes == -1) {
|
||||
logerr(__func__);
|
||||
if (bytes == -1 || bytes == 0) {
|
||||
#ifdef PRIVSEP
|
||||
if (IN_PRIVSEP(fd->ctx)) {
|
||||
if (ps_ctl_sendeof(fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
#endif
|
||||
control_free(fd);
|
||||
control_hangup(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -158,8 +164,11 @@ control_handle_write(struct fd_list *fd)
|
|||
}
|
||||
|
||||
if (writev(fd->fd, iov, iov_len) == -1) {
|
||||
logerr("%s: write", __func__);
|
||||
control_free(fd);
|
||||
if (errno != EPIPE && errno != ENOTCONN) {
|
||||
// We don't get ELE_HANGUP for some reason
|
||||
logerr("%s: write", __func__);
|
||||
}
|
||||
control_hangup(fd);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -194,13 +203,15 @@ control_handle_data(void *arg, unsigned short events)
|
|||
{
|
||||
struct fd_list *fd = arg;
|
||||
|
||||
if (!(events & (ELE_READ | ELE_WRITE)))
|
||||
if (!(events & (ELE_READ | ELE_WRITE | ELE_HANGUP)))
|
||||
logerrx("%s: unexpected event 0x%04x", __func__, events);
|
||||
|
||||
if (events & ELE_WRITE && !(events & ELE_HANGUP))
|
||||
control_handle_write(fd);
|
||||
if (events & ELE_READ)
|
||||
control_handle_read(fd);
|
||||
if (events & ELE_HANGUP)
|
||||
control_hangup(fd);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -487,9 +498,11 @@ control_stop(struct dhcpcd_ctx *ctx)
|
|||
|
||||
#ifdef PRIVSEP
|
||||
if (IN_PRIVSEP_SE(ctx)) {
|
||||
if (ps_root_unlink(ctx, ctx->control_sock) == -1)
|
||||
if (ctx->control_sock[0] != '\0' &&
|
||||
ps_root_unlink(ctx, ctx->control_sock) == -1)
|
||||
retval = -1;
|
||||
if (ps_root_unlink(ctx, ctx->control_sock_unpriv) == -1)
|
||||
if (ctx->control_sock_unpriv[0] != '\0' &&
|
||||
ps_root_unlink(ctx, ctx->control_sock_unpriv) == -1)
|
||||
retval = -1;
|
||||
return retval;
|
||||
} else if (ctx->options & DHCPCD_FORKED)
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#define CONFIG_H
|
||||
|
||||
#define PACKAGE "dhcpcd"
|
||||
#define VERSION "10.0.1"
|
||||
#define VERSION "10.0.2"
|
||||
|
||||
#ifndef PRIVSEP_USER
|
||||
# define PRIVSEP_USER "_" PACKAGE
|
||||
|
|
|
@ -413,26 +413,23 @@ decode_rfc1035(char *out, size_t len, const uint8_t *p, size_t pl)
|
|||
}
|
||||
|
||||
/* Check for a valid name as per RFC952 and RFC1123 section 2.1 */
|
||||
static int
|
||||
static ssize_t
|
||||
valid_domainname(char *lbl, int type)
|
||||
{
|
||||
char *slbl, *lst;
|
||||
char *slbl = lbl, *lst = NULL;
|
||||
unsigned char c;
|
||||
int start, len, errset;
|
||||
int len = 0;
|
||||
bool start = true, errset = false;
|
||||
|
||||
if (lbl == NULL || *lbl == '\0') {
|
||||
errno = EINVAL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
slbl = lbl;
|
||||
lst = NULL;
|
||||
start = 1;
|
||||
len = errset = 0;
|
||||
for (;;) {
|
||||
c = (unsigned char)*lbl++;
|
||||
if (c == '\0')
|
||||
return 1;
|
||||
return lbl - slbl - 1;
|
||||
if (c == ' ') {
|
||||
if (lbl - 1 == slbl) /* No space at start */
|
||||
break;
|
||||
|
@ -440,7 +437,7 @@ valid_domainname(char *lbl, int type)
|
|||
break;
|
||||
/* Skip to the next label */
|
||||
if (!start) {
|
||||
start = 1;
|
||||
start = true;
|
||||
lst = lbl - 1;
|
||||
}
|
||||
if (len)
|
||||
|
@ -459,13 +456,13 @@ valid_domainname(char *lbl, int type)
|
|||
{
|
||||
if (++len > NS_MAXLABEL) {
|
||||
errno = ERANGE;
|
||||
errset = 1;
|
||||
errset = true;
|
||||
break;
|
||||
}
|
||||
} else
|
||||
break;
|
||||
if (start)
|
||||
start = 0;
|
||||
start = false;
|
||||
}
|
||||
|
||||
if (!errset)
|
||||
|
@ -473,7 +470,7 @@ valid_domainname(char *lbl, int type)
|
|||
if (lst) {
|
||||
/* At least one valid domain, return it */
|
||||
*lst = '\0';
|
||||
return 1;
|
||||
return lst - slbl;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -665,7 +662,7 @@ print_option(FILE *fp, const char *prefix, const struct dhcp_opt *opt,
|
|||
goto err;
|
||||
if (sl == 0)
|
||||
goto done;
|
||||
if (valid_domainname(domain, opt->type) == -1)
|
||||
if (!valid_domainname(domain, opt->type))
|
||||
goto err;
|
||||
return efprintf(fp, "%s", domain);
|
||||
}
|
||||
|
|
|
@ -235,6 +235,7 @@ const char dhcpcd_embedded_conf[] =
|
|||
"define 100 string posix_timezone\n"
|
||||
"define 101 string tzdb_timezone\n"
|
||||
"define 108 uint32 ipv6_only_preferred\n"
|
||||
"define 114 string captive_portal_uri\n"
|
||||
"define 116 byte auto_configure\n"
|
||||
"define 117 array uint16 name_service_search\n"
|
||||
"define 118 ipaddress subnet_selection\n"
|
||||
|
@ -280,6 +281,8 @@ const char dhcpcd_embedded_conf[] =
|
|||
"embed ipaddress primary\n"
|
||||
"embed ipaddress secondary\n"
|
||||
"embed array domain domains\n"
|
||||
"define 147 domain dots_ri\n"
|
||||
"define 148 array ipaddress dots_address\n"
|
||||
"define 150 array ipaddress tftp_servers\n"
|
||||
"define 161 string mudurl\n"
|
||||
"define 208 binhex pxelinux_magic\n"
|
||||
|
@ -490,6 +493,9 @@ const char dhcpcd_embedded_conf[] =
|
|||
"encap 90 option\n"
|
||||
"encap 92 option\n"
|
||||
"define6 112 string mudurl\n"
|
||||
"define6 103 string captive_portal_uri\n"
|
||||
"define6 141 domain dots_ri\n"
|
||||
"define6 142 array ip6address dots_address\n"
|
||||
#endif
|
||||
"\0";
|
||||
|
||||
|
|
|
@ -30,9 +30,9 @@
|
|||
#define INITDEFINENDS 6
|
||||
#define INITDEFINE6S 14
|
||||
#else
|
||||
#define INITDEFINES 125
|
||||
#define INITDEFINES 128
|
||||
#define INITDEFINENDS 7
|
||||
#define INITDEFINE6S 69
|
||||
#define INITDEFINE6S 72
|
||||
#endif
|
||||
|
||||
extern const char dhcpcd_embedded_conf[];
|
||||
|
|
|
@ -153,6 +153,10 @@
|
|||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifndef __arraycount
|
||||
# define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Allow a backlog of signals.
|
||||
* If you use many eloops in the same process, they should all
|
||||
|
|
|
@ -328,7 +328,7 @@ ps_bpf_send(const struct interface *ifp, const struct in_addr *ia,
|
|||
if (ia != NULL)
|
||||
psm.ps_id.psi_addr.psa_in_addr = *ia;
|
||||
|
||||
return ps_sendpsmdata(ctx, ctx->ps_root->psp_fd, &psm, data, len);
|
||||
return ps_sendpsmdata(ctx, PS_ROOT_FD(ctx), &psm, data, len);
|
||||
}
|
||||
|
||||
#ifdef ARP
|
||||
|
|
|
@ -301,7 +301,7 @@ ps_root_ioctldom(struct dhcpcd_ctx *ctx, uint16_t domain, unsigned long request,
|
|||
void *data, size_t len)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, domain,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), domain,
|
||||
request, data, len) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, data, len);
|
||||
|
@ -327,7 +327,7 @@ ssize_t
|
|||
ps_root_route(struct dhcpcd_ctx *ctx, void *data, size_t len)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_ROUTE, 0, data, len) == -1)
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_ROUTE, 0, data, len) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, data, len);
|
||||
}
|
||||
|
@ -346,7 +346,7 @@ ps_root_indirectioctl(struct dhcpcd_ctx *ctx, unsigned long request,
|
|||
|
||||
strlcpy(buf, ifname, IFNAMSIZ);
|
||||
memcpy(buf + IFNAMSIZ, data, len);
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_IOCTLINDIRECT,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IOCTLINDIRECT,
|
||||
request, buf, IFNAMSIZ + len) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, data, len);
|
||||
|
@ -358,7 +358,7 @@ ssize_t
|
|||
ps_root_ifignoregroup(struct dhcpcd_ctx *ctx, const char *ifname)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_IFIGNOREGRP, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IFIGNOREGRP, 0,
|
||||
ifname, strlen(ifname) + 1) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -400,7 +400,7 @@ ps_root_sysctl(struct dhcpcd_ctx *ctx,
|
|||
p += newlen;
|
||||
}
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_SYSCTL,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SYSCTL,
|
||||
flags, buf, (size_t)(p - buf)) == -1)
|
||||
return -1;
|
||||
|
||||
|
|
|
@ -64,27 +64,13 @@ ps_ctl_startcb(struct ps_process *psp)
|
|||
ctx->options & DHCPCD_MANAGER ? NULL : *ctx->ifv, af);
|
||||
}
|
||||
|
||||
static ssize_t
|
||||
ps_ctl_recvmsgcb(void *arg, struct ps_msghdr *psm, __unused struct msghdr *msg)
|
||||
{
|
||||
struct dhcpcd_ctx *ctx = arg;
|
||||
|
||||
if (psm->ps_cmd != PS_CTL_EOF) {
|
||||
errno = ENOTSUP;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx->ps_control_client = NULL;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
ps_ctl_recvmsg(void *arg, unsigned short events)
|
||||
{
|
||||
struct ps_process *psp = arg;
|
||||
|
||||
if (ps_recvpsmsg(psp->psp_ctx, psp->psp_fd, events,
|
||||
ps_ctl_recvmsgcb, psp->psp_ctx) == -1)
|
||||
NULL, psp->psp_ctx) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
|
||||
|
@ -175,22 +161,26 @@ ps_ctl_recv(void *arg, unsigned short events)
|
|||
char buf[BUFSIZ];
|
||||
ssize_t len;
|
||||
|
||||
if (!(events & ELE_READ))
|
||||
if (!(events & (ELE_READ | ELE_HANGUP)))
|
||||
logerrx("%s: unexpected event 0x%04x", __func__, events);
|
||||
|
||||
len = read(ctx->ps_ctl->psp_work_fd, buf, sizeof(buf));
|
||||
if (len == 0)
|
||||
return;
|
||||
if (len == -1) {
|
||||
logerr("%s: read", __func__);
|
||||
eloop_exit(ctx->eloop, EXIT_FAILURE);
|
||||
return;
|
||||
if (events & ELE_READ) {
|
||||
len = read(ctx->ps_ctl->psp_work_fd, buf, sizeof(buf));
|
||||
if (len == -1)
|
||||
logerr("%s: read", __func__);
|
||||
else if (len == 0)
|
||||
// FIXME: Why does this happen?
|
||||
;
|
||||
else if (ctx->ps_control_client == NULL)
|
||||
logerrx("%s: clientfd #%d disconnected (len=%zd)",
|
||||
__func__, ctx->ps_ctl->psp_work_fd, len);
|
||||
else {
|
||||
errno = 0;
|
||||
if (control_queue(ctx->ps_control_client,
|
||||
buf, (size_t)len) == -1)
|
||||
logerr("%s: control_queue", __func__);
|
||||
}
|
||||
}
|
||||
if (ctx->ps_control_client == NULL) /* client disconnected */
|
||||
return;
|
||||
errno = 0;
|
||||
if (control_queue(ctx->ps_control_client, buf, (size_t)len) == -1)
|
||||
logerr("%s: control_queue", __func__);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -205,8 +195,6 @@ ps_ctl_listen(void *arg, unsigned short events)
|
|||
logerrx("%s: unexpected event 0x%04x", __func__, events);
|
||||
|
||||
len = read(ctx->ps_control->fd, buf, sizeof(buf));
|
||||
if (len == 0)
|
||||
return;
|
||||
if (len == -1) {
|
||||
logerr("%s: read", __func__);
|
||||
eloop_exit(ctx->eloop, EXIT_FAILURE);
|
||||
|
|
|
@ -53,7 +53,7 @@ ps_inet_recvbootp(void *arg, unsigned short events)
|
|||
{
|
||||
struct dhcpcd_ctx *ctx = arg;
|
||||
|
||||
if (ps_recvmsg(ctx, ctx->udp_rfd, events,
|
||||
if (ps_recvmsg(ctx->udp_rfd, events,
|
||||
PS_BOOTP, ctx->ps_inet->psp_fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
|
@ -68,13 +68,13 @@ ps_inet_recvra(void *arg, unsigned short events)
|
|||
struct rs_state *state = RS_STATE(ifp);
|
||||
struct dhcpcd_ctx *ctx = ifp->ctx;
|
||||
|
||||
if (ps_recvmsg(ctx, state->nd_fd, events,
|
||||
if (ps_recvmsg(state->nd_fd, events,
|
||||
PS_ND, ctx->ps_inet->psp_fd) == -1)
|
||||
logerr(__func__);
|
||||
#else
|
||||
struct dhcpcd_ctx *ctx = arg;
|
||||
|
||||
if (ps_recvmsg(ctx, ctx->nd_fd, events,
|
||||
if (ps_recvmsg(ctx->nd_fd, events,
|
||||
PS_ND, ctx->ps_inet->psp_fd) == -1)
|
||||
logerr(__func__);
|
||||
#endif
|
||||
|
@ -87,7 +87,7 @@ ps_inet_recvdhcp6(void *arg, unsigned short events)
|
|||
{
|
||||
struct dhcpcd_ctx *ctx = arg;
|
||||
|
||||
if (ps_recvmsg(ctx, ctx->dhcp6_rfd, events,
|
||||
if (ps_recvmsg(ctx->dhcp6_rfd, events,
|
||||
PS_DHCP6, ctx->ps_inet->psp_fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
|
@ -387,7 +387,7 @@ ps_inet_recvinbootp(void *arg, unsigned short events)
|
|||
{
|
||||
struct ps_process *psp = arg;
|
||||
|
||||
if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, events,
|
||||
if (ps_recvmsg(psp->psp_work_fd, events,
|
||||
PS_BOOTP, psp->psp_ctx->ps_data_fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
|
@ -430,7 +430,7 @@ ps_inet_recvin6nd(void *arg)
|
|||
{
|
||||
struct ps_process *psp = arg;
|
||||
|
||||
if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd,
|
||||
if (ps_recvmsg(psp->psp_work_fd,
|
||||
PS_ND, psp->psp_ctx->ps_data_fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
|
@ -470,7 +470,7 @@ ps_inet_recvin6dhcp6(void *arg, unsigned short events)
|
|||
{
|
||||
struct ps_process *psp = arg;
|
||||
|
||||
if (ps_recvmsg(psp->psp_ctx, psp->psp_work_fd, events,
|
||||
if (ps_recvmsg(psp->psp_work_fd, events,
|
||||
PS_DHCP6, psp->psp_ctx->ps_data_fd) == -1)
|
||||
logerr(__func__);
|
||||
}
|
||||
|
@ -622,7 +622,7 @@ ps_inet_in_docmd(struct ipv4_addr *ia, uint16_t cmd, const struct msghdr *msg)
|
|||
},
|
||||
};
|
||||
|
||||
return ps_sendpsmmsg(ctx, ctx->ps_root->psp_fd, &psm, msg);
|
||||
return ps_sendpsmmsg(ctx, PS_ROOT_FD(ctx), &psm, msg);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
|
@ -644,7 +644,7 @@ ps_inet_sendbootp(struct interface *ifp, const struct msghdr *msg)
|
|||
{
|
||||
struct dhcpcd_ctx *ctx = ifp->ctx;
|
||||
|
||||
return ps_sendmsg(ctx, ctx->ps_root->psp_fd, PS_BOOTP, 0, msg);
|
||||
return ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_BOOTP, 0, msg);
|
||||
}
|
||||
#endif /* INET */
|
||||
|
||||
|
@ -663,7 +663,7 @@ ps_inet_ifp_docmd(struct interface *ifp, uint16_t cmd, const struct msghdr *msg)
|
|||
},
|
||||
};
|
||||
|
||||
return ps_sendpsmmsg(ctx, ctx->ps_root->psp_fd, &psm, msg);
|
||||
return ps_sendpsmmsg(ctx, PS_ROOT_FD(ctx), &psm, msg);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
|
@ -692,7 +692,7 @@ ps_inet_sendnd(struct interface *ifp, const struct msghdr *msg)
|
|||
{
|
||||
struct dhcpcd_ctx *ctx = ifp->ctx;
|
||||
|
||||
return ps_sendmsg(ctx, ctx->ps_root->psp_fd, PS_ND, 0, msg);
|
||||
return ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_ND, 0, msg);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -711,7 +711,7 @@ ps_inet_in6_docmd(struct ipv6_addr *ia, uint16_t cmd, const struct msghdr *msg)
|
|||
},
|
||||
};
|
||||
|
||||
return ps_sendpsmmsg(ctx, ctx->ps_root->psp_fd, &psm, msg);
|
||||
return ps_sendpsmmsg(ctx, PS_ROOT_FD(ctx), &psm, msg);
|
||||
}
|
||||
|
||||
ssize_t
|
||||
|
@ -733,7 +733,7 @@ ps_inet_senddhcp6(struct interface *ifp, const struct msghdr *msg)
|
|||
{
|
||||
struct dhcpcd_ctx *ctx = ifp->ctx;
|
||||
|
||||
return ps_sendmsg(ctx, ctx->ps_root->psp_fd, PS_DHCP6, 0, msg);
|
||||
return ps_sendmsg(ctx, PS_ROOT_FD(ctx), PS_DHCP6, 0, msg);
|
||||
}
|
||||
#endif /* DHCP6 */
|
||||
#endif /* INET6 */
|
||||
|
|
|
@ -97,7 +97,7 @@ ps_root_readerrorcb(void *arg, unsigned short events)
|
|||
goto out; \
|
||||
} while (0 /* CONSTCOND */)
|
||||
|
||||
len = readv(ctx->ps_root->psp_fd, iov, __arraycount(iov));
|
||||
len = readv(PS_ROOT_FD(ctx), iov, __arraycount(iov));
|
||||
if (len == -1)
|
||||
PSR_ERROR(errno);
|
||||
else if ((size_t)len < sizeof(*psr_error))
|
||||
|
@ -115,14 +115,15 @@ ps_root_readerror(struct dhcpcd_ctx *ctx, void *data, size_t len)
|
|||
.psr_ctx = ctx,
|
||||
.psr_data = data, .psr_datalen = len,
|
||||
};
|
||||
int fd = PS_ROOT_FD(ctx);
|
||||
|
||||
if (eloop_event_add(ctx->ps_eloop, ctx->ps_root->psp_fd, ELE_READ,
|
||||
if (eloop_event_add(ctx->ps_eloop, fd, ELE_READ,
|
||||
ps_root_readerrorcb, &psr_ctx) == -1)
|
||||
return -1;
|
||||
|
||||
eloop_enter(ctx->ps_eloop);
|
||||
eloop_start(ctx->ps_eloop, &ctx->sigset);
|
||||
eloop_event_delete(ctx->ps_eloop, ctx->ps_root->psp_fd);
|
||||
eloop_event_delete(ctx->ps_eloop, fd);
|
||||
|
||||
errno = psr_ctx.psr_error.psr_errno;
|
||||
return psr_ctx.psr_error.psr_result;
|
||||
|
@ -145,8 +146,7 @@ ps_root_mreaderrorcb(void *arg, unsigned short events)
|
|||
if (events != ELE_READ)
|
||||
logerrx("%s: unexpected event 0x%04x", __func__, events);
|
||||
|
||||
len = recv(ctx->ps_root->psp_fd,
|
||||
psr_error, sizeof(*psr_error), MSG_PEEK);
|
||||
len = recv(PS_ROOT_FD(ctx), psr_error, sizeof(*psr_error), MSG_PEEK);
|
||||
if (len == -1)
|
||||
PSR_ERROR(errno);
|
||||
else if ((size_t)len < sizeof(*psr_error))
|
||||
|
@ -163,7 +163,7 @@ ps_root_mreaderrorcb(void *arg, unsigned short events)
|
|||
iov[1].iov_len = psr_ctx->psr_datalen;
|
||||
}
|
||||
|
||||
len = readv(ctx->ps_root->psp_fd, iov, __arraycount(iov));
|
||||
len = readv(PS_ROOT_FD(ctx), iov, __arraycount(iov));
|
||||
if (len == -1)
|
||||
PSR_ERROR(errno);
|
||||
else if ((size_t)len != sizeof(*psr_error) + psr_ctx->psr_datalen)
|
||||
|
@ -180,14 +180,15 @@ ps_root_mreaderror(struct dhcpcd_ctx *ctx, void **data, size_t *len)
|
|||
struct psr_ctx psr_ctx = {
|
||||
.psr_ctx = ctx,
|
||||
};
|
||||
int fd = PS_ROOT_FD(ctx);
|
||||
|
||||
if (eloop_event_add(ctx->ps_eloop, ctx->ps_root->psp_fd, ELE_READ,
|
||||
if (eloop_event_add(ctx->ps_eloop, fd, ELE_READ,
|
||||
ps_root_mreaderrorcb, &psr_ctx) == -1)
|
||||
return -1;
|
||||
|
||||
eloop_enter(ctx->ps_eloop);
|
||||
eloop_start(ctx->ps_eloop, &ctx->sigset);
|
||||
eloop_event_delete(ctx->ps_eloop, ctx->ps_root->psp_fd);
|
||||
eloop_event_delete(ctx->ps_eloop, fd);
|
||||
|
||||
errno = psr_ctx.psr_error.psr_errno;
|
||||
*data = psr_ctx.psr_data;
|
||||
|
@ -210,12 +211,13 @@ ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result,
|
|||
{ .iov_base = data, .iov_len = len },
|
||||
};
|
||||
ssize_t err;
|
||||
int fd = PS_ROOT_FD(ctx);
|
||||
|
||||
#ifdef PRIVSEP_DEBUG
|
||||
logdebugx("%s: result %zd errno %d", __func__, result, errno);
|
||||
#endif
|
||||
|
||||
err = writev(ctx->ps_root->psp_fd, iov, __arraycount(iov));
|
||||
err = writev(fd, iov, __arraycount(iov));
|
||||
|
||||
/* Error sending the message? Try sending the error of sending. */
|
||||
if (err == -1) {
|
||||
|
@ -225,7 +227,7 @@ ps_root_writeerror(struct dhcpcd_ctx *ctx, ssize_t result,
|
|||
psr.psr_errno = errno;
|
||||
iov[1].iov_base = NULL;
|
||||
iov[1].iov_len = 0;
|
||||
err = writev(ctx->ps_root->psp_fd, iov, __arraycount(iov));
|
||||
err = writev(fd, iov, __arraycount(iov));
|
||||
}
|
||||
|
||||
return err;
|
||||
|
@ -960,13 +962,15 @@ ps_root_stop(struct dhcpcd_ctx *ctx)
|
|||
* log dhcpcd exits because the latter requires the former.
|
||||
* So we just log the intent to exit.
|
||||
* Even sending this will be a race to exit. */
|
||||
logdebugx("%s%s%s will exit from PID %d",
|
||||
psp->psp_ifname,
|
||||
psp->psp_ifname[0] != '\0' ? ": " : "",
|
||||
psp->psp_name, psp->psp_pid);
|
||||
if (psp) {
|
||||
logdebugx("%s%s%s will exit from PID %d",
|
||||
psp->psp_ifname,
|
||||
psp->psp_ifname[0] != '\0' ? ": " : "",
|
||||
psp->psp_name, psp->psp_pid);
|
||||
|
||||
if (ps_stopprocess(psp) == -1)
|
||||
return -1;
|
||||
if (ps_stopprocess(psp) == -1)
|
||||
return -1;
|
||||
} /* else the root process has already exited :( */
|
||||
|
||||
return ps_stopwait(ctx);
|
||||
}
|
||||
|
@ -978,7 +982,7 @@ ps_root_stopprocesses(struct dhcpcd_ctx *ctx)
|
|||
if (!(IN_PRIVSEP_SE(ctx)))
|
||||
return 0;
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_STOPPROCS, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_STOPPROCS, 0,
|
||||
NULL, 0) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -988,7 +992,7 @@ ssize_t
|
|||
ps_root_script(struct dhcpcd_ctx *ctx, const void *data, size_t len)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_SCRIPT,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_SCRIPT,
|
||||
0, data, len) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -998,7 +1002,7 @@ ssize_t
|
|||
ps_root_ioctl(struct dhcpcd_ctx *ctx, ioctl_request_t req, void *data,
|
||||
size_t len)
|
||||
{
|
||||
int fd = ctx->ps_root->psp_fd;
|
||||
int fd = PS_ROOT_FD(ctx);
|
||||
#ifdef IOCTL_REQUEST_TYPE
|
||||
unsigned long ulreq = 0;
|
||||
|
||||
|
@ -1016,7 +1020,7 @@ ssize_t
|
|||
ps_root_unlink(struct dhcpcd_ctx *ctx, const char *file)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_UNLINK, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_UNLINK, 0,
|
||||
file, strlen(file) + 1) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -1026,7 +1030,7 @@ ssize_t
|
|||
ps_root_readfile(struct dhcpcd_ctx *ctx, const char *file,
|
||||
void *data, size_t len)
|
||||
{
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_READFILE, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_READFILE, 0,
|
||||
file, strlen(file) + 1) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, data, len);
|
||||
|
@ -1047,7 +1051,7 @@ ps_root_writefile(struct dhcpcd_ctx *ctx, const char *file, mode_t mode,
|
|||
}
|
||||
memcpy(buf + flen, data, len);
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_WRITEFILE, mode,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_WRITEFILE, mode,
|
||||
buf, flen + len) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -1057,7 +1061,7 @@ ssize_t
|
|||
ps_root_filemtime(struct dhcpcd_ctx *ctx, const char *file, time_t *time)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_FILEMTIME, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_FILEMTIME, 0,
|
||||
file, strlen(file) + 1) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, time, sizeof(*time));
|
||||
|
@ -1067,7 +1071,7 @@ ssize_t
|
|||
ps_root_logreopen(struct dhcpcd_ctx *ctx)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_LOGREOPEN, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_LOGREOPEN, 0,
|
||||
NULL, 0) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -1084,7 +1088,7 @@ ps_root_getifaddrs(struct dhcpcd_ctx *ctx, struct ifaddrs **ifahead)
|
|||
size_t len;
|
||||
ssize_t err;
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx),
|
||||
PS_GETIFADDRS, 0, NULL, 0) == -1)
|
||||
return -1;
|
||||
err = ps_root_mreaderror(ctx, &buf, &len);
|
||||
|
@ -1159,7 +1163,7 @@ ssize_t
|
|||
ps_root_ip6forwarding(struct dhcpcd_ctx *ctx, const char *ifname)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_IP6FORWARDING, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_IP6FORWARDING, 0,
|
||||
ifname, ifname != NULL ? strlen(ifname) + 1 : 0) == -1)
|
||||
return -1;
|
||||
return ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -1171,7 +1175,7 @@ int
|
|||
ps_root_getauthrdm(struct dhcpcd_ctx *ctx, uint64_t *rdm)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_AUTH_MONORDM, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_AUTH_MONORDM, 0,
|
||||
rdm, sizeof(*rdm))== -1)
|
||||
return -1;
|
||||
return (int)ps_root_readerror(ctx, rdm, sizeof(*rdm));
|
||||
|
@ -1183,7 +1187,7 @@ int
|
|||
ps_root_dev_initialised(struct dhcpcd_ctx *ctx, const char *ifname)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_DEV_INITTED, 0,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_INITTED, 0,
|
||||
ifname, strlen(ifname) + 1)== -1)
|
||||
return -1;
|
||||
return (int)ps_root_readerror(ctx, NULL, 0);
|
||||
|
@ -1193,7 +1197,7 @@ int
|
|||
ps_root_dev_listening(struct dhcpcd_ctx * ctx)
|
||||
{
|
||||
|
||||
if (ps_sendcmd(ctx, ctx->ps_root->psp_fd, PS_DEV_LISTENING,
|
||||
if (ps_sendcmd(ctx, PS_ROOT_FD(ctx), PS_DEV_LISTENING,
|
||||
0, NULL, 0) == -1)
|
||||
return -1;
|
||||
return (int)ps_root_readerror(ctx, NULL, 0);
|
||||
|
|
|
@ -113,6 +113,8 @@
|
|||
#define PRIVSEP_RIGHTS
|
||||
#endif
|
||||
|
||||
#define PS_ROOT_FD(ctx) ((ctx)->ps_root ? (ctx)->ps_root->psp_fd : -1)
|
||||
|
||||
#ifdef __linux__
|
||||
# include <linux/version.h>
|
||||
# if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 5, 0)
|
||||
|
@ -211,7 +213,7 @@ ssize_t ps_sendmsg(struct dhcpcd_ctx *, int, uint16_t, unsigned long,
|
|||
const struct msghdr *);
|
||||
ssize_t ps_sendcmd(struct dhcpcd_ctx *, int, uint16_t, unsigned long,
|
||||
const void *data, size_t len);
|
||||
ssize_t ps_recvmsg(struct dhcpcd_ctx *, int, unsigned short, uint16_t, int);
|
||||
ssize_t ps_recvmsg(int, unsigned short, uint16_t, int);
|
||||
ssize_t ps_recvpsmsg(struct dhcpcd_ctx *, int, unsigned short,
|
||||
ssize_t (*callback)(void *, struct ps_msghdr *, struct msghdr *), void *);
|
||||
|
||||
|
|
Loading…
Reference in New Issue