summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--plugins/check_ldap.c460
1 files changed, 223 insertions, 237 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c
index 87818da6..fc8eccec 100644
--- a/plugins/check_ldap.c
+++ b/plugins/check_ldap.c
@@ -1,30 +1,30 @@
1/***************************************************************************** 1/*****************************************************************************
2* 2 *
3* Monitoring check_ldap plugin 3 * Monitoring check_ldap plugin
4* 4 *
5* License: GPL 5 * License: GPL
6* Copyright (c) 2000-2024 Monitoring Plugins Development Team 6 * Copyright (c) 2000-2024 Monitoring Plugins Development Team
7* 7 *
8* Description: 8 * Description:
9* 9 *
10* This file contains the check_ldap plugin 10 * This file contains the check_ldap plugin
11* 11 *
12* 12 *
13* This program is free software: you can redistribute it and/or modify 13 * This program is free software: you can redistribute it and/or modify
14* it under the terms of the GNU General Public License as published by 14 * it under the terms of the GNU General Public License as published by
15* the Free Software Foundation, either version 3 of the License, or 15 * the Free Software Foundation, either version 3 of the License, or
16* (at your option) any later version. 16 * (at your option) any later version.
17* 17 *
18* This program is distributed in the hope that it will be useful, 18 * This program is distributed in the hope that it will be useful,
19* but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21* GNU General Public License for more details. 21 * GNU General Public License for more details.
22* 22 *
23* You should have received a copy of the GNU General Public License 23 * You should have received a copy of the GNU General Public License
24* along with this program. If not, see <http://www.gnu.org/licenses/>. 24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25* 25 *
26* 26 *
27*****************************************************************************/ 27 *****************************************************************************/
28 28
29/* progname may be check_ldaps */ 29/* progname may be check_ldaps */
30char *progname = "check_ldap"; 30char *progname = "check_ldap";
@@ -47,10 +47,10 @@ enum {
47 DEFAULT_PORT = 389 47 DEFAULT_PORT = 389
48}; 48};
49 49
50static int process_arguments (int, char **); 50static int process_arguments(int, char **);
51static int validate_arguments (void); 51static int validate_arguments(void);
52static void print_help (void); 52static void print_help(void);
53void print_usage (void); 53void print_usage(void);
54 54
55static char ld_defattr[] = "(objectclass=*)"; 55static char ld_defattr[] = "(objectclass=*)";
56static char *ld_attr = ld_defattr; 56static char *ld_attr = ld_defattr;
@@ -63,14 +63,14 @@ static int ld_port = -1;
63static int ld_protocol = DEFAULT_PROTOCOL; 63static int ld_protocol = DEFAULT_PROTOCOL;
64#endif 64#endif
65#ifndef LDAP_OPT_SUCCESS 65#ifndef LDAP_OPT_SUCCESS
66# define LDAP_OPT_SUCCESS LDAP_SUCCESS 66# define LDAP_OPT_SUCCESS LDAP_SUCCESS
67#endif 67#endif
68static double warn_time = UNDEFINED; 68static double warn_time = UNDEFINED;
69static double crit_time = UNDEFINED; 69static double crit_time = UNDEFINED;
70static thresholds *entries_thresholds = NULL; 70static thresholds *entries_thresholds = NULL;
71static struct timeval tv; 71static struct timeval tv;
72static char* warn_entries = NULL; 72static char *warn_entries = NULL;
73static char* crit_entries = NULL; 73static char *crit_entries = NULL;
74static bool starttls = false; 74static bool starttls = false;
75static bool ssl_on_connect = false; 75static bool ssl_on_connect = false;
76static bool verbose = false; 76static bool verbose = false;
@@ -79,9 +79,7 @@ static bool verbose = false;
79 79
80static char *SERVICE = "LDAP"; 80static char *SERVICE = "LDAP";
81 81
82int 82int main(int argc, char *argv[]) {
83main (int argc, char *argv[])
84{
85 83
86 LDAP *ld; 84 LDAP *ld;
87 LDAPMessage *result; 85 LDAPMessage *result;
@@ -95,145 +93,147 @@ main (int argc, char *argv[])
95 /* for ldap tls */ 93 /* for ldap tls */
96 94
97 int tls; 95 int tls;
98 int version=3; 96 int version = 3;
99 97
100 int status_entries = STATE_OK; 98 int status_entries = STATE_OK;
101 int num_entries = 0; 99 int num_entries = 0;
102 100
103 setlocale (LC_ALL, ""); 101 setlocale(LC_ALL, "");
104 bindtextdomain (PACKAGE, LOCALEDIR); 102 bindtextdomain(PACKAGE, LOCALEDIR);
105 textdomain (PACKAGE); 103 textdomain(PACKAGE);
106 104
107 if (strstr(argv[0],"check_ldaps")) { 105 if (strstr(argv[0], "check_ldaps")) {
108 xasprintf (&progname, "check_ldaps"); 106 xasprintf(&progname, "check_ldaps");
109 } 107 }
110 108
111 /* Parse extra opts if any */ 109 /* Parse extra opts if any */
112 argv=np_extra_opts (&argc, argv, progname); 110 argv = np_extra_opts(&argc, argv, progname);
113 111
114 if (process_arguments (argc, argv) == ERROR) 112 if (process_arguments(argc, argv) == ERROR) {
115 usage4 (_("Could not parse arguments")); 113 usage4(_("Could not parse arguments"));
114 }
116 115
117 if (strstr(argv[0],"check_ldaps") && ! starttls && ! ssl_on_connect) 116 if (strstr(argv[0], "check_ldaps") && !starttls && !ssl_on_connect) {
118 starttls = true; 117 starttls = true;
118 }
119 119
120 /* initialize alarm signal handling */ 120 /* initialize alarm signal handling */
121 signal (SIGALRM, socket_timeout_alarm_handler); 121 signal(SIGALRM, socket_timeout_alarm_handler);
122 122
123 /* set socket timeout */ 123 /* set socket timeout */
124 alarm (socket_timeout); 124 alarm(socket_timeout);
125 125
126 /* get the start time */ 126 /* get the start time */
127 gettimeofday (&tv, NULL); 127 gettimeofday(&tv, NULL);
128 128
129 /* initialize ldap */ 129 /* initialize ldap */
130#ifdef HAVE_LDAP_INIT 130#ifdef HAVE_LDAP_INIT
131 if (!(ld = ldap_init (ld_host, ld_port))) { 131 if (!(ld = ldap_init(ld_host, ld_port))) {
132 printf ("Could not connect to the server at port %i\n", ld_port); 132 printf("Could not connect to the server at port %i\n", ld_port);
133 return STATE_CRITICAL; 133 return STATE_CRITICAL;
134 } 134 }
135#else 135#else
136 if (!(ld = ldap_open (ld_host, ld_port))) { 136 if (!(ld = ldap_open(ld_host, ld_port))) {
137 if (verbose) 137 if (verbose) {
138 ldap_perror(ld, "ldap_open"); 138 ldap_perror(ld, "ldap_open");
139 printf (_("Could not connect to the server at port %i\n"), ld_port); 139 }
140 printf(_("Could not connect to the server at port %i\n"), ld_port);
140 return STATE_CRITICAL; 141 return STATE_CRITICAL;
141 } 142 }
142#endif /* HAVE_LDAP_INIT */ 143#endif /* HAVE_LDAP_INIT */
143 144
144#ifdef HAVE_LDAP_SET_OPTION 145#ifdef HAVE_LDAP_SET_OPTION
145 /* set ldap options */ 146 /* set ldap options */
146 if (ldap_set_option (ld, LDAP_OPT_PROTOCOL_VERSION, &ld_protocol) != 147 if (ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &ld_protocol) != LDAP_OPT_SUCCESS) {
147 LDAP_OPT_SUCCESS ) {
148 printf(_("Could not set protocol version %d\n"), ld_protocol); 148 printf(_("Could not set protocol version %d\n"), ld_protocol);
149 return STATE_CRITICAL; 149 return STATE_CRITICAL;
150 } 150 }
151#endif 151#endif
152 152
153 if (ld_port == LDAPS_PORT || ssl_on_connect) { 153 if (ld_port == LDAPS_PORT || ssl_on_connect) {
154 xasprintf (&SERVICE, "LDAPS"); 154 xasprintf(&SERVICE, "LDAPS");
155#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS) 155#if defined(HAVE_LDAP_SET_OPTION) && defined(LDAP_OPT_X_TLS)
156 /* ldaps: set option tls */ 156 /* ldaps: set option tls */
157 tls = LDAP_OPT_X_TLS_HARD; 157 tls = LDAP_OPT_X_TLS_HARD;
158 158
159 if (ldap_set_option (ld, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS) 159 if (ldap_set_option(ld, LDAP_OPT_X_TLS, &tls) != LDAP_SUCCESS) {
160 { 160 if (verbose) {
161 if (verbose)
162 ldap_perror(ld, "ldaps_option"); 161 ldap_perror(ld, "ldaps_option");
163 printf (_("Could not init TLS at port %i!\n"), ld_port); 162 }
163 printf(_("Could not init TLS at port %i!\n"), ld_port);
164 return STATE_CRITICAL; 164 return STATE_CRITICAL;
165 } 165 }
166#else 166#else
167 printf (_("TLS not supported by the libraries!\n")); 167 printf(_("TLS not supported by the libraries!\n"));
168 return STATE_CRITICAL; 168 return STATE_CRITICAL;
169#endif /* LDAP_OPT_X_TLS */ 169#endif /* LDAP_OPT_X_TLS */
170 } else if (starttls) { 170 } else if (starttls) {
171 xasprintf (&SERVICE, "LDAP-TLS"); 171 xasprintf(&SERVICE, "LDAP-TLS");
172#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S) 172#if defined(HAVE_LDAP_SET_OPTION) && defined(HAVE_LDAP_START_TLS_S)
173 /* ldap with startTLS: set option version */ 173 /* ldap with startTLS: set option version */
174 if (ldap_get_option(ld,LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS ) 174 if (ldap_get_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version) == LDAP_OPT_SUCCESS) {
175 { 175 if (version < LDAP_VERSION3) {
176 if (version < LDAP_VERSION3)
177 {
178 version = LDAP_VERSION3; 176 version = LDAP_VERSION3;
179 ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version); 177 ldap_set_option(ld, LDAP_OPT_PROTOCOL_VERSION, &version);
180 } 178 }
181 } 179 }
182 /* call start_tls */ 180 /* call start_tls */
183 if (ldap_start_tls_s(ld, NULL, NULL) != LDAP_SUCCESS) 181 if (ldap_start_tls_s(ld, NULL, NULL) != LDAP_SUCCESS) {
184 { 182 if (verbose) {
185 if (verbose)
186 ldap_perror(ld, "ldap_start_tls"); 183 ldap_perror(ld, "ldap_start_tls");
187 printf (_("Could not init startTLS at port %i!\n"), ld_port); 184 }
185 printf(_("Could not init startTLS at port %i!\n"), ld_port);
188 return STATE_CRITICAL; 186 return STATE_CRITICAL;
189 } 187 }
190#else 188#else
191 printf (_("startTLS not supported by the library, needs LDAPv3!\n")); 189 printf(_("startTLS not supported by the library, needs LDAPv3!\n"));
192 return STATE_CRITICAL; 190 return STATE_CRITICAL;
193#endif /* HAVE_LDAP_START_TLS_S */ 191#endif /* HAVE_LDAP_START_TLS_S */
194 } 192 }
195 193
196 /* bind to the ldap server */ 194 /* bind to the ldap server */
197 if (ldap_bind_s (ld, ld_binddn, ld_passwd, LDAP_AUTH_SIMPLE) != 195 if (ldap_bind_s(ld, ld_binddn, ld_passwd, LDAP_AUTH_SIMPLE) != LDAP_SUCCESS) {
198 LDAP_SUCCESS) { 196 if (verbose) {
199 if (verbose)
200 ldap_perror(ld, "ldap_bind"); 197 ldap_perror(ld, "ldap_bind");
201 printf (_("Could not bind to the LDAP server\n")); 198 }
199 printf(_("Could not bind to the LDAP server\n"));
202 return STATE_CRITICAL; 200 return STATE_CRITICAL;
203 } 201 }
204 202
205 /* do a search of all objectclasses in the base dn */ 203 /* do a search of all objectclasses in the base dn */
206 if (ldap_search_s (ld, ld_base, (crit_entries!=NULL || warn_entries!=NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, ld_attr, NULL, 0, &result) 204 if (ldap_search_s(ld, ld_base, (crit_entries != NULL || warn_entries != NULL) ? LDAP_SCOPE_SUBTREE : LDAP_SCOPE_BASE, ld_attr, NULL, 0,
207 != LDAP_SUCCESS) { 205 &result) != LDAP_SUCCESS) {
208 if (verbose) 206 if (verbose) {
209 ldap_perror(ld, "ldap_search"); 207 ldap_perror(ld, "ldap_search");
210 printf (_("Could not search/find objectclasses in %s\n"), ld_base); 208 }
209 printf(_("Could not search/find objectclasses in %s\n"), ld_base);
211 return STATE_CRITICAL; 210 return STATE_CRITICAL;
212 } else if (crit_entries!=NULL || warn_entries!=NULL) { 211 } else if (crit_entries != NULL || warn_entries != NULL) {
213 num_entries = ldap_count_entries(ld, result); 212 num_entries = ldap_count_entries(ld, result);
214 } 213 }
215 214
216 /* unbind from the ldap server */ 215 /* unbind from the ldap server */
217 ldap_unbind (ld); 216 ldap_unbind(ld);
218 217
219 /* reset the alarm handler */ 218 /* reset the alarm handler */
220 alarm (0); 219 alarm(0);
221 220
222 /* calculate the elapsed time and compare to thresholds */ 221 /* calculate the elapsed time and compare to thresholds */
223 222
224 microsec = deltime (tv); 223 microsec = deltime(tv);
225 elapsed_time = (double)microsec / 1.0e6; 224 elapsed_time = (double)microsec / 1.0e6;
226 225
227 if (crit_time!=UNDEFINED && elapsed_time>crit_time) 226 if (crit_time != UNDEFINED && elapsed_time > crit_time) {
228 status = STATE_CRITICAL; 227 status = STATE_CRITICAL;
229 else if (warn_time!=UNDEFINED && elapsed_time>warn_time) 228 } else if (warn_time != UNDEFINED && elapsed_time > warn_time) {
230 status = STATE_WARNING; 229 status = STATE_WARNING;
231 else 230 } else {
232 status = STATE_OK; 231 status = STATE_OK;
232 }
233 233
234 if(entries_thresholds != NULL) { 234 if (entries_thresholds != NULL) {
235 if (verbose) { 235 if (verbose) {
236 printf ("entries found: %d\n", num_entries); 236 printf("entries found: %d\n", num_entries);
237 print_thresholds("entry thresholds", entries_thresholds); 237 print_thresholds("entry thresholds", entries_thresholds);
238 } 238 }
239 status_entries = get_status(num_entries, entries_thresholds); 239 status_entries = get_status(num_entries, entries_thresholds);
@@ -245,92 +245,78 @@ main (int argc, char *argv[])
245 } 245 }
246 246
247 /* print out the result */ 247 /* print out the result */
248 if (crit_entries!=NULL || warn_entries!=NULL) { 248 if (crit_entries != NULL || warn_entries != NULL) {
249 printf (_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), 249 printf(_("LDAP %s - found %d entries in %.3f seconds|%s %s\n"), state_text(status), num_entries, elapsed_time,
250 state_text (status), 250 fperfdata("time", elapsed_time, "s", (int)warn_time, warn_time, (int)crit_time, crit_time, true, 0, false, 0),
251 num_entries, 251 sperfdata("entries", (double)num_entries, "", warn_entries, crit_entries, true, 0.0, false, 0.0));
252 elapsed_time,
253 fperfdata ("time", elapsed_time, "s",
254 (int)warn_time, warn_time,
255 (int)crit_time, crit_time,
256 true, 0, false, 0),
257 sperfdata ("entries", (double)num_entries, "",
258 warn_entries,
259 crit_entries,
260 true, 0.0, false, 0.0));
261 } else { 252 } else {
262 printf (_("LDAP %s - %.3f seconds response time|%s\n"), 253 printf(_("LDAP %s - %.3f seconds response time|%s\n"), state_text(status), elapsed_time,
263 state_text (status), 254 fperfdata("time", elapsed_time, "s", (int)warn_time, warn_time, (int)crit_time, crit_time, true, 0, false, 0));
264 elapsed_time,
265 fperfdata ("time", elapsed_time, "s",
266 (int)warn_time, warn_time,
267 (int)crit_time, crit_time,
268 true, 0, false, 0));
269 } 255 }
270 256
271 return status; 257 return status;
272} 258}
273 259
274/* process command-line arguments */ 260/* process command-line arguments */
275int 261int process_arguments(int argc, char **argv) {
276process_arguments (int argc, char **argv)
277{
278 int c; 262 int c;
279 263
280 int option = 0; 264 int option = 0;
281 /* initialize the long option struct */ 265 /* initialize the long option struct */
282 static struct option longopts[] = { 266 static struct option longopts[] = {{"help", no_argument, 0, 'h'},
283 {"help", no_argument, 0, 'h'}, 267 {"version", no_argument, 0, 'V'},
284 {"version", no_argument, 0, 'V'}, 268 {"timeout", required_argument, 0, 't'},
285 {"timeout", required_argument, 0, 't'}, 269 {"hostname", required_argument, 0, 'H'},
286 {"hostname", required_argument, 0, 'H'}, 270 {"base", required_argument, 0, 'b'},
287 {"base", required_argument, 0, 'b'}, 271 {"attr", required_argument, 0, 'a'},
288 {"attr", required_argument, 0, 'a'}, 272 {"bind", required_argument, 0, 'D'},
289 {"bind", required_argument, 0, 'D'}, 273 {"pass", required_argument, 0, 'P'},
290 {"pass", required_argument, 0, 'P'},
291#ifdef HAVE_LDAP_SET_OPTION 274#ifdef HAVE_LDAP_SET_OPTION
292 {"ver2", no_argument, 0, '2'}, 275 {"ver2", no_argument, 0, '2'},
293 {"ver3", no_argument, 0, '3'}, 276 {"ver3", no_argument, 0, '3'},
294#endif 277#endif
295 {"starttls", no_argument, 0, 'T'}, 278 {"starttls", no_argument, 0, 'T'},
296 {"ssl", no_argument, 0, 'S'}, 279 {"ssl", no_argument, 0, 'S'},
297 {"use-ipv4", no_argument, 0, '4'}, 280 {"use-ipv4", no_argument, 0, '4'},
298 {"use-ipv6", no_argument, 0, '6'}, 281 {"use-ipv6", no_argument, 0, '6'},
299 {"port", required_argument, 0, 'p'}, 282 {"port", required_argument, 0, 'p'},
300 {"warn", required_argument, 0, 'w'}, 283 {"warn", required_argument, 0, 'w'},
301 {"crit", required_argument, 0, 'c'}, 284 {"crit", required_argument, 0, 'c'},
302 {"warn-entries", required_argument, 0, 'W'}, 285 {"warn-entries", required_argument, 0, 'W'},
303 {"crit-entries", required_argument, 0, 'C'}, 286 {"crit-entries", required_argument, 0, 'C'},
304 {"verbose", no_argument, 0, 'v'}, 287 {"verbose", no_argument, 0, 'v'},
305 {0, 0, 0, 0} 288 {0, 0, 0, 0}};
306 }; 289
307 290 if (argc < 2) {
308 if (argc < 2)
309 return ERROR; 291 return ERROR;
292 }
310 293
311 for (c = 1; c < argc; c++) { 294 for (c = 1; c < argc; c++) {
312 if (strcmp ("-to", argv[c]) == 0) 295 if (strcmp("-to", argv[c]) == 0) {
313 strcpy (argv[c], "-t"); 296 strcpy(argv[c], "-t");
297 }
314 } 298 }
315 299
316 while (true) { 300 while (true) {
317 c = getopt_long (argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option); 301 c = getopt_long(argc, argv, "hvV234TS6t:c:w:H:b:p:a:D:P:C:W:", longopts, &option);
318 302
319 if (c == -1 || c == EOF) 303 if (c == -1 || c == EOF) {
320 break; 304 break;
305 }
321 306
322 switch (c) { 307 switch (c) {
323 case 'h': /* help */ 308 case 'h': /* help */
324 print_help (); 309 print_help();
325 exit (STATE_UNKNOWN); 310 exit(STATE_UNKNOWN);
326 case 'V': /* version */ 311 case 'V': /* version */
327 print_revision (progname, NP_VERSION); 312 print_revision(progname, NP_VERSION);
328 exit (STATE_UNKNOWN); 313 exit(STATE_UNKNOWN);
329 case 't': /* timeout period */ 314 case 't': /* timeout period */
330 if (!is_intnonneg (optarg)) 315 if (!is_intnonneg(optarg)) {
331 usage2 (_("Timeout interval must be a positive integer"), optarg); 316 usage2(_("Timeout interval must be a positive integer"), optarg);
332 else 317 } else {
333 socket_timeout = atoi (optarg); 318 socket_timeout = atoi(optarg);
319 }
334 break; 320 break;
335 case 'H': 321 case 'H':
336 ld_host = optarg; 322 ld_host = optarg;
@@ -339,7 +325,7 @@ process_arguments (int argc, char **argv)
339 ld_base = optarg; 325 ld_base = optarg;
340 break; 326 break;
341 case 'p': 327 case 'p':
342 ld_port = atoi (optarg); 328 ld_port = atoi(optarg);
343 break; 329 break;
344 case 'a': 330 case 'a':
345 ld_attr = optarg; 331 ld_attr = optarg;
@@ -351,10 +337,10 @@ process_arguments (int argc, char **argv)
351 ld_passwd = optarg; 337 ld_passwd = optarg;
352 break; 338 break;
353 case 'w': 339 case 'w':
354 warn_time = strtod (optarg, NULL); 340 warn_time = strtod(optarg, NULL);
355 break; 341 break;
356 case 'c': 342 case 'c':
357 crit_time = strtod (optarg, NULL); 343 crit_time = strtod(optarg, NULL);
358 break; 344 break;
359 case 'W': 345 case 'W':
360 warn_entries = optarg; 346 warn_entries = optarg;
@@ -377,141 +363,141 @@ process_arguments (int argc, char **argv)
377 verbose = true; 363 verbose = true;
378 break; 364 break;
379 case 'T': 365 case 'T':
380 if (! ssl_on_connect) 366 if (!ssl_on_connect) {
381 starttls = true; 367 starttls = true;
382 else 368 } else {
383 usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl"); 369 usage_va(_("%s cannot be combined with %s"), "-T/--starttls", "-S/--ssl");
370 }
384 break; 371 break;
385 case 'S': 372 case 'S':
386 if (! starttls) { 373 if (!starttls) {
387 ssl_on_connect = true; 374 ssl_on_connect = true;
388 if (ld_port == -1) 375 if (ld_port == -1) {
389 ld_port = LDAPS_PORT; 376 ld_port = LDAPS_PORT;
390 } else 377 }
378 } else {
391 usage_va(_("%s cannot be combined with %s"), "-S/--ssl", "-T/--starttls"); 379 usage_va(_("%s cannot be combined with %s"), "-S/--ssl", "-T/--starttls");
380 }
392 break; 381 break;
393 case '6': 382 case '6':
394#ifdef USE_IPV6 383#ifdef USE_IPV6
395 address_family = AF_INET6; 384 address_family = AF_INET6;
396#else 385#else
397 usage (_("IPv6 support not available\n")); 386 usage(_("IPv6 support not available\n"));
398#endif 387#endif
399 break; 388 break;
400 default: 389 default:
401 usage5 (); 390 usage5();
402 } 391 }
403 } 392 }
404 393
405 c = optind; 394 c = optind;
406 if (ld_host == NULL && is_host(argv[c])) 395 if (ld_host == NULL && is_host(argv[c])) {
407 ld_host = strdup (argv[c++]); 396 ld_host = strdup(argv[c++]);
397 }
408 398
409 if (ld_base == NULL && argv[c]) 399 if (ld_base == NULL && argv[c]) {
410 ld_base = strdup (argv[c++]); 400 ld_base = strdup(argv[c++]);
401 }
411 402
412 if (ld_port == -1) 403 if (ld_port == -1) {
413 ld_port = DEFAULT_PORT; 404 ld_port = DEFAULT_PORT;
405 }
414 406
415 return validate_arguments (); 407 return validate_arguments();
416} 408}
417 409
410int validate_arguments() {
411 if (ld_host == NULL || strlen(ld_host) == 0) {
412 usage4(_("Please specify the host name\n"));
413 }
418 414
419int 415 if (ld_base == NULL) {
420validate_arguments () 416 usage4(_("Please specify the LDAP base\n"));
421{ 417 }
422 if (ld_host==NULL || strlen(ld_host)==0)
423 usage4 (_("Please specify the host name\n"));
424
425 if (ld_base==NULL)
426 usage4 (_("Please specify the LDAP base\n"));
427 418
428 if (crit_entries!=NULL || warn_entries!=NULL) { 419 if (crit_entries != NULL || warn_entries != NULL) {
429 set_thresholds(&entries_thresholds, 420 set_thresholds(&entries_thresholds, warn_entries, crit_entries);
430 warn_entries, crit_entries);
431 } 421 }
432 if (ld_passwd==NULL) 422 if (ld_passwd == NULL) {
433 ld_passwd = getenv("LDAP_PASSWORD"); 423 ld_passwd = getenv("LDAP_PASSWORD");
424 }
434 425
435 return OK; 426 return OK;
436} 427}
437 428
438 429void print_help(void) {
439void
440print_help (void)
441{
442 char *myport; 430 char *myport;
443 xasprintf (&myport, "%d", DEFAULT_PORT); 431 xasprintf(&myport, "%d", DEFAULT_PORT);
444 432
445 print_revision (progname, NP_VERSION); 433 print_revision(progname, NP_VERSION);
446 434
447 printf ("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n"); 435 printf("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n");
448 printf (COPYRIGHT, copyright, email); 436 printf(COPYRIGHT, copyright, email);
449 437
450 printf ("\n\n"); 438 printf("\n\n");
451 439
452 print_usage (); 440 print_usage();
453 441
454 printf (UT_HELP_VRSN); 442 printf(UT_HELP_VRSN);
455 printf (UT_EXTRA_OPTS); 443 printf(UT_EXTRA_OPTS);
456 444
457 printf (UT_HOST_PORT, 'p', myport); 445 printf(UT_HOST_PORT, 'p', myport);
458 446
459 printf (UT_IPv46); 447 printf(UT_IPv46);
460 448
461 printf (" %s\n", "-a [--attr]"); 449 printf(" %s\n", "-a [--attr]");
462 printf (" %s\n", _("ldap attribute to search (default: \"(objectclass=*)\"")); 450 printf(" %s\n", _("ldap attribute to search (default: \"(objectclass=*)\""));
463 printf (" %s\n", "-b [--base]"); 451 printf(" %s\n", "-b [--base]");
464 printf (" %s\n", _("ldap base (eg. ou=my unit, o=my org, c=at")); 452 printf(" %s\n", _("ldap base (eg. ou=my unit, o=my org, c=at"));
465 printf (" %s\n", "-D [--bind]"); 453 printf(" %s\n", "-D [--bind]");
466 printf (" %s\n", _("ldap bind DN (if required)")); 454 printf(" %s\n", _("ldap bind DN (if required)"));
467 printf (" %s\n", "-P [--pass]"); 455 printf(" %s\n", "-P [--pass]");
468 printf (" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')")); 456 printf(" %s\n", _("ldap password (if required, or set the password through environment variable 'LDAP_PASSWORD')"));
469 printf (" %s\n", "-T [--starttls]"); 457 printf(" %s\n", "-T [--starttls]");
470 printf (" %s\n", _("use starttls mechanism introduced in protocol version 3")); 458 printf(" %s\n", _("use starttls mechanism introduced in protocol version 3"));
471 printf (" %s\n", "-S [--ssl]"); 459 printf(" %s\n", "-S [--ssl]");
472 printf (" %s %i\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to"), LDAPS_PORT); 460 printf(" %s %i\n", _("use ldaps (ldap v2 ssl method). this also sets the default port to"), LDAPS_PORT);
473 461
474#ifdef HAVE_LDAP_SET_OPTION 462#ifdef HAVE_LDAP_SET_OPTION
475 printf (" %s\n", "-2 [--ver2]"); 463 printf(" %s\n", "-2 [--ver2]");
476 printf (" %s\n", _("use ldap protocol version 2")); 464 printf(" %s\n", _("use ldap protocol version 2"));
477 printf (" %s\n", "-3 [--ver3]"); 465 printf(" %s\n", "-3 [--ver3]");
478 printf (" %s\n", _("use ldap protocol version 3")); 466 printf(" %s\n", _("use ldap protocol version 3"));
479 printf (" (%s %d)\n", _("default protocol version:"), DEFAULT_PROTOCOL); 467 printf(" (%s %d)\n", _("default protocol version:"), DEFAULT_PROTOCOL);
480#endif 468#endif
481 469
482 printf (UT_WARN_CRIT); 470 printf(UT_WARN_CRIT);
483 471
484 printf (" %s\n", "-W [--warn-entries]"); 472 printf(" %s\n", "-W [--warn-entries]");
485 printf (" %s\n", _("Number of found entries to result in warning status")); 473 printf(" %s\n", _("Number of found entries to result in warning status"));
486 printf (" %s\n", "-C [--crit-entries]"); 474 printf(" %s\n", "-C [--crit-entries]");
487 printf (" %s\n", _("Number of found entries to result in critical status")); 475 printf(" %s\n", _("Number of found entries to result in critical status"));
488 476
489 printf (UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT); 477 printf(UT_CONN_TIMEOUT, DEFAULT_SOCKET_TIMEOUT);
490 478
491 printf (UT_VERBOSE); 479 printf(UT_VERBOSE);
492 480
493 printf ("\n"); 481 printf("\n");
494 printf ("%s\n", _("Notes:")); 482 printf("%s\n", _("Notes:"));
495 printf (" %s\n", _("If this plugin is called via 'check_ldaps', method 'STARTTLS' will be")); 483 printf(" %s\n", _("If this plugin is called via 'check_ldaps', method 'STARTTLS' will be"));
496 printf (_(" implied (using default port %i) unless --port=636 is specified. In that case\n"), DEFAULT_PORT); 484 printf(_(" implied (using default port %i) unless --port=636 is specified. In that case\n"), DEFAULT_PORT);
497 printf (" %s\n", _("'SSL on connect' will be used no matter how the plugin was called.")); 485 printf(" %s\n", _("'SSL on connect' will be used no matter how the plugin was called."));
498 printf (" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags")); 486 printf(" %s\n", _("This detection is deprecated, please use 'check_ldap' with the '--starttls' or '--ssl' flags"));
499 printf (" %s\n", _("to define the behaviour explicitly instead.")); 487 printf(" %s\n", _("to define the behaviour explicitly instead."));
500 printf (" %s\n", _("The parameters --warn-entries and --crit-entries are optional.")); 488 printf(" %s\n", _("The parameters --warn-entries and --crit-entries are optional."));
501 489
502 printf (UT_SUPPORT); 490 printf(UT_SUPPORT);
503} 491}
504 492
505void 493void print_usage(void) {
506print_usage (void) 494 printf("%s\n", _("Usage:"));
507{ 495 printf(" %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]", progname);
508 printf ("%s\n", _("Usage:")); 496 printf("\n [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n",
509 printf (" %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]",progname);
510 printf ("\n [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n",
511#ifdef HAVE_LDAP_SET_OPTION 497#ifdef HAVE_LDAP_SET_OPTION
512 "\n [-2|-3] [-4|-6]" 498 "\n [-2|-3] [-4|-6]"
513#else 499#else
514 "" 500 ""
515#endif 501#endif
516 ); 502 );
517} 503}