Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 1 | From 682b7d79a7b81ec8e38760381104b24ad549e8c0 Mon Sep 17 00:00:00 2001 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 2 | From: Tom Hochstein <tom.hochstein@nxp.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3 | Date: Wed, 22 Feb 2017 15:53:30 +0200 |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 4 | Subject: [PATCH] weston-launch: Provide a default version that doesn't require |
| 5 | PAM |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 6 | |
| 7 | weston-launch requires PAM for starting weston as a non-root user. |
| 8 | |
| 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. |
| 12 | |
| 13 | Upstream-Status: Pending |
| 14 | |
| 15 | Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 17 | Signed-off-by: Denys Dmytriyenko <denys@ti.com> |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 18 | Signed-off-by: Ming Liu <ming.liu@toradex.com> |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 19 | --- |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 20 | libweston/meson.build | 16 ++++++++++++---- |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 21 | libweston/weston-launch.c | 21 +++++++++++++++++++++ |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 22 | meson_options.txt | 7 +++++++ |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 23 | 3 files changed, 40 insertions(+), 4 deletions(-) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 24 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 25 | diff --git a/libweston/meson.build b/libweston/meson.build |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 26 | index d8d3fc0..326683f 100644 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 27 | --- a/libweston/meson.build |
| 28 | +++ b/libweston/meson.build |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 29 | @@ -199,16 +199,24 @@ dep_vertex_clipping = declare_dependency( |
| 30 | ) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 31 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 32 | if get_option('weston-launch') |
| 33 | - dep_pam = cc.find_library('pam') |
| 34 | + deps_weston_launch = [systemd_dep, dep_libdrm] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 35 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 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') |
| 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 49 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 50 | 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 58 | diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 59 | index 4962bd6..fc531c5 100644 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | --- a/libweston/weston-launch.c |
| 61 | +++ b/libweston/weston-launch.c |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 62 | @@ -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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 72 | @@ -100,8 +102,10 @@ drmSetMaster(int drm_fd) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 73 | #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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 83 | @@ -192,6 +196,7 @@ weston_launch_allowed(struct weston_launch *wl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 84 | 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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 91 | @@ -232,6 +237,7 @@ setup_pam(struct weston_launch *wl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | +#endif |
| 96 | |
| 97 | static int |
| 98 | setup_launcher_socket(struct weston_launch *wl) |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 99 | @@ -431,6 +437,7 @@ quit(struct weston_launch *wl, int status) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 100 | 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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 107 | @@ -438,6 +445,7 @@ quit(struct weston_launch *wl, int status) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 108 | 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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 115 | @@ -660,6 +668,7 @@ setup_session(struct weston_launch *wl, char **child_argv) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 116 | 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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 123 | @@ -668,6 +677,7 @@ setup_session(struct weston_launch *wl, char **child_argv) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 124 | } |
| 125 | free(env); |
| 126 | } |
| 127 | +#endif |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 128 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 129 | /* |
| 130 | * We open a new session, so it makes sense |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 131 | @@ -739,8 +749,10 @@ static void |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 132 | help(const char *name) |
| 133 | { |
| 134 | fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name); |
| 135 | +#ifdef HAVE_PAM |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 136 | fprintf(stderr, " -u, --user Start session as specified username,\n" |
| 137 | " e.g. -u joe, requires root.\n"); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | +#endif |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 139 | fprintf(stderr, " -t, --tty Start session on alternative tty,\n" |
| 140 | " e.g. -t /dev/tty4, requires -u option.\n"); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 141 | fprintf(stderr, " -v, --verbose Be verbose\n"); |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 142 | @@ -754,7 +766,9 @@ main(int argc, char *argv[]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 143 | 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 Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 152 | @@ -766,11 +780,16 @@ main(int argc, char *argv[]) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 153 | while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 154 | switch (c) { |
| 155 | case 'u': |
| 156 | +#ifdef HAVE_PAM |
| 157 | wl.new_user = optarg; |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 158 | if (getuid() != 0) { |
| 159 | fprintf(stderr, "weston: Permission denied. -u allowed for root only\n"); |
| 160 | exit(EXIT_FAILURE); |
| 161 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 162 | +#else |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 163 | + fprintf(stderr, "weston: -u is unsupported in this weston-launch build\n"); |
| 164 | + exit(EXIT_FAILURE); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 165 | +#endif |
| 166 | break; |
| 167 | case 't': |
| 168 | tty = optarg; |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 169 | @@ -822,8 +841,10 @@ main(int argc, char *argv[]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 170 | if (setup_tty(&wl, tty) < 0) |
| 171 | exit(EXIT_FAILURE); |
| 172 | |
| 173 | +#ifdef HAVE_PAM |
| 174 | if (wl.new_user && setup_pam(&wl) < 0) |
| 175 | exit(EXIT_FAILURE); |
| 176 | +#endif |
| 177 | |
| 178 | if (setup_launcher_socket(&wl) < 0) |
| 179 | exit(EXIT_FAILURE); |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 180 | diff --git a/meson_options.txt b/meson_options.txt |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 181 | index d5bf1d5..254eb2b 100644 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 182 | --- a/meson_options.txt |
| 183 | +++ b/meson_options.txt |
| 184 | @@ -73,6 +73,13 @@ option( |
| 185 | ) |
| 186 | |
| 187 | option( |
| 188 | + 'pam', |
| 189 | + type: 'boolean', |
| 190 | + value: true, |
| 191 | + description: 'Define if PAM is available' |
| 192 | +) |
| 193 | + |
| 194 | +option( |
| 195 | 'xwayland', |
| 196 | type: 'boolean', |
| 197 | value: true, |
| 198 | -- |
| 199 | 2.7.4 |
| 200 | |