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 (-21 / +64 lines)
 Lines 498-522   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', [])
503
	if ttl:
504
		kwargs['ttl'] = int(ttl[0])
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):
 Lines 553-560   def __unpack_soaRecord(object): Link Here 
553
558
554
559
555
def __pack_nsRecord(object, dnsRecords):
560
def __pack_nsRecord(object, dnsRecords):
561
	kwargs = {}
562
	ttl = object['attributes'].get('dNSTTL', [])
563
	if ttl:
564
		kwargs['ttl'] = int(ttl[0])
565
556
	for nSRecord in object['attributes'].get('nSRecord', []):
566
	for nSRecord in object['attributes'].get('nSRecord', []):
557
		a_record = NSRecord(nSRecord)
567
		a_record = NSRecord(nSRecord, **kwargs)
558
		dnsRecords.append(ndr_pack(a_record))
568
		dnsRecords.append(ndr_pack(a_record))
559
569
560
570
 Lines 564-581   def __unpack_nsRecord(object): Link Here 
564
	for dnsRecord in dnsRecords:
574
	for dnsRecord in dnsRecords:
565
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
575
		ndrRecord = ndr_unpack(dnsp.DnssrvRpcRecord, dnsRecord)
566
		if ndrRecord.wType == dnsp.DNS_TYPE_NS:
576
		if ndrRecord.wType == dnsp.DNS_TYPE_NS:
567
			ns.append(__append_dot(ndrRecord.data))
577
			ns.append(ndrRecord)
568
	return ns
578
	return ns
569
579
570
580
571
def __pack_mxRecord(object, dnsRecords):
581
def __pack_mxRecord(object, dnsRecords):
582
	kwargs = {}
583
	ttl = object['attributes'].get('dNSTTL', [])
584
	if ttl:
585
		kwargs['ttl'] = int(ttl[0])
586
572
	for mXRecord in object['attributes'].get('mXRecord', []):
587
	for mXRecord in object['attributes'].get('mXRecord', []):
573
		if mXRecord:
588
		if mXRecord:
574
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % mXRecord)
589
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % mXRecord)
575
			mx = mXRecord.split(b' ')
590
			mx = mXRecord.split(b' ')
576
			priority = mx[0]
591
			priority = mx[0]
577
			name = mx[1]
592
			name = mx[1]
578
			mx_record = MXRecord(name, int(priority))
593
			mx_record = MXRecord(name, int(priority), **kwargs)
579
			dnsRecords.append(ndr_pack(mx_record))
594
			dnsRecords.append(ndr_pack(mx_record))
580
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
595
			ud.debug(ud.LDAP, ud.INFO, '__pack_mxRecord: %s' % ndr_pack(mx_record))
581
596
 Lines 591-601   def __unpack_mxRecord(object): Link Here 
591
606
592
607
593
def __pack_txtRecord(object, dnsRecords):
608
def __pack_txtRecord(object, dnsRecords):
609
	kwargs = {}
610
	ttl = object['attributes'].get('dNSTTL', [])
611
	if ttl:
612
		kwargs['ttl'] = int(ttl[0])
613
594
	for txtRecord in object['attributes'].get('tXTRecord', []):
614
	for txtRecord in object['attributes'].get('tXTRecord', []):
595
		if txtRecord:
615
		if txtRecord:
596
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % txtRecord)
616
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % txtRecord)
597
			token_list = TXT.from_text(rdataclass.IN, rdatatype.TXT, Tokenizer(txtRecord)).strings
617
			token_list = TXT.from_text(rdataclass.IN, rdatatype.TXT, Tokenizer(txtRecord)).strings
598
			ndr_txt_record = ndr_pack(TXTRecord(token_list))
618
			ndr_txt_record = ndr_pack(TXTRecord(token_list, **kwargs))
599
			dnsRecords.append(ndr_txt_record)
619
			dnsRecords.append(ndr_txt_record)
600
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % ndr_txt_record)
620
			ud.debug(ud.LDAP, ud.INFO, '__pack_txtRecord: %s' % ndr_txt_record)
601
621
 Lines 612-620   def __unpack_txtRecord(object): Link Here 
612
632
613
633
614
def __pack_cName(object, dnsRecords):
634
def __pack_cName(object, dnsRecords):
635
	kwargs = {}
636
	ttl = object['attributes'].get('dNSTTL', [])
637
	if ttl:
638
		kwargs['ttl'] = int(ttl[0])
