|
@ -1,4 +1,4 @@ |
|
|
/* $OpenBSD: constraint.c,v 1.21 2015/11/19 21:32:53 mmcc Exp $ */ |
|
|
|
|
|
|
|
|
/* $OpenBSD: constraint.c,v 1.22 2015/11/24 01:03:25 deraadt Exp $ */ |
|
|
|
|
|
|
|
|
/* |
|
|
/* |
|
|
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> |
|
|
* Copyright (c) 2015 Reyk Floeter <reyk@openbsd.org> |
|
@ -58,7 +58,7 @@ int constraint_cmp(const void *, const void *); |
|
|
|
|
|
|
|
|
void priv_constraint_close(int, int); |
|
|
void priv_constraint_close(int, int); |
|
|
void priv_constraint_child(struct constraint *, struct ntp_addr_msg *, |
|
|
void priv_constraint_child(struct constraint *, struct ntp_addr_msg *, |
|
|
u_int8_t *, int[2]); |
|
|
|
|
|
|
|
|
u_int8_t *, int[2], const char *, uid_t, gid_t); |
|
|
|
|
|
|
|
|
struct httpsdate * |
|
|
struct httpsdate * |
|
|
httpsdate_init(const char *, const char *, const char *, |
|
|
httpsdate_init(const char *, const char *, const char *, |
|
@ -207,7 +207,8 @@ constraint_query(struct constraint *cstr) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
priv_constraint_msg(u_int32_t id, u_int8_t *data, size_t len) |
|
|
|
|
|
|
|
|
priv_constraint_msg(u_int32_t id, u_int8_t *data, size_t len, |
|
|
|
|
|
const char *pw_dir, uid_t pw_uid, gid_t pw_gid) |
|
|
{ |
|
|
{ |
|
|
struct ntp_addr_msg am; |
|
|
struct ntp_addr_msg am; |
|
|
struct ntp_addr *h; |
|
|
struct ntp_addr *h; |
|
@ -257,7 +258,8 @@ priv_constraint_msg(u_int32_t id, u_int8_t *data, size_t len) |
|
|
close(pipes[1]); |
|
|
close(pipes[1]); |
|
|
return; |
|
|
return; |
|
|
case 0: |
|
|
case 0: |
|
|
priv_constraint_child(cstr, &am, data + sizeof(am), pipes); |
|
|
|
|
|
|
|
|
priv_constraint_child(cstr, &am, data + sizeof(am), pipes, |
|
|
|
|
|
pw_dir, pw_uid, pw_gid); |
|
|
|
|
|
|
|
|
_exit(0); |
|
|
_exit(0); |
|
|
/* NOTREACHED */ |
|
|
/* NOTREACHED */ |
|
@ -273,12 +275,11 @@ priv_constraint_msg(u_int32_t id, u_int8_t *data, size_t len) |
|
|
|
|
|
|
|
|
void |
|
|
void |
|
|
priv_constraint_child(struct constraint *cstr, struct ntp_addr_msg *am, |
|
|
priv_constraint_child(struct constraint *cstr, struct ntp_addr_msg *am, |
|
|
u_int8_t *data, int pipes[2]) |
|
|
|
|
|
|
|
|
u_int8_t *data, int pipes[2], const char *pw_dir, uid_t pw_uid, gid_t pw_gid) |
|
|
{ |
|
|
{ |
|
|
static char hname[NI_MAXHOST]; |
|
|
static char hname[NI_MAXHOST]; |
|
|
struct timeval rectv, xmttv; |
|
|
struct timeval rectv, xmttv; |
|
|
struct sigaction sa; |
|
|
struct sigaction sa; |
|
|
struct passwd *pw; |
|
|
|
|
|
void *ctx; |
|
|
void *ctx; |
|
|
struct iovec iov[2]; |
|
|
struct iovec iov[2]; |
|
|
int i; |
|
|
int i; |
|
@ -293,18 +294,14 @@ priv_constraint_child(struct constraint *cstr, struct ntp_addr_msg *am, |
|
|
&conf->ca_len, NULL)) == NULL) |
|
|
&conf->ca_len, NULL)) == NULL) |
|
|
log_warnx("constraint certificate verification turned off"); |
|
|
log_warnx("constraint certificate verification turned off"); |
|
|
|
|
|
|
|
|
/* Drop privileges */ |
|
|
|
|
|
if ((pw = getpwnam(NTPD_USER)) == NULL) |
|
|
|
|
|
fatalx("unknown user %s", NTPD_USER); |
|
|
|
|
|
|
|
|
|
|
|
if (chroot(pw->pw_dir) == -1) |
|
|
|
|
|
|
|
|
if (chroot(pw_dir) == -1) |
|
|
fatal("chroot"); |
|
|
fatal("chroot"); |
|
|
if (chdir("/") == -1) |
|
|
if (chdir("/") == -1) |
|
|
fatal("chdir(\"/\")"); |
|
|
fatal("chdir(\"/\")"); |
|
|
|
|
|
|
|
|
if (setgroups(1, &pw->pw_gid) || |
|
|
|
|
|
setresgid(pw->pw_gid, pw->pw_gid, pw->pw_gid) || |
|
|
|
|
|
setresuid(pw->pw_uid, pw->pw_uid, pw->pw_uid)) |
|
|
|
|
|
|
|
|
if (setgroups(1, &pw_gid) || |
|
|
|
|
|
setresgid(pw_gid, pw_gid, pw_gid) || |
|
|
|
|
|
setresuid(pw_uid, pw_uid, pw_uid)) |
|
|
fatal("can't drop privileges"); |
|
|
fatal("can't drop privileges"); |
|
|
|
|
|
|
|
|
/* Reset all signal handlers */ |
|
|
/* Reset all signal handlers */ |
|
|