All of lore.kernel.org
 help / color / mirror / Atom feed
From: Alon Bar-Lev <alon.barlev@gmail.com>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: [uml-devel] [PATCH] tunctl add group support
Date: Thu, 1 Nov 2007 19:18:34 +0200	[thread overview]
Message-ID: <200711011918.36294.alon.barlev@gmail.com> (raw)


Add support for -g (group) parameter to set permission of group
based.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>

---

diff -urNp tools-20060323.org/tunctl/tunctl.c tools-20060323/tunctl/tunctl.c
--- tools-20060323.org/tunctl/tunctl.c	2002-09-11 01:18:06.000000000 +0300
+++ tools-20060323/tunctl/tunctl.c	2007-11-01 17:05:09.000000000 +0200
@@ -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
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

                 reply	other threads:[~2007-11-01 17:19 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200711011918.36294.alon.barlev@gmail.com \
    --to=alon.barlev@gmail.com \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.