[gdm] Fix brokenness in parse enriched login



commit 3b50b45f3db6078c89819d0a82194520f2c697a1
Author: William Jon McCann <jmccann redhat com>
Date:   Thu Jun 17 17:10:20 2010 -0400

    Fix brokenness in parse enriched login

 daemon/gdm-slave.c |  140 ++++++++++++++++++++++++++++------------------------
 1 files changed, 76 insertions(+), 64 deletions(-)
---
diff --git a/daemon/gdm-slave.c b/daemon/gdm-slave.c
index e23432b..c0c4038 100644
--- a/daemon/gdm-slave.c
+++ b/daemon/gdm-slave.c
@@ -873,80 +873,91 @@ gdm_slave_add_user_authorization (GdmSlave   *slave,
         return res;
 }
 
-static gchar *
-gdm_slave_parse_enriched_login (GdmSlave *slave,
-                                char *username,
-                                char *display_name)
+static char *
+gdm_slave_parse_enriched_login (GdmSlave   *slave,
+                                const char *username,
+                                const char *display_name)
 {
-        char in_buffer[20];
-        char **argv = NULL;
-        gint pipe1[2], in_buffer_len;
-        int  username_length;
-        pid_t pid;
+        char     **argv;
+        int        username_len;
+        GPtrArray *env;
+        GError    *error;
+        gboolean   res;
+        char      *parsed_username;
+        char      *command;
+        char      *std_output;
+        char      *std_error;
 
-        if (username == NULL)
-                return (NULL);
+        parsed_username = NULL;
+
+        if (username == NULL || username[0] == '\0') {
+                return NULL;
+        }
 
         /* A script may be used to generate the automatic/timed login name
            based on the display/host by ending the name with the pipe symbol
            '|'. */
 
-        username_length = strlen (username);
-        if (username_length > 0 && username[username_length-1] == '|') {
-                GPtrArray *env;
-                GError    *error;
-                gboolean   res;
-                char     **argv;
-                char      *std_output;
-                char      *std_error;
-
-                /* Remove the pipe symbol */
-                username[username_length-1] = '\0';
-
-                argv = NULL;
-                error = NULL;
-                if (! g_shell_parse_argv (username, NULL, &argv, &error)) {
-                      g_warning ("Could not parse command: %s", error->message);
-                      return (NULL);
-                }
+        username_len = strlen (username);
+        if (username[username_len - 1] != '|') {
+                return g_strdup (username);
+        }
 
-                g_debug ("Calling script %s to acquire auto/timed username",
-                         username);
-
-                env = get_script_environment (slave, NULL);
-                error = NULL;
-                res = g_spawn_sync (NULL,
-                                    argv,
-                                    (char **)env->pdata,
-                                    G_SPAWN_SEARCH_PATH,
-                                    NULL,
-                                    NULL,
-                                    &std_output,
-                                    &std_error,
-                                    NULL,
-                                    &error);
-
-                g_ptr_array_foreach (env, (GFunc)g_free, NULL);
-                g_ptr_array_free (env, TRUE);
-                g_strfreev (argv);
-
-                if (! res) {
-                        g_warning ("Unable to launch auto/timed login script: %s", error->message);
-                        g_error_free (error);
-	        } else {
-                        if (std_output != NULL) {
-                                g_strchomp (std_output);
-                                if (std_output[0] != '\0') {
-                                        return (g_strdup (std_output));
-                                }
-                        }
-                        return NULL;
+        /* Remove the pipe symbol */
+        command = g_strndup (username, username_len - 1);
+
+        argv = NULL;
+        error = NULL;
+        if (! g_shell_parse_argv (command, NULL, &argv, &error)) {
+                g_warning ("GdmSlave: Could not parse command '%s': %s", command, error->message);
+                g_error_free (error);
+
+                g_free (command);
+                goto out;
+        }
+
+        g_debug ("GdmSlave: running '%s' to acquire auto/timed username", command);
+        g_free (command);
+
+        env = get_script_environment (slave, NULL);
+
+        error = NULL;
+        std_output = NULL;
+        std_error = NULL;
+        res = g_spawn_sync (NULL,
+                            argv,
+                            (char **)env->pdata,
+                            G_SPAWN_SEARCH_PATH,
+                            NULL,
+                            NULL,
+                            &std_output,
+                            &std_error,
+                            NULL,
+                            &error);
+
+        g_ptr_array_foreach (env, (GFunc)g_free, NULL);
+        g_ptr_array_free (env, TRUE);
+        g_strfreev (argv);
+
+        if (! res) {
+                g_warning ("GdmSlave: Unable to launch auto/timed login script '%s': %s", username, error->message);
+                g_error_free (error);
+
+                g_free (std_output);
+                g_free (std_error);
+                goto out;
+        }
+
+        if (std_output != NULL) {
+                g_strchomp (std_output);
+                if (std_output[0] != '\0') {
+                        parsed_username = g_strdup (std_output);
                 }
-        } else {
-                return (g_strdup (username));
         }
 
-	return NULL;
+ out:
+
+        return parsed_username;
 }
 
 gboolean
@@ -991,7 +1002,8 @@ gdm_slave_get_timed_login_details (GdmSlave   *slave,
 
         if (usernamep != NULL) {
                 *usernamep = gdm_slave_parse_enriched_login (slave,
-                        username, slave->priv->display_name);
+                                                             username,
+                                                             slave->priv->display_name);
         } else {
                 g_free (username);
 



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