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
464c4611
Unverified
Commit
464c4611
authored
Sep 09, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: make lxc_switch_uid_gid() return bool
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
8af07f82
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
12 additions
and
19 deletions
+12
-19
attach.c
src/lxc/attach.c
+2
-4
lxc_usernsexec.c
src/lxc/cmd/lxc_usernsexec.c
+1
-2
start.c
src/lxc/start.c
+2
-4
rsync.c
src/lxc/storage/rsync.c
+2
-4
utils.c
src/lxc/utils.c
+4
-4
utils.h
src/lxc/utils.h
+1
-1
No files found.
src/lxc/attach.c
View file @
464c4611
...
@@ -854,8 +854,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -854,8 +854,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
if
(
ns_root_uid
==
LXC_INVALID_UID
)
if
(
ns_root_uid
==
LXC_INVALID_UID
)
goto
on_error
;
goto
on_error
;
ret
=
lxc_switch_uid_gid
(
ns_root_uid
,
ns_root_gid
);
if
(
!
lxc_switch_uid_gid
(
ns_root_uid
,
ns_root_gid
))
if
(
ret
<
0
)
goto
on_error
;
goto
on_error
;
}
}
...
@@ -969,8 +968,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
...
@@ -969,8 +968,7 @@ static int attach_child_main(struct attach_clone_payload *payload)
if
(
new_gid
==
ns_root_gid
)
if
(
new_gid
==
ns_root_gid
)
new_gid
=
LXC_INVALID_GID
;
new_gid
=
LXC_INVALID_GID
;
ret
=
lxc_switch_uid_gid
(
new_uid
,
new_gid
);
if
(
!
lxc_switch_uid_gid
(
new_uid
,
new_gid
))
if
(
ret
<
0
)
goto
on_error
;
goto
on_error
;
/* We're done, so we can now do whatever the user intended us to do. */
/* We're done, so we can now do whatever the user intended us to do. */
...
...
src/lxc/cmd/lxc_usernsexec.c
View file @
464c4611
...
@@ -104,8 +104,7 @@ static int do_child(void *vargv)
...
@@ -104,8 +104,7 @@ static int do_child(void *vargv)
char
**
argv
=
(
char
**
)
vargv
;
char
**
argv
=
(
char
**
)
vargv
;
/* Assume we want to become root */
/* Assume we want to become root */
ret
=
lxc_switch_uid_gid
(
0
,
0
);
if
(
!
lxc_switch_uid_gid
(
0
,
0
))
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
if
(
!
lxc_setgroups
(
0
,
NULL
))
if
(
!
lxc_setgroups
(
0
,
NULL
))
...
...
src/lxc/start.c
View file @
464c4611
...
@@ -1124,8 +1124,7 @@ static int do_start(void *data)
...
@@ -1124,8 +1124,7 @@ static int do_start(void *data)
if
(
!
handler
->
conf
->
root_nsgid_map
)
if
(
!
handler
->
conf
->
root_nsgid_map
)
nsgid
=
handler
->
conf
->
init_gid
;
nsgid
=
handler
->
conf
->
init_gid
;
ret
=
lxc_switch_uid_gid
(
nsuid
,
nsgid
);
if
(
!
lxc_switch_uid_gid
(
nsuid
,
nsgid
))
if
(
ret
<
0
)
goto
out_warn_father
;
goto
out_warn_father
;
/* Drop groups only after we switched to a valid gid in the new
/* Drop groups only after we switched to a valid gid in the new
...
@@ -1362,8 +1361,7 @@ static int do_start(void *data)
...
@@ -1362,8 +1361,7 @@ static int do_start(void *data)
if
(
new_gid
==
nsgid
)
if
(
new_gid
==
nsgid
)
new_gid
=
LXC_INVALID_GID
;
new_gid
=
LXC_INVALID_GID
;
ret
=
lxc_switch_uid_gid
(
new_uid
,
new_gid
);
if
(
!
lxc_switch_uid_gid
(
new_uid
,
new_gid
))
if
(
ret
<
0
)
goto
out_warn_father
;
goto
out_warn_father
;
/* If we are in a new user namespace we already dropped all groups when
/* If we are in a new user namespace we already dropped all groups when
...
...
src/lxc/storage/rsync.c
View file @
464c4611
...
@@ -50,8 +50,7 @@ int lxc_rsync_exec_wrapper(void *data)
...
@@ -50,8 +50,7 @@ int lxc_rsync_exec_wrapper(void *data)
int
ret
;
int
ret
;
struct
rsync_data_char
*
args
=
data
;
struct
rsync_data_char
*
args
=
data
;
ret
=
lxc_switch_uid_gid
(
0
,
0
);
if
(
!
lxc_switch_uid_gid
(
0
,
0
))
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
if
(
!
lxc_setgroups
(
0
,
NULL
))
if
(
!
lxc_setgroups
(
0
,
NULL
))
...
@@ -116,8 +115,7 @@ int lxc_rsync(struct rsync_data *data)
...
@@ -116,8 +115,7 @@ int lxc_rsync(struct rsync_data *data)
return
-
1
;
return
-
1
;
}
}
ret
=
lxc_switch_uid_gid
(
0
,
0
);
if
(
!
lxc_switch_uid_gid
(
0
,
0
))
if
(
ret
<
0
)
return
-
1
;
return
-
1
;
if
(
!
lxc_setgroups
(
0
,
NULL
))
if
(
!
lxc_setgroups
(
0
,
NULL
))
...
...
src/lxc/utils.c
View file @
464c4611
...
@@ -1351,7 +1351,7 @@ int lxc_preserve_ns(const int pid, const char *ns)
...
@@ -1351,7 +1351,7 @@ int lxc_preserve_ns(const int pid, const char *ns)
return
open
(
path
,
O_RDONLY
|
O_CLOEXEC
);
return
open
(
path
,
O_RDONLY
|
O_CLOEXEC
);
}
}
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
)
bool
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
)
{
{
int
ret
=
0
;
int
ret
=
0
;
...
@@ -1359,7 +1359,7 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
...
@@ -1359,7 +1359,7 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
ret
=
setgid
(
gid
);
ret
=
setgid
(
gid
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to gid %d"
,
gid
);
SYSERROR
(
"Failed to switch to gid %d"
,
gid
);
return
-
1
;
return
false
;
}
}
NOTICE
(
"Switched to gid %d"
,
gid
);
NOTICE
(
"Switched to gid %d"
,
gid
);
}
}
...
@@ -1368,12 +1368,12 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
...
@@ -1368,12 +1368,12 @@ int lxc_switch_uid_gid(uid_t uid, gid_t gid)
ret
=
setuid
(
uid
);
ret
=
setuid
(
uid
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to uid %d"
,
uid
);
SYSERROR
(
"Failed to switch to uid %d"
,
uid
);
return
-
1
;
return
false
;
}
}
NOTICE
(
"Switched to uid %d"
,
uid
);
NOTICE
(
"Switched to uid %d"
,
uid
);
}
}
return
ret
;
return
true
;
}
}
/* Simple covenience function which enables uniform logging. */
/* Simple covenience function which enables uniform logging. */
...
...
src/lxc/utils.h
View file @
464c4611
...
@@ -361,7 +361,7 @@ extern bool task_blocks_signal(pid_t pid, int signal);
...
@@ -361,7 +361,7 @@ extern bool task_blocks_signal(pid_t pid, int signal);
/* Switch to a new uid and gid.
/* Switch to a new uid and gid.
* If LXC_INVALID_{G,U}ID is passed then the set{g,u}id() will not be called.
* If LXC_INVALID_{G,U}ID is passed then the set{g,u}id() will not be called.
*/
*/
extern
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
);
extern
bool
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
);
extern
bool
lxc_setgroups
(
int
size
,
gid_t
list
[]);
extern
bool
lxc_setgroups
(
int
size
,
gid_t
list
[]);
/* Find an unused loop device and associate it with source. */
/* Find an unused loop device and associate it with source. */
...
...
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