From 830c3395d37ef36bc96838ab27bc9457b3eb0d44 Mon Sep 17 00:00:00 2001 From: Ben Klang Date: Thu, 22 Dec 2005 20:35:09 +0000 Subject: [PATCH] + Bumped version to 0.3.7 + Changed default location of ldap.conf to /etc/ldap.conf + Added note on potential security vulns in deprecated/webadmin to README + Change port declarations and format strings from int to unsigned short to match standards + Updated doc/README.html git-svn-id: https://svn.alkaloid.net/gpl/ldap2dns/trunk@216 06cd67b6-e706-0410-b29e-9de616bca6e9 --- ChangeLog | 9 +- FAQ | 15 +- Makefile | 3 +- doc/README.html | 991 +++++++++++++++++++++++++++++++++--------------- ldap2dns.c | 81 ++-- 5 files changed, 762 insertions(+), 337 deletions(-) diff --git a/ChangeLog b/ChangeLog index 673ec2a..098ef36 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,6 +1,13 @@ # $Id$ -Version 0.3.6 (latest) +Version 0.3.7 (latest) ++ Changed default location of ldap.conf to /etc/ldap.conf ++ Added note on potential security vulns in deprecated/webadmin to README ++ Changed port declarations/format strings from int to unsigned short + to match standards ++ Updated doc/README.html + +Version 0.3.6 + New maintainer: Ben Klang + Fixed bug with duplicate OIDs in dns.schema from partially applied patch + Renamed schema file to ldap2dns.schema diff --git a/FAQ b/FAQ index f57771d..347f73a 100644 --- a/FAQ +++ b/FAQ @@ -1,6 +1,8 @@ 1) What happened to the webadmin directory? -2005-12-07 bklang +2005-12-22 bklang +** See security note at the end of this section regarding the old webadmin ** + I have deprecated that code in favor of another project I am working on. It is called Beatnik and is a Horde framework module. The status of the webadmin code was unclear and I was not willing to support it so I deprecated it. I @@ -12,6 +14,17 @@ own. You might also contact the author, Jacob Rief (jacob.rief@tiscover.com) for more information but he is no longer interested in maintaing this work so do not depend on him. +During a routine code audit on the ldap2dns sources a number of potential LDAP +injection vulnerabilities were discovered. Since this code is deprecated no +attempt to correct these flaws has been made. + + +IF YOU CHOOSE TO RUN THE DEPRECATED WEBADMIN SOFTWARE: Please take all +necessary steps to secure your environment. The author of this package takes no +responsibility for any problems related to the flawed webadmin code. + +Thanks to Erik Cabetas for bringing these issues to my attention. + 2) Why have you deprecated all that code? 2005-12-07 bklang diff --git a/Makefile b/Makefile index 7505ab3..5b3a646 100644 --- a/Makefile +++ b/Makefile @@ -54,7 +54,8 @@ install: all install -o root -g root -m 644 ldap2dns.schema $(LDAPCONFDIR)/schema/ clean: - rm -f *.o *.o-dbg ldap2dns ldap2dnsd data* *.db core $(SPECFILE) + rm -f *.o *.o-dbg ldap2dns ldap2dns-dbg ldap2dnsd data* *.db core \ + $(SPECFILE) tar: clean cd ..; \ diff --git a/doc/README.html b/doc/README.html index 161a655..32f84b5 100644 --- a/doc/README.html +++ b/doc/README.html @@ -1,353 +1,738 @@ -

LDAP to DNS gateway

-

-ldap2dns is a program to create DNS (Domain Name Service) records directly -from a LDAP directory. It can and should be be used to replace the secondary -name-server by a second primary one.
-ldap2dns reduces all kind of administration overhead: -No more flat file editing, no more zone file editing. After having installed -ldap2dns, the administrator only has to access the LDAP directory.
-Optionally she can add access control for each zone, create a GUI -and add all other kind of zone and resource record information without -interfering with the DNS server.
-ldap2dns is designed to write ASCII data files used by tinydns -from the djbdns package, but also may be used to write .db-files used -by named as found in the BIND package.
-

+ + +

+ +

LDAP to DNS gateway

+

ldap2dns is a program to read DNS (Domain Name Service) +records from an LDAP directory and format them into flat files suitable for TinyDNS (or Bind).

+

ldap2dns reduces all kind of administration overhead: No +more flat file editing, no more zone file editing. After having +installed ldap2dns, the administrator only has to access the +LDAP directory.
+Optionally access control can be configured for each zone, GUIs can +be more easily implemented, and add all other kind of zone and resource +record information can be managed without interfering with the DNS server.
+ldap2dns is designed to write ASCII data files used by +tinydns from the djbdns package, but also may be used +to write .db-files used by named as found in the BIND +package.

-

1. Introduction

