X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fopenldap.c;h=7b9b711c2d80b1d7228aa982f2bf15c25c0c7c08;hb=be126043c2be20399d7670fe194645292018bde0;hp=5269e5f2a2d715cf8ee44527f2434e43be58691a;hpb=e4504c3cc5582ab915903e1b4ba010545ffc8354;p=collectd.git diff --git a/src/openldap.c b/src/openldap.c index 5269e5f2..7b9b711c 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -85,14 +85,15 @@ static int cldap_init_host(cldap_t *st) /* {{{ */ if (st->state && st->ld) { DEBUG("openldap plugin: Already connected to %s", st->url); - return (0); + return 0; } rc = ldap_initialize(&ld, st->url); if (rc != LDAP_SUCCESS) { ERROR("openldap plugin: ldap_initialize failed: %s", ldap_err2string(rc)); st->state = 0; - ldap_unbind_ext_s(ld, NULL, NULL); + if (ld != NULL) + ldap_unbind_ext_s(ld, NULL, NULL); return (-1); } @@ -119,7 +120,8 @@ static int cldap_init_host(cldap_t *st) /* {{{ */ ERROR("openldap plugin: Failed to start tls on %s: %s", st->url, ldap_err2string(rc)); st->state = 0; - ldap_unbind_ext_s(st->ld, NULL, NULL); + if (st->ld != NULL) + ldap_unbind_ext_s(st->ld, NULL, NULL); return (-1); } } @@ -139,12 +141,13 @@ static int cldap_init_host(cldap_t *st) /* {{{ */ ERROR("openldap plugin: Failed to bind to %s: %s", st->url, ldap_err2string(rc)); st->state = 0; - ldap_unbind_ext_s(st->ld, NULL, NULL); + if (st->ld != NULL) + ldap_unbind_ext_s(st->ld, NULL, NULL); return (-1); } else { DEBUG("openldap plugin: Successfully connected to %s", st->url); st->state = 1; - return (0); + return 0; } } /* }}} static cldap_init_host */ @@ -197,14 +200,14 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((ud == NULL) || (ud->data == NULL)) { ERROR("openldap plugin: cldap_read_host: Invalid user data."); - return (-1); + return -1; } st = (cldap_t *)ud->data; status = cldap_init_host(st); if (status != 0) - return (-1); + return -1; rc = ldap_search_ext_s(st->ld, "cn=Monitor", LDAP_SCOPE_SUBTREE, "(|(!(cn=* *))(cn=Database*))", attrs, 0, NULL, NULL, @@ -214,7 +217,8 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ ERROR("openldap plugin: Failed to execute search: %s", ldap_err2string(rc)); ldap_msgfree(result); st->state = 0; - ldap_unbind_ext_s(st->ld, NULL, NULL); + if (st->ld != NULL) + ldap_unbind_ext_s(st->ld, NULL, NULL); return (-1); } @@ -310,7 +314,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBEntryCache")) != NULL) { olmbdb_data = *olmbdb_list[0]; - ssnprintf(typeinst, sizeof(typeinst), "bdbentrycache-%s", + snprintf(typeinst, sizeof(typeinst), "bdbentrycache-%s", nc_data.bv_val); cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val), st); @@ -320,7 +324,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBDNCache")) != NULL) { olmbdb_data = *olmbdb_list[0]; - ssnprintf(typeinst, sizeof(typeinst), "bdbdncache-%s", + snprintf(typeinst, sizeof(typeinst), "bdbdncache-%s", nc_data.bv_val); cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val), st); @@ -330,7 +334,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ if ((olmbdb_list = ldap_get_values_len(st->ld, e, "olmBDBIDLCache")) != NULL) { olmbdb_data = *olmbdb_list[0]; - ssnprintf(typeinst, sizeof(typeinst), "bdbidlcache-%s", + snprintf(typeinst, sizeof(typeinst), "bdbidlcache-%s", nc_data.bv_val); cldap_submit_gauge("cache_size", typeinst, atoll(olmbdb_data.bv_val), st); @@ -372,7 +376,7 @@ static int cldap_read_host(user_data_t *ud) /* {{{ */ } ldap_msgfree(result); - return (0); + return 0; } /* }}} int cldap_read_host */ /* Configuration handling functions {{{ @@ -393,13 +397,13 @@ static int cldap_config_add(oconfig_item_t *ci) /* {{{ */ st = calloc(1, sizeof(*st)); if (st == NULL) { ERROR("openldap plugin: calloc failed."); - return (-1); + return -1; } status = cf_util_get_string(ci, &st->name); if (status != 0) { sfree(st); - return (status); + return status; } st->starttls = 0; @@ -476,7 +480,7 @@ static int cldap_config_add(oconfig_item_t *ci) /* {{{ */ databases[databases_num] = st; databases_num++; - ssnprintf(callback_name, sizeof(callback_name), "openldap/%s/%s", + snprintf(callback_name, sizeof(callback_name), "openldap/%s/%s", (st->host != NULL) ? st->host : hostname_g, (st->name != NULL) ? st->name : "default"); @@ -491,10 +495,10 @@ static int cldap_config_add(oconfig_item_t *ci) /* {{{ */ if (status != 0) { cldap_free(st); - return (-1); + return -1; } - return (0); + return 0; } /* }}} int cldap_config_add */ static int cldap_config(oconfig_item_t *ci) /* {{{ */ @@ -514,7 +518,7 @@ static int cldap_config(oconfig_item_t *ci) /* {{{ */ child->key); } /* for (ci->children) */ - return (status); + return status; } /* }}} int cldap_config */ /* }}} End of configuration handling functions */ @@ -525,7 +529,7 @@ static int cldap_init(void) /* {{{ */ * ldap_initialize(3) */ int debug_level; ldap_get_option(NULL, LDAP_OPT_DEBUG_LEVEL, &debug_level); - return (0); + return 0; } /* }}} int cldap_init */ static int cldap_shutdown(void) /* {{{ */ @@ -536,7 +540,7 @@ static int cldap_shutdown(void) /* {{{ */ sfree(databases); databases_num = 0; - return (0); + return 0; } /* }}} int cldap_shutdown */ void module_register(void) /* {{{ */