Merge lp:~mfisch/lightdm/set-defaults-work into lp:lightdm

Proposed by Matt Fischer on 2012-04-16
Status: Merged
Merge reported by: Robert Ancell
Merged at revision: not available
Proposed branch: lp:~mfisch/lightdm/set-defaults-work
Merge into: lp:lightdm
Diff against target: 120 lines (+58/-12)
1 file modified
utils/lightdm-set-defaults.c (+58/-12)
To merge this branch: bzr merge lp:~mfisch/lightdm/set-defaults-work
Reviewer Review Type Date Requested Status
Robert Ancell 2012-04-16 Approve on 2012-04-18
Review via email: mp+102196@code.launchpad.net

Description of the Change

This adds some new options to lightdm-set-defaults so allow us to set show-manual-login and allow-guest. It also simplifies the option for hide-users by removing the dual options and replaces it with a "true/false'. This was pre-reviewed by Scott Sweeny. Here's the test output:

root@caprica:~/lightdm/utils# ./lightdm-set-defaults
Wrong usage of the command
Usage:
  lightdm-set-defaults [OPTION...] - set lightdm default values

Help Options:
  -h, --help Show help options

Application Options:
  -d, --debug Enable debugging
  -k, --keep-old Only update if no default already set
  -r, --remove Remove default value if it's the current one
  -s, --session Set default session
  -g, --greeter Set default greeter
  -a, --autologin Set autologin user
  -i, --hide-users Set greeter-hide-users to true or false
  -m, --show-manual-login Set show-manual-login to true or false
  -l, --allow-guest Set allow-guest to true or false

root@caprica:~/lightdm/utils# ./lightdm-set-defaults -m BOB
true and false are the only valid choices for show-manual-login
root@caprica:~/lightdm/utils# ./lightdm-set-defaults -i 222
true and false are the only valid choices for hide-users
root@caprica:~/lightdm/utils# ./lightdm-set-defaults -l
option parsing failed: Missing argument for -l
root@caprica:~/lightdm/utils# ./lightdm-set-defaults -l -1
true and false are the only valid choices for allow-guest
root@caprica:~/lightdm/utils# ./lightdm-set-defaults -i True -m FALSE -l FalsE
root@caprica:~/lightdm/utils# !cat
cat /usr/local/etc/lightdm/lightdm.conf

[SeatDefaults]
greeter-hide-users=true
greeter-show-manual-login=false
allow-guest=false
root@caprica:~/lightdm/utils# ./lightdm-set-defaults -i FALSe -m True -l True
root@caprica:~/lightdm/utils# cat /usr/local/etc/lightdm/lightdm.conf

[SeatDefaults]
greeter-hide-users=false
greeter-show-manual-login=true
allow-guest=true

To post a comment you must log in.
Robert Ancell (robert-ancell) wrote :