-Often it is desirable to store DNS information in a database rather than -in flat text files. This can greatly help to reduce administration overhead -since associate information such as billing contact, account management, etc. -can be stored and processed inside the same database. Also due to the nature of -DNS, information must be stored redundantly on two or more hosts. -The classical data replication through zone transfer is unreliable, insecure -and difficult to administer.
-To solve this problem some proprietary attempts have been proposed to -store DNS information in relational databases. The nature of DNS, however, -is hierarchical and such should the database be. Using a relational database -to store DNS information is undesirable, because it becomes difficult -to store free form information. Within a hierachical data scheme, the -administrator might define more than one IP-address for each canonical name. -To implement such a feature in a relational database without breaking the -normalization rules, one would have to add another table.
-One of the most widely spread hierarchical database protocols is LDAP. -ldap2dns retrieves DNS information stored in an LDAP directory service -and generates a file suitable for name-servers.
-Actually the most widely spread name-servers -named and -tinydns are -supported. ldap2dns specially has been designed to work with -tinydns and is the favored name server daemon for the author of this program. -ldap2dns can also generate files suitable for named version 8, -but this feature is not well supported. -There is a - -RFC for a format description how to store DNS information in LDAP. -This paper a draft RFC which expired in February 1999, looks as if it has been -specially designed to be used by named. This scheme -does not have strict attribute-value-pair mapping, making it difficult to be used by -user interfaces. It also lacks of an implementation (or I have never heard of any).
-Since tinydns is going another descriptive way. Therefore I implemented a similar -object-scheme more suitable for tinydns. Two object-classes have been defined. -DNSzone stores all the information to define a DNS zone, such as the SOA -(Start Of Authority), serial numbers etc. DNSrrset is used to store the information -for a single resource record, such as the domain name, IP-addresses, class and type.
-Here are the tables: -

-

DNSzone

