diff options
author | Mark Johnston <markj@FreeBSD.org> | 2018-08-07 13:50:21 +0000 |
---|---|---|
committer | Mark Johnston <markj@FreeBSD.org> | 2018-08-07 13:50:21 +0000 |
commit | 17cfcf1dc29b22f9d874cf42c9f0ec134edbfd41 (patch) | |
tree | ba6395ca170fa532602e9aefe68cf7b44f21edc8 /sbin/dhclient/dhclient.c | |
parent | 6938805f4155af8e97fdc664ebbed63ecf70a9e4 (diff) | |
download | src-test2-17cfcf1dc29b22f9d874cf42c9f0ec134edbfd41.tar.gz src-test2-17cfcf1dc29b22f9d874cf42c9f0ec134edbfd41.zip |
Notes
Diffstat (limited to 'sbin/dhclient/dhclient.c')
-rw-r--r-- | sbin/dhclient/dhclient.c | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index 34c748735f55..907a721512a7 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -529,23 +529,21 @@ main(int argc, char *argv[]) if (cap_rights_limit(routefd, &rights) < 0 && errno != ENOSYS) error("can't limit route socket: %m"); - if (setgroups(1, &pw->pw_gid) || - setegid(pw->pw_gid) || setgid(pw->pw_gid) || - seteuid(pw->pw_uid) || setuid(pw->pw_uid)) - error("can't drop privileges: %m"); - endpwent(); setproctitle("%s", ifi->name); + /* setgroups(2) is not permitted in capability mode. */ + if (setgroups(1, &pw->pw_gid) != 0) + error("can't restrict groups: %m"); + if (caph_enter_casper() < 0) error("can't enter capability mode: %m"); /* - * If we are not in capability mode (i.e., because Capsicum or - * libcasper is disabled), try to restrict filesystem access. This - * will fail if kern.chroot_allow_open_directories is 0 or the process - * is jailed. + * If we are not in capability mode (i.e., Capsicum or libcasper is + * disabled), try to restrict filesystem access. This will fail if + * kern.chroot_allow_open_directories is 0 or the process is jailed. */ if (cap_getmode(&capmode) < 0 || capmode == 0) { if (chroot(_PATH_VAREMPTY) == -1) @@ -554,6 +552,10 @@ main(int argc, char *argv[]) error("chdir(\"/\")"); } + if (setegid(pw->pw_gid) || setgid(pw->pw_gid) || + seteuid(pw->pw_uid) || setuid(pw->pw_uid)) + error("can't drop privileges: %m"); + if (immediate_daemon) go_daemon(); |