// $Id: reducecap.c,v 1.1.4.4 2004/03/05 04:59:36 ensc Exp $ // Copyright (C) 2003 Enrico Scholz // based on reducecap.cc by Jacques Gelinas // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef HAVE_CONFIG_H # include #endif #include "compat.h" #include #include #include #include #include #include #include "linuxcaps.h" #include "vserver.h" #ifndef CAP_QUOTACTL # define CAP_QUOTACTL 29 #endif extern int capget (struct __user_cap_header_struct *, struct __user_cap_data_struct *); extern int capset (struct __user_cap_header_struct *, struct __user_cap_data_struct *); static void usage() { fprintf (stderr,"reducecap version %s\n",VERSION); fprintf (stderr,"reducecap [ options ] command argument\n"); exit (-1); } static void reducecap_print(struct __user_cap_data_struct *user) { static const char *tb[]={ "CAP_CHOWN", "CAP_DAC_OVERRIDE", "CAP_DAC_READ_SEARCH", "CAP_FOWNER", "CAP_FSETID", "CAP_KILL", "CAP_SETGID", "CAP_SETUID", "CAP_SETPCAP", "CAP_LINUX_IMMUTABLE", "CAP_NET_BIND_SERVICE", "CAP_NET_BROADCAST", "CAP_NET_ADMIN", "CAP_NET_RAW", "CAP_IPC_LOCK", "CAP_IPC_OWNER", "CAP_SYS_MODULE", "CAP_SYS_RAWIO", "CAP_SYS_CHROOT", "CAP_SYS_PTRACE", "CAP_SYS_PACCT", "CAP_SYS_ADMIN", "CAP_SYS_BOOT", "CAP_SYS_NICE", "CAP_SYS_RESOURCE", "CAP_SYS_TIME", "CAP_SYS_TTY_CONFIG", "CAP_MKNOD", "CAP_LEASE", "CAP_QUOTACTL", NULL }; int i; printf ("%22s %9s %9s %9s\n","Capability","Effective","Permitted" ,"Inheritable"); for (i=0; tb[i] != NULL; i++){ int bit = (1 << i); printf ("%22s %9s %9s %9s\n" ,tb[i] ,(user->effective & bit) ? "X " : " " ,(user->permitted & bit) ? "X " : " " ,(user->inheritable & bit) ? "X " : " "); } } static void reducecap_show() { struct __user_cap_header_struct header; struct __user_cap_data_struct user; header.version = _LINUX_CAPABILITY_VERSION; header.pid = getpid(); if (capget(&header,&user)==-1){ perror ("capget"); }else{ reducecap_print (&user); } } int main (int argc, char *argv[]) { int ret = -1; unsigned long remove = 0; int show = 0; int flags = 0; unsigned long secure = (1<