#!/bin/bash targethost="$1" if [ -z "$1" ]; then echo "usage: $0 " exit 2 fi eval "$(ucr shell domainname kerberos/realm)" if ! klist -s || ! klist 2>/dev/null | grep -q "^ *Principal: Administrator@$kerberos_realm$"; then kinit Administrator if ! [ $? -eq 0 ]; then exit 1 fi fi ldif=$(univention-s4search DC="$targethost" --cross-ncs --show-binary) tombstoned=0 if grep -q 'dNSTombstoned: TRUE' <<<"$ldif"; then dn=$(sed -n 's/^dn: //p' <<<"$ldif") tombstoned=1 ldbmodify -H /var/lib/samba/private/sam.ldb <<-%EOR dn: $dn changetype: modify replace: dNSTombstoned dNSTombstoned: FALSE %EOR fi txt=$(grep -E '(ipv4|ipv6)' <<<"$ldif" | sort | uniq) ipv4_addrs=( $(sed -n 's/^ *ipv4 *: //p' <<<"$txt") ) ipv6_addrs=( $(sed -n 's/^ *ipv6 *: //p' <<<"$txt") ) { if [ -n "${ipv4_addrs}" ]; then echo "update delete $targethost.$domainname A" for ip in "${ipv4_addrs[@]}"; do echo "update add $targethost.$domainname 900 A $ip" done fi if [ -n "${ipv6_addrs}" ]; then echo "update delete $targethost.$domainname AAAA" for ip in "${ipv6_addrs[@]}"; do echo "update add $targethost.$domainname 900 AAA $ip" done fi echo send } | nsupdate -g