diff options
author | Martin Nagy <mnagy@redhat.com> | 2009-02-13 10:48:29 +0100 |
---|---|---|
committer | Martin Nagy <mnagy@redhat.com> | 2009-02-18 18:20:42 +0100 |
commit | ffa6b87e86b10b69791f3ac19e47eadefe94da46 (patch) | |
tree | cc05b3292d6349ebbbef4522edad87b3e57c8ace | |
parent | 719309ac5dd0bd875bb1854f291785c1efc16400 (diff) | |
download | ldap_driver-ffa6b87e86b10b69791f3ac19e47eadefe94da46.tar.gz ldap_driver-ffa6b87e86b10b69791f3ac19e47eadefe94da46.tar.xz ldap_driver-ffa6b87e86b10b69791f3ac19e47eadefe94da46.zip |
Add dnsname_to_dn().
This function will take dns_name_t as a parameter and in turn return a
suitable DN.
-rw-r--r-- | ldap_convert.c | 50 | ||||
-rw-r--r-- | ldap_convert.h | 5 |
2 files changed, 55 insertions, 0 deletions
diff --git a/ldap_convert.c b/ldap_convert.c index 41d0474..06e8176 100644 --- a/ldap_convert.c +++ b/ldap_convert.c @@ -178,3 +178,53 @@ count_rdns(char **exploded) return ret; } + +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 result; + isc_buffer_t target_buffer; + char target_base[DNS_NAME_MAXTEXT + 1]; + ld_string_t *str; + ld_split_t *split; + unsigned int split_count; + + REQUIRE(mctx != NULL); + REQUIRE(name != NULL); + REQUIRE(target != NULL); + + str = NULL; + split = NULL; + CHECK(str_new(mctx, &str)); + CHECK(str_new_split(mctx, &split)); + isc_buffer_init(&target_buffer, target_base, sizeof(target_base)); + CHECK(dns_name_totext(name, isc_boolean_true, &target_buffer)); + + target_base[isc_buffer_usedlength(&target_buffer)] = '\0'; + CHECK(str_init_char(str, target_base)); + CHECK(str_split(str, '.', split)); + split_count = str_split_count(split); + + for (unsigned int i = 0; i < split_count - 1; i++) { + CHECK(str_cat_char(target, "idnsName=")); + CHECK(str_cat_char(target, str_split_get(split, i))); + if (split_count - i > 2) + CHECK(str_cat_char(target, ", ")); + } + + CHECK(str_cat_char(target, ".")); + CHECK(str_cat_char(target, str_split_get(split, split_count - 1))); + + if (root_dn != NULL) { + CHECK(str_cat_char(target, ", ")); + CHECK(str_cat_char(target, root_dn)); + } + + log_error("%s", str_buf(target)); +cleanup: + str_destroy_split(&split); + str_destroy(&str); + + return result; +} diff --git a/ldap_convert.h b/ldap_convert.h index 1fb77e4..af66d1e 100644 --- a/ldap_convert.h +++ b/ldap_convert.h @@ -20,6 +20,8 @@ #ifndef _LD_LDAP_CONVERT_H_ #define _LD_LDAP_CONVERT_H_ +#include "str.h" + /* * Convert LDAP DN 'dn', to dns_name_t 'target'. 'target' needs to be * initialized with dns_name_init() before the call and freed by the caller @@ -28,4 +30,7 @@ isc_result_t dn_to_dnsname(isc_mem_t *mctx, const char *dn, const char *root_dn, dns_name_t *target); +isc_result_t dnsname_to_dn(isc_mem_t *mctx, dns_name_t *name, + const char *root_dn, ld_string_t *target); + #endif /* !_LD_LDAP_CONVERT_H_ */ |