3 // Copyright (C) 2003 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
4 // based on reducecap.cc by Jacques Gelinas
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2, or (at your option)
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
31 #include "linuxcaps.h"
34 extern int capget (struct __user_cap_header_struct *, struct __user_cap_data_struct *);
35 extern int capset (struct __user_cap_header_struct *, struct __user_cap_data_struct *);
39 fprintf (stderr,"reducecap version %s\n",VERSION);
40 fprintf (stderr,"reducecap [ options ] command argument\n");
44 static void reducecap_print(struct __user_cap_data_struct *user)
46 static const char *tb[]={
49 "CAP_DAC_READ_SEARCH",
56 "CAP_LINUX_IMMUTABLE",
57 "CAP_NET_BIND_SERVICE",
80 printf ("%22s %9s %9s %9s\n","Capability","Effective","Permitted"
82 for (i=0; tb[i] != NULL; i++){
84 printf ("%22s %9s %9s %9s\n"
86 ,(user->effective & bit) ? "X " : " "
87 ,(user->permitted & bit) ? "X " : " "
88 ,(user->inheritable & bit) ? "X " : " ");
92 static void reducecap_show()
94 struct __user_cap_header_struct header;
95 struct __user_cap_data_struct user;
96 header.version = _LINUX_CAPABILITY_VERSION;
97 header.pid = getpid();
98 if (capget(&header,&user)==-1){
101 reducecap_print (&user);
107 int main (int argc, char *argv[])
110 unsigned long remove = 0;
113 unsigned long secure = (1<<CAP_LINUX_IMMUTABLE)
114 |(1<<CAP_NET_BROADCAST)
125 |(1<<CAP_SYS_RESOURCE)
129 for (i=1; i<argc; i++){
130 const char *arg = argv[i];
131 const char *opt = argv[i+1];
132 if (strcmp(arg,"--secure")==0){
134 }else if (strcmp(arg,"--show")==0){
136 }else if (strcmp(arg,"--flag")==0){
137 if (strcmp(opt,"lock")==0){
139 }else if (strcmp(opt,"sched")==0){
141 }else if (strcmp(opt,"nproc")==0){
143 }else if (strcmp(opt,"private")==0){
145 }else if (strcmp(opt,"hideinfo")==0){
148 fprintf (stderr,"Unknown flag %s\n",opt);
151 }else if (arg[0] == '-' && arg[1] == '-'){
156 // The following capabilities are normally available
157 // to vservers administrator, but are place for
159 {"CAP_CHOWN",CAP_CHOWN},
160 {"CAP_DAC_OVERRIDE",CAP_DAC_OVERRIDE},
161 {"CAP_DAC_READ_SEARCH",CAP_DAC_READ_SEARCH},
162 {"CAP_FOWNER",CAP_FOWNER},
163 {"CAP_FSETID",CAP_FSETID},
164 {"CAP_KILL",CAP_KILL},
165 {"CAP_SETGID",CAP_SETGID},
166 {"CAP_SETUID",CAP_SETUID},
167 {"CAP_SETPCAP",CAP_SETPCAP},
168 {"CAP_SYS_TTY_CONFIG",CAP_SYS_TTY_CONFIG},
169 {"CAP_LEASE",CAP_LEASE},
170 {"CAP_SYS_CHROOT",CAP_SYS_CHROOT},
172 // Those capabilities are not normally available
173 // to vservers because they are not needed and
174 // may represent a security risk
175 {"--LINUX_IMMUTABLE",CAP_LINUX_IMMUTABLE},
176 {"--NET_BIND_SERVICE",CAP_NET_BIND_SERVICE},
177 {"--NET_BROADCAST",CAP_NET_BROADCAST},
178 {"--NET_ADMIN", CAP_NET_ADMIN},
179 {"--NET_RAW", CAP_NET_RAW},
180 {"--IPC_LOCK", CAP_IPC_LOCK},
181 {"--IPC_OWNER", CAP_IPC_OWNER},
182 {"--SYS_MODULE",CAP_SYS_MODULE},
183 {"--SYS_RAWIO", CAP_SYS_RAWIO},
184 {"--SYS_PACCT", CAP_SYS_PACCT},
185 {"--SYS_ADMIN", CAP_SYS_ADMIN},
186 {"--SYS_BOOT", CAP_SYS_BOOT},
187 {"--SYS_NICE", CAP_SYS_NICE},
188 {"--SYS_RESOURCE",CAP_SYS_RESOURCE},
189 {"--SYS_TIME", CAP_SYS_TIME},
190 {"--MKNOD", CAP_MKNOD},
194 for (j=0; tbcap[j].option != NULL; j++){
195 if (strcasecmp(tbcap[j].option,arg)==0){
196 remove |= (1<<tbcap[j].bit);
200 if (tbcap[j].option != NULL){
213 }else if (argv[i][0] == '-'){
216 struct __user_cap_header_struct header;
217 struct __user_cap_data_struct user;
218 header.version = _LINUX_CAPABILITY_VERSION;
220 if (capget(&header,&user)==-1){
224 reducecap_print (&user);
226 if (vc_new_s_context(-2,remove,flags)==-1){
227 perror ("new_s_context -2");
229 fprintf (stderr,"Executing\n");
230 execvp (argv[i],argv+i);
231 fprintf (stderr,"Can't execute command %s\n",argv[i]);