Bugfix for xattrless files and the capabilities module.

pull/6508/merge
nate@bx.psu.edu 11 years ago committed by Michael DeHaan
parent f26ebff438
commit 97db1676e0

@ -84,8 +84,6 @@ class CapabilitiesModule(object):
self.setcap_cmd = module.get_bin_path('setcap', required=True) self.setcap_cmd = module.get_bin_path('setcap', required=True)
self.capability_tup = self._parse_cap(self.capability, op_required=self.state=='present') self.capability_tup = self._parse_cap(self.capability, op_required=self.state=='present')
self.changed = False
self.run() self.run()
def run(self): def run(self):
@ -102,15 +100,16 @@ class CapabilitiesModule(object):
current = filter(lambda x: x[0] != self.capability_tup[0], current) current = filter(lambda x: x[0] != self.capability_tup[0], current)
# add new cap with correct op/flags # add new cap with correct op/flags
current.append( self.capability_tup ) current.append( self.capability_tup )
self.module.exit_json(changed=True, msg='capabilities changed', stdout=self.setcap(self.path, current)) self.module.exit_json(changed=True, state=self.state, msg='capabilities changed', stdout=self.setcap(self.path, current))
if self.state == 'absent' and self.capability_tup[0] in caps: elif self.state == 'absent' and self.capability_tup[0] in caps:
# need to remove capability # need to remove capability
if self.module.check_mode: if self.module.check_mode:
self.module.exit_json(changed=True, msg='capabilities changed') self.module.exit_json(changed=True, msg='capabilities changed')
else: else:
# remove from current cap list and then set current list # remove from current cap list and then set current list
current = filter(lambda x: x[0] != self.capability_tup[0], current) current = filter(lambda x: x[0] != self.capability_tup[0], current)
self.module.exit_json(changed=True, msg='capabilities changed', stdout=self.setcap(self.path, current)) self.module.exit_json(changed=True, state=self.state, msg='capabilities changed', stdout=self.setcap(self.path, current))
self.module.exit_json(changed=False, state=self.state)
def getcap(self, path): def getcap(self, path):
rval = [] rval = []
@ -123,19 +122,20 @@ class CapabilitiesModule(object):
# If the file does not eixst the output will be (with rc == 0...): # If the file does not eixst the output will be (with rc == 0...):
# '/foo (No such file or directory)' # '/foo (No such file or directory)'
if rc != 0 or (stdout.strip() != path and stdout.count(' =') != 1): if rc != 0 or (stdout.strip() != path and stdout.count(' =') != 1):
self.module.fail_json(msg="Unable to get capabilities of %s" % path, stdout=stdout, stderr=stderr) self.module.fail_json(msg="Unable to get capabilities of %s" % path, stdout=stdout.strip(), stderr=stderr)
caps = stdout.split(' =')[1].strip().split() if stdout.strip() != path:
for cap in caps: caps = stdout.split(' =')[1].strip().split()
cap = cap.lower() for cap in caps:
# getcap condenses capabilities with the same op/flags into a cap = cap.lower()
# comma-separated list, so we have to parse that # getcap condenses capabilities with the same op/flags into a
if ',' in cap: # comma-separated list, so we have to parse that
cap_group = cap.split(',') if ',' in cap:
cap_group[-1], op, flags = self._parse_cap(cap_group[-1]) cap_group = cap.split(',')
for subcap in cap_group: cap_group[-1], op, flags = self._parse_cap(cap_group[-1])
rval.append( ( subcap, op, flags ) ) for subcap in cap_group:
else: rval.append( ( subcap, op, flags ) )
rval.append(self._parse_cap(cap)) else:
rval.append(self._parse_cap(cap))
return rval return rval
def setcap(self, path, caps): def setcap(self, path, caps):

Loading…
Cancel
Save