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