View | Details | Raw Unified | Return to bug 53623 | Differences between
and this patch

Collapse All | Expand All

(-)a/services/univention-s4-connector/modules/univention/s4connector/s4/dns.py (-36 / +91 lines)
 Lines 498-536   def __create_s4_dns_node(s4connector, dnsNodeDn, relativeDomainNames, dnsRecords Link Here 
498
def __pack_aRecord(object, dnsRecords):
498
def __pack_aRecord(object, dnsRecords):
499
	# add aRecords
499
	# add aRecords
500
500
501
	kwargs = {}
502
	ttl = object['attributes'].get('dNSTTL', [None])[0]
503
	if ttl:
504
		kwargs['ttl'] = int(ttl)
505
501
	# IPv4
506
	# IPv4
502
	for a in object['attributes'].get('aRecord', []):
507
	for a in object['attributes'].get('aRecord', []):
503
		a_record = ARecord(a)
508
		a_record = ARecord(a, **kwargs)
504
		dnsRecords.append(ndr_pack(a_record))
509
		dnsRecords.append(ndr_pack(a_record))
505
510
506
	# IPv6
511
	# IPv6
507
	for a in object['attributes'].get('aAAARecord', []):
512
	for a in object['attributes'].get('aAAARecord', []):
508
		a_record = AAAARecord(a)
513
		a_record = AAAARecord(a, **kwargs)
509
		dnsRecords.append(ndr_pack(a_record))
514
		dnsRecords.append(ndr_pack(a_record))
510
515
511
516
512
def __unpack_aRecord(object):
517
def __unpack_aRecord(object):
513
	a = []
518
	r = []
514
	dnsRecords = object['attributes'].get('dnsRecord', [])
519
	dnsRecords = object['attributes'].get('dnsRecord', [])
515
	for dnsRecord in dnsRecords:
520
	for dnsRecord in dnsRecords:
516
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
521
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
517
		if ndrRecord.wType == dnsp.DNS_TYPE_A or ndrRecord.wType == dnsp.DNS_TYPE_AAAA:
522
		if ndrRecord.wType == dnsp.DNS_TYPE_A or ndrRecord.wType == dnsp.DNS_TYPE_AAAA:
518
			a.append(ndrRecord.data)
523
			r.append(ndrRecord)
519
	return a
524
	return r
520
525
521
526
522
def __pack_soaRecord(object, dnsRecords):
527
def __pack_soaRecord(object, dnsRecords):
528
	kwargs = {}
529
	ttl = object['attributes'].get('dNSTTL', [None])[0]
530
	if ttl:
531
		kwargs['ttl'] = int(ttl)
532
523
	soaRecord = object['attributes'].get('sOARecord', [None])[0]
533
	soaRecord = object['attributes'].get('sOARecord', [None])[0]
524
	if soaRecord:
534
	if soaRecord:
525
		soa = soaRecord.split(b' ')
535
		soa = soaRecord.split(b' ')
526
		mname = soa[0]
536
		kwargs['mname'] = soa[0]
527
		rname = soa[1]
537
		kwargs['rname'] = soa[1]
528
		serial = int(soa[2])
538
		kwargs['serial'] = int(soa[2])
529
		refresh = int(soa[3])
539
		kwargs['refresh'] = int(soa[3])
530
		retry = int(soa[4])
540
		kwargs['retry'] = int(soa[4])
531
		expire = int(soa[5])
541
		kwargs['expire'] = int(soa[5])
532
		ttl = int(soa[6])
542
		kwargs['minimum'] = int(soa[6])  # minimum ttl
533
		soa_record = SOARecord(mname=mname, rname=rname, serial=serial, refresh=refresh, retry=retry, expire=expire, minimum=3600, ttl=ttl)
543
		soa_record = SOARecord(**kwargs)
534
544
535
		dnsRecords.append(ndr_pack(soa_record))
545
		dnsRecords.append(ndr_pack(soa_record))
536
546
 Lines 553-560   def __unpack_soaRecord(object): Link Here 
553
563
554
564
555
def __pack_nsRecord(object, dnsRecords):
565
def __pack_nsRecord(object, dnsRecords):
566
	kwargs = {}
567
	ttl = object['attributes'].get('dNSTTL', [None])[0]
568
	if ttl:
569
		kwargs['ttl'] = int(ttl)
570
556
	for nSRecord in object['attributes'].get('nSRecord', []):
571
	for nSRecord in object['attributes'].get('nSRecord', []):
557
		a_record = NSRecord(nSRecord)
572
		a_record = NSRecord(nSRecord, **kwargs)
558
		dnsRecords.append(ndr_pack(a_record))
573
		dnsRecords.append(ndr_pack(a_record))
559
574
560
575
 Lines 564-581   def __unpack_nsRecord(object): Link Here 
564
	for dnsRecord in dnsRecords:
579
	for dnsRecord in dnsRecords:
565
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
580
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
566
		if ndrRecord.wType == dnsp.DNS_TYPE_NS:
581
		if ndrRecord.wType == dnsp.DNS_TYPE_NS:
567
			ns.append(__append_dot(ndrRecord.data))
582
			ns.append(ndrRecord)
568
	return ns
583
	return ns
569
584
570
585
571
def __pack_mxRecord(object, dnsRecords):
586
def __pack_mxRecord(object, dnsRecords):
587
	kwargs = {}
588
	ttl = object['attributes'].get('dNSTTL', [None])[0]
589
	if ttl:
590
		kwargs['ttl'] = int(ttl)
591
572
	for mXRecord in object['attributes'].get('mXRecord', []):
592
	for mXRecord in object['attributes'].get('mXRecord', []):
573
		if mXRecord:
593
		if mXRecord:
574
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % mXRecord)
594
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % mXRecord)
575
			mx = mXRecord.split(b' ')
