commit c7a1ad4850e394260cb61582aeefae8f95c3cae8
Author: Halton Huo <halton.huo@sun.com>
Date:   Fri Nov 27 22:01:20 2009 +0800

    gdm-02-sdtlogin.diff

diff --git a/common/gdm-common.h b/common/gdm-common.h
index 191bd70..634c091 100644
--- a/common/gdm-common.h
+++ b/common/gdm-common.h
@@ -26,6 +26,11 @@
 
 #include "gdm-common-unknown-origin.h"
 
+#ifdef __sun
+#define GDM_DT_DIR "/var/dt"
+#define GDM_SDTLOGIN_DIR "/var/dt/sdtlogin"
+#endif
+
 #define GDM_CUSTOM_SESSION  "custom"
 
 G_BEGIN_DECLS
diff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
index 757ef62..7012811 100644
--- a/daemon/gdm-server.c
+++ b/daemon/gdm-server.c
@@ -646,6 +646,13 @@ gdm_server_spawn (GdmServer  *server,
                         count ++;
                 }
                 g_free (socket_file);
+#if __sun
+                /* Remove old communication pipe, if present */
+                char *old_pipe;
+                old_pipe = g_strdup_printf ("%s/%d", GDM_SDTLOGIN_DIR, display_num);
+                g_unlink (old_pipe);
+                g_free (old_pipe);
+#endif
         }
 
         env = get_server_environment (server);
diff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
index 2ab53a0..8970297 100644
--- a/daemon/gdm-session-worker.c
+++ b/daemon/gdm-session-worker.c
@@ -32,6 +32,13 @@
 #include <grp.h>
 #include <pwd.h>
 
+#if __sun
+#include <sys/param.h>
+#define GDM_PAM_QUAL
+#else
+#define GDM_PAM_QUAL const
+#endif
+
 #include <security/pam_appl.h>
 
 #include <glib.h>
@@ -61,6 +68,7 @@
 #endif
 
 #include "gdm-session-settings.h"
+#include "gdm-common.h"
 
 #define GDM_SESSION_WORKER_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), GDM_TYPE_SESSION_WORKER, GdmSessionWorkerPrivate))
 
@@ -151,12 +159,115 @@ static void     gdm_session_worker_final
 static void     queue_state_change              (GdmSessionWorker      *worker);
 
 typedef int (* GdmSessionWorkerPamNewMessagesFunc) (int,
-                                                    const struct pam_message **,
+                                                    GDM_PAM_QUAL struct pam_message **,
                                                     struct pam_response **,
                                                     gpointer);
 
 G_DEFINE_TYPE (GdmSessionWorker, gdm_session_worker, G_TYPE_OBJECT)
 
