diff --git a/management/univention-management-console-module-udm/umc/python/udm/__init__.py b/management/univention-management-console-module-udm/umc/python/udm/__init__.py index c70ee92..a2e47ba 100644 --- a/management/univention-management-console-module-udm/umc/python/udm/__init__.py +++ b/management/univention-management-console-module-udm/umc/python/udm/__init__.py @@ -69,7 +69,7 @@ from .udm_ldap import ( UDM_Error, UDM_Module, UDM_Settings, - ldap_dn2path, get_module, read_syntax_choices, list_objects, + ldap_dn2path, get_module, read_syntax_choices, list_objects, _get_syntax, LDAP_Connection, set_bind_function, container_modules, info_syntax_choices, search_syntax_choices_by_key, UserWithoutDN, ObjectDoesNotExist, SuperordinateDoesNotExist, NoIpLeft, @@ -894,13 +894,23 @@ def _thread(request): thread = notifier.threads.Simple('Validate', notifier.Callback(_thread, request), notifier.Callback(self.thread_finished_callback, request)) thread.run() - @sanitize(key=LDAPSearchSanitizer(use_asterisks=False)) + @sanitize( + syntax=StringSanitizer(required=True), + key=LDAPSearchSanitizer(use_asterisks=False), + ) @simple_response def syntax_choices_key(self, syntax, key): + syntax = _get_syntax(syntax) + if syntax is None: + return return search_syntax_choices_by_key(syntax, key) + @sanitize(syntax=StringSanitizer(required=True)) @simple_response def syntax_choices_info(self, syntax): + syntax = _get_syntax(syntax) + if syntax is None: + return return info_syntax_choices(syntax) @sanitize( @@ -918,7 +928,10 @@ def syntax_choices(self, request): """ def _thread(request): - return read_syntax_choices(request.options['syntax'], request.options) + syntax = _get_syntax(request.options['syntax']) + if syntax is None: + return + return read_syntax_choices(syntax, request.options) thread = notifier.threads.Simple('SyntaxChoice', notifier.Callback(_thread, request), notifier.Callback(self.thread_finished_callback, request)) thread.run() diff --git a/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py b/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py index 0dbed9a..9ebe573 100644 --- a/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py +++ b/management/univention-management-console-module-udm/umc/python/udm/udm_ldap.py @@ -275,7 +275,7 @@ def get_default_values(self, property_name): if key == property_name: value = default_value(prop.syntax) if isinstance(value, (list, tuple)): - value = read_syntax_choices(prop.syntax.name) + value = read_syntax_choices(prop.syntax) return value def _map_properties(self, obj, properties): @@ -1126,16 +1126,12 @@ def _get_syntax(syntax_name): return udm_syntax.__dict__[syntax_name]() -def search_syntax_choices_by_key(syntax_name, key): - syn = _get_syntax(syntax_name) - if syn is None: - return None - +def search_syntax_choices_by_key(syn, key): if issubclass(syn.__class__, udm_syntax.UDM_Objects): if syn.key == 'dn': module_search_options = {'scope': 'base', 'container': key} try: - return read_syntax_choices(syntax_name, {}, module_search_options) + return read_syntax_choices(syn, {}, module_search_options) except udm_errors.base: # TODO: which exception is raised here exactly? # invalid DN return [] @@ -1144,19 +1140,15 @@ def search_syntax_choices_by_key(syntax_name, key): if match: attr = match.groups()[0] options = {'objectProperty': attr, 'objectPropertyValue': key} - return read_syntax_choices(syntax_name, options) + return read_syntax_choices(syn, options) - MODULE.warn('Syntax "%s": No fast search function' % syntax_name) + MODULE.warn('Syntax %r: No fast search function' % syn.name) # return them all, as there is no reason to filter after everything has loaded # frontend will cache it. - return read_syntax_choices(syntax_name) - + return read_syntax_choices(syn) -def info_syntax_choices(syntax_name, options={}): - syn = _get_syntax(syntax_name) - if syn is None: - return None +def info_syntax_choices(syn, options={}): if issubclass(syn.__class__, udm_syntax.UDM_Objects): size = 0 if syn.static_values is not None: @@ -1176,10 +1168,8 @@ def info_syntax_choices(syntax_name, options={}): @LDAP_Connection -def read_syntax_choices(syntax_name, options={}, module_search_options={}, ldap_connection=None, ldap_position=None): - syn = _get_syntax(syntax_name) - if syn is None: - return None +def read_syntax_choices(syn, options={}, module_search_options={}, ldap_connection=None, ldap_position=None): + syntax_name = syn.name if issubclass(syn.__class__, udm_syntax.UDM_Objects): syn.choices = [] @@ -1350,7 +1340,10 @@ def map_choice(obj): syn.choices.append((dn, dn_list[0].split('=', 1)[1])) elif issubclass(syn.__class__, udm_syntax.LDAP_Search): options = options.get('options', {}) - syntax = udm_syntax.LDAP_Search(options['syntax'], options['filter'], options['attributes'], options['base'], options['value'], options['viewonly'], options['empty'], options['empty_end']) + try: + syntax = udm_syntax.LDAP_Search(options['syntax'], options['filter'], options['attributes'], options['base'], options['value'], options['viewonly'], options['empty'], options['empty_end']) + except KeyError: + syntax = syn if '$dn$' in options: filter_mod = get_module(None, options['$dn$']) @@ -1391,7 +1384,7 @@ def map_choice(obj): id = obj.oldattr[store][0] else: # no valid store object, ignore - MODULE.warn('LDAP_Search syntax "%s": "%s" is no valid property for object "%s" - ignoring entry.' % (options['syntax'], store, dn)) + MODULE.warn('LDAP_Search syntax %r: %r is no valid property for object %r - ignoring entry.' % (syntax.name, store, dn)) continue # find the value to display