Re: [system-tools] Allowing password-less connexions



Here's a first version of a patch. Are you using Glade 2? There are so
many differences only adding a single checkbox, I guess this may be
because I saved the file with Glade 3. So I don't post this file here,
I'll try again with the version 2 if you confirm.

I had to move find_group_in_profile from privileges-table.c to
user-profiles.c in order to avoid code duplication. If this is a problem
I can simply copy 6 lines of code inline and revert this.

Another point is oobs_group_new (): is this function creating a new
OobsGroup referring to an already existing *system* group, or is it mean
to create a new system group? (see what I did in the code)

Attached is the same diff, if you prefer. Questions, comments and
criticisms are welcome!

Cheers



gnome-system-tools/src/users$ svn diff .
Index: privileges-table.c
===================================================================
--- privileges-table.c	(révision 4234)
+++ privileges-table.c	(copie de travail)
@@ -219,29 +219,6 @@
 	}
 }
 
-static gboolean
-find_group_in_profile (OobsGroup      *group,
-		       GstUserProfile *profile)
-{
-	gchar **groups;
-	const gchar *name;
-
-	if (!profile->groups)
-		return FALSE;
-
-	groups = profile->groups;
-	name = oobs_group_get_name (group);
-
-	while (*groups) {
-		if (strcmp (*groups, name) == 0)
-			return TRUE;
-
-		groups++;
-	}
-
-	return FALSE;
-}
-
 void
 privileges_table_set_from_profile (GstUserProfile *profile)
 {
@@ -262,7 +239,7 @@
 				    -1);
 
 		gtk_list_store_set (GTK_LIST_STORE (child_model), &iter,
-				    COL_MEMBER, find_group_in_profile (group, profile),
+				    COL_MEMBER, gst_user_profiles_find_group (group, profile),
 				    -1);
 
 		valid = gtk_tree_model_iter_next (child_model, &iter);
Index: user-profiles.c
===================================================================
--- user-profiles.c	(révision 4234)
+++ user-profiles.c	(copie de travail)
@@ -202,3 +202,26 @@
 
 	return priv->default_profile;
 }
+
+gboolean
+gst_user_profiles_find_group (OobsGroup      *group,
+		              GstUserProfile *profile)
+{
+	gchar **groups;
+	const gchar *name;
+
+	if (!profile->groups)
+		return FALSE;
+
+	groups = profile->groups;
+	name = oobs_group_get_name (group);
+
+	while (*groups) {
+		if (strcmp (*groups, name) == 0)
+			return TRUE;
+
+		groups++;
+	}
+
+	return FALSE;
+}
Index: user-profiles.h
===================================================================
--- user-profiles.h	(révision 4234)
+++ user-profiles.h	(copie de travail)
@@ -68,6 +68,8 @@
 						const gchar     *profile);
 GstUserProfile*  gst_user_profiles_get_current (GstUserProfiles
*profiles);
 GstUserProfile*  gst_user_profiles_get_default_profile (GstUserProfiles
*profiles);
+gboolean         gst_user_profiles_find_group (OobsGroup        *group,
+		                                       GstUserProfile   *profile);
 
 
 G_END_DECLS
Index: user-settings.c
===================================================================
--- user-settings.c	(révision 4234)
+++ user-settings.c	(copie de travail)
@@ -312,9 +312,11 @@
 user_settings_dialog_new (OobsUser *user)
 {
 	OobsUsersConfig *config;
+	OobsGroup passwdless_group;
 	GtkWidget *dialog, *widget;
 	const gchar *login = NULL;
 	gchar *title;
+	gchar *passwdless_group_name;
 	gint uid;
 
 	dialog = gst_dialog_get_widget (tool->main_dialog,
"user_settings_dialog");
@@ -389,6 +391,18 @@
 	widget = gst_dialog_get_widget (tool->main_dialog,
"user_passwd_manual");
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
 
+	/* set password-less login */
+	if (gstconf_get_bool (users, "passwordless_allowed")) {
+		widget = gst_dialog_get_widget (tool->main_dialog,
"user_passwd_passwordless");
+		gtk_widget_set_sensitive (widget, TRUE);
+		passwdless_group_name = gstconf_get_string (users,
"passwordless_group_name");
+		if (!passwdless_group_name)
+			passwdless_group_name = "passwordless";
+		passwdless_group = oobs_group_new (passwdless_group_name);
+		if (gst_profile_find_group (passwdless_group, user)
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), TRUE);
+	}
+
 	if (!login)
 		table_set_default_profile (GST_USERS_TOOL (tool));
 
@@ -638,8 +652,10 @@
 {
 	GtkWidget *widget;
 	OobsGroup *group;
+	OobsGroup *passwdless_group;
 	OobsUser *user;
 	const gchar *str;
+	gchar *passwdless_group_name;
 	gboolean password_changed;
 
 	widget = gst_dialog_get_widget (tool->main_dialog,
"user_settings_name");
@@ -690,6 +706,18 @@
 		oobs_user_set_password (user, gtk_entry_get_text (GTK_ENTRY
(widget)));
 	}
 
