7199N/AFrom f7978982d31f67867d8200f9f3102eb423312abc Mon Sep 17 00:00:00 2001
7199N/AFrom: Alan Coopersmith <alan.coopersmith@oracle.com>
7199N/ADate: Tue, 29 Dec 2015 12:50:16 -0800
7199N/ASubject: [PATCH 04/19] sdtlogin
7199N/A
7199N/AAdds SDTLOGIN interface, which drops the Xserver to user
7199N/Aperms rather than running as root, for added security on Solaris.
7199N/AOriginal date:2008-05-06 owner:yippi type:feature
7199N/A
7199N/AFor the original definition, see Sun ASARC case 1995/390.
7199N/AFor the current implementation in the X server, see sun-src/os/dtlogin.c
7199N/Aand dtlogin-userinfo.patch in open-src/xserver/xorg in the X gate.
7199N/A---
7199N/A common/gdm-common.h | 5 ++
7199N/A daemon/gdm-server.c | 11 +++++
7199N/A daemon/gdm-session-worker.c | 116 ++++++++++++++++++++++++++++++++++++++++++++
7199N/A daemon/main.c | 15 ++++++
7199N/A 4 files changed, 147 insertions(+)
7199N/A
7199N/Adiff --git a/common/gdm-common.h b/common/gdm-common.h
7199N/Aindex 19dbbbb..6ac61c0 100644
7199N/A--- a/common/gdm-common.h
7199N/A+++ b/common/gdm-common.h
7199N/A@@ -42,6 +42,11 @@ GQuark gdm_common_error_quark (void);
7199N/A typedef char * (*GdmExpandVarFunc) (const char *var,
7199N/A gpointer user_data);
7199N/A
7199N/A+#ifdef __sun
7199N/A+#define GDM_DT_DIR "/var/dt"
7199N/A+#define GDM_SDTLOGIN_DIR "/var/dt/sdtlogin"
7199N/A+#endif
7199N/A+
7199N/A G_BEGIN_DECLS
7199N/A
7199N/A int gdm_wait_on_pid (int pid);
7199N/Adiff --git a/daemon/gdm-server.c b/daemon/gdm-server.c
7199N/Aindex 08f2354..2cec263 100644
7199N/A--- a/daemon/gdm-server.c
7199N/A+++ b/daemon/gdm-server.c
7199N/A@@ -742,6 +742,17 @@ gdm_server_spawn (GdmServer *server,
7199N/A goto out;
7199N/A }
7199N/A
7199N/A+#if __sun
7199N/A+ /* Remove old communication pipe, if present */
7199N/A+ char *display_num = strchr(server->priv->display_name, ':');
7199N/A+ if (display_num != NULL && display_num[1] != '\0') {
7199N/A+ char *old_pipe = g_strdup_printf ("%s/%s", GDM_SDTLOGIN_DIR,
7199N/A+ display_num + 1);
7199N/A+ VE_IGNORE_EINTR (g_remove (old_pipe));
7199N/A+ g_free (old_pipe);
7199N/A+ }
7199N/A+#endif
7199N/A+
7199N/A env = get_server_environment (server);
7199N/A
7199N/A freeme = g_strjoinv (" ", argv);
7199N/Adiff --git a/daemon/gdm-session-worker.c b/daemon/gdm-session-worker.c
7199N/Aindex 291caad..93c9e82 100644
7199N/A--- a/daemon/gdm-session-worker.c
7199N/A+++ b/daemon/gdm-session-worker.c
7199N/A@@ -38,6 +38,7 @@
7199N/A #include <pwd.h>
7199N/A
7199N/A #if __sun
7199N/A+#include <sys/param.h>
7199N/A #define GDM_PAM_QUAL
7199N/A #else
7199N/A #define GDM_PAM_QUAL const
7199N/A@@ -2044,6 +2045,115 @@ out:
7199N/A return fd;
7199N/A }
7199N/A
7199N/A+#ifdef __sun
7199N/A+static void
7199N/A+solaris_xserver_cred (const char *username, struct passwd *passwd_entry,
7199N/A+ const char *x11_display_name)
7199N/A+{
7199N/A+ FILE *fp;
7199N/A+ struct stat statbuf;
7199N/A+ gid_t groups[NGROUPS_UMAX];
7199N/A+ char *tmp, *p, pipe[MAXPATHLEN], info[MAXPATHLEN];
7199N/A+ int display_number = 0;
7199N/A+ int fd, i;
7199N/A+ int ngroups;
7199N/A+
7199N/A+ if (g_access (passwd_entry->pw_dir, F_OK) != 0) {
7199N/A+ g_debug ("solaris_xserver_cred: no HOME dir access\n");
7199N/A+ return;
7199N/A+ }
7199N/A+
7199N/A+ /*
7199N/A+ * Handshake with server. Make sure it created a pipe.
7199N/A+ * Open and write.
7199N/A+ */
7199N/A+ if ((tmp = strstr (x11_display_name, ":")) != NULL) {
7199N/A+ tmp++;
7199N/A+ display_number = g_ascii_strtod (tmp, &p);
7199N/A+
7199N/A+ if (errno != 0) {
7199N/A+ g_debug ("solaris_xserver_cred: problem getting display number\n");
7199N/A+ return;
7199N/A+ }
7199N/A+ }
7199N/A+
7199N/A+ if (g_stat (GDM_SDTLOGIN_DIR, &statbuf) == 0) {
7199N/A+ if (! S_ISDIR(statbuf.st_mode)) {
7199N/A+ g_debug ("solaris_xserver_cred: %s is not a directory\n",
7199N/A+ GDM_SDTLOGIN_DIR);
7199N/A+ return;
7199N/A+ }
7199N/A+ } else {
7199N/A+ g_debug ("solaris_xserver_cred: %s does not exist\n", GDM_SDTLOGIN_DIR);
7199N/A+ return;
7199N/A+ }
7199N/A+
7199N/A+ snprintf (pipe, sizeof(pipe), "%s/%d", GDM_SDTLOGIN_DIR, display_number);
7199N/A+ fd = open (pipe, O_RDWR);
7199N/A+ g_remove (pipe);
7199N/A+
7199N/A+ if (fd < 0) {
7199N/A+ g_debug ("solaris_xserver_cred: could not open %s\n", pipe);
7199N/A+ return;
7199N/A+ }
7199N/A+ if (fstat (fd, &statbuf) == 0 ) {
7199N/A+ if (! S_ISFIFO(statbuf.st_mode)) {
7199N/A+ close (fd);
7199N/A+ g_debug ("solaris_xserver_cred: %s is not a pipe\n", pipe);
7199N/A+ return;
7199N/A+ }
7199N/A+ } else {
7199N/A+ close (fd);
7199N/A+ g_debug ("solaris_xserver_cred: %s does not exist\n", pipe);
7199N/A+ return;
7199N/A+ }
7199N/A+ fp = fdopen (fd, "w");
7199N/A+ if (fp == NULL) {
7199N/A+ close (fd);
7199N/A+ g_debug ("solaris_xserver_cred: could not fdopen %s\n", pipe);
7199N/A+ return;
7199N/A+ }
7199N/A+
7199N/A+ snprintf (info, sizeof(info), "GID=\"%d\"; ", passwd_entry->pw_gid);
7199N/A+ fputs (info, fp);
7199N/A+ g_debug ("solaris_xserver_cred: %s\n", info);
7199N/A+
7199N/A+ if (initgroups (username, passwd_entry->pw_gid) == -1) {
7199N/A+ ngroups = 0;
7199N/A+ } else {
7199N/A+ ngroups = getgroups (NGROUPS_UMAX, groups);
7199N/A+ }
7199N/A+
7199N/A+ for (i=0; i < ngroups; i++) {
7199N/A+ snprintf (info, sizeof(info), "G_LIST_ID=\"%u\" ", groups[i]);
7199N/A+ fputs (info, fp);
7199N/A+ g_debug ("solaris_xserver_cred: %s\n", info);
7199N/A+ }
7199N/A+
7199N/A+ if (ngroups > 0) {
7199N/A+ fputc (';', fp);
7199N/A+ }
7199N/A+
7199N/A+ snprintf (info, sizeof(info), " HOME=\"%s\" ", passwd_entry->pw_dir);
7199N/A+ fputs (info, fp);
7199N/A+ g_debug ("solaris_xserver_cred: %s\n", info);
7199N/A+
7199N/A+ snprintf (info, sizeof(info), " UID=\"%d\" EOF=\"\";", passwd_entry->pw_uid);
7199N/A+ fputs (info, fp);
7199N/A+ g_debug ("solaris_xserver_cred: %s\n", info);
7199N/A+
7199N/A+ /*
7199N/A+ * Handshake with server. Make sure it read the pipe.
7199N/A+ *
7199N/A+ * Close file descriptor.
7199N/A+ */
7199N/A+ fflush (fp);
7199N/A+ fclose (fp);
7199N/A+
7199N/A+ return;
7199N/A+}
7199N/A+#endif
7199N/A+
7199N/A static gboolean
7199N/A gdm_session_worker_start_session (GdmSessionWorker *worker,
7199N/A GError **error)
7199N/A@@ -2061,6 +2171,12 @@ gdm_session_worker_start_session (GdmSessionWorker *worker,
7199N/A worker->priv->arguments[0]);
7199N/A }
7199N/A
7199N/A+#ifdef __sun
7199N/A+ solaris_xserver_cred (worker->priv->username,
7199N/A+ passwd_entry,
7199N/A+ worker->priv->x11_display_name);
7199N/A+#endif
7199N/A+
7199N/A error_code = PAM_SUCCESS;
7199N/A
7199N/A #ifdef WITH_SYSTEMD
7199N/Adiff --git a/daemon/main.c b/daemon/main.c
7199N/Aindex ca2dda3..50f6e94 100644
7199N/A--- a/daemon/main.c
7199N/A+++ b/daemon/main.c
7199N/A@@ -324,6 +324,21 @@ main (int argc,
7199N/A
7199N/A block_sigusr1 ();
7199N/A
7199N/A+#ifdef __sun
7199N/A+ {
7199N/A+ struct stat statbuf;
7199N/A+ int r;
7199N/A+
7199N/A+ r = stat (GDM_DT_DIR, &statbuf);
7199N/A+ if (r < 0) {
7199N/A+ g_mkdir (GDM_DT_DIR, 0755);
7199N/A+ }
7199N/A+
7199N/A+ g_remove (GDM_SDTLOGIN_DIR);
7199N/A+ g_mkdir (GDM_SDTLOGIN_DIR, 0700);
7199N/A+ }
7199N/A+#endif
7199N/A+
7199N/A bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
7199N/A textdomain (GETTEXT_PACKAGE);
7199N/A setlocale (LC_ALL, "");
7199N/A--
7199N/A2.7.4
7199N/A