-This object-class represents a DNS zone. It is the container for all the resource records -within a zone. Zones can be primary or secondary. If used in conjunction with -tinydns zones are always primary. Secondary zones don't make sense anyway! -In addition to being a container, the zone object has attributes related to -the management of the zone. These include the zone's SOA information. Each zone-object -can have none to many children of class DNSrrset.
- - - - - - - - - - - - - - - - -
ATTRIBUTEVALUEComment
objectclassDNSzonerequired
cncommon namerequired
DNSzonenameName of the zonerequired, multivalued
DNSserialSerial number of SOAoptional
DNSrefreshRefresh time of SOAoptional, only used for zone transfers
DNSretryRetry time of SOAoptional, only used for zone transfers
DNSexpireExpire time of SOAoptional, only used for zone transfers
DNSminimumMinimum time to liveoptional, only used for zone transfers
DNSadminmailboxHostmaster's contact addressoptional
DNSzonemasterPrimary nameserver for this zoneoptional
DNStypeSOAmust be SOA
DNSclassINmust be IN
DNSttltime to liveoptional, only used with tinydns
DNStimestamptimestampoptional, only used with tinydns
-
    -
  • DNSzonename: This field is required to describe the zone's domain name, for instance -myorg.com. More than one DNSzonename my be specified for a DNSzone so that the -same host is accessable with different zonenames.
  • +
    -
  • DNSserial: This is the serial number as used for BIND's zone transfers. Here it is -used to inform ldap2dns that it has to rebuild its data-file. Without increasing the serial -number ldap2dns will ignore all modifications until it is restarted.
  • + + +Often it is desirable to store DNS information in a database rather +than in flat text files. This can greatly help to reduce +administration overhead since associate information such as billing +contact, account management, etc. can be stored and processed +inside the same database. Also due to the nature of DNS, +information must be stored redundantly on two or more hosts. The +classical data replication through zone transfer is unreliable, +insecure and difficult to administer.
    +To solve this problem some proprietary attempts have been proposed +to store DNS information in relational databases. The nature of +DNS, however, is hierarchical and such should the database be. +Using a relational database to store DNS information is +undesirable, because it becomes difficult to store free form +information. Within a hierachical data scheme, the administrator +might define more than one IP-address for each canonical name. To +implement such a feature in a relational database without breaking +the normalization rules, one would have to add another table.
    +One of the most widely spread hierarchical database protocols is +LDAP. ldap2dns retrieves DNS information stored in an LDAP +directory service and generates a file suitable for +name-servers.
    +Actually the most widely spread name-servers named and tinydns are supported. -
  • DNSrefresh, DNSretry, DNSexpire, DNSminimum: You may safly ignore these numbers -if You don't do zone-transfers. Since Your secondary nameserver will connect to the LDAP -server the same way Your primary does, You don't need zone-transfers anyway.
  • +ldap2dns specially has been designed to work with tinydns +and is the favored name server daemon for the author of this +program. ldap2dns can also generate files suitable for +named version 8, but this feature is not well supported. +There is a +RFC for a format description how to store DNS information in +LDAP. This paper a draft RFC which expired in February 1999, looks +as if it has been specially designed to be used by named. +This scheme does not have strict attribute-value-pair mapping, +making it difficult to be used by user interfaces. It also lacks of +an implementation (or I have never heard of any).
    +Since tinydns is going another descriptive way. Therefore I +implemented a similar object-scheme more suitable for tinydns. +
    -
  • DNSzonemaster: Here you specify the canonical name of your primary nameserver.
  • + + +
      +
    • Install an LDAP server such as openldap. Other LDAP implementations may +work but have not been tested. Also install the development +libraries and include files.
    • +
    • Install djbdns or if +you really have to, go with BIND.
      +I suggest to install tinydns included in the djbdns -
    • DNSadminmailbox: This is the contact address of Your DNS-administrator. The first dot -is converted to a @.
    • - -
    • DNStype: Must be SOA (Start Of Authority)
    • - -
    • DNSclass: Must be IN (Internet, or do still use Chaosnet?)
    • - -
    • DNSttl: This is the time-to-live value as used by tinydns. -If TTL is nonzero (or omitted), the timestamp is a starting time from whereon this zone's -information is valid. If TTL is zero, the timestamp is an ending time (``time to die'').
    • - -
    • DNStimestamp: This is the timestamp as used by tinydns. It represents a -string as external TAI64 timestamp, printed as 16 lowercase hexadecimal characters
    • -
    -

    - -

    DNSrrset

    -The Resource Record Set represents all of the resource records for -a given host name within a zone. It must be a child of a DNSzone object.
    - - - - - - - - - - - - - -
    ATTRIBUTEVALUEComment
    objectclassDNSrrsetrequired
    cncommon namerequired
    DNSdomainnameName of this recordoptional, relative to zonename
    DNSipaddrIP addressoptional, mutivalued
    DNScnameCanonical nameoptional, without ending dot relative to zonename
    DNSpreferenceintegeroptional, only used for MX records
    DNStypeA, CNAME, NS, MX, PTR or TXTmust be any valid record type
    DNSclassINmust be IN
    DNSttltime to liveoptional, only used with tinydns
    DNStimestamptimestampoptional, only used with tinydns
    -

    - -

      -
    • DNSrrset: This object-class must be a direct child of DNSzone. Its dn should be -specified as
      cn=domainname,cn=zonename,...
    • - -
    • DNSdomainname This is the partial domain-name, ie. the part in front of the -zone-name.
    • - -
    • DNSipaddr: This specifies the IP-address in dotted format. It can be used for DNSrrset's -of type A, NS, MX or PTR. DNSipaddr is multivalued to specifiy more than one -IP-address for a service. If used in DNSrrset's with DNStype = PTR it -overrides the old-fashioned form used in DNSdomainname such as 13.178.23.in-addr.arpa -for reverse lookups.
    • - -
    • DNScname: Whenever there is a mapping of a domain-name to a canonical name, use -this attribute. DNScname may be used for DNSrrset's with DNStype CNAME, -NS, MX, PTR or TXT. If the last character of a CNAME is a dot its name is considered -absolute. If it does not contain a dot, its name is prepended to the zone-name.
    • - -
    • DNSpreference: This number is the mail-exchange preference as used by BIND.
    • - -
    • DNStype: This must be A, CNAME, NS, MX, PTR or TXT. It specifies -the DNSrrset type.
    • - -
    • DNSclass: Must be IN
    • - -
    • DNSttl: This is the time-to-live value as used by tinydns. -If TTL is non-zero (or omitted), the time-stamp is a starting time from where-on this zone's -information is valid. If TTL is zero, the timestamp is an ending time (``time to die'').
    • - -
    • DNStimestamp: This is the timestamp as used by tinydns. It represents a -string as external TAI64 time-stamp, printed as 16 lowercase hexadecimal characters
    • -
    -

    - -

    2. Installation

    -
      -
    • Install an LDAP server such as openldap. Other -LDAP implementations may work but have not been tested. Also install the -development libraries and include files.
    • - -
    • Install djbdns or if you really -have to, go with BIND.
      -I suggest to install tinydns included in the djbdns package, because it is -safer, but You may have reasons why You want to use BIND.
    • - -
    • Install ldap2dns
      +package, because it is safer, but You may have reasons why You want +to use BIND.
    • +
    • Install ldap2dns
      Unpack the package and build it: -
      -gzcat ldap2dns.tar.gz | tar x
      -cd ldap2dns-version
      -make
      -make install
      -
      -If you run ldap2dns togther with tinydns, go into -/var/tinydns and run ldap2tinydns-conf. -
    • +
      +$ gzcat ldap2dns.tar.gz | tar x
      +$ cd ldap2dns-version
      +$ make
      +$ make install
      +
      +Copy the file ldap2dns.schema into the directory +/etc/openldap/schema. Add the following +line to Your slapd.conf file:
      +
      +include         /etc/openldap/schema/ldap2dns.schema
      +
      +Now restart your LDAP server. +
      +Note: If you are running OpenLDAP 2.0 or earlier look for appropriate +schema files for your version in the deprecated/ subdirectory. These +files are known to work as of ldap2dns 0.3.5 but are no longer supported for future +feature updates.
      +
      +
    • Start to populate your LDAP server with DNS information. As a +first test do +
      +$ ldapadd -D "binddn" -w password < example.ldif
      +
      +Replace 'myorg' and 'binddn' with whatever is appropriate on Your +system. Start a search and see if something was added +
      +$ ldapsearch -D "binddn" "objectclass=dnsrrset"
      +
    • +
    • Test ldap2dns +
      +$ ./ldap2dns -D "binddn" [ -b "searchbase" ] [ -w passwd ] -o data -o db -L
      +
      +This should create a 'data' file, a 'corp.local.db' file and should +print the DNS content.
      +Note: The data file is text data which can be processed with +tinydns-data. corp.local.db is the file as used by +named. If You are using bind, You also have to adopt the +file /etc/named.conf and You have to restart named.
    • -
    • Add the extra object-classes to the slapd.conf file. -If You are using openldap-1.2.x:
      -copy the files dns.oc.conf and dns.ac.conf into the directory /etc/openldap or -appropriate and add the following two lines to Your slapd.conf file:
      -
      -include         /etc/openldap/dns.at.conf
      -include         /etc/openldap/dns.oc.conf
      -
      -or, if You are using openldap-2.0.x:
      -copy the file dns.schema-2.0 into the directory /etc/openldap/schema -and rename it to dns.schema. -If You are using openldap-2.2.x:
      -copy the file dns.schema-2.2 into the directory /etc/openldap/schema -and rename it to dns.schema. -Add the following line to Your slapd.conf file:
      -
      -include         /etc/openldap/schema/dns.schema
      -
      -Now restart your LDAP server.
    • -

      +

    +
    + + +Two object-classes have been defined. +DNSzone stores all the information to define a DNS zone, +such as the SOA (Start Of Authority), serial numbers etc. +DNSrrset is used to store the information for a single +resource record, such as the domain name, IP-addresses, class and +type.
    +Here are the tables: +

    DNSzone

    +This object-class represents a DNS zone. It is the container for +all the resource records within a zone. Zones can be primary or +secondary. If used in conjunction with tinydns zones are +always primary. Secondary zones don't make sense anyway! In +addition to being a container, the zone object has attributes +related to the management of the zone. These include the zone's SOA +information. Each zone-object can have none to many children of +class DNSrrset.
    -
  • Start to populate your LDAP server with DNS information. As a first test do -
    -$ ldapadd -D "binddn" -w password < example.ldif
    -
    -Replace 'myorg' and 'binddn' with whatever is appropriate on Your system. -Start a search and see if something was added -
    -$ ldapsearch -D "binddn" "objectclass=dnsrrset" 
  • - + + + + + + + + + + + -
  • Test ldap2dns -
    -$ ./ldap2dns -D "binddn" [ -b "searchbase" ] [ -w passwd ] -o data -o db -L
    -
    -This should create a 'data' file, a 'corp.local.db' file and should print the -DNS content.
    -Note: The data file is text data which can be processed with tinydns-data. -corp.local.db is the file as used by named. If You are using bind, You also -have to adopt the file /etc/named.conf and You have to restart named.
  • - -

    +

    + + + + + + + + + + -

    3. Running ldap2dns

    -If You are a tinydns user, run ldap2dns in /services/tinydns/root.
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ATTRIBUTEVALUEComment
    objectclassDNSzonerequired
    cncommon namerequired
    DNSzonenameName of the zonerequired, multivalued
    DNSserialSerial number of SOAoptional
    DNSrefreshRefresh time of SOAoptional, only used for zone transfers
    DNSretryRetry time of SOAoptional, only used for zone transfers
    DNSexpireExpire time of SOAoptional, only used for zone transfers
    DNSminimumMinimum time to liveoptional, only used for zone transfers
    DNSadminmailboxHostmaster's contact addressoptional
    DNSzonemasterPrimary nameserver for this zoneoptional
    DNStypeSOAmust be SOA
    DNSclassINmust be IN
    DNSttltime to liveoptional, only used with tinydns
    DNStimestamptimestampoptional, only used with tinydns
    + +
      +
    • DNSzonename: This field is required to describe the +zone's domain name, for instance myorg.com. More than one +DNSzonename my be specified for a DNSzone so that the +same host is accessable with different zonenames.
    • +
    • DNSserial: This is the serial number as used for BIND's +zone transfers. Here it is used to inform ldap2dns that it +has to rebuild its data-file. Without increasing the serial number + +ldap2dns will ignore all modifications until it is +restarted.
    • +
    • DNSrefresh, DNSretry, DNSexpire, DNSminimum: You may +safly ignore these numbers if You don't do zone-transfers. Since +Your secondary nameserver will connect to the LDAP server the same +way Your primary does, You don't need zone-transfers anyway.
    • +
    • DNSzonemaster: Here you specify the canonical name of +your primary nameserver.
    • +
    • DNSadminmailbox: This is the contact address of Your +DNS-administrator. The first dot is converted to a @.
    • + +
    • DNStype: Must be SOA (Start Of Authority)
    • +
    • DNSclass: Must be IN (Internet, or do still use +Chaosnet?)
    • +
    • DNSttl: This is the time-to-live value as used by + +tinydns. If TTL is nonzero (or omitted), the timestamp is a +starting time from whereon this zone's information is valid. If TTL +is zero, the timestamp is an ending time (``time to die'').
    • +
    • DNStimestamp: This is the timestamp as used by +tinydns. It represents a string as external TAI64 timestamp, +printed as 16 lowercase hexadecimal characters
    • +
    +

    DNSrrset

    +The Resource Record Set represents all of the resource records for +a given host name within a zone. It must be a child of a DNSzone +object.
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    ATTRIBUTEVALUEComment
    objectclassDNSrrsetrequired
    cncommon namerequired
    DNSdomainnameName of this recordoptional, relative to zonename
    DNSipaddrIP addressoptional, mutivalued
    DNScnameCanonical nameoptional, without ending dot relative to zonename
    DNSpreferenceintegeroptional, only used for MX records
    DNStypeA, CNAME, NS, MX, PTR or TXTmust be any valid record type
    DNSclassINmust be IN
    DNSttltime to liveoptional, only used with tinydns
    DNStimestamptimestampoptional, only used with tinydns
    DNSsrvprioritySRV Priorityoptional, defaults to 0 for SRV records
    DNSsrvweightSRV Weightoptional, defaults to 0 for SRV records
    DNSsrvportSRV PortRequired for SRV records
    +
    +
      + +
    • DNSrrset: This object-class must be a direct child of +DNSzone. Its dn should be specified as +
      +cn=domainname,cn=zonename,...
      +
    • +
    • DNSdomainname This is the partial domain-name, ie. the +part in front of the zone-name.
    • + +
    • DNSipaddr: This specifies the IP-address in dotted +format. It can be used for DNSrrset's of type A, NS, +MX or PTR. DNSipaddr is multivalued to specifiy +more than one IP-address for a service. If used in +DNSrrset's with DNStype = PTR it overrides the +old-fashioned form used in DNSdomainname such as +13.178.23.in-addr.arpa for reverse lookups.
    • + +
    • DNScname: Whenever there is a mapping of a domain-name +to a canonical name, use this attribute. DNScname may be +used for DNSrrset's with DNStype CNAME, NS, MX, PTR or +TXT. If the last character of a CNAME is a dot its name is +considered absolute. If it does not contain a dot, its name is +prepended to the zone-name.
    • +
    • DNSpreference: This number is the mail-exchange +preference as used by BIND.
    • +
    • DNStype: This must be A, CNAME, NS, MX, PTR or + +TXT. It specifies the DNSrrset type.
    • +
    • DNSclass: Must be IN
    • +
    • DNSttl: This is the time-to-live value as used by +tinydns. If TTL is non-zero (or omitted), the time-stamp is +a starting time from where-on this zone's information is valid. If +TTL is zero, the timestamp is an ending time (``time to +die'').
    • +
    • DNStimestamp: This is the timestamp as used by + +tinydns. It represents a string as external TAI64 +time-stamp, printed as 16 lowercase hexadecimal characters
    • +
    • DNSsrvpriority: Integer representing the relative priority of this DNS SRV record. See menandmice.com for more information about DNS SRV records.
    • +
    • DNSsrvweight: DNS SRV record weight field. Integer
    • +
    • DNSsrvport: DNS SRV record port number. Integer
    • +
    +
    + + + +If You are a tinydns user, run ldap2dns in /services/tinydns/root.
    If You are an openldap user, the command line switches are the same as for ldapsearch or ldapadd. -
    -$ ldap2dns -D "binddn" [ -w passwd ] -b "searchbase" -o data -e "cd /var/tinydns/root && /usr/bin/tinydns-data"
    -
    +
    +$ ldap2dns -D "binddn" [ -w passwd ] -b "searchbase" \
    +-o data -e "cd /var/tinydns/root && /usr/bin/tinydns-data"
    +
    This generates a data file which is converted into a data.cdb by tinydns-data as -soon as ldap2dns detects a modification in the LDAP directory. -The password is required if You restrict read queries to authenticated users only. -Test with -
    +soon as ldap2dns detects a modification in the LDAP directory.
    +The password is required if You restrict read queries to authenticated users only.
    +Test with
    +
     $ dnsq any corp.local ipaddr
    -
    +
    Replace ipaddr with whatever You configured tinydns to listen to. -

    + If You are a BIND user, run ldap2dns in /var/named with -

    -$ ldap2dns -D "binddn" -w passwd -b "searchbase" -o db -e "kill -HUP `cat /var/run/named-pid`"
    -
    +
    +$ ldap2dns -D "binddn" -w passwd -b "searchbase" \
    +-o db -e "kill -HUP `cat /var/run/named-pid`"
    +
    Do not forget to add You primary definition to Your named.boot file. Your named should be restarted automatically as soon as ldap2dns detects a modification in the LDAP directory. If bind is not restarted, do so with -
    +
     # kill -HUP PID
    -
    -Now run -
    +
    +Now run +
     $ nslookup - localhost
     > ns1.corp.local
    -
    +
    Note that nslookup only works with tinydns if Your nameserver resolves its IP-address backwards. -

    -

    4. Running ldap2dnsd

    -ldap2dnsd is a hard link onto ldap2dns. If invoked, the program -starts as backgound-daemon and contineously checks for modifications in the LDAP directory. -If the the daemon sees a modification in the DNSserial numbers it updates the data + + +When ldap2dns is invoked as ldap2dnsd, the program +starts as backgound-daemon and continuously checks for modifications in the LDAP directory. +If the the daemon sees a modification in the DNSserial numbers it updates the data or .db files, depending what kind of output was configured. This check is done about once -a minute.
    -The command-line options for ldap2dnsd are the same as for ldap2dns. -Use the -u option to modify the update intervall. You may also use -u on ldap2dns -to start as a foreground daemon. This is useful if You want to run ldap2dns from -daemontools. To do this run ldap2tinydns-conf -in /service/tinydns and link /service/ldap2dns onto /service/tinydns/ldap2dns. -
    -# ln -s /service/tinydns/ldap2dns /service/ldap2dns
    -
    -After a few seconds daemontools starts ldap2dns which itself generates data -files whenever a modification is commited into the LDAP directory. -

    -ldap2dns and ldap2dnsd recognize the following options: -

    --D binddn specify the distinguished name to bind to the LDAP directory
    --w bindpasswd use bindpasswd as the password for simple authentication
    --b searchbase use searchbase as the starting point for the search instead of the default
    --o Generate a "data" file to be processed by tinydns-data. 
    --o db	For each zone generate a ".db" file to be used by named.
    --L[filename] print output in LDIF format for reimport. If no filename is specified output goes to stdout. 
    --h host specify the hostname of LDAP directory. Default is localhost.
    --p port portnumber to connect to LDAP directory. Defaults is 389
    +a minute and is configurable.
    +The command-line options for ldap2dnsd are the same as for ldap2dns. +Use the -u option to modify the update interval. You may also use -u on ldap2dns +to start as a foreground daemon. This is useful if You want to run ldap2dns from +daemontools.
    +
    +These instructions assume you will be running ldap2dns under +daemontoolsb> and that tinydns is also running under +daemontools. These instructions also assume you are using Dan Bernstein's +standard directory locations. Make sure you change the below examples +to match your environment.
    +
    +Start by creating the a non-root user to run your ldap2dns and associated +logging mechanism: +
    +# groupadd -r ldap2dns
    +# useradd -r -d /dev/null -s /bin/false -c "ldap2dns Daemon" \
    + -g ldap2dns ldap2dns
    +# groupadd -r l2dnslog
    +# useradd -r -d /dev/null -s /bin/false -c "ldap2dns Logger" \
    + -g l2dnslog l2dnslog
    +
    +
    +Next configure the ldap2dns area to be managed by daemontools. +Typically this is /etc/ldap2dns +
    +# cd /etc
    +# ldap2tinydns-conf ldap2dns l2dnslog /etc/ldap2dns /etc/tinydns/root
    +
    +The syntax is close to tinydns-conf except that you will also need to specify +the path to the root directory for tinydns. This is the directory that +holds the data file.
    +
    +Next edit the file /etc/ldap2dns/run and optionally the environment +variables in /etc/ldap2dns/env as necessary for your environment. This +may include configuring a base DN, a bind DN, a password, and an interval.
    +
    +When everything is ready configured properly create a symlink from +/etc/ldap2dns into /service. This action will cause +daemontools to launch ldap2dns. +
    +# ln -s /etc/ldap2dns /service/ldap2dns
    +
    +After a few seconds daemontools starts ldap2dnsd which itself generates data +files whenever a modification is commited into the LDAP directory. + +ldap2dns and ldap2dnsd recognize the following options: +
    +-D binddn specify the distinguished name to bind to the LDAP directory
    +-w bindpasswd use bindpasswd as password for simple authentication
    +-b searchbase use searchbase as starting point for search instead default
    +-o data generate a "data" file to be processed by tinydns-data
    +-o db for each zone generate a "<zonename>.db" file to be used by named
    +-L[filename] print output in LDIF format to [filename] or stdout for reimport
    +-h host specify the hostname of LDAP directory. Default is localhost
    +-p port portnumber to connect to LDAP directory. Defaults is 389
     -v run in verbose mode
     -vv even more verbose
     -V print version and exit
    --u numsecs update DNS data every numsecs.
    -
    -ldap2dns and ldap2dnsd recognizes the following environement variables:
    -TINYDNSDIR: Specifies the directory where ldap2dns writes its data file.
    -LDAP2DNS_UPDATE: Specifies the update intervall as the -u command line option would.
    -LDAP2DNS_OUTPUT: Specifies the default output, as the -o command line option would. -

    -ldap2dns and ldap2dnsd use the following parameters from /etc/ldap.conf if not -specified on the command line: -BASE: The LDAP search base.
    -HOST: The LDAP server.
    -PORT: The LDAP port. -

    +-u numsecs update DNS data every numsecs. +

    +ldap2dns and ldap2dnsd recognizes the following environement +variables:
    +TINYDNSDIR: Specifies the directory where ldap2dns writes its data +file.
    +LDAP2DNS_UPDATE: Specifies the update intervall as the -u command line +option would.
    +LDAP2DNS_OUTPUT: Specifies the default output, as the -o command line +option would. -

    5. Importing DNS data from Your named

    +ldap2dns and ldap2dnsd use the following parameters from +/etc/ldap.conf if not +specified on the command line: +BASE: The LDAP search base.
    +HOST: The LDAP server.
    +PORT: The LDAP port. + + + A perl-script import.pl is contained in this package. Edit the first lines of the script to conform to Your configuration. If You have installed the Perl packages Net::LDAP and Net::DNS skip the following lines, otherwise do -
    +
     # perl -MCPAN -e 'shell'
     (...snip...)
     > install Net::DNS
     > install Net::LDAP
    -
    +
    Now check that Your nameserver allows zone transfers to your host and run the import script: -
    +
     $ echo 'primary mydomain.org ' | ./import.pl
    -
    +
    for a single domain or -
    +
     # cat named.boot | ./import.pl
    -
    +
    to populate Your LDAP directory. -

    -

    6. Coming soon

    + + +Use the supplied data2ldap.pl in the scripts/ directory +
    +$ data2ldap.pl data data.ldif ou=DNS,dc=example,dc=com
    +
    +More to come...
    +
    + + + + A browser-based administration toolkit, which connects directly -to the LDAP-directory service. -Here is a screenshot -

    +to the LDAP-directory service. -

    7. To Do

    -
      -
    • Write a man page.
    • -
    • named.conf should be created automatically.
    • -
    -

    -

    8. Copyright and disclaimer

    -This program is licensed under the GPL version 2 or at Your choice any later -version.
    -It is maintained by Jacob Rief. -If you run ldap2dns on a productive nameserver, please mail me -and tell me on what OS and with which nameserver you do so. + + +
      +
    • Write a man page.
    • +
    • named.conf should be created automatically.
    • +
    + + +This program is Copyright 1999-2004 Jacob Rief and 2005 Ben Klang
    +This program is licensed under the GPL version 2
    +ldap2dns was originally written by Jacob Rief (jacob.rief@tiscover.com). It is now maintained by Ben Klang (ben@alkaloid.net). If you run ldap2dns on a production nameserver, please send the maintainer an email and mention on what OS and with which nameserver you do so.
    +
    +Disclaimer: The author and all contributors disclaim any kind of warranty or liability or suitability for any purpose. By running this software you agree that you are a competent systems administrator and will bear the responsibility for your actions.
    + + + +

    Latest Release: +ldap2dns-0.3.6 +

    +Released December 16, 2005 |  +ChangeLog | Download (tarball) +

    Old Releases:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    Versiontar.gzrpmsrpmReleased
    0.1.1ldap2dns2000-Sep-19
    0.1.2ldap2dns2000-Sep-22
    0.1.3ldap2dns2000-Sep-28
    0.1.4ldap2dns2000-Oct-04
    0.2.0ldap2dnsldap2dnsldap2dns2000-Dec-14
    0.2.2ldap2dnsldap2dnsldap2dns2001-Feb-16
    0.2.3ldap2dnsldap2dnsldap2dns2001-Mar-23
    0.2.4ldap2dnsldap2dnsldap2dns2001-May-08
    0.2.5ldap2dnsldap2dnsldap2dns2001-Jun-27
    0.2.6ldap2dnsldap2dnsldap2dns2001-Aug-09
    0.3.4ldap2dns2004-Apr-07
    0.3.5ldap2dns2005-Nov-30
    + +

    Developer Access:

    +The bleeding edge of ldap2dns is in the Alkaloid Networks subversion repository found at https://svn.alkaloid.net/gpl/ldap2dns/trunk. Following the Subversion standard, releases are kept in /gpl/ldap2dns/tags and branches are in /gpl/ldap2dns/branches.
    +
    +
