Move set_cap() to ncmlib/cap.[ch].

This commit is contained in:
Nicholas J. Kain
2010-11-12 09:04:43 -05:00
parent a7ea0dd378
commit b2daf09c10
9 changed files with 103 additions and 100 deletions

View File

@@ -8,7 +8,6 @@ set(NDHC_SRCS
packet.c
script.c
clientpacket.c
rootcap.c
dhcpc.c
)

View File

@@ -36,8 +36,6 @@
#include <sys/ioctl.h>
#include <net/if.h>
#include <errno.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#include <pwd.h>
#include <grp.h>
@@ -50,7 +48,7 @@
#include "socket.h"
#include "log.h"
#include "chroot.h"
#include "rootcap.h"
#include "cap.h"
#include "strl.h"
#define VERSION "1.0"

View File

@@ -1,46 +0,0 @@
#include <unistd.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#include <grp.h>
#include "log.h"
void set_cap(uid_t uid, gid_t gid, char *captxt)
{
cap_t caps;
if (!captxt) {
log_error("FATAL - set_cap: captxt == NULL");
exit(EXIT_FAILURE);
}
if (prctl(PR_SET_KEEPCAPS, 1)) {
log_error("FATAL - set_cap: prctl() failed");
exit(EXIT_FAILURE);
}
if (setgroups(0, NULL) == -1) {
log_error("FATAL - set_cap: setgroups() failed");
exit(EXIT_FAILURE);
}
if (setegid(gid) == -1 || seteuid(uid) == -1) {
log_error("FATAL - set_cap: seteuid() failed");
exit(EXIT_FAILURE);
}
caps = cap_from_text(captxt);
if (!caps) {
log_error("FATAL - set_cap: cap_from_text() failed");
exit(EXIT_FAILURE);
}
if (cap_set_proc(caps) == -1) {
log_error("FATAL - set_cap: cap_set_proc() failed");
exit(EXIT_FAILURE);
}
cap_free(caps);
}

View File

@@ -1,6 +0,0 @@
#ifndef ROOTCAP_H_
#define ROOTCAP_H_
void set_cap(uid_t uid, gid_t gid, char *captxt);
#endif /* ROOTCAP_H_ */