summaryrefslogtreecommitdiff
path: root/tools/virt-login-shell-helper.c
Commit message (Collapse)AuthorAgeFilesLines
* tools: Update format strings in translated messages (part 2)Jiri Denemark2023-04-011-11/+11
| | | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
* lib: Use the same style in the 'struct option'Jiang Jiacheng2022-11-221-3/+3
| | | | | | | | | | | | | Use same style in the 'struct option' as: struct option opt[] = { { a, b }, { a, b }, ... { a, b }, }; Signed-off-by: Jiang Jiacheng <jiangjiacheng@huawei.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* tools: Remove unused includesPeng Liang2022-06-161-1/+0
| | | | | Signed-off-by: Peng Liang <tcx4c70@gmail.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
* Prefer g_auto(GStrv) over g_strfreev()Michal Privoznik2021-11-111-4/+3
| | | | | | | | | There are a few cases where a string list is freed by an explicit call of g_strfreev(), but the same result can be achieved by g_atuo(GStrv). Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
* Replace AbsPath judgement method with g_path_is_absolute()Luke Yue2021-04-211-1/+1
| | | | | | | | | | | The g_path_is_absolute() considers more situations than just a simply "path[0] == '/'". Related issue: https://gitlab.com/libvirt/libvirt/-/issues/12 Signed-off-by: Luke Yue <lukedyue@gmail.com> Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* lib: Drop internal virXXXPtr typedefsMichal Privoznik2021-04-131-2/+2
| | | | | | | | | | | | | | | | | | | | | | Historically, we declared pointer type to our types: typedef struct _virXXX virXXX; typedef virXXX *virXXXPtr; But usefulness of such declaration is questionable, at best. Unfortunately, we can't drop every such declaration - we have to carry some over, because they are part of public API (e.g. virDomainPtr). But for internal types - we can do drop them and use what every other C project uses 'virXXX *'. This change was generated by a very ugly shell script that generated sed script which was then called over each file in the repository. For the shell script refer to the cover letter: https://listman.redhat.com/archives/libvir-list/2021-March/msg00537.html Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Peter Krempa <pkrempa@redhat.com>
* Do not check return value of VIR_REALLOC_NJiri Denemark2021-03-221-2/+1
| | | | | Signed-off-by: Jiri Denemark <jdenemar@redhat.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
* Replace virStringListLength by g_strv_lengthPeter Krempa2021-02-111-1/+1
| | | | | | | | The glib implementation doesn't tolerate NULL but in most cases we check before anyways. The rest of the callers adds a NULL check. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* Fix incorrect g_new0 conversionsJán Tomko2020-10-061-1/+0
| | | | | | | | | I left in a 'return' or 'goto cleanup' in a few places where I did the conversion manually. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reported-by: John Ferlan <jferlan@redhat.com> Reviewed-by: John Ferlan <jferlan@redhat.com>
* tools: use g_new0 instead of VIR_ALLOC*Ján Tomko2020-10-011-9/+4
| | | | | | | With the exception of vsh*alloc. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
* Use g_strfeev instead of virStringFreeListJán Tomko2020-08-031-3/+3
| | | | | | | | | Both accept a NULL value gracefully and virStringFreeList does not zero the pointer afterwards, so a straight replace is safe. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* virt-login-shell: correctly calculate string lengthJán Tomko2020-08-031-1/+1
| | | | | | | | | | virLoginShellGetShellArgv was not dereferencing the pointer to the string list containing the shell parameters from the config file, thus setting some random number as shargvlen. Signed-off-by: Ján Tomko <jtomko@redhat.com> Fixes: 740e4d705284ba0598258291c2656f50075486f0 Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
* src: switch from fnmatch to g_pattern_match_simpleDaniel P. Berrangé2020-01-031-3/+2
| | | | | | | | | | | | | The g_pattern_match function_simple is an acceptably close approximation of fnmatch for libvirt's needs. In contrast to fnmatch(), the '/' character can be matched by the wildcards, there are no '[...]' character ranges and '*' and '?' can not be escaped to include them literally in a pattern. Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* src: switch to use g_setenv/g_unsetenvDaniel P. Berrangé2020-01-031-6/+6
| | | | | | | | | Eliminate direct use of normal setenv/unsetenv calls in favour of GLib's wrapper. This eliminates two gnulib modules Reviewed-by: Fabiano Fidêncio <fidencio@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* tools: use g_strdup instead of VIR_STRDUPJán Tomko2019-10-211-12/+5
| | | | | | | | | | | Replace all occurrences of if (VIR_STRDUP(a, b) < 0) /* effectively dead code */ with: a = g_strdup(b); Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* Use g_autoptr instead of VIR_AUTOPTRJán Tomko2019-10-161-1/+1
| | | | | | | | | | | Since commit 44e7f029159ed701b4a1739ac711507ee53790ed util: rewrite auto cleanup macros to use glib's equivalent VIR_AUTOPTR aliases to g_autoptr. Replace all of its use by the GLib macro version. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* tools: use G_GNUC_UNUSEDJán Tomko2019-10-151-2/+2
| | | | | | | Use G_GNUC_UNUSED from GLib instead of ATTRIBUTE_UNUSED. Signed-off-by: Ján Tomko <jtomko@redhat.com> Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
* lib: Define and use autofree for virConfPtrMichal Privoznik2019-09-101-2/+1
| | | | | Signed-off-by: Michal Privoznik <mprivozn@redhat.com> Reviewed-by: Daniel Henrique Barboza <danielhb413@gmail.com>
* util: get rid of virGetEnv{Allow,Block}SUID functionsDaniel P. Berrangé2019-08-071-2/+2
| | | | | | | | | | | | Now that 100% of libvirt code is forbidden in a SUID environment, we no longer need to worry about whether env variables are trustworthy or not. The virt-login-shell setuid program, which does not link to any libvirt code, will purge all environment variables, except $TERM, before invoking the virt-login-shell-helper program which uses libvirt. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* tools: split virt-login-shell into two binariesDaniel P. Berrangé2019-08-071-7/+31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The virt-login-shell binary is a setuid program that takes no arguments. When invoked it looks at the invoking uid, resolves it to a username, and finds an LXC guest with the same name. It then starts the guest and runs the shell in side the namespaces of the container. Given this set of tasks the virt-login-shell binary needs to connect to libvirtd, make various other libvirt API calls. This is a problem for setuid binaries as various libraries that libvirt.so links to are not safe. For example, they have constructor functions which execute an unknown amount of code that can be influenced by env variables. For this reason virt-login-shell doesn't use libvirt.so, but instead links to a custom, cut down, set of source files sufficient to be a local client only. This introduces a problem for integrating glib2 into libvirt though, as once integrated, there would be no way to build virt-login-shell without an external dependancy on glib2 and this is definitely not setuid safe. To resolve this problem, we split the virt-login-shell binary into two parts. The first part is setuid and does almost nothing. It simply records the original uid+gid, and then invokes the virt-login-shell-helper binary. Crucially when it does this it completes scrubs all environment variables. It is thus safe for virt-login-shell-helper to link to the normal libvirt.so. Any things that constructor functions do cannot be influenced by user control env vars or cli args. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
* tools: rename source for virt-login-shellDaniel P. Berrangé2019-08-071-0/+415
We'll shortly be renaming the binary to virt-login-shell-helper and introducing a new tool as virt-login-shell. Renaming the source file first gives a much more usefull diff for the next commit. Reviewed-by: Michal Privoznik <mprivozn@redhat.com> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>