mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-04-16 12:06:55 +02:00
Do not inherit open file descriptors on fork() in MacEthernetTapAgent
This commit is contained in:
parent
ed8fe8990b
commit
d2974f2e60
1 changed files with 11 additions and 0 deletions
|
@ -64,6 +64,7 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/resource.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/bpf.h>
|
||||
|
@ -181,6 +182,14 @@ static void die()
|
|||
run("/sbin/ifconfig",s_peerDeviceName,"destroy",(char *)0);
|
||||
}
|
||||
|
||||
static inline void close_inherited_fds()
|
||||
{
|
||||
struct rlimit lim;
|
||||
getrlimit(RLIMIT_NOFILE, &lim);
|
||||
for (int i=3,j=(int)lim.rlim_cur;i<j;++i)
|
||||
close(i);
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char buf[128];
|
||||
|
@ -206,6 +215,8 @@ int main(int argc,char **argv)
|
|||
signal(SIGINT,&exit);
|
||||
signal(SIGPIPE,&exit);
|
||||
|
||||
close_inherited_fds();
|
||||
|
||||
if (getuid() != 0) {
|
||||
if (setuid(0) != 0) {
|
||||
fprintf(stderr,"E must be run as root or with root setuid bit on executable\n");
|
||||
|
|
Loading…
Add table
Reference in a new issue