~serge-hallyn/ubuntu/quantal/lxc/lxc-aa-custom-profile

« back to all changes in this revision

Viewing changes to src/lxc/lxc-setcap.in

  • Committer: Bazaar Package Importer
  • Author(s): Guido Trotter
  • Date: 2009-04-29 17:49:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090429174913-jvahs1ykizqtodje
Tags: upstream-0.6.2
ImportĀ upstreamĀ versionĀ 0.6.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
 
 
3
#
 
4
# lxc: linux Container library
 
5
 
 
6
# Authors:
 
7
# Daniel Lezcano <daniel.lezcano@free.fr>
 
8
 
 
9
# This library is free software; you can redistribute it and/or
 
10
# modify it under the terms of the GNU Lesser General Public
 
11
# License as published by the Free Software Foundation; either
 
12
# version 2.1 of the License, or (at your option) any later version.
 
13
 
 
14
# This library is distributed in the hope that it will be useful,
 
15
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
17
# Lesser General Public License for more details.
 
18
 
 
19
# You should have received a copy of the GNU Lesser General Public
 
20
# License along with this library; if not, write to the Free Software
 
21
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
22
 
 
23
#
 
24
# This script allows to set or remove the capabilities on the lxc tools.
 
25
# When the capabilities are set, a non root user can manage the containers.
 
26
#
 
27
 
 
28
LXC_CREATE_CAPS="cap_sys_admin"
 
29
LXC_NETSTAT_CAPS="cap_sys_admin"
 
30
LXC_INIT_CAPS="cap_sys_admin"
 
31
LXC_UNSHARE_CAPS="cap_net_admin,cap_net_raw,cap_sys_admin,cap_dac_override"
 
32
LXC_START_CAPS="cap_sys_chroot,cap_setpcap,cap_net_admin,cap_net_raw,cap_sys_admin,cap_dac_override"
 
33
LXC_EXECUTE_CAPS=$LXC_START_CAPS
 
34
LXC_RESTART_CAPS=$LXC_START_CAPS
 
35
 
 
36
LXC_DROP_CAPS=""
 
37
 
 
38
usage()
 
39
{
 
40
    echo "lxc-setcap [-d] : set or remove capabilities on the lxc tools"
 
41
}
 
42
 
 
43
lxc_setcaps()
 
44
{
 
45
    setcap $LXC_CREATE_CAPS=ep @BINDIR@/lxc-create
 
46
    setcap $LXC_EXECUTE_CAPS=ep @BINDIR@/lxc-execute
 
47
    setcap $LXC_START_CAPS=ep @BINDIR@/lxc-start
 
48
    setcap $LXC_RESTART_CAPS=ep @BINDIR@/lxc-restart
 
49
    setcap $LXC_UNSHARE_CAPS=ep @BINDIR@/lxc-unshare
 
50
    setcap $LXC_NETSTAT_CAPS=ep @BINDIR@/lxc-netstat
 
51
    setcap $LXC_INIT_CAPS=ep @LIBEXECDIR@/lxc-init
 
52
    chmod 2777 @LXCPATH@
 
53
}
 
54
 
 
55
lxc_dropcaps()
 
56
{
 
57
    setcap -r @BINDIR@/lxc-create
 
58
    setcap -r @BINDIR@/lxc-execute
 
59
    setcap -r @BINDIR@/lxc-start
 
60
    setcap -r @BINDIR@/lxc-restart
 
61
    setcap -r @BINDIR@/lxc-unshare
 
62
    setcap -r @BINDIR@/lxc-netstat
 
63
    setcap -r @LIBEXECDIR@/lxc-init
 
64
    chmod 0755 @LXCPATH@
 
65
}
 
66
 
 
67
if [ "$(id -u)" != "0" ]; then
 
68
    echo "You have to be root to run this script"
 
69
    exit 1
 
70
fi
 
71
 
 
72
 
 
73
if [ $? != 0 ]; then
 
74
    usage
 
75
    exit 1
 
76
fi
 
77
 
 
78
set -- $(getopt dh $*)
 
79
 
 
80
for i in $*; do
 
81
    case "$1" in
 
82
        -d)
 
83
            LXC_DROP_CAPS="yes"
 
84
            shift
 
85
            ;;
 
86
        -h)
 
87
            usage
 
88
            exit 0
 
89
            ;;
 
90
        --)
 
91
            shift
 
92
            break
 
93
            ;;
 
94
        *)
 
95
            usage
 
96
            exit 1
 
97
            ;;
 
98
    esac
 
99
done;
 
100
 
 
101
if [ -z "$LXC_DROP_CAPS" ]; then
 
102
    lxc_setcaps
 
103
else
 
104
    lxc_dropcaps
 
105
fi