]> code.ossystems Code Review - openembedded-core.git/blob
5542036be2fbfd586cd99aa875ee25b858c7c1d6
[openembedded-core.git] /
1 From d02226b3d5872b184c1d50c7f4706ac9467ffb81 Mon Sep 17 00:00:00 2001
2 From: Tom Hochstein <tom.hochstein@nxp.com>
3 Date: Fri, 15 Jul 2016 11:00:15 +0300
4 Subject: [PATCH] weston-launch: Provide a default version that doesn't require
5  PAM
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>
16 ---
17  configure.ac        |  9 +++++++--
18  src/weston-launch.c | 20 ++++++++++++++++++++
19  2 files changed, 27 insertions(+), 2 deletions(-)
20
21 diff --git a/configure.ac b/configure.ac
22 index 32fdde7..240966f 100644
23 --- a/configure.ac
24 +++ b/configure.ac
25 @@ -416,13 +416,17 @@ AC_ARG_ENABLE(resize-optimization,
26  AS_IF([test "x$enable_resize_optimization" = "xyes"],
27        [AC_DEFINE([USE_RESIZE_POOL], [1], [Use resize memory pool as a performance optimization])])
28  
29 +AC_ARG_WITH(pam,
30 +            AS_HELP_STRING([--with-pam], [Use PAM]),
31 +            [use_pam=$withval], [use_pam=yes])
32  AC_ARG_ENABLE(weston-launch, [  --enable-weston-launch],, enable_weston_launch=yes)
33  AM_CONDITIONAL(BUILD_WESTON_LAUNCH, test x$enable_weston_launch == xyes)
34 -if test x$enable_weston_launch == xyes; then
35 +if test x$enable_weston_launch = xyes -a x$use_pam = xyes; then
36    WESTON_SEARCH_LIBS([PAM], [pam], [pam_open_session], [have_pam=yes], [have_pam=no])
37    if test x$have_pam == xno; then
38 -    AC_ERROR([weston-launch requires pam])
39 +    AC_ERROR([PAM support is explicitly requested, but libpam couldn't be found])
40    fi
41 +  AC_DEFINE([HAVE_PAM], [1], [Define if PAM is available])
42  fi
43  
44  AM_CONDITIONAL(HAVE_PANGO, test "x$have_pango" = "xyes")
45 @@ -673,6 +677,7 @@ AC_MSG_RESULT([
46         Enable developer documentation  ${enable_devdocs}
47  
48         weston-launch utility           ${enable_weston_launch}
49 +       PAM support                     ${use_pam}
50         systemd-login support           ${have_systemd_login}
51         systemd notify support          ${enable_systemd_notify}
52  
53 diff --git a/src/weston-launch.c b/src/weston-launch.c
54 index b8b2ba0..a865061 100644
55 --- a/src/weston-launch.c
56 +++ b/src/weston-launch.c
57 @@ -51,7 +51,9 @@
58  
59  #include <pwd.h>
60  #include <grp.h>
61 +#ifdef HAVE_PAM
62  #include <security/pam_appl.h>
63 +#endif
64  
65  #ifdef HAVE_SYSTEMD_LOGIN
66  #include <systemd/sd-login.h>
67 @@ -93,8 +95,10 @@ drmSetMaster(int drm_fd)
68  #endif
69  
70  struct weston_launch {
71 +#ifdef HAVE_PAM
72         struct pam_conv pc;
73         pam_handle_t *ph;
74 +#endif
75         int tty;
76         int ttynr;
77         int sock[2];
78 @@ -181,6 +185,7 @@ weston_launch_allowed(struct weston_launch *wl)
79         return false;
80  }
81  
82 +#ifdef HAVE_PAM
83  static int
84  pam_conversation_fn(int msg_count,
85                     const struct pam_message **messages,
86 @@ -221,6 +226,7 @@ setup_pam(struct weston_launch *wl)
87  
88         return 0;
89  }
90 +#endif
91  
92  static int
93  setup_launcher_socket(struct weston_launch *wl)
94 @@ -414,6 +420,7 @@ quit(struct weston_launch *wl, int status)
95         close(wl->signalfd);
96         close(wl->sock[0]);
97  
98 +#ifdef HAVE_PAM
99         if (wl->new_user) {
100                 err = pam_close_session(wl->ph, 0);
101                 if (err)
102 @@ -421,6 +428,7 @@ quit(struct weston_launch *wl, int status)
103                                 err, pam_strerror(wl->ph, err));
104                 pam_end(wl->ph, err);
105         }
106 +#endif
107  
108         if (ioctl(wl->tty, KDSKBMUTE, 0) &&
109             ioctl(wl->tty, KDSKBMODE, wl->kb_mode))
110 @@ -600,6 +608,7 @@ setup_session(struct weston_launch *wl)
111         setenv("HOME", wl->pw->pw_dir, 1);
112         setenv("SHELL", wl->pw->pw_shell, 1);
113  
114 +#ifdef HAVE_PAM
115         env = pam_getenvlist(wl->ph);
116         if (env) {
117                 for (i = 0; env[i]; ++i) {
118 @@ -608,6 +617,7 @@ setup_session(struct weston_launch *wl)
119                 }
120                 free(env);
121         }
122 +#endif
123  }
124  
125  static void
126 @@ -665,7 +675,9 @@ static void
127  help(const char *name)
128  {
129         fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
130 +#ifdef HAVE_PAM
131         fprintf(stderr, "  -u, --user      Start session as specified username\n");
132 +#endif
133         fprintf(stderr, "  -t, --tty       Start session on alternative tty\n");
134         fprintf(stderr, "  -v, --verbose   Be verbose\n");
135         fprintf(stderr, "  -h, --help      Display this help message\n");
136 @@ -678,7 +690,9 @@ main(int argc, char *argv[])
137         int i, c;
138         char *tty = NULL;
139         struct option opts[] = {
140 +#ifdef HAVE_PAM
141                 { "user",    required_argument, NULL, 'u' },
142 +#endif
143                 { "tty",     required_argument, NULL, 't' },
144                 { "verbose", no_argument,       NULL, 'v' },
145                 { "help",    no_argument,       NULL, 'h' },
146 @@ -690,9 +704,13 @@ main(int argc, char *argv[])
147         while ((c = getopt_long(argc, argv, "u:t::vh", opts, &i)) != -1) {
148                 switch (c) {
149                 case 'u':
150 +#ifdef HAVE_PAM
151                         wl.new_user = optarg;
152                         if (getuid() != 0)
153                                 error(1, 0, "Permission denied. -u allowed for root only");
154 +#else
155 +                       error(1, 0, "-u is unsupported in this weston-launch build");
156 +#endif
157                         break;
158                 case 't':
159                         tty = optarg;
160 @@ -730,8 +748,10 @@ main(int argc, char *argv[])
161         if (setup_tty(&wl, tty) < 0)
162                 exit(EXIT_FAILURE);
163  
164 +#ifdef HAVE_PAM
165         if (wl.new_user && setup_pam(&wl) < 0)
166                 exit(EXIT_FAILURE);
167 +#endif
168  
169         if (setup_launcher_socket(&wl) < 0)
170                 exit(EXIT_FAILURE);
171 -- 
172 2.1.4
173