You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

92 lines
3.0 KiB

  1. From c31d49234f0c7a81b69d525e249b154e11c486a9 Mon Sep 17 00:00:00 2001
  2. From: Michal Vasilek <michal.vasilek@nic.cz>
  3. Date: Thu, 12 Aug 2021 15:57:01 +0200
  4. Subject: [PATCH] utils: use internal which implementation
  5. * removes runtime dependency on which
  6. * fixes aa-unconfined when ss is installed outside {/usr,}/bin
  7. Signed-off-by: Michal Vasilek <michal.vasilek@nic.cz>
  8. ---
  9. utils/aa-unconfined | 2 +-
  10. utils/apparmor/easyprof.py | 8 +++-----
  11. utils/apparmor/sandbox.py | 10 ++++------
  12. 3 files changed, 8 insertions(+), 12 deletions(-)
  13. --- a/utils/aa-unconfined
  14. +++ b/utils/aa-unconfined
  15. @@ -116,7 +116,7 @@ def read_proc_current(filename):
  16. pids = set()
  17. if paranoid:
  18. pids = get_all_pids()
  19. -elif args.with_ss or (not args.with_netstat and (os.path.exists('/bin/ss') or os.path.exists('/usr/bin/ss'))):
  20. +elif args.with_ss or (not args.with_netstat and (aa.which("ss") is not None)):
  21. pids = get_pids_ss()
  22. else:
  23. pids = get_pids_netstat()
  24. --- a/utils/apparmor/easyprof.py
  25. +++ b/utils/apparmor/easyprof.py
  26. @@ -22,6 +22,8 @@ import subprocess
  27. import sys
  28. import tempfile
  29. +from apparmor.aa import which
  30. +
  31. #
  32. # TODO: move this out to the common library
  33. #
  34. @@ -294,13 +296,9 @@ class AppArmorEasyProfile:
  35. if os.path.isfile(self.conffile):
  36. self._get_defaults()
  37. - self.parser_path = '/sbin/apparmor_parser'
  38. + self.parser_path = which('apparmor_parser')
  39. if opt.parser_path:
  40. self.parser_path = opt.parser_path
  41. - elif not os.path.exists(self.parser_path):
  42. - rc, self.parser_path = cmd(['which', 'apparmor_parser'])
  43. - if rc != 0:
  44. - self.parser_path = None
  45. self.parser_base = "/etc/apparmor.d"
  46. if opt.parser_base:
  47. --- a/utils/apparmor/sandbox.py
  48. +++ b/utils/apparmor/sandbox.py
  49. @@ -9,6 +9,7 @@
  50. # ------------------------------------------------------------------
  51. from apparmor.common import AppArmorException, debug, error, msg, cmd
  52. +from apparmor.aa import which
  53. import apparmor.easyprof
  54. import optparse
  55. import os
  56. @@ -31,8 +32,7 @@ def check_requirements(binary):
  57. for e in exes:
  58. debug("Searching for '%s'" % e)
  59. - rc, report = cmd(['which', e])
  60. - if rc != 0:
  61. + if which(e) is None:
  62. error("Could not find '%s'" % e, do_exit=False)
  63. return False
  64. @@ -306,8 +306,7 @@ class SandboxXephyr(SandboxXserver):
  65. def start(self):
  66. for e in ['Xephyr', 'matchbox-window-manager']:
  67. debug("Searching for '%s'" % e)
  68. - rc, report = cmd(['which', e])
  69. - if rc != 0:
  70. + if which(e) is None:
  71. raise AppArmorException("Could not find '%s'" % e)
  72. '''Run any setup code'''
  73. @@ -567,8 +566,7 @@ EndSection
  74. def start(self):
  75. debug("Searching for '%s'" % 'xpra')
  76. - rc, report = cmd(['which', 'xpra'])
  77. - if rc != 0:
  78. + if which('xpra') is None:
  79. raise AppArmorException("Could not find '%s'" % 'xpra')
  80. if self.driver == "xdummy":