Use clang-tidy to add curly braces around one-line statements

The command used to reformat the files in this commit was:

./util/run-clang-tidy \
	-clang-tidy-binary clang-tidy-11
	-clang-apply-replacements-binary clang-apply-replacements-11 \
	-checks=-*,readability-braces-around-statements \
	-j 9 \
	-fix \
	-format \
	-style=file \
	-quiet
clang-format -i --style=format $(git ls-files '*.c' '*.h')
uncrustify -c .uncrustify.cfg --replace --no-backup $(git ls-files '*.c' '*.h')
clang-format -i --style=format $(git ls-files '*.c' '*.h')
This commit is contained in:
Ondřej Surý 2020-02-13 21:48:23 +01:00
parent d14bb71319
commit 056e133c4c
637 changed files with 28926 additions and 16901 deletions

View file

@ -17,7 +17,7 @@
#ifdef _WIN32
#include <Winsock2.h>
#endif
#endif /* ifdef _WIN32 */
#include <isc/buffer.h>
#include <isc/log.h>
@ -54,11 +54,11 @@
#ifndef CHECK_SIBLING
#define CHECK_SIBLING 1
#endif
#endif /* ifndef CHECK_SIBLING */
#ifndef CHECK_LOCAL
#define CHECK_LOCAL 1
#endif
#endif /* ifndef CHECK_LOCAL */
#define CHECK(r) \
do { \
@ -85,17 +85,17 @@ bool nomerge = true;
bool docheckmx = true;
bool dochecksrv = true;
bool docheckns = true;
#else
#else /* if CHECK_LOCAL */
bool docheckmx = false;
bool dochecksrv = false;
bool docheckns = false;
#endif
#endif /* if CHECK_LOCAL */
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
#endif /* if CHECK_SIBLING */
DNS_ZONEOPT_CHECKWILDCARD |
DNS_ZONEOPT_WARNMXCNAME | DNS_ZONEOPT_WARNSRVCNAME;
@ -130,8 +130,9 @@ add(char *key, int value)
if (symtab == NULL) {
result = isc_symtab_create(sym_mctx, 100, freekey, sym_mctx,
false, &symtab);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return;
}
}
key = isc_mem_strdup(sym_mctx, key);
@ -139,8 +140,9 @@ add(char *key, int value)
symvalue.as_pointer = NULL;
result = isc_symtab_define(symtab, key, value, symvalue,
isc_symexists_reject);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
isc_mem_free(sym_mctx, key);
}
}
static bool
@ -148,12 +150,14 @@ logged(char *key, int value)
{
isc_result_t result;
if (symtab == NULL)
if (symtab == NULL) {
return (false);
}
result = isc_symtab_lookup(symtab, key, value, NULL);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return (true);
}
return (false);
}
@ -178,8 +182,9 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
REQUIRE(aaaa == NULL || !dns_rdataset_isassociated(aaaa) ||
aaaa->type == dns_rdatatype_aaaa);
if (a == NULL || aaaa == NULL)
if (a == NULL || aaaa == NULL) {
return (answer);
}
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME;
@ -206,8 +211,9 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
*/
cur = ai;
while (cur != NULL && cur->ai_canonname == NULL &&
cur->ai_next != NULL)
cur->ai_next != NULL) {
cur = cur->ai_next;
}
if (cur != NULL && cur->ai_canonname != NULL &&
strcasecmp(cur->ai_canonname, namebuf) != 0 &&
!logged(namebuf, ERR_IS_CNAME)) {
@ -223,7 +229,7 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
case EAI_NONAME:
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
case EAI_NODATA:
#endif
#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */
if (!logged(namebuf, ERR_NO_ADDRESSES)) {
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/NS '%s' (out of zone) "
@ -247,15 +253,17 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
/*
* Check that all glue records really exist.
*/
if (!dns_rdataset_isassociated(a))
if (!dns_rdataset_isassociated(a)) {
goto checkaaaa;
}
result = dns_rdataset_first(a);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(a, &rdata);
match = false;
for (cur = ai; cur != NULL; cur = cur->ai_next) {
if (cur->ai_family != AF_INET)
if (cur->ai_family != AF_INET) {
continue;
}
ptr = &((struct sockaddr_in *)(cur->ai_addr))->sin_addr;
if (memcmp(ptr, rdata.data, rdata.length) == 0) {
match = true;
@ -278,15 +286,17 @@ checkns(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner,
}
checkaaaa:
if (!dns_rdataset_isassociated(aaaa))
if (!dns_rdataset_isassociated(aaaa)) {
goto checkmissing;
}
result = dns_rdataset_first(aaaa);
while (result == ISC_R_SUCCESS) {
dns_rdataset_current(aaaa, &rdata);
match = false;
for (cur = ai; cur != NULL; cur = cur->ai_next) {
if (cur->ai_family != AF_INET6)
if (cur->ai_family != AF_INET6) {
continue;
}
ptr = &((struct sockaddr_in6 *)(cur->ai_addr))
->sin6_addr;
if (memcmp(ptr, rdata.data, rdata.length) == 0) {
@ -333,14 +343,17 @@ checkmissing:
continue;
}
match = false;
if (dns_rdataset_isassociated(rdataset))
if (dns_rdataset_isassociated(rdataset)) {
result = dns_rdataset_first(rdataset);
else
} else {
result = ISC_R_FAILURE;
}
while (result == ISC_R_SUCCESS && !match) {
dns_rdataset_current(rdataset, &rdata);
if (memcmp(ptr, rdata.data, rdata.length) == 0)
if (memcmp(ptr, rdata.data, rdata.length) ==
0) {
match = true;
}
dns_rdata_reset(&rdata);
result = dns_rdataset_next(rdataset);
}
@ -357,8 +370,9 @@ checkmissing:
missing_glue = true;
}
}
if (missing_glue)
if (missing_glue) {
add(namebuf, ERR_MISSING_GLUE);
}
}
freeaddrinfo(ai);
return (answer);
@ -399,12 +413,14 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
*/
cur = ai;
while (cur != NULL && cur->ai_canonname == NULL &&
cur->ai_next != NULL)
cur->ai_next != NULL) {
cur = cur->ai_next;
}
if (cur != NULL && cur->ai_canonname != NULL &&
strcasecmp(cur->ai_canonname, namebuf) != 0) {
if ((zone_options & DNS_ZONEOPT_WARNMXCNAME) != 0)
if ((zone_options & DNS_ZONEOPT_WARNMXCNAME) != 0) {
level = ISC_LOG_WARNING;
}
if ((zone_options & DNS_ZONEOPT_IGNOREMXCNAME) == 0) {
if (!logged(namebuf, ERR_IS_MXCNAME)) {
dns_zone_log(zone, level,
@ -415,8 +431,9 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
cur->ai_canonname);
add(namebuf, ERR_IS_MXCNAME);
}
if (level == ISC_LOG_ERROR)
if (level == ISC_LOG_ERROR) {
answer = false;
}
}
}
freeaddrinfo(ai);
@ -425,7 +442,7 @@ checkmx(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
case EAI_NONAME:
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
case EAI_NODATA:
#endif
#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */
if (!logged(namebuf, ERR_NO_ADDRESSES)) {
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/MX '%s' (out of zone) "
@ -482,12 +499,14 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
*/
cur = ai;
while (cur != NULL && cur->ai_canonname == NULL &&
cur->ai_next != NULL)
cur->ai_next != NULL) {
cur = cur->ai_next;
}
if (cur != NULL && cur->ai_canonname != NULL &&
strcasecmp(cur->ai_canonname, namebuf) != 0) {
if ((zone_options & DNS_ZONEOPT_WARNSRVCNAME) != 0)
if ((zone_options & DNS_ZONEOPT_WARNSRVCNAME) != 0) {
level = ISC_LOG_WARNING;
}
if ((zone_options & DNS_ZONEOPT_IGNORESRVCNAME) == 0) {
if (!logged(namebuf, ERR_IS_SRVCNAME)) {
dns_zone_log(zone, level,
@ -498,8 +517,9 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
cur->ai_canonname);
add(namebuf, ERR_IS_SRVCNAME);
}
if (level == ISC_LOG_ERROR)
if (level == ISC_LOG_ERROR) {
answer = false;
}
}
}
freeaddrinfo(ai);
@ -508,7 +528,7 @@ checksrv(dns_zone_t *zone, const dns_name_t *name, const dns_name_t *owner)
case EAI_NONAME:
#if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME)
case EAI_NODATA:
#endif
#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */
if (!logged(namebuf, ERR_NO_ADDRESSES)) {
dns_zone_log(zone, ISC_LOG_ERROR,
"%s/SRV '%s' (out of zone) "
@ -584,8 +604,9 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl)
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)
if (result == DNS_R_NEWORIGIN) {
result = ISC_R_SUCCESS;
}
CHECK(result);
CHECK(dns_db_allrdatasets(db, node, version, 0, &rdsiter));
@ -614,28 +635,35 @@ check_ttls(dns_zone_t *zone, dns_ttl_t maxttl)
}
dns_rdataset_disassociate(&rdataset);
}
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
}
CHECK(result);
dns_rdatasetiter_destroy(&rdsiter);
dns_db_detachnode(db, &node);
}
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
}
cleanup:
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
if (rdsiter != NULL)
}
if (rdsiter != NULL) {
dns_rdatasetiter_destroy(&rdsiter);
if (dbiter != NULL)
}
if (dbiter != NULL) {
dns_dbiterator_destroy(&dbiter);
if (version != NULL)
}
if (version != NULL) {
dns_db_closeversion(db, &version, false);
if (db != NULL)
}
if (db != NULL) {
dns_db_detach(&db);
}
return (result);
}
@ -656,9 +684,10 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
REQUIRE(zonep == NULL || *zonep == NULL);
if (debug)
if (debug) {
fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n",
zonename, filename, classname);
}
CHECK(dns_zone_create(&zone, mctx));
@ -672,8 +701,9 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
dns_zone_setdbtype(zone, 1, (const char *const *)dbtype);
CHECK(dns_zone_setfile(zone, filename, fileformat,
&dns_master_style_default));
if (journal != NULL)
if (journal != NULL) {
CHECK(dns_zone_setjournal(zone, journal));
}
DE_CONST(classname, region.base);
region.length = strlen(classname);
@ -685,12 +715,15 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
dns_zone_setmaxttl(zone, maxttl);
if (docheckmx)
if (docheckmx) {
dns_zone_setcheckmx(zone, checkmx);
if (docheckns)
}
if (docheckns) {
dns_zone_setcheckns(zone, checkns);
if (dochecksrv)
}
if (dochecksrv) {
dns_zone_setchecksrv(zone, checksrv);
}
CHECK(dns_zone_load(zone, false));
@ -708,8 +741,9 @@ load_zone(isc_mem_t *mctx, const char *zonename, const char *filename,
}
cleanup:
if (zone != NULL)
if (zone != NULL) {
dns_zone_detach(&zone);
}
return (result);
}
@ -726,11 +760,12 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
flags = (fileformat == dns_masterformat_text) ? "w" : "wb";
if (debug) {
if (filename != NULL && strcmp(filename, "-") != 0)
if (filename != NULL && strcmp(filename, "-") != 0) {
fprintf(stderr, "dumping \"%s\" to \"%s\"\n", zonename,
filename);
else
} else {
fprintf(stderr, "dumping \"%s\"\n", zonename);
}
}
if (filename != NULL && strcmp(filename, "-") != 0) {
@ -747,8 +782,9 @@ dump_zone(const char *zonename, dns_zone_t *zone, const char *filename,
result = dns_zone_dumptostream(zone, output, fileformat, style,
rawversion);
if (output != stdout)
if (output != stdout) {
(void)isc_stdio_close(output);
}
return (result);
}
@ -775,4 +811,4 @@ DestroySockets(void)
{
WSACleanup();
}
#endif
#endif /* ifdef _WIN32 */

View file

@ -45,7 +45,7 @@ void
InitSockets(void);
void
DestroySockets(void);
#endif
#endif /* ifdef _WIN32 */
extern int debug;
extern const char * journal;
@ -57,4 +57,4 @@ extern dns_zoneopt_t zone_options;
ISC_LANG_ENDDECLS
#endif
#endif /* ifndef CHECK_TOOL_H */

View file

@ -101,10 +101,12 @@ get_maps(const cfg_obj_t **maps, const char *name, const cfg_obj_t **obj)
{
int i;
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
return (false);
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
}
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS) {
return (true);
}
}
}
@ -119,12 +121,14 @@ get_checknames(const cfg_obj_t **maps, const cfg_obj_t **obj)
int i;
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
return (false);
}
checknames = NULL;
result = cfg_map_get(maps[i], "check-names", &checknames);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
continue;
}
if (checknames != NULL && !cfg_obj_islist(checknames)) {
*obj = checknames;
return (true);
@ -153,18 +157,21 @@ configure_hint(const char *zfile, const char *zclass, isc_mem_t *mctx)
dns_rdataclass_t rdclass;
isc_textregion_t r;
if (zfile == NULL)
if (zfile == NULL) {
return (ISC_R_FAILURE);
}
DE_CONST(zclass, r.base);
r.length = strlen(zclass);
result = dns_rdataclass_fromtext(&rdclass, &r);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
result = dns_rootns_create(mctx, rdclass, zfile, &db);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_db_detach(&db);
return (ISC_R_SUCCESS);
@ -199,19 +206,22 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
zname = cfg_obj_asstring(cfg_tuple_get(zconfig, "name"));
classobj = cfg_tuple_get(zconfig, "class");
if (!cfg_obj_isstring(classobj))
if (!cfg_obj_isstring(classobj)) {
zclass = vclass;
else
} else {
zclass = cfg_obj_asstring(classobj);
}
zoptions = cfg_tuple_get(zconfig, "options");
maps[i++] = zoptions;
if (vconfig != NULL)
if (vconfig != NULL) {
maps[i++] = cfg_tuple_get(vconfig, "options");
}
if (config != NULL) {
cfg_map_get(config, "options", &obj);
if (obj != NULL)
if (obj != NULL) {
maps[i++] = obj;
}
}
maps[i] = NULL;
@ -220,12 +230,14 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
const char *inview = cfg_obj_asstring(inviewobj);
printf("%s %s %s in-view %s\n", zname, zclass, view, inview);
}
if (inviewobj != NULL)
if (inviewobj != NULL) {
return (ISC_R_SUCCESS);
}
cfg_map_get(zoptions, "type", &typeobj);
if (typeobj == NULL)
if (typeobj == NULL) {
return (ISC_R_FAILURE);
}
if (list) {
const char *ztype = cfg_obj_asstring(typeobj);
@ -238,16 +250,19 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
*/
cfg_map_get(zoptions, "database", &dbobj);
if (dbobj != NULL && strcmp("rbt", cfg_obj_asstring(dbobj)) != 0 &&
strcmp("rbt64", cfg_obj_asstring(dbobj)) != 0)
strcmp("rbt64", cfg_obj_asstring(dbobj)) != 0) {
return (ISC_R_SUCCESS);
}
cfg_map_get(zoptions, "dlz", &dlzobj);
if (dlzobj != NULL)
if (dlzobj != NULL) {
return (ISC_R_SUCCESS);
}
cfg_map_get(zoptions, "file", &fileobj);
if (fileobj != NULL)
if (fileobj != NULL) {
zfile = cfg_obj_asstring(fileobj);
}
/*
* Check hints files for hint zones.
@ -267,12 +282,14 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
*/
if (strcasecmp(cfg_obj_asstring(typeobj), "redirect") == 0) {
cfg_map_get(zoptions, "masters", &mastersobj);
if (mastersobj != NULL)
if (mastersobj != NULL) {
return (ISC_R_SUCCESS);
}
}
if (zfile == NULL)
if (zfile == NULL) {
return (ISC_R_FAILURE);
}
obj = NULL;
if (get_maps(maps, "check-dup-records", &obj)) {
@ -316,12 +333,14 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
obj = NULL;
if (get_maps(maps, "check-integrity", &obj)) {
if (cfg_obj_asboolean(obj))
if (cfg_obj_asboolean(obj)) {
zone_options |= DNS_ZONEOPT_CHECKINTEGRITY;
else
} else {
zone_options &= ~DNS_ZONEOPT_CHECKINTEGRITY;
} else
}
} else {
zone_options |= DNS_ZONEOPT_CHECKINTEGRITY;
}
obj = NULL;
if (get_maps(maps, "check-mx-cname", &obj)) {
@ -365,10 +384,11 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
obj = NULL;
if (get_maps(maps, "check-sibling", &obj)) {
if (cfg_obj_asboolean(obj))
if (cfg_obj_asboolean(obj)) {
zone_options |= DNS_ZONEOPT_CHECKSIBLING;
else
} else {
zone_options &= ~DNS_ZONEOPT_CHECKSIBLING;
}
}
obj = NULL;
@ -429,9 +449,10 @@ configure_zone(const char *vclass, const char *view, const cfg_obj_t *zconfig,
result = load_zone(mctx, zname, zfile, masterformat, zclass, maxttl,
NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s/%s/%s: %s\n", view, zname, zclass,
dns_result_totext(result));
}
return (result);
}
@ -447,22 +468,25 @@ configure_view(const char *vclass, const char *view, const cfg_obj_t *config,
isc_result_t tresult;
voptions = NULL;
if (vconfig != NULL)
if (vconfig != NULL) {
voptions = cfg_tuple_get(vconfig, "options");
}
zonelist = NULL;
if (voptions != NULL)
if (voptions != NULL) {
(void)cfg_map_get(voptions, "zone", &zonelist);
else
} else {
(void)cfg_map_get(config, "zone", &zonelist);
}
for (element = cfg_list_first(zonelist); element != NULL;
element = cfg_list_next(element)) {
const cfg_obj_t *zconfig = cfg_listelt_value(element);
tresult = configure_zone(vclass, view, zconfig, vconfig, config,
mctx, list);
if (tresult != ISC_R_SUCCESS)
if (tresult != ISC_R_SUCCESS) {
result = tresult;
}
}
return (result);
}
@ -503,27 +527,31 @@ load_zones_fromconfig(const cfg_obj_t *config, isc_mem_t *mctx, bool list_zones)
char buf[sizeof("CLASS65535")];
vconfig = cfg_listelt_value(element);
if (vconfig == NULL)
if (vconfig == NULL) {
continue;
}
classobj = cfg_tuple_get(vconfig, "class");
CHECK(config_getclass(classobj, dns_rdataclass_in, &viewclass));
if (dns_rdataclass_ismeta(viewclass))
if (dns_rdataclass_ismeta(viewclass)) {
CHECK(ISC_R_FAILURE);
}
dns_rdataclass_format(viewclass, buf, sizeof(buf));
vname = cfg_obj_asstring(cfg_tuple_get(vconfig, "name"));
tresult = configure_view(buf, vname, config, vconfig, mctx,
list_zones);
if (tresult != ISC_R_SUCCESS)
if (tresult != ISC_R_SUCCESS) {
result = tresult;
}
}
if (views == NULL) {
tresult = configure_view("IN", "_default", config, NULL, mctx,
list_zones);
if (tresult != ISC_R_SUCCESS)
if (tresult != ISC_R_SUCCESS) {
result = tresult;
}
}
cleanup:
@ -566,16 +594,24 @@ main(int argc, char **argv)
while ((c = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (c) {
case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0)
if (strcasecmp(isc_commandline_argument, "record") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
if (strcasecmp(isc_commandline_argument, "trace") == 0)
}
if (strcasecmp(isc_commandline_argument, "trace") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
if (strcasecmp(isc_commandline_argument, "usage") == 0)
}
if (strcasecmp(isc_commandline_argument, "usage") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
if (strcasecmp(isc_commandline_argument, "size") == 0)
}
if (strcasecmp(isc_commandline_argument, "size") == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGSIZE;
if (strcasecmp(isc_commandline_argument, "mctx") == 0)
}
if (strcasecmp(isc_commandline_argument, "mctx") == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGCTX;
}
break;
default:
break;
@ -639,10 +675,11 @@ main(int argc, char **argv)
break;
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
usage();
@ -662,16 +699,19 @@ main(int argc, char **argv)
exit(1);
}
if (isc_commandline_index + 1 < argc)
if (isc_commandline_index + 1 < argc) {
usage();
if (argv[isc_commandline_index] != NULL)
}
if (argv[isc_commandline_index] != NULL) {
conffile = argv[isc_commandline_index];
if (conffile == NULL || conffile[0] == '\0')
}
if (conffile == NULL || conffile[0] == '\0') {
conffile = NAMED_CONFFILE;
}
#ifdef _WIN32
InitSockets();
#endif
#endif /* ifdef _WIN32 */
RUNTIME_CHECK(setup_logging(mctx, stdout, &logc) == ISC_R_SUCCESS);
@ -696,12 +736,14 @@ main(int argc, char **argv)
if (result == ISC_R_SUCCESS && (load_zones || list_zones)) {
result = load_zones_fromconfig(config, mctx, list_zones);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
exit_status = 1;
}
}
if (print && exit_status == 0)
if (print && exit_status == 0) {
cfg_printx(config, flags, output, NULL);
}
cfg_obj_destroy(parser, &config);
cfg_parser_destroy(&parser);
@ -712,7 +754,7 @@ main(int argc, char **argv)
#ifdef _WIN32
DestroySockets();
#endif
#endif /* ifdef _WIN32 */
return (exit_status);
}

View file

@ -123,18 +123,21 @@ main(int argc, char **argv)
outputstyle = &dns_master_style_full;
prog_name = strrchr(argv[0], '/');
if (prog_name == NULL)
if (prog_name == NULL) {
prog_name = strrchr(argv[0], '\\');
if (prog_name != NULL)
}
if (prog_name != NULL) {
prog_name++;
else
} else {
prog_name = argv[0];
}
/*
* Libtool doesn't preserve the program name prior to final
* installation. Remove the libtool prefix ("lt-").
*/
if (strncmp(prog_name, "lt-", 3) == 0)
if (strncmp(prog_name, "lt-", 3) == 0) {
prog_name += 3;
}
#define PROGCMP(X) \
(strcasecmp(prog_name, X) == 0 || strcasecmp(prog_name, X ".exe") == 0)
@ -155,8 +158,9 @@ main(int argc, char **argv)
DNS_ZONEOPT_CHECKSPF | DNS_ZONEOPT_CHECKDUPRR |
DNS_ZONEOPT_CHECKNAMES | DNS_ZONEOPT_CHECKNAMESFAIL |
DNS_ZONEOPT_CHECKWILDCARD);
} else
} else {
zone_options |= (DNS_ZONEOPT_CHECKDUPRR | DNS_ZONEOPT_CHECKSPF);
}
#define ARGCMP(X) (strcmp(isc_commandline_argument, X) == 0)
@ -328,9 +332,9 @@ main(int argc, char **argv)
break;
case 's':
if (ARGCMP("full"))
if (ARGCMP("full")) {
outputstyle = &dns_master_style_full;
else if (ARGCMP("relative")) {
} else if (ARGCMP("relative")) {
outputstyle = &dns_master_style_default;
} else {
fprintf(stderr,
@ -409,17 +413,19 @@ main(int argc, char **argv)
break;
case 'W':
if (ARGCMP("warn"))
if (ARGCMP("warn")) {
zone_options |= DNS_ZONEOPT_CHECKWILDCARD;
else if (ARGCMP("ignore"))
} else if (ARGCMP("ignore")) {
zone_options &= ~DNS_ZONEOPT_CHECKWILDCARD;
}
break;
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
prog_name, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
usage();
@ -440,11 +446,11 @@ main(int argc, char **argv)
}
if (inputformatstr != NULL) {
if (strcasecmp(inputformatstr, "text") == 0)
if (strcasecmp(inputformatstr, "text") == 0) {
inputformat = dns_masterformat_text;
else if (strcasecmp(inputformatstr, "raw") == 0)
} else if (strcasecmp(inputformatstr, "raw") == 0) {
inputformat = dns_masterformat_raw;
else if (strncasecmp(inputformatstr, "raw=", 4) == 0) {
} else if (strncasecmp(inputformatstr, "raw=", 4) == 0) {
inputformat = dns_masterformat_raw;
fprintf(stderr, "WARNING: input format raw, version "
"ignored\n");
@ -491,8 +497,9 @@ main(int argc, char **argv)
}
}
if (output_filename != NULL)
if (output_filename != NULL) {
dumpzone = 1;
}
/*
* If we are outputing to stdout then send the informational
@ -506,17 +513,19 @@ main(int argc, char **argv)
logdump = false;
}
if (isc_commandline_index + 2 != argc)
if (isc_commandline_index + 2 != argc) {
usage();
}
#ifdef _WIN32
InitSockets();
#endif
#endif /* ifdef _WIN32 */
isc_mem_create(&mctx);
if (!quiet)
if (!quiet) {
RUNTIME_CHECK(setup_logging(mctx, errout, &lctx) ==
ISC_R_SUCCESS);
}
dns_result_register();
@ -539,18 +548,21 @@ main(int argc, char **argv)
}
result = dump_zone(origin, zone, output_filename, outputformat,
outputstyle, rawversion);
if (logdump)
if (logdump) {
fprintf(errout, "done\n");
}
}
if (!quiet && result == ISC_R_SUCCESS)
if (!quiet && result == ISC_R_SUCCESS) {
fprintf(errout, "OK\n");
}
destroy();
if (lctx != NULL)
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
isc_mem_destroy(&mctx);
#ifdef _WIN32
DestroySockets();
#endif
#endif /* ifdef _WIN32 */
return ((result == ISC_R_SUCCESS) ? 0 : 1);
}

View file

@ -36,7 +36,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include <dns/keyvalues.h>
#include <dns/name.h>
@ -104,20 +104,22 @@ main(int argc, char **argv)
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
result = isc_file_progname(*argv, program, sizeof(program));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
memmove(program, "tsig-keygen", 11);
}
progname = program;
/*
* Libtool doesn't preserve the program name prior to final
* installation. Remove the libtool prefix ("lt-").
*/
if (strncmp(progname, "lt-", 3) == 0)
if (strncmp(progname, "lt-", 3) == 0) {
progname += 3;
}
#define PROGCMP(X) \
(strcasecmp(progname, X) == 0 || strcasecmp(progname, X ".exe") == 0)
@ -140,18 +142,20 @@ main(int argc, char **argv)
case 'a':
algname = isc_commandline_argument;
alg = alg_fromtext(algname);
if (alg == DST_ALG_UNKNOWN)
if (alg == DST_ALG_UNKNOWN) {
fatal("Unsupported algorithm '%s'", algname);
}
keysize = alg_bits(alg);
break;
case 'h':
usage(0);
case 'k':
case 'y':
if (progmode == progmode_confgen)
if (progmode == progmode_confgen) {
keyname = isc_commandline_argument;
else
} else {
usage(1);
}
break;
case 'M':
isc_mem_debugging = ISC_MEM_DEBUGTRACE;
@ -160,33 +164,37 @@ main(int argc, char **argv)
show_final_mem = true;
break;
case 'q':
if (progmode == progmode_confgen)
if (progmode == progmode_confgen) {
quiet = true;
else
} else {
usage(1);
}
break;
case 'r':
fatal("The -r option has been deprecated.");
break;
case 's':
if (progmode == progmode_confgen)
if (progmode == progmode_confgen) {
self_domain = isc_commandline_argument;
else
} else {
usage(1);
}
break;
case 'z':
if (progmode == progmode_confgen)
if (progmode == progmode_confgen) {
zone = isc_commandline_argument;
else
} else {
usage(1);
}
break;
case '?':
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
usage(1);
} else
} else {
usage(0);
}
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
@ -195,16 +203,19 @@ main(int argc, char **argv)
}
}
if (progmode == progmode_keygen)
if (progmode == progmode_keygen) {
keyname = argv[isc_commandline_index++];
}
POST(argv);
if (self_domain != NULL && zone != NULL)
if (self_domain != NULL && zone != NULL) {
usage(1); /* -s and -z cannot coexist */
}
if (argc > isc_commandline_index)
if (argc > isc_commandline_index) {
usage(1);
}
/* Use canonical algorithm name */
algname = alg_totext(alg);
@ -216,10 +227,11 @@ main(int argc, char **argv)
keyname = ((progmode == progmode_keygen) ? KEYGEN_DEFAULT
: CONFGEN_DEFAULT);
if (self_domain != NULL)
if (self_domain != NULL) {
suffix = self_domain;
else if (zone != NULL)
} else if (zone != NULL) {
suffix = zone;
}
if (suffix != NULL) {
len = strlen(keyname) + strlen(suffix) + 2;
keybuf = isc_mem_get(mctx, len);
@ -232,11 +244,12 @@ main(int argc, char **argv)
generate_key(mctx, alg, keysize, &key_txtbuffer);
if (!quiet)
if (!quiet) {
printf("\
# To activate this key, place the following in named.conf, and\n\
# in a separate keyfile on the system or systems from which nsupdate\n\
# will be run:\n");
}
printf("\
key \"%s\" {\n\
@ -283,11 +296,13 @@ update-policy {\n\
nsupdate -k <keyfile>\n");
}
if (keybuf != NULL)
if (keybuf != NULL) {
isc_mem_put(mctx, keybuf, len);
}
if (show_final_mem)
if (show_final_mem) {
isc_mem_stats(mctx, stderr);
}
isc_mem_destroy(&mctx);

View file

@ -31,4 +31,4 @@ set_user(FILE *fd, const char *user);
ISC_LANG_ENDDECLS
#endif
#endif /* ifndef RNDC_OS_H */

View file

@ -41,19 +41,19 @@ alg_totext(dns_secalg_t alg)
{
switch (alg) {
case DST_ALG_HMACMD5:
return "hmac-md5";
return ("hmac-md5");
case DST_ALG_HMACSHA1:
return "hmac-sha1";
return ("hmac-sha1");
case DST_ALG_HMACSHA224:
return "hmac-sha224";
return ("hmac-sha224");
case DST_ALG_HMACSHA256:
return "hmac-sha256";
return ("hmac-sha256");
case DST_ALG_HMACSHA384:
return "hmac-sha384";
return ("hmac-sha384");
case DST_ALG_HMACSHA512:
return "hmac-sha512";
return ("hmac-sha512");
default:
return "(unknown)";
return ("(unknown)");
}
}
@ -64,22 +64,29 @@ dns_secalg_t
alg_fromtext(const char *name)
{
const char *p = name;
if (strncasecmp(p, "hmac-", 5) == 0)
if (strncasecmp(p, "hmac-", 5) == 0) {
p = &name[5];
}
if (strcasecmp(p, "md5") == 0)
return DST_ALG_HMACMD5;
if (strcasecmp(p, "sha1") == 0)
return DST_ALG_HMACSHA1;
if (strcasecmp(p, "sha224") == 0)
return DST_ALG_HMACSHA224;
if (strcasecmp(p, "sha256") == 0)
return DST_ALG_HMACSHA256;
if (strcasecmp(p, "sha384") == 0)
return DST_ALG_HMACSHA384;
if (strcasecmp(p, "sha512") == 0)
return DST_ALG_HMACSHA512;
return DST_ALG_UNKNOWN;
if (strcasecmp(p, "md5") == 0) {
return (DST_ALG_HMACMD5);
}
if (strcasecmp(p, "sha1") == 0) {
return (DST_ALG_HMACSHA1);
}
if (strcasecmp(p, "sha224") == 0) {
return (DST_ALG_HMACSHA224);
}
if (strcasecmp(p, "sha256") == 0) {
return (DST_ALG_HMACSHA256);
}
if (strcasecmp(p, "sha384") == 0) {
return (DST_ALG_HMACSHA384);
}
if (strcasecmp(p, "sha512") == 0) {
return (DST_ALG_HMACSHA512);
}
return (DST_ALG_UNKNOWN);
}
/*%
@ -90,19 +97,19 @@ alg_bits(dns_secalg_t alg)
{
switch (alg) {
case DST_ALG_HMACMD5:
return 128;
return (128);
case DST_ALG_HMACSHA1:
return 160;
return (160);
case DST_ALG_HMACSHA224:
return 224;
return (224);
case DST_ALG_HMACSHA256:
return 256;
return (256);
case DST_ALG_HMACSHA384:
return 384;
return (384);
case DST_ALG_HMACSHA512:
return 512;
return (512);
default:
return 0;
return (0);
}
}
@ -124,15 +131,17 @@ generate_key(isc_mem_t *mctx, dns_secalg_t alg, int keysize,
case DST_ALG_HMACSHA1:
case DST_ALG_HMACSHA224:
case DST_ALG_HMACSHA256:
if (keysize < 1 || keysize > 512)
if (keysize < 1 || keysize > 512) {
fatal("keysize %d out of range (must be 1-512)\n",
keysize);
}
break;
case DST_ALG_HMACSHA384:
case DST_ALG_HMACSHA512:
if (keysize < 1 || keysize > 1024)
if (keysize < 1 || keysize > 1024) {
fatal("keysize %d out of range (must be 1-1024)\n",
keysize);
}
break;
default:
fatal("unsupported algorithm %d\n", alg);
@ -153,8 +162,9 @@ generate_key(isc_mem_t *mctx, dns_secalg_t alg, int keysize,
DO("bsse64 encode secret",
isc_base64_totext(&key_rawregion, -1, "", key_txtbuffer));
if (key != NULL)
if (key != NULL) {
dst_key_free(&key);
}
dst_lib_destroy();
}
@ -175,8 +185,9 @@ write_key_file(const char *keyfile, const char *user, const char *keyname,
DO("create keyfile", isc_file_safecreate(keyfile, &fd));
if (user != NULL) {
if (set_user(fd, user) == -1)
if (set_user(fd, user) == -1) {
fatal("unable to set file owner\n");
}
}
fprintf(fd,
@ -185,9 +196,11 @@ write_key_file(const char *keyfile, const char *user, const char *keyname,
keyname, algname, (int)isc_buffer_usedlength(secret),
(char *)isc_buffer_base(secret));
fflush(fd);
if (ferror(fd))
if (ferror(fd)) {
fatal("write to %s failed\n", keyfile);
if (fclose(fd))
}
if (fclose(fd)) {
fatal("fclose(%s) failed\n", keyfile);
}
fprintf(stderr, "wrote key file \"%s\"\n", keyfile);
}

View file

@ -108,8 +108,9 @@ main(int argc, char **argv)
keydef = keyfile = RNDC_KEYFILE;
result = isc_file_progname(*argv, program, sizeof(program));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
memmove(program, "rndc-confgen", 13);
}
progname = program;
keyname = DEFAULT_KEYNAME;
@ -128,13 +129,15 @@ main(int argc, char **argv)
case 'A':
algname = isc_commandline_argument;
alg = alg_fromtext(algname);
if (alg == DST_ALG_UNKNOWN)
if (alg == DST_ALG_UNKNOWN) {
fatal("Unsupported algorithm '%s'", algname);
}
break;
case 'b':
keysize = strtol(isc_commandline_argument, &p, 10);
if (*p != '\0' || keysize < 0)
if (*p != '\0' || keysize < 0) {
fatal("-b requires a non-negative number");
}
break;
case 'c':
keyfile = isc_commandline_argument;
@ -154,9 +157,10 @@ main(int argc, char **argv)
break;
case 'p':
port = strtol(isc_commandline_argument, &p, 10);
if (*p != '\0' || port < 0 || port > 65535)
if (*p != '\0' || port < 0 || port > 65535) {
fatal("port '%s' out of range",
isc_commandline_argument);
}
break;
case 'r':
fatal("The -r option has been deprecated.");
@ -164,8 +168,10 @@ main(int argc, char **argv)
case 's':
serveraddr = isc_commandline_argument;
if (inet_pton(AF_INET, serveraddr, &addr4_dummy) != 1 &&
inet_pton(AF_INET6, serveraddr, &addr6_dummy) != 1)
inet_pton(AF_INET6, serveraddr, &addr6_dummy) !=
1) {
fatal("-s should be an IPv4 or IPv6 address");
}
break;
case 't':
chrootdir = isc_commandline_argument;
@ -181,8 +187,9 @@ main(int argc, char **argv)
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
usage(1);
} else
} else {
usage(0);
}
break;
default:
fprintf(stderr, "%s: unhandled option -%c\n", program,
@ -195,8 +202,9 @@ main(int argc, char **argv)
argv += isc_commandline_index;
POST(argv);
if (argc > 0)
if (argc > 0) {
usage(1);
}
if (alg == DST_ALG_HMACMD5) {
fprintf(stderr, "warning: use of hmac-md5 for RNDC keys "
@ -204,8 +212,9 @@ main(int argc, char **argv)
"recommended.\n");
}
if (keysize < 0)
if (keysize < 0) {
keysize = alg_bits(alg);
}
algname = alg_totext(alg);
isc_mem_create(&mctx);
@ -262,8 +271,9 @@ options {\n\
port, serveraddr, keyname);
}
if (show_final_mem)
if (show_final_mem) {
isc_mem_stats(mctx, stderr);
}
isc_mem_destroy(&mctx);

View file

@ -19,7 +19,7 @@
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/types.h>
#endif
#endif /* ifndef WIN32 */
#include <inttypes.h>
#include <stdbool.h>
@ -38,7 +38,7 @@
#include <isc/mem.h>
#ifdef WIN32
#include <isc/ntpaths.h>
#endif
#endif /* ifdef WIN32 */
#include <isc/parseint.h>
#include <isc/print.h>
#include <isc/sockaddr.h>
@ -255,8 +255,9 @@ delv_log(int level, const char *fmt, ...)
va_list ap;
char msgbuf[2048];
if (!isc_log_wouldlog(lctx, level))
if (!isc_log_wouldlog(lctx, level)) {
return;
}
va_start(ap, fmt);
@ -276,8 +277,9 @@ setup_logging(FILE *errout)
isc_logconfig_t * logconfig = NULL;
result = isc_log_create(mctx, &lctx, &logconfig);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up logging");
}
isc_log_registercategories(lctx, categories);
isc_log_registermodules(lctx, modules);
@ -294,60 +296,69 @@ setup_logging(FILE *errout)
result = isc_log_createchannel(logconfig, "stderr", ISC_LOG_TOFILEDESC,
ISC_LOG_DYNAMIC, &destination,
ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'stderr'");
}
isc_log_setdebuglevel(lctx, loglevel);
result = isc_log_settag(logconfig, ";; ");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set log tag");
}
result = isc_log_usechannel(logconfig, "stderr",
ISC_LOGCATEGORY_DEFAULT, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't attach to log channel 'stderr'");
}
if (resolve_trace && loglevel < 1) {
result = isc_log_createchannel(
logconfig, "resolver", ISC_LOG_TOFILEDESC,
ISC_LOG_DEBUG(1), &destination, ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'resolver'");
}
result = isc_log_usechannel(logconfig, "resolver",
DNS_LOGCATEGORY_RESOLVER,
DNS_LOGMODULE_RESOLVER);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't attach to log channel 'resolver'");
}
}
if (validator_trace && loglevel < 3) {
result = isc_log_createchannel(
logconfig, "validator", ISC_LOG_TOFILEDESC,
ISC_LOG_DEBUG(3), &destination, ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'validator'");
}
result = isc_log_usechannel(logconfig, "validator",
DNS_LOGCATEGORY_DNSSEC,
DNS_LOGMODULE_VALIDATOR);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't attach to log channel 'validator'");
}
}
if (message_trace && loglevel < 10) {
result = isc_log_createchannel(
logconfig, "messages", ISC_LOG_TOFILEDESC,
ISC_LOG_DEBUG(10), &destination, ISC_LOG_PRINTPREFIX);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't set up log channel 'messages'");
}
result = isc_log_usechannel(logconfig, "messages",
DNS_LOGCATEGORY_RESOLVER,
DNS_LOGMODULE_PACKETS);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't attach to log channel 'messagse'");
}
}
}
@ -449,8 +460,9 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner,
return (ISC_R_SUCCESS);
}
if (!showdnssec && rdataset->type == dns_rdatatype_rrsig)
if (!showdnssec && rdataset->type == dns_rdatatype_rrsig) {
return (ISC_R_SUCCESS);
}
if (first || rdataset->trust != trust) {
if (!first && showtrust && !short_form && !yaml) {
@ -471,15 +483,17 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner,
result == ISC_R_SUCCESS;
result = dns_rdataset_next(rdataset)) {
if ((rdataset->attributes &
DNS_RDATASETATTR_NEGATIVE) != 0)
DNS_RDATASETATTR_NEGATIVE) != 0) {
continue;
}
dns_rdataset_current(rdataset, &rdata);
result = dns_rdata_tofmttext(
&rdata, dns_rootname, styleflags, 0,
splitwidth, " ", &target);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
break;
}
if (isc_buffer_availablelength(&target) < 1) {
result = ISC_R_NOSPACE;
@ -504,18 +518,20 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner,
if (result == ISC_R_NOSPACE) {
isc_mem_put(mctx, t, len);
len += 1024;
} else if (result == ISC_R_NOMORE)
} else if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
else
} else {
CHECK(result);
}
} while (result == ISC_R_NOSPACE);
isc_buffer_usedregion(&target, &r);
printf("%.*s", (int)r.length, (char *)r.base);
cleanup:
if (t != NULL)
if (t != NULL) {
isc_mem_put(mctx, t, len);
}
return (ISC_R_SUCCESS);
}
@ -751,14 +767,14 @@ key_fromconfig(const cfg_obj_t *key, dns_client_t *client)
CHECK(dns_client_addtrustedkey(client, dns_rdataclass_in,
dns_rdatatype_ds, keyname,
&rrdatabuf));
};
}
num_keys++;
cleanup:
if (result == DST_R_NOCRYPTO)
if (result == DST_R_NOCRYPTO) {
cfg_obj_log(key, lctx, ISC_LOG_ERROR, "no crypto support");
else if (result == DST_R_UNSUPPORTEDALG) {
} else if (result == DST_R_UNSUPPORTEDALG) {
cfg_obj_log(key, lctx, ISC_LOG_WARNING,
"skipping trusted key '%s': %s", keynamestr,
isc_result_totext(result));
@ -792,8 +808,9 @@ load_keys(const cfg_obj_t *keys, dns_client_t *client)
}
cleanup:
if (result == DST_R_NOCRYPTO)
if (result == DST_R_NOCRYPTO) {
result = ISC_R_SUCCESS;
}
return (result);
}
@ -815,12 +832,12 @@ setup_dnsseckeys(dns_client_t *client)
if (filename == NULL) {
#ifndef WIN32
filename = SYSCONFDIR "/bind.keys";
#else
#else /* ifndef WIN32 */
static char buf[MAX_PATH];
strlcpy(buf, isc_ntpaths_get(SYS_CONF_DIR), sizeof(buf));
strlcat(buf, "\\bind.keys", sizeof(buf));
filename = buf;
#endif
#endif /* ifndef WIN32 */
}
if (trust_anchor == NULL) {
@ -908,8 +925,9 @@ addserver(dns_client_t *client)
dns_name_t * name = NULL;
result = parse_uint(&destport, port, 0xffff, "port");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse port number");
}
ISC_LIST_INIT(servers);
@ -931,12 +949,13 @@ addserver(dns_client_t *client)
ISC_LIST_APPEND(servers, sa, link);
} else {
memset(&hints, 0, sizeof(hints));
if (!use_ipv6)
if (!use_ipv6) {
hints.ai_family = AF_INET;
else if (!use_ipv4)
} else if (!use_ipv4) {
hints.ai_family = AF_INET6;
else
} else {
hints.ai_family = AF_UNSPEC;
}
hints.ai_socktype = SOCK_DGRAM;
hints.ai_protocol = IPPROTO_UDP;
gaierror = getaddrinfo(server, port, &hints, &res);
@ -949,8 +968,9 @@ addserver(dns_client_t *client)
result = ISC_R_SUCCESS;
for (cur = res; cur != NULL; cur = cur->ai_next) {
if (cur->ai_family != AF_INET &&
cur->ai_family != AF_INET6)
cur->ai_family != AF_INET6) {
continue;
}
sa = isc_mem_get(mctx, sizeof(*sa));
memset(sa, 0, sizeof(*sa));
ISC_LINK_INIT(sa, link);
@ -971,9 +991,10 @@ cleanup:
isc_mem_put(mctx, sa, sizeof(*sa));
}
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
delv_log(ISC_LOG_ERROR, "addserver: %s",
isc_result_totext(result));
}
return (result);
}
@ -988,8 +1009,9 @@ findserver(dns_client_t *client)
uint32_t destport;
result = parse_uint(&destport, port, 0xffff, "port");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse port number");
}
result = irs_resconf_load(mctx, "/etc/resolv.conf", &resconf);
if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) {
@ -1041,13 +1063,15 @@ findserver(dns_client_t *client)
result = dns_client_setservers(client, dns_rdataclass_in, NULL,
nameservers);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
delv_log(ISC_LOG_ERROR, "dns_client_setservers: %s",
isc_result_totext(result));
}
cleanup:
if (resconf != NULL)
if (resconf != NULL) {
irs_resconf_destroy(&resconf);
}
return (result);
}
@ -1056,8 +1080,9 @@ parse_uint(uint32_t *uip, const char *value, uint32_t max, const char *desc)
{
uint32_t n;
isc_result_t result = isc_parse_uint32(&n, value, 10);
if (result == ISC_R_SUCCESS && n > max)
if (result == ISC_R_SUCCESS && n > max) {
result = ISC_R_RANGE;
}
if (result != ISC_R_SUCCESS) {
printf("invalid %s '%s': %s\n", desc, value,
isc_result_totext(result));
@ -1146,8 +1171,9 @@ plus_option(char *option)
switch (cmd[1]) {
case 't': /* mtrace */
message_trace = state;
if (state)
if (state) {
resolve_trace = state;
}
break;
case 'u': /* multiline */
FULLCHECK("multiline");
@ -1161,8 +1187,9 @@ plus_option(char *option)
switch (cmd[1]) {
case 'o': /* root */
FULLCHECK("root");
if (state && no_sigs)
if (state && no_sigs) {
break;
}
root_validation = state;
if (value != NULL) {
trust_anchor = isc_mem_strdup(mctx, value);
@ -1194,13 +1221,15 @@ plus_option(char *option)
break;
case 'p': /* split */
FULLCHECK("split");
if (value != NULL && !state)
if (value != NULL && !state) {
goto invalid_option;
}
if (!state) {
splitwidth = 0;
break;
} else if (value == NULL)
} else if (value == NULL) {
break;
}
result = parse_uint(&splitwidth, value, 1023, "split");
if (splitwidth % 4 != 0) {
@ -1216,10 +1245,12 @@ plus_option(char *option)
* using the default width but incorrect in this
* case, so we correct for it
*/
if (splitwidth)
if (splitwidth) {
splitwidth += 3;
if (result != ISC_R_SUCCESS)
}
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse split");
}
break;
default:
goto invalid_option;
@ -1250,8 +1281,9 @@ plus_option(char *option)
case 'v': /* vtrace */
FULLCHECK("vtrace");
validator_trace = state;
if (state)
if (state) {
resolve_trace = state;
}
break;
case 'y': /* yaml */
FULLCHECK("yaml");
@ -1303,16 +1335,18 @@ dash_option(char *option, char *next, bool *open_type_class)
opt = option[0];
switch (opt) {
case '4':
if (isc_net_probeipv4() != ISC_R_SUCCESS)
if (isc_net_probeipv4() != ISC_R_SUCCESS) {
fatal("IPv4 networking not available");
}
if (use_ipv6) {
isc_net_disableipv6();
use_ipv6 = false;
}
break;
case '6':
if (isc_net_probeipv6() != ISC_R_SUCCESS)
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
fatal("IPv6 networking not available");
}
if (use_ipv4) {
isc_net_disableipv4();
use_ipv4 = false;
@ -1321,7 +1355,7 @@ dash_option(char *option, char *next, bool *open_type_class)
case 'h':
usage();
exit(0);
/* NOTREACHED */
/* NOTREACHED */
case 'i':
no_sigs = true;
root_validation = false;
@ -1332,15 +1366,16 @@ dash_option(char *option, char *next, bool *open_type_class)
case 'v':
fputs("delv " VERSION "\n", stderr);
exit(0);
/* NOTREACHED */
/* NOTREACHED */
default:
INSIST(0);
ISC_UNREACHABLE();
}
if (strlen(option) > 1U)
if (strlen(option) > 1U) {
option = &option[1];
else
} else {
return (false);
}
}
opt = option[0];
if (strlen(option) > 1U) {
@ -1350,8 +1385,9 @@ dash_option(char *option, char *next, bool *open_type_class)
value_from_next = true;
value = next;
}
if (value == NULL)
if (value == NULL) {
goto invalid_option;
}
switch (opt) {
case 'a':
anchorfile = isc_mem_strdup(mctx, value);
@ -1360,53 +1396,62 @@ dash_option(char *option, char *next, bool *open_type_class)
hash = strchr(value, '#');
if (hash != NULL) {
result = parse_uint(&num, hash + 1, 0xffff, "port");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse port number");
}
srcport = num;
*hash = '\0';
} else
} else {
srcport = 0;
}
if (inet_pton(AF_INET, value, &in4) == 1) {
if (srcaddr4 != NULL)
if (srcaddr4 != NULL) {
fatal("Only one local address per family "
"can be specified\n");
}
isc_sockaddr_fromin(&a4, &in4, srcport);
srcaddr4 = &a4;
} else if (inet_pton(AF_INET6, value, &in6) == 1) {
if (srcaddr6 != NULL)
if (srcaddr6 != NULL) {
fatal("Only one local address per family "
"can be specified\n");
}
isc_sockaddr_fromin6(&a6, &in6, srcport);
srcaddr6 = &a6;
} else {
if (hash != NULL)
if (hash != NULL) {
*hash = '#';
}
fatal("Invalid address %s", value);
}
if (hash != NULL)
if (hash != NULL) {
*hash = '#';
}
return (value_from_next);
case 'c':
if (classset)
if (classset) {
warn("extra query class");
}
*open_type_class = false;
tr.base = value;
tr.length = strlen(value);
result = dns_rdataclass_fromtext(&rdclass,
(isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
classset = true;
else if (rdclass != dns_rdataclass_in)
} else if (rdclass != dns_rdataclass_in) {
warn("ignoring non-IN query class");
else
} else {
warn("ignoring invalid class");
}
return (value_from_next);
case 'd':
result = parse_uint(&num, value, 99, "debug level");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse debug level");
}
loglevel = num;
return (value_from_next);
case 'p':
@ -1426,15 +1471,18 @@ dash_option(char *option, char *next, bool *open_type_class)
result = dns_rdatatype_fromtext(&rdtype,
(isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS) {
if (typeset)
if (typeset) {
warn("extra query type");
}
if (rdtype == dns_rdatatype_ixfr ||
rdtype == dns_rdatatype_axfr)
rdtype == dns_rdatatype_axfr) {
fatal("Transfer not supported");
}
qtype = rdtype;
typeset = true;
} else
} else {
warn("ignoring invalid type");
}
return (value_from_next);
case 'x':
result = get_reverse(textname, sizeof(textname), value, false);
@ -1444,8 +1492,9 @@ dash_option(char *option, char *next, bool *open_type_class)
warn("extra query name");
}
curqname = isc_mem_strdup(mctx, textname);
if (typeset)
if (typeset) {
warn("extra query type");
}
qtype = dns_rdatatype_ptr;
typeset = true;
} else {
@ -1566,11 +1615,13 @@ parse_args(int argc, char **argv)
result = dns_rdatatype_fromtext(
&rdtype, (isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS) {
if (typeset)
if (typeset) {
warn("extra query type");
}
if (rdtype == dns_rdatatype_ixfr ||
rdtype == dns_rdatatype_axfr)
rdtype == dns_rdatatype_axfr) {
fatal("Transfer not supported");
}
qtype = rdtype;
typeset = true;
continue;
@ -1578,11 +1629,13 @@ parse_args(int argc, char **argv)
result = dns_rdataclass_fromtext(
&rdclass, (isc_textregion_t *)&tr);
if (result == ISC_R_SUCCESS) {
if (classset)
if (classset) {
warn("extra query class");
else if (rdclass != dns_rdataclass_in)
} else if (rdclass !=
dns_rdataclass_in) {
warn("ignoring non-IN "
"query class");
}
continue;
}
}
@ -1597,23 +1650,27 @@ parse_args(int argc, char **argv)
* If no qname or qtype specified, search for root/NS
* If no qtype specified, use A
*/
if (!typeset)
if (!typeset) {
qtype = dns_rdatatype_a;
}
if (curqname == NULL) {
qname = isc_mem_strdup(mctx, ".");
if (!typeset)
if (!typeset) {
qtype = dns_rdatatype_ns;
} else
}
} else {
qname = curqname;
}
}
static isc_result_t
append_str(const char *text, int len, char **p, char *end)
{
if (len > end - *p)
if (len > end - *p) {
return (ISC_R_NOSPACE);
}
memmove(*p, text, len);
*p += len;
return (ISC_R_SUCCESS);
@ -1627,14 +1684,17 @@ reverse_octets(const char *in, char **p, char *end)
if (dot != NULL) {
isc_result_t result;
result = reverse_octets(dot + 1, p, end);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
result = append_str(".", 1, p, end);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
len = (int)(dot - in);
} else
} else {
len = strlen(in);
}
return (append_str(in, len, p, end));
}
@ -1655,8 +1715,9 @@ get_reverse(char *reverse, size_t len, char *value, bool strict)
name = dns_fixedname_initname(&fname);
result = dns_byaddr_createptrname(&addr, options, name);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
dns_name_format(name, reverse, (unsigned int)len);
return (ISC_R_SUCCESS);
} else {
@ -1670,14 +1731,17 @@ get_reverse(char *reverse, size_t len, char *value, bool strict)
*/
char *p = reverse;
char *end = reverse + len;
if (strict && inet_pton(AF_INET, value, &addr.type.in) != 1)
if (strict && inet_pton(AF_INET, value, &addr.type.in) != 1) {
return (DNS_R_BADDOTTEDQUAD);
}
result = reverse_octets(value, &p, end);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
result = append_str(".in-addr.arpa.", 15, &p, end);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
return (ISC_R_SUCCESS);
}
}
@ -1700,7 +1764,7 @@ main(int argc, char *argv[])
dns_master_style_t *style = NULL;
#ifndef WIN32
struct sigaction sa;
#endif
#endif /* ifndef WIN32 */
progname = argv[0];
preparse_args(argc, argv);
@ -1710,8 +1774,9 @@ main(int argc, char *argv[])
isc_lib_register();
result = dns_lib_init();
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_lib_init failed: %d", result);
}
isc_mem_create(&mctx);
@ -1732,9 +1797,10 @@ main(int argc, char *argv[])
/* Unblock SIGINT if it's been blocked by isc_app_ctxstart() */
memset(&sa, 0, sizeof(sa));
sa.sa_handler = SIG_DFL;
if (sigfillset(&sa.sa_mask) != 0 || sigaction(SIGINT, &sa, NULL) < 0)
if (sigfillset(&sa.sa_mask) != 0 || sigaction(SIGINT, &sa, NULL) < 0) {
fatal("Couldn't set up signal handler");
#endif
}
#endif /* ifndef WIN32 */
/* Create client */
clopt = DNS_CLIENTCREATEOPT_USECACHE;
@ -1747,10 +1813,11 @@ main(int argc, char *argv[])
}
/* Set the nameserver */
if (server != NULL)
if (server != NULL) {
addserver(client);
else
} else {
findserver(client);
}
CHECK(setup_dnsseckeys(client));
@ -1795,34 +1862,45 @@ main(int argc, char *argv[])
rdataset != NULL;
rdataset = ISC_LIST_NEXT(rdataset, link)) {
result = printdata(rdataset, response_name, style);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
delv_log(ISC_LOG_ERROR, "print data failed");
}
}
}
dns_client_freeresanswer(client, &namelist);
cleanup:
if (trust_anchor != NULL)
if (trust_anchor != NULL) {
isc_mem_free(mctx, trust_anchor);
if (anchorfile != NULL)
}
if (anchorfile != NULL) {
isc_mem_free(mctx, anchorfile);
if (qname != NULL)
}
if (qname != NULL) {
isc_mem_free(mctx, qname);
if (style != NULL)
}
if (style != NULL) {
dns_master_styledestroy(&style, mctx);
if (client != NULL)
}
if (client != NULL) {
dns_client_destroy(&client);
if (taskmgr != NULL)
}
if (taskmgr != NULL) {
isc_taskmgr_destroy(&taskmgr);
if (timermgr != NULL)
}
if (timermgr != NULL) {
isc_timermgr_destroy(&timermgr);
if (socketmgr != NULL)
}
if (socketmgr != NULL) {
isc_socketmgr_destroy(&socketmgr);
if (actx != NULL)
}
if (actx != NULL) {
isc_appctx_destroy(&actx);
if (lctx != NULL)
}
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
isc_mem_detach(&mctx);
dns_lib_shutdown();

View file

@ -45,7 +45,7 @@
#define ADD_STRING(b, s) \
{ \
if (strlen(s) >= isc_buffer_availablelength(b)) \
return (ISC_R_NOSPACE); \
return ((ISC_R_NOSPACE)); \
else \
isc_buffer_putstr(b, s); \
}
@ -109,7 +109,7 @@ usage(void)
{
fprintf(stderr, "Press <Help> for complete list of options\n");
}
#else
#else /* if TARGET_OS_IPHONE */
ISC_PLATFORM_NORETURN_PRE static void
usage(void) ISC_PLATFORM_NORETURN_POST;
@ -122,7 +122,7 @@ usage(void)
stderr);
exit(1);
}
#endif
#endif /* if TARGET_OS_IPHONE */
/*% version */
static void
@ -228,7 +228,7 @@ help(void)
"[default=on on tty])\n"
" +[no]idnout (Convert IDN response "
"[default=on on tty])\n"
#endif
#endif /* ifdef HAVE_LIBIDN2 */
" +[no]ignore (Don't revert to TCP for "
"TC responses.)\n"
" +[no]keepalive (Request EDNS TCP "
@ -322,9 +322,9 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query)
struct tm tmnow;
#ifdef WIN32
wchar_t time_str[100];
#else
#else /* ifdef WIN32 */
char time_str[100];
#endif
#endif /* ifdef WIN32 */
char fromtext[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_format(from, fromtext, sizeof(fromtext));
@ -335,17 +335,18 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query)
if (query->lookup->stats) {
diff = isc_time_microdiff(&query->time_recv, &query->time_sent);
if (query->lookup->use_usec)
if (query->lookup->use_usec) {
printf(";; Query time: %ld usec\n", (long)diff);
else
} else {
printf(";; Query time: %ld msec\n", (long)diff / 1000);
}
printf(";; SERVER: %s(%s)\n", fromtext, query->servname);
time(&tnow);
#if !defined(WIN32)
(void)localtime_r(&tnow, &tmnow);
#else
#else /* if !defined(WIN32) */
tmnow = *localtime(&tnow);
#endif
#endif /* if !defined(WIN32) */
#ifdef WIN32
/*
@ -356,12 +357,12 @@ received(unsigned int bytes, isc_sockaddr_t *from, dig_query_t *query)
L"%a %b %d %H:%M:%S %Z %Y", &tmnow) > 0U) {
printf(";; WHEN: %ls\n", time_str);
}
#else
#else /* ifdef WIN32 */
if (strftime(time_str, sizeof(time_str),
"%a %b %d %H:%M:%S %Z %Y", &tmnow) > 0U) {
printf(";; WHEN: %s\n", time_str);
}
#endif
#endif /* ifdef WIN32 */
if (query->lookup->doing_xfr) {
printf(";; XFR size: %u records (messages %u, "
"bytes %" PRIu64 ")\n",
@ -423,20 +424,25 @@ say_message(dns_rdata_t *rdata, dig_query_t *query, isc_buffer_t *buf)
if (query->lookup->trace || query->lookup->ns_search_only) {
result = dns_rdatatype_totext(rdata->type, buf);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
ADD_STRING(buf, " ");
}
/* Turn on rrcomments if explicitly enabled */
if (query->lookup->rrcomments > 0)
if (query->lookup->rrcomments > 0) {
styleflags |= DNS_STYLEFLAG_RRCOMMENT;
if (query->lookup->nocrypto)
}
if (query->lookup->nocrypto) {
styleflags |= DNS_STYLEFLAG_NOCRYPTO;
if (query->lookup->print_unknown_format)
}
if (query->lookup->print_unknown_format) {
styleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT;
if (query->lookup->expandaaaa)
}
if (query->lookup->expandaaaa) {
styleflags |= DNS_STYLEFLAG_EXPANDAAAA;
}
result = dns_rdata_tofmttext(rdata, NULL, styleflags, 0, splitwidth,
" ", buf);
if (result == ISC_R_NOSPACE) {
@ -477,10 +483,11 @@ short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf,
dns_name_init(&empty_name, NULL);
result = dns_message_firstname(msg, DNS_SECTION_ANSWER);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
return (result);
}
for (;;) {
name = NULL;
@ -492,18 +499,20 @@ short_answer(dns_message_t *msg, dns_messagetextflag_t flags, isc_buffer_t *buf,
while (loopresult == ISC_R_SUCCESS) {
dns_rdataset_current(rdataset, &rdata);
result = say_message(&rdata, query, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
return (result);
}
check_result(result, "say_message");
loopresult = dns_rdataset_next(rdataset);
dns_rdata_reset(&rdata);
}
}
result = dns_message_nextname(msg, DNS_SECTION_ANSWER);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
break;
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
return (result);
}
}
return (ISC_R_SUCCESS);
@ -523,8 +532,9 @@ isdotlocal(dns_message_t *msg)
result = dns_message_nextname(msg, DNS_SECTION_QUESTION)) {
dns_name_t *name = NULL;
dns_message_currentname(msg, DNS_SECTION_QUESTION, &name);
if (dns_name_issubdomain(name, &local))
if (dns_name_issubdomain(name, &local)) {
return (true);
}
}
return (false);
}
@ -619,11 +629,13 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
}
if (query->lookup->onesoa &&
query->lookup->rdtype == dns_rdatatype_axfr)
query->lookup->rdtype == dns_rdatatype_axfr) {
flags |= (query->msg_count == 0) ? DNS_MESSAGETEXTFLAG_ONESOA
: DNS_MESSAGETEXTFLAG_OMITSOA;
if (!query->lookup->comments)
}
if (!query->lookup->comments) {
flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS;
}
isc_buffer_allocate(mctx, &buf, len);
@ -742,22 +754,30 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
opcodetext[msg->opcode],
rcode_totext(msg->rcode), msg->id);
printf(";; flags:");
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0)
if ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) {
printf(" qr");
if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0)
}
if ((msg->flags & DNS_MESSAGEFLAG_AA) != 0) {
printf(" aa");
if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0)
}
if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0) {
printf(" tc");
if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0)
}
if ((msg->flags & DNS_MESSAGEFLAG_RD) != 0) {
printf(" rd");
if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0)
}
if ((msg->flags & DNS_MESSAGEFLAG_RA) != 0) {
printf(" ra");
if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0)
}
if ((msg->flags & DNS_MESSAGEFLAG_AD) != 0) {
printf(" ad");
if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0)
}
if ((msg->flags & DNS_MESSAGEFLAG_CD) != 0) {
printf(" cd");
if ((msg->flags & 0x0040U) != 0)
}
if ((msg->flags & 0x0040U) != 0) {
printf("; MBZ: 0x4");
}
printf("; QUERY: %u, ANSWER: %u, "
"AUTHORITY: %u, ADDITIONAL: %u\n",
@ -768,22 +788,25 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
if (msg != query->lookup->sendmsg &&
(msg->flags & DNS_MESSAGEFLAG_RD) != 0 &&
(msg->flags & DNS_MESSAGEFLAG_RA) == 0)
(msg->flags & DNS_MESSAGEFLAG_RA) == 0) {
printf(";; WARNING: recursion requested "
"but not available\n");
}
}
if (msg != query->lookup->sendmsg &&
query->lookup->edns != -1 && msg->opt == NULL &&
(msg->rcode == dns_rcode_formerr ||
msg->rcode == dns_rcode_notimp))
msg->rcode == dns_rcode_notimp)) {
printf("\n;; WARNING: EDNS query returned status "
"%s - retry with '%s+noedns'\n",
rcode_totext(msg->rcode),
query->lookup->dnssec ? "+nodnssec " : "");
if (msg != query->lookup->sendmsg && extrabytes != 0U)
}
if (msg != query->lookup->sendmsg && extrabytes != 0U) {
printf(";; WARNING: Message has %u extra byte%s at "
"end\n",
extrabytes, extrabytes != 0 ? "s" : "");
}
}
repopulate_buffer:
@ -805,8 +828,9 @@ repopulate_buffer:
if (!short_form) {
result = dns_message_sectiontotext(
msg, DNS_SECTION_QUESTION, style, flags, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "dns_message_sectiontotext");
}
}
@ -814,13 +838,15 @@ repopulate_buffer:
if (!short_form) {
result = dns_message_sectiontotext(
msg, DNS_SECTION_ANSWER, style, flags, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "dns_message_sectiontotext");
} else {
result = short_answer(msg, flags, buf, query);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "short_answer");
}
}
@ -828,8 +854,9 @@ repopulate_buffer:
if (!short_form) {
result = dns_message_sectiontotext(
msg, DNS_SECTION_AUTHORITY, style, flags, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "dns_message_sectiontotext");
}
}
@ -837,8 +864,9 @@ repopulate_buffer:
if (!short_form) {
result = dns_message_sectiontotext(
msg, DNS_SECTION_ADDITIONAL, style, flags, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "dns_message_sectiontotext");
/*
* Only print the signature on the first record.
@ -847,15 +875,17 @@ repopulate_buffer:
result = dns_message_pseudosectiontotext(
msg, DNS_PSEUDOSECTION_TSIG, style,
flags, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "dns_message_"
"pseudosectiontotext");
result = dns_message_pseudosectiontotext(
msg, DNS_PSEUDOSECTION_SIG0, style,
flags, buf);
if (result == ISC_R_NOSPACE)
if (result == ISC_R_NOSPACE) {
goto buftoosmall;
}
check_result(result, "dns_message_"
"pseudosectiontotext");
}
@ -870,8 +900,9 @@ repopulate_buffer:
(char *)isc_buffer_base(buf));
isc_buffer_free(&buf);
if (style != NULL)
if (style != NULL) {
dns_master_styledestroy(&style, mctx);
}
return (result);
}
@ -1013,10 +1044,12 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 'u': /* bufsize */
FULLCHECK("bufsize");
if (value == NULL)
if (value == NULL) {
goto need_value;
if (!state)
}
if (!state) {
goto invalid_option;
}
result = parse_uint(&num, value, COMMSIZE,
"buffer size");
if (result != ISC_R_SUCCESS) {
@ -1056,13 +1089,15 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
case 'm':
FULLCHECK("comments");
lookup->comments = state;
if (lookup == default_lookup)
if (lookup == default_lookup) {
pluscomm = state;
}
break;
case 'o': /* cookie */
FULLCHECK("cookie");
if (state && lookup->edns == -1)
if (state && lookup->edns == -1) {
lookup->edns = 0;
}
lookup->sendcookie = state;
if (value != NULL) {
n = strlcpy(hexcookie, value,
@ -1072,8 +1107,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
goto exit_or_usage;
}
lookup->cookie = hexcookie;
} else
} else {
lookup->cookie = NULL;
}
break;
default:
goto invalid_option;
@ -1098,18 +1134,22 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
case 'n': /* dnssec */
FULLCHECK("dnssec");
dnssec:
if (state && lookup->edns == -1)
if (state && lookup->edns == -1) {
lookup->edns = 0;
}
lookup->dnssec = state;
break;
case 'o': /* domain ... but treat "do" as synonym for dnssec */
if (cmd[2] == '\0')
if (cmd[2] == '\0') {
goto dnssec;
}
FULLCHECK("domain");
if (value == NULL)
if (value == NULL) {
goto need_value;
if (!state)
}
if (!state) {
goto invalid_option;
}
strlcpy(domainopt, value, sizeof(domainopt));
break;
case 's': /* dscp */
@ -1118,8 +1158,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
lookup->dscp = -1;
break;
}
if (value == NULL)
if (value == NULL) {
goto need_value;
}
result = parse_uint(&num, value, 0x3f, "DSCP");
if (result != ISC_R_SUCCESS) {
warn("Couldn't parse DSCP value");
@ -1265,18 +1306,18 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
#ifndef HAVE_LIBIDN2
fprintf(stderr, ";; IDN input support"
" not enabled\n");
#else
#else /* ifndef HAVE_LIBIDN2 */
lookup->idnin = state;
#endif
#endif /* ifndef HAVE_LIBIDN2 */
break;
case 'o':
FULLCHECK("idnout");
#ifndef HAVE_LIBIDN2
fprintf(stderr, ";; IDN output support"
" not enabled\n");
#else
#else /* ifndef HAVE_LIBIDN2 */
lookup->idnout = state;
#endif
#endif /* ifndef HAVE_LIBIDN2 */
break;
default:
goto invalid_option;
@ -1344,10 +1385,12 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
switch (cmd[1]) {
case 'd': /* ndots */
FULLCHECK("ndots");
if (value == NULL)
if (value == NULL) {
goto need_value;
if (!state)
}
if (!state) {
goto invalid_option;
}
result = parse_uint(&num, value, MAXNDOTS, "ndots");
if (result != ISC_R_SUCCESS) {
warn("Couldn't parse ndots");
@ -1359,8 +1402,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
switch (cmd[2]) {
case 'i': /* nsid */
FULLCHECK("nsid");
if (state && lookup->edns == -1)
if (state && lookup->edns == -1) {
lookup->edns = 0;
}
lookup->nsid = state;
break;
case 's': /* nssearch */
@ -1401,13 +1445,15 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
lookup->opcode = 0; /* default - query */
break;
}
if (value == NULL)
if (value == NULL) {
goto need_value;
}
for (num = 0;
num < sizeof(opcodetext) / sizeof(opcodetext[0]);
num++) {
if (strcasecmp(opcodetext[num], value) == 0)
if (strcasecmp(opcodetext[num], value) == 0) {
break;
}
}
if (num < 16) {
lookup->opcode = (dns_opcode_t)num;
@ -1426,10 +1472,12 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 'p':
FULLCHECK("padding");
if (state && lookup->edns == -1)
if (state && lookup->edns == -1) {
lookup->edns = 0;
if (value == NULL)
}
if (value == NULL) {
goto need_value;
}
result = parse_uint(&num, value, 512, "padding");
if (result != ISC_R_SUCCESS) {
warn("Couldn't parse padding");
@ -1446,8 +1494,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
case 'u': /* question */
FULLCHECK("question");
lookup->section_question = state;
if (lookup == default_lookup)
if (lookup == default_lookup) {
plusquest = state;
}
break;
default:
goto invalid_option;
@ -1471,10 +1520,12 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 't': /* retry / retries */
FULLCHECK2("retry", "retries");
if (value == NULL)
if (value == NULL) {
goto need_value;
if (!state)
}
if (!state) {
goto invalid_option;
}
result = parse_uint(&lookup->retries, value,
MAXTRIES - 1, "retries");
if (result != ISC_R_SUCCESS) {
@ -1504,8 +1555,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
}
break;
case 'h':
if (cmd[2] != 'o')
if (cmd[2] != 'o') {
goto invalid_option;
}
switch (cmd[3]) {
case 'r': /* short */
FULLCHECK("short");
@ -1538,13 +1590,15 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 'p': /* split */
FULLCHECK("split");
if (value != NULL && !state)
if (value != NULL && !state) {
goto invalid_option;
}
if (!state) {
splitwidth = 0;
break;
} else if (value == NULL)
} else if (value == NULL) {
break;
}
result = parse_uint(&splitwidth, value, 1023, "split");
if ((splitwidth % 4) != 0U) {
@ -1562,8 +1616,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
* using the default width but incorrect in this
* case, so we correct for it
*/
if (splitwidth)
if (splitwidth) {
splitwidth += 3;
}
if (result != ISC_R_SUCCESS) {
warn("Couldn't parse split");
goto exit_or_usage;
@ -1575,8 +1630,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 'u': /* subnet */
FULLCHECK("subnet");
if (state && value == NULL)
if (state && value == NULL) {
goto need_value;
}
if (!state) {
if (lookup->ecs_addr != NULL) {
isc_mem_free(mctx, lookup->ecs_addr);
@ -1584,8 +1640,9 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
}
break;
}
if (lookup->edns == -1)
if (lookup->edns == -1) {
lookup->edns = 0;
}
if (lookup->ecs_addr != NULL) {
isc_mem_free(mctx, lookup->ecs_addr);
lookup->ecs_addr = NULL;
@ -1621,18 +1678,21 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 'i': /* timeout */
FULLCHECK("timeout");
if (value == NULL)
if (value == NULL) {
goto need_value;
if (!state)
}
if (!state) {
goto invalid_option;
}
result = parse_uint(&timeout, value, MAXTIMEOUT,
"timeout");
if (result != ISC_R_SUCCESS) {
warn("Couldn't parse timeout");
goto exit_or_usage;
}
if (timeout == 0)
if (timeout == 0) {
timeout = 1;
}
break;
case 'o':
FULLCHECK("topdown");
@ -1660,18 +1720,21 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
break;
case 'i': /* tries */
FULLCHECK("tries");
if (value == NULL)
if (value == NULL) {
goto need_value;
if (!state)
}
if (!state) {
goto invalid_option;
}
result = parse_uint(&lookup->retries, value,
MAXTRIES, "tries");
if (result != ISC_R_SUCCESS) {
warn("Couldn't parse tries");
goto exit_or_usage;
}
if (lookup->retries == 0)
if (lookup->retries == 0) {
lookup->retries = 1;
}
break;
case 'u': /* trusted-key */
FULLCHECK("trusted-key");
@ -1754,7 +1817,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
need_value:
#if TARGET_OS_IPHONE
exit_or_usage:
#endif
#endif /* if TARGET_OS_IPHONE */
fprintf(stderr, "Invalid option: +%s\n", option);
usage();
}
@ -1763,7 +1826,7 @@ plus_option(char *option, bool is_batchfile, dig_lookup_t *lookup)
#if !TARGET_OS_IPHONE
exit_or_usage:
digexit();
#endif
#endif /* if !TARGET_OS_IPHONE */
}
/*%
@ -1824,8 +1887,9 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
FULLCHECK("debug");
debugging = true;
return (false);
} else
} else {
debugging = true;
}
break;
case 'h':
help();
@ -1852,10 +1916,11 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
exit(0);
break;
}
if (strlen(option) > 1U)
if (strlen(option) > 1U) {
option = &option[1];
else
} else {
return (false);
}
}
opt = option[0];
if (strlen(option) > 1U) {
@ -1865,20 +1930,23 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
value_from_next = true;
value = next;
}
if (value == NULL)
if (value == NULL) {
goto invalid_option;
}
switch (opt) {
case 'b':
hash = strchr(value, '#');
if (hash != NULL) {
result = parse_uint(&num, hash + 1, MAXPORT,
"port number");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse port number");
}
srcport = num;
*hash = '\0';
} else
} else {
srcport = 0;
}
if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) {
isc_sockaddr_fromin6(&bind_address, &in6, srcport);
isc_net_disableipv4();
@ -1886,12 +1954,14 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
isc_sockaddr_fromin(&bind_address, &in4, srcport);
isc_net_disableipv6();
} else {
if (hash != NULL)
if (hash != NULL) {
*hash = '#';
}
fatal("invalid address %s", value);
}
if (hash != NULL)
if (hash != NULL) {
*hash = '#';
}
specified_source = true;
return (value_from_next);
case 'c':
@ -1906,11 +1976,12 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
if (result == ISC_R_SUCCESS) {
(*lookup)->rdclass = rdclass;
(*lookup)->rdclassset = true;
} else
} else {
fprintf(stderr,
";; Warning, ignoring "
"invalid class %s\n",
value);
}
return (value_from_next);
case 'f':
atomic_store(&batchname, (uintptr_t)value);
@ -1920,14 +1991,16 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
return (value_from_next);
case 'p':
result = parse_uint(&num, value, MAXPORT, "port number");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse port number");
}
port = num;
return (value_from_next);
case 'q':
if (!config_only) {
if (*need_clone)
if (*need_clone) {
(*lookup) = clone_lookup(default_lookup, true);
}
*need_clone = true;
strlcpy((*lookup)->textname, value,
sizeof((*lookup)->textname));
@ -1968,42 +2041,47 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
(*lookup)->rdtypeset = true;
result = parse_uint(&serial, &value[5],
MAXSERIAL, "serial number");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse serial number");
}
(*lookup)->ixfr_serial = serial;
(*lookup)->section_question = plusquest;
(*lookup)->comments = pluscomm;
if (!(*lookup)->tcp_mode_set)
if (!(*lookup)->tcp_mode_set) {
(*lookup)->tcp_mode = true;
}
} else {
(*lookup)->rdtype = rdtype;
if (!config_only)
if (!config_only) {
(*lookup)->rdtypeset = true;
}
if (rdtype == dns_rdatatype_axfr) {
(*lookup)->section_question = plusquest;
(*lookup)->comments = pluscomm;
} else if (rdtype == dns_rdatatype_any) {
if (!(*lookup)->tcp_mode_set)
if (!(*lookup)->tcp_mode_set) {
(*lookup)->tcp_mode = true;
}
}
(*lookup)->ixfr_serial = false;
}
} else
} else {
fprintf(stderr,
";; Warning, ignoring "
"invalid type %s\n",
value);
}
return (value_from_next);
case 'y':
if ((ptr = strtok_r(value, ":", &last)) == NULL) {
usage();
}
if ((ptr2 = strtok_r(NULL, ":", &last)) == NULL) { /* name or
secret */
* secret */
usage();
}
if ((ptr3 = strtok_r(NULL, ":", &last)) != NULL) { /* secret or
NULL */
* NULL */
parse_hmac(ptr);
ptr = ptr2;
ptr2 = ptr3;
@ -2016,8 +2094,9 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
strlcpy(keysecret, ptr2, sizeof(keysecret));
return (value_from_next);
case 'x':
if (*need_clone)
if (*need_clone) {
*lookup = clone_lookup(default_lookup, true);
}
*need_clone = true;
if (get_reverse(textname, sizeof(textname), value, false) ==
ISC_R_SUCCESS) {
@ -2026,10 +2105,12 @@ dash_option(char *option, char *next, dig_lookup_t **lookup,
debug("looking up %s", (*lookup)->textname);
(*lookup)->trace_root =
((*lookup)->trace || (*lookup)->ns_search_only);
if (!(*lookup)->rdtypeset)
if (!(*lookup)->rdtypeset) {
(*lookup)->rdtype = dns_rdatatype_ptr;
if (!(*lookup)->rdclassset)
}
if (!(*lookup)->rdclassset) {
(*lookup)->rdclass = dns_rdataclass_in;
}
(*lookup)->new_search = true;
if (*firstarg) {
printgreeting(argc, argv, *lookup);
@ -2069,8 +2150,9 @@ preparse_args(int argc, char **argv)
rc = argc;
rv = argv;
for (rc--, rv++; rc > 0; rc--, rv++) {
if (rv[0][0] != '-')
if (rv[0][0] != '-') {
continue;
}
option = &rv[0][1];
while (strpbrk(option, single_dash_opts) == &option[0]) {
switch (option[0]) {
@ -2092,13 +2174,15 @@ preparse_args(int argc, char **argv)
digrc = false;
break;
case '4':
if (ipv6only)
if (ipv6only) {
fatal("only one of -4 and -6 allowed");
}
ipv4only = true;
break;
case '6':
if (ipv4only)
if (ipv4only) {
fatal("only one of -4 and -6 allowed");
}
ipv6only = true;
break;
}
@ -2116,8 +2200,9 @@ preparse_args(int argc, char **argv)
/* Dash value is next argument so we need to skip it. */
rc--, rv++;
/* Handle missing argument */
if (rc == 0)
if (rc == 0) {
break;
}
}
}
@ -2155,7 +2240,7 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
#ifndef NOPOSIX
char *homedir;
char rcfile[PATH_MAX];
#endif
#endif /* ifndef NOPOSIX */
bool need_clone = true;
/*
@ -2204,7 +2289,7 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
}
fclose(batchfp);
}
#endif
#endif /* ifndef NOPOSIX */
}
if (is_batchfile && !config_only) {
@ -2219,8 +2304,9 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
rv = argv;
for (rc--, rv++; rc > 0; rc--, rv++) {
debug("main parsing %s", rv[0]);
if (strncmp(rv[0], "%", 1) == 0)
if (strncmp(rv[0], "%", 1) == 0) {
break;
}
if (rv[0][0] == '@') {
if (is_batchfile && !config_only) {
addresscount = getaddresses(lookup, &rv[0][1],
@ -2232,18 +2318,20 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
"lookup\n",
&rv[0][1],
isc_result_totext(result));
if (ISC_LINK_LINKED(lookup, link))
if (ISC_LINK_LINKED(lookup, link)) {
ISC_LIST_DEQUEUE(lookup_list,
lookup, link);
}
destroy_lookup(lookup);
return;
}
} else {
addresscount =
getaddresses(lookup, &rv[0][1], NULL);
if (addresscount == 0)
if (addresscount == 0) {
fatal("no valid addresses for '%s'\n",
&rv[0][1]);
}
}
} else if (rv[0][0] == '+') {
plus_option(&rv[0][1], is_batchfile, lookup);
@ -2305,15 +2393,17 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
MAXSERIAL,
"serial "
"number");
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Couldn't parse "
"serial number");
}
lookup->ixfr_serial = serial;
lookup->section_question =
plusquest;
lookup->comments = pluscomm;
if (!lookup->tcp_mode_set)
if (!lookup->tcp_mode_set) {
lookup->tcp_mode = true;
}
} else {
lookup->rdtype = rdtype;
lookup->rdtypeset = true;
@ -2326,8 +2416,9 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
}
if (rdtype ==
dns_rdatatype_any &&
!lookup->tcp_mode_set)
!lookup->tcp_mode_set) {
lookup->tcp_mode = true;
}
lookup->ixfr_serial = false;
}
continue;
@ -2347,9 +2438,10 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
}
if (!config_only) {
if (need_clone)
if (need_clone) {
lookup = clone_lookup(default_lookup,
true);
}
need_clone = true;
strlcpy(lookup->textname, rv[0],
sizeof(lookup->textname));
@ -2381,8 +2473,9 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
}
if (batchfp == NULL) {
perror(filename);
if (exitcode < 8)
if (exitcode < 8) {
exitcode = 8;
}
fatal("couldn't open specified batch file");
}
/* XXX Remove code dup from shutdown code */
@ -2390,8 +2483,9 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
if (fgets(batchline, sizeof(batchline), batchfp) != 0) {
debug("batch line %s", batchline);
if (batchline[0] == '\r' || batchline[0] == '\n' ||
batchline[0] == '#' || batchline[0] == ';')
batchline[0] == '#' || batchline[0] == ';') {
goto next_line;
}
bargc = split_batchline(batchline, bargv, 14,
"batch argv");
bargv[0] = argv[0];
@ -2405,8 +2499,9 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
* If no lookup specified, search for root
*/
if ((lookup_list.head == NULL) && !config_only) {
if (need_clone)
if (need_clone) {
lookup = clone_lookup(default_lookup, true);
}
need_clone = true;
lookup->trace_root = (lookup->trace || lookup->ns_search_only);
lookup->new_search = true;
@ -2419,8 +2514,9 @@ parse_args(bool is_batchfile, bool config_only, int argc, char **argv)
}
ISC_LIST_APPEND(lookup_list, lookup, link);
}
if (!need_clone)
if (!need_clone) {
destroy_lookup(lookup);
}
}
/*
@ -2444,8 +2540,9 @@ query_finished(void)
if (feof(batchfp)) {
atomic_store(&batchname, 0);
isc_app_shutdown();
if (batchfp != stdin)
if (batchfp != stdin) {
fclose(batchfp);
}
return;
}
@ -2457,8 +2554,9 @@ query_finished(void)
start_lookup();
} else {
atomic_store(&batchname, 0);
if (batchfp != stdin)
if (batchfp != stdin) {
fclose(batchfp);
}
isc_app_shutdown();
return;
}
@ -2562,10 +2660,11 @@ dig_query_setup(bool is_batchfile, bool config_only, int argc, char **argv)
debug("dig_query_setup");
parse_args(is_batchfile, config_only, argc, argv);
if (keyfile[0] != 0)
if (keyfile[0] != 0) {
setup_file_key();
else if (keysecret[0] != 0)
} else if (keysecret[0] != 0) {
setup_text_key();
}
if (domainopt[0] != '\0') {
set_search_domain(domainopt);
usesearch = true;

File diff suppressed because it is too large Load diff

View file

@ -18,7 +18,7 @@
#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif
#endif /* ifdef HAVE_LOCALE_H */
#include <isc/app.h>
#include <isc/commandline.h>
@ -96,9 +96,10 @@ rcode_totext(dns_rcode_t rcode)
if (rcode >= (sizeof(rcodetext) / sizeof(rcodetext[0]))) {
snprintf(buf, sizeof(buf), "?%u", rcode);
totext.deconsttext = buf;
} else
} else {
totext.consttext = rcodetext[rcode];
return totext.deconsttext;
}
return (totext.deconsttext);
}
ISC_PLATFORM_NORETURN_PRE static void
@ -162,8 +163,9 @@ trying(char *frm, dig_lookup_t *lookup)
{
UNUSED(lookup);
if (!short_form)
if (!short_form) {
printf("Trying \"%s\"\n", frm);
}
}
static void
@ -213,21 +215,24 @@ printsection(dns_message_t *msg, dns_section_t sectionid,
bool first;
bool no_rdata;
if (sectionid == DNS_SECTION_QUESTION)
if (sectionid == DNS_SECTION_QUESTION) {
no_rdata = true;
else
} else {
no_rdata = false;
}
if (headers)
if (headers) {
printf(";; %s SECTION:\n", section_name);
}
dns_name_init(&empty_name, NULL);
result = dns_message_firstname(msg, sectionid);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
return (result);
}
for (;;) {
name = NULL;
@ -247,27 +252,30 @@ printsection(dns_message_t *msg, dns_section_t sectionid,
(rdataset->type == dns_rdatatype_a ||
rdataset->type == dns_rdatatype_aaaa ||
rdataset->type == dns_rdatatype_ns ||
rdataset->type == dns_rdatatype_ptr))))
rdataset->type == dns_rdatatype_ptr)))) {
continue;
}
if (list_almost_all &&
(rdataset->type == dns_rdatatype_rrsig ||
rdataset->type == dns_rdatatype_nsec ||
rdataset->type == dns_rdatatype_nsec3))
rdataset->type == dns_rdatatype_nsec3)) {
continue;
}
if (!short_form) {
result = dns_rdataset_totext(rdataset,
print_name, false,
no_rdata, &target);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
#ifdef USEINITALWS
if (first) {
print_name = &empty_name;
first = false;
}
#else
#else /* ifdef USEINITALWS */
UNUSED(first); /* Shut up compiler. */
#endif
#endif /* ifdef USEINITALWS */
} else {
loopresult = dns_rdataset_first(rdataset);
while (loopresult == ISC_R_SUCCESS) {
@ -302,17 +310,19 @@ printsection(dns_message_t *msg, dns_section_t sectionid,
}
if (!short_form) {
isc_buffer_usedregion(&target, &r);
if (no_rdata)
if (no_rdata) {
printf(";%.*s", (int)r.length, (char *)r.base);
else
} else {
printf("%.*s", (int)r.length, (char *)r.base);
}
}
result = dns_message_nextname(msg, sectionid);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
break;
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
return (result);
}
}
return (ISC_R_SUCCESS);
@ -328,14 +338,16 @@ printrdata(dns_message_t *msg, dns_rdataset_t *rdataset,
char tbuf[4096];
UNUSED(msg);
if (headers)
if (headers) {
printf(";; %s SECTION:\n", set_name);
}
isc_buffer_init(&target, tbuf, sizeof(tbuf));
result = dns_rdataset_totext(rdataset, owner, false, false, &target);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
isc_buffer_usedregion(&target, &r);
printf("%.*s", (int)r.length, (char *)r.base);
@ -356,8 +368,9 @@ chase_cnamechain(dns_message_t *msg, dns_name_t *qname)
result = dns_message_findname(msg, DNS_SECTION_ANSWER, qname,
dns_rdatatype_cname, 0, NULL,
&rdataset);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return;
}
result = dns_rdataset_first(rdataset);
check_result(result, "dns_rdataset_first");
dns_rdata_reset(&rdata);
@ -403,19 +416,20 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
char namestr[DNS_NAME_FORMATSIZE];
dns_name_format(query->lookup->name, namestr, sizeof(namestr));
if (query->lookup->identify_previous_line)
if (query->lookup->identify_previous_line) {
printf("Nameserver %s:\n\t%s not found: %d(%s)\n",
query->servname,
(msg->rcode != dns_rcode_nxdomain)
? namestr
: query->lookup->textname,
msg->rcode, rcode_totext(msg->rcode));
else
} else {
printf("Host %s not found: %d(%s)\n",
(msg->rcode != dns_rcode_nxdomain)
? namestr
: query->lookup->textname,
msg->rcode, rcode_totext(msg->rcode));
}
return (ISC_R_SUCCESS);
}
@ -493,30 +507,35 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
msg->counts[DNS_SECTION_AUTHORITY],
msg->counts[DNS_SECTION_ADDITIONAL]);
opt = dns_message_getopt(msg);
if (opt != NULL)
if (opt != NULL) {
printf(";; EDNS: version: %u, udp=%u\n",
(unsigned int)((opt->ttl & 0x00ff0000) >> 16),
(unsigned int)opt->rdclass);
}
tsigname = NULL;
tsig = dns_message_gettsig(msg, &tsigname);
if (tsig != NULL)
if (tsig != NULL) {
printf(";; PSEUDOSECTIONS: TSIG\n");
}
}
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_QUESTION]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_QUESTION, "QUESTION",
true, query);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
if (!short_form)
if (!short_form) {
printf("\n");
}
result = printsection(msg, DNS_SECTION_ANSWER, "ANSWER",
!short_form, query);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_AUTHORITY]) &&
@ -524,26 +543,30 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
printf("\n");
result = printsection(msg, DNS_SECTION_AUTHORITY, "AUTHORITY",
true, query);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ADDITIONAL]) &&
!short_form) {
printf("\n");
result = printsection(msg, DNS_SECTION_ADDITIONAL, "ADDITIONAL",
true, query);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if ((tsig != NULL) && !short_form) {
printf("\n");
result = printrdata(msg, tsig, tsigname, "PSEUDOSECTION TSIG",
true);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (!short_form)
if (!short_form) {
printf("\n");
}
if (short_form && !default_lookups &&
ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
@ -576,24 +599,28 @@ pre_parse_args(int argc, char **argv)
switch (c) {
case 'm':
memdebugging = true;
if (strcasecmp("trace", isc_commandline_argument) == 0)
if (strcasecmp("trace", isc_commandline_argument) ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
else if (strcasecmp("record",
isc_commandline_argument) == 0)
} else if (strcasecmp("record",
isc_commandline_argument) == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
else if (strcasecmp("usage",
isc_commandline_argument) == 0)
} else if (strcasecmp("usage",
isc_commandline_argument) == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
}
break;
case '4':
if (ipv6only)
if (ipv6only) {
fatal("only one of -4 and -6 allowed");
}
ipv4only = true;
break;
case '6':
if (ipv4only)
if (ipv4only) {
fatal("only one of -4 and -6 allowed");
}
ipv6only = true;
break;
case 'a':
@ -607,8 +634,9 @@ pre_parse_args(int argc, char **argv)
case 'd':
break;
case 'D':
if (debugging)
if (debugging) {
debugtiming = true;
}
debugging = true;
break;
case 'i':
@ -706,8 +734,9 @@ parse_args(bool is_batchfile, int argc, char **argv)
isc_commandline_argument);
}
if (!lookup->rdtypeset ||
lookup->rdtype != dns_rdatatype_axfr)
lookup->rdtype != dns_rdatatype_axfr) {
lookup->rdtype = rdtype;
}
lookup->rdtypeset = true;
if (rdtype == dns_rdatatype_axfr) {
/* -l -t any -v */
@ -719,10 +748,12 @@ parse_args(bool is_batchfile, int argc, char **argv)
lookup->tcp_mode = true;
list_type = rdtype;
} else if (rdtype == dns_rdatatype_any) {
if (!lookup->tcp_mode_set)
if (!lookup->tcp_mode_set) {
lookup->tcp_mode = true;
} else
}
} else {
list_type = rdtype;
}
list_addresses = false;
default_lookups = false;
break;
@ -744,11 +775,12 @@ parse_args(bool is_batchfile, int argc, char **argv)
break;
case 'A':
list_almost_all = true;
/* FALL THROUGH */
/* FALL THROUGH */
case 'a':
if (!lookup->rdtypeset ||
lookup->rdtype != dns_rdatatype_axfr)
lookup->rdtype != dns_rdatatype_axfr) {
lookup->rdtype = dns_rdatatype_any;
}
list_type = dns_rdatatype_any;
list_addresses = false;
lookup->rdtypeset = true;
@ -773,13 +805,15 @@ parse_args(bool is_batchfile, int argc, char **argv)
break;
case 'W':
timeout = atoi(isc_commandline_argument);
if (timeout < 1)
if (timeout < 1) {
timeout = 1;
}
break;
case 'R':
tries = atoi(isc_commandline_argument) + 1;
if (tries < 2)
if (tries < 2) {
tries = 2;
}
break;
case 'T':
lookup->tcp_mode = true;
@ -821,8 +855,9 @@ parse_args(bool is_batchfile, int argc, char **argv)
lookup->retries = tries;
if (isc_commandline_index >= argc)
if (isc_commandline_index >= argc) {
show_usage();
}
strlcpy(hostname, argv[isc_commandline_index], sizeof(hostname));
@ -830,8 +865,9 @@ parse_args(bool is_batchfile, int argc, char **argv)
set_nameserver(argv[isc_commandline_index + 1]);
debug("server is %s", argv[isc_commandline_index + 1]);
listed_server = true;
} else
} else {
check_ra = true;
}
lookup->pending = false;
if (get_reverse(store, sizeof(store), hostname, true) ==
@ -875,10 +911,11 @@ main(int argc, char **argv)
setup_libs();
setup_system(ipv4only, ipv6only);
parse_args(false, argc, argv);
if (keyfile[0] != 0)
if (keyfile[0] != 0) {
setup_file_key();
else if (keysecret[0] != 0)
} else if (keysecret[0] != 0) {
setup_text_key();
}
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
check_result(result, "isc_app_onrun");
isc_app_run();

View file

@ -34,7 +34,7 @@
#ifdef __APPLE__
#include <TargetConditionals.h>
#endif
#endif /* ifdef __APPLE__ */
#define MXSERV 20
#define MXNAME (DNS_NAME_MAXTEXT + 1)
@ -45,7 +45,7 @@
#ifndef RESOLV_CONF
/*% location of resolve.conf */
#define RESOLV_CONF "/etc/resolv.conf"
#endif
#endif /* ifndef RESOLV_CONF */
/*% output buffer */
#define OUTPUTBUF 32767
/*% Max RR Limit */
@ -89,14 +89,16 @@ typedef struct dig_searchlist dig_searchlist_t;
/*% The dig_lookup structure */
struct dig_lookup {
bool pending, /*%< Pending a successful answer */
waiting_connect, doing_xfr, ns_search_only, /*%< dig +nssearch,
host -C */
waiting_connect, doing_xfr, ns_search_only, /*%< dig
* +nssearch,
* host -C */
identify, /*%< Append an "on server <foo>" message */
identify_previous_line, /*% Prepend a "Nameserver <foo>:"
message, with newline and tab */
* message, with newline and tab */
ignore, recurse, aaonly, adflag, cdflag, raflag, tcflag, zflag,
trace, /*% dig +trace */
trace_root, /*% initial query for either +trace or +nssearch */
trace_root, /*% initial query for either +trace or +nssearch
* */
tcp_mode, tcp_mode_set, comments, stats, section_question,
section_answer, section_authority, section_additional,
servfail_stops, new_search, need_search, done_as_is, besteffort,
@ -105,10 +107,12 @@ struct dig_lookup {
tcp_keepalive, header_only, ednsneg, mapped,
print_unknown_format, multiline, nottl, noclass, onesoa,
use_usec, nocrypto, ttlunits, idnin, idnout, expandaaaa, qr,
accept_reply_unexpected_src; /*% print replies from unexpected
sources. */
char textname[MXNAME]; /*% Name we're going to be looking up */
char cmdline[MXNAME];
accept_reply_unexpected_src; /*% print replies from
* unexpected
* sources. */
char textname[MXNAME]; /*% Name we're going to be
* looking up */
char cmdline[MXNAME];
dns_rdatatype_t rdtype;
dns_rdatatype_t qrdtype;
dns_rdataclass_t rdclass;
@ -411,4 +415,4 @@ dig_shutdown(void);
ISC_LANG_ENDDECLS
#endif
#endif /* ifndef DIG_H */

View file

@ -42,16 +42,16 @@
#include <edit/readline/readline.h>
#if defined(HAVE_EDIT_READLINE_HISTORY_H)
#include <edit/readline/history.h>
#endif
#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */
#elif defined(HAVE_EDITLINE_READLINE_H)
#include <editline/readline.h>
#elif defined(HAVE_READLINE_READLINE_H)
#include <readline/readline.h>
#if defined(HAVE_READLINE_HISTORY_H)
#include <readline/history.h>
#endif
#endif
#endif
#endif /* if defined(HAVE_READLINE_HISTORY_H) */
#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */
#endif /* if defined(HAVE_READLINE) */
static bool short_form = true, tcpmode = false, tcpmode_set = false,
identify = false, stats = true, comments = true,
@ -141,9 +141,10 @@ rcode_totext(dns_rcode_t rcode)
if (rcode >= (sizeof(rcodetext) / sizeof(rcodetext[0]))) {
snprintf(buf, sizeof(buf), "?%u", rcode);
totext.deconsttext = buf;
} else
} else {
totext.consttext = rcodetext[rcode];
return totext.deconsttext;
}
return (totext.deconsttext);
}
static void
@ -206,10 +207,11 @@ printrdata(dns_rdata_t *rdata)
unsigned int size = 1024;
bool done = false;
if (rdata->type < N_KNOWN_RRTYPES)
if (rdata->type < N_KNOWN_RRTYPES) {
printf("%s", rtypetext[rdata->type]);
else
} else {
printf("rdata_%d = ", rdata->type);
}
while (!done) {
isc_buffer_allocate(mctx, &b, size);
@ -218,8 +220,9 @@ printrdata(dns_rdata_t *rdata)
printf("%.*s\n", (int)isc_buffer_usedlength(b),
(char *)isc_buffer_base(b));
done = true;
} else if (result != ISC_R_NOSPACE)
} else if (result != ISC_R_NOSPACE) {
check_result(result, "dns_rdata_totext");
}
isc_buffer_free(&b);
size *= 2;
}
@ -241,10 +244,11 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers,
debug("printsection()");
result = dns_message_firstname(msg, section);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
return (result);
}
for (;;) {
name = NULL;
dns_message_currentname(msg, section, &name);
@ -256,8 +260,9 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers,
switch (rdata.type) {
case dns_rdatatype_a:
case dns_rdatatype_aaaa:
if (section != DNS_SECTION_ANSWER)
if (section != DNS_SECTION_ANSWER) {
goto def_short_section;
}
dns_name_format(name, namebuf,
sizeof(namebuf));
printf("Name:\t%s\n", namebuf);
@ -282,9 +287,9 @@ printsection(dig_query_t *query, dns_message_t *msg, bool headers,
}
}
result = dns_message_nextname(msg, section);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
break;
else if (result != ISC_R_SUCCESS) {
} else if (result != ISC_R_SUCCESS) {
return (result);
}
}
@ -323,10 +328,11 @@ detailsection(dig_query_t *query, dns_message_t *msg, bool headers,
}
result = dns_message_firstname(msg, section);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
return (ISC_R_SUCCESS);
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
return (result);
}
for (;;) {
name = NULL;
dns_message_currentname(msg, section, &name);
@ -363,9 +369,9 @@ detailsection(dig_query_t *query, dns_message_t *msg, bool headers,
}
}
result = dns_message_nextname(msg, section);
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
break;
else if (result != ISC_R_SUCCESS) {
} else if (result != ISC_R_SUCCESS) {
return (result);
}
}
@ -401,8 +407,9 @@ chase_cnamechain(dns_message_t *msg, dns_name_t *qname)
result = dns_message_findname(msg, DNS_SECTION_ANSWER, qname,
dns_rdatatype_cname, 0, NULL,
&rdataset);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return;
}
result = dns_rdataset_first(rdataset);
check_result(result, "dns_rdataset_first");
dns_rdata_reset(&rdata);
@ -483,19 +490,21 @@ printmessage(dig_query_t *query, const isc_buffer_t *msgbuf, dns_message_t *msg,
}
if ((msg->flags & DNS_MESSAGEFLAG_AA) == 0 &&
(!default_lookups || query->lookup->rdtype == dns_rdatatype_a))
(!default_lookups || query->lookup->rdtype == dns_rdatatype_a)) {
puts("Non-authoritative answer:");
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER]))
}
if (!ISC_LIST_EMPTY(msg->sections[DNS_SECTION_ANSWER])) {
printsection(query, msg, headers, DNS_SECTION_ANSWER);
else {
if (default_lookups && query->lookup->rdtype == dns_rdatatype_a)
} else {
if (default_lookups &&
query->lookup->rdtype == dns_rdatatype_a) {
a_noanswer = true;
else if (!default_lookups ||
(query->lookup->rdtype == dns_rdatatype_aaaa &&
a_noanswer))
} else if (!default_lookups ||
(query->lookup->rdtype == dns_rdatatype_aaaa &&
a_noanswer)) {
printf("*** Can't find %s: No answer\n",
query->lookup->textname);
}
}
if (((msg->flags & DNS_MESSAGEFLAG_AA) == 0) &&
@ -527,12 +536,14 @@ show_settings(bool full, bool serv_only)
isc_sockaddr_format(&sockaddr, sockstr, sizeof(sockstr));
printf("Default server: %s\nAddress: %s\n", srv->userarg,
sockstr);
if (!full)
if (!full) {
return;
}
srv = ISC_LIST_NEXT(srv, link);
}
if (serv_only)
if (serv_only) {
return;
}
printf("\nSet options:\n");
printf(" %s\t\t\t%s\t\t%s\n", tcpmode ? "vc" : "novc",
short_form ? "nodebug" : "debug", debugging ? "d2" : "nod2");
@ -545,8 +556,9 @@ show_settings(bool full, bool serv_only)
for (listent = ISC_LIST_HEAD(search_list); listent != NULL;
listent = ISC_LIST_NEXT(listent, link)) {
printf("%s", listent->origin);
if (ISC_LIST_NEXT(listent, link) != NULL)
if (ISC_LIST_NEXT(listent, link) != NULL) {
printf("/");
}
}
printf("\n");
}
@ -561,9 +573,9 @@ testtype(char *typetext)
tr.base = typetext;
tr.length = strlen(typetext);
result = dns_rdatatype_fromtext(&rdtype, &tr);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return (true);
else {
} else {
printf("unknown query type: %s\n", typetext);
return (false);
}
@ -579,9 +591,9 @@ testclass(char *typetext)
tr.base = typetext;
tr.length = strlen(typetext);
result = dns_rdataclass_fromtext(&rdclass, &tr);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return (true);
else {
} else {
printf("unknown query class: %s\n", typetext);
return (false);
}
@ -592,8 +604,9 @@ set_port(const char *value)
{
uint32_t n;
isc_result_t result = parse_uint(&n, value, 65535, "port");
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
port = (uint16_t)n;
}
}
static void
@ -601,8 +614,9 @@ set_timeout(const char *value)
{
uint32_t n;
isc_result_t result = parse_uint(&n, value, UINT_MAX, "timeout");
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
timeout = n;
}
}
static void
@ -610,8 +624,9 @@ set_tries(const char *value)
{
uint32_t n;
isc_result_t result = parse_uint(&n, value, INT_MAX, "tries");
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
tries = n;
}
}
static void
@ -619,8 +634,9 @@ set_ndots(const char *value)
{
uint32_t n;
isc_result_t result = parse_uint(&n, value, 128, "ndots");
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
ndots = n;
}
}
static void
@ -640,11 +656,13 @@ setoption(char *opt)
if (CHECKOPT("all", 3)) {
show_settings(true, false);
} else if (strncasecmp(opt, "class=", 6) == 0) {
if (testclass(&opt[6]))
if (testclass(&opt[6])) {
strlcpy(defclass, &opt[6], sizeof(defclass));
}
} else if (strncasecmp(opt, "cl=", 3) == 0) {
if (testclass(&opt[3]))
if (testclass(&opt[3])) {
strlcpy(defclass, &opt[3], sizeof(defclass));
}
} else if (strncasecmp(opt, "type=", 5) == 0) {
if (testtype(&opt[5])) {
strlcpy(deftype, &opt[5], sizeof(deftype));
@ -785,18 +803,20 @@ addlookup(char *opt)
lookup->retries = tries;
lookup->udpsize = 0;
lookup->comments = comments;
if (lookup->rdtype == dns_rdatatype_any && !tcpmode_set)
if (lookup->rdtype == dns_rdatatype_any && !tcpmode_set) {
lookup->tcp_mode = true;
else
} else {
lookup->tcp_mode = tcpmode;
}
lookup->stats = stats;
lookup->section_question = section_question;
lookup->section_answer = section_answer;
lookup->section_authority = section_authority;
lookup->section_additional = section_additional;
lookup->new_search = true;
if (nofail)
if (nofail) {
lookup->servfail_stops = false;
}
ISC_LIST_INIT(lookup->q);
ISC_LINK_INIT(lookup, link);
ISC_LIST_APPEND(lookup_list, lookup, link);
@ -814,10 +834,10 @@ do_next_command(char *input)
return;
}
arg = strtok_r(NULL, " \t\r\n", &last);
if ((strcasecmp(ptr, "set") == 0) && (arg != NULL))
if ((strcasecmp(ptr, "set") == 0) && (arg != NULL)) {
setoption(arg);
else if ((strcasecmp(ptr, "server") == 0) ||
(strcasecmp(ptr, "lserver") == 0)) {
} else if ((strcasecmp(ptr, "server") == 0) ||
(strcasecmp(ptr, "lserver") == 0)) {
isc_app_block();
set_nameserver(arg);
check_ra = false;
@ -831,8 +851,9 @@ do_next_command(char *input)
strcasecmp(ptr, "root") == 0 || strcasecmp(ptr, "ls") == 0 ||
strcasecmp(ptr, "view") == 0) {
printf("The '%s' command is not implemented.\n", ptr);
} else
} else {
addlookup(ptr);
}
}
static void
@ -847,24 +868,28 @@ get_next_command(void)
if (interactive) {
#ifdef HAVE_READLINE
ptr = readline("> ");
if (ptr != NULL)
if (ptr != NULL) {
add_history(ptr);
#else
}
#else /* ifdef HAVE_READLINE */
fputs("> ", stderr);
fflush(stderr);
ptr = fgets(buf, COMMSIZE, stdin);
#endif
} else
#endif /* ifdef HAVE_READLINE */
} else {
ptr = fgets(buf, COMMSIZE, stdin);
}
isc_app_unblock();
if (ptr == NULL) {
in_use = false;
} else
} else {
do_next_command(ptr);
}
#ifdef HAVE_READLINE
if (interactive)
if (interactive) {
free(ptr);
#endif
}
#endif /* ifdef HAVE_READLINE */
isc_mem_free(mctx, buf);
}
@ -900,8 +925,9 @@ parse_args(int argc, char **argv)
exit(0);
} else if (argv[0][1] != 0) {
setoption(&argv[0][1]);
} else
} else {
have_lookup = true;
}
} else {
if (!have_lookup) {
have_lookup = true;
@ -949,8 +975,9 @@ flush_lookup_list(void)
ISC_LIST_DEQUEUE(l->my_server_list, sp, link);
isc_mem_free(mctx, sp);
}
if (l->sendmsg != NULL)
if (l->sendmsg != NULL) {
dns_message_destroy(&l->sendmsg);
}
lp = l;
l = ISC_LIST_NEXT(l, link);
ISC_LIST_DEQUEUE(lookup_list, lp, link);
@ -962,8 +989,9 @@ static void
getinput(isc_task_t *task, isc_event_t *event)
{
UNUSED(task);
if (global_event == NULL)
if (global_event == NULL) {
global_event = event;
}
while (in_use) {
get_next_command();
if (ISC_LIST_HEAD(lookup_list) != NULL) {
@ -1001,16 +1029,19 @@ main(int argc, char **argv)
setup_system(false, false);
parse_args(argc, argv);
if (keyfile[0] != 0)
if (keyfile[0] != 0) {
setup_file_key();
else if (keysecret[0] != 0)
} else if (keysecret[0] != 0) {
setup_text_key();
if (domainopt[0] != '\0')
}
if (domainopt[0] != '\0') {
set_search_domain(domainopt);
if (in_use)
}
if (in_use) {
result = isc_app_onrun(mctx, global_task, onrun_callback, NULL);
else
} else {
result = isc_app_onrun(mctx, global_task, getinput, NULL);
}
check_result(result, "isc_app_onrun");
in_use = !in_use;
@ -1018,8 +1049,9 @@ main(int argc, char **argv)
puts("");
debug("done, and starting to shut down");
if (global_event != NULL)
if (global_event != NULL) {
isc_event_free(&global_event);
}
cancel_all();
destroy_libs();
isc_app_finish();

View file

@ -55,7 +55,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -1085,7 +1085,7 @@ main(int argc, char *argv[])
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;

View file

@ -43,7 +43,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -78,17 +78,20 @@ db_load_from_stream(dns_db_t *db, FILE *fp)
dns_rdatacallbacks_init(&callbacks);
result = dns_db_beginload(db, &callbacks);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_db_beginload failed: %s", isc_result_totext(result));
}
result = dns_master_loadstream(fp, name, name, rdclass, 0, &callbacks,
mctx);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't load from input: %s", isc_result_totext(result));
}
result = dns_db_endload(db, &callbacks);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_db_endload failed: %s", isc_result_totext(result));
}
}
static isc_result_t
@ -103,35 +106,41 @@ loadset(const char *filename, dns_rdataset_t *rdataset)
result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, rdclass, 0,
NULL, &db);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't create database");
}
if (strcmp(filename, "-") == 0) {
db_load_from_stream(db, stdin);
filename = "input";
} else {
result = dns_db_load(db, filename, dns_masterformat_text, 0);
if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE)
if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) {
fatal("can't load %s: %s", filename,
isc_result_totext(result));
}
}
result = dns_db_findnode(db, name, false, &node);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't find %s node in %s", setname, filename);
}
result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_dnskey, 0, 0,
rdataset, NULL);
if (result == ISC_R_NOTFOUND)
if (result == ISC_R_NOTFOUND) {
fatal("no DNSKEY RR for %s in %s", setname, filename);
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
fatal("dns_db_findrdataset");
}
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
if (db != NULL)
}
if (db != NULL) {
dns_db_detach(&db);
}
return (result);
}
@ -147,21 +156,25 @@ loadkeyset(char *dirname, dns_rdataset_t *rdataset)
isc_buffer_init(&buf, filename, sizeof(filename));
if (dirname != NULL) {
/* allow room for a trailing slash */
if (strlen(dirname) >= isc_buffer_availablelength(&buf))
if (strlen(dirname) >= isc_buffer_availablelength(&buf)) {
return (ISC_R_NOSPACE);
}
isc_buffer_putstr(&buf, dirname);
if (dirname[strlen(dirname) - 1] != '/')
if (dirname[strlen(dirname) - 1] != '/') {
isc_buffer_putstr(&buf, "/");
}
}
if (isc_buffer_availablelength(&buf) < 7)
if (isc_buffer_availablelength(&buf) < 7) {
return (ISC_R_NOSPACE);
}
isc_buffer_putstr(&buf, "keyset-");
result = dns_name_tofilenametext(name, false, &buf);
check_result(result, "dns_name_tofilenametext()");
if (isc_buffer_availablelength(&buf) == 0)
if (isc_buffer_availablelength(&buf) == 0) {
return (ISC_R_NOSPACE);
}
isc_buffer_putuint8(&buf, 0);
return (loadset(filename, rdataset));
@ -182,9 +195,10 @@ loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
result = dst_key_fromnamedfile(filename, NULL, DST_TYPE_PUBLIC, mctx,
&key);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't load %s.key: %s", filename,
isc_result_totext(result));
}
if (verbose > 2) {
char keystr[DST_KEY_FORMATSIZE];
@ -194,8 +208,9 @@ loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
}
result = dst_key_todns(key, &keyb);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't decode key");
}
isc_buffer_usedregion(&keyb, &r);
dns_rdata_fromregion(rdata, dst_key_class(key), dns_rdatatype_dnskey,
@ -220,8 +235,9 @@ logkey(dns_rdata_t *rdata)
isc_buffer_init(&buf, rdata->data, rdata->length);
isc_buffer_add(&buf, rdata->length);
result = dst_key_fromdns(name, rdclass, &buf, mctx, &key);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return;
}
dst_key_format(key, keystr, sizeof(keystr));
fprintf(stderr, "%s: %s\n", program, keystr);
@ -249,35 +265,42 @@ emit(dns_dsdigest_t dt, bool showall, bool cds, dns_rdata_t *rdata)
dns_rdata_init(&ds);
result = dns_rdata_tostruct(rdata, &dnskey, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't convert DNSKEY");
}
if ((dnskey.flags & DNS_KEYFLAG_KSK) == 0 && !showall)
if ((dnskey.flags & DNS_KEYFLAG_KSK) == 0 && !showall) {
return;
}
result = dns_ds_buildrdata(name, rdata, dt, buf, &ds);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't build record");
}
result = dns_name_totext(name, false, &nameb);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't print name");
}
result = dns_rdata_tofmttext(&ds, (dns_name_t *)NULL, 0, 0, 0, "",
&textb);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't print rdata");
}
result = dns_rdataclass_totext(rdclass, &classb);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't print class");
}
isc_buffer_usedregion(&nameb, &r);
printf("%.*s ", (int)r.length, r.base);
if (emitttl)
if (emitttl) {
printf("%u ", ttl);
}
isc_buffer_usedregion(&classb, &r);
printf("%.*s", (int)r.length, r.base);
@ -364,7 +387,7 @@ main(int argc, char **argv)
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -395,11 +418,12 @@ main(int argc, char **argv)
"%s: the -d option is deprecated; "
"use -K\n",
program);
/* fall through */
/* fall through */
case 'K':
dir = isc_commandline_argument;
if (strlen(dir) == 0U)
if (strlen(dir) == 0U) {
fatal("directory must be non-empty string");
}
break;
case 'f':
filename = isc_commandline_argument;
@ -416,17 +440,19 @@ main(int argc, char **argv)
break;
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("-v must be followed by a number");
}
break;
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
/* Does not return. */
usage();

View file

@ -42,7 +42,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -82,17 +82,20 @@ db_load_from_stream(dns_db_t *db, FILE *fp)
dns_rdatacallbacks_init(&callbacks);
result = dns_db_beginload(db, &callbacks);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_db_beginload failed: %s", isc_result_totext(result));
}
result = dns_master_loadstream(fp, name, name, rdclass, 0, &callbacks,
mctx);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't load from input: %s", isc_result_totext(result));
}
result = dns_db_endload(db, &callbacks);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("dns_db_endload failed: %s", isc_result_totext(result));
}
}
static isc_result_t
@ -107,8 +110,9 @@ loadset(const char *filename, dns_rdataset_t *rdataset)
result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, rdclass, 0,
NULL, &db);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't create database");
}
if (strcmp(filename, "-") == 0) {
db_load_from_stream(db, stdin);
@ -116,27 +120,32 @@ loadset(const char *filename, dns_rdataset_t *rdataset)
} else {
result = dns_db_load(db, filename, dns_masterformat_text,
DNS_MASTER_NOTTL);
if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE)
if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) {
fatal("can't load %s: %s", filename,
isc_result_totext(result));
}
}
result = dns_db_findnode(db, name, false, &node);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't find %s node in %s", setname, filename);
}
result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_dnskey, 0, 0,
rdataset, NULL);
if (result == ISC_R_NOTFOUND)
if (result == ISC_R_NOTFOUND) {
fatal("no DNSKEY RR for %s in %s", setname, filename);
else if (result != ISC_R_SUCCESS)
} else if (result != ISC_R_SUCCESS) {
fatal("dns_db_findrdataset");
}
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
if (db != NULL)
}
if (db != NULL) {
dns_db_detach(&db);
}
return (result);
}
@ -155,9 +164,10 @@ loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
result = dst_key_fromnamedfile(filename, NULL, DST_TYPE_PUBLIC, mctx,
&key);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("invalid keyfile name %s: %s", filename,
isc_result_totext(result));
}
if (verbose > 2) {
char keystr[DST_KEY_FORMATSIZE];
@ -167,8 +177,9 @@ loadkey(char *filename, unsigned char *key_buf, unsigned int key_buf_size,
}
result = dst_key_todns(key, &keyb);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("can't decode key");
}
isc_buffer_usedregion(&keyb, &r);
dns_rdata_fromregion(rdata, dst_key_class(key), dns_rdatatype_dnskey,
@ -216,23 +227,29 @@ emit(const char *dir, dns_rdata_t *rdata)
dst_key_name(key), dst_key_id(key), dst_key_alg(key),
DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, dir, mctx, &tmp);
if (result == ISC_R_SUCCESS) {
if (dst_key_isprivate(tmp) && !dst_key_isexternal(tmp))
if (dst_key_isprivate(tmp) && !dst_key_isexternal(tmp)) {
fatal("Private key already exists in %s", priname);
}
dst_key_free(&tmp);
}
dst_key_setexternal(key, true);
if (setpub)
if (setpub) {
dst_key_settime(key, DST_TIME_PUBLISH, pub);
if (setdel)
}
if (setdel) {
dst_key_settime(key, DST_TIME_DELETE, del);
if (setsyncadd)
}
if (setsyncadd) {
dst_key_settime(key, DST_TIME_SYNCPUBLISH, syncadd);
if (setsyncdel)
}
if (setsyncdel) {
dst_key_settime(key, DST_TIME_SYNCDELETE, syncdel);
}
if (setttl)
if (setttl) {
dst_key_setttl(key, ttl);
}
result = dst_key_tofile(key, DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, dir);
if (result != ISC_R_SUCCESS) {
@ -299,14 +316,15 @@ main(int argc, char **argv)
dns_rdata_init(&rdata);
isc_stdtime_get(&now);
if (argc == 1)
if (argc == 1) {
usage();
}
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -317,9 +335,10 @@ main(int argc, char **argv)
case 'D':
/* -Dsync ? */
if (isoptarg("sync", argv, usage)) {
if (setsyncdel)
if (setsyncdel) {
fatal("-D sync specified more than "
"once");
}
syncdel = strtotime(isc_commandline_argument,
now, now, &setsyncdel);
@ -327,16 +346,18 @@ main(int argc, char **argv)
}
/* -Ddnskey ? */
(void)isoptarg("dnskey", argv, usage);
if (setdel)
if (setdel) {
fatal("-D specified more than once");
}
del = strtotime(isc_commandline_argument, now, now,
&setdel);
break;
case 'K':
dir = isc_commandline_argument;
if (strlen(dir) == 0U)
if (strlen(dir) == 0U) {
fatal("directory must be non-empty string");
}
break;
case 'L':
ttl = strtottl(isc_commandline_argument);
@ -345,9 +366,10 @@ main(int argc, char **argv)
case 'P':
/* -Psync ? */
if (isoptarg("sync", argv, usage)) {
if (setsyncadd)
if (setsyncadd) {
fatal("-P sync specified more than "
"once");
}
syncadd = strtotime(isc_commandline_argument,
now, now, &setsyncadd);
@ -355,8 +377,9 @@ main(int argc, char **argv)
}
/* -Pdnskey ? */
(void)isoptarg("dnskey", argv, usage);
if (setpub)
if (setpub) {
fatal("-P specified more than once");
}
pub = strtotime(isc_commandline_argument, now, now,
&setpub);
@ -366,14 +389,16 @@ main(int argc, char **argv)
break;
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("-v must be followed by a number");
}
break;
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
/* Does not return. */
usage();
@ -391,15 +416,18 @@ main(int argc, char **argv)
rdclass = strtoclass(classname);
if (argc < isc_commandline_index + 1 && filename == NULL)
if (argc < isc_commandline_index + 1 && filename == NULL) {
fatal("the key file name was not specified");
if (argc > isc_commandline_index + 1)
}
if (argc > isc_commandline_index + 1) {
fatal("extraneous arguments");
}
result = dst_lib_init(mctx, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("could not initialize dst: %s",
isc_result_totext(result));
}
setup_logging(mctx, &log);
@ -409,18 +437,21 @@ main(int argc, char **argv)
if (argc < isc_commandline_index + 1) {
/* using filename as zone name */
namestr = filename;
} else
} else {
namestr = argv[isc_commandline_index];
}
result = initname(namestr);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("could not initialize name %s", namestr);
}
result = loadset(filename, &rdataset);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("could not load DNSKEY set: %s\n",
isc_result_totext(result));
}
for (result = dns_rdataset_first(&rdataset);
result == ISC_R_SUCCESS;
@ -438,18 +469,21 @@ main(int argc, char **argv)
emit(dir, &rdata);
}
if (dns_rdataset_isassociated(&rdataset))
if (dns_rdataset_isassociated(&rdataset)) {
dns_rdataset_disassociate(&rdataset);
}
cleanup_logging(&log);
dst_lib_destroy();
if (verbose > 10)
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
fflush(stdout);
if (ferror(stdout)) {
fprintf(stderr, "write error\n");
return (1);
} else
} else {
return (0);
}
}

View file

@ -38,7 +38,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -72,9 +72,9 @@ usage(void)
" path to PKCS#11 provider library "
"(default is %s)\n",
PK11_LIB_LOCATION);
#else
#else /* if USE_PKCS11 */
fprintf(stderr, " name of an OpenSSL engine to use\n");
#endif
#endif /* if USE_PKCS11 */
fprintf(stderr, " -f keyflag: KSK | REVOKE\n");
fprintf(stderr, " -K directory: directory in which to place "
"key files\n");
@ -163,14 +163,15 @@ main(int argc, char **argv)
bool unsetsyncadd = false, setsyncadd = false;
bool unsetsyncdel = false, setsyncdel = false;
if (argc == 1)
if (argc == 1) {
usage();
}
isc_mem_create(&mctx);
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -197,20 +198,22 @@ main(int argc, char **argv)
break;
case 'f':
c = (unsigned char)(isc_commandline_argument[0]);
if (toupper(c) == 'K')
if (toupper(c) == 'K') {
kskflag = DNS_KEYFLAG_KSK;
else if (toupper(c) == 'R')
} else if (toupper(c) == 'R') {
revflag = DNS_KEYFLAG_REVOKE;
else
} else {
fatal("unknown flag '%s'",
isc_commandline_argument);
}
break;
case 'K':
directory = isc_commandline_argument;
ret = try_dir(directory);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("cannot open directory %s: %s", directory,
isc_result_totext(ret));
}
break;
case 'k':
options |= DST_TYPE_KEY;
@ -227,17 +230,19 @@ main(int argc, char **argv)
break;
case 'p':
protocol = strtol(isc_commandline_argument, &endp, 10);
if (*endp != '\0' || protocol < 0 || protocol > 255)
if (*endp != '\0' || protocol < 0 || protocol > 255) {
fatal("-p must be followed by a number "
"[0..255]");
}
break;
case 't':
type = isc_commandline_argument;
break;
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("-v must be followed by a number");
}
break;
case 'y':
avoid_collisions = false;
@ -248,9 +253,10 @@ main(int argc, char **argv)
case 'P':
/* -Psync ? */
if (isoptarg("sync", argv, usage)) {
if (unsetsyncadd || setsyncadd)
if (unsetsyncadd || setsyncadd) {
fatal("-P sync specified more than "
"once");
}
syncadd = strtotime(isc_commandline_argument,
now, now, &setsyncadd);
@ -259,32 +265,36 @@ main(int argc, char **argv)
}
/* -Pdnskey ? */
(void)isoptarg("dnskey", argv, usage);
if (setpub || unsetpub)
if (setpub || unsetpub) {
fatal("-P specified more than once");
}
publish = strtotime(isc_commandline_argument, now, now,
&setpub);
unsetpub = !setpub;
break;
case 'A':
if (setact || unsetact)
if (setact || unsetact) {
fatal("-A specified more than once");
}
activate = strtotime(isc_commandline_argument, now, now,
&setact);
unsetact = !setact;
break;
case 'R':
if (setrev || unsetrev)
if (setrev || unsetrev) {
fatal("-R specified more than once");
}
revoke = strtotime(isc_commandline_argument, now, now,
&setrev);
unsetrev = !setrev;
break;
case 'I':
if (setinact || unsetinact)
if (setinact || unsetinact) {
fatal("-I specified more than once");
}
inactive = strtotime(isc_commandline_argument, now, now,
&setinact);
@ -293,9 +303,10 @@ main(int argc, char **argv)
case 'D':
/* -Dsync ? */
if (isoptarg("sync", argv, usage)) {
if (unsetsyncdel || setsyncdel)
if (unsetsyncdel || setsyncdel) {
fatal("-D sync specified more than "
"once");
}
syncdel = strtotime(isc_commandline_argument,
now, now, &setsyncdel);
@ -304,8 +315,9 @@ main(int argc, char **argv)
}
/* -Ddnskey ? */
(void)isoptarg("dnskey", argv, usage);
if (setdel || unsetdel)
if (setdel || unsetdel) {
fatal("-D specified more than once");
}
deltime = strtotime(isc_commandline_argument, now, now,
&setdel);
@ -318,13 +330,14 @@ main(int argc, char **argv)
prepub = strtottl(isc_commandline_argument);
break;
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
/* Does not return. */
usage();
@ -341,28 +354,33 @@ main(int argc, char **argv)
}
ret = dst_lib_init(mctx, engine);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("could not initialize dst: %s", isc_result_totext(ret));
}
setup_logging(mctx, &log);
if (predecessor == NULL) {
if (label == NULL)
if (label == NULL) {
fatal("the key label was not specified");
if (argc < isc_commandline_index + 1)
}
if (argc < isc_commandline_index + 1) {
fatal("the key name was not specified");
if (argc > isc_commandline_index + 1)
}
if (argc > isc_commandline_index + 1) {
fatal("extraneous arguments");
}
name = dns_fixedname_initname(&fname);
isc_buffer_init(&buf, argv[isc_commandline_index],
strlen(argv[isc_commandline_index]));
isc_buffer_add(&buf, strlen(argv[isc_commandline_index]));
ret = dns_name_fromtext(name, &buf, dns_rootname, 0, NULL);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("invalid key name %s: %s",
argv[isc_commandline_index],
isc_result_totext(ret));
}
if (strchr(label, ':') == NULL) {
char *l;
@ -410,24 +428,26 @@ main(int argc, char **argv)
}
if (type != NULL && (options & DST_TYPE_KEY) != 0) {
if (strcasecmp(type, "NOAUTH") == 0)
if (strcasecmp(type, "NOAUTH") == 0) {
flags |= DNS_KEYTYPE_NOAUTH;
else if (strcasecmp(type, "NOCONF") == 0)
} else if (strcasecmp(type, "NOCONF") == 0) {
flags |= DNS_KEYTYPE_NOCONF;
else if (strcasecmp(type, "NOAUTHCONF") == 0)
} else if (strcasecmp(type, "NOAUTHCONF") == 0) {
flags |= (DNS_KEYTYPE_NOAUTH |
DNS_KEYTYPE_NOCONF);
else if (strcasecmp(type, "AUTHCONF") == 0)
/* nothing */;
else
} else if (strcasecmp(type, "AUTHCONF") == 0) {
/* nothing */
} else {
fatal("invalid type %s", type);
}
}
if (!oldstyle && prepub > 0) {
if (setpub && setact && (activate - prepub) < publish)
if (setpub && setact && (activate - prepub) < publish) {
fatal("Activation and publication dates "
"are closer together than the\n\t"
"prepublication interval.");
}
if (!setpub && !setact) {
setpub = setact = true;
@ -441,43 +461,55 @@ main(int argc, char **argv)
publish = activate - prepub;
}
if ((activate - prepub) < now)
if ((activate - prepub) < now) {
fatal("Time until activation is shorter "
"than the\n\tprepublication interval.");
}
}
} else {
char keystr[DST_KEY_FORMATSIZE];
isc_stdtime_t when;
int major, minor;
if (prepub == -1)
if (prepub == -1) {
prepub = (30 * 86400);
}
if (algname != NULL)
if (algname != NULL) {
fatal("-S and -a cannot be used together");
if (nametype != NULL)
}
if (nametype != NULL) {
fatal("-S and -n cannot be used together");
if (type != NULL)
}
if (type != NULL) {
fatal("-S and -t cannot be used together");
if (setpub || unsetpub)
}
if (setpub || unsetpub) {
fatal("-S and -P cannot be used together");
if (setact || unsetact)
}
if (setact || unsetact) {
fatal("-S and -A cannot be used together");
if (use_nsec3)
}
if (use_nsec3) {
fatal("-S and -3 cannot be used together");
if (oldstyle)
}
if (oldstyle) {
fatal("-S and -C cannot be used together");
if (genonly)
}
if (genonly) {
fatal("-S and -G cannot be used together");
}
ret = dst_key_fromnamedfile(predecessor, directory,
DST_TYPE_PUBLIC | DST_TYPE_PRIVATE,
mctx, &prevkey);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("Invalid keyfile %s: %s", predecessor,
isc_result_totext(ret));
if (!dst_key_isprivate(prevkey))
}
if (!dst_key_isprivate(prevkey)) {
fatal("%s is not a private key", predecessor);
}
name = dst_key_name(prevkey);
alg = dst_key_alg(prevkey);
@ -485,27 +517,30 @@ main(int argc, char **argv)
dst_key_format(prevkey, keystr, sizeof(keystr));
dst_key_getprivateformat(prevkey, &major, &minor);
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION)
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION) {
fatal("Key %s has incompatible format version %d.%d\n\t"
"It is not possible to generate a successor key.",
keystr, major, minor);
}
ret = dst_key_gettime(prevkey, DST_TIME_ACTIVATE, &when);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("Key %s has no activation date.\n\t"
"You must use dnssec-settime -A to set one "
"before generating a successor.",
keystr);
}
ret = dst_key_gettime(prevkey, DST_TIME_INACTIVE, &activate);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("Key %s has no inactivation date.\n\t"
"You must use dnssec-settime -I to set one "
"before generating a successor.",
keystr);
}
publish = activate - prepub;
if (publish < now)
if (publish < now) {
fatal("Key %s becomes inactive\n\t"
"sooner than the prepublication period "
"for the new key ends.\n\t"
@ -514,9 +549,10 @@ main(int argc, char **argv)
"or use the -i option to set a shorter "
"prepublication interval.",
keystr);
}
ret = dst_key_gettime(prevkey, DST_TIME_DELETE, &when);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fprintf(stderr,
"%s: WARNING: Key %s has no removal "
"date;\n\t it will remain in the zone "
@ -524,54 +560,62 @@ main(int argc, char **argv)
"You can use dnssec-settime -D to "
"change this.\n",
program, keystr);
}
setpub = setact = true;
}
if (nametype == NULL) {
if ((options & DST_TYPE_KEY) != 0) /* KEY */
if ((options & DST_TYPE_KEY) != 0) { /* KEY */
fatal("no nametype specified");
}
flags |= DNS_KEYOWNER_ZONE; /* DNSKEY */
} else if (strcasecmp(nametype, "zone") == 0)
} else if (strcasecmp(nametype, "zone") == 0) {
flags |= DNS_KEYOWNER_ZONE;
else if ((options & DST_TYPE_KEY) != 0) { /* KEY */
} else if ((options & DST_TYPE_KEY) != 0) { /* KEY */
if (strcasecmp(nametype, "host") == 0 ||
strcasecmp(nametype, "entity") == 0)
strcasecmp(nametype, "entity") == 0) {
flags |= DNS_KEYOWNER_ENTITY;
else if (strcasecmp(nametype, "user") == 0)
} else if (strcasecmp(nametype, "user") == 0) {
flags |= DNS_KEYOWNER_USER;
else
} else {
fatal("invalid KEY nametype %s", nametype);
} else if (strcasecmp(nametype, "other") != 0) /* DNSKEY */
}
} else if (strcasecmp(nametype, "other") != 0) { /* DNSKEY */
fatal("invalid DNSKEY nametype %s", nametype);
}
rdclass = strtoclass(classname);
if (directory == NULL)
if (directory == NULL) {
directory = ".";
}
if ((options & DST_TYPE_KEY) != 0) /* KEY */
if ((options & DST_TYPE_KEY) != 0) { /* KEY */
flags |= signatory;
else if ((flags & DNS_KEYOWNER_ZONE) != 0) { /* DNSKEY */
} else if ((flags & DNS_KEYOWNER_ZONE) != 0) { /* DNSKEY */
flags |= kskflag;
flags |= revflag;
}
if (protocol == -1)
if (protocol == -1) {
protocol = DNS_KEYPROTO_DNSSEC;
else if ((options & DST_TYPE_KEY) == 0 &&
protocol != DNS_KEYPROTO_DNSSEC)
} else if ((options & DST_TYPE_KEY) == 0 &&
protocol != DNS_KEYPROTO_DNSSEC) {
fatal("invalid DNSKEY protocol: %d", protocol);
}
if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY) {
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0) {
fatal("specified null key with signing authority");
}
}
if ((flags & DNS_KEYFLAG_OWNERMASK) == DNS_KEYOWNER_ZONE &&
alg == DNS_KEYALG_DH)
alg == DNS_KEYALG_DH) {
fatal("a key with algorithm '%s' cannot be a zone key",
algname);
}
isc_buffer_init(&buf, filename, sizeof(filename) - 1);
@ -579,9 +623,9 @@ main(int argc, char **argv)
ret = dst_key_fromlabel(name, alg, flags, protocol, rdclass,
#if USE_PKCS11
"pkcs11",
#else
#else /* if USE_PKCS11 */
engine,
#endif
#endif /* if USE_PKCS11 */
label, NULL, mctx, &key);
if (ret != ISC_R_SUCCESS) {
@ -604,48 +648,56 @@ main(int argc, char **argv)
if (!oldstyle) {
dst_key_settime(key, DST_TIME_CREATED, now);
if (genonly && (setpub || setact))
if (genonly && (setpub || setact)) {
fatal("cannot use -G together with -P or -A options");
}
if (setpub)
if (setpub) {
dst_key_settime(key, DST_TIME_PUBLISH, publish);
else if (setact)
} else if (setact) {
dst_key_settime(key, DST_TIME_PUBLISH, activate);
else if (!genonly && !unsetpub)
} else if (!genonly && !unsetpub) {
dst_key_settime(key, DST_TIME_PUBLISH, now);
}
if (setact)
if (setact) {
dst_key_settime(key, DST_TIME_ACTIVATE, activate);
else if (!genonly && !unsetact)
} else if (!genonly && !unsetact) {
dst_key_settime(key, DST_TIME_ACTIVATE, now);
}
if (setrev) {
if (kskflag == 0)
if (kskflag == 0) {
fprintf(stderr,
"%s: warning: Key is "
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
program);
}
dst_key_settime(key, DST_TIME_REVOKE, revoke);
}
if (setinact)
if (setinact) {
dst_key_settime(key, DST_TIME_INACTIVE, inactive);
}
if (setdel)
if (setdel) {
dst_key_settime(key, DST_TIME_DELETE, deltime);
if (setsyncadd)
}
if (setsyncadd) {
dst_key_settime(key, DST_TIME_SYNCPUBLISH, syncadd);
if (setsyncdel)
}
if (setsyncdel) {
dst_key_settime(key, DST_TIME_SYNCDELETE, syncdel);
}
} else {
if (setpub || setact || setrev || setinact || setdel ||
unsetpub || unsetact || unsetrev || unsetinact ||
unsetdel || genonly || setsyncadd || setsyncdel)
unsetdel || genonly || setsyncadd || setsyncdel) {
fatal("cannot use -C together with "
"-P, -A, -R, -I, -D, or -G options");
}
/*
* Compatibility mode: Private-key-format
* should be set to 1.2.
@ -654,8 +706,9 @@ main(int argc, char **argv)
}
/* Set default key TTL */
if (setttl)
if (setttl) {
dst_key_setttl(key, ttl);
}
/*
* Do not overwrite an existing key. Warn LOUDLY if there
@ -665,16 +718,19 @@ main(int argc, char **argv)
if (key_collision(key, name, directory, mctx, &exact)) {
isc_buffer_clear(&buf);
ret = dst_key_buildfilename(key, 0, directory, &buf);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("dst_key_buildfilename returned: %s\n",
isc_result_totext(ret));
if (exact)
}
if (exact) {
fatal("%s: %s already exists\n", program, filename);
}
if (avoid_collisions)
if (avoid_collisions) {
fatal("%s: %s could collide with another key upon "
"revokation\n",
program, filename);
}
fprintf(stderr,
"%s: WARNING: Key %s could collide with "
@ -694,23 +750,27 @@ main(int argc, char **argv)
isc_buffer_clear(&buf);
ret = dst_key_buildfilename(key, 0, NULL, &buf);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("dst_key_buildfilename returned: %s\n",
isc_result_totext(ret));
}
printf("%s\n", filename);
dst_key_free(&key);
if (prevkey != NULL)
if (prevkey != NULL) {
dst_key_free(&prevkey);
}
cleanup_logging(&log);
dst_lib_destroy();
if (verbose > 10)
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_free(mctx, label);
isc_mem_destroy(&mctx);
if (freeit != NULL)
if (freeit != NULL) {
free(freeit);
}
return (0);
}

View file

@ -59,7 +59,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -172,9 +172,9 @@ usage(void)
" path to PKCS#11 provider library "
"(default is %s)\n",
PK11_LIB_LOCATION);
#else
#else /* if USE_PKCS11 */
fprintf(stderr, " name of an OpenSSL engine to use\n");
#endif
#endif /* if USE_PKCS11 */
fprintf(stderr, " -f <keyflag>: KSK | REVOKE\n");
fprintf(stderr, " -g <generator>: use specified generator "
"(DH only)\n");
@ -315,8 +315,9 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
dns_secalg_format(ctx->alg, algstr, sizeof(algstr));
if (ctx->predecessor == NULL) {
if (ctx->prepub == -1)
if (ctx->prepub == -1) {
ctx->prepub = 0;
}
name = dns_fixedname_initname(&fname);
isc_buffer_init(&buf, argv[isc_commandline_index],
@ -365,10 +366,11 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
} else if (strcasecmp(ctx->type, "NOAUTHCONF") == 0) {
flags |= (DNS_KEYTYPE_NOAUTH |
DNS_KEYTYPE_NOCONF);
if (ctx->size < 0)
if (ctx->size < 0) {
ctx->size = 0;
}
} else if (strcasecmp(ctx->type, "AUTHCONF") == 0) {
/* nothing */;
/* nothing */
} else {
fatal("invalid type %s", ctx->type);
}
@ -419,46 +421,59 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
ctx->publish = ctx->activate - ctx->prepub;
}
if ((ctx->activate - ctx->prepub) < ctx->now)
if ((ctx->activate - ctx->prepub) < ctx->now) {
fatal("Time until activation is shorter "
"than the\n\tprepublication interval.");
}
}
} else {
char keystr[DST_KEY_FORMATSIZE];
isc_stdtime_t when;
int major, minor;
if (ctx->prepub == -1)
if (ctx->prepub == -1) {
ctx->prepub = (30 * 86400);
}
if (ctx->alg != 0)
if (ctx->alg != 0) {
fatal("-S and -a cannot be used together");
if (ctx->size >= 0)
}
if (ctx->size >= 0) {
fatal("-S and -b cannot be used together");
if (ctx->nametype != NULL)
}
if (ctx->nametype != NULL) {
fatal("-S and -n cannot be used together");
if (ctx->type != NULL)
}
if (ctx->type != NULL) {
fatal("-S and -t cannot be used together");
if (ctx->setpub || ctx->unsetpub)
}
if (ctx->setpub || ctx->unsetpub) {
fatal("-S and -P cannot be used together");
if (ctx->setact || ctx->unsetact)
}
if (ctx->setact || ctx->unsetact) {
fatal("-S and -A cannot be used together");
if (ctx->use_nsec3)
}
if (ctx->use_nsec3) {
fatal("-S and -3 cannot be used together");
if (ctx->oldstyle)
}
if (ctx->oldstyle) {
fatal("-S and -C cannot be used together");
if (ctx->genonly)
}
if (ctx->genonly) {
fatal("-S and -G cannot be used together");
}
ret = dst_key_fromnamedfile(
ctx->predecessor, ctx->directory,
(DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_STATE),
mctx, &prevkey);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("Invalid keyfile %s: %s", ctx->predecessor,
isc_result_totext(ret));
if (!dst_key_isprivate(prevkey))
}
if (!dst_key_isprivate(prevkey)) {
fatal("%s is not a private key", ctx->predecessor);
}
name = dst_key_name(prevkey);
ctx->alg = dst_key_alg(prevkey);
@ -467,28 +482,31 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
dst_key_format(prevkey, keystr, sizeof(keystr));
dst_key_getprivateformat(prevkey, &major, &minor);
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION)
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION) {
fatal("Key %s has incompatible format version %d.%d\n\t"
"It is not possible to generate a successor key.",
keystr, major, minor);
}
ret = dst_key_gettime(prevkey, DST_TIME_ACTIVATE, &when);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("Key %s has no activation date.\n\t"
"You must use dnssec-settime -A to set one "
"before generating a successor.",
keystr);
}
ret = dst_key_gettime(prevkey, DST_TIME_INACTIVE,
&ctx->activate);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("Key %s has no inactivation date.\n\t"
"You must use dnssec-settime -I to set one "
"before generating a successor.",
keystr);
}
ctx->publish = ctx->activate - ctx->prepub;
if (ctx->publish < ctx->now)
if (ctx->publish < ctx->now) {
fatal("Key %s becomes inactive\n\t"
"sooner than the prepublication period "
"for the new key ends.\n\t"
@ -497,9 +515,10 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
"or use the -i option to set a shorter "
"prepublication interval.",
keystr);
}
ret = dst_key_gettime(prevkey, DST_TIME_DELETE, &when);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fprintf(stderr,
"%s: WARNING: Key %s has no removal "
"date;\n\t it will remain in the zone "
@ -507,6 +526,7 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
"You can use dnssec-settime -D to "
"change this.\n",
program, keystr);
}
ctx->setpub = ctx->setact = true;
}
@ -515,16 +535,21 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
case DNS_KEYALG_RSASHA1:
case DNS_KEYALG_NSEC3RSASHA1:
case DNS_KEYALG_RSASHA256:
if (ctx->size != 0 && (ctx->size < 1024 || ctx->size > MAX_RSA))
if (ctx->size != 0 &&
(ctx->size < 1024 || ctx->size > MAX_RSA)) {
fatal("RSA key size %d out of range", ctx->size);
}
break;
case DNS_KEYALG_RSASHA512:
if (ctx->size != 0 && (ctx->size < 1024 || ctx->size > MAX_RSA))
if (ctx->size != 0 &&
(ctx->size < 1024 || ctx->size > MAX_RSA)) {
fatal("RSA key size %d out of range", ctx->size);
}
break;
case DNS_KEYALG_DH:
if (ctx->size != 0 && (ctx->size < 128 || ctx->size > 4096))
if (ctx->size != 0 && (ctx->size < 128 || ctx->size > 4096)) {
fatal("DH key size %d out of range", ctx->size);
}
break;
case DST_ALG_ECDSA256:
ctx->size = 256;
@ -540,47 +565,55 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
break;
}
if (ctx->alg != DNS_KEYALG_DH && ctx->generator != 0)
if (ctx->alg != DNS_KEYALG_DH && ctx->generator != 0) {
fatal("specified DH generator for a non-DH key");
}
if (ctx->nametype == NULL) {
if ((ctx->options & DST_TYPE_KEY) != 0) /* KEY */
if ((ctx->options & DST_TYPE_KEY) != 0) { /* KEY */
fatal("no nametype specified");
}
flags |= DNS_KEYOWNER_ZONE; /* DNSKEY */
} else if (strcasecmp(ctx->nametype, "zone") == 0)
} else if (strcasecmp(ctx->nametype, "zone") == 0) {
flags |= DNS_KEYOWNER_ZONE;
else if ((ctx->options & DST_TYPE_KEY) != 0) { /* KEY */
} else if ((ctx->options & DST_TYPE_KEY) != 0) { /* KEY */
if (strcasecmp(ctx->nametype, "host") == 0 ||
strcasecmp(ctx->nametype, "entity") == 0)
strcasecmp(ctx->nametype, "entity") == 0) {
flags |= DNS_KEYOWNER_ENTITY;
else if (strcasecmp(ctx->nametype, "user") == 0)
} else if (strcasecmp(ctx->nametype, "user") == 0) {
flags |= DNS_KEYOWNER_USER;
else
} else {
fatal("invalid KEY nametype %s", ctx->nametype);
} else if (strcasecmp(ctx->nametype, "other") != 0) /* DNSKEY */
}
} else if (strcasecmp(ctx->nametype, "other") != 0) { /* DNSKEY */
fatal("invalid DNSKEY nametype %s", ctx->nametype);
}
if (ctx->directory == NULL)
if (ctx->directory == NULL) {
ctx->directory = ".";
}
if ((ctx->options & DST_TYPE_KEY) != 0) /* KEY */
if ((ctx->options & DST_TYPE_KEY) != 0) { /* KEY */
flags |= ctx->signatory;
else if ((flags & DNS_KEYOWNER_ZONE) != 0) { /* DNSKEY */
} else if ((flags & DNS_KEYOWNER_ZONE) != 0) { /* DNSKEY */
flags |= ctx->kskflag;
flags |= ctx->revflag;
}
if (ctx->protocol == -1)
if (ctx->protocol == -1) {
ctx->protocol = DNS_KEYPROTO_DNSSEC;
else if ((ctx->options & DST_TYPE_KEY) == 0 &&
ctx->protocol != DNS_KEYPROTO_DNSSEC)
} else if ((ctx->options & DST_TYPE_KEY) == 0 &&
ctx->protocol != DNS_KEYPROTO_DNSSEC) {
fatal("invalid DNSKEY protocol: %d", ctx->protocol);
}
if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY) {
if (ctx->size > 0)
if (ctx->size > 0) {
fatal("specified null key with non-zero size");
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0)
}
if ((flags & DNS_KEYFLAG_SIGNATORYMASK) != 0) {
fatal("specified null key with signing authority");
}
}
if ((flags & DNS_KEYFLAG_OWNERMASK) == DNS_KEYOWNER_ZONE &&
@ -608,8 +641,9 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
break;
}
if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY)
if ((flags & DNS_KEYFLAG_TYPEMASK) == DNS_KEYTYPE_NOKEY) {
null_key = true;
}
isc_buffer_init(&buf, filename, sizeof(filename) - 1);
@ -658,42 +692,47 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
if (!ctx->oldstyle) {
dst_key_settime(key, DST_TIME_CREATED, ctx->now);
if (ctx->genonly && (ctx->setpub || ctx->setact))
if (ctx->genonly && (ctx->setpub || ctx->setact)) {
fatal("cannot use -G together with "
"-P or -A options");
}
if (ctx->setpub)
if (ctx->setpub) {
dst_key_settime(key, DST_TIME_PUBLISH,
ctx->publish);
else if (ctx->setact && !ctx->unsetpub)
} else if (ctx->setact && !ctx->unsetpub) {
dst_key_settime(key, DST_TIME_PUBLISH,
ctx->activate - ctx->prepub);
else if (!ctx->genonly && !ctx->unsetpub)
} else if (!ctx->genonly && !ctx->unsetpub) {
dst_key_settime(key, DST_TIME_PUBLISH,
ctx->now);
}
if (ctx->setact)
if (ctx->setact) {
dst_key_settime(key, DST_TIME_ACTIVATE,
ctx->activate);
else if (!ctx->genonly && !ctx->unsetact)
} else if (!ctx->genonly && !ctx->unsetact) {
dst_key_settime(key, DST_TIME_ACTIVATE,
ctx->now);
}
if (ctx->setrev) {
if (ctx->kskflag == 0)
if (ctx->kskflag == 0) {
fprintf(stderr,
"%s: warning: Key is "
"not flagged as a KSK, but -R "
"was used. Revoking a ZSK is "
"legal, but undefined.\n",
program);
}
dst_key_settime(key, DST_TIME_REVOKE,
ctx->revokekey);
}
if (ctx->setinact)
if (ctx->setinact) {
dst_key_settime(key, DST_TIME_INACTIVE,
ctx->inactive);
}
if (ctx->setdel) {
if (ctx->setinact &&
@ -709,13 +748,15 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
ctx->deltime);
}
if (ctx->setsyncadd)
if (ctx->setsyncadd) {
dst_key_settime(key, DST_TIME_SYNCPUBLISH,
ctx->syncadd);
}
if (ctx->setsyncdel)
if (ctx->setsyncdel) {
dst_key_settime(key, DST_TIME_SYNCDELETE,
ctx->syncdel);
}
} else {
if (ctx->setpub || ctx->setact || ctx->setrev ||
ctx->setinact || ctx->setdel || ctx->unsetpub ||
@ -733,8 +774,9 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
}
/* Set the default key TTL */
if (ctx->setttl)
if (ctx->setttl) {
dst_key_setttl(key, ctx->ttl);
}
/* Set dnssec-policy related metadata */
if (ctx->policy) {
@ -759,22 +801,24 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
isc_buffer_clear(&buf);
ret = dst_key_buildfilename(
key, 0, ctx->directory, &buf);
if (ret == ISC_R_SUCCESS)
if (ret == ISC_R_SUCCESS) {
fprintf(stderr,
"%s: %s already exists, or "
"might collide with another "
"key upon revokation. "
"Generating a new key\n",
program, filename);
}
}
dst_key_free(&key);
}
} while (conflict == true);
if (conflict)
if (conflict) {
fatal("cannot generate a null key due to possible key ID "
"collision");
}
if (ctx->predecessor != NULL && prevkey != NULL) {
dst_key_setnum(prevkey, DST_NUM_SUCCESSOR, dst_key_id(key));
@ -799,9 +843,10 @@ keygen(keygen_ctx_t *ctx, isc_mem_t *mctx, int argc, char **argv)
isc_buffer_clear(&buf);
ret = dst_key_buildfilename(key, 0, NULL, &buf);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("dst_key_buildfilename returned: %s\n",
isc_result_totext(ret));
}
printf("%s\n", filename);
dst_key_free(&key);
@ -836,7 +881,7 @@ main(int argc, char **argv)
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -850,16 +895,24 @@ main(int argc, char **argv)
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) {
case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0)
if (strcasecmp(isc_commandline_argument, "record") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
if (strcasecmp(isc_commandline_argument, "trace") == 0)
}
if (strcasecmp(isc_commandline_argument, "trace") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
if (strcasecmp(isc_commandline_argument, "usage") == 0)
}
if (strcasecmp(isc_commandline_argument, "usage") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
if (strcasecmp(isc_commandline_argument, "size") == 0)
}
if (strcasecmp(isc_commandline_argument, "size") == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGSIZE;
if (strcasecmp(isc_commandline_argument, "mctx") == 0)
}
if (strcasecmp(isc_commandline_argument, "mctx") == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGCTX;
}
break;
default:
break;
@ -880,8 +933,9 @@ main(int argc, char **argv)
break;
case 'b':
ctx.size = strtol(isc_commandline_argument, &endp, 10);
if (*endp != '\0' || ctx.size < 0)
if (*endp != '\0' || ctx.size < 0) {
fatal("-b requires a non-negative number");
}
break;
case 'C':
ctx.oldstyle = true;
@ -891,8 +945,9 @@ main(int argc, char **argv)
break;
case 'd':
ctx.dbits = strtol(isc_commandline_argument, &endp, 10);
if (*endp != '\0' || ctx.dbits < 0)
if (*endp != '\0' || ctx.dbits < 0) {
fatal("-d requires a non-negative number");
}
break;
case 'E':
engine = isc_commandline_argument;
@ -903,26 +958,29 @@ main(int argc, char **argv)
break;
case 'f':
c = (unsigned char)(isc_commandline_argument[0]);
if (toupper(c) == 'K')
if (toupper(c) == 'K') {
ctx.kskflag = DNS_KEYFLAG_KSK;
else if (toupper(c) == 'R')
} else if (toupper(c) == 'R') {
ctx.revflag = DNS_KEYFLAG_REVOKE;
else
} else {
fatal("unknown flag '%s'",
isc_commandline_argument);
}
break;
case 'g':
ctx.generator =
strtol(isc_commandline_argument, &endp, 10);
if (*endp != '\0' || ctx.generator <= 0)
if (*endp != '\0' || ctx.generator <= 0) {
fatal("-g requires a positive number");
}
break;
case 'K':
ctx.directory = isc_commandline_argument;
ret = try_dir(ctx.directory);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("cannot open directory %s: %s",
ctx.directory, isc_result_totext(ret));
}
break;
case 'k':
ctx.policy = isc_commandline_argument;
@ -965,15 +1023,16 @@ main(int argc, char **argv)
}
break;
case 'T':
if (strcasecmp(isc_commandline_argument, "KEY") == 0)
if (strcasecmp(isc_commandline_argument, "KEY") == 0) {
ctx.options |= DST_TYPE_KEY;
else if (strcasecmp(isc_commandline_argument, "DNSKE"
"Y") == 0)
} else if (strcasecmp(isc_commandline_argument,
"DNSKE"
"Y") == 0) {
/* default behavior */
;
else
} else {
fatal("unknown type '%s'",
isc_commandline_argument);
}
break;
case 't':
ctx.type = isc_commandline_argument;
@ -981,8 +1040,9 @@ main(int argc, char **argv)
case 'v':
endp = NULL;
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("-v must be followed by a number");
}
break;
case 'G':
ctx.genonly = true;
@ -990,9 +1050,10 @@ main(int argc, char **argv)
case 'P':
/* -Psync ? */
if (isoptarg("sync", argv, usage)) {
if (ctx.setsyncadd)
if (ctx.setsyncadd) {
fatal("-P sync specified more than "
"once");
}
ctx.syncadd = strtotime(
isc_commandline_argument, ctx.now,
@ -1000,24 +1061,27 @@ main(int argc, char **argv)
break;
}
(void)isoptarg("dnskey", argv, usage);
if (ctx.setpub || ctx.unsetpub)
if (ctx.setpub || ctx.unsetpub) {
fatal("-P specified more than once");
}
ctx.publish = strtotime(isc_commandline_argument,
ctx.now, ctx.now, &ctx.setpub);
ctx.unsetpub = !ctx.setpub;
break;
case 'A':
if (ctx.setact || ctx.unsetact)
if (ctx.setact || ctx.unsetact) {
fatal("-A specified more than once");
}
ctx.activate = strtotime(isc_commandline_argument,
ctx.now, ctx.now, &ctx.setact);
ctx.unsetact = !ctx.setact;
break;
case 'R':
if (ctx.setrev || ctx.unsetrev)
if (ctx.setrev || ctx.unsetrev) {
fatal("-R specified more than once");
}
ctx.revokekey = strtotime(isc_commandline_argument,
ctx.now, ctx.now,
@ -1025,8 +1089,9 @@ main(int argc, char **argv)
ctx.unsetrev = !ctx.setrev;
break;
case 'I':
if (ctx.setinact || ctx.unsetinact)
if (ctx.setinact || ctx.unsetinact) {
fatal("-I specified more than once");
}
ctx.inactive = strtotime(isc_commandline_argument,
ctx.now, ctx.now,
@ -1036,9 +1101,10 @@ main(int argc, char **argv)
case 'D':
/* -Dsync ? */
if (isoptarg("sync", argv, usage)) {
if (ctx.setsyncdel)
if (ctx.setsyncdel) {
fatal("-D sync specified more than "
"once");
}
ctx.syncdel = strtotime(
isc_commandline_argument, ctx.now,
@ -1046,8 +1112,9 @@ main(int argc, char **argv)
break;
}
(void)isoptarg("dnskey", argv, usage);
if (ctx.setdel || ctx.unsetdel)
if (ctx.setdel || ctx.unsetdel) {
fatal("-D specified more than once");
}
ctx.deltime = strtotime(isc_commandline_argument,
ctx.now, ctx.now, &ctx.setdel);
@ -1060,13 +1127,14 @@ main(int argc, char **argv)
ctx.prepub = strtottl(isc_commandline_argument);
break;
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
/* Does not return. */
usage();
@ -1082,12 +1150,14 @@ main(int argc, char **argv)
}
}
if (!isatty(0))
if (!isatty(0)) {
ctx.quiet = true;
}
ret = dst_lib_init(mctx, engine);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
fatal("could not initialize dst: %s", isc_result_totext(ret));
}
setup_logging(mctx, &lctx);
@ -1098,10 +1168,12 @@ main(int argc, char **argv)
}
if (ctx.predecessor == NULL) {
if (argc < isc_commandline_index + 1)
if (argc < isc_commandline_index + 1) {
fatal("the key name was not specified");
if (argc > isc_commandline_index + 1)
}
if (argc > isc_commandline_index + 1) {
fatal("extraneous arguments");
}
}
if (ctx.predecessor == NULL && ctx.policy == NULL) {
@ -1230,12 +1302,14 @@ main(int argc, char **argv)
cleanup_logging(&lctx);
dst_lib_destroy();
if (verbose > 10)
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
if (freeit != NULL)
if (freeit != NULL) {
free(freeit);
}
return (0);
}

View file

@ -32,7 +32,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -54,9 +54,9 @@ usage(void)
" -E engine: specify PKCS#11 provider "
"(default: %s)\n",
PK11_LIB_LOCATION);
#else
#else /* if USE_PKCS11 */
fprintf(stderr, " -E engine: specify OpenSSL engine\n");
#endif
#endif /* if USE_PKCS11 */
fprintf(stderr, " -f: force overwrite\n");
fprintf(stderr, " -h: help\n");
fprintf(stderr, " -K directory: use directory for key files\n");
@ -89,14 +89,15 @@ main(int argc, char **argv)
bool removefile = false;
bool id = false;
if (argc == 1)
if (argc == 1) {
usage();
}
isc_mem_create(&mctx);
#if HAVE_PKCS11
pk11_result_register();
#endif
#endif /* if HAVE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -124,14 +125,16 @@ main(int argc, char **argv)
break;
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("-v must be followed by a number");
}
break;
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
/* Does not return. */
usage();
@ -148,20 +151,23 @@ main(int argc, char **argv)
}
if (argc < isc_commandline_index + 1 ||
argv[isc_commandline_index] == NULL)
argv[isc_commandline_index] == NULL) {
fatal("The key file name was not specified");
if (argc > isc_commandline_index + 1)
}
if (argc > isc_commandline_index + 1) {
fatal("Extraneous arguments");
}
if (dir != NULL) {
filename = argv[isc_commandline_index];
} else {
result = isc_file_splitpath(mctx, argv[isc_commandline_index],
&dir, &filename);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("cannot process filename %s: %s",
argv[isc_commandline_index],
isc_result_totext(result));
}
if (strcmp(dir, ".") == 0) {
isc_mem_free(mctx, dir);
dir = NULL;
@ -169,15 +175,17 @@ main(int argc, char **argv)
}
result = dst_lib_init(mctx, engine);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Could not initialize dst: %s",
isc_result_totext(result));
}
result = dst_key_fromnamedfile(
filename, dir, DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, mctx, &key);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Invalid keyfile name %s: %s", filename,
isc_result_totext(result));
}
if (id) {
fprintf(stdout, "%u\n", dst_key_rid(key));
@ -185,24 +193,27 @@ main(int argc, char **argv)
}
dst_key_format(key, keystr, sizeof(keystr));
if (verbose > 2)
if (verbose > 2) {
fprintf(stderr, "%s: %s\n", program, keystr);
}
if (force)
if (force) {
set_keyversion(key);
else
} else {
check_keyversion(key, keystr);
}
flags = dst_key_flags(key);
if ((flags & DNS_KEYFLAG_REVOKE) == 0) {
isc_stdtime_t now;
if ((flags & DNS_KEYFLAG_KSK) == 0)
if ((flags & DNS_KEYFLAG_KSK) == 0) {
fprintf(stderr,
"%s: warning: Key is not flagged "
"as a KSK. Revoking a ZSK is "
"legal, but undefined.\n",
program);
}
isc_stdtime_get(&now);
dst_key_settime(key, DST_TIME_REVOKE, now);
@ -238,8 +249,9 @@ main(int argc, char **argv)
isc_buffer_init(&buf, oldname, sizeof(oldname));
dst_key_setflags(key, flags & ~DNS_KEYFLAG_REVOKE);
dst_key_buildfilename(key, DST_TYPE_PRIVATE, dir, &buf);
if (strcmp(oldname, newname) == 0)
if (strcmp(oldname, newname) == 0) {
goto cleanup;
}
(void)unlink(oldname);
isc_buffer_clear(&buf);
dst_key_buildfilename(key, DST_TYPE_PUBLIC, dir, &buf);
@ -253,10 +265,12 @@ main(int argc, char **argv)
cleanup:
dst_key_free(&key);
dst_lib_destroy();
if (verbose > 10)
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
if (dir != NULL)
}
if (dir != NULL) {
isc_mem_free(mctx, dir);
}
isc_mem_destroy(&mctx);
return (0);

View file

@ -35,7 +35,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -61,9 +61,9 @@ usage(void)
#elif defined(USE_PKCS11)
fprintf(stderr, " -E engine: specify OpenSSL engine "
"(default \"pkcs11\")\n");
#else
#else /* if USE_PKCS11 */
fprintf(stderr, " -E engine: specify OpenSSL engine\n");
#endif
#endif /* if USE_PKCS11 */
fprintf(stderr, " -f: force update of old-style "
"keys\n");
fprintf(stderr, " -K directory: set key file location\n");
@ -119,8 +119,9 @@ printtime(dst_key_t *key, int type, const char *tag, bool epoch, FILE *stream)
const char * output = NULL;
isc_stdtime_t when;
if (tag != NULL)
if (tag != NULL) {
fprintf(stream, "%s: ", tag);
}
result = dst_key_gettime(key, type, &when);
if (result == ISC_R_NOTFOUND) {
@ -237,8 +238,9 @@ main(int argc, char **argv)
options = DST_TYPE_PUBLIC | DST_TYPE_PRIVATE | DST_TYPE_STATE;
if (argc == 1)
if (argc == 1) {
usage();
}
isc_mem_create(&mctx);
@ -246,7 +248,7 @@ main(int argc, char **argv)
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -257,8 +259,9 @@ main(int argc, char **argv)
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) {
case 'A':
if (setact || unsetact)
if (setact || unsetact) {
fatal("-A specified more than once");
}
changed = true;
act = strtotime(isc_commandline_argument, now, now,
@ -268,9 +271,10 @@ main(int argc, char **argv)
case 'D':
/* -Dsync ? */
if (isoptarg("sync", argv, usage)) {
if (unsetsyncdel || setsyncdel)
if (unsetsyncdel || setsyncdel) {
fatal("-D sync specified more than "
"once");
}
changed = true;
syncdel = strtotime(isc_commandline_argument,
@ -280,8 +284,9 @@ main(int argc, char **argv)
}
/* -Ddnskey ? */
(void)isoptarg("dnskey", argv, usage);
if (setdel || unsetdel)
if (setdel || unsetdel) {
fatal("-D specified more than once");
}
changed = true;
del = strtotime(isc_commandline_argument, now, now,
@ -321,16 +326,18 @@ main(int argc, char **argv)
setgoal = true;
break;
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
case 'h':
/* Does not return. */
usage();
case 'I':
if (setinact || unsetinact)
if (setinact || unsetinact) {
fatal("-I specified more than once");
}
changed = true;
inact = strtotime(isc_commandline_argument, now, now,
@ -367,9 +374,10 @@ main(int argc, char **argv)
case 'P':
/* -Psync ? */
if (isoptarg("sync", argv, usage)) {
if (unsetsyncadd || setsyncadd)
if (unsetsyncadd || setsyncadd) {
fatal("-P sync specified more than "
"once");
}
changed = true;
syncadd = strtotime(isc_commandline_argument,
@ -378,8 +386,9 @@ main(int argc, char **argv)
break;
}
(void)isoptarg("dnskey", argv, usage);
if (setpub || unsetpub)
if (setpub || unsetpub) {
fatal("-P specified more than once");
}
changed = true;
pub = strtotime(isc_commandline_argument, now, now,
@ -439,8 +448,9 @@ main(int argc, char **argv)
} while (*p != '\0');
break;
case 'R':
if (setrev || unsetrev)
if (setrev || unsetrev) {
fatal("-R specified more than once");
}
changed = true;
rev = strtotime(isc_commandline_argument, now, now,
@ -473,8 +483,9 @@ main(int argc, char **argv)
version(program);
case 'v':
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("-v must be followed by a number");
}
break;
case 'z':
if (setzrrsig) {
@ -496,10 +507,12 @@ main(int argc, char **argv)
}
if (argc < isc_commandline_index + 1 ||
argv[isc_commandline_index] == NULL)
argv[isc_commandline_index] == NULL) {
fatal("The key file name was not specified");
if (argc > isc_commandline_index + 1)
}
if (argc > isc_commandline_index + 1) {
fatal("Extraneous arguments");
}
if ((setgoal || setds || setdnskey || setkrrsig || setzrrsig) &&
!write_state) {
@ -507,28 +520,35 @@ main(int argc, char **argv)
}
result = dst_lib_init(mctx, engine);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Could not initialize dst: %s",
isc_result_totext(result));
}
if (predecessor != NULL) {
int major, minor;
if (prepub == -1)
if (prepub == -1) {
prepub = (30 * 86400);
}
if (setpub || unsetpub)
if (setpub || unsetpub) {
fatal("-S and -P cannot be used together");
if (setact || unsetact)
}
if (setact || unsetact) {
fatal("-S and -A cannot be used together");
}
result = dst_key_fromnamedfile(predecessor, directory, options,
mctx, &prevkey);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Invalid keyfile %s: %s", filename,
isc_result_totext(result));
if (!dst_key_isprivate(prevkey) && !dst_key_isexternal(prevkey))
}
if (!dst_key_isprivate(prevkey) &&
!dst_key_isexternal(prevkey)) {
fatal("%s is not a private key", filename);
}
name = dst_key_name(prevkey);
alg = dst_key_alg(prevkey);
@ -537,61 +557,68 @@ main(int argc, char **argv)
dst_key_format(prevkey, keystr, sizeof(keystr));
dst_key_getprivateformat(prevkey, &major, &minor);
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION)
if (major != DST_MAJOR_VERSION || minor < DST_MINOR_VERSION) {
fatal("Predecessor has incompatible format "
"version %d.%d\n\t",
major, minor);
}
result = dst_key_gettime(prevkey, DST_TIME_ACTIVATE, &prevact);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Predecessor has no activation date. "
"You must set one before\n\t"
"generating a successor.");
}
result =
dst_key_gettime(prevkey, DST_TIME_INACTIVE, &previnact);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Predecessor has no inactivation date. "
"You must set one before\n\t"
"generating a successor.");
}
pub = previnact - prepub;
act = previnact;
if ((previnact - prepub) < now && prepub != 0)
if ((previnact - prepub) < now && prepub != 0) {
fatal("Time until predecessor inactivation is\n\t"
"shorter than the prepublication interval. "
"Either change\n\t"
"predecessor inactivation date, or use the -i "
"option to set\n\t"
"a shorter prepublication interval.");
}
result = dst_key_gettime(prevkey, DST_TIME_DELETE, &prevdel);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fprintf(stderr,
"%s: warning: Predecessor has no "
"removal date;\n\t"
"it will remain in the zone "
"indefinitely after rollover.\n",
program);
else if (prevdel < previnact)
} else if (prevdel < previnact) {
fprintf(stderr,
"%s: warning: Predecessor is "
"scheduled to be deleted\n\t"
"before it is scheduled to be "
"inactive.\n",
program);
}
changed = setpub = setact = true;
} else {
if (prepub < 0)
if (prepub < 0) {
prepub = 0;
}
if (prepub > 0) {
if (setpub && setact && (act - prepub) < pub)
if (setpub && setact && (act - prepub) < pub) {
fatal("Activation and publication dates "
"are closer together than the\n\t"
"prepublication interval.");
}
if (setpub && !setact) {
setact = true;
@ -601,9 +628,10 @@ main(int argc, char **argv)
pub = act - prepub;
}
if ((act - prepub) < now)
if ((act - prepub) < now) {
fatal("Time until activation is shorter "
"than the\n\tprepublication interval.");
}
}
}
@ -612,32 +640,39 @@ main(int argc, char **argv)
} else {
result = isc_file_splitpath(mctx, argv[isc_commandline_index],
&directory, &filename);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("cannot process filename %s: %s",
argv[isc_commandline_index],
isc_result_totext(result));
}
}
result =
dst_key_fromnamedfile(filename, directory, options, mctx, &key);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("Invalid keyfile %s: %s", filename,
isc_result_totext(result));
}
if (!dst_key_isprivate(key) && !dst_key_isexternal(key))
if (!dst_key_isprivate(key) && !dst_key_isexternal(key)) {
fatal("%s is not a private key", filename);
}
dst_key_format(key, keystr, sizeof(keystr));
if (predecessor != NULL) {
if (!dns_name_equal(name, dst_key_name(key)))
if (!dns_name_equal(name, dst_key_name(key))) {
fatal("Key name mismatch");
if (alg != dst_key_alg(key))
}
if (alg != dst_key_alg(key)) {
fatal("Key algorithm mismatch");
if (size != dst_key_size(key))
}
if (size != dst_key_size(key)) {
fatal("Key size mismatch");
if (flags != dst_key_flags(key))
}
if (flags != dst_key_flags(key)) {
fatal("Key flags mismatch");
}
}
prevdel = previnact = 0;
@ -648,80 +683,93 @@ main(int argc, char **argv)
(dst_key_gettime(key, DST_TIME_DELETE, &prevdel) == ISC_R_SUCCESS &&
setinact && !setdel && !unsetdel && prevdel < inact) ||
(!setdel && !unsetdel && !setinact && !unsetinact && prevdel != 0 &&
prevdel < previnact))
prevdel < previnact)) {
fprintf(stderr,
"%s: warning: Key is scheduled to "
"be deleted before it is\n\t"
"scheduled to be inactive.\n",
program);
}
if (force)
if (force) {
set_keyversion(key);
else
} else {
check_keyversion(key, keystr);
}
if (verbose > 2)
if (verbose > 2) {
fprintf(stderr, "%s: %s\n", program, keystr);
}
/*
* Set time values.
*/
if (setpub)
if (setpub) {
dst_key_settime(key, DST_TIME_PUBLISH, pub);
else if (unsetpub)
} else if (unsetpub) {
dst_key_unsettime(key, DST_TIME_PUBLISH);
}
if (setact)
if (setact) {
dst_key_settime(key, DST_TIME_ACTIVATE, act);
else if (unsetact)
} else if (unsetact) {
dst_key_unsettime(key, DST_TIME_ACTIVATE);
}
if (setrev) {
if ((dst_key_flags(key) & DNS_KEYFLAG_REVOKE) != 0)
if ((dst_key_flags(key) & DNS_KEYFLAG_REVOKE) != 0) {
fprintf(stderr,
"%s: warning: Key %s is already "
"revoked; changing the revocation date "
"will not affect this.\n",
program, keystr);
if ((dst_key_flags(key) & DNS_KEYFLAG_KSK) == 0)
}
if ((dst_key_flags(key) & DNS_KEYFLAG_KSK) == 0) {
fprintf(stderr,
"%s: warning: Key %s is not flagged as "
"a KSK, but -R was used. Revoking a "
"ZSK is legal, but undefined.\n",
program, keystr);
}
dst_key_settime(key, DST_TIME_REVOKE, rev);
} else if (unsetrev) {
if ((dst_key_flags(key) & DNS_KEYFLAG_REVOKE) != 0)
if ((dst_key_flags(key) & DNS_KEYFLAG_REVOKE) != 0) {
fprintf(stderr,
"%s: warning: Key %s is already "
"revoked; removing the revocation date "
"will not affect this.\n",
program, keystr);
}
dst_key_unsettime(key, DST_TIME_REVOKE);
}
if (setinact)
if (setinact) {
dst_key_settime(key, DST_TIME_INACTIVE, inact);
else if (unsetinact)
} else if (unsetinact) {
dst_key_unsettime(key, DST_TIME_INACTIVE);
}
if (setdel)
if (setdel) {
dst_key_settime(key, DST_TIME_DELETE, del);
else if (unsetdel)
} else if (unsetdel) {
dst_key_unsettime(key, DST_TIME_DELETE);
}
if (setsyncadd)
if (setsyncadd) {
dst_key_settime(key, DST_TIME_SYNCPUBLISH, syncadd);
else if (unsetsyncadd)
} else if (unsetsyncadd) {
dst_key_unsettime(key, DST_TIME_SYNCPUBLISH);
}
if (setsyncdel)
if (setsyncdel) {
dst_key_settime(key, DST_TIME_SYNCDELETE, syncdel);
else if (unsetsyncdel)
} else if (unsetsyncdel) {
dst_key_unsettime(key, DST_TIME_SYNCDELETE);
}
if (setttl)
if (setttl) {
dst_key_setttl(key, ttl);
}
if (predecessor != NULL && prevkey != NULL) {
dst_key_setnum(prevkey, DST_NUM_SUCCESSOR, dst_key_id(key));
@ -795,37 +843,46 @@ main(int argc, char **argv)
}
}
if (!changed && setttl)
if (!changed && setttl) {
changed = true;
}
/*
* Print out time values, if -p was used.
*/
if (printcreate)
if (printcreate) {
printtime(key, DST_TIME_CREATED, "Created", epoch, stdout);
}
if (printpub)
if (printpub) {
printtime(key, DST_TIME_PUBLISH, "Publish", epoch, stdout);
}
if (printact)
if (printact) {
printtime(key, DST_TIME_ACTIVATE, "Activate", epoch, stdout);
}
if (printrev)
if (printrev) {
printtime(key, DST_TIME_REVOKE, "Revoke", epoch, stdout);
}
if (printinact)
if (printinact) {
printtime(key, DST_TIME_INACTIVE, "Inactive", epoch, stdout);
}
if (printdel)
if (printdel) {
printtime(key, DST_TIME_DELETE, "Delete", epoch, stdout);
}
if (printsyncadd)
if (printsyncadd) {
printtime(key, DST_TIME_SYNCPUBLISH, "SYNC Publish", epoch,
stdout);
}
if (printsyncdel)
if (printsyncdel) {
printtime(key, DST_TIME_SYNCDELETE, "SYNC Delete", epoch,
stdout);
}
if (changed) {
writekey(key, directory, write_state);
@ -834,12 +891,14 @@ main(int argc, char **argv)
}
}
if (prevkey != NULL)
if (prevkey != NULL) {
dst_key_free(&prevkey);
}
dst_key_free(&key);
dst_lib_destroy();
if (verbose > 10)
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
cleanup_logging(&log);
isc_mem_free(mctx, directory);
isc_mem_destroy(&mctx);

File diff suppressed because it is too large Load diff

View file

@ -62,7 +62,7 @@
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include "dnssectool.h"
@ -107,9 +107,10 @@ loadzone(char *file, char *origin, dns_rdataclass_t rdclass, dns_db_t **db)
name = dns_fixedname_initname(&fname);
result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("failed converting name '%s' to dns format: %s", origin,
isc_result_totext(result));
}
result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone, rdclass, 0,
NULL, db);
@ -131,7 +132,7 @@ loadzone(char *file, char *origin, dns_rdataclass_t rdclass, dns_db_t **db)
"use -o to specify a different zone origin",
origin, file);
}
/* FALLTHROUGH */
/* FALLTHROUGH */
default:
fatal("failed loading zone from '%s': %s", file,
isc_result_totext(result));
@ -166,9 +167,9 @@ usage(void)
"\t\tpath to PKCS#11 provider library "
"(default is %s)\n",
PK11_LIB_LOCATION);
#else
#else /* if USE_PKCS11 */
fprintf(stderr, "\t\tname of an OpenSSL engine to use\n");
#endif
#endif /* if USE_PKCS11 */
fprintf(stderr, "\t-x:\tDNSKEY record signed with KSKs only, "
"not ZSKs\n");
fprintf(stderr, "\t-z:\tAll records signed with KSKs\n");
@ -196,16 +197,24 @@ main(int argc, char *argv[])
while ((ch = isc_commandline_parse(argc, argv, CMDLINE_FLAGS)) != -1) {
switch (ch) {
case 'm':
if (strcasecmp(isc_commandline_argument, "record") == 0)
if (strcasecmp(isc_commandline_argument, "record") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGRECORD;
if (strcasecmp(isc_commandline_argument, "trace") == 0)
}
if (strcasecmp(isc_commandline_argument, "trace") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGTRACE;
if (strcasecmp(isc_commandline_argument, "usage") == 0)
}
if (strcasecmp(isc_commandline_argument, "usage") ==
0) {
isc_mem_debugging |= ISC_MEM_DEBUGUSAGE;
if (strcasecmp(isc_commandline_argument, "size") == 0)
}
if (strcasecmp(isc_commandline_argument, "size") == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGSIZE;
if (strcasecmp(isc_commandline_argument, "mctx") == 0)
}
if (strcasecmp(isc_commandline_argument, "mctx") == 0) {
isc_mem_debugging |= ISC_MEM_DEBUGCTX;
}
break;
default:
break;
@ -218,7 +227,7 @@ main(int argc, char *argv[])
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
dns_result_register();
isc_commandline_errprint = false;
@ -247,8 +256,9 @@ main(int argc, char *argv[])
case 'v':
endp = NULL;
verbose = strtol(isc_commandline_argument, &endp, 0);
if (*endp != '\0')
if (*endp != '\0') {
fatal("verbose level must be numeric");
}
break;
case 'q':
@ -264,9 +274,10 @@ main(int argc, char *argv[])
break;
case '?':
if (isc_commandline_option != '?')
if (isc_commandline_option != '?') {
fprintf(stderr, "%s: invalid argument -%c\n",
program, isc_commandline_option);
}
/* FALLTHROUGH */
case 'h':
@ -285,9 +296,10 @@ main(int argc, char *argv[])
}
result = dst_lib_init(mctx, engine);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("could not initialize dst: %s",
isc_result_totext(result));
}
isc_stdtime_get(&now);
@ -298,8 +310,9 @@ main(int argc, char *argv[])
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 1)
if (argc < 1) {
usage();
}
file = argv[0];
@ -309,16 +322,18 @@ main(int argc, char *argv[])
POST(argc);
POST(argv);
if (origin == NULL)
if (origin == NULL) {
origin = file;
}
if (inputformatstr != NULL) {
if (strcasecmp(inputformatstr, "text") == 0)
if (strcasecmp(inputformatstr, "text") == 0) {
inputformat = dns_masterformat_text;
else if (strcasecmp(inputformatstr, "raw") == 0)
} else if (strcasecmp(inputformatstr, "raw") == 0) {
inputformat = dns_masterformat_raw;
else
} else {
fatal("unknown file format: %s\n", inputformatstr);
}
}
gdb = NULL;
@ -339,8 +354,9 @@ main(int argc, char *argv[])
cleanup_logging(&log);
dst_lib_destroy();
if (verbose > 10)
if (verbose > 10) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
(void)isc_app_finish();

View file

@ -21,7 +21,7 @@
#ifdef _WIN32
#include <Winsock2.h>
#endif
#endif /* ifdef _WIN32 */
#include <isc/base32.h>
#include <isc/buffer.h>
@ -81,8 +81,9 @@ fatal(const char *format, ...)
vfprintf(stderr, format, args);
va_end(args);
fprintf(stderr, "\n");
if (fatalcallback != NULL)
if (fatalcallback != NULL) {
(*fatalcallback)();
}
exit(1);
}
@ -95,16 +96,18 @@ setfatalcallback(fatalcallback_t *callback)
void
check_result(isc_result_t result, const char *message)
{
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("%s: %s", message, isc_result_totext(result));
}
}
void
vbprintf(int level, const char *fmt, ...)
{
va_list ap;
if (level > verbose)
if (level > verbose) {
return;
}
va_start(ap, fmt);
fprintf(stderr, "%s: ", program);
vfprintf(stderr, fmt, ap);
@ -138,8 +141,9 @@ setup_logging(isc_mem_t *mctx, isc_log_t **logp)
isc_log_t * log = NULL;
int level;
if (verbose < 0)
if (verbose < 0) {
verbose = 0;
}
switch (verbose) {
case 0:
/*
@ -194,8 +198,9 @@ cleanup_logging(isc_log_t **logp)
log = *logp;
*logp = NULL;
if (log == NULL)
if (log == NULL) {
return;
}
isc_log_destroy(&log);
isc_log_setcontext(NULL);
@ -261,12 +266,14 @@ strtottl(const char *str)
dns_ttl_t ttl;
char * endp;
if (isnone(str))
if (isnone(str)) {
return ((dns_ttl_t)0);
}
ttl = strtol(str, &endp, 0);
if (ttl == 0 && endp == str)
if (ttl == 0 && endp == str) {
fatal("TTL must be numeric");
}
ttl = time_units(ttl, endp, orig);
return (ttl);
}
@ -281,7 +288,7 @@ strtokeystate(const char *str)
for (int i = 0; i < KEYSTATES_NVALUES; i++) {
if (keystates[i] != NULL &&
strcasecmp(str, keystates[i]) == 0) {
return (dst_key_state_t)i;
return ((dst_key_state_t)i);
}
}
fatal("unknown key state");
@ -297,16 +304,19 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp)
size_t n;
if (isnone(str)) {
if (setp != NULL)
if (setp != NULL) {
*setp = false;
}
return ((isc_stdtime_t)0);
}
if (setp != NULL)
if (setp != NULL) {
*setp = true;
}
if ((str[0] == '0' || str[0] == '-') && str[1] == '\0')
if ((str[0] == '0' || str[0] == '-') && str[1] == '\0') {
return ((isc_stdtime_t)0);
}
/*
* We accept times in the following formats:
@ -322,12 +332,14 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp)
strlcpy(timestr, str, sizeof(timestr));
timestr[n] = 0;
if (n == 8u)
if (n == 8u) {
strlcat(timestr, "000000", sizeof(timestr));
}
result = dns_time64_fromtext(timestr, &val);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("time value %s is invalid: %s", orig,
isc_result_totext(result));
}
base = val;
str += n;
} else if (strncmp(str, "now", 3) == 0) {
@ -335,9 +347,9 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp)
str += 3;
}
if (str[0] == '\0')
if (str[0] == '\0') {
return ((isc_stdtime_t)base);
else if (str[0] == '+') {
} else if (str[0] == '+') {
offset = strtol(str + 1, &endp, 0);
offset = time_units((isc_stdtime_t)offset, endp, orig);
val = base + offset;
@ -345,8 +357,9 @@ strtotime(const char *str, int64_t now, int64_t base, bool *setp)
offset = strtol(str + 1, &endp, 0);
offset = time_units((isc_stdtime_t)offset, endp, orig);
val = base - offset;
} else
} else {
fatal("time value %s is invalid", orig);
}
return ((isc_stdtime_t)val);
}
@ -358,13 +371,15 @@ strtoclass(const char *str)
dns_rdataclass_t rdclass;
isc_result_t result;
if (str == NULL)
return dns_rdataclass_in;
if (str == NULL) {
return (dns_rdataclass_in);
}
DE_CONST(str, r.base);
r.length = strlen(str);
result = dns_rdataclass_fromtext(&rdclass, &r);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("unknown class %s", str);
}
return (rdclass);
}
@ -378,8 +393,9 @@ strtodsdigest(const char *str)
DE_CONST(str, r.base);
r.length = strlen(str);
result = dns_dsdigest_fromtext(&alg, &r);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("unknown DS algorithm %s", str);
}
return (alg);
}
@ -435,14 +451,16 @@ check_keyversion(dst_key_t *key, char *keystr)
dst_key_getprivateformat(key, &major, &minor);
INSIST(major <= DST_MAJOR_VERSION); /* invalid private key */
if (major < DST_MAJOR_VERSION || minor < DST_MINOR_VERSION)
if (major < DST_MAJOR_VERSION || minor < DST_MINOR_VERSION) {
fatal("Key %s has incompatible format version %d.%d, "
"use -f to force upgrade to new version.",
keystr, major, minor);
if (minor > DST_MINOR_VERSION)
}
if (minor > DST_MINOR_VERSION) {
fatal("Key %s has incompatible format version %d.%d, "
"use -f to force downgrade to current version.",
keystr, major, minor);
}
}
void
@ -452,9 +470,10 @@ set_keyversion(dst_key_t *key)
dst_key_getprivateformat(key, &major, &minor);
INSIST(major <= DST_MAJOR_VERSION);
if (major != DST_MAJOR_VERSION || minor != DST_MINOR_VERSION)
if (major != DST_MAJOR_VERSION || minor != DST_MINOR_VERSION) {
dst_key_setprivateformat(key, DST_MAJOR_VERSION,
DST_MINOR_VERSION);
}
/*
* If the key is from a version older than 1.3, set
@ -482,8 +501,9 @@ key_collision(dst_key_t *dstkey, dns_name_t *name, const char *dir,
isc_buffer_t fileb;
isc_stdtime_t now;
if (exact != NULL)
if (exact != NULL) {
*exact = false;
}
id = dst_key_id(dstkey);
rid = dst_key_rid(dstkey);
@ -498,21 +518,24 @@ key_collision(dst_key_t *dstkey, dns_name_t *name, const char *dir,
isc_buffer_init(&fileb, filename, sizeof(filename));
result = dst_key_buildfilename(dstkey, DST_TYPE_PRIVATE, dir,
&fileb);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (true);
}
return (isc_file_exists(filename));
}
ISC_LIST_INIT(matchkeys);
isc_stdtime_get(&now);
result = dns_dnssec_findmatchingkeys(name, dir, now, mctx, &matchkeys);
if (result == ISC_R_NOTFOUND)
if (result == ISC_R_NOTFOUND) {
return (false);
}
while (!ISC_LIST_EMPTY(matchkeys) && !conflict) {
key = ISC_LIST_HEAD(matchkeys);
if (dst_key_alg(key->key) != alg)
if (dst_key_alg(key->key) != alg) {
goto next;
}
oldid = dst_key_id(key->key);
roldid = dst_key_rid(key->key);
@ -520,17 +543,20 @@ key_collision(dst_key_t *dstkey, dns_name_t *name, const char *dir,
if (oldid == rid || roldid == id || id == oldid) {
conflict = true;
if (id != oldid) {
if (verbose > 1)
if (verbose > 1) {
fprintf(stderr,
"Key ID %d could "
"collide with %d\n",
id, oldid);
}
} else {
if (exact != NULL)
if (exact != NULL) {
*exact = true;
if (verbose > 1)
}
if (verbose > 1) {
fprintf(stderr, "Key ID %d exists\n",
id);
}
}
}
@ -589,4 +615,4 @@ DestroySockets(void)
{
WSACleanup();
}
#endif
#endif /* ifdef _WIN32 */

View file

@ -108,6 +108,6 @@ void
InitSockets(void);
void
DestroySockets(void);
#endif
#endif /* ifdef _WIN32 */
#endif /* DNSSEC_DNSSECTOOL_H */

View file

@ -98,8 +98,9 @@ dns64_rdata(unsigned char *v, size_t start, unsigned char *rdata)
for (i = 0; i < 4U; i++) {
unsigned char c = v[start++];
if (start == 7U)
if (start == 7U) {
start++;
}
if (c > 99) {
rdata[j++] = 3;
rdata[j++] = decimal[c / 100];
@ -141,8 +142,9 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
*/
zlen = zone->length;
nlen = name->length;
if ((zlen + nlen) > 74U || zlen < 10U || (nlen % 2) != 0U)
if ((zlen + nlen) > 74U || zlen < 10U || (nlen % 2) != 0U) {
return (ISC_R_NOTFOUND);
}
/*
* We assume the zone name is well formed.
@ -166,11 +168,13 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
memset(v, 0, sizeof(v));
while (j != 0U) {
INSIST((i / 2) < sizeof(v));
if (ndata[0] != 1)
if (ndata[0] != 1) {
return (ISC_R_NOTFOUND);
}
n = hex16[ndata[1] & 0xff];
if (n == 1)
if (n == 1) {
return (ISC_R_NOTFOUND);
}
v[i / 2] = n | (v[i / 2] >> 4);
j -= 2;
ndata += 2;
@ -190,14 +194,16 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
if (nlen > 16U && v[(nlen - 1) / 4 - 4] != 0)
if (nlen > 16U && v[(nlen - 1) / 4 - 4] != 0) {
return (ISC_R_NOTFOUND);
}
/*
* If the total length is not 74 then this is a empty node
* so return success.
*/
if (nlen + zlen != 74U)
if (nlen + zlen != 74U) {
return (ISC_R_SUCCESS);
}
len = dns64_rdata(v, 8, rdata);
break;
case ZLEN(40): /* prefix len 40 */
@ -205,14 +211,16 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
if (nlen > 12U && v[(nlen - 1) / 4 - 3] != 0)
if (nlen > 12U && v[(nlen - 1) / 4 - 3] != 0) {
return (ISC_R_NOTFOUND);
}
/*
* If the total length is not 74 then this is a empty node
* so return success.
*/
if (nlen + zlen != 74U)
if (nlen + zlen != 74U) {
return (ISC_R_SUCCESS);
}
len = dns64_rdata(v, 6, rdata);
break;
case ZLEN(48): /* prefix len 48 */
@ -220,14 +228,16 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
if (nlen > 8U && v[(nlen - 1) / 4 - 2] != 0)
if (nlen > 8U && v[(nlen - 1) / 4 - 2] != 0) {
return (ISC_R_NOTFOUND);
}
/*
* If the total length is not 74 then this is a empty node
* so return success.
*/
if (nlen + zlen != 74U)
if (nlen + zlen != 74U) {
return (ISC_R_SUCCESS);
}
len = dns64_rdata(v, 5, rdata);
break;
case ZLEN(56): /* prefix len 56 */
@ -235,14 +245,16 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
if (nlen > 4U && v[(nlen - 1) / 4 - 1] != 0)
if (nlen > 4U && v[(nlen - 1) / 4 - 1] != 0) {
return (ISC_R_NOTFOUND);
}
/*
* If the total length is not 74 then this is a empty node
* so return success.
*/
if (nlen + zlen != 74U)
if (nlen + zlen != 74U) {
return (ISC_R_SUCCESS);
}
len = dns64_rdata(v, 4, rdata);
break;
case ZLEN(64): /* prefix len 64 */
@ -250,14 +262,16 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
* The nibbles that map to this byte must be zero for 'name'
* to exist in the zone.
*/
if (v[(nlen - 1) / 4] != 0)
if (v[(nlen - 1) / 4] != 0) {
return (ISC_R_NOTFOUND);
}
/*
* If the total length is not 74 then this is a empty node
* so return success.
*/
if (nlen + zlen != 74U)
if (nlen + zlen != 74U) {
return (ISC_R_SUCCESS);
}
len = dns64_rdata(v, 3, rdata);
break;
case ZLEN(96): /* prefix len 96 */
@ -265,8 +279,9 @@ dns64_cname(const dns_name_t *zone, const dns_name_t *name,
* If the total length is not 74 then this is a empty node
* so return success.
*/
if (nlen + zlen != 74U)
if (nlen + zlen != 74U) {
return (ISC_R_SUCCESS);
}
len = dns64_rdata(v, 0, rdata);
break;
default:
@ -291,10 +306,11 @@ builtin_lookup(const char *zone, const char *name, void *dbdata,
UNUSED(methods);
UNUSED(clientinfo);
if (strcmp(name, "@") == 0)
if (strcmp(name, "@") == 0) {
return (b->do_lookup(lookup));
else
} else {
return (ISC_R_NOTFOUND);
}
}
static isc_result_t
@ -307,10 +323,11 @@ dns64_lookup(const dns_name_t *zone, const dns_name_t *name, void *dbdata,
UNUSED(methods);
UNUSED(clientinfo);
if (name->labels == 0 && name->length == 0)
if (name->labels == 0 && name->length == 0) {
return (b->do_lookup(lookup));
else
} else {
return (dns64_cname(zone, name, lookup));
}
}
static isc_result_t
@ -318,8 +335,9 @@ put_txt(dns_sdblookup_t *lookup, const char *text)
{
unsigned char buf[256];
unsigned int len = strlen(text);
if (len > 255)
if (len > 255) {
len = 255; /* Silently truncate */
}
buf[0] = len;
memmove(&buf[1], text, len);
return (dns_sdb_putrdata(lookup, dns_rdatatype_txt, 0, buf, len + 1));
@ -329,10 +347,11 @@ static isc_result_t
do_version_lookup(dns_sdblookup_t *lookup)
{
if (named_g_server->version_set) {
if (named_g_server->version == NULL)
if (named_g_server->version == NULL) {
return (ISC_R_SUCCESS);
else
} else {
return (put_txt(lookup, named_g_server->version));
}
} else {
return (put_txt(lookup, named_g_version));
}
@ -342,15 +361,17 @@ static isc_result_t
do_hostname_lookup(dns_sdblookup_t *lookup)
{
if (named_g_server->hostname_set) {
if (named_g_server->hostname == NULL)
if (named_g_server->hostname == NULL) {
return (ISC_R_SUCCESS);
else
} else {
return (put_txt(lookup, named_g_server->hostname));
}
} else {
char buf[256];
isc_result_t result = named_os_gethostname(buf, sizeof(buf));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
return (put_txt(lookup, buf));
}
}
@ -373,13 +394,15 @@ do_authors_lookup(dns_sdblookup_t *lookup)
/*
* If a version string is specified, disable the authors.bind zone.
*/
if (named_g_server->version_set)
if (named_g_server->version_set) {
return (ISC_R_SUCCESS);
}
for (p = authors; *p != NULL; p++) {
result = put_txt(lookup, *p);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
return (ISC_R_SUCCESS);
}
@ -392,13 +415,15 @@ do_id_lookup(dns_sdblookup_t *lookup)
isc_result_t result;
result = named_g_server->sctx->gethostname(buf, sizeof(buf));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
return (put_txt(lookup, buf));
} else if (named_g_server->sctx->server_id != NULL)
} else if (named_g_server->sctx->server_id != NULL) {
return (put_txt(lookup, named_g_server->sctx->server_id));
else
} else {
return (ISC_R_SUCCESS);
}
}
static isc_result_t
@ -430,19 +455,23 @@ builtin_authority(const char *zone, void *dbdata, dns_sdblookup_t *lookup)
server = ".";
contact = ".";
} else {
if (b->server != NULL)
if (b->server != NULL) {
server = b->server;
if (b->contact != NULL)
}
if (b->contact != NULL) {
contact = b->contact;
}
}
result = dns_sdb_putsoa(lookup, server, contact, 0);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
}
result = dns_sdb_putrr(lookup, "ns", 0, server);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (ISC_R_FAILURE);
}
return (ISC_R_SUCCESS);
}
@ -457,21 +486,23 @@ builtin_create(const char *zone, int argc, char **argv, void *driverdata,
UNUSED(driverdata);
if (strcmp(argv[0], "empty") == 0 || strcmp(argv[0], "dns64") == 0) {
if (argc != 3)
if (argc != 3) {
return (DNS_R_SYNTAX);
} else if (argc != 1)
}
} else if (argc != 1) {
return (DNS_R_SYNTAX);
}
if (strcmp(argv[0], "version") == 0)
if (strcmp(argv[0], "version") == 0) {
*dbdata = &version_builtin;
else if (strcmp(argv[0], "hostname") == 0)
} else if (strcmp(argv[0], "hostname") == 0) {
*dbdata = &hostname_builtin;
else if (strcmp(argv[0], "authors") == 0)
} else if (strcmp(argv[0], "authors") == 0) {
*dbdata = &authors_builtin;
else if (strcmp(argv[0], "id") == 0)
} else if (strcmp(argv[0], "id") == 0) {
*dbdata = &id_builtin;
else if (strcmp(argv[0], "empty") == 0 ||
strcmp(argv[0], "dns64") == 0) {
} else if (strcmp(argv[0], "empty") == 0 ||
strcmp(argv[0], "dns64") == 0) {
builtin_t *empty;
char * server;
char * contact;
@ -483,30 +514,36 @@ builtin_create(const char *zone, int argc, char **argv, void *driverdata,
server = isc_mem_strdup(named_g_mctx, argv[1]);
contact = isc_mem_strdup(named_g_mctx, argv[2]);
if (empty == NULL || server == NULL || contact == NULL) {
if (strcmp(argv[0], "empty") == 0)
if (strcmp(argv[0], "empty") == 0) {
*dbdata = &empty_builtin;
else
} else {
*dbdata = &dns64_builtin;
if (server != NULL)
}
if (server != NULL) {
isc_mem_free(named_g_mctx, server);
if (contact != NULL)
}
if (contact != NULL) {
isc_mem_free(named_g_mctx, contact);
if (empty != NULL)
}
if (empty != NULL) {
isc_mem_put(named_g_mctx, empty,
sizeof(*empty));
}
} else {
if (strcmp(argv[0], "empty") == 0)
if (strcmp(argv[0], "empty") == 0) {
memmove(empty, &empty_builtin,
sizeof(empty_builtin));
else
} else {
memmove(empty, &dns64_builtin,
sizeof(empty_builtin));
}
empty->server = server;
empty->contact = contact;
*dbdata = empty;
}
} else
} else {
return (ISC_R_NOTIMPLEMENTED);
}
return (ISC_R_SUCCESS);
}
@ -523,8 +560,9 @@ builtin_destroy(const char *zone, void *driverdata, void **dbdata)
*/
if (*dbdata == &version_builtin || *dbdata == &hostname_builtin ||
*dbdata == &authors_builtin || *dbdata == &id_builtin ||
*dbdata == &empty_builtin || *dbdata == &dns64_builtin)
*dbdata == &empty_builtin || *dbdata == &dns64_builtin) {
return;
}
isc_mem_free(named_g_mctx, b->server);
isc_mem_free(named_g_mctx, b->contact);

View file

@ -51,7 +51,7 @@ options {\n\
#ifndef WIN32
" coresize default;\n\
datasize default;\n"
#endif
#endif /* ifndef WIN32 */
"\
# deallocate-on-exit <obsolete>;\n\
# directory <none>\n\
@ -61,14 +61,14 @@ options {\n\
# fake-iquery <obsolete>;\n"
#ifndef WIN32
" files unlimited;\n"
#endif
#endif /* ifndef WIN32 */
#if defined(HAVE_GEOIP2) && !defined(WIN32)
" geoip-directory \"" MAXMINDDB_PREFIX "/share/"
"GeoIP\";"
"\n"
#elif defined(HAVE_GEOIP2)
" geoip-directory \".\";\n"
#endif
#endif /* if defined(HAVE_GEOIP2) && !defined(WIN32) */
"\
# has-old-clients <obsolete>;\n\
heartbeat-interval 60;\n\
@ -107,7 +107,7 @@ options {\n\
session-keyname local-ddns;\n"
#ifndef WIN32
" stacksize default;\n"
#endif
#endif /* ifndef WIN32 */
" startup-notify-rate 20;\n\
statistics-file \"named.stats\";\n\
# statistics-interval <obsolete>;\n\
@ -150,7 +150,7 @@ options {\n\
dnssec-validation " VALIDATION_DEFAULT "; \n"
#ifdef HAVE_DNSTAP
" dnstap-identity hostname;\n"
#endif
#endif /* ifdef HAVE_DNSTAP */
"\
# fetch-glue <obsolete>;\n\
fetch-quota-params 100 0.1 0.3 0.7;\n\
@ -160,7 +160,7 @@ options {\n\
lame-ttl 600;\n"
#ifdef HAVE_LMDB
" lmdb-mapsize 32M;\n"
#endif
#endif /* ifdef HAVE_LMDB */
" max-cache-size 90%;\n\
max-cache-ttl 604800; /* 1 week */\n\
max-clients-per-query 100;\n\
@ -333,10 +333,12 @@ named_config_get(cfg_obj_t const *const *maps, const char *name,
int i;
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
return (ISC_R_NOTFOUND);
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS)
}
if (cfg_map_get(maps[i], name, obj) == ISC_R_SUCCESS) {
return (ISC_R_SUCCESS);
}
}
}
@ -351,8 +353,9 @@ named_checknames_get(const cfg_obj_t **maps, const char *which,
int i;
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
return (ISC_R_NOTFOUND);
}
checknames = NULL;
if (cfg_map_get(maps[i], "check-names", &checknames) ==
ISC_R_SUCCESS) {
@ -384,8 +387,9 @@ named_config_listcount(const cfg_obj_t *list)
const cfg_listelt_t *e;
int i = 0;
for (e = cfg_list_first(list); e != NULL; e = cfg_list_next(e))
for (e = cfg_list_first(list); e != NULL; e = cfg_list_next(e)) {
i++;
}
return (i);
}
@ -404,9 +408,10 @@ named_config_getclass(const cfg_obj_t *classobj, dns_rdataclass_t defclass,
DE_CONST(cfg_obj_asstring(classobj), r.base);
r.length = strlen(r.base);
result = dns_rdataclass_fromtext(classp, &r);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
cfg_obj_log(classobj, named_g_lctx, ISC_LOG_ERROR,
"unknown class '%s'", r.base);
}
return (result);
}
@ -424,9 +429,10 @@ named_config_gettype(const cfg_obj_t *typeobj, dns_rdatatype_t deftype,
DE_CONST(cfg_obj_asstring(typeobj), r.base);
r.length = strlen(r.base);
result = dns_rdatatype_fromtext(typep, &r);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
cfg_obj_log(typeobj, named_g_lctx, ISC_LOG_ERROR,
"unknown type '%s'", r.base);
}
return (result);
}
@ -488,12 +494,13 @@ named_config_getiplist(const cfg_obj_t *config, const cfg_obj_t *list,
return (ISC_R_RANGE);
}
port = (in_port_t)val;
} else if (defport != 0)
} else if (defport != 0) {
port = defport;
else {
} else {
result = named_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (dscpsp != NULL) {
@ -523,20 +530,23 @@ named_config_getiplist(const cfg_obj_t *config, const cfg_obj_t *list,
if (dscpsp != NULL) {
isc_dscp_t innerdscp;
innerdscp = cfg_obj_getdscp(addr);
if (innerdscp == -1)
if (innerdscp == -1) {
innerdscp = dscp;
}
dscps[i] = innerdscp;
}
if (isc_sockaddr_getport(&addrs[i]) == 0)
if (isc_sockaddr_getport(&addrs[i]) == 0) {
isc_sockaddr_setport(&addrs[i], port);
}
}
INSIST(i == count);
*addrsp = addrs;
*countp = count;
if (dscpsp != NULL)
if (dscpsp != NULL) {
*dscpsp = dscps;
}
return (ISC_R_SUCCESS);
}
@ -566,8 +576,9 @@ named_config_getmastersdef(const cfg_obj_t *cctx, const char *name,
const cfg_listelt_t *elt;
result = cfg_map_get(cctx, "masters", &masters);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
for (elt = cfg_list_first(masters); elt != NULL;
elt = cfg_list_next(elt)) {
const cfg_obj_t *list;
@ -623,12 +634,14 @@ named_config_getipandkeylist(const cfg_obj_t *config, const cfg_obj_t *list,
* Get system defaults.
*/
result = named_config_getport(config, &port);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = named_config_getdscp(config, &dscp);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
newlist:
addrlist = cfg_tuple_get(list, "addresses");
@ -697,8 +710,9 @@ resume:
break;
}
}
if (j < l)
if (j < l) {
continue;
}
tresult = named_config_getmastersdef(config, listname,
&list);
if (tresult == ISC_R_NOTFOUND) {
@ -709,8 +723,9 @@ resume:
result = tresult;
goto cleanup;
}
if (tresult != ISC_R_SUCCESS)
if (tresult != ISC_R_SUCCESS) {
goto cleanup;
}
lists[l++].name = listname;
/* Grow stack? */
if (stackcount == pushed) {
@ -776,15 +791,18 @@ resume:
}
addrs[i] = *cfg_obj_assockaddr(addr);
if (isc_sockaddr_getport(&addrs[i]) == 0)
if (isc_sockaddr_getport(&addrs[i]) == 0) {
isc_sockaddr_setport(&addrs[i], port);
}
dscps[i] = cfg_obj_getdscp(addr);
if (dscps[i] == -1)
if (dscps[i] == -1) {
dscps[i] = dscp;
}
keys[i] = NULL;
i++; /* Increment here so that cleanup on error works. */
if (!cfg_obj_isstring(key))
if (!cfg_obj_isstring(key)) {
continue;
}
keys[i - 1] = isc_mem_get(mctx, sizeof(dns_name_t));
dns_name_init(keys[i - 1], NULL);
@ -794,8 +812,9 @@ resume:
dns_fixedname_init(&fname);
result = dns_name_fromtext(dns_fixedname_name(&fname), &b,
dns_rootname, 0, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
dns_name_dup(dns_fixedname_name(&fname), mctx, keys[i - 1]);
}
if (pushed != 0) {
@ -814,8 +833,9 @@ resume:
if (i != 0) {
tmp = isc_mem_get(mctx, newsize);
memmove(tmp, addrs, newsize);
} else
} else {
tmp = NULL;
}
isc_mem_put(mctx, addrs, oldsize);
addrs = tmp;
addrcount = i;
@ -825,8 +845,9 @@ resume:
if (i != 0) {
tmp = isc_mem_get(mctx, newsize);
memmove(tmp, dscps, newsize);
} else
} else {
tmp = NULL;
}
isc_mem_put(mctx, dscps, oldsize);
dscps = tmp;
dscpcount = i;
@ -836,17 +857,20 @@ resume:
if (i != 0) {
tmp = isc_mem_get(mctx, newsize);
memmove(tmp, keys, newsize);
} else
} else {
tmp = NULL;
}
isc_mem_put(mctx, keys, oldsize);
keys = tmp;
keycount = i;
}
if (lists != NULL)
if (lists != NULL) {
isc_mem_put(mctx, lists, listcount * sizeof(*lists));
if (stack != NULL)
}
if (stack != NULL) {
isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
}
INSIST(dscpcount == addrcount);
INSIST(keycount == addrcount);
@ -861,24 +885,30 @@ resume:
return (ISC_R_SUCCESS);
cleanup:
if (addrs != NULL)
if (addrs != NULL) {
isc_mem_put(mctx, addrs, addrcount * sizeof(isc_sockaddr_t));
if (dscps != NULL)
}
if (dscps != NULL) {
isc_mem_put(mctx, dscps, dscpcount * sizeof(isc_dscp_t));
}
if (keys != NULL) {
for (j = 0; j < i; j++) {
if (keys[j] == NULL)
if (keys[j] == NULL) {
continue;
if (dns_name_dynamic(keys[j]))
}
if (dns_name_dynamic(keys[j])) {
dns_name_free(keys[j], mctx);
}
isc_mem_put(mctx, keys[j], sizeof(dns_name_t));
}
isc_mem_put(mctx, keys, keycount * sizeof(dns_name_t *));
}
if (lists != NULL)
if (lists != NULL) {
isc_mem_put(mctx, lists, listcount * sizeof(*lists));
if (stack != NULL)
}
if (stack != NULL) {
isc_mem_put(mctx, stack, stackcount * sizeof(*stack));
}
return (result);
}
@ -893,8 +923,9 @@ named_config_getport(const cfg_obj_t *config, in_port_t *portp)
(void)cfg_map_get(config, "options", &options);
i = 0;
if (options != NULL)
if (options != NULL) {
maps[i++] = options;
}
maps[i++] = named_g_defaults;
maps[i] = NULL;
@ -918,8 +949,9 @@ named_config_getdscp(const cfg_obj_t *config, isc_dscp_t *dscpp)
isc_result_t result;
(void)cfg_map_get(config, "options", &options);
if (options == NULL)
if (options == NULL) {
return (ISC_R_SUCCESS);
}
result = cfg_map_get(options, "dscp", &dscpobj);
if (result != ISC_R_SUCCESS || dscpobj == NULL) {
@ -977,21 +1009,26 @@ named_config_getkeyalgorithm2(const char *str, const dns_name_t **name,
len = strlen(algorithms[i].str);
if (strncasecmp(algorithms[i].str, str, len) == 0 &&
(str[len] == '\0' ||
(algorithms[i].size != 0 && str[len] == '-')))
(algorithms[i].size != 0 && str[len] == '-'))) {
break;
}
}
if (algorithms[i].str == NULL)
if (algorithms[i].str == NULL) {
return (ISC_R_NOTFOUND);
}
if (str[len] == '-') {
result = isc_parse_uint16(&bits, str + len + 1, 10);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
if (bits > algorithms[i].size)
}
if (bits > algorithms[i].size) {
return (ISC_R_RANGE);
} else if (algorithms[i].size == 0)
}
} else if (algorithms[i].size == 0) {
bits = 128;
else
} else {
bits = algorithms[i].size;
}
if (name != NULL) {
switch (algorithms[i].hmac) {
@ -1018,9 +1055,11 @@ named_config_getkeyalgorithm2(const char *str, const dns_name_t **name,
ISC_UNREACHABLE();
}
}
if (typep != NULL)
if (typep != NULL) {
*typep = algorithms[i].type;
if (digestbits != NULL)
}
if (digestbits != NULL) {
*digestbits = bits;
}
return (ISC_R_SUCCESS);
}

View file

@ -33,7 +33,7 @@
#include <named/server.h>
#ifdef HAVE_LIBSCF
#include <named/smf_globals.h>
#endif
#endif /* ifdef HAVE_LIBSCF */
static isc_result_t
getcommand(isc_lex_t *lex, char **cmdp)
@ -44,13 +44,15 @@ getcommand(isc_lex_t *lex, char **cmdp)
REQUIRE(cmdp != NULL && *cmdp == NULL);
result = isc_lex_gettoken(lex, ISC_LEXOPT_EOF, &token);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
isc_lex_ungettoken(lex, &token);
if (token.type != isc_tokentype_string)
if (token.type != isc_tokentype_string) {
return (ISC_R_FAILURE);
}
*cmdp = token.value.as_textregion.base;
@ -80,7 +82,7 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
isc_lex_t * lex = NULL;
#ifdef HAVE_LIBSCF
named_smf_want_disable = 0;
#endif
#endif /* ifdef HAVE_LIBSCF */
data = isccc_alist_lookup(message, "_data");
if (!isccc_alist_alistp(data)) {
@ -99,18 +101,21 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
}
result = isc_lex_create(named_g_mctx, strlen(cmdline), &lex);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
isc_buffer_init(&src, cmdline, strlen(cmdline));
isc_buffer_add(&src, strlen(cmdline));
result = isc_lex_openbuffer(lex, &src);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = getcommand(lex, &command);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
/*
* Compare the 'command' parameter against all known control commands.
@ -166,14 +171,15 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
* If we are managed by smf(5) but not in chroot,
* try to disable ourselves the smf way.
*/
if (named_smf_got_instance == 1 && named_smf_chroot == 0)
if (named_smf_got_instance == 1 && named_smf_chroot == 0) {
named_smf_want_disable = 1;
/*
* If named_smf_got_instance = 0, named_smf_chroot
* is not relevant and we fall through to
* isc_app_shutdown below.
*/
#endif
}
/*
* If named_smf_got_instance = 0, named_smf_chroot
* is not relevant and we fall through to
* isc_app_shutdown below.
*/
#endif /* ifdef HAVE_LIBSCF */
/* Do not flush master files */
named_server_flushonshutdown(named_g_server, false);
named_os_shutdownmsg(cmdline, *text);
@ -189,9 +195,10 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
result = named_smf_add_message(text);
goto cleanup;
}
if (named_smf_got_instance == 1 && named_smf_chroot == 0)
if (named_smf_got_instance == 1 && named_smf_chroot == 0) {
named_smf_want_disable = 1;
#endif
}
#endif /* ifdef HAVE_LIBSCF */
named_server_flushonshutdown(named_g_server, true);
named_os_shutdownmsg(cmdline, *text);
isc_app_shutdown();
@ -288,8 +295,9 @@ named_control_docommand(isccc_sexpr_t *message, bool readonly,
}
cleanup:
if (lex != NULL)
if (lex != NULL) {
isc_lex_destroy(&lex);
}
return (result);
}

View file

@ -117,10 +117,12 @@ control_recvmessage(isc_task_t *task, isc_event_t *event);
static void
free_controlkey(controlkey_t *key, isc_mem_t *mctx)
{
if (key->keyname != NULL)
if (key->keyname != NULL) {
isc_mem_free(mctx, key->keyname);
if (key->secret.base != NULL)
}
if (key->secret.base != NULL) {
isc_mem_put(mctx, key->secret.base, key->secret.length);
}
isc_mem_put(mctx, key, sizeof(*key));
}
@ -141,13 +143,15 @@ free_listener(controllistener_t *listener)
INSIST(!listener->listening);
INSIST(ISC_LIST_EMPTY(listener->connections));
if (listener->sock != NULL)
if (listener->sock != NULL) {
isc_socket_detach(&listener->sock);
}
free_controlkeylist(&listener->keys, listener->mctx);
if (listener->acl != NULL)
if (listener->acl != NULL) {
dns_acl_detach(&listener->acl);
}
isc_mem_putanddetach(&listener->mctx, listener, sizeof(*listener));
}
@ -156,8 +160,9 @@ static void
maybe_free_listener(controllistener_t *listener)
{
if (listener->exiting && !listener->listening &&
ISC_LIST_EMPTY(listener->connections))
ISC_LIST_EMPTY(listener->connections)) {
free_listener(listener);
}
}
static void
@ -165,11 +170,13 @@ maybe_free_connection(controlconnection_t *conn)
{
controllistener_t *listener = conn->listener;
if (conn->buffer != NULL)
if (conn->buffer != NULL) {
isc_buffer_free(&conn->buffer);
}
if (conn->timer != NULL)
if (conn->timer != NULL) {
isc_timer_detach(&conn->timer);
}
if (conn->ccmsg_valid) {
isccc_ccmsg_cancelread(&conn->ccmsg);
@ -187,7 +194,7 @@ maybe_free_connection(controlconnection_t *conn)
if (named_g_fuzz_type == isc_fuzz_rndc) {
named_fuzz_notify();
}
#endif
#endif /* ifdef ENABLE_AFL */
isc_mem_put(listener->mctx, conn, sizeof(*conn));
}
@ -207,8 +214,9 @@ shutdown_listener(controllistener_t *listener)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_CONTROL, ISC_LOG_NOTICE,
"stopping command channel on %s", socktext);
if (listener->type == isc_sockettype_unix)
if (listener->type == isc_sockettype_unix) {
isc_socket_cleanunix(&listener->address, true);
}
listener->exiting = true;
}
@ -218,9 +226,10 @@ shutdown_listener(controllistener_t *listener)
maybe_free_connection(conn);
}
if (listener->listening)
if (listener->listening) {
isc_socket_cancel(listener->sock, listener->task,
ISC_SOCKCANCEL_ACCEPT);
}
maybe_free_listener(listener);
}
@ -246,12 +255,13 @@ control_accept(controllistener_t *listener)
isc_result_t result;
result = isc_socket_accept(listener->sock, listener->task,
control_newconn, listener);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_socket_accept() failed: %s",
isc_result_totext(result));
else
} else {
listener->listening = true;
}
return (result);
}
@ -261,10 +271,11 @@ control_listen(controllistener_t *listener)
isc_result_t result;
result = isc_socket_listen(listener->sock, 0);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"isc_socket_listen() failed: %s",
isc_result_totext(result));
}
return (result);
}
@ -357,13 +368,15 @@ control_recvmessage(isc_task_t *task, isc_event_t *event)
text = NULL;
/* Is the server shutting down? */
if (listener->controls->shuttingdown)
if (listener->controls->shuttingdown) {
goto cleanup;
}
if (conn->ccmsg.result != ISC_R_SUCCESS) {
if (conn->ccmsg.result != ISC_R_CANCELED &&
conn->ccmsg.result != ISC_R_EOF)
conn->ccmsg.result != ISC_R_EOF) {
log_invalid(&conn->ccmsg, conn->ccmsg.result);
}
goto cleanup;
}
@ -381,8 +394,9 @@ control_recvmessage(isc_task_t *task, isc_event_t *event)
algorithm = key->algorithm;
result = isccc_cc_fromwire(&ccregion, &request, algorithm,
&secret);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
break;
}
isc_mem_put(listener->mctx, secret.rstart, REGION_SIZE(secret));
if (result != ISCCC_R_BADAUTH) {
log_invalid(&conn->ccmsg, result);
@ -437,8 +451,9 @@ control_recvmessage(isc_task_t *task, isc_event_t *event)
isccc_cc_cleansymtab(listener->controls->symtab, now);
result = isccc_cc_checkdup(listener->controls->symtab, request, now);
if (result != ISC_R_SUCCESS) {
if (result == ISC_R_EXISTS)
if (result == ISC_R_EXISTS) {
result = ISCCC_R_DUPLICATE;
}
log_invalid(&conn->ccmsg, result);
goto cleanup_request;
}
@ -460,40 +475,46 @@ control_recvmessage(isc_task_t *task, isc_event_t *event)
isc_nonce_buf(&conn->nonce, sizeof(conn->nonce));
}
eresult = ISC_R_SUCCESS;
} else
} else {
eresult = named_control_docommand(request, listener->readonly,
&text);
}
result = isccc_cc_createresponse(request, now, now + 60, &response);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup_request;
}
data = isccc_alist_lookup(response, "_data");
if (data != NULL) {
if (isccc_cc_defineuint32(data, "result", eresult) == NULL)
if (isccc_cc_defineuint32(data, "result", eresult) == NULL) {
goto cleanup_response;
}
}
if (eresult != ISC_R_SUCCESS) {
if (data != NULL) {
const char *estr = isc_result_totext(eresult);
if (isccc_cc_definestring(data, "err", estr) == NULL)
if (isccc_cc_definestring(data, "err", estr) == NULL) {
goto cleanup_response;
}
}
}
if (isc_buffer_usedlength(text) > 0) {
if (data != NULL) {
char *str = (char *)isc_buffer_base(text);
if (isccc_cc_definestring(data, "text", str) == NULL)
if (isccc_cc_definestring(data, "text", str) == NULL) {
goto cleanup_response;
}
}
}
_ctrl = isccc_alist_lookup(response, "_ctrl");
if (_ctrl == NULL ||
isccc_cc_defineuint32(_ctrl, "_nonce", conn->nonce) == NULL)
isccc_cc_defineuint32(_ctrl, "_nonce", conn->nonce) == NULL) {
goto cleanup_response;
}
if (conn->buffer == NULL) {
isc_buffer_allocate(listener->mctx, &conn->buffer, 2 * 2048);
@ -504,8 +525,9 @@ control_recvmessage(isc_task_t *task, isc_event_t *event)
isc_buffer_add(conn->buffer, 4);
result = isccc_cc_towire(response, &conn->buffer, algorithm, &secret);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup_response;
}
isc_buffer_init(&b, conn->buffer->base, 4);
isc_buffer_putuint32(&b, conn->buffer->used - 4);
@ -514,8 +536,9 @@ control_recvmessage(isc_task_t *task, isc_event_t *event)
r.length = conn->buffer->used;
result = isc_socket_send(conn->sock, &r, task, control_senddone, conn);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup_response;
}
conn->sending = true;
isc_mem_put(listener->mctx, secret.rstart, REGION_SIZE(secret));
@ -530,8 +553,9 @@ cleanup_response:
cleanup_request:
isccc_sexpr_free(&request);
isc_mem_put(listener->mctx, secret.rstart, REGION_SIZE(secret));
if (text != NULL)
if (text != NULL) {
isc_buffer_free(&text);
}
cleanup:
isc_socket_detach(&conn->sock);
@ -577,8 +601,9 @@ newconnection(controllistener_t *listener, isc_socket_t *sock)
result = isc_timer_create(named_g_timermgr, isc_timertype_once, NULL,
&interval, listener->task, control_timeout,
conn, &conn->timer);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
conn->listener = listener;
conn->nonce = 0;
@ -586,24 +611,27 @@ newconnection(controllistener_t *listener, isc_socket_t *sock)
result = isccc_ccmsg_readmessage(&conn->ccmsg, listener->task,
control_recvmessage, conn);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
ISC_LIST_APPEND(listener->connections, conn, link);
return (ISC_R_SUCCESS);
cleanup:
if (conn->buffer != NULL)
if (conn->buffer != NULL) {
isc_buffer_free(&conn->buffer);
}
isccc_ccmsg_invalidate(&conn->ccmsg);
if (conn->timer != NULL)
if (conn->timer != NULL) {
isc_timer_detach(&conn->timer);
}
isc_mem_put(listener->mctx, conn, sizeof(*conn));
#ifdef ENABLE_AFL
if (named_g_fuzz_type == isc_fuzz_rndc) {
named_fuzz_notify();
}
#endif
#endif /* ifdef ENABLE_AFL */
return (result);
}
@ -697,11 +725,13 @@ cfgkeylist_find(const cfg_obj_t *keylist, const char *keyname,
element = cfg_list_next(element)) {
obj = cfg_listelt_value(element);
str = cfg_obj_asstring(cfg_map_getname(obj));
if (strcasecmp(str, keyname) == 0)
if (strcasecmp(str, keyname) == 0) {
break;
}
}
if (element == NULL)
if (element == NULL) {
return (ISC_R_NOTFOUND);
}
obj = cfg_listelt_value(element);
*objp = obj;
return (ISC_R_SUCCESS);
@ -836,8 +866,9 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_CONTROL, ISC_LOG_INFO,
"configuring command channel from '%s'", named_g_keyfile);
if (!isc_file_exists(named_g_keyfile))
if (!isc_file_exists(named_g_keyfile)) {
return (ISC_R_FILENOTFOUND);
}
CHECK(cfg_parser_create(mctx, named_g_lctx, &pctx));
CHECK(cfg_parse_file(pctx, named_g_keyfile, &cfg_type_rndckey,
@ -851,8 +882,9 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids)
keyid->secret.length = 0;
keyid->algorithm = DST_ALG_UNKNOWN;
ISC_LINK_INIT(keyid, link);
if (keyid->keyname == NULL)
if (keyid->keyname == NULL) {
CHECK(ISC_R_NOMEMORY);
}
CHECK(bind9_check_key(key, named_g_lctx));
@ -892,12 +924,15 @@ get_rndckey(isc_mem_t *mctx, controlkeylist_t *keyids)
result = ISC_R_SUCCESS;
cleanup:
if (keyid != NULL)
if (keyid != NULL) {
free_controlkey(keyid, mctx);
if (config != NULL)
}
if (config != NULL) {
cfg_obj_destroy(pctx, &config);
if (pctx != NULL)
}
if (pctx != NULL) {
cfg_parser_destroy(&pctx);
}
return (result);
}
@ -948,7 +983,6 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
listener = ISC_LIST_NEXT(listener, link)) {
if (isc_sockaddr_equal(addr, &listener->address)) {
break;
}
}
@ -977,9 +1011,10 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
* channel reload, then the response will be with the new key
* and not able to be decrypted by the client.
*/
if (control != NULL)
if (control != NULL) {
get_key_info(config, control, &global_keylist,
&control_keylist);
}
if (control_keylist != NULL) {
INSIST(global_keylist != NULL);
@ -1002,17 +1037,18 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
* but tracking whether they are identical just for the
* sake of avoiding this message would be too much trouble.
*/
if (control != NULL)
if (control != NULL) {
cfg_obj_log(control, named_g_lctx, ISC_LOG_WARNING,
"couldn't install new keys for "
"command channel %s: %s",
socktext, isc_result_totext(result));
else
} else {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_CONTROL, ISC_LOG_WARNING,
"couldn't install new keys for "
"command channel %s: %s",
socktext, isc_result_totext(result));
}
}
/*
@ -1031,8 +1067,9 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
const cfg_obj_t *readonly;
readonly = cfg_tuple_get(control, "read-only");
if (!cfg_obj_isvoid(readonly))
if (!cfg_obj_isvoid(readonly)) {
listener->readonly = cfg_obj_asboolean(readonly);
}
}
if (result == ISC_R_SUCCESS) {
@ -1040,17 +1077,18 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
dns_acl_attach(new_acl, &listener->acl);
dns_acl_detach(&new_acl);
/* XXXDCL say the old acl is still used? */
} else if (control != NULL)
} else if (control != NULL) {
cfg_obj_log(control, named_g_lctx, ISC_LOG_WARNING,
"couldn't install new acl for "
"command channel %s: %s",
socktext, isc_result_totext(result));
else
} else {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_CONTROL, ISC_LOG_WARNING,
"couldn't install new acl for "
"command channel %s: %s",
socktext, isc_result_totext(result));
}
if (result == ISC_R_SUCCESS && type == isc_sockettype_unix) {
uint32_t perm, owner, group;
@ -1059,18 +1097,20 @@ update_listener(named_controls_t *cp, controllistener_t **listenerp,
group = cfg_obj_asuint32(cfg_tuple_get(control, "group"));
result = ISC_R_SUCCESS;
if (listener->perm != perm || listener->owner != owner ||
listener->group != group)
listener->group != group) {
result = isc_socket_permunix(&listener->address, perm,
owner, group);
}
if (result == ISC_R_SUCCESS) {
listener->perm = perm;
listener->owner = owner;
listener->group = group;
} else if (control != NULL)
} else if (control != NULL) {
cfg_obj_log(control, named_g_lctx, ISC_LOG_WARNING,
"couldn't update ownership/permission for "
"command channel %s",
socktext);
}
}
*listenerp = listener;
@ -1128,17 +1168,19 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
const cfg_obj_t *readonly;
readonly = cfg_tuple_get(control, "read-only");
if (!cfg_obj_isvoid(readonly))
if (!cfg_obj_isvoid(readonly)) {
listener->readonly = cfg_obj_asboolean(readonly);
}
}
if (result == ISC_R_SUCCESS) {
dns_acl_attach(new_acl, &listener->acl);
dns_acl_detach(&new_acl);
if (config != NULL)
if (config != NULL) {
get_key_info(config, control, &global_keylist,
&control_keylist);
}
if (control_keylist != NULL) {
controlkeylist_fromcfg(control_keylist, listener->mctx,
@ -1149,11 +1191,12 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
result = get_rndckey(mctx, &listener->keys);
}
if (result != ISC_R_SUCCESS && control != NULL)
if (result != ISC_R_SUCCESS && control != NULL) {
cfg_obj_log(control, named_g_lctx, ISC_LOG_WARNING,
"couldn't install keys for "
"command channel %s: %s",
socktext, isc_result_totext(result));
}
}
if (result == ISC_R_SUCCESS) {
@ -1161,29 +1204,35 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
if ((pf == AF_INET && isc_net_probeipv4() != ISC_R_SUCCESS) ||
#ifdef ISC_PLATFORM_HAVESYSUNH
(pf == AF_UNIX && isc_net_probeunix() != ISC_R_SUCCESS) ||
#endif
(pf == AF_INET6 && isc_net_probeipv6() != ISC_R_SUCCESS))
#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */
(pf == AF_INET6 && isc_net_probeipv6() != ISC_R_SUCCESS)) {
result = ISC_R_FAMILYNOSUPPORT;
}
}
if (result == ISC_R_SUCCESS && type == isc_sockettype_unix)
if (result == ISC_R_SUCCESS && type == isc_sockettype_unix) {
isc_socket_cleanunix(&listener->address, false);
}
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
result = isc_socket_create(named_g_socketmgr,
isc_sockaddr_pf(&listener->address),
type, &listener->sock);
if (result == ISC_R_SUCCESS)
}
if (result == ISC_R_SUCCESS) {
isc_socket_setname(listener->sock, "control", NULL);
}
#ifndef ISC_ALLOW_MAPPED
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
isc_socket_ipv6only(listener->sock, true);
#endif
}
#endif /* ifndef ISC_ALLOW_MAPPED */
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
result = isc_socket_bind(listener->sock, &listener->address,
ISC_SOCKET_REUSEADDRESS);
}
if (result == ISC_R_SUCCESS && type == isc_sockettype_unix) {
listener->perm = cfg_obj_asuint32(cfg_tuple_get(control, "per"
@ -1195,33 +1244,35 @@ add_listener(named_controls_t *cp, controllistener_t **listenerp,
result = isc_socket_permunix(&listener->address, listener->perm,
listener->owner, listener->group);
}
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
result = control_listen(listener);
}
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
result = control_accept(listener);
}
if (result == ISC_R_SUCCESS) {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_CONTROL, ISC_LOG_NOTICE,
"command channel listening on %s", socktext);
*listenerp = listener;
} else {
if (listener != NULL) {
listener->exiting = true;
free_listener(listener);
}
if (control != NULL)
if (control != NULL) {
cfg_obj_log(control, named_g_lctx, ISC_LOG_WARNING,
"couldn't add command channel %s: %s",
socktext, isc_result_totext(result));
else
} else {
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_CONTROL, ISC_LOG_NOTICE,
"couldn't add command channel %s: %s",
socktext, isc_result_totext(result));
}
*listenerp = NULL;
}
@ -1262,8 +1313,9 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
controls = cfg_listelt_value(element);
(void)cfg_map_get(controls, "inet", &inetcontrols);
if (inetcontrols == NULL)
if (inetcontrols == NULL) {
continue;
}
for (element2 = cfg_list_first(inetcontrols);
element2 != NULL;
@ -1281,9 +1333,10 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
obj = cfg_tuple_get(control, "address");
addr = *cfg_obj_assockaddr(obj);
if (isc_sockaddr_getport(&addr) == 0)
if (isc_sockaddr_getport(&addr) == 0) {
isc_sockaddr_setport(
&addr, NAMED_CONTROL_PORT);
}
isc_sockaddr_format(&addr, socktext,
sizeof(socktext));
@ -1299,14 +1352,14 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
&addr, aclconfctx, socktext,
isc_sockettype_tcp);
if (listener != NULL)
if (listener != NULL) {
/*
* Remove the listener from the old
* list, so it won't be shut down.
*/
ISC_LIST_UNLINK(cp->listeners, listener,
link);
else
} else {
/*
* This is a new listener.
*/
@ -1314,10 +1367,12 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
config, &addr, aclconfctx,
socktext,
isc_sockettype_tcp);
}
if (listener != NULL)
if (listener != NULL) {
ISC_LIST_APPEND(new_listeners, listener,
link);
}
}
}
for (element = cfg_list_first(controlslist); element != NULL;
@ -1327,8 +1382,9 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
controls = cfg_listelt_value(element);
(void)cfg_map_get(controls, "unix", &unixcontrols);
if (unixcontrols == NULL)
if (unixcontrols == NULL) {
continue;
}
for (element2 = cfg_list_first(unixcontrols);
element2 != NULL;
@ -1372,14 +1428,14 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
cfg_obj_asstring(path),
isc_sockettype_unix);
if (listener != NULL)
if (listener != NULL) {
/*
* Remove the listener from the old
* list, so it won't be shut down.
*/
ISC_LIST_UNLINK(cp->listeners, listener,
link);
else
} else {
/*
* This is a new listener.
*/
@ -1387,10 +1443,12 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
config, &addr, aclconfctx,
cfg_obj_asstring(path),
isc_sockettype_unix);
}
if (listener != NULL)
if (listener != NULL) {
ISC_LIST_APPEND(new_listeners, listener,
link);
}
}
}
} else {
@ -1402,13 +1460,15 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
if (i == 0) {
struct in_addr localhost;
if (isc_net_probeipv4() != ISC_R_SUCCESS)
if (isc_net_probeipv4() != ISC_R_SUCCESS) {
continue;
}
localhost.s_addr = htonl(INADDR_LOOPBACK);
isc_sockaddr_fromin(&addr, &localhost, 0);
} else {
if (isc_net_probeipv6() != ISC_R_SUCCESS)
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
continue;
}
isc_sockaddr_fromin6(&addr, &in6addr_loopback,
0);
}
@ -1419,22 +1479,24 @@ named_controls_configure(named_controls_t *cp, const cfg_obj_t *config,
update_listener(cp, &listener, NULL, NULL, &addr, NULL,
socktext, isc_sockettype_tcp);
if (listener != NULL)
if (listener != NULL) {
/*
* Remove the listener from the old
* list, so it won't be shut down.
*/
ISC_LIST_UNLINK(cp->listeners, listener, link);
else
} else {
/*
* This is a new listener.
*/
add_listener(cp, &listener, NULL, NULL, &addr,
NULL, socktext,
isc_sockettype_tcp);
}
if (listener != NULL)
if (listener != NULL) {
ISC_LIST_APPEND(new_listeners, listener, link);
}
}
}
@ -1462,8 +1524,9 @@ named_controls_create(named_server_t *server, named_controls_t **ctrlsp)
isc_result_t result;
named_controls_t *controls = isc_mem_get(mctx, sizeof(*controls));
if (controls == NULL)
if (controls == NULL) {
return (ISC_R_NOMEMORY);
}
controls->server = server;
ISC_LIST_INIT(controls->listeners);
controls->shuttingdown = false;

View file

@ -100,9 +100,9 @@ fuzz_thread_client(void *arg)
*/
#ifdef __AFL_LOOP
for (int loop = 0; loop < 100000; loop++) {
#else
#else /* ifdef __AFL_LOOP */
{
#endif
#endif /* ifdef __AFL_LOOP */
ssize_t length;
ssize_t sent;
@ -146,8 +146,9 @@ fuzz_thread_client(void *arg)
*/
(void)recvfrom(sockfd, buf, 65536, MSG_DONTWAIT, NULL, NULL);
while (!ready)
while (!ready) {
pthread_cond_wait(&cond, &mutex);
}
RUNTIME_CHECK(pthread_mutex_unlock(&mutex) == 0);
next:;
@ -449,8 +450,9 @@ fuzz_thread_resolver(void *arg)
/* Skip the name to get to the qtype */
i = 0;
while (((llen = nameptr[i]) != 0) && (i < 255) &&
(((nameptr + i + 1 + llen) - buf) < length))
(((nameptr + i + 1 + llen) - buf) < length)) {
i += 1 + llen;
}
if (i <= 255) {
nameptr += 1 + i;
@ -521,8 +523,9 @@ fuzz_thread_resolver(void *arg)
/* Skip the name to get to the qtype */
i = 0;
while (((llen = nameptr[i]) != 0) && (i < 255) &&
(((nameptr + i + 1 + llen) - buf) < length))
(((nameptr + i + 1 + llen) - buf) < length)) {
i += 1 + llen;
}
if (i <= 255) {
nameptr += 1 + i;
@ -557,8 +560,9 @@ fuzz_thread_resolver(void *arg)
RUNTIME_CHECK(sent == length);
}
while (!ready)
while (!ready) {
pthread_cond_wait(&cond, &mutex);
}
RUNTIME_CHECK(pthread_mutex_unlock(&mutex) == 0);
}
@ -579,7 +583,7 @@ fuzz_thread_resolver(void *arg)
* in persistent mode if it's present.
*/
__AFL_LOOP(0);
#endif
#endif /* ifdef __AFL_LOOP */
return (NULL);
}
@ -688,8 +692,9 @@ fuzz_thread_tcp(void *arg)
do {
r = connect(sockfd, (struct sockaddr *)&servaddr,
sizeof(servaddr));
if (r != 0)
if (r != 0) {
usleep(10000);
}
} while (r != 0);
/*
@ -700,8 +705,9 @@ fuzz_thread_tcp(void *arg)
close(sockfd);
while (!ready)
while (!ready) {
pthread_cond_wait(&cond, &mutex);
}
RUNTIME_CHECK(pthread_mutex_unlock(&mutex) == 0);
}

View file

@ -13,7 +13,7 @@
#if defined(HAVE_GEOIP2)
#include <maxminddb.h>
#endif
#endif /* if defined(HAVE_GEOIP2) */
#include <isc/print.h>
#include <isc/string.h>
@ -69,9 +69,9 @@ named_geoip_init(void)
if (named_g_geoip == NULL) {
named_g_geoip = &geoip_table;
}
#else
#else /* if defined(HAVE_GEOIP2) */
return;
#endif
#endif /* if defined(HAVE_GEOIP2) */
}
void
@ -106,11 +106,11 @@ named_geoip_load(char *dir)
named_g_geoip->isp = open_geoip2(dir, "GeoIP2-ISP.mmdb", &geoip_isp);
named_g_geoip->domain =
open_geoip2(dir, "GeoIP2-Domain.mmdb", &geoip_domain);
#else
#else /* if defined(HAVE_GEOIP2) */
UNUSED(dir);
return;
#endif
#endif /* if defined(HAVE_GEOIP2) */
}
void
@ -137,7 +137,7 @@ named_geoip_unload(void)
MMDB_close(named_g_geoip->domain);
named_g_geoip->domain = NULL;
}
#endif
#endif /* ifdef HAVE_GEOIP2 */
}
void

View file

@ -17,4 +17,4 @@ dlz_dlopen_init(isc_mem_t *mctx);
void
dlz_dlopen_clear(void);
#endif
#endif /* ifndef DLZ_DLOPEN_DRIVER_H */

View file

@ -36,14 +36,14 @@
#ifdef NAMED_MAIN
#define EXTERN
#define INIT(v) = (v)
#else
#else /* ifdef NAMED_MAIN */
#define EXTERN extern
#define INIT(v)
#endif
#endif /* ifdef NAMED_MAIN */
#ifndef NAMED_RUN_PID_DIR
#define NAMED_RUN_PID_DIR 1
#endif
#endif /* ifndef NAMED_RUN_PID_DIR */
EXTERN isc_mem_t *named_g_mctx INIT(NULL);
EXTERN unsigned int named_g_cpus INIT(0);
@ -54,7 +54,7 @@ EXTERN unsigned int named_g_cpus_detected INIT(1);
#ifdef ENABLE_AFL
EXTERN bool named_g_run_done INIT(false);
#endif
#endif /* ifdef ENABLE_AFL */
/*
* XXXRTH We're going to want multiple timer managers eventually. One
* for really short timers, another for client timers, and one
@ -128,10 +128,10 @@ EXTERN bool named_g_forcelock INIT(false);
#if NAMED_RUN_PID_DIR
EXTERN const char *named_g_defaultpidfile INIT(NAMED_LOCALSTATEDIR "/run/named/"
"named.pid");
#else
#else /* if NAMED_RUN_PID_DIR */
EXTERN const char *named_g_defaultpidfile INIT(NAMED_LOCALSTATEDIR "/run/"
"named.pid");
#endif
#endif /* if NAMED_RUN_PID_DIR */
EXTERN const char *named_g_username INIT(NULL);
@ -146,7 +146,7 @@ EXTERN unsigned int named_g_tat_interval INIT(24 * 3600);
#if defined(HAVE_GEOIP2)
EXTERN dns_geoip_databases_t *named_g_geoip INIT(NULL);
#endif
#endif /* if defined(HAVE_GEOIP2) */
EXTERN const char *named_g_fuzz_addr INIT(NULL);
EXTERN isc_fuzztype_t named_g_fuzz_type INIT(isc_fuzz_none);

View file

@ -16,7 +16,7 @@
#ifdef ISC_MAIN_HOOK
#define main(argc, argv) bindmain(argc, argv)
#endif
#endif /* ifdef ISC_MAIN_HOOK */
/*
* Commandline arguments for named; also referenced in win32/ntservice.c

View file

@ -53,12 +53,16 @@ struct named_server {
char *statsfile; /*%< Statistics file name */
char *dumpfile; /*%< Dump file name */
char *secrootsfile; /*%< Secroots file name */
char *bindkeysfile; /*%< bind.keys file name */
char *bindkeysfile; /*%< bind.keys file name
* */
char *recfile; /*%< Recursive file name */
bool version_set; /*%< User has set version */
bool version_set; /*%< User has set version
* */
char *version; /*%< User-specified version */
bool hostname_set; /*%< User has set hostname */
char *hostname; /*%< User-specified hostname */
bool hostname_set; /*%< User has set hostname
* */
char *hostname; /*%< User-specified hostname
* */
/* Server data structures. */
dns_loadmgr_t * loadmgr;
@ -82,10 +86,11 @@ struct named_server {
bool flushonshutdown;
named_cachelist_t cachelist; /*%< Possibly shared caches */
isc_stats_t * zonestats; /*% Zone management stats */
isc_stats_t * resolverstats; /*% Resolver stats */
isc_stats_t * sockstats; /*%< Socket stats */
named_cachelist_t cachelist; /*%< Possibly shared caches
* */
isc_stats_t *zonestats; /*% Zone management stats */
isc_stats_t *resolverstats; /*% Resolver stats */
isc_stats_t *sockstats; /*%< Socket stats */
named_controls_t * controls; /*%< Control channels */
unsigned int dispatchgen;

View file

@ -19,10 +19,10 @@
#ifdef NAMED_MAIN
#define EXTERN
#define INIT(v) = (v)
#else
#else /* ifdef NAMED_MAIN */
#define EXTERN extern
#define INIT(v)
#endif
#endif /* ifdef NAMED_MAIN */
EXTERN unsigned int named_smf_got_instance INIT(0);
EXTERN unsigned int named_smf_chroot INIT(0);

View file

@ -23,7 +23,7 @@
#ifndef ISC_FACILITY
#define ISC_FACILITY LOG_DAEMON
#endif
#endif /* ifndef ISC_FACILITY */
/*%
* When adding a new category, be sure to add the appropriate
@ -55,8 +55,9 @@ named_log_init(bool safe)
* Setup a logging context.
*/
result = isc_log_create(named_g_mctx, &named_g_lctx, &lcfg);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
/*
* named-checktool.c:setup_logging() needs to be kept in sync.
@ -70,16 +71,19 @@ named_log_init(bool safe)
ns_log_init(named_g_lctx);
ns_log_setcontext(named_g_lctx);
if (safe)
if (safe) {
result = named_log_setsafechannels(lcfg);
else
} else {
result = named_log_setdefaultchannels(lcfg);
if (result != ISC_R_SUCCESS)
}
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = named_log_setdefaultcategory(lcfg);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
return (ISC_R_SUCCESS);
@ -110,8 +114,9 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg)
result = isc_log_createchannel(
lcfg, "default_debug", ISC_LOG_TOFILE, ISC_LOG_DYNAMIC,
&destination, ISC_LOG_PRINTTIME | ISC_LOG_DEBUGONLY);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
}
if (named_g_logfile != NULL) {
@ -124,17 +129,19 @@ named_log_setdefaultchannels(isc_logconfig_t *lcfg)
ISC_LOG_DYNAMIC, &destination,
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY |
ISC_LOG_PRINTLEVEL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
}
#if ISC_FACILITY != LOG_DAEMON
destination.facility = ISC_FACILITY;
result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG,
ISC_LOG_INFO, &destination, 0);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
#endif
}
#endif /* if ISC_FACILITY != LOG_DAEMON */
/*
* Set the initial debug level.
@ -157,8 +164,9 @@ named_log_setsafechannels(isc_logconfig_t *lcfg)
result = isc_log_createchannel(lcfg, "default_debug",
ISC_LOG_TONULL, ISC_LOG_DYNAMIC,
NULL, 0);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
/*
* Setting the debug level to zero should get the output
@ -179,17 +187,19 @@ named_log_setsafechannels(isc_logconfig_t *lcfg)
ISC_LOG_DYNAMIC, &destination,
ISC_LOG_PRINTTIME | ISC_LOG_PRINTCATEGORY |
ISC_LOG_PRINTLEVEL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
}
#if ISC_FACILITY != LOG_DAEMON
destination.facility = ISC_FACILITY;
result = isc_log_createchannel(lcfg, "default_syslog", ISC_LOG_TOSYSLOG,
ISC_LOG_INFO, &destination, 0);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
#endif
}
#endif /* if ISC_FACILITY != LOG_DAEMON */
result = ISC_R_SUCCESS;
@ -204,18 +214,20 @@ named_log_setdefaultcategory(isc_logconfig_t *lcfg)
result = isc_log_usechannel(lcfg, "default_debug",
ISC_LOGCATEGORY_DEFAULT, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
if (!named_g_logstderr) {
if (named_g_logfile != NULL)
if (named_g_logfile != NULL) {
result = isc_log_usechannel(lcfg, "default_logfile",
ISC_LOGCATEGORY_DEFAULT,
NULL);
else if (!named_g_nosyslog)
} else if (!named_g_nosyslog) {
result = isc_log_usechannel(lcfg, "default_syslog",
ISC_LOGCATEGORY_DEFAULT,
NULL);
}
}
cleanup:

View file

@ -61,8 +61,9 @@ category_fromconf(const cfg_obj_t *ccat, isc_logconfig_t *logconfig)
return (ISC_R_SUCCESS);
}
if (logconfig == NULL)
if (logconfig == NULL) {
return (ISC_R_SUCCESS);
}
module = NULL;
@ -113,14 +114,18 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig)
(void)cfg_map_get(channel, "stderr", &stderrobj);
i = 0;
if (fileobj != NULL)
if (fileobj != NULL) {
i++;
if (syslogobj != NULL)
}
if (syslogobj != NULL) {
i++;
if (nullobj != NULL)
}
if (nullobj != NULL) {
i++;
if (stderrobj != NULL)
}
if (stderrobj != NULL) {
i++;
}
if (i != 1) {
cfg_obj_log(channel, named_g_lctx, ISC_LOG_ERROR,
@ -161,18 +166,23 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig)
type = ISC_LOG_TOFILE;
if (versionsobj != NULL && cfg_obj_isuint32(versionsobj))
if (versionsobj != NULL && cfg_obj_isuint32(versionsobj)) {
versions = cfg_obj_asuint32(versionsobj);
else if (versionsobj != NULL && cfg_obj_isstring(versionsobj) &&
strcasecmp(cfg_obj_asstring(versionsobj), "unlimite"
"d") == 0)
} else if (versionsobj != NULL &&
cfg_obj_isstring(versionsobj) &&
strcasecmp(cfg_obj_asstring(versionsobj),
"unlimite"
"d") == 0) {
versions = ISC_LOG_ROLLINFINITE;
}
if (sizeobj != NULL && cfg_obj_isuint64(sizeobj) &&
cfg_obj_asuint64(sizeobj) < maxoffset)
cfg_obj_asuint64(sizeobj) < maxoffset) {
size = (isc_offset_t)cfg_obj_asuint64(sizeobj);
}
if (suffixobj != NULL && cfg_obj_isstring(suffixobj) &&
strcasecmp(cfg_obj_asstring(suffixobj), "timestamp") == 0)
strcasecmp(cfg_obj_asstring(suffixobj), "timestamp") == 0) {
suffix = isc_log_rollsuffix_timestamp;
}
dest.file.stream = NULL;
dest.file.name = cfg_obj_asstring(pathobj);
@ -213,22 +223,27 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig)
(void)cfg_map_get(channel, "print-time", &printtime);
(void)cfg_map_get(channel, "buffered", &buffered);
if (printcat != NULL && cfg_obj_asboolean(printcat))
if (printcat != NULL && cfg_obj_asboolean(printcat)) {
flags |= ISC_LOG_PRINTCATEGORY;
if (printsev != NULL && cfg_obj_asboolean(printsev))
}
if (printsev != NULL && cfg_obj_asboolean(printsev)) {
flags |= ISC_LOG_PRINTLEVEL;
if (buffered != NULL && cfg_obj_asboolean(buffered))
}
if (buffered != NULL && cfg_obj_asboolean(buffered)) {
flags |= ISC_LOG_BUFFERED;
}
if (printtime != NULL && cfg_obj_isboolean(printtime)) {
if (cfg_obj_asboolean(printtime))
if (cfg_obj_asboolean(printtime)) {
flags |= ISC_LOG_PRINTTIME;
}
} else if (printtime != NULL) { /* local/iso8601/iso8601-utc */
const char *s = cfg_obj_asstring(printtime);
flags |= ISC_LOG_PRINTTIME;
if (strcasecmp(s, "iso8601") == 0)
if (strcasecmp(s, "iso8601") == 0) {
flags |= ISC_LOG_ISO8601;
else if (strcasecmp(s, "iso8601-utc") == 0)
} else if (strcasecmp(s, "iso8601-utc") == 0) {
flags |= ISC_LOG_ISO8601 | ISC_LOG_UTC;
}
}
}
@ -236,28 +251,31 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig)
if (cfg_map_get(channel, "severity", &severity) == ISC_R_SUCCESS) {
if (cfg_obj_isstring(severity)) {
const char *str = cfg_obj_asstring(severity);
if (strcasecmp(str, "critical") == 0)
if (strcasecmp(str, "critical") == 0) {
level = ISC_LOG_CRITICAL;
else if (strcasecmp(str, "error") == 0)
} else if (strcasecmp(str, "error") == 0) {
level = ISC_LOG_ERROR;
else if (strcasecmp(str, "warning") == 0)
} else if (strcasecmp(str, "warning") == 0) {
level = ISC_LOG_WARNING;
else if (strcasecmp(str, "notice") == 0)
} else if (strcasecmp(str, "notice") == 0) {
level = ISC_LOG_NOTICE;
else if (strcasecmp(str, "info") == 0)
} else if (strcasecmp(str, "info") == 0) {
level = ISC_LOG_INFO;
else if (strcasecmp(str, "dynamic") == 0)
} else if (strcasecmp(str, "dynamic") == 0) {
level = ISC_LOG_DYNAMIC;
} else
}
} else {
/* debug */
level = cfg_obj_asuint32(severity);
}
}
if (logconfig == NULL)
if (logconfig == NULL) {
result = ISC_R_SUCCESS;
else
} else {
result = isc_log_createchannel(logconfig, channelname, type,
level, &dest, flags);
}
if (result == ISC_R_SUCCESS && type == ISC_LOG_TOFILE) {
FILE *fp;
@ -275,23 +293,26 @@ channel_fromconf(const cfg_obj_t *channel, isc_logconfig_t *logconfig)
*/
result = isc_stdio_open(dest.file.name, "a", &fp);
if (result != ISC_R_SUCCESS) {
if (logconfig != NULL && !named_g_nosyslog)
if (logconfig != NULL && !named_g_nosyslog) {
syslog(LOG_ERR,
"isc_stdio_open '%s' failed: "
"%s",
dest.file.name,
isc_result_totext(result));
}
fprintf(stderr,
"isc_stdio_open '%s' failed: %s\n",
dest.file.name,
isc_result_totext(result));
} else
} else {
(void)isc_stdio_close(fp);
}
goto done;
}
if (logconfig != NULL && !named_g_nosyslog)
if (logconfig != NULL && !named_g_nosyslog) {
syslog(LOG_ERR, "isc_file_isplainfile '%s' failed: %s",
dest.file.name, isc_result_totext(result));
}
fprintf(stderr, "isc_file_isplainfile '%s' failed: %s\n",
dest.file.name, isc_result_totext(result));
}
@ -311,8 +332,9 @@ named_logconfig(isc_logconfig_t *logconfig, const cfg_obj_t *logstmt)
bool unmatched_set = false;
const cfg_obj_t * catname;
if (logconfig != NULL)
if (logconfig != NULL) {
CHECK(named_log_setdefaultchannels(logconfig));
}
(void)cfg_map_get(logstmt, "channel", &channels);
for (element = cfg_list_first(channels); element != NULL;
@ -328,21 +350,26 @@ named_logconfig(isc_logconfig_t *logconfig, const cfg_obj_t *logstmt)
CHECK(category_fromconf(category, logconfig));
if (!default_set) {
catname = cfg_tuple_get(category, "name");
if (strcmp(cfg_obj_asstring(catname), "default") == 0)
if (strcmp(cfg_obj_asstring(catname), "default") == 0) {
default_set = true;
}
}
if (!unmatched_set) {
catname = cfg_tuple_get(category, "name");
if (strcmp(cfg_obj_asstring(catname), "unmatched") == 0)
if (strcmp(cfg_obj_asstring(catname), "unmatched") ==
0) {
unmatched_set = true;
}
}
}
if (logconfig != NULL && !default_set)
if (logconfig != NULL && !default_set) {
CHECK(named_log_setdefaultcategory(logconfig));
}
if (logconfig != NULL && !unmatched_set)
if (logconfig != NULL && !unmatched_set) {
CHECK(named_log_setunmatchedcategory(logconfig));
}
return (ISC_R_SUCCESS);

View file

@ -47,13 +47,13 @@
#include <isccc/result.h>
#if USE_PKCS11
#include <pk11/result.h>
#endif
#endif /* if USE_PKCS11 */
#include <dlz/dlz_dlopen_driver.h>
#ifdef HAVE_GPERFTOOLS_PROFILER
#include <gperftools/profiler.h>
#endif
#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */
#ifdef HAVE_JSON_C
#include <json_c_version.h>
@ -61,7 +61,7 @@
#ifdef HAVE_GEOIP2
#include <maxminddb.h>
#endif
#endif /* ifdef HAVE_GEOIP2 */
/*
* Defining NAMED_MAIN provides storage declarations (rather than extern)
@ -82,17 +82,17 @@
#include <named/server.h>
#ifdef HAVE_LIBSCF
#include <named/smf_globals.h>
#endif
#endif /* ifdef HAVE_LIBSCF */
#include <openssl/crypto.h>
#include <openssl/opensslv.h>
#ifdef HAVE_LIBXML2
#include <libxml/parser.h>
#include <libxml/xmlversion.h>
#endif
#endif /* ifdef HAVE_LIBXML2 */
#ifdef HAVE_ZLIB
#include <zlib.h>
#endif
#endif /* ifdef HAVE_ZLIB */
/*
* Include header files for database drivers here.
*/
@ -103,14 +103,14 @@
* Include contributed DLZ drivers if appropriate.
*/
#include <dlz/dlz_drivers.h>
#endif
#endif /* ifdef CONTRIB_DLZ */
/*
* The maximum number of stack frames to dump on assertion failure.
*/
#ifndef BACKTRACE_MAXFRAME
#define BACKTRACE_MAXFRAME 128
#endif
#endif /* ifndef BACKTRACE_MAXFRAME */
LIBISC_EXTERNAL_DATA extern int isc_dscp_check_value;
LIBDNS_EXTERNAL_DATA extern unsigned int dns_zone_mkey_hour;
@ -217,8 +217,9 @@ assertion_failed(const char *file, int line, isc_assertiontype_t type,
result = isc_backtrace_gettrace(tracebuf, BACKTRACE_MAXFRAME,
&nframes);
if (result == ISC_R_SUCCESS && nframes > 0)
if (result == ISC_R_SUCCESS && nframes > 0) {
logsuffix = ", back trace";
}
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_CRITICAL,
"%s:%d: %s(%s) failed%s", file, line,
@ -257,8 +258,9 @@ assertion_failed(const char *file, int line, isc_assertiontype_t type,
fflush(stderr);
}
if (named_g_coreok)
if (named_g_coreok) {
abort();
}
exit(1);
}
@ -298,8 +300,9 @@ library_fatal_error(const char *file, int line, const char *format,
fflush(stderr);
}
if (named_g_coreok)
if (named_g_coreok) {
abort();
}
exit(1);
}
@ -424,10 +427,12 @@ parse_int(char *arg, const char *desc)
ltmp = strtol(arg, &endp, 10);
tmp = (int)ltmp;
if (*endp != '\0')
if (*endp != '\0') {
named_main_earlyfatal("%s '%s' must be numeric", desc, arg);
if (tmp < 0 || tmp != ltmp)
}
if (tmp < 0 || tmp != ltmp) {
named_main_earlyfatal("%s '%s' out of range", desc, arg);
}
return (tmp);
}
@ -456,30 +461,35 @@ set_flags(const char *arg, struct flag_def *defs, unsigned int *ret)
const struct flag_def *def;
const char * end = strchr(arg, ',');
int arglen;
if (end == NULL)
if (end == NULL) {
end = arg + strlen(arg);
}
arglen = (int)(end - arg);
for (def = defs; def->name != NULL; def++) {
if (arglen == (int)strlen(def->name) &&
memcmp(arg, def->name, arglen) == 0) {
if (def->value == 0)
if (def->value == 0) {
clear = true;
if (def->negate)
}
if (def->negate) {
*ret &= ~(def->value);
else
} else {
*ret |= def->value;
}
goto found;
}
}
named_main_earlyfatal("unrecognized flag '%.*s'", arglen, arg);
found:
if (clear || (*end == '\0'))
if (clear || (*end == '\0')) {
break;
}
arg = end + 1;
}
if (clear)
if (clear) {
*ret = 0;
}
}
static void
@ -491,7 +501,7 @@ printversion(bool verbose)
cfg_parser_t * parser = NULL;
cfg_obj_t * config = NULL;
const cfg_obj_t *defaults = NULL, *obj = NULL;
#endif
#endif /* if defined(HAVE_GEOIP2) */
printf("%s %s%s%s <id:%s>\n", named_g_product, named_g_version,
(*named_g_description != '\0') ? " " : "", named_g_description,
@ -505,51 +515,52 @@ printversion(bool verbose)
printf("built by %s with %s\n", named_g_builder, named_g_configargs);
#ifdef __clang__
printf("compiled by CLANG %s\n", __VERSION__);
#else
#else /* ifdef __clang__ */
#if defined(__ICC) || defined(__INTEL_COMPILER)
printf("compiled by ICC %s\n", __VERSION__);
#else
#else /* if defined(__ICC) || defined(__INTEL_COMPILER) */
#ifdef __GNUC__
printf("compiled by GCC %s\n", __VERSION__);
#endif
#endif
#endif
#endif /* ifdef __GNUC__ */
#endif /* if defined(__ICC) || defined(__INTEL_COMPILER) */
#endif /* ifdef __clang__ */
#ifdef _MSC_VER
printf("compiled by MSVC %d\n", _MSC_VER);
#endif
#endif /* ifdef _MSC_VER */
#ifdef __SUNPRO_C
printf("compiled by Solaris Studio %x\n", __SUNPRO_C);
#endif
#endif /* ifdef __SUNPRO_C */
printf("compiled with OpenSSL version: %s\n", OPENSSL_VERSION_TEXT);
#if !defined(LIBRESSL_VERSION_NUMBER) && \
OPENSSL_VERSION_NUMBER >= 0x10100000L /* 1.1.0 or higher */
printf("linked to OpenSSL version: %s\n",
OpenSSL_version(OPENSSL_VERSION));
#else
#else /* if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= \
* 0x10100000L */
printf("linked to OpenSSL version: %s\n",
SSLeay_version(SSLEAY_VERSION));
#endif /* OPENSSL_VERSION_NUMBER >= 0x10100000L */
#ifdef HAVE_LIBXML2
printf("compiled with libxml2 version: %s\n", LIBXML_DOTTED_VERSION);
printf("linked to libxml2 version: %s\n", xmlParserVersion);
#endif
#endif /* ifdef HAVE_LIBXML2 */
#if defined(HAVE_JSON_C)
printf("compiled with json-c version: %s\n", JSON_C_VERSION);
printf("linked to json-c version: %s\n", json_c_version());
#endif
#endif /* if defined(HAVE_JSON_C) */
#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
printf("compiled with zlib version: %s\n", ZLIB_VERSION);
printf("linked to zlib version: %s\n", zlibVersion());
#endif
#endif /* if defined(HAVE_ZLIB) && defined(ZLIB_VERSION) */
#if defined(HAVE_GEOIP2)
/* Unfortunately, no version define on link time */
printf("linked to maxminddb version: %s\n", MMDB_lib_version());
#endif
#endif /* if defined(HAVE_GEOIP2) */
#if defined(HAVE_DNSTAP)
printf("compiled with protobuf-c version: %s\n", PROTOBUF_C_VERSION);
printf("linked to protobuf-c version: %s\n", protobuf_c_version());
#endif
#endif /* if defined(HAVE_DNSTAP) */
printf("threads support is enabled\n\n");
/*
@ -681,8 +692,9 @@ parse_T_opt(char *option)
}
dns_zone_mkey_day = atoi(p);
if (dns_zone_mkey_day < dns_zone_mkey_hour)
if (dns_zone_mkey_day < dns_zone_mkey_hour) {
named_main_earlyfatal("bad mkeytimer");
}
p = strtok_r(NULL, "/", &last);
if (p == NULL) {
@ -721,22 +733,26 @@ parse_command_line(int argc, char *argv[])
-1) {
switch (ch) {
case '4':
if (disable4)
if (disable4) {
named_main_earlyfatal("cannot specify "
"-4 and -6");
if (isc_net_probeipv4() != ISC_R_SUCCESS)
}
if (isc_net_probeipv4() != ISC_R_SUCCESS) {
named_main_earlyfatal("IPv4 not supported "
"by OS");
}
isc_net_disableipv6();
disable6 = true;
break;
case '6':
if (disable6)
if (disable6) {
named_main_earlyfatal("cannot specify "
"-4 and -6");
if (isc_net_probeipv6() != ISC_R_SUCCESS)
}
if (isc_net_probeipv6() != ISC_R_SUCCESS) {
named_main_earlyfatal("IPv6 not supported "
"by OS");
}
isc_net_disableipv4();
disable4 = true;
break;
@ -784,14 +800,16 @@ parse_command_line(int argc, char *argv[])
" cp"
"u"
"s");
if (named_g_cpus == 0)
if (named_g_cpus == 0) {
named_g_cpus = 1;
}
break;
case 'p':
port = parse_int(isc_commandline_argument, "port");
if (port < 1 || port > 65535)
if (port < 1 || port > 65535) {
named_main_earlyfatal("port '%s' out of range",
isc_commandline_argument);
}
named_g_port = port;
break;
case 's':
@ -831,28 +849,31 @@ parse_command_line(int argc, char *argv[])
break;
case 'X':
named_g_forcelock = true;
if (strcasecmp(isc_commandline_argument, "none") != 0)
if (strcasecmp(isc_commandline_argument, "none") != 0) {
named_g_defaultlockfile =
isc_commandline_argument;
else
} else {
named_g_defaultlockfile = NULL;
}
break;
case 'F':
/* Reserved for FIPS mode */
/* FALLTHROUGH */
/* Reserved for FIPS mode */
/* FALLTHROUGH */
case '?':
usage();
if (isc_commandline_option == '?')
if (isc_commandline_option == '?') {
exit(0);
}
p = strchr(NAMED_MAIN_ARGS, isc_commandline_option);
if (p == NULL || *++p != ':')
if (p == NULL || *++p != ':') {
named_main_earlyfatal("unknown option '-%c'",
isc_commandline_option);
else
} else {
named_main_earlyfatal("option '-%c' requires "
"an argument",
isc_commandline_option);
/* FALLTHROUGH */
}
/* FALLTHROUGH */
default:
named_main_earlyfatal("parsing options returned %d",
ch);
@ -877,8 +898,9 @@ create_managers(void)
INSIST(named_g_cpus_detected > 0);
if (named_g_cpus == 0)
if (named_g_cpus == 0) {
named_g_cpus = named_g_cpus_detected;
}
isc_log_write(
named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER,
ISC_LOG_INFO, "found %u CPU%s, using %u worker thread%s",
@ -886,13 +908,14 @@ create_managers(void)
named_g_cpus, named_g_cpus == 1 ? "" : "s");
#ifdef WIN32
named_g_udpdisp = 1;
#else
#else /* ifdef WIN32 */
if (named_g_udpdisp == 0) {
named_g_udpdisp = named_g_cpus_detected;
}
if (named_g_udpdisp > named_g_cpus)
if (named_g_udpdisp > named_g_cpus) {
named_g_udpdisp = named_g_cpus;
#endif
}
#endif /* ifdef WIN32 */
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_SERVER, ISC_LOG_INFO,
"using %u UDP listener%s per interface", named_g_udpdisp,
@ -979,11 +1002,13 @@ dump_symboltable(void)
const char * fname;
const void * addr;
if (isc__backtrace_nsymbols == 0)
if (isc__backtrace_nsymbols == 0) {
return;
}
if (!isc_log_wouldlog(named_g_lctx, ISC_LOG_DEBUG(99)))
if (!isc_log_wouldlog(named_g_lctx, ISC_LOG_DEBUG(99))) {
return;
}
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_DEBUG(99), "Symbol table:");
@ -1008,7 +1033,7 @@ setup(void)
ns_server_t * sctx;
#ifdef HAVE_LIBSCF
char *instance = NULL;
#endif
#endif /* ifdef HAVE_LIBSCF */
/*
* Get the user and group information before changing the root
@ -1028,12 +1053,14 @@ setup(void)
/* Check if named is under smf control, before chroot. */
result = named_smf_get_instance(&instance, 0, named_g_mctx);
/* We don't care about instance, just check if we got one. */
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
named_smf_got_instance = 1;
else
} else {
named_smf_got_instance = 0;
if (instance != NULL)
}
if (instance != NULL) {
isc_mem_free(named_g_mctx, instance);
}
#endif /* HAVE_LIBSCF */
/*
@ -1054,9 +1081,10 @@ setup(void)
named_os_minprivs();
result = named_log_init(named_g_username != NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("named_log_init() failed: %s",
isc_result_totext(result));
}
/*
* Now is the time to daemonize (if we're not running in the
@ -1065,17 +1093,19 @@ setup(void)
* because calling create_managers() will create threads, which
* would be lost after fork().
*/
if (!named_g_foreground)
if (!named_g_foreground) {
named_os_daemonize();
}
/*
* We call isc_app_start() here as some versions of FreeBSD's fork()
* destroys all the signal handling it sets up.
*/
result = isc_app_start();
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("isc_app_start() failed: %s",
isc_result_totext(result));
}
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
@ -1099,29 +1129,29 @@ setup(void)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"compiled by CLANG %s", __VERSION__);
#else
#else /* ifdef __clang__ */
#if defined(__ICC) || defined(__INTEL_COMPILER)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"compiled by ICC %s", __VERSION__);
#else
#else /* if defined(__ICC) || defined(__INTEL_COMPILER) */
#ifdef __GNUC__
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"compiled by GCC %s", __VERSION__);
#endif
#endif
#endif
#endif /* ifdef __GNUC__ */
#endif /* if defined(__ICC) || defined(__INTEL_COMPILER) */
#endif /* ifdef __clang__ */
#ifdef _MSC_VER
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"compiled by MSVC %d", _MSC_VER);
#endif
#endif /* ifdef _MSC_VER */
#ifdef __SUNPRO_C
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"compiled by Solaris Studio %x", __SUNPRO_C);
#endif
#endif /* ifdef __SUNPRO_C */
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"compiled with OpenSSL version: %s",
@ -1132,7 +1162,8 @@ setup(void)
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"linked to OpenSSL version: %s",
OpenSSL_version(OPENSSL_VERSION));
#else
#else /* if !defined(LIBRESSL_VERSION_NUMBER) && OPENSSL_VERSION_NUMBER >= \
* 0x10100000L */
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"linked to OpenSSL version: %s",
@ -1146,7 +1177,7 @@ setup(void)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"linked to libxml2 version: %s", xmlParserVersion);
#endif
#endif /* ifdef HAVE_LIBXML2 */
#if defined(HAVE_JSON_C)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
@ -1154,7 +1185,7 @@ setup(void)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"linked to json-c version: %s", json_c_version());
#endif
#endif /* if defined(HAVE_JSON_C) */
#if defined(HAVE_ZLIB) && defined(ZLIB_VERSION)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
@ -1162,7 +1193,7 @@ setup(void)
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"linked to zlib version: %s", zlibVersion());
#endif
#endif /* if defined(HAVE_ZLIB) && defined(ZLIB_VERSION) */
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE,
"----------------------------------------------------");
@ -1197,7 +1228,7 @@ setup(void)
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_coresize,
&named_g_initcoresize) ==
ISC_R_SUCCESS);
#endif
#endif /* ifndef WIN32 */
RUNTIME_CHECK(isc_resource_getlimit(isc_resource_openfiles,
&named_g_initopenfiles) ==
ISC_R_SUCCESS);
@ -1228,11 +1259,12 @@ setup(void)
result = isc_file_absolutepath(named_g_conffile,
absolute_conffile,
sizeof(absolute_conffile));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("could not construct "
"absolute path "
"of configuration file: %s",
isc_result_totext(result));
}
named_g_conffile = absolute_conffile;
}
@ -1240,14 +1272,16 @@ setup(void)
* Record the server's startup time.
*/
result = isc_time_now(&named_g_boottime);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("isc_time_now() failed: %s",
isc_result_totext(result));
}
result = create_managers();
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("create_managers() failed: %s",
isc_result_totext(result));
}
named_builtin_init();
@ -1261,20 +1295,22 @@ setup(void)
* Register the DLZ "dlopen" driver.
*/
result = dlz_dlopen_init(named_g_mctx);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("dlz_dlopen_init() failed: %s",
isc_result_totext(result));
#endif
}
#endif /* ifdef ISC_DLZ_DLOPEN */
#if CONTRIB_DLZ
/*
* Register any other contributed DLZ drivers.
*/
result = dlz_drivers_init();
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("dlz_drivers_init() failed: %s",
isc_result_totext(result));
#endif
}
#endif /* if CONTRIB_DLZ */
named_server_create(named_g_mctx, &named_g_server);
sctx = named_g_server->sctx;
@ -1282,32 +1318,45 @@ setup(void)
/*
* Modify server context according to command line options
*/
if (disable4)
if (disable4) {
ns_server_setoption(sctx, NS_SERVER_DISABLE4, true);
if (disable6)
}
if (disable6) {
ns_server_setoption(sctx, NS_SERVER_DISABLE6, true);
if (dropedns)
}
if (dropedns) {
ns_server_setoption(sctx, NS_SERVER_DROPEDNS, true);
if (ednsformerr) /* STD13 server */
}
if (ednsformerr) { /* STD13 server */
ns_server_setoption(sctx, NS_SERVER_EDNSFORMERR, true);
if (ednsnotimp)
}
if (ednsnotimp) {
ns_server_setoption(sctx, NS_SERVER_EDNSNOTIMP, true);
if (ednsrefused)
}
if (ednsrefused) {
ns_server_setoption(sctx, NS_SERVER_EDNSREFUSED, true);
if (fixedlocal)
}
if (fixedlocal) {
ns_server_setoption(sctx, NS_SERVER_FIXEDLOCAL, true);
if (noaa)
}
if (noaa) {
ns_server_setoption(sctx, NS_SERVER_NOAA, true);
if (noedns)
}
if (noedns) {
ns_server_setoption(sctx, NS_SERVER_NOEDNS, true);
if (nonearest)
}
if (nonearest) {
ns_server_setoption(sctx, NS_SERVER_NONEAREST, true);
if (nosoa)
}
if (nosoa) {
ns_server_setoption(sctx, NS_SERVER_NOSOA, true);
if (notcp)
}
if (notcp) {
ns_server_setoption(sctx, NS_SERVER_NOTCP, true);
if (sigvalinsecs)
}
if (sigvalinsecs) {
ns_server_setoption(sctx, NS_SERVER_SIGVALINSECS, true);
}
}
static void
@ -1315,8 +1364,9 @@ cleanup(void)
{
destroy_managers();
if (named_g_mapped != NULL)
if (named_g_mapped != NULL) {
dns_acl_detach(&named_g_mapped);
}
named_server_destroy(&named_g_server);
@ -1332,13 +1382,13 @@ cleanup(void)
* Unregister contributed DLZ drivers.
*/
dlz_drivers_clear();
#endif
#endif /* ifdef CONTRIB_DLZ */
#ifdef ISC_DLZ_DLOPEN
/*
* Unregister "dlopen" DLZ driver.
*/
dlz_dlopen_clear();
#endif
#endif /* ifdef ISC_DLZ_DLOPEN */
isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL,
NAMED_LOGMODULE_MAIN, ISC_LOG_NOTICE, "exiting");
@ -1359,8 +1409,9 @@ named_main_setmemstats(const char *filename)
memstats = NULL;
}
if (filename == NULL)
if (filename == NULL) {
return;
}
memstats = strdup(filename);
}
@ -1379,27 +1430,30 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx)
REQUIRE(ins_name != NULL && *ins_name == NULL);
if ((h = scf_handle_create(SCF_VERSION)) == NULL) {
if (debug)
if (debug) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_handle_create() failed: %s",
scf_strerror(scf_error()));
}
return (ISC_R_FAILURE);
}
if (scf_handle_bind(h) == -1) {
if (debug)
if (debug) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_handle_bind() failed: %s",
scf_strerror(scf_error()));
}
scf_handle_destroy(h);
return (ISC_R_FAILURE);
}
if ((namelen = scf_myname(h, NULL, 0)) == -1) {
if (debug)
if (debug) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_myname() failed: %s",
scf_strerror(scf_error()));
}
scf_handle_destroy(h);
return (ISC_R_FAILURE);
}
@ -1414,10 +1468,11 @@ named_smf_get_instance(char **ins_name, int debug, isc_mem_t *mctx)
}
if (scf_myname(h, instance, namelen + 1) == -1) {
if (debug)
if (debug) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"scf_myname() failed: %s",
scf_strerror(scf_error()));
}
scf_handle_destroy(h);
isc_mem_free(mctx, instance);
return (ISC_R_FAILURE);
@ -1437,11 +1492,11 @@ main(int argc, char *argv[])
isc_result_t result;
#ifdef HAVE_LIBSCF
char *instance = NULL;
#endif
#endif /* ifdef HAVE_LIBSCF */
#ifdef HAVE_GPERFTOOLS_PROFILER
(void)ProfilerStart(NULL);
#endif
#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */
#ifdef WIN32
/*
@ -1452,7 +1507,7 @@ main(int argc, char *argv[])
* written to the default stderr logging channels created by libisc.
*/
setvbuf(stderr, NULL, _IOFBF, BUFSIZ);
#endif
#endif /* ifdef WIN32 */
#ifdef HAVE_LIBXML2
xmlInitThreads();
@ -1465,13 +1520,14 @@ main(int argc, char *argv[])
strlcat(version,
#if defined(NO_VERSION_DATE) || !defined(__DATE__)
"named version: BIND " VERSION " <" SRCID ">",
#else
#else /* if defined(NO_VERSION_DATE) || !defined(__DATE__) */
"named version: BIND " VERSION " <" SRCID "> (" __DATE__ ")",
#endif
#endif /* if defined(NO_VERSION_DATE) || !defined(__DATE__) */
sizeof(version));
result = isc_file_progname(*argv, program_name, sizeof(program_name));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlyfatal("program name too long");
}
isc_assertion_setcallback(assertion_failed);
isc_error_setfatal(library_fatal_error);
@ -1484,7 +1540,7 @@ main(int argc, char *argv[])
isccc_result_register();
#if USE_PKCS11
pk11_result_register();
#endif
#endif /* if USE_PKCS11 */
#if !ISC_MEM_DEFAULTFILL
/*
@ -1493,7 +1549,7 @@ main(int argc, char *argv[])
* it can be turned back on with -M fill.
*/
isc_mem_defaultflags &= ~ISC_MEMFLAG_FILL;
#endif
#endif /* if !ISC_MEM_DEFAULTFILL */
parse_command_line(argc, argv);
@ -1507,7 +1563,7 @@ main(int argc, char *argv[])
} else if (named_g_fuzz_type == isc_fuzz_http) {
isc_httpd_setfinishhook(named_fuzz_notify);
}
#endif
#endif /* ifdef ENABLE_AFL */
/*
* Warn about common configuration error.
*/
@ -1515,11 +1571,12 @@ main(int argc, char *argv[])
int len = strlen(named_g_chrootdir);
if (strncmp(named_g_chrootdir, named_g_conffile, len) == 0 &&
(named_g_conffile[len] == '/' ||
named_g_conffile[len] == '\\'))
named_g_conffile[len] == '\\')) {
named_main_earlywarning("config filename (-c %s) "
"contains chroot path (-t %s)",
named_g_conffile,
named_g_chrootdir);
}
}
isc_mem_create(&named_g_mctx);
@ -1551,15 +1608,17 @@ main(int argc, char *argv[])
if (named_smf_want_disable == 1) {
result = named_smf_get_instance(&instance, 1, named_g_mctx);
if (result == ISC_R_SUCCESS && instance != NULL) {
if (smf_disable_instance(instance, 0) != 0)
if (smf_disable_instance(instance, 0) != 0) {
UNEXPECTED_ERROR(__FILE__, __LINE__,
"smf_disable_instance() "
"failed for %s : %s",
instance,
scf_strerror(scf_error()));
}
}
if (instance != NULL)
if (instance != NULL) {
isc_mem_free(named_g_mctx, instance);
}
}
#endif /* HAVE_LIBSCF */
@ -1596,7 +1655,7 @@ main(int argc, char *argv[])
#ifdef HAVE_GPERFTOOLS_PROFILER
ProfilerStop();
#endif
#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */
return (0);
}

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -54,8 +54,9 @@ named_tkeyctx_fromconfig(const cfg_obj_t *options, isc_mem_t *mctx,
int type;
result = dns_tkeyctx_create(mctx, &tctx);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
obj = NULL;
result = cfg_map_get(options, "tkey-dhkey", &obj);

View file

@ -73,8 +73,9 @@ add_initial_keys(const cfg_obj_t *list, dns_tsig_keyring_t *ring,
isc_buffer_init(&keynamebuf, keynamedata, sizeof(keynamedata));
ret = dns_name_fromtext(&keyname, &keynamesrc, dns_rootname,
DNS_NAME_DOWNCASE, &keynamebuf);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
goto failure;
}
/*
* Create the algorithm.
@ -95,8 +96,9 @@ add_initial_keys(const cfg_obj_t *list, dns_tsig_keyring_t *ring,
secret = isc_mem_get(mctx, secretlen);
isc_buffer_init(&secretbuf, secret, secretlen);
ret = isc_base64_decodestring(secretstr, &secretbuf);
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
goto failure;
}
secretlen = isc_buffer_usedlength(&secretbuf);
isc_stdtime_get(&now);
@ -105,8 +107,9 @@ add_initial_keys(const cfg_obj_t *list, dns_tsig_keyring_t *ring,
&tsigkey);
isc_mem_put(mctx, secret, secretalloc);
secret = NULL;
if (ret != ISC_R_SUCCESS)
if (ret != ISC_R_SUCCESS) {
goto failure;
}
/*
* Set digest bits.
*/
@ -120,8 +123,9 @@ failure:
cfg_obj_log(key, named_g_lctx, ISC_LOG_ERROR,
"configuring key '%s': %s", keyid, isc_result_totext(ret));
if (secret != NULL)
if (secret != NULL) {
isc_mem_put(mctx, secret, secretalloc);
}
return (ret);
}
@ -138,26 +142,32 @@ named_tsigkeyring_fromconfig(const cfg_obj_t *config, const cfg_obj_t *vconfig,
REQUIRE(ringp != NULL && *ringp == NULL);
i = 0;
if (config != NULL)
if (config != NULL) {
maps[i++] = config;
if (vconfig != NULL)
}
if (vconfig != NULL) {
maps[i++] = cfg_tuple_get(vconfig, "options");
}
maps[i] = NULL;
result = dns_tsigkeyring_create(mctx, &ring);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
for (i = 0;; i++) {
if (maps[i] == NULL)
if (maps[i] == NULL) {
break;
}
keylist = NULL;
result = cfg_map_get(maps[i], "key", &keylist);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
continue;
}
result = add_initial_keys(keylist, ring, mctx);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto failure;
}
}
*ringp = ring;

View file

@ -16,7 +16,7 @@
#include <string.h>
#if HAVE_DLFCN_H
#include <dlfcn.h>
#endif
#endif /* if HAVE_DLFCN_H */
#include <isc/mem.h>
#include <isc/print.h>
@ -250,7 +250,7 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
* a segfault).
*/
dlopen_flags |= RTLD_DEEPBIND;
#endif
#endif /* if defined(RTLD_DEEPBIND) && !__SANITIZE_ADDRESS__ */
cd->dl_handle = dlopen(cd->dl_path, dlopen_flags);
if (cd->dl_handle == NULL) {
@ -326,8 +326,9 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
"putnamedrr", dns_sdlz_putnamedrr,
"writeable_zone", dns_dlz_writeablezone, NULL);
MAYBE_UNLOCK(cd);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto failed;
}
*dbdata = cd;
@ -348,7 +349,7 @@ failed:
if (cd->dl_handle) {
dlclose(cd->dl_handle);
}
#endif
#endif /* ifdef HAVE_DLCLOSE */
isc_mem_put(mctx, cd, sizeof(*cd));
isc_mem_destroy(&mctx);
return (result);
@ -382,7 +383,7 @@ dlopen_dlz_destroy(void *driverarg, void *dbdata)
if (cd->dl_handle) {
dlclose(cd->dl_handle);
}
#endif
#endif /* ifdef HAVE_DLCLOSE */
isc_mutex_destroy(&cd->lock);
@ -403,8 +404,9 @@ dlopen_dlz_newversion(const char *zone, void *driverarg, void *dbdata,
UNUSED(driverarg);
if (cd->dlz_newversion == NULL)
if (cd->dlz_newversion == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_newversion(zone, cd->dbdata, versionp);
@ -445,8 +447,9 @@ dlopen_dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_configure == NULL)
if (cd->dlz_configure == NULL) {
return (ISC_R_SUCCESS);
}
MAYBE_LOCK(cd);
cd->in_configure = true;
@ -470,8 +473,9 @@ dlopen_dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
UNUSED(driverarg);
if (cd->dlz_ssumatch == NULL)
if (cd->dlz_ssumatch == NULL) {
return (false);
}
MAYBE_LOCK(cd);
ret = cd->dlz_ssumatch(signer, name, tcpaddr, type, key, keydatalen,
@ -493,8 +497,9 @@ dlopen_dlz_addrdataset(const char *name, const char *rdatastr, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_addrdataset == NULL)
if (cd->dlz_addrdataset == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_addrdataset(name, rdatastr, cd->dbdata, version);
@ -515,8 +520,9 @@ dlopen_dlz_subrdataset(const char *name, const char *rdatastr, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_subrdataset == NULL)
if (cd->dlz_subrdataset == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_subrdataset(name, rdatastr, cd->dbdata, version);
@ -537,8 +543,9 @@ dlopen_dlz_delrdataset(const char *name, const char *type, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_delrdataset == NULL)
if (cd->dlz_delrdataset == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_delrdataset(name, type, cd->dbdata, version);
@ -554,7 +561,7 @@ static dns_sdlzmethods_t dlz_dlopen_methods = {
dlopen_dlz_configure, dlopen_dlz_ssumatch, dlopen_dlz_addrdataset,
dlopen_dlz_subrdataset, dlopen_dlz_delrdataset
};
#endif
#endif /* ifdef ISC_DLZ_DLOPEN */
/*
* Register driver with BIND
@ -565,7 +572,7 @@ dlz_dlopen_init(isc_mem_t *mctx)
#ifndef ISC_DLZ_DLOPEN
UNUSED(mctx);
return (ISC_R_NOTIMPLEMENTED);
#else
#else /* ifndef ISC_DLZ_DLOPEN */
isc_result_t result;
dlopen_log(2, "Registering DLZ_dlopen driver");
@ -584,7 +591,7 @@ dlz_dlopen_init(isc_mem_t *mctx)
}
return (result);
#endif
#endif /* ifndef ISC_DLZ_DLOPEN */
}
/*
@ -595,7 +602,8 @@ dlz_dlopen_clear(void)
{
#ifdef ISC_DLZ_DLOPEN
dlopen_log(2, "Unregistering DLZ_dlopen driver");
if (dlz_dlopen != NULL)
if (dlz_dlopen != NULL) {
dns_sdlzunregister(&dlz_dlopen);
#endif
}
#endif /* ifdef ISC_DLZ_DLOPEN */
}

View file

@ -17,7 +17,7 @@
#include <sys/types.h> /* dev_t FreeBSD 2.1 */
#ifdef HAVE_UNAME
#include <sys/utsname.h>
#endif
#endif /* ifdef HAVE_UNAME */
#include <ctype.h>
#include <errno.h>
@ -30,7 +30,7 @@
#include <syslog.h>
#ifdef HAVE_TZSET
#include <time.h>
#endif
#endif /* ifdef HAVE_TZSET */
#include <unistd.h>
#include <isc/buffer.h>
@ -46,7 +46,7 @@
#include <named/os.h>
#ifdef HAVE_LIBSCF
#include <named/smf_globals.h>
#endif
#endif /* ifdef HAVE_LIBSCF */
static char *pidfile = NULL;
static char *lockfile = NULL;
@ -55,7 +55,7 @@ static int singletonfd = -1;
#ifndef ISC_FACILITY
#define ISC_FACILITY LOG_DAEMON
#endif
#endif /* ifndef ISC_FACILITY */
static struct passwd *runas_pw = NULL;
static bool done_setuid = false;
@ -245,8 +245,9 @@ linux_keepcaps(void)
}
} else {
non_root_caps = true;
if (getuid() != 0)
if (getuid() != 0) {
non_root = true;
}
}
}
@ -260,7 +261,7 @@ setup_syslog(const char *progname)
options = LOG_PID;
#ifdef LOG_NDELAY
options |= LOG_NDELAY;
#endif
#endif /* ifdef LOG_NDELAY */
openlog(isc_file_basename(progname), options, ISC_FACILITY);
}
@ -270,10 +271,10 @@ named_os_init(const char *progname)
setup_syslog(progname);
#ifdef HAVE_SYS_CAPABILITY_H
linux_initialprivs();
#endif
#endif /* ifdef HAVE_SYS_CAPABILITY_H */
#ifdef SIGXFSZ
signal(SIGXFSZ, SIG_IGN);
#endif
#endif /* ifdef SIGXFSZ */
}
void
@ -303,8 +304,9 @@ named_os_daemonize(void)
do {
char buf;
n = read(dfd[0], &buf, 1);
if (n == 1)
if (n == 1) {
_exit(0);
}
} while (n == -1 && errno == EINTR);
_exit(1);
}
@ -354,10 +356,11 @@ named_os_started(void)
* Signal to the parent that we started successfully.
*/
if (dfd[0] != -1 && dfd[1] != -1) {
if (write(dfd[1], &buf, 1) != 1)
if (write(dfd[1], &buf, 1) != 1) {
named_main_earlyfatal("unable to signal parent that we "
"otherwise started "
"successfully.");
}
close(dfd[1]);
dfd[0] = dfd[1] = -1;
}
@ -382,11 +385,13 @@ named_os_closedevnull(void)
static bool
all_digits(const char *s)
{
if (*s == '\0')
if (*s == '\0') {
return (false);
}
while (*s != '\0') {
if (!isdigit((*s) & 0xff))
if (!isdigit((*s) & 0xff)) {
return (false);
}
s++;
}
return (true);
@ -398,16 +403,16 @@ named_os_chroot(const char *root)
char strbuf[ISC_STRERRORSIZE];
#ifdef HAVE_LIBSCF
named_smf_chroot = 0;
#endif
#endif /* ifdef HAVE_LIBSCF */
if (root != NULL) {
#ifdef HAVE_CHROOT
if (chroot(root) < 0) {
strerror_r(errno, strbuf, sizeof(strbuf));
named_main_earlyfatal("chroot(): %s", strbuf);
}
#else
#else /* ifdef HAVE_CHROOT */
named_main_earlyfatal("chroot(): disabled");
#endif
#endif /* ifdef HAVE_CHROOT */
if (chdir("/") < 0) {
strerror_r(errno, strbuf, sizeof(strbuf));
named_main_earlyfatal("chdir(/): %s", strbuf);
@ -415,7 +420,7 @@ named_os_chroot(const char *root)
#ifdef HAVE_LIBSCF
/* Set named_smf_chroot flag on successful chroot. */
named_smf_chroot = 1;
#endif
#endif /* ifdef HAVE_LIBSCF */
}
}
@ -423,17 +428,20 @@ void
named_os_inituserinfo(const char *username)
{
char strbuf[ISC_STRERRORSIZE];
if (username == NULL)
if (username == NULL) {
return;
}
if (all_digits(username))
if (all_digits(username)) {
runas_pw = getpwuid((uid_t)atoi(username));
else
} else {
runas_pw = getpwnam(username);
}
endpwent();
if (runas_pw == NULL)
if (runas_pw == NULL) {
named_main_earlyfatal("user '%s' unknown", username);
}
if (getuid() == 0) {
if (initgroups(runas_pw->pw_name, runas_pw->pw_gid) < 0) {
@ -447,8 +455,9 @@ void
named_os_changeuser(void)
{
char strbuf[ISC_STRERRORSIZE];
if (runas_pw == NULL || done_setuid)
if (runas_pw == NULL || done_setuid) {
return;
}
done_setuid = true;
@ -474,14 +483,15 @@ named_os_changeuser(void)
}
linux_minprivs();
#endif
#endif /* if defined(HAVE_SYS_CAPABILITY_H) */
}
uid_t
ns_os_uid(void)
{
if (runas_pw == NULL)
if (runas_pw == NULL) {
return (0);
}
return (runas_pw->pw_uid);
}
@ -499,9 +509,10 @@ named_os_adjustnofile(void)
newvalue = ISC_RESOURCE_UNLIMITED;
result = isc_resource_setlimit(isc_resource_openfiles, newvalue);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
named_main_earlywarning("couldn't adjust limit on open files");
#endif
}
#endif /* if defined(__linux__) */
}
void
@ -511,7 +522,7 @@ named_os_minprivs(void)
linux_keepcaps();
named_os_changeuser();
linux_minprivs();
#endif
#endif /* if defined(HAVE_SYS_CAPABILITY_H) */
}
static int
@ -521,18 +532,20 @@ safe_open(const char *filename, mode_t mode, bool append)
struct stat sb;
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
if (errno != ENOENT) {
return (-1);
}
} else if ((sb.st_mode & S_IFREG) == 0) {
errno = EOPNOTSUPP;
return (-1);
}
if (append)
if (append) {
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, mode);
else {
if (unlink(filename) < 0 && errno != ENOENT)
} else {
if (unlink(filename) < 0 && errno != ENOENT) {
return (-1);
}
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, mode);
}
return (fd);
@ -544,8 +557,9 @@ cleanup_pidfile(void)
int n;
if (pidfile != NULL) {
n = unlink(pidfile);
if (n == -1 && errno != ENOENT)
if (n == -1 && errno != ENOENT) {
named_main_earlywarning("unlink '%s': failed", pidfile);
}
free(pidfile);
}
pidfile = NULL;
@ -561,9 +575,10 @@ cleanup_lockfile(void)
if (lockfile != NULL) {
int n = unlink(lockfile);
if (n == -1 && errno != ENOENT)
if (n == -1 && errno != ENOENT) {
named_main_earlywarning("unlink '%s': failed",
lockfile);
}
free(lockfile);
lockfile = NULL;
}
@ -592,8 +607,9 @@ mkdirpath(char *filename, void (*report)(const char *, ...))
strbuf);
goto error;
}
if (mkdirpath(filename, report) == -1)
if (mkdirpath(filename, report) == -1) {
goto error;
}
/*
* Handle "//", "/./" and "/../" in path.
*/
@ -633,13 +649,13 @@ setperms(uid_t uid, gid_t gid)
{
#if defined(HAVE_SETEGID) || defined(HAVE_SETRESGID)
char strbuf[ISC_STRERRORSIZE];
#endif
#endif /* if defined(HAVE_SETEGID) || defined(HAVE_SETRESGID) */
#if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID)
gid_t oldgid, tmpg;
#endif
#endif /* if !defined(HAVE_SETEGID) && defined(HAVE_SETRESGID) */
#if !defined(HAVE_SETEUID) && defined(HAVE_SETRESUID)
uid_t olduid, tmpu;
#endif
#endif /* if !defined(HAVE_SETEUID) && defined(HAVE_SETRESUID) */
#if defined(HAVE_SETEGID)
if (getegid() != gid && setegid(gid) == -1) {
strerror_r(errno, strbuf, sizeof(strbuf));
@ -656,7 +672,7 @@ setperms(uid_t uid, gid_t gid)
gid, strbuf);
}
}
#endif
#endif /* if defined(HAVE_SETEGID) */
#if defined(HAVE_SETEUID)
if (geteuid() != uid && seteuid(uid) == -1) {
@ -674,7 +690,7 @@ setperms(uid_t uid, gid_t gid)
uid, strbuf);
}
}
#endif
#endif /* if defined(HAVE_SETEUID) */
}
FILE *
@ -763,8 +779,9 @@ named_os_writepidfile(const char *filename, bool first_time)
cleanup_pidfile();
if (filename == NULL)
if (filename == NULL) {
return;
}
pidfile = strdup(filename);
if (pidfile == NULL) {
@ -801,11 +818,13 @@ named_os_issingleton(const char *filename)
char strbuf[ISC_STRERRORSIZE];
struct flock lock;
if (singletonfd != -1)
if (singletonfd != -1) {
return (true);
}
if (strcasecmp(filename, "none") == 0)
if (strcasecmp(filename, "none") == 0) {
return (true);
}
/*
* Make the containing directory if it doesn't exist.
@ -898,7 +917,7 @@ named_os_tzset(void)
{
#ifdef HAVE_TZSET
tzset();
#endif
#endif /* ifdef HAVE_TZSET */
}
static char unamebuf[BUFSIZ];
@ -918,16 +937,17 @@ getuname(void)
snprintf(unamebuf, sizeof(unamebuf), "%s %s %s %s", uts.sysname,
uts.machine, uts.release, uts.version);
#else
#else /* ifdef HAVE_UNAME */
snprintf(unamebuf, sizeof(unamebuf), "unknown architecture");
#endif
#endif /* ifdef HAVE_UNAME */
unamep = unamebuf;
}
char *
named_os_uname(void)
{
if (unamep == NULL)
if (unamep == NULL) {
getuname();
}
return (unamep);
}

View file

@ -311,8 +311,9 @@ dlopen_dlz_create(const char *dlzname, unsigned int argc, char *argv[],
"putnamedrr", dns_sdlz_putnamedrr,
"writeable_zone", dns_dlz_writeablezone, NULL);
MAYBE_UNLOCK(cd);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup_lock;
}
*dbdata = cd;
@ -356,13 +357,16 @@ dlopen_dlz_destroy(void *driverarg, void *dbdata)
MAYBE_UNLOCK(cd);
}
if (cd->dl_path)
if (cd->dl_path) {
isc_mem_free(cd->mctx, cd->dl_path);
if (cd->dlzname)
}
if (cd->dlzname) {
isc_mem_free(cd->mctx, cd->dlzname);
}
if (cd->dl_handle)
if (cd->dl_handle) {
FreeLibrary(cd->dl_handle);
}
isc_mutex_destroy(&cd->lock);
@ -383,8 +387,9 @@ dlopen_dlz_newversion(const char *zone, void *driverarg, void *dbdata,
UNUSED(driverarg);
if (cd->dlz_newversion == NULL)
if (cd->dlz_newversion == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_newversion(zone, cd->dbdata, versionp);
@ -425,8 +430,9 @@ dlopen_dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_configure == NULL)
if (cd->dlz_configure == NULL) {
return (ISC_R_SUCCESS);
}
MAYBE_LOCK(cd);
cd->in_configure = true;
@ -450,8 +456,9 @@ dlopen_dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr,
UNUSED(driverarg);
if (cd->dlz_ssumatch == NULL)
if (cd->dlz_ssumatch == NULL) {
return (false);
}
MAYBE_LOCK(cd);
ret = cd->dlz_ssumatch(signer, name, tcpaddr, type, key, keydatalen,
@ -473,8 +480,9 @@ dlopen_dlz_addrdataset(const char *name, const char *rdatastr, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_addrdataset == NULL)
if (cd->dlz_addrdataset == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_addrdataset(name, rdatastr, cd->dbdata, version);
@ -495,8 +503,9 @@ dlopen_dlz_subrdataset(const char *name, const char *rdatastr, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_subrdataset == NULL)
if (cd->dlz_subrdataset == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_subrdataset(name, rdatastr, cd->dbdata, version);
@ -506,7 +515,7 @@ dlopen_dlz_subrdataset(const char *name, const char *rdatastr, void *driverarg,
}
/*
delete a rdataset
* delete a rdataset
*/
static isc_result_t
dlopen_dlz_delrdataset(const char *name, const char *type, void *driverarg,
@ -517,8 +526,9 @@ dlopen_dlz_delrdataset(const char *name, const char *type, void *driverarg,
UNUSED(driverarg);
if (cd->dlz_delrdataset == NULL)
if (cd->dlz_delrdataset == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
MAYBE_LOCK(cd);
result = cd->dlz_delrdataset(name, type, cd->dbdata, version);
@ -534,7 +544,7 @@ static dns_sdlzmethods_t dlz_dlopen_methods = {
dlopen_dlz_configure, dlopen_dlz_ssumatch, dlopen_dlz_addrdataset,
dlopen_dlz_subrdataset, dlopen_dlz_delrdataset
};
#endif
#endif /* ifdef ISC_DLZ_DLOPEN */
/*
* Register driver with BIND
@ -545,7 +555,7 @@ dlz_dlopen_init(isc_mem_t *mctx)
#ifndef ISC_DLZ_DLOPEN
UNUSED(mctx);
return (ISC_R_NOTIMPLEMENTED);
#else
#else /* ifndef ISC_DLZ_DLOPEN */
isc_result_t result;
dlopen_log(2, "Registering DLZ_dlopen driver");
@ -564,7 +574,7 @@ dlz_dlopen_init(isc_mem_t *mctx)
}
return (result);
#endif
#endif /* ifndef ISC_DLZ_DLOPEN */
}
/*
@ -575,7 +585,8 @@ dlz_dlopen_clear(void)
{
#ifdef ISC_DLZ_DLOPEN
dlopen_log(2, "Unregistering DLZ_dlopen driver");
if (dlz_dlopen != NULL)
if (dlz_dlopen != NULL) {
dns_sdlzunregister(&dlz_dlopen);
#endif
}
#endif /* ifdef ISC_DLZ_DLOPEN */
}

View file

@ -26,4 +26,4 @@ void
ntservice_shutdown();
BOOL
ntservice_isservice();
#endif
#endif /* ifndef NTSERVICE_H */

View file

@ -104,8 +104,9 @@ UpdateSCM(DWORD state)
static DWORD dwState = SERVICE_STOPPED;
if (hServiceStatus) {
if (state)
if (state) {
dwState = state;
}
memset(&ss, 0, sizeof(SERVICE_STATUS));
ss.dwServiceType |= SERVICE_WIN32_OWN_PROCESS;

View file

@ -48,8 +48,9 @@ static char *version_error = "named requires Windows 2000 Service Pack 2 or "
void
named_paths_init(void)
{
if (!Initialized)
if (!Initialized) {
isc_ntpaths_init();
}
named_g_conffile = isc_ntpaths_get(NAMED_CONF_PATH);
named_g_defaultpidfile = isc_ntpaths_get(NAMED_PID_PATH);
@ -70,13 +71,16 @@ static void
version_check(const char *progname)
{
if ((isc_win32os_versioncheck(4, 0, 0, 0) >= 0) &&
(isc_win32os_versioncheck(5, 0, 0, 0) < 0))
(isc_win32os_versioncheck(5, 0, 0, 0) < 0)) {
return; /* No problem with Version 4.0 */
if (isc_win32os_versioncheck(5, 0, 2, 0) < 0)
if (ntservice_isservice())
}
if (isc_win32os_versioncheck(5, 0, 2, 0) < 0) {
if (ntservice_isservice()) {
NTReportError(progname, version_error);
else
} else {
fprintf(stderr, "%s\n", version_error);
}
}
}
static void
@ -87,7 +91,7 @@ setup_syslog(const char *progname)
options = LOG_PID;
#ifdef LOG_NDELAY
options |= LOG_NDELAY;
#endif
#endif /* ifdef LOG_NDELAY */
openlog(progname, options, LOG_DAEMON);
}
@ -162,8 +166,9 @@ named_os_closedevnull(void)
void
named_os_chroot(const char *root)
{
if (root != NULL)
if (root != NULL) {
named_main_earlyfatal("chroot(): isn't supported by Win32 API");
}
}
void
@ -199,14 +204,16 @@ safe_open(const char *filename, int mode, bool append)
struct stat sb;
if (stat(filename, &sb) == -1) {
if (errno != ENOENT)
if (errno != ENOENT) {
return (-1);
} else if ((sb.st_mode & S_IFREG) == 0)
}
} else if ((sb.st_mode & S_IFREG) == 0) {
return (-1);
}
if (append)
if (append) {
fd = open(filename, O_WRONLY | O_CREAT | O_APPEND, mode);
else {
} else {
(void)unlink(filename);
fd = open(filename, O_WRONLY | O_CREAT | O_EXCL, mode);
}
@ -233,9 +240,10 @@ cleanup_lockfile(void)
if (lockfile != NULL) {
int n = unlink(lockfile);
if (n == -1 && errno != ENOENT)
if (n == -1 && errno != ENOENT) {
named_main_earlywarning("unlink '%s': failed",
lockfile);
}
free(lockfile);
lockfile = NULL;
}
@ -284,8 +292,9 @@ named_os_writepidfile(const char *filename, bool first_time)
cleanup_pidfile();
if (filename == NULL)
if (filename == NULL) {
return;
}
pidfile = strdup(filename);
if (pidfile == NULL) {
@ -325,11 +334,13 @@ named_os_issingleton(const char *filename)
char strbuf[ISC_STRERRORSIZE];
OVERLAPPED o;
if (lockfilefd != -1)
if (lockfilefd != -1) {
return (true);
}
if (strcasecmp(filename, "none") == 0)
if (strcasecmp(filename, "none") == 0) {
return (true);
}
lockfile = strdup(filename);
if (lockfile == NULL) {
@ -397,7 +408,7 @@ named_os_tzset(void)
{
#ifdef HAVE_TZSET
tzset();
#endif
#endif /* ifdef HAVE_TZSET */
}
void
@ -479,7 +490,8 @@ err:
char *
named_os_uname(void)
{
if (unamep == NULL)
if (unamep == NULL) {
getuname();
}
return (unamep);
}

View file

@ -63,7 +63,7 @@ typedef enum {
do { \
isc_result_t _r = (x); \
if (_r != ISC_R_SUCCESS) \
return (_r); \
return ((_r)); \
} while (0)
#define CHECK(x) \
@ -95,33 +95,39 @@ configure_zone_acl(const cfg_obj_t *zconfig, const cfg_obj_t *vconfig,
switch (acltype) {
case allow_notify:
if (view != NULL)
if (view != NULL) {
aclp = &view->notifyacl;
}
aclname = "allow-notify";
break;
case allow_query:
if (view != NULL)
if (view != NULL) {
aclp = &view->queryacl;
}
aclname = "allow-query";
break;
case allow_query_on:
if (view != NULL)
if (view != NULL) {
aclp = &view->queryonacl;
}
aclname = "allow-query-on";
break;
case allow_transfer:
if (view != NULL)
if (view != NULL) {
aclp = &view->transferacl;
}
aclname = "allow-transfer";
break;
case allow_update:
if (view != NULL)
if (view != NULL) {
aclp = &view->updateacl;
}
aclname = "allow-update";
break;
case allow_update_forwarding:
if (view != NULL)
if (view != NULL) {
aclp = &view->upfwdacl;
}
aclname = "allow-update-forwarding";
break;
default:
@ -148,14 +154,16 @@ configure_zone_acl(const cfg_obj_t *zconfig, const cfg_obj_t *vconfig,
/* Check for default ACLs that haven't been parsed yet */
if (vconfig != NULL) {
const cfg_obj_t *options = cfg_tuple_get(vconfig, "options");
if (options != NULL)
if (options != NULL) {
maps[i++] = options;
}
}
if (config != NULL) {
const cfg_obj_t *options = NULL;
(void)cfg_map_get(config, "options", &options);
if (options != NULL)
if (options != NULL) {
maps[i++] = options;
}
}
maps[i++] = named_g_defaults;
maps[i] = NULL;
@ -169,13 +177,15 @@ configure_zone_acl(const cfg_obj_t *zconfig, const cfg_obj_t *vconfig,
parse_acl:
result = cfg_acl_fromconfig(aclobj, config, named_g_lctx, actx,
dns_zone_getmctx(zone), 0, &acl);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
(*setzacl)(zone, acl);
/* Set the view default now */
if (aclp != NULL)
if (aclp != NULL) {
dns_acl_attach(acl, aclp);
}
dns_acl_detach(&acl);
return (ISC_R_SUCCESS);
@ -209,8 +219,9 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
}
result = dns_ssutable_create(mctx, &table);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
for (element = cfg_list_first(updatepolicy); element != NULL;
element = cfg_list_next(element)) {
@ -276,9 +287,9 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
}
n = named_config_listcount(typelist);
if (n == 0)
if (n == 0) {
types = NULL;
else {
} else {
types = isc_mem_get(mctx, n * sizeof(dns_rdatatype_t));
}
@ -310,8 +321,9 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
result = dns_ssutable_addrule(
table, grant, dns_fixedname_name(&fident), mtype,
dns_fixedname_name(&fname), n, types);
if (types != NULL)
if (types != NULL) {
isc_mem_put(mctx, types, n * sizeof(dns_rdatatype_t));
}
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
@ -340,8 +352,9 @@ configure_zone_ssutable(const cfg_obj_t *zconfig, dns_zone_t *zone,
dns_ssumatchtype_local, dns_zone_getorigin(zone), 1,
&any);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
}
result = ISC_R_SUCCESS;
@ -677,8 +690,9 @@ strtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp,
isc_result_t result;
/* Discard leading whitespace. */
while (*s == ' ' || *s == '\t')
while (*s == ' ' || *s == '\t') {
s++;
}
if (*s == '\0') {
/* We have reached the end of the string. */
@ -686,14 +700,17 @@ strtoargvsub(isc_mem_t *mctx, char *s, unsigned int *argcp, char ***argvp,
*argvp = isc_mem_get(mctx, n * sizeof(char *));
} else {
char *p = s;
while (*p != ' ' && *p != '\t' && *p != '\0')
while (*p != ' ' && *p != '\t' && *p != '\0') {
p++;
if (*p != '\0')
}
if (*p != '\0') {
*p++ = '\0';
}
result = strtoargvsub(mctx, p, argcp, argvp, n + 1);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
(*argvp)[n] = s;
}
return (ISC_R_SUCCESS);
@ -753,11 +770,13 @@ isself(dns_view_t *myview, dns_tsigkey_t *mykey, const isc_sockaddr_t *srcaddr,
isc_netaddr_t netsrc;
isc_netaddr_t netdst;
if (interfacemgr == NULL)
if (interfacemgr == NULL) {
return (true);
}
if (!ns_interfacemgr_listeningon(interfacemgr, dstaddr))
if (!ns_interfacemgr_listeningon(interfacemgr, dstaddr)) {
return (false);
}
isc_netaddr_fromsockaddr(&netsrc, srcaddr);
isc_netaddr_fromsockaddr(&netdst, dstaddr);
@ -766,23 +785,27 @@ isself(dns_view_t *myview, dns_tsigkey_t *mykey, const isc_sockaddr_t *srcaddr,
view = ISC_LIST_NEXT(view, link)) {
const dns_name_t *tsig = NULL;
if (view->matchrecursiveonly)
if (view->matchrecursiveonly) {
continue;
}
if (rdclass != view->rdclass)
if (rdclass != view->rdclass) {
continue;
}
if (mykey != NULL) {
bool match;
isc_result_t result;
result = dns_view_gettsig(view, &mykey->name, &key);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
continue;
}
match = dst_key_compare(mykey->key, key->key);
dns_tsigkey_detach(&key);
if (!match)
if (!match) {
continue;
}
tsig = dns_tsigkey_identity(mykey);
}
@ -897,11 +920,12 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
maps[i++] = named_g_defaults;
maps[i] = NULL;
if (vconfig != NULL)
if (vconfig != NULL) {
RETERR(named_config_getclass(cfg_tuple_get(vconfig, "class"),
dns_rdataclass_in, &vclass));
else
} else {
vclass = dns_rdataclass_in;
}
/*
* Configure values common to all zone types.
@ -912,22 +936,26 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
RETERR(named_config_getclass(cfg_tuple_get(zconfig, "class"), vclass,
&zclass));
dns_zone_setclass(zone, zclass);
if (raw != NULL)
if (raw != NULL) {
dns_zone_setclass(raw, zclass);
}
ztype = zonetype_fromconfig(zoptions);
if (raw != NULL) {
dns_zone_settype(raw, ztype);
dns_zone_settype(zone, dns_zone_master);
} else
} else {
dns_zone_settype(zone, ztype);
}
obj = NULL;
result = cfg_map_get(zoptions, "database", &obj);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
cpval = isc_mem_strdup(mctx, cfg_obj_asstring(obj));
if (cpval == NULL)
}
if (cpval == NULL) {
return (ISC_R_NOMEMORY);
}
obj = NULL;
result = cfg_map_get(zoptions, "dlz", &obj);
@ -968,8 +996,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = cfg_map_get(zoptions, "file", &obj);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
filename = cfg_obj_asstring(obj);
}
/*
* Unless we're using some alternative database, a master zone
@ -983,10 +1012,11 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
return (ISC_R_FAILURE);
}
if (ztype == dns_zone_slave || ztype == dns_zone_mirror)
if (ztype == dns_zone_slave || ztype == dns_zone_mirror) {
masterformat = dns_masterformat_raw;
else
} else {
masterformat = dns_masterformat_text;
}
obj = NULL;
result = named_config_get(maps, "masterfile-format", &obj);
if (result == ISC_R_SUCCESS) {
@ -1040,19 +1070,22 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
} else if (result == ISC_R_SUCCESS) {
dns_ttl_t maxttl = 0; /* unlimited */
if (cfg_obj_isduration(obj))
if (cfg_obj_isduration(obj)) {
maxttl = cfg_obj_asduration(obj);
}
dns_zone_setmaxttl(zone, maxttl);
if (raw != NULL)
if (raw != NULL) {
dns_zone_setmaxttl(raw, maxttl);
}
}
obj = NULL;
result = named_config_get(maps, "max-records", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
dns_zone_setmaxrecords(mayberaw, cfg_obj_asuint32(obj));
if (zone != mayberaw)
if (zone != mayberaw) {
dns_zone_setmaxrecords(zone, 0);
}
if (raw != NULL && filename != NULL) {
#define SIGNED ".signed"
@ -1067,24 +1100,28 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = dns_zone_setfile(zone, signedname,
dns_masterformat_raw, NULL);
isc_mem_put(mctx, signedname, signedlen);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
} else
}
} else {
RETERR(dns_zone_setfile(zone, filename, masterformat,
masterstyle));
}
obj = NULL;
result = cfg_map_get(zoptions, "journal", &obj);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
RETERR(dns_zone_setjournal(mayberaw, cfg_obj_asstring(obj)));
}
/*
* Notify messages are processed by the raw zone if it exists.
*/
if (ztype == dns_zone_slave || ztype == dns_zone_mirror)
if (ztype == dns_zone_slave || ztype == dns_zone_mirror) {
RETERR(configure_zone_acl(
zconfig, vconfig, config, allow_notify, ac, mayberaw,
dns_zone_setnotifyacl, dns_zone_clearnotifyacl));
}
/*
* XXXAG This probably does not make sense for stubs.
@ -1101,10 +1138,11 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = named_config_get(maps, "dialup", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
if (cfg_obj_isboolean(obj)) {
if (cfg_obj_asboolean(obj))
if (cfg_obj_asboolean(obj)) {
dialup = dns_dialuptype_yes;
else
} else {
dialup = dns_dialuptype_no;
}
} else {
const char *dialupstr = cfg_obj_asstring(obj);
if (strcasecmp(dialupstr, "notify") == 0) {
@ -1120,18 +1158,20 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
ISC_UNREACHABLE();
}
}
if (raw != NULL)
if (raw != NULL) {
dns_zone_setdialup(raw, dialup);
}
dns_zone_setdialup(zone, dialup);
obj = NULL;
result = named_config_get(maps, "zone-statistics", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
if (cfg_obj_isboolean(obj)) {
if (cfg_obj_asboolean(obj))
if (cfg_obj_asboolean(obj)) {
statlevel = dns_zonestat_full;
else
} else {
statlevel = dns_zonestat_none;
}
} else {
const char *levelstr = cfg_obj_asstring(obj);
if (strcasecmp(levelstr, "full") == 0) {
@ -1163,11 +1203,13 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_zone_setdnssecsignstats(zone, dnssecsignstats);
dns_zone_setdnssecrefreshstats(zone, dnssecrefreshstats);
if (zoneqrystats != NULL)
if (zoneqrystats != NULL) {
isc_stats_detach(&zoneqrystats);
}
if (rcvquerystats != NULL)
if (rcvquerystats != NULL) {
dns_stats_detach(&rcvquerystats);
}
if (dnssecsignstats != NULL) {
dns_stats_detach(&dnssecsignstats);
@ -1207,10 +1249,11 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
result = named_config_get(maps, "notify", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
if (cfg_obj_isboolean(obj)) {
if (cfg_obj_asboolean(obj))
if (cfg_obj_asboolean(obj)) {
notifytype = dns_notifytype_yes;
else
} else {
notifytype = dns_notifytype_no;
}
} else {
const char *notifystr = cfg_obj_asstring(obj);
if (strcasecmp(notifystr, "explicit") == 0) {
@ -1224,8 +1267,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
}
notifytype =
process_notifytype(notifytype, ztype, zname, nodefault);
if (raw != NULL)
if (raw != NULL) {
dns_zone_setnotifytype(raw, dns_notifytype_no);
}
dns_zone_setnotifytype(zone, notifytype);
obj = NULL;
@ -1245,16 +1289,18 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
ipkl.count);
dns_ipkeylist_clear(mctx, &ipkl);
RETERR(result);
} else
} else {
RETERR(dns_zone_setalsonotify(zone, NULL, 0));
}
obj = NULL;
result = named_config_get(maps, "notify-source", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setnotifysrc4(zone, cfg_obj_assockaddr(obj)));
dscp = cfg_obj_getdscp(obj);
if (dscp == -1)
if (dscp == -1) {
dscp = named_g_dscp;
}
RETERR(dns_zone_setnotifysrc4dscp(zone, dscp));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
@ -1264,8 +1310,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
INSIST(result == ISC_R_SUCCESS && obj != NULL);
RETERR(dns_zone_setnotifysrc6(zone, cfg_obj_assockaddr(obj)));
dscp = cfg_obj_getdscp(obj);
if (dscp == -1)
if (dscp == -1) {
dscp = named_g_dscp;
}
RETERR(dns_zone_setnotifysrc6dscp(zone, dscp));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
@ -1295,8 +1342,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = named_config_get(maps, "max-journal-size", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
if (raw != NULL)
if (raw != NULL) {
dns_zone_setjournalsize(raw, -1);
}
dns_zone_setjournalsize(zone, -1);
if (cfg_obj_isstring(obj)) {
const char *str = cfg_obj_asstring(obj);
@ -1319,8 +1367,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
}
journal_size = (uint32_t)value;
}
if (raw != NULL)
if (raw != NULL) {
dns_zone_setjournalsize(raw, journal_size);
}
dns_zone_setjournalsize(zone, journal_size);
obj = NULL;
@ -1345,9 +1394,10 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
true);
dns_zone_setoption(zone, DNS_ZONEOPT_IXFRFROMDIFFS,
false);
} else
} else {
dns_zone_setoption(zone, DNS_ZONEOPT_IXFRFROMDIFFS,
ixfrdiff);
}
obj = NULL;
result = named_config_get(maps, "request-expire", &obj);
@ -1462,12 +1512,13 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_zone_setupdateacl, dns_zone_clearupdateacl));
updateacl = dns_zone_getupdateacl(mayberaw);
if (updateacl != NULL && dns_acl_isinsecure(updateacl))
if (updateacl != NULL && dns_acl_isinsecure(updateacl)) {
isc_log_write(named_g_lctx, DNS_LOGCATEGORY_SECURITY,
NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING,
"zone '%s' allows unsigned updates "
"from remote hosts, which is insecure",
zname);
}
RETERR(configure_zone_ssutable(zoptions, mayberaw, zname));
}
@ -1586,7 +1637,6 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
} else if (strcasecmp(arg, "maintain") == 0) {
allow = maint = true;
} else if (strcasecmp(arg, "off") == 0) {
;
} else {
INSIST(0);
ISC_UNREACHABLE();
@ -1610,10 +1660,11 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
if (ztype == dns_zone_master) {
obj = NULL;
result = named_config_get(maps, "check-wildcard", &obj);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
check = cfg_obj_asboolean(obj);
else
} else {
check = false;
}
dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKWILDCARD, check);
/*
@ -1630,10 +1681,11 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
} else {
result = named_config_get(nodefault,
"check-dup-records", &obj);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
dupcheck = cfg_obj_asstring(obj);
else
} else {
dupcheck = "ignore";
}
}
if (strcasecmp(dupcheck, "warn") == 0) {
fail = false;
@ -1682,8 +1734,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
check = false;
result = named_config_get(nodefault, "check-integrity",
&obj);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
check = cfg_obj_asboolean(obj);
}
dns_zone_setoption(mayberaw, DNS_ZONEOPT_CHECKINTEGRITY,
check);
}
@ -1738,7 +1791,6 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_zone_setkeyopt(zone, DNS_ZONEKEY_NORESIGN,
true);
} else if (strcasecmp(arg, "maintain") == 0) {
;
} else {
INSIST(0);
ISC_UNREACHABLE();
@ -1748,15 +1800,16 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
obj = NULL;
result = named_config_get(maps, "serial-update-method", &obj);
INSIST(result == ISC_R_SUCCESS && obj != NULL);
if (strcasecmp(cfg_obj_asstring(obj), "unixtime") == 0)
if (strcasecmp(cfg_obj_asstring(obj), "unixtime") == 0) {
dns_zone_setserialupdatemethod(
zone, dns_updatemethod_unixtime);
else if (strcasecmp(cfg_obj_asstring(obj), "date") == 0)
} else if (strcasecmp(cfg_obj_asstring(obj), "date") == 0) {
dns_zone_setserialupdatemethod(zone,
dns_updatemethod_date);
else
} else {
dns_zone_setserialupdatemethod(
zone, dns_updatemethod_increment);
}
}
/*
@ -1776,7 +1829,7 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
dns_zone_setxfracl(zone, none);
dns_acl_detach(&none);
}
/* FALLTHROUGH */
/* FALLTHROUGH */
case dns_zone_slave:
case dns_zone_stub:
case dns_zone_redirect:
@ -1805,8 +1858,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
count = ipkl.count;
dns_ipkeylist_clear(mctx, &ipkl);
RETERR(result);
} else
} else {
result = dns_zone_setmasters(mayberaw, NULL, 0);
}
RETERR(result);
multi = false;
@ -1854,8 +1908,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
RETERR(dns_zone_setxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
dscp = cfg_obj_getdscp(obj);
if (dscp == -1)
if (dscp == -1) {
dscp = named_g_dscp;
}
RETERR(dns_zone_setxfrsource4dscp(mayberaw, dscp));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
@ -1866,8 +1921,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
RETERR(dns_zone_setxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
dscp = cfg_obj_getdscp(obj);
if (dscp == -1)
if (dscp == -1) {
dscp = named_g_dscp;
}
RETERR(dns_zone_setxfrsource6dscp(mayberaw, dscp));
named_add_reserved_dispatch(named_g_server,
cfg_obj_assockaddr(obj));
@ -1878,8 +1934,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
RETERR(dns_zone_setaltxfrsource4(mayberaw,
cfg_obj_assockaddr(obj)));
dscp = cfg_obj_getdscp(obj);
if (dscp == -1)
if (dscp == -1) {
dscp = named_g_dscp;
}
RETERR(dns_zone_setaltxfrsource4dscp(mayberaw, dscp));
obj = NULL;
@ -1888,8 +1945,9 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
RETERR(dns_zone_setaltxfrsource6(mayberaw,
cfg_obj_assockaddr(obj)));
dscp = cfg_obj_getdscp(obj);
if (dscp == -1)
if (dscp == -1) {
dscp = named_g_dscp;
}
RETERR(dns_zone_setaltxfrsource6dscp(mayberaw, dscp));
obj = NULL;
@ -1900,12 +1958,15 @@ named_zone_configure(const cfg_obj_t *config, const cfg_obj_t *vconfig,
* on for BIND 8 compatibility.
*/
view = dns_zone_getview(zone);
if (view != NULL && strcmp(view->name, "_default") == 0)
if (view != NULL &&
strcmp(view->name, "_default") == 0) {
alt = true;
else
} else {
alt = false;
} else
}
} else {
alt = cfg_obj_asboolean(obj);
}
dns_zone_setoption(mayberaw, DNS_ZONEOPT_USEALTXFRSRC, alt);
obj = NULL;
@ -1941,8 +2002,9 @@ named_zone_configure_writeable_dlz(dns_dlzdb_t *dlzdatabase, dns_zone_t *zone,
dns_zone_settype(zone, dns_zone_dlz);
result = dns_sdlz_setdb(dlzdatabase, rdclass, name, &db);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
result = dns_zone_dlzpostload(zone, db);
dns_db_detach(&db);
return (result);
@ -2004,10 +2066,11 @@ named_zone_reusable(dns_zone_t *zone, const cfg_obj_t *zconfig)
obj = NULL;
(void)cfg_map_get(zoptions, "file", &obj);
if (obj != NULL)
if (obj != NULL) {
cfilename = cfg_obj_asstring(obj);
else
} else {
cfilename = NULL;
}
if (!((cfilename == NULL && zfilename == NULL) ||
(cfilename != NULL && zfilename != NULL &&
strcmp(cfilename, zfilename) == 0))) {

File diff suppressed because it is too large Load diff

View file

@ -62,7 +62,7 @@
#ifdef WIN32
#define sleep(x) Sleep(x)
#endif
#endif /* ifdef WIN32 */
int
main(int argc, char *argv[])
@ -138,8 +138,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -183,8 +184,9 @@ main(int argc, char *argv[])
if (ulObjectCount == 0) {
printf("No matching key objects found.\n");
goto exit_search;
} else
} else {
printf("Key object%s found:\n", ulObjectCount > 1 ? "s" : "");
}
for (i = 0; i < ulObjectCount; i++) {
CK_OBJECT_CLASS oclass = 0;
@ -211,16 +213,19 @@ main(int argc, char *argv[])
len = attr_template[2].ulValueLen;
printf(" object[%u]: class %lu, label '%s', id[%lu] ", i,
oclass, labelbuf, attr_template[2].ulValueLen);
if (len > 4)
if (len > 4) {
len = 4;
if (len > 0)
}
if (len > 0) {
printf("0x");
}
for (j = 0; j < len; j++)
printf("%02x", idbuf[j]);
if (attr_template[2].ulValueLen > len)
if (attr_template[2].ulValueLen > len) {
printf("...\n");
else
} else {
printf("\n");
}
}
if (wait != 0) {
@ -245,8 +250,9 @@ main(int argc, char *argv[])
}
}
if (error == 0)
if (error == 0) {
printf("Destruction complete.\n");
}
exit_search:
rv = pkcs_C_FindObjectsFinal(hSession);

View file

@ -150,20 +150,22 @@ static CK_ATTRIBUTE ecc_template[] = {
static key_class_t
keyclass_fromtext(const char *name)
{
if (name == NULL)
if (name == NULL) {
return (key_unknown);
}
if (strncasecmp(name, "rsa", 3) == 0 ||
strncasecmp(name, "nsec3rsa", 8) == 0)
strncasecmp(name, "nsec3rsa", 8) == 0) {
return (key_rsa);
else if (strncasecmp(name, "ecc", 3) == 0 ||
strncasecmp(name, "ecdsa", 5) == 0)
} else if (strncasecmp(name, "ecc", 3) == 0 ||
strncasecmp(name, "ecdsa", 5) == 0) {
return (key_ecc);
else if (strncasecmp(name, "ecx", 3) == 0 ||
strncasecmp(name, "ed", 2) == 0)
} else if (strncasecmp(name, "ecx", 3) == 0 ||
strncasecmp(name, "ed", 2) == 0) {
return (key_ecx);
else
} else {
return (key_unknown);
}
}
static void
@ -253,11 +255,13 @@ main(int argc, char *argv[])
}
}
if (label == NULL && isc_commandline_index < argc)
if (label == NULL && isc_commandline_index < argc) {
label = (CK_CHAR *)argv[isc_commandline_index];
}
if (errflg || (label == NULL))
if (errflg || (label == NULL)) {
usage();
}
if (expsize != 0 && keyclass != key_rsa) {
fprintf(stderr, "The -e option is only compatible "
@ -268,10 +272,12 @@ main(int argc, char *argv[])
switch (keyclass) {
case key_rsa:
op_type = OP_RSA;
if (expsize == 0)
if (expsize == 0) {
expsize = 3;
if (bits == 0)
}
if (bits == 0) {
usage();
}
mech.mechanism = CKM_RSA_PKCS_KEY_PAIR_GEN;
mech.pParameter = NULL;
@ -284,9 +290,9 @@ main(int argc, char *argv[])
/* Set public exponent to F4 or F5 */
exponent[0] = 0x01;
exponent[1] = 0x00;
if (expsize == 3)
if (expsize == 3) {
exponent[2] = 0x01;
else {
} else {
exponent[2] = 0x00;
exponent[3] = 0x00;
exponent[4] = 0x01;
@ -299,9 +305,9 @@ main(int argc, char *argv[])
break;
case key_ecc:
op_type = OP_ECDSA;
if (bits == 0)
if (bits == 0) {
bits = 256;
else if (bits != 256 && bits != 384) {
} else if (bits != 256 && bits != 384) {
fprintf(stderr, "ECC keys only support bit sizes of "
"256 and 384\n");
exit(2);
@ -330,11 +336,11 @@ main(int argc, char *argv[])
#ifndef CKM_EDDSA_KEY_PAIR_GEN
fprintf(stderr, "CKM_EDDSA_KEY_PAIR_GEN is not defined\n");
usage();
#else
#else /* ifndef CKM_EDDSA_KEY_PAIR_GEN */
op_type = OP_EDDSA;
if (bits == 0)
if (bits == 0) {
bits = 256;
else if (bits != 256 && bits != 456) {
} else if (bits != 256 && bits != 456) {
fprintf(stderr, "ECX keys only support bit sizes of "
"256 and 456\n");
exit(2);
@ -357,7 +363,7 @@ main(int argc, char *argv[])
public_template[4].ulValueLen = sizeof(pk11_ecc_ed448);
}
#endif
#endif /* ifndef CKM_EDDSA_KEY_PAIR_GEN */
break;
case key_unknown:
usage();
@ -394,8 +400,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");

View file

@ -114,11 +114,13 @@ main(int argc, char *argv[])
exit(1);
}
if (!id && (label == NULL))
if (!id && (label == NULL)) {
all = true;
}
if (slot)
if (slot) {
printf("slot %lu\n", slot);
}
if (id) {
printf("id %u\n", id);
@ -134,8 +136,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (logon && pin == NULL) {
pin = getpass("Enter Pin: ");
@ -160,8 +163,9 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen(pin));
}
hSession = pctx.session;
@ -208,12 +212,13 @@ main(int argc, char *argv[])
"C_GetAttributeValue[%u]: "
"rv = 0x%.8lX\n",
i, rv);
if (rv == CKR_BUFFER_TOO_SMALL)
if (rv == CKR_BUFFER_TOO_SMALL) {
fprintf(stderr,
"%u too small: %lu %lu %lu\n",
i, template[0].ulValueLen,
template[1].ulValueLen,
template[2].ulValueLen);
}
error = 1;
continue;
}
@ -228,14 +233,17 @@ main(int argc, char *argv[])
id |= idbuf[1] & 0xff;
printf("%u", id);
} else {
if (len > 8)
if (len > 8) {
len = 8;
if (len > 0)
}
if (len > 0) {
printf("0x");
}
for (j = 0; j < len; j++)
printf("%02x", idbuf[j]);
if (template[2].ulValueLen > len)
if (template[2].ulValueLen > len) {
printf("...");
}
}
if ((oclass == CKO_PRIVATE_KEY ||
oclass == CKO_SECRET_KEY) &&

View file

@ -70,8 +70,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
result = pk11_get_session(&pctx, OP_ANY, true, false, false, NULL, 0);
if (result == PK11_R_NORANDOMSERVICE ||
@ -89,8 +90,9 @@ main(int argc, char *argv[])
pk11_dump_tokens();
if (pctx.handle != NULL)
if (pctx.handle != NULL) {
pk11_return_session(&pctx);
}
(void)pk11_finalize();
isc_mem_destroy(&mctx);

View file

@ -174,8 +174,8 @@ install_hooks(ns_hooktable_t *hooktable, isc_mem_t *mctx,
}
/**
** Support for parsing of parameters and configuration of the module.
**/
** Support for parsing of parameters and configuration of the module.
**/
/*
* Support for parsing of parameters.
@ -326,13 +326,13 @@ cleanup:
}
/**
** Mandatory plugin API functions:
**
** - plugin_destroy
** - plugin_register
** - plugin_version
** - plugin_check
**/
** Mandatory plugin API functions:
**
** - plugin_destroy
** - plugin_register
** - plugin_version
** - plugin_check
**/
/*
* Called by ns_plugin_register() to initialize the plugin and
@ -461,8 +461,8 @@ plugin_version(void)
}
/**
** "filter-aaaa" feature implementation begins here.
**/
** "filter-aaaa" feature implementation begins here.
**/
/*%
* Structure describing the filtering to be applied by process_section().

View file

@ -31,4 +31,4 @@ set_user(FILE *fd, const char *user);
ISC_LANG_ENDDECLS
#endif
#endif /* ifndef RNDC_OS_H */

View file

@ -256,17 +256,19 @@ get_addresses(const char *host, in_port_t port)
if (*host == '/') {
result =
isc_sockaddr_frompath(&serveraddrs[nserveraddrs], host);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
nserveraddrs++;
}
} else {
count = SERVERADDRS - nserveraddrs;
result = bind9_getaddresses(
host, port, &serveraddrs[nserveraddrs], count, &found);
nserveraddrs += found;
}
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("couldn't get address for '%s': %s", host,
isc_result_totext(result));
}
INSIST(nserveraddrs > 0);
}
@ -301,7 +303,7 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event)
atomic_fetch_sub_release(&recvs, 1);
if (ccmsg.result == ISC_R_EOF)
if (ccmsg.result == ISC_R_EOF) {
fatal("connection to remote host closed\n"
"This may indicate that\n"
"* the remote server is using an older version of"
@ -309,9 +311,11 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event)
"* this host is not authorized to connect,\n"
"* the clocks are not synchronized, or\n"
"* the key is invalid.");
}
if (ccmsg.result != ISC_R_SUCCESS)
if (ccmsg.result != ISC_R_SUCCESS) {
fatal("recv failed: %s", isc_result_totext(ccmsg.result));
}
source.rstart = isc_buffer_base(&ccmsg.buffer);
source.rend = isc_buffer_used(&ccmsg.buffer);
@ -320,33 +324,38 @@ rndc_recvdone(isc_task_t *task, isc_event_t *event)
isccc_cc_fromwire(&source, &response, algorithm, &secret));
data = isccc_alist_lookup(response, "_data");
if (!isccc_alist_alistp(data))
if (!isccc_alist_alistp(data)) {
fatal("bad or missing data section in response");
}
result = isccc_cc_lookupstring(data, "err", &errormsg);
if (result == ISC_R_SUCCESS) {
failed = true;
fprintf(stderr, "%s: '%s' failed: %s\n", progname, command,
errormsg);
} else if (result != ISC_R_NOTFOUND)
} else if (result != ISC_R_NOTFOUND) {
fprintf(stderr, "%s: parsing response failed: %s\n", progname,
isc_result_totext(result));
}
result = isccc_cc_lookupstring(data, "text", &textmsg);
if (result == ISC_R_SUCCESS) {
if ((!quiet || failed) && strlen(textmsg) != 0U)
if ((!quiet || failed) && strlen(textmsg) != 0U) {
fprintf(failed ? stderr : stdout, "%s\n", textmsg);
} else if (result != ISC_R_NOTFOUND)
}
} else if (result != ISC_R_NOTFOUND) {
fprintf(stderr, "%s: parsing response failed: %s\n", progname,
isc_result_totext(result));
}
if (showresult) {
isc_result_t eresult;
result = isccc_cc_lookupuint32(data, "result", &eresult);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
printf("%s %u\n", isc_result_toid(eresult), eresult);
else
} else {
printf("NONE -1\n");
}
}
isc_event_free(&event);
@ -375,7 +384,7 @@ rndc_recvnonce(isc_task_t *task, isc_event_t *event)
atomic_fetch_sub_release(&recvs, 1);
if (ccmsg.result == ISC_R_EOF)
if (ccmsg.result == ISC_R_EOF) {
fatal("connection to remote host closed\n"
"This may indicate that\n"
"* the remote server is using an older version of"
@ -384,9 +393,11 @@ rndc_recvnonce(isc_task_t *task, isc_event_t *event)
"* the clocks are not synchronized,\n"
"* the key signing algorithm is incorrect, or\n"
"* the key is invalid.");
}
if (ccmsg.result != ISC_R_SUCCESS)
if (ccmsg.result != ISC_R_SUCCESS) {
fatal("recv failed: %s", isc_result_totext(ccmsg.result));
}
source.rstart = isc_buffer_base(&ccmsg.buffer);
source.rend = isc_buffer_used(&ccmsg.buffer);
@ -395,27 +406,33 @@ rndc_recvnonce(isc_task_t *task, isc_event_t *event)
isccc_cc_fromwire(&source, &response, algorithm, &secret));
_ctrl = isccc_alist_lookup(response, "_ctrl");
if (!isccc_alist_alistp(_ctrl))
if (!isccc_alist_alistp(_ctrl)) {
fatal("bad or missing ctrl section in response");
}
nonce = 0;
if (isccc_cc_lookupuint32(_ctrl, "_nonce", &nonce) != ISC_R_SUCCESS)
if (isccc_cc_lookupuint32(_ctrl, "_nonce", &nonce) != ISC_R_SUCCESS) {
nonce = 0;
}
isc_stdtime_get(&now);
DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,
now, now + 60, &request));
data = isccc_alist_lookup(request, "_data");
if (data == NULL)
if (data == NULL) {
fatal("_data section missing");
if (isccc_cc_definestring(data, "type", args) == NULL)
}
if (isccc_cc_definestring(data, "type", args) == NULL) {
fatal("out of memory");
}
if (nonce != 0) {
_ctrl = isccc_alist_lookup(request, "_ctrl");
if (_ctrl == NULL)
if (_ctrl == NULL) {
fatal("_ctrl section missing");
if (isccc_cc_defineuint32(_ctrl, "_nonce", nonce) == NULL)
}
if (isccc_cc_defineuint32(_ctrl, "_nonce", nonce) == NULL) {
fatal("out of memory");
}
}
isc_buffer_clear(databuf);
@ -470,19 +487,22 @@ rndc_connected(isc_task_t *task, isc_event_t *event)
isc_event_free(&event);
rndc_startconnect(&serveraddrs[currentaddr], task);
return;
} else
} else {
fatal("connect failed: %s: %s", socktext,
isc_result_totext(sevent->result));
}
}
isc_stdtime_get(&now);
DO("create message", isccc_cc_createmessage(1, NULL, NULL, ++serial,
now, now + 60, &request));
data = isccc_alist_lookup(request, "_data");
if (data == NULL)
if (data == NULL) {
fatal("_data section missing");
if (isccc_cc_definestring(data, "type", "null") == NULL)
}
if (isccc_cc_definestring(data, "type", "null") == NULL) {
fatal("out of memory");
}
isc_buffer_clear(databuf);
/* Skip the length field (4 bytes) */
@ -524,10 +544,11 @@ rndc_startconnect(isc_sockaddr_t *addr, isc_task_t *task)
notify("using server %s (%s)", servername, socktext);
pf = isc_sockaddr_pf(addr);
if (pf == AF_INET || pf == AF_INET6)
if (pf == AF_INET || pf == AF_INET6) {
type = isc_sockettype_tcp;
else
} else {
type = isc_sockettype_unix;
}
DO("create socket", isc_socket_create(socketmgr, pf, type, &sock));
switch (isc_sockaddr_pf(addr)) {
case AF_INET:
@ -583,12 +604,14 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
conffile = admin_keyfile;
conftype = &cfg_type_rndckey;
if (c_flag)
if (c_flag) {
fatal("%s does not exist", admin_conffile);
}
if (!isc_file_exists(conffile))
if (!isc_file_exists(conffile)) {
fatal("neither %s nor %s was found", admin_conffile,
admin_keyfile);
}
key_only = true;
} else if (!c_flag && isc_file_exists(admin_keyfile)) {
fprintf(stderr,
@ -603,23 +626,27 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
* The parser will output its own errors, so DO() is not used.
*/
result = cfg_parse_file(*pctxp, conffile, conftype, &config);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("could not load rndc configuration");
if (!key_only)
(void)cfg_map_get(config, "options", &options);
if (key_only && servername == NULL)
servername = "127.0.0.1";
else if (servername == NULL && options != NULL) {
const cfg_obj_t *defserverobj = NULL;
(void)cfg_map_get(options, "default-server", &defserverobj);
if (defserverobj != NULL)
servername = cfg_obj_asstring(defserverobj);
}
if (servername == NULL)
if (!key_only) {
(void)cfg_map_get(config, "options", &options);
}
if (key_only && servername == NULL) {
servername = "127.0.0.1";
} else if (servername == NULL && options != NULL) {
const cfg_obj_t *defserverobj = NULL;
(void)cfg_map_get(options, "default-server", &defserverobj);
if (defserverobj != NULL) {
servername = cfg_obj_asstring(defserverobj);
}
}
if (servername == NULL) {
fatal("no server specified and no default");
}
if (!key_only) {
(void)cfg_map_get(config, "server", &servers);
@ -630,8 +657,9 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
server = cfg_listelt_value(elt);
name = cfg_obj_asstring(
cfg_map_getname(server));
if (strcasecmp(name, servername) == 0)
if (strcasecmp(name, servername) == 0) {
break;
}
server = NULL;
}
}
@ -640,39 +668,43 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
/*
* Look for the name of the key to use.
*/
if (keyname != NULL)
; /* Was set on command line, do nothing. */
else if (server != NULL) {
if (keyname != NULL) {
/* Was set on command line, do nothing. */
} else if (server != NULL) {
DO("get key for server", cfg_map_get(server, "key", &defkey));
keyname = cfg_obj_asstring(defkey);
} else if (options != NULL) {
DO("get default key",
cfg_map_get(options, "default-key", &defkey));
keyname = cfg_obj_asstring(defkey);
} else if (!key_only)
} else if (!key_only) {
fatal("no key for server and no default");
}
/*
* Get the key's definition.
*/
if (key_only)
if (key_only) {
DO("get key", cfg_map_get(config, "key", &key));
else {
} else {
DO("get config key list", cfg_map_get(config, "key", &keys));
for (elt = cfg_list_first(keys); elt != NULL;
elt = cfg_list_next(elt)) {
key = cfg_listelt_value(elt);
if (strcasecmp(cfg_obj_asstring(cfg_map_getname(key)),
keyname) == 0)
keyname) == 0) {
break;
}
}
if (elt == NULL)
if (elt == NULL) {
fatal("no key definition for name %s", keyname);
}
}
(void)cfg_map_get(key, "secret", &secretobj);
(void)cfg_map_get(key, "algorithm", &algorithmobj);
if (secretobj == NULL || algorithmobj == NULL)
if (secretobj == NULL || algorithmobj == NULL) {
fatal("key must have algorithm and secret");
}
secretstr = cfg_obj_asstring(secretobj);
algorithmstr = cfg_obj_asstring(algorithmobj);
@ -702,25 +734,30 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
/*
* Find the port to connect to.
*/
if (remoteport != 0)
; /* Was set on command line, do nothing. */
else {
if (server != NULL)
if (remoteport != 0) {
/* Was set on command line, do nothing. */
} else {
if (server != NULL) {
(void)cfg_map_get(server, "port", &defport);
if (defport == NULL && options != NULL)
}
if (defport == NULL && options != NULL) {
(void)cfg_map_get(options, "default-port", &defport);
}
}
if (defport != NULL) {
remoteport = cfg_obj_asuint32(defport);
if (remoteport > 65535 || remoteport == 0)
if (remoteport > 65535 || remoteport == 0) {
fatal("port %u out of range", remoteport);
} else if (remoteport == 0)
}
} else if (remoteport == 0) {
remoteport = NS_CONTROL_PORT;
}
if (server != NULL)
if (server != NULL) {
result = cfg_map_get(server, "addresses", &addresses);
else
} else {
result = ISC_R_NOTFOUND;
}
if (result == ISC_R_SUCCESS) {
for (element = cfg_list_first(addresses); element != NULL;
element = cfg_list_next(element)) {
@ -737,26 +774,31 @@ parse_config(isc_mem_t *mctx, isc_log_t *log, const char *keyname,
obj = cfg_tuple_get(address, "port");
if (cfg_obj_isuint32(obj)) {
myport = cfg_obj_asuint32(obj);
if (myport > UINT16_MAX || myport == 0)
if (myport > UINT16_MAX ||
myport == 0) {
fatal("port %u out of range",
myport);
} else
}
} else {
myport = remoteport;
if (nserveraddrs < SERVERADDRS)
}
if (nserveraddrs < SERVERADDRS) {
get_addresses(name, (in_port_t)myport);
else
} else {
fprintf(stderr,
"too many address: "
"%s: dropped\n",
name);
}
continue;
}
sa = *cfg_obj_assockaddr(address);
if (isc_sockaddr_getport(&sa) == 0)
if (isc_sockaddr_getport(&sa) == 0) {
isc_sockaddr_setport(&sa, remoteport);
if (nserveraddrs < SERVERADDRS)
}
if (nserveraddrs < SERVERADDRS) {
serveraddrs[nserveraddrs++] = sa;
else {
} else {
char socktext[ISC_SOCKADDR_FORMATSIZE];
isc_sockaddr_format(&sa, socktext,
@ -826,8 +868,9 @@ main(int argc, char **argv)
int i;
result = isc_file_progname(*argv, program, sizeof(program));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
memmove(program, "rndc", 5);
}
progname = program;
admin_conffile = RNDC_CONFFILE;
@ -837,8 +880,9 @@ main(int argc, char **argv)
isc_sockaddr_any6(&local6);
result = isc_app_start();
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("isc_app_start() failed: %s", isc_result_totext(result));
}
isc_commandline_errprint = false;
@ -889,9 +933,10 @@ main(int argc, char **argv)
case 'p':
remoteport = atoi(isc_commandline_argument);
if (remoteport > 65535 || remoteport == 0)
if (remoteport > 65535 || remoteport == 0) {
fatal("port '%s' out of range",
isc_commandline_argument);
}
break;
case 'q':
@ -920,7 +965,7 @@ main(int argc, char **argv)
program, isc_commandline_option);
usage(1);
}
/* FALLTHROUGH */
/* FALLTHROUGH */
case 'h':
usage(0);
break;
@ -934,8 +979,9 @@ main(int argc, char **argv)
argc -= isc_commandline_index;
argv += isc_commandline_index;
if (argc < 1)
if (argc < 1) {
usage(1);
}
serial = isc_random32();
@ -975,8 +1021,9 @@ main(int argc, char **argv)
* (if that were implemented).
*/
argslen = 0;
for (i = 0; i < argc; i++)
for (i = 0; i < argc; i++) {
argslen += strlen(argv[i]) + 1;
}
args = isc_mem_get(rndc_mctx, argslen);
@ -994,17 +1041,20 @@ main(int argc, char **argv)
notify("%s", command);
if (strcmp(command, "restart") == 0)
if (strcmp(command, "restart") == 0) {
fatal("'%s' is not implemented", command);
}
if (nserveraddrs == 0)
if (nserveraddrs == 0) {
get_addresses(servername, (in_port_t)remoteport);
}
DO("post event", isc_app_onrun(rndc_mctx, task, rndc_start, NULL));
result = isc_app_run();
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fatal("isc_app_run() failed: %s", isc_result_totext(result));
}
if (atomic_load_acquire(&connects) > 0 ||
atomic_load_acquire(&sends) > 0 ||
@ -1026,13 +1076,15 @@ main(int argc, char **argv)
isc_buffer_free(&databuf);
if (show_final_mem)
if (show_final_mem) {
isc_mem_stats(rndc_mctx, stderr);
}
isc_mem_destroy(&rndc_mctx);
if (failed)
if (failed) {
return (1);
}
return (0);
}

View file

@ -30,8 +30,9 @@ check_result(isc_result_t result, const char *format, ...)
{
va_list args;
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return;
}
va_start(args, format);
vfprintf(stderr, format, args);
@ -98,8 +99,9 @@ main(int argc, char **argv)
*/
isc_log_setdebuglevel(lctx, 2);
if (argc < 3)
if (argc < 3) {
usage();
}
while (argc > 1) {
if (strcmp(argv[1], "--active") == 0) {
@ -151,14 +153,16 @@ main(int argc, char **argv)
}
if (grammar) {
if (type == NULL)
if (type == NULL) {
usage();
}
cfg_print_grammar(type, pflags, output, NULL);
} else if (zonetype != 0) {
cfg_print_zonegrammar(zonetype, pflags, output, NULL);
} else {
if (type == NULL || filename == NULL)
if (type == NULL || filename == NULL) {
usage();
}
RUNTIME_CHECK(cfg_parser_create(mctx, lctx, &pctx) ==
ISC_R_SUCCESS);
@ -166,8 +170,9 @@ main(int argc, char **argv)
fprintf(stderr, "read config: %s\n", isc_result_totext(result));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
exit(1);
}
cfg_print(cfg, output, NULL);
@ -177,14 +182,16 @@ main(int argc, char **argv)
}
isc_log_destroy(&lctx);
if (memstats)
if (memstats) {
isc_mem_stats(mctx, stderr);
}
isc_mem_destroy(&mctx);
fflush(stdout);
if (ferror(stdout)) {
fprintf(stderr, "write error\n");
return (1);
} else
} else {
return (0);
}
}

View file

@ -63,13 +63,15 @@ loadzone(dns_db_t **db, const char *origin, const char *filename)
name = dns_fixedname_initname(&fixed);
result = dns_name_fromstring(name, origin, 0, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
result = dns_db_create(mctx, "rbt", name, dns_dbtype_zone,
dns_rdataclass_in, 0, NULL, db);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
result = dns_db_load(*db, filename, dns_masterformat_text, 0);
return (result);
@ -131,22 +133,27 @@ main(int argc, char **argv)
result = dns_db_diff(mctx, newdb, NULL, olddb, NULL, journal);
cleanup:
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "%s\n", isc_result_totext(result));
}
if (newdb != NULL)
if (newdb != NULL) {
dns_db_detach(&newdb);
if (olddb != NULL)
}
if (olddb != NULL) {
dns_db_detach(&olddb);
}
if (lctx != NULL)
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
if (dst_active) {
dst_lib_destroy();
dst_active = false;
}
if (mctx != NULL)
if (mctx != NULL) {
isc_mem_destroy(&mctx);
}
return (result != ISC_R_SUCCESS ? 1 : 0);
}

View file

@ -65,8 +65,9 @@ check_result(isc_result_t result, const char *format, ...)
{
va_list args;
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return;
}
va_start(args, format);
vfprintf(stderr, format, args);
@ -260,8 +261,9 @@ lookup(const char *target)
result = dns_adb_createfind(
adb, t2, lookup_callback, client, &client->name, dns_rootname,
0, options, now, NULL, view->dstport, 0, NULL, &client->find);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
printf("DNS_ADB_CREATEFIND -> %s\n", dns_result_totext(result));
}
dns_adb_dumpfind(client->find, stderr);
if ((client->find->options & DNS_ADBFIND_WANTEVENT) != 0) {

View file

@ -35,8 +35,9 @@ func3()
return (1);
}
if (nframes < 4)
if (nframes < 4) {
error++;
}
for (i = 0; i < 4 && i < nframes; i++) {
fname = NULL;
@ -45,8 +46,9 @@ func3()
error++;
continue;
}
if (strcmp(fname, expected_symbols[i]) != 0)
if (strcmp(fname, expected_symbols[i]) != 0) {
error++;
}
}
if (error) {
@ -57,9 +59,9 @@ func3()
fname = NULL;
result = isc_backtrace_getsymbol(tracebuf[i], &fname,
&offset);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
printf(" [%d] %s\n", i, fname);
else {
} else {
printf(" [%d] %p getsymbol failed: %s\n", i,
tracebuf[i], isc_result_totext(result));
}

View file

@ -174,10 +174,12 @@ main(int argc, char *argv[])
dispatchmgr, disp4,
disp6) == ISC_R_SUCCESS);
if (disp4 != NULL)
if (disp4 != NULL) {
dns_dispatch_detach(&disp4);
if (disp6 != NULL)
}
if (disp6 != NULL) {
dns_dispatch_detach(&disp6);
}
}
{
@ -240,8 +242,9 @@ main(int argc, char *argv[])
isc_socketmgr_destroy(&socketmgr);
isc_timermgr_destroy(&timermgr);
if (verbose)
if (verbose) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_app_finish();

View file

@ -111,8 +111,9 @@ do_find(bool want_event)
unsigned int options;
options = DNS_ADBFIND_INET | DNS_ADBFIND_INET6;
if (want_event)
if (want_event) {
options |= DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_EMPTYEVENT;
}
dns_fixedname_init(&target);
result = dns_adb_createfind(view->adb, task, adb_callback, NULL,
dns_fixedname_name(&fixed), dns_rootname, 0,
@ -154,8 +155,9 @@ do_find(bool want_event)
}
if (done) {
if (find != NULL)
if (find != NULL) {
dns_adb_destroyfind(&find);
}
isc_app_shutdown();
}
}
@ -170,9 +172,9 @@ adb_callback(isc_task_t *etask, isc_event_t *event)
isc_event_free(&event);
dns_adb_destroyfind(&find);
if (type == DNS_EVENT_ADBMOREADDRESSES)
if (type == DNS_EVENT_ADBMOREADDRESSES) {
do_find(false);
else if (type == DNS_EVENT_ADBNOMOREADDRESSES) {
} else if (type == DNS_EVENT_ADBNOMOREADDRESSES) {
printf("no more addresses\n");
isc_app_shutdown();
} else {
@ -292,10 +294,12 @@ main(int argc, char *argv[])
dispatchmgr, disp4,
disp6) == ISC_R_SUCCESS);
if (disp4 != NULL)
if (disp4 != NULL) {
dns_dispatch_detach(&disp4);
if (disp6 != NULL)
}
if (disp6 != NULL) {
dns_dispatch_detach(&disp6);
}
}
{
@ -345,8 +349,9 @@ main(int argc, char *argv[])
isc_log_destroy(&lctx);
if (verbose)
if (verbose) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_app_finish();

View file

@ -62,8 +62,9 @@ static bool ascending = true;
static void
print_result(const char *message, isc_result_t result)
{
if (message == NULL)
if (message == NULL) {
message = "";
}
printf("%s%sresult %08x: %s\n", message, (*message == '\0') ? "" : " ",
result, isc_result_totext(result));
}
@ -79,10 +80,11 @@ print_rdataset(dns_name_t *name, dns_rdataset_t *rdataset)
isc_buffer_init(&text, t, sizeof(t));
result = dns_rdataset_totext(rdataset, name, false, false, &text);
isc_buffer_usedregion(&text, &r);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
printf("%.*s", (int)r.length, (char *)r.base);
else
} else {
print_result("", result);
}
}
static void
@ -99,8 +101,9 @@ print_rdatasets(dns_name_t *name, dns_rdatasetiter_t *rdsiter)
dns_rdataset_disassociate(&rdataset);
result = dns_rdatasetiter_next(rdsiter);
}
if (result != ISC_R_NOMORE)
if (result != ISC_R_NOMORE) {
print_result("", result);
}
}
static dbinfo *
@ -114,8 +117,9 @@ select_db(char *origintext)
isc_result_t result;
if (strcasecmp(origintext, "cache") == 0) {
if (cache_dbi == NULL)
if (cache_dbi == NULL) {
printf("the cache does not exist\n");
}
return (cache_dbi);
}
len = strlen(origintext);
@ -130,8 +134,9 @@ select_db(char *origintext)
for (dbi = ISC_LIST_HEAD(dbs); dbi != NULL;
dbi = ISC_LIST_NEXT(dbi, link)) {
if (dns_name_compare(dns_db_origin(dbi->db), origin) == 0)
if (dns_name_compare(dns_db_origin(dbi->db), origin) == 0) {
break;
}
}
return (dbi);
@ -156,11 +161,12 @@ list(dbinfo *dbi, char *seektext)
if (dbi->dbiterator == NULL) {
INSIST(dbi->iversion == NULL);
if (dns_db_iszone(dbi->db)) {
if (dbi->version != NULL)
if (dbi->version != NULL) {
dns_db_attachversion(dbi->db, dbi->version,
&dbi->iversion);
else
} else {
dns_db_currentversion(dbi->db, &dbi->iversion);
}
}
result = dns_db_createiterator(dbi->db, 0, &dbi->dbiterator);
@ -173,24 +179,28 @@ list(dbinfo *dbi, char *seektext)
result = dns_name_fromtext(
seekname, &source,
dns_db_origin(dbi->db), 0, NULL);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
result = dns_dbiterator_seek(
dbi->dbiterator, seekname);
} else if (dbi->ascending)
}
} else if (dbi->ascending) {
result = dns_dbiterator_first(dbi->dbiterator);
else
} else {
result = dns_dbiterator_last(dbi->dbiterator);
}
}
} else
} else {
result = ISC_R_SUCCESS;
}
node = NULL;
rdsiter = NULL;
i = 0;
while (result == ISC_R_SUCCESS) {
result = dns_dbiterator_current(dbi->dbiterator, &node, name);
if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN)
if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) {
break;
}
result = dns_db_allrdatasets(dbi->db, node, dbi->iversion, 0,
&rdsiter);
if (result != ISC_R_SUCCESS) {
@ -200,24 +210,28 @@ list(dbinfo *dbi, char *seektext)
print_rdatasets(name, rdsiter);
dns_rdatasetiter_destroy(&rdsiter);
dns_db_detachnode(dbi->db, &node);
if (dbi->ascending)
if (dbi->ascending) {
result = dns_dbiterator_next(dbi->dbiterator);
else
} else {
result = dns_dbiterator_prev(dbi->dbiterator);
}
i++;
if (result == ISC_R_SUCCESS && i == dbi->pause_every) {
printf("[more...]\n");
result = dns_dbiterator_pause(dbi->dbiterator);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
return;
}
}
}
if (result != ISC_R_NOMORE)
if (result != ISC_R_NOMORE) {
print_result("", result);
}
dns_dbiterator_destroy(&dbi->dbiterator);
if (dbi->iversion != NULL)
if (dbi->iversion != NULL) {
dns_db_closeversion(dbi->db, &dbi->iversion, false);
}
}
static isc_result_t
@ -236,11 +250,13 @@ load(const char *filename, const char *origintext, bool cache)
dbi->db = NULL;
dbi->version = NULL;
dbi->wversion = NULL;
for (i = 0; i < MAXVERSIONS; i++)
for (i = 0; i < MAXVERSIONS; i++) {
dbi->rversions[i] = NULL;
}
dbi->hold_count = 0;
for (i = 0; i < MAXHOLD; i++)
for (i = 0; i < MAXHOLD; i++) {
dbi->hold_nodes[i] = NULL;
}
dbi->dbiterator = NULL;
dbi->iversion = NULL;
dbi->pause_every = pause_every;
@ -298,9 +314,9 @@ unload_all(void)
for (dbi = ISC_LIST_HEAD(dbs); dbi != NULL; dbi = dbi_next) {
dbi_next = ISC_LIST_NEXT(dbi, link);
if (dns_db_iszone(dbi->db))
if (dns_db_iszone(dbi->db)) {
dns_dbtable_remove(dbtable, dbi->db);
else {
} else {
INSIST(dbi == cache_dbi);
dns_dbtable_removedefault(dbtable);
cache_dbi = NULL;
@ -374,10 +390,11 @@ main(int argc, char *argv[])
switch (ch) {
case 'c':
result = load(isc_commandline_argument, ".", true);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
printf("cache load(%s) %08x: %s\n",
isc_commandline_argument, result,
isc_result_totext(result));
}
break;
case 'd':
n = strlcpy(dbtype, isc_commandline_argument,
@ -420,16 +437,18 @@ main(int argc, char *argv[])
break;
case 'z':
origintext = strrchr(isc_commandline_argument, '/');
if (origintext == NULL)
if (origintext == NULL) {
origintext = isc_commandline_argument;
else
} else {
origintext++; /* Skip '/'. */
}
result = load(isc_commandline_argument, origintext,
false);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
printf("zone load(%s) %08x: %s\n",
isc_commandline_argument, result,
isc_result_totext(result));
}
break;
}
}
@ -438,8 +457,9 @@ main(int argc, char *argv[])
argv += isc_commandline_index;
POST(argv);
if (argc != 0)
if (argc != 0) {
printf("ignoring trailing arguments\n");
}
/*
* Some final initialization...
@ -454,8 +474,9 @@ main(int argc, char *argv[])
}
while (!done) {
if (!quiet)
if (!quiet) {
printf("\n");
}
if (fgets(s, sizeof(s), stdin) == NULL) {
done = true;
continue;
@ -466,8 +487,9 @@ main(int argc, char *argv[])
len--;
}
if (verbose && dbi != NULL) {
if (dbi->wversion != NULL)
if (dbi->wversion != NULL) {
printf("future version (%p)\n", dbi->wversion);
}
for (i = 0; i < dbi->rcount; i++) {
if (dbi->rversions[i] != NULL) {
printf("open version %d (%p)\n", i,
@ -498,10 +520,11 @@ main(int argc, char *argv[])
continue;
}
result = dns_db_newversion(dbi->db, &dbi->wversion);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
print_result("", result);
else
} else {
printf("newversion\n");
}
dbi->version = dbi->wversion;
version = dbi->version;
continue;
@ -509,8 +532,9 @@ main(int argc, char *argv[])
DBI_CHECK(dbi);
addmode = false;
delmode = false;
if (dbi->version == NULL)
if (dbi->version == NULL) {
continue;
}
if (dbi->version == dbi->wversion) {
printf("closing future version\n");
dbi->wversion = NULL;
@ -532,8 +556,9 @@ main(int argc, char *argv[])
DBI_CHECK(dbi);
addmode = false;
delmode = false;
if (dbi->version == NULL)
if (dbi->version == NULL) {
continue;
}
if (dbi->version == dbi->wversion) {
printf("aborting future version\n");
dbi->wversion = NULL;
@ -554,33 +579,37 @@ main(int argc, char *argv[])
} else if (strcmp(s, "!A") == 0) {
DBI_CHECK(dbi);
delmode = false;
if (addmode)
if (addmode) {
addmode = false;
else
} else {
addmode = true;
}
printf("addmode = %s\n", addmode ? "TRUE" : "FALSE");
continue;
} else if (strcmp(s, "!D") == 0) {
DBI_CHECK(dbi);
addmode = false;
if (delmode)
if (delmode) {
delmode = false;
else
} else {
delmode = true;
}
printf("delmode = %s\n", delmode ? "TRUE" : "FALSE");
continue;
} else if (strcmp(s, "!H") == 0) {
DBI_CHECK(dbi);
if (holdmode)
if (holdmode) {
holdmode = false;
else
} else {
holdmode = true;
}
printf("holdmode = %s\n", holdmode ? "TRUE" : "FALSE");
continue;
} else if (strcmp(s, "!HR") == 0) {
DBI_CHECK(dbi);
for (i = 0; i < dbi->hold_count; i++)
for (i = 0; i < dbi->hold_count; i++) {
dns_db_detachnode(dbi->db, &dbi->hold_nodes[i]);
}
dbi->hold_count = 0;
holdmode = false;
printf("held nodes have been detached\n");
@ -615,29 +644,32 @@ main(int argc, char *argv[])
printf("now searching for type %u\n", type);
continue;
} else if (strcmp(s, "!G") == 0) {
if ((options & DNS_DBFIND_GLUEOK) != 0)
if ((options & DNS_DBFIND_GLUEOK) != 0) {
options &= ~DNS_DBFIND_GLUEOK;
else
} else {
options |= DNS_DBFIND_GLUEOK;
}
printf("glue ok = %s\n",
((options & DNS_DBFIND_GLUEOK) != 0) ? "TRUE"
: "FALSE");
continue;
} else if (strcmp(s, "!GV") == 0) {
if ((options & DNS_DBFIND_VALIDATEGLUE) != 0)
if ((options & DNS_DBFIND_VALIDATEGLUE) != 0) {
options &= ~DNS_DBFIND_VALIDATEGLUE;
else
} else {
options |= DNS_DBFIND_VALIDATEGLUE;
}
printf("validate glue = %s\n",
((options & DNS_DBFIND_VALIDATEGLUE) != 0)
? "TRUE"
: "FALSE");
continue;
} else if (strcmp(s, "!WC") == 0) {
if ((options & DNS_DBFIND_NOWILD) != 0)
if ((options & DNS_DBFIND_NOWILD) != 0) {
options &= ~DNS_DBFIND_NOWILD;
else
} else {
options |= DNS_DBFIND_NOWILD;
}
printf("wildcard matching = %s\n",
((options & DNS_DBFIND_NOWILD) == 0) ? "TRUE"
: "FALSE");
@ -659,10 +691,11 @@ main(int argc, char *argv[])
}
continue;
} else if (strcmp(s, "!PN") == 0) {
if (printnode)
if (printnode) {
printnode = false;
else
} else {
printnode = true;
}
printf("printnode = %s\n",
printnode ? "TRUE" : "FALSE");
continue;
@ -703,18 +736,20 @@ main(int argc, char *argv[])
}
continue;
} else if (strcmp(s, "!ZC") == 0) {
if (find_zonecut)
if (find_zonecut) {
find_zonecut = false;
else
} else {
find_zonecut = true;
}
printf("find_zonecut = %s\n",
find_zonecut ? "TRUE" : "FALSE");
continue;
} else if (strcmp(s, "!NZ") == 0) {
if (noexact_zonecut)
if (noexact_zonecut) {
noexact_zonecut = false;
else
} else {
noexact_zonecut = true;
}
printf("noexact_zonecut = %s\n",
noexact_zonecut ? "TRUE" : "FALSE");
continue;
@ -731,8 +766,9 @@ main(int argc, char *argv[])
if (dbi == NULL) {
zcoptions = 0;
if (noexact_zonecut)
if (noexact_zonecut) {
zcoptions |= DNS_DBTABLEFIND_NOEXACT;
}
db = NULL;
result = dns_dbtable_find(dbtable, &name, zcoptions,
&db);
@ -763,8 +799,9 @@ main(int argc, char *argv[])
if (find_zonecut && dns_db_iscache(db)) {
zcoptions = options;
if (noexact_zonecut)
if (noexact_zonecut) {
zcoptions |= DNS_DBFIND_NOEXACT;
}
result = dns_db_findzonecut(db, &name, zcoptions, 0,
&node, fname, NULL,
&rdataset, &sigrdataset);
@ -775,8 +812,9 @@ main(int argc, char *argv[])
}
if (!quiet) {
if (dbi != NULL)
if (dbi != NULL) {
printf("\n");
}
print_result("", result);
}
@ -792,8 +830,9 @@ main(int argc, char *argv[])
found_as = true;
break;
case DNS_R_NXRRSET:
if (dns_rdataset_isassociated(&rdataset))
if (dns_rdataset_isassociated(&rdataset)) {
break;
}
if (dbi != NULL) {
if (holdmode) {
RUNTIME_CHECK(dbi->hold_count <
@ -801,22 +840,26 @@ main(int argc, char *argv[])
dbi->hold_nodes[dbi->hold_count++] =
node;
node = NULL;
} else
} else {
dns_db_detachnode(db, &node);
}
} else {
dns_db_detachnode(db, &node);
dns_db_detach(&db);
}
continue;
case DNS_R_NXDOMAIN:
if (dns_rdataset_isassociated(&rdataset))
if (dns_rdataset_isassociated(&rdataset)) {
break;
/* FALLTHROUGH */
}
/* FALLTHROUGH */
default:
if (dbi == NULL)
if (dbi == NULL) {
dns_db_detach(&db);
if (quiet)
}
if (quiet) {
print_result("", result);
}
continue;
}
if (found_as && !quiet) {
@ -826,16 +869,18 @@ main(int argc, char *argv[])
if (result != ISC_R_SUCCESS) {
print_result("", result);
dns_db_detachnode(db, &node);
if (dbi == NULL)
if (dbi == NULL) {
dns_db_detach(&db);
}
continue;
}
result = dns_name_totext(fname, false, &tb2);
if (result != ISC_R_SUCCESS) {
print_result("", result);
dns_db_detachnode(db, &node);
if (dbi == NULL)
if (dbi == NULL) {
dns_db_detach(&db);
}
continue;
}
isc_buffer_usedregion(&tb1, &r1);
@ -844,48 +889,58 @@ main(int argc, char *argv[])
(int)r2.length, r2.base);
}
if (printnode)
if (printnode) {
dns_db_printnode(db, node, stdout);
}
if (!found_as && type == dns_rdatatype_any) {
rdsiter = NULL;
result = dns_db_allrdatasets(db, node, version, 0,
&rdsiter);
if (result == ISC_R_SUCCESS) {
if (!quiet)
if (!quiet) {
print_rdatasets(fname, rdsiter);
}
dns_rdatasetiter_destroy(&rdsiter);
} else
} else {
print_result("", result);
}
} else {
if (!quiet)
if (!quiet) {
print_rdataset(fname, &rdataset);
}
if (dns_rdataset_isassociated(&sigrdataset)) {
if (!quiet)
if (!quiet) {
print_rdataset(fname, &sigrdataset);
}
dns_rdataset_disassociate(&sigrdataset);
}
if (dbi != NULL && addmode && !found_as) {
rdataset.ttl++;
rdataset.trust = trust;
if (dns_db_iszone(db))
if (dns_db_iszone(db)) {
addopts = DNS_DBADD_MERGE;
else
} else {
addopts = 0;
}
result = dns_db_addrdataset(db, node, version,
0, &rdataset,
addopts, NULL);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
print_result("", result);
if (printnode)
}
if (printnode) {
dns_db_printnode(db, node, stdout);
}
} else if (dbi != NULL && delmode && !found_as) {
result = dns_db_deleterdataset(
db, node, version, type, 0);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
print_result("", result);
if (printnode)
}
if (printnode) {
dns_db_printnode(db, node, stdout);
}
}
dns_rdataset_disassociate(&rdataset);
}
@ -895,8 +950,9 @@ main(int argc, char *argv[])
RUNTIME_CHECK(dbi->hold_count < MAXHOLD);
dbi->hold_nodes[dbi->hold_count++] = node;
node = NULL;
} else
} else {
dns_db_detachnode(db, &node);
}
} else {
dns_db_detachnode(db, &node);
dns_db_detach(&db);
@ -919,11 +975,13 @@ main(int argc, char *argv[])
dns_dbtable_detach(&dbtable);
if (lctx != NULL)
if (lctx != NULL) {
isc_log_destroy(&lctx);
}
if (!quiet)
if (!quiet) {
isc_mem_stats(mctx, stdout);
}
return (0);
}

View file

@ -60,8 +60,9 @@ main(void)
printf("fsaccess=%u\n", access);
result = isc_fsaccess_set(PATH, access);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
fprintf(stderr, "result = %s\n", isc_result_totext(result));
}
(void)fclose(fp);
return (0);

View file

@ -158,15 +158,18 @@ recvresponse(isc_task_t *task, isc_event_t *event)
CHECK("dns_request_getresponse", result2);
if (response != NULL)
if (response != NULL) {
dns_message_destroy(&response);
}
end:
if (query != NULL)
if (query != NULL) {
dns_message_destroy(&query);
}
if (reqev->request != NULL)
if (reqev->request != NULL) {
dns_request_destroy(&reqev->request);
}
isc_event_free(&event);
@ -195,8 +198,9 @@ sendquery(isc_task_t *task, isc_event_t *event)
printf("Query => ");
c = scanf("%255s", host);
if (c == EOF)
if (c == EOF) {
return;
}
dns_fixedname_init(&queryname);
isc_buffer_init(&buf, host, strlen(host));
@ -206,20 +210,23 @@ sendquery(isc_task_t *task, isc_event_t *event)
CHECK("dns_name_fromtext", result);
result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &message);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto end;
}
message->opcode = dns_opcode_query;
message->rdclass = dns_rdataclass_in;
message->id = (unsigned short)(random() & 0xFFFF);
result = dns_message_gettempname(message, &qname);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto end;
}
result = dns_message_gettemprdataset(message, &qrdataset);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto end;
}
dns_name_init(qname, NULL);
dns_name_clone(dns_fixedname_name(&queryname), qname);
@ -244,12 +251,15 @@ sendquery(isc_task_t *task, isc_event_t *event)
return;
end:
if (qname != NULL)
if (qname != NULL) {
dns_message_puttempname(message, &qname);
if (qrdataset != NULL)
}
if (qrdataset != NULL) {
dns_message_puttemprdataset(message, &qrdataset);
if (message != NULL)
}
if (message != NULL) {
dns_message_destroy(&message);
}
}
static void
@ -318,11 +328,13 @@ initctx2(isc_task_t *task, isc_event_t *event)
dns_message_destroy(&response);
end:
if (query != NULL)
if (query != NULL) {
dns_message_destroy(&query);
}
if (reqev->request != NULL)
if (reqev->request != NULL) {
dns_request_destroy(&reqev->request);
}
isc_event_free(&event);
@ -347,8 +359,9 @@ initctx1(isc_task_t *task, isc_event_t *event)
printf("Initctx - GSS name => ");
c = scanf("%511s", gssid);
if (c == EOF)
if (c == EOF) {
return;
}
snprintf(contextname, sizeof(contextname), "gsstest.context.%d.",
(int)time(NULL));
@ -514,8 +527,9 @@ main(int argc, char *argv[])
(void)isc_app_run();
if (tsigkey)
if (tsigkey) {
dns_tsigkey_detach(&tsigkey);
}
dns_requestmgr_shutdown(requestmgr);
dns_requestmgr_detach(&requestmgr);
@ -544,7 +558,7 @@ main(int argc, char *argv[])
return (0);
}
#else
#else /* ifdef GSSAPI */
int
main(int argc, char *argv[])
{
@ -553,4 +567,4 @@ main(int argc, char *argv[])
fprintf(stderr, "R:GSSAPIONLY\n");
return (0);
}
#endif
#endif /* ifdef GSSAPI */

View file

@ -33,8 +33,9 @@ main(int argc, char **argv)
isc_mem_create(&mctx);
result = isc_interfaceiter_create(mctx, &iter);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = isc_interfaceiter_first(iter);
while (result == ISC_R_SUCCESS) {
result = isc_interfaceiter_current(iter, &ifdata);
@ -48,12 +49,13 @@ main(int argc, char **argv)
INSIST(ifdata.af == AF_INET || ifdata.af == AF_INET6);
res = inet_ntop(ifdata.af, &ifdata.address.type, buf,
sizeof(buf));
if (ifdata.address.zone != 0)
if (ifdata.address.zone != 0) {
fprintf(stdout, "address = %s (zone %u)\n",
res == NULL ? "BAD" : res, ifdata.address.zone);
else
} else {
fprintf(stdout, "address = %s\n",
res == NULL ? "BAD" : res);
}
INSIST(ifdata.address.family == ifdata.af);
res = inet_ntop(ifdata.af, &ifdata.netmask.type, buf,
sizeof(buf));
@ -79,8 +81,9 @@ main(int argc, char **argv)
fprintf(stdout, "\nPass 2\n\n");
result = isc_interfaceiter_create(mctx, &iter);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
goto cleanup;
}
result = isc_interfaceiter_first(iter);
while (result == ISC_R_SUCCESS) {
result = isc_interfaceiter_current(iter, &ifdata);
@ -94,12 +97,13 @@ main(int argc, char **argv)
INSIST(ifdata.af == AF_INET || ifdata.af == AF_INET6);
res = inet_ntop(ifdata.af, &ifdata.address.type, buf,
sizeof(buf));
if (ifdata.address.zone != 0)
if (ifdata.address.zone != 0) {
fprintf(stdout, "address = %s (zone %u)\n",
res == NULL ? "BAD" : res, ifdata.address.zone);
else
} else {
fprintf(stdout, "address = %s\n",
res == NULL ? "BAD" : res);
}
INSIST(ifdata.address.family == ifdata.af);
res = inet_ntop(ifdata.af, &ifdata.netmask.type, buf,
sizeof(buf));

View file

@ -136,18 +136,22 @@ main(int argc, char *argv[])
isc_lex_getsourceline(lex),
(name == NULL) ? "<none>" : name);
}
if (token.type == isc_tokentype_eof)
if (token.type == isc_tokentype_eof) {
isc_lex_close(lex);
if (token.type == isc_tokentype_nomore)
}
if (token.type == isc_tokentype_nomore) {
done = 1;
}
}
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
printf("Result: %s\n", isc_result_totext(result));
}
isc_lex_close(lex);
isc_lex_destroy(&lex);
if (!quiet && stats)
if (!quiet && stats) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
return (0);

View file

@ -41,10 +41,11 @@ main(int argc, char **argv)
isc_lfsr_init(&lfsr1, 0, 32, 0x80000057U, 0, NULL, NULL);
for (i = 0; i < 32; i++) {
isc_lfsr_generate(&lfsr1, &temp, 4);
if (state[i] != temp)
if (state[i] != temp) {
printf("lfsr1: state[%2d] = %08x, "
"but new state is %08x\n",
i, state[i], temp);
}
}
/*
@ -60,10 +61,11 @@ main(int argc, char **argv)
for (i = 0; i < 32; i++) {
isc_lfsr_generate(&lfsr1, &temp, 4);
isc_lfsr_skip(&lfsr1, 32);
if (state[i] != temp)
if (state[i] != temp) {
printf("lfsr1: state[%2d] = %08x, "
"but new state is %08x\n",
i, state[i], temp);
}
}
/*
@ -79,10 +81,11 @@ main(int argc, char **argv)
isc_lfsr_init(&lfsr2, 0, 16, 0x00008016U, 0, NULL, NULL);
for (i = 0; i < 32; i++) {
isc_lfsr_generate(&lfsr2, &temp, 4);
if (state[i] != temp)
if (state[i] != temp) {
printf("lfsr2: state[%2d] = %08x, "
"but new state is %08x\n",
i, state[i], temp);
}
}
return (0);

View file

@ -49,10 +49,11 @@ main(int argc, char **argv)
const isc_logmodule_t * module;
progname = strrchr(*argv, '/');
if (progname != NULL)
if (progname != NULL) {
progname++;
else
} else {
progname = *argv;
}
syslog_file = SYSLOG_FILE;
file_versions = FILE_VERSIONS;
@ -123,17 +124,19 @@ main(int argc, char **argv)
* Test isc_log_categorybyname and isc_log_modulebyname.
*/
category = isc_log_categorybyname(lctx, "notify");
if (category != NULL)
if (category != NULL) {
fprintf(stderr, "%s category found. (expected)\n",
category->name);
else
} else {
fprintf(stderr, "notify category not found!\n");
}
module = isc_log_modulebyname(lctx, "xyzzy");
if (module != NULL)
if (module != NULL) {
fprintf(stderr, "%s module found!\n", module->name);
else
} else {
fprintf(stderr, "xyzzy module not found. (expected)\n");
}
/*
* Create a file channel to test file opening, size limiting and
@ -233,29 +236,31 @@ main(int argc, char **argv)
* the "should not appear" and "should be in file" messages
* to ensure they get rolled.
*/
if (file_versions <= 0)
if (file_versions <= 0) {
file_versions = FILE_VERSIONS;
else
} else {
isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_DB, ISC_LOG_NOTICE,
"This should be rolled over "
"and not appear!");
}
for (i = file_versions - 1; i >= 0; i--)
for (i = file_versions - 1; i >= 0; i--) {
isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_DB, ISC_LOG_NOTICE,
"should be in file %d/%d", i,
file_versions - 1);
}
isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DB,
ISC_LOG_NOTICE, "should be in base file");
} else {
file_versions = FILE_VERSIONS;
for (i = 1; i <= file_versions; i++)
for (i = 1; i <= file_versions; i++) {
isc_log_write(lctx, DNS_LOGCATEGORY_GENERAL,
DNS_LOGMODULE_DB, ISC_LOG_NOTICE,
"This is message %d in the log file", i);
}
}
/*
@ -330,8 +335,9 @@ main(int argc, char **argv)
cleanup:
isc_log_destroy(&lctx);
if (show_final_mem)
if (show_final_mem) {
isc_mem_stats(mctx, stderr);
}
return (0);
}

View file

@ -36,12 +36,13 @@ print_dataset(void *arg, const dns_name_t *owner, dns_rdataset_t *dataset)
isc_buffer_init(&target, buf, 64 * 1024);
result = dns_rdataset_totext(dataset, owner, false, false, &target);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
fprintf(stdout, "%.*s\n", (int)target.used,
(char *)target.base);
else
} else {
fprintf(stdout, "dns_rdataset_totext: %s\n",
dns_result_totext(result));
}
return (ISC_R_SUCCESS);
}

View file

@ -31,8 +31,9 @@ print_wirename(isc_region_t *name)
}
ccurr = name->base;
cend = ccurr + name->length;
while (ccurr != cend)
while (ccurr != cend) {
printf("%02x ", *ccurr++);
}
printf("\n");
}
@ -45,18 +46,21 @@ print_name(dns_name_t *name)
char s[1000];
isc_buffer_init(&source, s, sizeof(s));
if (dns_name_countlabels(name) > 0)
if (dns_name_countlabels(name) > 0) {
result = dns_name_totext(name, false, &source);
else
} else {
result = ISC_R_SUCCESS;
}
if (result == ISC_R_SUCCESS) {
isc_buffer_usedregion(&source, &r);
if (r.length > 0)
if (r.length > 0) {
printf("%.*s\n", (int)r.length, r.base);
else
} else {
printf("<empty text name>\n");
} else
}
} else {
printf("error: %s\n", dns_result_totext(result));
}
}
int
@ -115,9 +119,9 @@ main(int argc, char *argv[])
argv += isc_commandline_index;
if (argc > 0) {
if (strcasecmp("none", argv[0]) == 0)
if (strcasecmp("none", argv[0]) == 0) {
origin = NULL;
else {
} else {
len = strlen(argv[0]);
isc_buffer_init(&source, argv[0], len);
isc_buffer_add(&source, len);
@ -133,15 +137,16 @@ main(int argc, char *argv[])
}
origin = dns_fixedname_name(&oname);
}
} else if (concatenate)
} else if (concatenate) {
origin = NULL;
else
} else {
origin = dns_rootname;
}
if (argc >= 1) {
if (strcasecmp("none", argv[1]) == 0)
if (strcasecmp("none", argv[1]) == 0) {
comp = NULL;
else {
} else {
len = strlen(argv[1]);
isc_buffer_init(&source, argv[1], len);
isc_buffer_add(&source, len);
@ -155,8 +160,9 @@ main(int argc, char *argv[])
exit(1);
}
}
} else
} else {
comp = NULL;
}
name = dns_fixedname_initname(&wname);
dns_fixedname_init(&wname2);
@ -169,37 +175,41 @@ main(int argc, char *argv[])
isc_buffer_init(&source, s, len);
isc_buffer_add(&source, len);
if (len > 0U)
if (len > 0U) {
result = dns_name_fromtext(name, &source, origin,
downcase, NULL);
else {
if (name == dns_fixedname_name(&wname))
} else {
if (name == dns_fixedname_name(&wname)) {
dns_fixedname_init(&wname);
else
} else {
dns_fixedname_init(&wname2);
}
result = ISC_R_SUCCESS;
}
if (result != ISC_R_SUCCESS) {
printf("%s\n", dns_result_totext(result));
if (name == dns_fixedname_name(&wname))
if (name == dns_fixedname_name(&wname)) {
dns_fixedname_init(&wname);
else
} else {
dns_fixedname_init(&wname2);
}
continue;
}
if (check_absolute && dns_name_countlabels(name) > 0) {
if (dns_name_isabsolute(name))
if (dns_name_isabsolute(name)) {
printf("absolute\n");
else
} else {
printf("relative\n");
}
}
if (check_wildcard && dns_name_countlabels(name) > 0) {
if (dns_name_iswildcard(name))
if (dns_name_iswildcard(name)) {
printf("wildcard\n");
else
} else {
printf("not wildcard\n");
}
}
dns_name_toregion(name, &r);
if (!quiet) {
@ -219,18 +229,20 @@ main(int argc, char *argv[])
if (result == ISC_R_SUCCESS) {
if (check_absolute &&
dns_name_countlabels(name) > 0) {
if (dns_name_isabsolute(name))
if (dns_name_isabsolute(name)) {
printf("absolute\n");
else
} else {
printf("relative\n");
}
}
if (check_wildcard &&
dns_name_countlabels(name) > 0) {
if (dns_name_iswildcard(name))
if (dns_name_iswildcard(name)) {
printf("wildcard\n");
else
} else {
printf("not "
"wildcard\n");
}
}
dns_name_toregion(name, &r);
if (!quiet) {
@ -241,29 +253,34 @@ main(int argc, char *argv[])
name),
r.length);
}
} else
} else {
printf("%s\n",
dns_result_totext(result));
}
got_name = false;
} else
} else {
got_name = true;
}
}
isc_buffer_init(&source, s, sizeof(s));
if (dns_name_countlabels(name) > 0)
if (dns_name_countlabels(name) > 0) {
result = dns_name_totext(name, false, &source);
else
} else {
result = ISC_R_SUCCESS;
}
if (result == ISC_R_SUCCESS) {
isc_buffer_usedregion(&source, &r);
if (r.length > 0)
if (r.length > 0) {
printf("%.*s\n", (int)r.length, r.base);
else
} else {
printf("<empty text name>\n");
}
if (!quiet) {
printf("%u bytes.\n", source.used);
}
} else
} else {
printf("%s\n", dns_result_totext(result));
}
if (test_downcase) {
if (inplace) {
@ -291,12 +308,13 @@ main(int argc, char *argv[])
namereln = dns_name_fullcompare(name, comp, &order,
&nlabels);
if (!quiet) {
if (order < 0)
if (order < 0) {
printf("<");
else if (order > 0)
} else if (order > 0) {
printf(">");
else
} else {
printf("=");
}
switch (namereln) {
case dns_namereln_contains:
printf(", contains");
@ -311,8 +329,9 @@ main(int argc, char *argv[])
break;
}
if (namereln != dns_namereln_none &&
namereln != dns_namereln_equal)
namereln != dns_namereln_equal) {
printf(", nlabels = %u", nlabels);
}
printf("\n");
}
printf("dns_name_equal() returns %s\n",
@ -332,10 +351,11 @@ main(int argc, char *argv[])
}
if (concatenate) {
if (got_name)
if (got_name) {
name = dns_fixedname_name(&wname2);
else
} else {
name = dns_fixedname_name(&wname);
}
}
}

View file

@ -60,16 +60,19 @@ active_node(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node)
result = dns_rdatasetiter_first(rdsiter);
while (result == ISC_R_SUCCESS) {
dns_rdatasetiter_current(rdsiter, &rdataset);
if (rdataset.type != dns_rdatatype_nsec)
if (rdataset.type != dns_rdatatype_nsec) {
active = true;
}
dns_rdataset_disassociate(&rdataset);
if (!active)
if (!active) {
result = dns_rdatasetiter_next(rdsiter);
else
} else {
result = ISC_R_NOMORE;
}
}
if (result != ISC_R_NOMORE)
if (result != ISC_R_NOMORE) {
fatal("rdataset iteration failed");
}
dns_rdatasetiter_destroy(&rdsiter);
if (!active) {
@ -78,8 +81,9 @@ active_node(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node)
*/
result = dns_db_deleterdataset(db, node, version,
dns_rdatatype_nsec, 0);
if (result == DNS_R_UNCHANGED)
if (result == DNS_R_UNCHANGED) {
result = ISC_R_SUCCESS;
}
check_result(result, "dns_db_deleterdataset");
}
@ -127,10 +131,11 @@ nsecify(char *filename)
nextname = dns_fixedname_initname(&fnextname);
origintext = strrchr(filename, '/');
if (origintext == NULL)
if (origintext == NULL) {
origintext = filename;
else
} else {
origintext++; /* Skip '/'. */
}
len = strlen(origintext);
isc_buffer_constinit(&b, origintext, len);
isc_buffer_add(&b, len);
@ -142,8 +147,9 @@ nsecify(char *filename)
dns_rdataclass_in, 0, NULL, &db);
check_result(result, "dns_db_create()");
result = dns_db_load(db, filename, dns_masterformat_text, 0);
if (result == DNS_R_SEENINCLUDE)
if (result == DNS_R_SEENINCLUDE) {
result = ISC_R_SUCCESS;
}
check_result(result, "dns_db_load()");
wversion = NULL;
result = dns_db_newversion(db, &wversion);
@ -158,14 +164,15 @@ nsecify(char *filename)
while (result == ISC_R_SUCCESS) {
nextnode = NULL;
result = dns_dbiterator_next(dbiter);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
result = next_active(db, wversion, dbiter, nextname,
&nextnode);
if (result == ISC_R_SUCCESS)
}
if (result == ISC_R_SUCCESS) {
target = nextname;
else if (result == ISC_R_NOMORE)
} else if (result == ISC_R_NOMORE) {
target = dns_db_origin(db);
else {
} else {
target = NULL; /* Make compiler happy. */
fatal("db iteration failed");
}
@ -173,16 +180,18 @@ nsecify(char *filename)
dns_db_detachnode(db, &node);
node = nextnode;
}
if (result != ISC_R_NOMORE)
if (result != ISC_R_NOMORE) {
fatal("db iteration failed");
}
dns_dbiterator_destroy(&dbiter);
/*
* XXXRTH For now, we don't increment the SOA serial.
*/
dns_db_closeversion(db, &wversion, true);
len = strlen(filename);
if (len + 4 + 1 > sizeof(newfilename))
if (len + 4 + 1 > sizeof(newfilename)) {
fatal("filename too long");
}
snprintf(newfilename, sizeof(newfilename), "%s.new", filename);
result = dns_db_dump(db, NULL, newfilename);
check_result(result, "dns_db_dump");
@ -201,8 +210,9 @@ main(int argc, char *argv[])
argc--;
argv++;
for (i = 0; i < argc; i++)
for (i = 0; i < argc; i++) {
nsecify(argv[i]);
}
/* isc_mem_stats(mctx, stdout); */
isc_mem_destroy(&mctx);

View file

@ -141,8 +141,9 @@ detail(dns_rbt_t *rbt, dns_name_t *name)
if (node1 != NULL && node1->data != NULL) {
printf(" data at node: ");
print_name(node1->data);
} else
} else {
printf(" no data at node.");
}
if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) {
printf("\n name from dns_rbt_findnode: ");
@ -156,22 +157,24 @@ detail(dns_rbt_t *rbt, dns_name_t *name)
result =
dns_name_concatenate(foundname, origin, fullname, NULL);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
print_name(fullname);
else
} else {
printf("%s\n", dns_result_totext(result));
}
printf("\n (foundname = ");
print_name(foundname);
printf(", origin = ");
print_name(origin);
printf(")\n");
if (nodes_should_match && node1 != node2)
if (nodes_should_match && node1 != node2) {
printf(" nodes returned from each function "
"DO NOT match!\n");
} else
}
} else {
printf("\n result from dns_rbtnodechain_current: %s\n",
dns_result_totext(result));
}
printf(" level_matches = %u, level_count = %u\n", chain.level_matches,
chain.level_count);
@ -198,7 +201,6 @@ iterate(dns_rbt_t *rbt, bool forward)
result =
dns_rbtnodechain_first(&chain, rbt, &foundname, origin);
} else {
printf("iterating backward\n");
move = dns_rbtnodechain_prev;
@ -206,10 +208,9 @@ iterate(dns_rbt_t *rbt, bool forward)
result = dns_rbtnodechain_last(&chain, rbt, &foundname, origin);
}
if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN)
if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) {
printf("start not found!\n");
else {
} else {
for (;;) {
if (result == DNS_R_NEWORIGIN) {
printf(" new origin: ");
@ -221,11 +222,11 @@ iterate(dns_rbt_t *rbt, bool forward)
result == DNS_R_NEWORIGIN) {
print_name(&foundname);
printf("\n");
} else {
if (result != ISC_R_NOMORE)
if (result != ISC_R_NOMORE) {
printf("UNEXEPCTED ITERATION ERROR: %s",
dns_result_totext(result));
}
break;
}
@ -253,10 +254,11 @@ main(int argc, char **argv)
void * data;
progname = strrchr(*argv, '/');
if (progname != NULL)
if (progname != NULL) {
progname++;
else
} else {
progname = *argv;
}
while ((ch = isc_commandline_parse(argc, argv, "m")) != -1) {
switch (ch) {
@ -306,8 +308,9 @@ main(int argc, char **argv)
command = buffer + strspn(buffer, whitespace);
if (*command == '#')
if (*command == '#') {
continue;
}
arg = strpbrk(command, whitespace);
if (arg != NULL) {
@ -325,7 +328,6 @@ main(int argc, char **argv)
name);
PRINTERR(result);
}
} else if (CMDCHECK("delete")) {
name = create_name(arg);
if (name != NULL) {
@ -335,7 +337,6 @@ main(int argc, char **argv)
PRINTERR(result);
delete_name(name, NULL);
}
} else if (CMDCHECK("nuke")) {
name = create_name(arg);
if (name != NULL) {
@ -347,7 +348,6 @@ main(int argc, char **argv)
PRINTERR(result);
delete_name(name, NULL);
}
} else if (CMDCHECK("search")) {
name = create_name(arg);
if (name != NULL) {
@ -385,7 +385,6 @@ main(int argc, char **argv)
delete_name(name, NULL);
}
} else if (CMDCHECK("check")) {
/*
* Or "chain". I know, I know. Lame name.
@ -403,24 +402,22 @@ main(int argc, char **argv)
delete_name(name, NULL);
}
} else if (CMDCHECK("forward")) {
iterate(rbt, true);
} else if (CMDCHECK("backward")) {
iterate(rbt, false);
} else if (CMDCHECK("print")) {
if (arg == NULL || *arg == '\0')
if (arg == NULL || *arg == '\0') {
dns_rbt_printtext(rbt, NULL, stdout);
else
} else {
printf("usage: print\n");
}
} else if (CMDCHECK("quit")) {
if (arg == NULL || *arg == '\0')
if (arg == NULL || *arg == '\0') {
break;
else
} else {
printf("usage: quit\n");
}
} else {
printf("a(dd) NAME, d(elete) NAME, "
"s(earch) NAME, p(rint), or q(uit)\n");
@ -430,8 +427,9 @@ main(int argc, char **argv)
dns_rbt_destroy(&rbt);
if (show_final_mem)
if (show_final_mem) {
isc_mem_stats(mctx, stderr);
}
return (0);
}

View file

@ -21,14 +21,14 @@
#ifdef WIN32
#define sleep(x) Sleep(1000 * x)
#endif
#endif /* ifdef WIN32 */
isc_rwlock_t lock;
static isc_threadresult_t
#ifdef WIN32
WINAPI
#endif
#endif /* ifdef WIN32 */
run1(void *arg)
{
char *message = arg;
@ -60,7 +60,7 @@ static isc_threadresult_t
static isc_threadresult_t
#ifdef WIN32
WINAPI
#endif
#endif /* ifdef WIN32 */
run2(void *arg)
{
char *message = arg;
@ -98,12 +98,14 @@ main(int argc, char *argv[])
char name[100];
void * dupname;
if (argc > 1)
if (argc > 1) {
nworkers = atoi(argv[1]);
else
} else {
nworkers = 2;
if (nworkers > 100)
}
if (nworkers > 100) {
nworkers = 100;
}
printf("%u workers\n", nworkers);
RUNTIME_CHECK(isc_rwlock_init(&lock, 5, 10) == ISC_R_SUCCESS);

View file

@ -27,12 +27,14 @@ main()
buf[sizeof(buf) - 1] = '\0';
s = buf;
a = strtoul(s, &e, 0);
if (s == e)
if (s == e) {
continue;
}
s = e;
b = strtoul(s, &e, 0);
if (s == e)
if (s == e) {
continue;
}
fprintf(stdout, "%u %u gt:%d lt:%d ge:%d le:%d eq:%d ne:%d\n",
a, b, isc_serial_gt(a, b), isc_serial_lt(a, b),
isc_serial_ge(a, b), isc_serial_le(a, b),

View file

@ -172,12 +172,15 @@ main(int argc, char *argv[])
if (argc > 1) {
workers = atoi(argv[1]);
if (workers < 1)
if (workers < 1) {
workers = 1;
if (workers > 8192)
}
if (workers > 8192) {
workers = 8192;
} else
}
} else {
workers = 2;
}
printf("%u workers\n", workers);
mctx = NULL;

View file

@ -279,8 +279,9 @@ main(int argc, char *argv[])
isc_log_destroy(&lctx);
if (verbose)
if (verbose) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
isc_mutex_destroy(&lock);

View file

@ -53,8 +53,9 @@ my_send(isc_task_t *task, isc_event_t *event)
isc_task_shutdown(task);
}
if (dev->region.base != NULL)
if (dev->region.base != NULL) {
isc_mem_put(mctx, dev->region.base, dev->region.length);
}
isc_event_free(&event);
}
@ -89,8 +90,9 @@ my_recv(isc_task_t *task, isc_event_t *event)
if (dev->result != ISC_R_SUCCESS) {
isc_socket_detach(&sock);
if (dev->region.base != NULL)
if (dev->region.base != NULL) {
isc_mem_put(mctx, dev->region.base, dev->region.length);
}
isc_event_free(&event);
isc_task_shutdown(task);
@ -138,8 +140,9 @@ my_http_get(isc_task_t *task, isc_event_t *event)
if (dev->result != ISC_R_SUCCESS) {
isc_socket_detach(&sock);
isc_task_shutdown(task);
if (dev->region.base != NULL)
if (dev->region.base != NULL) {
isc_mem_put(mctx, dev->region.base, dev->region.length);
}
isc_event_free(&event);
return;
}
@ -274,18 +277,22 @@ main(int argc, char *argv[])
if (argc > 1) {
workers = atoi(argv[1]);
if (workers < 1)
if (workers < 1) {
workers = 1;
if (workers > 8192)
}
if (workers > 8192) {
workers = 8192;
} else
}
} else {
workers = 2;
}
printf("%u workers\n", workers);
if (isc_net_probeipv6() == ISC_R_SUCCESS)
if (isc_net_probeipv6() == ISC_R_SUCCESS) {
pf = PF_INET6;
else
} else {
pf = PF_INET;
}
/*
* EVERYTHING needs a memory context.
@ -357,10 +364,11 @@ main(int argc, char *argv[])
*/
so2 = NULL;
ina.s_addr = inet_addr("204.152.184.97");
if (0 && pf == PF_INET6)
if (0 && pf == PF_INET6) {
isc_sockaddr_v6fromin(&sockaddr, &ina, 80);
else
} else {
isc_sockaddr_fromin(&sockaddr, &ina, 80);
}
RUNTIME_CHECK(isc_socket_create(socketmgr, isc_sockaddr_pf(&sockaddr),
isc_sockettype_tcp,
&so2) == ISC_R_SUCCESS);
@ -380,9 +388,9 @@ main(int argc, char *argv[])
*/
#ifndef WIN32
sleep(10);
#else
#else /* ifndef WIN32 */
Sleep(10000);
#endif
#endif /* ifndef WIN32 */
fprintf(stderr, "Destroying socket manager\n");
isc_socketmgr_destroy(&socketmgr);

View file

@ -76,13 +76,15 @@ main(int argc, char *argv[])
if (cp[0] == '!') {
cp++;
result = isc_symtab_undefine(st, cp, 1);
if (trace || result != ISC_R_SUCCESS)
if (trace || result != ISC_R_SUCCESS) {
printf("undefine('%s'): %s\n", cp,
isc_result_totext(result));
}
} else {
key = cp;
while (*cp != '\0' && *cp != ' ' && *cp != '\t')
while (*cp != '\0' && *cp != ' ' && *cp != '\t') {
cp++;
}
if (*cp == '\0') {
result = isc_symtab_lookup(st, key, 0, &value);
if (trace || result != ISC_R_SUCCESS) {
@ -103,9 +105,10 @@ main(int argc, char *argv[])
if (trace || result != ISC_R_SUCCESS) {
printf("define('%s', '%s'): %s\n", key,
cp, isc_result_totext(result));
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
undefine_action(key, 1, value,
NULL);
}
}
}
}

View file

@ -28,8 +28,9 @@ my_callback(isc_task_t *task, isc_event_t *event)
char *name = event->ev_arg;
j = 0;
for (i = 0; i < 1000000; i++)
for (i = 0; i < 1000000; i++) {
j += 100;
}
printf("task %s (%p): %d\n", name, task, j);
isc_event_free(&event);
}
@ -73,12 +74,15 @@ main(int argc, char *argv[])
if (argc > 1) {
workers = atoi(argv[1]);
if (workers < 1)
if (workers < 1) {
workers = 1;
if (workers > 8192)
}
if (workers > 8192) {
workers = 8192;
} else
}
} else {
workers = 2;
}
printf("%u workers\n", workers);
isc_mem_create(&mctx);
@ -119,9 +123,9 @@ main(int argc, char *argv[])
printf("task 2 = %p\n", t2);
#ifndef WIN32
sleep(2);
#else
#else /* ifndef WIN32 */
Sleep(2000);
#endif
#endif /* ifndef WIN32 */
/*
* Note: (void *)1 is used as a sender here, since some compilers
@ -186,9 +190,9 @@ main(int argc, char *argv[])
#ifndef WIN32
sleep(10);
#else
#else /* ifndef WIN32 */
Sleep(10000);
#endif
#endif /* ifndef WIN32 */
printf("destroy\n");
isc_timer_detach(&ti1);
isc_timer_detach(&ti2);

View file

@ -44,8 +44,9 @@ tick(isc_task_t *task, isc_event_t *event)
printf("task %s (%p) tick\n", name, task);
tick_count++;
if (ti3 != NULL && tick_count % 3 == 0)
if (ti3 != NULL && tick_count % 3 == 0) {
isc_timer_touch(ti3);
}
if (ti3 != NULL && tick_count == 7) {
isc_time_t expires;
@ -72,10 +73,11 @@ timeout(isc_task_t *task, isc_event_t *event)
INSIST(event->ev_type == ISC_TIMEREVENT_IDLE ||
event->ev_type == ISC_TIMEREVENT_LIFE);
if (event->ev_type == ISC_TIMEREVENT_IDLE)
if (event->ev_type == ISC_TIMEREVENT_IDLE) {
type = "idle";
else
} else {
type = "life";
}
printf("task %s (%p) %s timeout\n", name, task, type);
if (strcmp(name, "3") == 0) {
@ -103,12 +105,15 @@ main(int argc, char *argv[])
if (argc > 1) {
workers = atoi(argv[1]);
if (workers < 1)
if (workers < 1) {
workers = 1;
if (workers > 8192)
}
if (workers > 8192) {
workers = 8192;
} else
}
} else {
workers = 2;
}
printf("%u workers\n", workers);
isc_mem_create(&mctx1);
@ -155,18 +160,18 @@ main(int argc, char *argv[])
#ifndef WIN32
sleep(15);
#else
#else /* ifndef WIN32 */
Sleep(15000);
#endif
#endif /* ifndef WIN32 */
printf("destroy\n");
isc_timer_detach(&ti1);
isc_timer_detach(&ti2);
isc_timer_detach(&ti3);
#ifndef WIN32
sleep(2);
#else
#else /* ifndef WIN32 */
Sleep(2000);
#endif
#endif /* ifndef WIN32 */
isc_timermgr_destroy(&timgr);
isc_taskmgr_destroy(&manager);
printf("destroyed\n");

View file

@ -82,9 +82,10 @@ setup(const char *zonename, const char *filename, const char *classname)
dns_name_t * origin;
const char * rbt = "rbt";
if (debug)
if (debug) {
fprintf(stderr, "loading \"%s\" from \"%s\" class \"%s\"\n",
zonename, filename, classname);
}
result = dns_zone_create(&zone, mctx);
ERRRET(result, "dns_zone_new");
@ -115,8 +116,9 @@ setup(const char *zonename, const char *filename, const char *classname)
dns_zone_setclass(zone, rdclass);
if (zonetype == dns_zone_slave)
if (zonetype == dns_zone_slave) {
dns_zone_setmasters(zone, &addr, 1);
}
result = dns_zone_load(zone, false);
ERRRET(result, "dns_zone_load");
@ -136,10 +138,11 @@ print_rdataset(dns_name_t *name, dns_rdataset_t *rdataset)
isc_buffer_init(&text, t, sizeof(t));
result = dns_rdataset_totext(rdataset, name, false, false, &text);
isc_buffer_usedregion(&text, &r);
if (result == ISC_R_SUCCESS)
if (result == ISC_R_SUCCESS) {
printf("%.*s", (int)r.length, (char *)r.base);
else
} else {
printf("%s\n", dns_result_totext(result));
}
}
static void
@ -181,19 +184,22 @@ query(void)
buf[sizeof(buf) - 1] = '\0';
s = strchr(buf, '\n');
if (s != NULL)
if (s != NULL) {
*s = '\0';
}
s = strchr(buf, '\r');
if (s != NULL)
if (s != NULL) {
*s = '\0';
}
if (strcmp(buf, "dump") == 0) {
dns_zone_dumptostream(zone, stdout,
dns_masterformat_text,
&dns_master_style_default, 0);
continue;
}
if (strlen(buf) == 0U)
if (strlen(buf) == 0U) {
continue;
}
dns_fixedname_init(&name);
isc_buffer_init(&buffer, buf, strlen(buf));
isc_buffer_add(&buffer, strlen(buf));
@ -219,10 +225,12 @@ query(void)
break;
}
if (dns_rdataset_isassociated(&rdataset))
if (dns_rdataset_isassociated(&rdataset)) {
dns_rdataset_disassociate(&rdataset);
if (dns_rdataset_isassociated(&sigset))
}
if (dns_rdataset_isassociated(&sigset)) {
dns_rdataset_disassociate(&sigset);
}
} while (1);
dns_rdataset_invalidate(&rdataset);
dns_db_detach(&db);
@ -244,8 +252,9 @@ main(int argc, char **argv)
debug++;
break;
case 'f':
if (filename != NULL)
if (filename != NULL) {
usage();
}
filename = isc_commandline_argument;
break;
case 'm':
@ -276,8 +285,9 @@ main(int argc, char **argv)
}
}
if (argv[isc_commandline_index] == NULL)
if (argv[isc_commandline_index] == NULL) {
usage();
}
RUNTIME_CHECK(isc_app_start() == ISC_R_SUCCESS);
isc_mem_create(&mctx);
@ -287,19 +297,22 @@ main(int argc, char **argv)
RUNTIME_CHECK(isc_socketmgr_create(mctx, &socketmgr) == ISC_R_SUCCESS);
RUNTIME_CHECK(dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&zonemgr) == ISC_R_SUCCESS);
if (filename == NULL)
if (filename == NULL) {
filename = argv[isc_commandline_index];
}
setup(argv[isc_commandline_index], filename, classname);
query();
if (zone != NULL)
if (zone != NULL) {
dns_zone_detach(&zone);
}
dns_zonemgr_shutdown(zonemgr);
dns_zonemgr_detach(&zonemgr);
isc_socketmgr_destroy(&socketmgr);
isc_taskmgr_destroy(&taskmgr);
isc_timermgr_destroy(&timermgr);
if (!quiet && stats)
if (!quiet && stats) {
isc_mem_stats(mctx, stdout);
}
isc_mem_destroy(&mctx);
return (0);

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE buf[1024];
char label[16];
@ -164,11 +164,13 @@ main(int argc, char *argv[])
hKey[i] = CK_INVALID_HANDLE;
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL)
if (pin == NULL) {
pin = getpass("Enter Pin: ");
}
result = pk11_get_session(&pctx, OP_ANY, true, true, true,
(const char *)pin, slot);
@ -180,8 +182,9 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
@ -192,8 +195,9 @@ main(int argc, char *argv[])
goto exit_objects;
}
if (ontoken)
if (ontoken) {
kTemplate[1].pValue = &truevalue;
}
if (clock_gettime(CLOCK_REALTIME, &starttime) < 0) {
perror("clock_gettime(start)");
@ -208,8 +212,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_CreateObject[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_objects;
}
break;
}
}
@ -227,17 +232,19 @@ main(int argc, char *argv[])
}
printf("%u created objects in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g created objects/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_objects:
for (i = 0; i < count; i++) {
/* Destroy objects */
if (hKey[i] == CK_INVALID_HANDLE)
if (hKey[i] == CK_INVALID_HANDLE) {
continue;
}
rv = pkcs_C_DestroyObject(hSession, hKey[i]);
if ((rv != CKR_OK) && !errflg) {
fprintf(stderr,

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE label[] = "foo??bar!!";
@ -144,8 +144,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -161,8 +162,9 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
@ -212,11 +214,12 @@ main(int argc, char *argv[])
}
printf("%u object searches in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g object searches/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_objects:
pk11_return_session(&pctx);

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
static CK_BBOOL truevalue = TRUE;
static CK_BBOOL falsevalue = FALSE;
@ -189,8 +189,9 @@ main(int argc, char *argv[])
}
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -206,8 +207,9 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
@ -230,8 +232,9 @@ main(int argc, char *argv[])
"C_GenerateKeyPair[%u]: Error = 0x%.8lX\n", i,
rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_keys;
}
break;
}
}
@ -249,17 +252,19 @@ main(int argc, char *argv[])
}
printf("%u generated RSA in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g generated RSA/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_keys:
for (i = 0; i < count; i++) {
/* Destroy keys */
if (pubKey[i] == CK_INVALID_HANDLE)
if (pubKey[i] == CK_INVALID_HANDLE) {
goto destroy_priv;
}
rv = pkcs_C_DestroyObject(hSession, pubKey[i]);
if ((rv != CKR_OK) && !errflg) {
fprintf(stderr,
@ -268,8 +273,9 @@ exit_keys:
errflg = 1;
}
destroy_priv:
if (privKey[i] == CK_INVALID_HANDLE)
if (privKey[i] == CK_INVALID_HANDLE) {
continue;
}
rv = pkcs_C_DestroyObject(hSession, privKey[i]);
if ((rv != CKR_OK) && !errflg) {
fprintf(stderr,

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
int
main(int argc, char *argv[])
@ -141,8 +141,9 @@ main(int argc, char *argv[])
hSession[i] = CK_INVALID_HANDLE;
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = (CK_UTF8CHAR *)getpass("Enter Pin: ");
@ -150,11 +151,12 @@ main(int argc, char *argv[])
rv = pkcs_C_Initialize(NULL_PTR);
if (rv != CKR_OK) {
if (rv == 0xfe)
if (rv == 0xfe) {
fprintf(stderr, "Can't load or link module \"%s\"\n",
pk11_get_lib_name());
else
} else {
fprintf(stderr, "C_Initialize: Error = 0x%.8lX\n", rv);
}
free(hSession);
exit(1);
}
@ -173,8 +175,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_OpenSession[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_program;
}
break;
}
@ -185,8 +188,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_Login[%u]: Error = 0x%.8lX\n", i,
rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_program;
}
break;
}
@ -196,8 +200,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_Logout[%u]: Error = 0x%.8lX\n", i,
rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_program;
}
break;
}
}
@ -214,14 +219,16 @@ main(int argc, char *argv[])
endtime.tv_nsec += 1000000000;
}
printf("%u logins in %ld.%09lds\n", i, endtime.tv_sec, endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g logins/s\n",
i / ((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
for (j = 0; j < i; j++) {
if (hSession[j] == CK_INVALID_HANDLE)
if (hSession[j] == CK_INVALID_HANDLE) {
continue;
}
/* Close sessions */
rv = pkcs_C_CloseSession(hSession[j]);
if ((rv != CKR_OK) && !errflg) {
@ -235,8 +242,9 @@ exit_program:
free(hSession);
rv = pkcs_C_Finalize(NULL_PTR);
if (rv != CKR_OK)
if (rv != CKR_OK) {
fprintf(stderr, "C_Finalize: Error = 0x%.8lX\n", rv);
}
exit(error);
}

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE modulus[] = {
0x00, 0xb7, 0x9c, 0x1f, 0x05, 0xa3, 0xc2, 0x99, 0x44, 0x82, 0x20, 0x78,
@ -237,8 +237,9 @@ main(int argc, char *argv[])
hKey[i] = CK_INVALID_HANDLE;
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -255,13 +256,15 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
if (ontoken)
if (ontoken) {
kTemplate[2].pValue = &truevalue;
}
if (clock_gettime(CLOCK_REALTIME, &starttime) < 0) {
perror("clock_gettime(start)");
@ -276,8 +279,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_CreateObject[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_objects;
}
break;
}
}
@ -295,17 +299,19 @@ main(int argc, char *argv[])
}
printf("%u private RSA keys in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g private RSA keys/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_objects:
for (i = 0; i < count; i++) {
/* Destroy objects */
if (hKey[i] == CK_INVALID_HANDLE)
if (hKey[i] == CK_INVALID_HANDLE) {
continue;
}
rv = pkcs_C_DestroyObject(hSession, hKey[i]);
if ((rv != CKR_OK) && !errflg) {
fprintf(stderr,

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE modulus[] = {
0x00, 0xb7, 0x9c, 0x1f, 0x05, 0xa3, 0xc2, 0x99, 0x44, 0x82, 0x20, 0x78,
@ -183,8 +183,9 @@ main(int argc, char *argv[])
hKey[i] = CK_INVALID_HANDLE;
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -201,13 +202,15 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
if (ontoken)
if (ontoken) {
kTemplate[2].pValue = &truevalue;
}
if (clock_gettime(CLOCK_REALTIME, &starttime) < 0) {
perror("clock_gettime(start)");
@ -222,8 +225,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_CreateObject[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_objects;
}
break;
}
}
@ -241,17 +245,19 @@ main(int argc, char *argv[])
}
printf("%u public RSA keys in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g public RSA keys/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_objects:
for (i = 0; i < count; i++) {
/* Destroy objects */
if (hKey[i] == CK_INVALID_HANDLE)
if (hKey[i] == CK_INVALID_HANDLE) {
continue;
}
rv = pkcs_C_DestroyObject(hSession, hKey[i]);
if ((rv != CKR_OK) && !errflg) {
fprintf(stderr,

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
int
main(int argc, char *argv[])
@ -136,16 +136,18 @@ main(int argc, char *argv[])
hSession[i] = CK_INVALID_HANDLE;
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
rv = pkcs_C_Initialize(NULL_PTR);
if (rv != CKR_OK) {
if (rv == 0xfe)
if (rv == 0xfe) {
fprintf(stderr, "Can't load or link module \"%s\"\n",
pk11_get_lib_name());
else
} else {
fprintf(stderr, "C_Initialize: Error = 0x%.8lX\n", rv);
}
free(hSession);
exit(1);
}
@ -164,8 +166,9 @@ main(int argc, char *argv[])
fprintf(stderr, "C_OpenSession[%u]: Error = 0x%.8lX\n",
i, rv);
error = 1;
if (i == 0)
if (i == 0) {
goto exit_program;
}
break;
}
}
@ -183,15 +186,17 @@ main(int argc, char *argv[])
}
printf("%u sessions in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g sessions/s\n",
i / ((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
for (i = 0; i < count; i++) {
/* Close sessions */
if (hSession[i] == CK_INVALID_HANDLE)
if (hSession[i] == CK_INVALID_HANDLE) {
continue;
}
rv = pkcs_C_CloseSession(hSession[i]);
if ((rv != CKR_OK) && !errflg) {
fprintf(stderr, "C_CloseSession[%u]: Error = 0x%.8lX\n",
@ -204,8 +209,9 @@ exit_program:
free(hSession);
rv = pkcs_C_Finalize(NULL_PTR);
if (rv != CKR_OK)
if (rv != CKR_OK) {
fprintf(stderr, "C_Finalize: Error = 0x%.8lX\n", rv);
}
exit(error);
}

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE buf[1024];
@ -136,8 +136,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
result = pk11_get_session(&pctx, op_type, false, false, false, NULL,
slot);
@ -183,8 +184,9 @@ main(int argc, char *argv[])
/* Finalize Digest (unconditionally) */
len = 20U;
rv = pkcs_C_DigestFinal(hSession, buf, &len);
if ((rv != CKR_OK) && !error)
if ((rv != CKR_OK) && !error) {
fprintf(stderr, "C_DigestFinal: Error = 0x%.8lX\n", rv);
}
if (clock_gettime(CLOCK_REALTIME, &endtime) < 0) {
perror("clock_gettime(end)");
@ -199,11 +201,12 @@ main(int argc, char *argv[])
}
printf("%uK digested bytes in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g digested bytes/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_session:
pk11_return_session(&pctx);

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE modulus[] = {
0x00, 0xb7, 0x9c, 0x1f, 0x05, 0xa3, 0xc2, 0x99, 0x44, 0x82, 0x20, 0x78,
@ -231,8 +231,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -248,14 +249,16 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
/* Create the private RSA key */
if (ontoken)
if (ontoken) {
kTemplate[2].pValue = &truevalue;
}
rv = pkcs_C_CreateObject(hSession, kTemplate, 13, &hKey);
if (rv != CKR_OK) {
@ -309,18 +312,20 @@ main(int argc, char *argv[])
}
printf("%u RSA signs in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g RSA signs/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_key:
if (hKey != CK_INVALID_HANDLE) {
rv = pkcs_C_DestroyObject(hSession, hKey);
if (rv != CKR_OK)
if (rv != CKR_OK) {
fprintf(stderr, "C_DestroyObject: Error = 0x%.8lX\n",
rv);
}
}
pk11_return_session(&pctx);

View file

@ -59,7 +59,7 @@
#ifndef CLOCK_REALTIME
#define CLOCK_REALTIME 0
#endif
#endif /* ifndef CLOCK_REALTIME */
static int
clock_gettime(int32_t id, struct timespec *tp);
@ -79,7 +79,7 @@ clock_gettime(int32_t id, struct timespec *tp)
}
return (result);
}
#endif
#endif /* ifndef HAVE_CLOCK_GETTIME */
CK_BYTE modulus[] = {
0x00, 0xb7, 0x9c, 0x1f, 0x05, 0xa3, 0xc2, 0x99, 0x44, 0x82, 0x20, 0x78,
@ -177,8 +177,9 @@ main(int argc, char *argv[])
pk11_result_register();
/* Initialize the CRYPTOKI library */
if (lib_name != NULL)
if (lib_name != NULL) {
pk11_set_lib_name(lib_name);
}
if (pin == NULL) {
pin = getpass("Enter Pin: ");
@ -194,14 +195,16 @@ main(int argc, char *argv[])
exit(1);
}
if (pin != NULL)
if (pin != NULL) {
memset(pin, 0, strlen((char *)pin));
}
hSession = pctx.session;
/* Create the private RSA key */
if (ontoken)
if (ontoken) {
kTemplate[2].pValue = &truevalue;
}
rv = pkcs_C_CreateObject(hSession, kTemplate, 7, &hKey);
if (rv != CKR_OK) {
@ -257,11 +260,12 @@ main(int argc, char *argv[])
}
printf("%u RSA verify in %ld.%09lds\n", i, endtime.tv_sec,
endtime.tv_nsec);
if (i > 0)
if (i > 0) {
printf("%g RSA verify/s\n",
1024 * i /
((double)endtime.tv_sec +
(double)endtime.tv_nsec / 1000000000.));
}
exit_key:
if (hKey != CK_INVALID_HANDLE) {

View file

@ -109,12 +109,15 @@ add_name(struct dlz_example_data *state, struct record *list, const char *name,
if (first_empty == -1 && strlen(list[i].name) == 0U) {
first_empty = i;
}
if (strcasecmp(list[i].name, name) != 0)
if (strcasecmp(list[i].name, name) != 0) {
continue;
if (strcasecmp(list[i].type, type) != 0)
}
if (strcasecmp(list[i].type, type) != 0) {
continue;
if (!single && strcasecmp(list[i].data, data) != 0)
}
if (!single && strcasecmp(list[i].data, data) != 0) {
continue;
}
break;
}
if (i == MAX_RECORDS && first_empty != -1) {
@ -127,8 +130,9 @@ add_name(struct dlz_example_data *state, struct record *list, const char *name,
if (strlen(name) >= sizeof(list[i].name) ||
strlen(type) >= sizeof(list[i].type) ||
strlen(data) >= sizeof(list[i].data))
strlen(data) >= sizeof(list[i].data)) {
return (ISC_R_NOSPACE);
}
strncpy(list[i].name, name, sizeof(list[i].name) - 1);
list[i].name[sizeof(list[i].name) - 1] = '\0';
@ -191,8 +195,9 @@ fmt_address(isc_sockaddr_t *addr, char *buffer, size_t size)
return (ISC_R_FAILURE);
}
if (ret == NULL)
if (ret == NULL) {
return (ISC_R_FAILURE);
}
snprintf(buffer, size, "%s#%u", addr_buf, port);
return (ISC_R_SUCCESS);
@ -215,14 +220,18 @@ static void
b9_add_helper(struct dlz_example_data *state, const char *helper_name,
void *ptr)
{
if (strcmp(helper_name, "log") == 0)
if (strcmp(helper_name, "log") == 0) {
state->log = (log_t *)ptr;
if (strcmp(helper_name, "putrr") == 0)
}
if (strcmp(helper_name, "putrr") == 0) {
state->putrr = (dns_sdlz_putrr_t *)ptr;
if (strcmp(helper_name, "putnamedrr") == 0)
}
if (strcmp(helper_name, "putnamedrr") == 0) {
state->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr;
if (strcmp(helper_name, "writeable_zone") == 0)
}
if (strcmp(helper_name, "writeable_zone") == 0) {
state->writeable_zone = (dns_dlz_writeablezone_t *)ptr;
}
}
/*
@ -243,8 +252,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
UNUSED(dlzname);
state = calloc(1, sizeof(struct dlz_example_data));
if (state == NULL)
if (state == NULL) {
return (ISC_R_NOMEMORY);
}
/* Fill in the helper functions */
va_start(ap, dbdata);
@ -265,23 +275,27 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata,
free(state);
return (ISC_R_NOMEMORY);
}
if (argv[1][strlen(argv[1]) - 1] == '.')
if (argv[1][strlen(argv[1]) - 1] == '.') {
strcpy(state->zone_name, argv[1]);
else
} else {
sprintf(state->zone_name, "%s.", argv[1]);
}
if (strcmp(state->zone_name, ".") == 0)
if (strcmp(state->zone_name, ".") == 0) {
extra = ".root";
else
} else {
extra = ".";
}
n = sprintf(soa_data, "%s hostmaster%s%s 123 900 600 86400 3600",
state->zone_name, extra, state->zone_name);
if (n < 0)
if (n < 0) {
CHECK(ISC_R_FAILURE);
if ((unsigned)n >= sizeof(soa_data))
}
if ((unsigned)n >= sizeof(soa_data)) {
CHECK(ISC_R_NOSPACE);
}
add_name(state, &state->current[0], state->zone_name, "soa", 3600,
soa_data);
@ -344,35 +358,40 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods,
* Returning ISC_R_NOMORE prevents the query logic from doing
* this; it will move onto the next database after a single query.
*/
if (strcasecmp(name, "test.example.com") == 0)
if (strcasecmp(name, "test.example.com") == 0) {
return (ISC_R_NOMORE);
}
/*
* For example.net, only return ISC_R_NOMORE when queried
* from 10.53.0.1.
*/
if (strcasecmp(name, "test.example.net") == 0 &&
strncmp(addrbuf, "10.53.0.1", 9) == 0)
strncmp(addrbuf, "10.53.0.1", 9) == 0) {
return (ISC_R_NOMORE);
}
/*
* For bigcname.domain, return success so it appears to be
* the zone origin; this regression tests a bug in which
* zone origin nodes could fail to return SERVFAIL to the client.
*/
if (strcasecmp(name, "bigcname.domain") == 0)
if (strcasecmp(name, "bigcname.domain") == 0) {
return (ISC_R_SUCCESS);
}
/*
* Return success if we have an exact match between the
* zone name and the qname
*/
if (strcasecmp(state->zone_name, name) == 0)
if (strcasecmp(state->zone_name, name) == 0) {
return (ISC_R_SUCCESS);
}
snprintf(absolute, sizeof(absolute), "%s.", name);
if (strcasecmp(state->zone_name, absolute) == 0)
if (strcasecmp(state->zone_name, absolute) == 0) {
return (ISC_R_SUCCESS);
}
return (ISC_R_NOTFOUND);
}
@ -471,35 +490,40 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
found = true;
result = state->putrr(lookup, "TXT", 0, buf);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (strcmp(name, "too-long") == 0 ||
strcmp(zone, "bigcname.domain") == 0) {
for (i = 0; i < 511; i++)
for (i = 0; i < 511; i++) {
buf[i] = 'x';
}
buf[i] = '\0';
found = true;
result = state->putrr(lookup, "TXT", 0, buf);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
/* Tests for DLZ redirection zones */
if (strcmp(name, "*") == 0 && strcmp(zone, ".") == 0) {
result = state->putrr(lookup, "A", 0, "100.100.100.2");
found = true;
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
if (strcmp(name, "long.name.is.not.there") == 0 &&
strcmp(zone, ".") == 0) {
result = state->putrr(lookup, "A", 0, "100.100.100.3");
found = true;
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
/* Answer from current records */
@ -509,13 +533,15 @@ dlz_lookup(const char *zone, const char *name, void *dbdata,
result = state->putrr(lookup, state->current[i].type,
state->current[i].ttl,
state->current[i].data);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
}
if (!found)
if (!found) {
return (ISC_R_NOTFOUND);
}
return (ISC_R_SUCCESS);
}
@ -572,8 +598,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes)
UNUSED(zone);
if (state->putnamedrr == NULL)
if (state->putnamedrr == NULL) {
return (ISC_R_NOTIMPLEMENTED);
}
for (i = 0; i < MAX_RECORDS; i++) {
isc_result_t result;
@ -584,8 +611,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes)
state->current[i].type,
state->current[i].ttl,
state->current[i].data);
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
return (result);
}
}
return (ISC_R_SUCCESS);
@ -720,8 +748,9 @@ modrdataset(struct dlz_example_data *state, const char *name,
char * saveptr = NULL;
buf = strdup(rdatastr);
if (buf == NULL)
if (buf == NULL) {
return (ISC_R_FAILURE);
}
/*
* The format is:
@ -732,24 +761,29 @@ modrdataset(struct dlz_example_data *state, const char *name,
*/
full_name = strtok_r(buf, "\t", &saveptr);
if (full_name == NULL)
if (full_name == NULL) {
goto error;
}
ttlstr = strtok_r(NULL, "\t", &saveptr);
if (ttlstr == NULL)
if (ttlstr == NULL) {
goto error;
}
dclass = strtok_r(NULL, "\t", &saveptr);
if (dclass == NULL)
if (dclass == NULL) {
goto error;
}
type = strtok_r(NULL, "\t", &saveptr);
if (type == NULL)
if (type == NULL) {
goto error;
}
data = strtok_r(NULL, "\t", &saveptr);
if (data == NULL)
if (data == NULL) {
goto error;
}
if (name[strlen(name) - 1] != '.') {
snprintf(absolute, sizeof(absolute), "%s.", name);
@ -772,8 +806,9 @@ dlz_addrdataset(const char *name, const char *rdatastr, void *dbdata,
{
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
if (version != (void *)&state->transaction_started)
if (version != (void *)&state->transaction_started) {
return (ISC_R_FAILURE);
}
loginfo("dlz_example: adding rdataset %s '%s'", name, rdatastr);
@ -786,8 +821,9 @@ dlz_subrdataset(const char *name, const char *rdatastr, void *dbdata,
{
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
if (version != (void *)&state->transaction_started)
if (version != (void *)&state->transaction_started) {
return (ISC_R_FAILURE);
}
loginfo("dlz_example: subtracting rdataset %s '%s'", name, rdatastr);
@ -799,8 +835,9 @@ dlz_delrdataset(const char *name, const char *type, void *dbdata, void *version)
{
struct dlz_example_data *state = (struct dlz_example_data *)dbdata;
if (version != (void *)&state->transaction_started)
if (version != (void *)&state->transaction_started) {
return (ISC_R_FAILURE);
}
loginfo("dlz_example: deleting rdataset %s of type %s", name, type);

View file

@ -353,8 +353,9 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version,
dns_fixedname_init(&name);
result = dns_db_subtractrdataset(sampledb->rbtdb, node, version,
rdataset, options, newrdataset);
if (result != ISC_R_SUCCESS && result != DNS_R_NXRRSET)
if (result != ISC_R_SUCCESS && result != DNS_R_NXRRSET) {
goto cleanup;
}
if (rdataset->type == dns_rdatatype_a ||
rdataset->type == dns_rdatatype_aaaa) {
@ -668,8 +669,9 @@ add_soa(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name,
CHECK(dns_db_findnode(db, name, true, &node));
CHECK(dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL));
cleanup:
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
}
return (result);
}
@ -706,8 +708,9 @@ add_ns(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name,
CHECK(dns_db_findnode(db, name, true, &node));
CHECK(dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL));
cleanup:
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
}
return (result);
}
@ -742,8 +745,9 @@ add_a(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name,
CHECK(dns_db_findnode(db, name, true, &node));
CHECK(dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL));
cleanup:
if (node != NULL)
if (node != NULL) {
dns_db_detachnode(db, &node);
}
return (result);
}
@ -811,8 +815,9 @@ create_db(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type,
cleanup:
if (sampledb != NULL) {
if (dns_name_dynamic(&sampledb->common.origin))
if (dns_name_dynamic(&sampledb->common.origin)) {
dns_name_free(&sampledb->common.origin, mctx);
}
isc_mem_putanddetach(&sampledb->common.mctx, sampledb,
sizeof(*sampledb));

View file

@ -120,8 +120,9 @@ dyndb_init(isc_mem_t *mctx, const char *name, const char *parameters,
cleanup:
isc_mem_free(mctx, s);
if (argv != NULL)
if (argv != NULL) {
isc_mem_put(mctx, argv, argc * sizeof(*argv));
}
return (result);
}

View file

@ -126,8 +126,9 @@ new_sample_instance(isc_mem_t *mctx, const char *db_name, int argc, char **argv,
result = ISC_R_SUCCESS;
cleanup:
if (result != ISC_R_SUCCESS)
if (result != ISC_R_SUCCESS) {
destroy_sample_instance(&inst);
}
return (result);
}
@ -182,17 +183,22 @@ destroy_sample_instance(sample_instance_t **instp)
inst = *instp;
*instp = NULL;
if (inst == NULL)
if (inst == NULL) {
return;
}
if (inst->db_name != NULL)
if (inst->db_name != NULL) {
isc_mem_free(inst->mctx, inst->db_name);
if (inst->zone1 != NULL)
}
if (inst->zone1 != NULL) {
dns_zone_detach(&inst->zone1);
if (inst->zone2 != NULL)
}
if (inst->zone2 != NULL) {
dns_zone_detach(&inst->zone2);
if (inst->db_imp != NULL)
}
if (inst->db_imp != NULL) {
dns_db_unregister(&inst->db_imp);
}
dns_view_detach(&inst->view);
dns_zonemgr_detach(&inst->zmgr);

View file

@ -47,11 +47,12 @@ run_exclusive_enter(sample_instance_t *inst, isc_result_t *statep)
void
run_exclusive_exit(sample_instance_t *inst, isc_result_t state)
{
if (state == ISC_R_SUCCESS)
if (state == ISC_R_SUCCESS) {
isc_task_endexclusive(inst->task);
else
} else {
/* Unlocking recursive lock or the lock was never locked. */
INSIST(state == ISC_R_LOCKBUSY || state == ISC_R_IGNORE);
}
return;
}

View file

@ -33,9 +33,10 @@ struct syncptrevent {
isc_mem_t * mctx;
dns_zone_t * zone;
dns_diff_t diff;
dns_fixedname_t ptr_target_name; /* referenced by owner name in tuple */
isc_buffer_t b; /* referenced by target name in tuple */
unsigned char buf[DNS_NAME_MAXWIRE];
dns_fixedname_t ptr_target_name; /* referenced by owner name in
* tuple */
isc_buffer_t b; /* referenced by target name in tuple */
unsigned char buf[DNS_NAME_MAXWIRE];
};
/*
@ -84,8 +85,9 @@ syncptr_write(isc_task_t *task, isc_event_t *event)
cleanup:
if (db != NULL) {
if (version != NULL)
if (version != NULL) {
dns_db_closeversion(db, &version, true);
}
dns_db_detach(&db);
}
dns_zone_detach(&pevent->zone);
@ -150,9 +152,9 @@ syncptr_find_zone(sample_instance_t *inst, dns_rdata_t *rdata, dns_name_t *name,
/* Find a zone containing owner name of the PTR record. */
result = dns_zt_find(inst->view->zonetable, name, 0, NULL, zone);
if (result == DNS_R_PARTIALMATCH)
if (result == DNS_R_PARTIALMATCH) {
result = ISC_R_SUCCESS;
else if (result != ISC_R_SUCCESS) {
} else if (result != ISC_R_SUCCESS) {
log_write(ISC_LOG_ERROR,
"syncptr_find_zone: dns_zt_find -> %s\n",
isc_result_totext(result));
@ -167,10 +169,11 @@ syncptr_find_zone(sample_instance_t *inst, dns_rdata_t *rdata, dns_name_t *name,
}
cleanup:
if (rdata->type == dns_rdatatype_a)
if (rdata->type == dns_rdatatype_a) {
dns_rdata_freestruct(&ipv4);
else
} else {
dns_rdata_freestruct(&ipv6);
}
return (result);
}
@ -262,14 +265,18 @@ syncptr(sample_instance_t *inst, dns_name_t *name, dns_rdata_t *addr_rdata,
isc_task_send(task, (isc_event_t **)&pevent);
cleanup:
if (ptr_zone != NULL)
if (ptr_zone != NULL) {
dns_zone_detach(&ptr_zone);
if (tp != NULL)
}
if (tp != NULL) {
dns_difftuple_free(&tp);
if (task != NULL)
}
if (task != NULL) {
isc_task_detach(&task);
if (pevent != NULL)
}
if (pevent != NULL) {
isc_event_free((isc_event_t **)&pevent);
}
return (result);
}
@ -293,11 +300,13 @@ syncptrs(sample_instance_t *inst, dns_name_t *name, dns_rdataset_t *rdataset,
result = dns_rdataset_next(rdataset)) {
dns_rdataset_current(rdataset, &rdata);
result = syncptr(inst, name, &rdata, rdataset->ttl, op);
if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND)
if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) {
goto cleanup;
}
}
if (result == ISC_R_NOMORE)
if (result == ISC_R_NOMORE) {
result = ISC_R_SUCCESS;
}
cleanup:
return (result);

Some files were not shown because too many files have changed in this diff Show more