From 397e79b66f7078c81aba8500011121aa49070cfe Mon Sep 17 00:00:00 2001 From: Enrico Scholz Date: Mon, 20 Oct 2003 21:28:51 +0000 Subject: [PATCH] initial checkin git-svn-id: http://svn.linux-vserver.org/svn/util-vserver/trunk@240 94cd875c-1c1d-0410-91d2-eb244daf1a30 --- util-vserver/lib/capabilities.c | 87 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 util-vserver/lib/capabilities.c diff --git a/util-vserver/lib/capabilities.c b/util-vserver/lib/capabilities.c new file mode 100644 index 0000000..ad1b4f9 --- /dev/null +++ b/util-vserver/lib/capabilities.c @@ -0,0 +1,87 @@ +// $Id$ --*- c -*-- + +// Copyright (C) 2003 Enrico Scholz +// +// 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; version 2 of the License. +// +// 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 "vserver.h" +#include + +#if 1 +# define DECLARECAP(X,Y) { #X, VC_##X } +#else +# define DECLARECAP(X,Y) { #X, Y } +#endif + +static struct { + char const * const id; + unsigned char bit; +} const CAP2BIT[] = { + DECLARECAP(CAP_CHOWN, 0), + DECLARECAP(CAP_DAC_OVERRIDE, 1), + DECLARECAP(CAP_DAC_READ_SEARCH, 2), + DECLARECAP(CAP_FOWNER, 3), + DECLARECAP(CAP_FSETID, 4), + DECLARECAP(CAP_KILL, 5), + DECLARECAP(CAP_SETGID, 6), + DECLARECAP(CAP_SETUID, 7), + DECLARECAP(CAP_SETPCAP, 8), + DECLARECAP(CAP_LINUX_IMMUTABLE, 9), + DECLARECAP(CAP_NET_BIND_SERVICE, 10), + DECLARECAP(CAP_NET_BROADCAST, 11), + DECLARECAP(CAP_NET_ADMIN, 12), + DECLARECAP(CAP_NET_RAW, 13), + DECLARECAP(CAP_IPC_LOCK, 14), + DECLARECAP(CAP_IPC_OWNER, 15), + DECLARECAP(CAP_SYS_MODULE, 16), + DECLARECAP(CAP_SYS_RAWIO, 17), + DECLARECAP(CAP_SYS_CHROOT, 18), + DECLARECAP(CAP_SYS_PTRACE, 19), + DECLARECAP(CAP_SYS_PACCT, 20), + DECLARECAP(CAP_SYS_ADMIN, 21), + DECLARECAP(CAP_SYS_BOOT, 22), + DECLARECAP(CAP_SYS_NICE, 23), + DECLARECAP(CAP_SYS_RESOURCE, 24), + DECLARECAP(CAP_SYS_TIME, 25), + DECLARECAP(CAP_SYS_TTY_CONFIG, 26), + DECLARECAP(CAP_MKNOD, 27), + DECLARECAP(CAP_LEASE, 28), + DECLARECAP(CAP_OPENDEV, 29), +}; + +int +vc_text2cap(char const *str) +{ + size_t i; + if (strncmp(str, "CAP_", 4)!=0) return -1; + str += 4; + + for (i=0; i=sizeof(CAP2BIT)/sizeof(CAP2BIT[0])) return 0; + return CAP2BIT[bit].id; +} -- 1.8.1.5