libxl: Do root checks once in libxl__domain_get_device_model_uid
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 21 Dec 2018 15:41:07 +0000 (15:41 +0000)
committerGeorge Dunlap <george.dunlap@citrix.com>
Fri, 21 Dec 2018 18:41:53 +0000 (18:41 +0000)
commit436bf83bf13c94eb68a34e8ae5d7fe3e4be2af33
tree51be4a2915e3be947934dc09eb0e9d8a583045e6
parent53bf85de47b6cb1f727c71bbcc533d0ed78efc64
libxl: Do root checks once in libxl__domain_get_device_model_uid

At the moment, we check for equivalence to literal "root" before
deciding whether to add the `runas` command-line option to QEMU.  This
is unsatisfactory for several reasons.

First, just because the string doesn't match "root" doesn't mean the
final uid won't end up being zero; in particular, the range_base
calculations may end up producing "0:NNN", which would be root in any
case.

Secondly, it's almost certainly a configuration error if the resulting
uid ends up to be zero; rather than silently do what was specified but
probably not intended, throw an error.

To fix this, check for root once in
libxl__domain_get_device_model_uid.  If the result is root, return an
error; if appropriate, set `runas`.

After that, assume that the presence of state->dm_runas implies that a
`runas` argument should be constructed.

One side effect of this is to check whether device_model_user exists
before passing it to qemu, resulting in better error reporting.

While we're here:
- Refactor the function to use the "goto out" idiom
- Use 'rc' rather than 'ret', in line with CODING_STYLE

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
Acked-by: Ian Jackson <ian.jackson@eu.citrix.com>
tools/libxl/libxl_dm.c