Thanks Matt!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'utils/lightdm-set-defaults.c'
2--- utils/lightdm-set-defaults.c 2012-03-15 15:49:14 +0000
3+++ utils/lightdm-set-defaults.c 2012-04-16 22:24:18 +0000
4@@ -24,6 +24,8 @@
5 #define GREETER_KEY_NAME "greeter-session"
6 #define AUTOLOGIN_KEY_NAME "autologin-user"
7 #define HIDE_USERS_KEY_NAME "greeter-hide-users"
8+#define MANUAL_LOGIN_KEY_NAME "greeter-show-manual-login"
9+#define ALLOW_GUEST_KEY_NAME "allow-guest"
10
11 #define IS_STRING_EMPTY(x) ((x)==NULL||(x)[0]=='\0')
12
13@@ -31,11 +33,15 @@
14 static gboolean keep_old = FALSE;
15 static gboolean remove = FALSE;
16 static gboolean hide_users = FALSE;
17-static gboolean show_users = FALSE;
18+static gboolean show_manual_login = FALSE;
19+static gboolean allow_guest = FALSE;
20
21 static char *session = NULL;
22 static char *greeter = NULL;
23 static char *autologin = NULL;
24+static char *str_hide_users = NULL;
25+static char *str_show_manual_login = NULL;
26+static char *str_allow_guest = NULL;
27
28 static GOptionEntry entries[] =
29 {
30@@ -45,8 +51,9 @@
31 { "session", 's', 0, G_OPTION_ARG_STRING, &session, N_("Set default session"), NULL },
32 { "greeter", 'g', 0, G_OPTION_ARG_STRING, &greeter, N_("Set default greeter"), NULL },
33 { "autologin",'a', 0, G_OPTION_ARG_STRING, &autologin, N_("Set autologin user"), NULL },
34- { "hide-users",'i', 0, G_OPTION_ARG_NONE, &hide_users, N_("Hide user list in greeter (exclusive to show-users)"), NULL },
35- { "show-users",'w', 0, G_OPTION_ARG_NONE, &show_users, N_("Show user list in greeter (exclusive to hide-users)"), NULL },
36+ { "hide-users",'i', 0, G_OPTION_ARG_STRING, &str_hide_users, N_("Set greeter-hide-users to true or false"), NULL },
37+ { "show-manual-login",'m', 0, G_OPTION_ARG_STRING, &str_show_manual_login, N_("Set show-manual-login to true or false"), NULL },
38+ { "allow-guest",'l', 0, G_OPTION_ARG_STRING, &str_allow_guest, N_("Set allow-guest to true or false"), NULL },
39 { NULL }
40 };
41
42@@ -119,6 +126,25 @@
43 }
44
45 int
46+str_to_bool(const gchar *str, gboolean *bool_out)
47+{
48+ if (IS_STRING_EMPTY(str)) {
49+ return -1;
50+ }
51+ else if (strncasecmp(str, "true", 4)==0) {
52+ *bool_out = TRUE;
53+ return 0;
54+ }
55+ else if (strncasecmp(str, "false", 5)==0) {
56+ *bool_out = FALSE;
57+ return 0;
58+ }
59+ else {
60+ return -2;
61+ }
62+}
63+
64+int
65 main (int argc, char *argv[])
66 {
67 GOptionContext *context = NULL;
68@@ -149,12 +175,7 @@
69 g_error_free (error);
70 return 1;
71 }
72- if (show_users && hide_users) {
73- g_printerr (N_("show-users and hide-users are mutually exclusive\n"));
74- g_option_context_free (context);
75- return 1;
76- }
77- if (IS_STRING_EMPTY (session) && IS_STRING_EMPTY (greeter) && IS_STRING_EMPTY (autologin) && !show_users && !hide_users) {
78+ if (IS_STRING_EMPTY (session) && IS_STRING_EMPTY (greeter) && IS_STRING_EMPTY (autologin) && IS_STRING_EMPTY(str_hide_users) && IS_STRING_EMPTY(str_show_manual_login) && IS_STRING_EMPTY(str_allow_guest)) {
79 g_printerr (N_("Wrong usage of the command\n%s"), g_option_context_get_help (context, FALSE, NULL));
80 g_option_context_free (context);
81 return 1;
82@@ -183,10 +204,35 @@
83 return_code = update_string (default_greeter, greeter, keep_old, remove, SEATDEFAULT_KEY_GROUP, GREETER_KEY_NAME, keyfile);
84 if (!(IS_STRING_EMPTY (autologin)) && (return_code == 0))
85 return_code = update_string (default_autologin, autologin, keep_old, remove, SEATDEFAULT_KEY_GROUP, AUTOLOGIN_KEY_NAME, keyfile);
86- if ((show_users || hide_users) && (return_code == 0))
87- return_code = update_boolean (hide_users, keep_old, SEATDEFAULT_KEY_GROUP, HIDE_USERS_KEY_NAME, keyfile);
88+ if (!(IS_STRING_EMPTY(str_hide_users)) && (return_code == 0)) {
89+ if (str_to_bool(str_hide_users, &hide_users) == 0) {
90+ return_code = update_boolean (hide_users, keep_old, SEATDEFAULT_KEY_GROUP, HIDE_USERS_KEY_NAME, keyfile);
91+ }
92+ else {
93+ g_printerr (N_("true and false are the only valid choices for hide-users\n"));
94+ return 1;
95+ }
96+ }
97+ if (!(IS_STRING_EMPTY(str_allow_guest)) && (return_code == 0)) {
98+ if (str_to_bool(str_allow_guest, &allow_guest) == 0) {
99+ return_code = update_boolean (allow_guest, keep_old, SEATDEFAULT_KEY_GROUP, ALLOW_GUEST_KEY_NAME, keyfile);
100+ }
101+ else {
102+ g_printerr (N_("true and false are the only valid choices for allow-guest\n"));
103+ return 1;
104+ }
105+ }
106+ if (!(IS_STRING_EMPTY(str_show_manual_login)) && (return_code == 0)) {
107+ if (str_to_bool(str_show_manual_login, &show_manual_login) == 0) {
108+ return_code = update_boolean (show_manual_login, keep_old, SEATDEFAULT_KEY_GROUP, MANUAL_LOGIN_KEY_NAME, keyfile);
109+ }
110+ else {
111+ g_printerr (N_("true and false are the only valid choices for show-manual-login\n"));
112+ return 1;
113+ }
114+ }
115
116- if(return_code == 0) {
117+ if (return_code == 0) {
118 s_data = g_key_file_to_data (keyfile, &size, &error);
119 if (!s_data) {
120 g_debug ("Can't convert data to string: %s", error->message);

Subscribers

People subscribed via source and target branches