|
|
6e7d01 |
From 15331267d11713906361ddd767c3e04ae46d9a83 Mon Sep 17 00:00:00 2001
|
|
|
6e7d01 |
From: =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= <marcandre.lureau@redhat.com>
|
|
|
6e7d01 |
Date: Thu, 29 Jul 2021 04:55:50 -0400
|
|
|
6e7d01 |
Subject: [PATCH 01/14] glib-compat: add g_unix_get_passwd_entry_qemu()
|
|
|
6e7d01 |
MIME-Version: 1.0
|
|
|
6e7d01 |
Content-Type: text/plain; charset=UTF-8
|
|
|
6e7d01 |
Content-Transfer-Encoding: 8bit
|
|
|
6e7d01 |
|
|
|
6e7d01 |
RH-Author: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
6e7d01 |
Message-id: <20210609100615.2501448-2-marcandre.lureau@redhat.com>
|
|
|
6e7d01 |
Patchwork-id: 101687
|
|
|
6e7d01 |
O-Subject: [RHEL-8.5.0 qemu-kvm PATCH 1/4] glib-compat: add g_unix_get_passwd_entry_qemu()
|
|
|
6e7d01 |
Bugzilla: 1967716
|
|
|
6e7d01 |
RH-Acked-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
6e7d01 |
RH-Acked-by: Philippe Mathieu-Daudé <philmd@redhat.com>
|
|
|
6e7d01 |
RH-Acked-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
6e7d01 |
|
|
|
6e7d01 |
From: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
6e7d01 |
|
|
|
6e7d01 |
The glib function was introduced in 2.64. It's a safer version of
|
|
|
6e7d01 |
getpwnam, and also simpler to use than getpwnam_r.
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Currently, it's only use by the next patch in qemu-ga, which doesn't
|
|
|
6e7d01 |
(well well...) need the thread safety guarantees. Since the fallback
|
|
|
6e7d01 |
version is still unsafe, I would rather keep the _qemu postfix, to make
|
|
|
6e7d01 |
sure it's not being misused by mistake. When/if necessary, we can
|
|
|
6e7d01 |
implement a safer fallback and drop the _qemu suffix.
|
|
|
6e7d01 |
|
|
|
6e7d01 |
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
6e7d01 |
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
|
|
|
6e7d01 |
*fix checkpatch warnings about newlines before/after block comments
|
|
|
6e7d01 |
Signed-off-by: Michael Roth <michael.roth@amd.com>
|
|
|
6e7d01 |
|
|
|
6e7d01 |
(cherry picked from commit 6d593ab451c490b0ca941c6a519894231634751e)
|
|
|
6e7d01 |
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
|
|
|
6e7d01 |
Signed-off-by: Miroslav Rezanina <mrezanin@redhat.com>
|
|
|
6e7d01 |
---
|
|
|
6e7d01 |
include/glib-compat.h | 28 ++++++++++++++++++++++++++++
|
|
|
6e7d01 |
1 file changed, 28 insertions(+)
|
|
|
6e7d01 |
|
|
|
6e7d01 |
diff --git a/include/glib-compat.h b/include/glib-compat.h
|
|
|
6e7d01 |
index 0b0ec76299..695a96f7ea 100644
|
|
|
6e7d01 |
--- a/include/glib-compat.h
|
|
|
6e7d01 |
+++ b/include/glib-compat.h
|
|
|
6e7d01 |
@@ -30,6 +30,11 @@
|
|
|
6e7d01 |
#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
|
|
6e7d01 |
|
|
|
6e7d01 |
#include <glib.h>
|
|
|
6e7d01 |
+#if defined(G_OS_UNIX)
|
|
|
6e7d01 |
+#include <glib-unix.h>
|
|
|
6e7d01 |
+#include <sys/types.h>
|
|
|
6e7d01 |
+#include <pwd.h>
|
|
|
6e7d01 |
+#endif
|
|
|
6e7d01 |
|
|
|
6e7d01 |
/*
|
|
|
6e7d01 |
* Note that because of the GLIB_VERSION_MAX_ALLOWED constant above, allowing
|
|
|
6e7d01 |
@@ -72,6 +77,29 @@
|
|
|
6e7d01 |
gint g_poll_fixed(GPollFD *fds, guint nfds, gint timeout);
|
|
|
6e7d01 |
#endif
|
|
|
6e7d01 |
|
|
|
6e7d01 |
+#if defined(G_OS_UNIX)
|
|
|
6e7d01 |
+/*
|
|
|
6e7d01 |
+ * Note: The fallback implementation is not MT-safe, and it returns a copy of
|
|
|
6e7d01 |
+ * the libc passwd (must be g_free() after use) but not the content. Because of
|
|
|
6e7d01 |
+ * these important differences the caller must be aware of, it's not #define for
|
|
|
6e7d01 |
+ * GLib API substitution.
|
|
|
6e7d01 |
+ */
|
|
|
6e7d01 |
+static inline struct passwd *
|
|
|
6e7d01 |
+g_unix_get_passwd_entry_qemu(const gchar *user_name, GError **error)
|
|
|
6e7d01 |
+{
|
|
|
6e7d01 |
+#if GLIB_CHECK_VERSION(2, 64, 0)
|
|
|
6e7d01 |
+ return g_unix_get_passwd_entry(user_name, error);
|
|
|
6e7d01 |
+#else
|
|
|
6e7d01 |
+ struct passwd *p = getpwnam(user_name);
|
|
|
6e7d01 |
+ if (!p) {
|
|
|
6e7d01 |
+ g_set_error_literal(error, G_UNIX_ERROR, 0, g_strerror(errno));
|
|
|
6e7d01 |
+ return NULL;
|
|
|
6e7d01 |
+ }
|
|
|
6e7d01 |
+ return (struct passwd *)g_memdup(p, sizeof(*p));
|
|
|
6e7d01 |
+#endif
|
|
|
6e7d01 |
+}
|
|
|
6e7d01 |
+#endif /* G_OS_UNIX */
|
|
|
6e7d01 |
+
|
|
|
6e7d01 |
#pragma GCC diagnostic pop
|
|
|
6e7d01 |
|
|
|
6e7d01 |
#endif
|
|
|
6e7d01 |
--
|
|
|
6e7d01 |
2.27.0
|
|
|
6e7d01 |
|