+	/* allowed to login without password? */
+	widget = gst_dialog_get_widget (tool->main_dialog,
"user_passwd_passwordless");
+	passwdless_group_name = gstconf_get_string (users,
"passwordless_group_name");
+	if (!passwdless_group_name)
+		passwdless_group_name = "passwordless";
+	passwdless_group = oobs_group_new (passwdless_group_name);
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
+		oobs_group_add_user (passwdless_group, user);
+	else
+		oobs_group_remove_user (passwdless_group, user);
+	}
+
 	group = get_main_group (oobs_user_get_login_name (user));
 	oobs_user_set_main_group (user, group);
 	g_object_unref (group);


gnome-system-tools/src/users$ svn diff .
Index: privileges-table.c
===================================================================
--- privileges-table.c	(révision 4234)
+++ privileges-table.c	(copie de travail)
@@ -219,29 +219,6 @@
 	}
 }
 
-static gboolean
-find_group_in_profile (OobsGroup      *group,
-		       GstUserProfile *profile)
-{
-	gchar **groups;
-	const gchar *name;
-
-	if (!profile->groups)
-		return FALSE;
-
-	groups = profile->groups;
-	name = oobs_group_get_name (group);
-
-	while (*groups) {
-		if (strcmp (*groups, name) == 0)
-			return TRUE;
-
-		groups++;
-	}
-
-	return FALSE;
-}
-
 void
 privileges_table_set_from_profile (GstUserProfile *profile)
 {
@@ -262,7 +239,7 @@
 				    -1);
 
 		gtk_list_store_set (GTK_LIST_STORE (child_model), &iter,
-				    COL_MEMBER, find_group_in_profile (group, profile),
+				    COL_MEMBER, gst_user_profiles_find_group (group, profile),
 				    -1);
 
 		valid = gtk_tree_model_iter_next (child_model, &iter);
Index: user-profiles.c
===================================================================
--- user-profiles.c	(révision 4234)
+++ user-profiles.c	(copie de travail)
@@ -202,3 +202,26 @@
 
 	return priv->default_profile;
 }
+
+gboolean
+gst_user_profiles_find_group (OobsGroup      *group,
+		              GstUserProfile *profile)
+{
+	gchar **groups;
+	const gchar *name;
+
+	if (!profile->groups)
+		return FALSE;
+
+	groups = profile->groups;
+	name = oobs_group_get_name (group);
+
+	while (*groups) {
+		if (strcmp (*groups, name) == 0)
+			return TRUE;
+
+		groups++;
+	}
+
+	return FALSE;
+}
Index: user-profiles.h
===================================================================
--- user-profiles.h	(révision 4234)
+++ user-profiles.h	(copie de travail)
@@ -68,6 +68,8 @@
 						const gchar     *profile);
 GstUserProfile*  gst_user_profiles_get_current (GstUserProfiles *profiles);
 GstUserProfile*  gst_user_profiles_get_default_profile (GstUserProfiles *profiles);
+gboolean         gst_user_profiles_find_group (OobsGroup        *group,
+		                                       GstUserProfile   *profile);
 
 
 G_END_DECLS
Index: user-settings.c
===================================================================
--- user-settings.c	(révision 4234)
+++ user-settings.c	(copie de travail)
@@ -312,9 +312,11 @@
 user_settings_dialog_new (OobsUser *user)
 {
 	OobsUsersConfig *config;
+	OobsGroup passwdless_group;
 	GtkWidget *dialog, *widget;
 	const gchar *login = NULL;
 	gchar *title;
+	gchar *passwdless_group_name;
 	gint uid;
 
 	dialog = gst_dialog_get_widget (tool->main_dialog, "user_settings_dialog");
@@ -389,6 +391,18 @@
 	widget = gst_dialog_get_widget (tool->main_dialog, "user_passwd_manual");
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
 
+	/* set password-less login */
+	if (gstconf_get_bool (users, "passwordless_allowed")) {
+		widget = gst_dialog_get_widget (tool->main_dialog, "user_passwd_passwordless");
+		gtk_widget_set_sensitive (widget, TRUE);
+		passwdless_group_name = gstconf_get_string (users, "passwordless_group_name");
+		if (!passwdless_group_name)
+			passwdless_group_name = "passwordless";
+		passwdless_group = oobs_group_new (passwdless_group_name);
+		if (gst_profile_find_group (passwdless_group, user)
+			gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget), TRUE);
+	}
+
 	if (!login)
 		table_set_default_profile (GST_USERS_TOOL (tool));
 
@@ -638,8 +652,10 @@
 {
 	GtkWidget *widget;
 	OobsGroup *group;
+	OobsGroup *passwdless_group;
 	OobsUser *user;
 	const gchar *str;
+	gchar *passwdless_group_name;
 	gboolean password_changed;
 
 	widget = gst_dialog_get_widget (tool->main_dialog, "user_settings_name");
@@ -690,6 +706,18 @@
 		oobs_user_set_password (user, gtk_entry_get_text (GTK_ENTRY (widget)));
 	}
 
+	/* allowed to login without password? */
+	widget = gst_dialog_get_widget (tool->main_dialog, "user_passwd_passwordless");
+	passwdless_group_name = gstconf_get_string (users, "passwordless_group_name");
+	if (!passwdless_group_name)
+		passwdless_group_name = "passwordless";
+	passwdless_group = oobs_group_new (passwdless_group_name);
+	if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)))
+		oobs_group_add_user (passwdless_group, user);
+	else
+		oobs_group_remove_user (passwdless_group, user);
+	}
+
 	group = get_main_group (oobs_user_get_login_name (user));
 	oobs_user_set_main_group (user, group);
 	g_object_unref (group);


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