capabilities: command args as list rather than string (#10524)

* capabilities: command args as list rather than string

* add changelog frag
This commit is contained in:
Alexei Znamensky 2025-08-05 06:00:39 +12:00 committed by GitHub
commit 7e2d91e53d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- capabilities - using safer mechanism to run external command (https://github.com/ansible-collections/community.general/pull/10524).

View file

@ -109,7 +109,7 @@ class CapabilitiesModule(object):
def getcap(self, path): def getcap(self, path):
rval = [] rval = []
cmd = "%s -v %s" % (self.getcap_cmd, path) cmd = [self.getcap_cmd, "-v", path]
rc, stdout, stderr = self.module.run_command(cmd) rc, stdout, stderr = self.module.run_command(cmd)
# If file xattrs are set but no caps are set the output will be: # If file xattrs are set but no caps are set the output will be:
# '/foo =' # '/foo ='
@ -144,7 +144,7 @@ class CapabilitiesModule(object):
def setcap(self, path, caps): def setcap(self, path, caps):
caps = ' '.join([''.join(cap) for cap in caps]) caps = ' '.join([''.join(cap) for cap in caps])
cmd = "%s '%s' %s" % (self.setcap_cmd, caps, path) cmd = [self.setcap_cmd, caps, path]
rc, stdout, stderr = self.module.run_command(cmd) rc, stdout, stderr = self.module.run_command(cmd)
if rc != 0: if rc != 0:
self.module.fail_json(msg="Unable to set capabilities of %s" % path, stdout=stdout, stderr=stderr) self.module.fail_json(msg="Unable to set capabilities of %s" % path, stdout=stdout, stderr=stderr)