diff options
| author | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-09 12:11:02 +0100 |
|---|---|---|
| committer | Lorenz Kästle <12514511+RincewindsHat@users.noreply.github.com> | 2025-03-09 12:11:02 +0100 |
| commit | c0d9580dac9779c40434c9b63a0ef4ef82b2e8ba (patch) | |
| tree | 927921aa5477355a97c77c75f9b661c3060b2113 | |
| parent | 65794e31374b3aa6e1f2c03d090b52e137df13e6 (diff) | |
| download | monitoring-plugins-c0d9580dac9779c40434c9b63a0ef4ef82b2e8ba.tar.gz | |
check_dns: some comments, small improvements
| -rw-r--r-- | plugins/check_dns.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/plugins/check_dns.c b/plugins/check_dns.c index 7071c01f..e98c709f 100644 --- a/plugins/check_dns.c +++ b/plugins/check_dns.c | |||
| @@ -106,14 +106,16 @@ int main(int argc, char **argv) { | |||
| 106 | result = STATE_WARNING; | 106 | result = STATE_WARNING; |
| 107 | } | 107 | } |
| 108 | 108 | ||
| 109 | char *address = NULL; /* comma separated str with addrs/ptrs (sorted) */ | 109 | /* ===== |
| 110 | char **addresses = NULL; | 110 | * scan stdout, main results get retrieved here |
| 111 | size_t n_addresses = 0; | 111 | * ===== |
| 112 | */ | ||
| 113 | char *address = NULL; /* comma separated str with addrs/ptrs (sorted) */ | ||
| 114 | char **addresses = NULL; // All addresses parsed from stdout | ||
| 115 | size_t n_addresses = 0; // counter for retrieved addresses | ||
| 112 | bool non_authoritative = false; | 116 | bool non_authoritative = false; |
| 113 | bool is_nxdomain = false; | 117 | bool is_nxdomain = false; |
| 114 | char *temp_buffer = NULL; | ||
| 115 | bool parse_address = false; /* This flag scans for Address: but only after Name: */ | 118 | bool parse_address = false; /* This flag scans for Address: but only after Name: */ |
| 116 | /* scan stdout */ | ||
| 117 | for (size_t i = 0; i < chld_out.lines; i++) { | 119 | for (size_t i = 0; i < chld_out.lines; i++) { |
| 118 | if (addresses == NULL) { | 120 | if (addresses == NULL) { |
| 119 | addresses = malloc(sizeof(*addresses) * 10); | 121 | addresses = malloc(sizeof(*addresses) * 10); |
| @@ -126,6 +128,7 @@ int main(int argc, char **argv) { | |||
| 126 | } | 128 | } |
| 127 | 129 | ||
| 128 | if (strcasestr(chld_out.line[i], ".in-addr.arpa") || strcasestr(chld_out.line[i], ".ip6.arpa")) { | 130 | if (strcasestr(chld_out.line[i], ".in-addr.arpa") || strcasestr(chld_out.line[i], ".ip6.arpa")) { |
| 131 | char *temp_buffer = NULL; | ||
| 129 | if ((temp_buffer = strstr(chld_out.line[i], "name = "))) { | 132 | if ((temp_buffer = strstr(chld_out.line[i], "name = "))) { |
| 130 | addresses[n_addresses++] = strdup(temp_buffer + 7); | 133 | addresses[n_addresses++] = strdup(temp_buffer + 7); |
| 131 | } else { | 134 | } else { |
| @@ -137,6 +140,7 @@ int main(int argc, char **argv) { | |||
| 137 | /* bug ID: 2946553 - Older versions of bind will use all available dns | 140 | /* bug ID: 2946553 - Older versions of bind will use all available dns |
| 138 | servers, we have to match the one specified */ | 141 | servers, we have to match the one specified */ |
| 139 | if (strstr(chld_out.line[i], "Server:") && strlen(config.dns_server) > 0) { | 142 | if (strstr(chld_out.line[i], "Server:") && strlen(config.dns_server) > 0) { |
| 143 | char *temp_buffer = NULL; | ||
| 140 | temp_buffer = strchr(chld_out.line[i], ':'); | 144 | temp_buffer = strchr(chld_out.line[i], ':'); |
| 141 | temp_buffer++; | 145 | temp_buffer++; |
| 142 | 146 | ||
| @@ -159,6 +163,7 @@ int main(int argc, char **argv) { | |||
| 159 | if (strstr(chld_out.line[i], "Name:")) { | 163 | if (strstr(chld_out.line[i], "Name:")) { |
| 160 | parse_address = true; | 164 | parse_address = true; |
| 161 | } else if (parse_address && (strstr(chld_out.line[i], "Address:") || strstr(chld_out.line[i], "Addresses:"))) { | 165 | } else if (parse_address && (strstr(chld_out.line[i], "Address:") || strstr(chld_out.line[i], "Addresses:"))) { |
| 166 | char *temp_buffer = NULL; | ||
| 162 | temp_buffer = index(chld_out.line[i], ':'); | 167 | temp_buffer = index(chld_out.line[i], ':'); |
| 163 | temp_buffer++; | 168 | temp_buffer++; |
| 164 | 169 | ||
| @@ -216,6 +221,8 @@ int main(int argc, char **argv) { | |||
| 216 | for (size_t i = 0; i < n_addresses; i++) { | 221 | for (size_t i = 0; i < n_addresses; i++) { |
| 217 | slen += strlen(addresses[i]) + 1; | 222 | slen += strlen(addresses[i]) + 1; |
| 218 | } | 223 | } |
| 224 | |||
| 225 | // Temporary pointer adrp gets moved, address stays on the beginning | ||
| 219 | adrp = address = malloc(slen); | 226 | adrp = address = malloc(slen); |
| 220 | for (size_t i = 0; i < n_addresses; i++) { | 227 | for (size_t i = 0; i < n_addresses; i++) { |
| 221 | if (i) { | 228 | if (i) { |
| @@ -232,7 +239,7 @@ int main(int argc, char **argv) { | |||
| 232 | /* compare to expected address */ | 239 | /* compare to expected address */ |
| 233 | if (result == STATE_OK && config.expected_address_cnt > 0) { | 240 | if (result == STATE_OK && config.expected_address_cnt > 0) { |
| 234 | result = STATE_CRITICAL; | 241 | result = STATE_CRITICAL; |
| 235 | temp_buffer = ""; | 242 | char *temp_buffer = ""; |
| 236 | unsigned long expect_match = (1 << config.expected_address_cnt) - 1; | 243 | unsigned long expect_match = (1 << config.expected_address_cnt) - 1; |
| 237 | unsigned long addr_match = (1 << n_addresses) - 1; | 244 | unsigned long addr_match = (1 << n_addresses) - 1; |
| 238 | 245 | ||
