diff options
author | aidaleuc <aidan_leuck@selinc.com> | 2024-04-24 08:40:28 -0600 |
---|---|---|
committer | Konstantin Kostiuk <kkostiuk@redhat.com> | 2024-05-01 10:35:45 +0300 |
commit | 1cc9932700339042e83c6c54114734231630548c (patch) | |
tree | 3fd3260136b40adae458ca589b354fedf37ae67f /qga/commands-posix-ssh.c | |
parent | 0e5b75a3902f2325cbdb07954e2c2ca2f7fcb9dd (diff) | |
download | qemu-1cc9932700339042e83c6c54114734231630548c.zip qemu-1cc9932700339042e83c6c54114734231630548c.tar.gz qemu-1cc9932700339042e83c6c54114734231630548c.tar.bz2 |
qga: Refactor common SSH functions
Message-Id: <20240424144029.30665-2-aidan_leuck@selinc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: 8bit
In preparation of a Windows implementation, move the
non-POSIX specific code to commands-common-ssh.
Signed-off-by: Aidan Leuck <aidan_leuck@selinc.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Tested-by: Dehan Meng <demeng@redhat.com>
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Link: https://lore.kernel.org/r/20240424144029.30665-2-aidan_leuck@selinc.com
Signed-off-by: Konstantin Kostiuk <kkostiuk@redhat.com>
Diffstat (limited to 'qga/commands-posix-ssh.c')
-rw-r--r-- | qga/commands-posix-ssh.c | 47 |
1 files changed, 1 insertions, 46 deletions
diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c index 236f80d..dd2ecb4 100644 --- a/qga/commands-posix-ssh.c +++ b/qga/commands-posix-ssh.c @@ -9,6 +9,7 @@ #include <locale.h> #include <pwd.h> +#include "commands-common-ssh.h" #include "qapi/error.h" #include "qga-qapi-commands.h" @@ -81,37 +82,6 @@ mkdir_for_user(const char *path, const struct passwd *p, } static bool -check_openssh_pub_key(const char *key, Error **errp) -{ - /* simple sanity-check, we may want more? */ - if (!key || key[0] == '#' || strchr(key, '\n')) { - error_setg(errp, "invalid OpenSSH public key: '%s'", key); - return false; - } - - return true; -} - -static bool -check_openssh_pub_keys(strList *keys, size_t *nkeys, Error **errp) -{ - size_t n = 0; - strList *k; - - for (k = keys; k != NULL; k = k->next) { - if (!check_openssh_pub_key(k->value, errp)) { - return false; - } - n++; - } - - if (nkeys) { - *nkeys = n; - } - return true; -} - -static bool write_authkeys(const char *path, const GStrv keys, const struct passwd *p, Error **errp) { @@ -139,21 +109,6 @@ write_authkeys(const char *path, const GStrv keys, return true; } -static GStrv -read_authkeys(const char *path, Error **errp) -{ - g_autoptr(GError) err = NULL; - g_autofree char *contents = NULL; - - if (!g_file_get_contents(path, &contents, NULL, &err)) { - error_setg(errp, "failed to read '%s': %s", path, err->message); - return NULL; - } - - return g_strsplit(contents, "\n", -1); - -} - void qmp_guest_ssh_add_authorized_keys(const char *username, strList *keys, bool has_reset, bool reset, |