From: marcandre.lureau@redhat.com
To: qemu-devel@nongnu.org
Cc: berrange@redhat.com, "Michael Roth" <mdroth@linux.vnet.ibm.com>,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PATCH v3 3/7] fixup! qga: add ssh-{add,remove}-authorized-keys
Date: Tue, 20 Oct 2020 12:12:53 +0400 [thread overview]
Message-ID: <20201020081257.2054548-4-marcandre.lureau@redhat.com> (raw)
In-Reply-To: <20201020081257.2054548-1-marcandre.lureau@redhat.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
I forgot to reset the file ownership after it is written.
---
qga/commands-posix-ssh.c | 13 ++++++++++---
1 file changed, 10 insertions(+), 3 deletions(-)
diff --git a/qga/commands-posix-ssh.c b/qga/commands-posix-ssh.c
index d41c114c3c..a7bc9a1c24 100644
--- a/qga/commands-posix-ssh.c
+++ b/qga/commands-posix-ssh.c
@@ -120,7 +120,8 @@ check_openssh_pub_keys(strList *keys, size_t *nkeys, Error **errp)
}
static bool
-write_authkeys(const char *path, const GStrv keys, Error **errp)
+write_authkeys(const char *path, const GStrv keys,
+ const struct passwd *p, Error **errp)
{
g_autofree char *contents = NULL;
g_autoptr(GError) err = NULL;
@@ -133,6 +134,12 @@ write_authkeys(const char *path, const GStrv keys, Error **errp)
return false;
}
+ if (chown(path, p->pw_uid, p->pw_gid) == -1) {
+ error_setg(errp, "failed to set ownership of directory '%s': %s",
+ path, g_strerror(errno));
+ return false;
+ }
+
if (chmod(path, 0600) == -1) {
error_setg(errp, "failed to set permissions of '%s': %s",
path, g_strerror(errno));
@@ -203,7 +210,7 @@ qmp_guest_ssh_add_authorized_keys(const char *username, strList *keys,
authkeys[nauthkeys++] = g_strdup(k->value);
}
- write_authkeys(authkeys_path, authkeys, errp);
+ write_authkeys(authkeys_path, authkeys, p, errp);
}
void
@@ -254,7 +261,7 @@ qmp_guest_ssh_remove_authorized_keys(const char *username, strList *keys,
new_keys[nkeys++] = *a;
}
- write_authkeys(authkeys_path, new_keys, errp);
+ write_authkeys(authkeys_path, new_keys, p, errp);
}
--
2.28.0
next prev parent reply other threads:[~2020-10-20 8:17 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-10-20 8:12 [PATCH v3 0/7] qemu-ga: add ssh-{get,add,remove}-authorized-keys marcandre.lureau
2020-10-20 8:12 ` [PATCH v3 1/7] glib-compat: add g_unix_get_passwd_entry_qemu() marcandre.lureau
2020-10-20 8:12 ` [PATCH v3 2/7] qga: add ssh-{add,remove}-authorized-keys marcandre.lureau
2020-10-20 8:12 ` marcandre.lureau [this message]
2020-10-20 8:12 ` [PATCH v3 4/7] fixup! " marcandre.lureau
2020-10-20 8:12 ` [PATCH v3 5/7] qga: add *reset argument to ssh-add-authorized-keys marcandre.lureau
2020-10-20 8:12 ` [PATCH v3 6/7] meson: minor simplification marcandre.lureau
2020-10-20 8:12 ` [PATCH v3 7/7] qga: add ssh-get-authorized-keys marcandre.lureau
2020-10-20 8:24 ` [PATCH v3 0/7] qemu-ga: add ssh-{get,add,remove}-authorized-keys no-reply
2020-10-26 17:10 ` Marc-André Lureau
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=20201020081257.2054548-4-marcandre.lureau@redhat.com \
--to=marcandre.lureau@redhat.com \
--cc=berrange@redhat.com \
--cc=mdroth@linux.vnet.ibm.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).