Do not use extra command options in the automount plugin

Allowing Commands to be called with ignored unknown options opens the
door to problems, for example with misspelled option names.
Before we start rejecting them, we need to make sure IPA itself does
not use them when it calls commands internally.

This patch does that for the automount plugin and its tests.

Part of the work for https://fedorahosted.org/freeipa/ticket/2509
This commit is contained in:
Petr Viktorin 2012-04-16 09:29:42 -04:00 committed by Martin Kosek
parent 343aba2486
commit c45174d680
2 changed files with 20 additions and 23 deletions

View File

@ -788,6 +788,8 @@ class automountkey_add(LDAPCreate):
msg_summary = _('Added automount key "%(value)s"') msg_summary = _('Added automount key "%(value)s"')
def pre_callback(self, ldap, dn, entry_attrs, *keys, **options): def pre_callback(self, ldap, dn, entry_attrs, *keys, **options):
options.pop('add_operation', None)
options.pop('description', None)
self.obj.check_key_uniqueness(keys[-2], keys[-1], **options) self.obj.check_key_uniqueness(keys[-2], keys[-1], **options)
return dn return dn
@ -827,39 +829,35 @@ class automountmap_add_indirect(LDAPCreate):
) )
def execute(self, *keys, **options): def execute(self, *keys, **options):
parentmap = options.pop('parentmap', None)
key = options.pop('key')
result = self.api.Command['automountmap_add'](*keys, **options) result = self.api.Command['automountmap_add'](*keys, **options)
try: try:
if options['parentmap'] != u'auto.master': if parentmap != u'auto.master':
if options['key'].startswith('/'): if key.startswith('/'):
raise errors.ValidationError(name='mount', error=_('mount point is relative to parent map, cannot begin with /')) raise errors.ValidationError(name='mount',
error=_('mount point is relative to parent map, '
'cannot begin with /'))
location = keys[0] location = keys[0]
map = keys[1] map = keys[1]
options['automountinformation'] = map options['automountinformation'] = map
# Ensure the referenced map exists # Ensure the referenced map exists
self.api.Command['automountmap_show']( self.api.Command['automountmap_show'](location, parentmap)
location, options['parentmap']
)
# Add a submount key # Add a submount key
kw = dict(key=options['key'], automountinformation='-fstype=autofs ldap:%s' % map)
self.api.Command['automountkey_add']( self.api.Command['automountkey_add'](
location, options['parentmap'], location, parentmap, automountkey=key, key=key,
automountkey=options['key'], **kw automountinformation='-fstype=autofs ldap:%s' % map)
)
else: # adding to auto.master else: # adding to auto.master
# Ensure auto.master exists # Ensure auto.master exists
self.api.Command['automountmap_show']( self.api.Command['automountmap_show'](keys[0], parentmap)
keys[0], options['parentmap']
)
options['automountinformation'] = keys[1]
self.api.Command['automountkey_add']( self.api.Command['automountkey_add'](
keys[0], u'auto.master', keys[0], u'auto.master', automountkey=key,
automountkey=options['key'], **options automountinformation=keys[1])
) except Exception:
except Exception, e:
# The key exists, drop the map # The key exists, drop the map
self.api.Command['automountmap_del'](*keys, **options) self.api.Command['automountmap_del'](*keys)
raise e raise
return result return result
api.register(automountmap_add_indirect) api.register(automountmap_add_indirect)

View File

@ -145,7 +145,7 @@ class test_automount(XMLRPC_test):
""" """
Test the `xmlrpc.automountkey_del` method. Test the `xmlrpc.automountkey_del` method.
""" """
delkey_kw={'automountkey': self.keyname_rename, 'automountinformation' : self.newinfo, 'raw': True} delkey_kw={'automountkey': self.keyname_rename, 'automountinformation' : self.newinfo}
res = api.Command['automountkey_del'](self.locname, self.mapname, **delkey_kw)['result'] res = api.Command['automountkey_del'](self.locname, self.mapname, **delkey_kw)['result']
assert res assert res
assert_attr_equal(res, 'failed', '') assert_attr_equal(res, 'failed', '')
@ -227,8 +227,7 @@ class test_automount_indirect(XMLRPC_test):
mapname = u'auto.home' mapname = u'auto.home'
keyname = u'/home' keyname = u'/home'
parentmap = u'auto.master' parentmap = u'auto.master'
info = u'somehost:/homes' map_kw = {'key': keyname, 'parentmap': parentmap, 'raw': True}
map_kw = {'key': keyname, 'parentmap': parentmap, 'info': info, 'raw': True}
key_kw = {'automountkey': keyname, 'automountinformation': mapname} key_kw = {'automountkey': keyname, 'automountinformation': mapname}
def test_0_automountlocation_add(self): def test_0_automountlocation_add(self):