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-539   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 = compatible_modstring(a)
508
		a = compatible_modstring(a)
504
		a_record = ARecord(a)
509
		a_record = ARecord(a, **kwargs)
505
		dnsRecords.append(ndr_pack(a_record))
510
		dnsRecords.append(ndr_pack(a_record))
506
511
507
	# IPv6
512
	# IPv6
508
	for a in object['attributes'].get('aAAARecord', []):
513
	for a in object['attributes'].get('aAAARecord', []):
509
		a = compatible_modstring(a)
514
		a = compatible_modstring(a)
510
		a_record = AAAARecord(a)
515
		a_record = AAAARecord(a, **kwargs)
511
		dnsRecords.append(ndr_pack(a_record))
516
		dnsRecords.append(ndr_pack(a_record))
512
517
513
518
514
def __unpack_aRecord(object):
519
def __unpack_aRecord(object):
515
	a = []
520
	r = []
516
	dnsRecords = object['attributes'].get('dnsRecord', [])
521
	dnsRecords = object['attributes'].get('dnsRecord', [])
517
	for dnsRecord in dnsRecords:
522
	for dnsRecord in dnsRecords:
518
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
523
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
519
		if ndrRecord.wType == dnsp.DNS_TYPE_A or ndrRecord.wType == dnsp.DNS_TYPE_AAAA:
524
		if ndrRecord.wType == dnsp.DNS_TYPE_A or ndrRecord.wType == dnsp.DNS_TYPE_AAAA:
520
			a.append(ndrRecord.data)
525
			r.append(ndrRecord)
521
	return a
526
	return r
522
527
523
528
524
def __pack_soaRecord(object, dnsRecords):
529
def __pack_soaRecord(object, dnsRecords):
530
	kwargs = {}
531
	ttl = object['attributes'].get('dNSTTL', [None])[0]
532
	if ttl:
533
		kwargs['ttl'] = int(ttl)
534
525
	soaRecord = object['attributes'].get('sOARecord', [None])[0]
535
	soaRecord = object['attributes'].get('sOARecord', [None])[0]
526
	if soaRecord:
536
	if soaRecord:
527
		soaRecord = compatible_modstring(soaRecord)
537
		soaRecord = compatible_modstring(soaRecord)
528
		soa = soaRecord.split(' ')
538
		soa = soaRecord.split(' ')
529
		mname = soa[0]
539
		kwargs['mname'] = soa[0]
530
		rname = soa[1]
540
		kwargs['rname'] = soa[1]
531
		serial = int(soa[2])
541
		kwargs['serial'] = int(soa[2])
532
		refresh = int(soa[3])
542
		kwargs['refresh'] = int(soa[3])
533
		retry = int(soa[4])
543
		kwargs['retry'] = int(soa[4])
534
		expire = int(soa[5])
544
		kwargs['expire'] = int(soa[5])
535
		ttl = int(soa[6])
545
		kwargs['minimum'] = int(soa[6])  # minimum ttl
536
		soa_record = SOARecord(mname=mname, rname=rname, serial=serial, refresh=refresh, retry=retry, expire=expire, minimum=3600, ttl=ttl)
546
		soa_record = SOARecord(**kwargs)
537
547
538
		dnsRecords.append(ndr_pack(soa_record))
548
		dnsRecords.append(ndr_pack(soa_record))
539
549
 Lines 553-561   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
		nSRecord = compatible_modstring(nSRecord)
572
		nSRecord = compatible_modstring(nSRecord)
558
		a_record = NSRecord(nSRecord)
573
		a_record = NSRecord(nSRecord, **kwargs)
559
		dnsRecords.append(ndr_pack(a_record))
574
		dnsRecords.append(ndr_pack(a_record))
560
575
561
576
 Lines 564-582   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
			mXRecord = compatible_modstring(mXRecord)
595
			mXRecord = compatible_modstring(mXRecord)
576
			mx = mXRecord.split(' ')
596
			mx = mXRecord.split(' ')
577
			priority = mx[0]
597
			priority = mx[0]
578
			name = mx[1]
598
			name = mx[1]
579
			mx_record = MXRecord(name, int(priority))
599
			mx_record = MXRecord(name, int(priority), **kwargs)
580
			dnsRecords.append(ndr_pack(mx_record))
600
			dnsRecords.append(ndr_pack(mx_record))
581
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
601
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
582
602
 Lines 591-603   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
	slist = []
619
	slist = []
595
	for txtRecord in object['attributes'].get('tXTRecord', []):
620
	for txtRecord in object['attributes'].get('tXTRecord', []):
596
		if txtRecord:
621
		if txtRecord:
597
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % txtRecord)
622
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % txtRecord)
598
			txtRecord = compatible_modstring(txtRecord)
623
			txtRecord = compatible_modstring(txtRecord)
599
			token_list = TXT.from_text(rdataclass.IN, rdatatype.TXT, Tokenizer(txtRecord)).strings
624
			token_list = TXT.from_text(rdataclass.IN, rdatatype.TXT, Tokenizer(txtRecord)).strings
600
			ndr_txt_record = ndr_pack(TXTRecord(token_list))
625
			ndr_txt_record = ndr_pack(TXTRecord(token_list, **kwargs))
601
			dnsRecords.append(ndr_txt_record)
626
			dnsRecords.append(ndr_txt_record)
602
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % ndr_txt_record)
627
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % ndr_txt_record)
603
628
 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 = compatible_modstring(__remove_dot(c))
646
		c = compatible_modstring(__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-645   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
		srvRecord = compatible_modstring(srvRecord)
671
		srvRecord = compatible_modstring(srvRecord)
637
		srv = srvRecord.split(' ')
672
		srv = srvRecord.split(' ')
638
		priority = int(srv[0])
673
		priority = int(srv[0])
639
		weight = int(srv[1])
674
		weight = int(srv[1])
640
		port = int(srv[2])
675
		port = int(srv[2])
641
		target = __remove_dot(srv[3])
676
		target = __remove_dot(srv[3])
642
		s = SRVRecord(target, port, priority, weight)
677
		s = SRVRecord(target, port, priority, weight, **kwargs)
643
		dnsRecords.append(ndr_pack(s))
678
		dnsRecords.append(ndr_pack(s))
644
679
645
680
 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 = compatible_modstring(__remove_dot(ptr))
697
		ptr = compatible_modstring(__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], attributes=[], update_zone=False)
972
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], attributes=[], 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, attributes=[], update_zone=False)
988
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position, dn=None, attributes=[], 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]
1324
	relativeDomainName = object['attributes']['relativeDomainName'][0]
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], attributes=[], update_zone=False)
1334
		foundRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], attributes=[], 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, attributes=[], update_zone=False)
1347
		newRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position, dn=None, attributes=[], 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