~ubuntu-branches/ubuntu/precise/xdm/precise

« back to all changes in this revision

Viewing changes to debian/patches/selinux_support.diff

  • Committer: Bazaar Package Importer
  • Author(s): Artur Rona
  • Date: 2011-01-30 00:53:09 UTC
  • mfrom: (9.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20110130005309-30mjjyk7div7d494
Tags: 1:1.1.10-3ubuntu1
* Merge from debian unstable.  Remaining changes: (LP: #682196)
  - debian/{rules, xdm.install, local/ubuntu*}:
    + Add Ubuntu graphics and configure xdm to use them by default.
  - debian/patches/ubuntu_no_whiteglass.diff: Don't hardcode
    the default Xcursor theme to whiteglass. Use the Ubuntu
    default x-cursor-theme instead.
* debian/patches/ftbfs_binutils-gold.diff: Fix FTBFS with binutils-gold
  and ld --as-needed. (Closes: #556694)
* Dropped changes, no longer applicable:
  - debian/{xdm.postinst.in, xdm.postrm.in, xdm.preinst.in}

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From: Manoj Srivastava <srivasta@golden-gryphon.com>
2
 
Subject: xdm: add SELinux support
3
 
 
4
 
History:
5
 
Initial patch submitted in Debian bug#233551
6
 
Forward-ported to modular X by Eugene Konev (changes: remove Imakefile hunks,
7
 
add --with-selinux flag to configure.ac).
8
 
Updated to latest SE Linux code by Russell Coker 3rd Aug 2008, with bugfix from
9
 
Julien Cristau (Debian bug#493524).
10
 
 
11
 
Index: xdm/configure.ac
12
 
===================================================================
13
 
--- xdm.orig/configure.ac
14
 
+++ xdm/configure.ac
15
 
@@ -116,6 +116,23 @@
16
 
                 fi])
17
 
 fi
18
 
 
19
 
+use_selinux_default=no
20
 
+# Check for selinux support
21
 
+AC_ARG_WITH(selinux, AC_HELP_STRING([--with-selinux],[Add support for selinux]),
22
 
+       [USE_SELINUX=$withval], [USE_SELINUX=$use_selinux_default])
23
 
+if test "x$USE_SELINUX" != "xno" ; then
24
 
+       old_LIBS="$LIBS"
25
 
+       LIBS=""
26
 
+       AC_SEARCH_LIBS(is_selinux_enabled,[selinux])
27
 
+       AC_CHECK_FUNC(is_selinux_enabled,
28
 
+               [AC_DEFINE(HAVE_SELINUX,1,[Add support for selinux])],
29
 
+               [if test "x$USE_SELINUX" != "xtry" ; then
30
 
+                       AC_MSG_ERROR(["selinux support requested, but is_selinux_enabled not found."])
31
 
+                fi])
32
 
+       XDM_LIBS="$XDM_LIBS $LIBS"
33
 
+       LIBS="$old_LIBS"
34
 
+fi
35
 
+
36
 
 # FIXME: Find better test for which OS'es use su -m  - for now, just try to
37
 
 # mirror the Imakefile setting of:
38
 
 # if  defined(OpenBSDArchitecture) || defined(NetBSDArchitecture) || defined(FreeBSDArchitecture) || defined(DarwinArchitecture)
39
 
Index: xdm/session.c
40
 
===================================================================
41
 
--- xdm.orig/session.c
42
 
+++ xdm/session.c
43
 
@@ -36,6 +36,10 @@
44
 
  * session.c
45
 
  */
46
 
 
47
 
+#ifdef HAVE_CONFIG_H
48
 
+# include "config.h"
49
 
+#endif
50
 
+
51
 
 #include "dm.h"
52
 
 #include "dm_auth.h"
53
 
 #include "dm_error.h"
54
 
@@ -70,6 +74,11 @@
55
 
 #include <prot.h>
56
 
 #endif
57
 
 
58
 
+#ifdef HAVE_SELINUX
59
 
+#include <selinux/selinux.h>
60
 
+#include <selinux/get_context_list.h>
61
 
+#endif /* HAVE_SELINUX */
62
 
+
63
 
 #ifndef GREET_USER_STATIC
64
 
 # include <dlfcn.h>
65
 
 # ifndef RTLD_NOW
66
 
@@ -77,6 +86,42 @@
67
 
 # endif
68
 
 #endif
69
 
 
70
 
+#ifdef HAVE_SELINUX
71
 
+/* This should be run just before we exec the user session. */
72
 
+static int
73
 
+xdm_selinux_setup (const char *login)
74
 
+  {
75
 
+       security_context_t scontext;
76
 
+       int ret = -1;
77
 
+       char *seuser=NULL;
78
 
+       char *level=NULL;
79
 
+
80
 
+       /* If SELinux is not enabled, then we don't do anything. */
81
 
+       if ( is_selinux_enabled () <= 0)
82
 
+               return TRUE;
83
 
+
84
 
+       if (getseuserbyname(login, &seuser, &level) == 0) {
85
 
+               ret=get_default_context_with_level(seuser, level, 0, &scontext);
86
 
+               free(seuser);
87
 
+               free(level);
88
 
+       }
89
 
+       if (ret < 0 || scontext == NULL) {
90
 
+               LogError ("SELinux: unable to obtain default security context for %s\n", login);
91
 
+               return FALSE;
92
 
+       }
93
 
+
94
 
+       if (setexeccon (scontext) != 0) {
95
 
+       freecon (scontext);
96
 
+       LogError ("SELinux: unable to set executable context %s\n",
97
 
+             (char *)scontext);
98
 
+       return FALSE;
99
 
+       }
100
 
+
101
 
+       freecon (scontext);
102
 
+       return TRUE;
103
 
+}
104
 
+#endif /* HAVE_SELINUX */
105
 
+
106
 
 static int     runAndWait (char **args, char **environ);
107
 
 
108
 
 #ifdef HAVE_GRP_H
109
 
@@ -785,6 +830,17 @@
110
 
            bzero(passwd, strlen(passwd));
111
 
 
112
 
        SetUserAuthorization (d, verify);
113
 
+#ifdef HAVE_SELINUX
114
 
+   /*
115
 
+    * For Security Enhanced Linux:
116
 
+    * set the default security context for this user.
117
 
+    */
118
 
+   if ( ! xdm_selinux_setup (name)) {
119
 
+      LogError ("failed to set security context\n");
120
 
+       exit (UNMANAGE_DISPLAY);
121
 
+       return (0);
122
 
+   }
123
 
+#endif /* HAVE_SELINUX */
124
 
        home = getEnv (verify->userEnviron, "HOME");
125
 
        if (home)
126
 
            if (chdir (home) == -1) {