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
b962868f
Unverified
Commit
b962868f
authored
Sep 09, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
utils: improve get_ns_uid() and add get_ns_gid()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
0b26d75e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
37 additions
and
1 deletion
+37
-1
cgfsng.c
src/lxc/cgroups/cgfsng.c
+2
-0
macro.h
src/lxc/macro.h
+3
-0
utils.c
src/lxc/utils.c
+28
-1
utils.h
src/lxc/utils.h
+4
-0
No files found.
src/lxc/cgroups/cgfsng.c
View file @
b962868f
...
...
@@ -1388,6 +1388,8 @@ static int chown_cgroup_wrapper(void *data)
}
destuid
=
get_ns_uid
(
arg
->
origuid
);
if
(
destuid
==
LXC_INVALID_UID
)
destuid
=
0
;
for
(
i
=
0
;
arg
->
hierarchies
[
i
];
i
++
)
{
char
*
fullpath
;
...
...
src/lxc/macro.h
View file @
b962868f
...
...
@@ -340,4 +340,7 @@ extern int __build_bug_on_failed;
#define PTR_TO_INTMAX(p) ((intmax_t)((intptr_t)(p)))
#define INTMAX_TO_PTR(u) ((void *)((intptr_t)(u)))
#define LXC_INVALID_UID ((uid_t)-1)
#define LXC_INVALID_GID ((gid_t)-1)
#endif
/* __LXC_MACRO_H */
src/lxc/utils.c
View file @
b962868f
...
...
@@ -544,7 +544,34 @@ uid_t get_ns_uid(uid_t orig)
}
}
nsid
=
0
;
nsid
=
LXC_INVALID_UID
;
found
:
fclose
(
f
);
free
(
line
);
return
nsid
;
}
gid_t
get_ns_gid
(
gid_t
orig
)
{
char
*
line
=
NULL
;
size_t
sz
=
0
;
gid_t
nsid
,
hostid
,
range
;
FILE
*
f
=
fopen
(
"/proc/self/gid_map"
,
"r"
);
if
(
!
f
)
return
0
;
while
(
getline
(
&
line
,
&
sz
,
f
)
!=
-
1
)
{
if
(
sscanf
(
line
,
"%u %u %u"
,
&
nsid
,
&
hostid
,
&
range
)
!=
3
)
continue
;
if
(
hostid
<=
orig
&&
hostid
+
range
>
orig
)
{
nsid
+=
orig
-
hostid
;
goto
found
;
}
}
nsid
=
LXC_INVALID_GID
;
found
:
fclose
(
f
);
...
...
src/lxc/utils.h
View file @
b962868f
...
...
@@ -328,6 +328,10 @@ inline static bool am_host_unpriv(void)
* parse /proc/self/uid_map to find what @orig maps to
*/
extern
uid_t
get_ns_uid
(
uid_t
orig
);
/*
* parse /proc/self/gid_map to find what @orig maps to
*/
extern
gid_t
get_ns_gid
(
gid_t
orig
);
extern
bool
dir_exists
(
const
char
*
path
);
...
...
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