commit a73196ba2ee402abf9687c9553132116c5249317 Author: Florian Best Date: Fri Jan 14 15:02:29 2022 +0100 WIP: Bug #54339: allow to search for dns/ptr_record ip=$address The property "ip" of a dns/ptr_record is not part of the mapping and therefore not evaluated in a filter. Therefor the filter needs to be manually rewritten in the UDM module. This is not quite easy as the IP address is not part of the dns/ptr_records LDAP attributes - only the address (relativeDomainName) and the subnet reverse address (zoneName). The IP is constructed virtually. So we have to search for the host parts of the given IP address only in the reverse zones matching the subnet. But we don't know the subnet - the IP address in your filter doesn't contain a subnet mask. And in real life there could be more subnet masks as the common /8 and /16 and /24 and 32. We could search for every possible combination - but this would be a large LDAP filter. diff --git management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/ptr_record.py management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/ptr_record.py index 18a9575870..b54e82ac60 100644 --- management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/ptr_record.py +++ management/univention-directory-manager-modules/modules/univention/admin/handlers/dns/ptr_record.py @@ -213,6 +213,22 @@ class object(univention.admin.handlers.simpleLdap): super(object, self)._ldap_post_remove() self._updateZone() + @classmethod + def rewrite_filter(cls, filter, mapping): + if filter.variable == 'ip': + filter.variable = 'relativeDomainName' + if ':' in filter.value: + addr = ipaddress.IPv6Address(u'%s' % (filter.value,)) + raise NotImplementedError('IPv6') + else: + subnets = [ipaddress.IPv4Interface(u'%s/%d' % (filter.value, netmask)) for netmask in (24, 16, 8)] + subnets = [s.network.network_address.compressed.replace('.0', '') for s in subnets] + filter.transform_to_conjunction(univention.admin.filter.conjunction('|', [ + rewrite_rev(expression('ip', filter.value), subnet=subnet) for subnet in subnets + ])) + else: + super(object, cls).rewrite_filter(filter, mapping) + @classmethod def lookup_filter_superordinate(cls, filter, superordinate): filter.expressions.append(univention.admin.filter.expression('zoneName', superordinate.mapping.mapValueDecoded('subnet', superordinate['subnet']), escape=True))