]> code.ossystems Code Review - openembedded-core.git/blob
62b864c134c97063f2d2ccdb59207a2fec3c0a9a
[openembedded-core.git] /
1 From 5f2d71998eb77068cbaee2d468cbb296a42d5739 Mon Sep 17 00:00:00 2001
2 From: Tom Hochstein <tom.hochstein@nxp.com>
3 Date: Wed, 22 Feb 2017 15:53:30 +0200
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 Signed-off-by: Jussi Kukkonen <jussi.kukkonen@intel.com>
17 Signed-off-by: Denys Dmytriyenko <denys@ti.com>
18 Signed-off-by: Ming Liu <ming.liu@toradex.com>
19
20 ---
21  libweston/meson.build     | 16 ++++++++++++----
22  libweston/weston-launch.c | 21 +++++++++++++++++++++
23  meson_options.txt         |  7 +++++++
24  3 files changed, 40 insertions(+), 4 deletions(-)
25
26 diff --git a/libweston/meson.build b/libweston/meson.build
27 index 08d23ec..cb9fd3f 100644
28 --- a/libweston/meson.build
29 +++ b/libweston/meson.build
30 @@ -216,16 +216,24 @@ dep_vertex_clipping = declare_dependency(
31  )
32  
33  if get_option('weston-launch')
34 -       dep_pam = cc.find_library('pam')
35 +       deps_weston_launch = [systemd_dep, dep_libdrm]
36  
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
50  
51         executable(
52                 'weston-launch',
53                 'weston-launch.c',
54 -               dependencies: [dep_pam, systemd_dep, dep_libdrm],
55 +               dependencies: deps_weston_launch,
56                 include_directories: common_inc,
57                 install: true
58         )
59 diff --git a/libweston/weston-launch.c b/libweston/weston-launch.c
60 index 8a711b4..54c567a 100644
61 --- a/libweston/weston-launch.c
62 +++ b/libweston/weston-launch.c
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>
73 @@ -100,8 +102,10 @@ drmSetMaster(int drm_fd)
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];
84 @@ -192,6 +196,7 @@ weston_launch_allowed(struct weston_launch *wl)
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,
92 @@ -232,6 +237,7 @@ setup_pam(struct weston_launch *wl)
93  
94         return 0;
95  }
96 +#endif
97  
98  static int
99  setup_launcher_socket(struct weston_launch *wl)
100 @@ -431,6 +437,7 @@ quit(struct weston_launch *wl, int status)
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)
108 @@ -438,6 +445,7 @@ quit(struct weston_launch *wl, int status)
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))
116 @@ -666,6 +674,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
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) {
124 @@ -674,6 +683,7 @@ setup_session(struct weston_launch *wl, char **child_argv)
125                 }
126                 free(env);
127         }
128 +#endif
129  
130         /*
131          * We open a new session, so it makes sense
132 @@ -745,8 +755,10 @@ static void
133  help(const char *name)
134  {
135         fprintf(stderr, "Usage: %s [args...] [-- [weston args..]]\n", name);
136 +#ifdef HAVE_PAM
137         fprintf(stderr, "  -u, --user      Start session as specified username,\n"
138                         "                  e.g. -u joe, requires root.\n");
139 +#endif
140         fprintf(stderr, "  -t, --tty       Start session on alternative tty,\n"
141                         "                  e.g. -t /dev/tty4, requires -u option.\n");
142         fprintf(stderr, "  -v, --verbose   Be verbose\n");
143 @@ -760,7 +772,9 @@ main(int argc, char *argv[])
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' },
153 @@ -772,11 +786,16 @@ main(int argc, char *argv[])
154         while ((c = getopt_long(argc, argv, "u:t:vh", opts, &i)) != -1) {
155                 switch (c) {
156                 case 'u':
157 +#ifdef HAVE_PAM
158                         wl.new_user = optarg;
159                         if (getuid() != 0) {
160                                 fprintf(stderr, "weston: Permission denied. -u allowed for root only\n");
161                                 exit(EXIT_FAILURE);
162                         }
163 +#else
164 +                       fprintf(stderr, "weston: -u is unsupported in this weston-launch build\n");
165 +                       exit(EXIT_FAILURE);
166 +#endif
167                         break;
168                 case 't':
169                         tty = optarg;
170 @@ -828,8 +847,10 @@ main(int argc, char *argv[])
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);
181 diff --git a/meson_options.txt b/meson_options.txt
182 index c862ecc..73ef2c3 100644
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,