Merge tag 'pull-maintainer-july24-050724-1' of https://gitlab.com/stsquad/qemu into...
[qemu/ar7.git] / qga / commands-common-ssh.c
blob537869fb98ba58ac7259b8a5457f0480c6a661f8
1 /*
2 * This work is licensed under the terms of the GNU GPL, version 2 or later.
3 * See the COPYING file in the top-level directory.
4 */
6 #include "qemu/osdep.h"
7 #include "qapi/error.h"
8 #include "commands-common-ssh.h"
10 GStrv read_authkeys(const char *path, Error **errp)
12 g_autoptr(GError) err = NULL;
13 g_autofree char *contents = NULL;
15 if (!g_file_get_contents(path, &contents, NULL, &err)) {
16 error_setg(errp, "failed to read '%s': %s", path, err->message);
17 return NULL;
20 return g_strsplit(contents, "\n", -1);
23 bool check_openssh_pub_keys(strList *keys, size_t *nkeys, Error **errp)
25 size_t n = 0;
26 strList *k;
28 for (k = keys; k != NULL; k = k->next) {
29 if (!check_openssh_pub_key(k->value, errp)) {
30 return false;
32 n++;
35 if (nkeys) {
36 *nkeys = n;
38 return true;
41 bool check_openssh_pub_key(const char *key, Error **errp)
43 /* simple sanity-check, we may want more? */
44 if (!key || key[0] == '#' || strchr(key, '\n')) {
45 error_setg(errp, "invalid OpenSSH public key: '%s'", key);
46 return false;
49 return true;