1 From 682b7d79a7b81ec8e38760381104b24ad549e8c0 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
7 weston-launch requires PAM for starting weston as a non-root user.
9 Since starting weston as root is a valid use case by itself, if
10 PAM is not available, provide a default version of weston-launch
11 without non-root-user support.
13 Upstream-Status: Pending
15 Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com>
16 Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
17 Signed-off-by: Denys Dmytriyenko <denys@ti.com>
18 Signed-off-by: Ming Liu <ming.liu@toradex.com>
20 libweston/meson.build | 16 ++++++++++++----
21 libweston/weston-launch.c | 21 +++++++++++++++++++++
22 meson_options.txt | 7 +++++++
23 3 files changed, 40 insertions(+), 4 deletions(-)
25 diff --git a/libweston/meson.build b/libweston/meson.build
26 index d8d3fc0..326683f 100644
27 --- a/libweston/meson.build
28 +++ b/libweston/meson.build
29 @@ -199,16 +199,24 @@ dep_vertex_clipping = declare_dependency(
32 if get_option('weston-launch')
33 - dep_pam = cc.find_library('pam')
34 + deps_weston_launch = [systemd_dep, dep_libdrm]
36 - 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')
45 + deps_weston_launch += dep_pam
46 + config_h.set('HAVE_PAM', '1')
53 - dependencies: [dep_pam, systemd_dep, dep_libdrm],
54 + dependencies: deps_weston_launch,
55 include_directories: include_directories('..'),
58 diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
59 index 4962bd6..fc531c5 100644
60 --- a/libweston/weston-launch.c
61 +++ b/libweston/weston-launch.c
67 #include <security/pam_appl.h>
70 #ifdef HAVE_SYSTEMD_LOGIN
71 #include <systemd/sd-login.h>
72 @@ -100,8 +102,10 @@ drmSetMaster(int drm_fd)
75 struct weston_launch {
83 @@ -192,6 +196,7 @@ weston_launch_allowed(struct weston_launch *wl)
89 pam_conversation_fn(int msg_count,
90 const struct pam_message **messages,
91 @@ -232,6 +237,7 @@ setup_pam(struct weston_launch *wl)
98 setup_launcher_socket(struct weston_launch *wl)
99 @@ -431,6 +437,7 @@ quit(struct weston_launch *wl, int status)
105 err = pam_close_session(wl->ph, 0);
107 @@ -438,6 +445,7 @@ quit(struct weston_launch *wl, int status)
108 err, pam_strerror(wl->ph, err));
109 pam_end(wl->ph, err);
113 if (ioctl(wl->tty, KDSKBMUTE, 0) &&
114 ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
115 @@ -660,6 +668,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
116 setenv("HOME", wl->pw->pw_dir, 1);
117 setenv("SHELL", wl->pw->pw_shell, 1);
120 env = pam_getenvlist(wl->ph);
122 for (i = 0; env[i]; ++i) {
123 @@ -668,6 +677,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
130 * We open a new session, so it makes sense
131 @@ -739,8 +749,10 @@ static void
132 help(const char *name)
134 fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
136 fprintf(stderr, " -u, --user Start session as specified username,\n"
137 " e.g. -u joe, requires root.\n");
139 fprintf(stderr, " -t, --tty Start session on alternative tty,\n"
140 " e.g. -t /dev/tty4, requires -u option.\n");
141 fprintf(stderr, " -v, --verbose Be verbose\n");
142 @@ -754,7 +766,9 @@ main(int argc, char *argv[])
145 struct option opts[] = {
147 { "user", required_argument, NULL, 'u' },
149 { "tty", required_argument, NULL, 't' },
150 { "verbose", no_argument, NULL, 'v' },
151 { "help", no_argument, NULL, 'h' },
152 @@ -766,11 +780,16 @@ main(int argc, char *argv[])
153 while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) {
157 wl.new_user = optarg;
159 fprintf(stderr, "weston: Permission denied. -u allowed for root only\n");
163 + fprintf(stderr, "weston: -u is unsupported in this weston-launch build\n");
164 + exit(EXIT_FAILURE);
169 @@ -822,8 +841,10 @@ main(int argc, char *argv[])
170 if (setup_tty(&wl, tty) < 0)
174 if (wl.new_user && setup_pam(&wl) < 0)
178 if (setup_launcher_socket(&wl) < 0)
180 diff --git a/meson_options.txt b/meson_options.txt
181 index d5bf1d5..254eb2b 100644
182 --- a/meson_options.txt
183 +++ b/meson_options.txt
184 @@ -73,6 +73,13 @@ option(
191 + description: 'Define if PAM is available'