Re: Allowing password-less connexions

Milan Bouchet-Valat <[email protected]> Thu, 15 May 2008 19:09:56 +0200
Newsgroups gmane.comp.gnome.system-tools
Message-ID <1210871396.17142.9.camel@milan>
--=-2iLHU7Esr+Ud2W+dGjnI
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

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 =EF=BB=BFfind_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
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- privileges-table.c	(r=C3=A9vision 4234)
+++ privileges-table.c	(copie de travail)
@@ -219,29 +219,6 @@
 	}
 }
=20
-static gboolean
-find_group_in_profile (OobsGroup      *group,
-		       GstUserProfile *profile)
-{
-	gchar **groups;
-	const gchar *name;
-
-	if (!profile->groups)
-		return FALSE;
-
-	groups =3D profile->groups;
-	name =3D oobs_group_get_name (group);
-
-	while (*groups) {
-		if (strcmp (*groups, name) =3D=3D 0)
-			return TRUE;
-
-		groups++;
-	}
-
-	return FALSE;
-}
-
 void
 privileges_table_set_from_profile (GstUserProfile *profile)
 {
@@ -262,7 +239,7 @@
 				    -1);
=20
 		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);
=20
 		valid =3D gtk_tree_model_iter_next (child_model, &iter);
Index: user-profiles.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- user-profiles.c	(r=C3=A9vision 4234)
+++ user-profiles.c	(copie de travail)
@@ -202,3 +202,26 @@
=20
 	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 =3D profile->groups;
+	name =3D oobs_group_get_name (group);
+
+	while (*groups) {
+		if (strcmp (*groups, name) =3D=3D 0)
+			return TRUE;
+
+		groups++;
+	}
+
+	return FALSE;
+}
Index: user-profiles.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- user-profiles.h	(r=C3=A9vision 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);
=20
=20
 G_END_DECLS
Index: user-settings.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- user-settings.c	(r=C3=A9vision 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 =3D NULL;
 	gchar *title;
+	gchar *passwdless_group_name;
 	gint uid;
=20
 	dialog =3D gst_dialog_get_widget (tool->main_dialog,
"user_settings_dialog");
@@ -389,6 +391,18 @@
 	widget =3D gst_dialog_get_widget (tool->main_dialog,
"user_passwd_manual");
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
=20
+	/* set password-less login */
+	if (gstconf_get_bool (users, "passwordless_allowed")) {
+		widget =3D gst_dialog_get_widget (tool->main_dialog,
"user_passwd_passwordless");
+		gtk_widget_set_sensitive (widget, TRUE);
+		passwdless_group_name =3D gstconf_get_string (users,
"passwordless_group_name");
+		if (!passwdless_group_name)
+			passwdless_group_name =3D "passwordless";
+		passwdless_group =3D 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));
=20
@@ -638,8 +652,10 @@
 {
 	GtkWidget *widget;
 	OobsGroup *group;
+	OobsGroup *passwdless_group;
 	OobsUser *user;
 	const gchar *str;
+	gchar *passwdless_group_name;
 	gboolean password_changed;
=20
 	widget =3D 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)));
 	}
=20
+	/* allowed to login without password? */
+	widget =3D gst_dialog_get_widget (tool->main_dialog,
"user_passwd_passwordless");
+	passwdless_group_name =3D gstconf_get_string (users,
"passwordless_group_name");
+	if (!passwdless_group_name)
+		passwdless_group_name =3D "passwordless";
+	passwdless_group =3D 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 =3D get_main_group (oobs_user_get_login_name (user));
 	oobs_user_set_main_group (user, group);
 	g_object_unref (group);



--=-2iLHU7Esr+Ud2W+dGjnI
Content-Disposition: attachment; filename=passwordless.diff
Content-Type: text/x-patch; name=passwordless.diff; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

gnome-system-tools/src/users$ svn diff .
Index: privileges-table.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- privileges-table.c	(r=C3=A9vision 4234)
+++ privileges-table.c	(copie de travail)
@@ -219,29 +219,6 @@
 	}
 }
