[gnome-system-tools] Work around adduser limitation when main group already exists



commit 9bbe17cbabf8f05fa05e03e4c13d7f9c81a6f4bd
Author: Milan Bouchet-Valat <nalimilan club fr>
Date:   Mon Mar 8 22:12:47 2010 +0100

    Work around adduser limitation when main group already exists
    
    Hack to avoid failing silently in the backends when a group named as the new user already exists.

 src/users/user-settings.c |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
---
diff --git a/src/users/user-settings.c b/src/users/user-settings.c
index dd06c91..aa21210 100644
--- a/src/users/user-settings.c
+++ b/src/users/user-settings.c
@@ -929,9 +929,11 @@ on_user_new (GtkButton *button, gpointer user_data)
 	GtkTreeModel *model;
 	GtkTreePath *user_path;
 	OobsUser *user;
+	OobsGroup *main_group;
 	const char *fullname, *login;
 	GstUserProfile *profile;
 	OobsUsersConfig *users_config;
+	OobsGroupsConfig *groups_config;
 	OobsResult result;
 	gboolean encrypt;
 
@@ -947,6 +949,7 @@ on_user_new (GtkButton *button, gpointer user_data)
 	encrypted_home = gst_dialog_get_widget (tool->main_dialog, "user_new_encrypted_home");
 
 	users_config = OOBS_USERS_CONFIG (GST_USERS_TOOL (tool)->users_config);
+	groups_config = OOBS_GROUPS_CONFIG (GST_USERS_TOOL (tool)->groups_config);
 
 	/* clear any text, colors or icon left */
 	gtk_entry_set_text (GTK_ENTRY (user_name), "");
@@ -985,6 +988,15 @@ on_user_new (GtkButton *button, gpointer user_data)
 	oobs_user_set_encrypted_home (user, encrypt);
 	oobs_user_set_home_flags (user, OOBS_USER_CHOWN_HOME);
 
+	/* If the user group already exists and /etc/adduser.conf USERGROUPS option is yes,
+	 * then adduser will fail, and the backends don't allow reporting that error.
+	 * So assume we want the user to be in that group. */
+	main_group = oobs_groups_config_get_from_name (groups_config, login);
+	if (main_group) {
+		oobs_user_set_main_group (user, main_group);
+		g_object_unref (main_group);
+	}
+
 	g_return_if_fail (user != NULL);
 
 	/* fill settings with values from default profile */



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