blob: a2f61bfdd3e4b713ba479745185f0697d9042f10 [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001From 7d2fea61a95e9498b5a19c8cffcb2ab5631d5685 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
Brad Bishopc342db32019-05-15 21:57:59 -04004Subject: [PATCH] weston-launch: Provide a default version that doesn't require
5 PAM
Patrick Williamsc0f7c042017-02-23 20:41:17 -06006
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>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080017Signed-off-by: Denys Dmytriyenko <denys@ti.com>
18
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019---
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 configure.ac | 9 +++++++--
21 libweston/weston-launch.c | 20 ++++++++++++++++++++
Patrick Williamsc0f7c042017-02-23 20:41:17 -060022 2 files changed, 27 insertions(+), 2 deletions(-)
23
24diff --git a/configure.ac b/configure.ac
Brad Bishopc342db32019-05-15 21:57:59 -040025index 6da6e04..681f7c8 100644
Patrick Williamsc0f7c042017-02-23 20:41:17 -060026--- a/configure.ac
27+++ b/configure.ac
Brad Bishopc342db32019-05-15 21:57:59 -040028@@ -515,13 +515,17 @@ AC_ARG_ENABLE(resize-optimization,
Patrick Williamsc0f7c042017-02-23 20:41:17 -060029 AS_IF([test "x$enable_resize_optimization" = "xyes"],
30 [AC_DEFINE([USE_RESIZE_POOL], [1], [Use resize memory pool as a performance optimization])])
31
32+AC_ARG_WITH(pam,
33+ AS_HELP_STRING([--with-pam], [Use PAM]),
34+ [use_pam=$withval], [use_pam=yes])
35 AC_ARG_ENABLE(weston-launch, [ --enable-weston-launch],, enable_weston_launch=yes)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050036 AM_CONDITIONAL(BUILD_WESTON_LAUNCH, test x$enable_weston_launch = xyes)
37-if test x$enable_weston_launch = xyes; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038+if test x$enable_weston_launch = xyes -a x$use_pam = xyes; then
39 WESTON_SEARCH_LIBS([PAM], [pam], [pam_open_session], [have_pam=yes], [have_pam=no])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050040 if test x$have_pam = xno; then
Patrick Williamsc0f7c042017-02-23 20:41:17 -060041- AC_ERROR([weston-launch requires pam])
42+ AC_ERROR([PAM support is explicitly requested, but libpam couldn't be found])
43 fi
44+ AC_DEFINE([HAVE_PAM], [1], [Define if PAM is available])
45 fi
46
47 AM_CONDITIONAL(HAVE_PANGO, test "x$have_pango" = "xyes")
Brad Bishopc342db32019-05-15 21:57:59 -040048@@ -767,6 +771,7 @@ AC_MSG_RESULT([
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049 Enable developer documentation ${enable_devdocs}
50
51 weston-launch utility ${enable_weston_launch}
52+ PAM support ${use_pam}
53 systemd-login support ${have_systemd_login}
54 systemd notify support ${enable_systemd_notify}
55
Brad Bishop6e60e8b2018-02-01 10:27:11 -050056diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
Brad Bishopc342db32019-05-15 21:57:59 -040057index 9064439..c6abe92 100644
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058--- a/libweston/weston-launch.c
59+++ b/libweston/weston-launch.c
Patrick Williamsc0f7c042017-02-23 20:41:17 -060060@@ -51,7 +51,9 @@
61
62 #include <pwd.h>
63 #include <grp.h>
64+#ifdef HAVE_PAM
65 #include <security/pam_appl.h>
66+#endif
67
68 #ifdef HAVE_SYSTEMD_LOGIN
69 #include <systemd/sd-login.h>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080070@@ -101,8 +103,10 @@ drmSetMaster(int drm_fd)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060071 #endif
72
73 struct weston_launch {
74+#ifdef HAVE_PAM
75 struct pam_conv pc;
76 pam_handle_t *ph;
77+#endif
78 int tty;
79 int ttynr;
80 int sock[2];
Brad Bishopc342db32019-05-15 21:57:59 -040081@@ -191,6 +195,7 @@ weston_launch_allowed(struct weston_launch *wl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060082 return false;
83 }
84
85+#ifdef HAVE_PAM
86 static int
87 pam_conversation_fn(int msg_count,
88 const struct pam_message **messages,
Brad Bishopc342db32019-05-15 21:57:59 -040089@@ -231,6 +236,7 @@ setup_pam(struct weston_launch *wl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060090
91 return 0;
92 }
93+#endif
94
95 static int
96 setup_launcher_socket(struct weston_launch *wl)
Brad Bishopc342db32019-05-15 21:57:59 -040097@@ -424,6 +430,7 @@ quit(struct weston_launch *wl, int status)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060098 close(wl->signalfd);
99 close(wl->sock[0]);
100
101+#ifdef HAVE_PAM
102 if (wl->new_user) {
103 err = pam_close_session(wl->ph, 0);
104 if (err)
Brad Bishopc342db32019-05-15 21:57:59 -0400105@@ -431,6 +438,7 @@ quit(struct weston_launch *wl, int status)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600106 err, pam_strerror(wl->ph, err));
107 pam_end(wl->ph, err);
108 }
109+#endif
110
111 if (ioctl(wl->tty, KDSKBMUTE, 0) &&
112 ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
Brad Bishopc342db32019-05-15 21:57:59 -0400113@@ -610,6 +618,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600114 setenv("HOME", wl->pw->pw_dir, 1);
115 setenv("SHELL", wl->pw->pw_shell, 1);
116
117+#ifdef HAVE_PAM
118 env = pam_getenvlist(wl->ph);
119 if (env) {
120 for (i = 0; env[i]; ++i) {
Brad Bishopc342db32019-05-15 21:57:59 -0400121@@ -618,6 +627,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600122 }
123 free(env);
124 }
125+#endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600126
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500127 /*
128 * We open a new session, so it makes sense
Brad Bishopc342db32019-05-15 21:57:59 -0400129@@ -685,8 +695,10 @@ static void
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600130 help(const char *name)
131 {
132 fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
133+#ifdef HAVE_PAM
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800134 fprintf(stderr, " -u, --user Start session as specified username,\n"
135 " e.g. -u joe, requires root.\n");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600136+#endif
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137 fprintf(stderr, " -t, --tty Start session on alternative tty,\n"
138 " e.g. -t /dev/tty4, requires -u option.\n");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600139 fprintf(stderr, " -v, --verbose Be verbose\n");
Brad Bishopc342db32019-05-15 21:57:59 -0400140@@ -700,7 +712,9 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600141 int i, c;
142 char *tty = NULL;
143 struct option opts[] = {
144+#ifdef HAVE_PAM
145 { "user", required_argument, NULL, 'u' },
146+#endif
147 { "tty", required_argument, NULL, 't' },
148 { "verbose", no_argument, NULL, 'v' },
149 { "help", no_argument, NULL, 'h' },
Brad Bishopc342db32019-05-15 21:57:59 -0400150@@ -712,9 +726,13 @@ main(int argc, char *argv[])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800151 while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600152 switch (c) {
153 case 'u':
154+#ifdef HAVE_PAM
155 wl.new_user = optarg;
156 if (getuid() != 0)
157 error(1, 0, "Permission denied. -u allowed for root only");
158+#else
159+ error(1, 0, "-u is unsupported in this weston-launch build");
160+#endif
161 break;
162 case 't':
163 tty = optarg;
Brad Bishopc342db32019-05-15 21:57:59 -0400164@@ -755,8 +773,10 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600165 if (setup_tty(&wl, tty) < 0)
166 exit(EXIT_FAILURE);
167
168+#ifdef HAVE_PAM
169 if (wl.new_user && setup_pam(&wl) < 0)
170 exit(EXIT_FAILURE);
171+#endif
172
173 if (setup_launcher_socket(&wl) < 0)
174 exit(EXIT_FAILURE);