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