From: Michael Roth <michael.roth@amd.com>
To: qemu-devel@nongnu.org
Cc: "Michal Privoznik" <mprivozn@redhat.com>,
peter.maydell@linaro.org,
"Marc-André Lureau" <marcandre.lureau@redhat.com>
Subject: [PULL v2 08/12] glib-compat: add g_unix_get_passwd_entry_qemu()
Date: Mon, 2 Nov 2020 19:11:30 -0600 [thread overview]
Message-ID: <20201103011134.887744-9-michael.roth@amd.com> (raw)
In-Reply-To: <20201103011134.887744-1-michael.roth@amd.com>
From: Marc-André Lureau <marcandre.lureau@redhat.com>
The glib function was introduced in 2.64. It's a safer version of
getpwnam, and also simpler to use than getpwnam_r.
Currently, it's only use by the next patch in qemu-ga, which doesn't
(well well...) need the thread safety guarantees. Since the fallback
version is still unsafe, I would rather keep the _qemu postfix, to make
sure it's not being misused by mistake. When/if necessary, we can
implement a safer fallback and drop the _qemu suffix.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Michael Roth <michael.roth@amd.com>
---
include/glib-compat.h | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
diff --git a/include/glib-compat.h b/include/glib-compat.h
index 0b0ec76299..64e68aa730 100644
--- a/include/glib-compat.h
+++ b/include/glib-compat.h
@@ -30,6 +30,11 @@
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <glib.h>
+#if defined(G_OS_UNIX)
+#include <glib-unix.h>
+#include <sys/types.h>
+#include <pwd.h>
+#endif
/*
* Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing
@@ -72,6 +77,27 @@
gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout);
#endif
+#if defined(G_OS_UNIX)
+/* Note: The fallback implementation is not MT-safe, and it returns a copy of
+ * the libc passwd (must be g_free() after use) but not the content. Because of
+ * these important differences the caller must be aware of, it's not #define for
+ * GLib API substitution. */
+static inline struct passwd *
+g_unix_get_passwd_entry_qemu(const gchar *user_name, GError **error)
+{
+#if GLIB_CHECK_VERSION(2, 64, 0)
+ return g_unix_get_passwd_entry(user_name, error);
+#else
+ struct passwd *p = getpwnam(user_name);
+ if (!p) {
+ g_set_error_literal(error, G_UNIX_ERROR, 0, g_strerror(errno));
+ return NULL;
+ }
+ return (struct passwd *)g_memdup(p, sizeof(*p));
+#endif
+}
+#endif /* G_OS_UNIX */
+
#pragma GCC diagnostic pop
#endif
--
2.25.1
next prev parent reply other threads:[~2020-11-03 1:22 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-03 1:11 [PULL v2 00/12] qemu-ga patch queue for soft-freeze Michael Roth
2020-11-03 1:11 ` [PULL v2 01/12] qga: Rename guest-get-devices return member 'address' to 'id' Michael Roth
2020-11-03 1:11 ` [PULL v2 02/12] qga: Use common time encoding for guest-get-devices 'driver-date' Michael Roth
2020-11-03 1:11 ` [PULL v2 03/12] qga-win: Fix guest-get-devices error API violations Michael Roth
2020-11-03 1:11 ` [PULL v2 04/12] qga: Flatten simple union GuestDeviceId Michael Roth
2020-11-03 1:11 ` [PULL v2 05/12] qga: add command guest-get-disks Michael Roth
2020-11-03 1:11 ` [PULL v2 06/12] qga: add implementation of guest-get-disks for Linux Michael Roth
2020-11-03 1:11 ` [PULL v2 07/12] qga: add implementation of guest-get-disks for Windows Michael Roth
2020-11-03 1:11 ` Michael Roth [this message]
2020-11-03 1:11 ` [PULL v2 09/12] qga: add ssh-{add,remove}-authorized-keys Michael Roth
2020-11-03 1:11 ` [PULL v2 10/12] qga: add *reset argument to ssh-add-authorized-keys Michael Roth
2020-11-03 1:11 ` [PULL v2 11/12] meson: minor simplification Michael Roth
2020-11-03 1:11 ` [PULL v2 12/12] qga: add ssh-get-authorized-keys Michael Roth
2020-11-03 1:39 ` [PULL v2 00/12] qemu-ga patch queue for soft-freeze no-reply
2020-11-03 2:37 ` Michael Roth
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=20201103011134.887744-9-michael.roth@amd.com \
--to=michael.roth@amd.com \
--cc=marcandre.lureau@redhat.com \
--cc=mprivozn@redhat.com \
--cc=peter.maydell@linaro.org \
--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).