2 * Copyright (C) 2010-2011 Robert Ancell.
3 * Author: Robert Ancell <robert.ancell@canonical.com>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option) any later
8 * version. See http://www.gnu.org/copyleft/gpl.html the full text of the
15 #include "guest-account.h"
16 #include "configuration.h"
19 get_setup_script (void)
22 static gchar *setup_script = NULL;
27 script = config_get_string (config_get_instance (), "LightDM", "guest-account-script");
31 setup_script = g_find_program_in_path (script);
38 guest_account_is_installed (void)
40 return get_setup_script () != NULL;
44 run_script (const gchar *script, gchar **stdout_text, gint *exit_status, GError **error)
50 if (!g_shell_parse_argv (script, &argc, &argv, error))
53 result = g_spawn_sync (NULL, argv, NULL,
56 stdout_text, NULL, exit_status, error);
63 guest_account_setup (void)
65 gchar *command, *stdout_text, *username, **lines;
70 command = g_strdup_printf ("%s add", get_setup_script ());
71 g_debug ("Opening guest account with command '%s'", command);
72 result = run_script (command, &stdout_text, &exit_status, &error);
75 g_warning ("Error running guest account setup script '%s': %s", get_setup_script (), error->message);
76 g_clear_error (&error);
82 g_debug ("Guest account setup script returns %d: %s", exit_status, stdout_text);
87 /* Use the last line and trim whitespace */
88 lines = g_strsplit (g_strstrip (stdout_text), "\n", -1);
90 username = g_strdup (g_strstrip (lines[g_strv_length (lines) - 1]));
92 username = g_strdup ("");
95 if (strcmp (username, "") == 0)
98 g_debug ("Guest account setup script didn't return a username");
102 g_debug ("Guest account %s setup", username);
108 guest_account_cleanup (const gchar *username)
113 GError *error = NULL;
115 command = g_strdup_printf ("%s remove %s", get_setup_script (), username);
116 g_debug ("Closing guest account %s with command '%s'", username, command);
118 result = run_script (command, NULL, &exit_status, &error);
122 g_warning ("Error running guest account cleanup script '%s': %s", get_setup_script (), error->message);
123 g_clear_error (&error);
125 if (result && exit_status != 0)
126 g_debug ("Guest account cleanup script returns %d", exit_status);