diff options
author | Martin Nagy <mnagy@redhat.com> | 2009-02-17 19:11:43 +0100 |
---|---|---|
committer | Martin Nagy <mnagy@redhat.com> | 2009-02-18 18:20:59 +0100 |
commit | 9e114a57057d433622a0e3ff2ff854657defdab5 (patch) | |
tree | 39d897f5ac4f3fcbb83ed27b6a485b28e4266661 | |
parent | 5547d52f8f4893e361f1a09f7afd4f285e1f0f02 (diff) | |
download | ldap_driver_testing-9e114a57057d433622a0e3ff2ff854657defdab5.tar.gz ldap_driver_testing-9e114a57057d433622a0e3ff2ff854657defdab5.tar.xz ldap_driver_testing-9e114a57057d433622a0e3ff2ff854657defdab5.zip |
Add conversion function, from LDAP to DNS.
The ldap_record_to_rdatatype() function will convert an LDAP attribute
name to dns_rdatatype_t.
-rw-r--r-- | ldap_convert.c | 51 | ||||
-rw-r--r-- | ldap_convert.h | 5 |
2 files changed, 55 insertions, 1 deletions
diff --git a/ldap_convert.c b/ldap_convert.c index 568d68e..63f1e25 100644 --- a/ldap_convert.c +++ b/ldap_convert.c @@ -23,16 +23,41 @@ #include <isc/util.h> #include <dns/name.h> +#include <dns/rdatatype.h> +#include <dns/types.h> -#include <errno.h> #define LDAP_DEPRECATED 1 #include <ldap.h> +#include <errno.h> +#include <strings.h> + #include "str.h" #include "ldap_convert.h" #include "log.h" #include "util.h" +/* + * Consistency must be preserved in these tables. + * ldap_dns_records[i] must always corespond to dns_records[i] + */ +const char *ldap_dns_records[] = { + "ARecord", "AAAARecord", "A6Record", "NSRecord", + "CNAMERecord", "PTRRecord", "SRVRecord", "TXTRecord", "MXRecord", + "MDRecord", "HINFORecord", "MINFORecord", "AFSDBRecord", "SIGRecord", + "KEYRecord", "LOCRecord", "NXTRecord", "NAPTRRecord", "KXRecord", + "CERTRecord", "DNAMERecord", "DSRecord", "SSHFPRecord", + "RRSIGRecord", "NSECRecord", NULL +}; + +const char *dns_records[] = { + "a", "aaaa", "a6", "ns", + "cname", "ptr", "srv", "txt", "mx", + "md", "hinfo", "minfo", "afsdb", "sig", + "key", "loc", "NXT", "NAPTR", "KX", + "CERT", "DNAME", "DS", "SSHFP", + "RRSIG", "NSEC", NULL +}; static isc_result_t dn_to_text(const char *dn, const char *root_dn, ld_string_t *target); @@ -228,3 +253,27 @@ cleanup: return result; } + +isc_result_t +ldap_record_to_rdatatype(const char *ldap_record, dns_rdatatype_t *rdtype) +{ + isc_result_t result; + unsigned i; + isc_consttextregion_t region; + + for (i = 0; ldap_dns_records[i] != NULL; i++) { + if (!strcasecmp(ldap_record, ldap_dns_records[i])) + break; + } + if (dns_records[i] == NULL) + return ISC_R_NOTFOUND; + + region.base = dns_records[i]; + region.length = strlen(region.base); + result = dns_rdatatype_fromtext(rdtype, (isc_textregion_t *)®ion); + if (result != ISC_R_SUCCESS) { + log_error("dns_rdatatype_fromtext() failed"); + } + + return result; +} diff --git a/ldap_convert.h b/ldap_convert.h index af66d1e..9f62497 100644 --- a/ldap_convert.h +++ b/ldap_convert.h @@ -20,6 +20,8 @@ #ifndef _LD_LDAP_CONVERT_H_ #define _LD_LDAP_CONVERT_H_ +#include <dns/types.h> + #include "str.h" /* @@ -33,4 +35,7 @@ isc_result_t dn_to_dnsname(isc_mem_t *mctx, const char *dn, const char *root_dn, isc_result_t dnsname_to_dn(isc_mem_t *mctx, dns_name_t *name, const char *root_dn, ld_string_t *target); +isc_result_t ldap_record_to_rdatatype(const char *ldap_record, + dns_rdatatype_t *rdtype); + #endif /* !_LD_LDAP_CONVERT_H_ */ |