595
			mx = mXRecord.split(b' ')
576
			priority = mx[0]
596
			priority = mx[0]
577
			name = mx[1]
597
			name = mx[1]
578
			mx_record = MXRecord(name, int(priority))
598
			mx_record = MXRecord(name, int(priority), **kwargs)
579
			dnsRecords.append(ndr_pack(mx_record))
599
			dnsRecords.append(ndr_pack(mx_record))
580
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
600
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
581
601
 Lines 591-601   def __unpack_mxRecord(object): Link Here 
591
611
592
612
593
def __pack_txtRecord(object, dnsRecords):
613
def __pack_txtRecord(object, dnsRecords):
614
	kwargs = {}
615
	ttl = object['attributes'].get('dNSTTL', [None])[0]
616
	if ttl:
617
		kwargs['ttl'] = int(ttl)
618
594
	for txtRecord in object['attributes'].get('tXTRecord', []):
619
	for txtRecord in object['attributes'].get('tXTRecord', []):
595
		if txtRecord:
620
		if txtRecord:
596
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % txtRecord)
621
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % txtRecord)
597
			token_list = TXT.from_text(rdataclass.IN, rdatatype.TXT, Tokenizer(txtRecord)).strings
622
			token_list = TXT.from_text(rdataclass.IN, rdatatype.TXT, Tokenizer(txtRecord)).strings
598
			ndr_txt_record = ndr_pack(TXTRecord(token_list))
623
			ndr_txt_record = ndr_pack(TXTRecord(token_list, **kwargs))
599
			dnsRecords.append(ndr_txt_record)
624
			dnsRecords.append(ndr_txt_record)
600
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % ndr_txt_record)
625
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % ndr_txt_record)
601
626
 Lines 612-620   def __unpack_txtRecord(object): Link Here 
612
637
613
638
614
def __pack_cName(object, dnsRecords):
639
def __pack_cName(object, dnsRecords):
640
	kwargs = {}
641
	ttl = object['attributes'].get('dNSTTL', [None])[0]
642
	if ttl:
643
		kwargs['ttl'] = int(ttl)
644
615
	for c in object['attributes'].get('cNAMERecord', []):
645
	for c in object['attributes'].get('cNAMERecord', []):
