blob: 81cc025371837f0ae0aedaca09087285e76e3a70 [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>
Brad Bishop08902b02019-08-20 09:16:51 -040018Signed-off-by: Ming Liu <ming.liu@toradex.com>
Patrick Williamsc0f7c042017-02-23 20:41:17 -060019---
Brad Bishop08902b02019-08-20 09:16:51 -040020 libweston/meson.build | 16 ++++++++++++----
Brad Bishop6e60e8b2018-02-01 10:27:11 -050021 libweston/weston-launch.c | 20 ++++++++++++++++++++
Brad Bishop08902b02019-08-20 09:16:51 -040022 meson_options.txt | 7 +++++++
23 3 files changed, 39 insertions(+), 4 deletions(-)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060024
Brad Bishop08902b02019-08-20 09:16:51 -040025diff --git a/libweston/meson.build b/libweston/meson.build
26index 33ab970..32f495a 100644
27--- a/libweston/meson.build
28+++ b/libweston/meson.build
29@@ -472,16 +472,24 @@ if get_option('renderer-gl')
30 endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -060031
Brad Bishop08902b02019-08-20 09:16:51 -040032 if get_option('weston-launch')
33- dep_pam = cc.find_library('pam')
34+ deps_weston_launch = [systemd_dep, dep_libdrm]
Patrick Williamsc0f7c042017-02-23 20:41:17 -060035
Brad Bishop08902b02019-08-20 09:16:51 -040036- if not cc.has_function('pam_open_session', dependencies: dep_pam)
37- error('pam_open_session not found for weston-launch')
38+ if get_option('pam')
39+ dep_pam = cc.find_library('pam')
40+ if not cc.has_function('pam_open_session', dependencies: dep_pam)
41+ error('pam_open_session not found for weston-launch')
42+ endif
43+
44+ if dep_pam.found()
45+ deps_weston_launch += dep_pam
46+ config_h.set('HAVE_PAM', '1')
47+ endif
48 endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -060049
Brad Bishop08902b02019-08-20 09:16:51 -040050 executable(
51 'weston-launch',
52 'weston-launch.c',
53- dependencies: [dep_pam, systemd_dep, dep_libdrm],
54+ dependencies: deps_weston_launch,
55 include_directories: include_directories('..'),
56 install: true
57 )
Brad Bishop6e60e8b2018-02-01 10:27:11 -050058diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
Brad Bishopc342db32019-05-15 21:57:59 -040059index 9064439..c6abe92 100644
Brad Bishop6e60e8b2018-02-01 10:27:11 -050060--- a/libweston/weston-launch.c
61+++ b/libweston/weston-launch.c
Patrick Williamsc0f7c042017-02-23 20:41:17 -060062@@ -51,7 +51,9 @@
63
64 #include <pwd.h>
65 #include <grp.h>
66+#ifdef HAVE_PAM
67 #include <security/pam_appl.h>
68+#endif
69
70 #ifdef HAVE_SYSTEMD_LOGIN
71 #include <systemd/sd-login.h>
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080072@@ -101,8 +103,10 @@ drmSetMaster(int drm_fd)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060073 #endif
74
75 struct weston_launch {
76+#ifdef HAVE_PAM
77 struct pam_conv pc;
78 pam_handle_t *ph;
79+#endif
80 int tty;
81 int ttynr;
82 int sock[2];
Brad Bishopc342db32019-05-15 21:57:59 -040083@@ -191,6 +195,7 @@ weston_launch_allowed(struct weston_launch *wl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060084 return false;
85 }
86
87+#ifdef HAVE_PAM
88 static int
89 pam_conversation_fn(int msg_count,
90 const struct pam_message **messages,
Brad Bishopc342db32019-05-15 21:57:59 -040091@@ -231,6 +236,7 @@ setup_pam(struct weston_launch *wl)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060092
93 return 0;
94 }
95+#endif
96
97 static int
98 setup_launcher_socket(struct weston_launch *wl)
Brad Bishopc342db32019-05-15 21:57:59 -040099@@ -424,6 +430,7 @@ quit(struct weston_launch *wl, int status)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600100 close(wl->signalfd);
101 close(wl->sock[0]);
102
103+#ifdef HAVE_PAM
104 if (wl->new_user) {
105 err = pam_close_session(wl->ph, 0);
106 if (err)
Brad Bishopc342db32019-05-15 21:57:59 -0400107@@ -431,6 +438,7 @@ quit(struct weston_launch *wl, int status)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600108 err, pam_strerror(wl->ph, err));
109 pam_end(wl->ph, err);
110 }
111+#endif
112
113 if (ioctl(wl->tty, KDSKBMUTE, 0) &&
114 ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
Brad Bishopc342db32019-05-15 21:57:59 -0400115@@ -610,6 +618,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600116 setenv("HOME", wl->pw->pw_dir, 1);
117 setenv("SHELL", wl->pw->pw_shell, 1);
118
119+#ifdef HAVE_PAM
120 env = pam_getenvlist(wl->ph);
121 if (env) {
122 for (i = 0; env[i]; ++i) {
Brad Bishopc342db32019-05-15 21:57:59 -0400123@@ -618,6 +627,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600124 }
125 free(env);
126 }
127+#endif
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600128
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500129 /*
130 * We open a new session, so it makes sense
Brad Bishopc342db32019-05-15 21:57:59 -0400131@@ -685,8 +695,10 @@ static void
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600132 help(const char *name)
133 {
134 fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
135+#ifdef HAVE_PAM
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800136 fprintf(stderr, " -u, --user Start session as specified username,\n"
137 " e.g. -u joe, requires root.\n");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600138+#endif
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800139 fprintf(stderr, " -t, --tty Start session on alternative tty,\n"
140 " e.g. -t /dev/tty4, requires -u option.\n");
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600141 fprintf(stderr, " -v, --verbose Be verbose\n");
Brad Bishopc342db32019-05-15 21:57:59 -0400142@@ -700,7 +712,9 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600143 int i, c;
144 char *tty = NULL;
145 struct option opts[] = {
146+#ifdef HAVE_PAM
147 { "user", required_argument, NULL, 'u' },
148+#endif
149 { "tty", required_argument, NULL, 't' },
150 { "verbose", no_argument, NULL, 'v' },
151 { "help", no_argument, NULL, 'h' },
Brad Bishopc342db32019-05-15 21:57:59 -0400152@@ -712,9 +726,13 @@ main(int argc, char *argv[])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800153 while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) {
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600154 switch (c) {
155 case 'u':
156+#ifdef HAVE_PAM
157 wl.new_user = optarg;
158 if (getuid() != 0)
159 error(1, 0, "Permission denied. -u allowed for root only");
160+#else
161+ error(1, 0, "-u is unsupported in this weston-launch build");
162+#endif
163 break;
164 case 't':
165 tty = optarg;
Brad Bishopc342db32019-05-15 21:57:59 -0400166@@ -755,8 +773,10 @@ main(int argc, char *argv[])
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600167 if (setup_tty(&wl, tty) < 0)
168 exit(EXIT_FAILURE);
169
170+#ifdef HAVE_PAM
171 if (wl.new_user && setup_pam(&wl) < 0)
172 exit(EXIT_FAILURE);
173+#endif
174
175 if (setup_launcher_socket(&wl) < 0)
176 exit(EXIT_FAILURE);
Brad Bishop08902b02019-08-20 09:16:51 -0400177diff --git a/meson_options.txt b/meson_options.txt
178index 0e1d183..9a5c3d5 100644
179--- a/meson_options.txt
180+++ b/meson_options.txt
181@@ -73,6 +73,13 @@ option(
182 )
183
184 option(
185+ 'pam',
186+ type: 'boolean',
187+ value: true,
188+ description: 'Define if PAM is available'
189+)
190+
191+option(
192 'xwayland',
193 type: 'boolean',
194 value: true,
195--
1962.7.4
197