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

@@ -1,5 +1,5 @@
/* ifchd.c - interface change daemon
* Time-stamp: <2010-11-12 06:02:59 njk>
* Time-stamp: <2010-11-12 09:02:54 njk>
*
* (C) 2004 Nicholas J. Kain <njk@aerifal.cx>
*
@@ -49,6 +49,7 @@
#include "strlist.h"
#include "ifproto.h"
#include "strl.h"
#include "cap.h"
#include "linux.h"
enum states {

View File

@@ -1,5 +1,5 @@
/* linux.c - ifchd Linux-specific functions
* Time-stamp: <2010-11-12 05:14:52 njk>
* Time-stamp: <2010-11-12 08:45:42 njk>
*
* (C) 2004 Nicholas J. Kain <njk@aerifal.cx>
*
@@ -27,8 +27,6 @@
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/types.h>
#include <sys/capability.h>
#include <sys/prctl.h>
#include <sys/ioctl.h>
#include <netinet/in.h>
#include <arpa/inet.h>
@@ -333,41 +331,3 @@ void perform_broadcast(int idx, char *str)
ifnam[idx], strerror(errno));
close(fd);
}
void set_cap(uid_t uid, gid_t gid, char *captxt)
{
cap_t caps;
if (!captxt) {
log_line("FATAL - set_cap: captxt == NULL\n");
exit(EXIT_FAILURE);
}
if (prctl(PR_SET_KEEPCAPS, 1)) {
log_line("FATAL - set_cap: prctl() failed\n");
exit(EXIT_FAILURE);
}
if (setgroups(0, NULL) == -1) {
log_line("FATAL - set_cap: setgroups() failed\n");
exit(EXIT_FAILURE);
}
if (setegid(gid) == -1 || seteuid(uid) == -1) {
log_line("FATAL - set_cap: seteuid() failed\n");
exit(EXIT_FAILURE);
}
caps = cap_from_text(captxt);
if (!caps) {
log_line("FATAL - set_cap: cap_from_text() failed\n");
exit(EXIT_FAILURE);
}
if (cap_set_proc(caps) == -1) {
log_line("FATAL - set_cap: cap_set_proc() failed\n");
exit(EXIT_FAILURE);
}
cap_free(caps);
}

View File

@@ -1,5 +1,5 @@
/* linux.h - ifchd Linux-specific functions include
* Time-stamp: <2010-11-12 04:59:01 njk>
* Time-stamp: <2010-11-12 09:03:29 njk>
*
* (C) 2004 Nicholas J. Kain <njk@aerifal.cx>
*
@@ -31,6 +31,5 @@ void perform_subnet(int idx, char *str);
void perform_router(int idx, char *str);
void perform_mtu(int idx, char *str);
void perform_broadcast(int idx, char *str);
void set_cap(uid_t uid, gid_t gid, char *captxt);
#endif