tunctl add group support
PATCH 1/1 tunctl add group support
Add support for -g (group) parameter to set permission of group based.
Signed-off-by Alon Bar-Lev <[email protected]>
---
tunctl/tunctl.c +27 -4
@@ -9,13 +9,14 @@#include <fcntl.h> #include <unistd.h> #include <pwd.h> +#include <grp.h> #include <net/if.h> #include <sys/ioctl.h> #include <linux/if_tun.h> static void Usage (char *name) { -fprintf (stderr,"Create: %s [-b] [-u owner] [-t device-name] " +fprintf (stderr,"Create: %s [-b] [ -g group ] [-u owner] [-t device-name] " "[-f tun-clone-device]\n" , name);fprintf (stderr,"Delete: %s -d device-name [-f tun-clone-device]\n\n" , name);
@@ -29,11 +30,13 @@ int main(int argc, char **argv) {struct ifreq ifr;struct passwd *pw; +struct group *gr;long owner =geteuid (); +long group =getegid ();int tap_fd, opt, delete =0 , brief =0 ;char *tun ="" , *file ="/dev/net/tun" , *name = argv[0 ], *end; -while ((opt =getopt (argc, argv,"bd:f:t:u:" )) >0 ){ +while ((opt =getopt (argc, argv,"bd:f:t:u:g:" )) >0 ){switch (opt) {case 'b' : brief =1 ;
@@ -58,6 +61,19 @@ int main(int argc, char **argv)Usage (name); }break ; +case 'g' : + gr =getgrnam (optarg); +if (gr !=NULL ){ + group = gr->gr_gid; +break ; + } + group =strtol (optarg, &end,0 ); +if (*end !='\0' ){ +fprintf (stderr,"'%s' is neither a groupname nor a numeric gid.\n" , + optarg); +Usage (name); + } +break ;case 't' : tun = optarg;break ;
@@ -104,10 +120,17 @@ int main(int argc, char **argv)perror ("TUNSETPERSIST" );exit (1 ); } +#ifndef TUNSETGROUP +#define TUNSETGROUP _IOW('T', 206, int) +#endif +if (ioctl (tap_fd,TUNSETGROUP , group) <0 ){ +perror ("TUNSETGROUP" ); + group=-1 ; + }if (brief)printf ("%s\n" , ifr.ifr_name); -else printf ("Set '%s' persistent and owned by uid %ld\n" , ifr.ifr_name, - owner); +else printf ("Set '%s' persistent and owned by gid %ld uid %ld\n" , + ifr.ifr_name, group, owner); }return (0 ); }
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems? Stop. Now Search log events and configuration files using AJAX and a browser. Download your FREE copy of Splunk now >> http://get.splunk.com/
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel