Commit Graph

17 Commits

Author SHA1 Message Date
Serge Hallyn
8f7b58d68f lxc-user-nic: dont risk passing EOF
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-25 15:12:07 -05:00
Serge Hallyn
49aba4d3c8 lxc_user_nic: fix fd leak reported by coverity
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-19 17:10:32 -06:00
Serge Hallyn
03c2eb1563 lxc-user-nic: improve cull_entries
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:27:43 -06:00
Serge Hallyn
82160e6f08 lxc_user_nic: initialize cnic to NULL to please compiler
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:27:17 -06:00
Serge Hallyn
552a7d0595 lxc_user_nic: make all fns static for consistency
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:27:12 -06:00
Serge Hallyn
8c81de199c lxc_user_nic: fix get_allotted description.
get_allotted doesn't get the list of nic names, only the # of nics
allowed to the user.  We check the db_file later for existing
number of nics.

Also close the conf file on success, and print filename and errno
if we failed to open conf file.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:27:02 -06:00
Serge Hallyn
c8f73ce205 lxc_user_nic: report failing filename in open_and_lock error cases
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:26:58 -06:00
Serge Hallyn
78f97d4c4f lxc_user_nic: only exit from main and usage
Everywhere else return an error code instead.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:26:33 -06:00
Serge Hallyn
d56e223681 lxc_user_nic: report strerror(errno)
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:26:29 -06:00
Serge Hallyn
95dfc8bd4b lxc_user_nic: don't pass unused arg to get_username()
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:26:22 -06:00
Serge Hallyn
8d9f636daf lxc_user_nic: add a check to make sure caller owns target netns
Temporarily set our euid back to the calling ruid, so that the
access(2) check can succeed based on the euid being the userns
creator.

Also switch from atoi to strtol

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-19 16:25:52 -06:00
Qiang Huang
94d942c3d2 lxc_user_nic: remove duplicate code
It's a duplicate of util.h.

Signed-off-by: Qiang Huang <h.huangqiang@huawei.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-11-07 22:25:26 -06:00
Serge Hallyn
4119204eef lxc-user-nic: rename nic inside container to desired name
To do so we do a quick setns into the container's netns.  This
(unexpectedly) turns out cleaner than trying to rename it from
lxc_setup(), because we don't know the original nic name in
the container until we created it which we do in the parent
after the init has been cloned.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
Acked-by: Stéphane Graber <stgraber@ubuntu.com>
2013-11-06 09:04:13 -06:00
Dwight Engen
5da6aa8c71 coverity: ifr_name buffer not NULL terminated
The kernel (net/core/dev_ioctl.c:dev_ioctl()) is going to NULL terminate
this name after the copy-in of the ifr, so even though this is a fixed
sized array the last byte isn't usable as part of the name. All the ioctls
we're using go through this code path.

Use the ifr name in the DEBUG message in case it was possibly truncated.

Signed-off-by: Dwight Engen <dwight.engen@oracle.com>
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-10-29 09:38:50 -05:00
Stéphane Graber
37fc7b9e2e Fix lxc-user-nic to work on bionic
This adds a couple of missing includes, uses the local version of
getline on bionic and replaces getpwuid_r by getpwuid.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
2013-08-19 14:33:36 +02:00
Serge Hallyn
070a4b8e68 lxc-user-nic: specify config and db files in autoconf
Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-14 10:50:46 -05:00
Serge Hallyn
20ab58c777 add lxc-user-nic
It is meant to be run setuid-root to allow unprivileged users to
tunnel veths from a host bridge to their containers.  The program
looks at /etc/lxc/lxc-usernet which has entries of the form

	user type bridge number

The type currently must be veth.  Whenver lxc-user-nic creates a
nic for a user, it records it in /var/lib/lxc/nics (better location
is needed).  That way when a container dies lxc-user-nic can cull
the dead nic from the list.

The -DISTEST allows lxc-user-nic to be compiled so that it uses
files under /tmp and doesn't actually create the nic, so that
unprivileged users can compile and test the code.  lxc-test-usernic
is a script which runs a few tests using lxc-usernic-test, which
is a version of lxc-user-nic compiled with -DISTEST.

The next step, after issues with this code are raised and addressed,
is to have lxc-start, when running unprivileged, call out to
lxc-user-nic (will have to exec so that setuid-root is honored).
On top of my previous unprivileged-creation patchset, that should
allow unprivileged users to create and start useful containers.

Also update .gitignore.

Signed-off-by: Serge Hallyn <serge.hallyn@ubuntu.com>
2013-08-14 10:50:37 -05:00