From: Konstantin Kostiuk <kkostiuk@redhat.com>
To: aidan_leuck@selinc.com
Cc: qemu-devel@nongnu.org
Subject: Re: [PATCH v8 1/2] Refactor common functions between POSIX and Windows implementation
Date: Wed, 24 Apr 2024 12:28:02 +0300 [thread overview]
Message-ID: <CAPMcbCoGTfd__9RUJXxWbT5Hz64KBTtpQLBz1xaTwx9Gyb-1sw@mail.gmail.com> (raw)
In-Reply-To: <20240423150005.48175-2-aidan_leuck@selinc.com>
[-- Attachment #1: Type: text/plain, Size: 5204 bytes --]
On Tue, Apr 23, 2024 at 6:01 PM <aidan_leuck@selinc.com> wrote:
> From: aidaleuc <aidan_leuck@selinc.com>
>
> Signed-off-by: aidaleuc <aidan_leuck@selinc.com>
>
Please resend with the real name in Signed-off-by
Assuming this changes:
Reviewed-by: Konstantin Kostiuk <kkostiuk@redhat.com>
> ---
> qga/commands-common-ssh.c | 50 +++++++++++++++++++++++++++++++++++++++
> qga/commands-common-ssh.h | 10 ++++++++
> qga/commands-posix-ssh.c | 47 +-----------------------------------
> qga/meson.build | 1 +
> 4 files changed, 62 insertions(+), 46 deletions(-)
> create mode 100644 qga/commands-common-ssh.c
> create mode 100644 qga/commands-common-ssh.h
>
> diff --git a/qga/commands-common-ssh.c b/qga/commands-common-ssh.c
> new file mode 100644
> index 0000000000..537869fb98
> --- /dev/null
> +++ b/qga/commands-common-ssh.c
> @@ -0,0 +1,50 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qemu/osdep.h"
> +#include "qapi/error.h"
> +#include "commands-common-ssh.h"
> +
> +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);
> +}
> +
> +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;
> +}
> +
> +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;
> +}
> diff --git a/qga/commands-common-ssh.h b/qga/commands-common-ssh.h
> new file mode 100644
> index 0000000000..14d955fa84
> --- /dev/null
> +++ b/qga/commands-common-ssh.h
> @@ -0,0 +1,10 @@
> +/*
> + * This work is licensed under the terms of the GNU GPL, version 2 or
> later.
> + * See the COPYING file in the top-level directory.
> + */
> +
> +#include "qapi/qapi-builtin-types.h"
> +
> +GStrv read_authkeys(const char *path, Error **errp);
> +bool check_openssh_pub_keys(strList *keys, size_t *nkeys, Error **errp);
> +bool check_openssh_pub_key(const char *key, Error **errp);
> diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c
> index 236f80de44..dd2ecb453a 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"
>
> @@ -80,37 +81,6 @@ mkdir_for_user(const char *path, const struct passwd *p,
> return true;
> }
>
> -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,
> diff --git a/qga/meson.build b/qga/meson.build
> index 1c3d2a3d1b..4c3899751b 100644
> --- a/qga/meson.build
> +++ b/qga/meson.build
> @@ -66,6 +66,7 @@ qga_ss.add(files(
> 'guest-agent-command-state.c',
> 'main.c',
> 'cutils.c',
> + 'commands-common-ssh.c'
> ))
> if host_os == 'windows'
> qga_ss.add(files(
> --
> 2.34.1
>
>
[-- Attachment #2: Type: text/html, Size: 6705 bytes --]
next prev parent reply other threads:[~2024-04-24 9:28 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-23 15:00 [PATCH v8 0/2] Implement SSH commands in QEMU GA for Windows aidan_leuck
2024-04-23 15:00 ` [PATCH v8 1/2] Refactor common functions between POSIX and Windows implementation aidan_leuck
2024-04-24 9:28 ` Konstantin Kostiuk [this message]
2024-04-23 15:00 ` [PATCH v8 2/2] Implement SSH commands in QEMU GA for Windows aidan_leuck
2024-04-24 8:55 ` Dehan Meng
2024-04-24 9:21 ` Dehan Meng
2024-04-24 9:27 ` Konstantin Kostiuk
2024-04-24 14:30 ` Aidan Leuck
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAPMcbCoGTfd__9RUJXxWbT5Hz64KBTtpQLBz1xaTwx9Gyb-1sw@mail.gmail.com \
--to=kkostiuk@redhat.com \
--cc=aidan_leuck@selinc.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).