616
		c = __remove_dot(c)
646
		c = __remove_dot(c)
617
		c_record = CNameRecord(c)
647
		c_record = CNameRecord(c, **kwargs)
618
		dnsRecords.append(ndr_pack(c_record))
648
		dnsRecords.append(ndr_pack(c_record))
619
649
620
650
 Lines 632-644   def __unpack_cName(object): Link Here 
632
662
633
663
634
def __pack_sRVrecord(object, dnsRecords):
664
def __pack_sRVrecord(object, dnsRecords):
665
	kwargs = {}
666
	ttl = object['attributes'].get('dNSTTL', [None])[0]
667
	if ttl:
668
		kwargs['ttl'] = int(ttl)
669
635
	for srvRecord in object['attributes'].get('sRVRecord', []):
670
	for srvRecord in object['attributes'].get('sRVRecord', []):
636
		srv = srvRecord.split(b' ')
671
		srv = srvRecord.split(b' ')
637
		priority = int(srv[0])
672
		priority = int(srv[0])
638
		weight = int(srv[1])
673
		weight = int(srv[1])
639
		port = int(srv[2])
674
		port = int(srv[2])
640
		target = __remove_dot(srv[3])
675
		target = __remove_dot(srv[3])
641
		s = SRVRecord(target, port, priority, weight)
676
		s = SRVRecord(target, port, priority, weight, **kwargs)
642
		dnsRecords.append(ndr_pack(s))
677
		dnsRecords.append(ndr_pack(s))
643
678
644
679
 Lines 653-661   def __unpack_sRVrecord(object): Link Here 
653
688
654
689
655
def __pack_ptrRecord(object, dnsRecords):
690
def __pack_ptrRecord(object, dnsRecords):
691
	kwargs = {}
692
	ttl = object['attributes'].get('dNSTTL', [None])[0]
693
	if ttl:
694
		kwargs['ttl'] = int(ttl)
695
656
	for ptr in object['attributes'].get('pTRRecord', []):
696
	for ptr in object['attributes'].get('pTRRecord', []):
657
		ptr = __remove_dot(ptr)
697
		ptr = __remove_dot(ptr)
658
		ptr_record = PTRRecord(ptr)
698
		ptr_record = PTRRecord(ptr, **kwargs)
659
		dnsRecords.append(ndr_pack(ptr_record))
699
		dnsRecords.append(ndr_pack(ptr_record))
660
700
661
701
 Lines 923-929   def ucs_host_record_create(s4connector, object): Link Here 
923
		return
963
		return
924
964
925
	# unpack the host record
965
	# unpack the host record
926
	a = __unpack_aRecord(object)
966
	a_ndrRecord_list = __unpack_aRecord(object)
927
967
928
	# Does a host record for this zone already exist?
968
	# Does a host record for this zone already exist?
929
	ol_filter = format_escaped('(&(relativeDomainName={0!e})(zoneName={1!e}))', relativeDomainName, zoneName)
969
	ol_filter = format_escaped('(&(relativeDomainName={0!e})(zoneName={1!e}))', relativeDomainName, zoneName)
 Lines 931-938   def ucs_host_record_create(s4connector, object): Link Here 
931
	if len(searchResult) > 0:
971
	if len(searchResult) > 0:
932
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], update_zone=False)
972
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], update_zone=False)
933
		newRecord.open()
973
		newRecord.open()
974
		a = [r.data for r in a_ndrRecord_list]
934
		if set(newRecord['a']) != set(a):
975
		if set(newRecord['a']) != set(a):
935
			newRecord['a'] = a
976
			newRecord['a'] = a
977
			newRecord['zonettl'] = [min([r.dwTtlSeconds for r in a_ndrRecord_list])]  # complex UDM syntax
936
			newRecord.modify()
978
			newRecord.modify()
937
		else:
979
		else:
938
			ud.debug(ud.LDAP, ud.INFO, 'ucs_host_record_create: do not modify host record')
