1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

[capabilities] fix for a newer versions of libcap (#1061) (#1110)

* [capabilities] fix for a newer versions of libcap

fixes: #993

* Minor correction for files without caps set.

PS: side note, getcap (per sources) does not set non-zero return code,
even for files which are not found (i.e. wrong filename).

* add changelog fragment

* review/suggested changes

* change comment to explicitly state stderr vs output

(cherry picked from commit 07d123a71a)

Co-authored-by: Anatoly Pugachev <matorola@gmail.com>
This commit is contained in:
patchback[bot] 2020-10-16 21:23:43 +02:00 committed by GitHub
parent b3cac071fa
commit 22e0fa03b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 3 deletions

View file

@ -0,0 +1,2 @@
bugfixes:
- capabilities - fix for a newer version of libcap release (https://github.com/ansible-collections/community.general/pull/1061).

View file

@ -108,12 +108,18 @@ class CapabilitiesModule(object):
# '/foo ='
# If file xattrs are unset the output will be:
# '/foo'
# If the file does not exist the output will be (with rc == 0...):
# If the file does not exist, the stderr will be (with rc == 0...):
# '/foo (No such file or directory)'
if rc != 0 or (stdout.strip() != path and stdout.count(' =') != 1):
if rc != 0 or stderr != "":
self.module.fail_json(msg="Unable to get capabilities of %s" % path, stdout=stdout.strip(), stderr=stderr)
if stdout.strip() != path:
caps = stdout.split(' =')[1].strip().split()
if ' =' in stdout:
# process output of an older version of libcap
caps = stdout.split(' =')[1].strip().split()
else:
# otherwise, we have a newer version here
# see original commit message of cap/v0.2.40-18-g177cd41 in libcap.git
caps = stdout.split()[1].strip().split()
for cap in caps:
cap = cap.lower()
# getcap condenses capabilities with the same op/flags into a