- Timestamp:
- Feb 8, 2008 2:19:33 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Installer/linux/tunctl.c
r4050 r6866 10 10 #include <unistd.h> 11 11 #include <pwd.h> 12 #include <grp.h> 12 13 #include <net/if.h> 13 14 #include <sys/ioctl.h> 14 15 #include <linux/if_tun.h> 15 16 17 /* TUNSETGROUP appeared in 2.6.23 */ 18 #ifndef TUNSETGROUP 19 #define TUNSETGROUP _IOW('T', 206, int) 20 #endif 21 16 22 static void Usage(char *name) 17 23 { 18 fprintf(stderr, "Create: %s [-b] [-u owner] [- t device-name] "24 fprintf(stderr, "Create: %s [-b] [-u owner] [-g group] [-t device-name] " 19 25 "[-f tun-clone-device]\n", name); 20 fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n", 26 fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n", 21 27 name); 22 28 fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems" … … 30 36 struct ifreq ifr; 31 37 struct passwd *pw; 32 long owner = geteuid(); 38 struct group *gr; 39 uid_t owner = -1; 40 gid_t group = -1; 33 41 int tap_fd, opt, delete = 0, brief = 0; 34 42 char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end; 35 43 36 while((opt = getopt(argc, argv, "bd:f:t:u: ")) > 0){44 while((opt = getopt(argc, argv, "bd:f:t:u:g:")) > 0){ 37 45 switch(opt) { 38 46 case 'b': … … 59 67 } 60 68 break; 69 case 'g': 70 gr = getgrnam(optarg); 71 if(gr != NULL){ 72 group = gr->gr_gid; 73 break; 74 } 75 group = strtol(optarg, &end, 0); 76 if(*end != '\0'){ 77 fprintf(stderr, "'%s' is neither a groupname nor a numeric group.\n", 78 optarg); 79 Usage(name); 80 } 81 break; 82 61 83 case 't': 62 84 tun = optarg; … … 91 113 if(delete){ 92 114 if(ioctl(tap_fd, TUNSETPERSIST, 0) < 0){ 93 perror(" TUNSETPERSIST");115 perror("disabling TUNSETPERSIST"); 94 116 exit(1); 95 } 117 } 96 118 printf("Set '%s' nonpersistent\n", ifr.ifr_name); 97 119 } 98 120 else { 121 /* emulate behaviour prior to TUNSETGROUP */ 122 if(owner == -1 && group == -1) { 123 owner = geteuid(); 124 } 125 126 if(owner != -1) { 127 if(ioctl(tap_fd, TUNSETOWNER, owner) < 0){ 128 perror("TUNSETOWNER"); 129 exit(1); 130 } 131 } 132 if(group != -1) { 133 if(ioctl(tap_fd, TUNSETGROUP, group) < 0){ 134 perror("TUNSETGROUP"); 135 exit(1); 136 } 137 } 138 99 139 if(ioctl(tap_fd, TUNSETPERSIST, 1) < 0){ 100 perror(" TUNSETPERSIST");140 perror("enabling TUNSETPERSIST"); 101 141 exit(1); 102 142 } 103 if(ioctl(tap_fd, TUNSETOWNER, owner) < 0){ 104 perror("TUNSETPERSIST"); 105 exit(1); 106 } 143 107 144 if(brief) 108 145 printf("%s\n", ifr.ifr_name); 109 else printf("Set '%s' persistent and owned by uid %ld\n", ifr.ifr_name, 110 owner); 146 else { 147 printf("Set '%s' persistent and owned by", ifr.ifr_name); 148 if(owner != -1) 149 printf(" uid %d", owner); 150 if(group != -1) 151 printf(" gid %d", group); 152 printf("\n"); 153 } 111 154 } 112 155 return(0);
Note:
See TracChangeset
for help on using the changeset viewer.