From a23e7844c3f11d19deaedd4906563ed96009bdcd Mon Sep 17 00:00:00 2001 From: Toni Uhlig Date: Thu, 21 Jun 2018 02:43:53 +0200 Subject: several minor bugfixes Signed-off-by: Toni Uhlig --- src/main.c | 6 +++--- src/protocol_ssh.c | 11 +++-------- src/utils.c | 29 +++++++++++++++-------------- 3 files changed, 21 insertions(+), 25 deletions(-) diff --git a/src/main.c b/src/main.c index cf62d32..235a0f5 100644 --- a/src/main.c +++ b/src/main.c @@ -309,9 +309,6 @@ int main(int argc, char *argv[]) LOG_SET_FUNCS_VA(LOG_COLORED_FUNCS); } - ABORT_ON_FATAL( selftest_minimal_requirements(), - "Selfcheck" ); - if (getopt_used(OPT_LOGLEVEL)) { value = getopt_str(OPT_LOGLEVEL); if (!strcasecmp(value, "debug")) @@ -335,6 +332,9 @@ int main(int argc, char *argv[]) N("%s (C) 2018 Toni Uhlig <%s>", PACKAGE_STRING, PACKAGE_BUGREPORT); #endif + ABORT_ON_FATAL( selftest_minimal_requirements(), + "Selfcheck" ); + if (geteuid() != 0) { E("%s", "I was made for root!"); exit(EXIT_FAILURE); diff --git a/src/protocol_ssh.c b/src/protocol_ssh.c index eeada5d..2ae0a07 100644 --- a/src/protocol_ssh.c +++ b/src/protocol_ssh.c @@ -202,8 +202,7 @@ static int set_default_keys(ssh_bind sshbind, int rsa_already_set, E_STRERR("RSA key '%s' inaccessible", path); return 1; } - if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, - "./ssh_host_rsa_key")) { + if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_RSAKEY, path)) { E2("Faled to set RSA key: %s", ssh_get_error(sshbind)); return 1; } @@ -215,9 +214,7 @@ static int set_default_keys(ssh_bind sshbind, int rsa_already_set, if (access(path, R_OK)) { W_STRERR("Access DSA key '%s'", path); } else - if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, - "./ssh_host_dsa_key")) - { + if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_DSAKEY, path)) { E2("Failed to set DSA key: %s", ssh_get_error(sshbind)); return 1; } @@ -229,9 +226,7 @@ static int set_default_keys(ssh_bind sshbind, int rsa_already_set, if (access(path, R_OK)) { W_STRERR("Access ECDSA key '%s'", path); } else - if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY, - "./ssh_host_ecdsa_key")) - { + if (ssh_bind_options_set(sshbind, SSH_BIND_OPTIONS_ECDSAKEY, path)) { E2("Failed to set ECDSA key: %s", ssh_get_error(sshbind)); return 1; } diff --git a/src/utils.c b/src/utils.c index d8fc0fe..dc98db7 100644 --- a/src/utils.c +++ b/src/utils.c @@ -482,11 +482,6 @@ int setup_network_namespace(const char *name) } } - if (path_is_mountpoint(netns_path)) { - W2("Network namespace '%s' already mounted, doing nothing.", netns_path); - return 1; - } - while (mount("", getopt_str(OPT_NETNS_RUN_DIR), "none", MS_SHARED|MS_REC, NULL)) { @@ -544,24 +539,30 @@ int switch_network_namespace(const char *name) netns = open(net_path, O_RDONLY | O_CLOEXEC); if (netns < 0) { E_STRERR("Open network namespace '%s'", name); - return 1; + goto error; } if (setns(netns, CLONE_NEWNET) < 0) { E_STRERR("Setting the network namespace '%s'", name); close(netns); -#ifdef HAVE_VALGRIND - /* older valgrind versions dont support the setns syscall */ - if (RUNNING_ON_VALGRIND) { - W2("%s", "Running on valgrind, using unshare instead of setns .."); - return unshare(CLONE_NEWNET) != 0; - } -#endif - return 1; + goto error; } close(netns); return 0; +error: +#ifdef HAVE_VALGRIND + /* + * Older valgrind versions dont support the setns syscall + * or the open might fail with ENOENT. + */ + if (RUNNING_ON_VALGRIND) { + W2("%s", "Running on valgrind, using unshare instead of setns and " + "ignoring erros before .."); + return unshare(CLONE_NEWNET) != 0; + } +#endif + return 1; } int create_device_file_checked(const char *mount_path, const char *device_file, -- cgit v1.2.3