]>
Commit | Line | Data |
---|---|---|
1 | /* | |
2 | * lxc: linux Container library | |
3 | * | |
4 | * (C) Copyright IBM Corp. 2007, 2008 | |
5 | * | |
6 | * Authors: | |
7 | * Daniel Lezcano <dlezcano at fr.ibm.com> | |
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 | #include "config.h" | |
24 | ||
25 | #ifndef _caps_h | |
26 | #define _caps_h | |
27 | ||
28 | #if HAVE_SYS_CAPABILITY_H | |
29 | extern int lxc_caps_reset(void); | |
30 | extern int lxc_caps_down(void); | |
31 | extern int lxc_caps_up(void); | |
32 | extern int lxc_caps_init(void); | |
33 | extern int lxc_caps_check(void); | |
34 | ||
35 | extern int lxc_caps_last_cap(void); | |
36 | #else | |
37 | static inline int lxc_caps_reset(void) { | |
38 | return 0; | |
39 | } | |
40 | static inline int lxc_caps_down(void) { | |
41 | return 0; | |
42 | } | |
43 | static inline int lxc_caps_up(void) { | |
44 | return 0; | |
45 | } | |
46 | static inline int lxc_caps_init(void) { | |
47 | return 0; | |
48 | } | |
49 | static inline int lxc_caps_check(void) { | |
50 | return 1; | |
51 | } | |
52 | ||
53 | static inline int lxc_caps_last_cap(void) { | |
54 | return 0; | |
55 | } | |
56 | #endif | |
57 | ||
58 | #define lxc_priv(__lxc_function) \ | |
59 | ({ \ | |
60 | __label__ out; \ | |
61 | int __ret, __ret2, ___errno = 0; \ | |
62 | __ret = lxc_caps_up(); \ | |
63 | if (__ret) \ | |
64 | goto out; \ | |
65 | __ret = __lxc_function; \ | |
66 | if (__ret) \ | |
67 | ___errno = errno; \ | |
68 | __ret2 = lxc_caps_down(); \ | |
69 | out: __ret ? errno = ___errno,__ret : __ret2; \ | |
70 | }) | |
71 | ||
72 | #define lxc_unpriv(__lxc_function) \ | |
73 | ({ \ | |
74 | __label__ out; \ | |
75 | int __ret, __ret2, ___errno = 0; \ | |
76 | __ret = lxc_caps_down(); \ | |
77 | if (__ret) \ | |
78 | goto out; \ | |
79 | __ret = __lxc_function; \ | |
80 | if (__ret) \ | |
81 | ___errno = errno; \ | |
82 | __ret2 = lxc_caps_up(); \ | |
83 | out: __ret ? errno = ___errno,__ret : __ret2; \ | |
84 | }) | |
85 | #endif |