1 From a1548c742bf2dedbb47282d8a00407b60bbab669 Mon Sep 17 00:00:00 2001
2 From: Tom Hochstein <tom.hochstein@nxp.com>
3 Date: Wed, 22 Feb 2017 15:53:30 +0200
4 Subject: [PATCH] weston-launch: Provide a default version that doesn't require
8 weston-launch requires PAM for starting weston as a non-root user.
10 Since starting weston as root is a valid use case by itself, if
11 PAM is not available, provide a default version of weston-launch
12 without non-root-user support.
14 Upstream-Status: Submitted [https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/725]
16 Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com>
17 Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
18 Signed-off-by: Denys Dmytriyenko <denys@ti.com>
19 Signed-off-by: Ming Liu <ming.liu@toradex.com>
22 libweston/meson.build | 16 ++++++++++++----
23 libweston/weston-launch.c | 21 +++++++++++++++++++++
24 meson_options.txt | 7 +++++++
25 3 files changed, 40 insertions(+), 4 deletions(-)
27 diff --git a/libweston/meson.build b/libweston/meson.build
28 index 08d23ec..cb9fd3f 100644
29 --- a/libweston/meson.build
30 +++ b/libweston/meson.build
31 @@ -216,16 +216,24 @@ dep_vertex_clipping = declare_dependency(
34 if get_option('weston-launch')
35 - dep_pam = cc.find_library('pam')
36 + deps_weston_launch = [systemd_dep, dep_libdrm]
38 - if not cc.has_function('pam_open_session', dependencies: dep_pam)
39 - error('pam_open_session not found for weston-launch')
40 + if get_option('pam')
41 + dep_pam = cc.find_library('pam')
42 + if not cc.has_function('pam_open_session', dependencies: dep_pam)
43 + error('pam_open_session not found for weston-launch')
47 + deps_weston_launch += dep_pam
48 + config_h.set('HAVE_PAM', '1')
55 - dependencies: [dep_pam, systemd_dep, dep_libdrm],
56 + dependencies: deps_weston_launch,
57 include_directories: common_inc,
60 diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
61 index 521cb2c..2d42d33 100644
62 --- a/libweston/weston-launch.c
63 +++ b/libweston/weston-launch.c
69 #include <security/pam_appl.h>
72 #ifdef HAVE_SYSTEMD_LOGIN
73 #include <systemd/sd-login.h>
74 @@ -100,8 +102,10 @@ drmSetMaster(int drm_fd)
77 struct weston_launch {
85 @@ -192,6 +196,7 @@ weston_launch_allowed(struct weston_launch *wl)
91 pam_conversation_fn(int msg_count,
92 const struct pam_message **messages,
93 @@ -232,6 +237,7 @@ setup_pam(struct weston_launch *wl)
100 setup_launcher_socket(struct weston_launch *wl)
101 @@ -466,6 +472,7 @@ quit(struct weston_launch *wl, int status)
107 err = pam_close_session(wl->ph, 0);
109 @@ -473,6 +480,7 @@ quit(struct weston_launch *wl, int status)
110 err, pam_strerror(wl->ph, err));
111 pam_end(wl->ph, err);
116 * Get a fresh handle to the tty as the previous one is in
117 @@ -710,6 +718,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
118 setenv("HOME", wl->pw->pw_dir, 1);
119 setenv("SHELL", wl->pw->pw_shell, 1);
122 env = pam_getenvlist(wl->ph);
124 for (i = 0; env[i]; ++i) {
125 @@ -718,6 +727,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
132 * We open a new session, so it makes sense
133 @@ -789,8 +799,10 @@ static void
134 help(const char *name)
136 fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
138 fprintf(stderr, " -u, --user Start session as specified username,\n"
139 " e.g. -u joe, requires root.\n");
141 fprintf(stderr, " -t, --tty Start session on alternative tty,\n"
142 " e.g. -t /dev/tty4, requires -u option.\n");
143 fprintf(stderr, " -v, --verbose Be verbose\n");
144 @@ -804,7 +816,9 @@ main(int argc, char *argv[])
147 struct option opts[] = {
149 { "user", required_argument, NULL, 'u' },
151 { "tty", required_argument, NULL, 't' },
152 { "verbose", no_argument, NULL, 'v' },
153 { "help", no_argument, NULL, 'h' },
154 @@ -816,11 +830,16 @@ main(int argc, char *argv[])
155 while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) {
159 wl.new_user = optarg;
161 fprintf(stderr, "weston: Permission denied. -u allowed for root only\n");
165 + fprintf(stderr, "weston: -u is unsupported in this weston-launch build\n");
166 + exit(EXIT_FAILURE);
171 @@ -872,8 +891,10 @@ main(int argc, char *argv[])
172 if (setup_tty(&wl, tty) < 0)
176 if (wl.new_user && setup_pam(&wl) < 0)
180 if (setup_launcher_socket(&wl) < 0)
182 diff --git a/meson_options.txt b/meson_options.txt
183 index 239bd2d..99e4ec3 100644
184 --- a/meson_options.txt
185 +++ b/meson_options.txt
186 @@ -73,6 +73,13 @@ option(
193 + description: 'Define if PAM is available'