Move set_cap() to ncmlib/cap.[ch].
This commit is contained in:
@@ -8,7 +8,6 @@ set(NDHC_SRCS
|
||||
packet.c
|
||||
script.c
|
||||
clientpacket.c
|
||||
rootcap.c
|
||||
dhcpc.c
|
||||
)
|
||||
|
||||
|
@@ -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"
|
||||
|
@@ -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);
|
||||
}
|
@@ -1,6 +0,0 @@
|
||||
#ifndef ROOTCAP_H_
|
||||
#define ROOTCAP_H_
|
||||
|
||||
void set_cap(uid_t uid, gid_t gid, char *captxt);
|
||||
|
||||
#endif /* ROOTCAP_H_ */
|
Reference in New Issue
Block a user