Commit f50b1e06 authored by Ondřej Surý's avatar Ondřej Surý
Browse files

Use clang-format to reformat the source files

parent 4c3b063e
......@@ -9,23 +9,21 @@
* information regarding copyright ownership.
*/
/*! \file */
#include <inttypes.h>
#include <stdbool.h>
#include <stdio.h>
#include <inttypes.h>
#ifdef _WIN32
#include <Winsock2.h>
#endif
#include "check-tool.h"
#include <isc/buffer.h>
#include <isc/log.h>
#include <isc/mem.h>
#include <isc/netdb.h>
#include <isc/net.h>
#include <isc/netdb.h>
#include <isc/print.h>
#include <isc/region.h>
#include <isc/stdio.h>
......@@ -52,6 +50,8 @@
#include <ns/log.h>
#include "check-tool.h"
#ifndef CHECK_SIBLING
#define CHECK_SIBLING 1
#endif
......@@ -60,11 +60,11 @@
#define CHECK_LOCAL 1
#endif
#define CHECK(r) \
do { \
result = (r); \
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
goto cleanup; \
} while (0)
#define ERR_IS_CNAME 1
......@@ -78,9 +78,9 @@
static const char *dbtype[] = { "rbt" };
int debug = 0;
int debug = 0;
const char *journal = NULL;
bool nomerge = true;
bool nomerge = true;
#if CHECK_LOCAL
bool docheckmx = true;
bool dochecksrv = true;
......@@ -90,40 +90,37 @@ bool docheckmx = false;
bool dochecksrv = false;
bool docheckns = false;
#endif
dns_zoneopt_t zone_options = DNS_ZONEOPT_CHECKNS |
DNS_ZONEOPT_CHECKMX |
DNS_ZONEOPT_MANYERRORS |
DNS_ZONEOPT_CHECKNAMES |
dns_zoneopt_t zone_options = DNS_ZONEOPT_CHECKNS | DNS_ZONEOPT_CHECKMX |
DNS_ZONEOPT_MANYERRORS | DNS_ZONEOPT_CHECKNAMES |
DNS_ZONEOPT_CHECKINTEGRITY |
#if CHECK_SIBLING
DNS_ZONEOPT_CHECKSIBLING |
#endif
DNS_ZONEOPT_CHECKWILDCARD |
DNS_ZONEOPT_WARNMXCNAME |
DNS_ZONEOPT_WARNSRVCNAME;
DNS_ZONEOPT_WARNMXCNAME | DNS_ZONEOPT_WARNSRVCNAME;
/*
* This needs to match the list in bin/named/log.c.
*/
static isc_logcategory_t categories[] = {
{ "", 0 },
{ "unmatched", 0 },
{ NULL, 0 }
};
static isc_logcategory_t categories[] = { { "", 0 },
{ "unmatched", 0 },
{ NULL, 0 } };
static isc_symtab_t *symtab = NULL;
static isc_mem_t *sym_mctx;
static isc_mem_t * sym_mctx;
static void
freekey(char *key, unsigned int type, isc_symvalue_t value, void *userarg) {
freekey(char *key, unsigned int type, isc_symvalue_t value, void *userarg)
{
UNUSED(type);
UNUSED(value);
isc_mem_free(userarg, key);
}
static void
add(char *key, int value) {
isc_result_t result;
add(char *key, int value)
{
isc_result_t result;
isc_symvalue_t symvalue;
if (sym_mctx == NULL) {
......@@ -147,7 +144,8 @@ add(char *key, int value) {
}
static bool
logged(char *key, int value) {
logged(char *key, int value)
{
isc_result_t result;
if (symtab == NULL)
......@@ -164,16 +162,16 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
dns_rdataset_t *a, dns_rdataset_t *aaaa)
{
dns_rdataset_t *rdataset;
dns_rdata_t rdata = DNS_RDATA_INIT;
dns_rdata_t rdata = DNS_RDATA_INIT;
struct addrinfo hints, *ai, *cur;
char namebuf[DNS_NAME_FORMATSIZE + 1];
char ownerbuf[DNS_NAME_FORMATSIZE];
char namebuf[DNS_NAME_FORMATSIZE + 1];
char ownerbuf[DNS_NAME_FORMATSIZE];
char addrbuf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:123.123.123.123")];
bool answer = true;
bool match;
const char *type;
void *ptr = NULL;
int result;
void * ptr = NULL;
int result;
REQUIRE(a == NULL || !dns_rdataset_isassociated(a) ||
a->type == dns_rdatatype_a);
......@@ -216,8 +214,7 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/NS '%s' (out of zone) "
"is a CNAME '%s' (illegal)",
ownerbuf, namebuf,
cur->ai_canonname);
ownerbuf, namebuf, cur->ai_canonname);
/* XXX950 make fatal for 9.5.0 */
/* answer = false; */
add(namebuf, ERR_IS_CNAME);
......@@ -240,8 +237,8 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
default:
if (!logged(namebuf, ERR_LOOKUP_FAILURE)) {
dns_zone_log(zone, ISC_LOG_WARNING,
"getaddrinfo(%s) failed: %s",
namebuf, gai_strerror(result));
"getaddrinfo(%s) failed: %s", namebuf,
gai_strerror(result));
add(namebuf, ERR_LOOKUP_FAILURE);
}
return (true);
......@@ -266,11 +263,12 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
}
}
if (!match && !logged(namebuf, ERR_EXTRA_A)) {
dns_zone_log(zone, ISC_LOG_ERROR, "%s/NS '%s' "
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/NS '%s' "
"extra GLUE A record (%s)",
ownerbuf, namebuf,
inet_ntop(AF_INET, rdata.data,
addrbuf, sizeof(addrbuf)));
inet_ntop(AF_INET, rdata.data, addrbuf,
sizeof(addrbuf)));
add(namebuf, ERR_EXTRA_A);
/* XXX950 make fatal for 9.5.0 */
/* answer = false; */
......@@ -279,7 +277,7 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
result = dns_rdataset_next(a);
}
checkaaaa:
checkaaaa:
if (!dns_rdataset_isassociated(aaaa))
goto checkmissing;
result = dns_rdataset_first(aaaa);
......@@ -289,18 +287,20 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
for (cur = ai; cur != NULL; cur = cur->ai_next) {
if (cur->ai_family != AF_INET6)
continue;
ptr = &((struct sockaddr_in6 *)(cur->ai_addr))->sin6_addr;
ptr = &((struct sockaddr_in6 *)(cur->ai_addr))
->sin6_addr;
if (memcmp(ptr, rdata.data, rdata.length) == 0) {
match = true;
break;
}
}
if (!match && !logged(namebuf, ERR_EXTRA_AAAA)) {
dns_zone_log(zone, ISC_LOG_ERROR, "%s/NS '%s' "
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/NS '%s' "
"extra GLUE AAAA record (%s)",
ownerbuf, namebuf,
inet_ntop(AF_INET6, rdata.data,
addrbuf, sizeof(addrbuf)));
inet_ntop(AF_INET6, rdata.data, addrbuf,
sizeof(addrbuf)));
add(namebuf, ERR_EXTRA_AAAA);
/* XXX950 make fatal for 9.5.0. */
/* answer = false; */
......@@ -309,7 +309,7 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
result = dns_rdataset_next(aaaa);
}
checkmissing:
checkmissing:
/*
* Check that all addresses appear in the glue.
*/
......@@ -319,16 +319,18 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
switch (cur->ai_family) {
case AF_INET:
rdataset = a;
ptr = &((struct sockaddr_in *)(cur->ai_addr))->sin_addr;
ptr = &((struct sockaddr_in *)(cur->ai_addr))
->sin_addr;
type = "A";
break;
case AF_INET6:
rdataset = aaaa;
ptr = &((struct sockaddr_in6 *)(cur->ai_addr))->sin6_addr;
ptr = &((struct sockaddr_in6 *)(cur->ai_addr))
->sin6_addr;
type = "AAAA";
break;
default:
continue;
continue;
}
match = false;
if (dns_rdataset_isassociated(rdataset))
......@@ -343,11 +345,13 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
result = dns_rdataset_next(rdataset);
}
if (!match) {
dns_zone_log(zone, ISC_LOG_ERROR, "%s/NS '%s' "
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/NS '%s' "
"missing GLUE %s record (%s)",
ownerbuf, namebuf, type,
inet_ntop(cur->ai_family, ptr,
addrbuf, sizeof(addrbuf)));
addrbuf,
sizeof(addrbuf)));
/* XXX950 make fatal for 9.5.0. */
/* answer = false; */
missing_glue = true;
......@@ -361,13 +365,14 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
}
static bool
checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
{
struct addrinfo hints, *ai, *cur;
char namebuf[DNS_NAME_FORMATSIZE + 1];
char ownerbuf[DNS_NAME_FORMATSIZE];
int result;
int level = ISC_LOG_ERROR;
bool answer = true;
char namebuf[DNS_NAME_FORMATSIZE + 1];
char ownerbuf[DNS_NAME_FORMATSIZE];
int result;
int level = ISC_LOG_ERROR;
bool answer = true;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
......@@ -434,8 +439,8 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
default:
if (!logged(namebuf, ERR_LOOKUP_FAILURE)) {
dns_zone_log(zone, ISC_LOG_WARNING,
"getaddrinfo(%s) failed: %s",
namebuf, gai_strerror(result));
"getaddrinfo(%s) failed: %s", namebuf,
gai_strerror(result));
add(namebuf, ERR_LOOKUP_FAILURE);
}
return (true);
......@@ -443,13 +448,14 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
}
static bool
checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
{
struct addrinfo hints, *ai, *cur;
char namebuf[DNS_NAME_FORMATSIZE + 1];
char ownerbuf[DNS_NAME_FORMATSIZE];
int result;
int level = ISC_LOG_ERROR;
bool answer = true;
char namebuf[DNS_NAME_FORMATSIZE + 1];
char ownerbuf[DNS_NAME_FORMATSIZE];
int result;
int level = ISC_LOG_ERROR;
bool answer = true;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
......@@ -484,7 +490,8 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
level = ISC_LOG_WARNING;
if ((zone_options & DNS_ZONEOPT_IGNORESRVCNAME) == 0) {
if (!logged(namebuf, ERR_IS_SRVCNAME)) {
dns_zone_log(zone, level, "%s/SRV '%s'"
dns_zone_log(zone, level,
"%s/SRV '%s'"
" (out of zone) is a "
"CNAME '%s' (illegal)",
ownerbuf, namebuf,
......@@ -515,8 +522,8 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
default:
if (!logged(namebuf, ERR_LOOKUP_FAILURE)) {
dns_zone_log(zone, ISC_LOG_WARNING,
"getaddrinfo(%s) failed: %s",
namebuf, gai_strerror(result));
"getaddrinfo(%s) failed: %s", namebuf,
gai_strerror(result));
add(namebuf, ERR_LOOKUP_FAILURE);
}
return (true);
......@@ -524,10 +531,11 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner) {
}
isc_result_t
setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp)
{
isc_logdestination_t destination;
isc_logconfig_t *logconfig = NULL;
isc_log_t *log = NULL;
isc_logconfig_t * logconfig = NULL;
isc_log_t * log = NULL;
RUNTIME_CHECK(isc_log_create(mctx, &log, &logconfig) == ISC_R_SUCCESS);
isc_log_registercategories(log, categories);
......@@ -542,11 +550,10 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
destination.file.versions = ISC_LOG_ROLLNEVER;
destination.file.maximum_size = 0;
RUNTIME_CHECK(isc_log_createchannel(logconfig, "stderr",
ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC,
&destination, 0) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr",
NULL, NULL) == ISC_R_SUCCESS);
ISC_LOG_TOFILEDESC, ISC_LOG_DYNAMIC,
&destination, 0) == ISC_R_SUCCESS);
RUNTIME_CHECK(isc_log_usechannel(logconfig, "stderr", NULL, NULL) ==
ISC_R_SUCCESS);
*logp = log;
return (ISC_R_SUCCESS);
......@@ -554,16 +561,17 @@ setup_logging(isc_mem_t *mctx, FILE *errout, isc_log_t **logp) {
/*% scan the zone for oversize TTLs */
static isc_result_t
check_ttls(dns_zone_t *zone, dns_ttl_t maxttl) {
isc_result_t result;
dns_db_t *db = NULL;
dns_dbversion_t *version = NULL;
dns_dbnode_t *node = NULL;
dns_dbiterator_t *dbiter = NULL;
check_ttls(dns_zone_t *zone, dns_ttl_t maxttl)
{
isc_result_t result;
dns_db_t * db = NULL;
dns_dbversion_t * version = NULL;
dns_dbnode_t * node = NULL;
dns_dbiterator_t * dbiter = NULL;
dns_rdatasetiter_t *rdsiter = NULL;
dns_rdataset_t rdataset;
dns_fixedname_t fname;
dns_name_t *name;
dns_rdataset_t rdataset;
dns_fixedname_t fname;
dns_name_t * name;
name = dns_fixedname_initname(&fname);
dns_rdataset_init(&rdataset);
......@@ -573,8 +581,7 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl) {
CHECK(dns_db_newversion(db, &version));
CHECK(dns_db_createiterator(db, 0, &dbiter));
for (result = dns_dbiterator_first(dbiter);
result == ISC_R_SUCCESS;
for (result = dns_dbiterator_first(dbiter); result == ISC_R_SUCCESS;
result = dns_dbiterator_next(dbiter)) {
result = dns_dbiterator_current(dbiter, &node, name);
if (result == DNS_R_NEWORIGIN)
......@@ -587,8 +594,8 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl) {
result = dns_rdatasetiter_next(rdsiter)) {
dns_rdatasetiter_current(rdsiter, &rdataset);
if (rdataset.ttl > maxttl) {
char nbuf[DNS_NAME_FORMATSIZE];
char tbuf[255];
char nbuf[DNS_NAME_FORMATSIZE];
char tbuf[255];
isc_buffer_t b;
isc_region_t r;
......@@ -618,7 +625,7 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl) {
if (result == ISC_R_NOMORE)
result = ISC_R_SUCCESS;
cleanup:
cleanup:
if (node != NULL)
dns_db_detachnode(db, &node);
if (rdsiter != NULL)
......@@ -639,13 +646,13 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
dns_masterformat_t fileformat, const char *classname,
dns_ttl_t maxttl, dns_zone_t **zonep)
{
isc_result_t result;
isc_result_t result;
dns_rdataclass_t rdclass;
isc_textregion_t region;
isc_buffer_t buffer;
dns_fixedname_t fixorigin;
dns_name_t *origin;
dns_zone_t *zone = NULL;
isc_buffer_t buffer;
dns_fixedname_t fixorigin;
dns_name_t * origin;
dns_zone_t * zone = NULL;
REQUIRE(zonep == NULL || *zonep == NULL);
......@@ -662,7 +669,7 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
origin = dns_fixedname_initname(&fixorigin);
CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL));
CHECK(dns_zone_setorigin(zone, origin));
dns_zone_setdbtype(zone, 1, (const char * const *) dbtype);
dns_zone_setdbtype(zone, 1, (const char *const *)dbtype);
CHECK(dns_zone_setfile(zone, filename, fileformat,
&dns_master_style_default));
if (journal != NULL)
......@@ -700,7 +707,7 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
zone = NULL;
}
cleanup:
cleanup:
if (zone != NULL)
dns_zone_detach(&zone);
return (result);
......@@ -713,15 +720,15 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
const uint32_t rawversion)
{
isc_result_t result;
FILE *output = stdout;
const char *flags;
FILE * output = stdout;
const char * flags;
flags = (fileformat == dns_masterformat_text) ? "w" : "wb";
if (debug) {
if (filename != NULL && strcmp(filename, "-") != 0)
fprintf(stderr, "dumping \"%s\" to \"%s\"\n",
zonename, filename);
fprintf(stderr, "dumping \"%s\" to \"%s\"\n", zonename,
filename);
else
fprintf(stderr, "dumping \"%s\"\n", zonename);
}
......@@ -730,8 +737,10 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
result = isc_stdio_open(filename, flags, &output);
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "could not open output "
"file \"%s\" for writing\n", filename);
fprintf(stderr,
"could not open output "
"file \"%s\" for writing\n",
filename);
return (ISC_R_FAILURE);
}
}
......@@ -746,14 +755,15 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
#ifdef _WIN32
void
InitSockets(void) {
WORD wVersionRequested;
InitSockets(void)
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
int err;
wVersionRequested = MAKEWORD(2, 0);
err = WSAStartup( wVersionRequested, &wsaData );
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0) {
fprintf(stderr, "WSAStartup() failed: %d\n", err);
exit(1);
......@@ -761,7 +771,8 @@ InitSockets(void) {
}
void
DestroySockets(void) {
DestroySockets(void)
{
WSACleanup();
}
#endif
......@@ -9,7 +9,6 @@
* information regarding copyright ownership.
*/
#ifndef CHECK_TOOL_H
#define CHECK_TOOL_H
......@@ -42,16 +41,18 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
const uint32_t rawversion);
#ifdef _WIN32
void InitSockets(void);
void DestroySockets(void);
void
InitSockets(void);
void
DestroySockets(void);
#endif
extern int debug;
extern const char *journal;
extern bool nomerge;
extern bool docheckmx;
extern bool docheckns;
extern bool dochecksrv;
extern int debug;
extern const char * journal;
extern bool nomerge;
extern bool docheckmx;
extern bool docheckns;
extern bool dochecksrv;
extern dns_zoneopt_t zone_options;
ISC_LANG_ENDDECLS
......
......@@ -9,13 +9,12 @@
* information regarding copyright ownership.
*/
/*! \file */
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdlib.h>
#include <isc/commandline.h>
#include <isc/dir.h>
......@@ -27,11 +26,6 @@
#include <isc/string.h>
#include <isc/util.h>
#include <isccfg/namedconf.h>
#include <isccfg/grammar.h>
#include <bind9/check.h>
#include <dns/db.h>
#include <dns/fixedname.h>
#include <dns/log.h>
......@@ -41,19 +35,24 @@
#include <dns/rootns.h>
#include <dns/zone.h>
#include <isccfg/grammar.h>
#include <isccfg/namedconf.h>
#include "check-tool.h"
#include <bind9/check.h>
static const char *program = "named-checkconf";
static bool loadplugins = true;
isc_log_t *logc = NULL;
#define CHECK(r)\
do { \
result = (r); \
#define CHECK(r) \
do { \
result = (r); \
if (result != ISC_R_SUCCESS) \
goto cleanup; \
goto cleanup; \
} while (0)
/*% usage */
......@@ -61,17 +60,21 @@ ISC_PLATFORM_NORETURN_PRE static void
usage(void) ISC_PLATFORM_NORETURN_POST;
static void
usage(void) {
fprintf(stderr, "usage: %s [-chijlvz] [-p [-x]] [-t directory] "
"[named.conf]\n", program);
usage(void)
{
fprintf(stderr,
"usage: %s [-chijlvz] [-p [-x]] [-t directory] "
"[named.conf]\n",
program);
exit(1);
}
/*% directory callback */
static isc_result_t
directory_callback(const char *clausename, const cfg_obj_t *obj, void *arg) {
directory_callback(const char *clausename, const cfg_obj_t *obj, void *arg)
{
isc_result_t result;
const char *directory;
const char * directory;
REQUIRE(strcasecmp("directory", clausename) == 0);
......@@ -85,8 +88,8 @@ directory_callback(const char *clausename, const cfg_obj_t *obj, void *arg) {
result = isc_dir_chdir(directory);
if (result != ISC_R_SUCCESS) {