639
615
	for c in object['attributes'].get('cNAMERecord', []):
640
	for c in object['attributes'].get('cNAMERecord', []):
616
		c = __remove_dot(c)
641
		c = __remove_dot(c)
617
		c_record = CNameRecord(c)
642
		c_record = CNameRecord(c, **kwargs)
618
		dnsRecords.append(ndr_pack(c_record))
643
		dnsRecords.append(ndr_pack(c_record))
619
644
620
645
 Lines 632-644   def __unpack_cName(object): Link Here 
632
657
633
658
634
def __pack_sRVrecord(object, dnsRecords):
659
def __pack_sRVrecord(object, dnsRecords):
660
	kwargs = {}
661
	ttl = object['attributes'].get('dNSTTL', [])
662
	if ttl:
663
		kwargs['ttl'] = int(ttl[0])
664
635
	for srvRecord in object['attributes'].get('sRVRecord', []):
665
	for srvRecord in object['attributes'].get('sRVRecord', []):
636
		srv = srvRecord.split(b' ')
666
		srv = srvRecord.split(b' ')
637
		priority = int(srv[0])
667
		priority = int(srv[0])
638
		weight = int(srv[1])
668
		weight = int(srv[1])
639
		port = int(srv[2])
669
		port = int(srv[2])
640
		target = __remove_dot(srv[3])
670
		target = __remove_dot(srv[3])
641
		s = SRVRecord(target, port, priority, weight)
671
		s = SRVRecord(target, port, priority, weight, **kwargs)
642
		dnsRecords.append(ndr_pack(s))
672
		dnsRecords.append(ndr_pack(s))
643
673
644
674
 Lines 653-661   def __unpack_sRVrecord(object): Link Here 
653
683
654
684
655
def __pack_ptrRecord(object, dnsRecords):
685
def __pack_ptrRecord(object, dnsRecords):
686
	kwargs = {}
687
	ttl = object['attributes'].get('dNSTTL', [])
688
	if ttl:
689
		kwargs['ttl'] = int(ttl[0])
690
656
	for ptr in object['attributes'].get('pTRRecord', []):
691
	for ptr in object['attributes'].get('pTRRecord', []):
657
		ptr = __remove_dot(ptr)
692
		ptr = __remove_dot(ptr)
658
		ptr_record = PTRRecord(ptr)
693
		ptr_record = PTRRecord(ptr, **kwargs)
659
		dnsRecords.append(ndr_pack(ptr_record))
694
		dnsRecords.append(ndr_pack(ptr_record))
660
695
661
696
 Lines 923-929   def ucs_host_record_create(s4connector, object): Link Here 
923
		return
958
		return
924
959
925
	# unpack the host record
960
	# unpack the host record
926
	a = __unpack_aRecord(object)
961
	a_ndrRecord_list = __unpack_aRecord(object)
927
962
928
	# Does a host record for this zone already exist?
963
	# Does a host record for this zone already exist?
929
	ol_filter = format_escaped('(&(relativeDomainName={0!e})(zoneName={1!e}))', relativeDomainName, zoneName)
964
	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:
966
	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)
967
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], update_zone=False)
933
		newRecord.open()
968
		newRecord.open()
969
		a = [r.data for r in a_ndrRecord_list]
934
		if set(newRecord['a']) != set(a):
970
		if set(newRecord['a']) != set(a):
935
			newRecord['a'] = a
971
			newRecord['a'] = a
972
			newRecord['zonettl'] = [min([r.dwTtlSeconds for r in a_ndrRecord_list])]  # complex UDM syntax
936
			newRecord.modify()
973
			newRecord.modify()
937
		else:
974
		else:
938
			ud.debug(ud.LDAP, ud.INFO, 'ucs_host_record_create: do not modify host record')
975
			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)
983
		newRecord = univention.admin.handlers.dns.host_record.object(None, s4connector.lo, position, dn=None, update_zone=False)
947
		newRecord.open()
984
		newRecord.open()
948
		newRecord['name'] = relativeDomainName
985
		newRecord['name'] = relativeDomainName
949
		newRecord['a'] = a
986
		newRecord['a'] = [r.data for r in a_ndrRecord_list]
987
		newRecord['zonettl'] = [min([r.dwTtlSeconds for r in a_ndrRecord_list])]  # complex UDM syntax
950
		newRecord.create()
988
		newRecord.create()
