0001-python-sepolgen-fix-ausearch-path.patch 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. From 8610efc1610a4e9d4cbfa19ed4a519a6425aee70 Mon Sep 17 00:00:00 2001
  2. From: "Yann E. MORIN" <yann.morin.1998@free.fr>
  3. Date: Tue, 9 May 2023 22:28:36 +0200
  4. Subject: [PATCH] python?sepolgen: fix ausearch path
  5. ausearch is not always isntalled in /sbin; some systems install it in
  6. /usr/sbin, or it can also be locally installed in /usr/local/sbin.
  7. The python doc [0] suggests using shutil.which() to find the path where
  8. a command is. which() returns None if the command is not found. If
  9. ausearch is not found, that would result in an exception being raised by
  10. Popen():
  11. TypeError: expected str, bytes or os.PathLike object, not NoneType
  12. This is not very informative of what actually failed...
  13. However, the doc suggests so for portability. In our case, the python
  14. tools are only ever going to run on a Linux host (by their virtue of
  15. dealing with SELinux), so the search will be reliably done by looking in
  16. PATH, so we can let Popen() bubble the resolving of an unqualified
  17. command, down to execvpe() (or the similar actual syscall of the exec*()
  18. family). If ausearch is then not found, Popen() raises an exception
  19. that is wy more informative then:
  20. FileNotFoundError: [Errno 2] No such file or directory: 'ausearch'
  21. [0] https://docs.python.org/3/library/subprocess.html#subprocess.Popen
  22. Signed-off-by: Adam Duskett <aduskett@gmail.com>
  23. [yann.morin.1998@free.fr:
  24. - let Popen() resolve from PATH
  25. - rewrite commit log
  26. ]
  27. Signed-off-by: Yann E. MORIN <yann.morin.1998@free.fr>
  28. Upstream: not submitted
  29. ---
  30. python/sepolgen/src/sepolgen/audit.py | 4 ++--
  31. 1 file changed, 2 insertions(+), 2 deletions(-)
  32. diff --git a/python/sepolgen/src/sepolgen/audit.py b/python/sepolgen/src/sepolgen/audit.py
  33. index 4adb851f..5eafa587 100644
  34. --- a/sepolgen/src/sepolgen/audit.py
  35. +++ b/sepolgen/src/sepolgen/audit.py
  36. @@ -41,7 +41,7 @@ def get_audit_boot_msgs():
  37. s = time.localtime(time.time() - off)
  38. bootdate = time.strftime("%x", s)
  39. boottime = time.strftime("%X", s)
  40. - output = subprocess.Popen(["/sbin/ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR", "-ts", bootdate, boottime],
  41. + output = subprocess.Popen(["ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR", "-ts", bootdate, boottime],
  42. stdout=subprocess.PIPE).communicate()[0]
  43. if util.PY3:
  44. output = util.decode_input(output)
  45. @@ -56,7 +56,7 @@ def get_audit_msgs():
  46. string contain all of the audit messages returned by ausearch.
  47. """
  48. import subprocess
  49. - output = subprocess.Popen(["/sbin/ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR"],
  50. + output = subprocess.Popen(["ausearch", "-m", "AVC,USER_AVC,MAC_POLICY_LOAD,DAEMON_START,SELINUX_ERR"],
  51. stdout=subprocess.PIPE).communicate()[0]
  52. if util.PY3:
  53. output = util.decode_input(output)
  54. --
  55. 2.25.1