BEGIN { if (basedn == "") { basedn="ou=dns-dlz,dc=company,dc=com"; } # endif numrecords = 0; numdnsrecords = 0; inDN = 0; DNSobject = 0; rdn = ""; dom = ""; ptrrecord = ""; hinforecord = ""; soarecord = ""; cnamerecord = ""; TTL = 3600; #zones[ "dummy"] = "dummy"; print "# generated DNS import file - rather fix the input file than this one ;)" print "# generated by dnszone2dlzldap.awk, with base DN " basedn print "" } /somestuff/ { } /^dn: / { # a new record numrecords ++; if (inDN == 1) { print "# converter error: already in record."; } else { inDN = 1; } # endif } /^objectClass: dNSZone/ { # a DNS object numdnsrecords ++; DNSobject = 1; } /^relativeDomainName: / { # the name of the object rdn = $2; } /^zoneName: / { # the name of the containing DNS zone dom = $2; # we don't want a trailing "dot" if (substr( dom, length( dom), 1) == ".") { dom = substr( dom, 1, length( dom) - 1); } # endif } /^aRecord: / { # IP address arecords[ $2] = $2; } /^pTRRecord: / { # pointer to host name if (ptrrecord == "") { ptrrecord = $2; } else { print "# error: \"PTR\" record already set - new value lost." } # endif } /^hInfoRecord: / { # host info if (hinforecord == "") { hinforecord = substr( $0, index( $0, ": ") + 2); } else { print "# error: \"HINFO\" record already set - new value lost." } # endif } /^sOARecord: / { # zone of authority if (soarecord == "") { soarecord = substr( $0, index( $0, ": ") + 2); } else { print "# error: \"SOA\" record already set - new value lost." } # endif } /^cNAMERecord: / { # canonical name if (cnamerecord == "") { cnamerecord = $2; } else { print "# error: \"CNAME\" record already set - new value lost." } # endif } /^nSRecord: / { # name server nsrecords[ $2] = $2; } /^$/ { # end-of-record if (DNSobject == 1) { # if we have not created the zone yet - do so if ( zones[ dom] == "" ) { print "# zone " dom; # output LDIF for new zone print "dn: dlzZoneName=" dom "," basedn print "objectclass: dlzZone" print "dlzZoneName: " dom print "" # marker - to avoid re-defining zones[ dom] = dom; } # endif # the containing host object print "# host " rdn "." dom; print "dn: dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzHost" print "dlzHostName: " rdn print "" # a sub-entry per record - need a unique dn, so we use a counter subid = 1; for (i in arecords) { print "dn: dlzRecordID=" subid ",dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzARecord" print "dlzRecordID: " subid print "dlzHostName: " rdn print "dlzType: a" print "dlzIPAddr: " arecords[ i] print "dlzTTL: " TTL print "" # next sub-entry gets next id subid ++; } # endfor arecords for (i in nsrecords) { print "dn: dlzRecordID=" subid ",dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzNSRecord" print "dlzRecordID: " subid print "dlzHostName: " rdn print "dlzType: ns" print "dlzData: " nsrecords[ i] print "dlzTTL: " TTL print "" # next sub-entry gets next id subid ++; } # endfor nsrecords if (ptrrecord != "") { print "dn: dlzRecordID=" subid ",dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzPTRRecord" print "dlzHostName: " rdn print "dlzType: ptr" print "dlzData: " ptrrecord print "dlzTTL: " TTL print "" # next sub-entry gets next id subid ++; } # endif if (hinforecord != "") { print "dn: dlzRecordID=" subid ",dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzTextRecord" print "dlzHostName: " rdn print "dlzType: hinfo" print "dlzData: " hinforecord print "dlzTTL: " TTL print "" # next sub-entry gets next id subid ++; } # endif if (soarecord != "") { split( soarecord, soafields, " "); print "dn: dlzRecordID=" subid ",dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzSOARecord" print "dlzHostName: " rdn print "dlzType: soa" print "dlzPrimaryns: " soafields[ 1] print "dlzAdminEmail: " soafields[ 2] print "dlzSerial: " soafields[ 3] print "dlzRefresh: " soafields[ 4] print "dlzRetry: " soafields[ 5] print "dlzExpire: " soafields[ 6] print "dlzMinimum: " soafields[ 7] print "dlzTTL: " TTL print "" # next sub-entry gets next id subid ++; } # endif if (cnamerecord != "") { print "dn: dlzRecordID=" subid ",dlzHostName=" rdn ",dlzZoneName=" dom "," basedn print "objectclass: dlzCNameRecord" print "dlzHostName: " rdn print "dlzType: cname" print "dlzData: " cnamerecord print "dlzTTL: " TTL print "" # next sub-entry gets next id subid ++; } # endif # printf( "# fqdn %s.%s, a %s, ptr %s, hinfo %s, soa %s, cname %s, ns %s\n", rdn, dom, arecord, ptrrecord, hinforecord, soarecord, cnamerecord, nsrecord); } # reset to start. DNSobject = 0; rdn = ""; dom = ""; inDN = 0; for (i in arecords) { delete arecords[ i] } #endfor for (i in nsrecords) { delete nsrecords[ i] } #endfor ptrrecord = ""; hinforecord = ""; soarecord = ""; cnamerecord = ""; } END { # generate some helper elements if (binddn == "") { binddn="cn=Manager,o=bind-dlz"; } if (bindpw == "") { bindpw="secret"; } if (ldapserver == "") { ldapserver="127.0.0.1"; } print "" print "# The following lines need to be added to the bind configuration to access the LDAP-based zones:" print "# dlz \"dlz-ldap\" {" print "# database \"ldap 2" print "# v3 simple {" binddn "} {" bindpw "} {" ldapserver "}" print "# ldap:///dlzZoneName=$zone$," basedn "???objectclass=dlzZone" print "# ldap:///dlzHostName=$record$,dlzZoneName=$zone$," basedn "?dlzTTL,dlzType,dlzPreference,dlzData,dlzIPAddr?sub?(&(objectclass=dlzAbstractRecord)(!(dlzType=soa)))" print "# ldap:///dlzHostName=@,dlzZoneName=$zone$," basedn "?dlzTTL,dlzType,dlzData,dlzPrimaryNS,dlzAdminEmail,dlzSerial,dlzRefresh,dlzRetry,dlzExpire,dlzMinimum?sub?(&(objectclass=dlzAbstractRecord)(dlzType=soa))" print "# ldap:///dlzZoneName=$zone$," basedn "?dlzTTL,dlzType,dlzHostName,dlzPreference,dlzData,dlzIPAddr,dlzPrimaryNS,dlzAdminEmail,dlzSerial,dlzRefresh,dlzRetry,dlzExpire,dlzMinimum?sub?(&(objectclass=dlzAbstractRecord)(!(dlzType=soa)))" print "# ldap:///dlzZoneName=$zone$," basedn "??sub?(&(objectclass=dlzXFR)(dlzIPAddr=$client$))\";" print "# };" print "#" printf( "# statistics: read %d records, %d were DNS records.\n", numrecords, numdnsrecords); }