diff options
Diffstat (limited to 'plugins/check_ldap.c')
| -rw-r--r-- | plugins/check_ldap.c | 59 |
1 files changed, 13 insertions, 46 deletions
diff --git a/plugins/check_ldap.c b/plugins/check_ldap.c index d3f06158..213dc4a8 100644 --- a/plugins/check_ldap.c +++ b/plugins/check_ldap.c | |||
| @@ -34,7 +34,6 @@ | |||
| 34 | #define UNKNOWN -1 | 34 | #define UNKNOWN -1 |
| 35 | 35 | ||
| 36 | int process_arguments (int, char **); | 36 | int process_arguments (int, char **); |
| 37 | int call_getopt (int, char **); | ||
| 38 | int validate_arguments (void); | 37 | int validate_arguments (void); |
| 39 | static void print_help (void); | 38 | static void print_help (void); |
| 40 | static void print_usage (void); | 39 | static void print_usage (void); |
| @@ -124,35 +123,10 @@ process_arguments (int argc, char **argv) | |||
| 124 | { | 123 | { |
| 125 | int c; | 124 | int c; |
| 126 | 125 | ||
| 127 | if (argc < 2) | ||
| 128 | return ERROR; | ||
| 129 | |||
| 130 | for (c = 1; c < argc; c++) { | ||
| 131 | if (strcmp ("-to", argv[c]) == 0) | ||
| 132 | strcpy (argv[c], "-t"); | ||
| 133 | } | ||
| 134 | |||
| 135 | c = 0; | ||
| 136 | while (c += (call_getopt (argc - c, &argv[c]))) { | ||
| 137 | if (argc <= c) | ||
| 138 | break; | ||
| 139 | if (ld_host[0] == 0) { | ||
| 140 | strncpy (ld_host, argv[c], sizeof (ld_host) - 1); | ||
| 141 | ld_host[sizeof (ld_host) - 1] = 0; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | return c; | ||
| 146 | } | ||
| 147 | |||
| 148 | int | ||
| 149 | call_getopt (int argc, char **argv) | ||
| 150 | { | ||
| 151 | int c, i = 1; | ||
| 152 | #ifdef HAVE_GETOPT_H | 126 | #ifdef HAVE_GETOPT_H |
| 153 | int option_index = 0; | 127 | int option_index = 0; |
| 154 | /* initialize the long option struct */ | 128 | /* initialize the long option struct */ |
| 155 | static struct option long_options[] = { | 129 | static struct option longopts[] = { |
| 156 | {"help", no_argument, 0, 'h'}, | 130 | {"help", no_argument, 0, 'h'}, |
| 157 | {"version", no_argument, 0, 'V'}, | 131 | {"version", no_argument, 0, 'V'}, |
| 158 | {"timeout", required_argument, 0, 't'}, | 132 | {"timeout", required_argument, 0, 't'}, |
| @@ -168,15 +142,17 @@ call_getopt (int argc, char **argv) | |||
| 168 | }; | 142 | }; |
| 169 | #endif | 143 | #endif |
| 170 | 144 | ||
| 171 | for (c = 1; c < argc; c++) | 145 | if (argc < 2) |
| 146 | return ERROR; | ||
| 147 | |||
| 148 | for (c = 1; c < argc; c++) { | ||
| 172 | if (strcmp ("-to", argv[c]) == 0) | 149 | if (strcmp ("-to", argv[c]) == 0) |
| 173 | strcpy (argv[c], "-t"); | 150 | strcpy (argv[c], "-t"); |
| 151 | } | ||
| 174 | 152 | ||
| 175 | while (1) { | 153 | while (1) { |
| 176 | #ifdef HAVE_GETOPT_H | 154 | #ifdef HAVE_GETOPT_H |
| 177 | c = | 155 | c = getopt_long (argc, argv, "hVt:c:w:H:b:p:a:D:P:", longopts, &option_index); |
| 178 | getopt_long (argc, argv, "+hVt:c:w:H:b:p:a:D:P:", long_options, | ||
| 179 | &option_index); | ||
| 180 | #else | 156 | #else |
| 181 | c = getopt (argc, argv, "+?hVt:c:w:H:b:p:a:D:P:"); | 157 | c = getopt (argc, argv, "+?hVt:c:w:H:b:p:a:D:P:"); |
| 182 | #endif | 158 | #endif |
| @@ -184,20 +160,6 @@ call_getopt (int argc, char **argv) | |||
| 184 | if (c == -1 || c == EOF) | 160 | if (c == -1 || c == EOF) |
| 185 | break; | 161 | break; |
| 186 | 162 | ||
| 187 | i++; | ||
| 188 | switch (c) { | ||
| 189 | case 't': | ||
| 190 | case 'c': | ||
| 191 | case 'w': | ||
| 192 | case 'H': | ||
| 193 | case 'b': | ||
| 194 | case 'p': | ||
| 195 | case 'a': | ||
| 196 | case 'D': | ||
| 197 | case 'P': | ||
| 198 | i++; | ||
| 199 | } | ||
| 200 | |||
| 201 | switch (c) { | 163 | switch (c) { |
| 202 | case 'h': /* help */ | 164 | case 'h': /* help */ |
| 203 | print_help (); | 165 | print_help (); |
| @@ -239,7 +201,12 @@ call_getopt (int argc, char **argv) | |||
| 239 | break; | 201 | break; |
| 240 | } | 202 | } |
| 241 | } | 203 | } |
| 242 | return i; | 204 | |
| 205 | if (ld_host[0] == 0) { | ||
| 206 | asprintf (&ld_host, "%s", argv[c]); | ||
| 207 | } | ||
| 208 | |||
| 209 | return validate_arguments (); | ||
| 243 | } | 210 | } |
| 244 | 211 | ||
| 245 | int | 212 | int |
