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
9f520fee
Commit
9f520fee
authored
Sep 05, 2017
by
Serge Hallyn
Committed by
GitHub
Sep 05, 2017
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1788 from brauner/2017-09-05/fix_tty_creation
conf: bugfixes
parents
8a0c5033
954b7d9b
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
178 additions
and
155 deletions
+178
-155
conf.c
src/lxc/conf.c
+178
-155
No files found.
src/lxc/conf.c
View file @
9f520fee
...
@@ -817,9 +817,7 @@ static int setup_dev_symlinks(const struct lxc_rootfs *rootfs)
...
@@ -817,9 +817,7 @@ static int setup_dev_symlinks(const struct lxc_rootfs *rootfs)
return
0
;
return
0
;
}
}
/*
/* Build a space-separate list of ptys to pass to systemd. */
* Build a space-separate list of ptys to pass to systemd.
*/
static
bool
append_ptyname
(
char
**
pp
,
char
*
name
)
static
bool
append_ptyname
(
char
**
pp
,
char
*
name
)
{
{
char
*
p
;
char
*
p
;
...
@@ -840,7 +838,7 @@ static bool append_ptyname(char **pp, char *name)
...
@@ -840,7 +838,7 @@ static bool append_ptyname(char **pp, char *name)
return
true
;
return
true
;
}
}
static
int
lxc_setup_tty
(
struct
lxc_conf
*
conf
)
static
int
lxc_setup_tty
s
(
struct
lxc_conf
*
conf
)
{
{
int
i
,
ret
;
int
i
,
ret
;
const
struct
lxc_tty_info
*
tty_info
=
&
conf
->
tty_info
;
const
struct
lxc_tty_info
*
tty_info
=
&
conf
->
tty_info
;
...
@@ -854,23 +852,19 @@ static int lxc_setup_tty(struct lxc_conf *conf)
...
@@ -854,23 +852,19 @@ static int lxc_setup_tty(struct lxc_conf *conf)
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/dev/tty%d"
,
i
+
1
);
ret
=
snprintf
(
path
,
sizeof
(
path
),
"/dev/tty%d"
,
i
+
1
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
path
))
ERROR
(
"pathname too long for ttys"
);
return
-
1
;
return
-
1
;
}
if
(
ttydir
)
{
if
(
ttydir
)
{
/* create dev/lxc/tty%d" */
/* create dev/lxc/tty%d" */
ret
=
snprintf
(
lxcpath
,
sizeof
(
lxcpath
),
ret
=
snprintf
(
lxcpath
,
sizeof
(
lxcpath
),
"/dev/%s/tty%d"
,
ttydir
,
i
+
1
);
"/dev/%s/tty%d"
,
ttydir
,
i
+
1
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
lxcpath
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
lxcpath
))
ERROR
(
"pathname too long for ttys"
);
return
-
1
;
return
-
1
;
}
ret
=
creat
(
lxcpath
,
0660
);
ret
=
creat
(
lxcpath
,
0660
);
if
(
ret
<
0
&&
errno
!=
EEXIST
)
{
if
(
ret
<
0
&&
errno
!=
EEXIST
)
{
SYSERROR
(
"
f
ailed to create
\"
%s
\"
"
,
lxcpath
);
SYSERROR
(
"
F
ailed to create
\"
%s
\"
"
,
lxcpath
);
return
-
1
;
return
-
1
;
}
}
if
(
ret
>=
0
)
if
(
ret
>=
0
)
...
@@ -878,13 +872,13 @@ static int lxc_setup_tty(struct lxc_conf *conf)
...
@@ -878,13 +872,13 @@ static int lxc_setup_tty(struct lxc_conf *conf)
ret
=
unlink
(
path
);
ret
=
unlink
(
path
);
if
(
ret
<
0
&&
errno
!=
ENOENT
)
{
if
(
ret
<
0
&&
errno
!=
ENOENT
)
{
SYSERROR
(
"
f
ailed to unlink
\"
%s
\"
"
,
path
);
SYSERROR
(
"
F
ailed to unlink
\"
%s
\"
"
,
path
);
return
-
1
;
return
-
1
;
}
}
ret
=
mount
(
pty_info
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
);
ret
=
mount
(
pty_info
->
name
,
lxcpath
,
"none"
,
MS_BIND
,
0
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
WARN
(
"
f
ailed to bind mount
\"
%s
\"
onto
\"
%s
\"
"
,
WARN
(
"
F
ailed to bind mount
\"
%s
\"
onto
\"
%s
\"
"
,
pty_info
->
name
,
path
);
pty_info
->
name
,
path
);
continue
;
continue
;
}
}
...
@@ -893,14 +887,12 @@ static int lxc_setup_tty(struct lxc_conf *conf)
...
@@ -893,14 +887,12 @@ static int lxc_setup_tty(struct lxc_conf *conf)
ret
=
snprintf
(
lxcpath
,
sizeof
(
lxcpath
),
"%s/tty%d"
,
ret
=
snprintf
(
lxcpath
,
sizeof
(
lxcpath
),
"%s/tty%d"
,
ttydir
,
i
+
1
);
ttydir
,
i
+
1
);
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
lxcpath
))
{
if
(
ret
<
0
||
(
size_t
)
ret
>=
sizeof
(
lxcpath
))
ERROR
(
"tty pathname too long"
);
return
-
1
;
return
-
1
;
}
ret
=
symlink
(
lxcpath
,
path
);
ret
=
symlink
(
lxcpath
,
path
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"
f
ailed to create symlink
\"
%s
\"
->
\"
%s
\"
"
,
SYSERROR
(
"
F
ailed to create symlink
\"
%s
\"
->
\"
%s
\"
"
,
path
,
lxcpath
);
path
,
lxcpath
);
return
-
1
;
return
-
1
;
}
}
...
@@ -912,7 +904,7 @@ static int lxc_setup_tty(struct lxc_conf *conf)
...
@@ -912,7 +904,7 @@ static int lxc_setup_tty(struct lxc_conf *conf)
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ret
=
creat
(
path
,
0660
);
ret
=
creat
(
path
,
0660
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"
f
ailed to create
\"
%s
\"
"
,
path
);
SYSERROR
(
"
F
ailed to create
\"
%s
\"
"
,
path
);
/* this isn't fatal, continue */
/* this isn't fatal, continue */
}
else
{
}
else
{
close
(
ret
);
close
(
ret
);
...
@@ -921,11 +913,11 @@ static int lxc_setup_tty(struct lxc_conf *conf)
...
@@ -921,11 +913,11 @@ static int lxc_setup_tty(struct lxc_conf *conf)
ret
=
mount
(
pty_info
->
name
,
path
,
"none"
,
MS_BIND
,
0
);
ret
=
mount
(
pty_info
->
name
,
path
,
"none"
,
MS_BIND
,
0
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
SYSERROR
(
"
f
ailed to mount '%s'->'%s'"
,
pty_info
->
name
,
path
);
SYSERROR
(
"
F
ailed to mount '%s'->'%s'"
,
pty_info
->
name
,
path
);
continue
;
continue
;
}
}
DEBUG
(
"
b
ind mounted
\"
%s
\"
onto
\"
%s
\"
"
,
pty_info
->
name
,
DEBUG
(
"
B
ind mounted
\"
%s
\"
onto
\"
%s
\"
"
,
pty_info
->
name
,
path
);
path
);
}
}
...
@@ -935,10 +927,154 @@ static int lxc_setup_tty(struct lxc_conf *conf)
...
@@ -935,10 +927,154 @@ static int lxc_setup_tty(struct lxc_conf *conf)
}
}
}
}
INFO
(
"finished setting up %d /dev/tty<N> device(s)"
,
tty_info
->
nbtty
);
INFO
(
"Finished setting up %d /dev/tty<N> device(s)"
,
tty_info
->
nbtty
);
return
0
;
}
int
lxc_allocate_ttys
(
const
char
*
name
,
struct
lxc_conf
*
conf
)
{
struct
lxc_tty_info
*
tty_info
=
&
conf
->
tty_info
;
int
i
,
ret
;
/* no tty in the configuration */
if
(
!
conf
->
tty
)
return
0
;
tty_info
->
pty_info
=
malloc
(
sizeof
(
*
tty_info
->
pty_info
)
*
conf
->
tty
);
if
(
!
tty_info
->
pty_info
)
{
SYSERROR
(
"failed to allocate struct *pty_info"
);
return
-
ENOMEM
;
}
for
(
i
=
0
;
i
<
conf
->
tty
;
i
++
)
{
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
process_lock
();
ret
=
openpty
(
&
pty_info
->
master
,
&
pty_info
->
slave
,
pty_info
->
name
,
NULL
,
NULL
);
process_unlock
();
if
(
ret
)
{
SYSERROR
(
"failed to create pty device number %d"
,
i
);
tty_info
->
nbtty
=
i
;
lxc_delete_tty
(
tty_info
);
return
-
ENOTTY
;
}
DEBUG
(
"allocated pty
\"
%s
\"
with master fd %d and slave fd %d"
,
pty_info
->
name
,
pty_info
->
master
,
pty_info
->
slave
);
/* Prevent leaking the file descriptors to the container */
ret
=
fcntl
(
pty_info
->
master
,
F_SETFD
,
FD_CLOEXEC
);
if
(
ret
<
0
)
WARN
(
"failed to set FD_CLOEXEC flag on master fd %d of "
"pty device
\"
%s
\"
: %s"
,
pty_info
->
master
,
pty_info
->
name
,
strerror
(
errno
));
ret
=
fcntl
(
pty_info
->
slave
,
F_SETFD
,
FD_CLOEXEC
);
if
(
ret
<
0
)
WARN
(
"failed to set FD_CLOEXEC flag on slave fd %d of "
"pty device
\"
%s
\"
: %s"
,
pty_info
->
slave
,
pty_info
->
name
,
strerror
(
errno
));
pty_info
->
busy
=
0
;
}
tty_info
->
nbtty
=
conf
->
tty
;
INFO
(
"finished allocating %d pts devices"
,
conf
->
tty
);
return
0
;
return
0
;
}
}
void
lxc_delete_tty
(
struct
lxc_tty_info
*
tty_info
)
{
int
i
;
for
(
i
=
0
;
i
<
tty_info
->
nbtty
;
i
++
)
{
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
close
(
pty_info
->
master
);
close
(
pty_info
->
slave
);
}
free
(
tty_info
->
pty_info
);
tty_info
->
pty_info
=
NULL
;
tty_info
->
nbtty
=
0
;
}
static
int
lxc_send_ttys_to_parent
(
struct
lxc_handler
*
handler
)
{
int
i
;
struct
lxc_conf
*
conf
=
handler
->
conf
;
struct
lxc_tty_info
*
tty_info
=
&
conf
->
tty_info
;
int
sock
=
handler
->
data_sock
[
0
];
int
ret
=
-
1
;
if
(
!
conf
->
tty
)
return
0
;
for
(
i
=
0
;
i
<
conf
->
tty
;
i
++
)
{
int
ttyfds
[
2
];
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
ttyfds
[
0
]
=
pty_info
->
master
;
ttyfds
[
1
]
=
pty_info
->
slave
;
ret
=
lxc_abstract_unix_send_fds
(
sock
,
ttyfds
,
2
,
NULL
,
0
);
if
(
ret
<
0
)
break
;
TRACE
(
"Send pty
\"
%s
\"
with master fd %d and slave fd %d to "
"parent"
,
pty_info
->
name
,
pty_info
->
master
,
pty_info
->
slave
);
}
if
(
ret
<
0
)
ERROR
(
"Failed to send %d ttys to parent: %s"
,
conf
->
tty
,
strerror
(
errno
));
else
TRACE
(
"Sent %d ttys to parent"
,
conf
->
tty
);
return
ret
;
}
static
int
lxc_create_ttys
(
struct
lxc_handler
*
handler
)
{
int
ret
=
-
1
;
struct
lxc_conf
*
conf
=
handler
->
conf
;
ret
=
lxc_allocate_ttys
(
handler
->
name
,
conf
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to allocate ttys"
);
goto
on_error
;
}
ret
=
lxc_send_ttys_to_parent
(
handler
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to send ttys to parent"
);
goto
on_error
;
}
if
(
!
conf
->
is_execute
)
{
ret
=
lxc_setup_ttys
(
conf
);
if
(
ret
<
0
)
{
ERROR
(
"Failed to setup ttys"
);
goto
on_error
;
}
}
if
(
conf
->
pty_names
)
{
ret
=
setenv
(
"container_ttys"
,
conf
->
pty_names
,
1
);
if
(
ret
<
0
)
SYSERROR
(
"Failed to set
\"
container_ttys=%s
\"
"
,
conf
->
pty_names
);
}
ret
=
0
;
on_error:
lxc_delete_tty
(
&
conf
->
tty_info
);
return
ret
;
}
static
int
setup_rootfs_pivot_root
(
const
char
*
rootfs
)
static
int
setup_rootfs_pivot_root
(
const
char
*
rootfs
)
{
{
int
oldroot
=
-
1
,
newroot
=
-
1
;
int
oldroot
=
-
1
,
newroot
=
-
1
;
...
@@ -2602,8 +2738,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
...
@@ -2602,8 +2738,7 @@ int lxc_map_ids(struct lxc_list *idmap, pid_t pid)
}
else
{
}
else
{
ret
=
write_id_mapping
(
type
,
pid
,
mapbuf
,
pos
-
mapbuf
);
ret
=
write_id_mapping
(
type
,
pid
,
mapbuf
,
pos
-
mapbuf
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
ERROR
(
"Failed to write mapping
\"
%s
\"
: %s"
,
ERROR
(
"Failed to write mapping: %s"
,
mapbuf
);
cmd_output
,
mapbuf
);
return
-
1
;
return
-
1
;
}
}
TRACE
(
"Wrote mapping
\"
%s
\"
"
,
mapbuf
);
TRACE
(
"Wrote mapping
\"
%s
\"
"
,
mapbuf
);
...
@@ -2670,77 +2805,6 @@ again:
...
@@ -2670,77 +2805,6 @@ again:
return
freeid
;
return
freeid
;
}
}
int
lxc_create_tty
(
const
char
*
name
,
struct
lxc_conf
*
conf
)
{
struct
lxc_tty_info
*
tty_info
=
&
conf
->
tty_info
;
int
i
,
ret
;
/* no tty in the configuration */
if
(
!
conf
->
tty
)
return
0
;
tty_info
->
pty_info
=
malloc
(
sizeof
(
*
tty_info
->
pty_info
)
*
conf
->
tty
);
if
(
!
tty_info
->
pty_info
)
{
SYSERROR
(
"failed to allocate struct *pty_info"
);
return
-
ENOMEM
;
}
for
(
i
=
0
;
i
<
conf
->
tty
;
i
++
)
{
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
process_lock
();
ret
=
openpty
(
&
pty_info
->
master
,
&
pty_info
->
slave
,
pty_info
->
name
,
NULL
,
NULL
);
process_unlock
();
if
(
ret
)
{
SYSERROR
(
"failed to create pty device number %d"
,
i
);
tty_info
->
nbtty
=
i
;
lxc_delete_tty
(
tty_info
);
return
-
ENOTTY
;
}
DEBUG
(
"allocated pty
\"
%s
\"
with master fd %d and slave fd %d"
,
pty_info
->
name
,
pty_info
->
master
,
pty_info
->
slave
);
/* Prevent leaking the file descriptors to the container */
ret
=
fcntl
(
pty_info
->
master
,
F_SETFD
,
FD_CLOEXEC
);
if
(
ret
<
0
)
WARN
(
"failed to set FD_CLOEXEC flag on master fd %d of "
"pty device
\"
%s
\"
: %s"
,
pty_info
->
master
,
pty_info
->
name
,
strerror
(
errno
));
ret
=
fcntl
(
pty_info
->
slave
,
F_SETFD
,
FD_CLOEXEC
);
if
(
ret
<
0
)
WARN
(
"failed to set FD_CLOEXEC flag on slave fd %d of "
"pty device
\"
%s
\"
: %s"
,
pty_info
->
slave
,
pty_info
->
name
,
strerror
(
errno
));
pty_info
->
busy
=
0
;
}
tty_info
->
nbtty
=
conf
->
tty
;
INFO
(
"finished allocating %d pts devices"
,
conf
->
tty
);
return
0
;
}
void
lxc_delete_tty
(
struct
lxc_tty_info
*
tty_info
)
{
int
i
;
for
(
i
=
0
;
i
<
tty_info
->
nbtty
;
i
++
)
{
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
close
(
pty_info
->
master
);
close
(
pty_info
->
slave
);
}
free
(
tty_info
->
pty_info
);
tty_info
->
pty_info
=
NULL
;
tty_info
->
nbtty
=
0
;
}
int
chown_mapped_root_exec_wrapper
(
void
*
args
)
int
chown_mapped_root_exec_wrapper
(
void
*
args
)
{
{
execvp
(
"lxc-usernsexec"
,
args
);
execvp
(
"lxc-usernsexec"
,
args
);
...
@@ -3069,45 +3133,9 @@ static bool verify_start_hooks(struct lxc_conf *conf)
...
@@ -3069,45 +3133,9 @@ static bool verify_start_hooks(struct lxc_conf *conf)
return
true
;
return
true
;
}
}
static
int
lxc_send_ttys_to_parent
(
struct
lxc_handler
*
handler
)
{
int
i
;
struct
lxc_conf
*
conf
=
handler
->
conf
;
struct
lxc_tty_info
*
tty_info
=
&
conf
->
tty_info
;
int
sock
=
handler
->
data_sock
[
0
];
int
ret
=
-
1
;
if
(
!
conf
->
tty
)
return
0
;
for
(
i
=
0
;
i
<
conf
->
tty
;
i
++
)
{
int
ttyfds
[
2
];
struct
lxc_pty_info
*
pty_info
=
&
tty_info
->
pty_info
[
i
];
ttyfds
[
0
]
=
pty_info
->
master
;
ttyfds
[
1
]
=
pty_info
->
slave
;
ret
=
lxc_abstract_unix_send_fds
(
sock
,
ttyfds
,
2
,
NULL
,
0
);
if
(
ret
<
0
)
break
;
TRACE
(
"Send pty
\"
%s
\"
with master fd %d and slave fd %d to "
"parent"
,
pty_info
->
name
,
pty_info
->
master
,
pty_info
->
slave
);
}
if
(
ret
<
0
)
ERROR
(
"Failed to send %d ttys to parent: %s"
,
conf
->
tty
,
strerror
(
errno
));
else
TRACE
(
"Sent %d ttys to parent"
,
conf
->
tty
);
lxc_delete_tty
(
tty_info
);
return
ret
;
}
int
lxc_setup
(
struct
lxc_handler
*
handler
)
int
lxc_setup
(
struct
lxc_handler
*
handler
)
{
{
int
ret
;
const
char
*
name
=
handler
->
name
;
const
char
*
name
=
handler
->
name
;
struct
lxc_conf
*
lxc_conf
=
handler
->
conf
;
struct
lxc_conf
*
lxc_conf
=
handler
->
conf
;
const
char
*
lxcpath
=
handler
->
lxcpath
;
const
char
*
lxcpath
=
handler
->
lxcpath
;
...
@@ -3218,24 +3246,9 @@ int lxc_setup(struct lxc_handler *handler)
...
@@ -3218,24 +3246,9 @@ int lxc_setup(struct lxc_handler *handler)
return
-
1
;
return
-
1
;
}
}
if
(
lxc_create_tty
(
name
,
lxc_conf
))
{
ret
=
lxc_create_ttys
(
handler
);
ERROR
(
"failed to create the ttys"
);
if
(
ret
<
0
)
return
-
1
;
}
if
(
lxc_send_ttys_to_parent
(
handler
)
<
0
)
{
ERROR
(
"failure sending console info to parent"
);
return
-
1
;
}
if
(
!
lxc_conf
->
is_execute
&&
lxc_setup_tty
(
lxc_conf
))
{
ERROR
(
"failed to setup the ttys for '%s'"
,
name
);
return
-
1
;
return
-
1
;
}
if
(
lxc_conf
->
pty_names
&&
setenv
(
"container_ttys"
,
lxc_conf
->
pty_names
,
1
))
SYSERROR
(
"failed to set environment variable for container ptys"
);
if
(
setup_personality
(
lxc_conf
->
personality
))
{
if
(
setup_personality
(
lxc_conf
->
personality
))
{
ERROR
(
"failed to setup personality"
);
ERROR
(
"failed to setup personality"
);
...
@@ -3669,6 +3682,9 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
...
@@ -3669,6 +3682,9 @@ 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
;
euid
=
geteuid
();
egid
=
getegid
();
/* Find container root. */
/* Find container root. */
lxc_list_for_each
(
it
,
&
conf
->
id_map
)
{
lxc_list_for_each
(
it
,
&
conf
->
id_map
)
{
map
=
it
->
elem
;
map
=
it
->
elem
;
...
@@ -3684,6 +3700,12 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
...
@@ -3684,6 +3700,12 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
container_root_uid
->
hostid
=
map
->
hostid
;
container_root_uid
->
hostid
=
map
->
hostid
;
container_root_uid
->
nsid
=
0
;
container_root_uid
->
nsid
=
0
;
container_root_uid
->
range
=
map
->
range
;
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
)
{
}
else
if
(
map
->
idtype
==
ID_TYPE_GID
&&
container_root_gid
==
NULL
)
{
container_root_gid
=
malloc
(
sizeof
(
*
container_root_gid
));
container_root_gid
=
malloc
(
sizeof
(
*
container_root_gid
));
if
(
!
container_root_gid
)
if
(
!
container_root_gid
)
...
@@ -3692,6 +3714,12 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
...
@@ -3692,6 +3714,12 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
container_root_gid
->
hostid
=
map
->
hostid
;
container_root_gid
->
hostid
=
map
->
hostid
;
container_root_gid
->
nsid
=
0
;
container_root_gid
->
nsid
=
0
;
container_root_gid
->
range
=
map
->
range
;
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. */
/* Found container root. */
...
@@ -3705,16 +3733,11 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
...
@@ -3705,16 +3733,11 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
goto
on_error
;
goto
on_error
;
}
}
host_uid_map
=
container_root_uid
;
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. */
euid
=
geteuid
();
if
(
!
host_uid_map
)
egid
=
getegid
();
if
(
euid
!=
container_root_uid
->
hostid
)
host_uid_map
=
idmap_add
(
conf
,
euid
,
ID_TYPE_UID
);
host_uid_map
=
idmap_add
(
conf
,
euid
,
ID_TYPE_UID
);
if
(
egid
!=
container_root_gid
->
hostid
)
if
(
!
host_gid_map
)
host_gid_map
=
idmap_add
(
conf
,
egid
,
ID_TYPE_GID
);
host_gid_map
=
idmap_add
(
conf
,
egid
,
ID_TYPE_GID
);
if
(
!
host_uid_map
)
{
if
(
!
host_uid_map
)
{
...
...
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