Skip to content
This repository was archived by the owner on Jun 24, 2020. It is now read-only.

Commit 6b0a93f

Browse files
committed
Merge pull request #14 from Raizo62/master
Change owner of files when iouyap is launched with bit setuid set
2 parents 4847cf7 + 5bdc777 commit 6b0a93f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

iouyap.c

+9-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ foreign_port_t *port_table = NULL;
6363
static int
6464
set_socket_directory (char *dir)
6565
{
66-
return snprintf (dir, UNIX_PATH_MAX, "%s%u", NETIO_DIR_PREFIX, geteuid ());
66+
return snprintf (dir, UNIX_PATH_MAX, "%s%u", NETIO_DIR_PREFIX, getuid ());
6767
}
6868

6969

@@ -776,6 +776,10 @@ open_pcap_file (foreign_port_t * port, char *file, int no_hdr, int overwrite)
776776

777777
if ((fd = open (file, O_CREAT | O_WRONLY | O_APPEND, S_IRUSR | S_IWUSR)) < 0)
778778
fatal_error ("open");
779+
780+
if( getuid() != geteuid() )
781+
if( fchown(fd, getuid (), -1) )
782+
fatal_error ("fchown");
779783

780784
/* If we can get an exclusive lock (without blocking) then check to see
781785
* if the file is empty. Write a pcap header if it is.
@@ -1028,6 +1032,10 @@ open_iou_uds ()
10281032
unlink (sock_addr.sun_path);
10291033
if (bind (sfd, (struct sockaddr *) &sock_addr, sizeof sock_addr))
10301034
fatal_error ("bind");
1035+
1036+
if( getuid() != geteuid() )
1037+
if( chown(sock_addr.sun_path, getuid (), -1) )
1038+
fatal_error ("chown");
10311039

10321040
return sfd;
10331041
}

0 commit comments

Comments
 (0)