patches/gdm-12-setfacl.diff
author yippi
Mon, 27 Sep 2010 21:07:51 +0000
changeset 20108 51df67ca9307
parent 18225 b45d97b2f2c6
child 20115 4211fc844932
permissions -rw-r--r--
I had these modules listed as being owned by me, but they are really owned by wangke, correcting.

commit 5c3d0475ddd123d9a6748d8ab3b1d4cb0335f43e
Author: Halton Huo <[email protected]>
Date:   Fri Jul 2 16:30:11 2010 +0800

    gdm-13-setfacl.diff

diff --git a/daemon/gdm-welcome-session.c b/daemon/gdm-welcome-session.c
index 426e3d0..dd89194 100644
--- a/daemon/gdm-welcome-session.c
+++ b/daemon/gdm-welcome-session.c
@@ -372,7 +372,7 @@ get_welcome_environment (GdmWelcomeSessi
                 "LANG", "LANGUAGE", "LC_CTYPE", "LC_NUMERIC", "LC_TIME",
                 "LC_COLLATE", "LC_MONETARY", "LC_MESSAGES", "LC_PAPER",
                 "LC_NAME", "LC_ADDRESS", "LC_TELEPHONE", "LC_MEASUREMENT",
-                "LC_IDENTIFICATION", "LC_ALL",
+                "LC_IDENTIFICATION", "LC_ALL", "AUDIODEV",
                 NULL
         };
         int i;
@@ -931,6 +931,31 @@ gdm_welcome_session_spawn (GdmWelcomeSes
                 /* FIXME: */
         }
 
+        if (g_str_equal (welcome_session->priv->x11_display_device, "/dev/dtlocal") &&  g_file_test ("/opt/SUNWut/bin/utaudio", G_FILE_TEST_IS_EXECUTABLE)) {
+                char    *out;
+                int      status;
+                gboolean res;
+                GError  *error;
+
+                g_debug ("Running utaudio to get AUDIODEV");
+
+                res = g_spawn_command_line_sync ("/opt/SUNWut/bin/utaudio",
+                                                 &out,
+                                                 NULL,
+                                                 &status,
+                                                 &error);
+                if (! res) {
+                        g_warning ("Could not run utaudio: %s", error->message);
+                        g_error_free (error);
+                        g_free (out);
+                } else if (g_file_test (out, G_FILE_TEST_EXISTS)) {
+                        out = g_strstrip (out);
+                        if (out && out[0] != '\0') {
+                                g_setenv ("AUDIODEV", out, TRUE);
+                        }
+                }
+        }
+
         env = get_welcome_environment (welcome_session, TRUE);
 
         error = NULL;
@@ -939,6 +964,67 @@ gdm_welcome_session_spawn (GdmWelcomeSes
         log_path = g_build_filename (LOGDIR, log_file, NULL);
         g_free (log_file);
 
+#if __sun
+        /*
+         * Set ACL if running on the console or dtlocal.  In this case, we know that
+         * logindevperm will be called on authentication, which will reste the device 
+         * permissions.  So there is no need to worry about checking if the ACL is
+         * already set, or appending the same ACL to the file.
+         */
+        if (welcome_session->priv->x11_display_device) {
+                char *audiodev;
+                char *display_device;
+
+                audiodev = g_strdup (g_getenv ("AUDIODEV"));
+
+                if (g_str_has_prefix (welcome_session->priv->x11_display_device, "/dev/vt")
+                    && g_str_equal (welcome_session->priv->x11_display_name, ":0")) {
+                        display_device = g_strdup ("/dev/console");      
+                } else {
+                        display_device = g_strdup (welcome_session->priv->x11_display_device);      
+                }
+
+                if (g_str_equal (display_device, "/dev/console")
+                    && g_file_test ("/dev/audio", G_FILE_TEST_EXISTS)) {
+                        int acl_flavor;
+
+                        acl_flavor = pathconf("/dev/audio", _PC_ACL_ENABLED);
+
+                        if (acl_flavor & _ACL_ACLENT_ENABLED) {
+                                g_debug ("Setting device permissions: ACLIENT");
+                                system ("/usr/bin/setfacl -m user:gdm:rwx,mask:rwx /dev/audio");
+                                system ("/usr/bin/setfacl -m user:gdm:rwx,mask:rwx /dev/audioctl");
+                        } else if (acl_flavor & _ACL_ACE_ENABLED) {
+                                g_debug ("Setting device permissions: ACE");
+                                system ("/usr/bin/chmod A+user:gdm:rwx:allow /dev/audio");
+                                system ("/usr/bin/chmod A+user:gdm:rwx:allow /dev/audioctl");
+                        } else {
+                                g_debug ("Not setting device permissions: ACE");
+                        }
+
+                } else if (g_str_equal (display_device, "/dev/dtlocal")
+                           && (audiodev != NULL)
+                           && (audiodev[0] != '\0')
+                           && g_file_test (audiodev, G_FILE_TEST_EXISTS)) {
+
+                        char *tmp_cmd;
+
+                        g_debug ("Changing ownership for %s", audiodev);
+                        tmp_cmd = g_strdup_printf ("/usr/bin/chown gdm %s", audiodev); 
+                        system (tmp_cmd);
+                        g_free (tmp_cmd);
+                        g_debug ("Changing ownership for %sctl", audiodev);
+                        tmp_cmd = g_strdup_printf ("/usr/bin/chown gdm %sctl", audiodev); 
+                        system (tmp_cmd);
+                        g_free (tmp_cmd);
+                }
+
+                g_unsetenv ("AUDIODEV");
+                g_free (display_device);
+                g_free (audiodev);
+        }
+#endif
+
         ret = spawn_command_line_async_as_user (welcome_session->priv->command,
                                                 welcome_session->priv->user_name,
                                                 welcome_session->priv->group_name,