+#ifdef __sun
+void
+solaris_xserver_cred (char * username, struct passwd *passwd_entry, const char *x11_display_name)
+{
+        struct stat statbuf;
+        struct group *gr;
+        gid_t  groups[NGROUPS_UMAX];
+        char *home, *disp, *tmp, *p, pipe[MAXPATHLEN], info[MAXPATHLEN];
+        int display_number = 0;
+        int retval, fd, i, nb;
+        int ngroups;
+
+        if (g_access (passwd_entry->pw_dir, F_OK) != 0) {
+                g_debug ("solaris_xserver_cred: no HOME dir access\n");
+                return;
+        }
+
+        /*
+         * Handshake with server. Make sure it created a pipe.
+         * Open and write.
+         */
+        if ((tmp = strstr (x11_display_name, ":")) != NULL) {
+                tmp++;
+                display_number = g_ascii_strtod (tmp, &p);
+
+                if (errno != 0) {
+                        g_debug ("solaris_xserver_cred: problem getting display number\n");
+                        return;
+                }
+        }
+
+        sprintf (pipe, "%s/%d", GDM_SDTLOGIN_DIR, display_number);
+
+        if (g_stat (GDM_SDTLOGIN_DIR, &statbuf) == 0) {
+                if (! statbuf.st_mode & S_IFDIR) {
+                        g_debug ("solaris_xserver_cred: %s is not a directory\n",
+                                 GDM_SDTLOGIN_DIR);
+                        return;
+                }
+        } else {
+                g_debug ("solaris_xserver_cred: %s does not exist\n", GDM_SDTLOGIN_DIR);
+                return;
+        }
+
+        fd = open (pipe, O_RDWR);
+        g_unlink (pipe);
+
+        if (fd < 0) {
+                g_debug ("solaris_xserver_cred: could not open %s\n", pipe);
+                return;
+        }
+        if (fstat (fd, &statbuf) == 0 ) {
+                if ( ! statbuf.st_mode & S_IFIFO) {
+                        close (fd);
+                        g_debug ("solaris_xserver_cred: %s is not a pipe\n", pipe);
+                        return;
+                }
+        } else {
+                close (fd);
+                g_debug ("solaris_xserver_cred: %s does not exist\n", pipe);
+                return;
+        }
+
+        sprintf (info, "GID=\"%d\"; ", passwd_entry->pw_gid);
+        nb = write (fd, info, strlen (info));
+        g_debug ("solaris_xserver_cred: %s\n", info);
+
+        if (initgroups (username, passwd_entry->pw_gid) == -1) {
+                ngroups = 0;
+        } else {
+                ngroups = getgroups (NGROUPS_UMAX, groups);
+        }
+
+        for (i=0; i < ngroups; i++) {
+                sprintf (info, "G_LIST_ID=\"%u\" ", groups[i]);
+                nb = write (fd, info, strlen (info));
+                g_debug ("solaris_xserver_cred: %s\n", info);
+        }
+
+        if (ngroups > 0) {
+                sprintf (info, ";");
+                write (fd, info, strlen (info));
+        }
+
+        sprintf (info, " HOME=\"%s\" ", passwd_entry->pw_dir);
+        nb = write (fd, info, strlen (info));
+        g_debug ("solaris_xserver_cred: %s\n", info);
+
+        sprintf (info, " UID=\"%d\" EOF=\"\";", passwd_entry->pw_uid);
+        nb = write (fd, info, strlen (info));
+        g_debug ("solaris_xserver_cred: %s\n", info);
+
+        /*
+         * Handshake with server. Make sure it read the pipe.
+         *
+         * Close file descriptor.
+         */
+        close (fd);
+
+        return;
+}
+#endif
+
 GQuark
 gdm_session_worker_error_quark (void)
 {
@@ -591,7 +702,11 @@ static gboolean
 gdm_session_worker_get_username (GdmSessionWorker  *worker,
                                  char             **username)
 {
+#ifdef __sun
+        gpointer item;
+#else
         gconstpointer item;
+#endif
 
         g_assert (worker->priv->pam_handle != NULL);
 
@@ -870,7 +985,7 @@ gdm_session_worker_process_pam_message (
 
 static int
 gdm_session_worker_pam_new_messages_handler (int                        number_of_messages,
-                                             const struct pam_message **messages,
+                                             GDM_PAM_QUAL struct pam_message **messages,
                                              struct pam_response      **responses,
                                              GdmSessionWorker          *worker)
 {
@@ -1732,6 +1847,12 @@ gdm_session_worker_start_user_session (G
         g_debug ("GdmSessionWorker: opening user session with program '%s'",
                  worker->priv->arguments[0]);
 
+#ifdef __sun
+        solaris_xserver_cred (worker->priv->username,
+                              passwd_entry,
+                              worker->priv->x11_display_name);
+#endif
+
         error_code = PAM_SUCCESS;
 
         session_pid = fork ();
diff --git a/daemon/main.c b/daemon/main.c
index 8577ba7..0f2a007 100644
--- a/daemon/main.c
+++ b/daemon/main.c
@@ -525,6 +525,21 @@ main (int    argc,
                 { NULL }
         };
 
+#ifdef __sun
+        {
+                struct stat statbuf;
+                int r;
+
+                r = stat (GDM_DT_DIR, &statbuf);
+                if (r < 0) {
+                        g_mkdir (GDM_DT_DIR, 0755);
+                }
+
+                g_remove (GDM_SDTLOGIN_DIR);
+                g_mkdir (GDM_SDTLOGIN_DIR, 0700);
+        }
+#endif
+
         bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
         textdomain (GETTEXT_PACKAGE);
         setlocale (LC_ALL, "");
