blob: 62b864c134c97063f2d2ccdb59207a2fec3c0a9a [file] [log] [blame]
Andrew Geissler82c905d2020-04-13 13:39:40 -05001From 5f2d71998eb77068cbaee2d468cbb296a42d5739 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>
Brad Bishop08902b02019-08-20 09:16:51 -040018Signed-off-by: Ming Liu <ming.liu@toradex.com>
Andrew Geissler82c905d2020-04-13 13:39:40 -050019
Patrick Williamsc0f7c042017-02-23 20:41:17 -060020---
Brad Bishop08902b02019-08-20 09:16:51 -040021 libweston/meson.build | 16 ++++++++++++----
Brad Bishop79641f22019-09-10 07:20:22 -040022 libweston/weston-launch.c | 21 +++++++++++++++++++++
Brad Bishop08902b02019-08-20 09:16:51 -040023 meson_options.txt | 7 +++++++
Brad Bishop79641f22019-09-10 07:20:22 -040024 3 files changed, 40 insertions(+), 4 deletions(-)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060025
Brad Bishop08902b02019-08-20 09:16:51 -040026diff --git a/libweston/meson.build b/libweston/meson.build
Andrew Geissler82c905d2020-04-13 13:39:40 -050027index 08d23ec..cb9fd3f 100644
Brad Bishop08902b02019-08-20 09:16:51 -040028--- a/libweston/meson.build
29+++ b/libweston/meson.build
Andrew Geissler82c905d2020-04-13 13:39:40 -050030@@ -216,16 +216,24 @@ dep_vertex_clipping = declare_dependency(
Brad Bishop79641f22019-09-10 07:20:22 -040031 )
Patrick Williamsc0f7c042017-02-23 20:41:17 -060032
Brad Bishop08902b02019-08-20 09:16:51 -040033 if get_option('weston-launch')
34- dep_pam = cc.find_library('pam')
35+ deps_weston_launch = [systemd_dep, dep_libdrm]
Patrick Williamsc0f7c042017-02-23 20:41:17 -060036
Brad Bishop08902b02019-08-20 09:16:51 -040037- if not cc.has_function('pam_open_session', dependencies: dep_pam)
38- error('pam_open_session not found for weston-launch')
39+ if get_option('pam')
40+ dep_pam = cc.find_library('pam')
41+ if not cc.has_function('pam_open_session', dependencies: dep_pam)
42+ error('pam_open_session not found for weston-launch')
43+ endif
44+
45+ if dep_pam.found()
46+ deps_weston_launch += dep_pam
47+ config_h.set('HAVE_PAM', '1')
48+ endif
49 endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -060050
Brad Bishop08902b02019-08-20 09:16:51 -040051 executable(
52 'weston-launch',
53 'weston-launch.c',
54- dependencies: [dep_pam, systemd_dep, dep_libdrm],
55+ dependencies: deps_weston_launch,
Andrew Geissler82c905d2020-04-13 13:39:40 -050056 include_directories: common_inc,
Brad Bishop08902b02019-08-20 09:16:51 -040057 install: true
58 )
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050060index 8a711b4..54c567a 100644
Brad Bishop6e60e8b2018-02-01 10:27:11 -050061--- a/libweston/weston-launch.c
62+++ b/libweston/weston-launch.c
Patrick Williamsc0f7c042017-02-23 20:41:17 -060063@@ -51,7 +51,9 @@
64
65 #include <pwd.h>
66 #include <grp.h>
67+#ifdef HAVE_PAM
68 #include <security/pam_appl.h>
69+#endif
70
71 #ifdef HAVE_SYSTEMD_LOGIN
72 #include <systemd/sd-login.h>
Brad Bishop79641f22019-09-10 07:20:22 -040073@@ -100,8 +102,10 @@ drmSetMaster(int drm_fd)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074 #endif
75
76 struct weston_launch {
77+#ifdef HAVE_PAM
78 struct pam_conv pc;
79 pam_handle_t *ph;
80+#endif
81 int tty;
82 int ttynr;
83 int sock[2];
Brad Bishop79641f22019-09-10 07:20:22 -040084@@ -192,6 +196,7 @@ weston_launch_allowed(struct weston_launch *wl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060085 return false;
86 }
87
88+#ifdef HAVE_PAM
89 static int
90 pam_conversation_fn(int msg_count,
91 const struct pam_message **messages,
Brad Bishop79641f22019-09-10 07:20:22 -040092@@ -232,6 +237,7 @@ setup_pam(struct weston_launch *wl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060093
94 return 0;
95 }
96+#endif
97
98 static int
99 setup_launcher_socket(struct weston_launch *wl)
Brad Bishop79641f22019-09-10 07:20:22 -0400100@@ -431,6 +437,7 @@ quit(struct weston_launch *wl, int status)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600101 close(wl->signalfd);
102 close(wl->sock[0]);
103
104+#ifdef HAVE_PAM
105 if (wl->new_user) {
106 err = pam_close_session(wl->ph, 0);
107 if (err)
Brad Bishop79641f22019-09-10 07:20:22 -0400108@@ -438,6 +445,7 @@ quit(struct weston_launch *wl, int status)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600109 err, pam_strerror(wl->ph, err));
110 pam_end(wl->ph, err);
111 }
112+#endif
113
114 if (ioctl(wl->tty, KDSKBMUTE, 0) &&
115 ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
Andrew Geissler82c905d2020-04-13 13:39:40 -0500116@@ -666,6 +674,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600117 setenv("HOME", wl->pw->pw_dir, 1);
118 setenv("SHELL", wl->pw->pw_shell, 1);
119
120+#ifdef HAVE_PAM
121 env = pam_getenvlist(wl->ph);
122 if (env) {
123 for (i = 0; env[i]; ++i) {
Andrew Geissler82c905d2020-04-13 13:39:40 -0500124@@ -674,6 +683,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600125 }
126 free(env);
127 }
128+#endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600129
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500130 /*
131 * We open a new session, so it makes sense
Andrew Geissler82c905d2020-04-13 13:39:40 -0500132@@ -745,8 +755,10 @@ static void
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600133 help(const char *name)
134 {
135 fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
136+#ifdef HAVE_PAM
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800137 fprintf(stderr, " -u, --user Start session as specified username,\n"
138 " e.g. -u joe, requires root.\n");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600139+#endif
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800140 fprintf(stderr, " -t, --tty Start session on alternative tty,\n"
141 " e.g. -t /dev/tty4, requires -u option.\n");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600142 fprintf(stderr, " -v, --verbose Be verbose\n");
Andrew Geissler82c905d2020-04-13 13:39:40 -0500143@@ -760,7 +772,9 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600144 int i, c;
145 char *tty = NULL;
146 struct option opts[] = {
147+#ifdef HAVE_PAM
148 { "user", required_argument, NULL, 'u' },
149+#endif
150 { "tty", required_argument, NULL, 't' },
151 { "verbose", no_argument, NULL, 'v' },
152 { "help", no_argument, NULL, 'h' },
Andrew Geissler82c905d2020-04-13 13:39:40 -0500153@@ -772,11 +786,16 @@ main(int argc, char *argv[])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800154 while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600155 switch (c) {
156 case 'u':
157+#ifdef HAVE_PAM
158 wl.new_user = optarg;
Brad Bishop79641f22019-09-10 07:20:22 -0400159 if (getuid() != 0) {
160 fprintf(stderr, "weston: Permission denied. -u allowed for root only\n");
161 exit(EXIT_FAILURE);
162 }
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600163+#else
Brad Bishop79641f22019-09-10 07:20:22 -0400164+ fprintf(stderr, "weston: -u is unsupported in this weston-launch build\n");
165+ exit(EXIT_FAILURE);
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600166+#endif
167 break;
168 case 't':
169 tty = optarg;
Andrew Geissler82c905d2020-04-13 13:39:40 -0500170@@ -828,8 +847,10 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600171 if (setup_tty(&wl, tty) < 0)
172 exit(EXIT_FAILURE);
173
174+#ifdef HAVE_PAM
175 if (wl.new_user && setup_pam(&wl) < 0)
176 exit(EXIT_FAILURE);
177+#endif
178
179 if (setup_launcher_socket(&wl) < 0)
180 exit(EXIT_FAILURE);
Brad Bishop08902b02019-08-20 09:16:51 -0400181diff --git a/meson_options.txt b/meson_options.txt
Andrew Geissler82c905d2020-04-13 13:39:40 -0500182index c862ecc..73ef2c3 100644
Brad Bishop08902b02019-08-20 09:16:51 -0400183--- a/meson_options.txt
184+++ b/meson_options.txt
185@@ -73,6 +73,13 @@ option(
186 )
187
188 option(
189+ 'pam',
190+ type: 'boolean',
191+ value: true,
192+ description: 'Define if PAM is available'
193+)
194+
195+option(
196 'xwayland',
197 type: 'boolean',
198 value: true,