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
db2d1af1
Unverified
Commit
db2d1af1
authored
Sep 09, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: improve lxc_switch_uid_gid()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
b962868f
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
10 deletions
+20
-10
utils.c
src/lxc/utils.c
+17
-9
utils.h
src/lxc/utils.h
+3
-1
No files found.
src/lxc/utils.c
View file @
db2d1af1
...
@@ -1353,19 +1353,27 @@ int lxc_preserve_ns(const int pid, const char *ns)
...
@@ -1353,19 +1353,27 @@ int lxc_preserve_ns(const int pid, const char *ns)
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
)
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
)
{
{
if
(
setgid
(
gid
)
<
0
)
{
int
ret
=
0
;
SYSERROR
(
"Failed to switch to gid %d."
,
gid
);
return
-
errno
;
if
(
gid
!=
LXC_INVALID_GID
)
{
ret
=
setgid
(
gid
);
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to gid %d"
,
gid
);
return
-
1
;
}
NOTICE
(
"Switched to gid %d"
,
gid
);
}
}
NOTICE
(
"Switched to gid %d."
,
gid
);
if
(
setuid
(
uid
)
<
0
)
{
if
(
uid
!=
LXC_INVALID_UID
)
{
SYSERROR
(
"Failed to switch to uid %d."
,
uid
);
ret
=
setuid
(
uid
);
return
-
errno
;
if
(
ret
<
0
)
{
SYSERROR
(
"Failed to switch to uid %d"
,
uid
);
return
-
1
;
}
NOTICE
(
"Switched to uid %d"
,
uid
);
}
}
NOTICE
(
"Switched to uid %d."
,
uid
);
return
0
;
return
ret
;
}
}
/* Simple covenience function which enables uniform logging. */
/* Simple covenience function which enables uniform logging. */
...
...
src/lxc/utils.h
View file @
db2d1af1
...
@@ -358,7 +358,9 @@ extern int lxc_preserve_ns(const int pid, const char *ns);
...
@@ -358,7 +358,9 @@ extern int lxc_preserve_ns(const int pid, const char *ns);
/* Check whether a signal is blocked by a process. */
/* Check whether a signal is blocked by a process. */
extern
bool
task_blocks_signal
(
pid_t
pid
,
int
signal
);
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.
*/
extern
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
);
extern
int
lxc_switch_uid_gid
(
uid_t
uid
,
gid_t
gid
);
extern
int
lxc_setgroups
(
int
size
,
gid_t
list
[]);
extern
int
lxc_setgroups
(
int
size
,
gid_t
list
[]);
...
...
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