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
fad08f38
Unverified
Commit
fad08f38
authored
Apr 09, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: make id switching functions return bool
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
be905724
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
26 deletions
+31
-26
start.c
src/lxc/start.c
+5
-8
utils.c
src/lxc/utils.c
+24
-16
utils.h
src/lxc/utils.h
+2
-2
No files found.
src/lxc/start.c
View file @
fad08f38
...
...
@@ -1146,15 +1146,13 @@ static int do_start(void *data)
?
0
:
handler
->
conf
->
init_gid
;
ret
=
lxc_switch_uid_gid
(
nsuid
,
nsgid
);
if
(
ret
<
0
)
if
(
!
lxc_switch_uid_gid
(
nsuid
,
nsgid
))
goto
out_warn_father
;
/* Drop groups only after we switched to a valid gid in the new
* user namespace.
*/
ret
=
lxc_setgroups
(
0
,
NULL
);
if
(
ret
<
0
&&
(
handler
->
am_root
||
errno
!=
EPERM
))
if
(
!
lxc_setgroups
(
0
,
NULL
)
&&
(
handler
->
am_root
||
errno
!=
EPERM
))
goto
out_warn_father
;
ret
=
prctl
(
PR_SET_DUMPABLE
,
1
,
0
,
0
,
0
);
...
...
@@ -1349,12 +1347,11 @@ static int do_start(void *data)
#else
have_cap_setgid
=
false
;
#endif
if
(
lxc_list_empty
(
&
handler
->
conf
->
id_map
)
&&
have_cap_setgid
)
{
if
(
lxc_setgroups
(
0
,
NULL
)
<
0
)
if
(
lxc_list_empty
(
&
handler
->
conf
->
id_map
)
&&
have_cap_setgid
)
if
(
!
lxc_setgroups
(
0
,
NULL
)
)
goto
out_warn_father
;
}
if
(
lxc_switch_uid_gid
(
new_uid
,
new_gid
)
<
0
)
if
(
!
lxc_switch_uid_gid
(
new_uid
,
new_gid
)
)
goto
out_warn_father
;
ret
=
lxc_ambient_caps_down
();
...
...
src/lxc/utils.c
View file @
fad08f38
...
...
@@ -2059,33 +2059,41 @@ int lxc_safe_long_long(const char *numstr, long long int *converted)
return
0
;
}
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
)
bool
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
)
{
if
(
setgid
(
gid
)
<
0
)
{
SYSERROR
(
"Failed to switch to gid %d."
,
gid
);
return
-
errno
;
int
ret
=
0
;
if
(
gid
!=
LXC_INVALID_GID
)
{
ret
=
setgid
(
gid
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to gid %d"
,
gid
);
return
false
;
}
NOTICE
(
"Switched to gid %d"
,
gid
);
}
NOTICE
(
"Switched to gid %d."
,
gid
);
if
(
setuid
(
uid
)
<
0
)
{
SYSERROR
(
"Failed to switch to uid %d."
,
uid
);
return
-
errno
;
if
(
uid
!=
LXC_INVALID_UID
)
{
ret
=
setuid
(
uid
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to uid %d"
,
uid
);
return
false
;
}
NOTICE
(
"Switched to uid %d"
,
uid
);
}
NOTICE
(
"Switched to uid %d."
,
uid
);
return
0
;
return
true
;
}
/* Simple covenience function which enables uniform logging. */
int
lxc_setgroups
(
int
size
,
gid_t
list
[])
/* Simple co
n
venience function which enables uniform logging. */
bool
lxc_setgroups
(
int
size
,
gid_t
list
[])
{
if
(
setgroups
(
size
,
list
)
<
0
)
{
SYSERROR
(
"Failed to setgroups()
.
"
);
return
-
errno
;
SYSERROR
(
"Failed to setgroups()"
);
return
false
;
}
NOTICE
(
"Dropped additional groups
.
"
);
NOTICE
(
"Dropped additional groups"
);
return
0
;
return
true
;
}
static
int
lxc_get_unused_loop_dev_legacy
(
char
*
loop_name
)
...
...
src/lxc/utils.h
View file @
fad08f38
...
...
@@ -455,8 +455,8 @@ extern int lxc_safe_uint64(const char *numstr, uint64_t *converted, int base);
extern
int
parse_byte_size_string
(
const
char
*
s
,
int64_t
*
converted
);
/* Switch to a new uid and gid. */
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
);
int
lxc_setgroups
(
int
size
,
gid_t
list
[]);
bool
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
);
bool
lxc_setgroups
(
int
size
,
gid_t
list
[]);
/* Find an unused loop device and associate it with source. */
int
lxc_prepare_loop_dev
(
const
char
*
source
,
char
*
loop_dev
,
int
flags
);
...
...
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