X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=src%2Fopenldap.c;h=36a29f8dadb229a3955308035e71d3d012ca5c20;hb=ff9e11ade5cfabf32c63fb19fc76cbbc4186bc5b;hp=8667058ed049b164d7e496f37917253e55adcf14;hpb=dab48f284f9d4bb6ae98244310c5cdb6c5d91bf3;p=collectd.git diff --git a/src/openldap.c b/src/openldap.c index 8667058e..36a29f8d 100644 --- a/src/openldap.c +++ b/src/openldap.c @@ -31,6 +31,11 @@ #include "plugin.h" #include "configfile.h" +#if defined(__APPLE__) +#pragma clang diagnostic push +#pragma clang diagnostic warning "-Wdeprecated-declarations" +#endif + #include #include @@ -38,6 +43,8 @@ struct cldap_s /* {{{ */ { char *name; + char *binddn; + char *password; char *cacert; char *host; int state; @@ -56,6 +63,8 @@ static void cldap_free (cldap_t *st) /* {{{ */ if (st == NULL) return; + sfree (st->binddn); + sfree (st->password); sfree (st->cacert); sfree (st->host); sfree (st->name); @@ -110,10 +119,19 @@ static int cldap_init_host (cldap_t *st) /* {{{ */ } struct berval cred; - cred.bv_val = ""; - cred.bv_len = 0; + if (st->password != NULL) + { + cred.bv_val = st->password; + cred.bv_len = strlen (st->password); + } + else + { + cred.bv_val = ""; + cred.bv_len = 0; + } - rc = ldap_sasl_bind_s (st->ld, NULL, NULL, &cred, NULL, NULL, NULL); + rc = ldap_sasl_bind_s (st->ld, st->binddn, LDAP_SASL_SIMPLE, &cred, + NULL, NULL, NULL); if (rc != LDAP_SUCCESS) { ERROR ("openldap plugin: Failed to bind to %s: %s", @@ -535,13 +553,12 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ int i; int status; - st = malloc (sizeof (*st)); + st = calloc (1, sizeof (*st)); if (st == NULL) { - ERROR ("openldap plugin: malloc failed."); + ERROR ("openldap plugin: calloc failed."); return (-1); } - memset (st, 0, sizeof (*st)); status = cf_util_get_string (ci, &st->name); if (status != 0) @@ -559,7 +576,11 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ { oconfig_item_t *child = ci->children + i; - if (strcasecmp ("CACert", child->key) == 0) + if (strcasecmp ("BindDN", child->key) == 0) + status = cf_util_get_string (child, &st->binddn); + else if (strcasecmp ("Password", child->key) == 0) + status = cf_util_get_string (child, &st->password); + else if (strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &st->cacert); else if (strcasecmp ("StartTLS", child->key) == 0) status = cf_util_get_boolean (child, &st->starttls); @@ -630,7 +651,7 @@ static int cldap_config_add (oconfig_item_t *ci) /* {{{ */ status = plugin_register_complex_read (/* group = */ NULL, /* name = */ callback_name, /* callback = */ cldap_read_host, - /* interval = */ NULL, + /* interval = */ 0, /* user_data = */ &ud); } @@ -681,3 +702,7 @@ void module_register (void) /* {{{ */ plugin_register_complex_config ("openldap", cldap_config); plugin_register_init ("openldap", cldap_init); } /* }}} void module_register */ + +#if defined(__APPLE__) +#pragma clang diagnostic pop +#endif