diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-10-08 08:47:55 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2012-10-08 08:47:55 +0300 |
commit | 04f58aaf7a6f27e3b79e8f5ccffeb006db56aeaf (patch) | |
tree | 594c445f1486b6fa28cd122129a9a9b851a3d846 /lib | |
parent | 9c97ac525930863abd56a77db9b3cdcf63c4cdd6 (diff) | |
download | eclat-04f58aaf7a6f27e3b79e8f5ccffeb006db56aeaf.tar.gz eclat-04f58aaf7a6f27e3b79e8f5ccffeb006db56aeaf.tar.bz2 |
Minor fixes.
* lib/diag.c (parse_debug_level): Allow for category
specifications without level (100 is assumed).
* lib/ldapmap.c (ldap_map_config): Error checking.
(ldap_map_free): Free all allocated memory.
(parse_ldap_uri): Cleanup.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/diag.c | 13 | ||||
-rw-r--r-- | lib/ldapmap.c | 113 |
2 files changed, 79 insertions, 47 deletions
@@ -143,12 +143,13 @@ parse_debug_level(const char *arg) if (arg[len] == 0) { lev = strtoul(arg, &p, 10); - if (*p) - return -1; - for (dp = debug_category; dp < debug_category + debug_avail; - dp++) - dp->level = lev; - return 0; + if (*p == 0) { + for (dp = debug_category; + dp < debug_category + debug_avail; + dp++) + dp->level = lev; + return 0; + } } dp = find_category(arg, len); diff --git a/lib/ldapmap.c b/lib/ldapmap.c index a686718..5829f67 100644 --- a/lib/ldapmap.c +++ b/lib/ldapmap.c @@ -35,6 +35,8 @@ struct ldap_map { LDAP *ld; }; +static void ldap_map_free(int dbg, void *data); + static int cb_null(enum grecs_callback_command cmd, grecs_locus_t *locus, @@ -121,6 +123,7 @@ static int ldap_map_config(int dbg, struct grecs_node *node, void *data) { int i; + int rc = 0; struct ldap_map *ldap_map, **return_ldap_map = data; ldap_map = grecs_zalloc(sizeof(*ldap_map)); @@ -130,6 +133,24 @@ ldap_map_config(int dbg, struct grecs_node *node, void *data) if (grecs_tree_process(node->down, ldapmap_kw)) return eclat_map_failure; + if (!ldap_map->uri) { + grecs_error(&node->locus, 0, "LDAP URI not supplied"); + rc = 1; + } + if (!ldap_map->filter) { + grecs_error(&node->locus, 0, "LDAP filter not supplied"); + rc = 1; + } + if (!ldap_map->attr) { + grecs_error(&node->locus, 0, "LDAP attr not supplied"); + rc = 1; + } + + if (rc) { + ldap_map_free(dbg, ldap_map); + return eclat_map_failure; + } + *return_ldap_map = ldap_map; return eclat_map_ok; @@ -139,15 +160,63 @@ ldap_map_config(int dbg, struct grecs_node *node, void *data) static void ldap_map_free(int dbg, void *data) { + struct ldap_map *map = data; + + free(map->uri); + free(map->base); + free(map->binddn); + free(map->bindpw); + free(map->filter); + free(map->attr); + free(data); } static void ldap_unbind(LDAP *ld); +static void +dns2txtacc(struct grecs_txtacc *acc, LDAPURLDesc *lud) +{ + size_t i; + char *domain, *hostlist; + struct wordsplit ws; + int rc; + + if (ldap_dn2domain(lud->lud_dn, &domain) || !domain) { + err("DNS SRV: cannot convert DN=\"%s\" into a domain", + lud->lud_dn); + return; + } + + rc = ldap_domain2hostlist(domain, &hostlist); + ber_memfree(domain); + if (rc) { + err("DNS SRV: cannot convert domain=%s into a hostlist", + domain); + return; + } + + rc = wordsplit(hostlist, &ws, WRDSF_DEFFLAGS); + ber_memfree(hostlist); + if (rc) { + err("DNS SRV: could not parse hostlist=\"%s\": %s", + hostlist, wordsplit_strerror(&ws)); + return; + } + + for (i = 0; i < ws.ws_wordc; i++) { + grecs_txtacc_grow(acc, lud->lud_scheme, + strlen(lud->lud_scheme)); + grecs_txtacc_grow(acc, "//", 2); + grecs_txtacc_grow(acc, ws.ws_wordv[i], + strlen(ws.ws_wordv[i])); + } + wordsplit_free(&ws); +} + char * parse_ldap_uri(const char *uri) { - struct wordsplit ws; LDAPURLDesc *ludlist, **ludp; struct grecs_txtacc *acc; char *ldapuri = NULL; @@ -166,48 +235,10 @@ parse_ldap_uri(const char *uri) char **tmp; if (lud->lud_dn && lud->lud_dn[0] - && (lud->lud_host == NULL || lud->lud_host[0] == '\0')) { + && (lud->lud_host == NULL || lud->lud_host[0] == '\0')) { /* if no host but a DN is provided, try DNS SRV to gather the host list */ - char *domain = NULL, *hostlist = NULL; - size_t i; - - if (ldap_dn2domain(lud->lud_dn, &domain) || - !domain) { - err("DNS SRV: cannot convert " - "DN=\"%s\" into a domain", - lud->lud_dn); - goto dnssrv_free0; - } - - rc = ldap_domain2hostlist(domain, &hostlist); - if (rc) { - err("DNS SRV: cannot convert " - "domain=%s into a hostlist", - domain); - goto dnssrv_free0; - } - - if (wordsplit(hostlist, &ws, WRDSF_DEFFLAGS)) { - err("DNS SRV: could not parse " - "hostlist=\"%s\": %s", - hostlist, wordsplit_strerror(&ws)); - goto dnssrv_free; - } - - for (i = 0; i < ws.ws_wordc; i++) { - grecs_txtacc_grow(acc, lud->lud_scheme, - strlen(lud->lud_scheme)); - grecs_txtacc_grow(acc, "//", 2); - grecs_txtacc_grow(acc, ws.ws_wordv[i], - strlen(ws.ws_wordv[i])); - } - - dnssrv_free0: - wordsplit_free(&ws); - dnssrv_free: - ber_memfree(hostlist); - ber_memfree(domain); + dns2txtacc(acc, lud); } else { char *s = ldap_url_desc2str(lud); grecs_txtacc_grow(acc, s, strlen(s)); |