951
989
952
990
 Lines 1281-1287   def ucs_ns_record_create(s4connector, object): Link Here 
1281
	relativeDomainName = object['attributes']['relativeDomainName'][0].decode('UTF-8')
1319
	relativeDomainName = object['attributes']['relativeDomainName'][0].decode('UTF-8')
1282
1320
1283
	# unpack the record
1321
	# unpack the record
1284
	c = __unpack_nsRecord(object)
1322
	ns_ndrRecord_list = __unpack_nsRecord(object)
1323
	ns = [__append_dot(r.data) for r in ns_ndrRecord_list]
1285
1324
1286
	# Does a host record for this zone already exist?
1325
	# Does a host record for this zone already exist?
1287
	ol_filter = format_escaped('(&(relativeDomainName={0!e})(zoneName={1!e}))', relativeDomainName, zoneName)
1326
	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)
1329
		foundRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position=None, dn=searchResult[0][0], update_zone=False)
1291
		foundRecord.open()
1330
		foundRecord.open()
1292
1331
1293
		if set(foundRecord[udm_property]) != set(c):
1332
		if set(foundRecord[udm_property]) != set(ns):
1294
			foundRecord[udm_property] = c
1333
			foundRecord[udm_property] = ns
1334
			newRecord['zonettl'] = [min([r.dwTtlSeconds for r in ns_ndrRecord_list])]  # complex UDM syntax
1295
			foundRecord.modify()
1335
			foundRecord.modify()
1296
		else:
1336
		else:
1297
			ud.debug(ud.LDAP, ud.INFO, 'ucs_ns_record_create: do not modify ns record')
1337
			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)
1342
		newRecord = univention.admin.handlers.dns.ns_record.object(None, s4connector.lo, position, dn=None, update_zone=False)
1303
		newRecord.open()
1343
		newRecord.open()
1304
		newRecord['zone'] = relativeDomainName
1344
		newRecord['zone'] = relativeDomainName
1305
		newRecord[udm_property] = c
1345
		newRecord['zonettl'] = [min([r.dwTtlSeconds for r in ns_ndrRecord_list])]  # complex UDM syntax
1346
		newRecord[udm_property] = ns
1306
		newRecord.create()
1347
		newRecord.create()
1307
1348
1308
1349
 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,))
1384
		ud.debug(ud.LDAP, ud.INFO, "ucs_zone_create: ignoring DC=%s object" % (relativeDomainName,))
1344
		return
1385
		return
1345
1386
1346
	ns = __unpack_nsRecord(object)
1387
	ns_ndrRecord_list = __unpack_nsRecord(object)
1388
	ns = [__append_dot(r.data) for r in ns_ndrRecord_list]
1347
1389
1348
	soa = __unpack_soaRecord(object)
1390
	soa = __unpack_soaRecord(object)
1349
1391
1350
	a = __unpack_aRecord(object)
1392
	a_ndrRecord_list = __unpack_aRecord(object)
1351
1393
1352
	mx = __unpack_mxRecord(object)
1394
	mx = __unpack_mxRecord(object)
1353
1395
 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())
1441
			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())
1442
			aAAARecords = s4connector.configRegistry.get('connector/s4/mapping/dns/forward_zone/%s/static/ipv6' % zoneName.lower())
1401
			if not aRecords and not aAAARecords:
1443
			if not aRecords and not aAAARecords:
1444
				a = [r.data for r in a_ndrRecord_list]
1402
				if set(a) != set(zone['a']):
1445
				if set(a) != set(zone['a']):
1403
					zone['a'] = a
1446
					zone['a'] = a
1404
					modify = True
1447
					modify = True
 Lines 1430-1436   def ucs_zone_create(s4connector, object, dns_type): Link Here 
1430
		zone['expire'] = [soa['expire']]  # complex UDM syntax
1473
		zone['expire'] = [soa['expire']]  # complex UDM syntax
1431
		zone['ttl'] = [soa['ttl']]  # complex UDM syntax
1474
		zone['ttl'] = [soa['ttl']]  # complex UDM syntax
1432
		if dns_type == 'forward_zone':
1475
		if dns_type == 'forward_zone':
1433
			zone['a'] = a
1476
			zone['a'] = [r.data for r in a_ndrRecord_list]
1434
			zone['mx'] = mx
1477
			zone['mx'] = mx
1435
		zone.create()
1478
		zone.create()
1436
1479

Return to bug 53623