diff --git management/univention-directory-manager-modules/scripts/proof_class_b_reverse management/univention-directory-manager-modules/scripts/proof_class_b_reverse index 0dde7d66c3..9f50b5121d 100755 --- management/univention-directory-manager-modules/scripts/proof_class_b_reverse +++ management/univention-directory-manager-modules/scripts/proof_class_b_reverse @@ -34,36 +34,35 @@ from __future__ import print_function -import ldap from ldap.filter import filter_format import sys +import univention.admin.uldap as uldap import univention.config_registry ucr = univention.config_registry.ConfigRegistry() ucr.load() -baseDN = ucr['ldap/base'] - if ucr['interfaces/eth0/netmask'] != "255.255.0.0": print('Only for Class B') sys.exit(1) -lo = ldap.open('localhost', 7389) -bindpw = open('/etc/ldap.secret').read() -if bindpw[-1] == '\n': - bindpw = bindpw[0:-1] - lo.simple_bind_s("cn=admin," + baseDN, bindpw) +lo, position = uldap.getAdminConnection() +ldap_base = position.getBase() -computers = lo.search_s(baseDN, ldap.SCOPE_SUBTREE, 'objectClass=univentionHost', ['aRecord']) +computers = lo.search('objectClass=univentionHost', attr=['aRecord'], base=ldap_base) -for i in range(0, len(computers)): - print('DN: %s' % computers[i][0]) - if 'aRecord' in computers[i][1]: - entry = computers[i][1]['aRecord'][0].split('.')[2:4] - reverse = lo.search_s('cn=dns,%s' % baseDN, ldap.SCOPE_SUBTREE, filter_format('(&(relativeDomainName=%s)(pTRRecord=%s*))', ('.'.join(entry), ldap.explode_dn(computers[i][0], 1)[0]))) - if len(reverse) != 0: - print('Wrong DNS Reverse Entry for %s: %s' % (computers[i][0], reverse[0][0])) - entry.reverse() - entry = '.'.join(entry) - lo.modrdn_s(reverse[0][0], 'relativeDomainName=%s' % entry) +for dn, attribute in computers: + print('DN: %s' % dn) + entry = attribute['aRecord'][0].split(b'.')[2:4] + reverse = lo.search( + filter_format('(&(relativeDomainName=%s)(pTRRecord=%s*))', + (b'.'.join(entry).decode('utf-8'), + ucr.get('hostname'))), + base='cn=dns,%s' % ldap_base, + ) + if len(reverse) != 0: + print('Wrong DNS Reverse Entry for %s: %s' % (dn, reverse[0][0])) + entry.reverse() + entry = '.'.join(entry).decode('utf-8') + lo.modrdn_s(reverse[0][0], 'relativeDomainName=%s' % entry)