|
1095 |
ud.debug(ud.MODULE, ud.ERROR, "26univention-samba.inst failed with %d" % (p1.returncode,)) |
1095 |
ud.debug(ud.MODULE, ud.ERROR, "26univention-samba.inst failed with %d" % (p1.returncode,)) |
1096 |
raise sambaJoinScriptFailed() |
1096 |
raise sambaJoinScriptFailed() |
1097 |
|
1097 |
|
1098 |
def add_host_record_in_ad(uid=None, binddn=None, bindpw=None, bindpwdfile=None, fqdn=None, ip=None, sso=False): |
1098 |
def add_host_record_in_ad(uid=None, binddn=None, bindpw=None, bindpwdfile=None, fqdn=None, ipv4=None, ipv6=None, sso=False): |
1099 |
|
1099 |
|
1100 |
pwdfile = None |
1100 |
pwdfile = None |
1101 |
create_pwdfile = False |
1101 |
create_pwdfile = False |
|
1115 |
pwdfile = bindpw |
1115 |
pwdfile = bindpw |
1116 |
|
1116 |
|
1117 |
# take myself as default |
1117 |
# take myself as default |
1118 |
if not ip: |
1118 |
if not ipv4: |
1119 |
ip = Interfaces().get_default_ip_address().ip |
1119 |
ipv4 = Interfaces().get_default_ipv4_address().ip |
|
|
1120 |
if not ipv6: |
1121 |
ipv6 = Interfaces().get_default_ipv6_address().ip |
1120 |
|
1122 |
|
1121 |
if sso and not fqdn: |
1123 |
if sso and not fqdn: |
1122 |
fqdn = ucr.get('ucs/server/sso/fqdn', 'ucs-sso.' + domainname) |
1124 |
fqdn = ucr.get('ucs/server/sso/fqdn', 'ucs-sso.' + domainname) |
1123 |
|
1125 |
|
1124 |
if not uid or not pwdfile or not fqdn or not ip: |
1126 |
if not (uid and pwdfile and fqdn and (ipv4 or ipv6)): |
1125 |
print 'Missing binddn/bindpw/bindpwdfile/fqdn or ip, do nothing!' |
1127 |
print 'Missing binddn/bindpw/bindpwdfile/fqdn or ipv4/ipv6, do nothing!' |
1126 |
return False |
1128 |
return False |
1127 |
|
1129 |
|
1128 |
ad_domain_info = lookup_adds_dc() |
1130 |
ad_domain_info = lookup_adds_dc() |
|
1129 |
ad_ip = ad_domain_info['DC IP'] |
1131 |
ad_ip = ad_domain_info['DC IP'] |
1130 |
found = False |
1132 |
found = False |
1131 |
|
1133 |
|
1132 |
print "Create %s (%s) A record on %s" % (fqdn, ip, ad_ip) |
1134 |
resolver = dns.resolver.Resolver() |
|
|
1135 |
resolver.lifetime = 10 |
1136 |
resolver.nameservers = [ad_ip] |
1133 |
|
1137 |
|
1134 |
# check if we are already defined as host record |
1138 |
if ipv4: |
1135 |
try: |
1139 |
print "Create %s (%s) A record on %s" % (fqdn, ipv4, ad_ip) |
1136 |
resolver = dns.resolver.Resolver() |
1140 |
|
1137 |
resolver.lifetime = 10 |
1141 |
# check if we are already defined as host record |
1138 |
resolver.nameservers = [ad_ip] |
1142 |
try: |
1139 |
response = resolver.query(fqdn, 'A') |
1143 |
response = resolver.query(fqdn, 'A') |
1140 |
for data in response: |
1144 |
for data in response: |
1141 |
if str(data) == str(ip): |
1145 |
if str(data) == str(ipv4): |
1142 |
found = True |
1146 |
found = True |
1143 |
except dns.resolver.NXDOMAIN: |
1147 |
except dns.resolver.NXDOMAIN: |
1144 |
found = False |
1148 |
found = False |
1145 |
except Exception as err: |
1149 |
except Exception as err: |
1146 |
print 'failed to query for A record (%s, %s)' % (err.__class__.__name__, err.message) |
1150 |
print 'failed to query for A record (%s, %s)' % (err.__class__.__name__, err.message) |
1147 |
found = False |
1151 |
found = False |
1148 |
if found: |
1152 |
if found: |
1149 |
print '%s A record for %s found' % (fqdn, ip) |
1153 |
print '%s A record for %s found' % (fqdn, ipv4) |
|
|
1154 |
ipv4 = None |
1155 |
|
1156 |
if ipv6: |
1157 |
print "Create %s (%s) AAA record on %s" % (fqdn, ipv6, ad_ip) |
1158 |
|
1159 |
# check if we are already defined as host record |
1160 |
try: |
1161 |
response = resolver.query(fqdn, 'AAA') |
1162 |
for data in response: |
1163 |
if str(data) == str(ipv6): |
1164 |
found = True |
1165 |
except dns.resolver.NXDOMAIN: |
1166 |
found = False |
1167 |
except Exception as err: |
1168 |
print 'failed to query for AAA record (%s, %s)' % (err.__class__.__name__, err.message) |
1169 |
found = False |
1170 |
if found: |
1171 |
print '%s AAA record for %s found' % (fqdn, ipv6) |
1172 |
ipv6 = None |
1173 |
|
1174 |
if not (ipv4 or ipv6): |
1150 |
return True |
1175 |
return True |
1151 |
|
1176 |
|
1152 |
# create host record |
1177 |
# create host record |
1153 |
fd = tempfile.NamedTemporaryFile(delete=False) |
1178 |
fd = tempfile.NamedTemporaryFile(delete=False) |
1154 |
fd.write('server %s\n' % ad_ip) |
1179 |
fd.write('server %s\n' % ad_ip) |
1155 |
fd.write('update add %s 86400 A %s\n' % (fqdn, ip)) |
1180 |
if ipv4: |
|
|
1181 |
fd.write('update add %s 86400 A %s\n' % (fqdn, ipv4)) |
1182 |
if ipv6: |
1183 |
fd.write('update add %s 86400 AAA %s\n' % (fqdn, ipv6)) |
1156 |
fd.write('send\n') |
1184 |
fd.write('send\n') |
1157 |
fd.write('quit\n') |
1185 |
fd.write('quit\n') |
1158 |
fd.close() |
1186 |
fd.close() |
|
1172 |
ud.debug(ud.MODULE, ud.PROCESS, '%s' % stdout) |
1200 |
ud.debug(ud.MODULE, ud.PROCESS, '%s' % stdout) |
1173 |
if p1.returncode: |
1201 |
if p1.returncode: |
1174 |
print '%s failed with %d (%s)' % (cmd, p1.returncode, stderr) |
1202 |
print '%s failed with %d (%s)' % (cmd, p1.returncode, stderr) |
1175 |
print 'failed to add A record for ucs-sso to %s' % ad_ip |
1203 |
print 'failed to add DNS record for ucs-sso to %s' % ad_ip |
1176 |
return False |
1204 |
return False |
1177 |
finally: |
1205 |
finally: |
1178 |
os.unlink(fd.name) |
1206 |
os.unlink(fd.name) |