980
			ud.debug(ud.LDAP, ud.INFO, 'ucs_host_record_create: do not modify host record')
 Lines 946-952   def ucs_host_record_create(s4connector, object): Link Here 
946
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position, dn=None, update_zone=False)
988
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position, dn=None, update_zone=False)
947
		newRecord.open()
989
		newRecord.open()
948
		newRecord['name'] = relativeDomainName
990
		newRecord['name'] = relativeDomainName
949
		newRecord['a'] = a
991
		newRecord['a'] = [r.data for r in a_ndrRecord_list]
992
		newRecord['zonettl'] = [min([r.dwTtlSeconds for r in a_ndrRecord_list])]  # complex UDM syntax
950
		newRecord.create()
993
		newRecord.create()
951
994
952
995
 Lines 1281-1287   def ucs_ns_record_create(s4connector, object): Link Here 
1281
	relativeDomainName = object['attributes']['relativeDomainName'][0].decode('UTF-8')
1324
	relativeDomainName = object['attributes']['relativeDomainName'][0].decode('UTF-8')
1282
1325
1283
	# unpack the record
1326
	# unpack the record
1284
	c = __unpack_nsRecord(object)
1327
	ns_ndrRecord_list = __unpack_nsRecord(object)
1328
	ns = [__append_dot(r.data) for r in ns_ndrRecord_list]
1285
1329
1286
	# Does a host record for this zone already exist?
1330
	# Does a host record for this zone already exist?
1287
	ol_filter = format_escaped('(&(relativeDomainName={0!e})(zoneName={1!e}))', relativeDomainName, zoneName)
1331
	ol_filter = format_escaped('(&(relativeDomainName={0!e})(zoneName={1!e}))', relativeDomainName, zoneName)
 Lines 1290-1297   def ucs_ns_record_create(s4connector, object): Link Here 
1290
		foundRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], update_zone=False)
1334
		foundRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], update_zone=False)
1291
		foundRecord.open()
1335
		foundRecord.open()
1292
1336
1293
		if set(foundRecord[udm_property]) != set(c):
1337
		if set(foundRecord[udm_property]) != set(ns):
1294
			foundRecord[udm_property] = c
1338
			foundRecord[udm_property] = ns
1339
			newRecord['zonettl'] = [min([r.dwTtlSeconds for r in ns_ndrRecord_list])]  # complex UDM syntax
1295
			foundRecord.modify()
1340
			foundRecord.modify()
1296
		else:
1341
		else:
1297
			ud.debug(ud.LDAP, ud.INFO, 'ucs_ns_record_create: do not modify ns record')
1342
			ud.debug(ud.LDAP, ud.INFO, 'ucs_ns_record_create: do not modify ns record')
 Lines 1302-1308   def ucs_ns_record_create(s4connector, object): Link Here 
1302
		newRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position, dn=None, update_zone=False)
1347
		newRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position, dn=None, update_zone=False)
1303
		newRecord.open()
1348
		newRecord.open()
1304
		newRecord['zone'] = relativeDomainName
1349
		newRecord['zone'] = relativeDomainName
1305
		newRecord[udm_property] = c
1350
		newRecord['zonettl'] = [min([r.dwTtlSeconds for r in ns_ndrRecord_list])]  # complex UDM syntax
1351
		newRecord[udm_property] = ns
1306
		newRecord.create()
1352
		newRecord.create()
1307
1353
1308
1354
 Lines 1343-1353   def ucs_zone_create(s4connector, object, dns_type): Link Here 
1343
		ud.debug(ud.LDAP, ud.INFO, "ucs_zone_create: ignoring DC=%s object" % (relativeDomainName,))
1389
		ud.debug(ud.LDAP, ud.INFO, "ucs_zone_create: ignoring DC=%s object" % (relativeDomainName,))
1344
		return
1390
		return
1345
1391
1346
	ns = __unpack_nsRecord(object)
1392
	ns_ndrRecord_list = __unpack_nsRecord(object)
1393
	ns = [__append_dot(r.data) for r in ns_ndrRecord_list]
1347
1394
1348
	soa = __unpack_soaRecord(object)
