Revert "mausezahn: Add error handling for mismatched address families"
[netsniff-ng-new.git] / privs.c
blobac4ad25c337b2db978b5a9e76cefc2218e7eb07f
1 #include <unistd.h>
2 #include <sys/types.h>
4 #include "privs.h"
5 #include "die.h"
7 void drop_privileges(bool enforce, uid_t uid, gid_t gid)
9 if (enforce) {
10 if (uid == getuid())
11 panic("Uid cannot be the same as the current user!\n");
12 if (gid == getgid())
13 panic("Gid cannot be the same as the current user!\n");
15 if (setgid(gid) != 0)
16 panic("Unable to drop group privileges: %s!\n", strerror(errno));
17 if (setuid(uid) != 0)
18 panic("Unable to drop user privileges: %s!\n", strerror(errno));