aboutsummaryrefslogtreecommitdiff
path: root/sbin/bsdlabel/bsdlabel.c
diff options
context:
space:
mode:
authorKevin Lo <kevlo@FreeBSD.org>2010-05-16 08:03:24 +0000
committerKevin Lo <kevlo@FreeBSD.org>2010-05-16 08:03:24 +0000
commit73d6722d2731009f933df654878137b0ff1563fd (patch)
treee8298220934fc5f0c64a62e18cad9a0ef535283c /sbin/bsdlabel/bsdlabel.c
parentee56d88b763c1b47666c9e223d01840851a4e8eb (diff)
downloadsrc-73d6722d2731009f933df654878137b0ff1563fd.tar.gz
src-73d6722d2731009f933df654878137b0ff1563fd.zip
Use setresuid/setresgid to drop privileges
Notes
Notes: svn path=/head/; revision=208132
Diffstat (limited to 'sbin/bsdlabel/bsdlabel.c')
-rw-r--r--sbin/bsdlabel/bsdlabel.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/sbin/bsdlabel/bsdlabel.c b/sbin/bsdlabel/bsdlabel.c
index 9a6027c7951a..7f058747f246 100644
--- a/sbin/bsdlabel/bsdlabel.c
+++ b/sbin/bsdlabel/bsdlabel.c
@@ -684,6 +684,8 @@ editit(void)
int pid, xpid;
int locstat, omask;
const char *ed;
+ uid_t uid;
+ gid_t gid;
omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP));
while ((pid = fork()) < 0) {
@@ -699,8 +701,12 @@ editit(void)
}
if (pid == 0) {
sigsetmask(omask);
- setgid(getgid());
- setuid(getuid());
+ gid = getgid();
+ if (setresgid(gid, gid, gid) == -1)
+ err(1, "setresgid");
+ uid = getuid();
+ if (setresuid(uid, uid, uid) == -1)
+ err(1, "setresuid");
if ((ed = getenv("EDITOR")) == (char *)0)
ed = DEFEDITOR;
execlp(ed, ed, tmpfil, (char *)0);