diff options
Diffstat (limited to 'web/attachments/321739-check_dns.patch.git.txt')
-rw-r--r-- | web/attachments/321739-check_dns.patch.git.txt | 182 |
1 files changed, 182 insertions, 0 deletions
diff --git a/web/attachments/321739-check_dns.patch.git.txt b/web/attachments/321739-check_dns.patch.git.txt new file mode 100644 index 0000000..2f386cd --- /dev/null +++ b/web/attachments/321739-check_dns.patch.git.txt | |||
@@ -0,0 +1,182 @@ | |||
1 | diff --git a/plugins/check_dns.c b/plugins/check_dns.c | ||
2 | index 873dcae..4ca6b91 100644 | ||
3 | --- a/plugins/check_dns.c | ||
4 | +++ b/plugins/check_dns.c | ||
5 | @@ -45,15 +45,17 @@ int error_scan (char *); | ||
6 | void print_help (void); | ||
7 | void print_usage (void); | ||
8 | |||
9 | -#define ADDRESS_LENGTH 256 | ||
10 | +#define ADDRESS_LENGTH 384 | ||
11 | char query_address[ADDRESS_LENGTH] = ""; | ||
12 | char dns_server[ADDRESS_LENGTH] = ""; | ||
13 | char ptr_server[ADDRESS_LENGTH] = ""; | ||
14 | +char query_type[16] = ""; | ||
15 | int verbose = FALSE; | ||
16 | char **expected_address = NULL; | ||
17 | int expected_address_cnt = 0; | ||
18 | |||
19 | int expect_authority = FALSE; | ||
20 | +int accept_cname = FALSE; | ||
21 | thresholds *time_thresholds = NULL; | ||
22 | |||
23 | static int | ||
24 | @@ -65,6 +67,22 @@ qstrcmp(const void *p1, const void *p2) | ||
25 | return strcmp(* (char * const *) p1, * (char * const *) p2); | ||
26 | } | ||
27 | |||
28 | +char * | ||
29 | +check_new_address(char *temp_buffer) | ||
30 | +{ | ||
31 | + temp_buffer++; | ||
32 | + /* Strip leading spaces */ | ||
33 | + for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) | ||
34 | + /* NOOP */; | ||
35 | + | ||
36 | + strip(temp_buffer); | ||
37 | + if (temp_buffer==NULL || strlen(temp_buffer)==0) { | ||
38 | + die (STATE_CRITICAL, | ||
39 | + _("DNS CRITICAL - '%s' returned empty host name string\n"), | ||
40 | + NSLOOKUP_COMMAND); | ||
41 | + } | ||
42 | + return temp_buffer; | ||
43 | +} | ||
44 | |||
45 | int | ||
46 | main (int argc, char **argv) | ||
47 | @@ -103,7 +121,7 @@ main (int argc, char **argv) | ||
48 | } | ||
49 | |||
50 | /* get the command to run */ | ||
51 | - asprintf (&command_line, "%s %s %s", NSLOOKUP_COMMAND, query_address, dns_server); | ||
52 | + asprintf (&command_line, "%s %s %s %s", NSLOOKUP_COMMAND, query_type, query_address, dns_server); | ||
53 | |||
54 | alarm (timeout_interval); | ||
55 | gettimeofday (&tv, NULL); | ||
56 | @@ -136,28 +154,26 @@ main (int argc, char **argv) | ||
57 | } | ||
58 | } | ||
59 | |||
60 | + if (strstr (chld_out.line[i], "Authoritative answers can be found from:")) | ||
61 | + break; | ||
62 | /* the server is responding, we just got the host name... */ | ||
63 | if (strstr (chld_out.line[i], "Name:")) | ||
64 | parse_address = TRUE; | ||
65 | + else if (strstr (chld_out.line[i], "AAAA address")) { | ||
66 | + temp_buffer = rindex (chld_out.line[i], ' '); | ||
67 | + addresses[n_addresses++] = check_new_address(temp_buffer); | ||
68 | + } | ||
69 | + else if (strstr (chld_out.line[i], "text =") || strstr (chld_out.line[i], "exchanger =") \ | ||
70 | + || strstr (chld_out.line[i], "service =") || (accept_cname && strstr (chld_out.line[i], "name ="))) { | ||
71 | + temp_buffer = index (chld_out.line[i], '='); | ||
72 | + addresses[n_addresses++] = check_new_address(temp_buffer); | ||
73 | + } | ||
74 | else if (parse_address == TRUE && (strstr (chld_out.line[i], "Address:") || | ||
75 | strstr (chld_out.line[i], "Addresses:"))) { | ||
76 | temp_buffer = index (chld_out.line[i], ':'); | ||
77 | - temp_buffer++; | ||
78 | - | ||
79 | - /* Strip leading spaces */ | ||
80 | - for (; *temp_buffer != '\0' && *temp_buffer == ' '; temp_buffer++) | ||
81 | - /* NOOP */; | ||
82 | - | ||
83 | - strip(temp_buffer); | ||
84 | - if (temp_buffer==NULL || strlen(temp_buffer)==0) { | ||
85 | - die (STATE_CRITICAL, | ||
86 | - _("DNS CRITICAL - '%s' returned empty host name string\n"), | ||
87 | - NSLOOKUP_COMMAND); | ||
88 | - } | ||
89 | - | ||
90 | - addresses[n_addresses++] = strdup(temp_buffer); | ||
91 | - } | ||
92 | - else if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { | ||
93 | + addresses[n_addresses++] = check_new_address(temp_buffer); | ||
94 | + } | ||
95 | + if (strstr (chld_out.line[i], _("Non-authoritative answer:"))) { | ||
96 | non_authoritative = TRUE; | ||
97 | } | ||
98 | |||
99 | @@ -274,7 +290,7 @@ error_scan (char *input_buffer) | ||
100 | die (STATE_CRITICAL, _("No response from DNS %s\n"), dns_server); | ||
101 | |||
102 | /* Host name is valid, but server doesn't have records... */ | ||
103 | - else if (strstr (input_buffer, "No records")) | ||
104 | + else if (strstr (input_buffer, "No records") || strstr (input_buffer, "No answer")) | ||
105 | die (STATE_CRITICAL, _("DNS %s has no records\n"), dns_server); | ||
106 | |||
107 | /* Connection was refused */ | ||
108 | @@ -316,7 +332,6 @@ error_scan (char *input_buffer) | ||
109 | |||
110 | } | ||
111 | |||
112 | - | ||
113 | /* process command-line arguments */ | ||
114 | int | ||
115 | process_arguments (int argc, char **argv) | ||
116 | @@ -334,8 +349,10 @@ process_arguments (int argc, char **argv) | ||
117 | {"hostname", required_argument, 0, 'H'}, | ||
118 | {"server", required_argument, 0, 's'}, | ||
119 | {"reverse-server", required_argument, 0, 'r'}, | ||
120 | + {"querytype", required_argument, 0, 'q'}, | ||
121 | {"expected-address", required_argument, 0, 'a'}, | ||
122 | {"expect-authority", no_argument, 0, 'A'}, | ||
123 | + {"accept-cname", no_argument, 0, 'n'}, | ||
124 | {"warning", required_argument, 0, 'w'}, | ||
125 | {"critical", required_argument, 0, 'c'}, | ||
126 | {0, 0, 0, 0} | ||
127 | @@ -349,7 +366,7 @@ process_arguments (int argc, char **argv) | ||
128 | strcpy (argv[c], "-t"); | ||
129 | |||
130 | while (1) { | ||
131 | - c = getopt_long (argc, argv, "hVvAt:H:s:r:a:w:c:", long_opts, &opt_index); | ||
132 | + c = getopt_long (argc, argv, "hVvAnt:H:s:r:a:q:w:c:", long_opts, &opt_index); | ||
133 | |||
134 | if (c == -1 || c == EOF) | ||
135 | break; | ||
136 | @@ -394,9 +411,18 @@ process_arguments (int argc, char **argv) | ||
137 | expected_address[expected_address_cnt] = strdup(optarg); | ||
138 | expected_address_cnt++; | ||
139 | break; | ||
140 | + case 'q': /* querytype -- A or AAAA or ANY or SRV or TXT, etc. */ | ||
141 | + if (strlen (optarg) < 1 || strlen (optarg) > 4) | ||
142 | + die (STATE_UNKNOWN, _("Missing valid querytype parameter. Try using 'A' or 'AAAA' or 'SRV'\n")); | ||
143 | + strcpy(query_type, "-querytype="); | ||
144 | + strcat(query_type, optarg); | ||
145 | + break; | ||
146 | case 'A': /* expect authority */ | ||
147 | expect_authority = TRUE; | ||
148 | break; | ||
149 | + case 'n': /* accept cname responses as a result */ | ||
150 | + accept_cname = TRUE; | ||
151 | + break; | ||
152 | case 'w': | ||
153 | warning = optarg; | ||
154 | break; | ||
155 | @@ -462,13 +488,20 @@ print_help (void) | ||
156 | printf (" %s\n", _("The name or address you want to query")); | ||
157 | printf (" -s, --server=HOST\n"); | ||
158 | printf (" %s\n", _("Optional DNS server you want to use for the lookup")); | ||
159 | + printf (" -q, --querytype=TYPE\n"); | ||
160 | + printf (" %s\n", _("Optional DNS record query type where TYPE =(A, AAAA, SRV, TXT, MX, ANY)")); | ||
161 | + printf (" %s\n", _("The default query type is 'A' (IPv4 host entry)")); | ||
162 | printf (" -a, --expected-address=IP-ADDRESS|HOST\n"); | ||
163 | printf (" %s\n", _("Optional IP-ADDRESS you expect the DNS server to return. HOST must end with")); | ||
164 | printf (" %s\n", _("a dot (.). This option can be repeated multiple times (Returns OK if any")); | ||
165 | printf (" %s\n", _("value match). If multiple addresses are returned at once, you have to match")); | ||
166 | printf (" %s\n", _("the whole string of addresses separated with commas (sorted alphabetically).")); | ||
167 | + printf (" %s\n", _("If you would like to test for the presence of a cname, combine with -n param.")); | ||
168 | printf (" -A, --expect-authority\n"); | ||
169 | printf (" %s\n", _("Optionally expect the DNS server to be authoritative for the lookup")); | ||
170 | + printf (" -n, --accept-cname\n"); | ||
171 | + printf (" %s\n", _("Optionally accept cname responses as a valid result to a query")); | ||
172 | + printf (" %s\n", _("The default is to ignore cname responses as part of the result")); | ||
173 | printf (" -w, --warning=seconds\n"); | ||
174 | printf (" %s\n", _("Return warning if elapsed time exceeds value. Default off")); | ||
175 | printf (" -c, --critical=seconds\n"); | ||
176 | @@ -490,5 +523,5 @@ void | ||
177 | print_usage (void) | ||
178 | { | ||
179 | printf (_("Usage:")); | ||
180 | - printf ("%s -H host [-s server] [-a expected-address] [-A] [-t timeout] [-w warn] [-c crit]\n", progname); | ||
181 | + printf ("%s -H host [-s server] [-q type ] [-a expected-address] [-A] [-n] [-t timeout] [-w warn] [-c crit]\n", progname); | ||
182 | } | ||