]> git.proxmox.com Git - mirror_lxc.git/blame - src/lxc/caps.h
conf, confile: add parsing of a shmounts config parameter
[mirror_lxc.git] / src / lxc / caps.h
CommitLineData
b3357a6f
DL
1/*
2 * lxc: linux Container library
3 *
4 * (C) Copyright IBM Corp. 2007, 2008
5 *
6 * Authors:
9afe19d6 7 * Daniel Lezcano <daniel.lezcano at free.fr>
b3357a6f
DL
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
250b1eec 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
b3357a6f 22 */
ca364dc0 23
74a99f40
LW
24#ifndef __LXC_CAPS_H
25#define __LXC_CAPS_H
26
495d2046 27#include "config.h"
ca364dc0 28#include <stdbool.h>
495d2046 29
e37dda71 30#if HAVE_LIBCAP
9cd5f7fa 31#include <linux/types.h> /* workaround for libcap < 2.17 bug */
ca364dc0
CB
32#include <sys/capability.h>
33
7d40e69b
DL
34extern int lxc_caps_down(void);
35extern int lxc_caps_up(void);
611ddd34
CB
36extern int lxc_ambient_caps_up(void);
37extern int lxc_ambient_caps_down(void);
7d40e69b 38extern int lxc_caps_init(void);
20d81659 39extern int lxc_caps_last_cap(void);
207c4c71 40extern bool lxc_proc_cap_is_set(cap_value_t cap, cap_flag_t flag);
611ddd34
CB
41extern bool lxc_file_cap_is_set(const char *path, cap_value_t cap,
42 cap_flag_t flag);
495d2046 43#else
611ddd34
CB
44static inline int lxc_caps_down(void)
45{
d028235d 46 return 0;
495d2046 47}
611ddd34
CB
48
49static inline int lxc_caps_up(void)
50{
d028235d 51 return 0;
495d2046 52}
611ddd34
CB
53
54static inline int lxc_ambient_caps_up(void)
55{
56 return 0;
57}
58
59static inline int lxc_ambient_caps_down(void)
60{
61 return 0;
62}
63
64static inline int lxc_caps_init(void)
65{
d028235d 66 return 0;
495d2046 67}
495d2046 68
611ddd34
CB
69static inline int lxc_caps_last_cap(void)
70{
d028235d 71 return 0;
495d2046 72}
ca364dc0
CB
73
74typedef int cap_value_t;
75typedef int cap_flag_t;
611ddd34
CB
76static inline bool lxc_proc_cap_is_set(cap_value_t cap, cap_flag_t flag)
77{
c61079a4 78 return false;
207c4c71
CB
79}
80
611ddd34
CB
81static inline bool lxc_file_cap_is_set(const char *path, cap_value_t cap,
82 cap_flag_t flag)
83{
c61079a4 84 return false;
ca364dc0 85}
495d2046 86#endif
20d81659 87
611ddd34
CB
88#define lxc_priv(__lxc_function) \
89 ({ \
90 __label__ out; \
91 int __ret, __ret2, ___errno = 0; \
92 __ret = lxc_caps_up(); \
93 if (__ret) \
94 goto out; \
95 __ret = __lxc_function; \
96 if (__ret) \
97 ___errno = errno; \
98 __ret2 = lxc_caps_down(); \
99 out: \
100 __ret ? errno = ___errno, __ret : __ret2; \
7d40e69b
DL
101 })
102
611ddd34
CB
103#define lxc_unpriv(__lxc_function) \
104 ({ \
105 __label__ out; \
106 int __ret, __ret2, ___errno = 0; \
107 __ret = lxc_caps_down(); \
108 if (__ret) \
109 goto out; \
110 __ret = __lxc_function; \
111 if (__ret) \
112 ___errno = errno; \
113 __ret2 = lxc_caps_up(); \
114 out: \
115 __ret ? errno = ___errno, __ret : __ret2; \
7d40e69b 116 })
b3357a6f 117#endif