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
db7cfe23
Unverified
Commit
db7cfe23
authored
Jan 02, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
conf: adapt userns_exec_1()
Closes #2033. Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
c4333195
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
52 additions
and
46 deletions
+52
-46
conf.c
src/lxc/conf.c
+52
-46
No files found.
src/lxc/conf.c
View file @
db7cfe23
...
@@ -3722,6 +3722,44 @@ static int run_userns_fn(void *data)
...
@@ -3722,6 +3722,44 @@ static int run_userns_fn(void *data)
return
d
->
fn
(
d
->
arg
);
return
d
->
fn
(
d
->
arg
);
}
}
static
struct
id_map
*
find_mapped_nsid_entry
(
struct
lxc_conf
*
conf
,
unsigned
id
,
enum
idtype
idtype
)
{
struct
lxc_list
*
it
;
struct
id_map
*
map
;
struct
id_map
*
retmap
=
NULL
;
lxc_list_for_each
(
it
,
&
conf
->
id_map
)
{
map
=
it
->
elem
;
if
(
map
->
idtype
!=
idtype
)
continue
;
if
(
id
>=
map
->
nsid
&&
id
<
map
->
nsid
+
map
->
range
)
{
retmap
=
map
;
break
;
}
}
return
retmap
;
}
static
struct
id_map
*
mapped_nsid_add
(
struct
lxc_conf
*
conf
,
unsigned
id
,
enum
idtype
idtype
)
{
struct
id_map
*
map
,
*
retmap
;
map
=
find_mapped_nsid_entry
(
conf
,
id
,
idtype
);
if
(
!
map
)
return
NULL
;
retmap
=
malloc
(
sizeof
(
*
retmap
));
if
(
!
retmap
)
return
NULL
;
memcpy
(
retmap
,
map
,
sizeof
(
*
retmap
));
return
retmap
;
}
static
struct
id_map
*
find_mapped_hostid_entry
(
struct
lxc_conf
*
conf
,
static
struct
id_map
*
find_mapped_hostid_entry
(
struct
lxc_conf
*
conf
,
unsigned
id
,
enum
idtype
idtype
)
unsigned
id
,
enum
idtype
idtype
)
{
{
...
@@ -3824,56 +3862,24 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
...
@@ -3824,56 +3862,24 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
close
(
p
[
0
]);
close
(
p
[
0
]);
p
[
0
]
=
-
1
;
p
[
0
]
=
-
1
;
/* Find container root mappings. */
euid
=
geteuid
();
euid
=
geteuid
();
egid
=
getegid
();
container_root_uid
=
mapped_nsid_add
(
conf
,
0
,
ID_TYPE_UID
);
if
(
!
container_root_uid
)
{
/* Find container root. */
DEBUG
(
"Failed to find mapping for container root uid %d"
,
0
);
lxc_list_for_each
(
it
,
&
conf
->
id_map
)
{
map
=
it
->
elem
;
if
(
map
->
nsid
!=
0
)
continue
;
if
(
map
->
idtype
==
ID_TYPE_UID
&&
container_root_uid
==
NULL
)
{
container_root_uid
=
malloc
(
sizeof
(
*
container_root_uid
));
if
(
!
container_root_uid
)
goto
on_error
;
container_root_uid
->
idtype
=
map
->
idtype
;
container_root_uid
->
hostid
=
map
->
hostid
;
container_root_uid
->
nsid
=
0
;
container_root_uid
->
range
=
map
->
range
;
/* Check if container root mapping contains a mapping
* for user's uid.
*/
if
(
euid
>=
map
->
hostid
&&
euid
<
map
->
hostid
+
map
->
range
)
host_uid_map
=
container_root_uid
;
}
else
if
(
map
->
idtype
==
ID_TYPE_GID
&&
container_root_gid
==
NULL
)
{
container_root_gid
=
malloc
(
sizeof
(
*
container_root_gid
));
if
(
!
container_root_gid
)
goto
on_error
;
goto
on_error
;
container_root_gid
->
idtype
=
map
->
idtype
;
container_root_gid
->
hostid
=
map
->
hostid
;
container_root_gid
->
nsid
=
0
;
container_root_gid
->
range
=
map
->
range
;
/* Check if container root mapping contains a mapping
* for user's gid.
*/
if
(
egid
>=
map
->
hostid
&&
egid
<
map
->
hostid
+
map
->
range
)
host_gid_map
=
container_root_gid
;
}
/* Found container root. */
if
(
container_root_uid
&&
container_root_gid
)
break
;
}
}
if
(
euid
>=
container_root_uid
->
hostid
&&
euid
<
container_root_uid
->
hostid
+
container_root_uid
->
range
)
host_uid_map
=
container_root_uid
;
/* This is actually checked earlier but it can't hurt. */
egid
=
getegid
();
if
(
!
container_root_uid
||
!
container_root_gid
)
{
container_root_gid
=
mapped_nsid_add
(
conf
,
0
,
ID_TYPE_GID
);
ERROR
(
"no mapping for container root found"
);
if
(
!
container_root_gid
)
{
DEBUG
(
"Failed to find mapping for container root gid %d"
,
0
);
goto
on_error
;
goto
on_error
;
}
}
if
(
egid
>=
container_root_gid
->
hostid
&&
egid
<
container_root_gid
->
hostid
+
container_root_gid
->
range
)
host_gid_map
=
container_root_gid
;
/* Check whether the {g,u}id of the user has a mapping. */
/* Check whether the {g,u}id of the user has a mapping. */
if
(
!
host_uid_map
)
if
(
!
host_uid_map
)
...
@@ -3883,12 +3889,12 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
...
@@ -3883,12 +3889,12 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
host_gid_map
=
mapped_hostid_add
(
conf
,
egid
,
ID_TYPE_GID
);
host_gid_map
=
mapped_hostid_add
(
conf
,
egid
,
ID_TYPE_GID
);
if
(
!
host_uid_map
)
{
if
(
!
host_uid_map
)
{
DEBUG
(
"
f
ailed to find mapping for uid %d"
,
euid
);
DEBUG
(
"
F
ailed to find mapping for uid %d"
,
euid
);
goto
on_error
;
goto
on_error
;
}
}
if
(
!
host_gid_map
)
{
if
(
!
host_gid_map
)
{
DEBUG
(
"
f
ailed to find mapping for gid %d"
,
egid
);
DEBUG
(
"
F
ailed to find mapping for gid %d"
,
egid
);
goto
on_error
;
goto
on_error
;
}
}
...
...
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