diff options
Diffstat (limited to 'plugins/check_ldap.c')
| -rw-r--r-- | plugins/check_ldap.c | 50 |
1 files changed, 32 insertions, 18 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 597644bd..77a33304 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
| @@ -108,7 +108,8 @@ int main(int argc, char *argv[]) { | |||
| 108 | 108 | ||
| 109 | #ifdef HAVE_LDAP_SET_OPTION | 109 | #ifdef HAVE_LDAP_SET_OPTION |
| 110 | /* set ldap options */ | 110 | /* set ldap options */ |
| 111 | if (ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &config.ld_protocol) != LDAP_OPT_SUCCESS) { | 111 | if (ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &config.ld_protocol) != |
| 112 | LDAP_OPT_SUCCESS) { | ||
| 112 | printf(_("Could not set protocol version %d\n"), config.ld_protocol); | 113 | printf(_("Could not set protocol version %d\n"), config.ld_protocol); |
| 113 | return STATE_CRITICAL; | 114 | return STATE_CRITICAL; |
| 114 | } | 115 | } |
| @@ -135,7 +136,8 @@ int main(int argc, char *argv[]) { | |||
| 135 | } else if (config.starttls) { | 136 | } else if (config.starttls) { |
| 136 | #if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S) | 137 | #if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S) |
| 137 | /* ldap with startTLS: set option version */ | 138 | /* ldap with startTLS: set option version */ |
| 138 | if (ldap_get_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) { | 139 | if (ldap_get_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version) == |
| 140 | LDAP_OPT_SUCCESS) { | ||
| 139 | if (version < LDAP_VERSION3) { | 141 | if (version < LDAP_VERSION3) { |
| 140 | version = LDAP_VERSION3; | 142 | version = LDAP_VERSION3; |
| 141 | ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version); | 143 | ldap_set_option(ldap_connection, LDAP_OPT_PROTOCOL_VERSION, &version); |
| @@ -156,7 +158,8 @@ int main(int argc, char *argv[]) { | |||
| 156 | } | 158 | } |
| 157 | 159 | ||
| 158 | /* bind to the ldap server */ | 160 | /* bind to the ldap server */ |
| 159 | if (ldap_bind_s(ldap_connection, config.ld_binddn, config.ld_passwd, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) { | 161 | if (ldap_bind_s(ldap_connection, config.ld_binddn, config.ld_passwd, LDAP_AUTH_SIMPLE) != |
| 162 | LDAP_SUCCESS) { | ||
| 160 | if (verbose) { | 163 | if (verbose) { |
| 161 | ldap_perror(ldap_connection, "ldap_bind"); | 164 | ldap_perror(ldap_connection, "ldap_bind"); |
| 162 | } | 165 | } |
| @@ -168,8 +171,10 @@ int main(int argc, char *argv[]) { | |||
| 168 | int num_entries = 0; | 171 | int num_entries = 0; |
| 169 | /* do a search of all objectclasses in the base dn */ | 172 | /* do a search of all objectclasses in the base dn */ |
| 170 | if (ldap_search_s(ldap_connection, config.ld_base, | 173 | if (ldap_search_s(ldap_connection, config.ld_base, |
| 171 | (config.crit_entries != NULL || config.warn_entries != NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, config.ld_attr, | 174 | (config.crit_entries != NULL || config.warn_entries != NULL) |
| 172 | NULL, 0, &result) != LDAP_SUCCESS) { | 175 | ? LDAP_SCOPE_SUBTREE |
| 176 | : LDAP_SCOPE_BASE, | ||
| 177 | config.ld_attr, NULL, 0, &result) != LDAP_SUCCESS) { | ||
| 173 | if (verbose) { | 178 | if (verbose) { |
| 174 | ldap_perror(ldap_connection, "ldap_search"); | 179 | ldap_perror(ldap_connection, "ldap_search"); |
| 175 | } | 180 | } |
| @@ -215,14 +220,16 @@ int main(int argc, char *argv[]) { | |||
| 215 | 220 | ||
| 216 | /* print out the result */ | 221 | /* print out the result */ |
| 217 | if (config.crit_entries != NULL || config.warn_entries != NULL) { | 222 | if (config.crit_entries != NULL || config.warn_entries != NULL) { |
| 218 | printf(_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), state_text(status), num_entries, elapsed_time, | 223 | printf(_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), state_text(status), |
| 219 | fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, config.crit_time_set, config.crit_time, true, 0, | 224 | num_entries, elapsed_time, |
| 220 | false, 0), | 225 | fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, |
| 221 | sperfdata("entries", (double)num_entries, "", config.warn_entries, config.crit_entries, true, 0.0, false, 0.0)); | 226 | config.crit_time_set, config.crit_time, true, 0, false, 0), |
| 227 | sperfdata("entries", (double)num_entries, "", config.warn_entries, | ||
| 228 | config.crit_entries, true, 0.0, false, 0.0)); | ||
| 222 | } else { | 229 | } else { |
| 223 | printf(_("LDAP %s - %.3f seconds response time|%s\n"), state_text(status), elapsed_time, | 230 | printf(_("LDAP %s - %.3f seconds response time|%s\n"), state_text(status), elapsed_time, |
| 224 | fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, config.crit_time_set, config.crit_time, true, 0, | 231 | fperfdata("time", elapsed_time, "s", config.warn_time_set, config.warn_time, |
| 225 | false, 0)); | 232 | config.crit_time_set, config.crit_time, true, 0, false, 0)); |
| 226 | } | 233 | } |
| 227 | 234 | ||
| 228 | exit(status); | 235 | exit(status); |
| @@ -273,7 +280,8 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) { | |||
| 273 | 280 | ||
| 274 | int option = 0; | 281 | int option = 0; |
| 275 | while (true) { | 282 | while (true) { |
| 276 | int option_index = getopt_long(argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); | 283 | int option_index = |
| 284 | getopt_long(argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); | ||
| 277 | 285 | ||
| 278 | if (option_index == -1 || option_index == EOF) { | 286 | if (option_index == -1 || option_index == EOF) { |
| 279 | break; | 287 | break; |
| @@ -381,7 +389,8 @@ check_ldap_config_wrapper process_arguments(int argc, char **argv) { | |||
| 381 | result.config.ld_port = DEFAULT_PORT; | 389 | result.config.ld_port = DEFAULT_PORT; |
| 382 | } | 390 | } |
| 383 | 391 | ||
| 384 | if (strstr(argv[0], "check_ldaps") && !result.config.starttls && !result.config.ssl_on_connect) { | 392 | if (strstr(argv[0], "check_ldaps") && !result.config.starttls && |
| 393 | !result.config.ssl_on_connect) { | ||
| 385 | result.config.starttls = true; | 394 | result.config.starttls = true; |
| 386 | } | 395 | } |
| 387 | 396 | ||
| @@ -398,7 +407,8 @@ check_ldap_config_wrapper validate_arguments(check_ldap_config_wrapper config_wr | |||
| 398 | } | 407 | } |
| 399 | 408 | ||
| 400 | if (config_wrapper.config.crit_entries != NULL || config_wrapper.config.warn_entries != NULL) { | 409 | if (config_wrapper.config.crit_entries != NULL || config_wrapper.config.warn_entries != NULL) { |
| 401 | set_thresholds(&config_wrapper.config.entries_thresholds, config_wrapper.config.warn_entries, config_wrapper.config.crit_entries); | 410 | set_thresholds(&config_wrapper.config.entries_thresholds, |
| 411 | config_wrapper.config.warn_entries, config_wrapper.config.crit_entries); | ||
| 402 | } | 412 | } |
| 403 | 413 | ||
| 404 | if (config_wrapper.config.ld_passwd == NULL) { | 414 | if (config_wrapper.config.ld_passwd == NULL) { |
| @@ -435,11 +445,13 @@ void print_help(void) { | |||
| 435 | printf(" %s\n", "-D [--bind]"); | 445 | printf(" %s\n", "-D [--bind]"); |
| 436 | printf(" %s\n", _("ldap bind DN (if required)")); | 446 | printf(" %s\n", _("ldap bind DN (if required)")); |
| 437 | printf(" %s\n", "-P [--pass]"); | 447 | printf(" %s\n", "-P [--pass]"); |
| 438 | printf(" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')")); | 448 | printf(" %s\n", _("ldap password (if required, or set the password through environment " |
| 449 | "variable 'LDAP_PASSWORD')")); | ||
| 439 | printf(" %s\n", "-T [--starttls]"); | 450 | printf(" %s\n", "-T [--starttls]"); |
| 440 | printf(" %s\n", _("use starttls mechanism introduced in protocol version 3")); | 451 | printf(" %s\n", _("use starttls mechanism introduced in protocol version 3")); |
| 441 | printf(" %s\n", "-S [--ssl]"); | 452 | printf(" %s\n", "-S [--ssl]"); |
| 442 | printf(" %s %i\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to"), LDAPS_PORT); | 453 | printf(" %s %i\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to"), |
| 454 | LDAPS_PORT); | ||
| 443 | 455 | ||
| 444 | #ifdef HAVE_LDAP_SET_OPTION | 456 | #ifdef HAVE_LDAP_SET_OPTION |
| 445 | printf(" %s\n", "-2 [--ver2]"); | 457 | printf(" %s\n", "-2 [--ver2]"); |
| @@ -463,9 +475,11 @@ void print_help(void) { | |||
| 463 | printf("\n"); | 475 | printf("\n"); |
| 464 | printf("%s\n", _("Notes:")); | 476 | printf("%s\n", _("Notes:")); |
| 465 | printf(" %s\n", _("If this plugin is called via 'check_ldaps', method 'STARTTLS' will be")); | 477 | printf(" %s\n", _("If this plugin is called via 'check_ldaps', method 'STARTTLS' will be")); |
| 466 | printf(_(" implied (using default port %i) unless --port=636 is specified. In that case\n"), DEFAULT_PORT); | 478 | printf(_(" implied (using default port %i) unless --port=636 is specified. In that case\n"), |
| 479 | DEFAULT_PORT); | ||
| 467 | printf(" %s\n", _("'SSL on connect' will be used no matter how the plugin was called.")); | 480 | printf(" %s\n", _("'SSL on connect' will be used no matter how the plugin was called.")); |
| 468 | printf(" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags")); | 481 | printf(" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' " |
| 482 | "or '--ssl' flags")); | ||
| 469 | printf(" %s\n", _("to define the behaviour explicitly instead.")); | 483 | printf(" %s\n", _("to define the behaviour explicitly instead.")); |
| 470 | printf(" %s\n", _("The parameters --warn-entries and --crit-entries are optional.")); | 484 | printf(" %s\n", _("The parameters --warn-entries and --crit-entries are optional.")); |
| 471 | 485 | ||
