Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 1 | From b98b9dbda902225cdd972b5bff6a641c36cc7e90 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 | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 4 | Subject: [PATCH] weston-launch: Provide a default version that doesn't require PAM |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 5 | |
| 6 | weston-launch requires PAM for starting weston as a non-root user. |
| 7 | |
| 8 | Since starting weston as root is a valid use case by itself, if |
| 9 | PAM is not available, provide a default version of weston-launch |
| 10 | without non-root-user support. |
| 11 | |
| 12 | Upstream-Status: Pending |
| 13 | |
| 14 | Signed-off-by: Tom Hochstein <tom.hochstein@nxp.com> |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 16 | Signed-off-by: Denys Dmytriyenko <denys@ti.com> |
| 17 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 18 | --- |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 19 | configure.ac | 9 +++++++-- |
| 20 | libweston/weston-launch.c | 20 ++++++++++++++++++++ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 21 | 2 files changed, 27 insertions(+), 2 deletions(-) |
| 22 | |
| 23 | diff --git a/configure.ac b/configure.ac |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 24 | index dc9c802..48cf5cb 100644 |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 25 | --- a/configure.ac |
| 26 | +++ b/configure.ac |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 27 | @@ -451,13 +451,17 @@ AC_ARG_ENABLE(resize-optimization, |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 28 | AS_IF([test "x$enable_resize_optimization" = "xyes"], |
| 29 | [AC_DEFINE([USE_RESIZE_POOL], [1], [Use resize memory pool as a performance optimization])]) |
| 30 | |
| 31 | +AC_ARG_WITH(pam, |
| 32 | + AS_HELP_STRING([--with-pam], [Use PAM]), |
| 33 | + [use_pam=$withval], [use_pam=yes]) |
| 34 | AC_ARG_ENABLE(weston-launch, [ --enable-weston-launch],, enable_weston_launch=yes) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 35 | AM_CONDITIONAL(BUILD_WESTON_LAUNCH, test x$enable_weston_launch = xyes) |
| 36 | -if test x$enable_weston_launch = xyes; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 37 | +if test x$enable_weston_launch = xyes -a x$use_pam = xyes; then |
| 38 | WESTON_SEARCH_LIBS([PAM], [pam], [pam_open_session], [have_pam=yes], [have_pam=no]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 39 | if test x$have_pam = xno; then |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 40 | - AC_ERROR([weston-launch requires pam]) |
| 41 | + AC_ERROR([PAM support is explicitly requested, but libpam couldn't be found]) |
| 42 | fi |
| 43 | + AC_DEFINE([HAVE_PAM], [1], [Define if PAM is available]) |
| 44 | fi |
| 45 | |
| 46 | AM_CONDITIONAL(HAVE_PANGO, test "x$have_pango" = "xyes") |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 47 | @@ -702,6 +706,7 @@ AC_MSG_RESULT([ |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 48 | Enable developer documentation ${enable_devdocs} |
| 49 | |
| 50 | weston-launch utility ${enable_weston_launch} |
| 51 | + PAM support ${use_pam} |
| 52 | systemd-login support ${have_systemd_login} |
| 53 | systemd notify support ${enable_systemd_notify} |
| 54 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 55 | diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 56 | index 166bf3b..6fb9232 100644 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 57 | --- a/libweston/weston-launch.c |
| 58 | +++ b/libweston/weston-launch.c |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 59 | @@ -51,7 +51,9 @@ |
| 60 | |
| 61 | #include <pwd.h> |
| 62 | #include <grp.h> |
| 63 | +#ifdef HAVE_PAM |
| 64 | #include <security/pam_appl.h> |
| 65 | +#endif |
| 66 | |
| 67 | #ifdef HAVE_SYSTEMD_LOGIN |
| 68 | #include <systemd/sd-login.h> |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 69 | @@ -101,8 +103,10 @@ drmSetMaster(int drm_fd) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | #endif |
| 71 | |
| 72 | struct weston_launch { |
| 73 | +#ifdef HAVE_PAM |
| 74 | struct pam_conv pc; |
| 75 | pam_handle_t *ph; |
| 76 | +#endif |
| 77 | int tty; |
| 78 | int ttynr; |
| 79 | int sock[2]; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 80 | @@ -189,6 +193,7 @@ weston_launch_allowed(struct weston_launch *wl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 81 | return false; |
| 82 | } |
| 83 | |
| 84 | +#ifdef HAVE_PAM |
| 85 | static int |
| 86 | pam_conversation_fn(int msg_count, |
| 87 | const struct pam_message **messages, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 88 | @@ -229,6 +234,7 @@ setup_pam(struct weston_launch *wl) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 89 | |
| 90 | return 0; |
| 91 | } |
| 92 | +#endif |
| 93 | |
| 94 | static int |
| 95 | setup_launcher_socket(struct weston_launch *wl) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 96 | @@ -422,6 +428,7 @@ quit(struct weston_launch *wl, int status) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 97 | close(wl->signalfd); |
| 98 | close(wl->sock[0]); |
| 99 | |
| 100 | +#ifdef HAVE_PAM |
| 101 | if (wl->new_user) { |
| 102 | err = pam_close_session(wl->ph, 0); |
| 103 | if (err) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 104 | @@ -429,6 +436,7 @@ quit(struct weston_launch *wl, int status) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 105 | err, pam_strerror(wl->ph, err)); |
| 106 | pam_end(wl->ph, err); |
| 107 | } |
| 108 | +#endif |
| 109 | |
| 110 | if (ioctl(wl->tty, KDSKBMUTE, 0) && |
| 111 | ioctl(wl->tty, KDSKBMODE, wl->kb_mode)) |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 112 | @@ -608,6 +616,7 @@ setup_session(struct weston_launch *wl, char **child_argv) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 113 | setenv("HOME", wl->pw->pw_dir, 1); |
| 114 | setenv("SHELL", wl->pw->pw_shell, 1); |
| 115 | |
| 116 | +#ifdef HAVE_PAM |
| 117 | env = pam_getenvlist(wl->ph); |
| 118 | if (env) { |
| 119 | for (i = 0; env[i]; ++i) { |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 120 | @@ -616,6 +625,7 @@ setup_session(struct weston_launch *wl, char **child_argv) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 121 | } |
| 122 | free(env); |
| 123 | } |
| 124 | +#endif |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 125 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 126 | /* |
| 127 | * We open a new session, so it makes sense |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 128 | @@ -683,8 +693,10 @@ static void |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 129 | help(const char *name) |
| 130 | { |
| 131 | fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name); |
| 132 | +#ifdef HAVE_PAM |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 133 | fprintf(stderr, " -u, --user Start session as specified username,\n" |
| 134 | " e.g. -u joe, requires root.\n"); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 135 | +#endif |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 136 | fprintf(stderr, " -t, --tty Start session on alternative tty,\n" |
| 137 | " e.g. -t /dev/tty4, requires -u option.\n"); |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 138 | fprintf(stderr, " -v, --verbose Be verbose\n"); |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 139 | @@ -698,7 +710,9 @@ main(int argc, char *argv[]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 140 | int i, c; |
| 141 | char *tty = NULL; |
| 142 | struct option opts[] = { |
| 143 | +#ifdef HAVE_PAM |
| 144 | { "user", required_argument, NULL, 'u' }, |
| 145 | +#endif |
| 146 | { "tty", required_argument, NULL, 't' }, |
| 147 | { "verbose", no_argument, NULL, 'v' }, |
| 148 | { "help", no_argument, NULL, 'h' }, |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 149 | @@ -710,9 +724,13 @@ main(int argc, char *argv[]) |
| 150 | while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) { |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 151 | switch (c) { |
| 152 | case 'u': |
| 153 | +#ifdef HAVE_PAM |
| 154 | wl.new_user = optarg; |
| 155 | if (getuid() != 0) |
| 156 | error(1, 0, "Permission denied. -u allowed for root only"); |
| 157 | +#else |
| 158 | + error(1, 0, "-u is unsupported in this weston-launch build"); |
| 159 | +#endif |
| 160 | break; |
| 161 | case 't': |
| 162 | tty = optarg; |
Brad Bishop | 1a4b7ee | 2018-12-16 17:11:34 -0800 | [diff] [blame] | 163 | @@ -753,8 +771,10 @@ main(int argc, char *argv[]) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 164 | if (setup_tty(&wl, tty) < 0) |
| 165 | exit(EXIT_FAILURE); |
| 166 | |
| 167 | +#ifdef HAVE_PAM |
| 168 | if (wl.new_user && setup_pam(&wl) < 0) |
| 169 | exit(EXIT_FAILURE); |
| 170 | +#endif |
| 171 | |
| 172 | if (setup_launcher_socket(&wl) < 0) |
| 173 | exit(EXIT_FAILURE); |