+ \ No newline at end of file diff --git a/ldap2dns.c b/ldap2dns.c index 9f40eaf..7635d96 100644 --- a/ldap2dns.c +++ b/ldap2dns.c @@ -15,7 +15,7 @@ #include #define UPDATE_INTERVALL 59 -#define LDAP_CONF "/etc/ldap/ldap.conf" +#define LDAP_CONF "/etc/ldap.conf" #define OUTPUT_DATA 1 #define OUTPUT_DB 2 #define MAXHOSTS 10 @@ -100,11 +100,11 @@ static struct char binddn[128]; char hostname[MAXHOSTS][128]; char urildap[MAXHOSTS][128]; - int port[MAXHOSTS]; + unsigned short port[MAXHOSTS]; char password[128]; int usedhosts; int is_daemon; - int update_iv; + unsigned int update_iv; unsigned int output; int verbose; char ldifname[128]; @@ -172,7 +172,8 @@ static void print_usage(void) static void parse_hosts(char* buf) { - int i, port, k; + int i, k; + unsigned short port; char value[128], rest[512]; options.usedhosts = 0; @@ -182,13 +183,15 @@ static void parse_hosts(char* buf) if (!strncasecmp(buf, "ldap://", 7)) options.use_tls[i] = 1; if ((k = sscanf(buf, "%128s %512[A-Za-z0-9 .:/_+-]", value, rest))>=1) { - strcpy(options.urildap[i], value); + strncpy(options.urildap[i], value, sizeof(options.urildap[i])); + options.urildap[i][ sizeof(options.urildap[i]) -1 ] = '\0'; + options.usedhosts++; if (k==1) break; buf = rest; } else break; - } else if ((k = sscanf(buf, "%128s:%d %512[A-Za-z0-9 .:_+-]", value, &port, rest))>=2) { + } else if ((k = sscanf(buf, "%128s:%hd %512[A-Za-z0-9 .:_+-]", value, &port, rest))>=2) { strcpy(options.hostname[i], value); options.port[i] = port; options.usedhosts++; @@ -221,19 +224,23 @@ static int parse_options() if (ldap_conf = fopen(LDAP_CONF, "r")) { while(fgets(buf, 256, ldap_conf)!=0) { int i; - if (sscanf(buf, "BASE %128s", value)==1) - strcpy(options.searchbase, value); + if (sscanf(buf, "BASE %128s", value)==1){ + strncpy(options.searchbase, value, sizeof(options.searchbase)); + options.searchbase[sizeof(options.searchbase) -1] = '\0'; + } if (sscanf(buf, "URI %512[A-Za-z0-9 .:/_+-]", value)==1) parse_hosts(value); if (sscanf(buf, "HOST %512[A-Za-z0-9 .:_+-]", value)==1) parse_hosts(value); - if (sscanf(buf, "PORT %d", &len)==1) + if (sscanf(buf, "PORT %hd", &len)==1) for (i = 0; iipaddr[0], "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])==4) { /* lazy user, used DNSipaddr for reverse lookup */ - sprintf(buf, "%d.%d.%d.%d.in-addr.arpa", ip[3], ip[2], ip[1], ip[0]); + snprintf(buf, sizeof(buf), "%d.%d.%d.%d.in-addr.arpa", ip[3], ip[2], ip[1], ip[0]); } else { - strcpy(buf, rr->dnsdomainname); + strncpy(buf, rr->dnsdomainname, sizeof(buf)); + buf[ sizeof(buf) -1 ] = '\0'; } if (tinyfile) fprintf(tinyfile, "^%s:%s:%s:%s:%s\n", buf, rr->cname, rr->ttl, rr->timestamp, rr->location); @@ -486,7 +505,7 @@ static void parse_rr(struct resourcerecord* rr) sscanf(rr->rr, "%16s %16s %64s %64s", rr->class, rr->type, word1, word2); if (strcasecmp(rr->type, "NS")==0) { if (sscanf(word1, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])==4) { - sprintf(rr->ipaddr[0], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + snprintf(rr->ipaddr[0], sizeof(rr->ipaddr[0]), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); } else { int len = strlen(word1); expand_domainname(rr->cname, word1, len); @@ -495,14 +514,14 @@ static void parse_rr(struct resourcerecord* rr) if (sscanf(word1, "%s", rr->preference)!=1) rr->preference[0] = '\0'; if (sscanf(word2, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])==4) { - sprintf(rr->ipaddr[0], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + snprintf(rr->ipaddr[0], sizeof(rr->ipaddr[0]), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); } else { int len = strlen(word2); expand_domainname(rr->cname, word2, len); } } else if (strcasecmp(rr->type, "A")==0) { if (sscanf(word1, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])==4) - sprintf(rr->ipaddr[0], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + snprintf(rr->ipaddr[0], sizeof(rr->ipaddr[0]), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); else rr->ipaddr[0][0] = '\0'; } else if (strcasecmp(rr->type, "PTR")==0) { @@ -585,7 +604,7 @@ static void read_resourcerecords(char* dn, int znix) for (ipaddresses = 0; bvals[ipaddresses] && ipaddresses<256; ipaddresses++) { rr.ipaddr[ipaddresses][0] = '\0'; if (sscanf(bvals[ipaddresses]->bv_val, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])==4) { - sprintf(rr.ipaddr[ipaddresses], "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + snprintf(rr.ipaddr[ipaddresses], sizeof(rr.ipaddr[ipaddresses]), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); if (options.ldifname[0]) fprintf(ldifout, "%s: %s\n", attr, rr.ipaddr[ipaddresses]); } @@ -593,7 +612,7 @@ static void read_resourcerecords(char* dn, int znix) } else if (strcasecmp(attr, "DNScipaddr")==0) { int ip[4]; if (sscanf(bvals[0]->bv_val, "%d.%d.%d.%d", &ip[0], &ip[1], &ip[2], &ip[3])==4) { - sprintf(rr.cipaddr, "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); + snprintf(rr.cipaddr, sizeof(rr.cipaddr), "%d.%d.%d.%d", ip[0], ip[1], ip[2], ip[3]); if (options.ldifname[0]) fprintf(ldifout, "%s: %s\n", attr, rr.cipaddr); } @@ -855,7 +874,7 @@ static void read_dnszones(void) printf("zonename: %s\n", zone.domainname); if (options.output&OUTPUT_DB) { char namedzonename[128]; - sprintf(namedzonename, "%s.db", zone.domainname); + snprintf(namedzonename, sizeof(namedzonename), "%s.db", zone.domainname); if ( !(namedzone = fopen(namedzonename, "w")) ) die_exit("Unable to open db-file for writing"); }