Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 1 | From a1548c742bf2dedbb47282d8a00407b60bbab669 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 |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 5 | |
Brad Bishop | c342db3 | 2019-05-15 21:57:59 -0400 | [diff] [blame] | 6 | PAM |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | |
| 8 | weston-launch requires PAM for starting weston as a non-root user. |
| 9 | |
| 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. |
| 13 | |
Andrew Geissler | 595f630 | 2022-01-24 19:11:47 +0000 | [diff] [blame] | 14 | Upstream-Status: Denied [https://gitlab.freedesktop.org/wayland/weston/-/merge_requests/725] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | |
| 16 | Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 17 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 18 | Signed-off-by: Denys Dmytriyenko <denys@ti.com> |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 19 | Signed-off-by: Ming Liu <ming.liu@toradex.com> |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 20 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | --- |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 22 | libweston/meson.build | 16 ++++++++++++---- |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 23 | libweston/weston-launch.c | 21 +++++++++++++++++++++ |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 24 | meson_options.txt | 7 +++++++ |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 25 | 3 files changed, 40 insertions(+), 4 deletions(-) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 26 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 27 | diff --git a/libweston/meson.build b/libweston/meson.build |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 28 | index 08d23ec..cb9fd3f 100644 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 29 | --- a/libweston/meson.build |
| 30 | +++ b/libweston/meson.build |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 31 | @@ -216,16 +216,24 @@ dep_vertex_clipping = declare_dependency( |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 32 | ) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 34 | if get_option('weston-launch') |
| 35 | - dep_pam = cc.find_library('pam') |
| 36 | + deps_weston_launch = [systemd_dep, dep_libdrm] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 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') |
| 44 | + endif |
| 45 | + |
| 46 | + if dep_pam.found() |
| 47 | + deps_weston_launch += dep_pam |
| 48 | + config_h.set('HAVE_PAM', '1') |
| 49 | + endif |
| 50 | endif |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 51 | |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 52 | executable( |
| 53 | 'weston-launch', |
| 54 | 'weston-launch.c', |
| 55 | - dependencies: [dep_pam, systemd_dep, dep_libdrm], |
| 56 | + dependencies: deps_weston_launch, |
Andrew Geissler | 82c905d | 2020-04-13 13:39:40 -0500 | [diff] [blame] | 57 | include_directories: common_inc, |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 58 | install: true |
| 59 | ) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 60 | diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 61 | index 521cb2c..2d42d33 100644 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 62 | --- a/libweston/weston-launch.c |
| 63 | +++ b/libweston/weston-launch.c |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | @@ -51,7 +51,9 @@ |
| 65 | |
| 66 | #include <pwd.h> |
| 67 | #include <grp.h> |
| 68 | +#ifdef HAVE_PAM |
| 69 | #include <security/pam_appl.h> |
| 70 | +#endif |
| 71 | |
| 72 | #ifdef HAVE_SYSTEMD_LOGIN |
| 73 | #include <systemd/sd-login.h> |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 74 | @@ -100,8 +102,10 @@ drmSetMaster(int drm_fd) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | #endif |
| 76 | |
| 77 | struct weston_launch { |
| 78 | +#ifdef HAVE_PAM |
| 79 | struct pam_conv pc; |
| 80 | pam_handle_t *ph; |
| 81 | +#endif |
| 82 | int tty; |
| 83 | int ttynr; |
| 84 | int sock[2]; |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 85 | @@ -192,6 +196,7 @@ weston_launch_allowed(struct weston_launch *wl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 86 | return false; |
| 87 | } |
| 88 | |
| 89 | +#ifdef HAVE_PAM |
| 90 | static int |
| 91 | pam_conversation_fn(int msg_count, |
| 92 | const struct pam_message **messages, |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 93 | @@ -232,6 +237,7 @@ setup_pam(struct weston_launch *wl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 94 | |
| 95 | return 0; |
| 96 | } |
| 97 | +#endif |
| 98 | |
| 99 | static int |
| 100 | setup_launcher_socket(struct weston_launch *wl) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 101 | @@ -466,6 +472,7 @@ quit(struct weston_launch *wl, int status) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 102 | close(wl->signalfd); |
| 103 | close(wl->sock[0]); |
| 104 | |
| 105 | +#ifdef HAVE_PAM |
| 106 | if (wl->new_user) { |
| 107 | err = pam_close_session(wl->ph, 0); |
| 108 | if (err) |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 109 | @@ -473,6 +480,7 @@ quit(struct weston_launch *wl, int status) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 110 | err, pam_strerror(wl->ph, err)); |
| 111 | pam_end(wl->ph, err); |
| 112 | } |
| 113 | +#endif |
| 114 | |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 115 | /* |
| 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) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 118 | setenv("HOME", wl->pw->pw_dir, 1); |
| 119 | setenv("SHELL", wl->pw->pw_shell, 1); |
| 120 | |
| 121 | +#ifdef HAVE_PAM |
| 122 | env = pam_getenvlist(wl->ph); |
| 123 | if (env) { |
| 124 | for (i = 0; env[i]; ++i) { |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 125 | @@ -718,6 +727,7 @@ setup_session(struct weston_launch *wl, char **child_argv) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 126 | } |
| 127 | free(env); |
| 128 | } |
| 129 | +#endif |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 130 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 131 | /* |
| 132 | * We open a new session, so it makes sense |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 133 | @@ -789,8 +799,10 @@ static void |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 134 | help(const char *name) |
| 135 | { |
| 136 | fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name); |
| 137 | +#ifdef HAVE_PAM |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 138 | fprintf(stderr, " -u, --user Start session as specified username,\n" |
| 139 | " e.g. -u joe, requires root.\n"); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 140 | +#endif |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 141 | fprintf(stderr, " -t, --tty Start session on alternative tty,\n" |
| 142 | " e.g. -t /dev/tty4, requires -u option.\n"); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 143 | fprintf(stderr, " -v, --verbose Be verbose\n"); |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 144 | @@ -804,7 +816,9 @@ main(int argc, char *argv[]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 145 | int i, c; |
| 146 | char *tty = NULL; |
| 147 | struct option opts[] = { |
| 148 | +#ifdef HAVE_PAM |
| 149 | { "user", required_argument, NULL, 'u' }, |
| 150 | +#endif |
| 151 | { "tty", required_argument, NULL, 't' }, |
| 152 | { "verbose", no_argument, NULL, 'v' }, |
| 153 | { "help", no_argument, NULL, 'h' }, |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 154 | @@ -816,11 +830,16 @@ main(int argc, char *argv[]) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 155 | while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 156 | switch (c) { |
| 157 | case 'u': |
| 158 | +#ifdef HAVE_PAM |
| 159 | wl.new_user = optarg; |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 160 | if (getuid() != 0) { |
| 161 | fprintf(stderr, "weston: Permission denied. -u allowed for root only\n"); |
| 162 | exit(EXIT_FAILURE); |
| 163 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 164 | +#else |
Brad Bishop | 79641f2 | 2019-09-10 07:20:22 -0400 | [diff] [blame] | 165 | + fprintf(stderr, "weston: -u is unsupported in this weston-launch build\n"); |
| 166 | + exit(EXIT_FAILURE); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 167 | +#endif |
| 168 | break; |
| 169 | case 't': |
| 170 | tty = optarg; |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 171 | @@ -872,8 +891,10 @@ main(int argc, char *argv[]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 172 | if (setup_tty(&wl, tty) < 0) |
| 173 | exit(EXIT_FAILURE); |
| 174 | |
| 175 | +#ifdef HAVE_PAM |
| 176 | if (wl.new_user && setup_pam(&wl) < 0) |
| 177 | exit(EXIT_FAILURE); |
| 178 | +#endif |
| 179 | |
| 180 | if (setup_launcher_socket(&wl) < 0) |
| 181 | exit(EXIT_FAILURE); |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 182 | diff --git a/meson_options.txt b/meson_options.txt |
Andrew Geissler | c9f7865 | 2020-09-18 14:11:35 -0500 | [diff] [blame] | 183 | index 239bd2d..99e4ec3 100644 |
Brad Bishop | 08902b0 | 2019-08-20 09:16:51 -0400 | [diff] [blame] | 184 | --- a/meson_options.txt |
| 185 | +++ b/meson_options.txt |
| 186 | @@ -73,6 +73,13 @@ option( |
| 187 | ) |
| 188 | |
| 189 | option( |
| 190 | + 'pam', |
| 191 | + type: 'boolean', |
| 192 | + value: true, |
| 193 | + description: 'Define if PAM is available' |
| 194 | +) |
| 195 | + |
| 196 | +option( |
| 197 | 'xwayland', |
| 198 | type: 'boolean', |
| 199 | value: true, |