1395
	soa = __unpack_soaRecord(object)
1349
1396
1350
	a = __unpack_aRecord(object)
1397
	a_ndrRecord_list = __unpack_aRecord(object)
1351
1398
1352
	mx = __unpack_mxRecord(object)
1399
	mx = __unpack_mxRecord(object)
1353
1400
 Lines 1388-1396   def ucs_zone_create(s4connector, object, dns_type): Link Here 
1388
		if int(soa['serial']) != int(zone['serial']):
1435
		if int(soa['serial']) != int(zone['serial']):
1389
			zone['serial'] = soa['serial']
1436
			zone['serial'] = soa['serial']
1390
			modify = True
1437
			modify = True
1391
		for k in ['refresh', 'retry', 'expire', 'ttl']:
1438
		for k in ['refresh', 'retry', 'expire', ('minimum', 'ttl'), ('ttl', 'zonettl')]:
1392
			if int(soa[k]) != _unixTimeInverval2seconds(zone[k]):
1439
			if isinstance(k, str):
1393
				zone[k] = unmapUNIX_TimeInterval(soa[k])
1440
				samba_key = k
1441
				udm_property = k
1442
			else:
1443
				samba_key = k[0]
1444
				udm_property = k[1]
1445
			if int(soa[samba_key]) != _unixTimeInverval2seconds(zone[udm_property]):
1446
				zone[udm_property] = soa[samba_key]
1394
				modify = True
1447
				modify = True
1395
		if dns_type == 'forward_zone':
1448
		if dns_type == 'forward_zone':
1396
			# The IP address of the DNS forward zone will be used to determine the
1449
			# The IP address of the DNS forward zone will be used to determine the
 Lines 1399-1404   def ucs_zone_create(s4connector, object, dns_type): Link Here 
1399
			aRecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv4' % zoneName.lower())
1452
			aRecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv4' % zoneName.lower())
1400
			aAAARecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv6' % zoneName.lower())
1453
			aAAARecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv6' % zoneName.lower())
1401
			if not aRecords and not aAAARecords:
1454
			if not aRecords and not aAAARecords:
1455
				a = [r.data for r in a_ndrRecord_list]
1402
				if set(a) != set(zone['a']):
1456
				if set(a) != set(zone['a']):
1403
					zone['a'] = a
1457
					zone['a'] = a
1404
					modify = True
1458
					modify = True
 Lines 1425-1436   def ucs_zone_create(s4connector, object, dns_type): Link Here 
1425
		zone['nameserver'] = ns
1479
		zone['nameserver'] = ns
1426
		zone['contact'] = soa['rname'].replace('.', '@', 1)
1480
		zone['contact'] = soa['rname'].replace('.', '@', 1)
1427
		zone['serial'] = soa['serial']
1481
		zone['serial'] = soa['serial']
1428
		zone['refresh'] = [soa['refresh']]  # complex UDM syntax
1482
		zone['refresh'] = soa['refresh']  # UDM syntax is mapUNIX_TimeInterval
1429
		zone['retry'] = [soa['retry']]  # complex UDM syntax
1483
		zone['retry'] = soa['retry']  # UDM syntax is mapUNIX_TimeInterval
1430
		zone['expire'] = [soa['expire']]  # complex UDM syntax
1484
		zone['expire'] = soa['expire']  # UDM syntax is mapUNIX_TimeInterval
1431
		zone['ttl'] = [soa['ttl']]  # complex UDM syntax
1485
		zone['ttl'] = soa['minimum']  # this is the "minimum" ttl part of sOARecord, UDM syntax is mapUNIX_TimeInterval
1486
		zone['zonettl'] = soa['ttl']
1432
		if dns_type == 'forward_zone':
1487
		if dns_type == 'forward_zone':
1433
			zone['a'] = a
1488
			zone['a'] = [r.data for r in a_ndrRecord_list]
1434
			zone['mx'] = mx
1489
			zone['mx'] = mx
1435
		zone.create()
1490
		zone.create()
1436
1491

Return to bug 53623