0001-weston-launch-Provide-a-default-version-that-doesn-t.patch 5.3 KB

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