=20
-static gboolean
-find_group_in_profile (OobsGroup      *group,
-		       GstUserProfile *profile)
-{
-	gchar **groups;
-	const gchar *name;
-
-	if (!profile->groups)
-		return FALSE;
-
-	groups =3D profile->groups;
-	name =3D oobs_group_get_name (group);
-
-	while (*groups) {
-		if (strcmp (*groups, name) =3D=3D 0)
-			return TRUE;
-
-		groups++;
-	}
-
-	return FALSE;
-}
-
 void
 privileges_table_set_from_profile (GstUserProfile *profile)
 {
@@ -262,7 +239,7 @@
 				    -1);
=20
 		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);
=20
 		valid =3D gtk_tree_model_iter_next (child_model, &iter);
Index: user-profiles.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- user-profiles.c	(r=C3=A9vision 4234)
+++ user-profiles.c	(copie de travail)
@@ -202,3 +202,26 @@
=20
 	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 =3D profile->groups;
+	name =3D oobs_group_get_name (group);
+
+	while (*groups) {
+		if (strcmp (*groups, name) =3D=3D 0)
+			return TRUE;
+
+		groups++;
+	}
+
+	return FALSE;
+}
Index: user-profiles.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- user-profiles.h	(r=C3=A9vision 4234)
+++ user-profiles.h	(copie de travail)
@@ -68,6 +68,8 @@
 						const gchar     *profile);
 GstUserProfile*  gst_user_profiles_get_current (GstUserProfiles *profile=
s);
 GstUserProfile*  gst_user_profiles_get_default_profile (GstUserProfiles =
*profiles);
+gboolean         gst_user_profiles_find_group (OobsGroup        *group,
+		                                       GstUserProfile   *profile);
=20
=20
 G_END_DECLS
Index: user-settings.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- user-settings.c	(r=C3=A9vision 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 =3D NULL;
 	gchar *title;
+	gchar *passwdless_group_name;
 	gint uid;
=20
 	dialog =3D gst_dialog_get_widget (tool->main_dialog, "user_settings_dia=
log");
@@ -389,6 +391,18 @@
 	widget =3D gst_dialog_get_widget (tool->main_dialog, "user_passwd_manua=
l");
 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
=20
+	/* set password-less login */
+	if (gstconf_get_bool (users, "passwordless_allowed")) {
+		widget =3D gst_dialog_get_widget (tool->main_dialog, "user_passwd_pass=
wordless");
+		gtk_widget_set_sensitive (widget, TRUE);
+		passwdless_group_name =3D gstconf_get_string (users, "passwordless_gro=
up_name");
+		if (!passwdless_group_name)
+			passwdless_group_name =3D "passwordless";
+		passwdless_group =3D 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));
=20
@@ -638,8 +652,10 @@
 {
 	GtkWidget *widget;
 	OobsGroup *group;
+	OobsGroup *passwdless_group;
 	OobsUser *user;
 	const gchar *str;
+	gchar *passwdless_group_name;
 	gboolean password_changed;
=20
 	widget =3D gst_dialog_get_widget (tool->main_dialog, "user_settings_nam=
e");
@@ -690,6 +706,18 @@
 		oobs_user_set_password (user, gtk_entry_get_text (GTK_ENTRY (widget)))=
;
 	}
=20
+	/* allowed to login without password? */
+	widget =3D gst_dialog_get_widget (tool->main_dialog, "user_passwd_passw=
ordless");
+	passwdless_group_name =3D gstconf_get_string (users, "passwordless_grou=
p_name");
+	if (!passwdless_group_name)
+		passwdless_group_name =3D "passwordless";
+	passwdless_group =3D 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 =3D get_main_group (oobs_user_get_login_name (user));
 	oobs_user_set_main_group (user, group);
 	g_object_unref (group);

--=-2iLHU7Esr+Ud2W+dGjnI
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
system-tools-list mailing list
[email protected]
http://mail.gnome.org/mailman/listinfo/system-tools-list

--=-2iLHU7Esr+Ud2W+dGjnI--