[gnome-control-center/wip/lantw/fix-user-panel-problem-on-freebsd: 56/57] user-accounts: Use 'pw usershow' to check username validity on FreeBSD
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/wip/lantw/fix-user-panel-problem-on-freebsd: 56/57] user-accounts: Use 'pw usershow' to check username validity on FreeBSD
- Date: Tue, 10 Sep 2019 23:33:20 +0000 (UTC)
commit 564aa72b5ea79fca7c06db4bc1f0800776e71f75
Author: Ting-Wei Lan <lantw src gnome org>
Date: Thu Aug 29 11:59:55 2019 +0800
user-accounts: Use 'pw usershow' to check username validity on FreeBSD
FreeBSD has no standalone 'usermod' command. Most user and group
management functions are provided as subcommands of 'pw' tool.
panels/user-accounts/user-utils.c | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
---
diff --git a/panels/user-accounts/user-utils.c b/panels/user-accounts/user-utils.c
index 72401e40b..ce1815cc3 100644
--- a/panels/user-accounts/user-utils.c
+++ b/panels/user-accounts/user-utils.c
@@ -29,6 +29,10 @@
#include <utmpx.h>
#include <pwd.h>
+#ifdef __FreeBSD__
+#include <sysexits.h>
+#endif
+
#include <gio/gio.h>
#include <gio/gunixoutputstream.h>
#include <glib/gi18n.h>
@@ -403,10 +407,17 @@ is_valid_username_data_free (isValidUsernameData *data)
g_free (data);
}
+#ifdef __FreeBSD__
+/* Taken from pw(8) man page. */
+#define E_SUCCESS EX_OK
+#define E_BAD_ARG EX_DATAERR
+#define E_NOTFOUND EX_NOUSER
+#else
/* Taken from usermod.c in shadow-utils. */
#define E_SUCCESS 0
#define E_BAD_ARG 3
#define E_NOTFOUND 6
+#endif
static void
is_valid_username_child_watch_cb (GPid pid,
@@ -481,6 +492,17 @@ is_valid_username_async (const gchar *username,
return;
}
+#ifdef __FreeBSD__
+ /* Abuse "pw usershow -n <name>" in the same way as the code below. We
+ * don't use "pw usermod -n <name> -N -l <newname>" here because it has
+ * a special case for "root" to reject changes to the root user.
+ */
+ argv[0] = "pw";
+ argv[1] = "usershow";
+ argv[2] = "-n";
+ argv[3] = data->username;
+ argv[4] = NULL;
+#else
/* "usermod --login" is meant to be used to change a username, but the
* exit codes can be safely abused to check the validity of username.
* However, the current "usermod" implementation may change in the
@@ -493,6 +515,7 @@ is_valid_username_async (const gchar *username,
argv[3] = "--";
argv[4] = data->username;
argv[5] = NULL;
+#endif
if (!g_spawn_async (NULL, argv, NULL,
G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD |
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]