Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
ca364dc0
Unverified
Commit
ca364dc0
authored
Jan 07, 2017
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
caps: add lxc_cap_is_set()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
d08f8d2f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
5 deletions
+41
-5
caps.c
src/lxc/caps.c
+29
-5
caps.h
src/lxc/caps.h
+12
-0
No files found.
src/lxc/caps.c
View file @
ca364dc0
...
@@ -22,20 +22,21 @@
...
@@ -22,20 +22,21 @@
*/
*/
#define _GNU_SOURCE
#define _GNU_SOURCE
#include <unistd.h>
#include "config.h"
#include <errno.h>
#include <limits.h>
#include <fcntl.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdlib.h>
#include <
limits
.h>
#include <
unistd
.h>
#include <sys/prctl.h>
#include <sys/prctl.h>
#include <errno.h>
#include "c
onfig
.h"
#include "c
aps
.h"
#include "log.h"
#include "log.h"
lxc_log_define
(
lxc_caps
,
lxc
);
lxc_log_define
(
lxc_caps
,
lxc
);
#if HAVE_SYS_CAPABILITY_H
#if HAVE_SYS_CAPABILITY_H
#include <sys/capability.h>
#ifndef PR_CAPBSET_READ
#ifndef PR_CAPBSET_READ
#define PR_CAPBSET_READ 23
#define PR_CAPBSET_READ 23
...
@@ -208,4 +209,27 @@ int lxc_caps_last_cap(void)
...
@@ -208,4 +209,27 @@ int lxc_caps_last_cap(void)
return
last_cap
;
return
last_cap
;
}
}
bool
lxc_cap_is_set
(
cap_value_t
cap
,
cap_flag_t
flag
)
{
int
ret
;
cap_t
caps
;
cap_flag_value_t
flagval
;
caps
=
cap_get_proc
();
if
(
!
caps
)
{
ERROR
(
"Failed to perform cap_get_proc(): %s."
,
strerror
(
errno
));
return
false
;
}
ret
=
cap_get_flag
(
caps
,
cap
,
flag
,
&
flagval
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to perform cap_get_flag(): %s."
,
strerror
(
errno
));
cap_free
(
caps
);
return
false
;
}
cap_free
(
caps
);
return
flagval
==
CAP_SET
;
}
#endif
#endif
src/lxc/caps.h
View file @
ca364dc0
...
@@ -20,17 +20,23 @@
...
@@ -20,17 +20,23 @@
* License along with this library; if not, write to the Free Software
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
*/
#include "config.h"
#include "config.h"
#include <stdbool.h>
#ifndef __LXC_CAPS_H
#ifndef __LXC_CAPS_H
#define __LXC_CAPS_H
#define __LXC_CAPS_H
#if HAVE_SYS_CAPABILITY_H
#if HAVE_SYS_CAPABILITY_H
#include <sys/capability.h>
extern
int
lxc_caps_down
(
void
);
extern
int
lxc_caps_down
(
void
);
extern
int
lxc_caps_up
(
void
);
extern
int
lxc_caps_up
(
void
);
extern
int
lxc_caps_init
(
void
);
extern
int
lxc_caps_init
(
void
);
extern
int
lxc_caps_last_cap
(
void
);
extern
int
lxc_caps_last_cap
(
void
);
extern
bool
lxc_cap_is_set
(
cap_value_t
cap
,
cap_flag_t
flag
);
#else
#else
static
inline
int
lxc_caps_down
(
void
)
{
static
inline
int
lxc_caps_down
(
void
)
{
return
0
;
return
0
;
...
@@ -45,6 +51,12 @@ static inline int lxc_caps_init(void) {
...
@@ -45,6 +51,12 @@ static inline int lxc_caps_init(void) {
static
inline
int
lxc_caps_last_cap
(
void
)
{
static
inline
int
lxc_caps_last_cap
(
void
)
{
return
0
;
return
0
;
}
}
typedef
int
cap_value_t
;
typedef
int
cap_flag_t
;
static
inline
bool
lxc_cap_is_set
(
cap_value_t
cap
,
cap_flag_t
flag
)
{
return
true
;
}
#endif
#endif
#define lxc_priv(__lxc_function) \
#define lxc_priv(__lxc_function) \
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment