blob: 70b988898ccea35fb2c9b2fb0f9fb6ae323e3b14 [file] [log] [blame]
Brad Bishop6e60e8b2018-02-01 10:27:11 -05001From 8ff6ed03ec4079f32e9b34085414e57be4730e04 Mon Sep 17 00:00:00 2001
Patrick Williamsc0f7c042017-02-23 20:41:17 -06002From: Tom Hochstein <tom.hochstein@nxp.com>
Brad Bishop6e60e8b2018-02-01 10:27:11 -05003Date: Wed, 22 Feb 2017 15:53:30 +0200
Patrick Williamsc0f7c042017-02-23 20:41:17 -06004Subject: [PATCH] weston-launch: Provide a default version that doesn't require
5 PAM
6
7weston-launch requires PAM for starting weston as a non-root user.
8
9Since starting weston as root is a valid use case by itself, if
10PAM is not available, provide a default version of weston-launch
11without non-root-user support.
12
13Upstream-Status: Pending
14
15Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com>
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060017---
Brad Bishop6e60e8b2018-02-01 10:27:11 -050018 configure.ac | 9 +++++++--
19 libweston/weston-launch.c | 20 ++++++++++++++++++++
Patrick Williamsc0f7c042017-02-23 20:41:17 -060020 2 files changed, 27 insertions(+), 2 deletions(-)
21
22diff --git a/configure.ac b/configure.ac
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023index 46cb2c7..bb45f46 100644
Patrick Williamsc0f7c042017-02-23 20:41:17 -060024--- a/configure.ac
25+++ b/configure.ac
Brad Bishop6e60e8b2018-02-01 10:27:11 -050026@@ -435,13 +435,17 @@ AC_ARG_ENABLE(resize-optimization,
Patrick Williamsc0f7c042017-02-23 20:41:17 -060027 AS_IF([test "x$enable_resize_optimization" = "xyes"],
28 [AC_DEFINE([USE_RESIZE_POOL], [1], [Use resize memory pool as a performance optimization])])
29
30+AC_ARG_WITH(pam,
31+ AS_HELP_STRING([--with-pam], [Use PAM]),
32+ [use_pam=$withval], [use_pam=yes])
33 AC_ARG_ENABLE(weston-launch, [ --enable-weston-launch],, enable_weston_launch=yes)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034 AM_CONDITIONAL(BUILD_WESTON_LAUNCH, test x$enable_weston_launch = xyes)
35-if test x$enable_weston_launch = xyes; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036+if test x$enable_weston_launch = xyes -a x$use_pam = xyes; then
37 WESTON_SEARCH_LIBS([PAM], [pam], [pam_open_session], [have_pam=yes], [have_pam=no])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050038 if test x$have_pam = xno; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060039- AC_ERROR([weston-launch requires pam])
40+ AC_ERROR([PAM support is explicitly requested, but libpam couldn't be found])
41 fi
42+ AC_DEFINE([HAVE_PAM], [1], [Define if PAM is available])
43 fi
44
45 AM_CONDITIONAL(HAVE_PANGO, test "x$have_pango" = "xyes")
Brad Bishop6e60e8b2018-02-01 10:27:11 -050046@@ -701,6 +705,7 @@ AC_MSG_RESULT([
Patrick Williamsc0f7c042017-02-23 20:41:17 -060047 Enable developer documentation ${enable_devdocs}
48
49 weston-launch utility ${enable_weston_launch}
50+ PAM support ${use_pam}
51 systemd-login support ${have_systemd_login}
52 systemd notify support ${enable_systemd_notify}
53
Brad Bishop6e60e8b2018-02-01 10:27:11 -050054diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
55index 0491896..07e7469 100644
56--- a/libweston/weston-launch.c
57+++ b/libweston/weston-launch.c
Patrick Williamsc0f7c042017-02-23 20:41:17 -060058@@ -51,7 +51,9 @@
59
60 #include <pwd.h>
61 #include <grp.h>
62+#ifdef HAVE_PAM
63 #include <security/pam_appl.h>
64+#endif
65
66 #ifdef HAVE_SYSTEMD_LOGIN
67 #include <systemd/sd-login.h>
68@@ -93,8 +95,10 @@ drmSetMaster(int drm_fd)
69 #endif
70
71 struct weston_launch {
72+#ifdef HAVE_PAM
73 struct pam_conv pc;
74 pam_handle_t *ph;
75+#endif
76 int tty;
77 int ttynr;
78 int sock[2];
79@@ -181,6 +185,7 @@ weston_launch_allowed(struct weston_launch *wl)
80 return false;
81 }
82
83+#ifdef HAVE_PAM
84 static int
85 pam_conversation_fn(int msg_count,
86 const struct pam_message **messages,
87@@ -221,6 +226,7 @@ setup_pam(struct weston_launch *wl)
88
89 return 0;
90 }
91+#endif
92
93 static int
94 setup_launcher_socket(struct weston_launch *wl)
95@@ -414,6 +420,7 @@ quit(struct weston_launch *wl, int status)
96 close(wl->signalfd);
97 close(wl->sock[0]);
98
99+#ifdef HAVE_PAM
100 if (wl->new_user) {
101 err = pam_close_session(wl->ph, 0);
102 if (err)
103@@ -421,6 +428,7 @@ quit(struct weston_launch *wl, int status)
104 err, pam_strerror(wl->ph, err));
105 pam_end(wl->ph, err);
106 }
107+#endif
108
109 if (ioctl(wl->tty, KDSKBMUTE, 0) &&
110 ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500111@@ -600,6 +608,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600112 setenv("HOME", wl->pw->pw_dir, 1);
113 setenv("SHELL", wl->pw->pw_shell, 1);
114
115+#ifdef HAVE_PAM
116 env = pam_getenvlist(wl->ph);
117 if (env) {
118 for (i = 0; env[i]; ++i) {
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500119@@ -608,6 +617,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600120 }
121 free(env);
122 }
123+#endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600124
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500125 /*
126 * We open a new session, so it makes sense
127@@ -675,7 +685,9 @@ static void
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600128 help(const char *name)
129 {
130 fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
131+#ifdef HAVE_PAM
132 fprintf(stderr, " -u, --user Start session as specified username\n");
133+#endif
134 fprintf(stderr, " -t, --tty Start session on alternative tty\n");
135 fprintf(stderr, " -v, --verbose Be verbose\n");
136 fprintf(stderr, " -h, --help Display this help message\n");
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500137@@ -688,7 +700,9 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600138 int i, c;
139 char *tty = NULL;
140 struct option opts[] = {
141+#ifdef HAVE_PAM
142 { "user", required_argument, NULL, 'u' },
143+#endif
144 { "tty", required_argument, NULL, 't' },
145 { "verbose", no_argument, NULL, 'v' },
146 { "help", no_argument, NULL, 'h' },
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500147@@ -700,9 +714,13 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600148 while ((c = getopt_long(argc, argv, "u:t::vh", opts, &i)) != -1) {
149 switch (c) {
150 case 'u':
151+#ifdef HAVE_PAM
152 wl.new_user = optarg;
153 if (getuid() != 0)
154 error(1, 0, "Permission denied. -u allowed for root only");
155+#else
156+ error(1, 0, "-u is unsupported in this weston-launch build");
157+#endif
158 break;
159 case 't':
160 tty = optarg;
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500161@@ -740,8 +758,10 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600162 if (setup_tty(&wl, tty) < 0)
163 exit(EXIT_FAILURE);
164
165+#ifdef HAVE_PAM
166 if (wl.new_user && setup_pam(&wl) < 0)
167 exit(EXIT_FAILURE);
168+#endif
169
170 if (setup_launcher_socket(&wl) < 0)
171 exit(EXIT_FAILURE);
172--
1732.1.4
174