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
4a2ca8b2
Commit
4a2ca8b2
authored
Feb 02, 2012
by
Serge Hallyn
Committed by
Daniel Lezcano
Feb 26, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
lxc-start: exit early and cleanly if we have insufficient privs
Signed-off-by:
Serge Hallyn
<
serge.hallyn@canonical.com
>
Signed-off-by:
Daniel Lezcano
<
dlezcano@fr.ibm.com
>
parent
341a9bd8
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
0 deletions
+47
-0
caps.c
src/lxc/caps.c
+39
-0
caps.h
src/lxc/caps.h
+1
-0
start.c
src/lxc/start.c
+7
-0
No files found.
src/lxc/caps.c
View file @
4a2ca8b2
...
@@ -213,3 +213,42 @@ int lxc_caps_last_cap(void)
...
@@ -213,3 +213,42 @@ int lxc_caps_last_cap(void)
return
last_cap
;
return
last_cap
;
}
}
/*
* check if we have the caps needed to start a container. returns 1 on
* success, 0 on error. (I'd prefer this be a bool, but am afraid that
* might fail to build on some distros).
*/
int
lxc_caps_check
(
void
)
{
uid_t
uid
=
getuid
();
cap_t
caps
;
cap_flag_value_t
value
;
int
i
,
ret
;
cap_value_t
needed_caps
[]
=
{
CAP_SYS_ADMIN
,
CAP_NET_ADMIN
,
CAP_SETUID
,
CAP_SETGID
};
#define NUMCAPS ((int) (sizeof(needed_caps) / sizeof(cap_t)))
if
(
!
uid
)
return
1
;
caps
=
cap_get_proc
();
if
(
!
caps
)
{
ERROR
(
"failed to cap_get_proc: %m"
);
return
0
;
}
for
(
i
=
0
;
i
<
NUMCAPS
;
i
++
)
{
ret
=
cap_get_flag
(
caps
,
needed_caps
[
i
],
CAP_EFFECTIVE
,
&
value
);
if
(
ret
)
{
ERROR
(
"Failed to cap_get_flag: %m"
);
return
0
;
}
if
(
!
value
)
{
return
0
;
}
}
return
1
;
}
src/lxc/caps.h
View file @
4a2ca8b2
...
@@ -27,6 +27,7 @@ extern int lxc_caps_reset(void);
...
@@ -27,6 +27,7 @@ extern int lxc_caps_reset(void);
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_check
(
void
);
extern
int
lxc_caps_last_cap
(
void
);
extern
int
lxc_caps_last_cap
(
void
);
...
...
src/lxc/start.c
View file @
4a2ca8b2
...
@@ -319,10 +319,17 @@ out_sigfd:
...
@@ -319,10 +319,17 @@ out_sigfd:
return
-
1
;
return
-
1
;
}
}
extern
int
lxc_caps_check
(
void
);
struct
lxc_handler
*
lxc_init
(
const
char
*
name
,
struct
lxc_conf
*
conf
)
struct
lxc_handler
*
lxc_init
(
const
char
*
name
,
struct
lxc_conf
*
conf
)
{
{
struct
lxc_handler
*
handler
;
struct
lxc_handler
*
handler
;
if
(
!
lxc_caps_check
())
{
ERROR
(
"Not running with sufficient privilege"
);
return
NULL
;
}
handler
=
malloc
(
sizeof
(
*
handler
));
handler
=
malloc
(
sizeof
(
*
handler
));
if
(
!
handler
)
if
(
!
handler
)
return
NULL
;
return
NULL
;
...
...
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