X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=qemu-bridge-helper.c;h=a26e1663f02de3c99198df6e2080d52c051f1ac1;hb=6765e988e12825e9464a10b6451aeb25b29bfbc3;hp=2058e104541f868065c56b3cbc705097ef30cb57;hpb=6f5d8671225dc77190647f18a27a0d156d4ca97a;p=mirror_qemu.git diff --git a/qemu-bridge-helper.c b/qemu-bridge-helper.c index 2058e10454..a26e1663f0 100644 --- a/qemu-bridge-helper.c +++ b/qemu-bridge-helper.c @@ -40,10 +40,11 @@ #endif #include "qemu/queue.h" +#include "qemu/cutils.h" #include "net/tap-linux.h" -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG #include #endif @@ -102,9 +103,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (arg == NULL) { fprintf(stderr, "Invalid config line:\n %s\n", line); - fclose(f); - errno = EINVAL; - return -1; + goto err; } *arg = 0; @@ -121,9 +120,7 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) if (!g_str_equal(cmd, "include") && strlen(arg) >= IFNAMSIZ) { fprintf(stderr, "name `%s' too long: %zu\n", arg, strlen(arg)); - fclose(f); - errno = EINVAL; - return -1; + goto err; } if (strcmp(cmd, "deny") == 0) { @@ -149,15 +146,18 @@ static int parse_acl_file(const char *filename, ACLList *acl_list) parse_acl_file(arg, acl_list); } else { fprintf(stderr, "Unknown command `%s'\n", cmd); - fclose(f); - errno = EINVAL; - return -1; + goto err; } } fclose(f); - return 0; + +err: + fclose(f); + errno = EINVAL; + return -1; + } static bool has_vnet_hdr(int fd) @@ -208,7 +208,7 @@ static int send_fd(int c, int fd) return sendmsg(c, &msg, 0); } -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG static int drop_privileges(void) { /* clear all capabilities */ @@ -246,8 +246,9 @@ int main(int argc, char **argv) ACLList acl_list; int access_allowed, access_denied; int ret = EXIT_SUCCESS; + g_autofree char *acl_file = NULL; -#ifdef CONFIG_LIBCAP +#ifdef CONFIG_LIBCAP_NG /* if we're run from an suid binary, immediately drop privileges preserving * cap_net_admin */ if (geteuid() == 0 && getuid() != geteuid()) { @@ -258,6 +259,8 @@ int main(int argc, char **argv) } #endif + qemu_init_exec_dir(argv[0]); + /* parse arguments */ for (index = 1; index < argc; index++) { if (strcmp(argv[index], "--use-vnet") == 0) { @@ -283,9 +286,10 @@ int main(int argc, char **argv) /* parse default acl file */ QSIMPLEQ_INIT(&acl_list); - if (parse_acl_file(DEFAULT_ACL_FILE, &acl_list) == -1) { + acl_file = get_relocated_path(DEFAULT_ACL_FILE); + if (parse_acl_file(acl_file, &acl_list) == -1) { fprintf(stderr, "failed to parse default acl file `%s'\n", - DEFAULT_ACL_FILE); + acl_file); ret = EXIT_FAILURE; goto cleanup; }