diff options
Diffstat (limited to 'plugins/check_ldap.c')
-rw-r--r-- | plugins/check_ldap.c | 152 |
1 files changed, 81 insertions, 71 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index 2064dd3b..d2c6ae22 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
@@ -36,75 +36,18 @@ enum { | |||
36 | DEFAULT_PORT = 389 | 36 | DEFAULT_PORT = 389 |
37 | }; | 37 | }; |
38 | 38 | ||
39 | void | ||
40 | print_usage () | ||
41 | { | ||
42 | printf (_("\ | ||
43 | Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\ | ||
44 | [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\ | ||
45 | (Note: all times are in seconds.)\n"), | ||
46 | progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : "")); | ||
47 | printf (_(UT_HLP_VRS), progname, progname); | ||
48 | } | ||
49 | |||
50 | void | ||
51 | print_help () | ||
52 | { | ||
53 | char *myport; | ||
54 | asprintf (&myport, "%d", DEFAULT_PORT); | ||
55 | |||
56 | print_revision (progname, revision); | ||
57 | |||
58 | printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n")); | ||
59 | printf (_(COPYRIGHT), copyright, email); | ||
60 | |||
61 | print_usage (); | ||
62 | |||
63 | printf (_(UT_HELP_VRSN)); | ||
64 | |||
65 | printf (_(UT_HOST_PORT), 'p', myport); | ||
66 | |||
67 | printf (_(UT_IPv46)); | ||
68 | |||
69 | printf (_("\ | ||
70 | -a [--attr]\n\ | ||
71 | ldap attribute to search (default: \"(objectclass=*)\"\n\ | ||
72 | -b [--base]\n\ | ||
73 | ldap base (eg. ou=my unit, o=my org, c=at)\n\ | ||
74 | -D [--bind]\n\ | ||
75 | ldap bind DN (if required)\n\ | ||
76 | -P [--pass]\n\ | ||
77 | ldap password (if required)\n")); | ||
78 | |||
79 | #ifdef HAVE_LDAP_SET_OPTION | ||
80 | printf (_("\ | ||
81 | -2 [--ver2]\n\ | ||
82 | use ldap protocol version 2\n\ | ||
83 | -3 [--ver3]\n\ | ||
84 | use ldap protocol version 3\n\ | ||
85 | (default protocol version: %d)\n"), | ||
86 | DEFAULT_PROTOCOL); | ||
87 | #endif | ||
88 | |||
89 | printf (_(UT_WARN_CRIT)); | ||
90 | |||
91 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
92 | |||
93 | printf (_(UT_VERBOSE)); | ||
94 | |||
95 | printf (_(UT_SUPPORT)); | ||
96 | } | ||
97 | |||
98 | int process_arguments (int, char **); | 39 | int process_arguments (int, char **); |
99 | int validate_arguments (void); | 40 | int validate_arguments (void); |
41 | void print_help (void); | ||
42 | void print_usage (void); | ||
100 | 43 | ||
101 | char ld_defattr[] = "(objectclass=*)"; | 44 | char ld_defattr[] = "(objectclass=*)"; |
102 | char *ld_attr = ld_defattr; | 45 | char *ld_attr = ld_defattr; |
103 | char *ld_host = ""; | 46 | char *ld_host = NULL; |
104 | char *ld_base = ""; | 47 | char *ld_base = NULL; |
105 | char *ld_passwd = NULL; | 48 | char *ld_passwd = NULL; |
106 | char *ld_binddn = NULL; | 49 | char *ld_binddn = NULL; |
107 | unsigned int ld_port = DEFAULT_PORT; | 50 | int ld_port = DEFAULT_PORT; |
108 | #ifdef HAVE_LDAP_SET_OPTION | 51 | #ifdef HAVE_LDAP_SET_OPTION |
109 | int ld_protocol = DEFAULT_PROTOCOL; | 52 | int ld_protocol = DEFAULT_PROTOCOL; |
110 | #endif | 53 | #endif |
@@ -198,7 +141,7 @@ process_arguments (int argc, char **argv) | |||
198 | { | 141 | { |
199 | int c; | 142 | int c; |
200 | 143 | ||
201 | int option_index = 0; | 144 | int option = 0; |
202 | /* initialize the long option struct */ | 145 | /* initialize the long option struct */ |
203 | static struct option longopts[] = { | 146 | static struct option longopts[] = { |
204 | {"help", no_argument, 0, 'h'}, | 147 | {"help", no_argument, 0, 'h'}, |
@@ -230,7 +173,7 @@ process_arguments (int argc, char **argv) | |||
230 | } | 173 | } |
231 | 174 | ||
232 | while (1) { | 175 | while (1) { |
233 | c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option_index); | 176 | c = getopt_long (argc, argv, "hV2346t:c:w:H:b:p:a:D:P:", longopts, &option); |
234 | 177 | ||
235 | if (c == -1 || c == EOF) | 178 | if (c == -1 || c == EOF) |
236 | break; | 179 | break; |
@@ -245,7 +188,8 @@ process_arguments (int argc, char **argv) | |||
245 | case 't': /* timeout period */ | 188 | case 't': /* timeout period */ |
246 | if (!is_intnonneg (optarg)) | 189 | if (!is_intnonneg (optarg)) |
247 | usage2 (_("timeout interval must be a positive integer"), optarg); | 190 | usage2 (_("timeout interval must be a positive integer"), optarg); |
248 | socket_timeout = atoi (optarg); | 191 | else |
192 | socket_timeout = atoi (optarg); | ||
249 | break; | 193 | break; |
250 | case 'H': | 194 | case 'H': |
251 | ld_host = optarg; | 195 | ld_host = optarg; |
@@ -296,12 +240,11 @@ process_arguments (int argc, char **argv) | |||
296 | } | 240 | } |
297 | 241 | ||
298 | c = optind; | 242 | c = optind; |
299 | if (strlen(ld_host) == 0 && is_host(argv[c])) { | 243 | if (ld_host == NULL && is_host(argv[c])) |
300 | asprintf (&ld_host, "%s", argv[c++]); | 244 | ld_host = strdup (argv[c++]); |
301 | } | 245 | |
302 | if (strlen(ld_base) == 0 && argv[c]) { | 246 | if (ld_base == NULL && argv[c]) |
303 | asprintf (&ld_base, "%s", argv[c++]); | 247 | ld_base = strdup (argv[c++]); |
304 | } | ||
305 | 248 | ||
306 | return validate_arguments (); | 249 | return validate_arguments (); |
307 | } | 250 | } |
@@ -318,3 +261,70 @@ validate_arguments () | |||
318 | return OK; | 261 | return OK; |
319 | 262 | ||
320 | } | 263 | } |
264 | |||
265 | |||
266 | |||
267 | |||
268 | |||
269 | |||
270 | void | ||
271 | print_help (void) | ||
272 | { | ||
273 | char *myport; | ||
274 | asprintf (&myport, "%d", DEFAULT_PORT); | ||
275 | |||
276 | print_revision (progname, revision); | ||
277 | |||
278 | printf (_("Copyright (c) 1999 Didi Rieder (adrieder@sbox.tu-graz.ac.at)\n")); | ||
279 | printf (_(COPYRIGHT), copyright, email); | ||
280 | |||
281 | print_usage (); | ||
282 | |||
283 | printf (_(UT_HELP_VRSN)); | ||
284 | |||
285 | printf (_(UT_HOST_PORT), 'p', myport); | ||
286 | |||
287 | printf (_(UT_IPv46)); | ||
288 | |||
289 | printf (_("\ | ||
290 | -a [--attr]\n\ | ||
291 | ldap attribute to search (default: \"(objectclass=*)\"\n\ | ||
292 | -b [--base]\n\ | ||
293 | ldap base (eg. ou=my unit, o=my org, c=at)\n\ | ||
294 | -D [--bind]\n\ | ||
295 | ldap bind DN (if required)\n\ | ||
296 | -P [--pass]\n\ | ||
297 | ldap password (if required)\n")); | ||
298 | |||
299 | #ifdef HAVE_LDAP_SET_OPTION | ||
300 | printf (_("\ | ||
301 | -2 [--ver2]\n\ | ||
302 | use ldap protocol version 2\n\ | ||
303 | -3 [--ver3]\n\ | ||
304 | use ldap protocol version 3\n\ | ||
305 | (default protocol version: %d)\n"), | ||
306 | DEFAULT_PROTOCOL); | ||
307 | #endif | ||
308 | |||
309 | printf (_(UT_WARN_CRIT)); | ||
310 | |||
311 | printf (_(UT_TIMEOUT), DEFAULT_SOCKET_TIMEOUT); | ||
312 | |||
313 | printf (_(UT_VERBOSE)); | ||
314 | |||
315 | printf (_(UT_SUPPORT)); | ||
316 | } | ||
317 | |||
318 | |||
319 | |||
320 | |||
321 | void | ||
322 | print_usage (void) | ||
323 | { | ||
324 | printf (_("\ | ||
325 | Usage: %s -H <host> -b <base_dn> [-p <port>] [-a <attr>] [-D <binddn>]\n\ | ||
326 | [-P <password>] [-w <warn_time>] [-c <crit_time>] [-t timeout]%s\n\ | ||
327 | (Note: all times are in seconds.)\n"), | ||
328 | progname, (HAVE_LDAP_SET_OPTION ? "[-2|-3] [-4|-6]" : "")); | ||
329 | printf (_(UT_HLP_VRS), progname, progname); | ||
330 | } | ||