[gnome-system-tools/gnome-2-28: 7/8] Check that UID is free before creating users



commit 36cdbf80fa16cfac1a15f24ee32c2b272f68e521
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Mon Aug 31 18:05:54 2009 +0200

    Check that UID is free before creating users
    
    This led to silent failures from adduser in the backends. The main groups was created using a valid ID, but not the user. See https://bugs.launchpad.net/ubuntu/+source/gnome-system-tools/+bug/99276.

 src/users/user-settings.c |   33 +++++++++++++++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
---
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index 92c1b3f..d6740c3 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -309,6 +309,34 @@ is_user_root (OobsUser *user)
 	return (strcmp (login, "root") == 0);
 }
 
+static gboolean
+uid_exists (uid_t uid)
+{
+	OobsUsersConfig *config;
+	OobsList *list;
+	OobsListIter list_iter;
+	GObject *user;
+	gboolean valid;
+	uid_t user_uid;
+
+	config = OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config);
+	list = oobs_users_config_get_users (config);
+	valid = oobs_list_get_iter_first (list, &list_iter);
+
+	while (valid) {
+		user = oobs_list_get (list, &list_iter);
+		uid = oobs_user_get_uid (OOBS_USER (user));
+		g_object_unref (user);
+
+		if (user_uid == uid)
+			return TRUE;
+
+		valid = oobs_list_iter_next (list, &list_iter);
+	}
+
+	return FALSE;
+}
+
 static uid_t
 find_new_uid (gint uid_min,
 	      gint uid_max)
@@ -659,6 +687,11 @@ check_uid (gchar **primary_text, gchar **secondary_text, gpointer data)
 		*primary_text   = g_strdup (_("Administrator account's user ID should not be modified"));
 		*secondary_text = g_strdup (_("This would leave the system unusable."));
 	}
+
+	if (!user && uid_exists (uid)) {
+		*primary_text   = g_strdup_printf (_("User ID %d is already used"), uid);
+		*secondary_text = g_strdup (_("Please choose a different numeric identifier for the new user."));
+	}
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]