diff --git a/bin/check/check-tool.c b/bin/check/check-tool.c index 7b25dbc3ba..e1b370ecb8 100644 --- a/bin/check/check-tool.c +++ b/bin/check/check-tool.c @@ -17,7 +17,7 @@ #ifdef _WIN32 #include -#endif +#endif /* ifdef _WIN32 */ #include #include @@ -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 */ diff --git a/bin/check/check-tool.h b/bin/check/check-tool.h index a2a00c7d98..62a9d19640 100644 --- a/bin/check/check-tool.h +++ b/bin/check/check-tool.h @@ -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 */ diff --git a/bin/check/named-checkconf.c b/bin/check/named-checkconf.c index 646cb3741d..c1ba60e35c 100644 --- a/bin/check/named-checkconf.c +++ b/bin/check/named-checkconf.c @@ -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); } diff --git a/bin/check/named-checkzone.c b/bin/check/named-checkzone.c index c42df6a9dd..9209ab93e2 100644 --- a/bin/check/named-checkzone.c +++ b/bin/check/named-checkzone.c @@ -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); } diff --git a/bin/confgen/ddns-confgen.c b/bin/confgen/ddns-confgen.c index 8f55416d40..0ee722f414 100644 --- a/bin/confgen/ddns-confgen.c +++ b/bin/confgen/ddns-confgen.c @@ -36,7 +36,7 @@ #if USE_PKCS11 #include -#endif +#endif /* if USE_PKCS11 */ #include #include @@ -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 \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); diff --git a/bin/confgen/include/confgen/os.h b/bin/confgen/include/confgen/os.h index 9c2a585ff2..3b35718d6d 100644 --- a/bin/confgen/include/confgen/os.h +++ b/bin/confgen/include/confgen/os.h @@ -31,4 +31,4 @@ set_user(FILE *fd, const char *user); ISC_LANG_ENDDECLS -#endif +#endif /* ifndef RNDC_OS_H */ diff --git a/bin/confgen/keygen.c b/bin/confgen/keygen.c index 29d16a2784..d2ae7507fb 100644 --- a/bin/confgen/keygen.c +++ b/bin/confgen/keygen.c @@ -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); } diff --git a/bin/confgen/rndc-confgen.c b/bin/confgen/rndc-confgen.c index f86e5dfbf0..95c5c12df1 100644 --- a/bin/confgen/rndc-confgen.c +++ b/bin/confgen/rndc-confgen.c @@ -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); diff --git a/bin/delv/delv.c b/bin/delv/delv.c index 2ae89ae895..1f67619f38 100644 --- a/bin/delv/delv.c +++ b/bin/delv/delv.c @@ -19,7 +19,7 @@ #include #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -38,7 +38,7 @@ #include #ifdef WIN32 #include -#endif +#endif /* ifdef WIN32 */ #include #include #include @@ -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(); diff --git a/bin/dig/dig.c b/bin/dig/dig.c index ea4f7c2f6a..e194542ff6 100644 --- a/bin/dig/dig.c +++ b/bin/dig/dig.c @@ -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 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; diff --git a/bin/dig/dighost.c b/bin/dig/dighost.c index 2d8caa483b..057e9e96b8 100644 --- a/bin/dig/dighost.c +++ b/bin/dig/dighost.c @@ -29,7 +29,7 @@ #ifdef HAVE_LOCALE_H #include -#endif +#endif /* ifdef HAVE_LOCALE_H */ #ifdef HAVE_LIBIDN2 #include @@ -83,15 +83,15 @@ #if USE_PKCS11 #include -#endif +#endif /* if USE_PKCS11 */ #if !defined(NS_INADDRSZ) #define NS_INADDRSZ 4 -#endif +#endif /* if !defined(NS_INADDRSZ) */ #if !defined(NS_IN6ADDRSZ) #define NS_IN6ADDRSZ 16 -#endif +#endif /* if !defined(NS_IN6ADDRSZ) */ dig_lookuplist_t lookup_list; dig_serverlist_t server_list; @@ -193,7 +193,7 @@ default_warnerr(const char *format, ...) vprintf(format, args); va_end(args); printf("\n"); -}; +} static void default_comments(dig_lookup_t *lookup, const char *format, ...) @@ -207,7 +207,7 @@ default_comments(dig_lookup_t *lookup, const char *format, ...) va_end(args); printf("\n"); } -}; +} /* dynamic callbacks */ @@ -260,8 +260,9 @@ count_dots(char *string) s = string; while (*s != '\0') { - if (*s == '.') + if (*s == '.') { i++; + } s++; } return (i); @@ -281,23 +282,26 @@ hex_dump(isc_buffer_t *b) if (len % 16 == 15) { fputs(" ", stdout); for (i = len - 15; i <= len; i++) { - if (r.base[i] >= '!' && r.base[i] <= '}') + if (r.base[i] >= '!' && r.base[i] <= '}') { putchar(r.base[i]); - else + } else { putchar('.'); + } } printf("\n"); } } if (len % 16 != 0) { - for (i = len; (i % 16) != 0; i++) + for (i = len; (i % 16) != 0; i++) { fputs(" ", stdout); + } fputs(" ", stdout); for (i = ((len >> 4) << 4); i < len; i++) { - if (r.base[i] >= '!' && r.base[i] <= '}') + if (r.base[i] >= '!' && r.base[i] <= '}') { putchar(r.base[i]); - else + } else { putchar('.'); + } } printf("\n"); } @@ -310,8 +314,9 @@ hex_dump(isc_buffer_t *b) static isc_result_t append(const char *text, size_t len, char **p, char *end) { - if (*p + len > end) + if (*p + len > end) { return (ISC_R_NOSPACE); + } memmove(*p, text, len); *p += len; return (ISC_R_SUCCESS); @@ -325,11 +330,13 @@ 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(".", 1, p, end); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } len = (int)(dot - in); } else { len = (int)strlen(in); @@ -354,8 +361,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 { @@ -369,15 +377,18 @@ 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); + } /* Append .in-addr.arpa. and a terminating NUL. */ result = append(".in-addr.arpa.", 15, &p, end); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (ISC_R_SUCCESS); } } @@ -397,7 +408,7 @@ warn(const char *format, ...) va_end(args); fprintf(stderr, "\n"); } -#else +#else /* if TARGET_OS_IPHONE */ void warn(const char *format, ...) { @@ -410,15 +421,17 @@ warn(const char *format, ...) va_end(args); fprintf(stderr, "\n"); } -#endif +#endif /* if TARGET_OS_IPHONE */ void digexit(void) { - if (exitcode < 10) + if (exitcode < 10) { exitcode = 10; - if (fatalexit != 0) + } + if (fatalexit != 0) { exitcode = fatalexit; + } if (dighost_pre_exit_hook != NULL) { dighost_pre_exit_hook(); } @@ -508,16 +521,19 @@ get_server_list(irs_resconf_t *resconf) isc_result_t result; isc_buffer_t b; - if (pf == AF_INET && !have_ipv4) + if (pf == AF_INET && !have_ipv4) { continue; - if (pf == AF_INET6 && !have_ipv6) + } + if (pf == AF_INET6 && !have_ipv6) { continue; + } isc_buffer_init(&b, tmp, sizeof(tmp)); isc_netaddr_fromsockaddr(&na, sa); result = isc_netaddr_totext(&na, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } isc_buffer_putuint8(&b, 0); if (pf == AF_INET6 && na.zone != 0) { char buf[sizeof("%4000000000")]; @@ -555,14 +571,16 @@ set_nameserver(char *opt) dig_server_t * srv; char tmp[ISC_NETADDR_FORMATSIZE]; - if (opt == NULL) + if (opt == NULL) { return; + } result = bind9_getaddresses(opt, 0, sockaddrs, DIG_MAX_ADDRESSES, &count); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("couldn't get address for '%s': %s", opt, isc_result_totext(result)); + } flush_server_list(); @@ -570,8 +588,9 @@ set_nameserver(char *opt) isc_netaddr_fromsockaddr(&netaddr, &sockaddrs[i]); isc_netaddr_format(&netaddr, tmp, sizeof(tmp)); srv = make_server(tmp, opt); - if (srv == NULL) + if (srv == NULL) { fatal("memory allocation failure"); + } ISC_LIST_APPEND(server_list, srv, link); } } @@ -658,7 +677,7 @@ make_empty_lookup(void) #ifdef HAVE_LIBIDN2 looknew->idnin = isatty(1) ? (getenv("IDN_DISABLE") == NULL) : false; looknew->idnout = looknew->idnin; -#else +#else /* ifdef HAVE_LIBIDN2 */ looknew->idnin = false; looknew->idnout = false; #endif /* HAVE_LIBIDN2 */ @@ -720,8 +739,9 @@ cloneopts(dig_lookup_t *looknew, dig_lookup_t *lookold) looknew->ednsopts[i].value = NULL; } looknew->ednsoptscnt = 0; - if (lookold == NULL || lookold->ednsopts == NULL) + if (lookold == NULL || lookold->ednsopts == NULL) { return; + } for (i = 0; i < lookold->ednsoptscnt; i++) { len = lookold->ednsopts[i].length; @@ -843,9 +863,10 @@ clone_lookup(dig_lookup_t *lookold, bool servers) dns_name_copynf(dns_fixedname_name(&lookold->fdomain), dns_fixedname_name(&looknew->fdomain)); - if (servers) + if (servers) { clone_server_list(lookold->my_server_list, &looknew->my_server_list); + } return (looknew); } @@ -865,8 +886,9 @@ requeue_lookup(dig_lookup_t *lookold, bool servers) debug("requeue_lookup()"); lookup_counter++; - if (lookup_counter > LOOKUP_LIMIT) + if (lookup_counter > LOOKUP_LIMIT) { fatal("too many lookups"); + } looknew = clone_lookup(lookold, servers); INSIST(looknew != NULL); @@ -896,8 +918,9 @@ setup_text_key(void) secretstore = isc_mem_allocate(mctx, secretsize); isc_buffer_init(&secretbuf, secretstore, secretsize); result = isc_base64_decodestring(keysecret, &secretbuf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } secretsize = isc_buffer_usedlength(&secretbuf); @@ -907,18 +930,20 @@ setup_text_key(void) } result = dns_name_fromtext(&keyname, namebuf, dns_rootname, 0, namebuf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_tsigkey_create(&keyname, hmacname, secretstore, (int)secretsize, false, NULL, 0, 0, mctx, NULL, &tsigkey); failure: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { printf(";; Couldn't create key %s: %s\n", keynametext, isc_result_totext(result)); - else + } else { dst_key_setbits(tsigkey->key, digestbits); + } isc_mem_free(mctx, secretstore); dns_name_invalidate(&keyname); @@ -931,8 +956,9 @@ parse_uint_helper(uint32_t *uip, const char *value, uint32_t max, { uint32_t n; isc_result_t result = isc_parse_uint32(&n, value, base); - 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)); @@ -961,8 +987,9 @@ parse_bits(char *arg, const char *desc, uint32_t max) uint32_t tmp; result = parse_uint(&tmp, arg, max, desc); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("couldn't parse digest bits"); + } tmp = (tmp + 7) & ~0x7U; return (tmp); } @@ -982,8 +1009,9 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) REQUIRE(sap != NULL && *sap == NULL); - if (strlcpy(buf, value, sizeof(buf)) >= sizeof(buf)) + if (strlcpy(buf, value, sizeof(buf)) >= sizeof(buf)) { fatal("invalid prefix '%s'\n", value); + } sa = isc_mem_allocate(mctx, sizeof(*sa)); memset(sa, 0, sizeof(*sa)); @@ -1008,13 +1036,15 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) if (inet_pton(AF_INET6, buf, &in6) == 1) { parsed = true; isc_sockaddr_fromin6(sa, &in6, 0); - if (prefix_length > 128) + if (prefix_length > 128) { prefix_length = 128; + } } else if (inet_pton(AF_INET, buf, &in4) == 1) { parsed = true; isc_sockaddr_fromin(sa, &in4, 0); - if (prefix_length > 32) + if (prefix_length > 32) { prefix_length = 32; + } } else if (prefix_parsed) { int i; @@ -1027,12 +1057,14 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) } } - if (prefix_length > 32) + if (prefix_length > 32) { prefix_length = 32; + } } - if (!parsed) + if (!parsed) { fatal("invalid address '%s'", value); + } done: sa->length = prefix_length; @@ -1053,8 +1085,9 @@ parse_hmac(const char *hmac) REQUIRE(hmac != NULL); len = strlen(hmac); - if (len >= sizeof(buf)) + if (len >= sizeof(buf)) { fatal("unknown key type '%.*s'", (int)len, hmac); + } strlcpy(buf, hmac, sizeof(buf)); digestbits = 0; @@ -1114,25 +1147,30 @@ read_confkey(void) const char * algorithm; isc_result_t result; - if (!isc_file_exists(keyfile)) + if (!isc_file_exists(keyfile)) { return (ISC_R_FILENOTFOUND); + } result = cfg_parser_create(mctx, NULL, &pctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = cfg_parse_file(pctx, keyfile, &cfg_type_sessionkey, &file); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = cfg_map_get(file, "key", &keyobj); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } (void)cfg_map_get(keyobj, "secret", &secretobj); (void)cfg_map_get(keyobj, "algorithm", &algorithmobj); - if (secretobj == NULL || algorithmobj == NULL) + if (secretobj == NULL || algorithmobj == NULL) { fatal("key must have algorithm and secret"); + } keyname = cfg_obj_asstring(cfg_map_getname(keyobj)); secretstr = cfg_obj_asstring(secretobj); @@ -1145,8 +1183,9 @@ read_confkey(void) cleanup: if (pctx != NULL) { - if (file != NULL) + if (file != NULL) { cfg_obj_destroy(pctx, &file); + } cfg_parser_destroy(&pctx); } @@ -1168,8 +1207,9 @@ setup_file_key(void) /* If that didn't work, try reading it as a session.key keyfile */ if (result != ISC_R_SUCCESS) { result = read_confkey(); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return; + } } if (result != ISC_R_SUCCESS) { @@ -1211,8 +1251,9 @@ setup_file_key(void) goto failure; } failure: - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_free(&dstkey); + } } static dig_searchlist_t * @@ -1329,12 +1370,13 @@ setup_system(bool ipv4only, bool ipv6only) #ifdef HAVE_SETLOCALE /* Set locale */ (void)setlocale(LC_ALL, ""); -#endif +#endif /* ifdef HAVE_SETLOCALE */ - if (keyfile[0] != 0) + if (keyfile[0] != 0) { setup_file_key(); - else if (keysecret[0] != 0) + } else if (keysecret[0] != 0) { setup_text_key(); + } isc_nonce_buf(cookie_secret, sizeof(cookie_secret)); } @@ -1365,18 +1407,21 @@ setup_libs(void) #if USE_PKCS11 pk11_result_register(); -#endif +#endif /* if USE_PKCS11 */ dns_result_register(); result = isc_net_probeipv4(); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_ipv4 = true; + } result = isc_net_probeipv6(); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_ipv6 = true; - if (!have_ipv6 && !have_ipv4) + } + if (!have_ipv6 && !have_ipv4) { fatal("can't find either v4 or v6 networking"); + } isc_mem_create(&mctx); isc_mem_setname(mctx, "dig", NULL); @@ -1457,8 +1502,9 @@ save_opt(dig_lookup_t *lookup, char *code, char *value) bool found = false; unsigned int i; - if (lookup->ednsoptscnt >= EDNSOPT_OPTIONS) + if (lookup->ednsoptscnt >= EDNSOPT_OPTIONS) { fatal("too many ednsopts"); + } for (i = 0; i < N_EDNS_OPTNAMES; i++) { if (strcasecmp(code, optnames[i].name) == 0) { @@ -1470,16 +1516,18 @@ save_opt(dig_lookup_t *lookup, char *code, char *value) if (!found) { result = parse_uint(&num, code, 65535, "ednsopt"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("bad edns code point: %s", code); + } } if (lookup->ednsopts == NULL) { cloneopts(lookup, NULL); } - if (lookup->ednsopts[lookup->ednsoptscnt].value != NULL) + if (lookup->ednsopts[lookup->ednsoptscnt].value != NULL) { isc_mem_free(mctx, lookup->ednsopts[lookup->ednsoptscnt].value); + } lookup->ednsopts[lookup->ednsoptscnt].code = num; lookup->ednsopts[lookup->ednsoptscnt].length = 0; @@ -1666,26 +1714,31 @@ destroy_lookup(dig_lookup_t *lookup) link); isc_mem_free(mctx, ptr); } - if (lookup->sendmsg != NULL) + if (lookup->sendmsg != NULL) { dns_message_destroy(&lookup->sendmsg); + } if (lookup->querysig != NULL) { debug("freeing buffer %p", lookup->querysig); isc_buffer_free(&lookup->querysig); } - if (lookup->sendspace != NULL) + if (lookup->sendspace != NULL) { isc_mempool_put(commctx, lookup->sendspace); + } - if (lookup->tsigctx != NULL) + if (lookup->tsigctx != NULL) { dst_context_destroy(&lookup->tsigctx); + } - if (lookup->ecs_addr != NULL) + if (lookup->ecs_addr != NULL) { isc_mem_free(mctx, lookup->ecs_addr); + } if (lookup->ednsopts != NULL) { size_t i; for (i = 0; i < EDNSOPT_OPTIONS; i++) { - if (lookup->ednsopts[i].value != NULL) + if (lookup->ednsopts[i].value != NULL) { isc_mem_free(mctx, lookup->ednsopts[i].value); + } } isc_mem_free(mctx, lookup->ednsopts); } @@ -1703,8 +1756,9 @@ void start_lookup(void) { debug("start_lookup()"); - if (cancel_now) + if (cancel_now) { return; + } /* * If there's a current lookup running, we really shouldn't get @@ -1718,10 +1772,11 @@ start_lookup(void) */ if (current_lookup != NULL) { ISC_LIST_DEQUEUE(lookup_list, current_lookup, link); - if (setup_lookup(current_lookup)) + if (setup_lookup(current_lookup)) { do_lookup(current_lookup); - else if (next_origin(current_lookup)) + } else if (next_origin(current_lookup)) { check_next_lookup(current_lookup); + } } else { check_if_done(); } @@ -1787,14 +1842,16 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) rdataset = NULL; result = dns_message_findtype(name, dns_rdatatype_soa, 0, &rdataset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (0); + } } rdataset = NULL; result = dns_message_findtype(name, dns_rdatatype_ns, 0, &rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } debug("found NS set"); @@ -1828,8 +1885,9 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) dns_rdata_ns_t ns; if (query->lookup->trace_root && - query->lookup->nsfound >= MXSERV) + query->lookup->nsfound >= MXSERV) { break; + } dns_rdataset_current(rdataset, &rdata); @@ -1848,15 +1906,17 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) cancel_lookup(query->lookup); lookup->doing_xfr = false; if (!lookup->trace_root && - section == DNS_SECTION_ANSWER) + section == DNS_SECTION_ANSWER) { lookup->trace = false; - else + } else { lookup->trace = query->lookup->trace; + } lookup->ns_search_only = query->lookup->ns_search_only; lookup->trace_root = false; - if (lookup->ns_search_only) + if (lookup->ns_search_only) { lookup->recurse = false; + } domain = dns_fixedname_name(&lookup->fdomain); dns_name_copynf(name, domain); } @@ -1881,8 +1941,9 @@ followup_lookup(dns_message_t *msg, dig_query_t *query, dns_section_t section) } if (lookup == NULL && section == DNS_SECTION_ANSWER && - (query->lookup->trace || query->lookup->ns_search_only)) + (query->lookup->trace || query->lookup->ns_search_only)) { return (followup_lookup(msg, query, DNS_SECTION_AUTHORITY)); + } /* * Randomize the order the nameserver will be tried. @@ -1935,12 +1996,13 @@ next_origin(dig_lookup_t *oldlookup) debug("next_origin()"); debug("following up %s", oldlookup->textname); - if (!usesearch) + if (!usesearch) { /* * We're not using a search list, so don't even think * about finding the next entry. */ return (false); + } /* * Check for a absolute name or ndots being met. @@ -1949,22 +2011,25 @@ next_origin(dig_lookup_t *oldlookup) result = dns_name_fromstring2(name, oldlookup->textname, NULL, 0, NULL); if (result == ISC_R_SUCCESS && (dns_name_isabsolute(name) || - (int)dns_name_countlabels(name) > ndots)) + (int)dns_name_countlabels(name) > ndots)) { return (false); + } - if (oldlookup->origin == NULL && !oldlookup->need_search) + if (oldlookup->origin == NULL && !oldlookup->need_search) { /* * Then we just did rootorg; there's nothing left. */ return (false); + } if (oldlookup->origin == NULL && oldlookup->need_search) { newlookup = requeue_lookup(oldlookup, true); newlookup->origin = ISC_LIST_HEAD(search_list); newlookup->need_search = false; } else { search = ISC_LIST_NEXT(oldlookup->origin, link); - if (search == NULL && oldlookup->done_as_is) + if (search == NULL && oldlookup->done_as_is) { return (false); + } newlookup = requeue_lookup(oldlookup, true); newlookup->origin = search; } @@ -2197,9 +2262,9 @@ setup_lookup(dig_lookup_t *lookup) dns_message_puttempname(lookup->sendmsg, &lookup->oname); } else { debug("using root origin"); - if (lookup->trace && lookup->trace_root) + if (lookup->trace && lookup->trace_root) { dns_name_clone(dns_rootname, lookup->name); - else { + } else { len = (unsigned int)strlen(textname); isc_buffer_init(&b, textname, len); isc_buffer_add(&b, len); @@ -2215,9 +2280,9 @@ setup_lookup(dig_lookup_t *lookup) #if TARGET_OS_IPHONE check_next_lookup(current_lookup); return (false); -#else +#else /* if TARGET_OS_IPHONE */ digexit(); -#endif +#endif /* if TARGET_OS_IPHONE */ } } dns_name_format(lookup->name, store, sizeof(store)); @@ -2294,13 +2359,15 @@ setup_lookup(dig_lookup_t *lookup) } } - if (!lookup->header_only) + if (!lookup->header_only) { add_question(lookup->sendmsg, lookup->name, lookup->rdclass, lookup->rdtype); + } /* add_soa */ - if (lookup->rdtype == dns_rdatatype_ixfr) + if (lookup->rdtype == dns_rdatatype_ixfr) { insert_soa(lookup); + } /* XXX Insist this? */ lookup->tsigctx = NULL; @@ -2312,8 +2379,9 @@ setup_lookup(dig_lookup_t *lookup) } lookup->sendspace = isc_mempool_get(commctx); - if (lookup->sendspace == NULL) + if (lookup->sendspace == NULL) { fatal("memory allocation failure"); + } result = dns_compress_init(&cctx, -1, mctx); check_result(result, "dns_compress_init"); @@ -2336,10 +2404,12 @@ setup_lookup(dig_lookup_t *lookup) * and DNS_EDNSOPTIONS set by other arguments * (+nsid, +cookie, etc). */ - if (lookup->udpsize == 0) + if (lookup->udpsize == 0) { lookup->udpsize = 4096; - if (lookup->edns < 0) + } + if (lookup->edns < 0) { lookup->edns = 0; + } if (lookup->nsid) { INSIST(i < MAXOPTS); @@ -2422,9 +2492,10 @@ setup_lookup(dig_lookup_t *lookup) /* address */ if (addrl > 0) { /* Mask off last address byte */ - if ((plen % 8) != 0) + if ((plen % 8) != 0) { addr[addrl - 1] &= ~0U << (8 - (plen % 8)); + } isc_buffer_putmem(&b, addr, (unsigned)addrl); } @@ -2491,8 +2562,9 @@ setup_lookup(dig_lookup_t *lookup) flags = lookup->ednsflags; flags &= ~DNS_MESSAGEEXTFLAG_DO; - if (lookup->dnssec) + if (lookup->dnssec) { flags |= DNS_MESSAGEEXTFLAG_DO; + } add_opt(lookup->sendmsg, lookup->udpsize, lookup->edns, flags, opts, i); } @@ -2512,8 +2584,9 @@ setup_lookup(dig_lookup_t *lookup) /* * Force TCP mode if the request is larger than 512 bytes. */ - if (isc_buffer_usedlength(&lookup->renderbuf) > 512) + if (isc_buffer_usedlength(&lookup->renderbuf) > 512) { lookup->tcp_mode = true; + } lookup->pending = false; @@ -2657,18 +2730,21 @@ bringup_timer(dig_query_t *query, unsigned int default_timeout) * just reset it. */ l = query->lookup; - if (ISC_LINK_LINKED(query, link) && ISC_LIST_NEXT(query, link) != NULL) + if (ISC_LINK_LINKED(query, link) && + ISC_LIST_NEXT(query, link) != NULL) { local_timeout = SERVER_TIMEOUT; - else { - if (timeout == 0) + } else { + if (timeout == 0) { local_timeout = default_timeout; - else + } else { local_timeout = timeout; + } } debug("have local timeout of %d", local_timeout); isc_interval_set(&l->interval, local_timeout, 0); - if (query->timer != NULL) + if (query->timer != NULL) { isc_timer_detach(&query->timer); + } result = isc_timer_create(timermgr, isc_timertype_once, NULL, &l->interval, global_task, connect_timeout, query, &query->timer); @@ -2691,8 +2767,9 @@ force_timeout(dig_query_t *query) * We need to cancel the possible timeout event not to confuse * ourselves due to the duplicate events. */ - if (query->timer != NULL) + if (query->timer != NULL) { isc_timer_detach(&query->timer); + } } static void @@ -2737,10 +2814,11 @@ send_tcp_connect(dig_query_t *query) dighost_warning("Skipping mapped address '%s'", buf); query->waiting_connect = false; - if (ISC_LINK_LINKED(query, link)) + if (ISC_LINK_LINKED(query, link)) { next = ISC_LIST_NEXT(query, link); - else + } else { next = NULL; + } l = query->lookup; clear_query(query); if (next == NULL) { @@ -2767,17 +2845,20 @@ send_tcp_connect(dig_query_t *query) check_result(result, "isc_socket_create"); sockcount++; debug("sockcount=%d", sockcount); - if (query->lookup->dscp != -1) + if (query->lookup->dscp != -1) { isc_socket_dscp(query->sock, query->lookup->dscp); + } isc_socket_ipv6only(query->sock, !query->lookup->mapped); - if (specified_source) + if (specified_source) { result = isc_socket_bind(query->sock, &bind_address, ISC_SOCKET_REUSEADDRESS); - else { - if ((isc_sockaddr_pf(&query->sockaddr) == AF_INET) && have_ipv4) + } else { + if ((isc_sockaddr_pf(&query->sockaddr) == AF_INET) && + have_ipv4) { isc_sockaddr_any(&bind_any); - else + } else { isc_sockaddr_any6(&bind_any); + } result = isc_socket_bind(query->sock, &bind_any, 0); } check_result(result, "isc_socket_bind"); @@ -2795,11 +2876,13 @@ search: if (ISC_LINK_LINKED(query, link)) { next = ISC_LIST_NEXT(query, link); ISC_LIST_DEQUEUE(l->q, query, link); - } else + } else { next = NULL; + } ISC_LIST_ENQUEUE(l->connecting, query, clink); - if (next != NULL) + if (next != NULL) { send_tcp_connect(next); + } } } @@ -2871,8 +2954,9 @@ send_udp(dig_query_t *query) check_result(result, "isc_socket_create"); sockcount++; debug("sockcount=%d", sockcount); - if (query->lookup->dscp != -1) + if (query->lookup->dscp != -1) { isc_socket_dscp(query->sock, query->lookup->dscp); + } isc_socket_ipv6only(query->sock, !query->lookup->mapped); if (specified_source) { result = isc_socket_bind(query->sock, &bind_address, @@ -3026,8 +3110,9 @@ connect_timeout(isc_task_t *task, isc_event_t *event) } cancel_lookup(l); check_next_lookup(l); - if (exitcode < 9) + if (exitcode < 9) { exitcode = 9; + } } UNLOCK_LOOKUP; } @@ -3097,8 +3182,9 @@ tcp_length_done(isc_task_t *task, isc_event_t *event) isc_sockaddr_format(&query->sockaddr, sockstr, sizeof(sockstr)); dighost_error("communications error to %s: %s\n", sockstr, isc_result_totext(sevent->result)); - if (keep != NULL) + if (keep != NULL) { isc_socket_detach(&keep); + } l = query->lookup; isc_socket_detach(&query->sock); sockcount--; @@ -3211,7 +3297,7 @@ launch_next_query(dig_query_t *query, bool include_question) query->waiting_connect = false; #if 0 check_next_lookup(query->lookup); -#endif +#endif /* if 0 */ return; } @@ -3281,30 +3367,34 @@ connect_done(isc_task_t *task, isc_event_t *event) INSIST(sockcount > 0); sockcount--; /* XXX Clean up exitcodes */ - if (exitcode < 9) + if (exitcode < 9) { exitcode = 9; + } debug("sockcount=%d", sockcount); query->waiting_connect = false; isc_event_free(&event); l = query->lookup; if ((l->current_query != NULL) && - (ISC_LINK_LINKED(l->current_query, link))) + (ISC_LINK_LINKED(l->current_query, link))) { next = ISC_LIST_NEXT(l->current_query, link); - else + } else { next = NULL; + } clear_query(query); if (next != NULL) { bringup_timer(next, TCP_TIMEOUT); send_tcp_connect(next); - } else + } else { check_next_lookup(l); + } UNLOCK_LOOKUP; return; } exitcode = 0; if (keep_open) { - if (keep != NULL) + if (keep != NULL) { isc_socket_detach(&keep); + } isc_socket_attach(query->sock, &keep); keepaddr = query->sockaddr; } @@ -3331,8 +3421,9 @@ check_for_more_data(dig_query_t *query, dns_message_t *msg, bool ixfr = query->lookup->rdtype == dns_rdatatype_ixfr; bool axfr = query->lookup->rdtype == dns_rdatatype_axfr; - if (ixfr) + if (ixfr) { axfr = query->ixfr_axfr; + } debug("check_for_more_data()"); @@ -3359,8 +3450,9 @@ check_for_more_data(dig_query_t *query, dns_message_t *msg, for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { result = dns_rdataset_first(rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } do { query->rr_count++; dns_rdata_reset(&rdata); @@ -3388,8 +3480,9 @@ check_for_more_data(dig_query_t *query, dns_message_t *msg, * If the record is anything except an SOA * now, just continue on... */ - if (rdata.type != dns_rdatatype_soa) + if (rdata.type != dns_rdatatype_soa) { goto next_rdata; + } /* Now we have an SOA. Work with it. */ debug("got an SOA"); @@ -3594,8 +3687,9 @@ recv_done(isc_task_t *task, isc_event_t *event) isc_buffer_init(&b, sevent->region.base, sevent->n); isc_buffer_add(&b, sevent->n); - if ((l->tcp_mode) && (query->timer != NULL)) + if ((l->tcp_mode) && (query->timer != NULL)) { isc_timer_touch(query->timer); + } if ((!l->pending && !l->ns_search_only) || cancel_now) { debug("no longer pending. Got %s", isc_result_totext(sevent->result)); @@ -3615,8 +3709,9 @@ recv_done(isc_task_t *task, isc_event_t *event) } else { dighost_error("communications error: %s\n", isc_result_totext(sevent->result)); - if (keep != NULL) + if (keep != NULL) { isc_socket_detach(&keep); + } isc_socket_detach(&query->sock); sockcount--; debug("sockcount=%d", sockcount); @@ -3642,10 +3737,11 @@ recv_done(isc_task_t *task, isc_event_t *event) char buf2[ISC_SOCKADDR_FORMATSIZE]; isc_sockaddr_t any; - if (isc_sockaddr_pf(&query->sockaddr) == AF_INET) + if (isc_sockaddr_pf(&query->sockaddr) == AF_INET) { isc_sockaddr_any(&any); - else + } else { isc_sockaddr_any6(&any); + } /* * We don't expect a match when the packet is @@ -3685,8 +3781,9 @@ recv_done(isc_task_t *task, isc_event_t *event) : "ERROR", l->sendmsg->id, id); } - if (query->first_soa_rcvd) + if (query->first_soa_rcvd) { fail = false; + } query->warn_id = false; } else { dighost_warning("ERROR: short (< header size) " @@ -3715,8 +3812,9 @@ recv_done(isc_task_t *task, isc_event_t *event) dighost_warning("Warning: query response not set"); } - if (!match) + if (!match) { goto udp_mismatch; + } result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &msg); check_result(result, "dns_message_create"); @@ -3734,8 +3832,9 @@ recv_done(isc_task_t *task, isc_event_t *event) check_result(result, "dns_message_settsigkey"); msg->tsigctx = l->tsigctx; l->tsigctx = NULL; - if (l->msgcounter != 0) + if (l->msgcounter != 0) { msg->tcp_continuation = 1; + } l->msgcounter++; } @@ -3811,8 +3910,9 @@ recv_done(isc_task_t *task, isc_event_t *event) check_next_lookup(l); UNLOCK_LOOKUP; return; - } else + } else { goto udp_mismatch; + } } } if (msg->rcode == dns_rcode_badvers && msg->opt != NULL && @@ -3824,8 +3924,9 @@ recv_done(isc_task_t *task, isc_event_t *event) (unsigned int)newedns); l->edns = newedns; n = requeue_lookup(l, true); - if (l->trace && l->trace_root) + if (l->trace && l->trace_root) { n->rdtype = l->qrdtype; + } dns_message_destroy(&msg); isc_event_free(&event); clear_query(query); @@ -3836,13 +3937,15 @@ recv_done(isc_task_t *task, isc_event_t *event) } if ((msg->flags & DNS_MESSAGEFLAG_TC) != 0 && !l->ignore && !l->tcp_mode) { - if (l->cookie == NULL && l->sendcookie && msg->opt != NULL) + if (l->cookie == NULL && l->sendcookie && msg->opt != NULL) { process_opt(l, msg); + } dighost_comments(l, "Truncated, retrying in TCP mode."); n = requeue_lookup(l, true); n->tcp_mode = true; - if (l->trace && l->trace_root) + if (l->trace && l->trace_root) { n->rdtype = l->qrdtype; + } dns_message_destroy(&msg); isc_event_free(&event); clear_query(query); @@ -3859,11 +3962,13 @@ recv_done(isc_task_t *task, isc_event_t *event) l->seenbadcookie ? " in TCP mode" : ""); n = requeue_lookup(l, true); - if (l->seenbadcookie) + if (l->seenbadcookie) { n->tcp_mode = true; + } n->seenbadcookie = true; - if (l->trace && l->trace_root) + if (l->trace && l->trace_root) { n->rdtype = l->qrdtype; + } dns_message_destroy(&msg); isc_event_free(&event); clear_query(query); @@ -3878,14 +3983,16 @@ recv_done(isc_task_t *task, isc_event_t *event) (check_ra && (msg->flags & DNS_MESSAGEFLAG_RA) == 0 && l->recurse)) { dig_query_t *next = ISC_LIST_NEXT(query, link); - if (l->current_query == query) + if (l->current_query == query) { l->current_query = NULL; + } if (next != NULL) { debug("sending query %p\n", next); - if (l->tcp_mode) + if (l->tcp_mode) { send_tcp_connect(next); - else + } else { send_udp(next); + } } /* * If our query is at the head of the list and there @@ -3941,15 +4048,17 @@ recv_done(isc_task_t *task, isc_event_t *event) unsigned int local_timeout; if (timeout == 0) { - if (l->tcp_mode) + if (l->tcp_mode) { local_timeout = TCP_TIMEOUT * 4; - else + } else { local_timeout = UDP_TIMEOUT * 4; + } } else { - if (timeout < (INT_MAX / 4)) + if (timeout < (INT_MAX / 4)) { local_timeout = timeout * 4; - else + } else { local_timeout = INT_MAX; + } } debug("have local timeout of %d", local_timeout); isc_interval_set(&l->interval, local_timeout, 0); @@ -3987,21 +4096,25 @@ recv_done(isc_task_t *task, isc_event_t *event) int count = msg->counts[DNS_SECTION_ANSWER]; debug("in TRACE code"); - if (!l->ns_search_only) + if (!l->ns_search_only) { dighost_printmessage(query, &b, msg, true); + } l->rdtype = l->qrdtype; if (l->trace_root || (l->ns_search_only && count > 0)) { - if (!l->trace_root) + if (!l->trace_root) { l->rdtype = dns_rdatatype_soa; + } nl = followup_lookup(msg, query, DNS_SECTION_ANSWER); l->trace_root = false; - } else if (count == 0) + } else if (count == 0) { nl = followup_lookup(msg, query, DNS_SECTION_AUTHORITY); - if (nl == 0) + } + if (nl == 0) { docancel = true; + } } else { debug("in NSSEARCH code"); @@ -4014,8 +4127,9 @@ recv_done(isc_task_t *task, isc_event_t *event) l->rdtype = dns_rdatatype_soa; nl = followup_lookup(msg, query, DNS_SECTION_ANSWER); - if (nl == 0) + if (nl == 0) { docancel = true; + } l->trace_root = false; usesearch = false; } else { @@ -4024,8 +4138,9 @@ recv_done(isc_task_t *task, isc_event_t *event) } } - if (l->pending) + if (l->pending) { debug("still pending."); + } if (l->doing_xfr) { if (query != l->xfr_q) { dns_message_destroy(&msg); @@ -4034,8 +4149,9 @@ recv_done(isc_task_t *task, isc_event_t *event) UNLOCK_LOOKUP; return; } - if (!docancel) + if (!docancel) { docancel = check_for_more_data(query, msg, sevent); + } if (docancel) { dns_message_destroy(&msg); clear_query(query); @@ -4048,8 +4164,9 @@ recv_done(isc_task_t *task, isc_event_t *event) &sevent->address, query); } - if (!query->lookup->ns_search_only) + if (!query->lookup->ns_search_only) { query->lookup->pending = false; + } if (!query->lookup->ns_search_only || query->lookup->trace_root || docancel) { dns_message_destroy(&msg); @@ -4091,13 +4208,16 @@ get_address(char *host, in_port_t myport, isc_sockaddr_t *sockaddr) bool is_running; is_running = isc_app_isrunning(); - if (is_running) + if (is_running) { isc_app_block(); + } result = bind9_getaddresses(host, myport, sockaddr, 1, &count); - if (is_running) + if (is_running) { isc_app_unblock(); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } INSIST(count == 1); @@ -4116,12 +4236,14 @@ getaddresses(dig_lookup_t *lookup, const char *host, isc_result_t *resultp) result = bind9_getaddresses(host, 0, sockaddrs, DIG_MAX_ADDRESSES, &count); - if (resultp != NULL) + if (resultp != NULL) { *resultp = result; + } if (result != ISC_R_SUCCESS) { - if (resultp == NULL) + if (resultp == NULL) { fatal("couldn't get address for '%s': %s", host, isc_result_totext(result)); + } return (0); } @@ -4150,10 +4272,11 @@ do_lookup(dig_lookup_t *lookup) query = ISC_LIST_HEAD(lookup->q); if (query != NULL) { REQUIRE(DIG_VALID_QUERY(query)); - if (lookup->tcp_mode) + if (lookup->tcp_mode) { send_tcp_connect(query); - else + } else { send_udp(query); + } } } @@ -4194,22 +4317,24 @@ cancel_all(void) nq = ISC_LIST_NEXT(q, link); debug("canceling pending query %p, belonging to %p", q, current_lookup); - if (q->sock != NULL) + if (q->sock != NULL) { isc_socket_cancel(q->sock, NULL, ISC_SOCKCANCEL_ALL); - else + } else { clear_query(q); + } } for (q = ISC_LIST_HEAD(current_lookup->connecting); q != NULL; q = nq) { nq = ISC_LIST_NEXT(q, clink); debug("canceling connecting query %p, belonging to %p", q, current_lookup); - if (q->sock != NULL) + if (q->sock != NULL) { isc_socket_cancel(q->sock, NULL, ISC_SOCKCANCEL_ALL); - else + } else { clear_query(q); + } } } l = ISC_LIST_HEAD(lookup_list); @@ -4233,8 +4358,9 @@ destroy_libs(void) isc_result_t result; #endif /* HAVE_LIBIDN2 */ - if (keep != NULL) + if (keep != NULL) { isc_socket_detach(&keep); + } debug("destroy_libs()"); if (global_task != NULL) { debug("freeing task"); @@ -4284,8 +4410,9 @@ destroy_libs(void) debug("freeing key %p", tsigkey); dns_tsigkey_detach(&tsigkey); } - if (namebuf != NULL) + if (namebuf != NULL) { isc_buffer_free(&namebuf); + } if (is_dst_up) { debug("destroy DST lib"); @@ -4299,10 +4426,12 @@ destroy_libs(void) isc_log_destroy(&lctx); debug("Destroy memory"); - if (memdebugging != 0) + if (memdebugging != 0) { isc_mem_stats(mctx, stderr); - if (mctx != NULL) + } + if (mctx != NULL) { isc_mem_destroy(&mctx); + } } #ifdef HAVE_LIBIDN2 diff --git a/bin/dig/host.c b/bin/dig/host.c index 444e9bbeea..9f9e9176ea 100644 --- a/bin/dig/host.c +++ b/bin/dig/host.c @@ -18,7 +18,7 @@ #ifdef HAVE_LOCALE_H #include -#endif +#endif /* ifdef HAVE_LOCALE_H */ #include #include @@ -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(); diff --git a/bin/dig/include/dig/dig.h b/bin/dig/include/dig/dig.h index 05e038aa5d..4a6fe71b48 100644 --- a/bin/dig/include/dig/dig.h +++ b/bin/dig/include/dig/dig.h @@ -34,7 +34,7 @@ #ifdef __APPLE__ #include -#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 " message */ identify_previous_line, /*% Prepend a "Nameserver :" - 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 */ diff --git a/bin/dig/nslookup.c b/bin/dig/nslookup.c index f74a41f44c..dbd20d09c8 100644 --- a/bin/dig/nslookup.c +++ b/bin/dig/nslookup.c @@ -42,16 +42,16 @@ #include #if defined(HAVE_EDIT_READLINE_HISTORY_H) #include -#endif +#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */ #elif defined(HAVE_EDITLINE_READLINE_H) #include #elif defined(HAVE_READLINE_READLINE_H) #include #if defined(HAVE_READLINE_HISTORY_H) #include -#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(); diff --git a/bin/dnssec/dnssec-cds.c b/bin/dnssec/dnssec-cds.c index b92557ca6b..23fc55a560 100644 --- a/bin/dnssec/dnssec-cds.c +++ b/bin/dnssec/dnssec-cds.c @@ -55,7 +55,7 @@ #if USE_PKCS11 #include -#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; diff --git a/bin/dnssec/dnssec-dsfromkey.c b/bin/dnssec/dnssec-dsfromkey.c index 745fd22592..e80a1b4d75 100644 --- a/bin/dnssec/dnssec-dsfromkey.c +++ b/bin/dnssec/dnssec-dsfromkey.c @@ -43,7 +43,7 @@ #if USE_PKCS11 #include -#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(); diff --git a/bin/dnssec/dnssec-importkey.c b/bin/dnssec/dnssec-importkey.c index 42ecf5fc77..41f4767bf9 100644 --- a/bin/dnssec/dnssec-importkey.c +++ b/bin/dnssec/dnssec-importkey.c @@ -42,7 +42,7 @@ #if USE_PKCS11 #include -#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); + } } diff --git a/bin/dnssec/dnssec-keyfromlabel.c b/bin/dnssec/dnssec-keyfromlabel.c index 361f46bfa3..52835edc45 100644 --- a/bin/dnssec/dnssec-keyfromlabel.c +++ b/bin/dnssec/dnssec-keyfromlabel.c @@ -38,7 +38,7 @@ #if USE_PKCS11 #include -#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); } diff --git a/bin/dnssec/dnssec-keygen.c b/bin/dnssec/dnssec-keygen.c index 7af52a7563..fadb851bf2 100644 --- a/bin/dnssec/dnssec-keygen.c +++ b/bin/dnssec/dnssec-keygen.c @@ -59,7 +59,7 @@ #if USE_PKCS11 #include -#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 : KSK | REVOKE\n"); fprintf(stderr, " -g : 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); } diff --git a/bin/dnssec/dnssec-revoke.c b/bin/dnssec/dnssec-revoke.c index 4465e0b943..82968b6260 100644 --- a/bin/dnssec/dnssec-revoke.c +++ b/bin/dnssec/dnssec-revoke.c @@ -32,7 +32,7 @@ #if USE_PKCS11 #include -#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); diff --git a/bin/dnssec/dnssec-settime.c b/bin/dnssec/dnssec-settime.c index a8655c7876..55f70f84cc 100644 --- a/bin/dnssec/dnssec-settime.c +++ b/bin/dnssec/dnssec-settime.c @@ -35,7 +35,7 @@ #if USE_PKCS11 #include -#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); diff --git a/bin/dnssec/dnssec-signzone.c b/bin/dnssec/dnssec-signzone.c index 0d5391f80a..3cc5a5c341 100644 --- a/bin/dnssec/dnssec-signzone.c +++ b/bin/dnssec/dnssec-signzone.c @@ -83,7 +83,7 @@ #if USE_PKCS11 #include -#endif +#endif /* if USE_PKCS11 */ #include "dnssectool.h" @@ -213,8 +213,9 @@ dumpnode(dns_name_t *name, dns_dbnode_t *node) isc_result_t result; unsigned bufsize = 4096; - if (outputformat != dns_masterformat_text) + if (outputformat != dns_masterformat_text) { return; + } if (!output_dnssec_only) { result = dns_master_dumpnodetostream(mctx, gdb, gversion, node, @@ -246,8 +247,9 @@ dumpnode(dns_name_t *name, dns_dbnode_t *node) for (;;) { result = dns_master_rdatasettotext( name, &rds, masterstyle, NULL, buffer); - if (result != ISC_R_NOSPACE) + if (result != ISC_R_NOSPACE) { break; + } bufsize <<= 1; isc_buffer_free(&buffer); @@ -286,10 +288,11 @@ signwithkey(dns_name_t *name, dns_rdataset_t *rdataset, dst_key_t *key, dst_key_format(key, keystr, sizeof(keystr)); vbprintf(1, "\t%s %s\n", logmsg, keystr); - if (rdataset->type == dns_rdatatype_dnskey) + if (rdataset->type == dns_rdatatype_dnskey) { expiry = dnskey_endtime; - else + } else { expiry = endtime; + } jendtime = (jitter != 0) ? expiry - isc_random_uniform(jitter) : expiry; isc_buffer_init(&b, array, sizeof(array)); @@ -366,8 +369,9 @@ keythatsigned_unlocked(dns_rdata_rrsig_t *rrsig) key = ISC_LIST_NEXT(key, link)) { if (rrsig->keyid == dst_key_id(key->key) && rrsig->algorithm == dst_key_alg(key->key) && - dns_name_equal(&rrsig->signer, dst_key_name(key->key))) + dns_name_equal(&rrsig->signer, dst_key_name(key->key))) { return (key); + } } return (NULL); } @@ -386,8 +390,9 @@ keythatsigned(dns_rdata_rrsig_t *rrsig) isc_rwlock_lock(&keylist_lock, isc_rwlocktype_read); key = keythatsigned_unlocked(rrsig); isc_rwlock_unlock(&keylist_lock, isc_rwlocktype_read); - if (key != NULL) + if (key != NULL) { return (key); + } /* * We did not find the key in our list. Get a write lock now, since @@ -417,8 +422,9 @@ keythatsigned(dns_rdata_rrsig_t *rrsig) if (result == ISC_R_SUCCESS) { dst_key_free(&pubkey); result = dns_dnsseckey_create(mctx, &privkey, &key); - } else + } else { result = dns_dnsseckey_create(mctx, &pubkey, &key); + } if (result == ISC_R_SUCCESS) { key->force_publish = false; @@ -517,25 +523,29 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name, result = ISC_R_SUCCESS; nosigs = true; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed while looking for '%s RRSIG %s': %s", namestr, typestr, isc_result_totext(result)); + } vbprintf(1, "%s/%s:\n", namestr, typestr); arraysize = keycount; - if (!nosigs) + if (!nosigs) { arraysize += dns_rdataset_count(&sigset); + } wassignedby = isc_mem_get(mctx, arraysize * sizeof(bool)); nowsignedby = isc_mem_get(mctx, arraysize * sizeof(bool)); - for (i = 0; i < arraysize; i++) + for (i = 0; i < arraysize; i++) { wassignedby[i] = nowsignedby[i] = false; + } - if (nosigs) + if (nosigs) { result = ISC_R_NOMORE; - else + } else { result = dns_rdataset_first(&sigset); + } while (result == ISC_R_SUCCESS) { bool expired, future; @@ -550,10 +560,11 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name, key = keythatsigned(&rrsig); sig_format(&rrsig, sigstr, sizeof(sigstr)); - if (key != NULL && issigningkey(key)) + if (key != NULL && issigningkey(key)) { expired = isc_serial_gt(now + cycle, rrsig.timeexpire); - else + } else { expired = isc_serial_gt(now, rrsig.timeexpire); + } if (isc_serial_gt(rrsig.timesigned, rrsig.timeexpire)) { /* rrsig is dropped and not replaced */ @@ -621,8 +632,9 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name, } if (keep) { - if (key != NULL) + if (key != NULL) { nowsignedby[key->index] = true; + } INCSTAT(nretained); if (sigset.ttl != ttl) { vbprintf(2, "\tfixing ttl %s\n", sigstr); @@ -661,20 +673,24 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name, dns_rdata_freestruct(&rrsig); result = dns_rdataset_next(&sigset); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } check_result(result, "dns_rdataset_first/next"); - if (dns_rdataset_isassociated(&sigset)) + if (dns_rdataset_isassociated(&sigset)) { dns_rdataset_disassociate(&sigset); + } for (key = ISC_LIST_HEAD(keylist); key != NULL; key = ISC_LIST_NEXT(key, link)) { - if (nowsignedby[key->index]) + if (nowsignedby[key->index]) { continue; + } - if (!issigningkey(key)) + if (!issigningkey(key)) { continue; + } if ((set->type == dns_rdatatype_cds || set->type == dns_rdatatype_cdnskey || @@ -687,17 +703,21 @@ signset(dns_diff_t *del, dns_diff_t *add, dns_dbnode_t *node, dns_name_t *name, for (tmpkey = ISC_LIST_HEAD(keylist); tmpkey != NULL; tmpkey = ISC_LIST_NEXT(tmpkey, link)) { if (dst_key_alg(key->key) != - dst_key_alg(tmpkey->key)) + dst_key_alg(tmpkey->key)) { continue; - if (REVOKE(tmpkey->key)) + } + if (REVOKE(tmpkey->key)) { continue; - if (isksk(tmpkey)) + } + if (isksk(tmpkey)) { have_ksk = true; + } } if (isksk(key) || !have_ksk || - (iszsk(key) && !keyset_kskonly)) + (iszsk(key) && !keyset_kskonly)) { signwithkey(name, set, key->key, ttl, add, "signing with dnskey"); + } } else if (iszsk(key)) { signwithkey(name, set, key->key, ttl, add, "signing with dnskey"); @@ -724,8 +744,9 @@ hashlist_init(hashlist_t *l, unsigned int nodes, unsigned int length) if (nodes != 0) { l->size = nodes; l->hashbuf = malloc(l->size * l->length); - if (l->hashbuf == NULL) + if (l->hashbuf == NULL) { l->size = 0; + } } else { l->size = 0; l->hashbuf = NULL; @@ -752,8 +773,9 @@ hashlist_add(hashlist_t *l, const unsigned char *hash, size_t len) if (l->entries == l->size) { l->size = l->size * 2 + 100; l->hashbuf = realloc(l->hashbuf, l->size * l->length); - if (l->hashbuf == NULL) + if (l->hashbuf == NULL) { fatal("unable to grow hashlist: out of memory"); + } } memset(l->hashbuf + l->entries * l->length, 0, l->length); memmove(l->hashbuf + l->entries * l->length, hash, len); @@ -761,10 +783,10 @@ hashlist_add(hashlist_t *l, const unsigned char *hash, size_t len) } static void -hashlist_add_dns_name(hashlist_t *l, /*const*/ dns_name_t *name, - unsigned int hashalg, unsigned int iterations, - const unsigned char *salt, size_t salt_len, - bool speculative) +hashlist_add_dns_name(hashlist_t * l, + /*const*/ dns_name_t *name, unsigned int hashalg, + unsigned int iterations, const unsigned char *salt, + size_t salt_len, bool speculative) { char nametext[DNS_NAME_FORMATSIZE]; unsigned char hash[NSEC3_MAX_HASH_LENGTH + 1]; @@ -775,8 +797,9 @@ hashlist_add_dns_name(hashlist_t *l, /*const*/ dns_name_t *name, name->ndata, name->length); if (verbose) { dns_name_format(name, nametext, sizeof nametext); - for (i = 0; i < len; i++) + for (i = 0; i < len; i++) { fprintf(stderr, "%02x", hash[i]); + } fprintf(stderr, " %s\n", nametext); } hash[len++] = speculative ? 1 : 0; @@ -816,10 +839,12 @@ hashlist_hasdup(hashlist_t *l) current = next; while (entries-- > 1U) { next += l->length; - if (next[l->length - 1] != 0) + if (next[l->length - 1] != 0) { continue; - if (isc_safe_memequal(current, next, l->length - 1)) + } + if (isc_safe_memequal(current, next, l->length - 1)) { return (true); + } current = next; } return (false); @@ -835,12 +860,14 @@ hashlist_findnext(const hashlist_t * l, INSIST(next != NULL); do { - if (next < l->hashbuf + (l->entries - 1) * l->length) + if (next < l->hashbuf + (l->entries - 1) * l->length) { next += l->length; - else + } else { next = l->hashbuf; - if (next[l->length - 1] == 0) + } + if (next[l->length - 1] == 0) { break; + } } while (entries-- > 1U); INSIST(entries != 0U); return (next); @@ -850,16 +877,18 @@ static bool hashlist_exists(const hashlist_t * l, const unsigned char hash[NSEC3_MAX_HASH_LENGTH]) { - if (bsearch(hash, l->hashbuf, l->entries, l->length, hashlist_comp)) + if (bsearch(hash, l->hashbuf, l->entries, l->length, hashlist_comp)) { return (true); - else + } else { return (false); + } } static void -addnowildcardhash(hashlist_t *l, /*const*/ dns_name_t *name, - unsigned int hashalg, unsigned int iterations, - const unsigned char *salt, size_t salt_len) +addnowildcardhash(hashlist_t * l, + /*const*/ dns_name_t *name, unsigned int hashalg, + unsigned int iterations, const unsigned char *salt, + size_t salt_len) { dns_fixedname_t fixed; dns_name_t * wild; @@ -870,8 +899,9 @@ addnowildcardhash(hashlist_t *l, /*const*/ dns_name_t *name, wild = dns_fixedname_initname(&fixed); result = dns_name_concatenate(dns_wildcardname, name, wild, NULL); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { return; + } check_result(result, "addnowildcardhash: dns_name_concatenate()"); result = dns_db_findnode(gdb, wild, false, &node); @@ -900,14 +930,17 @@ opendb(const char *prefix, dns_name_t *name, dns_rdataclass_t rdclass, isc_buffer_init(&b, filename, sizeof(filename)); if (dsdir != NULL) { /* allow room for a trailing slash */ - if (strlen(dsdir) >= isc_buffer_availablelength(&b)) + if (strlen(dsdir) >= isc_buffer_availablelength(&b)) { fatal("path '%s' is too long", dsdir); + } isc_buffer_putstr(&b, dsdir); - if (dsdir[strlen(dsdir) - 1] != '/') + if (dsdir[strlen(dsdir) - 1] != '/') { isc_buffer_putstr(&b, "/"); + } } - if (strlen(prefix) > isc_buffer_availablelength(&b)) + if (strlen(prefix) > isc_buffer_availablelength(&b)) { fatal("path '%s' is too long", dsdir); + } isc_buffer_putstr(&b, prefix); result = dns_name_tofilenametext(name, false, &b); check_result(result, "dns_name_tofilenametext()"); @@ -923,8 +956,9 @@ opendb(const char *prefix, dns_name_t *name, dns_rdataclass_t rdclass, check_result(result, "dns_db_create()"); result = dns_db_load(*dbp, filename, inputformat, DNS_MASTER_HINT); - if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) + if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) { dns_db_detach(dbp); + } } /*% @@ -1027,14 +1061,16 @@ secure(dns_name_t *name, dns_dbnode_t *node) dns_rdataset_t dsset; isc_result_t result; - if (dns_name_equal(name, gorigin)) + if (dns_name_equal(name, gorigin)) { return (false); + } dns_rdataset_init(&dsset); result = dns_db_findrdataset(gdb, node, gversion, dns_rdatatype_ds, 0, 0, &dsset, NULL); - if (dns_rdataset_isassociated(&dsset)) + if (dns_rdataset_isassociated(&dsset)) { dns_rdataset_disassociate(&dsset); + } return (result == ISC_R_SUCCESS); } @@ -1046,15 +1082,17 @@ is_delegation(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *origin, dns_rdataset_t nsset; isc_result_t result; - if (dns_name_equal(name, origin)) + if (dns_name_equal(name, origin)) { return (false); + } dns_rdataset_init(&nsset); result = dns_db_findrdataset(db, node, ver, dns_rdatatype_ns, 0, 0, &nsset, NULL); if (dns_rdataset_isassociated(&nsset)) { - if (ttlp != NULL) + if (ttlp != NULL) { *ttlp = nsset.ttl; + } dns_rdataset_disassociate(&nsset); } @@ -1100,8 +1138,9 @@ signname(dns_dbnode_t *node, dns_name_t *name) /* * Determine if this is a delegation point. */ - if (is_delegation(gdb, gversion, gorigin, name, node, NULL)) + if (is_delegation(gdb, gversion, gorigin, name, node, NULL)) { isdelegation = true; + } /* * Now iterate through the rdatasets. @@ -1116,8 +1155,9 @@ signname(dns_dbnode_t *node, dns_name_t *name) dns_rdatasetiter_current(rdsiter, &rdataset); /* If this is a RRSIG set, skip it. */ - if (rdataset.type == dns_rdatatype_rrsig) + if (rdataset.type == dns_rdatatype_rrsig) { goto skip; + } /* * If this name is a delegation point, skip all records @@ -1126,8 +1166,9 @@ signname(dns_dbnode_t *node, dns_name_t *name) */ if (isdelegation) { if (rdataset.type != nsec_datatype && - rdataset.type != dns_rdatatype_ds) + rdataset.type != dns_rdatatype_ds) { goto skip; + } } else if (rdataset.type == dns_rdatatype_ds) { char namebuf[DNS_NAME_FORMATSIZE]; dns_name_format(name, namebuf, sizeof(namebuf)); @@ -1141,21 +1182,24 @@ signname(dns_dbnode_t *node, dns_name_t *name) dns_rdataset_disassociate(&rdataset); result = dns_rdatasetiter_next(rdsiter); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("rdataset iteration for name '%s' failed: %s", namestr, isc_result_totext(result)); + } dns_rdatasetiter_destroy(&rdsiter); result = dns_diff_applysilently(&del, gdb, gversion); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to delete SIGs at node '%s': %s", namestr, isc_result_totext(result)); + } result = dns_diff_applysilently(&add, gdb, gversion); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to add SIGs at node '%s': %s", namestr, isc_result_totext(result)); + } dns_diff_clear(&del); dns_diff_clear(&add); @@ -1185,17 +1229,20 @@ active_node(dns_dbnode_t *node) dns_rdatasetiter_current(rdsiter, &rdataset); if (rdataset.type != dns_rdatatype_nsec && rdataset.type != dns_rdatatype_nsec3 && - rdataset.type != dns_rdatatype_rrsig) + rdataset.type != dns_rdatatype_rrsig) { 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: %s", isc_result_totext(result)); + } if (!active && nsec_datatype == dns_rdatatype_nsec) { /*% @@ -1211,9 +1258,10 @@ active_node(dns_dbnode_t *node) check_result(result, "dns_db_deleterdataset()"); dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("rdataset iteration failed: %s", isc_result_totext(result)); + } } else { /* * Delete RRSIGs for types that no longer exist. @@ -1240,33 +1288,38 @@ active_node(dns_dbnode_t *node) "nsec/rrsig)"); continue; } - if (type != dns_rdatatype_rrsig) + if (type != dns_rdatatype_rrsig) { continue; + } found = false; for (result = dns_rdatasetiter_first(rdsiter2); !found && result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(rdsiter2)) { dns_rdatasetiter_current(rdsiter2, &rdataset); - if (rdataset.type == covers) + if (rdataset.type == covers) { found = true; + } dns_rdataset_disassociate(&rdataset); } if (!found) { - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("rdataset iteration failed: %s", isc_result_totext(result)); + } result = dns_db_deleterdataset( gdb, node, gversion, type, covers); check_result(result, "dns_db_deleterdataset(" "rrsig)"); } else if (result != ISC_R_NOMORE && - result != ISC_R_SUCCESS) + result != ISC_R_SUCCESS) { fatal("rdataset iteration failed: %s", isc_result_totext(result)); + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("rdataset iteration failed: %s", isc_result_totext(result)); + } dns_rdatasetiter_destroy(&rdsiter2); } dns_rdatasetiter_destroy(&rdsiter); @@ -1290,9 +1343,10 @@ get_soa_ttls(void) dns_rdataset_init(&soaset); result = dns_db_find(gdb, gorigin, gversion, dns_rdatatype_soa, 0, 0, NULL, name, &soaset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to find an SOA at the zone apex: %s", isc_result_totext(result)); + } result = dns_rdataset_first(&soaset); check_result(result, "dns_rdataset_first"); @@ -1319,15 +1373,17 @@ setsoaserial(uint32_t serial, dns_updatemethod_t method) uint32_t old_serial, new_serial; result = dns_db_getoriginnode(gdb, &node); - if (result != ISC_R_SUCCESS) - return result; + if (result != ISC_R_SUCCESS) { + return (result); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(gdb, node, gversion, dns_rdatatype_soa, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_rdataset_first(&rdataset); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -1345,8 +1401,9 @@ setsoaserial(uint32_t serial, dns_updatemethod_t method) } else { /* Increment SOA serial using RFC 1982 arithmetics */ new_serial = (old_serial + 1) & 0xFFFFFFFF; - if (new_serial == 0) + if (new_serial == 0) { new_serial = 1; + } } /* If the new serial is not likely to cause a zone transfer @@ -1356,29 +1413,34 @@ setsoaserial(uint32_t serial, dns_updatemethod_t method) * (2^(32-1))-1. Using u_int32_t arithmetic, we can do a single * comparison. (5 - 6 == (2^32)-1, not negative-one) */ - if (new_serial == old_serial || (new_serial - old_serial) > 0x7fffffffU) + if (new_serial == old_serial || + (new_serial - old_serial) > 0x7fffffffU) { fprintf(stderr, "%s: warning: Serial number not advanced, " "zone may not transfer\n", program); + } dns_soa_setserial(new_serial, &rdata); result = dns_db_deleterdataset(gdb, node, gversion, dns_rdatatype_soa, 0); check_result(result, "dns_db_deleterdataset"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_db_addrdataset(gdb, node, gversion, 0, &rdataset, 0, NULL); check_result(result, "dns_db_addrdataset"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } cleanup: dns_rdataset_disassociate(&rdataset); - if (node != NULL) + if (node != NULL) { dns_db_detachnode(gdb, &node); + } dns_rdata_reset(&rdata); return (result); @@ -1394,8 +1456,9 @@ cleannode(dns_db_t *db, dns_dbversion_t *dbversion, dns_dbnode_t *node) dns_rdataset_t set; isc_result_t result, dresult; - if (outputformat != dns_masterformat_text || !disable_zone_check) + if (outputformat != dns_masterformat_text || !disable_zone_check) { return; + } dns_rdataset_init(&set); result = dns_db_allrdatasets(db, node, dbversion, 0, &rdsiter); @@ -1418,9 +1481,10 @@ cleannode(dns_db_t *db, dns_dbversion_t *dbversion, dns_dbnode_t *node) check_result(dresult, "dns_db_deleterdataset"); } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("rdataset iteration failed: %s", isc_result_totext(result)); + } dns_rdatasetiter_destroy(&rdsiter); } @@ -1534,8 +1598,9 @@ assignwork(isc_task_t *task, isc_task_t *worker) dns_rdataset_init(&nsec); result = dns_db_findrdataset(gdb, node, gversion, nsec_datatype, 0, 0, &nsec, NULL); - if (dns_rdataset_isassociated(&nsec)) + if (dns_rdataset_isassociated(&nsec)) { dns_rdataset_disassociate(&nsec); + } if (result == ISC_R_SUCCESS) { found = true; } else if (nsec_datatype == dns_rdatatype_nsec3) { @@ -1568,9 +1633,10 @@ assignwork(isc_task_t *task, isc_task_t *worker) if (result == ISC_R_NOMORE) { atomic_store(&finished, true); break; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { fatal("failure iterating database: %s", isc_result_totext(result)); + } } if (!found) { ended++; @@ -1673,8 +1739,9 @@ add_ds(dns_name_t *name, dns_dbnode_t *node, uint32_t nsttl) NULL); check_result(result, "dns_db_addrdataset"); dns_rdataset_disassociate(&dsset); - if (dns_rdataset_isassociated(&sigdsset)) + if (dns_rdataset_isassociated(&sigdsset)) { dns_rdataset_disassociate(&sigdsset); + } } else if (dns_rdataset_isassociated(&sigdsset)) { result = dns_db_deleterdataset(gdb, node, gversion, dns_rdatatype_rrsig, @@ -1710,13 +1777,15 @@ remove_records(dns_dbnode_t *node, dns_rdatatype_t which, bool checknsec) dns_rdataset_disassociate(&rdataset); if (type == which || covers == which) { if (which == dns_rdatatype_nsec && checknsec && - !update_chain) + !update_chain) { fatal("Zone contains NSEC records. Use -u " "to update to NSEC3."); + } if (which == dns_rdatatype_nsec3param && checknsec && - !update_chain) + !update_chain) { fatal("Zone contains NSEC3 chains. Use -u " "to update to NSEC."); + } result = dns_db_deleterdataset(gdb, node, gversion, type, covers); check_result(result, "dns_db_deleterdataset()"); @@ -1748,17 +1817,20 @@ remove_sigs(dns_dbnode_t *node, bool delegation, dns_rdatatype_t which) covers = rdataset.covers; dns_rdataset_disassociate(&rdataset); - if (type != dns_rdatatype_rrsig) + if (type != dns_rdatatype_rrsig) { continue; + } if (which == 0 && delegation && (dns_rdatatype_atparent(covers) || (nsec_datatype == dns_rdatatype_nsec && - covers == nsec_datatype))) + covers == nsec_datatype))) { continue; + } - if (which != 0 && covers != which) + if (which != 0 && covers != which) { continue; + } result = dns_db_deleterdataset(gdb, node, gversion, type, covers); @@ -1831,10 +1903,11 @@ nsecify(void) */ if (!dns_name_issubdomain(name, gorigin)) { result = dns_dbiterator_next(dbiter); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { done = true; - else + } else { check_result(result, "dns_dbiterator_next()"); + } dns_db_detachnode(gdb, &node); continue; } @@ -1848,8 +1921,9 @@ nsecify(void) if (is_delegation(gdb, gversion, gorigin, name, node, &nsttl)) { zonecut = savezonecut(&fzonecut, name); remove_sigs(node, true, 0); - if (generateds) + if (generateds) { add_ds(name, node, nsttl); + } } else if (has_dname(gdb, gversion, node)) { zonecut = savezonecut(&fzonecut, name); } @@ -1883,9 +1957,10 @@ nsecify(void) if (result == ISC_R_NOMORE) { dns_name_clone(gorigin, nextname); done = true; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { fatal("iterating through the database failed: %s", isc_result_totext(result)); + } dns_dbiterator_pause(dbiter); result = dns_nsec_build(gdb, gversion, node, nextname, zone_soa_min_ttl); @@ -1940,14 +2015,16 @@ addnsec3param(const unsigned char *salt, size_t salt_len, */ result = dns_db_deleterdataset(gdb, node, gversion, dns_rdatatype_nsec3param, 0); - if (result == DNS_R_UNCHANGED) + if (result == DNS_R_UNCHANGED) { result = ISC_R_SUCCESS; + } check_result(result, "dddnsec3param: dns_db_deleterdataset()"); result = dns_db_addrdataset(gdb, node, gversion, 0, &rdataset, DNS_DBADD_MERGE, NULL); - if (result == DNS_R_UNCHANGED) + if (result == DNS_R_UNCHANGED) { result = ISC_R_SUCCESS; + } check_result(result, "addnsec3param: dns_db_addrdataset()"); dns_db_detachnode(gdb, &node); } @@ -1997,8 +2074,9 @@ addnsec3(dns_name_t *name, dns_dbnode_t *node, const unsigned char *salt, check_result(result, "addnsec3: dns_db_findnode()"); result = dns_db_addrdataset(gdb, nsec3node, gversion, 0, &rdataset, 0, NULL); - if (result == DNS_R_UNCHANGED) + if (result == DNS_R_UNCHANGED) { result = ISC_R_SUCCESS; + } check_result(result, "addnsec3: dns_db_addrdataset()"); dns_db_detachnode(gdb, &nsec3node); } @@ -2044,8 +2122,9 @@ nsec3clean(dns_name_t *name, dns_dbnode_t *node, unsigned int hashalg, */ isc_buffer_init(&target, hash, sizeof(hash) - 1); result = isc_base32hex_decoderegion(&label, &target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } hash[isc_buffer_usedlength(&target)] = 0; @@ -2060,8 +2139,9 @@ nsec3clean(dns_name_t *name, dns_dbnode_t *node, unsigned int hashalg, result = dns_db_findrdataset(gdb, node, gversion, dns_rdatatype_nsec3, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } /* * Delete any NSEC3 records which are not part of the current @@ -2076,13 +2156,15 @@ nsec3clean(dns_name_t *name, dns_dbnode_t *node, unsigned int hashalg, if (exists && nsec3.hash == hashalg && nsec3.iterations == iterations && nsec3.salt_length == salt_len && - isc_safe_memequal(nsec3.salt, salt, salt_len)) + isc_safe_memequal(nsec3.salt, salt, salt_len)) { continue; + } dns_rdatalist_init(&rdatalist); rdatalist.rdclass = rdata.rdclass; rdatalist.type = rdata.type; - if (set_maxttl) + if (set_maxttl) { rdatalist.ttl = ISC_MIN(rdataset.ttl, maxttl); + } dns_rdata_init(&delrdata); dns_rdata_clone(&rdata, &delrdata); ISC_LIST_APPEND(rdatalist.rdata, &delrdata, link); @@ -2091,23 +2173,27 @@ nsec3clean(dns_name_t *name, dns_dbnode_t *node, unsigned int hashalg, result = dns_db_subtractrdataset(gdb, node, gversion, &delrdataset, 0, NULL); dns_rdataset_disassociate(&delrdataset); - if (result != ISC_R_SUCCESS && result != DNS_R_NXRRSET) + if (result != ISC_R_SUCCESS && result != DNS_R_NXRRSET) { check_result(result, "dns_db_subtractrdataset(NSEC3)"); + } delete_rrsigs = true; } dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { check_result(result, "dns_rdataset_first/next"); + } - if (!delete_rrsigs) + if (!delete_rrsigs) { return; + } /* * Delete the NSEC3 RRSIGs */ result = dns_db_deleterdataset(gdb, node, gversion, dns_rdatatype_rrsig, dns_rdatatype_nsec3); - if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) + if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) { check_result(result, "dns_db_deleterdataset(RRSIG(NSEC3))"); + } } static void @@ -2204,13 +2290,15 @@ cleanup_zone(void) rrset_cleanup(name, &rdataset, &add, &del); dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("rdatasets iteration failed."); + } dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(gdb, &node); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { fatal("zone iteration failed."); + } result = dns_diff_applysilently(&del, gdb, gversion); check_result(result, "dns_diff_applysilently"); @@ -2264,10 +2352,11 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, */ if (!dns_name_issubdomain(name, gorigin)) { result = dns_dbiterator_next(dbiter); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { done = true; - else + } else { check_result(result, "dns_dbiterator_next()"); + } dns_db_detachnode(gdb, &node); continue; } @@ -2306,8 +2395,9 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, nextnode, &nsttl)) { zonecut = savezonecut(&fzonecut, nextname); remove_sigs(nextnode, true, 0); - if (generateds) + if (generateds) { add_ds(nextname, nextnode, nsttl); + } if (OPTOUT(nsec3flags) && !secure(nextname, nextnode)) { dns_db_detachnode(gdb, &nextnode); @@ -2323,9 +2413,10 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, if (result == ISC_R_NOMORE) { dns_name_copynf(gorigin, nextname); done = true; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { fatal("iterating through the database failed: %s", isc_result_totext(result)); + } dns_name_downcase(name, name, NULL); hashlist_add_dns_name(hashlist, name, hashalg, iterations, salt, salt_len, false); @@ -2362,8 +2453,9 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, * Check for duplicate hashes. If found the salt needs to * be changed. */ - if (hashlist_hasdup(hashlist)) + if (hashlist_hasdup(hashlist)) { fatal("Duplicate hash detected. Pick a different salt."); + } /* * Generate the nsec3 records. @@ -2406,10 +2498,11 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, */ if (!dns_name_issubdomain(name, gorigin)) { result = dns_dbiterator_next(dbiter); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { done = true; - else + } else { check_result(result, "dns_dbiterator_next()"); + } dns_db_detachnode(gdb, &node); continue; } @@ -2455,9 +2548,10 @@ nsec3ify(unsigned int hashalg, dns_iterations_t iterations, if (result == ISC_R_NOMORE) { dns_name_copynf(gorigin, nextname); done = true; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { fatal("iterating through the database failed: %s", isc_result_totext(result)); + } /* * We need to pause here to release the lock on the database. */ @@ -2498,18 +2592,20 @@ 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); check_result(result, "dns_db_create()"); result = dns_db_load(*db, file, inputformat, 0); - if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) + if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) { fatal("failed loading zone from '%s': %s", file, isc_result_totext(result)); + } } /*% @@ -2526,9 +2622,10 @@ loadzonekeys(bool preserve_keys, bool load_public) node = NULL; result = dns_db_findnode(gdb, gorigin, false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to find the zone's origin: %s", isc_result_totext(result)); + } dns_db_currentversion(gdb, ¤tversion); @@ -2540,8 +2637,9 @@ loadzonekeys(bool preserve_keys, bool load_public) result = dns_db_findrdataset(gdb, node, currentversion, dns_rdatatype_soa, 0, 0, &rdataset, &soasigs); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* Preserve the TTL of the DNSKEY RRset, if any */ dns_rdataset_disassociate(&rdataset); @@ -2549,8 +2647,9 @@ loadzonekeys(bool preserve_keys, bool load_public) dns_rdatatype_dnskey, 0, 0, &rdataset, &keysigs); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } if (set_keyttl && keyttl != rdataset.ttl) { fprintf(stderr, @@ -2568,17 +2667,21 @@ loadzonekeys(bool preserve_keys, bool load_public) result = dns_dnssec_keylistfromrdataset( gorigin, directory, mctx, &rdataset, &keysigs, &soasigs, preserve_keys, load_public, &keylist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to load the zone keys: %s", isc_result_totext(result)); + } cleanup: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (dns_rdataset_isassociated(&keysigs)) + } + if (dns_rdataset_isassociated(&keysigs)) { dns_rdataset_disassociate(&keysigs); - if (dns_rdataset_isassociated(&soasigs)) + } + if (dns_rdataset_isassociated(&soasigs)) { dns_rdataset_disassociate(&soasigs); + } dns_db_detachnode(gdb, &node); dns_db_closeversion(gdb, ¤tversion, false); } @@ -2596,23 +2699,27 @@ loadexplicitkeys(char *keyfiles[], int n, bool setksk) result = dst_key_fromnamedfile( keyfiles[i], directory, DST_TYPE_PUBLIC | DST_TYPE_PRIVATE, mctx, &newkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("cannot load dnskey %s: %s", keyfiles[i], isc_result_totext(result)); + } - if (!dns_name_equal(gorigin, dst_key_name(newkey))) + if (!dns_name_equal(gorigin, dst_key_name(newkey))) { fatal("key %s not at origin\n", keyfiles[i]); + } - if (!dst_key_isprivate(newkey)) + if (!dst_key_isprivate(newkey)) { fatal("cannot sign zone with non-private dnskey %s", keyfiles[i]); + } /* Skip any duplicates */ for (key = ISC_LIST_HEAD(keylist); key != NULL; key = ISC_LIST_NEXT(key, link)) { if (dst_key_id(key->key) == dst_key_id(newkey) && - dst_key_alg(key->key) == dst_key_alg(newkey)) + dst_key_alg(key->key) == dst_key_alg(newkey)) { break; + } } if (key == NULL) { @@ -2628,8 +2735,9 @@ loadexplicitkeys(char *keyfiles[], int n, bool setksk) key->force_publish = true; key->force_sign = true; - if (setksk) + if (setksk) { key->ksk = true; + } } } @@ -2756,17 +2864,19 @@ warnifallksk(dns_db_t *db) dns_db_currentversion(db, ¤tversion); result = dns_db_findnode(db, gorigin, false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to find the zone's origin: %s", isc_result_totext(result)); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, currentversion, dns_rdatatype_dnskey, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to find keys at the zone apex: %s", isc_result_totext(result)); + } result = dns_rdataset_first(&rdataset); check_result(result, "dns_rdataset_first"); while (result == ISC_R_SUCCESS) { @@ -2777,22 +2887,24 @@ warnifallksk(dns_db_t *db) if ((dnskey.flags & DNS_KEYFLAG_KSK) == 0) { have_non_ksk = true; result = ISC_R_NOMORE; - } else + } else { result = dns_rdataset_next(&rdataset); + } dns_rdata_freestruct(&dnskey); } dns_rdataset_disassociate(&rdataset); dns_db_detachnode(db, &node); dns_db_closeversion(db, ¤tversion, false); if (!have_non_ksk && !ignore_kskflag) { - if (disable_zone_check) + if (disable_zone_check) { fprintf(stderr, "%s: warning: No non-KSK DNSKEY found; " "supply a ZSK or use '-z'.\n", program); - else + } else { fatal("No non-KSK DNSKEY found; " "supply a ZSK or use '-z'."); + } } } @@ -2819,16 +2931,18 @@ set_nsec3params(bool update, bool set_salt, bool set_optout, bool set_iter) result = dns_db_getnsec3parameters(gdb, ver, &orig_hash, NULL, &orig_iter, orig_salt, &orig_saltlen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } nsec_datatype = dns_rdatatype_nsec3; if (!update && set_salt) { if (salt_length != orig_saltlen || - !isc_safe_memequal(saltbuf, orig_salt, salt_length)) + !isc_safe_memequal(saltbuf, orig_salt, salt_length)) { fatal("An NSEC3 chain exists with a different salt. " "Use -u to update it."); + } } else if (!set_salt) { salt_length = orig_saltlen; memmove(saltbuf, orig_salt, orig_saltlen); @@ -2836,11 +2950,13 @@ set_nsec3params(bool update, bool set_salt, bool set_optout, bool set_iter) } if (!update && set_iter) { - if (nsec3iter != orig_iter) + if (nsec3iter != orig_iter) { fatal("An NSEC3 chain exists with different " "iterations. Use -u to update it."); - } else if (!set_iter) + } + } else if (!set_iter) { nsec3iter = orig_iter; + } /* * Find an NSEC3 record to get the current OPTOUT value. @@ -2854,13 +2970,15 @@ set_nsec3params(bool update, bool set_salt, bool set_optout, bool set_iter) check_result(result, "dns_nsec3_hashname"); result = dns_db_findnsec3node(gdb, hashname, false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_db_findrdataset(gdb, node, ver, dns_rdatatype_nsec3, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_rdataset_first(&rdataset); check_result(result, "dns_rdataset_first"); @@ -2869,22 +2987,26 @@ set_nsec3params(bool update, bool set_salt, bool set_optout, bool set_iter) check_result(result, "dns_rdata_tostruct"); if (!update && set_optout) { - if (nsec3flags != nsec3.flags) + if (nsec3flags != nsec3.flags) { fatal("An NSEC3 chain exists with%s OPTOUT. " "Use -u -%s to %s it.", OPTOUT(nsec3.flags) ? "" : "out", OPTOUT(nsec3.flags) ? "AA" : "A", OPTOUT(nsec3.flags) ? "clear" : "set"); - } else if (!set_optout) + } + } else if (!set_optout) { nsec3flags = nsec3.flags; + } dns_rdata_freestruct(&nsec3); cleanup: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(gdb, &node); + } dns_db_closeversion(gdb, &ver, false); } @@ -2917,13 +3039,15 @@ writeset(const char *prefix, dns_rdatatype_t type) check_result(result, "dns_name_tofilenametext"); isc_buffer_putuint8(&namebuf, 0); filenamelen = strlen(prefix) + strlen(namestr) + 1; - if (dsdir != NULL) + if (dsdir != NULL) { filenamelen += strlen(dsdir) + 1; + } filename = isc_mem_get(mctx, filenamelen); - if (dsdir != NULL) + if (dsdir != NULL) { snprintf(filename, filenamelen, "%s/", dsdir); - else + } else { filename[0] = 0; + } strlcat(filename, prefix, filenamelen); strlcat(filename, namestr, filenamelen); @@ -2933,8 +3057,9 @@ writeset(const char *prefix, dns_rdatatype_t type) for (key = ISC_LIST_HEAD(keylist); key != NULL; key = ISC_LIST_NEXT(key, link)) { - if (REVOKE(key->key)) + if (REVOKE(key->key)) { continue; + } if (isksk(key)) { have_ksk = true; have_non_ksk = false; @@ -2944,17 +3069,21 @@ writeset(const char *prefix, dns_rdatatype_t type) } for (tmpkey = ISC_LIST_HEAD(keylist); tmpkey != NULL; tmpkey = ISC_LIST_NEXT(tmpkey, link)) { - if (dst_key_alg(key->key) != dst_key_alg(tmpkey->key)) + if (dst_key_alg(key->key) != dst_key_alg(tmpkey->key)) { continue; - if (REVOKE(tmpkey->key)) + } + if (REVOKE(tmpkey->key)) { continue; - if (isksk(tmpkey)) + } + if (isksk(tmpkey)) { have_ksk = true; - else + } else { have_non_ksk = true; + } } - if (have_ksk && have_non_ksk && !isksk(key)) + if (have_ksk && have_non_ksk && !isksk(key)) { continue; + } dns_rdata_init(&rdata); dns_rdata_init(&ds); isc_buffer_init(&b, keybuf, sizeof(keybuf)); @@ -2970,7 +3099,6 @@ writeset(const char *prefix, dns_rdatatype_t type) result = dns_difftuple_create(mctx, DNS_DIFFOP_ADDRESIGN, name, 0, &ds, &tuple); - } else { result = dns_difftuple_create( mctx, DNS_DIFFOP_ADDRESIGN, gorigin, @@ -3006,8 +3134,9 @@ print_time(FILE *fp) { time_t currenttime; - if (outputformat != dns_masterformat_text) + if (outputformat != dns_masterformat_text) { return; + } currenttime = time(NULL); fprintf(fp, "; File written on %s", ctime(¤ttime)); @@ -3016,8 +3145,9 @@ print_time(FILE *fp) static void print_version(FILE *fp) { - if (outputformat != dns_masterformat_text) + if (outputformat != dns_masterformat_text) { return; + } fprintf(fp, "; dnssec_signzone version " VERSION "\n"); } @@ -3088,9 +3218,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-P:\t"); fprintf(stderr, "disable post-sign verification\n"); fprintf(stderr, "\t-Q:\t"); @@ -3125,8 +3255,9 @@ usage(void) static void removetempfile(void) { - if (removefile) + if (removefile) { isc_file_remove(tempfile); + } } static void @@ -3207,16 +3338,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; @@ -3226,7 +3365,7 @@ main(int argc, char *argv[]) #ifdef _WIN32 InitSockets(); -#endif +#endif /* ifdef _WIN32 */ masterstyle = &dns_master_style_explicitttl; @@ -3236,7 +3375,7 @@ main(int argc, char *argv[]) #if USE_PKCS11 pk11_result_register(); -#endif +#endif /* if USE_PKCS11 */ dns_result_register(); isc_commandline_errprint = false; @@ -3262,10 +3401,11 @@ main(int argc, char *argv[]) case 'A': set_optout = true; - if (OPTOUT(nsec3flags)) + if (OPTOUT(nsec3flags)) { nsec3flags &= ~DNS_NSEC3FLAG_OPTOUT; - else + } else { nsec3flags |= DNS_NSEC3FLAG_OPTOUT; + } break; case 'a': @@ -3282,12 +3422,14 @@ main(int argc, char *argv[]) case 'd': dsdir = isc_commandline_argument; - if (strlen(dsdir) == 0U) + if (strlen(dsdir) == 0U) { fatal("DS directory must be non-empty string"); + } result = try_dir(dsdir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("cannot open directory %s: %s", dsdir, isc_result_totext(result)); + } break; case 'D': @@ -3304,8 +3446,9 @@ main(int argc, char *argv[]) case 'f': output = isc_commandline_argument; - if (strcmp(output, "-") == 0) + if (strcmp(output, "-") == 0) { output_stdout = true; + } break; case 'g': @@ -3315,10 +3458,12 @@ main(int argc, char *argv[]) case 'H': set_iter = true; nsec3iter = strtoul(isc_commandline_argument, &endp, 0); - if (*endp != '\0') + if (*endp != '\0') { fatal("iterations must be numeric"); - if (nsec3iter > 0xffffU) + } + if (nsec3iter > 0xffffU) { fatal("iterations too big"); + } break; case 'I': @@ -3328,16 +3473,18 @@ main(int argc, char *argv[]) case 'i': endp = NULL; cycle = strtol(isc_commandline_argument, &endp, 0); - if (*endp != '\0' || cycle < 0) + if (*endp != '\0' || cycle < 0) { fatal("cycle period must be numeric and " "positive"); + } break; case 'j': endp = NULL; jitter = strtol(isc_commandline_argument, &endp, 0); - if (*endp != '\0' || jitter < 0) + if (*endp != '\0' || jitter < 0) { fatal("jitter must be numeric and positive"); + } break; case 'K': @@ -3345,8 +3492,9 @@ main(int argc, char *argv[]) break; case 'k': - if (ndskeys == MAXDSKEYS) + if (ndskeys == MAXDSKEYS) { fatal("too many key-signing keys specified"); + } dskeyfile[ndskeys++] = isc_commandline_argument; break; @@ -3386,8 +3534,9 @@ main(int argc, char *argv[]) case 'n': endp = NULL; ntasks = strtol(isc_commandline_argument, &endp, 0); - if (*endp != '\0' || ntasks > INT32_MAX) + if (*endp != '\0' || ntasks > INT32_MAX) { fatal("number of cpus must be numeric"); + } break; case 'O': @@ -3447,8 +3596,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': @@ -3468,13 +3618,14 @@ main(int argc, char *argv[]) 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(); @@ -3484,8 +3635,9 @@ main(int argc, char *argv[]) version(program); case 'Z': /* Undocumented test options */ - if (!strcmp(isc_commandline_argument, "nonsecify")) + if (!strcmp(isc_commandline_argument, "nonsecify")) { nonsecify = true; + } break; default: @@ -3496,57 +3648,67 @@ 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); if (startstr != NULL) { starttime = strtotime(startstr, now, now, NULL); - } else + } else { starttime = now - 3600; /* Allow for some clock skew. */ + } - if (endstr != NULL) + if (endstr != NULL) { endtime = strtotime(endstr, now, starttime, NULL); - else + } else { endtime = starttime + (30 * 24 * 60 * 60); + } if (dnskey_endstr != NULL) { dnskey_endtime = strtotime(dnskey_endstr, now, starttime, NULL); - if (endstr != NULL && dnskey_endtime == endtime) + if (endstr != NULL && dnskey_endtime == endtime) { fprintf(stderr, "WARNING: -e and -X were both set, " "but have identical values.\n"); - } else + } + } else { dnskey_endtime = endtime; + } - if (cycle == -1) + if (cycle == -1) { cycle = (endtime - starttime) / 4; + } - if (ntasks == 0) + if (ntasks == 0) { ntasks = isc_os_ncpus() * 2; + } vbprintf(4, "using %d cpus\n", ntasks); rdclass = strtoclass(classname); - if (directory == NULL) + if (directory == NULL) { directory = "."; + } setup_logging(mctx, &log); argc -= isc_commandline_index; argv += isc_commandline_index; - if (argc < 1) + if (argc < 1) { usage(); + } file = argv[0]; argc -= 1; argv += 1; - if (origin == NULL) + if (origin == NULL) { origin = file; + } if (output == NULL) { size_t size; @@ -3557,18 +3719,19 @@ 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, "map") == 0) + } else if (strcasecmp(inputformatstr, "map") == 0) { inputformat = dns_masterformat_map; - 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 version " "ignored\n"); - } else + } else { fatal("unknown file format: %s", inputformatstr); + } } if (outputformatstr != NULL) { @@ -3591,32 +3754,37 @@ main(int argc, char *argv[]) fprintf(stderr, "unknown raw format version\n"); exit(1); } - } else + } else { fatal("unknown file format: %s", outputformatstr); + } } if (serialformatstr != NULL) { - if (strcasecmp(serialformatstr, "keep") == 0) + if (strcasecmp(serialformatstr, "keep") == 0) { serialformat = SOA_SERIAL_KEEP; - else if (strcasecmp(serialformatstr, "increment") == 0 || - strcasecmp(serialformatstr, "incr") == 0) + } else if (strcasecmp(serialformatstr, "increment") == 0 || + strcasecmp(serialformatstr, "incr") == 0) { serialformat = SOA_SERIAL_INCREMENT; - else if (strcasecmp(serialformatstr, "unixtime") == 0) + } else if (strcasecmp(serialformatstr, "unixtime") == 0) { serialformat = SOA_SERIAL_UNIXTIME; - else if (strcasecmp(serialformatstr, "date") == 0) + } else if (strcasecmp(serialformatstr, "date") == 0) { serialformat = SOA_SERIAL_DATE; - else + } else { fatal("unknown soa serial format: %s", serialformatstr); + } } - if (output_dnssec_only && outputformat != dns_masterformat_text) + if (output_dnssec_only && outputformat != dns_masterformat_text) { fatal("option -D can only be used with \"-O text\""); + } - if (output_dnssec_only && serialformat != SOA_SERIAL_KEEP) + if (output_dnssec_only && serialformat != SOA_SERIAL_KEEP) { fatal("option -D can only be used with \"-N keep\""); + } - if (output_dnssec_only && set_maxttl) + if (output_dnssec_only && set_maxttl) { fatal("option -D cannot be used with -M"); + } result = dns_master_stylecreate(&dsstyle, DNS_STYLEFLAG_NO_TTL, 0, 24, 0, 0, 0, 8, 0xffffffff, mctx); @@ -3637,17 +3805,19 @@ main(int argc, char *argv[]) keyttl = maxttl; } - if (!set_keyttl) + if (!set_keyttl) { keyttl = soa_ttl; + } /* * Check for any existing NSEC3 parameters in the zone, * and use them as defaults if -u was not specified. */ - if (update_chain && !set_optout && !set_iter && !set_salt) + if (update_chain && !set_optout && !set_iter && !set_salt) { nsec_datatype = dns_rdatatype_nsec; - else + } else { set_nsec3params(update_chain, set_salt, set_optout, set_iter); + } /* * We need to do this early on, as we start messing with the list @@ -3655,9 +3825,10 @@ main(int argc, char *argv[]) */ ISC_LIST_INIT(keylist); result = isc_rwlock_init(&keylist_lock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("could not initialize keylist_lock: %s", isc_result_totext(result)); + } /* * Fill keylist with: @@ -3693,13 +3864,14 @@ main(int argc, char *argv[]) } if (keycount == 0) { - if (disable_zone_check) + if (disable_zone_check) { fprintf(stderr, "%s: warning: No keys specified " "or found\n", program); - else + } else { fatal("No signing keys specified or found."); + } nokeys = true; } @@ -3713,23 +3885,25 @@ main(int argc, char *argv[]) hashlist_init(&hashlist, dns_db_nodecount(gdb) * 2, hash_length); result = dns_nsec_nseconly(gdb, gversion, &answer); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { fprintf(stderr, "%s: warning: NSEC3 generation " "requested with no DNSKEY; ignoring\n", program); - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { check_result(result, "dns_nsec_nseconly"); - else if (answer) + } else if (answer) { fatal("NSEC3 generation requested with " "NSEC-only DNSKEY"); + } result = dns_nsec3_maxiterations(gdb, NULL, mctx, &max); check_result(result, "dns_nsec3_maxiterations()"); - if (nsec3iter > max) + if (nsec3iter > max) { fatal("NSEC3 iterations too big for weakest DNSKEY " "strength. Maximum iterations allowed %u.", max); + } } else { hashlist_init(&hashlist, 0, 0); /* silence clang */ } @@ -3758,11 +3932,12 @@ main(int argc, char *argv[]) cleanup_zone(); if (!nonsecify) { - if (IS_NSEC3) + if (IS_NSEC3) { nsec3ify(dns_hash_sha1, nsec3iter, gsalt, salt_length, &hashlist); - else + } else { nsecify(); + } } if (!nokeys) { @@ -3774,8 +3949,9 @@ main(int argc, char *argv[]) if (output_stdout) { outfp = stdout; - if (outputformatstr == NULL) + if (outputformatstr == NULL) { masterstyle = &dns_master_style_full; + } } else { tempfilelen = strlen(output) + 20; tempfile = isc_mem_get(mctx, tempfilelen); @@ -3783,13 +3959,15 @@ main(int argc, char *argv[]) result = isc_file_mktemplate(output, tempfile, tempfilelen); check_result(result, "isc_file_mktemplate"); - if (outputformat == dns_masterformat_text) + if (outputformat == dns_masterformat_text) { result = isc_file_openunique(tempfile, &outfp); - else + } else { result = isc_file_bopenunique(tempfile, &outfp); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { fatal("failed to open temporary output file: %s", isc_result_totext(result)); + } removefile = true; setfatalcallback(&removetempfile); } @@ -3798,22 +3976,25 @@ main(int argc, char *argv[]) print_version(outfp); result = isc_taskmgr_create(mctx, ntasks, 0, NULL, &taskmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to create task manager: %s", isc_result_totext(result)); + } master = NULL; result = isc_task_create(taskmgr, 0, &master); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to create task: %s", isc_result_totext(result)); + } tasks = isc_mem_get(mctx, ntasks * sizeof(isc_task_t *)); for (i = 0; i < (int)ntasks; i++) { tasks[i] = NULL; result = isc_task_create(taskmgr, 0, &tasks[i]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to create task: %s", isc_result_totext(result)); + } } isc_mutex_init(&namelock); @@ -3833,20 +4014,22 @@ main(int argc, char *argv[]) for (i = 0; i < (int)ntasks; i++) { result = isc_app_onrun(mctx, master, startworker, tasks[i]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("failed to start task: %s", isc_result_totext(result)); + } } (void)isc_app_run(); if (!atomic_load(&finished)) { fatal("process aborted by user"); } - } else + } else { isc_task_detach(&master); + } atomic_store(&shuttingdown, true); - ; - for (i = 0; i < (int)ntasks; i++) + for (i = 0; i < (int)ntasks; i++) { isc_task_detach(&tasks[i]); + } isc_taskmgr_destroy(&taskmgr); isc_mem_put(mctx, tasks, ntasks * sizeof(isc_task_t *)); postsign(); @@ -3868,9 +4051,9 @@ main(int argc, char *argv[]) if (outputformat != dns_masterformat_text) { dns_masterrawheader_t header; dns_master_initrawheader(&header); - if (rawversion == 0U) + if (rawversion == 0U) { header.flags = DNS_MASTERRAW_COMPAT; - else if (snset) { + } else if (snset) { header.flags = DNS_MASTERRAW_SOURCESERIALSET; header.sourceserial = serialnum; } @@ -3881,8 +4064,9 @@ main(int argc, char *argv[]) } isc_mutex_destroy(&namelock); - if (printstats) + if (printstats) { isc_mutex_destroy(&statslock); + } if (!output_stdout) { result = isc_stdio_close(outfp); @@ -3912,18 +4096,21 @@ main(int argc, char *argv[]) dns_dnsseckey_destroy(mctx, &key); } - if (tempfilelen != 0) + if (tempfilelen != 0) { isc_mem_put(mctx, tempfile, tempfilelen); + } - if (free_output) + if (free_output) { isc_mem_free(mctx, output); + } dns_master_styledestroy(&dsstyle, mctx); 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(); @@ -3936,6 +4123,6 @@ main(int argc, char *argv[]) #ifdef _WIN32 DestroySockets(); -#endif +#endif /* ifdef _WIN32 */ return (vresult == ISC_R_SUCCESS ? 0 : 1); } diff --git a/bin/dnssec/dnssec-verify.c b/bin/dnssec/dnssec-verify.c index a2232baf34..a6e8388ec3 100644 --- a/bin/dnssec/dnssec-verify.c +++ b/bin/dnssec/dnssec-verify.c @@ -62,7 +62,7 @@ #if USE_PKCS11 #include -#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(); diff --git a/bin/dnssec/dnssectool.c b/bin/dnssec/dnssectool.c index b771e2be69..dd39f64684 100644 --- a/bin/dnssec/dnssectool.c +++ b/bin/dnssec/dnssectool.c @@ -21,7 +21,7 @@ #ifdef _WIN32 #include -#endif +#endif /* ifdef _WIN32 */ #include #include @@ -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 */ diff --git a/bin/dnssec/dnssectool.h b/bin/dnssec/dnssectool.h index bd60b12ba7..55c3dcd95b 100644 --- a/bin/dnssec/dnssectool.h +++ b/bin/dnssec/dnssectool.h @@ -108,6 +108,6 @@ void InitSockets(void); void DestroySockets(void); -#endif +#endif /* ifdef _WIN32 */ #endif /* DNSSEC_DNSSECTOOL_H */ diff --git a/bin/named/builtin.c b/bin/named/builtin.c index 93ee8878ee..b776b1accf 100644 --- a/bin/named/builtin.c +++ b/bin/named/builtin.c @@ -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); diff --git a/bin/named/config.c b/bin/named/config.c index 58a0a26c07..ce269faecf 100644 --- a/bin/named/config.c +++ b/bin/named/config.c @@ -51,7 +51,7 @@ options {\n\ #ifndef WIN32 " coresize default;\n\ datasize default;\n" -#endif +#endif /* ifndef WIN32 */ "\ # deallocate-on-exit ;\n\ # directory \n\ @@ -61,14 +61,14 @@ options {\n\ # fake-iquery ;\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 ;\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 ;\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 ;\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); } diff --git a/bin/named/control.c b/bin/named/control.c index 9af553eacb..53b2c109b1 100644 --- a/bin/named/control.c +++ b/bin/named/control.c @@ -33,7 +33,7 @@ #include #ifdef HAVE_LIBSCF #include -#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); } diff --git a/bin/named/controlconf.c b/bin/named/controlconf.c index 9752f58bd1..e2718131cb 100644 --- a/bin/named/controlconf.c +++ b/bin/named/controlconf.c @@ -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; diff --git a/bin/named/fuzz.c b/bin/named/fuzz.c index 84b0e332d4..69a005e0fd 100644 --- a/bin/named/fuzz.c +++ b/bin/named/fuzz.c @@ -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); } diff --git a/bin/named/geoip.c b/bin/named/geoip.c index 04814a6d70..97b91e05b3 100644 --- a/bin/named/geoip.c +++ b/bin/named/geoip.c @@ -13,7 +13,7 @@ #if defined(HAVE_GEOIP2) #include -#endif +#endif /* if defined(HAVE_GEOIP2) */ #include #include @@ -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 diff --git a/bin/named/include/dlz/dlz_dlopen_driver.h b/bin/named/include/dlz/dlz_dlopen_driver.h index 8e260cb122..7822b4102f 100644 --- a/bin/named/include/dlz/dlz_dlopen_driver.h +++ b/bin/named/include/dlz/dlz_dlopen_driver.h @@ -17,4 +17,4 @@ dlz_dlopen_init(isc_mem_t *mctx); void dlz_dlopen_clear(void); -#endif +#endif /* ifndef DLZ_DLOPEN_DRIVER_H */ diff --git a/bin/named/include/named/globals.h b/bin/named/include/named/globals.h index 1329b5039b..eb38625f44 100644 --- a/bin/named/include/named/globals.h +++ b/bin/named/include/named/globals.h @@ -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); diff --git a/bin/named/include/named/main.h b/bin/named/include/named/main.h index ff77ca9e6c..27b7624046 100644 --- a/bin/named/include/named/main.h +++ b/bin/named/include/named/main.h @@ -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 diff --git a/bin/named/include/named/server.h b/bin/named/include/named/server.h index 842e82ee6e..d27e8472c0 100644 --- a/bin/named/include/named/server.h +++ b/bin/named/include/named/server.h @@ -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; diff --git a/bin/named/include/named/smf_globals.h b/bin/named/include/named/smf_globals.h index bf3fa63da5..e7dba2bbef 100644 --- a/bin/named/include/named/smf_globals.h +++ b/bin/named/include/named/smf_globals.h @@ -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); diff --git a/bin/named/log.c b/bin/named/log.c index 0bb3068413..6d0ddb7bab 100644 --- a/bin/named/log.c +++ b/bin/named/log.c @@ -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: diff --git a/bin/named/logconf.c b/bin/named/logconf.c index 5a56539d78..8acf59f4b1 100644 --- a/bin/named/logconf.c +++ b/bin/named/logconf.c @@ -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); diff --git a/bin/named/main.c b/bin/named/main.c index 6a95f1e05d..f044689f55 100644 --- a/bin/named/main.c +++ b/bin/named/main.c @@ -47,13 +47,13 @@ #include #if USE_PKCS11 #include -#endif +#endif /* if USE_PKCS11 */ #include #ifdef HAVE_GPERFTOOLS_PROFILER #include -#endif +#endif /* ifdef HAVE_GPERFTOOLS_PROFILER */ #ifdef HAVE_JSON_C #include @@ -61,7 +61,7 @@ #ifdef HAVE_GEOIP2 #include -#endif +#endif /* ifdef HAVE_GEOIP2 */ /* * Defining NAMED_MAIN provides storage declarations (rather than extern) @@ -82,17 +82,17 @@ #include #ifdef HAVE_LIBSCF #include -#endif +#endif /* ifdef HAVE_LIBSCF */ #include #include #ifdef HAVE_LIBXML2 #include #include -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_ZLIB #include -#endif +#endif /* ifdef HAVE_ZLIB */ /* * Include header files for database drivers here. */ @@ -103,14 +103,14 @@ * Include contributed DLZ drivers if appropriate. */ #include -#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 \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); } diff --git a/bin/named/server.c b/bin/named/server.c index 546a0e6d05..cd0beff41d 100644 --- a/bin/named/server.c +++ b/bin/named/server.c @@ -123,7 +123,7 @@ #include #include -#endif +#endif /* ifdef HAVE_LIBSCF */ #ifdef HAVE_LMDB #include @@ -138,17 +138,17 @@ #ifndef SIZE_MAX #define SIZE_MAX ((size_t)-1) -#endif +#endif /* ifndef SIZE_MAX */ #ifndef SIZE_AS_PERCENT #define SIZE_AS_PERCENT ((size_t)-2) -#endif +#endif /* ifndef SIZE_AS_PERCENT */ #ifdef TUNE_LARGE #define RESOLVER_NTASKS 523 #define UDPBUFFERS 32768 #define EXCLBUFFERS 32768 -#else +#else /* ifdef TUNE_LARGE */ #define RESOLVER_NTASKS 31 #define UDPBUFFERS 1000 #define EXCLBUFFERS 4096 @@ -460,10 +460,10 @@ nzd_close(MDB_txn **txnp, bool commit); static isc_result_t nzd_count(dns_view_t *view, int *countp); -#else +#else /* ifdef HAVE_LMDB */ static isc_result_t nzf_append(dns_view_t *view, const cfg_obj_t *zconfig); -#endif +#endif /* ifdef HAVE_LMDB */ /*% * Configure a single view ACL at '*aclp'. Get its configuration from @@ -540,21 +540,25 @@ configure_view_sortlist(const cfg_obj_t *vconfig, const cfg_obj_t *config, const cfg_obj_t *aclobj = NULL; int i = 0; - if (*aclp != NULL) + if (*aclp != NULL) { dns_acl_detach(aclp); - if (vconfig != NULL) + } + if (vconfig != NULL) { maps[i++] = cfg_tuple_get(vconfig, "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] = NULL; (void)named_config_get(maps, "sortlist", &aclobj); - if (aclobj == NULL) + if (aclobj == NULL) { return (ISC_R_SUCCESS); + } /* * Use a nest level of 3 for the "top level" of the sortlist; @@ -584,34 +588,40 @@ configure_view_nametable(const cfg_obj_t *vconfig, const cfg_obj_t *config, const char * str; const cfg_obj_t * nameobj; - if (*rbtp != NULL) + if (*rbtp != NULL) { dns_rbt_destroy(rbtp); - if (vconfig != NULL) + } + if (vconfig != NULL) { maps[i++] = cfg_tuple_get(vconfig, "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] = NULL; (void)named_config_get(maps, confname, &obj); - if (obj == NULL) + if (obj == NULL) { /* * No value available. *rbtp == NULL. */ return (ISC_R_SUCCESS); + } if (conftuplename != NULL) { obj = cfg_tuple_get(obj, conftuplename); - if (cfg_obj_isvoid(obj)) + if (cfg_obj_isvoid(obj)) { return (ISC_R_SUCCESS); + } } result = dns_rbt_create(mctx, NULL, NULL, rbtp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } name = dns_fixedname_initname(&fixed); for (element = cfg_list_first(obj); element != NULL; @@ -995,15 +1005,18 @@ keyloaded(dns_view_t *view, const dns_name_t *name) dns_keynode_t * keynode = NULL; result = dns_view_getsecroots(view, &secroots); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } result = dns_keytable_find(secroots, name, &keynode); - if (keynode != NULL) + if (keynode != NULL) { dns_keytable_detachkeynode(secroots, &keynode); - if (secroots != NULL) + } + if (secroots != NULL) { dns_keytable_detach(&secroots); + } return (result == ISC_R_SUCCESS); } @@ -1154,15 +1167,15 @@ configure_view_dnsseckeys(dns_view_t *view, const cfg_obj_t *vconfig, obj = NULL; (void)named_config_get(maps, "managed-keys-directory", &obj); directory = (obj != NULL ? cfg_obj_asstring(obj) : NULL); - if (directory != NULL) + if (directory != NULL) { result = isc_file_isdirectory(directory); + } if (result != ISC_R_SUCCESS) { isc_log_write(named_g_lctx, DNS_LOGCATEGORY_SECURITY, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "invalid managed-keys-directory %s: %s", directory, isc_result_totext(result)); goto cleanup; - } else if (directory != NULL) { if (!isc_file_isdirwritable(directory)) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -1245,8 +1258,9 @@ get_view_querysource_dispatch(const cfg_obj_t **maps, int af, INSIST(isc_sockaddr_pf(&sa) == af); dscp = cfg_obj_getdscp(obj); - if (dscp != -1 && dscpp != NULL) + if (dscp != -1 && dscpp != NULL) { *dscpp = dscp; + } /* * If we don't support this address family, we're done! @@ -1262,8 +1276,9 @@ get_view_querysource_dispatch(const cfg_obj_t **maps, int af, INSIST(0); ISC_UNREACHABLE(); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } /* * Try to find a dispatcher that we can share. @@ -1314,8 +1329,9 @@ get_view_querysource_dispatch(const cfg_obj_t **maps, int af, isc_sockaddr_any6(&any); break; } - if (isc_sockaddr_equal(&sa, &any)) + if (isc_sockaddr_equal(&sa, &any)) { return (ISC_R_SUCCESS); + } isc_sockaddr_format(&sa, buf, sizeof(buf)); isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, @@ -1344,27 +1360,31 @@ configure_order(dns_order_t *order, const cfg_obj_t *ent) result = named_config_getclass(cfg_tuple_get(ent, "class"), dns_rdataclass_any, &rdclass); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = named_config_gettype(cfg_tuple_get(ent, "type"), dns_rdatatype_any, &rdtype); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } obj = cfg_tuple_get(ent, "name"); - if (cfg_obj_isstring(obj)) + if (cfg_obj_isstring(obj)) { str = cfg_obj_asstring(obj); - else + } else { str = "*"; + } addroot = (strcmp(str, "*") == 0); isc_buffer_constinit(&b, str, strlen(str)); isc_buffer_add(&b, strlen(str)); dns_fixedname_init(&fixed); result = dns_name_fromtext(dns_fixedname_name(&fixed), &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } obj = cfg_tuple_get(ent, "ordering"); INSIST(cfg_obj_isstring(obj)); @@ -1372,7 +1392,7 @@ configure_order(dns_order_t *order, const cfg_obj_t *ent) if (!strcasecmp(str, "fixed")) { #if DNS_RDATASET_FIXED mode = DNS_RDATASETATTR_FIXEDORDER; -#else +#else /* if DNS_RDATASET_FIXED */ mode = DNS_RDATASETATTR_CYCLIC; #endif /* DNS_RDATASET_FIXED */ } else if (!strcasecmp(str, "random")) { @@ -1394,8 +1414,9 @@ configure_order(dns_order_t *order, const cfg_obj_t *ent) if (addroot) { result = dns_order_add(order, dns_rootname, rdtype, rdclass, mode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (dns_order_add(order, dns_fixedname_name(&fixed), rdtype, @@ -1416,52 +1437,62 @@ configure_peer(const cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) peer = NULL; result = dns_peer_newprefix(mctx, &na, prefixlen, &peer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } obj = NULL; (void)cfg_map_get(cpeer, "bogus", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setbogus(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "provide-ixfr", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setprovideixfr(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "request-expire", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setrequestexpire(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "request-ixfr", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setrequestixfr(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "request-nsid", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setrequestnsid(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "send-cookie", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setsendcookie(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "edns", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setsupportedns(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "edns-udp-size", &obj); if (obj != NULL) { uint32_t udpsize = cfg_obj_asuint32(obj); - if (udpsize < 512U) + if (udpsize < 512U) { udpsize = 512U; - if (udpsize > 4096U) + } + if (udpsize > 4096U) { udpsize = 4096U; + } CHECK(dns_peer_setudpsize(peer, (uint16_t)udpsize)); } @@ -1469,8 +1500,9 @@ configure_peer(const cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) (void)cfg_map_get(cpeer, "edns-version", &obj); if (obj != NULL) { uint32_t ednsversion = cfg_obj_asuint32(obj); - if (ednsversion > 255U) + if (ednsversion > 255U) { ednsversion = 255U; + } CHECK(dns_peer_setednsversion(peer, (uint8_t)ednsversion)); } @@ -1478,10 +1510,12 @@ configure_peer(const cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) (void)cfg_map_get(cpeer, "max-udp-size", &obj); if (obj != NULL) { uint32_t udpsize = cfg_obj_asuint32(obj); - if (udpsize < 512U) + if (udpsize < 512U) { udpsize = 512U; - if (udpsize > 4096U) + } + if (udpsize > 4096U) { udpsize = 4096U; + } CHECK(dns_peer_setmaxudp(peer, (uint16_t)udpsize)); } @@ -1500,18 +1534,21 @@ configure_peer(const cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) obj = NULL; (void)cfg_map_get(cpeer, "tcp-only", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_setforcetcp(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "tcp-keepalive", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_settcpkeepalive(peer, cfg_obj_asboolean(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "transfers", &obj); - if (obj != NULL) + if (obj != NULL) { CHECK(dns_peer_settransfers(peer, cfg_obj_asuint32(obj))); + } obj = NULL; (void)cfg_map_get(cpeer, "transfer-format", &obj); @@ -1532,56 +1569,66 @@ configure_peer(const cfg_obj_t *cpeer, isc_mem_t *mctx, dns_peer_t **peerp) (void)cfg_map_get(cpeer, "keys", &obj); if (obj != NULL) { result = dns_peer_setkeybycharp(peer, cfg_obj_asstring(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } obj = NULL; - if (na.family == AF_INET) + if (na.family == AF_INET) { (void)cfg_map_get(cpeer, "transfer-source", &obj); - else + } else { (void)cfg_map_get(cpeer, "transfer-source-v6", &obj); + } if (obj != NULL) { result = dns_peer_settransfersource(peer, cfg_obj_assockaddr(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_peer_settransferdscp(peer, cfg_obj_getdscp(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } named_add_reserved_dispatch(named_g_server, cfg_obj_assockaddr(obj)); } obj = NULL; - if (na.family == AF_INET) + if (na.family == AF_INET) { (void)cfg_map_get(cpeer, "notify-source", &obj); - else + } else { (void)cfg_map_get(cpeer, "notify-source-v6", &obj); + } if (obj != NULL) { result = dns_peer_setnotifysource(peer, cfg_obj_assockaddr(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_peer_setnotifydscp(peer, cfg_obj_getdscp(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } named_add_reserved_dispatch(named_g_server, cfg_obj_assockaddr(obj)); } obj = NULL; - if (na.family == AF_INET) + if (na.family == AF_INET) { (void)cfg_map_get(cpeer, "query-source", &obj); - else + } else { (void)cfg_map_get(cpeer, "query-source-v6", &obj); + } if (obj != NULL) { result = dns_peer_setquerysource(peer, cfg_obj_assockaddr(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_peer_setquerydscp(peer, cfg_obj_getdscp(obj)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } named_add_reserved_dispatch(named_g_server, cfg_obj_assockaddr(obj)); } @@ -1608,19 +1655,21 @@ configure_dyndb(const cfg_obj_t *dyndb, isc_mem_t *mctx, library = cfg_obj_asstring(cfg_tuple_get(dyndb, "library")); obj = cfg_tuple_get(dyndb, "parameters"); - if (obj != NULL) + if (obj != NULL) { result = dns_dyndb_load(library, name, cfg_obj_asstring(obj), cfg_obj_file(obj), cfg_obj_line(obj), mctx, dctx); + } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "dynamic database '%s' configuration failed: %s", name, isc_result_totext(result)); + } return (result); } -#endif +#endif /* ifdef HAVE_DLOPEN */ static isc_result_t disable_algorithms(const cfg_obj_t *disabled, dns_resolver_t *resolver) @@ -1725,8 +1774,9 @@ on_disable_list(const cfg_obj_t *disablelist, dns_name_t *zonename) isc_buffer_add(&b, strlen(str)); result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (dns_name_equal(name, zonename)) + if (dns_name_equal(name, zonename)) { return (true); + } } return (false); } @@ -1748,17 +1798,18 @@ check_dbtype(dns_zone_t *zone, unsigned int dbtypec, const char **dbargv, if (argv[i] == NULL || strcmp(argv[i], dbargv[i]) != 0) { CHECK(ISC_R_FAILURE); - /* - * Check that there are not extra arguments. - */ + /* + * Check that there are not extra arguments. + */ } } /* * Check that there are not extra arguments. */ - if (i == dbtypec && argv[i] != NULL) + if (i == dbtypec && argv[i] != NULL) { result = ISC_R_FAILURE; + } cleanup: isc_mem_free(mctx, argv); @@ -1777,12 +1828,14 @@ setquerystats(dns_zone_t *zone, isc_mem_t *mctx, dns_zonestat_level_t level) if (level == dns_zonestat_full) { result = isc_stats_create(mctx, &zoneqrystats, ns_statscounter_max); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } dns_zone_setrequeststats(zone, zoneqrystats); - if (zoneqrystats != NULL) + if (zoneqrystats != NULL) { isc_stats_detach(&zoneqrystats); + } return (ISC_R_SUCCESS); } @@ -1796,8 +1849,9 @@ cachelist_find(named_cachelist_t *cachelist, const char *cachename, for (nsc = ISC_LIST_HEAD(*cachelist); nsc != NULL; nsc = ISC_LIST_NEXT(nsc, link)) { if (nsc->rdclass == rdclass && - strcmp(dns_cache_getname(nsc->cache), cachename) == 0) + strcmp(dns_cache_getname(nsc->cache), cachename) == 0) { return (nsc); + } } return (NULL); @@ -1830,8 +1884,9 @@ cache_sharable(dns_view_t *originview, dns_view_t *view, * If the cache cannot even reused for the same view, it cannot be * shared with other views. */ - if (!cache_reusable(originview, view, new_zero_no_soattl)) + if (!cache_reusable(originview, view, new_zero_no_soattl)) { return (false); + } /* * Check other cache related parameters that must be consistent among @@ -1856,8 +1911,9 @@ dlzconfigure_callback(dns_view_t *view, dns_dlzdb_t *dlzdb, dns_zone_t *zone) isc_result_t result; result = dns_zonemgr_managezone(named_g_server->zonemgr, zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_zone_setstats(zone, named_g_server->zonestats); return (named_zone_configure_writeable_dlz(dlzdb, zone, zclass, @@ -1904,10 +1960,12 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na, /* * Create the actual zone. */ - if (server != NULL) + if (server != NULL) { dns64_dbtype[2] = server; - if (contact != NULL) + } + if (contact != NULL) { dns64_dbtype[3] = contact; + } name = dns_fixedname_initname(&fixed); isc_buffer_constinit(&b, reverse, strlen(reverse)); isc_buffer_add(&b, strlen(reverse)); @@ -1920,10 +1978,12 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na, dns_zone_settype(zone, dns_zone_master); dns_zone_setstats(zone, named_g_server->zonestats); dns_zone_setdbtype(zone, dns64_dbtypec, dns64_dbtype); - if (view->queryacl != NULL) + if (view->queryacl != NULL) { dns_zone_setqueryacl(zone, view->queryacl); - if (view->queryonacl != NULL) + } + if (view->queryonacl != NULL) { dns_zone_setqueryonacl(zone, view->queryonacl); + } dns_zone_setdialup(zone, dns_dialuptype_no); dns_zone_setnotifytype(zone, dns_notifytype_no); dns_zone_setoption(zone, DNS_ZONEOPT_NOCHECKNS, true); @@ -1934,8 +1994,9 @@ dns64_reverse(dns_view_t *view, isc_mem_t *mctx, isc_netaddr_t *na, "dns64 reverse zone%s%s: %s", sep, viewname, reverse); cleanup: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -1971,8 +2032,9 @@ conf_dnsrps_sadd(conf_dnsrps_ctx_t *ctx, const char *p, ...) 1; va_end(args); - if (cur_len + new_len <= ctx->cstr_size) + if (cur_len + new_len <= ctx->cstr_size) { return (true); + } new_cstr_size = ((cur_len + new_len) / 256 + 1) * 256; new_cstr = isc_mem_get(ctx->mctx, new_cstr_size); @@ -2006,8 +2068,9 @@ conf_dnsrps_get(const cfg_obj_t **sub_obj, const cfg_obj_t **maps, if (cfg_obj_isvoid(*sub_obj)) { *sub_obj = NULL; if (maps != NULL && - ISC_R_SUCCESS != named_config_get(maps, name, sub_obj)) + ISC_R_SUCCESS != named_config_get(maps, name, sub_obj)) { *sub_obj = NULL; + } } return (true); } @@ -2022,10 +2085,12 @@ conf_dnsrps_yes_no(const cfg_obj_t *obj, const char *name, { const cfg_obj_t *sub_obj; - if (!conf_dnsrps_get(&sub_obj, NULL, obj, name, ctx)) + if (!conf_dnsrps_get(&sub_obj, NULL, obj, name, ctx)) { return; - if (sub_obj == NULL) + } + if (sub_obj == NULL) { return; + } if (ctx == NULL) { cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR, "\"%s\" without \"dnsrps-enable yes\"", name); @@ -2041,10 +2106,12 @@ conf_dnsrps_num(const cfg_obj_t *obj, const char *name, conf_dnsrps_ctx_t *ctx) { const cfg_obj_t *sub_obj; - if (!conf_dnsrps_get(&sub_obj, NULL, obj, name, ctx)) + if (!conf_dnsrps_get(&sub_obj, NULL, obj, name, ctx)) { return; - if (sub_obj == NULL) + } + if (sub_obj == NULL) { return; + } if (ctx == NULL) { cfg_obj_log(obj, named_g_lctx, ISC_LOG_ERROR, "\"%s\" without \"dnsrps-enable yes\"", name); @@ -2103,26 +2170,30 @@ conf_dnsrps(dns_view_t *view, const cfg_obj_t **maps, bool nsip_enabled, conf_dnsrps_num(zone_obj, "max-policy-ttl", &ctx); obj = cfg_tuple_get(rpz_obj, "nsip-enable"); if (!cfg_obj_isvoid(obj)) { - if (cfg_obj_asboolean(obj)) + if (cfg_obj_asboolean(obj)) { *nsip_on |= DNS_RPZ_ZBIT(rpz_num); - else + } else { *nsip_on &= ~DNS_RPZ_ZBIT(rpz_num); + } } on = ((*nsip_on & DNS_RPZ_ZBIT(rpz_num)) != 0); - if (nsip_enabled != on) + if (nsip_enabled != on) { conf_dnsrps_sadd(&ctx, on ? " nsip-enable yes " : " nsip-enable no "); + } obj = cfg_tuple_get(rpz_obj, "nsdname-enable"); if (!cfg_obj_isvoid(obj)) { - if (cfg_obj_asboolean(obj)) + if (cfg_obj_asboolean(obj)) { *nsdname_on |= DNS_RPZ_ZBIT(rpz_num); - else + } else { *nsdname_on &= ~DNS_RPZ_ZBIT(rpz_num); + } } on = ((*nsdname_on & DNS_RPZ_ZBIT(rpz_num)) != 0); - if (nsdname_enabled != on) + if (nsdname_enabled != on) { conf_dnsrps_sadd(&ctx, on ? " nsdname-enable yes " : " nsdname-enable no "); + } conf_dnsrps_sadd(&ctx, ";\n"); zone_element = cfg_list_next(zone_element); } @@ -2132,31 +2203,35 @@ conf_dnsrps(dns_view_t *view, const cfg_obj_t **maps, bool nsip_enabled, conf_dnsrps_num(rpz_obj, "min-ns-dots", &ctx); conf_dnsrps_yes_no(rpz_obj, "qname-wait-recurse", &ctx); conf_dnsrps_yes_no(rpz_obj, "break-dnssec", &ctx); - if (!nsip_enabled) + if (!nsip_enabled) { conf_dnsrps_sadd(&ctx, " nsip-enable no "); - if (!nsdname_enabled) + } + if (!nsdname_enabled) { conf_dnsrps_sadd(&ctx, " nsdname-enable no "); + } /* * Get the general dnsrpzd parameters from the response-policy * statement in the view and the general options. */ if (conf_dnsrps_get(&obj, maps, rpz_obj, "dnsrps-options", &ctx) && - obj != NULL) + obj != NULL) { conf_dnsrps_sadd(&ctx, " %s\n", cfg_obj_asstring(obj)); + } if (ctx.result == ISC_R_SUCCESS) { *rps_cstr = ctx.cstr; *rps_cstr_size = ctx.cstr_size; } else { - if (ctx.cstr != NULL) + if (ctx.cstr != NULL) { isc_mem_put(ctx.mctx, ctx.cstr, ctx.cstr_size); + } *rps_cstr = NULL; *rps_cstr_size = 0; } return (ctx.result); } -#endif +#endif /* ifdef USE_DNSRPS */ static isc_result_t configure_rpz_name(dns_view_t *view, const cfg_obj_t *obj, dns_name_t *name, @@ -2165,9 +2240,10 @@ configure_rpz_name(dns_view_t *view, const cfg_obj_t *obj, dns_name_t *name, isc_result_t result; result = dns_name_fromstring(name, str, DNS_NAME_DOWNCASE, view->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { cfg_obj_log(obj, named_g_lctx, DNS_RPZ_ERROR_LEVEL, "invalid %s '%s'", msg, str); + } return (result); } @@ -2179,9 +2255,10 @@ configure_rpz_name2(dns_view_t *view, const cfg_obj_t *obj, dns_name_t *name, result = dns_name_fromstring2(name, str, origin, DNS_NAME_DOWNCASE, view->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { cfg_obj_log(obj, named_g_lctx, DNS_RPZ_ERROR_LEVEL, "invalid zone '%s'", str); + } return (result); } @@ -2245,13 +2322,15 @@ configure_rpz_zone(dns_view_t *view, const cfg_listelt_t *element, zone->min_update_interval = minupdateinterval_default; } - if (*old_rpz_okp && zone->max_policy_ttl != old->max_policy_ttl) + if (*old_rpz_okp && zone->max_policy_ttl != old->max_policy_ttl) { *old_rpz_okp = false; + } str = cfg_obj_asstring(cfg_tuple_get(rpz_obj, "zone name")); result = configure_rpz_name(view, rpz_obj, &zone->origin, str, "zone"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (dns_name_equal(&zone->origin, dns_rootname)) { cfg_obj_log(rpz_obj, named_g_lctx, DNS_RPZ_ERROR_LEVEL, "invalid zone name '%s'", str); @@ -2270,43 +2349,51 @@ configure_rpz_zone(dns_view_t *view, const cfg_listelt_t *element, } } } - if (*old_rpz_okp && !dns_name_equal(&old->origin, &zone->origin)) + if (*old_rpz_okp && !dns_name_equal(&old->origin, &zone->origin)) { *old_rpz_okp = false; + } result = configure_rpz_name2(view, rpz_obj, &zone->client_ip, DNS_RPZ_CLIENT_IP_ZONE, &zone->origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = configure_rpz_name2(view, rpz_obj, &zone->ip, DNS_RPZ_IP_ZONE, &zone->origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = configure_rpz_name2(view, rpz_obj, &zone->nsdname, DNS_RPZ_NSDNAME_ZONE, &zone->origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = configure_rpz_name2(view, rpz_obj, &zone->nsip, DNS_RPZ_NSIP_ZONE, &zone->origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = configure_rpz_name(view, rpz_obj, &zone->passthru, DNS_RPZ_PASSTHRU_NAME, "name"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = configure_rpz_name(view, rpz_obj, &zone->drop, DNS_RPZ_DROP_NAME, "name"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = configure_rpz_name(view, rpz_obj, &zone->tcp_only, DNS_RPZ_TCP_ONLY_NAME, "name"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } obj = cfg_tuple_get(rpz_obj, "policy"); if (cfg_obj_isvoid(obj)) { @@ -2319,13 +2406,15 @@ configure_rpz_zone(dns_view_t *view, const cfg_listelt_t *element, str = cfg_obj_asstring(cfg_tuple_get(obj, "cname")); result = configure_rpz_name(view, rpz_obj, &zone->cname, str, "cname"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } } if (*old_rpz_okp && (zone->policy != old->policy || - !dns_name_equal(&old->cname, &zone->cname))) + !dns_name_equal(&old->cname, &zone->cname))) { *old_rpz_okp = false; + } obj = cfg_tuple_get(rpz_obj, "add-soa"); if (cfg_obj_isvoid(obj)) { @@ -2361,8 +2450,9 @@ configure_rpz(dns_view_t *view, const cfg_obj_t **maps, *old_rpz_okp = false; zone_element = cfg_list_first(cfg_tuple_get(rpz_obj, "zone list")); - if (zone_element == NULL) + if (zone_element == NULL) { return (ISC_R_SUCCESS); + } nsip_enabled = true; sub_obj = cfg_tuple_get(rpz_obj, "nsip-enable"); @@ -2401,7 +2491,7 @@ configure_rpz(dns_view_t *view, const cfg_obj_t **maps, " without `./configure --enable-dnsrps`"); return (ISC_R_FAILURE); } -#else +#else /* ifndef USE_DNSRPS */ if (dnsrps_enabled) { if (librpz == NULL) { cfg_obj_log(rpz_obj, named_g_lctx, DNS_RPZ_ERROR_LEVEL, @@ -2417,16 +2507,18 @@ configure_rpz(dns_view_t *view, const cfg_obj_t **maps, result = conf_dnsrps(view, maps, nsip_enabled, nsdname_enabled, &nsip_on, &nsdname_on, &rps_cstr, &rps_cstr_size, rpz_obj, zone_element); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } -#endif +#endif /* ifndef USE_DNSRPS */ result = dns_rpz_new_zones(&view->rpzs, rps_cstr, rps_cstr_size, view->mctx, named_g_taskmgr, named_g_timermgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } zones = view->rpzs; @@ -2455,34 +2547,39 @@ configure_rpz(dns_view_t *view, const cfg_obj_t **maps, } sub_obj = cfg_tuple_get(rpz_obj, "max-policy-ttl"); - if (cfg_obj_isduration(sub_obj)) + if (cfg_obj_isduration(sub_obj)) { ttl_default = cfg_obj_asduration(sub_obj); - else + } else { ttl_default = DNS_RPZ_MAX_TTL_DEFAULT; + } sub_obj = cfg_tuple_get(rpz_obj, "min-update-interval"); - if (cfg_obj_isduration(sub_obj)) + if (cfg_obj_isduration(sub_obj)) { minupdateinterval_default = cfg_obj_asduration(sub_obj); - else + } else { minupdateinterval_default = DNS_RPZ_MINUPDATEINTERVAL_DEFAULT; + } sub_obj = cfg_tuple_get(rpz_obj, "min-ns-dots"); - if (cfg_obj_isuint32(sub_obj)) + if (cfg_obj_isuint32(sub_obj)) { zones->p.min_ns_labels = cfg_obj_asuint32(sub_obj) + 1; - else + } else { zones->p.min_ns_labels = 2; + } sub_obj = cfg_tuple_get(rpz_obj, "qname-wait-recurse"); - if (cfg_obj_isvoid(sub_obj) || cfg_obj_asboolean(sub_obj)) + if (cfg_obj_isvoid(sub_obj) || cfg_obj_asboolean(sub_obj)) { zones->p.qname_wait_recurse = true; - else + } else { zones->p.qname_wait_recurse = false; + } sub_obj = cfg_tuple_get(rpz_obj, "nsip-wait-recurse"); - if (cfg_obj_isvoid(sub_obj) || cfg_obj_asboolean(sub_obj)) + if (cfg_obj_isvoid(sub_obj) || cfg_obj_asboolean(sub_obj)) { zones->p.nsip_wait_recurse = true; - else + } else { zones->p.nsip_wait_recurse = false; + } pview = NULL; result = dns_viewlist_find(&named_g_server->viewlist, view->name, @@ -2512,8 +2609,9 @@ configure_rpz(dns_view_t *view, const cfg_obj_t **maps, add_soa_default, ttl_default, minupdateinterval_default, old_zone, old_rpz_okp); if (result != ISC_R_SUCCESS) { - if (pview != NULL) + if (pview != NULL) { dns_view_detach(&pview); + } return (result); } } @@ -2617,7 +2715,6 @@ catz_addmodzone_taskaction(isc_task_t *task, isc_event_t *event0) } dns_zone_detach(&zone); } - } else { if (result == ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -2635,8 +2732,9 @@ catz_addmodzone_taskaction(isc_task_t *task, isc_event_t *event0) isc_result_totext(result), nameb); goto cleanup; } else { /* this can happen in case of DNS_R_PARTIALMATCH */ - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } } } RUNTIME_CHECK(zone == NULL); @@ -2662,8 +2760,9 @@ catz_addmodzone_taskaction(isc_task_t *task, isc_event_t *event0) goto cleanup; } CHECK(cfg_map_get(zoneconf, "zone", &zlist)); - if (!cfg_obj_islist(zlist)) + if (!cfg_obj_islist(zlist)) { CHECK(ISC_R_FAILURE); + } /* For now we only support adding one zone at a time */ zoneobj = cfg_listelt_value(cfg_list_first(zlist)); @@ -2721,10 +2820,12 @@ catz_addmodzone_taskaction(isc_task_t *task, isc_event_t *event0) dns_zone_set_parentcatz(zone, ev->origin); cleanup: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); - if (zoneconf != NULL) + } + if (zoneconf != NULL) { cfg_obj_destroy(cfg->add_parser, &zoneconf); + } dns_catz_entry_detach(ev->origin, &ev->entry); dns_catz_zone_detach(&ev->origin); dns_view_detach(&ev->view); @@ -2783,8 +2884,9 @@ catz_delzone_taskaction(isc_task_t *task, isc_event_t *event0) CHECK(dns_zt_unmount(ev->view->zonetable, zone)); file = dns_zone_getfile(zone); - if (file != NULL) + if (file != NULL) { isc_file_remove(file); + } isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING, @@ -2793,8 +2895,9 @@ catz_delzone_taskaction(isc_task_t *task, isc_event_t *event0) cname); cleanup: isc_task_endexclusive(task); - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } dns_catz_entry_detach(ev->origin, &ev->entry); dns_catz_zone_detach(&ev->origin); dns_view_detach(&ev->view); @@ -2887,8 +2990,9 @@ configure_catz_zone(dns_view_t *view, const cfg_obj_t *config, result = dns_name_fromstring(&origin, str, DNS_NAME_DOWNCASE, view->mctx); - if (result == ISC_R_SUCCESS && dns_name_equal(&origin, dns_rootname)) + if (result == ISC_R_SUCCESS && dns_name_equal(&origin, dns_rootname)) { result = DNS_R_EMPTYLABEL; + } if (result != ISC_R_SUCCESS) { cfg_obj_log(catz_obj, named_g_lctx, DNS_CATZ_ERROR_LEVEL, @@ -2965,13 +3069,15 @@ configure_catz_zone(dns_view_t *view, const cfg_obj_t *config, opts = dns_catz_zone_getdefoptions(zone); obj = cfg_tuple_get(catz_obj, "default-masters"); - if (obj != NULL && cfg_obj_istuple(obj)) + if (obj != NULL && cfg_obj_istuple(obj)) { result = named_config_getipandkeylist(config, obj, view->mctx, &opts->masters); + } obj = cfg_tuple_get(catz_obj, "in-memory"); - if (obj != NULL && cfg_obj_isboolean(obj)) + if (obj != NULL && cfg_obj_isboolean(obj)) { opts->in_memory = cfg_obj_asboolean(obj); + } obj = cfg_tuple_get(catz_obj, "zone-directory"); if (!opts->in_memory && obj != NULL && cfg_obj_isstring(obj)) { @@ -2988,12 +3094,14 @@ configure_catz_zone(dns_view_t *view, const cfg_obj_t *config, } obj = cfg_tuple_get(catz_obj, "min-update-interval"); - if (obj != NULL && cfg_obj_isduration(obj)) + if (obj != NULL && cfg_obj_isduration(obj)) { opts->min_update_interval = cfg_obj_asduration(obj); + } cleanup: - if (pview != NULL) + if (pview != NULL) { dns_view_detach(&pview); + } dns_name_free(&origin, view->mctx); return (result); @@ -3017,8 +3125,9 @@ configure_catz(dns_view_t *view, const cfg_obj_t *config, ns_catz_cbdata.server = named_g_server; zone_element = cfg_list_first(cfg_tuple_get(catz_obj, "zone list")); - if (zone_element == NULL) + if (zone_element == NULL) { return (ISC_R_SUCCESS); + } CHECK(dns_catz_new_zones(&view->catzs, &ns_catz_zonemodmethods, view->mctx, named_g_taskmgr, @@ -3026,8 +3135,9 @@ configure_catz(dns_view_t *view, const cfg_obj_t *config, result = dns_viewlist_find(&named_g_server->viewlist, view->name, view->rdclass, &pview); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { old = pview->catzs; + } if (old != NULL) { dns_catz_catzs_detach(&view->catzs); @@ -3040,14 +3150,16 @@ configure_catz(dns_view_t *view, const cfg_obj_t *config, zone_element = cfg_list_next(zone_element); } - if (old != NULL) + if (old != NULL) { dns_catz_postreconfig(view->catzs); + } result = ISC_R_SUCCESS; cleanup: - if (pview != NULL) + if (pview != NULL) { dns_view_detach(&pview); + } return (result); } @@ -3096,12 +3208,14 @@ configure_rrl(dns_view_t *view, const cfg_obj_t *config, const cfg_obj_t *map) result = cfg_map_get(map, "min-table-size", &obj); if (result == ISC_R_SUCCESS) { min_entries = cfg_obj_asuint32(obj); - if (min_entries < 1) + if (min_entries < 1) { min_entries = 1; + } } result = dns_rrl_init(&rrl, view, min_entries); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } i = ISC_MAX(20000, min_entries); obj = NULL; @@ -3158,10 +3272,11 @@ configure_rrl(dns_view_t *view, const cfg_obj_t *config, const cfg_obj_t *map) "invalid 'ipv4-prefix-length %d'%s", i, ""); } rrl->ipv4_prefixlen = i; - if (i == 32) + if (i == 32) { rrl->ipv4_mask = 0xffffffff; - else + } else { rrl->ipv4_mask = htonl(0xffffffff << (32 - i)); + } i = 56; obj = NULL; @@ -3196,10 +3311,11 @@ configure_rrl(dns_view_t *view, const cfg_obj_t *config, const cfg_obj_t *map) obj = NULL; result = cfg_map_get(map, "log-only", &obj); - if (result == ISC_R_SUCCESS && cfg_obj_asboolean(obj)) + if (result == ISC_R_SUCCESS && cfg_obj_asboolean(obj)) { rrl->log_only = true; - else + } else { rrl->log_only = false; + } return (ISC_R_SUCCESS); @@ -3234,8 +3350,9 @@ add_soa(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, 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); } @@ -3274,8 +3391,9 @@ add_ns(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, 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); } @@ -3322,8 +3440,9 @@ create_empty_zone(dns_zone_t *zone, dns_name_t *name, dns_view_t *view, str = cfg_obj_asstring(cfg_tuple_get(zconfig, "name")); CHECK(dns_name_fromstring(zname, str, 0, NULL)); namereln = dns_name_fullcompare(zname, name, &order, &nlabels); - if (namereln != dns_namereln_subdomain) + if (namereln != dns_namereln_subdomain) { continue; + } zoptions = cfg_tuple_get(zconfig, "options"); @@ -3333,21 +3452,24 @@ create_empty_zone(dns_zone_t *zone, dns_name_t *name, dns_view_t *view, strcasecmp(cfg_obj_asstring(obj), "forward") == 0) { obj = NULL; (void)cfg_map_get(zoptions, "forward", &obj); - if (obj == NULL) + if (obj == NULL) { continue; - if (strcasecmp(cfg_obj_asstring(obj), "only") != 0) + } + if (strcasecmp(cfg_obj_asstring(obj), "only") != 0) { continue; + } } if (db == NULL) { CHECK(dns_db_create(view->mctx, "rbt", name, dns_dbtype_zone, view->rdclass, 0, NULL, &db)); CHECK(dns_db_newversion(db, &version)); - if (strcmp(empty_dbtype[2], "@") == 0) + if (strcmp(empty_dbtype[2], "@") == 0) { dns_name_clone(name, ns); - else + } else { CHECK(dns_name_fromstring(ns, empty_dbtype[2], 0, NULL)); + } CHECK(dns_name_fromstring(contact, empty_dbtype[3], 0, NULL)); CHECK(add_soa(db, version, name, ns, contact)); @@ -3372,13 +3494,16 @@ create_empty_zone(dns_zone_t *zone, dns_name_t *name, dns_view_t *view, } result = check_dbtype(zone, typec, dbargv, view->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { zone = NULL; + } - if (zone != NULL && dns_zone_gettype(zone) != dns_zone_master) + if (zone != NULL && dns_zone_gettype(zone) != dns_zone_master) { zone = NULL; - if (zone != NULL && dns_zone_getfile(zone) != NULL) + } + if (zone != NULL && dns_zone_getfile(zone) != NULL) { zone = NULL; + } if (zone != NULL) { dns_zone_getraw(zone, &myzone); if (myzone != NULL) { @@ -3406,19 +3531,22 @@ create_empty_zone(dns_zone_t *zone, dns_name_t *name, dns_view_t *view, dns_zone_setnotifytype(zone, dns_notifytype_no); dns_zone_setdialup(zone, dns_dialuptype_no); dns_zone_setautomatic(zone, true); - if (view->queryacl != NULL) + if (view->queryacl != NULL) { dns_zone_setqueryacl(zone, view->queryacl); - else + } else { dns_zone_clearqueryacl(zone); - if (view->queryonacl != NULL) + } + if (view->queryonacl != NULL) { dns_zone_setqueryonacl(zone, view->queryonacl); - else + } else { dns_zone_clearqueryonacl(zone); + } dns_zone_clearupdateacl(zone); - if (view->transferacl != NULL) + if (view->transferacl != NULL) { dns_zone_setxfracl(zone, view->transferacl); - else + } else { dns_zone_clearxfracl(zone); + } CHECK(setquerystats(zone, view->mctx, statlevel)); if (db != NULL) { @@ -3439,12 +3567,15 @@ create_empty_zone(dns_zone_t *zone, dns_name_t *name, dns_view_t *view, "automatic empty zone%s%s: %s", sep, viewname, namebuf); cleanup: - if (myzone != NULL) + if (myzone != NULL) { dns_zone_detach(&myzone); - if (version != NULL) + } + if (version != NULL) { dns_db_closeversion(db, &version, false); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); + } INSIST(version == NULL); @@ -3465,8 +3596,9 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) struct fstrm_iothr_options *fopt = NULL; result = named_config_get(maps, "dnstap", &dlist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } for (element = cfg_list_first(dlist); element != NULL; element = cfg_list_next(element)) { @@ -3520,16 +3652,19 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) "'dnstap-output' must be set if 'dnstap' is set"); obj2 = cfg_tuple_get(obj, "mode"); - if (obj2 == NULL) + if (obj2 == NULL) { CHECKM(ISC_R_FAILURE, "dnstap-output mode not found"); - if (strcasecmp(cfg_obj_asstring(obj2), "file") == 0) + } + if (strcasecmp(cfg_obj_asstring(obj2), "file") == 0) { dmode = dns_dtmode_file; - else + } else { dmode = dns_dtmode_unix; + } obj2 = cfg_tuple_get(obj, "path"); - if (obj2 == NULL) + if (obj2 == NULL) { CHECKM(ISC_R_FAILURE, "dnstap-output path not found"); + } dpath = cfg_obj_asstring(obj2); @@ -3600,10 +3735,11 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) result = named_config_get(maps, "fstrm-set-output-queue-model", &obj); if (result == ISC_R_SUCCESS) { - if (strcasecmp(cfg_obj_asstring(obj), "spsc") == 0) + if (strcasecmp(cfg_obj_asstring(obj), "spsc") == 0) { i = FSTRM_IOTHR_QUEUE_MODEL_SPSC; - else + } else { i = FSTRM_IOTHR_QUEUE_MODEL_MPSC; + } fstrm_iothr_options_set_queue_model(fopt, i); } @@ -3633,8 +3769,9 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) "unable to set up dnstap logfile"); } - if (named_g_server->dtenv == NULL) + if (named_g_server->dtenv == NULL) { return (ISC_R_SUCCESS); + } obj = NULL; result = named_config_get(maps, "dnstap-version", &obj); @@ -3652,8 +3789,9 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) /* "hostname" is interpreted as boolean true */ char buf[256]; result = named_os_gethostname(buf, sizeof(buf)); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_dt_setidentity(named_g_server->dtenv, buf); + } } else if (result == ISC_R_SUCCESS && !cfg_obj_isvoid(obj)) { /* Quoted string */ dns_dt_setidentity(named_g_server->dtenv, @@ -3666,8 +3804,9 @@ configure_dnstap(const cfg_obj_t **maps, dns_view_t *view) result = ISC_R_SUCCESS; cleanup: - if (fopt != NULL) + if (fopt != NULL) { fstrm_iothr_options_destroy(&fopt); + } return (result); } @@ -3684,12 +3823,14 @@ create_mapped_acl(void) isc_netaddr_fromin6(&addr, &in6); result = dns_acl_create(named_g_mctx, 1, &acl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_iptable_addprefix(acl->iptable, &addr, 96, true); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_acl_attach(acl, &named_g_mapped); + } dns_acl_detach(&acl); return (result); } @@ -3733,7 +3874,7 @@ register_one_plugin(const cfg_obj_t *config, const cfg_obj_t *obj, return (result); } -#endif +#endif /* ifdef HAVE_DLOPEN */ /* * Configure 'view' according to 'vconfig', taking defaults from 'config' @@ -3807,8 +3948,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, REQUIRE(DNS_VIEW_VALID(view)); - if (config != NULL) + if (config != NULL) { (void)cfg_map_get(config, "options", &options); + } /* * maps: view options, options, defaults @@ -3829,8 +3971,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, maps[i++] = named_g_defaults; maps[i] = NULL; optionmaps[j] = NULL; - if (config != NULL) + if (config != NULL) { cfgmaps[k++] = config; + } cfgmaps[k] = NULL; /* @@ -3859,10 +4002,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, * Configure the zones. */ zonelist = NULL; - if (voptions != NULL) + if (voptions != NULL) { (void)cfg_map_get(voptions, "zone", &zonelist); - else + } else { (void)cfg_map_get(config, "zone", &zonelist); + } /* * Load zone configuration @@ -3913,10 +4057,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, * Create Dynamically Loadable Zone driver. */ dlzlist = NULL; - if (voptions != NULL) + if (voptions != NULL) { (void)cfg_map_get(voptions, "dlz", &dlzlist); - else + } else { (void)cfg_map_get(config, "dlz", &dlzlist); + } for (element = cfg_list_first(dlzlist); element != NULL; element = cfg_list_next(element)) { @@ -3947,8 +4092,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, &dlzdb); isc_mem_free(mctx, s); isc_mem_put(mctx, dlzargv, dlzargc * sizeof(*dlzargv)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * If the DLZ backend supports configuration, @@ -3961,8 +4107,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, dlzdb->search = true; result = dns_dlzconfigure( view, dlzdb, dlzconfigure_callback); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } ISC_LIST_APPEND(view->dlz_searched, dlzdb, link); } else { @@ -4059,17 +4206,19 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, myobj = NULL; result = named_config_get(maps, "dns64-server", &myobj); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { server = cfg_obj_asstring(myobj); - else + } else { server = NULL; + } myobj = NULL; result = named_config_get(maps, "dns64-contact", &myobj); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { contact = cfg_obj_asstring(myobj); - else + } else { contact = NULL; + } for (element = cfg_list_first(obj); element != NULL; element = cfg_list_next(element)) { @@ -4086,8 +4235,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, sp = &suffix; isc_netaddr_fromsockaddr( sp, cfg_obj_assockaddr(obj)); - } else + } else { sp = NULL; + } clients = mapped = excluded = NULL; obj = NULL; @@ -4096,8 +4246,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = cfg_acl_fromconfig(obj, config, named_g_lctx, actx, mctx, 0, &clients); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } obj = NULL; (void)cfg_map_get(map, "mapped", &obj); @@ -4105,8 +4256,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = cfg_acl_fromconfig(obj, config, named_g_lctx, actx, mctx, 0, &mapped); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } obj = NULL; (void)cfg_map_get(map, "exclude", &obj); @@ -4114,44 +4266,53 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = cfg_acl_fromconfig(obj, config, named_g_lctx, actx, mctx, 0, &excluded); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } else { if (named_g_mapped == NULL) { result = create_mapped_acl(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } dns_acl_attach(named_g_mapped, &excluded); } obj = NULL; (void)cfg_map_get(map, "recursive-only", &obj); - if (obj != NULL && cfg_obj_asboolean(obj)) + if (obj != NULL && cfg_obj_asboolean(obj)) { dns64options |= DNS_DNS64_RECURSIVE_ONLY; + } obj = NULL; (void)cfg_map_get(map, "break-dnssec", &obj); - if (obj != NULL && cfg_obj_asboolean(obj)) + if (obj != NULL && cfg_obj_asboolean(obj)) { dns64options |= DNS_DNS64_BREAK_DNSSEC; + } result = dns_dns64_create(mctx, &na, prefixlen, sp, clients, mapped, excluded, dns64options, &dns64); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_dns64_append(&view->dns64, dns64); view->dns64cnt++; result = dns64_reverse(view, mctx, &na, prefixlen, server, contact); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; - if (clients != NULL) + } + if (clients != NULL) { dns_acl_detach(&clients); - if (mapped != NULL) + } + if (mapped != NULL) { dns_acl_detach(&mapped); - if (excluded != NULL) + } + if (excluded != NULL) { dns_acl_detach(&excluded); + } } } @@ -4223,8 +4384,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, if (result == ISC_R_SUCCESS) { view->staleanswersok = pview->staleanswersok; dns_view_detach(&pview); - } else + } else { view->staleanswersok = dns_stale_answer_conf; + } /* * Configure the view's cache. @@ -4251,10 +4413,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, */ obj = NULL; result = named_config_get(maps, "attach-cache", &obj); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { cachename = cfg_obj_asstring(obj); - else + } else { cachename = view->name; + } cache = NULL; nsc = cachelist_find(cachelist, cachename, view->rdclass); if (nsc != NULL) { @@ -4275,8 +4438,10 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = dns_viewlist_find(&named_g_server->viewlist, cachename, view->rdclass, &pview); - if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) + if (result != ISC_R_NOTFOUND && + result != ISC_R_SUCCESS) { goto cleanup; + } if (pview != NULL) { if (!cache_reusable(pview, view, zero_no_soattl)) { @@ -4349,8 +4514,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "cache-file", &obj); if (result == ISC_R_SUCCESS && strcmp(view->name, "_bind") != 0) { CHECK(dns_cache_setfilename(cache, cfg_obj_asstring(obj))); - if (!reused_cache && !shared_cache) + if (!reused_cache && !shared_cache) { CHECK(dns_cache_load(cache)); + } } dns_cache_setcachesize(cache, max_cache_size); @@ -4387,8 +4553,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, dns_resstatscounter_max)); } dns_view_setresstats(view, resstats); - if (resquerystats == NULL) + if (resquerystats == NULL) { CHECK(dns_rdatatypestats_create(mctx, &resquerystats)); + } dns_view_setresquerystats(view, resquerystats); ndisp = 4 * ISC_MIN(named_g_udpdisp, MAX_UDP_DISPATCH); @@ -4397,14 +4564,18 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, named_g_socketmgr, named_g_timermgr, resopts, named_g_dispatchmgr, dispatch4, dispatch6)); - if (dscp4 == -1) + if (dscp4 == -1) { dscp4 = named_g_dscp; - if (dscp6 == -1) + } + if (dscp6 == -1) { dscp6 = named_g_dscp; - if (dscp4 != -1) + } + if (dscp4 != -1) { dns_resolver_setquerydscp4(view->resolver, dscp4); - if (dscp6 != -1) + } + if (dscp6 != -1) { dns_resolver_setquerydscp6(view->resolver, dscp6); + } /* * Set the ADB cache size to 1/8th of the max-cache-size or @@ -4413,8 +4584,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, max_adb_size = 0; if (max_cache_size != 0U) { max_adb_size = max_cache_size / 8; - if (max_adb_size == 0U) + if (max_adb_size == 0U) { max_adb_size = 1; /* Force minimum. */ + } if (view != nsc->primaryview && max_adb_size > MAX_ADB_SIZE_FOR_CACHESHARE) { max_adb_size = MAX_ADB_SIZE_FOR_CACHESHARE; @@ -4483,8 +4655,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "lame-ttl", &obj); INSIST(result == ISC_R_SUCCESS); lame_ttl = cfg_obj_asduration(obj); - if (lame_ttl > 1800) + if (lame_ttl > 1800) { lame_ttl = 1800; + } dns_resolver_setlamettl(view->resolver, lame_ttl); /* @@ -4506,10 +4679,12 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "edns-udp-size", &obj); INSIST(result == ISC_R_SUCCESS); udpsize = cfg_obj_asuint32(obj); - if (udpsize < 512) + if (udpsize < 512) { udpsize = 512; - if (udpsize > 4096) + } + if (udpsize > 4096) { udpsize = 4096; + } dns_resolver_setudpsize(view->resolver, (uint16_t)udpsize); /* @@ -4519,10 +4694,12 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "max-udp-size", &obj); INSIST(result == ISC_R_SUCCESS); udpsize = cfg_obj_asuint32(obj); - if (udpsize < 512) + if (udpsize < 512) { udpsize = 512; - if (udpsize > 4096) + } + if (udpsize > 4096) { udpsize = 4096; + } view->maxudp = udpsize; /* @@ -4532,10 +4709,12 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "nocookie-udp-size", &obj); INSIST(result == ISC_R_SUCCESS); udpsize = cfg_obj_asuint32(obj); - if (udpsize < 128) + if (udpsize < 128) { udpsize = 128; - if (udpsize > view->maxudp) + } + if (udpsize > view->maxudp) { udpsize = view->maxudp; + } view->nocookieudp = udpsize; /* @@ -4545,10 +4724,12 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "max-rsa-exponent-size", &obj); INSIST(result == ISC_R_SUCCESS); maxbits = cfg_obj_asuint32(obj); - if (maxbits != 0 && maxbits < 35) + if (maxbits != 0 && maxbits < 35) { maxbits = 35; - if (maxbits > 4096) + } + if (maxbits > 4096) { maxbits = 4096; + } view->maxbits = maxbits; /* @@ -4557,14 +4738,16 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, obj = NULL; CHECK(named_config_get(maps, "resolver-retry-interval", &obj)); resolver_param = cfg_obj_asuint32(obj); - if (resolver_param > 0) + if (resolver_param > 0) { dns_resolver_setretryinterval(view->resolver, resolver_param); + } obj = NULL; CHECK(named_config_get(maps, "resolver-nonbackoff-tries", &obj)); resolver_param = cfg_obj_asuint32(obj); - if (resolver_param > 0) + if (resolver_param > 0) { dns_resolver_setnonbackofftries(view->resolver, resolver_param); + } /* * Set supported DNSSEC algorithms. @@ -4574,9 +4757,10 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, (void)named_config_get(maps, "disable-algorithms", &disabled); if (disabled != NULL) { for (element = cfg_list_first(disabled); element != NULL; - element = cfg_list_next(element)) + element = cfg_list_next(element)) { CHECK(disable_algorithms(cfg_listelt_value(element), view->resolver)); + } } /* @@ -4587,9 +4771,10 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, (void)named_config_get(maps, "disable-ds-digests", &disabled); if (disabled != NULL) { for (element = cfg_list_first(disabled); element != NULL; - element = cfg_list_next(element)) + element = cfg_list_next(element)) { CHECK(disable_ds_digests(cfg_listelt_value(element), view->resolver)); + } } /* @@ -4600,23 +4785,26 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, forwarders = NULL; (void)named_config_get(maps, "forward", &forwardtype); (void)named_config_get(maps, "forwarders", &forwarders); - if (forwarders != NULL) + if (forwarders != NULL) { CHECK(configure_forward(config, view, dns_rootname, forwarders, forwardtype)); + } /* * Dual Stack Servers. */ alternates = NULL; (void)named_config_get(maps, "dual-stack-servers", &alternates); - if (alternates != NULL) + if (alternates != NULL) { CHECK(configure_alternates(config, view, alternates)); + } /* * We have default hints for class IN if we need them. */ - if (view->rdclass == dns_rdataclass_in && view->hints == NULL) + if (view->rdclass == dns_rdataclass_in && view->hints == NULL) { dns_view_sethints(view, named_g_server->in_roothints); + } /* * If we still have no hints, this is a non-IN view with no @@ -4632,11 +4820,12 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, dns_zone_detach(&rootzone); need_hints = false; } - if (need_hints) + if (need_hints) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING, "no root hints for view '%s'", view->name); + } } /* @@ -4655,16 +4844,19 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, */ result = dns_viewlist_find(&named_g_server->viewlist, view->name, view->rdclass, &pview); - if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) + if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) { goto cleanup; + } if (pview != NULL) { dns_view_getdynamickeyring(pview, &ring); - if (ring != NULL) + if (ring != NULL) { dns_view_setdynamickeyring(view, ring); + } dns_tsigkeyring_detach(&ring); dns_view_detach(&pview); - } else + } else { dns_view_restorekeyring(view); + } /* * Configure the view's peer list. @@ -4702,8 +4894,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(configure_order(order, ent)); } - if (view->order != NULL) + if (view->order != NULL) { dns_order_detach(&view->order); + } dns_order_attach(order, &view->order); dns_order_detach(&order); } @@ -4730,10 +4923,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, */ obj = NULL; (void)named_config_get(maps, "match-recursive-only", &obj); - if (obj != NULL && cfg_obj_asboolean(obj)) + if (obj != NULL && cfg_obj_asboolean(obj)) { view->matchrecursiveonly = true; - else + } else { view->matchrecursiveonly = false; + } /* * Configure other configurable data. @@ -4778,10 +4972,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "minimal-responses", &obj); INSIST(result == ISC_R_SUCCESS); if (cfg_obj_isboolean(obj)) { - if (cfg_obj_asboolean(obj)) + if (cfg_obj_asboolean(obj)) { view->minimalresponses = dns_minimal_yes; - else + } else { view->minimalresponses = dns_minimal_no; + } } else { str = cfg_obj_asstring(obj); if (strcasecmp(str, "no-auth") == 0) { @@ -5050,8 +5245,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, view->sendcookie = cfg_obj_asboolean(obj); obj = NULL; - if (view->pad_acl != NULL) + if (view->pad_acl != NULL) { dns_acl_detach(&view->pad_acl); + } result = named_config_get(optionmaps, "response-padding", &obj); if (result == ISC_R_SUCCESS) { const cfg_obj_t *padobj = cfg_tuple_get(obj, "block-size"); @@ -5130,8 +5326,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, trigger = cfg_tuple_get(obj, "trigger"); view->prefetch_trigger = cfg_obj_asuint32(trigger); - if (view->prefetch_trigger > 10) + if (view->prefetch_trigger > 10) { view->prefetch_trigger = 10; + } eligible = cfg_tuple_get(obj, "eligible"); if (cfg_obj_isvoid(eligible)) { int m; @@ -5141,14 +5338,16 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, &obj); INSIST(result == ISC_R_SUCCESS); eligible = cfg_tuple_get(obj, "eligible"); - if (cfg_obj_isuint32(eligible)) + if (cfg_obj_isuint32(eligible)) { break; + } } INSIST(cfg_obj_isuint32(eligible)); } view->prefetch_eligible = cfg_obj_asuint32(eligible); - if (view->prefetch_eligible < view->prefetch_trigger + 6) + if (view->prefetch_eligible < view->prefetch_trigger + 6) { view->prefetch_eligible = view->prefetch_trigger + 6; + } } /* @@ -5160,8 +5359,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, dns_resolver_resetmustbesecure(view->resolver); obj = NULL; result = named_config_get(maps, "dnssec-must-be-secure", &obj); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { CHECK(mustbesecure(obj, view->resolver)); + } obj = NULL; result = named_config_get(maps, "nta-recheck", &obj); @@ -5177,19 +5377,22 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "preferred-glue", &obj); if (result == ISC_R_SUCCESS) { str = cfg_obj_asstring(obj); - if (strcasecmp(str, "a") == 0) + if (strcasecmp(str, "a") == 0) { view->preferred_glue = dns_rdatatype_a; - else if (strcasecmp(str, "aaaa") == 0) + } else if (strcasecmp(str, "aaaa") == 0) { view->preferred_glue = dns_rdatatype_aaaa; - else + } else { view->preferred_glue = 0; - } else + } + } else { view->preferred_glue = 0; + } obj = NULL; result = named_config_get(maps, "root-delegation-only", &obj); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_view_setrootdelonly(view, true); + } if (result == ISC_R_SUCCESS && !cfg_obj_isvoid(obj)) { const cfg_obj_t *exclude; dns_fixedname_t fixed; @@ -5203,8 +5406,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, name, cfg_obj_asstring(exclude), 0, NULL)); CHECK(dns_view_excludedelegationonly(view, name)); } - } else + } else { dns_view_setrootdelonly(view, false); + } /* * Load DynDB modules. @@ -5231,7 +5435,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(configure_dyndb(dyndb, mctx, dctx)); } -#endif +#endif /* ifdef HAVE_DLOPEN */ /* * Load plugins. @@ -5256,7 +5460,7 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(cfg_pluginlist_foreach(config, plugin_list, named_g_lctx, register_one_plugin, view)); } -#endif +#endif /* ifdef HAVE_DLOPEN */ /* * Setup automatic empty zones. If recursion is off then @@ -5269,10 +5473,11 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, view->rdclass == dns_rdataclass_in) { empty_zones_enable = view->recursion; } else if (view->rdclass == dns_rdataclass_in) { - if (obj != NULL) + if (obj != NULL) { empty_zones_enable = cfg_obj_asboolean(obj); - else + } else { empty_zones_enable = view->recursion; + } } else { empty_zones_enable = false; } @@ -5301,8 +5506,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(dns_name_totext(name, false, &buffer)); server[isc_buffer_usedlength(&buffer)] = 0; empty_dbtype[2] = server; - } else + } else { empty_dbtype[2] = "@"; + } obj = NULL; result = named_config_get(maps, "empty-contact", &obj); @@ -5313,17 +5519,19 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(dns_name_totext(name, false, &buffer)); contact[isc_buffer_usedlength(&buffer)] = 0; empty_dbtype[3] = contact; - } else + } else { empty_dbtype[3] = "."; + } obj = NULL; result = named_config_get(maps, "zone-statistics", &obj); INSIST(result == ISC_R_SUCCESS); 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) { @@ -5347,8 +5555,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, */ CHECK(dns_name_fromstring(name, empty, 0, NULL)); if (disablelist != NULL && - on_disable_list(disablelist, name)) + on_disable_list(disablelist, name)) { continue; + } /* * This zone already exists. @@ -5366,8 +5575,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = dns_fwdtable_find(view->fwdtable, name, NULL, &dnsforwarders); if (result == ISC_R_SUCCESS && - dnsforwarders->fwdpolicy == dns_fwdpolicy_only) + dnsforwarders->fwdpolicy == dns_fwdpolicy_only) { continue; + } /* * See if we can re-use a existing zone. @@ -5375,8 +5585,10 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = dns_viewlist_find(&named_g_server->viewlist, view->name, view->rdclass, &pview); - if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) + if (result != ISC_R_NOTFOUND && + result != ISC_R_SUCCESS) { goto cleanup; + } if (pview != NULL) { (void)dns_view_findzone(pview, name, &zone); @@ -5386,8 +5598,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, CHECK(create_empty_zone(zone, name, view, zonelist, empty_dbtype, empty_dbtypec, statlevel)); - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } } } @@ -5395,8 +5608,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "rate-limit", &obj); if (result == ISC_R_SUCCESS) { result = configure_rrl(view, config, obj); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } /* @@ -5406,8 +5620,9 @@ configure_view(dns_view_t *view, dns_viewlist_t *viewlist, cfg_obj_t *config, result = named_config_get(maps, "servfail-ttl", &obj); INSIST(result == ISC_R_SUCCESS); fail_ttl = cfg_obj_asduration(obj); - if (fail_ttl > 30) + if (fail_ttl > 30) { fail_ttl = 30; + } dns_view_setfailttl(view, fail_ttl); /* @@ -5553,8 +5768,9 @@ configure_alternates(const cfg_obj_t *config, dns_view_t *view, } addresses = NULL; - if (alternates != NULL) + if (alternates != NULL) { addresses = cfg_tuple_get(alternates, "addresses"); + } for (element = cfg_list_first(addresses); element != NULL; element = cfg_list_next(element)) { @@ -5594,8 +5810,9 @@ configure_alternates(const cfg_obj_t *config, dns_view_t *view, } sa = *cfg_obj_assockaddr(alternate); - if (isc_sockaddr_getport(&sa) == 0) + if (isc_sockaddr_getport(&sa) == 0) { isc_sockaddr_setport(&sa, port); + } CHECK(dns_resolver_addalternate(view->resolver, &sa, NULL, 0)); } @@ -5658,28 +5875,32 @@ configure_forward(const cfg_obj_t *config, dns_view_t *view, } faddresses = NULL; - if (forwarders != NULL) + if (forwarders != NULL) { faddresses = cfg_tuple_get(forwarders, "addresses"); + } for (element = cfg_list_first(faddresses); element != NULL; element = cfg_list_next(element)) { const cfg_obj_t *forwarder = cfg_listelt_value(element); fwd = isc_mem_get(view->mctx, sizeof(dns_forwarder_t)); fwd->addr = *cfg_obj_assockaddr(forwarder); - if (isc_sockaddr_getport(&fwd->addr) == 0) + if (isc_sockaddr_getport(&fwd->addr) == 0) { isc_sockaddr_setport(&fwd->addr, port); + } fwd->dscp = cfg_obj_getdscp(forwarder); - if (fwd->dscp == -1) + if (fwd->dscp == -1) { fwd->dscp = dscp; + } ISC_LINK_INIT(fwd, link); ISC_LIST_APPEND(fwdlist, fwd, link); } if (ISC_LIST_EMPTY(fwdlist)) { - if (forwardtype != NULL) + if (forwardtype != NULL) { cfg_obj_log(forwardtype, named_g_lctx, ISC_LOG_WARNING, "no forwarders seen; disabling " "forwarding"); + } fwdpolicy = dns_fwdpolicy_none; } else { if (forwardtype == NULL) { @@ -5773,12 +5994,14 @@ find_view(const cfg_obj_t *vconfig, dns_viewlist_t *viewlist, dns_view_t * view = NULL; result = get_viewinfo(vconfig, &viewname, &viewclass); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_viewlist_find(viewlist, viewname, viewclass, &view); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } *viewp = view; return (ISC_R_SUCCESS); @@ -5801,19 +6024,23 @@ create_view(const cfg_obj_t *vconfig, dns_viewlist_t *viewlist, dns_view_t * view = NULL; result = get_viewinfo(vconfig, &viewname, &viewclass); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_viewlist_find(viewlist, viewname, viewclass, &view); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (ISC_R_EXISTS); - if (result != ISC_R_NOTFOUND) + } + if (result != ISC_R_NOTFOUND) { return (result); + } INSIST(view == NULL); result = dns_view_create(named_g_mctx, viewclass, viewname, &view); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_nonce_buf(view->secret, sizeof(view->secret)); @@ -5876,11 +6103,12 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, view->rdclass, &zclass)); if (zclass != view->rdclass) { const char *vname = NULL; - if (vconfig != NULL) + if (vconfig != NULL) { vname = cfg_obj_asstring(cfg_tuple_get(vconfig, "nam" "e")); - else + } else { vname = ""; + } isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, @@ -5975,8 +6203,10 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, only = NULL; tresult = cfg_map_get(zoptions, "delegation-only", &only); - if (tresult == ISC_R_SUCCESS && cfg_obj_asboolean(only)) + if (tresult == ISC_R_SUCCESS && + cfg_obj_asboolean(only)) { CHECK(dns_view_adddelegationonly(view, origin)); + } } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING, @@ -6006,8 +6236,9 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, */ only = NULL; tresult = cfg_map_get(zoptions, "delegation-only", &only); - if (tresult == ISC_R_SUCCESS && cfg_obj_asboolean(only)) + if (tresult == ISC_R_SUCCESS && cfg_obj_asboolean(only)) { CHECK(dns_view_adddelegationonly(view, origin)); + } goto cleanup; } @@ -6031,8 +6262,9 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, } result = dns_viewlist_find(viewlist, view->name, view->rdclass, &pview); - if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) + if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) { goto cleanup; + } if (pview != NULL && pview->redirect != NULL) { dns_zone_attach(pview->redirect, &zone); dns_zone_setview(zone, view); @@ -6080,13 +6312,16 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, rpz_num = DNS_RPZ_INVALID_NUM; break; } - if (dns_name_equal(&view->rpzs->zones[rpz_num]->origin, origin)) + if (dns_name_equal(&view->rpzs->zones[rpz_num]->origin, + origin)) { break; + } } if (view->catzs != NULL && - dns_catz_get_zone(view->catzs, origin) != NULL) + dns_catz_get_zone(view->catzs, origin) != NULL) { zone_is_catz = true; + } /* * See if we can reuse an existing zone. This is @@ -6102,19 +6337,24 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, */ result = dns_viewlist_find(&named_g_server->viewlist, view->name, view->rdclass, &pview); - if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) + if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) { goto cleanup; - if (pview != NULL) + } + if (pview != NULL) { result = dns_view_findzone(pview, origin, &zone); - if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) + } + if (result != ISC_R_NOTFOUND && result != ISC_R_SUCCESS) { goto cleanup; + } - if (zone != NULL && !named_zone_reusable(zone, zconfig)) + if (zone != NULL && !named_zone_reusable(zone, zconfig)) { dns_zone_detach(&zone); + } if (zone != NULL && (rpz_num != dns_zone_get_rpz_num(zone) || - (rpz_num != DNS_RPZ_INVALID_NUM && !old_rpz_ok))) + (rpz_num != DNS_RPZ_INVALID_NUM && !old_rpz_ok))) { dns_zone_detach(&zone); + } if (zone != NULL) { /* @@ -6146,8 +6386,9 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, } } - if (zone_is_catz) + if (zone_is_catz) { dns_zone_catz_enable(zone, view->catzs); + } /* * If the zone contains a 'forwarders' statement, configure @@ -6166,8 +6407,9 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, */ only = NULL; if (cfg_map_get(zoptions, "delegation-only", &only) == ISC_R_SUCCESS) { - if (cfg_obj_asboolean(only)) + if (cfg_obj_asboolean(only)) { CHECK(dns_view_adddelegationonly(view, origin)); + } } /* @@ -6214,8 +6456,9 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, /* * Add the zone to its view in the new view list. */ - if (!modify) + if (!modify) { CHECK(dns_view_addzone(view, zone)); + } if (zone_is_catz) { /* @@ -6234,16 +6477,20 @@ configure_zone(const cfg_obj_t *config, const cfg_obj_t *zconfig, /* * Ensure that zone keys are reloaded on reconfig */ - if ((dns_zone_getkeyopts(zone) & DNS_ZONEKEY_MAINTAIN) != 0) + if ((dns_zone_getkeyopts(zone) & DNS_ZONEKEY_MAINTAIN) != 0) { dns_zone_rekey(zone, false); + } cleanup: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); - if (raw != NULL) + } + if (raw != NULL) { dns_zone_detach(&raw); - if (pview != NULL) + } + if (pview != NULL) { dns_view_detach(&pview); + } return (result); } @@ -6369,10 +6616,11 @@ directory_callback(const char *clausename, const cfg_obj_t *obj, void *arg) */ directory = cfg_obj_asstring(obj); - if (!isc_file_ischdiridempotent(directory)) + if (!isc_file_ischdiridempotent(directory)) { cfg_obj_log(obj, named_g_lctx, ISC_LOG_WARNING, "option 'directory' contains relative path '%s'", directory); + } if (!isc_file_isdirwritable(directory)) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -6410,18 +6658,21 @@ add_listenelt(isc_mem_t *mctx, ns_listenlist_t *list, isc_sockaddr_t *addr, isc_netaddr_fromin6(&netaddr, &addr->type.sin6.sin6_addr); result = dns_acl_create(mctx, 0, &src_acl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_iptable_addprefix(src_acl->iptable, &netaddr, 128, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto clean; + } result = ns_listenelt_create(mctx, isc_sockaddr_getport(addr), dscp, src_acl, &lelt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto clean; + } ISC_LIST_APPEND(list->elts, lelt, link); } @@ -6451,19 +6702,22 @@ adjust_interfaces(named_server_t *server, isc_mem_t *mctx) isc_dscp_t dscp = -1; result = ns_listenlist_create(mctx, &list); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { dns_dispatch_t *dispatch6; dispatch6 = dns_resolver_dispatchv6(view->resolver); - if (dispatch6 == NULL) + if (dispatch6 == NULL) { continue; + } result = dns_dispatch_getlocaladdress(dispatch6, &addr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* * We always add non-wildcard address regardless of whether @@ -6475,8 +6729,9 @@ adjust_interfaces(named_server_t *server, isc_mem_t *mctx) */ /* XXXMPA fix dscp */ result = add_listenelt(mctx, list, &addr, dscp, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } zone = NULL; @@ -6494,26 +6749,30 @@ adjust_interfaces(named_server_t *server, isc_mem_t *mctx) * (zoneview == NULL). */ zoneview = dns_zone_getview(zone); - if (zoneview == NULL) + if (zoneview == NULL) { continue; + } for (view = ISC_LIST_HEAD(server->viewlist); view != NULL && view != zoneview; - view = ISC_LIST_NEXT(view, link)) - ; - if (view == NULL) + view = ISC_LIST_NEXT(view, link)) { + } + if (view == NULL) { continue; + } addrp = dns_zone_getnotifysrc6(zone); dscp = dns_zone_getnotifysrc6dscp(zone); result = add_listenelt(mctx, list, addrp, dscp, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } addrp = dns_zone_getxfrsource6(zone); dscp = dns_zone_getxfrsource6dscp(zone); result = add_listenelt(mctx, list, addrp, dscp, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } ns_interfacemgr_adjust(server->interfacemgr, list, true); @@ -6578,12 +6837,13 @@ cid(const void *a, const void *b) { const uint16_t ida = *(const uint16_t *)a; const uint16_t idb = *(const uint16_t *)b; - if (ida < idb) + if (ida < idb) { return (-1); - else if (ida > idb) + } else if (ida > idb) { return (1); - else + } else { return (0); + } } static void @@ -6600,16 +6860,20 @@ tat_done(isc_task_t *task, isc_event_t *event) devent = (dns_fetchevent_t *)event; /* Free resources which are not of interest */ - if (devent->node != NULL) + if (devent->node != NULL) { dns_db_detachnode(devent->db, &devent->node); - if (devent->db != NULL) + } + if (devent->db != NULL) { dns_db_detach(&devent->db); + } isc_event_free(&event); dns_resolver_destroyfetch(&tat->fetch); - if (dns_rdataset_isassociated(&tat->rdataset)) + if (dns_rdataset_isassociated(&tat->rdataset)) { dns_rdataset_disassociate(&tat->rdataset); - if (dns_rdataset_isassociated(&tat->sigrdataset)) + } + if (dns_rdataset_isassociated(&tat->sigrdataset)) { dns_rdataset_disassociate(&tat->sigrdataset); + } isc_task_detach(&tat->task); isc_mem_putanddetach(&tat->mctx, tat, sizeof(*tat)); } @@ -6848,8 +7112,9 @@ setstring(named_server_t *server, char **field, const char *value) copy = NULL; } - if (*field != NULL) + if (*field != NULL) { isc_mem_free(server->mctx, *field); + } *field = copy; return (ISC_R_SUCCESS); @@ -6863,10 +7128,11 @@ setstring(named_server_t *server, char **field, const char *value) static isc_result_t setoptstring(named_server_t *server, char **field, const cfg_obj_t *obj) { - if (cfg_obj_isvoid(obj)) + if (cfg_obj_isvoid(obj)) { return (setstring(server, field, NULL)); - else + } else { return (setstring(server, field, cfg_obj_asstring(obj))); + } } static void @@ -6879,19 +7145,21 @@ set_limit(const cfg_obj_t **maps, const char *configname, isc_resourcevalue_t value; isc_result_t result; - if (named_config_get(maps, configname, &obj) != ISC_R_SUCCESS) + if (named_config_get(maps, configname, &obj) != ISC_R_SUCCESS) { return; + } if (cfg_obj_isstring(obj)) { resource = cfg_obj_asstring(obj); - if (strcasecmp(resource, "unlimited") == 0) + if (strcasecmp(resource, "unlimited") == 0) { value = ISC_RESOURCE_UNLIMITED; - else { + } else { INSIST(strcasecmp(resource, "default") == 0); value = defaultvalue; } - } else + } else { value = cfg_obj_asuint64(obj); + } result = isc_resource_setlimit(resourceid, value); isc_log_write( @@ -6926,10 +7194,11 @@ portset_fromconf(isc_portset_t *portset, const cfg_obj_t *ports, bool positive) if (cfg_obj_isuint32(obj)) { in_port_t port = (in_port_t)cfg_obj_asuint32(obj); - if (positive) + if (positive) { isc_portset_add(portset, port); - else + } else { isc_portset_remove(portset, port); + } } else { const cfg_obj_t *obj_loport, *obj_hiport; in_port_t loport, hiport; @@ -6939,9 +7208,9 @@ portset_fromconf(isc_portset_t *portset, const cfg_obj_t *ports, bool positive) obj_hiport = cfg_tuple_get(obj, "hiport"); hiport = (in_port_t)cfg_obj_asuint32(obj_hiport); - if (positive) + if (positive) { isc_portset_addrange(portset, loport, hiport); - else { + } else { isc_portset_removerange(portset, loport, hiport); } @@ -6954,8 +7223,9 @@ removed(dns_zone_t *zone, void *uap) { const char *type; - if (dns_zone_getview(zone) != uap) + if (dns_zone_getview(zone) != uap) { return (ISC_R_SUCCESS); + } switch (dns_zone_gettype(zone)) { case dns_zone_master: @@ -6994,14 +7264,16 @@ cleanup_session_key(named_server_t *server, isc_mem_t *mctx) } if (server->session_keyname != NULL) { - if (dns_name_dynamic(server->session_keyname)) + if (dns_name_dynamic(server->session_keyname)) { dns_name_free(server->session_keyname, mctx); + } isc_mem_put(mctx, server->session_keyname, sizeof(dns_name_t)); server->session_keyname = NULL; } - if (server->sessionkey != NULL) + if (server->sessionkey != NULL) { dns_tsigkey_detach(&server->sessionkey); + } server->session_keyalg = DST_ALG_UNKNOWN; server->session_keybits = 0; @@ -7032,8 +7304,9 @@ generate_session_key(const char *filename, const char *keynamestr, result = dst_key_generate(keyname, algtype, bits, 1, 0, DNS_KEYPROTO_ANY, dns_rdataclass_in, mctx, &key, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Dump the key to the buffer for later use. Should be done before @@ -7071,8 +7344,9 @@ generate_session_key(const char *filename, const char *keynamestr, CHECK(isc_stdio_flush(fp)); result = isc_stdio_close(fp); fp = NULL; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dst_key_free(&key); @@ -7090,10 +7364,12 @@ cleanup: (void)isc_stdio_close(fp); (void)isc_file_remove(filename); } - if (tsigkey != NULL) + if (tsigkey != NULL) { dns_tsigkey_detach(&tsigkey); - if (key != NULL) + } + if (key != NULL) { dst_key_free(&key); + } return (result); } @@ -7117,12 +7393,14 @@ configure_session_key(const cfg_obj_t **maps, named_server_t *server, obj = NULL; result = named_config_get(maps, "session-keyfile", &obj); if (result == ISC_R_SUCCESS) { - if (cfg_obj_isvoid(obj)) + if (cfg_obj_isvoid(obj)) { keyfile = NULL; /* disable it */ - else + } else { keyfile = cfg_obj_asstring(obj); - } else + } + } else { keyfile = named_g_defaultsessionkeyfile; + } obj = NULL; result = named_config_get(maps, "session-keyname", &obj); @@ -7132,8 +7410,9 @@ configure_session_key(const cfg_obj_t **maps, named_server_t *server, isc_buffer_add(&buffer, strlen(keynamestr)); keyname = dns_fixedname_initname(&fname); result = dns_name_fromtext(keyname, &buffer, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } obj = NULL; result = named_config_get(maps, "session-keyalg", &obj); @@ -7154,14 +7433,15 @@ configure_session_key(const cfg_obj_t **maps, named_server_t *server, /* See if we need to (re)generate a new key. */ if (keyfile == NULL) { - if (server->session_keyfile != NULL) + if (server->session_keyfile != NULL) { need_deleteold = true; - } else if (server->session_keyfile == NULL) + } + } else if (server->session_keyfile == NULL) { need_createnew = true; - else if (strcmp(keyfile, server->session_keyfile) != 0 || - !dns_name_equal(server->session_keyname, keyname) || - server->session_keyalg != algtype || - server->session_keybits != bits) { + } else if (strcmp(keyfile, server->session_keyfile) != 0 || + !dns_name_equal(server->session_keyname, keyname) || + server->session_keyalg != algtype || + server->session_keybits != bits) { need_deleteold = true; need_createnew = true; } @@ -7232,8 +7512,9 @@ count_newzones(dns_view_t *view, ns_cfgctx_t *nzcfg, int *num_zonesp) NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "NZF file '%s' contains %d zones", view->new_zone_file, num_zones); - if (num_zonesp != NULL) + if (num_zonesp != NULL) { *num_zonesp = num_zones; + } } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, @@ -7274,8 +7555,9 @@ count_newzones(dns_view_t *view, ns_cfgctx_t *nzcfg, int *num_zonesp) n); cleanup: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { *num_zonesp = 0; + } return (ISC_R_SUCCESS); } @@ -7301,19 +7583,23 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig, REQUIRE(config != NULL); - if (vconfig != NULL) + if (vconfig != NULL) { voptions = cfg_tuple_get(vconfig, "options"); - if (voptions != NULL) + } + if (voptions != NULL) { maps[i++] = voptions; + } result = cfg_map_get(config, "options", &options); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { maps[i++] = options; + } maps[i++] = named_g_defaults; maps[i] = NULL; result = named_config_get(maps, "allow-new-zones", &nz); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { allow = cfg_obj_asboolean(nz); + } result = named_config_get(maps, "new-zones-directory", &nzdir); if (result == ISC_R_SUCCESS) { dir = cfg_obj_asstring(nzdir); @@ -7359,7 +7645,7 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig, return (ISC_R_FAILURE); } } -#else +#else /* ifdef HAVE_LMDB */ UNUSED(obj); #endif /* HAVE_LMDB */ @@ -7372,15 +7658,17 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig, if (result == ISC_R_SUCCESS) { const cfg_listelt_t *e = cfg_list_first(cfg_tuple_get(cz, "zone list")); - if (e != NULL) + if (e != NULL) { allow = true; + } } } if (!allow) { dns_view_setnewzones(view, false, NULL, NULL, 0ULL); - if (num_zones != NULL) + if (num_zones != NULL) { *num_zones = 0; + } return (ISC_R_SUCCESS); } @@ -7405,8 +7693,9 @@ setup_newzones(dns_view_t *view, cfg_obj_t *config, cfg_obj_t *vconfig, } cfg_obj_attach(config, &nzcfg->config); - if (vconfig != NULL) + if (vconfig != NULL) { cfg_obj_attach(vconfig, &nzcfg->vconfig); + } result = count_newzones(view, nzcfg, num_zones); return (result); @@ -7448,12 +7737,14 @@ configure_zone_setviewcommit(isc_result_t result, const cfg_obj_t *zconfig, if (result == ISC_R_SUCCESS) { dns_zone_setviewcommit(zone); - if (raw != NULL) + if (raw != NULL) { dns_zone_setviewcommit(raw); + } } else { dns_zone_setviewrevert(zone); - if (raw != NULL) + if (raw != NULL) { dns_zone_setviewrevert(raw); + } } if (raw != NULL) { @@ -7809,8 +8100,9 @@ count_zones(const cfg_obj_t *conf) cfg_map_get(conf, "zone", &zonelist); for (element = cfg_list_first(zonelist); element != NULL; - element = cfg_list_next(element)) + element = cfg_list_next(element)) { n++; + } return (n); } @@ -7828,8 +8120,9 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, bool first_time) i = 0; options = NULL; result = cfg_map_get(config, "options", &options); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { maps[i++] = options; + } maps[i++] = named_g_defaults; maps[i] = NULL; @@ -7839,12 +8132,13 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, bool first_time) if (!first_time) { if (obj != NULL && !cfg_obj_isstring(obj) && server->lockfile != NULL && - strcmp(cfg_obj_asstring(obj), server->lockfile) != 0) + strcmp(cfg_obj_asstring(obj), server->lockfile) != 0) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_WARNING, "changing 'lock-file' " "has no effect until the " "server is restarted"); + } return (ISC_R_SUCCESS); } @@ -7868,8 +8162,9 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, bool first_time) isc_mem_strdup(server->mctx, filename); } - if (server->lockfile == NULL) + if (server->lockfile == NULL) { return (ISC_R_NOMEMORY); + } } if (named_g_forcelock && named_g_defaultlockfile != NULL) { @@ -7878,11 +8173,13 @@ check_lockfile(named_server_t *server, const cfg_obj_t *config, bool first_time) isc_mem_strdup(server->mctx, named_g_defaultlockfile); } - if (server->lockfile == NULL) + if (server->lockfile == NULL) { return (ISC_R_SUCCESS); + } - if (named_os_issingleton(server->lockfile)) + if (named_os_issingleton(server->lockfile)) { return (ISC_R_SUCCESS); + } isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, @@ -8885,9 +9182,10 @@ load_configuration(const char *filename, named_server_t *server, cfg_obj_asboolean(obj)); } else { (void)cfg_map_get(config, "logging", &logobj); - if (logobj != NULL) + if (logobj != NULL) { (void)cfg_map_get(logobj, "category", &categories); + } if (categories != NULL) { for (element = cfg_list_first(categories); element != NULL; @@ -8898,11 +9196,12 @@ load_configuration(const char *filename, named_server_t *server, obj = cfg_listelt_value(element); catobj = cfg_tuple_get(obj, "name"); str = cfg_obj_asstring(catobj); - if (strcasecmp(str, "queries") == 0) + if (strcasecmp(str, "queries") == 0) { ns_server_setoption( server->sctx, NS_SERVER_LOGQUERIES, true); + } } } } @@ -9099,7 +9398,7 @@ load_configuration(const char *filename, named_server_t *server, goto cleanup; } } -#endif +#endif /* ifdef USE_DNSRPS */ result = ISC_R_SUCCESS; @@ -9256,7 +9555,7 @@ view_loaded(void *arg) NAMED_LOGMODULE_SERVER, ISC_LOG_NOTICE, "FIPS mode is %s", FIPS_mode() ? "enabled" : "disabled"); -#endif +#endif /* ifdef HAVE_FIPS_MODE */ server->reload_status = NAMED_RELOAD_DONE; isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -9292,15 +9591,17 @@ load_zones(named_server_t *server, bool init, bool reconfig) result = dns_zone_load(view->managed_keys, false); if (result != ISC_R_SUCCESS && result != DNS_R_UPTODATE && - result != DNS_R_CONTINUE) + result != DNS_R_CONTINUE) { goto cleanup; + } } if (view->redirect != NULL) { result = dns_zone_load(view->redirect, false); if (result != ISC_R_SUCCESS && result != DNS_R_UPTODATE && - result != DNS_R_CONTINUE) + result != DNS_R_CONTINUE) { goto cleanup; + } } /* @@ -9353,9 +9654,9 @@ run_server(isc_task_t *task, isc_event_t *event) #if defined(HAVE_GEOIP2) geoip = named_g_geoip; -#else +#else /* if defined(HAVE_GEOIP2) */ geoip = NULL; -#endif +#endif /* if defined(HAVE_GEOIP2) */ CHECKFATAL(ns_interfacemgr_create( named_g_mctx, server->sctx, named_g_taskmgr, @@ -9402,7 +9703,7 @@ run_server(isc_task_t *task, isc_event_t *event) CHECKFATAL(load_zones(server, true, false), "loading zones"); #ifdef ENABLE_AFL named_g_run_done = true; -#endif +#endif /* ifdef ENABLE_AFL */ } void @@ -9444,8 +9745,9 @@ shutdown_server(isc_task_t *task, isc_event_t *event) end_reserved_dispatches(server, true); cleanup_session_key(server, server->mctx); - if (named_g_aclconfctx != NULL) + if (named_g_aclconfctx != NULL) { cfg_aclconfctx_detach(&named_g_aclconfctx); + } cfg_obj_destroy(named_g_parser, &named_g_config); cfg_parser_destroy(&named_g_parser); @@ -9464,10 +9766,11 @@ shutdown_server(isc_task_t *task, isc_event_t *event) view = view_next) { view_next = ISC_LIST_NEXT(view, link); ISC_LIST_UNLINK(server->viewlist, view, link); - if (flush) + if (flush) { dns_view_flushanddetach(&view); - else + } else { dns_view_detach(&view); + } } /* @@ -9558,8 +9861,9 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) isc_result_t result; named_server_t *server = isc_mem_get(mctx, sizeof(*server)); - if (server == NULL) + if (server == NULL) { fatal(server, "allocating server object", ISC_R_NOMEMORY); + } server->mctx = mctx; server->task = NULL; @@ -9568,7 +9872,7 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) #ifdef USE_DNSRPS CHECKFATAL(dns_dnsrps_server_create(), "initializing RPZ service " "interface"); -#endif +#endif /* ifdef USE_DNSRPS */ /* Initialize server data structures. */ server->interfacemgr = NULL; @@ -9622,7 +9926,7 @@ named_server_create(isc_mem_t *mctx, named_server_t **serverp) #ifdef ENABLE_AFL server->sctx->fuzztype = named_g_fuzz_type; server->sctx->fuzznotify = named_fuzz_notify; -#endif +#endif /* ifdef ENABLE_AFL */ CHECKFATAL(isc_task_onshutdown(server->task, shutdown_server, server), "isc_task_onshutdown"); @@ -9724,13 +10028,14 @@ named_server_destroy(named_server_t **serverp) REQUIRE(NAMED_SERVER_VALID(server)); #ifdef HAVE_DNSTAP - if (server->dtenv != NULL) + if (server->dtenv != NULL) { dns_dt_detach(&server->dtenv); + } #endif /* HAVE_DNSTAP */ #ifdef USE_DNSRPS dns_dnsrps_server_destroy(); -#endif +#endif /* ifdef USE_DNSRPS */ named_controls_destroy(&server->controls); @@ -9738,8 +10043,9 @@ named_server_destroy(named_server_t **serverp) isc_stats_detach(&server->sockstats); isc_stats_detach(&server->resolverstats); - if (server->sctx != NULL) + if (server->sctx != NULL) { ns_server_detach(&server->sctx); + } isc_mem_free(server->mctx, server->statsfile); isc_mem_free(server->mctx, server->bindkeysfile); @@ -9747,15 +10053,19 @@ named_server_destroy(named_server_t **serverp) isc_mem_free(server->mctx, server->secrootsfile); isc_mem_free(server->mctx, server->recfile); - if (server->version != NULL) + if (server->version != NULL) { isc_mem_free(server->mctx, server->version); - if (server->hostname != NULL) + } + if (server->hostname != NULL) { isc_mem_free(server->mctx, server->hostname); - if (server->lockfile != NULL) + } + if (server->lockfile != NULL) { isc_mem_free(server->mctx, server->lockfile); + } - if (server->zonemgr != NULL) + if (server->zonemgr != NULL) { dns_zonemgr_detach(&server->zonemgr); + } dst_lib_destroy(); @@ -9809,8 +10119,9 @@ end_reserved_dispatches(named_server_t *server, bool all) for (dispatch = ISC_LIST_HEAD(server->dispatches); dispatch != NULL; dispatch = nextdispatch) { nextdispatch = ISC_LIST_NEXT(dispatch, link); - if (!all && server->dispatchgen == dispatch->dispatchgen) + if (!all && server->dispatchgen == dispatch->dispatchgen) { continue; + } ISC_LIST_UNLINK(server->dispatches, dispatch, link); dns_dispatch_detach(&dispatch->dispatch); isc_mem_put(server->mctx, dispatch, sizeof(*dispatch)); @@ -9829,13 +10140,15 @@ named_add_reserved_dispatch(named_server_t *server, const isc_sockaddr_t *addr) REQUIRE(NAMED_SERVER_VALID(server)); port = isc_sockaddr_getport(addr); - if (port == 0 || port >= 1024) + if (port == 0 || port >= 1024) { return; + } for (dispatch = ISC_LIST_HEAD(server->dispatches); dispatch != NULL; dispatch = ISC_LIST_NEXT(dispatch, link)) { - if (isc_sockaddr_equal(&dispatch->addr, addr)) + if (isc_sockaddr_equal(&dispatch->addr, addr)) { break; + } } if (dispatch != NULL) { dispatch->dispatchgen = server->dispatchgen; @@ -9871,8 +10184,9 @@ named_add_reserved_dispatch(named_server_t *server, const isc_sockaddr_t *addr) named_g_taskmgr, &dispatch->addr, 4096, UDPBUFFERS, 32768, 16411, 16433, attrs, attrmask, &dispatch->dispatch); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } ISC_LIST_INITANDPREPEND(server->dispatches, dispatch, link); @@ -9958,8 +10272,9 @@ void named_server_reloadwanted(named_server_t *server) { LOCK(&server->reload_event_lock); - if (server->reload_event != NULL) + if (server->reload_event != NULL) { isc_task_send(server->task, &server->reload_event); + } UNLOCK(&server->reload_event_lock); } @@ -9997,8 +10312,9 @@ next_token(isc_lex_t *lex, isc_buffer_t **text) (void)isc_lex_close(lex); break; case ISC_R_SUCCESS: - if (token.type == isc_tokentype_eof) + if (token.type == isc_tokentype_eof) { (void)isc_lex_close(lex); + } break; case ISC_R_NOSPACE: if (text != NULL) { @@ -10015,8 +10331,9 @@ next_token(isc_lex_t *lex, isc_buffer_t **text) } if (token.type == isc_tokentype_string || - token.type == isc_tokentype_qstring) + token.type == isc_tokentype_qstring) { return (token.value.as_textregion.base); + } return (NULL); } @@ -10055,26 +10372,31 @@ zone_from_args(named_server_t *server, isc_lex_t *lex, const char *zonetxt, if (skip) { /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } } /* Look for the zone name. */ - if (zonetxt == NULL) + if (zonetxt == NULL) { zonetxt = next_token(lex, text); - if (zonetxt == NULL) + } + if (zonetxt == NULL) { return (ISC_R_SUCCESS); + } /* Copy zonetxt because it'll be overwritten by next_token() */ /* To locate a zone named "-redirect" use "-redirect." */ if (strcmp(zonetxt, "-redirect") == 0) { redirect = true; strlcpy(zonebuf, ".", DNS_NAME_FORMATSIZE); - } else + } else { strlcpy(zonebuf, zonetxt, DNS_NAME_FORMATSIZE); - if (zonename != NULL) + } + if (zonename != NULL) { strlcpy(zonename, redirect ? "." : zonetxt, DNS_NAME_FORMATSIZE); + } name = dns_fixedname_initname(&fname); CHECK(dns_name_fromstring(name, zonebuf, 0, NULL)); @@ -10089,8 +10411,9 @@ zone_from_args(named_server_t *server, isc_lex_t *lex, const char *zonetxt, /* Look for the optional view name. */ viewtxt = next_token(lex, text); - } else + } else { rdclass = dns_rdataclass_in; + } if (viewtxt == NULL) { if (redirect) { @@ -10110,15 +10433,16 @@ zone_from_args(named_server_t *server, isc_lex_t *lex, const char *zonetxt, result = dns_viewlist_findzone(&server->viewlist, name, (classtxt == NULL), rdclass, zonep); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { snprintf(problem, sizeof(problem), "no matching zone '%s' in any view", zonebuf); - else if (result == ISC_R_MULTIPLE) + } else if (result == ISC_R_MULTIPLE) { snprintf(problem, sizeof(problem), "zone '%s' was found in multiple " "views", zonebuf); + } } } else { result = dns_viewlist_find(&server->viewlist, viewtxt, rdclass, @@ -10133,34 +10457,41 @@ zone_from_args(named_server_t *server, isc_lex_t *lex, const char *zonetxt, if (view->redirect != NULL) { dns_zone_attach(view->redirect, zonep); result = ISC_R_SUCCESS; - } else + } else { result = ISC_R_NOTFOUND; - } else + } + } else { result = dns_zt_find(view->zonetable, name, 0, NULL, zonep); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { snprintf(problem, sizeof(problem), "no matching zone '%s' in view '%s'", zonebuf, viewtxt); + } } /* Partial match? */ - if (result != ISC_R_SUCCESS && *zonep != NULL) + if (result != ISC_R_SUCCESS && *zonep != NULL) { dns_zone_detach(zonep); - if (result == DNS_R_PARTIALMATCH) + } + if (result == DNS_R_PARTIALMATCH) { result = ISC_R_NOTFOUND; + } report: if (result != ISC_R_SUCCESS) { isc_result_t tresult; tresult = putstr(text, problem); - if (tresult == ISC_R_SUCCESS) + if (tresult == ISC_R_SUCCESS) { (void)putnull(text); + } } cleanup: - if (view != NULL) + if (view != NULL) { dns_view_detach(&view); + } return (result); } @@ -10178,10 +10509,12 @@ named_server_retransfercommand(named_server_t *server, isc_lex_t *lex, dns_zonetype_t type; result = zone_from_args(server, lex, NULL, &zone, NULL, text, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (zone == NULL) + } + if (zone == NULL) { return (ISC_R_UNEXPECTEDEND); + } dns_zone_getraw(zone, &raw); if (raw != NULL) { dns_zone_detach(&zone); @@ -10192,10 +10525,11 @@ named_server_retransfercommand(named_server_t *server, isc_lex_t *lex, if (type == dns_zone_slave || type == dns_zone_mirror || type == dns_zone_stub || (type == dns_zone_redirect && - dns_zone_getredirecttype(zone) == dns_zone_slave)) + dns_zone_getredirecttype(zone) == dns_zone_slave)) { dns_zone_forcereload(zone); - else + } else { result = ISC_R_NOTFOUND; + } dns_zone_detach(&zone); return (result); } @@ -10213,12 +10547,14 @@ named_server_reloadcommand(named_server_t *server, isc_lex_t *lex, const char * msg = NULL; result = zone_from_args(server, lex, NULL, &zone, NULL, text, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (zone == NULL) { result = reload(server); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { msg = "server reload successful"; + } } else { type = dns_zone_gettype(zone); if (type == dns_zone_slave || type == dns_zone_mirror || @@ -10293,10 +10629,12 @@ named_server_notifycommand(named_server_t *server, isc_lex_t *lex, const char msg[] = "zone notify queued"; result = zone_from_args(server, lex, NULL, &zone, NULL, text, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (zone == NULL) + } + if (zone == NULL) { return (ISC_R_UNEXPECTEDEND); + } dns_zone_notify(zone); dns_zone_detach(&zone); @@ -10320,10 +10658,12 @@ named_server_refreshcommand(named_server_t *server, isc_lex_t *lex, dns_zonetype_t type; result = zone_from_args(server, lex, NULL, &zone, NULL, text, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (zone == NULL) + } + if (zone == NULL) { return (ISC_R_UNEXPECTEDEND); + } dns_zone_getraw(zone, &raw); if (raw != NULL) { @@ -10356,8 +10696,9 @@ named_server_togglequerylog(named_server_t *server, isc_lex_t *lex) /* Skip the command name. */ ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } prev = ns_server_getoption(server->sctx, NS_SERVER_LOGQUERIES); @@ -10374,8 +10715,9 @@ named_server_togglequerylog(named_server_t *server, isc_lex_t *lex) return (DNS_R_SYNTAX); } - if (value == prev) + if (value == prev) { return (ISC_R_SUCCESS); + } ns_server_setoption(server->sctx, NS_SERVER_LOGQUERIES, value); @@ -10397,8 +10739,9 @@ ns_listenlist_fromconfig(const cfg_obj_t *listenlist, const cfg_obj_t *config, REQUIRE(target != NULL && *target == NULL); result = ns_listenlist_create(mctx, &dlist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } for (element = cfg_list_first(listenlist); element != NULL; element = cfg_list_next(element)) { @@ -10406,8 +10749,9 @@ ns_listenlist_fromconfig(const cfg_obj_t *listenlist, const cfg_obj_t *config, const cfg_obj_t *listener = cfg_listelt_value(element); result = ns_listenelt_fromconfig(listener, config, actx, mctx, family, &delt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } ISC_LIST_APPEND(dlist->elts, delt, link); } *target = dlist; @@ -10440,8 +10784,9 @@ ns_listenelt_fromconfig(const cfg_obj_t *listener, const cfg_obj_t *config, port = named_g_port; } else { result = named_config_getport(config, &port); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } } else { if (cfg_obj_asuint32(portobj) >= UINT16_MAX) { @@ -10454,9 +10799,9 @@ ns_listenelt_fromconfig(const cfg_obj_t *listener, const cfg_obj_t *config, } dscpobj = cfg_tuple_get(listener, "dscp"); - if (!cfg_obj_isuint32(dscpobj)) + if (!cfg_obj_isuint32(dscpobj)) { dscp = named_g_dscp; - else { + } else { if (cfg_obj_asuint32(dscpobj) > 63) { cfg_obj_log(dscpobj, named_g_lctx, ISC_LOG_ERROR, "dscp value '%u' is out of range", @@ -10467,8 +10812,9 @@ ns_listenelt_fromconfig(const cfg_obj_t *listener, const cfg_obj_t *config, } result = ns_listenelt_create(mctx, port, dscp, NULL, &delt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = cfg_acl_fromconfig2(cfg_tuple_get(listener, "acl"), config, named_g_lctx, actx, mctx, 0, family, @@ -10493,17 +10839,19 @@ named_server_dumpstats(named_server_t *server) result = named_stats_dump(server, fp); cleanup: - if (fp != NULL) + if (fp != NULL) { (void)isc_stdio_close(fp); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "dumpstats complete"); - else + } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "dumpstats failed: %s", dns_result_totext(result)); + } return (result); } @@ -10534,7 +10882,6 @@ add_view_tolist(struct dumpcontext *dctx, dns_view_t *view) vle = ISC_LIST_NEXT(vle, link)) { if (vle->view == view) { return (ISC_R_SUCCESS); - } } @@ -10544,9 +10891,10 @@ add_view_tolist(struct dumpcontext *dctx, dns_view_t *view) ISC_LINK_INIT(vle, link); ISC_LIST_INIT(vle->zonelist); ISC_LIST_APPEND(dctx->viewlist, vle, link); - if (dctx->dumpzones) + if (dctx->dumpzones) { result = dns_zt_apply(view->zonetable, true, NULL, add_zone_tolist, dctx); + } return (result); } @@ -10570,18 +10918,24 @@ dumpcontext_destroy(struct dumpcontext *dctx) isc_mem_put(dctx->mctx, vle, sizeof *vle); vle = ISC_LIST_HEAD(dctx->viewlist); } - if (dctx->version != NULL) + if (dctx->version != NULL) { dns_db_closeversion(dctx->db, &dctx->version, false); - if (dctx->db != NULL) + } + if (dctx->db != NULL) { dns_db_detach(&dctx->db); - if (dctx->cache != NULL) + } + if (dctx->cache != NULL) { dns_db_detach(&dctx->cache); - if (dctx->task != NULL) + } + if (dctx->task != NULL) { isc_task_detach(&dctx->task); - if (dctx->fp != NULL) + } + if (dctx->fp != NULL) { (void)isc_stdio_close(dctx->fp); - if (dctx->mdctx != NULL) + } + if (dctx->mdctx != NULL) { dns_dumpctx_detach(&dctx->mdctx); + } isc_mem_put(dctx->mctx, dctx, sizeof *dctx); } @@ -10739,8 +11093,9 @@ named_server_dumpdb(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) /* Skip the command name. */ ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } dctx = isc_mem_get(server->mctx, sizeof(*dctx)); @@ -10810,8 +11165,9 @@ nextview: found = false; for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (ptr != NULL && strcmp(view->name, ptr) != 0) + if (ptr != NULL && strcmp(view->name, ptr) != 0) { continue; + } found = true; CHECK(add_view_tolist(dctx, view)); } @@ -10826,8 +11182,9 @@ nextview: return (result); } ptr = next_token(lex, NULL); - if (ptr != NULL) + if (ptr != NULL) { goto nextview; + } } dumpdone(dctx, ISC_R_SUCCESS); return (ISC_R_SUCCESS); @@ -10980,17 +11337,19 @@ named_server_dumprecursing(named_server_t *server) fprintf(fp, "; Dump complete\n"); cleanup: - if (fp != NULL) + if (fp != NULL) { result = isc_stdio_close(fp); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "dumprecursing complete"); - else + } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "dumprecursing failed: %s", dns_result_totext(result)); + } return (result); } @@ -11005,18 +11364,21 @@ named_server_setdebuglevel(named_server_t *server, isc_lex_t *lex) /* Skip the command name. */ ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Look for the new level name. */ ptr = next_token(lex, NULL); if (ptr == NULL) { - if (named_g_debuglevel < 99) + if (named_g_debuglevel < 99) { named_g_debuglevel++; + } } else { newlevel = strtol(ptr, &endp, 10); - if (*endp != '\0' || newlevel < 0 || newlevel > 99) + if (*endp != '\0' || newlevel < 0 || newlevel > 99) { return (ISC_R_RANGE); + } named_g_debuglevel = (unsigned int)newlevel; } isc_log_setdebuglevel(named_g_lctx, named_g_debuglevel); @@ -11038,13 +11400,15 @@ named_server_validation(named_server_t *server, isc_lex_t *lex, /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Find out what we are to do. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } if (!strcasecmp(ptr, "on") || !strcasecmp(ptr, "yes") || !strcasecmp(ptr, "enable") || !strcasecmp(ptr, "true")) { @@ -11066,16 +11430,18 @@ named_server_validation(named_server_t *server, isc_lex_t *lex, for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { if ((ptr != NULL && strcasecmp(ptr, view->name) != 0) || - strcasecmp("_bind", view->name) == 0) + strcasecmp("_bind", view->name) == 0) { continue; + } if (set) { CHECK(dns_view_flushcache(view, false)); view->enablevalidation = enable; changed = true; } else { - if (!first) + if (!first) { CHECK(putstr(text, "\n")); + } CHECK(putstr(text, "DNSSEC validation is ")); CHECK(putstr(text, view->enablevalidation ? "enabled" : "disable" @@ -11088,12 +11454,13 @@ named_server_validation(named_server_t *server, isc_lex_t *lex, } CHECK(putnull(text)); - if (!set) + if (!set) { result = ISC_R_SUCCESS; - else if (changed) + } else if (changed) { result = ISC_R_SUCCESS; - else + } else { result = ISC_R_FAILURE; + } cleanup: isc_task_endexclusive(server->task); return (result); @@ -11111,8 +11478,9 @@ named_server_flushcache(named_server_t *server, isc_lex_t *lex) /* Skip the command name. */ ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Look for the view name. */ ptr = next_token(lex, NULL); @@ -11137,25 +11505,29 @@ named_server_flushcache(named_server_t *server, isc_lex_t *lex) */ for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (strcasecmp(ptr, view->name) != 0) + if (strcasecmp(ptr, view->name) != 0) { continue; + } found = true; for (nsc = ISC_LIST_HEAD(server->cachelist); nsc != NULL; nsc = ISC_LIST_NEXT(nsc, link)) { - if (nsc->cache == view->cache) + if (nsc->cache == view->cache) { break; + } } INSIST(nsc != NULL); nsc->needflush = true; } - } else + } else { found = true; + } /* Perform flush */ for (nsc = ISC_LIST_HEAD(server->cachelist); nsc != NULL; nsc = ISC_LIST_NEXT(nsc, link)) { - if (ptr != NULL && !nsc->needflush) + if (ptr != NULL && !nsc->needflush) { continue; + } nsc->needflush = true; result = dns_view_flushcache(nsc->primaryview, false); if (result != ISC_R_SUCCESS) { @@ -11179,12 +11551,14 @@ named_server_flushcache(named_server_t *server, isc_lex_t *lex) */ for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (!dns_view_iscacheshared(view)) + if (!dns_view_iscacheshared(view)) { continue; + } for (nsc = ISC_LIST_HEAD(server->cachelist); nsc != NULL; nsc = ISC_LIST_NEXT(nsc, link)) { - if (!nsc->needflush || nsc->cache != view->cache) + if (!nsc->needflush || nsc->cache != view->cache) { continue; + } result = dns_view_flushcache(view, true); if (result != ISC_R_SUCCESS) { flushed = false; @@ -11205,15 +11579,16 @@ named_server_flushcache(named_server_t *server, isc_lex_t *lex) } if (flushed && found) { - if (ptr != NULL) + if (ptr != NULL) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "flushing cache in view '%s' succeeded", ptr); - else + } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "flushing caches in all views succeeded"); + } result = ISC_R_SUCCESS; } else { if (!found) { @@ -11223,8 +11598,9 @@ named_server_flushcache(named_server_t *server, isc_lex_t *lex) "view not found", ptr); result = ISC_R_NOTFOUND; - } else + } else { result = ISC_R_FAILURE; + } } isc_task_endexclusive(server->task); return (result); @@ -11245,21 +11621,24 @@ named_server_flushnode(named_server_t *server, isc_lex_t *lex, bool tree) /* Skip the command name. */ ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Find the domain name to flush. */ ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } strlcpy(target, ptr, DNS_NAME_FORMATSIZE); isc_buffer_constinit(&b, target, strlen(target)); isc_buffer_add(&b, strlen(target)); name = dns_fixedname_initname(&fixed); result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* Look for the view name. */ viewname = next_token(lex, NULL); @@ -11270,8 +11649,9 @@ named_server_flushnode(named_server_t *server, isc_lex_t *lex, bool tree) found = false; for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (viewname != NULL && strcasecmp(viewname, view->name) != 0) + if (viewname != NULL && strcasecmp(viewname, view->name) != 0) { continue; + } found = true; /* * It's a little inefficient to try flushing name for all views @@ -11290,26 +11670,28 @@ named_server_flushnode(named_server_t *server, isc_lex_t *lex, bool tree) } } if (flushed && found) { - if (viewname != NULL) + if (viewname != NULL) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "flushing %s '%s' in cache view '%s' " "succeeded", tree ? "tree" : "name", target, viewname); - else + } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, "flushing %s '%s' in all cache views " "succeeded", tree ? "tree" : "name", target); + } result = ISC_R_SUCCESS; } else { - if (!found) + if (!found) { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "flushing %s '%s' in cache view '%s' " "failed: view not found", tree ? "tree" : "name", target, viewname); + } result = ISC_R_FAILURE; } isc_task_endexclusive(server->task); @@ -11330,10 +11712,11 @@ named_server_status(named_server_t *server, isc_buffer_t **text) if (named_g_server->version_set) { ob = " ("; cb = ")"; - if (named_g_server->version == NULL) + if (named_g_server->version == NULL) { alt = "version.bind/txt/ch disabled"; - else + } else { alt = named_g_server->version; + } } zonecount = dns_zonemgr_getcount(server->zonemgr, DNS_ZONESTATE_ANY); xferrunning = dns_zonemgr_getcount(server->zonemgr, @@ -11357,8 +11740,9 @@ named_server_status(named_server_t *server, isc_buffer_t **text) CHECK(putstr(text, line)); result = named_os_gethostname(hostname, sizeof(hostname)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { strlcpy(hostname, "localhost", sizeof(hostname)); + } snprintf(line, sizeof(line), "running on %s: %s\n", hostname, named_os_uname()); CHECK(putstr(text, line)); @@ -11455,18 +11839,21 @@ named_server_testgen(isc_lex_t *lex, isc_buffer_t **text) /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { count = 26; - else + } else { count = strtoul(ptr, NULL, 10); + } CHECK(isc_buffer_reserve(text, count)); - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { CHECK(putuint8(text, chars[i % (sizeof(chars) - 1)])); + } CHECK(putnull(text)); @@ -11507,8 +11894,9 @@ again: tkey = node->data; if (tkey != NULL) { - if (!tkey->generated) + if (!tkey->generated) { goto nextkey; + } dns_name_format(&tkey->name, namestr, sizeof(namestr)); if (strcmp(namestr, target) == 0) { @@ -11522,8 +11910,9 @@ again: nextkey: result = dns_rbtnodechain_next(&chain, &foundname, origin); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { break; + } if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { dns_rbtnodechain_invalidate(&chain); return (result); @@ -11547,8 +11936,9 @@ named_server_tsigdelete(named_server_t *server, isc_lex_t *lex, (void)next_token(lex, text); /* skip command name */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } strlcpy(target, ptr, DNS_NAME_FORMATSIZE); viewname = next_token(lex, text); @@ -11596,10 +11986,11 @@ list_keynames(dns_view_t *view, dns_tsig_keyring_t *ring, isc_buffer_t **text, dns_tsigkey_t * tkey; const char * viewname; - if (view != NULL) + if (view != NULL) { viewname = view->name; - else + } else { viewname = "(global)"; + } dns_name_init(&foundname, NULL); origin = dns_fixedname_initname(&fixedorigin); @@ -11624,8 +12015,9 @@ list_keynames(dns_view_t *view, dns_tsig_keyring_t *ring, isc_buffer_t **text, if (tkey->generated) { dns_name_format(tkey->creator, creatorstr, sizeof(creatorstr)); - if (*foundkeys != 0) + if (*foundkeys != 0) { CHECK(putstr(text, "\n")); + } CHECK(putstr(text, "view \"")); CHECK(putstr(text, viewname)); CHECK(putstr(text, "\"; type \"dynamic\"; key " @@ -11635,8 +12027,9 @@ list_keynames(dns_view_t *view, dns_tsig_keyring_t *ring, isc_buffer_t **text, CHECK(putstr(text, creatorstr)); CHECK(putstr(text, "\";")); } else { - if (*foundkeys != 0) + if (*foundkeys != 0) { CHECK(putstr(text, "\n")); + } CHECK(putstr(text, "view \"")); CHECK(putstr(text, viewname)); CHECK(putstr(text, "\"; type \"static\"; key " @@ -11647,8 +12040,9 @@ list_keynames(dns_view_t *view, dns_tsig_keyring_t *ring, isc_buffer_t **text, (*foundkeys)++; } result = dns_rbtnodechain_next(&chain, &foundname, origin); - if (result == ISC_R_NOMORE || result == DNS_R_NEWORIGIN) + if (result == ISC_R_NOMORE || result == DNS_R_NEWORIGIN) { break; + } } return (ISC_R_SUCCESS); @@ -11687,11 +12081,13 @@ named_server_tsiglist(named_server_t *server, isc_buffer_t **text) } isc_task_endexclusive(server->task); - if (foundkeys == 0) + if (foundkeys == 0) { CHECK(putstr(text, "no tsig keys found.")); + } - if (isc_buffer_usedlength(*text) > 0) + if (isc_buffer_usedlength(*text) > 0) { CHECK(putnull(text)); + } cleanup: return (result); @@ -11711,17 +12107,21 @@ named_server_rekey(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) char * ptr; ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } - if (strcasecmp(ptr, NAMED_COMMAND_SIGN) == 0) + if (strcasecmp(ptr, NAMED_COMMAND_SIGN) == 0) { fullsign = true; + } result = zone_from_args(server, lex, NULL, &zone, NULL, text, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (zone == NULL) + } + if (zone == NULL) { return (ISC_R_UNEXPECTEDEND); /* XXX: or do all zones? */ + } type = dns_zone_gettype(zone); if (type != dns_zone_master) { @@ -11735,12 +12135,13 @@ named_server_rekey(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) * "rndc loadkeys" requires "auto-dnssec maintain" * or a "dnssec-policy". */ - if ((keyopts & DNS_ZONEKEY_ALLOW) == 0) + if ((keyopts & DNS_ZONEKEY_ALLOW) == 0) { result = ISC_R_NOPERM; - else if ((keyopts & DNS_ZONEKEY_MAINTAIN) == 0 && !fullsign) + } else if ((keyopts & DNS_ZONEKEY_MAINTAIN) == 0 && !fullsign) { result = ISC_R_NOPERM; - else + } else { dns_zone_rekey(zone, fullsign); + } dns_zone_detach(&zone); return (result); @@ -11764,12 +12165,14 @@ synczone(dns_zone_t *zone, void *uap) } result = dns_zone_flush(zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { cleanup = false; + } if (cleanup) { journal = dns_zone_getjournal(zone); - if (journal != NULL) + if (journal != NULL) { (void)isc_file_remove(journal); + } } return (result); @@ -11796,8 +12199,9 @@ named_server_sync(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) } result = zone_from_args(server, lex, arg, &zone, NULL, text, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (zone == NULL) { result = isc_task_beginexclusive(server->task); @@ -11807,8 +12211,10 @@ named_server_sync(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) view = ISC_LIST_NEXT(view, link)) { result = dns_zt_apply(view->zonetable, false, NULL, synczone, &cleanup); - if (result != ISC_R_SUCCESS && tresult == ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS && + tresult == ISC_R_SUCCESS) { tresult = result; + } } isc_task_endexclusive(server->task); isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -11863,8 +12269,9 @@ named_server_freeze(named_server_t *server, bool freeze, isc_lex_t *lex, const char * msg = NULL; result = zone_from_args(server, lex, NULL, &mayberaw, NULL, text, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (mayberaw == NULL) { result = isc_task_beginexclusive(server->task); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -11872,8 +12279,10 @@ named_server_freeze(named_server_t *server, bool freeze, isc_lex_t *lex, for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { result = dns_view_freezezones(view, freeze); - if (result != ISC_R_SUCCESS && tresult == ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS && + tresult == ISC_R_SUCCESS) { tresult = result; + } } isc_task_endexclusive(server->task); isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, @@ -11912,12 +12321,14 @@ named_server_freeze(named_server_t *server, bool freeze, isc_lex_t *lex, } if (result == ISC_R_SUCCESS) { result = dns_zone_flush(mayberaw); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { msg = "Flushing the zone updates to " "disk failed."; + } } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_zone_setupdatedisabled(mayberaw, freeze); + } } else { if (frozen) { result = dns_zone_loadandthaw(mayberaw); @@ -12021,8 +12432,9 @@ nzf_append(dns_view_t *view, const cfg_obj_t *zconfig) CHECK(isc_stdio_tell(fp, &offset)); offsetok = true; - if (offset == 0) + if (offset == 0) { CHECK(add_comment(fp, view->name)); + } CHECK(isc_stdio_write("zone ", 5, 1, fp, NULL)); cfg_printx(zconfig, CFG_PRINTER_ONELINE, dumpzone, fp); @@ -12068,14 +12480,17 @@ nzf_writeconf(const cfg_obj_t *config, dns_view_t *view) result = isc_file_template(view->new_zone_file, "nzf-XXXXXXXX", tmp, sizeof(tmp)); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_file_openunique(tmp, &fp); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } cfg_map_get(config, "zone", &zl); - if (!cfg_obj_islist(zl)) + if (!cfg_obj_islist(zl)) { CHECK(ISC_R_FAILURE); + } DE_CONST(&zl->value.list, list); @@ -12093,14 +12508,16 @@ nzf_writeconf(const cfg_obj_t *config, dns_view_t *view) CHECK(isc_stdio_flush(fp)); result = isc_stdio_close(fp); fp = NULL; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } CHECK(isc_file_rename(tmp, view->new_zone_file)); return (result); cleanup: - if (fp != NULL) + if (fp != NULL) { (void)isc_stdio_close(fp); + } (void)isc_file_remove(tmp); return (result); } @@ -12666,8 +13083,9 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp, CHECK(cfg_parse_buffer(named_g_addparser, &argbuf, bn, 0, &cfg_type_addzoneconf, 0, &zoneconf)); CHECK(cfg_map_get(zoneconf, "zone", &zlist)); - if (!cfg_obj_islist(zlist)) + if (!cfg_obj_islist(zlist)) { CHECK(ISC_R_FAILURE); + } /* For now we only support adding one zone at a time */ zoneobj = cfg_listelt_value(cfg_list_first(zlist)); @@ -12682,8 +13100,9 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp, if (obj != NULL) { (void)putstr(text, "'in-view' zones not supported by "); (void)putstr(text, bn); - } else + } else { (void)putstr(text, "zone type not specified"); + } CHECK(ISC_R_FAILURE); } @@ -12697,8 +13116,9 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp, CHECK(ISC_R_FAILURE); } - if (strcasecmp(cfg_obj_asstring(obj), "redirect") == 0) + if (strcasecmp(cfg_obj_asstring(obj), "redirect") == 0) { redirect = true; + } /* Make sense of optional class argument */ obj = cfg_tuple_get(zoneobj, "class"); @@ -12706,10 +13126,12 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp, /* Make sense of optional view argument */ obj = cfg_tuple_get(zoneobj, "view"); - if (obj && cfg_obj_isstring(obj)) + if (obj && cfg_obj_isstring(obj)) { viewname = cfg_obj_asstring(obj); - if (viewname == NULL || *viewname == '\0') + } + if (viewname == NULL || *viewname == '\0') { viewname = "_default"; + } result = dns_viewlist_find(&server->viewlist, viewname, rdclass, &view); if (result == ISC_R_NOTFOUND) { (void)putstr(text, "no matching view found for '"); @@ -12728,10 +13150,12 @@ newzone_parse(named_server_t *server, char *command, dns_view_t **viewp, return (ISC_R_SUCCESS); cleanup: - if (zoneconf != NULL) + if (zoneconf != NULL) { cfg_obj_destroy(named_g_addparser, &zoneconf); - if (view != NULL) + } + if (view != NULL) { dns_view_detach(&view); + } return (result); } @@ -12756,8 +13180,9 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config, cfg_map_get(config, "zone", &zl); - if (!cfg_obj_islist(zl)) + if (!cfg_obj_islist(zl)) { CHECK(ISC_R_FAILURE); + } DE_CONST(&zl->value.list, list); @@ -12771,8 +13196,9 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config, zn = cfg_obj_asstring(cfg_tuple_get(zconf, "name")); result = dns_name_fromstring(myname, zn, 0, NULL); - if (result != ISC_R_SUCCESS || !dns_name_equal(zname, myname)) + if (result != ISC_R_SUCCESS || !dns_name_equal(zname, myname)) { continue; + } DE_CONST(elt, e); ISC_LIST_UNLINK(*list, e, link); @@ -12785,8 +13211,9 @@ delete_zoneconf(dns_view_t *view, cfg_parser_t *pctx, const cfg_obj_t *config, /* * Write config to NZF file if appropriate */ - if (nzfwriter != NULL && view->new_zone_file != NULL) + if (nzfwriter != NULL && view->new_zone_file != NULL) { result = nzfwriter(config, view); + } cleanup: UNLOCK(&view->new_zone_lock); @@ -12814,8 +13241,9 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, if (redirect) { result = (view->redirect != NULL) ? ISC_R_SUCCESS : ISC_R_NOTFOUND; - } else + } else { result = dns_zt_find(view->zonetable, name, 0, NULL, &zone); + } if (result == ISC_R_SUCCESS) { result = ISC_R_EXISTS; goto cleanup; @@ -12823,8 +13251,9 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, /* Create our sub-zone anyway */ dns_zone_detach(&zone); zone = NULL; - } else if (result != ISC_R_NOTFOUND) + } else if (result != ISC_R_NOTFOUND) { goto cleanup; + } #ifndef HAVE_LMDB /* @@ -12874,8 +13303,9 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, /* Is it there yet? */ if (redirect) { - if (view->redirect == NULL) + if (view->redirect == NULL) { CHECK(ISC_R_NOTFOUND); + } dns_zone_attach(view->redirect, &zone); } else { result = dns_zt_find(view->zonetable, name, 0, NULL, &zone); @@ -12938,7 +13368,7 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, /* Save the new zone configuration into the NZD */ CHECK(nzd_open(view, 0, &txn, &dbi)); CHECK(nzd_save(&txn, dbi, zone, zoneobj)); -#else +#else /* ifdef HAVE_LMDB */ /* Append the zone configuration to the NZF */ result = nzf_append(view, zoneobj); #endif /* HAVE_LMDB */ @@ -12946,20 +13376,23 @@ do_addzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, cleanup: #ifndef HAVE_LMDB - if (fp != NULL) + if (fp != NULL) { (void)isc_stdio_close(fp); + } if (result != ISC_R_SUCCESS && cleanup_config) { tresult = delete_zoneconf(view, cfg->add_parser, cfg->nzf_config, name, NULL); RUNTIME_CHECK(tresult == ISC_R_SUCCESS); } #else /* HAVE_LMDB */ - if (txn != NULL) + if (txn != NULL) { (void)nzd_close(&txn, false); + } #endif /* HAVE_LMDB */ - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -12986,12 +13419,15 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, if (view->redirect != NULL) { dns_zone_attach(view->redirect, &zone); result = ISC_R_SUCCESS; - } else + } else { result = ISC_R_NOTFOUND; - } else + } + } else { result = dns_zt_find(view->zonetable, name, 0, NULL, &zone); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto cleanup; + } added = dns_zone_getadded(zone); dns_zone_detach(&zone); @@ -13002,7 +13438,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, TCHECK(putstr(text, "new zone config is not set")); CHECK(ISC_R_FAILURE); } -#endif +#endif /* ifndef HAVE_LMDB */ result = isc_task_beginexclusive(server->task); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -13051,11 +13487,13 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, /* Is it there yet? */ if (redirect) { - if (view->redirect == NULL) + if (view->redirect == NULL) { CHECK(ISC_R_NOTFOUND); + } dns_zone_attach(view->redirect, &zone); - } else + } else { CHECK(dns_zt_find(view->zonetable, name, 0, NULL, &zone)); + } #ifndef HAVE_LMDB /* Remove old zone from configuration (and NZF file if applicable) */ @@ -13099,8 +13537,9 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, /* * Dynamic zones need no reloading, so we can pass this result. */ - if (result == DNS_R_DYNAMIC) + if (result == DNS_R_DYNAMIC) { result = ISC_R_SUCCESS; + } if (result != ISC_R_SUCCESS) { dns_db_t *dbp = NULL; @@ -13138,7 +13577,7 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, #ifdef HAVE_LMDB CHECK(nzd_open(view, 0, &txn, &dbi)); CHECK(nzd_save(&txn, dbi, zone, zoneobj)); -#else +#else /* ifdef HAVE_LMDB */ result = nzf_append(view, zoneobj); if (result != ISC_R_SUCCESS) { TCHECK(putstr(text, "\nNew zone config not saved: ")); @@ -13150,7 +13589,6 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, TCHECK(putstr(text, "zone '")); TCHECK(putstr(text, zname)); TCHECK(putstr(text, "' reconfigured.")); - } else { TCHECK(putstr(text, "zone '")); TCHECK(putstr(text, zname)); @@ -13159,19 +13597,23 @@ do_modzone(named_server_t *server, ns_cfgctx_t *cfg, dns_view_t *view, } cleanup: - if (exclusive) + if (exclusive) { isc_task_endexclusive(server->task); + } #ifndef HAVE_LMDB - if (fp != NULL) + if (fp != NULL) { (void)isc_stdio_close(fp); + } #else /* HAVE_LMDB */ - if (txn != NULL) + if (txn != NULL) { (void)nzd_close(&txn, false); + } #endif /* HAVE_LMDB */ - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -13195,9 +13637,9 @@ named_server_changezone(named_server_t *server, char *command, dns_fixedname_t fname; dns_name_t * dnsname; - if (strncasecmp(command, "add", 3) == 0) + if (strncasecmp(command, "add", 3) == 0) { addzone = true; - else { + } else { INSIST(strncasecmp(command, "mod", 3) == 0); addzone = false; } @@ -13208,7 +13650,7 @@ named_server_changezone(named_server_t *server, char *command, /* Are we accepting new zones in this view? */ #ifdef HAVE_LMDB if (view->new_zone_db == NULL) -#else +#else /* ifdef HAVE_LMDB */ if (view->new_zone_file == NULL) #endif /* HAVE_LMDB */ { @@ -13240,12 +13682,13 @@ named_server_changezone(named_server_t *server, char *command, } } - if (addzone) + if (addzone) { CHECK(do_addzone(server, cfg, view, dnsname, zoneconf, zoneobj, redirect, text)); - else + } else { CHECK(do_modzone(server, cfg, view, dnsname, zonename, zoneobj, redirect, text)); + } isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_INFO, @@ -13257,12 +13700,15 @@ named_server_changezone(named_server_t *server, char *command, CHECK(isc_time_now(&named_g_configtime)); cleanup: - if (isc_buffer_usedlength(*text) > 0) + if (isc_buffer_usedlength(*text) > 0) { (void)putnull(text); - if (zoneconf != NULL) + } + if (zoneconf != NULL) { cfg_obj_destroy(named_g_addparser, &zoneconf); - if (view != NULL) + } + if (view != NULL) { dns_view_detach(&view); + } return (result); } @@ -13271,11 +13717,12 @@ static bool inuse(const char *file, bool first, isc_buffer_t **text) { if (file != NULL && isc_file_exists(file)) { - if (first) + if (first) { (void)putstr(text, "The following files were in use " "and may now be removed:\n"); - else + } else { (void)putstr(text, "\n"); + } (void)putstr(text, file); (void)putnull(text); return (false); @@ -13305,7 +13752,7 @@ rmzone(isc_task_t *task, isc_event_t *event) #ifdef HAVE_LMDB MDB_txn *txn = NULL; MDB_dbi dbi; -#endif +#endif /* ifdef HAVE_LMDB */ REQUIRE(dz != NULL); @@ -13345,7 +13792,7 @@ rmzone(isc_task_t *task, isc_event_t *event) "delete zone configuration: %s", isc_result_totext(result)); } -#else +#else /* ifdef HAVE_LMDB */ result = delete_zoneconf(view, cfg->add_parser, cfg->nzf_config, dns_zone_getorigin(zone), nzf_writeconf); @@ -13435,11 +13882,13 @@ rmzone(isc_task_t *task, isc_event_t *event) } #ifdef HAVE_LMDB - if (txn != NULL) + if (txn != NULL) { (void)nzd_close(&txn, false); -#endif - if (raw != NULL) + } +#endif /* ifdef HAVE_LMDB */ + if (raw != NULL) { dns_zone_detach(&raw); + } dns_zone_detach(&zone); isc_mem_put(named_g_mctx, dz, sizeof(*dz)); isc_task_detach(&task); @@ -13467,13 +13916,15 @@ named_server_delzone(named_server_t *server, isc_lex_t *lex, /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Find out what we are to do. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } if (strcmp(ptr, "-clean") == 0 || strcmp(ptr, "-clear") == 0) { cleanup = true; @@ -13499,10 +13950,11 @@ named_server_delzone(named_server_t *server, isc_lex_t *lex, } view = dns_zone_getview(zone); - if (dns_zone_gettype(zone) == dns_zone_redirect) + if (dns_zone_gettype(zone) == dns_zone_redirect) { dns_zone_detach(&view->redirect); - else + } else { CHECK(dns_zt_unmount(view->zonetable, zone)); + } /* Send cleanup event */ dz = isc_mem_get(named_g_mctx, sizeof(*dz)); @@ -13569,12 +14021,15 @@ named_server_delzone(named_server_t *server, isc_lex_t *lex, result = ISC_R_SUCCESS; cleanup: - if (isc_buffer_usedlength(*text) > 0) + if (isc_buffer_usedlength(*text) > 0) { (void)putnull(text); - if (raw != NULL) + } + if (raw != NULL) { dns_zone_detach(&raw); - if (zone != NULL) + } + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -13619,17 +14074,20 @@ find_name_in_list_from_map(const cfg_obj_t *config, const cfg_obj_t *typeobj = NULL; zoptions = cfg_tuple_get(obj, "options"); - if (zoptions != NULL) + if (zoptions != NULL) { cfg_map_get(zoptions, "type", &typeobj); + } if (redirect && typeobj != NULL && strcasecmp(cfg_obj_asstring(typeobj), - "redirect") == 0) + "redirect") == 0) { break; - else if (!redirect) + } else if (!redirect) { break; + } } - } else if (strcasecmp(vname, name) == 0) + } else if (strcasecmp(vname, name) == 0) { break; + } obj = NULL; } @@ -13699,33 +14157,37 @@ named_server_showzone(named_server_t *server, isc_lex_t *lex, view->name, false); /* Find the zone statement */ - if (vconfig != NULL) + if (vconfig != NULL) { map = cfg_tuple_get(vconfig, "options"); - else + } else { map = cfg->config; + } zconfig = find_name_in_list_from_map(map, "zone", zonename, redirect); } #ifndef HAVE_LMDB - if (zconfig == NULL && cfg->nzf_config != NULL) + if (zconfig == NULL && cfg->nzf_config != NULL) { zconfig = find_name_in_list_from_map(cfg->nzf_config, "zone", zonename, redirect); + } #else /* HAVE_LMDB */ if (zconfig == NULL) { const cfg_obj_t *zlist = NULL; CHECK(get_newzone_config(view, zonename, &nzconfig)); CHECK(cfg_map_get(nzconfig, "zone", &zlist)); - if (!cfg_obj_islist(zlist)) + if (!cfg_obj_islist(zlist)) { CHECK(ISC_R_FAILURE); + } zconfig = cfg_listelt_value(cfg_list_first(zlist)); } #endif /* HAVE_LMDB */ - if (zconfig == NULL) + if (zconfig == NULL) { CHECK(ISC_R_NOTFOUND); + } CHECK(putstr(text, "zone ")); dzarg.magic = DZARG_MAGIC; @@ -13740,13 +14202,16 @@ named_server_showzone(named_server_t *server, isc_lex_t *lex, cleanup: #ifdef HAVE_LMDB - if (nzconfig != NULL) + if (nzconfig != NULL) { cfg_obj_destroy(named_g_addparser, &nzconfig); + } #endif /* HAVE_LMDB */ - if (isc_buffer_usedlength(*text) > 0) + if (isc_buffer_usedlength(*text) > 0) { (void)putnull(text); - if (exclusive) + } + if (exclusive) { isc_task_endexclusive(server->task); + } return (result); } @@ -13761,20 +14226,24 @@ newzone_cfgctx_destroy(void **cfgp) cfg = *cfgp; if (cfg->conf_parser != NULL) { - if (cfg->config != NULL) + if (cfg->config != NULL) { cfg_obj_destroy(cfg->conf_parser, &cfg->config); - if (cfg->vconfig != NULL) + } + if (cfg->vconfig != NULL) { cfg_obj_destroy(cfg->conf_parser, &cfg->vconfig); + } cfg_parser_destroy(&cfg->conf_parser); } if (cfg->add_parser != NULL) { - if (cfg->nzf_config != NULL) + if (cfg->nzf_config != NULL) { cfg_obj_destroy(cfg->add_parser, &cfg->nzf_config); + } cfg_parser_destroy(&cfg->add_parser); } - if (cfg->actx != NULL) + if (cfg->actx != NULL) { cfg_aclconfctx_detach(&cfg->actx); + } isc_mem_putanddetach(&cfg->mctx, cfg, sizeof(*cfg)); *cfgp = NULL; @@ -13788,8 +14257,9 @@ generate_salt(unsigned char *salt, size_t saltlen) isc_buffer_t buf; isc_result_t result; - if (saltlen > 256U) + if (saltlen > 256U) { return (ISC_R_RANGE); + } isc_nonce_buf(salt, saltlen); @@ -13835,22 +14305,25 @@ named_server_signing(named_server_t *server, isc_lex_t *lex, /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* Find out what we are to do. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } - if (strcasecmp(ptr, "-list") == 0) + if (strcasecmp(ptr, "-list") == 0) { list = true; - else if ((strcasecmp(ptr, "-clear") == 0) || - (strcasecmp(ptr, "-clean") == 0)) { + } else if ((strcasecmp(ptr, "-clear") == 0) || + (strcasecmp(ptr, "-clean") == 0)) { clear = true; ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } strlcpy(keystr, ptr, sizeof(keystr)); } else if (strcasecmp(ptr, "-nsec3param") == 0) { char hashbuf[64], flagbuf[64], iterbuf[64]; @@ -13858,34 +14331,40 @@ named_server_signing(named_server_t *server, isc_lex_t *lex, chain = true; ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } - if (strcasecmp(ptr, "none") == 0) + if (strcasecmp(ptr, "none") == 0) { hash = 0; - else { + } else { strlcpy(hashbuf, ptr, sizeof(hashbuf)); ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } strlcpy(flagbuf, ptr, sizeof(flagbuf)); ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } strlcpy(iterbuf, ptr, sizeof(iterbuf)); n = snprintf(nbuf, sizeof(nbuf), "%s %s %s", hashbuf, flagbuf, iterbuf); - if (n == sizeof(nbuf)) + if (n == sizeof(nbuf)) { return (ISC_R_NOSPACE); + } n = sscanf(nbuf, "%hu %hu %hu", &hash, &flags, &iter); - if (n != 3U) + if (n != 3U) { return (ISC_R_BADNUMBER); + } - if (hash > 0xffU || flags > 0xffU) + if (hash > 0xffU || flags > 0xffU) { return (ISC_R_RANGE); + } ptr = next_token(lex, text); if (ptr == NULL) { @@ -13909,16 +14388,19 @@ named_server_signing(named_server_t *server, isc_lex_t *lex, } } else if (strcasecmp(ptr, "-serial") == 0) { ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } CHECK(isc_parse_uint32(&serial, ptr, 10)); setserial = true; - } else + } else { CHECK(DNS_R_SYNTAX); + } CHECK(zone_from_args(server, lex, NULL, &zone, NULL, text, false)); - if (zone == NULL) + if (zone == NULL) { CHECK(ISC_R_UNEXPECTEDEND); + } if (clear) { CHECK(dns_zone_keydone(zone, keystr)); @@ -13962,29 +14444,37 @@ named_server_signing(named_server_t *server, isc_lex_t *lex, isc_buffer_init(&buf, output, sizeof(output)); CHECK(dns_private_totext(&priv, &buf)); - if (!first) + if (!first) { CHECK(putstr(text, "\n")); + } CHECK(putstr(text, output)); first = false; } - if (!first) + if (!first) { CHECK(putnull(text)); + } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } } cleanup: - if (dns_rdataset_isassociated(&privset)) + if (dns_rdataset_isassociated(&privset)) { dns_rdataset_disassociate(&privset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); - if (version != NULL) + } + if (version != NULL) { dns_db_closeversion(db, &version, false); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); - if (zone != NULL) + } + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -13995,8 +14485,9 @@ putmem(isc_buffer_t **b, const char *str, size_t len) isc_result_t result; result = isc_buffer_reserve(b, (unsigned int)len); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putmem(*b, (const unsigned char *)str, (unsigned int)len); return (ISC_R_SUCCESS); @@ -14014,8 +14505,9 @@ putuint8(isc_buffer_t **b, uint8_t val) isc_result_t result; result = isc_buffer_reserve(b, 1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(*b, val); return (ISC_R_SUCCESS); @@ -14326,13 +14818,15 @@ argcheck(char *cmd, const char *full) { size_t l; - if (cmd == NULL || cmd[0] != '-') + if (cmd == NULL || cmd[0] != '-') { return (false); + } cmd++; l = strlen(cmd); - if (l > strlen(full) || strncasecmp(cmd, full, l) != 0) + if (l > strlen(full) || strncasecmp(cmd, full, l) != 0) { return (false); + } return (true); } @@ -14781,8 +15275,9 @@ mkey_dumpzone(dns_view_t *view, isc_buffer_t **text) dns_rriterator_current(&rrit, &name, &ttl, &kdset, NULL); if (kdset == NULL || kdset->type != dns_rdatatype_keydata || - !dns_rdataset_isassociated(kdset)) + !dns_rdataset_isassociated(kdset)) { continue; + } if (name != prevname) { char nbuf[DNS_NAME_FORMATSIZE]; @@ -14842,30 +15337,33 @@ mkey_dumpzone(dns_view_t *view, isc_buffer_t **text) isc_time_set(&t, kd.addhd, 0); isc_time_formathttptimestamp(&t, tbuf, sizeof(tbuf)); - if (kd.addhd == 0) + if (kd.addhd == 0) { snprintf(buf, sizeof(buf), "\n\tno trust"); - else if (revoked) + } else if (revoked) { snprintf(buf, sizeof(buf), "\n\ttrust revoked"); - else if (kd.addhd <= now) + } else if (kd.addhd <= now) { snprintf(buf, sizeof(buf), "\n\ttrusted since: %s", tbuf); - else if (kd.addhd > now) + } else if (kd.addhd > now) { snprintf(buf, sizeof(buf), "\n\ttrust pending: %s", tbuf); + } CHECK(putstr(text, buf)); } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: if (ver != NULL) { dns_rriterator_destroy(&rrit); dns_db_closeversion(db, &ver, false); } - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } return (result); } @@ -15025,21 +15523,24 @@ named_server_dnstap(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) bool reopen = false; int backups = 0; - if (server->dtenv == NULL) + if (server->dtenv == NULL) { return (ISC_R_NOTFOUND); + } /* Check the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } /* "dnstap-reopen" was used in 9.11.0b1 */ if (strcasecmp(ptr, "dnstap-reopen") == 0) { reopen = true; } else { ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } } if (reopen || strcasecmp(ptr, "-reopen") == 0) { @@ -15050,8 +15551,9 @@ named_server_dnstap(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) if (ptr != NULL) { unsigned int u; n = sscanf(ptr, "%u", &u); - if (n != 1U || u > INT_MAX) + if (n != 1U || u > INT_MAX) { return (ISC_R_BADNUMBER); + } backups = u; } else { backups = ISC_LOG_ROLLINFINITE; @@ -15062,12 +15564,12 @@ named_server_dnstap(named_server_t *server, isc_lex_t *lex, isc_buffer_t **text) result = dns_dt_reopen(server->dtenv, backups); return (result); -#else +#else /* ifdef HAVE_DNSTAP */ UNUSED(server); UNUSED(lex); UNUSED(text); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef HAVE_DNSTAP */ } isc_result_t @@ -15080,8 +15582,9 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } isc_nm_tcp_gettimeouts(named_g_nm, &initial, &idle, &keepalive, &advertised); @@ -15090,35 +15593,45 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) ptr = next_token(lex, NULL); if (ptr != NULL) { CHECK(isc_parse_uint32(&initial, ptr, 10)); - if (initial > 1200) + if (initial > 1200) { CHECK(ISC_R_RANGE); - if (initial < 25) + } + if (initial < 25) { CHECK(ISC_R_RANGE); + } ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } CHECK(isc_parse_uint32(&idle, ptr, 10)); - if (idle > 1200) + if (idle > 1200) { CHECK(ISC_R_RANGE); - if (idle < 1) + } + if (idle < 1) { CHECK(ISC_R_RANGE); + } ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } CHECK(isc_parse_uint32(&keepalive, ptr, 10)); - if (keepalive > MAX_TCP_TIMEOUT) + if (keepalive > MAX_TCP_TIMEOUT) { CHECK(ISC_R_RANGE); - if (keepalive < 1) + } + if (keepalive < 1) { CHECK(ISC_R_RANGE); + } ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } CHECK(isc_parse_uint32(&advertised, ptr, 10)); - if (advertised > MAX_TCP_TIMEOUT) + if (advertised > MAX_TCP_TIMEOUT) { CHECK(ISC_R_RANGE); + } result = isc_task_beginexclusive(named_g_server->task); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -15139,8 +15652,9 @@ named_server_tcptimeouts(isc_lex_t *lex, isc_buffer_t **text) CHECK(putstr(text, msg)); cleanup: - if (isc_buffer_usedlength(*text) > 0) + if (isc_buffer_usedlength(*text) > 0) { (void)putnull(text); + } return (result); } @@ -15161,12 +15675,14 @@ named_server_servestale(named_server_t *server, isc_lex_t *lex, /* Skip the command name. */ ptr = next_token(lex, text); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } ptr = next_token(lex, NULL); - if (ptr == NULL) + if (ptr == NULL) { return (ISC_R_UNEXPECTEDEND); + } if (!strcasecmp(ptr, "on") || !strcasecmp(ptr, "yes") || !strcasecmp(ptr, "enable") || !strcasecmp(ptr, "true")) { @@ -15178,8 +15694,9 @@ named_server_servestale(named_server_t *server, isc_lex_t *lex, staleanswersok = dns_stale_answer_conf; } else if (!strcasecmp(ptr, "check") || !strcasecmp(ptr, "status")) { wantstatus = true; - } else + } else { return (DNS_R_SYNTAX); + } /* Look for the optional class name. */ classtxt = next_token(lex, text); @@ -15217,11 +15734,13 @@ named_server_servestale(named_server_t *server, isc_lex_t *lex, dns_ttl_t stale_ttl = 0; dns_db_t *db = NULL; - if (classtxt != NULL && rdclass != view->rdclass) + if (classtxt != NULL && rdclass != view->rdclass) { continue; + } - if (viewtxt != NULL && strcmp(view->name, viewtxt) != 0) + if (viewtxt != NULL && strcmp(view->name, viewtxt) != 0) { continue; + } if (!wantstatus) { view->staleanswersok = staleanswersok; @@ -15233,27 +15752,30 @@ named_server_servestale(named_server_t *server, isc_lex_t *lex, dns_db_attach(view->cachedb, &db); (void)dns_db_getservestalettl(db, &stale_ttl); dns_db_detach(&db); - if (found) + if (found) { CHECK(putstr(text, "\n")); + } CHECK(putstr(text, view->name)); CHECK(putstr(text, ": ")); switch (view->staleanswersok) { case dns_stale_answer_yes: - if (stale_ttl > 0) + if (stale_ttl > 0) { CHECK(putstr(text, "on (rndc)")); - else + } else { CHECK(putstr(text, "off (not-cached)")); + } break; case dns_stale_answer_no: CHECK(putstr(text, "off (rndc)")); break; case dns_stale_answer_conf: - if (view->staleanswersenable && stale_ttl > 0) + if (view->staleanswersenable && stale_ttl > 0) { CHECK(putstr(text, "on")); - else if (view->staleanswersenable) + } else if (view->staleanswersenable) { CHECK(putstr(text, "off (not-cached)")); - else + } else { CHECK(putstr(text, "off")); + } break; } if (stale_ttl > 0) { @@ -15265,15 +15787,18 @@ named_server_servestale(named_server_t *server, isc_lex_t *lex, found = true; } - if (!found) + if (!found) { result = ISC_R_NOTFOUND; + } cleanup: - if (exclusive) + if (exclusive) { isc_task_endexclusive(named_g_server->task); + } - if (isc_buffer_usedlength(*text) > 0) + if (isc_buffer_usedlength(*text) > 0) { (void)putnull(text); + } return (result); } diff --git a/bin/named/statschannel.c b/bin/named/statschannel.c index 7d37a1b56d..606b373973 100644 --- a/bin/named/statschannel.c +++ b/bin/named/statschannel.c @@ -85,9 +85,9 @@ static isc_once_t once = ISC_ONCE_INIT; #if defined(HAVE_LIBXML2) || defined(HAVE_JSON_C) #define EXTENDED_STATS -#else +#else /* if defined(HAVE_LIBXML2) || defined(HAVE_JSON_C) */ #undef EXTENDED_STATS -#endif +#endif /* if defined(HAVE_LIBXML2) || defined(HAVE_JSON_C) */ #ifdef EXTENDED_STATS static const char * @@ -110,19 +110,22 @@ user_zonetype(dns_zone_t *zone) { 0, NULL } }; const struct zt *tp; - if ((dns_zone_getoptions(zone) & DNS_ZONEOPT_AUTOEMPTY) != 0) + if ((dns_zone_getoptions(zone) & DNS_ZONEOPT_AUTOEMPTY) != 0) { return ("builtin"); + } view = dns_zone_getview(zone); - if (view != NULL && strcmp(view->name, "_bind") == 0) + if (view != NULL && strcmp(view->name, "_bind") == 0) { return ("builtin"); + } ztype = dns_zone_gettype(zone); - for (tp = typemap; tp->string != NULL && tp->type != ztype; tp++) - /* empty */; + for (tp = typemap; tp->string != NULL && tp->type != ztype; tp++) { + /* empty */ + } return (tp->string); } -#endif +#endif /* ifdef EXTENDED_STATS */ /*% * Statistics descriptions. These could be statistically initialized at @@ -154,7 +157,7 @@ static const char *tcpinsizestats_xmldesc[dns_sizecounter_in_max]; static const char *tcpoutsizestats_xmldesc[dns_sizecounter_out_max]; static const char *dnstapstats_xmldesc[dns_dnstapcounter_max]; static const char *gluecachestats_xmldesc[dns_gluecachestatscounter_max]; -#else +#else /* if defined(EXTENDED_STATS) */ #define nsstats_xmldesc NULL #define resstats_xmldesc NULL #define adbstats_xmldesc NULL @@ -202,15 +205,15 @@ set_desc(int counter, int maxcounter, const char *fdesc, const char **fdescs, REQUIRE(fdescs != NULL && fdescs[counter] == NULL); #if defined(EXTENDED_STATS) REQUIRE(xdescs != NULL && xdescs[counter] == NULL); -#endif +#endif /* if defined(EXTENDED_STATS) */ fdescs[counter] = fdesc; #if defined(EXTENDED_STATS) xdescs[counter] = xdesc; -#else +#else /* if defined(EXTENDED_STATS) */ UNUSED(xdesc); UNUSED(xdescs); -#endif +#endif /* if defined(EXTENDED_STATS) */ } static void @@ -219,12 +222,14 @@ init_desc(void) int i; /* Initialize name server statistics */ - for (i = 0; i < ns_statscounter_max; i++) + for (i = 0; i < ns_statscounter_max; i++) { nsstats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < ns_statscounter_max; i++) + for (i = 0; i < ns_statscounter_max; i++) { nsstats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_NSSTATDESC(counterid, desc, xmldesc) \ do { \ @@ -338,12 +343,14 @@ init_desc(void) INSIST(i == ns_statscounter_max); /* Initialize resolver statistics */ - for (i = 0; i < dns_resstatscounter_max; i++) + for (i = 0; i < dns_resstatscounter_max; i++) { resstats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < dns_resstatscounter_max; i++) + for (i = 0; i < dns_resstatscounter_max; i++) { resstats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_RESSTATDESC(counterid, desc, xmldesc) \ do { \ @@ -427,12 +434,14 @@ init_desc(void) INSIST(i == dns_resstatscounter_max); /* Initialize adb statistics */ - for (i = 0; i < dns_adbstats_max; i++) + for (i = 0; i < dns_adbstats_max; i++) { adbstats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < dns_adbstats_max; i++) + for (i = 0; i < dns_adbstats_max; i++) { adbstats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_ADBSTATDESC(id, desc, xmldesc) \ do { \ @@ -449,12 +458,14 @@ init_desc(void) INSIST(i == dns_adbstats_max); /* Initialize zone statistics */ - for (i = 0; i < dns_zonestatscounter_max; i++) + for (i = 0; i < dns_zonestatscounter_max; i++) { zonestats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < dns_zonestatscounter_max; i++) + for (i = 0; i < dns_zonestatscounter_max; i++) { zonestats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_ZONESTATDESC(counterid, desc, xmldesc) \ do { \ @@ -482,12 +493,14 @@ init_desc(void) INSIST(i == dns_zonestatscounter_max); /* Initialize socket statistics */ - for (i = 0; i < isc_sockstatscounter_max; i++) + for (i = 0; i < isc_sockstatscounter_max; i++) { sockstats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < isc_sockstatscounter_max; i++) + for (i = 0; i < isc_sockstatscounter_max; i++) { sockstats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_SOCKSTATDESC(counterid, desc, xmldesc) \ do { \ @@ -601,12 +614,14 @@ init_desc(void) INSIST(i == isc_sockstatscounter_max); /* Initialize DNSSEC statistics */ - for (i = 0; i < dns_dnssecstats_max; i++) + for (i = 0; i < dns_dnssecstats_max; i++) { dnssecstats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < dns_dnssecstats_max; i++) + for (i = 0; i < dns_dnssecstats_max; i++) { dnssecstats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_DNSSECSTATDESC(counterid, desc, xmldesc) \ do { \ @@ -631,12 +646,14 @@ init_desc(void) INSIST(i == dns_dnssecstats_max); /* Initialize dnstap statistics */ - for (i = 0; i < dns_dnstapcounter_max; i++) + for (i = 0; i < dns_dnstapcounter_max; i++) { dnstapstats_desc[i] = NULL; + } #if defined(EXTENDED_STATS) - for (i = 0; i < dns_dnstapcounter_max; i++) + for (i = 0; i < dns_dnstapcounter_max; i++) { dnstapstats_xmldesc[i] = NULL; -#endif + } +#endif /* if defined(EXTENDED_STATS) */ #define SET_DNSTAPSTATDESC(counterid, desc, xmldesc) \ do { \ @@ -674,40 +691,56 @@ init_desc(void) INSIST(i == dns_gluecachestatscounter_max); /* Sanity check */ - for (i = 0; i < ns_statscounter_max; i++) + for (i = 0; i < ns_statscounter_max; i++) { INSIST(nsstats_desc[i] != NULL); - for (i = 0; i < dns_resstatscounter_max; i++) + } + for (i = 0; i < dns_resstatscounter_max; i++) { INSIST(resstats_desc[i] != NULL); - for (i = 0; i < dns_adbstats_max; i++) + } + for (i = 0; i < dns_adbstats_max; i++) { INSIST(adbstats_desc[i] != NULL); - for (i = 0; i < dns_zonestatscounter_max; i++) + } + for (i = 0; i < dns_zonestatscounter_max; i++) { INSIST(zonestats_desc[i] != NULL); - for (i = 0; i < isc_sockstatscounter_max; i++) + } + for (i = 0; i < isc_sockstatscounter_max; i++) { INSIST(sockstats_desc[i] != NULL); - for (i = 0; i < dns_dnssecstats_max; i++) + } + for (i = 0; i < dns_dnssecstats_max; i++) { INSIST(dnssecstats_desc[i] != NULL); - for (i = 0; i < dns_dnstapcounter_max; i++) + } + for (i = 0; i < dns_dnstapcounter_max; i++) { INSIST(dnstapstats_desc[i] != NULL); - for (i = 0; i < dns_gluecachestatscounter_max; i++) + } + for (i = 0; i < dns_gluecachestatscounter_max; i++) { INSIST(gluecachestats_desc[i] != NULL); + } #if defined(EXTENDED_STATS) - for (i = 0; i < ns_statscounter_max; i++) + for (i = 0; i < ns_statscounter_max; i++) { INSIST(nsstats_xmldesc[i] != NULL); - for (i = 0; i < dns_resstatscounter_max; i++) + } + for (i = 0; i < dns_resstatscounter_max; i++) { INSIST(resstats_xmldesc[i] != NULL); - for (i = 0; i < dns_adbstats_max; i++) + } + for (i = 0; i < dns_adbstats_max; i++) { INSIST(adbstats_xmldesc[i] != NULL); - for (i = 0; i < dns_zonestatscounter_max; i++) + } + for (i = 0; i < dns_zonestatscounter_max; i++) { INSIST(zonestats_xmldesc[i] != NULL); - for (i = 0; i < isc_sockstatscounter_max; i++) + } + for (i = 0; i < isc_sockstatscounter_max; i++) { INSIST(sockstats_xmldesc[i] != NULL); - for (i = 0; i < dns_dnssecstats_max; i++) + } + for (i = 0; i < dns_dnssecstats_max; i++) { INSIST(dnssecstats_xmldesc[i] != NULL); - for (i = 0; i < dns_dnstapcounter_max; i++) + } + for (i = 0; i < dns_dnstapcounter_max; i++) { INSIST(dnstapstats_xmldesc[i] != NULL); - for (i = 0; i < dns_gluecachestatscounter_max; i++) + } + for (i = 0; i < dns_gluecachestatscounter_max; i++) { INSIST(gluecachestats_xmldesc[i] != NULL); -#endif + } +#endif /* if defined(EXTENDED_STATS) */ /* Initialize traffic size statistics */ for (i = 0; i < dns_sizecounter_in_max; i++) { @@ -716,7 +749,7 @@ init_desc(void) #if defined(EXTENDED_STATS) udpinsizestats_xmldesc[i] = NULL; tcpinsizestats_xmldesc[i] = NULL; -#endif +#endif /* if defined(EXTENDED_STATS) */ } for (i = 0; i < dns_sizecounter_out_max; i++) { udpoutsizestats_desc[i] = NULL; @@ -724,7 +757,7 @@ init_desc(void) #if defined(EXTENDED_STATS) udpoutsizestats_xmldesc[i] = NULL; tcpoutsizestats_xmldesc[i] = NULL; -#endif +#endif /* if defined(EXTENDED_STATS) */ } #define SET_SIZESTATDESC(counterid, desc, xmldesc, inout) \ @@ -1220,18 +1253,24 @@ init_desc(void) INSIST(i == dns_sizecounter_out_max); /* Sanity check */ - for (i = 0; i < ns_statscounter_max; i++) + for (i = 0; i < ns_statscounter_max; i++) { INSIST(nsstats_desc[i] != NULL); - for (i = 0; i < dns_resstatscounter_max; i++) + } + for (i = 0; i < dns_resstatscounter_max; i++) { INSIST(resstats_desc[i] != NULL); - for (i = 0; i < dns_adbstats_max; i++) + } + for (i = 0; i < dns_adbstats_max; i++) { INSIST(adbstats_desc[i] != NULL); - for (i = 0; i < dns_zonestatscounter_max; i++) + } + for (i = 0; i < dns_zonestatscounter_max; i++) { INSIST(zonestats_desc[i] != NULL); - for (i = 0; i < isc_sockstatscounter_max; i++) + } + for (i = 0; i < isc_sockstatscounter_max; i++) { INSIST(sockstats_desc[i] != NULL); - for (i = 0; i < dns_dnssecstats_max; i++) + } + for (i = 0; i < dns_dnssecstats_max; i++) { INSIST(dnssecstats_desc[i] != NULL); + } for (i = 0; i < dns_sizecounter_in_max; i++) { INSIST(udpinsizestats_desc[i] != NULL); INSIST(tcpinsizestats_desc[i] != NULL); @@ -1241,18 +1280,24 @@ init_desc(void) INSIST(tcpoutsizestats_desc[i] != NULL); } #if defined(EXTENDED_STATS) - for (i = 0; i < ns_statscounter_max; i++) + for (i = 0; i < ns_statscounter_max; i++) { INSIST(nsstats_xmldesc[i] != NULL); - for (i = 0; i < dns_resstatscounter_max; i++) + } + for (i = 0; i < dns_resstatscounter_max; i++) { INSIST(resstats_xmldesc[i] != NULL); - for (i = 0; i < dns_adbstats_max; i++) + } + for (i = 0; i < dns_adbstats_max; i++) { INSIST(adbstats_xmldesc[i] != NULL); - for (i = 0; i < dns_zonestatscounter_max; i++) + } + for (i = 0; i < dns_zonestatscounter_max; i++) { INSIST(zonestats_xmldesc[i] != NULL); - for (i = 0; i < isc_sockstatscounter_max; i++) + } + for (i = 0; i < isc_sockstatscounter_max; i++) { INSIST(sockstats_xmldesc[i] != NULL); - for (i = 0; i < dns_dnssecstats_max; i++) + } + for (i = 0; i < dns_dnssecstats_max; i++) { INSIST(dnssecstats_xmldesc[i] != NULL); + } for (i = 0; i < dns_sizecounter_in_max; i++) { INSIST(udpinsizestats_xmldesc[i] != NULL); INSIST(tcpinsizestats_xmldesc[i] != NULL); @@ -1261,7 +1306,7 @@ init_desc(void) INSIST(udpoutsizestats_xmldesc[i] != NULL); INSIST(tcpoutsizestats_xmldesc[i] != NULL); } -#endif +#endif /* if defined(EXTENDED_STATS) */ } /*% @@ -1288,14 +1333,14 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg, #ifdef HAVE_LIBXML2 void *writer; int xmlrc; -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C json_object *job, *cat, *counter; -#endif +#endif /* ifdef HAVE_JSON_C */ #if !defined(EXTENDED_STATS) UNUSED(category); -#endif +#endif /* if !defined(EXTENDED_STATS) */ dumparg.type = type; dumparg.ncounters = ncounters; @@ -1310,19 +1355,21 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg, if (ncounters > 0 && type == isc_statsformat_json) { if (category != NULL) { cat = json_object_new_object(); - if (cat == NULL) + if (cat == NULL) { return (ISC_R_NOMEMORY); + } json_object_object_add(job, category, cat); } } -#endif +#endif /* ifdef HAVE_JSON_C */ for (i = 0; i < ncounters; i++) { idx = indices[i]; value = values[idx]; - if (value == 0 && (options & ISC_STATSDUMP_VERBOSE) == 0) + if (value == 0 && (options & ISC_STATSDUMP_VERBOSE) == 0) { continue; + } switch (dumparg.type) { case isc_statsformat_file: @@ -1356,7 +1403,6 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg, /* */ TRY0(xmlTextWriterEndElement(writer)); /* */ - } else { TRY0(xmlTextWriterStartElement( writer, ISC_XMLCHAR "counter")); @@ -1369,15 +1415,16 @@ dump_counters(isc_stats_t *stats, isc_statsformat_t type, void *arg, /* counter */ } -#endif +#endif /* ifdef HAVE_LIBXML2 */ break; case isc_statsformat_json: #ifdef HAVE_JSON_C counter = json_object_new_int64(value); - if (counter == NULL) + if (counter == NULL) { return (ISC_R_NOMEMORY); + } json_object_object_add(cat, desc[idx], counter); -#endif +#endif /* ifdef HAVE_JSON_C */ break; } } @@ -1388,7 +1435,7 @@ error: NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "failed at dump_counters()"); return (ISC_R_FAILURE); -#endif +#endif /* ifdef HAVE_LIBXML2 */ } static void @@ -1401,18 +1448,19 @@ rdtypestat_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) #ifdef HAVE_LIBXML2 void *writer; int xmlrc; -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C json_object *zoneobj, *obj; -#endif +#endif /* ifdef HAVE_JSON_C */ if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_OTHERTYPE) == 0) { dns_rdatatype_format(DNS_RDATASTATSTYPE_BASE(type), typebuf, sizeof(typebuf)); typestr = typebuf; - } else + } else { typestr = "Others"; + } switch (dumparg->type) { case isc_statsformat_file: @@ -1430,16 +1478,17 @@ rdtypestat_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, val)); TRY0(xmlTextWriterEndElement(writer)); /* type */ -#endif +#endif /* ifdef HAVE_LIBXML2 */ break; case isc_statsformat_json: #ifdef HAVE_JSON_C zoneobj = (json_object *)dumparg->arg; obj = json_object_new_int64(val); - if (obj == NULL) + if (obj == NULL) { return; + } json_object_object_add(zoneobj, typestr, obj); -#endif +#endif /* ifdef HAVE_JSON_C */ break; } return; @@ -1450,7 +1499,7 @@ error: "failed at rdtypestat_dump()"); dumparg->result = ISC_R_FAILURE; return; -#endif +#endif /* ifdef HAVE_LIBXML2 */ } static bool @@ -1472,11 +1521,11 @@ rdatasetstats_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) #ifdef HAVE_LIBXML2 void *writer; int xmlrc; -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C json_object *zoneobj, *obj; char buf[1024]; -#endif +#endif /* ifdef HAVE_JSON_C */ if ((DNS_RDATASTATSTYPE_ATTR(type) & DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) != 0) { @@ -1516,7 +1565,7 @@ rdatasetstats_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) TRY0(xmlTextWriterEndElement(writer)); /* counter */ TRY0(xmlTextWriterEndElement(writer)); /* rrset */ -#endif +#endif /* ifdef HAVE_LIBXML2 */ break; case isc_statsformat_json: #ifdef HAVE_JSON_C @@ -1524,10 +1573,11 @@ rdatasetstats_dump(dns_rdatastatstype_t type, uint64_t val, void *arg) snprintf(buf, sizeof(buf), "%s%s%s%s", ancient ? "~" : "", stale ? "#" : "", nxrrset ? "!" : "", typestr); obj = json_object_new_int64(val); - if (obj == NULL) + if (obj == NULL) { return; + } json_object_object_add(zoneobj, buf, obj); -#endif +#endif /* ifdef HAVE_JSON_C */ break; } return; @@ -1537,7 +1587,7 @@ error: NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "failed at rdatasetstats_dump()"); dumparg->result = ISC_R_FAILURE; -#endif +#endif /* ifdef HAVE_LIBXML2 */ } static void @@ -1550,10 +1600,10 @@ opcodestat_dump(dns_opcode_t code, uint64_t val, void *arg) #ifdef HAVE_LIBXML2 void *writer; int xmlrc; -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C json_object *zoneobj, *obj; -#endif +#endif /* ifdef HAVE_JSON_C */ isc_buffer_init(&b, codebuf, sizeof(codebuf) - 1); dns_opcode_totext(code, &b); @@ -1572,16 +1622,17 @@ opcodestat_dump(dns_opcode_t code, uint64_t val, void *arg) ISC_XMLCHAR codebuf)); TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, val)); TRY0(xmlTextWriterEndElement(writer)); /* counter */ -#endif +#endif /* ifdef HAVE_LIBXML2 */ break; case isc_statsformat_json: #ifdef HAVE_JSON_C zoneobj = (json_object *)dumparg->arg; obj = json_object_new_int64(val); - if (obj == NULL) + if (obj == NULL) { return; + } json_object_object_add(zoneobj, codebuf, obj); -#endif +#endif /* ifdef HAVE_JSON_C */ break; } return; @@ -1593,7 +1644,7 @@ error: "failed at opcodestat_dump()"); dumparg->result = ISC_R_FAILURE; return; -#endif +#endif /* ifdef HAVE_LIBXML2 */ } static void @@ -1606,10 +1657,10 @@ rcodestat_dump(dns_rcode_t code, uint64_t val, void *arg) #ifdef HAVE_LIBXML2 void *writer; int xmlrc; -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C json_object *zoneobj, *obj; -#endif +#endif /* ifdef HAVE_JSON_C */ isc_buffer_init(&b, codebuf, sizeof(codebuf) - 1); dns_rcode_totext(code, &b); @@ -1628,16 +1679,17 @@ rcodestat_dump(dns_rcode_t code, uint64_t val, void *arg) ISC_XMLCHAR codebuf)); TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, val)); TRY0(xmlTextWriterEndElement(writer)); /* counter */ -#endif +#endif /* ifdef HAVE_LIBXML2 */ break; case isc_statsformat_json: #ifdef HAVE_JSON_C zoneobj = (json_object *)dumparg->arg; obj = json_object_new_int64(val); - if (obj == NULL) + if (obj == NULL) { return; + } json_object_object_add(zoneobj, codebuf, obj); -#endif +#endif /* ifdef HAVE_JSON_C */ break; } return; @@ -1649,7 +1701,7 @@ error: "failed at rcodestat_dump()"); dumparg->result = ISC_R_FAILURE; return; -#endif +#endif /* ifdef HAVE_LIBXML2 */ } #if defined(EXTENDED_STATS) @@ -1662,10 +1714,10 @@ dnssecsignstat_dump(dns_keytag_t tag, uint64_t val, void *arg) #ifdef HAVE_LIBXML2 xmlTextWriterPtr writer; int xmlrc; -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C json_object *zoneobj, *obj; -#endif +#endif /* ifdef HAVE_JSON_C */ snprintf(tagbuf, sizeof(tagbuf), "%u", tag); @@ -1682,7 +1734,7 @@ dnssecsignstat_dump(dns_keytag_t tag, uint64_t val, void *arg) ISC_XMLCHAR tagbuf)); TRY0(xmlTextWriterWriteFormatString(writer, "%" PRIu64, val)); TRY0(xmlTextWriterEndElement(writer)); /* counter */ -#endif +#endif /* ifdef HAVE_LIBXML2 */ break; case isc_statsformat_json: #ifdef HAVE_JSON_C @@ -1692,7 +1744,7 @@ dnssecsignstat_dump(dns_keytag_t tag, uint64_t val, void *arg) return; } json_object_object_add(zoneobj, tagbuf, obj); -#endif +#endif /* ifdef HAVE_JSON_C */ break; } return; @@ -1703,7 +1755,7 @@ error: "failed at dnssecsignstat_dump()"); dumparg->result = ISC_R_FAILURE; return; -#endif +#endif /* ifdef HAVE_LIBXML2 */ } #endif /* defined(EXTENDED_STATS) */ @@ -1734,8 +1786,9 @@ zone_xmlrender(dns_zone_t *zone, void *arg) const char * ztype; statlevel = dns_zone_getstatlevel(zone); - if (statlevel == dns_zonestat_none) + if (statlevel == dns_zonestat_none) { return (ISC_R_SUCCESS); + } dumparg.type = isc_statsformat_xml; dumparg.arg = writer; @@ -1753,17 +1806,19 @@ zone_xmlrender(dns_zone_t *zone, void *arg) TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "type")); ztype = user_zonetype(zone); - if (ztype != NULL) + if (ztype != NULL) { TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR ztype)); - else + } else { TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR "unknown")); + } TRY0(xmlTextWriterEndElement(writer)); /* type */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "serial")); - if (dns_zone_getserial(zone, &serial) == ISC_R_SUCCESS) + if (dns_zone_getserial(zone, &serial) == ISC_R_SUCCESS) { TRY0(xmlTextWriterWriteFormatString(writer, "%u", serial)); - else + } else { TRY0(xmlTextWriterWriteString(writer, ISC_XMLCHAR "-")); + } TRY0(xmlTextWriterEndElement(writer)); /* serial */ if (statlevel == dns_zonestat_full) { @@ -1788,8 +1843,9 @@ zone_xmlrender(dns_zone_t *zone, void *arg) ns_statscounter_max, nsstats_index, nsstat_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } /* counters type="rcode"*/ TRY0(xmlTextWriterEndElement(writer)); } @@ -1809,8 +1865,9 @@ zone_xmlrender(dns_zone_t *zone, void *arg) dns_gluecachestatscounter_max, gluecachestats_index, gluecachestats_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } /* counters type="rcode"*/ TRY0(xmlTextWriterEndElement(writer)); } @@ -1826,8 +1883,9 @@ zone_xmlrender(dns_zone_t *zone, void *arg) dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(rcvquerystats, rdtypestat_dump, &dumparg, 0); - if (dumparg.result != ISC_R_SUCCESS) + if (dumparg.result != ISC_R_SUCCESS) { goto error; + } /* counters type="qtype"*/ TRY0(xmlTextWriterEndElement(writer)); @@ -1911,7 +1969,7 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) uint64_t tcpoutsizestat_values[dns_sizecounter_out_max]; #ifdef HAVE_DNSTAP uint64_t dnstapstat_values[dns_dnstapcounter_max]; -#endif +#endif /* ifdef HAVE_DNSTAP */ isc_result_t result; isc_time_now(&now); @@ -1921,8 +1979,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) isc_time_formatISO8601ms(&now, nowstr, sizeof nowstr); writer = xmlNewTextWriterDoc(&doc, 0); - if (writer == NULL) + if (writer == NULL) { goto error; + } TRY0(xmlTextWriterStartDocument(writer, NULL, "UTF-8", NULL)); TRY0(xmlTextWriterWritePI(writer, ISC_XMLCHAR "xml-stylesheet", ISC_XMLCHAR "type=\"text/xsl\" " @@ -1959,8 +2018,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dns_opcodestats_dump(server->sctx->opcodestats, opcodestat_dump, &dumparg, ISC_STATSDUMP_VERBOSE); - if (dumparg.result != ISC_R_SUCCESS) + if (dumparg.result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); @@ -1970,8 +2030,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dns_rcodestats_dump(server->sctx->rcodestats, rcodestat_dump, &dumparg, ISC_STATSDUMP_VERBOSE); - if (dumparg.result != ISC_R_SUCCESS) + if (dumparg.result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); @@ -1982,8 +2043,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(server->sctx->rcvquerystats, rdtypestat_dump, &dumparg, 0); - if (dumparg.result != ISC_R_SUCCESS) + if (dumparg.result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* counters */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "counters")); @@ -1995,8 +2057,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) nsstats_xmldesc, ns_statscounter_max, nsstats_index, nsstat_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* /nsstat */ @@ -2009,8 +2072,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dns_zonestatscounter_max, zonestats_index, zonestat_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* /zonestat */ @@ -2025,8 +2089,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->resolverstats, isc_statsformat_xml, writer, NULL, resstats_xmldesc, dns_resstatscounter_max, resstats_index, resstat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* resstat */ #ifdef HAVE_DNSTAP @@ -2043,11 +2108,12 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dnstapstats_xmldesc, dns_dnstapcounter_max, dnstapstats_index, dnstapstat_values, 0); isc_stats_detach(&dnstapstats); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* dnstap */ } -#endif +#endif /* ifdef HAVE_DNSTAP */ } if ((flags & STATS_XML_NET) != 0) { @@ -2060,8 +2126,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) isc_sockstatscounter_max, sockstats_index, sockstat_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* /sockstat */ } @@ -2079,8 +2146,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->udpinstats4, isc_statsformat_xml, writer, NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max, udpinsizestats_index, udpinsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2092,8 +2160,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->udpoutstats4, isc_statsformat_xml, writer, NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max, udpoutsizestats_index, udpoutsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2107,8 +2176,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->tcpinstats4, isc_statsformat_xml, writer, NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max, tcpinsizestats_index, tcpinsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2120,8 +2190,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->tcpoutstats4, isc_statsformat_xml, writer, NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max, tcpoutsizestats_index, tcpoutsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2137,8 +2208,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->udpinstats6, isc_statsformat_xml, writer, NULL, udpinsizestats_xmldesc, dns_sizecounter_in_max, udpinsizestats_index, udpinsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2150,8 +2222,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->udpoutstats6, isc_statsformat_xml, writer, NULL, udpoutsizestats_xmldesc, dns_sizecounter_out_max, udpoutsizestats_index, udpoutsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2165,8 +2238,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->tcpinstats6, isc_statsformat_xml, writer, NULL, tcpinsizestats_xmldesc, dns_sizecounter_in_max, tcpinsizestats_index, tcpinsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2178,8 +2252,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) server->sctx->tcpoutstats6, isc_statsformat_xml, writer, NULL, tcpoutsizestats_xmldesc, dns_sizecounter_out_max, tcpoutsizestats_index, tcpoutsizestat_values, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* */ TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2204,8 +2279,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) ISC_XMLCHAR "zones")); result = dns_zt_apply(view->zonetable, true, NULL, zone_xmlrender, writer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* /zones */ } @@ -2223,8 +2299,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dumparg.result = ISC_R_SUCCESS; dns_rdatatypestats_dump(view->resquerystats, rdtypestat_dump, &dumparg, 0); - if (dumparg.result != ISC_R_SUCCESS) + if (dumparg.result != ISC_R_SUCCESS) { goto error; + } } TRY0(xmlTextWriterEndElement(writer)); @@ -2238,8 +2315,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) NULL, resstats_xmldesc, dns_resstatscounter_max, resstats_index, resstat_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } } TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2253,8 +2331,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) dumparg.result = ISC_R_SUCCESS; dns_rdatasetstats_dump(cacherrstats, rdatasetstats_dump, &dumparg, 0); - if (dumparg.result != ISC_R_SUCCESS) + if (dumparg.result != ISC_R_SUCCESS) { goto error; + } TRY0(xmlTextWriterEndElement(writer)); /* cache */ } @@ -2268,8 +2347,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) NULL, adbstats_xmldesc, dns_adbstats_max, adbstats_index, adbstat_values, ISC_STATSDUMP_VERBOSE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } } TRY0(xmlTextWriterEndElement(writer)); /* */ @@ -2311,8 +2391,9 @@ generatexml(named_server_t *server, uint32_t flags, int *buflen, xmlChar **buf) xmlFreeTextWriter(writer); xmlDocDumpFormatMemoryEnc(doc, buf, buflen, "UTF-8", 0); - if (*buf == NULL) + if (*buf == NULL) { goto error; + } xmlFreeDoc(doc); return (ISC_R_SUCCESS); @@ -2320,10 +2401,12 @@ error: isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "failed generating XML response"); - if (writer != NULL) + if (writer != NULL) { xmlFreeTextWriter(writer); - if (doc != NULL) + } + if (doc != NULL) { xmlFreeDoc(doc); + } return (ISC_R_FAILURE); } @@ -2361,10 +2444,11 @@ render_xml(uint32_t flags, const char *url, isc_httpdurl_t *urlinfo, isc_buffer_add(b, msglen); *freecb = wrap_xmlfree; *freecb_args = NULL; - } else + } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "failed at rendering XML()"); + } return (result); } @@ -2499,8 +2583,9 @@ static void wrap_jsonfree(isc_buffer_t *buffer, void *arg) { json_object_put(isc_buffer_base(buffer)); - if (arg != NULL) + if (arg != NULL) { json_object_put((json_object *)arg); + } } static json_object * @@ -2509,18 +2594,21 @@ addzone(char *name, char *classname, const char *ztype, uint32_t serial, { json_object *node = json_object_new_object(); - if (node == NULL) + if (node == NULL) { return (NULL); + } json_object_object_add(node, "name", json_object_new_string(name)); json_object_object_add(node, "class", json_object_new_string(classname)); - if (add_serial) + if (add_serial) { json_object_object_add(node, "serial", json_object_new_int64(serial)); - if (ztype != NULL) + } + if (ztype != NULL) { json_object_object_add(node, "type", json_object_new_string(ztype)); + } return (node); } @@ -2539,8 +2627,9 @@ zone_jsonrender(dns_zone_t *zone, void *arg) dns_zonestat_level_t statlevel; statlevel = dns_zone_getstatlevel(zone); - if (statlevel == dns_zonestat_none) + if (statlevel == dns_zonestat_none) { return (ISC_R_SUCCESS); + } dns_zone_nameonly(zone, buf, sizeof(buf)); zone_name_only = buf; @@ -2549,15 +2638,17 @@ zone_jsonrender(dns_zone_t *zone, void *arg) dns_rdataclass_format(rdclass, classbuf, sizeof(classbuf)); class_only = classbuf; - if (dns_zone_getserial(zone, &serial) != ISC_R_SUCCESS) + if (dns_zone_getserial(zone, &serial) != ISC_R_SUCCESS) { zoneobj = addzone(zone_name_only, class_only, user_zonetype(zone), 0, false); - else + } else { zoneobj = addzone(zone_name_only, class_only, user_zonetype(zone), serial, true); + } - if (zoneobj == NULL) + if (zoneobj == NULL) { return (ISC_R_NOMEMORY); + } if (statlevel == dns_zonestat_full) { isc_stats_t *zonestats; @@ -2585,11 +2676,12 @@ zone_jsonrender(dns_zone_t *zone, void *arg) goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(zoneobj, "rcodes", counters); - else + } else { json_object_put(counters); + } } gluecachestats = dns_zone_getgluecachestats(zone); @@ -2610,11 +2702,12 @@ zone_jsonrender(dns_zone_t *zone, void *arg) goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(zoneobj, "gluecache", counters); - else + } else { json_object_put(counters); + } } rcvquerystats = dns_zone_getrcvquerystats(zone); @@ -2633,11 +2726,12 @@ zone_jsonrender(dns_zone_t *zone, void *arg) goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(zoneobj, "qtypes", counters); - else + } else { json_object_put(counters); + } } dnssecsignstats = dns_zone_getdnssecsignstats(zone); @@ -2696,8 +2790,9 @@ zone_jsonrender(dns_zone_t *zone, void *arg) result = ISC_R_SUCCESS; error: - if (zoneobj != NULL) + if (zoneobj != NULL) { json_object_put(zoneobj); + } return (result); } @@ -2724,7 +2819,7 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, uint64_t tcpoutsizestat_values[dns_sizecounter_out_max]; #ifdef HAVE_DNSTAP uint64_t dnstapstat_values[dns_dnstapcounter_max]; -#endif +#endif /* ifdef HAVE_DNSTAP */ stats_dumparg_t dumparg; char boottime[sizeof "yyyy-mm-ddThh:mm:ss.sssZ"]; char configtime[sizeof "yyyy-mm-ddThh:mm:ss.sssZ"]; @@ -2736,8 +2831,9 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, REQUIRE(rootp == NULL || *rootp == NULL); bindstats = json_object_new_object(); - if (bindstats == NULL) + if (bindstats == NULL) { return (ISC_R_NOMEMORY); + } /* * These statistics are included no matter which URL we use. @@ -2782,10 +2878,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "opcodes", counters); - else + } else { json_object_put(counters); + } /* OPCODE counters */ counters = json_object_new_object(); @@ -2800,10 +2897,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "rcodes", counters); - else + } else { json_object_put(counters); + } /* QTYPE counters */ counters = json_object_new_object(); @@ -2818,10 +2916,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "qtypes", counters); - else + } else { json_object_put(counters); + } /* server stat counters */ counters = json_object_new_object(); @@ -2838,10 +2937,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "nsstats", counters); - else + } else { json_object_put(counters); + } /* zone stat counters */ counters = json_object_new_object(); @@ -2858,11 +2958,12 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "zonestats", counters); - else + } else { json_object_put(counters); + } /* resolver stat counters */ counters = json_object_new_object(); @@ -2879,10 +2980,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "resstats", counters); - else + } else { json_object_put(counters); + } #ifdef HAVE_DNSTAP /* dnstap stat counters */ @@ -2903,13 +3005,14 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "dnstapstats", counters); - else + } else { json_object_put(counters); + } } -#endif +#endif /* ifdef HAVE_DNSTAP */ } if ((flags & (STATS_JSON_ZONES | STATS_JSON_SERVER)) != 0) { @@ -2937,10 +3040,11 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, } } - if (json_object_array_length(za) != 0) + if (json_object_array_length(za) != 0) { json_object_object_add(v, "zones", za); - else + } else { json_object_put(za); + } if ((flags & STATS_JSON_SERVER) != 0) { json_object *res; @@ -3070,11 +3174,12 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, goto error; } - if (json_object_get_object(counters)->count != 0) + if (json_object_get_object(counters)->count != 0) { json_object_object_add(bindstats, "sockstats", counters); - else + } else { json_object_put(counters); + } sockets = json_object_new_object(); CHECKMEM(sockets); @@ -3234,26 +3339,36 @@ generatejson(named_server_t *server, size_t *msglen, const char **msg, result = ISC_R_SUCCESS; error: - if (udpreq4 != NULL) + if (udpreq4 != NULL) { json_object_put(udpreq4); - if (udpresp4 != NULL) + } + if (udpresp4 != NULL) { json_object_put(udpresp4); - if (tcpreq4 != NULL) + } + if (tcpreq4 != NULL) { json_object_put(tcpreq4); - if (tcpresp4 != NULL) + } + if (tcpresp4 != NULL) { json_object_put(tcpresp4); - if (udpreq6 != NULL) + } + if (udpreq6 != NULL) { json_object_put(udpreq6); - if (udpresp6 != NULL) + } + if (udpresp6 != NULL) { json_object_put(udpresp6); - if (tcpreq6 != NULL) + } + if (tcpreq6 != NULL) { json_object_put(tcpreq6); - if (tcpresp6 != NULL) + } + if (tcpresp6 != NULL) { json_object_put(tcpresp6); - if (traffic != NULL) + } + if (traffic != NULL) { json_object_put(traffic); - if (bindstats != NULL) + } + if (bindstats != NULL) { json_object_put(bindstats); + } return (result); } @@ -3286,10 +3401,11 @@ render_json(uint32_t flags, const char *url, isc_httpdurl_t *urlinfo, isc_buffer_add(b, msglen); *freecb = wrap_jsonfree; *freecb_args = bindstats; - } else + } else { isc_log_write(named_g_lctx, NAMED_LOGCATEGORY_GENERAL, NAMED_LOGMODULE_SERVER, ISC_LOG_ERROR, "failed at rendering JSON()"); + } return (result); } @@ -3552,37 +3668,43 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, result = cfg_acl_fromconfig(allow, config, named_g_lctx, aclconfctx, listener->mctx, 0, &new_acl); - } else + } else { result = dns_acl_any(listener->mctx, &new_acl); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_acl_attach(new_acl, &listener->acl); dns_acl_detach(&new_acl); result = isc_task_create(named_g_taskmgr, 0, &task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_task_setname(task, "statchannel", NULL); result = isc_socket_create(named_g_socketmgr, isc_sockaddr_pf(addr), isc_sockettype_tcp, &sock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_socket_setname(sock, "statchannel", NULL); #ifndef ISC_ALLOW_MAPPED isc_socket_ipv6only(sock, true); -#endif +#endif /* ifndef ISC_ALLOW_MAPPED */ result = isc_socket_bind(sock, addr, ISC_SOCKET_REUSEADDRESS); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_httpdmgr_create(server->mctx, sock, task, client_ok, destroy_listener, listener, named_g_timermgr, &listener->httpdmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } #ifdef HAVE_LIBXML2 isc_httpdmgr_addurl(listener->httpdmgr, "/", render_xml_all, server); @@ -3603,7 +3725,7 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, server); isc_httpdmgr_addurl(listener->httpdmgr, "/xml/v3/traffic", render_xml_traffic, server); -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C isc_httpdmgr_addurl(listener->httpdmgr, "/json", render_json_all, server); @@ -3623,7 +3745,7 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, server); isc_httpdmgr_addurl(listener->httpdmgr, "/json/v1/traffic", render_json_traffic, server); -#endif +#endif /* ifdef HAVE_JSON_C */ isc_httpdmgr_addurl2(listener->httpdmgr, "/bind9.xsl", true, render_xsl, server); @@ -3634,16 +3756,19 @@ add_listener(named_server_t *server, named_statschannel_t **listenerp, cleanup: if (result != ISC_R_SUCCESS) { - if (listener->acl != NULL) + if (listener->acl != NULL) { dns_acl_detach(&listener->acl); + } isc_mutex_destroy(&listener->lock); isc_mem_putanddetach(&listener->mctx, listener, sizeof(*listener)); } - if (task != NULL) + if (task != NULL) { isc_task_detach(&task); - if (sock != NULL) + } + if (sock != NULL) { isc_socket_detach(&sock); + } return (result); } @@ -3663,7 +3788,6 @@ update_listener(named_server_t *server, named_statschannel_t **listenerp, listener = ISC_LIST_NEXT(listener, link)) { if (isc_sockaddr_equal(addr, &listener->address)) { break; - } } @@ -3680,8 +3804,9 @@ update_listener(named_server_t *server, named_statschannel_t **listenerp, result = cfg_acl_fromconfig(allow, config, named_g_lctx, aclconfctx, listener->mctx, 0, &new_acl); - } else + } else { result = dns_acl_any(listener->mctx, &new_acl); + } if (result == ISC_R_SUCCESS) { LOCK(&listener->lock); @@ -3756,8 +3881,9 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config, statschannel = cfg_listelt_value(element); (void)cfg_map_get(statschannel, "inet", &listenercfg); - if (listenercfg == NULL) + if (listenercfg == NULL) { continue; + } for (element2 = cfg_list_first(listenercfg); element2 != NULL; @@ -3770,10 +3896,11 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config, obj = cfg_tuple_get(listen_params, "address"); addr = *cfg_obj_assockaddr(obj); - if (isc_sockaddr_getport(&addr) == 0) + if (isc_sockaddr_getport(&addr) == 0) { isc_sockaddr_setport( &addr, NAMED_STATSCHANNEL_HTTPPORT); + } isc_sockaddr_format(&addr, socktext, sizeof(socktext)); @@ -3820,9 +3947,10 @@ named_statschannels_configure(named_server_t *server, const cfg_obj_t *config, } } - if (listener != NULL) + if (listener != NULL) { ISC_LIST_APPEND(new_listeners, listener, link); + } } } } @@ -3888,12 +4016,14 @@ named_stats_dump(named_server_t *server, FILE *fp) fprintf(fp, "++ Outgoing Queries ++\n"); for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (view->resquerystats == NULL) + if (view->resquerystats == NULL) { continue; - if (strcmp(view->name, "_default") == 0) + } + if (strcmp(view->name, "_default") == 0) { fprintf(fp, "[View: default]\n"); - else + } else { fprintf(fp, "[View: %s]\n", view->name); + } dns_rdatatypestats_dump(view->resquerystats, rdtypestat_dump, &dumparg, 0); } @@ -3916,12 +4046,14 @@ named_stats_dump(named_server_t *server, FILE *fp) resstats_index, resstat_values, 0); for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (view->resstats == NULL) + if (view->resstats == NULL) { continue; - if (strcmp(view->name, "_default") == 0) + } + if (strcmp(view->name, "_default") == 0) { fprintf(fp, "[View: default]\n"); - else + } else { fprintf(fp, "[View: %s]\n", view->name); + } (void)dump_counters(view->resstats, isc_statsformat_file, fp, NULL, resstats_desc, dns_resstatscounter_max, resstats_index, @@ -3931,16 +4063,18 @@ named_stats_dump(named_server_t *server, FILE *fp) fprintf(fp, "++ Cache Statistics ++\n"); for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (strcmp(view->name, "_default") == 0) + if (strcmp(view->name, "_default") == 0) { fprintf(fp, "[View: default]\n"); - else + } else { fprintf(fp, "[View: %s (Cache: %s)]\n", view->name, dns_cache_getname(view->cache)); + } /* * Avoid dumping redundant statistics when the cache is shared. */ - if (dns_view_iscacheshared(view)) + if (dns_view_iscacheshared(view)) { continue; + } dns_cache_dumpstats(view->cache, fp); } @@ -3950,13 +4084,15 @@ named_stats_dump(named_server_t *server, FILE *fp) dns_stats_t *cacherrstats; cacherrstats = dns_db_getrrsetstats(view->cachedb); - if (cacherrstats == NULL) + if (cacherrstats == NULL) { continue; - if (strcmp(view->name, "_default") == 0) + } + if (strcmp(view->name, "_default") == 0) { fprintf(fp, "[View: default]\n"); - else + } else { fprintf(fp, "[View: %s (Cache: %s)]\n", view->name, dns_cache_getname(view->cache)); + } if (dns_view_iscacheshared(view)) { /* * Avoid dumping redundant statistics when the cache is @@ -3971,12 +4107,14 @@ named_stats_dump(named_server_t *server, FILE *fp) fprintf(fp, "++ ADB stats ++\n"); for (view = ISC_LIST_HEAD(server->viewlist); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (view->adbstats == NULL) + if (view->adbstats == NULL) { continue; - if (strcmp(view->name, "_default") == 0) + } + if (strcmp(view->name, "_default") == 0) { fprintf(fp, "[View: default]\n"); - else + } else { fprintf(fp, "[View: %s]\n", view->name); + } (void)dump_counters(view->adbstats, isc_statsformat_file, fp, NULL, adbstats_desc, dns_adbstats_max, adbstats_index, adbstat_values, 0); @@ -3997,14 +4135,16 @@ named_stats_dump(named_server_t *server, FILE *fp) char zonename[DNS_NAME_FORMATSIZE]; view = dns_zone_getview(zone); - if (view == NULL) + if (view == NULL) { continue; + } dns_name_format(dns_zone_getorigin(zone), zonename, sizeof(zonename)); fprintf(fp, "[%s", zonename); - if (strcmp(view->name, "_default") != 0) + if (strcmp(view->name, "_default") != 0) { fprintf(fp, " (view: %s)", view->name); + } fprintf(fp, "]\n"); (void)dump_counters(zonestats, isc_statsformat_file, fp, @@ -4024,14 +4164,16 @@ named_stats_dump(named_server_t *server, FILE *fp) char zonename[DNS_NAME_FORMATSIZE]; view = dns_zone_getview(zone); - if (view == NULL) + if (view == NULL) { continue; + } dns_name_format(dns_zone_getorigin(zone), zonename, sizeof(zonename)); fprintf(fp, "[%s", zonename); - if (strcmp(view->name, "_default") != 0) + if (strcmp(view->name, "_default") != 0) { fprintf(fp, " (view: %s)", view->name); + } fprintf(fp, "]\n"); (void)dump_counters( diff --git a/bin/named/tkeyconf.c b/bin/named/tkeyconf.c index c08c08aca3..c1d9e7cae3 100644 --- a/bin/named/tkeyconf.c +++ b/bin/named/tkeyconf.c @@ -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); diff --git a/bin/named/tsigconf.c b/bin/named/tsigconf.c index 5483b8a0f7..2fcf04b32b 100644 --- a/bin/named/tsigconf.c +++ b/bin/named/tsigconf.c @@ -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; diff --git a/bin/named/unix/dlz_dlopen_driver.c b/bin/named/unix/dlz_dlopen_driver.c index c3ae24af44..1885412748 100644 --- a/bin/named/unix/dlz_dlopen_driver.c +++ b/bin/named/unix/dlz_dlopen_driver.c @@ -16,7 +16,7 @@ #include #if HAVE_DLFCN_H #include -#endif +#endif /* if HAVE_DLFCN_H */ #include #include @@ -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 */ } diff --git a/bin/named/unix/os.c b/bin/named/unix/os.c index 14f6815689..1fb842cadc 100644 --- a/bin/named/unix/os.c +++ b/bin/named/unix/os.c @@ -17,7 +17,7 @@ #include /* dev_t FreeBSD 2.1 */ #ifdef HAVE_UNAME #include -#endif +#endif /* ifdef HAVE_UNAME */ #include #include @@ -30,7 +30,7 @@ #include #ifdef HAVE_TZSET #include -#endif +#endif /* ifdef HAVE_TZSET */ #include #include @@ -46,7 +46,7 @@ #include #ifdef HAVE_LIBSCF #include -#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); } diff --git a/bin/named/win32/dlz_dlopen_driver.c b/bin/named/win32/dlz_dlopen_driver.c index 57d94222ee..4772d91ef1 100644 --- a/bin/named/win32/dlz_dlopen_driver.c +++ b/bin/named/win32/dlz_dlopen_driver.c @@ -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 */ } diff --git a/bin/named/win32/include/named/ntservice.h b/bin/named/win32/include/named/ntservice.h index c4c0ed0a3d..8fe6f5b32e 100644 --- a/bin/named/win32/include/named/ntservice.h +++ b/bin/named/win32/include/named/ntservice.h @@ -26,4 +26,4 @@ void ntservice_shutdown(); BOOL ntservice_isservice(); -#endif +#endif /* ifndef NTSERVICE_H */ diff --git a/bin/named/win32/ntservice.c b/bin/named/win32/ntservice.c index 70ced86569..d2e427669b 100644 --- a/bin/named/win32/ntservice.c +++ b/bin/named/win32/ntservice.c @@ -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; diff --git a/bin/named/win32/os.c b/bin/named/win32/os.c index 963e6388ff..83850883f0 100644 --- a/bin/named/win32/os.c +++ b/bin/named/win32/os.c @@ -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); } diff --git a/bin/named/zoneconf.c b/bin/named/zoneconf.c index b3f938246f..d9a29c6de5 100644 --- a/bin/named/zoneconf.c +++ b/bin/named/zoneconf.c @@ -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))) { diff --git a/bin/nsupdate/nsupdate.c b/bin/nsupdate/nsupdate.c index fa4b12e36e..6e424d26a6 100644 --- a/bin/nsupdate/nsupdate.c +++ b/bin/nsupdate/nsupdate.c @@ -76,10 +76,10 @@ #include #ifdef WIN32 #include -#else +#else /* ifdef WIN32 */ #include ISC_PLATFORM_KRB5HEADER -#endif -#endif +#endif /* ifdef WIN32 */ +#endif /* ifdef GSSAPI */ #include #if defined(HAVE_READLINE) @@ -87,14 +87,14 @@ #include #if defined(HAVE_EDIT_READLINE_HISTORY_H) #include -#endif +#endif /* if defined(HAVE_EDIT_READLINE_HISTORY_H) */ #elif defined(HAVE_EDITLINE_READLINE_H) #include -#else +#else /* if defined(HAVE_EDIT_READLINE_READLINE_H) */ #include #include -#endif -#endif +#endif /* if defined(HAVE_EDIT_READLINE_READLINE_H) */ +#endif /* if defined(HAVE_READLINE) */ #define MAXCMD (128 * 1024) #define MAXWIRE (64 * 1024) @@ -113,7 +113,7 @@ static uint16_t dnsport = DNSDEFAULTPORT; #ifndef RESOLV_CONF #define RESOLV_CONF "/etc/resolv.conf" -#endif +#endif /* ifndef RESOLV_CONF */ static bool debugging = false, ddebugging = false; static bool memdebugging = false; @@ -231,9 +231,10 @@ error(const char *format, ...) ISC_FORMAT_PRINTF(1, 2); static void master_from_servers(void) { - if (master_servers != NULL && master_servers != servers) + if (master_servers != NULL && master_servers != servers) { isc_mem_put(gmctx, master_servers, master_alloc * sizeof(isc_sockaddr_t)); + } master_servers = servers; master_total = ns_total; master_alloc = ns_alloc; @@ -243,18 +244,22 @@ master_from_servers(void) static dns_rdataclass_t getzoneclass(void) { - if (zoneclass == dns_rdataclass_none) + if (zoneclass == dns_rdataclass_none) { zoneclass = defaultclass; + } return (zoneclass); } static bool setzoneclass(dns_rdataclass_t rdclass) { - if (zoneclass == dns_rdataclass_none || rdclass == dns_rdataclass_none) + if (zoneclass == dns_rdataclass_none || + rdclass == dns_rdataclass_none) { zoneclass = rdclass; - if (zoneclass != rdclass) + } + if (zoneclass != rdclass) { return (false); + } return (true); } @@ -310,8 +315,9 @@ ddebug(const char *format, ...) static inline void check_result(isc_result_t result, const char *msg) { - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("%s: %s", msg, isc_result_totext(result)); + } } static char * @@ -323,17 +329,20 @@ nsu_strsep(char **stringp, const char *delim) const char *d; char sc, dc; - if (string == NULL) + if (string == NULL) { return (NULL); + } for (; *string != '\0'; string++) { sc = *string; for (d = delim; (dc = *d) != '\0'; d++) { - if (sc == dc) + if (sc == dc) { break; + } } - if (dc == 0) + if (dc == 0) { break; + } } for (s = string; *s != '\0'; s++) { @@ -356,19 +365,21 @@ reset_system(void) ddebug("reset_system()"); /* If the update message is still around, destroy it */ - if (updatemsg != NULL) + if (updatemsg != NULL) { dns_message_reset(updatemsg, DNS_MESSAGE_INTENTRENDER); - else { + } else { result = dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &updatemsg); check_result(result, "dns_message_create"); } updatemsg->opcode = dns_opcode_update; if (usegsstsig) { - if (tsigkey != NULL) + if (tsigkey != NULL) { dns_tsigkey_detach(&tsigkey); - if (gssring != NULL) + } + if (gssring != NULL) { dns_tsigkeyring_detach(&gssring); + } tried_other_gsstsig = false; } } @@ -464,12 +475,13 @@ basenamelen(const char *file) { int len = strlen(file); - if (len > 1 && file[len - 1] == '.') + if (len > 1 && file[len - 1] == '.') { len -= 1; - else if (len > 8 && strcmp(file + len - 8, ".private") == 0) + } else if (len > 8 && strcmp(file + len - 8, ".private") == 0) { len -= 8; - else if (len > 4 && strcmp(file + len - 4, ".key") == 0) + } else if (len > 4 && strcmp(file + len - 4, ".key") == 0) { len -= 4; + } return (len); } @@ -494,13 +506,15 @@ setup_keystr(void) debug("Creating key..."); s = strchr(keystr, ':'); - if (s == NULL || s == keystr || s[1] == 0) + if (s == NULL || s == keystr || s[1] == 0) { fatal("key option must specify [hmac:]keyname:secret"); + } secretstr = s + 1; n = strchr(secretstr, ':'); if (n != NULL) { - if (n == secretstr || n[1] == 0) + if (n == secretstr || n[1] == 0) { fatal("key option must specify [hmac:]keyname:secret"); + } name = secretstr; secretstr = n + 1; if (!parse_hmac(&hmacname, keystr, s - keystr, &digestbits)) { @@ -536,14 +550,16 @@ setup_keystr(void) debug("keycreate"); result = dns_tsigkey_create(mykeyname, hmacname, secret, secretlen, false, NULL, 0, 0, gmctx, NULL, &tsigkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fprintf(stderr, "could not create key from %s: %s\n", keystr, dns_result_totext(result)); - else + } else { dst_key_setbits(tsigkey->key, digestbits); + } failure: - if (secret != NULL) + if (secret != NULL) { isc_mem_free(gmctx, secret); + } } /* @@ -563,26 +579,31 @@ read_sessionkey(isc_mem_t *mctx, isc_log_t *lctx) isc_result_t result; int len; - if (!isc_file_exists(keyfile)) + if (!isc_file_exists(keyfile)) { return (ISC_R_FILENOTFOUND); + } result = cfg_parser_create(mctx, lctx, &pctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = cfg_parse_file(pctx, keyfile, &cfg_type_sessionkey, &sessionkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = cfg_map_get(sessionkey, "key", &key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } (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"); + } mykeyname = cfg_obj_asstring(cfg_map_getname(key)); secretstr = cfg_obj_asstring(secretobj); @@ -595,13 +616,15 @@ read_sessionkey(isc_mem_t *mctx, isc_log_t *lctx) cleanup: if (pctx != NULL) { - if (sessionkey != NULL) + if (sessionkey != NULL) { cfg_obj_destroy(pctx, &sessionkey); + } cfg_parser_destroy(&pctx); } - if (keystr != NULL) + if (keystr != NULL) { isc_mem_free(mctx, keystr); + } return (result); } @@ -615,8 +638,9 @@ setup_keyfile(isc_mem_t *mctx, isc_log_t *lctx) debug("Creating key..."); - if (sig0key != NULL) + if (sig0key != NULL) { dst_key_free(&sig0key); + } /* Try reading the key from a K* pair */ result = dst_key_fromnamedfile( @@ -625,8 +649,9 @@ setup_keyfile(isc_mem_t *mctx, isc_log_t *lctx) /* If that didn't work, try reading it as a session.key keyfile */ if (result != ISC_R_SUCCESS) { result = read_sessionkey(mctx, lctx); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return; + } } if (result != ISC_R_SUCCESS) { @@ -684,18 +709,22 @@ doshutdown(void) * isc_mem_put of servers as it sets the servers pointer * to NULL. */ - if (master_servers != NULL && master_servers != servers) + if (master_servers != NULL && master_servers != servers) { isc_mem_put(gmctx, master_servers, master_alloc * sizeof(isc_sockaddr_t)); + } - if (servers != NULL) + if (servers != NULL) { isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t)); + } - if (localaddr4 != NULL) + if (localaddr4 != NULL) { isc_mem_put(gmctx, localaddr4, sizeof(isc_sockaddr_t)); + } - if (localaddr6 != NULL) + if (localaddr6 != NULL) { isc_mem_put(gmctx, localaddr6, sizeof(isc_sockaddr_t)); + } if (tsigkey != NULL) { ddebug("Freeing TSIG key"); @@ -707,8 +736,9 @@ doshutdown(void) dst_key_free(&sig0key); } - if (updatemsg != NULL) + if (updatemsg != NULL) { dns_message_destroy(&updatemsg); + } if (is_dst_up) { ddebug("Destroy DST lib"); @@ -720,10 +750,12 @@ doshutdown(void) dns_requestmgr_detach(&requestmgr); ddebug("Freeing the dispatchers"); - if (have_ipv4) + if (have_ipv4) { dns_dispatch_detach(&dispatchv4); - if (have_ipv6) + } + if (have_ipv6) { dns_dispatch_detach(&dispatchv6); + } ddebug("Shutting down dispatch manager"); dns_dispatchmgr_destroy(&dispatchmgr); @@ -735,8 +767,9 @@ maybeshutdown(void) ddebug("Shutting down request manager"); dns_requestmgr_shutdown(requestmgr); - if (requests != 0) + if (requests != 0) { return; + } doshutdown(); } @@ -817,8 +850,9 @@ setup_system(void) nslist = irs_resconf_getnameservers(resconf); if (servers != NULL) { - if (master_servers == servers) + if (master_servers == servers) { master_servers = NULL; + } isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t)); } @@ -827,8 +861,9 @@ setup_system(void) struct in_addr in; struct in6_addr in6; - if (local_only && keyfile == NULL) + if (local_only && keyfile == NULL) { keyfile = SESSION_KEYFILE; + } default_servers = !local_only; @@ -959,15 +994,17 @@ setup_system(void) &requestmgr); check_result(result, "dns_requestmgr_create"); - if (keystr != NULL) + if (keystr != NULL) { setup_keystr(); - else if (local_only) { + } else if (local_only) { result = read_sessionkey(gmctx, glctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("can't read key from %s: %s\n", keyfile, isc_result_totext(result)); - } else if (keyfile != NULL) + } + } else if (keyfile != NULL) { setup_keyfile(gmctx, glctx); + } } static int @@ -979,9 +1016,10 @@ get_addresses(char *host, in_port_t port, isc_sockaddr_t *sockaddr, int naddrs) isc_app_block(); result = bind9_getaddresses(host, port, sockaddr, naddrs, &count); isc_app_unblock(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { error("couldn't get address for '%s': %s", host, isc_result_totext(result)); + } return (count); } @@ -1028,9 +1066,10 @@ pre_parse_args(int argc, char **argv) case '?': case 'h': - if (isc_commandline_option != '?') + if (isc_commandline_option != '?') { fprintf(stderr, "%s: invalid argument -%c\n", argv[0], isc_commandline_option); + } fprintf(stderr, "usage: nsupdate [-dDi] [-L level] [-l]" "[-g | -o | -y keyname:secret | -k " "keyfile] " @@ -1040,22 +1079,26 @@ pre_parse_args(int argc, char **argv) case 'P': for (t = 0xff00; t <= 0xfffe; t++) { - if (dns_rdatatype_ismeta(t)) + if (dns_rdatatype_ismeta(t)) { continue; + } dns_rdatatype_format(t, buf, sizeof(buf)); - if (strncmp(buf, "TYPE", 4) != 0) + if (strncmp(buf, "TYPE", 4) != 0) { fprintf(stdout, "%s\n", buf); + } } doexit = true; break; case 'T': for (t = 1; t <= 0xfeff; t++) { - if (dns_rdatatype_ismeta(t)) + if (dns_rdatatype_ismeta(t)) { continue; + } dns_rdatatype_format(t, buf, sizeof(buf)); - if (strncmp(buf, "TYPE", 4) != 0) + if (strncmp(buf, "TYPE", 4) != 0) { fprintf(stdout, "%s\n", buf); + } } doexit = true; break; @@ -1069,8 +1112,9 @@ pre_parse_args(int argc, char **argv) break; } } - if (doexit) + if (doexit) { exit(0); + } isc_commandline_reset = true; isc_commandline_index = 1; } @@ -1166,8 +1210,9 @@ parse_args(int argc, char **argv) isc_commandline_argument); exit(1); } - if (timeout == 0) + if (timeout == 0) { timeout = UINT_MAX; + } break; case 'u': result = isc_parse_uint32(&udp_timeout, @@ -1177,8 +1222,9 @@ parse_args(int argc, char **argv) isc_commandline_argument); exit(1); } - if (udp_timeout == 0) + if (udp_timeout == 0) { udp_timeout = UINT_MAX; + } break; case 'r': result = isc_parse_uint32(&udp_retries, @@ -1211,7 +1257,7 @@ parse_args(int argc, char **argv) argv[0]); exit(1); } -#else +#else /* ifdef GSSAPI */ if (usegsstsig) { fprintf(stderr, "%s: cannot specify -g or -o, " @@ -1219,7 +1265,7 @@ parse_args(int argc, char **argv) argv[0]); exit(1); } -#endif +#endif /* ifdef GSSAPI */ if (argv[isc_commandline_index] != NULL) { if (strcmp(argv[isc_commandline_index], "-") == 0) { @@ -1289,8 +1335,9 @@ parse_rdata(char **cmdlinep, dns_rdataclass_t rdataclass, return (STATUS_MORE); } - while (*cmdline != 0 && isspace((unsigned char)*cmdline)) + while (*cmdline != 0 && isspace((unsigned char)*cmdline)) { cmdline++; + } if (*cmdline != 0) { dns_rdatacallbacks_init(&callbacks); @@ -1346,8 +1393,9 @@ make_prereq(char *cmdline, bool ispositive, bool isrrset) * Read the owner name */ retval = parse_name(&cmdline, updatemsg, &name); - if (retval != STATUS_MORE) + if (retval != STATUS_MORE) { return (retval); + } /* * If this is an rrset prereq, read the class or type. @@ -1389,8 +1437,9 @@ make_prereq(char *cmdline, bool ispositive, bool isrrset) goto failure; } } - } else + } else { rdatatype = dns_rdatatype_any; + } result = dns_message_gettemprdata(updatemsg, &rdata); check_result(result, "dns_message_gettemprdata"); @@ -1400,10 +1449,12 @@ make_prereq(char *cmdline, bool ispositive, bool isrrset) if (isrrset && ispositive) { retval = parse_rdata(&cmdline, rdataclass, rdatatype, updatemsg, rdata); - if (retval != STATUS_MORE) + if (retval != STATUS_MORE) { goto failure; - } else + } + } else { rdata->flags = DNS_RDATA_UPDATE; + } result = dns_message_gettemprdatalist(updatemsg, &rdatalist); check_result(result, "dns_message_gettemprdatalist"); @@ -1411,12 +1462,14 @@ make_prereq(char *cmdline, bool ispositive, bool isrrset) check_result(result, "dns_message_gettemprdataset"); rdatalist->type = rdatatype; if (ispositive) { - if (isrrset && rdata->data != NULL) + if (isrrset && rdata->data != NULL) { rdatalist->rdclass = rdataclass; - else + } else { rdatalist->rdclass = dns_rdataclass_any; - } else + } + } else { rdatalist->rdclass = dns_rdataclass_none; + } rdata->rdclass = rdatalist->rdclass; rdata->type = rdatatype; ISC_LIST_APPEND(rdatalist->rdata, rdata, link); @@ -1427,8 +1480,9 @@ make_prereq(char *cmdline, bool ispositive, bool isrrset) return (STATUS_MORE); failure: - if (name != NULL) + if (name != NULL) { dns_message_puttempname(updatemsg, &name); + } return (STATUS_SYNTAX); } @@ -1482,9 +1536,9 @@ evaluate_server(char *cmdline) server = word; word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) + if (word == NULL || *word == 0) { port = dnsport; - else { + } else { char *endp; port = strtol(word, &endp, 10); if (*endp != 0) { @@ -1500,8 +1554,9 @@ evaluate_server(char *cmdline) } if (servers != NULL) { - if (master_servers == servers) + if (master_servers == servers) { master_servers = NULL; + } isc_mem_put(gmctx, servers, ns_alloc * sizeof(isc_sockaddr_t)); } @@ -1536,9 +1591,9 @@ evaluate_local(char *cmdline) local = word; word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) + if (word == NULL || *word == 0) { port = 0; - else { + } else { char *endp; port = strtol(word, &endp, 10); if (*endp != 0) { @@ -1554,12 +1609,14 @@ evaluate_local(char *cmdline) } if (have_ipv6 && inet_pton(AF_INET6, local, &in6) == 1) { - if (localaddr6 == NULL) + if (localaddr6 == NULL) { localaddr6 = isc_mem_get(gmctx, sizeof(isc_sockaddr_t)); + } isc_sockaddr_fromin6(localaddr6, &in6, (in_port_t)port); } else if (have_ipv4 && inet_pton(AF_INET, local, &in4) == 1) { - if (localaddr4 == NULL) + if (localaddr4 == NULL) { localaddr4 = isc_mem_get(gmctx, sizeof(isc_sockaddr_t)); + } isc_sockaddr_fromin(localaddr4, &in4, (in_port_t)port); } else { fprintf(stderr, "invalid address %s", local); @@ -1629,8 +1686,9 @@ evaluate_key(char *cmdline) } secretlen = isc_buffer_usedlength(&secretbuf); - if (tsigkey != NULL) + if (tsigkey != NULL) { dns_tsigkey_detach(&tsigkey); + } result = dns_tsigkey_create(mykeyname, hmacname, secret, secretlen, false, NULL, 0, 0, gmctx, NULL, &tsigkey); isc_mem_free(gmctx, secret); @@ -1683,8 +1741,9 @@ evaluate_realm(char *cmdline) } word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) + if (word == NULL || *word == 0) { return (STATUS_MORE); + } n = snprintf(buf, sizeof(buf), "@%s", word); if (n < 0 || (size_t)n >= sizeof(buf)) { @@ -1693,10 +1752,10 @@ evaluate_realm(char *cmdline) } realm = isc_mem_strdup(gmctx, buf); return (STATUS_MORE); -#else +#else /* ifdef GSSAPI */ UNUSED(cmdline); return (STATUS_SYNTAX); -#endif +#endif /* ifdef GSSAPI */ } static uint16_t @@ -1719,8 +1778,9 @@ evaluate_ttl(char *cmdline) } result = isc_parse_uint32(&ttl, word, 10); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (STATUS_SYNTAX); + } if (ttl > TTL_MAX) { fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n", word, @@ -1788,8 +1848,9 @@ update_addordelete(char *cmdline, bool isdelete) * Read the owner name. */ retval = parse_name(&cmdline, updatemsg, &name); - if (retval != STATUS_MORE) + if (retval != STATUS_MORE) { return (retval); + } result = dns_message_gettemprdata(updatemsg, &rdata); check_result(result, "dns_message_gettemprdata"); @@ -1828,9 +1889,9 @@ update_addordelete(char *cmdline, bool isdelete) } } - if (isdelete) + if (isdelete) { ttl = 0; - else if (ttl > TTL_MAX) { + } else if (ttl > TTL_MAX) { fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n", word, TTL_MAX); goto failure; @@ -1897,14 +1958,16 @@ parseclass: } retval = parse_rdata(&cmdline, rdataclass, rdatatype, updatemsg, rdata); - if (retval != STATUS_MORE) + if (retval != STATUS_MORE) { goto failure; + } if (isdelete) { - if ((rdata->flags & DNS_RDATA_UPDATE) != 0) + if ((rdata->flags & DNS_RDATA_UPDATE) != 0) { rdataclass = dns_rdataclass_any; - else + } else { rdataclass = dns_rdataclass_none; + } } else { if ((rdata->flags & DNS_RDATA_UPDATE) != 0) { fprintf(stderr, "could not read rdata\n"); @@ -1955,8 +2018,9 @@ doneparsing: return (STATUS_MORE); failure: - if (name != NULL) + if (name != NULL) { dns_message_puttempname(updatemsg, &name); + } dns_message_puttemprdata(updatemsg, &rdata); return (STATUS_SYNTAX); } @@ -1973,13 +2037,13 @@ evaluate_update(char *cmdline) fprintf(stderr, "could not read operation code\n"); return (STATUS_SYNTAX); } - if (strcasecmp(word, "delete") == 0) + if (strcasecmp(word, "delete") == 0) { isdelete = true; - else if (strcasecmp(word, "del") == 0) + } else if (strcasecmp(word, "del") == 0) { isdelete = true; - else if (strcasecmp(word, "add") == 0) + } else if (strcasecmp(word, "add") == 0) { isdelete = false; - else { + } else { fprintf(stderr, "incorrect operation code: %s\n", word); return (STATUS_SYNTAX); } @@ -2064,8 +2128,9 @@ show_message(FILE *stream, dns_message_t *msg, const char *description) "buffer to display message\n"); exit(1); } - if (buf != NULL) + if (buf != NULL) { isc_buffer_free(&buf); + } isc_buffer_allocate(gmctx, &buf, bufsz); result = dns_message_totext(msg, style, 0, buf); bufsz *= 2; @@ -2089,83 +2154,106 @@ do_next_command(char *cmdline) ddebug("do_next_command()"); word = nsu_strsep(&cmdline, " \t\r\n"); - if (word == NULL || *word == 0) + if (word == NULL || *word == 0) { return (STATUS_SEND); - if (word[0] == ';') - return (STATUS_MORE); - if (strcasecmp(word, "quit") == 0) - return (STATUS_QUIT); - if (strcasecmp(word, "prereq") == 0) - return (evaluate_prereq(cmdline)); - if (strcasecmp(word, "nxdomain") == 0) - return (make_prereq(cmdline, false, false)); - if (strcasecmp(word, "yxdomain") == 0) - return (make_prereq(cmdline, true, false)); - if (strcasecmp(word, "nxrrset") == 0) - return (make_prereq(cmdline, false, true)); - if (strcasecmp(word, "yxrrset") == 0) - return (make_prereq(cmdline, true, true)); - if (strcasecmp(word, "update") == 0) - return (evaluate_update(cmdline)); - if (strcasecmp(word, "delete") == 0) - return (update_addordelete(cmdline, true)); - if (strcasecmp(word, "del") == 0) - return (update_addordelete(cmdline, true)); - if (strcasecmp(word, "add") == 0) - return (update_addordelete(cmdline, false)); - if (strcasecmp(word, "server") == 0) - return (evaluate_server(cmdline)); - if (strcasecmp(word, "local") == 0) - return (evaluate_local(cmdline)); - if (strcasecmp(word, "zone") == 0) - return (evaluate_zone(cmdline)); - if (strcasecmp(word, "class") == 0) - return (evaluate_class(cmdline)); - if (strcasecmp(word, "send") == 0) - return (STATUS_SEND); - if (strcasecmp(word, "debug") == 0) { - if (debugging) - ddebugging = true; - else - debugging = true; + } + if (word[0] == ';') { return (STATUS_MORE); } - if (strcasecmp(word, "ttl") == 0) + if (strcasecmp(word, "quit") == 0) { + return (STATUS_QUIT); + } + if (strcasecmp(word, "prereq") == 0) { + return (evaluate_prereq(cmdline)); + } + if (strcasecmp(word, "nxdomain") == 0) { + return (make_prereq(cmdline, false, false)); + } + if (strcasecmp(word, "yxdomain") == 0) { + return (make_prereq(cmdline, true, false)); + } + if (strcasecmp(word, "nxrrset") == 0) { + return (make_prereq(cmdline, false, true)); + } + if (strcasecmp(word, "yxrrset") == 0) { + return (make_prereq(cmdline, true, true)); + } + if (strcasecmp(word, "update") == 0) { + return (evaluate_update(cmdline)); + } + if (strcasecmp(word, "delete") == 0) { + return (update_addordelete(cmdline, true)); + } + if (strcasecmp(word, "del") == 0) { + return (update_addordelete(cmdline, true)); + } + if (strcasecmp(word, "add") == 0) { + return (update_addordelete(cmdline, false)); + } + if (strcasecmp(word, "server") == 0) { + return (evaluate_server(cmdline)); + } + if (strcasecmp(word, "local") == 0) { + return (evaluate_local(cmdline)); + } + if (strcasecmp(word, "zone") == 0) { + return (evaluate_zone(cmdline)); + } + if (strcasecmp(word, "class") == 0) { + return (evaluate_class(cmdline)); + } + if (strcasecmp(word, "send") == 0) { + return (STATUS_SEND); + } + if (strcasecmp(word, "debug") == 0) { + if (debugging) { + ddebugging = true; + } else { + debugging = true; + } + return (STATUS_MORE); + } + if (strcasecmp(word, "ttl") == 0) { return (evaluate_ttl(cmdline)); + } if (strcasecmp(word, "show") == 0) { show_message(stdout, updatemsg, "Outgoing update query:"); return (STATUS_MORE); } if (strcasecmp(word, "answer") == 0) { - if (answer != NULL) + if (answer != NULL) { show_message(stdout, answer, "Answer:"); + } return (STATUS_MORE); } if (strcasecmp(word, "key") == 0) { usegsstsig = false; return (evaluate_key(cmdline)); } - if (strcasecmp(word, "realm") == 0) + if (strcasecmp(word, "realm") == 0) { return (evaluate_realm(cmdline)); - if (strcasecmp(word, "check-names") == 0 || strcasecmp(word, "checkname" - "s") == 0) + } + if (strcasecmp(word, "check-names") == 0 || + strcasecmp(word, "checkname" + "s") == 0) { return (evaluate_checknames(cmdline)); + } if (strcasecmp(word, "gsstsig") == 0) { #ifdef GSSAPI usegsstsig = true; use_win2k_gsstsig = false; -#else +#else /* ifdef GSSAPI */ fprintf(stderr, "gsstsig not supported\n"); -#endif +#endif /* ifdef GSSAPI */ return (STATUS_MORE); } if (strcasecmp(word, "oldgsstsig") == 0) { #ifdef GSSAPI usegsstsig = true; use_win2k_gsstsig = true; -#else +#else /* ifdef GSSAPI */ fprintf(stderr, "gsstsig not supported\n"); -#endif +#endif /* ifdef GSSAPI */ return (STATUS_MORE); } if (strcasecmp(word, "help") == 0) { @@ -2229,15 +2317,17 @@ get_next_command(void) if (interactive) { #ifdef HAVE_READLINE cmdline = readline("> "); - if (cmdline != NULL) + if (cmdline != NULL) { add_history(cmdline); -#else + } +#else /* ifdef HAVE_READLINE */ fprintf(stdout, "> "); fflush(stdout); cmdline = fgets(cmdlinebuf, MAXCMD, input); -#endif - } else +#endif /* ifdef HAVE_READLINE */ + } else { cmdline = fgets(cmdlinebuf, MAXCMD, input); + } isc_app_unblock(); if (cmdline != NULL) { @@ -2251,9 +2341,10 @@ get_next_command(void) result = do_next_command(cmdline); } #ifdef HAVE_READLINE - if (interactive) + if (interactive) { free(cmdline); -#endif + } +#endif /* ifdef HAVE_READLINE */ return (result); } @@ -2265,11 +2356,13 @@ user_interaction(void) ddebug("user_interaction()"); while ((result == STATUS_MORE) || (result == STATUS_SYNTAX)) { result = get_next_command(); - if (!interactive && result == STATUS_SYNTAX) + if (!interactive && result == STATUS_SYNTAX) { fatal("syntax error"); + } } - if (result == STATUS_SEND) + if (result == STATUS_SEND) { return (true); + } return (false); } @@ -2294,15 +2387,17 @@ check_tsig_error(dns_rdataset_t *rdataset, isc_buffer_t *b) result = dns_rdata_tostruct(&rdata, &tsig, NULL); check_result(result, "dns_rdata_tostruct"); if (tsig.error != 0) { - if (isc_buffer_remaininglength(b) < 1) + if (isc_buffer_remaininglength(b) < 1) { check_result(ISC_R_NOSPACE, "isc_buffer_" "remaininglength"); + } isc_buffer_putstr(b, "(" /*)*/); result = dns_tsigrcode_totext(tsig.error, b); check_result(result, "dns_tsigrcode_totext"); - if (isc_buffer_remaininglength(b) < 1) + if (isc_buffer_remaininglength(b) < 1) { check_result(ISC_R_NOSPACE, "isc_buffer_" "remaininglength"); + } isc_buffer_putstr(b, /*(*/ ")"); } } @@ -2315,8 +2410,9 @@ next_master(const char *caller, isc_sockaddr_t *addr, isc_result_t eresult) isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf)); fprintf(stderr, "; Communication with %s failed: %s\n", addrbuf, isc_result_totext(eresult)); - if (++master_inuse >= master_total) + if (++master_inuse >= master_total) { return (false); + } ddebug("%s: trying next server", caller); return (true); } @@ -2368,8 +2464,9 @@ update_completed(isc_task_t *task, isc_event_t *event) DNS_MESSAGEPARSE_PRESERVEORDER); switch (result) { case ISC_R_SUCCESS: - if (answer->verify_attempted) + if (answer->verify_attempted) { ddebug("tsig verification successful"); + } break; case DNS_R_CLOCKSKEW: case DNS_R_EXPECTEDTSIG: @@ -2384,7 +2481,7 @@ update_completed(isc_task_t *task, isc_event_t *event) */ break; } -#endif +#endif /* if 0 */ fprintf(stderr, "; TSIG error with server: %s\n", isc_result_totext(result)); seenerror = true; @@ -2404,14 +2501,16 @@ update_completed(isc_task_t *task, isc_event_t *event) result = dns_rcode_totext(answer->rcode, &b); check_result(result, "dns_rcode_totext"); rds = dns_message_gettsig(answer, NULL); - if (rds != NULL) + if (rds != NULL) { check_tsig_error(rds, &b); + } fprintf(stderr, "update failed: %.*s\n", (int)isc_buffer_usedlength(&b), buf); } } - if (debugging) + if (debugging) { show_message(stderr, answer, "\nReply from update query:"); + } done: dns_request_destroy(&request); @@ -2437,8 +2536,9 @@ send_update(dns_name_t *zone, isc_sockaddr_t *master) setzone(zone); - if (usevc) + if (usevc) { options |= DNS_REQUESTOPT_TCP; + } if (tsigkey == NULL && sig0key != NULL) { result = dns_message_setsig0key(updatemsg, sig0key); check_result(result, "dns_message_setsig0key"); @@ -2450,14 +2550,16 @@ send_update(dns_name_t *zone, isc_sockaddr_t *master) fprintf(stderr, "Sending update to %s\n", addrbuf); } - if (isc_sockaddr_pf(master) == AF_INET6) + if (isc_sockaddr_pf(master) == AF_INET6) { srcaddr = localaddr6; - else + } else { srcaddr = localaddr4; + } /* Windows doesn't like the tsig name to be compressed. */ - if (updatemsg->tsigname) + if (updatemsg->tsigname) { updatemsg->tsigname->attributes |= DNS_NAMEATTR_NOCOMPRESS; + } result = dns_request_createvia(requestmgr, updatemsg, srcaddr, master, -1, options, tsigkey, timeout, @@ -2465,8 +2567,9 @@ send_update(dns_name_t *zone, isc_sockaddr_t *master) update_completed, NULL, &request); check_result(result, "dns_request_createvia"); - if (debugging) + if (debugging) { show_message(stdout, updatemsg, "Outgoing update query:"); + } requests++; } @@ -2479,10 +2582,11 @@ next_server(const char *caller, isc_sockaddr_t *addr, isc_result_t eresult) isc_sockaddr_format(addr, addrbuf, sizeof(addrbuf)); fprintf(stderr, "; Communication with %s failed: %s\n", addrbuf, isc_result_totext(eresult)); - if (++ns_inuse >= ns_total) + if (++ns_inuse >= ns_total) { fatal("could not reach any name server"); - else + } else { ddebug("%s: trying next server", caller); + } } static void @@ -2563,10 +2667,11 @@ recvsoa(isc_task_t *task, isc_event_t *event) dns_message_renderreset(soaquery); ddebug("retrying soa request without TSIG"); - if (isc_sockaddr_pf(addr) == AF_INET6) + if (isc_sockaddr_pf(addr) == AF_INET6) { srcaddr = localaddr6; - else + } else { srcaddr = localaddr4; + } result = dns_request_createvia( requestmgr, soaquery, srcaddr, addr, -1, 0, NULL, @@ -2579,12 +2684,14 @@ recvsoa(isc_task_t *task, isc_event_t *event) check_result(result, "dns_request_getresponse"); section = DNS_SECTION_ANSWER; POST(section); - if (debugging) + if (debugging) { show_message(stderr, rcvmsg, "Reply from SOA query:"); + } if (rcvmsg->rcode != dns_rcode_noerror && - rcvmsg->rcode != dns_rcode_nxdomain) + rcvmsg->rcode != dns_rcode_nxdomain) { fatal("response to SOA query was unsuccessful"); + } if (userzone != NULL && rcvmsg->rcode == dns_rcode_nxdomain) { char namebuf[DNS_NAME_FORMATSIZE]; @@ -2600,12 +2707,13 @@ recvsoa(isc_task_t *task, isc_event_t *event) } lookforsoa: - if (pass == 0) + if (pass == 0) { section = DNS_SECTION_ANSWER; - else if (pass == 1) + } else if (pass == 1) { section = DNS_SECTION_AUTHORITY; - else + } else { goto droplabel; + } result = dns_message_firstname(rcvmsg, section); if (result != ISC_R_SUCCESS) { @@ -2618,8 +2726,9 @@ lookforsoa: soaset = NULL; result = dns_message_findtype(name, dns_rdatatype_soa, 0, &soaset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } if (section == DNS_SECTION_ANSWER) { dns_rdataset_t *tset = NULL; if (dns_message_findtype(name, dns_rdatatype_cname, 0, @@ -2639,8 +2748,9 @@ lookforsoa: goto lookforsoa; } - if (seencname) + if (seencname) { goto droplabel; + } if (debugging) { char namestr[DNS_NAME_FORMATSIZE]; @@ -2686,9 +2796,10 @@ lookforsoa: check_result(result, "dns_name_totext"); serverstr[isc_buffer_usedlength(&buf)] = 0; - if (master_servers != NULL && master_servers != servers) + if (master_servers != NULL && master_servers != servers) { isc_mem_put(gmctx, master_servers, master_alloc * sizeof(isc_sockaddr_t)); + } master_alloc = MAX_SERVERADDRS; size = master_alloc * sizeof(isc_sockaddr_t); master_servers = isc_mem_get(gmctx, size); @@ -2700,8 +2811,9 @@ lookforsoa: exit(1); } master_inuse = 0; - } else + } else { master_from_servers(); + } dns_rdata_freestruct(&soa); #ifdef GSSAPI @@ -2715,10 +2827,10 @@ lookforsoa: send_update(zname, &master_servers[master_inuse]); setzoneclass(dns_rdataclass_none); } -#else +#else /* ifdef GSSAPI */ send_update(zname, &master_servers[master_inuse]); setzoneclass(dns_rdataclass_none); -#endif +#endif /* ifdef GSSAPI */ dns_message_destroy(&soaquery); dns_request_destroy(&request); @@ -2734,8 +2846,9 @@ droplabel: name = NULL; dns_message_currentname(soaquery, DNS_SECTION_QUESTION, &name); nlabels = dns_name_countlabels(name); - if (nlabels == 1) + if (nlabels == 1) { fatal("could not find enclosing zone"); + } dns_name_init(&tname, NULL); dns_name_getlabelsequence(name, 1, nlabels - 1, &tname); dns_name_clone(&tname, name); @@ -2758,10 +2871,11 @@ sendrequest(isc_sockaddr_t *destaddr, dns_message_t *msg, reqinfo->msg = msg; reqinfo->addr = destaddr; - if (isc_sockaddr_pf(destaddr) == AF_INET6) + if (isc_sockaddr_pf(destaddr) == AF_INET6) { srcaddr = localaddr6; - else + } else { srcaddr = localaddr4; + } result = dns_request_createvia(requestmgr, msg, srcaddr, destaddr, -1, 0, default_servers ? NULL : tsigkey, @@ -2787,8 +2901,9 @@ get_ticket_realm(isc_mem_t *mctx) const char * ticket_realm; rc = krb5_init_context(&ctx); - if (rc != 0) + if (rc != 0) { return; + } rc = krb5_cc_default(ctx, &ccache); if (rc != 0) { @@ -2820,8 +2935,9 @@ get_ticket_realm(isc_mem_t *mctx) krb5_free_principal(ctx, princ); krb5_cc_close(ctx, ccache); krb5_free_context(ctx); - if (realm != NULL && debugging) + if (realm != NULL && debugging) { fprintf(stderr, "Found realm from ticket: %s\n", realm + 1); + } } static void @@ -2855,14 +2971,16 @@ start_gssrequest(dns_name_t *master) debug("start_gssrequest"); usevc = true; - if (gssring != NULL) + if (gssring != NULL) { dns_tsigkeyring_detach(&gssring); + } gssring = NULL; result = dns_tsigkeyring_create(gmctx, &gssring); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("dns_tsigkeyring_create failed: %s", isc_result_totext(result)); + } dns_name_format(master, namestr, sizeof(namestr)); if (kserver == NULL) { @@ -2873,8 +2991,9 @@ start_gssrequest(dns_name_t *master) servname = dns_fixedname_initname(&fname); - if (realm == NULL) + if (realm == NULL) { get_ticket_realm(gmctx); + } result = snprintf(servicename, sizeof(servicename), "DNS/%s%s", namestr, realm ? realm : ""); @@ -2909,9 +3028,10 @@ start_gssrequest(dns_name_t *master) rmsg = NULL; result = dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &rmsg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("dns_message_create failed: %s", isc_result_totext(result)); + } /* Build first request. */ context = GSS_C_NO_CONTEXT; @@ -2923,18 +3043,21 @@ start_gssrequest(dns_name_t *master) err_message != NULL ? err_message : "unknown error"); goto failure; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("dns_tkey_buildgssquery failed: %s", isc_result_totext(result)); + } send_gssrequest(kserver, rmsg, &request, context); return; failure: - if (rmsg != NULL) + if (rmsg != NULL) { dns_message_destroy(&rmsg); - if (err_message != NULL) + } + if (err_message != NULL) { isc_mem_free(gmctx, err_message); + } failed_gssrequest(); } @@ -2955,18 +3078,20 @@ send_gssrequest(isc_sockaddr_t *destaddr, dns_message_t *msg, options |= DNS_REQUESTOPT_TCP; - if (isc_sockaddr_pf(destaddr) == AF_INET6) + if (isc_sockaddr_pf(destaddr) == AF_INET6) { srcaddr = localaddr6; - else + } else { srcaddr = localaddr4; + } result = dns_request_createvia(requestmgr, msg, srcaddr, destaddr, -1, options, tsigkey, FIND_TIMEOUT * 20, FIND_TIMEOUT, 3, global_task, recvgss, reqinfo, request); check_result(result, "dns_request_createvia"); - if (debugging) + if (debugging) { show_message(stdout, msg, "Outgoing update query:"); + } requests++; } @@ -3039,25 +3164,28 @@ recvgss(isc_task_t *task, isc_event_t *event) DNS_MESSAGEPARSE_PRESERVEORDER); check_result(result, "dns_request_getresponse"); - if (debugging) + if (debugging) { show_message(stderr, rcvmsg, "recvmsg reply from GSS-TSIG query"); + } if (rcvmsg->rcode == dns_rcode_formerr && !tried_other_gsstsig) { ddebug("recvgss trying %s GSS-TSIG", use_win2k_gsstsig ? "Standard" : "Win2k"); - if (use_win2k_gsstsig) + if (use_win2k_gsstsig) { use_win2k_gsstsig = false; - else + } else { use_win2k_gsstsig = true; + } tried_other_gsstsig = true; start_gssrequest(&restart_master); goto done; } if (rcvmsg->rcode != dns_rcode_noerror && - rcvmsg->rcode != dns_rcode_nxdomain) + rcvmsg->rcode != dns_rcode_nxdomain) { fatal("response to GSS-TSIG query was unsuccessful"); + } servname = dns_fixedname_initname(&fname); isc_buffer_init(&buf, servicename, strlen(servicename)); @@ -3123,7 +3251,7 @@ done: dns_message_destroy(&rcvmsg); ddebug("Out of recvgss"); } -#endif +#endif /* ifdef GSSAPI */ static void start_update(void) @@ -3138,8 +3266,9 @@ start_update(void) ddebug("start_update()"); - if (answer != NULL) + if (answer != NULL) { dns_message_destroy(&answer); + } /* * If we have both the zone and the servers we have enough information @@ -3156,8 +3285,9 @@ start_update(void) result = dns_message_create(gmctx, DNS_MESSAGE_INTENTRENDER, &soaquery); check_result(result, "dns_message_create"); - if (default_servers) + if (default_servers) { soaquery->flags |= DNS_MESSAGEFLAG_RD; + } result = dns_message_gettempname(soaquery, &name); check_result(result, "dns_message_gettempname"); @@ -3217,8 +3347,9 @@ cleanup(void) { ddebug("cleanup()"); - if (answer != NULL) + if (answer != NULL) { dns_message_destroy(&answer); + } #ifdef GSSAPI if (tsigkey != NULL) { @@ -3243,10 +3374,11 @@ cleanup(void) if (dns_name_dynamic(&restart_master)) { dns_name_free(&restart_master, gmctx); } -#endif +#endif /* ifdef GSSAPI */ - if (sig0key != NULL) + if (sig0key != NULL) { dst_key_free(&sig0key); + } ddebug("Shutting down task manager"); isc_taskmgr_destroy(&taskmgr); @@ -3264,8 +3396,9 @@ cleanup(void) isc_log_destroy(&glctx); ddebug("Destroying memory context"); - if (memdebugging) + if (memdebugging) { isc_mem_stats(gmctx, stderr); + } isc_mem_destroy(&gmctx); } @@ -3281,8 +3414,9 @@ getinput(isc_task_t *task, isc_event_t *event) return; } - if (global_event == NULL) + if (global_event == NULL) { global_event = event; + } reset_system(); more = user_interaction(); @@ -3333,8 +3467,9 @@ main(int argc, char **argv) isc_app_finish(); - if (seenerror) + if (seenerror) { return (2); - else + } else { return (0); + } } diff --git a/bin/pkcs11/pkcs11-destroy.c b/bin/pkcs11/pkcs11-destroy.c index 60d8f6487c..3a0b52e8e0 100644 --- a/bin/pkcs11/pkcs11-destroy.c +++ b/bin/pkcs11/pkcs11-destroy.c @@ -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); diff --git a/bin/pkcs11/pkcs11-keygen.c b/bin/pkcs11/pkcs11-keygen.c index 902391299c..8425f0cd8b 100644 --- a/bin/pkcs11/pkcs11-keygen.c +++ b/bin/pkcs11/pkcs11-keygen.c @@ -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: "); diff --git a/bin/pkcs11/pkcs11-list.c b/bin/pkcs11/pkcs11-list.c index 2735cea912..5210f0084b 100644 --- a/bin/pkcs11/pkcs11-list.c +++ b/bin/pkcs11/pkcs11-list.c @@ -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) && diff --git a/bin/pkcs11/pkcs11-tokens.c b/bin/pkcs11/pkcs11-tokens.c index 70709138c6..4e015b1d48 100644 --- a/bin/pkcs11/pkcs11-tokens.c +++ b/bin/pkcs11/pkcs11-tokens.c @@ -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); diff --git a/bin/plugins/filter-aaaa.c b/bin/plugins/filter-aaaa.c index 3044584371..81da33845d 100644 --- a/bin/plugins/filter-aaaa.c +++ b/bin/plugins/filter-aaaa.c @@ -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(). diff --git a/bin/rndc/include/rndc/os.h b/bin/rndc/include/rndc/os.h index 9c2a585ff2..3b35718d6d 100644 --- a/bin/rndc/include/rndc/os.h +++ b/bin/rndc/include/rndc/os.h @@ -31,4 +31,4 @@ set_user(FILE *fd, const char *user); ISC_LANG_ENDDECLS -#endif +#endif /* ifndef RNDC_OS_H */ diff --git a/bin/rndc/rndc.c b/bin/rndc/rndc.c index 324c3bdf02..d88ed764b5 100644 --- a/bin/rndc/rndc.c +++ b/bin/rndc/rndc.c @@ -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); } diff --git a/bin/tests/cfg_test.c b/bin/tests/cfg_test.c index 7b496182b0..2dc984c6d5 100644 --- a/bin/tests/cfg_test.c +++ b/bin/tests/cfg_test.c @@ -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); + } } diff --git a/bin/tests/makejournal.c b/bin/tests/makejournal.c index 57d314e531..df4ea26aef 100644 --- a/bin/tests/makejournal.c +++ b/bin/tests/makejournal.c @@ -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); } diff --git a/bin/tests/optional/adb_test.c b/bin/tests/optional/adb_test.c index 1fb631745e..580acbb8e8 100644 --- a/bin/tests/optional/adb_test.c +++ b/bin/tests/optional/adb_test.c @@ -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) { diff --git a/bin/tests/optional/backtrace_test.c b/bin/tests/optional/backtrace_test.c index 98501db906..cc122b7e1e 100644 --- a/bin/tests/optional/backtrace_test.c +++ b/bin/tests/optional/backtrace_test.c @@ -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)); } diff --git a/bin/tests/optional/byaddr_test.c b/bin/tests/optional/byaddr_test.c index 154732c59c..1e18393e06 100644 --- a/bin/tests/optional/byaddr_test.c +++ b/bin/tests/optional/byaddr_test.c @@ -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(); diff --git a/bin/tests/optional/byname_test.c b/bin/tests/optional/byname_test.c index 640b4f23bf..77a89ad16e 100644 --- a/bin/tests/optional/byname_test.c +++ b/bin/tests/optional/byname_test.c @@ -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(); diff --git a/bin/tests/optional/db_test.c b/bin/tests/optional/db_test.c index 66b45f444e..7e132bd571 100644 --- a/bin/tests/optional/db_test.c +++ b/bin/tests/optional/db_test.c @@ -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); } diff --git a/bin/tests/optional/fsaccess_test.c b/bin/tests/optional/fsaccess_test.c index 4baea111ee..d3c51798a2 100644 --- a/bin/tests/optional/fsaccess_test.c +++ b/bin/tests/optional/fsaccess_test.c @@ -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); diff --git a/bin/tests/optional/gsstest.c b/bin/tests/optional/gsstest.c index a4178d2a76..4b304be68a 100644 --- a/bin/tests/optional/gsstest.c +++ b/bin/tests/optional/gsstest.c @@ -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 */ diff --git a/bin/tests/optional/inter_test.c b/bin/tests/optional/inter_test.c index 57986d4cb1..540d14d6e9 100644 --- a/bin/tests/optional/inter_test.c +++ b/bin/tests/optional/inter_test.c @@ -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)); diff --git a/bin/tests/optional/lex_test.c b/bin/tests/optional/lex_test.c index f707f403d3..17d07140a9 100644 --- a/bin/tests/optional/lex_test.c +++ b/bin/tests/optional/lex_test.c @@ -136,18 +136,22 @@ main(int argc, char *argv[]) isc_lex_getsourceline(lex), (name == NULL) ? "" : 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); diff --git a/bin/tests/optional/lfsr_test.c b/bin/tests/optional/lfsr_test.c index 371ddd3305..d282e6d67c 100644 --- a/bin/tests/optional/lfsr_test.c +++ b/bin/tests/optional/lfsr_test.c @@ -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); diff --git a/bin/tests/optional/log_test.c b/bin/tests/optional/log_test.c index bb6a061e5c..c22dcc461b 100644 --- a/bin/tests/optional/log_test.c +++ b/bin/tests/optional/log_test.c @@ -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); } diff --git a/bin/tests/optional/master_test.c b/bin/tests/optional/master_test.c index 12fe4b3144..27b2dfe4ff 100644 --- a/bin/tests/optional/master_test.c +++ b/bin/tests/optional/master_test.c @@ -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); } diff --git a/bin/tests/optional/name_test.c b/bin/tests/optional/name_test.c index 21e6974a2d..7bbd82d4ef 100644 --- a/bin/tests/optional/name_test.c +++ b/bin/tests/optional/name_test.c @@ -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("\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("\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); + } } } diff --git a/bin/tests/optional/nsecify.c b/bin/tests/optional/nsecify.c index d977b32b70..7d0f61d87f 100644 --- a/bin/tests/optional/nsecify.c +++ b/bin/tests/optional/nsecify.c @@ -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); diff --git a/bin/tests/optional/rbt_test.c b/bin/tests/optional/rbt_test.c index 98b3f44b17..b0d5ab0c16 100644 --- a/bin/tests/optional/rbt_test.c +++ b/bin/tests/optional/rbt_test.c @@ -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); } diff --git a/bin/tests/optional/rwlock_test.c b/bin/tests/optional/rwlock_test.c index b3698230ec..33eae38afe 100644 --- a/bin/tests/optional/rwlock_test.c +++ b/bin/tests/optional/rwlock_test.c @@ -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); diff --git a/bin/tests/optional/serial_test.c b/bin/tests/optional/serial_test.c index 7d0655e5e2..8780f2aa26 100644 --- a/bin/tests/optional/serial_test.c +++ b/bin/tests/optional/serial_test.c @@ -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), diff --git a/bin/tests/optional/shutdown_test.c b/bin/tests/optional/shutdown_test.c index 0d09a6fa5d..c1f62354ea 100644 --- a/bin/tests/optional/shutdown_test.c +++ b/bin/tests/optional/shutdown_test.c @@ -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; diff --git a/bin/tests/optional/sig0_test.c b/bin/tests/optional/sig0_test.c index 4075b28932..91acb36ddd 100644 --- a/bin/tests/optional/sig0_test.c +++ b/bin/tests/optional/sig0_test.c @@ -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); diff --git a/bin/tests/optional/sock_test.c b/bin/tests/optional/sock_test.c index 8d7686c72c..61891c694d 100644 --- a/bin/tests/optional/sock_test.c +++ b/bin/tests/optional/sock_test.c @@ -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); diff --git a/bin/tests/optional/sym_test.c b/bin/tests/optional/sym_test.c index 3a7be0e5eb..b3d710a0ce 100644 --- a/bin/tests/optional/sym_test.c +++ b/bin/tests/optional/sym_test.c @@ -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); + } } } } diff --git a/bin/tests/optional/task_test.c b/bin/tests/optional/task_test.c index 1db1a9a2cb..1a3410fea8 100644 --- a/bin/tests/optional/task_test.c +++ b/bin/tests/optional/task_test.c @@ -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); diff --git a/bin/tests/optional/timer_test.c b/bin/tests/optional/timer_test.c index aff62caf2c..98784cf7ad 100644 --- a/bin/tests/optional/timer_test.c +++ b/bin/tests/optional/timer_test.c @@ -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"); diff --git a/bin/tests/optional/zone_test.c b/bin/tests/optional/zone_test.c index d6a1b7e594..2a343b5ae5 100644 --- a/bin/tests/optional/zone_test.c +++ b/bin/tests/optional/zone_test.c @@ -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); diff --git a/bin/tests/pkcs11/benchmarks/create.c b/bin/tests/pkcs11/benchmarks/create.c index 439f7027d1..79de82cf82 100644 --- a/bin/tests/pkcs11/benchmarks/create.c +++ b/bin/tests/pkcs11/benchmarks/create.c @@ -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, diff --git a/bin/tests/pkcs11/benchmarks/find.c b/bin/tests/pkcs11/benchmarks/find.c index a97a9c8b5d..1c1114b13a 100644 --- a/bin/tests/pkcs11/benchmarks/find.c +++ b/bin/tests/pkcs11/benchmarks/find.c @@ -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); diff --git a/bin/tests/pkcs11/benchmarks/genrsa.c b/bin/tests/pkcs11/benchmarks/genrsa.c index e957c840dc..c827fb8859 100644 --- a/bin/tests/pkcs11/benchmarks/genrsa.c +++ b/bin/tests/pkcs11/benchmarks/genrsa.c @@ -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, diff --git a/bin/tests/pkcs11/benchmarks/login.c b/bin/tests/pkcs11/benchmarks/login.c index 5a0c361a90..b3623658a3 100644 --- a/bin/tests/pkcs11/benchmarks/login.c +++ b/bin/tests/pkcs11/benchmarks/login.c @@ -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); } diff --git a/bin/tests/pkcs11/benchmarks/privrsa.c b/bin/tests/pkcs11/benchmarks/privrsa.c index 2491d95ecc..b6d873f84a 100644 --- a/bin/tests/pkcs11/benchmarks/privrsa.c +++ b/bin/tests/pkcs11/benchmarks/privrsa.c @@ -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, diff --git a/bin/tests/pkcs11/benchmarks/pubrsa.c b/bin/tests/pkcs11/benchmarks/pubrsa.c index e576049d46..1ceb014004 100644 --- a/bin/tests/pkcs11/benchmarks/pubrsa.c +++ b/bin/tests/pkcs11/benchmarks/pubrsa.c @@ -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, diff --git a/bin/tests/pkcs11/benchmarks/session.c b/bin/tests/pkcs11/benchmarks/session.c index 648cec2964..d7c4fd1c22 100644 --- a/bin/tests/pkcs11/benchmarks/session.c +++ b/bin/tests/pkcs11/benchmarks/session.c @@ -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); } diff --git a/bin/tests/pkcs11/benchmarks/sha1.c b/bin/tests/pkcs11/benchmarks/sha1.c index f052e670e0..b4769690dd 100644 --- a/bin/tests/pkcs11/benchmarks/sha1.c +++ b/bin/tests/pkcs11/benchmarks/sha1.c @@ -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); diff --git a/bin/tests/pkcs11/benchmarks/sign.c b/bin/tests/pkcs11/benchmarks/sign.c index d1d7efd66c..e5c8815085 100644 --- a/bin/tests/pkcs11/benchmarks/sign.c +++ b/bin/tests/pkcs11/benchmarks/sign.c @@ -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); diff --git a/bin/tests/pkcs11/benchmarks/verify.c b/bin/tests/pkcs11/benchmarks/verify.c index af9e621d0f..bb68f46503 100644 --- a/bin/tests/pkcs11/benchmarks/verify.c +++ b/bin/tests/pkcs11/benchmarks/verify.c @@ -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) { diff --git a/bin/tests/system/dlzexternal/driver.c b/bin/tests/system/dlzexternal/driver.c index 5d79015b7a..eee310fbb1 100644 --- a/bin/tests/system/dlzexternal/driver.c +++ b/bin/tests/system/dlzexternal/driver.c @@ -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); diff --git a/bin/tests/system/dyndb/driver/db.c b/bin/tests/system/dyndb/driver/db.c index 48909e91e6..7fefbc3b6b 100644 --- a/bin/tests/system/dyndb/driver/db.c +++ b/bin/tests/system/dyndb/driver/db.c @@ -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)); diff --git a/bin/tests/system/dyndb/driver/driver.c b/bin/tests/system/dyndb/driver/driver.c index f890ac0edd..6fb4154c71 100644 --- a/bin/tests/system/dyndb/driver/driver.c +++ b/bin/tests/system/dyndb/driver/driver.c @@ -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); } diff --git a/bin/tests/system/dyndb/driver/instance.c b/bin/tests/system/dyndb/driver/instance.c index 347115c39c..e5a1cefc0d 100644 --- a/bin/tests/system/dyndb/driver/instance.c +++ b/bin/tests/system/dyndb/driver/instance.c @@ -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); diff --git a/bin/tests/system/dyndb/driver/lock.c b/bin/tests/system/dyndb/driver/lock.c index 6423805151..6a407cb330 100644 --- a/bin/tests/system/dyndb/driver/lock.c +++ b/bin/tests/system/dyndb/driver/lock.c @@ -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; } diff --git a/bin/tests/system/dyndb/driver/syncptr.c b/bin/tests/system/dyndb/driver/syncptr.c index d9ebccb3bf..b231aa1c16 100644 --- a/bin/tests/system/dyndb/driver/syncptr.c +++ b/bin/tests/system/dyndb/driver/syncptr.c @@ -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); diff --git a/bin/tests/system/dyndb/driver/zone.c b/bin/tests/system/dyndb/driver/zone.c index c714ea8cf7..75aae55c1c 100644 --- a/bin/tests/system/dyndb/driver/zone.c +++ b/bin/tests/system/dyndb/driver/zone.c @@ -87,12 +87,14 @@ cleanup: log_error_r("failed to create new zone '%s'", zone_name); if (raw != NULL) { - if (dns_zone_getmgr(raw) != NULL) + if (dns_zone_getmgr(raw) != NULL) { dns_zonemgr_releasezone(inst->zmgr, raw); + } dns_zone_detach(&raw); } - if (acl_any != NULL) + if (acl_any != NULL) { dns_acl_detach(&acl_any); + } return (result); } @@ -116,8 +118,9 @@ publish_zone(sample_instance_t *inst, dns_zone_t *zone) /* Return success if the zone is already in the view as expected. */ result = dns_view_findzone(inst->view, dns_zone_getorigin(zone), &zone_in_view); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto cleanup; + } view_in_zone = dns_zone_getview(zone); if (view_in_zone != NULL) { @@ -161,10 +164,12 @@ publish_zone(sample_instance_t *inst, dns_zone_t *zone) } cleanup: - if (zone_in_view != NULL) + if (zone_in_view != NULL) { dns_zone_detach(&zone_in_view); - if (freeze) + } + if (freeze) { dns_view_freeze(inst->view); + } run_exclusive_exit(inst, lock_state); return (result); @@ -183,8 +188,9 @@ load_zone(dns_zone_t *zone) result = dns_zone_load(zone, false); if (result != ISC_R_SUCCESS && result != DNS_R_UPTODATE && - result != DNS_R_DYNAMIC && result != DNS_R_CONTINUE) + result != DNS_R_DYNAMIC && result != DNS_R_CONTINUE) { goto cleanup; + } zone_dynamic = (result == DNS_R_DYNAMIC); result = dns_zone_getserial(zone, &serial); @@ -196,8 +202,9 @@ load_zone(dns_zone_t *zone) } dns_zone_log(zone, ISC_LOG_INFO, "loaded serial %u", serial); - if (zone_dynamic) + if (zone_dynamic) { dns_zone_notify(zone); + } cleanup: return (result); diff --git a/bin/tests/system/feature-test.c b/bin/tests/system/feature-test.c index 38b1128492..3538f9a80a 100644 --- a/bin/tests/system/feature-test.c +++ b/bin/tests/system/feature-test.c @@ -22,15 +22,15 @@ #ifdef WIN32 #include -#endif +#endif /* ifdef WIN32 */ #ifndef MAXHOSTNAMELEN #ifdef HOST_NAME_MAX #define MAXHOSTNAMELEN HOST_NAME_MAX -#else +#else /* ifdef HOST_NAME_MAX */ #define MAXHOSTNAMELEN 256 -#endif -#endif +#endif /* ifdef HOST_NAME_MAX */ +#endif /* ifndef MAXHOSTNAMELEN */ static void usage() @@ -61,17 +61,17 @@ main(int argc, char **argv) if (strcmp(argv[1], "--enable-dnsrps") == 0) { #ifdef USE_DNSRPS return (0); -#else +#else /* ifdef USE_DNSRPS */ return (1); -#endif +#endif /* ifdef USE_DNSRPS */ } if (strcmp(argv[1], "--edns-version") == 0) { #ifdef DNS_EDNS_VERSION printf("%d\n", DNS_EDNS_VERSION); -#else +#else /* ifdef DNS_EDNS_VERSION */ printf("0\n"); -#endif +#endif /* ifdef DNS_EDNS_VERSION */ return (0); } @@ -90,7 +90,7 @@ main(int argc, char **argv) fprintf(stderr, "WSAStartup() failed: %d\n", err); exit(1); } -#endif +#endif /* ifdef WIN32 */ n = gethostname(hostname, sizeof(hostname)); if (n == -1) { @@ -100,64 +100,64 @@ main(int argc, char **argv) fprintf(stdout, "%s\n", hostname); #ifdef WIN32 WSACleanup(); -#endif +#endif /* ifdef WIN32 */ return (0); } if (strcmp(argv[1], "--gssapi") == 0) { #if defined(GSSAPI) return (0); -#else +#else /* if defined(GSSAPI) */ return (1); -#endif +#endif /* if defined(GSSAPI) */ } if (strcmp(argv[1], "--have-dlopen") == 0) { #if defined(HAVE_DLOPEN) && defined(ISC_DLZ_DLOPEN) return (0); -#else +#else /* if defined(HAVE_DLOPEN) && defined(ISC_DLZ_DLOPEN) */ return (1); -#endif +#endif /* if defined(HAVE_DLOPEN) && defined(ISC_DLZ_DLOPEN) */ } if (strcmp(argv[1], "--have-geoip2") == 0) { #ifdef HAVE_GEOIP2 return (0); -#else +#else /* ifdef HAVE_GEOIP2 */ return (1); -#endif +#endif /* ifdef HAVE_GEOIP2 */ } if (strcmp(argv[1], "--have-libxml2") == 0) { #ifdef HAVE_LIBXML2 return (0); -#else +#else /* ifdef HAVE_LIBXML2 */ return (1); -#endif +#endif /* ifdef HAVE_LIBXML2 */ } if (strcmp(argv[1], "--with-idn") == 0) { #ifdef HAVE_LIBIDN2 return (0); -#else +#else /* ifdef HAVE_LIBIDN2 */ return (1); -#endif +#endif /* ifdef HAVE_LIBIDN2 */ } if (strcmp(argv[1], "--with-lmdb") == 0) { #ifdef HAVE_LMDB return (0); -#else +#else /* ifdef HAVE_LMDB */ return (1); -#endif +#endif /* ifdef HAVE_LMDB */ } if (strcmp(argv[1], "--with-dlz-filesystem") == 0) { #ifdef DLZ_FILESYSTEM return (0); -#else +#else /* ifdef DLZ_FILESYSTEM */ return (1); -#endif +#endif /* ifdef DLZ_FILESYSTEM */ } if (strcmp(argv[1], "--ipv6only=no") == 0) { @@ -176,9 +176,9 @@ main(int argc, char **argv) close(s); } return ((n == 0 && v6only == 0) ? 0 : 1); -#else +#else /* ifdef WIN32 */ return (1); -#endif +#endif /* ifdef WIN32 */ } fprintf(stderr, "unknown arg: %s\n", argv[1]); diff --git a/bin/tests/system/pipelined/pipequeries.c b/bin/tests/system/pipelined/pipequeries.c index 93f4674a15..87f038cf82 100644 --- a/bin/tests/system/pipelined/pipequeries.c +++ b/bin/tests/system/pipelined/pipequeries.c @@ -120,8 +120,9 @@ recvresponse(isc_task_t *task, isc_event_t *event) dns_request_destroy(&reqev->request); isc_event_free(&event); - if (--onfly == 0) + if (--onfly == 0) { isc_app_shutdown(); + } return; } @@ -139,8 +140,9 @@ sendquery(isc_task_t *task) int c; c = scanf("%255s", host); - if (c == EOF) - return ISC_R_NOMORE; + if (c == EOF) { + return (ISC_R_NOMORE); + } onfly++; @@ -182,7 +184,7 @@ sendquery(isc_task_t *task) task, recvresponse, message, &request); CHECK("dns_request_create", result); - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } static void @@ -196,8 +198,9 @@ sendqueries(isc_task_t *task, isc_event_t *event) result = sendquery(task); } while (result == ISC_R_SUCCESS); - if (onfly == 0) + if (onfly == 0) { isc_app_shutdown(); + } return; } @@ -259,13 +262,15 @@ main(int argc, char *argv[]) isc_sockaddr_any(&bind_any); result = ISC_R_FAILURE; - if (inet_pton(AF_INET, "10.53.0.7", &inaddr) != 1) + if (inet_pton(AF_INET, "10.53.0.7", &inaddr) != 1) { CHECK("inet_pton", result); + } isc_sockaddr_fromin(&srcaddr, &inaddr, 0); result = ISC_R_FAILURE; - if (inet_pton(AF_INET, "10.53.0.4", &inaddr) != 1) + if (inet_pton(AF_INET, "10.53.0.4", &inaddr) != 1) { CHECK("inet_pton", result); + } isc_sockaddr_fromin(&dstaddr, &inaddr, port); mctx = NULL; diff --git a/bin/tests/system/rndc/gencheck.c b/bin/tests/system/rndc/gencheck.c index 6338a63512..b590a869bd 100644 --- a/bin/tests/system/rndc/gencheck.c +++ b/bin/tests/system/rndc/gencheck.c @@ -30,13 +30,15 @@ check(const char *buf, ssize_t count, size_t *start) for (i = 0; i < count; i++, *start = (*start + 1) % (sizeof(chars) - 1)) { /* Just ignore the trailing newline */ - if (buf[i] == '\n') + if (buf[i] == '\n') { continue; - if (buf[i] != chars[*start]) - return 0; + } + if (buf[i] != chars[*start]) { + return (0); + } } - return 1; + return (1); } int @@ -59,16 +61,19 @@ main(int argc, char **argv) } fd = open(argv[1], O_RDONLY); - if (fd == -1) + if (fd == -1) { goto out; + } start = 0; while ((count = read(fd, buf, sizeof(buf))) != 0) { - if (count < 0) + if (count < 0) { goto out; + } - if (!check(buf, count, &start)) + if (!check(buf, count, &start)) { goto out; + } length += count; } @@ -78,8 +83,9 @@ main(int argc, char **argv) out: printf("%lu\n", (unsigned long)length); - if (fd != -1) + if (fd != -1) { close(fd); + } return (ret); } diff --git a/bin/tests/system/rpz/dnsrps.c b/bin/tests/system/rpz/dnsrps.c index 1aa056a3e1..368092776f 100644 --- a/bin/tests/system/rpz/dnsrps.c +++ b/bin/tests/system/rpz/dnsrps.c @@ -40,11 +40,11 @@ #include librpz_t *librpz; -#else +#else /* ifdef USE_DNSRPS */ typedef struct { char c[120]; } librpz_emsg_t; -#endif +#endif /* ifdef USE_DNSRPS */ static bool link_dnsrps(librpz_emsg_t *emsg); @@ -60,7 +60,7 @@ main(int argc, char **argv) librpz_client_t *client; librpz_rsp_t * rsp; uint32_t serial; -#endif +#endif /* ifdef USE_DNSRPS */ double seconds; librpz_emsg_t emsg; char * p; @@ -82,10 +82,10 @@ main(int argc, char **argv) } #ifdef USE_DNSRPS printf("%s\n", librpz->dnsrpzd_path); -#else +#else /* ifdef USE_DNSRPS */ INSIST(0); ISC_UNREACHABLE(); -#endif +#endif /* ifdef USE_DNSRPS */ return (0); case 'n': @@ -133,10 +133,10 @@ main(int argc, char **argv) librpz->rsp_detach(&rsp); librpz->client_detach(&client); printf("%u\n", serial); -#else +#else /* ifdef USE_DNSRPS */ INSIST(0); ISC_UNREACHABLE(); -#endif +#endif /* ifdef USE_DNSRPS */ return (0); case 'w': @@ -162,12 +162,13 @@ link_dnsrps(librpz_emsg_t *emsg) { #ifdef USE_DNSRPS librpz = librpz_lib_open(emsg, NULL, DNSRPS_LIBRPZ_PATH); - if (librpz == NULL) + if (librpz == NULL) { return (false); + } return (true); -#else +#else /* ifdef USE_DNSRPS */ snprintf(emsg->c, sizeof(emsg->c), "DNSRPS not configured"); return (false); -#endif +#endif /* ifdef USE_DNSRPS */ } diff --git a/bin/tests/system/tkey/keycreate.c b/bin/tests/system/tkey/keycreate.c index 45bdf9ff93..09600fa8bc 100644 --- a/bin/tests/system/tkey/keycreate.c +++ b/bin/tests/system/tkey/keycreate.c @@ -142,8 +142,9 @@ sendquery(isc_task_t *task, isc_event_t *event) isc_event_free(&event); result = ISC_R_FAILURE; - if (inet_pton(AF_INET, "10.53.0.1", &inaddr) != 1) + if (inet_pton(AF_INET, "10.53.0.1", &inaddr) != 1) { CHECK("inet_pton", result); + } isc_sockaddr_fromin(&address, &inaddr, PORT); dns_fixedname_init(&keyname); @@ -221,8 +222,9 @@ main(int argc, char *argv[]) } ourkeyname = argv[1]; - if (argc >= 3) + if (argc >= 3) { ownername_str = argv[2]; + } dns_result_register(); diff --git a/bin/tests/system/tkey/keydelete.c b/bin/tests/system/tkey/keydelete.c index b8031788db..d645406ad6 100644 --- a/bin/tests/system/tkey/keydelete.c +++ b/bin/tests/system/tkey/keydelete.c @@ -115,8 +115,9 @@ sendquery(isc_task_t *task, isc_event_t *event) isc_event_free(&event); result = ISC_R_FAILURE; - if (inet_pton(AF_INET, "10.53.0.1", &inaddr) != 1) + if (inet_pton(AF_INET, "10.53.0.1", &inaddr) != 1) { CHECK("inet_pton", result); + } isc_sockaddr_fromin(&address, &inaddr, PORT); query = NULL; diff --git a/bin/tests/wire_test.c b/bin/tests/wire_test.c index ca8b600f48..3cb65f2766 100644 --- a/bin/tests/wire_test.c +++ b/bin/tests/wire_test.c @@ -48,12 +48,13 @@ CHECKRESULT(isc_result_t result, const char *msg) static int fromhex(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { return (c - '0'); - else if (c >= 'a' && c <= 'f') + } else if (c >= 'a' && c <= 'f') { return (c - 'a' + 10); - else if (c >= 'A' && c <= 'F') + } else if (c >= 'A' && c <= 'F') { return (c - 'A' + 10); + } fprintf(stderr, "bad input format: %02x\n", c); exit(3); @@ -91,12 +92,14 @@ printmessage(dns_message_t *msg) if (result == ISC_R_NOSPACE) { isc_mem_put(mctx, buf, len); len *= 2; - } else if (result == ISC_R_SUCCESS) + } else if (result == ISC_R_SUCCESS) { printf("%.*s\n", (int)isc_buffer_usedlength(&b), buf); + } } while (result == ISC_R_NOSPACE); - if (buf != NULL) + if (buf != NULL) { isc_mem_put(mctx, buf, len); + } return (result); } @@ -120,16 +123,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; @@ -177,8 +188,9 @@ main(int argc, char *argv[]) exit(1); } need_close = true; - } else + } else { f = stdin; + } isc_buffer_allocate(mctx, &input, 64 * 1024); @@ -196,8 +208,9 @@ main(int argc, char *argv[]) size_t i, len = 0; while (*rp != '\0') { - if (*rp == '#') + if (*rp == '#') { break; + } if (*rp != ' ' && *rp != '\t' && *rp != '\r' && *rp != '\n') { *wp++ = *rp; @@ -205,8 +218,9 @@ main(int argc, char *argv[]) } rp++; } - if (len == 0U) + if (len == 0U) { continue; + } if (len % 2 != 0U) { fprintf(stderr, "bad input format: %lu\n", (unsigned long)len); @@ -225,8 +239,9 @@ main(int argc, char *argv[]) } } - if (need_close) + if (need_close) { fclose(f); + } if (tcp) { while (isc_buffer_remaininglength(input) != 0) { @@ -244,14 +259,17 @@ main(int argc, char *argv[]) } process_message(input); } - } else + } else { process_message(input); + } - if (input != NULL) + if (input != NULL) { isc_buffer_free(&input); + } - if (printmemstats) + if (printmemstats) { isc_mem_stats(mctx, stdout); + } isc_mem_destroy(&mctx); return (0); @@ -269,15 +287,17 @@ process_message(isc_buffer_t *source) CHECKRESULT(result, "dns_message_create failed"); result = dns_message_parse(message, source, parseflags); - if (result == DNS_R_RECOVERABLE) + if (result == DNS_R_RECOVERABLE) { result = ISC_R_SUCCESS; + } CHECKRESULT(result, "dns_message_parse failed"); result = printmessage(message); CHECKRESULT(result, "printmessage() failed"); - if (printmemstats) + if (printmemstats) { isc_mem_stats(mctx, stdout); + } if (dorender) { unsigned char b2[64 * 1024]; @@ -293,8 +313,9 @@ process_message(isc_buffer_t *source) */ message->from_to_wire = DNS_MESSAGE_INTENTRENDER; - for (i = 0; i < DNS_SECTION_MAX; i++) + for (i = 0; i < DNS_SECTION_MAX; i++) { message->counts[i] = 0; /* Another hack XXX */ + } result = dns_compress_init(&cctx, -1, mctx); CHECKRESULT(result, "dns_compress_init() failed"); @@ -329,8 +350,9 @@ process_message(isc_buffer_t *source) dns_message_destroy(&message); printf("Message rendered.\n"); - if (printmemstats) + if (printmemstats) { isc_mem_stats(mctx, stdout); + } result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &message); diff --git a/bin/tools/arpaname.c b/bin/tools/arpaname.c index d93ecbf34e..a3d9984e8d 100644 --- a/bin/tools/arpaname.c +++ b/bin/tools/arpaname.c @@ -26,9 +26,10 @@ main(int argc, char *argv[]) while (argv[1]) { if (inet_pton(AF_INET6, argv[1], buf) == 1) { - for (i = 15; i >= 0; i--) + for (i = 15; i >= 0; i--) { fprintf(stdout, "%X.%X.", buf[i] & 0xf, (buf[i] >> 4) & 0xf); + } fprintf(stdout, "IP6.ARPA\n"); argv++; continue; diff --git a/bin/tools/dnstap-read.c b/bin/tools/dnstap-read.c index 18262ee8da..3302d3205c 100644 --- a/bin/tools/dnstap-read.c +++ b/bin/tools/dnstap-read.c @@ -101,16 +101,18 @@ print_dtdata(dns_dtdata_t *dt) isc_buffer_t *b = NULL; isc_buffer_allocate(mctx, &b, 2048); - if (b == NULL) + if (b == NULL) { fatal("out of memory"); + } CHECKM(dns_dt_datatotext(dt, &b), "dns_dt_datatotext"); printf("%.*s\n", (int)isc_buffer_usedlength(b), (char *)isc_buffer_base(b)); cleanup: - if (b != NULL) + if (b != NULL) { isc_buffer_free(&b); + } } static void @@ -137,8 +139,9 @@ print_hex(dns_dtdata_t *dt) (char *)isc_buffer_base(b)); cleanup: - if (b != NULL) + if (b != NULL) { isc_buffer_free(&b); + } } static void @@ -151,13 +154,15 @@ print_packet(dns_dtdata_t *dt, const dns_master_style_t *style) size_t textlen = 2048; isc_buffer_allocate(mctx, &b, textlen); - if (b == NULL) + if (b == NULL) { fatal("out of memory"); + } for (;;) { isc_buffer_reserve(&b, textlen); - if (b == NULL) + if (b == NULL) { fatal("out of memory"); + } result = dns_message_totext(dt->msg, style, 0, b); if (result == ISC_R_NOSPACE) { @@ -177,8 +182,9 @@ print_packet(dns_dtdata_t *dt, const dns_master_style_t *style) } cleanup: - if (b != NULL) + if (b != NULL) { isc_buffer_free(&b); + } } static void @@ -191,33 +197,39 @@ print_yaml(dns_dtdata_t *dt) ftype = protobuf_c_enum_descriptor_get_value( &dnstap__dnstap__type__descriptor, frame->type); - if (ftype == NULL) + if (ftype == NULL) { return; + } - if (!first) + if (!first) { printf("---\n"); - else + } else { first = false; + } printf("type: %s\n", ftype->name); - if (frame->has_identity) + if (frame->has_identity) { printf("identity: %.*s\n", (int)frame->identity.len, frame->identity.data); + } - if (frame->has_version) + if (frame->has_version) { printf("version: %.*s\n", (int)frame->version.len, frame->version.data); + } - if (frame->type != DNSTAP__DNSTAP__TYPE__MESSAGE) + if (frame->type != DNSTAP__DNSTAP__TYPE__MESSAGE) { return; + } printf("message:\n"); mtype = protobuf_c_enum_descriptor_get_value( &dnstap__message__type__descriptor, m->type); - if (mtype == NULL) + if (mtype == NULL) { return; + } printf(" type: %s\n", mtype->name); @@ -235,16 +247,18 @@ print_yaml(dns_dtdata_t *dt) if (dt->msgdata.base != NULL) { printf(" message_size: %zub\n", (size_t)dt->msgdata.length); - } else + } else { printf(" message_size: 0b\n"); + } if (m->has_socket_family) { const ProtobufCEnumValue *type = protobuf_c_enum_descriptor_get_value( &dnstap__socket_family__descriptor, m->socket_family); - if (type != NULL) + if (type != NULL) { printf(" socket_family: %s\n", type->name); + } } printf(" socket_protocol: %s\n", dt->tcp ? "TCP" : "UDP"); @@ -267,11 +281,13 @@ print_yaml(dns_dtdata_t *dt) printf(" response_address: %s\n", buf); } - if (m->has_query_port) + if (m->has_query_port) { printf(" query_port: %u\n", m->query_port); + } - if (m->has_response_port) + if (m->has_response_port) { printf(" response_port: %u\n", m->response_port); + } if (m->has_query_zone) { isc_result_t result; @@ -308,7 +324,7 @@ print_yaml(dns_dtdata_t *dt) : "response_message"); print_packet(dt, &dns_master_style_indent); } -}; +} int main(int argc, char *argv[]) @@ -344,8 +360,9 @@ main(int argc, char *argv[]) argc -= isc_commandline_index; argv += isc_commandline_index; - if (argc < 1) + if (argc < 1) { fatal("no file specified"); + } isc_mem_create(&mctx); @@ -361,19 +378,22 @@ main(int argc, char *argv[]) size_t datalen; result = dns_dt_getframe(handle, &data, &datalen); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { break; - else + } else { CHECKM(result, "dns_dt_getframe"); + } input.base = data; input.length = datalen; - if (b != NULL) + if (b != NULL) { isc_buffer_free(&b); + } isc_buffer_allocate(mctx, &b, 2048); - if (b == NULL) + if (b == NULL) { fatal("out of memory"); + } result = dns_dt_parse(mctx, &input, &dt); if (result != ISC_R_SUCCESS) { @@ -397,14 +417,18 @@ main(int argc, char *argv[]) } cleanup: - if (dt != NULL) + if (dt != NULL) { dns_dtdata_free(&dt); - if (handle != NULL) + } + if (handle != NULL) { dns_dt_close(&handle); - if (message != NULL) + } + if (message != NULL) { dns_message_destroy(&message); - if (b != NULL) + } + if (b != NULL) { isc_buffer_free(&b); + } isc_mem_destroy(&mctx); exit(rv); diff --git a/bin/tools/mdig.c b/bin/tools/mdig.c index 7460884c75..22206730b8 100644 --- a/bin/tools/mdig.c +++ b/bin/tools/mdig.c @@ -66,7 +66,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); \ } @@ -117,17 +117,18 @@ static int onfly = 0; static char hexcookie[81]; struct query { - char textname[MXNAME]; /*% Name we're going to be looking up */ - bool recurse; - bool have_aaonly; - bool have_adflag; - bool have_cdflag; - bool have_zflag; - bool dnssec; - bool expire; - bool send_cookie; - char *cookie; - bool nsid; + char textname[MXNAME]; /*% Name we're going to be + * looking up */ + bool recurse; + bool have_aaonly; + bool have_adflag; + bool have_cdflag; + bool have_zflag; + bool dnssec; + bool expire; + bool send_cookie; + char * cookie; + bool nsid; dns_rdatatype_t rdtype; dns_rdataclass_t rdclass; uint16_t udpsize; @@ -174,9 +175,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); } /* receive response event handler */ @@ -201,10 +203,11 @@ recvresponse(isc_task_t *task, isc_event_t *event) if (reqev->result != ISC_R_SUCCESS) { fprintf(stderr, "response failed with %s\n", isc_result_totext(reqev->result)); - if (continue_on_error) + if (continue_on_error) { goto cleanup; - else + } else { exit(-1); + } } result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &response); @@ -261,18 +264,19 @@ recvresponse(isc_task_t *task, isc_event_t *event) } } } - if (display_multiline || (!display_ttl && !display_class)) + if (display_multiline || (!display_ttl && !display_class)) { result = dns_master_stylecreate(&style, styleflags, 24, 24, 24, 32, 80, 8, display_splitwidth, mctx); - else if (!display_ttl || !display_class) + } else if (!display_ttl || !display_class) { result = dns_master_stylecreate(&style, styleflags, 24, 24, 32, 40, 80, 8, display_splitwidth, mctx); - else + } else { result = dns_master_stylecreate(&style, styleflags, 24, 32, 40, 48, 80, 8, display_splitwidth, mctx); + } CHECK("dns_master_stylecreate2", result); flags = 0; @@ -280,8 +284,9 @@ recvresponse(isc_task_t *task, isc_event_t *event) flags |= DNS_MESSAGETEXTFLAG_NOHEADERS; flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS; } - if (!display_comments) + if (!display_comments) { flags |= DNS_MESSAGETEXTFLAG_NOCOMMENTS; + } isc_buffer_allocate(mctx, &buf, len); @@ -346,22 +351,30 @@ recvresponse(isc_task_t *task, isc_event_t *event) opcodetext[response->opcode], rcode_totext(response->rcode), response->id); printf(";; flags:"); - if ((response->flags & DNS_MESSAGEFLAG_QR) != 0) + if ((response->flags & DNS_MESSAGEFLAG_QR) != 0) { printf(" qr"); - if ((response->flags & DNS_MESSAGEFLAG_AA) != 0) + } + if ((response->flags & DNS_MESSAGEFLAG_AA) != 0) { printf(" aa"); - if ((response->flags & DNS_MESSAGEFLAG_TC) != 0) + } + if ((response->flags & DNS_MESSAGEFLAG_TC) != 0) { printf(" tc"); - if ((response->flags & DNS_MESSAGEFLAG_RD) != 0) + } + if ((response->flags & DNS_MESSAGEFLAG_RD) != 0) { printf(" rd"); - if ((response->flags & DNS_MESSAGEFLAG_RA) != 0) + } + if ((response->flags & DNS_MESSAGEFLAG_RA) != 0) { printf(" ra"); - if ((response->flags & DNS_MESSAGEFLAG_AD) != 0) + } + if ((response->flags & DNS_MESSAGEFLAG_AD) != 0) { printf(" ad"); - if ((response->flags & DNS_MESSAGEFLAG_CD) != 0) + } + if ((response->flags & DNS_MESSAGEFLAG_CD) != 0) { printf(" cd"); - if ((response->flags & 0x0040U) != 0) + } + if ((response->flags & 0x0040U) != 0) { printf("; MBZ: 0x4"); + } printf("; QUERY: %u, ANSWER: %u, " "AUTHORITY: %u, ADDITIONAL: %u\n", @@ -371,9 +384,10 @@ recvresponse(isc_task_t *task, isc_event_t *event) response->counts[DNS_SECTION_ADDITIONAL]); if ((response->flags & DNS_MESSAGEFLAG_RD) != 0 && - (response->flags & DNS_MESSAGEFLAG_RA) == 0) + (response->flags & DNS_MESSAGEFLAG_RA) == 0) { printf(";; WARNING: recursion requested " "but not available\n"); + } } } @@ -395,16 +409,18 @@ repopulate_buffer: if (display_question && display_headers && !display_short_form) { result = dns_message_sectiontotext( response, DNS_SECTION_QUESTION, style, flags, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_message_sectiontotext", result); } if (display_answer && !display_short_form) { result = dns_message_sectiontotext(response, DNS_SECTION_ANSWER, style, flags, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_message_sectiontotext", result); } else if (display_answer) { dns_name_t * name; @@ -414,19 +430,23 @@ repopulate_buffer: dns_rdata_t rdata = DNS_RDATA_INIT; unsigned int answerstyleflags = 0; - if (!display_crypto) + if (!display_crypto) { answerstyleflags |= DNS_STYLEFLAG_NOCRYPTO; - if (display_unknown_format) + } + if (display_unknown_format) { answerstyleflags |= DNS_STYLEFLAG_UNKNOWNFORMAT; + } dns_name_init(&empty_name, NULL); result = dns_message_firstname(response, DNS_SECTION_ANSWER); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { CHECK("dns_message_firstname", result); + } for (;;) { - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { break; + } CHECK("dns_message_nextname", result); name = NULL; dns_message_currentname(response, DNS_SECTION_ANSWER, @@ -441,15 +461,17 @@ repopulate_buffer: result = dns_rdata_tofmttext( &rdata, NULL, answerstyleflags, 0, 60, " ", buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_rdata_tofmttext", result); loopresult = dns_rdataset_next(rdataset); dns_rdata_reset(&rdata); if (strlen("\n") >= - isc_buffer_availablelength(buf)) + isc_buffer_availablelength(buf)) { goto buftoosmall; + } isc_buffer_putstr(buf, "\n"); } } @@ -461,16 +483,18 @@ repopulate_buffer: if (display_authority && !display_short_form) { result = dns_message_sectiontotext( response, DNS_SECTION_AUTHORITY, style, flags, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_message_sectiontotext", result); } if (display_additional && !display_short_form) { result = dns_message_sectiontotext( response, DNS_SECTION_ADDITIONAL, style, flags, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_message_sectiontotext", result); } @@ -480,13 +504,15 @@ repopulate_buffer: */ result = dns_message_pseudosectiontotext( response, DNS_PSEUDOSECTION_TSIG, style, flags, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_message_pseudosectiontotext", result); result = dns_message_pseudosectiontotext( response, DNS_PSEUDOSECTION_SIG0, style, flags, buf); - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { goto buftoosmall; + } CHECK("dns_message_pseudosectiontotext", result); } @@ -501,17 +527,21 @@ repopulate_buffer: cleanup: fflush(stdout); - if (style != NULL) + if (style != NULL) { dns_master_styledestroy(&style, mctx); - if (query != NULL) + } + if (query != NULL) { dns_message_destroy(&query); - if (response != NULL) + } + if (response != NULL) { dns_message_destroy(&response); + } dns_request_destroy(&reqev->request); isc_event_free(&event); - if (--onfly == 0) + if (--onfly == 0) { isc_app_shutdown(); + } return; } @@ -568,16 +598,21 @@ sendquery(struct query *query, isc_task_t *task) CHECK("dns_message_create", result); message->opcode = dns_opcode_query; - if (query->recurse) + if (query->recurse) { message->flags |= DNS_MESSAGEFLAG_RD; - if (query->have_aaonly) + } + if (query->have_aaonly) { message->flags |= DNS_MESSAGEFLAG_AA; - if (query->have_adflag) + } + if (query->have_adflag) { message->flags |= DNS_MESSAGEFLAG_AD; - if (query->have_cdflag) + } + if (query->have_cdflag) { message->flags |= DNS_MESSAGEFLAG_CD; - if (query->have_zflag) + } + if (query->have_zflag) { message->flags |= 0x0040U; + } message->rdclass = query->rdclass; message->id = (unsigned short)(random() & 0xFFFF); @@ -603,10 +638,12 @@ sendquery(struct query *query, isc_task_t *task) char ecsbuf[20]; unsigned char cookie[40]; - if (query->udpsize == 0) + if (query->udpsize == 0) { query->udpsize = 4096; - if (query->edns < 0) + } + if (query->edns < 0) { query->edns = 0; + } if (query->nsid) { INSIST(i < DNS_EDNSOPTIONS); @@ -640,9 +677,10 @@ sendquery(struct query *query, isc_task_t *task) family = 1; sin = (struct sockaddr_in *)sa; memmove(addr, &sin->sin_addr, 4); - if ((plen % 8) != 0) + if ((plen % 8) != 0) { addr[addrl - 1] &= ~0U << (8 - (plen % 8)); + } } else { family = 2; sin6 = (struct sockaddr_in6 *)sa; @@ -650,8 +688,9 @@ sendquery(struct query *query, isc_task_t *task) } /* Mask off last address byte */ - if (addrl > 0 && (plen % 8) != 0) + if (addrl > 0 && (plen % 8) != 0) { addr[addrl - 1] &= ~0U << (8 - (plen % 8)); + } /* family */ isc_buffer_putuint16(&b, family); @@ -660,8 +699,9 @@ sendquery(struct query *query, isc_task_t *task) /* scope prefix-length */ isc_buffer_putuint8(&b, 0); /* address */ - if (addrl > 0) + if (addrl > 0) { isc_buffer_putmem(&b, addr, (unsigned)addrl); + } opts[i].value = (uint8_t *)ecsbuf; i++; @@ -703,14 +743,16 @@ sendquery(struct query *query, isc_task_t *task) flags = query->ednsflags; flags &= ~DNS_MESSAGEEXTFLAG_DO; - if (query->dnssec) + if (query->dnssec) { flags |= DNS_MESSAGEEXTFLAG_DO; + } add_opt(message, query->udpsize, query->edns, flags, opts, i); } options = 0; - if (tcp_mode) + if (tcp_mode) { options |= DNS_REQUESTOPT_TCP | DNS_REQUESTOPT_SHARE; + } request = NULL; result = dns_request_createvia( requestmgr, message, have_src ? &srcaddr : NULL, &dstaddr, dscp, @@ -718,7 +760,7 @@ sendquery(struct query *query, isc_task_t *task) query->udpretries, task, recvresponse, message, &request); CHECK("dns_request_createvia4", result); - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } static void @@ -735,8 +777,9 @@ sendqueries(isc_task_t *task, isc_event_t *event) query = next; } - if (onfly == 0) + if (onfly == 0) { isc_app_shutdown(); + } return; } @@ -877,8 +920,9 @@ parse_uint_helper(uint32_t *uip, const char *value, uint32_t max, { uint32_t n; isc_result_t result = isc_parse_uint32(&n, value, base); - 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)); @@ -964,8 +1008,9 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) bool parsed = false; char buf[sizeof("xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:XXX.XXX.XXX.XXX/128")]; - if (strlcpy(buf, value, sizeof(buf)) >= sizeof(buf)) + if (strlcpy(buf, value, sizeof(buf)) >= sizeof(buf)) { fatal("invalid prefix '%s'\n", value); + } slash = strchr(buf, '/'); if (slash != NULL) { @@ -984,13 +1029,15 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) if (inet_pton(AF_INET6, buf, &in6) == 1) { parsed = true; isc_sockaddr_fromin6(sa, &in6, 0); - if (netmask > 128) + if (netmask > 128) { netmask = 128; + } } else if (inet_pton(AF_INET, buf, &in4) == 1) { parsed = true; isc_sockaddr_fromin(sa, &in4, 0); - if (netmask > 32) + if (netmask > 32) { netmask = 32; + } } else if (netmask != 0xffffffff) { int i; @@ -1003,12 +1050,14 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) } } - if (netmask > 32) + if (netmask > 32) { netmask = 32; + } } - if (!parsed) + if (!parsed) { fatal("invalid address '%s'", value); + } sa->length = netmask; *sap = sa; @@ -1023,8 +1072,9 @@ parse_netprefix(isc_sockaddr_t **sap, const char *value) static isc_result_t append(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); @@ -1190,10 +1240,12 @@ plus_option(char *option, struct query *query, bool global) 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"); CHECK("parse_uint(buffer size)", result); @@ -1235,17 +1287,20 @@ plus_option(char *option, struct query *query, bool global) break; case 'o': FULLCHECK("cookie"); - if (state && query->edns == -1) + if (state && query->edns == -1) { query->edns = 0; + } query->send_cookie = state; if (value != NULL) { n = strlcpy(hexcookie, value, sizeof(hexcookie)); - if (n >= sizeof(hexcookie)) + if (n >= sizeof(hexcookie)) { fatal("COOKIE data too large"); + } query->cookie = hexcookie; - } else + } else { query->cookie = NULL; + } break; default: goto invalid_option; @@ -1264,8 +1319,9 @@ plus_option(char *option, struct query *query, bool global) switch (cmd[1]) { case 'n': /* dnssec */ FULLCHECK("dnssec"); - if (state && query->edns == -1) + if (state && query->edns == -1) { query->edns = 0; + } query->dnssec = state; break; case 's': /* dscp */ @@ -1275,8 +1331,9 @@ plus_option(char *option, struct query *query, bool global) dscp = -1; break; } - if (value == NULL) + if (value == NULL) { goto need_value; + } result = parse_uint(&num, value, 0x3f, "DSCP"); CHECK("parse_uint(DSCP)", result); dscp = num; @@ -1376,8 +1433,9 @@ plus_option(char *option, struct query *query, bool global) break; case 'n': FULLCHECK("nsid"); - if (state && query->edns == -1) + if (state && query->edns == -1) { query->edns = 0; + } query->nsid = state; break; case 'q': @@ -1395,10 +1453,12 @@ plus_option(char *option, struct query *query, bool global) 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(&query->udpretries, value, MAXTRIES - 1, "udpretries"); CHECK("parse_uint(udpretries)", result); @@ -1435,13 +1495,15 @@ plus_option(char *option, struct query *query, bool global) case 'p': /* split */ FULLCHECK("split"); GLOBAL(); - if (value != NULL && !state) + if (value != NULL && !state) { goto invalid_option; + } if (!state) { display_splitwidth = 0; break; - } else if (value == NULL) + } else if (value == NULL) { break; + } result = parse_uint(&display_splitwidth, value, 1023, "split"); @@ -1461,14 +1523,16 @@ plus_option(char *option, struct query *query, bool global) * using the default width but incorrect in this * case, so we correct for it */ - if (display_splitwidth) + if (display_splitwidth) { display_splitwidth += 3; + } CHECK("parse_uint(split)", result); break; case 'u': /* subnet */ FULLCHECK("subnet"); - if (state && value == NULL) + if (state && value == NULL) { goto need_value; + } if (!state) { if (query->ecs_addr != NULL) { isc_mem_free(mctx, query->ecs_addr); @@ -1476,8 +1540,9 @@ plus_option(char *option, struct query *query, bool global) } break; } - if (query->edns == -1) + if (query->edns == -1) { query->edns = 0; + } result = parse_netprefix(&query->ecs_addr, value); CHECK("parse_netprefix", result); break; @@ -1494,27 +1559,33 @@ plus_option(char *option, struct query *query, bool global) 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(&query->timeout, value, MAXTIMEOUT, "timeout"); CHECK("parse_uint(timeout)", result); - if (query->timeout == 0) + if (query->timeout == 0) { query->timeout = 1; + } break; case 'r': FULLCHECK("tries"); - if (value == NULL) + if (value == NULL) { goto need_value; - if (!state) + } + if (!state) { goto invalid_option; + } result = parse_uint(&query->udpretries, value, MAXTRIES, "udpretries"); CHECK("parse_uint(udpretries)", result); - if (query->udpretries == 0) + if (query->udpretries == 0) { query->udpretries = 1; + } break; case 't': switch (cmd[2]) { @@ -1548,10 +1619,12 @@ plus_option(char *option, struct query *query, bool global) switch (cmd[1]) { case 'd': FULLCHECK("udptimeout"); - if (value == NULL) + if (value == NULL) { goto need_value; - if (!state) + } + if (!state) { goto invalid_option; + } result = parse_uint(&query->udptimeout, value, MAXTIMEOUT, "udptimeout"); CHECK("parse_uint(udptimeout)", result); @@ -1662,10 +1735,11 @@ dash_option(const char *option, char *next, struct query *query, bool global, 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) { @@ -1675,8 +1749,9 @@ dash_option(const char *option, char *next, struct query *query, bool global, value_from_next = true; value = next; } - if (value == NULL) + if (value == NULL) { goto invalid_option; + } switch (opt) { case 'b': GLOBAL(); @@ -1687,8 +1762,9 @@ dash_option(const char *option, char *next, struct query *query, bool global, CHECK("parse_uint(srcport)", result); srcport = num; *hash = '\0'; - } else + } else { srcport = 0; + } if (have_ipv6 && inet_pton(AF_INET6, value, &in6) == 1) { isc_sockaddr_fromin6(&srcaddr, &in6, srcport); isc_net_disableipv4(); @@ -1696,12 +1772,14 @@ dash_option(const char *option, char *next, struct query *query, bool global, isc_sockaddr_fromin(&srcaddr, &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 = '#'; + } have_src = true; return (value_from_next); case 'c': @@ -1762,10 +1840,11 @@ clone_default_query() memmove(query->ecs_addr, default_query.ecs_addr, len); } - if (query->timeout == 0) + if (query->timeout == 0) { query->timeout = tcp_mode ? TCPTIMEOUT : UDPTIMEOUT; + } - return query; + return (query); } /*% @@ -1788,8 +1867,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]) { @@ -1824,8 +1904,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; + } } } @@ -1882,17 +1963,20 @@ parse_args(bool is_batchfile, int argc, char **argv) /* Processing '-f batchfile'. */ query = clone_default_query(); global = false; - } else + } else { query = &default_query; + } rc = argc; rv = argv; for (rc--, rv++; rc > 0; rc--, rv++) { - if (strncmp(rv[0], "%", 1) == 0) + if (strncmp(rv[0], "%", 1) == 0) { break; + } if (rv[0][0] == '@') { - if (server != NULL) + if (server != NULL) { fatal("server already set to @%s", server); + } server = &rv[0][1]; } else if (rv[0][0] == '+') { plus_option(&rv[0][1], query, global); @@ -1913,8 +1997,9 @@ parse_args(bool is_batchfile, int argc, char **argv) } } if (setname) { - if (query == &default_query) + if (query == &default_query) { query = clone_default_query(); + } ISC_LIST_APPEND(queries, query, link); default_query.textname[0] = 0; @@ -1925,8 +2010,9 @@ parse_args(bool is_batchfile, int argc, char **argv) /* * Anything which isn't an option */ - if (query == &default_query) + if (query == &default_query) { query = clone_default_query(); + } strlcpy(query->textname, rv[0], sizeof(query->textname)); ISC_LIST_APPEND(queries, query, link); @@ -1941,18 +2027,20 @@ parse_args(bool is_batchfile, int argc, char **argv) * If we have a batchfile, read the query list from it. */ if ((batchname != NULL) && !is_batchfile) { - if (strcmp(batchname, "-") == 0) + if (strcmp(batchname, "-") == 0) { batchfp = stdin; - else + } else { batchfp = fopen(batchname, "r"); + } if (batchfp == NULL) { perror(batchname); fatal("couldn't open batch file '%s'", batchname); } while (fgets(batchline, sizeof(batchline), batchfp) != 0) { if (batchline[0] == '\r' || batchline[0] == '\n' || - batchline[0] == '#' || batchline[0] == ';') + batchline[0] == '#' || batchline[0] == ';') { continue; + } for (bargc = 1, bargv[bargc] = strtok_r( batchline, " \t\r\n", &last); (bargc < 14) && bargv[bargc]; bargc++, @@ -1963,12 +2051,14 @@ parse_args(bool is_batchfile, int argc, char **argv) bargv[0] = argv[0]; parse_args(true, bargc, (char **)bargv); } - if (batchfp != stdin) + if (batchfp != stdin) { fclose(batchfp); + } } if (query != &default_query) { - if (query->ecs_addr != NULL) + if (query->ecs_addr != NULL) { isc_mem_free(mctx, query->ecs_addr); + } isc_mem_free(mctx, query); } } @@ -1997,12 +2087,15 @@ main(int argc, char *argv[]) dns_result_register(); - if (isc_net_probeipv4() == ISC_R_SUCCESS) + if (isc_net_probeipv4() == ISC_R_SUCCESS) { have_ipv4 = true; - if (isc_net_probeipv6() == ISC_R_SUCCESS) + } + if (isc_net_probeipv6() == ISC_R_SUCCESS) { have_ipv6 = true; - if (!have_ipv4 && !have_ipv6) + } + if (!have_ipv4 && !have_ipv6) { fatal("could not find either IPv4 or IPv6"); + } preparse_args(argc, argv); @@ -2018,8 +2111,9 @@ main(int argc, char *argv[]) ISC_LIST_INIT(queries); parse_args(false, argc, argv); - if (server == NULL) + if (server == NULL) { fatal("a server '@xxx' is required"); + } ns = 0; result = bind9_getaddresses(server, port, &dstaddr, 1, &ns); @@ -2035,8 +2129,9 @@ main(int argc, char *argv[]) isc_net_disableipv4(); have_ipv4 = false; } - if (have_ipv4 && have_ipv6) + if (have_ipv4 && have_ipv6) { fatal("can't choose between IPv4 and IPv6"); + } taskmgr = NULL; RUNCHECK(isc_taskmgr_create(mctx, 1, 0, NULL, &taskmgr)); @@ -2100,8 +2195,9 @@ main(int argc, char *argv[]) query = next; } - if (default_query.ecs_addr != NULL) + if (default_query.ecs_addr != NULL) { isc_mem_free(mctx, default_query.ecs_addr); + } dns_view_detach(&view); diff --git a/bin/tools/named-journalprint.c b/bin/tools/named-journalprint.c index 11c2e4bbd2..4f457b0c5b 100644 --- a/bin/tools/named-journalprint.c +++ b/bin/tools/named-journalprint.c @@ -71,8 +71,9 @@ main(int argc, char **argv) RUNTIME_CHECK(setup_logging(mctx, stderr, &lctx) == ISC_R_SUCCESS); result = dns_journal_print(mctx, file, stdout); - if (result == DNS_R_NOJOURNAL) + if (result == DNS_R_NOJOURNAL) { fprintf(stderr, "%s\n", dns_result_totext(result)); + } isc_log_destroy(&lctx); isc_mem_detach(&mctx); return (result != ISC_R_SUCCESS ? 1 : 0); diff --git a/bin/tools/named-nzd2nzf.c b/bin/tools/named-nzd2nzf.c index 92fc1c8f88..342a099695 100644 --- a/bin/tools/named-nzd2nzf.c +++ b/bin/tools/named-nzd2nzf.c @@ -11,7 +11,7 @@ #ifndef HAVE_LMDB #error This program requires the LMDB library. -#endif +#endif /* ifndef HAVE_LMDB */ #include #include diff --git a/bin/tools/named-rrchecker.c b/bin/tools/named-rrchecker.c index 19f567ece7..15d0f90f01 100644 --- a/bin/tools/named-rrchecker.c +++ b/bin/tools/named-rrchecker.c @@ -105,32 +105,38 @@ main(int argc, char *argv[]) case 'C': for (t = 1; t <= 0xfeffu; t++) { - if (dns_rdataclass_ismeta(t)) + if (dns_rdataclass_ismeta(t)) { continue; + } dns_rdataclass_format(t, text, sizeof(text)); - if (strncmp(text, "CLASS", 4) != 0) + if (strncmp(text, "CLASS", 4) != 0) { fprintf(stdout, "%s\n", text); + } } exit(0); case 'P': for (t = 0xff00; t <= 0xfffeu; t++) { - if (dns_rdatatype_ismeta(t)) + if (dns_rdatatype_ismeta(t)) { continue; + } dns_rdatatype_format(t, text, sizeof(text)); - if (strncmp(text, "TYPE", 4) != 0) + if (strncmp(text, "TYPE", 4) != 0) { fprintf(stdout, "%s\n", text); + } } doexit = true; break; case 'T': for (t = 1; t <= 0xfeffu; t++) { - if (dns_rdatatype_ismeta(t)) + if (dns_rdatatype_ismeta(t)) { continue; + } dns_rdatatype_format(t, text, sizeof(text)); - if (strncmp(text, "TYPE", 4) != 0) + if (strncmp(text, "TYPE", 4) != 0) { fprintf(stdout, "%s\n", text); + } } doexit = true; break; @@ -146,8 +152,9 @@ main(int argc, char *argv[]) exit(1); } } - if (doexit) + if (doexit) { exit(0); + } isc_mem_create(&mctx); RUNTIME_CHECK(isc_lex_create(mctx, 256, &lex) == ISC_R_SUCCESS); @@ -176,10 +183,12 @@ main(int argc, char *argv[]) while ((result = isc_lex_gettoken(lex, options | ISC_LEXOPT_NUMBER, &token)) == ISC_R_SUCCESS) { - if (token.type == isc_tokentype_eof) + if (token.type == isc_tokentype_eof) { break; - if (token.type == isc_tokentype_eol) + } + if (token.type == isc_tokentype_eol) { continue; + } if (once) { fatal("extra data"); } @@ -214,12 +223,15 @@ main(int argc, char *argv[]) result = isc_lex_gettoken(lex, options | ISC_LEXOPT_NUMBER, &token); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; - if (token.type == isc_tokentype_eol) + } + if (token.type == isc_tokentype_eol) { continue; - if (token.type == isc_tokentype_eof) + } + if (token.type == isc_tokentype_eof) { break; + } /* * Get type. diff --git a/bin/tools/nsec3hash.c b/bin/tools/nsec3hash.c index 59aa9e31a0..11ddec508d 100644 --- a/bin/tools/nsec3hash.c +++ b/bin/tools/nsec3hash.c @@ -51,8 +51,9 @@ fatal(const char *format, ...) static 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)); + } } static void @@ -96,20 +97,25 @@ nsec3hash(nsec3printer *nsec3print, const char *algostr, const char *flagstr, result = isc_hex_decodestring(saltstr, &buffer); check_result(result, "isc_hex_decodestring(salt)"); salt_length = isc_buffer_usedlength(&buffer); - if (salt_length > DNS_NSEC3_SALTSIZE) + if (salt_length > DNS_NSEC3_SALTSIZE) { fatal("salt too long"); - if (salt_length == 0) + } + if (salt_length == 0) { saltstr = dash; + } } hash_alg = atoi(algostr); - if (hash_alg > 255U) + if (hash_alg > 255U) { fatal("hash algorithm too large"); + } flags = flagstr == NULL ? 0 : atoi(flagstr); - if (flags > 255U) + if (flags > 255U) { fatal("flags too large"); + } iterations = atoi(iterstr); - if (iterations > 0xffffU) + if (iterations > 0xffffU) { fatal("iterations to large"); + } name = dns_fixedname_initname(&fixed); isc_buffer_constinit(&buffer, domain, strlen(domain)); @@ -120,8 +126,9 @@ nsec3hash(nsec3printer *nsec3print, const char *algostr, const char *flagstr, dns_name_downcase(name, name, NULL); length = isc_iterated_hash(hash, hash_alg, iterations, salt, salt_length, name->ndata, name->length); - if (length == 0) + if (length == 0) { fatal("isc_iterated_hash failed"); + } region.base = hash; region.length = length; isc_buffer_init(&buffer, text, sizeof(text)); diff --git a/bin/win32/BINDInstall/BINDInstall.h b/bin/win32/BINDInstall/BINDInstall.h index cc5a1acaf5..3230f52525 100644 --- a/bin/win32/BINDInstall/BINDInstall.h +++ b/bin/win32/BINDInstall/BINDInstall.h @@ -31,27 +31,27 @@ #ifndef __AFXWIN_H__ #error include 'stdafx.h' before including this file for PCH -#endif +#endif /* ifndef __AFXWIN_H__ */ -#include "resource.h" // main symbols +#include "resource.h" /* main symbols */ class CBINDInstallApp : public CWinApp { public: CBINDInstallApp(); - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CBINDInstallApp) + /* ClassWizard generated virtual function overrides */ + /*{{AFX_VIRTUAL(CBINDInstallApp) */ public: virtual BOOL InitInstance(); - //}}AFX_VIRTUAL + /*}}AFX_VIRTUAL */ - //{{AFX_MSG(CBINDInstallApp) - // NOTE - the ClassWizard will add and remove member functions here. - // DO NOT EDIT what you see in these blocks of generated code ! - //}}AFX_MSG + /*{{AFX_MSG(CBINDInstallApp) */ + /* NOTE - the ClassWizard will add and remove member functions here. */ + /* DO NOT EDIT what you see in these blocks of generated code ! */ + /*}}AFX_MSG */ DECLARE_MESSAGE_MAP() }; -#endif +#endif /* ifndef BINDINSTALL_H */ diff --git a/bin/win32/BINDInstall/BINDInstallDlg.h b/bin/win32/BINDInstall/BINDInstallDlg.h index 20b352c376..788db45d75 100644 --- a/bin/win32/BINDInstall/BINDInstallDlg.h +++ b/bin/win32/BINDInstall/BINDInstallDlg.h @@ -32,9 +32,9 @@ class CBINDInstallDlg : public CDialog { public: - CBINDInstallDlg(CWnd *pParent = NULL); // standard constructor + CBINDInstallDlg(CWnd *pParent = NULL); /* standard constructor */ - //{{AFX_DATA(CBINDInstallDlg) + /*{{AFX_DATA(CBINDInstallDlg) */ enum { IDD = IDD_BINDINSTALL_DIALOG }; CString m_targetDir; CString m_version; @@ -43,14 +43,14 @@ class CBINDInstallDlg : public CDialog BOOL m_toolsOnly; CString m_current; BOOL m_startOnInstall; - //}}AFX_DATA + /*}}AFX_DATA */ - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CBINDInstallDlg) + /* ClassWizard generated virtual function overrides */ + /*{{AFX_VIRTUAL(CBINDInstallDlg) */ protected: virtual void - DoDataExchange(CDataExchange *pDX); // DDX/DDV support - //}}AFX_VIRTUAL + DoDataExchange(CDataExchange *pDX); /* DDX/DDV support */ + /*}}AFX_VIRTUAL */ protected: void @@ -135,8 +135,8 @@ class CBINDInstallDlg : public CDialog CString m_accountPassword; BOOL m_serviceExists; - // Generated message map functions - //{{AFX_MSG(CBINDInstallDlg) + /* Generated message map functions */ + /*{{AFX_MSG(CBINDInstallDlg) */ virtual BOOL OnInitDialog(); afx_msg void @@ -159,8 +159,8 @@ class CBINDInstallDlg : public CDialog OnKeepFiles(); afx_msg void OnStartOnInstall(); - //}}AFX_MSG + /*}}AFX_MSG */ DECLARE_MESSAGE_MAP() }; -#endif +#endif /* ifndef BINDINSTALLDLG_H */ diff --git a/bin/win32/BINDInstall/DirBrowse.h b/bin/win32/BINDInstall/DirBrowse.h index 13319d15df..f3b6c61716 100644 --- a/bin/win32/BINDInstall/DirBrowse.h +++ b/bin/win32/BINDInstall/DirBrowse.h @@ -31,42 +31,43 @@ class CDirBrowse : public CDialog { - // Construction + /* Construction */ public: - CDirBrowse(CString initialDir = "\\", - CWnd * pParent = NULL); // standard constructor + CDirBrowse(CString initialDir = "\\", CWnd *pParent = NULL); /* standard + * constructor + */ CString GetSelectedDir() { return (m_selectedDir); } - //{{AFX_DATA(CDirBrowse) + /*{{AFX_DATA(CDirBrowse) */ enum { IDD = IDD_BROWSE }; - // NOTE: the ClassWizard will add data members here - //}}AFX_DATA + /* NOTE: the ClassWizard will add data members here */ + /*}}AFX_DATA */ - // ClassWizard generated virtual function overrides - //{{AFX_VIRTUAL(CDirBrowse) + /* ClassWizard generated virtual function overrides */ + /*{{AFX_VIRTUAL(CDirBrowse) */ protected: virtual void - DoDataExchange(CDataExchange *pDX); // DDX/DDV support - //}}AFX_VIRTUAL + DoDataExchange(CDataExchange *pDX); /* DDX/DDV support */ + /*}}AFX_VIRTUAL */ protected: - // Generated message map functions - //{{AFX_MSG(CDirBrowse) + /* Generated message map functions */ + /*{{AFX_MSG(CDirBrowse) */ virtual BOOL OnInitDialog(); afx_msg void OnDblclkDirlist(); afx_msg void OnSelchangeDirlist(); - //}}AFX_MSG + /*}}AFX_MSG */ DECLARE_MESSAGE_MAP() private: CString m_selectedDir; }; -#endif +#endif /* ifndef DIRBROWSE_H */ diff --git a/bin/win32/BINDInstall/StdAfx.h b/bin/win32/BINDInstall/StdAfx.h index c2f36aee6c..d29163f429 100644 --- a/bin/win32/BINDInstall/StdAfx.h +++ b/bin/win32/BINDInstall/StdAfx.h @@ -1,7 +1,7 @@ -// stdafx.h : include file for standard system include files, -// or project specific include files that are used frequently, but -// are changed infrequently -// +/* stdafx.h : include file for standard system include files, */ +/* or project specific include files that are used frequently, but */ +/* are changed infrequently */ +/* */ /* * Minimum version is Windows 8 and Windows Server 2012 @@ -11,26 +11,28 @@ #ifndef _CRT_SECURE_NO_DEPRECATE #define _CRT_SECURE_NO_DEPRECATE 1 -#endif +#endif /* ifndef _CRT_SECURE_NO_DEPRECATE */ #if !defined(AFX_STDAFX_H__61537819_39FC_11D3_A97A_00105A12BD65__INCLUDED_) #define AFX_STDAFX_H__61537819_39FC_11D3_A97A_00105A12BD65__INCLUDED_ #if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 +#endif /* _MSC_VER > 1000 */ -#define VC_EXTRALEAN // Exclude rarely-used stuff from Windows headers +#define VC_EXTRALEAN /* Exclude rarely-used stuff from Windows headers */ -#include // MFC support for Internet Explorer 4 Common Controls -#include // MFC extensions -#include // MFC core and standard components +#include /* MFC support for Internet Explorer 4 Common Controls */ +#include /* MFC extensions */ +#include /* MFC core and standard components */ #ifndef _AFX_NO_AFXCMN_SUPPORT -#include // MFC support for Windows Common Controls -#endif // _AFX_NO_AFXCMN_SUPPORT +#include /* MFC support for Windows Common Controls */ +#endif /* _AFX_NO_AFXCMN_SUPPORT */ -//{{AFX_INSERT_LOCATION}} -// Microsoft Visual C++ will insert additional declarations immediately before -// the previous line. +/*{{AFX_INSERT_LOCATION}} */ +/* Microsoft Visual C++ will insert additional declarations immediately before + */ +/* the previous line. */ -#endif // !defined(AFX_STDAFX_H__61537819_39FC_11D3_A97A_00105A12BD65__INCLUDED_) +#endif /* !defined(AFX_STDAFX_H__61537819_39FC_11D3_A97A_00105A12BD65__INCLUDED_) \ + */ diff --git a/bin/win32/BINDInstall/VersionInfo.h b/bin/win32/BINDInstall/VersionInfo.h index c505205706..712e69b0e6 100644 --- a/bin/win32/BINDInstall/VersionInfo.h +++ b/bin/win32/BINDInstall/VersionInfo.h @@ -1,13 +1,13 @@ -// VersionInfo.h: interface for the CVersionInfo class. -// -////////////////////////////////////////////////////////////////////// +/* VersionInfo.h: interface for the CVersionInfo class. */ +/* */ +/*//////////////////////////////////////////////////////////////////// */ #if !defined(AFX_VERSIONINFO_H__F82E9FF3_5298_11D4_AB87_00C04F789BA0__INCLUDED_) #define AFX_VERSIONINFO_H__F82E9FF3_5298_11D4_AB87_00C04F789BA0__INCLUDED_ #if _MSC_VER > 1000 #pragma once -#endif // _MSC_VER > 1000 +#endif /* _MSC_VER > 1000 */ class CVersionInfo { @@ -17,13 +17,10 @@ class CVersionInfo BOOL IsValid() { - return m_isValid; + return (m_isValid); } DWORD - GetStatus() - { - return m_status; - } + GetStatus() { return (m_status); } BOOL CopyFileCheckVersion(CVersionInfo &originalFile); @@ -33,10 +30,10 @@ class CVersionInfo const CString & GetFilename() { - return m_filename; + return (m_filename); } - // Extract the elements of the file's string info block + /* Extract the elements of the file's string info block */ CString GetFileVersionString(); CString @@ -62,7 +59,7 @@ class CVersionInfo CString GetCompanyName(); - // Extract the elements of the file's VS_FIXEDFILEINFO block + /* Extract the elements of the file's VS_FIXEDFILEINFO block */ _int64 GetFileVersion(); _int64 @@ -93,4 +90,5 @@ class CVersionInfo QueryStringValue(CString value); }; -#endif // !defined(AFX_VERSIONINFO_H__F82E9FF3_5298_11D4_AB87_00C04F789BA0__INCLUDED_) +#endif /* !defined(AFX_VERSIONINFO_H__F82E9FF3_5298_11D4_AB87_00C04F789BA0__INCLUDED_) \ + */ diff --git a/bin/win32/BINDInstall/resource.h b/bin/win32/BINDInstall/resource.h index 11cb75b3ea..9e5a7780d8 100644 --- a/bin/win32/BINDInstall/resource.h +++ b/bin/win32/BINDInstall/resource.h @@ -1,7 +1,7 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Developer Studio generated include file. -// Used by BINDInstall.rc -// +/*{{NO_DEPENDENCIES}} */ +/* Microsoft Developer Studio generated include file. */ +/* Used by BINDInstall.rc */ +/* */ #define IDS_MAINFRAME 1 #define IDS_CREATEDIR 2 #define IDS_SUCCESS 3 @@ -93,13 +93,13 @@ #define IDC_TOOLS_ONLY 1033 #define IDS_ERR_START_SERVICE 1034 -// Next default values for new objects -// +/* Next default values for new objects */ +/* */ #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 144 #define _APS_NEXT_COMMAND_VALUE 32771 #define _APS_NEXT_CONTROL_VALUE 1027 #define _APS_NEXT_SYMED_VALUE 104 -#endif -#endif +#endif /* ifndef APSTUDIO_READONLY_SYMBOLS */ +#endif /* ifdef APSTUDIO_INVOKED */ diff --git a/conftools/perllib/dnsconf/DNSConf-macros.h b/conftools/perllib/dnsconf/DNSConf-macros.h index c91f5683d3..2e6544d535 100644 --- a/conftools/perllib/dnsconf/DNSConf-macros.h +++ b/conftools/perllib/dnsconf/DNSConf-macros.h @@ -35,13 +35,13 @@ isc_result_t tmpres; \ \ if (cfg == NULL || cfg->confctx == NULL) \ - return NULL; \ + return (NULL); \ \ tmpres = CONCAT(dns_c_ctx_get, FIELD)(cfg->confctx, &result); \ if (tmpres == ISC_R_NOTFOUND) \ - return NULL; \ + return (NULL); \ \ - return result; \ + return (result); \ } #define STRING_FIELD_DEFS(FIELD) \ diff --git a/contrib/dlz/bin/dlzbdb/dlzbdb.c b/contrib/dlz/bin/dlzbdb/dlzbdb.c index 94633b421d..4c32ca2ad5 100644 --- a/contrib/dlz/bin/dlzbdb/dlzbdb.c +++ b/contrib/dlz/bin/dlzbdb/dlzbdb.c @@ -312,18 +312,18 @@ getzone(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) UNUSED(pkey); if ((token = strtok_r(pdata->data, " ", &last)) == NULL) { - return BDBparseErr; + return (BDBparseErr); } /* copy string for "zone" secondary index */ if ((skey->data = strdup(token)) == NULL) { - return BDBparseErr; + return (BDBparseErr); } /* set required values for BDB */ skey->size = strlen(skey->data); skey->flags = DB_DBT_APPMALLOC; - return 0; + return (0); } /*% @@ -340,23 +340,23 @@ gethost(DB *dbp, const DBT *pkey, const DBT *pdata, DBT *skey) /* we don't care about first token. */ if ((token = strtok_r(right, " ", &last)) == NULL) { - return BDBparseErr; + return (BDBparseErr); } /* get "host" from data string */ if ((token = strtok_r(NULL, " ", &last)) == NULL) { - return BDBparseErr; + return (BDBparseErr); } /* copy string for "host" secondary index */ if ((skey->data = strdup(token)) == NULL) { - return BDBparseErr; + return (BDBparseErr); } /* set required values for BDB */ skey->size = strlen(skey->data); skey->flags = DB_DBT_APPMALLOC; - return 0; + return (0); } /*% @@ -427,7 +427,7 @@ bdb_opendb(DBTYPE db_type, DB **db_out, const char *db_name, int flags) fprintf(stderr, "BDB could not initialize %s database. BDB error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* set database flags. */ @@ -436,7 +436,7 @@ bdb_opendb(DBTYPE db_type, DB **db_out, const char *db_name, int flags) "BDB could not set flags for %s database. BDB error: " "%s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } if (create_allowed == true) { @@ -448,10 +448,10 @@ bdb_opendb(DBTYPE db_type, DB **db_out, const char *db_name, int flags) fprintf(stderr, "BDB could not open %s database in %s. BDB error: %s", db_name, db_file, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /*% @@ -504,7 +504,7 @@ insert_data(void) ISC_LEXOPT_EOF | /* Want end-of-file token. */ ISC_LEXOPT_QSTRING | /* Recognize qstrings. */ ISC_LEXOPT_QSTRINGMULTILINE; /* Allow multiline "" - strings */ + * strings */ isc_result_t result; isc_token_t token; /* token from lexer */ @@ -515,7 +515,7 @@ insert_data(void) char data_arr2[max_data_len]; isc_buffer_t buf2; char data_type = 'u'; /* u =unknown, b =bad token, d/D =DNS, c/C =client - IP */ + * IP */ /* Initialize buffers */ isc_buffer_init(&buf, &data_arr, max_data_len); @@ -523,8 +523,9 @@ insert_data(void) while (loop) { result = isc_lex_gettoken(lexer, opt, &token); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto data_cleanup; + } switch (token.type) { case isc_tokentype_string: @@ -660,24 +661,28 @@ openBDB(void) /* open dlz_data database. */ result = bdb_opendb(DB_RECNO, &db.data, dlz_data, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto openBDB_cleanup; + } /* open dlz_host database */ result = bdb_opendb(DB_BTREE, &db.host, dlz_host, DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto openBDB_cleanup; + } /* open dlz_zone database. */ result = bdb_opendb(DB_BTREE, &db.zone, dlz_zone, DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto openBDB_cleanup; + } /* open dlz_client database. */ result = bdb_opendb(DB_BTREE, &db.client, dlz_client, DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto openBDB_cleanup; + } /* associate the host secondary database with the primary database */ bdbres = db.data->associate(db.data, NULL, db.host, gethost, 0); @@ -701,12 +706,12 @@ openBDB(void) goto openBDB_cleanup; } - return result; + return (result); openBDB_cleanup: bdb_cleanup(); - return result; + return (result); } /*% Create & open lexer to parse input data */ @@ -717,31 +722,33 @@ open_lexer(void) isc_result_t result; /* check if we already opened the lexer, if we did, return success */ - if (lexer != NULL) - return ISC_R_SUCCESS; + if (lexer != NULL) { + return (ISC_R_SUCCESS); + } /* allocate memory for lexer, and verify it was allocated */ isc_mem_create(&lex_mctx); /* create lexer */ result = isc_lex_create(lex_mctx, 1500, &lexer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fprintf(stderr, "unexpected error creating lexer\n"); + } /* set allowed commenting style */ isc_lex_setcomments(lexer, ISC_LEXCOMMENT_C | /* Allow C comments */ ISC_LEXCOMMENT_CPLUSPLUS | /* Allow - C++ - comments + * C++ + * comments */ ISC_LEXCOMMENT_SHELL); /* Allow - shellcomments + * shellcomments */ isc_buffer_init(&lex_buffer, &lex_data_buf, max_data_len); - return result; + return (result); } /*% Close the lexer, and cleanup memory */ @@ -756,8 +763,9 @@ close_lexer(void) } /* if lexer memory is still allocated, destroy it. */ - if (lex_mctx != NULL) + if (lex_mctx != NULL) { isc_mem_destroy(&lex_mctx); + } } /*% Perform add operation */ @@ -845,7 +853,7 @@ bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) if (bdbdata->data == NULL) { fprintf(stderr, "Unable to allocate 5 MB buffer for bulk " "database dump\n"); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } bdbdata->ulen = buffer_size; bdbdata->flags = DB_DBT_USERMEM; @@ -856,7 +864,7 @@ bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) fprintf(stderr, "Unexpected error. BDB Error: %s\n", db_strerror(bdbres)); free(bdbdata->data); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* loop and dump all data */ @@ -872,35 +880,37 @@ bulk_write(char type, DB *database, DBC *dbcursor, DBT *bdbkey, DBT *bdbdata) "Unexpected error. BDB Error: %s\n", db_strerror(bdbres)); free(bdbdata->data); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* Hit DB_NOTFOUND which means end of data. */ break; } /* end of if (bdbres !=0) */ for (DB_MULTIPLE_INIT(p, bdbdata);;) { - if (type == 'c') + if (type == 'c') { DB_MULTIPLE_KEY_NEXT(p, bdbdata, retkey, retklen, retdata, retdlen); - else + } else { DB_MULTIPLE_RECNO_NEXT(p, bdbdata, recNum, retdata, retdlen); + } - if (p == NULL) + if (p == NULL) { break; - if (type == 'c') + } + if (type == 'c') { printf("c %.*s %.*s\n", (int)retklen, retkey, (int)retdlen, retdata); - else + } else { printf("d %.*s\n", (int)retdlen, retdata); + } } /* end of for (DB_MULTIPLE_INIT....) */ - - } /* end of for (;;) */ + } /* end of for (;;) */ /* free the buffer we created earlier */ free(bdbdata->data); - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /*% @@ -948,8 +958,9 @@ operation_listOrDelete(bool dlt) /* Dump database in "dlzbdb" bulk format */ if (list_everything == true) { if (bulk_write('c', db.client, db.cursor, &bdbkey, &bdbdata) != - ISC_R_SUCCESS) + ISC_R_SUCCESS) { return; + } memset(&bdbkey, 0, sizeof(bdbkey)); memset(&bdbdata, 0, sizeof(bdbdata)); bulk_write('d', db.data, db.cursor2, &bdbkey, &bdbdata); @@ -1165,8 +1176,9 @@ main(int argc, char **argv) char *endp; /* there has to be at least 2 args, some operations require more */ - if (argc < 2) + if (argc < 2) { show_usage(); + } /* use the ISC commandline parser to get all the program arguments */ while ((ch = isc_commandline_parse(argc, argv, @@ -1293,4 +1305,4 @@ main(int argc, char **argv) quit(0); } -#endif +#endif /* ifdef DLZ_BDB */ diff --git a/contrib/dlz/drivers/dlz_bdb_driver.c b/contrib/dlz/drivers/dlz_bdb_driver.c index 03df9f8508..2911d9745c 100644 --- a/contrib/dlz/drivers/dlz_bdb_driver.c +++ b/contrib/dlz/drivers/dlz_bdb_driver.c @@ -82,7 +82,6 @@ typedef struct bdb_instance { DB * host; /*%< host database handle */ DB * client; /*%< client database handle */ isc_mem_t *mctx; /*%< memory context */ - } bdb_instance_t; typedef struct parsed_data { @@ -129,13 +128,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) /* find space after zone and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to host */ pd->host = tmp; @@ -143,13 +144,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) /* find space after type and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to dns type */ pd->type = tmp; @@ -157,13 +160,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) /* find space after type and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to dns ttl */ ttlStr = tmp; @@ -171,13 +176,15 @@ bdb_parse_data(char *in, parsed_data_t *pd) /* find space after ttl and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to remainder of DNS data */ pd->data = tmp; @@ -188,11 +195,11 @@ bdb_parse_data(char *in, parsed_data_t *pd) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "BDB driver ttl must be a postive number"); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* if we get this far everything should have worked. */ - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /* @@ -210,8 +217,9 @@ bdb_allowzonexfr(void *driverarg, void *dbdata, const char *name, /* check to see if we are authoritative for the zone first. */ result = bdb_findzone(driverarg, dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } memset(&key, 0, sizeof(DBT)); key.flags = DB_DBT_MALLOC; @@ -252,18 +260,21 @@ bdb_allowzonexfr(void *driverarg, void *dbdata, const char *name, xfr_cleanup: /* free any memory duplicate string in the key field */ - if (key.data != NULL) + if (key.data != NULL) { free(key.data); + } /* free any memory allocated to the data field. */ - if (data.data != NULL) + if (data.data != NULL) { free(data.data); + } /* get rid of zone_cursor */ - if (client_cursor != NULL) + if (client_cursor != NULL) { client_cursor->c_close(client_cursor); + } - return result; + return (result); } static isc_result_t @@ -286,8 +297,9 @@ bdb_allnodes(const char *zone, void *driverarg, void *dbdata, key.data = tmp_zone = strdup(zone); - if (key.data == NULL) + if (key.data == NULL) { return (ISC_R_NOMEMORY); + } key.size = strlen(key.data); @@ -304,36 +316,41 @@ bdb_allnodes(const char *zone, void *driverarg, void *dbdata, flags = DB_NEXT_DUP; tmp = realloc(tmp, data.size + 1); - if (tmp == NULL) + if (tmp == NULL) { goto allnodes_cleanup; + } strncpy(tmp, data.data, data.size); tmp[data.size] = '\0'; - if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS) + if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS) { goto allnodes_cleanup; + } result = dns_sdlz_putnamedrr(allnodes, pd.host, pd.type, pd.ttl, pd.data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto allnodes_cleanup; - + } } /* end while loop */ allnodes_cleanup: - if (tmp != NULL) + if (tmp != NULL) { free(tmp); + } /* free any memory duplicate string in the key field */ - if (tmp_zone != NULL) + if (tmp_zone != NULL) { free(tmp_zone); + } /* get rid of zone_cursor */ - if (zone_cursor != NULL) + if (zone_cursor != NULL) { zone_cursor->c_close(zone_cursor); + } - return result; + return (result); } /*% @@ -348,18 +365,23 @@ bdb_cleanup(bdb_instance_t *db) isc_mem_t *mctx; /* close databases */ - if (db->data != NULL) + if (db->data != NULL) { db->data->close(db->data, 0); - if (db->host != NULL) + } + if (db->host != NULL) { db->host->close(db->host, 0); - if (db->zone != NULL) + } + if (db->zone != NULL) { db->zone->close(db->zone, 0); - if (db->client != NULL) + } + if (db->client != NULL) { db->client->close(db->client, 0); + } /* close environment */ - if (db->dbenv != NULL) + if (db->dbenv != NULL) { db->dbenv->close(db->dbenv, 0); + } /* cleanup memory */ if (db->mctx != NULL) { @@ -389,8 +411,9 @@ bdb_findzone(void *driverarg, void *dbdata, const char *name, key.data = strdup(name); - if (key.data == NULL) + if (key.data == NULL) { return (ISC_R_NOMEMORY); + } key.size = strlen(key.data); @@ -415,18 +438,21 @@ bdb_findzone(void *driverarg, void *dbdata, const char *name, findzone_cleanup: /* free any memory duplicate string in the key field */ - if (key.data != NULL) + if (key.data != NULL) { free(key.data); + } /* free any memory allocated to the data field. */ - if (data.data != NULL) + if (data.data != NULL) { free(data.data); + } /* get rid of zone_cursor */ - if (zone_cursor != NULL) + if (zone_cursor != NULL) { zone_cursor->c_close(zone_cursor); + } - return result; + return (result); } static isc_result_t @@ -502,43 +528,52 @@ bdb_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, while ((bdbres = join_cursor->c_get(join_cursor, &key, &data, 0)) == 0) { tmp = realloc(tmp, data.size + 1); - if (tmp == NULL) + if (tmp == NULL) { goto lookup_cleanup; + } strncpy(tmp, data.data, data.size); tmp[data.size] = '\0'; - if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS) + if (bdb_parse_data(tmp, &pd) != ISC_R_SUCCESS) { goto lookup_cleanup; + } result = dns_sdlz_putrr(lookup, pd.type, pd.ttl, pd.data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto lookup_cleanup; + } } /* end while loop */ lookup_cleanup: - if (tmp != NULL) + if (tmp != NULL) { free(tmp); - if (tmp_zone != NULL) + } + if (tmp_zone != NULL) { free(tmp_zone); - if (tmp_host != NULL) + } + if (tmp_host != NULL) { free(tmp_host); + } /* get rid of the joined cusor */ - if (join_cursor != NULL) + if (join_cursor != NULL) { join_cursor->c_close(join_cursor); + } /* get rid of zone_cursor */ - if (zone_cursor != NULL) + if (zone_cursor != NULL) { zone_cursor->c_close(zone_cursor); + } /* get rid of host_cursor */ - if (host_cursor != NULL) + if (host_cursor != NULL) { host_cursor->c_close(host_cursor); + } - return result; + return (result); } /*% Initializes, sets flags and then opens Berkeley databases. */ @@ -556,7 +591,7 @@ bdb_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name, "BDB could not initialize %s database. " "BDB error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* set database flags. */ @@ -566,7 +601,7 @@ bdb_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name, "BDB could not set flags for %s database. " "BDB error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* open the database. */ @@ -577,10 +612,10 @@ bdb_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name, "BDB could not open %s database in %s. " "BDB error: %s", db_name, db_file, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } static isc_result_t @@ -641,26 +676,30 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[], /* open dlz_data database. */ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->data, dlz_data, argv[2], 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_host database. */ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->host, dlz_host, argv[2], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_zone database. */ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->zone, dlz_zone, argv[2], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_client database. */ result = bdb_opendb(db->dbenv, DB_UNKNOWN, &db->client, dlz_client, argv[2], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* associate the host secondary database with the primary database */ bdbres = db->data->associate(db->data, NULL, db->host, NULL, 0); @@ -693,7 +732,7 @@ bdb_create(const char *dlzname, unsigned int argc, char *argv[], init_cleanup: bdb_cleanup(db); - return result; + return (result); } static void @@ -748,7 +787,7 @@ dlz_bdb_init(void) result = ISC_R_UNEXPECTED; } - return result; + return (result); } /*% @@ -763,8 +802,9 @@ dlz_bdb_clear(void) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2), "Unregistering DLZ bdb driver."); - if (dlz_bdb != NULL) + if (dlz_bdb != NULL) { dns_sdlzunregister(&dlz_bdb); + } } -#endif +#endif /* ifdef DLZ_BDB */ diff --git a/contrib/dlz/drivers/dlz_bdbhpt_driver.c b/contrib/dlz/drivers/dlz_bdbhpt_driver.c index 47b1772d5d..5d9b09b584 100644 --- a/contrib/dlz/drivers/dlz_bdbhpt_driver.c +++ b/contrib/dlz/drivers/dlz_bdbhpt_driver.c @@ -81,7 +81,6 @@ typedef struct bdbhpt_instance { DB * xfr; /*%< zone xfr database handle */ DB * client; /*%< client database handle */ isc_mem_t *mctx; /*%< memory context */ - } bdbhpt_instance_t; typedef struct bdbhpt_parsed_data { @@ -106,14 +105,15 @@ bdbhpt_strrev(char *str) { char *p1, *p2; - if (!str || !*str) - return str; + if (!str || !*str) { + return (str); + } for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { *p1 ^= *p2; *p2 ^= *p1; *p1 ^= *p2; } - return str; + return (str); } /*% @@ -158,11 +158,13 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) /* find space after replication id */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to host */ pd->host = tmp; @@ -170,13 +172,15 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) /* find space after host and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to ttl string */ ttlStr = tmp; @@ -184,13 +188,15 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) /* find space after ttl and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to dns type */ pd->type = tmp; @@ -198,13 +204,15 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) /* find space after type and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to remainder of DNS data */ pd->data = tmp; @@ -215,11 +223,11 @@ bdbhpt_parse_data(char *in, bdbhpt_parsed_data_t *pd) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "bdbhpt driver ttl must be a postive number"); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* if we get this far everything should have worked. */ - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /* @@ -236,8 +244,9 @@ bdbhpt_allowzonexfr(void *driverarg, void *dbdata, const char *name, /* check to see if we are authoritative for the zone first. */ result = bdbhpt_findzone(driverarg, dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } memset(&key, 0, sizeof(DBT)); key.flags = DB_DBT_MALLOC; @@ -271,14 +280,16 @@ bdbhpt_allowzonexfr(void *driverarg, void *dbdata, const char *name, xfr_cleanup: /* free any memory duplicate string in the key field */ - if (key.data != NULL) + if (key.data != NULL) { free(key.data); + } /* free any memory allocated to the data field. */ - if (data.data != NULL) + if (data.data != NULL) { free(data.data); + } - return result; + return (result); } /*% @@ -330,8 +341,9 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata, memset(&dns_data, 0, sizeof(DBT)); xfr_key.data = tmp_zone = strdup(zone); - if (xfr_key.data == NULL) + if (xfr_key.data == NULL) { return (ISC_R_NOMEMORY); + } xfr_key.size = strlen(xfr_key.data); @@ -359,8 +371,9 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata, /* +1 to allow for null term at end of string. */ dns_key.data = tmp_zone_host = malloc(dns_key.size + 1); - if (dns_key.data == NULL) + if (dns_key.data == NULL) { goto allnodes_cleanup; + } /* * construct search key for dns_data. @@ -379,22 +392,24 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata, /* +1 to allow for null term at end of string. */ tmp = realloc(tmp, dns_data.size + 1); - if (tmp == NULL) + if (tmp == NULL) { goto allnodes_cleanup; + } /* copy data to tmp string, and append null term. */ strncpy(tmp, dns_data.data, dns_data.size); tmp[dns_data.size] = '\0'; /* split string into dns data parts. */ - if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS) + if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS) { goto allnodes_cleanup; + } result = dns_sdlz_putnamedrr(allnodes, pd.host, pd.type, pd.ttl, pd.data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto allnodes_cleanup; - + } } /* end inner while loop */ /* clean up memory */ @@ -407,23 +422,28 @@ bdbhpt_allnodes(const char *zone, void *driverarg, void *dbdata, allnodes_cleanup: /* free any memory */ - if (tmp != NULL) + if (tmp != NULL) { free(tmp); + } - if (tmp_zone_host != NULL) + if (tmp_zone_host != NULL) { free(tmp_zone_host); + } - if (tmp_zone != NULL) + if (tmp_zone != NULL) { free(tmp_zone); + } /* get rid of cursors */ - if (xfr_cursor != NULL) + if (xfr_cursor != NULL) { xfr_cursor->c_close(xfr_cursor); + } - if (dns_cursor != NULL) + if (dns_cursor != NULL) { dns_cursor->c_close(dns_cursor); + } - return result; + return (result); } /*% @@ -438,18 +458,23 @@ bdbhpt_cleanup(bdbhpt_instance_t *db) isc_mem_t *mctx; /* close databases */ - if (db->data != NULL) + if (db->data != NULL) { db->data->close(db->data, 0); - if (db->xfr != NULL) + } + if (db->xfr != NULL) { db->xfr->close(db->xfr, 0); - if (db->zone != NULL) + } + if (db->zone != NULL) { db->zone->close(db->zone, 0); - if (db->client != NULL) + } + if (db->client != NULL) { db->client->close(db->client, 0); + } /* close environment */ - if (db->dbenv != NULL) + if (db->dbenv != NULL) { db->dbenv->close(db->dbenv, 0); + } /* cleanup memory */ if (db->mctx != NULL) { @@ -478,8 +503,9 @@ bdbhpt_findzone(void *driverarg, void *dbdata, const char *name, key.data = strdup(name); - if (key.data == NULL) + if (key.data == NULL) { return (ISC_R_NOMEMORY); + } /* * reverse string to take advantage of BDB locality of reference @@ -501,14 +527,16 @@ bdbhpt_findzone(void *driverarg, void *dbdata, const char *name, } /* free any memory duplicate string in the key field */ - if (key.data != NULL) + if (key.data != NULL) { free(key.data); + } /* free any memory allocated to the data field. */ - if (data.data != NULL) + if (data.data != NULL) { free(data.data); + } - return result; + return (result); } static isc_result_t @@ -539,8 +567,9 @@ bdbhpt_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, /* allocate mem for key */ key.data = keyStr = malloc((key.size + 1) * sizeof(char)); - if (keyStr == NULL) - return ISC_R_NOMEMORY; + if (keyStr == NULL) { + return (ISC_R_NOMEMORY); + } strcpy(keyStr, zone); strcat(keyStr, " "); @@ -559,32 +588,37 @@ bdbhpt_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, flags)) == 0) { flags = DB_NEXT_DUP; tmp = realloc(tmp, data.size + 1); - if (tmp == NULL) + if (tmp == NULL) { goto lookup_cleanup; + } strncpy(tmp, data.data, data.size); tmp[data.size] = '\0'; - if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS) + if (bdbhpt_parse_data(tmp, &pd) != ISC_R_SUCCESS) { goto lookup_cleanup; + } result = dns_sdlz_putrr(lookup, pd.type, pd.ttl, pd.data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto lookup_cleanup; + } } /* end while loop */ lookup_cleanup: /* get rid of cursor */ - if (data_cursor != NULL) + if (data_cursor != NULL) { data_cursor->c_close(data_cursor); + } free(keyStr); - if (tmp != NULL) + if (tmp != NULL) { free(tmp); + } - return result; + return (result); } /*% Initializes, sets flags and then opens Berkeley databases. */ @@ -602,7 +636,7 @@ bdbhpt_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name, "bdbhpt could not initialize %s database. " "bdbhpt error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* set database flags. */ @@ -612,7 +646,7 @@ bdbhpt_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name, "bdbhpt could not set flags for %s database. " "bdbhpt error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* open the database. */ @@ -623,10 +657,10 @@ bdbhpt_opendb(DB_ENV *db_env, DBTYPE db_type, DB **db, const char *db_name, "bdbhpt could not open %s database in %s. " "bdbhpt error: %s", db_name, db_file, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } static isc_result_t @@ -651,9 +685,9 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[], } switch ((char)*argv[1]) { - /* - * Transactional mode. Highest safety - lowest speed. - */ + /* + * Transactional mode. Highest safety - lowest speed. + */ case 'T': case 't': bdbFlags = DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG | @@ -662,10 +696,10 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[], DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1), "bdbhpt driver using transactional mode."); break; - /* - * Concurrent mode. Lower safety (no rollback) - - * higher speed. - */ + /* + * Concurrent mode. Lower safety (no rollback) - + * higher speed. + */ case 'C': case 'c': bdbFlags = DB_INIT_CDB | DB_INIT_MPOOL; @@ -673,10 +707,10 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[], DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(1), "bdbhpt driver using concurrent mode."); break; - /* - * Private mode. No inter-process communication & no locking. - * Lowest saftey - highest speed. - */ + /* + * Private mode. No inter-process communication & no locking. + * Lowest saftey - highest speed. + */ case 'P': case 'p': bdbFlags = DB_PRIVATE | DB_INIT_MPOOL; @@ -731,26 +765,30 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[], /* open dlz_data database. */ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->data, dlz_data, argv[3], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_xfr database. */ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->xfr, dlz_xfr, argv[3], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_zone database. */ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->zone, dlz_zone, argv[3], 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_client database. */ result = bdbhpt_opendb(db->dbenv, DB_UNKNOWN, &db->client, dlz_client, argv[3], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } *dbdata = db; @@ -759,7 +797,7 @@ bdbhpt_create(const char *dlzname, unsigned int argc, char *argv[], init_cleanup: bdbhpt_cleanup(db); - return result; + return (result); } static void @@ -816,7 +854,7 @@ dlz_bdbhpt_init(void) result = ISC_R_UNEXPECTED; } - return result; + return (result); } /*% @@ -831,8 +869,9 @@ dlz_bdbhpt_clear(void) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2), "Unregistering DLZ bdbhpt driver."); - if (dlz_bdbhpt != NULL) + if (dlz_bdbhpt != NULL) { dns_sdlzunregister(&dlz_bdbhpt); + } } -#endif +#endif /* ifdef DLZ_BDB */ diff --git a/contrib/dlz/drivers/dlz_drivers.c b/contrib/dlz/drivers/dlz_drivers.c index 778de82010..4da516223d 100644 --- a/contrib/dlz/drivers/dlz_drivers.c +++ b/contrib/dlz/drivers/dlz_drivers.c @@ -30,32 +30,32 @@ #ifdef DLZ_STUB #include -#endif +#endif /* ifdef DLZ_STUB */ #ifdef DLZ_POSTGRES #include -#endif +#endif /* ifdef DLZ_POSTGRES */ #ifdef DLZ_MYSQL #include -#endif +#endif /* ifdef DLZ_MYSQL */ #ifdef DLZ_FILESYSTEM #include -#endif +#endif /* ifdef DLZ_FILESYSTEM */ #ifdef DLZ_BDB #include #include -#endif +#endif /* ifdef DLZ_BDB */ #ifdef DLZ_LDAP #include -#endif +#endif /* ifdef DLZ_LDAP */ #ifdef DLZ_ODBC #include -#endif +#endif /* ifdef DLZ_ODBC */ /*% * Call init functions for all relevant DLZ drivers. @@ -68,48 +68,56 @@ dlz_drivers_init(void) #ifdef DLZ_STUB result = dlz_stub_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_STUB */ #ifdef DLZ_POSTGRES result = dlz_postgres_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_POSTGRES */ #ifdef DLZ_MYSQL result = dlz_mysql_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_MYSQL */ #ifdef DLZ_FILESYSTEM result = dlz_fs_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_FILESYSTEM */ #ifdef DLZ_BDB result = dlz_bdb_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dlz_bdbhpt_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_BDB */ #ifdef DLZ_LDAP result = dlz_ldap_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_LDAP */ #ifdef DLZ_ODBC result = dlz_odbc_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); -#endif + } +#endif /* ifdef DLZ_ODBC */ return (result); } @@ -123,30 +131,30 @@ dlz_drivers_clear(void) { #ifdef DLZ_STUB dlz_stub_clear(); -#endif +#endif /* ifdef DLZ_STUB */ #ifdef DLZ_POSTGRES dlz_postgres_clear(); -#endif +#endif /* ifdef DLZ_POSTGRES */ #ifdef DLZ_MYSQL dlz_mysql_clear(); -#endif +#endif /* ifdef DLZ_MYSQL */ #ifdef DLZ_FILESYSTEM dlz_fs_clear(); -#endif +#endif /* ifdef DLZ_FILESYSTEM */ #ifdef DLZ_BDB dlz_bdb_clear(); dlz_bdbhpt_clear(); -#endif +#endif /* ifdef DLZ_BDB */ #ifdef DLZ_LDAP dlz_ldap_clear(); -#endif +#endif /* ifdef DLZ_LDAP */ #ifdef DLZ_ODBC dlz_odbc_clear(); -#endif +#endif /* ifdef DLZ_ODBC */ } diff --git a/contrib/dlz/drivers/dlz_filesystem_driver.c b/contrib/dlz/drivers/dlz_filesystem_driver.c index 242a60fe73..31a9b4f7e7 100644 --- a/contrib/dlz/drivers/dlz_filesystem_driver.c +++ b/contrib/dlz/drivers/dlz_filesystem_driver.c @@ -107,44 +107,53 @@ is_safe(const char *input) /* '.' is allowed, but has special requirements */ if (input[i] == '.') { /* '.' is not allowed as first char */ - if (i == 0) + if (i == 0) { return (false); + } /* '..', two dots together is not allowed. */ - if (input[i - 1] == '.') + if (input[i - 1] == '.') { return (false); + } /* '.' is not allowed as last char */ - if (i == len - 1) + if (i == len - 1) { return (false); + } /* only 1 dot in ok location, continue at next char */ continue; } /* '-' is allowed, continue at next char */ - if (input[i] == '-') + if (input[i] == '-') { continue; + } /* 0-9 is allowed, continue at next char */ - if (input[i] >= '0' && input[i] <= '9') + if (input[i] >= '0' && input[i] <= '9') { continue; + } /* A-Z uppercase is allowed, continue at next char */ - if (input[i] >= 'A' && input[i] <= 'Z') + if (input[i] >= 'A' && input[i] <= 'Z') { continue; + } /* a-z lowercase is allowed, continue at next char */ - if (input[i] >= 'a' && input[i] <= 'z') + if (input[i] >= 'a' && input[i] <= 'z') { continue; + } /* * colon needs to be allowed for IPV6 client * addresses. Not dangerous in domain names, as not a * special char. */ - if (input[i] == ':') + if (input[i] == ':') { continue; + } /* * '@' needs to be allowed for in zone data. Not * dangerous in domain names, as not a special char. */ - if (input[i] == '@') + if (input[i] == '@') { continue; + } /* * if we reach this point we have encountered a @@ -172,17 +181,20 @@ create_path_helper(char *out, const char *in, config_data_t *cd) while ((tmpPtr = strrchr(tmpString, '.')) != NULL) { i = 0; while (tmpPtr[i + 1] != '\0') { - if (cd->splitcnt < 1) + if (cd->splitcnt < 1) { strcat(out, (char *)&tmpPtr[i + 1]); - else + } else { strncat(out, (char *)&tmpPtr[i + 1], cd->splitcnt); + } strncat(out, (char *)&cd->pathsep, 1); - if (cd->splitcnt == 0) + if (cd->splitcnt == 0) { break; + } if (strlen((char *)&tmpPtr[i + 1]) <= - (unsigned int)cd->splitcnt) + (unsigned int)cd->splitcnt) { break; + } i += cd->splitcnt; } tmpPtr[0] = '\0'; @@ -192,15 +204,18 @@ create_path_helper(char *out, const char *in, config_data_t *cd) i = 0; tmpPtr = tmpString; while (tmpPtr[i] != '\0') { - if (cd->splitcnt < 1) + if (cd->splitcnt < 1) { strcat(out, (char *)&tmpPtr[i]); - else + } else { strncat(out, (char *)&tmpPtr[i], cd->splitcnt); + } strncat(out, (char *)&cd->pathsep, 1); - if (cd->splitcnt == 0) + if (cd->splitcnt == 0) { break; - if (strlen((char *)&tmpPtr[i]) <= (unsigned int)cd->splitcnt) + } + if (strlen((char *)&tmpPtr[i]) <= (unsigned int)cd->splitcnt) { break; + } i += cd->splitcnt; } @@ -236,28 +251,33 @@ create_path(const char *zone, const char *host, const char *client, (host == NULL && client != NULL)); /* special case for root zone */ - if (strcmp(zone, ".") == 0) + if (strcmp(zone, ".") == 0) { isroot = true; + } /* if the requested zone is "unsafe", return error */ - if (!isroot && !is_safe(zone)) + if (!isroot && !is_safe(zone)) { return (ISC_R_FAILURE); + } /* if host was passed, verify that it is safe */ - if (host != NULL && !is_safe(host)) + if (host != NULL && !is_safe(host)) { return (ISC_R_FAILURE); + } /* if client was passed, verify that it is safe */ - if (client != NULL && !is_safe(client)) + if (client != NULL && !is_safe(client)) { return (ISC_R_FAILURE); + } /* Determine how much memory the split up string will require */ - if (host != NULL) + if (host != NULL) { len = strlen(zone) + strlen(host); - else if (client != NULL) + } else if (client != NULL) { len = strlen(zone) + strlen(client); - else + } else { len = strlen(zone); + } /* * even though datadir and xfrdir will never be in the same @@ -267,8 +287,9 @@ create_path(const char *zone, const char *host, const char *client, pathsize = len + cd->basedirsize + cd->datadirsize + cd->xfrdirsize + 4; /* if we are splitting names, we will need extra space. */ - if (cd->splitcnt > 0) + if (cd->splitcnt > 0) { pathsize += len / cd->splitcnt; + } tmpPath = isc_mem_allocate(named_g_mctx, pathsize * sizeof(char)); @@ -374,15 +395,17 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, cd->pathsep)) != NULL) { if ((strlen(host) + strlen(tmpPtr + 1) + 2) > - NAME_MAX) + NAME_MAX) { continue; + } strcat(host, tmpPtr + 1); strcat(host, "."); tmpPtr[0] = '\0'; } if ((strlen(host) + strlen(tmpString) + - 1) <= NAME_MAX) + 1) <= NAME_MAX) { strcat(host, tmpString); + } } foundHost = true; @@ -428,8 +451,9 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, dir->dirname, dir->entry.name); /* skip any entries starting with "." */ - if (dir->entry.name[0] == '.') + if (dir->entry.name[0] == '.') { continue; + } /* * get rid of '*', set to NULL. Effectively trims @@ -469,12 +493,12 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, * are performing a zone xfr and we * could not find a host entry. */ - } else if (dir_list != NULL && foundHost == false) { continue; } - } else /* if we cannot stat entry, skip it. */ + } else { /* if we cannot stat entry, skip it. */ continue; + } type = dir->entry.name; ttlStr = strchr(type, cd->separator); @@ -512,8 +536,9 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, len = strlen(data); for (i = 0; i < len; i++) { - if (data[i] == cd->separator) + if (data[i] == cd->separator) { data[i] = ' '; + } } /* convert text to int, make sure it worked right */ @@ -526,17 +551,19 @@ process_dir(isc_dir_t *dir, void *passback, config_data_t *cd, } /* pass data back to Bind */ - if (dir_list == NULL) + if (dir_list == NULL) { result = dns_sdlz_putrr((dns_sdlzlookup_t *)passback, type, ttl, data); - else + } else { result = dns_sdlz_putnamedrr( (dns_sdlzallnodes_t *)passback, (char *)host, type, ttl, data); + } /* if error, return error right away */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } /* end of while loop */ return (result); @@ -647,8 +674,9 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata, /* close the directory */ isc_dir_close(&dir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto complete_allnds; + } /* get first dir entry from list. */ dir_entry = ISC_LIST_HEAD(*dir_list); @@ -671,8 +699,9 @@ fs_allnodes(const char *zone, void *driverarg, void *dbdata, /* close the directory */ isc_dir_close(&dir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto complete_allnds; + } dir_entry = ISC_LIST_NEXT(dir_entry, link); } /* end while */ @@ -751,15 +780,16 @@ fs_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, UNUSED(methods); UNUSED(clientinfo); - if (strcmp(name, "*") == 0) + if (strcmp(name, "*") == 0) { /* * handle filesystem's special wildcard "-" */ result = create_path(zone, "-", NULL, (config_data_t *)dbdata, &path); - else + } else { result = create_path(zone, name, NULL, (config_data_t *)dbdata, &path); + } if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); @@ -850,10 +880,11 @@ fs_create(const char *dlzname, unsigned int argc, char *argv[], void *driverarg, } /* determine and save path separator for later */ - if (argv[1][len - 1] == '\\') + if (argv[1][len - 1] == '\\') { pathsep = '\\'; - else + } else { pathsep = '/'; + } /* allocate memory for our config data */ cd = isc_mem_get(named_g_mctx, sizeof(config_data_t)); @@ -911,14 +942,17 @@ fs_destroy(void *driverarg, void *dbdata) * free memory for each section of config data that was * allocated */ - if (cd->basedir != NULL) + if (cd->basedir != NULL) { isc_mem_free(named_g_mctx, cd->basedir); + } - if (cd->datadir != NULL) + if (cd->datadir != NULL) { isc_mem_free(named_g_mctx, cd->datadir); + } - if (cd->xfrdir != NULL) + if (cd->xfrdir != NULL) { isc_mem_free(named_g_mctx, cd->xfrdir); + } /* hold memory context to use later */ mctx = cd->mctx; @@ -984,8 +1018,9 @@ dlz_fs_clear(void) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2), "Unregistering DLZ filesystem driver."); - if (dlz_fs != NULL) + if (dlz_fs != NULL) { dns_sdlzunregister(&dlz_fs); + } } -#endif +#endif /* ifdef DLZ_FILESYSTEM */ diff --git a/contrib/dlz/drivers/dlz_ldap_driver.c b/contrib/dlz/drivers/dlz_ldap_driver.c index 15d263fe0b..3da3bf2369 100644 --- a/contrib/dlz/drivers/dlz_ldap_driver.c +++ b/contrib/dlz/drivers/dlz_ldap_driver.c @@ -183,8 +183,9 @@ dlz_ldap_checkURL(char *URL, int attrCnt, const char *msg) } cleanup: - if (ldap_url != NULL) + if (ldap_url != NULL) { ldap_free_urldesc(ldap_url); + } return (result); } @@ -206,8 +207,9 @@ dlz_ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) /* initialize. */ dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT); - if (dbc->dbconn == NULL) + if (dbc->dbconn == NULL) { return (ISC_R_NOMEMORY); + } /* set protocol version. */ ldap_result = ldap_set_option((LDAP *)dbc->dbconn, @@ -259,8 +261,9 @@ ldap_destroy_dblist(db_list_t *dblist) /* get the next DBI in the list */ ndbi = ISC_LIST_NEXT(dbi, link); /* release DB connection */ - if (dbi->dbconn != NULL) + if (dbi->dbconn != NULL) { ldap_unbind_s((LDAP *)dbi->dbconn); + } /* release all memory that comprised a DBI */ destroy_sqldbinstance(dbi); } @@ -291,9 +294,9 @@ ldap_find_avail_conn(db_list_t *dblist) /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ - if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) + if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) { return (dbi); /* success, return the DBI for use. */ - + } /* not successful, keep trying */ dbi = ISC_LIST_NEXT(dbi, link); @@ -353,8 +356,9 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, /* get the list of values for this attribute. */ vals = ldap_get_values(dbc, entry, attrs[j]); /* skip empty attributes. */ - if (vals == NULL || ldap_count_values(vals) < 1) + if (vals == NULL || ldap_count_values(vals) < 1) { continue; + } /* * we only use the first value. this driver * does not support multi-valued attributes. @@ -418,17 +422,18 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, break; case 2: j++; - if (allnodes) + if (allnodes) { host = isc_mem_strdup(named_g_mctx, vals[0]); - else + } else { strcpy(data, vals[0]); + } break; case 3: j++; - if (allnodes) + if (allnodes) { strcpy(data, vals[0]); - else { + } else { strcat(data, " "); strcat(data, vals[0]); } @@ -466,15 +471,16 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, } if (allnodes && host != NULL) { - if (strcasecmp(host, "~") == 0) + if (strcasecmp(host, "~") == 0) { result = dns_sdlz_putnamedrr( (dns_sdlzallnodes_t *)ptr, "*", type, ttl, data); - else + } else { result = dns_sdlz_putnamedrr( (dns_sdlzallnodes_t *)ptr, host, type, ttl, data); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, @@ -482,10 +488,11 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, "for \"%s %s %u %s\", %s", host, type, ttl, data, isc_result_totext(result)); + } } else { result = dns_sdlz_putrr((dns_sdlzlookup_t *)ptr, type, ttl, data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, @@ -493,6 +500,7 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, "for \"%s %u %s\", %s", type, ttl, data, isc_result_totext(result)); + } } if (result != ISC_R_SUCCESS) { @@ -506,8 +514,9 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, /* free memory for type, data and host for next loop */ isc_mem_free(named_g_mctx, type); isc_mem_free(named_g_mctx, data); - if (host != NULL) + if (host != NULL) { isc_mem_free(named_g_mctx, host); + } /* get the next entry to process */ entry = ldap_next_entry(dbc, entry); @@ -515,14 +524,18 @@ ldap_process_results(LDAP *dbc, LDAPMessage *msg, char **attrs, void *ptr, cleanup: /* de-allocate memory */ - if (vals != NULL) + if (vals != NULL) { ldap_value_free(vals); - if (host != NULL) + } + if (host != NULL) { isc_mem_free(named_g_mctx, host); - if (type != NULL) + } + if (type != NULL) { isc_mem_free(named_g_mctx, type); - if (data != NULL) + } + if (data != NULL) { isc_mem_free(named_g_mctx, data); + } return (result); } @@ -558,8 +571,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, (db_list_t *)((ldap_instance_t *)dbdata)->db); /* if DBI is null, can't do anything else */ - if (dbi == NULL) + if (dbi == NULL) { return (ISC_R_FAILURE); + } /* set fields */ if (zone != NULL) { @@ -722,8 +736,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, "LDAP driver attempting to re-connect"); result = dlz_ldap_connect((ldap_instance_t *)dbdata, dbi); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } break; default: /* @@ -740,8 +755,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, } /* close switch(ldap_result) */ } /* end for (int i = 0 i < 3; i++) */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } switch (query) { case ALLNODES: @@ -755,21 +771,23 @@ ldap_get_results(const char *zone, const char *record, const char *client, break; case ALLOWXFR: entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg); - if (entries == 0) + if (entries == 0) { result = ISC_R_NOPERM; - else if (entries > 0) + } else if (entries > 0) { result = ISC_R_SUCCESS; - else + } else { result = ISC_R_FAILURE; + } break; case FINDZONE: entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg); - if (entries == 0) + if (entries == 0) { result = ISC_R_NOTFOUND; - else if (entries > 0) + } else if (entries > 0) { result = ISC_R_SUCCESS; - else + } else { result = ISC_R_FAILURE; + } break; default: /* @@ -786,26 +804,32 @@ cleanup: /* it's always good to cleanup after yourself */ /* if we retrieved results, free them */ - if (ldap_msg != NULL) + if (ldap_msg != NULL) { ldap_msgfree(ldap_msg); + } - if (ldap_url != NULL) + if (ldap_url != NULL) { ldap_free_urldesc(ldap_url); + } /* cleanup */ - if (dbi->zone != NULL) + if (dbi->zone != NULL) { isc_mem_free(named_g_mctx, dbi->zone); - if (dbi->record != NULL) + } + if (dbi->record != NULL) { isc_mem_free(named_g_mctx, dbi->record); - if (dbi->client != NULL) + } + if (dbi->client != NULL) { isc_mem_free(named_g_mctx, dbi->client); + } /* release the lock so another thread can use this dbi */ isc_mutex_unlock(&dbi->instance_lock); /* release query string */ - if (querystring != NULL) + if (querystring != NULL) { isc_mem_free(named_g_mctx, querystring); + } /* return result */ return (result); @@ -871,12 +895,13 @@ dlz_ldap_lookup(const char *zone, const char *name, void *driverarg, UNUSED(methods); UNUSED(clientinfo); - if (strcmp(name, "*") == 0) + if (strcmp(name, "*") == 0) { result = ldap_get_results(zone, "~", NULL, LOOKUP, dbdata, lookup); - else + } else { result = ldap_get_results(zone, name, NULL, LOOKUP, dbdata, lookup); + } return (result); } @@ -961,25 +986,30 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], switch (argc) { case 12: result = dlz_ldap_checkURL(argv[11], 0, "allow zone transfer"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } case 11: result = dlz_ldap_checkURL(argv[10], 3, "all nodes"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } case 10: if (strlen(argv[9]) > 0) { result = dlz_ldap_checkURL(argv[9], 3, "authority"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } case 9: result = dlz_ldap_checkURL(argv[8], 3, "lookup"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dlz_ldap_checkURL(argv[7], 0, "find zone"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } break; default: /* not really needed, should shut up compiler. */ @@ -1059,13 +1089,13 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], * cleanup. */ switch (result) { - /* success, do nothing */ + /* success, do nothing */ case ISC_R_SUCCESS: break; - /* - * no memory means ldap_init could not - * allocate memory - */ + /* + * no memory means ldap_init could not + * allocate memory + */ case ISC_R_NOMEMORY: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, @@ -1074,10 +1104,10 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], i + 1); goto cleanup; break; - /* - * no perm means ldap_set_option could not set - * protocol version - */ + /* + * no perm means ldap_set_option could not set + * protocol version + */ case ISC_R_NOPERM: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, @@ -1086,7 +1116,7 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], result = ISC_R_FAILURE; goto cleanup; break; - /* failure means couldn't connect to ldap server */ + /* failure means couldn't connect to ldap server */ case ISC_R_FAILURE: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, @@ -1095,10 +1125,10 @@ dlz_ldap_create(const char *dlzname, unsigned int argc, char *argv[], i + 1); goto cleanup; break; - /* - * default should never happen. If it does, - * major errors. - */ + /* + * default should never happen. If it does, + * major errors. + */ default: UNEXPECTED_ERROR(__FILE__, __LINE__, "dlz_ldap_create() failed: %s", @@ -1134,17 +1164,20 @@ dlz_ldap_destroy(void *driverarg, void *dbdata) ldap_destroy_dblist( (db_list_t *)((ldap_instance_t *)dbdata)->db); - if (((ldap_instance_t *)dbdata)->hosts != NULL) + if (((ldap_instance_t *)dbdata)->hosts != NULL) { isc_mem_free(named_g_mctx, ((ldap_instance_t *)dbdata)->hosts); + } - if (((ldap_instance_t *)dbdata)->user != NULL) + if (((ldap_instance_t *)dbdata)->user != NULL) { isc_mem_free(named_g_mctx, ((ldap_instance_t *)dbdata)->user); + } - if (((ldap_instance_t *)dbdata)->cred != NULL) + if (((ldap_instance_t *)dbdata)->cred != NULL) { isc_mem_free(named_g_mctx, ((ldap_instance_t *)dbdata)->cred); + } isc_mem_put(named_g_mctx, dbdata, sizeof(ldap_instance_t)); } @@ -1207,8 +1240,9 @@ dlz_ldap_clear(void) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2), "Unregistering DLZ ldap driver."); - if (dlz_ldap != NULL) + if (dlz_ldap != NULL) { dns_sdlzunregister(&dlz_ldap); + } } -#endif +#endif /* ifdef DLZ_LDAP */ diff --git a/contrib/dlz/drivers/dlz_mysql_driver.c b/contrib/dlz/drivers/dlz_mysql_driver.c index 1f97f30cae..2711bd14dd 100644 --- a/contrib/dlz/drivers/dlz_mysql_driver.c +++ b/contrib/dlz/drivers/dlz_mysql_driver.c @@ -92,8 +92,9 @@ mysqldrv_escape_string(MYSQL *mysql, const char *instr) char * outstr; unsigned int len; - if (instr == NULL) - return NULL; + if (instr == NULL) { + return (NULL); + } len = strlen(instr); @@ -101,7 +102,7 @@ mysqldrv_escape_string(MYSQL *mysql, const char *instr) mysql_real_escape_string(mysql, outstr, instr, len); - return outstr; + return (outstr); } /*% @@ -125,10 +126,11 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, unsigned int j = 0; int qres = 0; - if (query != COUNTZONE) + if (query != COUNTZONE) { REQUIRE(*rs == NULL); - else + } else { REQUIRE(rs == NULL); + } /* get db instance / connection */ dbi = (dbinstance_t *)dbdata; @@ -302,8 +304,9 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, /* attempt query up to 3 times. */ for (i = 0; i < 3; i++) { qres = mysql_query((MYSQL *)dbi->dbconn, querystring); - if (qres == 0) + if (qres == 0) { break; + } for (j = 0; mysql_ping((MYSQL *)dbi->dbconn) != 0 && j < 4; j++) ; } @@ -312,8 +315,9 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, result = ISC_R_SUCCESS; if (query != COUNTZONE) { *rs = mysql_store_result((MYSQL *)dbi->dbconn); - if (*rs == NULL) + if (*rs == NULL) { result = ISC_R_FAILURE; + } } } else { result = ISC_R_FAILURE; @@ -323,23 +327,27 @@ cleanup: /* it's always good to cleanup after yourself */ /* free dbi->zone string */ - if (dbi->zone != NULL) + if (dbi->zone != NULL) { isc_mem_free(named_g_mctx, dbi->zone); + } /* free dbi->record string */ - if (dbi->record != NULL) + if (dbi->record != NULL) { isc_mem_free(named_g_mctx, dbi->record); + } /* free dbi->client string */ - if (dbi->client != NULL) + if (dbi->client != NULL) { isc_mem_free(named_g_mctx, dbi->client); + } /* release query string */ - if (querystring != NULL) + if (querystring != NULL) { isc_mem_free(named_g_mctx, querystring); + } /* return result */ - return result; + return (result); } /*% @@ -456,7 +464,7 @@ mysql_process_rs(dns_sdlzlookup_t *lookup, MYSQL_RES *rs) mysql_free_result(rs); /* return result code */ - return result; + return (result); } /* @@ -481,8 +489,9 @@ mysql_findzone(void *driverarg, void *dbdata, const char *name, result = mysql_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs); /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS || rs == NULL) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable to return " @@ -517,8 +526,9 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name, /* first check if the zone is supported by the database. */ result = mysql_findzone(driverarg, dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } /* * if we get to this point we know the zone is supported by @@ -530,12 +540,14 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name, */ result = mysql_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &rs); /* if we get "not implemented", send it along. */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS || rs == NULL) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable to return " @@ -548,8 +560,9 @@ mysql_allowzonexfr(void *driverarg, void *dbdata, const char *name, mysql_free_result(rs); /* if we returned any rows, zone xfr is allowed. */ - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } /* no rows returned, zone xfr not allowed */ return (ISC_R_NOPERM); @@ -579,12 +592,14 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata, /* run the query and get the result set from the database. */ result = mysql_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs); /* if we get "not implemented", send it along */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable to return " @@ -657,7 +672,7 @@ mysql_allnodes(const char *zone, void *driverarg, void *dbdata, /* free result set memory */ mysql_free_result(rs); - return result; + return (result); } /*% if the lookup function does not return SOA or NS records for the zone, @@ -676,12 +691,14 @@ mysql_authority(const char *zone, void *driverarg, void *dbdata, /* run the query and get the result set from the database. */ result = mysql_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &rs); /* if we get "not implemented", send it along */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable to return " @@ -692,7 +709,7 @@ mysql_authority(const char *zone, void *driverarg, void *dbdata, * lookup and authority result sets are processed in the same * manner mysql_process_rs does the job for both functions. */ - return mysql_process_rs(lookup, rs); + return (mysql_process_rs(lookup, rs)); } /*% if zone is supported, lookup up a (or multiple) record(s) in it */ @@ -712,8 +729,9 @@ mysql_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, result = mysql_get_resultset(zone, name, NULL, LOOKUP, dbdata, &rs); /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "mysql driver unable to return " @@ -724,7 +742,7 @@ mysql_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, * lookup and authority result sets are processed in the same manner * mysql_process_rs does the job for both functions. */ - return mysql_process_rs(lookup, rs); + return (mysql_process_rs(lookup, rs)); } /*% @@ -752,7 +770,7 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[], unsigned int flags = 0; #if MYSQL_VERSION_ID >= 50000 my_bool auto_reconnect = 1; -#endif +#endif /* if MYSQL_VERSION_ID >= 50000 */ UNUSED(driverarg); UNUSED(dlzname); @@ -860,22 +878,25 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[], tmp = getParameterValue(argv[1], "compress="); if (tmp != NULL) { - if (strcasecmp(tmp, "true") == 0) + if (strcasecmp(tmp, "true") == 0) { flags = CLIENT_COMPRESS; + } isc_mem_free(named_g_mctx, tmp); } tmp = getParameterValue(argv[1], "ssl="); if (tmp != NULL) { - if (strcasecmp(tmp, "true") == 0) + if (strcasecmp(tmp, "true") == 0) { flags = flags | CLIENT_SSL; + } isc_mem_free(named_g_mctx, tmp); } tmp = getParameterValue(argv[1], "space="); if (tmp != NULL) { - if (strcasecmp(tmp, "ignore") == 0) + if (strcasecmp(tmp, "ignore") == 0) { flags = flags | CLIENT_IGNORE_SPACE; + } isc_mem_free(named_g_mctx, tmp); } @@ -894,7 +915,7 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[], "mysql driver failed to set " "MYSQL_OPT_RECONNECT option, continuing"); } -#endif +#endif /* if MYSQL_VERSION_ID >= 50000 */ for (j = 0; dbc == NULL && j < 4; j++) dbc = mysql_real_connect((MYSQL *)dbi->dbconn, host, user, pass, @@ -918,23 +939,29 @@ mysql_create(const char *dlzname, unsigned int argc, char *argv[], full_cleanup: - if (dbi != NULL) + if (dbi != NULL) { destroy_sqldbinstance(dbi); + } cleanup: - if (dbname != NULL) + if (dbname != NULL) { isc_mem_free(named_g_mctx, dbname); - if (host != NULL) + } + if (host != NULL) { isc_mem_free(named_g_mctx, host); - if (user != NULL) + } + if (user != NULL) { isc_mem_free(named_g_mctx, user); - if (pass != NULL) + } + if (pass != NULL) { isc_mem_free(named_g_mctx, pass); - if (socket != NULL) + } + if (socket != NULL) { isc_mem_free(named_g_mctx, socket); + } - return result; + return (result); } /*% @@ -954,8 +981,9 @@ mysql_destroy(void *driverarg, void *dbdata) dbi = (dbinstance_t *)dbdata; /* release DB connection */ - if (dbi->dbconn != NULL) + if (dbi->dbconn != NULL) { mysql_close((MYSQL *)dbi->dbconn); + } /* destroy DB instance */ destroy_sqldbinstance(dbi); @@ -1014,7 +1042,7 @@ dlz_mysql_init(void) result = ISC_R_UNEXPECTED; } - return result; + return (result); } /*% @@ -1030,8 +1058,9 @@ dlz_mysql_clear(void) ISC_LOG_DEBUG(2), "Unregistering DLZ mysql driver."); /* unregister the driver. */ - if (dlz_mysql != NULL) + if (dlz_mysql != NULL) { dns_sdlzunregister(&dlz_mysql); + } } -#endif +#endif /* ifdef DLZ_MYSQL */ diff --git a/contrib/dlz/drivers/dlz_odbc_driver.c b/contrib/dlz/drivers/dlz_odbc_driver.c index 317bb7cf5a..cb9d9b932a 100644 --- a/contrib/dlz/drivers/dlz_odbc_driver.c +++ b/contrib/dlz/drivers/dlz_odbc_driver.c @@ -114,9 +114,10 @@ odbc_makesafe(char *to, const char *from, size_t length); static SQLSMALLINT safeLen(void *a) { - if (a == NULL) - return 0; - return strlen((char *)a); + if (a == NULL) { + return (0); + } + return (strlen((char *)a)); } /*% propertly cleans up an odbc_instance_t */ @@ -165,20 +166,25 @@ destroy_odbc_instance(odbc_instance_t *odbc_inst) isc_mem_put(named_g_mctx, odbc_inst->db, sizeof(db_list_t)); /* free sql environment */ - if (odbc_inst->sql_env != NULL) + if (odbc_inst->sql_env != NULL) { SQLFreeHandle(SQL_HANDLE_ENV, odbc_inst->sql_env); + } /* free ODBC instance strings */ - if (odbc_inst->dsn != NULL) + if (odbc_inst->dsn != NULL) { isc_mem_free(named_g_mctx, odbc_inst->dsn); - if (odbc_inst->pass != NULL) + } + if (odbc_inst->pass != NULL) { isc_mem_free(named_g_mctx, odbc_inst->pass); - if (odbc_inst->user != NULL) + } + if (odbc_inst->user != NULL) { isc_mem_free(named_g_mctx, odbc_inst->user); + } /* free memory for odbc_inst */ - if (odbc_inst != NULL) + if (odbc_inst != NULL) { isc_mem_put(named_g_mctx, odbc_inst, sizeof(odbc_instance_t)); + } } /*% Connects to database, and creates ODBC statements */ @@ -240,7 +246,7 @@ odbc_connect(odbc_instance_t *dbi, odbc_db_t **dbc) *dbc = ndb; - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); cleanup: @@ -261,7 +267,7 @@ cleanup: isc_mem_free(named_g_mctx, ndb); } - return result; + return (result); } /*% @@ -288,9 +294,9 @@ odbc_find_avail_conn(db_list_t *dblist) /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ - if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) - return dbi; /* success, return the DBI for use. */ - + if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) { + return (dbi); /* success, return the DBI for use. */ + } /* not successful, keep trying */ dbi = ISC_LIST_NEXT(dbi, link); @@ -305,7 +311,7 @@ odbc_find_avail_conn(db_list_t *dblist) "Odbc driver unable to find available " "connection after searching %d times", count); - return NULL; + return (NULL); } /*% Allocates memory for a new string, and then constructs the new @@ -321,8 +327,9 @@ odbc_escape_string(const char *instr) char * outstr; unsigned int len; - if (instr == NULL) - return NULL; + if (instr == NULL) { + return (NULL); + } len = strlen(instr); @@ -330,7 +337,7 @@ odbc_escape_string(const char *instr) odbc_makesafe(outstr, instr, len); - return outstr; + return (outstr); } /* --------------- @@ -386,7 +393,7 @@ odbc_makesafe(char *to, const char *from, size_t length) /* Write the terminating NUL character. */ *target = '\0'; - return target - to; + return (target - to); } /*% @@ -590,8 +597,9 @@ odbc_get_resultset(const char *zone, const char *record, const char *client, result = odbc_connect((odbc_instance_t *)dbdata, (odbc_db_t **)&(dbi->dbconn)); /* check if we reconnected */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } /* incase this is the last time through the loop */ result = ISC_R_FAILURE; } else { @@ -606,27 +614,32 @@ odbc_get_resultset(const char *zone, const char *record, const char *client, cleanup: /* it's always good to cleanup after yourself */ /* free dbi->zone string */ - if (dbi->zone != NULL) + if (dbi->zone != NULL) { isc_mem_free(named_g_mctx, dbi->zone); + } /* free dbi->record string */ - if (dbi->record != NULL) + if (dbi->record != NULL) { isc_mem_free(named_g_mctx, dbi->record); + } /* free dbi->client string */ - if (dbi->client != NULL) + if (dbi->client != NULL) { isc_mem_free(named_g_mctx, dbi->client); + } /* if we are done using this dbi, release the lock */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_mutex_unlock(&dbi->instance_lock); + } /* release query string */ - if (querystring != NULL) + if (querystring != NULL) { isc_mem_free(named_g_mctx, querystring); + } /* return result */ - return result; + return (result); } /*% @@ -649,12 +662,13 @@ odbc_getField(SQLHSTMT *stmnt, SQLSMALLINT field, char **data) *data = isc_mem_allocate(named_g_mctx, size + 1); if (data != NULL) { if (sqlOK(SQLGetData(stmnt, field, SQL_C_CHAR, *data, - size + 1, &size))) - return ISC_R_SUCCESS; + size + 1, &size))) { + return (ISC_R_SUCCESS); + } isc_mem_free(named_g_mctx, *data); } } - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /*% @@ -680,18 +694,20 @@ odbc_getManyFields(SQLHSTMT *stmnt, SQLSMALLINT startField, /* determine how large the data is */ for (i = startField; i <= endField; i++) { - if (sqlOK(SQLColAttribute(stmnt, i, SQL_DESC_DISPLAY_SIZE, NULL, 0, NULL, &size)) && size > 0) { + if (sqlOK(SQLColAttribute(stmnt, i, SQL_DESC_DISPLAY_SIZE, NULL, + 0, NULL, &size)) && + size > 0) { { - /* always allow for a " " (space) character */ + /* always allow for a " " (space) character */ totSize += (size + 1); - /* after the data item */ + /* after the data item */ } - } } - if (totSize < 1) - return ISC_R_FAILURE; + if (totSize < 1) { + return (ISC_R_FAILURE); + } /* allow for a "\n" at the end of the string/ */ data = isc_mem_allocate(named_g_mctx, ++totSize); @@ -710,17 +726,17 @@ odbc_getManyFields(SQLHSTMT *stmnt, SQLSMALLINT startField, } } else { isc_mem_free(named_g_mctx, data); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } } if (result != ISC_R_SUCCESS) { isc_mem_free(named_g_mctx, data); - return result; + return (result); } *retData = data; - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /*% @@ -825,12 +841,15 @@ odbc_process_rs(dns_sdlzlookup_t *lookup, dbinstance_t *dbi) } /* closes switch(fields) */ /* clean up mem */ - if (ttl_s != NULL) + if (ttl_s != NULL) { isc_mem_free(named_g_mctx, ttl_s); - if (type != NULL) + } + if (type != NULL) { isc_mem_free(named_g_mctx, type); - if (data != NULL) + } + if (data != NULL) { isc_mem_free(named_g_mctx, data); + } /* I sure hope we were successful */ if (result != ISC_R_SUCCESS) { @@ -852,7 +871,7 @@ process_rs_cleanup: /* free lock on dbi so someone else can use it. */ isc_mutex_unlock(&dbi->instance_lock); - return result; + return (result); } /* @@ -891,7 +910,7 @@ odbc_findzone(void *driverarg, void *dbdata, const char *name, isc_mutex_unlock(&dbi->instance_lock); } - return result; + return (result); } /*% Determine if the client is allowed to perform a zone transfer */ @@ -906,8 +925,9 @@ odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name, /* first check if the zone is supported by the database. */ result = odbc_findzone(driverarg, dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } /* * if we get to this point we know the zone is supported by @@ -922,8 +942,9 @@ odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name, result = odbc_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &dbi); /* if we get "not implemented", send it along. */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* Check that we got a result set with data */ if (result == ISC_R_SUCCESS && @@ -939,7 +960,7 @@ odbc_allowzonexfr(void *driverarg, void *dbdata, const char *name, isc_mutex_unlock(&dbi->instance_lock); } - return result; + return (result); } /*% @@ -969,8 +990,9 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata, result = odbc_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &dbi); /* if we get "not implemented", send it along */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { @@ -1038,14 +1060,18 @@ odbc_allnodes(const char *zone, void *driverarg, void *dbdata, } /* closes big if () */ /* clean up mem */ - if (ttl_s != NULL) + if (ttl_s != NULL) { isc_mem_free(named_g_mctx, ttl_s); - if (type != NULL) + } + if (type != NULL) { isc_mem_free(named_g_mctx, type); - if (host != NULL) + } + if (host != NULL) { isc_mem_free(named_g_mctx, host); - if (data != NULL) + } + if (data != NULL) { isc_mem_free(named_g_mctx, data); + } /* if we weren't successful, log err msg */ if (result != ISC_R_SUCCESS) { @@ -1067,7 +1093,7 @@ allnodes_cleanup: /* free lock on dbi so someone else can use it. */ isc_mutex_unlock(&dbi->instance_lock); - return result; + return (result); } /*% @@ -1087,8 +1113,9 @@ odbc_authority(const char *zone, void *driverarg, void *dbdata, /* run the query and get the result set from the database. */ result = odbc_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &dbi); /* if we get "not implemented", send it along */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, @@ -1099,7 +1126,7 @@ odbc_authority(const char *zone, void *driverarg, void *dbdata, } /* lookup and authority result sets are processed in the same manner */ /* odbc_process_rs does the job for both functions. */ - return odbc_process_rs(lookup, dbi); + return (odbc_process_rs(lookup, dbi)); } /*% if zone is supported, lookup up a (or multiple) record(s) in it */ @@ -1128,7 +1155,7 @@ odbc_lookup(const char *zone, const char *name, void *driverarg, void *dbdata, } /* lookup and authority result sets are processed in the same manner */ /* odbc_process_rs does the job for both functions. */ - return odbc_process_rs(lookup, dbi); + return (odbc_process_rs(lookup, dbi)); } /*% @@ -1302,7 +1329,6 @@ odbc_create(const char *dlzname, unsigned int argc, char *argv[], /* set DB = null for next loop through. */ db = NULL; - } /* end for loop */ /* set dbdata to the odbc_instance we created. */ @@ -1315,7 +1341,7 @@ cleanup: destroy_odbc_instance(odbc_inst); - return result; + return (result); } /*% @@ -1387,7 +1413,7 @@ dlz_odbc_init(void) result = ISC_R_UNEXPECTED; } - return result; + return (result); } /*% @@ -1403,8 +1429,9 @@ dlz_odbc_clear(void) ISC_LOG_DEBUG(2), "Unregistering DLZ odbc driver."); /* unregister the driver. */ - if (dlz_odbc != NULL) + if (dlz_odbc != NULL) { dns_sdlzunregister(&dlz_odbc); + } } -#endif +#endif /* ifdef DLZ_ODBC */ diff --git a/contrib/dlz/drivers/dlz_postgres_driver.c b/contrib/dlz/drivers/dlz_postgres_driver.c index db343c54ea..1499e2a62f 100644 --- a/contrib/dlz/drivers/dlz_postgres_driver.c +++ b/contrib/dlz/drivers/dlz_postgres_driver.c @@ -141,7 +141,7 @@ postgres_makesafe(char *to, const char *from, size_t length) /* Write the terminating NUL character. */ *target = '\0'; - return target - to; + return (target - to); } /*% @@ -164,8 +164,9 @@ postgres_destroy_dblist(db_list_t *dblist) /* get the next DBI in the list */ ndbi = ISC_LIST_NEXT(dbi, link); /* release DB connection */ - if (dbi->dbconn != NULL) + if (dbi->dbconn != NULL) { PQfinish((PGconn *)dbi->dbconn); + } /* release all memory that comprised a DBI */ destroy_sqldbinstance(dbi); } @@ -197,9 +198,9 @@ postgres_find_avail_conn(db_list_t *dblist) /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ - if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) - return dbi; /* success, return the DBI for use. */ - + if (isc_mutex_trylock(&dbi->instance_lock) == ISC_R_SUCCESS) { + return (dbi); /* success, return the DBI for use. */ + } /* not successful, keep trying */ dbi = ISC_LIST_NEXT(dbi, link); @@ -214,7 +215,7 @@ postgres_find_avail_conn(db_list_t *dblist) "Postgres driver unable to find available connection " "after searching %d times", count); - return NULL; + return (NULL); } /*% @@ -231,8 +232,9 @@ postgres_escape_string(const char *instr) char * outstr; unsigned int len; - if (instr == NULL) - return NULL; + if (instr == NULL) { + return (NULL); + } len = strlen(instr); @@ -241,7 +243,7 @@ postgres_escape_string(const char *instr) postgres_makesafe(outstr, instr, len); /* PQescapeString(outstr, instr, len); */ - return outstr; + return (outstr); } /*% @@ -272,8 +274,10 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, #if 0 /* temporarily get a unique thread # */ - unsigned int dlz_thread_num = 1+(int) (1000.0*rand()/(RAND_MAX+1.0)); -#endif + unsigned int dlz_thread_num = 1 + + (int) (1000.0 * rand() / + (RAND_MAX + 1.0)); +#endif /* if 0 */ REQUIRE(*rs == NULL); @@ -282,7 +286,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d Getting DBI", dlz_thread_num); -#endif +#endif /* if 0 */ /* get db instance / connection */ @@ -294,7 +298,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d Got DBI - checking query", dlz_thread_num); -#endif +#endif /* if 0 */ /* if DBI is null, can't do anything else */ if (dbi == NULL) { @@ -368,7 +372,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d checked query", dlz_thread_num); -#endif +#endif /* if 0 */ /* * was a zone string passed? If so, make it safe for use in @@ -389,7 +393,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d did zone", dlz_thread_num); -#endif +#endif /* if 0 */ /* * was a record string passed? If so, make it safe for use in @@ -410,7 +414,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d did record", dlz_thread_num); -#endif +#endif /* if 0 */ /* * was a client string passed? If so, make it safe for use in @@ -429,9 +433,9 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, #if 0 /* temporary logging message */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, - DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, + DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d did client", dlz_thread_num); -#endif +#endif /* if 0 */ /* * what type of query are we going to run? @@ -470,7 +474,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d built query", dlz_thread_num); -#endif +#endif /* if 0 */ /* if the querystring is null, Bummer, outta RAM. UPGRADE TIME!!! */ if (querystring == NULL) { @@ -483,7 +487,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d query is '%s'", dlz_thread_num, querystring); -#endif +#endif /* if 0 */ /* * output the full query string during debug so we can see @@ -500,7 +504,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d executing query for %d time", dlz_thread_num, j); -#endif +#endif /* if 0 */ /* try to get result set */ *rs = PQexec((PGconn *)dbi->dbconn, querystring); result = ISC_R_SUCCESS; @@ -515,12 +519,13 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d resetting connection", dlz_thread_num); -#endif +#endif /* if 0 */ result = ISC_R_FAILURE; PQreset((PGconn *)dbi->dbconn); /* connection ok, break inner loop */ - if (PQstatus((PGconn *)dbi->dbconn) == CONNECTION_OK) + if (PQstatus((PGconn *)dbi->dbconn) == CONNECTION_OK) { break; + } } /* result set ok, break outter loop */ if (PQresultStatus(*rs) == PGRES_TUPLES_OK) { @@ -529,7 +534,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d rs ok", dlz_thread_num); -#endif +#endif /* if 0 */ break; } else { /* we got a result set object, but it's not right. */ @@ -538,7 +543,7 @@ postgres_get_resultset(const char *zone, const char *record, const char *client, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d clearing rs", dlz_thread_num); -#endif +#endif /* if 0 */ PQclear(*rs); /* get rid of it */ /* in case this was the last attempt */ *rs = NULL; @@ -554,43 +559,47 @@ cleanup: isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d cleaning up", dlz_thread_num); -#endif +#endif /* if 0 */ /* free dbi->zone string */ - if (dbi->zone != NULL) + if (dbi->zone != NULL) { isc_mem_free(named_g_mctx, dbi->zone); + } /* free dbi->record string */ - if (dbi->record != NULL) + if (dbi->record != NULL) { isc_mem_free(named_g_mctx, dbi->record); + } /* free dbi->client string */ - if (dbi->client != NULL) + if (dbi->client != NULL) { isc_mem_free(named_g_mctx, dbi->client); + } #if 0 /* temporary logging message */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d unlocking mutex", dlz_thread_num); -#endif +#endif /* if 0 */ /* release the lock so another thread can use this dbi */ isc_mutex_unlock(&dbi->instance_lock); /* release query string */ - if (querystring != NULL) + if (querystring != NULL) { isc_mem_free(named_g_mctx, querystring); + } #if 0 /* temporary logging message */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "%d returning", dlz_thread_num); -#endif +#endif /* if 0 */ /* return result */ - return result; + return (result); } /*% @@ -704,8 +713,9 @@ postgres_process_rs(dns_sdlzlookup_t *lookup, PGresult *rs) PQclear(rs); /* if we did return results, we are successful */ - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } /* empty result set, no data found */ return (ISC_R_NOTFOUND); @@ -735,8 +745,9 @@ postgres_findzone(void *driverarg, void *dbdata, const char *name, postgres_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs); /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { PQclear(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Postgres driver unable to return " @@ -749,8 +760,9 @@ postgres_findzone(void *driverarg, void *dbdata, const char *name, PQclear(rs); /* if we returned any rows, zone is supported. */ - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } /* no rows returned, zone is not supported. */ return (ISC_R_NOTFOUND); @@ -768,8 +780,9 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name, /* first check if the zone is supported by the database. */ result = postgres_findzone(driverarg, dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } /* * if we get to this point we know the zone is supported by @@ -782,12 +795,14 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name, result = postgres_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &rs); /* if we get "not implemented", send it along. */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { PQclear(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Postgres driver unable to return " @@ -800,8 +815,9 @@ postgres_allowzonexfr(void *driverarg, void *dbdata, const char *name, PQclear(rs); /* if we returned any rows, zone xfr is allowed. */ - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } /* no rows returned, zone xfr not allowed */ return (ISC_R_NOPERM); @@ -833,12 +849,14 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata, result = postgres_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs); /* if we get "not implemented", send it along */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { PQclear(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Postgres driver unable to return " @@ -909,8 +927,9 @@ postgres_allnodes(const char *zone, void *driverarg, void *dbdata, PQclear(rs); /* if we did return results, we are successful */ - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } /* empty result set, no data found */ return (ISC_R_NOTFOUND); @@ -934,12 +953,14 @@ postgres_authority(const char *zone, void *driverarg, void *dbdata, result = postgres_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &rs); /* if we get "not implemented", send it along */ - if (result == ISC_R_NOTIMPLEMENTED) - return result; + if (result == ISC_R_NOTIMPLEMENTED) { + return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { PQclear(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Postgres driver unable to return " @@ -951,7 +972,7 @@ postgres_authority(const char *zone, void *driverarg, void *dbdata, * manner postgres_process_rs does the job for both * functions. */ - return postgres_process_rs(lookup, rs); + return (postgres_process_rs(lookup, rs)); } /*% if zone is supported, lookup up a (or multiple) record(s) in it */ @@ -971,8 +992,9 @@ postgres_lookup(const char *zone, const char *name, void *driverarg, result = postgres_get_resultset(zone, name, NULL, LOOKUP, dbdata, &rs); /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { PQclear(rs); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_ERROR, "Postgres driver unable to " @@ -983,7 +1005,7 @@ postgres_lookup(const char *zone, const char *name, void *driverarg, * lookup and authority result sets are processed in the same * manner postgres_process_rs does the job for both functions. */ - return postgres_process_rs(lookup, rs); + return (postgres_process_rs(lookup, rs)); } /*% @@ -1228,7 +1250,7 @@ dlz_postgres_init(void) result = ISC_R_UNEXPECTED; } - return result; + return (result); } /*% @@ -1244,8 +1266,9 @@ dlz_postgres_clear(void) ISC_LOG_DEBUG(2), "Unregistering DLZ postgres driver."); /* unregister the driver. */ - if (dlz_postgres != NULL) + if (dlz_postgres != NULL) { dns_sdlzunregister(&dlz_postgres); + } } -#endif +#endif /* ifdef DLZ_POSTGRES */ diff --git a/contrib/dlz/drivers/dlz_stub_driver.c b/contrib/dlz/drivers/dlz_stub_driver.c index 3be8592d70..2051c69ed4 100644 --- a/contrib/dlz/drivers/dlz_stub_driver.c +++ b/contrib/dlz/drivers/dlz_stub_driver.c @@ -86,14 +86,17 @@ stub_dlz_allnodes(const char *zone, void *driverarg, void *dbdata, result = dns_sdlz_putnamedrr(allnodes, cd->myname, "soa", 86400, "web root.localhost. " "0 28800 7200 604800 86400"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } result = dns_sdlz_putnamedrr(allnodes, "ns", "ns", 86400, cd->myname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } result = dns_sdlz_putnamedrr(allnodes, cd->myname, "a", 1, cd->myip); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } return (ISC_R_SUCCESS); } @@ -128,12 +131,14 @@ stub_dlz_authority(const char *zone, void *driverarg, void *dbdata, if (strcmp(zone, cd->myzone) == 0) { result = dns_sdlz_putsoa(lookup, cd->myname, "root.localhost.", 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } result = dns_sdlz_putrr(lookup, "ns", 86400, cd->myname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } return (ISC_R_SUCCESS); } @@ -158,10 +163,11 @@ stub_dlz_findzonedb(void *driverarg, void *dbdata, const char *name, ISC_LOG_DEBUG(2), "dlz_stub findzone looking for '%s'", name); - if (strcmp(cd->myzone, name) == 0) + if (strcmp(cd->myzone, name) == 0) { return (ISC_R_SUCCESS); - else + } else { return (ISC_R_NOTFOUND); + } } static isc_result_t @@ -181,8 +187,9 @@ stub_dlz_lookup(const char *zone, const char *name, void *driverarg, if (strcmp(name, cd->myname) == 0) { result = dns_sdlz_putrr(lookup, "a", 1, cd->myip); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } return (ISC_R_SUCCESS); } @@ -197,8 +204,9 @@ stub_dlz_create(const char *dlzname, unsigned int argc, char *argv[], UNUSED(driverarg); - if (argc < 4) + if (argc < 4) { return (ISC_R_FAILURE); + } /* * Write info message to log */ @@ -293,7 +301,7 @@ dlz_stub_init(void) result = ISC_R_UNEXPECTED; } - return result; + return (result); } /* @@ -308,8 +316,9 @@ dlz_stub_clear(void) isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DLZ, ISC_LOG_DEBUG(2), "Unregistering DLZ_stub driver."); - if (dlz_stub != NULL) + if (dlz_stub != NULL) { dns_sdlzunregister(&dlz_stub); + } } -#endif +#endif /* ifdef DLZ_STUB */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h b/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h index 1d706fc8b9..b180832c96 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_bdb_driver.h @@ -42,4 +42,4 @@ dlz_bdb_init(void); void dlz_bdb_clear(void); -#endif +#endif /* ifndef DLZ_BDB_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h b/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h index 0ccbc8da80..65a2b84ddd 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_bdbhpt_driver.h @@ -42,4 +42,4 @@ dlz_bdbhpt_init(void); void dlz_bdbhpt_clear(void); -#endif +#endif /* ifndef DLZ_BDBHPT_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h b/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h index 627427d941..a13c703371 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_filesystem_driver.h @@ -42,4 +42,4 @@ dlz_fs_init(void); void dlz_fs_clear(void); -#endif +#endif /* ifndef DLZ_FILESYSTEM_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h b/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h index 51efbf497f..3df72858d9 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_ldap_driver.h @@ -42,4 +42,4 @@ dlz_ldap_init(void); void dlz_ldap_clear(void); -#endif +#endif /* ifndef DLZ_LDAP_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h b/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h index b742838bc8..68a0b540a2 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_mysql_driver.h @@ -42,4 +42,4 @@ dlz_mysql_init(void); void dlz_mysql_clear(void); -#endif +#endif /* ifndef DLZ_MYSQL_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h b/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h index 5a072d8c98..b3ed620b60 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_odbc_driver.h @@ -42,4 +42,4 @@ dlz_odbc_init(void); void dlz_odbc_clear(void); -#endif +#endif /* ifndef DLZ_ODBC_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h b/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h index 3416dceadf..d8e250dcee 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_postgres_driver.h @@ -42,4 +42,4 @@ dlz_postgres_init(void); void dlz_postgres_clear(void); -#endif +#endif /* ifndef DLZ_POSTGRES_DRIVER_H */ diff --git a/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h b/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h index a517c69adc..73df7ba2f9 100644 --- a/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h +++ b/contrib/dlz/drivers/include/dlz/dlz_stub_driver.h @@ -42,4 +42,4 @@ dlz_stub_init(void); void dlz_stub_clear(void); -#endif +#endif /* ifndef DLZ_STUB_DRIVER_H */ diff --git a/contrib/dlz/drivers/sdlz_helper.c b/contrib/dlz/drivers/sdlz_helper.c index a743e5fe28..636401bb6b 100644 --- a/contrib/dlz/drivers/sdlz_helper.c +++ b/contrib/dlz/drivers/sdlz_helper.c @@ -71,8 +71,9 @@ destroy_querylist(isc_mem_t *mctx, query_list_t **querylist) REQUIRE(mctx != NULL); /* if query list is null, nothing to do */ - if (*querylist == NULL) + if (*querylist == NULL) { return; + } /* start at the top of the list */ nseg = ISC_LIST_HEAD(**querylist); @@ -83,8 +84,9 @@ destroy_querylist(isc_mem_t *mctx, query_list_t **querylist) * was really a query segment, and not a pointer to * %zone%, or %record%, or %client% */ - if (tseg->sql != NULL && tseg->direct == true) + if (tseg->sql != NULL && tseg->direct == true) { isc_mem_free(mctx, tseg->sql); + } /* get the next query segment, before we destroy this one. */ nseg = ISC_LIST_NEXT(nseg, link); /* deallocate this query segment. */ @@ -115,12 +117,13 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone, /* if query string is null, or zero length */ if (query_str == NULL || strlen(query_str) < 1) { - if ((flags & SDLZH_REQUIRE_QUERY) == 0) + if ((flags & SDLZH_REQUIRE_QUERY) == 0) { /* we don't need it were ok. */ return (ISC_R_SUCCESS); - else + } else { /* we did need it, PROBLEM!!! */ return (ISC_R_FAILURE); + } } /* allocate memory for query list */ @@ -249,13 +252,14 @@ build_querylist(isc_mem_t *mctx, const char *query_str, char **zone, cleanup: /* get rid of free_me */ - if (free_me != NULL) + if (free_me != NULL) { isc_mem_free(mctx, free_me); + } flag_fail: /* get rid of what was build of the query list */ destroy_querylist(mctx, &tql); - return result; + return (result); } /*% @@ -280,10 +284,11 @@ sdlzh_build_querystring(isc_mem_t *mctx, query_list_t *querylist) * if this is a query segment, use the * precalculated string length */ - if (tseg->direct == true) + if (tseg->direct == true) { length += tseg->strlen; - else /* calculate string length for dynamic segments. */ + } else { /* calculate string length for dynamic segments. */ length += strlen(*(char **)tseg->sql); + } /* get the next segment */ tseg = ISC_LIST_NEXT(tseg, link); } @@ -295,17 +300,18 @@ sdlzh_build_querystring(isc_mem_t *mctx, query_list_t *querylist) /* start at the top of the list again */ tseg = ISC_LIST_HEAD(*querylist); while (tseg != NULL) { - if (tseg->direct == true) + if (tseg->direct == true) { /* query segments */ strcat(qs, tseg->sql); - else + } else { /* dynamic segments */ strcat(qs, *(char **)tseg->sql); + } /* get the next segment */ tseg = ISC_LIST_NEXT(tseg, link); } - return qs; + return (qs); } /*% constructs a sql dbinstance (DBI) */ @@ -459,18 +465,21 @@ sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char *key) char value[255]; int i; - if (key == NULL || input == NULL || strlen(input) < 1) - return NULL; + if (key == NULL || input == NULL || strlen(input) < 1) { + return (NULL); + } keylen = strlen(key); - if (keylen < 1) - return NULL; + if (keylen < 1) { + return (NULL); + } keystart = strstr(input, key); - if (keystart == NULL) - return NULL; + if (keystart == NULL) { + return (NULL); + } REQUIRE(mctx != NULL); @@ -482,5 +491,5 @@ sdlzh_get_parameter_value(isc_mem_t *mctx, const char *input, const char *key) } } - return isc_mem_strdup(mctx, value); + return (isc_mem_strdup(mctx, value)); } diff --git a/contrib/dlz/example/dlz_example.c b/contrib/dlz/example/dlz_example.c index 5eef71192e..37090bddca 100644 --- a/contrib/dlz/example/dlz_example.c +++ b/contrib/dlz/example/dlz_example.c @@ -91,28 +91,33 @@ 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) { i = first_empty; } if (i == MAX_RECORDS) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "dlz_example: out of record " "space"); + } return (ISC_R_FAILURE); } 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)); list[i].name[sizeof(list[i].name) - 1] = '\0'; @@ -175,8 +180,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); @@ -199,14 +205,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; + } } /* @@ -227,8 +237,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); @@ -238,9 +249,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, va_end(ap); if (argc < 2 || argv[1][0] == '\0') { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "dlz_example: please specify " "a zone name"); + } dlz_destroy(state); return (ISC_R_FAILURE); } @@ -251,23 +263,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); @@ -276,9 +292,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, add_name(state, &state->current[0], state->zone_name, "a", 1800, "10.53.0.1"); - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: started for zone %s", state->zone_name); + } *dbdata = state; return (ISC_R_SUCCESS); @@ -296,9 +313,10 @@ dlz_destroy(void *dbdata) { struct dlz_example_data *state = (struct dlz_example_data *)dbdata; - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: shutting down zone %s", state->zone_name); + } free(state->zone_name); free(state); } @@ -337,23 +355,27 @@ 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); + } - 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); } @@ -384,14 +406,16 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, UNUSED(zone); - if (state->putrr == NULL) + if (state->putrr == NULL) { return (ISC_R_NOTIMPLEMENTED); + } if (strcmp(name, "@") == 0) { strncpy(full_name, state->zone_name, 255); full_name[255] = '\0'; - } else + } else { snprintf(full_name, 255, "%s.%s", name, state->zone_name); + } /* * If we need to know the database version (as set in @@ -411,10 +435,11 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, if (clientinfo != NULL && clientinfo->version >= DNS_CLIENTINFO_VERSION) { dbversion = clientinfo->dbversion; - if (dbversion != NULL && *(bool *)dbversion) + if (dbversion != NULL && *(bool *)dbversion) { state->log(ISC_LOG_INFO, "dlz_example: lookup against " "live " "transaction\n"); + } } if (strcmp(name, "source-addr") == 0) { @@ -432,8 +457,9 @@ 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) { @@ -442,8 +468,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, buf[i] = '\0'; found = true; result = state->putrr(lookup, "TXT", 0, buf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } for (i = 0; i < MAX_RECORDS; i++) { @@ -452,13 +479,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); } @@ -486,8 +515,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; @@ -498,8 +528,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); @@ -514,11 +545,12 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) struct dlz_example_data *state = (struct dlz_example_data *)dbdata; if (state->transaction_started) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: transaction already " "started for zone %s", zone); + } return (ISC_R_FAILURE); } @@ -537,11 +569,12 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) struct dlz_example_data *state = (struct dlz_example_data *)dbdata; if (!state->transaction_started) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: transaction not " "started for zone %s", zone); + } *versionp = NULL; return; } @@ -552,11 +585,12 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) if (commit) { int i; - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: committing " "transaction on zone %s", zone); + } for (i = 0; i < MAX_RECORDS; i++) { if (strlen(state->deletes[i].name) > 0U) { (void)del_name(state, &state->current[0], @@ -576,11 +610,12 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) } } } else { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: cancelling " "transaction on zone %s", zone); + } } memset(state->adds, 0, sizeof(state->adds)); memset(state->deletes, 0, sizeof(state->deletes)); @@ -595,32 +630,36 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) struct dlz_example_data *state = (struct dlz_example_data *)dbdata; isc_result_t result; - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: starting configure"); + } if (state->writeable_zone == NULL) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: no " "writeable_zone method " "available"); + } return (ISC_R_FAILURE); } result = state->writeable_zone(view, dlzdb, state->zone_name); if (result != ISC_R_SUCCESS) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "dlz_example: failed to " "configure zone %s", state->zone_name); + } return (result); } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: configured writeable " "zone %s", state->zone_name); + } return (ISC_R_SUCCESS); } @@ -641,18 +680,20 @@ dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr, UNUSED(keydata); if (strncmp(name, "deny.", 5) == 0) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: denying update " "of name=%s by %s", name, signer); + } return (false); } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: allowing update of " "name=%s by %s", name, signer); + } return (true); } @@ -665,11 +706,12 @@ modrdataset(struct dlz_example_data *state, const char *name, isc_result_t result; #if defined(WIN32) || defined(_REENTRANT) char *saveptr = NULL; -#endif +#endif /* if defined(WIN32) || defined(_REENTRANT) */ buf = strdup(rdatastr); - if (buf == NULL) + if (buf == NULL) { return (ISC_R_FAILURE); + } /* * The format is: @@ -680,24 +722,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); @@ -720,12 +767,14 @@ 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); + } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: adding rdataset %s '%s'", name, rdatastr); + } return (modrdataset(state, name, rdatastr, &state->adds[0])); } @@ -736,14 +785,16 @@ 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); + } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: subtracting rdataset " "%s '%s'", name, rdatastr); + } return (modrdataset(state, name, rdatastr, &state->deletes[0])); } @@ -753,14 +804,16 @@ 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); + } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_example: deleting rdataset %s " "of type %s", name, type); + } return (ISC_R_SUCCESS); } diff --git a/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c b/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c index 9f1f24fc84..a792517538 100644 --- a/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c +++ b/contrib/dlz/modules/bdbhpt/dlz_bdbhpt_dynamic.c @@ -114,14 +114,15 @@ bdbhpt_strrev(char *str) { char *p1, *p2; - if (!str || !*str) - return str; + if (!str || !*str) { + return (str); + } for (p1 = str, p2 = str + strlen(str) - 1; p2 > p1; ++p1, --p2) { *p1 ^= *p2; *p2 ^= *p1; *p1 ^= *p2; } - return str; + return (str); } /*% @@ -166,11 +167,13 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) /* find space after replication id */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to host */ pd->host = tmp; @@ -178,13 +181,15 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) /* find space after host and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to ttl string */ ttlStr = tmp; @@ -192,13 +197,15 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) /* find space after ttl and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to dns type */ pd->type = tmp; @@ -206,13 +213,15 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) /* find space after type and change it to a '\0' */ tmp = strchr(tmp, ' '); /* verify we found a space */ - if (tmp == NULL) - return ISC_R_FAILURE; + if (tmp == NULL) { + return (ISC_R_FAILURE); + } /* change the space to a null (string terminator) */ tmp[0] = '\0'; /* make sure it is safe to increment pointer */ - if (++tmp > lastchar) - return ISC_R_FAILURE; + if (++tmp > lastchar) { + return (ISC_R_FAILURE); + } /* save pointer to remainder of DNS data */ pd->data = tmp; @@ -222,11 +231,11 @@ bdbhpt_parse_data(log_t *log, char *in, bdbhpt_parsed_data_t *pd) if (*endp != '\0' || pd->ttl < 0) { log(ISC_LOG_ERROR, "bdbhpt_dynamic: " "ttl must be a positive number"); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* if we get this far everything should have worked. */ - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /* @@ -242,11 +251,12 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) /* check to see if we are authoritative for the zone first. */ #if DLZ_DLOPEN_VERSION >= 3 result = dlz_findzonedb(dbdata, name, NULL, NULL); -#else +#else /* if DLZ_DLOPEN_VERSION >= 3 */ result = dlz_findzonedb(dbdata, name); -#endif - if (result != ISC_R_SUCCESS) +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } memset(&key, 0, sizeof(DBT)); key.flags = DB_DBT_MALLOC; @@ -279,14 +289,16 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) xfr_cleanup: /* free any memory duplicate string in the key field */ - if (key.data != NULL) + if (key.data != NULL) { free(key.data); + } /* free any memory allocated to the data field. */ - if (data.data != NULL) + if (data.data != NULL) { free(data.data); + } - return result; + return (result); } /*% @@ -336,8 +348,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) memset(&dns_data, 0, sizeof(DBT)); xfr_key.data = tmp_zone = strdup(zone); - if (xfr_key.data == NULL) + if (xfr_key.data == NULL) { return (ISC_R_NOMEMORY); + } xfr_key.size = strlen(xfr_key.data); @@ -365,8 +378,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) /* +1 to allow for null term at end of string. */ dns_key.data = tmp_zone_host = malloc(dns_key.size + 1); - if (dns_key.data == NULL) + if (dns_key.data == NULL) { goto allnodes_cleanup; + } /* * construct search key for dns_data. @@ -385,8 +399,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) /* +1 to allow for null term at end of string. */ tmp = realloc(tmp, dns_data.size + 1); - if (tmp == NULL) + if (tmp == NULL) { goto allnodes_cleanup; + } /* copy data to tmp string, and append null term. */ strncpy(tmp, dns_data.data, dns_data.size); @@ -394,13 +409,14 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) /* split string into dns data parts. */ if (bdbhpt_parse_data(db->log, tmp, &pd) != - ISC_R_SUCCESS) + ISC_R_SUCCESS) { goto allnodes_cleanup; + } result = db->putnamedrr(allnodes, pd.host, pd.type, pd.ttl, pd.data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto allnodes_cleanup; - + } } /* end inner while loop */ /* clean up memory */ @@ -412,23 +428,28 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) allnodes_cleanup: /* free any memory */ - if (tmp != NULL) + if (tmp != NULL) { free(tmp); + } - if (tmp_zone_host != NULL) + if (tmp_zone_host != NULL) { free(tmp_zone_host); + } - if (tmp_zone != NULL) + if (tmp_zone != NULL) { free(tmp_zone); + } /* get rid of cursors */ - if (xfr_cursor != NULL) + if (xfr_cursor != NULL) { xfr_cursor->c_close(xfr_cursor); + } - if (dns_cursor != NULL) + if (dns_cursor != NULL) { dns_cursor->c_close(dns_cursor); + } - return result; + return (result); } /*% @@ -440,18 +461,23 @@ static void bdbhpt_cleanup(bdbhpt_instance_t *db) { /* close databases */ - if (db->data != NULL) + if (db->data != NULL) { db->data->close(db->data, 0); - if (db->xfr != NULL) + } + if (db->xfr != NULL) { db->xfr->close(db->xfr, 0); - if (db->zone != NULL) + } + if (db->zone != NULL) { db->zone->close(db->zone, 0); - if (db->client != NULL) + } + if (db->client != NULL) { db->client->close(db->client, 0); + } /* close environment */ - if (db->dbenv != NULL) + if (db->dbenv != NULL) { db->dbenv->close(db->dbenv, 0); + } } /* @@ -460,11 +486,11 @@ bdbhpt_cleanup(bdbhpt_instance_t *db) #if DLZ_DLOPEN_VERSION < 3 isc_result_t dlz_findzonedb(void *dbdata, const char *name) -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ { isc_result_t result; bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata; @@ -477,12 +503,13 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, #if DLZ_DLOPEN_VERSION >= 3 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ key.data = strdup(name); - if (key.data == NULL) + if (key.data == NULL) { return (ISC_R_NOMEMORY); + } /* * reverse string to take advantage of BDB locality of reference @@ -504,14 +531,16 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, } /* free any memory duplicate string in the key field */ - if (key.data != NULL) + if (key.data != NULL) { free(key.data); + } /* free any memory allocated to the data field. */ - if (data.data != NULL) + if (data.data != NULL) { free(data.data); + } - return result; + return (result); } /* @@ -522,12 +551,12 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup) -#else +#else /* if DLZ_DLOPEN_VERSION == 1 */ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION == 1 */ { isc_result_t result = ISC_R_NOTFOUND; bdbhpt_instance_t *db = (bdbhpt_instance_t *)dbdata; @@ -543,7 +572,7 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, #if DLZ_DLOPEN_VERSION >= 2 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 2 */ memset(&key, 0, sizeof(DBT)); memset(&data, 0, sizeof(DBT)); @@ -553,8 +582,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, /* allocate mem for key */ key.data = keyStr = malloc((key.size + 1) * sizeof(char)); - if (keyStr == NULL) - return ISC_R_NOMEMORY; + if (keyStr == NULL) { + return (ISC_R_NOMEMORY); + } strcpy(keyStr, zone); strcat(keyStr, " "); @@ -573,30 +603,35 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, flags)) == 0) { flags = DB_NEXT_DUP; tmp = realloc(tmp, data.size + 1); - if (tmp == NULL) + if (tmp == NULL) { goto lookup_cleanup; + } strncpy(tmp, data.data, data.size); tmp[data.size] = '\0'; - if (bdbhpt_parse_data(db->log, tmp, &pd) != ISC_R_SUCCESS) + if (bdbhpt_parse_data(db->log, tmp, &pd) != ISC_R_SUCCESS) { goto lookup_cleanup; + } result = db->putrr(lookup, pd.type, pd.ttl, pd.data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto lookup_cleanup; + } } /* end while loop */ lookup_cleanup: /* get rid of cursor */ - if (data_cursor != NULL) + if (data_cursor != NULL) { data_cursor->c_close(data_cursor); + } free(keyStr); - if (tmp != NULL) + if (tmp != NULL) { free(tmp); + } - return result; + return (result); } /*% @@ -614,7 +649,7 @@ bdbhpt_opendb(log_t *log, DB_ENV *db_env, DBTYPE db_type, DB **db, "bdbhpt_dynamic: could not initialize %s database. " "BerkeleyDB error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* set database flags. */ @@ -623,7 +658,7 @@ bdbhpt_opendb(log_t *log, DB_ENV *db_env, DBTYPE db_type, DB **db, "bdbhpt_dynamic: could not set flags for %s database. " "BerkeleyDB error: %s", db_name, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } /* open the database. */ @@ -633,10 +668,10 @@ bdbhpt_opendb(log_t *log, DB_ENV *db_env, DBTYPE db_type, DB **db, "bdbhpt_dynamic: could not open %s database in %s. " "BerkeleyDB error: %s", db_name, db_file, db_strerror(result)); - return ISC_R_FAILURE; + return (ISC_R_FAILURE); } - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } /* @@ -658,13 +693,15 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* Allocate memory for our db structures and helper functions */ db = calloc(1, sizeof(struct bdbhpt_instance)); - if (db == NULL) + if (db == NULL) { return (ISC_R_NOMEMORY); + } /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(db, helper_name, va_arg(ap, void *)); + } va_end(ap); /* verify we have 4 arg's passed to the driver */ @@ -677,9 +714,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, } switch ((char)*argv[1]) { - /* - * Transactional mode. Highest safety - lowest speed. - */ + /* + * Transactional mode. Highest safety - lowest speed. + */ case 'T': case 't': bdbFlags = DB_INIT_MPOOL | DB_INIT_LOCK | DB_INIT_LOG | @@ -688,20 +725,20 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, "mode."); break; - /* - * Concurrent mode. Lower safety (no rollback) - - * higher speed. - */ + /* + * Concurrent mode. Lower safety (no rollback) - + * higher speed. + */ case 'C': case 'c': bdbFlags = DB_INIT_CDB | DB_INIT_MPOOL; db->log(ISC_LOG_INFO, "bdbhpt_dynamic: using concurrent mode."); break; - /* - * Private mode. No inter-process communication & no locking. - * Lowest saftey - highest speed. - */ + /* + * Private mode. No inter-process communication & no locking. + * Lowest saftey - highest speed. + */ case 'P': case 'p': bdbFlags = DB_PRIVATE | DB_INIT_MPOOL; @@ -746,26 +783,30 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* open dlz_data database. */ result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->data, dlz_data, argv[3], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_xfr database. */ result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->xfr, dlz_xfr, argv[3], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_zone database. */ result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->zone, dlz_zone, argv[3], 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } /* open dlz_client database. */ result = bdbhpt_opendb(db->log, db->dbenv, DB_UNKNOWN, &db->client, dlz_client, argv[3], DB_DUP | DB_DUPSORT); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto init_cleanup; + } *dbdata = db; @@ -775,7 +816,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, init_cleanup: bdbhpt_cleanup(db); - return result; + return (result); } /* @@ -808,12 +849,16 @@ dlz_version(unsigned int *flags) static void b9_add_helper(struct bdbhpt_instance *db, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { db->log = (log_t *)ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { db->putrr = (dns_sdlz_putrr_t *)ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { db->writeable_zone = (dns_dlz_writeablezone_t *)ptr; + } } diff --git a/contrib/dlz/modules/common/dlz_dbi.c b/contrib/dlz/modules/common/dlz_dbi.c index fa0f573ba5..0bace2381c 100644 --- a/contrib/dlz/modules/common/dlz_dbi.c +++ b/contrib/dlz/modules/common/dlz_dbi.c @@ -67,8 +67,9 @@ destroy_querylist(query_list_t **querylist) query_segment_t *nseg = NULL; /* if query list is null, nothing to do */ - if (*querylist == NULL) + if (*querylist == NULL) { return; + } /* start at the top of the list */ nseg = DLZ_LIST_HEAD(**querylist); @@ -79,8 +80,9 @@ destroy_querylist(query_list_t **querylist) * was really a query segment, and not a pointer to * %zone%, or %record%, or %client% */ - if (tseg->cmd != NULL && tseg->direct == true) + if (tseg->cmd != NULL && tseg->direct == true) { free(tseg->cmd); + } /* get the next query segment, before we destroy this one. */ nseg = DLZ_LIST_NEXT(nseg, link); /* deallocate this query segment. */ @@ -108,19 +110,21 @@ build_querylist(const char *query_str, char **zone, char **record, /* if query string is null, or zero length */ if (query_str == NULL || strlen(query_str) < 1) { - if ((flags & REQUIRE_QUERY) == 0) + if ((flags & REQUIRE_QUERY) == 0) { /* we don't need it were ok. */ return (ISC_R_SUCCESS); - else + } else { /* we did need it, PROBLEM!!! */ return (ISC_R_FAILURE); + } } /* allocate memory for query list */ tql = calloc(1, sizeof(query_list_t)); /* couldn't allocate memory. Problem!! */ - if (tql == NULL) + if (tql == NULL) { return (ISC_R_NOMEMORY); + } /* initialize the query segment list */ DLZ_LIST_INIT(*tql); @@ -215,9 +219,10 @@ build_querylist(const char *query_str, char **zone, char **record, /* if this query requires %client%, make sure we found it */ if (((flags & REQUIRE_CLIENT) != 0) && (!foundclient)) { /* Write error message to log */ - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Required token $client$ not " "found."); + } result = ISC_R_FAILURE; goto flag_fail; } @@ -225,9 +230,10 @@ build_querylist(const char *query_str, char **zone, char **record, /* if this query requires %record%, make sure we found it */ if (((flags & REQUIRE_RECORD) != 0) && (!foundrecord)) { /* Write error message to log */ - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Required token $record$ not " "found."); + } result = ISC_R_FAILURE; goto flag_fail; } @@ -235,8 +241,9 @@ build_querylist(const char *query_str, char **zone, char **record, /* if this query requires %zone%, make sure we found it */ if (((flags & REQUIRE_ZONE) != 0) && (!foundzone)) { /* Write error message to log */ - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Required token $zone$ not found."); + } result = ISC_R_FAILURE; goto flag_fail; } @@ -278,28 +285,31 @@ build_querystring(query_list_t *querylist) * if this is a query segment, use the * precalculated string length */ - if (tseg->direct == true) + if (tseg->direct == true) { length += tseg->strlen; - else /* calculate string length for dynamic segments. */ + } else { /* calculate string length for dynamic segments. */ length += strlen(*(char **)tseg->cmd); + } /* get the next segment */ tseg = DLZ_LIST_NEXT(tseg, link); } qs = malloc(length + 1); - if (qs == NULL) + if (qs == NULL) { return (NULL); + } *qs = '\0'; /* start at the top of the list again */ tseg = DLZ_LIST_HEAD(*querylist); while (tseg != NULL) { - if (tseg->direct == true) + if (tseg->direct == true) { /* query segments */ strcat(qs, tseg->cmd); - else + } else { /* dynamic segments */ strcat(qs, *(char **)tseg->cmd); + } /* get the next segment */ tseg = DLZ_LIST_NEXT(tseg, link); } @@ -321,9 +331,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, /* allocate and zero memory for driver structure */ db = calloc(1, sizeof(dbinstance_t)); if (db == NULL) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not allocate memory for " "database instance object."); + } return (ISC_R_NOMEMORY); } memset(db, 0, sizeof(dbinstance_t)); @@ -355,9 +366,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not build all nodes query " "list"); + } goto cleanup; } @@ -367,9 +379,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, REQUIRE_ZONE | REQUIRE_CLIENT, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not build allow xfr query " "list"); + } goto cleanup; } @@ -379,9 +392,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not build authority query " "list"); + } goto cleanup; } @@ -391,9 +405,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not build find zone query " "list"); + } goto cleanup; } @@ -403,9 +418,10 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not build count zone query " "list"); + } goto cleanup; } @@ -415,8 +431,9 @@ build_dbinstance(const char *allnodes_str, const char *allowxfr_str, log); /* if unsuccessful, log err msg and cleanup */ if (result != ISC_R_SUCCESS) { - if (log != NULL) + if (log != NULL) { log(ISC_LOG_ERROR, "Could not build lookup query list"); + } goto cleanup; } @@ -459,18 +476,21 @@ get_parameter_value(const char *input, const char *key) char value[255]; int i; - if (key == NULL || input == NULL || *input == '\0') + if (key == NULL || input == NULL || *input == '\0') { return (NULL); + } keylen = strlen(key); - if (keylen < 1) + if (keylen < 1) { return (NULL); + } keystart = strstr(input, key); - if (keystart == NULL) + if (keystart == NULL) { return (NULL); + } for (i = 0; i < 255; i++) { value[i] = keystart[keylen + i]; diff --git a/contrib/dlz/modules/filesystem/dir.c b/contrib/dlz/modules/filesystem/dir.c index dbec24edfe..668ff95417 100644 --- a/contrib/dlz/modules/filesystem/dir.c +++ b/contrib/dlz/modules/filesystem/dir.c @@ -41,13 +41,15 @@ dir_open(dir_t *dir, const char *dirname) char * p; isc_result_t result = ISC_R_SUCCESS; - if (strlen(dirname) + 3 > sizeof(dir->dirname)) + if (strlen(dirname) + 3 > sizeof(dir->dirname)) { return (ISC_R_NOSPACE); + } strcpy(dir->dirname, dirname); p = dir->dirname + strlen(dir->dirname); - if (dir->dirname < p && *(p - 1) != '/') + if (dir->dirname < p && *(p - 1) != '/') { *p++ = '/'; + } *p++ = '*'; *p = '\0'; @@ -82,7 +84,7 @@ dir_open(dir_t *dir, const char *dirname) /*! * \brief Return previously retrieved file or get next one. - + * * Unix's dirent has * separate open and read functions, but the Win32 and DOS interfaces open * the dir stream and reads the first file in one operation. @@ -93,11 +95,13 @@ dir_read(dir_t *dir) struct dirent *entry; entry = readdir(dir->handle); - if (entry == NULL) + if (entry == NULL) { return (ISC_R_NOMORE); + } - if (sizeof(dir->entry.name) <= strlen(entry->d_name)) + if (sizeof(dir->entry.name) <= strlen(entry->d_name)) { return (ISC_R_UNEXPECTED); + } strcpy(dir->entry.name, entry->d_name); diff --git a/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c b/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c index a002d99176..40aef3eb0c 100644 --- a/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c +++ b/contrib/dlz/modules/filesystem/dlz_filesystem_dynamic.c @@ -105,44 +105,53 @@ is_safe(const char *input) /* '.' is allowed, but has special requirements */ if (input[i] == '.') { /* '.' is not allowed as first char */ - if (i == 0) + if (i == 0) { return (false); + } /* '..', two dots together is not allowed. */ - if (input[i - 1] == '.') + if (input[i - 1] == '.') { return (false); + } /* '.' is not allowed as last char */ - if (i == len - 1) + if (i == len - 1) { return (false); + } /* only 1 dot in ok location, continue at next char */ continue; } /* '-' is allowed, continue at next char */ - if (input[i] == '-') + if (input[i] == '-') { continue; + } /* 0-9 is allowed, continue at next char */ - if (input[i] >= '0' && input[i] <= '9') + if (input[i] >= '0' && input[i] <= '9') { continue; + } /* A-Z uppercase is allowed, continue at next char */ - if (input[i] >= 'A' && input[i] <= 'Z') + if (input[i] >= 'A' && input[i] <= 'Z') { continue; + } /* a-z lowercase is allowed, continue at next char */ - if (input[i] >= 'a' && input[i] <= 'z') + if (input[i] >= 'a' && input[i] <= 'z') { continue; + } /* * colon needs to be allowed for IPV6 client * addresses. Not dangerous in domain names, as not a * special char. */ - if (input[i] == ':') + if (input[i] == ':') { continue; + } /* * '@' needs to be allowed for in zone data. Not * dangerous in domain names, as not a special char. */ - if (input[i] == '@') + if (input[i] == '@') { continue; + } /* * if we reach this point we have encountered a @@ -162,8 +171,9 @@ create_path_helper(char *out, const char *in, config_data_t *cd) int i; tmpString = strdup(in); - if (tmpString == NULL) + if (tmpString == NULL) { return (ISC_R_NOMEMORY); + } /* * don't forget is_safe guarantees '.' will NOT be the @@ -172,17 +182,20 @@ create_path_helper(char *out, const char *in, config_data_t *cd) while ((tmpPtr = strrchr(tmpString, '.')) != NULL) { i = 0; while (tmpPtr[i + 1] != '\0') { - if (cd->splitcnt < 1) + if (cd->splitcnt < 1) { strcat(out, (char *)&tmpPtr[i + 1]); - else + } else { strncat(out, (char *)&tmpPtr[i + 1], cd->splitcnt); + } strncat(out, (char *)&cd->pathsep, 1); - if (cd->splitcnt == 0) + if (cd->splitcnt == 0) { break; + } if (strlen((char *)&tmpPtr[i + 1]) <= - (unsigned int)cd->splitcnt) + (unsigned int)cd->splitcnt) { break; + } i += cd->splitcnt; } tmpPtr[0] = '\0'; @@ -192,15 +205,18 @@ create_path_helper(char *out, const char *in, config_data_t *cd) i = 0; tmpPtr = tmpString; while (tmpPtr[i] != '\0') { - if (cd->splitcnt < 1) + if (cd->splitcnt < 1) { strcat(out, (char *)&tmpPtr[i]); - else + } else { strncat(out, (char *)&tmpPtr[i], cd->splitcnt); + } strncat(out, (char *)&cd->pathsep, 1); - if (cd->splitcnt == 0) + if (cd->splitcnt == 0) { break; - if (strlen((char *)&tmpPtr[i]) <= (unsigned int)cd->splitcnt) + } + if (strlen((char *)&tmpPtr[i]) <= (unsigned int)cd->splitcnt) { break; + } i += cd->splitcnt; } @@ -225,28 +241,33 @@ create_path(const char *zone, const char *host, const char *client, bool isroot = false; /* special case for root zone */ - if (strcmp(zone, ".") == 0) + if (strcmp(zone, ".") == 0) { isroot = true; + } /* if the requested zone is "unsafe", return error */ - if (!isroot && !is_safe(zone)) + if (!isroot && !is_safe(zone)) { return (ISC_R_FAILURE); + } /* if host was passed, verify that it is safe */ - if (host != NULL && !is_safe(host)) + if (host != NULL && !is_safe(host)) { return (ISC_R_FAILURE); + } /* if client was passed, verify that it is safe */ - if (client != NULL && !is_safe(client)) + if (client != NULL && !is_safe(client)) { return (ISC_R_FAILURE); + } /* Determine how much memory the split up string will require */ - if (host != NULL) + if (host != NULL) { len = strlen(zone) + strlen(host); - else if (client != NULL) + } else if (client != NULL) { len = strlen(zone) + strlen(client); - else + } else { len = strlen(zone); + } /* * even though datadir and xfrdir will never be in the same @@ -256,8 +277,9 @@ create_path(const char *zone, const char *host, const char *client, pathsize = len + cd->basedirsize + cd->datadirsize + cd->xfrdirsize + 4; /* if we are splitting names, we will need extra space. */ - if (cd->splitcnt > 0) + if (cd->splitcnt > 0) { pathsize += len / cd->splitcnt; + } tmpPath = malloc(pathsize * sizeof(char)); if (tmpPath == NULL) { @@ -277,8 +299,9 @@ create_path(const char *zone, const char *host, const char *client, /* add zone name - parsed properly */ if (!isroot) { result = create_path_helper(tmpPath, zone, cd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_mem; + } } /* @@ -306,15 +329,17 @@ create_path(const char *zone, const char *host, const char *client, strcat(tmpPath, cd->xfrdir); strncat(tmpPath, (char *)&cd->pathsep, 1); strcat(tmpPath, client); - } else + } else { strcat(tmpPath, cd->datadir); + } /* if host not null, add it. */ if (host != NULL) { strncat(tmpPath, (char *)&cd->pathsep, 1); result = create_path_helper(tmpPath, host, cd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_mem; + } } /* return the path we built. */ @@ -327,8 +352,9 @@ cleanup_mem: /* cleanup memory */ /* free tmpPath memory */ - if (tmpPath != NULL && result != ISC_R_SUCCESS) + if (tmpPath != NULL && result != ISC_R_SUCCESS) { free(tmpPath); + } return (result); } @@ -383,15 +409,17 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, cd->pathsep)) != NULL) { if ((strlen(host) + strlen(tmpPtr + 1) + 2) > - DIR_NAMEMAX) + DIR_NAMEMAX) { continue; + } strcat(host, tmpPtr + 1); strcat(host, "."); tmpPtr[0] = '\0'; } if ((strlen(host) + strlen(tmpString) + - 1) <= DIR_NAMEMAX) + 1) <= DIR_NAMEMAX) { strcat(host, tmpString); + } } foundHost = true; @@ -411,9 +439,9 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, * wildcard "-" */ if (strcmp((char *)&dir->entry.name[6], - "-") == 0) + "-") == 0) { strcpy(host, "*"); - else { + } else { strncpy(host, (char *)&dir->entry .name[6], @@ -436,8 +464,9 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, dir->dirname, dir->entry.name); /* skip any entries starting with "." */ - if (dir->entry.name[0] == '.') + if (dir->entry.name[0] == '.') { continue; + } /* * get rid of '*', set to NULL. Effectively trims @@ -461,8 +490,9 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, */ if (dir_list != NULL) { direntry = malloc(sizeof(dir_entry_t)); - if (direntry == NULL) + if (direntry == NULL) { return (ISC_R_NOMEMORY); + } strcpy(direntry->dirpath, tmp); DLZ_LINK_INIT(direntry, link); DLZ_LIST_APPEND(*dir_list, direntry, @@ -477,12 +507,12 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, * are performing a zone xfr and we * could not find a host entry. */ - } else if (dir_list != NULL && foundHost == false) { continue; } - } else /* if we cannot stat entry, skip it. */ + } else { /* if we cannot stat entry, skip it. */ continue; + } type = dir->entry.name; ttlStr = strchr(type, cd->separator); @@ -518,27 +548,31 @@ process_dir(dir_t *dir, void *passback, config_data_t *cd, dlist_t *dir_list, len = strlen(data); for (i = 0; i < len; i++) { - if (data[i] == cd->separator) + if (data[i] == cd->separator) { data[i] = ' '; + } } /* convert text to int, make sure it worked right */ ttl = strtol(ttlStr, &endp, 10); - if (*endp != '\0' || ttl < 0) + if (*endp != '\0' || ttl < 0) { cd->log(ISC_LOG_ERROR, "Filesystem driver " "ttl must be a postive number"); + } /* pass data back to Bind */ - if (dir_list == NULL) + if (dir_list == NULL) { result = cd->putrr((dns_sdlzlookup_t *)passback, type, ttl, data); - else + } else { result = cd->putnamedrr((dns_sdlzallnodes_t *)passback, (char *)host, type, ttl, data); + } /* if error, return error right away */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } /* end of while loop */ return (result); @@ -641,8 +675,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) /* close the directory */ dir_close(&dir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto complete_allnds; + } /* get first dir entry from list. */ dir_entry = DLZ_LIST_HEAD(*dir_list); @@ -664,8 +699,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) /* close the directory */ dir_close(&dir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto complete_allnds; + } dir_entry = DLZ_LIST_NEXT(dir_entry, link); } /* end while */ @@ -682,8 +718,9 @@ complete_allnds: free(dir_list); } - if (basepath != NULL) + if (basepath != NULL) { free(basepath); + } return (result); } @@ -691,11 +728,11 @@ complete_allnds: #if DLZ_DLOPEN_VERSION < 3 isc_result_t dlz_findzonedb(void *dbdata, const char *name) -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ { isc_result_t result; config_data_t *cd = (config_data_t *)dbdata; @@ -706,10 +743,11 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, #if DLZ_DLOPEN_VERSION >= 3 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ - if (create_path(name, NULL, NULL, cd, &path) != ISC_R_SUCCESS) + if (create_path(name, NULL, NULL, cd, &path) != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } cd->log(ISC_LOG_DEBUG(1), "Filesystem driver Findzone() Checking for path: '%s'\n", path); @@ -736,12 +774,12 @@ complete_FZ: isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup) -#else +#else /* if DLZ_DLOPEN_VERSION == 1 */ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION == 1 */ { isc_result_t result = ISC_R_NOTFOUND; config_data_t *cd = (config_data_t *)dbdata; @@ -754,18 +792,20 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, #if DLZ_DLOPEN_VERSION >= 2 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 2 */ - if (strcmp(name, "*") == 0) + if (strcmp(name, "*") == 0) { /* * handle filesystem's special wildcard "-" */ result = create_path(zone, "-", NULL, cd, &path); - else + } else { result = create_path(zone, name, NULL, cd, &path); + } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } /* remove path separator at end of path so stat works properly */ path[strlen(path) - 1] = '\0'; @@ -823,16 +863,18 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* allocate memory for our config data and helper functions */ cd = calloc(1, sizeof(config_data_t)); - if (cd == NULL) + if (cd == NULL) { goto no_mem; + } /* zero the memory */ memset(cd, 0, sizeof(config_data_t)); /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(cd, helper_name, va_arg(ap, void *)); + } va_end(ap); /* we require 5 command line args. */ @@ -863,36 +905,41 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, } /* determine and save path separator for later */ - if (argv[1][len - 1] == '\\') + if (argv[1][len - 1] == '\\') { pathsep = '\\'; - else + } else { pathsep = '/'; + } cd->pathsep = pathsep; /* get and store our base directory */ cd->basedir = strdup(argv[1]); - if (cd->basedir == NULL) + if (cd->basedir == NULL) { goto no_mem; + } cd->basedirsize = strlen(cd->basedir); /* get and store our data sub-dir */ cd->datadir = strdup(argv[2]); - if (cd->datadir == NULL) + if (cd->datadir == NULL) { goto no_mem; + } cd->datadirsize = strlen(cd->datadir); /* get and store our zone xfr sub-dir */ cd->xfrdir = strdup(argv[3]); - if (cd->xfrdir == NULL) + if (cd->xfrdir == NULL) { goto no_mem; + } cd->xfrdirsize = strlen(cd->xfrdir); /* get and store our directory split count */ cd->splitcnt = strtol(argv[4], &endp, 10); - if (*endp != '\0' || cd->splitcnt < 0) + if (*endp != '\0' || cd->splitcnt < 0) { cd->log(ISC_LOG_ERROR, "Directory split count must be zero (0) " "or a postive number"); + } /* get and store our separator character */ cd->separator = *argv[5]; @@ -907,15 +954,17 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, no_mem: /* write error message */ - if (cd != NULL && cd->log != NULL) + if (cd != NULL && cd->log != NULL) { cd->log(ISC_LOG_ERROR, "filesystem_dynamic: Filesystem driver " "unable to " "allocate memory for config data."); + } free_cd: /* if we allocated a config data object clean it up */ - if (cd != NULL) + if (cd != NULL) { dlz_destroy(cd); + } /* return error */ return (result); @@ -932,14 +981,17 @@ dlz_destroy(void *dbdata) * free memory for each section of config data that was * allocated */ - if (cd->basedir != NULL) + if (cd->basedir != NULL) { free(cd->basedir); + } - if (cd->datadir != NULL) + if (cd->datadir != NULL) { free(cd->datadir); + } - if (cd->xfrdir != NULL) + if (cd->xfrdir != NULL) { free(cd->xfrdir); + } /* free config data memory */ free(cd); @@ -961,12 +1013,16 @@ dlz_version(unsigned int *flags) static void b9_add_helper(struct config_data *cd, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { cd->log = (log_t *)ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { cd->putrr = (dns_sdlz_putrr_t *)ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { cd->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { cd->writeable_zone = (dns_dlz_writeablezone_t *)ptr; + } } diff --git a/contrib/dlz/modules/include/dlz_minimal.h b/contrib/dlz/modules/include/dlz_minimal.h index 415500f064..befea12bad 100644 --- a/contrib/dlz/modules/include/dlz_minimal.h +++ b/contrib/dlz/modules/include/dlz_minimal.h @@ -33,7 +33,7 @@ #include #ifdef ISC_PLATFORM_HAVESYSUNH #include -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ #include #include #include @@ -48,7 +48,7 @@ typedef uint32_t dns_ttl_t; #ifndef DLZ_DLOPEN_VERSION #define DLZ_DLOPEN_VERSION 3 #define DLZ_DLOPEN_AGE 0 -#endif +#endif /* ifndef DLZ_DLOPEN_VERSION */ /* return these in flags from dlz_version() */ #define DNS_SDLZFLAG_THREADSAFE 0x00000001U @@ -106,7 +106,7 @@ typedef struct isc_sockaddr { struct sockaddr_in6 sin6; #ifdef ISC_PLATFORM_HAVESYSUNH struct sockaddr_un sunix; -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } type; unsigned int length; void * link; diff --git a/contrib/dlz/modules/include/dlz_pthread.h b/contrib/dlz/modules/include/dlz_pthread.h index 90d143e5e1..75102774fd 100644 --- a/contrib/dlz/modules/include/dlz_pthread.h +++ b/contrib/dlz/modules/include/dlz_pthread.h @@ -19,7 +19,7 @@ #ifndef PTHREADS #define PTHREADS 1 -#endif +#endif /* ifndef PTHREADS */ #ifdef PTHREADS #include @@ -36,6 +36,6 @@ #define dlz_mutex_lock(a) (0) #define dlz_mutex_trylock(a) (0) #define dlz_mutex_unlock(a) (0) -#endif +#endif /* ifdef PTHREADS */ #endif /* DLZ_PTHREAD_H */ diff --git a/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c b/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c index 6e58dd6f38..048a4e97ab 100644 --- a/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c +++ b/contrib/dlz/modules/ldap/dlz_ldap_dynamic.c @@ -86,14 +86,17 @@ typedef struct { #if PTHREADS db_list_t *db; /*%< handle to a list of DB */ -#else +#else /* if PTHREADS */ dbinstance_t *db; /*%< handle to db */ -#endif - int method; /*%< security authentication method */ - char *user; /*%< who is authenticating */ - char *cred; /*%< password for simple authentication method */ - int protocol; /*%< LDAP communication protocol version */ - char *hosts; /*%< LDAP server hosts */ +#endif /* if PTHREADS */ + int method; /*%< security authentication + * method */ + char *user; /*%< who is authenticating */ + char *cred; /*%< password for simple + * authentication method */ + int protocol; /*%< LDAP communication + * protocol version */ + char *hosts; /*%< LDAP server hosts */ /* Helper functions from the dlz_dlopen driver */ log_t * log; @@ -107,11 +110,11 @@ typedef struct { #if DLZ_DLOPEN_VERSION < 3 isc_result_t dlz_findzonedb(void *dbdata, const char *name); -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ void dlz_destroy(void *dbdata); @@ -182,8 +185,9 @@ ldap_checkURL(ldap_instance_t *db, char *URL, int attrCnt, const char *msg) } cleanup: - if (ldap_url != NULL) + if (ldap_url != NULL) { ldap_free_urldesc(ldap_url); + } return (result); } @@ -205,8 +209,9 @@ ldap_connect(ldap_instance_t *dbi, dbinstance_t *dbc) /* initialize. */ dbc->dbconn = ldap_init(dbi->hosts, LDAP_PORT); - if (dbc->dbconn == NULL) + if (dbc->dbconn == NULL) { return (ISC_R_NOMEMORY); + } /* set protocol version. */ ldap_result = ldap_set_option((LDAP *)dbc->dbconn, @@ -259,8 +264,9 @@ ldap_destroy_dblist(db_list_t *dblist) /* get the next DBI in the list */ ndbi = DLZ_LIST_NEXT(dbi, link); /* release DB connection */ - if (dbi->dbconn != NULL) + if (dbi->dbconn != NULL) { ldap_unbind_s((LDAP *)dbi->dbconn); + } /* release all memory that comprised a DBI */ destroy_dbinstance(dbi); } @@ -291,9 +297,9 @@ ldap_find_avail_conn(ldap_instance_t *ldap) /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ - if (dlz_mutex_trylock(&dbi->lock) == 0) + if (dlz_mutex_trylock(&dbi->lock) == 0) { return (dbi); /* success, return the DBI for use. */ - + } /* not successful, keep trying */ dbi = DLZ_LIST_NEXT(dbi, link); @@ -349,8 +355,9 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg, /* get the list of values for this attribute. */ vals = ldap_get_values(dbc, entry, attrs[j]); /* skip empty attributes. */ - if (vals == NULL || ldap_count_values(vals) < 1) + if (vals == NULL || ldap_count_values(vals) < 1) { continue; + } /* * we only use the first value. this driver * does not support multi-valued attributes. @@ -419,16 +426,17 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg, break; case 2: j++; - if (allnodes) + if (allnodes) { host = strdup(vals[0]); - else + } else { strcpy(data, vals[0]); + } break; case 3: j++; - if (allnodes) + if (allnodes) { strcpy(data, vals[0]); - else { + } else { strcat(data, " "); strcat(data, vals[0]); } @@ -463,25 +471,28 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg, if (allnodes && host != NULL) { dns_sdlzallnodes_t *an = (dns_sdlzallnodes_t *)ptr; - if (strcasecmp(host, "~") == 0) + if (strcasecmp(host, "~") == 0) { result = db->putnamedrr(an, "*", type, ttl, data); - else + } else { result = db->putnamedrr(an, host, type, ttl, data); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { db->log(ISC_LOG_ERROR, "ldap_dynamic: putnamedrr failed " "for \"%s %s %u %s\" (%d)", host, type, ttl, data, result); + } } else { dns_sdlzlookup_t *lookup = (dns_sdlzlookup_t *)ptr; result = db->putrr(lookup, type, ttl, data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { db->log(ISC_LOG_ERROR, "ldap_dynamic: putrr failed " "for \"%s %u %s\" (%s)", type, ttl, data, result); + } } if (result != ISC_R_SUCCESS) { @@ -508,14 +519,18 @@ ldap_process_results(ldap_instance_t *db, LDAP *dbc, LDAPMessage *msg, cleanup: /* de-allocate memory */ - if (vals != NULL) + if (vals != NULL) { ldap_value_free(vals); - if (host != NULL) + } + if (host != NULL) { free(host); - if (type != NULL) + } + if (type != NULL) { free(type); - if (data != NULL) + } + if (data != NULL) { free(data); + } return (result); } @@ -559,8 +574,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, #endif /* PTHREADS */ /* if DBI is null, can't do anything else */ - if (dbi == NULL) + if (dbi == NULL) { return (ISC_R_FAILURE); + } /* set fields */ if (zone != NULL) { @@ -569,8 +585,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->zone = NULL; + } if (record != NULL) { dbi->record = strdup(record); @@ -578,8 +595,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->record = NULL; + } if (client != NULL) { dbi->client = strdup(client); @@ -587,8 +605,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->client = NULL; + } /* what type of query are we going to run? */ switch (query) { @@ -602,24 +621,27 @@ ldap_get_results(const char *zone, const char *record, const char *client, if (dbi->allnodes_q == NULL) { result = ISC_R_NOTIMPLEMENTED; goto cleanup; - } else + } else { querystring = build_querystring(dbi->allnodes_q); + } break; case ALLOWXFR: /* same as comments as ALLNODES */ if (dbi->allowxfr_q == NULL) { result = ISC_R_NOTIMPLEMENTED; goto cleanup; - } else + } else { querystring = build_querystring(dbi->allowxfr_q); + } break; case AUTHORITY: /* same as comments as ALLNODES */ if (dbi->authority_q == NULL) { result = ISC_R_NOTIMPLEMENTED; goto cleanup; - } else + } else { querystring = build_querystring(dbi->authority_q); + } break; case FINDZONE: /* this is required. It's the whole point of DLZ! */ @@ -629,8 +651,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, "Findzone requires a query"); result = ISC_R_FAILURE; goto cleanup; - } else + } else { querystring = build_querystring(dbi->findzone_q); + } break; case LOOKUP: /* this is required. It's also a major point of DLZ! */ @@ -640,8 +663,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, "Lookup requires a query"); result = ISC_R_FAILURE; goto cleanup; - } else + } else { querystring = build_querystring(dbi->lookup_q); + } break; default: /* @@ -714,8 +738,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, db->log(ISC_LOG_INFO, "LDAP driver attempting to " "re-connect"); result = ldap_connect((ldap_instance_t *)dbdata, dbi); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } break; default: /* @@ -730,8 +755,9 @@ ldap_get_results(const char *zone, const char *record, const char *client, } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } switch (query) { case ALLNODES: @@ -745,21 +771,23 @@ ldap_get_results(const char *zone, const char *record, const char *client, break; case ALLOWXFR: entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg); - if (entries == 0) + if (entries == 0) { result = ISC_R_NOPERM; - else if (entries > 0) + } else if (entries > 0) { result = ISC_R_SUCCESS; - else + } else { result = ISC_R_FAILURE; + } break; case FINDZONE: entries = ldap_count_entries((LDAP *)dbi->dbconn, ldap_msg); - if (entries == 0) + if (entries == 0) { result = ISC_R_NOTFOUND; - else if (entries > 0) + } else if (entries > 0) { result = ISC_R_SUCCESS; - else + } else { result = ISC_R_FAILURE; + } break; default: /* @@ -775,27 +803,33 @@ cleanup: /* it's always good to cleanup after yourself */ /* if we retrieved results, free them */ - if (ldap_msg != NULL) + if (ldap_msg != NULL) { ldap_msgfree(ldap_msg); + } - if (ldap_url != NULL) + if (ldap_url != NULL) { ldap_free_urldesc(ldap_url); + } /* cleanup */ - if (dbi->zone != NULL) + if (dbi->zone != NULL) { free(dbi->zone); - if (dbi->record != NULL) + } + if (dbi->record != NULL) { free(dbi->record); - if (dbi->client != NULL) + } + if (dbi->client != NULL) { free(dbi->client); + } dbi->zone = dbi->record = dbi->client = NULL; /* release the lock so another thread can use this dbi */ (void)dlz_mutex_unlock(&dbi->lock); /* release query string */ - if (querystring != NULL) + if (querystring != NULL) { free(querystring); + } /* return result */ return (result); @@ -812,9 +846,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) /* check to see if we are authoritative for the zone first */ #if DLZ_DLOPEN_VERSION < 3 result = dlz_findzonedb(dbdata, name); -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ result = dlz_findzonedb(dbdata, name, NULL, NULL); -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ if (result != ISC_R_SUCCESS) { return (result); } @@ -839,16 +873,16 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) #if DLZ_DLOPEN_VERSION < 3 isc_result_t dlz_findzonedb(void *dbdata, const char *name) -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ { #if DLZ_DLOPEN_VERSION >= 3 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ return (ldap_get_results(name, NULL, NULL, FINDZONE, dbdata, NULL)); } @@ -856,26 +890,27 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup) -#else +#else /* if DLZ_DLOPEN_VERSION == 1 */ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION == 1 */ { isc_result_t result; #if DLZ_DLOPEN_VERSION >= 2 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 2 */ - if (strcmp(name, "*") == 0) + if (strcmp(name, "*") == 0) { result = ldap_get_results(zone, "~", NULL, LOOKUP, dbdata, lookup); - else + } else { result = ldap_get_results(zone, name, NULL, LOOKUP, dbdata, lookup); + } return (result); } @@ -900,14 +935,16 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* allocate memory for LDAP instance */ ldap = calloc(1, sizeof(ldap_instance_t)); - if (ldap == NULL) + if (ldap == NULL) { return (ISC_R_NOMEMORY); + } memset(ldap, 0, sizeof(ldap_instance_t)); /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(ldap, helper_name, va_arg(ap, void *)); + } va_end(ap); #if PTHREADS @@ -932,11 +969,11 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, } /* determine protocol version. */ - if (strncasecmp(argv[2], V2, strlen(V2)) == 0) + if (strncasecmp(argv[2], V2, strlen(V2)) == 0) { protocol = 2; - else if (strncasecmp(argv[2], V3, strlen(V3)) == 0) + } else if (strncasecmp(argv[2], V3, strlen(V3)) == 0) { protocol = 3; - else { + } else { ldap->log(ISC_LOG_ERROR, "LDAP driver protocol must be either %s or %s", V2, V3); @@ -944,13 +981,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, } /* determine connection method. */ - if (strncasecmp(argv[3], SIMPLE, strlen(SIMPLE)) == 0) + if (strncasecmp(argv[3], SIMPLE, strlen(SIMPLE)) == 0) { method = LDAP_AUTH_SIMPLE; - else if (strncasecmp(argv[3], KRB41, strlen(KRB41)) == 0) + } else if (strncasecmp(argv[3], KRB41, strlen(KRB41)) == 0) { method = LDAP_AUTH_KRBV41; - else if (strncasecmp(argv[3], KRB42, strlen(KRB42)) == 0) + } else if (strncasecmp(argv[3], KRB42, strlen(KRB42)) == 0) { method = LDAP_AUTH_KRBV42; - else { + } else { ldap->log(ISC_LOG_ERROR, "LDAP driver authentication method must be " "one of %s, %s or %s", @@ -968,32 +1005,37 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, "must be positive."); goto cleanup; } -#endif +#endif /* if PTHREADS */ /* check that LDAP URL parameters make sense */ switch (argc) { case 12: result = ldap_checkURL(ldap, argv[11], 0, "allow zone transfer"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } case 11: result = ldap_checkURL(ldap, argv[10], 3, "all nodes"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } case 10: if (strlen(argv[9]) > 0) { result = ldap_checkURL(ldap, argv[9], 3, "authority"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } case 9: result = ldap_checkURL(ldap, argv[8], 3, "lookup"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = ldap_checkURL(ldap, argv[7], 0, "find zone"); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } break; default: /* not really needed, should shut up compiler. */ @@ -1077,13 +1119,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* when multithreaded, build a list of DBI's */ DLZ_LINK_INIT(dbi, link); DLZ_LIST_APPEND(*(ldap->db), dbi, link); -#else +#else /* if PTHREADS */ /* * when single threaded, hold onto the one connection * instance. */ ldap->db = dbi; -#endif +#endif /* if PTHREADS */ /* attempt to connect */ result = ldap_connect(ldap, dbi); @@ -1092,50 +1134,50 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, * cleanup. */ switch (result) { - /* success, do nothing */ + /* success, do nothing */ case ISC_R_SUCCESS: break; - /* - * no memory means ldap_init could not - * allocate memory - */ + /* + * no memory means ldap_init could not + * allocate memory + */ case ISC_R_NOMEMORY: #if PTHREADS ldap->log(ISC_LOG_ERROR, "LDAP driver could not allocate memory " "for connection number %u", i + 1); -#else +#else /* if PTHREADS */ ldap->log(ISC_LOG_ERROR, "LDAP driver could not allocate " "memory " "for connection"); -#endif +#endif /* if PTHREADS */ goto cleanup; - /* - * no perm means ldap_set_option could not set - * protocol version - */ + /* + * no perm means ldap_set_option could not set + * protocol version + */ case ISC_R_NOPERM: ldap->log(ISC_LOG_ERROR, "LDAP driver could not " "set protocol version."); result = ISC_R_FAILURE; goto cleanup; - /* failure means couldn't connect to ldap server */ + /* failure means couldn't connect to ldap server */ case ISC_R_FAILURE: #if PTHREADS ldap->log(ISC_LOG_ERROR, "LDAP driver could not bind " "connection number %u to server.", i + 1); -#else +#else /* if PTHREADS */ ldap->log(ISC_LOG_ERROR, "LDAP driver could not " "bind connection to server."); -#endif +#endif /* if PTHREADS */ goto cleanup; - /* - * default should never happen. If it does, - * major errors. - */ + /* + * default should never happen. If it does, + * major errors. + */ default: ldap->log(ISC_LOG_ERROR, "dlz_create() failed (%d)", result); @@ -1167,22 +1209,27 @@ dlz_destroy(void *dbdata) ldap_instance_t *db = (ldap_instance_t *)dbdata; #if PTHREADS /* cleanup the list of DBI's */ - if (db->db != NULL) + if (db->db != NULL) { ldap_destroy_dblist((db_list_t *)(db->db)); + } #else /* PTHREADS */ - if (db->db->dbconn != NULL) + if (db->db->dbconn != NULL) { ldap_unbind_s((LDAP *)(db->db->dbconn)); + } /* destroy single DB instance */ destroy_dbinstance(db->db); #endif /* PTHREADS */ - if (db->hosts != NULL) + if (db->hosts != NULL) { free(db->hosts); - if (db->user != NULL) + } + if (db->user != NULL) { free(db->user); - if (db->cred != NULL) + } + if (db->cred != NULL) { free(db->cred); + } free(dbdata); } } @@ -1196,9 +1243,9 @@ dlz_version(unsigned int *flags) *flags |= DNS_SDLZFLAG_RELATIVERDATA; #if PTHREADS *flags |= DNS_SDLZFLAG_THREADSAFE; -#else +#else /* if PTHREADS */ *flags &= ~DNS_SDLZFLAG_THREADSAFE; -#endif +#endif /* if PTHREADS */ return (DLZ_DLOPEN_VERSION); } @@ -1208,12 +1255,16 @@ dlz_version(unsigned int *flags) static void b9_add_helper(ldap_instance_t *db, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { db->log = (log_t *)ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { db->putrr = (dns_sdlz_putrr_t *)ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { db->writeable_zone = (dns_dlz_writeablezone_t *)ptr; + } } diff --git a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c index 135d20ba79..b280ae4940 100644 --- a/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c +++ b/contrib/dlz/modules/mysql/dlz_mysql_dynamic.c @@ -77,9 +77,9 @@ typedef struct { #if PTHREADS db_list_t *db; /*%< handle to a list of DB */ int dbcount; -#else +#else /* if PTHREADS */ dbinstance_t *db; /*%< handle to DB */ -#endif +#endif /* if PTHREADS */ unsigned int flags; char * dbname; @@ -115,8 +115,9 @@ void mysql_destroy(dbinstance_t *db) { /* release DB connection */ - if (db->dbconn != NULL) + if (db->dbconn != NULL) { mysql_close((MYSQL *)db->dbconn); + } /* destroy DB instance */ destroy_dbinstance(db); @@ -168,9 +169,9 @@ mysql_find_avail_conn(mysql_instance_t *mysql) /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ - if (dlz_mutex_trylock(&dbi->lock) == 0) + if (dlz_mutex_trylock(&dbi->lock) == 0) { return (dbi); /* success, return the DBI for use. */ - + } /* not successful, keep trying */ dbi = DLZ_LIST_NEXT(dbi, link); @@ -202,13 +203,15 @@ mysqldrv_escape_string(MYSQL *mysql, const char *instr) char * outstr; unsigned int len; - if (instr == NULL) + if (instr == NULL) { return (NULL); + } len = strlen(instr); outstr = malloc((2 * len * sizeof(char)) + 1); - if (outstr == NULL) + if (outstr == NULL) { return (NULL); + } mysql_real_escape_string(mysql, outstr, instr, len); @@ -303,20 +306,23 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, } if (zone != NULL) { - if (dbi->zone != NULL) + if (dbi->zone != NULL) { free(dbi->zone); + } dbi->zone = mysqldrv_escape_string((MYSQL *)dbi->dbconn, zone); if (dbi->zone == NULL) { result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->zone = NULL; + } if (record != NULL) { - if (dbi->record != NULL) + if (dbi->record != NULL) { free(dbi->record); + } dbi->record = mysqldrv_escape_string((MYSQL *)dbi->dbconn, record); @@ -324,12 +330,14 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->record = NULL; + } if (client != NULL) { - if (dbi->client != NULL) + if (dbi->client != NULL) { free(dbi->client); + } dbi->client = mysqldrv_escape_string((MYSQL *)dbi->dbconn, client); @@ -337,8 +345,9 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->client = NULL; + } /* * what type of query are we going to run? this time we build @@ -381,8 +390,9 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, /* attempt query up to 3 times. */ for (i = 0; i < 3; i++) { qres = mysql_query((MYSQL *)dbi->dbconn, querystring); - if (qres == 0) + if (qres == 0) { break; + } for (j = 0; j < 4; j++) { if (mysql_ping((MYSQL *)dbi->dbconn) == 0) { break; @@ -394,11 +404,13 @@ mysql_get_resultset(const char *zone, const char *record, const char *client, result = ISC_R_SUCCESS; if (query != COUNTZONE) { *rs = mysql_store_result((MYSQL *)dbi->dbconn); - if (*rs == NULL) + if (*rs == NULL) { result = ISC_R_FAILURE; + } } - } else + } else { result = ISC_R_FAILURE; + } cleanup: if (dbi->zone != NULL) { @@ -417,8 +429,9 @@ cleanup: /* release the lock so another thread can use this dbi */ (void)dlz_mutex_unlock(&dbi->lock); - if (querystring != NULL) + if (querystring != NULL) { free(querystring); + } return (result); } @@ -554,8 +567,9 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, result = mysql_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs); if (result != ISC_R_SUCCESS || rs == NULL) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } db->log(ISC_LOG_ERROR, "MySQL module unable to return " "result set for findzone query"); @@ -587,8 +601,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) /* first check if the zone is supported by the database. */ result = dlz_findzonedb(dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } /* * if we get to this point we know the zone is supported by @@ -597,12 +612,14 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) * have an allow zone xfr query. */ result = mysql_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &rs); - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { return (result); + } if (result != ISC_R_SUCCESS || rs == NULL) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } db->log(ISC_LOG_ERROR, "MySQL module unable to return " "result set for allow xfr query"); return (ISC_R_FAILURE); @@ -614,8 +631,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) */ rows = mysql_num_rows(rs); mysql_free_result(rs); - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } return (ISC_R_NOPERM); } @@ -639,8 +657,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) int ttl; result = mysql_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs); - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { @@ -717,8 +736,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) } cleanup: - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } return (result); } @@ -735,12 +755,14 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) mysql_instance_t *db = (mysql_instance_t *)dbdata; result = mysql_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &rs); - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { return (result); + } if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } db->log(ISC_LOG_ERROR, "MySQL module unable to return " "result set for authority query"); return (ISC_R_FAILURE); @@ -770,8 +792,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { mysql_free_result(rs); + } db->log(ISC_LOG_ERROR, "MySQL module unable to return " "result set for lookup query"); return (ISC_R_FAILURE); @@ -801,7 +824,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, const char * helper_name; #if MYSQL_VERSION_ID >= 50000 my_bool auto_reconnect = 1; -#endif +#endif /* if MYSQL_VERSION_ID >= 50000 */ #if PTHREADS int dbcount; int i; @@ -812,14 +835,16 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* allocate memory for MySQL instance */ mysql = calloc(1, sizeof(mysql_instance_t)); - if (mysql == NULL) + if (mysql == NULL) { return (ISC_R_NOMEMORY); + } memset(mysql, 0, sizeof(mysql_instance_t)); /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(mysql, helper_name, va_arg(ap, void *)); + } va_end(ap); #if PTHREADS @@ -855,9 +880,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* get db port. Not required, but must be > 0 if specified */ tmp = get_parameter_value(argv[1], "port="); - if (tmp == NULL) + if (tmp == NULL) { mysql->port = 0; - else { + } else { mysql->port = strtol(tmp, &endp, 10); if (*endp != '\0' || mysql->port < 0) { mysql->log(ISC_LOG_ERROR, "Mysql module: port " @@ -878,31 +903,34 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, tmp = get_parameter_value(argv[1], "compress="); if (tmp != NULL) { - if (strcasecmp(tmp, "true") == 0) + if (strcasecmp(tmp, "true") == 0) { mysql->flags |= CLIENT_COMPRESS; + } free(tmp); } tmp = get_parameter_value(argv[1], "ssl="); if (tmp != NULL) { - if (strcasecmp(tmp, "true") == 0) + if (strcasecmp(tmp, "true") == 0) { mysql->flags |= CLIENT_SSL; + } free(tmp); } tmp = get_parameter_value(argv[1], "space="); if (tmp != NULL) { - if (strcasecmp(tmp, "ignore") == 0) + if (strcasecmp(tmp, "ignore") == 0) { mysql->flags |= CLIENT_IGNORE_SPACE; + } free(tmp); } #if PTHREADS /* multithreaded build can have multiple DB connections */ tmp = get_parameter_value(argv[1], "threads="); - if (tmp == NULL) + if (tmp == NULL) { dbcount = 1; - else { + } else { dbcount = strtol(tmp, &endp, 10); if (*endp != '\0' || dbcount < 1) { mysql->log(ISC_LOG_ERROR, "MySQL database connection " @@ -973,13 +1001,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* when multithreaded, build a list of DBI's */ DLZ_LINK_INIT(dbi, link); DLZ_LIST_APPEND(*(mysql->db), dbi, link); -#else +#else /* if PTHREADS */ /* * when single threaded, hold onto the one connection * instance. */ mysql->db = dbi; -#endif +#endif /* if PTHREADS */ /* create and set db connection */ dbi->dbconn = mysql_init(NULL); @@ -1003,17 +1031,18 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, "MYSQL_OPT_RECONNECT " "option, continuing"); } -#endif +#endif /* if MYSQL_VERSION_ID >= 50000 */ for (j = 0; dbc == NULL && j < 4; j++) { dbc = mysql_real_connect( (MYSQL *)dbi->dbconn, mysql->host, mysql->user, mysql->pass, mysql->dbname, mysql->port, mysql->socket, mysql->flags); - if (dbc == NULL) + if (dbc == NULL) { mysql->log(ISC_LOG_ERROR, "MySQL connection failed: %s", mysql_error((MYSQL *)dbi->dbconn)); + } } if (dbc == NULL) { @@ -1050,22 +1079,28 @@ dlz_destroy(void *dbdata) mysql_instance_t *db = (mysql_instance_t *)dbdata; #if PTHREADS /* cleanup the list of DBI's */ - if (db->db != NULL) + if (db->db != NULL) { mysql_destroy_dblist((db_list_t *)(db->db)); + } #else /* PTHREADS */ mysql_destroy(db); #endif /* PTHREADS */ - if (db->dbname != NULL) + if (db->dbname != NULL) { free(db->dbname); - if (db->host != NULL) + } + if (db->host != NULL) { free(db->host); - if (db->user != NULL) + } + if (db->user != NULL) { free(db->user); - if (db->pass != NULL) + } + if (db->pass != NULL) { free(db->pass); - if (db->socket != NULL) + } + if (db->socket != NULL) { free(db->socket); + } } /* @@ -1085,12 +1120,16 @@ dlz_version(unsigned int *flags) static void b9_add_helper(mysql_instance_t *db, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { db->log = (log_t *)ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { db->putrr = (dns_sdlz_putrr_t *)ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { db->writeable_zone = (dns_dlz_writeablezone_t *)ptr; + } } diff --git a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c index c2ec7287b2..ddac8b9fd6 100644 --- a/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c +++ b/contrib/dlz/modules/mysqldyn/dlz_mysqldyn_mod.c @@ -259,21 +259,24 @@ db_connect(mysql_data_t *state, mysql_instance_t *dbi) */ mysql_thread_init(); - if (dbi->connected) + if (dbi->connected) { return (true); + } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "%s: init connection %d ", modname, dbi->id); + } conn = mysql_real_connect(dbi->sock, state->db_host, state->db_user, state->db_pass, state->db_name, 0, NULL, CLIENT_REMEMBER_OPTIONS); if (conn == NULL) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: database connection failed: %s", modname, mysql_error(dbi->sock)); + } dlz_mutex_unlock(&dbi->mutex); return (false); @@ -292,14 +295,16 @@ get_dbi(mysql_data_t *state) * Find an available dbi */ for (i = 0; i < MAX_DBI; i++) { - if (dlz_mutex_trylock(&state->db[i].mutex) == 0) + if (dlz_mutex_trylock(&state->db[i].mutex) == 0) { break; + } } if (i == MAX_DBI) { - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: No available connections", modname); + } return (NULL); } return (&state->db[i]); @@ -314,8 +319,9 @@ sanitize(mysql_instance_t *dbi, const char *original) { char *s; - if (original == NULL) + if (original == NULL) { return (NULL); + } s = (char *)malloc((strlen(original) * 2) + 1); if (s != NULL) { @@ -338,8 +344,9 @@ additem(mysql_arglist_t *arglist, char **s, size_t *len) mysql_arg_t *item; item = malloc(sizeof(*item)); - if (item == NULL) + if (item == NULL) { return (ISC_R_NOMEMORY); + } DLZ_LINK_INIT(item, link); item->arg = *s; @@ -376,71 +383,82 @@ build_query(mysql_data_t *state, mysql_instance_t *dbi, const char *command, /* Get a DB instance if needed */ if (dbi == NULL) { dbi = get_dbi(state); - if (dbi == NULL) + if (dbi == NULL) { return (NULL); + } localdbi = true; } /* Make sure this instance is connected */ - if (!db_connect(state, dbi)) + if (!db_connect(state, dbi)) { goto fail; + } va_start(ap1, command); DLZ_LIST_INIT(arglist); q = querystr = strdup(command); - if (querystr == NULL) + if (querystr == NULL) { goto fail; + } for (;;) { - if (*q == '\0') + if (*q == '\0') { break; + } p = strstr(q, "%s"); if (p != NULL) { *p = '\0'; tmp = strdup(q); - if (tmp == NULL) + if (tmp == NULL) { goto fail; + } result = additem(&arglist, &tmp, &len); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } tmp = sanitize(dbi, va_arg(ap1, const char *)); - if (tmp == NULL) + if (tmp == NULL) { goto fail; + } result = additem(&arglist, &tmp, &len); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } q = p + 2; } else { tmp = strdup(q); - if (tmp == NULL) + if (tmp == NULL) { goto fail; + } result = additem(&arglist, &tmp, &len); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } break; } } - if (len == 0) + if (len == 0) { goto fail; + } query = malloc(len + 1); - if (query == NULL) + if (query == NULL) { goto fail; + } *query = '\0'; for (item = DLZ_LIST_HEAD(arglist); item != NULL; item = DLZ_LIST_NEXT(item, link)) { if (item->arg != NULL) { strcat(query, item->arg); - } } @@ -449,18 +467,22 @@ fail: for (item = DLZ_LIST_HEAD(arglist); item != NULL; item = DLZ_LIST_NEXT(item, link)) { - if (item->arg != NULL) + if (item->arg != NULL) { free(item->arg); + } free(item); } - if (tmp != NULL) + if (tmp != NULL) { free(tmp); - if (querystr != NULL) + } + if (querystr != NULL) { free(querystr); + } - if (dbi != NULL && localdbi) + if (dbi != NULL && localdbi) { dlz_mutex_unlock(&dbi->mutex); + } return (query); } @@ -469,8 +491,9 @@ fail: static bool isrelative(const char *s) { - if (s == NULL || s[strlen(s) - 1] == '.') + if (s == NULL || s[strlen(s) - 1] == '.') { return (false); + } return (true); } @@ -489,16 +512,18 @@ dot(const char *s) static void fqhn(const char *name, const char *zone, char *dest) { - if (dest == NULL) + if (dest == NULL) { return; + } - if (strlen(name) == 0 || strcmp(name, "@") == 0) + if (strlen(name) == 0 || strcmp(name, "@") == 0) { sprintf(dest, "%s%s", zone, dot(zone)); - else { - if (isrelative(name)) + } else { + if (isrelative(name)) { sprintf(dest, "%s.%s%s", name, zone, dot(zone)); - else + } else { strcpy(dest, name); + } } } @@ -514,8 +539,9 @@ relname(const char *name, const char *zone) char *new; new = (char *)malloc(strlen(name) + 1); - if (new == NULL) + if (new == NULL) { return (NULL); + } nlen = strlen(name); zlen = strlen(zone); @@ -555,8 +581,9 @@ validate_txn(mysql_data_t *state, mysql_transaction_t *txn) } dlz_mutex_unlock(&state->tx_mutex); - if (result != ISC_R_SUCCESS && state->log != NULL) + if (result != ISC_R_SUCCESS && state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: invalid txn %x", modname, txn); + } return (result); } @@ -567,20 +594,23 @@ db_execute(mysql_data_t *state, mysql_instance_t *dbi, const char *query) int ret; /* Make sure this instance is connected. */ - if (!db_connect(state, dbi)) - return (ISC_R_FAILURE); - - ret = mysql_real_query(dbi->sock, query, strlen(query)); - if (ret != 0) { - if (state->debug && state->log != NULL) - state->log(ISC_LOG_ERROR, "%s: query '%s' failed: %s", - modname, query, mysql_error(dbi->sock)); + if (!db_connect(state, dbi)) { return (ISC_R_FAILURE); } - if (state->debug && state->log != NULL) + ret = mysql_real_query(dbi->sock, query, strlen(query)); + if (ret != 0) { + if (state->debug && state->log != NULL) { + state->log(ISC_LOG_ERROR, "%s: query '%s' failed: %s", + modname, query, mysql_error(dbi->sock)); + } + return (ISC_R_FAILURE); + } + + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: execute(%d) %s", modname, dbi->id, query); + } return (ISC_R_SUCCESS); } @@ -592,41 +622,48 @@ db_query(mysql_data_t *state, mysql_instance_t *dbi, const char *query) bool localdbi = false; MYSQL_RES * res = NULL; - if (query == NULL) + if (query == NULL) { return (NULL); + } /* Get a DB instance if needed */ if (dbi == NULL) { dbi = get_dbi(state); - if (dbi == NULL) + if (dbi == NULL) { return (NULL); + } localdbi = true; } /* Make sure this instance is connected */ - if (!db_connect(state, dbi)) - goto fail; - - result = db_execute(state, dbi, query); - if (result != ISC_R_SUCCESS) - goto fail; - - res = mysql_store_result(dbi->sock); - if (res == NULL) { - if (state->log != NULL) - state->log(ISC_LOG_ERROR, - "%s: unable to store result: %s", modname, - mysql_error(dbi->sock)); + if (!db_connect(state, dbi)) { goto fail; } - if (state->debug && state->log != NULL) + result = db_execute(state, dbi, query); + if (result != ISC_R_SUCCESS) { + goto fail; + } + + res = mysql_store_result(dbi->sock); + if (res == NULL) { + if (state->log != NULL) { + state->log(ISC_LOG_ERROR, + "%s: unable to store result: %s", modname, + mysql_error(dbi->sock)); + } + goto fail; + } + + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: query(%d) returned %d rows", modname, dbi->id, mysql_num_rows(res)); + } fail: - if (dbi != NULL && localdbi) + if (dbi != NULL && localdbi) { dlz_mutex_unlock(&dbi->mutex); + } return (res); } @@ -649,8 +686,9 @@ make_notify(const char *zone, int *packetlen) int i, j; unsigned char *packet = (unsigned char *)malloc(strlen(zone) + 18); - if (packet == NULL) + if (packet == NULL) { return (NULL); + } *packetlen = strlen(zone) + 18; memset(packet, 0, *packetlen); @@ -705,8 +743,9 @@ send_notify(struct sockaddr_in *addr, const unsigned char *p, const int plen) addr->sin_family = AF_INET; addr->sin_port = htons(53); - if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) + if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { return; + } sendto(s, p, plen, 0, (struct sockaddr *)addr, sizeof(*addr)); close(s); @@ -732,8 +771,9 @@ notify(mysql_data_t *state, const char *zone, int sn) query = build_query(state, NULL, Q_GETNS, zone); res = db_query(state, NULL, query); free(query); - if (res == NULL) + if (res == NULL) { return; + } /* Create a DNS NOTIFY packet */ packet = make_notify(zone, &packetlen); @@ -743,8 +783,9 @@ notify(mysql_data_t *state, const char *zone, int sn) } /* Get a list of our own addresses */ - if (getifaddrs(&ifap) < 0) + if (getifaddrs(&ifap) < 0) { ifap = NULL; + } /* Tell each nameserver of the update */ while ((row = mysql_fetch_row(res)) != NULL) { @@ -758,8 +799,9 @@ notify(mysql_data_t *state, const char *zone, int sn) * this to inet_pton/getaddrinfo.) */ h = gethostbyname(row[0]); - if (h == NULL) + if (h == NULL) { continue; + } memmove(&addr.sin_addr, h->h_addr, h->h_length); addrp = &addr.sin_addr; @@ -769,8 +811,9 @@ notify(mysql_data_t *state, const char *zone, int sn) for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { char ifaddr[INET_ADDRSTRLEN]; - if (ifa->ifa_addr->sa_family != AF_INET) + if (ifa->ifa_addr->sa_family != AF_INET) { continue; + } /* Get local address into a string */ sin = (struct sockaddr_in *)ifa->ifa_addr; @@ -778,23 +821,26 @@ notify(mysql_data_t *state, const char *zone, int sn) inet_ntop(AF_INET, addrp, ifaddr, INET_ADDRSTRLEN); /* See if nameserver address matches this one */ - if (strcmp(ifaddr, zaddr) == 0) + if (strcmp(ifaddr, zaddr) == 0) { local = true; + } } if (!local) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "%s: notify %s zone %s serial %d", modname, row[0], zone, sn); + } send_notify(&addr, packet, packetlen); } } mysql_free_result(res); free(packet); - if (ifap != NULL) + if (ifap != NULL) { freeifaddrs(ifap); + } } /* @@ -811,19 +857,21 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) new_record = (mysql_record_t *)malloc(sizeof(mysql_record_t)); if (new_record == NULL) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: makerecord - unable to malloc", modname); + } return (NULL); } buf = strdup(rdatastr); if (buf == NULL) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: makerecord - unable to malloc", modname); + } free(new_record); return (NULL); } @@ -836,24 +884,29 @@ makerecord(mysql_data_t *state, const char *name, const char *rdatastr) * for the type used by dig */ real_name = strtok_r(buf, "\t", &saveptr); - if (real_name == NULL) + if (real_name == NULL) { goto error; + } ttlstr = strtok_r(NULL, "\t", &saveptr); - if (ttlstr == NULL || sscanf(ttlstr, "%d", &ttlvalue) != 1) + if (ttlstr == NULL || sscanf(ttlstr, "%d", &ttlvalue) != 1) { 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; + } strcpy(new_record->name, name); strcpy(new_record->type, type); @@ -875,14 +928,18 @@ error: static void b9_add_helper(mysql_data_t *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; + } } /* @@ -915,27 +972,31 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, UNUSED(dlzname); state = calloc(1, sizeof(mysql_data_t)); - if (state == NULL) + if (state == NULL) { return (ISC_R_NOMEMORY); + } dlz_mutex_init(&state->tx_mutex, NULL); state->transactions = NULL; /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(state, helper_name, va_arg(ap, void *)); + } va_end(ap); - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "loading %s module", modname); + } if ((argc < 2) || (argc > 6)) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: missing args " "[ [ ]]", modname); + } dlz_destroy(state); return (ISC_R_FAILURE); } @@ -956,9 +1017,10 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, state->db_pass = strdup(""); } - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_INFO, "%s: DB=%s, Host=%s, User=%s", modname, state->db_name, state->db_host, state->db_user); + } /* * Assign the 'state' to dbdata so we get it in our callbacks @@ -1007,8 +1069,9 @@ dlz_destroy(void *dbdata) mysql_data_t *state = (mysql_data_t *)dbdata; int i; - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: shutting down", modname); + } for (i = 0; i < MAX_DBI; i++) { if (state->db[i].sock) { @@ -1039,15 +1102,18 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, /* Query the Zones table to see if this zone is present */ query = build_query(state, NULL, Q_FINDZONE, name); - if (query == NULL) + if (query == NULL) { return (ISC_R_NOMEMORY); + } res = db_query(state, NULL, query); - if (res == NULL) + if (res == NULL) { return (ISC_R_FAILURE); + } - if (mysql_num_rows(res) == 0) + if (mysql_num_rows(res) == 0) { result = ISC_R_NOTFOUND; + } mysql_free_result(res); return (result); @@ -1072,9 +1138,10 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, mysql_instance_t * dbi = NULL; if (state->putrr == NULL) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: dlz_lookup - no putrr", modname); + } return (ISC_R_NOTIMPLEMENTED); } @@ -1082,8 +1149,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, if (clientinfo != NULL && clientinfo->version >= DNS_CLIENTINFO_VERSION) { txn = (mysql_transaction_t *)clientinfo->dbversion; - if (txn != NULL && validate_txn(state, txn) == ISC_R_SUCCESS) + if (txn != NULL && validate_txn(state, txn) == ISC_R_SUCCESS) { dbi = txn->dbi; + } if (dbi != NULL) { state->log(ISC_LOG_DEBUG(1), "%s: lookup in live transaction %p, DBI %p", @@ -1093,13 +1161,15 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, if (strcmp(name, "@") == 0) { real_name = (char *)malloc(strlen(zone) + 1); - if (real_name == NULL) + if (real_name == NULL) { return (ISC_R_NOMEMORY); + } strcpy(real_name, zone); } else { real_name = (char *)malloc(strlen(name) + 1); - if (real_name == NULL) + if (real_name == NULL) { return (ISC_R_NOMEMORY); + } strcpy(real_name, name); } @@ -1149,8 +1219,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, * Now we'll get the rest of the apex data */ query = build_query(state, dbi, Q_GETAPEX, zone, real_name); - } else + } else { query = build_query(state, dbi, Q_GETNODE, zone, real_name); + } res = db_query(state, dbi, query); free(query); @@ -1173,15 +1244,17 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, found = true; } - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: dlz_lookup %s/%s/%s - (%d rows)", modname, name, real_name, zone, mysql_num_rows(res)); + } mysql_free_result(res); free(real_name); - if (!found) + if (!found) { return (ISC_R_NOTFOUND); + } return (ISC_R_SUCCESS); } @@ -1194,9 +1267,10 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) { mysql_data_t *state = (mysql_data_t *)dbdata; - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "dlz_allowzonexfr: %s %s", name, client); + } /* Just say yes for all our zones */ return (dlz_findzonedb(dbdata, name, NULL, NULL)); @@ -1216,23 +1290,27 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) UNUSED(zone); - if (state->debug && (state->log != NULL)) + if (state->debug && (state->log != NULL)) { state->log(ISC_LOG_INFO, "dlz_allnodes: %s", zone); + } - if (state->putnamedrr == NULL) + if (state->putnamedrr == NULL) { return (ISC_R_NOTIMPLEMENTED); + } /* * Get all the ZoneData for this zone */ query = build_query(state, NULL, Q_GETALL, zone); - if (query == NULL) + if (query == NULL) { return (ISC_R_NOMEMORY); + } res = db_query(state, NULL, query); free(query); - if (res == NULL) + if (res == NULL) { return (ISC_R_NOTFOUND); + } while ((row = mysql_fetch_row(res)) != NULL) { char hostname[1024]; @@ -1242,8 +1320,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) fqhn(row[0], zone, hostname); result = state->putnamedrr(allnodes, hostname, row[1], ttl, row[2]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } mysql_free_result(res); @@ -1268,13 +1347,15 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) * Check Zone is writable */ query = build_query(state, NULL, Q_WRITEABLE, zone); - if (query == NULL) + if (query == NULL) { return (ISC_R_NOMEMORY); + } res = db_query(state, NULL, query); free(query); - if (res == NULL) + if (res == NULL) { return (ISC_R_FAILURE); + } if ((row = mysql_fetch_row(res)) == NULL) { mysql_free_result(res); @@ -1290,11 +1371,12 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) dlz_mutex_lock(&state->tx_mutex); for (txn = state->transactions; txn != NULL; txn = txn->next) { if (strcmp(txn->zone, zone) == 0) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: transaction already " "started for zone %s", modname, zone); + } dlz_mutex_unlock(&state->tx_mutex); return (ISC_R_FAILURE); } @@ -1338,8 +1420,9 @@ dlz_newversion(const char *zone, void *dbdata, void **versionp) newtx->next = state->transactions; state->transactions = newtx; - if (state->debug && (state->log != NULL)) + if (state->debug && (state->log != NULL)) { state->log(ISC_LOG_INFO, "%s: New tx %x", modname, newtx); + } cleanup: dlz_mutex_unlock(&state->tx_mutex); @@ -1423,8 +1506,9 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) res = db_query(state, txn->dbi, query); if (res != NULL) { - while ((row = mysql_fetch_row(res)) != NULL) + while ((row = mysql_fetch_row(res)) != NULL) { sscanf(row[0], "%d", &oldsn); + } mysql_free_result(res); } @@ -1439,11 +1523,12 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) return; } - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: (%x) committing transaction " "on zone %s", modname, txn, zone); + } /* * Now get the serial number again @@ -1453,22 +1538,25 @@ dlz_closeversion(const char *zone, bool commit, void *dbdata, void **versionp) free(query); if (res != NULL) { - while ((row = mysql_fetch_row(res)) != NULL) + while ((row = mysql_fetch_row(res)) != NULL) { sscanf(row[0], "%d", &newsn); + } mysql_free_result(res); } /* * Look to see if serial numbers have changed */ - if (newsn > oldsn) + if (newsn > oldsn) { notify(state, zone, newsn); + } } else { result = db_execute(state, txn->dbi, "ROLLBACK"); - if (state->debug && (state->log != NULL)) + if (state->debug && (state->log != NULL)) { state->log(ISC_LOG_INFO, "%s: (%x) roll back transaction on zone %s", modname, txn, zone); + } } /* @@ -1506,14 +1594,16 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) */ srand(getpid()); - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: dlz_confgure", modname); + } if (state->writeable_zone == NULL) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: no writeable_zone method available", modname); + } return (ISC_R_FAILURE); } @@ -1521,8 +1611,9 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) * Get a list of Zones (ignore writeable column at this point) */ res = db_query(state, NULL, Q_GETZONES); - if (res == NULL) + if (res == NULL) { return (ISC_R_FAILURE); + } count = 0; while ((row = mysql_fetch_row(res)) != NULL) { @@ -1532,13 +1623,14 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) result = state->writeable_zone(view, #if DLZ_DLOPEN_VERSION >= 3 dlzdb, -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ row[0]); if (result != ISC_R_SUCCESS) { - if (state->log != NULL) + if (state->log != NULL) { state->log(ISC_LOG_ERROR, "%s: failed to configure zone %s", modname, row[0]); + } mysql_free_result(res); return (result); } @@ -1546,9 +1638,10 @@ dlz_configure(dns_view_t *view, dns_dlzdb_t *dlzdb, void *dbdata) } mysql_free_result(res); - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: configured %d zones", modname, count); + } return (ISC_R_SUCCESS); } @@ -1568,9 +1661,10 @@ dlz_ssumatch(const char *signer, const char *name, const char *tcpaddr, UNUSED(keydata); UNUSED(key); - if (state->debug && state->log != NULL) + if (state->debug && state->log != NULL) { state->log(ISC_LOG_INFO, "%s: allowing update of %s by key %s", modname, name, signer); + } return (true); } @@ -1584,21 +1678,25 @@ dlz_addrdataset(const char *name, const char *rdatastr, void *dbdata, mysql_record_t * record; isc_result_t result; - if (txn == NULL) + if (txn == NULL) { return (ISC_R_FAILURE); + } new_name = relname(name, txn->zone); - if (new_name == NULL) + if (new_name == NULL) { return (ISC_R_NOMEMORY); + } - if (state->debug && (state->log != NULL)) + if (state->debug && (state->log != NULL)) { state->log(ISC_LOG_INFO, "%s: add (%x) %s (as %s) %s", modname, version, name, new_name, rdatastr); + } record = makerecord(state, new_name, rdatastr); free(new_name); - if (record == NULL) + if (record == NULL) { return (ISC_R_FAILURE); + } /* Write out data to database */ if (strcasecmp(record->type, "SOA") != 0) { @@ -1644,27 +1742,31 @@ dlz_subrdataset(const char *name, const char *rdatastr, void *dbdata, mysql_record_t * record; isc_result_t result; - if (txn == NULL) + if (txn == NULL) { return (ISC_R_FAILURE); + } new_name = relname(name, txn->zone); - if (new_name == NULL) + if (new_name == NULL) { return (ISC_R_NOMEMORY); + } - if (state->debug && (state->log != NULL)) + if (state->debug && (state->log != NULL)) { state->log(ISC_LOG_INFO, "%s: sub (%x) %s %s", modname, version, name, rdatastr); + } record = makerecord(state, new_name, rdatastr); free(new_name); - if (record == NULL) + if (record == NULL) { return (ISC_R_FAILURE); + } /* * If 'type' isn't 'SOA', delete the records */ - if (strcasecmp(record->type, "SOA") == 0) + if (strcasecmp(record->type, "SOA") == 0) { result = ISC_R_SUCCESS; - else { + } else { query = build_query(state, txn->dbi, D_RECORD, txn->zone_id, record->name, record->type, record->data, record->ttl); @@ -1690,16 +1792,19 @@ dlz_delrdataset(const char *name, const char *type, void *dbdata, void *version) char * new_name, *query; isc_result_t result; - if (txn == NULL) + if (txn == NULL) { return (ISC_R_FAILURE); + } new_name = relname(name, txn->zone); - if (new_name == NULL) + if (new_name == NULL) { return (ISC_R_NOMEMORY); + } - if (state->debug && (state->log != NULL)) + if (state->debug && (state->log != NULL)) { state->log(ISC_LOG_INFO, "%s: del (%x) %s %s", modname, version, name, type); + } query = build_query(state, txn->dbi, D_RRSET, txn->zone_id, new_name, type); diff --git a/contrib/dlz/modules/perl/dlz_perl_driver.c b/contrib/dlz/modules/perl/dlz_perl_driver.c index 12b678aa8b..91c158bd66 100644 --- a/contrib/dlz/modules/perl/dlz_perl_driver.c +++ b/contrib/dlz/modules/perl/dlz_perl_driver.c @@ -70,9 +70,9 @@ /* Enable debug logging? */ #if 0 #define carp(...) cd->log(ISC_LOG_INFO, __VA_ARGS__); -#else +#else /* if 0 */ #define carp(...) -#endif +#endif /* if 0 */ #ifndef MULTIPLICITY /* This is a pretty terrible work-around for handling HUP/rndc reconfig, but @@ -82,7 +82,7 @@ * it properly and link against a perl compiled with multiplicity. */ static PerlInterpreter *global_perl = NULL; static int global_perl_dont_free = 0; -#endif +#endif /* ifndef MULTIPLICITY */ typedef struct config_data { PerlInterpreter *perl; @@ -129,20 +129,24 @@ EXTERN_C void xs_init(pTHX) static void b9_add_helper(config_data_t *state, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { state->log = ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { state->putrr = ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { state->putnamedrr = ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { state->writeable_zone = ptr; + } } int dlz_version(unsigned int *flags) { - return DLZ_DLOPEN_VERSION; + return (DLZ_DLOPEN_VERSION); } isc_result_t @@ -158,7 +162,7 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) SV ** rr_data; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; -#endif +#endif /* ifdef MULTIPLICITY */ dSP; PERL_SET_CONTEXT(cd->perl); @@ -256,7 +260,7 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) isc_result_t retval; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; -#endif +#endif /* ifdef MULTIPLICITY */ dSP; PERL_SET_CONTEXT(cd->perl); @@ -288,8 +292,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) retval = ISC_R_NOTFOUND; } else if (r > 1) { /* Once again, clean out the stack when possible. */ - while (r--) + while (r--) { POPi; + } cd->log(ISC_LOG_ERROR, "DLZ Perl: allowzonexfr returned too " "many parameters!"); retval = ISC_R_FAILURE; @@ -299,10 +304,11 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) * the zone. */ r = POPi; - if (r) + if (r) { retval = ISC_R_SUCCESS; - else + } else { retval = ISC_R_NOPERM; + } } PUTBACK; @@ -314,23 +320,23 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) #if DLZ_DLOPEN_VERSION < 3 isc_result_t dlz_findzonedb(void *dbdata, const char *name) -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ { config_data_t *cd = (config_data_t *)dbdata; int r; isc_result_t retval; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; -#endif +#endif /* ifdef MULTIPLICITY */ #if DLZ_DLOPEN_VERSION >= 3 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ dSP; carp("DLZ Perl: findzone looking for '%s'", name); @@ -361,17 +367,19 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, retval = ISC_R_FAILURE; } else if (r > 1) { /* Once again, clean out the stack when possible. */ - while (r--) + while (r--) { POPi; + } cd->log(ISC_LOG_ERROR, "DLZ Perl: findzone returned too many " "parameters!"); retval = ISC_R_FAILURE; } else { r = POPi; - if (r) + if (r) { retval = ISC_R_SUCCESS; - else + } else { retval = ISC_R_NOTFOUND; + } } PUTBACK; @@ -384,12 +392,12 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup) -#else +#else /* if DLZ_DLOPEN_VERSION == 1 */ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION == 1 */ { isc_result_t retval; config_data_t * cd = (config_data_t *)dbdata; @@ -401,12 +409,12 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, SV ** rr_data; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; -#endif +#endif /* ifdef MULTIPLICITY */ #if DLZ_DLOPEN_VERSION >= 2 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 2 */ dSP; PERL_SET_CONTEXT(cd->perl); @@ -499,9 +507,9 @@ CLEAN_UP_AND_RETURN: const char * #ifdef MULTIPLICITY missing_perl_method(const char *perl_class_name, PerlInterpreter *my_perl) -#else +#else /* ifdef MULTIPLICITY */ missing_perl_method(const char *perl_class_name) -#endif +#endif /* ifdef MULTIPLICITY */ { const int BUF_LEN = 64; /* Should be big enough, right? hah */ char full_name[BUF_LEN]; @@ -513,7 +521,7 @@ missing_perl_method(const char *perl_class_name) methods[i]); if (get_cv(full_name, 0) == NULL) { - return methods[i]; + return (methods[i]); } i++; } @@ -536,11 +544,12 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, char * call_argv_args = NULL; #ifdef MULTIPLICITY PerlInterpreter *my_perl; -#endif +#endif /* ifdef MULTIPLICITY */ cd = malloc(sizeof(config_data_t)); - if (cd == NULL) + if (cd == NULL) { return (ISC_R_NOMEMORY); + } memset(cd, 0, sizeof(config_data_t)); @@ -582,7 +591,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, global_perl = NULL; global_perl_dont_free = 1; } -#endif +#endif /* ifndef MULTIPLICITY */ cd->perl = perl_alloc(); if (cd->perl == NULL) { @@ -591,7 +600,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, } #ifdef MULTIPLICITY my_perl = cd->perl; -#endif +#endif /* ifdef MULTIPLICITY */ PERL_SET_CONTEXT(cd->perl); /* @@ -637,9 +646,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, #ifdef MULTIPLICITY if (missing_method_name = missing_perl_method(perl_class_name, my_perl)) -#else +#else /* ifdef MULTIPLICITY */ if (missing_method_name = missing_perl_method(perl_class_name)) -#endif +#endif /* ifdef MULTIPLICITY */ { cd->log(ISC_LOG_ERROR, "DLZ Perl '%s': Missing required function '%s', " @@ -671,8 +680,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, SPAGAIN; - if (r) + if (r) { cd->perl_class = SvREFCNT_inc(POPs); + } PUTBACK; FREETMPS; @@ -696,7 +706,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, #ifndef MULTIPLICITY global_perl = cd->perl; -#endif +#endif /* ifndef MULTIPLICITY */ return (ISC_R_SUCCESS); CLEAN_UP_PERL_AND_FAIL: @@ -714,13 +724,13 @@ dlz_destroy(void *dbdata) config_data_t *cd = (config_data_t *)dbdata; #ifdef MULTIPLICITY PerlInterpreter *my_perl = cd->perl; -#endif +#endif /* ifdef MULTIPLICITY */ cd->log(ISC_LOG_INFO, "DLZ Perl: Unloading driver."); #ifndef MULTIPLICITY if (!global_perl_dont_free) { -#endif +#endif /* ifndef MULTIPLICITY */ PERL_SET_CONTEXT(cd->perl); PL_perl_destruct_level = 1; perl_destruct(cd->perl); @@ -729,7 +739,7 @@ dlz_destroy(void *dbdata) global_perl_dont_free = 0; global_perl = NULL; } -#endif +#endif /* ifndef MULTIPLICITY */ free(cd->perl_source); free(cd); diff --git a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c index dbde56bcd5..e05a298235 100644 --- a/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c +++ b/contrib/dlz/modules/sqlite3/dlz_sqlite3_dynamic.c @@ -77,9 +77,9 @@ typedef struct { #if PTHREADS db_list_t *db; /*%< handle to a list of DB */ int dbcount; -#else +#else /* if PTHREADS */ dbinstance_t *db; /*%< handle to DB */ -#endif +#endif /* if PTHREADS */ char *dbname; @@ -120,8 +120,9 @@ void sqlite3_destroy(dbinstance_t *db) { /* release DB connection */ - if (db->dbconn != NULL) + if (db->dbconn != NULL) { sqlite3_close((sqlite3 *)db->dbconn); + } sqlite3_shutdown(); /* destroy DB instance */ @@ -174,9 +175,9 @@ sqlite3_find_avail(sqlite3_instance_t *sqlite3) /* loop through list */ while (count < dbc_search_limit) { /* try to lock on the mutex */ - if (dlz_mutex_trylock(&dbi->lock) == 0) + if (dlz_mutex_trylock(&dbi->lock) == 0) { return (dbi); /* success, return the DBI for use. */ - + } /* not successful, keep trying */ dbi = DLZ_LIST_NEXT(dbi, link); @@ -212,18 +213,21 @@ escape_string(const char *instr) unsigned int atlen = 0; unsigned int i; - if (instr == NULL) + if (instr == NULL) { return (NULL); + } len = strlen(instr); atlen = (2 * len * sizeof(char)) + 1; outstr = malloc(atlen); - if (outstr == NULL) + if (outstr == NULL) { return (NULL); + } ptr = outstr; for (i = 0; i < len; i++) { - if (tlen > atlen || instr[i] == '\0') + if (tlen > atlen || instr[i] == '\0') { break; + } if (instr[i] == '\'') { *ptr++ = '\''; @@ -334,40 +338,46 @@ sqlite3_get_resultset(const char *zone, const char *record, const char *client, } if (zone != NULL) { - if (dbi->zone != NULL) + if (dbi->zone != NULL) { free(dbi->zone); + } dbi->zone = escape_string(zone); if (dbi->zone == NULL) { result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->zone = NULL; + } if (record != NULL) { - if (dbi->record != NULL) + if (dbi->record != NULL) { free(dbi->record); + } dbi->record = escape_string(record); if (dbi->record == NULL) { result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->record = NULL; + } if (client != NULL) { - if (dbi->client != NULL) + if (dbi->client != NULL) { free(dbi->client); + } dbi->client = escape_string(client); if (dbi->client == NULL) { result = ISC_R_NOMEMORY; goto cleanup; } - } else + } else { dbi->client = NULL; + } /* * what type of query are we going to run? this time we build @@ -452,8 +462,9 @@ cleanup: /* release the lock so another thread can use this dbi */ (void)dlz_mutex_unlock(&dbi->lock); - if (querystring != NULL) + if (querystring != NULL) { free(querystring); + } return (result); } @@ -482,8 +493,9 @@ unsigned int sqlite3_num_fields(sqlite3_res_t *rs) { unsigned int retval = 0; - if (rs != NULL) + if (rs != NULL) { retval = rs->pnColumn; + } return (retval); } @@ -491,8 +503,9 @@ unsigned int sqlite3_num_rows(sqlite3_res_t *rs) { unsigned int retval = 0; - if (rs != NULL) + if (rs != NULL) { retval = rs->pnRow; + } return (retval); } @@ -632,8 +645,9 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, result = sqlite3_get_resultset(name, NULL, NULL, FINDZONE, dbdata, &rs); if (result != ISC_R_SUCCESS || rs == NULL) { - if (rs != NULL) + if (rs != NULL) { sqlite3_free_result(rs); + } db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return " "result set for FINDZONE query"); @@ -666,8 +680,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) /* first check if the zone is supported by the database. */ result = dlz_findzonedb(dbdata, name, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } /* * if we get to this point we know the zone is supported by @@ -677,12 +692,14 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) */ result = sqlite3_get_resultset(name, NULL, client, ALLOWXFR, dbdata, &rs); - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { return (result); + } if (result != ISC_R_SUCCESS || rs == NULL) { - if (rs != NULL) + if (rs != NULL) { sqlite3_free_result(rs); + } db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return " "result set for ALLOWXFR query"); return (ISC_R_FAILURE); @@ -694,8 +711,9 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) */ rows = sqlite3_num_rows(rs); sqlite3_free_result(rs); - if (rows > 0) + if (rows > 0) { return (ISC_R_SUCCESS); + } return (ISC_R_NOPERM); } @@ -719,8 +737,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) int ttl; result = sqlite3_get_resultset(zone, NULL, NULL, ALLNODES, dbdata, &rs); - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { return (result); + } /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { @@ -797,8 +816,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) } cleanup: - if (rs != NULL) + if (rs != NULL) { sqlite3_free_result(rs); + } return (result); } @@ -816,12 +836,14 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) result = sqlite3_get_resultset(zone, NULL, NULL, AUTHORITY, dbdata, &rs); - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { return (result); + } if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { sqlite3_free_result(rs); + } db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return " "result set for AUTHORITY query"); return (ISC_R_FAILURE); @@ -851,8 +873,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, /* if we didn't get a result set, log an err msg. */ if (result != ISC_R_SUCCESS) { - if (rs != NULL) + if (rs != NULL) { sqlite3_free_result(rs); + } db->log(ISC_LOG_ERROR, "SQLite3 module: unable to return " "result set for LOOKUP query"); return (ISC_R_FAILURE); @@ -881,7 +904,7 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, const char * helper_name; #if SQLITE3_VERSION_ID >= 50000 my_bool auto_reconnect = 1; -#endif +#endif /* if SQLITE3_VERSION_ID >= 50000 */ #if PTHREADS int dbcount; int i, ret; @@ -892,14 +915,16 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* allocate memory for SQLite3 instance */ s3 = calloc(1, sizeof(sqlite3_instance_t)); - if (s3 == NULL) + if (s3 == NULL) { return (ISC_R_NOMEMORY); + } memset(s3, 0, sizeof(sqlite3_instance_t)); /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(s3, helper_name, va_arg(ap, void *)); + } va_end(ap); #if PTHREADS @@ -936,9 +961,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, #if PTHREADS /* multithreaded build can have multiple DB connections */ tmp = get_parameter_value(argv[1], "threads="); - if (tmp == NULL) + if (tmp == NULL) { dbcount = 1; - else { + } else { dbcount = strtol(tmp, &endp, 10); if (*endp != '\0' || dbcount < 1) { s3->log(ISC_LOG_ERROR, "SQLite3 module: database " @@ -1026,13 +1051,13 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, /* when multithreaded, build a list of DBI's */ DLZ_LINK_INIT(dbi, link); DLZ_LIST_APPEND(*(s3->db), dbi, link); -#else +#else /* if PTHREADS */ /* * when single threaded, hold onto the one connection * instance. */ s3->db = dbi; -#endif +#endif /* if PTHREADS */ dbi->dbconn = dbc; dbc = NULL; @@ -1060,14 +1085,16 @@ dlz_destroy(void *dbdata) sqlite3_instance_t *db = (sqlite3_instance_t *)dbdata; #if PTHREADS /* cleanup the list of DBI's */ - if (db->db != NULL) + if (db->db != NULL) { sqlite3_destroy_dblist((db_list_t *)(db->db)); + } #else /* PTHREADS */ sqlite3_destroy(db); #endif /* PTHREADS */ - if (db->dbname != NULL) + if (db->dbname != NULL) { free(db->dbname); + } } /* @@ -1087,12 +1114,16 @@ dlz_version(unsigned int *flags) static void b9_add_helper(sqlite3_instance_t *db, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { db->log = (log_t *)ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { db->putrr = (dns_sdlz_putrr_t *)ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { db->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { db->writeable_zone = (dns_dlz_writeablezone_t *)ptr; + } } diff --git a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c index 9146b0fb86..e177263eb3 100644 --- a/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c +++ b/contrib/dlz/modules/wildcard/dlz_wildcard_dynamic.c @@ -161,8 +161,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) result = cd->putnamedrr(allnodes, nrec->name, nrec->type, nrec->ttl, querystring); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } nrec = DLZ_LIST_NEXT(nrec, link); } @@ -170,8 +171,9 @@ dlz_allnodes(const char *zone, void *dbdata, dns_sdlzallnodes_t *allnodes) done: cd->zone = NULL; - if (querystring != NULL) + if (querystring != NULL) { free(querystring); + } return (result); } @@ -187,20 +189,21 @@ dlz_allowzonexfr(void *dbdata, const char *name, const char *client) cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard allowzonexfr called for client '%s'", client); - if (fnmatch(cd->axfr_pattern, client, FNM_CASEFOLD) == 0) + if (fnmatch(cd->axfr_pattern, client, FNM_CASEFOLD) == 0) { return (ISC_R_SUCCESS); - else + } else { return (ISC_R_NOTFOUND); + } } #if DLZ_DLOPEN_VERSION < 3 isc_result_t dlz_findzonedb(void *dbdata, const char *name) -#else +#else /* if DLZ_DLOPEN_VERSION < 3 */ isc_result_t dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION < 3 */ { config_data_t *cd = (config_data_t *)dbdata; const char * p; @@ -208,11 +211,12 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, #if DLZ_DLOPEN_VERSION >= 3 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 3 */ p = shortest_match(cd->zone_pattern, name); - if (p == NULL) + if (p == NULL) { return (ISC_R_NOTFOUND); + } /* Write info message to log */ cd->log(ISC_LOG_DEBUG(1), "dlz_wildcard findzonedb matched '%s'", p); @@ -224,12 +228,12 @@ dlz_findzonedb(void *dbdata, const char *name, dns_clientinfomethods_t *methods, isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup) -#else +#else /* if DLZ_DLOPEN_VERSION == 1 */ isc_result_t dlz_lookup(const char *zone, const char *name, void *dbdata, dns_sdlzlookup_t *lookup, dns_clientinfomethods_t *methods, dns_clientinfo_t *clientinfo) -#endif +#endif /* if DLZ_DLOPEN_VERSION == 1 */ { isc_result_t result; config_data_t *cd = (config_data_t *)dbdata; @@ -242,11 +246,12 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, #if DLZ_DLOPEN_VERSION >= 2 UNUSED(methods); UNUSED(clientinfo); -#endif +#endif /* if DLZ_DLOPEN_VERSION >= 2 */ p = shortest_match(cd->zone_pattern, zone); - if (p == NULL) + if (p == NULL) { return (ISC_R_NOTFOUND); + } DE_CONST(name, cd->record); DE_CONST(p, cd->zone); @@ -255,14 +260,16 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, (strcmp(name, "@") == 0 || strcmp(name, zone) == 0)) { size_t len = p - zone; namebuf = malloc(len); - if (namebuf == NULL) + if (namebuf == NULL) { return (ISC_R_NOMEMORY); + } strncpy(namebuf, zone, len - 1); namebuf[len - 1] = '\0'; cd->record = namebuf; origin = false; - } else if (p == zone) + } else if (p == zone) { cd->record = "@"; + } /* Write info message to log */ cd->log(ISC_LOG_DEBUG(1), @@ -290,8 +297,9 @@ dlz_lookup(const char *zone, const char *name, void *dbdata, result = cd->putrr(lookup, nrec->type, nrec->ttl, querystring); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } result = ISC_R_SUCCESS; @@ -305,8 +313,9 @@ done: cd->zone = NULL; cd->record = NULL; - if (querystring != NULL) + if (querystring != NULL) { free(querystring); + } return (result); } @@ -321,8 +330,9 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) const char * p, *name = "@"; p = shortest_match(cd->zone_pattern, zone); - if (p == NULL) + if (p == NULL) { return (ISC_R_NOTFOUND); + } DE_CONST(p, cd->zone); @@ -361,8 +371,9 @@ dlz_authority(const char *zone, void *dbdata, dns_sdlzlookup_t *lookup) done: cd->zone = NULL; - if (querystring != NULL) + if (querystring != NULL) { free(querystring); + } return (result); } @@ -379,10 +390,12 @@ destroy_rrlist(config_data_t *cd) destroy_querylist(&trec->data); - if (trec->name != NULL) + if (trec->name != NULL) { free(trec->name); - if (trec->type != NULL) + } + if (trec->type != NULL) { free(trec->type); + } trec->name = trec->type = NULL; /* Get the next record, before we destroy this one. */ @@ -404,18 +417,21 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, const char * helper_name; va_list ap; - if (argc < 8 || argc % 4 != 0) + if (argc < 8 || argc % 4 != 0) { return (ISC_R_FAILURE); + } cd = calloc(1, sizeof(config_data_t)); - if (cd == NULL) + if (cd == NULL) { return (ISC_R_NOMEMORY); + } memset(cd, 0, sizeof(config_data_t)); /* Fill in the helper functions */ va_start(ap, dbdata); - while ((helper_name = va_arg(ap, const char *)) != NULL) + while ((helper_name = va_arg(ap, const char *)) != NULL) { b9_add_helper(cd, helper_name, va_arg(ap, void *)); + } va_end(ap); /* @@ -446,8 +462,9 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, result = ISC_R_NOMEMORY; trec = malloc(sizeof(nrr_t)); - if (trec == NULL) + if (trec == NULL) { goto full_cleanup; + } memset(trec, 0, sizeof(nrr_t)); @@ -457,16 +474,19 @@ dlz_create(const char *dlzname, unsigned int argc, char *argv[], void **dbdata, DLZ_LIST_APPEND(cd->rrs_list, trec, link); trec->name = strdup(argv[i]); - if (trec->name == NULL) + if (trec->name == NULL) { goto full_cleanup; + } trec->type = strdup(argv[i + 2]); - if (trec->type == NULL) + if (trec->type == NULL) { goto full_cleanup; + } trec->ttl = strtol(argv[i + 1], &endp, 10); - if (argv[i + 1][0] == '\0' || *endp != '\0' || trec->ttl < 0) + if (argv[i + 1][0] == '\0' || *endp != '\0' || trec->ttl < 0) { trec->ttl = def_ttl; + } result = build_querylist(argv[i + 3], &cd->zone, &cd->record, &cd->client, &trec->data, 0, cd->log); @@ -487,10 +507,12 @@ full_cleanup: destroy_rrlist(cd); cleanup: - if (cd->zone_pattern != NULL) + if (cd->zone_pattern != NULL) { free(cd->zone_pattern); - if (cd->axfr_pattern != NULL) + } + if (cd->axfr_pattern != NULL) { free(cd->axfr_pattern); + } free(cd); return (result); @@ -530,32 +552,39 @@ dlz_version(unsigned int *flags) static void b9_add_helper(struct config_data *cd, const char *helper_name, void *ptr) { - if (strcmp(helper_name, "log") == 0) + if (strcmp(helper_name, "log") == 0) { cd->log = (log_t *)ptr; - if (strcmp(helper_name, "putrr") == 0) + } + if (strcmp(helper_name, "putrr") == 0) { cd->putrr = (dns_sdlz_putrr_t *)ptr; - if (strcmp(helper_name, "putnamedrr") == 0) + } + if (strcmp(helper_name, "putnamedrr") == 0) { cd->putnamedrr = (dns_sdlz_putnamedrr_t *)ptr; - if (strcmp(helper_name, "writeable_zone") == 0) + } + if (strcmp(helper_name, "writeable_zone") == 0) { cd->writeable_zone = (dns_dlz_writeablezone_t *)ptr; + } } static const char * shortest_match(const char *pattern, const char *string) { const char *p = string; - if (pattern == NULL || p == NULL || *p == '\0') + if (pattern == NULL || p == NULL || *p == '\0') { return (NULL); + } p += strlen(p); while (p-- > string) { if (*p == '.') { - if (fnmatch(pattern, p + 1, FNM_CASEFOLD) == 0) + if (fnmatch(pattern, p + 1, FNM_CASEFOLD) == 0) { return (p + 1); + } } } - if (fnmatch(pattern, string, FNM_CASEFOLD) == 0) + if (fnmatch(pattern, string, FNM_CASEFOLD) == 0) { return (string); + } return (NULL); } @@ -584,67 +613,80 @@ fnmatch(const char *pattern, const char *string, int flags) for (stringstart = string;;) switch (c = *pattern++) { case EOS: - if ((flags & FNM_LEADING_DIR) && *string == '/') + if ((flags & FNM_LEADING_DIR) && *string == '/') { return (0); + } return (*string == EOS ? 0 : FNM_NOMATCH); case '?': - if (*string == EOS) + if (*string == EOS) { return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) + } + if (*string == '/' && (flags & FNM_PATHNAME)) { return (FNM_NOMATCH); + } if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + (string == stringstart || ((flags & FNM_PATHNAME) && + *(string - 1) == '/'))) { return (FNM_NOMATCH); + } ++string; break; case '*': c = *pattern; /* Collapse multiple stars. */ - while (c == '*') + while (c == '*') { c = *++pattern; + } if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + (string == stringstart || ((flags & FNM_PATHNAME) && + *(string - 1) == '/'))) { return (FNM_NOMATCH); + } /* Optimize for pattern with * at end or before /. */ - if (c == EOS) - if (flags & FNM_PATHNAME) + if (c == EOS) { + if (flags & FNM_PATHNAME) { return ((flags & FNM_LEADING_DIR) || index(string, '/') == NULL ? 0 : FNM_NOMATCH); - else + } else { return (0); - else if (c == '/' && flags & FNM_PATHNAME) { - if ((string = index(string, '/')) == NULL) + } + } else if (c == '/' && flags & FNM_PATHNAME) { + if ((string = index(string, '/')) == NULL) { return (FNM_NOMATCH); + } break; } /* General case, use recursion. */ while ((test = *string) != EOS) { if (!fnmatch(pattern, string, - flags & ~FNM_PERIOD)) + flags & ~FNM_PERIOD)) { return (0); - if (test == '/' && flags & FNM_PATHNAME) + } + if (test == '/' && flags & FNM_PATHNAME) { break; + } ++string; } return (FNM_NOMATCH); case '[': - if (*string == EOS) + if (*string == EOS) { return (FNM_NOMATCH); - if (*string == '/' && (flags & FNM_PATHNAME)) + } + if (*string == '/' && (flags & FNM_PATHNAME)) { return (FNM_NOMATCH); + } if (*string == '.' && (flags & FNM_PERIOD) && - (string == stringstart || - ((flags & FNM_PATHNAME) && *(string - 1) == '/'))) + (string == stringstart || ((flags & FNM_PATHNAME) && + *(string - 1) == '/'))) { return (FNM_NOMATCH); + } switch (rangematch(pattern, *string, flags, &newp)) { case RANGE_ERROR: @@ -664,17 +706,16 @@ fnmatch(const char *pattern, const char *string, int flags) --pattern; } } - /* FALLTHROUGH */ + /* FALLTHROUGH */ default: norm: - if (c == *string) - ; - else if ((flags & FNM_CASEFOLD) && - (tolower((unsigned char)c) == - tolower((unsigned char)*string))) - ; - else + if (c == *string) { + } else if ((flags & FNM_CASEFOLD) && + (tolower((unsigned char)c) == + tolower((unsigned char)*string))) { + } else { return (FNM_NOMATCH); + } string++; break; } @@ -694,11 +735,13 @@ rangematch(const char *pattern, char test, int flags, char **newp) * consistency with the regular expression syntax. * J.T. Conklin (conklin@ngai.kaleida.com) */ - if ((negate = (*pattern == '!' || *pattern == '^'))) + if ((negate = (*pattern == '!' || *pattern == '^'))) { ++pattern; + } - if (flags & FNM_CASEFOLD) + if (flags & FNM_CASEFOLD) { test = tolower((unsigned char)test); + } /* * A right bracket shall lose its special meaning and represent @@ -708,32 +751,41 @@ rangematch(const char *pattern, char test, int flags, char **newp) ok = 0; c = *pattern++; do { - if (c == '\\' && !(flags & FNM_NOESCAPE)) + if (c == '\\' && !(flags & FNM_NOESCAPE)) { c = *pattern++; - if (c == EOS) + } + if (c == EOS) { return (RANGE_ERROR); + } - if (c == '/' && (flags & FNM_PATHNAME)) + if (c == '/' && (flags & FNM_PATHNAME)) { return (RANGE_NOMATCH); + } - if (flags & FNM_CASEFOLD) + if (flags & FNM_CASEFOLD) { c = tolower((unsigned char)c); + } if (*pattern == '-' && (c2 = *(pattern + 1)) != EOS && c2 != ']') { pattern += 2; - if (c2 == '\\' && !(flags & FNM_NOESCAPE)) + if (c2 == '\\' && !(flags & FNM_NOESCAPE)) { c2 = *pattern++; - if (c2 == EOS) + } + if (c2 == EOS) { return (RANGE_ERROR); + } - if (flags & FNM_CASEFOLD) + if (flags & FNM_CASEFOLD) { c2 = tolower((unsigned char)c2); + } - if (c <= test && test <= c2) + if (c <= test && test <= c2) { ok = 1; - } else if (c == test) + } + } else if (c == test) { ok = 1; + } } while ((c = *pattern++) != ']'); *newp = (char *)(uintptr_t)pattern; diff --git a/fuzz/dns_name_fromtext_target.c b/fuzz/dns_name_fromtext_target.c index 3c884b9231..b4aa9078bf 100644 --- a/fuzz/dns_name_fromtext_target.c +++ b/fuzz/dns_name_fromtext_target.c @@ -30,7 +30,7 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) char * de_const; if (size < 5) { - return 0; + return (0); } dns_fixedname_init(&origin); @@ -40,5 +40,5 @@ LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) result = dns_name_fromtext(dns_fixedname_name(&origin), &buf, dns_rootname, 0, NULL); UNUSED(result); - return 0; + return (0); } diff --git a/fuzz/main.c b/fuzz/main.c index c109874555..eef2f12182 100644 --- a/fuzz/main.c +++ b/fuzz/main.c @@ -108,7 +108,7 @@ main(int argc, char **argv) test_all_from(corpusdir); - return 0; + return (0); } #elif __AFL_COMPILER @@ -123,19 +123,19 @@ main(int argc, char **argv) UNUSED(argv); #ifdef __AFL_LOOP - while (__AFL_LOOP(10000)) { // only works with afl-clang-fast -#else + while (__AFL_LOOP(10000)) { /* only works with afl-clang-fast */ +#else /* ifdef __AFL_LOOP */ { -#endif +#endif /* ifdef __AFL_LOOP */ ret = fread(buf, 1, sizeof(buf), stdin); if (ret < 0) { - return 0; + return (0); } LLVMFuzzerTestOneInput(buf, ret); } - return 0; + return (0); } #endif /* FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ diff --git a/lib/bind9/check.c b/lib/bind9/check.c index e34c88a56b..229b59cd78 100644 --- a/lib/bind9/check.c +++ b/lib/bind9/check.c @@ -94,8 +94,9 @@ check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) if (tresult != ISC_R_SUCCESS) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "rrset-order: invalid class '%s'", r.base); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } @@ -107,8 +108,9 @@ check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) if (tresult != ISC_R_SUCCESS) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "rrset-order: invalid type '%s'", r.base); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } @@ -122,8 +124,9 @@ check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) if (tresult != ISC_R_SUCCESS) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "rrset-order: invalid name '%s'", str); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } @@ -132,30 +135,33 @@ check_orderent(const cfg_obj_t *ent, isc_log_t *logctx) strcasecmp("order", cfg_obj_asstring(obj)) != 0) { cfg_obj_log(ent, logctx, ISC_LOG_ERROR, "rrset-order: keyword 'order' missing"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } obj = cfg_tuple_get(ent, "ordering"); if (!cfg_obj_isstring(obj)) { cfg_obj_log(ent, logctx, ISC_LOG_ERROR, "rrset-order: missing ordering"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } else if (strcasecmp(cfg_obj_asstring(obj), "fixed") == 0) { #if !DNS_RDATASET_FIXED cfg_obj_log(obj, logctx, ISC_LOG_WARNING, "rrset-order: order 'fixed' was disabled at " "compilation time"); -#endif +#endif /* if !DNS_RDATASET_FIXED */ } else if (strcasecmp(cfg_obj_asstring(obj), "random") != 0 && strcasecmp(cfg_obj_asstring(obj), "cyclic") != 0 && strcasecmp(cfg_obj_asstring(obj), "none") != 0) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "rrset-order: invalid order '%s'", cfg_obj_asstring(obj)); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } return (result); } @@ -168,14 +174,16 @@ check_order(const cfg_obj_t *options, isc_log_t *logctx) const cfg_listelt_t *element; const cfg_obj_t * obj = NULL; - if (cfg_map_get(options, "rrset-order", &obj) != ISC_R_SUCCESS) + if (cfg_map_get(options, "rrset-order", &obj) != ISC_R_SUCCESS) { return (result); + } for (element = cfg_list_first(obj); element != NULL; element = cfg_list_next(element)) { tresult = check_orderent(cfg_listelt_value(element), logctx); - if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) { result = tresult; + } } return (result); } @@ -196,8 +204,9 @@ check_dual_stack(const cfg_obj_t *options, isc_log_t *logctx) (void)cfg_map_get(options, "dual-stack-servers", &alternates); - if (alternates == NULL) + if (alternates == NULL) { return (ISC_R_SUCCESS); + } obj = cfg_tuple_get(alternates, "port"); if (cfg_obj_isuint32(obj)) { @@ -205,16 +214,18 @@ check_dual_stack(const cfg_obj_t *options, isc_log_t *logctx) if (val > UINT16_MAX) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "port '%u' out of range", val); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } } obj = cfg_tuple_get(alternates, "addresses"); for (element = cfg_list_first(obj); element != NULL; element = cfg_list_next(element)) { value = cfg_listelt_value(element); - if (cfg_obj_issockaddr(value)) + if (cfg_obj_issockaddr(value)) { continue; + } obj = cfg_tuple_get(value, "name"); str = cfg_obj_asstring(obj); isc_buffer_constinit(&buffer, str, strlen(str)); @@ -225,8 +236,9 @@ check_dual_stack(const cfg_obj_t *options, isc_log_t *logctx) if (tresult != ISC_R_SUCCESS) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "bad name '%s'", str); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = tresult; + } } obj = cfg_tuple_get(value, "port"); if (cfg_obj_isuint32(obj)) { @@ -234,8 +246,9 @@ check_dual_stack(const cfg_obj_t *options, isc_log_t *logctx) if (val > UINT16_MAX) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "port '%u' out of range", val); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } } } @@ -381,8 +394,9 @@ nameexist(const cfg_obj_t *obj, const char *name, int value, file = cfg_obj_file(symvalue.as_cpointer); line = cfg_obj_line(symvalue.as_cpointer); - if (file == NULL) + if (file == NULL) { file = ""; + } cfg_obj_log(obj, logctx, ISC_LOG_ERROR, fmt, key, file, line); isc_mem_free(mctx, key); result = ISC_R_EXISTS; @@ -437,20 +451,24 @@ checkacl(const char *aclname, cfg_aclconfctx_t *actx, const cfg_obj_t *zconfig, options = cfg_tuple_get(zconfig, "options"); cfg_map_get(options, aclname, &aclobj); } - if (voptions != NULL && aclobj == NULL) + if (voptions != NULL && aclobj == NULL) { cfg_map_get(voptions, aclname, &aclobj); + } if (config != NULL && aclobj == NULL) { options = NULL; cfg_map_get(config, "options", &options); - if (options != NULL) + if (options != NULL) { cfg_map_get(options, aclname, &aclobj); + } } - if (aclobj == NULL) + if (aclobj == NULL) { return (ISC_R_SUCCESS); + } result = cfg_acl_fromconfig(aclobj, config, logctx, actx, mctx, 0, &acl); - if (acl != NULL) + if (acl != NULL) { dns_acl_detach(&acl); + } return (result); } @@ -472,8 +490,9 @@ check_viewacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, while (acls[i] != NULL) { tresult = checkacl(acls[i++], actx, NULL, voptions, config, logctx, mctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } return (result); } @@ -496,16 +515,19 @@ check_dns64(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, static const char *acls[] = { "clients", "exclude", "mapped", NULL }; - if (voptions != NULL) + if (voptions != NULL) { cfg_map_get(voptions, "dns64", &dns64); + } if (config != NULL && dns64 == NULL) { options = NULL; cfg_map_get(config, "options", &options); - if (options != NULL) + if (options != NULL) { cfg_map_get(options, "dns64", &dns64); + } } - if (dns64 == NULL) + if (dns64 == NULL) { return (ISC_R_SUCCESS); + } for (element = cfg_list_first(dns64); element != NULL; element = cfg_list_next(element)) { @@ -547,10 +569,12 @@ check_dns64(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, tresult = cfg_acl_fromconfig(obj, config, logctx, actx, mctx, 0, &acl); - if (acl != NULL) + if (acl != NULL) { dns_acl_detach(&acl); - if (tresult != ISC_R_SUCCESS) + } + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } } @@ -565,8 +589,9 @@ check_dns64(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, continue; } nbytes = prefixlen / 8 + 4; - if (prefixlen <= 64) + if (prefixlen <= 64) { nbytes++; + } if (memcmp(sa.type.in6.s6_addr, zeros, nbytes) != 0) { char netaddrbuf[ISC_NETADDR_FORMATSIZE]; isc_netaddr_format(&sa, netaddrbuf, @@ -622,24 +647,28 @@ check_ratelimit(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, int responses_per_second; int slip; - if (voptions != NULL) + if (voptions != NULL) { cfg_map_get(voptions, "rate-limit", &map); + } if (config != NULL && map == NULL) { options = NULL; cfg_map_get(config, "options", &options); - if (options != NULL) + if (options != NULL) { cfg_map_get(options, "rate-limit", &map); + } } - if (map == NULL) + if (map == NULL) { return (ISC_R_SUCCESS); + } min_entries = 500; obj = NULL; mresult = cfg_map_get(map, "min-table-size", &obj); if (mresult == ISC_R_SUCCESS) { min_entries = cfg_obj_asuint32(obj); - if (min_entries < 1) + if (min_entries < 1) { min_entries = 1; + } } obj = NULL; @@ -707,10 +736,12 @@ check_ratelimit(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, tresult = cfg_acl_fromconfig(obj, config, logctx, actx, mctx, 0, &acl); - if (acl != NULL) + if (acl != NULL) { dns_acl_detach(&acl); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { result = tresult; + } } return (result); @@ -735,18 +766,21 @@ check_recursionacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, static const char *acls[] = { "allow-recursion", "allow-recursion-on", NULL }; - if (voptions != NULL) + if (voptions != NULL) { cfg_map_get(voptions, "recursion", &obj); + } if (obj == NULL && config != NULL) { options = NULL; cfg_map_get(config, "options", &options); - if (options != NULL) + if (options != NULL) { cfg_map_get(options, "recursion", &obj); + } } - if (obj == NULL) + if (obj == NULL) { recursion = true; - else + } else { recursion = cfg_obj_asboolean(obj); + } if (viewname == NULL) { viewname = ""; @@ -757,25 +791,30 @@ check_recursionacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, aclobj = options = NULL; acl = NULL; - if (voptions != NULL) + if (voptions != NULL) { cfg_map_get(voptions, acls[i], &aclobj); + } if (config != NULL && aclobj == NULL) { options = NULL; cfg_map_get(config, "options", &options); - if (options != NULL) + if (options != NULL) { cfg_map_get(options, acls[i], &aclobj); + } } - if (aclobj == NULL) + if (aclobj == NULL) { continue; + } tresult = cfg_acl_fromconfig(aclobj, config, logctx, actx, mctx, 0, &acl); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } - if (acl == NULL) + if (acl == NULL) { continue; + } if (recursion == false && !dns_acl_isnone(acl)) { cfg_obj_log(aclobj, logctx, ISC_LOG_WARNING, @@ -784,8 +823,9 @@ check_recursionacls(cfg_aclconfctx_t *actx, const cfg_obj_t *voptions, acls[i], forview, viewname); } - if (acl != NULL) + if (acl != NULL) { dns_acl_detach(&acl); + } } return (result); @@ -803,7 +843,7 @@ typedef struct { unsigned int min; unsigned int max; } fstrmtable; -#endif +#endif /* ifdef HAVE_DNSTAP */ typedef enum { optlevel_config, @@ -851,12 +891,12 @@ kasp_name_allowed(const cfg_listelt_t *element) cfg_tuple_get(cfg_listelt_value(element), "name")); if (strcmp("none", name) == 0) { - return false; + return (false); } if (strcmp("default", name) == 0) { - return false; + return (false); } - return true; + return (true); } static isc_result_t @@ -917,7 +957,7 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, { "fstrm-set-reopen-interval", FSTRM_IOTHR_REOPEN_INTERVAL_MIN, FSTRM_IOTHR_REOPEN_INTERVAL_MAX } }; -#endif +#endif /* ifdef HAVE_DNSTAP */ /* * Check that fields specified in units of time other than seconds @@ -927,8 +967,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, uint32_t val; obj = NULL; (void)cfg_map_get(options, intervals[i].name, &obj); - if (obj == NULL) + if (obj == NULL) { continue; + } if (cfg_obj_isduration(obj)) { val = cfg_obj_asduration(obj); } else { @@ -1048,8 +1089,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, validity = cfg_obj_asuint32(cfg_tuple_get(obj, "validity")); resignobj = cfg_tuple_get(obj, "re-sign"); - if (!cfg_obj_isvoid(resignobj)) + if (!cfg_obj_isvoid(resignobj)) { resign = cfg_obj_asuint32(resignobj); + } if (validity > 3660 || validity == 0) { /* 10 years */ cfg_obj_log(obj, logctx, ISC_LOG_ERROR, @@ -1111,10 +1153,11 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (obj != NULL) { str = cfg_obj_asstring(obj); if (strcasecmp(str, "a") != 0 && strcasecmp(str, "aaaa") != 0 && - strcasecmp(str, "none") != 0) + strcasecmp(str, "none") != 0) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "preferred-glue unexpected value '%s'", str); + } } obj = NULL; @@ -1148,8 +1191,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, element = cfg_list_next(element)) { obj = cfg_listelt_value(element); tresult = disabled_algorithms(obj, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } } @@ -1163,8 +1207,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, element = cfg_list_next(element)) { obj = cfg_listelt_value(element); tresult = disabled_ds_digests(obj, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } } @@ -1179,8 +1224,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "auto-dnssec may only be activated at the " "zone level"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } @@ -1192,14 +1238,17 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (obj != NULL) { tresult = isc_symtab_create(mctx, 100, freekey, mctx, false, &symtab); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } for (element = cfg_list_first(obj); element != NULL; element = cfg_list_next(element)) { obj = cfg_listelt_value(element); tresult = mustbesecure(obj, symtab, logctx, mctx); - if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS && + tresult != ISC_R_SUCCESS) { result = tresult; + } } if (symtab != NULL) { isc_symtab_destroy(&symtab); @@ -1218,8 +1267,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "%s: invalid name '%s'", server_contact[i], str); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } } @@ -1237,8 +1287,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "disable-empty-zone: invalid name '%s'", str); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } @@ -1252,13 +1303,15 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, strlen(cfg_obj_asstring(obj)) > 1024U) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "'server-id' too big (>1024 bytes)"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } tresult = check_dscp(options, logctx); - if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS && tresult != ISC_R_SUCCESS) { result = tresult; + } obj = NULL; (void)cfg_map_get(options, "nta-lifetime", &obj); @@ -1267,13 +1320,15 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (lifetime > 604800) { /* 7 days */ cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "'nta-lifetime' cannot exceed one week"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } else if (lifetime == 0) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "'nta-lifetime' may not be zero"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } } @@ -1284,16 +1339,18 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (recheck > 604800) { /* 7 days */ cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "'nta-recheck' cannot exceed one week"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } - if (recheck > lifetime) + if (recheck > lifetime) { cfg_obj_log(obj, logctx, ISC_LOG_WARNING, "'nta-recheck' (%d seconds) is " "greater than 'nta-lifetime' " "(%d seconds)", recheck, lifetime); + } } obj = NULL; @@ -1326,8 +1383,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, "string"); } if (tresult != ISC_R_SUCCESS) { - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = tresult; + } continue; } @@ -1337,16 +1395,18 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "AES cookie-secret must be 128 " "bits"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } if (strcasecmp(ccalg, "siphash24") == 0 && usedlength != ISC_SIPHASH24_KEY_LENGTH) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "SipHash-2-4 cookie-secret must be " "128 bits"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } } } @@ -1357,8 +1417,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, obj = NULL; (void)cfg_map_get(options, fstrm[i].name, &obj); - if (obj == NULL) + if (obj == NULL) { continue; + } if (cfg_obj_isduration(obj)) { value = cfg_obj_asduration(obj); @@ -1367,17 +1428,19 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, } if (value < fstrm[i].min || (fstrm[i].max != 0U && value > fstrm[i].max)) { - if (fstrm[i].max != 0U) + if (fstrm[i].max != 0U) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "%s '%u' out of range (%u..%u)", fstrm[i].name, value, fstrm[i].min, fstrm[i].max); - else + } else { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "%s out of range (%u < %u)", fstrm[i].name, value, fstrm[i].min); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } if (strcmp(fstrm[i].name, "fstrm-set-input-queue-size") == 0) { @@ -1391,8 +1454,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, "%s '%u' not a power-of-2", fstrm[i].name, cfg_obj_asuint32(obj)); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } } } @@ -1408,13 +1472,15 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (obj2 == NULL) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "dnstap-output mode not found"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } else { - if (strcasecmp(cfg_obj_asstring(obj2), "file") == 0) + if (strcasecmp(cfg_obj_asstring(obj2), "file") == 0) { dmode = dns_dtmode_file; - else + } else { dmode = dns_dtmode_unix; + } obj2 = cfg_tuple_get(obj, "size"); if (obj2 != NULL && !cfg_obj_isvoid(obj2) && @@ -1422,8 +1488,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "dnstap-output size " "cannot be set with mode unix"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } obj2 = cfg_tuple_get(obj, "versions"); @@ -1432,8 +1499,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "dnstap-output versions " "cannot be set with mode unix"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } obj2 = cfg_tuple_get(obj, "suffix"); @@ -1442,12 +1510,13 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "dnstap-output suffix " "cannot be set with mode unix"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } } -#endif +#endif /* ifdef HAVE_DNSTAP */ obj = NULL; (void)cfg_map_get(options, "lmdb-mapsize", &obj); @@ -1460,16 +1529,18 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, "%" PRId64 "' " "is too small", mapsize); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } else if (mapsize > (1ULL << 40)) { /* 1 terabyte */ cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "'lmdb-mapsize " "%" PRId64 "' " "is too large", mapsize); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } } @@ -1478,8 +1549,9 @@ check_options(const cfg_obj_t *options, isc_log_t *logctx, isc_mem_t *mctx, if (obj != NULL && cfg_obj_asuint32(obj) == 0U) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "'resolver-nonbackoff-tries' must be >= 1"); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_RANGE; + } } obj = NULL; @@ -1504,8 +1576,9 @@ get_masters_def(const cfg_obj_t *cctx, const char *name, const cfg_obj_t **ret) 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; @@ -1564,19 +1637,22 @@ resume: cfg_obj_log(key, logctx, ISC_LOG_ERROR, "unexpected token '%s'", cfg_obj_asstring(key)); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } listname = cfg_obj_asstring(addr); symvalue.as_cpointer = addr; tresult = isc_symtab_define(symtab, listname, 1, symvalue, isc_symexists_reject); - if (tresult == ISC_R_EXISTS) + if (tresult == ISC_R_EXISTS) { continue; + } tresult = get_masters_def(config, listname, &obj); if (tresult != ISC_R_SUCCESS) { - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = tresult; + } cfg_obj_log(addr, logctx, ISC_LOG_ERROR, "unable to find masters list '%s'", listname); @@ -1634,8 +1710,9 @@ check_update_policy(const cfg_obj_t *policy, isc_log_t *logctx) /* Check for "update-policy local;" */ if (cfg_obj_isstring(policy) && - strcmp("local", cfg_obj_asstring(policy)) == 0) + strcmp("local", cfg_obj_asstring(policy)) == 0) { return (ISC_R_SUCCESS); + } /* Now check the grant policy */ for (element = cfg_list_first(policy); element != NULL; @@ -1955,8 +2032,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, zoptions = cfg_tuple_get(zconfig, "options"); - if (config != NULL) + if (config != NULL) { cfg_map_get(config, "options", &goptions); + } inviewobj = NULL; (void)cfg_map_get(zoptions, "in-view", &inviewobj); @@ -2061,14 +2139,16 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, "zone '%s': already exists " "previous definition: %s:%u", logctx, mctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; - if (dns_name_equal(zname, dns_rootname)) + } + if (dns_name_equal(zname, dns_rootname)) { root = true; - else if (dns_name_isrfc1918(zname)) + } else if (dns_name_isrfc1918(zname)) { rfc1918 = true; - else if (dns_name_isula(zname)) + } else if (dns_name_isula(zname)) { ula = true; + } tmp += strlen(tmp); len -= strlen(tmp); (void)snprintf(tmp, len, "%u/%s", zclass, @@ -2113,8 +2193,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, isc_mem_free(mctx, tmp); } if (result == ISC_R_SUCCESS && - tresult != ISC_R_SUCCESS) + tresult != ISC_R_SUCCESS) { result = tresult; + } } break; @@ -2129,19 +2210,22 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, unsigned int maxopts = 1; (void)cfg_map_get(zoptions, "forward", &fwd); - if (fwd != NULL) + if (fwd != NULL) { maxopts++; + } fwd = NULL; (void)cfg_map_get(zoptions, "forwarders", &fwd); - if (fwd != NULL) + if (fwd != NULL) { maxopts++; + } if (cfg_map_count(zoptions) > maxopts) { cfg_obj_log(zconfig, logctx, ISC_LOG_ERROR, "zone '%s': 'in-view' used " "with incompatible zone options", znamestr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } return (result); } @@ -2149,8 +2233,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, /* * Check if value is zero. */ - if (check_nonzero(zoptions, logctx) != ISC_R_SUCCESS) + if (check_nonzero(zoptions, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } /* * Check if a dnssec-policy is set. @@ -2236,18 +2321,21 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, obj = NULL; tresult = cfg_map_get(zoptions, "notify", &obj); - if (tresult != ISC_R_SUCCESS && voptions != NULL) + if (tresult != ISC_R_SUCCESS && voptions != NULL) { tresult = cfg_map_get(voptions, "notify", &obj); - if (tresult != ISC_R_SUCCESS && goptions != NULL) + } + if (tresult != ISC_R_SUCCESS && goptions != NULL) { tresult = cfg_map_get(goptions, "notify", &obj); + } if (tresult == ISC_R_SUCCESS) { - if (cfg_obj_isboolean(obj)) + if (cfg_obj_isboolean(obj)) { donotify = cfg_obj_asboolean(obj); - else { + } else { const char *notifystr = cfg_obj_asstring(obj); if (ztype != CFG_ZONE_MASTER && - strcasecmp(notifystr, "master-only") == 0) + strcasecmp(notifystr, "master-only") == 0) { donotify = false; + } } } @@ -2259,16 +2347,20 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, "'notify' is disabled", znamestr); } - if (tresult != ISC_R_SUCCESS && voptions != NULL) + if (tresult != ISC_R_SUCCESS && voptions != NULL) { tresult = cfg_map_get(voptions, "also-notify", &obj); - if (tresult != ISC_R_SUCCESS && goptions != NULL) + } + if (tresult != ISC_R_SUCCESS && goptions != NULL) { tresult = cfg_map_get(goptions, "also-notify", &obj); + } if (tresult == ISC_R_SUCCESS && donotify) { uint32_t count; tresult = validate_masters(obj, config, &count, logctx, mctx); - if (tresult != ISC_R_SUCCESS && result == ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS && + result == ISC_R_SUCCESS) { result = tresult; + } } } @@ -2290,8 +2382,10 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, uint32_t count; tresult = validate_masters(obj, config, &count, logctx, mctx); - if (tresult != ISC_R_SUCCESS && result == ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS && + result == ISC_R_SUCCESS) { result = tresult; + } if (tresult == ISC_R_SUCCESS && count == 0) { cfg_obj_log(zoptions, logctx, ISC_LOG_ERROR, "zone '%s': empty 'masters' entry", @@ -2335,8 +2429,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, result = ISC_R_FAILURE; } else if (res2 == ISC_R_SUCCESS) { res3 = check_update_policy(obj, logctx); - if (res3 != ISC_R_SUCCESS) + if (res3 != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } /* @@ -2344,14 +2439,16 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, * we should also check for allow-update at the * view and options levels. */ - if (res1 != ISC_R_SUCCESS && voptions != NULL) + if (res1 != ISC_R_SUCCESS && voptions != NULL) { res1 = cfg_map_get(voptions, "allow-update", &au); - if (res1 != ISC_R_SUCCESS && goptions != NULL) + } + if (res1 != ISC_R_SUCCESS && goptions != NULL) { res1 = cfg_map_get(goptions, "allow-update", &au); + } - if (res2 == ISC_R_SUCCESS) + if (res2 == ISC_R_SUCCESS) { ddns = true; - else if (res1 == ISC_R_SUCCESS) { + } else if (res1 == ISC_R_SUCCESS) { dns_acl_t *acl = NULL; res1 = cfg_acl_fromconfig(au, config, logctx, actx, mctx, 0, &acl); @@ -2361,16 +2458,18 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, isc_result_totext(result)); result = ISC_R_FAILURE; } else if (acl != NULL) { - if (!dns_acl_isnone(acl)) + if (!dns_acl_isnone(acl)) { ddns = true; + } dns_acl_detach(&acl); } } obj = NULL; res1 = cfg_map_get(zoptions, "inline-signing", &obj); - if (res1 == ISC_R_SUCCESS) + if (res1 == ISC_R_SUCCESS) { signing = cfg_obj_asboolean(obj); + } if (signing && has_dnssecpolicy) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, @@ -2413,11 +2512,12 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, res1 = cfg_map_get(zoptions, "sig-signing-type", &obj); if (res1 == ISC_R_SUCCESS) { uint32_t type = cfg_obj_asuint32(obj); - if (type < 0xff00U || type > 0xffffU) + if (type < 0xff00U || type > 0xffffU) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "sig-signing-type: %u out of " "range [%u..%u]", type, 0xff00U, 0xffffU); + } result = ISC_R_FAILURE; } @@ -2493,8 +2593,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, const char *str = cfg_obj_asstring(obj); for (i = 0; i < sizeof(dialups) / sizeof(dialups[0]); i++) { - if (strcasecmp(dialups[i].name, str) != 0) + if (strcasecmp(dialups[i].name, str) != 0) { continue; + } if ((dialups[i].allowed & ztype) == 0) { cfg_obj_log(obj, logctx, ISC_LOG_ERROR, "dialup type '%s' is not " @@ -2520,13 +2621,16 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, */ obj = NULL; if (root) { - if (voptions != NULL) + if (voptions != NULL) { (void)cfg_map_get(voptions, "forwarders", &obj); - if (obj == NULL && goptions != NULL) + } + if (obj == NULL && goptions != NULL) { (void)cfg_map_get(goptions, "forwarders", &obj); + } } - if (check_forward(zoptions, obj, logctx) != ISC_R_SUCCESS) + if (check_forward(zoptions, obj, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } /* * Check that a RFC 1918 / ULA reverse zone is not forward first @@ -2539,18 +2643,21 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, /* * Forward mode not explicity configured. */ - if (voptions != NULL) + if (voptions != NULL) { cfg_map_get(voptions, "forward", &obj); - if (obj == NULL && goptions != NULL) + } + if (obj == NULL && goptions != NULL) { cfg_map_get(goptions, "forward", &obj); + } if (obj == NULL || - strcasecmp(cfg_obj_asstring(obj), "first") == 0) + strcasecmp(cfg_obj_asstring(obj), "first") == 0) { cfg_obj_log(zconfig, logctx, ISC_LOG_WARNING, "inherited 'forward first;' for " "%s zone '%s' - did you want " "'forward only;'?", rfc1918 ? "rfc1918" : "ula", znamestr); + } } } @@ -2638,10 +2745,12 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, if (masterformat == dns_masterformat_map) { obj = NULL; (void)cfg_map_get(zoptions, "max-zone-ttl", &obj); - if (obj == NULL && voptions != NULL) + if (obj == NULL && voptions != NULL) { (void)cfg_map_get(voptions, "max-zone-ttl", &obj); - if (obj == NULL && goptions != NULL) + } + if (obj == NULL && goptions != NULL) { (void)cfg_map_get(goptions, "max-zone-ttl", &obj); + } if (obj != NULL) { cfg_obj_log(zconfig, logctx, ISC_LOG_ERROR, "zone '%s': 'max-zone-ttl' is not " @@ -2683,8 +2792,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, * Check various options. */ tresult = check_options(zoptions, logctx, mctx, optlevel_zone); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } /* * If the zone type is rbt/rbt64 then master/hint zones @@ -2695,8 +2805,9 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, obj = NULL; dlz = false; tresult = cfg_map_get(zoptions, "dlz", &obj); - if (tresult == ISC_R_SUCCESS) + if (tresult == ISC_R_SUCCESS) { dlz = true; + } obj = NULL; tresult = cfg_map_get(zoptions, "database", &obj); @@ -2727,14 +2838,16 @@ check_zoneconf(const cfg_obj_t *zconfig, const cfg_obj_t *voptions, (ztype == CFG_ZONE_SLAVE || ztype == CFG_ZONE_MIRROR || ddns)) { tresult = fileexist(fileobj, files, true, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } else if (tresult == ISC_R_SUCCESS && (ztype == CFG_ZONE_MASTER || ztype == CFG_ZONE_HINT)) { tresult = fileexist(fileobj, files, false, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } } @@ -2793,8 +2906,9 @@ bind9_check_key(const cfg_obj_t *key, isc_log_t *logctx) len = strlen(algorithms[i].name); if (strncasecmp(algorithms[i].name, algorithm, len) == 0 && (algorithm[len] == '\0' || - (algorithms[i].size != 0 && algorithm[len] == '-'))) + (algorithms[i].size != 0 && algorithm[len] == '-'))) { break; + } } if (algorithms[i].name == NULL) { cfg_obj_log(algobj, logctx, ISC_LOG_ERROR, @@ -2825,11 +2939,12 @@ bind9_check_key(const cfg_obj_t *key, isc_log_t *logctx) * Recommended minima for hmac algorithms. */ if ((digestbits < (algorithms[i].size / 2U) || - (digestbits < 80U))) + (digestbits < 80U))) { cfg_obj_log(algobj, logctx, ISC_LOG_WARNING, "key '%s' digest-bits too small " "[<%u]", keyname, algorithms[i].size / 2); + } } else { cfg_obj_log(algobj, logctx, ISC_LOG_ERROR, "key '%s': unable to parse digest-bits", @@ -2917,8 +3032,9 @@ check_keylist(const cfg_obj_t *keys, isc_symtab_t *symtab, isc_mem_t *mctx, continue; } tresult = bind9_check_key(key, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { return (tresult); + } dns_name_format(name, namebuf, sizeof(namebuf)); keyname = isc_mem_strdup(mctx, namebuf); @@ -2935,8 +3051,9 @@ check_keylist(const cfg_obj_t *keys, isc_symtab_t *symtab, isc_mem_t *mctx, file = cfg_obj_file(symvalue.as_cpointer); line = cfg_obj_line(symvalue.as_cpointer); - if (file == NULL) + if (file == NULL) { file = ""; + } cfg_obj_log(key, logctx, ISC_LOG_ERROR, "key '%s': already exists " "previous definition: %s:%u", @@ -2971,15 +3088,17 @@ rndckey_exists(const cfg_obj_t *keylist, const char *keyname) const cfg_obj_t * obj; const char * str; - if (keylist == NULL) + if (keylist == NULL) { return (false); + } for (element = cfg_list_first(keylist); element != NULL; element = cfg_list_next(element)) { obj = cfg_listelt_value(element); str = cfg_obj_asstring(cfg_map_getname(obj)); - if (!strcasecmp(str, keyname)) + if (!strcasecmp(str, keyname)) { return (true); + } } return (false); } @@ -3006,12 +3125,15 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions, dns_name_t * keyname; servers = NULL; - if (voptions != NULL) + if (voptions != NULL) { (void)cfg_map_get(voptions, "server", &servers); - if (servers == NULL) + } + if (servers == NULL) { (void)cfg_map_get(config, "server", &servers); - if (servers == NULL) + } + if (servers == NULL) { return (ISC_R_SUCCESS); + } for (e1 = cfg_list_first(servers); e1 != NULL; e1 = cfg_list_next(e1)) { v1 = cfg_listelt_value(e1); @@ -3032,10 +3154,11 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions, source = 0; do { obj = NULL; - if (n1.family == AF_INET) + if (n1.family == AF_INET) { xfr = sources[source].v6; - else + } else { xfr = sources[source].v4; + } (void)cfg_map_get(v1, xfr, &obj); if (obj != NULL) { isc_netaddr_format(&n1, buf, sizeof(buf)); @@ -3053,8 +3176,9 @@ check_servers(const cfg_obj_t *config, const cfg_obj_t *voptions, const char * file = cfg_obj_file(v1); unsigned int line = cfg_obj_line(v1); - if (file == NULL) + if (file == NULL) { file = ""; + } isc_netaddr_format(&n2, buf, sizeof(buf)); cfg_obj_log(v2, logctx, ISC_LOG_ERROR, @@ -3703,8 +3827,9 @@ check_rpz_catz(const char *rpz_catz, const cfg_obj_t *rpz_obj, if (tresult != ISC_R_SUCCESS) { cfg_obj_log(nameobj, logctx, ISC_LOG_ERROR, "bad domain name '%s'", zonename); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = tresult; + } continue; } dns_name_format(name, namebuf, sizeof(namebuf)); @@ -3712,12 +3837,15 @@ check_rpz_catz(const char *rpz_catz, const cfg_obj_t *rpz_obj, if (tresult == ISC_R_SUCCESS) { obj = NULL; zoneobj = value.as_cpointer; - if (zoneobj != NULL && cfg_obj_istuple(zoneobj)) + if (zoneobj != NULL && cfg_obj_istuple(zoneobj)) { zoneobj = cfg_tuple_get(zoneobj, "options"); - if (zoneobj != NULL && cfg_obj_ismap(zoneobj)) + } + if (zoneobj != NULL && cfg_obj_ismap(zoneobj)) { (void)cfg_map_get(zoneobj, "type", &obj); - if (obj != NULL) + } + if (obj != NULL) { zonetype = cfg_obj_asstring(obj); + } } if (strcasecmp(zonetype, "primary") != 0 && strcasecmp(zonetype, "master") != 0 && @@ -3726,8 +3854,9 @@ check_rpz_catz(const char *rpz_catz, const cfg_obj_t *rpz_obj, cfg_obj_log(nameobj, logctx, ISC_LOG_ERROR, "%s '%s'%s%s is not a master or slave zone", rpz_catz, zonename, forview, viewname); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } } return (result); @@ -3782,7 +3911,7 @@ check_one_plugin(const cfg_obj_t *config, const cfg_obj_t *obj, return (ISC_R_SUCCESS); } -#endif +#endif /* ifdef HAVE_DLOPEN */ static isc_result_t check_dnstap(const cfg_obj_t *voptions, const cfg_obj_t *config, @@ -3813,13 +3942,13 @@ check_dnstap(const cfg_obj_t *voptions, const cfg_obj_t *config, } } return (ISC_R_SUCCESS); -#else +#else /* ifdef HAVE_DNSTAP */ UNUSED(voptions); UNUSED(config); UNUSED(logctx); return (ISC_R_SUCCESS); -#endif +#endif /* ifdef HAVE_DNSTAP */ } static isc_result_t @@ -3836,7 +3965,7 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, const cfg_obj_t *keys = NULL; #ifndef HAVE_DLOPEN const cfg_obj_t *dyndb = NULL; -#endif +#endif /* ifndef HAVE_DLOPEN */ const cfg_listelt_t *element, *element2; isc_symtab_t * symtab = NULL; isc_result_t result = ISC_R_SUCCESS; @@ -3858,25 +3987,28 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, /* * The most relevant options for this view */ - if (voptions != NULL) + if (voptions != NULL) { opts = voptions; - else + } else { opts = options; + } /* * Check that all zone statements are syntactically correct and * there are no duplicate zones. */ tresult = isc_symtab_create(mctx, 1000, freekey, mctx, false, &symtab); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { return (ISC_R_NOMEMORY); + } cfg_aclconfctx_create(mctx, &actx); - if (voptions != NULL) + if (voptions != NULL) { (void)cfg_map_get(voptions, "zone", &zones); - else + } else { (void)cfg_map_get(config, "zone", &zones); + } for (element = cfg_list_first(zones); element != NULL; element = cfg_list_next(element)) { @@ -3885,23 +4017,26 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, tresult = check_zoneconf(zone, voptions, config, symtab, files, inview, viewname, vclass, actx, logctx, mctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } #ifndef HAVE_DLOPEN - if (voptions != NULL) + if (voptions != NULL) { (void)cfg_map_get(voptions, "dyndb", &dyndb); - else + } else { (void)cfg_map_get(config, "dyndb", &dyndb); + } if (dyndb != NULL) { cfg_obj_log(dyndb, logctx, ISC_LOG_ERROR, "dynamic loading of databases is not supported"); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = ISC_R_NOTIMPLEMENTED; + } } -#endif +#endif /* ifndef HAVE_DLOPEN */ /* * Check that the response-policy and catalog-zones options @@ -3932,43 +4067,51 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, /* * Check that forwarding is reasonable. */ - if (opts != NULL && check_forward(opts, NULL, logctx) != ISC_R_SUCCESS) + if (opts != NULL && + check_forward(opts, NULL, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } /* * Check non-zero options at the global and view levels. */ - if (options != NULL && check_nonzero(options, logctx) != ISC_R_SUCCESS) + if (options != NULL && + check_nonzero(options, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } if (voptions != NULL && - check_nonzero(voptions, logctx) != ISC_R_SUCCESS) + check_nonzero(voptions, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } /* * Check that dual-stack-servers is reasonable. */ - if (opts != NULL && check_dual_stack(opts, logctx) != ISC_R_SUCCESS) + if (opts != NULL && check_dual_stack(opts, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } /* * Check that rrset-order is reasonable. */ - if (opts != NULL && check_order(opts, logctx) != ISC_R_SUCCESS) + if (opts != NULL && check_order(opts, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } /* * Check that all key statements are syntactically correct and * there are no duplicate keys. */ tresult = isc_symtab_create(mctx, 1000, freekey, mctx, false, &symtab); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { goto cleanup; + } (void)cfg_map_get(config, "key", &keys); tresult = check_keylist(keys, symtab, mctx, logctx); - if (tresult == ISC_R_EXISTS) + if (tresult == ISC_R_EXISTS) { result = ISC_R_FAILURE; - else if (tresult != ISC_R_SUCCESS) { + } else if (tresult != ISC_R_SUCCESS) { result = tresult; goto cleanup; } @@ -3977,9 +4120,9 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, keys = NULL; (void)cfg_map_get(voptions, "key", &keys); tresult = check_keylist(keys, symtab, mctx, logctx); - if (tresult == ISC_R_EXISTS) + if (tresult == ISC_R_EXISTS) { result = ISC_R_FAILURE; - else if (tresult != ISC_R_SUCCESS) { + } else if (tresult != ISC_R_SUCCESS) { result = tresult; goto cleanup; } @@ -3988,8 +4131,9 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, /* * Global servers can refer to keys in views. */ - if (check_servers(config, voptions, symtab, logctx) != ISC_R_SUCCESS) + if (check_servers(config, voptions, symtab, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } isc_symtab_destroy(&symtab); @@ -4208,10 +4352,12 @@ check_viewconf(const cfg_obj_t *config, const cfg_obj_t *voptions, #endif /* HAVE_DLOPEN */ cleanup: - if (symtab != NULL) + if (symtab != NULL) { isc_symtab_destroy(&symtab); - if (actx != NULL) + } + if (actx != NULL) { cfg_aclconfctx_detach(&actx); + } return (result); } @@ -4242,19 +4388,22 @@ bind9_check_logging(const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) int i; (void)cfg_map_get(config, "logging", &logobj); - if (logobj == NULL) + if (logobj == NULL) { return (ISC_R_SUCCESS); + } result = isc_symtab_create(mctx, 100, NULL, NULL, false, &symtab); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } symvalue.as_cpointer = NULL; for (i = 0; default_channels[i] != NULL; i++) { tresult = isc_symtab_define(symtab, default_channels[i], 1, symvalue, isc_symexists_replace); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } cfg_map_get(logobj, "channel", &channels); @@ -4269,14 +4418,18 @@ bind9_check_logging(const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) (void)cfg_map_get(channel, "null", &nullobj); (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, logctx, ISC_LOG_ERROR, "channel '%s': exactly one of file, " @@ -4287,8 +4440,9 @@ bind9_check_logging(const cfg_obj_t *config, isc_log_t *logctx, isc_mem_t *mctx) } tresult = isc_symtab_define(symtab, channelname, 1, symvalue, isc_symexists_replace); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } cfg_map_get(logobj, "category", &categories); @@ -4332,8 +4486,9 @@ bind9_check_controlskeys(const cfg_obj_t *control, const cfg_obj_t *keylist, const char * keyval; control_keylist = cfg_tuple_get(control, "keys"); - if (cfg_obj_isvoid(control_keylist)) + if (cfg_obj_isvoid(control_keylist)) { return (ISC_R_SUCCESS); + } for (element = cfg_list_first(control_keylist); element != NULL; element = cfg_list_next(element)) { @@ -4370,8 +4525,9 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, int i; (void)cfg_map_get(config, "controls", &controlslist); - if (controlslist == NULL) + if (controlslist == NULL) { return (ISC_R_SUCCESS); + } (void)cfg_map_get(config, "key", &keylist); @@ -4394,14 +4550,17 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, allow = cfg_tuple_get(control, "allow"); tresult = cfg_acl_fromconfig(allow, config, logctx, actx, mctx, 0, &acl); - if (acl != NULL) + if (acl != NULL) { dns_acl_detach(&acl); - if (tresult != ISC_R_SUCCESS) + } + if (tresult != ISC_R_SUCCESS) { result = tresult; + } tresult = bind9_check_controlskeys(control, keylist, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } for (element2 = cfg_list_first(unixcontrols); element2 != NULL; element2 = cfg_list_next(element2)) { @@ -4418,11 +4577,12 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, for (i = 0; i < 3; i++) { #ifdef NEED_SECURE_DIRECTORY mask = (0x1 << (i * 3)); /* SEARCH */ -#else +#else /* ifdef NEED_SECURE_DIRECTORY */ mask = (0x6 << (i * 3)); /* READ + WRITE */ -#endif - if ((perm & mask) == mask) +#endif /* ifdef NEED_SECURE_DIRECTORY */ + if ((perm & mask) == mask) { break; + } } if (i == 0) { cfg_obj_log(control, logctx, ISC_LOG_WARNING, @@ -4437,8 +4597,9 @@ bind9_check_controls(const cfg_obj_t *config, isc_log_t *logctx, } tresult = bind9_check_controlskeys(control, keylist, logctx); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { result = tresult; + } } } cfg_aclconfctx_detach(&actx); @@ -4466,15 +4627,19 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, (void)cfg_map_get(config, "options", &options); - if (options != NULL && check_options(options, logctx, mctx, - optlevel_options) != ISC_R_SUCCESS) + if (options != NULL && + check_options(options, logctx, mctx, optlevel_options) != + ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } - if (bind9_check_logging(config, logctx, mctx) != ISC_R_SUCCESS) + if (bind9_check_logging(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } - if (bind9_check_controls(config, logctx, mctx) != ISC_R_SUCCESS) + if (bind9_check_controls(config, logctx, mctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } (void)cfg_map_get(config, "view", &views); @@ -4482,11 +4647,12 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, if (check_dual_stack(options, logctx) != ISC_R_SUCCESS) { result = ISC_R_FAILURE; - /* - * Use case insensitive comparision as not all file systems are - * case sensitive. This will prevent people using FOO.DB and foo.db - * on case sensitive file systems but that shouldn't be a major issue. - */ + /* + * Use case insensitive comparision as not all file + * systems are case sensitive. This will prevent people + * using FOO.DB and foo.db on case sensitive file + * systems but that shouldn't be a major issue. + */ } } @@ -4558,10 +4724,11 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, DE_CONST(cfg_obj_asstring(vclassobj), r.base); r.length = strlen(r.base); tresult = dns_rdataclass_fromtext(&vclass, &r); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { cfg_obj_log(vclassobj, logctx, ISC_LOG_ERROR, "view '%s': invalid class %s", cfg_obj_asstring(vname), r.base); + } } symtype = vclass + 1; if (tresult == ISC_R_SUCCESS && symtab != NULL) { @@ -4596,12 +4763,14 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, result = ISC_R_EXISTS; } } - if (tresult == ISC_R_SUCCESS) + if (tresult == ISC_R_SUCCESS) { tresult = check_viewconf(config, voptions, key, vclass, files, check_plugins, inview, logctx, mctx); - if (tresult != ISC_R_SUCCESS) + } + if (tresult != ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } } if (views != NULL && options != NULL) { @@ -4635,13 +4804,13 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, { cfg_obj_log(acl, logctx, ISC_LOG_ERROR, - "attempt to redefine " + "attempt to " + "redefine " "builtin acl '%s'", aclname); result = ISC_R_FAILURE; break; } - } } @@ -4654,8 +4823,9 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, if (strcasecmp(aclname, name) == 0) { const char *file = cfg_obj_file(acl); - if (file == NULL) + if (file == NULL) { file = ""; + } cfg_obj_log(acl2, logctx, ISC_LOG_ERROR, "attempt to redefine " @@ -4690,8 +4860,9 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, const char * file = cfg_obj_file(acl); unsigned int line = cfg_obj_line(acl); - if (file == NULL) + if (file == NULL) { file = ""; + } cfg_obj_log(acl2, logctx, ISC_LOG_ERROR, "attempt to redefine " @@ -4705,12 +4876,15 @@ bind9_check_namedconf(const cfg_obj_t *config, bool check_plugins, } cleanup: - if (symtab != NULL) + if (symtab != NULL) { isc_symtab_destroy(&symtab); - if (inview != NULL) + } + if (inview != NULL) { isc_symtab_destroy(&inview); - if (files != NULL) + } + if (files != NULL) { isc_symtab_destroy(&files); + } return (result); } diff --git a/lib/bind9/getaddresses.c b/lib/bind9/getaddresses.c index 012a9a9c4f..1baddcdfe6 100644 --- a/lib/bind9/getaddresses.c +++ b/lib/bind9/getaddresses.c @@ -56,10 +56,11 @@ bind9_getaddresses(const char *hostname, in_port_t port, isc_sockaddr_t *addrs, * terminating NULL character. */ if (inet_pton(AF_INET, hostname, &in4) == 1) { - if (have_ipv4) + if (have_ipv4) { isc_sockaddr_fromin(&addrs[0], &in4, port); - else + } else { isc_sockaddr_v6fromin(&addrs[0], &in4, port); + } *addrcount = 1; return (ISC_R_SUCCESS); } else if (strlen(hostname) <= 127U) { @@ -68,14 +69,16 @@ bind9_getaddresses(const char *hostname, in_port_t port, isc_sockaddr_t *addrs, strlcpy(tmpbuf, hostname, sizeof(tmpbuf)); d = strchr(tmpbuf, '%'); - if (d != NULL) + if (d != NULL) { *d = '\0'; + } if (inet_pton(AF_INET6, tmpbuf, &in6) == 1) { isc_netaddr_t na; - if (!have_ipv6) + if (!have_ipv6) { return (ISC_R_FAMILYNOSUPPORT); + } if (d != NULL) { isc_result_t iresult; @@ -83,8 +86,9 @@ bind9_getaddresses(const char *hostname, in_port_t port, isc_sockaddr_t *addrs, iresult = isc_netscope_pton(AF_INET6, d + 1, &in6, &zone); - if (iresult != ISC_R_SUCCESS) + if (iresult != ISC_R_SUCCESS) { return (iresult); + } } isc_netaddr_fromin6(&na, &in6); @@ -97,20 +101,20 @@ bind9_getaddresses(const char *hostname, in_port_t port, isc_sockaddr_t *addrs, } } memset(&hints, 0, sizeof(hints)); - if (!have_ipv6) + if (!have_ipv6) { hints.ai_family = PF_INET; - else if (!have_ipv4) + } else if (!have_ipv4) { hints.ai_family = PF_INET6; - else { + } else { hints.ai_family = PF_UNSPEC; #ifdef AI_ADDRCONFIG hints.ai_flags = AI_ADDRCONFIG; -#endif +#endif /* ifdef AI_ADDRCONFIG */ } hints.ai_socktype = SOCK_STREAM; #ifdef AI_ADDRCONFIG again: -#endif +#endif /* ifdef AI_ADDRCONFIG */ result = getaddrinfo(hostname, NULL, &hints, &ai); switch (result) { case 0: @@ -118,7 +122,7 @@ again: case EAI_NONAME: #if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) case EAI_NODATA: -#endif +#endif /* if defined(EAI_NODATA) && (EAI_NODATA != EAI_NONAME) */ return (ISC_R_NOTFOUND); #ifdef AI_ADDRCONFIG case EAI_BADFLAGS: @@ -126,15 +130,17 @@ again: hints.ai_flags &= ~AI_ADDRCONFIG; goto again; } -#endif - /* FALLTHROUGH */ +#endif /* ifdef AI_ADDRCONFIG */ + /* FALLTHROUGH */ default: return (ISC_R_FAILURE); } for (tmpai = ai, i = 0; tmpai != NULL && i < addrsize; tmpai = tmpai->ai_next) { - if (tmpai->ai_family != AF_INET && tmpai->ai_family != AF_INET6) + if (tmpai->ai_family != AF_INET && + tmpai->ai_family != AF_INET6) { continue; + } if (tmpai->ai_family == AF_INET) { struct sockaddr_in *sin; sin = (struct sockaddr_in *)tmpai->ai_addr; @@ -148,8 +154,9 @@ again: } freeaddrinfo(ai); *addrcount = i; - if (*addrcount == 0) + if (*addrcount == 0) { return (ISC_R_NOTFOUND); - else + } else { return (ISC_R_SUCCESS); + } } diff --git a/lib/dns/acl.c b/lib/dns/acl.c index 4b1f0d7557..ebcb77efcf 100644 --- a/lib/dns/acl.c +++ b/lib/dns/acl.c @@ -36,8 +36,9 @@ dns_acl_create(isc_mem_t *mctx, int n, dns_acl_t **target) /* * Work around silly limitation of isc_mem_get(). */ - if (n == 0) + if (n == 0) { n = 1; + } acl = isc_mem_get(mctx, sizeof(*acl)); @@ -85,8 +86,9 @@ dns_acl_anyornone(isc_mem_t *mctx, bool neg, dns_acl_t **target) dns_acl_t * acl = NULL; result = dns_acl_create(mctx, 0, &acl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_iptable_addprefix(acl->iptable, NULL, 0, !neg); if (result != ISC_R_SUCCESS) { @@ -126,18 +128,21 @@ dns_acl_isanyornone(dns_acl_t *acl, bool pos) /* Should never happen but let's be safe */ if (acl == NULL || acl->iptable == NULL || acl->iptable->radix == NULL || acl->iptable->radix->head == NULL || - acl->iptable->radix->head->prefix == NULL) + acl->iptable->radix->head->prefix == NULL) { return (false); + } - if (acl->length != 0 || dns_acl_node_count(acl) != 1) + if (acl->length != 0 || dns_acl_node_count(acl) != 1) { return (false); + } if (acl->iptable->radix->head->prefix->bitlen == 0 && acl->iptable->radix->head->data[0] != NULL && acl->iptable->radix->head->data[0] == acl->iptable->radix->head->data[1] && - *(bool *)(acl->iptable->radix->head->data[0]) == pos) + *(bool *)(acl->iptable->radix->head->data[0]) == pos) { return (true); + } return (false); /* All others */ } @@ -225,10 +230,11 @@ dns_acl_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner, if (dns_aclelement_match(reqaddr, reqsigner, e, env, matchelt)) { if (match_num == -1 || e->node_num < match_num) { - if (e->negative) + if (e->negative) { *match = -e->node_num; - else + } else { *match = e->node_num; + } } break; } @@ -258,8 +264,9 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) void *newmem; newalloc = dest->alloc + source->alloc; - if (newalloc < 4) + if (newalloc < 4) { newalloc = 4; + } newmem = isc_mem_get(dest->mctx, newalloc * sizeof(dns_aclelement_t)); @@ -287,8 +294,9 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) nelem = dest->length; dest->length += source->length; for (i = 0; i < source->length; i++) { - if (source->elements[i].node_num > max_node) + if (source->elements[i].node_num > max_node) { max_node = source->elements[i].node_num; + } /* Copy type. */ dest->elements[nelem + i].type = source->elements[i].type; @@ -299,9 +307,10 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) /* Duplicate nested acl. */ if (source->elements[i].type == dns_aclelementtype_nestedacl && - source->elements[i].nestedacl != NULL) + source->elements[i].nestedacl != NULL) { dns_acl_attach(source->elements[i].nestedacl, &dest->elements[nelem + i].nestedacl); + } /* Duplicate key name. */ if (source->elements[i].type == dns_aclelementtype_keyname) { @@ -316,7 +325,7 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) dest->elements[nelem + i].geoip_elem = source->elements[i].geoip_elem; } -#endif +#endif /* if defined(HAVE_GEOIP2) */ /* reverse sense of positives if this is a negative acl */ if (!pos && !source->elements[i].negative) { @@ -333,10 +342,12 @@ dns_acl_merge(dns_acl_t *dest, dns_acl_t *source, bool pos) */ nodes = max_node + dns_acl_node_count(dest); result = dns_iptable_merge(dest->iptable, source->iptable, pos); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (nodes > dns_acl_node_count(dest)) + } + if (nodes > dns_acl_node_count(dest)) { dns_acl_node_count(dest) = nodes; + } return (ISC_R_SUCCESS); } @@ -364,34 +375,39 @@ dns_aclelement_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner, case dns_aclelementtype_keyname: if (reqsigner != NULL && dns_name_equal(reqsigner, &e->keyname)) { - if (matchelt != NULL) + if (matchelt != NULL) { *matchelt = e; + } return (true); - } else + } else { return (false); + } case dns_aclelementtype_nestedacl: inner = e->nestedacl; break; case dns_aclelementtype_localhost: - if (env == NULL || env->localhost == NULL) + if (env == NULL || env->localhost == NULL) { return (false); + } inner = env->localhost; break; case dns_aclelementtype_localnets: - if (env == NULL || env->localnets == NULL) + if (env == NULL || env->localnets == NULL) { return (false); + } inner = env->localnets; break; #if defined(HAVE_GEOIP2) case dns_aclelementtype_geoip: - if (env == NULL || env->geoip == NULL) + if (env == NULL || env->geoip == NULL) { return (false); + } return (dns_geoip_match(reqaddr, env->geoip, &e->geoip_elem)); -#endif +#endif /* if defined(HAVE_GEOIP2) */ default: INSIST(0); ISC_UNREACHABLE(); @@ -408,8 +424,9 @@ dns_aclelement_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner, * XXXDCL this should be documented. */ if (indirectmatch > 0) { - if (matchelt != NULL) + if (matchelt != NULL) { *matchelt = e; + } return (true); } @@ -417,8 +434,9 @@ dns_aclelement_match(const isc_netaddr_t *reqaddr, const dns_name_t *reqsigner, * A negative indirect match may have set *matchelt, but we don't * want it set when we return. */ - if (matchelt != NULL) + if (matchelt != NULL) { *matchelt = NULL; + } return (false); } @@ -447,13 +465,16 @@ destroy(dns_acl_t *dacl) dns_acl_detach(&de->nestedacl); } } - if (dacl->elements != NULL) + if (dacl->elements != NULL) { isc_mem_put(dacl->mctx, dacl->elements, dacl->alloc * sizeof(dns_aclelement_t)); - if (dacl->name != NULL) + } + if (dacl->name != NULL) { isc_mem_free(dacl->mctx, dacl->name); - if (dacl->iptable != NULL) + } + if (dacl->iptable != NULL) { dns_iptable_detach(&dacl->iptable); + } isc_refcount_destroy(&dacl->refcount); dacl->magic = 0; isc_mem_putanddetach(&dacl->mctx, dacl, sizeof(*dacl)); @@ -542,16 +563,18 @@ dns_acl_isinsecure(const dns_acl_t *a) isc_radix_process(a->iptable->radix, is_insecure); insecure = insecure_prefix_found; UNLOCK(&insecure_prefix_lock); - if (insecure) + if (insecure) { return (true); + } /* Now check non-radix elements */ for (i = 0; i < a->length; i++) { dns_aclelement_t *e = &a->elements[i]; /* A negated match can never be insecure. */ - if (e->negative) + if (e->negative) { continue; + } switch (e->type) { case dns_aclelementtype_keyname: @@ -559,13 +582,14 @@ dns_acl_isinsecure(const dns_acl_t *a) continue; case dns_aclelementtype_nestedacl: - if (dns_acl_isinsecure(e->nestedacl)) + if (dns_acl_isinsecure(e->nestedacl)) { return (true); + } continue; #if defined(HAVE_GEOIP2) case dns_aclelementtype_geoip: -#endif +#endif /* if defined(HAVE_GEOIP2) */ case dns_aclelementtype_localnets: return (true); @@ -610,15 +634,17 @@ dns_aclenv_init(isc_mem_t *mctx, dns_aclenv_t *env) env->localhost = NULL; env->localnets = NULL; result = dns_acl_create(mctx, 0, &env->localhost); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_nothing; + } result = dns_acl_create(mctx, 0, &env->localnets); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_localhost; + } env->match_mapped = false; #if defined(HAVE_GEOIP2) env->geoip = NULL; -#endif +#endif /* if defined(HAVE_GEOIP2) */ return (ISC_R_SUCCESS); cleanup_localhost: @@ -637,14 +663,16 @@ dns_aclenv_copy(dns_aclenv_t *t, dns_aclenv_t *s) t->match_mapped = s->match_mapped; #if defined(HAVE_GEOIP2) t->geoip = s->geoip; -#endif +#endif /* if defined(HAVE_GEOIP2) */ } void dns_aclenv_destroy(dns_aclenv_t *env) { - if (env->localhost != NULL) + if (env->localhost != NULL) { dns_acl_detach(&env->localhost); - if (env->localnets != NULL) + } + if (env->localnets != NULL) { dns_acl_detach(&env->localnets); + } } diff --git a/lib/dns/adb.c b/lib/dns/adb.c index f843f2ae34..768f9d3d68 100644 --- a/lib/dns/adb.c +++ b/lib/dns/adb.c @@ -75,7 +75,7 @@ */ #ifndef ADB_STALE_MARGIN #define ADB_STALE_MARGIN 1800 -#endif +#endif /* ifndef ADB_STALE_MARGIN */ #define FREE_ITEMS 64 /*%< free count for memory pools */ #define FILL_COUNT 16 /*%< fill count for memory pools */ @@ -520,8 +520,9 @@ DP(int level, const char *format, ...) static inline void inc_stats(dns_adb_t *adb, isc_statscounter_t counter) { - if (adb->view->resstats != NULL) + if (adb->view->resstats != NULL) { isc_stats_increment(adb->view->resstats, counter); + } } /*% @@ -530,31 +531,36 @@ inc_stats(dns_adb_t *adb, isc_statscounter_t counter) static inline void set_adbstat(dns_adb_t *adb, uint64_t val, isc_statscounter_t counter) { - if (adb->view->adbstats != NULL) + if (adb->view->adbstats != NULL) { isc_stats_set(adb->view->adbstats, val, counter); + } } static inline void dec_adbstats(dns_adb_t *adb, isc_statscounter_t counter) { - if (adb->view->adbstats != NULL) + if (adb->view->adbstats != NULL) { isc_stats_decrement(adb->view->adbstats, counter); + } } static inline void inc_adbstats(dns_adb_t *adb, isc_statscounter_t counter) { - if (adb->view->adbstats != NULL) + if (adb->view->adbstats != NULL) { isc_stats_increment(adb->view->adbstats, counter); + } } static inline dns_ttl_t ttlclamp(dns_ttl_t ttl) { - if (ttl < ADB_CACHE_MINIMUM) + if (ttl < ADB_CACHE_MINIMUM) { ttl = ADB_CACHE_MINIMUM; - if (ttl > ADB_CACHE_MAXIMUM) + } + if (ttl > ADB_CACHE_MAXIMUM) { ttl = ADB_CACHE_MAXIMUM; + } return (ttl); } @@ -594,16 +600,19 @@ grow_entries(isc_task_t *task, isc_event_t *ev) isc_event_free(&ev); result = isc_task_beginexclusive(task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto check_exit; + } i = 0; - while (nbuckets[i] != 0 && adb->nentries >= nbuckets[i]) + while (nbuckets[i] != 0 && adb->nentries >= nbuckets[i]) { i++; - if (nbuckets[i] != 0) + } + if (nbuckets[i] != 0) { n = nbuckets[i]; - else + } else { goto done; + } DP(ISC_LOG_INFO, "adb: grow_entries to %u starting", n); @@ -614,9 +623,9 @@ grow_entries(isc_task_t *task, isc_event_t *ev) if (adb->entry_sd[i]) { goto cleanup; - /* - * Grab all the resources we need. - */ + /* + * Grab all the resources we need. + */ } } @@ -630,8 +639,9 @@ grow_entries(isc_task_t *task, isc_event_t *ev) newentry_refcnt = isc_mem_get(adb->mctx, sizeof(*newentry_refcnt) * n); if (newentries == NULL || newdeadentries == NULL || newentrylocks == NULL || newentry_sd == NULL || - newentry_refcnt == NULL) + newentry_refcnt == NULL) { goto cleanup; + } /* * Initialise the new resources. @@ -711,26 +721,32 @@ grow_entries(isc_task_t *task, isc_event_t *ev) goto done; cleanup: - if (newentries != NULL) + if (newentries != NULL) { isc_mem_put(adb->mctx, newentries, sizeof(*newentries) * n); - if (newdeadentries != NULL) + } + if (newdeadentries != NULL) { isc_mem_put(adb->mctx, newdeadentries, sizeof(*newdeadentries) * n); - if (newentrylocks != NULL) + } + if (newentrylocks != NULL) { isc_mem_put(adb->mctx, newentrylocks, sizeof(*newentrylocks) * n); - if (newentry_sd != NULL) + } + if (newentry_sd != NULL) { isc_mem_put(adb->mctx, newentry_sd, sizeof(*newentry_sd) * n); - if (newentry_refcnt != NULL) + } + if (newentry_refcnt != NULL) { isc_mem_put(adb->mctx, newentry_refcnt, sizeof(*newentry_refcnt) * n); + } done: isc_task_endexclusive(task); check_exit: LOCK(&adb->lock); - if (dec_adb_irefcnt(adb)) + if (dec_adb_irefcnt(adb)) { check_exit(adb); + } UNLOCK(&adb->lock); DP(ISC_LOG_INFO, "adb: grow_entries finished"); } @@ -754,16 +770,19 @@ grow_names(isc_task_t *task, isc_event_t *ev) isc_event_free(&ev); result = isc_task_beginexclusive(task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto check_exit; + } i = 0; - while (nbuckets[i] != 0 && adb->nnames >= nbuckets[i]) + while (nbuckets[i] != 0 && adb->nnames >= nbuckets[i]) { i++; - if (nbuckets[i] != 0) + } + if (nbuckets[i] != 0) { n = nbuckets[i]; - else + } else { goto done; + } DP(ISC_LOG_INFO, "adb: grow_names to %u starting", n); @@ -774,9 +793,9 @@ grow_names(isc_task_t *task, isc_event_t *ev) if (adb->name_sd[i]) { goto cleanup; - /* - * Grab all the resources we need. - */ + /* + * Grab all the resources we need. + */ } } @@ -789,8 +808,9 @@ grow_names(isc_task_t *task, isc_event_t *ev) newname_sd = isc_mem_get(adb->mctx, sizeof(*newname_sd) * n); newname_refcnt = isc_mem_get(adb->mctx, sizeof(*newname_refcnt) * n); if (newnames == NULL || newdeadnames == NULL || newnamelocks == NULL || - newname_sd == NULL || newname_refcnt == NULL) + newname_sd == NULL || newname_refcnt == NULL) { goto cleanup; + } /* * Initialise the new resources. @@ -869,24 +889,30 @@ grow_names(isc_task_t *task, isc_event_t *ev) goto done; cleanup: - if (newnames != NULL) + if (newnames != NULL) { isc_mem_put(adb->mctx, newnames, sizeof(*newnames) * n); - if (newdeadnames != NULL) + } + if (newdeadnames != NULL) { isc_mem_put(adb->mctx, newdeadnames, sizeof(*newdeadnames) * n); - if (newnamelocks != NULL) + } + if (newnamelocks != NULL) { isc_mem_put(adb->mctx, newnamelocks, sizeof(*newnamelocks) * n); - if (newname_sd != NULL) + } + if (newname_sd != NULL) { isc_mem_put(adb->mctx, newname_sd, sizeof(*newname_sd) * n); - if (newname_refcnt != NULL) + } + if (newname_refcnt != NULL) { isc_mem_put(adb->mctx, newname_refcnt, sizeof(*newname_refcnt) * n); + } done: isc_task_endexclusive(task); check_exit: LOCK(&adb->lock); - if (dec_adb_irefcnt(adb)) + if (dec_adb_irefcnt(adb)) { check_exit(adb); + } UNLOCK(&adb->lock); DP(ISC_LOG_INFO, "adb: grow_names finished"); } @@ -921,10 +947,11 @@ import_rdataset(dns_adbname_t *adbname, dns_rdataset_t *rdataset, rdtype = rdataset->type; INSIST((rdtype == dns_rdatatype_a) || (rdtype == dns_rdatatype_aaaa)); - if (rdtype == dns_rdatatype_a) + if (rdtype == dns_rdatatype_a) { findoptions = DNS_ADBFIND_INET; - else + } else { findoptions = DNS_ADBFIND_INET6; + } addr_bucket = DNS_ADB_INVALIDBUCKET; new_addresses_added = false; @@ -984,31 +1011,36 @@ import_rdataset(dns_adbname_t *adbname, dns_rdataset_t *rdataset, foundentry->refcnt++; foundentry->nh++; nh->entry = foundentry; - } else + } else { free_adbnamehook(adb, &nh); + } } new_addresses_added = true; - if (nh != NULL) + if (nh != NULL) { ISC_LIST_APPEND(*hookhead, nh, plink); + } nh = NULL; result = dns_rdataset_next(rdataset); } fail: - if (nh != NULL) + if (nh != NULL) { free_adbnamehook(adb, &nh); + } - if (addr_bucket != DNS_ADB_INVALIDBUCKET) + if (addr_bucket != DNS_ADB_INVALIDBUCKET) { UNLOCK(&adb->entrylocks[addr_bucket]); + } if (rdataset->trust == dns_trust_glue || - rdataset->trust == dns_trust_additional) + rdataset->trust == dns_trust_additional) { rdataset->ttl = ADB_CACHE_MINIMUM; - else if (rdataset->trust == dns_trust_ultimate) + } else if (rdataset->trust == dns_trust_ultimate) { rdataset->ttl = 0; - else + } else { rdataset->ttl = ttlclamp(rdataset->ttl); + } if (rdtype == dns_rdatatype_a) { DP(NCACHE_LEVEL, "expire_v4 set to MIN(%u,%u) import_rdataset", @@ -1063,8 +1095,9 @@ kill_name(dns_adbname_t **n, isc_eventtype_t ev) if (NAME_DEAD(name) && !NAME_FETCH(name)) { result = unlink_name(adb, name); free_adbname(adb, &name); - if (result) + if (result) { result = dec_adb_irefcnt(adb); + } return (result); } @@ -1086,8 +1119,9 @@ kill_name(dns_adbname_t **n, isc_eventtype_t ev) INSIST(result == false); result = unlink_name(adb, name); free_adbname(adb, &name); - if (result) + if (result) { result = dec_adb_irefcnt(adb); + } } else { cancel_fetches_at_name(name); if (!NAME_DEAD(name)) { @@ -1175,15 +1209,17 @@ unlink_name(dns_adb_t *adb, dns_adbname_t *name) bucket = name->lock_bucket; INSIST(bucket != DNS_ADB_INVALIDBUCKET); - if (NAME_DEAD(name)) + if (NAME_DEAD(name)) { ISC_LIST_UNLINK(adb->deadnames[bucket], name, plink); - else + } else { ISC_LIST_UNLINK(adb->names[bucket], name, plink); + } name->lock_bucket = DNS_ADB_INVALIDBUCKET; INSIST(adb->name_refcnt[bucket] > 0); adb->name_refcnt[bucket]--; - if (adb->name_sd[bucket] && adb->name_refcnt[bucket] == 0) + if (adb->name_sd[bucket] && adb->name_refcnt[bucket] == 0) { result = true; + } return (result); } @@ -1199,8 +1235,9 @@ link_entry(dns_adb_t *adb, int bucket, dns_adbentry_t *entry) if (isc_mem_isovermem(adb->mctx)) { for (i = 0; i < 2; i++) { e = ISC_LIST_TAIL(adb->entries[bucket]); - if (e == NULL) + if (e == NULL) { break; + } if (e->refcnt == 0) { unlink_entry(adb, e); free_adbentry(adb, &e); @@ -1230,15 +1267,17 @@ unlink_entry(dns_adb_t *adb, dns_adbentry_t *entry) bucket = entry->lock_bucket; INSIST(bucket != DNS_ADB_INVALIDBUCKET); - if ((entry->flags & ENTRY_IS_DEAD) != 0) + if ((entry->flags & ENTRY_IS_DEAD) != 0) { ISC_LIST_UNLINK(adb->deadentries[bucket], entry, plink); - else + } else { ISC_LIST_UNLINK(adb->entries[bucket], entry, plink); + } entry->lock_bucket = DNS_ADB_INVALIDBUCKET; INSIST(adb->entry_refcnt[bucket] > 0); adb->entry_refcnt[bucket]--; - if (adb->entry_sd[bucket] && adb->entry_refcnt[bucket] == 0) + if (adb->entry_sd[bucket] && adb->entry_refcnt[bucket] == 0) { result = true; + } return (result); } @@ -1332,8 +1371,9 @@ shutdown_entries(dns_adb_t *adb) if (entry->refcnt == 0 && entry->expires != 0) { result = unlink_entry(adb, entry); free_adbentry(adb, &entry); - if (result) + if (result) { result = dec_adb_irefcnt(adb); + } } entry = next_entry; } @@ -1350,11 +1390,13 @@ shutdown_entries(dns_adb_t *adb) static void cancel_fetches_at_name(dns_adbname_t *name) { - if (NAME_FETCH_A(name)) + if (NAME_FETCH_A(name)) { dns_resolver_cancelfetch(name->fetch_a->fetch); + } - if (NAME_FETCH_AAAA(name)) + if (NAME_FETCH_AAAA(name)) { dns_resolver_cancelfetch(name->fetch_aaaa->fetch); + } } /* @@ -1382,8 +1424,9 @@ clean_namehooks(dns_adb_t *adb, dns_adbnamehooklist_t *namehooks) INSIST(DNS_ADBENTRY_VALID(entry)); if (addr_bucket != entry->lock_bucket) { - if (addr_bucket != DNS_ADB_INVALIDBUCKET) + if (addr_bucket != DNS_ADB_INVALIDBUCKET) { UNLOCK(&adb->entrylocks[addr_bucket]); + } addr_bucket = entry->lock_bucket; INSIST(addr_bucket != DNS_ADB_INVALIDBUCKET); LOCK(&adb->entrylocks[addr_bucket]); @@ -1403,8 +1446,9 @@ clean_namehooks(dns_adb_t *adb, dns_adbnamehooklist_t *namehooks) namehook = ISC_LIST_HEAD(*namehooks); } - if (addr_bucket != DNS_ADB_INVALIDBUCKET) + if (addr_bucket != DNS_ADB_INVALIDBUCKET) { UNLOCK(&adb->entrylocks[addr_bucket]); + } return (result); } @@ -1438,12 +1482,14 @@ set_target(dns_adb_t *adb, const dns_name_t *name, const dns_name_t *fname, * Copy the CNAME's target into the target name. */ result = dns_rdataset_first(rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_current(rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &cname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_dup(&cname.cname, adb->mctx, target); dns_rdata_freestruct(&cname); } else { @@ -1456,12 +1502,14 @@ set_target(dns_adb_t *adb, const dns_name_t *name, const dns_name_t *fname, * Get the target name of the DNAME. */ result = dns_rdataset_first(rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_current(rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &dname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Construct the new target name. */ @@ -1471,8 +1519,9 @@ set_target(dns_adb_t *adb, const dns_name_t *name, const dns_name_t *fname, result = dns_name_concatenate(prefix, &dname.dname, new_target, NULL); dns_rdata_freestruct(&dname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_dup(new_target, adb->mctx, target); } @@ -1536,8 +1585,9 @@ clean_finds_at_name(dns_adbname_t *name, isc_eventtype_t evtype, DP(ISC_LOG_DEBUG(3), "DNS_EVENT_ADBNOMOREADDRESSES"); find->flags &= ~addrs; wanted = find->flags & DNS_ADBFIND_ADDRESSMASK; - if (wanted == 0) + if (wanted == 0) { process = true; + } break; default: find->flags &= ~addrs; @@ -1626,8 +1676,9 @@ dec_adb_irefcnt(dns_adb_t *adb) } } - if (adb->irefcnt == 0 && adb->erefcnt == 0) + if (adb->irefcnt == 0 && adb->erefcnt == 0) { result = true; + } UNLOCK(&adb->reflock); return (result); } @@ -1655,13 +1706,15 @@ inc_entry_refcnt(dns_adb_t *adb, dns_adbentry_t *entry, bool lock) bucket = entry->lock_bucket; - if (lock) + if (lock) { LOCK(&adb->entrylocks[bucket]); + } entry->refcnt++; - if (lock) + if (lock) { UNLOCK(&adb->entrylocks[bucket]); + } } static inline bool @@ -1673,8 +1726,9 @@ dec_entry_refcnt(dns_adb_t *adb, bool overmem, dns_adbentry_t *entry, bool lock) bucket = entry->lock_bucket; - if (lock) + if (lock) { LOCK(&adb->entrylocks[bucket]); + } INSIST(entry->refcnt > 0); entry->refcnt--; @@ -1687,17 +1741,20 @@ dec_entry_refcnt(dns_adb_t *adb, bool overmem, dns_adbentry_t *entry, bool lock) result = unlink_entry(adb, entry); } - if (lock) + if (lock) { UNLOCK(&adb->entrylocks[bucket]); + } - if (!destroy_entry) + if (!destroy_entry) { return (result); + } entry->lock_bucket = DNS_ADB_INVALIDBUCKET; free_adbentry(adb, &entry); - if (result) + if (result) { result = dec_adb_irefcnt(adb); + } return (result); } @@ -1708,8 +1765,9 @@ new_adbname(dns_adb_t *adb, const dns_name_t *dnsname) dns_adbname_t *name; name = isc_mempool_get(adb->nmp); - if (name == NULL) + if (name == NULL) { return (NULL); + } dns_name_init(&name->name, NULL); dns_name_dup(dnsname, adb->mctx, &name->name); @@ -1780,8 +1838,9 @@ new_adbnamehook(dns_adb_t *adb, dns_adbentry_t *entry) dns_adbnamehook_t *nh; nh = isc_mempool_get(adb->nhmp); - if (nh == NULL) + if (nh == NULL) { return (NULL); + } nh->magic = DNS_ADBNAMEHOOK_MAGIC; nh->entry = entry; @@ -1812,8 +1871,9 @@ new_adblameinfo(dns_adb_t *adb, const dns_name_t *qname, dns_rdatatype_t qtype) dns_adblameinfo_t *li; li = isc_mempool_get(adb->limp); - if (li == NULL) + if (li == NULL) { return (NULL); + } dns_name_init(&li->qname, NULL); dns_name_dup(qname, adb->mctx, &li->qname); @@ -1849,8 +1909,9 @@ new_adbentry(dns_adb_t *adb) dns_adbentry_t *e; e = isc_mempool_get(adb->emp); - if (e == NULL) + if (e == NULL) { return (NULL); + } e->magic = DNS_ADBENTRY_MAGIC; e->lock_bucket = DNS_ADB_INVALIDBUCKET; @@ -1909,8 +1970,9 @@ free_adbentry(dns_adb_t *adb, dns_adbentry_t **entry) e->magic = 0; - if (e->cookie != NULL) + if (e->cookie != NULL) { isc_mem_put(adb->mctx, e->cookie, e->cookielen); + } li = ISC_LIST_HEAD(e->lameinfo); while (li != NULL) { @@ -1932,8 +1994,9 @@ new_adbfind(dns_adb_t *adb) dns_adbfind_t *h; h = isc_mempool_get(adb->ahmp); - if (h == NULL) + if (h == NULL) { return (NULL); + } /* * Public members. @@ -1970,8 +2033,9 @@ new_adbfetch(dns_adb_t *adb) dns_adbfetch_t *f; f = isc_mempool_get(adb->afmp); - if (f == NULL) + if (f == NULL) { return (NULL); + } f->magic = 0; f->fetch = NULL; @@ -1994,8 +2058,9 @@ free_adbfetch(dns_adb_t *adb, dns_adbfetch_t **fetch) f->magic = 0; - if (dns_rdataset_isassociated(&f->rdataset)) + if (dns_rdataset_isassociated(&f->rdataset)) { dns_rdataset_disassociate(&f->rdataset); + } isc_mempool_put(adb->afmp, f); } @@ -2033,8 +2098,9 @@ new_adbaddrinfo(dns_adb_t *adb, dns_adbentry_t *entry, in_port_t port) dns_adbaddrinfo_t *ai; ai = isc_mempool_get(adb->aimp); - if (ai == NULL) + if (ai == NULL) { return (NULL); + } ai->magic = DNS_ADBADDRINFO_MAGIC; ai->sockaddr = entry->sockaddr; @@ -2095,8 +2161,9 @@ find_name_and_lock(dns_adb_t *adb, const dns_name_t *name, unsigned int options, if (!NAME_DEAD(adbname)) { if (dns_name_equal(name, &adbname->name) && GLUEHINT_OK(adbname, options) && - STARTATZONE_MATCHES(adbname, options)) + STARTATZONE_MATCHES(adbname, options)) { return (adbname); + } } adbname = ISC_LIST_NEXT(adbname, plink); } @@ -2162,8 +2229,9 @@ entry_is_lame(dns_adb_t *adb, dns_adbentry_t *entry, const dns_name_t *qname, is_bad = false; li = ISC_LIST_HEAD(entry->lameinfo); - if (li == NULL) + if (li == NULL) { return (false); + } while (li != NULL) { next_li = ISC_LIST_NEXT(li, plink); @@ -2182,8 +2250,9 @@ entry_is_lame(dns_adb_t *adb, dns_adbentry_t *entry, const dns_name_t *qname, * we use the loop for house keeping. */ if (li != NULL && !is_bad && li->qtype == qtype && - dns_name_equal(qname, &li->qname)) + dns_name_equal(qname, &li->qname)) { is_bad = true; + } li = next_li; } @@ -2300,8 +2369,9 @@ copy_namehook_lists(dns_adb_t *adb, dns_adbfind_t *find, } out: - if (bucket != DNS_ADB_INVALIDBUCKET) + if (bucket != DNS_ADB_INVALIDBUCKET) { UNLOCK(&adb->entrylocks[bucket]); + } } static void @@ -2335,16 +2405,21 @@ check_expire_name(dns_adbname_t **namep, isc_stdtime_t now) INSIST(namep != NULL && DNS_ADBNAME_VALID(*namep)); name = *namep; - if (NAME_HAS_V4(name) || NAME_HAS_V6(name)) + if (NAME_HAS_V4(name) || NAME_HAS_V6(name)) { return (result); - if (NAME_FETCH(name)) + } + if (NAME_FETCH(name)) { return (result); - if (!EXPIRE_OK(name->expire_v4, now)) + } + if (!EXPIRE_OK(name->expire_v4, now)) { return (result); - if (!EXPIRE_OK(name->expire_v6, now)) + } + if (!EXPIRE_OK(name->expire_v6, now)) { return (result); - if (!EXPIRE_OK(name->expire_target, now)) + } + if (!EXPIRE_OK(name->expire_target, now)) { return (result); + } /* * The name is empty. Delete it. @@ -2409,8 +2484,9 @@ check_stale_name(dns_adb_t *adb, int bucket, isc_stdtime_t now) } next: - if (!overmem) + if (!overmem) { break; + } } } @@ -2426,11 +2502,13 @@ check_expire_entry(dns_adb_t *adb, dns_adbentry_t **entryp, isc_stdtime_t now) INSIST(entryp != NULL && DNS_ADBENTRY_VALID(*entryp)); entry = *entryp; - if (entry->refcnt != 0) + if (entry->refcnt != 0) { return (result); + } - if (entry->expires == 0 || entry->expires > now) + if (entry->expires == 0 || entry->expires > now) { return (result); + } /* * The entry is not in use. Delete it. @@ -2440,8 +2518,9 @@ check_expire_entry(dns_adb_t *adb, dns_adbentry_t **entryp, isc_stdtime_t now) INSIST(ISC_LINK_LINKED(entry, plink)); result = unlink_entry(adb, entry); free_adbentry(adb, &entry); - if (result) + if (result) { dec_adb_irefcnt(adb); + } return (result); } @@ -2468,8 +2547,9 @@ cleanup_names(dns_adb_t *adb, int bucket, isc_stdtime_t now) next_name = ISC_LIST_NEXT(name, plink); INSIST(result == false); result = check_expire_namehooks(name, now); - if (!result) + if (!result) { result = check_expire_name(&name, now); + } name = next_name; } UNLOCK(&adb->namelocks[bucket]); @@ -2505,8 +2585,9 @@ destroy(dns_adb_t *adb) adb->magic = 0; isc_task_detach(&adb->task); - if (adb->excl != NULL) + if (adb->excl != NULL) { isc_task_detach(&adb->excl); + } isc_mempool_destroy(&adb->nmp); isc_mempool_destroy(&adb->nhmp); @@ -2726,14 +2807,16 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr, * Allocate an internal task. */ result = isc_task_create(adb->taskmgr, 0, &adb->task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail2; + } isc_task_setname(adb->task, "ADB", adb); result = isc_stats_create(adb->mctx, &view->adbstats, dns_adbstats_max); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail2; + } set_adbstat(adb, adb->nentries, dns_adbstats_nentries); set_adbstat(adb, adb->nnames, dns_adbstats_nnames); @@ -2746,58 +2829,76 @@ dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *timermgr, return (ISC_R_SUCCESS); fail2: - if (adb->task != NULL) + if (adb->task != NULL) { isc_task_detach(&adb->task); + } /* clean up entrylocks */ isc_mutexblock_destroy(adb->entrylocks, adb->nentries); isc_mutexblock_destroy(adb->namelocks, adb->nnames); fail1: /* clean up only allocated memory */ - if (adb->entries != NULL) + if (adb->entries != NULL) { isc_mem_put(adb->mctx, adb->entries, sizeof(*adb->entries) * adb->nentries); - if (adb->deadentries != NULL) + } + if (adb->deadentries != NULL) { isc_mem_put(adb->mctx, adb->deadentries, sizeof(*adb->deadentries) * adb->nentries); - if (adb->entrylocks != NULL) + } + if (adb->entrylocks != NULL) { isc_mem_put(adb->mctx, adb->entrylocks, sizeof(*adb->entrylocks) * adb->nentries); - if (adb->entry_sd != NULL) + } + if (adb->entry_sd != NULL) { isc_mem_put(adb->mctx, adb->entry_sd, sizeof(*adb->entry_sd) * adb->nentries); - if (adb->entry_refcnt != NULL) + } + if (adb->entry_refcnt != NULL) { isc_mem_put(adb->mctx, adb->entry_refcnt, sizeof(*adb->entry_refcnt) * adb->nentries); - if (adb->names != NULL) + } + if (adb->names != NULL) { isc_mem_put(adb->mctx, adb->names, sizeof(*adb->names) * adb->nnames); - if (adb->deadnames != NULL) + } + if (adb->deadnames != NULL) { isc_mem_put(adb->mctx, adb->deadnames, sizeof(*adb->deadnames) * adb->nnames); - if (adb->namelocks != NULL) + } + if (adb->namelocks != NULL) { isc_mem_put(adb->mctx, adb->namelocks, sizeof(*adb->namelocks) * adb->nnames); - if (adb->name_sd != NULL) + } + if (adb->name_sd != NULL) { isc_mem_put(adb->mctx, adb->name_sd, sizeof(*adb->name_sd) * adb->nnames); - if (adb->name_refcnt != NULL) + } + if (adb->name_refcnt != NULL) { isc_mem_put(adb->mctx, adb->name_refcnt, sizeof(*adb->name_refcnt) * adb->nnames); - if (adb->nmp != NULL) + } + if (adb->nmp != NULL) { isc_mempool_destroy(&adb->nmp); - if (adb->nhmp != NULL) + } + if (adb->nhmp != NULL) { isc_mempool_destroy(&adb->nhmp); - if (adb->limp != NULL) + } + if (adb->limp != NULL) { isc_mempool_destroy(&adb->limp); - if (adb->emp != NULL) + } + if (adb->emp != NULL) { isc_mempool_destroy(&adb->emp); - if (adb->ahmp != NULL) + } + if (adb->ahmp != NULL) { isc_mempool_destroy(&adb->ahmp); - if (adb->aimp != NULL) + } + if (adb->aimp != NULL) { isc_mempool_destroy(&adb->aimp); - if (adb->afmp != NULL) + } + if (adb->afmp != NULL) { isc_mempool_destroy(&adb->afmp); + } isc_mutex_destroy(&adb->namescntlock); isc_mutex_destroy(&adb->entriescntlock); @@ -2805,8 +2906,9 @@ fail1: /* clean up only allocated memory */ isc_mutex_destroy(&adb->reflock); isc_mutex_destroy(&adb->mplock); isc_mutex_destroy(&adb->lock); - if (adb->excl != NULL) + if (adb->excl != NULL) { isc_task_detach(&adb->excl); + } isc_mem_putanddetach(&adb->mctx, adb, sizeof(dns_adb_t)); return (result); @@ -2902,8 +3004,9 @@ shutdown_stage2(isc_task_t *task, isc_event_t *event) adb->cevent_out = false; (void)shutdown_names(adb); (void)shutdown_entries(adb); - if (dec_adb_irefcnt(adb)) + if (dec_adb_irefcnt(adb)) { check_exit(adb); + } UNLOCK(&adb->lock); } @@ -2973,8 +3076,9 @@ dns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, start_at_zone = false; alias = false; - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); + } /* * XXXMLG Move this comment somewhere else! @@ -2998,8 +3102,9 @@ dns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, */ find = new_adbfind(adb); - if (find == NULL) + if (find == NULL) { return (ISC_R_NOMEMORY); + } find->port = port; @@ -3012,10 +3117,11 @@ dns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, REQUIRE(task != NULL); } - if (isc_log_wouldlog(dns_lctx, DEF_LEVEL)) + if (isc_log_wouldlog(dns_lctx, DEF_LEVEL)) { dns_name_format(name, namebuf, sizeof(namebuf)); - else + } else { namebuf[0] = 0; + } /* * Try to see if we know anything about this name at all. @@ -3048,12 +3154,15 @@ dns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, goto out; } link_name(adb, bucket, adbname); - if (FIND_HINTOK(find)) + if (FIND_HINTOK(find)) { adbname->flags |= NAME_HINT_OK; - if (FIND_GLUEOK(find)) + } + if (FIND_GLUEOK(find)) { adbname->flags |= NAME_GLUE_OK; - if (FIND_STARTATZONE(find)) + } + if (FIND_STARTATZONE(find)) { adbname->flags |= NAME_STARTATZONE; + } } else { /* Move this name forward in the LRU list */ ISC_LIST_UNLINK(adb->names[bucket], adbname, plink); @@ -3115,13 +3224,15 @@ dns_adb_createfind(dns_adb_t *adb, isc_task_t *task, isc_taskaction_t action, * * If the result is neither of these, try a fetch for A. */ - if (NXDOMAIN_RESULT(result)) + if (NXDOMAIN_RESULT(result)) { goto fetch; - else if (NXRRSET_RESULT(result)) + } else if (NXRRSET_RESULT(result)) { goto v6; + } - if (!NAME_FETCH_V4(adbname)) + if (!NAME_FETCH_V4(adbname)) { wanted_fetches |= DNS_ADBFIND_INET; + } } v6: @@ -3150,19 +3261,22 @@ v6: * Listen to negative cache hints, and don't start * another query. */ - if (NCACHE_RESULT(result) || AUTH_NX(result)) + if (NCACHE_RESULT(result) || AUTH_NX(result)) { goto fetch; + } - if (!NAME_FETCH_V6(adbname)) + if (!NAME_FETCH_V6(adbname)) { wanted_fetches |= DNS_ADBFIND_INET6; + } } fetch: if ((WANT_INET(wanted_addresses) && NAME_HAS_V4(adbname)) || - (WANT_INET6(wanted_addresses) && NAME_HAS_V6(adbname))) + (WANT_INET6(wanted_addresses) && NAME_HAS_V6(adbname))) { have_address = true; - else + } else { have_address = false; + } if (wanted_fetches != 0 && !(FIND_AVOIDFETCHES(find) && have_address)) { /* * We're missing at least one address family. Either the @@ -3171,8 +3285,9 @@ fetch: * be acceptable so we have to launch fetches. */ - if (FIND_STARTATZONE(find)) + if (FIND_STARTATZONE(find)) { start_at_zone = true; + } /* * Start V4. @@ -3206,24 +3321,30 @@ fetch: copy_namehook_lists(adb, find, qname, qtype, adbname, now); post_copy: - if (NAME_FETCH_V4(adbname)) + if (NAME_FETCH_V4(adbname)) { query_pending |= DNS_ADBFIND_INET; - if (NAME_FETCH_V6(adbname)) + } + if (NAME_FETCH_V6(adbname)) { query_pending |= DNS_ADBFIND_INET6; + } /* * Attach to the name's query list if there are queries * already running, and we have been asked to. */ want_event = true; - if (!FIND_WANTEVENT(find)) + if (!FIND_WANTEVENT(find)) { want_event = false; - if (FIND_WANTEMPTYEVENT(find) && FIND_HAS_ADDRS(find)) + } + if (FIND_WANTEMPTYEVENT(find) && FIND_HAS_ADDRS(find)) { want_event = false; - if ((wanted_addresses & query_pending) == 0) + } + if ((wanted_addresses & query_pending) == 0) { want_event = false; - if (alias) + } + if (alias) { want_event = false; + } if (want_event) { find->adbname = adbname; find->name_bucket = bucket; @@ -3255,8 +3376,9 @@ post_copy: dns_name_copynf(&adbname->target, target); } result = DNS_R_ALIAS; - } else + } else { result = ISC_R_SUCCESS; + } /* * Copy out error flags from the name structure into the find. @@ -3339,8 +3461,9 @@ dns_adb_destroyfind(dns_adbfind_t **findp) * lock is destroyed. */ LOCK(&adb->lock); - if (free_adbfind(adb, &find)) + if (free_adbfind(adb, &find)) { check_exit(adb); + } UNLOCK(&adb->lock); } @@ -3364,8 +3487,9 @@ dns_adb_cancelfind(dns_adbfind_t *find) REQUIRE(FIND_WANTEVENT(find)); bucket = find->name_bucket; - if (bucket == DNS_ADB_INVALIDBUCKET) + if (bucket == DNS_ADB_INVALIDBUCKET) { goto cleanup; + } /* * We need to get the adbname's lock to unlink the find. @@ -3422,10 +3546,12 @@ dns_adb_dump(dns_adb_t *adb, FILE *f) LOCK(&adb->lock); isc_stdtime_get(&now); - for (i = 0; i < adb->nnames; i++) + for (i = 0; i < adb->nnames; i++) { RUNTIME_CHECK(cleanup_names(adb, i, now) == false); - for (i = 0; i < adb->nentries; i++) + } + for (i = 0; i < adb->nentries; i++) { RUNTIME_CHECK(cleanup_entries(adb, i, now) == false); + } dump_adb(adb, f, false, now); UNLOCK(&adb->lock); @@ -3434,8 +3560,9 @@ dns_adb_dump(dns_adb_t *adb, FILE *f) static void dump_ttl(FILE *f, const char *legend, isc_stdtime_t value, isc_stdtime_t now) { - if (value == INT_MAX) + if (value == INT_MAX) { return; + } fprintf(f, " [%s TTL %d]", legend, (int)(value - now)); } @@ -3470,7 +3597,7 @@ dump_adb(dns_adb_t *adb, FILE *f, bool debug, isc_stdtime_t now) for (size_t i = 0; i < adb->nentries; i++) { LOCK(&adb->entrylocks[i]); } -#endif +#endif /* ifndef __SANITIZE_THREAD__ */ /* * Dump the names @@ -3478,12 +3605,12 @@ dump_adb(dns_adb_t *adb, FILE *f, bool debug, isc_stdtime_t now) for (size_t i = 0; i < adb->nnames; i++) { #ifdef __SANITIZE_THREAD__ LOCK(&adb->namelocks[i]); -#endif +#endif /* ifdef __SANITIZE_THREAD__ */ name = ISC_LIST_HEAD(adb->names[i]); if (name == NULL) { #ifdef __SANITIZE_THREAD__ UNLOCK(&adb->namelocks[i]); -#endif +#endif /* ifdef __SANITIZE_THREAD__ */ continue; } if (debug) { @@ -3523,7 +3650,7 @@ dump_adb(dns_adb_t *adb, FILE *f, bool debug, isc_stdtime_t now) } #ifdef __SANITIZE_THREAD__ UNLOCK(&adb->namelocks[i]); -#endif +#endif /* ifdef __SANITIZE_THREAD__ */ } fprintf(f, ";\n; Unassociated entries\n;\n"); @@ -3531,16 +3658,17 @@ dump_adb(dns_adb_t *adb, FILE *f, bool debug, isc_stdtime_t now) for (size_t i = 0; i < adb->nentries; i++) { #ifdef __SANITIZE_THREAD__ LOCK(&adb->entrylocks[i]); -#endif +#endif /* ifdef __SANITIZE_THREAD__ */ entry = ISC_LIST_HEAD(adb->entries[i]); while (entry != NULL) { - if (entry->nh == 0) + if (entry->nh == 0) { dump_entry(f, adb, entry, debug, now); + } entry = ISC_LIST_NEXT(entry, plink); } #ifdef __SANITIZE_THREAD__ UNLOCK(&adb->entrylocks[i]); -#endif +#endif /* ifdef __SANITIZE_THREAD__ */ } #ifndef __SANITIZE_THREAD__ @@ -3553,7 +3681,7 @@ dump_adb(dns_adb_t *adb, FILE *f, bool debug, isc_stdtime_t now) for (ssize_t i = adb->nnames - 1; i >= 0; i--) { UNLOCK(&adb->namelocks[i]); } -#endif +#endif /* ifndef __SANITIZE_THREAD__ */ } static void @@ -3568,8 +3696,9 @@ dump_entry(FILE *f, dns_adb_t *adb, dns_adbentry_t *entry, bool debug, isc_netaddr_fromsockaddr(&netaddr, &entry->sockaddr); isc_netaddr_format(&netaddr, addrbuf, sizeof(addrbuf)); - if (debug) + if (debug) { fprintf(f, ";\t%p: refcnt %u\n", entry, entry->refcnt); + } fprintf(f, ";\t%s [srtt %u] [flags %08x] [edns %u/%u/%u/%u/%u] " @@ -3577,17 +3706,20 @@ dump_entry(FILE *f, dns_adb_t *adb, dns_adbentry_t *entry, bool debug, addrbuf, entry->srtt, entry->flags, entry->edns, entry->to4096, entry->to1432, entry->to1232, entry->to512, entry->plain, entry->plainto); - if (entry->udpsize != 0U) + if (entry->udpsize != 0U) { fprintf(f, " [udpsize %u]", entry->udpsize); + } if (entry->cookie != NULL) { unsigned int i; fprintf(f, " [cookie="); - for (i = 0; i < entry->cookielen; i++) + for (i = 0; i < entry->cookielen; i++) { fprintf(f, "%02x", entry->cookie[i]); + } fprintf(f, "]"); } - if (entry->expires != 0) + if (entry->expires != 0) { fprintf(f, " [ttl %d]", (int)(entry->expires - now)); + } if (adb != NULL && adb->quota != 0 && adb->atr_freq != 0) { fprintf(f, " [atr %0.2f] [quota %" PRIuFAST32 "]", entry->atr, @@ -3628,8 +3760,9 @@ dns_adb_dumpfind(dns_adbfind_t *find, FILE *f) find->name_bucket, find->adbname, find->event.ev_sender); ai = ISC_LIST_HEAD(find->list); - if (ai != NULL) + if (ai != NULL) { fprintf(f, "\tAddresses:\n"); + } while (ai != NULL) { sa = &ai->sockaddr; switch (sa->type.sa.sa_family) { @@ -3645,8 +3778,9 @@ dns_adb_dumpfind(dns_adbfind_t *find, FILE *f) tmpp = "UnkFamily"; } - if (tmpp == NULL) + if (tmpp == NULL) { tmpp = "BadAddress"; + } fprintf(f, "\t\tentry %p, flags %08x" @@ -3678,8 +3812,9 @@ print_namehook_list(FILE *f, const char *legend, dns_adb_t *adb, for (nh = ISC_LIST_HEAD(*list); nh != NULL; nh = ISC_LIST_NEXT(nh, plink)) { - if (debug) + if (debug) { fprintf(f, ";\tHook(%s) %p\n", legend, nh); + } dump_entry(f, adb, nh->entry, debug, now); } } @@ -3693,10 +3828,12 @@ print_fetch(FILE *f, dns_adbfetch_t *ft, const char *type) static void print_fetch_list(FILE *f, dns_adbname_t *n) { - if (NAME_FETCH_A(n)) + if (NAME_FETCH_A(n)) { print_fetch(f, n->fetch_a, "A"); - if (NAME_FETCH_AAAA(n)) + } + if (NAME_FETCH_AAAA(n)) { print_fetch(f, n->fetch_aaaa, "AAAA"); + } } static void @@ -3728,10 +3865,11 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype) fname = dns_fixedname_initname(&foundname); dns_rdataset_init(&rdataset); - if (rdtype == dns_rdatatype_a) + if (rdtype == dns_rdatatype_a) { adbname->fetch_err = FIND_ERR_UNEXPECTED; - else + } else { adbname->fetch6_err = FIND_ERR_UNEXPECTED; + } /* * We need to specify whether to search static-stub zones (if @@ -3757,10 +3895,11 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype) * any information, return success, or else a fetch * will be made, which will only make things worse. */ - if (rdtype == dns_rdatatype_a) + if (rdtype == dns_rdatatype_a) { adbname->fetch_err = FIND_ERR_SUCCESS; - else + } else { adbname->fetch6_err = FIND_ERR_SUCCESS; + } result = import_rdataset(adbname, &rdataset, now); break; case DNS_R_NXDOMAIN: @@ -3778,19 +3917,21 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype) DP(NCACHE_LEVEL, "adb name %p: Caching auth negative entry for A", adbname); - if (result == DNS_R_NXDOMAIN) + if (result == DNS_R_NXDOMAIN) { adbname->fetch_err = FIND_ERR_NXDOMAIN; - else + } else { adbname->fetch_err = FIND_ERR_NXRRSET; + } } else { DP(NCACHE_LEVEL, "adb name %p: Caching auth negative entry for AAAA", adbname); adbname->expire_v6 = now + 30; - if (result == DNS_R_NXDOMAIN) + if (result == DNS_R_NXDOMAIN) { adbname->fetch6_err = FIND_ERR_NXDOMAIN; - else + } else { adbname->fetch6_err = FIND_ERR_NXRRSET; + } } break; case DNS_R_NCACHENXDOMAIN: @@ -3802,10 +3943,11 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype) rdataset.ttl = ttlclamp(rdataset.ttl); if (rdtype == dns_rdatatype_a) { adbname->expire_v4 = rdataset.ttl + now; - if (result == DNS_R_NCACHENXDOMAIN) + if (result == DNS_R_NCACHENXDOMAIN) { adbname->fetch_err = FIND_ERR_NXDOMAIN; - else + } else { adbname->fetch_err = FIND_ERR_NXRRSET; + } DP(NCACHE_LEVEL, "adb name %p: Caching negative entry for A (ttl %u)", adbname, rdataset.ttl); @@ -3815,10 +3957,11 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype) "%u)", adbname, rdataset.ttl); adbname->expire_v6 = rdataset.ttl + now; - if (result == DNS_R_NCACHENXDOMAIN) + if (result == DNS_R_NCACHENXDOMAIN) { adbname->fetch6_err = FIND_ERR_NXDOMAIN; - else + } else { adbname->fetch6_err = FIND_ERR_NXRRSET; + } } break; case DNS_R_CNAME: @@ -3840,15 +3983,17 @@ dbfind_name(dns_adbname_t *adbname, isc_stdtime_t now, dns_rdatatype_t rdtype) adbname); adbname->expire_target = rdataset.ttl + now; } - if (rdtype == dns_rdatatype_a) + if (rdtype == dns_rdatatype_a) { adbname->fetch_err = FIND_ERR_SUCCESS; - else + } else { adbname->fetch6_err = FIND_ERR_SUCCESS; + } break; } - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -3890,8 +4035,9 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) address_type = DNS_ADBFIND_INET6; fetch = name->fetch_aaaa; name->fetch_aaaa = NULL; - } else + } else { fetch = NULL; + } INSIST(address_type != 0 && fetch != NULL); @@ -3903,10 +4049,12 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) /* * Cleanup things we don't care about. */ - if (dev->node != NULL) + if (dev->node != NULL) { dns_db_detachnode(dev->db, &dev->node); - if (dev->db != NULL) + } + if (dev->db != NULL) { dns_db_detach(&dev->db); + } /* * If this name is marked as dead, clean up, throwing away @@ -3943,10 +4091,11 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) name, dev->rdataset->ttl); name->expire_v4 = ISC_MIN(name->expire_v4, dev->rdataset->ttl + now); - if (dev->result == DNS_R_NCACHENXDOMAIN) + if (dev->result == DNS_R_NCACHENXDOMAIN) { name->fetch_err = FIND_ERR_NXDOMAIN; - else + } else { name->fetch_err = FIND_ERR_NXRRSET; + } inc_stats(adb, dns_resstatscounter_gluefetchv4fail); } else { DP(NCACHE_LEVEL, @@ -3955,10 +4104,11 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) name, dev->rdataset->ttl); name->expire_v6 = ISC_MIN(name->expire_v6, dev->rdataset->ttl + now); - if (dev->result == DNS_R_NCACHENXDOMAIN) + if (dev->result == DNS_R_NCACHENXDOMAIN) { name->fetch6_err = FIND_ERR_NXDOMAIN; - else + } else { name->fetch6_err = FIND_ERR_NXRRSET; + } inc_stats(adb, dns_resstatscounter_gluefetchv6fail); } goto out; @@ -3997,8 +4147,9 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) * Don't record a failure unless this is the initial * fetch of a chain. */ - if (fetch->depth > 1) + if (fetch->depth > 1) { goto out; + } /* XXXMLG Don't pound on bad servers. */ if (address_type == DNS_ADBFIND_INET) { name->expire_v4 = ISC_MIN(name->expire_v4, now + 10); @@ -4020,10 +4171,11 @@ fetch_callback(isc_task_t *task, isc_event_t *ev) check_result: if (result == ISC_R_SUCCESS) { ev_status = DNS_EVENT_ADBMOREADDRESSES; - if (address_type == DNS_ADBFIND_INET) + if (address_type == DNS_ADBFIND_INET) { name->fetch_err = FIND_ERR_SUCCESS; - else + } else { name->fetch6_err = FIND_ERR_SUCCESS; + } } out: @@ -4069,8 +4221,9 @@ fetch_name(dns_adbname_t *adbname, bool start_at_zone, unsigned int depth, result = dns_view_findzonecut(adb->view, &adbname->name, name, NULL, 0, 0, true, false, &rdataset, NULL); - if (result != ISC_R_SUCCESS && result != DNS_R_HINT) + if (result != ISC_R_SUCCESS && result != DNS_R_HINT) { goto cleanup; + } nameservers = &rdataset; options |= DNS_FETCHOPT_UNSHARED; } @@ -4109,10 +4262,12 @@ fetch_name(dns_adbname_t *adbname, bool start_at_zone, unsigned int depth, fetch = NULL; /* Keep us from cleaning this up below. */ cleanup: - if (fetch != NULL) + if (fetch != NULL) { free_adbfetch(adb, &fetch); - if (dns_rdataset_isassociated(&rdataset)) + } + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -4138,11 +4293,13 @@ dns_adb_marklame(dns_adb_t *adb, dns_adbaddrinfo_t *addr, LOCK(&adb->entrylocks[bucket]); li = ISC_LIST_HEAD(addr->entry->lameinfo); while (li != NULL && - (li->qtype != qtype || !dns_name_equal(qname, &li->qname))) + (li->qtype != qtype || !dns_name_equal(qname, &li->qname))) { li = ISC_LIST_NEXT(li, plink); + } if (li != NULL) { - if (expire_time > li->lame_timer) + if (expire_time > li->lame_timer) { li->lame_timer = expire_time; + } goto unlock; } li = new_adblameinfo(adb, qname, qtype); @@ -4174,8 +4331,9 @@ dns_adb_adjustsrtt(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int rtt, bucket = addr->entry->lock_bucket; LOCK(&adb->entrylocks[bucket]); - if (addr->entry->expires == 0 || factor == DNS_ADB_RTTADJAGE) + if (addr->entry->expires == 0 || factor == DNS_ADB_RTTADJAGE) { isc_stdtime_get(&now); + } adjustsrtt(addr, rtt, factor, now); UNLOCK(&adb->entrylocks[bucket]); @@ -4210,17 +4368,20 @@ adjustsrtt(dns_adbaddrinfo_t *addr, unsigned int rtt, unsigned int factor, new_srtt -= addr->entry->srtt; new_srtt >>= 9; addr->entry->lastage = now; - } else + } else { new_srtt = addr->entry->srtt; - } else + } + } else { new_srtt = ((uint64_t)addr->entry->srtt / 10 * factor) + ((uint64_t)rtt / 10 * (10 - factor)); + } addr->entry->srtt = (unsigned int)new_srtt; addr->srtt = (unsigned int)new_srtt; - if (addr->entry->expires == 0) + if (addr->entry->expires == 0) { addr->entry->expires = now + ADB_ENTRY_WINDOW; + } } void @@ -4284,14 +4445,17 @@ maybe_adjust_quota(dns_adb_t *adb, dns_adbaddrinfo_t *addr, bool timeout) UNUSED(adb); - if (adb->quota == 0 || adb->atr_freq == 0) + if (adb->quota == 0 || adb->atr_freq == 0) { return; + } - if (timeout) + if (timeout) { addr->entry->timeouts++; + } - if (addr->entry->completed++ <= adb->atr_freq) + if (addr->entry->completed++ <= adb->atr_freq) { return; + } /* * Calculate an exponential rolling average of the timeout ratio @@ -4461,8 +4625,9 @@ dns_adb_ednsto(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int size) addr->entry->to4096++; } } else { - if (addr->entry->to4096 <= EDNSTOS) + if (addr->entry->to4096 <= EDNSTOS) { addr->entry->to4096++; + } } if (addr->entry->to4096 == 0xff) { @@ -4487,10 +4652,12 @@ dns_adb_setudpsize(dns_adb_t *adb, dns_adbaddrinfo_t *addr, unsigned int size) bucket = addr->entry->lock_bucket; LOCK(&adb->entrylocks[bucket]); - if (size < 512U) + if (size < 512U) { size = 512U; - if (size > addr->entry->udpsize) + } + if (size > addr->entry->udpsize) { addr->entry->udpsize = size; + } maybe_adjust_quota(adb, addr, false); @@ -4535,21 +4702,23 @@ dns_adb_probesize(dns_adb_t *adb, dns_adbaddrinfo_t *addr, int lookups) bucket = addr->entry->lock_bucket; LOCK(&adb->entrylocks[bucket]); - if (addr->entry->to1232 > EDNSTOS || lookups >= 2) + if (addr->entry->to1232 > EDNSTOS || lookups >= 2) { size = 512; - else if (addr->entry->to1432 > EDNSTOS || lookups >= 1) + } else if (addr->entry->to1432 > EDNSTOS || lookups >= 1) { size = 1232; - else if (addr->entry->to4096 > EDNSTOS) + } else if (addr->entry->to4096 > EDNSTOS) { size = 1432; - else + } else { size = 4096; + } /* * Don't shrink probe size below what we have seen due to multiple * lookups. */ if (lookups > 0 && size < addr->entry->udpsize && - addr->entry->udpsize < 4096) + addr->entry->udpsize < 4096) { size = addr->entry->udpsize; + } UNLOCK(&adb->entrylocks[bucket]); return (size); @@ -4580,8 +4749,9 @@ dns_adb_setcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr, addr->entry->cookielen = (uint16_t)len; } - if (addr->entry->cookie != NULL) + if (addr->entry->cookie != NULL) { memmove(addr->entry->cookie, cookie, len); + } UNLOCK(&adb->entrylocks[bucket]); } @@ -4600,8 +4770,9 @@ dns_adb_getcookie(dns_adb_t *adb, dns_adbaddrinfo_t *addr, len >= addr->entry->cookielen) { memmove(cookie, addr->entry->cookie, addr->entry->cookielen); len = addr->entry->cookielen; - } else + } else { len = 0; + } UNLOCK(&adb->entrylocks[bucket]); return (len); @@ -4642,8 +4813,9 @@ dns_adb_findaddrinfo(dns_adb_t *adb, const isc_sockaddr_t *sa, entry->sockaddr = *sa; link_entry(adb, bucket, entry); DP(ENTER_LEVEL, "findaddrinfo: new entry %p", entry); - } else + } else { DP(ENTER_LEVEL, "findaddrinfo: found entry %p", entry); + } port = isc_sockaddr_getport(sa); addr = new_adbaddrinfo(adb, entry, port); @@ -4714,14 +4886,16 @@ dns_adb_flush(dns_adb_t *adb) /* * Call our cleanup routines. */ - for (i = 0; i < adb->nnames; i++) + for (i = 0; i < adb->nnames; i++) { RUNTIME_CHECK(cleanup_names(adb, i, INT_MAX) == false); - for (i = 0; i < adb->nentries; i++) + } + for (i = 0; i < adb->nentries; i++) { RUNTIME_CHECK(cleanup_entries(adb, i, INT_MAX) == false); + } #ifdef DUMP_ADB_AFTER_CLEANING dump_adb(adb, stdout, true, INT_MAX); -#endif +#endif /* ifdef DUMP_ADB_AFTER_CLEANING */ UNLOCK(&adb->lock); } @@ -4810,16 +4984,18 @@ dns_adb_setadbsize(dns_adb_t *adb, size_t size) INSIST(DNS_ADB_VALID(adb)); - if (size != 0U && size < DNS_ADB_MINADBSIZE) + if (size != 0U && size < DNS_ADB_MINADBSIZE) { size = DNS_ADB_MINADBSIZE; + } hiwater = size - (size >> 3); /* Approximately 7/8ths. */ lowater = size - (size >> 2); /* Approximately 3/4ths. */ - if (size == 0U || hiwater == 0U || lowater == 0U) + if (size == 0U || hiwater == 0U || lowater == 0U) { isc_mem_setwater(adb->mctx, water, adb, 0, 0); - else + } else { isc_mem_setwater(adb->mctx, water, adb, hiwater, lowater); + } } void diff --git a/lib/dns/badcache.c b/lib/dns/badcache.c index e18cf24e09..86903f4cd3 100644 --- a/lib/dns/badcache.c +++ b/lib/dns/badcache.c @@ -109,10 +109,11 @@ badcache_resize(dns_badcache_t *bc, isc_time_t *now, bool grow) dns_bcentry_t **newtable, *bad, *next; unsigned int newsize, i; - if (grow) + if (grow) { newsize = bc->size * 2 + 1; - else + } else { newsize = (bc->size - 1) / 2; + } newtable = isc_mem_get(bc->mctx, sizeof(dns_bcentry_t *) * newsize); memset(newtable, 0, sizeof(dns_bcentry_t *) * newsize); @@ -156,8 +157,9 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, LOCK(&bc->lock); result = isc_time_now(&now); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_time_settoepoch(&now); + } hashval = dns_name_hash(name, false); i = hashval % bc->size; @@ -172,15 +174,17 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, break; } if (isc_time_compare(&bad->expire, &now) < 0) { - if (prev == NULL) + if (prev == NULL) { bc->table[i] = bad->next; - else + } else { prev->next = bad->next; + } isc_mem_put(bc->mctx, bad, sizeof(*bad) + bad->name.length); bc->count--; - } else + } else { prev = bad; + } } if (bad == NULL) { @@ -196,12 +200,15 @@ dns_badcache_add(dns_badcache_t *bc, const dns_name_t *name, bad->next = bc->table[i]; bc->table[i] = bad; bc->count++; - if (bc->count > bc->size * 8) + if (bc->count > bc->size * 8) { badcache_resize(bc, &now, true); - if (bc->count < bc->size * 2 && bc->size > bc->minsize) + } + if (bc->count < bc->size * 2 && bc->size > bc->minsize) { badcache_resize(bc, &now, false); - } else + } + } else { bad->expire = *expire; + } UNLOCK(&bc->lock); } @@ -232,8 +239,9 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name, * name->link to store the type specific part. */ - if (bc->count == 0) + if (bc->count == 0) { goto skip; + } i = dns_name_hash(name, false) % bc->size; prev = NULL; @@ -243,10 +251,11 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name, * Search the hash list. Clean out expired records as we go. */ if (isc_time_compare(&bad->expire, now) < 0) { - if (prev != NULL) + if (prev != NULL) { prev->next = bad->next; - else + } else { bc->table[i] = bad->next; + } isc_mem_put(bc->mctx, bad, sizeof(*bad) + bad->name.length); @@ -254,8 +263,9 @@ dns_badcache_find(dns_badcache_t *bc, const dns_name_t *name, continue; } if (bad->type == type && dns_name_equal(name, &bad->name)) { - if (flagp != NULL) + if (flagp != NULL) { *flagp = bad->flags; + } answer = true; break; } @@ -311,8 +321,9 @@ dns_badcache_flushname(dns_badcache_t *bc, const dns_name_t *name) LOCK(&bc->lock); result = isc_time_now(&now); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_time_settoepoch(&now); + } i = dns_name_hash(name, false) % bc->size; prev = NULL; for (bad = bc->table[i]; bad != NULL; bad = next) { @@ -320,16 +331,18 @@ dns_badcache_flushname(dns_badcache_t *bc, const dns_name_t *name) next = bad->next; n = isc_time_compare(&bad->expire, &now); if (n < 0 || dns_name_equal(name, &bad->name)) { - if (prev == NULL) + if (prev == NULL) { bc->table[i] = bad->next; - else + } else { prev->next = bad->next; + } isc_mem_put(bc->mctx, bad, sizeof(*bad) + bad->name.length); bc->count--; - } else + } else { prev = bad; + } } UNLOCK(&bc->lock); @@ -350,8 +363,9 @@ dns_badcache_flushtree(dns_badcache_t *bc, const dns_name_t *name) LOCK(&bc->lock); result = isc_time_now(&now); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_time_settoepoch(&now); + } for (i = 0; bc->count > 0 && i < bc->size; i++) { prev = NULL; @@ -359,16 +373,18 @@ dns_badcache_flushtree(dns_badcache_t *bc, const dns_name_t *name) next = bad->next; n = isc_time_compare(&bad->expire, &now); if (n < 0 || dns_name_issubdomain(&bad->name, name)) { - if (prev == NULL) + if (prev == NULL) { bc->table[i] = bad->next; - else + } else { prev->next = bad->next; + } isc_mem_put(bc->mctx, bad, sizeof(*bad) + bad->name.length); bc->count--; - } else + } else { prev = bad; + } } } @@ -398,10 +414,11 @@ dns_badcache_print(dns_badcache_t *bc, const char *cachename, FILE *fp) for (bad = bc->table[i]; bad != NULL; bad = next) { next = bad->next; if (isc_time_compare(&bad->expire, &now) < 0) { - if (prev != NULL) + if (prev != NULL) { prev->next = bad->next; - else + } else { bc->table[i] = bad->next; + } isc_mem_put(bc->mctx, bad, sizeof(*bad) + bad->name.length); diff --git a/lib/dns/byaddr.c b/lib/dns/byaddr.c index c940b5f806..f46d20bc33 100644 --- a/lib/dns/byaddr.c +++ b/lib/dns/byaddr.c @@ -78,8 +78,9 @@ dns_byaddr_createptrname(const isc_netaddr_t *address, unsigned int options, } remaining = sizeof(textname) - (cp - textname); strlcpy(cp, "ip6.arpa.", remaining); - } else + } else { return (ISC_R_NOTIMPLEMENTED); + } len = (unsigned int)strlen(textname); isc_buffer_init(&buffer, textname, len); @@ -122,8 +123,9 @@ copy_ptr_targets(dns_byaddr_t *byaddr, dns_rdataset_t *rdataset) dns_rdata_ptr_t ptr; dns_rdataset_current(rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &ptr, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } name = isc_mem_get(byaddr->mctx, sizeof(*name)); dns_name_init(name, NULL); dns_name_dup(&ptr.ptr, byaddr->mctx, name); @@ -132,8 +134,9 @@ copy_ptr_targets(dns_byaddr_t *byaddr, dns_rdataset_t *rdataset) dns_rdata_reset(&rdata); result = dns_rdataset_next(rdataset); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } return (result); } @@ -156,8 +159,9 @@ lookup_done(isc_task_t *task, isc_event_t *event) if (levent->result == ISC_R_SUCCESS) { result = copy_ptr_targets(byaddr, levent->rdataset); byaddr->event->result = result; - } else + } else { byaddr->event->result = levent->result; + } isc_event_free(&event); isc_task_sendanddetach(&byaddr->task, (isc_event_t **)&byaddr->event); } @@ -213,15 +217,17 @@ dns_byaddr_create(isc_mem_t *mctx, const isc_netaddr_t *address, result = dns_byaddr_createptrname(address, options, dns_fixedname_name(&byaddr->name)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_lock; + } byaddr->lookup = NULL; result = dns_lookup_create(mctx, dns_fixedname_name(&byaddr->name), dns_rdatatype_ptr, view, 0, task, lookup_done, byaddr, &byaddr->lookup); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_lock; + } byaddr->canceled = false; byaddr->magic = BYADDR_MAGIC; @@ -253,8 +259,9 @@ dns_byaddr_cancel(dns_byaddr_t *byaddr) if (!byaddr->canceled) { byaddr->canceled = true; - if (byaddr->lookup != NULL) + if (byaddr->lookup != NULL) { dns_lookup_cancel(byaddr->lookup); + } } UNLOCK(&byaddr->lock); diff --git a/lib/dns/cache.c b/lib/dns/cache.c index 4fce32e0dc..0d50a2aaaa 100644 --- a/lib/dns/cache.c +++ b/lib/dns/cache.c @@ -106,15 +106,16 @@ struct cache_cleaner { dns_cache_t *cache; isc_task_t * task; isc_event_t *resched_event; /*% Sent by cleaner task to - itself to reschedule */ + * itself to reschedule */ isc_event_t *overmem_event; dns_dbiterator_t *iterator; unsigned int increment; /*% Number of names to - clean in one increment */ + * clean in one increment */ cleaner_state_t state; /*% Idle/Busy. */ - bool overmem; /*% The cache is in an overmem state. */ - bool replaceiterator; + bool overmem; /*% The cache is in an overmem state. + * */ + bool replaceiterator; }; /*% @@ -172,8 +173,9 @@ cache_create_db(dns_cache_t *cache, dns_db_t **db) result = dns_db_create(cache->mctx, cache->db_type, dns_rootname, dns_dbtype_cache, cache->rdclass, cache->db_argc, cache->db_argv, db); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_db_setservestalettl(*db, cache->serve_stale_ttl); + } return (result); } @@ -216,8 +218,9 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, cache->stats = NULL; result = isc_stats_create(cmctx, &cache->stats, dns_cachestatscounter_max); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_filelock; + } cache->db_type = isc_mem_strdup(cmctx, db_type); @@ -226,8 +229,9 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, * via cache->db_argv, followed by the rest of the arguments in * db_argv (of which there really shouldn't be any). */ - if (strcmp(cache->db_type, "rbt") == 0) + if (strcmp(cache->db_type, "rbt") == 0) { extra = 1; + } cache->db_argc = db_argc + extra; cache->db_argv = NULL; @@ -236,8 +240,9 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, cache->db_argv = isc_mem_get(cmctx, cache->db_argc * sizeof(char *)); - for (i = 0; i < cache->db_argc; i++) + for (i = 0; i < cache->db_argc; i++) { cache->db_argv[i] = NULL; + } cache->db_argv[0] = (char *)hmctx; for (i = extra; i < cache->db_argc; i++) { @@ -251,13 +256,15 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, */ cache->db = NULL; result = cache_create_db(cache, &cache->db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_dbargv; + } if (taskmgr != NULL) { dbtask = NULL; result = isc_task_create(taskmgr, 1, &dbtask); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_db; + } isc_task_setname(dbtask, "cache_dbtask", NULL); dns_db_settask(cache->db, dbtask); @@ -272,18 +279,20 @@ dns_cache_create(isc_mem_t *cmctx, isc_mem_t *hmctx, isc_taskmgr_t *taskmgr, * RBT-type cache DB has its own mechanism of cache cleaning and doesn't * need the control of the generic cleaner. */ - if (strcmp(db_type, "rbt") == 0) + if (strcmp(db_type, "rbt") == 0) { result = cache_cleaner_init(cache, NULL, NULL, &cache->cleaner); - else { + } else { result = cache_cleaner_init(cache, taskmgr, timermgr, &cache->cleaner); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_db; + } result = dns_db_setcachestats(cache->db, cache->stats); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_db; + } *cachep = cache; return (ISC_R_SUCCESS); @@ -296,9 +305,10 @@ cleanup_dbargv: isc_mem_free(cmctx, cache->db_argv[i]); } } - if (cache->db_argv != NULL) + if (cache->db_argv != NULL) { isc_mem_put(cmctx, cache->db_argv, cache->db_argc * sizeof(char *)); + } isc_mem_free(cmctx, cache->db_type); cleanup_filelock: isc_mutex_destroy(&cache->filelock); @@ -456,8 +466,9 @@ dns_cache_setfilename(dns_cache_t *cache, const char *filename) newname = isc_mem_strdup(cache->mctx, filename); LOCK(&cache->filelock); - if (cache->filename) + if (cache->filename) { isc_mem_free(cache->mctx, cache->filename); + } cache->filename = newname; UNLOCK(&cache->filelock); @@ -471,8 +482,9 @@ dns_cache_load(dns_cache_t *cache) REQUIRE(VALID_CACHE(cache)); - if (cache->filename == NULL) + if (cache->filename == NULL) { return (ISC_R_SUCCESS); + } LOCK(&cache->filelock); result = dns_db_load(cache->db, cache->filename, dns_masterformat_text, @@ -489,8 +501,9 @@ dns_cache_dump(dns_cache_t *cache) REQUIRE(VALID_CACHE(cache)); - if (cache->filename == NULL) + if (cache->filename == NULL) { return (ISC_R_SUCCESS); + } LOCK(&cache->filelock); result = dns_master_dump(cache->mctx, cache->db, NULL, @@ -534,8 +547,9 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr, result = dns_db_createiterator(cleaner->cache->db, false, &cleaner->iterator); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } if (taskmgr != NULL && timermgr != NULL) { result = isc_task_create(taskmgr, 1, &cleaner->task); @@ -573,14 +587,18 @@ cache_cleaner_init(dns_cache_t *cache, isc_taskmgr_t *taskmgr, return (ISC_R_SUCCESS); cleanup: - if (cleaner->overmem_event != NULL) + if (cleaner->overmem_event != NULL) { isc_event_free(&cleaner->overmem_event); - if (cleaner->resched_event != NULL) + } + if (cleaner->resched_event != NULL) { isc_event_free(&cleaner->resched_event); - if (cleaner->task != NULL) + } + if (cleaner->task != NULL) { isc_task_detach(&cleaner->task); - if (cleaner->iterator != NULL) + } + if (cleaner->iterator != NULL) { dns_dbiterator_destroy(&cleaner->iterator); + } isc_mutex_destroy(&cleaner->lock); return (result); @@ -597,16 +615,17 @@ begin_cleaning(cache_cleaner_t *cleaner) * Create an iterator, if it does not already exist, and * position it at the beginning of the cache. */ - if (cleaner->iterator == NULL) + if (cleaner->iterator == NULL) { result = dns_db_createiterator(cleaner->cache->db, false, &cleaner->iterator); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_WARNING, "cache cleaner could not create " "iterator: %s", isc_result_totext(result)); - else { + } else { dns_dbiterator_setcleanmode(cleaner->iterator, true); result = dns_dbiterator_first(cleaner->iterator); } @@ -652,8 +671,9 @@ end_cleaning(cache_cleaner_t *cleaner, isc_event_t *event) REQUIRE(event != NULL); result = dns_dbiterator_pause(cleaner->iterator); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_dbiterator_destroy(&cleaner->iterator); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1), "end cache cleaning, mem inuse %lu", @@ -688,10 +708,11 @@ overmem_cleaning_action(isc_task_t *task, isc_event_t *event) LOCK(&cleaner->lock); if (cleaner->overmem) { - if (cleaner->state == cleaner_s_idle) + if (cleaner->state == cleaner_s_idle) { want_cleaning = true; + } } else { - if (cleaner->state == cleaner_s_busy) + if (cleaner->state == cleaner_s_busy) { /* * end_cleaning() can't be called here because * then both cleaner->overmem_event and @@ -701,14 +722,16 @@ overmem_cleaning_action(isc_task_t *task, isc_event_t *event) * is posted, it will handle the end_cleaning. */ cleaner->state = cleaner_s_done; + } } cleaner->overmem_event = event; UNLOCK(&cleaner->lock); - if (want_cleaning) + if (want_cleaning) { begin_cleaning(cleaner); + } } /* @@ -783,13 +806,13 @@ incremental_cleaning_action(isc_task_t *task, isc_event_t *event) * overmem and no error was encountered, * keep trying to clean it, otherwise stop cleaning. */ - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { UNEXPECTED_ERROR(__FILE__, __LINE__, "cache cleaner: " "dns_dbiterator_next() " "failed: %s", dns_result_totext(result)); - else if (cleaner->overmem) { + } else if (cleaner->overmem) { result = dns_dbiterator_first(cleaner->iterator); if (result == ISC_R_SUCCESS) { @@ -842,8 +865,9 @@ dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) REQUIRE(VALID_CACHE(cache)); result = dns_db_createiterator(cache->db, 0, &iterator); - if (result != ISC_R_SUCCESS) - return result; + if (result != ISC_R_SUCCESS) { + return (result); + } result = dns_dbiterator_first(iterator); @@ -851,8 +875,9 @@ dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) dns_dbnode_t *node = NULL; result = dns_dbiterator_current(iterator, &node, (dns_name_t *)NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } /* * Check TTLs, mark expired rdatasets stale. @@ -878,8 +903,9 @@ dns_cache_clean(dns_cache_t *cache, isc_stdtime_t now) dns_dbiterator_destroy(&iterator); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } return (result); } @@ -900,9 +926,10 @@ water(void *arg, int mark) isc_mem_waterack(cache->mctx, mark); } - if (cache->cleaner.overmem_event != NULL) + if (cache->cleaner.overmem_event != NULL) { isc_task_send(cache->cleaner.task, &cache->cleaner.overmem_event); + } UNLOCK(&cache->cleaner.lock); } @@ -918,8 +945,9 @@ dns_cache_setcachesize(dns_cache_t *cache, size_t size) * Impose a minimum cache size; pathological things happen if there * is too little room. */ - if (size != 0U && size < DNS_CACHE_MINSIZE) + if (size != 0U && size < DNS_CACHE_MINSIZE) { size = DNS_CACHE_MINSIZE; + } LOCK(&cache->lock); cache->size = size; @@ -935,17 +963,18 @@ dns_cache_setcachesize(dns_cache_t *cache, size_t size) * water(). */ - if (size == 0U || hiwater == 0U || lowater == 0U) + if (size == 0U || hiwater == 0U || lowater == 0U) { /* * Disable cache memory limiting. */ isc_mem_setwater(cache->mctx, water, cache, 0, 0); - else + } else { /* * Establish new cache memory limits (either for the first * time, or replacing other limits). */ isc_mem_setwater(cache->mctx, water, cache, hiwater, lowater); + } } size_t @@ -987,7 +1016,7 @@ dns_cache_getservestalettl(dns_cache_t *cache) * to confirm the value that the db is really using. */ result = dns_db_getservestalettl(cache->db, &ttl); - return result == ISC_R_SUCCESS ? ttl : 0; + return (result == ISC_R_SUCCESS ? ttl : 0); } /* @@ -1025,8 +1054,9 @@ dns_cache_flush(dns_cache_t *cache) isc_result_t result; result = cache_create_db(cache, &db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_createiterator(db, false, &dbiterator); if (result != ISC_R_SUCCESS) { @@ -1041,8 +1071,9 @@ dns_cache_flush(dns_cache_t *cache) cache->cleaner.iterator = dbiterator; dbiterator = NULL; } else { - if (cache->cleaner.state == cleaner_s_busy) + if (cache->cleaner.state == cleaner_s_busy) { cache->cleaner.state = cleaner_s_done; + } cache->cleaner.replaceiterator = true; } olddb = cache->db; @@ -1051,10 +1082,12 @@ dns_cache_flush(dns_cache_t *cache) UNLOCK(&cache->cleaner.lock); UNLOCK(&cache->lock); - if (dbiterator != NULL) + if (dbiterator != NULL) { dns_dbiterator_destroy(&dbiterator); - if (olddbiterator != NULL) + } + if (olddbiterator != NULL) { dns_dbiterator_destroy(&olddbiterator); + } dns_db_detach(&olddb); return (ISC_R_SUCCESS); @@ -1067,8 +1100,9 @@ clearnode(dns_db_t *db, dns_dbnode_t *node) dns_rdatasetiter_t *iter = NULL; result = dns_db_allrdatasets(db, node, NULL, (isc_stdtime_t)0, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(iter)) { @@ -1079,12 +1113,14 @@ clearnode(dns_db_t *db, dns_dbnode_t *node) result = dns_db_deleterdataset(db, node, NULL, rdataset.type, rdataset.covers); dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) + if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) { break; + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } dns_rdatasetiter_destroy(&iter); return (result); @@ -1108,48 +1144,60 @@ cleartree(dns_db_t *db, const dns_name_t *name) nodename = dns_fixedname_initname(&fnodename); result = dns_db_createiterator(db, 0, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_dbiterator_seek(iter, name); - if (result == DNS_R_PARTIALMATCH) + if (result == DNS_R_PARTIALMATCH) { result = dns_dbiterator_next(iter); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto cleanup; + } while (result == ISC_R_SUCCESS) { result = dns_dbiterator_current(iter, &node, nodename); - if (result == DNS_R_NEWORIGIN) + if (result == DNS_R_NEWORIGIN) { result = ISC_R_SUCCESS; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Are we done? */ - if (!dns_name_issubdomain(nodename, name)) + if (!dns_name_issubdomain(nodename, name)) { goto cleanup; + } /* * If clearnode fails record and move onto the next node. */ result = clearnode(db, node); - if (result != ISC_R_SUCCESS && answer == ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS && answer == ISC_R_SUCCESS) { answer = result; + } dns_db_detachnode(db, &node); result = dns_dbiterator_next(iter); } cleanup: - if (result == ISC_R_NOMORE || result == ISC_R_NOTFOUND) + if (result == ISC_R_NOMORE || result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; - if (result != ISC_R_SUCCESS && answer == ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS && answer == ISC_R_SUCCESS) { answer = result; - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); - if (iter != NULL) + } + if (iter != NULL) { dns_dbiterator_destroy(&iter); - if (top != NULL) + } + if (top != NULL) { dns_db_detachnode(db, &top); + } return (answer); } @@ -1167,15 +1215,18 @@ dns_cache_flushnode(dns_cache_t *cache, const dns_name_t *name, bool tree) dns_dbnode_t *node = NULL; dns_db_t * db = NULL; - if (tree && dns_name_equal(name, dns_rootname)) + if (tree && dns_name_equal(name, dns_rootname)) { return (dns_cache_flush(cache)); + } LOCK(&cache->lock); - if (cache->db != NULL) + if (cache->db != NULL) { dns_db_attach(cache->db, &db); + } UNLOCK(&cache->lock); - if (db == NULL) + if (db == NULL) { return (ISC_R_SUCCESS); + } if (tree) { result = cleartree(cache->db, name); @@ -1185,8 +1236,9 @@ dns_cache_flushnode(dns_cache_t *cache, const dns_name_t *name, bool tree) result = ISC_R_SUCCESS; goto cleanup_db; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_db; + } result = clearnode(cache->db, node); dns_db_detachnode(cache->db, &node); } @@ -1207,8 +1259,9 @@ void dns_cache_updatestats(dns_cache_t *cache, isc_result_t result) { REQUIRE(VALID_CACHE(cache)); - if (cache->stats == NULL) + if (cache->stats == NULL) { return; + } switch (result) { case ISC_R_SUCCESS: @@ -1375,7 +1428,7 @@ dns_cache_renderxml(dns_cache_t *cache, void *writer0) error: return (xmlrc); } -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C #define CHECKMEM(m) \ @@ -1460,4 +1513,4 @@ dns_cache_renderjson(dns_cache_t *cache, void *cstats0) error: return (result); } -#endif +#endif /* ifdef HAVE_JSON_C */ diff --git a/lib/dns/catz.c b/lib/dns/catz.c index f17c02f99a..886581c55d 100644 --- a/lib/dns/catz.c +++ b/lib/dns/catz.c @@ -127,16 +127,19 @@ dns_catz_options_free(dns_catz_options_t *options, isc_mem_t *mctx) REQUIRE(options != NULL); REQUIRE(mctx != NULL); - if (options->masters.count != 0) + if (options->masters.count != 0) { dns_ipkeylist_clear(mctx, &options->masters); + } if (options->zonedir != NULL) { isc_mem_free(mctx, options->zonedir); options->zonedir = NULL; } - if (options->allow_query != NULL) + if (options->allow_query != NULL) { isc_buffer_free(&options->allow_query); - if (options->allow_transfer != NULL) + } + if (options->allow_transfer != NULL) { isc_buffer_free(&options->allow_transfer); + } } isc_result_t @@ -150,22 +153,26 @@ dns_catz_options_copy(isc_mem_t *mctx, const dns_catz_options_t *src, REQUIRE(dst->allow_query == NULL); REQUIRE(dst->allow_transfer == NULL); - if (src->masters.count != 0) + if (src->masters.count != 0) { dns_ipkeylist_copy(mctx, &src->masters, &dst->masters); + } if (dst->zonedir != NULL) { isc_mem_free(mctx, dst->zonedir); dst->zonedir = NULL; } - if (src->zonedir != NULL) + if (src->zonedir != NULL) { dst->zonedir = isc_mem_strdup(mctx, src->zonedir); + } - if (src->allow_query != NULL) + if (src->allow_query != NULL) { isc_buffer_dup(mctx, &dst->allow_query, src->allow_query); + } - if (src->allow_transfer != NULL) + if (src->allow_transfer != NULL) { isc_buffer_dup(mctx, &dst->allow_transfer, src->allow_transfer); + } return (ISC_R_SUCCESS); } @@ -178,17 +185,21 @@ dns_catz_options_setdefault(isc_mem_t *mctx, const dns_catz_options_t *defaults, REQUIRE(defaults != NULL); REQUIRE(opts != NULL); - if (opts->masters.count == 0 && defaults->masters.count != 0) + if (opts->masters.count == 0 && defaults->masters.count != 0) { dns_ipkeylist_copy(mctx, &defaults->masters, &opts->masters); + } - if (defaults->zonedir != NULL) + if (defaults->zonedir != NULL) { opts->zonedir = isc_mem_strdup(mctx, defaults->zonedir); + } - if (opts->allow_query == NULL && defaults->allow_query != NULL) + if (opts->allow_query == NULL && defaults->allow_query != NULL) { isc_buffer_dup(mctx, &opts->allow_query, defaults->allow_query); - if (opts->allow_transfer == NULL && defaults->allow_transfer != NULL) + } + if (opts->allow_transfer == NULL && defaults->allow_transfer != NULL) { isc_buffer_dup(mctx, &opts->allow_transfer, defaults->allow_transfer); + } /* This option is always taken from config, so it's always 'default' */ opts->in_memory = defaults->in_memory; @@ -237,13 +248,15 @@ dns_catz_entry_copy(dns_catz_zone_t *zone, const dns_catz_entry_t *entry, REQUIRE(nentryp != NULL && *nentryp == NULL); result = dns_catz_entry_new(zone->catzs->mctx, &entry->name, &nentry); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_catz_options_copy(zone->catzs->mctx, &entry->opts, &nentry->opts); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_catz_entry_detach(zone, &nentry); + } *nentryp = nentry; return (result); @@ -275,8 +288,9 @@ dns_catz_entry_detach(dns_catz_zone_t *zone, dns_catz_entry_t **entryp) entry->magic = 0; isc_refcount_destroy(&entry->refs); dns_catz_options_free(&entry->opts, mctx); - if (dns_name_dynamic(&entry->name)) + if (dns_name_dynamic(&entry->name)) { dns_name_free(&entry->name, mctx); + } isc_mem_put(mctx, entry, sizeof(dns_catz_entry_t)); } } @@ -298,38 +312,45 @@ dns_catz_entry_cmp(const dns_catz_entry_t *ea, const dns_catz_entry_t *eb) REQUIRE(DNS_CATZ_ENTRY_VALID(ea)); REQUIRE(DNS_CATZ_ENTRY_VALID(eb)); - if (ea == eb) + if (ea == eb) { return (true); + } - if (ea->opts.masters.count != eb->opts.masters.count) + if (ea->opts.masters.count != eb->opts.masters.count) { return (false); + } if (memcmp(ea->opts.masters.addrs, eb->opts.masters.addrs, - ea->opts.masters.count * sizeof(isc_sockaddr_t))) + ea->opts.masters.count * sizeof(isc_sockaddr_t))) { return (false); + } /* If one is NULL and the other isn't, the entries don't match */ - if ((ea->opts.allow_query == NULL) != (eb->opts.allow_query == NULL)) + if ((ea->opts.allow_query == NULL) != (eb->opts.allow_query == NULL)) { return (false); + } /* If one is non-NULL, then they both are */ if (ea->opts.allow_query != NULL) { isc_buffer_usedregion(ea->opts.allow_query, &ra); isc_buffer_usedregion(eb->opts.allow_query, &rb); - if (isc_region_compare(&ra, &rb)) + if (isc_region_compare(&ra, &rb)) { return (false); + } } /* Repeat the above checks with allow_transfer */ if ((ea->opts.allow_transfer == NULL) != - (eb->opts.allow_transfer == NULL)) + (eb->opts.allow_transfer == NULL)) { return (false); + } if (ea->opts.allow_transfer != NULL) { isc_buffer_usedregion(ea->opts.allow_transfer, &ra); isc_buffer_usedregion(eb->opts.allow_transfer, &rb); - if (isc_region_compare(&ra, &rb)) + if (isc_region_compare(&ra, &rb)) { return (false); + } } /* xxxwpk TODO compare dscps/keys! */ @@ -393,32 +414,38 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) dns_name_format(&target->name, czname, DNS_NAME_FORMATSIZE); result = isc_ht_init(&toadd, target->catzs->mctx, 16); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_ht_init(&tomod, target->catzs->mctx, 16); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_ht_iter_create(newzone->entries, &iter1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_ht_iter_create(target->entries, &iter2); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * We can create those iterators now, even though toadd and tomod are * empty */ result = isc_ht_iter_create(toadd, &iteradd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_ht_iter_create(tomod, &itermod); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * First - walk the new zone and find all nodes that are not in the @@ -462,7 +489,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) if (result != ISC_R_SUCCESS) { result = isc_ht_add(toadd, key, (uint32_t)keysize, nentry); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, @@ -470,13 +497,14 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) "from catalog '%s' - %s", zname, czname, isc_result_totext(result)); + } continue; } if (dns_catz_entry_cmp(oentry, nentry) != true) { result = isc_ht_add(tomod, key, (uint32_t)keysize, nentry); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, @@ -484,6 +512,7 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) "from catalog '%s' - %s", zname, czname, isc_result_totext(result)); + } } dns_catz_entry_detach(target, &oentry); result = isc_ht_delete(target->entries, key, (uint32_t)keysize); @@ -554,18 +583,24 @@ dns_catz_zones_merge(dns_catz_zone_t *target, dns_catz_zone_t *newzone) result = ISC_R_SUCCESS; cleanup: - if (iter1 != NULL) + if (iter1 != NULL) { isc_ht_iter_destroy(&iter1); - if (iter2 != NULL) + } + if (iter2 != NULL) { isc_ht_iter_destroy(&iter2); - if (iteradd != NULL) + } + if (iteradd != NULL) { isc_ht_iter_destroy(&iteradd); - if (itermod != NULL) + } + if (itermod != NULL) { isc_ht_iter_destroy(&itermod); - if (toadd != NULL) + } + if (toadd != NULL) { isc_ht_destroy(&toadd); - if (tomod != NULL) + } + if (tomod != NULL) { isc_ht_destroy(&tomod); + } return (result); } @@ -588,8 +623,9 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm, isc_refcount_init(&new_zones->refs, 1); result = isc_ht_init(&new_zones->zones, mctx, 4); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_refcount; + } isc_mem_attach(mctx, &new_zones->mctx); new_zones->zmm = zmm; @@ -597,8 +633,9 @@ dns_catz_new_zones(dns_catz_zones_t **catzsp, dns_catz_zonemodmethods_t *zmm, new_zones->taskmgr = taskmgr; result = isc_task_create(taskmgr, 0, &new_zones->updater); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_ht; + } new_zones->magic = DNS_CATZ_ZONES_MAGIC; *catzsp = new_zones; @@ -644,16 +681,18 @@ dns_catz_new_zone(dns_catz_zones_t *catzs, dns_catz_zone_t **zonep, dns_name_dup(name, catzs->mctx, &new_zone->name); result = isc_ht_init(&new_zone->entries, catzs->mctx, 4); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_name; + } new_zone->updatetimer = NULL; result = isc_timer_create(catzs->timermgr, isc_timertype_inactive, NULL, NULL, catzs->updater, dns_catz_update_taskaction, new_zone, &new_zone->updatetimer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_ht; + } isc_time_settoepoch(&new_zone->lastupdated); new_zone->updatepending = false; @@ -700,15 +739,17 @@ dns_catz_add_zone(dns_catz_zones_t *catzs, const dns_name_t *name, LOCK(&catzs->lock); result = dns_catz_new_zone(catzs, &new_zone, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_ht_add(catzs->zones, new_zone->name.ndata, new_zone->name.length, new_zone); if (result != ISC_R_SUCCESS) { dns_catz_zone_detach(&new_zone); - if (result != ISC_R_EXISTS) + if (result != ISC_R_EXISTS) { goto cleanup; + } } if (result == ISC_R_EXISTS) { @@ -737,8 +778,9 @@ dns_catz_get_zone(dns_catz_zones_t *catzs, const dns_name_t *name) result = isc_ht_find(catzs->zones, name->ndata, name->length, (void **)&found); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (NULL); + } return (found); } @@ -799,10 +841,12 @@ dns_catz_zone_detach(dns_catz_zone_t **zonep) zone->db, dns_catz_dbupdate_callback, zone->catzs) == ISC_R_SUCCESS); } - if (zone->dbversion) + if (zone->dbversion) { dns_db_closeversion(zone->db, &zone->dbversion, false); - if (zone->db != NULL) + } + if (zone->db != NULL) { dns_db_detach(&zone->db); + } dns_name_free(&zone->name, mctx); dns_catz_options_free(&zone->defoptions, mctx); @@ -863,27 +907,29 @@ catz_opt_cmp(const dns_label_t *option, const char *opt) { unsigned int l = strlen(opt); if (option->length - 1 == l && - memcmp(opt, option->base + 1, l - 1) == 0) + memcmp(opt, option->base + 1, l - 1) == 0) { return (true); - else + } else { return (false); + } } static catz_opt_t catz_get_option(const dns_label_t *option) { - if (catz_opt_cmp(option, "zones")) + if (catz_opt_cmp(option, "zones")) { return (CATZ_OPT_ZONES); - else if (catz_opt_cmp(option, "masters")) + } else if (catz_opt_cmp(option, "masters")) { return (CATZ_OPT_MASTERS); - else if (catz_opt_cmp(option, "allow-query")) + } else if (catz_opt_cmp(option, "allow-query")) { return (CATZ_OPT_ALLOW_QUERY); - else if (catz_opt_cmp(option, "allow-transfer")) + } else if (catz_opt_cmp(option, "allow-transfer")) { return (CATZ_OPT_ALLOW_TRANSFER); - else if (catz_opt_cmp(option, "version")) + } else if (catz_opt_cmp(option, "version")) { return (CATZ_OPT_VERSION); - else + } else { return (CATZ_OPT_NONE); + } } static isc_result_t @@ -897,17 +943,19 @@ catz_process_zones(dns_catz_zone_t *zone, dns_rdataset_t *value, REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC)); - if (value->rdclass != dns_rdataclass_in) + if (value->rdclass != dns_rdataclass_in) { return (ISC_R_FAILURE); + } - if (name->labels == 0) + if (name->labels == 0) { return (ISC_R_FAILURE); + } dns_name_getlabel(name, name->labels - 1, &mhash); - if (name->labels == 1) + if (name->labels == 1) { return (catz_process_zones_entry(zone, value, &mhash)); - else { + } else { dns_name_init(&opt, NULL); dns_name_split(name, 1, &opt, NULL); return (catz_process_zones_suboption(zone, value, &mhash, @@ -928,12 +976,14 @@ catz_process_zones_entry(dns_catz_zone_t *zone, dns_rdataset_t *value, * We only take -first- value, as mhash must be * different. */ - if (value->type != dns_rdatatype_ptr) + if (value->type != dns_rdatatype_ptr) { return (ISC_R_FAILURE); + } result = dns_rdataset_first(value); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } dns_rdata_init(&rdata); dns_rdataset_current(value, &rdata); @@ -987,12 +1037,14 @@ catz_process_version(dns_catz_zone_t *zone, dns_rdataset_t *value) REQUIRE(DNS_RDATASET_VALID(value)); if (value->rdclass != dns_rdataclass_in || - value->type != dns_rdatatype_txt) + value->type != dns_rdatatype_txt) { return (ISC_R_FAILURE); + } result = dns_rdataset_first(value); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdata_init(&rdata); dns_rdataset_current(value, &rdata); @@ -1001,12 +1053,14 @@ catz_process_version(dns_catz_zone_t *zone, dns_rdataset_t *value) RUNTIME_CHECK(result == ISC_R_SUCCESS); result = dns_rdata_txt_first(&rdatatxt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_rdata_txt_current(&rdatatxt, &rdatastr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_rdata_txt_next(&rdatatxt); if (result != ISC_R_NOMORE) { @@ -1066,8 +1120,9 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl, * - label and IN A/IN AAAA * - label and IN TXT - TSIG key name */ - if (value->rdclass != dns_rdataclass_in) + if (value->rdclass != dns_rdataclass_in) { return (ISC_R_FAILURE); + } if (name->labels > 0) { isc_sockaddr_t sockaddr; @@ -1097,16 +1152,19 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl, RUNTIME_CHECK(result == ISC_R_SUCCESS); result = dns_rdata_txt_first(&rdata_txt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_rdata_txt_current(&rdata_txt, &rdatastr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_rdata_txt_next(&rdata_txt); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (ISC_R_FAILURE); + } /* rdatastr.length < DNS_NAME_MAXTEXT */ keyname = isc_mem_get(mctx, sizeof(dns_name_t)); @@ -1132,16 +1190,18 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl, */ for (i = 0; i < ipkl->count; i++) { if (ipkl->labels[i] != NULL && - !dns_name_compare(name, ipkl->labels[i])) + !dns_name_compare(name, ipkl->labels[i])) { break; + } } if (i < ipkl->count) { /* we have this record already */ - if (value->type == dns_rdatatype_txt) + if (value->type == dns_rdatatype_txt) { ipkl->keys[i] = keyname; - else /* A/AAAA */ + } else { /* A/AAAA */ memmove(&ipkl->addrs[i], &sockaddr, sizeof(isc_sockaddr_t)); + } } else { result = dns_ipkeylist_resize(mctx, ipkl, i + 1); if (result != ISC_R_SUCCESS) { @@ -1152,19 +1212,22 @@ catz_process_masters(dns_catz_zone_t *zone, dns_ipkeylist_t *ipkl, dns_name_init(ipkl->labels[i], NULL); dns_name_dup(name, mctx, ipkl->labels[i]); - if (value->type == dns_rdatatype_txt) + if (value->type == dns_rdatatype_txt) { ipkl->keys[i] = keyname; - else /* A/AAAA */ + } else { /* A/AAAA */ memmove(&ipkl->addrs[i], &sockaddr, sizeof(isc_sockaddr_t)); + } ipkl->count++; } return (ISC_R_SUCCESS); } /* else - 'simple' case - without labels */ - if (value->type != dns_rdatatype_a && value->type != dns_rdatatype_aaaa) + if (value->type != dns_rdatatype_a && + value->type != dns_rdatatype_aaaa) { return (ISC_R_FAILURE); + } rcount = dns_rdataset_count(value) + ipkl->count; @@ -1218,8 +1281,9 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp, REQUIRE(dns_rdataset_isassociated(value)); if (value->rdclass != dns_rdataclass_in || - value->type != dns_rdatatype_apl) + value->type != dns_rdatatype_apl) { return (ISC_R_FAILURE); + } if (dns_rdataset_count(value) > 1) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, @@ -1232,8 +1296,9 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp, dns_rdata_init(&rdata); dns_rdataset_current(value, &rdata); result = dns_rdata_tostruct(&rdata, &rdata_apl, zone->catzs->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_allocate(zone->catzs->mctx, &aclb, 16); isc_buffer_setautorealloc(aclb, true); for (result = dns_rdata_apl_first(&rdata_apl); result == ISC_R_SUCCESS; @@ -1241,16 +1306,19 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp, result = dns_rdata_apl_current(&rdata_apl, &apl_ent); RUNTIME_CHECK(result == ISC_R_SUCCESS); memset(buf, 0, sizeof(buf)); - if (apl_ent.data != NULL && apl_ent.length > 0) + if (apl_ent.data != NULL && apl_ent.length > 0) { memmove(buf, apl_ent.data, apl_ent.length); - if (apl_ent.family == 1) + } + if (apl_ent.family == 1) { isc_netaddr_fromin(&addr, (struct in_addr *)buf); - else if (apl_ent.family == 2) + } else if (apl_ent.family == 2) { isc_netaddr_fromin6(&addr, (struct in6_addr *)buf); - else + } else { continue; /* xxxwpk log it or simply ignore? */ - if (apl_ent.negative) + } + if (apl_ent.negative) { isc_buffer_putuint8(aclb, '!'); + } isc_buffer_reserve(&aclb, INET6_ADDRSTRLEN); result = isc_netaddr_totext(&addr, aclb); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -1261,15 +1329,17 @@ catz_process_apl(dns_catz_zone_t *zone, isc_buffer_t **aclbp, } isc_buffer_putstr(aclb, "; "); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; - else + } else { goto cleanup; + } *aclbp = aclb; aclb = NULL; cleanup: - if (aclb != NULL) + if (aclb != NULL) { isc_buffer_free(&aclb); + } dns_rdata_freestruct(&rdata_apl); return (result); } @@ -1289,8 +1359,9 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value, REQUIRE(DNS_RDATASET_VALID(value)); REQUIRE(ISC_MAGIC_VALID(name, DNS_NAME_MAGIC)); - if (name->labels == 0) + if (name->labels == 0) { return (ISC_R_FAILURE); + } dns_name_getlabel(name, name->labels - 1, &option); opt = catz_get_option(&option); @@ -1302,8 +1373,9 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value, (void **)&entry); if (result != ISC_R_SUCCESS) { result = dns_catz_entry_new(zone->catzs->mctx, NULL, &entry); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = isc_ht_add(zone->entries, mhash->base, mhash->length, entry); if (result != ISC_R_SUCCESS) { @@ -1319,13 +1391,15 @@ catz_process_zones_suboption(dns_catz_zone_t *zone, dns_rdataset_t *value, return (catz_process_masters(zone, &entry->opts.masters, value, &prefix)); case CATZ_OPT_ALLOW_QUERY: - if (prefix.labels != 0) + if (prefix.labels != 0) { return (ISC_R_FAILURE); + } return (catz_process_apl(zone, &entry->opts.allow_query, value)); case CATZ_OPT_ALLOW_TRANSFER: - if (prefix.labels != 0) + if (prefix.labels != 0) { return (ISC_R_FAILURE); + } return (catz_process_apl(zone, &entry->opts.allow_transfer, value)); default: @@ -1358,18 +1432,21 @@ catz_process_value(dns_catz_zone_t *zone, dns_name_t *name, return (catz_process_masters(zone, &zone->zoneoptions.masters, rdataset, &prefix)); case CATZ_OPT_ALLOW_QUERY: - if (prefix.labels != 0) + if (prefix.labels != 0) { return (ISC_R_FAILURE); + } return (catz_process_apl(zone, &zone->zoneoptions.allow_query, rdataset)); case CATZ_OPT_ALLOW_TRANSFER: - if (prefix.labels != 0) + if (prefix.labels != 0) { return (ISC_R_FAILURE); + } return (catz_process_apl( zone, &zone->zoneoptions.allow_transfer, rdataset)); case CATZ_OPT_VERSION: - if (prefix.labels != 0) + if (prefix.labels != 0) { return (ISC_R_FAILURE); + } return (catz_process_version(zone, rdataset)); default: return (ISC_R_FAILURE); @@ -1396,8 +1473,9 @@ dns_catz_update_process(dns_catz_zones_t *catzs, dns_catz_zone_t *zone, if (nrres == dns_namereln_equal) { if (rdataset->type == dns_rdatatype_soa) { result = dns_rdataset_first(rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_current(rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &soa, NULL); @@ -1407,7 +1485,6 @@ dns_catz_update_process(dns_catz_zones_t *catzs, dns_catz_zone_t *zone, * xxxwpk TODO do we want to save something from SOA? */ return (result); - } else if (rdataset->type == dns_rdatatype_ns) { return (ISC_R_SUCCESS); } else { @@ -1691,13 +1768,15 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg) LOCK(&catzs->lock); result = isc_ht_find(catzs->zones, r.base, r.length, (void **)&zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* New zone came as AXFR */ if (zone->db != NULL && zone->db != db) { - if (zone->dbversion != NULL) + if (zone->dbversion != NULL) { dns_db_closeversion(zone->db, &zone->dbversion, false); + } dns_db_detach(&zone->db); /* * We're not registering db update callback, it will be @@ -1705,8 +1784,9 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg) */ zone->db_registered = false; } - if (zone->db == NULL) + if (zone->db == NULL) { dns_db_attach(db, &zone->db); + } if (zone->updatepending == false) { zone->updatepending = true; @@ -1726,8 +1806,9 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg) result = isc_timer_reset(zone->updatetimer, isc_timertype_once, NULL, &interval, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } else { isc_event_t *event; @@ -1744,8 +1825,9 @@ dns_catz_dbupdate_callback(dns_db_t *db, void *fn_arg) isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, ISC_LOG_DEBUG(3), "catz: update already queued"); - if (zone->dbversion != NULL) + if (zone->dbversion != NULL) { dns_db_closeversion(zone->db, &zone->dbversion, false); + } dns_db_currentversion(zone->db, &zone->dbversion); } @@ -1933,8 +2015,9 @@ dns_catz_update_from_db(dns_db_t *db, dns_catz_zones_t *catzs) if (oldzone->db_registered == false) { result = dns_db_updatenotify_register( db, dns_catz_dbupdate_callback, oldzone->catzs); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { oldzone->db_registered = true; + } } } diff --git a/lib/dns/client.c b/lib/dns/client.c index fc9ad96a12..a6f2d39ac8 100644 --- a/lib/dns/client.c +++ b/lib/dns/client.c @@ -66,7 +66,7 @@ #ifdef TUNE_LARGE #define RESOLVER_NTASKS 523 -#else +#else /* ifdef TUNE_LARGE */ #define RESOLVER_NTASKS 31 #endif /* TUNE_LARGE */ @@ -352,8 +352,9 @@ getudpdispatch(int family, dns_dispatchmgr_t *dispatchmgr, buffersize, maxbuffers, maxrequests, buckets, increment, attrs, attrmask, &disp); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *dispp = disp; + } return (result); } @@ -370,8 +371,9 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, unsigned int options, const char * dbtype; result = dns_view_create(mctx, rdclass, DNS_CLIENTVIEW_NAME, &view); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* Initialize view security roots */ result = dns_view_initsecroots(view, mctx); @@ -393,10 +395,11 @@ createview(isc_mem_t *mctx, dns_rdataclass_t rdclass, unsigned int options, * XXX: it may be better if specific DB implementations can be * specified via some configuration knob. */ - if ((options & DNS_CLIENTCREATEOPT_USECACHE) != 0) + if ((options & DNS_CLIENTCREATEOPT_USECACHE) != 0) { dbtype = "rbt"; - else + } else { dbtype = "ecdb"; + } result = dns_db_create(mctx, dbtype, dns_rootname, dns_dbtype_cache, rdclass, 0, NULL, &view->cachedb); if (result != ISC_R_SUCCESS) { @@ -422,40 +425,48 @@ dns_client_create(dns_client_t **clientp, unsigned int options) isc_log_t *lctx = NULL; isc_logconfig_t *logconfig = NULL; unsigned int logdebuglevel = 0; -#endif +#endif /* if 0 */ isc_mem_create(&mctx); result = isc_appctx_create(mctx, &actx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_app_ctxstart(actx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_socketmgr_createinctx(mctx, &socketmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_timermgr_createinctx(mctx, &timermgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } #if 0 result = isc_log_create(mctx, &lctx, &logconfig); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_log_setcontext(lctx); dns_log_init(lctx); dns_log_setcontext(lctx); result = isc_log_usechannel(logconfig, "default_debug", NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_log_setdebuglevel(lctx, logdebuglevel); -#endif +#endif /* if 0 */ result = dns_client_createx(mctx, actx, taskmgr, socketmgr, timermgr, options, clientp, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } (*clientp)->attributes |= DNS_CLIENTATTR_OWNCTX; @@ -465,14 +476,18 @@ dns_client_create(dns_client_t **clientp, unsigned int options) return (ISC_R_SUCCESS); cleanup: - 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); + } isc_mem_detach(&mctx); return (result); @@ -514,8 +529,9 @@ dns_client_createx(isc_mem_t *mctx, isc_appctx_t *actx, isc_taskmgr_t *taskmgr, } result = dns_dispatchmgr_create(mctx, &dispatchmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_task; + } client->dispatchmgr = dispatchmgr; (void)setsourceports(mctx, dispatchmgr); @@ -614,10 +630,12 @@ destroyclient(dns_client_t *client) dns_view_detach(&view); } - if (client->dispatchv4 != NULL) + if (client->dispatchv4 != NULL) { dns_dispatch_detach(&client->dispatchv4); - if (client->dispatchv6 != NULL) + } + if (client->dispatchv6 != NULL) { dns_dispatch_detach(&client->dispatchv6); + } dns_dispatchmgr_destroy(&client->dispatchmgr); @@ -667,8 +685,9 @@ dns_client_setservers(dns_client_t *client, dns_rdataclass_t rdclass, REQUIRE(DNS_CLIENT_VALID(client)); REQUIRE(addrs != NULL); - if (name_space == NULL) + if (name_space == NULL) { name_space = dns_rootname; + } LOCK(&client->lock); result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME, @@ -696,8 +715,9 @@ dns_client_clearservers(dns_client_t *client, dns_rdataclass_t rdclass, REQUIRE(DNS_CLIENT_VALID(client)); - if (name_space == NULL) + if (name_space == NULL) { name_space = dns_rootname; + } LOCK(&client->lock); result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME, @@ -742,8 +762,9 @@ putrdataset(isc_mem_t *mctx, dns_rdataset_t **rdatasetp) *rdatasetp = NULL; REQUIRE(rdataset != NULL); - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } isc_mem_put(mctx, rdataset, sizeof(*rdataset)); } @@ -774,12 +795,15 @@ start_fetch(resctx_t *rctx) REQUIRE(rctx->fetch == NULL); - if (!rctx->want_cdflag) + if (!rctx->want_cdflag) { fopts |= DNS_FETCHOPT_NOCDFLAG; - if (!rctx->want_validation) + } + if (!rctx->want_validation) { fopts |= DNS_FETCHOPT_NOVALIDATE; - if (rctx->want_tcp) + } + if (rctx->want_tcp) { fopts |= DNS_FETCHOPT_TCP; + } result = dns_resolver_createfetch( rctx->view->resolver, dns_fixedname_name(&rctx->name), @@ -798,10 +822,11 @@ view_find(resctx_t *rctx, dns_db_t **dbp, dns_dbnode_t **nodep, dns_name_t * name = dns_fixedname_name(&rctx->name); dns_rdatatype_t type; - if (rctx->type == dns_rdatatype_rrsig) + if (rctx->type == dns_rdatatype_rrsig) { type = dns_rdatatype_any; - else + } else { type = rctx->type; + } result = dns_view_find(rctx->view, name, type, 0, 0, false, false, dbp, nodep, foundname, rctx->rdataset, @@ -860,14 +885,16 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) INSIST(db != NULL); dns_db_detachnode(db, &node); } - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } result = start_fetch(rctx); if (result != ISC_R_SUCCESS) { putrdataset(mctx, &rctx->rdataset); - if (rctx->sigrdataset != NULL) + if (rctx->sigrdataset != NULL) { putrdataset(mctx, &rctx->sigrdataset); + } send_event = true; } goto done; @@ -888,9 +915,9 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) /* * If we've been canceled, forget about the result. */ - if (rctx->canceled) + if (rctx->canceled) { result = ISC_R_CANCELED; - else { + } else { /* * Otherwise, get some resource for copying the * result. @@ -930,13 +957,15 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) * query name and start over. */ tresult = dns_rdataset_first(trdataset); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { goto done; + } dns_rdataset_current(trdataset, &rdata); tresult = dns_rdata_tostruct(&rdata, &cname, NULL); dns_rdata_reset(&rdata); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { goto done; + } dns_name_copynf(&cname.cname, name); dns_rdata_freestruct(&cname); want_restart = true; @@ -982,10 +1011,11 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) tresult = dns_name_concatenate(prefix, &dname.dname, name, NULL); dns_rdata_freestruct(&dname); - if (tresult == ISC_R_SUCCESS) + if (tresult == ISC_R_SUCCESS) { want_restart = true; - else + } else { result = tresult; + } goto done; case DNS_R_NCACHENXDOMAIN: case DNS_R_NCACHENXRRSET: @@ -994,15 +1024,18 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) ansname = NULL; rctx->rdataset = NULL; /* What about sigrdataset? */ - if (rctx->sigrdataset != NULL) + if (rctx->sigrdataset != NULL) { putrdataset(mctx, &rctx->sigrdataset); + } send_event = true; goto done; default: - if (rctx->rdataset != NULL) + if (rctx->rdataset != NULL) { putrdataset(mctx, &rctx->rdataset); - if (rctx->sigrdataset != NULL) + } + if (rctx->sigrdataset != NULL) { putrdataset(mctx, &rctx->sigrdataset); + } send_event = true; goto done; } @@ -1067,10 +1100,11 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) ansname = NULL; } dns_rdatasetiter_destroy(&rdsiter); - if (tresult != ISC_R_NOMORE) + if (tresult != ISC_R_NOMORE) { result = DNS_R_SERVFAIL; /* ditto */ - else + } else { result = ISC_R_SUCCESS; + } goto done; } else { /* @@ -1104,12 +1138,15 @@ client_resfind(resctx_t *rctx, dns_fetchevent_t *event) isc_mem_put(mctx, ansname, sizeof(*ansname)); } - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); - if (event != NULL) + } + if (event != NULL) { isc_event_free(ISC_EVENT_PTR(&event)); + } /* * Limit the number of restarts. @@ -1204,8 +1241,9 @@ resolve_done(isc_task_t *task, isc_event_t *event) */ result = isc_app_ctxonrun(resarg->actx, resarg->client->mctx, task, suspend, resarg->actx); - if (result == ISC_R_ALREADYRUNNING) + if (result == ISC_R_ALREADYRUNNING) { isc_app_ctxsuspend(resarg->actx); + } } else { /* * We have already exited from the loop (due to some @@ -1237,8 +1275,9 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name, * particular resolution. */ return (ISC_R_NOTIMPLEMENTED); /* XXXTBD */ - } else + } else { actx = client->actx; + } resarg = isc_mem_get(client->mctx, sizeof(*resarg)); @@ -1266,8 +1305,9 @@ dns_client_resolve(dns_client_t *client, const dns_name_t *name, result = isc_app_ctxrun(actx); LOCK(&resarg->lock); - if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) + if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) { result = resarg->result; + } if (result != ISC_R_SUCCESS && resarg->vresult != ISC_R_SUCCESS) { /* * If this lookup failed due to some error in DNSSEC @@ -1320,8 +1360,9 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name, result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME, rdclass, &view); UNLOCK(&client->lock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } mctx = client->mctx; rdataset = NULL; @@ -1346,14 +1387,16 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name, isc_mutex_init(&rctx->lock); result = getrdataset(mctx, &rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } rctx->rdataset = rdataset; if (want_dnssec) { result = getrdataset(mctx, &sigrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } rctx->sigrdataset = sigrdataset; @@ -1388,10 +1431,12 @@ dns_client_startresolve(dns_client_t *client, const dns_name_t *name, return (ISC_R_SUCCESS); cleanup: - if (rdataset != NULL) + if (rdataset != NULL) { putrdataset(client->mctx, &rdataset); - if (sigrdataset != NULL) + } + if (sigrdataset != NULL) { putrdataset(client->mctx, &sigrdataset); + } if (rctx != NULL) { isc_mutex_destroy(&rctx->lock); isc_mem_put(mctx, rctx, sizeof(*rctx)); @@ -1416,8 +1461,9 @@ dns_client_cancelresolve(dns_clientrestrans_t *trans) if (!rctx->canceled) { rctx->canceled = true; - if (rctx->fetch != NULL) + if (rctx->fetch != NULL) { dns_resolver_cancelfetch(rctx->fetch); + } } UNLOCK(&rctx->lock); @@ -1575,13 +1621,15 @@ request_done(isc_task_t *task, isc_event_t *event) ctx->parseoptions); } - if (ctx->tsigkey != NULL) + if (ctx->tsigkey != NULL) { dns_tsigkey_detach(&ctx->tsigkey); + } - if (ctx->canceled) + if (ctx->canceled) { ctx->event->result = ISC_R_CANCELED; - else + } else { ctx->event->result = result; + } task = ctx->event->ev_sender; ctx->event->ev_sender = ctx; isc_task_sendanddetach(&task, ISC_EVENT_PTR(&ctx->event)); @@ -1644,8 +1692,9 @@ dns_client_request(dns_client_t *client, dns_message_t *qmessage, * particular resolution. */ return (ISC_R_NOTIMPLEMENTED); /* XXXTBD */ - } else + } else { actx = client->actx; + } reqarg = isc_mem_get(client->mctx, sizeof(*reqarg)); @@ -1673,8 +1722,9 @@ dns_client_request(dns_client_t *client, dns_message_t *qmessage, result = isc_app_ctxrun(actx); LOCK(&reqarg->lock); - if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) + if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) { result = reqarg->result; + } if (reqarg->trans != NULL) { /* * Unusual termination (perhaps due to signal). We need some @@ -1720,20 +1770,23 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage, if (tsec != NULL) { tsectype = dns_tsec_gettype(tsec); - if (tsectype != dns_tsectype_tsig) + if (tsectype != dns_tsectype_tsig) { return (ISC_R_NOTIMPLEMENTED); /* XXX */ + } } LOCK(&client->lock); result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME, qmessage->rdclass, &view); UNLOCK(&client->lock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } reqoptions = 0; - if ((options & DNS_CLIENTREQOPT_TCP) != 0) + if ((options & DNS_CLIENTREQOPT_TCP) != 0) { reqoptions |= DNS_REQUESTOPT_TCP; + } tclone = NULL; isc_task_attach(task, &tclone); @@ -1751,8 +1804,9 @@ dns_client_startrequest(dns_client_t *client, dns_message_t *qmessage, ctx->event = event; ctx->event->rmessage = rmessage; ctx->tsigkey = NULL; - if (tsec != NULL) + if (tsec != NULL) { dns_tsec_getkey(tsec, &ctx->tsigkey); + } ctx->magic = REQCTX_MAGIC; @@ -1800,8 +1854,9 @@ dns_client_cancelrequest(dns_clientreqtrans_t *trans) if (!ctx->canceled) { ctx->canceled = true; - if (ctx->request != NULL) + if (ctx->request != NULL) { dns_request_cancel(ctx->request); + } } UNLOCK(&ctx->lock); @@ -1882,15 +1937,18 @@ update_sendevent(updatectx_t *uctx, isc_result_t result) isc_task_t *task; dns_message_destroy(&uctx->updatemsg); - if (uctx->tsigkey != NULL) + if (uctx->tsigkey != NULL) { dns_tsigkey_detach(&uctx->tsigkey); - if (uctx->sig0key != NULL) + } + if (uctx->sig0key != NULL) { dst_key_free(&uctx->sig0key); + } - if (uctx->canceled) + if (uctx->canceled) { uctx->event->result = ISC_R_CANCELED; - else + } else { uctx->event->result = result; + } uctx->event->state = uctx->state; task = uctx->event->ev_sender; uctx->event->ev_sender = uctx; @@ -1918,22 +1976,26 @@ update_done(isc_task_t *task, isc_event_t *event) REQUIRE(DNS_CLIENT_VALID(client)); result = reqev->result; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto out; + } result = dns_message_create(client->mctx, DNS_MESSAGE_INTENTPARSE, &answer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto out; + } uctx->state = dns_clientupdatestate_done; result = dns_request_getresponse(request, answer, DNS_MESSAGEPARSE_PRESERVEORDER); - if (result == ISC_R_SUCCESS && answer->rcode != dns_rcode_noerror) + if (result == ISC_R_SUCCESS && answer->rcode != dns_rcode_noerror) { result = rcode2result(answer->rcode); + } out: - if (answer != NULL) + if (answer != NULL) { dns_message_destroy(&answer); + } isc_event_free(&event); LOCK(&uctx->lock); @@ -1957,11 +2019,13 @@ out: dns_message_settsigkey(uctx->updatemsg, NULL); timeout = client->update_timeout / uctx->nservers; - if (timeout < MIN_UPDATE_TIMEOUT) + if (timeout < MIN_UPDATE_TIMEOUT) { timeout = MIN_UPDATE_TIMEOUT; + } reqoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { reqoptions |= DNS_REQUESTOPT_TCP; + } result = dns_request_createvia( uctx->view->requestmgr, uctx->updatemsg, NULL, uctx->currentserver, -1, reqoptions, uctx->tsigkey, @@ -1975,8 +2039,9 @@ out: uctx->state = dns_clientupdatestate_sent; return; } - } else + } else { UNLOCK(&uctx->lock); + } update_sendevent(uctx, result); } @@ -1993,8 +2058,9 @@ send_update(updatectx_t *uctx) REQUIRE(uctx->zonename != NULL && uctx->currentserver != NULL); result = dns_message_gettempname(uctx->updatemsg, &name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_init(name, NULL); dns_name_clone(uctx->zonename, name); result = dns_message_gettemprdataset(uctx->updatemsg, &rdataset); @@ -2008,15 +2074,18 @@ send_update(updatectx_t *uctx) dns_message_addname(uctx->updatemsg, name, DNS_SECTION_ZONE); if (uctx->tsigkey == NULL && uctx->sig0key != NULL) { result = dns_message_setsig0key(uctx->updatemsg, uctx->sig0key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } timeout = client->update_timeout / uctx->nservers; - if (timeout < MIN_UPDATE_TIMEOUT) + if (timeout < MIN_UPDATE_TIMEOUT) { timeout = MIN_UPDATE_TIMEOUT; + } reqoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { reqoptions |= DNS_REQUESTOPT_TCP; + } result = dns_request_createvia( uctx->view->requestmgr, uctx->updatemsg, NULL, uctx->currentserver, -1, reqoptions, uctx->tsigkey, timeout, @@ -2064,17 +2133,20 @@ resolveaddr_done(isc_task_t *task, isc_event_t *event) } result = rev->result; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } for (name = ISC_LIST_HEAD(rev->answerlist); name != NULL; name = ISC_LIST_NEXT(name, link)) { for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { continue; - if (rdataset->type != qtype) + } + if (rdataset->type != qtype) { continue; + } for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -2121,18 +2193,20 @@ done: isc_event_free(&event); LOCK(&uctx->lock); - if (uctx->restrans == NULL && uctx->restrans2 == NULL) + if (uctx->restrans == NULL && uctx->restrans2 == NULL) { completed = true; + } UNLOCK(&uctx->lock); if (completed) { INSIST(uctx->currentserver == NULL); uctx->currentserver = ISC_LIST_HEAD(uctx->servers); - if (uctx->currentserver != NULL && !uctx->canceled) + if (uctx->currentserver != NULL && !uctx->canceled) { send_update(uctx); - else { - if (result == ISC_R_SUCCESS) + } else { + if (result == ISC_R_SUCCESS) { result = ISC_R_NOTFOUND; + } update_sendevent(uctx, result); } } @@ -2149,13 +2223,15 @@ process_soa(updatectx_t *uctx, dns_rdataset_t *soaset, unsigned int resoptions; result = dns_rdataset_first(soaset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdata_init(&soarr); dns_rdataset_current(soaset, &soarr); result = dns_rdata_tostruct(&soarr, &soa, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_init(&primary, NULL); dns_name_clone(&soa.origin, &primary); @@ -2165,9 +2241,9 @@ process_soa(updatectx_t *uctx, dns_rdataset_t *soaset, dns_name_copynf(soaname, uctx->zonename); } - if (uctx->currentserver != NULL) + if (uctx->currentserver != NULL) { result = send_update(uctx); - else { + } else { /* * Get addresses of the primary server. We don't use the ADB * feature so that we could avoid caching data. @@ -2175,8 +2251,9 @@ process_soa(updatectx_t *uctx, dns_rdataset_t *soaset, LOCK(&uctx->lock); uctx->bp4 = uctx; resoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { resoptions |= DNS_CLIENTRESOPT_TCP; + } result = dns_client_startresolve( uctx->client, &primary, uctx->rdclass, dns_rdatatype_a, resoptions, uctx->client->task, resolveaddr_done, @@ -2239,8 +2316,9 @@ receive_soa(isc_task_t *task, isc_event_t *event) result = dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTPARSE, &rcvmsg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto out; + } result = dns_request_getresponse(request, rcvmsg, DNS_MESSAGEPARSE_PRESERVEORDER); @@ -2251,8 +2329,9 @@ receive_soa(isc_task_t *task, isc_event_t *event) dns_message_destroy(&rcvmsg); dns_message_renderreset(uctx->soaquery); reqoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { reqoptions |= DNS_REQUESTOPT_TCP; + } result = dns_request_createvia( uctx->view->requestmgr, uctx->soaquery, NULL, addr, -1, reqoptions, NULL, client->find_timeout * 20, @@ -2279,11 +2358,11 @@ receive_soa(isc_task_t *task, isc_event_t *event) } lookforsoa: - if (pass == 0) + if (pass == 0) { section = DNS_SECTION_ANSWER; - else if (pass == 1) + } else if (pass == 1) { section = DNS_SECTION_AUTHORITY; - else { + } else { droplabel = true; goto out; } @@ -2299,8 +2378,9 @@ lookforsoa: soaset = NULL; result = dns_message_findtype(name, dns_rdatatype_soa, 0, &soaset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } if (section == DNS_SECTION_ANSWER) { dns_rdataset_t *tset = NULL; if (dns_message_findtype(name, dns_rdatatype_cname, 0, @@ -2334,9 +2414,9 @@ out: name = NULL; dns_message_currentname(soaquery, DNS_SECTION_QUESTION, &name); nlabels = dns_name_countlabels(name); - if (nlabels == 1) + if (nlabels == 1) { result = DNS_R_SERVFAIL; /* is there a better error? */ - else { + } else { dns_name_init(&tname, NULL); dns_name_getlabelsequence(name, 1, nlabels - 1, &tname); dns_name_clone(&tname, name); @@ -2347,8 +2427,9 @@ out: dns_message_renderreset(soaquery); dns_message_settsigkey(soaquery, NULL); reqoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { reqoptions |= DNS_REQUESTOPT_TCP; + } result = dns_request_createvia( uctx->view->requestmgr, soaquery, NULL, uctx->currentserver, -1, reqoptions, @@ -2365,11 +2446,13 @@ out: UNLOCK(&uctx->lock); } - if (rcvmsg != NULL) + if (rcvmsg != NULL) { dns_message_destroy(&rcvmsg); + } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { update_sendevent(uctx, result); + } } static isc_result_t @@ -2385,16 +2468,19 @@ request_soa(updatectx_t *uctx) result = dns_message_create(uctx->client->mctx, DNS_MESSAGE_INTENTRENDER, &soaquery); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } soaquery->flags |= DNS_MESSAGEFLAG_RD; result = dns_message_gettempname(soaquery, &name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = dns_message_gettemprdataset(soaquery, &rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_rdataset_makequestion(rdataset, uctx->rdclass, dns_rdatatype_soa); dns_name_clone(uctx->firstname, name); ISC_LIST_APPEND(name->list, rdataset, link); @@ -2402,8 +2488,9 @@ request_soa(updatectx_t *uctx) rdataset = NULL; name = NULL; reqoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { reqoptions |= DNS_REQUESTOPT_TCP; + } result = dns_request_createvia( uctx->view->requestmgr, soaquery, NULL, uctx->currentserver, -1, @@ -2420,8 +2507,9 @@ fail: ISC_LIST_UNLINK(name->list, rdataset, link); /* for safety */ dns_message_puttemprdataset(soaquery, &rdataset); } - if (name != NULL) + if (name != NULL) { dns_message_puttempname(soaquery, &name); + } dns_message_destroy(&soaquery); return (result); @@ -2458,8 +2546,9 @@ resolvesoa_done(isc_task_t *task, isc_event_t *event) for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { if (dns_rdataset_isassociated(rdataset) && - rdataset->type == dns_rdatatype_soa) + rdataset->type == dns_rdatatype_soa) { break; + } } } @@ -2475,22 +2564,25 @@ resolvesoa_done(isc_task_t *task, isc_event_t *event) &tname); dns_name_clone(&tname, &uctx->soaqname); resoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { resoptions |= DNS_CLIENTRESOPT_TCP; + } result = dns_client_startresolve( uctx->client, &uctx->soaqname, uctx->rdclass, dns_rdatatype_soa, resoptions, uctx->client->task, resolvesoa_done, uctx, &uctx->restrans); - } else + } else { result = process_soa(uctx, rdataset, &uctx->soaqname); + } out: dns_client_freeresanswer(uctx->client, &rev->answerlist); isc_event_free(&event); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { update_sendevent(uctx, result); + } } static isc_result_t @@ -2506,8 +2598,9 @@ copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name, dns_rdata_t rdata = DNS_RDATA_INIT, *newrdata; result = dns_message_gettempname(msg, &newname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_allocate(mctx, &namebuf, DNS_NAME_MAXWIRE); dns_name_init(newname, NULL); dns_name_setbuffer(newname, namebuf); @@ -2518,8 +2611,9 @@ copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name, rdataset = ISC_LIST_NEXT(rdataset, link)) { rdatalist = NULL; result = dns_message_gettemprdatalist(msg, &rdatalist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_rdatalist_init(rdatalist); rdatalist->type = rdataset->type; rdatalist->rdclass = rdataset->rdclass; @@ -2533,8 +2627,9 @@ copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name, newrdata = NULL; result = dns_message_gettemprdata(msg, &newrdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_rdata_toregion(&rdata, &r); rdatabuf = NULL; isc_buffer_allocate(mctx, &rdatabuf, r.length); @@ -2553,8 +2648,9 @@ copy_name(isc_mem_t *mctx, dns_message_t *msg, const dns_name_t *name, newrdataset = NULL; result = dns_message_gettemprdataset(msg, &newrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_rdatalist_tordataset(rdatalist, newrdataset); ISC_LIST_APPEND(newname->list, newrdataset, link); @@ -2621,8 +2717,9 @@ dns_client_update(dns_client_t *client, dns_rdataclass_t rdclass, * particular update. */ return (ISC_R_NOTIMPLEMENTED); /* XXXTBD */ - } else + } else { actx = client->actx; + } uarg = isc_mem_get(client->mctx, sizeof(*uarg)); @@ -2651,8 +2748,9 @@ dns_client_update(dns_client_t *client, dns_rdataclass_t rdclass, result = isc_app_ctxrun(actx); LOCK(&uarg->lock); - if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) + if (result == ISC_R_SUCCESS || result == ISC_R_SUSPEND) { result = uarg->result; + } if (uarg->trans != NULL) { /* @@ -2690,30 +2788,35 @@ startupdate(isc_task_t *task, isc_event_t *event) if (uctx->zonename != NULL && uctx->currentserver != NULL) { result = send_update(uctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } else if (uctx->currentserver != NULL) { result = request_soa(uctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } else { resoptions = 0; - if (uctx->want_tcp) + if (uctx->want_tcp) { resoptions |= DNS_CLIENTRESOPT_TCP; + } dns_name_clone(uctx->firstname, &uctx->soaqname); result = dns_client_startresolve( uctx->client, &uctx->soaqname, uctx->rdclass, dns_rdatatype_soa, resoptions, uctx->client->task, resolvesoa_done, uctx, &uctx->restrans); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } isc_event_free(&event); fail: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { update_sendevent(uctx, result); + } } isc_result_t @@ -2744,16 +2847,18 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, if (tsec != NULL) { tsectype = dns_tsec_gettype(tsec); - if (tsectype != dns_tsectype_tsig) + if (tsectype != dns_tsectype_tsig) { return (ISC_R_NOTIMPLEMENTED); /* XXX */ + } } LOCK(&client->lock); result = dns_viewlist_find(&client->viewlist, DNS_CLIENTVIEW_NAME, rdclass, &view); UNLOCK(&client->lock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } want_tcp = ((options & DNS_CLIENTUPDOPT_TCP) != 0); @@ -2791,8 +2896,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, uctx->nservers = 0; uctx->currentserver = NULL; dns_fixedname_init(&uctx->zonefname); - if (tsec != NULL) + if (tsec != NULL) { dns_tsec_getkey(tsec, &uctx->tsigkey); + } uctx->event = (dns_clientupdateevent_t *)isc_event_allocate( client->mctx, tclone, DNS_EVENT_UPDATEDONE, action, arg, sizeof(*uctx->event)); @@ -2808,8 +2914,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, sa->length = server->length; ISC_LINK_INIT(sa, link); ISC_LIST_APPEND(uctx->servers, sa, link); - if (uctx->currentserver == NULL) + if (uctx->currentserver == NULL) { uctx->currentserver = sa; + } uctx->nservers++; } } @@ -2817,8 +2924,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, /* Make update message */ result = dns_message_create(client->mctx, DNS_MESSAGE_INTENTRENDER, &uctx->updatemsg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } uctx->updatemsg->opcode = dns_opcode_update; if (prerequisites != NULL) { @@ -2827,8 +2935,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, newname = NULL; result = copy_name(client->mctx, uctx->updatemsg, name, &newname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_message_addname(uctx->updatemsg, newname, DNS_SECTION_PREREQUISITE); } @@ -2839,8 +2948,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, newname = NULL; result = copy_name(client->mctx, uctx->updatemsg, name, &newname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_message_addname(uctx->updatemsg, newname, DNS_SECTION_UPDATE); } @@ -2851,8 +2961,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, section = DNS_SECTION_PREREQUISITE; result = dns_message_firstname(uctx->updatemsg, section); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } dns_message_currentname(uctx->updatemsg, section, &uctx->firstname); uctx->magic = UCTX_MAGIC; @@ -2873,8 +2984,9 @@ dns_client_startupdate(dns_client_t *client, dns_rdataclass_t rdclass, result = ISC_R_SUCCESS; isc_task_send(task, &event); } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (result); + } isc_refcount_decrement(&client->references); *transp = NULL; @@ -2885,16 +2997,19 @@ fail: ISC_LIST_UNLINK(client->updatectxs, uctx, link); UNLOCK(&client->lock); } - if (uctx->updatemsg != NULL) + if (uctx->updatemsg != NULL) { dns_message_destroy(&uctx->updatemsg); + } while ((sa = ISC_LIST_HEAD(uctx->servers)) != NULL) { ISC_LIST_UNLINK(uctx->servers, sa, link); isc_mem_put(client->mctx, sa, sizeof(*sa)); } - if (uctx->event != NULL) + if (uctx->event != NULL) { isc_event_free(ISC_EVENT_PTR(&uctx->event)); - if (uctx->tsigkey != NULL) + } + if (uctx->tsigkey != NULL) { dns_tsigkey_detach(&uctx->tsigkey); + } isc_task_detach(&tclone); isc_mutex_destroy(&uctx->lock); uctx->magic = 0; @@ -2917,14 +3032,18 @@ dns_client_cancelupdate(dns_clientupdatetrans_t *trans) if (!uctx->canceled) { uctx->canceled = true; - if (uctx->updatereq != NULL) + if (uctx->updatereq != NULL) { dns_request_cancel(uctx->updatereq); - if (uctx->soareq != NULL) + } + if (uctx->soareq != NULL) { dns_request_cancel(uctx->soareq); - if (uctx->restrans != NULL) + } + if (uctx->restrans != NULL) { dns_client_cancelresolve(uctx->restrans); - if (uctx->restrans2 != NULL) + } + if (uctx->restrans2 != NULL) { dns_client_cancelresolve(uctx->restrans2); + } } UNLOCK(&uctx->lock); @@ -3003,8 +3122,9 @@ dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, REQUIRE((rdataset != NULL && rdatalist != NULL && rdata != NULL) || (rdataset == NULL && rdatalist == NULL && rdata == NULL && mctx != NULL)); - if (op == updateop_add) + if (op == updateop_add) { REQUIRE(source != NULL); + } if (source != NULL) { REQUIRE(source->type == type); REQUIRE(op == updateop_add || op == updateop_delete || @@ -3012,8 +3132,9 @@ dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, } size += owner->length; - if (source != NULL) + if (source != NULL) { size += source->length; + } if (rdataset == NULL) { updaterec = isc_mem_get(mctx, size); @@ -3037,8 +3158,9 @@ dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, } updaterec->mctx = NULL; isc_mem_attach(mctx, &updaterec->mctx); - } else if (source != NULL) + } else if (source != NULL) { dns_rdata_clone(source, rdata); + } switch (op) { case updateop_add: @@ -3047,8 +3169,9 @@ dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, if (source != NULL) { ttl = 0; dns_rdata_makedelete(rdata); - } else + } else { dns_rdata_deleterrset(rdata, type); + } break; case updateop_notexist: dns_rdata_notexist(rdata, type); @@ -3078,10 +3201,11 @@ dns_client_updaterec(dns_client_updateop_t op, const dns_name_t *owner, target->attributes |= DNS_NAMEATTR_HASUPDATEREC; dns_name_setbuffer(target, &updaterec->buffer); } - if (op == updateop_add || op == updateop_delete) + if (op == updateop_add || op == updateop_delete) { target->attributes |= DNS_NAMEATTR_UPDATE; - else + } else { target->attributes |= DNS_NAMEATTR_PREREQUISITE; + } return (ISC_R_SUCCESS); } @@ -3107,8 +3231,9 @@ dns_client_freeupdate(dns_name_t **namep) continue; } for (rdata = ISC_LIST_HEAD(rdatalist->rdata); rdata != NULL; - rdata = ISC_LIST_HEAD(rdatalist->rdata)) + rdata = ISC_LIST_HEAD(rdatalist->rdata)) { ISC_LIST_UNLINK(rdatalist->rdata, rdata, link); + } dns_rdataset_disassociate(rdataset); } diff --git a/lib/dns/compress.c b/lib/dns/compress.c index 5c7a0dff01..1e0778cc47 100644 --- a/lib/dns/compress.c +++ b/lib/dns/compress.c @@ -150,11 +150,13 @@ dns_compress_invalidate(dns_compress_t *cctx) while (cctx->table[i] != NULL) { node = cctx->table[i]; cctx->table[i] = cctx->table[i]->next; - if ((node->offset & 0x8000) != 0) + if ((node->offset & 0x8000) != 0) { isc_mem_put(cctx->mctx, node->r.base, node->r.length); - if (node->count < DNS_COMPRESS_INITIALNODES) + } + if (node->count < DNS_COMPRESS_INITIALNODES) { continue; + } isc_mem_put(cctx->mctx, node, sizeof(*node)); } } @@ -192,10 +194,11 @@ dns_compress_setsensitive(dns_compress_t *cctx, bool sensitive) { REQUIRE(VALID_CCTX(cctx)); - if (sensitive) + if (sensitive) { cctx->allowed |= DNS_COMPRESS_CASESENSITIVE; - else + } else { cctx->allowed &= ~DNS_COMPRESS_CASESENSITIVE; + } } bool @@ -232,11 +235,13 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, REQUIRE(dns_name_isabsolute(name) == true); REQUIRE(offset != NULL); - if (ISC_UNLIKELY((cctx->allowed & DNS_COMPRESS_ENABLED) == 0)) + if (ISC_UNLIKELY((cctx->allowed & DNS_COMPRESS_ENABLED) == 0)) { return (false); + } - if (cctx->count == 0) + if (cctx->count == 0) { return (false); + } labels = dns_name_countlabels(name); INSIST(labels > 0); @@ -263,12 +268,14 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, 0)) { for (node = cctx->table[i]; node != NULL; node = node->next) { - if (ISC_UNLIKELY(node->name.length != length)) + if (ISC_UNLIKELY(node->name.length != length)) { continue; + } if (ISC_LIKELY(memcmp(node->name.ndata, p, - length) == 0)) + length) == 0)) { goto found; + } } } else { for (node = cctx->table[i]; node != NULL; @@ -277,19 +284,22 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, unsigned char c; unsigned char *label1, *label2; - if (ISC_UNLIKELY(node->name.length != length)) + if (ISC_UNLIKELY(node->name.length != length)) { continue; + } l = labels - n; - if (ISC_UNLIKELY(node->name.labels != l)) + if (ISC_UNLIKELY(node->name.labels != l)) { continue; + } label1 = node->name.ndata; label2 = p; while (ISC_LIKELY(l-- > 0)) { count = *label1++; - if (count != *label2++) + if (count != *label2++) { goto cont1; + } /* no bitstring support */ INSIST(count <= 63); @@ -297,25 +307,35 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, /* Loop unrolled for performance */ while (ISC_LIKELY(count > 3)) { c = maptolower[label1[0]]; - if (c != maptolower[label2[0]]) + if (c != + maptolower[label2[0]]) { goto cont1; + } c = maptolower[label1[1]]; - if (c != maptolower[label2[1]]) + if (c != + maptolower[label2[1]]) { goto cont1; + } c = maptolower[label1[2]]; - if (c != maptolower[label2[2]]) + if (c != + maptolower[label2[2]]) { goto cont1; + } c = maptolower[label1[3]]; - if (c != maptolower[label2[3]]) + if (c != + maptolower[label2[3]]) { goto cont1; + } count -= 4; label1 += 4; label2 += 4; } while (ISC_LIKELY(count-- > 0)) { c = maptolower[*label1++]; - if (c != maptolower[*label2++]) + if (c != + maptolower[*label2++]) { goto cont1; + } } } break; @@ -324,8 +344,9 @@ dns_compress_findglobal(dns_compress_t *cctx, const dns_name_t *name, } } - if (node != NULL) + if (node != NULL) { break; + } llen = *p; p += llen + 1; @@ -335,13 +356,15 @@ found: /* * If node == NULL, we found no match at all. */ - if (node == NULL) + if (node == NULL) { return (false); + } - if (n == 0) + if (n == 0) { dns_name_reset(prefix); - else + } else { dns_name_getlabelsequence(name, 0, n, prefix); + } *offset = (node->offset & 0x7fff); return (true); @@ -374,20 +397,24 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, REQUIRE(VALID_CCTX(cctx)); REQUIRE(dns_name_isabsolute(name)); - if (ISC_UNLIKELY((cctx->allowed & DNS_COMPRESS_ENABLED) == 0)) + if (ISC_UNLIKELY((cctx->allowed & DNS_COMPRESS_ENABLED) == 0)) { return; + } - if (offset >= 0x4000) + if (offset >= 0x4000) { return; + } dns_name_init(&tname, NULL); dns_name_init(&xname, NULL); n = dns_name_countlabels(name); count = dns_name_countlabels(prefix); - if (dns_name_isabsolute(prefix)) + if (dns_name_isabsolute(prefix)) { count--; - if (count == 0) + } + if (count == 0) { return; + } start = 0; dns_name_toregion(name, &r); length = r.length; @@ -399,8 +426,9 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, r.base = tmp; dns_name_fromregion(&xname, &r); - if (count > 2U) + if (count > 2U) { count = 2U; + } while (count > 0) { unsigned char ch; @@ -414,14 +442,15 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, i = tableindex[ch]; tlength = name_length(&tname); toffset = (uint16_t)(offset + (length - tlength)); - if (toffset >= 0x4000) + if (toffset >= 0x4000) { break; + } /* * Create a new node and add it. */ - if (cctx->count < DNS_COMPRESS_INITIALNODES) + if (cctx->count < DNS_COMPRESS_INITIALNODES) { node = &cctx->initialnodes[cctx->count]; - else { + } else { node = isc_mem_get(cctx->mctx, sizeof(dns_compressnode_t)); } @@ -430,8 +459,9 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, * 'node->r.base' becomes 'tmp' when start == 0. * Record this by setting 0x8000 so it can be freed later. */ - if (start == 0) + if (start == 0) { toffset |= 0x8000; + } node->offset = toffset; dns_name_toregion(&tname, &node->r); dns_name_init(&node->name, NULL); @@ -446,8 +476,9 @@ dns_compress_add(dns_compress_t *cctx, const dns_name_t *name, count--; } - if (start == 0) + if (start == 0) { isc_mem_put(cctx->mctx, tmp, length); + } } void @@ -458,8 +489,9 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset) REQUIRE(VALID_CCTX(cctx)); - if (ISC_UNLIKELY((cctx->allowed & DNS_COMPRESS_ENABLED) == 0)) + if (ISC_UNLIKELY((cctx->allowed & DNS_COMPRESS_ENABLED) == 0)) { return; + } for (i = 0; i < DNS_COMPRESS_TABLESIZE; i++) { node = cctx->table[i]; @@ -471,11 +503,13 @@ dns_compress_rollback(dns_compress_t *cctx, uint16_t offset) */ while (node != NULL && (node->offset & 0x7fff) >= offset) { cctx->table[i] = node->next; - if ((node->offset & 0x8000) != 0) + if ((node->offset & 0x8000) != 0) { isc_mem_put(cctx->mctx, node->r.base, node->r.length); - if (node->count >= DNS_COMPRESS_INITIALNODES) + } + if (node->count >= DNS_COMPRESS_INITIALNODES) { isc_mem_put(cctx->mctx, node, sizeof(*node)); + } cctx->count--; node = cctx->table[i]; } diff --git a/lib/dns/db.c b/lib/dns/db.c index 486d55ffb7..0691f3160f 100644 --- a/lib/dns/db.c +++ b/lib/dns/db.c @@ -170,8 +170,9 @@ dns_db_iscache(dns_db_t *db) REQUIRE(DNS_DB_VALID(db)); - if ((db->attributes & DNS_DBATTR_CACHE) != 0) + if ((db->attributes & DNS_DBATTR_CACHE) != 0) { return (true); + } return (false); } @@ -185,8 +186,9 @@ dns_db_iszone(dns_db_t *db) REQUIRE(DNS_DB_VALID(db)); - if ((db->attributes & (DNS_DBATTR_CACHE | DNS_DBATTR_STUB)) == 0) + if ((db->attributes & (DNS_DBATTR_CACHE | DNS_DBATTR_STUB)) == 0) { return (true); + } return (false); } @@ -200,8 +202,9 @@ dns_db_isstub(dns_db_t *db) REQUIRE(DNS_DB_VALID(db)); - if ((db->attributes & DNS_DBATTR_STUB) != 0) + if ((db->attributes & DNS_DBATTR_STUB) != 0) { return (true); + } return (false); } @@ -216,8 +219,9 @@ dns_db_isdnssec(dns_db_t *db) REQUIRE(DNS_DB_VALID(db)); REQUIRE((db->attributes & DNS_DBATTR_CACHE) == 0); - if (db->methods->isdnssec != NULL) + if (db->methods->isdnssec != NULL) { return ((db->methods->isdnssec)(db)); + } return ((db->methods->issecure)(db)); } @@ -297,8 +301,9 @@ dns_db_endload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) REQUIRE(callbacks->add_private != NULL); for (listener = ISC_LIST_HEAD(db->update_listeners); listener != NULL; - listener = ISC_LIST_NEXT(listener, link)) + listener = ISC_LIST_NEXT(listener, link)) { listener->onupdate(db, listener->onupdate_arg); + } return ((db->methods->endload)(db, callbacks)); } @@ -316,13 +321,15 @@ dns_db_load(dns_db_t *db, const char *filename, dns_masterformat_t format, REQUIRE(DNS_DB_VALID(db)); - if ((db->attributes & DNS_DBATTR_CACHE) != 0) + if ((db->attributes & DNS_DBATTR_CACHE) != 0) { options |= DNS_MASTER_AGETTL; + } dns_rdatacallbacks_init(&callbacks); result = dns_db_beginload(db, &callbacks); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_master_loadfile(filename, &db->origin, &db->origin, db->rdclass, options, 0, &callbacks, NULL, NULL, db->mctx, format, 0); @@ -333,8 +340,9 @@ dns_db_load(dns_db_t *db, const char *filename, dns_masterformat_t format, * failed, we want to return the result code it gave us. */ if (eresult != ISC_R_SUCCESS && - (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE)) + (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE)) { result = eresult; + } return (result); } @@ -343,8 +351,9 @@ isc_result_t dns_db_serialize(dns_db_t *db, dns_dbversion_t *version, FILE *file) { REQUIRE(DNS_DB_VALID(db)); - if (db->methods->serialize == NULL) + if (db->methods->serialize == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((db->methods->serialize)(db, version, file)); } @@ -422,8 +431,10 @@ dns_db_closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) if (commit == true) { for (listener = ISC_LIST_HEAD(db->update_listeners); - listener != NULL; listener = ISC_LIST_NEXT(listener, link)) + listener != NULL; + listener = ISC_LIST_NEXT(listener, link)) { listener->onupdate(db, listener->onupdate_arg); + } } ENSURE(*versionp == NULL); @@ -444,11 +455,12 @@ dns_db_findnode(dns_db_t *db, const dns_name_t *name, bool create, REQUIRE(DNS_DB_VALID(db)); REQUIRE(nodep != NULL && *nodep == NULL); - if (db->methods->findnode != NULL) + if (db->methods->findnode != NULL) { return ((db->methods->findnode)(db, name, create, nodep)); - else + } else { return ((db->methods->findnodeext)(db, name, create, NULL, NULL, nodep)); + } } isc_result_t @@ -464,11 +476,12 @@ dns_db_findnodeext(dns_db_t *db, const dns_name_t *name, bool create, REQUIRE(DNS_DB_VALID(db)); REQUIRE(nodep != NULL && *nodep == NULL); - if (db->methods->findnodeext != NULL) + if (db->methods->findnodeext != NULL) { return ((db->methods->findnodeext)(db, name, create, methods, clientinfo, nodep)); - else + } else { return ((db->methods->findnode)(db, name, create, nodep)); + } } isc_result_t @@ -506,14 +519,15 @@ dns_db_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, (DNS_RDATASET_VALID(sigrdataset) && !dns_rdataset_isassociated(sigrdataset))); - if (db->methods->find != NULL) + if (db->methods->find != NULL) { return ((db->methods->find)(db, name, version, type, options, now, nodep, foundname, rdataset, sigrdataset)); - else + } else { return ((db->methods->findext)(db, name, version, type, options, now, nodep, foundname, NULL, NULL, rdataset, sigrdataset)); + } } isc_result_t @@ -538,14 +552,15 @@ dns_db_findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, (DNS_RDATASET_VALID(sigrdataset) && !dns_rdataset_isassociated(sigrdataset))); - if (db->methods->findext != NULL) + if (db->methods->findext != NULL) { return ((db->methods->findext)( db, name, version, type, options, now, nodep, foundname, methods, clientinfo, rdataset, sigrdataset)); - else + } else { return ((db->methods->find)(db, name, version, type, options, now, nodep, foundname, rdataset, sigrdataset)); + } } isc_result_t @@ -620,8 +635,9 @@ dns_db_transfernode(dns_db_t *db, dns_dbnode_t **sourcep, if (db->methods->transfernode == NULL) { *targetp = *sourcep; *sourcep = NULL; - } else + } else { (db->methods->transfernode)(db, sourcep, targetp); + } ENSURE(*sourcep == NULL); } @@ -800,18 +816,21 @@ dns_db_getsoaserial(dns_db_t *db, dns_dbversion_t *ver, uint32_t *serialp) REQUIRE(dns_db_iszone(db) || dns_db_isstub(db)); result = dns_db_findnode(db, dns_db_origin(db), false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0, (isc_stdtime_t)0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto freenode; + } result = dns_rdataset_first(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto freerdataset; + } dns_rdataset_current(&rdataset, &rdata); result = dns_rdataset_next(&rdataset); INSIST(result == ISC_R_NOMORE); @@ -845,8 +864,9 @@ dns_db_hashsize(dns_db_t *db) { REQUIRE(DNS_DB_VALID(db)); - if (db->methods->hashsize == NULL) + if (db->methods->hashsize == NULL) { return (0); + } return ((db->methods->hashsize)(db)); } @@ -917,8 +937,9 @@ dns_db_getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) REQUIRE(dns_db_iszone(db) == true); REQUIRE(nodep != NULL && *nodep == NULL); - if (db->methods->getoriginnode != NULL) + if (db->methods->getoriginnode != NULL) { return ((db->methods->getoriginnode)(db, nodep)); + } return (ISC_R_NOTFOUND); } @@ -928,8 +949,9 @@ dns_db_getrrsetstats(dns_db_t *db) { REQUIRE(DNS_DB_VALID(db)); - if (db->methods->getrrsetstats != NULL) + if (db->methods->getrrsetstats != NULL) { return ((db->methods->getrrsetstats)(db)); + } return (NULL); } @@ -939,8 +961,9 @@ dns_db_setcachestats(dns_db_t *db, isc_stats_t *stats) { REQUIRE(DNS_DB_VALID(db)); - if (db->methods->setcachestats != NULL) + if (db->methods->setcachestats != NULL) { return ((db->methods->setcachestats)(db, stats)); + } return (ISC_R_NOTIMPLEMENTED); } @@ -954,10 +977,11 @@ dns_db_getnsec3parameters(dns_db_t *db, dns_dbversion_t *version, REQUIRE(DNS_DB_VALID(db)); REQUIRE(dns_db_iszone(db) == true); - if (db->methods->getnsec3parameters != NULL) + if (db->methods->getnsec3parameters != NULL) { return ((db->methods->getnsec3parameters)(db, version, hash, flags, iterations, salt, salt_length)); + } return (ISC_R_NOTFOUND); } @@ -969,8 +993,9 @@ dns_db_getsize(dns_db_t *db, dns_dbversion_t *version, uint64_t *records, REQUIRE(DNS_DB_VALID(db)); REQUIRE(dns_db_iszone(db) == true); - if (db->methods->getsize != NULL) + if (db->methods->getsize != NULL) { return ((db->methods->getsize)(db, version, records, bytes)); + } return (ISC_R_NOTFOUND); } @@ -979,16 +1004,18 @@ isc_result_t dns_db_setsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, isc_stdtime_t resign) { - if (db->methods->setsigningtime != NULL) + if (db->methods->setsigningtime != NULL) { return ((db->methods->setsigningtime)(db, rdataset, resign)); + } return (ISC_R_NOTIMPLEMENTED); } isc_result_t dns_db_getsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, dns_name_t *name) { - if (db->methods->getsigningtime != NULL) + if (db->methods->getsigningtime != NULL) { return ((db->methods->getsigningtime)(db, rdataset, name)); + } return (ISC_R_NOTFOUND); } @@ -996,8 +1023,9 @@ void dns_db_resigned(dns_db_t *db, dns_rdataset_t *rdataset, dns_dbversion_t *version) { - if (db->methods->resigned != NULL) + if (db->methods->resigned != NULL) { (db->methods->resigned)(db, rdataset, version); + } } /* @@ -1018,8 +1046,9 @@ dns_db_rpz_attach(dns_db_t *db, void *rpzs, uint8_t rpz_num) isc_result_t dns_db_rpz_ready(dns_db_t *db) { - if (db->methods->rpz_ready == NULL) + if (db->methods->rpz_ready == NULL) { return (ISC_R_SUCCESS); + } return ((db->methods->rpz_ready)(db)); } @@ -1075,8 +1104,9 @@ dns_db_nodefullname(dns_db_t *db, dns_dbnode_t *node, dns_name_t *name) REQUIRE(node != NULL); REQUIRE(name != NULL); - if (db->methods->nodefullname == NULL) + if (db->methods->nodefullname == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((db->methods->nodefullname)(db, node, name)); } @@ -1086,8 +1116,9 @@ dns_db_setservestalettl(dns_db_t *db, dns_ttl_t ttl) REQUIRE(DNS_DB_VALID(db)); REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0); - if (db->methods->setservestalettl != NULL) + if (db->methods->setservestalettl != NULL) { return ((db->methods->setservestalettl)(db, ttl)); + } return (ISC_R_NOTIMPLEMENTED); } @@ -1097,8 +1128,9 @@ dns_db_getservestalettl(dns_db_t *db, dns_ttl_t *ttl) REQUIRE(DNS_DB_VALID(db)); REQUIRE((db->attributes & DNS_DBATTR_CACHE) != 0); - if (db->methods->getservestalettl != NULL) + if (db->methods->getservestalettl != NULL) { return ((db->methods->getservestalettl)(db, ttl)); + } return (ISC_R_NOTIMPLEMENTED); } diff --git a/lib/dns/dbtable.c b/lib/dns/dbtable.c index d685337972..dc888a5742 100644 --- a/lib/dns/dbtable.c +++ b/lib/dns/dbtable.c @@ -60,12 +60,14 @@ dns_dbtable_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dbtable->rbt = NULL; result = dns_rbt_create(mctx, dbdetach, NULL, &dbtable->rbt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto clean1; + } result = isc_rwlock_init(&dbtable->tree_lock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto clean3; + } dbtable->default_db = NULL; dbtable->mctx = NULL; @@ -96,8 +98,9 @@ dbtable_free(dns_dbtable_t *dbtable) RWLOCK(&dbtable->tree_lock, isc_rwlocktype_write); - if (dbtable->default_db != NULL) + if (dbtable->default_db != NULL) { dns_db_detach(&dbtable->default_db); + } dns_rbt_destroy(&dbtable->rbt); @@ -238,21 +241,23 @@ dns_dbtable_find(dns_dbtable_t *dbtable, const dns_name_t *name, REQUIRE(dbp != NULL && *dbp == NULL); - if ((options & DNS_DBTABLEFIND_NOEXACT) != 0) + if ((options & DNS_DBTABLEFIND_NOEXACT) != 0) { rbtoptions |= DNS_RBTFIND_NOEXACT; + } RWLOCK(&dbtable->tree_lock, isc_rwlocktype_read); result = dns_rbt_findname(dbtable->rbt, name, rbtoptions, NULL, (void **)(void *)&stored_data); - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { dns_db_attach(stored_data, dbp); - else if (dbtable->default_db != NULL) { + } else if (dbtable->default_db != NULL) { dns_db_attach(dbtable->default_db, dbp); result = DNS_R_PARTIALMATCH; - } else + } else { result = ISC_R_NOTFOUND; + } RWUNLOCK(&dbtable->tree_lock, isc_rwlocktype_read); diff --git a/lib/dns/diff.c b/lib/dns/diff.c index b67e4df637..9010fd1bf5 100644 --- a/lib/dns/diff.c +++ b/lib/dns/diff.c @@ -209,10 +209,11 @@ setresign(dns_rdataset_t *modified) INSIST(result == ISC_R_SUCCESS); dns_rdataset_current(modified, &rdata); (void)dns_rdata_tostruct(&rdata, &sig, NULL); - if ((rdata.flags & DNS_RDATA_OFFLINE) != 0) + if ((rdata.flags & DNS_RDATA_OFFLINE) != 0) { when = 0; - else + } else { when = dns_time64_from32(sig.timeexpire); + } dns_rdata_reset(&rdata); result = dns_rdataset_next(modified); @@ -222,8 +223,9 @@ setresign(dns_rdataset_t *modified) if ((rdata.flags & DNS_RDATA_OFFLINE) != 0) { goto next_rr; } - if (when == 0 || dns_time64_from32(sig.timeexpire) < when) + if (when == 0 || dns_time64_from32(sig.timeexpire) < when) { when = dns_time64_from32(sig.timeexpire); + } next_rr: dns_rdata_reset(&rdata); result = dns_rdataset_next(modified); @@ -235,15 +237,17 @@ setresign(dns_rdataset_t *modified) static void getownercase(dns_rdataset_t *rdataset, dns_name_t *name) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_getownercase(rdataset, name); + } } static void setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_setownercase(rdataset, name); + } } static isc_result_t @@ -309,11 +313,12 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver, bool warn) node = NULL; if (type != dns_rdatatype_nsec3 && - covers != dns_rdatatype_nsec3) + covers != dns_rdatatype_nsec3) { CHECK(dns_db_findnode(db, name, true, &node)); - else + } else { CHECK(dns_db_findnsec3node(db, name, true, &node)); + } while (t != NULL && dns_name_equal(&t->name, name) && t->op == op && t->rdata.type == type && @@ -389,11 +394,13 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver, bool warn) resign); } if (op == DNS_DIFFOP_ADD || - op == DNS_DIFFOP_ADDRESIGN) + op == DNS_DIFFOP_ADDRESIGN) { setownercase(&ardataset, name); + } if (op == DNS_DIFFOP_DEL || - op == DNS_DIFFOP_DELRESIGN) + op == DNS_DIFFOP_DELRESIGN) { getownercase(&ardataset, name); + } } else if (result == DNS_R_UNCHANGED) { /* * This will not happen when executing a @@ -417,35 +424,42 @@ diff_apply(dns_diff_t *diff, dns_db_t *db, dns_dbversion_t *ver, bool warn) namebuf, classbuf); } if (op == DNS_DIFFOP_ADD || - op == DNS_DIFFOP_ADDRESIGN) + op == DNS_DIFFOP_ADDRESIGN) { setownercase(&ardataset, name); + } if (op == DNS_DIFFOP_DEL || - op == DNS_DIFFOP_DELRESIGN) + op == DNS_DIFFOP_DELRESIGN) { getownercase(&ardataset, name); + } } else if (result == DNS_R_NXRRSET) { /* * OK. */ if (op == DNS_DIFFOP_DEL || - op == DNS_DIFFOP_DELRESIGN) + op == DNS_DIFFOP_DELRESIGN) { getownercase(&ardataset, name); - if (dns_rdataset_isassociated(&ardataset)) + } + if (dns_rdataset_isassociated(&ardataset)) { dns_rdataset_disassociate(&ardataset); + } } else { - if (dns_rdataset_isassociated(&ardataset)) + if (dns_rdataset_isassociated(&ardataset)) { dns_rdataset_disassociate(&ardataset); + } CHECK(result); } dns_db_detachnode(db, &node); - if (dns_rdataset_isassociated(&ardataset)) + if (dns_rdataset_isassociated(&ardataset)) { dns_rdataset_disassociate(&ardataset); + } } } return (ISC_R_SUCCESS); failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -544,10 +558,12 @@ dns_diff_sort(dns_diff_t *diff, dns_diff_compare_func *compare) REQUIRE(DNS_DIFF_VALID(diff)); for (p = ISC_LIST_HEAD(diff->tuples); p != NULL; - p = ISC_LIST_NEXT(p, link)) + p = ISC_LIST_NEXT(p, link)) { length++; - if (length == 0) + } + if (length == 0) { return (ISC_R_SUCCESS); + } v = isc_mem_get(diff->mctx, length * sizeof(dns_difftuple_t *)); for (i = 0; i < length; i++) { p = ISC_LIST_HEAD(diff->tuples); @@ -630,8 +646,9 @@ dns_diff_print(dns_diff_t *diff, FILE *file) goto again; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Get rid of final newline. */ @@ -657,17 +674,19 @@ dns_diff_print(dns_diff_t *diff, FILE *file) op = "del re-sign"; break; } - if (file != NULL) + if (file != NULL) { fprintf(file, "%s %.*s\n", op, (int)r.length, (char *)r.base); - else + } else { isc_log_write(DIFF_COMMON_LOGARGS, ISC_LOG_DEBUG(7), "%s %.*s", op, (int)r.length, (char *)r.base); + } } result = ISC_R_SUCCESS; cleanup: - if (mem != NULL) + if (mem != NULL) { isc_mem_put(diff->mctx, mem, size); + } return (result); } diff --git a/lib/dns/dispatch.c b/lib/dns/dispatch.c index c4c640ddb9..18678571f9 100644 --- a/lib/dns/dispatch.c +++ b/lib/dns/dispatch.c @@ -140,7 +140,7 @@ struct dns_dispentry { */ #ifndef DNS_DISPATCH_POOLSOCKS #define DNS_DISPATCH_POOLSOCKS 2048 -#endif +#endif /* ifndef DNS_DISPATCH_POOLSOCKS */ /*% * Quota to control the number of dispatch sockets. If a dispatch has more @@ -150,7 +150,7 @@ struct dns_dispentry { */ #ifndef DNS_DISPATCH_SOCKSQUOTA #define DNS_DISPATCH_SOCKSQUOTA 3072 -#endif +#endif /* ifndef DNS_DISPATCH_SOCKSQUOTA */ struct dispsocket { unsigned int magic; @@ -179,7 +179,7 @@ struct dispportentry { #ifndef DNS_DISPATCH_PORTTABLESIZE #define DNS_DISPATCH_PORTTABLESIZE 1024 -#endif +#endif /* ifndef DNS_DISPATCH_PORTTABLESIZE */ #define INVALID_BUCKET (0xffffdead) @@ -222,7 +222,10 @@ struct dns_dispatch { unsigned int refcount; /*%< number of users */ dns_dispatchevent_t *failsafe_ev; /*%< failsafe cancel event */ unsigned int shutting_down : 1, shutdown_out : 1, connected : 1, - tcpmsg_valid : 1, recv_pending : 1; /*%< is a recv() pending? */ + tcpmsg_valid : 1, recv_pending : 1; /*%< is a + * recv() + * pending? + * */ isc_result_t shutdown_why; ISC_LIST(dispsocket_t) activesockets; ISC_LIST(dispsocket_t) inactivesockets; @@ -348,8 +351,9 @@ mgr_log(dns_dispatchmgr_t *mgr, int level, const char *fmt, ...) char msgbuf[2048]; va_list ap; - if (!isc_log_wouldlog(dns_lctx, level)) + if (!isc_log_wouldlog(dns_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -363,15 +367,17 @@ mgr_log(dns_dispatchmgr_t *mgr, int level, const char *fmt, ...) static inline void inc_stats(dns_dispatchmgr_t *mgr, isc_statscounter_t counter) { - if (mgr->stats != NULL) + if (mgr->stats != NULL) { isc_stats_increment(mgr->stats, counter); + } } static inline void dec_stats(dns_dispatchmgr_t *mgr, isc_statscounter_t counter) { - if (mgr->stats != NULL) + if (mgr->stats != NULL) { isc_stats_decrement(mgr->stats, counter); + } } static void @@ -384,8 +390,9 @@ dispatch_log(dns_dispatch_t *disp, int level, const char *fmt, ...) char msgbuf[2048]; va_list ap; - if (!isc_log_wouldlog(dns_lctx, level)) + if (!isc_log_wouldlog(dns_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -408,8 +415,9 @@ request_log(dns_dispatch_t *disp, dns_dispentry_t *resp, int level, char peerbuf[256]; va_list ap; - if (!isc_log_wouldlog(dns_lctx, level)) + if (!isc_log_wouldlog(dns_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -460,8 +468,9 @@ linear_first(dns_qid_t *qid) while (bucket < qid->qid_nbuckets) { ret = ISC_LIST_HEAD(qid->qid_table[bucket]); - if (ret != NULL) + if (ret != NULL) { return (ret); + } bucket++; } @@ -479,15 +488,17 @@ linear_next(dns_qid_t *qid, dns_dispentry_t *resp) unsigned int bucket; ret = ISC_LIST_NEXT(resp, link); - if (ret != NULL) + if (ret != NULL) { return (ret); + } bucket = resp->bucket; bucket++; while (bucket < qid->qid_nbuckets) { ret = ISC_LIST_HEAD(qid->qid_table[bucket]); - if (ret != NULL) + if (ret != NULL) { return (ret); + } bucket++; } @@ -500,17 +511,21 @@ linear_next(dns_qid_t *qid, dns_dispentry_t *resp) static bool destroy_disp_ok(dns_dispatch_t *disp) { - if (disp->refcount != 0) + if (disp->refcount != 0) { return (false); + } - if (disp->recv_pending != 0) + if (disp->recv_pending != 0) { return (false); + } - if (!ISC_LIST_EMPTY(disp->activesockets)) + if (!ISC_LIST_EMPTY(disp->activesockets)) { return (false); + } - if (disp->shutting_down == 0) + if (disp->shutting_down == 0) { return (false); + } return (true); } @@ -549,22 +564,25 @@ destroy_disp(isc_task_t *task, isc_event_t *event) isc_mutex_destroy(&disp->sepool_lock); } - if (disp->socket != NULL) + if (disp->socket != NULL) { isc_socket_detach(&disp->socket); + } while ((dispsocket = ISC_LIST_HEAD(disp->inactivesockets)) != NULL) { ISC_LIST_UNLINK(disp->inactivesockets, dispsocket, link); destroy_dispsocket(disp, &dispsocket); } - for (i = 0; i < disp->ntasks; i++) + for (i = 0; i < disp->ntasks; i++) { isc_task_detach(&disp->task[i]); + } isc_event_free(&event); dispatch_free(&disp); killmgr = destroy_mgr_ok(mgr); UNLOCK(&mgr->lock); - if (killmgr) + if (killmgr) { destroy_mgr(&mgr); + } } /*% @@ -581,8 +599,9 @@ port_search(dns_dispatch_t *disp, in_port_t port) portentry = ISC_LIST_HEAD( disp->port_table[port % DNS_DISPATCH_PORTTABLESIZE]); while (portentry != NULL) { - if (portentry->port == port) + if (portentry->port == port) { return (portentry); + } portentry = ISC_LIST_NEXT(portentry, link); } @@ -598,8 +617,9 @@ new_portentry(dns_dispatch_t *disp, in_port_t port) REQUIRE(disp->port_table != NULL); portentry = isc_mempool_get(disp->portpool); - if (portentry == NULL) + if (portentry == NULL) { return (portentry); + } portentry->port = port; isc_refcount_init(&portentry->refs, 1); @@ -655,8 +675,9 @@ socket_search(dns_qid_t *qid, const isc_sockaddr_t *dest, in_port_t port, while (dispsock != NULL) { if (dispsock->portentry != NULL && dispsock->portentry->port == port && - isc_sockaddr_equal(dest, &dispsock->host)) + isc_sockaddr_equal(dest, &dispsock->host)) { return (dispsock); + } dispsock = ISC_LIST_NEXT(dispsock, blink); } @@ -693,8 +714,9 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest, nports = disp->mgr->nv6ports; ports = disp->mgr->v6ports; } - if (nports == 0) + if (nports == 0) { return (ISC_R_ADDRNOTAVAIL); + } dispsock = ISC_LIST_HEAD(disp->inactivesockets); if (dispsock != NULL) { @@ -703,8 +725,9 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest, dispsock->socket = NULL; } else { dispsock = isc_mempool_get(mgr->spool); - if (dispsock == NULL) + if (dispsock == NULL) { return (ISC_R_NOMEMORY); + } disp->nsockets++; dispsock->socket = NULL; @@ -741,8 +764,9 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest, bindoptions = 0; portentry = port_search(disp, port); - if (portentry != NULL) + if (portentry != NULL) { bindoptions |= ISC_SOCKET_REUSEADDRESS; + } result = open_socket(sockmgr, &localaddr, bindoptions, &sock, NULL, false); if (result == ISC_R_SUCCESS) { @@ -762,8 +786,9 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest, dispatch_log(disp, ISC_LOG_WARNING, "open_socket(%s) -> %s: continuing", buf, isc_result_totext(result)); - } else if (result != ISC_R_ADDRINUSE) + } else if (result != ISC_R_ADDRINUSE) { break; + } } if (result == ISC_R_SUCCESS) { @@ -782,8 +807,9 @@ get_dispsocket(dns_dispatch_t *disp, const isc_sockaddr_t *dest, * be an exceptional case and might be resource shortage, we'd * rather destroy it. */ - if (sock != NULL) + if (sock != NULL) { isc_socket_detach(&sock); + } destroy_dispsocket(disp, &dispsock); } @@ -810,10 +836,12 @@ destroy_dispsocket(dns_dispatch_t *disp, dispsocket_t **dispsockp) disp->nsockets--; dispsock->magic = 0; - if (dispsock->portentry != NULL) + if (dispsock->portentry != NULL) { deref_portentry(disp, &dispsock->portentry); - if (dispsock->socket != NULL) + } + if (dispsock->socket != NULL) { isc_socket_detach(&dispsock->socket); + } if (ISC_LINK_LINKED(dispsock, blink)) { qid = DNS_QID(disp); LOCK(&qid->lock); @@ -821,8 +849,9 @@ destroy_dispsocket(dns_dispatch_t *disp, dispsocket_t **dispsockp) blink); UNLOCK(&qid->lock); } - if (dispsock->task != NULL) + if (dispsock->task != NULL) { isc_task_detach(&dispsock->task); + } isc_mempool_put(disp->mgr->spool, dispsock); } @@ -848,9 +877,9 @@ deactivate_dispsocket(dns_dispatch_t *disp, dispsocket_t *dispsock) INSIST(dispsock->portentry != NULL); deref_portentry(disp, &dispsock->portentry); - if (disp->nsockets > DNS_DISPATCH_POOLSOCKS) + if (disp->nsockets > DNS_DISPATCH_POOLSOCKS) { destroy_dispsocket(disp, &dispsock); - else { + } else { result = isc_socket_close(dispsock->socket); qid = DNS_QID(disp); @@ -859,9 +888,9 @@ deactivate_dispsocket(dns_dispatch_t *disp, dispsocket_t *dispsock) blink); UNLOCK(&qid->lock); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { ISC_LIST_APPEND(disp->inactivesockets, dispsock, link); - else { + } else { /* * If the underlying system does not allow this * optimization, destroy this temporary structure (and @@ -969,8 +998,9 @@ allocate_sevent(dns_dispatch_t *disp, isc_socket_t *sock, isc_eventtype_t type, void * deconst_arg; ev = isc_mempool_get(disp->sepool); - if (ev == NULL) + if (ev == NULL) { return (NULL); + } DE_CONST(arg, deconst_arg); ISC_EVENT_INIT(ev, sizeof(*ev), 0, NULL, type, action, deconst_arg, sock, free_sevent, disp->sepool); @@ -1003,8 +1033,9 @@ allocate_devent(dns_dispatch_t *disp) dns_dispatchevent_t *ev; ev = isc_mempool_get(disp->mgr->depool); - if (ev == NULL) + if (ev == NULL) { return (NULL); + } ISC_EVENT_INIT(ev, sizeof(*ev), 0, NULL, 0, NULL, NULL, NULL, NULL, NULL); @@ -1112,8 +1143,9 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) killit = destroy_disp_ok(disp); UNLOCK(&disp->lock); - if (killit) + if (killit) { isc_task_send(disp->task[0], &disp->ctlevent); + } return; } @@ -1141,10 +1173,11 @@ udp_recv(isc_event_t *ev_in, dns_dispatch_t *disp, dispsocket_t *dispsock) } else if (ev->result != ISC_R_SUCCESS) { free_buffer(disp, ev->region.base, ev->region.length); - if (ev->result != ISC_R_CANCELED) + if (ev->result != ISC_R_CANCELED) { dispatch_log(disp, ISC_LOG_ERROR, "odd socket result in udp_recv(): %s", isc_result_totext(ev->result)); + } isc_event_free(&ev_in); UNLOCK(&disp->lock); @@ -1302,8 +1335,9 @@ sendresponse: isc_task_send(resp->task, ISC_EVENT_PTR(&rev)); } unlock: - if (qidlocked) + if (qidlocked) { UNLOCK(&qid->lock); + } /* * Restart recv() to get the next packet. @@ -1418,8 +1452,9 @@ tcp_recv(isc_task_t *task, isc_event_t *ev_in) */ killit = destroy_disp_ok(disp); UNLOCK(&disp->lock); - if (killit) + if (killit) { isc_task_send(disp->task[0], &disp->ctlevent); + } return; } @@ -1465,12 +1500,14 @@ tcp_recv(isc_task_t *task, isc_event_t *ev_in) dispatch_log(disp, LVL(90), "search for response in bucket %d: %s", bucket, (resp == NULL ? "not found" : "found")); - if (resp == NULL) + if (resp == NULL) { goto unlock; + } queue_response = resp->item_out; rev = allocate_devent(disp); - if (rev == NULL) + if (rev == NULL) { goto unlock; + } /* * At this point, rev contains the event we want to fill in, and @@ -1517,34 +1554,40 @@ startrecv(dns_dispatch_t *disp, dispsocket_t *dispsock) isc_region_t region; isc_socket_t *sock; - if (disp->shutting_down == 1) + if (disp->shutting_down == 1) { return (ISC_R_SUCCESS); + } - if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) != 0) + if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) != 0) { return (ISC_R_SUCCESS); + } - if (disp->recv_pending != 0 && dispsock == NULL) + if (disp->recv_pending != 0 && dispsock == NULL) { return (ISC_R_SUCCESS); + } if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0 && - dispsock == NULL) + dispsock == NULL) { return (ISC_R_SUCCESS); + } - if (dispsock != NULL) + if (dispsock != NULL) { sock = dispsock->socket; - else + } else { sock = disp->socket; + } INSIST(sock != NULL); switch (disp->socktype) { - /* - * UDP reads are always maximal. - */ + /* + * UDP reads are always maximal. + */ case isc_sockettype_udp: region.length = disp->mgr->buffersize; region.base = allocate_udp_buffer(disp); - if (region.base == NULL) + if (region.base == NULL) { return (ISC_R_NOMEMORY); + } if (dispsock != NULL) { isc_task_t * dt = dispsock->task; isc_socketevent_t *sev = allocate_sevent( @@ -1616,16 +1659,21 @@ destroy_mgr_ok(dns_dispatchmgr_t *mgr) isc_mempool_getallocated(mgr->depool), isc_mempool_getallocated(mgr->rpool), isc_mempool_getallocated(mgr->dpool)); - if (!MGR_IS_SHUTTINGDOWN(mgr)) + if (!MGR_IS_SHUTTINGDOWN(mgr)) { return (false); - if (!ISC_LIST_EMPTY(mgr->list)) + } + if (!ISC_LIST_EMPTY(mgr->list)) { return (false); - if (isc_mempool_getallocated(mgr->depool) != 0) + } + if (isc_mempool_getallocated(mgr->depool) != 0) { return (false); - if (isc_mempool_getallocated(mgr->rpool) != 0) + } + if (isc_mempool_getallocated(mgr->rpool) != 0) { return (false); - if (isc_mempool_getallocated(mgr->dpool) != 0) + } + if (isc_mempool_getallocated(mgr->dpool) != 0) { return (false); + } return (true); } @@ -1648,10 +1696,12 @@ destroy_mgr(dns_dispatchmgr_t **mgrp) isc_mempool_destroy(&mgr->depool); isc_mempool_destroy(&mgr->rpool); isc_mempool_destroy(&mgr->dpool); - if (mgr->bpool != NULL) + if (mgr->bpool != NULL) { isc_mempool_destroy(&mgr->bpool); - if (mgr->spool != NULL) + } + if (mgr->spool != NULL) { isc_mempool_destroy(&mgr->spool); + } isc_mutex_destroy(&mgr->spool_lock); isc_mutex_destroy(&mgr->bpool_lock); @@ -1720,7 +1770,7 @@ open_socket(isc_socketmgr_t *mgr, const isc_sockaddr_t *local, #ifndef ISC_ALLOW_MAPPED isc_socket_ipv6only(sock, true); -#endif +#endif /* ifndef ISC_ALLOW_MAPPED */ result = isc_socket_bind(sock, local, options); if (result != ISC_R_SUCCESS) { if (*sockp == NULL) { @@ -1747,8 +1797,9 @@ create_default_portset(isc_mem_t *mctx, isc_portset_t **portsetp) isc_result_t result; result = isc_portset_create(mctx, portsetp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_portset_addrange(*portsetp, 1024, 65535); return (ISC_R_SUCCESS); @@ -1835,12 +1886,15 @@ dns_dispatchmgr_create(isc_mem_t *mctx, dns_dispatchmgr_t **mgrp) v6portset); } } - if (v4portset != NULL) + if (v4portset != NULL) { isc_portset_destroy(mctx, &v4portset); - if (v6portset != NULL) + } + if (v6portset != NULL) { isc_portset_destroy(mctx, &v6portset); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto kill_dpool; + } *mgrp = mgr; return (ISC_R_SUCCESS); @@ -1865,8 +1919,9 @@ void dns_dispatchmgr_setblackhole(dns_dispatchmgr_t *mgr, dns_acl_t *blackhole) { REQUIRE(VALID_DISPATCHMGR(mgr)); - if (mgr->blackhole != NULL) + if (mgr->blackhole != NULL) { dns_acl_detach(&mgr->blackhole); + } dns_acl_attach(blackhole, &mgr->blackhole); } @@ -1976,8 +2031,9 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize, * XXXMLG */ - if (maxbuffers < 8) + if (maxbuffers < 8) { maxbuffers = 8; + } LOCK(&mgr->buffer_lock); @@ -2025,8 +2081,9 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize, isc_mempool_setfillcount(mgr->spool, 32); result = qid_allocate(mgr, buckets, increment, &mgr->qid, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } mgr->buffersize = buffersize; mgr->maxbuffers = maxbuffers; @@ -2035,8 +2092,9 @@ dns_dispatchmgr_setudp(dns_dispatchmgr_t *mgr, unsigned int buffersize, cleanup: isc_mempool_destroy(&mgr->bpool); - if (mgr->spool != NULL) + if (mgr->spool != NULL) { isc_mempool_destroy(&mgr->spool); + } UNLOCK(&mgr->buffer_lock); return (result); } @@ -2060,8 +2118,9 @@ dns_dispatchmgr_destroy(dns_dispatchmgr_t **mgrp) mgr_log(mgr, LVL(90), "destroy: killit=%d", killit); - if (killit) + if (killit) { destroy_mgr(&mgr); + } } void @@ -2080,12 +2139,13 @@ port_cmp(const void *key, const void *ent) in_port_t p1 = *(const in_port_t *)key; in_port_t p2 = *(const in_port_t *)ent; - if (p1 < p2) + if (p1 < p2) { return (-1); - else if (p1 == p2) + } else if (p1 == p2) { return (0); - else + } else { return (1); + } } static bool @@ -2104,8 +2164,9 @@ portavailable(dns_dispatchmgr_t *mgr, isc_socket_t *sock, if (sock != NULL) { sockaddrp = &sockaddr; result = isc_socket_getsockname(sock, sockaddrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } } if (isc_sockaddr_pf(sockaddrp) == AF_INET) { @@ -2115,12 +2176,15 @@ portavailable(dns_dispatchmgr_t *mgr, isc_socket_t *sock, ports = mgr->v6ports; nports = mgr->nv6ports; } - if (ports == NULL) + if (ports == NULL) { goto unlock; + } port = isc_sockaddr_getport(sockaddrp); - if (bsearch(&port, ports, nports, sizeof(in_port_t), port_cmp) != NULL) + if (bsearch(&port, ports, nports, sizeof(in_port_t), port_cmp) != + NULL) { available = true; + } unlock: PORTBUFUNLOCK(mgr); @@ -2137,8 +2201,9 @@ local_addr_match(dns_dispatch_t *disp, const isc_sockaddr_t *addr) REQUIRE(disp->socket != NULL); - if (addr == NULL) + if (addr == NULL) { return (true); + } /* * Don't match wildcard ports unless the port is available in the @@ -2154,19 +2219,23 @@ local_addr_match(dns_dispatch_t *disp, const isc_sockaddr_t *addr) * Check if we match the binding . * Wildcard ports match/fail here. */ - if (isc_sockaddr_equal(&disp->local, addr)) + if (isc_sockaddr_equal(&disp->local, addr)) { return (true); - if (isc_sockaddr_getport(addr) == 0) + } + if (isc_sockaddr_getport(addr) == 0) { return (false); + } /* * Check if we match a bound wildcard port . */ - if (!isc_sockaddr_eqaddr(&disp->local, addr)) + if (!isc_sockaddr_eqaddr(&disp->local, addr)) { return (false); + } result = isc_socket_getsockname(disp->socket, &sockaddr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } return (isc_sockaddr_equal(&sockaddr, addr)); } @@ -2200,8 +2269,9 @@ dispatch_find(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *local, LOCK(&disp->lock); if ((disp->shutting_down == 0) && ATTRMATCH(disp->attributes, attributes, mask) && - local_addr_match(disp, local)) + local_addr_match(disp, local)) { break; + } UNLOCK(&disp->lock); disp = ISC_LIST_NEXT(disp, link); } @@ -2245,8 +2315,9 @@ qid_allocate(dns_dispatchmgr_t *mgr, unsigned int buckets, for (i = 0; i < buckets; i++) { ISC_LIST_INIT(qid->qid_table[i]); - if (qid->sock_table != NULL) + if (qid->sock_table != NULL) { ISC_LIST_INIT(qid->sock_table[i]); + } } qid->qid_nbuckets = buckets; @@ -2297,8 +2368,9 @@ dispatch_allocate(dns_dispatchmgr_t *mgr, unsigned int maxrequests, */ disp = isc_mempool_get(mgr->dpool); - if (disp == NULL) + if (disp == NULL) { return (ISC_R_NOMEMORY); + } disp->magic = 0; disp->mgr = mgr; @@ -2378,8 +2450,9 @@ dispatch_free(dns_dispatch_t **dispp) isc_mempool_put(mgr->depool, disp->failsafe_ev); disp->failsafe_ev = NULL; - if (disp->qid != NULL) + if (disp->qid != NULL) { qid_destroy(mgr->mctx, &disp->qid); + } if (disp->port_table != NULL) { for (int i = 0; i < DNS_DISPATCH_PORTTABLESIZE; i++) { @@ -2390,8 +2463,9 @@ dispatch_free(dns_dispatch_t **dispp) DNS_DISPATCH_PORTTABLESIZE); } - if (disp->portpool != NULL) + if (disp->portpool != NULL) { isc_mempool_destroy(&disp->portpool); + } disp->mgr = NULL; isc_mutex_destroy(&disp->lock); @@ -2418,8 +2492,9 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock, REQUIRE((attributes & DNS_DISPATCHATTR_TCP) != 0); REQUIRE((attributes & DNS_DISPATCHATTR_UDP) == 0); - if (destaddr == NULL) + if (destaddr == NULL) { attributes |= DNS_DISPATCHATTR_PRIVATE; /* XXXMLG */ + } LOCK(&mgr->lock); @@ -2435,8 +2510,9 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock, } result = qid_allocate(mgr, buckets, increment, &disp->qid, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto deallocate_dispatch; + } disp->socktype = isc_sockettype_tcp; disp->socket = NULL; @@ -2447,8 +2523,9 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock, disp->ntasks = 1; disp->task[0] = NULL; result = isc_task_create(taskmgr, 50, &disp->task[0]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto kill_socket; + } disp->ctlevent = isc_event_allocate(mgr->mctx, disp, DNS_EVENT_DISPATCHCONTROL, @@ -2472,11 +2549,13 @@ dns_dispatch_createtcp(dns_dispatchmgr_t *mgr, isc_socket_t *sock, break; } } - } else + } else { disp->local = *localaddr; + } - if (destaddr != NULL) + if (destaddr != NULL) { disp->peer = *destaddr; + } /* * Append it to the dispatcher list. @@ -2531,9 +2610,10 @@ dns_dispatch_gettcp(dns_dispatchmgr_t *mgr, const isc_sockaddr_t *destaddr, isc_sockaddr_eqaddr(localaddr, &disp->local))) { result = isc_socket_getsockname(disp->socket, &sockname); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_socket_getpeername(disp->socket, &peeraddr); + } if (result == ISC_R_SUCCESS && isc_sockaddr_equal(destaddr, &peeraddr) && (localaddr == NULL || @@ -2603,8 +2683,9 @@ dns_dispatch_getudp_dup(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr, result = dns_dispatchmgr_setudp(mgr, buffersize, maxbuffers, maxrequests, buckets, increment); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } LOCK(&mgr->lock); @@ -2621,17 +2702,19 @@ dns_dispatch_getudp_dup(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr, if (result == ISC_R_SUCCESS) { disp->refcount++; - if (disp->maxrequests < maxrequests) + if (disp->maxrequests < maxrequests) { disp->maxrequests = maxrequests; + } if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) == 0 && (attributes & DNS_DISPATCHATTR_NOLISTEN) != 0) { disp->attributes |= DNS_DISPATCHATTR_NOLISTEN; - if (disp->recv_pending != 0) + if (disp->recv_pending != 0) { isc_socket_cancel(disp->socket, disp->task[0], ISC_SOCKCANCEL_RECV); + } } UNLOCK(&disp->lock); @@ -2682,7 +2765,7 @@ dns_dispatch_getudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr, #ifndef DNS_DISPATCH_HELD #define DNS_DISPATCH_HELD 20U -#endif +#endif /* ifndef DNS_DISPATCH_HELD */ static isc_result_t get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, @@ -2716,8 +2799,9 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, nports = disp->mgr->nv6ports; ports = disp->mgr->v6ports; } - if (nports == 0) + if (nports == 0) { return (ISC_R_ADDRNOTAVAIL); + } for (i = 0; i < 1024; i++) { in_port_t prt; @@ -2730,8 +2814,10 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, * Continue if the port choosen is already in use * or the OS has reserved it. */ - if (result == ISC_R_NOPERM || result == ISC_R_ADDRINUSE) + if (result == ISC_R_NOPERM || + result == ISC_R_ADDRINUSE) { continue; + } disp->localport = prt; *sockp = sock; return (result); @@ -2747,8 +2833,9 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, ISC_SOCKET_REUSEADDRESS, &sock, dup_socket, duponly); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *sockp = sock; + } return (result); } @@ -2758,16 +2845,19 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, for (j = 0; j < 0xffffU; j++) { result = open_socket(sockmgr, localaddr, 0, &sock, NULL, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto end; - else if (portavailable(mgr, sock, NULL)) + } else if (portavailable(mgr, sock, NULL)) { break; - if (held[i] != NULL) + } + if (held[i] != NULL) { isc_socket_detach(&held[i]); + } held[i++] = sock; sock = NULL; - if (i == DNS_DISPATCH_HELD) + if (i == DNS_DISPATCH_HELD) { i = 0; + } } if (j == 0xffffU) { mgr_log(mgr, ISC_LOG_ERROR, @@ -2781,8 +2871,9 @@ get_udpsocket(dns_dispatchmgr_t *mgr, dns_dispatch_t *disp, end: for (i = 0; i < DNS_DISPATCH_HELD; i++) { - if (held[i] != NULL) + if (held[i] != NULL) { isc_socket_detach(&held[i]); + } } return (result); @@ -2830,7 +2921,6 @@ dispatch_createudp(dns_dispatchmgr_t *mgr, isc_socketmgr_t *sockmgr, " UDP dispatch for %s with socket fd %d", addrbuf, isc_socket_getfd(sock)); } - } else { isc_sockaddr_t sa_any; @@ -2969,9 +3059,10 @@ dns_dispatch_detach(dns_dispatch_t **dispp) INSIST(disp->refcount > 0); disp->refcount--; if (disp->refcount == 0) { - if (disp->recv_pending > 0) + if (disp->recv_pending > 0) { isc_socket_cancel(disp->socket, disp->task[0], ISC_SOCKCANCEL_RECV); + } for (dispsock = ISC_LIST_HEAD(disp->activesockets); dispsock != NULL; dispsock = ISC_LIST_NEXT(dispsock, link)) { @@ -2985,8 +3076,9 @@ dns_dispatch_detach(dns_dispatch_t **dispp) killit = destroy_disp_ok(disp); UNLOCK(&disp->lock); - if (killit) + if (killit) { isc_task_send(disp->task[0], &disp->ctlevent); + } } isc_result_t @@ -3011,8 +3103,9 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options, REQUIRE(dest != NULL); REQUIRE(resp != NULL && *resp == NULL); REQUIRE(idp != NULL); - if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0) + if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0) { REQUIRE(sockmgr != NULL); + } LOCK(&disp->lock); @@ -3100,8 +3193,9 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options, ok = true; break; } - if ((disp->attributes & DNS_DISPATCHATTR_FIXEDID) != 0) + if ((disp->attributes & DNS_DISPATCHATTR_FIXEDID) != 0) { break; + } id += qid->qid_increment; id &= 0x0000ffff; } while (i++ < 64); @@ -3114,8 +3208,9 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options, res = isc_mempool_get(disp->mgr->rpool); if (res == NULL) { - if (dispsocket != NULL) + if (dispsocket != NULL) { destroy_dispsocket(disp, &dispsocket); + } UNLOCK(&disp->lock); return (ISC_R_NOMEMORY); } @@ -3132,8 +3227,9 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options, res->action = action; res->arg = arg; res->dispsocket = dispsocket; - if (dispsocket != NULL) + if (dispsocket != NULL) { dispsocket->resp = res; + } res->item_out = false; ISC_LIST_INIT(res->items); ISC_LINK_INIT(res, link); @@ -3157,8 +3253,9 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options, ISC_LIST_UNLINK(qid->qid_table[bucket], res, link); UNLOCK(&qid->lock); - if (dispsocket != NULL) + if (dispsocket != NULL) { destroy_dispsocket(disp, &dispsocket); + } disp->refcount--; disp->requests--; @@ -3175,16 +3272,18 @@ dns_dispatch_addresponse(dns_dispatch_t *disp, unsigned int options, } } - if (dispsocket != NULL) + if (dispsocket != NULL) { ISC_LIST_APPEND(disp->activesockets, dispsocket, link); + } UNLOCK(&disp->lock); *idp = id; *resp = res; - if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0) + if ((disp->attributes & DNS_DISPATCHATTR_EXCLUSIVE) != 0) { INSIST(res->dispsocket != NULL); + } return (ISC_R_SUCCESS); } @@ -3224,8 +3323,9 @@ dns_dispatch_getnext(dns_dispentry_t *resp, dns_dispatchevent_t **sockevent) REQUIRE(resp->item_out == true); resp->item_out = false; - if (ev->buffer.base != NULL) + if (ev->buffer.base != NULL) { free_buffer(disp, ev->buffer.base, ev->buffer.length); + } free_devent(disp, ev); if (disp->shutting_down == 1) { @@ -3293,9 +3393,10 @@ dns_dispatch_removeresponse(dns_dispentry_t ** resp, INSIST(disp->refcount > 0); disp->refcount--; if (disp->refcount == 0) { - if (disp->recv_pending > 0) + if (disp->recv_pending > 0) { isc_socket_cancel(disp->socket, disp->task[0], ISC_SOCKCANCEL_RECV); + } for (dispsock = ISC_LIST_HEAD(disp->activesockets); dispsock != NULL; dispsock = ISC_LIST_NEXT(dispsock, link)) { @@ -3329,8 +3430,9 @@ dns_dispatch_removeresponse(dns_dispentry_t ** resp, if (ev != NULL) { REQUIRE(res->item_out == true); res->item_out = false; - if (ev->buffer.base != NULL) + if (ev->buffer.base != NULL) { free_buffer(disp, ev->buffer.base, ev->buffer.length); + } free_devent(disp, ev); } @@ -3349,22 +3451,25 @@ dns_dispatch_removeresponse(dns_dispentry_t ** resp, ev = ISC_LIST_HEAD(res->items); while (ev != NULL) { ISC_LIST_UNLINK(res->items, ev, ev_link); - if (ev->buffer.base != NULL) + if (ev->buffer.base != NULL) { free_buffer(disp, ev->buffer.base, ev->buffer.length); + } free_devent(disp, ev); ev = ISC_LIST_HEAD(res->items); } res->magic = 0; isc_mempool_put(disp->mgr->rpool, res); - if (disp->shutting_down == 1) + if (disp->shutting_down == 1) { do_cancel(disp); - else + } else { (void)startrecv(disp, NULL); + } killit = destroy_disp_ok(disp); UNLOCK(&disp->lock); - if (killit) + if (killit) { isc_task_send(disp->task[0], &disp->ctlevent); + } } /* @@ -3377,8 +3482,9 @@ do_cancel(dns_dispatch_t *disp) dns_dispentry_t * resp; dns_qid_t * qid; - if (disp->shutdown_out == 1) + if (disp->shutdown_out == 1) { return; + } qid = DNS_QID(disp); @@ -3388,14 +3494,16 @@ do_cancel(dns_dispatch_t *disp) */ LOCK(&qid->lock); for (resp = linear_first(qid); resp != NULL && resp->item_out; - /* Empty. */) + /* Empty. */) { resp = linear_next(qid, resp); + } /* * No one to send the cancel event to, so nothing to do. */ - if (resp == NULL) + if (resp == NULL) { goto unlock; + } /* * Send the shutdown failsafe event to this resp. @@ -3428,10 +3536,11 @@ dns_dispatch_getentrysocket(dns_dispentry_t *resp) { REQUIRE(VALID_RESPONSE(resp)); - if (resp->dispsocket != NULL) + if (resp->dispsocket != NULL) { return (resp->dispsocket->socket); - else + } else { return (NULL); + } } isc_result_t @@ -3506,9 +3615,10 @@ dns_dispatch_changeattributes(dns_dispatch_t *disp, unsigned int attributes, 0 && (attributes & DNS_DISPATCHATTR_NOLISTEN) != 0) { disp->attributes |= DNS_DISPATCHATTR_NOLISTEN; - if (disp->recv_pending != 0) + if (disp->recv_pending != 0) { isc_socket_cancel(disp->socket, disp->task[0], ISC_SOCKCANCEL_RECV); + } } } @@ -3526,8 +3636,9 @@ dns_dispatch_importrecv(dns_dispatch_t *disp, isc_event_t *event) REQUIRE(VALID_DISPATCH(disp)); REQUIRE(event != NULL); - if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) == 0) + if ((disp->attributes & DNS_DISPATCHATTR_NOLISTEN) == 0) { return; + } sevent = (isc_socketevent_t *)event; INSIST(sevent->n <= disp->mgr->buffersize); @@ -3560,14 +3671,16 @@ dns_dispatchset_get(dns_dispatchset_t *dset) dns_dispatch_t *disp; /* check that dispatch set is configured */ - if (dset == NULL || dset->ndisp == 0) + if (dset == NULL || dset->ndisp == 0) { return (NULL); + } LOCK(&dset->lock); disp = dset->dispatches[dset->cur]; dset->cur++; - if (dset->cur == dset->ndisp) + if (dset->cur == dset->ndisp) { dset->cur = 0; + } UNLOCK(&dset->lock); return (disp); @@ -3610,8 +3723,9 @@ dns_dispatchset_create(isc_mem_t *mctx, isc_socketmgr_t *sockmgr, mgr, sockmgr, taskmgr, &source->local, source->maxrequests, source->attributes, &dset->dispatches[i], source->socket); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } UNLOCK(&mgr->lock); @@ -3622,11 +3736,13 @@ dns_dispatchset_create(isc_mem_t *mctx, isc_socketmgr_t *sockmgr, fail: UNLOCK(&mgr->lock); - for (j = 0; j < i; j++) + for (j = 0; j < i; j++) { dns_dispatch_detach(&(dset->dispatches[j])); + } isc_mem_put(mctx, dset->dispatches, sizeof(dns_dispatch_t *) * n); - if (dset->mctx == mctx) + if (dset->mctx == mctx) { isc_mem_detach(&dset->mctx); + } isc_mutex_destroy(&dset->lock); isc_mem_put(mctx, dset, sizeof(dns_dispatchset_t)); @@ -3657,8 +3773,9 @@ dns_dispatchset_destroy(dns_dispatchset_t **dsetp) dset = *dsetp; *dsetp = NULL; - for (i = 0; i < dset->ndisp; i++) + for (i = 0; i < dset->ndisp; i++) { dns_dispatch_detach(&(dset->dispatches[i])); + } isc_mem_put(dset->mctx, dset->dispatches, sizeof(dns_dispatch_t *) * dset->ndisp); isc_mutex_destroy(&dset->lock); @@ -3692,4 +3809,4 @@ dns_dispatchmgr_dump(dns_dispatchmgr_t *mgr) { disp = ISC_LIST_NEXT(disp, link); } } -#endif +#endif /* if 0 */ diff --git a/lib/dns/dlz.c b/lib/dns/dlz.c index c7b39b7a00..f9523c9a60 100644 --- a/lib/dns/dlz.c +++ b/lib/dns/dlz.c @@ -145,8 +145,9 @@ dns_dlzallowzonexfr(dns_view_t *view, const dns_name_t *name, } } - if (result == ISC_R_NOTIMPLEMENTED) + if (result == ISC_R_NOTIMPLEMENTED) { result = ISC_R_NOTFOUND; + } return (result); } @@ -203,8 +204,9 @@ dns_dlzcreate(isc_mem_t *mctx, const char *dlzname, const char *drivername, ISC_LINK_INIT(db, link); db->implementation = impinfo; - if (dlzname != NULL) + if (dlzname != NULL) { db->dlzname = isc_mem_strdup(mctx, dlzname); + } /* Create a new database using implementation 'drivername'. */ result = ((impinfo->methods->create)(mctx, dlzname, argc, argv, @@ -250,12 +252,14 @@ dns_dlzdestroy(dns_dlzdb_t **dbp) db = *dbp; *dbp = NULL; - if (db->ssutable != NULL) + if (db->ssutable != NULL) { dns_ssutable_detach(&db->ssutable); + } /* call the drivers destroy method */ - if (db->dlzname != NULL) + if (db->dlzname != NULL) { isc_mem_free(db->mctx, db->dlzname); + } destroy = db->implementation->methods->destroy; (*destroy)(db->implementation->driverarg, db->dbdata); /* return memory and detach */ @@ -429,8 +433,9 @@ dns_dlz_writeablezone(dns_view_t *view, dns_dlzdb_t *dlzdb, dns_fixedname_init(&fixorigin); result = dns_name_fromtext(dns_fixedname_name(&fixorigin), &buffer, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } origin = dns_fixedname_name(&fixorigin); if (!dlzdb->search) { @@ -454,11 +459,13 @@ dns_dlz_writeablezone(dns_view_t *view, dns_dlzdb_t *dlzdb, /* Create it */ result = dns_zone_create(&zone, view->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_zone_setorigin(zone, origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_zone_setview(zone, view); dns_zone_setadded(zone, true); @@ -466,20 +473,23 @@ dns_dlz_writeablezone(dns_view_t *view, dns_dlzdb_t *dlzdb, if (dlzdb->ssutable == NULL) { result = dns_ssutable_createdlz(dlzdb->mctx, &dlzdb->ssutable, dlzdb); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } dns_zone_setssutable(zone, dlzdb->ssutable); result = dlzdb->configure_callback(view, dlzdb, zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_view_addzone(view, zone); cleanup: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -500,8 +510,9 @@ dns_dlzconfigure(dns_view_t *view, dns_dlzdb_t *dlzdb, impl = dlzdb->implementation; - if (impl->methods->configure == NULL) + if (impl->methods->configure == NULL) { return (ISC_R_SUCCESS); + } dlzdb->configure_callback = callback; diff --git a/lib/dns/dns64.c b/lib/dns/dns64.c index 07b81e5f8b..eda30ac129 100644 --- a/lib/dns/dns64.c +++ b/lib/dns/dns64.c @@ -68,26 +68,31 @@ dns_dns64_create(isc_mem_t *mctx, const isc_netaddr_t *prefix, REQUIRE(prefix->family == AF_INET6); nbytes = prefixlen / 8 + 4; /* Bits 64-71 are zeros. rfc6052.txt */ - if (prefixlen >= 32 && prefixlen <= 64) + if (prefixlen >= 32 && prefixlen <= 64) { nbytes++; + } REQUIRE(memcmp(suffix->type.in6.s6_addr, zeros, nbytes) == 0); } dns64 = isc_mem_get(mctx, sizeof(dns_dns64_t)); memset(dns64->bits, 0, sizeof(dns64->bits)); memmove(dns64->bits, prefix->type.in6.s6_addr, prefixlen / 8); - if (suffix != NULL) + if (suffix != NULL) { memmove(dns64->bits + nbytes, suffix->type.in6.s6_addr + nbytes, 16 - nbytes); + } dns64->clients = NULL; - if (clients != NULL) + if (clients != NULL) { dns_acl_attach(clients, &dns64->clients); + } dns64->mapped = NULL; - if (mapped != NULL) + if (mapped != NULL) { dns_acl_attach(mapped, &dns64->mapped); + } dns64->excluded = NULL; - if (excluded != NULL) + if (excluded != NULL) { dns_acl_attach(excluded, &dns64->excluded); + } dns64->prefixlen = prefixlen; dns64->flags = flags; ISC_LINK_INIT(dns64, link); @@ -109,12 +114,15 @@ dns_dns64_destroy(dns_dns64_t **dns64p) REQUIRE(!ISC_LINK_LINKED(dns64, link)); - if (dns64->clients != NULL) + if (dns64->clients != NULL) { dns_acl_detach(&dns64->clients); - if (dns64->mapped != NULL) + } + if (dns64->mapped != NULL) { dns_acl_detach(&dns64->mapped); - if (dns64->excluded != NULL) + } + if (dns64->excluded != NULL) { dns_acl_detach(&dns64->excluded); + } isc_mem_putanddetach(&dns64->mctx, dns64, sizeof(*dns64)); } @@ -128,20 +136,24 @@ dns_dns64_aaaafroma(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, int match; if ((dns64->flags & DNS_DNS64_RECURSIVE_ONLY) != 0 && - (flags & DNS_DNS64_RECURSIVE) == 0) + (flags & DNS_DNS64_RECURSIVE) == 0) { return (DNS_R_DISALLOWED); + } if ((dns64->flags & DNS_DNS64_BREAK_DNSSEC) == 0 && - (flags & DNS_DNS64_DNSSEC) != 0) + (flags & DNS_DNS64_DNSSEC) != 0) { return (DNS_R_DISALLOWED); + } if (dns64->clients != NULL) { result = dns_acl_match(reqaddr, reqsigner, dns64->clients, env, &match, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (match <= 0) + } + if (match <= 0) { return (DNS_R_DISALLOWED); + } } if (dns64->mapped != NULL) { @@ -152,10 +164,12 @@ dns_dns64_aaaafroma(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, isc_netaddr_fromin(&netaddr, &ina); result = dns_acl_match(&netaddr, NULL, dns64->mapped, env, &match, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (match <= 0) + } + if (match <= 0) { return (DNS_R_DISALLOWED); + } } nbytes = dns64->prefixlen / 8; @@ -163,14 +177,16 @@ dns_dns64_aaaafroma(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, /* Copy prefix. */ memmove(aaaa, dns64->bits, nbytes); /* Bits 64-71 are zeros. rfc6052.txt */ - if (nbytes == 8) + if (nbytes == 8) { aaaa[nbytes++] = 0; + } /* Copy mapped address. */ for (i = 0; i < 4U; i++) { aaaa[nbytes++] = a[i]; /* Bits 64-71 are zeros. rfc6052.txt */ - if (nbytes == 8) + if (nbytes == 8) { aaaa[nbytes++] = 0; + } } /* Copy suffix. */ memmove(aaaa + nbytes, dns64->bits + nbytes, 16 - nbytes); @@ -213,17 +229,20 @@ dns_dns64_aaaaok(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, REQUIRE(rdataset != NULL); REQUIRE(rdataset->type == dns_rdatatype_aaaa); REQUIRE(rdataset->rdclass == dns_rdataclass_in); - if (aaaaok != NULL) + if (aaaaok != NULL) { REQUIRE(aaaaoklen == dns_rdataset_count(rdataset)); + } for (; dns64 != NULL; dns64 = ISC_LIST_NEXT(dns64, link)) { if ((dns64->flags & DNS_DNS64_RECURSIVE_ONLY) != 0 && - (flags & DNS_DNS64_RECURSIVE) == 0) + (flags & DNS_DNS64_RECURSIVE) == 0) { continue; + } if ((dns64->flags & DNS_DNS64_BREAK_DNSSEC) == 0 && - (flags & DNS_DNS64_DNSSEC) != 0) + (flags & DNS_DNS64_DNSSEC) != 0) { continue; + } /* * Work out if this dns64 structure applies to this client. */ @@ -231,15 +250,18 @@ dns_dns64_aaaaok(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, result = dns_acl_match(reqaddr, reqsigner, dns64->clients, env, &match, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; - if (match <= 0) + } + if (match <= 0) { continue; + } } if (!found && aaaaok != NULL) { - for (i = 0; i < aaaaoklen; i++) + for (i = 0; i < aaaaoklen; i++) { aaaaok[i] = false; + } } found = true; @@ -249,10 +271,12 @@ dns_dns64_aaaaok(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, */ if (dns64->excluded == NULL) { answer = true; - if (aaaaok == NULL) + if (aaaaok == NULL) { goto done; - for (i = 0; i < aaaaoklen; i++) + } + for (i = 0; i < aaaaoklen; i++) { aaaaok[i] = true; + } goto done; } @@ -272,26 +296,30 @@ dns_dns64_aaaaok(const dns_dns64_t *dns64, const isc_netaddr_t *reqaddr, &match, NULL); if (result == ISC_R_SUCCESS && match <= 0) { answer = true; - if (aaaaok == NULL) + if (aaaaok == NULL) { goto done; + } aaaaok[i] = true; ok++; } - } else + } else { ok++; + } i++; } /* * Are all addresses ok? */ - if (aaaaok != NULL && ok == aaaaoklen) + if (aaaaok != NULL && ok == aaaaoklen) { goto done; + } } done: if (!found && aaaaok != NULL) { - for (i = 0; i < aaaaoklen; i++) + for (i = 0; i < aaaaoklen; i++) { aaaaok[i] = true; + } } return (found ? answer : true); } diff --git a/lib/dns/dnsrps.c b/lib/dns/dnsrps.c index 4fae740749..0f88fb2b46 100644 --- a/lib/dns/dnsrps.c +++ b/lib/dns/dnsrps.c @@ -93,8 +93,9 @@ dnsrps_log_fnc(librpz_log_level_t level, void *ctxt, const char *buf) /* Setting librpz_log_level in the configuration overrides the * BIND9 logging levels. */ if (level > LIBRPZ_LOG_TRACE1 && - level <= librpz->log_level_val(LIBRPZ_LOG_INVALID)) + level <= librpz->log_level_val(LIBRPZ_LOG_INVALID)) { level = LIBRPZ_LOG_TRACE1; + } switch (level) { case LIBRPZ_LOG_FATAL: @@ -146,8 +147,9 @@ dns_dnsrps_server_create(void) * Complain later if and when librpz is needed for a view with * "dnsrps-enable yse" (including the default view). */ - if (librpz == NULL) + if (librpz == NULL) { return (ISC_R_SUCCESS); + } isc_mutex_init(&dnsrps_mutex); @@ -172,19 +174,21 @@ dns_dnsrps_server_create(void) void dns_dnsrps_server_destroy(void) { - if (clist != NULL) + if (clist != NULL) { librpz->clist_detach(&clist); + } #ifdef LIBRPZ_USE_DLOPEN if (librpz != NULL) { INSIST(librpz_handle != NULL); - if (dlclose(librpz_handle) != 0) + if (dlclose(librpz_handle) != 0) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RPZ, DNS_LOGMODULE_RBTDB, DNS_RPZ_ERROR_LEVEL, "dnsrps: dlclose(): %s", dlerror()); + } librpz_handle = NULL; } -#endif +#endif /* ifdef LIBRPZ_USE_DLOPEN */ } /* @@ -220,8 +224,9 @@ dns_dnsrps_connect(dns_rpz_zones_t *rpzs) { librpz_emsg_t emsg; - if (rpzs == NULL || !rpzs->p.dnsrps_enabled) + if (rpzs == NULL || !rpzs->p.dnsrps_enabled) { return (ISC_R_SUCCESS); + } /* * Fail only if we failed to link to librpz. @@ -389,8 +394,9 @@ rpsdb_detach(dns_db_t **dbp) /* * Simple count because only one thread uses a rpsdb_t. */ - if (--rpsdb->ref_cnt != 0) + if (--rpsdb->ref_cnt != 0) { return; + } librpz->rsp_detach(&rpsdb->rsp); rpsdb->common.impmagic = 0; @@ -442,10 +448,11 @@ rpsdb_findnode(dns_db_t *db, const dns_name_t *name, bool create, * One is the origin to support query_addsoa() in bin/named/query.c. * The other contains rewritten RRs. */ - if (dns_name_equal(name, &db->origin)) + if (dns_name_equal(name, &db->origin)) { *nodep = &rpsdb->origin_node; - else + } else { *nodep = &rpsdb->data_node; + } dbp = NULL; rpsdb_attach(db, &dbp); @@ -516,10 +523,12 @@ rpsdb_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, REQUIRE(VALID_RPSDB(rpsdb)); if (node == &rpsdb->origin_node) { - if (type == dns_rdatatype_any) + if (type == dns_rdatatype_any) { return (ISC_R_SUCCESS); - if (type == dns_rdatatype_soa) + } + if (type == dns_rdatatype_soa) { return (rpsdb_bind_soa(rdataset, rpsdb)); + } return (DNS_R_NXRRSET); } @@ -550,14 +559,16 @@ rpsdb_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, break; } - if (type == dns_rdatatype_soa) + if (type == dns_rdatatype_soa) { return (rpsdb_bind_soa(rdataset, rpsdb)); + } /* * There is little to do for an ANY query. */ - if (type == dns_rdatatype_any) + if (type == dns_rdatatype_any) { return (ISC_R_SUCCESS); + } /* * Reset to the start of the RRs. @@ -581,8 +592,9 @@ rpsdb_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, */ count = 0; do { - if (type == foundtype || type == dns_rdatatype_any) + if (type == foundtype || type == dns_rdatatype_any) { ++count; + } if (!librpz->rsp_rr(&emsg, &foundtype, NULL, NULL, NULL, &rpsdb->result, rpsdb->qname->ndata, @@ -591,8 +603,9 @@ rpsdb_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, return (DNS_R_SERVFAIL); } } while (foundtype != dns_rdatatype_none); - if (count == 0) + if (count == 0) { return (DNS_R_NXRRSET); + } rpsdb_bind_rdataset(rdataset, count, rpsdb->result.next_rr, type, class, ttl, rpsdb); return (ISC_R_SUCCESS); @@ -709,8 +722,9 @@ rpsdb_rdataset_next(dns_rdataset_t *rdataset) * SOAs differ. */ if (rdataset->type == dns_rdatatype_soa) { - if (RD_NEXT_RR(rdataset) == LIBRPZ_IDX_NULL) + if (RD_NEXT_RR(rdataset) == LIBRPZ_IDX_NULL) { return (ISC_R_NOMORE); + } RD_NEXT_RR(rdataset) = LIBRPZ_IDX_NULL; if (!librpz->rsp_soa(&emsg, NULL, &rr, NULL, &rpsdb->result, rpsdb->rsp)) { @@ -734,8 +748,9 @@ rpsdb_rdataset_next(dns_rdataset_t *rdataset) RD_NEXT_RR(rdataset) = rpsdb->result.next_rr; return (ISC_R_SUCCESS); } - if (type == dns_rdatatype_none) + if (type == dns_rdatatype_none) { return (ISC_R_NOMORE); + } free(rr); } } @@ -758,10 +773,11 @@ rpsdb_rdataset_first(dns_rdataset_t *rdataset) librpz->log(LIBRPZ_LOG_ERROR, NULL, "%s", emsg.c); return (DNS_R_SERVFAIL); } - if (rdataset->type == dns_rdatatype_soa) + if (rdataset->type == dns_rdatatype_soa) { RD_NEXT_RR(rdataset) = LIBRPZ_IDX_BAD; - else + } else { RD_NEXT_RR(rdataset) = rpsdb->result.next_rr; + } return (rpsdb_rdataset_next(rdataset)); } @@ -867,8 +883,9 @@ rpsdb_rdatasetiter_next(dns_rdatasetiter_t *iter) return (DNS_R_SERVFAIL); } if (type == dns_rdatatype_none) { - if (next_type == dns_rdatatype_none) + if (next_type == dns_rdatatype_none) { return (ISC_R_NOMORE); + } rpsdb_iter->type = next_type; rpsdb_iter->class = next_class; return (ISC_R_SUCCESS); @@ -877,8 +894,9 @@ rpsdb_rdatasetiter_next(dns_rdatasetiter_t *iter) * Skip RRs with the current class and type or before. */ if (rpsdb_iter->class > class || - (rpsdb_iter->class = class && rpsdb_iter->type >= type)) + (rpsdb_iter->class = class && rpsdb_iter->type >= type)) { continue; + } if (next_type == dns_rdatatype_none || next_class > class || (next_class == class && next_type > type)) { /* diff --git a/lib/dns/dnssec.c b/lib/dns/dnssec.c index 359dd8996c..4a8b2ee822 100644 --- a/lib/dns/dnssec.c +++ b/lib/dns/dnssec.c @@ -77,8 +77,9 @@ digest_callback(void *arg, isc_region_t *data) static inline void inc_stat(isc_statscounter_t counter) { - if (dns_dnssec_stats != NULL) + if (dns_dnssec_stats != NULL) { isc_stats_increment(dns_dnssec_stats, counter); + } } /* @@ -168,8 +169,9 @@ digest_sig(dst_context_t *ctx, bool downcase, dns_rdata_t *sigrdata, r.length = 18; ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } if (downcase) { dns_fixedname_init(&fname); @@ -177,8 +179,9 @@ digest_sig(dst_context_t *ctx, bool downcase, dns_rdata_t *sigrdata, dns_fixedname_name(&fname), NULL) == ISC_R_SUCCESS); dns_name_toregion(dns_fixedname_name(&fname), &r); - } else + } else { dns_name_toregion(&rrsig->signer, &r); + } return (dst_context_adddata(ctx, &r)); } @@ -212,8 +215,9 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, REQUIRE(mctx != NULL); REQUIRE(sigrdata != NULL); - if (*inception >= *expire) + if (*inception >= *expire) { return (DNS_R_INVALIDTIME); + } /* * Is the key allowed to sign data? @@ -244,15 +248,17 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, sig.covered = set->type; sig.algorithm = dst_key_alg(key); sig.labels = dns_name_countlabels(name) - 1; - if (dns_name_iswildcard(name)) + if (dns_name_iswildcard(name)) { sig.labels--; + } sig.originalttl = set->ttl; sig.timesigned = *inception; sig.timeexpire = *expire; sig.keyid = dst_key_id(key); ret = dst_key_sigsize(key, &sigsize); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } sig.siglen = sigsize; /* * The actual contents of sig.signature are not important yet, since @@ -265,20 +271,23 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, dns_rdata_init(&tmpsigrdata); ret = dns_rdata_fromstruct(&tmpsigrdata, sig.common.rdclass, sig.common.rdtype, &sig, databuf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_databuf; + } ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, true, 0, &ctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_databuf; + } /* * Digest the SIG rdata. */ ret = digest_sig(ctx, false, &tmpsigrdata, &sig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } dns_fixedname_init(&fnewname); RUNTIME_CHECK(dns_name_downcase(name, dns_fixedname_name(&fnewname), @@ -296,8 +305,9 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, isc_buffer_putuint32(&envbuf, set->ttl); ret = rdataset_to_sortedarray(set, mctx, &rdatas, &nrdatas); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } isc_buffer_usedregion(&envbuf, &r); for (i = 0; i < nrdatas; i++) { @@ -308,15 +318,18 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, /* * Skip duplicates. */ - if (i > 0 && dns_rdata_compare(&rdatas[i], &rdatas[i - 1]) == 0) + if (i > 0 && + dns_rdata_compare(&rdatas[i], &rdatas[i - 1]) == 0) { continue; + } /* * Digest the envelope. */ ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } /* * Digest the length of the rdata. @@ -326,21 +339,24 @@ dns_dnssec_sign(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, isc_buffer_putuint16(&lenbuf, (uint16_t)rdatas[i].length); isc_buffer_usedregion(&lenbuf, &lenr); ret = dst_context_adddata(ctx, &lenr); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } /* * Digest the rdata. */ ret = dns_rdata_digest(&rdatas[i], digest_callback, ctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } } isc_buffer_init(&sigbuf, sig.signature, sig.siglen); ret = dst_context_sign(ctx, &sigbuf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } isc_buffer_usedregion(&sigbuf, &r); if (r.length != sig.siglen) { ret = ISC_R_NOSPACE; @@ -387,11 +403,13 @@ dns_dnssec_verify(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, REQUIRE(sigrdata != NULL && sigrdata->type == dns_rdatatype_rrsig); ret = dns_rdata_tostruct(sigrdata, &sig, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } - if (set->type != sig.covered) + if (set->type != sig.covered) { return (DNS_R_SIGINVALID); + } if (isc_serial_lt(sig.timeexpire, sig.timesigned)) { inc_stat(dns_dnssecstats_fail); @@ -431,7 +449,7 @@ dns_dnssec_verify(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, inc_stat(dns_dnssecstats_fail); return (DNS_R_SIGINVALID); } - /* FALLTHROUGH */ + /* FALLTHROUGH */ default: if (!dns_name_issubdomain(name, &sig.signer)) { inc_stat(dns_dnssecstats_fail); @@ -456,15 +474,17 @@ dns_dnssec_verify(const dns_name_t *name, dns_rdataset_t *set, dst_key_t *key, again: ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, maxbits, &ctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_struct; + } /* * Digest the SIG rdata (not including the signature). */ ret = digest_sig(ctx, downcase, sigrdata, &sig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * If the name is an expanded wildcard, use the wildcard name. @@ -473,9 +493,10 @@ again: labels = dns_name_countlabels(name) - 1; RUNTIME_CHECK(dns_name_downcase(name, dns_fixedname_name(&fnewname), NULL) == ISC_R_SUCCESS); - if (labels - sig.labels > 0) + if (labels - sig.labels > 0) { dns_name_split(dns_fixedname_name(&fnewname), sig.labels + 1, NULL, dns_fixedname_name(&fnewname)); + } dns_name_toregion(dns_fixedname_name(&fnewname), &r); @@ -487,16 +508,18 @@ again: isc_buffer_putuint8(&envbuf, 1); isc_buffer_putuint8(&envbuf, '*'); memmove(data + 2, r.base, r.length); - } else + } else { memmove(data, r.base, r.length); + } isc_buffer_add(&envbuf, r.length); isc_buffer_putuint16(&envbuf, set->type); isc_buffer_putuint16(&envbuf, set->rdclass); isc_buffer_putuint32(&envbuf, sig.originalttl); ret = rdataset_to_sortedarray(set, mctx, &rdatas, &nrdatas); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } isc_buffer_usedregion(&envbuf, &r); @@ -508,15 +531,18 @@ again: /* * Skip duplicates. */ - if (i > 0 && dns_rdata_compare(&rdatas[i], &rdatas[i - 1]) == 0) + if (i > 0 && + dns_rdata_compare(&rdatas[i], &rdatas[i - 1]) == 0) { continue; + } /* * Digest the envelope. */ ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } /* * Digest the rdata length. @@ -530,11 +556,13 @@ again: * Digest the rdata. */ ret = dst_context_adddata(ctx, &lenr); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } ret = dns_rdata_digest(&rdatas[i], digest_callback, ctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_array; + } } r.base = sig.signature; @@ -549,8 +577,9 @@ again: "signer '%s'", namebuf); inc_stat(dns_dnssecstats_downcase); - } else if (ret == ISC_R_SUCCESS) + } else if (ret == ISC_R_SUCCESS) { inc_stat(dns_dnssecstats_asis); + } cleanup_array: isc_mem_put(mctx, rdatas, nrdatas * sizeof(dns_rdata_t)); @@ -563,18 +592,21 @@ cleanup_context: cleanup_struct: dns_rdata_freestruct(&sig); - if (ret == DST_R_VERIFYFAILURE) + if (ret == DST_R_VERIFYFAILURE) { ret = DNS_R_SIGINVALID; + } - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { inc_stat(dns_dnssecstats_fail); + } if (ret == ISC_R_SUCCESS && labels - sig.labels > 0) { - if (wild != NULL) + if (wild != NULL) { RUNTIME_CHECK(dns_name_concatenate( dns_wildcardname, dns_fixedname_name(&fnewname), wild, NULL) == ISC_R_SUCCESS); + } inc_stat(dns_dnssecstats_wildcard); ret = DNS_R_FROMWILDCARD; } @@ -609,8 +641,9 @@ dns_dnssec_keyactive(dst_key_t *key, isc_stdtime_t now) * Smart signing started with key format 1.3; prior to that, all * keys are assumed active. */ - if (major == 1 && minor <= 2) + if (major == 1 && minor <= 2) { return (true); + } hint_publish = dst_key_is_published(key, now, &publish); hint_zsign = dst_key_is_signing(key, DST_BOOL_ZSK, now, &active); @@ -767,11 +800,13 @@ dns_dnssec_findzonekeys(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, dst_key_setttl(pubkey, rdataset.ttl); if (!is_zone_key(pubkey) || - (dst_key_flags(pubkey) & DNS_KEYTYPE_NOAUTH) != 0) + (dst_key_flags(pubkey) & DNS_KEYTYPE_NOAUTH) != 0) { goto next; + } /* Corrupted .key file? */ - if (!dns_name_equal(name, dst_key_name(pubkey))) + if (!dns_name_equal(name, dst_key_name(pubkey))) { goto next; + } keys[count] = NULL; result = dst_key_fromfile( dst_key_name(pubkey), dst_key_id(pubkey), @@ -846,8 +881,9 @@ dns_dnssec_findzonekeys(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, goto next; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } /* * If a key is marked inactive, skip it @@ -874,26 +910,33 @@ dns_dnssec_findzonekeys(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, } count++; next: - if (pubkey != NULL) + if (pubkey != NULL) { dst_key_free(&pubkey); + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&rdataset); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; - if (count == 0) + } + if (count == 0) { result = ISC_R_NOTFOUND; - else + } else { result = ISC_R_SUCCESS; + } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (pubkey != NULL) + } + if (pubkey != NULL) { dst_key_free(&pubkey); - if (result != ISC_R_SUCCESS) - while (count > 0) + } + if (result != ISC_R_SUCCESS) { + while (count > 0) { dst_key_free(&keys[--count]); + } + } *nkeys = count; return (result); } @@ -920,8 +963,9 @@ dns_dnssec_signmessage(dns_message_t *msg, dst_key_t *key) REQUIRE(msg != NULL); REQUIRE(key != NULL); - if (is_response(msg)) + if (is_response(msg)) { REQUIRE(msg->query.base != NULL); + } mctx = msg->mctx; @@ -968,8 +1012,9 @@ dns_dnssec_signmessage(dns_message_t *msg, dst_key_t *key) /* * If this is a response, digest the query. */ - if (is_response(msg)) + if (is_response(msg)) { RETERR(dst_context_adddata(ctx, &msg->query)); + } /* * Digest the header. @@ -1020,12 +1065,15 @@ dns_dnssec_signmessage(dns_message_t *msg, dst_key_t *key) return (ISC_R_SUCCESS); failure: - if (dynbuf != NULL) + if (dynbuf != NULL) { isc_buffer_free(&dynbuf); - if (signeedsfree) + } + if (signeedsfree) { isc_mem_put(mctx, sig.signature, sig.siglen); - if (ctx != NULL) + } + if (ctx != NULL) { dst_context_destroy(&ctx); + } return (result); } @@ -1056,8 +1104,9 @@ dns_dnssec_verifymessage(isc_buffer_t *source, dns_message_t *msg, msg->sig0status = dns_tsigerror_badsig; if (is_response(msg)) { - if (msg->query.base == NULL) + if (msg->query.base == NULL) { return (DNS_R_UNEXPECTEDTSIG); + } } isc_buffer_usedregion(source, &source_r); @@ -1109,8 +1158,9 @@ dns_dnssec_verifymessage(isc_buffer_t *source, dns_message_t *msg, /* * If this is a response, digest the query. */ - if (is_response(msg)) + if (is_response(msg)) { RETERR(dst_context_adddata(ctx, &msg->query)); + } /* * Extract the header. @@ -1156,10 +1206,12 @@ dns_dnssec_verifymessage(isc_buffer_t *source, dns_message_t *msg, return (ISC_R_SUCCESS); failure: - if (signeedsfree) + if (signeedsfree) { dns_rdata_freestruct(&sig); - if (ctx != NULL) + } + if (ctx != NULL) { dst_context_destroy(&ctx); + } return (result); } @@ -1199,12 +1251,14 @@ dns_dnssec_signs(dns_rdata_t *rdata, const dns_name_t *name, isc_result_t result; INSIST(sigrdataset->type == dns_rdatatype_rrsig); - if (sigrdataset->covers != rdataset->type) + if (sigrdataset->covers != rdataset->type) { return (false); + } result = dns_dnssec_keyfromrdata(name, rdata, mctx, &dstkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } result = dns_rdata_tostruct(rdata, &key, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -1284,8 +1338,9 @@ dns_dnsseckey_destroy(isc_mem_t *mctx, dns_dnsseckey_t **dkp) REQUIRE(dkp != NULL && *dkp != NULL); dk = *dkp; *dkp = NULL; - if (dk->key != NULL) + if (dk->key != NULL) { dst_key_free(&dk->key); + } isc_mem_put(mctx, dk, sizeof(dns_dnsseckey_t)); } @@ -1378,21 +1433,25 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory, len = isc_buffer_usedlength(&b); namebuf[len] = '\0'; - if (directory == NULL) + if (directory == NULL) { directory = "."; + } RETERR(isc_dir_open(&dir, directory)); dir_open = true; while (isc_dir_read(&dir) == ISC_R_SUCCESS) { if (dir.entry.name[0] != 'K' || dir.entry.length < len + 1 || dir.entry.name[len + 1] != '+' || - strncasecmp(dir.entry.name + 1, namebuf, len) != 0) + strncasecmp(dir.entry.name + 1, namebuf, len) != 0) { continue; + } alg = 0; for (i = len + 1 + 1; i < dir.entry.length; i++) { - if (dir.entry.name[i] < '0' || dir.entry.name[i] > '9') + if (dir.entry.name[i] < '0' || + dir.entry.name[i] > '9') { break; + } alg *= 10; alg += dir.entry.name[i] - '0'; } @@ -1403,18 +1462,20 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory, * Did we correctly terminate? */ if (i != len + 1 + 1 + 3 || i >= dir.entry.length || - dir.entry.name[i] != '+') + dir.entry.name[i] != '+') { continue; + } for (i++; i < dir.entry.length; i++) { - if (dir.entry.name[i] < '0' || dir.entry.name[i] > '9') { + if (dir.entry.name[i] < '0' || + dir.entry.name[i] > '9') { break; - /* - * Did we not read exactly 5 more digits? - * Did we overflow? - * Did we correctly terminate? - */ + /* + * Did we not read exactly 5 more digits? + * Did we overflow? + * Did we correctly terminate? + */ } } @@ -1424,8 +1485,9 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory, * Did we correctly terminate? */ if (i != len + 1 + 1 + 3 + 1 + 5 || i >= dir.entry.length || - strcmp(dir.entry.name + i, ".private") != 0) + strcmp(dir.entry.name + i, ".private") != 0) { continue; + } dstkey = NULL; result = dst_key_fromnamedfile( @@ -1440,8 +1502,9 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory, case DST_ALG_HMACSHA256: case DST_ALG_HMACSHA384: case DST_ALG_HMACSHA512: - if (result == DST_R_BADKEYTYPE) + if (result == DST_R_BADKEYTYPE) { continue; + } } if (result != ISC_R_SUCCESS) { @@ -1469,12 +1532,14 @@ dns_dnssec_findmatchingkeys(const dns_name_t *origin, const char *directory, if (!ISC_LIST_EMPTY(list)) { result = ISC_R_SUCCESS; ISC_LIST_APPENDLIST(*keylist, list, link); - } else + } else { result = ISC_R_NOTFOUND; + } failure: - if (dir_open) + if (dir_open) { isc_dir_close(&dir); + } INSIST(key == NULL); while ((key = ISC_LIST_HEAD(list)) != NULL) { ISC_LIST_UNLINK(list, key, link); @@ -1482,8 +1547,9 @@ failure: dst_key_free(&key->key); dns_dnsseckey_destroy(mctx, &key); } - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_free(&dstkey); + } return (result); } @@ -1507,8 +1573,9 @@ addkey(dns_dnsseckeylist_t *keylist, dst_key_t **newkey, bool savekeys, if (dst_key_id(key->key) == dst_key_id(*newkey) && dst_key_alg(key->key) == dst_key_alg(*newkey) && dns_name_equal(dst_key_name(key->key), - dst_key_name(*newkey))) + dst_key_name(*newkey))) { break; + } } if (key != NULL) { @@ -1530,8 +1597,9 @@ addkey(dns_dnsseckeylist_t *keylist, dst_key_t **newkey, bool savekeys, } result = dns_dnsseckey_create(mctx, newkey, &key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (key->legacy || savekeys) { key->force_publish = true; key->force_sign = dst_key_isprivate(key->key); @@ -1583,11 +1651,13 @@ mark_active_keys(dns_dnsseckeylist_t *keylist, dns_rdataset_t *rrsigs) } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } - if (dns_rdataset_isassociated(&sigs)) + if (dns_rdataset_isassociated(&sigs)) { dns_rdataset_disassociate(&sigs); + } return (result); } @@ -1621,19 +1691,22 @@ dns_dnssec_keylistfromrdataset(const dns_name_t *origin, const char *directory, REQUIRE(rdata.length > 3); /* Skip unsupported algorithms */ - if (!dst_algorithm_supported(rdata.data[3])) + if (!dst_algorithm_supported(rdata.data[3])) { goto skip; + } RETERR(dns_dnssec_keyfromrdata(origin, &rdata, mctx, &pubkey)); dst_key_setttl(pubkey, keys.ttl); if (!is_zone_key(pubkey) || - (dst_key_flags(pubkey) & DNS_KEYTYPE_NOAUTH) != 0) + (dst_key_flags(pubkey) & DNS_KEYTYPE_NOAUTH) != 0) { goto skip; + } /* Corrupted .key file? */ - if (!dns_name_equal(origin, dst_key_name(pubkey))) + if (!dns_name_equal(origin, dst_key_name(pubkey))) { goto skip; + } if (publickey) { RETERR(addkey(keylist, &pubkey, savekeys, mctx)); @@ -1713,8 +1786,9 @@ dns_dnssec_keylistfromrdataset(const dns_name_t *origin, const char *directory, RETERR(result); /* This should never happen. */ - if ((dst_key_flags(privkey) & DNS_KEYTYPE_NOAUTH) != 0) + if ((dst_key_flags(privkey) & DNS_KEYTYPE_NOAUTH) != 0) { goto skip; + } /* * Whatever the key's default TTL may have @@ -1724,30 +1798,38 @@ dns_dnssec_keylistfromrdataset(const dns_name_t *origin, const char *directory, RETERR(addkey(keylist, &privkey, savekeys, mctx)); skip: - if (pubkey != NULL) + if (pubkey != NULL) { dst_key_free(&pubkey); - if (privkey != NULL) + } + if (privkey != NULL) { dst_key_free(&privkey); + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { RETERR(result); + } - if (keysigs != NULL && dns_rdataset_isassociated(keysigs)) + if (keysigs != NULL && dns_rdataset_isassociated(keysigs)) { RETERR(mark_active_keys(keylist, keysigs)); + } - if (soasigs != NULL && dns_rdataset_isassociated(soasigs)) + if (soasigs != NULL && dns_rdataset_isassociated(soasigs)) { RETERR(mark_active_keys(keylist, soasigs)); + } result = ISC_R_SUCCESS; failure: - if (dns_rdataset_isassociated(&keys)) + if (dns_rdataset_isassociated(&keys)) { dns_rdataset_disassociate(&keys); - if (pubkey != NULL) + } + if (pubkey != NULL) { dst_key_free(&pubkey); - if (privkey != NULL) + } + if (privkey != NULL) { dst_key_free(&privkey); + } return (result); } @@ -1761,8 +1843,9 @@ make_dnskey(dst_key_t *key, unsigned char *buf, int bufsize, isc_buffer_init(&b, buf, bufsize); result = dst_key_todns(key, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdata_reset(target); isc_buffer_usedregion(&b, &r); diff --git a/lib/dns/dnstap.c b/lib/dns/dnstap.c index 3135e30474..8060a573c2 100644 --- a/lib/dns/dnstap.c +++ b/lib/dns/dnstap.c @@ -109,8 +109,9 @@ struct dns_dtenv { struct fstrm_iothr_options *fopt; isc_task_t *reopen_task; - isc_mutex_t reopen_lock; /* locks 'reopen_queued' */ - bool reopen_queued; + isc_mutex_t reopen_lock; /* locks 'reopen_queued' + * */ + bool reopen_queued; isc_region_t identity; isc_region_t version; @@ -476,8 +477,9 @@ dns_dt_getstats(dns_dtenv_t *env, isc_stats_t **statsp) REQUIRE(VALID_DTENV(env)); REQUIRE(statsp != NULL && *statsp == NULL); - if (env->stats == NULL) + if (env->stats == NULL) { return (ISC_R_NOTFOUND); + } isc_stats_attach(env->stats, statsp); return (ISC_R_SUCCESS); } @@ -491,10 +493,12 @@ destroy(dns_dtenv_t *env) atomic_fetch_add(&global_generation, 1); - if (env->iothr != NULL) + if (env->iothr != NULL) { fstrm_iothr_destroy(&env->iothr); - if (env->fopt != NULL) + } + if (env->fopt != NULL) { fstrm_iothr_options_destroy(&env->fopt); + } if (env->identity.base != NULL) { isc_mem_free(env->mctx, env->identity.base); @@ -504,10 +508,12 @@ destroy(dns_dtenv_t *env) isc_mem_free(env->mctx, env->version.base); env->version.length = 0; } - if (env->path != NULL) + if (env->path != NULL) { isc_mem_free(env->mctx, env->path); - if (env->stats != NULL) + } + if (env->stats != NULL) { isc_stats_detach(&env->stats); + } isc_mem_putanddetach(&env->mctx, env, sizeof(*env)); } @@ -540,13 +546,15 @@ pack_dt(const Dnstap__Dnstap *d, void **buf, size_t *sz) /* Need to use malloc() here because protobuf uses free() */ sbuf.data = malloc(sbuf.alloced); - if (sbuf.data == NULL) + if (sbuf.data == NULL) { return (ISC_R_NOMEMORY); + } sbuf.must_free_data = 1; *sz = dnstap__dnstap__pack_to_buffer(d, (ProtobufCBuffer *)&sbuf); - if (sbuf.data == NULL) + if (sbuf.data == NULL) { return (ISC_R_FAILURE); + } *buf = sbuf.data; return (ISC_R_SUCCESS); @@ -560,8 +568,9 @@ send_dt(dns_dtenv_t *env, void *buf, size_t len) REQUIRE(env != NULL); - if (buf == NULL) + if (buf == NULL) { return; + } ioq = dt_queue(env); if (ioq == NULL) { @@ -572,13 +581,15 @@ send_dt(dns_dtenv_t *env, void *buf, size_t len) res = fstrm_iothr_submit(env->iothr, ioq, buf, len, fstrm_free_wrapper, NULL); if (res != fstrm_res_success) { - if (env->stats != NULL) + if (env->stats != NULL) { isc_stats_increment(env->stats, dns_dnstapcounter_drop); + } free(buf); } else { - if (env->stats != NULL) + if (env->stats != NULL) { isc_stats_increment(env->stats, dns_dnstapcounter_success); + } } } @@ -658,8 +669,9 @@ setaddr(dns_dtmsg_t *dm, isc_sockaddr_t *sa, bool tcp, { int family = isc_sockaddr_pf(sa); - if (family != AF_INET6 && family != AF_INET) + if (family != AF_INET6 && family != AF_INET) { return; + } if (family == AF_INET6) { dm->m.socket_family = DNSTAP__SOCKET_FAMILY__INET6; @@ -673,10 +685,11 @@ setaddr(dns_dtmsg_t *dm, isc_sockaddr_t *sa, bool tcp, *port = ntohs(sa->type.sin.sin_port); } - if (tcp) + if (tcp) { dm->m.socket_protocol = DNSTAP__SOCKET_PROTOCOL__TCP; - else + } else { dm->m.socket_protocol = DNSTAP__SOCKET_PROTOCOL__UDP; + } dm->m.has_socket_protocol = 1; dm->m.has_socket_family = 1; @@ -777,11 +790,13 @@ dns_dt_send(dns_view_t *view, dns_dtmsgtype_t msgtype, isc_sockaddr_t *qaddr, REQUIRE(DNS_VIEW_VALID(view)); - if ((msgtype & view->dttypes) == 0) + if ((msgtype & view->dttypes) == 0) { return; + } - if (view->dtenv == NULL) + if (view->dtenv == NULL) { return; + } REQUIRE(VALID_DTENV(view->dtenv)); @@ -803,8 +818,9 @@ dns_dt_send(dns_view_t *view, dns_dtmsgtype_t msgtype, isc_sockaddr_t *qaddr, case DNS_DTTYPE_SR: case DNS_DTTYPE_TR: case DNS_DTTYPE_UR: - if (rtime != NULL) + if (rtime != NULL) { t = rtime; + } dm.m.response_time_sec = isc_time_seconds(t); dm.m.has_response_time_sec = 1; @@ -814,10 +830,11 @@ dns_dt_send(dns_view_t *view, dns_dtmsgtype_t msgtype, isc_sockaddr_t *qaddr, cpbuf(buf, &dm.m.response_message, &dm.m.has_response_message); /* Types RR and FR get both query and response times */ - if (msgtype == DNS_DTTYPE_CR || msgtype == DNS_DTTYPE_AR) + if (msgtype == DNS_DTTYPE_CR || msgtype == DNS_DTTYPE_AR) { break; + } - /* FALLTHROUGH */ + /* FALLTHROUGH */ case DNS_DTTYPE_AQ: case DNS_DTTYPE_CQ: case DNS_DTTYPE_FQ: @@ -825,8 +842,9 @@ dns_dt_send(dns_view_t *view, dns_dtmsgtype_t msgtype, isc_sockaddr_t *qaddr, case DNS_DTTYPE_SQ: case DNS_DTTYPE_TQ: case DNS_DTTYPE_UQ: - if (qtime != NULL) + if (qtime != NULL) { t = qtime; + } dm.m.query_time_sec = isc_time_seconds(t); dm.m.has_query_time_sec = 1; @@ -870,8 +888,9 @@ dns_dt_send(dns_view_t *view, dns_dtmsgtype_t msgtype, isc_sockaddr_t *qaddr, &dm.m.has_response_port); } - if (pack_dt(&dm.d, &dm.buf, &dm.len) == ISC_R_SUCCESS) + if (pack_dt(&dm.d, &dm.buf, &dm.len) == ISC_R_SUCCESS) { send_dt(view->dtenv, dm.buf, dm.len); + } } static isc_result_t @@ -880,8 +899,9 @@ putstr(isc_buffer_t **b, const char *str) isc_result_t result; result = isc_buffer_reserve(b, strlen(str)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putstr(*b, str); return (ISC_R_SUCCESS); @@ -893,13 +913,16 @@ putaddr(isc_buffer_t **b, isc_region_t *ip) char buf[64]; if (ip->length == 4) { - if (!inet_ntop(AF_INET, ip->base, buf, sizeof(buf))) + if (!inet_ntop(AF_INET, ip->base, buf, sizeof(buf))) { return (ISC_R_FAILURE); + } } else if (ip->length == 16) { - if (!inet_ntop(AF_INET6, ip->base, buf, sizeof(buf))) + if (!inet_ntop(AF_INET6, ip->base, buf, sizeof(buf))) { return (ISC_R_FAILURE); - } else + } + } else { return (ISC_R_BADADDRESSFORM); + } return (putstr(b, buf)); } @@ -914,23 +937,28 @@ dnstap_file(struct fstrm_reader *r) size_t n = 0; res = fstrm_reader_get_control(r, FSTRM_CONTROL_START, &control); - if (res != fstrm_res_success) + if (res != fstrm_res_success) { return (false); + } res = fstrm_control_get_num_field_content_type(control, &n); - if (res != fstrm_res_success) + if (res != fstrm_res_success) { return (false); + } if (n > 0) { res = fstrm_control_get_field_content_type(control, 0, &rtype, &rlen); - if (res != fstrm_res_success) + if (res != fstrm_res_success) { return (false); + } - if (rlen != dlen) + if (rlen != dlen) { return (false); + } - if (memcmp(DNSTAP_CONTENT_TYPE, rtype, dlen) == 0) + if (memcmp(DNSTAP_CONTENT_TYPE, rtype, dlen) == 0) { return (true); + } } return (false); @@ -955,21 +983,25 @@ dns_dt_open(const char *filename, dns_dtmode_t mode, isc_mem_t *mctx, switch (mode) { case dns_dtmode_file: fopt = fstrm_file_options_init(); - if (fopt == NULL) + if (fopt == NULL) { CHECK(ISC_R_NOMEMORY); + } fstrm_file_options_set_file_path(fopt, filename); handle->reader = fstrm_file_reader_init(fopt, NULL); - if (handle->reader == NULL) + if (handle->reader == NULL) { CHECK(ISC_R_NOMEMORY); + } res = fstrm_reader_open(handle->reader); - if (res != fstrm_res_success) + if (res != fstrm_res_success) { CHECK(ISC_R_FAILURE); + } - if (!dnstap_file(handle->reader)) + if (!dnstap_file(handle->reader)) { CHECK(DNS_R_BADDNSTAP); + } break; case dns_dtmode_unix: return (ISC_R_NOTIMPLEMENTED); @@ -988,10 +1020,12 @@ cleanup: fstrm_reader_destroy(&handle->reader); handle->reader = NULL; } - if (fopt != NULL) + if (fopt != NULL) { fstrm_file_options_destroy(&fopt); - if (handle != NULL) + } + if (handle != NULL) { isc_mem_put(mctx, handle, sizeof(*handle)); + } return (result); } @@ -1010,8 +1044,9 @@ dns_dt_getframe(dns_dthandle_t *handle, uint8_t **bufp, size_t *sizep) res = fstrm_reader_read(handle->reader, &data, sizep); switch (res) { case fstrm_res_success: - if (data == NULL) + if (data == NULL) { return (ISC_R_FAILURE); + } DE_CONST(data, *bufp); return (ISC_R_SUCCESS); case fstrm_res_stop: @@ -1056,13 +1091,15 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) isc_mem_attach(mctx, &d->mctx); d->frame = dnstap__dnstap__unpack(NULL, src->length, src->base); - if (d->frame == NULL) + if (d->frame == NULL) { CHECK(ISC_R_NOMEMORY); + } frame = (Dnstap__Dnstap *)d->frame; - if (frame->type != DNSTAP__DNSTAP__TYPE__MESSAGE) + if (frame->type != DNSTAP__DNSTAP__TYPE__MESSAGE) { CHECK(DNS_R_BADDNSTAP); + } m = frame->message; @@ -1115,10 +1152,11 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) } /* Query? */ - if ((d->type & DNS_DTTYPE_QUERY) != 0) + if ((d->type & DNS_DTTYPE_QUERY) != 0) { d->query = true; - else + } else { d->query = false; + } /* Parse DNS message */ if (d->query && m->has_query_message) { @@ -1134,20 +1172,23 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) CHECK(dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &d->msg)); result = dns_message_parse(d->msg, &b, 0); if (result != ISC_R_SUCCESS) { - if (result != DNS_R_RECOVERABLE) + if (result != DNS_R_RECOVERABLE) { dns_message_destroy(&d->msg); + } result = ISC_R_SUCCESS; } /* Timestamp */ if (d->query) { - if (m->has_query_time_sec && m->has_query_time_nsec) + if (m->has_query_time_sec && m->has_query_time_nsec) { isc_time_set(&d->qtime, m->query_time_sec, m->query_time_nsec); + } } else { - if (m->has_response_time_sec && m->has_response_time_nsec) + if (m->has_response_time_sec && m->has_response_time_nsec) { isc_time_set(&d->rtime, m->response_time_sec, m->response_time_nsec); + } } /* Peer address */ @@ -1173,10 +1214,12 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) protobuf_c_enum_descriptor_get_value( &dnstap__socket_protocol__descriptor, m->socket_protocol); - if (type != NULL && type->value == DNSTAP__SOCKET_PROTOCOL__TCP) + if (type != NULL && + type->value == DNSTAP__SOCKET_PROTOCOL__TCP) { d->tcp = true; - else + } else { d->tcp = false; + } } /* Query tuple */ @@ -1198,8 +1241,9 @@ dns_dt_parse(isc_mem_t *mctx, isc_region_t *src, dns_dtdata_t **destp) *destp = d; cleanup: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_dtdata_free(&d); + } return (result); } @@ -1216,14 +1260,15 @@ dns_dt_datatotext(dns_dtdata_t *d, isc_buffer_t **dest) memset(buf, 0, sizeof(buf)); /* Timestamp */ - if (d->query && !isc_time_isepoch(&d->qtime)) + if (d->query && !isc_time_isepoch(&d->qtime)) { isc_time_formattimestamp(&d->qtime, buf, sizeof(buf)); - else if (!d->query && !isc_time_isepoch(&d->rtime)) + } else if (!d->query && !isc_time_isepoch(&d->rtime)) { isc_time_formattimestamp(&d->rtime, buf, sizeof(buf)); + } - if (buf[0] == '\0') + if (buf[0] == '\0') { CHECK(putstr(dest, "???\?-?\?-?? ??:??:??.??? ")); - else { + } else { CHECK(putstr(dest, buf)); CHECK(putstr(dest, " ")); } @@ -1300,37 +1345,40 @@ dns_dt_datatotext(dns_dtdata_t *d, isc_buffer_t **dest) CHECK(putstr(dest, " ")); /* Protocol */ - if (d->tcp) + if (d->tcp) { CHECK(putstr(dest, "TCP ")); - else + } else { CHECK(putstr(dest, "UDP ")); + } /* Message size */ if (d->msgdata.base != NULL) { snprintf(buf, sizeof(buf), "%zub ", (size_t)d->msgdata.length); CHECK(putstr(dest, buf)); - } else + } else { CHECK(putstr(dest, "0b ")); + } /* Query tuple */ - if (d->namebuf[0] == '\0') + if (d->namebuf[0] == '\0') { CHECK(putstr(dest, "?/")); - else { + } else { CHECK(putstr(dest, d->namebuf)); CHECK(putstr(dest, "/")); } - if (d->classbuf[0] == '\0') + if (d->classbuf[0] == '\0') { CHECK(putstr(dest, "?/")); - else { + } else { CHECK(putstr(dest, d->classbuf)); CHECK(putstr(dest, "/")); } - if (d->typebuf[0] == '\0') + if (d->typebuf[0] == '\0') { CHECK(putstr(dest, "?")); - else + } else { CHECK(putstr(dest, d->typebuf)); + } CHECK(isc_buffer_reserve(dest, 1)); isc_buffer_putuint8(*dest, 0); @@ -1349,10 +1397,12 @@ dns_dtdata_free(dns_dtdata_t **dp) d = *dp; *dp = NULL; - if (d->msg != NULL) + if (d->msg != NULL) { dns_message_destroy(&d->msg); - if (d->frame != NULL) + } + if (d->frame != NULL) { dnstap__dnstap__free_unpacked(d->frame, NULL); + } isc_mem_putanddetach(&d->mctx, d, sizeof(*d)); } diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index f0cc50f12e..5d73a4a361 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -178,7 +178,7 @@ addsuffix(char *filename, int len, const char *dirname, const char *ofilename, isc_result_t _r; \ _r = algorithm_status(alg); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0); isc_result_t @@ -215,10 +215,10 @@ dst_lib_init(isc_mem_t *mctx, const char *engine) RETERR(dst__opensslecdsa_init(&dst_t_func[DST_ALG_ECDSA384])); #ifdef HAVE_OPENSSL_ED25519 RETERR(dst__openssleddsa_init(&dst_t_func[DST_ALG_ED25519])); -#endif +#endif /* ifdef HAVE_OPENSSL_ED25519 */ #ifdef HAVE_OPENSSL_ED448 RETERR(dst__openssleddsa_init(&dst_t_func[DST_ALG_ED448])); -#endif +#endif /* ifdef HAVE_OPENSSL_ED448 */ #endif /* USE_OPENSSL */ #if USE_PKCS11 @@ -231,14 +231,14 @@ dst_lib_init(isc_mem_t *mctx, const char *engine) RETERR(dst__pkcs11ecdsa_init(&dst_t_func[DST_ALG_ECDSA384])); #ifdef HAVE_PKCS11_ED25519 RETERR(dst__pkcs11eddsa_init(&dst_t_func[DST_ALG_ED25519])); -#endif +#endif /* ifdef HAVE_PKCS11_ED25519 */ #ifdef HAVE_PKCS11_ED448 RETERR(dst__pkcs11eddsa_init(&dst_t_func[DST_ALG_ED448])); -#endif +#endif /* ifdef HAVE_PKCS11_ED448 */ #endif /* USE_PKCS11 */ #ifdef GSSAPI RETERR(dst__gssapi_init(&dst_t_func[DST_ALG_GSSAPI])); -#endif +#endif /* ifdef GSSAPI */ dst_initialized = true; return (ISC_R_SUCCESS); @@ -273,8 +273,9 @@ dst_algorithm_supported(unsigned int alg) { REQUIRE(dst_initialized == true); - if (alg >= DST_MAX_ALGS || dst_t_func[alg] == NULL) + if (alg >= DST_MAX_ALGS || dst_t_func[alg] == NULL) { return (false); + } return (true); } @@ -298,27 +299,32 @@ dst_context_create(dst_key_t *key, isc_mem_t *mctx, isc_logcategory_t *category, REQUIRE(mctx != NULL); REQUIRE(dctxp != NULL && *dctxp == NULL); - if (key->func->createctx == NULL && key->func->createctx2 == NULL) + if (key->func->createctx == NULL && key->func->createctx2 == NULL) { return (DST_R_UNSUPPORTEDALG); - if (key->keydata.generic == NULL) + } + if (key->keydata.generic == NULL) { return (DST_R_NULLKEY); + } dctx = isc_mem_get(mctx, sizeof(dst_context_t)); memset(dctx, 0, sizeof(*dctx)); dst_key_attach(key, &dctx->key); isc_mem_attach(mctx, &dctx->mctx); dctx->category = category; - if (useforsigning) + if (useforsigning) { dctx->use = DO_SIGN; - else + } else { dctx->use = DO_VERIFY; - if (key->func->createctx2 != NULL) + } + if (key->func->createctx2 != NULL) { result = key->func->createctx2(key, maxbits, dctx); - else + } else { result = key->func->createctx(key, dctx); + } if (result != ISC_R_SUCCESS) { - if (dctx->key != NULL) + if (dctx->key != NULL) { dst_key_free(&dctx->key); + } isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(dst_context_t)); return (result); } @@ -338,8 +344,9 @@ dst_context_destroy(dst_context_t **dctxp) *dctxp = NULL; INSIST(dctx->key->func->destroyctx != NULL); dctx->key->func->destroyctx(dctx); - if (dctx->key != NULL) + if (dctx->key != NULL) { dst_key_free(&dctx->key); + } dctx->magic = 0; isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(dst_context_t)); } @@ -364,13 +371,17 @@ dst_context_sign(dst_context_t *dctx, isc_buffer_t *sig) key = dctx->key; CHECKALG(key->key_alg); - if (key->keydata.generic == NULL) + if (key->keydata.generic == NULL) { return (DST_R_NULLKEY); + } - if (key->func->sign == NULL) + if (key->func->sign == NULL) { return (DST_R_NOTPRIVATEKEY); - if (key->func->isprivate == NULL || key->func->isprivate(key) == false) + } + if (key->func->isprivate == NULL || + key->func->isprivate(key) == false) { return (DST_R_NOTPRIVATEKEY); + } return (key->func->sign(dctx, sig)); } @@ -382,10 +393,12 @@ dst_context_verify(dst_context_t *dctx, isc_region_t *sig) REQUIRE(sig != NULL); CHECKALG(dctx->key->key_alg); - if (dctx->key->keydata.generic == NULL) + if (dctx->key->keydata.generic == NULL) { return (DST_R_NULLKEY); - if (dctx->key->func->verify == NULL) + } + if (dctx->key->func->verify == NULL) { return (DST_R_NOTPUBLICKEY); + } return (dctx->key->func->verify(dctx, sig)); } @@ -398,10 +411,13 @@ dst_context_verify2(dst_context_t *dctx, unsigned int maxbits, REQUIRE(sig != NULL); CHECKALG(dctx->key->key_alg); - if (dctx->key->keydata.generic == NULL) + if (dctx->key->keydata.generic == NULL) { return (DST_R_NULLKEY); - if (dctx->key->func->verify == NULL && dctx->key->func->verify2 == NULL) + } + if (dctx->key->func->verify == NULL && + dctx->key->func->verify2 == NULL) { return (DST_R_NOTPUBLICKEY); + } return (dctx->key->func->verify2 != NULL ? dctx->key->func->verify2(dctx, maxbits, sig) @@ -419,15 +435,18 @@ dst_key_computesecret(const dst_key_t *pub, const dst_key_t *priv, CHECKALG(pub->key_alg); CHECKALG(priv->key_alg); - if (pub->keydata.generic == NULL || priv->keydata.generic == NULL) + if (pub->keydata.generic == NULL || priv->keydata.generic == NULL) { return (DST_R_NULLKEY); + } if (pub->key_alg != priv->key_alg || pub->func->computesecret == NULL || - priv->func->computesecret == NULL) + priv->func->computesecret == NULL) { return (DST_R_KEYCANNOTCOMPUTESECRET); + } - if (dst_key_isprivate(priv) == false) + if (dst_key_isprivate(priv) == false) { return (DST_R_NOTPRIVATEKEY); + } return (pub->func->computesecret(pub, priv, secret)); } @@ -499,10 +518,11 @@ dst_key_getfilename(dns_name_t *name, dns_keytag_t id, unsigned int alg, result = buildfilename(name, id, alg, type, directory, buf); if (result == ISC_R_SUCCESS) { - if (isc_buffer_availablelength(buf) > 0) + if (isc_buffer_availablelength(buf) > 0) { isc_buffer_putuint8(buf, 0); - else + } else { result = ISC_R_NOSPACE; + } } return (result); @@ -529,16 +549,19 @@ dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type, isc_buffer_init(&buf, filename, NAME_MAX); result = dst_key_getfilename(name, id, alg, type, NULL, mctx, &buf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto out; + } result = dst_key_fromnamedfile(filename, directory, type, mctx, &key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto out; + } result = computeid(key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto out; + } if (!dns_name_equal(name, key->key_name) || id != key->key_id || alg != key->key_alg) { @@ -550,8 +573,9 @@ dst_key_fromfile(dns_name_t *name, dns_keytag_t id, unsigned int alg, int type, result = ISC_R_SUCCESS; out: - if ((key != NULL) && (result != ISC_R_SUCCESS)) + if ((key != NULL) && (result != ISC_R_SUCCESS)) { dst_key_free(&key); + } return (result); } @@ -574,16 +598,19 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, int type, /* If an absolute path is specified, don't use the key directory */ #ifndef WIN32 - if (filename[0] == '/') + if (filename[0] == '/') { dirname = NULL; -#else /* WIN32 */ - if (filename[0] == '/' || filename[0] == '\\') + } +#else /* WIN32 */ + if (filename[0] == '/' || filename[0] == '\\') { dirname = NULL; -#endif + } +#endif /* ifndef WIN32 */ newfilenamelen = strlen(filename) + 5; - if (dirname != NULL) + if (dirname != NULL) { newfilenamelen += strlen(dirname) + 1; + } newfilename = isc_mem_get(mctx, newfilenamelen); result = addsuffix(newfilename, newfilenamelen, dirname, filename, ".key"); @@ -621,8 +648,9 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, int type, return (ISC_R_NOMEMORY); } - if (key->func->parse == NULL) + if (key->func->parse == NULL) { RETERR(DST_R_UNSUPPORTEDALG); + } /* * Read the state file, if requested by type. @@ -649,8 +677,9 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, int type, } newfilenamelen = strlen(filename) + 9; - if (dirname != NULL) + if (dirname != NULL) { newfilenamelen += strlen(dirname) + 1; + } newfilename = isc_mem_get(mctx, newfilenamelen); result = addsuffix(newfilename, newfilenamelen, dirname, filename, ".private"); @@ -665,22 +694,27 @@ dst_key_fromnamedfile(const char *filename, const char *dirname, int type, RETERR(computeid(key)); - if (pubkey->key_id != key->key_id) + if (pubkey->key_id != key->key_id) { RETERR(DST_R_INVALIDPRIVATEKEY); + } dst_key_free(&pubkey); *keyp = key; return (ISC_R_SUCCESS); out: - if (pubkey != NULL) + if (pubkey != NULL) { dst_key_free(&pubkey); - if (newfilename != NULL) + } + if (newfilename != NULL) { isc_mem_put(mctx, newfilename, newfilenamelen); - if (lex != NULL) + } + if (lex != NULL) { isc_lex_destroy(&lex); - if (key != NULL) + } + if (key != NULL) { dst_key_free(&key); + } return (result); } @@ -693,24 +727,28 @@ dst_key_todns(const dst_key_t *key, isc_buffer_t *target) CHECKALG(key->key_alg); - if (key->func->todns == NULL) + if (key->func->todns == NULL) { return (DST_R_UNSUPPORTEDALG); + } - if (isc_buffer_availablelength(target) < 4) + if (isc_buffer_availablelength(target) < 4) { return (ISC_R_NOSPACE); + } isc_buffer_putuint16(target, (uint16_t)(key->key_flags & 0xffff)); isc_buffer_putuint8(target, (uint8_t)key->key_proto); isc_buffer_putuint8(target, (uint8_t)key->key_alg); if ((key->key_flags & DNS_KEYFLAG_EXTENDED) != 0) { - if (isc_buffer_availablelength(target) < 2) + if (isc_buffer_availablelength(target) < 2) { return (ISC_R_NOSPACE); + } isc_buffer_putuint16( target, (uint16_t)((key->key_flags >> 16) & 0xffff)); } - if (key->keydata.generic == NULL) /*%< NULL KEY */ + if (key->keydata.generic == NULL) { /*%< NULL KEY */ return (ISC_R_SUCCESS); + } return (key->func->todns(key, target)); } @@ -730,8 +768,9 @@ dst_key_fromdns(const dns_name_t *name, dns_rdataclass_t rdclass, isc_buffer_remainingregion(source, &r); - if (isc_buffer_remaininglength(source) < 4) + if (isc_buffer_remaininglength(source) < 4) { return (DST_R_INVALIDPUBLICKEY); + } flags = isc_buffer_getuint16(source); proto = isc_buffer_getuint8(source); alg = isc_buffer_getuint8(source); @@ -740,16 +779,18 @@ dst_key_fromdns(const dns_name_t *name, dns_rdataclass_t rdclass, rid = dst_region_computerid(&r); if ((flags & DNS_KEYFLAG_EXTENDED) != 0) { - if (isc_buffer_remaininglength(source) < 2) + if (isc_buffer_remaininglength(source) < 2) { return (DST_R_INVALIDPUBLICKEY); + } extflags = isc_buffer_getuint16(source); flags |= (extflags << 16); } result = frombuffer(name, alg, flags, proto, rdclass, source, mctx, &key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } key->key_id = id; key->key_rid = rid; @@ -769,8 +810,9 @@ dst_key_frombuffer(const dns_name_t *name, unsigned int alg, unsigned int flags, result = frombuffer(name, alg, flags, protocol, rdclass, source, mctx, &key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = computeid(key); if (result != ISC_R_SUCCESS) { @@ -791,8 +833,9 @@ dst_key_tobuffer(const dst_key_t *key, isc_buffer_t *target) CHECKALG(key->key_alg); - if (key->func->todns == NULL) + if (key->func->todns == NULL) { return (DST_R_UNSUPPORTEDALG); + } return (key->func->todns(key, target)); } @@ -808,15 +851,17 @@ dst_key_privatefrombuffer(dst_key_t *key, isc_buffer_t *buffer) REQUIRE(!dst_key_isprivate(key)); REQUIRE(buffer != NULL); - if (key->func->parse == NULL) + if (key->func->parse == NULL) { RETERR(DST_R_UNSUPPORTEDALG); + } RETERR(isc_lex_create(key->mctx, 1500, &lex)); RETERR(isc_lex_openbuffer(lex, buffer)); RETERR(key->func->parse(key, lex, NULL)); out: - if (lex != NULL) + if (lex != NULL) { isc_lex_destroy(&lex); + } return (result); } @@ -840,8 +885,9 @@ dst_key_fromgssapi(const dns_name_t *name, gss_ctx_id_t gssctx, isc_mem_t *mctx, key = get_key_struct(name, DST_ALG_GSSAPI, 0, DNS_KEYPROTO_DNSSEC, 0, dns_rdataclass_in, 0, mctx); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } if (intoken != NULL) { /* @@ -860,7 +906,7 @@ out: if (result != ISC_R_SUCCESS) { dst_key_free(&key); } - return result; + return (result); } isc_result_t @@ -882,8 +928,9 @@ dst_key_buildinternal(const dns_name_t *name, unsigned int alg, key = get_key_struct(name, alg, flags, protocol, bits, rdclass, 0, mctx); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } key->keydata.generic = data; @@ -915,8 +962,9 @@ dst_key_fromlabel(const dns_name_t *name, int alg, unsigned int flags, CHECKALG(alg); key = get_key_struct(name, alg, flags, protocol, 0, rdclass, 0, mctx); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } if (key->func->fromlabel == NULL) { dst_key_free(&key); @@ -957,8 +1005,9 @@ dst_key_generate(const dns_name_t *name, unsigned int alg, unsigned int bits, key = get_key_struct(name, alg, flags, protocol, bits, rdclass, 0, mctx); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } if (bits == 0) { /*%< NULL KEY */ key->key_flags |= DNS_KEYTYPE_NOKEY; @@ -1135,27 +1184,33 @@ comparekeys(const dst_key_t *key1, const dst_key_t *key2, REQUIRE(VALID_KEY(key1)); REQUIRE(VALID_KEY(key2)); - if (key1 == key2) + if (key1 == key2) { return (true); - - if (key1->key_alg != key2->key_alg) - return (false); - - if (key1->key_id != key2->key_id) { - if (!match_revoked_key) - return (false); - if ((key1->key_flags & DNS_KEYFLAG_REVOKE) == - (key2->key_flags & DNS_KEYFLAG_REVOKE)) - return (false); - if (key1->key_id != key2->key_rid && - key1->key_rid != key2->key_id) - return (false); } - if (compare != NULL) - return (compare(key1, key2)); - else + if (key1->key_alg != key2->key_alg) { return (false); + } + + if (key1->key_id != key2->key_id) { + if (!match_revoked_key) { + return (false); + } + if ((key1->key_flags & DNS_KEYFLAG_REVOKE) == + (key2->key_flags & DNS_KEYFLAG_REVOKE)) { + return (false); + } + if (key1->key_id != key2->key_rid && + key1->key_rid != key2->key_id) { + return (false); + } + } + + if (compare != NULL) { + return (compare(key1, key2)); + } else { + return (false); + } } /* @@ -1172,21 +1227,25 @@ pub_compare(const dst_key_t *key1, const dst_key_t *key2) isc_buffer_init(&b1, buf1, sizeof(buf1)); result = dst_key_todns(key1, &b1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } /* Zero out flags. */ buf1[0] = buf1[1] = 0; - if ((key1->key_flags & DNS_KEYFLAG_EXTENDED) != 0) + if ((key1->key_flags & DNS_KEYFLAG_EXTENDED) != 0) { isc_buffer_subtract(&b1, 2); + } isc_buffer_init(&b2, buf2, sizeof(buf2)); result = dst_key_todns(key2, &b2); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } /* Zero out flags. */ buf2[0] = buf2[1] = 0; - if ((key2->key_flags & DNS_KEYFLAG_EXTENDED) != 0) + if ((key2->key_flags & DNS_KEYFLAG_EXTENDED) != 0) { isc_buffer_subtract(&b2, 2); + } isc_buffer_usedregion(&b1, &r1); /* Remove extended flags. */ @@ -1224,14 +1283,16 @@ dst_key_paramcompare(const dst_key_t *key1, const dst_key_t *key2) REQUIRE(VALID_KEY(key1)); REQUIRE(VALID_KEY(key2)); - if (key1 == key2) + if (key1 == key2) { return (true); + } if (key1->key_alg == key2->key_alg && key1->func->paramcompare != NULL && - key1->func->paramcompare(key1, key2) == true) + key1->func->paramcompare(key1, key2) == true) { return (true); - else + } else { return (false); + } } void @@ -1260,10 +1321,12 @@ dst_key_free(dst_key_t **keyp) INSIST(key->func->destroy != NULL); key->func->destroy(key); } - if (key->engine != NULL) + if (key->engine != NULL) { isc_mem_free(mctx, key->engine); - if (key->label != NULL) + } + if (key->label != NULL) { isc_mem_free(mctx, key->label); + } dns_name_free(key->key_name, mctx); isc_mem_put(mctx, key->key_name, sizeof(dns_name_t)); if (key->key_tkeytoken) { @@ -1393,8 +1456,9 @@ dst_key_dump(dst_key_t *key, isc_mem_t *mctx, char **buffer, int *length) REQUIRE(length != NULL && *length == 0); REQUIRE(VALID_KEY(key)); - if (key->func->dump == NULL) + if (key->func->dump == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return (key->func->dump(key, mctx, buffer, length)); } @@ -1409,21 +1473,25 @@ dst_key_restore(dns_name_t *name, unsigned int alg, unsigned int flags, REQUIRE(dst_initialized == true); REQUIRE(keyp != NULL && *keyp == NULL); - if (alg >= DST_MAX_ALGS || dst_t_func[alg] == NULL) + if (alg >= DST_MAX_ALGS || dst_t_func[alg] == NULL) { return (DST_R_UNSUPPORTEDALG); + } - if (dst_t_func[alg]->restore == NULL) + if (dst_t_func[alg]->restore == NULL) { return (ISC_R_NOTIMPLEMENTED); + } key = get_key_struct(name, alg, flags, protocol, 0, rdclass, 0, mctx); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } result = (dst_t_func[alg]->restore)(key, keystr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *keyp = key; - else + } else { dst_key_free(&key); + } return (result); } @@ -1519,8 +1587,9 @@ dst_key_read_public(const char *filename, int type, isc_mem_t *mctx, /* 1500 should be large enough for any key */ ret = isc_lex_create(mctx, 1500, &lex); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup; + } memset(specials, 0, sizeof(specials)); specials['('] = 1; @@ -1530,55 +1599,65 @@ dst_key_read_public(const char *filename, int type, isc_mem_t *mctx, isc_lex_setcomments(lex, ISC_LEXCOMMENT_DNSMASTERFILE); ret = isc_lex_openfile(lex, filename); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup; + } /* Read the domain name */ NEXTTOKEN(lex, opt, &token); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { BADTOKEN(); + } /* * We don't support "@" in .key files. */ - if (!strcmp(DST_AS_STR(token), "@")) + if (!strcmp(DST_AS_STR(token), "@")) { BADTOKEN(); + } dns_fixedname_init(&name); isc_buffer_init(&b, DST_AS_STR(token), strlen(DST_AS_STR(token))); isc_buffer_add(&b, strlen(DST_AS_STR(token))); ret = dns_name_fromtext(dns_fixedname_name(&name), &b, dns_rootname, 0, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup; + } /* Read the next word: either TTL, class, or 'KEY' */ NEXTTOKEN(lex, opt, &token); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { BADTOKEN(); + } /* If it's a TTL, read the next one */ result = dns_ttl_fromtext(&token.value.as_textregion, &ttl); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { NEXTTOKEN(lex, opt, &token); + } - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { BADTOKEN(); + } ret = dns_rdataclass_fromtext(&rdclass, &token.value.as_textregion); - if (ret == ISC_R_SUCCESS) + if (ret == ISC_R_SUCCESS) { NEXTTOKEN(lex, opt, &token); + } - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { BADTOKEN(); + } - if (strcasecmp(DST_AS_STR(token), "DNSKEY") == 0) + if (strcasecmp(DST_AS_STR(token), "DNSKEY") == 0) { keytype = dns_rdatatype_dnskey; - else if (strcasecmp(DST_AS_STR(token), "KEY") == 0) + } else if (strcasecmp(DST_AS_STR(token), "KEY") == 0) { keytype = dns_rdatatype_key; /*%< SIG(0), TKEY */ - else + } else { BADTOKEN(); + } if (((type & DST_TYPE_KEY) != 0 && keytype != dns_rdatatype_key) || ((type & DST_TYPE_KEY) == 0 && keytype != dns_rdatatype_dnskey)) { @@ -1589,19 +1668,22 @@ dst_key_read_public(const char *filename, int type, isc_mem_t *mctx, isc_buffer_init(&b, rdatabuf, sizeof(rdatabuf)); ret = dns_rdata_fromtext(&rdata, rdclass, keytype, lex, NULL, false, mctx, &b, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup; + } ret = dst_key_fromdns(dns_fixedname_name(&name), rdclass, &b, mctx, keyp); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup; + } dst_key_setttl(*keyp, ttl); cleanup: - if (lex != NULL) + if (lex != NULL) { isc_lex_destroy(&lex); + } return (ret); } @@ -1609,8 +1691,9 @@ static int find_metadata(const char *s, const char *tags[], int ntags) { for (int i = 0; i < ntags; i++) { - if (tags[i] != NULL && strcasecmp(s, tags[i]) == 0) + if (tags[i] != NULL && strcasecmp(s, tags[i]) == 0) { return (i); + } } return (-1); } @@ -1894,23 +1977,27 @@ printtime(const dst_key_t *key, int type, const char *tag, FILE *stream) isc_region_t r; result = dst_key_gettime(key, type, &when); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return; + } /* time_t and isc_stdtime_t might be different sizes */ t = when; #ifdef WIN32 - if (ctime_s(output, sizeof(output), &t) != 0) + if (ctime_s(output, sizeof(output), &t) != 0) { goto error; -#else - if (ctime_r(&t, output) == NULL) + } +#else /* ifdef WIN32 */ + if (ctime_r(&t, output) == NULL) { goto error; -#endif + } +#endif /* ifdef WIN32 */ isc_buffer_init(&b, utc, sizeof(utc)); result = dns_time32_totext(when, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error; + } isc_buffer_usedregion(&b, &r); fprintf(stream, "%s: %.*s (%.*s)\n", tag, (int)r.length, r.base, @@ -2015,8 +2102,9 @@ write_key_state(const dst_key_t *key, int type, const char *directory) } fflush(fp); - if (ferror(fp)) + if (ferror(fp)) { ret = DST_R_WRITEERROR; + } fclose(fp); return (ret); @@ -2116,26 +2204,31 @@ write_public_key(const dst_key_t *key, int type, const char *directory) ret = dns_name_print(key->key_name, fp); fprintf(fp, " "); - if (key->key_ttl != 0) + if (key->key_ttl != 0) { fprintf(fp, "%u ", key->key_ttl); + } isc_buffer_usedregion(&classb, &r); - if ((unsigned)fwrite(r.base, 1, r.length, fp) != r.length) + if ((unsigned)fwrite(r.base, 1, r.length, fp) != r.length) { ret = DST_R_WRITEERROR; + } - if ((type & DST_TYPE_KEY) != 0) + if ((type & DST_TYPE_KEY) != 0) { fprintf(fp, " KEY "); - else + } else { fprintf(fp, " DNSKEY "); + } isc_buffer_usedregion(&textb, &r); - if ((unsigned)fwrite(r.base, 1, r.length, fp) != r.length) + if ((unsigned)fwrite(r.base, 1, r.length, fp) != r.length) { ret = DST_R_WRITEERROR; + } fputc('\n', fp); fflush(fp); - if (ferror(fp)) + if (ferror(fp)) { ret = DST_R_WRITEERROR; + } fclose(fp); return (ret); @@ -2158,19 +2251,23 @@ buildfilename(dns_name_t *name, dns_keytag_t id, unsigned int alg, } if (directory != NULL) { - if (isc_buffer_availablelength(out) < strlen(directory)) + if (isc_buffer_availablelength(out) < strlen(directory)) { return (ISC_R_NOSPACE); + } isc_buffer_putstr(out, directory); if (strlen(directory) > 0U && - directory[strlen(directory) - 1] != '/') + directory[strlen(directory) - 1] != '/') { isc_buffer_putstr(out, "/"); + } } - if (isc_buffer_availablelength(out) < 1) + if (isc_buffer_availablelength(out) < 1) { return (ISC_R_NOSPACE); + } isc_buffer_putstr(out, "K"); result = dns_name_tofilenametext(name, false, out); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (isc_buffer_printf(out, "+%03d+%05d%s", alg, id, suffix)); } @@ -2185,8 +2282,9 @@ computeid(dst_key_t *key) isc_buffer_init(&dnsbuf, dns_array, sizeof(dns_array)); ret = dst_key_todns(key, &dnsbuf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } isc_buffer_usedregion(&dnsbuf, &r); key->key_id = dst_region_computeid(&r); @@ -2208,8 +2306,9 @@ frombuffer(const dns_name_t *name, unsigned int alg, unsigned int flags, REQUIRE(keyp != NULL && *keyp == NULL); key = get_key_struct(name, alg, flags, protocol, 0, rdclass, 0, mctx); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } if (isc_buffer_remaininglength(source) > 0) { ret = algorithm_status(alg); @@ -2251,22 +2350,26 @@ addsuffix(char *filename, int len, const char *odirname, const char *ofilename, int olen = strlen(ofilename); int n; - if (olen > 1 && ofilename[olen - 1] == '.') + if (olen > 1 && ofilename[olen - 1] == '.') { olen -= 1; - else if (olen > 8 && strcmp(ofilename + olen - 8, ".private") == 0) + } else if (olen > 8 && strcmp(ofilename + olen - 8, ".private") == 0) { olen -= 8; - else if (olen > 4 && strcmp(ofilename + olen - 4, ".key") == 0) + } else if (olen > 4 && strcmp(ofilename + olen - 4, ".key") == 0) { olen -= 4; + } - if (odirname == NULL) + if (odirname == NULL) { n = snprintf(filename, len, "%.*s%s", olen, ofilename, suffix); - else + } else { n = snprintf(filename, len, "%s/%.*s%s", odirname, olen, ofilename, suffix); - if (n < 0) + } + if (n < 0) { return (ISC_R_FAILURE); - if (n >= len) + } + if (n >= len) { return (ISC_R_NOSPACE); + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/dst_internal.h b/lib/dns/dst_internal.h index 4b88f1c955..7b08bc146d 100644 --- a/lib/dns/dst_internal.h +++ b/lib/dns/dst_internal.h @@ -80,12 +80,13 @@ struct dst_key { isc_refcount_t refs; dns_name_t * key_name; /*%< name of the key */ unsigned int key_size; /*%< size of the key in bits */ - unsigned int key_proto; /*%< protocols this key is used for */ - unsigned int key_alg; /*%< algorithm of the key */ - uint32_t key_flags; /*%< flags of the public key */ - uint16_t key_id; /*%< identifier of the key */ - uint16_t key_rid; /*%< identifier of the key when - revoked */ + unsigned int key_proto; /*%< protocols this key is used for + * */ + unsigned int key_alg; /*%< algorithm of the key */ + uint32_t key_flags; /*%< flags of the public key */ + uint16_t key_id; /*%< identifier of the key */ + uint16_t key_rid; /*%< identifier of the key when + * revoked */ uint16_t key_bits; /*%< hmac digest bits */ dns_rdataclass_t key_class; /*%< class of the key record */ dns_ttl_t key_ttl; /*%< default/initial dnskey ttl */ @@ -98,30 +99,37 @@ struct dst_key { DH * dh; #if USE_OPENSSL EVP_PKEY *pkey; -#endif +#endif /* if USE_OPENSSL */ #if USE_PKCS11 pk11_object_t *pkey; -#endif +#endif /* if USE_PKCS11 */ dst_hmac_key_t *hmac_key; } keydata; /*%< pointer to key in crypto pkg fmt */ isc_stdtime_t times[DST_MAX_TIMES + 1]; /*%< timing metadata */ bool timeset[DST_MAX_TIMES + 1]; /*%< data set? */ - uint32_t nums[DST_MAX_NUMERIC + 1]; /*%< numeric metadata */ - bool numset[DST_MAX_NUMERIC + 1]; /*%< data set? */ + uint32_t nums[DST_MAX_NUMERIC + 1]; /*%< numeric metadata + * */ + bool numset[DST_MAX_NUMERIC + 1]; /*%< data set? */ - bool bools[DST_MAX_BOOLEAN + 1]; /*%< boolean metadata */ + bool bools[DST_MAX_BOOLEAN + 1]; /*%< boolean metadata + * */ bool boolset[DST_MAX_BOOLEAN + 1]; /*%< data set? */ - dst_key_state_t keystates[DST_MAX_KEYSTATES + 1]; /*%< key states */ - bool keystateset[DST_MAX_KEYSTATES + 1]; /*%< data set? */ + dst_key_state_t keystates[DST_MAX_KEYSTATES + 1]; /*%< key states + * */ + bool keystateset[DST_MAX_KEYSTATES + 1]; /*%< data + * set? */ - bool inactive; /*%< private key not present as it is inactive */ + bool inactive; /*%< private key not present as it is + * inactive */ bool external; /*%< external key */ - int fmt_major; /*%< private key format, major version */ - int fmt_minor; /*%< private key format, minor version */ + int fmt_major; /*%< private key format, major version + * */ + int fmt_minor; /*%< private key format, minor version + * */ dst_func_t * func; /*%< crypto package specific functions */ isc_buffer_t *key_tkeytoken; /*%< TKEY token data */ @@ -140,7 +148,7 @@ struct dst_context { EVP_MD_CTX * evp_md_ctx; #if USE_PKCS11 pk11_context_t *pk11_ctx; -#endif +#endif /* if USE_PKCS11 */ } ctxdata; }; @@ -228,7 +236,7 @@ dst__pkcs11ecdsa_init(struct dst_func **funcp); #if defined(HAVE_PKCS11_ED25519) || defined(HAVE_PKCS11_ED448) isc_result_t dst__pkcs11eddsa_init(struct dst_func **funcp); -#endif +#endif /* if defined(HAVE_PKCS11_ED25519) || defined(HAVE_PKCS11_ED448) */ #endif /* USE_PKCS11 */ #ifdef GSSAPI isc_result_t diff --git a/lib/dns/dst_openssl.h b/lib/dns/dst_openssl.h index f05742d104..d4e74390ca 100644 --- a/lib/dns/dst_openssl.h +++ b/lib/dns/dst_openssl.h @@ -35,7 +35,8 @@ #define BN_GENCB_free(x) ((void)0) #define BN_GENCB_new() (&_cb) #define BN_GENCB_get_arg(x) ((x)->arg) -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ #if OPENSSL_VERSION_NUMBER >= 0x10100000L /* @@ -44,7 +45,7 @@ * the link has been eliminated and EVP_sha1() can be used now instead. */ #define EVP_dss1 EVP_sha1 -#endif +#endif /* if OPENSSL_VERSION_NUMBER >= 0x10100000L */ ISC_LANG_BEGINDECLS @@ -61,9 +62,9 @@ dst__openssl_toresult3(isc_logcategory_t *category, const char *funcname, #if !defined(OPENSSL_NO_ENGINE) ENGINE * dst__openssl_getengine(const char *engine); -#else +#else /* if !defined(OPENSSL_NO_ENGINE) */ #define dst__openssl_getengine(x) NULL -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ ISC_LANG_ENDDECLS diff --git a/lib/dns/dst_parse.c b/lib/dns/dst_parse.c index 1e41cca49e..3612b08feb 100644 --- a/lib/dns/dst_parse.c +++ b/lib/dns/dst_parse.c @@ -122,8 +122,9 @@ find_value(const char *s, const unsigned int alg) for (i = 0; map[i].tag != NULL; i++) { if (strcasecmp(s, map[i].tag) == 0 && - (TAG_ALG(map[i].value) == alg)) + (TAG_ALG(map[i].value) == alg)) { return (map[i].value); + } } return (-1); } @@ -134,10 +135,11 @@ find_tag(const int value) int i; for (i = 0;; i++) { - if (map[i].tag == NULL) + if (map[i].tag == NULL) { return (NULL); - else if (value == map[i].value) + } else if (value == map[i].value) { return (map[i].tag); + } } } @@ -147,8 +149,9 @@ find_metadata(const char *s, const char *tags[], int ntags) int i; for (i = 0; i < ntags; i++) { - if (tags[i] != NULL && strcasecmp(s, tags[i]) == 0) + if (tags[i] != NULL && strcasecmp(s, tags[i]) == 0) { return (i); + } } return (-1); @@ -174,11 +177,13 @@ check_rsa(const dst_private_t *priv, bool external) bool ok; unsigned int mask; - if (external) + if (external) { return ((priv->nelements == 0) ? 0 : -1); + } - for (i = 0; i < RSA_NTAGS; i++) + for (i = 0; i < RSA_NTAGS; i++) { have[i] = false; + } for (j = 0; j < priv->nelements; j++) { for (i = 0; i < RSA_NTAGS; i++) { @@ -186,18 +191,19 @@ check_rsa(const dst_private_t *priv, bool external) break; } } - if (i == RSA_NTAGS) + if (i == RSA_NTAGS) { return (-1); + } have[i] = true; } mask = (1ULL << TAG_SHIFT) - 1; - if (have[TAG_RSA_ENGINE & mask]) + if (have[TAG_RSA_ENGINE & mask]) { ok = have[TAG_RSA_MODULUS & mask] && have[TAG_RSA_PUBLICEXPONENT & mask] && have[TAG_RSA_LABEL & mask]; - else + } else { ok = have[TAG_RSA_MODULUS & mask] && have[TAG_RSA_PUBLICEXPONENT & mask] && have[TAG_RSA_PRIVATEEXPONENT & mask] && @@ -206,6 +212,7 @@ check_rsa(const dst_private_t *priv, bool external) have[TAG_RSA_EXPONENT1 & mask] && have[TAG_RSA_EXPONENT2 & mask] && have[TAG_RSA_COEFFICIENT & mask]; + } return (ok ? 0 : -1); } @@ -213,16 +220,18 @@ static int check_dh(const dst_private_t *priv) { int i, j; - if (priv->nelements != DH_NTAGS) + if (priv->nelements != DH_NTAGS) { return (-1); + } for (i = 0; i < DH_NTAGS; i++) { for (j = 0; j < priv->nelements; j++) { if (priv->elements[j].tag == TAG(DST_ALG_DH, i)) { break; } } - if (j == priv->nelements) + if (j == priv->nelements) { return (-1); + } } return (0); } @@ -235,28 +244,32 @@ check_ecdsa(const dst_private_t *priv, bool external) bool ok; unsigned int mask; - if (external) + if (external) { return ((priv->nelements == 0) ? 0 : -1); + } - for (i = 0; i < ECDSA_NTAGS; i++) + for (i = 0; i < ECDSA_NTAGS; i++) { have[i] = false; + } for (j = 0; j < priv->nelements; j++) { for (i = 0; i < ECDSA_NTAGS; i++) { if (priv->elements[j].tag == TAG(DST_ALG_ECDSA256, i)) { break; } } - if (i == ECDSA_NTAGS) + if (i == ECDSA_NTAGS) { return (-1); + } have[i] = true; } mask = (1ULL << TAG_SHIFT) - 1; - if (have[TAG_ECDSA_ENGINE & mask]) + if (have[TAG_ECDSA_ENGINE & mask]) { ok = have[TAG_ECDSA_LABEL & mask]; - else + } else { ok = have[TAG_ECDSA_PRIVATEKEY & mask]; + } return (ok ? 0 : -1); } @@ -268,28 +281,32 @@ check_eddsa(const dst_private_t *priv, bool external) bool ok; unsigned int mask; - if (external) + if (external) { return ((priv->nelements == 0) ? 0 : -1); + } - for (i = 0; i < EDDSA_NTAGS; i++) + for (i = 0; i < EDDSA_NTAGS; i++) { have[i] = false; + } for (j = 0; j < priv->nelements; j++) { for (i = 0; i < EDDSA_NTAGS; i++) { if (priv->elements[j].tag == TAG(DST_ALG_ED25519, i)) { break; } } - if (i == EDDSA_NTAGS) + if (i == EDDSA_NTAGS) { return (-1); + } have[i] = true; } mask = (1ULL << TAG_SHIFT) - 1; - if (have[TAG_EDDSA_ENGINE & mask]) + if (have[TAG_EDDSA_ENGINE & mask]) { ok = have[TAG_EDDSA_LABEL & mask]; - else + } else { ok = have[TAG_EDDSA_PRIVATEKEY & mask]; + } return (ok ? 0 : -1); } @@ -304,8 +321,9 @@ check_hmac_md5(const dst_private_t *priv, bool old) * the old format return success. */ if (old && priv->nelements == OLD_HMACMD5_NTAGS && - priv->elements[0].tag == TAG_HMACMD5_KEY) + priv->elements[0].tag == TAG_HMACMD5_KEY) { return (0); + } return (-1); } /* @@ -317,8 +335,9 @@ check_hmac_md5(const dst_private_t *priv, bool old) break; } } - if (j == priv->nelements) + if (j == priv->nelements) { return (-1); + } } return (0); } @@ -327,16 +346,18 @@ static int check_hmac_sha(const dst_private_t *priv, unsigned int ntags, unsigned int alg) { unsigned int i, j; - if (priv->nelements != ntags) + if (priv->nelements != ntags) { return (-1); + } for (i = 0; i < ntags; i++) { for (j = 0; j < priv->nelements; j++) { if (priv->elements[j].tag == TAG(alg, i)) { break; } } - if (j == priv->nelements) + if (j == priv->nelements) { return (-1); + } } return (0); } @@ -383,11 +404,13 @@ dst__privstruct_free(dst_private_t *priv, isc_mem_t *mctx) { int i; - if (priv == NULL) + if (priv == NULL) { return; + } for (i = 0; i < priv->nelements; i++) { - if (priv->elements[i].data == NULL) + if (priv->elements[i].data == NULL) { continue; + } memset(priv->elements[i].data, 0, MAXFIELDSIZE); isc_mem_put(mctx, priv->elements[i].data, MAXFIELDSIZE); } @@ -488,10 +511,12 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, isc_region_t r; do { ret = isc_lex_gettoken(lex, opt, &token); - if (ret == ISC_R_EOF) + if (ret == ISC_R_EOF) { goto done; - if (ret != ISC_R_SUCCESS) + } + if (ret != ISC_R_SUCCESS) { goto fail; + } } while (token.type == isc_tokentype_eol); if (token.type != isc_tokentype_string) { @@ -531,8 +556,9 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, } ret = dns_time32_fromtext(DST_AS_STR(token), &when); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto fail; + } dst_key_settime(key, tag, when); @@ -541,9 +567,9 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, /* Key data */ tag = find_value(DST_AS_STR(token), alg); - if (tag < 0 && minor > DST_MINOR_VERSION) + if (tag < 0 && minor > DST_MINOR_VERSION) { goto next; - else if (tag < 0) { + } else if (tag < 0) { ret = DST_R_INVALIDPRIVATEKEY; goto fail; } @@ -554,8 +580,9 @@ dst__privstruct_parse(dst_key_t *key, unsigned int alg, isc_lex_t *lex, isc_buffer_init(&b, data, MAXFIELDSIZE); ret = isc_base64_tobuffer(lex, &b, -1); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto fail; + } isc_buffer_usedregion(&b, &r); priv->elements[n].length = r.length; @@ -588,8 +615,9 @@ done: fail: dst__privstruct_free(priv, mctx); - if (data != NULL) + if (data != NULL) { isc_mem_put(mctx, data, MAXFIELDSIZE); + } return (ret); } @@ -614,15 +642,17 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, REQUIRE(priv != NULL); ret = check_data(priv, dst_key_alg(key), false, key->external); - if (ret < 0) + if (ret < 0) { return (DST_R_INVALIDPRIVATEKEY); - else if (ret != ISC_R_SUCCESS) + } else if (ret != ISC_R_SUCCESS) { return (ret); + } isc_buffer_init(&b, filename, sizeof(filename)); result = dst_key_buildfilename(key, DST_TYPE_PRIVATE, directory, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = isc_file_mode(filename, &mode); if (result == ISC_R_SUCCESS && mode != 0600) { @@ -633,9 +663,9 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, /* Windows security model is pretty different, * e.g., there is no umask... */ level = ISC_LOG_NOTICE; -#else +#else /* ifdef _WIN32 */ level = ISC_LOG_WARNING; -#endif +#endif /* ifdef _WIN32 */ isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_DNSSEC, level, "Permissions on the file %s " @@ -644,8 +674,9 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, filename, (unsigned int)mode); } - if ((fp = fopen(filename, "w")) == NULL) + if ((fp = fopen(filename, "w")) == NULL) { return (DST_R_WRITEERROR); + } access = 0; isc_fsaccess_add(ISC_FSACCESS_OWNER, @@ -733,23 +764,26 @@ dst__privstruct_writefile(const dst_key_t *key, const dst_private_t *priv, fprintf(fp, "%s %.*s\n", s, (int)r.length, r.base); } - if (key->external) + if (key->external) { fprintf(fp, "External:\n"); + } /* Add the metadata tags */ if (major > 1 || (major == 1 && minor >= 3)) { for (i = 0; i < NUMERIC_NTAGS; i++) { result = dst_key_getnum(key, i, &value); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } if (numerictags[i] != NULL) { fprintf(fp, "%s %u\n", numerictags[i], value); } } for (i = 0; i < TIMING_NTAGS; i++) { result = dst_key_gettime(key, i, &when); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } isc_buffer_init(&b, buffer, sizeof(buffer)); result = dns_time32_totext(when, &b); diff --git a/lib/dns/dst_result.c b/lib/dns/dst_result.c index 355f8e2e2d..77b016dbef 100644 --- a/lib/dns/dst_result.c +++ b/lib/dns/dst_result.c @@ -77,14 +77,16 @@ initialize_action(void) result = isc_result_register(ISC_RESULTCLASS_DST, DST_R_NRESULTS, text, DST_RESULT_RESULTSET); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_result_register() failed: %u", result); + } result = isc_result_registerids(ISC_RESULTCLASS_DST, DST_R_NRESULTS, ids, DST_RESULT_RESULTSET); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_result_registerids() failed: %u", result); + } } static void diff --git a/lib/dns/dyndb.c b/lib/dns/dyndb.c index 8f574df742..5dfab9ee82 100644 --- a/lib/dns/dyndb.c +++ b/lib/dns/dyndb.c @@ -13,7 +13,7 @@ #include #elif _WIN32 #include -#endif +#endif /* if HAVE_DLFCN_H */ #include @@ -98,8 +98,9 @@ load_symbol(void *handle, const char *filename, const char *symbol_name, symbol = dlsym(handle, symbol_name); if (symbol == NULL) { errmsg = dlerror(); - if (errmsg == NULL) + if (errmsg == NULL) { errmsg = "returned function pointer is NULL"; + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR, "failed to lookup symbol %s in " @@ -135,11 +136,12 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, flags = RTLD_NOW | RTLD_LOCAL; #if defined(RTLD_DEEPBIND) && !__SANITIZE_ADDRESS__ flags |= RTLD_DEEPBIND; -#endif +#endif /* if defined(RTLD_DEEPBIND) && !__SANITIZE_ADDRESS__ */ handle = dlopen(filename, flags); - if (handle == NULL) + if (handle == NULL) { CHECK(ISC_R_FAILURE); + } /* Clear dlerror */ dlerror(); @@ -178,18 +180,21 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, imp = NULL; cleanup: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR, "failed to dynamically load instance '%s' " "driver '%s': %s (%s)", instname, filename, dlerror(), isc_result_totext(result)); - if (imp != NULL) + } + if (imp != NULL) { isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t)); - if (result != ISC_R_SUCCESS && handle != NULL) + } + if (result != ISC_R_SUCCESS && handle != NULL) { dlclose(handle); + } return (result); } @@ -252,8 +257,9 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, instname, filename); handle = LoadLibraryA(filename); - if (handle == NULL) + if (handle == NULL) { CHECK(ISC_R_FAILURE); + } CHECK(load_symbol(handle, filename, "dyndb_version", (void **)&version_func)); @@ -289,18 +295,21 @@ load_library(isc_mem_t *mctx, const char *filename, const char *instname, imp = NULL; cleanup: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_DYNDB, ISC_LOG_ERROR, "failed to dynamically load instance '%s' " "driver '%s': %d (%s)", instname, filename, GetLastError(), isc_result_totext(result)); - if (imp != NULL) + } + if (imp != NULL) { isc_mem_putanddetach(&imp->mctx, imp, sizeof(dyndb_implementation_t)); - if (result != ISC_R_SUCCESS && handle != NULL) + } + if (result != ISC_R_SUCCESS && handle != NULL) { FreeLibrary(handle); + } return (result); } @@ -358,8 +367,9 @@ dns_dyndb_load(const char *libname, const char *name, const char *parameters, LOCK(&dyndb_lock); /* duplicate instance names are not allowed */ - if (impfind(name) != NULL) + if (impfind(name) != NULL) { CHECK(ISC_R_EXISTS); + } CHECK(load_library(mctx, libname, name, &implementation)); CHECK(implementation->register_func(mctx, name, parameters, file, line, @@ -372,7 +382,6 @@ cleanup: if (result != ISC_R_SUCCESS) { if (implementation != NULL) { unload_library(&implementation); - } } @@ -403,8 +412,9 @@ dns_dyndb_cleanup(bool exiting) } UNLOCK(&dyndb_lock); - if (exiting == true) + if (exiting == true) { isc_mutex_destroy(&dyndb_lock); + } } isc_result_t @@ -419,12 +429,15 @@ dns_dyndb_createctx(isc_mem_t *mctx, const void *hashinit, isc_log_t *lctx, dctx = isc_mem_get(mctx, sizeof(*dctx)); memset(dctx, 0, sizeof(*dctx)); - if (view != NULL) + if (view != NULL) { dns_view_attach(view, &dctx->view); - if (zmgr != NULL) + } + if (zmgr != NULL) { dns_zonemgr_attach(zmgr, &dctx->zmgr); - if (task != NULL) + } + if (task != NULL) { isc_task_attach(task, &dctx->task); + } dctx->timermgr = tmgr; dctx->hashinit = hashinit; dctx->lctx = lctx; @@ -450,12 +463,15 @@ dns_dyndb_destroyctx(dns_dyndbctx_t **dctxp) dctx->magic = 0; - if (dctx->view != NULL) + if (dctx->view != NULL) { dns_view_detach(&dctx->view); - if (dctx->zmgr != NULL) + } + if (dctx->zmgr != NULL) { dns_zonemgr_detach(&dctx->zmgr); - if (dctx->task != NULL) + } + if (dctx->task != NULL) { isc_task_detach(&dctx->task); + } dctx->timermgr = NULL; dctx->lctx = NULL; diff --git a/lib/dns/ecdb.c b/lib/dns/ecdb.c index 96967e9124..d97a6bf890 100644 --- a/lib/dns/ecdb.c +++ b/lib/dns/ecdb.c @@ -382,10 +382,12 @@ bind_rdataset(dns_ecdb_t *ecdb, dns_ecdbnode_t *node, rdatasetheader_t *header, rdataset->covers = header->covers; rdataset->ttl = header->ttl; rdataset->trust = header->trust; - if (NXDOMAIN(header)) + if (NXDOMAIN(header)) { rdataset->attributes |= DNS_RDATASETATTR_NXDOMAIN; - if (NEGATIVE(header)) + } + if (NEGATIVE(header)) { rdataset->attributes |= DNS_RDATASETATTR_NEGATIVE; + } rdataset->private1 = ecdb; rdataset->private2 = node; @@ -437,8 +439,9 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, result = dns_rdataslab_fromrdataset(rdataset, mctx, &r, sizeof(rdatasetheader_t)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } header = (rdatasetheader_t *)r.base; header->type = rdataset->type; @@ -446,15 +449,18 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, header->trust = rdataset->trust; header->covers = rdataset->covers; header->attributes = 0; - if ((rdataset->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0) + if ((rdataset->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0) { header->attributes |= RDATASET_ATTR_NXDOMAIN; - if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) + } + if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) { header->attributes |= RDATASET_ATTR_NEGATIVE; + } ISC_LINK_INIT(header, link); ISC_LIST_APPEND(ecdbnode->rdatasets, header, link); - if (addedrdataset == NULL) + if (addedrdataset == NULL) { goto unlock; + } bind_rdataset(ecdb, ecdbnode, header, addedrdataset); @@ -637,9 +643,9 @@ rdataset_first(dns_rdataset_t *rdataset) } #if DNS_RDATASET_FIXED raw += 2 + (4 * count); -#else +#else /* if DNS_RDATASET_FIXED */ raw += 2; -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * The privateuint4 field is the number of rdata beyond the cursor * position, so we decrement the total count by one before storing @@ -660,17 +666,18 @@ rdataset_next(dns_rdataset_t *rdataset) unsigned char *raw; count = rdataset->privateuint4; - if (count == 0) + if (count == 0) { return (ISC_R_NOMORE); + } count--; rdataset->privateuint4 = count; raw = rdataset->private5; length = raw[0] * 256 + raw[1]; #if DNS_RDATASET_FIXED raw += length + 4; -#else +#else /* if DNS_RDATASET_FIXED */ raw += length + 2; -#endif +#endif /* if DNS_RDATASET_FIXED */ rdataset->private5 = raw; return (ISC_R_SUCCESS); @@ -689,12 +696,13 @@ rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) length = raw[0] * 256 + raw[1]; #if DNS_RDATASET_FIXED raw += 4; -#else +#else /* if DNS_RDATASET_FIXED */ raw += 2; -#endif +#endif /* if DNS_RDATASET_FIXED */ if (rdataset->type == dns_rdatatype_rrsig) { - if ((*raw & DNS_RDATASLAB_OFFLINE) != 0) + if ((*raw & DNS_RDATASLAB_OFFLINE) != 0) { flags |= DNS_RDATA_OFFLINE; + } length--; raw++; } diff --git a/lib/dns/forward.c b/lib/dns/forward.c index 82c4a87d79..443b0df3e5 100644 --- a/lib/dns/forward.c +++ b/lib/dns/forward.c @@ -48,12 +48,14 @@ dns_fwdtable_create(isc_mem_t *mctx, dns_fwdtable_t **fwdtablep) fwdtable->table = NULL; result = dns_rbt_create(mctx, auto_detach, fwdtable, &fwdtable->table); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_fwdtable; + } result = isc_rwlock_init(&fwdtable->rwlock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rbt; + } fwdtable->mctx = NULL; isc_mem_attach(mctx, &fwdtable->mctx); @@ -97,8 +99,9 @@ dns_fwdtable_addfwd(dns_fwdtable_t *fwdtable, const dns_name_t *name, result = dns_rbt_addname(fwdtable->table, name, forwarders); RWUNLOCK(&fwdtable->rwlock, isc_rwlocktype_write); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } return (ISC_R_SUCCESS); @@ -140,8 +143,9 @@ dns_fwdtable_add(dns_fwdtable_t *fwdtable, const dns_name_t *name, result = dns_rbt_addname(fwdtable->table, name, forwarders); RWUNLOCK(&fwdtable->rwlock, isc_rwlocktype_write); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } return (ISC_R_SUCCESS); @@ -166,8 +170,9 @@ dns_fwdtable_delete(dns_fwdtable_t *fwdtable, const dns_name_t *name) result = dns_rbt_deletename(fwdtable->table, name, false); RWUNLOCK(&fwdtable->rwlock, isc_rwlocktype_write); - if (result == DNS_R_PARTIALMATCH) + if (result == DNS_R_PARTIALMATCH) { result = ISC_R_NOTFOUND; + } return (result); } @@ -184,8 +189,9 @@ dns_fwdtable_find(dns_fwdtable_t *fwdtable, const dns_name_t *name, result = dns_rbt_findname(fwdtable->table, name, 0, foundname, (void **)forwardersp); - if (result == DNS_R_PARTIALMATCH) + if (result == DNS_R_PARTIALMATCH) { result = ISC_R_SUCCESS; + } RWUNLOCK(&fwdtable->rwlock, isc_rwlocktype_read); diff --git a/lib/dns/gen-unix.h b/lib/dns/gen-unix.h index 2d621105a8..d6a50d1d7a 100644 --- a/lib/dns/gen-unix.h +++ b/lib/dns/gen-unix.h @@ -37,7 +37,7 @@ #ifdef NEED_OPTARG extern char *optarg; -#endif +#endif /* ifdef NEED_OPTARG */ #define isc_commandline_parse getopt #define isc_commandline_argument optarg @@ -54,10 +54,11 @@ start_directory(const char *path, isc_dir_t *dir) { dir->handle = opendir(path); - if (dir->handle != NULL) + if (dir->handle != NULL) { return (true); - else + } else { return (false); + } } static bool @@ -79,17 +80,19 @@ next_file(isc_dir_t *dir) } } - if (dir->filename != NULL) + if (dir->filename != NULL) { return (true); - else + } else { return (false); + } } static void end_directory(isc_dir_t *dir) { - if (dir->handle != NULL) + if (dir->handle != NULL) { (void)closedir(dir->handle); + } dir->handle = NULL; } diff --git a/lib/dns/gen-win32.h b/lib/dns/gen-win32.h index 74c3b6bf20..f602edac8c 100644 --- a/lib/dns/gen-win32.h +++ b/lib/dns/gen-win32.h @@ -98,8 +98,9 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) if (isc_commandline_reset || *place == '\0') { isc_commandline_reset = false; - if (isc_commandline_progname == NULL) + if (isc_commandline_progname == NULL) { isc_commandline_progname = argv[0]; + } if (isc_commandline_index >= argc || *(place = argv[isc_commandline_index]) != '-') { @@ -130,13 +131,15 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) * distinguish ':' from the argument specifier in the options string. */ if (isc_commandline_option == ':' || option == NULL) { - if (*place == '\0') + if (*place == '\0') { isc_commandline_index++; + } - if (isc_commandline_errprint && *options != ':') + if (isc_commandline_errprint && *options != ':') { fprintf(stderr, "%s: illegal option -- %c\n", isc_commandline_progname, isc_commandline_option); + } return (BADOPT); } @@ -150,26 +153,24 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) /* * Skip to next argv if at the end of the current argv. */ - if (*place == '\0') + if (*place == '\0') { ++isc_commandline_index; - + } } else { /* * Option needs an argument. */ - if (*place != '\0') + if (*place != '\0') { /* * Option is in this argv, -D1 style. */ isc_commandline_argument = place; - - else if (argc > ++isc_commandline_index) + } else if (argc > ++isc_commandline_index) { /* * Option is next argv, -D 1 style. */ isc_commandline_argument = argv[isc_commandline_index]; - - else { + } else { /* * Argument needed, but no more argv. */ @@ -179,15 +180,17 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) * Silent failure with "missing argument" return * when ':' starts options string, per historical spec. */ - if (*options == ':') + if (*options == ':') { return (BADARG); + } - if (isc_commandline_errprint) + if (isc_commandline_errprint) { fprintf(stderr, "%s: option requires an argument -- " "%c\n", isc_commandline_progname, isc_commandline_option); + } return (BADOPT); } @@ -218,8 +221,9 @@ start_directory(const char *path, isc_dir_t *dir) /* * Need space for slash-splat and final NUL. */ - if (strlen(path) + 3 > sizeof(pattern)) + if (strlen(path) + 3 > sizeof(pattern)) { return (false); + } strcpy(pattern, path); @@ -227,8 +231,9 @@ start_directory(const char *path, isc_dir_t *dir) * Append slash (if needed) and splat. */ p = pattern + strlen(pattern); - if (p != pattern && p[-1] != '\\' && p[-1] != ':') + if (p != pattern && p[-1] != '\\' && p[-1] != ':') { *p++ = '\\'; + } *p++ = '*'; *p++ = '\0'; @@ -248,29 +253,31 @@ start_directory(const char *path, isc_dir_t *dir) bool next_file(isc_dir_t *dir) { - if (dir->first_file) + if (dir->first_file) { dir->first_file = false; - - else if (dir->handle != INVALID_HANDLE_VALUE) { - if (FindNextFile(dir->handle, &dir->find_data) == TRUE) + } else if (dir->handle != INVALID_HANDLE_VALUE) { + if (FindNextFile(dir->handle, &dir->find_data) == TRUE) { dir->filename = dir->find_data.cFileName; - else + } else { dir->filename = NULL; - - } else + } + } else { dir->filename = NULL; + } - if (dir->filename != NULL) + if (dir->filename != NULL) { return (true); - else + } else { return (false); + } } void end_directory(isc_dir_t *dir) { - if (dir->handle != INVALID_HANDLE_VALUE) + if (dir->handle != INVALID_HANDLE_VALUE) { FindClose(dir->handle); + } } ISC_LANG_ENDDECLS diff --git a/lib/dns/gen.c b/lib/dns/gen.c index e2a570661c..41a659607d 100644 --- a/lib/dns/gen.c +++ b/lib/dns/gen.c @@ -21,8 +21,8 @@ */ #if _MSC_VER < 1900 #define snprintf _snprintf -#endif -#endif +#endif /* if _MSC_VER < 1900 */ +#endif /* ifdef WIN32 */ #include #include @@ -37,17 +37,17 @@ #ifndef PATH_MAX #define PATH_MAX 1024 -#endif +#endif /* ifndef PATH_MAX */ #ifdef WIN32 #include "gen-win32.h" -#else +#else /* ifdef WIN32 */ #include "gen-unix.h" -#endif +#endif /* ifdef WIN32 */ #ifndef ULLONG_MAX #define ULLONG_MAX (~0ULL) -#endif +#endif /* ifndef ULLONG_MAX */ #define INSIST(cond) \ if (!(cond)) { \ @@ -199,14 +199,16 @@ upper(char *s) int c; buf_to_use++; - if (buf_to_use > 9) + if (buf_to_use > 9) { buf_to_use = 0; + } b = buf[buf_to_use]; memset(b, 0, 256); - while ((c = (*s++) & 0xff)) + while ((c = (*s++) & 0xff)) { *b++ = islower(c) ? toupper(c) : c; + } *b = '\0'; return (buf[buf_to_use]); } @@ -236,8 +238,9 @@ doswitch(const char *name, const char *function, const char *args, char buf1[TYPECLASSBUF], buf2[TYPECLASSBUF]; const char *result = " result ="; - if (res == NULL) + if (res == NULL) { result = ""; + } for (tt = types; tt != NULL; tt = tt->next) { if (first) { @@ -246,11 +249,12 @@ doswitch(const char *name, const char *function, const char *args, first = 0; } if (tt->type != lasttype && subswitch) { - if (res == NULL) + if (res == NULL) { fprintf(stdout, "\t\tdefault: break; \\\n"); - else + } else { fprintf(stdout, "\t\tdefault: %s; break; \\\n", res); + } fputs(/*{*/ "\t\t} \\\n", stdout); fputs("\t\tbreak; \\\n", stdout); subswitch = 0; @@ -260,36 +264,40 @@ doswitch(const char *name, const char *function, const char *args, tt->type, csw); subswitch = 1; } - if (tt->rdclass == 0) + if (tt->rdclass == 0) { fprintf(stdout, "\tcase %d:%s %s_%s(%s); break;", tt->type, result, function, funname(tt->typebuf, buf1), args); - else + } else { fprintf(stdout, "\t\tcase %d:%s %s_%s_%s(%s); break;", tt->rdclass, result, function, funname(tt->classbuf, buf1), funname(tt->typebuf, buf2), args); + } fputs(" \\\n", stdout); lasttype = tt->type; } if (subswitch) { - if (res == NULL) + if (res == NULL) { fprintf(stdout, "\t\tdefault: break; \\\n"); - else + } else { fprintf(stdout, "\t\tdefault: %s; break; \\\n", res); + } fputs(/*{*/ "\t\t} \\\n", stdout); fputs("\t\tbreak; \\\n", stdout); } if (first) { - if (res == NULL) + if (res == NULL) { fprintf(stdout, "\n#define %s\n", name); - else + } else { fprintf(stdout, "\n#define %s %s;\n", name, res); + } } else { - if (res == NULL) + if (res == NULL) { fprintf(stdout, "\tdefault: break; \\\n"); - else + } else { fprintf(stdout, "\tdefault: %s; break; \\\n", res); + } fputs(/*{*/ "\t}\n", stdout); } } @@ -529,7 +537,7 @@ HASH(char *string) a = tolower((unsigned char)string[0]); b = tolower((unsigned char)string[n - 1]); - return ((a + n) * b) % 256; + return (((a + n) * b) % 256); } int @@ -563,11 +571,12 @@ main(int argc, char **argv) char * endptr; isc_dir_t dir; - for (i = 0; i < TYPENAMES; i++) + for (i = 0; i < TYPENAMES; i++) { memset(&typenames[i], 0, sizeof(typenames[i])); + } srcdir[0] = '\0'; - while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1) + while ((c = isc_commandline_parse(argc, argv, "cdits:F:P:S:")) != -1) { switch (c) { case 'c': code = 0; @@ -625,6 +634,7 @@ main(int argc, char **argv) case '?': exit(1); } + } n = snprintf(buf, sizeof(buf), "%srdata", srcdir); INSIST(n > 0 && (unsigned)n < sizeof(srcdir)); @@ -942,7 +952,6 @@ main(int argc, char **argv) "((dns_rdatatype_t)dns_rdatatype_any)\n"); fprintf(stdout, "\n#endif /* DNS_ENUMTYPE_H */\n"); - } else if (class_enum) { char *s; int classnum; diff --git a/lib/dns/geoip2.c b/lib/dns/geoip2.c index aa9fe6fe03..f5503e8b59 100644 --- a/lib/dns/geoip2.c +++ b/lib/dns/geoip2.c @@ -32,10 +32,10 @@ #include #ifndef WIN32 #include -#else +#else /* ifndef WIN32 */ #ifndef _WINSOCKAPI_ #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ -#endif +#endif /* ifndef _WINSOCKAPI_ */ #include #endif /* WIN32 */ #include diff --git a/lib/dns/gssapi_link.c b/lib/dns/gssapi_link.c index d638d6bb8a..f786d28ff6 100644 --- a/lib/dns/gssapi_link.c +++ b/lib/dns/gssapi_link.c @@ -74,8 +74,9 @@ gssapi_destroy_signverify_ctx(dst_context_t *dctx) dst_gssapi_signverifyctx_t *ctx = dctx->ctxdata.gssctx; if (ctx != NULL) { - if (ctx->buffer != NULL) + if (ctx->buffer != NULL) { isc_buffer_free(&ctx->buffer); + } isc_mem_put(dctx->mctx, ctx, sizeof(dst_gssapi_signverifyctx_t)); dctx->ctxdata.gssctx = NULL; @@ -98,8 +99,9 @@ gssapi_adddata(dst_context_t *dctx, const isc_region_t *data) isc_result_t result; result = isc_buffer_copyregion(ctx->buffer, data); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } length = isc_buffer_length(ctx->buffer) + data->length + BUFFER_EXTRA; @@ -164,8 +166,9 @@ gssapi_sign(dst_context_t *dctx, isc_buffer_t *sig) * allocated space. */ isc_buffer_putmem(sig, gsig.value, (unsigned int)gsig.length); - if (gsig.length != 0U) + if (gsig.length != 0U) { gss_release_buffer(&minor, &gsig); + } return (ISC_R_SUCCESS); } @@ -211,10 +214,11 @@ gssapi_verify(dst_context_t *dctx, const isc_region_t *sig) gret == GSS_S_DUPLICATE_TOKEN || gret == GSS_S_OLD_TOKEN || gret == GSS_S_UNSEQ_TOKEN || gret == GSS_S_GAP_TOKEN || gret == GSS_S_CONTEXT_EXPIRED || gret == GSS_S_NO_CONTEXT || - gret == GSS_S_FAILURE) + gret == GSS_S_FAILURE) { return (DST_R_VERIFYFAILURE); - else + } else { return (ISC_R_FAILURE); + } } return (ISC_R_SUCCESS); @@ -267,8 +271,9 @@ gssapi_restore(dst_key_t *key, const char *keystr) isc_result_t result; len = strlen(keystr); - if ((len % 4) != 0U) + if ((len % 4) != 0U) { return (ISC_R_BADBASE64); + } len = (len / 4) * 3; @@ -311,8 +316,9 @@ gssapi_dump(dst_key_t *key, isc_mem_t *mctx, char **buffer, int *length) minor); return (ISC_R_FAILURE); } - if (gssbuffer.length == 0U) + if (gssbuffer.length == 0U) { return (ISC_R_FAILURE); + } len = ((gssbuffer.length + 2) / 3) * 4; buf = isc_mem_get(mctx, len); isc_buffer_init(&b, buf, (unsigned int)len); @@ -353,13 +359,14 @@ isc_result_t dst__gssapi_init(dst_func_t **funcp) { REQUIRE(funcp != NULL); - if (*funcp == NULL) + if (*funcp == NULL) { *funcp = &gssapi_functions; + } return (ISC_R_SUCCESS); } -#else +#else /* ifdef GSSAPI */ int gssapi_link_unneeded = 1; -#endif +#endif /* ifdef GSSAPI */ /*! \file */ diff --git a/lib/dns/gssapictx.c b/lib/dns/gssapictx.c index 22d743c912..5fb329e79d 100644 --- a/lib/dns/gssapictx.c +++ b/lib/dns/gssapictx.c @@ -50,7 +50,7 @@ #include "spnego.h" #define gss_accept_sec_context gss_accept_sec_context_spnego #define gss_init_sec_context gss_init_sec_context_spnego -#endif +#endif /* if defined(GSSAPI) && defined(USE_ISC_SPNEGO) */ /* * Solaris8 apparently needs an explicit OID set, and Solaris10 needs @@ -62,9 +62,9 @@ #ifdef GSSAPI #ifdef WIN32 #include -#else +#else /* ifdef WIN32 */ #include ISC_PLATFORM_KRB5HEADER -#endif +#endif /* ifdef WIN32 */ static unsigned char krb5_mech_oid_bytes[] = { 0x2a, 0x86, 0x48, 0x86, 0xf7, 0x12, 0x01, 0x02, 0x02 }; @@ -72,20 +72,20 @@ static unsigned char krb5_mech_oid_bytes[] = { 0x2a, 0x86, 0x48, 0x86, 0xf7, #ifndef USE_ISC_SPNEGO static unsigned char spnego_mech_oid_bytes[] = { 0x2b, 0x06, 0x01, 0x05, 0x05, 0x02 }; -#endif +#endif /* ifndef USE_ISC_SPNEGO */ static gss_OID_desc mech_oid_set_array[] = { { sizeof(krb5_mech_oid_bytes), krb5_mech_oid_bytes }, #ifndef USE_ISC_SPNEGO { sizeof(spnego_mech_oid_bytes), spnego_mech_oid_bytes }, -#endif +#endif /* ifndef USE_ISC_SPNEGO */ }; static gss_OID_set_desc mech_oid_set = { sizeof(mech_oid_set_array) / sizeof(*mech_oid_set_array), mech_oid_set_array }; -#endif +#endif /* ifdef GSSAPI */ #define REGION_TO_GBUFFER(r, gb) \ do { \ @@ -116,9 +116,9 @@ name_to_gbuffer(const dns_name_t *name, isc_buffer_t *buffer, isc_region_t r; isc_result_t result; - if (!dns_name_isabsolute(name)) + if (!dns_name_isabsolute(name)) { namep = name; - else { + } else { unsigned int labels; dns_name_init(&tname, NULL); labels = dns_name_countlabels(name); @@ -151,10 +151,10 @@ log_cred(const gss_cred_id_t cred) } gret = gss_display_name(&minor, gname, &gbuffer, NULL); - if (gret != GSS_S_COMPLETE) + if (gret != GSS_S_COMPLETE) { gss_log(3, "failed gss_display_name: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); - else { + } else { switch (usage) { case GSS_C_BOTH: usage_text = "GSS_C_BOTH"; @@ -175,19 +175,21 @@ log_cred(const gss_cred_id_t cred) if (gret == GSS_S_COMPLETE) { if (gbuffer.length != 0U) { gret = gss_release_buffer(&minor, &gbuffer); - if (gret != GSS_S_COMPLETE) + if (gret != GSS_S_COMPLETE) { gss_log(3, "failed gss_release_buffer: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); + } } } gret = gss_release_name(&minor, &gname); - if (gret != GSS_S_COMPLETE) + if (gret != GSS_S_COMPLETE) { gss_log(3, "failed gss_release_name: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); + } } -#endif +#endif /* ifdef GSSAPI */ #ifdef GSSAPI /* @@ -244,7 +246,7 @@ check_config(const char *gss_name) } krb5_free_context(krb5_ctx); } -#endif +#endif /* ifdef GSSAPI */ isc_result_t dst_gssapi_acquirecred(const dns_name_t *name, bool initiate, @@ -284,22 +286,24 @@ dst_gssapi_acquirecred(const dns_name_t *name, bool initiate, sizeof(buf))); return (ISC_R_FAILURE); } - } else + } else { gname = NULL; + } /* Get the credentials. */ - if (gname != NULL) + if (gname != NULL) { gss_log(3, "acquiring credentials for %s", (char *)gnamebuf.value); - else { + } else { /* XXXDCL does this even make any sense? */ gss_log(3, "acquiring credentials for ?"); } - if (initiate) + if (initiate) { usage = GSS_C_INITIATE; - else + } else { usage = GSS_C_ACCEPT; + } gret = gss_acquire_cred(&minor, gname, GSS_C_INDEFINITE, &mech_oid_set, usage, cred, NULL, &lifetime); @@ -309,8 +313,9 @@ dst_gssapi_acquirecred(const dns_name_t *name, bool initiate, initiate ? "initiate" : "accept", (gname != NULL) ? (char *)gnamebuf.value : "?", gss_error_tostring(gret, minor, buf, sizeof(buf))); - if (gname != NULL) + if (gname != NULL) { check_config((char *)array); + } result = ISC_R_FAILURE; goto cleanup; } @@ -325,14 +330,15 @@ dst_gssapi_acquirecred(const dns_name_t *name, bool initiate, cleanup: if (gname != NULL) { gret = gss_release_name(&minor, &gname); - if (gret != GSS_S_COMPLETE) + if (gret != GSS_S_COMPLETE) { gss_log(3, "failed gss_release_name: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); + } } return (result); -#else +#else /* ifdef GSSAPI */ REQUIRE(cred != NULL && *cred == NULL); UNUSED(name); @@ -340,7 +346,7 @@ cleanup: UNUSED(cred); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef GSSAPI */ } bool @@ -420,13 +426,13 @@ dst_gssapi_identitymatchesrealmkrb5(const dns_name_t *signer, } return (true); -#else +#else /* ifdef GSSAPI */ UNUSED(signer); UNUSED(name); UNUSED(realm); UNUSED(subdomain); return (false); -#endif +#endif /* ifdef GSSAPI */ } bool @@ -509,13 +515,13 @@ dst_gssapi_identitymatchesrealmms(const dns_name_t *signer, } return (true); -#else +#else /* ifdef GSSAPI */ UNUSED(signer); UNUSED(name); UNUSED(realm); UNUSED(subdomain); return (false); -#endif +#endif /* ifdef GSSAPI */ } isc_result_t @@ -536,11 +542,11 @@ dst_gssapi_releasecred(gss_cred_id_t *cred) *cred = NULL; return (ISC_R_SUCCESS); -#else +#else /* ifdef GSSAPI */ UNUSED(cred); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef GSSAPI */ } #ifdef GSSAPI @@ -562,10 +568,11 @@ gss_err_message(isc_mem_t *mctx, uint32_t major, uint32_t minor, } estr = gss_error_tostring(major, minor, buf, sizeof(buf)); - if (estr != NULL) + if (estr != NULL) { (*err_message) = isc_mem_strdup(mctx, estr); + } } -#endif +#endif /* ifdef GSSAPI */ isc_result_t dst_gssapi_initctx(const dns_name_t *name, isc_buffer_t *intoken, @@ -618,11 +625,12 @@ dst_gssapi_initctx(const dns_name_t *name, isc_buffer_t *intoken, if (gret != GSS_S_COMPLETE && gret != GSS_S_CONTINUE_NEEDED) { gss_err_message(mctx, gret, minor, err_message); - if (err_message != NULL && *err_message != NULL) + if (err_message != NULL && *err_message != NULL) { gss_log(3, "Failure initiating security context: %s", *err_message); - else + } else { gss_log(3, "Failure initiating security context"); + } result = ISC_R_FAILURE; goto out; @@ -641,17 +649,19 @@ dst_gssapi_initctx(const dns_name_t *name, isc_buffer_t *intoken, RETERR(isc_buffer_copyregion(outtoken, &r)); } - if (gret == GSS_S_COMPLETE) + if (gret == GSS_S_COMPLETE) { result = ISC_R_SUCCESS; - else + } else { result = DNS_R_CONTINUE; + } out: - if (gouttoken.length != 0U) + if (gouttoken.length != 0U) { (void)gss_release_buffer(&minor, &gouttoken); + } (void)gss_release_name(&minor, &gname); return (result); -#else +#else /* ifdef GSSAPI */ UNUSED(name); UNUSED(intoken); UNUSED(outtoken); @@ -660,7 +670,7 @@ out: UNUSED(err_message); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef GSSAPI */ } isc_result_t @@ -684,10 +694,11 @@ dst_gssapi_acceptctx(gss_cred_id_t cred, const char *gssapi_keytab, REGION_TO_GBUFFER(*intoken, gintoken); - if (*ctxout == NULL) + if (*ctxout == NULL) { context = GSS_C_NO_CONTEXT; - else + } else { context = *ctxout; + } if (gssapi_keytab != NULL) { #if defined(ISC_PLATFORM_GSSAPI_KRB5_HEADER) || defined(WIN32) @@ -700,7 +711,7 @@ dst_gssapi_acceptctx(gss_cred_id_t cred, const char *gssapi_keytab, gss_error_tostring(gret, 0, buf, sizeof(buf))); return (DNS_R_INVALIDTKEY); } -#else +#else /* if defined(ISC_PLATFORM_GSSAPI_KRB5_HEADER) || defined(WIN32) */ /* * Minimize memory leakage by only setting KRB5_KTNAME * if it needs to change. @@ -712,13 +723,15 @@ dst_gssapi_acceptctx(gss_cred_id_t cred, const char *gssapi_keytab, size = strlen(gssapi_keytab) + 13; kt = malloc(size); - if (kt == NULL) + if (kt == NULL) { return (ISC_R_NOMEMORY); + } snprintf(kt, size, "KRB5_KTNAME=%s", gssapi_keytab); - if (putenv(kt) != 0) + if (putenv(kt) != 0) { return (ISC_R_NOMEMORY); + } } -#endif +#endif /* if defined(ISC_PLATFORM_GSSAPI_KRB5_HEADER) || defined(WIN32) */ } log_cred(cred); @@ -745,7 +758,7 @@ dst_gssapi_acceptctx(gss_cred_id_t cred, const char *gssapi_keytab, case GSS_S_BAD_MECH: case GSS_S_FAILURE: result = DNS_R_INVALIDTKEY; - /* fall through */ + /* fall through */ default: gss_log(3, "failed gss_accept_sec_context: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); @@ -776,8 +789,9 @@ dst_gssapi_acceptctx(gss_cred_id_t cred, const char *gssapi_keytab, * contain null characters. */ if (gnamebuf.length > 0U && - ((char *)gnamebuf.value)[gnamebuf.length - 1] == '\0') + ((char *)gnamebuf.value)[gnamebuf.length - 1] == '\0') { gnamebuf.length--; + } gss_log(3, "gss-api source name (accept) is %.*s", (int)gnamebuf.length, (char *)gnamebuf.value); @@ -791,27 +805,30 @@ dst_gssapi_acceptctx(gss_cred_id_t cred, const char *gssapi_keytab, if (gnamebuf.length != 0U) { gret = gss_release_buffer(&minor, &gnamebuf); - if (gret != GSS_S_COMPLETE) + if (gret != GSS_S_COMPLETE) { gss_log(3, "failed gss_release_buffer: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); + } } - } else + } else { result = DNS_R_CONTINUE; + } *ctxout = context; out: if (gname != NULL) { gret = gss_release_name(&minor, &gname); - if (gret != GSS_S_COMPLETE) + if (gret != GSS_S_COMPLETE) { gss_log(3, "failed gss_release_name: %s", gss_error_tostring(gret, minor, buf, sizeof(buf))); + } } return (result); -#else +#else /* ifdef GSSAPI */ UNUSED(cred); UNUSED(gssapi_keytab); UNUSED(intoken); @@ -821,7 +838,7 @@ out: UNUSED(mctx); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef GSSAPI */ } isc_result_t @@ -843,11 +860,11 @@ dst_gssapi_deletectx(isc_mem_t *mctx, gss_ctx_id_t *gssctx) gss_error_tostring(gret, minor, buf, sizeof(buf))); } return (ISC_R_SUCCESS); -#else +#else /* ifdef GSSAPI */ UNUSED(mctx); UNUSED(gssctx); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef GSSAPI */ } char * @@ -871,17 +888,19 @@ gss_error_tostring(uint32_t major, uint32_t minor, char *buf, size_t buflen) snprintf(buf, buflen, "GSSAPI error: Major = %s, Minor = %s.", (char *)msg_major.value, (char *)msg_minor.value); - if (msg_major.length != 0U) + if (msg_major.length != 0U) { (void)gss_release_buffer(&minor_stat, &msg_major); - if (msg_minor.length != 0U) + } + if (msg_minor.length != 0U) { (void)gss_release_buffer(&minor_stat, &msg_minor); + } return (buf); -#else +#else /* ifdef GSSAPI */ snprintf(buf, buflen, "GSSAPI error: Major = %u, Minor = %u.", major, minor); return (buf); -#endif +#endif /* ifdef GSSAPI */ } void diff --git a/lib/dns/hmac_link.c b/lib/dns/hmac_link.c index 7dd6089627..e851fb28bb 100644 --- a/lib/dns/hmac_link.c +++ b/lib/dns/hmac_link.c @@ -44,7 +44,7 @@ #include #ifdef HAVE_FIPS_MODE #include "dst_openssl.h" /* FIPS_mode() prototype */ -#endif +#endif /* ifdef HAVE_FIPS_MODE */ #include "dst_parse.h" #define ISC_MD_md5 ISC_MD_MD5 diff --git a/lib/dns/include/dns/acl.h b/lib/dns/include/dns/acl.h index 317f0808e7..d7699ba386 100644 --- a/lib/dns/include/dns/acl.h +++ b/lib/dns/include/dns/acl.h @@ -13,8 +13,8 @@ #define DNS_ACL_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/acl.h * \brief diff --git a/lib/dns/include/dns/adb.h b/lib/dns/include/dns/adb.h index d1ff7db3ef..c44102d8ed 100644 --- a/lib/dns/include/dns/adb.h +++ b/lib/dns/include/dns/adb.h @@ -13,8 +13,8 @@ #define DNS_ADB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/adb.h *\brief @@ -245,8 +245,8 @@ struct dns_adbaddrinfo { */ /**** - **** FUNCTIONS - ****/ +**** FUNCTIONS +****/ isc_result_t dns_adb_create(isc_mem_t *mem, dns_view_t *view, isc_timermgr_t *tmgr, diff --git a/lib/dns/include/dns/badcache.h b/lib/dns/include/dns/badcache.h index fab05e278a..39d249b342 100644 --- a/lib/dns/include/dns/badcache.h +++ b/lib/dns/include/dns/badcache.h @@ -13,8 +13,8 @@ #define DNS_BADCACHE_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/badcache.h * \brief diff --git a/lib/dns/include/dns/byaddr.h b/lib/dns/include/dns/byaddr.h index 1732dfdfbe..0606934cfc 100644 --- a/lib/dns/include/dns/byaddr.h +++ b/lib/dns/include/dns/byaddr.h @@ -13,8 +13,8 @@ #define DNS_BYADDR_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/byaddr.h * \brief diff --git a/lib/dns/include/dns/cache.h b/lib/dns/include/dns/cache.h index 80c7401a66..f64a626193 100644 --- a/lib/dns/include/dns/cache.h +++ b/lib/dns/include/dns/cache.h @@ -13,8 +13,8 @@ #define DNS_CACHE_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/cache.h * \brief diff --git a/lib/dns/include/dns/client.h b/lib/dns/include/dns/client.h index 486a48a4de..5e03fd86dd 100644 --- a/lib/dns/include/dns/client.h +++ b/lib/dns/include/dns/client.h @@ -13,8 +13,8 @@ #define DNS_CLIENT_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * diff --git a/lib/dns/include/dns/clientinfo.h b/lib/dns/include/dns/clientinfo.h index e9b4a779ee..376bb6cd07 100644 --- a/lib/dns/include/dns/clientinfo.h +++ b/lib/dns/include/dns/clientinfo.h @@ -13,8 +13,8 @@ #define DNS_CLIENTINFO_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/clientinfo.h * \brief @@ -33,8 +33,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include @@ -44,8 +44,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Types - *****/ +***** Types +*****/ #define DNS_CLIENTINFO_VERSION 2 typedef struct dns_clientinfo { @@ -67,8 +67,8 @@ typedef struct dns_clientinfomethods { } dns_clientinfomethods_t; /***** - ***** Methods - *****/ +***** Methods +*****/ void dns_clientinfomethods_init(dns_clientinfomethods_t * methods, dns_clientinfo_sourceip_t sourceip); diff --git a/lib/dns/include/dns/db.h b/lib/dns/include/dns/db.h index 0c9e6435d4..48947f43e8 100644 --- a/lib/dns/include/dns/db.h +++ b/lib/dns/include/dns/db.h @@ -13,8 +13,8 @@ #define DNS_DB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/db.h * \brief @@ -43,8 +43,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include #include @@ -65,8 +65,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Types - *****/ +***** Types +*****/ typedef struct dns_dbmethods { void (*attach)(dns_db_t *source, dns_db_t **targetp); @@ -266,8 +266,8 @@ struct dns_dbonupdatelistener { /*@}*/ /***** - ***** Methods - *****/ +***** Methods +*****/ /*** *** Basic DB Methods @@ -1229,7 +1229,7 @@ dns_db_addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, * * \li #ISC_R_SUCCESS * \li #DNS_R_UNCHANGED The operation did not change - *anything. \li #ISC_R_NOMEMORY \li #DNS_R_NOTEXACT + * anything. \li #ISC_R_NOMEMORY \li #DNS_R_NOTEXACT * * \li Other results are possible, depending upon the database * implementation used. @@ -1271,9 +1271,10 @@ dns_db_subtractrdataset(dns_db_t *db, dns_dbnode_t *node, * * \li #ISC_R_SUCCESS * \li #DNS_R_UNCHANGED The operation did not change - *anything. \li #DNS_R_NXRRSET All rdata of the same type as - *those in 'rdataset' have been deleted. \li #DNS_R_NOTEXACT - *Some part of 'rdataset' did not exist and DNS_DBSUB_EXACT was set. + * anything. \li #DNS_R_NXRRSET All rdata of the same + *type as + * those in 'rdataset' have been deleted. \li #DNS_R_NOTEXACT + * Some part of 'rdataset' did not exist and DNS_DBSUB_EXACT was set. * * \li Other results are possible, depending upon the database * implementation used. @@ -1312,7 +1313,7 @@ dns_db_deleterdataset(dns_db_t *db, dns_dbnode_t *node, * * \li #ISC_R_SUCCESS * \li #DNS_R_UNCHANGED No rdatasets of 'type' existed - *before the operation was attempted. + * before the operation was attempted. * * \li Other results are possible, depending upon the database * implementation used. diff --git a/lib/dns/include/dns/dbiterator.h b/lib/dns/include/dns/dbiterator.h index 3f68f12e21..cc54036da7 100644 --- a/lib/dns/include/dns/dbiterator.h +++ b/lib/dns/include/dns/dbiterator.h @@ -13,8 +13,8 @@ #define DNS_DBITERATOR_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/dbiterator.h * \brief @@ -50,8 +50,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include @@ -63,8 +63,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Types - *****/ +***** Types +*****/ typedef struct dns_dbiteratormethods { void (*destroy)(dns_dbiterator_t **iteratorp); @@ -221,8 +221,10 @@ dns_dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep, * *\li #ISC_R_SUCCESS *\li #DNS_R_NEWORIGIN If this iterator was created - *with 'relative_names' set to true, then #DNS_R_NEWORIGIN will be returned when - *the origin the names are relative to changes. This result can occur only when + * with 'relative_names' set to true, then #DNS_R_NEWORIGIN will be returned + *when + * the origin the names are relative to changes. This result can occur only + *when *'name' is not NULL. This is also a successful result. * *\li Other results are possible, depending on the DB implementation. diff --git a/lib/dns/include/dns/dbtable.h b/lib/dns/include/dns/dbtable.h index c641c5b330..7fa4034a29 100644 --- a/lib/dns/include/dns/dbtable.h +++ b/lib/dns/include/dns/dbtable.h @@ -13,8 +13,8 @@ #define DNS_DBTABLE_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/dbtable.h * \brief diff --git a/lib/dns/include/dns/diff.h b/lib/dns/include/dns/diff.h index 4445081e4b..2e63055fa7 100644 --- a/lib/dns/include/dns/diff.h +++ b/lib/dns/include/dns/diff.h @@ -13,8 +13,8 @@ #define DNS_DIFF_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/diff.h * \brief @@ -209,7 +209,7 @@ dns_diff_appendminimal(dns_diff_t *diff, dns_difftuple_t **tuple); *\li 'diff' is still a minimal diff. * \li *tuple is NULL. * \li The tuple has been freed, or will be freed when the diff is - *cleared. + * cleared. * */ diff --git a/lib/dns/include/dns/dispatch.h b/lib/dns/include/dns/dispatch.h index 478bd4dfd2..240ce7e9ef 100644 --- a/lib/dns/include/dns/dispatch.h +++ b/lib/dns/include/dns/dispatch.h @@ -13,8 +13,8 @@ #define DNS_DISPATCH_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/dispatch.h * \brief diff --git a/lib/dns/include/dns/dlz.h b/lib/dns/include/dns/dlz.h index f00cf650ce..68fc273abb 100644 --- a/lib/dns/include/dns/dlz.h +++ b/lib/dns/include/dns/dlz.h @@ -50,8 +50,8 @@ #define DLZ_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /* * DLZ Interface @@ -73,8 +73,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include diff --git a/lib/dns/include/dns/dlz_dlopen.h b/lib/dns/include/dns/dlz_dlopen.h index cdc25c511e..47e856c4ee 100644 --- a/lib/dns/include/dns/dlz_dlopen.h +++ b/lib/dns/include/dns/dlz_dlopen.h @@ -154,4 +154,4 @@ dlz_dlopen_delrdataset_t(const char *name, const char *type, void *dbdata, ISC_LANG_ENDDECLS -#endif +#endif /* ifndef DLZ_DLOPEN_H */ diff --git a/lib/dns/include/dns/dnssec.h b/lib/dns/include/dns/dnssec.h index 9a6f54a53e..4912a9f39d 100644 --- a/lib/dns/include/dns/dnssec.h +++ b/lib/dns/include/dns/dnssec.h @@ -47,11 +47,14 @@ typedef enum { * A DNSSEC key and hints about its intended use gleaned from metadata */ struct dns_dnsseckey { - dst_key_t * key; - bool hint_publish; /*% metadata says to publish */ - bool force_publish; /*% publish regardless of metadata */ - bool hint_sign; /*% metadata says to sign with this key */ - bool force_sign; /*% sign with key regardless of metadata */ + dst_key_t *key; + bool hint_publish; /*% metadata says to publish */ + bool force_publish; /*% publish regardless of metadata + * */ + bool hint_sign; /*% metadata says to sign with this + * key */ + bool force_sign; /*% sign with key regardless of + * metadata */ bool hint_revoke; /*% metadata says revoke key */ bool hint_remove; /*% metadata says *don't* publish */ bool is_active; /*% key is already active */ @@ -61,10 +64,10 @@ struct dns_dnsseckey { bool ksk; /*% this is a key-signing key */ bool zsk; /*% this is a zone-signing key */ bool legacy; /*% this is old-style key with no - metadata (possibly generated by - an older version of BIND9) and - should be ignored when searching - for keys to import into the zone */ + * metadata (possibly generated by + * an older version of BIND9) and + * should be ignored when searching + * for keys to import into the zone */ unsigned int index; /*% position in list */ ISC_LINK(dns_dnsseckey_t) link; }; diff --git a/lib/dns/include/dns/dnstap.h b/lib/dns/include/dns/dnstap.h index 98babf36f2..b0afa07139 100644 --- a/lib/dns/include/dns/dnstap.h +++ b/lib/dns/include/dns/dnstap.h @@ -13,8 +13,8 @@ #define _DNSTAP_H /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief @@ -30,7 +30,7 @@ #include #include -#else +#else /* ifdef HAVE_DNSTAP */ struct fstrm_iothr_options; #endif /* HAVE_DNSTAP */ diff --git a/lib/dns/include/dns/dyndb.h b/lib/dns/include/dns/dyndb.h index e0f459cbe3..469d1a8545 100644 --- a/lib/dns/include/dns/dyndb.h +++ b/lib/dns/include/dns/dyndb.h @@ -57,7 +57,7 @@ struct dns_dyndbctx { #ifndef DNS_DYNDB_VERSION #define DNS_DYNDB_VERSION 1 #define DNS_DYNDB_AGE 0 -#endif +#endif /* ifndef DNS_DYNDB_VERSION */ typedef isc_result_t dns_dyndb_register_t(isc_mem_t *mctx, const char *name, const char *parameters, diff --git a/lib/dns/include/dns/ecdb.h b/lib/dns/include/dns/ecdb.h index 8f0554e157..66bac17b95 100644 --- a/lib/dns/include/dns/ecdb.h +++ b/lib/dns/include/dns/ecdb.h @@ -13,8 +13,8 @@ #define DNS_ECDB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /* TBD */ diff --git a/lib/dns/include/dns/edns.h b/lib/dns/include/dns/edns.h index 018c89d34e..e95c18aeb0 100644 --- a/lib/dns/include/dns/edns.h +++ b/lib/dns/include/dns/edns.h @@ -22,6 +22,6 @@ * Warning: this currently disables sending COOKIE requests in resolver.c */ #define DNS_EDNS_VERSION 1 /* draft-andrews-edns1 */ -#endif +#endif /* ifdef DRAFT_ANDREWS_EDNS1 */ -#endif +#endif /* ifndef DNS_EDNS_H */ diff --git a/lib/dns/include/dns/fixedname.h b/lib/dns/include/dns/fixedname.h index b7ef5ae97f..ea984a1dd1 100644 --- a/lib/dns/include/dns/fixedname.h +++ b/lib/dns/include/dns/fixedname.h @@ -13,8 +13,8 @@ #define DNS_FIXEDNAME_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/fixedname.h * \brief @@ -45,8 +45,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include #include @@ -54,8 +54,8 @@ #include /***** - ***** Types - *****/ +***** Types +*****/ struct dns_fixedname { dns_name_t name; diff --git a/lib/dns/include/dns/geoip.h b/lib/dns/include/dns/geoip.h index 6a7eed75b8..8128444c92 100644 --- a/lib/dns/include/dns/geoip.h +++ b/lib/dns/include/dns/geoip.h @@ -13,8 +13,8 @@ #define DNS_GEOIP_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/geoip.h * \brief diff --git a/lib/dns/include/dns/ipkeylist.h b/lib/dns/include/dns/ipkeylist.h index 9e344c3e97..cd5ed1056e 100644 --- a/lib/dns/include/dns/ipkeylist.h +++ b/lib/dns/include/dns/ipkeylist.h @@ -85,4 +85,4 @@ dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n); * \li #ISC_R_NOMEMORY if there's no memory, ipkeylist is left untoched */ -#endif +#endif /* ifndef DNS_IPKEYLIST_H */ diff --git a/lib/dns/include/dns/journal.h b/lib/dns/include/dns/journal.h index 77bc4c6518..c771381830 100644 --- a/lib/dns/include/dns/journal.h +++ b/lib/dns/include/dns/journal.h @@ -13,8 +13,8 @@ #define DNS_JOURNAL_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/journal.h * \brief diff --git a/lib/dns/include/dns/kasp.h b/lib/dns/include/dns/kasp.h index 4c366fd1f8..38f64e5527 100644 --- a/lib/dns/include/dns/kasp.h +++ b/lib/dns/include/dns/kasp.h @@ -13,8 +13,8 @@ #define DNS_KASP_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/kasp.h * \brief @@ -88,7 +88,7 @@ struct dns_kasp { uint32_t parent_propagation_delay; uint32_t parent_registration_delay; - // TODO: The rest of the KASP configuration + /* TODO: The rest of the KASP configuration */ }; #define DNS_KASP_MAGIC ISC_MAGIC('K', 'A', 'S', 'P') diff --git a/lib/dns/include/dns/keydata.h b/lib/dns/include/dns/keydata.h index 84d76b5c49..37a6f6e2f1 100644 --- a/lib/dns/include/dns/keydata.h +++ b/lib/dns/include/dns/keydata.h @@ -13,8 +13,8 @@ #define DNS_KEYDATA_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/keydata.h * \brief diff --git a/lib/dns/include/dns/keytable.h b/lib/dns/include/dns/keytable.h index 6291dc4b0e..1144f26bfe 100644 --- a/lib/dns/include/dns/keytable.h +++ b/lib/dns/include/dns/keytable.h @@ -13,8 +13,8 @@ #define DNS_KEYTABLE_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief @@ -276,7 +276,7 @@ dns_keytable_issecuredomain(dns_keytable_t *keytable, const dns_name_t *name, *\li 'foundanme' is NULL or is a pointer to an initialized dns_name_t * *\li '*wantsdnssecp' is a valid bool. - + * * Ensures: * *\li On success, *wantsdnssecp will be true if and only if 'name' diff --git a/lib/dns/include/dns/librpz.h b/lib/dns/include/dns/librpz.h index 5690a51e04..30c548df3a 100644 --- a/lib/dns/include/dns/librpz.h +++ b/lib/dns/include/dns/librpz.h @@ -50,10 +50,10 @@ #ifdef LIBRPZ_INTERNAL #define LIBDEF(t, s) extern t s; #define LIBDEF_F(f) LIBDEF(librpz_##f##_t, librpz_##f) -#else +#else /* ifdef LIBRPZ_INTERNAL */ #define LIBDEF(t, s) #define LIBDEF_F(f) -#endif +#endif /* ifdef LIBRPZ_INTERNAL */ /* * Response Policy Zone triggers. @@ -169,7 +169,8 @@ typedef struct librpz_result { librpz_dznum_t dznum; /* dnsrpzd zone number */ librpz_cznum_t cznum; /* librpz client zone number */ librpz_trig_t trig : LIBRPZ_TRIG_SIZE; - bool log : 1; /* log rewrite given librpz_log_level */ + bool log : 1; /* log rewrite given librpz_log_level + * */ } librpz_result_t; /** @@ -216,19 +217,19 @@ typedef struct { #define LIBRPZ_UNUSED __attribute__((unused)) #define LIBRPZ_PF(f, l) __attribute__((format(printf, f, l))) #define LIBRPZ_NORET __attribute__((__noreturn__)) -#else +#else /* ifdef LIBRPZ_HAVE_ATTR */ #define LIBRPZ_UNUSED #define LIBRPZ_PF(f, l) #define LIBRPZ_NORET -#endif +#endif /* ifdef LIBRPZ_HAVE_ATTR */ #ifdef HAVE_BUILTIN_EXPECT #define LIBRPZ_LIKELY(c) __builtin_expect(!!(c), 1) #define LIBRPZ_UNLIKELY(c) __builtin_expect(!!(c), 0) -#else +#else /* ifdef HAVE_BUILTIN_EXPECT */ #define LIBRPZ_LIKELY(c) (c) #define LIBRPZ_UNLIKELY(c) (c) -#endif +#endif /* ifdef HAVE_BUILTIN_EXPECT */ typedef bool(librpz_parse_log_opt_t)(librpz_emsg_t *emsg, const char *arg); LIBDEF_F(parse_log_opt) @@ -891,8 +892,9 @@ librpz_lib_open(librpz_emsg_t *emsg, void **dl_handle, const char *path) if (handle != NULL) { new_librpz = dlsym(handle, LIBRPZ_DEF_STR); if (new_librpz != NULL) { - if (dl_handle != NULL) + if (dl_handle != NULL) { *dl_handle = handle; + } return (new_librpz); } if (dlclose(handle) != 0) { @@ -917,8 +919,9 @@ librpz_lib_open(librpz_emsg_t *emsg, void **dl_handle, const char *path) } new_librpz = dlsym(handle, LIBRPZ_DEF_STR); if (new_librpz != NULL) { - if (dl_handle != NULL) + if (dl_handle != NULL) { *dl_handle = handle; + } return (new_librpz); } snprintf(emsg->c, sizeof(librpz_emsg_t), @@ -935,13 +938,14 @@ librpz_lib_open(librpz_emsg_t *emsg, void **dl_handle, const char *path) { (void)(path); - if (dl_handle != NULL) + if (dl_handle != NULL) { *dl_handle = NULL; + } #if LIBRPZ_LIB_OPEN == 1 emsg->c[0] = '\0'; return (&LIBRPZ_DEF); -#else +#else /* if LIBRPZ_LIB_OPEN == 1 */ snprintf(emsg->c, sizeof(librpz_emsg_t), "librpz not available via ./configure"); return (NULL); diff --git a/lib/dns/include/dns/lookup.h b/lib/dns/include/dns/lookup.h index f4fe3bbcdf..ca4d3fffba 100644 --- a/lib/dns/include/dns/lookup.h +++ b/lib/dns/include/dns/lookup.h @@ -13,8 +13,8 @@ #define DNS_LOOKUP_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/lookup.h * \brief diff --git a/lib/dns/include/dns/masterdump.h b/lib/dns/include/dns/masterdump.h index 752f2775b3..4d21955a03 100644 --- a/lib/dns/include/dns/masterdump.h +++ b/lib/dns/include/dns/masterdump.h @@ -74,7 +74,7 @@ typedef struct dns_master_style dns_master_style_t; #define DNS_STYLEFLAG_REL_OWNER 0x000100000ULL /*% Print domain names in RR data in relative form when possible. - For this to take effect, DNS_STYLEFLAG_REL_OWNER must also be set. */ + * For this to take effect, DNS_STYLEFLAG_REL_OWNER must also be set. */ #define DNS_STYLEFLAG_REL_DATA 0x000200000ULL /*% Print the trust level of each rdataset. */ diff --git a/lib/dns/include/dns/message.h b/lib/dns/include/dns/message.h index ac9e8df1df..71f1fa328f 100644 --- a/lib/dns/include/dns/message.h +++ b/lib/dns/include/dns/message.h @@ -168,11 +168,11 @@ typedef int dns_messagetextflag_t; #define DNS_MESSAGEPARSE_PRESERVEORDER 0x0001 /*%< preserve rdata order */ #define DNS_MESSAGEPARSE_BESTEFFORT \ 0x0002 /*%< return a message if a \ - recoverable parse error \ - occurs */ + * recoverable parse error \ + * occurs */ #define DNS_MESSAGEPARSE_CLONEBUFFER \ 0x0004 /*%< save a copy of the \ - source buffer */ + * source buffer */ #define DNS_MESSAGEPARSE_IGNORETRUNCATION \ 0x0008 /*%< truncation errors are \ * not fatal. */ @@ -185,10 +185,10 @@ typedef int dns_messagetextflag_t; #define DNS_MESSAGERENDER_OMITDNSSEC 0x0004 /*%< omit DNSSEC records */ #define DNS_MESSAGERENDER_PREFER_A \ 0x0008 /*%< prefer A records in \ - additional section. */ + * additional section. */ #define DNS_MESSAGERENDER_PREFER_AAAA \ 0x0010 /*%< prefer AAAA records in \ - additional section. */ + * additional section. */ /* Obsolete: DNS_MESSAGERENDER_FILTER_AAAA 0x0020 */ typedef struct dns_msgblock dns_msgblock_t; @@ -257,16 +257,18 @@ struct dns_message { ISC_LIST(dns_rdata_t) freerdata; ISC_LIST(dns_rdatalist_t) freerdatalist; - dns_rcode_t tsigstatus; - dns_rcode_t querytsigstatus; - dns_name_t * tsigname; /* Owner name of TSIG, if any */ + dns_rcode_t tsigstatus; + dns_rcode_t querytsigstatus; + dns_name_t *tsigname; /* Owner name of TSIG, if any + * */ dns_rdataset_t *querytsig; dns_tsigkey_t * tsigkey; dst_context_t * tsigctx; int sigstart; int timeadjust; - dns_name_t * sig0name; /* Owner name of SIG0, if any */ + dns_name_t *sig0name; /* Owner name of SIG0, if any + * */ dst_key_t * sig0key; dns_rcode_t sig0status; isc_region_t query; @@ -1294,7 +1296,7 @@ dns_message_signer(dns_message_t *msg, dns_name_t *signer); * message * *\li #DNS_R_TSIGVERIFYFAILURE - the message was signed by a TSIG, but - *the signature failed to verify + * the signature failed to verify * *\li #DNS_R_TSIGERRORSET - the message was signed by a TSIG and * verified, but the query was rejected by diff --git a/lib/dns/include/dns/name.h b/lib/dns/include/dns/name.h index b39af8e92a..287ad69821 100644 --- a/lib/dns/include/dns/name.h +++ b/lib/dns/include/dns/name.h @@ -13,8 +13,8 @@ #define DNS_NAME_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/name.h * \brief @@ -76,20 +76,20 @@ ISC_LANG_BEGINDECLS /***** - ***** Labels - ***** - ***** A 'label' is basically a region. It contains one DNS wire format - ***** label of type 00 (ordinary). - *****/ +***** Labels +***** +***** A 'label' is basically a region. It contains one DNS wire format +***** label of type 00 (ordinary). +*****/ /***** - ***** Names - ***** - ***** A 'name' is a handle to a binary region. It contains a sequence of one - ***** or more DNS wire format labels of type 00 (ordinary). - ***** Note that all names are not required to end with the root label, - ***** as they are in the actual DNS wire protocol. - *****/ +***** Names +***** +***** A 'name' is a handle to a binary region. It contains a sequence of one +***** or more DNS wire format labels of type 00 (ordinary). +***** Note that all names are not required to end with the root label, +***** as they are in the actual DNS wire protocol. +*****/ /*** *** Types diff --git a/lib/dns/include/dns/ncache.h b/lib/dns/include/dns/ncache.h index f92def2327..12a5ceca75 100644 --- a/lib/dns/include/dns/ncache.h +++ b/lib/dns/include/dns/ncache.h @@ -13,8 +13,8 @@ #define DNS_NCACHE_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/ncache.h *\brief diff --git a/lib/dns/include/dns/nta.h b/lib/dns/include/dns/nta.h index c4d080cfb3..923d4b10ea 100644 --- a/lib/dns/include/dns/nta.h +++ b/lib/dns/include/dns/nta.h @@ -13,8 +13,8 @@ #define DNS_NTA_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief diff --git a/lib/dns/include/dns/peer.h b/lib/dns/include/dns/peer.h index 479244afd2..9b39445543 100644 --- a/lib/dns/include/dns/peer.h +++ b/lib/dns/include/dns/peer.h @@ -13,8 +13,8 @@ #define DNS_PEER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/peer.h * \brief diff --git a/lib/dns/include/dns/private.h b/lib/dns/include/dns/private.h index f6c2a0e6e4..6480989d94 100644 --- a/lib/dns/include/dns/private.h +++ b/lib/dns/include/dns/private.h @@ -64,4 +64,4 @@ dns_private_totext(dns_rdata_t *privaterdata, isc_buffer_t *buffer); ISC_LANG_ENDDECLS -#endif +#endif /* ifndef DNS_PRIVATE_H */ diff --git a/lib/dns/include/dns/rbt.h b/lib/dns/include/dns/rbt.h index 58599ad500..5083d11766 100644 --- a/lib/dns/include/dns/rbt.h +++ b/lib/dns/include/dns/rbt.h @@ -45,9 +45,9 @@ ISC_LANG_BEGINDECLS #define DNS_RBTNODE_MAGIC ISC_MAGIC('R', 'B', 'N', 'O') #if DNS_RBT_USEMAGIC #define DNS_RBTNODE_VALID(n) ISC_MAGIC_VALID(n, DNS_RBTNODE_MAGIC) -#else +#else /* if DNS_RBT_USEMAGIC */ #define DNS_RBTNODE_VALID(n) true -#endif +#endif /* if DNS_RBT_USEMAGIC */ /*% * This is the structure that is used for each node in the red/black @@ -65,7 +65,7 @@ enum { DNS_RBT_NSEC_NORMAL = 0, /* in main tree */ struct dns_rbtnode { #if DNS_RBT_USEMAGIC unsigned int magic; -#endif +#endif /* if DNS_RBT_USEMAGIC */ /*@{*/ /*! * The following bitfields add up to a total bitwidth of 32. @@ -152,8 +152,9 @@ struct dns_rbtnode { uint8_t : 0; /* start of bitfields c/o node lock */ uint8_t dirty : 1; uint8_t wild : 1; - uint8_t : 0; /* end of bitfields c/o node lock */ - uint16_t locknum; /* note that this is not in the bitfield */ + uint8_t : 0; /* end of bitfields c/o node lock */ + uint16_t locknum; /* note that this is not in the bitfield + * */ isc_refcount_t references; /*@}*/ }; @@ -172,8 +173,8 @@ typedef isc_result_t (*dns_rbtdatafixer_t)(dns_rbtnode_t *rbtnode, void *base, typedef void (*dns_rbtdeleter_t)(void *, void *); /***** - ***** Chain Info - *****/ +***** Chain Info +*****/ /*! * A chain is used to keep track of the sequence of nodes to reach any given @@ -270,8 +271,8 @@ typedef struct dns_rbtnodechain { } dns_rbtnodechain_t; /***** - ***** Public interfaces. - *****/ +***** Public interfaces. +*****/ isc_result_t dns_rbt_create(isc_mem_t *mctx, dns_rbtdeleter_t deleter, void *deleter_arg, dns_rbt_t **rbtp); @@ -484,10 +485,10 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, *\li If result is ISC_R_SUCCESS: *\verbatim * *node is the terminal node for 'name'. - + * * 'foundname' and 'name' represent the same name (though not * the same memory). - + * * 'chain' points to the DNSSEC predecessor, if any, of 'name'. * * chain->level_matches and chain->level_count are equal. @@ -822,8 +823,8 @@ dns__rbtnode_getdistance(dns_rbtnode_t *node); */ /***** - ***** Chain Functions - *****/ +***** Chain Functions +*****/ void dns_rbtnodechain_init(dns_rbtnodechain_t *chain); @@ -980,9 +981,9 @@ dns_rbtnodechain_prev(dns_rbtnodechain_t *chain, dns_name_t *name, * Returns: *\li #ISC_R_SUCCESS The predecessor was found and 'name' was set. *\li #DNS_R_NEWORIGIN The predecessor was found with a - *different origin and 'name' and 'origin' were set. \li #ISC_R_NOMORE There - *was no predecessor. \li <something_else> Any error result from - *dns_rbtnodechain_current. + * different origin and 'name' and 'origin' were set. \li #ISC_R_NOMORE There + * was no predecessor. \li <something_else> Any error result from + * dns_rbtnodechain_current. */ isc_result_t diff --git a/lib/dns/include/dns/rdata.h b/lib/dns/include/dns/rdata.h index bf1fcc304b..609eabd9b6 100644 --- a/lib/dns/include/dns/rdata.h +++ b/lib/dns/include/dns/rdata.h @@ -13,8 +13,8 @@ #define DNS_RDATA_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/rdata.h * \brief @@ -127,13 +127,13 @@ struct dns_rdata { ((rdata)->data == NULL && (rdata)->length == 0 && \ (rdata)->rdclass == 0 && (rdata)->type == 0 && (rdata)->flags == 0 && \ !ISC_LINK_LINKED((rdata), link)) -#else +#else /* ifdef DNS_RDATA_CHECKINITIALIZED */ #ifdef ISC_LIST_CHECKINIT #define DNS_RDATA_INITIALIZED(rdata) (!ISC_LINK_LINKED((rdata), link)) -#else +#else /* ifdef ISC_LIST_CHECKINIT */ #define DNS_RDATA_INITIALIZED(rdata) true -#endif -#endif +#endif /* ifdef ISC_LIST_CHECKINIT */ +#endif /* ifdef DNS_RDATA_CHECKINITIALIZED */ #define DNS_RDATA_UPDATE 0x0001 /*%< update pseudo record. */ #define DNS_RDATA_OFFLINE 0x0002 /*%< RRSIG has a offline key. */ @@ -159,7 +159,7 @@ struct dns_rdata { */ /*% Split the rdata into multiple lines to try to keep it - within the "width". */ + * within the "width". */ #define DNS_STYLEFLAG_MULTILINE 0x00000001ULL /*% Output explanatory comments. */ @@ -391,10 +391,10 @@ dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass, * Ensures, * if result is success: *\li If 'rdata' is not NULL, it is attached to the target. - + * *\li The conditions dns_name_fromtext() ensures for names hold * for all names in the rdata. - + * *\li The used space in target is updated. * * Result: diff --git a/lib/dns/include/dns/rdatalist.h b/lib/dns/include/dns/rdatalist.h index dccf2c34bc..ad8357acfe 100644 --- a/lib/dns/include/dns/rdatalist.h +++ b/lib/dns/include/dns/rdatalist.h @@ -13,8 +13,8 @@ #define DNS_RDATALIST_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/rdatalist.h * \brief diff --git a/lib/dns/include/dns/rdataset.h b/lib/dns/include/dns/rdataset.h index d88af45a5f..1b742c91e2 100644 --- a/lib/dns/include/dns/rdataset.h +++ b/lib/dns/include/dns/rdataset.h @@ -13,8 +13,8 @@ #define DNS_RDATASET_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/rdataset.h * \brief diff --git a/lib/dns/include/dns/rdatasetiter.h b/lib/dns/include/dns/rdatasetiter.h index 1962951349..8257052a24 100644 --- a/lib/dns/include/dns/rdatasetiter.h +++ b/lib/dns/include/dns/rdatasetiter.h @@ -13,8 +13,8 @@ #define DNS_RDATASETITER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/rdatasetiter.h * \brief @@ -50,8 +50,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include #include @@ -62,8 +62,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Types - *****/ +***** Types +*****/ typedef struct dns_rdatasetitermethods { void (*destroy)(dns_rdatasetiter_t **iteratorp); diff --git a/lib/dns/include/dns/request.h b/lib/dns/include/dns/request.h index 8e8219ecaa..d238e7c6b5 100644 --- a/lib/dns/include/dns/request.h +++ b/lib/dns/include/dns/request.h @@ -13,8 +13,8 @@ #define DNS_REQUEST_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/request.h * diff --git a/lib/dns/include/dns/resolver.h b/lib/dns/include/dns/resolver.h index 11681c0dff..a2ed53aa6c 100644 --- a/lib/dns/include/dns/resolver.h +++ b/lib/dns/include/dns/resolver.h @@ -13,8 +13,8 @@ #define DNS_RESOLVER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/resolver.h * @@ -96,7 +96,7 @@ typedef enum { dns_quotatype_zone = 0, dns_quotatype_server } dns_quotatype_t; #define DNS_FETCHOPT_NOVALIDATE 0x00000020 /*%< Disable validation. */ #define DNS_FETCHOPT_EDNS512 \ 0x00000040 /*%< Advertise a 512 byte \ - UDP buffer. */ + * UDP buffer. */ #define DNS_FETCHOPT_WANTNSID 0x00000080 /*%< Request NSID */ #define DNS_FETCHOPT_PREFETCH 0x00000100 /*%< Do prefetch */ #define DNS_FETCHOPT_NOCDFLAG 0x00000200 /*%< Don't set CD flag. */ @@ -108,27 +108,27 @@ typedef enum { dns_quotatype_zone = 0, dns_quotatype_server } dns_quotatype_t; #define DNS_FETCHOPT_NOCACHED 0x00008000 /*%< Force cache update. */ #define DNS_FETCHOPT_QMINIMIZE \ 0x00010000 /*%< Use qname \ - minimization. */ + * minimization. */ #define DNS_FETCHOPT_NOFOLLOW \ 0x00020000 /*%< Don't follow \ - delegations */ + * delegations */ #define DNS_FETCHOPT_QMIN_STRICT \ 0x00040000 /*%< Do not work around \ - servers that return \ - errors on non-empty \ - terminals. */ + * servers that return \ + * errors on non-empty \ + * terminals. */ #define DNS_FETCHOPT_QMIN_USE_A \ 0x00080000 /*%< Use A type queries \ - instead of NS when \ - doing minimization */ + * instead of NS when \ + * doing minimization */ #define DNS_FETCHOPT_QMIN_SKIP_IP6A \ 0x00100000 /*%< Skip some labels \ - when doing qname \ - minimization on \ - ip6.arpa. */ + * when doing qname \ + * minimization on \ + * ip6.arpa. */ #define DNS_FETCHOPT_NOFORWARD \ 0x00200000 /*%< Do not use forwarders \ - if possible. */ + * if possible. */ /* Reserved in use by adb.c 0x00400000 */ #define DNS_FETCHOPT_EDNSVERSIONSET 0x00800000 @@ -737,7 +737,7 @@ dns_resolver_dumpfetches(dns_resolver_t *resolver, isc_statsformat_t format, */ void dns_resolver_setfuzzing(void); -#endif +#endif /* ifdef ENABLE_AFL */ ISC_LANG_ENDDECLS diff --git a/lib/dns/include/dns/result.h b/lib/dns/include/dns/result.h index 34f02020b6..04a6595d9c 100644 --- a/lib/dns/include/dns/result.h +++ b/lib/dns/include/dns/result.h @@ -35,10 +35,10 @@ /* * Since we dropped the support of bitstring labels, deprecate the related * result codes too. - -#define DNS_R_BADBITSTRING (ISC_RESULTCLASS_DNS + 2) -#define DNS_R_BITSTRINGTOOLONG (ISC_RESULTCLASS_DNS + 3) -*/ + * + #define DNS_R_BADBITSTRING (ISC_RESULTCLASS_DNS + 2) + #define DNS_R_BITSTRINGTOOLONG (ISC_RESULTCLASS_DNS + 3) + */ #define DNS_R_EMPTYLABEL (ISC_RESULTCLASS_DNS + 4) #define DNS_R_BADDOTTEDQUAD (ISC_RESULTCLASS_DNS + 5) #define DNS_R_INVALIDNS (ISC_RESULTCLASS_DNS + 6) diff --git a/lib/dns/include/dns/rpz.h b/lib/dns/include/dns/rpz.h index 5f92630763..bbab50b3e0 100644 --- a/lib/dns/include/dns/rpz.h +++ b/lib/dns/include/dns/rpz.h @@ -142,22 +142,27 @@ struct dns_rpz_zone { dns_ttl_t max_policy_ttl; dns_rpz_policy_t policy; /* DNS_RPZ_POLICY_GIVEN or override */ - uint32_t min_update_interval; /* minimal interval between updates */ - isc_ht_t *nodes; /* entries in zone */ - dns_rpz_zones_t *rpzs; /* owner */ - isc_time_t lastupdated; /* last time the zone was processed */ - bool updatepending; /* there is an update pending/waiting */ - bool updaterunning; /* there is an update running */ - dns_db_t * db; /* zones database */ - dns_dbversion_t *dbversion; /* version we will be updating to */ - dns_db_t * updb; /* zones database we're working on */ - dns_dbversion_t *updbversion; /* version we're currently working on */ - dns_dbiterator_t *updbit; /* iterator to use when updating */ - isc_ht_t * newnodes; /* entries in zone being updated */ - bool db_registered; /* is the notify event registered? */ - bool addsoa; /* add soa to the additional section */ - isc_timer_t * updatetimer; - isc_event_t updateevent; + uint32_t min_update_interval; /* minimal interval between + * updates */ + isc_ht_t * nodes; /* entries in zone */ + dns_rpz_zones_t *rpzs; /* owner */ + isc_time_t lastupdated; /* last time the zone was processed + * */ + bool updatepending; /* there is an update + * pending/waiting */ + bool updaterunning; /* there is an update running */ + dns_db_t * db; /* zones database */ + dns_dbversion_t *dbversion; /* version we will be updating to */ + dns_db_t * updb; /* zones database we're working on */ + dns_dbversion_t *updbversion; /* version we're currently working + * on */ + dns_dbiterator_t *updbit; /* iterator to use when updating */ + isc_ht_t * newnodes; /* entries in zone being updated */ + bool db_registered; /* is the notify event + * registered? */ + bool addsoa; /* add soa to the additional section */ + isc_timer_t *updatetimer; + isc_event_t updateevent; }; /* diff --git a/lib/dns/include/dns/rriterator.h b/lib/dns/include/dns/rriterator.h index 9db5fbf7dd..6c70233578 100644 --- a/lib/dns/include/dns/rriterator.h +++ b/lib/dns/include/dns/rriterator.h @@ -13,8 +13,8 @@ #define DNS_RRITERATOR_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/rriterator.h * \brief @@ -22,8 +22,8 @@ */ /***** - ***** Imports - *****/ +***** Imports +*****/ #include @@ -43,8 +43,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Types - *****/ +***** Types +*****/ /*% * A dns_rriterator_t is an iterator that iterates over an entire database, diff --git a/lib/dns/include/dns/rrl.h b/lib/dns/include/dns/rrl.h index c55cd9194a..d33c9a32f8 100644 --- a/lib/dns/include/dns/rrl.h +++ b/lib/dns/include/dns/rrl.h @@ -134,23 +134,24 @@ struct dns_rrl_entry { #define DNS_RRL_MAX_WINDOW 3600 #if DNS_RRL_MAX_WINDOW >= DNS_RRL_MAX_TS #error "DNS_RRL_MAX_WINDOW is too large" -#endif +#endif /* if DNS_RRL_MAX_WINDOW >= DNS_RRL_MAX_TS */ #define DNS_RRL_MAX_RATE 1000 #if DNS_RRL_MAX_RATE >= (DNS_RRL_MAX_RESPONSES / DNS_RRL_MAX_WINDOW) #error "DNS_RRL_MAX_rate is too large" -#endif +#endif /* if DNS_RRL_MAX_RATE >= (DNS_RRL_MAX_RESPONSES / DNS_RRL_MAX_WINDOW) \ + */ #if (1 << DNS_RRL_LOG_BITS) >= DNS_RRL_FOREVER #error DNS_RRL_LOG_BITS is too big -#endif +#endif /* if (1 << DNS_RRL_LOG_BITS) >= DNS_RRL_FOREVER */ #define DNS_RRL_MAX_LOG_SECS 1800 #if DNS_RRL_MAX_LOG_SECS >= (1 << DNS_RRL_LOG_BITS) #error "DNS_RRL_MAX_LOG_SECS is too large" -#endif +#endif /* if DNS_RRL_MAX_LOG_SECS >= (1 << DNS_RRL_LOG_BITS) */ #define DNS_RRL_STOP_LOG_SECS 60 #if DNS_RRL_STOP_LOG_SECS >= (1 << DNS_RRL_LOG_BITS) #error "DNS_RRL_STOP_LOG_SECS is too large" -#endif +#endif /* if DNS_RRL_STOP_LOG_SECS >= (1 << DNS_RRL_LOG_BITS) */ /* * A hash table of rate-limit entries. diff --git a/lib/dns/include/dns/sdb.h b/lib/dns/include/dns/sdb.h index 2712a576dd..5187772ed8 100644 --- a/lib/dns/include/dns/sdb.h +++ b/lib/dns/include/dns/sdb.h @@ -13,8 +13,8 @@ #define DNS_SDB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/sdb.h * \brief diff --git a/lib/dns/include/dns/soa.h b/lib/dns/include/dns/soa.h index 5a6dc2952b..6b2349e9c3 100644 --- a/lib/dns/include/dns/soa.h +++ b/lib/dns/include/dns/soa.h @@ -13,8 +13,8 @@ #define DNS_SOA_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/soa.h * \brief diff --git a/lib/dns/include/dns/stats.h b/lib/dns/include/dns/stats.h index bac8de8d09..f4374e9bd7 100644 --- a/lib/dns/include/dns/stats.h +++ b/lib/dns/include/dns/stats.h @@ -448,7 +448,7 @@ enum { dns_sizecounter_out_0 = 0, * intentionally defined to be the same value to ensure binary compatibility. */ #define DNS_STATSDUMP_VERBOSE 0x00000001 /*%< dump 0-value counters */ -#endif +#endif /* if 0 */ /*%< * (Obsoleted) diff --git a/lib/dns/include/dns/tsec.h b/lib/dns/include/dns/tsec.h index 649f866a12..99b5fdd32c 100644 --- a/lib/dns/include/dns/tsec.h +++ b/lib/dns/include/dns/tsec.h @@ -13,8 +13,8 @@ #define DNS_TSEC_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * diff --git a/lib/dns/include/dns/types.h b/lib/dns/include/dns/types.h index 008757fc9b..5939906a4d 100644 --- a/lib/dns/include/dns/types.h +++ b/lib/dns/include/dns/types.h @@ -162,7 +162,7 @@ typedef struct dns_ipkeylist dns_ipkeylist_t; #ifndef GSSAPI typedef struct not_defined_gss_cred_id *gss_cred_id_t; typedef struct not_defined_gss_ctx * gss_ctx_id_t; -#endif +#endif /* ifndef GSSAPI */ typedef struct dst_gssapi_signverifyctx dst_gssapi_signverifyctx_t; typedef enum { dns_hash_sha1 = 1 } dns_hash_t; @@ -262,8 +262,10 @@ enum { dns_rcode_badcookie = 23 #define dns_rcode_badcookie ((dns_rcode_t)dns_rcode_badcookie) /* - * Update dns_rcodestats_create() and dns_rcodestats_increment() - * and this comment if a rcode > dns_rcode_badcookie is assigned. + * Update dns_rcodestats_create() and + *dns_rcodestats_increment() + * and this comment if a rcode > + *dns_rcode_badcookie is assigned. */ /* Private space [3841..4095] */ }; @@ -325,7 +327,7 @@ enum { #define dns_trust_answer ((dns_trust_t)dns_trust_answer) /* Received in the authority section as part of an - authoritative response */ + * authoritative response */ dns_trust_authauthority = 6, #define dns_trust_authauthority ((dns_trust_t)dns_trust_authauthority) diff --git a/lib/dns/include/dns/validator.h b/lib/dns/include/dns/validator.h index 78b0029866..c56e376190 100644 --- a/lib/dns/include/dns/validator.h +++ b/lib/dns/include/dns/validator.h @@ -13,8 +13,8 @@ #define DNS_VALIDATOR_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/validator.h * diff --git a/lib/dns/include/dns/view.h b/lib/dns/include/dns/view.h index dc7175dec0..4a7932fd10 100644 --- a/lib/dns/include/dns/view.h +++ b/lib/dns/include/dns/view.h @@ -13,8 +13,8 @@ #define DNS_VIEW_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/view.h * \brief @@ -171,19 +171,20 @@ struct dns_view { uint16_t maxudp; dns_ttl_t staleanswerttl; dns_stale_answer_t staleanswersok; /* rndc setting */ - bool staleanswersenable; /* named.conf setting */ - uint16_t nocookieudp; - uint16_t padding; - dns_acl_t * pad_acl; - unsigned int maxbits; - dns_dns64list_t dns64; - unsigned int dns64cnt; - dns_rpz_zones_t * rpzs; - dns_catz_zones_t * catzs; - dns_dlzdblist_t dlz_searched; - dns_dlzdblist_t dlz_unsearched; - uint32_t fail_ttl; - dns_badcache_t * failcache; + bool staleanswersenable; /* named.conf setting + * */ + uint16_t nocookieudp; + uint16_t padding; + dns_acl_t * pad_acl; + unsigned int maxbits; + dns_dns64list_t dns64; + unsigned int dns64cnt; + dns_rpz_zones_t * rpzs; + dns_catz_zones_t *catzs; + dns_dlzdblist_t dlz_searched; + dns_dlzdblist_t dlz_unsearched; + uint32_t fail_ttl; + dns_badcache_t * failcache; /* * Configurable data for server use only, @@ -230,7 +231,7 @@ struct dns_view { dns_dtenv_t * dtenv; /* Dnstap environment */ dns_dtmsgtype_t dttypes; /* Dnstap message types - to log */ + * to log */ /* Registered module instances */ void *plugins; diff --git a/lib/dns/include/dns/xfrin.h b/lib/dns/include/dns/xfrin.h index 9c6301e372..d1d27da44f 100644 --- a/lib/dns/include/dns/xfrin.h +++ b/lib/dns/include/dns/xfrin.h @@ -13,8 +13,8 @@ #define DNS_XFRIN_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file dns/xfrin.h * \brief diff --git a/lib/dns/include/dns/zone.h b/lib/dns/include/dns/zone.h index 58c7f82409..9c0b3058b1 100644 --- a/lib/dns/include/dns/zone.h +++ b/lib/dns/include/dns/zone.h @@ -83,7 +83,7 @@ typedef enum { DNS_ZONEOPT_DNSKEYKSKONLY = 1 << 24, /*%< dnssec-dnskey-kskonly */ DNS_ZONEOPT_CHECKDUPRR = 1 << 25, /*%< check-dup-records */ DNS_ZONEOPT_CHECKDUPRRFAIL = 1 << 26, /*%< fatal check-dup-records - failures */ + * failures */ DNS_ZONEOPT_CHECKSPF = 1 << 27, /*%< check SPF records */ DNS_ZONEOPT_CHECKTTL = 1 << 28, /*%< check max-zone-ttl */ DNS_ZONEOPT_AUTOEMPTY = 1 << 29, /*%< automatic empty zone */ @@ -104,24 +104,24 @@ typedef enum { #ifndef DNS_ZONE_MINREFRESH #define DNS_ZONE_MINREFRESH 300 /*%< 5 minutes */ -#endif +#endif /* ifndef DNS_ZONE_MINREFRESH */ #ifndef DNS_ZONE_MAXREFRESH #define DNS_ZONE_MAXREFRESH 2419200 /*%< 4 weeks */ -#endif +#endif /* ifndef DNS_ZONE_MAXREFRESH */ #ifndef DNS_ZONE_DEFAULTREFRESH #define DNS_ZONE_DEFAULTREFRESH 3600 /*%< 1 hour */ -#endif +#endif /* ifndef DNS_ZONE_DEFAULTREFRESH */ #ifndef DNS_ZONE_MINRETRY #define DNS_ZONE_MINRETRY 300 /*%< 5 minutes */ -#endif +#endif /* ifndef DNS_ZONE_MINRETRY */ #ifndef DNS_ZONE_MAXRETRY #define DNS_ZONE_MAXRETRY 1209600 /*%< 2 weeks */ -#endif +#endif /* ifndef DNS_ZONE_MAXRETRY */ #ifndef DNS_ZONE_DEFAULTRETRY #define DNS_ZONE_DEFAULTRETRY \ 60 /*%< 1 minute, subject to \ - exponential backoff */ -#endif + * exponential backoff */ +#endif /* ifndef DNS_ZONE_DEFAULTRETRY */ #define DNS_ZONESTATE_XFERRUNNING 1 #define DNS_ZONESTATE_XFERDEFERRED 2 diff --git a/lib/dns/include/dst/dst.h b/lib/dns/include/dst/dst.h index 0118d11aee..6d5c03523d 100644 --- a/lib/dns/include/dst/dst.h +++ b/lib/dns/include/dst/dst.h @@ -602,7 +602,7 @@ dst_key_buildinternal(const dns_name_t *name, unsigned int alg, unsigned int bits, unsigned int flags, unsigned int protocol, dns_rdataclass_t rdclass, void *data, isc_mem_t *mctx, dst_key_t **keyp); -#endif +#endif /* ifdef DST_KEY_INTERNAL */ isc_result_t dst_key_fromlabel(const dns_name_t *name, int alg, unsigned int flags, diff --git a/lib/dns/include/dst/gssapi.h b/lib/dns/include/dst/gssapi.h index 9f276b8af0..4248b39ace 100644 --- a/lib/dns/include/dst/gssapi.h +++ b/lib/dns/include/dst/gssapi.h @@ -31,16 +31,16 @@ */ #include #include -#else +#else /* ifdef WIN32 */ #include ISC_PLATFORM_GSSAPIHEADER #ifdef ISC_PLATFORM_GSSAPI_KRB5_HEADER #include ISC_PLATFORM_GSSAPI_KRB5_HEADER -#endif -#endif +#endif /* ifdef ISC_PLATFORM_GSSAPI_KRB5_HEADER */ +#endif /* ifdef WIN32 */ #ifndef GSS_SPNEGO_MECHANISM #define GSS_SPNEGO_MECHANISM ((void *)0) -#endif -#endif +#endif /* ifndef GSS_SPNEGO_MECHANISM */ +#endif /* ifdef GSSAPI */ ISC_LANG_BEGINDECLS diff --git a/lib/dns/ipkeylist.c b/lib/dns/ipkeylist.c index a6def68d1d..7d8af68b81 100644 --- a/lib/dns/ipkeylist.c +++ b/lib/dns/ipkeylist.c @@ -37,23 +37,28 @@ dns_ipkeylist_clear(isc_mem_t *mctx, dns_ipkeylist_t *ipkl) REQUIRE(ipkl != NULL); - if (ipkl->allocated == 0) + if (ipkl->allocated == 0) { return; + } - if (ipkl->addrs != NULL) + if (ipkl->addrs != NULL) { isc_mem_put(mctx, ipkl->addrs, ipkl->allocated * sizeof(isc_sockaddr_t)); + } - if (ipkl->dscps != NULL) + if (ipkl->dscps != NULL) { isc_mem_put(mctx, ipkl->dscps, ipkl->allocated * sizeof(isc_dscp_t)); + } if (ipkl->keys != NULL) { for (i = 0; i < ipkl->allocated; i++) { - if (ipkl->keys[i] == NULL) + if (ipkl->keys[i] == NULL) { continue; - if (dns_name_dynamic(ipkl->keys[i])) + } + if (dns_name_dynamic(ipkl->keys[i])) { dns_name_free(ipkl->keys[i], mctx); + } isc_mem_put(mctx, ipkl->keys[i], sizeof(dns_name_t)); } isc_mem_put(mctx, ipkl->keys, @@ -62,10 +67,12 @@ dns_ipkeylist_clear(isc_mem_t *mctx, dns_ipkeylist_t *ipkl) if (ipkl->labels != NULL) { for (i = 0; i < ipkl->allocated; i++) { - if (ipkl->labels[i] == NULL) + if (ipkl->labels[i] == NULL) { continue; - if (dns_name_dynamic(ipkl->labels[i])) + } + if (dns_name_dynamic(ipkl->labels[i])) { dns_name_free(ipkl->labels[i], mctx); + } isc_mem_put(mctx, ipkl->labels[i], sizeof(dns_name_t)); } isc_mem_put(mctx, ipkl->labels, @@ -86,12 +93,14 @@ dns_ipkeylist_copy(isc_mem_t *mctx, const dns_ipkeylist_t *src, /* dst might be preallocated, we don't care, but it must be empty */ REQUIRE(dst->count == 0); - if (src->count == 0) + if (src->count == 0) { return (ISC_R_SUCCESS); + } result = dns_ipkeylist_resize(mctx, dst, src->count); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } memmove(dst->addrs, src->addrs, src->count * sizeof(isc_sockaddr_t)); @@ -141,8 +150,9 @@ dns_ipkeylist_resize(isc_mem_t *mctx, dns_ipkeylist_t *ipkl, unsigned int n) REQUIRE(ipkl != NULL); REQUIRE(n > ipkl->count); - if (n <= ipkl->allocated) + if (n <= ipkl->allocated) { return (ISC_R_SUCCESS); + } addrs = isc_mem_get(mctx, n * sizeof(isc_sockaddr_t)); dscps = isc_mem_get(mctx, n * sizeof(isc_dscp_t)); diff --git a/lib/dns/iptable.c b/lib/dns/iptable.c index 3f21f6b279..b8a6601e8b 100644 --- a/lib/dns/iptable.c +++ b/lib/dns/iptable.c @@ -38,8 +38,9 @@ dns_iptable_create(isc_mem_t *mctx, dns_iptable_t **target) tab->magic = DNS_IPTABLE_MAGIC; result = isc_radix_create(mctx, &tab->radix, RADIX_MAXBITS); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } *target = tab; return (ISC_R_SUCCESS); @@ -80,9 +81,10 @@ dns_iptable_addprefix(dns_iptable_t *tab, const isc_netaddr_t *addr, /* "any" or "none" */ INSIST(pfx.bitlen == 0); for (i = 0; i < RADIX_FAMILIES; i++) { - if (node->data[i] == NULL) + if (node->data[i] == NULL) { node->data[i] = pos ? &dns_iptable_pos : &dns_iptable_neg; + } } } else { /* any other prefix */ @@ -112,8 +114,9 @@ dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos) new_node = NULL; result = isc_radix_insert(tab->radix, &new_node, node, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * If we're negating a nested ACL, then we should @@ -125,11 +128,13 @@ dns_iptable_merge(dns_iptable_t *tab, dns_iptable_t *source, bool pos) */ for (i = 0; i < RADIX_FAMILIES; i++) { if (!pos) { - if (node->data[i] && *(bool *)node->data[i]) + if (node->data[i] && *(bool *)node->data[i]) { new_node->data[i] = &dns_iptable_neg; + } } - if (node->node_num[i] > max_node) + if (node->node_num[i] > max_node) { max_node = node->node_num[i]; + } } } RADIX_WALK_END; diff --git a/lib/dns/journal.c b/lib/dns/journal.c index ff141fea14..60f271a2c3 100644 --- a/lib/dns/journal.c +++ b/lib/dns/journal.c @@ -137,18 +137,21 @@ dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx, node = NULL; result = dns_db_findnode(db, zonename, false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto nonode; + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, ver, dns_rdatatype_soa, 0, (isc_stdtime_t)0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto freenode; + } result = dns_rdataset_first(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto freenode; + } dns_rdataset_current(&rdataset, &rdata); dns_rdataset_getownercase(&rdataset, zonename); @@ -303,8 +306,9 @@ struct dns_journal { FILE * fp; /*%< File handle */ isc_offset_t offset; /*%< Current file offset */ journal_header_t header; /*%< In-core journal header */ - unsigned char * rawindex; /*%< In-core buffer for journal index in - on-disk format */ + unsigned char * rawindex; /*%< In-core buffer for journal index + * in + * on-disk format */ journal_pos_t *index; /*%< In-core journal index */ /*% Current transaction state (when writing). */ @@ -319,9 +323,11 @@ struct dns_journal { journal_pos_t bpos; /*%< Position before first, */ journal_pos_t epos; /*%< and after last transaction */ /* The rest is iterator state. */ - uint32_t current_serial; /*%< Current SOA serial */ - isc_buffer_t source; /*%< Data from disk */ - isc_buffer_t target; /*%< Data from _fromwire check */ + uint32_t current_serial; /*%< Current SOA serial + * */ + isc_buffer_t source; /*%< Data from disk */ + isc_buffer_t target; /*%< Data from _fromwire check + * */ dns_decompress_t dctx; /*%< Dummy decompression ctx */ dns_name_t name; /*%< Current domain name */ dns_rdata_t rdata; /*%< Current rdata */ @@ -405,8 +411,9 @@ journal_read(dns_journal_t *j, void *mem, size_t nbytes) result = isc_stdio_read(mem, 1, nbytes, j->fp, NULL); if (result != ISC_R_SUCCESS) { - if (result == ISC_R_EOF) + if (result == ISC_R_EOF) { return (ISC_R_NOMORE); + } isc_log_write(JOURNAL_COMMON_LOGARGS, ISC_LOG_ERROR, "%s: read: %s", j->filename, isc_result_totext(result)); @@ -463,8 +470,9 @@ journal_read_xhdr(dns_journal_t *j, journal_xhdr_t *xhdr) journal_rawxhdr_t raw; isc_result_t result; result = journal_read(j, &raw, sizeof(raw)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } xhdr->size = decode_uint32(raw.size); xhdr->serial0 = decode_uint32(raw.serial0); xhdr->serial1 = decode_uint32(raw.serial1); @@ -492,8 +500,9 @@ journal_read_rrhdr(dns_journal_t *j, journal_rrhdr_t *rrhdr) journal_rawrrhdr_t raw; isc_result_t result; result = journal_read(j, &raw, sizeof(raw)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } rrhdr->size = decode_uint32(raw.size); return (ISC_R_SUCCESS); } @@ -574,8 +583,9 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, bool create, j->index = NULL; j->rawindex = NULL; - if (j->filename == NULL) + if (j->filename == NULL) { FAIL(ISC_R_NOMEMORY); + } result = isc_stdio_open(j->filename, writable ? "rb+" : "rb", &fp); @@ -669,16 +679,20 @@ journal_open(isc_mem_t *mctx, const char *filename, bool writable, bool create, failure: j->magic = 0; - if (j->rawindex != NULL) + if (j->rawindex != NULL) { isc_mem_put(j->mctx, j->rawindex, j->header.index_size * sizeof(journal_rawpos_t)); - if (j->index != NULL) + } + if (j->index != NULL) { isc_mem_put(j->mctx, j->index, j->header.index_size * sizeof(journal_pos_t)); - if (j->filename != NULL) + } + if (j->filename != NULL) { isc_mem_free(j->mctx, j->filename); - if (j->fp != NULL) + } + if (j->fp != NULL) { (void)isc_stdio_close(j->fp); + } isc_mem_putanddetach(&j->mctx, j, sizeof(*j)); return (result); } @@ -698,13 +712,15 @@ dns_journal_open(isc_mem_t *mctx, const char *filename, unsigned int mode, result = journal_open(mctx, filename, writable, create, journalp); if (result == ISC_R_NOTFOUND) { namelen = strlen(filename); - if (namelen > 4U && strcmp(filename + namelen - 4, ".jnl") == 0) + if (namelen > 4U && + strcmp(filename + namelen - 4, ".jnl") == 0) { namelen -= 4; + } result = snprintf(backup, sizeof(backup), "%.*s.jbk", (int)namelen, filename); if (result >= sizeof(backup)) { - return ISC_R_NOSPACE; + return (ISC_R_NOSPACE); } result = journal_open(mctx, backup, writable, writable, journalp); @@ -763,13 +779,15 @@ ixfr_order(const void *av, const void *bv) } r = bop - aop; - if (r != 0) + if (r != 0) { return (r); + } r = (b->rdata.type == dns_rdatatype_soa) - (a->rdata.type == dns_rdatatype_soa); - if (r != 0) + if (r != 0) { return (r); + } r = (a->rdata.type - b->rdata.type); return (r); @@ -799,18 +817,21 @@ journal_next(dns_journal_t *j, journal_pos_t *pos) REQUIRE(DNS_JOURNAL_VALID(j)); result = journal_seek(j, pos->offset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (pos->serial == j->header.end.serial) + if (pos->serial == j->header.end.serial) { return (ISC_R_NOMORE); + } /* * Read the header of the current transaction. * This will return ISC_R_NOMORE if we are at EOF. */ result = journal_read_xhdr(j, &xhdr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Check serial number consistency. @@ -849,13 +870,15 @@ static void index_find(dns_journal_t *j, uint32_t serial, journal_pos_t *best_guess) { unsigned int i; - if (j->index == NULL) + if (j->index == NULL) { return; + } for (i = 0; i < j->header.index_size; i++) { if (POS_VALID(j->index[i]) && DNS_SERIAL_GE(serial, j->index[i].serial) && - DNS_SERIAL_GT(j->index[i].serial, best_guess->serial)) + DNS_SERIAL_GT(j->index[i].serial, best_guess->serial)) { *best_guess = j->index[i]; + } } } @@ -872,14 +895,16 @@ static void index_add(dns_journal_t *j, journal_pos_t *pos) { unsigned int i; - if (j->index == NULL) + if (j->index == NULL) { return; + } /* * Search for a vacant position. */ for (i = 0; i < j->header.index_size; i++) { - if (!POS_VALID(j->index[i])) + if (!POS_VALID(j->index[i])) { break; + } } if (i == j->header.index_size) { unsigned int k = 0; @@ -912,11 +937,13 @@ static void index_invalidate(dns_journal_t *j, uint32_t serial) { unsigned int i; - if (j->index == NULL) + if (j->index == NULL) { return; + } for (i = 0; i < j->header.index_size; i++) { - if (!DNS_SERIAL_GT(serial, j->index[i].serial)) + if (!DNS_SERIAL_GT(serial, j->index[i].serial)) { POS_INVALIDATE(j->index[i]); + } } } @@ -946,10 +973,12 @@ journal_find(dns_journal_t *j, uint32_t serial, journal_pos_t *pos) journal_pos_t current_pos; REQUIRE(DNS_JOURNAL_VALID(j)); - if (DNS_SERIAL_GT(j->header.begin.serial, serial)) + if (DNS_SERIAL_GT(j->header.begin.serial, serial)) { return (ISC_R_RANGE); - if (DNS_SERIAL_GT(serial, j->header.end.serial)) + } + if (DNS_SERIAL_GT(serial, j->header.end.serial)) { return (ISC_R_RANGE); + } if (serial == j->header.end.serial) { *pos = j->header.end; return (ISC_R_SUCCESS); @@ -959,11 +988,13 @@ journal_find(dns_journal_t *j, uint32_t serial, journal_pos_t *pos) index_find(j, serial, ¤t_pos); while (current_pos.serial != serial) { - if (DNS_SERIAL_GT(current_pos.serial, serial)) + if (DNS_SERIAL_GT(current_pos.serial, serial)) { return (ISC_R_NOTFOUND); + } result = journal_next(j, ¤t_pos); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } *pos = current_pos; return (ISC_R_SUCCESS); @@ -1035,9 +1066,10 @@ dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff) for (t = ISC_LIST_HEAD(diff->tuples); t != NULL; t = ISC_LIST_NEXT(t, link)) { if (t->rdata.type == dns_rdatatype_soa) { - if (j->x.n_soa < 2) + if (j->x.n_soa < 2) { j->x.pos[j->x.n_soa].serial = dns_soa_getserial(&t->rdata); + } j->x.n_soa++; } size += sizeof(journal_rawrrhdr_t); @@ -1094,8 +1126,9 @@ dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff) result = ISC_R_SUCCESS; failure: - if (mem != NULL) + if (mem != NULL) { isc_mem_put(j->mctx, mem, size); + } return (result); } @@ -1180,7 +1213,7 @@ dns_journal_commit(dns_journal_t *j) if (DNS_SERIAL_GT(last_dumped_serial, j->x.pos[1].serial)) { force_dump(...); } -#endif +#endif /* ifdef notyet */ /* * Commit the transaction data to stable storage. @@ -1202,8 +1235,9 @@ dns_journal_commit(dns_journal_t *j) /* * Update the journal header. */ - if (JOURNAL_EMPTY(&j->header)) + if (JOURNAL_EMPTY(&j->header)) { j->header.begin = j->x.pos[0]; + } j->header.end = j->x.pos[1]; journal_header_encode(&j->header, &rawheader); CHECK(journal_seek(j, 0)); @@ -1259,20 +1293,26 @@ dns_journal_destroy(dns_journal_t **journalp) j->it.result = ISC_R_FAILURE; dns_name_invalidate(&j->it.name); dns_decompress_invalidate(&j->it.dctx); - if (j->rawindex != NULL) + if (j->rawindex != NULL) { isc_mem_put(j->mctx, j->rawindex, j->header.index_size * sizeof(journal_rawpos_t)); - if (j->index != NULL) + } + if (j->index != NULL) { isc_mem_put(j->mctx, j->index, j->header.index_size * sizeof(journal_pos_t)); - if (j->it.target.base != NULL) + } + if (j->it.target.base != NULL) { isc_mem_put(j->mctx, j->it.target.base, j->it.target.length); - if (j->it.source.base != NULL) + } + if (j->it.source.base != NULL) { isc_mem_put(j->mctx, j->it.source.base, j->it.source.length); - if (j->filename != NULL) + } + if (j->filename != NULL) { isc_mem_free(j->mctx, j->filename); - if (j->fp != NULL) + } + if (j->fp != NULL) { (void)isc_stdio_close(j->fp); + } j->magic = 0; isc_mem_putanddetach(&j->mctx, j, sizeof(*j)); } @@ -1337,8 +1377,9 @@ roll_forward(dns_journal_t *j, dns_db_t *db, unsigned int options) */ end_serial = dns_journal_last_serial(j); - if (db_serial == end_serial) + if (db_serial == end_serial) { CHECK(DNS_R_UPTODATE); + } CHECK(dns_journal_iter_init(j, db_serial, end_serial)); @@ -1355,12 +1396,14 @@ roll_forward(dns_journal_t *j, dns_db_t *db, unsigned int options) if (rdata->type == dns_rdatatype_soa) { n_soa++; - if (n_soa == 2) + if (n_soa == 2) { db_serial = j->it.current_serial; + } } - if (n_soa == 3) + if (n_soa == 3) { n_soa = 1; + } if (n_soa == 0) { isc_log_write(JOURNAL_COMMON_LOGARGS, ISC_LOG_ERROR, "%s: journal file corrupt: missing " @@ -1368,11 +1411,12 @@ roll_forward(dns_journal_t *j, dns_db_t *db, unsigned int options) j->filename); FAIL(ISC_R_UNEXPECTED); } - if ((options & DNS_JOURNALOPT_RESIGN) != 0) + if ((options & DNS_JOURNALOPT_RESIGN) != 0) { op = (n_soa == 1) ? DNS_DIFFOP_DELRESIGN : DNS_DIFFOP_ADDRESIGN; - else + } else { op = (n_soa == 1) ? DNS_DIFFOP_DEL : DNS_DIFFOP_ADD; + } CHECK(dns_difftuple_create(diff.mctx, op, name, ttl, rdata, &tuple)); @@ -1388,8 +1432,9 @@ roll_forward(dns_journal_t *j, dns_db_t *db, unsigned int options) n_put = 0; } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } CHECK(result); if (n_put != 0) { @@ -1402,14 +1447,17 @@ roll_forward(dns_journal_t *j, dns_db_t *db, unsigned int options) } failure: - if (ver != NULL) + if (ver != NULL) { dns_db_closeversion(db, &ver, result == ISC_R_SUCCESS ? true : false); + } - if (source.base != NULL) + if (source.base != NULL) { isc_mem_put(j->mctx, source.base, source.length); - if (target.base != NULL) + } + if (target.base != NULL) { isc_mem_put(j->mctx, target.base, target.length); + } dns_diff_clear(&diff); @@ -1435,12 +1483,14 @@ dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, unsigned int options, "that's OK"); return (DNS_R_NOJOURNAL); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (JOURNAL_EMPTY(&j->header)) + } + if (JOURNAL_EMPTY(&j->header)) { result = DNS_R_UPTODATE; - else + } else { result = roll_forward(j, db, options); + } dns_journal_destroy(&j); @@ -1476,8 +1526,9 @@ dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file) return (result); } - if (j->header.serialset) + if (j->header.serialset) { fprintf(file, "Source serial = %u\n", j->header.sourceserial); + } dns_diff_init(j->mctx, &diff); /* @@ -1504,11 +1555,13 @@ dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file) rdata = NULL; dns_journal_current_rr(j, &name, &ttl, &rdata); - if (rdata->type == dns_rdatatype_soa) + if (rdata->type == dns_rdatatype_soa) { n_soa++; + } - if (n_soa == 3) + if (n_soa == 3) { n_soa = 1; + } if (n_soa == 0) { isc_log_write(JOURNAL_COMMON_LOGARGS, ISC_LOG_ERROR, "%s: journal file corrupt: missing " @@ -1525,12 +1578,14 @@ dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file) result = dns_diff_print(&diff, file); dns_diff_clear(&diff); n_put = 0; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } CHECK(result); if (n_put != 0) { @@ -1544,10 +1599,12 @@ failure: "%s: cannot print: journal file corrupt", j->filename); cleanup: - if (source.base != NULL) + if (source.base != NULL) { isc_mem_put(j->mctx, source.base, source.length); - if (target.base != NULL) + } + if (target.base != NULL) { isc_mem_put(j->mctx, target.base, target.length); + } dns_diff_clear(&diff); dns_journal_destroy(&j); @@ -1586,8 +1643,9 @@ dns_journal_set_sourceserial(dns_journal_t *j, uint32_t sourceserial) j->header.sourceserial = sourceserial; j->header.serialset = true; - if (j->state == JOURNAL_STATE_WRITE) + if (j->state == JOURNAL_STATE_WRITE) { j->state = JOURNAL_STATE_INLINE; + } } bool @@ -1595,8 +1653,9 @@ dns_journal_get_sourceserial(dns_journal_t *j, uint32_t *sourceserial) { REQUIRE(sourceserial != NULL); - if (!j->header.serialset) + if (!j->header.serialset) { return (false); + } *sourceserial = j->header.sourceserial; return (true); } @@ -1630,10 +1689,12 @@ size_buffer(isc_mem_t *mctx, isc_buffer_t *b, unsigned size) { if (b->length < size) { void *mem = isc_mem_get(mctx, size); - if (mem == NULL) + if (mem == NULL) { return (ISC_R_NOMEMORY); - if (b->base != NULL) + } + if (b->base != NULL) { isc_mem_put(mctx, b->base, b->length); + } b->base = mem; b->length = size; } @@ -1698,8 +1759,9 @@ read_one_rr(dns_journal_t *j) j->filename); return (ISC_R_UNEXPECTED); } - if (j->offset == j->it.epos.offset) + if (j->offset == j->it.epos.offset) { return (ISC_R_NOMORE); + } if (j->it.xpos == j->it.xsize) { /* * We are at a transaction boundary. @@ -1767,8 +1829,9 @@ read_one_rr(dns_journal_t *j) /* * Check that the RR header is there, and parse it. */ - if (isc_buffer_remaininglength(&j->it.source) < 10) + if (isc_buffer_remaininglength(&j->it.source) < 10) { FAIL(DNS_R_FORMERR); + } rdtype = isc_buffer_getuint16(&j->it.source); rdclass = isc_buffer_getuint16(&j->it.source); @@ -1778,8 +1841,9 @@ read_one_rr(dns_journal_t *j) /* * Parse the rdata. */ - if (isc_buffer_remaininglength(&j->it.source) != rdlen) + if (isc_buffer_remaininglength(&j->it.source) != rdlen) { FAIL(DNS_R_FORMERR); + } isc_buffer_setactive(&j->it.source, rdlen); dns_rdata_reset(&j->it.rdata); CHECK(dns_rdata_fromwire(&j->it.rdata, rdclass, rdtype, &j->it.source, @@ -1841,12 +1905,14 @@ get_name_diff(dns_db_t *db, dns_dbversion_t *ver, isc_stdtime_t now, dns_difftuple_t * tuple = NULL; result = dns_dbiterator_current(dbit, &node, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_allrdatasets(db, node, ver, now, &rdsiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(rdsiter)) { @@ -1870,11 +1936,13 @@ get_name_diff(dns_db_t *db, dns_dbversion_t *ver, isc_stdtime_t now, dns_diff_append(diff, &tuple); } dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto cleanup_iterator; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto cleanup_iterator; + } result = ISC_R_SUCCESS; @@ -1902,8 +1970,9 @@ rdata_order(const void *av, const void *bv) dns_difftuple_t const * b = *bp; int r; r = (b->rdata.type - a->rdata.type); - if (r != 0) + if (r != 0) { return (r); + } r = dns_rdata_compare(&a->rdata, &b->rdata); return (r); } @@ -1922,8 +1991,9 @@ dns_diff_subtract(dns_diff_t diff[2], dns_diff_t *r) for (;;) { p[0] = ISC_LIST_HEAD(diff[0].tuples); p[1] = ISC_LIST_HEAD(diff[1].tuples); - if (p[0] == NULL && p[1] == NULL) + if (p[0] == NULL && p[1] == NULL) { break; + } for (i = 0; i < 2; i++) { if (p[!i] == NULL) { @@ -1991,11 +2061,13 @@ diff_namespace(dns_db_t *dba, dns_dbversion_t *dbvera, dns_db_t *dbb, dns_fixedname_init(&fixname[1]); result = dns_db_createiterator(db[0], options, &dbit[0]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_createiterator(db[1], options, &dbit[1]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iterator; + } itresult[0] = dns_dbiterator_first(dbit[0]); itresult[1] = dns_dbiterator_first(dbit[1]); @@ -2053,10 +2125,12 @@ diff_namespace(dns_db_t *dba, dns_dbversion_t *dbvera, dns_db_t *dbb, have[0] = have[1] = false; next:; } - if (itresult[0] != ISC_R_NOMORE) + if (itresult[0] != ISC_R_NOMORE) { FAIL(itresult[0]); - if (itresult[1] != ISC_R_NOMORE) + } + if (itresult[1] != ISC_R_NOMORE) { FAIL(itresult[1]); + } INSIST(ISC_LIST_EMPTY(diff[0].tuples)); INSIST(ISC_LIST_EMPTY(diff[1].tuples)); @@ -2103,23 +2177,26 @@ dns_db_diffx(dns_diff_t *diff, dns_db_t *dba, dns_dbversion_t *dbvera, if (filename != NULL) { result = dns_journal_open(diff->mctx, filename, DNS_JOURNAL_CREATE, &journal); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } CHECK(diff_namespace(dba, dbvera, dbb, dbverb, DNS_DB_NONSEC3, diff)); CHECK(diff_namespace(dba, dbvera, dbb, dbverb, DNS_DB_NSEC3ONLY, diff)); if (journal != NULL) { - if (ISC_LIST_EMPTY(diff->tuples)) + if (ISC_LIST_EMPTY(diff->tuples)) { isc_log_write(JOURNAL_DEBUG_LOGARGS(3), "no changes"); - else + } else { CHECK(dns_journal_write_transaction(journal, diff)); + } } failure: - if (journal != NULL) + if (journal != NULL) { dns_journal_destroy(&journal); + } return (result); } @@ -2163,8 +2240,9 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, is_backup = true; result = journal_open(mctx, backup, false, false, &j1); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (JOURNAL_EMPTY(&j1->header)) { dns_journal_destroy(&j1); @@ -2182,10 +2260,12 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, */ indexend = sizeof(journal_rawheader_t) + j1->header.index_size * sizeof(journal_rawpos_t); - if (target_size < DNS_JOURNAL_SIZE_MIN) + if (target_size < DNS_JOURNAL_SIZE_MIN) { target_size = DNS_JOURNAL_SIZE_MIN; - if (target_size < indexend * 2) + } + if (target_size < indexend * 2) { target_size = target_size / 2 + indexend; + } /* * See if there is any work to do. @@ -2200,8 +2280,9 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, /* * Remove overhead so space test below can succeed. */ - if (target_size >= indexend) + if (target_size >= indexend) { target_size -= indexend; + } /* * Find if we can create enough free space. @@ -2212,28 +2293,32 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, DNS_SERIAL_GE(serial, j1->index[i].serial) && ((uint32_t)(j1->header.end.offset - j1->index[i].offset) >= target_size / 2) && - j1->index[i].offset > best_guess.offset) + j1->index[i].offset > best_guess.offset) { best_guess = j1->index[i]; + } } current_pos = best_guess; while (current_pos.serial != serial) { CHECK(journal_next(j1, ¤t_pos)); - if (current_pos.serial == j1->header.end.serial) + if (current_pos.serial == j1->header.end.serial) { break; + } if (DNS_SERIAL_GE(serial, current_pos.serial) && ((uint32_t)(j1->header.end.offset - current_pos.offset) >= (target_size / 2)) && - current_pos.offset > best_guess.offset) + current_pos.offset > best_guess.offset) { best_guess = current_pos; - else + } else { break; + } } INSIST(best_guess.serial != j1->header.end.serial); - if (best_guess.serial != serial) + if (best_guess.serial != serial) { CHECK(journal_next(j1, &best_guess)); + } /* * We should now be roughly half target_size provided @@ -2247,8 +2332,9 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, * Copy best_guess to end into space just freed. */ size = 64 * 1024; - if (copy_length < size) + if (copy_length < size) { size = copy_length; + } buf = isc_mem_get(mctx, size); CHECK(journal_seek(j1, best_guess.offset)); @@ -2322,12 +2408,15 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, if (errno == EEXIST && !is_backup) { result = isc_file_remove(backup); if (result != ISC_R_SUCCESS && - result != ISC_R_FILENOTFOUND) + result != ISC_R_FILENOTFOUND) { goto failure; - if (rename(filename, backup) == -1) + } + if (rename(filename, backup) == -1) { goto maperrno; - if (rename(newname, filename) == -1) + } + if (rename(newname, filename) == -1) { goto maperrno; + } (void)isc_file_remove(backup); } else { maperrno: @@ -2340,12 +2429,15 @@ dns_journal_compact(isc_mem_t *mctx, char *filename, uint32_t serial, failure: (void)isc_file_remove(newname); - if (buf != NULL) + if (buf != NULL) { isc_mem_put(mctx, buf, size); - if (j1 != NULL) + } + if (j1 != NULL) { dns_journal_destroy(&j1); - if (j2 != NULL) + } + if (j2 != NULL) { dns_journal_destroy(&j2); + } return (result); } diff --git a/lib/dns/key.c b/lib/dns/key.c index b8b059619a..afd3655e58 100644 --- a/lib/dns/key.c +++ b/lib/dns/key.c @@ -36,11 +36,13 @@ dst_region_computeid(const isc_region_t *source) p = source->base; size = source->length; - for (ac = 0; size > 1; size -= 2, p += 2) + for (ac = 0; size > 1; size -= 2, p += 2) { ac += ((*p) << 8) + *(p + 1); + } - if (size > 0) + if (size > 0) { ac += ((*p) << 8); + } ac += (ac >> 16) & 0xffff; return ((uint16_t)(ac & 0xffff)); @@ -61,11 +63,13 @@ dst_region_computerid(const isc_region_t *source) ac = ((*p) << 8) + *(p + 1); ac |= DNS_KEYFLAG_REVOKE; - for (size -= 2, p += 2; size > 1; size -= 2, p += 2) + for (size -= 2, p += 2; size > 1; size -= 2, p += 2) { ac += ((*p) << 8) + *(p + 1); + } - if (size > 0) + if (size > 0) { ac += ((*p) << 8); + } ac += (ac >> 16) & 0xffff; return ((uint16_t)(ac & 0xffff)); @@ -132,13 +136,16 @@ dst_key_iszonekey(const dst_key_t *key) { REQUIRE(VALID_KEY(key)); - if ((key->key_flags & DNS_KEYTYPE_NOAUTH) != 0) + if ((key->key_flags & DNS_KEYTYPE_NOAUTH) != 0) { return (false); - if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) + } + if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) { return (false); + } if (key->key_proto != DNS_KEYPROTO_DNSSEC && - key->key_proto != DNS_KEYPROTO_ANY) + key->key_proto != DNS_KEYPROTO_ANY) { return (false); + } return (true); } @@ -147,13 +154,16 @@ dst_key_isnullkey(const dst_key_t *key) { REQUIRE(VALID_KEY(key)); - if ((key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY) + if ((key->key_flags & DNS_KEYFLAG_TYPEMASK) != DNS_KEYTYPE_NOKEY) { return (false); - if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) + } + if ((key->key_flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) { return (false); + } if (key->key_proto != DNS_KEYPROTO_DNSSEC && - key->key_proto != DNS_KEYPROTO_ANY) + key->key_proto != DNS_KEYPROTO_ANY) { return (false); + } return (true); } diff --git a/lib/dns/keydata.c b/lib/dns/keydata.c index a5c8481a99..0024c5f034 100644 --- a/lib/dns/keydata.c +++ b/lib/dns/keydata.c @@ -37,9 +37,9 @@ dns_keydata_todnskey(dns_rdata_keydata_t *keydata, dns_rdata_dnskey_t *dnskey, dnskey->datalen = keydata->datalen; - if (mctx == NULL) + if (mctx == NULL) { dnskey->data = keydata->data; - else { + } else { dnskey->data = isc_mem_allocate(mctx, dnskey->datalen); memmove(dnskey->data, keydata->data, dnskey->datalen); } @@ -65,9 +65,9 @@ dns_keydata_fromdnskey(dns_rdata_keydata_t *keydata, dns_rdata_dnskey_t *dnskey, keydata->algorithm = dnskey->algorithm; keydata->datalen = dnskey->datalen; - if (mctx == NULL) + if (mctx == NULL) { keydata->data = dnskey->data; - else { + } else { keydata->data = isc_mem_allocate(mctx, keydata->datalen); memmove(keydata->data, dnskey->data, keydata->datalen); } diff --git a/lib/dns/lib.c b/lib/dns/lib.c index 37ca1b0ad1..b9e8d8100f 100644 --- a/lib/dns/lib.c +++ b/lib/dns/lib.c @@ -56,22 +56,26 @@ initialize(void) isc_mem_create(&dns_g_mctx); dns_result_register(); result = dns_ecdb_register(dns_g_mctx, &dbimp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_mctx; + } result = dst_lib_init(dns_g_mctx, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_db; + } initialize_done = true; return; cleanup_db: - if (dbimp != NULL) + if (dbimp != NULL) { dns_ecdb_unregister(&dbimp); + } cleanup_mctx: - if (dns_g_mctx != NULL) + if (dns_g_mctx != NULL) { isc_mem_detach(&dns_g_mctx); + } } isc_result_t @@ -85,11 +89,13 @@ dns_lib_init(void) * abort, on any failure. */ result = isc_once_do(&init_once, initialize); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (!initialize_done) + if (!initialize_done) { return (ISC_R_FAILURE); + } isc_refcount_increment0(&references); diff --git a/lib/dns/lookup.c b/lib/dns/lookup.c index 1e54f59d72..d71b5417ef 100644 --- a/lib/dns/lookup.c +++ b/lib/dns/lookup.c @@ -129,10 +129,11 @@ view_find(dns_lookup_t *lookup, dns_name_t *foundname) dns_name_t * name = dns_fixedname_name(&lookup->name); dns_rdatatype_t type; - if (lookup->type == dns_rdatatype_rrsig) + if (lookup->type == dns_rdatatype_rrsig) { type = dns_rdatatype_any; - else + } else { type = lookup->type; + } result = dns_view_find(lookup->view, name, type, 0, 0, false, false, &lookup->event->db, &lookup->event->node, @@ -181,8 +182,9 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) dns_db_detachnode(lookup->event->db, &lookup->event->node); } - if (lookup->event->db != NULL) + if (lookup->event->db != NULL) { dns_db_detach(&lookup->event->db); + } result = view_find(lookup, fname); if (result == ISC_R_NOTFOUND) { /* @@ -194,11 +196,13 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) dns_db_detachnode(lookup->event->db, &lookup->event->node); } - if (lookup->event->db != NULL) + if (lookup->event->db != NULL) { dns_db_detach(&lookup->event->db); + } result = start_fetch(lookup); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { send_event = false; + } goto done; } } else if (event != NULL) { @@ -207,26 +211,31 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) dns_resolver_destroyfetch(&lookup->fetch); INSIST(event->rdataset == &lookup->rdataset); INSIST(event->sigrdataset == &lookup->sigrdataset); - } else + } else { fname = NULL; /* Silence compiler warning. */ + } /* * If we've been canceled, forget about the result. */ - if (lookup->canceled) + if (lookup->canceled) { result = ISC_R_CANCELED; + } switch (result) { case ISC_R_SUCCESS: result = build_event(lookup); - if (event == NULL) + if (event == NULL) { break; - if (event->db != NULL) + } + if (event->db != NULL) { dns_db_attach(event->db, &lookup->event->db); - if (event->node != NULL) + } + if (event->node != NULL) { dns_db_attachnode(lookup->event->db, event->node, &lookup->event->node); + } break; case DNS_R_CNAME: /* @@ -234,13 +243,15 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) * query name and start over. */ result = dns_rdataset_first(&lookup->rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } dns_rdataset_current(&lookup->rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &cname, NULL); dns_rdata_reset(&rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } dns_name_copynf(&cname.cname, name); dns_rdata_freestruct(&cname); want_restart = true; @@ -254,13 +265,15 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) * Get the target name of the DNAME. */ result = dns_rdataset_first(&lookup->rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } dns_rdataset_current(&lookup->rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &dname, NULL); dns_rdata_reset(&rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } /* * Construct the new query name and start over. */ @@ -278,17 +291,21 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) send_event = true; } - if (dns_rdataset_isassociated(&lookup->rdataset)) + if (dns_rdataset_isassociated(&lookup->rdataset)) { dns_rdataset_disassociate(&lookup->rdataset); - if (dns_rdataset_isassociated(&lookup->sigrdataset)) + } + if (dns_rdataset_isassociated(&lookup->sigrdataset)) { dns_rdataset_disassociate(&lookup->sigrdataset); + } done: if (event != NULL) { - if (event->node != NULL) + if (event->node != NULL) { dns_db_detachnode(event->db, &event->node); - if (event->db != NULL) + } + if (event->db != NULL) { dns_db_detach(&event->db); + } isc_event_free(ISC_EVENT_PTR(&event)); } @@ -300,7 +317,6 @@ lookup_find(dns_lookup_t *lookup, dns_fetchevent_t *event) result = ISC_R_QUOTA; send_event = true; } - } while (want_restart); if (send_event) { @@ -325,8 +341,9 @@ levent_destroy(isc_event_t *event) levent = (dns_lookupevent_t *)event; if (levent->name != NULL) { - if (dns_name_dynamic(levent->name)) + if (dns_name_dynamic(levent->name)) { dns_name_free(levent->name, mctx); + } isc_mem_put(mctx, levent->name, sizeof(dns_name_t)); } if (levent->rdataset != NULL) { @@ -337,10 +354,12 @@ levent_destroy(isc_event_t *event) dns_rdataset_disassociate(levent->sigrdataset); isc_mem_put(mctx, levent->sigrdataset, sizeof(dns_rdataset_t)); } - if (levent->node != NULL) + if (levent->node != NULL) { dns_db_detachnode(levent->db, &levent->node); - if (levent->db != NULL) + } + if (levent->db != NULL) { dns_db_detach(&levent->db); + } isc_mem_put(mctx, event, event->ev_size); } @@ -425,10 +444,12 @@ dns_lookup_destroy(dns_lookup_t **lookupp) REQUIRE(lookup->event == NULL); REQUIRE(lookup->task == NULL); REQUIRE(lookup->view == NULL); - if (dns_rdataset_isassociated(&lookup->rdataset)) + if (dns_rdataset_isassociated(&lookup->rdataset)) { dns_rdataset_disassociate(&lookup->rdataset); - if (dns_rdataset_isassociated(&lookup->sigrdataset)) + } + if (dns_rdataset_isassociated(&lookup->sigrdataset)) { dns_rdataset_disassociate(&lookup->sigrdataset); + } isc_mutex_destroy(&lookup->lock); lookup->magic = 0; diff --git a/lib/dns/master.c b/lib/dns/master.c index be8e10c596..092b4e6823 100644 --- a/lib/dns/master.c +++ b/lib/dns/master.c @@ -364,25 +364,27 @@ gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *token, bool eol, /*NOTREACHED*/ } if (eol != true) { - if (token->type == isc_tokentype_eol || token->type == isc_tokentype_eof) { + if (token->type == isc_tokentype_eol || + token->type == isc_tokentype_eof) { { unsigned long int line; - const char *what; - const char *file; + const char * what; + const char * file; file = isc_lex_getsourcename(lex); line = isc_lex_getsourceline(lex); if (token->type == isc_tokentype_eol) { line--; what = "line"; - }else + } else { what = "file"; + } (*callbacks->error)(callbacks, "dns_master_load: %s:%lu: " "unexpected end of %s", file, line, what); return (ISC_R_UNEXPECTEDEND); } - } + } } return (ISC_R_SUCCESS); } @@ -525,8 +527,9 @@ loadctx_create(dns_masterformat_t format, isc_mem_t *mctx, unsigned int options, lctx->inc = NULL; result = incctx_create(mctx, origin, &lctx->inc); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_ctx; + } lctx->maxttl = 0; @@ -555,8 +558,9 @@ loadctx_create(dns_masterformat_t format, isc_mem_t *mctx, unsigned int options, } else { lctx->lex = NULL; result = isc_lex_create(mctx, TOKENSIZ, &lctx->lex); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_inc; + } lctx->keep_lex = false; /* * If specials change update dns_test_rdatafromstring() @@ -598,8 +602,9 @@ loadctx_create(dns_masterformat_t format, isc_mem_t *mctx, unsigned int options, lctx->loop_cnt = (done != NULL) ? 100 : 0; lctx->callbacks = callbacks; lctx->task = NULL; - if (task != NULL) + if (task != NULL) { isc_task_attach(task, &lctx->task); + } lctx->done = done; lctx->done_arg = done_arg; atomic_init(&lctx->canceled, false); @@ -649,8 +654,9 @@ nibbles(char *numbuf, size_t length, unsigned int width, char mode, int value) *numbuf = '\0'; length--; } - if (width > 0) + if (width > 0) { width--; + } count++; /* * If width is non zero then we need to add a label seperator. @@ -663,8 +669,9 @@ nibbles(char *numbuf, size_t length, unsigned int width, char mode, int value) *numbuf = '\0'; length--; } - if (width > 0) + if (width > 0) { width--; + } count++; } } while (value != 0 || width > 0); @@ -691,8 +698,9 @@ genname(char *name, int it, char *buffer, size_t length) if (*name == '$') { name++; if (*name == '$') { - if (r.length == 0) + if (r.length == 0) { return (ISC_R_NOSPACE); + } r.base[0] = *name++; isc_textregion_consume(&r, 1); continue; @@ -711,55 +719,66 @@ genname(char *name, int it, char *buffer, size_t length) width); break; case 3: - if (mode[0] == 'n' || mode[0] == 'N') + if (mode[0] == 'n' || mode[0] == 'N') { nibblemode = true; + } n = snprintf(fmt, sizeof(fmt), "%%0%u%c", width, mode[0]); break; default: return (DNS_R_SYNTAX); } - if (n >= sizeof(fmt)) + if (n >= sizeof(fmt)) { return (ISC_R_NOSPACE); + } /* Skip past closing brace. */ - while (*name != '\0' && *name++ != '}') + while (*name != '\0' && *name++ != '}') { continue; + } } - if (nibblemode) + if (nibblemode) { n = nibbles(numbuf, sizeof(numbuf), width, mode[0], it + delta); - else + } else { n = snprintf(numbuf, sizeof(numbuf), fmt, it + delta); - if (n >= sizeof(numbuf)) + } + if (n >= sizeof(numbuf)) { return (ISC_R_NOSPACE); + } cp = numbuf; while (*cp != '\0') { - if (r.length == 0) + if (r.length == 0) { return (ISC_R_NOSPACE); + } r.base[0] = *cp++; isc_textregion_consume(&r, 1); } } else if (*name == '\\') { - if (r.length == 0) + if (r.length == 0) { return (ISC_R_NOSPACE); + } r.base[0] = *name++; isc_textregion_consume(&r, 1); - if (*name == '\0') + if (*name == '\0') { continue; - if (r.length == 0) + } + if (r.length == 0) { return (ISC_R_NOSPACE); + } r.base[0] = *name++; isc_textregion_consume(&r, 1); } else { - if (r.length == 0) + if (r.length == 0) { return (ISC_R_NOSPACE); + } r.base[0] = *name++; isc_textregion_consume(&r, 1); } } - if (r.length == 0) + if (r.length == 0) { return (ISC_R_NOSPACE); + } r.base[0] = '\0'; return (ISC_R_SUCCESS); } @@ -809,8 +828,9 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs, result = DNS_R_SYNTAX; goto insist_cleanup; } - if (n == 2) + if (n == 2) { step = 1; + } /* * Get type. @@ -840,19 +860,22 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs, for (i = start; i <= stop; i += step) { result = genname(lhs, i, lhsbuf, DNS_MASTER_LHS); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error_cleanup; + } result = genname(rhs, i, rhsbuf, DNS_MASTER_RHS); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error_cleanup; + } isc_buffer_init(&buffer, lhsbuf, strlen(lhsbuf)); isc_buffer_add(&buffer, strlen(lhsbuf)); isc_buffer_setactive(&buffer, strlen(lhsbuf)); result = dns_name_fromtext(owner, &buffer, ictx->origin, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error_cleanup; + } if ((lctx->options & DNS_MASTER_ZONE) != 0 && (lctx->options & DNS_MASTER_SLAVE) == 0 && @@ -875,16 +898,18 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs, isc_buffer_setactive(&buffer, strlen(rhsbuf)); result = isc_lex_openbuffer(lctx->lex, &buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error_cleanup; + } isc_buffer_init(&target, target_mem, target_size); result = dns_rdata_fromtext(&rdata, lctx->zclass, type, lctx->lex, ictx->origin, 0, lctx->mctx, &target, callbacks); RUNTIME_CHECK(isc_lex_close(lctx->lex) == ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error_cleanup; + } dns_rdatalist_init(&rdatalist); rdatalist.type = type; @@ -894,31 +919,36 @@ generate(dns_loadctx_t *lctx, char *range, char *lhs, char *gtype, char *rhs, ISC_LIST_APPEND(rdatalist.rdata, &rdata, link); result = commit(callbacks, lctx, &head, owner, source, line); ISC_LIST_UNLINK(rdatalist.rdata, &rdata, link); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto error_cleanup; + } dns_rdata_reset(&rdata); } result = ISC_R_SUCCESS; goto cleanup; error_cleanup: - if (result == ISC_R_NOMEMORY) + if (result == ISC_R_NOMEMORY) { (*callbacks->error)(callbacks, "$GENERATE: %s", dns_result_totext(result)); - else + } else { (*callbacks->error)(callbacks, "$GENERATE: %s:%lu: %s", source, line, dns_result_totext(result)); + } insist_cleanup: INSIST(result != ISC_R_SUCCESS); cleanup: - if (target_mem != NULL) + if (target_mem != NULL) { isc_mem_put(lctx->mctx, target_mem, target_size); - if (lhsbuf != NULL) + } + if (lhsbuf != NULL) { isc_mem_put(lctx->mctx, lhsbuf, DNS_MASTER_LHS); - if (rhsbuf != NULL) + } + if (rhsbuf != NULL) { isc_mem_put(lctx->mctx, rhsbuf, DNS_MASTER_RHS); + } return (result); } @@ -944,10 +974,11 @@ check_ns(dns_loadctx_t *lctx, isc_token_t *token, const char *source, isc_result_t result = ISC_R_SUCCESS; void (*callback)(struct dns_rdatacallbacks *, const char *, ...); - if ((lctx->options & DNS_MASTER_FATALNS) != 0) + if ((lctx->options & DNS_MASTER_FATALNS) != 0) { callback = lctx->callbacks->error; - else + } else { callback = lctx->callbacks->warn; + } if (token->type == isc_tokentype_string) { struct in_addr addr; @@ -957,19 +988,23 @@ check_ns(dns_loadctx_t *lctx, isc_token_t *token, const char *source, /* * Catch both "1.2.3.4" and "1.2.3.4." */ - if (tmp[strlen(tmp) - 1] == '.') + if (tmp[strlen(tmp) - 1] == '.') { tmp[strlen(tmp) - 1] = '\0'; + } if (inet_pton(AF_INET, tmp, &addr) == 1 || - inet_pton(AF_INET6, tmp, &addr6) == 1) + inet_pton(AF_INET6, tmp, &addr6) == 1) { result = DNS_R_NSISADDRESS; + } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { (*callback)(lctx->callbacks, "%s:%lu: NS record '%s' " "appears to be an address", source, line, DNS_AS_STR(*token)); - if (tmp != NULL) + } + if (tmp != NULL) { isc_mem_free(lctx->mctx, tmp); + } return (result); } @@ -1078,14 +1113,18 @@ load_text(dns_loadctx_t *lctx) isc_buffer_init(&target, target_mem, target_size); target_save = target; - if ((lctx->options & DNS_MASTER_CHECKNAMES) != 0) + if ((lctx->options & DNS_MASTER_CHECKNAMES) != 0) { options |= DNS_RDATA_CHECKNAMES; - if ((lctx->options & DNS_MASTER_CHECKNAMESFAIL) != 0) + } + if ((lctx->options & DNS_MASTER_CHECKNAMESFAIL) != 0) { options |= DNS_RDATA_CHECKNAMESFAIL; - if ((lctx->options & DNS_MASTER_CHECKMX) != 0) + } + if ((lctx->options & DNS_MASTER_CHECKMX) != 0) { options |= DNS_RDATA_CHECKMX; - if ((lctx->options & DNS_MASTER_CHECKMXFAIL) != 0) + } + if ((lctx->options & DNS_MASTER_CHECKMXFAIL) != 0) { options |= DNS_RDATA_CHECKMXFAIL; + } source = isc_lex_getsourcename(lctx->lex); do { initialws = false; @@ -1095,8 +1134,9 @@ load_text(dns_loadctx_t *lctx) line = isc_lex_getsourceline(lctx->lex); if (token.type == isc_tokentype_eof) { - if (read_till_eol) + if (read_till_eol) { WARNUNEXPECTEDEOF(lctx->lex); + } /* Pop the include stack? */ if (ictx->parent != NULL) { COMMITALL; @@ -1120,8 +1160,9 @@ load_text(dns_loadctx_t *lctx) continue; /* blank line */ } - if (read_till_eol) + if (read_till_eol) { continue; + } if (token.type == isc_tokentype_initialws) { /* @@ -1150,8 +1191,9 @@ load_text(dns_loadctx_t *lctx) if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); lctx->ttl = 0; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } limit_ttl(callbacks, source, line, &lctx->ttl); lctx->default_ttl = lctx->ttl; lctx->default_ttl_known = true; @@ -1184,16 +1226,18 @@ load_text(dns_loadctx_t *lctx) } GETTOKEN(lctx->lex, ISC_LEXOPT_QSTRING, &token, false); - if (include_file != NULL) + if (include_file != NULL) { isc_mem_free(mctx, include_file); + } include_file = isc_mem_strdup(mctx, DNS_AS_STR(token)); GETTOKEN(lctx->lex, 0, &token, true); if (token.type == isc_tokentype_eol || token.type == isc_tokentype_eof) { - if (token.type == isc_tokentype_eof) + if (token.type == isc_tokentype_eof) { WARNUNEXPECTEDEOF(lctx->lex); + } /* * No origin field. */ @@ -1232,8 +1276,9 @@ load_text(dns_loadctx_t *lctx) SETRESULT(lctx, result); LOGIT(result); dump_time64 = 0; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto log_and_cleanup; + } dump_time = (isc_stdtime_t)dump_time64; if (dump_time != dump_time64) { UNEXPECTED_ERROR(__FILE__, __LINE__, @@ -1261,14 +1306,18 @@ load_text(dns_loadctx_t *lctx) /* * Lazy cleanup. */ - if (range != NULL) + if (range != NULL) { isc_mem_free(mctx, range); - if (lhs != NULL) + } + if (lhs != NULL) { isc_mem_free(mctx, lhs); - if (gtype != NULL) + } + if (gtype != NULL) { isc_mem_free(mctx, gtype); - if (rhs != NULL) + } + if (rhs != NULL) { isc_mem_free(mctx, rhs); + } range = lhs = gtype = rhs = NULL; /* RANGE */ GETTOKEN(lctx->lex, 0, &token, false); @@ -1301,8 +1350,9 @@ load_text(dns_loadctx_t *lctx) dns_rdataclass_fromtext( &rdclass, &token.value.as_textregion) == - ISC_R_SUCCESS) + ISC_R_SUCCESS) { GETTOKEN(lctx->lex, 0, &token, false); + } /* TYPE */ gtype = isc_mem_strdup(mctx, DNS_AS_STR(token)); /* RHS */ @@ -1339,8 +1389,9 @@ load_text(dns_loadctx_t *lctx) source, line); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } EXPECTEOL; continue; } else if (strncasecmp(DNS_AS_STR(token), "$", 1) == @@ -1376,16 +1427,18 @@ load_text(dns_loadctx_t *lctx) LOGIT(result); read_till_eol = true; continue; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto log_and_cleanup; + } /* * Finish $ORIGIN / $INCLUDE processing if required. */ if (finish_origin) { - if (ictx->origin_in_use != -1) + if (ictx->origin_in_use != -1) { ictx->in_use[ictx->origin_in_use] = false; + } ictx->origin_in_use = new_in_use; ictx->in_use[ictx->origin_in_use] = true; ictx->origin = new_name; @@ -1431,10 +1484,12 @@ load_text(dns_loadctx_t *lctx) ictx->glue_line); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; - if (ictx->glue_in_use != -1) + } + if (ictx->glue_in_use != -1) { ictx->in_use[ictx->glue_in_use] = false; + } ictx->glue_in_use = -1; ictx->glue = NULL; rdcount = rdcount_save; @@ -1467,14 +1522,16 @@ load_text(dns_loadctx_t *lctx) ictx->current_line); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } rdcount = 0; rdlcount = 0; - if (ictx->current_in_use != -1) + if (ictx->current_in_use != -1) { ictx->in_use [ictx->current_in_use] = false; + } ictx->current_in_use = new_in_use; ictx->in_use[ictx->current_in_use] = true; @@ -1487,9 +1544,10 @@ load_text(dns_loadctx_t *lctx) * Check for internal wildcards. */ if ((lctx->options & - DNS_MASTER_CHECKWILDCARD) != 0) + DNS_MASTER_CHECKWILDCARD) != 0) { check_wildcard(ictx, source, line, callbacks); + } } if ((lctx->options & DNS_MASTER_ZONE) != 0 && (lctx->options & DNS_MASTER_SLAVE) == 0 && @@ -1507,8 +1565,9 @@ load_text(dns_loadctx_t *lctx) "(%s)", source, line, namebuf); ictx->drop = true; - } else + } else { ictx->drop = false; + } } else { UNEXPECTED_ERROR(__FILE__, __LINE__, "%s:%lu: isc_lex_gettoken() returned " @@ -1587,8 +1646,9 @@ load_text(dns_loadctx_t *lctx) if (dns_rdataclass_fromtext(&rdclass, &token.value.as_textregion) == - ISC_R_SUCCESS) + ISC_R_SUCCESS) { GETTOKEN(lctx->lex, 0, &token, false); + } explicit_ttl = false; result = dns_ttl_fromtext(&token.value.as_textregion, @@ -1617,8 +1677,9 @@ load_text(dns_loadctx_t *lctx) if (rdclass == 0 && dns_rdataclass_fromtext(&rdclass, &token.value.as_textregion) == - ISC_R_SUCCESS) + ISC_R_SUCCESS) { GETTOKEN(lctx->lex, 0, &token, false); + } if (token.type != isc_tokentype_string) { UNEXPECTED_ERROR(__FILE__, __LINE__, @@ -1645,8 +1706,9 @@ load_text(dns_loadctx_t *lctx) SETRESULT(lctx, result); read_till_eol = true; continue; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } } /* @@ -1675,8 +1737,9 @@ load_text(dns_loadctx_t *lctx) } } - if (type == dns_rdatatype_ns && ictx->glue == NULL) + if (type == dns_rdatatype_ns && ictx->glue == NULL) { current_has_delegation = true; + } /* * RFC1123: MD and MF are not allowed to be loaded from @@ -1695,8 +1758,9 @@ load_text(dns_loadctx_t *lctx) dns_result_totext(result)); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else + } else { goto insist_and_cleanup; + } } /* @@ -1716,8 +1780,9 @@ load_text(dns_loadctx_t *lctx) dns_result_totext(result)); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else + } else { goto insist_and_cleanup; + } } /* @@ -1747,8 +1812,9 @@ load_text(dns_loadctx_t *lctx) if ((lctx->options & DNS_MASTER_FATALNS) != 0) { if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } } } @@ -1790,8 +1856,9 @@ load_text(dns_loadctx_t *lctx) !dns_name_isdnssd(name) && (dns_name_issubdomain(name, &in_addr_arpa) || dns_name_issubdomain(name, &ip6_arpa) || - dns_name_issubdomain(name, &ip6_int))) + dns_name_issubdomain(name, &ip6_int))) { options |= DNS_RDATA_CHECKREVERSE; + } } /* @@ -1805,8 +1872,9 @@ load_text(dns_loadctx_t *lctx) if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); continue; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } if (ictx->drop) { target = target_ft; @@ -1834,10 +1902,11 @@ load_text(dns_loadctx_t *lctx) } } - if (type == dns_rdatatype_rrsig || type == dns_rdatatype_sig) + if (type == dns_rdatatype_rrsig || type == dns_rdatatype_sig) { covers = dns_rdata_covers(&rdata[rdcount]); - else + } else { covers = 0; + } if (!lctx->ttl_known && !lctx->default_ttl_known) { if (type == dns_rdatatype_soa) { @@ -1913,10 +1982,11 @@ load_text(dns_loadctx_t *lctx) * way this was written before the patch it * could potentially add 0 TTLs anyway. */ - if (lctx->ttl < ttl_offset) + if (lctx->ttl < ttl_offset) { lctx->ttl = 0; - else + } else { lctx->ttl -= ttl_offset; + } } /* @@ -1924,14 +1994,16 @@ load_text(dns_loadctx_t *lctx) * If it does not exist create new one and prepend to list * as this will minimise list traversal. */ - if (ictx->glue != NULL) + if (ictx->glue != NULL) { this = ISC_LIST_HEAD(glue_list); - else + } else { this = ISC_LIST_HEAD(current_list); + } while (this != NULL) { - if (this->type == type && this->covers == covers) + if (this->type == type && this->covers == covers) { break; + } this = ISC_LIST_NEXT(this, link); } @@ -1954,11 +2026,12 @@ load_text(dns_loadctx_t *lctx) this->covers = covers; this->rdclass = lctx->zclass; this->ttl = lctx->ttl; - if (ictx->glue != NULL) + if (ictx->glue != NULL) { ISC_LIST_INITANDPREPEND(glue_list, this, link); - else + } else { ISC_LIST_INITANDPREPEND(current_list, this, link); + } } else if (this->ttl != lctx->ttl) { (*callbacks->warn)(callbacks, "%s:%lu: " @@ -1980,18 +2053,20 @@ load_text(dns_loadctx_t *lctx) } ISC_LIST_APPEND(this->rdata, &rdata[rdcount], link); - if (ictx->glue != NULL) + if (ictx->glue != NULL) { ictx->glue_line = line; - else + } else { ictx->current_line = line; + } rdcount++; /* * We must have at least 64k as rdlen is 16 bits. * If we don't commit everything we have so far. */ - if ((target.length - target.used) < MINTSIZ) + if ((target.length - target.used) < MINTSIZ) { COMMITALL; + } next_line:; } while (!done && (lctx->loop_cnt == 0 || loop_cnt++ < lctx->loop_cnt)); @@ -2002,22 +2077,25 @@ load_text(dns_loadctx_t *lctx) ictx->current_line); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } result = commit(callbacks, lctx, &glue_list, ictx->glue, source, ictx->glue_line); if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto insist_and_cleanup; + } if (!done) { INSIST(lctx->done != NULL && lctx->task != NULL); result = DNS_R_CONTINUE; } else if (result == ISC_R_SUCCESS && lctx->result != ISC_R_SUCCESS) { result = lctx->result; - } else if (result == ISC_R_SUCCESS && lctx->seen_include) + } else if (result == ISC_R_SUCCESS && lctx->seen_include) { result = DNS_R_SEENINCLUDE; + } goto cleanup; log_and_cleanup: @@ -2027,27 +2105,37 @@ insist_and_cleanup: INSIST(result != ISC_R_SUCCESS); cleanup: - while ((this = ISC_LIST_HEAD(current_list)) != NULL) + while ((this = ISC_LIST_HEAD(current_list)) != NULL) { ISC_LIST_UNLINK(current_list, this, link); - while ((this = ISC_LIST_HEAD(glue_list)) != NULL) + } + while ((this = ISC_LIST_HEAD(glue_list)) != NULL) { ISC_LIST_UNLINK(glue_list, this, link); - if (rdatalist != NULL) + } + if (rdatalist != NULL) { isc_mem_put(mctx, rdatalist, rdatalist_size * sizeof(*rdatalist)); - if (rdata != NULL) + } + if (rdata != NULL) { isc_mem_put(mctx, rdata, rdata_size * sizeof(*rdata)); - if (target_mem != NULL) + } + if (target_mem != NULL) { isc_mem_put(mctx, target_mem, target_size); - if (include_file != NULL) + } + if (include_file != NULL) { isc_mem_free(mctx, include_file); - if (range != NULL) + } + if (range != NULL) { isc_mem_free(mctx, range); - if (lhs != NULL) + } + if (lhs != NULL) { isc_mem_free(mctx, lhs); - if (gtype != NULL) + } + if (gtype != NULL) { isc_mem_free(mctx, gtype); - if (rhs != NULL) + } + if (rhs != NULL) { isc_mem_free(mctx, rhs); + } return (result); } @@ -2066,8 +2154,9 @@ pushfile(const char *master_file, dns_name_t *origin, dns_loadctx_t *lctx) lctx->seen_include = true; result = incctx_create(lctx->mctx, origin, &newctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Push origin_changed. @@ -2087,13 +2176,15 @@ pushfile(const char *master_file, dns_name_t *origin, dns_loadctx_t *lctx) } result = (lctx->openfile)(lctx, master_file); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } newctx->parent = ictx; lctx->inc = newctx; - if (lctx->include_cb != NULL) + if (lctx->include_cb != NULL) { lctx->include_cb(master_file, lctx->include_arg); + } return (ISC_R_SUCCESS); cleanup: @@ -2117,14 +2208,17 @@ read_and_check(bool do_read, isc_buffer_t *buffer, size_t len, FILE *f, INSIST(isc_buffer_availablelength(buffer) >= len); result = isc_stdio_read(isc_buffer_used(buffer), 1, len, f, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_add(buffer, (unsigned int)len); - if (*totallen < len) + if (*totallen < len) { return (ISC_R_RANGE); + } *totallen -= (uint32_t)len; - } else if (isc_buffer_remaininglength(buffer) < len) + } else if (isc_buffer_remaininglength(buffer) < len) { return (ISC_R_RANGE); + } return (ISC_R_SUCCESS); } @@ -2143,8 +2237,9 @@ load_header(dns_loadctx_t *lctx) REQUIRE(DNS_LCTX_VALID(lctx)); if (lctx->format != dns_masterformat_raw && - lctx->format != dns_masterformat_map) + lctx->format != dns_masterformat_map) { return (ISC_R_NOTIMPLEMENTED); + } callbacks = lctx->callbacks; dns_master_initrawheader(&header); @@ -2240,8 +2335,9 @@ load_map(dns_loadctx_t *lctx) if (lctx->first) { result = load_header(lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = (*callbacks->deserialize)( callbacks->deserialize_private, lctx->f, @@ -2291,8 +2387,9 @@ load_raw(dns_loadctx_t *lctx) if (lctx->first) { result = load_header(lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } ISC_LIST_INIT(head); @@ -2333,8 +2430,9 @@ load_raw(dns_loadctx_t *lctx) done = true; break; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_buffer_add(&target, sizeof(totallen)); totallen = isc_buffer_getuint32(&target); @@ -2375,8 +2473,9 @@ load_raw(dns_loadctx_t *lctx) readlen = totallen; } result = isc_stdio_read(target.base, 1, readlen, lctx->f, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_buffer_add(&target, (unsigned int)readlen); totallen -= (uint32_t)readlen; @@ -2400,8 +2499,9 @@ load_raw(dns_loadctx_t *lctx) /* Owner name: length followed by name */ result = read_and_check(sequential_read, &target, sizeof(namelen), lctx->f, &totallen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } namelen = isc_buffer_getuint16(&target); if (namelen > sizeof(namebuf)) { result = ISC_R_RANGE; @@ -2410,13 +2510,15 @@ load_raw(dns_loadctx_t *lctx) result = read_and_check(sequential_read, &target, namelen, lctx->f, &totallen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_buffer_setactive(&target, (unsigned int)namelen); result = dns_name_fromwire(name, &target, &dctx, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } if ((lctx->options & DNS_MASTER_CHECKTTL) != 0 && rdatalist.ttl > lctx->maxttl) { @@ -2464,8 +2566,9 @@ load_raw(dns_loadctx_t *lctx) &rdata[j], link); dns_rdata_reset(&rdata[j]); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* Rewind the buffer and continue */ isc_buffer_clear(&target); @@ -2479,15 +2582,17 @@ load_raw(dns_loadctx_t *lctx) result = read_and_check(sequential_read, &target, sizeof(rdlen), lctx->f, &totallen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } rdlen = isc_buffer_getuint16(&target); /* rdata */ result = read_and_check(sequential_read, &target, rdlen, lctx->f, &totallen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_buffer_setactive(&target, (unsigned int)rdlen); /* * It is safe to have the source active region and @@ -2500,8 +2605,9 @@ load_raw(dns_loadctx_t *lctx) result = dns_rdata_fromwire( &rdata[i], rdatalist.rdclass, rdatalist.type, &target, &dctx, 0, &buf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } ISC_LIST_APPEND(rdatalist.rdata, &rdata[i], link); } @@ -2525,24 +2631,29 @@ load_raw(dns_loadctx_t *lctx) dns_rdata_reset(&rdata[i]); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } if (!done) { INSIST(lctx->done != NULL && lctx->task != NULL); result = DNS_R_CONTINUE; - } else if (result == ISC_R_SUCCESS && lctx->result != ISC_R_SUCCESS) + } else if (result == ISC_R_SUCCESS && lctx->result != ISC_R_SUCCESS) { result = lctx->result; + } - if (result == ISC_R_SUCCESS && callbacks->rawdata != NULL) + if (result == ISC_R_SUCCESS && callbacks->rawdata != NULL) { (*callbacks->rawdata)(callbacks->zone, &lctx->header); + } cleanup: - if (rdata != NULL) + if (rdata != NULL) { isc_mem_put(mctx, rdata, rdata_size * sizeof(*rdata)); - if (target_mem != NULL) + } + if (target_mem != NULL) { isc_mem_put(mctx, target_mem, target_size); + } if (result != ISC_R_SUCCESS && result != DNS_R_CONTINUE) { (*callbacks->error)(callbacks, "dns_master_load: %s", dns_result_totext(result)); @@ -2566,14 +2677,16 @@ dns_master_loadfile(const char *master_file, dns_name_t *top, result = loadctx_create(format, mctx, options, resign, top, zclass, origin, callbacks, NULL, NULL, NULL, include_cb, include_arg, NULL, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } lctx->maxttl = maxttl; result = (lctx->openfile)(lctx, master_file); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = (lctx->load)(lctx); INSIST(result != DNS_R_CONTINUE); @@ -2602,14 +2715,16 @@ dns_master_loadfileinc(const char *master_file, dns_name_t *top, result = loadctx_create(format, mctx, options, resign, top, zclass, origin, callbacks, task, done, done_arg, include_cb, include_arg, NULL, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } lctx->maxttl = maxttl; result = (lctx->openfile)(lctx, master_file); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = task_send(lctx); if (result == ISC_R_SUCCESS) { @@ -2635,19 +2750,22 @@ dns_master_loadstream(FILE *stream, dns_name_t *top, dns_name_t *origin, result = loadctx_create(dns_masterformat_text, mctx, options, 0, top, zclass, origin, callbacks, NULL, NULL, NULL, NULL, NULL, NULL, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_lex_openstream(lctx->lex, stream); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = (lctx->load)(lctx); INSIST(result != DNS_R_CONTINUE); cleanup: - if (lctx != NULL) + if (lctx != NULL) { dns_loadctx_detach(&lctx); + } return (result); } @@ -2668,12 +2786,14 @@ dns_master_loadstreaminc(FILE *stream, dns_name_t *top, dns_name_t *origin, result = loadctx_create(dns_masterformat_text, mctx, options, 0, top, zclass, origin, callbacks, task, done, done_arg, NULL, NULL, NULL, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_lex_openstream(lctx->lex, stream); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = task_send(lctx); if (result == ISC_R_SUCCESS) { @@ -2682,8 +2802,9 @@ dns_master_loadstreaminc(FILE *stream, dns_name_t *top, dns_name_t *origin, } cleanup: - if (lctx != NULL) + if (lctx != NULL) { dns_loadctx_detach(&lctx); + } return (result); } @@ -2700,12 +2821,14 @@ dns_master_loadbuffer(isc_buffer_t *buffer, dns_name_t *top, dns_name_t *origin, result = loadctx_create(dns_masterformat_text, mctx, options, 0, top, zclass, origin, callbacks, NULL, NULL, NULL, NULL, NULL, NULL, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = isc_lex_openbuffer(lctx->lex, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = (lctx->load)(lctx); INSIST(result != DNS_R_CONTINUE); @@ -2732,12 +2855,14 @@ dns_master_loadbufferinc(isc_buffer_t *buffer, dns_name_t *top, result = loadctx_create(dns_masterformat_text, mctx, options, 0, top, zclass, origin, callbacks, task, done, done_arg, NULL, NULL, NULL, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = isc_lex_openbuffer(lctx->lex, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = task_send(lctx); if (result == ISC_R_SUCCESS) { @@ -2763,8 +2888,9 @@ dns_master_loadlexer(isc_lex_t *lex, dns_name_t *top, dns_name_t *origin, result = loadctx_create(dns_masterformat_text, mctx, options, 0, top, zclass, origin, callbacks, NULL, NULL, NULL, NULL, NULL, lex, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = (lctx->load)(lctx); INSIST(result != DNS_R_CONTINUE); @@ -2790,8 +2916,9 @@ dns_master_loadlexerinc(isc_lex_t *lex, dns_name_t *top, dns_name_t *origin, result = loadctx_create(dns_masterformat_text, mctx, options, 0, top, zclass, origin, callbacks, task, done, done_arg, NULL, NULL, lex, &lctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = task_send(lctx); if (result == ISC_R_SUCCESS) { @@ -2818,8 +2945,9 @@ grow_rdatalist(int new_len, dns_rdatalist_t *oldlist, int old_len, dns_rdatalist_t *this; newlist = isc_mem_get(mctx, new_len * sizeof(*newlist)); - if (newlist == NULL) + if (newlist == NULL) { return (NULL); + } ISC_LIST_INIT(save); while ((this = ISC_LIST_HEAD(*current)) != NULL) { @@ -2848,8 +2976,9 @@ grow_rdatalist(int new_len, dns_rdatalist_t *oldlist, int old_len, } INSIST(rdlcount == old_len); - if (oldlist != NULL) + if (oldlist != NULL) { isc_mem_put(mctx, oldlist, old_len * sizeof(*oldlist)); + } return (newlist); } @@ -2868,8 +2997,9 @@ grow_rdata(int new_len, dns_rdata_t *oldlist, int old_len, dns_rdata_t *rdata; newlist = isc_mem_get(mctx, new_len * sizeof(*newlist)); - if (newlist == NULL) + if (newlist == NULL) { return (NULL); + } memset(newlist, 0, new_len * sizeof(*newlist)); /* @@ -2912,8 +3042,9 @@ grow_rdata(int new_len, dns_rdata_t *oldlist, int old_len, this = ISC_LIST_NEXT(this, link); } INSIST(rdcount == old_len || rdcount == 0); - if (oldlist != NULL) + if (oldlist != NULL) { isc_mem_put(mctx, oldlist, old_len * sizeof(*oldlist)); + } return (newlist); } @@ -2927,18 +3058,20 @@ resign_fromlist(dns_rdatalist_t *this, dns_loadctx_t *lctx) rdata = ISC_LIST_HEAD(this->rdata); INSIST(rdata != NULL); (void)dns_rdata_tostruct(rdata, &sig, NULL); - if (isc_serial_gt(sig.timesigned, lctx->now)) + if (isc_serial_gt(sig.timesigned, lctx->now)) { when = lctx->now; - else + } else { when = sig.timeexpire - lctx->resign; + } rdata = ISC_LIST_NEXT(rdata, link); while (rdata != NULL) { (void)dns_rdata_tostruct(rdata, &sig, NULL); - if (isc_serial_gt(sig.timesigned, lctx->now)) + if (isc_serial_gt(sig.timesigned, lctx->now)) { when = lctx->now; - else if (sig.timeexpire - lctx->resign < when) + } else if (sig.timeexpire - lctx->resign < when) { when = sig.timeexpire - lctx->resign; + } rdata = ISC_LIST_NEXT(rdata, link); } return (when); @@ -2963,8 +3096,9 @@ commit(dns_rdatacallbacks_t *callbacks, dns_loadctx_t *lctx, this = ISC_LIST_HEAD(*head); error = callbacks->error; - if (this == NULL) + if (this == NULL) { return (ISC_R_SUCCESS); + } do { dns_rdataset_init(&dataset); RUNTIME_CHECK(dns_rdatalist_tordataset(this, &dataset) == @@ -2995,10 +3129,11 @@ commit(dns_rdatacallbacks_t *callbacks, dns_loadctx_t *lctx, dns_result_totext(result)); } } - if (MANYERRS(lctx, result)) + if (MANYERRS(lctx, result)) { SETRESULT(lctx, result); - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { return (result); + } ISC_LIST_UNLINK(*head, this, link); this = ISC_LIST_HEAD(*head); } while (this != NULL); @@ -3022,12 +3157,14 @@ is_glue(rdatalist_head_t *head, dns_name_t *owner) */ this = ISC_LIST_HEAD(*head); while (this != NULL) { - if (this->type == dns_rdatatype_ns) + if (this->type == dns_rdatatype_ns) { break; + } this = ISC_LIST_NEXT(this, link); } - if (this == NULL) + if (this == NULL) { return (false); + } rdata = ISC_LIST_HEAD(this->rdata); while (rdata != NULL) { diff --git a/lib/dns/masterdump.c b/lib/dns/masterdump.c index a7ca871f7a..2462d3fb01 100644 --- a/lib/dns/masterdump.c +++ b/lib/dns/masterdump.c @@ -55,7 +55,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) #define CHECK(x) \ @@ -281,24 +281,28 @@ indent(unsigned int *current, unsigned int to, int tabwidth, from = *current; - if (to < from + 1) + if (to < from + 1) { to = from + 1; + } ntabs = to / tabwidth - from / tabwidth; - if (ntabs < 0) + if (ntabs < 0) { ntabs = 0; + } if (ntabs > 0) { isc_buffer_availableregion(target, &r); - if (r.length < (unsigned)ntabs) + if (r.length < (unsigned)ntabs) { return (ISC_R_NOSPACE); + } p = r.base; t = ntabs; while (t) { int n = t; - if (n > N_TABS) + if (n > N_TABS) { n = N_TABS; + } memmove(p, tabs, n); p += n; t -= n; @@ -311,15 +315,17 @@ indent(unsigned int *current, unsigned int to, int tabwidth, INSIST(nspaces >= 0); isc_buffer_availableregion(target, &r); - if (r.length < (unsigned)nspaces) + if (r.length < (unsigned)nspaces) { return (ISC_R_NOSPACE); + } p = r.base; t = nspaces; while (t) { int n = t; - if (n > N_SPACES) + if (n > N_SPACES) { n = N_SPACES; + } memmove(p, spaces, n); p += n; t -= n; @@ -363,8 +369,9 @@ totext_ctx_init(const dns_master_style_t *style, const dns_indent_t *indentctx, sizeof(ctx->linebreak_buf)); isc_buffer_availableregion(&buf, &r); - if (r.length < 1) + if (r.length < 1) { return (DNS_R_TEXTTOOLONG); + } r.base[0] = '\n'; isc_buffer_add(&buf, 1); @@ -372,16 +379,18 @@ totext_ctx_init(const dns_master_style_t *style, const dns_indent_t *indentctx, (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) { unsigned int i, len = strlen(indentctx->string); for (i = 0; i < indentctx->count; i++) { - if (isc_buffer_availablelength(&buf) < len) + if (isc_buffer_availablelength(&buf) < len) { return (DNS_R_TEXTTOOLONG); + } isc_buffer_putstr(&buf, indentctx->string); } } if ((ctx->style.flags & DNS_STYLEFLAG_COMMENTDATA) != 0) { isc_buffer_availableregion(&buf, &r); - if (r.length < 1) + if (r.length < 1) { return (DNS_R_TEXTTOOLONG); + } r.base[0] = ';'; isc_buffer_add(&buf, 1); } @@ -395,14 +404,17 @@ totext_ctx_init(const dns_master_style_t *style, const dns_indent_t *indentctx, * bigger target buffers. That's a different buffer, * so it won't help. Use DNS_R_TEXTTOOLONG as a substitute. */ - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { return (DNS_R_TEXTTOOLONG); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_availableregion(&buf, &r); - if (r.length < 1) + if (r.length < 1) { return (DNS_R_TEXTTOOLONG); + } r.base[0] = '\0'; isc_buffer_add(&buf, 1); ctx->linebreak = ctx->linebreak_buf; @@ -425,11 +437,11 @@ totext_ctx_init(const dns_master_style_t *style, const dns_indent_t *indentctx, if ((ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) { \ if ((result = str_totext(" ", target)) != \ ISC_R_SUCCESS) \ - return (result); \ + return ((result)); \ } else if ((result = indent(&column, ctx->style.col, \ ctx->style.tab_width, target)) != \ ISC_R_SUCCESS) \ - return (result); \ + return ((result)); \ } while (0) static isc_result_t @@ -441,8 +453,9 @@ str_totext(const char *source, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(source); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, source, l); isc_buffer_add(target, l); @@ -500,11 +513,13 @@ ncache_summary(dns_rdataset_t *rdataset, bool omit_final_dot, result = dns_rdataset_next(rdataset); } while (result == ISC_R_SUCCESS); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: - if (dns_rdataset_isassociated(&rds)) + if (dns_rdataset_isassociated(&rds)) { dns_rdataset_disassociate(&rds); + } return (result); } @@ -554,8 +569,9 @@ rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, */ if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 || (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) { - for (i = 0; i < ctx->indent.count; i++) + for (i = 0; i < ctx->indent.count; i++) { RETERR(str_totext(ctx->indent.string, target)); + } } /* @@ -594,16 +610,18 @@ rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, length = target->used; result = dns_ttl_totext(rdataset->ttl, false, false, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } column += target->used - length; } else { length = snprintf(ttlbuf, sizeof(ttlbuf), "%u", rdataset->ttl); INSIST(length <= sizeof(ttlbuf)); isc_buffer_availableregion(target, &r); - if (r.length < length) + if (r.length < length) { return (ISC_R_NOSPACE); + } memmove(r.base, ttlbuf, length); isc_buffer_add(target, length); column += length; @@ -629,14 +647,16 @@ rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, INDENT_TO(class_column); class_start = target->used; if ((ctx->style.flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != - 0) + 0) { result = dns_rdataclass_tounknowntext( rdataset->rdclass, target); - else + } else { result = dns_rdataclass_totext( rdataset->rdclass, target); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } column += (target->used - class_start); } @@ -652,28 +672,32 @@ rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, INDENT_TO(type_column); type_start = target->used; - if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) + if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) { RETERR(str_totext("\\-", target)); + } switch (type) { case dns_rdatatype_keydata: #define KEYDATA "KEYDATA" if ((ctx->style.flags & DNS_STYLEFLAG_KEYDATA) != 0) { if (isc_buffer_availablelength(target) < - (sizeof(KEYDATA) - 1)) + (sizeof(KEYDATA) - 1)) { return (ISC_R_NOSPACE); + } isc_buffer_putstr(target, KEYDATA); break; } - /* FALLTHROUGH */ + /* FALLTHROUGH */ default: if ((ctx->style.flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != - 0) + 0) { result = dns_rdatatype_tounknowntext(type, target); - else + } else { result = dns_rdatatype_totext(type, target); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } } column += (target->used - type_start); @@ -708,8 +732,9 @@ rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, target)); isc_buffer_availableregion(target, &r); - if (r.length < 1) + if (r.length < 1) { return (ISC_R_NOSPACE); + } r.base[0] = '\n'; isc_buffer_add(target, 1); } @@ -718,8 +743,9 @@ rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, result = dns_rdataset_next(rdataset); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } /* * Update the ctx state to reflect what we just printed. @@ -767,14 +793,16 @@ question_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, unsigned int class_start; INDENT_TO(class_column); class_start = target->used; - if ((ctx->style.flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0) + if ((ctx->style.flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0) { result = dns_rdataclass_tounknowntext(rdataset->rdclass, target); - else + } else { result = dns_rdataclass_totext(rdataset->rdclass, target); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } column += (target->used - class_start); } @@ -783,19 +811,22 @@ question_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, unsigned int type_start; INDENT_TO(type_column); type_start = target->used; - if ((ctx->style.flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0) + if ((ctx->style.flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0) { result = dns_rdatatype_tounknowntext(rdataset->type, target); - else + } else { result = dns_rdatatype_totext(rdataset->type, target); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } column += (target->used - type_start); } isc_buffer_availableregion(target, &r); - if (r.length < 1) + if (r.length < 1) { return (ISC_R_NOSPACE); + } r.base[0] = '\n'; isc_buffer_add(target, 1); @@ -821,15 +852,17 @@ dns_rdataset_totext(dns_rdataset_t *rdataset, const dns_name_t *owner_name, * file and this rdataset has the same name as the * previous one.) */ - if (dns_name_countlabels(owner_name) == 0) + if (dns_name_countlabels(owner_name) == 0) { owner_name = NULL; + } - if (question) + if (question) { return (question_totext(rdataset, owner_name, &ctx, omit_final_dot, target)); - else + } else { return (rdataset_totext(rdataset, owner_name, &ctx, omit_final_dot, target)); + } } isc_result_t @@ -916,16 +949,18 @@ dump_rdataset(isc_mem_t *mctx, const dns_name_t *name, dns_rdataset_t *rdataset, int newlength; void *newmem; result = rdataset_totext(rdataset, name, ctx, false, buffer); - if (result != ISC_R_NOSPACE) + if (result != ISC_R_NOSPACE) { break; + } newlength = buffer->length * 2; newmem = isc_mem_get(mctx, newlength); isc_mem_put(mctx, buffer->base, buffer->length); isc_buffer_init(buffer, newmem, newlength); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Write the buffer contents to the master file. @@ -975,7 +1010,7 @@ dump_order(const dns_rdataset_t *rds) t += 2; break; } - return (t << 1) + sig; + return ((t << 1) + sig); } static int @@ -1038,8 +1073,9 @@ again: if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 || (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) { unsigned int j; - for (j = 0; j < ctx->indent.count; j++) + for (j = 0; j < ctx->indent.count; j++) { fprintf(f, "%s", ctx->indent.string); + } } fprintf(f, "; %s\n", dns_trust_totext(rds->trust)); } @@ -1056,10 +1092,13 @@ again: ctx->serve_stale_ttl)); } result = dump_rdataset(mctx, name, rds, ctx, buffer, f); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dumpresult = result; - if ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != 0) + } + if ((ctx->style.flags & DNS_STYLEFLAG_OMIT_OWNER) != + 0) { name = NULL; + } } if (((ctx->style.flags & DNS_STYLEFLAG_RESIGN) != 0) && ((rds->attributes & DNS_RDATASETATTR_RESIGN) != 0)) { @@ -1071,26 +1110,30 @@ again: if ((ctx->style.flags & DNS_STYLEFLAG_INDENT) != 0 || (ctx->style.flags & DNS_STYLEFLAG_YAML) != 0) { unsigned int j; - for (j = 0; j < ctx->indent.count; j++) + for (j = 0; j < ctx->indent.count; j++) { fprintf(f, "%s", ctx->indent.string); + } } fprintf(f, "; resign=%s\n", buf); } dns_rdataset_disassociate(rds); } - if (dumpresult != ISC_R_SUCCESS) + if (dumpresult != ISC_R_SUCCESS) { return (dumpresult); + } /* * If we got more data than could be sorted at once, * go handle the rest. */ - if (itresult == ISC_R_SUCCESS) + if (itresult == ISC_R_SUCCESS) { goto again; + } - if (itresult == ISC_R_NOMORE) + if (itresult == ISC_R_NOMORE) { itresult = ISC_R_SUCCESS; + } return (itresult); } @@ -1173,8 +1216,9 @@ restart: result = dns_rdataset_next(rdataset); } while (result == ISC_R_SUCCESS); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } /* * Fill in the total length field. @@ -1229,12 +1273,14 @@ dump_rdatasets_raw(isc_mem_t *mctx, const dns_name_t *owner_name, buffer, f); } dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } return (result); } @@ -1275,15 +1321,19 @@ dumpctx_destroy(dns_dumpctx_t *dctx) dctx->magic = 0; isc_mutex_destroy(&dctx->lock); dns_dbiterator_destroy(&dctx->dbiter); - if (dctx->version != NULL) + if (dctx->version != NULL) { dns_db_closeversion(dctx->db, &dctx->version, false); + } dns_db_detach(&dctx->db); - if (dctx->task != NULL) + if (dctx->task != NULL) { isc_task_detach(&dctx->task); - if (dctx->file != NULL) + } + if (dctx->file != NULL) { isc_mem_free(dctx->mctx, dctx->file); - if (dctx->tmpfile != NULL) + } + if (dctx->tmpfile != NULL) { isc_mem_free(dctx->mctx, dctx->tmpfile); + } isc_mem_putanddetach(&dctx->mctx, dctx, sizeof(*dctx)); } @@ -1340,35 +1390,39 @@ flushandsync(FILE *f, isc_result_t result, const char *temp) { bool logit = (result == ISC_R_SUCCESS); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_stdio_flush(f); + } if (result != ISC_R_SUCCESS && logit) { - if (temp != NULL) + if (temp != NULL) { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, "dumping to master file: %s: flush: %s", temp, isc_result_totext(result)); - else + } else { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, "dumping to stream: flush: %s", isc_result_totext(result)); + } logit = false; } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_stdio_sync(f); + } if (result != ISC_R_SUCCESS && logit) { - if (temp != NULL) + if (temp != NULL) { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, "dumping to master file: %s: fsync: %s", temp, isc_result_totext(result)); - else + } else { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, "dumping to stream: fsync: %s", isc_result_totext(result)); + } } return (result); } @@ -1380,12 +1434,14 @@ closeandrename(FILE *f, isc_result_t result, const char *temp, const char *file) bool logit = (result == ISC_R_SUCCESS); result = flushandsync(f, result, temp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { logit = false; + } tresult = isc_stdio_close(f); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = tresult; + } if (result != ISC_R_SUCCESS && logit) { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, @@ -1393,10 +1449,11 @@ closeandrename(FILE *f, isc_result_t result, const char *temp, const char *file) isc_result_totext(result)); logit = false; } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_file_rename(temp, file); - else + } else { (void)isc_file_remove(temp); + } if (result != ISC_R_SUCCESS && logit) { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, @@ -1430,10 +1487,12 @@ dump_quantum(isc_task_t *task, isc_event_t *event) if (dctx->file != NULL) { tresult = closeandrename(dctx->f, result, dctx->tmpfile, dctx->file); - if (tresult != ISC_R_SUCCESS && result == ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS && result == ISC_R_SUCCESS) { result = tresult; - } else + } + } else { result = flushandsync(dctx->f, result, NULL); + } (dctx->done)(dctx->done_arg, result); isc_event_free(&event); dns_dumpctx_detach(&dctx); @@ -1475,10 +1534,11 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, dctx->file = NULL; dctx->tmpfile = NULL; dctx->format = format; - if (header == NULL) + if (header == NULL) { dns_master_initrawheader(&dctx->header); - else + } else { dctx->header = *header; + } switch (format) { case dns_masterformat_text: @@ -1520,18 +1580,21 @@ dumpctx_create(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, if (dctx->format == dns_masterformat_text && (dctx->tctx.style.flags & DNS_STYLEFLAG_REL_OWNER) != 0) { options = DNS_DB_RELATIVENAMES; - } else + } else { options = 0; + } result = dns_db_createiterator(dctx->db, options, &dctx->dbiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_mutex_init(&dctx->lock); - if (version != NULL) + if (version != NULL) { dns_db_attachversion(dctx->db, version, &dctx->version); - else if (!dns_db_iscache(db)) + } else if (!dns_db_iscache(db)) { dns_db_currentversion(dctx->db, &dctx->version); + } isc_mem_attach(mctx, &dctx->mctx); isc_refcount_init(&dctx->references, 1); @@ -1591,8 +1654,9 @@ writeheader(dns_dumpctx_t *dctx) isc_buffer_region(&buffer, &r); now32 = dctx->now; rawversion = 1; - if ((dctx->header.flags & DNS_MASTERRAW_COMPAT) != 0) + if ((dctx->header.flags & DNS_MASTERRAW_COMPAT) != 0) { rawversion = 0; + } isc_buffer_putuint32(&buffer, dctx->format); isc_buffer_putuint32(&buffer, rawversion); @@ -1609,8 +1673,9 @@ writeheader(dns_dumpctx_t *dctx) result = isc_stdio_write(buffer.base, 1, isc_buffer_usedlength(&buffer), dctx->f, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } break; default: @@ -1655,12 +1720,14 @@ dumptostreaminc(dns_dumpctx_t *dctx) } result = dns_dbiterator_first(dctx->dbiter); - if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) + if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) { goto cleanup; + } dctx->first = false; - } else + } else { result = ISC_R_SUCCESS; + } nodes = dctx->nodes; isc_time_now(&start); @@ -1669,16 +1736,18 @@ dumptostreaminc(dns_dumpctx_t *dctx) dns_dbnode_t * node = NULL; result = dns_dbiterator_current(dctx->dbiter, &node, name); - if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) + if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { break; + } if (result == DNS_R_NEWORIGIN) { dns_name_t *origin = dns_fixedname_name(&dctx->tctx.origin_fixname); result = dns_dbiterator_origin(dctx->dbiter, origin); RUNTIME_CHECK(result == ISC_R_SUCCESS); if ((dctx->tctx.style.flags & DNS_STYLEFLAG_REL_DATA) != - 0) + 0) { dctx->tctx.origin = origin; + } dctx->tctx.neworigin = origin; } result = dns_db_allrdatasets(dctx->db, node, dctx->version, @@ -1711,23 +1780,27 @@ dumptostreaminc(dns_dumpctx_t *dctx) isc_time_t end; isc_time_now(&end); - if (pps < 100) + if (pps < 100) { pps = 100; + } interval = 1000000 / pps; /* interval in usecs */ - if (interval == 0) + if (interval == 0) { interval = 1; + } usecs = isc_time_microdiff(&end, &start); if (usecs == 0) { dctx->nodes = dctx->nodes * 2; - if (dctx->nodes > 1000) + if (dctx->nodes > 1000) { dctx->nodes = 1000; + } } else { nodes = dctx->nodes * interval; nodes /= (unsigned int)usecs; - if (nodes == 0) + if (nodes == 0) { nodes = 1; - else if (nodes > 1000) + } else if (nodes > 1000) { nodes = 1000; + } /* Smooth and assign. */ dctx->nodes = (nodes + dctx->nodes * 7) / 8; @@ -1739,8 +1812,9 @@ dumptostreaminc(dns_dumpctx_t *dctx) dctx, dctx->nodes); } result = DNS_R_CONTINUE; - } else if (result == ISC_R_NOMORE) + } else if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: RUNTIME_CHECK(dns_dbiterator_pause(dctx->dbiter) == ISC_R_SUCCESS); isc_mem_put(dctx->mctx, buffer.base, buffer.length); @@ -1763,8 +1837,9 @@ dns_master_dumptostreaminc(isc_mem_t *mctx, dns_db_t *db, result = dumpctx_create(mctx, db, version, style, f, &dctx, dns_masterformat_text, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_task_attach(task, &dctx->task); dctx->done = done; dctx->done_arg = done_arg; @@ -1791,8 +1866,9 @@ dns_master_dumptostream(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, result = dumpctx_create(mctx, db, version, style, f, &dctx, format, header); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dumptostreaminc(dctx); INSIST(result != DNS_R_CONTINUE); @@ -1815,13 +1891,15 @@ opentmp(isc_mem_t *mctx, dns_masterformat_t format, const char *file, tempname = isc_mem_allocate(mctx, tempnamelen); result = isc_file_mktemplate(file, tempname, tempnamelen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } - if (format == dns_masterformat_text) + if (format == dns_masterformat_text) { result = isc_file_openunique(tempname, &f); - else + } else { result = isc_file_bopenunique(tempname, &f); + } if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, ISC_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTERDUMP, ISC_LOG_ERROR, @@ -1854,8 +1932,9 @@ dns_master_dumpinc(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, file = isc_mem_strdup(mctx, filename); result = opentmp(mctx, format, filename, &tempname, &f); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dumpctx_create(mctx, db, version, style, f, &dctx, format, header); @@ -1881,12 +1960,15 @@ dns_master_dumpinc(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, } cleanup: - if (dctx != NULL) + if (dctx != NULL) { dns_dumpctx_detach(&dctx); - if (file != NULL) + } + if (file != NULL) { isc_mem_free(mctx, file); - if (tempname != NULL) + } + if (tempname != NULL) { isc_mem_free(mctx, tempname); + } return (result); } @@ -1901,13 +1983,15 @@ dns_master_dump(isc_mem_t *mctx, dns_db_t *db, dns_dbversion_t *version, dns_dumpctx_t *dctx = NULL; result = opentmp(mctx, format, filename, &tempname, &f); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dumpctx_create(mctx, db, version, style, f, &dctx, format, header); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dumptostreaminc(dctx); INSIST(result != DNS_R_CONTINUE); @@ -1951,11 +2035,13 @@ dns_master_dumpnodetostream(isc_mem_t *mctx, dns_db_t *db, isc_buffer_init(&buffer, bufmem, initial_buffer_length); result = dns_db_allrdatasets(db, node, version, now, &rdsiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } result = dump_rdatasets_text(mctx, name, rdsiter, &ctx, &buffer, f); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } dns_rdatasetiter_destroy(&rdsiter); result = ISC_R_SUCCESS; diff --git a/lib/dns/message.c b/lib/dns/message.c index ae706b8a14..5217e207d2 100644 --- a/lib/dns/message.c +++ b/lib/dns/message.c @@ -54,22 +54,25 @@ hexdump(const char *msg, const char *msg2, void *base, size_t len) printf("*** %s [%s] (%u bytes @ %p)\n", msg, msg2, (unsigned)len, base); while (cnt < len) { - if (cnt % 16 == 0) + if (cnt % 16 == 0) { printf("%p: ", p); - else if (cnt % 8 == 0) + } else if (cnt % 8 == 0) { printf(" |"); + } printf(" %02x %c", *p, (isprint(*p) ? *p : ' ')); p++; cnt++; - if (cnt % 16 == 0) + if (cnt % 16 == 0) { printf("\n"); + } } - if (cnt % 16 != 0) + if (cnt % 16 != 0) { printf("\n"); + } } -#endif +#endif /* ifdef SKAN_MSG_DEBUG */ #define DNS_MESSAGE_OPCODE_MASK 0x7800U #define DNS_MESSAGE_OPCODE_SHIFT 11 @@ -188,8 +191,9 @@ msgblock_internalget(dns_msgblock_t *block, unsigned int sizeof_type) { void *ptr; - if (block == NULL || block->remaining == 0) + if (block == NULL || block->remaining == 0) { return (NULL); + } block->remaining--; @@ -269,8 +273,9 @@ newrdata(dns_message_t *msg) if (rdata == NULL) { msgblock = msgblock_allocate(msg->mctx, sizeof(dns_rdata_t), RDATA_COUNT); - if (msgblock == NULL) + if (msgblock == NULL) { return (NULL); + } ISC_LIST_APPEND(msg->rdatas, msgblock, link); @@ -304,16 +309,18 @@ newrdatalist(dns_message_t *msg) if (rdatalist == NULL) { msgblock = msgblock_allocate(msg->mctx, sizeof(dns_rdatalist_t), RDATALIST_COUNT); - if (msgblock == NULL) + if (msgblock == NULL) { return (NULL); + } ISC_LIST_APPEND(msg->rdatalists, msgblock, link); rdatalist = msgblock_get(msgblock, dns_rdatalist_t); } out: - if (rdatalist != NULL) + if (rdatalist != NULL) { dns_rdatalist_init(rdatalist); + } return (rdatalist); } @@ -329,8 +336,9 @@ newoffsets(dns_message_t *msg) if (offsets == NULL) { msgblock = msgblock_allocate(msg->mctx, sizeof(dns_offsets_t), OFFSET_COUNT); - if (msgblock == NULL) + if (msgblock == NULL) { return (NULL); + } ISC_LIST_APPEND(msg->offsets, msgblock, link); @@ -446,8 +454,9 @@ msgresetnames(dns_message_t *msg, unsigned int first_section) isc_mempool_put(msg->rdspool, rds); rds = next_rds; } - if (dns_name_dynamic(name)) + if (dns_name_dynamic(name)) { dns_name_free(name, msg->mctx); + } isc_mempool_put(msg->namepool, name); name = next_name; } @@ -492,8 +501,9 @@ msgresetsigs(dns_message_t *msg, bool replying) isc_mempool_put(msg->rdspool, msg->querytsig); } } - if (dns_name_dynamic(msg->tsigname)) + if (dns_name_dynamic(msg->tsigname)) { dns_name_free(msg->tsigname, msg->mctx); + } isc_mempool_put(msg->namepool, msg->tsigname); msg->tsig = NULL; msg->tsigname = NULL; @@ -507,8 +517,9 @@ msgresetsigs(dns_message_t *msg, bool replying) dns_rdataset_disassociate(msg->sig0); isc_mempool_put(msg->rdspool, msg->sig0); if (msg->sig0name != NULL) { - if (dns_name_dynamic(msg->sig0name)) + if (dns_name_dynamic(msg->sig0name)) { dns_name_free(msg->sig0name, msg->mctx); + } isc_mempool_put(msg->namepool, msg->sig0name); } msg->sig0 = NULL; @@ -610,21 +621,24 @@ msgreset(dns_message_t *msg, bool everything) msg->tsigkey = NULL; } - if (msg->tsigctx != NULL) + if (msg->tsigctx != NULL) { dst_context_destroy(&msg->tsigctx); + } if (msg->query.base != NULL) { - if (msg->free_query != 0) + if (msg->free_query != 0) { isc_mem_put(msg->mctx, msg->query.base, msg->query.length); + } msg->query.base = NULL; msg->query.length = 0; } if (msg->saved.base != NULL) { - if (msg->free_saved != 0) + if (msg->free_saved != 0) { isc_mem_put(msg->mctx, msg->saved.base, msg->saved.length); + } msg->saved.base = NULL; msg->saved.length = 0; } @@ -643,8 +657,9 @@ msgreset(dns_message_t *msg, bool everything) /* * Set other bits to normal default values. */ - if (!everything) + if (!everything) { msginit(msg); + } ENSURE(isc_mempool_getallocated(msg->namepool) == 0); ENSURE(isc_mempool_getallocated(msg->rdspool) == 0); @@ -680,12 +695,13 @@ spacefortsig(dns_tsigkey_t *key, int otherlen) dns_name_toregion(&key->name, &r1); dns_name_toregion(key->algorithm, &r2); - if (key->key == NULL) + if (key->key == NULL) { x = 0; - else { + } else { result = dst_key_sigsize(key->key, &x); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { x = 0; + } } return (26 + r1.length + r2.length + x + otherlen); } @@ -714,8 +730,9 @@ dns_message_create(isc_mem_t *mctx, unsigned int intent, dns_message_t **msgp) m->from_to_wire = intent; msginit(m); - for (i = 0; i < DNS_SECTION_MAX; i++) + for (i = 0; i < DNS_SECTION_MAX; i++) { ISC_LIST_INIT(m->sections[i]); + } m->mctx = NULL; isc_mem_attach(mctx, &m->mctx); @@ -792,8 +809,9 @@ findname(dns_name_t **foundname, const dns_name_t *target, for (curr = ISC_LIST_TAIL(*section); curr != NULL; curr = ISC_LIST_PREV(curr, link)) { if (dns_name_equal(curr, target)) { - if (foundname != NULL) + if (foundname != NULL) { *foundname = curr; + } return (ISC_R_SUCCESS); } } @@ -815,8 +833,9 @@ dns_message_find(const dns_name_t *name, dns_rdataclass_t rdclass, curr = ISC_LIST_PREV(curr, link)) { if (curr->rdclass == rdclass && curr->type == type && curr->covers == covers) { - if (rdataset != NULL) + if (rdataset != NULL) { *rdataset = curr; + } return (ISC_R_SUCCESS); } } @@ -836,8 +855,9 @@ dns_message_findtype(const dns_name_t *name, dns_rdatatype_t type, for (curr = ISC_LIST_TAIL(name->list); curr != NULL; curr = ISC_LIST_PREV(curr, link)) { if (curr->type == type && curr->covers == covers) { - if (ISC_UNLIKELY(rdataset != NULL)) + if (ISC_UNLIKELY(rdataset != NULL)) { *rdataset = curr; + } return (ISC_R_SUCCESS); } } @@ -870,8 +890,9 @@ getname(dns_name_t *name, isc_buffer_t *source, dns_message_t *msg, tries++; result = newbuffer(msg, SCRATCHPAD_SIZE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } scratch = currentbuffer(msg); dns_name_reset(name); @@ -915,19 +936,22 @@ getrdata(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, if (result == ISC_R_NOSPACE) { if (tries == 0) { trysize = 2 * rdatalen; - if (trysize < SCRATCHPAD_SIZE) + if (trysize < SCRATCHPAD_SIZE) { trysize = SCRATCHPAD_SIZE; + } } else { INSIST(trysize != 0); - if (trysize >= 65535) + if (trysize >= 65535) { return (ISC_R_NOSPACE); + } /* XXX DNS_R_RRTOOLONG? */ trysize *= 2; } tries++; result = newbuffer(msg, trysize); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } scratch = currentbuffer(msg); } else { @@ -976,8 +1000,9 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, for (count = 0; count < msg->counts[DNS_SECTION_QUESTION]; count++) { name = isc_mempool_get(msg->namepool); - if (name == NULL) + if (name == NULL) { return (ISC_R_NOMEMORY); + } free_name = true; offsets = newoffsets(msg); @@ -993,8 +1018,9 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, isc_buffer_remainingregion(source, &r); isc_buffer_setactive(source, r.length); result = getname(name, source, msg, dctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Run through the section, looking to see if this name @@ -1015,8 +1041,9 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, * need this name pointer. */ if (result != ISC_R_SUCCESS) { - if (!ISC_LIST_EMPTY(*section)) + if (!ISC_LIST_EMPTY(*section)) { DO_ERROR(DNS_R_FORMERR); + } ISC_LIST_APPEND(*section, name, link); free_name = false; } else { @@ -1044,21 +1071,24 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, if (msg->rdclass_set == 0) { msg->rdclass = rdclass; msg->rdclass_set = 1; - } else if (msg->rdclass != rdclass) + } else if (msg->rdclass != rdclass) { DO_ERROR(DNS_R_FORMERR); + } /* * Is this a TKEY query? */ - if (rdtype == dns_rdatatype_tkey) + if (rdtype == dns_rdatatype_tkey) { msg->tkey = 1; + } /* * Can't ask the same question twice. */ result = dns_message_find(name, rdclass, rdtype, 0, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { DO_ERROR(DNS_R_FORMERR); + } /* * Allocate a new rdatalist. @@ -1083,8 +1113,9 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, dns_rdataset_init(rdataset); result = dns_rdatalist_tordataset(rdatalist, rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } rdataset->attributes |= DNS_RDATASETATTR_QUESTION; @@ -1092,8 +1123,9 @@ getquestions(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, rdataset = NULL; } - if (seen_problem) + if (seen_problem) { return (DNS_R_RECOVERABLE); + } return (ISC_R_SUCCESS); cleanup: @@ -1102,11 +1134,13 @@ cleanup: isc_mempool_put(msg->rdspool, rdataset); } #if 0 - if (rdatalist != NULL) + if (rdatalist != NULL) { isc_mempool_put(msg->rdlpool, rdatalist); -#endif - if (free_name) + } +#endif /* if 0 */ + if (free_name) { isc_mempool_put(msg->namepool, name); + } return (result); } @@ -1114,11 +1148,13 @@ cleanup: static bool update(dns_section_t section, dns_rdataclass_t rdclass) { - if (section == DNS_SECTION_PREREQUISITE) + if (section == DNS_SECTION_PREREQUISITE) { return (rdclass == dns_rdataclass_any || rdclass == dns_rdataclass_none); - if (section == DNS_SECTION_UPDATE) + } + if (section == DNS_SECTION_UPDATE) { return (rdclass == dns_rdataclass_any); + } return (false); } @@ -1169,8 +1205,9 @@ auth_signed(dns_namelist_t *section) } } - if (auth_dnssec != auth_rrsig) + if (auth_dnssec != auth_rrsig) { return (false); + } } return (true); @@ -1215,8 +1252,9 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, istsig = false; name = isc_mempool_get(msg->namepool); - if (name == NULL) + if (name == NULL) { return (ISC_R_NOMEMORY); + } free_name = true; offsets = newoffsets(msg); @@ -1232,8 +1270,9 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, isc_buffer_remainingregion(source, &r); isc_buffer_setactive(source, r.length); result = getname(name, source, msg, dctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Get type, class, ttl, and rdatalen. Verify that at least @@ -1267,12 +1306,13 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, if (msg->opcode != dns_opcode_update && rdtype != dns_rdatatype_tsig && rdtype != dns_rdatatype_opt && - rdtype != dns_rdatatype_key /* in a TKEY query */ - && rdtype != dns_rdatatype_sig /* SIG(0) */ - && rdtype != dns_rdatatype_tkey /* Win2000 TKEY */ - && msg->rdclass != dns_rdataclass_any && - msg->rdclass != rdclass) + rdtype != dns_rdatatype_key && /* in a TKEY query */ + rdtype != dns_rdatatype_sig && /* SIG(0) */ + rdtype != dns_rdatatype_tkey && /* Win2000 TKEY */ + msg->rdclass != dns_rdataclass_any && + msg->rdclass != rdclass) { DO_ERROR(DNS_R_FORMERR); + } /* * If this is not a TKEY query/response then the KEY @@ -1281,8 +1321,9 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, if (msg->opcode != dns_opcode_update && !msg->tkey && rdtype == dns_rdatatype_key && msg->rdclass != dns_rdataclass_any && - msg->rdclass != rdclass) + msg->rdclass != rdclass) { DO_ERROR(DNS_R_FORMERR); + } /* * Special type handling for TSIG, OPT, and TKEY. @@ -1326,13 +1367,15 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, */ dns_section_t tkeysection; - if ((msg->flags & DNS_MESSAGEFLAG_QR) == 0) + if ((msg->flags & DNS_MESSAGEFLAG_QR) == 0) { tkeysection = DNS_SECTION_ADDITIONAL; - else + } else { tkeysection = DNS_SECTION_ANSWER; + } if (sectionid != tkeysection && - sectionid != DNS_SECTION_ANSWER) + sectionid != DNS_SECTION_ANSWER) { DO_ERROR(DNS_R_FORMERR); + } } /* @@ -1381,16 +1424,19 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, sectionid == DNS_SECTION_UPDATE) { result = getrdata(source, msg, dctx, msg->rdclass, rdtype, rdatalen, rdata); - } else + } else { result = getrdata(source, msg, dctx, rdclass, rdtype, rdatalen, rdata); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto cleanup; + } rdata->rdclass = rdclass; if (rdtype == dns_rdatatype_rrsig && rdata->flags == 0) { covers = dns_rdata_covers(rdata); - if (covers == 0) + if (covers == 0) { DO_ERROR(DNS_R_FORMERR); + } } else if (rdtype == dns_rdatatype_sig /* SIG(0) */ && rdata->flags == 0) { covers = dns_rdata_covers(rdata); @@ -1405,11 +1451,13 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, } } else { if (msg->rdclass != dns_rdataclass_any && - msg->rdclass != rdclass) + msg->rdclass != rdclass) { DO_ERROR(DNS_R_FORMERR); + } } - } else + } else { covers = 0; + } /* * Check the ownername of NSEC3 records @@ -1457,15 +1505,16 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, * Skip this stage if in update mode or this is a meta-type. */ if (preserve_order || msg->opcode == dns_opcode_update || - skip_type_search) + skip_type_search) { result = ISC_R_NOTFOUND; - else { + } else { /* * If this is a type that can only occur in * the question section, fail. */ - if (dns_rdatatype_questiononly(rdtype)) + if (dns_rdatatype_questiononly(rdtype)) { DO_ERROR(DNS_R_FORMERR); + } rdataset = NULL; result = dns_message_find(name, rdclass, rdtype, covers, @@ -1490,8 +1539,9 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, &rdatalist); first = ISC_LIST_HEAD(rdatalist->rdata); INSIST(first != NULL); - if (dns_rdata_compare(rdata, first) != 0) + if (dns_rdata_compare(rdata, first) != 0) { DO_ERROR(DNS_R_FORMERR); + } } } @@ -1536,8 +1586,9 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, */ if (ttl != rdataset->ttl) { rdataset->attributes |= DNS_RDATASETATTR_TTLADJUSTED; - if (ttl < rdataset->ttl) + if (ttl < rdataset->ttl) { rdataset->ttl = ttl; + } } /* Append this rdata to the rdataset. */ @@ -1585,10 +1636,12 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, } if (seen_problem) { - if (free_name) + if (free_name) { isc_mempool_put(msg->namepool, name); - if (free_rdataset) + } + if (free_rdataset) { isc_mempool_put(msg->rdspool, rdataset); + } free_name = free_rdataset = false; } INSIST(free_name == false); @@ -1604,18 +1657,22 @@ getsection(isc_buffer_t *source, dns_message_t *msg, dns_decompress_t *dctx, msg->opcode == dns_opcode_query && ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) && ((msg->flags & DNS_MESSAGEFLAG_TC) == 0) && !preserve_order && - !auth_signed(section)) + !auth_signed(section)) { DO_ERROR(DNS_R_FORMERR); + } - if (seen_problem) + if (seen_problem) { return (DNS_R_RECOVERABLE); + } return (ISC_R_SUCCESS); cleanup: - if (free_name) + if (free_name) { isc_mempool_put(msg->namepool, name); - if (free_rdataset) + } + if (free_rdataset) { isc_mempool_put(msg->rdspool, rdataset); + } return (result); } @@ -1645,8 +1702,9 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, msg->question_ok = 0; isc_buffer_remainingregion(source, &r); - if (r.length < DNS_MESSAGE_HEADERLEN) + if (r.length < DNS_MESSAGE_HEADERLEN) { return (ISC_R_UNEXPECTEDEND); + } msg->id = isc_buffer_getuint16(source); tmpflags = isc_buffer_getuint16(source); @@ -1670,45 +1728,53 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, dns_decompress_setmethods(&dctx, DNS_COMPRESS_GLOBAL14); ret = getquestions(source, msg, &dctx, options); - if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) + if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; + } if (ret == DNS_R_RECOVERABLE) { seen_problem = true; ret = ISC_R_SUCCESS; } - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } msg->question_ok = 1; ret = getsection(source, msg, &dctx, DNS_SECTION_ANSWER, options); - if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) + if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; + } if (ret == DNS_R_RECOVERABLE) { seen_problem = true; ret = ISC_R_SUCCESS; } - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } ret = getsection(source, msg, &dctx, DNS_SECTION_AUTHORITY, options); - if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) + if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; + } if (ret == DNS_R_RECOVERABLE) { seen_problem = true; ret = ISC_R_SUCCESS; } - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } ret = getsection(source, msg, &dctx, DNS_SECTION_ADDITIONAL, options); - if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) + if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { goto truncated; + } if (ret == DNS_R_RECOVERABLE) { seen_problem = true; ret = ISC_R_SUCCESS; } - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } isc_buffer_remainingregion(source, &r); if (r.length != 0) { @@ -1719,9 +1785,9 @@ dns_message_parse(dns_message_t *msg, isc_buffer_t *source, } truncated: - if ((options & DNS_MESSAGEPARSE_CLONEBUFFER) == 0) + if ((options & DNS_MESSAGEPARSE_CLONEBUFFER) == 0) { isc_buffer_usedregion(&origsource, &msg->saved); - else { + } else { msg->saved.length = isc_buffer_usedlength(&origsource); msg->saved.base = isc_mem_get(msg->mctx, msg->saved.length); memmove(msg->saved.base, isc_buffer_base(&origsource), @@ -1729,10 +1795,12 @@ truncated: msg->free_saved = 1; } - if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) + if (ret == ISC_R_UNEXPECTEDEND && ignore_tc) { return (DNS_R_RECOVERABLE); - if (seen_problem == true) + } + if (seen_problem == true) { return (DNS_R_RECOVERABLE); + } return (ISC_R_SUCCESS); } @@ -1759,11 +1827,13 @@ dns_message_renderbegin(dns_message_t *msg, dns_compress_t *cctx, * buffer. */ isc_buffer_availableregion(buffer, &r); - if (r.length < DNS_MESSAGE_HEADERLEN) + if (r.length < DNS_MESSAGE_HEADERLEN) { return (ISC_R_NOSPACE); + } - if (r.length - DNS_MESSAGE_HEADERLEN < msg->reserved) + if (r.length - DNS_MESSAGE_HEADERLEN < msg->reserved) { return (ISC_R_NOSPACE); + } /* * Reserve enough space for the header in this buffer. @@ -1823,8 +1893,9 @@ dns_message_renderreserve(dns_message_t *msg, unsigned int space) if (msg->buffer != NULL) { isc_buffer_availableregion(msg->buffer, &r); - if (r.length < (space + msg->reserved)) + if (r.length < (space + msg->reserved)) { return (ISC_R_NOSPACE); + } } msg->reserved += space; @@ -1840,16 +1911,18 @@ wrong_priority(dns_rdataset_t *rds, int pass, dns_rdatatype_t preferred_glue) /* * If we are not rendering class IN, this ordering is bogus. */ - if (rds->rdclass != dns_rdataclass_in) + if (rds->rdclass != dns_rdataclass_in) { return (false); + } switch (rds->type) { case dns_rdatatype_a: case dns_rdatatype_aaaa: - if (preferred_glue == rds->type) + if (preferred_glue == rds->type) { pass_needed = 4; - else + } else { pass_needed = 3; + } break; case dns_rdatatype_rrsig: case dns_rdatatype_dnskey: @@ -1859,8 +1932,9 @@ wrong_priority(dns_rdataset_t *rds, int pass, dns_rdatatype_t preferred_glue) pass_needed = 1; } - if (pass_needed >= pass) + if (pass_needed >= pass) { return (false); + } return (true); } @@ -1875,8 +1949,9 @@ renderset(dns_rdataset_t *rdataset, const dns_name_t *owner_name, /* * Shrink the space in the buffer by the reserved amount. */ - if (target->length - target->used < reserved) + if (target->length - target->used < reserved) { return (ISC_R_NOSPACE); + } target->length -= reserved; result = dns_rdataset_towire(rdataset, owner_name, cctx, target, @@ -1892,8 +1967,9 @@ maybe_clear_ad(dns_message_t *msg, dns_section_t sectionid) if (msg->counts[sectionid] == 0 && (sectionid == DNS_SECTION_ANSWER || (sectionid == DNS_SECTION_AUTHORITY && - msg->counts[DNS_SECTION_ANSWER] == 0))) + msg->counts[DNS_SECTION_ANSWER] == 0))) { msg->flags &= ~DNS_MESSAGEFLAG_AD; + } } isc_result_t @@ -1925,26 +2001,31 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, } else if ((options & DNS_MESSAGERENDER_PREFER_AAAA) != 0) { preferred_glue = dns_rdatatype_aaaa; pass = 4; - } else + } else { pass = 3; - } else + } + } else { pass = 1; + } - if ((options & DNS_MESSAGERENDER_OMITDNSSEC) == 0) + if ((options & DNS_MESSAGERENDER_OMITDNSSEC) == 0) { rd_options = 0; - else + } else { rd_options = DNS_RDATASETTOWIRE_OMITDNSSEC; + } /* * Shrink the space in the buffer by the reserved amount. */ - if (msg->buffer->length - msg->buffer->used < msg->reserved) + if (msg->buffer->length - msg->buffer->used < msg->reserved) { return (ISC_R_NOSPACE); + } msg->buffer->length -= msg->reserved; total = 0; - if (msg->reserved == 0 && (options & DNS_MESSAGERENDER_PARTIAL) != 0) + if (msg->reserved == 0 && (options & DNS_MESSAGERENDER_PARTIAL) != 0) { partial = true; + } /* * Render required glue first. Set TC if it won't fit. @@ -1959,16 +2040,17 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, const void *order_arg = &msg->order_arg; st = *(msg->buffer); count = 0; - if (partial) + if (partial) { result = dns_rdataset_towirepartial( rdataset, name, msg->cctx, msg->buffer, msg->order, order_arg, rd_options, &count, NULL); - else + } else { result = dns_rdataset_towiresorted( rdataset, name, msg->cctx, msg->buffer, msg->order, order_arg, rd_options, &count); + } total += count; if (partial && result == ISC_R_NOSPACE) { msg->flags |= DNS_MESSAGEFLAG_TC; @@ -1976,8 +2058,9 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, msg->counts[sectionid] += total; return (result); } - if (result == ISC_R_NOSPACE) + if (result == ISC_R_NOSPACE) { msg->flags |= DNS_MESSAGEFLAG_TC; + } if (result != ISC_R_SUCCESS) { INSIST(st.used < 65536); dns_compress_rollback(msg->cctx, @@ -2007,31 +2090,34 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, next_rdataset = ISC_LIST_NEXT(rdataset, link); if ((rdataset->attributes & - DNS_RDATASETATTR_RENDERED) != 0) + DNS_RDATASETATTR_RENDERED) != 0) { goto next; + } if (((options & DNS_MESSAGERENDER_ORDERED) == 0) && (sectionid == DNS_SECTION_ADDITIONAL) && wrong_priority(rdataset, pass, - preferred_glue)) + preferred_glue)) { goto next; + } st = *(msg->buffer); count = 0; - if (partial) + if (partial) { result = dns_rdataset_towirepartial( rdataset, name, msg->cctx, msg->buffer, msg->order, &msg->order_arg, rd_options, &count, NULL); - else + } else { result = dns_rdataset_towiresorted( rdataset, name, msg->cctx, msg->buffer, msg->order, &msg->order_arg, rd_options, &count); + } total += count; @@ -2070,10 +2156,12 @@ dns_message_rendersection(dns_message_t *msg, dns_section_t sectionid, */ if (rdataset->trust != dns_trust_secure && (sectionid == DNS_SECTION_ANSWER || - sectionid == DNS_SECTION_AUTHORITY)) + sectionid == DNS_SECTION_AUTHORITY)) { msg->flags &= ~DNS_MESSAGEFLAG_AD; - if (OPTOUT(rdataset)) + } + if (OPTOUT(rdataset)) { msg->flags &= ~DNS_MESSAGEFLAG_AD; + } rdataset->attributes |= DNS_RDATASETATTR_RENDERED; @@ -2163,8 +2251,9 @@ dns_message_renderend(dns_message_t *msg) dns_compress_rollback(msg->cctx, 0); result = dns_message_rendersection(msg, DNS_SECTION_QUESTION, 0); - if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE) + if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE) { return (result); + } } /* @@ -2186,8 +2275,9 @@ dns_message_renderend(dns_message_t *msg) result = renderset(msg->opt, dns_rootname, msg->cctx, msg->buffer, msg->reserved, 0, &count); msg->counts[DNS_SECTION_ADDITIONAL] += count; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } /* @@ -2203,8 +2293,9 @@ dns_message_renderend(dns_message_t *msg) /* Check PAD */ if ((cp[-4] != 0) || (cp[-3] != DNS_OPT_PAD) || (cp[-2] != 0) || - (cp[-1] != 0)) + (cp[-1] != 0)) { return (ISC_R_UNEXPECTED); + } /* * Zero-fill the PAD to the computed size; @@ -2222,8 +2313,9 @@ dns_message_renderend(dns_message_t *msg) } /* Stay below the available length */ remaining = isc_buffer_availablelength(msg->buffer); - if (padsize > remaining) + if (padsize > remaining) { padsize = remaining; + } isc_buffer_add(msg->buffer, padsize); memset(cp, 0, padsize); @@ -2244,14 +2336,16 @@ dns_message_renderend(dns_message_t *msg) dns_message_renderrelease(msg, msg->sig_reserved); msg->sig_reserved = 0; result = dns_tsig_sign(msg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } count = 0; result = renderset(msg->tsig, msg->tsigname, msg->cctx, msg->buffer, msg->reserved, 0, &count); msg->counts[DNS_SECTION_ADDITIONAL] += count; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } /* @@ -2261,8 +2355,9 @@ dns_message_renderend(dns_message_t *msg) dns_message_renderrelease(msg, msg->sig_reserved); msg->sig_reserved = 0; result = dns_dnssec_signmessage(msg, msg->sig0key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } count = 0; /* * Note: dns_rootname is used here, not msg->sig0name, since @@ -2272,8 +2367,9 @@ dns_message_renderend(dns_message_t *msg) result = renderset(msg->sig0, dns_rootname, msg->cctx, msg->buffer, msg->reserved, 0, &count); msg->counts[DNS_SECTION_ADDITIONAL] += count; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } isc_buffer_usedregion(msg->buffer, &r); @@ -2313,8 +2409,9 @@ dns_message_renderreset(dns_message_t *msg) } } } - if (msg->tsigname != NULL) + if (msg->tsigname != NULL) { dns_message_puttempname(msg, &msg->tsigname); + } if (msg->tsig != NULL) { dns_rdataset_disassociate(msg->tsig); dns_message_puttemprdataset(msg, &msg->tsig); @@ -2333,8 +2430,9 @@ dns_message_firstname(dns_message_t *msg, dns_section_t section) msg->cursors[section] = ISC_LIST_HEAD(msg->sections[section]); - if (msg->cursors[section] == NULL) + if (msg->cursors[section] == NULL) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } @@ -2348,8 +2446,9 @@ dns_message_nextname(dns_message_t *msg, dns_section_t section) msg->cursors[section] = ISC_LIST_NEXT(msg->cursors[section], link); - if (msg->cursors[section] == NULL) + if (msg->cursors[section] == NULL) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } @@ -2394,23 +2493,27 @@ dns_message_findname(dns_message_t *msg, dns_section_t section, result = findname(&foundname, target, &msg->sections[section]); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (DNS_R_NXDOMAIN); - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { return (result); + } - if (name != NULL) + if (name != NULL) { *name = foundname; + } /* * And now look for the type. */ - if (ISC_UNLIKELY(type == dns_rdatatype_any)) + if (ISC_UNLIKELY(type == dns_rdatatype_any)) { return (ISC_R_SUCCESS); + } result = dns_message_findtype(foundname, type, covers, rdataset); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (DNS_R_NXRRSET); + } return (result); } @@ -2462,8 +2565,9 @@ dns_message_gettempname(dns_message_t *msg, dns_name_t **item) REQUIRE(item != NULL && *item == NULL); *item = isc_mempool_get(msg->namepool); - if (*item == NULL) + if (*item == NULL) { return (ISC_R_NOMEMORY); + } dns_name_init(*item, NULL); return (ISC_R_SUCCESS); @@ -2476,8 +2580,9 @@ dns_message_gettempoffsets(dns_message_t *msg, dns_offsets_t **item) REQUIRE(item != NULL && *item == NULL); *item = newoffsets(msg); - if (*item == NULL) + if (*item == NULL) { return (ISC_R_NOMEMORY); + } return (ISC_R_SUCCESS); } @@ -2489,8 +2594,9 @@ dns_message_gettemprdata(dns_message_t *msg, dns_rdata_t **item) REQUIRE(item != NULL && *item == NULL); *item = newrdata(msg); - if (*item == NULL) + if (*item == NULL) { return (ISC_R_NOMEMORY); + } return (ISC_R_SUCCESS); } @@ -2502,8 +2608,9 @@ dns_message_gettemprdataset(dns_message_t *msg, dns_rdataset_t **item) REQUIRE(item != NULL && *item == NULL); *item = isc_mempool_get(msg->rdspool); - if (*item == NULL) + if (*item == NULL) { return (ISC_R_NOMEMORY); + } dns_rdataset_init(*item); @@ -2517,8 +2624,9 @@ dns_message_gettemprdatalist(dns_message_t *msg, dns_rdatalist_t **item) REQUIRE(item != NULL && *item == NULL); *item = newrdatalist(msg); - if (*item == NULL) + if (*item == NULL) { return (ISC_R_NOMEMORY); + } return (ISC_R_SUCCESS); } @@ -2535,8 +2643,9 @@ dns_message_puttempname(dns_message_t *msg, dns_name_t **itemp) REQUIRE(!ISC_LINK_LINKED(item, link)); REQUIRE(ISC_LIST_HEAD(item->list) == NULL); - if (dns_name_dynamic(item)) + if (dns_name_dynamic(item)) { dns_name_free(item, msg->mctx); + } isc_mempool_put(msg->namepool, item); } @@ -2585,17 +2694,20 @@ dns_message_peekheader(isc_buffer_t *source, dns_messageid_t *idp, buffer = *source; isc_buffer_remainingregion(&buffer, &r); - if (r.length < DNS_MESSAGE_HEADERLEN) + if (r.length < DNS_MESSAGE_HEADERLEN) { return (ISC_R_UNEXPECTEDEND); + } id = isc_buffer_getuint16(&buffer); flags = isc_buffer_getuint16(&buffer); flags &= DNS_MESSAGE_FLAG_MASK; - if (flagsp != NULL) + if (flagsp != NULL) { *flagsp = flags; - if (idp != NULL) + } + if (idp != NULL) { *idp = id; + } return (ISC_R_SUCCESS); } @@ -2609,18 +2721,23 @@ dns_message_reply(dns_message_t *msg, bool want_question_section) REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE((msg->flags & DNS_MESSAGEFLAG_QR) == 0); - if (!msg->header_ok) + if (!msg->header_ok) { return (DNS_R_FORMERR); - if (msg->opcode != dns_opcode_query && msg->opcode != dns_opcode_notify) + } + if (msg->opcode != dns_opcode_query && + msg->opcode != dns_opcode_notify) { want_question_section = false; - if (msg->opcode == dns_opcode_update) + } + if (msg->opcode == dns_opcode_update) { clear_from = DNS_SECTION_PREREQUISITE; - else if (want_question_section) { - if (!msg->question_ok) + } else if (want_question_section) { + if (!msg->question_ok) { return (DNS_R_FORMERR); + } clear_from = DNS_SECTION_ANSWER; - } else + } else { clear_from = DNS_SECTION_QUESTION; + } msg->from_to_wire = DNS_MESSAGE_INTENTRENDER; msgresetnames(msg, clear_from); msgresetopt(msg); @@ -2630,10 +2747,11 @@ dns_message_reply(dns_message_t *msg, bool want_question_section) * We now clear most flags and then set QR, ensuring that the * reply's flags will be in a reasonable state. */ - if (msg->opcode == dns_opcode_query) + if (msg->opcode == dns_opcode_query) { msg->flags &= DNS_MESSAGE_REPLYPRESERVE; - else + } else { msg->flags = 0; + } msg->flags |= DNS_MESSAGEFLAG_QR; /* @@ -2644,8 +2762,9 @@ dns_message_reply(dns_message_t *msg, bool want_question_section) unsigned int otherlen = 0; msg->querytsigstatus = msg->tsigstatus; msg->tsigstatus = dns_rcode_noerror; - if (msg->querytsigstatus == dns_tsigerror_badtime) + if (msg->querytsigstatus == dns_tsigerror_badtime) { otherlen = 6; + } msg->sig_reserved = spacefortsig(msg->tsigkey, otherlen); result = dns_message_renderreserve(msg, msg->sig_reserved); if (result != ISC_R_SUCCESS) { @@ -2709,8 +2828,9 @@ dns_message_setopt(dns_message_t *msg, dns_rdataset_t *opt) msgresetopt(msg); result = dns_rdataset_first(opt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdataset_current(opt, &rdata); msg->opt_reserved = 11 + rdata.length; result = dns_message_renderreserve(msg, msg->opt_reserved); @@ -2739,8 +2859,9 @@ dns_message_gettsig(dns_message_t *msg, const dns_name_t **owner) REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(owner == NULL || *owner == NULL); - if (owner != NULL) + if (owner != NULL) { *owner = msg->tsigname; + } return (msg->tsig); } @@ -2804,19 +2925,23 @@ dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) REQUIRE(DNS_MESSAGE_VALID(msg)); REQUIRE(msg->querytsig == NULL); - if (querytsig == NULL) + if (querytsig == NULL) { return (ISC_R_SUCCESS); + } result = dns_message_gettemprdata(msg, &rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdatalist(msg, &list); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdataset(msg, &set); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_buffer_usedregion(querytsig, &r); isc_buffer_allocate(msg->mctx, &buf, r.length); @@ -2827,20 +2952,24 @@ dns_message_setquerytsig(dns_message_t *msg, isc_buffer_t *querytsig) dns_message_takebuffer(msg, &buf); ISC_LIST_APPEND(list->rdata, rdata, link); result = dns_rdatalist_tordataset(list, set); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } msg->querytsig = set; return (result); cleanup: - if (rdata != NULL) + if (rdata != NULL) { dns_message_puttemprdata(msg, &rdata); - if (list != NULL) + } + if (list != NULL) { dns_message_puttemprdatalist(msg, &list); - if (set != NULL) + } + if (set != NULL) { dns_message_puttemprdataset(msg, &set); + } return (ISC_R_NOMEMORY); } @@ -2856,12 +2985,14 @@ dns_message_getquerytsig(dns_message_t *msg, isc_mem_t *mctx, REQUIRE(mctx != NULL); REQUIRE(querytsig != NULL && *querytsig == NULL); - if (msg->tsig == NULL) + if (msg->tsig == NULL) { return (ISC_R_SUCCESS); + } result = dns_rdataset_first(msg->tsig); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_current(msg->tsig, &rdata); dns_rdata_toregion(&rdata, &r); @@ -2885,10 +3016,11 @@ dns_message_getsig0(dns_message_t *msg, const dns_name_t **owner) * after the SIG(0) has been applied, we need to return the * root name, not NULL. */ - if (msg->sig0name == NULL) + if (msg->sig0name == NULL) { *owner = dns_rootname; - else + } else { *owner = msg->sig0name; + } } return (msg->sig0); } @@ -2979,11 +3111,13 @@ dns_message_signer(dns_message_t *msg, dns_name_t *signer) REQUIRE(signer != NULL); REQUIRE(msg->from_to_wire == DNS_MESSAGE_INTENTPARSE); - if (msg->tsig == NULL && msg->sig0 == NULL) + if (msg->tsig == NULL && msg->sig0 == NULL) { return (ISC_R_NOTFOUND); + } - if (msg->verify_attempted == 0) + if (msg->verify_attempted == 0) { return (DNS_R_NOTVERIFIEDYET); + } if (!dns_name_hasbuffer(signer)) { isc_buffer_t *dynbuf = NULL; @@ -3000,13 +3134,15 @@ dns_message_signer(dns_message_t *msg, dns_name_t *signer) dns_rdataset_current(msg->sig0, &rdata); result = dns_rdata_tostruct(&rdata, &sig, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (msg->verified_sig && msg->sig0status == dns_rcode_noerror) + if (msg->verified_sig && msg->sig0status == dns_rcode_noerror) { result = ISC_R_SUCCESS; - else + } else { result = DNS_R_SIGINVALID; + } dns_name_clone(&sig.signer, signer); dns_rdata_freestruct(&sig); } else { @@ -3042,8 +3178,9 @@ dns_message_signer(dns_message_t *msg, dns_name_t *signer) } else { identity = dns_tsigkey_identity(msg->tsigkey); if (identity == NULL) { - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_NOIDENTITY; + } identity = &msg->tsigkey->name; } dns_name_clone(identity, signer); @@ -3102,7 +3239,7 @@ dns_message_dumpsig(dns_message_t *msg, char *txt1) querytsig.siglen); } } -#endif +#endif /* ifdef SKAN_MSG_DEBUG */ isc_result_t dns_message_checksig(dns_message_t *msg, dns_view_t *view) @@ -3111,8 +3248,9 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) REQUIRE(DNS_MESSAGE_VALID(msg)); - if (msg->tsigkey == NULL && msg->tsig == NULL && msg->sig0 == NULL) + if (msg->tsigkey == NULL && msg->tsig == NULL && msg->sig0 == NULL) { return (ISC_R_SUCCESS); + } INSIST(msg->saved.base != NULL); isc_buffer_init(&msgb, msg->saved.base, msg->saved.length); @@ -3120,11 +3258,12 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) if (msg->tsigkey != NULL || msg->tsig != NULL) { #ifdef SKAN_MSG_DEBUG dns_message_dumpsig(msg, "dns_message_checksig#1"); -#endif - if (view != NULL) +#endif /* ifdef SKAN_MSG_DEBUG */ + if (view != NULL) { return (dns_view_checksig(view, &msgb, msg)); - else + } else { return (dns_tsig_verify(&msgb, msg, NULL, NULL)); + } } else { dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdata_sig_t sig; @@ -3142,16 +3281,19 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) * looked for in the additional section, and the dynamic update * meta-records are in the prerequisite and update sections. */ - if (rdata.length == 0) + if (rdata.length == 0) { return (ISC_R_UNEXPECTEDEND); + } result = dns_rdata_tostruct(&rdata, &sig, msg->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_init(&keyset); - if (view == NULL) + if (view == NULL) { return (DNS_R_KEYUNAUTHORIZED); + } result = dns_view_simplefind(view, &sig.signer, dns_rdatatype_key /* SIG(0) */, 0, 0, false, &keyset, NULL); @@ -3178,8 +3320,9 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) result = dst_key_fromdns(&sig.signer, rdata.rdclass, &b, view->mctx, &key); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } if (dst_key_alg(key) != sig.algorithm || dst_key_id(key) != sig.keyid || !(dst_key_proto(key) == DNS_KEYPROTO_DNSSEC || @@ -3189,15 +3332,18 @@ dns_message_checksig(dns_message_t *msg, dns_view_t *view) } result = dns_dnssec_verifymessage(&msgb, msg, key); dst_key_free(&key); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = DNS_R_KEYUNAUTHORIZED; + } freesig: - if (dns_rdataset_isassociated(&keyset)) + if (dns_rdataset_isassociated(&keyset)) { dns_rdataset_disassociate(&keyset); + } dns_rdata_freestruct(&sig); return (result); } @@ -3272,11 +3418,14 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, rdataset = ISC_LIST_NEXT(rdataset, link)) { if (section == DNS_SECTION_ANSWER && rdataset->type == dns_rdatatype_soa) { - if ((flags & DNS_MESSAGETEXTFLAG_OMITSOA) != 0) + if ((flags & DNS_MESSAGETEXTFLAG_OMITSOA) != + 0) { continue; + } if (seensoa && - (flags & DNS_MESSAGETEXTFLAG_ONESOA) != 0) + (flags & DNS_MESSAGETEXTFLAG_ONESOA) != 0) { continue; + } seensoa = true; } if (section == DNS_SECTION_QUESTION) { @@ -3293,8 +3442,9 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, name, rdataset, style, &msg->indent, target); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } result = dns_message_nextname(msg, section); } while (result == ISC_R_SUCCESS); @@ -3307,8 +3457,9 @@ dns_message_sectiontotext(dns_message_t *msg, dns_section_t section, INDENT(style); ADD_STRING(target, "\n"); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: msg->indent.count = saved_count; @@ -3328,37 +3479,44 @@ render_ecs(isc_buffer_t *ecsbuf, isc_buffer_t *target) * Note: This routine needs to handle malformed ECS options. */ - if (isc_buffer_remaininglength(ecsbuf) < 4) + if (isc_buffer_remaininglength(ecsbuf) < 4) { return (DNS_R_OPTERR); + } family = isc_buffer_getuint16(ecsbuf); addrlen = isc_buffer_getuint8(ecsbuf); scopelen = isc_buffer_getuint8(ecsbuf); addrbytes = (addrlen + 7) / 8; - if (isc_buffer_remaininglength(ecsbuf) < addrbytes) + if (isc_buffer_remaininglength(ecsbuf) < addrbytes) { return (DNS_R_OPTERR); + } - if (addrbytes > sizeof(addr)) + if (addrbytes > sizeof(addr)) { return (DNS_R_OPTERR); + } memset(addr, 0, sizeof(addr)); - for (i = 0; i < addrbytes; i++) + for (i = 0; i < addrbytes; i++) { addr[i] = isc_buffer_getuint8(ecsbuf); + } switch (family) { case 0: - if (addrlen != 0U || scopelen != 0U) + if (addrlen != 0U || scopelen != 0U) { return (DNS_R_OPTERR); + } strlcpy(addr_text, "0", sizeof(addr_text)); break; case 1: - if (addrlen > 32 || scopelen > 32) + if (addrlen > 32 || scopelen > 32) { return (DNS_R_OPTERR); + } inet_ntop(AF_INET, addr, addr_text, sizeof(addr_text)); break; case 2: - if (addrlen > 128 || scopelen > 128) + if (addrlen > 128 || scopelen > 128) { return (DNS_R_OPTERR); + } inet_ntop(AF_INET6, addr, addr_text, sizeof(addr_text)); break; default: @@ -3460,8 +3618,9 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, ADD_STRING(target, "\n"); INDENT(style); ADD_STRING(target, "flags:"); - if ((ps->ttl & DNS_MESSAGEEXTFLAG_DO) != 0) + if ((ps->ttl & DNS_MESSAGEEXTFLAG_DO) != 0) { ADD_STRING(target, " do"); + } ADD_STRING(target, "\n"); mbz = ps->ttl & 0xffff; mbz &= ~DNS_MESSAGEEXTFLAG_DO; /* Known Flags. */ @@ -3546,8 +3705,9 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, ADD_STRING(target, " ("); result = dns_ttl_totext(secs, true, true, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } ADD_STRING(target, ")\n"); continue; } @@ -3644,20 +3804,23 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, /* * Valid server cookie? */ - if (msg->cc_ok && optlen >= 16) + if (msg->cc_ok && optlen >= 16) { ADD_STRING(target, " (good)"); + } /* * Server cookie is not valid but * we had our cookie echoed back. */ - if (msg->cc_ok && optlen < 16) + if (msg->cc_ok && optlen < 16) { ADD_STRING(target, " (echoed)"); + } /* * We didn't get our cookie echoed * back. */ - if (msg->cc_bad) + if (msg->cc_bad) { ADD_STRING(target, " (bad)"); + } ADD_STRING(target, "\n"); continue; } @@ -3678,11 +3841,12 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, goto cleanup; } for (i = 0; i < optlen; i++) { - if (isprint(optdata[i])) + if (isprint(optdata[i])) { isc_buffer_putmem( target, &optdata[i], 1); - else + } else { isc_buffer_putstr(target, "."); + } } ADD_STRING(target, "\")"); } @@ -3713,8 +3877,9 @@ dns_message_pseudosectiontoyaml(dns_message_t *msg, dns_pseudosection_t section, result = dns_master_rdatasettotext(name, ps, style, &msg->indent, target); if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 && - (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) + (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { ADD_STRING(target, "\n"); + } goto cleanup; } @@ -3753,8 +3918,9 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, switch (section) { case DNS_PSEUDOSECTION_OPT: ps = dns_message_getopt(msg); - if (ps == NULL) + if (ps == NULL) { return (ISC_R_SUCCESS); + } if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { INDENT(style); ADD_STRING(target, ";; OPT PSEUDOSECTION:\n"); @@ -3766,8 +3932,9 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, (unsigned int)((ps->ttl & 0x00ff0000) >> 16)); ADD_STRING(target, buf); ADD_STRING(target, ", flags:"); - if ((ps->ttl & DNS_MESSAGEEXTFLAG_DO) != 0) + if ((ps->ttl & DNS_MESSAGEEXTFLAG_DO) != 0) { ADD_STRING(target, " do"); + } mbz = ps->ttl & 0xffff; mbz &= ~DNS_MESSAGEEXTFLAG_DO; /* Known Flags. */ if (mbz != 0) { @@ -3775,14 +3942,16 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, snprintf(buf, sizeof(buf), "0x%.4x", mbz); ADD_STRING(target, buf); ADD_STRING(target, ", udp: "); - } else + } else { ADD_STRING(target, "; udp: "); + } snprintf(buf, sizeof(buf), "%u\n", (unsigned int)ps->rdclass); ADD_STRING(target, buf); result = dns_rdataset_first(ps); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } /* * Print EDNS info, if any. @@ -3846,8 +4015,9 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, ADD_STRING(target, " ("); result = dns_ttl_totext(secs, true, true, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } ADD_STRING(target, ")\n"); continue; } @@ -3944,20 +4114,23 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, /* * Valid server cookie? */ - if (msg->cc_ok && optlen >= 16) + if (msg->cc_ok && optlen >= 16) { ADD_STRING(target, " (good)"); + } /* * Server cookie is not valid but * we had our cookie echoed back. */ - if (msg->cc_ok && optlen < 16) + if (msg->cc_ok && optlen < 16) { ADD_STRING(target, " (echoed)"); + } /* * We didn't get our cookie echoed * back. */ - if (msg->cc_bad) + if (msg->cc_bad) { ADD_STRING(target, " (bad)"); + } ADD_STRING(target, "\n"); continue; } @@ -3972,14 +4145,17 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, * version */ ADD_STRING(target, "(\""); - if (isc_buffer_availablelength(target) < optlen) + if (isc_buffer_availablelength(target) < + optlen) { return (ISC_R_NOSPACE); + } for (i = 0; i < optlen; i++) { - if (isprint(optdata[i])) + if (isprint(optdata[i])) { isc_buffer_putmem( target, &optdata[i], 1); - else + } else { isc_buffer_putstr(target, "."); + } } ADD_STRING(target, "\")"); } @@ -3988,29 +4164,35 @@ dns_message_pseudosectiontotext(dns_message_t *msg, dns_pseudosection_t section, return (ISC_R_SUCCESS); case DNS_PSEUDOSECTION_TSIG: ps = dns_message_gettsig(msg, &name); - if (ps == NULL) + if (ps == NULL) { return (ISC_R_SUCCESS); + } INDENT(style); - if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) + if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { ADD_STRING(target, ";; TSIG PSEUDOSECTION:\n"); + } result = dns_master_rdatasettotext(name, ps, style, &msg->indent, target); if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 && - (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) + (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { ADD_STRING(target, "\n"); + } return (result); case DNS_PSEUDOSECTION_SIG0: ps = dns_message_getsig0(msg, &name); - if (ps == NULL) + if (ps == NULL) { return (ISC_R_SUCCESS); + } INDENT(style); - if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) + if ((flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { ADD_STRING(target, ";; SIG0 PSEUDOSECTION:\n"); + } result = dns_master_rdatasettotext(name, ps, style, &msg->indent, target); if ((flags & DNS_MESSAGETEXTFLAG_NOHEADERS) == 0 && - (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) + (flags & DNS_MESSAGETEXTFLAG_NOCOMMENTS) == 0) { ADD_STRING(target, "\n"); + } return (result); } result = ISC_R_UNEXPECTED; @@ -4295,8 +4477,9 @@ dns_opcode_totext(dns_opcode_t opcode, isc_buffer_t *target) { REQUIRE(opcode < 16); - if (isc_buffer_availablelength(target) < strlen(opcodetext[opcode])) + if (isc_buffer_availablelength(target) < strlen(opcodetext[opcode])) { return (ISC_R_NOSPACE); + } isc_buffer_putstr(target, opcodetext[opcode]); return (ISC_R_SUCCESS); } @@ -4340,18 +4523,20 @@ logfmtpacket(dns_message_t *message, const char *description, int len = 1024; isc_result_t result; - if (!isc_log_wouldlog(dns_lctx, level)) + if (!isc_log_wouldlog(dns_lctx, level)) { return; + } /* * Note that these are multiline debug messages. We want a newline * to appear in the log after each message. */ - if (address != NULL) + if (address != NULL) { isc_sockaddr_format(address, addrbuf, sizeof(addrbuf)); - else + } else { newline = space = ""; + } do { buf = isc_mem_get(mctx, len); @@ -4360,15 +4545,17 @@ logfmtpacket(dns_message_t *message, const char *description, if (result == ISC_R_NOSPACE) { isc_mem_put(mctx, buf, len); len += 1024; - } else if (result == ISC_R_SUCCESS) + } else if (result == ISC_R_SUCCESS) { isc_log_write(dns_lctx, category, module, level, "%s%s%s%s%.*s", description, space, addrbuf, newline, (int)isc_buffer_usedlength(&buffer), buf); + } } while (result == ISC_R_NOSPACE); - if (buf != NULL) + if (buf != NULL) { isc_mem_put(mctx, buf, len); + } } isc_result_t @@ -4386,14 +4573,17 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp, REQUIRE(rdatasetp != NULL && *rdatasetp == NULL); result = dns_message_gettemprdatalist(message, &rdatalist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_message_gettemprdata(message, &rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdataset(message, &rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } rdatalist->type = dns_rdatatype_opt; @@ -4414,8 +4604,9 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp, if (count != 0U) { isc_buffer_t *buf = NULL; bool seenpad = false; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { len += ednsopts[i].length + 4; + } if (len > 0xffffU) { result = ISC_R_NOSPACE; @@ -4446,8 +4637,9 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp, rdata->data = isc_buffer_base(buf); rdata->length = len; dns_message_takebuffer(message, &buf); - if (seenpad) + if (seenpad) { message->padding_off = len; + } } else { rdata->data = NULL; rdata->length = 0; @@ -4465,12 +4657,15 @@ dns_message_buildopt(dns_message_t *message, dns_rdataset_t **rdatasetp, return (ISC_R_SUCCESS); cleanup: - if (rdata != NULL) + if (rdata != NULL) { dns_message_puttemprdata(message, &rdata); - if (rdataset != NULL) + } + if (rdataset != NULL) { dns_message_puttemprdataset(message, &rdataset); - if (rdatalist != NULL) + } + if (rdatalist != NULL) { dns_message_puttemprdatalist(message, &rdatalist); + } return (result); } @@ -4492,7 +4687,8 @@ dns_message_setpadding(dns_message_t *msg, uint16_t padding) REQUIRE(DNS_MESSAGE_VALID(msg)); /* Avoid silly large padding */ - if (padding > 512) + if (padding > 512) { padding = 512; + } msg->padding = padding; } diff --git a/lib/dns/name.c b/lib/dns/name.c index 9d851bd8fd..c24a5c876e 100644 --- a/lib/dns/name.c +++ b/lib/dns/name.c @@ -197,11 +197,13 @@ dns_name_isvalid(const dns_name_t *name) unsigned char *ndata, *offsets; unsigned int offset, count, length, nlabels; - if (!VALID_NAME(name)) + if (!VALID_NAME(name)) { return (false); + } - if (name->length > 255U || name->labels > 127U) + if (name->length > 255U || name->labels > 127U) { return (false); + } ndata = name->ndata; length = name->length; @@ -211,23 +213,28 @@ dns_name_isvalid(const dns_name_t *name) while (offset != length) { count = *ndata; - if (count > 63U) + if (count > 63U) { return (false); - if (offsets != NULL && offsets[nlabels] != offset) + } + if (offsets != NULL && offsets[nlabels] != offset) { return (false); + } nlabels++; offset += count + 1; ndata += count + 1; - if (offset > length) + if (offset > length) { return (false); + } - if (count == 0) + if (count == 0) { break; + } } - if (nlabels != name->labels || offset != name->length) + if (nlabels != name->labels || offset != name->length) { return (false); + } return (true); } @@ -254,8 +261,9 @@ dns_name_hasbuffer(const dns_name_t *name) REQUIRE(VALID_NAME(name)); - if (name->buffer != NULL) + if (name->buffer != NULL) { return (true); + } return (false); } @@ -269,8 +277,9 @@ dns_name_isabsolute(const dns_name_t *name) REQUIRE(VALID_NAME(name)); - if ((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((name->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { return (true); + } return (false); } @@ -297,20 +306,23 @@ dns_name_ismailbox(const dns_name_t *name) /* * Root label. */ - if (name->length == 1) + if (name->length == 1) { return (true); + } ndata = name->ndata; n = *ndata++; INSIST(n <= 63); while (n--) { ch = *ndata++; - if (!domainchar(ch)) + if (!domainchar(ch)) { return (false); + } } - if (ndata == name->ndata + name->length) + if (ndata == name->ndata + name->length) { return (false); + } /* * RFC292/RFC1123 hostname. @@ -322,11 +334,13 @@ dns_name_ismailbox(const dns_name_t *name) while (n--) { ch = *ndata++; if (first || n == 0) { - if (!borderchar(ch)) + if (!borderchar(ch)) { return (false); + } } else { - if (!middlechar(ch)) + if (!middlechar(ch)) { return (false); + } } first = false; } @@ -348,15 +362,17 @@ dns_name_ishostname(const dns_name_t *name, bool wildcard) /* * Root label. */ - if (name->length == 1) + if (name->length == 1) { return (true); + } /* * Skip wildcard if this is a ownername. */ ndata = name->ndata; - if (wildcard && ndata[0] == 1 && ndata[1] == '*') + if (wildcard && ndata[0] == 1 && ndata[1] == '*') { ndata += 2; + } /* * RFC292/RFC1123 hostname. @@ -368,11 +384,13 @@ dns_name_ishostname(const dns_name_t *name, bool wildcard) while (n--) { ch = *ndata++; if (first || n == 0) { - if (!borderchar(ch)) + if (!borderchar(ch)) { return (false); + } } else { - if (!middlechar(ch)) + if (!middlechar(ch)) { return (false); + } } first = false; } @@ -394,8 +412,9 @@ dns_name_iswildcard(const dns_name_t *name) if (name->length >= 2) { ndata = name->ndata; - if (ndata[0] == 1 && ndata[1] == '*') + if (ndata[0] == 1 && ndata[1] == '*') { return (true); + } } return (false); @@ -429,8 +448,9 @@ dns_name_internalwildcard(const dns_name_t *name) while (label + 1 < name->labels) { count = *ndata++; INSIST(count <= 63); - if (count == 1 && *ndata == '*') + if (count == 1 && *ndata == '*') { return (true); + } ndata += count; label++; } @@ -545,10 +565,11 @@ dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2, INSIST(count1 <= 63 && count2 <= 63); cdiff = (int)count1 - (int)count2; - if (cdiff < 0) + if (cdiff < 0) { count = count1; - else + } else { count = count2; + } /* Loop unrolled for performance */ while (ISC_LIKELY(count > 3)) { @@ -596,19 +617,21 @@ dns_name_fullcompare(const dns_name_t *name1, const dns_name_t *name2, } *orderp = ldiff; - if (ldiff < 0) + if (ldiff < 0) { namereln = dns_namereln_contains; - else if (ldiff > 0) + } else if (ldiff > 0) { namereln = dns_namereln_subdomain; - else + } else { namereln = dns_namereln_equal; + } *nlabelsp = nlabels; return (namereln); done: *nlabelsp = nlabels; - if (nlabels > 0) + if (nlabels > 0) { namereln = dns_namereln_commonancestor; + } return (namereln); } @@ -658,48 +681,57 @@ dns_name_equal(const dns_name_t *name1, const dns_name_t *name2) REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) == (name2->attributes & DNS_NAMEATTR_ABSOLUTE)); - if (ISC_UNLIKELY(name1 == name2)) + if (ISC_UNLIKELY(name1 == name2)) { return (true); + } - if (name1->length != name2->length) + if (name1->length != name2->length) { return (false); + } l = name1->labels; - if (l != name2->labels) + if (l != name2->labels) { return (false); + } label1 = name1->ndata; label2 = name2->ndata; while (ISC_LIKELY(l-- > 0)) { count = *label1++; - if (count != *label2++) + if (count != *label2++) { return (false); + } INSIST(count <= 63); /* no bitstring support */ /* Loop unrolled for performance */ while (ISC_LIKELY(count > 3)) { c = maptolower[label1[0]]; - if (c != maptolower[label2[0]]) + if (c != maptolower[label2[0]]) { return (false); + } c = maptolower[label1[1]]; - if (c != maptolower[label2[1]]) + if (c != maptolower[label2[1]]) { return (false); + } c = maptolower[label1[2]]; - if (c != maptolower[label2[2]]) + if (c != maptolower[label2[2]]) { return (false); + } c = maptolower[label1[3]]; - if (c != maptolower[label2[3]]) + if (c != maptolower[label2[3]]) { return (false); + } count -= 4; label1 += 4; label2 += 4; } while (ISC_LIKELY(count-- > 0)) { c = maptolower[*label1++]; - if (c != maptolower[*label2++]) + if (c != maptolower[*label2++]) { return (false); + } } } @@ -726,11 +758,13 @@ dns_name_caseequal(const dns_name_t *name1, const dns_name_t *name2) REQUIRE((name1->attributes & DNS_NAMEATTR_ABSOLUTE) == (name2->attributes & DNS_NAMEATTR_ABSOLUTE)); - if (name1->length != name2->length) + if (name1->length != name2->length) { return (false); + } - if (memcmp(name1->ndata, name2->ndata, name1->length) != 0) + if (memcmp(name1->ndata, name2->ndata, name1->length) != 0) { return (false); + } return (true); } @@ -768,17 +802,19 @@ dns_name_rdatacompare(const dns_name_t *name1, const dns_name_t *name2) /* no bitstring support */ INSIST(count1 <= 63 && count2 <= 63); - if (count1 != count2) + if (count1 != count2) { return ((count1 < count2) ? -1 : 1); + } count = count1; while (count > 0) { count--; c1 = maptolower[*label1++]; c2 = maptolower[*label2++]; - if (c1 < c2) + if (c1 < c2) { return (-1); - else if (c1 > c2) + } else if (c1 > c2) { return (1); + } } } @@ -812,8 +848,9 @@ dns_name_issubdomain(const dns_name_t *name1, const dns_name_t *name2) namereln = dns_name_fullcompare(name1, name2, &order, &nlabels); if (namereln == dns_namereln_subdomain || - namereln == dns_namereln_equal) + namereln == dns_namereln_equal) { return (true); + } return (false); } @@ -835,12 +872,15 @@ dns_name_matcheswildcard(const dns_name_t *name, const dns_name_t *wname) #if defined(__clang__) && \ (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)) memset(&tname, 0, sizeof(tname)); -#endif +#endif /* if defined(__clang__) && (__clang_major__ < 3 || (__clang_major__ == \ + * 3 \ + * && __clang_minor__ < 2)) */ DNS_NAME_INIT(&tname, NULL); dns_name_getlabelsequence(wname, 1, labels - 1, &tname); if (dns_name_fullcompare(name, &tname, &order, &nlabels) == - dns_namereln_subdomain) + dns_namereln_subdomain) { return (true); + } return (false); } @@ -876,10 +916,11 @@ dns_name_getlabel(const dns_name_t *name, unsigned int n, dns_label_t *label) SETUP_OFFSETS(name, offsets, odata); label->base = &name->ndata[offsets[n]]; - if (n == name->labels - 1) + if (n == name->labels - 1) { label->length = name->length - offsets[n]; - else + } else { label->length = offsets[n + 1] - offsets[n]; + } } void @@ -912,9 +953,9 @@ dns_name_getlabelsequence(const dns_name_t *source, unsigned int first, firstoffset = (unsigned int)(p - source->ndata); } - if (ISC_LIKELY(first + n == source->labels)) + if (ISC_LIKELY(first + n == source->labels)) { endoffset = source->length; - else { + } else { for (i = 0; i < n; i++) { l = *p; p += l + 1; @@ -926,10 +967,11 @@ dns_name_getlabelsequence(const dns_name_t *source, unsigned int first, target->length = endoffset - firstoffset; if (first + n == source->labels && n > 0 && - (source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + (source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { target->attributes |= DNS_NAMEATTR_ABSOLUTE; - else + } else { target->attributes &= ~DNS_NAMEATTR_ABSOLUTE; + } target->labels = n; @@ -938,8 +980,9 @@ dns_name_getlabelsequence(const dns_name_t *source, unsigned int first, * a prefix of source, the offsets table is correct already * so we don't need to call set_offsets(). */ - if (target->offsets != NULL && (target != source || first != 0)) + if (target->offsets != NULL && (target != source || first != 0)) { set_offsets(target, target->offsets, NULL); + } } void @@ -961,11 +1004,12 @@ dns_name_clone(const dns_name_t *source, dns_name_t *target) (unsigned int)~(DNS_NAMEATTR_READONLY | DNS_NAMEATTR_DYNAMIC | DNS_NAMEATTR_DYNOFFSETS); if (target->offsets != NULL && source->labels > 0) { - if (source->offsets != NULL) + if (source->offsets != NULL) { memmove(target->offsets, source->offsets, source->labels); - else + } else { set_offsets(target, target->offsets, NULL); + } } } @@ -991,10 +1035,12 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) isc_buffer_clear(name->buffer); isc_buffer_availableregion(name->buffer, &r2); len = (r->length < r2.length) ? r->length : r2.length; - if (len > DNS_NAME_MAXWIRE) + if (len > DNS_NAME_MAXWIRE) { len = DNS_NAME_MAXWIRE; - if (len != 0) + } + if (len != 0) { memmove(r2.base, r->base, len); + } name->ndata = r2.base; name->length = len; } else { @@ -1004,15 +1050,16 @@ dns_name_fromregion(dns_name_t *name, const isc_region_t *r) : DNS_NAME_MAXWIRE; } - if (r->length > 0) + if (r->length > 0) { set_offsets(name, offsets, name); - else { + } else { name->labels = 0; name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; } - if (name->buffer != NULL) + if (name->buffer != NULL) { isc_buffer_add(name->buffer, name->length); + } } void @@ -1085,8 +1132,9 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, tused = 0; ndata = isc_buffer_used(target); nrem = isc_buffer_availablelength(target); - if (nrem > 255) + if (nrem > 255) { nrem = 255; + } nused = 0; labels = 0; done = false; @@ -1103,8 +1151,9 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, * Is this the root name? */ if (c == '.') { - if (tlen != 0) + if (tlen != 0) { return (DNS_R_EMPTYLABEL); + } labels++; *ndata++ = 0; nrem--; @@ -1117,7 +1166,7 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, break; } - /* FALLTHROUGH */ + /* FALLTHROUGH */ case ft_start: label = ndata; ndata++; @@ -1129,13 +1178,15 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, break; } state = ft_ordinary; - if (nrem == 0) + if (nrem == 0) { return (ISC_R_NOSPACE); - /* FALLTHROUGH */ + } + /* FALLTHROUGH */ case ft_ordinary: if (c == '.') { - if (count == 0) + if (count == 0) { return (DNS_R_EMPTYLABEL); + } *label = count; labels++; INSIST(labels <= 127); @@ -1151,12 +1202,14 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, } else if (c == '\\') { state = ft_escape; } else { - if (count >= 63) + if (count >= 63) { return (DNS_R_LABELTOOLONG); + } count++; CONVERTTOASCII(c); - if (downcase) + if (downcase) { c = maptolower[c & 0xff]; + } *ndata++ = c; nrem--; nused++; @@ -1172,15 +1225,17 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, } state = ft_escape; POST(state); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case ft_escape: if (!isdigit(c & 0xff)) { - if (count >= 63) + if (count >= 63) { return (DNS_R_LABELTOOLONG); + } count++; CONVERTTOASCII(c); - if (downcase) + if (downcase) { c = maptolower[c & 0xff]; + } *ndata++ = c; nrem--; nused++; @@ -1190,21 +1245,25 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, digits = 0; value = 0; state = ft_escdecimal; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case ft_escdecimal: - if (!isdigit(c & 0xff)) + if (!isdigit(c & 0xff)) { return (DNS_R_BADESCAPE); + } value *= 10; value += digitvalue[c & 0xff]; digits++; if (digits == 3) { - if (value > 255) + if (value > 255) { return (DNS_R_BADESCAPE); - if (count >= 63) + } + if (count >= 63) { return (DNS_R_LABELTOOLONG); + } count++; - if (downcase) + if (downcase) { value = maptolower[value]; + } *ndata++ = value; nrem--; nused++; @@ -1219,11 +1278,13 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, } if (!done) { - if (nrem == 0) + if (nrem == 0) { return (ISC_R_NOSPACE); + } INSIST(tlen == 0); - if (state != ft_ordinary && state != ft_at) + if (state != ft_ordinary && state != ft_at) { return (ISC_R_UNEXPECTEDEND); + } if (state == ft_ordinary) { INSIST(count != 0); *label = count; @@ -1232,8 +1293,9 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, offsets[labels] = nused; } if (origin != NULL) { - if (nrem < origin->length) + if (nrem < origin->length) { return (ISC_R_NOSPACE); + } label = origin->ndata; n1 = origin->length; nrem -= n1; @@ -1246,8 +1308,9 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, nused += n2 + 1; while (n2 > 0) { c = *label++; - if (downcase) + if (downcase) { c = maptolower[c & 0xff]; + } *ndata++ = c; n2--; } @@ -1257,11 +1320,13 @@ dns_name_fromtext(dns_name_t *name, isc_buffer_t *source, offsets[labels] = nused; } } - if ((origin->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((origin->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { name->attributes |= DNS_NAMEATTR_ABSOLUTE; + } } - } else + } else { name->attributes |= DNS_NAMEATTR_ABSOLUTE; + } name->ndata = (unsigned char *)target->base + target->used; name->labels = labels; @@ -1279,8 +1344,9 @@ dns_name_totext(const dns_name_t *name, bool omit_final_dot, { unsigned int options = DNS_NAME_MASTERFILE; - if (omit_final_dot) + if (omit_final_dot) { options |= DNS_NAME_OMITFINALDOT; + } return (dns_name_totext2(name, options, target)); } @@ -1325,8 +1391,9 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, /* * Special handling for an empty name. */ - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } /* * The names of these booleans are misleading in this case. @@ -1348,8 +1415,9 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, /* * Special handling for the root label. */ - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } saw_root = true; omit_final_dot = false; @@ -1379,17 +1447,19 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, case 0x40: /* '@' */ case 0x24: /* '$' */ if ((options & DNS_NAME_MASTERFILE) == - 0) + 0) { goto no_escape; - /* FALLTHROUGH */ + } + /* FALLTHROUGH */ case 0x22: /* '"' */ case 0x28: /* '(' */ case 0x29: /* ')' */ case 0x2E: /* '.' */ case 0x3B: /* ';' */ case 0x5C: /* '\\' */ - if (trem < 2) + if (trem < 2) { return (ISC_R_NOSPACE); + } *tdata++ = '\\'; CONVERTFROMASCII(c); *tdata++ = c; @@ -1400,16 +1470,18 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, no_escape: default: if (c > 0x20 && c < 0x7f) { - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } CONVERTFROMASCII(c); *tdata++ = c; ndata++; trem--; nlen--; } else { - if (trem < 4) + if (trem < 4) { return (ISC_R_NOSPACE); + } *tdata++ = 0x5c; *tdata++ = 0x30 + ((c / 100) % 10); @@ -1435,14 +1507,16 @@ dns_name_totext2(const dns_name_t *name, unsigned int options, * cases one more byte of text buffer is required than is * needed in the final output. */ - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } *tdata++ = '.'; trem--; } - if (nlen != 0 && trem == 0) + if (nlen != 0 && trem == 0) { return (ISC_R_NOSPACE); + } if (!saw_root || omit_final_dot) { trem++; @@ -1491,8 +1565,9 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot, /* * Special handling for the root label. */ - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } omit_final_dot = false; *tdata++ = '.'; @@ -1508,8 +1583,9 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot, labels--; count = *ndata++; nlen--; - if (count == 0) + if (count == 0) { break; + } if (count < 64) { INSIST(nlen >= count); while (count > 0) { @@ -1520,19 +1596,22 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot, c == 0x2D || /* hyphen */ c == 0x5F) /* underscore */ { - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } /* downcase */ - if (c >= 0x41 && c <= 0x5A) + if (c >= 0x41 && c <= 0x5A) { c += 0x20; + } CONVERTFROMASCII(c); *tdata++ = c; ndata++; trem--; nlen--; } else { - if (trem < 4) + if (trem < 4) { return (ISC_R_NOSPACE); + } snprintf(tdata, trem, "%%%02X", c); tdata += 3; trem -= 3; @@ -1553,17 +1632,20 @@ dns_name_tofilenametext(const dns_name_t *name, bool omit_final_dot, * cases one more byte of text buffer is required than is * needed in the final output. */ - if (trem == 0) + if (trem == 0) { return (ISC_R_NOSPACE); + } *tdata++ = '.'; trem--; } - if (nlen != 0 && trem == 0) + if (nlen != 0 && trem == 0) { return (ISC_R_NOSPACE); + } - if (omit_final_dot) + if (omit_final_dot) { trem++; + } isc_buffer_add(target, tlen - trem); @@ -1632,12 +1714,14 @@ dns_name_downcase(const dns_name_t *source, dns_name_t *name, if (source != name) { name->labels = source->labels; name->length = source->length; - if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { name->attributes = DNS_NAMEATTR_ABSOLUTE; - else + } else { name->attributes = 0; - if (name->labels > 0 && name->offsets != NULL) + } + if (name->labels > 0 && name->offsets != NULL) { set_offsets(name, name->offsets, NULL); + } } isc_buffer_add(target, name->length); @@ -1676,10 +1760,11 @@ set_offsets(const dns_name_t *name, unsigned char *offsets, set_name->labels = nlabels; set_name->length = offset; - if (absolute) + if (absolute) { set_name->attributes |= DNS_NAMEATTR_ABSOLUTE; - else + } else { set_name->attributes &= ~DNS_NAMEATTR_ABSOLUTE; + } } INSIST(nlabels == name->labels); INSIST(offset == name->length); @@ -1752,8 +1837,9 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, * maximum legal domain name length (255). */ nmax = isc_buffer_availablelength(target); - if (nmax > DNS_NAME_MAXWIRE) + if (nmax > DNS_NAME_MAXWIRE) { nmax = DNS_NAME_MAXWIRE; + } cdata = isc_buffer_current(source); cused = 0; @@ -1769,20 +1855,23 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, while (current < source->active && !done) { c = *cdata++; current++; - if (!seen_pointer) + if (!seen_pointer) { cused++; + } switch (state) { case fw_start: if (c < 64) { offsets[labels] = nused; labels++; - if (nused + c + 1 > nmax) + if (nused + c + 1 > nmax) { goto full; + } nused += c + 1; *ndata++ = c; - if (c == 0) + if (c == 0) { done = true; + } n = c; state = fw_ordinary; } else if (c >= 128 && c < 192) { @@ -1802,22 +1891,26 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, } new_current = c & 0x3F; state = fw_newcurrent; - } else + } else { return (DNS_R_BADLABELTYPE); + } break; case fw_ordinary: - if (downcase) + if (downcase) { c = maptolower[c]; + } *ndata++ = c; n--; - if (n == 0) + if (n == 0) { state = fw_start; + } break; case fw_newcurrent: new_current *= 256; new_current += c; - if (new_current >= biggest_pointer) + if (new_current >= biggest_pointer) { return (DNS_R_BADPOINTER); + } biggest_pointer = new_current; current = new_current; cdata = (unsigned char *)source->base + current; @@ -1831,8 +1924,9 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, } } - if (!done) + if (!done) { return (ISC_R_UNEXPECTEDEND); + } name->ndata = (unsigned char *)target->base + target->used; name->labels = labels; @@ -1845,18 +1939,19 @@ dns_name_fromwire(dns_name_t *name, isc_buffer_t *source, return (ISC_R_SUCCESS); full: - if (nmax == DNS_NAME_MAXWIRE) + if (nmax == DNS_NAME_MAXWIRE) { /* * The name did not fit even though we had a buffer * big enough to fit a maximum-length name. */ return (DNS_R_NAMETOOLONG); - else + } else { /* * The name might fit if only the caller could give us a * big enough buffer. */ return (ISC_R_NOSPACE); + } } isc_result_t @@ -1896,8 +1991,9 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, if (comp_offsetp != NULL && *comp_offsetp < 0x4000 && (name->attributes & DNS_NAMEATTR_NOCOMPRESS) == 0 && (methods & DNS_COMPRESS_GLOBAL14) != 0) { - if (ISC_UNLIKELY(target->length - target->used < 2)) + if (ISC_UNLIKELY(target->length - target->used < 2)) { return (ISC_R_NOSPACE); + } offset = *comp_offsetp; offset |= 0xc000; isc_buffer_putuint16(target, offset); @@ -1912,7 +2008,9 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, #if defined(__clang__) && \ (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)) memset(&clname, 0, sizeof(clname)); -#endif +#endif /* if defined(__clang__) && (__clang_major__ < 3 || (__clang_major__ == \ + * 3 \ + * && __clang_minor__ < 2)) */ DNS_NAME_INIT(&clname, clo); dns_name_clone(name, &clname); name = &clname; @@ -1922,46 +2020,54 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, offset = target->used; /*XXX*/ if ((name->attributes & DNS_NAMEATTR_NOCOMPRESS) == 0 && - (methods & DNS_COMPRESS_GLOBAL14) != 0) + (methods & DNS_COMPRESS_GLOBAL14) != 0) { gf = dns_compress_findglobal(cctx, name, &gp, &go); - else + } else { gf = false; + } /* * If the offset is too high for 14 bit global compression, we're * out of luck. */ - if (gf && ISC_UNLIKELY(go >= 0x4000)) + if (gf && ISC_UNLIKELY(go >= 0x4000)) { gf = false; + } /* * Will the compression pointer reduce the message size? */ - if (gf && (gp.length + 2) >= name->length) + if (gf && (gp.length + 2) >= name->length) { gf = false; + } if (gf) { - if (ISC_UNLIKELY(target->length - target->used < gp.length)) + if (ISC_UNLIKELY(target->length - target->used < gp.length)) { return (ISC_R_NOSPACE); + } if (gp.length != 0) { unsigned char *base = target->base; (void)memmove(base + target->used, gp.ndata, (size_t)gp.length); } isc_buffer_add(target, gp.length); - if (ISC_UNLIKELY(target->length - target->used < 2)) + if (ISC_UNLIKELY(target->length - target->used < 2)) { return (ISC_R_NOSPACE); + } isc_buffer_putuint16(target, go | 0xc000); if (gp.length != 0) { dns_compress_add(cctx, name, &gp, offset); - if (comp_offsetp != NULL) + if (comp_offsetp != NULL) { *comp_offsetp = offset; + } } else if (comp_offsetp != NULL) { *comp_offsetp = go; } } else { - if (ISC_UNLIKELY(target->length - target->used < name->length)) + if (ISC_UNLIKELY(target->length - target->used < + name->length)) { return (ISC_R_NOSPACE); + } if (name->length != 0) { unsigned char *base = target->base; (void)memmove(base + target->used, name->ndata, @@ -1969,8 +2075,9 @@ dns_name_towire2(const dns_name_t *name, dns_compress_t *cctx, } isc_buffer_add(target, name->length); dns_compress_add(cctx, name, name, offset); - if (comp_offsetp != NULL) + if (comp_offsetp != NULL) { *comp_offsetp = offset; + } } return (ISC_R_SUCCESS); @@ -1998,10 +2105,12 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix, REQUIRE((target != NULL && ISC_BUFFER_VALID(target)) || (target == NULL && name != NULL && ISC_BUFFER_VALID(name->buffer))); - if (prefix == NULL || prefix->labels == 0) + if (prefix == NULL || prefix->labels == 0) { copy_prefix = false; - if (suffix == NULL || suffix->labels == 0) + } + if (suffix == NULL || suffix->labels == 0) { copy_suffix = false; + } if (copy_prefix && (prefix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { absolute = true; REQUIRE(!copy_suffix); @@ -2023,8 +2132,9 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix, */ nrem = target->length - target->used; ndata = (unsigned char *)target->base + target->used; - if (nrem > DNS_NAME_MAXWIRE) + if (nrem > DNS_NAME_MAXWIRE) { nrem = DNS_NAME_MAXWIRE; + } length = 0; prefix_length = 0; labels = 0; @@ -2047,8 +2157,9 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix, } if (copy_suffix) { - if ((suffix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((suffix->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { absolute = true; + } memmove(ndata + prefix_length, suffix->ndata, suffix->length); } @@ -2057,16 +2168,18 @@ dns_name_concatenate(const dns_name_t *prefix, const dns_name_t *suffix, * a dedicated buffer, and we're using it, then we don't have to * copy anything. */ - if (copy_prefix && (prefix != name || prefix->buffer != target)) + if (copy_prefix && (prefix != name || prefix->buffer != target)) { memmove(ndata, prefix->ndata, prefix_length); + } name->ndata = ndata; name->labels = labels; name->length = length; - if (absolute) + if (absolute) { name->attributes = DNS_NAMEATTR_ABSOLUTE; - else + } else { name->attributes = 0; + } if (name->labels > 0 && name->offsets != NULL) { INIT_OFFSETS(name, offsets, odata); @@ -2094,12 +2207,14 @@ dns_name_split(const dns_name_t *name, unsigned int suffixlabels, splitlabel = name->labels - suffixlabels; - if (prefix != NULL) + if (prefix != NULL) { dns_name_getlabelsequence(name, 0, splitlabel, prefix); + } - if (suffix != NULL) + if (suffix != NULL) { dns_name_getlabelsequence(name, splitlabel, suffixlabels, suffix); + } return; } @@ -2128,14 +2243,16 @@ dns_name_dup(const dns_name_t *source, isc_mem_t *mctx, dns_name_t *target) target->length = source->length; target->labels = source->labels; target->attributes = DNS_NAMEATTR_DYNAMIC; - if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { target->attributes |= DNS_NAMEATTR_ABSOLUTE; + } if (target->offsets != NULL) { - if (source->offsets != NULL) + if (source->offsets != NULL) { memmove(target->offsets, source->offsets, source->labels); - else + } else { set_offsets(target, target->offsets, NULL); + } } } @@ -2167,13 +2284,15 @@ dns_name_dupwithoffsets(const dns_name_t *source, isc_mem_t *mctx, target->labels = source->labels; target->attributes = DNS_NAMEATTR_DYNAMIC | DNS_NAMEATTR_DYNOFFSETS | DNS_NAMEATTR_READONLY; - if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) + if ((source->attributes & DNS_NAMEATTR_ABSOLUTE) != 0) { target->attributes |= DNS_NAMEATTR_ABSOLUTE; + } target->offsets = target->ndata + source->length; - if (source->offsets != NULL) + if (source->offsets != NULL) { memmove(target->offsets, source->offsets, source->labels); - else + } else { set_offsets(target, target->offsets, NULL); + } return (ISC_R_SUCCESS); } @@ -2191,8 +2310,9 @@ dns_name_free(dns_name_t *name, isc_mem_t *mctx) REQUIRE((name->attributes & DNS_NAMEATTR_DYNAMIC) != 0); size = name->length; - if ((name->attributes & DNS_NAMEATTR_DYNOFFSETS) != 0) + if ((name->attributes & DNS_NAMEATTR_DYNOFFSETS) != 0) { size += name->labels; + } isc_mem_put(mctx, name->ndata, size); dns_name_invalidate(name); } @@ -2216,14 +2336,17 @@ dns_name_digest(const dns_name_t *name, dns_digestfunc_t digest, void *arg) #if defined(__clang__) && \ (__clang_major__ < 3 || (__clang_major__ == 3 && __clang_minor__ < 2)) memset(&downname, 0, sizeof(downname)); -#endif +#endif /* if defined(__clang__) && (__clang_major__ < 3 || (__clang_major__ == \ + * 3 \ + * && __clang_minor__ < 2)) */ DNS_NAME_INIT(&downname, NULL); isc_buffer_init(&buffer, data, sizeof(data)); result = dns_name_downcase(name, &downname, &buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_usedregion(&buffer, &r); @@ -2258,8 +2381,9 @@ dns_name_print(const dns_name_t *name, FILE *stream) isc_buffer_init(&b, t, sizeof(t)); result = dns_name_totext(name, false, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_usedregion(&b, &r); fprintf(stream, "%.*s", (int)r.length, (char *)r.base); @@ -2324,8 +2448,9 @@ dns_name_tostring(const dns_name_t *name, char **target, isc_mem_t *mctx) isc_buffer_init(&buf, txt, sizeof(txt)); result = dns_name_totext(name, false, &buf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_usedregion(&buf, ®); p = isc_mem_allocate(mctx, reg.length + 1); @@ -2361,18 +2486,20 @@ dns_name_fromstring2(dns_name_t *target, const char *src, isc_buffer_constinit(&buf, src, strlen(src)); isc_buffer_add(&buf, strlen(src)); - if (BINDABLE(target) && target->buffer != NULL) + if (BINDABLE(target) && target->buffer != NULL) { name = target; - else { + } else { name = dns_fixedname_initname(&fn); } result = dns_name_fromtext(name, &buf, origin, options, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (name != target) + if (name != target) { result = dns_name_dupwithoffsets(name, mctx, target); + } return (result); } @@ -2586,8 +2713,9 @@ dns_name_istat(const dns_name_t *name) REQUIRE(VALID_NAME(name)); - if (name->labels < 1) + if (name->labels < 1) { return (false); + } ndata = name->ndata; len = ndata[0]; diff --git a/lib/dns/ncache.c b/lib/dns/ncache.c index 2e972dfca6..8ec36ab10a 100644 --- a/lib/dns/ncache.c +++ b/lib/dns/ncache.c @@ -58,8 +58,9 @@ copy_rdataset(dns_rdataset_t *rdataset, isc_buffer_t *buffer) * Copy the rdataset count to the buffer. */ isc_buffer_availableregion(buffer, &ar); - if (ar.length < 2) + if (ar.length < 2) { return (ISC_R_NOSPACE); + } count = dns_rdataset_count(rdataset); INSIST(count <= 65535); isc_buffer_putuint16(buffer, (uint16_t)count); @@ -70,8 +71,9 @@ copy_rdataset(dns_rdataset_t *rdataset, isc_buffer_t *buffer) dns_rdata_toregion(&rdata, &r); INSIST(r.length <= 65535); isc_buffer_availableregion(buffer, &ar); - if (ar.length < 2) + if (ar.length < 2) { return (ISC_R_NOSPACE); + } /* * Copy the rdata length to the buffer. */ @@ -80,13 +82,15 @@ copy_rdataset(dns_rdataset_t *rdataset, isc_buffer_t *buffer) * Copy the rdata to the buffer. */ result = isc_buffer_copyregion(buffer, &r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdata_reset(&rdata); result = dns_rdataset_next(rdataset); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } return (ISC_R_SUCCESS); } @@ -156,10 +160,11 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, ttl = maxttl; trust = 0xffff; isc_buffer_init(&buffer, data, sizeof(data)); - if (message->counts[DNS_SECTION_AUTHORITY]) + if (message->counts[DNS_SECTION_AUTHORITY]) { result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); - else + } else { result = ISC_R_NOMORE; + } while (result == ISC_R_SUCCESS) { name = NULL; dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name); @@ -168,11 +173,13 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { if ((rdataset->attributes & - DNS_RDATASETATTR_NCACHE) == 0) + DNS_RDATASETATTR_NCACHE) == 0) { continue; + } type = rdataset->type; - if (type == dns_rdatatype_rrsig) + if (type == dns_rdatatype_rrsig) { type = rdataset->covers; + } if (type == dns_rdatatype_soa || type == dns_rdatatype_nsec || type == dns_rdatatype_nsec3) { @@ -191,14 +198,16 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, dns_name_toregion(name, &r); result = isc_buffer_copyregion(&buffer, &r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Copy the type to the buffer. */ isc_buffer_availableregion(&buffer, &r); - if (r.length < 3) + if (r.length < 3) { return (ISC_R_NOSPACE); + } isc_buffer_putuint16(&buffer, rdataset->type); isc_buffer_putuint8( @@ -209,11 +218,13 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, */ result = copy_rdataset(rdataset, &buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (next >= DNS_NCACHE_RDATA) + if (next >= DNS_NCACHE_RDATA) { return (ISC_R_NOSPACE); + } dns_rdata_init(&rdata[next]); isc_buffer_remainingregion(&buffer, &r); rdata[next].data = r.base; @@ -231,8 +242,9 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, } result = dns_message_nextname(message, DNS_SECTION_AUTHORITY); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } if (trust == 0xffff) { if ((message->flags & DNS_MESSAGEFLAG_AA) != 0 && @@ -242,8 +254,9 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, * any CNAME or DNAME chains. */ trust = dns_trust_authauthority; - } else + } else { trust = dns_trust_additional; + } ttl = 0; } @@ -254,14 +267,17 @@ addoptout(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, dns_rdataset_init(&ncrdataset); RUNTIME_CHECK(dns_rdatalist_tordataset(&ncrdatalist, &ncrdataset) == ISC_R_SUCCESS); - if (!secure && trust > dns_trust_answer) + if (!secure && trust > dns_trust_answer) { trust = dns_trust_answer; + } ncrdataset.trust = trust; ncrdataset.attributes |= DNS_RDATASETATTR_NEGATIVE; - if (message->rcode == dns_rcode_nxdomain) + if (message->rcode == dns_rcode_nxdomain) { ncrdataset.attributes |= DNS_RDATASETATTR_NXDOMAIN; - if (optout) + } + if (optout) { ncrdataset.attributes |= DNS_RDATASETATTR_OPTOUT; + } return (dns_db_addrdataset(cache, node, NULL, now, &ncrdataset, 0, addedrdataset)); @@ -327,16 +343,18 @@ dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx, isc_buffer_forward(&source, rdata.length); if ((options & DNS_NCACHETOWIRE_OMITDNSSEC) != 0 && - dns_rdatatype_isdnssec(type)) + dns_rdatatype_isdnssec(type)) { continue; + } /* * Write the name. */ dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); result = dns_name_towire(&name, cctx, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto rollback; + } /* * See if we have space for type, class, ttl, and @@ -361,8 +379,9 @@ dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx, * Write the rdata. */ result = dns_rdata_towire(&rdata, cctx, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto rollback; + } /* * Set the rdata length field to the compressed @@ -380,8 +399,9 @@ dns_ncache_towire(dns_rdataset_t *rdataset, dns_compress_t *cctx, result = dns_rdataset_next(rdataset); dns_rdata_reset(&rdata); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto rollback; + } *countp = count; @@ -434,8 +454,9 @@ rdataset_next(dns_rdataset_t *rdataset) unsigned char *raw; count = rdataset->privateuint4; - if (count == 0) + if (count == 0) { return (ISC_R_NOMORE); + } count--; rdataset->privateuint4 = count; raw = rdataset->private5; @@ -557,10 +578,12 @@ dns_ncache_getrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name, dns_rdata_reset(&rdata); } dns_rdataset_disassociate(&rclone); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { return (ISC_R_NOTFOUND); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } INSIST(remaining.length != 0); @@ -656,10 +679,12 @@ dns_ncache_getsigrdataset(dns_rdataset_t *ncacherdataset, dns_name_t *name, dns_rdata_reset(&rdata); } dns_rdataset_disassociate(&rclone); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { return (ISC_R_NOTFOUND); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } INSIST(remaining.length != 0); @@ -739,8 +764,9 @@ dns_ncache_current(dns_rdataset_t *ncacherdataset, dns_name_t *found, &sigregion); (void)dns_rdata_tostruct(&rdata, &rrsig, NULL); rdataset->covers = rrsig.covered; - } else + } else { rdataset->covers = 0; + } rdataset->ttl = ncacherdataset->ttl; rdataset->trust = trust; rdataset->private1 = NULL; diff --git a/lib/dns/nsec.c b/lib/dns/nsec.c index 00413feab7..66484f3e8d 100644 --- a/lib/dns/nsec.c +++ b/lib/dns/nsec.c @@ -43,10 +43,11 @@ dns_nsec_setbit(unsigned char *array, unsigned int type, unsigned int bit) shift = 7 - (type % 8); mask = 1 << shift; - if (bit != 0) + if (bit != 0) { array[type / 8] |= mask; - else + } else { array[type / 8] &= (~mask & 0xFF); + } } bool @@ -69,12 +70,14 @@ dns_nsec_compressbitmap(unsigned char *map, const unsigned char *raw, unsigned int window; int octet; - if (raw == NULL) + if (raw == NULL) { return (0); + } for (window = 0; window < 256; window++) { - if (window * 256 > max_type) + if (window * 256 > max_type) { break; + } for (octet = 31; octet >= 0; octet--) { if (*(raw + octet) != 0) { break; @@ -93,7 +96,7 @@ dns_nsec_compressbitmap(unsigned char *map, const unsigned char *raw, map += octet + 1; raw += 32; } - return (unsigned int)(map - start); + return ((unsigned int)(map - start)); } isc_result_t @@ -128,16 +131,18 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, dns_rdataset_init(&rdataset); rdsiter = NULL; result = dns_db_allrdatasets(db, node, version, 0, &rdsiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(rdsiter)) { dns_rdatasetiter_current(rdsiter, &rdataset); if (rdataset.type != dns_rdatatype_nsec && rdataset.type != dns_rdatatype_nsec3 && rdataset.type != dns_rdatatype_rrsig) { - if (rdataset.type > max_type) + if (rdataset.type > max_type) { max_type = rdataset.type; + } dns_nsec_setbit(bm, rdataset.type, 1); } dns_rdataset_disassociate(&rdataset); @@ -150,14 +155,16 @@ dns_nsec_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, !dns_nsec_isset(bm, dns_rdatatype_soa)) { for (i = 0; i <= max_type; i++) { if (dns_nsec_isset(bm, i) && - !dns_rdatatype_iszonecutauth((dns_rdatatype_t)i)) + !dns_rdatatype_iszonecutauth((dns_rdatatype_t)i)) { dns_nsec_setbit(bm, i, 0); + } } } dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } nsec_bits += dns_nsec_compressbitmap(nsec_bits, bm, max_type); @@ -190,12 +197,14 @@ dns_nsec_build(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, ISC_LIST_APPEND(rdatalist.rdata, &rdata, link); RETERR(dns_rdatalist_tordataset(&rdatalist, &rdataset)); result = dns_db_addrdataset(db, node, version, 0, &rdataset, 0, NULL); - if (result == DNS_R_UNCHANGED) + if (result == DNS_R_UNCHANGED) { result = ISC_R_SUCCESS; + } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -251,17 +260,20 @@ dns_nsec_nseconly(dns_db_t *db, dns_dbversion_t *version, bool *answer) dns_rdataset_init(&rdataset); result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_findrdataset(db, node, version, dns_rdatatype_dnskey, 0, 0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { *answer = false; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { dns_rdata_t rdata = DNS_RDATA_INIT; @@ -271,12 +283,14 @@ dns_nsec_nseconly(dns_db_t *db, dns_dbversion_t *version, bool *answer) RUNTIME_CHECK(result == ISC_R_SUCCESS); if (dnskey.algorithm == DST_ALG_RSAMD5 || - dnskey.algorithm == DST_ALG_RSASHA1) + dnskey.algorithm == DST_ALG_RSASHA1) { break; + } } dns_rdataset_disassociate(&rdataset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *answer = true; + } if (result == ISC_R_NOMORE) { *answer = false; result = ISC_R_SUCCESS; @@ -392,8 +406,9 @@ dns_nsec_noexistnodata(dns_rdatatype_t type, const dns_name_t *name, } result = dns_rdata_tostruct(&rdata, &nsec, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } relation = dns_name_fullcompare(&nsec.next, name, &order, &nlabels); if (order == 0) { dns_rdata_freestruct(&nsec); diff --git a/lib/dns/nsec3.c b/lib/dns/nsec3.c index b2c0239127..294b2847e7 100644 --- a/lib/dns/nsec3.c +++ b/lib/dns/nsec3.c @@ -112,13 +112,15 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, bm = r.base + r.length + 512; nsec_bits = r.base + r.length; max_type = 0; - if (node == NULL) + if (node == NULL) { goto collapse_bitmap; + } dns_rdataset_init(&rdataset); rdsiter = NULL; result = dns_db_allrdatasets(db, node, version, 0, &rdsiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } found = found_ns = need_rrsig = false; for (result = dns_rdatasetiter_first(rdsiter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(rdsiter)) { @@ -126,8 +128,9 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, if (rdataset.type != dns_rdatatype_nsec && rdataset.type != dns_rdatatype_nsec3 && rdataset.type != dns_rdatatype_rrsig) { - if (rdataset.type > max_type) + if (rdataset.type > max_type) { max_type = rdataset.type; + } dns_nsec_setbit(bm, rdataset.type, 1); /* * Work out if we need to set the RRSIG bit for @@ -139,18 +142,20 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, * a NS record but do have other data. */ if (rdataset.type == dns_rdatatype_soa || - rdataset.type == dns_rdatatype_ds) + rdataset.type == dns_rdatatype_ds) { need_rrsig = true; - else if (rdataset.type == dns_rdatatype_ns) + } else if (rdataset.type == dns_rdatatype_ns) { found_ns = true; - else + } else { found = true; + } } dns_rdataset_disassociate(&rdataset); } if ((found && !found_ns) || need_rrsig) { - if (dns_rdatatype_rrsig > max_type) + if (dns_rdatatype_rrsig > max_type) { max_type = dns_rdatatype_rrsig; + } dns_nsec_setbit(bm, dns_rdatatype_rrsig, 1); } @@ -161,14 +166,16 @@ dns_nsec3_buildrdata(dns_db_t *db, dns_dbversion_t *version, dns_dbnode_t *node, !dns_nsec_isset(bm, dns_rdatatype_soa)) { for (i = 0; i <= max_type; i++) { if (dns_nsec_isset(bm, i) && - !dns_rdatatype_iszonecutauth((dns_rdatatype_t)i)) + !dns_rdatatype_iszonecutauth((dns_rdatatype_t)i)) { dns_nsec_setbit(bm, i, 0); + } } } dns_rdatasetiter_destroy(&rdsiter); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } collapse_bitmap: nsec_bits += dns_nsec_compressbitmap(nsec_bits, bm, max_type); @@ -202,10 +209,12 @@ dns_nsec3_typepresent(dns_rdata_t *rdata, dns_rdatatype_t type) INSIST(len > 0 && len <= 32); i += 2; INSIST(i + len <= nsec3.len); - if (window * 256 > type) + if (window * 256 > type) { break; - if ((window + 1) * 256 <= type) + } + if ((window + 1) * 256 <= type) { continue; + } if (type < (window * 256) + len * 8) { present = dns_nsec_isset(&nsec3.typebits[i], type % 256); @@ -232,8 +241,9 @@ dns_nsec3_hashname(dns_fixedname_t *result, isc_region_t region; size_t len; - if (rethash == NULL) + if (rethash == NULL) { rethash = hash; + } memset(rethash, 0, NSEC3_MAX_HASH_LENGTH); @@ -244,11 +254,13 @@ dns_nsec3_hashname(dns_fixedname_t *result, len = isc_iterated_hash(rethash, hashalg, iterations, salt, (int)saltlength, downcased->ndata, downcased->length); - if (len == 0U) + if (len == 0U) { return (DNS_R_BADALG); + } - if (hash_length != NULL) + if (hash_length != NULL) { *hash_length = len; + } /* convert the hash to base32hex non-padded */ region.base = rethash; @@ -340,13 +352,15 @@ name_exists(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, *exists = false; return (ISC_R_SUCCESS); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_allrdatasets(db, node, version, (isc_stdtime_t)0, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } result = dns_rdatasetiter_first(iter); if (result == ISC_R_SUCCESS) { @@ -354,8 +368,9 @@ name_exists(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, } else if (result == ISC_R_NOMORE) { *exists = false; result = ISC_R_SUCCESS; - } else + } else { *exists = false; + } dns_rdatasetiter_destroy(&iter); cleanup_node: @@ -370,8 +385,9 @@ match_nsec3param(const dns_rdata_nsec3_t * nsec3, if (nsec3->hash == nsec3param->hash && nsec3->iterations == nsec3param->iterations && nsec3->salt_length == nsec3param->salt_length && - !memcmp(nsec3->salt, nsec3param->salt, nsec3->salt_length)) + !memcmp(nsec3->salt, nsec3param->salt, nsec3->salt_length)) { return (true); + } return (false); } @@ -390,10 +406,12 @@ delnsec3(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, isc_result_t result; result = dns_db_findnsec3node(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, version, dns_rdatatype_nsec3, 0, @@ -403,8 +421,9 @@ delnsec3(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, result = ISC_R_SUCCESS; goto cleanup_node; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -412,19 +431,23 @@ delnsec3(dns_db_t *db, dns_dbversion_t *version, const dns_name_t *name, dns_rdataset_current(&rdataset, &rdata); CHECK(dns_rdata_tostruct(&rdata, &nsec3, NULL)); - if (!match_nsec3param(&nsec3, nsec3param)) + if (!match_nsec3param(&nsec3, nsec3param)) { continue; + } result = dns_difftuple_create(diff->mctx, DNS_DIFFOP_DEL, name, rdataset.ttl, &rdata, &tuple); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } result = do_one_tuple(&tuple, db, version, diff); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } result = ISC_R_SUCCESS; failure: @@ -441,8 +464,9 @@ better_param(dns_rdataset_t *nsec3paramset, dns_rdata_t *param) dns_rdataset_t rdataset; isc_result_t result; - if (REMOVE(param->data[1])) + if (REMOVE(param->data[1])) { return (true); + } dns_rdataset_init(&rdataset); dns_rdataset_clone(nsec3paramset, &rdataset); @@ -455,19 +479,23 @@ better_param(dns_rdataset_t *nsec3paramset, dns_rdata_t *param) dns_rdata_t tmprdata = DNS_RDATA_INIT; dns_rdataset_current(&rdataset, &tmprdata); if (!dns_nsec3param_fromprivate(&tmprdata, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; - } else + } + } else { dns_rdataset_current(&rdataset, &rdata); + } - if (rdata.length != param->length) + if (rdata.length != param->length) { continue; + } if (rdata.data[0] != param->data[0] || REMOVE(rdata.data[1]) || rdata.data[2] != param->data[2] || rdata.data[3] != param->data[3] || rdata.data[4] != param->data[4] || - memcmp(&rdata.data[5], ¶m->data[5], param->data[4])) + memcmp(&rdata.data[5], ¶m->data[5], param->data[4])) { continue; + } if (CREATE(rdata.data[1]) && !CREATE(param->data[1])) { dns_rdataset_disassociate(&rdataset); return (true); @@ -489,8 +517,9 @@ find_nsec3(dns_rdata_nsec3_t *nsec3, dns_rdataset_t *rdataset, dns_rdataset_current(rdataset, &rdata); CHECK(dns_rdata_tostruct(&rdata, nsec3, NULL)); dns_rdata_reset(&rdata); - if (match_nsec3param(nsec3, nsec3param)) + if (match_nsec3param(nsec3, nsec3param)) { break; + } } failure: return (result); @@ -582,8 +611,9 @@ dns_nsec3_addnsec3(dns_db_t *db, dns_dbversion_t *version, if (result == ISC_R_SUCCESS) { result = find_nsec3(&nsec3, &rdataset, nsec3param); if (result == ISC_R_SUCCESS) { - if (!CREATE(nsec3param->flags)) + if (!CREATE(nsec3param->flags)) { flags = nsec3.flags; + } next_length = nsec3.next_length; INSIST(next_length <= sizeof(nexthash)); memmove(nexthash, nsec3.next, next_length); @@ -595,18 +625,20 @@ dns_nsec3_addnsec3(dns_db_t *db, dns_dbversion_t *version, * remove the NSEC3 record or not by examining the * previous NSEC3 record. */ - if (!unsecure) + if (!unsecure) { goto addnsec3; - else if (CREATE(nsec3param->flags) && OPTOUT(flags)) { + } else if (CREATE(nsec3param->flags) && OPTOUT(flags)) { result = dns_nsec3_delnsec3(db, version, name, nsec3param, diff); goto failure; - } else + } else { maybe_remove_unsecure = true; + } } else { dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } } } @@ -626,16 +658,18 @@ dns_nsec3_addnsec3(dns_db_t *db, dns_dbversion_t *version, dns_rdatatype_nsec3, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = find_nsec3(&nsec3, &rdataset, nsec3param); if (result == ISC_R_NOMORE) { dns_rdataset_disassociate(&rdataset); continue; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } if (maybe_remove_unsecure) { dns_rdataset_disassociate(&rdataset); @@ -683,8 +717,9 @@ dns_nsec3_addnsec3(dns_db_t *db, dns_dbversion_t *version, CHECK(do_one_tuple(&tuple, db, version, diff)); INSIST(old_length <= sizeof(nexthash)); memmove(nexthash, old_next, old_length); - if (!CREATE(nsec3param->flags)) + if (!CREATE(nsec3param->flags)) { flags = nsec3.flags; + } dns_rdata_reset(&rdata); dns_rdataset_disassociate(&rdataset); break; @@ -721,12 +756,14 @@ addnsec3: dns_name_clone(name, &empty); do { labels = dns_name_countlabels(&empty) - 1; - if (labels <= dns_name_countlabels(origin)) + if (labels <= dns_name_countlabels(origin)) { break; + } dns_name_getlabelsequence(&empty, 1, labels, &empty); CHECK(name_exists(db, version, &empty, &exists)); - if (exists) + if (exists) { break; + } CHECK(dns_nsec3_hashname(&fixed, nexthash, &next_length, &empty, origin, hash, iterations, salt, salt_length)); @@ -747,8 +784,9 @@ addnsec3: dns_db_detachnode(db, &newnode); break; } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } } /* @@ -768,15 +806,17 @@ addnsec3: db, node, version, dns_rdatatype_nsec3, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = find_nsec3(&nsec3, &rdataset, nsec3param); if (result == ISC_R_NOMORE) { dns_rdataset_disassociate(&rdataset); continue; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } old_next = nsec3.next; old_length = nsec3.next_length; @@ -801,8 +841,9 @@ addnsec3: CHECK(do_one_tuple(&tuple, db, version, diff)); INSIST(old_length <= sizeof(nexthash)); memmove(nexthash, old_next, old_length); - if (!CREATE(nsec3param->flags)) + if (!CREATE(nsec3param->flags)) { flags = nsec3.flags; + } dns_rdata_reset(&rdata); dns_rdataset_disassociate(&rdataset); break; @@ -836,14 +877,18 @@ addnsec3: INSIST(result != ISC_R_NOMORE); failure: - if (dbit != NULL) + if (dbit != NULL) { dns_dbiterator_destroy(&dbit); - if (dns_rdataset_isassociated(&rdataset)) + } + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); - if (newnode != NULL) + } + if (newnode != NULL) { dns_db_detachnode(db, &newnode); + } return (result); } @@ -867,17 +912,20 @@ dns_nsec3_addnsec3s(dns_db_t *db, dns_dbversion_t *version, * Find the NSEC3 parameters for this zone. */ result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_findrdataset(db, node, version, dns_rdatatype_nsec3param, 0, 0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } /* * Update each active NSEC3 chain. @@ -889,22 +937,26 @@ dns_nsec3_addnsec3s(dns_db_t *db, dns_dbversion_t *version, dns_rdataset_current(&rdataset, &rdata); CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); - if (nsec3param.flags != 0) + if (nsec3param.flags != 0) { continue; + } /* * We have a active chain. Update it. */ CHECK(dns_nsec3_addnsec3(db, version, name, &nsec3param, nsecttl, unsecure, diff)); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -922,8 +974,9 @@ dns_nsec3param_fromprivate(dns_rdata_t *src, dns_rdata_t *target, * Algorithm 0 (reserved by RFC 4034) is used to identify * NSEC3PARAM records from DNSKEY pointers. */ - if (src->length < 1 || src->data[0] != 0) + if (src->length < 1 || src->data[0] != 0) { return (false); + } isc_buffer_init(&buf1, src->data + 1, src->length - 1); isc_buffer_add(&buf1, src->length - 1); @@ -966,10 +1019,11 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, const dns_name_t *name, isc_result_t result; dns_rdataset_init(&rdataset); - if (rdata->type == dns_rdatatype_nsec3) + if (rdata->type == dns_rdatatype_nsec3) { CHECK(dns_db_findnsec3node(db, name, false, &node)); - else + } else { CHECK(dns_db_findnode(db, name, false, &node)); + } result = dns_db_findrdataset(db, node, ver, rdata->type, 0, (isc_stdtime_t)0, &rdataset, NULL); if (result == ISC_R_NOTFOUND) { @@ -982,8 +1036,9 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, const dns_name_t *name, result = dns_rdataset_next(&rdataset)) { dns_rdata_t myrdata = DNS_RDATA_INIT; dns_rdataset_current(&rdataset, &myrdata); - if (!dns_rdata_casecompare(&myrdata, rdata)) + if (!dns_rdata_casecompare(&myrdata, rdata)) { break; + } } dns_rdataset_disassociate(&rdataset); if (result == ISC_R_SUCCESS) { @@ -994,8 +1049,9 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, const dns_name_t *name, } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1054,18 +1110,21 @@ dns_nsec3param_deletechains(dns_db_t *db, dns_dbversion_t *ver, dns_rdataset_init(&rdataset); result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Cause all NSEC3 chains to be deleted. */ result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3param, 0, (isc_stdtime_t)0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto try_private; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -1081,8 +1140,9 @@ dns_nsec3param_deletechains(dns_db_t *db, dns_dbversion_t *ver, dns_nsec3param_toprivate(&rdata, &private, privatetype, buf, sizeof(buf)); buf[2] = DNS_NSEC3FLAG_REMOVE; - if (nonsec) + if (nonsec) { buf[2] |= DNS_NSEC3FLAG_NONSEC; + } CHECK(rr_exists(db, ver, origin, &private, &flag)); @@ -1095,20 +1155,24 @@ dns_nsec3param_deletechains(dns_db_t *db, dns_dbversion_t *ver, } dns_rdata_reset(&rdata); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } dns_rdataset_disassociate(&rdataset); try_private: - if (privatetype == 0) + if (privatetype == 0) { goto success; + } result = dns_db_findrdataset(db, node, ver, privatetype, 0, (isc_stdtime_t)0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -1123,8 +1187,9 @@ try_private: */ if (rdata.length < 6 || buf[0] != 0 || (buf[2] & DNS_NSEC3FLAG_REMOVE) != 0 || - (nonsec && (buf[2] & DNS_NSEC3FLAG_NONSEC) != 0)) + (nonsec && (buf[2] & DNS_NSEC3FLAG_NONSEC) != 0)) { continue; + } CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_DEL, origin, 0, &rdata, &tuple)); @@ -1133,8 +1198,9 @@ try_private: rdata.data = buf; buf[2] = DNS_NSEC3FLAG_REMOVE; - if (nonsec) + if (nonsec) { buf[2] |= DNS_NSEC3FLAG_NONSEC; + } CHECK(rr_exists(db, ver, origin, &rdata, &flag)); @@ -1145,14 +1211,16 @@ try_private: INSIST(tuple == NULL); } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } success: result = ISC_R_SUCCESS; failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } dns_db_detachnode(db, &node); return (result); } @@ -1175,21 +1243,25 @@ dns_nsec3_addnsec3sx(dns_db_t *db, dns_dbversion_t *version, * Find the NSEC3 parameters for this zone. */ result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_findrdataset(db, node, version, type, 0, 0, &prdataset, NULL); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto failure; + } result = dns_db_findrdataset(db, node, version, dns_rdatatype_nsec3param, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto try_private; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Update each active NSEC3 chain. @@ -1201,8 +1273,9 @@ dns_nsec3_addnsec3sx(dns_db_t *db, dns_dbversion_t *version, dns_rdataset_current(&rdataset, &rdata); CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); - if (nsec3param.flags != 0) + if (nsec3param.flags != 0) { continue; + } /* * We have a active chain. Update it. @@ -1210,14 +1283,16 @@ dns_nsec3_addnsec3sx(dns_db_t *db, dns_dbversion_t *version, CHECK(dns_nsec3_addnsec3(db, version, name, &nsec3param, nsecttl, unsecure, diff)); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } dns_rdataset_disassociate(&rdataset); try_private: - if (!dns_rdataset_isassociated(&prdataset)) + if (!dns_rdataset_isassociated(&prdataset)) { goto success; + } /* * Update each active NSEC3 chain. */ @@ -1229,14 +1304,17 @@ try_private: dns_rdataset_current(&prdataset, &rdata1); if (!dns_nsec3param_fromprivate(&rdata1, &rdata2, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } CHECK(dns_rdata_tostruct(&rdata2, &nsec3param, NULL)); - if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) + if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) { continue; - if (better_param(&prdataset, &rdata2)) + } + if (better_param(&prdataset, &rdata2)) { continue; + } /* * We have a active chain. Update it. @@ -1244,16 +1322,20 @@ try_private: CHECK(dns_nsec3_addnsec3(db, version, name, &nsec3param, nsecttl, unsecure, diff)); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { success: result = ISC_R_SUCCESS; + } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (dns_rdataset_isassociated(&prdataset)) + } + if (dns_rdataset_isassociated(&prdataset)) { dns_rdataset_disassociate(&prdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1349,20 +1431,24 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, CHECK(dns_db_createiterator(db, DNS_DB_NSEC3ONLY, &dbit)); result = dns_dbiterator_seek(dbit, hashname); - if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } CHECK(dns_dbiterator_current(dbit, &node, NULL)); CHECK(dns_dbiterator_pause(dbit)); result = dns_db_findrdataset(db, node, version, dns_rdatatype_nsec3, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } /* * If we find a existing NSEC3 for this chain then save the @@ -1375,10 +1461,12 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, memmove(nexthash, nsec3.next, next_length); } dns_rdataset_disassociate(&rdataset); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Find the previous NSEC3 and update it. @@ -1396,15 +1484,17 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, dns_rdatatype_nsec3, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = find_nsec3(&nsec3, &rdataset, nsec3param); if (result == ISC_R_NOMORE) { dns_rdataset_disassociate(&rdataset); continue; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Delete the old previous NSEC3. @@ -1416,8 +1506,9 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, */ nsec3.next = nexthash; nsec3.next_length = (unsigned char)next_length; - if (CREATE(nsec3param->flags)) + if (CREATE(nsec3param->flags)) { nsec3.flags = nsec3param->flags & DNS_NSEC3FLAG_OPTOUT; + } isc_buffer_init(&buffer, nsec3buf, sizeof(nsec3buf)); CHECK(dns_rdata_fromstruct(&rdata, rdataset.rdclass, dns_rdatatype_nsec3, &nsec3, @@ -1442,21 +1533,25 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, dns_name_clone(name, &empty); do { labels = dns_name_countlabels(&empty) - 1; - if (labels <= dns_name_countlabels(origin)) + if (labels <= dns_name_countlabels(origin)) { break; + } dns_name_getlabelsequence(&empty, 1, labels, &empty); CHECK(deleteit(db, version, &empty, &yesno)); - if (!yesno) + if (!yesno) { break; + } CHECK(dns_nsec3_hashname(&fixed, nexthash, &next_length, &empty, origin, hash, iterations, salt, salt_length)); result = dns_dbiterator_seek(dbit, hashname); - if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } CHECK(dns_dbiterator_current(dbit, &node, NULL)); CHECK(dns_dbiterator_pause(dbit)); @@ -1464,10 +1559,12 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, dns_rdatatype_nsec3, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } result = find_nsec3(&nsec3, &rdataset, nsec3param); if (result == ISC_R_SUCCESS) { @@ -1476,10 +1573,12 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, memmove(nexthash, nsec3.next, next_length); } dns_rdataset_disassociate(&rdataset); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } pass = 0; do { @@ -1494,15 +1593,17 @@ dns_nsec3_delnsec3(dns_db_t *db, dns_dbversion_t *version, db, node, version, dns_rdatatype_nsec3, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = find_nsec3(&nsec3, &rdataset, nsec3param); if (result == ISC_R_NOMORE) { dns_rdataset_disassociate(&rdataset); continue; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Delete the old previous NSEC3. @@ -1539,12 +1640,15 @@ success: result = ISC_R_SUCCESS; failure: - if (dbit != NULL) + if (dbit != NULL) { dns_dbiterator_destroy(&dbit); - if (dns_rdataset_isassociated(&rdataset)) + } + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1571,16 +1675,19 @@ dns_nsec3_delnsec3sx(dns_db_t *db, dns_dbversion_t *version, * Find the NSEC3 parameters for this zone. */ result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_findrdataset(db, node, version, dns_rdatatype_nsec3param, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto try_private; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Update each active NSEC3 chain. @@ -1592,8 +1699,9 @@ dns_nsec3_delnsec3sx(dns_db_t *db, dns_dbversion_t *version, dns_rdataset_current(&rdataset, &rdata); CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); - if (nsec3param.flags != 0) + if (nsec3param.flags != 0) { continue; + } /* * We have a active chain. Update it. */ @@ -1602,14 +1710,17 @@ dns_nsec3_delnsec3sx(dns_db_t *db, dns_dbversion_t *version, dns_rdataset_disassociate(&rdataset); try_private: - if (privatetype == 0) + if (privatetype == 0) { goto success; + } result = dns_db_findrdataset(db, node, version, privatetype, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Update each NSEC3 chain being built. @@ -1622,29 +1733,35 @@ try_private: dns_rdataset_current(&rdataset, &rdata1); if (!dns_nsec3param_fromprivate(&rdata1, &rdata2, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } CHECK(dns_rdata_tostruct(&rdata2, &nsec3param, NULL)); - if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) + if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) { continue; - if (better_param(&rdataset, &rdata2)) + } + if (better_param(&rdataset, &rdata2)) { continue; + } /* * We have a active chain. Update it. */ CHECK(dns_nsec3_delnsec3(db, version, name, &nsec3param, diff)); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { success: result = ISC_R_SUCCESS; + } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1670,15 +1787,17 @@ dns_nsec3_activex(dns_db_t *db, dns_dbversion_t *version, bool complete, dns_rdataset_init(&rdataset); result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_findrdataset(db, node, version, dns_rdatatype_nsec3param, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto try_private; + } if (result != ISC_R_SUCCESS) { dns_db_detachnode(db, &node); @@ -1692,8 +1811,9 @@ dns_nsec3_activex(dns_db_t *db, dns_dbversion_t *version, bool complete, result = dns_rdata_tostruct(&rdata, &nsec3param, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (nsec3param.flags == 0) + if (nsec3param.flags == 0) { break; + } } dns_rdataset_disassociate(&rdataset); if (result == ISC_R_SUCCESS) { @@ -1701,8 +1821,9 @@ dns_nsec3_activex(dns_db_t *db, dns_dbversion_t *version, bool complete, *answer = true; return (ISC_R_SUCCESS); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { *answer = false; + } try_private: if (privatetype == 0 || complete) { @@ -1717,8 +1838,9 @@ try_private: *answer = false; return (ISC_R_SUCCESS); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -1728,13 +1850,15 @@ try_private: dns_rdataset_current(&rdataset, &rdata1); if (!dns_nsec3param_fromprivate(&rdata1, &rdata2, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } result = dns_rdata_tostruct(&rdata2, &nsec3param, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (!complete && CREATE(nsec3param.flags)) + if (!complete && CREATE(nsec3param.flags)) { break; + } } dns_rdataset_disassociate(&rdataset); if (result == ISC_R_SUCCESS) { @@ -1761,8 +1885,9 @@ dns_nsec3_maxiterations(dns_db_t *db, dns_dbversion_t *version, isc_mem_t *mctx, unsigned int bits, minbits = 4096; result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, version, dns_rdatatype_dnskey, 0, @@ -1772,8 +1897,9 @@ dns_nsec3_maxiterations(dns_db_t *db, dns_dbversion_t *version, isc_mem_t *mctx, *iterationsp = 0; return (ISC_R_SUCCESS); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -1787,8 +1913,9 @@ dns_nsec3_maxiterations(dns_db_t *db, dns_dbversion_t *version, isc_mem_t *mctx, /* Skip unsupported algorithms when * calculating the maximum iterations. */ - if (!dst_algorithm_supported(rdata.data[3])) + if (!dst_algorithm_supported(rdata.data[3])) { continue; + } isc_buffer_init(&buffer, rdata.data, rdata.length); isc_buffer_add(&buffer, rdata.length); @@ -1796,23 +1923,27 @@ dns_nsec3_maxiterations(dns_db_t *db, dns_dbversion_t *version, isc_mem_t *mctx, &buffer, mctx, &key)); bits = dst_key_size(key); dst_key_free(&key); - if (minbits > bits) + if (minbits > bits) { minbits = bits; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } - if (minbits <= 1024) + if (minbits <= 1024) { *iterationsp = 150; - else if (minbits <= 2048) + } else if (minbits <= 2048) { *iterationsp = 500; - else + } else { *iterationsp = 2500; + } result = ISC_R_SUCCESS; failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -1864,8 +1995,9 @@ dns_nsec3_noexistnodata(dns_rdatatype_t type, const dns_name_t *name, dns_rdataset_current(nsec3set, &rdata); result = dns_rdata_tostruct(&rdata, &nsec3, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } (*logit)(arg, ISC_LOG_DEBUG(3), "looking for relevant NSEC3"); @@ -1875,8 +2007,9 @@ dns_nsec3_noexistnodata(dns_rdatatype_t type, const dns_name_t *name, /* * NSEC3 records must have two or more labels to be valid. */ - if (zlabels < 2) + if (zlabels < 2) { return (ISC_R_IGNORE); + } /* * Strip off the NSEC3 hash to get the zone. @@ -1887,32 +2020,37 @@ dns_nsec3_noexistnodata(dns_rdatatype_t type, const dns_name_t *name, /* * If not below the zone name we can ignore this record. */ - if (!dns_name_issubdomain(name, zone)) + if (!dns_name_issubdomain(name, zone)) { return (ISC_R_IGNORE); + } /* * Is this zone the same or deeper than the current zone? */ if (dns_name_countlabels(zonename) == 0 || - dns_name_issubdomain(zone, zonename)) + dns_name_issubdomain(zone, zonename)) { dns_name_copynf(zone, zonename); + } - if (!dns_name_equal(zone, zonename)) + if (!dns_name_equal(zone, zonename)) { return (ISC_R_IGNORE); + } /* * Are we only looking for the most enclosing zone? */ - if (exists == NULL || data == NULL) + if (exists == NULL || data == NULL) { return (ISC_R_SUCCESS); + } /* * Only set unknown once we are sure that this NSEC3 is from * the deepest covering zone. */ if (!dns_nsec3_supportedhash(nsec3.hash)) { - if (unknown != NULL) + if (unknown != NULL) { *unknown = true; + } return (ISC_R_IGNORE); } @@ -1923,14 +2061,16 @@ dns_nsec3_noexistnodata(dns_rdatatype_t type, const dns_name_t *name, isc_region_consume(&hashlabel, 1); isc_buffer_init(&buffer, owner, sizeof(owner)); result = isc_base32hex_decoderegion(&hashlabel, &buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * The hash lengths should match. If not ignore the record. */ - if (isc_buffer_usedlength(&buffer) != nsec3.next_length) + if (isc_buffer_usedlength(&buffer) != nsec3.next_length) { return (ISC_R_IGNORE); + } /* * Work out what this NSEC3 covers. @@ -2090,8 +2230,9 @@ dns_nsec3_noexistnodata(dns_rdatatype_t type, const dns_name_t *name, } qlabels--; - if (qlabels > 0) + if (qlabels > 0) { dns_name_split(qname, qlabels, NULL, qname); + } first = false; } return (answer); diff --git a/lib/dns/nta.c b/lib/dns/nta.c index fca1578fd0..b97f80db3b 100644 --- a/lib/dns/nta.c +++ b/lib/dns/nta.c @@ -115,19 +115,22 @@ dns_ntatable_create(dns_view_t *view, isc_taskmgr_t *taskmgr, ntatable->task = NULL; result = isc_task_create(taskmgr, 0, &ntatable->task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_ntatable; + } isc_task_setname(ntatable->task, "ntatable", ntatable); ntatable->table = NULL; result = dns_rbt_create(view->mctx, free_nta, view->mctx, &ntatable->table); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_task; + } result = isc_rwlock_init(&ntatable->rwlock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rbt; + } ntatable->timermgr = timermgr; ntatable->taskmgr = taskmgr; @@ -177,8 +180,9 @@ dns_ntatable_detach(dns_ntatable_t **ntatablep) dns_rbt_destroy(&ntatable->table); isc_rwlock_destroy(&ntatable->rwlock); isc_refcount_destroy(&ntatable->references); - if (ntatable->task != NULL) + if (ntatable->task != NULL) { isc_task_detach(&ntatable->task); + } ntatable->timermgr = NULL; ntatable->taskmgr = NULL; ntatable->magic = 0; @@ -198,18 +202,23 @@ fetch_done(isc_task_t *task, isc_event_t *event) UNUSED(task); - if (dns_rdataset_isassociated(&nta->rdataset)) + if (dns_rdataset_isassociated(&nta->rdataset)) { dns_rdataset_disassociate(&nta->rdataset); - if (dns_rdataset_isassociated(&nta->sigrdataset)) + } + if (dns_rdataset_isassociated(&nta->sigrdataset)) { dns_rdataset_disassociate(&nta->sigrdataset); - if (nta->fetch == devent->fetch) + } + if (nta->fetch == devent->fetch) { nta->fetch = NULL; + } dns_resolver_destroyfetch(&devent->fetch); - if (devent->node != NULL) + if (devent->node != NULL) { dns_db_detachnode(devent->db, &devent->node); - if (devent->db != NULL) + } + if (devent->db != NULL) { dns_db_detach(&devent->db); + } isc_event_free(&event); isc_stdtime_get(&now); @@ -220,8 +229,9 @@ fetch_done(isc_task_t *task, isc_event_t *event) case DNS_R_NXDOMAIN: case DNS_R_NCACHENXRRSET: case DNS_R_NXRRSET: - if (nta->expiry > now) + if (nta->expiry > now) { nta->expiry = now; + } break; default: break; @@ -231,9 +241,10 @@ fetch_done(isc_task_t *task, isc_event_t *event) * If we're expiring before the next recheck, we might * as well stop the timer now. */ - if (nta->timer != NULL && nta->expiry - now < view->nta_recheck) + if (nta->timer != NULL && nta->expiry - now < view->nta_recheck) { (void)isc_timer_reset(nta->timer, isc_timertype_inactive, NULL, NULL, true); + } nta_detach(view->mctx, &nta); } @@ -249,10 +260,12 @@ checkbogus(isc_task_t *task, isc_event_t *event) dns_resolver_cancelfetch(nta->fetch); nta->fetch = NULL; } - if (dns_rdataset_isassociated(&nta->rdataset)) + if (dns_rdataset_isassociated(&nta->rdataset)) { dns_rdataset_disassociate(&nta->rdataset); - if (dns_rdataset_isassociated(&nta->sigrdataset)) + } + if (dns_rdataset_isassociated(&nta->sigrdataset)) { dns_rdataset_disassociate(&nta->sigrdataset); + } isc_event_free(&event); @@ -261,8 +274,9 @@ checkbogus(isc_task_t *task, isc_event_t *event) view->resolver, nta->name, dns_rdatatype_nsec, NULL, NULL, NULL, NULL, 0, DNS_FETCHOPT_NONTA, 0, NULL, task, fetch_done, nta, &nta->rdataset, &nta->sigrdataset, &nta->fetch); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { nta_detach(view->mctx, &nta); + } } static isc_result_t @@ -275,12 +289,14 @@ settimer(dns_ntatable_t *ntatable, dns_nta_t *nta, uint32_t lifetime) REQUIRE(VALID_NTATABLE(ntatable)); REQUIRE(VALID_NTA(nta)); - if (ntatable->timermgr == NULL) + if (ntatable->timermgr == NULL) { return (ISC_R_SUCCESS); + } view = ntatable->view; - if (view->nta_recheck == 0 || lifetime <= view->nta_recheck) + if (view->nta_recheck == 0 || lifetime <= view->nta_recheck) { return (ISC_R_SUCCESS); + } isc_interval_set(&interval, view->nta_recheck, 0); result = isc_timer_create(ntatable->timermgr, isc_timertype_ticker, @@ -334,8 +350,9 @@ dns_ntatable_add(dns_ntatable_t *ntatable, const dns_name_t *name, bool force, view = ntatable->view; result = nta_create(ntatable, name, &nta); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } nta->expiry = now + lifetime; nta->forced = force; @@ -345,15 +362,17 @@ dns_ntatable_add(dns_ntatable_t *ntatable, const dns_name_t *name, bool force, node = NULL; result = dns_rbt_addnode(ntatable->table, name, &node); if (result == ISC_R_SUCCESS) { - if (!force) + if (!force) { (void)settimer(ntatable, nta, lifetime); + } node->data = nta; nta = NULL; } else if (result == ISC_R_EXISTS) { dns_nta_t *n = node->data; if (n == NULL) { - if (!force) + if (!force) { (void)settimer(ntatable, nta, lifetime); + } node->data = nta; nta = NULL; } else { @@ -365,8 +384,9 @@ dns_ntatable_add(dns_ntatable_t *ntatable, const dns_name_t *name, bool force, RWUNLOCK(&ntatable->rwlock, isc_rwlocktype_write); - if (nta != NULL) + if (nta != NULL) { nta_detach(view->mctx, &nta); + } return (result); } @@ -386,13 +406,15 @@ deletenode(dns_ntatable_t *ntatable, const dns_name_t *name) result = dns_rbt_findnode(ntatable->table, name, NULL, &node, NULL, DNS_RBTFIND_NOOPTIONS, NULL, NULL); if (result == ISC_R_SUCCESS) { - if (node->data != NULL) + if (node->data != NULL) { result = dns_rbt_deletenode(ntatable->table, node, false); - else + } else { result = ISC_R_NOTFOUND; - } else if (result == DNS_R_PARTIALMATCH) + } + } else if (result == DNS_R_PARTIALMATCH) { result = ISC_R_NOTFOUND; + } return (result); } @@ -424,8 +446,9 @@ dns_ntatable_covered(dns_ntatable_t *ntatable, isc_stdtime_t now, REQUIRE(ntatable == NULL || VALID_NTATABLE(ntatable)); REQUIRE(dns_name_isabsolute(name)); - if (ntatable == NULL) + if (ntatable == NULL) { return (false); + } foundname = dns_fixedname_initname(&fn); @@ -436,8 +459,9 @@ again: result = dns_rbt_findnode(ntatable->table, name, foundname, &node, NULL, DNS_RBTFIND_NOOPTIONS, NULL, NULL); if (result == DNS_R_PARTIALMATCH) { - if (dns_name_issubdomain(foundname, anchor)) + if (dns_name_issubdomain(foundname, anchor)) { result = ISC_R_SUCCESS; + } } if (result == ISC_R_SUCCESS) { nta = (dns_nta_t *)node->data; @@ -486,8 +510,9 @@ putstr(isc_buffer_t **b, const char *str) isc_result_t result; result = isc_buffer_reserve(b, strlen(str)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_putstr(*b, str); return (ISC_R_SUCCESS); @@ -511,8 +536,9 @@ dns_ntatable_totext(dns_ntatable_t *ntatable, const char *view, dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ntatable->table, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; + } goto cleanup; } for (;;) { @@ -548,14 +574,16 @@ dns_ntatable_totext(dns_ntatable_t *ntatable, const char *view, tbuf); first = false; result = putstr(buf, obuf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } } result = dns_rbtnodechain_next(&chain, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } break; } } @@ -608,8 +636,9 @@ dns_ntatable_save(dns_ntatable_t *ntatable, FILE *fp) RWLOCK(&ntatable->rwlock, isc_rwlocktype_read); dns_rbtnodechain_init(&chain); result = dns_rbtnodechain_first(&chain, ntatable->table, NULL, NULL); - if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) + if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { goto cleanup; + } for (;;) { dns_rbtnodechain_current(&chain, NULL, NULL, &node); @@ -633,8 +662,9 @@ dns_ntatable_save(dns_ntatable_t *ntatable, FILE *fp) isc_buffer_init(&b, nbuf, sizeof(nbuf)); result = dns_name_totext(name, false, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto skip; + } /* Zero terminate. */ isc_buffer_putuint8(&b, 0); @@ -652,8 +682,9 @@ dns_ntatable_save(dns_ntatable_t *ntatable, FILE *fp) skip: result = dns_rbtnodechain_next(&chain, NULL, NULL); if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } break; } } @@ -662,8 +693,9 @@ cleanup: dns_rbtnodechain_invalidate(&chain); RWUNLOCK(&ntatable->rwlock, isc_rwlocktype_read); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - else + } else { return (written ? ISC_R_SUCCESS : ISC_R_NOTFOUND); + } } diff --git a/lib/dns/openssl_link.c b/lib/dns/openssl_link.c index 06db4355bd..7593b10310 100644 --- a/lib/dns/openssl_link.c +++ b/lib/dns/openssl_link.c @@ -42,16 +42,17 @@ static isc_mem_t *dst__mctx = NULL; #if !defined(OPENSSL_NO_ENGINE) #include -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) static isc_mutex_t *locks = NULL; static int nlocks; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ #if !defined(OPENSSL_NO_ENGINE) static ENGINE *e = NULL; -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ static void enable_fips_mode(void) @@ -77,12 +78,14 @@ lock_callback(int mode, int type, const char *file, int line) { UNUSED(file); UNUSED(line); - if ((mode & CRYPTO_LOCK) != 0) + if ((mode & CRYPTO_LOCK) != 0) { LOCK(&locks[type]); - else + } else { UNLOCK(&locks[type]); + } } -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ #if defined(LIBRESSL_VERSION_NUMBER) static unsigned long @@ -90,7 +93,7 @@ id_callback(void) { return ((unsigned long)isc_thread_self()); } -#endif +#endif /* if defined(LIBRESSL_VERSION_NUMBER) */ #if OPENSSL_VERSION_NUMBER < 0x10100000L static void @@ -98,7 +101,7 @@ _set_thread_id(CRYPTO_THREADID *id) { CRYPTO_THREADID_set_numeric(id, (unsigned long)isc_thread_self()); } -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L */ isc_result_t dst__openssl_init(isc_mem_t *mctx, const char *engine) @@ -110,7 +113,7 @@ dst__openssl_init(isc_mem_t *mctx, const char *engine) #if defined(OPENSSL_NO_ENGINE) UNUSED(engine); -#endif +#endif /* if defined(OPENSSL_NO_ENGINE) */ enable_fips_mode(); @@ -123,14 +126,15 @@ dst__openssl_init(isc_mem_t *mctx, const char *engine) CRYPTO_set_id_callback(id_callback); #elif OPENSSL_VERSION_NUMBER < 0x10100000L CRYPTO_THREADID_set_callback(_set_thread_id); -#endif +#endif /* if defined(LIBRESSL_VERSION_NUMBER) */ ERR_load_crypto_strings(); -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ #if !defined(OPENSSL_NO_ENGINE) #if !defined(CONF_MFLAGS_DEFAULT_SECTION) OPENSSL_config(NULL); -#else +#else /* if !defined(CONF_MFLAGS_DEFAULT_SECTION) */ /* * OPENSSL_config() can only be called a single time as of * 1.0.2e so do the steps individually. @@ -141,10 +145,11 @@ dst__openssl_init(isc_mem_t *mctx, const char *engine) CONF_modules_load_file(NULL, NULL, CONF_MFLAGS_DEFAULT_SECTION | CONF_MFLAGS_IGNORE_MISSING_FILE); -#endif +#endif /* if !defined(CONF_MFLAGS_DEFAULT_SECTION) */ - if (engine != NULL && *engine == '\0') + if (engine != NULL && *engine == '\0') { engine = NULL; + } if (engine != NULL) { e = ENGINE_by_id(engine); @@ -173,16 +178,18 @@ dst__openssl_init(isc_mem_t *mctx, const char *engine) #if !defined(OPENSSL_NO_ENGINE) cleanup_rm: - if (e != NULL) + if (e != NULL) { ENGINE_free(e); + } e = NULL; -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) CRYPTO_set_locking_callback(NULL); isc_mutexblock_destroy(locks, nlocks); isc_mem_free(dst__mctx, locks); locks = NULL; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ return (result); } @@ -197,23 +204,24 @@ dst__openssl_destroy(void) OBJ_cleanup(); EVP_cleanup(); #if !defined(OPENSSL_NO_ENGINE) - if (e != NULL) + if (e != NULL) { ENGINE_free(e); + } e = NULL; ENGINE_cleanup(); -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ CRYPTO_cleanup_all_ex_data(); ERR_clear_error(); #if OPENSSL_VERSION_NUMBER < 0x10100000L ERR_remove_thread_state(NULL); #elif defined(LIBRESSL_VERSION_NUMBER) ERR_remove_state(0); -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L */ ERR_free_strings(); #ifdef DNS_CRYPTO_LEAKS CRYPTO_mem_leaks_fp(stderr); -#endif +#endif /* ifdef DNS_CRYPTO_LEAKS */ if (locks != NULL) { CRYPTO_set_locking_callback(NULL); @@ -221,7 +229,8 @@ dst__openssl_destroy(void) isc_mem_free(dst__mctx, locks); locks = NULL; } -#endif +#endif /* if (OPENSSL_VERSION_NUMBER < 0x10100000L) || \ + * defined(LIBRESSL_VERSION_NUMBER) */ isc_mem_detach(&dst__mctx); } @@ -232,7 +241,7 @@ toresult(isc_result_t fallback) unsigned long err = ERR_peek_error(); #if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED) int lib = ERR_GET_LIB(err); -#endif +#endif /* if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED) */ int reason = ERR_GET_REASON(err); switch (reason) { @@ -250,7 +259,7 @@ toresult(isc_result_t fallback) result = ISC_R_NOENTROPY; break; } -#endif +#endif /* if defined(ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED) */ break; } @@ -290,13 +299,15 @@ dst__openssl_toresult3(isc_logcategory_t *category, const char *funcname, isc_log_write(dns_lctx, category, DNS_LOGMODULE_CRYPTO, ISC_LOG_WARNING, "%s failed (%s)", funcname, isc_result_totext(result)); - if (result == ISC_R_NOMEMORY) + if (result == ISC_R_NOMEMORY) { goto done; + } for (;;) { err = ERR_get_error_line_data(&file, &line, &data, &flags); - if (err == 0U) + if (err == 0U) { goto done; + } ERR_error_string_n(err, buf, sizeof(buf)); isc_log_write(dns_lctx, category, DNS_LOGMODULE_CRYPTO, ISC_LOG_INFO, "%s:%s:%d:%s", buf, file, line, @@ -312,14 +323,17 @@ done: ENGINE * dst__openssl_getengine(const char *engine) { - if (engine == NULL) + if (engine == NULL) { return (NULL); - if (e == NULL) + } + if (e == NULL) { return (NULL); - if (strcmp(engine, ENGINE_get_id(e)) == 0) + } + if (strcmp(engine, ENGINE_get_id(e)) == 0) { return (e); + } return (NULL); } -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ /*! \file */ diff --git a/lib/dns/openssldh_link.c b/lib/dns/openssldh_link.c index 2e76830b2e..de9ff8b0d8 100644 --- a/lib/dns/openssldh_link.c +++ b/lib/dns/openssldh_link.c @@ -124,7 +124,7 @@ DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g) * parameters MUST be non-NULL. q may remain NULL. */ if ((dh->p == NULL && p == NULL) || (dh->g == NULL && g == NULL)) { - return 0; + return (0); } if (p != NULL) { @@ -169,14 +169,16 @@ openssldh_computesecret(const dst_key_t *pub, const dst_key_t *priv, len = DH_size(dhpriv); isc_buffer_availableregion(secret, &r); - if (r.length < len) + if (r.length < len) { return (ISC_R_NOSPACE); + } DH_get0_key(dhpub, &pub_key, NULL); ret = DH_compute_key(r.base, pub_key, dhpriv); - if (ret <= 0) + if (ret <= 0) { return (dst__openssl_toresult2("DH_compute_key", DST_R_COMPUTESECRETFAILURE)); + } isc_buffer_add(secret, len); return (ISC_R_SUCCESS); } @@ -192,10 +194,11 @@ openssldh_compare(const dst_key_t *key1, const dst_key_t *key2) dh1 = key1->keydata.dh; dh2 = key2->keydata.dh; - if (dh1 == NULL && dh2 == NULL) + if (dh1 == NULL && dh2 == NULL) { return (true); - else if (dh1 == NULL || dh2 == NULL) + } else if (dh1 == NULL || dh2 == NULL) { return (false); + } DH_get0_key(dh1, &pub_key1, &priv_key1); DH_get0_key(dh2, &pub_key2, &priv_key2); @@ -203,14 +206,17 @@ openssldh_compare(const dst_key_t *key1, const dst_key_t *key2) DH_get0_pqg(dh2, &p2, NULL, &g2); if (BN_cmp(p1, p2) != 0 || BN_cmp(g1, g2) != 0 || - BN_cmp(pub_key1, pub_key2) != 0) + BN_cmp(pub_key1, pub_key2) != 0) { return (false); + } if (priv_key1 != NULL || priv_key2 != NULL) { - if (priv_key1 == NULL || priv_key2 == NULL) + if (priv_key1 == NULL || priv_key2 == NULL) { return (false); - if (BN_cmp(priv_key1, priv_key2) != 0) + } + if (BN_cmp(priv_key1, priv_key2) != 0) { return (false); + } } return (true); } @@ -224,16 +230,18 @@ openssldh_paramcompare(const dst_key_t *key1, const dst_key_t *key2) dh1 = key1->keydata.dh; dh2 = key2->keydata.dh; - if (dh1 == NULL && dh2 == NULL) + if (dh1 == NULL && dh2 == NULL) { return (true); - else if (dh1 == NULL || dh2 == NULL) + } else if (dh1 == NULL || dh2 == NULL) { return (false); + } DH_get0_pqg(dh1, &p1, NULL, &g1); DH_get0_pqg(dh2, &p2, NULL, &g2); - if (BN_cmp(p1, p2) != 0 || BN_cmp(g1, g2) != 0) + if (BN_cmp(p1, p2) != 0 || BN_cmp(g1, g2) != 0) { return (false); + } return (true); } @@ -248,8 +256,9 @@ progress_cb(int p, int n, BN_GENCB *cb) UNUSED(n); u.dptr = BN_GENCB_get_arg(cb); - if (u.fptr != NULL) + if (u.fptr != NULL) { u.fptr(p); + } return (1); } @@ -260,7 +269,8 @@ openssldh_generate(dst_key_t *key, int generator, void (*callback)(int)) BN_GENCB *cb; #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) BN_GENCB _cb; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ union { void *dptr; void (*fptr)(int); @@ -271,38 +281,45 @@ openssldh_generate(dst_key_t *key, int generator, void (*callback)(int)) key->key_size == 1536) { BIGNUM *p, *g; dh = DH_new(); - if (key->key_size == 768) + if (key->key_size == 768) { p = BN_dup(bn768); - else if (key->key_size == 1024) + } else if (key->key_size == 1024) { p = BN_dup(bn1024); - else + } else { p = BN_dup(bn1536); + } g = BN_dup(bn2); if (dh == NULL || p == NULL || g == NULL) { - if (dh != NULL) + if (dh != NULL) { DH_free(dh); - if (p != NULL) + } + if (p != NULL) { BN_free(p); - if (g != NULL) + } + if (g != NULL) { BN_free(g); + } return (dst__openssl_toresult(ISC_R_NOMEMORY)); } DH_set0_pqg(dh, p, NULL, g); - } else + } else { generator = 2; + } } if (generator != 0) { dh = DH_new(); - if (dh == NULL) + if (dh == NULL) { return (dst__openssl_toresult(ISC_R_NOMEMORY)); + } cb = BN_GENCB_new(); #if OPENSSL_VERSION_NUMBER >= 0x10100000L && !defined(LIBRESSL_VERSION_NUMBER) if (cb == NULL) { DH_free(dh); return (dst__openssl_toresult(ISC_R_NOMEMORY)); } -#endif +#endif /* if OPENSSL_VERSION_NUMBER >= 0x10100000L && \ + * !defined(LIBRESSL_VERSION_NUMBER) */ if (callback == NULL) { BN_GENCB_set_old(cb, NULL, NULL); } else { @@ -348,8 +365,9 @@ openssldh_destroy(dst_key_t *key) { DH *dh = key->keydata.dh; - if (dh == NULL) + if (dh == NULL) { return; + } DH_free(dh); key->keydata.dh = NULL; @@ -405,24 +423,28 @@ openssldh_todns(const dst_key_t *key, isc_buffer_t *data) DH_get0_key(dh, &pub_key, NULL); publen = BN_num_bytes(pub_key); dnslen = plen + glen + publen + 6; - if (r.length < (unsigned int)dnslen) + if (r.length < (unsigned int)dnslen) { return (ISC_R_NOSPACE); + } uint16_toregion(plen, &r); if (plen == 1) { - if (BN_cmp(p, bn768) == 0) + if (BN_cmp(p, bn768) == 0) { *r.base = 1; - else if (BN_cmp(p, bn1024) == 0) + } else if (BN_cmp(p, bn1024) == 0) { *r.base = 2; - else + } else { *r.base = 3; - } else + } + } else { BN_bn2bin(p, r.base); + } isc_region_consume(&r, plen); uint16_toregion(glen, &r); - if (glen > 0) + if (glen > 0) { BN_bn2bin(g, r.base); + } isc_region_consume(&r, glen); uint16_toregion(publen, &r); @@ -444,12 +466,14 @@ openssldh_fromdns(dst_key_t *key, isc_buffer_t *data) int special = 0; isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); + } dh = DH_new(); - if (dh == NULL) + if (dh == NULL) { return (dst__openssl_toresult(ISC_R_NOMEMORY)); + } DH_clear_flags(dh, DH_FLAG_CACHE_MONT_P); /* @@ -510,9 +534,9 @@ openssldh_fromdns(dst_key_t *key, isc_buffer_t *data) return (DST_R_INVALIDPUBLICKEY); } if (special != 0) { - if (glen == 0) + if (glen == 0) { g = BN_dup(bn2); - else { + } else { g = BN_bin2bn(r.base, glen, NULL); if (g != NULL && BN_cmp(g, bn2) != 0) { DH_free(dh); @@ -531,10 +555,12 @@ openssldh_fromdns(dst_key_t *key, isc_buffer_t *data) if (p == NULL || g == NULL) { DH_free(dh); - if (p != NULL) + if (p != NULL) { BN_free(p); - if (g != NULL) + } + if (g != NULL) { BN_free(g); + } return (dst__openssl_toresult(ISC_R_NOMEMORY)); } DH_set0_pqg(dh, p, NULL, g); @@ -584,11 +610,13 @@ openssldh_tofile(const dst_key_t *key, const char *directory) unsigned char *bufs[4]; isc_result_t result; - if (key->keydata.dh == NULL) + if (key->keydata.dh == NULL) { return (DST_R_NULLKEY); + } - if (key->external) + if (key->external) { return (DST_R_EXTERNALKEY); + } dh = key->keydata.dh; DH_get0_key(dh, &pub_key, &priv_key); @@ -629,8 +657,9 @@ openssldh_tofile(const dst_key_t *key, const char *directory) result = dst__privstruct_writefile(key, &priv, directory); for (i = 0; i < 4; i++) { - if (bufs[i] == NULL) + if (bufs[i] == NULL) { break; + } isc_mem_put(key->mctx, bufs[i], BN_num_bytes(p)); } return (result); @@ -656,15 +685,18 @@ openssldh_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_DH, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } - if (key->external) + if (key->external) { DST_RET(DST_R_EXTERNALKEY); + } dh = DH_new(); - if (dh == NULL) + if (dh == NULL) { DST_RET(ISC_R_NOMEMORY); + } DH_clear_flags(dh, DH_FLAG_CACHE_MONT_P); key->keydata.dh = dh; @@ -672,8 +704,9 @@ openssldh_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) BIGNUM *bn; bn = BN_bin2bn(priv.elements[i].data, priv.elements[i].length, NULL); - if (bn == NULL) + if (bn == NULL) { DST_RET(ISC_R_NOMEMORY); + } switch (priv.elements[i].tag) { case TAG_DH_PRIME: @@ -698,14 +731,18 @@ openssldh_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) return (ISC_R_SUCCESS); err: - if (p != NULL) + if (p != NULL) { BN_free(p); - if (g != NULL) + } + if (g != NULL) { BN_free(g); - if (pub_key != NULL) + } + if (pub_key != NULL) { BN_free(pub_key); - if (priv_key != NULL) + } + if (priv_key != NULL) { BN_free(priv_key); + } openssldh_destroy(key); dst__privstruct_free(&priv, mctx); isc_safe_memwipe(&priv, sizeof(priv)); @@ -774,13 +811,17 @@ dst__openssldh_init(dst_func_t **funcp) return (ISC_R_SUCCESS); cleanup: - if (bn2 != NULL) + if (bn2 != NULL) { BN_free(bn2); - if (bn768 != NULL) + } + if (bn768 != NULL) { BN_free(bn768); - if (bn1024 != NULL) + } + if (bn1024 != NULL) { BN_free(bn1024); - if (bn1536 != NULL) + } + if (bn1536 != NULL) { BN_free(bn1536); + } return (ISC_R_NOMEMORY); } diff --git a/lib/dns/opensslecdsa_link.c b/lib/dns/opensslecdsa_link.c index 03fc0494bf..efd2f8e362 100644 --- a/lib/dns/opensslecdsa_link.c +++ b/lib/dns/opensslecdsa_link.c @@ -34,10 +34,10 @@ #ifndef NID_X9_62_prime256v1 #error "P-256 group is not known (NID_X9_62_prime256v1)" -#endif +#endif /* ifndef NID_X9_62_prime256v1 */ #ifndef NID_secp384r1 #error "P-384 group is not known (NID_secp384r1)" -#endif +#endif /* ifndef NID_secp384r1 */ #define DST_RET(a) \ { \ @@ -62,7 +62,7 @@ static int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) { if (r == NULL || s == NULL) { - return 0; + return (0); } BN_clear_free(sig->r); @@ -70,7 +70,7 @@ ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) sig->r = r; sig->s = s; - return 1; + return (1); } #endif /* !HAVE_ECDSA_SIG_GET0 */ @@ -88,12 +88,14 @@ opensslecdsa_createctx(dst_key_t *key, dst_context_t *dctx) dctx->key->key_alg == DST_ALG_ECDSA384); evp_md_ctx = EVP_MD_CTX_create(); - if (evp_md_ctx == NULL) + if (evp_md_ctx == NULL) { return (ISC_R_NOMEMORY); - if (dctx->key->key_alg == DST_ALG_ECDSA256) + } + if (dctx->key->key_alg == DST_ALG_ECDSA256) { type = EVP_sha256(); - else + } else { type = EVP_sha384(); + } if (!EVP_DigestInit_ex(evp_md_ctx, type, NULL)) { EVP_MD_CTX_destroy(evp_md_ctx); @@ -128,9 +130,10 @@ opensslecdsa_adddata(dst_context_t *dctx, const isc_region_t *data) REQUIRE(dctx->key->key_alg == DST_ALG_ECDSA256 || dctx->key->key_alg == DST_ALG_ECDSA384); - if (!EVP_DigestUpdate(evp_md_ctx, data->base, data->length)) + if (!EVP_DigestUpdate(evp_md_ctx, data->base, data->length)) { return (dst__openssl_toresult3( dctx->category, "EVP_DigestUpdate", ISC_R_FAILURE)); + } return (ISC_R_SUCCESS); } @@ -140,8 +143,9 @@ BN_bn2bin_fixed(const BIGNUM *bn, unsigned char *buf, int size) { int bytes = size - BN_num_bytes(bn); - while (bytes-- > 0) + while (bytes-- > 0) { *buf++ = 0; + } BN_bn2bin(bn, buf); return (size); } @@ -163,26 +167,31 @@ opensslecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) REQUIRE(key->key_alg == DST_ALG_ECDSA256 || key->key_alg == DST_ALG_ECDSA384); - if (eckey == NULL) + if (eckey == NULL) { return (ISC_R_FAILURE); + } - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { siglen = DNS_SIG_ECDSA256SIZE; - else + } else { siglen = DNS_SIG_ECDSA384SIZE; + } isc_buffer_availableregion(sig, ®ion); - if (region.length < siglen) + if (region.length < siglen) { DST_RET(ISC_R_NOSPACE); + } - if (!EVP_DigestFinal(evp_md_ctx, digest, &dgstlen)) + if (!EVP_DigestFinal(evp_md_ctx, digest, &dgstlen)) { DST_RET(dst__openssl_toresult3( dctx->category, "EVP_DigestFinal", ISC_R_FAILURE)); + } ecdsasig = ECDSA_do_sign(digest, dgstlen, eckey); - if (ecdsasig == NULL) + if (ecdsasig == NULL) { DST_RET(dst__openssl_toresult3(dctx->category, "ECDSA_do_sign", DST_R_SIGNFAILURE)); + } ECDSA_SIG_get0(ecdsasig, &r, &s); BN_bn2bin_fixed(r, region.base, siglen / 2); isc_region_consume(®ion, siglen / 2); @@ -215,24 +224,29 @@ opensslecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) REQUIRE(key->key_alg == DST_ALG_ECDSA256 || key->key_alg == DST_ALG_ECDSA384); - if (eckey == NULL) + if (eckey == NULL) { return (ISC_R_FAILURE); + } - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { siglen = DNS_SIG_ECDSA256SIZE; - else + } else { siglen = DNS_SIG_ECDSA384SIZE; + } - if (sig->length != siglen) + if (sig->length != siglen) { return (DST_R_VERIFYFAILURE); + } - if (!EVP_DigestFinal_ex(evp_md_ctx, digest, &dgstlen)) + if (!EVP_DigestFinal_ex(evp_md_ctx, digest, &dgstlen)) { DST_RET(dst__openssl_toresult3( dctx->category, "EVP_DigestFinal_ex", ISC_R_FAILURE)); + } ecdsasig = ECDSA_SIG_new(); - if (ecdsasig == NULL) + if (ecdsasig == NULL) { DST_RET(ISC_R_NOMEMORY); + } r = BN_bin2bn(cp, siglen / 2, NULL); cp += siglen / 2; s = BN_bin2bn(cp, siglen / 2, NULL); @@ -254,8 +268,9 @@ opensslecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) } err: - if (ecdsasig != NULL) + if (ecdsasig != NULL) { ECDSA_SIG_free(ecdsasig); + } EC_KEY_free(eckey); return (ret); } @@ -271,37 +286,44 @@ opensslecdsa_compare(const dst_key_t *key1, const dst_key_t *key2) EC_KEY * eckey2 = NULL; const BIGNUM *priv1, *priv2; - if (pkey1 == NULL && pkey2 == NULL) + if (pkey1 == NULL && pkey2 == NULL) { return (true); - else if (pkey1 == NULL || pkey2 == NULL) + } else if (pkey1 == NULL || pkey2 == NULL) { return (false); + } eckey1 = EVP_PKEY_get1_EC_KEY(pkey1); eckey2 = EVP_PKEY_get1_EC_KEY(pkey2); if (eckey1 == NULL && eckey2 == NULL) { DST_RET(true); - } else if (eckey1 == NULL || eckey2 == NULL) + } else if (eckey1 == NULL || eckey2 == NULL) { DST_RET(false); + } status = EVP_PKEY_cmp(pkey1, pkey2); - if (status != 1) + if (status != 1) { DST_RET(false); + } priv1 = EC_KEY_get0_private_key(eckey1); priv2 = EC_KEY_get0_private_key(eckey2); if (priv1 != NULL || priv2 != NULL) { - if (priv1 == NULL || priv2 == NULL) + if (priv1 == NULL || priv2 == NULL) { DST_RET(false); - if (BN_cmp(priv1, priv2) != 0) + } + if (BN_cmp(priv1, priv2) != 0) { DST_RET(false); + } } ret = true; err: - if (eckey1 != NULL) + if (eckey1 != NULL) { EC_KEY_free(eckey1); - if (eckey2 != NULL) + } + if (eckey2 != NULL) { EC_KEY_free(eckey2); + } return (ret); } @@ -327,17 +349,20 @@ opensslecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) } eckey = EC_KEY_new_by_curve_name(group_nid); - if (eckey == NULL) + if (eckey == NULL) { return (dst__openssl_toresult2("EC_KEY_new_by_curve_name", DST_R_OPENSSLFAILURE)); + } - if (EC_KEY_generate_key(eckey) != 1) + if (EC_KEY_generate_key(eckey) != 1) { DST_RET(dst__openssl_toresult2("EC_KEY_generate_key", DST_R_OPENSSLFAILURE)); + } pkey = EVP_PKEY_new(); - if (pkey == NULL) + if (pkey == NULL) { DST_RET(ISC_R_NOMEMORY); + } if (!EVP_PKEY_set1_EC_KEY(pkey, eckey)) { EVP_PKEY_free(pkey); DST_RET(ISC_R_FAILURE); @@ -358,8 +383,9 @@ opensslecdsa_isprivate(const dst_key_t *key) EC_KEY * eckey = EVP_PKEY_get1_EC_KEY(pkey); ret = (eckey != NULL && EC_KEY_get0_private_key(eckey) != NULL); - if (eckey != NULL) + if (eckey != NULL) { EC_KEY_free(eckey); + } return (ret); } @@ -387,18 +413,21 @@ opensslecdsa_todns(const dst_key_t *key, isc_buffer_t *data) pkey = key->keydata.pkey; eckey = EVP_PKEY_get1_EC_KEY(pkey); - if (eckey == NULL) + if (eckey == NULL) { return (dst__openssl_toresult(ISC_R_FAILURE)); + } len = i2o_ECPublicKey(eckey, NULL); /* skip form */ len--; isc_buffer_availableregion(data, &r); - if (r.length < (unsigned int)len) + if (r.length < (unsigned int)len) { DST_RET(ISC_R_NOSPACE); + } cp = buf; - if (!i2o_ECPublicKey(eckey, &cp)) + if (!i2o_ECPublicKey(eckey, &cp)) { DST_RET(dst__openssl_toresult(ISC_R_FAILURE)); + } memmove(r.base, buf + 1, len); isc_buffer_add(data, len); ret = ISC_R_SUCCESS; @@ -432,27 +461,33 @@ opensslecdsa_fromdns(dst_key_t *key, isc_buffer_t *data) } isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); - if (r.length < len) + } + if (r.length < len) { return (DST_R_INVALIDPUBLICKEY); + } eckey = EC_KEY_new_by_curve_name(group_nid); - if (eckey == NULL) + if (eckey == NULL) { return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } buf[0] = POINT_CONVERSION_UNCOMPRESSED; memmove(buf + 1, r.base, len); cp = buf; if (o2i_ECPublicKey(&eckey, (const unsigned char **)&cp, - (long)len + 1) == NULL) + (long)len + 1) == NULL) { DST_RET(dst__openssl_toresult(DST_R_INVALIDPUBLICKEY)); - if (EC_KEY_check_key(eckey) != 1) + } + if (EC_KEY_check_key(eckey) != 1) { DST_RET(dst__openssl_toresult(DST_R_INVALIDPUBLICKEY)); + } pkey = EVP_PKEY_new(); - if (pkey == NULL) + if (pkey == NULL) { DST_RET(ISC_R_NOMEMORY); + } if (!EVP_PKEY_set1_EC_KEY(pkey, eckey)) { EVP_PKEY_free(pkey); DST_RET(dst__openssl_toresult(ISC_R_FAILURE)); @@ -464,8 +499,9 @@ opensslecdsa_fromdns(dst_key_t *key, isc_buffer_t *data) ret = ISC_R_SUCCESS; err: - if (eckey != NULL) + if (eckey != NULL) { EC_KEY_free(eckey); + } return (ret); } @@ -479,8 +515,9 @@ opensslecdsa_tofile(const dst_key_t *key, const char *directory) dst_private_t priv; unsigned char *buf = NULL; - if (key->keydata.pkey == NULL) + if (key->keydata.pkey == NULL) { return (DST_R_NULLKEY); + } if (key->external) { priv.nelements = 0; @@ -489,11 +526,13 @@ opensslecdsa_tofile(const dst_key_t *key, const char *directory) pkey = key->keydata.pkey; eckey = EVP_PKEY_get1_EC_KEY(pkey); - if (eckey == NULL) + if (eckey == NULL) { return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } privkey = EC_KEY_get0_private_key(eckey); - if (privkey == NULL) + if (privkey == NULL) { DST_RET(ISC_R_FAILURE); + } buf = isc_mem_get(key->mctx, BN_num_bytes(privkey)); @@ -506,8 +545,9 @@ opensslecdsa_tofile(const dst_key_t *key, const char *directory) err: EC_KEY_free(eckey); - if (buf != NULL) + if (buf != NULL) { isc_mem_put(key->mctx, buf, BN_num_bytes(privkey)); + } return (ret); } @@ -519,21 +559,27 @@ ecdsa_check(EC_KEY *eckey, dst_key_t *pub) EC_KEY * pubeckey = NULL; const EC_POINT *pubkey; - if (pub == NULL) + if (pub == NULL) { return (ISC_R_SUCCESS); + } pkey = pub->keydata.pkey; - if (pkey == NULL) + if (pkey == NULL) { return (ISC_R_SUCCESS); + } pubeckey = EVP_PKEY_get1_EC_KEY(pkey); - if (pubeckey == NULL) + if (pubeckey == NULL) { return (ISC_R_SUCCESS); + } pubkey = EC_KEY_get0_public_key(pubeckey); - if (pubkey == NULL) + if (pubkey == NULL) { DST_RET(ISC_R_SUCCESS); - if (EC_KEY_set_public_key(eckey, pubkey) != 1) + } + if (EC_KEY_set_public_key(eckey, pubkey) != 1) { DST_RET(ISC_R_SUCCESS); - if (EC_KEY_check_key(eckey) == 1) + } + if (EC_KEY_check_key(eckey) == 1) { DST_RET(ISC_R_SUCCESS); + } err: EC_KEY_free(pubeckey); @@ -556,14 +602,17 @@ opensslecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_ECDSA256, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } if (key->external) { - if (priv.nelements != 0) + if (priv.nelements != 0) { DST_RET(DST_R_INVALIDPRIVATEKEY); - if (pub == NULL) + } + if (pub == NULL) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } key->keydata.pkey = pub->keydata.pkey; pub->keydata.pkey = NULL; dst__privstruct_free(&priv, mctx); @@ -571,43 +620,52 @@ opensslecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) return (ISC_R_SUCCESS); } - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { group_nid = NID_X9_62_prime256v1; - else + } else { group_nid = NID_secp384r1; + } eckey = EC_KEY_new_by_curve_name(group_nid); - if (eckey == NULL) + if (eckey == NULL) { return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } privkey = BN_bin2bn(priv.elements[0].data, priv.elements[0].length, NULL); - if (privkey == NULL) + if (privkey == NULL) { DST_RET(ISC_R_NOMEMORY); - if (!EC_KEY_set_private_key(eckey, privkey)) + } + if (!EC_KEY_set_private_key(eckey, privkey)) { DST_RET(ISC_R_NOMEMORY); - if (ecdsa_check(eckey, pub) != ISC_R_SUCCESS) + } + if (ecdsa_check(eckey, pub) != ISC_R_SUCCESS) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } pkey = EVP_PKEY_new(); - if (pkey == NULL) + if (pkey == NULL) { DST_RET(ISC_R_NOMEMORY); + } if (!EVP_PKEY_set1_EC_KEY(pkey, eckey)) { EVP_PKEY_free(pkey); DST_RET(dst__openssl_toresult(DST_R_OPENSSLFAILURE)); } key->keydata.pkey = pkey; - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { key->key_size = DNS_KEY_ECDSA256SIZE * 4; - else + } else { key->key_size = DNS_KEY_ECDSA384SIZE * 4; + } ret = ISC_R_SUCCESS; err: - if (privkey != NULL) + if (privkey != NULL) { BN_clear_free(privkey); - if (eckey != NULL) + } + if (eckey != NULL) { EC_KEY_free(eckey); + } dst__privstruct_free(&priv, mctx); isc_safe_memwipe(&priv, sizeof(priv)); return (ret); @@ -641,8 +699,9 @@ isc_result_t dst__opensslecdsa_init(dst_func_t **funcp) { REQUIRE(funcp != NULL); - if (*funcp == NULL) + if (*funcp == NULL) { *funcp = &opensslecdsa_functions; + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/openssleddsa_link.c b/lib/dns/openssleddsa_link.c index 9f3d189aba..08777a31b7 100644 --- a/lib/dns/openssleddsa_link.c +++ b/lib/dns/openssleddsa_link.c @@ -44,7 +44,7 @@ #ifndef NID_ED25519 #error "Ed25519 group is not known (NID_ED25519)" -#endif +#endif /* ifndef NID_ED25519 */ /* OpenSSL doesn't provide direct access to key values */ @@ -75,13 +75,15 @@ pub_ed25519_from_ossl(EVP_PKEY *pkey, unsigned char *key) len = i2d_PUBKEY(pkey, NULL); if ((len <= DNS_KEY_ED25519SIZE) || - (len > PUBPREFIXLEN + DNS_KEY_ED25519SIZE)) + (len > PUBPREFIXLEN + DNS_KEY_ED25519SIZE)) { return (DST_R_OPENSSLFAILURE); + } p = buf; len = i2d_PUBKEY(pkey, &p); if ((len <= DNS_KEY_ED25519SIZE) || - (len > PUBPREFIXLEN + DNS_KEY_ED25519SIZE)) + (len > PUBPREFIXLEN + DNS_KEY_ED25519SIZE)) { return (DST_R_OPENSSLFAILURE); + } memmove(key, buf + len - DNS_KEY_ED25519SIZE, DNS_KEY_ED25519SIZE); return (ISC_R_SUCCESS); } @@ -115,13 +117,15 @@ priv_ed25519_from_ossl(EVP_PKEY *pkey, unsigned char *key) len = i2d_PrivateKey(pkey, NULL); if ((len <= DNS_KEY_ED25519SIZE) || - (len > PRIVPREFIXLEN + DNS_KEY_ED25519SIZE)) + (len > PRIVPREFIXLEN + DNS_KEY_ED25519SIZE)) { return (DST_R_OPENSSLFAILURE); + } p = buf; len = i2d_PrivateKey(pkey, &p); if ((len <= DNS_KEY_ED25519SIZE) || - (len > PRIVPREFIXLEN + DNS_KEY_ED25519SIZE)) + (len > PRIVPREFIXLEN + DNS_KEY_ED25519SIZE)) { return (DST_R_OPENSSLFAILURE); + } memmove(key, buf + len - DNS_KEY_ED25519SIZE, DNS_KEY_ED25519SIZE); return (ISC_R_SUCCESS); } @@ -164,7 +168,7 @@ priv_ed25519_from_ossl(EVP_PKEY *pkey, unsigned char *key) #ifndef NID_ED448 #error "Ed448 group is not known (NID_ED448)" -#endif +#endif /* ifndef NID_ED448 */ static const unsigned char ed448_pub_prefix[] = { 0x30, 0x43, 0x30, 0x05, 0x06, 0x03, 0x2b, 0x65, @@ -191,13 +195,15 @@ pub_ed448_from_ossl(EVP_PKEY *pkey, unsigned char *key) len = i2d_PUBKEY(pkey, NULL); if ((len <= DNS_KEY_ED448SIZE) || - (len > PUBPREFIXLEN + DNS_KEY_ED448SIZE)) + (len > PUBPREFIXLEN + DNS_KEY_ED448SIZE)) { return (DST_R_OPENSSLFAILURE); + } p = buf; len = i2d_PUBKEY(pkey, &p); if ((len <= DNS_KEY_ED448SIZE) || - (len > PUBPREFIXLEN + DNS_KEY_ED448SIZE)) + (len > PUBPREFIXLEN + DNS_KEY_ED448SIZE)) { return (DST_R_OPENSSLFAILURE); + } memmove(key, buf + len - DNS_KEY_ED448SIZE, DNS_KEY_ED448SIZE); return (ISC_R_SUCCESS); } @@ -229,13 +235,15 @@ priv_ed448_from_ossl(EVP_PKEY *pkey, unsigned char *key) len = i2d_PrivateKey(pkey, NULL); if ((len <= DNS_KEY_ED448SIZE) || - (len > PRIVPREFIXLEN + DNS_KEY_ED448SIZE)) + (len > PRIVPREFIXLEN + DNS_KEY_ED448SIZE)) { return (DST_R_OPENSSLFAILURE); + } p = buf; len = i2d_PrivateKey(pkey, &p); if ((len <= DNS_KEY_ED448SIZE) || - (len > PRIVPREFIXLEN + DNS_KEY_ED448SIZE)) + (len > PRIVPREFIXLEN + DNS_KEY_ED448SIZE)) { return (DST_R_OPENSSLFAILURE); + } memmove(key, buf + len - DNS_KEY_ED448SIZE, DNS_KEY_ED448SIZE); return (ISC_R_SUCCESS); } @@ -299,8 +307,9 @@ openssleddsa_destroyctx(dst_context_t *dctx) REQUIRE(dctx->key->key_alg == DST_ALG_ED25519 || dctx->key->key_alg == DST_ALG_ED448); - if (buf != NULL) + if (buf != NULL) { isc_buffer_free(&buf); + } dctx->ctxdata.generic = NULL; } @@ -317,8 +326,9 @@ openssleddsa_adddata(dst_context_t *dctx, const isc_region_t *data) dctx->key->key_alg == DST_ALG_ED448); result = isc_buffer_copyregion(buf, data); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } length = isc_buffer_length(buf) + data->length + 64; isc_buffer_allocate(dctx->mctx, &nbuf, length); @@ -346,17 +356,20 @@ openssleddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) REQUIRE(key->key_alg == DST_ALG_ED25519 || key->key_alg == DST_ALG_ED448); - if (ctx == NULL) + if (ctx == NULL) { return (ISC_R_NOMEMORY); + } - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { siglen = DNS_SIG_ED25519SIZE; - else + } else { siglen = DNS_SIG_ED448SIZE; + } isc_buffer_availableregion(sig, &sigreg); - if (sigreg.length < (unsigned int)siglen) + if (sigreg.length < (unsigned int)siglen) { DST_RET(ISC_R_NOSPACE); + } isc_buffer_usedregion(buf, &tbsreg); @@ -395,25 +408,27 @@ openssleddsa_verify(dst_context_t *dctx, const isc_region_t *sig) REQUIRE(key->key_alg == DST_ALG_ED25519 || key->key_alg == DST_ALG_ED448); - if (ctx == NULL) + if (ctx == NULL) { return (ISC_R_NOMEMORY); + } #if HAVE_OPENSSL_ED25519 if (key->key_alg == DST_ALG_ED25519) { siglen = DNS_SIG_ED25519SIZE; } -#endif +#endif /* if HAVE_OPENSSL_ED25519 */ #if HAVE_OPENSSL_ED448 if (key->key_alg == DST_ALG_ED448) { siglen = DNS_SIG_ED448SIZE; } -#endif +#endif /* if HAVE_OPENSSL_ED448 */ if (siglen == 0) { return (ISC_R_NOTIMPLEMENTED); } - if (sig->length != siglen) + if (sig->length != siglen) { return (DST_R_VERIFYFAILURE); + } isc_buffer_usedregion(buf, &tbsreg); @@ -453,14 +468,16 @@ openssleddsa_compare(const dst_key_t *key1, const dst_key_t *key2) EVP_PKEY *pkey1 = key1->keydata.pkey; EVP_PKEY *pkey2 = key2->keydata.pkey; - if (pkey1 == NULL && pkey2 == NULL) + if (pkey1 == NULL && pkey2 == NULL) { return (true); - else if (pkey1 == NULL || pkey2 == NULL) + } else if (pkey1 == NULL || pkey2 == NULL) { return (false); + } status = EVP_PKEY_cmp(pkey1, pkey2); - if (status == 1) + if (status == 1) { return (true); + } return (false); } @@ -482,31 +499,34 @@ openssleddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) nid = NID_ED25519; key->key_size = DNS_KEY_ED25519SIZE; } -#endif +#endif /* if HAVE_OPENSSL_ED25519 */ #if HAVE_OPENSSL_ED448 if (key->key_alg == DST_ALG_ED448) { nid = NID_ED448; key->key_size = DNS_KEY_ED448SIZE; } -#endif +#endif /* if HAVE_OPENSSL_ED448 */ if (nid == 0) { return (ISC_R_NOTIMPLEMENTED); } ctx = EVP_PKEY_CTX_new_id(nid, NULL); - if (ctx == NULL) + if (ctx == NULL) { return (dst__openssl_toresult2("EVP_PKEY_CTX_new_id", DST_R_OPENSSLFAILURE)); + } status = EVP_PKEY_keygen_init(ctx); - if (status != 1) + if (status != 1) { DST_RET(dst__openssl_toresult2("EVP_PKEY_keygen_init", DST_R_OPENSSLFAILURE)); + } status = EVP_PKEY_keygen(ctx, &pkey); - if (status != 1) + if (status != 1) { DST_RET(dst__openssl_toresult2("EVP_PKEY_keygen", DST_R_OPENSSLFAILURE)); + } key->keydata.pkey = pkey; ret = ISC_R_SUCCESS; @@ -523,15 +543,18 @@ openssleddsa_isprivate(const dst_key_t *key) int len; unsigned long err; - if (pkey == NULL) + if (pkey == NULL) { return (false); + } len = i2d_PrivateKey(pkey, NULL); - if (len > 0) + if (len > 0) { return (true); + } /* can check if first error is EC_R_INVALID_PRIVATE_KEY */ - while ((err = ERR_get_error()) != 0) - /**/; + while ((err = ERR_get_error()) != 0) { + /**/ + } return (false); } @@ -558,19 +581,23 @@ openssleddsa_todns(const dst_key_t *key, isc_buffer_t *data) switch (key->key_alg) { case DST_ALG_ED25519: isc_buffer_availableregion(data, &r); - if (r.length < DNS_KEY_ED25519SIZE) + if (r.length < DNS_KEY_ED25519SIZE) { return (ISC_R_NOSPACE); + } result = pub_ed25519_from_ossl(pkey, r.base); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_buffer_add(data, DNS_KEY_ED25519SIZE); + } return (result); case DST_ALG_ED448: isc_buffer_availableregion(data, &r); - if (r.length < DNS_KEY_ED448SIZE) + if (r.length < DNS_KEY_ED448SIZE) { return (ISC_R_NOSPACE); + } result = pub_ed448_from_ossl(pkey, r.base); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_buffer_add(data, DNS_KEY_ED448SIZE); + } return (result); default: INSIST(0); @@ -589,21 +616,25 @@ openssleddsa_fromdns(dst_key_t *key, isc_buffer_t *data) key->key_alg == DST_ALG_ED448); isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); + } if (key->key_alg == DST_ALG_ED25519) { len = DNS_KEY_ED25519SIZE; - if (r.length < len) + if (r.length < len) { return (DST_R_INVALIDPUBLICKEY); + } pkey = pub_ed25519_to_ossl(r.base); } else { len = DNS_KEY_ED448SIZE; - if (r.length < len) + if (r.length < len) { return (DST_R_INVALIDPUBLICKEY); + } pkey = pub_ed448_to_ossl(r.base); } - if (pkey == NULL) + if (pkey == NULL) { return (dst__openssl_toresult(ISC_R_FAILURE)); + } isc_buffer_forward(data, len); key->keydata.pkey = pkey; key->key_size = len; @@ -622,8 +653,9 @@ openssleddsa_tofile(const dst_key_t *key, const char *directory) REQUIRE(key->key_alg == DST_ALG_ED25519 || key->key_alg == DST_ALG_ED448); - if (key->keydata.pkey == NULL) + if (key->keydata.pkey == NULL) { return (DST_R_NULLKEY); + } if (key->external) { priv.nelements = 0; @@ -637,8 +669,9 @@ openssleddsa_tofile(const dst_key_t *key, const char *directory) priv.elements[0].tag = TAG_EDDSA_PRIVATEKEY; priv.elements[0].length = len; ret = priv_ed25519_from_ossl(pkey, buf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { DST_RET(dst__openssl_toresult(ret)); + } priv.elements[0].data = buf; priv.nelements = 1; ret = dst__privstruct_writefile(key, &priv, directory); @@ -648,16 +681,18 @@ openssleddsa_tofile(const dst_key_t *key, const char *directory) priv.elements[0].tag = TAG_EDDSA_PRIVATEKEY; priv.elements[0].length = len; ret = priv_ed448_from_ossl(pkey, buf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { DST_RET(dst__openssl_toresult(ret)); + } priv.elements[0].data = buf; priv.nelements = 1; ret = dst__privstruct_writefile(key, &priv, directory); } err: - if (buf != NULL) + if (buf != NULL) { isc_mem_put(key->mctx, buf, len); + } return (ret); } @@ -666,13 +701,16 @@ eddsa_check(EVP_PKEY *privkey, dst_key_t *pub) { EVP_PKEY *pkey; - if (pub == NULL) + if (pub == NULL) { return (ISC_R_SUCCESS); + } pkey = pub->keydata.pkey; - if (pkey == NULL) + if (pkey == NULL) { return (ISC_R_SUCCESS); - if (EVP_PKEY_cmp(privkey, pkey) == 1) + } + if (EVP_PKEY_cmp(privkey, pkey) == 1) { return (ISC_R_SUCCESS); + } return (ISC_R_FAILURE); } @@ -690,14 +728,17 @@ openssleddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_ED25519, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } if (key->external) { - if (priv.nelements != 0) + if (priv.nelements != 0) { DST_RET(DST_R_INVALIDPRIVATEKEY); - if (pub == NULL) + } + if (pub == NULL) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } key->keydata.pkey = pub->keydata.pkey; pub->keydata.pkey = NULL; dst__privstruct_free(&priv, mctx); @@ -707,17 +748,20 @@ openssleddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) if (key->key_alg == DST_ALG_ED25519) { len = DNS_KEY_ED25519SIZE; - if (priv.elements[0].length < len) + if (priv.elements[0].length < len) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } pkey = priv_ed25519_to_ossl(priv.elements[0].data); } else { len = DNS_KEY_ED448SIZE; - if (priv.elements[0].length < len) + if (priv.elements[0].length < len) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } pkey = priv_ed448_to_ossl(priv.elements[0].data); } - if (pkey == NULL) + if (pkey == NULL) { DST_RET(dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } if (eddsa_check(pkey, pub) != ISC_R_SUCCESS) { EVP_PKEY_free(pkey); DST_RET(DST_R_INVALIDPRIVATEKEY); @@ -760,8 +804,9 @@ isc_result_t dst__openssleddsa_init(dst_func_t **funcp) { REQUIRE(funcp != NULL); - if (*funcp == NULL) + if (*funcp == NULL) { *funcp = &openssleddsa_functions; + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/opensslrsa_link.c b/lib/dns/opensslrsa_link.c index 66d09055e9..d7eae209fa 100644 --- a/lib/dns/opensslrsa_link.c +++ b/lib/dns/opensslrsa_link.c @@ -31,14 +31,14 @@ #include #if !defined(OPENSSL_NO_ENGINE) #include -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ /* * Limit the size of public exponents. */ #ifndef RSA_MAX_PUBEXP_BITS #define RSA_MAX_PUBEXP_BITS 35 -#endif +#endif /* ifndef RSA_MAX_PUBEXP_BITS */ /* * We don't use configure for windows so enforce the OpenSSL version @@ -46,7 +46,7 @@ */ #if defined(WIN32) && (OPENSSL_VERSION_NUMBER < 0x10000000L) #error Please upgrade OpenSSL to 1.0.0 or greater. -#endif +#endif /* if defined(WIN32) && (OPENSSL_VERSION_NUMBER < 0x10000000L) */ #define DST_RET(a) \ { \ @@ -65,7 +65,7 @@ RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) * left NULL (in case only the public key is used). */ if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) { - return 0; + return (0); } if (n != NULL) { @@ -81,7 +81,7 @@ RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) r->d = d; } - return 1; + return (1); } static int @@ -92,7 +92,7 @@ RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) * parameters MUST be non-NULL. */ if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL)) { - return 0; + return (0); } if (p != NULL) { @@ -104,7 +104,7 @@ RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) r->q = q; } - return 1; + return (1); } static int @@ -117,7 +117,7 @@ RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) if ((r->dmp1 == NULL && dmp1 == NULL) || (r->dmq1 == NULL && dmq1 == NULL) || (r->iqmp == NULL && iqmp == NULL)) { - return 0; + return (0); } if (dmp1 != NULL) { @@ -133,7 +133,7 @@ RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) r->iqmp = iqmp; } - return 1; + return (1); } static void @@ -206,19 +206,23 @@ opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx) case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (dctx->key->key_size > 4096) + if (dctx->key->key_size > 4096) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((dctx->key->key_size < 512) || (dctx->key->key_size > 4096)) + if ((dctx->key->key_size < 512) || + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ if ((dctx->key->key_size < 1024) || - (dctx->key->key_size > 4096)) + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; default: INSIST(0); @@ -226,8 +230,9 @@ opensslrsa_createctx(dst_key_t *key, dst_context_t *dctx) } evp_md_ctx = EVP_MD_CTX_create(); - if (evp_md_ctx == NULL) + if (evp_md_ctx == NULL) { return (ISC_R_NOMEMORY); + } switch (dctx->key->key_alg) { case DST_ALG_RSASHA1: @@ -304,8 +309,9 @@ opensslrsa_sign(dst_context_t *dctx, isc_buffer_t *sig) isc_buffer_availableregion(sig, &r); - if (r.length < (unsigned int)EVP_PKEY_size(pkey)) + if (r.length < (unsigned int)EVP_PKEY_size(pkey)) { return (ISC_R_NOSPACE); + } if (!EVP_SignFinal(evp_md_ctx, r.base, &siglen, pkey)) { return (dst__openssl_toresult3(dctx->category, "EVP_SignFinal", @@ -334,13 +340,15 @@ opensslrsa_verify2(dst_context_t *dctx, int maxbits, const isc_region_t *sig) dctx->key->key_alg == DST_ALG_RSASHA512); rsa = EVP_PKEY_get1_RSA(pkey); - if (rsa == NULL) + if (rsa == NULL) { return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } RSA_get0_key(rsa, NULL, &e, NULL); bits = BN_num_bits(e); RSA_free(rsa); - if (bits > maxbits && maxbits != 0) + if (bits > maxbits && maxbits != 0) { return (DST_R_VERIFYFAILURE); + } status = EVP_VerifyFinal(evp_md_ctx, sig->base, sig->length, pkey); switch (status) { @@ -388,23 +396,26 @@ opensslrsa_compare(const dst_key_t *key1, const dst_key_t *key2) RSA_free(rsa2); } - if (rsa1 == NULL && rsa2 == NULL) + if (rsa1 == NULL && rsa2 == NULL) { return (true); - else if (rsa1 == NULL || rsa2 == NULL) + } else if (rsa1 == NULL || rsa2 == NULL) { return (false); + } RSA_get0_key(rsa1, &n1, &e1, &d1); RSA_get0_key(rsa2, &n2, &e2, &d2); status = BN_cmp(n1, n2) || BN_cmp(e1, e2); - if (status != 0) + if (status != 0) { return (false); + } if (RSA_test_flags(rsa1, RSA_FLAG_EXT_PKEY) != 0 || RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) != 0) { if (RSA_test_flags(rsa1, RSA_FLAG_EXT_PKEY) == 0 || - RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) == 0) + RSA_test_flags(rsa2, RSA_FLAG_EXT_PKEY) == 0) { return (false); + } /* * Can't compare private parameters, BTW does it make sense? */ @@ -412,14 +423,16 @@ opensslrsa_compare(const dst_key_t *key1, const dst_key_t *key2) } if (d1 != NULL || d2 != NULL) { - if (d1 == NULL || d2 == NULL) + if (d1 == NULL || d2 == NULL) { return (false); + } RSA_get0_factors(rsa1, &p1, &q1); RSA_get0_factors(rsa2, &p2, &q2); status = BN_cmp(d1, d2) || BN_cmp(p1, p1) || BN_cmp(q1, q2); - if (status != 0) + if (status != 0) { return (false); + } } return (true); } @@ -435,8 +448,9 @@ progress_cb(int p, int n, BN_GENCB *cb) UNUSED(n); u.dptr = BN_GENCB_get_arg(cb); - if (u.fptr != NULL) + if (u.fptr != NULL) { u.fptr(p); + } return (1); } @@ -452,7 +466,8 @@ opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int)) BIGNUM *e = BN_new(); #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) BN_GENCB _cb; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ BN_GENCB *cb = BN_GENCB_new(); EVP_PKEY *pkey = EVP_PKEY_new(); @@ -463,30 +478,36 @@ opensslrsa_generate(dst_key_t *key, int exp, void (*callback)(int)) case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (key->key_size > 4096) + if (key->key_size > 4096) { goto err; + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((key->key_size < 512) || (key->key_size > 4096)) + if ((key->key_size < 512) || (key->key_size > 4096)) { goto err; + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ - if ((key->key_size < 1024) || (key->key_size > 4096)) + if ((key->key_size < 1024) || (key->key_size > 4096)) { goto err; + } break; default: INSIST(0); ISC_UNREACHABLE(); } - if (rsa == NULL || e == NULL || cb == NULL) + if (rsa == NULL || e == NULL || cb == NULL) { goto err; - if (pkey == NULL) + } + if (pkey == NULL) { goto err; - if (!EVP_PKEY_set1_RSA(pkey, rsa)) + } + if (!EVP_PKEY_set1_RSA(pkey, rsa)) { goto err; + } if (exp == 0) { /* RSA_F4 0x10001 */ @@ -545,8 +566,9 @@ opensslrsa_isprivate(const dst_key_t *key) INSIST(rsa != NULL); RSA_free(rsa); /* key->keydata.pkey still has a reference so rsa is still valid. */ - if (rsa != NULL && RSA_test_flags(rsa, RSA_FLAG_EXT_PKEY) != 0) + if (rsa != NULL && RSA_test_flags(rsa, RSA_FLAG_EXT_PKEY) != 0) { return (true); + } RSA_get0_key(rsa, NULL, NULL, &d); return (rsa != NULL && d != NULL); } @@ -574,8 +596,9 @@ opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data) pkey = key->keydata.pkey; rsa = EVP_PKEY_get1_RSA(pkey); - if (rsa == NULL) + if (rsa == NULL) { return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } isc_buffer_availableregion(data, &r); @@ -584,20 +607,23 @@ opensslrsa_todns(const dst_key_t *key, isc_buffer_t *data) e_bytes = BN_num_bytes(e); if (e_bytes < 256) { /*%< key exponent is <= 2040 bits */ - if (r.length < 1) + if (r.length < 1) { DST_RET(ISC_R_NOSPACE); + } isc_buffer_putuint8(data, (uint8_t)e_bytes); isc_region_consume(&r, 1); } else { - if (r.length < 3) + if (r.length < 3) { DST_RET(ISC_R_NOSPACE); + } isc_buffer_putuint8(data, 0); isc_buffer_putuint16(data, (uint16_t)e_bytes); isc_region_consume(&r, 3); } - if (r.length < e_bytes + mod_bytes) + if (r.length < e_bytes + mod_bytes) { DST_RET(ISC_R_NOSPACE); + } RSA_get0_key(rsa, &n, &e, NULL); BN_bn2bin(e, r.base); @@ -623,13 +649,15 @@ opensslrsa_fromdns(dst_key_t *key, isc_buffer_t *data) BIGNUM * e = NULL, *n = NULL; isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); + } length = r.length; rsa = RSA_new(); - if (rsa == NULL) + if (rsa == NULL) { return (dst__openssl_toresult(ISC_R_NOMEMORY)); + } if (r.length < 1) { RSA_free(rsa); @@ -657,10 +685,12 @@ opensslrsa_fromdns(dst_key_t *key, isc_buffer_t *data) isc_region_consume(&r, e_bytes); n = BN_bin2bn(r.base, r.length, NULL); if (RSA_set0_key(rsa, n, e, NULL) == 0) { - if (n != NULL) + if (n != NULL) { BN_free(n); - if (e != NULL) + } + if (e != NULL) { BN_free(e); + } RSA_free(rsa); return (ISC_R_NOMEMORY); } @@ -696,11 +726,13 @@ opensslrsa_tofile(const dst_key_t *key, const char *directory) const BIGNUM * p = NULL, *q = NULL; const BIGNUM * dmp1 = NULL, *dmq1 = NULL, *iqmp = NULL; - if (key->keydata.pkey == NULL) + if (key->keydata.pkey == NULL) { return (DST_R_NULLKEY); + } rsa = EVP_PKEY_get1_RSA(key->keydata.pkey); - if (rsa == NULL) + if (rsa == NULL) { return (dst__openssl_toresult(DST_R_OPENSSLFAILURE)); + } memset(bufs, 0, sizeof(bufs)); RSA_get0_key(rsa, &n, &e, &d); @@ -800,8 +832,9 @@ opensslrsa_tofile(const dst_key_t *key, const char *directory) fail: RSA_free(rsa); for (i = 0; i < 8; i++) { - if (bufs[i] == NULL) + if (bufs[i] == NULL) { break; + } isc_mem_put(key->mctx, bufs[i], BN_num_bytes(n)); } return (result); @@ -822,27 +855,32 @@ rsa_check(RSA *rsa, RSA *pub) if (pub != NULL) { RSA_get0_key(pub, &n2, &e2, NULL); if (n1 != NULL) { - if (BN_cmp(n1, n2) != 0) + if (BN_cmp(n1, n2) != 0) { return (DST_R_INVALIDPRIVATEKEY); + } } else { n = BN_dup(n2); } if (e1 != NULL) { - if (BN_cmp(e1, e2) != 0) + if (BN_cmp(e1, e2) != 0) { return (DST_R_INVALIDPRIVATEKEY); + } } else { e = BN_dup(e2); } if (RSA_set0_key(rsa, n, e, NULL) == 0) { - if (n != NULL) + if (n != NULL) { BN_free(n); - if (e != NULL) + } + if (e != NULL) { BN_free(e); + } } } RSA_get0_key(rsa, &n1, &e1, NULL); - if (n1 == NULL || e1 == NULL) + if (n1 == NULL || e1 == NULL) { return (DST_R_INVALIDPRIVATEKEY); + } return (ISC_R_SUCCESS); } @@ -856,7 +894,7 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) #if !defined(OPENSSL_NO_ENGINE) ENGINE * ep = NULL; const BIGNUM *ex = NULL; -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ isc_mem_t * mctx = key->mctx; const char *engine = NULL, *label = NULL; EVP_PKEY * pkey = NULL; @@ -866,14 +904,17 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_RSA, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } if (key->external) { - if (priv.nelements != 0) + if (priv.nelements != 0) { DST_RET(DST_R_INVALIDPRIVATEKEY); - if (pub == NULL) + } + if (pub == NULL) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } key->keydata.pkey = pub->keydata.pkey; pub->keydata.pkey = NULL; key->key_size = pub->key_size; @@ -882,8 +923,9 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) return (ISC_R_SUCCESS); } - if (pub != NULL && pub->keydata.pkey != NULL) + if (pub != NULL && pub->keydata.pkey != NULL) { pubrsa = EVP_PKEY_get1_RSA(pub->keydata.pkey); + } for (i = 0; i < priv.nelements; i++) { switch (priv.elements[i].tag) { @@ -904,48 +946,58 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) */ if (label != NULL) { #if !defined(OPENSSL_NO_ENGINE) - if (engine == NULL) + if (engine == NULL) { DST_RET(DST_R_NOENGINE); + } ep = dst__openssl_getengine(engine); - if (ep == NULL) + if (ep == NULL) { DST_RET(DST_R_NOENGINE); + } pkey = ENGINE_load_private_key(ep, label, NULL, NULL); - if (pkey == NULL) + if (pkey == NULL) { DST_RET(dst__openssl_toresult2("ENGINE_load_private_" "key", ISC_R_NOTFOUND)); + } key->engine = isc_mem_strdup(key->mctx, engine); key->label = isc_mem_strdup(key->mctx, label); rsa = EVP_PKEY_get1_RSA(pkey); - if (rsa == NULL) + if (rsa == NULL) { DST_RET(dst__openssl_toresult(DST_R_OPENSSLFAILURE)); - if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) + } + if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } RSA_get0_key(rsa, NULL, &ex, NULL); - if (BN_num_bits(ex) > RSA_MAX_PUBEXP_BITS) + if (BN_num_bits(ex) > RSA_MAX_PUBEXP_BITS) { DST_RET(ISC_R_RANGE); - if (pubrsa != NULL) + } + if (pubrsa != NULL) { RSA_free(pubrsa); + } key->key_size = EVP_PKEY_bits(pkey); key->keydata.pkey = pkey; RSA_free(rsa); dst__privstruct_free(&priv, mctx); isc_safe_memwipe(&priv, sizeof(priv)); return (ISC_R_SUCCESS); -#else +#else /* if !defined(OPENSSL_NO_ENGINE) */ DST_RET(DST_R_NOENGINE); -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ } rsa = RSA_new(); - if (rsa == NULL) + if (rsa == NULL) { DST_RET(ISC_R_NOMEMORY); + } pkey = EVP_PKEY_new(); - if (pkey == NULL) + if (pkey == NULL) { DST_RET(ISC_R_NOMEMORY); - if (!EVP_PKEY_set1_RSA(pkey, rsa)) + } + if (!EVP_PKEY_set1_RSA(pkey, rsa)) { DST_RET(ISC_R_FAILURE); + } key->keydata.pkey = pkey; for (i = 0; i < priv.nelements; i++) { @@ -958,8 +1010,9 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) default: bn = BN_bin2bn(priv.elements[i].data, priv.elements[i].length, NULL); - if (bn == NULL) + if (bn == NULL) { DST_RET(ISC_R_NOMEMORY); + } switch (priv.elements[i].tag) { case TAG_RSA_MODULUS: n = bn; @@ -992,46 +1045,60 @@ opensslrsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) isc_safe_memwipe(&priv, sizeof(priv)); if (RSA_set0_key(rsa, n, e, d) == 0) { - if (n != NULL) + if (n != NULL) { BN_free(n); - if (e != NULL) + } + if (e != NULL) { BN_free(e); - if (d != NULL) + } + if (d != NULL) { BN_free(d); + } } if (RSA_set0_factors(rsa, p, q) == 0) { - if (p != NULL) + if (p != NULL) { BN_free(p); - if (q != NULL) + } + if (q != NULL) { BN_free(q); + } } if (RSA_set0_crt_params(rsa, dmp1, dmq1, iqmp) == 0) { - if (dmp1 != NULL) + if (dmp1 != NULL) { BN_free(dmp1); - if (dmq1 != NULL) + } + if (dmq1 != NULL) { BN_free(dmq1); - if (iqmp != NULL) + } + if (iqmp != NULL) { BN_free(iqmp); + } } - if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) + if (rsa_check(rsa, pubrsa) != ISC_R_SUCCESS) { DST_RET(DST_R_INVALIDPRIVATEKEY); - if (BN_num_bits(e) > RSA_MAX_PUBEXP_BITS) + } + if (BN_num_bits(e) > RSA_MAX_PUBEXP_BITS) { DST_RET(ISC_R_RANGE); + } key->key_size = BN_num_bits(n); - if (pubrsa != NULL) + if (pubrsa != NULL) { RSA_free(pubrsa); + } RSA_free(rsa); return (ISC_R_SUCCESS); err: - if (pkey != NULL) + if (pkey != NULL) { EVP_PKEY_free(pkey); - if (rsa != NULL) + } + if (rsa != NULL) { RSA_free(rsa); - if (pubrsa != NULL) + } + if (pubrsa != NULL) { RSA_free(pubrsa); + } key->keydata.generic = NULL; dst__privstruct_free(&priv, mctx); isc_safe_memwipe(&priv, sizeof(priv)); @@ -1093,20 +1160,23 @@ opensslrsa_fromlabel(dst_key_t *key, const char *engine, const char *label, return (ISC_R_SUCCESS); err: - if (rsa != NULL) + if (rsa != NULL) { RSA_free(rsa); - if (pubrsa != NULL) + } + if (pubrsa != NULL) { RSA_free(pubrsa); - if (pkey != NULL) + } + if (pkey != NULL) { EVP_PKEY_free(pkey); + } return (ret); -#else +#else /* if !defined(OPENSSL_NO_ENGINE) */ UNUSED(key); UNUSED(engine); UNUSED(label); UNUSED(pin); return (DST_R_NOENGINE); -#endif +#endif /* if !defined(OPENSSL_NO_ENGINE) */ } static dst_func_t opensslrsa_functions = { diff --git a/lib/dns/order.c b/lib/dns/order.c index 71dab28387..ea986dcb34 100644 --- a/lib/dns/order.c +++ b/lib/dns/order.c @@ -92,8 +92,9 @@ dns_order_add(dns_order_t *order, const dns_name_t *name, static inline bool match(const dns_name_t *name1, const dns_name_t *name2) { - if (dns_name_iswildcard(name2)) + if (dns_name_iswildcard(name2)) { return (dns_name_matcheswildcard(name1, name2)); + } return (dns_name_equal(name1, name2)); } @@ -106,13 +107,16 @@ dns_order_find(dns_order_t *order, const dns_name_t *name, for (ent = ISC_LIST_HEAD(order->ents); ent != NULL; ent = ISC_LIST_NEXT(ent, link)) { - if (ent->rdtype != rdtype && ent->rdtype != dns_rdatatype_any) + if (ent->rdtype != rdtype && ent->rdtype != dns_rdatatype_any) { continue; + } if (ent->rdclass != rdclass && - ent->rdclass != dns_rdataclass_any) + ent->rdclass != dns_rdataclass_any) { continue; - if (match(name, dns_fixedname_name(&ent->name))) + } + if (match(name, dns_fixedname_name(&ent->name))) { return (ent->mode); + } } return (DNS_RDATASETATTR_NONE); } diff --git a/lib/dns/peer.c b/lib/dns/peer.c index cdacc459d6..7596bbb5a0 100644 --- a/lib/dns/peer.c +++ b/lib/dns/peer.c @@ -140,14 +140,14 @@ dns_peerlist_addpeer(dns_peerlist_t *peers, dns_peer_t *peer) p = ISC_LIST_NEXT(p, next)) { if (p->prefixlen < peer->prefixlen) { break; - } } - if (p != NULL) + if (p != NULL) { ISC_LIST_INSERTBEFORE(peers->elements, p, peer, next); - else + } else { ISC_LIST_APPEND(peers->elements, peer, next); + } } isc_result_t @@ -163,8 +163,9 @@ dns_peerlist_peerbyaddr(dns_peerlist_t *servers, const isc_netaddr_t *addr, server = ISC_LIST_HEAD(servers->elements); while (server != NULL) { if (isc_netaddr_eqprefix(addr, &server->address, - server->prefixlen)) + server->prefixlen)) { break; + } server = ISC_LIST_NEXT(server, next); } @@ -291,15 +292,18 @@ peer_delete(dns_peer_t **peer) isc_mem_put(mem, p->key, sizeof(dns_name_t)); } - if (p->query_source != NULL) + if (p->query_source != NULL) { isc_mem_put(mem, p->query_source, sizeof(*p->query_source)); + } - if (p->notify_source != NULL) + if (p->notify_source != NULL) { isc_mem_put(mem, p->notify_source, sizeof(*p->notify_source)); + } - if (p->transfer_source != NULL) + if (p->transfer_source != NULL) { isc_mem_put(mem, p->transfer_source, sizeof(*p->transfer_source)); + } isc_mem_put(mem, p, sizeof(*p)); } @@ -328,8 +332,9 @@ dns_peer_getbogus(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(BOGUS_BIT, &peer->bitflags)) { *retval = peer->bogus; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -385,8 +390,9 @@ dns_peer_getrequestixfr(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(REQUEST_IXFR_BIT, &peer->bitflags)) { *retval = peer->request_ixfr; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -413,8 +419,9 @@ dns_peer_getsupportedns(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(SUPPORT_EDNS_BIT, &peer->bitflags)) { *retval = peer->support_edns; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -441,8 +448,9 @@ dns_peer_getrequestnsid(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(REQUEST_NSID_BIT, &peer->bitflags)) { *retval = peer->request_nsid; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -469,8 +477,9 @@ dns_peer_getsendcookie(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(SEND_COOKIE_BIT, &peer->bitflags)) { *retval = peer->send_cookie; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -497,8 +506,9 @@ dns_peer_getrequestexpire(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(REQUEST_EXPIRE_BIT, &peer->bitflags)) { *retval = peer->request_expire; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -525,8 +535,9 @@ dns_peer_getforcetcp(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(FORCE_TCP_BIT, &peer->bitflags)) { *retval = peer->force_tcp; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -553,8 +564,9 @@ dns_peer_gettcpkeepalive(dns_peer_t *peer, bool *retval) if (DNS_BIT_CHECK(REQUEST_TCP_KEEPALIVE_BIT, &peer->bitflags)) { *retval = peer->tcp_keepalive; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } isc_result_t @@ -658,8 +670,9 @@ dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) isc_buffer_add(&b, strlen(keyval)); result = dns_name_fromtext(dns_fixedname_name(&fname), &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } name = isc_mem_get(peer->mem, sizeof(dns_name_t)); @@ -667,8 +680,9 @@ dns_peer_setkeybycharp(dns_peer_t *peer, const char *keyval) dns_name_dup(dns_fixedname_name(&fname), peer->mem, name); result = dns_peer_setkey(peer, &name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_mem_put(peer->mem, name, sizeof(dns_name_t)); + } return (result); } @@ -699,8 +713,9 @@ dns_peer_gettransfersource(dns_peer_t *peer, isc_sockaddr_t *transfer_source) REQUIRE(DNS_PEER_VALID(peer)); REQUIRE(transfer_source != NULL); - if (peer->transfer_source == NULL) + if (peer->transfer_source == NULL) { return (ISC_R_NOTFOUND); + } *transfer_source = *peer->transfer_source; return (ISC_R_SUCCESS); } @@ -730,8 +745,9 @@ dns_peer_getnotifysource(dns_peer_t *peer, isc_sockaddr_t *notify_source) REQUIRE(DNS_PEER_VALID(peer)); REQUIRE(notify_source != NULL); - if (peer->notify_source == NULL) + if (peer->notify_source == NULL) { return (ISC_R_NOTFOUND); + } *notify_source = *peer->notify_source; return (ISC_R_SUCCESS); } @@ -761,8 +777,9 @@ dns_peer_getquerysource(dns_peer_t *peer, isc_sockaddr_t *query_source) REQUIRE(DNS_PEER_VALID(peer)); REQUIRE(query_source != NULL); - if (peer->query_source == NULL) + if (peer->query_source == NULL) { return (ISC_R_NOTFOUND); + } *query_source = *peer->query_source; return (ISC_R_SUCCESS); } @@ -834,8 +851,9 @@ dns_peer_setpadding(dns_peer_t *peer, uint16_t padding) existed = DNS_BIT_CHECK(SERVER_PADDING_BIT, &peer->bitflags); - if (padding > 512) + if (padding > 512) { padding = 512; + } peer->padding = padding; DNS_BIT_SET(SERVER_PADDING_BIT, &peer->bitflags); @@ -948,6 +966,7 @@ dns_peer_getednsversion(dns_peer_t *peer, uint8_t *ednsversion) if (DNS_BIT_CHECK(EDNS_VERSION_BIT, &peer->bitflags)) { *ednsversion = peer->ednsversion; return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_NOTFOUND); + } } diff --git a/lib/dns/pkcs11.c b/lib/dns/pkcs11.c index 4d5b0b0363..250570920e 100644 --- a/lib/dns/pkcs11.c +++ b/lib/dns/pkcs11.c @@ -29,8 +29,9 @@ dst__pkcs11_toresult(const char *funcname, const char *file, int line, isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_CRYPTO, ISC_LOG_WARNING, "%s:%d: %s: Error = 0x%.8lX\n", file, line, funcname, rv); - if (rv == CKR_HOST_MEMORY) + if (rv == CKR_HOST_MEMORY) { return (ISC_R_NOMEMORY); + } return (fallback); } diff --git a/lib/dns/pkcs11ecdsa_link.c b/lib/dns/pkcs11ecdsa_link.c index 94091c283b..05bc025842 100644 --- a/lib/dns/pkcs11ecdsa_link.c +++ b/lib/dns/pkcs11ecdsa_link.c @@ -86,21 +86,24 @@ pkcs11ecdsa_createctx(dst_key_t *key, dst_context_t *dctx) dctx->key->key_alg == DST_ALG_ECDSA384); REQUIRE(ec != NULL); - if (dctx->key->key_alg == DST_ALG_ECDSA256) + if (dctx->key->key_alg == DST_ALG_ECDSA256) { mech.mechanism = CKM_SHA256; - else + } else { mech.mechanism = CKM_SHA384; + } pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); - if (ec->ontoken && (dctx->use == DO_SIGN)) + if (ec->ontoken && (dctx->use == DO_SIGN)) { slotid = ec->slot; - else + } else { slotid = pk11_get_best_token(OP_ECDSA); + } ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, ec->reqlogon, NULL, slotid); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } PK11_RET(pkcs_C_DigestInit, (pk11_ctx->session, &mech), ISC_R_FAILURE); dctx->ctxdata.pk11_ctx = pk11_ctx; @@ -196,8 +199,9 @@ pkcs11ecdsa_sign(dst_context_t *dctx, isc_buffer_t *sig) ISC_R_FAILURE); isc_buffer_availableregion(sig, &r); - if (r.length < siglen) + if (r.length < siglen) { DST_RET(ISC_R_NOSPACE); + } if (ec->ontoken && (ec->object != CK_INVALID_HANDLE)) { pk11_ctx->ontoken = ec->ontoken; @@ -247,8 +251,9 @@ token_key: err: - if (hKey != CK_INVALID_HANDLE) + if (hKey != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, hKey); + } for (i = 5; i <= 6; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -297,10 +302,11 @@ pkcs11ecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) key->key_alg == DST_ALG_ECDSA384); REQUIRE(ec != NULL); - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { dgstlen = ISC_SHA256_DIGESTLENGTH; - else + } else { dgstlen = ISC_SHA384_DIGESTLENGTH; + } PK11_RET(pkcs_C_DigestFinal, (pk11_ctx->session, digest, &dgstlen), ISC_R_FAILURE); @@ -341,8 +347,9 @@ pkcs11ecdsa_verify(dst_context_t *dctx, const isc_region_t *sig) err: - if (hKey != CK_INVALID_HANDLE) + if (hKey != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, hKey); + } for (i = 5; i <= 6; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -370,30 +377,33 @@ pkcs11ecdsa_compare(const dst_key_t *key1, const dst_key_t *key2) ec1 = key1->keydata.pkey; ec2 = key2->keydata.pkey; - if ((ec1 == NULL) && (ec2 == NULL)) + if ((ec1 == NULL) && (ec2 == NULL)) { return (true); - else if ((ec1 == NULL) || (ec2 == NULL)) + } else if ((ec1 == NULL) || (ec2 == NULL)) { return (false); + } attr1 = pk11_attribute_bytype(ec1, CKA_EC_PARAMS); attr2 = pk11_attribute_bytype(ec2, CKA_EC_PARAMS); - if ((attr1 == NULL) && (attr2 == NULL)) + if ((attr1 == NULL) && (attr2 == NULL)) { return (true); - else if ((attr1 == NULL) || (attr2 == NULL) || - (attr1->ulValueLen != attr2->ulValueLen) || - !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen)) + } else if ((attr1 == NULL) || (attr2 == NULL) || + (attr1->ulValueLen != attr2->ulValueLen) || + !isc_safe_memequal(attr1->pValue, attr2->pValue, + attr1->ulValueLen)) { return (false); + } attr1 = pk11_attribute_bytype(ec1, CKA_EC_POINT); attr2 = pk11_attribute_bytype(ec2, CKA_EC_POINT); - if ((attr1 == NULL) && (attr2 == NULL)) + if ((attr1 == NULL) && (attr2 == NULL)) { return (true); - else if ((attr1 == NULL) || (attr2 == NULL) || - (attr1->ulValueLen != attr2->ulValueLen) || - !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen)) + } else if ((attr1 == NULL) || (attr2 == NULL) || + (attr1->ulValueLen != attr2->ulValueLen) || + !isc_safe_memequal(attr1->pValue, attr2->pValue, + attr1->ulValueLen)) { return (false); + } attr1 = pk11_attribute_bytype(ec1, CKA_VALUE); attr2 = pk11_attribute_bytype(ec2, CKA_VALUE); @@ -401,13 +411,16 @@ pkcs11ecdsa_compare(const dst_key_t *key1, const dst_key_t *key2) ((attr1 == NULL) || (attr2 == NULL) || (attr1->ulValueLen != attr2->ulValueLen) || !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen))) + attr1->ulValueLen))) { return (false); + } - if (!ec1->ontoken && !ec2->ontoken) + if (!ec1->ontoken && !ec2->ontoken) { return (true); - else if (ec1->ontoken || ec2->ontoken || (ec1->object != ec2->object)) + } else if (ec1->ontoken || ec2->ontoken || + (ec1->object != ec2->object)) { return (false); + } return (true); } @@ -476,8 +489,9 @@ pkcs11ecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, false, NULL, pk11_get_best_token(OP_ECDSA)); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); @@ -527,19 +541,22 @@ pkcs11ecdsa_generate(dst_key_t *key, int unused, void (*callback)(int)) memset(pk11_ctx, 0, sizeof(*pk11_ctx)); isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx)); - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { key->key_size = DNS_KEY_ECDSA256SIZE * 4; - else + } else { key->key_size = DNS_KEY_ECDSA384SIZE * 4; + } return (ISC_R_SUCCESS); err: pkcs11ecdsa_destroy(key); - if (priv != CK_INVALID_HANDLE) + if (priv != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, priv); - if (pub != CK_INVALID_HANDLE) + } + if (pub != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, pub); + } pk11_return_session(pk11_ctx); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx)); @@ -553,8 +570,9 @@ pkcs11ecdsa_isprivate(const dst_key_t *key) pk11_object_t *ec = key->keydata.pkey; CK_ATTRIBUTE * attr; - if (ec == NULL) + if (ec == NULL) { return (false); + } attr = pk11_attribute_bytype(ec, CKA_VALUE); return (attr != NULL || ec->ontoken); } @@ -565,8 +583,9 @@ pkcs11ecdsa_destroy(dst_key_t *key) pk11_object_t *ec = key->keydata.pkey; CK_ATTRIBUTE * attr; - if (ec == NULL) + if (ec == NULL) { return; + } INSIST((ec->object == CK_INVALID_HANDLE) || ec->ontoken); @@ -600,22 +619,25 @@ pkcs11ecdsa_todns(const dst_key_t *key, isc_buffer_t *data) REQUIRE(key->keydata.pkey != NULL); - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { len = DNS_KEY_ECDSA256SIZE; - else + } else { len = DNS_KEY_ECDSA384SIZE; + } ec = key->keydata.pkey; attr = pk11_attribute_bytype(ec, CKA_EC_POINT); if ((attr == NULL) || (attr->ulValueLen != len + 3) || (((CK_BYTE_PTR)attr->pValue)[0] != TAG_OCTECT_STRING) || (((CK_BYTE_PTR)attr->pValue)[1] != len + 1) || - (((CK_BYTE_PTR)attr->pValue)[2] != UNCOMPRESSED)) + (((CK_BYTE_PTR)attr->pValue)[2] != UNCOMPRESSED)) { return (ISC_R_FAILURE); + } isc_buffer_availableregion(data, &r); - if (r.length < len) + if (r.length < len) { return (ISC_R_NOSPACE); + } memmove(r.base, (CK_BYTE_PTR)attr->pValue + 3, len); isc_buffer_add(data, len); @@ -633,16 +655,19 @@ pkcs11ecdsa_fromdns(dst_key_t *key, isc_buffer_t *data) REQUIRE(key->key_alg == DST_ALG_ECDSA256 || key->key_alg == DST_ALG_ECDSA384); - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { len = DNS_KEY_ECDSA256SIZE; - else + } else { len = DNS_KEY_ECDSA384SIZE; + } isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); - if (r.length != len) + } + if (r.length != len) { return (DST_R_INVALIDPUBLICKEY); + } ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); @@ -691,8 +716,9 @@ pkcs11ecdsa_tofile(const dst_key_t *key, const char *directory) unsigned int i = 0; CK_ATTRIBUTE * attr; - if (key->keydata.pkey == NULL) + if (key->keydata.pkey == NULL) { return (DST_R_NULLKEY); + } if (key->external) { priv.nelements = 0; @@ -755,8 +781,9 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, pk11_context_t *pk11_ctx = NULL; isc_result_t ret; - if (label == NULL) + if (label == NULL) { return (DST_R_NOENGINE); + } ec = key->keydata.pkey; pubec = pub->keydata.pkey; @@ -785,14 +812,16 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, attr->ulValueLen = pubattr->ulValueLen; ret = pk11_parse_uri(ec, label, key->mctx, OP_ECDSA); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, ec->reqlogon, NULL, ec->slot); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } attr = pk11_attribute_bytype(ec, CKA_LABEL); if (attr == NULL) { @@ -810,10 +839,12 @@ pkcs11ecdsa_fetch(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &ec->object, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } if (engine != NULL) { key->engine = isc_mem_strdup(key->mctx, engine); @@ -849,17 +880,20 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) REQUIRE(key->key_alg == DST_ALG_ECDSA256 || key->key_alg == DST_ALG_ECDSA384); - if ((pub == NULL) || (pub->keydata.pkey == NULL)) + if ((pub == NULL) || (pub->keydata.pkey == NULL)) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_ECDSA256, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } if (key->external) { - if (priv.nelements != 0) + if (priv.nelements != 0) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } key->keydata.pkey = pub->keydata.pkey; pub->keydata.pkey = NULL; @@ -890,8 +924,9 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* Is this key is stored in a HSM? See if we can fetch it. */ if ((label != NULL) || (engine != NULL)) { ret = pkcs11ecdsa_fetch(key, engine, label, pub); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } dst__privstruct_free(&priv, mctx); memset(&priv, 0, sizeof(priv)); return (ret); @@ -925,10 +960,11 @@ pkcs11ecdsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) dst__privstruct_free(&priv, mctx); memset(&priv, 0, sizeof(priv)); - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { key->key_size = DNS_KEY_ECDSA256SIZE * 4; - else + } else { key->key_size = DNS_KEY_ECDSA384SIZE * 4; + } return (ISC_R_SUCCESS); @@ -977,14 +1013,16 @@ pkcs11ecdsa_fromlabel(dst_key_t *key, const char *engine, const char *label, attr[1].type = CKA_EC_POINT; ret = pk11_parse_uri(ec, label, key->mctx, OP_ECDSA); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_ECDSA, true, false, ec->reqlogon, NULL, ec->slot); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } attr = pk11_attribute_bytype(ec, CKA_LABEL); if (attr == NULL) { @@ -1002,10 +1040,12 @@ pkcs11ecdsa_fromlabel(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &hKey, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } attr = ec->repr; PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, hKey, attr, 2), @@ -1025,20 +1065,23 @@ pkcs11ecdsa_fromlabel(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &ec->object, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } if (engine != NULL) { key->engine = isc_mem_strdup(key->mctx, engine); } key->label = isc_mem_strdup(key->mctx, label); - if (key->key_alg == DST_ALG_ECDSA256) + if (key->key_alg == DST_ALG_ECDSA256) { key->key_size = DNS_KEY_ECDSA256SIZE * 4; - else + } else { key->key_size = DNS_KEY_ECDSA384SIZE * 4; + } pk11_return_session(pk11_ctx); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); @@ -1083,8 +1126,9 @@ isc_result_t dst__pkcs11ecdsa_init(dst_func_t **funcp) { REQUIRE(funcp != NULL); - if (*funcp == NULL) + if (*funcp == NULL) { *funcp = &pkcs11ecdsa_functions; + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/pkcs11eddsa_link.c b/lib/dns/pkcs11eddsa_link.c index 234e1b89ef..9dd12f55a8 100644 --- a/lib/dns/pkcs11eddsa_link.c +++ b/lib/dns/pkcs11eddsa_link.c @@ -93,8 +93,9 @@ pkcs11eddsa_destroyctx(dst_context_t *dctx) REQUIRE(dctx->key->key_alg == DST_ALG_ED25519 || dctx->key->key_alg == DST_ALG_ED448); - if (buf != NULL) + if (buf != NULL) { isc_buffer_free(&buf); + } dctx->ctxdata.generic = NULL; } @@ -111,8 +112,9 @@ pkcs11eddsa_adddata(dst_context_t *dctx, const isc_region_t *data) dctx->key->key_alg == DST_ALG_ED448); result = isc_buffer_copyregion(buf, data); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } length = isc_buffer_length(buf) + data->length + 64; isc_buffer_allocate(dctx->mctx, &nbuf, length); @@ -158,25 +160,29 @@ pkcs11eddsa_sign(dst_context_t *dctx, isc_buffer_t *sig) key->key_alg == DST_ALG_ED448); REQUIRE(ec != NULL); - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { siglen = DNS_SIG_ED25519SIZE; - else + } else { siglen = DNS_SIG_ED448SIZE; + } pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); - if (ec->ontoken && (dctx->use == DO_SIGN)) + if (ec->ontoken && (dctx->use == DO_SIGN)) { slotid = ec->slot; - else + } else { slotid = pk11_get_best_token(OP_EC); + } ret = pk11_get_session(pk11_ctx, OP_EC, true, false, ec->reqlogon, NULL, slotid); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } isc_buffer_availableregion(sig, &r); - if (r.length < siglen) + if (r.length < siglen) { DST_RET(ISC_R_NOSPACE); + } if (ec->ontoken && (ec->object != CK_INVALID_HANDLE)) { pk11_ctx->ontoken = ec->ontoken; @@ -228,8 +234,9 @@ token_key: err: - if (hKey != CK_INVALID_HANDLE) + if (hKey != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, hKey); + } for (i = 5; i <= 6; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -282,14 +289,16 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); - if (ec->ontoken && (dctx->use == DO_SIGN)) + if (ec->ontoken && (dctx->use == DO_SIGN)) { slotid = ec->slot; - else + } else { slotid = pk11_get_best_token(OP_EC); + } ret = pk11_get_session(pk11_ctx, OP_EC, true, false, ec->reqlogon, NULL, slotid); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } for (attr = pk11_attribute_first(ec); attr != NULL; attr = pk11_attribute_next(ec, attr)) @@ -329,8 +338,9 @@ pkcs11eddsa_verify(dst_context_t *dctx, const isc_region_t *sig) err: - if (hKey != CK_INVALID_HANDLE) + if (hKey != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, hKey); + } for (i = 5; i <= 6; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -359,30 +369,33 @@ pkcs11eddsa_compare(const dst_key_t *key1, const dst_key_t *key2) ec1 = key1->keydata.pkey; ec2 = key2->keydata.pkey; - if ((ec1 == NULL) && (ec2 == NULL)) + if ((ec1 == NULL) && (ec2 == NULL)) { return (true); - else if ((ec1 == NULL) || (ec2 == NULL)) + } else if ((ec1 == NULL) || (ec2 == NULL)) { return (false); + } attr1 = pk11_attribute_bytype(ec1, CKA_EC_PARAMS); attr2 = pk11_attribute_bytype(ec2, CKA_EC_PARAMS); - if ((attr1 == NULL) && (attr2 == NULL)) + if ((attr1 == NULL) && (attr2 == NULL)) { return (true); - else if ((attr1 == NULL) || (attr2 == NULL) || - (attr1->ulValueLen != attr2->ulValueLen) || - !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen)) + } else if ((attr1 == NULL) || (attr2 == NULL) || + (attr1->ulValueLen != attr2->ulValueLen) || + !isc_safe_memequal(attr1->pValue, attr2->pValue, + attr1->ulValueLen)) { return (false); + } attr1 = pk11_attribute_bytype(ec1, CKA_EC_POINT); attr2 = pk11_attribute_bytype(ec2, CKA_EC_POINT); - if ((attr1 == NULL) && (attr2 == NULL)) + if ((attr1 == NULL) && (attr2 == NULL)) { return (true); - else if ((attr1 == NULL) || (attr2 == NULL) || - (attr1->ulValueLen != attr2->ulValueLen) || - !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen)) + } else if ((attr1 == NULL) || (attr2 == NULL) || + (attr1->ulValueLen != attr2->ulValueLen) || + !isc_safe_memequal(attr1->pValue, attr2->pValue, + attr1->ulValueLen)) { return (false); + } attr1 = pk11_attribute_bytype(ec1, CKA_VALUE); attr2 = pk11_attribute_bytype(ec2, CKA_VALUE); @@ -390,13 +403,16 @@ pkcs11eddsa_compare(const dst_key_t *key1, const dst_key_t *key2) ((attr1 == NULL) || (attr2 == NULL) || (attr1->ulValueLen != attr2->ulValueLen) || !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen))) + attr1->ulValueLen))) { return (false); + } - if (!ec1->ontoken && !ec2->ontoken) + if (!ec1->ontoken && !ec2->ontoken) { return (true); - else if (ec1->ontoken || ec2->ontoken || (ec1->object != ec2->object)) + } else if (ec1->ontoken || ec2->ontoken || + (ec1->object != ec2->object)) { return (false); + } return (true); } @@ -463,8 +479,9 @@ pkcs11eddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_EC, true, false, false, NULL, pk11_get_best_token(OP_EC)); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); @@ -515,19 +532,22 @@ pkcs11eddsa_generate(dst_key_t *key, int unused, void (*callback)(int)) memset(pk11_ctx, 0, sizeof(*pk11_ctx)); isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx)); - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { key->key_size = DNS_KEY_ED25519SIZE; - else + } else { key->key_size = DNS_KEY_ED448SIZE; + } return (ISC_R_SUCCESS); err: pkcs11eddsa_destroy(key); - if (priv != CK_INVALID_HANDLE) + if (priv != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, priv); - if (pub != CK_INVALID_HANDLE) + } + if (pub != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, pub); + } pk11_return_session(pk11_ctx); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx)); @@ -541,10 +561,11 @@ pkcs11eddsa_isprivate(const dst_key_t *key) pk11_object_t *ec = key->keydata.pkey; CK_ATTRIBUTE * attr; - if (ec == NULL) + if (ec == NULL) { return (false); + } attr = pk11_attribute_bytype(ec, CKA_VALUE); - return (attr != NULL || ec->ontoken)); + return((attr != NULL || ec->ontoken))); } static void @@ -553,8 +574,9 @@ pkcs11eddsa_destroy(dst_key_t *key) pk11_object_t *ec = key->keydata.pkey; CK_ATTRIBUTE * attr; - if (ec == NULL) + if (ec == NULL) { return; + } INSIST((ec->object == CK_INVALID_HANDLE) || ec->ontoken); @@ -588,19 +610,22 @@ pkcs11eddsa_todns(const dst_key_t *key, isc_buffer_t *data) REQUIRE(key->keydata.pkey != NULL); - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { len = DNS_KEY_ED25519SIZE; - else + } else { len = DNS_KEY_ED448SIZE; + } ec = key->keydata.pkey; attr = pk11_attribute_bytype(ec, CKA_EC_POINT); - if ((attr == NULL) || (attr->ulValueLen != len)) + if ((attr == NULL) || (attr->ulValueLen != len)) { return (ISC_R_FAILURE); + } isc_buffer_availableregion(data, &r); - if (r.length < len) + if (r.length < len) { return (ISC_R_NOSPACE); + } memmove(r.base, (CK_BYTE_PTR)attr->pValue, len); isc_buffer_add(data, len); @@ -618,16 +643,19 @@ pkcs11eddsa_fromdns(dst_key_t *key, isc_buffer_t *data) REQUIRE(key->key_alg == DST_ALG_ED25519 || key->key_alg == DST_ALG_ED448); - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { len = DNS_KEY_ED25519SIZE; - else + } else { len = DNS_KEY_ED448SIZE; + } isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); - if (r.length != len) + } + if (r.length != len) { return (DST_R_INVALIDPUBLICKEY); + } ec = isc_mem_get(key->mctx, sizeof(*ec)); memset(ec, 0, sizeof(*ec)); @@ -686,8 +714,9 @@ pkcs11eddsa_tofile(const dst_key_t *key, const char *directory) unsigned int i = 0; CK_ATTRIBUTE * attr; - if (key->keydata.pkey == NULL) + if (key->keydata.pkey == NULL) { return (DST_R_NULLKEY); + } if (key->external) { priv.nelements = 0; @@ -750,8 +779,9 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, pk11_context_t *pk11_ctx = NULL; isc_result_t ret; - if (label == NULL) + if (label == NULL) { return (DST_R_NOENGINE); + } ec = key->keydata.pkey; pubec = pub->keydata.pkey; @@ -778,14 +808,16 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, attr->ulValueLen = pubattr->ulValueLen; ret = pk11_parse_uri(ec, label, key->mctx, OP_EC); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_EC, true, false, ec->reqlogon, NULL, ec->slot); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } attr = pk11_attribute_bytype(ec, CKA_LABEL); if (attr == NULL) { @@ -803,10 +835,12 @@ pkcs11eddsa_fetch(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &ec->object, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } if (engine != NULL) { key->engine = isc_mem_strdup(key->mctx, engine); @@ -842,17 +876,20 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) REQUIRE(key->key_alg == DST_ALG_ED25519 || key->key_alg == DST_ALG_ED448); - if ((pub == NULL) || (pub->keydata.pkey == NULL)) + if ((pub == NULL) || (pub->keydata.pkey == NULL)) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_ED25519, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } if (key->external) { - if (priv.nelements != 0) + if (priv.nelements != 0) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } key->keydata.pkey = pub->keydata.pkey; pub->keydata.pkey = NULL; @@ -883,8 +920,9 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* Is this key is stored in a HSM? See if we can fetch it. */ if ((label != NULL) || (engine != NULL)) { ret = pkcs11eddsa_fetch(key, engine, label, pub); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } dst__privstruct_free(&priv, mctx); memset(&priv, 0, sizeof(priv)); return (ret); @@ -918,10 +956,11 @@ pkcs11eddsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) dst__privstruct_free(&priv, mctx); memset(&priv, 0, sizeof(priv)); - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { key->key_size = DNS_KEY_ED25519SIZE; - else + } else { key->key_size = DNS_KEY_ED448SIZE; + } return (ISC_R_SUCCESS); @@ -970,14 +1009,16 @@ pkcs11eddsa_fromlabel(dst_key_t *key, const char *engine, const char *label, attr[1].type = CKA_VALUE; ret = pk11_parse_uri(ec, label, key->mctx, OP_EC); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_EC, true, false, ec->reqlogon, NULL, ec->slot); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } attr = pk11_attribute_bytype(ec, CKA_LABEL); if (attr == NULL) { @@ -995,10 +1036,12 @@ pkcs11eddsa_fromlabel(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &hKey, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } attr = ec->repr; PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, hKey, attr, 2), @@ -1019,20 +1062,23 @@ pkcs11eddsa_fromlabel(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &ec->object, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } if (engine != NULL) { key->engine = isc_mem_strdup(key->mctx, engine); } key->label = isc_mem_strdup(key->mctx, label); - if (key->key_alg == DST_ALG_ED25519) + if (key->key_alg == DST_ALG_ED25519) { key->key_size = DNS_KEY_ED25519SIZE; - else + } else { key->key_size = DNS_KEY_ED448SIZE; + } pk11_return_session(pk11_ctx); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); @@ -1077,8 +1123,9 @@ isc_result_t dst__pkcs11eddsa_init(dst_func_t **funcp) { REQUIRE(funcp != NULL); - if (*funcp == NULL) + if (*funcp == NULL) { *funcp = &pkcs11eddsa_functions; + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/pkcs11rsa_link.c b/lib/dns/pkcs11rsa_link.c index 3d6fd18149..19bf39243e 100644 --- a/lib/dns/pkcs11rsa_link.c +++ b/lib/dns/pkcs11rsa_link.c @@ -34,7 +34,7 @@ */ #ifndef RSA_MAX_PUBEXP_BITS #define RSA_MAX_PUBEXP_BITS 35 -#endif +#endif /* ifndef RSA_MAX_PUBEXP_BITS */ #define DST_RET(a) \ { \ @@ -97,19 +97,23 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (dctx->key->key_size > 4096) + if (dctx->key->key_size > 4096) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((dctx->key->key_size < 512) || (dctx->key->key_size > 4096)) + if ((dctx->key->key_size < 512) || + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ if ((dctx->key->key_size < 1024) || - (dctx->key->key_size > 4096)) + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; default: INSIST(0); @@ -120,14 +124,16 @@ pkcs11rsa_createctx_sign(dst_key_t *key, dst_context_t *dctx) pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); - if (rsa->ontoken) + if (rsa->ontoken) { slotid = rsa->slot; - else + } else { slotid = pk11_get_best_token(OP_RSA); + } ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, slotid); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } if (rsa->ontoken && (rsa->object != CK_INVALID_HANDLE)) { pk11_ctx->ontoken = rsa->ontoken; @@ -241,15 +247,15 @@ token_key: isc_mem_put(dctx->mctx, keyTemplate[i].pValue, keyTemplate[i].ulValueLen); } - } } return (ISC_R_SUCCESS); err: - if (!pk11_ctx->ontoken && (pk11_ctx->object != CK_INVALID_HANDLE)) + if (!pk11_ctx->ontoken && (pk11_ctx->object != CK_INVALID_HANDLE)) { (void)pkcs_C_DestroyObject(pk11_ctx->session, pk11_ctx->object); + } for (i = 6; i <= 13; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -302,19 +308,23 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (dctx->key->key_size > 4096) + if (dctx->key->key_size > 4096) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((dctx->key->key_size < 512) || (dctx->key->key_size > 4096)) + if ((dctx->key->key_size < 512) || + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ if ((dctx->key->key_size < 1024) || - (dctx->key->key_size > 4096)) + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; default: INSIST(0); @@ -326,8 +336,9 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, pk11_get_best_token(OP_RSA)); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } for (attr = pk11_attribute_first(rsa); attr != NULL; attr = pk11_attribute_next(rsa, attr)) @@ -349,8 +360,9 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, keyTemplate[6].ulValueLen = attr->ulValueLen; if (pk11_numbits(attr->pValue, attr->ulValueLen) > maxbits && - maxbits != 0) + maxbits != 0) { DST_RET(DST_R_VERIFYFAILURE); + } break; } pk11_ctx->object = CK_INVALID_HANDLE; @@ -389,15 +401,15 @@ pkcs11rsa_createctx_verify(dst_key_t *key, unsigned int maxbits, isc_mem_put(dctx->mctx, keyTemplate[i].pValue, keyTemplate[i].ulValueLen); } - } } return (ISC_R_SUCCESS); err: - if (!pk11_ctx->ontoken && (pk11_ctx->object != CK_INVALID_HANDLE)) + if (!pk11_ctx->ontoken && (pk11_ctx->object != CK_INVALID_HANDLE)) { (void)pkcs_C_DestroyObject(pk11_ctx->session, pk11_ctx->object); + } for (i = 5; i <= 6; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -418,20 +430,22 @@ err: static isc_result_t pkcs11rsa_createctx(dst_key_t *key, dst_context_t *dctx) { - if (dctx->use == DO_SIGN) + if (dctx->use == DO_SIGN) { return (pkcs11rsa_createctx_sign(key, dctx)); - else + } else { return (pkcs11rsa_createctx_verify(key, 0U, dctx)); + } } static isc_result_t pkcs11rsa_createctx2(dst_key_t *key, int maxbits, dst_context_t *dctx) { - if (dctx->use == DO_SIGN) + if (dctx->use == DO_SIGN) { return (pkcs11rsa_createctx_sign(key, dctx)); - else + } else { return (pkcs11rsa_createctx_verify(key, (unsigned)maxbits, dctx)); + } } static void @@ -441,9 +455,10 @@ pkcs11rsa_destroyctx(dst_context_t *dctx) if (pk11_ctx != NULL) { if (!pk11_ctx->ontoken && - (pk11_ctx->object != CK_INVALID_HANDLE)) + (pk11_ctx->object != CK_INVALID_HANDLE)) { (void)pkcs_C_DestroyObject(pk11_ctx->session, pk11_ctx->object); + } pk11_return_session(pk11_ctx); isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx)); isc_mem_put(dctx->mctx, pk11_ctx, sizeof(*pk11_ctx)); @@ -458,16 +473,17 @@ pkcs11rsa_adddata(dst_context_t *dctx, const isc_region_t *data) pk11_context_t *pk11_ctx = dctx->ctxdata.pk11_ctx; isc_result_t ret = ISC_R_SUCCESS; - if (dctx->use == DO_SIGN) + if (dctx->use == DO_SIGN) { PK11_CALL(pkcs_C_SignUpdate, (pk11_ctx->session, (CK_BYTE_PTR)data->base, (CK_ULONG)data->length), ISC_R_FAILURE); - else + } else { PK11_CALL(pkcs_C_VerifyUpdate, (pk11_ctx->session, (CK_BYTE_PTR)data->base, (CK_ULONG)data->length), ISC_R_FAILURE); + } return (ret); } @@ -485,8 +501,9 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) isc_buffer_availableregion(sig, &r); - if (r.length < (unsigned int)siglen) + if (r.length < (unsigned int)siglen) { return (ISC_R_NOSPACE); + } PK11_RET(pkcs_C_SignFinal, (pk11_ctx->session, (CK_BYTE_PTR)r.base, &siglen), @@ -512,7 +529,7 @@ pkcs11rsa_verify(dst_context_t *dctx, const isc_region_t *sig) return (ret); } -#else +#else /* ifndef PK11_RSA_PKCS_REPLACE */ /* * CKM__RSA_PKCS mechanisms are not available so fall back @@ -555,19 +572,23 @@ pkcs11rsa_createctx(dst_key_t *key, dst_context_t *dctx) case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (dctx->key->key_size > 4096) + if (dctx->key->key_size > 4096) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((dctx->key->key_size < 512) || (dctx->key->key_size > 4096)) + if ((dctx->key->key_size < 512) || + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ if ((dctx->key->key_size < 1024) || - (dctx->key->key_size > 4096)) + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; default: INSIST(0); @@ -592,14 +613,16 @@ pkcs11rsa_createctx(dst_key_t *key, dst_context_t *dctx) pk11_ctx = isc_mem_get(dctx->mctx, sizeof(*pk11_ctx)); memset(pk11_ctx, 0, sizeof(*pk11_ctx)); - if (rsa->ontoken) + if (rsa->ontoken) { slotid = rsa->slot; - else + } else { slotid = pk11_get_best_token(OP_RSA); + } ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, slotid); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } PK11_RET(pkcs_C_DigestInit, (pk11_ctx->session, &mech), ISC_R_FAILURE); dctx->ctxdata.pk11_ctx = pk11_ctx; @@ -696,19 +719,23 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (dctx->key->key_size > 4096) + if (dctx->key->key_size > 4096) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((dctx->key->key_size < 512) || (dctx->key->key_size > 4096)) + if ((dctx->key->key_size < 512) || + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ if ((dctx->key->key_size < 1024) || - (dctx->key->key_size > 4096)) + (dctx->key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; default: INSIST(0); @@ -745,8 +772,9 @@ pkcs11rsa_sign(dst_context_t *dctx, isc_buffer_t *sig) DST_R_SIGNFAILURE); isc_buffer_availableregion(sig, &r); - if (r.length < (unsigned int)dgstlen + MIN_PKCS1_PADLEN) + if (r.length < (unsigned int)dgstlen + MIN_PKCS1_PADLEN) { return (ISC_R_NOSPACE); + } if (rsa->ontoken && (rsa->object != CK_INVALID_HANDLE)) { pk11_ctx->ontoken = rsa->ontoken; @@ -839,8 +867,9 @@ token_key: (pk11_ctx->session, digest, dgstlen, NULL, &siglen), DST_R_SIGNFAILURE); - if (r.length < (unsigned int)siglen) + if (r.length < (unsigned int)siglen) { return (ISC_R_NOSPACE); + } PK11_RET(pkcs_C_Sign, (pk11_ctx->session, digest, dgstlen, (CK_BYTE_PTR)r.base, @@ -850,8 +879,9 @@ token_key: isc_buffer_add(sig, (unsigned int)siglen); err: - if (hKey != CK_INVALID_HANDLE) + if (hKey != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, hKey); + } for (i = 6; i <= 13; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -953,8 +983,9 @@ pkcs11rsa_verify(dst_context_t *dctx, const isc_region_t *sig) attr->ulValueLen); keyTemplate[6].ulValueLen = attr->ulValueLen; if (pk11_numbits(attr->pValue, attr->ulValueLen) > - RSA_MAX_PUBEXP_BITS) + RSA_MAX_PUBEXP_BITS) { DST_RET(DST_R_VERIFYFAILURE); + } break; } pk11_ctx->object = CK_INVALID_HANDLE; @@ -972,8 +1003,9 @@ pkcs11rsa_verify(dst_context_t *dctx, const isc_region_t *sig) DST_R_VERIFYFAILURE); err: - if (hKey != CK_INVALID_HANDLE) + if (hKey != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, hKey); + } for (i = 5; i <= 6; i++) { if (keyTemplate[i].pValue != NULL) { { @@ -991,7 +1023,7 @@ err: return (ret); } -#endif +#endif /* ifndef PK11_RSA_PKCS_REPLACE */ static bool pkcs11rsa_compare(const dst_key_t *key1, const dst_key_t *key2) @@ -1002,30 +1034,33 @@ pkcs11rsa_compare(const dst_key_t *key1, const dst_key_t *key2) rsa1 = key1->keydata.pkey; rsa2 = key2->keydata.pkey; - if ((rsa1 == NULL) && (rsa2 == NULL)) + if ((rsa1 == NULL) && (rsa2 == NULL)) { return (true); - else if ((rsa1 == NULL) || (rsa2 == NULL)) + } else if ((rsa1 == NULL) || (rsa2 == NULL)) { return (false); + } attr1 = pk11_attribute_bytype(rsa1, CKA_MODULUS); attr2 = pk11_attribute_bytype(rsa2, CKA_MODULUS); - if ((attr1 == NULL) && (attr2 == NULL)) + if ((attr1 == NULL) && (attr2 == NULL)) { return (true); - else if ((attr1 == NULL) || (attr2 == NULL) || - (attr1->ulValueLen != attr2->ulValueLen) || - !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen)) + } else if ((attr1 == NULL) || (attr2 == NULL) || + (attr1->ulValueLen != attr2->ulValueLen) || + !isc_safe_memequal(attr1->pValue, attr2->pValue, + attr1->ulValueLen)) { return (false); + } attr1 = pk11_attribute_bytype(rsa1, CKA_PUBLIC_EXPONENT); attr2 = pk11_attribute_bytype(rsa2, CKA_PUBLIC_EXPONENT); - if ((attr1 == NULL) && (attr2 == NULL)) + if ((attr1 == NULL) && (attr2 == NULL)) { return (true); - else if ((attr1 == NULL) || (attr2 == NULL) || - (attr1->ulValueLen != attr2->ulValueLen) || - !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen)) + } else if ((attr1 == NULL) || (attr2 == NULL) || + (attr1->ulValueLen != attr2->ulValueLen) || + !isc_safe_memequal(attr1->pValue, attr2->pValue, + attr1->ulValueLen)) { return (false); + } attr1 = pk11_attribute_bytype(rsa1, CKA_PRIVATE_EXPONENT); attr2 = pk11_attribute_bytype(rsa2, CKA_PRIVATE_EXPONENT); @@ -1033,14 +1068,16 @@ pkcs11rsa_compare(const dst_key_t *key1, const dst_key_t *key2) ((attr1 == NULL) || (attr2 == NULL) || (attr1->ulValueLen != attr2->ulValueLen) || !isc_safe_memequal(attr1->pValue, attr2->pValue, - attr1->ulValueLen))) + attr1->ulValueLen))) { return (false); + } - if (!rsa1->ontoken && !rsa2->ontoken) + if (!rsa1->ontoken && !rsa2->ontoken) { return (true); - else if (rsa1->ontoken || rsa2->ontoken || - (rsa1->object != rsa2->object)) + } else if (rsa1->ontoken || rsa2->ontoken || + (rsa1->object != rsa2->object)) { return (false); + } return (true); } @@ -1090,18 +1127,21 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) case DST_ALG_RSASHA1: case DST_ALG_NSEC3RSASHA1: /* From RFC 3110 */ - if (key->key_size > 4096) + if (key->key_size > 4096) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA256: /* From RFC 5702 */ - if ((key->key_size < 512) || (key->key_size > 4096)) + if ((key->key_size < 512) || (key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; case DST_ALG_RSASHA512: /* From RFC 5702 */ - if ((key->key_size < 1024) || (key->key_size > 4096)) + if ((key->key_size < 1024) || (key->key_size > 4096)) { return (ISC_R_FAILURE); + } break; default: INSIST(0); @@ -1111,8 +1151,9 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, false, NULL, pk11_get_best_token(OP_RSA)); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } bits = key->key_size; if (exp == 0) { @@ -1182,10 +1223,12 @@ pkcs11rsa_generate(dst_key_t *key, int exp, void (*callback)(int)) err: pkcs11rsa_destroy(key); - if (priv != CK_INVALID_HANDLE) + if (priv != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, priv); - if (pub != CK_INVALID_HANDLE) + } + if (pub != CK_INVALID_HANDLE) { (void)pkcs_C_DestroyObject(pk11_ctx->session, pub); + } pk11_return_session(pk11_ctx); isc_safe_memwipe(pk11_ctx, sizeof(*pk11_ctx)); isc_mem_put(key->mctx, pk11_ctx, sizeof(*pk11_ctx)); @@ -1199,8 +1242,9 @@ pkcs11rsa_isprivate(const dst_key_t *key) pk11_object_t *rsa = key->keydata.pkey; CK_ATTRIBUTE * attr; - if (rsa == NULL) + if (rsa == NULL) { return (false); + } attr = pk11_attribute_bytype(rsa, CKA_PRIVATE_EXPONENT); return (attr != NULL || rsa->ontoken); } @@ -1211,8 +1255,9 @@ pkcs11rsa_destroy(dst_key_t *key) pk11_object_t *rsa = key->keydata.pkey; CK_ATTRIBUTE * attr; - if (rsa == NULL) + if (rsa == NULL) { return; + } INSIST((rsa->object == CK_INVALID_HANDLE) || rsa->ontoken); @@ -1276,20 +1321,23 @@ pkcs11rsa_todns(const dst_key_t *key, isc_buffer_t *data) isc_buffer_availableregion(data, &r); if (e_bytes < 256) { /*%< key exponent is <= 2040 bits */ - if (r.length < 1) + if (r.length < 1) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(data, (uint8_t)e_bytes); isc_region_consume(&r, 1); } else { - if (r.length < 3) + if (r.length < 3) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(data, 0); isc_buffer_putuint16(data, (uint16_t)e_bytes); isc_region_consume(&r, 3); } - if (r.length < e_bytes + mod_bytes) + if (r.length < e_bytes + mod_bytes) { return (ISC_R_NOSPACE); + } memmove(r.base, exponent, e_bytes); isc_region_consume(&r, e_bytes); @@ -1311,8 +1359,9 @@ pkcs11rsa_fromdns(dst_key_t *key, isc_buffer_t *data) unsigned int length; isc_buffer_remainingregion(data, &r); - if (r.length == 0) + if (r.length == 0) { return (ISC_R_SUCCESS); + } length = r.length; rsa = isc_mem_get(key->mctx, sizeof(*rsa)); @@ -1379,8 +1428,9 @@ pkcs11rsa_tofile(const dst_key_t *key, const char *directory) unsigned char *bufs[10]; isc_result_t result; - if (key->keydata.pkey == NULL) + if (key->keydata.pkey == NULL) { return (DST_R_NULLKEY); + } if (key->external) { priv.nelements = 0; @@ -1417,8 +1467,9 @@ pkcs11rsa_tofile(const dst_key_t *key, const char *directory) iqmp = attr; break; } - if ((modulus == NULL) || (exponent == NULL)) + if ((modulus == NULL) || (exponent == NULL)) { return (DST_R_NULLKEY); + } memset(bufs, 0, sizeof(bufs)); @@ -1508,8 +1559,9 @@ pkcs11rsa_tofile(const dst_key_t *key, const char *directory) priv.nelements = i; result = dst__privstruct_writefile(key, &priv, directory); for (i = 0; i < 10; i++) { - if (bufs[i] == NULL) + if (bufs[i] == NULL) { break; + } isc_safe_memwipe(bufs[i], modulus->ulValueLen); isc_mem_put(key->mctx, bufs[i], modulus->ulValueLen); } @@ -1537,8 +1589,9 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, pk11_context_t *pk11_ctx = NULL; isc_result_t ret; - if (label == NULL) + if (label == NULL) { return (DST_R_NOENGINE); + } rsa = key->keydata.pkey; pubrsa = pub->keydata.pkey; @@ -1567,14 +1620,16 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, attr->ulValueLen = pubattr->ulValueLen; ret = pk11_parse_uri(rsa, label, key->mctx, OP_RSA); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, rsa->slot); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } attr = pk11_attribute_bytype(rsa, CKA_LABEL); if (attr == NULL) { @@ -1592,10 +1647,12 @@ pkcs11rsa_fetch(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &rsa->object, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } if (engine != NULL) { key->engine = isc_mem_strdup(key->mctx, engine); @@ -1645,10 +1702,12 @@ rsa_check(pk11_object_t *rsa, pk11_object_t *pubrsa) pub_explen = pubattr->ulValueLen; if (priv_exp != NULL) { - if (priv_explen != pub_explen) + if (priv_explen != pub_explen) { return (DST_R_INVALIDPRIVATEKEY); - if (!isc_safe_memequal(priv_exp, pub_exp, pub_explen)) + } + if (!isc_safe_memequal(priv_exp, pub_exp, pub_explen)) { return (DST_R_INVALIDPRIVATEKEY); + } } else { privattr->pValue = pub_exp; privattr->ulValueLen = pub_explen; @@ -1656,8 +1715,9 @@ rsa_check(pk11_object_t *rsa, pk11_object_t *pubrsa) pubattr->ulValueLen = 0; } - if (privattr->pValue == NULL) + if (privattr->pValue == NULL) { return (DST_R_INVALIDPRIVATEKEY); + } privattr = pk11_attribute_bytype(rsa, CKA_MODULUS); INSIST(privattr != NULL); @@ -1670,10 +1730,12 @@ rsa_check(pk11_object_t *rsa, pk11_object_t *pubrsa) pub_modlen = pubattr->ulValueLen; if (priv_mod != NULL) { - if (priv_modlen != pub_modlen) + if (priv_modlen != pub_modlen) { return (DST_R_INVALIDPRIVATEKEY); - if (!isc_safe_memequal(priv_mod, pub_mod, pub_modlen)) + } + if (!isc_safe_memequal(priv_mod, pub_mod, pub_modlen)) { return (DST_R_INVALIDPRIVATEKEY); + } } else { privattr->pValue = pub_mod; privattr->ulValueLen = pub_modlen; @@ -1681,8 +1743,9 @@ rsa_check(pk11_object_t *rsa, pk11_object_t *pubrsa) pubattr->ulValueLen = 0; } - if (privattr->pValue == NULL) + if (privattr->pValue == NULL) { return (DST_R_INVALIDPRIVATEKEY); + } return (ISC_R_SUCCESS); } @@ -1700,14 +1763,17 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* read private key file */ ret = dst__privstruct_parse(key, DST_ALG_RSA, lexer, mctx, &priv); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } if (key->external) { - if (priv.nelements != 0) + if (priv.nelements != 0) { DST_RET(DST_R_INVALIDPRIVATEKEY); - if (pub == NULL) + } + if (pub == NULL) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } key->keydata.pkey = pub->keydata.pkey; pub->keydata.pkey = NULL; @@ -1738,8 +1804,9 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) /* Is this key is stored in a HSM? See if we can fetch it. */ if ((label != NULL) || (engine != NULL)) { ret = pkcs11rsa_fetch(key, engine, label, pub); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } dst__privstruct_free(&priv, mctx); isc_safe_memwipe(&priv, sizeof(priv)); return (ret); @@ -1824,8 +1891,9 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) } } - if (rsa_check(rsa, pub->keydata.pkey) != ISC_R_SUCCESS) + if (rsa_check(rsa, pub->keydata.pkey) != ISC_R_SUCCESS) { DST_RET(DST_R_INVALIDPRIVATEKEY); + } attr = pk11_attribute_bytype(rsa, CKA_MODULUS); INSIST(attr != NULL); @@ -1833,8 +1901,10 @@ pkcs11rsa_parse(dst_key_t *key, isc_lex_t *lexer, dst_key_t *pub) attr = pk11_attribute_bytype(rsa, CKA_PUBLIC_EXPONENT); INSIST(attr != NULL); - if (pk11_numbits(attr->pValue, attr->ulValueLen) > RSA_MAX_PUBEXP_BITS) + if (pk11_numbits(attr->pValue, attr->ulValueLen) > + RSA_MAX_PUBEXP_BITS) { DST_RET(ISC_R_RANGE); + } dst__privstruct_free(&priv, mctx); isc_safe_memwipe(&priv, sizeof(priv)); @@ -1886,14 +1956,16 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, attr[1].type = CKA_PUBLIC_EXPONENT; ret = pk11_parse_uri(rsa, label, key->mctx, OP_RSA); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } pk11_ctx = isc_mem_get(key->mctx, sizeof(*pk11_ctx)); ret = pk11_get_session(pk11_ctx, OP_RSA, true, false, rsa->reqlogon, NULL, rsa->slot); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } attr = pk11_attribute_bytype(rsa, CKA_LABEL); if (attr == NULL) { @@ -1911,10 +1983,12 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &hKey, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } attr = rsa->repr; PK11_RET(pkcs_C_GetAttributeValue, (pk11_ctx->session, hKey, attr, 2), @@ -1934,10 +2008,12 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, (pk11_ctx->session, &rsa->object, (CK_ULONG)1, &cnt), DST_R_CRYPTOFAILURE); (void)pkcs_C_FindObjectsFinal(pk11_ctx->session); - if (cnt == 0) + if (cnt == 0) { DST_RET(ISC_R_NOTFOUND); - if (cnt > 1) + } + if (cnt > 1) { DST_RET(ISC_R_EXISTS); + } if (engine != NULL) { key->engine = isc_mem_strdup(key->mctx, engine); @@ -1947,8 +2023,10 @@ pkcs11rsa_fromlabel(dst_key_t *key, const char *engine, const char *label, attr = pk11_attribute_bytype(rsa, CKA_PUBLIC_EXPONENT); INSIST(attr != NULL); - if (pk11_numbits(attr->pValue, attr->ulValueLen) > RSA_MAX_PUBEXP_BITS) + if (pk11_numbits(attr->pValue, attr->ulValueLen) > + RSA_MAX_PUBEXP_BITS) { DST_RET(ISC_R_RANGE); + } attr = pk11_attribute_bytype(rsa, CKA_MODULUS); INSIST(attr != NULL); @@ -1975,9 +2053,9 @@ static dst_func_t pkcs11rsa_functions = { pkcs11rsa_createctx, #ifndef PK11_RSA_PKCS_REPLACE pkcs11rsa_createctx2, -#else +#else /* ifndef PK11_RSA_PKCS_REPLACE */ NULL, /*%< createctx2 */ -#endif +#endif /* ifndef PK11_RSA_PKCS_REPLACE */ pkcs11rsa_destroyctx, pkcs11rsa_adddata, pkcs11rsa_sign, @@ -2004,8 +2082,9 @@ dst__pkcs11rsa_init(dst_func_t **funcp) { REQUIRE(funcp != NULL); - if (*funcp == NULL) + if (*funcp == NULL) { *funcp = &pkcs11rsa_functions; + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/portlist.c b/lib/dns/portlist.c index d03ebe2d9d..7e2fcde46f 100644 --- a/lib/dns/portlist.c +++ b/lib/dns/portlist.c @@ -56,10 +56,12 @@ compare(const void *arg1, const void *arg2) const dns_element_t *e1 = (const dns_element_t *)arg1; const dns_element_t *e2 = (const dns_element_t *)arg2; - if (e1->port < e2->port) + if (e1->port < e2->port) { return (-1); - if (e1->port > e2->port) + } + if (e1->port > e2->port) { return (1); + } return (0); } @@ -92,25 +94,30 @@ find_port(dns_element_t *list, unsigned int len, in_port_t port) unsigned int last = len; for (;;) { - if (list[xtry].port == port) + if (list[xtry].port == port) { return (&list[xtry]); + } if (port > list[xtry].port) { - if (xtry == max) + if (xtry == max) { break; + } min = xtry; xtry = xtry + (max - xtry + 1) / 2; INSIST(xtry <= max); - if (xtry == last) + if (xtry == last) { break; + } last = min; } else { - if (xtry == min) + if (xtry == min) { break; + } max = xtry; xtry = xtry - (xtry - min + 1) / 2; INSIST(xtry >= min); - if (xtry == last) + if (xtry == last) { break; + } last = max; } } @@ -130,10 +137,11 @@ dns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) if (portlist->active != 0) { el = find_port(portlist->list, portlist->active, port); if (el != NULL) { - if (af == AF_INET) + if (af == AF_INET) { el->flags |= DNS_PL_INET; - else + } else { el->flags |= DNS_PL_INET6; + } result = ISC_R_SUCCESS; goto unlock; } @@ -153,10 +161,11 @@ dns_portlist_add(dns_portlist_t *portlist, int af, in_port_t port) portlist->allocated = allocated; } portlist->list[portlist->active].port = port; - if (af == AF_INET) + if (af == AF_INET) { portlist->list[portlist->active].flags = DNS_PL_INET; - else + } else { portlist->list[portlist->active].flags = DNS_PL_INET6; + } portlist->active++; qsort(portlist->list, portlist->active, sizeof(*el), compare); result = ISC_R_SUCCESS; @@ -177,10 +186,11 @@ dns_portlist_remove(dns_portlist_t *portlist, int af, in_port_t port) if (portlist->active != 0) { el = find_port(portlist->list, portlist->active, port); if (el != NULL) { - if (af == AF_INET) + if (af == AF_INET) { el->flags &= ~DNS_PL_INET; - else + } else { el->flags &= ~DNS_PL_INET6; + } if (el->flags == 0) { *el = portlist->list[portlist->active]; portlist->active--; @@ -204,10 +214,12 @@ dns_portlist_match(dns_portlist_t *portlist, int af, in_port_t port) if (portlist->active != 0) { el = find_port(portlist->list, portlist->active, port); if (el != NULL) { - if (af == AF_INET && (el->flags & DNS_PL_INET) != 0) + if (af == AF_INET && (el->flags & DNS_PL_INET) != 0) { result = true; - if (af == AF_INET6 && (el->flags & DNS_PL_INET6) != 0) + } + if (af == AF_INET6 && (el->flags & DNS_PL_INET6) != 0) { result = true; + } } } UNLOCK(&portlist->lock); @@ -234,10 +246,11 @@ dns_portlist_detach(dns_portlist_t **portlistp) if (isc_refcount_decrement(&portlist->refcount) == 1) { portlist->magic = 0; isc_refcount_destroy(&portlist->refcount); - if (portlist->list != NULL) + if (portlist->list != NULL) { isc_mem_put(portlist->mctx, portlist->list, portlist->allocated * sizeof(*portlist->list)); + } isc_mutex_destroy(&portlist->lock); isc_mem_putanddetach(&portlist->mctx, portlist, sizeof(*portlist)); diff --git a/lib/dns/private.c b/lib/dns/private.c index 46fe1847b4..5673d09883 100644 --- a/lib/dns/private.c +++ b/lib/dns/private.c @@ -70,27 +70,31 @@ ignore(dns_rdata_t *param, dns_rdataset_t *privateset) dns_rdataset_current(privateset, &private); if (!dns_nsec3param_fromprivate(&private, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } /* * We are going to create a new NSEC3 chain so it * doesn't matter if we are removing this one. */ - if (CREATE(rdata.data[1])) + if (CREATE(rdata.data[1])) { return (false); + } if (rdata.data[0] != param->data[0] || rdata.data[2] != param->data[2] || rdata.data[3] != param->data[3] || rdata.data[4] != param->data[4] || - memcmp(&rdata.data[5], ¶m->data[5], param->data[4])) + memcmp(&rdata.data[5], ¶m->data[5], param->data[4])) { continue; + } /* * The removal of this NSEC3 chain does NOT cause a * NSEC chain to be created so we don't need to tell * the caller that it will be removed. */ - if (NONSEC(rdata.data[1])) + if (NONSEC(rdata.data[1])) { return (false); + } return (true); } return (false); @@ -119,20 +123,24 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec, 0, (isc_stdtime_t)0, &nsecset, NULL); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto failure; + } result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3param, 0, (isc_stdtime_t)0, &nsec3paramset, NULL); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto failure; + } if (dns_rdataset_isassociated(&nsecset) && dns_rdataset_isassociated(&nsec3paramset)) { - if (build_nsec != NULL) + if (build_nsec != NULL) { *build_nsec = true; - if (build_nsec3 != NULL) + } + if (build_nsec3 != NULL) { *build_nsec3 = true; + } goto success; } @@ -140,20 +148,24 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, result = dns_db_findrdataset(db, node, ver, privatetype, 0, (isc_stdtime_t)0, &privateset, NULL); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto failure; + } } /* * Look to see if we also need to be creating a NSEC3 chain. */ if (dns_rdataset_isassociated(&nsecset)) { - if (build_nsec != NULL) + if (build_nsec != NULL) { *build_nsec = true; - if (build_nsec3 != NULL) + } + if (build_nsec3 != NULL) { *build_nsec3 = false; - if (!dns_rdataset_isassociated(&privateset)) + } + if (!dns_rdataset_isassociated(&privateset)) { goto success; + } for (result = dns_rdataset_first(&privateset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&privateset)) { @@ -162,24 +174,30 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, dns_rdataset_current(&privateset, &private); if (!dns_nsec3param_fromprivate(&private, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; - if (REMOVE(rdata.data[1])) + } + if (REMOVE(rdata.data[1])) { continue; - if (build_nsec3 != NULL) + } + if (build_nsec3 != NULL) { *build_nsec3 = true; + } break; } goto success; } if (dns_rdataset_isassociated(&nsec3paramset)) { - if (build_nsec3 != NULL) + if (build_nsec3 != NULL) { *build_nsec3 = true; - if (build_nsec != NULL) + } + if (build_nsec != NULL) { *build_nsec = false; - if (!dns_rdataset_isassociated(&privateset)) + } + if (!dns_rdataset_isassociated(&privateset)) { goto success; + } /* * If we are in the process of building a new NSEC3 chain * then we don't need to build a NSEC chain. @@ -192,10 +210,12 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, dns_rdataset_current(&privateset, &private); if (!dns_nsec3param_fromprivate(&private, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; - if (CREATE(rdata.data[1])) + } + if (CREATE(rdata.data[1])) { goto success; + } } /* @@ -212,11 +232,13 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, * If there is more that one NSEC3 chain present then * we don't need to construct a NSEC chain. */ - if (++count > 1) + if (++count > 1) { goto success; + } dns_rdataset_current(&nsec3paramset, &rdata); - if (ignore(&rdata, &privateset)) + if (ignore(&rdata, &privateset)) { continue; + } /* * We still have a good NSEC3 chain or we are * not creating a NSEC chain as NONSEC is set. @@ -228,17 +250,21 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, * The last NSEC3 chain is being removed and does not have * have NONSEC set. */ - if (build_nsec != NULL) + if (build_nsec != NULL) { *build_nsec = true; + } goto success; } - if (build_nsec != NULL) + if (build_nsec != NULL) { *build_nsec = false; - if (build_nsec3 != NULL) + } + if (build_nsec3 != NULL) { *build_nsec3 = false; - if (!dns_rdataset_isassociated(&privateset)) + } + if (!dns_rdataset_isassociated(&privateset)) { goto success; + } signing = false; nsec3chain = false; @@ -256,35 +282,43 @@ dns_private_chains(dns_db_t *db, dns_dbversion_t *ver, * zone with a key. */ if (private.length == 5 && private.data[0] != 0 && - private.data[3] == 0 && private.data[4] == 0) + private.data[3] == 0 && private.data[4] == 0) { signing = true; + } } else { - if (CREATE(rdata.data[1])) + if (CREATE(rdata.data[1])) { nsec3chain = true; + } } } if (signing) { if (nsec3chain) { - if (build_nsec3 != NULL) + if (build_nsec3 != NULL) { *build_nsec3 = true; + } } else { - if (build_nsec != NULL) + if (build_nsec != NULL) { *build_nsec = true; + } } } success: result = ISC_R_SUCCESS; failure: - if (dns_rdataset_isassociated(&nsecset)) + if (dns_rdataset_isassociated(&nsecset)) { dns_rdataset_disassociate(&nsecset); - if (dns_rdataset_isassociated(&nsec3paramset)) + } + if (dns_rdataset_isassociated(&nsec3paramset)) { dns_rdataset_disassociate(&nsec3paramset); - if (dns_rdataset_isassociated(&privateset)) + } + if (dns_rdataset_isassociated(&privateset)) { dns_rdataset_disassociate(&privateset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -293,8 +327,9 @@ dns_private_totext(dns_rdata_t *private, isc_buffer_t *buf) { isc_result_t result; - if (private->length < 5) + if (private->length < 5) { return (ISC_R_NOTFOUND); + } if (private->data[0] == 0) { unsigned char nsec3buf[DNS_NSEC3PARAM_BUFFERSIZE]; @@ -305,8 +340,9 @@ dns_private_totext(dns_rdata_t *private, isc_buffer_t *buf) isc_buffer_t b; if (!dns_nsec3param_fromprivate(private, &rdata, nsec3buf, - sizeof(nsec3buf))) + sizeof(nsec3buf))) { CHECK(ISC_R_FAILURE); + } CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); @@ -318,12 +354,13 @@ dns_private_totext(dns_rdata_t *private, isc_buffer_t *buf) ~(DNS_NSEC3FLAG_CREATE | DNS_NSEC3FLAG_REMOVE | DNS_NSEC3FLAG_INITIAL | DNS_NSEC3FLAG_NONSEC); - if (init) + if (init) { isc_buffer_putstr(buf, "Pending NSEC3 chain "); - else if (del) + } else if (del) { isc_buffer_putstr(buf, "Removing NSEC3 chain "); - else + } else { isc_buffer_putstr(buf, "Creating NSEC3 chain "); + } dns_rdata_reset(&rdata); isc_buffer_init(&b, newbuf, sizeof(newbuf)); @@ -333,8 +370,9 @@ dns_private_totext(dns_rdata_t *private, isc_buffer_t *buf) CHECK(dns_rdata_totext(&rdata, NULL, buf)); - if (del && !nonsec) + if (del && !nonsec) { isc_buffer_putstr(buf, " / creating NSEC chain"); + } } else if (private->length == 5) { unsigned char alg = private->data[0]; dns_keytag_t keyid = (private->data[2] | private->data[1] << 8); @@ -342,20 +380,22 @@ dns_private_totext(dns_rdata_t *private, isc_buffer_t *buf) bool del = private->data[3]; bool complete = private->data[4]; - if (del && complete) + if (del && complete) { isc_buffer_putstr(buf, "Done removing signatures for "); - else if (del) + } else if (del) { isc_buffer_putstr(buf, "Removing signatures for "); - else if (complete) + } else if (complete) { isc_buffer_putstr(buf, "Done signing with "); - else + } else { isc_buffer_putstr(buf, "Signing with "); + } dns_secalg_format(alg, algbuf, sizeof(algbuf)); snprintf(keybuf, sizeof(keybuf), "key %d/%s", keyid, algbuf); isc_buffer_putstr(buf, keybuf); - } else + } else { return (ISC_R_NOTFOUND); + } isc_buffer_putuint8(buf, 0); result = ISC_R_SUCCESS; diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c index a362634767..affbec0486 100644 --- a/lib/dns/rbt.c +++ b/lib/dns/rbt.c @@ -66,7 +66,7 @@ #ifdef RBT_MEM_TEST #undef RBT_HASH_SIZE #define RBT_HASH_SIZE 2 /*%< To give the reallocation code a workout. */ -#endif +#endif /* ifdef RBT_MEM_TEST */ struct dns_rbt { unsigned int magic; @@ -106,7 +106,8 @@ struct file_header { */ uint32_t ptrsize; unsigned int bigendian : 1; /* big or little endian system */ - unsigned int rdataset_fixed : 1; /* compiled with --enable-rrset-fixed + unsigned int rdataset_fixed : 1; /* compiled with + * --enable-rrset-fixed */ unsigned int nodecount; /* shadow from rbt structure */ uint64_t crc; @@ -317,8 +318,9 @@ Name(dns_rbtnode_t *node) dns_name_t name; dns_name_init(&name, NULL); - if (node != NULL) + if (node != NULL) { NODENAME(node, &name); + } return (name); } @@ -361,8 +363,9 @@ get_upper_node(dns_rbtnode_t *node) static void fixup_uppernodes_helper(dns_rbtnode_t *node, dns_rbtnode_t *uppernode) { - if (node == NULL) + if (node == NULL) { return; + } UPPERNODE(node) = uppernode; @@ -387,8 +390,9 @@ dns__rbtnode_getdistance(dns_rbtnode_t *node) size_t nodes = 1; while (node != NULL) { - if (IS_ROOT(node)) + if (IS_ROOT(node)) { break; + } nodes++; node = PARENT(node); } @@ -454,12 +458,14 @@ dns_rbt_zero_header(FILE *file) memset(buffer, 0, HEADER_LENGTH); result = isc_stdio_write(buffer, 1, HEADER_LENGTH, file, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = fflush(file); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (ISC_R_SUCCESS); } @@ -503,9 +509,9 @@ write_header(FILE *file, dns_rbt_t *rbt, uint64_t first_node_offset, #ifdef DNS_RDATASET_FIXED header.rdataset_fixed = 1; -#else +#else /* ifdef DNS_RDATASET_FIXED */ header.rdataset_fixed = 0; -#endif +#endif /* ifdef DNS_RDATASET_FIXED */ header.nodecount = rbt->nodecount; @@ -550,7 +556,7 @@ serialize_node(FILE *file, dns_rbtnode_t *node, uintptr_t left, uintptr_t right, isc_result_t result; #ifdef DEBUG dns_name_t nodename; -#endif +#endif /* ifdef DEBUG */ INSIST(node != NULL); @@ -609,7 +615,7 @@ serialize_node(FILE *file, dns_rbtnode_t *node, uintptr_t left, uintptr_t right, hexdump("node header", (unsigned char *)&temp_node, sizeof(dns_rbtnode_t)); hexdump("node data", node_data, datasize); -#endif +#endif /* ifdef DEBUG */ isc_crc64_update(crc, (const uint8_t *)&temp_node, sizeof(dns_rbtnode_t)); @@ -629,8 +635,9 @@ serialize_nodes(FILE *file, dns_rbtnode_t *node, uintptr_t parent, isc_result_t result; if (node == NULL) { - if (where != NULL) + if (where != NULL) { *where = 0; + } return (ISC_R_SUCCESS); } @@ -675,8 +682,9 @@ serialize_nodes(FILE *file, dns_rbtnode_t *node, uintptr_t parent, /* Ensure we are always at the end of the file. */ CHECK(isc_stdio_seek(file, 0, SEEK_END)); - if (where != NULL) + if (where != NULL) { *where = (uintptr_t)location; + } cleanup: return (result); @@ -687,10 +695,11 @@ dns_rbt_serialize_align(off_t target) { off_t offset = target % 8; - if (offset == 0) + if (offset == 0) { return (target); - else + } else { return (target + 8 - offset); + } } isc_result_t @@ -728,7 +737,7 @@ dns_rbt_serialize_tree(FILE *file, dns_rbt_t *rbt, isc_crc64_final(&crc); #ifdef DEBUG hexdump("serializing CRC", (unsigned char *)&crc, sizeof(crc)); -#endif +#endif /* ifdef DEBUG */ /* Serialize header */ CHECK(isc_stdio_seek(file, header_position, SEEK_SET)); @@ -762,8 +771,9 @@ treefix(dns_rbt_t *rbt, void *base, size_t filesize, dns_rbtnode_t *n, dns_rbtnode_t header; size_t datasize, nodemax = filesize - sizeof(dns_rbtnode_t); - if (n == NULL) + if (n == NULL) { return (ISC_R_SUCCESS); + } CONFIRM((void *)n >= base); CONFIRM((char *)n - (char *)base <= (int)nodemax); @@ -788,16 +798,18 @@ treefix(dns_rbt_t *rbt, void *base, size_t filesize, dns_rbtnode_t *n, n->left = getleft(n, rbt->mmap_location); n->left_is_relative = 0; CONFIRM(DNS_RBTNODE_VALID(n->left)); - } else + } else { CONFIRM(n->left == NULL); + } if (n->right_is_relative) { CONFIRM(n->right <= (dns_rbtnode_t *)nodemax); n->right = getright(n, rbt->mmap_location); n->right_is_relative = 0; CONFIRM(DNS_RBTNODE_VALID(n->right)); - } else + } else { CONFIRM(n->right == NULL); + } if (n->down_is_relative) { CONFIRM(n->down <= (dns_rbtnode_t *)nodemax); @@ -805,8 +817,9 @@ treefix(dns_rbt_t *rbt, void *base, size_t filesize, dns_rbtnode_t *n, n->down_is_relative = 0; CONFIRM(n->down > (dns_rbtnode_t *)n); CONFIRM(DNS_RBTNODE_VALID(n->down)); - } else + } else { CONFIRM(n->down == NULL); + } if (n->parent_is_relative) { CONFIRM(n->parent <= (dns_rbtnode_t *)nodemax); @@ -814,32 +827,38 @@ treefix(dns_rbt_t *rbt, void *base, size_t filesize, dns_rbtnode_t *n, n->parent_is_relative = 0; CONFIRM(n->parent < (dns_rbtnode_t *)n); CONFIRM(DNS_RBTNODE_VALID(n->parent)); - } else + } else { CONFIRM(n->parent == NULL); + } if (n->data_is_relative) { CONFIRM(n->data <= (void *)filesize); n->data = getdata(n, rbt->mmap_location); n->data_is_relative = 0; CONFIRM(n->data > (void *)n); - } else + } else { CONFIRM(n->data == NULL); + } hash_node(rbt, n, fullname); /* a change in the order (from left, right, down) will break hashing*/ - if (n->left != NULL) + if (n->left != NULL) { CHECK(treefix(rbt, base, filesize, n->left, name, datafixer, fixer_arg, crc)); - if (n->right != NULL) + } + if (n->right != NULL) { CHECK(treefix(rbt, base, filesize, n->right, name, datafixer, fixer_arg, crc)); - if (n->down != NULL) + } + if (n->down != NULL) { CHECK(treefix(rbt, base, filesize, n->down, fullname, datafixer, fixer_arg, crc)); + } - if (datafixer != NULL && n->data != NULL) + if (datafixer != NULL && n->data != NULL) { CHECK(datafixer(n, base, filesize, fixer_arg, crc)); + } rbt->nodecount++; node_data = (unsigned char *)n + sizeof(dns_rbtnode_t); @@ -851,7 +870,7 @@ treefix(dns_rbt_t *rbt, void *base, size_t filesize, dns_rbtnode_t *n, fprintf(stderr, "\n"); hexdump("node header", (unsigned char *)&header, sizeof(dns_rbtnode_t)); hexdump("node data", node_data, datasize); -#endif +#endif /* ifdef DEBUG */ isc_crc64_update(crc, (const uint8_t *)&header, sizeof(dns_rbtnode_t)); isc_crc64_update(crc, (const uint8_t *)node_data, datasize); @@ -893,12 +912,12 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize, goto cleanup; } -#else +#else /* ifdef DNS_RDATASET_FIXED */ if (header->rdataset_fixed != 0) { result = ISC_R_INVALIDFILE; goto cleanup; } -#endif +#endif /* ifdef DNS_RDATASET_FIXED */ if (header->ptrsize != (uint32_t)sizeof(void *)) { result = ISC_R_INVALIDFILE; @@ -927,7 +946,7 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize, isc_crc64_final(&crc); #ifdef DEBUG hexdump("deserializing CRC", (unsigned char *)&crc, sizeof(crc)); -#endif +#endif /* ifdef DEBUG */ /* Check file hash */ if (header->crc != crc) { @@ -943,8 +962,9 @@ dns_rbt_deserialize_tree(void *base_address, size_t filesize, fixup_uppernodes(rbt); *rbtp = rbt; - if (originp != NULL) + if (originp != NULL) { *originp = rbt->root; + } cleanup: if (result != ISC_R_SUCCESS && rbt != NULL) { @@ -1014,8 +1034,9 @@ dns_rbt_destroy2(dns_rbt_t **rbtp, unsigned int quantum) rbt = *rbtp; deletetreeflat(rbt, quantum, false, &rbt->root); - if (rbt->root != NULL) + if (rbt->root != NULL) { return (ISC_R_QUOTA); + } *rbtp = NULL; @@ -1023,9 +1044,10 @@ dns_rbt_destroy2(dns_rbt_t **rbtp, unsigned int quantum) rbt->mmap_location = NULL; - if (rbt->hashtable != NULL) + if (rbt->hashtable != NULL) { isc_mem_put(rbt->mctx, rbt->hashtable, rbt->hashsize * sizeof(dns_rbtnode_t *)); + } rbt->magic = 0; @@ -1061,15 +1083,17 @@ chain_name(dns_rbtnodechain_t *chain, dns_name_t *name, bool include_chain_end) if (include_chain_end && chain->end != NULL) { NODENAME(chain->end, &nodename); dns_name_copynf(&nodename, name); - } else + } else { dns_name_reset(name); + } for (i = (int)chain->level_count - 1; i >= 0; i--) { NODENAME(chain->levels[i], &nodename); result = dns_name_concatenate(name, &nodename, name, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (result); } @@ -1082,11 +1106,13 @@ move_chain_to_last(dns_rbtnodechain_t *chain, dns_rbtnode_t *node) * Go as far right and then down as much as possible, * as long as the rightmost node has a down pointer. */ - while (RIGHT(node) != NULL) + while (RIGHT(node) != NULL) { node = RIGHT(node); + } - if (DOWN(node) == NULL) + if (DOWN(node) == NULL) { break; + } ADD_LEVEL(chain, node); node = DOWN(node); @@ -1211,12 +1237,10 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) if (order < 0) { parent = current; child = LEFT(current); - } else if (order > 0) { parent = current; child = RIGHT(current); } - } else { /* * This name has some suffix in common with the @@ -1291,18 +1315,20 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) result = create_node(rbt->mctx, suffix, &new_current); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } /* * Reproduce the tree attributes of the * current node. */ new_current->is_root = current->is_root; - if (current->nsec == DNS_RBT_NSEC_HAS_NSEC) + if (current->nsec == DNS_RBT_NSEC_HAS_NSEC) { new_current->nsec = DNS_RBT_NSEC_NORMAL; - else + } else { new_current->nsec = current->nsec; + } PARENT(new_current) = PARENT(current); LEFT(new_current) = LEFT(current); RIGHT(new_current) = RIGHT(current); @@ -1312,18 +1338,22 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) * Fix pointers that were to the current node. */ if (parent != NULL) { - if (LEFT(parent) == current) + if (LEFT(parent) == current) { LEFT(parent) = new_current; - else + } else { RIGHT(parent) = new_current; + } } - if (LEFT(new_current) != NULL) + if (LEFT(new_current) != NULL) { PARENT(LEFT(new_current)) = new_current; - if (RIGHT(new_current) != NULL) + } + if (RIGHT(new_current) != NULL) { PARENT(RIGHT(new_current)) = new_current; - if (*root == current) + } + if (*root == current) { *root = new_current; + } NAMELEN(current) = prefix->length; OFFSETLEN(current) = prefix->labels; @@ -1365,7 +1395,6 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) */ *nodep = new_current; return (ISC_R_SUCCESS); - } else { /* * The current node has no data, @@ -1389,11 +1418,11 @@ dns_rbt_addnode(dns_rbt_t *rbt, const dns_name_t *name, dns_rbtnode_t **nodep) } } } - } while (ISC_LIKELY(child != NULL)); - if (ISC_LIKELY(result == ISC_R_SUCCESS)) + if (ISC_LIKELY(result == ISC_R_SUCCESS)) { result = create_node(rbt->mctx, add_name, &new_current); + } if (ISC_LIKELY(result == ISC_R_SUCCESS)) { if (*root == NULL) { @@ -1476,11 +1505,13 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, options |= DNS_RBTFIND_NOPREDECESSOR; chain = &localchain; dns_rbtnodechain_init(chain); - } else + } else { dns_rbtnodechain_reset(chain); + } - if (ISC_UNLIKELY(rbt->root == NULL)) + if (ISC_UNLIKELY(rbt->root == NULL)) { return (ISC_R_NOTFOUND); + } /* * Appease GCC about variables it incorrectly thinks are @@ -1520,8 +1551,9 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, */ last_compared = current; - if (compared == dns_namereln_equal) + if (compared == dns_namereln_equal) { break; + } if (compared == dns_namereln_none) { /* @@ -1586,8 +1618,9 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, hnode != NULL; hnode = hnode->hashnext) { dns_name_t hnode_name; - if (ISC_LIKELY(hash != HASHVAL(hnode))) + if (ISC_LIKELY(hash != HASHVAL(hnode))) { continue; + } /* * This checks that the hashed label * sequence being looked up is at the @@ -1630,8 +1663,9 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, } } - if (tlabels++ < nlabels) + if (tlabels++ < nlabels) { goto hashagain; + } /* * All of the labels have been tried against the hash @@ -1740,16 +1774,18 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, chain->end = current; chain->level_matches = chain->level_count; - if (foundname != NULL) + if (foundname != NULL) { result = chain_name(chain, foundname, true); - else + } else { result = ISC_R_SUCCESS; + } if (result == ISC_R_SUCCESS) { *node = current; result = saved_result; - } else + } else { *node = NULL; + } } else { /* * Did not find an exact match (or did not want one). @@ -1780,14 +1816,16 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, result = chain_name(chain, foundname, false); chain->level_count = saved_count; - } else + } else { result = ISC_R_SUCCESS; + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_PARTIALMATCH; - - } else + } + } else { result = ISC_R_NOTFOUND; + } if (current != NULL) { /* @@ -1805,13 +1843,11 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, ((options & DNS_RBTFIND_EMPTYDATA) == 0 && DATA(current) == NULL)); chain->end = current; - } else if ((options & DNS_RBTFIND_NOPREDECESSOR) != 0) { /* * Ensure the chain points nowhere. */ chain->end = NULL; - } else { /* * Since there was no exact match, the chain argument @@ -1832,7 +1868,6 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, chain->level_count); chain->end = chain->levels[--chain->level_count]; - } else { isc_result_t result2; @@ -1853,10 +1888,11 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, * the while loop in one more level of * indentation. */ - if (compared == dns_namereln_none) + if (compared == dns_namereln_none) { current = last_compared; - else + } else { current = NULL; + } while (current != NULL) { NODENAME(current, ¤t_name); @@ -1870,10 +1906,11 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, /* * Standard binary search movement. */ - if (order < 0) + if (order < 0) { current = LEFT(current); - else + } else { current = RIGHT(current); + } } current = last_compared; @@ -1911,16 +1948,17 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, result2 = move_chain_to_last( chain, DOWN(current)); - if (result2 != ISC_R_SUCCESS) + if (result2 != ISC_R_SUCCESS) { result = result2; - } else + } + } else { /* * Ah, the pure and simple * case. The stop node is the * predecessor. */ chain->end = current; - + } } else { INSIST(order < 0); @@ -1929,15 +1967,16 @@ dns_rbt_findnode(dns_rbt_t *rbt, const dns_name_t *name, dns_name_t *foundname, result2 = dns_rbtnodechain_prev( chain, NULL, NULL); if (result2 == ISC_R_SUCCESS || - result2 == DNS_R_NEWORIGIN) - ; /* Nothing. */ - else if (result2 == ISC_R_NOMORE) + result2 == DNS_R_NEWORIGIN) { + /* Nothing. */ + } else if (result2 == ISC_R_NOMORE) { /* * There is no predecessor. */ dns_rbtnodechain_reset(chain); - else + } else { result = result2; + } } } } @@ -1964,10 +2003,11 @@ dns_rbt_findname(dns_rbt_t *rbt, const dns_name_t *name, unsigned int options, NULL, NULL); if (node != NULL && - (DATA(node) != NULL || (options & DNS_RBTFIND_EMPTYDATA) != 0)) + (DATA(node) != NULL || (options & DNS_RBTFIND_EMPTYDATA) != 0)) { *data = DATA(node); - else + } else { result = ISC_R_NOTFOUND; + } return (result); } @@ -2002,13 +2042,14 @@ dns_rbt_deletename(dns_rbt_t *rbt, const dns_name_t *name, bool recurse) DNS_RBTFIND_NOOPTIONS, NULL, NULL); if (result == ISC_R_SUCCESS) { - if (DATA(node) != NULL) + if (DATA(node) != NULL) { result = dns_rbt_deletenode(rbt, node, recurse); - else + } else { result = ISC_R_NOTFOUND; - - } else if (result == DNS_R_PARTIALMATCH) + } + } else if (result == DNS_R_PARTIALMATCH) { result = ISC_R_NOTFOUND; + } return (result); } @@ -2063,8 +2104,9 @@ dns_rbt_deletenode(dns_rbt_t *rbt, dns_rbtnode_t *node, bool recurse) PARENT(DOWN(node)) = NULL; deletetreeflat(rbt, 0, true, &DOWN(node)); } else { - if (DATA(node) != NULL && rbt->data_deleter != NULL) + if (DATA(node) != NULL && rbt->data_deleter != NULL) { rbt->data_deleter(DATA(node), rbt->deleter_arg); + } DATA(node) = NULL; /* @@ -2093,13 +2135,14 @@ dns_rbt_deletenode(dns_rbt_t *rbt, dns_rbtnode_t *node, bool recurse) */ deletefromlevel(node, parent == NULL ? &rbt->root : &DOWN(parent)); - if (DATA(node) != NULL && rbt->data_deleter != NULL) + if (DATA(node) != NULL && rbt->data_deleter != NULL) { rbt->data_deleter(DATA(node), rbt->deleter_arg); + } unhash_node(rbt, node); #if DNS_RBT_USEMAGIC node->magic = 0; -#endif +#endif /* if DNS_RBT_USEMAGIC */ isc_refcount_destroy(&node->references); freenode(rbt, &node); @@ -2139,8 +2182,9 @@ dns_rbt_fullnamefromnode(dns_rbtnode_t *node, dns_name_t *name) NODENAME(node, ¤t); result = dns_name_concatenate(name, ¤t, name, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } node = get_upper_node(node); } while (!dns_name_isabsolute(name)); @@ -2160,11 +2204,12 @@ dns_rbt_formatnodename(dns_rbtnode_t *node, char *printname, unsigned int size) name = dns_fixedname_initname(&fixedname); result = dns_rbt_fullnamefromnode(node, name); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_name_format(name, printname, size); - else + } else { snprintf(printname, size, "", dns_result_totext(result)); + } return (printname); } @@ -2241,7 +2286,7 @@ create_node(isc_mem_t *mctx, const dns_name_t *name, dns_rbtnode_t **nodep) #if DNS_RBT_USEMAGIC node->magic = DNS_RBTNODE_MAGIC; -#endif +#endif /* if DNS_RBT_USEMAGIC */ *nodep = node; return (ISC_R_SUCCESS); @@ -2304,8 +2349,9 @@ rehash(dns_rbt_t *rbt, unsigned int newcount) rbt->hashtable = isc_mem_get(rbt->mctx, rbt->hashsize * sizeof(dns_rbtnode_t *)); - for (i = 0; i < rbt->hashsize; i++) + for (i = 0; i < rbt->hashsize; i++) { rbt->hashtable[i] = NULL; + } for (i = 0; i < oldsize; i++) { for (node = oldtable[i]; node != NULL; node = nextnode) { @@ -2328,8 +2374,9 @@ hash_node(dns_rbt_t *rbt, dns_rbtnode_t *node, const dns_name_t *name) { REQUIRE(DNS_RBTNODE_VALID(node)); - if (rbt->nodecount >= (rbt->hashsize * 3)) + if (rbt->nodecount >= (rbt->hashsize * 3)) { rehash(rbt, rbt->nodecount); + } hash_add_node(rbt, node, name); } @@ -2371,8 +2418,9 @@ rotate_left(dns_rbtnode_t *node, dns_rbtnode_t **rootp) INSIST(child != NULL); RIGHT(node) = LEFT(child); - if (LEFT(child) != NULL) + if (LEFT(child) != NULL) { PARENT(LEFT(child)) = node; + } LEFT(child) = node; PARENT(child) = PARENT(node); @@ -2381,12 +2429,12 @@ rotate_left(dns_rbtnode_t *node, dns_rbtnode_t **rootp) *rootp = child; child->is_root = 1; node->is_root = 0; - } else { - if (LEFT(PARENT(node)) == node) + if (LEFT(PARENT(node)) == node) { LEFT(PARENT(node)) = child; - else + } else { RIGHT(PARENT(node)) = child; + } } PARENT(node) = child; @@ -2404,8 +2452,9 @@ rotate_right(dns_rbtnode_t *node, dns_rbtnode_t **rootp) INSIST(child != NULL); LEFT(node) = RIGHT(child); - if (RIGHT(child) != NULL) + if (RIGHT(child) != NULL) { PARENT(RIGHT(child)) = node; + } RIGHT(child) = node; PARENT(child) = PARENT(node); @@ -2414,12 +2463,12 @@ rotate_right(dns_rbtnode_t *node, dns_rbtnode_t **rootp) *rootp = child; child->is_root = 1; node->is_root = 0; - } else { - if (LEFT(PARENT(node)) == node) + if (LEFT(PARENT(node)) == node) { LEFT(PARENT(node)) = child; - else + } else { RIGHT(PARENT(node)) = child; + } } PARENT(node) = child; @@ -2562,18 +2611,18 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) *rootp = NULL; return; } - } else + } else { /* * This node has one child, on the right. */ child = RIGHT(item); - - } else if (RIGHT(item) == NULL) + } + } else if (RIGHT(item) == NULL) { /* * This node has one child, on the left. */ child = LEFT(item); - else { + } else { dns_rbtnode_t holder, *tmp = &holder; /* @@ -2583,15 +2632,17 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) * old site of the successor. */ successor = RIGHT(item); - while (LEFT(successor) != NULL) + while (LEFT(successor) != NULL) { successor = LEFT(successor); + } /* * The successor cannot possibly have a left child; * if there is any child, it is on the right. */ - if (RIGHT(successor) != NULL) + if (RIGHT(successor) != NULL) { child = RIGHT(successor); + } /* * Swap the two nodes; it would be simpler to just replace @@ -2614,21 +2665,23 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) *rootp = successor; successor->is_root = true; item->is_root = false; - - } else if (LEFT(PARENT(item)) == item) + } else if (LEFT(PARENT(item)) == item) { LEFT(PARENT(item)) = successor; - else + } else { RIGHT(PARENT(item)) = successor; + } PARENT(successor) = PARENT(item); LEFT(successor) = LEFT(item); RIGHT(successor) = RIGHT(item); COLOR(successor) = COLOR(item); - if (LEFT(successor) != NULL) + if (LEFT(successor) != NULL) { PARENT(LEFT(successor)) = successor; - if (RIGHT(successor) != successor) + } + if (RIGHT(successor) != successor) { PARENT(RIGHT(successor)) = successor; + } /* * Now relink the node to be deleted into the @@ -2643,7 +2696,6 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) */ RIGHT(successor) = item; PARENT(item) = successor; - } else { LEFT(PARENT(tmp)) = item; PARENT(item) = PARENT(tmp); @@ -2661,14 +2713,15 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) * Remove the node by removing the links from its parent. */ if (!IS_ROOT(item)) { - if (LEFT(PARENT(item)) == item) + if (LEFT(PARENT(item)) == item) { LEFT(PARENT(item)) = child; - else + } else { RIGHT(PARENT(item)) = child; + } - if (child != NULL) + if (child != NULL) { PARENT(child) = PARENT(item); - + } } else { /* * This is the root being deleted, and at this point @@ -2708,7 +2761,6 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) IS_BLACK(RIGHT(sibling))) { MAKE_RED(sibling); child = parent; - } else { if (IS_BLACK(RIGHT(sibling))) { MAKE_BLACK(LEFT(sibling)); @@ -2724,7 +2776,6 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) rotate_left(parent, rootp); child = *rootp; } - } else { /* * Child is parent's right child. @@ -2748,7 +2799,6 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) IS_BLACK(RIGHT(sibling))) { MAKE_RED(sibling); child = parent; - } else { if (IS_BLACK(LEFT(sibling))) { MAKE_BLACK(RIGHT(sibling)); @@ -2769,8 +2819,9 @@ deletefromlevel(dns_rbtnode_t *item, dns_rbtnode_t **rootp) parent = PARENT(child); } - if (IS_RED(child)) + if (IS_RED(child)) { MAKE_BLACK(child); + } } } @@ -2818,20 +2869,23 @@ deletetreeflat(dns_rbt_t *rbt, unsigned int quantum, bool unhash, dns_rbtnode_t *node = root; root = PARENT(root); - if (DATA(node) != NULL && rbt->data_deleter != NULL) + if (DATA(node) != NULL && rbt->data_deleter != NULL) { rbt->data_deleter(DATA(node), rbt->deleter_arg); - if (unhash) + } + if (unhash) { unhash_node(rbt, node); - /* - * Note: we don't call unhash_node() here as we - * are destroying the complete RBT tree. - */ + } + /* + * Note: we don't call unhash_node() here as we + * are destroying the complete RBT tree. + */ #if DNS_RBT_USEMAGIC node->magic = 0; -#endif +#endif /* if DNS_RBT_USEMAGIC */ freenode(rbt, &node); - if (quantum != 0 && --quantum == 0) + if (quantum != 0 && --quantum == 0) { break; + } } } @@ -2844,8 +2898,9 @@ getheight_helper(dns_rbtnode_t *node) size_t dl, dr; size_t this_height, down_height; - if (node == NULL) + if (node == NULL) { return (0); + } dl = getheight_helper(LEFT(node)); dr = getheight_helper(RIGHT(node)); @@ -2865,29 +2920,35 @@ dns__rbt_getheight(dns_rbt_t *rbt) static bool check_properties_helper(dns_rbtnode_t *node) { - if (node == NULL) + if (node == NULL) { return (true); + } if (IS_RED(node)) { /* Root nodes must be BLACK. */ - if (IS_ROOT(node)) + if (IS_ROOT(node)) { return (false); + } /* Both children of RED nodes must be BLACK. */ - if (IS_RED(LEFT(node)) || IS_RED(RIGHT(node))) + if (IS_RED(LEFT(node)) || IS_RED(RIGHT(node))) { return (false); + } } /* cppcheck-suppress nullPointerRedundantCheck symbolName=node */ - if ((DOWN(node) != NULL) && (!IS_ROOT(DOWN(node)))) + if ((DOWN(node) != NULL) && (!IS_ROOT(DOWN(node)))) { return (false); + } if (IS_ROOT(node)) { - if ((PARENT(node) != NULL) && (DOWN(PARENT(node)) != node)) + if ((PARENT(node) != NULL) && (DOWN(PARENT(node)) != node)) { return (false); + } - if (get_upper_node(node) != PARENT(node)) + if (get_upper_node(node) != PARENT(node)) { return (false); + } } /* If node is assigned to the down_ pointer of its parent, it is @@ -2915,23 +2976,28 @@ check_black_distance_helper(dns_rbtnode_t *node, size_t *distance) } /* cppcheck-suppress nullPointerRedundantCheck symbolName=node */ - if (!check_black_distance_helper(LEFT(node), &dl)) + if (!check_black_distance_helper(LEFT(node), &dl)) { return (false); + } /* cppcheck-suppress nullPointerRedundantCheck symbolName=node */ - if (!check_black_distance_helper(RIGHT(node), &dr)) + if (!check_black_distance_helper(RIGHT(node), &dr)) { return (false); + } /* cppcheck-suppress nullPointerRedundantCheck symbolName=node */ - if (!check_black_distance_helper(DOWN(node), &dd)) + if (!check_black_distance_helper(DOWN(node), &dd)) { return (false); + } /* Left and right side black node counts must match. */ - if (dl != dr) + if (dl != dr) { return (false); + } - if (IS_BLACK(node)) + if (IS_BLACK(node)) { dl++; + } *distance = dl; @@ -2943,8 +3009,9 @@ dns__rbt_checkproperties(dns_rbt_t *rbt) { size_t dd; - if (!check_properties_helper(rbt->root)) + if (!check_properties_helper(rbt->root)) { return (false); + } /* Path from a given node to all its leaves must contain the * same number of BLACK child nodes. This is done separately @@ -2961,8 +3028,9 @@ dns_rbt_indent(FILE *f, int depth) fprintf(f, "%4d ", depth); - for (i = 0; i < depth; i++) + for (i = 0; i < depth; i++) { fprintf(f, "- "); + } } void @@ -3011,10 +3079,11 @@ printnodename(dns_rbtnode_t *node, bool quoted, FILE *f) dns_name_format(&name, buffer, sizeof(buffer)); - if (quoted) + if (quoted) { fprintf(f, "\"%s\"", buffer); - else + } else { fprintf(f, "%s", buffer); + } } static void @@ -3037,10 +3106,11 @@ print_text_helper(dns_rbtnode_t *root, dns_rbtnode_t *parent, int depth, (IS_ROOT(root) && depth > 0 && DOWN(PARENT(root)) != root)) { fprintf(f, " (BAD parent pointer! -> "); - if (PARENT(root) != NULL) + if (PARENT(root) != NULL) { printnodename(PARENT(root), true, f); - else + } else { fprintf(f, "NULL"); + } fprintf(f, ")"); } @@ -3094,8 +3164,9 @@ print_dot_helper(dns_rbtnode_t *node, unsigned int *nodecount, { unsigned int l, r, d; - if (node == NULL) + if (node == NULL) { return (0); + } l = print_dot_helper(LEFT(node), nodecount, show_pointers, f); r = print_dot_helper(RIGHT(node), nodecount, show_pointers, f); @@ -3107,36 +3178,43 @@ print_dot_helper(dns_rbtnode_t *node, unsigned int *nodecount, printnodename(node, false, f); fprintf(f, "|"); - if (show_pointers) + if (show_pointers) { fprintf(f, "| n=%p| p=%p", node, PARENT(node)); + } fprintf(f, "\"] ["); - if (IS_RED(node)) + if (IS_RED(node)) { fprintf(f, "color=red"); - else + } else { fprintf(f, "color=black"); + } /* XXXMUKS: verify that IS_ROOT() indicates subtree root and not * forest root. */ - if (IS_ROOT(node)) + if (IS_ROOT(node)) { fprintf(f, ",penwidth=3"); + } - if (IS_EMPTY(node)) + if (IS_EMPTY(node)) { fprintf(f, ",style=filled,fillcolor=lightgrey"); + } fprintf(f, "];\n"); - if (LEFT(node) != NULL) + if (LEFT(node) != NULL) { fprintf(f, "\"node%u\":f0 -> \"node%u\":f1;\n", *nodecount, l); + } - if (DOWN(node) != NULL) + if (DOWN(node) != NULL) { fprintf(f, "\"node%u\":f1 -> \"node%u\":f1 [penwidth=5];\n", *nodecount, d); + } - if (RIGHT(node) != NULL) + if (RIGHT(node) != NULL) { fprintf(f, "\"node%u\":f2 -> \"node%u\":f1;\n", *nodecount, r); + } return (*nodecount); } @@ -3182,11 +3260,13 @@ dns_rbtnodechain_current(dns_rbtnodechain_t *chain, dns_name_t *name, REQUIRE(VALID_CHAIN(chain)); - if (node != NULL) + if (node != NULL) { *node = chain->end; + } - if (chain->end == NULL) + if (chain->end == NULL) { return (ISC_R_NOTFOUND); + } if (name != NULL) { NODENAME(chain->end, name); @@ -3239,11 +3319,11 @@ dns_rbtnodechain_prev(dns_rbtnodechain_t *chain, dns_name_t *name, */ current = LEFT(current); - while (RIGHT(current) != NULL) + while (RIGHT(current) != NULL) { current = RIGHT(current); + } predecessor = current; - } else { /* * No left links, so move toward the root. If at any point on @@ -3286,15 +3366,16 @@ dns_rbtnodechain_prev(dns_rbtnodechain_t *chain, dns_name_t *name, /* XXX DCL duplicated from above; clever * way to unduplicate? */ - while (RIGHT(predecessor) != NULL) + while (RIGHT(predecessor) != NULL) { predecessor = RIGHT(predecessor); + } } while (DOWN(predecessor) != NULL); /* XXX DCL probably needs work on the concept */ - if (origin != NULL) + if (origin != NULL) { new_origin = true; + } } - } else if (chain->level_count > 0) { /* * Dang, didn't find a predecessor in this level. @@ -3312,8 +3393,9 @@ dns_rbtnodechain_prev(dns_rbtnodechain_t *chain, dns_name_t *name, * for the second level tree. */ if (origin != NULL && - (chain->level_count > 0 || OFFSETLEN(predecessor) > 1)) + (chain->level_count > 0 || OFFSETLEN(predecessor) > 1)) { new_origin = true; + } } if (predecessor != NULL) { @@ -3322,15 +3404,16 @@ dns_rbtnodechain_prev(dns_rbtnodechain_t *chain, dns_name_t *name, if (new_origin) { result = dns_rbtnodechain_current(chain, name, origin, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_NEWORIGIN; - - } else + } + } else { result = dns_rbtnodechain_current(chain, name, NULL, NULL); - - } else + } + } else { result = ISC_R_NOMORE; + } return (result); } @@ -3355,14 +3438,16 @@ dns_rbtnodechain_down(dns_rbtnodechain_t *chain, dns_name_t *name, * at the second level tree, because "." is already declared * as the origin for the top level tree. */ - if (chain->level_count > 0 || OFFSETLEN(current) > 1) + if (chain->level_count > 0 || OFFSETLEN(current) > 1) { new_origin = true; + } ADD_LEVEL(chain, current); current = DOWN(current); - while (LEFT(current) != NULL) + while (LEFT(current) != NULL) { current = LEFT(current); + } successor = current; } @@ -3379,21 +3464,24 @@ dns_rbtnodechain_down(dns_rbtnodechain_t *chain, dns_name_t *name, * the second level or below. */ - if (name != NULL) + if (name != NULL) { NODENAME(chain->end, name); + } if (new_origin) { - if (origin != NULL) + if (origin != NULL) { result = chain_name(chain, origin, false); + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_NEWORIGIN; - - } else + } + } else { result = ISC_R_SUCCESS; - - } else + } + } else { result = ISC_R_NOMORE; + } return (result); } @@ -3423,8 +3511,9 @@ dns_rbtnodechain_nextflat(dns_rbtnodechain_t *chain, dns_name_t *name) } else { current = RIGHT(current); - while (LEFT(current) != NULL) + while (LEFT(current) != NULL) { current = LEFT(current); + } successor = current; } @@ -3432,12 +3521,14 @@ dns_rbtnodechain_nextflat(dns_rbtnodechain_t *chain, dns_name_t *name) if (successor != NULL) { chain->end = successor; - if (name != NULL) + if (name != NULL) { NODENAME(chain->end, name); + } result = ISC_R_SUCCESS; - } else + } else { result = ISC_R_NOMORE; + } return (result); } @@ -3466,17 +3557,18 @@ dns_rbtnodechain_next(dns_rbtnodechain_t *chain, dns_name_t *name, * at the second level tree, because "." is already declared * as the origin for the top level tree. */ - if (chain->level_count > 0 || OFFSETLEN(current) > 1) + if (chain->level_count > 0 || OFFSETLEN(current) > 1) { new_origin = true; + } ADD_LEVEL(chain, current); current = DOWN(current); - while (LEFT(current) != NULL) + while (LEFT(current) != NULL) { current = LEFT(current); + } successor = current; - } else if (RIGHT(current) == NULL) { /* * The successor is up, either in this level or a previous one. @@ -3524,8 +3616,9 @@ dns_rbtnodechain_next(dns_rbtnodechain_t *chain, dns_name_t *name, current = chain->levels[--chain->level_count]; new_origin = true; - if (RIGHT(current) != NULL) + if (RIGHT(current) != NULL) { break; + } } } while (successor == NULL); } @@ -3533,8 +3626,9 @@ dns_rbtnodechain_next(dns_rbtnodechain_t *chain, dns_name_t *name, if (successor == NULL && RIGHT(current) != NULL) { current = RIGHT(current); - while (LEFT(current) != NULL) + while (LEFT(current) != NULL) { current = LEFT(current); + } successor = current; } @@ -3557,21 +3651,24 @@ dns_rbtnodechain_next(dns_rbtnodechain_t *chain, dns_name_t *name, * the second level or below. */ - if (name != NULL) + if (name != NULL) { NODENAME(chain->end, name); + } if (new_origin) { - if (origin != NULL) + if (origin != NULL) { result = chain_name(chain, origin, false); + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_NEWORIGIN; - - } else + } + } else { result = ISC_R_SUCCESS; - - } else + } + } else { result = ISC_R_NOMORE; + } return (result); } @@ -3592,8 +3689,9 @@ dns_rbtnodechain_first(dns_rbtnodechain_t *chain, dns_rbt_t *rbt, result = dns_rbtnodechain_current(chain, name, origin, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_NEWORIGIN; + } return (result); } @@ -3611,13 +3709,15 @@ dns_rbtnodechain_last(dns_rbtnodechain_t *chain, dns_rbt_t *rbt, dns_rbtnodechain_reset(chain); result = move_chain_to_last(chain, rbt->root); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_rbtnodechain_current(chain, name, origin, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_NEWORIGIN; + } return (result); } diff --git a/lib/dns/rbtdb.c b/lib/dns/rbtdb.c index be9bfec5f2..14e6f8082f 100644 --- a/lib/dns/rbtdb.c +++ b/lib/dns/rbtdb.c @@ -65,12 +65,12 @@ #ifndef WIN32 #include -#else +#else /* ifndef WIN32 */ #define PROT_READ 0x01 #define PROT_WRITE 0x02 #define MAP_PRIVATE 0x0002 #define MAP_FAILED ((void *)-1) -#endif +#endif /* ifndef WIN32 */ #include "rbtdb.h" @@ -175,7 +175,7 @@ typedef isc_rwlock_t nodelock_t; */ #ifndef DNS_RBTDB_LIMITLRUUPDATE #define DNS_RBTDB_LIMITLRUUPDATE 0 -#endif +#endif /* ifndef DNS_RBTDB_LIMITLRUUPDATE */ /* * Allow clients with a virtual time of up to 5 minutes in the past to see @@ -315,10 +315,10 @@ typedef ISC_LIST(dns_rbtnode_t) rbtnodelist_t; #ifdef DNS_RBTDB_CACHE_NODE_LOCK_COUNT #if DNS_RBTDB_CACHE_NODE_LOCK_COUNT <= 1 #error "DNS_RBTDB_CACHE_NODE_LOCK_COUNT must be larger than 1" -#else +#else /* if DNS_RBTDB_CACHE_NODE_LOCK_COUNT <= 1 */ #define DEFAULT_CACHE_NODE_LOCK_COUNT DNS_RBTDB_CACHE_NODE_LOCK_COUNT -#endif -#else +#endif /* if DNS_RBTDB_CACHE_NODE_LOCK_COUNT <= 1 */ +#else /* ifdef DNS_RBTDB_CACHE_NODE_LOCK_COUNT */ #define DEFAULT_CACHE_NODE_LOCK_COUNT 16 #endif /* DNS_RBTDB_CACHE_NODE_LOCK_COUNT */ @@ -749,7 +749,7 @@ hexdump(const char *desc, unsigned char *data, size_t size) } while (size > 0); fprintf(stderr, "\n"); } -#endif +#endif /* ifdef DEBUG */ /* Fixed RRSet helper macros */ @@ -794,8 +794,9 @@ update_cachestats(dns_rbtdb_t *rbtdb, isc_result_t result) { INSIST(IS_CACHE(rbtdb)); - if (rbtdb->cachestats == NULL) + if (rbtdb->cachestats == NULL) { return; + } switch (result) { case ISC_R_SUCCESS: @@ -835,9 +836,9 @@ update_rrsetstats(dns_rbtdb_t *rbtdb, rdatasetheader_t *header, bool increment) INSIST(IS_CACHE(rbtdb)); if (NEGATIVE(header)) { - if (NXDOMAIN(header)) + if (NXDOMAIN(header)) { statattributes = DNS_RDATASTATSTYPE_ATTR_NXDOMAIN; - else { + } else { statattributes = DNS_RDATASTATSTYPE_ATTR_NXRRSET; base = RBTDB_RDATATYPE_EXT(header->type); } @@ -880,17 +881,20 @@ set_ttl(dns_rbtdb_t *rbtdb, rdatasetheader_t *header, dns_ttl_t newttl) * we will not have a heap, and we move on. If we do, though, * we might need to adjust things. */ - if (header->heap_index == 0 || newttl == oldttl) + if (header->heap_index == 0 || newttl == oldttl) { return; + } idx = header->node->locknum; - if (rbtdb->heaps == NULL || rbtdb->heaps[idx] == NULL) + if (rbtdb->heaps == NULL || rbtdb->heaps[idx] == NULL) { return; + } heap = rbtdb->heaps[idx]; - if (newttl < oldttl) + if (newttl < oldttl) { isc_heap_increased(heap, header->heap_index); - else + } else { isc_heap_decreased(heap, header->heap_index); + } } /*% @@ -942,13 +946,15 @@ adjust_quantum(unsigned int old, isc_time_t *start) isc_time_t end; unsigned int nodes; - if (pps < 100) + if (pps < 100) { pps = 100; + } isc_time_now(&end); interval = 1000000 / pps; /* interval in usec */ - if (interval == 0) + if (interval == 0) { interval = 1; + } usecs = isc_time_microdiff(&end, start); if (usecs == 0) { /* @@ -956,24 +962,27 @@ adjust_quantum(unsigned int old, isc_time_t *start) * Double the nodes deleted next time. */ old *= 2; - if (old > 1000) + if (old > 1000) { old = 1000; + } return (old); } nodes = old * interval; nodes /= (unsigned int)usecs; - if (nodes == 0) + if (nodes == 0) { nodes = 1; - else if (nodes > 1000) + } else if (nodes > 1000) { nodes = 1000; + } /* Smooth */ nodes = (nodes + old * 3) / 4; - if (nodes != old) + if (nodes != old) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1), "adjust_quantum: old=%d, new=%d", old, nodes); + } return (nodes); } @@ -988,8 +997,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) isc_time_t start; dns_dbonupdatelistener_t *listener, *listener_next; - if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) + if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) { overmem((dns_db_t *)rbtdb, (bool)-1); + } REQUIRE(rbtdb->current_version != NULL || EMPTY(rbtdb->open_versions)); REQUIRE(rbtdb->future_version == NULL); @@ -1020,8 +1030,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) } } - if (event == NULL) + if (event == NULL) { rbtdb->quantum = (rbtdb->task != NULL) ? 100 : 0; + } for (;;) { /* @@ -1035,8 +1046,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) /* * we're finished after clear cutting */ - if (*treep == NULL) + if (*treep == NULL) { break; + } } } @@ -1044,35 +1056,40 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) result = dns_rbt_destroy2(treep, rbtdb->quantum); if (result == ISC_R_QUOTA) { INSIST(rbtdb->task != NULL); - if (rbtdb->quantum != 0) + if (rbtdb->quantum != 0) { rbtdb->quantum = adjust_quantum(rbtdb->quantum, &start); - if (event == NULL) + } + if (event == NULL) { event = isc_event_allocate( rbtdb->common.mctx, NULL, DNS_EVENT_FREESTORAGE, free_rbtdb_callback, rbtdb, sizeof(isc_event_t)); + } isc_task_send(rbtdb->task, &event); return; } INSIST(result == ISC_R_SUCCESS && *treep == NULL); } - if (event != NULL) + if (event != NULL) { isc_event_free(&event); + } if (log) { - if (dns_name_dynamic(&rbtdb->common.origin)) + if (dns_name_dynamic(&rbtdb->common.origin)) { dns_name_format(&rbtdb->common.origin, buf, sizeof(buf)); - else + } else { strlcpy(buf, "", sizeof(buf)); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1), "done free_rbtdb(%s)", buf); } - if (dns_name_dynamic(&rbtdb->common.origin)) + if (dns_name_dynamic(&rbtdb->common.origin)) { dns_name_free(&rbtdb->common.origin, rbtdb->common.mctx); + } for (i = 0; i < rbtdb->node_lock_count; i++) { isc_refcount_destroy(&rbtdb->node_locks[i].references); NODE_DESTROYLOCK(&rbtdb->node_locks[i].lock); @@ -1082,8 +1099,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) * Clean up LRU / re-signing order lists. */ if (rbtdb->rdatasets != NULL) { - for (i = 0; i < rbtdb->node_lock_count; i++) + for (i = 0; i < rbtdb->node_lock_count; i++) { INSIST(ISC_LIST_EMPTY(rbtdb->rdatasets[i])); + } isc_mem_put(rbtdb->common.mctx, rbtdb->rdatasets, rbtdb->node_lock_count * sizeof(rdatasetheaderlist_t)); @@ -1092,8 +1110,9 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) * Clean up dead node buckets. */ if (rbtdb->deadnodes != NULL) { - for (i = 0; i < rbtdb->node_lock_count; i++) + for (i = 0; i < rbtdb->node_lock_count; i++) { INSIST(ISC_LIST_EMPTY(rbtdb->deadnodes[i])); + } isc_mem_put(rbtdb->common.mctx, rbtdb->deadnodes, rbtdb->node_lock_count * sizeof(rbtnodelist_t)); } @@ -1101,33 +1120,39 @@ free_rbtdb(dns_rbtdb_t *rbtdb, bool log, isc_event_t *event) * Clean up heap objects. */ if (rbtdb->heaps != NULL) { - for (i = 0; i < rbtdb->node_lock_count; i++) + for (i = 0; i < rbtdb->node_lock_count; i++) { isc_heap_destroy(&rbtdb->heaps[i]); + } isc_mem_put(rbtdb->hmctx, rbtdb->heaps, rbtdb->node_lock_count * sizeof(isc_heap_t *)); } - if (rbtdb->rrsetstats != NULL) + if (rbtdb->rrsetstats != NULL) { dns_stats_detach(&rbtdb->rrsetstats); - if (rbtdb->cachestats != NULL) + } + if (rbtdb->cachestats != NULL) { isc_stats_detach(&rbtdb->cachestats); - if (rbtdb->gluecachestats != NULL) + } + if (rbtdb->gluecachestats != NULL) { isc_stats_detach(&rbtdb->gluecachestats); + } isc_mem_put(rbtdb->common.mctx, rbtdb->node_locks, rbtdb->node_lock_count * sizeof(rbtdb_nodelock_t)); isc_rwlock_destroy(&rbtdb->tree_lock); isc_refcount_destroy(&rbtdb->references); - if (rbtdb->task != NULL) + if (rbtdb->task != NULL) { isc_task_detach(&rbtdb->task); + } RBTDB_DESTROYLOCK(&rbtdb->lock); rbtdb->common.magic = 0; rbtdb->common.impmagic = 0; isc_mem_detach(&rbtdb->hmctx); - if (rbtdb->mmap_location != NULL) + if (rbtdb->mmap_location != NULL) { isc_file_munmap(rbtdb->mmap_location, (size_t)rbtdb->mmap_size); + } for (listener = ISC_LIST_HEAD(rbtdb->common.update_listeners); listener != NULL; listener = listener_next) { @@ -1149,10 +1174,12 @@ maybe_free_rbtdb(dns_rbtdb_t *rbtdb) /* XXX check for open versions here */ - if (rbtdb->soanode != NULL) + if (rbtdb->soanode != NULL) { dns_db_detachnode((dns_db_t *)rbtdb, &rbtdb->soanode); - if (rbtdb->nsnode != NULL) + } + if (rbtdb->nsnode != NULL) { dns_db_detachnode((dns_db_t *)rbtdb, &rbtdb->nsnode); + } /* * The current version's glue table needs to be freed early @@ -1259,8 +1286,9 @@ allocate_version(isc_mem_t *mctx, rbtdb_serial_t serial, ISC_LIST_INIT(version->resigned_list); ISC_LINK_INIT(version, link); - for (i = 0; i < version->glue_table_size; i++) + for (i = 0; i < version->glue_table_size; i++) { version->glue_table[i] = NULL; + } return (version); } @@ -1319,12 +1347,14 @@ newversion(dns_db_t *db, dns_dbversion_t **versionp) rbtdb->next_serial++; rbtdb->future_version = version; } - } else + } else { result = ISC_R_NOMEMORY; + } RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write); - if (version == NULL) + if (version == NULL) { return (result); + } *versionp = version; @@ -1366,8 +1396,9 @@ add_changed(dns_rbtdb_t *rbtdb, rbtdb_version_t *version, dns_rbtnode_t *node) changed->node = node; changed->dirty = false; ISC_LIST_INITANDAPPEND(version->changed_list, changed, link); - } else + } else { version->commit_ok = false; + } RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write); @@ -1377,14 +1408,17 @@ add_changed(dns_rbtdb_t *rbtdb, rbtdb_version_t *version, dns_rbtnode_t *node) static inline void free_noqname(isc_mem_t *mctx, struct noqname **noqname) { - if (dns_name_dynamic(&(*noqname)->name)) + if (dns_name_dynamic(&(*noqname)->name)) { dns_name_free(&(*noqname)->name, mctx); - if ((*noqname)->neg != NULL) + } + if ((*noqname)->neg != NULL) { isc_mem_put(mctx, (*noqname)->neg, dns_rdataslab_size((*noqname)->neg, 0)); - if ((*noqname)->negsig != NULL) + } + if ((*noqname)->negsig != NULL) { isc_mem_put(mctx, (*noqname)->negsig, dns_rdataslab_size((*noqname)->negsig, 0)); + } isc_mem_put(mctx, *noqname, sizeof(**noqname)); *noqname = NULL; } @@ -1399,11 +1433,12 @@ init_rdataset(dns_rbtdb_t *rbtdb, rdatasetheader_t *h) h->node_is_relative = 0; #if TRACE_HEADER - if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) + if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) { fprintf(stderr, "initialized header: %p\n", h); -#else + } +#else /* if TRACE_HEADER */ UNUSED(rbtdb); -#endif +#endif /* if TRACE_HEADER */ } /* @@ -1442,9 +1477,10 @@ new_rdataset(dns_rbtdb_t *rbtdb, isc_mem_t *mctx) h = isc_mem_get(mctx, sizeof(*h)); #if TRACE_HEADER - if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) + if (IS_CACHE(rbtdb) && rbtdb->common.rdclass == dns_rdataclass_in) { fprintf(stderr, "allocated header: %p\n", h); -#endif + } +#endif /* if TRACE_HEADER */ memset(h->upper, 0xeb, sizeof(h->upper)); init_rdataset(rbtdb, h); h->rdh_ttl = 0; @@ -1465,23 +1501,28 @@ free_rdataset(dns_rbtdb_t *rbtdb, isc_mem_t *mctx, rdatasetheader_t *rdataset) ISC_LIST_UNLINK(rbtdb->rdatasets[idx], rdataset, link); } - if (rdataset->heap_index != 0) + if (rdataset->heap_index != 0) { isc_heap_delete(rbtdb->heaps[idx], rdataset->heap_index); + } rdataset->heap_index = 0; - if (rdataset->noqname != NULL) + if (rdataset->noqname != NULL) { free_noqname(mctx, &rdataset->noqname); - if (rdataset->closest != NULL) + } + if (rdataset->closest != NULL) { free_noqname(mctx, &rdataset->closest); + } - if (NONEXISTENT(rdataset)) + if (NONEXISTENT(rdataset)) { size = sizeof(*rdataset); - else + } else { size = dns_rdataslab_size((unsigned char *)rdataset, sizeof(*rdataset)); + } - if (rdataset->is_mmapped == 1) + if (rdataset->is_mmapped == 1) { return; + } isc_mem_put(mctx, rdataset, size); } @@ -1514,8 +1555,9 @@ rollback_node(dns_rbtnode_t *node, rbtdb_serial_t serial) } } } - if (make_dirty) + if (make_dirty) { node->dirty = 1; + } } static inline void @@ -1598,13 +1640,15 @@ clean_cache_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node) */ if (NONEXISTENT(current) || ANCIENT(current) || (STALE(current) && !KEEPSTALE(rbtdb))) { - if (top_prev != NULL) + if (top_prev != NULL) { top_prev->next = current->next; - else + } else { node->data = current->next; + } free_rdataset(rbtdb, mctx, current); - } else + } else { top_prev = current; + } } node->dirty = 0; } @@ -1639,12 +1683,14 @@ clean_zone_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, INSIST(dcurrent->serial <= dparent->serial); if (dcurrent->serial == dparent->serial || IGNORE(dcurrent)) { - if (down_next != NULL) + if (down_next != NULL) { down_next->next = dparent; + } dparent->down = down_next; free_rdataset(rbtdb, mctx, dcurrent); - } else + } else { dparent = dcurrent; + } } /* @@ -1654,10 +1700,11 @@ clean_zone_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, if (IGNORE(current)) { down_next = current->down; if (down_next == NULL) { - if (top_prev != NULL) + if (top_prev != NULL) { top_prev->next = current->next; - else + } else { node->data = current->next; + } free_rdataset(rbtdb, mctx, current); /* * current no longer exists, so we can @@ -1669,10 +1716,11 @@ clean_zone_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, * Pull up current->down, making it the new * current. */ - if (top_prev != NULL) + if (top_prev != NULL) { top_prev->next = down_next; - else + } else { node->data = down_next; + } down_next->next = top_next; free_rdataset(rbtdb, mctx, current); current = down_next; @@ -1687,8 +1735,9 @@ clean_zone_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, for (dcurrent = current->down; dcurrent != NULL; dcurrent = down_next) { down_next = dcurrent->down; - if (dcurrent->serial < least_serial) + if (dcurrent->serial < least_serial) { break; + } dparent = dcurrent; } @@ -1720,17 +1769,20 @@ clean_zone_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, * If this is a NONEXISTENT rdataset, we can delete it. */ if (NONEXISTENT(current)) { - if (top_prev != NULL) + if (top_prev != NULL) { top_prev->next = current->next; - else + } else { node->data = current->next; + } free_rdataset(rbtdb, mctx, current); - } else + } else { top_prev = current; + } } } - if (!still_dirty) + if (!still_dirty) { node->dirty = 0; + } } /* @@ -1942,11 +1994,13 @@ reactivate_node(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, locktype = isc_rwlocktype_write; POST(locktype); NODE_LOCK(nodelock, locktype); - if (ISC_LINK_LINKED(node, deadlink)) + if (ISC_LINK_LINKED(node, deadlink)) { ISC_LIST_UNLINK(rbtdb->deadnodes[node->locknum], node, deadlink); - if (maybe_cleanup) + } + if (maybe_cleanup) { cleanup_dead_nodes(rbtdb, node->locknum); + } } new_reference(rbtdb, node); @@ -2006,15 +2060,16 @@ decrement_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, if (isc_refcount_decrement(&node->references) > 1) { /* Restore the lock? */ - if (nlock == isc_rwlocktype_read) + if (nlock == isc_rwlocktype_read) { NODE_DOWNGRADE(&nodelock->lock); + } return (false); } if (node->dirty) { - if (IS_CACHE(rbtdb)) + if (IS_CACHE(rbtdb)) { clean_cache_node(rbtdb, node); - else { + } else { if (least_serial == 0) { /* * Caller doesn't know the least serial. @@ -2039,17 +2094,19 @@ decrement_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, * the node lock before acquiring the tree write lock because * we only do a trylock. */ - if (tlock == isc_rwlocktype_read) + if (tlock == isc_rwlocktype_read) { result = isc_rwlock_tryupgrade(&rbtdb->tree_lock); - else + } else { result = isc_rwlock_trylock(&rbtdb->tree_lock, isc_rwlocktype_write); + } RUNTIME_CHECK(result == ISC_R_SUCCESS || result == ISC_R_LOCKBUSY); write_locked = (result == ISC_R_SUCCESS); - } else + } else { write_locked = true; + } refs = isc_refcount_decrement(&nodelock->references); INSIST(refs > 0); @@ -2095,8 +2152,9 @@ decrement_reference(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, restore_locks: /* Restore the lock? */ - if (nlock == isc_rwlocktype_read) + if (nlock == isc_rwlocktype_read) { NODE_DOWNGRADE(&nodelock->lock); + } /* * Relock a read lock, or unlock the write lock if no lock was held. @@ -2104,14 +2162,12 @@ restore_locks: if (tlock == isc_rwlocktype_none) { if (write_locked) { RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_write); - } } if (tlock == isc_rwlocktype_read) { if (write_locked) { isc_rwlock_downgrade(&rbtdb->tree_lock); - } } @@ -2167,12 +2223,14 @@ prune_tree(isc_task_t *task, isc_event_t *event) * from the list beforehand as we do in * reactivate_node(). */ - if (ISC_LINK_LINKED(parent, deadlink)) + if (ISC_LINK_LINKED(parent, deadlink)) { ISC_LIST_UNLINK(rbtdb->deadnodes[locknum], parent, deadlink); + } new_reference(rbtdb, parent); - } else + } else { parent = NULL; + } node = parent; } while (node != NULL); @@ -2272,10 +2330,11 @@ iszonesecure(dns_db_t *db, rbtdb_version_t *version, dns_dbnode_t *origin) /* * Do we have a valid NSEC/NSEC3 chain? */ - if (version->havensec3 || hasnsec) + if (version->havensec3 || hasnsec) { version->secure = dns_db_secure; - else + } else { version->secure = dns_db_insecure; + } } /*%< @@ -2305,11 +2364,13 @@ setnsec3parameters(dns_db_t *db, rbtdb_version_t *version) do { if (header->serial <= version->serial && !IGNORE(header)) { - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); if (header != NULL && @@ -2335,11 +2396,13 @@ setnsec3parameters(dns_db_t *db, rbtdb_version_t *version) dns_rdata_reset(&rdata); if (nsec3param.hash != DNS_NSEC3_UNKNOWNALG && - !dns_nsec3_supportedhash(nsec3param.hash)) + !dns_nsec3_supportedhash(nsec3param.hash)) { continue; + } - if (nsec3param.flags != 0) + if (nsec3param.flags != 0) { continue; + } memmove(version->salt, nsec3param.salt, nsec3param.salt_length); @@ -2352,8 +2415,9 @@ setnsec3parameters(dns_db_t *db, rbtdb_version_t *version) * Look for a better algorithm than the * unknown test algorithm. */ - if (nsec3param.hash != DNS_NSEC3_UNKNOWNALG) + if (nsec3param.hash != DNS_NSEC3_UNKNOWNALG) { goto unlock; + } } } } @@ -2375,15 +2439,16 @@ cleanup_dead_nodes_callback(isc_task_t *task, isc_event_t *event) NODE_LOCK(&rbtdb->node_locks[locknum].lock, isc_rwlocktype_write); cleanup_dead_nodes(rbtdb, locknum); - if (ISC_LIST_HEAD(rbtdb->deadnodes[locknum]) != NULL) + if (ISC_LIST_HEAD(rbtdb->deadnodes[locknum]) != NULL) { again = true; + } NODE_UNLOCK(&rbtdb->node_locks[locknum].lock, isc_rwlocktype_write); } RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_write); - if (again) + if (again) { isc_task_send(task, &event); - else { + } else { isc_event_free(&event); if (isc_refcount_decrement(&rbtdb->references) == 1) { (void)isc_refcount_current(&rbtdb->references); @@ -2427,8 +2492,9 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) * Update the zone's secure status in version before making * it the current version. */ - if (version->writer && commit && !IS_CACHE(rbtdb)) + if (version->writer && commit && !IS_CACHE(rbtdb)) { iszonesecure(db, version, rbtdb->origin_node); + } RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_write); serial = version->serial; @@ -2450,9 +2516,11 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) if (cur_ref == 1) { (void)isc_refcount_current( &cur_version->references); - if (cur_version->serial == rbtdb->least_serial) + if (cur_version->serial == + rbtdb->least_serial) { INSIST(EMPTY( cur_version->changed_list)); + } UNLINK(rbtdb->open_versions, cur_version, link); } if (EMPTY(rbtdb->open_versions)) { @@ -2534,8 +2602,9 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) * number greater than ours. */ least_greater = PREV(version, link); - if (least_greater == NULL) + if (least_greater == NULL) { least_greater = rbtdb->current_version; + } INSIST(version->serial < least_greater->serial); /* @@ -2556,8 +2625,9 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) APPENDLIST(least_greater->changed_list, version->changed_list, link); } - } else if (version->serial == rbtdb->least_serial) + } else if (version->serial == rbtdb->least_serial) { INSIST(EMPTY(version->changed_list)); + } UNLINK(rbtdb->open_versions, version, link); } least_serial = rbtdb->least_serial; @@ -2587,13 +2657,14 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) isc_result_t result; result = resign_insert(rbtdb, header->node->locknum, header); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_ZONE, ISC_LOG_ERROR, "Unable to reinsert header to " "re-signing heap: %s", dns_result_totext(result)); + } } decrement_reference(rbtdb, header->node, least_serial, isc_rwlocktype_write, isc_rwlocktype_none, @@ -2605,11 +2676,12 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) isc_event_t * event = NULL; isc_rwlocktype_t tlock = isc_rwlocktype_none; - if (rbtdb->task != NULL) + if (rbtdb->task != NULL) { event = isc_event_allocate(rbtdb->common.mctx, NULL, DNS_EVENT_RBTDEADNODES, cleanup_dead_nodes_callback, rbtdb, sizeof(isc_event_t)); + } if (event == NULL) { /* * We acquire a tree write lock here in order to make @@ -2637,11 +2709,13 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) * This is a good opportunity to purge any dead nodes, * so use it. */ - if (event == NULL) + if (event == NULL) { cleanup_dead_nodes(rbtdb, rbtnode->locknum); + } - if (rollback) + if (rollback) { rollback_node(rbtnode, serial); + } decrement_reference(rbtdb, rbtnode, least_serial, isc_rwlocktype_write, tlock, false); @@ -2653,8 +2727,9 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) if (event != NULL) { isc_refcount_increment(&rbtdb->references); isc_task_send(rbtdb->task, &event); - } else + } else { RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_write); + } } end: @@ -2691,10 +2766,12 @@ add_wildcard_magic(dns_rbtdb_t *rbtdb, const dns_name_t *name) n--; dns_name_getlabelsequence(name, 1, n, &foundname); result = dns_rbt_addnode(rbtdb->tree, &foundname, &node); - if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) + if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) { return (result); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { node->nsec = DNS_RBT_NSEC_NORMAL; + } node->find_callback = 1; node->wild = 1; return (ISC_R_SUCCESS); @@ -2720,14 +2797,17 @@ add_empty_wildcards(dns_rbtdb_t *rbtdb, const dns_name_t *name) dns_name_getlabelsequence(name, n - i, i, &foundname); if (dns_name_iswildcard(&foundname)) { result = add_wildcard_magic(rbtdb, &foundname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_rbt_addnode(rbtdb->tree, &foundname, &node); - if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) + if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) { return (result); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { node->nsec = DNS_RBT_NSEC_NORMAL; + } } i++; } @@ -2752,8 +2832,9 @@ findnodeintree(dns_rbtdb_t *rbtdb, dns_rbt_t *tree, const dns_name_t *name, if (result != ISC_R_SUCCESS) { RWUNLOCK(&rbtdb->tree_lock, locktype); if (!create) { - if (result == DNS_R_PARTIALMATCH) + if (result == DNS_R_PARTIALMATCH) { result = ISC_R_NOTFOUND; + } return (result); } /* @@ -2780,16 +2861,18 @@ findnodeintree(dns_rbtdb_t *rbtdb, dns_rbt_t *tree, const dns_name_t *name, } } } - if (tree == rbtdb->nsec3) + if (tree == rbtdb->nsec3) { node->nsec = DNS_RBT_NSEC_NSEC3; + } } else if (result != ISC_R_EXISTS) { RWUNLOCK(&rbtdb->tree_lock, locktype); return (result); } } - if (tree == rbtdb->nsec3) + if (tree == rbtdb->nsec3) { INSIST(node->nsec == DNS_RBT_NSEC_NSEC3); + } reactivate_node(rbtdb, node, locktype); @@ -2837,8 +2920,9 @@ zone_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) * that counts, so we'll just continue if we've already found a * zonecut. */ - if (search->zonecut != NULL) + if (search->zonecut != NULL) { return (DNS_R_CONTINUE); + } found = NULL; result = DNS_R_CONTINUE; @@ -2865,20 +2949,22 @@ zone_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) * Is this a "this rdataset doesn't * exist" record? */ - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); if (header != NULL) { - if (header->type == dns_rdatatype_dname) + if (header->type == dns_rdatatype_dname) { dname_header = header; - else if (header->type == - RBTDB_RDATATYPE_SIGDNAME) + } else if (header->type == + RBTDB_RDATATYPE_SIGDNAME) { sigdname_header = header; - else if (node != onode || - IS_STUB(search->rbtdb)) { + } else if (node != onode || + IS_STUB(search->rbtdb)) { /* * We've found an NS rdataset that * isn't at the origin node. We check @@ -2956,8 +3042,9 @@ zone_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) * in case we need to go searching for wildcard matches * later on. */ - if (node->wild && (search->options & DNS_DBFIND_NOWILD) == 0) + if (node->wild && (search->options & DNS_DBFIND_NOWILD) == 0) { search->wild = true; + } } NODE_UNLOCK(&(search->rbtdb->node_locks[node->locknum].lock), @@ -2980,8 +3067,9 @@ bind_rdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rdatasetheader_t *header, * use atomic increment when available). */ - if (rdataset == NULL) + if (rdataset == NULL) { return; + } new_reference(rbtdb, node); @@ -2993,14 +3081,18 @@ bind_rdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rdatasetheader_t *header, rdataset->covers = RBTDB_RDATATYPE_EXT(header->type); rdataset->ttl = header->rdh_ttl - now; rdataset->trust = header->trust; - if (NEGATIVE(header)) + if (NEGATIVE(header)) { rdataset->attributes |= DNS_RDATASETATTR_NEGATIVE; - if (NXDOMAIN(header)) + } + if (NXDOMAIN(header)) { rdataset->attributes |= DNS_RDATASETATTR_NXDOMAIN; - if (OPTOUT(header)) + } + if (OPTOUT(header)) { rdataset->attributes |= DNS_RDATASETATTR_OPTOUT; - if (PREFETCH(header)) + } + if (PREFETCH(header)) { rdataset->attributes |= DNS_RDATASETATTR_PREFETCH; + } if (STALE(header)) { rdataset->attributes |= DNS_RDATASETATTR_STALE; rdataset->stale_ttl = @@ -3012,8 +3104,9 @@ bind_rdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rdatasetheader_t *header, raw = (unsigned char *)header + sizeof(*header); rdataset->private3 = raw; rdataset->count = atomic_fetch_add_relaxed(&header->count, 1); - if (rdataset->count == UINT32_MAX) + if (rdataset->count == UINT32_MAX) { rdataset->count = 0; + } /* * Reset iterator state. @@ -3025,11 +3118,13 @@ bind_rdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rdatasetheader_t *header, * Add noqname proof. */ rdataset->private6 = header->noqname; - if (rdataset->private6 != NULL) + if (rdataset->private6 != NULL) { rdataset->attributes |= DNS_RDATASETATTR_NOQNAME; + } rdataset->private7 = header->closest; - if (rdataset->private7 != NULL) + if (rdataset->private7 != NULL) { rdataset->attributes |= DNS_RDATASETATTR_CLOSEST; + } /* * Copy out re-signing information. @@ -3037,8 +3132,9 @@ bind_rdataset(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rdatasetheader_t *header, if (RESIGN(header)) { rdataset->attributes |= DNS_RDATASETATTR_RESIGN; rdataset->resign = (header->resign << 1) | header->resign_lsb; - } else + } else { rdataset->resign = 0; + } } static inline isc_result_t @@ -3082,16 +3178,19 @@ setup_delegation(rbtdb_search_t *search, dns_dbnode_t **nodep, isc_rwlocktype_read); bind_rdataset(search->rbtdb, node, search->zonecut_rdataset, search->now, rdataset); - if (sigrdataset != NULL && search->zonecut_sigrdataset != NULL) + if (sigrdataset != NULL && + search->zonecut_sigrdataset != NULL) { bind_rdataset(search->rbtdb, node, search->zonecut_sigrdataset, search->now, sigrdataset); + } NODE_UNLOCK(&(search->rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); } - if (type == dns_rdatatype_dname) + if (type == dns_rdatatype_dname) { return (DNS_R_DNAME); + } return (DNS_R_DELEGATION); } @@ -3177,26 +3276,31 @@ activeempty(rbtdb_search_t *search, dns_rbtnodechain_t *chain, node = NULL; result = dns_rbtnodechain_current(chain, &prefix, origin, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } NODE_LOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); for (header = node->data; header != NULL; header = header->next) { if (header->serial <= search->serial && - !IGNORE(header) && EXISTS(header)) + !IGNORE(header) && EXISTS(header)) { break; + } } NODE_UNLOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); - if (header != NULL) + if (header != NULL) { break; + } result = dns_rbtnodechain_next(chain, NULL, NULL); } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_name_concatenate(&prefix, origin, next, NULL); - if (result == ISC_R_SUCCESS && dns_name_issubdomain(next, name)) + } + if (result == ISC_R_SUCCESS && dns_name_issubdomain(next, name)) { answer = true; + } return (answer); } @@ -3241,51 +3345,61 @@ activeemtpynode(rbtdb_search_t *search, const dns_name_t *qname, do { node = NULL; result = dns_rbtnodechain_current(&chain, &name, origin, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } NODE_LOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); for (header = node->data; header != NULL; header = header->next) { if (header->serial <= search->serial && - !IGNORE(header) && EXISTS(header)) + !IGNORE(header) && EXISTS(header)) { break; + } } NODE_UNLOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); - if (header != NULL) + if (header != NULL) { break; + } result = dns_rbtnodechain_prev(&chain, NULL, NULL); } while (result == ISC_R_SUCCESS || result == DNS_R_NEWORIGIN); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_name_concatenate(&name, origin, prev, NULL); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { check_prev = false; + } result = dns_rbtnodechain_next(&chain, NULL, NULL); while (result == ISC_R_SUCCESS || result == DNS_R_NEWORIGIN) { node = NULL; result = dns_rbtnodechain_current(&chain, &name, origin, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } NODE_LOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); for (header = node->data; header != NULL; header = header->next) { if (header->serial <= search->serial && - !IGNORE(header) && EXISTS(header)) + !IGNORE(header) && EXISTS(header)) { break; + } } NODE_UNLOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); - if (header != NULL) + if (header != NULL) { break; + } result = dns_rbtnodechain_next(&chain, NULL, NULL); } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_name_concatenate(&name, origin, next, NULL); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { check_next = false; + } dns_name_clone(qname, &rname); @@ -3357,18 +3471,21 @@ find_wildcard(rbtdb_search_t *search, dns_rbtnode_t **nodep, for (header = node->data; header != NULL; header = header->next) { if (header->serial <= search->serial && - !IGNORE(header) && EXISTS(header)) + !IGNORE(header) && EXISTS(header)) { break; + } } - if (header != NULL) + if (header != NULL) { active = true; - else + } else { active = false; + } - if (node->wild) + if (node->wild) { wild = true; - else + } else { wild = false; + } NODE_UNLOCK(&(rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); @@ -3391,8 +3508,9 @@ find_wildcard(rbtdb_search_t *search, dns_rbtnode_t **nodep, result = dns_name_concatenate(wname, &name, wname, NULL); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } wnode = NULL; dns_rbtnodechain_init(&wchain); @@ -3412,8 +3530,9 @@ find_wildcard(rbtdb_search_t *search, dns_rbtnode_t **nodep, for (header = wnode->data; header != NULL; header = header->next) { if (header->serial <= search->serial && - !IGNORE(header) && EXISTS(header)) + !IGNORE(header) && EXISTS(header)) { break; + } } NODE_UNLOCK(lock, isc_rwlocktype_read); if (header != NULL || @@ -3453,8 +3572,9 @@ find_wildcard(rbtdb_search_t *search, dns_rbtnode_t **nodep, if (i > 0) { i--; node = search->chain.levels[i]; - } else + } else { done = true; + } } while (!done); return (result); @@ -3490,8 +3610,9 @@ matchparams(rdatasetheader_t *header, rbtdb_search_t *search) nsec3.iterations == search->rbtversion->iterations && nsec3.salt_length == search->rbtversion->salt_length && memcmp(nsec3.salt, search->rbtversion->salt, - nsec3.salt_length) == 0) + nsec3.salt_length) == 0) { return (true); + } dns_rdata_reset(&rdata); } return (false); @@ -3515,8 +3636,9 @@ previous_closest_nsec(dns_rdatatype_t type, rbtdb_search_t *search, if (type == dns_rdatatype_nsec3) { result = dns_rbtnodechain_prev(&search->chain, NULL, NULL); - if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) + if (result != ISC_R_SUCCESS && result != DNS_R_NEWORIGIN) { return (result); + } result = dns_rbtnodechain_current(&search->chain, name, origin, nodep); return (result); @@ -3534,8 +3656,9 @@ previous_closest_nsec(dns_rdatatype_t type, rbtdb_search_t *search, dns_rbtnodechain_init(nsecchain); result = dns_name_concatenate(name, origin, target, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } nsecnode = NULL; result = dns_rbt_findnode( search->rbtdb->nsec, target, NULL, &nsecnode, @@ -3550,14 +3673,16 @@ previous_closest_nsec(dns_rdatatype_t type, rbtdb_search_t *search, */ result = dns_rbtnodechain_prev(nsecchain, name, origin); - if (result == DNS_R_NEWORIGIN) + if (result == DNS_R_NEWORIGIN) { result = ISC_R_SUCCESS; + } } else if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) { result = dns_rbtnodechain_current( nsecchain, name, origin, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_NOMORE; + } } } else { /* @@ -3568,25 +3693,29 @@ previous_closest_nsec(dns_rdatatype_t type, rbtdb_search_t *search, * records. Perhaps they lacked signature records. */ result = dns_rbtnodechain_prev(nsecchain, name, origin); - if (result == DNS_R_NEWORIGIN) + if (result == DNS_R_NEWORIGIN) { result = ISC_R_SUCCESS; + } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Construct the name to seek in the main tree. */ result = dns_name_concatenate(name, origin, target, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } *nodep = NULL; result = dns_rbt_findnode(search->rbtdb->tree, target, NULL, nodep, &search->chain, DNS_RBTFIND_NOOPTIONS, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (result); + } /* * There should always be a node in the main tree with the @@ -3647,8 +3776,9 @@ again: node = NULL; prevnode = NULL; result = dns_rbtnodechain_current(&search->chain, name, origin, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } do { NODE_LOCK(&(search->rbtdb->node_locks[node->locknum].lock), isc_rwlocktype_read); @@ -3668,11 +3798,13 @@ again: * Is this a "this rdataset doesn't * exist" record? */ - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); if (header != NULL) { /* @@ -3682,12 +3814,14 @@ again: empty_node = false; if (header->type == type) { found = header; - if (foundsig != NULL) + if (foundsig != NULL) { break; + } } else if (header->type == sigtype) { foundsig = header; - if (found != NULL) + if (found != NULL) { break; + } } } } @@ -3723,11 +3857,12 @@ again: bind_rdataset(search->rbtdb, node, found, search->now, rdataset); - if (foundsig != NULL) + if (foundsig != NULL) { bind_rdataset(search->rbtdb, node, foundsig, search->now, sigrdataset); + } } } else if (found == NULL && foundsig == NULL) { /* @@ -3764,8 +3899,9 @@ again: prevnode = NULL; } while (empty_node && result == ISC_R_SUCCESS); - if (!first) + if (!first) { dns_rbtnodechain_invalidate(&nsecchain); + } if (result == ISC_R_NOMORE && wraps) { result = @@ -3781,8 +3917,9 @@ again: * the database and didn't find a NSEC record. This shouldn't * happen. */ - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = DNS_R_BADDB; + } return (result); } @@ -3879,8 +4016,9 @@ zone_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, dns_name_copynf(name, foundname); wild = true; goto found; - } else if (result != ISC_R_NOTFOUND) + } else if (result != ISC_R_NOTFOUND) { goto tree_exit; + } } chain = search.chain; @@ -3897,14 +4035,17 @@ zone_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, result = find_closest_nsec(&search, nodep, foundname, rdataset, sigrdataset, tree, search.rbtversion->secure); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = active ? DNS_R_EMPTYNAME : DNS_R_NXDOMAIN; - } else + } + } else { result = active ? DNS_R_EMPTYNAME : DNS_R_NXDOMAIN; + } goto tree_exit; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto tree_exit; + } found: /* @@ -3932,8 +4073,9 @@ found: if (node->find_callback && ((node != search.rbtdb->origin_node && !dns_rdatatype_atparent(type)) || - IS_STUB(search.rbtdb))) + IS_STUB(search.rbtdb))) { maybe_zonecut = true; + } } /* @@ -3943,8 +4085,9 @@ found: * We don't check for RRSIG, because we don't store RRSIG records * directly. */ - if (type == dns_rdatatype_key || type == dns_rdatatype_nsec) + if (type == dns_rdatatype_key || type == dns_rdatatype_nsec) { cname_ok = false; + } /* * We now go looking for rdata... @@ -3972,11 +4115,13 @@ found: * Is this a "this rdataset doesn't * exist" record? */ - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); if (header != NULL) { /* @@ -4018,8 +4163,9 @@ found: found = NULL; break; } - if (found != NULL && foundsig != NULL) + if (found != NULL && foundsig != NULL) { break; + } } /* @@ -4051,17 +4197,19 @@ found: * use it, otherwise change sigtype * so that we find it. */ - if (cnamesig != NULL) + if (cnamesig != NULL) { foundsig = cnamesig; - else + } else { sigtype = RBTDB_RDATATYPE_SIGCNAME; + } } /* * If we've got all we need, end the search. */ - if (!maybe_zonecut && foundsig != NULL) + if (!maybe_zonecut && foundsig != NULL) { break; + } } else if (header->type == sigtype) { /* * We've found the RRSIG rdataset for our @@ -4071,8 +4219,9 @@ found: /* * If we've got all we need, end the search. */ - if (!maybe_zonecut && found != NULL) + if (!maybe_zonecut && found != NULL) { break; + } } else if (header->type == dns_rdatatype_nsec && !search.rbtversion->havensec3) { /* @@ -4149,8 +4298,9 @@ found: rdataset, sigrdataset, search.rbtdb->tree, search.rbtversion->secure); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_EMPTYWILD; + } goto tree_exit; } if ((search.options & DNS_DBFIND_FORCENSEC) != 0 && @@ -4171,12 +4321,14 @@ found: (search.options & DNS_DBFIND_FORCENSEC) != 0) { bind_rdataset(search.rbtdb, node, nsecheader, 0, rdataset); - if (nsecsig != NULL) + if (nsecsig != NULL) { bind_rdataset(search.rbtdb, node, nsecsig, 0, sigrdataset); + } } - if (wild) + if (wild) { foundname->attributes |= DNS_NAMEATTR_WILDCARD; + } goto node_exit; } @@ -4207,14 +4359,16 @@ found: */ if (type == dns_rdatatype_nsec || type == dns_rdatatype_nsec3 || - type == dns_rdatatype_key) + type == dns_rdatatype_key) { result = ISC_R_SUCCESS; - else if (type == dns_rdatatype_any) + } else if (type == dns_rdatatype_any) { result = DNS_R_ZONECUT; - else + } else { result = DNS_R_GLUE; - } else + } + } else { result = DNS_R_GLUE; + } /* * We might have found data that isn't glue, but was occluded * by a dynamic update. If the caller cares about this, they @@ -4238,22 +4392,25 @@ found: } if (nodep != NULL) { - if (!at_zonecut) + if (!at_zonecut) { new_reference(search.rbtdb, node); - else + } else { search.need_cleanup = false; + } *nodep = node; } if (type != dns_rdatatype_any) { bind_rdataset(search.rbtdb, node, found, 0, rdataset); - if (foundsig != NULL) + if (foundsig != NULL) { bind_rdataset(search.rbtdb, node, foundsig, 0, sigrdataset); + } } - if (wild) + if (wild) { foundname->attributes |= DNS_NAMEATTR_WILDCARD; + } node_exit: NODE_UNLOCK(lock, isc_rwlocktype_read); @@ -4276,8 +4433,9 @@ tree_exit: NODE_UNLOCK(lock, isc_rwlocktype_read); } - if (close_version) + if (close_version) { closeversion(db, &version, false); + } dns_rbtnodechain_reset(&search.chain); @@ -4358,17 +4516,19 @@ check_stale_header(dns_rbtnode_t *node, rdatasetheader_t *header, mctx = search->rbtdb->common.mctx; clean_stale_headers(search->rbtdb, mctx, header); - if (*header_prev != NULL) + if (*header_prev != NULL) { (*header_prev)->next = header->next; - else + } else { node->data = header->next; + } free_rdataset(search->rbtdb, mctx, header); } else { mark_header_ancient(search->rbtdb, header); *header_prev = header; } - } else + } else { *header_prev = header; + } return (true); } return (false); @@ -4416,8 +4576,9 @@ cache_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) EXISTS(header)) { sigdname_header = header; header_prev = header; - } else + } else { header_prev = header; + } } if (dname_header != NULL && @@ -4434,8 +4595,9 @@ cache_zonecut_callback(dns_rbtnode_t *node, dns_name_t *name, void *arg) search->zonecut_sigrdataset = sigdname_header; search->need_cleanup = true; result = DNS_R_PARTIALMATCH; - } else + } else { result = DNS_R_CONTINUE; + } NODE_UNLOCK(lock, locktype); @@ -4489,17 +4651,20 @@ find_deepest_zonecut(rbtdb_search_t *search, dns_rbtnode_t *node, */ if (header->type == dns_rdatatype_ns) { found = header; - if (foundsig != NULL) + if (foundsig != NULL) { break; + } } else if (header->type == RBTDB_RDATATYPE_SIGNS) { foundsig = header; - if (found != NULL) + if (found != NULL) { break; + } } header_prev = header; - } else + } else { header_prev = header; + } } if (found != NULL) { @@ -4538,9 +4703,10 @@ find_deepest_zonecut(rbtdb_search_t *search, dns_rbtnode_t *node, } bind_rdataset(search->rbtdb, node, found, search->now, rdataset); - if (foundsig != NULL) + if (foundsig != NULL) { bind_rdataset(search->rbtdb, node, foundsig, search->now, sigrdataset); + } if (need_headerupdate(found, search->now) || (foundsig != NULL && need_headerupdate(foundsig, search->now))) { @@ -4550,9 +4716,10 @@ find_deepest_zonecut(rbtdb_search_t *search, dns_rbtnode_t *node, locktype = isc_rwlocktype_write; POST(locktype); } - if (need_headerupdate(found, search->now)) + if (need_headerupdate(found, search->now)) { update_header(search->rbtdb, found, search->now); + } if (foundsig != NULL && need_headerupdate(foundsig, search->now)) { update_header(search->rbtdb, foundsig, @@ -4567,9 +4734,9 @@ find_deepest_zonecut(rbtdb_search_t *search, dns_rbtnode_t *node, if (found == NULL && i > 0) { i--; node = search->chain.levels[i]; - } else + } else { done = true; - + } } while (!done); return (result); @@ -4603,8 +4770,9 @@ find_coveringnsec(rbtdb_search_t *search, dns_dbnode_t **nodep, name = dns_fixedname_initname(&fname); origin = dns_fixedname_initname(&forigin); result = dns_rbtnodechain_current(&chain, name, origin, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } locktype = isc_rwlocktype_read; lock = &(search->rbtdb->node_locks[node->locknum].lock); NODE_LOCK(lock, locktype); @@ -4632,29 +4800,33 @@ find_coveringnsec(rbtdb_search_t *search, dns_dbnode_t **nodep, dns_rdatatype_rrsig) { empty_node = false; } - if (header->type == matchtype) + if (header->type == matchtype) { found = header; - else if (header->type == sigmatchtype) + } else if (header->type == sigmatchtype) { foundsig = header; + } header_prev = header; } if (found != NULL) { result = dns_name_concatenate(name, origin, foundname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock_node; + } bind_rdataset(search->rbtdb, node, found, now, rdataset); - if (foundsig != NULL) + if (foundsig != NULL) { bind_rdataset(search->rbtdb, node, foundsig, now, sigrdataset); + } new_reference(search->rbtdb, node); *nodep = node; result = DNS_R_COVERINGNSEC; } else if (!empty_node) { result = ISC_R_NOTFOUND; - } else + } else { result = dns_rbtnodechain_prev(&chain, NULL, NULL); + } unlock_node: NODE_UNLOCK(lock, locktype); } while (empty_node && result == ISC_R_SUCCESS); @@ -4688,8 +4860,9 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, REQUIRE(VALID_RBTDB(search.rbtdb)); REQUIRE(version == NULL); - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); + } search.rbtversion = NULL; search.serial = 1; @@ -4720,8 +4893,9 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, result = find_coveringnsec(&search, nodep, now, foundname, rdataset, sigrdataset); - if (result == DNS_R_COVERINGNSEC) + if (result == DNS_R_COVERINGNSEC) { goto tree_exit; + } } if (search.zonecut != NULL) { result = setup_delegation(&search, nodep, foundname, @@ -4734,8 +4908,9 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, sigrdataset); goto tree_exit; } - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto tree_exit; + } /* * Certain DNSSEC types are not subject to CNAME matching @@ -4744,8 +4919,9 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, * We don't check for RRSIG, because we don't store RRSIG records * directly. */ - if (type == dns_rdatatype_key || type == dns_rdatatype_nsec) + if (type == dns_rdatatype_key || type == dns_rdatatype_nsec) { cname_ok = false; + } /* * We now go looking for rdata... @@ -4836,8 +5012,9 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, cnamesig = header; } header_prev = header; - } else + } else { header_prev = header; + } } if (empty_node) { @@ -4872,13 +5049,15 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, } bind_rdataset(search.rbtdb, node, nsecheader, search.now, rdataset); - if (need_headerupdate(nsecheader, search.now)) + if (need_headerupdate(nsecheader, search.now)) { update = nsecheader; + } if (nsecsig != NULL) { bind_rdataset(search.rbtdb, node, nsecsig, search.now, sigrdataset); - if (need_headerupdate(nsecsig, search.now)) + if (need_headerupdate(nsecsig, search.now)) { updatesig = nsecsig; + } } result = DNS_R_COVERINGNSEC; goto node_exit; @@ -4896,13 +5075,15 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, } bind_rdataset(search.rbtdb, node, nsheader, search.now, rdataset); - if (need_headerupdate(nsheader, search.now)) + if (need_headerupdate(nsheader, search.now)) { update = nsheader; + } if (nssig != NULL) { bind_rdataset(search.rbtdb, node, nssig, search.now, sigrdataset); - if (need_headerupdate(nssig, search.now)) + if (need_headerupdate(nssig, search.now)) { updatesig = nssig; + } } result = DNS_R_DELEGATION; goto node_exit; @@ -4929,10 +5110,11 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, /* * We found a negative cache entry. */ - if (NXDOMAIN(found)) + if (NXDOMAIN(found)) { result = DNS_R_NCACHENXDOMAIN; - else + } else { result = DNS_R_NCACHENXRRSET; + } } else if (type != found->type && type != dns_rdatatype_any && found->type == dns_rdatatype_cname) { /* @@ -4951,13 +5133,15 @@ cache_find(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, if (type != dns_rdatatype_any || result == DNS_R_NCACHENXDOMAIN || result == DNS_R_NCACHENXRRSET) { bind_rdataset(search.rbtdb, node, found, search.now, rdataset); - if (need_headerupdate(found, search.now)) + if (need_headerupdate(found, search.now)) { update = found; + } if (!NEGATIVE(found) && foundsig != NULL) { bind_rdataset(search.rbtdb, node, foundsig, search.now, sigrdataset); - if (need_headerupdate(foundsig, search.now)) + if (need_headerupdate(foundsig, search.now)) { updatesig = foundsig; + } } } @@ -4969,10 +5153,12 @@ node_exit: locktype = isc_rwlocktype_write; POST(locktype); } - if (update != NULL && need_headerupdate(update, search.now)) + if (update != NULL && need_headerupdate(update, search.now)) { update_header(search.rbtdb, update, search.now); - if (updatesig != NULL && need_headerupdate(updatesig, search.now)) + } + if (updatesig != NULL && need_headerupdate(updatesig, search.now)) { update_header(search.rbtdb, updatesig, search.now); + } NODE_UNLOCK(lock, locktype); @@ -5020,8 +5206,9 @@ cache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, REQUIRE(VALID_RBTDB(search.rbtdb)); - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); + } search.rbtversion = NULL; search.serial = 1; @@ -5038,8 +5225,9 @@ cache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, dcname = foundname; } - if ((options & DNS_DBFIND_NOEXACT) != 0) + if ((options & DNS_DBFIND_NOEXACT) != 0) { rbtoptions |= DNS_RBTFIND_NOEXACT; + } RWLOCK(&search.rbtdb->tree_lock, isc_rwlocktype_read); @@ -5094,8 +5282,9 @@ cache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, foundsig = header; } header_prev = header; - } else + } else { header_prev = header; + } } if (found == NULL) { @@ -5115,9 +5304,10 @@ cache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, } bind_rdataset(search.rbtdb, node, found, search.now, rdataset); - if (foundsig != NULL) + if (foundsig != NULL) { bind_rdataset(search.rbtdb, node, foundsig, search.now, sigrdataset); + } if (need_headerupdate(found, search.now) || (foundsig != NULL && need_headerupdate(foundsig, search.now))) { @@ -5127,8 +5317,9 @@ cache_findzonecut(dns_db_t *db, const dns_name_t *name, unsigned int options, locktype = isc_rwlocktype_write; POST(locktype); } - if (need_headerupdate(found, search.now)) + if (need_headerupdate(found, search.now)) { update_header(search.rbtdb, found, search.now); + } if (foundsig != NULL && need_headerupdate(foundsig, search.now)) { update_header(search.rbtdb, foundsig, search.now); @@ -5144,8 +5335,9 @@ tree_exit: dns_rbtnodechain_reset(&search.chain); - if (result == DNS_R_DELEGATION) + if (result == DNS_R_DELEGATION) { result = ISC_R_SUCCESS; + } return (result); } @@ -5196,16 +5388,18 @@ detachnode(dns_db_t *db, dns_dbnode_t **targetp) if (inactive) { RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_write); rbtdb->active--; - if (rbtdb->active == 0) + if (rbtdb->active == 0) { want_free = true; + } RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write); if (want_free) { char buf[DNS_NAME_FORMATSIZE]; - if (dns_name_dynamic(&rbtdb->common.origin)) + if (dns_name_dynamic(&rbtdb->common.origin)) { dns_name_format(&rbtdb->common.origin, buf, sizeof(buf)); - else + } else { strlcpy(buf, "", sizeof(buf)); + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_DEBUG(1), "calling free_rbtdb(%s)", buf); @@ -5236,8 +5430,9 @@ expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) * Caller must hold a tree lock. */ - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); + } if (isc_mem_isovermem(rbtdb->common.mctx)) { /* @@ -5253,13 +5448,14 @@ expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) * databases -- hence all of the "overmem cache" log strings. */ log = isc_log_wouldlog(dns_lctx, level); - if (log) + if (log) { isc_log_write( dns_lctx, category, module, level, "overmem cache: %s %s", force_expire ? "FORCE" : "check", dns_rbt_formatnodename(rbtnode, printname, sizeof(printname))); + } } /* @@ -5269,7 +5465,7 @@ expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) NODE_LOCK(&rbtdb->node_locks[rbtnode->locknum].lock, isc_rwlocktype_write); - for (header = rbtnode->data; header != NULL; header = header->next) + for (header = rbtnode->data; header != NULL; header = header->next) { if (header->rdh_ttl <= now - RBTDB_VIRTUAL) { /* * We don't check if refcurrent(rbtnode) == 0 and try @@ -5278,10 +5474,11 @@ expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) * because 'node' is an argument to the function. */ mark_header_ancient(rbtdb, header); - if (log) + if (log) { isc_log_write(dns_lctx, category, module, level, "overmem cache: ancient %s", printname); + } } else if (force_expire) { if (!RETAIN(header)) { set_ttl(rbtdb, header, 0); @@ -5296,6 +5493,7 @@ expirenode(dns_db_t *db, dns_dbnode_t *node, isc_stdtime_t now) isc_log_write(dns_lctx, category, module, level, "overmem cache: saved %s", printname); } + } NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, isc_rwlocktype_write); @@ -5339,8 +5537,9 @@ printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) first = true; fprintf(out, "\ttype %u", current->type); do { - if (!first) + if (!first) { fprintf(out, "\t"); + } first = false; fprintf(out, "\tserial = %lu, ttl = %u, " @@ -5354,8 +5553,9 @@ printnode(dns_db_t *db, dns_dbnode_t *node, FILE *out) current = current->down; } while (current != NULL); } - } else + } else { fprintf(out, "(empty)\n"); + } NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, isc_rwlocktype_read); @@ -5390,10 +5590,11 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) memset(rbtdbiter->deletions, 0, sizeof(rbtdbiter->deletions)); dns_rbtnodechain_init(&rbtdbiter->chain); dns_rbtnodechain_init(&rbtdbiter->nsec3chain); - if (rbtdbiter->nsec3only) + if (rbtdbiter->nsec3only) { rbtdbiter->current = &rbtdbiter->nsec3chain; - else + } else { rbtdbiter->current = &rbtdbiter->chain; + } *iteratorp = (dns_dbiterator_t *)rbtdbiter; @@ -5431,10 +5632,11 @@ zone_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, found = NULL; foundsig = NULL; matchtype = RBTDB_RDATATYPE_VALUE(type, covers); - if (covers == 0) + if (covers == 0) { sigmatchtype = RBTDB_RDATATYPE_VALUE(dns_rdatatype_rrsig, type); - else + } else { sigmatchtype = 0; + } for (header = rbtnode->data; header != NULL; header = header_next) { header_next = header->next; @@ -5444,11 +5646,13 @@ zone_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, * Is this a "this rdataset doesn't * exist" record? */ - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); if (header != NULL) { /* @@ -5457,31 +5661,36 @@ zone_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, */ if (header->type == matchtype) { found = header; - if (foundsig != NULL) + if (foundsig != NULL) { break; + } } else if (header->type == sigmatchtype) { foundsig = header; - if (found != NULL) + if (found != NULL) { break; + } } } } if (found != NULL) { bind_rdataset(rbtdb, rbtnode, found, now, rdataset); - if (foundsig != NULL) + if (foundsig != NULL) { bind_rdataset(rbtdb, rbtnode, foundsig, now, sigrdataset); + } } NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, isc_rwlocktype_read); - if (close_version) + if (close_version) { closeversion(db, (dns_dbversion_t **)(void *)(&rbtversion), false); + } - if (found == NULL) + if (found == NULL) { return (ISC_R_NOTFOUND); + } return (ISC_R_SUCCESS); } @@ -5507,8 +5716,9 @@ cache_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, result = ISC_R_SUCCESS; - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); + } lock = &rbtdb->node_locks[rbtnode->locknum].lock; locktype = isc_rwlocktype_read; @@ -5518,10 +5728,11 @@ cache_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, foundsig = NULL; matchtype = RBTDB_RDATATYPE_VALUE(type, covers); negtype = RBTDB_RDATATYPE_VALUE(0, type); - if (covers == 0) + if (covers == 0) { sigmatchtype = RBTDB_RDATATYPE_VALUE(dns_rdatatype_rrsig, type); - else + } else { sigmatchtype = 0; + } for (header = rbtnode->data; header != NULL; header = header_next) { header_next = header->next; @@ -5545,35 +5756,39 @@ cache_findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, mark_header_ancient(rbtdb, header); } } else if (EXISTS(header) && !ANCIENT(header)) { - if (header->type == matchtype) + if (header->type == matchtype) { found = header; - else if (header->type == RBTDB_RDATATYPE_NCACHEANY || - header->type == negtype) + } else if (header->type == RBTDB_RDATATYPE_NCACHEANY || + header->type == negtype) { found = header; - else if (header->type == sigmatchtype) + } else if (header->type == sigmatchtype) { foundsig = header; + } } } if (found != NULL) { bind_rdataset(rbtdb, rbtnode, found, now, rdataset); - if (!NEGATIVE(found) && foundsig != NULL) + if (!NEGATIVE(found) && foundsig != NULL) { bind_rdataset(rbtdb, rbtnode, foundsig, now, sigrdataset); + } } NODE_UNLOCK(lock, locktype); - if (found == NULL) + if (found == NULL) { return (ISC_R_NOTFOUND); + } if (NEGATIVE(found)) { /* * We found a negative cache entry. */ - if (NXDOMAIN(found)) + if (NXDOMAIN(found)) { result = DNS_R_NCACHENXDOMAIN; - else + } else { result = DNS_R_NCACHENXRRSET; + } } update_cachestats(rbtdb, result); @@ -5596,17 +5811,18 @@ allrdatasets(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, if ((db->attributes & DNS_DBATTR_CACHE) == 0) { now = 0; - if (rbtversion == NULL) + if (rbtversion == NULL) { currentversion( db, (dns_dbversion_t **)(void *)(&rbtversion)); - else { + } else { INSIST(rbtversion->rbtdb == rbtdb); (void)isc_refcount_increment(&rbtversion->references); } } else { - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); + } rbtversion = NULL; } @@ -5655,14 +5871,17 @@ cname_and_other_data(dns_rbtnode_t *node, rbtdb_serial_t serial) * Is this a "this rdataset doesn't * exist" record? */ - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); - if (header != NULL) + if (header != NULL) { cname = true; + } } else { /* * Look for active extant "other data". @@ -5685,20 +5904,24 @@ cname_and_other_data(dns_rbtnode_t *node, rbtdb_serial_t serial) * Is this a "this rdataset * doesn't exist" record? */ - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); - if (header != NULL) + if (header != NULL) { other_data = true; + } } } } - if (cname && other_data) + if (cname && other_data) { return (true); + } return (false); } @@ -5780,13 +6003,15 @@ add32(dns_rbtdb_t *rbtdb, dns_rbtnode_t *rbtnode, rbtdb_version_t *rbtversion, if ((options & DNS_DBADD_MERGE) != 0) { REQUIRE(rbtversion != NULL); merge = true; - } else + } else { merge = false; + } - if ((options & DNS_DBADD_FORCE) != 0) + if ((options & DNS_DBADD_FORCE) != 0) { trust = dns_trust_ultimate; - else + } else { trust = newheader->trust; + } if (rbtversion != NULL && !loading) { /* @@ -5873,10 +6098,11 @@ add32(dns_rbtdb_t *rbtdb, dns_rbtnode_t *rbtnode, rbtdb_version_t *rbtversion, */ free_rdataset(rbtdb, rbtdb->common.mctx, newheader); - if (addedrdataset != NULL) + if (addedrdataset != NULL) { bind_rdataset(rbtdb, rbtnode, topheader, now, addedrdataset); + } return (DNS_R_UNCHANGED); } /* @@ -5895,8 +6121,9 @@ add32(dns_rbtdb_t *rbtdb, dns_rbtnode_t *rbtnode, rbtdb_version_t *rbtversion, for (topheader = rbtnode->data; topheader != NULL; topheader = topheader->next) { if (topheader->type == newheader->type || - topheader->type == negtype) + topheader->type == negtype) { break; + } topheader_prev = topheader; } @@ -5907,8 +6134,9 @@ find_header: * data. We skip over them. */ header = topheader; - while (header != NULL && IGNORE(header)) + while (header != NULL && IGNORE(header)) { header = header->down; + } if (header != NULL) { header_nx = NONEXISTENT(header) ? true : false; @@ -5930,17 +6158,19 @@ find_header: if (rbtversion == NULL && trust < header->trust && (ACTIVE(header, now) || header_nx)) { free_rdataset(rbtdb, rbtdb->common.mctx, newheader); - if (addedrdataset != NULL) + if (addedrdataset != NULL) { bind_rdataset(rbtdb, rbtnode, header, now, addedrdataset); + } return (DNS_R_UNCHANGED); } /* * Don't merge if a nonexistent rdataset is involved. */ - if (merge && (header_nx || newheader_nx)) + if (merge && (header_nx || newheader_nx)) { merge = false; + } /* * If 'merge' is true, we'll try to create a new rdataset @@ -5952,18 +6182,20 @@ find_header: merged = NULL; result = ISC_R_SUCCESS; - if ((options & DNS_DBADD_EXACT) != 0) + if ((options & DNS_DBADD_EXACT) != 0) { flags |= DNS_RDATASLAB_EXACT; + } /* * TTL use here is irrelevant to the cache; * merge is only done with zonedbs. */ if ((options & DNS_DBADD_EXACTTTL) != 0 && - newheader->rdh_ttl != header->rdh_ttl) + newheader->rdh_ttl != header->rdh_ttl) { result = DNS_R_NOTEXACT; - else if (newheader->rdh_ttl != header->rdh_ttl) + } else if (newheader->rdh_ttl != header->rdh_ttl) { flags |= DNS_RDATASLAB_FORCE; - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { result = dns_rdataslab_merge( (unsigned char *)header, (unsigned char *)newheader, @@ -5972,6 +6204,7 @@ find_header: rbtdb->common.rdclass, (dns_rdatatype_t)header->type, flags, &merged); + } if (result == ISC_R_SUCCESS) { /* * If 'header' has the same serial number as @@ -6019,8 +6252,9 @@ find_header: * Honour the new ttl if it is less than the * older one. */ - if (header->rdh_ttl > newheader->rdh_ttl) + if (header->rdh_ttl > newheader->rdh_ttl) { set_ttl(rbtdb, header, newheader->rdh_ttl); + } if (header->noqname == NULL && newheader->noqname != NULL) { header->noqname = newheader->noqname; @@ -6032,9 +6266,10 @@ find_header: newheader->closest = NULL; } free_rdataset(rbtdb, rbtdb->common.mctx, newheader); - if (addedrdataset != NULL) + if (addedrdataset != NULL) { bind_rdataset(rbtdb, rbtnode, header, now, addedrdataset); + } return (ISC_R_SUCCESS); } /* @@ -6064,8 +6299,9 @@ find_header: * Honour the new ttl if it is less than the * older one. */ - if (header->rdh_ttl > newheader->rdh_ttl) + if (header->rdh_ttl > newheader->rdh_ttl) { set_ttl(rbtdb, header, newheader->rdh_ttl); + } if (header->noqname == NULL && newheader->noqname != NULL) { header->noqname = newheader->noqname; @@ -6077,9 +6313,10 @@ find_header: newheader->closest = NULL; } free_rdataset(rbtdb, rbtdb->common.mctx, newheader); - if (addedrdataset != NULL) + if (addedrdataset != NULL) { bind_rdataset(rbtdb, rbtnode, header, now, addedrdataset); + } return (ISC_R_SUCCESS); } INSIST(rbtversion == NULL || @@ -6088,12 +6325,13 @@ find_header: newheader->down = NULL; idx = newheader->node->locknum; if (IS_CACHE(rbtdb)) { - if (ZEROTTL(newheader)) + if (ZEROTTL(newheader)) { ISC_LIST_APPEND(rbtdb->rdatasets[idx], newheader, link); - else + } else { ISC_LIST_PREPEND(rbtdb->rdatasets[idx], newheader, link); + } INSIST(rbtdb->heaps != NULL); result = isc_heap_insert(rbtdb->heaps[idx], newheader); @@ -6122,10 +6360,11 @@ find_header: * Since we don't generate changed records when * loading, we MUST clean up 'header' now. */ - if (topheader_prev != NULL) + if (topheader_prev != NULL) { topheader_prev->next = newheader; - else + } else { rbtnode->data = newheader; + } newheader->next = topheader->next; if (rbtversion != NULL && !header_nx) { update_recordsandbytes(false, rbtversion, @@ -6143,12 +6382,13 @@ find_header: newheader); return (result); } - if (ZEROTTL(newheader)) + if (ZEROTTL(newheader)) { ISC_LIST_APPEND(rbtdb->rdatasets[idx], newheader, link); - else + } else { ISC_LIST_PREPEND(rbtdb->rdatasets[idx], newheader, link); + } } else if (RESIGN(newheader)) { result = resign_insert(rbtdb, idx, newheader); if (result != ISC_R_SUCCESS) { @@ -6158,16 +6398,18 @@ find_header: } resign_delete(rbtdb, rbtversion, header); } - if (topheader_prev != NULL) + if (topheader_prev != NULL) { topheader_prev->next = newheader; - else + } else { rbtnode->data = newheader; + } newheader->next = topheader->next; newheader->down = topheader; topheader->next = newheader; rbtnode->dirty = 1; - if (changed != NULL) + if (changed != NULL) { changed->dirty = true; + } if (rbtversion == NULL) { set_ttl(rbtdb, header, 0); mark_header_ancient(rbtdb, header); @@ -6203,12 +6445,13 @@ find_header: newheader); return (result); } - if (ZEROTTL(newheader)) + if (ZEROTTL(newheader)) { ISC_LIST_APPEND(rbtdb->rdatasets[idx], newheader, link); - else + } else { ISC_LIST_PREPEND(rbtdb->rdatasets[idx], newheader, link); + } } else if (RESIGN(newheader)) { result = resign_insert(rbtdb, idx, newheader); if (result != ISC_R_SUCCESS) { @@ -6261,11 +6504,13 @@ find_header: * Check if the node now contains CNAME and other data. */ if (rbtversion != NULL && - cname_and_other_data(rbtnode, rbtversion->serial)) + cname_and_other_data(rbtnode, rbtversion->serial)) { return (DNS_R_CNAMEANDOTHER); + } - if (addedrdataset != NULL) + if (addedrdataset != NULL) { bind_rdataset(rbtdb, rbtnode, newheader, now, addedrdataset); + } return (ISC_R_SUCCESS); } @@ -6274,14 +6519,16 @@ static inline bool delegating_type(dns_rbtdb_t *rbtdb, dns_rbtnode_t *node, rbtdb_rdatatype_t type) { if (IS_CACHE(rbtdb)) { - if (type == dns_rdatatype_dname) + if (type == dns_rdatatype_dname) { return (true); - else + } else { return (false); + } } else if (type == dns_rdatatype_dname || (type == dns_rdatatype_ns && - (node != rbtdb->origin_node || IS_STUB(rbtdb)))) + (node != rbtdb->origin_node || IS_STUB(rbtdb)))) { return (true); + } return (false); } @@ -6310,12 +6557,14 @@ addnoqname(dns_rbtdb_t *rbtdb, rdatasetheader_t *newheader, noqname->type = neg.type; dns_name_dup(&name, mctx, &noqname->name); result = dns_rdataslab_fromrdataset(&neg, mctx, &r, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } noqname->neg = r.base; result = dns_rdataslab_fromrdataset(&negsig, mctx, &r, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } noqname->negsig = r.base; dns_rdataset_disassociate(&neg); dns_rdataset_disassociate(&negsig); @@ -6354,12 +6603,14 @@ addclosest(dns_rbtdb_t *rbtdb, rdatasetheader_t *newheader, closest->type = neg.type; dns_name_dup(&name, mctx, &closest->name); result = dns_rdataslab_fromrdataset(&neg, mctx, &r, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } closest->neg = r.base; result = dns_rdataslab_fromrdataset(&negsig, mctx, &r, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } closest->negsig = r.base; dns_rdataset_disassociate(&neg); dns_rdataset_disassociate(&negsig); @@ -6409,15 +6660,18 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, } if (rbtversion == NULL) { - if (now == 0) + if (now == 0) { isc_stdtime_get(&now); - } else + } + } else { now = 0; + } result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx, ®ion, sizeof(rdatasetheader_t)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } name = dns_fixedname_initname(&fixed); RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_read); @@ -6432,8 +6686,9 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, newheader->type = RBTDB_RDATATYPE_VALUE(rdataset->type, rdataset->covers); newheader->attributes = 0; - if (rdataset->ttl == 0U) + if (rdataset->ttl == 0U) { newheader->attributes |= RDATASET_ATTR_ZEROTTL; + } newheader->noqname = NULL; newheader->closest = NULL; atomic_init(&newheader->count, @@ -6458,14 +6713,18 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, newheader->serial = 1; newheader->resign = 0; newheader->resign_lsb = 0; - if ((rdataset->attributes & DNS_RDATASETATTR_PREFETCH) != 0) + if ((rdataset->attributes & DNS_RDATASETATTR_PREFETCH) != 0) { newheader->attributes |= RDATASET_ATTR_PREFETCH; - if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) + } + if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) { newheader->attributes |= RDATASET_ATTR_NEGATIVE; - if ((rdataset->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0) + } + if ((rdataset->attributes & DNS_RDATASETATTR_NXDOMAIN) != 0) { newheader->attributes |= RDATASET_ATTR_NXDOMAIN; - if ((rdataset->attributes & DNS_RDATASETATTR_OPTOUT) != 0) + } + if ((rdataset->attributes & DNS_RDATASETATTR_OPTOUT) != 0) { newheader->attributes |= RDATASET_ATTR_OPTOUT; + } if ((rdataset->attributes & DNS_RDATASETATTR_NOQNAME) != 0) { result = addnoqname(rbtdb, newheader, rdataset); if (result != ISC_R_SUCCESS) { @@ -6489,10 +6748,11 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, * just DNAME for the cache), then we need to set the callback bit * on the node. */ - if (delegating_type(rbtdb, rbtnode, rdataset->type)) + if (delegating_type(rbtdb, rbtnode, rdataset->type)) { delegating = true; - else + } else { delegating = false; + } /* * Add to the auxiliary NSEC tree if we're adding an NSEC record. @@ -6512,15 +6772,17 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, * the tree. In the latter case the lock does not necessarily have to * be acquired but it will help purge ancient entries more effectively. */ - if (IS_CACHE(rbtdb) && isc_mem_isovermem(rbtdb->common.mctx)) + if (IS_CACHE(rbtdb) && isc_mem_isovermem(rbtdb->common.mctx)) { cache_is_overmem = true; + } if (delegating || newnsec || cache_is_overmem) { tree_locked = true; RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_write); } - if (cache_is_overmem) + if (cache_is_overmem) { overmem_purge(rbtdb, rbtnode->locknum, now, tree_locked); + } NODE_LOCK(&rbtdb->node_locks[rbtnode->locknum].lock, isc_rwlocktype_write); @@ -6531,12 +6793,14 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, } if (IS_CACHE(rbtdb)) { - if (tree_locked) + if (tree_locked) { cleanup_dead_nodes(rbtdb, rbtnode->locknum); + } header = isc_heap_element(rbtdb->heaps[rbtnode->locknum], 1); - if (header && header->rdh_ttl < now - RBTDB_VIRTUAL) + if (header && header->rdh_ttl < now - RBTDB_VIRTUAL) { expire_header(rbtdb, header, tree_locked, expire_ttl); + } /* * If we've been holding a write lock on the tree just for @@ -6565,24 +6829,28 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, } } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = add32(rbtdb, rbtnode, rbtversion, newheader, options, false, addedrdataset, now); - if (result == ISC_R_SUCCESS && delegating) + } + if (result == ISC_R_SUCCESS && delegating) { rbtnode->find_callback = 1; + } NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, isc_rwlocktype_write); - if (tree_locked) + if (tree_locked) { RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_write); + } /* * Update the zone's secure status. If version is non-NULL * this is deferred until closeversion() is called. */ - if (result == ISC_R_SUCCESS && version == NULL && !IS_CACHE(rbtdb)) + if (result == ISC_R_SUCCESS && version == NULL && !IS_CACHE(rbtdb)) { iszonesecure(db, version, rbtdb->origin_node); + } return (result); } @@ -6617,8 +6885,9 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx, ®ion, sizeof(rdatasetheader_t)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } newheader = (rdatasetheader_t *)region.base; init_rdataset(rbtdb, newheader); set_ttl(rbtdb, newheader, rdataset->ttl); @@ -6657,8 +6926,9 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, topheader_prev = NULL; for (topheader = rbtnode->data; topheader != NULL; topheader = topheader->next) { - if (topheader->type == newheader->type) + if (topheader->type == newheader->type) { break; + } topheader_prev = topheader; } /* @@ -6667,18 +6937,20 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, * data. We skip over them. */ header = topheader; - while (header != NULL && IGNORE(header)) + while (header != NULL && IGNORE(header)) { header = header->down; + } if (header != NULL && EXISTS(header)) { unsigned int flags = 0; subresult = NULL; result = ISC_R_SUCCESS; if ((options & DNS_DBSUB_EXACT) != 0) { flags |= DNS_RDATASLAB_EXACT; - if (newheader->rdh_ttl != header->rdh_ttl) + if (newheader->rdh_ttl != header->rdh_ttl) { result = DNS_R_NOTEXACT; + } } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_rdataslab_subtract( (unsigned char *)header, (unsigned char *)newheader, @@ -6686,6 +6958,7 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, rbtdb->common.mctx, rbtdb->common.rdclass, (dns_rdatatype_t)header->type, flags, &subresult); + } if (result == ISC_R_SUCCESS) { free_rdataset(rbtdb, rbtdb->common.mctx, newheader); newheader = (rdatasetheader_t *)subresult; @@ -6750,10 +7023,11 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, */ INSIST(rbtversion->serial >= topheader->serial); update_recordsandbytes(false, rbtversion, header); - if (topheader_prev != NULL) + if (topheader_prev != NULL) { topheader_prev->next = newheader; - else + } else { rbtnode->data = newheader; + } newheader->next = topheader->next; newheader->down = topheader; topheader->next = newheader; @@ -6766,18 +7040,21 @@ subtractrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, * to satisfy the deletion request. */ free_rdataset(rbtdb, rbtdb->common.mctx, newheader); - if ((options & DNS_DBSUB_EXACT) != 0) + if ((options & DNS_DBSUB_EXACT) != 0) { result = DNS_R_NOTEXACT; - else + } else { result = DNS_R_UNCHANGED; + } } - if (result == ISC_R_SUCCESS && newrdataset != NULL) + if (result == ISC_R_SUCCESS && newrdataset != NULL) { bind_rdataset(rbtdb, rbtnode, newheader, 0, newrdataset); + } if (result == DNS_R_NXRRSET && newrdataset != NULL && - (options & DNS_DBSUB_WANTOLD) != 0) + (options & DNS_DBSUB_WANTOLD) != 0) { bind_rdataset(rbtdb, rbtnode, header, 0, newrdataset); + } unlock: NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, @@ -6810,14 +7087,17 @@ deleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, REQUIRE(VALID_RBTDB(rbtdb)); INSIST(rbtversion == NULL || rbtversion->rbtdb == rbtdb); - if (type == dns_rdatatype_any) + if (type == dns_rdatatype_any) { return (ISC_R_NOTIMPLEMENTED); - if (type == dns_rdatatype_rrsig && covers == 0) + } + if (type == dns_rdatatype_rrsig && covers == 0) { return (ISC_R_NOTIMPLEMENTED); + } newheader = new_rdataset(rbtdb, rbtdb->common.mctx); - if (newheader == NULL) + if (newheader == NULL) { return (ISC_R_NOMEMORY); + } init_rdataset(rbtdb, newheader); set_ttl(rbtdb, newheader, 0); newheader->type = RBTDB_RDATATYPE_VALUE(type, covers); @@ -6825,10 +7105,11 @@ deleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, newheader->trust = 0; newheader->noqname = NULL; newheader->closest = NULL; - if (rbtversion != NULL) + if (rbtversion != NULL) { newheader->serial = rbtversion->serial; - else + } else { newheader->serial = 0; + } atomic_init(&newheader->count, 0); newheader->last_used = 0; newheader->node = rbtnode; @@ -6867,17 +7148,20 @@ loadnode(dns_rbtdb_t *rbtdb, const dns_name_t *name, dns_rbtnode_t **nodep, dns_rbtnode_t *nsecnode = NULL, *node = NULL; noderesult = dns_rbt_addnode(rbtdb->tree, name, &node); - if (!hasnsec) + if (!hasnsec) { goto done; + } if (noderesult == ISC_R_EXISTS) { /* * Add a node to the auxiliary NSEC tree for an old node * just now getting an NSEC record. */ - if (node->nsec == DNS_RBT_NSEC_HAS_NSEC) + if (node->nsec == DNS_RBT_NSEC_HAS_NSEC) { goto done; - } else if (noderesult != ISC_R_SUCCESS) + } + } else if (noderesult != ISC_R_SUCCESS) { goto done; + } /* * Build the auxiliary tree for NSECs as we go. @@ -6899,7 +7183,7 @@ loadnode(dns_rbtdb_t *rbtdb, const dns_name_t *name, dns_rbtnode_t **nodep, isc_log_write(dns_lctx, DNS_LOGCATEGORY_DATABASE, DNS_LOGMODULE_CACHE, ISC_LOG_WARNING, "addnode: NSEC node already exists"); -#endif +#endif /* if 1 */ node->nsec = DNS_RBT_NSEC_HAS_NSEC; goto done; } @@ -6926,8 +7210,9 @@ loadnode(dns_rbtdb_t *rbtdb, const dns_name_t *name, dns_rbtnode_t **nodep, noderesult = nsecresult; done: - if (noderesult == ISC_R_SUCCESS || noderesult == ISC_R_EXISTS) + if (noderesult == ISC_R_SUCCESS || noderesult == ISC_R_EXISTS) { *nodep = node; + } return (noderesult); } @@ -6954,42 +7239,49 @@ loading_addrdataset(void *arg, const dns_name_t *name, dns_rdataset_t *rdataset) * SOA records are only allowed at top of zone. */ if (rdataset->type == dns_rdatatype_soa && !IS_CACHE(rbtdb) && - !dns_name_equal(name, &rbtdb->common.origin)) + !dns_name_equal(name, &rbtdb->common.origin)) { return (DNS_R_NOTZONETOP); + } if (rdataset->type != dns_rdatatype_nsec3 && - rdataset->covers != dns_rdatatype_nsec3) + rdataset->covers != dns_rdatatype_nsec3) { add_empty_wildcards(rbtdb, name); + } if (dns_name_iswildcard(name)) { /* * NS record owners cannot legally be wild cards. */ - if (rdataset->type == dns_rdatatype_ns) + if (rdataset->type == dns_rdatatype_ns) { return (DNS_R_INVALIDNS); + } /* * NSEC3 record owners cannot legally be wild cards. */ - if (rdataset->type == dns_rdatatype_nsec3) + if (rdataset->type == dns_rdatatype_nsec3) { return (DNS_R_INVALIDNSEC3); + } result = add_wildcard_magic(rbtdb, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } node = NULL; if (rdataset->type == dns_rdatatype_nsec3 || rdataset->covers == dns_rdatatype_nsec3) { result = dns_rbt_addnode(rbtdb->nsec3, name, &node); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { node->nsec = DNS_RBT_NSEC_NSEC3; + } } else if (rdataset->type == dns_rdatatype_nsec) { result = loadnode(rbtdb, name, &node, true); } else { result = loadnode(rbtdb, name, &node, false); } - if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) + if (result != ISC_R_SUCCESS && result != ISC_R_EXISTS) { return (result); + } if (result == ISC_R_SUCCESS) { dns_name_t foundname; dns_name_init(&foundname, NULL); @@ -6999,12 +7291,13 @@ loading_addrdataset(void *arg, const dns_name_t *name, dns_rdataset_t *rdataset) result = dns_rdataslab_fromrdataset(rdataset, rbtdb->common.mctx, ®ion, sizeof(rdatasetheader_t)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } newheader = (rdatasetheader_t *)region.base; init_rdataset(rbtdb, newheader); set_ttl(rbtdb, newheader, rdataset->ttl + loadctx->now); /* XXX overflow - check */ + * check */ newheader->type = RBTDB_RDATATYPE_VALUE(rdataset->type, rdataset->covers); newheader->attributes = 0; @@ -7037,10 +7330,11 @@ loading_addrdataset(void *arg, const dns_name_t *name, dns_rdataset_t *rdataset) isc_rwlocktype_write); if (result == ISC_R_SUCCESS && - delegating_type(rbtdb, node, rdataset->type)) + delegating_type(rbtdb, node, rdataset->type)) { node->find_callback = 1; - else if (result == DNS_R_UNCHANGED) + } else if (result == DNS_R_UNCHANGED) { result = ISC_R_SUCCESS; + } return (result); } @@ -7065,7 +7359,7 @@ rbt_datafixer(dns_rbtnode_t *rbtnode, void *base, size_t filesize, void *arg, hexdump("hashing header", p, sizeof(rdatasetheader_t)); hexdump("hashing slab", p + sizeof(rdatasetheader_t), size - sizeof(rdatasetheader_t)); -#endif +#endif /* ifdef DEBUG */ header->serial = 1; header->is_mmapped = 1; header->node = rbtnode; @@ -7075,20 +7369,23 @@ rbt_datafixer(dns_rbtnode_t *rbtnode, void *base, size_t filesize, void *arg, (header->resign != 0 || header->resign_lsb != 0)) { int idx = header->node->locknum; result = isc_heap_insert(rbtdb->heaps[idx], header); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } if (header->next != NULL) { size_t cooked = dns_rbt_serialize_align(size); if ((uintptr_t)header->next != - (p - (unsigned char *)base) + cooked) + (p - (unsigned char *)base) + cooked) { return (ISC_R_INVALIDFILE); + } header->next = (rdatasetheader_t *)(p + cooked); header->next_is_relative = 0; if ((header->next < (rdatasetheader_t *)base) || - (header->next > (rdatasetheader_t *)limit)) + (header->next > (rdatasetheader_t *)limit)) { return (ISC_R_INVALIDFILE); + } } update_recordsandbytes(true, rbtdb->current_version, header); } @@ -7128,7 +7425,7 @@ deserialize32(void *arg, FILE *f, off_t offset) flags = MAP_PRIVATE; #ifdef MAP_FILE flags |= MAP_FILE; -#endif +#endif /* ifdef MAP_FILE */ base = isc_file_mmap(NULL, filesize, protect, flags, fd, 0); if (base == NULL || base == MAP_FAILED) { @@ -7146,14 +7443,16 @@ deserialize32(void *arg, FILE *f, off_t offset) base, filesize, (off_t)header->tree, rbtdb->common.mctx, delete_callback, rbtdb, rbt_datafixer, rbtdb, NULL, &tree); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_rbt_findnode(tree, &rbtdb->common.origin, NULL, &origin_node, NULL, DNS_RBTFIND_EMPTYDATA, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } if (header->nsec != 0) { @@ -7161,8 +7460,9 @@ deserialize32(void *arg, FILE *f, off_t offset) base, filesize, (off_t)header->nsec, rbtdb->common.mctx, delete_callback, rbtdb, rbt_datafixer, rbtdb, NULL, &nsec); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } if (header->nsec3 != 0) { @@ -7170,8 +7470,9 @@ deserialize32(void *arg, FILE *f, off_t offset) base, filesize, (off_t)header->nsec3, rbtdb->common.mctx, delete_callback, rbtdb, rbt_datafixer, rbtdb, NULL, &nsec3); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } /* @@ -7201,12 +7502,15 @@ deserialize32(void *arg, FILE *f, off_t offset) return (ISC_R_SUCCESS); cleanup: - if (tree != NULL) + if (tree != NULL) { dns_rbt_destroy(&tree); - if (nsec != NULL) + } + if (nsec != NULL) { dns_rbt_destroy(&nsec); - if (nsec3 != NULL) + } + if (nsec3 != NULL) { dns_rbt_destroy(&nsec3); + } isc_file_munmap(base, (size_t)filesize); return (result); } @@ -7224,10 +7528,11 @@ beginload(dns_db_t *db, dns_rdatacallbacks_t *callbacks) loadctx = isc_mem_get(rbtdb->common.mctx, sizeof(*loadctx)); loadctx->rbtdb = rbtdb; - if (IS_CACHE(rbtdb)) + if (IS_CACHE(rbtdb)) { isc_stdtime_get(&loadctx->now); - else + } else { loadctx->now = 0; + } RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_write); @@ -7315,15 +7620,18 @@ rbt_datawriter(FILE *rbtfile, unsigned char *data, void *arg, uint64_t *crc) next = header->next; do { if (header->serial <= serial && !IGNORE(header)) { - if (NONEXISTENT(header)) + if (NONEXISTENT(header)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); - if (header == NULL) + if (header == NULL) { continue; + } CHECK(isc_stdio_tell(rbtfile, &where)); size = dns_rdataslab_size((unsigned char *)header, @@ -7334,8 +7642,9 @@ rbt_datawriter(FILE *rbtfile, unsigned char *data, void *arg, uint64_t *crc) newheader.down = NULL; newheader.next = NULL; off = where; - if ((off_t)off != where) + if ((off_t)off != where) { return (ISC_R_RANGE); + } newheader.node = (dns_rbtnode_t *)off; newheader.node_is_relative = 1; newheader.serial = 1; @@ -7355,7 +7664,7 @@ rbt_datawriter(FILE *rbtfile, unsigned char *data, void *arg, uint64_t *crc) sizeof(rdatasetheader_t)); hexdump("writing slab", p + sizeof(rdatasetheader_t), size - sizeof(rdatasetheader_t)); -#endif +#endif /* ifdef DEBUG */ isc_crc64_update(crc, (unsigned char *)&newheader, sizeof(rdatasetheader_t)); CHECK(isc_stdio_write(&newheader, sizeof(rdatasetheader_t), 1, @@ -7613,10 +7922,12 @@ settask(dns_db_t *db, isc_task_t *task) REQUIRE(VALID_RBTDB(rbtdb)); RBTDB_LOCK(&rbtdb->lock, isc_rwlocktype_write); - if (rbtdb->task != NULL) + if (rbtdb->task != NULL) { isc_task_detach(&rbtdb->task); - if (task != NULL) + } + if (task != NULL) { isc_task_attach(task, &rbtdb->task); + } RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_write); } @@ -7671,19 +7982,23 @@ getnsec3parameters(dns_db_t *db, dns_dbversion_t *version, dns_hash_t *hash, } if (rbtversion->havensec3) { - if (hash != NULL) + if (hash != NULL) { *hash = rbtversion->hash; + } if (salt != NULL && salt_length != NULL) { REQUIRE(*salt_length >= rbtversion->salt_length); memmove(salt, rbtversion->salt, rbtversion->salt_length); } - if (salt_length != NULL) + if (salt_length != NULL) { *salt_length = rbtversion->salt_length; - if (iterations != NULL) + } + if (iterations != NULL) { *iterations = rbtversion->iterations; - if (flags != NULL) + } + if (flags != NULL) { *flags = rbtversion->flags; + } result = ISC_R_SUCCESS; } RBTDB_UNLOCK(&rbtdb->lock, isc_rwlocktype_read); @@ -7794,25 +8109,28 @@ getsigningtime(dns_db_t *db, dns_rdataset_t *rdataset, dns_name_t *foundname) isc_rwlocktype_read); continue; } - if (header == NULL) + if (header == NULL) { header = this; - else if (resign_sooner(this, header)) { + } else if (resign_sooner(this, header)) { locknum = header->node->locknum; NODE_UNLOCK(&rbtdb->node_locks[locknum].lock, isc_rwlocktype_read); header = this; - } else + } else { NODE_UNLOCK(&rbtdb->node_locks[i].lock, isc_rwlocktype_read); + } } - if (header == NULL) + if (header == NULL) { goto unlock; + } bind_rdataset(rbtdb, header->node, header, 0, rdataset); - if (foundname != NULL) + if (foundname != NULL) { dns_rbt_fullnamefromnode(header->node, foundname); + } NODE_UNLOCK(&rbtdb->node_locks[header->node->locknum].lock, isc_rwlocktype_read); @@ -7847,8 +8165,9 @@ resigned(dns_db_t *db, dns_rdataset_t *rdataset, dns_dbversion_t *version) INSIST(header != NULL); header--; - if (header->heap_index == 0) + if (header->heap_index == 0) { return; + } RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_write); NODE_LOCK(&rbtdb->node_locks[node->locknum].lock, isc_rwlocktype_write); @@ -8060,8 +8379,9 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, /* * If argv[0] exists, it points to a memory context to use for heap */ - if (argc != 0) + if (argc != 0) { hmctx = (isc_mem_t *)argv[0]; + } memset(rbtdb, '\0', sizeof(*rbtdb)); dns_name_init(&rbtdb->common.origin, NULL); @@ -8072,20 +8392,23 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, } else if (type == dns_dbtype_stub) { rbtdb->common.methods = &zone_methods; rbtdb->common.attributes |= DNS_DBATTR_STUB; - } else + } else { rbtdb->common.methods = &zone_methods; + } rbtdb->common.rdclass = rdclass; rbtdb->common.mctx = NULL; ISC_LIST_INIT(rbtdb->common.update_listeners); result = RBTDB_INITLOCK(&rbtdb->lock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rbtdb; + } result = isc_rwlock_init(&rbtdb->tree_lock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_lock; + } /* * Initialize node_lock_count in a generic way to support future @@ -8094,10 +8417,11 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, * as commented with the definition of DEFAULT_CACHE_NODE_LOCK_COUNT. */ if (rbtdb->node_lock_count == 0) { - if (IS_CACHE(rbtdb)) + if (IS_CACHE(rbtdb)) { rbtdb->node_lock_count = DEFAULT_CACHE_NODE_LOCK_COUNT; - else + } else { rbtdb->node_lock_count = DEFAULT_NODE_LOCK_COUNT; + } } else if (rbtdb->node_lock_count < 2 && IS_CACHE(rbtdb)) { result = ISC_R_RANGE; goto cleanup_tree_lock; @@ -8112,29 +8436,34 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, rbtdb->rrsetstats = NULL; if (IS_CACHE(rbtdb)) { result = dns_rdatasetstats_create(mctx, &rbtdb->rrsetstats); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node_locks; + } rbtdb->rdatasets = isc_mem_get(mctx, rbtdb->node_lock_count * sizeof(rdatasetheaderlist_t)); - for (i = 0; i < (int)rbtdb->node_lock_count; i++) + for (i = 0; i < (int)rbtdb->node_lock_count; i++) { ISC_LIST_INIT(rbtdb->rdatasets[i]); - } else + } + } else { rbtdb->rdatasets = NULL; + } /* * Create the heaps. */ rbtdb->heaps = isc_mem_get(hmctx, rbtdb->node_lock_count * sizeof(isc_heap_t *)); - for (i = 0; i < (int)rbtdb->node_lock_count; i++) + for (i = 0; i < (int)rbtdb->node_lock_count; i++) { rbtdb->heaps[i] = NULL; + } sooner = IS_CACHE(rbtdb) ? ttl_sooner : resign_sooner; for (i = 0; i < (int)rbtdb->node_lock_count; i++) { result = isc_heap_create(hmctx, sooner, set_index, 0, &rbtdb->heaps[i]); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_heaps; + } } /* @@ -8142,8 +8471,9 @@ dns_rbtdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, */ rbtdb->deadnodes = isc_mem_get(mctx, rbtdb->node_lock_count * sizeof(rbtnodelist_t)); - for (i = 0; i < (int)rbtdb->node_lock_count; i++) + for (i = 0; i < (int)rbtdb->node_lock_count; i++) { ISC_LIST_INIT(rbtdb->deadnodes[i]); + } rbtdb->active = rbtdb->node_lock_count; @@ -8330,12 +8660,14 @@ cleanup_heaps: rbtdb->node_lock_count * sizeof(isc_heap_t *)); } - if (rbtdb->rdatasets != NULL) + if (rbtdb->rdatasets != NULL) { isc_mem_put(mctx, rbtdb->rdatasets, rbtdb->node_lock_count * sizeof(rdatasetheaderlist_t)); - if (rbtdb->rrsetstats != NULL) + } + if (rbtdb->rrsetstats != NULL) { dns_stats_detach(&rbtdb->rrsetstats); + } cleanup_node_locks: isc_mem_put(mctx, rbtdb->node_locks, @@ -8407,8 +8739,9 @@ rdataset_next(dns_rdataset_t *rdataset) unsigned char *raw; /* RDATASLAB */ count = rdataset->privateuint4; - if (count == 0) + if (count == 0) { return (ISC_R_NOMORE); + } count--; rdataset->privateuint4 = count; @@ -8451,15 +8784,16 @@ rdataset_current(dns_rdataset_t *rdataset, dns_rdata_t *rdata) raw = rdataset->private3; raw += offset; } -#endif +#endif /* if DNS_RDATASET_FIXED */ length = raw[0] * 256 + raw[1]; raw += DNS_RDATASET_ORDER + DNS_RDATASET_LENGTH; if (rdataset->type == dns_rdatatype_rrsig) { - if (*raw & DNS_RDATASLAB_OFFLINE) + if (*raw & DNS_RDATASLAB_OFFLINE) { flags |= DNS_RDATA_OFFLINE; + } length--; raw++; } @@ -8647,9 +8981,10 @@ rdatasetiter_destroy(dns_rdatasetiter_t **iteratorp) rbtiterator = (rbtdb_rdatasetiter_t *)(*iteratorp); - if (rbtiterator->common.version != NULL) + if (rbtiterator->common.version != NULL) { closeversion(rbtiterator->common.db, &rbtiterator->common.version, false); + } detachnode(rbtiterator->common.db, &rbtiterator->common.node); isc_mem_put(rbtiterator->common.db->mctx, rbtiterator, sizeof(*rbtiterator)); @@ -8696,14 +9031,17 @@ rdatasetiter_first(dns_rdatasetiter_t *iterator) if (NONEXISTENT(header) || (now != 0 && now > header->rdh_ttl + - rbtdb->serve_stale_ttl)) + rbtdb->serve_stale_ttl)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); - if (header != NULL) + if (header != NULL) { break; + } } NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, @@ -8711,8 +9049,9 @@ rdatasetiter_first(dns_rdatasetiter_t *iterator) rbtiterator->current = header; - if (header == NULL) + if (header == NULL) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } @@ -8731,8 +9070,9 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator) dns_rdatatype_t rdtype, covers; header = rbtiterator->current; - if (header == NULL) + if (header == NULL) { return (ISC_R_NOMORE); + } if (IS_CACHE(rbtdb)) { serial = 1; @@ -8750,8 +9090,9 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator) if (NEGATIVE(header)) { covers = RBTDB_RDATATYPE_EXT(header->type); negtype = RBTDB_RDATATYPE_VALUE(covers, 0); - } else + } else { negtype = RBTDB_RDATATYPE_VALUE(0, rdtype); + } for (header = header->next; header != NULL; header = top_next) { top_next = header->next; /* @@ -8772,14 +9113,18 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator) * rdatasets to work. */ if (NONEXISTENT(header) || - (now != 0 && now > header->rdh_ttl)) + (now != 0 && + now > header->rdh_ttl)) { header = NULL; + } break; - } else + } else { header = header->down; + } } while (header != NULL); - if (header != NULL) + if (header != NULL) { break; + } } } @@ -8788,8 +9133,9 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator) rbtiterator->current = header; - if (header == NULL) + if (header == NULL) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } @@ -8825,8 +9171,9 @@ reference_iter_node(rbtdb_dbiterator_t *rbtdbiter) dns_rbtdb_t * rbtdb = (dns_rbtdb_t *)rbtdbiter->common.db; dns_rbtnode_t *node = rbtdbiter->node; - if (node == NULL) + if (node == NULL) { return; + } INSIST(rbtdbiter->tree_locked != isc_rwlocktype_none); reactivate_node(rbtdb, node, rbtdbiter->tree_locked); @@ -8839,8 +9186,9 @@ dereference_iter_node(rbtdb_dbiterator_t *rbtdbiter) dns_rbtnode_t *node = rbtdbiter->node; nodelock_t * lock; - if (node == NULL) + if (node == NULL) { return; + } lock = &rbtdb->node_locks[node->locknum].lock; NODE_LOCK(lock, isc_rwlocktype_read); @@ -8896,7 +9244,6 @@ flush_deletions(rbtdb_dbiterator_t *rbtdbiter) if (was_read_locked) { RWLOCK(&rbtdb->tree_lock, isc_rwlocktype_read); rbtdbiter->tree_locked = isc_rwlocktype_read; - } else { rbtdbiter->tree_locked = isc_rwlocktype_none; } @@ -8927,8 +9274,9 @@ dbiterator_destroy(dns_dbiterator_t **iteratorp) if (rbtdbiter->tree_locked == isc_rwlocktype_read) { RWUNLOCK(&rbtdb->tree_lock, isc_rwlocktype_read); rbtdbiter->tree_locked = isc_rwlocktype_none; - } else + } else { INSIST(rbtdbiter->tree_locked == isc_rwlocktype_none); + } dereference_iter_node(rbtdbiter); @@ -8956,11 +9304,13 @@ dbiterator_first(dns_dbiterator_t *iterator) if (rbtdbiter->result != ISC_R_SUCCESS && rbtdbiter->result != ISC_R_NOTFOUND && rbtdbiter->result != DNS_R_PARTIALMATCH && - rbtdbiter->result != ISC_R_NOMORE) + rbtdbiter->result != ISC_R_NOMORE) { return (rbtdbiter->result); + } - if (rbtdbiter->paused) + if (rbtdbiter->paused) { resume_iteration(rbtdbiter); + } dereference_iter_node(rbtdbiter); @@ -8997,8 +9347,9 @@ dbiterator_first(dns_dbiterator_t *iterator) rbtdbiter->result = result; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { ENSURE(!rbtdbiter->paused); + } return (result); } @@ -9014,11 +9365,13 @@ dbiterator_last(dns_dbiterator_t *iterator) if (rbtdbiter->result != ISC_R_SUCCESS && rbtdbiter->result != ISC_R_NOTFOUND && rbtdbiter->result != DNS_R_PARTIALMATCH && - rbtdbiter->result != ISC_R_NOMORE) + rbtdbiter->result != ISC_R_NOMORE) { return (rbtdbiter->result); + } - if (rbtdbiter->paused) + if (rbtdbiter->paused) { resume_iteration(rbtdbiter); + } dereference_iter_node(rbtdbiter); @@ -9066,11 +9419,13 @@ dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name) if (rbtdbiter->result != ISC_R_SUCCESS && rbtdbiter->result != ISC_R_NOTFOUND && rbtdbiter->result != DNS_R_PARTIALMATCH && - rbtdbiter->result != ISC_R_NOMORE) + rbtdbiter->result != ISC_R_NOMORE) { return (rbtdbiter->result); + } - if (rbtdbiter->paused) + if (rbtdbiter->paused) { resume_iteration(rbtdbiter); + } dereference_iter_node(rbtdbiter); @@ -9121,8 +9476,9 @@ dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name) result = tresult; rbtdbiter->node = NULL; } - } else + } else { rbtdbiter->node = NULL; + } rbtdbiter->result = (result == DNS_R_PARTIALMATCH) ? ISC_R_SUCCESS : result; @@ -9140,11 +9496,13 @@ dbiterator_prev(dns_dbiterator_t *iterator) REQUIRE(rbtdbiter->node != NULL); - if (rbtdbiter->result != ISC_R_SUCCESS) + if (rbtdbiter->result != ISC_R_SUCCESS) { return (rbtdbiter->result); + } - if (rbtdbiter->paused) + if (rbtdbiter->paused) { resume_iteration(rbtdbiter); + } name = dns_fixedname_name(&rbtdbiter->name); origin = dns_fixedname_name(&rbtdbiter->origin); @@ -9156,8 +9514,9 @@ dbiterator_prev(dns_dbiterator_t *iterator) dns_rbtnodechain_reset(rbtdbiter->current); result = dns_rbtnodechain_last(rbtdbiter->current, rbtdb->tree, name, origin); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_NOMORE; + } } dereference_iter_node(rbtdbiter); @@ -9168,8 +9527,9 @@ dbiterator_prev(dns_dbiterator_t *iterator) NULL, &rbtdbiter->node); } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { reference_iter_node(rbtdbiter); + } rbtdbiter->result = result; @@ -9186,11 +9546,13 @@ dbiterator_next(dns_dbiterator_t *iterator) REQUIRE(rbtdbiter->node != NULL); - if (rbtdbiter->result != ISC_R_SUCCESS) + if (rbtdbiter->result != ISC_R_SUCCESS) { return (rbtdbiter->result); + } - if (rbtdbiter->paused) + if (rbtdbiter->paused) { resume_iteration(rbtdbiter); + } name = dns_fixedname_name(&rbtdbiter->name); origin = dns_fixedname_name(&rbtdbiter->origin); @@ -9201,8 +9563,9 @@ dbiterator_next(dns_dbiterator_t *iterator) dns_rbtnodechain_reset(rbtdbiter->current); result = dns_rbtnodechain_first(rbtdbiter->current, rbtdb->nsec3, name, origin); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_NOMORE; + } } dereference_iter_node(rbtdbiter); @@ -9212,8 +9575,9 @@ dbiterator_next(dns_dbiterator_t *iterator) result = dns_rbtnodechain_current(rbtdbiter->current, NULL, NULL, &rbtdbiter->node); } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { reference_iter_node(rbtdbiter); + } rbtdbiter->result = result; @@ -9234,19 +9598,24 @@ dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep, REQUIRE(rbtdbiter->result == ISC_R_SUCCESS); REQUIRE(rbtdbiter->node != NULL); - if (rbtdbiter->paused) + if (rbtdbiter->paused) { resume_iteration(rbtdbiter); + } if (name != NULL) { - if (rbtdbiter->common.relative_names) + if (rbtdbiter->common.relative_names) { origin = NULL; + } result = dns_name_concatenate(nodename, origin, name, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (rbtdbiter->common.relative_names && rbtdbiter->new_origin) + } + if (rbtdbiter->common.relative_names && rbtdbiter->new_origin) { result = DNS_R_NEWORIGIN; - } else + } + } else { result = ISC_R_SUCCESS; + } new_reference(rbtdb, node); @@ -9260,8 +9629,9 @@ dbiterator_current(dns_dbiterator_t *iterator, dns_dbnode_t **nodep, * to expire the current node. The current node can't * fully deleted while the iteration cursor is still on it. */ - if (rbtdbiter->delcnt == DELETION_BATCH_MAX) + if (rbtdbiter->delcnt == DELETION_BATCH_MAX) { flush_deletions(rbtdbiter); + } expire_result = expirenode(iterator->db, *nodep, 0); @@ -9286,11 +9656,13 @@ dbiterator_pause(dns_dbiterator_t *iterator) if (rbtdbiter->result != ISC_R_SUCCESS && rbtdbiter->result != ISC_R_NOTFOUND && rbtdbiter->result != DNS_R_PARTIALMATCH && - rbtdbiter->result != ISC_R_NOMORE) + rbtdbiter->result != ISC_R_NOMORE) { return (rbtdbiter->result); + } - if (rbtdbiter->paused) + if (rbtdbiter->paused) { return (ISC_R_SUCCESS); + } rbtdbiter->paused = true; @@ -9311,8 +9683,9 @@ dbiterator_origin(dns_dbiterator_t *iterator, dns_name_t *name) rbtdb_dbiterator_t *rbtdbiter = (rbtdb_dbiterator_t *)iterator; dns_name_t * origin = dns_fixedname_name(&rbtdbiter->origin); - if (rbtdbiter->result != ISC_R_SUCCESS) + if (rbtdbiter->result != ISC_R_SUCCESS) { return (rbtdbiter->result); + } dns_name_copynf(origin, name); return (ISC_R_SUCCESS); @@ -9339,8 +9712,9 @@ setownercase(rdatasetheader_t *header, const dns_name_t *name) } } header->attributes |= RDATASET_ATTR_CASESET; - if (ISC_LIKELY(fully_lower)) + if (ISC_LIKELY(fully_lower)) { header->attributes |= RDATASET_ATTR_CASEFULLYLOWER; + } } static void @@ -9440,16 +9814,16 @@ rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) * Set the case bit if it does not match the recorded bit. */ if (name->ndata[i] >= 0x61 && name->ndata[i] <= 0x7a && - (header->upper[i/8] & (1 << (i%8))) != 0) + (header->upper[i / 8] & (1 << (i % 8))) != 0) { name->ndata[i] &= ~0x20; /* clear the lower case bit */ } else if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a && - (header->upper[i/8] & (1 << (i%8))) == 0) + (header->upper[i / 8] & (1 << (i % 8))) == 0) { name->ndata[i] |= 0x20; /* set the lower case bit */ } } -#else +#else /* if 0 */ if (ISC_LIKELY(CASEFULLYLOWER(header))) { unsigned char *bp, *be; @@ -9507,7 +9881,7 @@ rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) bits >>= 1; } -#endif +#endif /* if 0 */ unlock: NODE_UNLOCK(&rbtdb->node_locks[rbtnode->locknum].lock, @@ -9534,22 +9908,27 @@ free_gluelist(rbtdb_glue_t *glue_list, dns_rbtdb_t *rbtdb) { rbtdb_glue_t *cur, *cur_next; - if (glue_list == (void *)-1) + if (glue_list == (void *)-1) { return; + } cur = glue_list; while (cur != NULL) { cur_next = cur->next; - if (dns_rdataset_isassociated(&cur->rdataset_a)) + if (dns_rdataset_isassociated(&cur->rdataset_a)) { dns_rdataset_disassociate(&cur->rdataset_a); - if (dns_rdataset_isassociated(&cur->sigrdataset_a)) + } + if (dns_rdataset_isassociated(&cur->sigrdataset_a)) { dns_rdataset_disassociate(&cur->sigrdataset_a); + } - if (dns_rdataset_isassociated(&cur->rdataset_aaaa)) + if (dns_rdataset_isassociated(&cur->rdataset_aaaa)) { dns_rdataset_disassociate(&cur->rdataset_aaaa); - if (dns_rdataset_isassociated(&cur->sigrdataset_aaaa)) + } + if (dns_rdataset_isassociated(&cur->sigrdataset_aaaa)) { dns_rdataset_disassociate(&cur->sigrdataset_aaaa); + } dns_rdataset_invalidate(&cur->rdataset_a); dns_rdataset_invalidate(&cur->sigrdataset_a); @@ -9603,8 +9982,9 @@ rehash_gluetable(rbtdb_version_t *version) uint32_t hash; if (ISC_LIKELY(version->glue_table_nodecount < - (version->glue_table_size * 3U))) + (version->glue_table_size * 3U))) { return (false); + } oldsize = version->glue_table_size; oldtable = version->glue_table; @@ -9624,8 +10004,9 @@ rehash_gluetable(rbtdb_version_t *version) return (false); } - for (i = 0; i < version->glue_table_size; i++) + for (i = 0; i < version->glue_table_size; i++) { version->glue_table[i] = NULL; + } for (i = 0; i < oldsize; i++) { for (gluenode = oldtable[i]; gluenode != NULL; @@ -9740,20 +10121,26 @@ glue_nsdname_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype) result = ISC_R_SUCCESS; - if (dns_rdataset_isassociated(&rdataset_a)) + if (dns_rdataset_isassociated(&rdataset_a)) { rdataset_disassociate(&rdataset_a); - if (dns_rdataset_isassociated(&sigrdataset_a)) + } + if (dns_rdataset_isassociated(&sigrdataset_a)) { rdataset_disassociate(&sigrdataset_a); + } - if (dns_rdataset_isassociated(&rdataset_aaaa)) + if (dns_rdataset_isassociated(&rdataset_aaaa)) { rdataset_disassociate(&rdataset_aaaa); - if (dns_rdataset_isassociated(&sigrdataset_aaaa)) + } + if (dns_rdataset_isassociated(&sigrdataset_aaaa)) { rdataset_disassociate(&sigrdataset_aaaa); + } - if (node_a != NULL) + if (node_a != NULL) { detachnode((dns_db_t *)ctx->rbtdb, (dns_dbnode_t *)&node_a); - if (node_aaaa != NULL) + } + if (node_aaaa != NULL) { detachnode((dns_db_t *)ctx->rbtdb, (dns_dbnode_t *)&node_aaaa); + } return (result); } @@ -9802,7 +10189,6 @@ restart: for (cur = rbtversion->glue_table[idx]; cur != NULL; cur = cur->next) { if (cur->node == node) { break; - } } @@ -9902,12 +10288,14 @@ restart: dns_message_puttemprdataset( msg, &rdataset_a); } - if (sigrdataset_a != NULL) + if (sigrdataset_a != NULL) { dns_message_puttemprdataset( msg, &sigrdataset_a); - if (rdataset_aaaa != NULL) + } + if (rdataset_aaaa != NULL) { dns_message_puttemprdataset( msg, &rdataset_aaaa); + } goto no_glue; } } @@ -10034,8 +10422,9 @@ need_headerupdate(rdatasetheader_t *header, isc_stdtime_t now) { if ((header->attributes & (RDATASET_ATTR_NONEXISTENT | RDATASET_ATTR_ANCIENT | - RDATASET_ATTR_ZEROTTL)) != 0) + RDATASET_ATTR_ZEROTTL)) != 0) { return (false); + } #if DNS_RBTDB_LIMITLRUUPDATE if (header->type == dns_rdatatype_ns || @@ -10051,11 +10440,11 @@ need_headerupdate(rdatasetheader_t *header, isc_stdtime_t now) /* Other records are updated if 5 minutes have passed. */ return (header->last_used + 300 <= now); -#else +#else /* if DNS_RBTDB_LIMITLRUUPDATE */ UNUSED(now); return (true); -#endif +#endif /* if DNS_RBTDB_LIMITLRUUPDATE */ } /*% @@ -10154,8 +10543,9 @@ expire_header(dns_rbtdb_t *rbtdb, rdatasetheader_t *header, bool tree_locked, : isc_rwlocktype_none, false); - if (rbtdb->cachestats == NULL) + if (rbtdb->cachestats == NULL) { return; + } switch (reason) { case expire_ttl: diff --git a/lib/dns/rbtdb.h b/lib/dns/rbtdb.h index c73c80d605..db9d682b3d 100644 --- a/lib/dns/rbtdb.h +++ b/lib/dns/rbtdb.h @@ -17,8 +17,8 @@ #include /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief diff --git a/lib/dns/rcode.c b/lib/dns/rcode.c index 2f779f4e83..dce734cbab 100644 --- a/lib/dns/rcode.c +++ b/lib/dns/rcode.c @@ -41,7 +41,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) #define NUMBERSIZE sizeof("037777777777") /* 2^32-1 octal + NUL */ @@ -209,8 +209,9 @@ str_totext(const char *source, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(source); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, source, l); isc_buffer_add(target, l); @@ -265,8 +266,9 @@ dns_mnemonic_fromtext(unsigned int *valuep, isc_textregion_t *source, int i; result = maybe_numeric(valuep, source, max, false); - if (result != ISC_R_BADNUMBER) + if (result != ISC_R_BADNUMBER) { return (result); + } for (i = 0; table[i].name != NULL; i++) { unsigned int n; @@ -404,15 +406,16 @@ dns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source) unsigned int value = 0; #ifdef notyet unsigned int mask = 0; -#endif +#endif /* ifdef notyet */ result = maybe_numeric(&value, source, 0xffff, true); if (result == ISC_R_SUCCESS) { *flagsp = value; return (ISC_R_SUCCESS); } - if (result != ISC_R_BADNUMBER) + if (result != ISC_R_BADNUMBER) { return (result); + } text = source->base; end = source->base + source->length; @@ -421,25 +424,30 @@ dns_keyflags_fromtext(dns_keyflags_t *flagsp, isc_textregion_t *source) struct keyflag *p; unsigned int len; char * delim = memchr(text, '|', end - text); - if (delim != NULL) + if (delim != NULL) { len = (unsigned int)(delim - text); - else + } else { len = (unsigned int)(end - text); - for (p = keyflags; p->name != NULL; p++) { - if (strncasecmp(p->name, text, len) == 0) - break; } - if (p->name == NULL) + for (p = keyflags; p->name != NULL; p++) { + if (strncasecmp(p->name, text, len) == 0) { + break; + } + } + if (p->name == NULL) { return (DNS_R_UNKNOWNFLAG); + } value |= p->value; #ifdef notyet - if ((mask & p->mask) != 0) + if ((mask & p->mask) != 0) { warn("overlapping key flags"); + } mask |= p->mask; -#endif +#endif /* ifdef notyet */ text += len; - if (delim != NULL) + if (delim != NULL) { text++; /* Skip "|" */ + } } *flagsp = value; return (ISC_R_SUCCESS); @@ -580,8 +588,9 @@ dns_rdataclass_format(dns_rdataclass_t rdclass, char *array, unsigned int size) isc_result_t result; isc_buffer_t buf; - if (size == 0U) + if (size == 0U) { return; + } isc_buffer_init(&buf, array, size); result = dns_rdataclass_totext(rdclass, &buf); @@ -589,11 +598,13 @@ dns_rdataclass_format(dns_rdataclass_t rdclass, char *array, unsigned int size) * Null terminate. */ if (result == ISC_R_SUCCESS) { - if (isc_buffer_availablelength(&buf) >= 1) + if (isc_buffer_availablelength(&buf) >= 1) { isc_buffer_putuint8(&buf, 0); - else + } else { result = ISC_R_NOSPACE; + } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { strlcpy(array, "", size); + } } diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 85729e2857..3b8f316c14 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -47,7 +47,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) #define RETTOK(x) \ @@ -318,20 +318,24 @@ locator_pton(const char *src, unsigned char *dst) const char *pch; pch = strchr((xdigits = xdigits_l), ch); - if (pch == NULL) + if (pch == NULL) { pch = strchr((xdigits = xdigits_u), ch); + } if (pch != NULL) { val <<= 4; val |= (pch - xdigits); - if (++seen_xdigits > 4) + if (++seen_xdigits > 4) { return (0); + } continue; } if (ch == ':') { - if (!seen_xdigits) + if (!seen_xdigits) { return (0); - if (tp + NS_INT16SZ > endp) + } + if (tp + NS_INT16SZ > endp) { return (0); + } *tp++ = (unsigned char)(val >> 8) & 0xff; *tp++ = (unsigned char)val & 0xff; seen_xdigits = 0; @@ -341,13 +345,15 @@ locator_pton(const char *src, unsigned char *dst) return (0); } if (seen_xdigits) { - if (tp + NS_INT16SZ > endp) + if (tp + NS_INT16SZ > endp) { return (0); + } *tp++ = (unsigned char)(val >> 8) & 0xff; *tp++ = (unsigned char)val & 0xff; } - if (tp != endp) + if (tp != endp) { return (0); + } memmove(dst, tmp, NS_LOCATORSZ); return (1); } @@ -368,8 +374,9 @@ mem_maybedup(isc_mem_t *mctx, void *source, size_t length) { void *copy; - if (mctx == NULL) + if (mctx == NULL) { return (source); + } copy = isc_mem_allocate(mctx, length); memmove(copy, source, length); @@ -394,8 +401,9 @@ typemap_fromtext(isc_lex_t *lexer, isc_buffer_t *target, bool allow_empty) do { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, true)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { break; + } RETTOK(dns_rdatatype_fromtext(&covered, &token.value.as_textregion)); if (covered > max_used) { @@ -410,28 +418,33 @@ typemap_fromtext(isc_lex_t *lexer, isc_buffer_t *target, bool allow_empty) first = false; } while (1); isc_lex_ungettoken(lexer, &token); - if (!allow_empty && first) + if (!allow_empty && first) { return (DNS_R_FORMERR); + } for (window = 0; window < 256; window++) { - if (max_used < window * 256) + if (max_used < window * 256) { break; + } max_octet = max_used - (window * 256); - if (max_octet >= 256) + if (max_octet >= 256) { max_octet = 31; - else + } else { max_octet /= 8; + } /* * Find if we have a type in this window. */ for (octet = max_octet; octet >= 0; octet--) { - if (bm[window * 32 + octet] != 0) + if (bm[window * 32 + octet] != 0) { break; + } } - if (octet < 0) + if (octet < 0) { continue; + } RETERR(uint8_tobuffer(window, target)); RETERR(uint8_tobuffer(octet + 1, target)); RETERR(mem_tobuffer(target, &bm[window * 32], octet + 1)); @@ -461,14 +474,17 @@ typemap_totext(isc_region_t *sr, dns_rdata_textctx_t *tctx, INSIST(i + len <= sr->length); for (j = 0; j < len; j++) { dns_rdatatype_t t; - if (sr->base[i + j] == 0) + if (sr->base[i + j] == 0) { continue; + } for (k = 0; k < 8; k++) { - if ((sr->base[i + j] & (0x80 >> k)) == 0) + if ((sr->base[i + j] & (0x80 >> k)) == 0) { continue; + } t = window * 256 + j * 8 + k; - if (!first) + if (!first) { RETERR(str_totext(" ", target)); + } first = false; if (dns_rdatatype_isknown(t)) { RETERR(dns_rdatatype_totext(t, target)); @@ -495,38 +511,45 @@ typemap_test(isc_region_t *sr, bool allow_empty) /* * Check for overflow. */ - if (i + 2 > sr->length) + if (i + 2 > sr->length) { RETERR(DNS_R_FORMERR); + } window = sr->base[i]; len = sr->base[i + 1]; i += 2; /* * Check that bitmap windows are in the correct order. */ - if (!first && window <= lastwindow) + if (!first && window <= lastwindow) { RETERR(DNS_R_FORMERR); + } /* * Check for legal lengths. */ - if (len < 1 || len > 32) + if (len < 1 || len > 32) { RETERR(DNS_R_FORMERR); + } /* * Check for overflow. */ - if (i + len > sr->length) + if (i + len > sr->length) { RETERR(DNS_R_FORMERR); + } /* * The last octet of the bitmap must be non zero. */ - if (sr->base[i + len - 1] == 0) + if (sr->base[i + len - 1] == 0) { RETERR(DNS_R_FORMERR); + } lastwindow = window; first = false; } - if (i != sr->length) + if (i != sr->length) { return (DNS_R_EXTRADATA); - if (!allow_empty && first) + } + if (!allow_empty && first) { RETERR(DNS_R_FORMERR); + } return (ISC_R_SUCCESS); } @@ -610,11 +633,13 @@ dns_rdata_compare(const dns_rdata_t *rdata1, const dns_rdata_t *rdata2) REQUIRE(DNS_RDATA_VALIDFLAGS(rdata1)); REQUIRE(DNS_RDATA_VALIDFLAGS(rdata2)); - if (rdata1->rdclass != rdata2->rdclass) + if (rdata1->rdclass != rdata2->rdclass) { return (rdata1->rdclass < rdata2->rdclass ? -1 : 1); + } - if (rdata1->type != rdata2->type) + if (rdata1->type != rdata2->type) { return (rdata1->type < rdata2->type ? -1 : 1); + } COMPARESWITCH @@ -642,11 +667,13 @@ dns_rdata_casecompare(const dns_rdata_t *rdata1, const dns_rdata_t *rdata2) REQUIRE(DNS_RDATA_VALIDFLAGS(rdata1)); REQUIRE(DNS_RDATA_VALIDFLAGS(rdata2)); - if (rdata1->rdclass != rdata2->rdclass) + if (rdata1->rdclass != rdata2->rdclass) { return (rdata1->rdclass < rdata2->rdclass ? -1 : 1); + } - if (rdata1->type != rdata2->type) + if (rdata1->type != rdata2->type) { return (rdata1->type < rdata2->type ? -1 : 1); + } CASECOMPARESWITCH @@ -715,8 +742,9 @@ dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass, REQUIRE(source != NULL); REQUIRE(target != NULL); - if (type == 0) + if (type == 0) { return (DNS_R_FORMERR); + } ss = *source; st = *target; @@ -727,9 +755,9 @@ dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass, FROMWIRESWITCH if (use_default) { - if (activelength > isc_buffer_availablelength(target)) + if (activelength > isc_buffer_availablelength(target)) { result = ISC_R_NOSPACE; - else { + } else { isc_buffer_putmem(target, isc_buffer_current(source), activelength); isc_buffer_forward(source, activelength); @@ -742,14 +770,16 @@ dns_rdata_fromwire(dns_rdata_t *rdata, dns_rdataclass_t rdclass, * as we cannot transmit it. */ length = isc_buffer_usedlength(target) - isc_buffer_usedlength(&st); - if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH) + if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH) { result = DNS_R_FORMERR; + } /* * We should have consumed all of our buffer. */ - if (result == ISC_R_SUCCESS && !buffer_empty(source)) + if (result == ISC_R_SUCCESS && !buffer_empty(source)) { result = DNS_R_EXTRADATA; + } if (rdata != NULL && result == ISC_R_SUCCESS) { region.base = isc_buffer_used(&st); @@ -789,8 +819,9 @@ dns_rdata_towire(dns_rdata_t *rdata, dns_compress_t *cctx, isc_buffer_t *target) if (use_default) { isc_buffer_availableregion(target, &tr); - if (tr.length < rdata->length) + if (tr.length < rdata->length) { return (ISC_R_NOSPACE); + } memmove(tr.base, rdata->data, rdata->length); isc_buffer_add(target, rdata->length); return (ISC_R_SUCCESS); @@ -831,13 +862,15 @@ unknown_fromtext(dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_t *buf = NULL; isc_token_t token; - if (type == 0 || dns_rdatatype_ismeta(type)) + if (type == 0 || dns_rdatatype_ismeta(type)) { return (DNS_R_METATYPE); + } RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 65535U) + if (token.value.as_ulong > 65535U) { return (ISC_R_RANGE); + } isc_buffer_allocate(mctx, &buf, token.value.as_ulong); if (token.value.as_ulong != 0U) { @@ -859,8 +892,9 @@ unknown_fromtext(dns_rdataclass_t rdclass, dns_rdatatype_t type, isc_buffer_usedregion(buf, &r); result = isc_buffer_copyregion(target, &r); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } isc_buffer_free(&buf); return (ISC_R_SUCCESS); @@ -902,10 +936,11 @@ dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass, st = *target; - if (callbacks != NULL) + if (callbacks != NULL) { callback = callbacks->error; - else + } else { callback = default_fromtext_callback; + } result = isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, true); @@ -927,42 +962,49 @@ dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass, if (type == dns_rdatatype_txt) { result = isc_lex_getmastertoken( lexer, &token, isc_tokentype_number, false); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_lex_ungettoken(lexer, &token); + } } if (result == ISC_R_SUCCESS) { unknown = true; result = unknown_fromtext(rdclass, type, lexer, mctx, target); - } else + } else { options |= DNS_RDATA_UNKNOWNESCAPE; - } else + } + } else { isc_lex_ungettoken(lexer, &token); + } - if (!unknown) + if (!unknown) { FROMTEXTSWITCH - /* - * Consume to end of line / file. - * If not at end of line initially set error code. - * Call callback via fromtext_error once if there was an error. - */ + /* + * Consume to end of line / file. + * If not at end of line initially set error code. + * Call callback via fromtext_error once if there was an error. + */ + } do { name = isc_lex_getsourcename(lexer); line = isc_lex_getsourceline(lexer); tresult = isc_lex_gettoken(lexer, lexoptions, &token); if (tresult != ISC_R_SUCCESS) { - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = tresult; - if (callback != NULL) + } + if (callback != NULL) { fromtext_error(callback, callbacks, name, line, NULL, result); + } break; } else if (token.type != isc_tokentype_eol && token.type != isc_tokentype_eof) { - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_EXTRATOKEN; + } if (callback != NULL) { fromtext_error(callback, callbacks, name, line, &token, result); @@ -973,15 +1015,17 @@ dns_rdata_fromtext(dns_rdata_t *rdata, dns_rdataclass_t rdclass, result); break; } else { - if (token.type == isc_tokentype_eof) + if (token.type == isc_tokentype_eof) { fromtext_warneof(lexer, callbacks); + } break; } } while (1); length = isc_buffer_usedlength(target) - isc_buffer_usedlength(&st); - if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH) + if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH) { result = ISC_R_NOSPACE; + } if (rdata != NULL && result == ISC_R_SUCCESS) { region.base = isc_buffer_used(&st); @@ -1004,33 +1048,39 @@ unknown_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, strlcpy(buf, "\\# ", sizeof(buf)); result = str_totext(buf, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdata_toregion(rdata, &sr); INSIST(sr.length < 65536); snprintf(buf, sizeof(buf), "%u", sr.length); result = str_totext(buf, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (sr.length != 0U) { - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { result = str_totext(" ( ", target); - else + } else { result = str_totext(" ", target); + } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ result = isc_hex_totext(&sr, 0, "", target); - else + } else { result = isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target); + } if (result == ISC_R_SUCCESS && - (tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + (tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { result = str_totext(" )", target); + } } return (result); } @@ -1055,8 +1105,9 @@ rdata_totext(dns_rdata_t *rdata, dns_rdata_textctx_t *tctx, return (ISC_R_SUCCESS); } - if ((tctx->flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0) + if ((tctx->flags & DNS_STYLEFLAG_UNKNOWNFORMAT) != 0) { return (unknown_totext(rdata, tctx, target)); + } cur = isc_buffer_usedlength(target); @@ -1106,16 +1157,18 @@ dns_rdata_tofmttext(dns_rdata_t *rdata, const dns_name_t *origin, */ tctx.origin = origin; tctx.flags = flags; - if (split_width == 0xffffffff) + if (split_width == 0xffffffff) { tctx.width = width; - else + } else { tctx.width = split_width; + } - if ((flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((flags & DNS_STYLEFLAG_MULTILINE) != 0) { tctx.linebreak = linebreak; - else { - if (split_width == 0xffffffff) + } else { + if (split_width == 0xffffffff) { tctx.width = 60; /* Used for hex word length only. */ + } tctx.linebreak = " "; } return (rdata_totext(rdata, &tctx, target)); @@ -1141,20 +1194,23 @@ dns_rdata_fromstruct(dns_rdata_t *rdata, dns_rdataclass_t rdclass, FROMSTRUCTSWITCH - if (use_default) + if (use_default) { (void)NULL; + } length = isc_buffer_usedlength(target) - isc_buffer_usedlength(&st); - if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH) + if (result == ISC_R_SUCCESS && length > DNS_RDATA_MAXLENGTH) { result = ISC_R_NOSPACE; + } if (rdata != NULL && result == ISC_R_SUCCESS) { region.base = isc_buffer_used(&st); region.length = length; dns_rdata_fromregion(rdata, rdclass, type, ®ion); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { *target = st; + } return (result); } @@ -1169,8 +1225,9 @@ dns_rdata_tostruct(const dns_rdata_t *rdata, void *target, isc_mem_t *mctx) TOSTRUCTSWITCH - if (use_default) + if (use_default) { (void)NULL; + } return (result); } @@ -1203,8 +1260,9 @@ dns_rdata_additionaldata(dns_rdata_t *rdata, dns_additionaldatafunc_t add, ADDITIONALDATASWITCH /* No additional processing for unknown types */ - if (use_default) + if (use_default) { result = ISC_R_SUCCESS; + } return (result); } @@ -1258,8 +1316,9 @@ unsigned int dns_rdatatype_attributes(dns_rdatatype_t type) { RDATATYPE_ATTRIBUTE_SW - if (type >= (dns_rdatatype_t)128 && type < (dns_rdatatype_t)255) + if (type >= (dns_rdatatype_t)128 && type < (dns_rdatatype_t)255) { return (DNS_RDATATYPEATTR_UNKNOWN | DNS_RDATATYPEATTR_META); + } return (DNS_RDATATYPEATTR_UNKNOWN); } @@ -1272,8 +1331,9 @@ dns_rdatatype_fromtext(dns_rdatatype_t *typep, isc_textregion_t *source) n = source->length; - if (n == 0) + if (n == 0) { return (DNS_R_UNKNOWN); + } a = tolower((unsigned char)source->base[0]); b = tolower((unsigned char)source->base[n - 1]); @@ -1332,8 +1392,9 @@ dns_rdatatype_format(dns_rdatatype_t rdtype, char *array, unsigned int size) isc_result_t result; isc_buffer_t buf; - if (size == 0U) + if (size == 0U) { return; + } isc_buffer_init(&buf, array, size); result = dns_rdatatype_totext(rdtype, &buf); @@ -1341,13 +1402,15 @@ dns_rdatatype_format(dns_rdatatype_t rdtype, char *array, unsigned int size) * Null terminate. */ if (result == ISC_R_SUCCESS) { - if (isc_buffer_availablelength(&buf) >= 1) + if (isc_buffer_availablelength(&buf) >= 1) { isc_buffer_putuint8(&buf, 0); - else + } else { result = ISC_R_NOSPACE; + } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { strlcpy(array, "", size); + } } /* @@ -1377,12 +1440,14 @@ txt_totext(isc_region_t *source, bool quote, isc_buffer_t *target) n = *sp++; REQUIRE(n + 1 <= source->length); - if (n == 0U) + if (n == 0U) { REQUIRE(quote == true); + } if (quote) { - if (tl < 1) + if (tl < 1) { return (ISC_R_NOSPACE); + } *tp++ = '"'; tl--; } @@ -1391,8 +1456,9 @@ txt_totext(isc_region_t *source, bool quote, isc_buffer_t *target) * \DDD space (0x20) if not quoting. */ if (*sp < (quote ? 0x20 : 0x21) || *sp >= 0x7f) { - if (tl < 4) + if (tl < 4) { return (ISC_R_NOSPACE); + } *tp++ = 0x5c; *tp++ = 0x30 + ((*sp / 100) % 10); *tp++ = 0x30 + ((*sp / 10) % 10); @@ -1408,19 +1474,22 @@ txt_totext(isc_region_t *source, bool quote, isc_buffer_t *target) */ if (*sp == 0x22 || *sp == 0x5c || (!quote && (*sp == 0x40 || *sp == 0x3b))) { - if (tl < 2) + if (tl < 2) { return (ISC_R_NOSPACE); + } *tp++ = '\\'; tl--; } - if (tl < 1) + if (tl < 1) { return (ISC_R_NOSPACE); + } *tp++ = *sp++; tl--; } if (quote) { - if (tl < 1) + if (tl < 1) { return (ISC_R_NOSPACE); + } *tp++ = '"'; tl--; POST(tl); @@ -1447,8 +1516,9 @@ txt_fromtext(isc_textregion_t *source, isc_buffer_t *target) t = tregion.base; nrem = tregion.length; escape = false; - if (nrem < 1) + if (nrem < 1) { return (ISC_R_NOSPACE); + } /* * Length byte. */ @@ -1457,41 +1527,49 @@ txt_fromtext(isc_textregion_t *source, isc_buffer_t *target) /* * Maximum text string length. */ - if (nrem > 255) + if (nrem > 255) { nrem = 255; + } while (n-- != 0) { c = (*s++) & 0xff; if (escape && (d = decvalue((char)c)) != -1) { c = d; - if (n == 0) + if (n == 0) { return (DNS_R_SYNTAX); + } n--; - if ((d = decvalue(*s++)) != -1) + if ((d = decvalue(*s++)) != -1) { c = c * 10 + d; - else + } else { return (DNS_R_SYNTAX); - if (n == 0) + } + if (n == 0) { return (DNS_R_SYNTAX); + } n--; - if ((d = decvalue(*s++)) != -1) + if ((d = decvalue(*s++)) != -1) { c = c * 10 + d; - else + } else { return (DNS_R_SYNTAX); - if (c > 255) + } + if (c > 255) { return (DNS_R_SYNTAX); + } } else if (!escape && c == '\\') { escape = true; continue; } escape = false; - if (nrem == 0) + if (nrem == 0) { return ((tregion.length <= 256U) ? ISC_R_NOSPACE : DNS_R_SYNTAX); + } *t++ = c; nrem--; } - if (escape) + if (escape) { return (DNS_R_SYNTAX); + } *tregion.base = (unsigned char)(t - tregion.base - 1); isc_buffer_add(target, *tregion.base + 1); return (ISC_R_SUCCESS); @@ -1505,18 +1583,22 @@ txt_fromwire(isc_buffer_t *source, isc_buffer_t *target) isc_region_t tregion; isc_buffer_activeregion(source, &sregion); - if (sregion.length == 0) + if (sregion.length == 0) { return (ISC_R_UNEXPECTEDEND); + } n = *sregion.base + 1; - if (n > sregion.length) + if (n > sregion.length) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_availableregion(target, &tregion); - if (n > tregion.length) + if (n > tregion.length) { return (ISC_R_NOSPACE); + } - if (tregion.base != sregion.base) + if (tregion.base != sregion.base) { memmove(tregion.base, sregion.base, n); + } isc_buffer_forward(source, n); isc_buffer_add(target, n); return (ISC_R_SUCCESS); @@ -1539,8 +1621,9 @@ multitxt_totext(isc_region_t *source, isc_buffer_t *target) tp = (char *)region.base; tl = region.length; - if (tl < 1) + if (tl < 1) { return (ISC_R_NOSPACE); + } *tp++ = '"'; tl--; do { @@ -1549,8 +1632,9 @@ multitxt_totext(isc_region_t *source, isc_buffer_t *target) while (n--) { if (*sp < 0x20 || *sp >= 0x7f) { - if (tl < 4) + if (tl < 4) { return (ISC_R_NOSPACE); + } *tp++ = 0x5c; *tp++ = 0x30 + ((*sp / 100) % 10); *tp++ = 0x30 + ((*sp / 10) % 10); @@ -1561,20 +1645,23 @@ multitxt_totext(isc_region_t *source, isc_buffer_t *target) } /* double quote, backslash */ if (*sp == 0x22 || *sp == 0x5c) { - if (tl < 2) + if (tl < 2) { return (ISC_R_NOSPACE); + } *tp++ = '\\'; tl--; } - if (tl < 1) + if (tl < 1) { return (ISC_R_NOSPACE); + } *tp++ = *sp++; tl--; } isc_region_consume(source, n0 + 1); } while (source->length != 0); - if (tl < 1) + if (tl < 1) { return (ISC_R_NOSPACE); + } *tp++ = '"'; tl--; POST(tl); @@ -1601,30 +1688,36 @@ multitxt_fromtext(isc_textregion_t *source, isc_buffer_t *target) isc_buffer_availableregion(target, &tregion); t0 = t = tregion.base; nrem = tregion.length; - if (nrem < 1) + if (nrem < 1) { return (ISC_R_NOSPACE); + } while (n != 0) { --n; c = (*s++) & 0xff; if (escape && (d = decvalue((char)c)) != -1) { c = d; - if (n == 0) + if (n == 0) { return (DNS_R_SYNTAX); + } n--; - if ((d = decvalue(*s++)) != -1) + if ((d = decvalue(*s++)) != -1) { c = c * 10 + d; - else + } else { return (DNS_R_SYNTAX); - if (n == 0) + } + if (n == 0) { return (DNS_R_SYNTAX); + } n--; - if ((d = decvalue(*s++)) != -1) + if ((d = decvalue(*s++)) != -1) { c = c * 10 + d; - else + } else { return (DNS_R_SYNTAX); - if (c > 255) + } + if (c > 255) { return (DNS_R_SYNTAX); + } } else if (!escape && c == '\\') { escape = true; continue; @@ -1632,11 +1725,13 @@ multitxt_fromtext(isc_textregion_t *source, isc_buffer_t *target) escape = false; *t++ = c; nrem--; - if (nrem == 0) + if (nrem == 0) { break; + } } - if (escape) + if (escape) { return (DNS_R_SYNTAX); + } isc_buffer_add(target, (unsigned int)(t - t0)); } while (n != 0); @@ -1648,25 +1743,30 @@ name_prefix(dns_name_t *name, const dns_name_t *origin, dns_name_t *target) { int l1, l2; - if (origin == NULL) + if (origin == NULL) { goto return_false; + } - if (dns_name_compare(origin, dns_rootname) == 0) + if (dns_name_compare(origin, dns_rootname) == 0) { goto return_false; + } - if (!dns_name_issubdomain(name, origin)) + if (!dns_name_issubdomain(name, origin)) { goto return_false; + } l1 = dns_name_countlabels(name); l2 = dns_name_countlabels(origin); - if (l1 == l2) + if (l1 == l2) { goto return_false; + } /* Master files should be case preserving. */ dns_name_getlabelsequence(name, l1 - l2, l2, target); - if (!dns_name_caseequal(origin, target)) + if (!dns_name_caseequal(origin, target)) { goto return_false; + } dns_name_getlabelsequence(name, 0, l1 - l2, target); return (true); @@ -1685,8 +1785,9 @@ str_totext(const char *source, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(source); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, source, l); isc_buffer_add(target, l); @@ -1699,10 +1800,12 @@ inet_totext(int af, isc_region_t *src, isc_buffer_t *target) char tmpbuf[64]; /* Note - inet_ntop doesn't do size checking on its input. */ - if (inet_ntop(af, src->base, tmpbuf, sizeof(tmpbuf)) == NULL) + if (inet_ntop(af, src->base, tmpbuf, sizeof(tmpbuf)) == NULL) { return (ISC_R_NOSPACE); - if (strlen(tmpbuf) > isc_buffer_availablelength(target)) + } + if (strlen(tmpbuf) > isc_buffer_availablelength(target)) { return (ISC_R_NOSPACE); + } isc_buffer_putstr(target, tmpbuf); return (ISC_R_SUCCESS); } @@ -1727,8 +1830,9 @@ uint32_tobuffer(uint32_t value, isc_buffer_t *target) isc_region_t region; isc_buffer_availableregion(target, ®ion); - if (region.length < 4) + if (region.length < 4) { return (ISC_R_NOSPACE); + } isc_buffer_putuint32(target, value); return (ISC_R_SUCCESS); } @@ -1738,11 +1842,13 @@ uint16_tobuffer(uint32_t value, isc_buffer_t *target) { isc_region_t region; - if (value > 0xffff) + if (value > 0xffff) { return (ISC_R_RANGE); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 2) + if (region.length < 2) { return (ISC_R_NOSPACE); + } isc_buffer_putuint16(target, (uint16_t)value); return (ISC_R_SUCCESS); } @@ -1752,11 +1858,13 @@ uint8_tobuffer(uint32_t value, isc_buffer_t *target) { isc_region_t region; - if (value > 0xff) + if (value > 0xff) { return (ISC_R_RANGE); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 1) + if (region.length < 1) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(target, (uint8_t)value); return (ISC_R_SUCCESS); } @@ -1788,7 +1896,7 @@ uint16_consume_fromregion(isc_region_t *region) uint16_t r = uint16_fromregion(region); isc_region_consume(region, 2); - return r; + return (r); } static uint16_t @@ -1813,7 +1921,7 @@ uint8_consume_fromregion(isc_region_t *region) uint8_t r = uint8_fromregion(region); isc_region_consume(region, 1); - return r; + return (r); } static isc_result_t @@ -1821,14 +1929,17 @@ mem_tobuffer(isc_buffer_t *target, void *base, unsigned int length) { isc_region_t tr; - if (length == 0U) + if (length == 0U) { return (ISC_R_SUCCESS); + } isc_buffer_availableregion(target, &tr); - if (length > tr.length) + if (length > tr.length) { return (ISC_R_NOSPACE); - if (tr.base != base) + } + if (tr.base != base) { memmove(tr.base, base, length); + } isc_buffer_add(target, length); return (ISC_R_SUCCESS); } @@ -1841,13 +1952,16 @@ hexvalue(char value) c = (unsigned char)value; - if (!isascii(c)) + if (!isascii(c)) { return (-1); - if (isupper(c)) + } + if (isupper(c)) { c = tolower(c); - if ((s = strchr(hexdigits, c)) == NULL) + } + if ((s = strchr(hexdigits, c)) == NULL) { return (-1); - return (int)(s - hexdigits); + } + return ((int)(s - hexdigits)); } static int @@ -1859,11 +1973,13 @@ decvalue(char value) * isascii() is valid for full range of int values, no need to * mask or cast. */ - if (!isascii(value)) + if (!isascii(value)) { return (-1); - if ((s = strchr(decdigits, value)) == NULL) + } + if ((s = strchr(decdigits, value)) == NULL) { return (-1); - return (int)(s - decdigits); + } + return ((int)(s - decdigits)); } static void @@ -1884,8 +2000,9 @@ fromtext_warneof(isc_lex_t *lexer, dns_rdatacallbacks_t *callbacks) { if (isc_lex_isfile(lexer) && callbacks != NULL) { const char *name = isc_lex_getsourcename(lexer); - if (name == NULL) + if (name == NULL) { name = "UNKNOWN"; + } (*callbacks->warn)(callbacks, "%s:%lu: file does not end with newline", name, isc_lex_getsourceline(lexer)); @@ -1931,8 +2048,9 @@ fromtext_error(void (*callback)(dns_rdatacallbacks_t *, const char *, ...), dns_rdatacallbacks_t *callbacks, const char *name, unsigned long line, isc_token_t *token, isc_result_t result) { - if (name == NULL) + if (name == NULL) { name = "UNKNOWN"; + } if (token != NULL) { switch (token->type) { @@ -1974,24 +2092,28 @@ fromtext_error(void (*callback)(dns_rdatacallbacks_t *, const char *, ...), dns_rdatatype_t dns_rdata_covers(dns_rdata_t *rdata) { - if (rdata->type == dns_rdatatype_rrsig) + if (rdata->type == dns_rdatatype_rrsig) { return (covers_rrsig(rdata)); + } return (covers_sig(rdata)); } bool dns_rdatatype_ismeta(dns_rdatatype_t type) { - if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_META) != 0) + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_META) != 0) { return (true); + } return (false); } bool dns_rdatatype_issingleton(dns_rdatatype_t type) { - if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_SINGLETON) != 0) + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_SINGLETON) != + 0) { return (true); + } return (false); } @@ -1999,8 +2121,9 @@ bool dns_rdatatype_notquestion(dns_rdatatype_t type) { if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_NOTQUESTION) != - 0) + 0) { return (true); + } return (false); } @@ -2008,8 +2131,9 @@ bool dns_rdatatype_questiononly(dns_rdatatype_t type) { if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_QUESTIONONLY) != - 0) + 0) { return (true); + } return (false); } @@ -2025,8 +2149,10 @@ dns_rdatatype_atcname(dns_rdatatype_t type) bool dns_rdatatype_atparent(dns_rdatatype_t type) { - if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_ATPARENT) != 0) + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_ATPARENT) != + 0) { return (true); + } return (false); } @@ -2034,8 +2160,9 @@ bool dns_rdataclass_ismeta(dns_rdataclass_t rdclass) { if (rdclass == dns_rdataclass_reserved0 || - rdclass == dns_rdataclass_none || rdclass == dns_rdataclass_any) + rdclass == dns_rdataclass_none || rdclass == dns_rdataclass_any) { return (true); + } return (false); /* Assume it is not a meta class. */ } @@ -2043,8 +2170,9 @@ dns_rdataclass_ismeta(dns_rdataclass_t rdclass) bool dns_rdatatype_isdnssec(dns_rdatatype_t type) { - if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_DNSSEC) != 0) + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_DNSSEC) != 0) { return (true); + } return (false); } @@ -2061,8 +2189,9 @@ dns_rdatatype_iszonecutauth(dns_rdatatype_t type) bool dns_rdatatype_isknown(dns_rdatatype_t type) { - if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_UNKNOWN) == 0) + if ((dns_rdatatype_attributes(type) & DNS_RDATATYPEATTR_UNKNOWN) == 0) { return (true); + } return (false); } diff --git a/lib/dns/rdata/any_255/tsig_250.c b/lib/dns/rdata/any_255/tsig_250.c index a19d9e71ce..5a7dca061f 100644 --- a/lib/dns/rdata/any_255/tsig_250.c +++ b/lib/dns/rdata/any_255/tsig_250.c @@ -39,8 +39,9 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); /* @@ -49,10 +50,12 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); sigtime = strtoull(DNS_AS_STR(token), &e, 10); - if (*e != 0) + if (*e != 0) { RETTOK(DNS_R_SYNTAX); - if ((sigtime >> 48) != 0) + } + if ((sigtime >> 48) != 0) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer((uint16_t)(sigtime >> 32), target)); RETERR(uint32_tobuffer((uint32_t)(sigtime & 0xffffffffU), target)); @@ -61,8 +64,9 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -70,8 +74,9 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -84,8 +89,9 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -96,10 +102,12 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion) != ISC_R_SUCCESS) { i = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0) + if (*e != 0) { RETTOK(DNS_R_UNKNOWN); - if (i < 0 || i > 0xffff) + } + if (i < 0 || i > 0xffff) { RETTOK(ISC_R_RANGE); + } rcode = (dns_rcode_t)i; } RETERR(uint16_tobuffer(rcode, target)); @@ -109,8 +117,9 @@ static inline isc_result_t fromtext_any_tsig(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -187,18 +196,21 @@ static inline isc_result_t totext_any_tsig(ARGS_TOTEXT) REQUIRE(n <= sr.length); sigr = sr; sigr.length = n; - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sigr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sigr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" ) ", target)); - else + } else { RETERR(str_totext(" ", target)); + } isc_region_consume(&sr, n); } else { RETERR(str_totext(" ", target)); @@ -230,10 +242,11 @@ static inline isc_result_t totext_any_tsig(ARGS_TOTEXT) /* * Other. */ - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ return (isc_base64_totext(&sr, 60, "", target)); - else + } else { return (isc_base64_totext(&sr, 60, " ", target)); + } } static inline isc_result_t fromwire_any_tsig(ARGS_FROMWIRE) @@ -260,8 +273,9 @@ static inline isc_result_t fromwire_any_tsig(ARGS_FROMWIRE) /* * Time Signed + Fudge. */ - if (sr.length < 8) + if (sr.length < 8) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, 8)); isc_region_consume(&sr, 8); isc_buffer_forward(source, 8); @@ -269,11 +283,13 @@ static inline isc_result_t fromwire_any_tsig(ARGS_FROMWIRE) /* * Signature Length + Signature. */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } n = uint16_fromregion(&sr); - if (sr.length < n + 2) + if (sr.length < n + 2) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, n + 2)); isc_region_consume(&sr, n + 2); isc_buffer_forward(source, n + 2); @@ -281,8 +297,9 @@ static inline isc_result_t fromwire_any_tsig(ARGS_FROMWIRE) /* * Original ID + Error. */ - if (sr.length < 4) + if (sr.length < 4) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, 4)); isc_region_consume(&sr, 4); isc_buffer_forward(source, 4); @@ -290,11 +307,13 @@ static inline isc_result_t fromwire_any_tsig(ARGS_FROMWIRE) /* * Other Length + Other. */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } n = uint16_fromregion(&sr); - if (sr.length < n + 2) + if (sr.length < n + 2) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, n + 2); return (mem_tobuffer(target, sr.base, n + 2)); } @@ -340,8 +359,9 @@ static inline int compare_any_tsig(ARGS_COMPARE) dns_name_fromregion(&name1, &r1); dns_name_fromregion(&name2, &r2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(&r1, name_length(&name1)); isc_region_consume(&r2, name_length(&name2)); return (isc_region_compare(&r1, &r2)); @@ -367,8 +387,9 @@ static inline isc_result_t fromstruct_any_tsig(ARGS_FROMSTRUCT) RETERR(name_tobuffer(&tsig->algorithm, target)); isc_buffer_availableregion(target, &tr); - if (tr.length < 6 + 2 + 2) + if (tr.length < 6 + 2 + 2) { return (ISC_R_NOSPACE); + } /* * Time Signed: 48 bits. @@ -393,8 +414,9 @@ static inline isc_result_t fromstruct_any_tsig(ARGS_FROMSTRUCT) RETERR(mem_tobuffer(target, tsig->signature, tsig->siglen)); isc_buffer_availableregion(target, &tr); - if (tr.length < 2 + 2 + 2) + if (tr.length < 2 + 2 + 2) { return (ISC_R_NOSPACE); + } /* * Original ID. @@ -471,8 +493,9 @@ static inline isc_result_t tostruct_any_tsig(ARGS_TOSTRUCT) */ INSIST(sr.length >= tsig->siglen); tsig->signature = mem_maybedup(mctx, sr.base, tsig->siglen); - if (tsig->signature == NULL) + if (tsig->signature == NULL) { goto cleanup; + } isc_region_consume(&sr, tsig->siglen); /* @@ -498,17 +521,20 @@ static inline isc_result_t tostruct_any_tsig(ARGS_TOSTRUCT) */ INSIST(sr.length == tsig->otherlen); tsig->other = mem_maybedup(mctx, sr.base, tsig->otherlen); - if (tsig->other == NULL) + if (tsig->other == NULL) { goto cleanup; + } tsig->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&tsig->algorithm, tsig->mctx); - if (mctx != NULL && tsig->signature != NULL) + } + if (mctx != NULL && tsig->signature != NULL) { isc_mem_free(mctx, tsig->signature); + } return (ISC_R_NOMEMORY); } @@ -520,14 +546,17 @@ static inline void freestruct_any_tsig(ARGS_FREESTRUCT) REQUIRE(tsig->common.rdtype == dns_rdatatype_tsig); REQUIRE(tsig->common.rdclass == dns_rdataclass_any); - if (tsig->mctx == NULL) + if (tsig->mctx == NULL) { return; + } dns_name_free(&tsig->algorithm, tsig->mctx); - if (tsig->signature != NULL) + if (tsig->signature != NULL) { isc_mem_free(tsig->mctx, tsig->signature); - if (tsig->other != NULL) + } + if (tsig->other != NULL) { isc_mem_free(tsig->mctx, tsig->other); + } tsig->mctx = NULL; } diff --git a/lib/dns/rdata/ch_3/a_1.c b/lib/dns/rdata/ch_3/a_1.c index b210b412ef..45c7833f49 100644 --- a/lib/dns/rdata/ch_3/a_1.c +++ b/lib/dns/rdata/ch_3/a_1.c @@ -37,23 +37,27 @@ static inline isc_result_t fromtext_ch_a(ARGS_FROMTEXT) /* get domain name */ dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); if ((options & DNS_RDATA_CHECKNAMES) != 0 && (options & DNS_RDATA_CHECKREVERSE) != 0) { bool ok; ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } } /* 16-bit octal address */ RETERR(isc_lex_getoctaltoken(lexer, &token, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } return (uint16_tobuffer(token.value.as_ulong, target)); } @@ -106,10 +110,12 @@ static inline isc_result_t fromwire_ch_a(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sregion); isc_buffer_availableregion(target, &tregion); - if (sregion.length < 2) + if (sregion.length < 2) { return (ISC_R_UNEXPECTEDEND); - if (tregion.length < 2) + } + if (tregion.length < 2) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 2); isc_buffer_forward(source, 2); @@ -140,8 +146,9 @@ static inline isc_result_t towire_ch_a(ARGS_TOWIRE) RETERR(dns_name_towire(&name, cctx, target)); isc_buffer_availableregion(target, &tregion); - if (tregion.length < 2) + if (tregion.length < 2) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 2); isc_buffer_add(target, 2); @@ -175,12 +182,14 @@ static inline int compare_ch_a(ARGS_COMPARE) isc_region_consume(®ion2, name_length(&name2)); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } order = memcmp(region1.base, region2.base, 2); - if (order != 0) + if (order != 0) { order = (order < 0) ? -1 : 1; + } return (order); } @@ -237,8 +246,9 @@ static inline void freestruct_ch_a(ARGS_FREESTRUCT) REQUIRE(a != NULL); REQUIRE(a->common.rdtype == dns_rdatatype_a); - if (a->mctx == NULL) + if (a->mctx == NULL) { return; + } dns_name_free(&a->ch_addr_dom, a->mctx); a->mctx = NULL; @@ -296,8 +306,9 @@ static inline bool checknames_ch_a(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } diff --git a/lib/dns/rdata/ch_3/a_1.h b/lib/dns/rdata/ch_3/a_1.h index d43df916bd..03d9cddbb7 100644 --- a/lib/dns/rdata/ch_3/a_1.h +++ b/lib/dns/rdata/ch_3/a_1.h @@ -20,8 +20,10 @@ typedef uint16_t ch_addr_t; typedef struct dns_rdata_ch_a { dns_rdatacommon_t common; isc_mem_t * mctx; - dns_name_t ch_addr_dom; /* ch-addr domain for back mapping */ - ch_addr_t ch_addr; /* chaos address (16 bit) network order */ + dns_name_t ch_addr_dom; /* ch-addr domain for back mapping + * */ + ch_addr_t ch_addr; /* chaos address (16 bit) network + * order */ } dns_rdata_ch_a_t; #endif /* CH_3_A_1_H */ diff --git a/lib/dns/rdata/generic/afsdb_18.c b/lib/dns/rdata/generic/afsdb_18.c index 4e6685c100..1e874645b1 100644 --- a/lib/dns/rdata/generic/afsdb_18.c +++ b/lib/dns/rdata/generic/afsdb_18.c @@ -34,8 +34,9 @@ static inline isc_result_t fromtext_afsdb(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -45,16 +46,20 @@ static inline isc_result_t fromtext_afsdb(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } return (ISC_R_SUCCESS); } @@ -100,10 +105,12 @@ static inline isc_result_t fromwire_afsdb(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sr); isc_buffer_availableregion(target, &tr); - if (tr.length < 2) + if (tr.length < 2) { return (ISC_R_NOSPACE); - if (sr.length < 2) + } + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } memmove(tr.base, sr.base, 2); isc_buffer_forward(source, 2); isc_buffer_add(target, 2); @@ -123,8 +130,9 @@ static inline isc_result_t towire_afsdb(ARGS_TOWIRE) dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); isc_buffer_availableregion(target, &tr); dns_rdata_toregion(rdata, &sr); - if (tr.length < 2) + if (tr.length < 2) { return (ISC_R_NOSPACE); + } memmove(tr.base, sr.base, 2); isc_region_consume(&sr, 2); isc_buffer_add(target, 2); @@ -150,8 +158,9 @@ static inline int compare_afsdb(ARGS_COMPARE) REQUIRE(rdata2->length != 0); result = memcmp(rdata1->data, rdata2->data, 2); - if (result != 0) + if (result != 0) { return (result < 0 ? -1 : 1); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -222,8 +231,9 @@ static inline void freestruct_afsdb(ARGS_FREESTRUCT) REQUIRE(afsdb != NULL); REQUIRE(afsdb->common.rdtype == dns_rdatatype_afsdb); - if (afsdb->mctx == NULL) + if (afsdb->mctx == NULL) { return; + } dns_name_free(&afsdb->server, afsdb->mctx); afsdb->mctx = NULL; @@ -289,8 +299,9 @@ static inline bool checknames_afsdb(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/amtrelay_260.c b/lib/dns/rdata/generic/amtrelay_260.c index 4f013893cb..c69cd24c4d 100644 --- a/lib/dns/rdata/generic/amtrelay_260.c +++ b/lib/dns/rdata/generic/amtrelay_260.c @@ -60,8 +60,9 @@ static inline isc_result_t fromtext_amtrelay(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0x7fU) + if (token.value.as_ulong > 0x7fU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong | (discovery << 7), target)); gateway = token.value.as_ulong; @@ -133,8 +134,9 @@ static inline isc_result_t totext_amtrelay(ARGS_TOTEXT) REQUIRE(rdata->type == dns_rdatatype_amtrelay); REQUIRE(rdata->length >= 2); - if ((rdata->data[1] & 0x7f) > 3U) + if ((rdata->data[1] & 0x7f) > 3U) { return (ISC_R_NOTIMPLEMENTED); + } /* * Precedence. @@ -193,8 +195,9 @@ static inline isc_result_t fromwire_amtrelay(ARGS_FROMWIRE) dns_decompress_setmethods(dctx, DNS_COMPRESS_NONE); isc_buffer_activeregion(source, ®ion); - if (region.length < 2) + if (region.length < 2) { return (ISC_R_UNEXPECTEDEND); + } switch (region.base[1] & 0x7f) { case 0: @@ -372,14 +375,17 @@ static inline void freestruct_amtrelay(ARGS_FREESTRUCT) REQUIRE(amtrelay != NULL); REQUIRE(amtrelay->common.rdtype == dns_rdatatype_amtrelay); - if (amtrelay->mctx == NULL) + if (amtrelay->mctx == NULL) { return; + } - if (amtrelay->gateway_type == 3) + if (amtrelay->gateway_type == 3) { dns_name_free(&amtrelay->gateway, amtrelay->mctx); + } - if (amtrelay->data != NULL) + if (amtrelay->data != NULL) { isc_mem_free(amtrelay->mctx, amtrelay->data); + } amtrelay->mctx = NULL; } @@ -445,8 +451,9 @@ static inline int casecompare_amtrelay(ARGS_COMPARE) dns_rdata_toregion(rdata2, ®ion2); if (memcmp(region1.base, region2.base, 2) != 0 || - (region1.base[1] & 0x7f) != 3) + (region1.base[1] & 0x7f) != 3) { return (isc_region_compare(®ion1, ®ion2)); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); diff --git a/lib/dns/rdata/generic/caa_257.c b/lib/dns/rdata/generic/caa_257.c index 5475ee05a9..fe70ffeed9 100644 --- a/lib/dns/rdata/generic/caa_257.c +++ b/lib/dns/rdata/generic/caa_257.c @@ -291,8 +291,9 @@ static inline isc_result_t fromtext_caa(ARGS_FROMTEXT) /* Flags. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 255U) + if (token.value.as_ulong > 255U) { RETTOK(ISC_R_RANGE); + } flags = (uint8_t)(token.value.as_ulong & 255U); RETERR(uint8_tobuffer(flags, target)); @@ -316,8 +317,9 @@ static inline isc_result_t fromtext_caa(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, false)); if (token.type != isc_tokentype_qstring && - token.type != isc_tokentype_string) + token.type != isc_tokentype_string) { RETERR(DNS_R_SYNTAX); + } RETERR(multitxt_fromtext(&token.value.as_textregion, target)); return (ISC_R_SUCCESS); } @@ -372,8 +374,9 @@ static inline isc_result_t fromwire_caa(ARGS_FROMWIRE) * Flags */ isc_buffer_activeregion(source, &sr); - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } /* * Flags, tag length @@ -386,16 +389,17 @@ static inline isc_result_t fromwire_caa(ARGS_FROMWIRE) /* * Zero length tag fields are illegal. */ - if (sr.length < len || len == 0) + if (sr.length < len || len == 0) { RETERR(DNS_R_FORMERR); + } /* Check the Tag's value */ for (i = 0; i < len; i++) { if (!alphanumeric[sr.base[i]]) { RETERR(DNS_R_FORMERR); - /* - * Tag + Value - */ + /* + * Tag + Value + */ } } /* @@ -501,27 +505,31 @@ static inline isc_result_t tostruct_caa(ARGS_TOSTRUCT) /* * Flags */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } caa->flags = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* * Tag length */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } caa->tag_len = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* * Tag */ - if (sr.length < caa->tag_len) + if (sr.length < caa->tag_len) { return (ISC_R_UNEXPECTEDEND); + } caa->tag = mem_maybedup(mctx, sr.base, caa->tag_len); - if (caa->tag == NULL) + if (caa->tag == NULL) { return (ISC_R_NOMEMORY); + } isc_region_consume(&sr, caa->tag_len); /* @@ -529,8 +537,9 @@ static inline isc_result_t tostruct_caa(ARGS_TOSTRUCT) */ caa->value_len = sr.length; caa->value = mem_maybedup(mctx, sr.base, sr.length); - if (caa->value == NULL) + if (caa->value == NULL) { return (ISC_R_NOMEMORY); + } caa->mctx = mctx; return (ISC_R_SUCCESS); @@ -543,13 +552,16 @@ static inline void freestruct_caa(ARGS_FREESTRUCT) REQUIRE(caa != NULL); REQUIRE(caa->common.rdtype == dns_rdatatype_caa); - if (caa->mctx == NULL) + if (caa->mctx == NULL) { return; + } - if (caa->tag != NULL) + if (caa->tag != NULL) { isc_mem_free(caa->mctx, caa->tag); - if (caa->value != NULL) + } + if (caa->value != NULL) { isc_mem_free(caa->mctx, caa->value); + } caa->mctx = NULL; } diff --git a/lib/dns/rdata/generic/cert_37.c b/lib/dns/rdata/generic/cert_37.c index e15db2e455..d39eda0b6b 100644 --- a/lib/dns/rdata/generic/cert_37.c +++ b/lib/dns/rdata/generic/cert_37.c @@ -43,8 +43,9 @@ static inline isc_result_t fromtext_cert(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -96,16 +97,19 @@ static inline isc_result_t totext_cert(ARGS_TOTEXT) /* * Cert. */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -121,8 +125,9 @@ static inline isc_result_t fromwire_cert(ARGS_FROMWIRE) UNUSED(options); isc_buffer_activeregion(source, &sr); - if (sr.length < 5) + if (sr.length < 5) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); @@ -200,8 +205,9 @@ static inline isc_result_t tostruct_cert(ARGS_TOSTRUCT) cert->length = region.length; cert->certificate = mem_maybedup(mctx, region.base, region.length); - if (cert->certificate == NULL) + if (cert->certificate == NULL) { return (ISC_R_NOMEMORY); + } cert->mctx = mctx; return (ISC_R_SUCCESS); @@ -214,11 +220,13 @@ static inline void freestruct_cert(ARGS_FREESTRUCT) REQUIRE(cert != NULL); REQUIRE(cert->common.rdtype == dns_rdatatype_cert); - if (cert->mctx == NULL) + if (cert->mctx == NULL) { return; + } - if (cert->certificate != NULL) + if (cert->certificate != NULL) { isc_mem_free(cert->mctx, cert->certificate); + } cert->mctx = NULL; } diff --git a/lib/dns/rdata/generic/cname_5.c b/lib/dns/rdata/generic/cname_5.c index a7c616fcee..6ec523b4b2 100644 --- a/lib/dns/rdata/generic/cname_5.c +++ b/lib/dns/rdata/generic/cname_5.c @@ -32,8 +32,9 @@ static inline isc_result_t fromtext_cname(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -163,8 +164,9 @@ static inline void freestruct_cname(ARGS_FREESTRUCT) REQUIRE(cname != NULL); - if (cname->mctx == NULL) + if (cname->mctx == NULL) { return; + } dns_name_free(&cname->cname, cname->mctx); cname->mctx = NULL; diff --git a/lib/dns/rdata/generic/csync_62.c b/lib/dns/rdata/generic/csync_62.c index b0e3c7723b..637a9581c4 100644 --- a/lib/dns/rdata/generic/csync_62.c +++ b/lib/dns/rdata/generic/csync_62.c @@ -36,8 +36,9 @@ static inline isc_result_t fromtext_csync(ARGS_FROMTEXT) /* Flags. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* Type Map */ @@ -93,8 +94,9 @@ static /* inline */ isc_result_t fromwire_csync(ARGS_FROMWIRE) * Serial + Flags */ isc_buffer_activeregion(source, &sr); - if (sr.length < 6) + if (sr.length < 6) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, 6)); isc_buffer_forward(source, 6); @@ -179,8 +181,9 @@ static inline isc_result_t tostruct_csync(ARGS_TOSTRUCT) csync->len = region.length; csync->typebits = mem_maybedup(mctx, region.base, region.length); - if (csync->typebits == NULL) + if (csync->typebits == NULL) { goto cleanup; + } csync->mctx = mctx; return (ISC_R_SUCCESS); @@ -196,11 +199,13 @@ static inline void freestruct_csync(ARGS_FREESTRUCT) REQUIRE(csync != NULL); REQUIRE(csync->common.rdtype == dns_rdatatype_csync); - if (csync->mctx == NULL) + if (csync->mctx == NULL) { return; + } - if (csync->typebits != NULL) + if (csync->typebits != NULL) { isc_mem_free(csync->mctx, csync->typebits); + } csync->mctx = NULL; } diff --git a/lib/dns/rdata/generic/dlv_32769.c b/lib/dns/rdata/generic/dlv_32769.c index 57ae27d9b1..e24f8aaa43 100644 --- a/lib/dns/rdata/generic/dlv_32769.c +++ b/lib/dns/rdata/generic/dlv_32769.c @@ -98,11 +98,13 @@ static inline void freestruct_dlv(ARGS_FREESTRUCT) REQUIRE(dlv != NULL); REQUIRE(dlv->common.rdtype == dns_rdatatype_dlv); - if (dlv->mctx == NULL) + if (dlv->mctx == NULL) { return; + } - if (dlv->digest != NULL) + if (dlv->digest != NULL) { isc_mem_free(dlv->mctx, dlv->digest); + } dlv->mctx = NULL; } diff --git a/lib/dns/rdata/generic/dname_39.c b/lib/dns/rdata/generic/dname_39.c index b23b5ecd3d..a667d896c3 100644 --- a/lib/dns/rdata/generic/dname_39.c +++ b/lib/dns/rdata/generic/dname_39.c @@ -33,8 +33,9 @@ static inline isc_result_t fromtext_dname(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -164,8 +165,9 @@ static inline void freestruct_dname(ARGS_FREESTRUCT) REQUIRE(dname != NULL); REQUIRE(dname->common.rdtype == dns_rdatatype_dname); - if (dname->mctx == NULL) + if (dname->mctx == NULL) { return; + } dns_name_free(&dname->dname, dname->mctx); dname->mctx = NULL; diff --git a/lib/dns/rdata/generic/ds_43.c b/lib/dns/rdata/generic/ds_43.c index 5b6d6232c3..04165b2604 100644 --- a/lib/dns/rdata/generic/ds_43.c +++ b/lib/dns/rdata/generic/ds_43.c @@ -39,8 +39,9 @@ static inline isc_result_t generic_fromtext_ds(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -126,19 +127,23 @@ static inline isc_result_t generic_totext_ds(ARGS_TOTEXT) /* * Digest. */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_hex_totext(&sr, 0, "", target)); - else + } else { RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - } else + } + } else { RETERR(str_totext("[omitted]", target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -169,20 +174,22 @@ static inline isc_result_t generic_fromwire_ds(ARGS_FROMWIRE) (sr.base[3] == DNS_DSDIGEST_SHA256 && sr.length < 4 + ISC_SHA256_DIGESTLENGTH) || (sr.base[3] == DNS_DSDIGEST_SHA384 && - sr.length < 4 + ISC_SHA384_DIGESTLENGTH)) + sr.length < 4 + ISC_SHA384_DIGESTLENGTH)) { return (ISC_R_UNEXPECTEDEND); + } /* * Only copy digest lengths if we know them. * If there is extra data dns_rdata_fromwire() will * detect that. */ - if (sr.base[3] == DNS_DSDIGEST_SHA1) + if (sr.base[3] == DNS_DSDIGEST_SHA1) { sr.length = 4 + ISC_SHA1_DIGESTLENGTH; - else if (sr.base[3] == DNS_DSDIGEST_SHA256) + } else if (sr.base[3] == DNS_DSDIGEST_SHA256) { sr.length = 4 + ISC_SHA256_DIGESTLENGTH; - else if (sr.base[3] == DNS_DSDIGEST_SHA384) + } else if (sr.base[3] == DNS_DSDIGEST_SHA384) { sr.length = 4 + ISC_SHA384_DIGESTLENGTH; + } isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); @@ -284,8 +291,9 @@ static inline isc_result_t generic_tostruct_ds(ARGS_TOSTRUCT) ds->length = region.length; ds->digest = mem_maybedup(mctx, region.base, region.length); - if (ds->digest == NULL) + if (ds->digest == NULL) { return (ISC_R_NOMEMORY); + } ds->mctx = mctx; return (ISC_R_SUCCESS); @@ -312,11 +320,13 @@ static inline void freestruct_ds(ARGS_FREESTRUCT) REQUIRE(ds != NULL); REQUIRE(ds->common.rdtype == dns_rdatatype_ds); - if (ds->mctx == NULL) + if (ds->mctx == NULL) { return; + } - if (ds->digest != NULL) + if (ds->digest != NULL) { isc_mem_free(ds->mctx, ds->digest); + } ds->mctx = NULL; } diff --git a/lib/dns/rdata/generic/eui48_108.c b/lib/dns/rdata/generic/eui48_108.c index c416808fe6..f86d1fe9bf 100644 --- a/lib/dns/rdata/generic/eui48_108.c +++ b/lib/dns/rdata/generic/eui48_108.c @@ -36,8 +36,9 @@ static inline isc_result_t fromtext_eui48(ARGS_FROMTEXT) n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x", &l0, &l1, &l2, &l3, &l4, &l5); if (n != 6 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U || - l4 > 255U || l5 > 255U) + l4 > 255U || l5 > 255U) { return (DNS_R_BADEUI); + } eui48[0] = l0; eui48[1] = l1; @@ -75,8 +76,9 @@ static inline isc_result_t fromwire_eui48(ARGS_FROMWIRE) UNUSED(dctx); isc_buffer_activeregion(source, &sregion); - if (sregion.length != 6) + if (sregion.length != 6) { return (DNS_R_FORMERR); + } isc_buffer_forward(source, sregion.length); return (mem_tobuffer(target, sregion.base, sregion.length)); } diff --git a/lib/dns/rdata/generic/eui64_109.c b/lib/dns/rdata/generic/eui64_109.c index fdbce2819a..3a0973d79e 100644 --- a/lib/dns/rdata/generic/eui64_109.c +++ b/lib/dns/rdata/generic/eui64_109.c @@ -36,8 +36,9 @@ static inline isc_result_t fromtext_eui64(ARGS_FROMTEXT) n = sscanf(DNS_AS_STR(token), "%2x-%2x-%2x-%2x-%2x-%2x-%2x-%2x", &l0, &l1, &l2, &l3, &l4, &l5, &l6, &l7); if (n != 8 || l0 > 255U || l1 > 255U || l2 > 255U || l3 > 255U || - l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U) + l4 > 255U || l5 > 255U || l6 > 255U || l7 > 255U) { return (DNS_R_BADEUI); + } eui64[0] = l0; eui64[1] = l1; @@ -78,8 +79,9 @@ static inline isc_result_t fromwire_eui64(ARGS_FROMWIRE) UNUSED(dctx); isc_buffer_activeregion(source, &sregion); - if (sregion.length != 8) + if (sregion.length != 8) { return (DNS_R_FORMERR); + } isc_buffer_forward(source, sregion.length); return (mem_tobuffer(target, sregion.base, sregion.length)); } diff --git a/lib/dns/rdata/generic/gpos_27.c b/lib/dns/rdata/generic/gpos_27.c index 80d17b227a..e6431b7909 100644 --- a/lib/dns/rdata/generic/gpos_27.c +++ b/lib/dns/rdata/generic/gpos_27.c @@ -51,8 +51,9 @@ static inline isc_result_t totext_gpos(ARGS_TOTEXT) for (i = 0; i < 3; i++) { RETERR(txt_totext(®ion, true, target)); - if (i != 2) + if (i != 2) { RETERR(str_totext(" ", target)); + } } return (ISC_R_SUCCESS); @@ -137,36 +138,42 @@ static inline isc_result_t tostruct_gpos(ARGS_TOSTRUCT) gpos->long_len = uint8_fromregion(®ion); isc_region_consume(®ion, 1); gpos->longitude = mem_maybedup(mctx, region.base, gpos->long_len); - if (gpos->longitude == NULL) + if (gpos->longitude == NULL) { return (ISC_R_NOMEMORY); + } isc_region_consume(®ion, gpos->long_len); gpos->lat_len = uint8_fromregion(®ion); isc_region_consume(®ion, 1); gpos->latitude = mem_maybedup(mctx, region.base, gpos->lat_len); - if (gpos->latitude == NULL) + if (gpos->latitude == NULL) { goto cleanup_longitude; + } isc_region_consume(®ion, gpos->lat_len); gpos->alt_len = uint8_fromregion(®ion); isc_region_consume(®ion, 1); if (gpos->lat_len > 0) { gpos->altitude = mem_maybedup(mctx, region.base, gpos->alt_len); - if (gpos->altitude == NULL) + if (gpos->altitude == NULL) { goto cleanup_latitude; - } else + } + } else { gpos->altitude = NULL; + } gpos->mctx = mctx; return (ISC_R_SUCCESS); cleanup_latitude: - if (mctx != NULL && gpos->longitude != NULL) + if (mctx != NULL && gpos->longitude != NULL) { isc_mem_free(mctx, gpos->longitude); + } cleanup_longitude: - if (mctx != NULL && gpos->latitude != NULL) + if (mctx != NULL && gpos->latitude != NULL) { isc_mem_free(mctx, gpos->latitude); + } return (ISC_R_NOMEMORY); } @@ -177,15 +184,19 @@ static inline void freestruct_gpos(ARGS_FREESTRUCT) REQUIRE(gpos != NULL); REQUIRE(gpos->common.rdtype == dns_rdatatype_gpos); - if (gpos->mctx == NULL) + if (gpos->mctx == NULL) { return; + } - if (gpos->longitude != NULL) + if (gpos->longitude != NULL) { isc_mem_free(gpos->mctx, gpos->longitude); - if (gpos->latitude != NULL) + } + if (gpos->latitude != NULL) { isc_mem_free(gpos->mctx, gpos->latitude); - if (gpos->altitude != NULL) + } + if (gpos->altitude != NULL) { isc_mem_free(gpos->mctx, gpos->altitude); + } gpos->mctx = NULL; } diff --git a/lib/dns/rdata/generic/hinfo_13.c b/lib/dns/rdata/generic/hinfo_13.c index 165d12bb0b..b55176b3cb 100644 --- a/lib/dns/rdata/generic/hinfo_13.c +++ b/lib/dns/rdata/generic/hinfo_13.c @@ -124,22 +124,25 @@ static inline isc_result_t tostruct_hinfo(ARGS_TOSTRUCT) hinfo->cpu_len = uint8_fromregion(®ion); isc_region_consume(®ion, 1); hinfo->cpu = mem_maybedup(mctx, region.base, hinfo->cpu_len); - if (hinfo->cpu == NULL) + if (hinfo->cpu == NULL) { return (ISC_R_NOMEMORY); + } isc_region_consume(®ion, hinfo->cpu_len); hinfo->os_len = uint8_fromregion(®ion); isc_region_consume(®ion, 1); hinfo->os = mem_maybedup(mctx, region.base, hinfo->os_len); - if (hinfo->os == NULL) + if (hinfo->os == NULL) { goto cleanup; + } hinfo->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL && hinfo->cpu != NULL) + if (mctx != NULL && hinfo->cpu != NULL) { isc_mem_free(mctx, hinfo->cpu); + } return (ISC_R_NOMEMORY); } @@ -149,13 +152,16 @@ static inline void freestruct_hinfo(ARGS_FREESTRUCT) REQUIRE(hinfo != NULL); - if (hinfo->mctx == NULL) + if (hinfo->mctx == NULL) { return; + } - if (hinfo->cpu != NULL) + if (hinfo->cpu != NULL) { isc_mem_free(hinfo->mctx, hinfo->cpu); - if (hinfo->os != NULL) + } + if (hinfo->os != NULL) { isc_mem_free(hinfo->mctx, hinfo->os); + } hinfo->mctx = NULL; } diff --git a/lib/dns/rdata/generic/hip_55.c b/lib/dns/rdata/generic/hip_55.c index a4064f3bcd..7d2dde0f63 100644 --- a/lib/dns/rdata/generic/hip_55.c +++ b/lib/dns/rdata/generic/hip_55.c @@ -43,8 +43,9 @@ static inline isc_result_t fromtext_hip(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -65,8 +66,9 @@ static inline isc_result_t fromtext_hip(ARGS_FROMTEXT) * Fill in HIT len. */ len = (unsigned char *)isc_buffer_used(target) - start; - if (len > 0xffU) + if (len > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer((uint32_t)len, &hit_len)); /* @@ -81,12 +83,14 @@ static inline isc_result_t fromtext_hip(ARGS_FROMTEXT) * Fill in KEY len. */ len = (unsigned char *)isc_buffer_used(target) - start; - if (len > 0xffffU) + if (len > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer((uint32_t)len, &key_len)); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } /* * Rendezvous Servers. @@ -95,8 +99,9 @@ static inline isc_result_t fromtext_hip(ARGS_FROMTEXT) do { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, true)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { break; + } buffer_fromregion(&buffer, &token.value.as_region); RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); @@ -132,8 +137,9 @@ static inline isc_result_t totext_hip(ARGS_TOTEXT) key_len = uint16_fromregion(®ion); isc_region_consume(®ion, 2); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext("( ", target)); + } /* * Algorithm @@ -170,11 +176,13 @@ static inline isc_result_t totext_hip(ARGS_TOTEXT) RETERR(dns_name_totext(&name, false, target)); isc_region_consume(®ion, name.length); - if (region.length > 0) + if (region.length > 0) { RETERR(str_totext(tctx->linebreak, target)); + } } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -191,20 +199,24 @@ static inline isc_result_t fromwire_hip(ARGS_FROMWIRE) UNUSED(rdclass); isc_buffer_activeregion(source, ®ion); - if (region.length < 4U) + if (region.length < 4U) { RETERR(DNS_R_FORMERR); + } rr = region; hit_len = uint8_fromregion(®ion); - if (hit_len == 0) + if (hit_len == 0) { RETERR(DNS_R_FORMERR); + } isc_region_consume(®ion, 2); /* hit length + algorithm */ key_len = uint16_fromregion(®ion); - if (key_len == 0) + if (key_len == 0) { RETERR(DNS_R_FORMERR); + } isc_region_consume(®ion, 2); - if (region.length < (unsigned)(hit_len + key_len)) + if (region.length < (unsigned)(hit_len + key_len)) { RETERR(DNS_R_FORMERR); + } RETERR(mem_tobuffer(target, rr.base, 4 + hit_len + key_len)); isc_buffer_forward(source, 4 + hit_len + key_len); @@ -305,22 +317,25 @@ static inline isc_result_t tostruct_hip(ARGS_TOSTRUCT) hip->hit = hip->key = hip->servers = NULL; hip->hit = mem_maybedup(mctx, region.base, hip->hit_len); - if (hip->hit == NULL) + if (hip->hit == NULL) { goto cleanup; + } isc_region_consume(®ion, hip->hit_len); INSIST(hip->key_len <= region.length); hip->key = mem_maybedup(mctx, region.base, hip->key_len); - if (hip->key == NULL) + if (hip->key == NULL) { goto cleanup; + } isc_region_consume(®ion, hip->key_len); hip->servers_len = region.length; if (hip->servers_len != 0) { hip->servers = mem_maybedup(mctx, region.base, region.length); - if (hip->servers == NULL) + if (hip->servers == NULL) { goto cleanup; + } } hip->offset = hip->servers_len; @@ -328,12 +343,15 @@ static inline isc_result_t tostruct_hip(ARGS_TOSTRUCT) return (ISC_R_SUCCESS); cleanup: - if (hip->hit != NULL) + if (hip->hit != NULL) { isc_mem_free(mctx, hip->hit); - if (hip->key != NULL) + } + if (hip->key != NULL) { isc_mem_free(mctx, hip->key); - if (hip->servers != NULL) + } + if (hip->servers != NULL) { isc_mem_free(mctx, hip->servers); + } return (ISC_R_NOMEMORY); } @@ -343,13 +361,15 @@ static inline void freestruct_hip(ARGS_FREESTRUCT) REQUIRE(hip != NULL); - if (hip->mctx == NULL) + if (hip->mctx == NULL) { return; + } isc_mem_free(hip->mctx, hip->hit); isc_mem_free(hip->mctx, hip->key); - if (hip->servers != NULL) + if (hip->servers != NULL) { isc_mem_free(hip->mctx, hip->servers); + } hip->mctx = NULL; } @@ -400,8 +420,9 @@ static inline bool checknames_hip(ARGS_CHECKNAMES) isc_result_t dns_rdata_hip_first(dns_rdata_hip_t *hip) { - if (hip->servers_len == 0) + if (hip->servers_len == 0) { return (ISC_R_NOMORE); + } hip->offset = 0; return (ISC_R_SUCCESS); } @@ -412,8 +433,9 @@ dns_rdata_hip_next(dns_rdata_hip_t *hip) isc_region_t region; dns_name_t name; - if (hip->offset >= hip->servers_len) + if (hip->offset >= hip->servers_len) { return (ISC_R_NOMORE); + } region.base = hip->servers + hip->offset; region.length = hip->servers_len - hip->offset; @@ -460,8 +482,9 @@ static inline int casecompare_hip(ARGS_COMPARE) INSIST(r1.length > 4); INSIST(r2.length > 4); order = memcmp(r1.base, r2.base, 4); - if (order != 0) + if (order != 0) { return (order); + } hit_len = uint8_fromregion(&r1); isc_region_consume(&r1, 2); /* hit length + algorithm */ @@ -472,8 +495,9 @@ static inline int casecompare_hip(ARGS_COMPARE) INSIST(r1.length >= (unsigned)(hit_len + key_len)); INSIST(r2.length >= (unsigned)(hit_len + key_len)); order = memcmp(r1.base, r2.base, hit_len + key_len); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(&r1, hit_len + key_len); isc_region_consume(&r2, hit_len + key_len); @@ -483,8 +507,9 @@ static inline int casecompare_hip(ARGS_COMPARE) dns_name_fromregion(&name1, &r1); dns_name_fromregion(&name2, &r2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(&r1, name_length(&name1)); isc_region_consume(&r2, name_length(&name2)); diff --git a/lib/dns/rdata/generic/ipseckey_45.c b/lib/dns/rdata/generic/ipseckey_45.c index ce2da330f4..5e80c82c84 100644 --- a/lib/dns/rdata/generic/ipseckey_45.c +++ b/lib/dns/rdata/generic/ipseckey_45.c @@ -39,8 +39,9 @@ static inline isc_result_t fromtext_ipseckey(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -48,8 +49,9 @@ static inline isc_result_t fromtext_ipseckey(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0x3U) + if (token.value.as_ulong > 0x3U) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); gateway = token.value.as_ulong; @@ -58,8 +60,9 @@ static inline isc_result_t fromtext_ipseckey(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -70,26 +73,31 @@ static inline isc_result_t fromtext_ipseckey(ARGS_FROMTEXT) switch (gateway) { case 0: - if (strcmp(DNS_AS_STR(token), ".") != 0) + if (strcmp(DNS_AS_STR(token), ".") != 0) { RETTOK(DNS_R_SYNTAX); + } break; case 1: - if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) + if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) { RETTOK(DNS_R_BADDOTTEDQUAD); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 4) + if (region.length < 4) { return (ISC_R_NOSPACE); + } memmove(region.base, &addr, 4); isc_buffer_add(target, 4); break; case 2: - if (inet_pton(AF_INET6, DNS_AS_STR(token), addr6) != 1) + if (inet_pton(AF_INET6, DNS_AS_STR(token), addr6) != 1) { RETTOK(DNS_R_BADAAAA); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 16) + if (region.length < 16) { return (ISC_R_NOSPACE); + } memmove(region.base, addr6, 16); isc_buffer_add(target, 16); break; @@ -97,8 +105,9 @@ static inline isc_result_t fromtext_ipseckey(ARGS_FROMTEXT) case 3: dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); break; @@ -123,11 +132,13 @@ static inline isc_result_t totext_ipseckey(ARGS_TOTEXT) dns_name_init(&name, NULL); - if (rdata->data[1] > 3U) + if (rdata->data[1] > 3U) { return (ISC_R_NOTIMPLEMENTED); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext("( ", target)); + } /* * Precedence. @@ -184,15 +195,17 @@ static inline isc_result_t totext_ipseckey(ARGS_TOTEXT) */ if (region.length > 0U) { RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(®ion, 60, "", target)); - else + } else { RETERR(isc_base64_totext(®ion, tctx->width - 2, tctx->linebreak, target)); + } } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -211,8 +224,9 @@ static inline isc_result_t fromwire_ipseckey(ARGS_FROMWIRE) dns_name_init(&name, NULL); isc_buffer_activeregion(source, ®ion); - if (region.length < 3) + if (region.length < 3) { return (ISC_R_UNEXPECTEDEND); + } switch (region.base[1]) { case 0: @@ -220,14 +234,16 @@ static inline isc_result_t fromwire_ipseckey(ARGS_FROMWIRE) return (mem_tobuffer(target, region.base, region.length)); case 1: - if (region.length < 7) + if (region.length < 7) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, region.length); return (mem_tobuffer(target, region.base, region.length)); case 2: - if (region.length < 19) + if (region.length < 19) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, region.length); return (mem_tobuffer(target, region.base, region.length)); @@ -288,8 +304,9 @@ static inline isc_result_t fromstruct_ipseckey(ARGS_FROMSTRUCT) UNUSED(type); UNUSED(rdclass); - if (ipseckey->gateway_type > 3U) + if (ipseckey->gateway_type > 3U) { return (ISC_R_NOTIMPLEMENTED); + } RETERR(uint8_tobuffer(ipseckey->precedence, target)); RETERR(uint8_tobuffer(ipseckey->gateway_type, target)); @@ -328,8 +345,9 @@ static inline isc_result_t tostruct_ipseckey(ARGS_TOSTRUCT) REQUIRE(ipseckey != NULL); REQUIRE(rdata->length >= 3); - if (rdata->data[1] > 3U) + if (rdata->data[1] > 3U) { return (ISC_R_NOTIMPLEMENTED); + } ipseckey->common.rdclass = rdata->rdclass; ipseckey->common.rdtype = rdata->type; @@ -375,13 +393,15 @@ static inline isc_result_t tostruct_ipseckey(ARGS_TOSTRUCT) ipseckey->key = mem_maybedup(mctx, region.base, ipseckey->keylength); if (ipseckey->key == NULL) { - if (ipseckey->gateway_type == 3) + if (ipseckey->gateway_type == 3) { dns_name_free(&ipseckey->gateway, ipseckey->mctx); + } return (ISC_R_NOMEMORY); } - } else + } else { ipseckey->key = NULL; + } ipseckey->mctx = mctx; return (ISC_R_SUCCESS); @@ -394,14 +414,17 @@ static inline void freestruct_ipseckey(ARGS_FREESTRUCT) REQUIRE(ipseckey != NULL); REQUIRE(ipseckey->common.rdtype == dns_rdatatype_ipseckey); - if (ipseckey->mctx == NULL) + if (ipseckey->mctx == NULL) { return; + } - if (ipseckey->gateway_type == 3) + if (ipseckey->gateway_type == 3) { dns_name_free(&ipseckey->gateway, ipseckey->mctx); + } - if (ipseckey->key != NULL) + if (ipseckey->key != NULL) { isc_mem_free(ipseckey->mctx, ipseckey->key); + } ipseckey->mctx = NULL; } @@ -467,8 +490,10 @@ static inline int casecompare_ipseckey(ARGS_COMPARE) dns_rdata_toregion(rdata1, ®ion1); dns_rdata_toregion(rdata2, ®ion2); - if (memcmp(region1.base, region2.base, 3) != 0 || region1.base[1] != 3) + if (memcmp(region1.base, region2.base, 3) != 0 || + region1.base[1] != 3) { return (isc_region_compare(®ion1, ®ion2)); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -480,8 +505,9 @@ static inline int casecompare_ipseckey(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); diff --git a/lib/dns/rdata/generic/isdn_20.c b/lib/dns/rdata/generic/isdn_20.c index e8cfc4939b..10ebdcef89 100644 --- a/lib/dns/rdata/generic/isdn_20.c +++ b/lib/dns/rdata/generic/isdn_20.c @@ -56,8 +56,9 @@ static inline isc_result_t totext_isdn(ARGS_TOTEXT) dns_rdata_toregion(rdata, ®ion); RETERR(txt_totext(®ion, true, target)); - if (region.length == 0) + if (region.length == 0) { return (ISC_R_SUCCESS); + } RETERR(str_totext(" ", target)); return (txt_totext(®ion, true, target)); } @@ -72,8 +73,9 @@ static inline isc_result_t fromwire_isdn(ARGS_FROMWIRE) UNUSED(options); RETERR(txt_fromwire(source, target)); - if (buffer_empty(source)) + if (buffer_empty(source)) { return (ISC_R_SUCCESS); + } return (txt_fromwire(source, target)); } @@ -117,8 +119,9 @@ static inline isc_result_t fromstruct_isdn(ARGS_FROMSTRUCT) RETERR(uint8_tobuffer(isdn->isdn_len, target)); RETERR(mem_tobuffer(target, isdn->isdn, isdn->isdn_len)); - if (isdn->subaddress == NULL) + if (isdn->subaddress == NULL) { return (ISC_R_SUCCESS); + } RETERR(uint8_tobuffer(isdn->subaddress_len, target)); return (mem_tobuffer(target, isdn->subaddress, isdn->subaddress_len)); } @@ -141,8 +144,9 @@ static inline isc_result_t tostruct_isdn(ARGS_TOSTRUCT) isdn->isdn_len = uint8_fromregion(&r); isc_region_consume(&r, 1); isdn->isdn = mem_maybedup(mctx, r.base, isdn->isdn_len); - if (isdn->isdn == NULL) + if (isdn->isdn == NULL) { return (ISC_R_NOMEMORY); + } isc_region_consume(&r, isdn->isdn_len); if (r.length == 0) { @@ -153,16 +157,18 @@ static inline isc_result_t tostruct_isdn(ARGS_TOSTRUCT) isc_region_consume(&r, 1); isdn->subaddress = mem_maybedup(mctx, r.base, isdn->subaddress_len); - if (isdn->subaddress == NULL) + if (isdn->subaddress == NULL) { goto cleanup; + } } isdn->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL && isdn->isdn != NULL) + if (mctx != NULL && isdn->isdn != NULL) { isc_mem_free(mctx, isdn->isdn); + } return (ISC_R_NOMEMORY); } @@ -172,13 +178,16 @@ static inline void freestruct_isdn(ARGS_FREESTRUCT) REQUIRE(isdn != NULL); - if (isdn->mctx == NULL) + if (isdn->mctx == NULL) { return; + } - if (isdn->isdn != NULL) + if (isdn->isdn != NULL) { isc_mem_free(isdn->mctx, isdn->isdn); - if (isdn->subaddress != NULL) + } + if (isdn->subaddress != NULL) { isc_mem_free(isdn->mctx, isdn->subaddress); + } isdn->mctx = NULL; } diff --git a/lib/dns/rdata/generic/key_25.c b/lib/dns/rdata/generic/key_25.c index 5075f3600b..ee744e2985 100644 --- a/lib/dns/rdata/generic/key_25.c +++ b/lib/dns/rdata/generic/key_25.c @@ -105,12 +105,14 @@ static inline isc_result_t generic_totext_key(ARGS_TOTEXT) RETERR(str_totext(buf, target)); RETERR(str_totext(" ", target)); if ((flags & DNS_KEYFLAG_KSK) != 0) { - if (flags & DNS_KEYFLAG_REVOKE) + if (flags & DNS_KEYFLAG_REVOKE) { keyinfo = "revoked KSK"; - else + } else { keyinfo = "KSK"; - } else + } + } else { keyinfo = "ZSK"; + } /* protocol */ snprintf(buf, sizeof(buf), "%u", sr.base[0]); @@ -141,16 +143,18 @@ static inline isc_result_t generic_totext_key(ARGS_TOTEXT) } /* key */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); + } } else { dns_rdata_toregion(rdata, &tmpr); snprintf(buf, sizeof(buf), "[key id = %u]", @@ -158,13 +162,15 @@ static inline isc_result_t generic_totext_key(ARGS_TOTEXT) RETERR(str_totext(buf, target)); } - if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) + if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) { RETERR(str_totext(tctx->linebreak, target)); - else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" ", target)); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(")", target)); + } if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) { if (rdata->type == dns_rdatatype_dnskey || @@ -326,28 +332,32 @@ static inline isc_result_t generic_tostruct_key(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &sr); /* Flags */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } key->flags = uint16_fromregion(&sr); isc_region_consume(&sr, 2); /* Protocol */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } key->protocol = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Algorithm */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } key->algorithm = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Data */ key->datalen = sr.length; key->data = mem_maybedup(mctx, sr.base, key->datalen); - if (key->data == NULL) + if (key->data == NULL) { return (ISC_R_NOMEMORY); + } key->mctx = mctx; return (ISC_R_SUCCESS); @@ -359,11 +369,13 @@ static inline void generic_freestruct_key(ARGS_FREESTRUCT) REQUIRE(key != NULL); - if (key->mctx == NULL) + if (key->mctx == NULL) { return; + } - if (key->data != NULL) + if (key->data != NULL) { isc_mem_free(key->mctx, key->data); + } key->mctx = NULL; } diff --git a/lib/dns/rdata/generic/keydata_65533.c b/lib/dns/rdata/generic/keydata_65533.c index 04b892f222..a71969c138 100644 --- a/lib/dns/rdata/generic/keydata_65533.c +++ b/lib/dns/rdata/generic/keydata_65533.c @@ -72,8 +72,9 @@ static inline isc_result_t fromtext_keydata(ARGS_FROMTEXT) RETERR(mem_tobuffer(target, &alg, 1)); /* No Key? */ - if ((flags & 0xc000) == 0xc000) + if ((flags & 0xc000) == 0xc000) { return (ISC_R_SUCCESS); + } return (isc_base64_tobuffer(lexer, target, -2)); } @@ -90,8 +91,9 @@ static inline isc_result_t totext_keydata(ARGS_TOTEXT) REQUIRE(rdata->type == dns_rdatatype_keydata); - if ((tctx->flags & DNS_STYLEFLAG_KEYDATA) == 0 || rdata->length < 16) + if ((tctx->flags & DNS_STYLEFLAG_KEYDATA) == 0 || rdata->length < 16) { return (unknown_totext(rdata, tctx, target)); + } dns_rdata_toregion(rdata, &sr); @@ -142,26 +144,31 @@ static inline isc_result_t totext_keydata(ARGS_TOTEXT) RETERR(str_totext(buf, target)); /* No Key? */ - if ((flags & 0xc000) == 0xc000) + if ((flags & 0xc000) == 0xc000) { return (ISC_R_SUCCESS); + } /* key */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); + } - if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) + if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) { RETERR(str_totext(tctx->linebreak, target)); - else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } else if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" ", target)); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(")", target)); + } if ((tctx->flags & DNS_STYLEFLAG_RRCOMMENT) != 0) { isc_region_t tmpr; @@ -317,46 +324,53 @@ static inline isc_result_t tostruct_keydata(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &sr); /* Refresh timer */ - if (sr.length < 4) + if (sr.length < 4) { return (ISC_R_UNEXPECTEDEND); + } keydata->refresh = uint32_fromregion(&sr); isc_region_consume(&sr, 4); /* Add hold-down */ - if (sr.length < 4) + if (sr.length < 4) { return (ISC_R_UNEXPECTEDEND); + } keydata->addhd = uint32_fromregion(&sr); isc_region_consume(&sr, 4); /* Remove hold-down */ - if (sr.length < 4) + if (sr.length < 4) { return (ISC_R_UNEXPECTEDEND); + } keydata->removehd = uint32_fromregion(&sr); isc_region_consume(&sr, 4); /* Flags */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } keydata->flags = uint16_fromregion(&sr); isc_region_consume(&sr, 2); /* Protocol */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } keydata->protocol = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Algorithm */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } keydata->algorithm = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Data */ keydata->datalen = sr.length; keydata->data = mem_maybedup(mctx, sr.base, keydata->datalen); - if (keydata->data == NULL) + if (keydata->data == NULL) { return (ISC_R_NOMEMORY); + } keydata->mctx = mctx; return (ISC_R_SUCCESS); @@ -369,11 +383,13 @@ static inline void freestruct_keydata(ARGS_FREESTRUCT) REQUIRE(keydata != NULL); REQUIRE(keydata->common.rdtype == dns_rdatatype_keydata); - if (keydata->mctx == NULL) + if (keydata->mctx == NULL) { return; + } - if (keydata->data != NULL) + if (keydata->data != NULL) { isc_mem_free(keydata->mctx, keydata->data); + } keydata->mctx = NULL; } diff --git a/lib/dns/rdata/generic/l32_105.c b/lib/dns/rdata/generic/l32_105.c index eeebac35a2..e643ee3e65 100644 --- a/lib/dns/rdata/generic/l32_105.c +++ b/lib/dns/rdata/generic/l32_105.c @@ -34,18 +34,21 @@ static inline isc_result_t fromtext_l32(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) + if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) { RETTOK(DNS_R_BADDOTTEDQUAD); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 4) + if (region.length < 4) { return (ISC_R_NOSPACE); + } memmove(region.base, &addr, 4); isc_buffer_add(target, 4); return (ISC_R_SUCCESS); @@ -85,8 +88,9 @@ static inline isc_result_t fromwire_l32(ARGS_FROMWIRE) UNUSED(dctx); isc_buffer_activeregion(source, &sregion); - if (sregion.length != 6) + if (sregion.length != 6) { return (DNS_R_FORMERR); + } isc_buffer_forward(source, sregion.length); return (mem_tobuffer(target, sregion.base, sregion.length)); } diff --git a/lib/dns/rdata/generic/l64_106.c b/lib/dns/rdata/generic/l64_106.c index 782c41f735..bf31cd557e 100644 --- a/lib/dns/rdata/generic/l64_106.c +++ b/lib/dns/rdata/generic/l64_106.c @@ -33,15 +33,17 @@ static inline isc_result_t fromtext_l64(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (locator_pton(DNS_AS_STR(token), locator) != 1) + if (locator_pton(DNS_AS_STR(token), locator) != 1) { RETTOK(DNS_R_SYNTAX); + } return (mem_tobuffer(target, locator, NS_LOCATORSZ)); } @@ -84,8 +86,9 @@ static inline isc_result_t fromwire_l64(ARGS_FROMWIRE) UNUSED(dctx); isc_buffer_activeregion(source, &sregion); - if (sregion.length != 10) + if (sregion.length != 10) { return (DNS_R_FORMERR); + } isc_buffer_forward(source, sregion.length); return (mem_tobuffer(target, sregion.base, sregion.length)); } diff --git a/lib/dns/rdata/generic/loc_29.c b/lib/dns/rdata/generic/loc_29.c index 230f4d7301..53e84f5fc8 100644 --- a/lib/dns/rdata/generic/loc_29.c +++ b/lib/dns/rdata/generic/loc_29.c @@ -62,48 +62,60 @@ static inline isc_result_t fromtext_loc(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 90U) + if (token.value.as_ulong > 90U) { RETTOK(ISC_R_RANGE); + } d1 = (int)token.value.as_ulong; /* * Minutes. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (strcasecmp(DNS_AS_STR(token), "N") == 0) + if (strcasecmp(DNS_AS_STR(token), "N") == 0) { north = true; - if (north || strcasecmp(DNS_AS_STR(token), "S") == 0) + } + if (north || strcasecmp(DNS_AS_STR(token), "S") == 0) { goto getlong; + } m1 = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0) + if (*e != 0) { RETTOK(DNS_R_SYNTAX); - if (m1 < 0 || m1 > 59) + } + if (m1 < 0 || m1 > 59) { RETTOK(ISC_R_RANGE); - if (d1 == 90 && m1 != 0) + } + if (d1 == 90 && m1 != 0) { RETTOK(ISC_R_RANGE); + } /* * Seconds. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (strcasecmp(DNS_AS_STR(token), "N") == 0) + if (strcasecmp(DNS_AS_STR(token), "N") == 0) { north = true; - if (north || strcasecmp(DNS_AS_STR(token), "S") == 0) + } + if (north || strcasecmp(DNS_AS_STR(token), "S") == 0) { goto getlong; + } s1 = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0 && *e != '.') + if (*e != 0 && *e != '.') { RETTOK(DNS_R_SYNTAX); - if (s1 < 0 || s1 > 59) + } + if (s1 < 0 || s1 > 59) { RETTOK(ISC_R_RANGE); + } if (*e == '.') { const char *l; e++; for (i = 0; i < 3; i++) { - if (*e == 0) + if (*e == 0) { break; - if ((tmp = decvalue(*e++)) < 0) + } + if ((tmp = decvalue(*e++)) < 0) { RETTOK(DNS_R_SYNTAX); + } s1 *= 10; s1 += tmp; } @@ -111,35 +123,41 @@ static inline isc_result_t fromtext_loc(ARGS_FROMTEXT) s1 *= 10; l = e; while (*e != 0) { - if (decvalue(*e++) < 0) + if (decvalue(*e++) < 0) { RETTOK(DNS_R_SYNTAX); + } } if (*l != '\0' && callbacks != NULL) { const char * file = isc_lex_getsourcename(lexer); unsigned long line = isc_lex_getsourceline(lexer); - if (file == NULL) + if (file == NULL) { file = "UNKNOWN"; + } (*callbacks->warn)(callbacks, "%s: %s:%u: '%s' extra " "precision digits ignored", "dns_rdata_fromtext", file, line, DNS_AS_STR(token)); } - } else + } else { s1 *= 1000; - if (d1 == 90 && s1 != 0) + } + if (d1 == 90 && s1 != 0) { RETTOK(ISC_R_RANGE); + } /* * Direction. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (strcasecmp(DNS_AS_STR(token), "N") == 0) + if (strcasecmp(DNS_AS_STR(token), "N") == 0) { north = true; - if (!north && strcasecmp(DNS_AS_STR(token), "S") != 0) + } + if (!north && strcasecmp(DNS_AS_STR(token), "S") != 0) { RETTOK(DNS_R_SYNTAX); + } getlong: /* @@ -147,8 +165,9 @@ getlong: */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 180U) + if (token.value.as_ulong > 180U) { RETTOK(ISC_R_RANGE); + } d2 = (int)token.value.as_ulong; /* @@ -156,40 +175,51 @@ getlong: */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (strcasecmp(DNS_AS_STR(token), "E") == 0) + if (strcasecmp(DNS_AS_STR(token), "E") == 0) { east = true; - if (east || strcasecmp(DNS_AS_STR(token), "W") == 0) + } + if (east || strcasecmp(DNS_AS_STR(token), "W") == 0) { goto getalt; + } m2 = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0) + if (*e != 0) { RETTOK(DNS_R_SYNTAX); - if (m2 < 0 || m2 > 59) + } + if (m2 < 0 || m2 > 59) { RETTOK(ISC_R_RANGE); - if (d2 == 180 && m2 != 0) + } + if (d2 == 180 && m2 != 0) { RETTOK(ISC_R_RANGE); + } /* * Seconds. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (strcasecmp(DNS_AS_STR(token), "E") == 0) + if (strcasecmp(DNS_AS_STR(token), "E") == 0) { east = true; - if (east || strcasecmp(DNS_AS_STR(token), "W") == 0) + } + if (east || strcasecmp(DNS_AS_STR(token), "W") == 0) { goto getalt; + } s2 = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0 && *e != '.') + if (*e != 0 && *e != '.') { RETTOK(DNS_R_SYNTAX); - if (s2 < 0 || s2 > 59) + } + if (s2 < 0 || s2 > 59) { RETTOK(ISC_R_RANGE); + } if (*e == '.') { const char *l; e++; for (i = 0; i < 3; i++) { - if (*e == 0) + if (*e == 0) { break; - if ((tmp = decvalue(*e++)) < 0) + } + if ((tmp = decvalue(*e++)) < 0) { RETTOK(DNS_R_SYNTAX); + } s2 *= 10; s2 += tmp; } @@ -197,35 +227,41 @@ getlong: s2 *= 10; l = e; while (*e != 0) { - if (decvalue(*e++) < 0) + if (decvalue(*e++) < 0) { RETTOK(DNS_R_SYNTAX); + } } if (*l != '\0' && callbacks != NULL) { const char * file = isc_lex_getsourcename(lexer); unsigned long line = isc_lex_getsourceline(lexer); - if (file == NULL) + if (file == NULL) { file = "UNKNOWN"; + } (*callbacks->warn)(callbacks, "%s: %s:%u: '%s' extra " "precision digits ignored", "dns_rdata_fromtext", file, line, DNS_AS_STR(token)); } - } else + } else { s2 *= 1000; - if (d2 == 180 && s2 != 0) + } + if (d2 == 180 && s2 != 0) { RETTOK(ISC_R_RANGE); + } /* * Direction. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (strcasecmp(DNS_AS_STR(token), "E") == 0) + if (strcasecmp(DNS_AS_STR(token), "E") == 0) { east = true; - if (!east && strcasecmp(DNS_AS_STR(token), "W") != 0) + } + if (!east && strcasecmp(DNS_AS_STR(token), "W") != 0) { RETTOK(DNS_R_SYNTAX); + } getalt: /* @@ -234,35 +270,44 @@ getalt: RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); m = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0 && *e != '.' && *e != 'm') + if (*e != 0 && *e != '.' && *e != 'm') { RETTOK(DNS_R_SYNTAX); - if (m < -100000 || m > 42849672) + } + if (m < -100000 || m > 42849672) { RETTOK(ISC_R_RANGE); + } cm = 0; if (*e == '.') { e++; for (i = 0; i < 2; i++) { - if (*e == 0 || *e == 'm') + if (*e == 0 || *e == 'm') { break; - if ((tmp = decvalue(*e++)) < 0) + } + if ((tmp = decvalue(*e++)) < 0) { return (DNS_R_SYNTAX); + } cm *= 10; - if (m < 0) + if (m < 0) { cm -= tmp; - else + } else { cm += tmp; + } } for (; i < 2; i++) cm *= 10; } - if (*e == 'm') + if (*e == 'm') { e++; - if (*e != 0) + } + if (*e != 0) { RETTOK(DNS_R_SYNTAX); - if (m == -100000 && cm != 0) + } + if (m == -100000 && cm != 0) { RETTOK(ISC_R_RANGE); - if (m == 42849672 && cm > 95) + } + if (m == 42849672 && cm > 95) { RETTOK(ISC_R_RANGE); + } /* * Adjust base. */ @@ -281,28 +326,34 @@ getalt: goto encode; } m = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0 && *e != '.' && *e != 'm') + if (*e != 0 && *e != '.' && *e != 'm') { RETTOK(DNS_R_SYNTAX); - if (m < 0 || m > 90000000) + } + if (m < 0 || m > 90000000) { RETTOK(ISC_R_RANGE); + } cm = 0; if (*e == '.') { e++; for (i = 0; i < 2; i++) { - if (*e == 0 || *e == 'm') + if (*e == 0 || *e == 'm') { break; - if ((tmp = decvalue(*e++)) < 0) + } + if ((tmp = decvalue(*e++)) < 0) { RETTOK(DNS_R_SYNTAX); + } cm *= 10; cm += tmp; } for (; i < 2; i++) cm *= 10; } - if (*e == 'm') + if (*e == 'm') { e++; - if (*e != 0) + } + if (*e != 0) { RETTOK(DNS_R_SYNTAX); + } /* * We don't just multiply out as we will overflow. */ @@ -336,28 +387,34 @@ getalt: goto encode; } m = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0 && *e != '.' && *e != 'm') + if (*e != 0 && *e != '.' && *e != 'm') { RETTOK(DNS_R_SYNTAX); - if (m < 0 || m > 90000000) + } + if (m < 0 || m > 90000000) { RETTOK(ISC_R_RANGE); + } cm = 0; if (*e == '.') { e++; for (i = 0; i < 2; i++) { - if (*e == 0 || *e == 'm') + if (*e == 0 || *e == 'm') { break; - if ((tmp = decvalue(*e++)) < 0) + } + if ((tmp = decvalue(*e++)) < 0) { RETTOK(DNS_R_SYNTAX); + } cm *= 10; cm += tmp; } for (; i < 2; i++) cm *= 10; } - if (*e == 'm') + if (*e == 'm') { e++; - if (*e != 0) + } + if (*e != 0) { RETTOK(DNS_R_SYNTAX); + } /* * We don't just multiply out as we will overflow. */ @@ -389,28 +446,34 @@ getalt: goto encode; } m = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0 && *e != '.' && *e != 'm') + if (*e != 0 && *e != '.' && *e != 'm') { RETTOK(DNS_R_SYNTAX); - if (m < 0 || m > 90000000) + } + if (m < 0 || m > 90000000) { RETTOK(ISC_R_RANGE); + } cm = 0; if (*e == '.') { e++; for (i = 0; i < 2; i++) { - if (*e == 0 || *e == 'm') + if (*e == 0 || *e == 'm') { break; - if ((tmp = decvalue(*e++)) < 0) + } + if ((tmp = decvalue(*e++)) < 0) { RETTOK(DNS_R_SYNTAX); + } cm *= 10; cm += tmp; } for (; i < 2; i++) cm *= 10; } - if (*e == 'm') + if (*e == 'm') { e++; - if (*e != 0) + } + if (*e != 0) { RETTOK(DNS_R_SYNTAX); + } /* * We don't just multiply out as we will overflow. */ @@ -436,16 +499,18 @@ encode: RETERR(mem_tobuffer(target, &size, 1)); RETERR(mem_tobuffer(target, &hp, 1)); RETERR(mem_tobuffer(target, &vp, 1)); - if (north) + if (north) { latitude = 0x80000000 + (d1 * 3600 + m1 * 60) * 1000 + s1; - else + } else { latitude = 0x80000000 - (d1 * 3600 + m1 * 60) * 1000 - s1; + } RETERR(uint32_tobuffer(latitude, target)); - if (east) + if (east) { longitude = 0x80000000 + (d2 * 3600 + m2 * 60) * 1000 + s2; - else + } else { longitude = 0x80000000 - (d2 * 3600 + m2 * 60) * 1000 - s2; + } RETERR(uint32_tobuffer(longitude, target)); return (uint32_tobuffer(altitude, target)); @@ -480,8 +545,9 @@ static inline isc_result_t totext_loc(ARGS_TOTEXT) dns_rdata_toregion(rdata, &sr); - if (sr.base[0] != 0) + if (sr.base[0] != 0) { return (ISC_R_NOTIMPLEMENTED); + } REQUIRE(rdata->length == 16); @@ -584,27 +650,30 @@ static inline isc_result_t fromwire_loc(ARGS_FROMWIRE) UNUSED(options); isc_buffer_activeregion(source, &sr); - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } if (sr.base[0] != 0) { /* Treat as unknown. */ isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); } - if (sr.length < 16) + if (sr.length < 16) { return (ISC_R_UNEXPECTEDEND); + } /* * Size. */ c = sr.base[1]; if (c != 0) { - if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) { + if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || + ((c >> 4) & 0xf) == 0) { return (ISC_R_RANGE); - /* - * Horizontal precision. - */ + /* + * Horizontal precision. + */ } } @@ -613,12 +682,13 @@ static inline isc_result_t fromwire_loc(ARGS_FROMWIRE) */ c = sr.base[2]; if (c != 0) { - if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) { + if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || + ((c >> 4) & 0xf) == 0) { return (ISC_R_RANGE); - /* - * Vertical precision. - */ + /* + * Vertical precision. + */ } } @@ -627,7 +697,8 @@ static inline isc_result_t fromwire_loc(ARGS_FROMWIRE) */ c = sr.base[3]; if (c != 0) { - if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) { + if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || + ((c >> 4) & 0xf) == 0) { return (ISC_R_RANGE); } } @@ -638,8 +709,9 @@ static inline isc_result_t fromwire_loc(ARGS_FROMWIRE) */ latitude = uint32_fromregion(&sr); if (latitude < (0x80000000UL - 90 * 3600000) || - latitude > (0x80000000UL + 90 * 3600000)) + latitude > (0x80000000UL + 90 * 3600000)) { return (ISC_R_RANGE); + } isc_region_consume(&sr, 4); /* @@ -647,8 +719,9 @@ static inline isc_result_t fromwire_loc(ARGS_FROMWIRE) */ longitude = uint32_fromregion(&sr); if (longitude < (0x80000000UL - 180 * 3600000) || - longitude > (0x80000000UL + 180 * 3600000)) + longitude > (0x80000000UL + 180 * 3600000)) { return (ISC_R_RANGE); + } /* * Altitude. @@ -699,33 +772,39 @@ static inline isc_result_t fromstruct_loc(ARGS_FROMSTRUCT) UNUSED(type); UNUSED(rdclass); - if (loc->v.v0.version != 0) + if (loc->v.v0.version != 0) { return (ISC_R_NOTIMPLEMENTED); + } RETERR(uint8_tobuffer(loc->v.v0.version, target)); c = loc->v.v0.size; - if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) + if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) { return (ISC_R_RANGE); + } RETERR(uint8_tobuffer(loc->v.v0.size, target)); c = loc->v.v0.horizontal; - if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) + if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) { return (ISC_R_RANGE); + } RETERR(uint8_tobuffer(loc->v.v0.horizontal, target)); c = loc->v.v0.vertical; - if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) + if ((c & 0xf) > 9 || ((c >> 4) & 0xf) > 9 || ((c >> 4) & 0xf) == 0) { return (ISC_R_RANGE); + } RETERR(uint8_tobuffer(loc->v.v0.vertical, target)); if (loc->v.v0.latitude < (0x80000000UL - 90 * 3600000) || - loc->v.v0.latitude > (0x80000000UL + 90 * 3600000)) + loc->v.v0.latitude > (0x80000000UL + 90 * 3600000)) { return (ISC_R_RANGE); + } RETERR(uint32_tobuffer(loc->v.v0.latitude, target)); if (loc->v.v0.longitude < (0x80000000UL - 180 * 3600000) || - loc->v.v0.longitude > (0x80000000UL + 180 * 3600000)) + loc->v.v0.longitude > (0x80000000UL + 180 * 3600000)) { return (ISC_R_RANGE); + } RETERR(uint32_tobuffer(loc->v.v0.longitude, target)); return (uint32_tobuffer(loc->v.v0.altitude, target)); } @@ -744,8 +823,9 @@ static inline isc_result_t tostruct_loc(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &r); version = uint8_fromregion(&r); - if (version != 0) + if (version != 0) { return (ISC_R_NOTIMPLEMENTED); + } loc->common.rdclass = rdata->rdclass; loc->common.rdtype = rdata->type; diff --git a/lib/dns/rdata/generic/lp_107.c b/lib/dns/rdata/generic/lp_107.c index 02ab3af7fd..df22c0ed26 100644 --- a/lib/dns/rdata/generic/lp_107.c +++ b/lib/dns/rdata/generic/lp_107.c @@ -32,8 +32,9 @@ static inline isc_result_t fromtext_lp(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, @@ -41,8 +42,9 @@ static inline isc_result_t fromtext_lp(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } return (dns_name_fromtext(&name, &buffer, origin, options, target)); } @@ -89,8 +91,9 @@ static inline isc_result_t fromwire_lp(ARGS_FROMWIRE) dns_name_init(&name, NULL); isc_buffer_activeregion(source, &sregion); - if (sregion.length < 2) + if (sregion.length < 2) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sregion.base, 2)); isc_buffer_forward(source, 2); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -173,8 +176,9 @@ static inline void freestruct_lp(ARGS_FREESTRUCT) REQUIRE(lp != NULL); REQUIRE(lp->common.rdtype == dns_rdatatype_lp); - if (lp->mctx == NULL) + if (lp->mctx == NULL) { return; + } dns_name_free(&lp->lp, lp->mctx); lp->mctx = NULL; @@ -195,8 +199,9 @@ static inline isc_result_t additionaldata_lp(ARGS_ADDLDATA) dns_name_fromregion(&name, ®ion); result = (add)(arg, &name, dns_rdatatype_l32); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return ((add)(arg, &name, dns_rdatatype_l64)); } @@ -247,8 +252,9 @@ static inline int casecompare_lp(ARGS_COMPARE) REQUIRE(rdata2->length != 0); order = memcmp(rdata1->data, rdata2->data, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); diff --git a/lib/dns/rdata/generic/mb_7.c b/lib/dns/rdata/generic/mb_7.c index f3d15bdbea..022607c295 100644 --- a/lib/dns/rdata/generic/mb_7.c +++ b/lib/dns/rdata/generic/mb_7.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_mb(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -162,8 +163,9 @@ static inline void freestruct_mb(ARGS_FREESTRUCT) REQUIRE(mb != NULL); - if (mb->mctx == NULL) + if (mb->mctx == NULL) { return; + } dns_name_free(&mb->mb, mb->mctx); mb->mctx = NULL; diff --git a/lib/dns/rdata/generic/md_3.c b/lib/dns/rdata/generic/md_3.c index 5540a53cfa..f48d7467bb 100644 --- a/lib/dns/rdata/generic/md_3.c +++ b/lib/dns/rdata/generic/md_3.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_md(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -163,8 +164,9 @@ static inline void freestruct_md(ARGS_FREESTRUCT) REQUIRE(md != NULL); REQUIRE(md->common.rdtype == dns_rdatatype_md); - if (md->mctx == NULL) + if (md->mctx == NULL) { return; + } dns_name_free(&md->md, md->mctx); md->mctx = NULL; diff --git a/lib/dns/rdata/generic/mf_4.c b/lib/dns/rdata/generic/mf_4.c index 973dd6c6ac..3d872d1072 100644 --- a/lib/dns/rdata/generic/mf_4.c +++ b/lib/dns/rdata/generic/mf_4.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_mf(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -163,8 +164,9 @@ static inline void freestruct_mf(ARGS_FREESTRUCT) REQUIRE(mf != NULL); REQUIRE(mf->common.rdtype == dns_rdatatype_mf); - if (mf->mctx == NULL) + if (mf->mctx == NULL) { return; + } dns_name_free(&mf->mf, mf->mctx); mf->mctx = NULL; } diff --git a/lib/dns/rdata/generic/mg_8.c b/lib/dns/rdata/generic/mg_8.c index bf110f822b..e21eb76b00 100644 --- a/lib/dns/rdata/generic/mg_8.c +++ b/lib/dns/rdata/generic/mg_8.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_mg(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -163,8 +164,9 @@ static inline void freestruct_mg(ARGS_FREESTRUCT) REQUIRE(mg != NULL); REQUIRE(mg->common.rdtype == dns_rdatatype_mg); - if (mg->mctx == NULL) + if (mg->mctx == NULL) { return; + } dns_name_free(&mg->mg, mg->mctx); mg->mctx = NULL; } diff --git a/lib/dns/rdata/generic/minfo_14.c b/lib/dns/rdata/generic/minfo_14.c index 404c96c239..92f59a0888 100644 --- a/lib/dns/rdata/generic/minfo_14.c +++ b/lib/dns/rdata/generic/minfo_14.c @@ -28,8 +28,9 @@ static inline isc_result_t fromtext_minfo(ARGS_FROMTEXT) UNUSED(rdclass); UNUSED(callbacks); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, @@ -39,12 +40,15 @@ static inline isc_result_t fromtext_minfo(ARGS_FROMTEXT) RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ismailbox(&name); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } } return (ISC_R_SUCCESS); } @@ -154,8 +158,9 @@ static inline int compare_minfo(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); @@ -214,14 +219,16 @@ static inline isc_result_t tostruct_minfo(ARGS_TOSTRUCT) dns_name_fromregion(&name, ®ion); dns_name_init(&minfo->emailbox, NULL); result = name_duporclone(&name, mctx, &minfo->emailbox); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } minfo->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&minfo->rmailbox, mctx); + } return (ISC_R_NOMEMORY); } @@ -232,8 +239,9 @@ static inline void freestruct_minfo(ARGS_FREESTRUCT) REQUIRE(minfo != NULL); REQUIRE(minfo->common.rdtype == dns_rdatatype_minfo); - if (minfo->mctx == NULL) + if (minfo->mctx == NULL) { return; + } dns_name_free(&minfo->rmailbox, minfo->mctx); dns_name_free(&minfo->emailbox, minfo->mctx); @@ -263,8 +271,9 @@ static inline isc_result_t digest_minfo(ARGS_DIGEST) dns_name_init(&name, NULL); dns_name_fromregion(&name, &r); result = dns_name_digest(&name, digest, arg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_region_consume(&r, name_length(&name)); dns_name_init(&name, NULL); dns_name_fromregion(&name, &r); @@ -297,15 +306,17 @@ static inline bool checknames_minfo(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ismailbox(&name)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } isc_region_consume(®ion, name_length(&name)); dns_name_fromregion(&name, ®ion); if (!dns_name_ismailbox(&name)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/mr_9.c b/lib/dns/rdata/generic/mr_9.c index b40ca164b1..30062c34da 100644 --- a/lib/dns/rdata/generic/mr_9.c +++ b/lib/dns/rdata/generic/mr_9.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_mr(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -163,8 +164,9 @@ static inline void freestruct_mr(ARGS_FREESTRUCT) REQUIRE(mr != NULL); REQUIRE(mr->common.rdtype == dns_rdatatype_mr); - if (mr->mctx == NULL) + if (mr->mctx == NULL) { return; + } dns_name_free(&mr->mr, mr->mctx); mr->mctx = NULL; } diff --git a/lib/dns/rdata/generic/mx_15.c b/lib/dns/rdata/generic/mx_15.c index 3fab359806..f0b5de8929 100644 --- a/lib/dns/rdata/generic/mx_15.c +++ b/lib/dns/rdata/generic/mx_15.c @@ -27,11 +27,13 @@ check_mx(isc_token_t *token) struct in_addr addr; struct in6_addr addr6; - if (strlcpy(tmp, DNS_AS_STR(*token), sizeof(tmp)) >= sizeof(tmp)) + if (strlcpy(tmp, DNS_AS_STR(*token), sizeof(tmp)) >= sizeof(tmp)) { return (true); + } - if (tmp[strlen(tmp) - 1] == '.') + if (tmp[strlen(tmp) - 1] == '.') { tmp[strlen(tmp) - 1] = '\0'; + } if (inet_pton(AF_INET, tmp, &addr) == 1 || inet_pton(AF_INET6, tmp, &addr6) == 1) { return (false); @@ -54,33 +56,41 @@ static inline isc_result_t fromtext_mx(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); ok = true; - if ((options & DNS_RDATA_CHECKMX) != 0) + if ((options & DNS_RDATA_CHECKMX) != 0) { ok = check_mx(&token); - if (!ok && (options & DNS_RDATA_CHECKMXFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKMXFAIL) != 0) { RETTOK(DNS_R_MXISADDRESS); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badmx(&token, lexer, callbacks); + } dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } return (ISC_R_SUCCESS); } @@ -127,8 +137,9 @@ static inline isc_result_t fromwire_mx(ARGS_FROMWIRE) dns_name_init(&name, NULL); isc_buffer_activeregion(source, &sregion); - if (sregion.length < 2) + if (sregion.length < 2) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sregion.base, 2)); isc_buffer_forward(source, 2); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -170,8 +181,9 @@ static inline int compare_mx(ARGS_COMPARE) REQUIRE(rdata2->length != 0); order = memcmp(rdata1->data, rdata2->data, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -238,8 +250,9 @@ static inline void freestruct_mx(ARGS_FREESTRUCT) REQUIRE(mx != NULL); REQUIRE(mx->common.rdtype == dns_rdatatype_mx); - if (mx->mctx == NULL) + if (mx->mctx == NULL) { return; + } dns_name_free(&mx->mx, mx->mctx); mx->mctx = NULL; @@ -265,18 +278,21 @@ static inline isc_result_t additionaldata_mx(ARGS_ADDLDATA) isc_region_consume(®ion, 2); dns_name_fromregion(&name, ®ion); - if (dns_name_equal(&name, dns_rootname)) + if (dns_name_equal(&name, dns_rootname)) { return (ISC_R_SUCCESS); + } result = (add)(arg, &name, dns_rdatatype_a); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_fixedname_init(&fixed); result = dns_name_concatenate(&port25, &name, dns_fixedname_name(&fixed), NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } return ((add)(arg, dns_fixedname_name(&fixed), dns_rdatatype_tlsa)); } @@ -322,8 +338,9 @@ static inline bool checknames_mx(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/naptr_35.c b/lib/dns/rdata/generic/naptr_35.c index b54f7f2ce2..025d6ba34c 100644 --- a/lib/dns/rdata/generic/naptr_35.c +++ b/lib/dns/rdata/generic/naptr_35.c @@ -36,8 +36,9 @@ txt_valid_regex(const unsigned char *txt) int n; len = *txt++; - if (len == 0U) + if (len == 0U) { return (ISC_R_SUCCESS); + } delim = *txt++; len--; @@ -65,16 +66,18 @@ txt_valid_regex(const unsigned char *txt) cp = regex; while (len-- > 0) { c = *txt++; - if (c == 0) + if (c == 0) { return (DNS_R_SYNTAX); + } if (c == delim && !replace) { replace = true; continue; } else if (c == delim && !flags) { flags = true; continue; - } else if (c == delim) + } else if (c == delim) { return (DNS_R_SYNTAX); + } /* * Flags are not escaped. */ @@ -86,66 +89,82 @@ txt_valid_regex(const unsigned char *txt) return (DNS_R_SYNTAX); } } - if (!replace) + if (!replace) { *cp++ = c; + } if (c == '\\') { - if (len == 0) + if (len == 0) { return (DNS_R_SYNTAX); + } c = *txt++; - if (c == 0) + if (c == 0) { return (DNS_R_SYNTAX); + } len--; - if (replace) + if (replace) { switch (c) { case '0': return (DNS_R_SYNTAX); case '1': - if (nsub < 1) + if (nsub < 1) { nsub = 1; + } break; case '2': - if (nsub < 2) + if (nsub < 2) { nsub = 2; + } break; case '3': - if (nsub < 3) + if (nsub < 3) { nsub = 3; + } break; case '4': - if (nsub < 4) + if (nsub < 4) { nsub = 4; + } break; case '5': - if (nsub < 5) + if (nsub < 5) { nsub = 5; + } break; case '6': - if (nsub < 6) + if (nsub < 6) { nsub = 6; + } break; case '7': - if (nsub < 7) + if (nsub < 7) { nsub = 7; + } break; case '8': - if (nsub < 8) + if (nsub < 8) { nsub = 8; + } break; case '9': - if (nsub < 9) + if (nsub < 9) { nsub = 9; + } break; } - if (!replace) + } + if (!replace) { *cp++ = c; + } } } - if (!flags) + if (!flags) { return (DNS_R_SYNTAX); + } *cp = '\0'; n = isc_regex_validate(regex); - if (n < 0 || nsub > (unsigned int)n) + if (n < 0 || nsub > (unsigned int)n) { return (DNS_R_SYNTAX); + } return (ISC_R_SUCCESS); } @@ -167,8 +186,9 @@ static inline isc_result_t fromtext_naptr(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -176,8 +196,9 @@ static inline isc_result_t fromtext_naptr(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -210,8 +231,9 @@ static inline isc_result_t fromtext_naptr(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -296,8 +318,9 @@ static inline isc_result_t fromwire_naptr(ARGS_FROMWIRE) * Order, preference. */ isc_buffer_activeregion(source, &sr); - if (sr.length < 4) + if (sr.length < 4) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, 4)); isc_buffer_forward(source, 4); @@ -388,8 +411,9 @@ static inline int compare_naptr(ARGS_COMPARE) * Order, preference. */ order = memcmp(region1.base, region2.base, 4); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } isc_region_consume(®ion1, 4); isc_region_consume(®ion2, 4); @@ -398,8 +422,9 @@ static inline int compare_naptr(ARGS_COMPARE) */ len = ISC_MIN(region1.base[0], region2.base[0]); order = memcmp(region1.base, region2.base, len + 1); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } isc_region_consume(®ion1, region1.base[0] + 1); isc_region_consume(®ion2, region2.base[0] + 1); @@ -408,8 +433,9 @@ static inline int compare_naptr(ARGS_COMPARE) */ len = ISC_MIN(region1.base[0], region2.base[0]); order = memcmp(region1.base, region2.base, len + 1); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } isc_region_consume(®ion1, region1.base[0] + 1); isc_region_consume(®ion2, region2.base[0] + 1); @@ -418,8 +444,9 @@ static inline int compare_naptr(ARGS_COMPARE) */ len = ISC_MIN(region1.base[0], region2.base[0]); order = memcmp(region1.base, region2.base, len + 1); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } isc_region_consume(®ion1, region1.base[0] + 1); isc_region_consume(®ion2, region2.base[0] + 1); @@ -494,42 +521,49 @@ static inline isc_result_t tostruct_naptr(ARGS_TOSTRUCT) isc_region_consume(&r, 1); INSIST(naptr->flags_len <= r.length); naptr->flags = mem_maybedup(mctx, r.base, naptr->flags_len); - if (naptr->flags == NULL) + if (naptr->flags == NULL) { goto cleanup; + } isc_region_consume(&r, naptr->flags_len); naptr->service_len = uint8_fromregion(&r); isc_region_consume(&r, 1); INSIST(naptr->service_len <= r.length); naptr->service = mem_maybedup(mctx, r.base, naptr->service_len); - if (naptr->service == NULL) + if (naptr->service == NULL) { goto cleanup; + } isc_region_consume(&r, naptr->service_len); naptr->regexp_len = uint8_fromregion(&r); isc_region_consume(&r, 1); INSIST(naptr->regexp_len <= r.length); naptr->regexp = mem_maybedup(mctx, r.base, naptr->regexp_len); - if (naptr->regexp == NULL) + if (naptr->regexp == NULL) { goto cleanup; + } isc_region_consume(&r, naptr->regexp_len); dns_name_init(&name, NULL); dns_name_fromregion(&name, &r); dns_name_init(&naptr->replacement, NULL); result = name_duporclone(&name, mctx, &naptr->replacement); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } naptr->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL && naptr->flags != NULL) + if (mctx != NULL && naptr->flags != NULL) { isc_mem_free(mctx, naptr->flags); - if (mctx != NULL && naptr->service != NULL) + } + if (mctx != NULL && naptr->service != NULL) { isc_mem_free(mctx, naptr->service); - if (mctx != NULL && naptr->regexp != NULL) + } + if (mctx != NULL && naptr->regexp != NULL) { isc_mem_free(mctx, naptr->regexp); + } return (ISC_R_NOMEMORY); } @@ -540,15 +574,19 @@ static inline void freestruct_naptr(ARGS_FREESTRUCT) REQUIRE(naptr != NULL); REQUIRE(naptr->common.rdtype == dns_rdatatype_naptr); - if (naptr->mctx == NULL) + if (naptr->mctx == NULL) { return; + } - if (naptr->flags != NULL) + if (naptr->flags != NULL) { isc_mem_free(naptr->mctx, naptr->flags); - if (naptr->service != NULL) + } + if (naptr->service != NULL) { isc_mem_free(naptr->mctx, naptr->service); - if (naptr->regexp != NULL) + } + if (naptr->regexp != NULL) { isc_mem_free(naptr->mctx, naptr->regexp); + } dns_name_free(&naptr->replacement, naptr->mctx); naptr->mctx = NULL; } @@ -604,8 +642,9 @@ static inline isc_result_t additionaldata_naptr(ARGS_ADDLDATA) dns_name_init(&name, offsets); dns_name_fromregion(&name, &sr); - if (atype != 0) + if (atype != 0) { return ((add)(arg, &name, atype)); + } return (ISC_R_SUCCESS); } @@ -655,8 +694,9 @@ static inline isc_result_t digest_naptr(ARGS_DIGEST) */ r1.length = length; result = (digest)(arg, &r1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Replacement. diff --git a/lib/dns/rdata/generic/nid_104.c b/lib/dns/rdata/generic/nid_104.c index 6153d61009..001bbc724e 100644 --- a/lib/dns/rdata/generic/nid_104.c +++ b/lib/dns/rdata/generic/nid_104.c @@ -33,15 +33,17 @@ static inline isc_result_t fromtext_nid(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (locator_pton(DNS_AS_STR(token), locator) != 1) + if (locator_pton(DNS_AS_STR(token), locator) != 1) { RETTOK(DNS_R_SYNTAX); + } return (mem_tobuffer(target, locator, NS_LOCATORSZ)); } @@ -84,8 +86,9 @@ static inline isc_result_t fromwire_nid(ARGS_FROMWIRE) UNUSED(dctx); isc_buffer_activeregion(source, &sregion); - if (sregion.length != 10) + if (sregion.length != 10) { return (DNS_R_FORMERR); + } isc_buffer_forward(source, sregion.length); return (mem_tobuffer(target, sregion.base, sregion.length)); } diff --git a/lib/dns/rdata/generic/ns_2.c b/lib/dns/rdata/generic/ns_2.c index b5858627d2..e74613be22 100644 --- a/lib/dns/rdata/generic/ns_2.c +++ b/lib/dns/rdata/generic/ns_2.c @@ -32,16 +32,20 @@ static inline isc_result_t fromtext_ns(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } return (ISC_R_SUCCESS); } @@ -170,8 +174,9 @@ static inline void freestruct_ns(ARGS_FREESTRUCT) REQUIRE(ns != NULL); - if (ns->mctx == NULL) + if (ns->mctx == NULL) { return; + } dns_name_free(&ns->name, ns->mctx); ns->mctx = NULL; @@ -231,8 +236,9 @@ static inline bool checknames_ns(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/nsec3_50.c b/lib/dns/rdata/generic/nsec3_50.c index 2c3ea332a6..71aa3e04ed 100644 --- a/lib/dns/rdata/generic/nsec3_50.c +++ b/lib/dns/rdata/generic/nsec3_50.c @@ -61,22 +61,25 @@ static inline isc_result_t fromtext_nsec3(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); flags = token.value.as_ulong; - if (flags > 255U) + if (flags > 255U) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(flags, target)); /* Iterations. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* salt */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (token.value.as_textregion.length > (255 * 2)) + if (token.value.as_textregion.length > (255 * 2)) { RETTOK(DNS_R_TEXTTOOLONG); + } if (strcmp(DNS_AS_STR(token), "-") == 0) { RETERR(uint8_tobuffer(0, target)); } else { @@ -91,8 +94,9 @@ static inline isc_result_t fromtext_nsec3(ARGS_FROMTEXT) false)); isc_buffer_init(&b, buf, sizeof(buf)); RETTOK(isc_base32hexnp_decodestring(DNS_AS_STR(token), &b)); - if (isc_buffer_usedlength(&b) > 0xffU) + if (isc_buffer_usedlength(&b) > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(isc_buffer_usedlength(&b), target)); RETERR(mem_tobuffer(target, &buf, isc_buffer_usedlength(&b))); @@ -141,11 +145,13 @@ static inline isc_result_t totext_nsec3(ARGS_TOTEXT) sr.length = j; RETERR(isc_hex_totext(&sr, 1, "", target)); sr.length = i - j; - } else + } else { RETERR(str_totext("-", target)); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); /* Next hash */ @@ -166,8 +172,9 @@ static inline isc_result_t totext_nsec3(ARGS_TOTEXT) } RETERR(typemap_totext(&sr, tctx, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -188,22 +195,26 @@ static inline isc_result_t fromwire_nsec3(ARGS_FROMWIRE) rr = sr; /* hash(1), flags(1), iteration(2), saltlen(1) */ - if (sr.length < 5U) + if (sr.length < 5U) { RETERR(DNS_R_FORMERR); + } saltlen = sr.base[4]; isc_region_consume(&sr, 5); - if (sr.length < saltlen) + if (sr.length < saltlen) { RETERR(DNS_R_FORMERR); + } isc_region_consume(&sr, saltlen); - if (sr.length < 1U) + if (sr.length < 1U) { RETERR(DNS_R_FORMERR); + } hashlen = sr.base[0]; isc_region_consume(&sr, 1); - if (sr.length < hashlen) + if (sr.length < hashlen) { RETERR(DNS_R_FORMERR); + } isc_region_consume(&sr, hashlen); RETERR(typemap_test(&sr, true)); @@ -292,27 +303,31 @@ static inline isc_result_t tostruct_nsec3(ARGS_TOSTRUCT) nsec3->salt_length = uint8_consume_fromregion(®ion); nsec3->salt = mem_maybedup(mctx, region.base, nsec3->salt_length); - if (nsec3->salt == NULL) + if (nsec3->salt == NULL) { return (ISC_R_NOMEMORY); + } isc_region_consume(®ion, nsec3->salt_length); nsec3->next_length = uint8_consume_fromregion(®ion); nsec3->next = mem_maybedup(mctx, region.base, nsec3->next_length); - if (nsec3->next == NULL) + if (nsec3->next == NULL) { goto cleanup; + } isc_region_consume(®ion, nsec3->next_length); nsec3->len = region.length; nsec3->typebits = mem_maybedup(mctx, region.base, region.length); - if (nsec3->typebits == NULL) + if (nsec3->typebits == NULL) { goto cleanup; + } nsec3->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (nsec3->next != NULL) + if (nsec3->next != NULL) { isc_mem_free(mctx, nsec3->next); + } isc_mem_free(mctx, nsec3->salt); return (ISC_R_NOMEMORY); } @@ -324,15 +339,19 @@ static inline void freestruct_nsec3(ARGS_FREESTRUCT) REQUIRE(nsec3 != NULL); REQUIRE(nsec3->common.rdtype == dns_rdatatype_nsec3); - if (nsec3->mctx == NULL) + if (nsec3->mctx == NULL) { return; + } - if (nsec3->salt != NULL) + if (nsec3->salt != NULL) { isc_mem_free(nsec3->mctx, nsec3->salt); - if (nsec3->next != NULL) + } + if (nsec3->next != NULL) { isc_mem_free(nsec3->mctx, nsec3->next); - if (nsec3->typebits != NULL) + } + if (nsec3->typebits != NULL) { isc_mem_free(nsec3->mctx, nsec3->typebits); + } nsec3->mctx = NULL; } @@ -375,8 +394,9 @@ static inline bool checkowner_nsec3(ARGS_CHECKOWNER) dns_name_getlabel(name, 0, &label); isc_region_consume(&label, 1); isc_buffer_init(&buffer, owner, sizeof(owner)); - if (isc_base32hexnp_decoderegion(&label, &buffer) == ISC_R_SUCCESS) + if (isc_base32hexnp_decoderegion(&label, &buffer) == ISC_R_SUCCESS) { return (true); + } return (false); } diff --git a/lib/dns/rdata/generic/nsec3param_51.c b/lib/dns/rdata/generic/nsec3param_51.c index 40b1ffb533..c9361abf9a 100644 --- a/lib/dns/rdata/generic/nsec3param_51.c +++ b/lib/dns/rdata/generic/nsec3param_51.c @@ -59,22 +59,25 @@ static inline isc_result_t fromtext_nsec3param(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); flags = token.value.as_ulong; - if (flags > 255U) + if (flags > 255U) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(flags, target)); /* Iterations. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* Salt. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (token.value.as_textregion.length > (255 * 2)) + if (token.value.as_textregion.length > (255 * 2)) { RETTOK(DNS_R_TEXTTOOLONG); + } if (strcmp(DNS_AS_STR(token), "-") == 0) { RETERR(uint8_tobuffer(0, target)); } else { @@ -128,8 +131,9 @@ static inline isc_result_t totext_nsec3param(ARGS_TOTEXT) sr.length = j; RETERR(isc_hex_totext(&sr, 1, "", target)); sr.length = i - j; - } else + } else { RETERR(str_totext("-", target)); + } return (ISC_R_SUCCESS); } @@ -150,13 +154,15 @@ static inline isc_result_t fromwire_nsec3param(ARGS_FROMWIRE) rr = sr; /* hash(1), flags(1), iterations(2), saltlen(1) */ - if (sr.length < 5U) + if (sr.length < 5U) { RETERR(DNS_R_FORMERR); + } saltlen = sr.base[4]; isc_region_consume(&sr, 5); - if (sr.length < saltlen) + if (sr.length < saltlen) { RETERR(DNS_R_FORMERR); + } isc_region_consume(&sr, saltlen); RETERR(mem_tobuffer(target, rr.base, rr.length)); isc_buffer_forward(source, rr.length); @@ -234,8 +240,9 @@ static inline isc_result_t tostruct_nsec3param(ARGS_TOSTRUCT) nsec3param->salt_length = uint8_consume_fromregion(®ion); nsec3param->salt = mem_maybedup(mctx, region.base, nsec3param->salt_length); - if (nsec3param->salt == NULL) + if (nsec3param->salt == NULL) { return (ISC_R_NOMEMORY); + } isc_region_consume(®ion, nsec3param->salt_length); nsec3param->mctx = mctx; @@ -249,11 +256,13 @@ static inline void freestruct_nsec3param(ARGS_FREESTRUCT) REQUIRE(nsec3param != NULL); REQUIRE(nsec3param->common.rdtype == dns_rdatatype_nsec3param); - if (nsec3param->mctx == NULL) + if (nsec3param->mctx == NULL) { return; + } - if (nsec3param->salt != NULL) + if (nsec3param->salt != NULL) { isc_mem_free(nsec3param->mctx, nsec3param->salt); + } nsec3param->mctx = NULL; } diff --git a/lib/dns/rdata/generic/nsec_47.c b/lib/dns/rdata/generic/nsec_47.c index cb342ea0d0..d51c91ad21 100644 --- a/lib/dns/rdata/generic/nsec_47.c +++ b/lib/dns/rdata/generic/nsec_47.c @@ -41,8 +41,9 @@ static inline isc_result_t fromtext_nsec(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (typemap_fromtext(lexer, target, false)); @@ -175,15 +176,17 @@ static inline isc_result_t tostruct_nsec(ARGS_TOSTRUCT) nsec->len = region.length; nsec->typebits = mem_maybedup(mctx, region.base, region.length); - if (nsec->typebits == NULL) + if (nsec->typebits == NULL) { goto cleanup; + } nsec->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&nsec->next, mctx); + } return (ISC_R_NOMEMORY); } @@ -194,12 +197,14 @@ static inline void freestruct_nsec(ARGS_FREESTRUCT) REQUIRE(nsec != NULL); REQUIRE(nsec->common.rdtype == dns_rdatatype_nsec); - if (nsec->mctx == NULL) + if (nsec->mctx == NULL) { return; + } dns_name_free(&nsec->next, nsec->mctx); - if (nsec->typebits != NULL) + if (nsec->typebits != NULL) { isc_mem_free(nsec->mctx, nsec->typebits); + } nsec->mctx = NULL; } @@ -271,8 +276,9 @@ static inline int casecompare_nsec(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); diff --git a/lib/dns/rdata/generic/null_10.c b/lib/dns/rdata/generic/null_10.c index 8fd6863db6..e26882ca2c 100644 --- a/lib/dns/rdata/generic/null_10.c +++ b/lib/dns/rdata/generic/null_10.c @@ -106,8 +106,9 @@ static inline isc_result_t tostruct_null(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &r); null->length = r.length; null->data = mem_maybedup(mctx, r.base, r.length); - if (null->data == NULL) + if (null->data == NULL) { return (ISC_R_NOMEMORY); + } null->mctx = mctx; return (ISC_R_SUCCESS); @@ -120,11 +121,13 @@ static inline void freestruct_null(ARGS_FREESTRUCT) REQUIRE(null != NULL); REQUIRE(null->common.rdtype == dns_rdatatype_null); - if (null->mctx == NULL) + if (null->mctx == NULL) { return; + } - if (null->data != NULL) + if (null->data != NULL) { isc_mem_free(null->mctx, null->data); + } null->mctx = NULL; } diff --git a/lib/dns/rdata/generic/nxt_30.c b/lib/dns/rdata/generic/nxt_30.c index 731bba2505..9ac4684127 100644 --- a/lib/dns/rdata/generic/nxt_30.c +++ b/lib/dns/rdata/generic/nxt_30.c @@ -45,36 +45,42 @@ static inline isc_result_t fromtext_nxt(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); memset(bm, 0, sizeof(bm)); do { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, true)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { break; + } n = strtol(DNS_AS_STR(token), &e, 10); if (e != DNS_AS_STR(token) && *e == '\0') { covered = (dns_rdatatype_t)n; } else if (dns_rdatatype_fromtext(&covered, &token.value.as_textregion) == - DNS_R_UNKNOWN) + DNS_R_UNKNOWN) { RETTOK(DNS_R_UNKNOWN); + } /* * NXT is only specified for types 1..127. */ - if (covered < 1 || covered > 127) + if (covered < 1 || covered > 127) { return (ISC_R_RANGE); - if (first || covered > maxcovered) + } + if (first || covered > maxcovered) { maxcovered = covered; + } first = false; bm[covered / 8] |= (0x80 >> (covered % 8)); } while (1); isc_lex_ungettoken(lexer, &token); - if (first) + if (first) { return (ISC_R_SUCCESS); + } n = (maxcovered + 8) / 8; return (mem_tobuffer(target, bm, n)); } @@ -99,19 +105,24 @@ static inline isc_result_t totext_nxt(ARGS_TOTEXT) RETERR(dns_name_totext(&prefix, sub, target)); for (i = 0; i < sr.length; i++) { - if (sr.base[i] != 0) + if (sr.base[i] != 0) { for (j = 0; j < 8; j++) { if ((sr.base[i] & (0x80 >> j)) != 0) { { dns_rdatatype_t t = i * 8 + j; RETERR(str_totext(" ", target)); if (dns_rdatatype_isknown(t)) { - RETERR(dns_rdatatype_totext(t, target)); - }else { - char buf[sizeof("65535")]; - snprintf(buf, sizeof(buf), - "%u", t); - RETERR(str_totext(buf, target)); + RETERR(dns_rdatatype_totext( + t, target)); + } else { + char buf[sizeof("6553" + "5")]; + snprintf(buf, + sizeof(buf), + "%u", t); + RETERR(str_totext( + buf, target)); + } } } } @@ -137,8 +148,9 @@ static inline isc_result_t fromwire_nxt(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sr); if (sr.length > 0 && (sr.base[0] & 0x80) == 0 && - ((sr.length > 16) || sr.base[sr.length - 1] == 0)) + ((sr.length > 16) || sr.base[sr.length - 1] == 0)) { return (DNS_R_BADBITMAP); + } RETERR(mem_tobuffer(target, sr.base, sr.length)); isc_buffer_forward(source, sr.length); return (ISC_R_SUCCESS); @@ -184,8 +196,9 @@ static inline int compare_nxt(ARGS_COMPARE) dns_name_fromregion(&name1, &r1); dns_name_fromregion(&name2, &r2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(&r1, name_length(&name1)); isc_region_consume(&r2, name_length(&name2)); @@ -240,15 +253,17 @@ static inline isc_result_t tostruct_nxt(ARGS_TOSTRUCT) nxt->len = region.length; nxt->typebits = mem_maybedup(mctx, region.base, region.length); - if (nxt->typebits == NULL) + if (nxt->typebits == NULL) { goto cleanup; + } nxt->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&nxt->next, mctx); + } return (ISC_R_NOMEMORY); } @@ -259,12 +274,14 @@ static inline void freestruct_nxt(ARGS_FREESTRUCT) REQUIRE(nxt != NULL); REQUIRE(nxt->common.rdtype == dns_rdatatype_nxt); - if (nxt->mctx == NULL) + if (nxt->mctx == NULL) { return; + } dns_name_free(&nxt->next, nxt->mctx); - if (nxt->typebits != NULL) + if (nxt->typebits != NULL) { isc_mem_free(nxt->mctx, nxt->typebits); + } nxt->mctx = NULL; } @@ -291,8 +308,9 @@ static inline isc_result_t digest_nxt(ARGS_DIGEST) dns_name_init(&name, NULL); dns_name_fromregion(&name, &r); result = dns_name_digest(&name, digest, arg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_region_consume(&r, name_length(&name)); return ((digest)(arg, &r)); diff --git a/lib/dns/rdata/generic/openpgpkey_61.c b/lib/dns/rdata/generic/openpgpkey_61.c index 1e78e04059..3ffca3667d 100644 --- a/lib/dns/rdata/generic/openpgpkey_61.c +++ b/lib/dns/rdata/generic/openpgpkey_61.c @@ -42,20 +42,24 @@ static inline isc_result_t totext_openpgpkey(ARGS_TOTEXT) /* * Keyring */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext("( ", target)); + } if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - } else + } + } else { RETERR(str_totext("[omitted]", target)); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -75,8 +79,9 @@ static inline isc_result_t fromwire_openpgpkey(ARGS_FROMWIRE) * Keyring. */ isc_buffer_activeregion(source, &sr); - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); } @@ -149,8 +154,9 @@ static inline isc_result_t tostruct_openpgpkey(ARGS_TOSTRUCT) */ sig->length = sr.length; sig->keyring = mem_maybedup(mctx, sr.base, sig->length); - if (sig->keyring == NULL) + if (sig->keyring == NULL) { goto cleanup; + } sig->mctx = mctx; return (ISC_R_SUCCESS); @@ -166,11 +172,13 @@ static inline void freestruct_openpgpkey(ARGS_FREESTRUCT) REQUIRE(sig != NULL); REQUIRE(sig->common.rdtype == dns_rdatatype_openpgpkey); - if (sig->mctx == NULL) + if (sig->mctx == NULL) { return; + } - if (sig->keyring != NULL) + if (sig->keyring != NULL) { isc_mem_free(sig->mctx, sig->keyring); + } sig->mctx = NULL; } diff --git a/lib/dns/rdata/generic/opt_41.c b/lib/dns/rdata/generic/opt_41.c index 20afb44c2c..38e1d098f0 100644 --- a/lib/dns/rdata/generic/opt_41.c +++ b/lib/dns/rdata/generic/opt_41.c @@ -61,23 +61,27 @@ static inline isc_result_t totext_opt(ARGS_TOTEXT) RETERR(str_totext(buf, target)); INSIST(r.length >= length); if (length > 0) { - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); or = r; or.length = length; - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(& or, 60, "", target)); - else + } else { RETERR(isc_base64_totext(& or, tctx->width - 2, tctx->linebreak, target)); + } isc_region_consume(&r, length); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } } - if (r.length > 0) + if (r.length > 0) { RETERR(str_totext(" ", target)); + } } return (ISC_R_SUCCESS); @@ -203,7 +207,7 @@ static inline isc_result_t fromwire_opt(ARGS_FROMWIRE) isc_region_consume(&sregion, length); break; case DNS_OPT_CLIENT_TAG: - /* FALLTHROUGH */ + /* FALLTHROUGH */ case DNS_OPT_SERVER_TAG: if (length != 2) { return (DNS_R_OPTERR); @@ -273,12 +277,14 @@ static inline isc_result_t fromstruct_opt(ARGS_FROMSTRUCT) isc_region_consume(®ion, 2); /* opt */ length = uint16_fromregion(®ion); isc_region_consume(®ion, 2); - if (region.length < length) + if (region.length < length) { return (ISC_R_UNEXPECTEDEND); + } isc_region_consume(®ion, length); } - if (region.length != 0) + if (region.length != 0) { return (ISC_R_UNEXPECTEDEND); + } return (mem_tobuffer(target, opt->options, opt->length)); } @@ -298,8 +304,9 @@ static inline isc_result_t tostruct_opt(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &r); opt->length = r.length; opt->options = mem_maybedup(mctx, r.base, r.length); - if (opt->options == NULL) + if (opt->options == NULL) { return (ISC_R_NOMEMORY); + } opt->offset = 0; opt->mctx = mctx; @@ -313,11 +320,13 @@ static inline void freestruct_opt(ARGS_FREESTRUCT) REQUIRE(opt != NULL); REQUIRE(opt->common.rdtype == dns_rdatatype_opt); - if (opt->mctx == NULL) + if (opt->mctx == NULL) { return; + } - if (opt->options != NULL) + if (opt->options != NULL) { isc_mem_free(opt->mctx, opt->options); + } opt->mctx = NULL; } @@ -381,8 +390,9 @@ dns_rdata_opt_first(dns_rdata_opt_t *opt) REQUIRE(opt->common.rdtype == dns_rdatatype_opt); REQUIRE(opt->options != NULL || opt->length == 0); - if (opt->length == 0) + if (opt->length == 0) { return (ISC_R_NOMORE); + } opt->offset = 0; return (ISC_R_SUCCESS); @@ -405,8 +415,9 @@ dns_rdata_opt_next(dns_rdata_opt_t *opt) length = uint16_fromregion(&r); INSIST(opt->offset + 4 + length <= opt->length); opt->offset = opt->offset + 4 + length; - if (opt->offset == opt->length) + if (opt->offset == opt->length) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/rdata/generic/ptr_12.c b/lib/dns/rdata/generic/ptr_12.c index fad4776bba..d36fe0e578 100644 --- a/lib/dns/rdata/generic/ptr_12.c +++ b/lib/dns/rdata/generic/ptr_12.c @@ -31,18 +31,21 @@ static inline isc_result_t fromtext_ptr(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); if (rdclass == dns_rdataclass_in && (options & DNS_RDATA_CHECKNAMES) != 0 && (options & DNS_RDATA_CHECKREVERSE) != 0) { bool ok; ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } } return (ISC_R_SUCCESS); } @@ -173,8 +176,9 @@ static inline void freestruct_ptr(ARGS_FREESTRUCT) REQUIRE(ptr != NULL); REQUIRE(ptr->common.rdtype == dns_rdatatype_ptr); - if (ptr->mctx == NULL) + if (ptr->mctx == NULL) { return; + } dns_name_free(&ptr->ptr, ptr->mctx); ptr->mctx = NULL; @@ -239,11 +243,13 @@ static inline bool checknames_ptr(ARGS_CHECKNAMES) REQUIRE(rdata->type == dns_rdatatype_ptr); - if (rdata->rdclass != dns_rdataclass_in) + if (rdata->rdclass != dns_rdataclass_in) { return (true); + } - if (dns_name_isdnssd(owner)) + if (dns_name_isdnssd(owner)) { return (true); + } if (dns_name_issubdomain(owner, &in_addr_arpa) || dns_name_issubdomain(owner, &ip6_arpa) || @@ -252,8 +258,9 @@ static inline bool checknames_ptr(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } } diff --git a/lib/dns/rdata/generic/rp_17.c b/lib/dns/rdata/generic/rp_17.c index e1125472d5..9141f83ab2 100644 --- a/lib/dns/rdata/generic/rp_17.c +++ b/lib/dns/rdata/generic/rp_17.c @@ -30,8 +30,9 @@ static inline isc_result_t fromtext_rp(ARGS_FROMTEXT) UNUSED(rdclass); UNUSED(callbacks); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, @@ -41,12 +42,15 @@ static inline isc_result_t fromtext_rp(ARGS_FROMTEXT) RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0 && i == 0) { ok = dns_name_ismailbox(&name); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } } return (ISC_R_SUCCESS); } @@ -154,8 +158,9 @@ static inline int compare_rp(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); @@ -212,15 +217,17 @@ static inline isc_result_t tostruct_rp(ARGS_TOSTRUCT) dns_name_fromregion(&name, ®ion); dns_name_init(&rp->text, NULL); result = name_duporclone(&name, mctx, &rp->text); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } rp->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&rp->mail, mctx); + } return (ISC_R_NOMEMORY); } @@ -231,8 +238,9 @@ static inline void freestruct_rp(ARGS_FREESTRUCT) REQUIRE(rp != NULL); REQUIRE(rp->common.rdtype == dns_rdatatype_rp); - if (rp->mctx == NULL) + if (rp->mctx == NULL) { return; + } dns_name_free(&rp->mail, rp->mctx); dns_name_free(&rp->text, rp->mctx); @@ -295,8 +303,9 @@ static inline bool checknames_rp(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ismailbox(&name)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/rrsig_46.c b/lib/dns/rdata/generic/rrsig_46.c index fb7f1815d9..581dff721b 100644 --- a/lib/dns/rdata/generic/rrsig_46.c +++ b/lib/dns/rdata/generic/rrsig_46.c @@ -44,10 +44,12 @@ static inline isc_result_t fromtext_rrsig(ARGS_FROMTEXT) result = dns_rdatatype_fromtext(&covered, &token.value.as_textregion); if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) { i = strtol(DNS_AS_STR(token), &e, 10); - if (i < 0 || i > 65535) + if (i < 0 || i > 65535) { RETTOK(ISC_R_RANGE); - if (*e != 0) + } + if (*e != 0) { RETTOK(result); + } covered = (dns_rdatatype_t)i; } RETERR(uint16_tobuffer(covered, target)); @@ -65,8 +67,9 @@ static inline isc_result_t fromtext_rrsig(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } c = (unsigned char)token.value.as_ulong; RETERR(mem_tobuffer(target, &c, 1)); @@ -89,13 +92,16 @@ static inline isc_result_t fromtext_rrsig(ARGS_FROMTEXT) uint64_t u64; u64 = u = strtoul(DNS_AS_STR(token), &end, 10); - if (u == ULONG_MAX || *end != 0) + if (u == ULONG_MAX || *end != 0) { RETTOK(DNS_R_SYNTAX); - if (u64 > 0xffffffffUL) + } + if (u64 > 0xffffffffUL) { RETTOK(ISC_R_RANGE); + } time_expire = u; - } else + } else { RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_expire)); + } RETERR(uint32_tobuffer(time_expire, target)); /* @@ -110,13 +116,16 @@ static inline isc_result_t fromtext_rrsig(ARGS_FROMTEXT) uint64_t u64; u64 = u = strtoul(DNS_AS_STR(token), &end, 10); - if (u == ULONG_MAX || *end != 0) + if (u == ULONG_MAX || *end != 0) { RETTOK(DNS_R_SYNTAX); - if (u64 > 0xffffffffUL) + } + if (u64 > 0xffffffffUL) { RETTOK(ISC_R_RANGE); + } time_signed = u; - } else + } else { RETTOK(dns_time32_fromtext(DNS_AS_STR(token), &time_signed)); + } RETERR(uint32_tobuffer(time_signed, target)); /* @@ -133,8 +142,9 @@ static inline isc_result_t fromtext_rrsig(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); /* @@ -200,8 +210,9 @@ static inline isc_result_t totext_rrsig(ARGS_TOTEXT) snprintf(buf, sizeof(buf), "%lu", ttl); RETERR(str_totext(buf, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); /* @@ -242,16 +253,19 @@ static inline isc_result_t totext_rrsig(ARGS_TOTEXT) */ RETERR(str_totext(tctx->linebreak, target)); if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - } else + } + } else { RETERR(str_totext("[omitted]", target)); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -278,8 +292,9 @@ static inline isc_result_t fromwire_rrsig(ARGS_FROMWIRE) * time signed: 4 * key footprint: 2 */ - if (sr.length < 18) + if (sr.length < 18) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, 18); RETERR(mem_tobuffer(target, sr.base, 18)); @@ -479,15 +494,17 @@ static inline isc_result_t tostruct_rrsig(ARGS_TOSTRUCT) */ sig->siglen = sr.length; sig->signature = mem_maybedup(mctx, sr.base, sig->siglen); - if (sig->signature == NULL) + if (sig->signature == NULL) { goto cleanup; + } sig->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&sig->signer, mctx); + } return (ISC_R_NOMEMORY); } @@ -498,12 +515,14 @@ static inline void freestruct_rrsig(ARGS_FREESTRUCT) REQUIRE(sig != NULL); REQUIRE(sig->common.rdtype == dns_rdatatype_rrsig); - if (sig->mctx == NULL) + if (sig->mctx == NULL) { return; + } dns_name_free(&sig->signer, sig->mctx); - if (sig->signature != NULL) + if (sig->signature != NULL) { isc_mem_free(sig->mctx, sig->signature); + } sig->mctx = NULL; } @@ -588,8 +607,9 @@ static inline int casecompare_rrsig(ARGS_COMPARE) r1.length = 18; r2.length = 18; order = isc_region_compare(&r1, &r2); - if (order != 0) + if (order != 0) { return (order); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -600,8 +620,9 @@ static inline int casecompare_rrsig(ARGS_COMPARE) dns_name_fromregion(&name1, &r1); dns_name_fromregion(&name2, &r2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(&r1, name_length(&name1)); isc_region_consume(&r2, name_length(&name2)); diff --git a/lib/dns/rdata/generic/rt_21.c b/lib/dns/rdata/generic/rt_21.c index c235343875..a00b867dae 100644 --- a/lib/dns/rdata/generic/rt_21.c +++ b/lib/dns/rdata/generic/rt_21.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_rt(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, @@ -40,16 +41,20 @@ static inline isc_result_t fromtext_rt(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } return (ISC_R_SUCCESS); } @@ -96,10 +101,12 @@ static inline isc_result_t fromwire_rt(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sregion); isc_buffer_availableregion(target, &tregion); - if (tregion.length < 2) + if (tregion.length < 2) { return (ISC_R_NOSPACE); - if (sregion.length < 2) + } + if (sregion.length < 2) { return (ISC_R_UNEXPECTEDEND); + } memmove(tregion.base, sregion.base, 2); isc_buffer_forward(source, 2); isc_buffer_add(target, 2); @@ -119,8 +126,9 @@ static inline isc_result_t towire_rt(ARGS_TOWIRE) dns_compress_setmethods(cctx, DNS_COMPRESS_NONE); isc_buffer_availableregion(target, &tr); dns_rdata_toregion(rdata, ®ion); - if (tr.length < 2) + if (tr.length < 2) { return (ISC_R_NOSPACE); + } memmove(tr.base, region.base, 2); isc_region_consume(®ion, 2); isc_buffer_add(target, 2); @@ -146,8 +154,9 @@ static inline int compare_rt(ARGS_COMPARE) REQUIRE(rdata2->length != 0); order = memcmp(rdata1->data, rdata2->data, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -215,8 +224,9 @@ static inline void freestruct_rt(ARGS_FREESTRUCT) REQUIRE(rt != NULL); REQUIRE(rt->common.rdtype == dns_rdatatype_rt); - if (rt->mctx == NULL) + if (rt->mctx == NULL) { return; + } dns_name_free(&rt->host, rt->mctx); rt->mctx = NULL; @@ -237,11 +247,13 @@ static inline isc_result_t additionaldata_rt(ARGS_ADDLDATA) dns_name_fromregion(&name, ®ion); result = (add)(arg, &name, dns_rdatatype_x25); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = (add)(arg, &name, dns_rdatatype_isdn); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return ((add)(arg, &name, dns_rdatatype_a)); } @@ -258,8 +270,9 @@ static inline isc_result_t digest_rt(ARGS_DIGEST) isc_region_consume(&r2, 2); r1.length = 2; result = (digest)(arg, &r1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_init(&name, NULL); dns_name_fromregion(&name, &r2); return (dns_name_digest(&name, digest, arg)); @@ -291,8 +304,9 @@ static inline bool checknames_rt(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/sig_24.c b/lib/dns/rdata/generic/sig_24.c index f3b897e28d..4f46f73191 100644 --- a/lib/dns/rdata/generic/sig_24.c +++ b/lib/dns/rdata/generic/sig_24.c @@ -42,10 +42,12 @@ static inline isc_result_t fromtext_sig(ARGS_FROMTEXT) result = dns_rdatatype_fromtext(&covered, &token.value.as_textregion); if (result != ISC_R_SUCCESS && result != ISC_R_NOTIMPLEMENTED) { i = strtol(DNS_AS_STR(token), &e, 10); - if (i < 0 || i > 65535) + if (i < 0 || i > 65535) { RETTOK(ISC_R_RANGE); - if (*e != 0) + } + if (*e != 0) { RETTOK(result); + } covered = (dns_rdatatype_t)i; } RETERR(uint16_tobuffer(covered, target)); @@ -63,8 +65,9 @@ static inline isc_result_t fromtext_sig(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } c = (unsigned char)token.value.as_ulong; RETERR(mem_tobuffer(target, &c, 1)); @@ -105,8 +108,9 @@ static inline isc_result_t fromtext_sig(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); /* @@ -182,8 +186,9 @@ static inline isc_result_t totext_sig(ARGS_TOTEXT) isc_region_consume(&sr, 4); RETERR(dns_time32_totext(exp, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); /* @@ -217,13 +222,15 @@ static inline isc_result_t totext_sig(ARGS_TOTEXT) * Sig. */ RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -250,8 +257,9 @@ static inline isc_result_t fromwire_sig(ARGS_FROMWIRE) * time signed: 4 * key footprint: 2 */ - if (sr.length < 18) + if (sr.length < 18) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, 18); RETERR(mem_tobuffer(target, sr.base, 18)); @@ -329,8 +337,9 @@ static inline int compare_sig(ARGS_COMPARE) r1.length = 18; r2.length = 18; order = isc_region_compare(&r1, &r2); - if (order != 0) + if (order != 0) { return (order); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -341,8 +350,9 @@ static inline int compare_sig(ARGS_COMPARE) dns_name_fromregion(&name1, &r1); dns_name_fromregion(&name2, &r2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(&r1, name_length(&name1)); isc_region_consume(&r2, name_length(&name2)); @@ -478,15 +488,17 @@ static inline isc_result_t tostruct_sig(ARGS_TOSTRUCT) */ sig->siglen = sr.length; sig->signature = mem_maybedup(mctx, sr.base, sig->siglen); - if (sig->signature == NULL) + if (sig->signature == NULL) { goto cleanup; + } sig->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&sig->signer, mctx); + } return (ISC_R_NOMEMORY); } @@ -497,12 +509,14 @@ static inline void freestruct_sig(ARGS_FREESTRUCT) REQUIRE(sig != NULL); REQUIRE(sig->common.rdtype == dns_rdatatype_sig); - if (sig->mctx == NULL) + if (sig->mctx == NULL) { return; + } dns_name_free(&sig->signer, sig->mctx); - if (sig->signature != NULL) + if (sig->signature != NULL) { isc_mem_free(sig->mctx, sig->signature); + } sig->mctx = NULL; } diff --git a/lib/dns/rdata/generic/sink_40.c b/lib/dns/rdata/generic/sink_40.c index 85392e1fda..88b8b5c24a 100644 --- a/lib/dns/rdata/generic/sink_40.c +++ b/lib/dns/rdata/generic/sink_40.c @@ -31,22 +31,25 @@ static inline isc_result_t fromtext_sink(ARGS_FROMTEXT) /* meaning */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* coding */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* subcoding */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); return (isc_base64_tobuffer(lexer, target, -1)); @@ -73,23 +76,27 @@ static inline isc_result_t totext_sink(ARGS_TOTEXT) snprintf(buf, sizeof(buf), "%u %u %u", meaning, coding, subcoding); RETERR(str_totext(buf, target)); - if (sr.length == 0U) + if (sr.length == 0U) { return (ISC_R_SUCCESS); + } /* data */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); + } - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -106,8 +113,9 @@ static inline isc_result_t fromwire_sink(ARGS_FROMWIRE) UNUSED(options); isc_buffer_activeregion(source, &sr); - if (sr.length < 3) + if (sr.length < 3) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, sr.length)); isc_buffer_forward(source, sr.length); @@ -181,28 +189,32 @@ static inline isc_result_t tostruct_sink(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &sr); /* Meaning */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } sink->meaning = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Coding */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } sink->coding = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Subcoding */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } sink->subcoding = uint8_fromregion(&sr); isc_region_consume(&sr, 1); /* Data */ sink->datalen = sr.length; sink->data = mem_maybedup(mctx, sr.base, sink->datalen); - if (sink->data == NULL) + if (sink->data == NULL) { return (ISC_R_NOMEMORY); + } sink->mctx = mctx; return (ISC_R_SUCCESS); @@ -215,11 +227,13 @@ static inline void freestruct_sink(ARGS_FREESTRUCT) REQUIRE(sink != NULL); REQUIRE(sink->common.rdtype == dns_rdatatype_sink); - if (sink->mctx == NULL) + if (sink->mctx == NULL) { return; + } - if (sink->data != NULL) + if (sink->data != NULL) { isc_mem_free(sink->mctx, sink->data); + } sink->mctx = NULL; } diff --git a/lib/dns/rdata/generic/soa_6.c b/lib/dns/rdata/generic/soa_6.c index bb4ec42030..dcc1212c2c 100644 --- a/lib/dns/rdata/generic/soa_6.c +++ b/lib/dns/rdata/generic/soa_6.c @@ -29,8 +29,9 @@ static inline isc_result_t fromtext_soa(ARGS_FROMTEXT) UNUSED(rdclass); UNUSED(callbacks); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, @@ -41,7 +42,7 @@ static inline isc_result_t fromtext_soa(ARGS_FROMTEXT) RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { switch (i) { case 0: ok = dns_name_ishostname(&name, false); @@ -50,10 +51,13 @@ static inline isc_result_t fromtext_soa(ARGS_FROMTEXT) ok = dns_name_ismailbox(&name); break; } - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } } RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, @@ -114,8 +118,9 @@ static inline isc_result_t totext_soa(ARGS_TOTEXT) sub = name_prefix(&rname, tctx->origin, &prefix); RETERR(dns_name_totext(&prefix, sub, target)); - if (multiline) + if (multiline) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); for (i = 0; i < 5; i++) { @@ -139,8 +144,9 @@ static inline isc_result_t totext_soa(ARGS_TOTEXT) } } - if (multiline) + if (multiline) { RETERR(str_totext(")", target)); + } return (ISC_R_SUCCESS); } @@ -168,10 +174,12 @@ static inline isc_result_t fromwire_soa(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sregion); isc_buffer_availableregion(target, &tregion); - if (sregion.length < 20) + if (sregion.length < 20) { return (ISC_R_UNEXPECTEDEND); - if (tregion.length < 20) + } + if (tregion.length < 20) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 20); isc_buffer_forward(source, 20); @@ -208,8 +216,9 @@ static inline isc_result_t towire_soa(ARGS_TOWIRE) RETERR(dns_name_towire(&rname, cctx, target)); isc_buffer_availableregion(target, &tregion); - if (tregion.length < 20) + if (tregion.length < 20) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 20); isc_buffer_add(target, 20); @@ -240,8 +249,9 @@ static inline int compare_soa(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); @@ -253,8 +263,9 @@ static inline int compare_soa(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); @@ -313,8 +324,9 @@ static inline isc_result_t tostruct_soa(ARGS_TOSTRUCT) isc_region_consume(®ion, name_length(&name)); dns_name_init(&soa->contact, NULL); result = name_duporclone(&name, mctx, &soa->contact); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } soa->serial = uint32_fromregion(®ion); isc_region_consume(®ion, 4); @@ -334,8 +346,9 @@ static inline isc_result_t tostruct_soa(ARGS_TOSTRUCT) return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&soa->origin, mctx); + } return (ISC_R_NOMEMORY); } @@ -346,8 +359,9 @@ static inline void freestruct_soa(ARGS_FREESTRUCT) REQUIRE(soa != NULL); REQUIRE(soa->common.rdtype == dns_rdatatype_soa); - if (soa->mctx == NULL) + if (soa->mctx == NULL) { return; + } dns_name_free(&soa->origin, soa->mctx); dns_name_free(&soa->contact, soa->mctx); @@ -412,15 +426,17 @@ static inline bool checknames_soa(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } isc_region_consume(®ion, name_length(&name)); dns_name_fromregion(&name, ®ion); if (!dns_name_ismailbox(&name)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/generic/sshfp_44.c b/lib/dns/rdata/generic/sshfp_44.c index 3aa20f20c2..b92c900241 100644 --- a/lib/dns/rdata/generic/sshfp_44.c +++ b/lib/dns/rdata/generic/sshfp_44.c @@ -34,8 +34,9 @@ static inline isc_result_t fromtext_sshfp(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -43,8 +44,9 @@ static inline isc_result_t fromtext_sshfp(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -103,16 +105,19 @@ static inline isc_result_t totext_sshfp(ARGS_TOTEXT) /* * Digest. */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_hex_totext(&sr, 0, "", target)); - else + } else { RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -210,8 +215,9 @@ static inline isc_result_t tostruct_sshfp(ARGS_TOSTRUCT) sshfp->length = region.length; sshfp->digest = mem_maybedup(mctx, region.base, region.length); - if (sshfp->digest == NULL) + if (sshfp->digest == NULL) { return (ISC_R_NOMEMORY); + } sshfp->mctx = mctx; return (ISC_R_SUCCESS); @@ -224,11 +230,13 @@ static inline void freestruct_sshfp(ARGS_FREESTRUCT) REQUIRE(sshfp != NULL); REQUIRE(sshfp->common.rdtype == dns_rdatatype_sshfp); - if (sshfp->mctx == NULL) + if (sshfp->mctx == NULL) { return; + } - if (sshfp->digest != NULL) + if (sshfp->digest != NULL) { isc_mem_free(sshfp->mctx, sshfp->digest); + } sshfp->mctx = NULL; } diff --git a/lib/dns/rdata/generic/ta_32768.c b/lib/dns/rdata/generic/ta_32768.c index 376a4ff5b7..b56b98e605 100644 --- a/lib/dns/rdata/generic/ta_32768.c +++ b/lib/dns/rdata/generic/ta_32768.c @@ -99,11 +99,13 @@ static inline void freestruct_ta(ARGS_FREESTRUCT) REQUIRE(ds != NULL); REQUIRE(ds->common.rdtype == dns_rdatatype_ta); - if (ds->mctx == NULL) + if (ds->mctx == NULL) { return; + } - if (ds->digest != NULL) + if (ds->digest != NULL) { isc_mem_free(ds->mctx, ds->digest); + } ds->mctx = NULL; } diff --git a/lib/dns/rdata/generic/talink_58.c b/lib/dns/rdata/generic/talink_58.c index ffd125f859..76dae5b891 100644 --- a/lib/dns/rdata/generic/talink_58.c +++ b/lib/dns/rdata/generic/talink_58.c @@ -27,8 +27,9 @@ static inline isc_result_t fromtext_talink(ARGS_FROMTEXT) UNUSED(rdclass); UNUSED(callbacks); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } for (i = 0; i < 2; i++) { RETERR(isc_lex_getmastertoken(lexer, &token, @@ -183,15 +184,17 @@ static inline isc_result_t tostruct_talink(ARGS_TOSTRUCT) isc_region_consume(®ion, name_length(&name)); dns_name_init(&talink->next, NULL); result = name_duporclone(&name, mctx, &talink->next); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } talink->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&talink->prev, mctx); + } return (ISC_R_NOMEMORY); } @@ -202,8 +205,9 @@ static inline void freestruct_talink(ARGS_FREESTRUCT) REQUIRE(talink != NULL); REQUIRE(talink->common.rdtype == dns_rdatatype_talink); - if (talink->mctx == NULL) + if (talink->mctx == NULL) { return; + } dns_name_free(&talink->prev, talink->mctx); dns_name_free(&talink->next, talink->mctx); diff --git a/lib/dns/rdata/generic/talink_58.h b/lib/dns/rdata/generic/talink_58.h index 45f57d8e8b..5fc6931a3c 100644 --- a/lib/dns/rdata/generic/talink_58.h +++ b/lib/dns/rdata/generic/talink_58.h @@ -9,7 +9,8 @@ * information regarding copyright ownership. */ -/* http://www.iana.org/assignments/dns-parameters/TALINK/talink-completed-template +/* + * http://www.iana.org/assignments/dns-parameters/TALINK/talink-completed-template */ #ifndef GENERIC_TALINK_58_H diff --git a/lib/dns/rdata/generic/tkey_249.c b/lib/dns/rdata/generic/tkey_249.c index 9d3edd4e24..f63df5a9c1 100644 --- a/lib/dns/rdata/generic/tkey_249.c +++ b/lib/dns/rdata/generic/tkey_249.c @@ -38,8 +38,9 @@ static inline isc_result_t fromtext_tkey(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); /* @@ -61,8 +62,9 @@ static inline isc_result_t fromtext_tkey(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -73,10 +75,12 @@ static inline isc_result_t fromtext_tkey(ARGS_FROMTEXT) if (dns_tsigrcode_fromtext(&rcode, &token.value.as_textregion) != ISC_R_SUCCESS) { i = strtol(DNS_AS_STR(token), &e, 10); - if (*e != 0) + if (*e != 0) { RETTOK(DNS_R_UNKNOWN); - if (i < 0 || i > 0xffff) + } + if (i < 0 || i > 0xffff) { RETTOK(ISC_R_RANGE); + } rcode = (dns_rcode_t)i; } RETERR(uint16_tobuffer(rcode, target)); @@ -86,8 +90,9 @@ static inline isc_result_t fromtext_tkey(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -100,8 +105,9 @@ static inline isc_result_t fromtext_tkey(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -164,9 +170,9 @@ static inline isc_result_t totext_tkey(ARGS_TOTEXT) */ n = uint16_fromregion(&sr); isc_region_consume(&sr, 2); - if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS) + if (dns_tsigrcode_totext((dns_rcode_t)n, target) == ISC_R_SUCCESS) { RETERR(str_totext(" ", target)); - else { + } else { snprintf(buf, sizeof(buf), "%lu ", n); RETERR(str_totext(buf, target)); } @@ -185,18 +191,21 @@ static inline isc_result_t totext_tkey(ARGS_TOTEXT) REQUIRE(n <= sr.length); dr = sr; dr.length = n; - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&dr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&dr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" ) ", target)); - else + } else { RETERR(str_totext(" ", target)); + } isc_region_consume(&sr, n); /* @@ -214,16 +223,19 @@ static inline isc_result_t totext_tkey(ARGS_TOTEXT) if (n != 0U) { dr = sr; dr.length = n; - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&dr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&dr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } } return (ISC_R_SUCCESS); } @@ -254,8 +266,9 @@ static inline isc_result_t fromwire_tkey(ARGS_FROMWIRE) * Error: 2 */ isc_buffer_activeregion(source, &sr); - if (sr.length < 12) + if (sr.length < 12) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, 12)); isc_region_consume(&sr, 12); isc_buffer_forward(source, 12); @@ -263,11 +276,13 @@ static inline isc_result_t fromwire_tkey(ARGS_FROMWIRE) /* * Key Length + Key Data. */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } n = uint16_fromregion(&sr); - if (sr.length < n + 2) + if (sr.length < n + 2) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, n + 2)); isc_region_consume(&sr, n + 2); isc_buffer_forward(source, n + 2); @@ -275,11 +290,13 @@ static inline isc_result_t fromwire_tkey(ARGS_FROMWIRE) /* * Other Length + Other Data. */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } n = uint16_fromregion(&sr); - if (sr.length < n + 2) + if (sr.length < n + 2) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, n + 2); return (mem_tobuffer(target, sr.base, n + 2)); } @@ -329,8 +346,9 @@ static inline int compare_tkey(ARGS_COMPARE) dns_name_init(&name2, NULL); dns_name_fromregion(&name1, &r1); dns_name_fromregion(&name2, &r2); - if ((order = dns_name_rdatacompare(&name1, &name2)) != 0) + if ((order = dns_name_rdatacompare(&name1, &name2)) != 0) { return (order); + } isc_region_consume(&r1, name_length(&name1)); isc_region_consume(&r2, name_length(&name2)); return (isc_region_compare(&r1, &r2)); @@ -454,8 +472,9 @@ static inline isc_result_t tostruct_tkey(ARGS_TOSTRUCT) */ INSIST(tkey->keylen + 2U <= sr.length); tkey->key = mem_maybedup(mctx, sr.base, tkey->keylen); - if (tkey->key == NULL) + if (tkey->key == NULL) { goto cleanup; + } isc_region_consume(&sr, tkey->keylen); /* @@ -469,17 +488,20 @@ static inline isc_result_t tostruct_tkey(ARGS_TOSTRUCT) */ INSIST(tkey->otherlen <= sr.length); tkey->other = mem_maybedup(mctx, sr.base, tkey->otherlen); - if (tkey->other == NULL) + if (tkey->other == NULL) { goto cleanup; + } tkey->mctx = mctx; return (ISC_R_SUCCESS); cleanup: - if (mctx != NULL) + if (mctx != NULL) { dns_name_free(&tkey->algorithm, mctx); - if (mctx != NULL && tkey->key != NULL) + } + if (mctx != NULL && tkey->key != NULL) { isc_mem_free(mctx, tkey->key); + } return (ISC_R_NOMEMORY); } @@ -489,14 +511,17 @@ static inline void freestruct_tkey(ARGS_FREESTRUCT) REQUIRE(tkey != NULL); - if (tkey->mctx == NULL) + if (tkey->mctx == NULL) { return; + } dns_name_free(&tkey->algorithm, tkey->mctx); - if (tkey->key != NULL) + if (tkey->key != NULL) { isc_mem_free(tkey->mctx, tkey->key); - if (tkey->other != NULL) + } + if (tkey->other != NULL) { isc_mem_free(tkey->mctx, tkey->other); + } tkey->mctx = NULL; } diff --git a/lib/dns/rdata/generic/tlsa_52.c b/lib/dns/rdata/generic/tlsa_52.c index 3a5107f9f8..d8c0e72793 100644 --- a/lib/dns/rdata/generic/tlsa_52.c +++ b/lib/dns/rdata/generic/tlsa_52.c @@ -31,8 +31,9 @@ static inline isc_result_t generic_fromtext_tlsa(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -40,8 +41,9 @@ static inline isc_result_t generic_fromtext_tlsa(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -49,8 +51,9 @@ static inline isc_result_t generic_fromtext_tlsa(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffU) + if (token.value.as_ulong > 0xffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint8_tobuffer(token.value.as_ulong, target)); /* @@ -98,16 +101,19 @@ static inline isc_result_t generic_totext_tlsa(ARGS_TOTEXT) /* * Certificate Association Data. */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_hex_totext(&sr, 0, "", target)); - else + } else { RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target)); - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + } + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" )", target)); + } return (ISC_R_SUCCESS); } @@ -122,8 +128,9 @@ static inline isc_result_t generic_fromwire_tlsa(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sr); - if (sr.length < 3) + if (sr.length < 3) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); @@ -223,8 +230,9 @@ static inline isc_result_t generic_tostruct_tlsa(ARGS_TOSTRUCT) tlsa->length = region.length; tlsa->data = mem_maybedup(mctx, region.base, region.length); - if (tlsa->data == NULL) + if (tlsa->data == NULL) { return (ISC_R_NOMEMORY); + } tlsa->mctx = mctx; return (ISC_R_SUCCESS); @@ -236,11 +244,13 @@ static inline void generic_freestruct_tlsa(ARGS_FREESTRUCT) REQUIRE(tlsa != NULL); - if (tlsa->mctx == NULL) + if (tlsa->mctx == NULL) { return; + } - if (tlsa->data != NULL) + if (tlsa->data != NULL) { isc_mem_free(tlsa->mctx, tlsa->data); + } tlsa->mctx = NULL; } diff --git a/lib/dns/rdata/generic/txt_16.c b/lib/dns/rdata/generic/txt_16.c index cdd43f2c62..4a91c4c412 100644 --- a/lib/dns/rdata/generic/txt_16.c +++ b/lib/dns/rdata/generic/txt_16.c @@ -37,8 +37,9 @@ static inline isc_result_t generic_fromtext_txt(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, true)); if (token.type != isc_tokentype_qstring && - token.type != isc_tokentype_string) + token.type != isc_tokentype_string) { break; + } RETTOK(txt_fromtext(&token.value.as_textregion, target)); strings++; } @@ -57,8 +58,9 @@ static inline isc_result_t generic_totext_txt(ARGS_TOTEXT) while (region.length > 0) { RETERR(txt_totext(®ion, true, target)); - if (region.length > 0) + if (region.length > 0) { RETERR(str_totext(" ", target)); + } } return (ISC_R_SUCCESS); @@ -75,8 +77,9 @@ static inline isc_result_t generic_fromwire_txt(ARGS_FROMWIRE) do { result = txt_fromwire(source, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } while (!buffer_empty(source)); return (ISC_R_SUCCESS); } @@ -146,8 +149,9 @@ static inline isc_result_t generic_fromstruct_txt(ARGS_FROMSTRUCT) while (region.length > 0) { length = uint8_fromregion(®ion); isc_region_consume(®ion, 1); - if (region.length < length) + if (region.length < length) { return (ISC_R_UNEXPECTEDEND); + } isc_region_consume(®ion, length); } @@ -167,8 +171,9 @@ static inline isc_result_t generic_tostruct_txt(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &r); txt->txt_len = r.length; txt->txt = mem_maybedup(mctx, r.base, r.length); - if (txt->txt == NULL) + if (txt->txt == NULL) { return (ISC_R_NOMEMORY); + } txt->offset = 0; txt->mctx = mctx; @@ -181,11 +186,13 @@ static inline void generic_freestruct_txt(ARGS_FREESTRUCT) REQUIRE(txt != NULL); - if (txt->mctx == NULL) + if (txt->mctx == NULL) { return; + } - if (txt->txt != NULL) + if (txt->txt != NULL) { isc_mem_free(txt->mctx, txt->txt); + } txt->mctx = NULL; } @@ -276,8 +283,9 @@ generic_txt_first(dns_rdata_txt_t *txt) REQUIRE(txt != NULL); REQUIRE(txt->txt != NULL || txt->txt_len == 0); - if (txt->txt_len == 0) + if (txt->txt_len == 0) { return (ISC_R_NOMORE); + } txt->offset = 0; return (ISC_R_SUCCESS); @@ -298,8 +306,9 @@ generic_txt_next(dns_rdata_txt_t *txt) length = uint8_fromregion(&r); INSIST(txt->offset + 1 + length <= txt->txt_len); txt->offset = txt->offset + 1 + length; - if (txt->offset == txt->txt_len) + if (txt->offset == txt->txt_len) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/rdata/generic/uri_256.c b/lib/dns/rdata/generic/uri_256.c index a5d4b7c27f..4b5f5cf5bb 100644 --- a/lib/dns/rdata/generic/uri_256.c +++ b/lib/dns/rdata/generic/uri_256.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_uri(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -40,8 +41,9 @@ static inline isc_result_t fromtext_uri(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -49,8 +51,9 @@ static inline isc_result_t fromtext_uri(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, false)); - if (token.type != isc_tokentype_qstring) + if (token.type != isc_tokentype_qstring) { RETTOK(DNS_R_SYNTAX); + } RETTOK(multitxt_fromtext(&token.value.as_textregion, target)); return (ISC_R_SUCCESS); } @@ -106,8 +109,9 @@ static inline isc_result_t fromwire_uri(ARGS_FROMWIRE) * Priority, weight */ isc_buffer_activeregion(source, ®ion); - if (region.length < 4) + if (region.length < 4) { return (ISC_R_UNEXPECTEDEND); + } /* * Priority, weight and target URI @@ -148,8 +152,9 @@ static inline int compare_uri(ARGS_COMPARE) * Priority */ order = memcmp(r1.base, r2.base, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } isc_region_consume(&r1, 2); isc_region_consume(&r2, 2); @@ -157,8 +162,9 @@ static inline int compare_uri(ARGS_COMPARE) * Weight */ order = memcmp(r1.base, r2.base, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } isc_region_consume(&r1, 2); isc_region_consume(&r2, 2); @@ -212,16 +218,18 @@ static inline isc_result_t tostruct_uri(ARGS_TOSTRUCT) /* * Priority */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } uri->priority = uint16_fromregion(&sr); isc_region_consume(&sr, 2); /* * Weight */ - if (sr.length < 2) + if (sr.length < 2) { return (ISC_R_UNEXPECTEDEND); + } uri->weight = uint16_fromregion(&sr); isc_region_consume(&sr, 2); @@ -230,8 +238,9 @@ static inline isc_result_t tostruct_uri(ARGS_TOSTRUCT) */ uri->tgt_len = sr.length; uri->target = mem_maybedup(mctx, sr.base, sr.length); - if (uri->target == NULL) + if (uri->target == NULL) { return (ISC_R_NOMEMORY); + } uri->mctx = mctx; return (ISC_R_SUCCESS); @@ -244,11 +253,13 @@ static inline void freestruct_uri(ARGS_FREESTRUCT) REQUIRE(uri != NULL); REQUIRE(uri->common.rdtype == dns_rdatatype_uri); - if (uri->mctx == NULL) + if (uri->mctx == NULL) { return; + } - if (uri->target != NULL) + if (uri->target != NULL) { isc_mem_free(uri->mctx, uri->target); + } uri->mctx = NULL; } diff --git a/lib/dns/rdata/generic/x25_19.c b/lib/dns/rdata/generic/x25_19.c index 0e7be82f86..1ba36dc6a1 100644 --- a/lib/dns/rdata/generic/x25_19.c +++ b/lib/dns/rdata/generic/x25_19.c @@ -31,8 +31,9 @@ static inline isc_result_t fromtext_x25(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_qstring, false)); - if (token.value.as_textregion.length < 4) + if (token.value.as_textregion.length < 4) { RETTOK(DNS_R_SYNTAX); + } for (i = 0; i < token.value.as_textregion.length; i++) { if (!isdigit(token.value.as_textregion.base[i] & 0xff)) { RETTOK(ISC_R_RANGE); @@ -67,8 +68,9 @@ static inline isc_result_t fromwire_x25(ARGS_FROMWIRE) UNUSED(options); isc_buffer_activeregion(source, &sr); - if (sr.length < 5) + if (sr.length < 5) { return (DNS_R_FORMERR); + } return (txt_fromwire(source, target)); } @@ -112,13 +114,13 @@ static inline isc_result_t fromstruct_x25(ARGS_FROMSTRUCT) UNUSED(type); UNUSED(rdclass); - if (x25->x25_len < 4) + if (x25->x25_len < 4) { return (ISC_R_RANGE); + } for (i = 0; i < x25->x25_len; i++) { if (!isdigit(x25->x25[i] & 0xff)) { return (ISC_R_RANGE); - } } @@ -143,8 +145,9 @@ static inline isc_result_t tostruct_x25(ARGS_TOSTRUCT) x25->x25_len = uint8_fromregion(&r); isc_region_consume(&r, 1); x25->x25 = mem_maybedup(mctx, r.base, x25->x25_len); - if (x25->x25 == NULL) + if (x25->x25 == NULL) { return (ISC_R_NOMEMORY); + } x25->mctx = mctx; return (ISC_R_SUCCESS); @@ -157,11 +160,13 @@ static inline void freestruct_x25(ARGS_FREESTRUCT) REQUIRE(x25 != NULL); REQUIRE(x25->common.rdtype == dns_rdatatype_x25); - if (x25->mctx == NULL) + if (x25->mctx == NULL) { return; + } - if (x25->x25 != NULL) + if (x25->x25 != NULL) { isc_mem_free(x25->mctx, x25->x25); + } x25->mctx = NULL; } diff --git a/lib/dns/rdata/generic/zonemd_63.c b/lib/dns/rdata/generic/zonemd_63.c index 6c7ebea479..c63e2f5256 100644 --- a/lib/dns/rdata/generic/zonemd_63.c +++ b/lib/dns/rdata/generic/zonemd_63.c @@ -106,15 +106,17 @@ static inline isc_result_t totext_zonemd(ARGS_TOTEXT) /* * Digest. */ - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(" (", target)); + } RETERR(str_totext(tctx->linebreak, target)); if ((tctx->flags & DNS_STYLEFLAG_NOCRYPTO) == 0) { - if (tctx->width == 0) /* No splitting */ + if (tctx->width == 0) { /* No splitting */ RETERR(isc_hex_totext(&sr, 0, "", target)); - else + } else { RETERR(isc_hex_totext(&sr, tctx->width - 2, tctx->linebreak, target)); + } } else { RETERR(str_totext("[omitted]", target)); } diff --git a/lib/dns/rdata/hs_4/a_1.c b/lib/dns/rdata/hs_4/a_1.c index 49a17bd4c5..cec4e4d005 100644 --- a/lib/dns/rdata/hs_4/a_1.c +++ b/lib/dns/rdata/hs_4/a_1.c @@ -34,11 +34,13 @@ static inline isc_result_t fromtext_hs_a(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) + if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) { RETTOK(DNS_R_BADDOTTEDQUAD); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 4) + if (region.length < 4) { return (ISC_R_NOSPACE); + } memmove(region.base, &addr, 4); isc_buffer_add(target, 4); return (ISC_R_SUCCESS); @@ -73,10 +75,12 @@ static inline isc_result_t fromwire_hs_a(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sregion); isc_buffer_availableregion(target, &tregion); - if (sregion.length < 4) + if (sregion.length < 4) { return (ISC_R_UNEXPECTEDEND); - if (tregion.length < 4) + } + if (tregion.length < 4) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 4); isc_buffer_forward(source, 4); @@ -95,8 +99,9 @@ static inline isc_result_t towire_hs_a(ARGS_TOWIRE) UNUSED(cctx); isc_buffer_availableregion(target, ®ion); - if (region.length < rdata->length) + if (region.length < rdata->length) { return (ISC_R_NOSPACE); + } memmove(region.base, rdata->data, rdata->length); isc_buffer_add(target, 4); return (ISC_R_SUCCESS); @@ -114,8 +119,9 @@ static inline int compare_hs_a(ARGS_COMPARE) REQUIRE(rdata2->length == 4); order = memcmp(rdata1->data, rdata2->data, 4); - if (order != 0) + if (order != 0) { order = (order < 0) ? -1 : 1; + } return (order); } diff --git a/lib/dns/rdata/in_1/a6_38.c b/lib/dns/rdata/in_1/a6_38.c index f78d198627..33d1a7db21 100644 --- a/lib/dns/rdata/in_1/a6_38.c +++ b/lib/dns/rdata/in_1/a6_38.c @@ -41,8 +41,9 @@ static inline isc_result_t fromtext_in_a6(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 128U) + if (token.value.as_ulong > 128U) { RETTOK(ISC_R_RANGE); + } prefixlen = (unsigned char)token.value.as_ulong; RETERR(mem_tobuffer(target, &prefixlen, 1)); @@ -60,30 +61,36 @@ static inline isc_result_t fromtext_in_a6(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1) + if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1) { RETTOK(DNS_R_BADAAAA); + } mask = 0xff >> (prefixlen % 8); addr[octets] &= mask; RETERR(mem_tobuffer(target, &addr[octets], 16 - octets)); } - if (prefixlen == 0) + if (prefixlen == 0) { return (ISC_R_SUCCESS); + } RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } return (ISC_R_SUCCESS); } @@ -123,8 +130,9 @@ static inline isc_result_t totext_in_a6(ARGS_TOTEXT) isc_region_consume(&sr, 16 - octets); } - if (prefixlen == 0) + if (prefixlen == 0) { return (ISC_R_SUCCESS); + } RETERR(str_totext(" ", target)); dns_name_init(&name, NULL); @@ -154,11 +162,13 @@ static inline isc_result_t fromwire_in_a6(ARGS_FROMWIRE) /* * Prefix length. */ - if (sr.length < 1) + if (sr.length < 1) { return (ISC_R_UNEXPECTEDEND); + } prefixlen = sr.base[0]; - if (prefixlen > 128) + if (prefixlen > 128) { return (ISC_R_RANGE); + } isc_region_consume(&sr, 1); RETERR(mem_tobuffer(target, &prefixlen, 1)); isc_buffer_forward(source, 1); @@ -168,16 +178,18 @@ static inline isc_result_t fromwire_in_a6(ARGS_FROMWIRE) */ if (prefixlen != 128) { octets = 16 - prefixlen / 8; - if (sr.length < octets) + if (sr.length < octets) { return (ISC_R_UNEXPECTEDEND); + } mask = 0xff >> (prefixlen % 8); sr.base[0] &= mask; /* Ensure pad bits are zero. */ RETERR(mem_tobuffer(target, sr.base, octets)); isc_buffer_forward(source, octets); } - if (prefixlen == 0) + if (prefixlen == 0) { return (ISC_R_SUCCESS); + } dns_name_init(&name, NULL); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -204,8 +216,9 @@ static inline isc_result_t towire_in_a6(ARGS_TOWIRE) RETERR(mem_tobuffer(target, sr.base, octets)); isc_region_consume(&sr, octets); - if (prefixlen == 0) + if (prefixlen == 0) { return (ISC_R_SUCCESS); + } dns_name_init(&name, offsets); dns_name_fromregion(&name, &sr); @@ -235,10 +248,11 @@ static inline int compare_in_a6(ARGS_COMPARE) prefixlen2 = region2.base[0]; isc_region_consume(®ion1, 1); isc_region_consume(®ion2, 1); - if (prefixlen1 < prefixlen2) + if (prefixlen1 < prefixlen2) { return (-1); - else if (prefixlen1 > prefixlen2) + } else if (prefixlen1 > prefixlen2) { return (1); + } /* * Prefix lengths are equal. */ @@ -246,15 +260,17 @@ static inline int compare_in_a6(ARGS_COMPARE) if (octets > 0) { order = memcmp(region1.base, region2.base, octets); - if (order < 0) + if (order < 0) { return (-1); - else if (order > 0) + } else if (order > 0) { return (1); + } /* * Address suffixes are equal. */ - if (prefixlen1 == 0) + if (prefixlen1 == 0) { return (order); + } isc_region_consume(®ion1, octets); isc_region_consume(®ion2, octets); } @@ -284,8 +300,9 @@ static inline isc_result_t fromstruct_in_a6(ARGS_FROMSTRUCT) UNUSED(type); UNUSED(rdclass); - if (a6->prefixlen > 128) + if (a6->prefixlen > 128) { return (ISC_R_RANGE); + } RETERR(uint8_tobuffer(a6->prefixlen, target)); @@ -299,14 +316,16 @@ static inline isc_result_t fromstruct_in_a6(ARGS_FROMSTRUCT) RETERR(uint8_tobuffer(first, target)); octets--; } - if (octets > 0) + if (octets > 0) { RETERR(mem_tobuffer(target, a6->in6_addr.s6_addr + 16 - octets, octets)); + } } - if (a6->prefixlen == 0) + if (a6->prefixlen == 0) { return (ISC_R_SUCCESS); + } dns_name_toregion(&a6->prefix, ®ion); return (isc_buffer_copyregion(target, ®ion)); } @@ -364,11 +383,13 @@ static inline void freestruct_in_a6(ARGS_FREESTRUCT) REQUIRE(a6->common.rdclass == dns_rdataclass_in); REQUIRE(a6->common.rdtype == dns_rdatatype_a6); - if (a6->mctx == NULL) + if (a6->mctx == NULL) { return; + } - if (dns_name_dynamic(&a6->prefix)) + if (dns_name_dynamic(&a6->prefix)) { dns_name_free(&a6->prefix, a6->mctx); + } a6->mctx = NULL; } @@ -401,10 +422,12 @@ static inline isc_result_t digest_in_a6(ARGS_DIGEST) r1.length = octets; result = (digest)(arg, &r1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (prefixlen == 0) + } + if (prefixlen == 0) { return (ISC_R_SUCCESS); + } isc_region_consume(&r2, octets); dns_name_init(&name, NULL); @@ -436,14 +459,16 @@ static inline bool checknames_in_a6(ARGS_CHECKNAMES) dns_rdata_toregion(rdata, ®ion); prefixlen = uint8_fromregion(®ion); - if (prefixlen == 0) + if (prefixlen == 0) { return (true); + } isc_region_consume(®ion, 1 + 16 - prefixlen / 8); dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/in_1/a_1.c b/lib/dns/rdata/in_1/a_1.c index 81622e20d2..916a79f6df 100644 --- a/lib/dns/rdata/in_1/a_1.c +++ b/lib/dns/rdata/in_1/a_1.c @@ -36,11 +36,13 @@ static inline isc_result_t fromtext_in_a(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) + if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) { RETTOK(DNS_R_BADDOTTEDQUAD); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 4) + if (region.length < 4) { return (ISC_R_NOSPACE); + } memmove(region.base, &addr, 4); isc_buffer_add(target, 4); return (ISC_R_SUCCESS); @@ -75,10 +77,12 @@ static inline isc_result_t fromwire_in_a(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sregion); isc_buffer_availableregion(target, &tregion); - if (sregion.length < 4) + if (sregion.length < 4) { return (ISC_R_UNEXPECTEDEND); - if (tregion.length < 4) + } + if (tregion.length < 4) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 4); isc_buffer_forward(source, 4); @@ -97,8 +101,9 @@ static inline isc_result_t towire_in_a(ARGS_TOWIRE) UNUSED(cctx); isc_buffer_availableregion(target, ®ion); - if (region.length < rdata->length) + if (region.length < rdata->length) { return (ISC_R_NOSPACE); + } memmove(region.base, rdata->data, rdata->length); isc_buffer_add(target, 4); return (ISC_R_SUCCESS); @@ -218,8 +223,9 @@ static inline bool checkowner_in_a(ARGS_CHECKOWNER) dns_name_split(name, dns_name_countlabels(name) - 2, &prefix, &suffix); if (dns_name_equal(&gc_msdcs, &prefix) && - dns_name_ishostname(&suffix, false)) + dns_name_ishostname(&suffix, false)) { return (true); + } } return (dns_name_ishostname(name, wildcard)); diff --git a/lib/dns/rdata/in_1/aaaa_28.c b/lib/dns/rdata/in_1/aaaa_28.c index fae406b79e..d3af610693 100644 --- a/lib/dns/rdata/in_1/aaaa_28.c +++ b/lib/dns/rdata/in_1/aaaa_28.c @@ -36,11 +36,13 @@ static inline isc_result_t fromtext_in_aaaa(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); - if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1) + if (inet_pton(AF_INET6, DNS_AS_STR(token), addr) != 1) { RETTOK(DNS_R_BADAAAA); + } isc_buffer_availableregion(target, ®ion); - if (region.length < 16) + if (region.length < 16) { return (ISC_R_NOSPACE); + } memmove(region.base, addr, 16); isc_buffer_add(target, 16); return (ISC_R_SUCCESS); @@ -91,10 +93,12 @@ static inline isc_result_t fromwire_in_aaaa(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sregion); isc_buffer_availableregion(target, &tregion); - if (sregion.length < 16) + if (sregion.length < 16) { return (ISC_R_UNEXPECTEDEND); - if (tregion.length < 16) + } + if (tregion.length < 16) { return (ISC_R_NOSPACE); + } memmove(tregion.base, sregion.base, 16); isc_buffer_forward(source, 16); @@ -113,8 +117,9 @@ static inline isc_result_t towire_in_aaaa(ARGS_TOWIRE) REQUIRE(rdata->length == 16); isc_buffer_availableregion(target, ®ion); - if (region.length < rdata->length) + if (region.length < rdata->length) { return (ISC_R_NOSPACE); + } memmove(region.base, rdata->data, rdata->length); isc_buffer_add(target, 16); return (ISC_R_SUCCESS); @@ -230,8 +235,9 @@ static inline bool checkowner_in_aaaa(ARGS_CHECKOWNER) dns_name_split(name, dns_name_countlabels(name) - 2, &prefix, &suffix); if (dns_name_equal(&gc_msdcs, &prefix) && - dns_name_ishostname(&suffix, false)) + dns_name_ishostname(&suffix, false)) { return (true); + } } return (dns_name_ishostname(name, wildcard)); diff --git a/lib/dns/rdata/in_1/apl_42.c b/lib/dns/rdata/in_1/apl_42.c index 90d2f55721..90835ce6f0 100644 --- a/lib/dns/rdata/in_1/apl_42.c +++ b/lib/dns/rdata/in_1/apl_42.c @@ -39,31 +39,38 @@ static inline isc_result_t fromtext_in_apl(ARGS_FROMTEXT) do { RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, true)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { break; + } cp = DNS_AS_STR(token); neg = (*cp == '!'); - if (neg) + if (neg) { cp++; + } afi = strtoul(cp, &ap, 10); - if (*ap++ != ':' || cp == ap) + if (*ap++ != ':' || cp == ap) { RETTOK(DNS_R_SYNTAX); - if (afi > 0xffffU) + } + if (afi > 0xffffU) { RETTOK(ISC_R_RANGE); + } slash = strchr(ap, '/'); - if (slash == NULL || slash == ap) + if (slash == NULL || slash == ap) { RETTOK(DNS_R_SYNTAX); + } RETTOK(isc_parse_uint8(&prefix, slash + 1, 10)); switch (afi) { case 1: *slash = '\0'; n = inet_pton(AF_INET, ap, addr); *slash = '/'; - if (n != 1) + if (n != 1) { RETTOK(DNS_R_BADDOTTEDQUAD); - if (prefix > 32) + } + if (prefix > 32) { RETTOK(ISC_R_RANGE); + } for (len = 4; len > 0; len--) { if (addr[len - 1] != 0) { break; @@ -75,10 +82,12 @@ static inline isc_result_t fromtext_in_apl(ARGS_FROMTEXT) *slash = '\0'; n = inet_pton(AF_INET6, ap, addr); *slash = '/'; - if (n != 1) + if (n != 1) { RETTOK(DNS_R_BADAAAA); - if (prefix > 128) + } + if (prefix > 128) { RETTOK(ISC_R_RANGE); + } for (len = 16; len > 0; len--) { if (addr[len - 1] != 0) { break; @@ -186,33 +195,39 @@ static inline isc_result_t fromwire_in_apl(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sr); isc_buffer_availableregion(target, &tr); - if (sr.length > tr.length) + if (sr.length > tr.length) { return (ISC_R_NOSPACE); + } sr2 = sr; /* Zero or more items */ while (sr.length > 0) { - if (sr.length < 4) + if (sr.length < 4) { return (ISC_R_UNEXPECTEDEND); + } afi = uint16_fromregion(&sr); isc_region_consume(&sr, 2); prefix = *sr.base; isc_region_consume(&sr, 1); len = (*sr.base & 0x7f); isc_region_consume(&sr, 1); - if (len > sr.length) + if (len > sr.length) { return (ISC_R_UNEXPECTEDEND); + } switch (afi) { case 1: - if (prefix > 32 || len > 4) + if (prefix > 32 || len > 4) { return (ISC_R_RANGE); + } break; case 2: - if (prefix > 128 || len > 16) + if (prefix > 128 || len > 16) { return (ISC_R_RANGE); + } } - if (len > 0 && sr.base[len - 1] == 0) + if (len > 0 && sr.base[len - 1] == 0) { return (DNS_R_FORMERR); + } isc_region_consume(&sr, len); } isc_buffer_forward(source, sr2.length); @@ -278,8 +293,9 @@ static inline isc_result_t tostruct_in_apl(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &r); apl->apl_len = r.length; apl->apl = mem_maybedup(mctx, r.base, r.length); - if (apl->apl == NULL) + if (apl->apl == NULL) { return (ISC_R_NOMEMORY); + } apl->offset = 0; apl->mctx = mctx; @@ -294,10 +310,12 @@ static inline void freestruct_in_apl(ARGS_FREESTRUCT) REQUIRE(apl->common.rdtype == dns_rdatatype_apl); REQUIRE(apl->common.rdclass == dns_rdataclass_in); - if (apl->mctx == NULL) + if (apl->mctx == NULL) { return; - if (apl->apl != NULL) + } + if (apl->apl != NULL) { isc_mem_free(apl->mctx, apl->apl); + } apl->mctx = NULL; } @@ -314,8 +332,9 @@ dns_rdata_apl_first(dns_rdata_in_apl_t *apl) /* * If no APL return ISC_R_NOMORE. */ - if (apl->apl == NULL) + if (apl->apl == NULL) { return (ISC_R_NOMORE); + } /* * Sanity check data. @@ -341,8 +360,9 @@ dns_rdata_apl_next(dns_rdata_in_apl_t *apl) /* * No APL or have already reached the end return ISC_R_NOMORE. */ - if (apl->apl == NULL || apl->offset == apl->apl_len) + if (apl->apl == NULL || apl->offset == apl->apl_len) { return (ISC_R_NOMORE); + } /* * Sanity check data. @@ -373,8 +393,9 @@ dns_rdata_apl_current(dns_rdata_in_apl_t *apl, dns_rdata_apl_ent_t *ent) REQUIRE(apl->apl != NULL || apl->apl_len == 0); REQUIRE(apl->offset <= apl->apl_len); - if (apl->offset == apl->apl_len) + if (apl->offset == apl->apl_len) { return (ISC_R_NOMORE); + } /* * Sanity check data. @@ -392,10 +413,11 @@ dns_rdata_apl_current(dns_rdata_in_apl_t *apl, dns_rdata_apl_ent_t *ent) ent->prefix = apl->apl[apl->offset + 2]; ent->length = length; ent->negative = (apl->apl[apl->offset + 3] & 0x80); - if (ent->length != 0) + if (ent->length != 0) { ent->data = &apl->apl[apl->offset + 4]; - else + } else { ent->data = NULL; + } return (ISC_R_SUCCESS); } diff --git a/lib/dns/rdata/in_1/dhcid_49.c b/lib/dns/rdata/in_1/dhcid_49.c index d2ac3bf5b0..77ff578f06 100644 --- a/lib/dns/rdata/in_1/dhcid_49.c +++ b/lib/dns/rdata/in_1/dhcid_49.c @@ -43,13 +43,15 @@ static inline isc_result_t totext_in_dhcid(ARGS_TOTEXT) dns_rdata_toregion(rdata, &sr); sr2 = sr; - if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) + if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext("( " /*)*/, target)); - if (tctx->width == 0) /* No splitting */ + } + if (tctx->width == 0) { /* No splitting */ RETERR(isc_base64_totext(&sr, 60, "", target)); - else + } else { RETERR(isc_base64_totext(&sr, tctx->width - 2, tctx->linebreak, target)); + } if ((tctx->flags & DNS_STYLEFLAG_MULTILINE) != 0) { RETERR(str_totext(/* ( */ " )", target)); if (rdata->length > 2) { @@ -75,8 +77,9 @@ static inline isc_result_t fromwire_in_dhcid(ARGS_FROMWIRE) UNUSED(options); isc_buffer_activeregion(source, &sr); - if (sr.length == 0) + if (sr.length == 0) { return (ISC_R_UNEXPECTEDEND); + } isc_buffer_forward(source, sr.length); return (mem_tobuffer(target, sr.base, sr.length)); @@ -147,8 +150,9 @@ static inline isc_result_t tostruct_in_dhcid(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, ®ion); dhcid->dhcid = mem_maybedup(mctx, region.base, region.length); - if (dhcid->dhcid == NULL) + if (dhcid->dhcid == NULL) { return (ISC_R_NOMEMORY); + } dhcid->mctx = mctx; return (ISC_R_SUCCESS); @@ -162,11 +166,13 @@ static inline void freestruct_in_dhcid(ARGS_FREESTRUCT) REQUIRE(dhcid->common.rdtype == dns_rdatatype_dhcid); REQUIRE(dhcid->common.rdclass == dns_rdataclass_in); - if (dhcid->mctx == NULL) + if (dhcid->mctx == NULL) { return; + } - if (dhcid->dhcid != NULL) + if (dhcid->dhcid != NULL) { isc_mem_free(dhcid->mctx, dhcid->dhcid); + } dhcid->mctx = NULL; } diff --git a/lib/dns/rdata/in_1/kx_36.c b/lib/dns/rdata/in_1/kx_36.c index a3ca912bef..388214268b 100644 --- a/lib/dns/rdata/in_1/kx_36.c +++ b/lib/dns/rdata/in_1/kx_36.c @@ -31,16 +31,18 @@ static inline isc_result_t fromtext_in_kx(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -90,8 +92,9 @@ static inline isc_result_t fromwire_in_kx(ARGS_FROMWIRE) dns_name_init(&name, NULL); isc_buffer_activeregion(source, &sregion); - if (sregion.length < 2) + if (sregion.length < 2) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sregion.base, 2)); isc_buffer_forward(source, 2); return (dns_name_fromwire(&name, source, dctx, options, target)); @@ -134,8 +137,9 @@ static inline int compare_in_kx(ARGS_COMPARE) REQUIRE(rdata2->length != 0); order = memcmp(rdata1->data, rdata2->data, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -207,8 +211,9 @@ static inline void freestruct_in_kx(ARGS_FREESTRUCT) REQUIRE(kx->common.rdclass == dns_rdataclass_in); REQUIRE(kx->common.rdtype == dns_rdatatype_kx); - if (kx->mctx == NULL) + if (kx->mctx == NULL) { return; + } dns_name_free(&kx->exchange, kx->mctx); kx->mctx = NULL; diff --git a/lib/dns/rdata/in_1/nsap-ptr_23.c b/lib/dns/rdata/in_1/nsap-ptr_23.c index c432f49a10..b2de76e840 100644 --- a/lib/dns/rdata/in_1/nsap-ptr_23.c +++ b/lib/dns/rdata/in_1/nsap-ptr_23.c @@ -34,8 +34,9 @@ static inline isc_result_t fromtext_in_nsap_ptr(ARGS_FROMTEXT) dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); return (ISC_R_SUCCESS); } @@ -172,8 +173,9 @@ static inline void freestruct_in_nsap_ptr(ARGS_FREESTRUCT) REQUIRE(nsap_ptr->common.rdclass == dns_rdataclass_in); REQUIRE(nsap_ptr->common.rdtype == dns_rdatatype_nsap_ptr); - if (nsap_ptr->mctx == NULL) + if (nsap_ptr->mctx == NULL) { return; + } dns_name_free(&nsap_ptr->owner, nsap_ptr->mctx); nsap_ptr->mctx = NULL; diff --git a/lib/dns/rdata/in_1/nsap_22.c b/lib/dns/rdata/in_1/nsap_22.c index e54ab4c5bc..15e0382c46 100644 --- a/lib/dns/rdata/in_1/nsap_22.c +++ b/lib/dns/rdata/in_1/nsap_22.c @@ -38,18 +38,21 @@ static inline isc_result_t fromtext_in_nsap(ARGS_FROMTEXT) RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, false)); sr = &token.value.as_textregion; - if (sr->length < 2) + if (sr->length < 2) { RETTOK(ISC_R_UNEXPECTEDEND); - if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X')) + } + if (sr->base[0] != '0' || (sr->base[1] != 'x' && sr->base[1] != 'X')) { RETTOK(DNS_R_SYNTAX); + } isc_textregion_consume(sr, 2); while (sr->length > 0) { if (sr->base[0] == '.') { isc_textregion_consume(sr, 1); continue; } - if ((n = hexvalue(sr->base[0])) == -1) + if ((n = hexvalue(sr->base[0])) == -1) { RETTOK(DNS_R_SYNTAX); + } c <<= 4; c += n; if (++digits == 2) { @@ -60,8 +63,9 @@ static inline isc_result_t fromtext_in_nsap(ARGS_FROMTEXT) } isc_textregion_consume(sr, 1); } - if (digits != 0 || !valid) + if (digits != 0 || !valid) { RETTOK(ISC_R_UNEXPECTEDEND); + } return (ISC_R_SUCCESS); } @@ -99,8 +103,9 @@ static inline isc_result_t fromwire_in_nsap(ARGS_FROMWIRE) UNUSED(rdclass); isc_buffer_activeregion(source, ®ion); - if (region.length < 1) + if (region.length < 1) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, region.base, region.length)); isc_buffer_forward(source, region.length); @@ -169,8 +174,9 @@ static inline isc_result_t tostruct_in_nsap(ARGS_TOSTRUCT) dns_rdata_toregion(rdata, &r); nsap->nsap_len = r.length; nsap->nsap = mem_maybedup(mctx, r.base, r.length); - if (nsap->nsap == NULL) + if (nsap->nsap == NULL) { return (ISC_R_NOMEMORY); + } nsap->mctx = mctx; return (ISC_R_SUCCESS); @@ -184,11 +190,13 @@ static inline void freestruct_in_nsap(ARGS_FREESTRUCT) REQUIRE(nsap->common.rdclass == dns_rdataclass_in); REQUIRE(nsap->common.rdtype == dns_rdatatype_nsap); - if (nsap->mctx == NULL) + if (nsap->mctx == NULL) { return; + } - if (nsap->nsap != NULL) + if (nsap->nsap != NULL) { isc_mem_free(nsap->mctx, nsap->nsap); + } nsap->mctx = NULL; } diff --git a/lib/dns/rdata/in_1/px_26.c b/lib/dns/rdata/in_1/px_26.c index 5b07f46549..1bba436708 100644 --- a/lib/dns/rdata/in_1/px_26.c +++ b/lib/dns/rdata/in_1/px_26.c @@ -29,16 +29,18 @@ static inline isc_result_t fromtext_in_px(ARGS_FROMTEXT) UNUSED(rdclass); UNUSED(callbacks); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } /* * Preference. */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -123,8 +125,9 @@ static inline isc_result_t fromwire_in_px(ARGS_FROMWIRE) * Preference. */ isc_buffer_activeregion(source, &sregion); - if (sregion.length < 2) + if (sregion.length < 2) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sregion.base, 2)); isc_buffer_forward(source, 2); @@ -189,8 +192,9 @@ static inline int compare_in_px(ARGS_COMPARE) REQUIRE(rdata2->length != 0); order = memcmp(rdata1->data, rdata2->data, 2); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } dns_name_init(&name1, NULL); dns_name_init(&name2, NULL); @@ -205,8 +209,9 @@ static inline int compare_in_px(ARGS_COMPARE) dns_name_fromregion(&name2, ®ion2); order = dns_name_rdatacompare(&name1, &name2); - if (order != 0) + if (order != 0) { return (order); + } isc_region_consume(®ion1, name_length(&name1)); isc_region_consume(®ion2, name_length(&name2)); @@ -268,8 +273,9 @@ static inline isc_result_t tostruct_in_px(ARGS_TOSTRUCT) dns_name_init(&px->mapx400, NULL); result = name_duporclone(&name, mctx, &px->mapx400); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } px->mctx = mctx; return (result); @@ -287,8 +293,9 @@ static inline void freestruct_in_px(ARGS_FREESTRUCT) REQUIRE(px->common.rdclass == dns_rdataclass_in); REQUIRE(px->common.rdtype == dns_rdatatype_px); - if (px->mctx == NULL) + if (px->mctx == NULL) { return; + } dns_name_free(&px->map822, px->mctx); dns_name_free(&px->mapx400, px->mctx); @@ -321,13 +328,15 @@ static inline isc_result_t digest_in_px(ARGS_DIGEST) isc_region_consume(&r2, 2); r1.length = 2; result = (digest)(arg, &r1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_init(&name, NULL); dns_name_fromregion(&name, &r2); result = dns_name_digest(&name, digest, arg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_region_consume(&r2, name_length(&name)); dns_name_init(&name, NULL); dns_name_fromregion(&name, &r2); diff --git a/lib/dns/rdata/in_1/srv_33.c b/lib/dns/rdata/in_1/srv_33.c index a2afe3af22..d15d312a97 100644 --- a/lib/dns/rdata/in_1/srv_33.c +++ b/lib/dns/rdata/in_1/srv_33.c @@ -35,8 +35,9 @@ static inline isc_result_t fromtext_in_srv(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -44,8 +45,9 @@ static inline isc_result_t fromtext_in_srv(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -53,8 +55,9 @@ static inline isc_result_t fromtext_in_srv(ARGS_FROMTEXT) */ RETERR(isc_lex_getmastertoken(lexer, &token, isc_tokentype_number, false)); - if (token.value.as_ulong > 0xffffU) + if (token.value.as_ulong > 0xffffU) { RETTOK(ISC_R_RANGE); + } RETERR(uint16_tobuffer(token.value.as_ulong, target)); /* @@ -64,16 +67,20 @@ static inline isc_result_t fromtext_in_srv(ARGS_FROMTEXT) false)); dns_name_init(&name, NULL); buffer_fromregion(&buffer, &token.value.as_region); - if (origin == NULL) + if (origin == NULL) { origin = dns_rootname; + } RETTOK(dns_name_fromtext(&name, &buffer, origin, options, target)); ok = true; - if ((options & DNS_RDATA_CHECKNAMES) != 0) + if ((options & DNS_RDATA_CHECKNAMES) != 0) { ok = dns_name_ishostname(&name, false); - if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) + } + if (!ok && (options & DNS_RDATA_CHECKNAMESFAIL) != 0) { RETTOK(DNS_R_BADNAME); - if (!ok && callbacks != NULL) + } + if (!ok && callbacks != NULL) { warn_badname(&name, lexer, callbacks); + } return (ISC_R_SUCCESS); } @@ -148,8 +155,9 @@ static inline isc_result_t fromwire_in_srv(ARGS_FROMWIRE) * Priority, weight, port. */ isc_buffer_activeregion(source, &sr); - if (sr.length < 6) + if (sr.length < 6) { return (ISC_R_UNEXPECTEDEND); + } RETERR(mem_tobuffer(target, sr.base, 6)); isc_buffer_forward(source, 6); @@ -203,8 +211,9 @@ static inline int compare_in_srv(ARGS_COMPARE) * Priority, weight, port. */ order = memcmp(rdata1->data, rdata2->data, 6); - if (order != 0) + if (order != 0) { return (order < 0 ? -1 : 1); + } /* * Target. @@ -283,8 +292,9 @@ static inline void freestruct_in_srv(ARGS_FREESTRUCT) REQUIRE(srv->common.rdclass == dns_rdataclass_in); REQUIRE(srv->common.rdtype == dns_rdatatype_srv); - if (srv->mctx == NULL) + if (srv->mctx == NULL) { return; + } dns_name_free(&srv->target, srv->mctx); srv->mctx = NULL; @@ -310,24 +320,28 @@ static inline isc_result_t additionaldata_in_srv(ARGS_ADDLDATA) isc_region_consume(®ion, 2); dns_name_fromregion(&name, ®ion); - if (dns_name_equal(&name, dns_rootname)) + if (dns_name_equal(&name, dns_rootname)) { return (ISC_R_SUCCESS); + } result = (add)(arg, &name, dns_rdatatype_a); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_fixedname_init(&fixed); snprintf(buf, sizeof(buf), "_%u._tcp", port); result = dns_name_fromstring2(dns_fixedname_name(&fixed), buf, NULL, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } result = dns_name_concatenate(dns_fixedname_name(&fixed), &name, dns_fixedname_name(&fixed), NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } return ((add)(arg, dns_fixedname_name(&fixed), dns_rdatatype_tlsa)); } @@ -378,8 +392,9 @@ static inline bool checknames_in_srv(ARGS_CHECKNAMES) dns_name_init(&name, NULL); dns_name_fromregion(&name, ®ion); if (!dns_name_ishostname(&name, false)) { - if (bad != NULL) + if (bad != NULL) { dns_name_clone(&name, bad); + } return (false); } return (true); diff --git a/lib/dns/rdata/in_1/wks_11.c b/lib/dns/rdata/in_1/wks_11.c index 37e0dcf824..3fd07a5720 100644 --- a/lib/dns/rdata/in_1/wks_11.c +++ b/lib/dns/rdata/in_1/wks_11.c @@ -29,7 +29,7 @@ if (result != ISC_R_SUCCESS) \ goto cleanup; \ } while (0) -#endif +#endif /* ifndef CHECK */ #define RRTYPE_WKS_ATTRIBUTES (0) @@ -48,8 +48,9 @@ mygetprotobyname(const char *name, long *proto) LOCK(&wks_lock); pe = getprotobyname(name); - if (pe != NULL) + if (pe != NULL) { *proto = pe->p_proto; + } UNLOCK(&wks_lock); return (pe != NULL); } @@ -61,8 +62,9 @@ mygetservbyname(const char *name, const char *proto, long *port) LOCK(&wks_lock); se = getservbyname(name, proto); - if (se != NULL) + if (se != NULL) { *port = ntohs(se->s_port); + } UNLOCK(&wks_lock); return (se != NULL); } @@ -71,7 +73,7 @@ mygetservbyname(const char *name, const char *proto, long *port) #include #include #include -#endif +#endif /* ifdef _WIN32 */ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) { @@ -110,10 +112,11 @@ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) wVersionRequested = MAKEWORD(2, 0); err = WSAStartup(wVersionRequested, &wsaData); - if (err != 0) + if (err != 0) { return (ISC_R_FAILURE); + } } -#endif +#endif /* ifdef _WIN32 */ /* * IPv4 dotted quad. @@ -122,10 +125,12 @@ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) false)); isc_buffer_availableregion(target, ®ion); - if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) + if (inet_pton(AF_INET, DNS_AS_STR(token), &addr) != 1) { CHECKTOK(DNS_R_BADDOTTEDQUAD); - if (region.length < 4) + } + if (region.length < 4) { return (ISC_R_NOSPACE); + } memmove(region.base, &addr, 4); isc_buffer_add(target, 4); @@ -136,18 +141,20 @@ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) false)); proto = strtol(DNS_AS_STR(token), &e, 10); - if (*e == 0) - ; - else if (!mygetprotobyname(DNS_AS_STR(token), &proto)) + if (*e == 0) { + } else if (!mygetprotobyname(DNS_AS_STR(token), &proto)) { CHECKTOK(DNS_R_UNKNOWNPROTO); + } - if (proto < 0 || proto > 0xff) + if (proto < 0 || proto > 0xff) { CHECKTOK(ISC_R_RANGE); + } - if (proto == IPPROTO_TCP) + if (proto == IPPROTO_TCP) { ps = "tcp"; - else if (proto == IPPROTO_UDP) + } else if (proto == IPPROTO_UDP) { ps = "udp"; + } CHECK(uint8_tobuffer(proto, target)); @@ -155,8 +162,9 @@ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) do { CHECK(isc_lex_getmastertoken(lexer, &token, isc_tokentype_string, true)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { break; + } /* * Lowercase the service string as some getservbyname() are @@ -166,20 +174,21 @@ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) for (i = strlen(service) - 1; i >= 0; i--) { if (isupper(service[i] & 0xff)) { service[i] = tolower(service[i] & 0xff); - } } port = strtol(DNS_AS_STR(token), &e, 10); - if (*e == 0) - ; - else if (!mygetservbyname(service, ps, &port) && - !mygetservbyname(DNS_AS_STR(token), ps, &port)) + if (*e == 0) { + } else if (!mygetservbyname(service, ps, &port) && + !mygetservbyname(DNS_AS_STR(token), ps, &port)) { CHECKTOK(DNS_R_UNKNOWNSERVICE); - if (port < 0 || port > 0xffff) + } + if (port < 0 || port > 0xffff) { CHECKTOK(ISC_R_RANGE); - if (port > maxport) + } + if (port > maxport) { maxport = port; + } bm[port / 8] |= (0x80 >> (port % 8)); } while (1); @@ -194,7 +203,7 @@ static inline isc_result_t fromtext_in_wks(ARGS_FROMTEXT) cleanup: #ifdef _WIN32 WSACleanup(); -#endif +#endif /* ifdef _WIN32 */ return (result); } @@ -224,17 +233,18 @@ static inline isc_result_t totext_in_wks(ARGS_TOTEXT) INSIST(sr.length <= 8 * 1024); for (i = 0; i < sr.length; i++) { - if (sr.base[i] != 0) + if (sr.base[i] != 0) { for (j = 0; j < 8; j++) { if ((sr.base[i] & (0x80 >> j)) != 0) { { - snprintf(buf, sizeof(buf), - "%u", i * 8 + j); + snprintf(buf, sizeof(buf), "%u", + i * 8 + j); RETERR(str_totext(" ", target)); RETERR(str_totext(buf, target)); } } } + } } return (ISC_R_SUCCESS); @@ -256,12 +266,15 @@ static inline isc_result_t fromwire_in_wks(ARGS_FROMWIRE) isc_buffer_activeregion(source, &sr); isc_buffer_availableregion(target, &tr); - if (sr.length < 5) + if (sr.length < 5) { return (ISC_R_UNEXPECTEDEND); - if (sr.length > 8 * 1024 + 5) + } + if (sr.length > 8 * 1024 + 5) { return (DNS_R_EXTRADATA); - if (tr.length < sr.length) + } + if (tr.length < sr.length) { return (ISC_R_NOSPACE); + } memmove(tr.base, sr.base, sr.length); isc_buffer_add(target, sr.length); @@ -346,8 +359,9 @@ static inline isc_result_t tostruct_in_wks(ARGS_TOSTRUCT) isc_region_consume(®ion, 1); wks->map_len = region.length; wks->map = mem_maybedup(mctx, region.base, region.length); - if (wks->map == NULL) + if (wks->map == NULL) { return (ISC_R_NOMEMORY); + } wks->mctx = mctx; return (ISC_R_SUCCESS); } @@ -360,11 +374,13 @@ static inline void freestruct_in_wks(ARGS_FREESTRUCT) REQUIRE(wks->common.rdtype == dns_rdatatype_wks); REQUIRE(wks->common.rdclass == dns_rdataclass_in); - if (wks->mctx == NULL) + if (wks->mctx == NULL) { return; + } - if (wks->map != NULL) + if (wks->map != NULL) { isc_mem_free(wks->mctx, wks->map); + } wks->mctx = NULL; } diff --git a/lib/dns/rdatalist.c b/lib/dns/rdatalist.c index d9287ee3ec..88ba7af01d 100644 --- a/lib/dns/rdatalist.c +++ b/lib/dns/rdatalist.c @@ -118,8 +118,9 @@ isc__rdatalist_first(dns_rdataset_t *rdataset) rdatalist = rdataset->private1; rdataset->private2 = ISC_LIST_HEAD(rdatalist->rdata); - if (rdataset->private2 == NULL) + if (rdataset->private2 == NULL) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } @@ -132,13 +133,15 @@ isc__rdatalist_next(dns_rdataset_t *rdataset) REQUIRE(rdataset != NULL); rdata = rdataset->private2; - if (rdata == NULL) + if (rdata == NULL) { return (ISC_R_NOMORE); + } rdataset->private2 = ISC_LIST_NEXT(rdata, link); - if (rdataset->private2 == NULL) + if (rdataset->private2 == NULL) { return (ISC_R_NOMORE); + } return (ISC_R_SUCCESS); } @@ -183,8 +186,9 @@ isc__rdatalist_count(dns_rdataset_t *rdataset) count = 0; for (rdata = ISC_LIST_HEAD(rdatalist->rdata); rdata != NULL; - rdata = ISC_LIST_NEXT(rdata, link)) + rdata = ISC_LIST_NEXT(rdata, link)) { count++; + } return (count); } @@ -201,32 +205,39 @@ isc__rdatalist_addnoqname(dns_rdataset_t *rdataset, const dns_name_t *name) for (rdset = ISC_LIST_HEAD(name->list); rdset != NULL; rdset = ISC_LIST_NEXT(rdset, link)) { - if (rdset->rdclass != rdataset->rdclass) + if (rdset->rdclass != rdataset->rdclass) { continue; + } if (rdset->type == dns_rdatatype_nsec || - rdset->type == dns_rdatatype_nsec3) + rdset->type == dns_rdatatype_nsec3) { neg = rdset; + } } - if (neg == NULL) + if (neg == NULL) { return (ISC_R_NOTFOUND); + } for (rdset = ISC_LIST_HEAD(name->list); rdset != NULL; rdset = ISC_LIST_NEXT(rdset, link)) { if (rdset->type == dns_rdatatype_rrsig && - rdset->covers == neg->type) + rdset->covers == neg->type) { negsig = rdset; + } } - if (negsig == NULL) + if (negsig == NULL) { return (ISC_R_NOTFOUND); + } /* * Minimise ttl. */ ttl = rdataset->ttl; - if (neg->ttl < ttl) + if (neg->ttl < ttl) { ttl = neg->ttl; - if (negsig->ttl < ttl) + } + if (negsig->ttl < ttl) { ttl = negsig->ttl; + } rdataset->ttl = neg->ttl = negsig->ttl = ttl; rdataset->attributes |= DNS_RDATASETATTR_NOQNAME; rdataset->private6 = name; @@ -252,23 +263,28 @@ isc__rdatalist_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name, for (rdataset = ISC_LIST_HEAD(noqname->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (rdataset->rdclass != rdclass) + if (rdataset->rdclass != rdclass) { continue; + } if (rdataset->type == dns_rdatatype_nsec || - rdataset->type == dns_rdatatype_nsec3) + rdataset->type == dns_rdatatype_nsec3) { tneg = rdataset; + } } - if (tneg == NULL) + if (tneg == NULL) { return (ISC_R_NOTFOUND); + } for (rdataset = ISC_LIST_HEAD(noqname->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { if (rdataset->type == dns_rdatatype_rrsig && - rdataset->covers == tneg->type) + rdataset->covers == tneg->type) { tnegsig = rdataset; + } } - if (tnegsig == NULL) + if (tnegsig == NULL) { return (ISC_R_NOTFOUND); + } dns_name_clone(noqname, name); dns_rdataset_clone(tneg, neg); @@ -288,32 +304,39 @@ isc__rdatalist_addclosest(dns_rdataset_t *rdataset, const dns_name_t *name) for (rdset = ISC_LIST_HEAD(name->list); rdset != NULL; rdset = ISC_LIST_NEXT(rdset, link)) { - if (rdset->rdclass != rdataset->rdclass) + if (rdset->rdclass != rdataset->rdclass) { continue; + } if (rdset->type == dns_rdatatype_nsec || - rdset->type == dns_rdatatype_nsec3) + rdset->type == dns_rdatatype_nsec3) { neg = rdset; + } } - if (neg == NULL) + if (neg == NULL) { return (ISC_R_NOTFOUND); + } for (rdset = ISC_LIST_HEAD(name->list); rdset != NULL; rdset = ISC_LIST_NEXT(rdset, link)) { if (rdset->type == dns_rdatatype_rrsig && - rdset->covers == neg->type) + rdset->covers == neg->type) { negsig = rdset; + } } - if (negsig == NULL) + if (negsig == NULL) { return (ISC_R_NOTFOUND); + } /* * Minimise ttl. */ ttl = rdataset->ttl; - if (neg->ttl < ttl) + if (neg->ttl < ttl) { ttl = neg->ttl; - if (negsig->ttl < ttl) + } + if (negsig->ttl < ttl) { ttl = negsig->ttl; + } rdataset->ttl = neg->ttl = negsig->ttl = ttl; rdataset->attributes |= DNS_RDATASETATTR_CLOSEST; rdataset->private7 = name; @@ -339,23 +362,28 @@ isc__rdatalist_getclosest(dns_rdataset_t *rdataset, dns_name_t *name, for (rdataset = ISC_LIST_HEAD(closest->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (rdataset->rdclass != rdclass) + if (rdataset->rdclass != rdclass) { continue; + } if (rdataset->type == dns_rdatatype_nsec || - rdataset->type == dns_rdatatype_nsec3) + rdataset->type == dns_rdatatype_nsec3) { tneg = rdataset; + } } - if (tneg == NULL) + if (tneg == NULL) { return (ISC_R_NOTFOUND); + } for (rdataset = ISC_LIST_HEAD(closest->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { if (rdataset->type == dns_rdatatype_rrsig && - rdataset->covers == tneg->type) + rdataset->covers == tneg->type) { tnegsig = rdataset; + } } - if (tnegsig == NULL) + if (tnegsig == NULL) { return (ISC_R_NOTFOUND); + } dns_name_clone(closest, name); dns_rdataset_clone(tneg, neg); @@ -378,9 +406,9 @@ isc__rdatalist_setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) for (i = 1; i < name->length; i++) { if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a) { rdatalist->upper[i / 8] |= 1 << (i % 8); - /* - * Record that upper has been set. - */ + /* + * Record that upper has been set. + */ } } /* @@ -396,17 +424,19 @@ isc__rdatalist_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) unsigned int i; rdatalist = rdataset->private1; - if ((rdatalist->upper[0] & 0x01) == 0) + if ((rdatalist->upper[0] & 0x01) == 0) { return; + } for (i = 0; i < name->length; i++) { /* * Set the case bit if it does not match the recorded bit. */ if (name->ndata[i] >= 0x61 && name->ndata[i] <= 0x7a && - (rdatalist->upper[i / 8] & (1 << (i % 8))) != 0) + (rdatalist->upper[i / 8] & (1 << (i % 8))) != 0) { name->ndata[i] &= ~0x20; /* clear the lower case bit */ - else if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a && - (rdatalist->upper[i / 8] & (1 << (i % 8))) == 0) + } else if (name->ndata[i] >= 0x41 && name->ndata[i] <= 0x5a && + (rdatalist->upper[i / 8] & (1 << (i % 8))) == 0) { name->ndata[i] |= 0x20; /* set the lower case bit */ + } } } diff --git a/lib/dns/rdataset.c b/lib/dns/rdataset.c index dbd517382d..0ed4a29cb8 100644 --- a/lib/dns/rdataset.c +++ b/lib/dns/rdataset.c @@ -39,8 +39,9 @@ static const char *trustnames[] = { const char * dns_trust_totext(dns_trust_t trust) { - if (trust >= sizeof(trustnames) / sizeof(*trustnames)) + if (trust >= sizeof(trustnames) / sizeof(*trustnames)) { return ("bad"); + } return (trustnames[trust]); } @@ -138,8 +139,9 @@ dns_rdataset_isassociated(dns_rdataset_t *rdataset) REQUIRE(DNS_RDATASET_VALID(rdataset)); - if (rdataset->methods != NULL) + if (rdataset->methods != NULL) { return (true); + } return (false); } @@ -365,17 +367,20 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, * This is a negative caching rdataset. */ unsigned int ncache_opts = 0; - if ((options & DNS_RDATASETTOWIRE_OMITDNSSEC) != 0) + if ((options & DNS_RDATASETTOWIRE_OMITDNSSEC) != 0) { ncache_opts |= DNS_NCACHETOWIRE_OMITDNSSEC; + } return (dns_ncache_towire(rdataset, cctx, target, ncache_opts, countp)); } else { count = (rdataset->methods->count)(rdataset); result = dns_rdataset_first(rdataset); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } } /* @@ -467,12 +472,14 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, rrbuffer = *target; dns_compress_setmethods(cctx, DNS_COMPRESS_GLOBAL14); result = dns_name_towire2(name, cctx, target, &offset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto rollback; + } headlen = sizeof(dns_rdataclass_t) + sizeof(dns_rdatatype_t); - if (!question) - headlen += sizeof(dns_ttl_t) + 2; /* XXX 2 for rdata len - */ + if (!question) { + headlen += sizeof(dns_ttl_t) + 2; + } /* XXX 2 for rdata len + */ isc_buffer_availableregion(target, &r); if (r.length < headlen) { result = ISC_R_NOSPACE; @@ -501,8 +508,9 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, dns_rdataset_current(rdataset, &rdata); } result = dns_rdata_towire(&rdata, cctx, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto rollback; + } INSIST((target->used >= rdlen.used + 2) && (target->used - rdlen.used - 2 < 65536)); isc_buffer_putuint16( @@ -513,17 +521,19 @@ towiresorted(dns_rdataset_t *rdataset, const dns_name_t *owner_name, if (shuffle || sort) { i++; - if (i == count) + if (i == count) { result = ISC_R_NOMORE; - else + } else { result = ISC_R_SUCCESS; + } } else { result = dns_rdataset_next(rdataset); } } while (result == ISC_R_SUCCESS); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto rollback; + } *countp += count; @@ -544,10 +554,12 @@ rollback: *target = savedbuffer; cleanup: - if (out != NULL && out != out_fixed) + if (out != NULL && out != out_fixed) { isc_mem_put(cctx->mctx, out, count * sizeof(*out)); - if (in != NULL && in != in_fixed) + } + if (in != NULL && in != in_fixed) { isc_mem_put(cctx->mctx, in, count * sizeof(*in)); + } return (result); } @@ -599,19 +611,22 @@ dns_rdataset_additionaldata(dns_rdataset_t * rdataset, REQUIRE((rdataset->attributes & DNS_RDATASETATTR_QUESTION) == 0); result = dns_rdataset_first(rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } do { dns_rdataset_current(rdataset, &rdata); result = dns_rdata_additionaldata(&rdata, add, arg); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_rdataset_next(rdataset); + } dns_rdata_reset(&rdata); } while (result == ISC_R_SUCCESS); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } return (ISC_R_SUCCESS); } @@ -621,8 +636,9 @@ dns_rdataset_addnoqname(dns_rdataset_t *rdataset, dns_name_t *name) { REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->addnoqname == NULL) + if (rdataset->methods->addnoqname == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((rdataset->methods->addnoqname)(rdataset, name)); } @@ -633,8 +649,9 @@ dns_rdataset_getnoqname(dns_rdataset_t *rdataset, dns_name_t *name, REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->getnoqname == NULL) + if (rdataset->methods->getnoqname == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((rdataset->methods->getnoqname)(rdataset, name, neg, negsig)); } @@ -643,8 +660,9 @@ dns_rdataset_addclosest(dns_rdataset_t *rdataset, const dns_name_t *name) { REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->addclosest == NULL) + if (rdataset->methods->addclosest == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((rdataset->methods->addclosest)(rdataset, name)); } @@ -655,8 +673,9 @@ dns_rdataset_getclosest(dns_rdataset_t *rdataset, dns_name_t *name, REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->getclosest == NULL) + if (rdataset->methods->getclosest == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((rdataset->methods->getclosest)(rdataset, name, neg, negsig)); } @@ -666,10 +685,11 @@ dns_rdataset_settrust(dns_rdataset_t *rdataset, dns_trust_t trust) REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->settrust != NULL) + if (rdataset->methods->settrust != NULL) { (rdataset->methods->settrust)(rdataset, trust); - else + } else { rdataset->trust = trust; + } } void @@ -678,8 +698,9 @@ dns_rdataset_expire(dns_rdataset_t *rdataset) REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->expire != NULL) + if (rdataset->methods->expire != NULL) { (rdataset->methods->expire)(rdataset); + } } void @@ -688,8 +709,9 @@ dns_rdataset_clearprefetch(dns_rdataset_t *rdataset) REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->clearprefetch != NULL) + if (rdataset->methods->clearprefetch != NULL) { (rdataset->methods->clearprefetch)(rdataset); + } } void @@ -698,8 +720,9 @@ dns_rdataset_setownercase(dns_rdataset_t *rdataset, const dns_name_t *name) REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->setownercase != NULL) + if (rdataset->methods->setownercase != NULL) { (rdataset->methods->setownercase)(rdataset, name); + } } void @@ -708,8 +731,9 @@ dns_rdataset_getownercase(const dns_rdataset_t *rdataset, dns_name_t *name) REQUIRE(DNS_RDATASET_VALID(rdataset)); REQUIRE(rdataset->methods != NULL); - if (rdataset->methods->getownercase != NULL) + if (rdataset->methods->getownercase != NULL) { (rdataset->methods->getownercase)(rdataset, name); + } } void @@ -728,10 +752,11 @@ dns_rdataset_trimttl(dns_rdataset_t *rdataset, dns_rdataset_t *sigrdataset, */ if (acceptexpired && (isc_serial_le(rrsig->timeexpire, ((now + 120) & 0xffffffff)) || - isc_serial_le(rrsig->timeexpire, now))) + isc_serial_le(rrsig->timeexpire, now))) { ttl = 120; - else if (isc_serial_ge(rrsig->timeexpire, now)) + } else if (isc_serial_ge(rrsig->timeexpire, now)) { ttl = rrsig->timeexpire - now; + } ttl = ISC_MIN(ISC_MIN(rdataset->ttl, sigrdataset->ttl), ISC_MIN(rrsig->originalttl, ttl)); @@ -747,8 +772,9 @@ dns_rdataset_addglue(dns_rdataset_t *rdataset, dns_dbversion_t *version, REQUIRE(rdataset->methods != NULL); REQUIRE(rdataset->type == dns_rdatatype_ns); - if (rdataset->methods->addglue == NULL) + if (rdataset->methods->addglue == NULL) { return (ISC_R_NOTIMPLEMENTED); + } return ((rdataset->methods->addglue)(rdataset, version, msg)); } diff --git a/lib/dns/rdataslab.c b/lib/dns/rdataslab.c index 30464e8ce5..0dd2be15dd 100644 --- a/lib/dns/rdataslab.c +++ b/lib/dns/rdataslab.c @@ -89,8 +89,9 @@ fillin_offsets(unsigned char *offsetbase, unsigned int *offsettable, unsigned char *raw; for (i = 0, j = 0; i < length; i++) { - if (offsettable[i] == 0) + if (offsettable[i] == 0) { continue; + } /* * Fill in offset table. @@ -109,7 +110,7 @@ fillin_offsets(unsigned char *offsetbase, unsigned int *offsettable, *raw = j++ & 0xff; } } -#endif +#endif /* if DNS_RDATASET_FIXED */ isc_result_t dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, @@ -124,7 +125,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, unsigned char * rawbuf; #if DNS_RDATASET_FIXED unsigned char *offsetbase; -#endif +#endif /* if DNS_RDATASET_FIXED */ unsigned int buflen; isc_result_t result; unsigned int nitems; @@ -132,7 +133,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, unsigned int i; #if DNS_RDATASET_FIXED unsigned int *offsettable; -#endif +#endif /* if DNS_RDATASET_FIXED */ unsigned int length; buflen = reservelen + 2; @@ -144,8 +145,9 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, * with zero a record count. */ if (nitems == 0) { - if (rdataset->type != 0) + if (rdataset->type != 0) { return (ISC_R_FAILURE); + } rawbuf = isc_mem_get(mctx, buflen); region->base = rawbuf; region->length = buflen; @@ -155,8 +157,9 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, return (ISC_R_SUCCESS); } - if (nitems > 0xffff) + if (nitems > 0xffff) { return (ISC_R_NOSPACE); + } /* * Remember the original number of items. @@ -168,8 +171,9 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, * Save all of the rdata members into an array. */ result = dns_rdataset_first(rdataset); - if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) + if (result != ISC_R_SUCCESS && result != ISC_R_NOMORE) { goto free_rdatas; + } for (i = 0; i < nalloc && result == ISC_R_SUCCESS; i++) { INSIST(result == ISC_R_SUCCESS); dns_rdata_init(&x[i].rdata); @@ -177,7 +181,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, INSIST(x[i].rdata.data != &removed); #if DNS_RDATASET_FIXED x[i].order = i; -#endif +#endif /* if DNS_RDATASET_FIXED */ result = dns_rdataset_next(rdataset); } if (i != nalloc || result != ISC_R_NOMORE) { @@ -194,8 +198,9 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, /* * Put into DNSSEC order. */ - if (nalloc > 1U) + if (nalloc > 1U) { qsort(x, nalloc, sizeof(struct xrdata), compare_rdata); + } /* * Remove duplicates and compute the total storage required. @@ -214,21 +219,23 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, * Preserve the least order so A, B, A -> A, B * after duplicate removal. */ - if (x[i - 1].order < x[i].order) + if (x[i - 1].order < x[i].order) { x[i].order = x[i - 1].order; -#endif + } +#endif /* if DNS_RDATASET_FIXED */ nitems--; } else { #if DNS_RDATASET_FIXED buflen += (8 + x[i - 1].rdata.length); -#else +#else /* if DNS_RDATASET_FIXED */ buflen += (2 + x[i - 1].rdata.length); -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Provide space to store the per RR meta data. */ - if (rdataset->type == dns_rdatatype_rrsig) + if (rdataset->type == dns_rdatatype_rrsig) { buflen++; + } } } @@ -237,14 +244,15 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, */ #if DNS_RDATASET_FIXED buflen += (8 + x[i - 1].rdata.length); -#else +#else /* if DNS_RDATASET_FIXED */ buflen += (2 + x[i - 1].rdata.length); -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Provide space to store the per RR meta data. */ - if (rdataset->type == dns_rdatatype_rrsig) + if (rdataset->type == dns_rdatatype_rrsig) { buflen++; + } /* * Ensure that singleton types are actually singletons. @@ -268,7 +276,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, /* Allocate temporary offset table. */ offsettable = isc_mem_get(mctx, nalloc * sizeof(unsigned int)); memset(offsettable, 0, nalloc * sizeof(unsigned int)); -#endif +#endif /* if DNS_RDATASET_FIXED */ region->base = rawbuf; region->length = buflen; @@ -278,7 +286,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, #if DNS_RDATASET_FIXED offsetbase = rawbuf; -#endif +#endif /* if DNS_RDATASET_FIXED */ *rawbuf++ = (nitems & 0xff00) >> 8; *rawbuf++ = (nitems & 0x00ff); @@ -286,23 +294,25 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, #if DNS_RDATASET_FIXED /* Skip load order table. Filled in later. */ rawbuf += nitems * 4; -#endif +#endif /* if DNS_RDATASET_FIXED */ for (i = 0; i < nalloc; i++) { - if (x[i].rdata.data == &removed) + if (x[i].rdata.data == &removed) { continue; + } #if DNS_RDATASET_FIXED offsettable[x[i].order] = rawbuf - offsetbase; -#endif +#endif /* if DNS_RDATASET_FIXED */ length = x[i].rdata.length; - if (rdataset->type == dns_rdatatype_rrsig) + if (rdataset->type == dns_rdatatype_rrsig) { length++; + } INSIST(length <= 0xffff); *rawbuf++ = (length & 0xff00) >> 8; *rawbuf++ = (length & 0x00ff); #if DNS_RDATASET_FIXED rawbuf += 2; /* filled in later */ -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Store the per RR meta data. */ @@ -318,7 +328,7 @@ dns_rdataslab_fromrdataset(dns_rdataset_t *rdataset, isc_mem_t *mctx, #if DNS_RDATASET_FIXED fillin_offsets(offsetbase, offsettable, nalloc); isc_mem_put(mctx, offsettable, nalloc * sizeof(unsigned int)); -#endif +#endif /* if DNS_RDATASET_FIXED */ result = ISC_R_SUCCESS; @@ -340,16 +350,16 @@ dns_rdataslab_size(unsigned char *slab, unsigned int reservelen) count += *current++; #if DNS_RDATASET_FIXED current += (4 * count); -#endif +#endif /* if DNS_RDATASET_FIXED */ while (count > 0) { count--; length = *current++ * 256; length += *current++; #if DNS_RDATASET_FIXED current += length + 2; -#else +#else /* if DNS_RDATASET_FIXED */ current += length; -#endif +#endif /* if DNS_RDATASET_FIXED */ } return ((unsigned int)(current - slab)); @@ -388,20 +398,22 @@ rdata_from_slab(unsigned char **current, dns_rdataclass_t rdclass, length += *tcurrent++; if (type == dns_rdatatype_rrsig) { - if ((*tcurrent & DNS_RDATASLAB_OFFLINE) != 0) + if ((*tcurrent & DNS_RDATASLAB_OFFLINE) != 0) { offline = true; + } length--; tcurrent++; } region.length = length; #if DNS_RDATASET_FIXED tcurrent += 2; -#endif +#endif /* if DNS_RDATASET_FIXED */ region.base = tcurrent; tcurrent += region.length; dns_rdata_fromregion(rdata, rdclass, type, ®ion); - if (offline) + if (offline) { rdata->flags |= DNS_RDATA_OFFLINE; + } *current = tcurrent; } @@ -426,16 +438,18 @@ rdata_in_slab(unsigned char *slab, unsigned int reservelen, #if DNS_RDATASET_FIXED current += (4 * count); -#endif +#endif /* if DNS_RDATASET_FIXED */ for (i = 0; i < count; i++) { rdata_from_slab(¤t, rdclass, type, &trdata); n = dns_rdata_compare(&trdata, rdata); - if (n == 0) + if (n == 0) { return (true); - if (n > 0) /* In DNSSEC order. */ + } + if (n > 0) { /* In DNSSEC order. */ break; + } dns_rdata_reset(&trdata); } return (false); @@ -461,7 +475,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, unsigned int oorder = 0; unsigned char *offsetbase; unsigned int * offsettable; -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * XXX Need parameter to allow "delete rdatasets in nslab" merge, @@ -476,19 +490,19 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, ocount += *ocurrent++; #if DNS_RDATASET_FIXED ocurrent += (4 * ocount); -#endif +#endif /* if DNS_RDATASET_FIXED */ ostart = ocurrent; ncurrent = nslab + reservelen; ncount = *ncurrent++ * 256; ncount += *ncurrent++; #if DNS_RDATASET_FIXED ncurrent += (4 * ncount); -#endif +#endif /* if DNS_RDATASET_FIXED */ INSIST(ocount > 0 && ncount > 0); #if DNS_RDATASET_FIXED oncount = ncount; -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Yes, this is inefficient! @@ -504,10 +518,10 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, #if DNS_RDATASET_FIXED olength += length + 8; ocurrent += length + 2; -#else +#else /* if DNS_RDATASET_FIXED */ olength += length + 2; ocurrent += length; -#endif +#endif /* if DNS_RDATASET_FIXED */ } /* @@ -529,11 +543,12 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, */ #if DNS_RDATASET_FIXED tlength += nrdata.length + 8; -#else +#else /* if DNS_RDATASET_FIXED */ tlength += nrdata.length + 2; -#endif - if (type == dns_rdatatype_rrsig) +#endif /* if DNS_RDATASET_FIXED */ + if (type == dns_rdatatype_rrsig) { tlength++; + } tcount++; nncount++; added_something = true; @@ -542,11 +557,14 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, } while (ncount > 0); ncount = nncount; - if (((flags & DNS_RDATASLAB_EXACT) != 0) && (tcount != ncount + ocount)) + if (((flags & DNS_RDATASLAB_EXACT) != 0) && + (tcount != ncount + ocount)) { return (DNS_R_NOTEXACT); + } - if (!added_something && (flags & DNS_RDATASLAB_FORCE) == 0) + if (!added_something && (flags & DNS_RDATASLAB_FORCE) == 0) { return (DNS_R_UNCHANGED); + } /* * Ensure that singleton types are actually singletons. @@ -559,8 +577,9 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, return (DNS_R_SINGLETON); } - if (tcount > 0xffff) + if (tcount > 0xffff) { return (ISC_R_NOSPACE); + } /* * Copy the reserved area from the new slab. @@ -570,7 +589,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, tcurrent = tstart + reservelen; #if DNS_RDATASET_FIXED offsetbase = tcurrent; -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Write the new count. @@ -587,7 +606,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, offsettable = isc_mem_get(mctx, (ocount + oncount) * sizeof(unsigned int)); memset(offsettable, 0, (ocount + oncount) * sizeof(unsigned int)); -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Merge the two slabs. @@ -597,13 +616,13 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, #if DNS_RDATASET_FIXED oorder = ocurrent[2] * 256 + ocurrent[3]; INSIST(oorder < ocount); -#endif +#endif /* if DNS_RDATASET_FIXED */ rdata_from_slab(&ocurrent, rdclass, type, &ordata); ncurrent = nslab + reservelen + 2; #if DNS_RDATASET_FIXED ncurrent += (4 * oncount); -#endif +#endif /* if DNS_RDATASET_FIXED */ if (ncount > 0) { do { @@ -612,7 +631,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, norder = ncurrent[2] * 256 + ncurrent[3]; INSIST(norder < oncount); -#endif +#endif /* if DNS_RDATASET_FIXED */ rdata_from_slab(&ncurrent, rdclass, type, &nrdata); } while (rdata_in_slab(oslab, reservelen, rdclass, type, &nrdata)); @@ -620,16 +639,17 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, while (oadded < ocount || nadded < ncount) { bool fromold; - if (oadded == ocount) + if (oadded == ocount) { fromold = false; - else if (nadded == ncount) + } else if (nadded == ncount) { fromold = true; - else + } else { fromold = (dns_rdata_compare(&ordata, &nrdata) < 0); + } if (fromold) { #if DNS_RDATASET_FIXED offsettable[oorder] = tcurrent - offsetbase; -#endif +#endif /* if DNS_RDATASET_FIXED */ length = ordata.length; data = ordata.data; if (type == dns_rdatatype_rrsig) { @@ -640,7 +660,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, *tcurrent++ = (length & 0x00ff); #if DNS_RDATASET_FIXED tcurrent += 2; /* fill in later */ -#endif +#endif /* if DNS_RDATASET_FIXED */ memmove(tcurrent, data, length); tcurrent += length; oadded++; @@ -649,14 +669,14 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, #if DNS_RDATASET_FIXED oorder = ocurrent[2] * 256 + ocurrent[3]; INSIST(oorder < ocount); -#endif +#endif /* if DNS_RDATASET_FIXED */ rdata_from_slab(&ocurrent, rdclass, type, &ordata); } } else { #if DNS_RDATASET_FIXED offsettable[ocount + norder] = tcurrent - offsetbase; -#endif +#endif /* if DNS_RDATASET_FIXED */ length = nrdata.length; data = nrdata.data; if (type == dns_rdatatype_rrsig) { @@ -667,7 +687,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, *tcurrent++ = (length & 0x00ff); #if DNS_RDATASET_FIXED tcurrent += 2; /* fill in later */ -#endif +#endif /* if DNS_RDATASET_FIXED */ memmove(tcurrent, data, length); tcurrent += length; nadded++; @@ -678,7 +698,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, norder = ncurrent[2] * 256 + ncurrent[3]; INSIST(norder < oncount); -#endif +#endif /* if DNS_RDATASET_FIXED */ rdata_from_slab(&ncurrent, rdclass, type, &nrdata); } while (rdata_in_slab(oslab, reservelen, @@ -692,7 +712,7 @@ dns_rdataslab_merge(unsigned char *oslab, unsigned char *nslab, isc_mem_put(mctx, offsettable, (ocount + oncount) * sizeof(unsigned int)); -#endif +#endif /* if DNS_RDATASET_FIXED */ INSIST(tcurrent == tstart + tlength); @@ -715,7 +735,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, unsigned char *offsetbase; unsigned int * offsettable; unsigned int order; -#endif +#endif /* if DNS_RDATASET_FIXED */ REQUIRE(tslabp != NULL && *tslabp == NULL); REQUIRE(mslab != NULL && sslab != NULL); @@ -742,7 +762,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, #if DNS_RDATASET_FIXED mcurrent += 4 * mcount; scurrent += 4 * scount; -#endif +#endif /* if DNS_RDATASET_FIXED */ sstart = scurrent; /* @@ -756,8 +776,9 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, for (count = 0; count < scount; count++) { dns_rdata_reset(&srdata); rdata_from_slab(&scurrent, rdclass, type, &srdata); - if (dns_rdata_compare(&mrdata, &srdata) == 0) + if (dns_rdata_compare(&mrdata, &srdata) == 0) { break; + } } if (count == scount) { /* @@ -766,33 +787,37 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, */ tlength += (unsigned int)(mcurrent - mrdatabegin); tcount++; - } else + } else { rcount++; + } dns_rdata_reset(&mrdata); } #if DNS_RDATASET_FIXED tlength += (4 * tcount); -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Check that all the records originally existed. The numeric * check only works as rdataslabs do not contain duplicates. */ - if (((flags & DNS_RDATASLAB_EXACT) != 0) && (rcount != scount)) + if (((flags & DNS_RDATASLAB_EXACT) != 0) && (rcount != scount)) { return (DNS_R_NOTEXACT); + } /* * Don't continue if the new rdataslab would be empty. */ - if (tcount == 0) + if (tcount == 0) { return (DNS_R_NXRRSET); + } /* * If nothing is going to change, we can stop. */ - if (rcount == 0) + if (rcount == 0) { return (DNS_R_UNCHANGED); + } /* * Copy the reserved area from the mslab. @@ -805,7 +830,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, offsettable = isc_mem_get(mctx, mcount * sizeof(unsigned int)); memset(offsettable, 0, mcount * sizeof(unsigned int)); -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Write the new count. @@ -815,7 +840,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, #if DNS_RDATASET_FIXED tcurrent += (4 * tcount); -#endif +#endif /* if DNS_RDATASET_FIXED */ /* * Copy the parts of mslab not in sslab. @@ -825,20 +850,21 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, mcount += *mcurrent++; #if DNS_RDATASET_FIXED mcurrent += (4 * mcount); -#endif +#endif /* if DNS_RDATASET_FIXED */ for (i = 0; i < mcount; i++) { unsigned char *mrdatabegin = mcurrent; #if DNS_RDATASET_FIXED order = mcurrent[2] * 256 + mcurrent[3]; INSIST(order < mcount); -#endif +#endif /* if DNS_RDATASET_FIXED */ rdata_from_slab(&mcurrent, rdclass, type, &mrdata); scurrent = sstart; for (count = 0; count < scount; count++) { dns_rdata_reset(&srdata); rdata_from_slab(&scurrent, rdclass, type, &srdata); - if (dns_rdata_compare(&mrdata, &srdata) == 0) + if (dns_rdata_compare(&mrdata, &srdata) == 0) { break; + } } if (count == scount) { /* @@ -849,7 +875,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, length = (unsigned int)(mcurrent - mrdatabegin); #if DNS_RDATASET_FIXED offsettable[order] = tcurrent - offsetbase; -#endif +#endif /* if DNS_RDATASET_FIXED */ memmove(tcurrent, mrdatabegin, length); tcurrent += length; } @@ -860,7 +886,7 @@ dns_rdataslab_subtract(unsigned char *mslab, unsigned char *sslab, fillin_offsets(offsetbase, offsettable, mcount); isc_mem_put(mctx, offsettable, mcount * sizeof(unsigned int)); -#endif +#endif /* if DNS_RDATASET_FIXED */ INSIST(tcurrent == tstart + tlength); @@ -885,13 +911,14 @@ dns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2, count2 = *current2++ * 256; count2 += *current2++; - if (count1 != count2) + if (count1 != count2) { return (false); + } #if DNS_RDATASET_FIXED current1 += (4 * count1); current2 += (4 * count2); -#endif +#endif /* if DNS_RDATASET_FIXED */ while (count1 > 0) { length1 = *current1++ * 256; @@ -903,11 +930,12 @@ dns_rdataslab_equal(unsigned char *slab1, unsigned char *slab2, #if DNS_RDATASET_FIXED current1 += 2; current2 += 2; -#endif +#endif /* if DNS_RDATASET_FIXED */ if (length1 != length2 || - memcmp(current1, current2, length1) != 0) + memcmp(current1, current2, length1) != 0) { return (false); + } current1 += length1; current2 += length1; @@ -935,19 +963,21 @@ dns_rdataslab_equalx(unsigned char *slab1, unsigned char *slab2, count2 = *current2++ * 256; count2 += *current2++; - if (count1 != count2) + if (count1 != count2) { return (false); + } #if DNS_RDATASET_FIXED current1 += (4 * count1); current2 += (4 * count2); -#endif +#endif /* if DNS_RDATASET_FIXED */ while (count1-- > 0) { rdata_from_slab(¤t1, rdclass, type, &rdata1); rdata_from_slab(¤t2, rdclass, type, &rdata2); - if (dns_rdata_compare(&rdata1, &rdata2) != 0) + if (dns_rdata_compare(&rdata1, &rdata2) != 0) { return (false); + } dns_rdata_reset(&rdata1); dns_rdata_reset(&rdata2); } diff --git a/lib/dns/request.c b/lib/dns/request.c index ae39f24ae2..97043d73ea 100644 --- a/lib/dns/request.c +++ b/lib/dns/request.c @@ -89,7 +89,7 @@ struct dns_request { #define DNS_REQUEST_F_SENDING 0x0002 #define DNS_REQUEST_F_CANCELED \ 0x0004 /*%< ctlevent received, or otherwise \ - synchronously canceled */ + * synchronously canceled */ #define DNS_REQUEST_F_TIMEDOUT 0x0008 /*%< canceled due to a timeout */ #define DNS_REQUEST_F_TCP 0x0010 /*%< This request used TCP */ #define DNS_REQUEST_CANCELED(r) (((r)->flags & DNS_REQUEST_F_CANCELED) != 0) @@ -179,11 +179,13 @@ dns_requestmgr_create(isc_mem_t *mctx, isc_timermgr_t *timermgr, requestmgr->taskmgr = taskmgr; requestmgr->dispatchmgr = dispatchmgr; requestmgr->dispatchv4 = NULL; - if (dispatchv4 != NULL) + if (dispatchv4 != NULL) { dns_dispatch_attach(dispatchv4, &requestmgr->dispatchv4); + } requestmgr->dispatchv6 = NULL; - if (dispatchv6 != NULL) + if (dispatchv6 != NULL) { dns_dispatch_attach(dispatchv6, &requestmgr->dispatchv6); + } requestmgr->mctx = NULL; isc_mem_attach(mctx, &requestmgr->mctx); requestmgr->eref = 1; /* implicit attach */ @@ -305,13 +307,15 @@ requestmgr_detach(dns_requestmgr_t **requestmgrp) if (requestmgr->iref == 0 && requestmgr->exiting) { INSIST(ISC_LIST_HEAD(requestmgr->requests) == NULL); send_shutdown_events(requestmgr); - if (requestmgr->eref == 0) + if (requestmgr->eref == 0) { need_destroy = true; + } } UNLOCK(&requestmgr->lock); - if (need_destroy) + if (need_destroy) { mgr_destroy(requestmgr); + } } void @@ -355,8 +359,9 @@ dns_requestmgr_detach(dns_requestmgr_t **requestmgrp) } UNLOCK(&requestmgr->lock); - if (need_destroy) + if (need_destroy) { mgr_destroy(requestmgr); + } } static void @@ -391,12 +396,15 @@ mgr_destroy(dns_requestmgr_t *requestmgr) REQUIRE(requestmgr->iref == 0); isc_mutex_destroy(&requestmgr->lock); - for (i = 0; i < DNS_REQUEST_NLOCKS; i++) + for (i = 0; i < DNS_REQUEST_NLOCKS; i++) { isc_mutex_destroy(&requestmgr->locks[i]); - if (requestmgr->dispatchv4 != NULL) + } + if (requestmgr->dispatchv4 != NULL) { dns_dispatch_detach(&requestmgr->dispatchv4); - if (requestmgr->dispatchv6 != NULL) + } + if (requestmgr->dispatchv6 != NULL) { dns_dispatch_detach(&requestmgr->dispatchv6); + } requestmgr->magic = 0; isc_mem_putanddetach(&requestmgr->mctx, requestmgr, sizeof(*requestmgr)); @@ -435,8 +443,9 @@ req_send(dns_request_t *request, isc_task_t *task, sendevent = isc_socket_socketevent(request->mctx, sock, ISC_SOCKEVENT_SENDDONE, req_senddone, request); - if (sendevent == NULL) + if (sendevent == NULL) { return (ISC_R_NOMEMORY); + } if (request->dscp == -1) { sendevent->attributes &= ~ISC_SOCKEVENTATTR_DSCP; sendevent->dscp = 0; @@ -558,8 +567,9 @@ create_tcp_dispatch(bool newtcp, bool share, dns_requestmgr_t *requestmgr, result = isc_socket_create(requestmgr->socketmgr, isc_sockaddr_pf(destaddr), isc_sockettype_tcp, &sock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } #ifndef BROKEN_TCP_BIND_BEFORE_CONNECT if (srcaddr == NULL) { isc_sockaddr_anyofpf(&bind_any, isc_sockaddr_pf(destaddr)); @@ -569,16 +579,18 @@ create_tcp_dispatch(bool newtcp, bool share, dns_requestmgr_t *requestmgr, isc_sockaddr_setport(&src, 0); result = isc_socket_bind(sock, &src, 0); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; -#endif + } +#endif /* ifndef BROKEN_TCP_BIND_BEFORE_CONNECT */ attrs = 0; attrs |= DNS_DISPATCHATTR_TCP; - if (isc_sockaddr_pf(destaddr) == AF_INET) + if (isc_sockaddr_pf(destaddr) == AF_INET) { attrs |= DNS_DISPATCHATTR_IPV4; - else + } else { attrs |= DNS_DISPATCHATTR_IPV6; + } attrs |= DNS_DISPATCHATTR_MAKEQUERY; isc_socket_dscp(sock, dscp); @@ -610,8 +622,9 @@ find_udp_dispatch(dns_requestmgr_t *requestmgr, const isc_sockaddr_t *srcaddr, default: return (ISC_R_NOTIMPLEMENTED); } - if (disp == NULL) + if (disp == NULL) { return (ISC_R_FAMILYNOSUPPORT); + } dns_dispatch_attach(disp, dispatchp); return (ISC_R_SUCCESS); } @@ -647,13 +660,14 @@ get_dispatch(bool tcp, bool newtcp, bool share, dns_requestmgr_t *requestmgr, { isc_result_t result; - if (tcp) + if (tcp) { result = create_tcp_dispatch(newtcp, share, requestmgr, srcaddr, destaddr, dscp, connected, dispatchp); - else + } else { result = find_udp_dispatch(requestmgr, srcaddr, destaddr, dispatchp); + } return (result); } @@ -670,9 +684,10 @@ set_timer(isc_timer_t *timer, unsigned int timeout, unsigned int udpresend) isc_interval_set(&interval, udpresend, 0); timertype = udpresend != 0 ? isc_timertype_limited : isc_timertype_once; - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_timer_reset(timer, timertype, &expires, &interval, false); + } return (result); } @@ -705,25 +720,29 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf, REQUIRE(action != NULL); REQUIRE(requestp != NULL && *requestp == NULL); REQUIRE(timeout > 0); - if (srcaddr != NULL) + if (srcaddr != NULL) { REQUIRE(isc_sockaddr_pf(srcaddr) == isc_sockaddr_pf(destaddr)); + } mctx = requestmgr->mctx; req_log(ISC_LOG_DEBUG(3), "dns_request_createraw"); - if (isblackholed(requestmgr->dispatchmgr, destaddr)) + if (isblackholed(requestmgr->dispatchmgr, destaddr)) { return (DNS_R_BLACKHOLED); + } request = NULL; result = new_request(mctx, &request); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (udptimeout == 0 && udpretries != 0) { udptimeout = timeout / (udpretries + 1); - if (udptimeout == 0) + if (udptimeout == 0) { udptimeout = 1; + } } request->udpcount = udpretries; request->dscp = dscp; @@ -734,8 +753,9 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf, result = isc_timer_create(requestmgr->timermgr, isc_timertype_inactive, NULL, NULL, task, req_timeout, request, &request->timer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } request->event = (dns_requestevent_t *)isc_event_allocate( mctx, task, DNS_EVENT_REQUESTDONE, action, arg, @@ -751,15 +771,17 @@ dns_request_createraw(dns_requestmgr_t *requestmgr, isc_buffer_t *msgbuf, goto cleanup; } - if ((options & DNS_REQUESTOPT_TCP) != 0 || r.length > 512) + if ((options & DNS_REQUESTOPT_TCP) != 0 || r.length > 512) { tcp = true; + } share = (options & DNS_REQUESTOPT_SHARE); again: result = get_dispatch(tcp, newtcp, share, requestmgr, srcaddr, destaddr, dscp, &connected, &request->dispatch); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } if ((options & DNS_REQUESTOPT_FIXEDID) != 0) { id = (r.base[0] << 8) | r.base[1]; @@ -783,16 +805,19 @@ again: INSIST(sock != NULL); isc_buffer_allocate(mctx, &request->query, r.length + (tcp ? 2 : 0)); - if (tcp) + if (tcp) { isc_buffer_putuint16(request->query, (uint16_t)r.length); + } result = isc_buffer_copyregion(request->query, &r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* Add message ID. */ isc_buffer_usedregion(request->query, &r); - if (tcp) + if (tcp) { isc_region_consume(&r, 2); + } r.base[0] = (id >> 8) & 0xff; r.base[1] = id & 0xff; @@ -808,20 +833,23 @@ again: UNLOCK(&requestmgr->lock); result = set_timer(request->timer, timeout, tcp ? 0 : udptimeout); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlink; + } request->destaddr = *destaddr; if (tcp && !connected) { result = isc_socket_connect(sock, destaddr, task, req_connected, request); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlink; + } request->flags |= DNS_REQUEST_F_CONNECTING | DNS_REQUEST_F_TCP; } else { result = req_send(request, task, connected ? NULL : destaddr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlink; + } } req_log(ISC_LOG_DEBUG(3), "dns_request_createraw: request %p", request); @@ -834,8 +862,9 @@ unlink: UNLOCK(&requestmgr->lock); cleanup: - if (tclone != NULL) + if (tclone != NULL) { isc_task_detach(&tclone); + } req_destroy(request); req_log(ISC_LOG_DEBUG(3), "dns_request_createraw: failed %s", dns_result_totext(result)); @@ -887,21 +916,25 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message, req_log(ISC_LOG_DEBUG(3), "dns_request_createvia"); if (srcaddr != NULL && - isc_sockaddr_pf(srcaddr) != isc_sockaddr_pf(destaddr)) + isc_sockaddr_pf(srcaddr) != isc_sockaddr_pf(destaddr)) { return (ISC_R_FAMILYMISMATCH); + } - if (isblackholed(requestmgr->dispatchmgr, destaddr)) + if (isblackholed(requestmgr->dispatchmgr, destaddr)) { return (DNS_R_BLACKHOLED); + } request = NULL; result = new_request(mctx, &request); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (udptimeout == 0 && udpretries != 0) { udptimeout = timeout / (udpretries + 1); - if (udptimeout == 0) + if (udptimeout == 0) { udptimeout = 1; + } } request->udpcount = udpretries; request->dscp = dscp; @@ -912,8 +945,9 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message, result = isc_timer_create(requestmgr->timermgr, isc_timertype_inactive, NULL, NULL, task, req_timeout, request, &request->timer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } request->event = (dns_requestevent_t *)isc_event_allocate( mctx, task, DNS_EVENT_REQUESTDONE, action, arg, @@ -922,30 +956,34 @@ dns_request_createvia(dns_requestmgr_t *requestmgr, dns_message_t *message, request->event->ev_sender = task; request->event->request = request; request->event->result = ISC_R_FAILURE; - if (key != NULL) + if (key != NULL) { dns_tsigkey_attach(key, &request->tsigkey); + } use_tcp: tcp = ((options & DNS_REQUESTOPT_TCP) != 0); share = ((options & DNS_REQUESTOPT_SHARE) != 0); result = get_dispatch(tcp, false, share, requestmgr, srcaddr, destaddr, dscp, &connected, &request->dispatch); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_dispatch_addresponse( request->dispatch, 0, destaddr, task, req_response, request, &id, &request->dispentry, requestmgr->socketmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } sock = req_getsocket(request); INSIST(sock != NULL); message->id = id; if (settsigkey) { result = dns_message_settsigkey(message, request->tsigkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } result = req_render(message, &request->query, options, mctx); if (result == DNS_R_USETCP && (options & DNS_REQUESTOPT_TCP) == 0) { @@ -960,12 +998,14 @@ use_tcp: settsigkey = false; goto use_tcp; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_getquerytsig(message, mctx, &request->tsig); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } LOCK(&requestmgr->lock); if (requestmgr->exiting) { @@ -979,20 +1019,23 @@ use_tcp: UNLOCK(&requestmgr->lock); result = set_timer(request->timer, timeout, tcp ? 0 : udptimeout); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlink; + } request->destaddr = *destaddr; if (tcp && !connected) { result = isc_socket_connect(sock, destaddr, task, req_connected, request); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlink; + } request->flags |= DNS_REQUEST_F_CONNECTING | DNS_REQUEST_F_TCP; } else { result = req_send(request, task, connected ? NULL : destaddr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlink; + } } req_log(ISC_LOG_DEBUG(3), "dns_request_createvia: request %p", request); @@ -1005,8 +1048,9 @@ unlink: UNLOCK(&requestmgr->lock); cleanup: - if (tclone != NULL) + if (tclone != NULL) { isc_task_detach(&tclone); + } req_destroy(request); req_log(ISC_LOG_DEBUG(3), "dns_request_createvia: failed %s", dns_result_totext(result)); @@ -1035,34 +1079,42 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp, unsigned int options, isc_buffer_allocate(mctx, &buf1, 65535); result = dns_compress_init(&cctx, -1, mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } cleanup_cctx = true; - if ((options & DNS_REQUESTOPT_CASE) != 0) + if ((options & DNS_REQUESTOPT_CASE) != 0) { dns_compress_setsensitive(&cctx, true); + } /* * Render message. */ result = dns_message_renderbegin(message, &cctx, buf1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_rendersection(message, DNS_SECTION_QUESTION, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_rendersection(message, DNS_SECTION_ANSWER, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_rendersection(message, DNS_SECTION_AUTHORITY, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_rendersection(message, DNS_SECTION_ADDITIONAL, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_renderend(message); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_compress_invalidate(&cctx); cleanup_cctx = false; @@ -1078,11 +1130,13 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp, unsigned int options, goto cleanup; } isc_buffer_allocate(mctx, &buf2, r.length + (tcp ? 2 : 0)); - if (tcp) + if (tcp) { isc_buffer_putuint16(buf2, (uint16_t)r.length); + } result = isc_buffer_copyregion(buf2, &r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Cleanup and return. @@ -1093,12 +1147,15 @@ req_render(dns_message_t *message, isc_buffer_t **bufferp, unsigned int options, cleanup: dns_message_renderreset(message); - if (buf1 != NULL) + if (buf1 != NULL) { isc_buffer_free(&buf1); - if (buf2 != NULL) + } + if (buf2 != NULL) { isc_buffer_free(&buf2); - if (cleanup_cctx) + } + if (cleanup_cctx) { dns_compress_invalidate(&cctx); + } return (result); } @@ -1113,8 +1170,9 @@ cleanup: static void send_if_done(dns_request_t *request, isc_result_t result) { - if (request->event != NULL && !request->canceling) + if (request->event != NULL && !request->canceling) { req_sendevent(request, result); + } } /* @@ -1128,8 +1186,9 @@ do_cancel(isc_task_t *task, isc_event_t *event) INSIST(event->ev_type == DNS_EVENT_REQUESTCONTROL); LOCK(&request->requestmgr->locks[request->hash]); request->canceling = false; - if (!DNS_REQUEST_CANCELED(request)) + if (!DNS_REQUEST_CANCELED(request)) { req_cancel(request); + } send_if_done(request, ISC_R_CANCELED); UNLOCK(&request->requestmgr->locks[request->hash]); } @@ -1165,16 +1224,20 @@ dns_request_getresponse(dns_request_t *request, dns_message_t *message, request); result = dns_message_setquerytsig(message, request->tsig); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_message_settsigkey(message, request->tsigkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_message_parse(message, request->answer, options); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (request->tsigkey != NULL) + } + if (request->tsigkey != NULL) { result = dns_tsig_verify(request->answer, message, NULL, NULL); + } return (result); } @@ -1240,8 +1303,9 @@ req_getsocket(dns_request_t *request) if ((dispattr & DNS_DISPATCHATTR_EXCLUSIVE) != 0) { INSIST(request->dispentry != NULL); sock = dns_dispatch_getentrysocket(request->dispentry); - } else + } else { sock = dns_dispatch_getsocket(request->dispatch); + } return (sock); } @@ -1266,15 +1330,17 @@ req_connected(isc_task_t *task, isc_event_t *event) /* * Send delayed event. */ - if (DNS_REQUEST_TIMEDOUT(request)) + if (DNS_REQUEST_TIMEDOUT(request)) { send_if_done(request, ISC_R_TIMEDOUT); - else + } else { send_if_done(request, ISC_R_CANCELED); + } } else { dns_dispatch_starttcp(request->dispatch); result = sevent->result; - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = req_send(request, task, NULL); + } if (result != ISC_R_SUCCESS) { req_cancel(request); @@ -1306,10 +1372,11 @@ req_senddone(isc_task_t *task, isc_event_t *event) /* * Send delayed event. */ - if (DNS_REQUEST_TIMEDOUT(request)) + if (DNS_REQUEST_TIMEDOUT(request)) { send_if_done(request, ISC_R_TIMEDOUT); - else + } else { send_if_done(request, ISC_R_CANCELED); + } } else if (sevent->result != ISC_R_SUCCESS) { req_cancel(request); send_if_done(request, ISC_R_CANCELED); @@ -1337,8 +1404,9 @@ req_response(isc_task_t *task, isc_event_t *event) LOCK(&request->requestmgr->locks[request->hash]); result = devent->result; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } /* * Copy buffer to request. @@ -1346,8 +1414,9 @@ req_response(isc_task_t *task, isc_event_t *event) isc_buffer_usedregion(&devent->buffer, &r); isc_buffer_allocate(request->mctx, &request->answer, r.length); result = isc_buffer_copyregion(request->answer, &r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_buffer_free(&request->answer); + } done: /* * Cleanup. @@ -1416,24 +1485,33 @@ req_destroy(dns_request_t *request) req_log(ISC_LOG_DEBUG(3), "req_destroy: request %p", request); request->magic = 0; - if (request->query != NULL) + if (request->query != NULL) { isc_buffer_free(&request->query); - if (request->answer != NULL) + } + if (request->answer != NULL) { isc_buffer_free(&request->answer); - if (request->event != NULL) + } + if (request->event != NULL) { isc_event_free((isc_event_t **)&request->event); - if (request->dispentry != NULL) + } + if (request->dispentry != NULL) { dns_dispatch_removeresponse(&request->dispentry, NULL); - if (request->dispatch != NULL) + } + if (request->dispatch != NULL) { dns_dispatch_detach(&request->dispatch); - if (request->timer != NULL) + } + if (request->timer != NULL) { isc_timer_detach(&request->timer); - if (request->tsig != NULL) + } + if (request->tsig != NULL) { isc_buffer_free(&request->tsig); - if (request->tsigkey != NULL) + } + if (request->tsigkey != NULL) { dns_tsigkey_detach(&request->tsigkey); - if (request->requestmgr != NULL) + } + if (request->requestmgr != NULL) { requestmgr_detach(&request->requestmgr); + } isc_mem_putanddetach(&request->mctx, request, sizeof(*request)); } @@ -1455,8 +1533,9 @@ req_cancel(dns_request_t *request) */ request->flags |= DNS_REQUEST_F_CANCELED; - if (request->timer != NULL) + if (request->timer != NULL) { isc_timer_detach(&request->timer); + } dispattr = dns_dispatch_getattributes(request->dispatch); sock = NULL; if (DNS_REQUEST_CONNECTING(request) || DNS_REQUEST_SENDING(request)) { @@ -1465,15 +1544,19 @@ req_cancel(dns_request_t *request) sock = dns_dispatch_getentrysocket( request->dispentry); } - } else + } else { sock = dns_dispatch_getsocket(request->dispatch); - if (DNS_REQUEST_CONNECTING(request) && sock != NULL) + } + if (DNS_REQUEST_CONNECTING(request) && sock != NULL) { isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT); - if (DNS_REQUEST_SENDING(request) && sock != NULL) + } + if (DNS_REQUEST_SENDING(request) && sock != NULL) { isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND); + } } - if (request->dispentry != NULL) + if (request->dispentry != NULL) { dns_dispatch_removeresponse(&request->dispentry, NULL); + } dns_dispatch_detach(&request->dispatch); } diff --git a/lib/dns/resolver.c b/lib/dns/resolver.c index c387e5cff0..c618d8cd3b 100644 --- a/lib/dns/resolver.c +++ b/lib/dns/resolver.c @@ -104,7 +104,7 @@ DNS_LOGMODULE_RESOLVER, ISC_LOG_DEBUG(3), \ "resquery %p (fctx %p(%s)): %s", query, query->fctx, \ query->fctx->info, (m)) -#else +#else /* ifdef WANT_QUERYTRACE */ #define RTRACE(m) \ do { \ UNUSED(m); \ @@ -166,27 +166,27 @@ /* The default time in seconds for the whole query to live. */ #ifndef DEFAULT_QUERY_TIMEOUT #define DEFAULT_QUERY_TIMEOUT MINIMUM_QUERY_TIMEOUT -#endif +#endif /* ifndef DEFAULT_QUERY_TIMEOUT */ /* The maximum time in seconds for the whole query to live. */ #ifndef MAXIMUM_QUERY_TIMEOUT #define MAXIMUM_QUERY_TIMEOUT 30000 -#endif +#endif /* ifndef MAXIMUM_QUERY_TIMEOUT */ /* The default maximum number of recursions to follow before giving up. */ #ifndef DEFAULT_RECURSION_DEPTH #define DEFAULT_RECURSION_DEPTH 7 -#endif +#endif /* ifndef DEFAULT_RECURSION_DEPTH */ /* The default maximum number of iterative queries to allow before giving up. */ #ifndef DEFAULT_MAX_QUERIES #define DEFAULT_MAX_QUERIES 75 -#endif +#endif /* ifndef DEFAULT_MAX_QUERIES */ /* Number of hash buckets for zone counters */ #ifndef RES_DOMAIN_BUCKETS #define RES_DOMAIN_BUCKETS 523 -#endif +#endif /* ifndef RES_DOMAIN_BUCKETS */ #define RES_NOBUCKET 0xffffffff /*% @@ -512,12 +512,12 @@ struct dns_resolver { uint16_t udpsize; #if USE_ALGLOCK isc_rwlock_t alglock; -#endif +#endif /* if USE_ALGLOCK */ dns_rbt_t *algorithms; dns_rbt_t *digests; #if USE_MBSLOCK isc_rwlock_t mbslock; -#endif +#endif /* if USE_MBSLOCK */ dns_rbt_t * mustbesecure; unsigned int spillatmax; unsigned int spillatmin; @@ -587,7 +587,7 @@ dns_resolver_setfuzzing() { dns_fuzzing_resolver = true; } -#endif +#endif /* ifdef ENABLE_AFL */ static unsigned char ip6_arpa_data[] = "\003IP6\004ARPA"; static unsigned char ip6_arpa_offsets[] = { 0, 4, 9 }; @@ -720,19 +720,24 @@ typedef struct respctx { bool aa; /* authoritative answer? */ dns_trust_t trust; /* answer trust level */ bool chaining; /* CNAME/DNAME processing? */ - bool next_server; /* give up, try the next server */ + bool next_server; /* give up, try the next server + * */ - badnstype_t broken_type; /* type of name server problem */ + badnstype_t broken_type; /* type of name server problem + * */ isc_result_t broken_server; - bool get_nameservers; /* get a new NS rrset at zone cut? */ + bool get_nameservers; /* get a new NS rrset at + * zone cut? */ bool resend; /* resend this query? */ bool nextitem; /* invalid response; keep * listening for the correct one */ bool truncated; /* response was truncated */ bool no_response; /* no response was received */ - bool glue_in_answer; /* glue may be in the answer section */ - bool ns_in_answer; /* NS may be in the answer section */ + bool glue_in_answer; /* glue may be in the answer + * section */ + bool ns_in_answer; /* NS may be in the answer + * section */ bool negative; /* is this a negative response? */ isc_stdtime_t now; /* time info */ @@ -740,7 +745,8 @@ typedef struct respctx { isc_time_t * finish; unsigned int dname_labels; - unsigned int domain_labels; /* range of permissible number of + unsigned int domain_labels; /* range of permissible number + * of * labels in a DNAME */ dns_name_t * aname; /* answer name */ @@ -758,8 +764,10 @@ typedef struct respctx { dns_name_t *soa_name; /* SOA name in a negative answer */ dns_name_t *ds_name; /* DS name in a negative answer */ - dns_name_t * found_name; /* invalid name in negative response */ - dns_rdatatype_t found_type; /* invalid type in negative response */ + dns_name_t *found_name; /* invalid name in negative + * response */ + dns_rdatatype_t found_type; /* invalid type in negative + * response */ dns_rdataset_t *opt; /* OPT rdataset */ } respctx_t; @@ -859,15 +867,17 @@ rctx_ncache(respctx_t *rctx); static inline void inc_stats(dns_resolver_t *res, isc_statscounter_t counter) { - if (res->view->resstats != NULL) + if (res->view->resstats != NULL) { isc_stats_increment(res->view->resstats, counter); + } } static inline void dec_stats(dns_resolver_t *res, isc_statscounter_t counter) { - if (res->view->resstats != NULL) + if (res->view->resstats != NULL) { isc_stats_decrement(res->view->resstats, counter); + } } static isc_result_t @@ -885,10 +895,11 @@ valcreate(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, dns_name_t *name, valarg->fctx = fctx; valarg->addrinfo = addrinfo; - if (!ISC_LIST_EMPTY(fctx->validators)) + if (!ISC_LIST_EMPTY(fctx->validators)) { valoptions |= DNS_VALIDATOR_DEFER; - else + } else { valoptions &= ~DNS_VALIDATOR_DEFER; + } result = dns_validator_create(fctx->res->view, name, type, rdataset, sigrdataset, fctx->rmessage, valoptions, @@ -900,8 +911,9 @@ valcreate(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, dns_name_t *name, fctx->validator = validator; } ISC_LIST_APPEND(fctx->validators, validator, link); - } else + } else { isc_mem_put(fctx->mctx, valarg, sizeof(*valarg)); + } return (result); } @@ -922,8 +934,9 @@ rrsig_fromchildzone(fetchctx_t *fctx, dns_rdataset_t *rdataset) RUNTIME_CHECK(result == ISC_R_SUCCESS); namereln = dns_name_fullcompare(&rrsig.signer, &fctx->domain, &order, &labels); - if (namereln == dns_namereln_subdomain) + if (namereln == dns_namereln_subdomain) { return (true); + } dns_rdata_reset(&rdata); } return (false); @@ -939,8 +952,9 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) isc_result_t result; bool keep_auth = false; - if (message->rcode == dns_rcode_nxdomain) + if (message->rcode == dns_rcode_nxdomain) { return (false); + } /* * A DS RRset can appear anywhere in a zone, even for a delegation-only @@ -987,15 +1001,17 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (!dns_name_equal(name, &fctx->name)) + if (!dns_name_equal(name, &fctx->name)) { continue; + } type = rdataset->type; /* * RRsig from child? */ if (type == dns_rdatatype_rrsig && - rrsig_fromchildzone(fctx, rdataset)) + rrsig_fromchildzone(fctx, rdataset)) { return (false); + } /* * Direct query for apex records or DS. */ @@ -1003,8 +1019,9 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) (type == dns_rdatatype_ds || type == dns_rdatatype_ns || type == dns_rdatatype_soa || - type == dns_rdatatype_dnskey)) + type == dns_rdatatype_dnskey)) { return (false); + } /* * Indirect query for apex records or DS. */ @@ -1012,8 +1029,9 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) (type == dns_rdatatype_ns || type == dns_rdatatype_ds || type == dns_rdatatype_soa || - type == dns_rdatatype_dnskey)) + type == dns_rdatatype_dnskey)) { return (false); + } } result = dns_message_nextname(message, DNS_SECTION_ANSWER); @@ -1024,12 +1042,14 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) * A NODATA response to a DS query? */ if (fctx->type == dns_rdatatype_ds && - message->counts[DNS_SECTION_ANSWER] == 0) + message->counts[DNS_SECTION_ANSWER] == 0) { return (false); + } /* Look for referral or indication of answer from child zone? */ - if (message->counts[DNS_SECTION_AUTHORITY] == 0) + if (message->counts[DNS_SECTION_AUTHORITY] == 0) { goto munge; + } result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); while (result == ISC_R_SUCCESS) { @@ -1039,19 +1059,22 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) rdataset = ISC_LIST_NEXT(rdataset, link)) { type = rdataset->type; if (type == dns_rdatatype_soa && - dns_name_equal(name, domain)) + dns_name_equal(name, domain)) { keep_auth = true; + } if (type != dns_rdatatype_ns && type != dns_rdatatype_soa && - type != dns_rdatatype_rrsig) + type != dns_rdatatype_rrsig) { continue; + } if (type == dns_rdatatype_rrsig) { - if (rrsig_fromchildzone(fctx, rdataset)) + if (rrsig_fromchildzone(fctx, rdataset)) { return (false); - else + } else { continue; + } } /* NS or SOA records. */ @@ -1066,8 +1089,9 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) * case. */ if (message->counts[DNS_SECTION_ANSWER] == 0 && - fctx->type == dns_rdatatype_any) + fctx->type == dns_rdatatype_any) { return (false); + } } else if (dns_name_issubdomain(name, domain)) { /* Referral or answer from child zone. */ return (false); @@ -1079,8 +1103,9 @@ fix_mustbedelegationornxdomain(dns_message_t *message, fetchctx_t *fctx) munge: message->rcode = dns_rcode_nxdomain; message->counts[DNS_SECTION_ANSWER] = 0; - if (!keep_auth) + if (!keep_auth) { message->counts[DNS_SECTION_AUTHORITY] = 0; + } message->counts[DNS_SECTION_ADDITIONAL] = 0; return (true); } @@ -1163,8 +1188,9 @@ resquery_destroy(resquery_t **queryp) query->magic = 0; isc_mem_put(query->mctx, query, sizeof(*query)); - if (empty) + if (empty) { empty_bucket(res); + } } /*% @@ -1266,20 +1292,21 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, */ INSIST(no_response); value = isc_random32(); - if (query->addrinfo->srtt > 800000) + if (query->addrinfo->srtt > 800000) { mask = 0x3fff; - else if (query->addrinfo->srtt > 400000) + } else if (query->addrinfo->srtt > 400000) { mask = 0x7fff; - else if (query->addrinfo->srtt > 200000) + } else if (query->addrinfo->srtt > 200000) { mask = 0xffff; - else if (query->addrinfo->srtt > 100000) + } else if (query->addrinfo->srtt > 100000) { mask = 0x1ffff; - else if (query->addrinfo->srtt > 50000) + } else if (query->addrinfo->srtt > 50000) { mask = 0x3ffff; - else if (query->addrinfo->srtt > 25000) + } else if (query->addrinfo->srtt > 25000) { mask = 0x7ffff; - else + } else { mask = 0xfffff; + } /* * Don't adjust timeout on EDNS queries unless we have @@ -1291,8 +1318,9 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, } rtt = query->addrinfo->srtt + (value & mask); - if (rtt > MAX_SINGLE_QUERY_TIMEOUT_US) + if (rtt > MAX_SINGLE_QUERY_TIMEOUT_US) { rtt = MAX_SINGLE_QUERY_TIMEOUT_US; + } /* * Replace the current RTT with our value. @@ -1311,17 +1339,17 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, * Age RTTs of servers not tried. */ isc_stdtime_get(&now); - if (finish != NULL || age_untried) + if (finish != NULL || age_untried) { for (addrinfo = ISC_LIST_HEAD(fctx->forwaddrs); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { if (UNMARKED(addrinfo)) { dns_adb_agesrtt(fctx->adb, addrinfo, now); - } } + } - if ((finish != NULL || age_untried) && TRIEDFIND(fctx)) + if ((finish != NULL || age_untried) && TRIEDFIND(fctx)) { for (find = ISC_LIST_HEAD(fctx->finds); find != NULL; find = ISC_LIST_NEXT(find, publink)) { for (addrinfo = ISC_LIST_HEAD(find->list); @@ -1329,11 +1357,11 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { if (UNMARKED(addrinfo)) { dns_adb_agesrtt(fctx->adb, addrinfo, - now); - + now); } } } + } if ((finish != NULL || age_untried) && TRIEDALT(fctx)) { for (addrinfo = ISC_LIST_HEAD(fctx->altaddrs); addrinfo != NULL; @@ -1349,7 +1377,7 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { if (UNMARKED(addrinfo)) { dns_adb_agesrtt(fctx->adb, addrinfo, - now); + now); } } } @@ -1371,42 +1399,50 @@ fctx_cancelquery(resquery_t **queryp, dns_dispatchevent_t **deventp, } else if (query->dispentry != NULL) { INSIST(query->exclusivesocket); sock = dns_dispatch_getentrysocket(query->dispentry); - if (sock != NULL) + if (sock != NULL) { isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_CONNECT); + } } } if (RESQUERY_SENDING(query)) { /* * Cancel the pending send. */ - if (query->exclusivesocket && query->dispentry != NULL) + if (query->exclusivesocket && query->dispentry != NULL) { sock = dns_dispatch_getentrysocket(query->dispentry); - else + } else { sock = dns_dispatch_getsocket(query->dispatch); - if (sock != NULL) + } + if (sock != NULL) { isc_socket_cancel(sock, NULL, ISC_SOCKCANCEL_SEND); + } } - if (query->dispentry != NULL) + if (query->dispentry != NULL) { dns_dispatch_removeresponse(&query->dispentry, deventp); + } ISC_LIST_UNLINK(fctx->queries, query, link); - if (query->tsig != NULL) + if (query->tsig != NULL) { isc_buffer_free(&query->tsig); + } - if (query->tsigkey != NULL) + if (query->tsigkey != NULL) { dns_tsigkey_detach(&query->tsigkey); + } - if (query->dispatch != NULL) + if (query->dispatch != NULL) { dns_dispatch_detach(&query->dispatch); + } - if (!(RESQUERY_CONNECTING(query) || RESQUERY_SENDING(query))) + if (!(RESQUERY_CONNECTING(query) || RESQUERY_SENDING(query))) { /* * It's safe to destroy the query now. */ resquery_destroy(&query); + } } static void @@ -1508,12 +1544,14 @@ fcount_logspill(fetchctx_t *fctx, fctxcount_t *counter) char dbuf[DNS_NAME_FORMATSIZE]; isc_stdtime_t now; - if (!isc_log_wouldlog(dns_lctx, ISC_LOG_INFO)) + if (!isc_log_wouldlog(dns_lctx, ISC_LOG_INFO)) { return; + } isc_stdtime_get(&now); - if (counter->logged > now - 60) + if (counter->logged > now - 60) { return; + } dns_name_format(&fctx->domain, dbuf, sizeof(dbuf)); @@ -1546,8 +1584,9 @@ fcount_incr(fetchctx_t *fctx, bool force) LOCK(&dbucket->lock); for (counter = ISC_LIST_HEAD(dbucket->list); counter != NULL; counter = ISC_LIST_NEXT(counter, link)) { - if (dns_name_equal(counter->domain, &fctx->domain)) + if (dns_name_equal(counter->domain, &fctx->domain)) { break; + } } if (counter == NULL) { @@ -1576,8 +1615,9 @@ fcount_incr(fetchctx_t *fctx, bool force) } UNLOCK(&dbucket->lock); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { fctx->dbucketnum = bucketnum; + } return (result); } @@ -1590,16 +1630,18 @@ fcount_decr(fetchctx_t *fctx) REQUIRE(fctx != NULL); - if (fctx->dbucketnum == RES_NOBUCKET) + if (fctx->dbucketnum == RES_NOBUCKET) { return; + } dbucket = &fctx->res->dbuckets[fctx->dbucketnum]; LOCK(&dbucket->lock); for (counter = ISC_LIST_HEAD(dbucket->list); counter != NULL; counter = ISC_LIST_NEXT(counter, link)) { - if (dns_name_equal(counter->domain, &fctx->domain)) + if (dns_name_equal(counter->domain, &fctx->domain)) { break; + } } if (counter != NULL) { @@ -1627,7 +1669,7 @@ fctx_sendevents(fetchctx_t *fctx, isc_result_t result, int line) isc_time_t now; unsigned int old_spillat; unsigned int new_spillat = 0; /* initialized to silence - compiler warnings */ + * compiler warnings */ /* * Caller must be holding the appropriate bucket lock. @@ -1651,8 +1693,9 @@ fctx_sendevents(fetchctx_t *fctx, isc_result_t result, int line) task = event->ev_sender; event->ev_sender = fctx; event->vresult = fctx->vresult; - if (!HAVE_ANSWER(fctx)) + if (!HAVE_ANSWER(fctx)) { event->result = result; + } INSIST(event->result != ISC_R_SUCCESS || dns_rdataset_isassociated(event->rdataset) || @@ -1681,8 +1724,9 @@ fctx_sendevents(fetchctx_t *fctx, isc_result_t result, int line) old_spillat = fctx->res->spillat; fctx->res->spillat += 5; if (fctx->res->spillat > fctx->res->spillatmax && - fctx->res->spillatmax != 0) + fctx->res->spillatmax != 0) { fctx->res->spillat = fctx->res->spillatmax; + } new_spillat = fctx->res->spillat; if (new_spillat != old_spillat) { logit = true; @@ -1694,11 +1738,12 @@ fctx_sendevents(fetchctx_t *fctx, isc_result_t result, int line) RUNTIME_CHECK(result == ISC_R_SUCCESS); } UNLOCK(&fctx->res->lock); - if (logit) + if (logit) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_RESOLVER, ISC_LOG_NOTICE, "clients-per-query increased to %u", new_spillat); + } } } @@ -1707,8 +1752,9 @@ log_edns(fetchctx_t *fctx) { char domainbuf[DNS_NAME_FORMATSIZE]; - if (fctx->reason == NULL) + if (fctx->reason == NULL) { return; + } /* * We do not know if fctx->domain is the actual domain the record @@ -1784,8 +1830,9 @@ process_sendevent(resquery_t *query, isc_event_t *event) * This query was canceled while the * isc_socket_sendto/connect() was in progress. */ - if (query->tcpsocket != NULL) + if (query->tcpsocket != NULL) { isc_socket_detach(&query->tcpsocket); + } destroy_query = true; } } else { @@ -1821,8 +1868,9 @@ process_sendevent(resquery_t *query, isc_event_t *event) } } - if (event->ev_type == ISC_SOCKEVENT_CONNECT) + if (event->ev_type == ISC_SOCKEVENT_CONNECT) { isc_event_free(&event); + } if (retry) { /* @@ -1831,14 +1879,16 @@ process_sendevent(resquery_t *query, isc_event_t *event) */ FCTX_ATTR_CLR(fctx, FCTX_ATTR_ADDRWAIT); result = fctx_stopidletimer(fctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fctx_done(fctx, result, __LINE__); - else + } else { fctx_try(fctx, true, false); + } } - if (destroy_query) + if (destroy_query) { resquery_destroy(&query); + } } static void @@ -1894,8 +1944,9 @@ fctx_addopt(dns_message_t *message, unsigned int version, uint16_t udpsize, result = dns_message_buildopt(message, &rdataset, version, udpsize, DNS_MESSAGEEXTFLAG_DO, ednsopts, count); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (dns_message_setopt(message, rdataset)); } @@ -1911,8 +1962,9 @@ fctx_setretryinterval(fetchctx_t *fctx, unsigned int rtt) */ if (fctx->restarts > fctx->res->nonbackofftries) { int shift = fctx->restarts - fctx->res->nonbackofftries; - if (shift > 6) + if (shift > 6) { shift = 6; + } us <<= shift; } @@ -1920,24 +1972,27 @@ fctx_setretryinterval(fetchctx_t *fctx, unsigned int rtt) * Add a fudge factor to the expected rtt based on the current * estimate. */ - if (rtt < 50000) + if (rtt < 50000) { rtt += 50000; - else if (rtt < 100000) + } else if (rtt < 100000) { rtt += 100000; - else + } else { rtt += 200000; + } /* * Always wait for at least the expected rtt. */ - if (us < rtt) + if (us < rtt) { us = rtt; + } /* * But don't ever wait for more than 10 seconds. */ - if (us > MAX_SINGLE_QUERY_TIMEOUT_US) + if (us > MAX_SINGLE_QUERY_TIMEOUT_US) { us = MAX_SINGLE_QUERY_TIMEOUT_US; + } seconds = us / US_PER_SEC; us -= seconds * US_PER_SEC; @@ -1977,13 +2032,15 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) * A forwarder needs to make multiple queries. Give it at least * a second to do these in. */ - if (ISFORWARDER(addrinfo) && srtt < 1000000) + if (ISFORWARDER(addrinfo) && srtt < 1000000) { srtt = 1000000; + } fctx_setretryinterval(fctx, srtt); result = fctx_startidletimer(fctx, &fctx->interval); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } INSIST(ISC_LIST_EMPTY(fctx->validators)); @@ -2022,14 +2079,17 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) &peer); if (result == ISC_R_SUCCESS) { result = dns_peer_getquerysource(peer, &addr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_addr = true; + } result = dns_peer_getquerydscp(peer, &dscp); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { query->dscp = dscp; + } result = dns_peer_getforcetcp(peer, &usetcp); - if (result == ISC_R_SUCCESS && usetcp) + if (result == ISC_R_SUCCESS && usetcp) { query->options |= DNS_FETCHOPT_TCP; + } } } @@ -2054,24 +2114,28 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) result = ISC_R_NOTIMPLEMENTED; break; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_query; + } } isc_sockaddr_setport(&addr, 0); - if (query->dscp == -1) + if (query->dscp == -1) { query->dscp = dscp; + } result = isc_socket_create(res->socketmgr, pf, isc_sockettype_tcp, &query->tcpsocket); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_query; + } #ifndef BROKEN_TCP_BIND_BEFORE_CONNECT result = isc_socket_bind(query->tcpsocket, &addr, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_socket; -#endif + } +#endif /* ifndef BROKEN_TCP_BIND_BEFORE_CONNECT */ /* * A dispatch will be created once the connect succeeds. */ @@ -2100,8 +2164,9 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) res->dispatchmgr, res->socketmgr, res->taskmgr, &addr, 4096, 20000, 32768, 16411, 16433, attrs, attrmask, &query->dispatch); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_query; + } } else { switch (isc_sockaddr_pf(&addrinfo->sockaddr)) { case PF_INET: @@ -2124,8 +2189,9 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) } } - if (query->dscp == -1) + if (query->dscp == -1) { query->dscp = dscp; + } /* * We should always have a valid dispatcher here. If we * don't support a protocol family, then its dispatcher @@ -2149,25 +2215,29 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) * * XXXRTH Should we attach to the socket? */ - if (query->dscp != -1) + if (query->dscp != -1) { isc_socket_dscp(query->tcpsocket, query->dscp); + } result = isc_socket_connect(query->tcpsocket, &addrinfo->sockaddr, task, resquery_connected, query); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_socket; + } query->connects++; QTRACE("connecting via TCP"); } else { - if (dns_adbentry_overquota(addrinfo->entry)) + if (dns_adbentry_overquota(addrinfo->entry)) { goto cleanup_dispatch; + } /* Inform the ADB that we're starting a UDP fetch */ dns_adb_beginudpfetch(fctx->adb, addrinfo); result = resquery_send(query); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_dispatch; + } } fctx->querysent++; @@ -2177,13 +2247,15 @@ fctx_query(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unsigned int options) LOCK(&res->buckets[bucketnum].lock); fctx->nqueries++; UNLOCK(&res->buckets[bucketnum].lock); - if (isc_sockaddr_pf(&addrinfo->sockaddr) == PF_INET) + if (isc_sockaddr_pf(&addrinfo->sockaddr) == PF_INET) { inc_stats(res, dns_resstatscounter_queryv4); - else + } else { inc_stats(res, dns_resstatscounter_queryv6); - if (res->view->resquerystats != NULL) + } + if (res->view->resquerystats != NULL) { dns_rdatatypestats_increment(res->view->resquerystats, fctx->type); + } return (ISC_R_SUCCESS); @@ -2191,8 +2263,9 @@ cleanup_socket: isc_socket_detach(&query->tcpsocket); cleanup_dispatch: - if (query->dispatch != NULL) + if (query->dispatch != NULL) { dns_dispatch_detach(&query->dispatch); + } cleanup_query: if (query->connects == 0) { @@ -2212,8 +2285,9 @@ bad_edns(fetchctx_t *fctx, isc_sockaddr_t *address) for (sa = ISC_LIST_HEAD(fctx->bad_edns); sa != NULL; sa = ISC_LIST_NEXT(sa, link)) { - if (isc_sockaddr_equal(sa, address)) + if (isc_sockaddr_equal(sa, address)) { return (true); + } } return (false); @@ -2225,11 +2299,13 @@ add_bad_edns(fetchctx_t *fctx, isc_sockaddr_t *address) isc_sockaddr_t *sa; #ifdef ENABLE_AFL - if (dns_fuzzing_resolver) + if (dns_fuzzing_resolver) { return; -#endif - if (bad_edns(fctx, address)) + } +#endif /* ifdef ENABLE_AFL */ + if (bad_edns(fctx, address)) { return; + } sa = isc_mem_get(fctx->mctx, sizeof(*sa)); @@ -2244,8 +2320,9 @@ triededns(fetchctx_t *fctx, isc_sockaddr_t *address) for (tried = ISC_LIST_HEAD(fctx->edns); tried != NULL; tried = ISC_LIST_NEXT(tried, link)) { - if (isc_sockaddr_equal(&tried->addr, address)) + if (isc_sockaddr_equal(&tried->addr, address)) { return (tried); + } } return (NULL); @@ -2276,8 +2353,9 @@ triededns512(fetchctx_t *fctx, isc_sockaddr_t *address) for (tried = ISC_LIST_HEAD(fctx->edns512); tried != NULL; tried = ISC_LIST_NEXT(tried, link)) { - if (isc_sockaddr_equal(&tried->addr, address)) + if (isc_sockaddr_equal(&tried->addr, address)) { return (tried); + } } return (NULL); @@ -2435,11 +2513,13 @@ resquery_send(resquery_t *query) } result = dns_message_gettempname(fctx->qmessage, &qname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_temps; + } result = dns_message_gettemprdataset(fctx->qmessage, &qrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_temps; + } /* * Get a query id from the dispatch. @@ -2448,8 +2528,9 @@ resquery_send(resquery_t *query) &query->addrinfo->sockaddr, task, resquery_response, query, &query->id, &query->dispentry, res->socketmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_temps; + } fctx->qmessage->opcode = dns_opcode_query; @@ -2469,8 +2550,9 @@ resquery_send(resquery_t *query) * or if we're sending to a forwarder. */ if ((query->options & DNS_FETCHOPT_RECURSIVE) != 0 || - ISFORWARDER(query->addrinfo)) + ISFORWARDER(query->addrinfo)) { fctx->qmessage->flags |= DNS_MESSAGEFLAG_RD; + } /* * Set CD if the client says not to validate, or if the @@ -2506,18 +2588,21 @@ resquery_send(resquery_t *query) * Convert the question to wire format. */ result = dns_compress_init(&cctx, -1, fctx->res->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } cleanup_cctx = true; result = dns_message_renderbegin(fctx->qmessage, &cctx, &query->buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } result = dns_message_rendersection(fctx->qmessage, DNS_SECTION_QUESTION, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } peer = NULL; isc_netaddr_fromsockaddr(&ipaddr, &query->addrinfo->sockaddr); @@ -2537,8 +2622,9 @@ resquery_send(resquery_t *query) } /* Sync NOEDNS0 flag in addrinfo->flags and options now. */ - if ((query->addrinfo->flags & DNS_FETCHOPT_NOEDNS0) != 0) + if ((query->addrinfo->flags & DNS_FETCHOPT_NOEDNS0) != 0) { query->options |= DNS_FETCHOPT_NOEDNS0; + } if (fctx->timeout && (query->options & DNS_FETCHOPT_NOEDNS0) == 0) { isc_sockaddr_t *sockaddr = &query->addrinfo->sockaddr; @@ -2576,34 +2662,40 @@ resquery_send(resquery_t *query) udpsize = dns_adb_probesize(fctx->adb, query->addrinfo, fctx->timeouts); - if (udpsize > res->udpsize) + if (udpsize > res->udpsize) { udpsize = res->udpsize; + } } - if (peer != NULL) + if (peer != NULL) { (void)dns_peer_getudpsize(peer, &udpsize); + } - if (udpsize == 0U && res->udpsize == 512U) + if (udpsize == 0U && res->udpsize == 512U) { udpsize = 512; + } /* * Was the size forced to 512 in the configuration? */ - if (udpsize == 512U) + if (udpsize == 512U) { query->options |= DNS_FETCHOPT_EDNS512; + } /* * We have talked to this server before. */ - if (hint != 0U) + if (hint != 0U) { udpsize = hint; + } /* * We know nothing about the peer's capabilities * so start with minimal EDNS UDP size. */ - if (udpsize == 0U) + if (udpsize == 0U) { udpsize = 512; + } if ((flags & DNS_FETCHOPT_EDNSVERSIONSET) != 0) { version = flags & DNS_FETCHOPT_EDNSVERSIONMASK; @@ -2618,11 +2710,13 @@ resquery_send(resquery_t *query) result = dns_peer_getednsversion(peer, &ednsversion); if (result == ISC_R_SUCCESS && - ednsversion < version) + ednsversion < version) { version = ednsversion; + } } - if (NOCOOKIE(query->addrinfo)) + if (NOCOOKIE(query->addrinfo)) { sendcookie = false; + } if (reqnsid) { INSIST(ednsopt < DNS_EDNSOPTIONS); ednsopts[ednsopt].code = DNS_OPT_NSID; @@ -2654,9 +2748,10 @@ resquery_send(resquery_t *query) } /* Add TCP keepalive option if appropriate */ - if ((peer != NULL) && tcp) + if ((peer != NULL) && tcp) { (void)dns_peer_gettcpkeepalive(peer, &tcpkeepalive); + } if (tcpkeepalive) { INSIST(ednsopt < DNS_EDNSOPTIONS); ednsopts[ednsopt].code = DNS_OPT_TCP_KEEPALIVE; @@ -2666,8 +2761,9 @@ resquery_send(resquery_t *query) } /* Add PAD for current peer? Require TCP for now */ - if ((peer != NULL) && tcp) + if ((peer != NULL) && tcp) { (void)dns_peer_getpadding(peer, &padding); + } if (padding != 0) { INSIST(ednsopt < DNS_EDNSOPTIONS); ednsopts[ednsopt].code = DNS_OPT_PAD; @@ -2700,8 +2796,9 @@ resquery_send(resquery_t *query) query->options |= DNS_FETCHOPT_NOEDNS0; query->ednsversion = -1; } - } else + } else { query->ednsversion = -1; + } /* * Record the UDP EDNS size choosen. @@ -2716,48 +2813,56 @@ resquery_send(resquery_t *query) goto cleanup_message; } - if (udpsize > 512U) + if (udpsize > 512U) { add_triededns(fctx, &query->addrinfo->sockaddr); + } - if (udpsize == 512U) + if (udpsize == 512U) { add_triededns512(fctx, &query->addrinfo->sockaddr); + } /* * Clear CD if EDNS is not in use. */ - if ((query->options & DNS_FETCHOPT_NOEDNS0) != 0) + if ((query->options & DNS_FETCHOPT_NOEDNS0) != 0) { fctx->qmessage->flags &= ~DNS_MESSAGEFLAG_CD; + } /* * Add TSIG record tailored to the current recipient. */ result = dns_view_getpeertsig(fctx->res->view, &ipaddr, &tsigkey); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto cleanup_message; + } if (tsigkey != NULL) { result = dns_message_settsigkey(fctx->qmessage, tsigkey); dns_tsigkey_detach(&tsigkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } } result = dns_message_rendersection(fctx->qmessage, DNS_SECTION_ADDITIONAL, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } result = dns_message_renderend(fctx->qmessage); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } #ifdef HAVE_DNSTAP memset(&zr, 0, sizeof(zr)); isc_buffer_init(&zb, zone, sizeof(zone)); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); result = dns_name_towire(&fctx->domain, &cctx, &zb); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&zb, &zr); + } #endif /* HAVE_DNSTAP */ dns_compress_invalidate(&cctx); @@ -2768,8 +2873,9 @@ resquery_send(resquery_t *query) &query->tsigkey); result = dns_message_getquerytsig( fctx->qmessage, fctx->res->mctx, &query->tsig); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } } /* @@ -2806,8 +2912,9 @@ resquery_send(resquery_t *query) result = isc_socket_connect(sock, address, task, resquery_udpconnected, query); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_message; + } query->connects++; } } @@ -2828,8 +2935,9 @@ resquery_send(resquery_t *query) } else { query->sendevent.attributes |= ISC_SOCKEVENTATTR_DSCP; query->sendevent.dscp = query->dscp; - if (tcp) + if (tcp) { isc_socket_dscp(sock, query->dscp); + } } result = isc_socket_sendto2(sock, &r, task, address, NULL, @@ -2844,14 +2952,16 @@ resquery_send(resquery_t *query) /* * Log the outgoing query via dnstap. */ - if ((fctx->qmessage->flags & DNS_MESSAGEFLAG_RD) != 0) + if ((fctx->qmessage->flags & DNS_MESSAGEFLAG_RD) != 0) { dtmsgtype = DNS_DTTYPE_FQ; - else + } else { dtmsgtype = DNS_DTTYPE_RQ; + } result = isc_socket_getsockname(sock, &localaddr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { la = &localaddr; + } dns_dt_send(fctx->res->view, dtmsgtype, la, &query->addrinfo->sockaddr, tcp, &zr, &query->start, NULL, &query->buffer); @@ -2860,8 +2970,9 @@ resquery_send(resquery_t *query) return (ISC_R_SUCCESS); cleanup_message: - if (cleanup_cctx) + if (cleanup_cctx) { dns_compress_invalidate(&cctx); + } dns_message_reset(fctx->qmessage, DNS_MESSAGE_INTENTRENDER); @@ -2871,10 +2982,12 @@ cleanup_message: dns_dispatch_removeresponse(&query->dispentry, NULL); cleanup_temps: - if (qname != NULL) + if (qname != NULL) { dns_message_puttempname(fctx->qmessage, &qname); - if (qrdataset != NULL) + } + if (qrdataset != NULL) { dns_message_puttemprdataset(fctx->qmessage, &qrdataset); + } return (result); } @@ -2945,10 +3058,11 @@ resquery_connected(isc_task_t *task, isc_event_t *event) attrs |= DNS_DISPATCHATTR_PRIVATE; attrs |= DNS_DISPATCHATTR_CONNECTED; if (isc_sockaddr_pf(&query->addrinfo->sockaddr) == - AF_INET) + AF_INET) { attrs |= DNS_DISPATCHATTR_IPV4; - else + } else { attrs |= DNS_DISPATCHATTR_IPV6; + } attrs |= DNS_DISPATCHATTR_MAKEQUERY; result = dns_dispatch_createtcp( @@ -2963,8 +3077,9 @@ resquery_connected(isc_task_t *task, isc_event_t *event) */ isc_socket_detach(&query->tcpsocket); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = resquery_send(query); + } if (result != ISC_R_SUCCESS) { FCTXTRACE("query canceled: " @@ -3027,10 +3142,11 @@ resquery_connected(isc_task_t *task, isc_event_t *event) */ FCTX_ATTR_CLR(fctx, FCTX_ATTR_ADDRWAIT); result = fctx_stopidletimer(fctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fctx_done(fctx, result, __LINE__); - else + } else { fctx_try(fctx, true, false); + } } } @@ -3100,8 +3216,9 @@ fctx_finddone(isc_task_t *task, isc_event_t *event) fctx_done(fctx, ISC_R_FAILURE, __LINE__); } else if (dodestroy) { fctx_destroy(fctx); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } } } @@ -3112,8 +3229,9 @@ bad_server(fetchctx_t *fctx, isc_sockaddr_t *address) for (sa = ISC_LIST_HEAD(fctx->bad); sa != NULL; sa = ISC_LIST_NEXT(sa, link)) { - if (isc_sockaddr_equal(sa, address)) + if (isc_sockaddr_equal(sa, address)) { return (true); + } } return (false); @@ -3130,7 +3248,7 @@ mark_bad(fetchctx_t *fctx) if (dns_fuzzing_resolver) { return (false); } -#endif +#endif /* ifdef ENABLE_AFL */ /* * Mark all known bad servers, so we don't try to talk to them @@ -3144,10 +3262,11 @@ mark_bad(fetchctx_t *fctx) curr = ISC_LIST_NEXT(curr, publink)) { for (addrinfo = ISC_LIST_HEAD(curr->list); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (bad_server(fctx, &addrinfo->sockaddr)) + if (bad_server(fctx, &addrinfo->sockaddr)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; - else + } else { all_bad = false; + } } } @@ -3156,10 +3275,11 @@ mark_bad(fetchctx_t *fctx) */ for (addrinfo = ISC_LIST_HEAD(fctx->forwaddrs); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (bad_server(fctx, &addrinfo->sockaddr)) + if (bad_server(fctx, &addrinfo->sockaddr)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; - else + } else { all_bad = false; + } } /* @@ -3169,19 +3289,21 @@ mark_bad(fetchctx_t *fctx) curr = ISC_LIST_NEXT(curr, publink)) { for (addrinfo = ISC_LIST_HEAD(curr->list); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (bad_server(fctx, &addrinfo->sockaddr)) + if (bad_server(fctx, &addrinfo->sockaddr)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; - else + } else { all_bad = false; + } } } for (addrinfo = ISC_LIST_HEAD(fctx->altaddrs); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (bad_server(fctx, &addrinfo->sockaddr)) + if (bad_server(fctx, &addrinfo->sockaddr)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; - else + } else { all_bad = false; + } } return (all_bad); @@ -3202,13 +3324,14 @@ add_bad(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, isc_result_t reason, isc_sockaddr_t *address = &addrinfo->sockaddr; #ifdef ENABLE_AFL - if (dns_fuzzing_resolver) + if (dns_fuzzing_resolver) { return; -#endif + } +#endif /* ifdef ENABLE_AFL */ - if (reason == DNS_R_LAME) + if (reason == DNS_R_LAME) { fctx->lamecount++; - else { + } else { switch (badtype) { case badns_unreachable: fctx->neterr++; @@ -3240,13 +3363,15 @@ add_bad(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, isc_result_t reason, *sa = *address; ISC_LIST_INITANDAPPEND(fctx->bad, sa, link); - if (reason == DNS_R_LAME) /* already logged */ + if (reason == DNS_R_LAME) { /* already logged */ return; + } if (reason == DNS_R_UNEXPECTEDRCODE && fctx->rmessage->rcode == dns_rcode_servfail && - ISFORWARDER(addrinfo)) + ISFORWARDER(addrinfo)) { return; + } if (reason == DNS_R_UNEXPECTEDRCODE) { isc_buffer_init(&b, code, sizeof(code) - 1); @@ -3286,13 +3411,15 @@ sort_adbfind(dns_adbfind_t *find, unsigned int bias) while (!ISC_LIST_EMPTY(find->list)) { best = ISC_LIST_HEAD(find->list); best_srtt = best->srtt; - if (isc_sockaddr_pf(&best->sockaddr) != AF_INET6) + if (isc_sockaddr_pf(&best->sockaddr) != AF_INET6) { best_srtt += bias; + } curr = ISC_LIST_NEXT(best, publink); while (curr != NULL) { curr_srtt = curr->srtt; - if (isc_sockaddr_pf(&curr->sockaddr) != AF_INET6) + if (isc_sockaddr_pf(&curr->sockaddr) != AF_INET6) { curr_srtt += bias; + } if (curr_srtt < best_srtt) { best = curr; best_srtt = curr_srtt; @@ -3318,8 +3445,9 @@ sort_finds(dns_adbfindlist_t *findlist, unsigned int bias) /* Sort each find's addrinfo list by SRTT. */ for (curr = ISC_LIST_HEAD(*findlist); curr != NULL; - curr = ISC_LIST_NEXT(curr, publink)) + curr = ISC_LIST_NEXT(curr, publink)) { sort_adbfind(curr, bias); + } /* Lame N^2 bubble sort. */ ISC_LIST_INIT(sorted); @@ -3328,15 +3456,17 @@ sort_finds(dns_adbfindlist_t *findlist, unsigned int bias) bestaddrinfo = ISC_LIST_HEAD(best->list); INSIST(bestaddrinfo != NULL); best_srtt = bestaddrinfo->srtt; - if (isc_sockaddr_pf(&bestaddrinfo->sockaddr) != AF_INET6) + if (isc_sockaddr_pf(&bestaddrinfo->sockaddr) != AF_INET6) { best_srtt += bias; + } curr = ISC_LIST_NEXT(best, publink); while (curr != NULL) { addrinfo = ISC_LIST_HEAD(curr->list); INSIST(addrinfo != NULL); curr_srtt = addrinfo->srtt; - if (isc_sockaddr_pf(&addrinfo->sockaddr) != AF_INET6) + if (isc_sockaddr_pf(&addrinfo->sockaddr) != AF_INET6) { curr_srtt += bias; + } if (curr_srtt < best_srtt) { best = curr; best_srtt = curr_srtt; @@ -3370,8 +3500,9 @@ findname(fetchctx_t *fctx, const dns_name_t *name, in_port_t port, * and we don't know its address (e.g. because the A record has * expired). */ - if (dns_name_issubdomain(name, &fctx->domain)) + if (dns_name_issubdomain(name, &fctx->domain)) { options |= DNS_ADBFIND_STARTATZONE; + } options |= DNS_ADBFIND_GLUEOK; options |= DNS_ADBFIND_HINTOK; @@ -3414,15 +3545,17 @@ findname(fetchctx_t *fctx, const dns_name_t *name, in_port_t port, for (ai = ISC_LIST_HEAD(find->list); ai != NULL; ai = ISC_LIST_NEXT(ai, publink)) { ai->flags |= flags; - if (port != 0) + if (port != 0) { isc_sockaddr_setport(&ai->sockaddr, port); + } } } - if ((flags & FCTX_ADDRINFO_FORWARDER) != 0) + if ((flags & FCTX_ADDRINFO_FORWARDER) != 0) { ISC_LIST_APPEND(fctx->altfinds, find, publink); - else + } else { ISC_LIST_APPEND(fctx->finds, find, publink); + } } else { /* * We don't know any of the addresses for this @@ -3442,18 +3575,21 @@ findname(fetchctx_t *fctx, const dns_name_t *name, in_port_t port, ((res->dispatches4 == NULL && find->result_v6 != DNS_R_NXDOMAIN) || (res->dispatches6 == NULL && - find->result_v4 != DNS_R_NXDOMAIN))) + find->result_v4 != DNS_R_NXDOMAIN))) { *need_alternate = true; + } } else { if ((find->options & DNS_ADBFIND_OVERQUOTA) != 0) { - if (overquota != NULL) + if (overquota != NULL) { *overquota = true; + } fctx->quotacount++; /* quota exceeded */ } else if ((find->options & DNS_ADBFIND_LAMEPRUNED) != - 0) + 0) { fctx->lamecount++; /* cached lame server */ - else + } else { fctx->adberr++; /* unreachable server, etc. */ + } /* * If we know there are no addresses for @@ -3464,8 +3600,9 @@ findname(fetchctx_t *fctx, const dns_name_t *name, in_port_t port, ((res->dispatches4 == NULL && find->result_v6 == DNS_R_NXRRSET) || (res->dispatches6 == NULL && - find->result_v4 == DNS_R_NXRRSET))) + find->result_v4 == DNS_R_NXRRSET))) { *need_alternate = true; + } dns_adb_destroyfind(&find); } } @@ -3576,8 +3713,9 @@ fctx_getaddresses(fetchctx_t *fctx, bool badcache) dns_name_init(&fctx->domain, NULL); dns_name_dup(domain, fctx->mctx, &fctx->domain); result = fcount_incr(fctx, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } } } @@ -3597,13 +3735,15 @@ fctx_getaddresses(fetchctx_t *fctx, bool badcache) ai->flags |= FCTX_ADDRINFO_FORWARDER; ai->dscp = fwd->dscp; cur = ISC_LIST_HEAD(fctx->forwaddrs); - while (cur != NULL && cur->srtt < ai->srtt) + while (cur != NULL && cur->srtt < ai->srtt) { cur = ISC_LIST_NEXT(cur, publink); - if (cur != NULL) + } + if (cur != NULL) { ISC_LIST_INSERTBEFORE(fctx->forwaddrs, cur, ai, publink); - else + } else { ISC_LIST_APPEND(fctx->forwaddrs, ai, publink); + } } fwd = ISC_LIST_NEXT(fwd, link); } @@ -3612,8 +3752,9 @@ fctx_getaddresses(fetchctx_t *fctx, bool badcache) * If the forwarding policy is "only", we don't need the addresses * of the nameservers. */ - if (fctx->fwdpolicy == dns_fwdpolicy_only) + if (fctx->fwdpolicy == dns_fwdpolicy_only) { goto out; + } /* * Normal nameservers. @@ -3634,13 +3775,16 @@ normal_nses: */ stdoptions |= DNS_ADBFIND_AVOIDFETCHES; } - if (res->dispatches4 != NULL) + if (res->dispatches4 != NULL) { stdoptions |= DNS_ADBFIND_INET; - if (res->dispatches6 != NULL) + } + if (res->dispatches6 != NULL) { stdoptions |= DNS_ADBFIND_INET6; + } - if ((stdoptions & DNS_ADBFIND_ADDRESSMASK) == 0) + if ((stdoptions & DNS_ADBFIND_ADDRESSMASK) == 0) { return (DNS_R_SERVFAIL); + } isc_stdtime_get(&now); @@ -3657,20 +3801,23 @@ normal_nses: * Extract the name from the NS record. */ result = dns_rdata_tostruct(&rdata, &ns, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } findname(fctx, &ns.name, 0, stdoptions, 0, now, &overquota, &need_alternate); - if (!overquota) + if (!overquota) { all_spilled = false; + } dns_rdata_reset(&rdata); dns_rdata_freestruct(&ns); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } /* * Do we need to use 6 to 4? @@ -3687,8 +3834,9 @@ normal_nses: now, NULL, NULL); continue; } - if (isc_sockaddr_pf(&a->_u.addr) != family) + if (isc_sockaddr_pf(&a->_u.addr) != family) { continue; + } ai = NULL; result = dns_adb_findaddrinfo(fctx->adb, &a->_u.addr, &ai, 0); @@ -3696,14 +3844,16 @@ normal_nses: dns_adbaddrinfo_t *cur; ai->flags |= FCTX_ADDRINFO_FORWARDER; cur = ISC_LIST_HEAD(fctx->altaddrs); - while (cur != NULL && cur->srtt < ai->srtt) + while (cur != NULL && cur->srtt < ai->srtt) { cur = ISC_LIST_NEXT(cur, publink); - if (cur != NULL) + } + if (cur != NULL) { ISC_LIST_INSERTBEFORE(fctx->altaddrs, cur, ai, publink); - else + } else { ISC_LIST_APPEND(fctx->altaddrs, ai, publink); + } } } } @@ -3741,9 +3891,10 @@ out: if (badcache && (fctx->type == dns_rdatatype_dnskey || fctx->type == dns_rdatatype_ds) && - result == ISC_R_SUCCESS) + result == ISC_R_SUCCESS) { dns_resolver_addbadcache(res, &fctx->name, fctx->type, &expire); + } result = ISC_R_FAILURE; @@ -3802,8 +3953,9 @@ possibly_mark(fetchctx_t *fctx, dns_adbaddrinfo_t *addr) } if (peer != NULL && dns_peer_getbogus(peer, &bogus) == ISC_R_SUCCESS && - bogus) + bogus) { aborted = true; + } if (aborted) { addr->flags |= FCTX_ADDRINFO_MARK; @@ -3825,8 +3977,9 @@ possibly_mark(fetchctx_t *fctx, dns_adbaddrinfo_t *addr) } else if (IN6_IS_ADDR_V4COMPAT(&sa->type.sin6.sin6_addr)) { addr->flags |= FCTX_ADDRINFO_MARK; msg = "ignoring IPv6 compatibility IPV4 address: "; - } else + } else { return; + } if (isc_log_wouldlog(dns_lctx, ISC_LOG_DEBUG(3))) { isc_netaddr_fromsockaddr(&na, sa); @@ -3851,8 +4004,9 @@ fctx_nextaddress(fetchctx_t *fctx) */ for (addrinfo = ISC_LIST_HEAD(fctx->forwaddrs); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (!UNMARKED(addrinfo)) + if (!UNMARKED(addrinfo)) { continue; + } possibly_mark(fctx, addrinfo); if (UNMARKED(addrinfo)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; @@ -3873,8 +4027,9 @@ fctx_nextaddress(fetchctx_t *fctx) find = ISC_LIST_HEAD(fctx->finds); } else { find = ISC_LIST_NEXT(find, publink); - if (find == NULL) + if (find == NULL) { find = ISC_LIST_HEAD(fctx->finds); + } } /* @@ -3887,25 +4042,29 @@ fctx_nextaddress(fetchctx_t *fctx) for (addrinfo = ISC_LIST_HEAD(find->list); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (!UNMARKED(addrinfo)) + if (!UNMARKED(addrinfo)) { continue; + } possibly_mark(fctx, addrinfo); if (UNMARKED(addrinfo)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; break; } } - if (addrinfo != NULL) + if (addrinfo != NULL) { break; + } find = ISC_LIST_NEXT(find, publink); - if (find == NULL) + if (find == NULL) { find = ISC_LIST_HEAD(fctx->finds); + } } while (find != start); } fctx->find = find; - if (addrinfo != NULL) + if (addrinfo != NULL) { return (addrinfo); + } /* * No nameservers left. Try alternates. @@ -3918,8 +4077,9 @@ fctx_nextaddress(fetchctx_t *fctx) find = ISC_LIST_HEAD(fctx->altfinds); } else { find = ISC_LIST_NEXT(find, publink); - if (find == NULL) + if (find == NULL) { find = ISC_LIST_HEAD(fctx->altfinds); + } } /* @@ -3932,19 +4092,22 @@ fctx_nextaddress(fetchctx_t *fctx) for (addrinfo = ISC_LIST_HEAD(find->list); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (!UNMARKED(addrinfo)) + if (!UNMARKED(addrinfo)) { continue; + } possibly_mark(fctx, addrinfo); if (UNMARKED(addrinfo)) { addrinfo->flags |= FCTX_ADDRINFO_MARK; break; } } - if (addrinfo != NULL) + if (addrinfo != NULL) { break; + } find = ISC_LIST_NEXT(find, publink); - if (find == NULL) + if (find == NULL) { find = ISC_LIST_HEAD(fctx->altfinds); + } } while (find != start); } @@ -3956,13 +4119,15 @@ fctx_nextaddress(fetchctx_t *fctx) for (addrinfo = ISC_LIST_HEAD(fctx->altaddrs); addrinfo != NULL; addrinfo = ISC_LIST_NEXT(addrinfo, publink)) { - if (!UNMARKED(addrinfo)) + if (!UNMARKED(addrinfo)) { continue; + } possibly_mark(fctx, addrinfo); if (UNMARKED(addrinfo) && (faddrinfo == NULL || addrinfo->srtt < faddrinfo->srtt)) { - if (faddrinfo != NULL) + if (faddrinfo != NULL) { faddrinfo->flags &= ~FCTX_ADDRINFO_MARK; + } addrinfo->flags |= FCTX_ADDRINFO_MARK; break; } @@ -4127,8 +4292,9 @@ fctx_try(fetchctx_t *fctx, bool retrying, bool badcache) LOCK(&res->buckets[bucketnum].lock); bucket_empty = fctx_decreference(fctx); UNLOCK(&res->buckets[bucketnum].lock); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } } else if (retrying) { inc_stats(res, dns_resstatscounter_retry); } @@ -4158,10 +4324,12 @@ resume_qmin(isc_task_t *task, isc_event_t *event) UNUSED(task); FCTXTRACE("resume_qmin"); - if (fevent->node != NULL) + if (fevent->node != NULL) { dns_db_detachnode(fevent->db, &fevent->node); - if (fevent->db != NULL) + } + if (fevent->db != NULL) { dns_db_detach(&fevent->db); + } bucketnum = fctx->bucketnum; @@ -4275,8 +4443,9 @@ cleanup: LOCK(&res->buckets[bucketnum].lock); bucket_empty = fctx_decreference(fctx); UNLOCK(&res->buckets[bucketnum].lock); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } } static bool @@ -4373,10 +4542,12 @@ fctx_destroy(fetchctx_t *fctx) isc_timer_detach(&fctx->timer); dns_message_destroy(&fctx->rmessage); dns_message_destroy(&fctx->qmessage); - if (dns_name_countlabels(&fctx->domain) > 0) + if (dns_name_countlabels(&fctx->domain) > 0) { dns_name_free(&fctx->domain, fctx->mctx); - if (dns_rdataset_isassociated(&fctx->nameservers)) + } + if (dns_rdataset_isassociated(&fctx->nameservers)) { dns_rdataset_disassociate(&fctx->nameservers); + } dns_name_free(&fctx->name, fctx->mctx); dns_name_free(&fctx->qminname, fctx->mctx); dns_name_free(&fctx->qmindcname, fctx->mctx); @@ -4462,8 +4633,9 @@ fctx_shutdown(fetchctx_t *fctx) * The caller must be holding the appropriate bucket lock. */ - if (fctx->want_shutdown) + if (fctx->want_shutdown) { return; + } fctx->want_shutdown = true; @@ -4514,11 +4686,13 @@ fctx_doshutdown(isc_task_t *task, isc_event_t *event) validator = ISC_LIST_NEXT(validator, link); } - if (fctx->nsfetch != NULL) + if (fctx->nsfetch != NULL) { dns_resolver_cancelfetch(fctx->nsfetch); + } - if (fctx->qminfetch != NULL) + if (fctx->qminfetch != NULL) { dns_resolver_cancelfetch(fctx->qminfetch); + } /* * Shut down anything still running on behalf of this @@ -4552,8 +4726,9 @@ fctx_doshutdown(isc_task_t *task, isc_event_t *event) if (dodestroy) { fctx_destroy(fctx); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } } } @@ -4626,14 +4801,16 @@ fctx_start(isc_task_t *task, isc_event_t *event) * All is well. Start working on the fetch. */ result = fctx_starttimer(fctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fctx_done(fctx, result, __LINE__); - else + } else { fctx_try(fctx, false, false); + } } else if (dodestroy) { fctx_destroy(fctx); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } } } @@ -4677,10 +4854,11 @@ fctx_join(fetchctx_t *fctx, isc_task_t *task, const isc_sockaddr_t *client, * Make sure that we can store the sigrdataset in the * first event if it is needed by any of the events. */ - if (event->sigrdataset != NULL) + if (event->sigrdataset != NULL) { ISC_LIST_PREPEND(fctx->events, event, ev_link); - else + } else { ISC_LIST_APPEND(fctx->events, event, ev_link); + } fctx_increference(fctx); @@ -4734,8 +4912,9 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type, } else { result = isc_counter_create(res->mctx, res->maxqueries, &fctx->qc); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_fetch; + } } /* @@ -4854,8 +5033,9 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type, fname = dns_fixedname_initname(&fixed); result = dns_fwdtable_find(fctx->res->view->fwdtable, fwdname, fname, &forwarders); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { fctx->fwdpolicy = forwarders->fwdpolicy; + } if (fctx->fwdpolicy != dns_fwdpolicy_only) { dns_fixedname_t dcfixed; @@ -4866,8 +5046,9 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type, * nameservers, and we're not in forward-only mode, * so find the best nameservers to use. */ - if (dns_rdatatype_atparent(fctx->type)) + if (dns_rdatatype_atparent(fctx->type)) { findoptions |= DNS_DBFIND_NOEXACT; + } result = dns_view_findzonecut(res->view, name, fname, dcname, fctx->now, findoptions, true, true, @@ -4917,15 +5098,17 @@ fctx_create(dns_resolver_t *res, const dns_name_t *name, dns_rdatatype_t type, result = dns_message_create(mctx, DNS_MESSAGE_INTENTRENDER, &fctx->qmessage); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_fcount; + } fctx->rmessage = NULL; result = dns_message_create(mctx, DNS_MESSAGE_INTENTPARSE, &fctx->rmessage); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_qmessage; + } /* * Compute an expiration time for the entire fetch. @@ -5018,14 +5201,17 @@ cleanup_fcount: fcount_decr(fctx); cleanup_domain: - if (dns_name_countlabels(&fctx->domain) > 0) + if (dns_name_countlabels(&fctx->domain) > 0) { dns_name_free(&fctx->domain, mctx); - if (dns_name_countlabels(&fctx->qmindcname) > 0) + } + if (dns_name_countlabels(&fctx->qmindcname) > 0) { dns_name_free(&fctx->qmindcname, mctx); + } cleanup_nameservers: - if (dns_rdataset_isassociated(&fctx->nameservers)) + if (dns_rdataset_isassociated(&fctx->nameservers)) { dns_rdataset_disassociate(&fctx->nameservers); + } dns_name_free(&fctx->name, mctx); dns_name_free(&fctx->qminname, mctx); isc_mem_free(mctx, fctx->info); @@ -5050,14 +5236,17 @@ is_lame(fetchctx_t *fctx) if (message->rcode != dns_rcode_noerror && message->rcode != dns_rcode_yxdomain && - message->rcode != dns_rcode_nxdomain) + message->rcode != dns_rcode_nxdomain) { return (false); + } - if (message->counts[DNS_SECTION_ANSWER] != 0) + if (message->counts[DNS_SECTION_ANSWER] != 0) { return (false); + } - if (message->counts[DNS_SECTION_AUTHORITY] == 0) + if (message->counts[DNS_SECTION_AUTHORITY] == 0) { return (false); + } result = dns_message_firstname(message, DNS_SECTION_AUTHORITY); while (result == ISC_R_SUCCESS) { @@ -5068,15 +5257,18 @@ is_lame(fetchctx_t *fctx) dns_namereln_t namereln; int order; unsigned int labels; - if (rdataset->type != dns_rdatatype_ns) + if (rdataset->type != dns_rdatatype_ns) { continue; + } namereln = dns_name_fullcompare(name, &fctx->domain, &order, &labels); if (namereln == dns_namereln_equal && - (message->flags & DNS_MESSAGEFLAG_AA) != 0) + (message->flags & DNS_MESSAGEFLAG_AA) != 0) { return (false); - if (namereln == dns_namereln_subdomain) + } + if (namereln == dns_namereln_subdomain) { return (false); + } return (true); } result = dns_message_nextname(message, DNS_SECTION_AUTHORITY); @@ -5174,8 +5366,9 @@ same_question(fetchctx_t *fctx) } result = dns_message_firstname(message, DNS_SECTION_QUESTION); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } name = NULL; dns_message_currentname(message, DNS_SECTION_QUESTION, &name); rdataset = ISC_LIST_HEAD(name->list); @@ -5218,8 +5411,9 @@ clone_results(fetchctx_t *fctx) fctx->cloned = true; hevent = ISC_LIST_HEAD(fctx->events); - if (hevent == NULL) + if (hevent == NULL) { return; + } hname = dns_fixedname_name(&hevent->foundname); for (event = ISC_LIST_NEXT(hevent, ev_link); event != NULL; event = ISC_LIST_NEXT(event, ev_link)) { @@ -5230,15 +5424,17 @@ clone_results(fetchctx_t *fctx) dns_db_attachnode(hevent->db, hevent->node, &event->node); INSIST(hevent->rdataset != NULL); INSIST(event->rdataset != NULL); - if (dns_rdataset_isassociated(hevent->rdataset)) + if (dns_rdataset_isassociated(hevent->rdataset)) { dns_rdataset_clone(hevent->rdataset, event->rdataset); + } INSIST(!(hevent->sigrdataset == NULL && event->sigrdataset != NULL)); if (hevent->sigrdataset != NULL && dns_rdataset_isassociated(hevent->sigrdataset) && - event->sigrdataset != NULL) + event->sigrdataset != NULL) { dns_rdataset_clone(hevent->sigrdataset, event->sigrdataset); + } } } @@ -5270,13 +5466,15 @@ maybe_destroy(fetchctx_t *fctx, bool locked) bool dodestroy = false; bucketnum = fctx->bucketnum; - if (!locked) + if (!locked) { LOCK(&res->buckets[bucketnum].lock); + } REQUIRE(SHUTTINGDOWN(fctx)); - if (fctx->pending != 0 || fctx->nqueries != 0) + if (fctx->pending != 0 || fctx->nqueries != 0) { goto unlock; + } for (validator = ISC_LIST_HEAD(fctx->validators); validator != NULL; validator = next_validator) { @@ -5290,10 +5488,12 @@ maybe_destroy(fetchctx_t *fctx, bool locked) dodestroy = true; } unlock: - if (!locked) + if (!locked) { UNLOCK(&res->buckets[bucketnum].lock); - if (dodestroy) + } + if (dodestroy) { fctx_destroy(fctx); + } return (bucket_empty); } @@ -5374,8 +5574,9 @@ validated(isc_task_t *task, isc_event_t *event) bool bucket_empty; bucket_empty = maybe_destroy(fctx, true); UNLOCK(&res->buckets[bucketnum].lock); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } goto cleanup_event; } @@ -5387,15 +5588,16 @@ validated(isc_task_t *task, isc_event_t *event) */ if (vevent->result == ISC_R_SUCCESS && !negative && vevent->rdataset != NULL && CHAINING(vevent->rdataset)) { - if (vevent->rdataset->type == dns_rdatatype_cname) + if (vevent->rdataset->type == dns_rdatatype_cname) { eresult = DNS_R_CNAME; - else { + } else { INSIST(vevent->rdataset->type == dns_rdatatype_dname); eresult = DNS_R_DNAME; } chaining = true; - } else + } else { chaining = false; + } /* * Either we're not shutting down, or we are shutting down but want @@ -5426,41 +5628,48 @@ validated(isc_task_t *task, isc_event_t *event) fctx->vresult = vevent->result; if (fctx->vresult != DNS_R_BROKENCHAIN) { result = ISC_R_NOTFOUND; - if (vevent->rdataset != NULL) + if (vevent->rdataset != NULL) { result = dns_db_findnode( fctx->cache, vevent->name, true, &node); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { (void)dns_db_deleterdataset(fctx->cache, node, NULL, vevent->type, 0); + } if (result == ISC_R_SUCCESS && - vevent->sigrdataset != NULL) + vevent->sigrdataset != NULL) { (void)dns_db_deleterdataset( fctx->cache, node, NULL, dns_rdatatype_rrsig, vevent->type); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { dns_db_detachnode(fctx->cache, &node); + } } if (fctx->vresult == DNS_R_BROKENCHAIN && !negative) { /* * Cache the data as pending for later validation. */ result = ISC_R_NOTFOUND; - if (vevent->rdataset != NULL) + if (vevent->rdataset != NULL) { result = dns_db_findnode( fctx->cache, vevent->name, true, &node); + } if (result == ISC_R_SUCCESS) { (void)dns_db_addrdataset( fctx->cache, node, NULL, now, vevent->rdataset, 0, NULL); } if (result == ISC_R_SUCCESS && - vevent->sigrdataset != NULL) + vevent->sigrdataset != NULL) { (void)dns_db_addrdataset( fctx->cache, node, NULL, now, vevent->sigrdataset, 0, NULL); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { dns_db_detachnode(fctx->cache, &node); + } } result = fctx->vresult; add_bad(fctx, addrinfo, result, badns_validation); @@ -5468,11 +5677,11 @@ validated(isc_task_t *task, isc_event_t *event) UNLOCK(&res->buckets[bucketnum].lock); INSIST(fctx->validator == NULL); fctx->validator = ISC_LIST_HEAD(fctx->validators); - if (fctx->validator != NULL) + if (fctx->validator != NULL) { dns_validator_send(fctx->validator); - else if (sentresponse) + } else if (sentresponse) { fctx_done(fctx, result, __LINE__); /* Locks bucket. */ - else if (result == DNS_R_BROKENCHAIN) { + } else if (result == DNS_R_BROKENCHAIN) { isc_result_t tresult; isc_time_t expire; isc_interval_t i; @@ -5482,12 +5691,14 @@ validated(isc_task_t *task, isc_event_t *event) if (negative && (fctx->type == dns_rdatatype_dnskey || fctx->type == dns_rdatatype_ds) && - tresult == ISC_R_SUCCESS) + tresult == ISC_R_SUCCESS) { dns_resolver_addbadcache(res, &fctx->name, fctx->type, &expire); + } fctx_done(fctx, result, __LINE__); /* Locks bucket. */ - } else + } else { fctx_try(fctx, true, true); /* Locks bucket. */ + } return; } @@ -5501,15 +5712,17 @@ validated(isc_task_t *task, isc_event_t *event) * Cache DS NXDOMAIN seperately to other types. */ if (fctx->rmessage->rcode == dns_rcode_nxdomain && - fctx->type != dns_rdatatype_ds) + fctx->type != dns_rdatatype_ds) { covers = dns_rdatatype_any; - else + } else { covers = fctx->type; + } result = dns_db_findnode(fctx->cache, vevent->name, true, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto noanswer_response; + } /* * If we are asking for a SOA record set the cache time @@ -5518,18 +5731,21 @@ validated(isc_task_t *task, isc_event_t *event) */ ttl = res->view->maxncachettl; if (fctx->type == dns_rdatatype_soa && - covers == dns_rdatatype_any && res->zero_no_soa_ttl) + covers == dns_rdatatype_any && res->zero_no_soa_ttl) { ttl = 0; + } result = ncache_adderesult( fctx->rmessage, fctx->cache, node, covers, now, fctx->res->view->minncachettl, ttl, vevent->optout, vevent->secure, ardataset, &eresult); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto noanswer_response; + } goto answer_response; - } else + } else { inc_stats(res, dns_resstatscounter_valsuccess); + } FCTXTRACE("validation OK"); @@ -5566,27 +5782,32 @@ validated(isc_task_t *task, isc_event_t *event) * event list. */ result = dns_db_findnode(fctx->cache, vevent->name, true, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto noanswer_response; + } options = 0; - if ((fctx->options & DNS_FETCHOPT_PREFETCH) != 0) + if ((fctx->options & DNS_FETCHOPT_PREFETCH) != 0) { options = DNS_DBADD_PREFETCH; + } result = dns_db_addrdataset(fctx->cache, node, NULL, now, vevent->rdataset, options, ardataset); - if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) + if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) { goto noanswer_response; + } if (ardataset != NULL && NEGATIVE(ardataset)) { - if (NXDOMAIN(ardataset)) + if (NXDOMAIN(ardataset)) { eresult = DNS_R_NCACHENXDOMAIN; - else + } else { eresult = DNS_R_NCACHENXRRSET; + } } else if (vevent->sigrdataset != NULL) { result = dns_db_addrdataset(fctx->cache, node, NULL, now, vevent->sigrdataset, options, asigrdataset); - if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) + if (result != ISC_R_SUCCESS && result != DNS_R_UNCHANGED) { goto noanswer_response; + } } if (sentresponse) { @@ -5596,11 +5817,13 @@ validated(isc_task_t *task, isc_event_t *event) * the data, destroy now. */ dns_db_detachnode(fctx->cache, &node); - if (SHUTTINGDOWN(fctx)) + if (SHUTTINGDOWN(fctx)) { bucket_empty = maybe_destroy(fctx, true); + } UNLOCK(&res->buckets[bucketnum].lock); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } goto cleanup_event; } @@ -5634,33 +5857,39 @@ answer_response: if ((rdataset->type != dns_rdatatype_ns && rdataset->type != dns_rdatatype_soa && rdataset->type != dns_rdatatype_nsec) || - rdataset->trust != dns_trust_secure) + rdataset->trust != dns_trust_secure) { continue; + } for (sigrdataset = ISC_LIST_HEAD(name->list); sigrdataset != NULL; sigrdataset = ISC_LIST_NEXT(sigrdataset, link)) { if (sigrdataset->type != dns_rdatatype_rrsig || - sigrdataset->covers != rdataset->type) + sigrdataset->covers != rdataset->type) { continue; + } break; } if (sigrdataset == NULL || - sigrdataset->trust != dns_trust_secure) + sigrdataset->trust != dns_trust_secure) { continue; + } result = dns_db_findnode(fctx->cache, name, true, &nsnode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = dns_db_addrdataset(fctx->cache, nsnode, NULL, now, rdataset, 0, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_db_addrdataset( fctx->cache, nsnode, NULL, now, sigrdataset, 0, NULL); + } dns_db_detachnode(fctx->cache, &nsnode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } } result = dns_message_nextname(fctx->rmessage, DNS_SECTION_AUTHORITY); @@ -5679,15 +5908,18 @@ answer_response: dns_dbnode_t *wnode = NULL; result = dns_db_findnode(fctx->cache, wild, true, &wnode); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_db_addrdataset(fctx->cache, wnode, NULL, now, vevent->rdataset, 0, NULL); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { (void)dns_db_addrdataset(fctx->cache, wnode, NULL, now, vevent->sigrdataset, 0, NULL); - if (wnode != NULL) + } + if (wnode != NULL) { dns_db_detachnode(fctx->cache, &wnode); + } } result = ISC_R_SUCCESS; @@ -5718,8 +5950,9 @@ answer_response: } noanswer_response: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(fctx->cache, &node); + } UNLOCK(&res->buckets[bucketnum].lock); fctx_done(fctx, result, __LINE__); /* Locks bucket. */ @@ -5773,12 +6006,14 @@ findnoqname(fetchctx_t *fctx, dns_name_t *name, dns_rdatatype_t type, for (sigrdataset = ISC_LIST_HEAD(name->list); sigrdataset != NULL; sigrdataset = ISC_LIST_NEXT(sigrdataset, link)) { if (sigrdataset->type == dns_rdatatype_rrsig && - sigrdataset->covers == type) + sigrdataset->covers == type) { break; + } } - if (sigrdataset == NULL) + if (sigrdataset == NULL) { return (ISC_R_NOTFOUND); + } labels = dns_name_countlabels(name); @@ -5789,15 +6024,18 @@ findnoqname(fetchctx_t *fctx, dns_name_t *name, dns_rdatatype_t type, result = dns_rdata_tostruct(&rdata, &rrsig, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); /* Wildcard has rrsig.labels < labels - 1. */ - if (rrsig.labels + 1U >= labels) + if (rrsig.labels + 1U >= labels) { continue; + } break; } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { return (ISC_R_NOTFOUND); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } zonename = dns_fixedname_initname(&fzonename); closest = dns_fixedname_initname(&fclosest); @@ -5820,8 +6058,9 @@ findnoqname(fetchctx_t *fctx, dns_name_t *name, dns_rdatatype_t type, next = ISC_LIST_NEXT(nrdataset, link); if (nrdataset->type != dns_rdatatype_nsec && - nrdataset->type != dns_rdatatype_nsec3) + nrdataset->type != dns_rdatatype_nsec3) { continue; + } if (nrdataset->type == dns_rdatatype_nsec && NXND(dns_nsec_noexistnodata( @@ -5846,18 +6085,21 @@ findnoqname(fetchctx_t *fctx, dns_name_t *name, dns_rdatatype_t type, } } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } if (noqname != NULL) { for (sigrdataset = ISC_LIST_HEAD(noqname->list); sigrdataset != NULL; sigrdataset = ISC_LIST_NEXT(sigrdataset, link)) { if (sigrdataset->type == dns_rdatatype_rrsig && - sigrdataset->covers == found) + sigrdataset->covers == found) { break; + } } - if (sigrdataset != NULL) + if (sigrdataset != NULL) { *noqnamep = noqname; + } } return (result); } @@ -6344,16 +6586,19 @@ cache_message(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, isc_stdtime_t now) dns_message_currentname(fctx->rmessage, section, &name); if ((name->attributes & DNS_NAMEATTR_CACHE) != 0) { result = cache_name(fctx, name, addrinfo, now); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } result = dns_message_nextname(fctx->rmessage, section); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { break; + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } UNLOCK(&fctx->res->buckets[fctx->bucketnum].lock); @@ -6376,13 +6621,14 @@ ncache_adderesult(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, dns_rdataset_init(&rdataset); ardataset = &rdataset; } - if (secure) + if (secure) { result = dns_ncache_addoptout(message, cache, node, covers, now, minttl, maxttl, optout, ardataset); - else + } else { result = dns_ncache_add(message, cache, node, covers, now, minttl, maxttl, ardataset); + } if (result == DNS_R_UNCHANGED || result == ISC_R_SUCCESS) { /* * If the cache now contains a negative entry and we @@ -6393,10 +6639,11 @@ ncache_adderesult(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, /* * The cache data is a negative cache entry. */ - if (NXDOMAIN(ardataset)) + if (NXDOMAIN(ardataset)) { *eresultp = DNS_R_NCACHENXDOMAIN; - else + } else { *eresultp = DNS_R_NCACHENXRRSET; + } } else { /* * Either we don't care about the nature of the @@ -6411,8 +6658,9 @@ ncache_adderesult(dns_message_t *message, dns_db_t *cache, dns_dbnode_t *node, } result = ISC_R_SUCCESS; } - if (ardataset == &rdataset && dns_rdataset_isassociated(ardataset)) + if (ardataset == &rdataset && dns_rdataset_isassociated(ardataset)) { dns_rdataset_disassociate(ardataset); + } return (result); } @@ -6463,17 +6711,20 @@ ncache_message(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, if (fctx->res->view->enablevalidation) { result = issecuredomain(res->view, name, fctx->type, now, checknta, NULL, &secure_domain); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } - if ((fctx->options & DNS_FETCHOPT_NOCDFLAG) != 0) + if ((fctx->options & DNS_FETCHOPT_NOCDFLAG) != 0) { valoptions |= DNS_VALIDATOR_NOCDFLAG; + } - if ((fctx->options & DNS_FETCHOPT_NOVALIDATE) != 0) + if ((fctx->options & DNS_FETCHOPT_NOVALIDATE) != 0) { need_validation = false; - else + } else { need_validation = secure_domain; + } if (secure_domain) { /* @@ -6490,13 +6741,15 @@ ncache_message(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, DNS_SECTION_AUTHORITY, &tname); for (trdataset = ISC_LIST_HEAD(tname->list); trdataset != NULL; - trdataset = ISC_LIST_NEXT(trdataset, link)) + trdataset = ISC_LIST_NEXT(trdataset, link)) { trdataset->trust = dns_trust_pending_answer; + } result = dns_message_nextname(fctx->rmessage, DNS_SECTION_AUTHORITY); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } } if (need_validation) { @@ -6529,12 +6782,14 @@ ncache_message(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, anodep = &event->node; ardataset = event->rdataset; } - } else + } else { event = NULL; + } result = dns_db_findnode(fctx->cache, name, true, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } /* * If we are asking for a SOA record set the cache time @@ -6543,22 +6798,25 @@ ncache_message(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, */ ttl = fctx->res->view->maxncachettl; if (fctx->type == dns_rdatatype_soa && covers == dns_rdatatype_any && - fctx->res->zero_no_soa_ttl) + fctx->res->zero_no_soa_ttl) { ttl = 0; + } result = ncache_adderesult(fctx->rmessage, fctx->cache, node, covers, now, fctx->res->view->minncachettl, ttl, false, false, ardataset, &eresult); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } if (!HAVE_ANSWER(fctx)) { FCTX_ATTR_SET(fctx, FCTX_ATTR_HAVEANSWER); if (event != NULL) { event->result = eresult; if (adbp != NULL && *adbp != NULL) { - if (anodep != NULL && *anodep != NULL) + if (anodep != NULL && *anodep != NULL) { dns_db_detachnode(*adbp, anodep); + } dns_db_detach(adbp); } dns_db_attach(fctx->cache, adbp); @@ -6570,8 +6828,9 @@ ncache_message(fetchctx_t *fctx, dns_adbaddrinfo_t *addrinfo, unlock: UNLOCK(&res->buckets[fctx->bucketnum].lock); - if (node != NULL) + if (node != NULL) { dns_db_detachnode(fctx->cache, &node); + } return (result); } @@ -6587,10 +6846,12 @@ mark_related(dns_name_t *name, dns_rdataset_t *rdataset, bool external, * Glue with 0 TTL causes problems. We force the TTL to * 1 second to prevent this. */ - if (rdataset->ttl == 0) + if (rdataset->ttl == 0) { rdataset->ttl = 1; - } else + } + } else { rdataset->trust = dns_trust_additional; + } /* * Avoid infinite loops by only marking new rdatasets. */ @@ -6599,8 +6860,9 @@ mark_related(dns_name_t *name, dns_rdataset_t *rdataset, bool external, rdataset->attributes |= DNS_RDATASETATTR_CHASE; } rdataset->attributes |= DNS_RDATASETATTR_CACHE; - if (external) + if (external) { rdataset->attributes |= DNS_RDATASETATTR_EXTERNAL; + } } static isc_result_t @@ -6618,9 +6880,10 @@ check_section(void *arg, const dns_name_t *addname, dns_rdatatype_t type, REQUIRE(VALID_FCTX(fctx)); #if CHECK_FOR_GLUE_IN_ANSWER - if (section == DNS_SECTION_ANSWER && type != dns_rdatatype_a) + if (section == DNS_SECTION_ANSWER && type != dns_rdatatype_a) { return (ISC_R_SUCCESS); -#endif + } +#endif /* if CHECK_FOR_GLUE_IN_ANSWER */ gluing = (GLUING(fctx) || (fctx->type == dns_rdatatype_ns && dns_name_equal(&fctx->name, dns_rootname))); @@ -6633,14 +6896,16 @@ check_section(void *arg, const dns_name_t *addname, dns_rdatatype_t type, for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (rdataset->type == dns_rdatatype_rrsig) + if (rdataset->type == dns_rdatatype_rrsig) { rtype = rdataset->covers; - else + } else { rtype = rdataset->type; + } if (rtype == dns_rdatatype_a || - rtype == dns_rdatatype_aaaa) + rtype == dns_rdatatype_aaaa) { mark_related(name, rdataset, external, gluing); + } } } else { result = dns_message_findtype(name, type, 0, &rdataset); @@ -6653,9 +6918,10 @@ check_section(void *arg, const dns_name_t *addname, dns_rdatatype_t type, result = dns_message_findtype( name, dns_rdatatype_rrsig, type, &rdataset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { mark_related(name, rdataset, external, gluing); + } } } } @@ -6671,7 +6937,7 @@ check_related(void *arg, const dns_name_t *addname, dns_rdatatype_t type) #ifndef CHECK_FOR_GLUE_IN_ANSWER #define CHECK_FOR_GLUE_IN_ANSWER 0 -#endif +#endif /* ifndef CHECK_FOR_GLUE_IN_ANSWER */ #if CHECK_FOR_GLUE_IN_ANSWER static isc_result_t @@ -6679,7 +6945,7 @@ check_answer(void *arg, const dns_name_t *addname, dns_rdatatype_t type) { return (check_section(arg, addname, type, DNS_SECTION_ANSWER)); } -#endif +#endif /* if CHECK_FOR_GLUE_IN_ANSWER */ static bool is_answeraddress_allowed(dns_view_t *view, dns_name_t *name, @@ -6697,8 +6963,9 @@ is_answeraddress_allowed(dns_view_t *view, dns_name_t *name, int match; /* By default, we allow any addresses. */ - if (view->denyansweracl == NULL) + if (view->denyansweracl == NULL) { return (true); + } /* * If the owner name matches one in the exclusion list, either exactly @@ -6710,8 +6977,9 @@ is_answeraddress_allowed(dns_view_t *view, dns_name_t *name, result = dns_rbt_findnode(view->answeracl_exclude, name, NULL, &node, NULL, 0, NULL, NULL); - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { return (true); + } } /* @@ -6781,8 +7049,9 @@ is_answertarget_allowed(fetchctx_t *fctx, dns_name_t *qname, dns_name_t *rname, * By default, we allow any target name. * If newqname != NULL we also need to extract the newqname. */ - if (chainingp == NULL && view->denyanswernames == NULL) + if (chainingp == NULL && view->denyanswernames == NULL) { return (true); + } result = dns_rdataset_first(rdataset); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -6819,11 +7088,13 @@ is_answertarget_allowed(fetchctx_t *fctx, dns_name_t *qname, dns_name_t *rname, ISC_UNREACHABLE(); } - if (chainingp != NULL) + if (chainingp != NULL) { *chainingp = true; + } - if (view->denyanswernames == NULL) + if (view->denyanswernames == NULL) { return (true); + } /* * If the owner name matches one in the exclusion list, either exactly @@ -6832,15 +7103,17 @@ is_answertarget_allowed(fetchctx_t *fctx, dns_name_t *qname, dns_name_t *rname, if (view->answernames_exclude != NULL) { result = dns_rbt_findnode(view->answernames_exclude, qname, NULL, &node, NULL, 0, NULL, NULL); - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { return (true); + } } /* * If the target name is a subdomain of the search domain, allow it. */ - if (dns_name_issubdomain(tname, &fctx->domain)) + if (dns_name_issubdomain(tname, &fctx->domain)) { return (true); + } /* * Otherwise, apply filters. @@ -6972,10 +7245,12 @@ resume_dslookup(isc_task_t *task, isc_event_t *event) UNUSED(task); FCTXTRACE("resume_dslookup"); - if (fevent->node != NULL) + if (fevent->node != NULL) { dns_db_detachnode(fevent->db, &fevent->node); - if (fevent->db != NULL) + } + if (fevent->db != NULL) { dns_db_detach(&fevent->db); + } dns_rdataset_init(&nameservers); @@ -7051,15 +7326,17 @@ resume_dslookup(isc_task_t *task, isc_event_t *event) dns_rdataset_clone(&fctx->nsfetch->private->nameservers, &nameservers); nsrdataset = &nameservers; - } else + } else { domain = NULL; + } dns_resolver_destroyfetch(&fctx->nsfetch); n = dns_name_countlabels(&fctx->nsname); dns_name_getlabelsequence(&fctx->nsname, 1, n - 1, &fctx->nsname); - if (dns_rdataset_isassociated(fevent->rdataset)) + if (dns_rdataset_isassociated(fevent->rdataset)) { dns_rdataset_disassociate(fevent->rdataset); + } fevent = NULL; isc_event_free(&event); @@ -7208,8 +7485,9 @@ betterreferral(fetchctx_t *fctx) result = dns_message_nextname(message, DNS_SECTION_AUTHORITY)) { name = NULL; dns_message_currentname(message, DNS_SECTION_AUTHORITY, &name); - if (!isstrictsubdomain(name, &fctx->domain)) + if (!isstrictsubdomain(name, &fctx->domain)) { continue; + } for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { if (rdataset->type == dns_rdatatype_ns) { @@ -7241,10 +7519,11 @@ resquery_response(isc_task_t *task, isc_event_t *event) QTRACE("response"); - if (isc_sockaddr_pf(&query->addrinfo->sockaddr) == PF_INET) + if (isc_sockaddr_pf(&query->addrinfo->sockaddr) == PF_INET) { inc_stats(fctx->res, dns_resstatscounter_responsev4); - else + } else { inc_stats(fctx->res, dns_resstatscounter_responsev6); + } (void)isc_timer_touch(fctx->timer); @@ -7355,9 +7634,10 @@ resquery_response(isc_task_t *task, isc_event_t *event) switch (fctx->rmessage->rcode) { case dns_rcode_notimp: case dns_rcode_formerr: - if (fctx->rmessage->counts[DNS_SECTION_QUESTION] == 0) + if (fctx->rmessage->counts[DNS_SECTION_QUESTION] == 0) { break; - /* FALLTHROUGH */ + } + /* FALLTHROUGH */ case dns_rcode_nxrrset: /* Not expected. */ case dns_rcode_badcookie: case dns_rcode_noerror: @@ -7530,8 +7810,9 @@ resquery_response(isc_task_t *task, isc_event_t *event) /* * Something has gone wrong. */ - if (result == DNS_R_FORMERR) + if (result == DNS_R_FORMERR) { rctx.next_server = true; + } FCTXTRACE3("rctx_answer_none", result); rctx_done(&rctx, result); return; @@ -7857,8 +8138,9 @@ rctx_opt(respctx_t *rctx) addrinfo = query->addrinfo; dns_adb_setcookie(fctx->adb, addrinfo, optvalue, optlen); - } else + } else { fctx->rmessage->cc_bad = 1; + } isc_buffer_forward(&optbuf, optlen); inc_stats(fctx->res, dns_resstatscounter_cookiein); @@ -9037,7 +9319,7 @@ rctx_referral(respctx_t *rctx) (void)dns_rdataset_additionaldata(rctx->ns_rdataset, check_answer, fctx); } -#endif +#endif /* if CHECK_FOR_GLUE_IN_ANSWER */ FCTX_ATTR_CLR(fctx, FCTX_ATTR_GLUING); /* @@ -9136,8 +9418,9 @@ again: dns_rdataset_t *rdataset; dns_message_currentname(fctx->rmessage, DNS_SECTION_ADDITIONAL, &name); - if ((name->attributes & DNS_NAMEATTR_CHASE) == 0) + if ((name->attributes & DNS_NAMEATTR_CHASE) == 0) { continue; + } name->attributes &= ~DNS_NAMEATTR_CHASE; for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { @@ -9149,8 +9432,9 @@ again: } } } - if (rescan) + if (rescan) { goto again; + } } /* @@ -9164,8 +9448,9 @@ rctx_nextserver(respctx_t *rctx, dns_adbaddrinfo_t *addrinfo, { fetchctx_t *fctx = rctx->fctx; - if (result == DNS_R_FORMERR) + if (result == DNS_R_FORMERR) { rctx->broken_server = DNS_R_FORMERR; + } if (rctx->broken_server != ISC_R_SUCCESS) { /* * Add this server to the list of bad servers for @@ -9186,8 +9471,9 @@ rctx_nextserver(respctx_t *rctx, dns_adbaddrinfo_t *addrinfo, fctx_done(fctx, DNS_R_SERVFAIL, __LINE__); return; } - if (dns_rdatatype_atparent(fctx->type)) + if (dns_rdatatype_atparent(fctx->type)) { findoptions |= DNS_DBFIND_NOEXACT; + } if ((rctx->retryopts & DNS_FETCHOPT_UNSHARED) == 0) { name = &fctx->name; } else { @@ -9282,7 +9568,7 @@ rctx_next(respctx_t *rctx) { #ifdef WANT_QUERYTRACE fetchctx_t *fctx = rctx->fctx; -#endif +#endif /* ifdef WANT_QUERYTRACE */ isc_result_t result; FCTXTRACE("nextitem"); @@ -9327,8 +9613,9 @@ rctx_chaseds(respctx_t *rctx, dns_adbaddrinfo_t *addrinfo, isc_result_t result) } else { fctx_increference(fctx); result = fctx_stopidletimer(fctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fctx_done(fctx, result, __LINE__); + } } } @@ -9369,7 +9656,7 @@ rctx_done(respctx_t *rctx, isc_result_t result) fctx_done(fctx, DNS_R_SERVFAIL, __LINE__); return; } else -#endif +#endif /* ifdef ENABLE_AFL */ if (rctx->next_server) { rctx_nextserver(rctx, addrinfo, result); } else if (rctx->resend) { @@ -9390,8 +9677,9 @@ rctx_done(respctx_t *rctx, isc_result_t result) * it has references to the current rmessage. */ result = fctx_stopidletimer(fctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fctx_done(fctx, result, __LINE__); + } } else { /* * We're done. @@ -9435,8 +9723,9 @@ rctx_logpacket(respctx_t *rctx) isc_buffer_init(&zb, zone, sizeof(zone)); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); result = dns_name_towire(&fctx->domain, &cctx, &zb); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&zb, &zr); + } dns_compress_invalidate(&cctx); } @@ -9524,7 +9813,7 @@ rctx_badserver(respctx_t *rctx, isc_result_t result) unsigned int version; #if DNS_EDNS_VERSION > 0 unsigned int flags, mask; -#endif +#endif /* if DNS_EDNS_VERSION > 0 */ INSIST(rctx->opt != NULL); version = (rctx->opt->ttl >> 16) & 0xff; @@ -9533,7 +9822,7 @@ rctx_badserver(respctx_t *rctx, isc_result_t result) DNS_FETCHOPT_EDNSVERSIONSET; mask = DNS_FETCHOPT_EDNSVERSIONMASK | DNS_FETCHOPT_EDNSVERSIONSET; -#endif +#endif /* if DNS_EDNS_VERSION > 0 */ /* * Record that we got a good EDNS response. @@ -9562,10 +9851,10 @@ rctx_badserver(respctx_t *rctx, isc_result_t result) rctx->broken_server = DNS_R_BADVERS; rctx->next_server = true; } -#else +#else /* if DNS_EDNS_VERSION > 0 */ rctx->broken_server = DNS_R_BADVERS; rctx->next_server = true; -#endif +#endif /* if DNS_EDNS_VERSION > 0 */ } else if (fctx->rmessage->rcode == dns_rcode_badcookie && fctx->rmessage->cc_ok) { /* @@ -9610,11 +9899,12 @@ rctx_lameserver(respctx_t *rctx) log_lame(fctx, query->addrinfo); result = dns_adb_marklame(fctx->adb, query->addrinfo, &fctx->name, fctx->type, rctx->now + fctx->res->lame_ttl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_RESOLVER, ISC_LOG_ERROR, "could not mark server as lame: %s", isc_result_totext(result)); + } rctx->broken_server = DNS_R_LAME; rctx->next_server = true; FCTXTRACE("lame server"); @@ -9692,14 +9982,17 @@ destroy(dns_resolver_t *res) } isc_mem_put(res->mctx, res->dbuckets, RES_DOMAIN_BUCKETS * sizeof(zonebucket_t)); - if (res->dispatches4 != NULL) + if (res->dispatches4 != NULL) { dns_dispatchset_destroy(&res->dispatches4); - if (res->dispatches6 != NULL) + } + if (res->dispatches6 != NULL) { dns_dispatchset_destroy(&res->dispatches6); + } while ((a = ISC_LIST_HEAD(res->alternates)) != NULL) { ISC_LIST_UNLINK(res->alternates, a, link); - if (!a->isaddress) + if (!a->isaddress) { dns_name_free(&a->_u._n.name, res->mctx); + } isc_mem_put(res->mctx, a, sizeof(*a)); } dns_resolver_reset_algorithms(res); @@ -9708,10 +10001,10 @@ destroy(dns_resolver_t *res) dns_resolver_resetmustbesecure(res); #if USE_ALGLOCK isc_rwlock_destroy(&res->alglock); -#endif +#endif /* if USE_ALGLOCK */ #if USE_MBSLOCK isc_rwlock_destroy(&res->mbslock); -#endif +#endif /* if USE_MBSLOCK */ isc_timer_detach(&res->spillattimer); res->magic = 0; isc_mem_put(res->mctx, res, sizeof(*res)); @@ -9746,8 +10039,9 @@ empty_bucket(dns_resolver_t *res) INSIST(res->activebuckets > 0); res->activebuckets--; - if (res->activebuckets == 0) + if (res->activebuckets == 0) { send_shutdown_events(res); + } UNLOCK(&res->lock); } @@ -9778,10 +10072,11 @@ spillattimer_countdown(isc_task_t *task, isc_event_t *event) } count = res->spillat; UNLOCK(&res->lock); - if (logit) + if (logit) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RESOLVER, DNS_LOGMODULE_RESOLVER, ISC_LOG_NOTICE, "clients-per-query decreased to %u", count); + } isc_event_free(&event); } @@ -9847,9 +10142,10 @@ dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr, res->quotaresp[dns_quotatype_zone] = DNS_R_DROP; res->quotaresp[dns_quotatype_server] = DNS_R_SERVFAIL; res->nbuckets = ntasks; - if (view->resstats != NULL) + if (view->resstats != NULL) { isc_stats_set(view->resstats, ntasks, dns_resstatscounter_buckets); + } res->activebuckets = ntasks; res->buckets = isc_mem_get(view->mctx, ntasks * sizeof(fctxbucket_t)); for (i = 0; i < ntasks; i++) { @@ -9923,31 +10219,38 @@ dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr, task = NULL; result = isc_task_create(taskmgr, 0, &task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_primelock; + } isc_task_setname(task, "resolver_task", NULL); result = isc_timer_create(timermgr, isc_timertype_inactive, NULL, NULL, task, spillattimer_countdown, res, &res->spillattimer); isc_task_detach(&task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_primelock; + } #if USE_ALGLOCK result = isc_rwlock_init(&res->alglock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_spillattimer; -#endif + } +#endif /* if USE_ALGLOCK */ #if USE_MBSLOCK result = isc_rwlock_init(&res->mbslock, 0, 0); if (result != ISC_R_SUCCESS) #if USE_ALGLOCK + { goto cleanup_alglock; -#else + } +#else /* if USE_ALGLOCK */ + { goto cleanup_spillattimer; -#endif -#endif + } +#endif /* if USE_ALGLOCK */ +#endif /* if USE_MBSLOCK */ res->magic = RES_MAGIC; @@ -9958,21 +10261,23 @@ dns_resolver_create(dns_view_t *view, isc_taskmgr_t *taskmgr, #if USE_ALGLOCK && USE_MBSLOCK cleanup_alglock: isc_rwlock_destroy(&res->alglock); -#endif +#endif /* if USE_ALGLOCK && USE_MBSLOCK */ #if USE_ALGLOCK || USE_MBSLOCK cleanup_spillattimer: isc_timer_detach(&res->spillattimer); -#endif +#endif /* if USE_ALGLOCK || USE_MBSLOCK */ cleanup_primelock: isc_mutex_destroy(&res->primelock); isc_mutex_destroy(&res->lock); - if (res->dispatches6 != NULL) + if (res->dispatches6 != NULL) { dns_dispatchset_destroy(&res->dispatches6); - if (res->dispatches4 != NULL) + } + if (res->dispatches4 != NULL) { dns_dispatchset_destroy(&res->dispatches4); + } for (i = 0; i < dbuckets_created; i++) { isc_mutex_destroy(&res->dbuckets[i].lock); @@ -10036,12 +10341,15 @@ prime_done(isc_task_t *task, isc_event_t *event) dns_db_detach(&db); } - if (fevent->node != NULL) + if (fevent->node != NULL) { dns_db_detachnode(fevent->db, &fevent->node); - if (fevent->db != NULL) + } + if (fevent->db != NULL) { dns_db_detach(&fevent->db); - if (dns_rdataset_isassociated(fevent->rdataset)) + } + if (dns_rdataset_isassociated(fevent->rdataset)) { dns_rdataset_disassociate(fevent->rdataset); + } INSIST(fevent->sigrdataset == NULL); isc_mem_put(res->mctx, fevent->rdataset, sizeof(*fevent->rdataset)); @@ -10182,8 +10490,9 @@ dns_resolver_shutdown(dns_resolver_t *res) for (i = 0; i < res->nbuckets; i++) { LOCK(&res->buckets[i].lock); for (fctx = ISC_LIST_HEAD(res->buckets[i].fctxs); - fctx != NULL; fctx = ISC_LIST_NEXT(fctx, link)) + fctx != NULL; fctx = ISC_LIST_NEXT(fctx, link)) { fctx_shutdown(fctx); + } if (res->dispatches4 != NULL && !res->exclusivev4) { dns_dispatchset_cancelall(res->dispatches4, res->buckets[i].task); @@ -10199,8 +10508,9 @@ dns_resolver_shutdown(dns_resolver_t *res) } UNLOCK(&res->buckets[i].lock); } - if (res->activebuckets == 0) + if (res->activebuckets == 0) { send_shutdown_events(res); + } result = isc_timer_reset(res->spillattimer, isc_timertype_inactive, NULL, NULL, true); @@ -10238,11 +10548,13 @@ fctx_match(fetchctx_t *fctx, const dns_name_t *name, dns_rdatatype_t type, * Don't match fetch contexts that are shutting down. */ if (fctx->cloned || fctx->state == fetchstate_done || - ISC_LIST_EMPTY(fctx->events)) + ISC_LIST_EMPTY(fctx->events)) { return (false); + } - if (fctx->type != type || fctx->options != options) + if (fctx->type != type || fctx->options != options) { return (false); + } return (dns_name_equal(&fctx->name, name)); } @@ -10257,8 +10569,9 @@ log_fetch(const dns_name_t *name, dns_rdatatype_t type) * If there's no chance of logging it, don't render (format) the * name and RDATA type (further below), and return early. */ - if (!isc_log_wouldlog(dns_lctx, level)) + if (!isc_log_wouldlog(dns_lctx, level)) { return; + } dns_name_format(name, namebuf, sizeof(namebuf)); dns_rdatatype_format(type, typebuf, sizeof(typebuf)); @@ -10390,8 +10703,9 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name, if (domain != NULL) { REQUIRE(DNS_RDATASET_VALID(nameservers)); REQUIRE(nameservers->type == dns_rdatatype_ns); - } else + } else { REQUIRE(nameservers == NULL); + } REQUIRE(forwarders == NULL); REQUIRE(!dns_rdataset_isassociated(rdataset)); REQUIRE(sigrdataset == NULL || !dns_rdataset_isassociated(sigrdataset)); @@ -10422,8 +10736,9 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name, if ((options & DNS_FETCHOPT_UNSHARED) == 0) { for (fctx = ISC_LIST_HEAD(res->buckets[bucketnum].fctxs); fctx != NULL; fctx = ISC_LIST_NEXT(fctx, link)) { - if (fctx_match(fctx, name, type, options)) + if (fctx_match(fctx, name, type, options)) { break; + } } } @@ -10444,8 +10759,9 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name, } if (count >= spillatmin && spillatmin != 0) { INSIST(fctx != NULL); - if (count >= spillat) + if (count >= spillat) { fctx->spilled = true; + } if (fctx->spilled) { result = DNS_R_DROP; goto unlock; @@ -10456,11 +10772,13 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name, result = fctx_create(res, name, type, domain, nameservers, client, options, bucketnum, depth, qc, &fctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } new_fctx = true; - } else if (fctx->depth > depth) + } else if (fctx->depth > depth) { fctx->depth = depth; + } result = fctx_join(fctx, task, client, id, action, arg, rdataset, sigrdataset, fetch); @@ -10487,14 +10805,16 @@ dns_resolver_createfetch(dns_resolver_t *res, const dns_name_t *name, unlock: UNLOCK(&res->buckets[bucketnum].lock); - if (dodestroy) + if (dodestroy) { fctx_destroy(fctx); + } if (result == ISC_R_SUCCESS) { FTRACE("created"); *fetchp = fetch; - } else + } else { isc_mem_putanddetach(&fetch->mctx, fetch, sizeof(*fetch)); + } return (result); } @@ -10587,8 +10907,9 @@ dns_resolver_destroyfetch(dns_fetch_t **fetchp) isc_mem_putanddetach(&fetch->mctx, fetch, sizeof(*fetch)); - if (bucket_empty) + if (bucket_empty) { empty_bucket(res); + } } void @@ -10724,10 +11045,11 @@ dns_resolver_getudpsize(dns_resolver_t *resolver) void dns_resolver_flushbadcache(dns_resolver_t *resolver, const dns_name_t *name) { - if (name != NULL) + if (name != NULL) { dns_badcache_flushname(resolver->badcache, name); - else + } else { dns_badcache_flush(resolver->badcache); + } } void @@ -10742,7 +11064,7 @@ dns_resolver_addbadcache(dns_resolver_t *resolver, const dns_name_t *name, { #ifdef ENABLE_AFL if (!dns_fuzzing_resolver) -#endif +#endif /* ifdef ENABLE_AFL */ { dns_badcache_add(resolver->badcache, name, type, false, 0, expire); @@ -10778,12 +11100,13 @@ dns_resolver_reset_algorithms(dns_resolver_t *resolver) #if USE_ALGLOCK RWLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif - if (resolver->algorithms != NULL) +#endif /* if USE_ALGLOCK */ + if (resolver->algorithms != NULL) { dns_rbt_destroy(&resolver->algorithms); + } #if USE_ALGLOCK RWUNLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif +#endif /* if USE_ALGLOCK */ } isc_result_t @@ -10803,17 +11126,19 @@ dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name, */ REQUIRE(VALID_RESOLVER(resolver)); - if (alg > 255) + if (alg > 255) { return (ISC_R_RANGE); + } #if USE_ALGLOCK RWLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif +#endif /* if USE_ALGLOCK */ if (resolver->algorithms == NULL) { result = dns_rbt_create(resolver->mctx, free_algorithm, resolver->mctx, &resolver->algorithms); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } len = alg / 8 + 2; @@ -10836,24 +11161,27 @@ dns_resolver_disable_algorithm(dns_resolver_t *resolver, const dns_name_t *name, */ tmp = isc_mem_get(resolver->mctx, len); memset(tmp, 0, len); - if (algorithms != NULL) + if (algorithms != NULL) { memmove(tmp, algorithms, *algorithms); + } tmp[len - 1] |= mask; /* 'tmp[0]' should contain the length of 'tmp'. */ *tmp = len; node->data = tmp; /* Free the older bitfield. */ - if (algorithms != NULL) + if (algorithms != NULL) { isc_mem_put(resolver->mctx, algorithms, *algorithms); - } else + } + } else { algorithms[len - 1] |= mask; + } } result = ISC_R_SUCCESS; cleanup: #if USE_ALGLOCK RWUNLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif +#endif /* if USE_ALGLOCK */ return (result); } @@ -10872,28 +11200,32 @@ dns_resolver_algorithm_supported(dns_resolver_t * resolver, /* * DH is unsupported for DNSKEYs, see RFC 4034 sec. A.1. */ - if ((alg == DST_ALG_DH) || (alg == DST_ALG_INDIRECT)) + if ((alg == DST_ALG_DH) || (alg == DST_ALG_INDIRECT)) { return (false); + } #if USE_ALGLOCK RWLOCK(&resolver->alglock, isc_rwlocktype_read); -#endif - if (resolver->algorithms == NULL) +#endif /* if USE_ALGLOCK */ + if (resolver->algorithms == NULL) { goto unlock; + } result = dns_rbt_findname(resolver->algorithms, name, 0, NULL, &data); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { len = alg / 8 + 2; mask = 1 << (alg % 8); algorithms = data; - if (len <= *algorithms && (algorithms[len - 1] & mask) != 0) + if (len <= *algorithms && (algorithms[len - 1] & mask) != 0) { found = true; + } } unlock: #if USE_ALGLOCK RWUNLOCK(&resolver->alglock, isc_rwlocktype_read); -#endif - if (found) +#endif /* if USE_ALGLOCK */ + if (found) { return (false); + } return (dst_algorithm_supported(alg)); } @@ -10914,12 +11246,13 @@ dns_resolver_reset_ds_digests(dns_resolver_t *resolver) #if USE_ALGLOCK RWLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif - if (resolver->digests != NULL) +#endif /* if USE_ALGLOCK */ + if (resolver->digests != NULL) { dns_rbt_destroy(&resolver->digests); + } #if USE_ALGLOCK RWUNLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif +#endif /* if USE_ALGLOCK */ } isc_result_t @@ -10938,17 +11271,19 @@ dns_resolver_disable_ds_digest(dns_resolver_t *resolver, const dns_name_t *name, */ REQUIRE(VALID_RESOLVER(resolver)); - if (digest_type > 255) + if (digest_type > 255) { return (ISC_R_RANGE); + } #if USE_ALGLOCK RWLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif +#endif /* if USE_ALGLOCK */ if (resolver->digests == NULL) { result = dns_rbt_create(resolver->mctx, free_digest, resolver->mctx, &resolver->digests); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } len = digest_type / 8 + 2; @@ -10968,23 +11303,26 @@ dns_resolver_disable_ds_digest(dns_resolver_t *resolver, const dns_name_t *name, */ tmp = isc_mem_get(resolver->mctx, len); memset(tmp, 0, len); - if (digests != NULL) + if (digests != NULL) { memmove(tmp, digests, *digests); + } tmp[len - 1] |= mask; /* tmp[0] should contain the length of 'tmp'. */ *tmp = len; node->data = tmp; /* Free the older bitfield. */ - if (digests != NULL) + if (digests != NULL) { isc_mem_put(resolver->mctx, digests, *digests); - } else + } + } else { digests[len - 1] |= mask; + } } result = ISC_R_SUCCESS; cleanup: #if USE_ALGLOCK RWUNLOCK(&resolver->alglock, isc_rwlocktype_write); -#endif +#endif /* if USE_ALGLOCK */ return (result); } @@ -11003,23 +11341,26 @@ dns_resolver_ds_digest_supported(dns_resolver_t * resolver, #if USE_ALGLOCK RWLOCK(&resolver->alglock, isc_rwlocktype_read); -#endif - if (resolver->digests == NULL) +#endif /* if USE_ALGLOCK */ + if (resolver->digests == NULL) { goto unlock; + } result = dns_rbt_findname(resolver->digests, name, 0, NULL, &data); if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { len = digest_type / 8 + 2; mask = 1 << (digest_type % 8); digests = data; - if (len <= *digests && (digests[len - 1] & mask) != 0) + if (len <= *digests && (digests[len - 1] & mask) != 0) { found = true; + } } unlock: #if USE_ALGLOCK RWUNLOCK(&resolver->alglock, isc_rwlocktype_read); -#endif - if (found) +#endif /* if USE_ALGLOCK */ + if (found) { return (false); + } return (dst_ds_digest_supported(digest_type)); } @@ -11030,12 +11371,13 @@ dns_resolver_resetmustbesecure(dns_resolver_t *resolver) #if USE_MBSLOCK RWLOCK(&resolver->mbslock, isc_rwlocktype_write); -#endif - if (resolver->mustbesecure != NULL) +#endif /* if USE_MBSLOCK */ + if (resolver->mustbesecure != NULL) { dns_rbt_destroy(&resolver->mustbesecure); + } #if USE_MBSLOCK RWUNLOCK(&resolver->mbslock, isc_rwlocktype_write); -#endif +#endif /* if USE_MBSLOCK */ } static bool yes = true, no = false; @@ -11050,19 +11392,20 @@ dns_resolver_setmustbesecure(dns_resolver_t *resolver, const dns_name_t *name, #if USE_MBSLOCK RWLOCK(&resolver->mbslock, isc_rwlocktype_write); -#endif +#endif /* if USE_MBSLOCK */ if (resolver->mustbesecure == NULL) { result = dns_rbt_create(resolver->mctx, NULL, NULL, &resolver->mustbesecure); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } result = dns_rbt_addname(resolver->mustbesecure, name, value ? &yes : &no); cleanup: #if USE_MBSLOCK RWUNLOCK(&resolver->mbslock, isc_rwlocktype_write); -#endif +#endif /* if USE_MBSLOCK */ return (result); } @@ -11077,16 +11420,18 @@ dns_resolver_getmustbesecure(dns_resolver_t *resolver, const dns_name_t *name) #if USE_MBSLOCK RWLOCK(&resolver->mbslock, isc_rwlocktype_read); -#endif - if (resolver->mustbesecure == NULL) +#endif /* if USE_MBSLOCK */ + if (resolver->mustbesecure == NULL) { goto unlock; + } result = dns_rbt_findname(resolver->mustbesecure, name, 0, NULL, &data); - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { value = *(bool *)data; + } unlock: #if USE_MBSLOCK RWUNLOCK(&resolver->mbslock, isc_rwlocktype_read); -#endif +#endif /* if USE_MBSLOCK */ return (value); } @@ -11097,12 +11442,15 @@ dns_resolver_getclientsperquery(dns_resolver_t *resolver, uint32_t *cur, REQUIRE(VALID_RESOLVER(resolver)); LOCK(&resolver->lock); - if (cur != NULL) + if (cur != NULL) { *cur = resolver->spillat; - if (min != NULL) + } + if (min != NULL) { *min = resolver->spillatmin; - if (max != NULL) + } + if (max != NULL) { *max = resolver->spillatmax; + } UNLOCK(&resolver->lock); } @@ -11163,15 +11511,19 @@ dns_resolver_settimeout(dns_resolver_t *resolver, unsigned int timeout) { REQUIRE(VALID_RESOLVER(resolver)); - if (timeout <= 300) + if (timeout <= 300) { timeout *= 1000; + } - if (timeout == 0) + if (timeout == 0) { timeout = DEFAULT_QUERY_TIMEOUT; - if (timeout > MAXIMUM_QUERY_TIMEOUT) + } + if (timeout > MAXIMUM_QUERY_TIMEOUT) { timeout = MAXIMUM_QUERY_TIMEOUT; - if (timeout < MINIMUM_QUERY_TIMEOUT) + } + if (timeout < MINIMUM_QUERY_TIMEOUT) { timeout = MINIMUM_QUERY_TIMEOUT; + } resolver->query_timeout = timeout; } diff --git a/lib/dns/result.c b/lib/dns/result.c index a6dd12686a..a4ef2bdb38 100644 --- a/lib/dns/result.c +++ b/lib/dns/result.c @@ -335,23 +335,27 @@ initialize_action(void) result = isc_result_register(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS, text, DNS_RESULT_RESULTSET); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_result_register(ISC_RESULTCLASS_DNSRCODE, DNS_R_NRCODERESULTS, rcode_text, DNS_RESULT_RCODERESULTSET); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_result_register() failed: %u", result); + } result = isc_result_registerids(ISC_RESULTCLASS_DNS, DNS_R_NRESULTS, ids, DNS_RESULT_RESULTSET); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_result_registerids(ISC_RESULTCLASS_DNSRCODE, DNS_R_NRCODERESULTS, rcode_ids, DNS_RESULT_RCODERESULTSET); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_result_registerids() failed: %u", result); + } } static void diff --git a/lib/dns/rootns.c b/lib/dns/rootns.c index a3839e28b7..ef3e575bbf 100644 --- a/lib/dns/rootns.c +++ b/lib/dns/rootns.c @@ -84,22 +84,26 @@ in_rootns(dns_rdataset_t *rootns, dns_name_t *name) dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdata_ns_t ns; - if (!dns_rdataset_isassociated(rootns)) + if (!dns_rdataset_isassociated(rootns)) { return (ISC_R_NOTFOUND); + } result = dns_rdataset_first(rootns); while (result == ISC_R_SUCCESS) { dns_rdataset_current(rootns, &rdata); result = dns_rdata_tostruct(&rdata, &ns, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (dns_name_compare(name, &ns.name) == 0) + } + if (dns_name_compare(name, &ns.name) == 0) { return (ISC_R_SUCCESS); + } result = dns_rdataset_next(rootns); dns_rdata_reset(&rdata); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_NOTFOUND; + } return (result); } @@ -118,13 +122,15 @@ check_node(dns_rdataset_t *rootns, dns_name_t *name, case dns_rdatatype_a: case dns_rdatatype_aaaa: result = in_rootns(rootns, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } break; case dns_rdatatype_ns: - if (dns_name_compare(name, dns_rootname) == 0) + if (dns_name_compare(name, dns_rootname) == 0) { break; - /* FALLTHROUGH */ + } + /* FALLTHROUGH */ default: result = ISC_R_FAILURE; goto cleanup; @@ -132,11 +138,13 @@ check_node(dns_rdataset_t *rootns, dns_name_t *name, dns_rdataset_disassociate(&rdataset); result = dns_rdatasetiter_next(rdsiter); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -160,35 +168,44 @@ check_hints(dns_db_t *db) (void)dns_db_find(db, dns_rootname, NULL, dns_rdatatype_ns, 0, now, NULL, name, &rootns, NULL); result = dns_db_createiterator(db, 0, &dbiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_dbiterator_first(dbiter); while (result == ISC_R_SUCCESS) { result = dns_dbiterator_current(dbiter, &node, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_db_allrdatasets(db, node, NULL, now, &rdsiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = check_node(&rootns, name, rdsiter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdatasetiter_destroy(&rdsiter); dns_db_detachnode(db, &node); result = dns_dbiterator_next(dbiter); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: - if (dns_rdataset_isassociated(&rootns)) + if (dns_rdataset_isassociated(&rootns)) { dns_rdataset_disassociate(&rootns); - if (rdsiter != NULL) + } + if (rdsiter != NULL) { dns_rdatasetiter_destroy(&rdsiter); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); - if (dbiter != NULL) + } + if (dbiter != NULL) { dns_dbiterator_destroy(&dbiter); + } return (result); } @@ -206,8 +223,9 @@ dns_rootns_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, result = dns_db_create(mctx, "rbt", dns_rootname, dns_dbtype_zone, rdclass, 0, NULL, &db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } len = strlen(root_ns); isc_buffer_init(&source, root_ns, len); @@ -215,8 +233,9 @@ dns_rootns_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_rdatacallbacks_init(&callbacks); result = dns_db_beginload(db, &callbacks); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } if (filename != NULL) { /* * Load the hints from the specified filename. @@ -232,18 +251,22 @@ dns_rootns_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, result = dns_master_loadbuffer( &source, &db->origin, &db->origin, db->rdclass, DNS_MASTER_HINT, &callbacks, db->mctx); - } else + } else { result = ISC_R_NOTFOUND; + } eresult = dns_db_endload(db, &callbacks); - if (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE) + if (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE) { result = eresult; - if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) + } + if (result != ISC_R_SUCCESS && result != DNS_R_SEENINCLUDE) { goto failure; - if (check_hints(db) != ISC_R_SUCCESS) + } + if (check_hints(db) != ISC_R_SUCCESS) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_HINTS, ISC_LOG_WARNING, "extra data in root hints '%s'", (filename != NULL) ? filename : ""); + } *target = db; return (ISC_R_SUCCESS); @@ -255,8 +278,9 @@ failure: (filename != NULL) ? filename : "", isc_result_totext(result)); - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } return (result); } @@ -284,17 +308,18 @@ report(dns_view_t *view, dns_name_t *name, bool missing, dns_rdata_t *rdata) RUNTIME_CHECK(result == ISC_R_SUCCESS); databuf[isc_buffer_usedlength(&buffer)] = '\0'; - if (missing) + if (missing) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_HINTS, ISC_LOG_WARNING, "checkhints%s%s: %s/%s (%s) missing from hints", sep, viewname, namebuf, typebuf, databuf); - else + } else { isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_HINTS, ISC_LOG_WARNING, "checkhints%s%s: %s/%s (%s) extra record " "in hints", sep, viewname, namebuf, typebuf, databuf); + } } static bool @@ -306,8 +331,9 @@ inrrset(dns_rdataset_t *rrset, dns_rdata_t *rdata) result = dns_rdataset_first(rrset); while (result == ISC_R_SUCCESS) { dns_rdataset_current(rrset, ¤t); - if (dns_rdata_compare(rdata, ¤t) == 0) + if (dns_rdata_compare(rdata, ¤t) == 0) { return (true); + } dns_rdata_reset(¤t); result = dns_rdataset_next(rrset); } @@ -345,16 +371,18 @@ check_address_records(dns_view_t *view, dns_db_t *hints, dns_db_t *db, while (result == ISC_R_SUCCESS) { dns_rdata_reset(&rdata); dns_rdataset_current(&rootrrset, &rdata); - if (!inrrset(&hintrrset, &rdata)) + if (!inrrset(&hintrrset, &rdata)) { report(view, name, true, &rdata); + } result = dns_rdataset_next(&rootrrset); } result = dns_rdataset_first(&hintrrset); while (result == ISC_R_SUCCESS) { dns_rdata_reset(&rdata); dns_rdataset_current(&hintrrset, &rdata); - if (!inrrset(&rootrrset, &rdata)) + if (!inrrset(&rootrrset, &rdata)) { report(view, name, false, &rdata); + } result = dns_rdataset_next(&hintrrset); } } @@ -368,10 +396,12 @@ check_address_records(dns_view_t *view, dns_db_t *hints, dns_db_t *db, result = dns_rdataset_next(&rootrrset); } } - if (dns_rdataset_isassociated(&rootrrset)) + if (dns_rdataset_isassociated(&rootrrset)) { dns_rdataset_disassociate(&rootrrset); - if (dns_rdataset_isassociated(&hintrrset)) + } + if (dns_rdataset_isassociated(&hintrrset)) { dns_rdataset_disassociate(&hintrrset); + } /* * Check AAAA records. @@ -387,8 +417,9 @@ check_address_records(dns_view_t *view, dns_db_t *hints, dns_db_t *db, while (result == ISC_R_SUCCESS) { dns_rdata_reset(&rdata); dns_rdataset_current(&rootrrset, &rdata); - if (!inrrset(&hintrrset, &rdata)) + if (!inrrset(&hintrrset, &rdata)) { report(view, name, true, &rdata); + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&rootrrset); } @@ -396,8 +427,9 @@ check_address_records(dns_view_t *view, dns_db_t *hints, dns_db_t *db, while (result == ISC_R_SUCCESS) { dns_rdata_reset(&rdata); dns_rdataset_current(&hintrrset, &rdata); - if (!inrrset(&rootrrset, &rdata)) + if (!inrrset(&rootrrset, &rdata)) { report(view, name, false, &rdata); + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&hintrrset); } @@ -413,10 +445,12 @@ check_address_records(dns_view_t *view, dns_db_t *hints, dns_db_t *db, result = dns_rdataset_next(&rootrrset); } } - if (dns_rdataset_isassociated(&rootrrset)) + if (dns_rdataset_isassociated(&rootrrset)) { dns_rdataset_disassociate(&rootrrset); - if (dns_rdataset_isassociated(&hintrrset)) + } + if (dns_rdataset_isassociated(&hintrrset)) { dns_rdataset_disassociate(&hintrrset); + } } void @@ -487,8 +521,9 @@ dns_root_checkhints(dns_view_t *view, dns_db_t *hints, dns_db_t *db) "checkhints%s%s: unable to find root " "NS '%s' in hints", sep, viewname, namebuf); - } else + } else { check_address_records(view, hints, db, &ns.name, now); + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&rootns); } @@ -522,8 +557,10 @@ dns_root_checkhints(dns_view_t *view, dns_db_t *hints, dns_db_t *db) } cleanup: - if (dns_rdataset_isassociated(&rootns)) + if (dns_rdataset_isassociated(&rootns)) { dns_rdataset_disassociate(&rootns); - if (dns_rdataset_isassociated(&hintns)) + } + if (dns_rdataset_isassociated(&hintns)) { dns_rdataset_disassociate(&hintns); + } } diff --git a/lib/dns/rpz.c b/lib/dns/rpz.c index ba9a7ef882..6551b38bab 100644 --- a/lib/dns/rpz.c +++ b/lib/dns/rpz.c @@ -193,7 +193,7 @@ catch_name(const dns_name_t *src_name, const char *tgt, const char *str) { "rpz hit failed: %s %s", str, tgt); } } -#endif +#endif /* if 0 */ const char * dns_rpz_type2str(dns_rpz_type_t type) @@ -235,11 +235,13 @@ dns_rpz_str2policy(const char *str) }; unsigned int n; - if (str == NULL) + if (str == NULL) { return (DNS_RPZ_POLICY_ERROR); + } for (n = 0; n < sizeof(tbl) / sizeof(tbl[0]); ++n) { - if (!strcasecmp(tbl[n].str, str)) + if (!strcasecmp(tbl[n].str, str)) { return (tbl[n].policy); + } } return (DNS_RPZ_POLICY_ERROR); } @@ -316,8 +318,9 @@ zbit_to_num(dns_rpz_zbits_t zbit) zbit >>= 2; rpz_num += 2; } - if ((zbit & 2) != 0) + if ((zbit & 2) != 0) { ++rpz_num; + } return (rpz_num); } @@ -396,8 +399,9 @@ set_sum_pair(dns_rpz_cidr_node_t *cnode) } if (cnode->sum.client_ip == sum.client_ip && - cnode->sum.ip == sum.ip && cnode->sum.nsip == sum.nsip) + cnode->sum.ip == sum.ip && cnode->sum.nsip == sum.nsip) { break; + } cnode->sum = sum; cnode = cnode->parent; } while (cnode != NULL); @@ -649,8 +653,9 @@ new_node(dns_rpz_zones_t *rpzs, const dns_rpz_cidr_key_t *ip, node = isc_mem_get(rpzs->mctx, sizeof(*node)); memset(node, 0, sizeof(*node)); - if (child != NULL) + if (child != NULL) { node->sum = child->sum; + } node->prefix = prefix; words = prefix / DNS_RPZ_CIDR_WORD_BITS; @@ -664,8 +669,9 @@ new_node(dns_rpz_zones_t *rpzs, const dns_rpz_cidr_key_t *ip, node->ip.w[i] = ip->w[i] & DNS_RPZ_WORD_MASK(wlen); ++i; } - while (i < DNS_RPZ_CIDR_WORDS) + while (i < DNS_RPZ_CIDR_WORDS) { node->ip.w[i++] = 0; + } return (node); } @@ -704,7 +710,7 @@ ip2name(const dns_rpz_cidr_key_t *tgt_ip, dns_rpz_prefix_t tgt_prefix, { #ifndef INET6_ADDRSTRLEN #define INET6_ADDRSTRLEN 46 -#endif +#endif /* ifndef INET6_ADDRSTRLEN */ int w[DNS_RPZ_CIDR_WORDS * 2]; char str[1 + 8 + 1 + INET6_ADDRSTRLEN + 1]; isc_buffer_t buffer; @@ -835,10 +841,11 @@ name2ipkey(int log_level, const dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, make_addr_set(new_set, DNS_RPZ_ZBIT(rpz_num), rpz_type); ip_labels = dns_name_countlabels(src_name); - if (rpz_type == DNS_RPZ_TYPE_QNAME) + if (rpz_type == DNS_RPZ_TYPE_QNAME) { ip_labels -= dns_name_countlabels(&rpz->origin); - else + } else { ip_labels -= dns_name_countlabels(&rpz->nsdname); + } if (ip_labels < 2) { badname(log_level, src_name, "; too short", ""); return (ISC_R_FAILURE); @@ -890,8 +897,9 @@ name2ipkey(int log_level, const dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, for (i = 0; i < 32; i += 8) { l = strtoul(cp, &cp2, 10); if (l > 255U || (*cp2 != '.' && *cp2 != '\0')) { - if (*cp2 == '.') + if (*cp2 == '.') { *cp2 = '\0'; + } badname(log_level, src_name, "; invalid IPv4 octet ", cp); return (ISC_R_FAILURE); @@ -909,8 +917,9 @@ name2ipkey(int log_level, const dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, if (cp[0] == 'z' && cp[1] == 'z' && (cp[2] == '.' || cp[2] == '\0') && i <= 6) { do { - if ((i & 1) == 0) + if ((i & 1) == 0) { tgt_ip->w[3 - i / 2] = 0; + } ++i; } while (ip_labels + i <= 8); cp += 3; @@ -918,16 +927,18 @@ name2ipkey(int log_level, const dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, l = strtoul(cp, &cp2, 16); if (l > 0xffffu || (*cp2 != '.' && *cp2 != '\0')) { - if (*cp2 == '.') + if (*cp2 == '.') { *cp2 = '\0'; + } badname(log_level, src_name, "; invalid IPv6 word ", cp); return (ISC_R_FAILURE); } - if ((i & 1) == 0) + if ((i & 1) == 0) { tgt_ip->w[3 - i / 2] = l; - else + } else { tgt_ip->w[3 - i / 2] |= l << 16; + } i++; cp = cp2 + 1; } @@ -1018,10 +1029,11 @@ name2data(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, dns_name_init(&tmp_name, tmp_name_offsets); n = dns_name_countlabels(src_name); n -= prefix_len; - if (rpz_type == DNS_RPZ_TYPE_QNAME) + if (rpz_type == DNS_RPZ_TYPE_QNAME) { n -= dns_name_countlabels(&rpz->origin); - else + } else { n -= dns_name_countlabels(&rpz->nsdname); + } dns_name_getlabelsequence(src_name, prefix_len, n, &tmp_name); (void)dns_name_concatenate(&tmp_name, dns_rootname, trig_name, NULL); } @@ -1058,12 +1070,13 @@ clz(dns_rpz_cidr_word_t w) bit -= 2; } - if ((w & 2) != 0) + if ((w & 2) != 0) { --bit; + } return (bit); } -#endif +#endif /* ifndef HAVE_BUILTIN_CLZ */ /* * Find the first differing bit in two keys (IP addresses). @@ -1087,9 +1100,9 @@ diff_keys(const dns_rpz_cidr_key_t *key1, dns_rpz_prefix_t prefix1, if (ISC_UNLIKELY(delta != 0)) { #ifdef HAVE_BUILTIN_CLZ bit += __builtin_clz(delta); -#else +#else /* ifdef HAVE_BUILTIN_CLZ */ bit += clz(delta); -#endif +#endif /* ifdef HAVE_BUILTIN_CLZ */ break; } } @@ -1147,15 +1160,18 @@ search(dns_rpz_zones_t *rpzs, const dns_rpz_cidr_key_t *tgt_ip, * Quit with whatever we already found * or add the target as a child of the current parent. */ - if (!create) + if (!create) { return (find_result); + } child = new_node(rpzs, tgt_ip, tgt_prefix, NULL); - if (child == NULL) + if (child == NULL) { return (ISC_R_NOMEMORY); - if (parent == NULL) + } + if (parent == NULL) { rpzs->cidr = child; - else + } else { parent->child[cur_num] = child; + } child->parent = parent; child->set.client_ip |= tgt_set->client_ip; child->set.ip |= tgt_set->ip; @@ -1176,8 +1192,9 @@ search(dns_rpz_zones_t *rpzs, const dns_rpz_cidr_key_t *tgt_ip, * If we are adding, continue down to eventually add * a node and mark/put this node in the correct tree. */ - if (!create) + if (!create) { return (find_result); + } } dbit = diff_keys(tgt_ip, tgt_prefix, &cur->ip, cur->prefix); @@ -1223,17 +1240,20 @@ search(dns_rpz_zones_t *rpzs, const dns_rpz_cidr_key_t *tgt_ip, * the target is shorter than the current node. * Add the target as the current node's parent. */ - if (!create) + if (!create) { return (find_result); + } new_parent = new_node(rpzs, tgt_ip, tgt_prefix, cur); - if (new_parent == NULL) + if (new_parent == NULL) { return (ISC_R_NOMEMORY); + } new_parent->parent = parent; - if (parent == NULL) + if (parent == NULL) { rpzs->cidr = new_parent; - else + } else { parent->child[cur_num] = new_parent; + } child_num = DNS_RPZ_IP_BIT(&cur->ip, tgt_prefix); new_parent->child[child_num] = cur; cur->parent = new_parent; @@ -1272,22 +1292,25 @@ search(dns_rpz_zones_t *rpzs, const dns_rpz_cidr_key_t *tgt_ip, * Insert a fork of a parent above the current node and * add the target as a sibling of the current node */ - if (!create) + if (!create) { return (find_result); + } sibling = new_node(rpzs, tgt_ip, tgt_prefix, NULL); - if (sibling == NULL) + if (sibling == NULL) { return (ISC_R_NOMEMORY); + } new_parent = new_node(rpzs, tgt_ip, dbit, cur); if (new_parent == NULL) { isc_mem_put(rpzs->mctx, sibling, sizeof(*sibling)); return (ISC_R_NOMEMORY); } new_parent->parent = parent; - if (parent == NULL) + if (parent == NULL) { rpzs->cidr = new_parent; - else + } else { parent->child[cur_num] = new_parent; + } child_num = DNS_RPZ_IP_BIT(tgt_ip, dbit); new_parent->child[child_num] = sibling; new_parent->child[1 - child_num] = cur; @@ -1318,8 +1341,9 @@ add_cidr(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, /* * Log complaints about bad owner names but let the zone load. */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_SUCCESS); + } result = search(rpzs, &tgt_ip, tgt_prefix, &set, true, &found); if (result != ISC_R_SUCCESS) { @@ -1329,8 +1353,9 @@ add_cidr(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, * Do not worry if the radix tree already exists, * because diff_apply() likes to add nodes before deleting. */ - if (result == ISC_R_EXISTS) + if (result == ISC_R_EXISTS) { return (ISC_R_SUCCESS); + } /* * bin/tests/system/rpz/tests.sh looks for "rpz.*failed". @@ -1378,8 +1403,9 @@ add_nm(dns_rpz_zones_t *rpzs, dns_name_t *trig_name, if ((nm_data->set.qname & new_data->set.qname) != 0 || (nm_data->set.ns & new_data->set.ns) != 0 || (nm_data->wild.qname & new_data->wild.qname) != 0 || - (nm_data->wild.ns & new_data->wild.ns) != 0) + (nm_data->wild.ns & new_data->wild.ns) != 0) { return (ISC_R_EXISTS); + } nm_data->set.qname |= new_data->set.qname; nm_data->set.ns |= new_data->set.ns; @@ -1411,10 +1437,12 @@ add_name(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, * Do not worry if the node already exists, * because diff_apply() likes to add nodes before deleting. */ - if (result == ISC_R_EXISTS) + if (result == ISC_R_EXISTS) { return (ISC_R_SUCCESS); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { adj_trigger_cnt(rpzs, rpz_num, rpz_type, NULL, 0, true); + } return (result); } @@ -1444,8 +1472,9 @@ dns_rpz_new_zones(dns_rpz_zones_t **rpzsp, char *rps_cstr, size_t rps_cstr_size, memset(zones, 0, sizeof(*zones)); result = isc_rwlock_init(&zones->search_lock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rwlock; + } isc_mutex_init(&zones->maint_lock); isc_refcount_init(&zones->refs, 1); @@ -1457,20 +1486,22 @@ dns_rpz_new_zones(dns_rpz_zones_t **rpzsp, char *rps_cstr, size_t rps_cstr_size, if (rps_cstr != NULL) { result = dns_dnsrps_view_init(zones, rps_cstr); } -#else +#else /* ifdef USE_DNSRPS */ INSIST(!zones->p.dnsrps_enabled); -#endif +#endif /* ifdef USE_DNSRPS */ if (result == ISC_R_SUCCESS && !zones->p.dnsrps_enabled) { result = dns_rbt_create(mctx, rpz_node_deleter, mctx, &zones->rbt); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rbt; + } result = isc_task_create(taskmgr, 0, &zones->updater); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_task; + } isc_mem_attach(mctx, &zones->mctx); zones->timermgr = timermgr; @@ -1519,8 +1550,9 @@ dns_rpz_new_zone(dns_rpz_zones_t *rpzs, dns_rpz_zone_t **rpzp) NULL, rpzs->updater, dns_rpz_update_taskaction, zone, &zone->updatetimer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_timer; + } /* * This will never be used, but costs us nothing and @@ -1528,8 +1560,9 @@ dns_rpz_new_zone(dns_rpz_zones_t *rpzs, dns_rpz_zone_t **rpzp) */ result = isc_ht_init(&zone->nodes, rpzs->mctx, 1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_ht; + } dns_name_init(&zone->origin, NULL); dns_name_init(&zone->client_ip, NULL); @@ -1592,8 +1625,9 @@ dns_rpz_dbupdate_callback(dns_db_t *db, void *fn_arg) /* New zone came as AXFR */ if (zone->db != NULL && zone->db != db) { /* We need to clean up the old DB */ - if (zone->dbversion != NULL) + if (zone->dbversion != NULL) { dns_db_closeversion(zone->db, &zone->dbversion, false); + } dns_db_updatenotify_unregister(zone->db, dns_rpz_dbupdate_callback, zone); dns_db_detach(&zone->db); @@ -1624,8 +1658,9 @@ dns_rpz_dbupdate_callback(dns_db_t *db, void *fn_arg) result = isc_timer_reset(zone->updatetimer, isc_timertype_once, NULL, &interval, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } else { isc_event_t *event; @@ -1702,8 +1737,9 @@ setup_update(dns_rpz_zone_t *rpz) nodecount >>= 1; } - if (hashsize > DNS_RPZ_HTSIZE_DIV) + if (hashsize > DNS_RPZ_HTSIZE_DIV) { hashsize -= DNS_RPZ_HTSIZE_DIV; + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, ISC_LOG_DEBUG(1), "rpz: %s: using hashtable size %d", @@ -1747,10 +1783,12 @@ setup_update(dns_rpz_zone_t *rpz) cleanup: if (result != ISC_R_SUCCESS) { - if (rpz->updbit != NULL) + if (rpz->updbit != NULL) { dns_dbiterator_destroy(&rpz->updbit); - if (rpz->newnodes != NULL) + } + if (rpz->newnodes != NULL) { isc_ht_destroy(&rpz->newnodes); + } dns_db_closeversion(rpz->updb, &rpz->updbversion, false); } @@ -1837,8 +1875,9 @@ finish_update(dns_rpz_zone_t *rpz) UNLOCK(&rpz->rpzs->maint_lock); cleanup: - if (iter != NULL) + if (iter != NULL) { isc_ht_iter_destroy(&iter); + } } static void @@ -1896,13 +1935,14 @@ update_quantum(isc_task_t *task, isc_event_t *event) result = dns_rdatasetiter_first(rdsiter); dns_rdatasetiter_destroy(&rdsiter); if (result != ISC_R_SUCCESS) { /* empty non-terminal */ - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { isc_log_write( dns_lctx, DNS_LOGCATEGORY_GENERAL, DNS_LOGMODULE_MASTER, ISC_LOG_ERROR, "rpz: %s: error %s while creating " "rdatasetiter", domain, isc_result_totext(result)); + } dns_db_detachnode(rpz->updb, &node); result = dns_dbiterator_next(rpz->updbit); continue; @@ -1981,10 +2021,12 @@ update_quantum(isc_task_t *task, isc_event_t *event) * If we're here, we've either finished or something went wrong, * so clean up. */ - if (rpz->updbit != NULL) + if (rpz->updbit != NULL) { dns_dbiterator_destroy(&rpz->updbit); - if (rpz->newnodes != NULL) + } + if (rpz->newnodes != NULL) { isc_ht_destroy(&rpz->newnodes); + } dns_db_closeversion(rpz->updb, &rpz->updbversion, false); dns_db_detach(&rpz->updb); rpz_detach(&rpz); @@ -2022,10 +2064,12 @@ dns_rpz_update_from_db(dns_rpz_zone_t *rpz) return; cleanup: - if (rpz->updbit != NULL) + if (rpz->updbit != NULL) { dns_dbiterator_destroy(&rpz->updbit); - if (rpz->newnodes != NULL) + } + if (rpz->newnodes != NULL) { isc_ht_destroy(&rpz->newnodes); + } dns_db_closeversion(rpz->updb, &rpz->updbversion, false); dns_db_detach(&rpz->updb); rpz_detach(&rpz); @@ -2055,10 +2099,11 @@ cidr_free(dns_rpz_zones_t *rpzs) /* Delete this leaf and go up. */ parent = cur->parent; - if (parent == NULL) + if (parent == NULL) { rpzs->cidr = NULL; - else + } else { parent->child[parent->child[1] == cur] = NULL; + } isc_mem_put(rpzs->mctx, cur, sizeof(*cur)); cur = parent; } @@ -2192,7 +2237,7 @@ rpz_detach_rpzs(dns_rpz_zones_t **rpzsp) if (rpzs->rps_cstr_size != 0) { #ifdef USE_DNSRPS librpz->client_detach(&rpzs->rps_client); -#endif +#endif /* ifdef USE_DNSRPS */ isc_mem_put(rpzs->mctx, rpzs->rps_cstr, rpzs->rps_cstr_size); } @@ -2292,8 +2337,9 @@ del_cidr(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, */ result = name2ipkey(DNS_RPZ_DEBUG_QUIET, rpzs, rpz_num, rpz_type, src_name, &tgt_ip, &tgt_prefix, &tgt_set); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } result = search(rpzs, &tgt_ip, tgt_prefix, &tgt_set, false, &tgt); if (result != ISC_R_SUCCESS) { @@ -2331,14 +2377,16 @@ del_cidr(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, * and 0 or 1 children. We are finished if it is not useless. */ if ((child = tgt->child[0]) != NULL) { - if (tgt->child[1] != NULL) + if (tgt->child[1] != NULL) { break; + } } else { child = tgt->child[1]; } if (tgt->set.client_ip != 0 || tgt->set.ip != 0 || - tgt->set.nsip != 0) + tgt->set.nsip != 0) { break; + } /* * Replace the pointer to this node in the parent with @@ -2353,8 +2401,9 @@ del_cidr(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, /* * If the child exists fix up its parent pointer. */ - if (child != NULL) + if (child != NULL) { child->parent = parent; + } isc_mem_put(rpzs->mctx, tgt, sizeof(*tgt)); tgt = parent; @@ -2391,8 +2440,9 @@ del_name(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, * that were later added for (often empty) wildcards * and then to the RBTDB deferred cleanup list. */ - if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH) { return; + } dns_name_format(src_name, namebuf, sizeof(namebuf)); isc_log_write(dns_lctx, DNS_LOGCATEGORY_RPZ, DNS_LOGMODULE_RBTDB, DNS_RPZ_ERROR_LEVEL, @@ -2437,8 +2487,9 @@ del_name(dns_rpz_zones_t *rpzs, dns_rpz_num_t rpz_num, dns_rpz_type_t rpz_type, } } - if (exists) + if (exists) { adj_trigger_cnt(rpzs, rpz_num, rpz_type, NULL, 0, false); + } } /* @@ -2553,8 +2604,9 @@ dns_rpz_find_ip(dns_rpz_zones_t *rpzs, dns_rpz_type_t rpz_type, return (DNS_RPZ_INVALID_NUM); } - if (zbits == 0) + if (zbits == 0) { return (DNS_RPZ_INVALID_NUM); + } make_addr_set(&tgt_set, zbits, rpz_type); RWLOCK(&rpzs->search_lock, isc_rwlocktype_read); @@ -2700,15 +2752,17 @@ dns_rpz_decode_cname(dns_rpz_zone_t *rpz, dns_rdataset_t *rdataset, /* * CNAME . means NXDOMAIN */ - if (dns_name_equal(&cname.cname, dns_rootname)) + if (dns_name_equal(&cname.cname, dns_rootname)) { return (DNS_RPZ_POLICY_NXDOMAIN); + } if (dns_name_iswildcard(&cname.cname)) { /* * CNAME *. means NODATA */ - if (dns_name_countlabels(&cname.cname) == 2) + if (dns_name_countlabels(&cname.cname) == 2) { return (DNS_RPZ_POLICY_NODATA); + } /* * A qname of www.evil.com and a policy of @@ -2716,33 +2770,38 @@ dns_rpz_decode_cname(dns_rpz_zone_t *rpz, dns_rdataset_t *rdataset, * gives a result of * evil.com CNAME evil.com.garden.net */ - if (dns_name_countlabels(&cname.cname) > 2) + if (dns_name_countlabels(&cname.cname) > 2) { return (DNS_RPZ_POLICY_WILDCNAME); + } } /* * CNAME rpz-tcp-only. means "send truncated UDP responses." */ - if (dns_name_equal(&cname.cname, &rpz->tcp_only)) + if (dns_name_equal(&cname.cname, &rpz->tcp_only)) { return (DNS_RPZ_POLICY_TCP_ONLY); + } /* * CNAME rpz-drop. means "do not respond." */ - if (dns_name_equal(&cname.cname, &rpz->drop)) + if (dns_name_equal(&cname.cname, &rpz->drop)) { return (DNS_RPZ_POLICY_DROP); + } /* * CNAME rpz-passthru. means "do not rewrite." */ - if (dns_name_equal(&cname.cname, &rpz->passthru)) + if (dns_name_equal(&cname.cname, &rpz->passthru)) { return (DNS_RPZ_POLICY_PASSTHRU); + } /* * 128.1.0.127.rpz-ip CNAME 128.1.0.0.127. is obsolete PASSTHRU */ - if (selfname != NULL && dns_name_equal(&cname.cname, selfname)) + if (selfname != NULL && dns_name_equal(&cname.cname, selfname)) { return (DNS_RPZ_POLICY_PASSTHRU); + } /* * Any other rdata gives a response consisting of the rdata. diff --git a/lib/dns/rriterator.c b/lib/dns/rriterator.c index 08a02afbe3..a8972d2ed7 100644 --- a/lib/dns/rriterator.c +++ b/lib/dns/rriterator.c @@ -44,8 +44,9 @@ dns_rriterator_init(dns_rriterator_t *it, dns_db_t *db, dns_dbversion_t *ver, it->now = now; it->node = NULL; result = dns_db_createiterator(it->db, 0, &it->dbit); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } it->rdatasetit = NULL; dns_rdata_init(&it->rdata); dns_rdataset_init(&it->rdataset); @@ -60,12 +61,15 @@ dns_rriterator_first(dns_rriterator_t *it) { REQUIRE(VALID_RRITERATOR(it)); /* Reset state */ - if (dns_rdataset_isassociated(&it->rdataset)) + if (dns_rdataset_isassociated(&it->rdataset)) { dns_rdataset_disassociate(&it->rdataset); - if (it->rdatasetit != NULL) + } + if (it->rdatasetit != NULL) { dns_rdatasetiter_destroy(&it->rdatasetit); - if (it->node != NULL) + } + if (it->node != NULL) { dns_db_detachnode(it->db, &it->node); + } it->result = dns_dbiterator_first(it->dbit); /* @@ -76,13 +80,15 @@ dns_rriterator_first(dns_rriterator_t *it) it->result = dns_dbiterator_current( it->dbit, &it->node, dns_fixedname_name(&it->fixedname)); - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } it->result = dns_db_allrdatasets(it->db, it->node, it->ver, it->now, &it->rdatasetit); - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } it->result = dns_rdatasetiter_first(it->rdatasetit); if (it->result != ISC_R_SUCCESS) { @@ -108,8 +114,9 @@ isc_result_t dns_rriterator_nextrrset(dns_rriterator_t *it) { REQUIRE(VALID_RRITERATOR(it)); - if (dns_rdataset_isassociated(&it->rdataset)) + if (dns_rdataset_isassociated(&it->rdataset)) { dns_rdataset_disassociate(&it->rdataset); + } it->result = dns_rdatasetiter_next(it->rdatasetit); /* * The while loop body is executed more than once @@ -123,21 +130,25 @@ dns_rriterator_nextrrset(dns_rriterator_t *it) /* We are at the end of the entire database. */ return (it->result); } - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } it->result = dns_dbiterator_current( it->dbit, &it->node, dns_fixedname_name(&it->fixedname)); - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } it->result = dns_db_allrdatasets(it->db, it->node, it->ver, it->now, &it->rdatasetit); - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } it->result = dns_rdatasetiter_first(it->rdatasetit); } - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } dns_rdatasetiter_current(it->rdatasetit, &it->rdataset); dns_rdataset_getownercase(&it->rdataset, dns_fixedname_name(&it->fixedname)); @@ -150,16 +161,18 @@ isc_result_t dns_rriterator_next(dns_rriterator_t *it) { REQUIRE(VALID_RRITERATOR(it)); - if (it->result != ISC_R_SUCCESS) + if (it->result != ISC_R_SUCCESS) { return (it->result); + } INSIST(it->dbit != NULL); INSIST(it->node != NULL); INSIST(it->rdatasetit != NULL); it->result = dns_rdataset_next(&it->rdataset); - if (it->result == ISC_R_NOMORE) + if (it->result == ISC_R_NOMORE) { return (dns_rriterator_nextrrset(it)); + } return (it->result); } @@ -174,12 +187,15 @@ void dns_rriterator_destroy(dns_rriterator_t *it) { REQUIRE(VALID_RRITERATOR(it)); - if (dns_rdataset_isassociated(&it->rdataset)) + if (dns_rdataset_isassociated(&it->rdataset)) { dns_rdataset_disassociate(&it->rdataset); - if (it->rdatasetit != NULL) + } + if (it->rdatasetit != NULL) { dns_rdatasetiter_destroy(&it->rdatasetit); - if (it->node != NULL) + } + if (it->node != NULL) { dns_db_detachnode(it->db, &it->node); + } dns_dbiterator_destroy(&it->dbit); } @@ -199,9 +215,11 @@ dns_rriterator_current(dns_rriterator_t *it, dns_name_t **name, uint32_t *ttl, dns_rdata_reset(&it->rdata); dns_rdataset_current(&it->rdataset, &it->rdata); - if (rdataset != NULL) + if (rdataset != NULL) { *rdataset = &it->rdataset; + } - if (rdata != NULL) + if (rdata != NULL) { *rdata = &it->rdata; + } } diff --git a/lib/dns/rrl.c b/lib/dns/rrl.c index 56ab4e8403..b4419d9a4e 100644 --- a/lib/dns/rrl.c +++ b/lib/dns/rrl.c @@ -86,8 +86,8 @@ hash_divisor(unsigned int initial) 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, - 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997,1009, -#endif + 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, 1009, +#endif /* if 0 */ }; int divisions, tries; unsigned int result; @@ -97,13 +97,15 @@ hash_divisor(unsigned int initial) if (primes[sizeof(primes) / sizeof(primes[0]) - 1] >= result) { pp = primes; - while (*pp < result) + while (*pp < result) { ++pp; + } return (*pp); } - if ((result & 1) == 0) + if ((result & 1) == 0) { ++result; + } divisions = 0; tries = 1; @@ -118,12 +120,13 @@ hash_divisor(unsigned int initial) } } while (pp < &primes[sizeof(primes) / sizeof(primes[0])]); - if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) + if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DEBUG3, "%d hash_divisor() divisions in %d tries" " to get %d from %d", divisions, tries, result, initial); + } return (result); } @@ -137,8 +140,9 @@ delta_rrl_time(isc_stdtime_t ts, isc_stdtime_t now) int delta; delta = now - ts; - if (delta >= 0) + if (delta >= 0) { return (delta); + } /* * The timestamp is in the future. That future might result from @@ -147,16 +151,18 @@ delta_rrl_time(isc_stdtime_t ts, isc_stdtime_t now) * assumed to result from clock changes. When the clock changes to * the past, make existing timestamps appear to be in the past. */ - if (delta < -DNS_RRL_MAX_TIME_TRAVEL) + if (delta < -DNS_RRL_MAX_TIME_TRAVEL) { return (DNS_RRL_FOREVER); + } return (0); } static inline int get_age(const dns_rrl_t *rrl, const dns_rrl_entry_t *e, isc_stdtime_t now) { - if (!e->ts_valid) + if (!e->ts_valid) { return (DNS_RRL_FOREVER); + } return (delta_rrl_time(e->ts + rrl->ts_bases[e->ts_gen], now)); } @@ -170,10 +176,11 @@ set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now) ts_gen = rrl->ts_gen; ts = now - rrl->ts_bases[ts_gen]; if (ts < 0) { - if (ts < -DNS_RRL_MAX_TIME_TRAVEL) + if (ts < -DNS_RRL_MAX_TIME_TRAVEL) { ts = DNS_RRL_FOREVER; - else + } else { ts = 0; + } } /* @@ -196,7 +203,7 @@ set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now) e_old = ISC_LIST_PREV(e_old, lru), ++i) { e_old->ts_valid = false; } - if (i != 0) + if (i != 0) { isc_log_write( dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DEBUG1, @@ -206,6 +213,7 @@ set_age(dns_rrl_t *rrl, dns_rrl_entry_t *e, isc_stdtime_t now) rrl->ts_bases[(ts_gen + 1) % DNS_RRL_TS_BASES], rrl->ts_bases[(ts_gen + 2) % DNS_RRL_TS_BASES], rrl->ts_bases[(ts_gen + 3) % DNS_RRL_TS_BASES]); + } rrl->ts_gen = ts_gen; rrl->ts_bases[ts_gen] = now; ts = 0; @@ -228,8 +236,9 @@ expand_entries(dns_rrl_t *rrl, int newsize) if (rrl->num_entries + newsize >= rrl->max_entries && rrl->max_entries != 0) { newsize = rrl->max_entries - rrl->num_entries; - if (newsize <= 0) + if (newsize <= 0) { return (ISC_R_SUCCESS); + } } /* @@ -238,8 +247,9 @@ expand_entries(dns_rrl_t *rrl, int newsize) */ if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DROP) && rrl->hash != NULL) { rate = rrl->probes; - if (rrl->searches != 0) + if (rrl->searches != 0) { rate /= rrl->searches; + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DROP, "increase from %d to %d RRL entries with" @@ -301,8 +311,9 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) int old_bins, new_bins, hsize; double rate; - if (rrl->old_hash != NULL) + if (rrl->old_hash != NULL) { free_old_hash(rrl); + } /* * Most searches fail and so go to the end of the chain. @@ -310,8 +321,9 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) */ old_bins = (rrl->hash == NULL) ? 0 : rrl->hash->length; new_bins = old_bins / 8 + old_bins; - if (new_bins < rrl->num_entries) + if (new_bins < rrl->num_entries) { new_bins = rrl->num_entries; + } new_bins = hash_divisor(new_bins); hsize = sizeof(dns_rrl_hash_t) + (new_bins - 1) * sizeof(hash->bins[0]); @@ -323,8 +335,9 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DROP) && old_bins != 0) { rate = rrl->probes; - if (rrl->searches != 0) + if (rrl->searches != 0) { rate /= rrl->searches; + } isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DROP, "increase from %d to %d RRL bins for" @@ -333,8 +346,9 @@ expand_rrl_hash(dns_rrl_t *rrl, isc_stdtime_t now) } rrl->old_hash = rrl->hash; - if (rrl->old_hash != NULL) + if (rrl->old_hash != NULL) { rrl->old_hash->check_time = now; + } rrl->hash = hash; return (ISC_R_SUCCESS); @@ -347,8 +361,9 @@ ref_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, int probes, isc_stdtime_t now) * Make the entry most recently used. */ if (ISC_LIST_HEAD(rrl->lru) != e) { - if (e == rrl->last_logged) + if (e == rrl->last_logged) { rrl->last_logged = ISC_LIST_PREV(e, lru); + } ISC_LIST_UNLINK(rrl->lru, e, lru); ISC_LIST_PREPEND(rrl->lru, e, lru); } @@ -363,8 +378,9 @@ ref_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, int probes, isc_stdtime_t now) ++rrl->searches; if (rrl->searches > 100 && delta_rrl_time(rrl->hash->check_time, now) > 1) { - if (rrl->probes / rrl->searches > 2) + if (rrl->probes / rrl->searches > 2) { expand_rrl_hash(rrl, now); + } rrl->hash->check_time = now; rrl->probes = 0; rrl->searches = 0; @@ -374,8 +390,9 @@ ref_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, int probes, isc_stdtime_t now) static inline bool key_cmp(const dns_rrl_key_t *a, const dns_rrl_key_t *b) { - if (memcmp(a, b, sizeof(dns_rrl_key_t)) == 0) + if (memcmp(a, b, sizeof(dns_rrl_key_t)) == 0) { return (true); + } return (false); } @@ -449,8 +466,9 @@ make_key(const dns_rrl_t *rrl, dns_rrl_key_t *key, key->s.ipv6 = true; memmove(key->s.ip, &client_addr->type.sin6.sin6_addr, sizeof(key->s.ip)); - for (i = 0; i < DNS_RRL_MAX_PREFIX / 32; ++i) + for (i = 0; i < DNS_RRL_MAX_PREFIX / 32; ++i) { key->s.ip[i] &= rrl->ipv6_mask[i]; + } break; } } @@ -491,8 +509,9 @@ response_balance(dns_rrl_t *rrl, const dns_rrl_entry_t *e, int age) } balance = e->responses + age * rate; - if (balance > rate) + if (balance > rate) { balance = rate; + } return (balance); } @@ -551,12 +570,14 @@ get_entry(dns_rrl_t *rrl, const isc_sockaddr_t *client_addr, * Discard prevous hash table when all of its entries are old. */ age = delta_rrl_time(rrl->old_hash->check_time, now); - if (age > rrl->window) + if (age > rrl->window) { free_old_hash(rrl); + } } - if (!create) + if (!create) { return (NULL); + } /* * The entry does not exist, so create it by finding a free entry. @@ -566,27 +587,31 @@ get_entry(dns_rrl_t *rrl, const isc_sockaddr_t *client_addr, */ for (e = ISC_LIST_TAIL(rrl->lru); e != NULL; e = ISC_LIST_PREV(e, lru)) { - if (!ISC_LINK_LINKED(e, hlink)) + if (!ISC_LINK_LINKED(e, hlink)) { break; + } age = get_age(rrl, e, now); if (age <= 1) { e = NULL; break; } - if (!e->logged && response_balance(rrl, e, age) > 0) + if (!e->logged && response_balance(rrl, e, age) > 0) { break; + } } if (e == NULL) { expand_entries(rrl, ISC_MIN((rrl->num_entries + 1) / 2, 1000)); e = ISC_LIST_TAIL(rrl->lru); } - if (e->logged) + if (e->logged) { log_end(rrl, e, true, log_buf, log_buf_len); + } if (ISC_LINK_LINKED(e, hlink)) { - if (e->hash_gen == rrl->hash_gen) + if (e->hash_gen == rrl->hash_gen) { hash = rrl->hash; - else + } else { hash = rrl->old_hash; + } old_bin = get_bin(hash, hash_key(&e->key)); ISC_LIST_UNLINK(*old_bin, e, hlink); } @@ -630,8 +655,9 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale, */ ratep = get_rate(rrl, e->key.s.rtype); rate = ratep->r; - if (rate == 0) + if (rate == 0) { return (DNS_RRL_RESULT_OK); + } if (scale < 1.0) { /* @@ -642,14 +668,16 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale, log_buf, log_buf_len); if (credit_e != NULL) { age = get_age(rrl, e, now); - if (age < rrl->window) + if (age < rrl->window) { scale = 1.0; + } } } if (scale < 1.0) { new_rate = (int)(rate * scale); - if (new_rate < 1) + if (new_rate < 1) { new_rate = 1; + } if (ratep->scaled != new_rate) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DEBUG1, @@ -695,8 +723,9 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale, if (e->logged) { log_secs = e->log_secs; log_secs += age; - if (log_secs > DNS_RRL_MAX_LOG_SECS || log_secs < 0) + if (log_secs > DNS_RRL_MAX_LOG_SECS || log_secs < 0) { log_secs = DNS_RRL_MAX_LOG_SECS; + } e->log_secs = log_secs; } } @@ -706,13 +735,15 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale, * Debit the entry for this response. */ if (--e->responses >= 0) { - if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) + if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) { debit_log(e, age, ""); + } return (DNS_RRL_RESULT_OK); } - if (e->responses < min) + if (e->responses < min) { e->responses = min; + } /* * Drop this response unless it should slip or leak. @@ -720,8 +751,9 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale, slip = rrl->slip.r; if (slip > 2 && scale < 1.0) { new_slip = (int)(slip * scale); - if (new_slip < 2) + if (new_slip < 2) { new_slip = 2; + } if (rrl->slip.scaled != new_slip) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, DNS_RRL_LOG_DEBUG1, @@ -734,18 +766,21 @@ debit_rrl_entry(dns_rrl_t *rrl, dns_rrl_entry_t *e, double qps, double scale, } if (slip != 0 && e->key.s.rtype != DNS_RRL_RTYPE_ALL) { if (e->slip_cnt++ == 0) { - if ((int)e->slip_cnt >= slip) + if ((int)e->slip_cnt >= slip) { e->slip_cnt = 0; - if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) + } + if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) { debit_log(e, age, "slip"); + } return (DNS_RRL_RESULT_SLIP); } else if ((int)e->slip_cnt >= slip) { e->slip_cnt = 0; } } - if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) + if (isc_log_wouldlog(dns_lctx, DNS_RRL_LOG_DEBUG3)) { debit_log(e, age, "drop"); + } return (DNS_RRL_RESULT_DROP); } @@ -755,8 +790,9 @@ get_qname(dns_rrl_t *rrl, const dns_rrl_entry_t *e) dns_rrl_qname_buf_t *qbuf; qbuf = rrl->qnames[e->log_qname]; - if (qbuf == NULL || qbuf->e != e) + if (qbuf == NULL || qbuf->e != e) { return (NULL); + } return (qbuf); } @@ -779,8 +815,9 @@ add_log_str(isc_buffer_t *lb, const char *str, unsigned int str_len) isc_buffer_availableregion(lb, ®ion); if (str_len >= region.length) { - if (region.length == 0U) + if (region.length == 0U) { return; + } str_len = region.length; } memmove(region.base, str, str_len); @@ -806,16 +843,19 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1, isc_result_t msg_result; if (log_buf_len <= 1) { - if (log_buf_len == 1) + if (log_buf_len == 1) { log_buf[0] = '\0'; + } return; } isc_buffer_init(&lb, log_buf, log_buf_len - 1); - if (str1 != NULL) + if (str1 != NULL) { add_log_str(&lb, str1, strlen(str1)); - if (str2 != NULL) + } + if (str2 != NULL) { add_log_str(&lb, str2, strlen(str2)); + } switch (rrl_result) { case DNS_RRL_RESULT_OK: @@ -860,10 +900,11 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1, ISC_UNREACHABLE(); } - if (plural) + if (plural) { ADD_LOG_CSTR(&lb, "responses to "); - else + } else { ADD_LOG_CSTR(&lb, "response to "); + } memset(&cidr, 0, sizeof(cidr)); if (e->key.s.ipv6) { @@ -877,8 +918,9 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1, cidr.type.in.s_addr = e->key.s.ip[0]; } msg_result = isc_netaddr_totext(&cidr, &lb); - if (msg_result != ISC_R_SUCCESS) + if (msg_result != ISC_R_SUCCESS) { ADD_LOG_CSTR(&lb, "?"); + } add_log_str(&lb, strbuf, strlen(strbuf)); if (e->key.s.rtype == DNS_RRL_RTYPE_QUERY || @@ -911,8 +953,9 @@ make_log_buf(dns_rrl_t *rrl, dns_rrl_entry_t *e, const char *str1, &qbuf->qname)); } } - if (qbuf != NULL) + if (qbuf != NULL) { qname = dns_fixedname_name(&qbuf->qname); + } if (qname != NULL) { ADD_LOG_CSTR(&lb, " for "); (void)dns_name_totext(qname, true, &lb); @@ -968,18 +1011,21 @@ log_stops(dns_rrl_t *rrl, isc_stdtime_t now, int limit, char *log_buf, int age; for (e = rrl->last_logged; e != NULL; e = ISC_LIST_PREV(e, lru)) { - if (!e->logged) + if (!e->logged) { continue; + } if (now != 0) { age = get_age(rrl, e, now); if (age < DNS_RRL_STOP_LOG_SECS || - response_balance(rrl, e, age) < 0) + response_balance(rrl, e, age) < 0) { break; + } } log_end(rrl, e, now == 0, log_buf, log_buf_len); - if (rrl->num_logged <= 0) + if (rrl->num_logged <= 0) { break; + } /* * Too many messages could stall real work. @@ -1022,8 +1068,9 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp, isc_netaddr_fromsockaddr(&netclient, client_addr); result = dns_acl_match(&netclient, NULL, rrl->exempt, &view->aclenv, &exempt_match, NULL); - if (result == ISC_R_SUCCESS && exempt_match > 0) + if (result == ISC_R_SUCCESS && exempt_match > 0) { return (DNS_RRL_RESULT_OK); + } } LOCK(&rrl->lock); @@ -1043,7 +1090,7 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp, qps = (1.0 * rrl->qps_responses) / secs; if (secs >= rrl->window) { if (isc_log_wouldlog(dns_lctx, - DNS_RRL_LOG_DEBUG3)) + DNS_RRL_LOG_DEBUG3)) { isc_log_write(dns_lctx, DNS_LOGCATEGORY_RRL, DNS_LOGMODULE_REQUEST, @@ -1052,6 +1099,7 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp, " = %d qps", rrl->qps_responses, secs, (int)qps); + } rrl->qps = qps; rrl->qps_responses = 0; rrl->qps_time = now; @@ -1065,8 +1113,9 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp, /* * Do maintenance once per second. */ - if (rrl->num_logged > 0 && rrl->log_stops_time != now) + if (rrl->num_logged > 0 && rrl->log_stops_time != now) { log_stops(rrl, now, 8, log_buf, log_buf_len); + } /* * Notice TCP responses when scaling limits by qps. @@ -1185,8 +1234,9 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp, log_buf, log_buf_len); if (!e->logged) { e->logged = true; - if (++rrl->num_logged <= 1) + if (++rrl->num_logged <= 1) { rrl->last_logged = e; + } } e->log_secs = 0; @@ -1205,20 +1255,22 @@ dns_rrl(dns_view_t *view, const isc_sockaddr_t *client_addr, bool is_tcp, /* * Make a log message for the caller. */ - if (wouldlog) + if (wouldlog) { make_log_buf(rrl, e, rrl->log_only ? "would rate limit " : "rate limit ", NULL, false, qname, false, rrl_result, resp_result, log_buf, log_buf_len); + } if (e != NULL) { /* * Do not save the qname unless we might need it for * the ending log message. */ - if (!e->logged) + if (!e->logged) { free_qname(rrl, e); + } UNLOCK(&rrl->lock); } @@ -1235,25 +1287,29 @@ dns_rrl_view_destroy(dns_view_t *view) int i; rrl = view->rrl; - if (rrl == NULL) + if (rrl == NULL) { return; + } view->rrl = NULL; /* * Assume the caller takes care of locking the view and anything else. */ - if (rrl->num_logged > 0) + if (rrl->num_logged > 0) { log_stops(rrl, 0, INT32_MAX, log_buf, sizeof(log_buf)); + } for (i = 0; i < DNS_RRL_QNAMES; ++i) { - if (rrl->qnames[i] == NULL) + if (rrl->qnames[i] == NULL) { break; + } isc_mem_put(rrl->mctx, rrl->qnames[i], sizeof(*rrl->qnames[i])); } - if (rrl->exempt != NULL) + if (rrl->exempt != NULL) { dns_acl_detach(&rrl->exempt); + } isc_mutex_destroy(&rrl->lock); @@ -1264,14 +1320,16 @@ dns_rrl_view_destroy(dns_view_t *view) } h = rrl->hash; - if (h != NULL) + if (h != NULL) { isc_mem_put(rrl->mctx, h, sizeof(*h) + (h->length - 1) * sizeof(h->bins[0])); + } h = rrl->old_hash; - if (h != NULL) + if (h != NULL) { isc_mem_put(rrl->mctx, h, sizeof(*h) + (h->length - 1) * sizeof(h->bins[0])); + } isc_mem_putanddetach(&rrl->mctx, rrl, sizeof(*rrl)); } diff --git a/lib/dns/sdb.c b/lib/dns/sdb.c index c6c23941a0..4a2df5adf8 100644 --- a/lib/dns/sdb.c +++ b/lib/dns/sdb.c @@ -116,7 +116,7 @@ typedef struct sdb_rdatasetiter { #ifdef __COVERITY__ #define MAYBE_LOCK(sdb) LOCK(&sdb->implementation->driverlock) #define MAYBE_UNLOCK(sdb) UNLOCK(&sdb->implementation->driverlock) -#else +#else /* ifdef __COVERITY__ */ #define MAYBE_LOCK(sdb) \ do { \ unsigned int flags = sdb->implementation->flags; \ @@ -130,7 +130,7 @@ typedef struct sdb_rdatasetiter { if ((flags & DNS_SDBFLAG_THREADSAFE) == 0) \ UNLOCK(&sdb->implementation->driverlock); \ } while (0) -#endif +#endif /* ifdef __COVERITY__ */ static int dummy; @@ -228,8 +228,9 @@ dns_sdb_register(const char *drivername, const dns_sdbmethods_t *methods, imp->dbimp = NULL; result = dns_db_register(drivername, dns_sdb_create, imp, mctx, &imp->dbimp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_mutex; + } *sdbimp = imp; return (ISC_R_SUCCESS); @@ -282,8 +283,9 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval, rdatalist = ISC_LIST_HEAD(lookup->lists); while (rdatalist != NULL) { - if (rdatalist->type == typeval) + if (rdatalist->type == typeval) { break; + } rdatalist = ISC_LIST_NEXT(rdatalist, link); } @@ -294,8 +296,9 @@ dns_sdb_putrdata(dns_sdblookup_t *lookup, dns_rdatatype_t typeval, rdatalist->type = typeval; rdatalist->ttl = ttl; ISC_LIST_APPEND(lookup->lists, rdatalist, link); - } else if (rdatalist->ttl != ttl) + } else if (rdatalist->ttl != ttl) { return (DNS_R_BADTTL); + } rdata = isc_mem_get(mctx, sizeof(dns_rdata_t)); @@ -339,18 +342,21 @@ dns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl, DE_CONST(type, r.base); r.length = strlen(type); result = dns_rdatatype_fromtext(&typeval, &r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } imp = lookup->sdb->implementation; - if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0) + if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0) { origin = &lookup->sdb->common.origin; - else + } else { origin = dns_rootname; + } result = isc_lex_create(mctx, 64, &lex); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } datalen = strlen(data); size = initial_size(datalen); @@ -358,39 +364,46 @@ dns_sdb_putrr(dns_sdblookup_t *lookup, const char *type, dns_ttl_t ttl, isc_buffer_constinit(&b, data, datalen); isc_buffer_add(&b, datalen); result = isc_lex_openbuffer(lex, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } - if (size >= 65535) + if (size >= 65535) { size = 65535; + } p = isc_mem_get(mctx, size); isc_buffer_init(&rb, p, size); result = dns_rdata_fromtext(NULL, lookup->sdb->common.rdclass, typeval, lex, origin, 0, mctx, &rb, &lookup->callbacks); - if (result != ISC_R_NOSPACE) + if (result != ISC_R_NOSPACE) { break; + } /* * Is the RR too big? */ - if (size >= 65535) + if (size >= 65535) { break; + } isc_mem_put(mctx, p, size); p = NULL; size *= 2; } while (result == ISC_R_NOSPACE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_sdb_putrdata(lookup, typeval, ttl, isc_buffer_base(&rb), isc_buffer_usedlength(&rb)); failure: - if (p != NULL) + if (p != NULL) { isc_mem_put(mctx, p, size); - if (lex != NULL) + } + if (lex != NULL) { isc_lex_destroy(&lex); + } return (result); } @@ -410,16 +423,18 @@ getnode(dns_sdballnodes_t *allnodes, const char *name, dns_sdbnode_t **nodep) newname = dns_fixedname_initname(&fnewname); - if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0) + if ((imp->flags & DNS_SDBFLAG_RELATIVERDATA) != 0) { origin = &sdb->common.origin; - else + } else { origin = dns_rootname; + } isc_buffer_constinit(&b, name, strlen(name)); isc_buffer_add(&b, strlen(name)); result = dns_name_fromtext(newname, &b, origin, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (allnodes->common.relative_names) { /* All names are relative to the root */ @@ -431,15 +446,17 @@ getnode(dns_sdballnodes_t *allnodes, const char *name, dns_sdbnode_t **nodep) if (sdbnode == NULL || !dns_name_equal(sdbnode->name, newname)) { sdbnode = NULL; result = createnode(sdb, &sdbnode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } sdbnode->name = isc_mem_get(mctx, sizeof(dns_name_t)); dns_name_init(sdbnode->name, NULL); dns_name_dup(newname, mctx, sdbnode->name); ISC_LIST_PREPEND(allnodes->nodelist, sdbnode, link); if (allnodes->origin == NULL && - dns_name_equal(newname, &sdb->common.origin)) + dns_name_equal(newname, &sdb->common.origin)) { allnodes->origin = sdbnode; + } } *nodep = sdbnode; return (ISC_R_SUCCESS); @@ -452,8 +469,9 @@ dns_sdb_putnamedrr(dns_sdballnodes_t *allnodes, const char *name, isc_result_t result; dns_sdbnode_t *sdbnode = NULL; result = getnode(allnodes, name, &sdbnode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (dns_sdb_putrr(sdbnode, type, ttl, data)); } @@ -465,8 +483,9 @@ dns_sdb_putnamedrdata(dns_sdballnodes_t *allnodes, const char *name, isc_result_t result; dns_sdbnode_t *sdbnode = NULL; result = getnode(allnodes, name, &sdbnode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (dns_sdb_putrdata(sdbnode, type, ttl, rdata, rdlen)); } @@ -483,8 +502,9 @@ dns_sdb_putsoa(dns_sdblookup_t *lookup, const char *mname, const char *rname, n = snprintf(str, sizeof(str), "%s %s %u %u %u %u %u", mname, rname, serial, SDB_DEFAULT_REFRESH, SDB_DEFAULT_RETRY, SDB_DEFAULT_EXPIRE, SDB_DEFAULT_MINIMUM); - if (n >= (int)sizeof(str) || n < 0) + if (n >= (int)sizeof(str) || n < 0) { return (ISC_R_NOSPACE); + } return (dns_sdb_putrr(lookup, "SOA", SDB_DEFAULT_TTL, str)); } @@ -789,28 +809,32 @@ findnodeext(dns_db_t *db, const dns_name_t *name, bool create, dns_name_init(&relname, NULL); dns_name_getlabelsequence(name, 0, labels, &relname); result = dns_name_totext(&relname, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } else { result = dns_name_totext(name, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } isc_buffer_putuint8(&b, 0); } result = createnode(sdb, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } MAYBE_LOCK(sdb); - if (imp->methods->lookup2 != NULL) + if (imp->methods->lookup2 != NULL) { result = imp->methods->lookup2(&sdb->common.origin, name, sdb->dbdata, node, methods, clientinfo); - else + } else { result = imp->methods->lookup(sdb->zone, namestr, sdb->dbdata, node, methods, clientinfo); + } MAYBE_UNLOCK(sdb); if (result != ISC_R_SUCCESS && !(result == ISC_R_NOTFOUND && isorigin && imp->methods->authority != NULL)) { @@ -855,8 +879,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, UNUSED(options); - if (!dns_name_issubdomain(name, &db->origin)) + if (!dns_name_issubdomain(name, &db->origin)) { return (DNS_R_NXDOMAIN); + } olabels = dns_name_countlabels(&db->origin); nlabels = dns_name_countlabels(name); @@ -882,25 +907,29 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, /* * No data at zone apex? */ - if (i == olabels) + if (i == olabels) { return (DNS_R_BADDB); + } result = DNS_R_NXDOMAIN; continue; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * DNS64 zone's don't have DNAME or NS records. */ - if ((flags & DNS_SDBFLAG_DNS64) != 0) + if ((flags & DNS_SDBFLAG_DNS64) != 0) { goto skip; + } /* * DNS64 zone's don't have DNAME or NS records. */ - if ((flags & DNS_SDBFLAG_DNS64) != 0) + if ((flags & DNS_SDBFLAG_DNS64) != 0) { goto skip; + } /* * Look for a DNAME at the current label, unless this is @@ -934,8 +963,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, dns_rdataset_disassociate( sigrdataset); } - } else + } else { result = DNS_R_DELEGATION; + } break; } } @@ -964,8 +994,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, */ result = findrdataset(db, node, version, type, 0, now, rdataset, sigrdataset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } /* * Look for a CNAME @@ -984,17 +1015,19 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, break; } - if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset)) + if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (foundname != NULL) { dns_name_copynf(xname, foundname); } - if (nodep != NULL) + if (nodep != NULL) { *nodep = node; - else if (node != NULL) + } else if (node != NULL) { detachnode(db, &node); + } return (result); } @@ -1082,12 +1115,14 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) isc_result_t result; dns_sdbimplementation_t *imp = sdb->implementation; - if (imp->methods->allnodes == NULL) + if (imp->methods->allnodes == NULL) { return (ISC_R_NOTIMPLEMENTED); + } if ((options & DNS_DB_NSEC3ONLY) != 0 || - (options & DNS_DB_NONSEC3) != 0) + (options & DNS_DB_NONSEC3) != 0) { return (ISC_R_NOTIMPLEMENTED); + } sdbiter = isc_mem_get(sdb->common.mctx, sizeof(sdb_dbiterator_t)); @@ -1135,17 +1170,20 @@ findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, UNUSED(now); UNUSED(sigrdataset); - if (type == dns_rdatatype_rrsig) + if (type == dns_rdatatype_rrsig) { return (ISC_R_NOTIMPLEMENTED); + } list = ISC_LIST_HEAD(sdbnode->lists); while (list != NULL) { - if (list->type == type) + if (list->type == type) { break; + } list = ISC_LIST_NEXT(list, link); } - if (list == NULL) + if (list == NULL) { return (ISC_R_NOTFOUND); + } list_tordataset(list, db, node, rdataset); @@ -1325,8 +1363,9 @@ dns_sdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, imp = driverarg; - if (type != dns_dbtype_zone) + if (type != dns_dbtype_zone) { return (ISC_R_NOTIMPLEMENTED); + } sdb = isc_mem_get(mctx, sizeof(dns_sdb_t)); memset(sdb, 0, sizeof(dns_sdb_t)); @@ -1341,13 +1380,15 @@ dns_sdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, isc_mem_attach(mctx, &sdb->common.mctx); result = dns_name_dupwithoffsets(origin, mctx, &sdb->common.origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_lock; + } isc_buffer_init(&b, zonestr, sizeof(zonestr)); result = dns_name_totext(origin, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_origin; + } isc_buffer_putuint8(&b, 0); sdb->zone = isc_mem_strdup(mctx, zonestr); @@ -1358,8 +1399,9 @@ dns_sdb_create(isc_mem_t *mctx, const dns_name_t *origin, dns_dbtype_t type, result = imp->methods->create(sdb->zone, argc, argv, imp->driverdata, &sdb->dbdata); MAYBE_UNLOCK(sdb); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_zonestr; + } } isc_refcount_init(&sdb->references, 1); @@ -1475,10 +1517,11 @@ dbiterator_first(dns_dbiterator_t *iterator) sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator; sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist); - if (sdbiter->current == NULL) + if (sdbiter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1487,10 +1530,11 @@ dbiterator_last(dns_dbiterator_t *iterator) sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator; sdbiter->current = ISC_LIST_TAIL(sdbiter->nodelist); - if (sdbiter->current == NULL) + if (sdbiter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1500,8 +1544,9 @@ dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name) sdbiter->current = ISC_LIST_HEAD(sdbiter->nodelist); while (sdbiter->current != NULL) { - if (dns_name_equal(sdbiter->current->name, name)) + if (dns_name_equal(sdbiter->current->name, name)) { return (ISC_R_SUCCESS); + } sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link); } return (ISC_R_NOTFOUND); @@ -1513,10 +1558,11 @@ dbiterator_prev(dns_dbiterator_t *iterator) sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator; sdbiter->current = ISC_LIST_PREV(sdbiter->current, link); - if (sdbiter->current == NULL) + if (sdbiter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1525,10 +1571,11 @@ dbiterator_next(dns_dbiterator_t *iterator) sdb_dbiterator_t *sdbiter = (sdb_dbiterator_t *)iterator; sdbiter->current = ISC_LIST_NEXT(sdbiter->current, link); - if (sdbiter->current == NULL) + if (sdbiter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1580,8 +1627,9 @@ rdatasetiter_first(dns_rdatasetiter_t *iterator) sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator; dns_sdbnode_t * sdbnode = (dns_sdbnode_t *)iterator->node; - if (ISC_LIST_EMPTY(sdbnode->lists)) + if (ISC_LIST_EMPTY(sdbnode->lists)) { return (ISC_R_NOMORE); + } sdbiterator->current = ISC_LIST_HEAD(sdbnode->lists); return (ISC_R_SUCCESS); } @@ -1592,10 +1640,11 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator) sdb_rdatasetiter_t *sdbiterator = (sdb_rdatasetiter_t *)iterator; sdbiterator->current = ISC_LIST_NEXT(sdbiterator->current, link); - if (sdbiterator->current == NULL) + if (sdbiterator->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static void diff --git a/lib/dns/sdlz.c b/lib/dns/sdlz.c index 0155a4b989..8916d8b129 100644 --- a/lib/dns/sdlz.c +++ b/lib/dns/sdlz.c @@ -163,7 +163,7 @@ typedef struct sdlz_rdatasetiter { #ifdef __COVERITY__ #define MAYBE_LOCK(imp) LOCK(&imp->driverlock) #define MAYBE_UNLOCK(imp) UNLOCK(&imp->driverlock) -#else +#else /* ifdef __COVERITY__ */ #define MAYBE_LOCK(imp) \ do { \ unsigned int flags = imp->flags; \ @@ -177,7 +177,7 @@ typedef struct sdlz_rdatasetiter { if ((flags & DNS_SDLZFLAG_THREADSAFE) == 0) \ UNLOCK(&imp->driverlock); \ } while (0) -#endif +#endif /* ifdef __COVERITY__ */ /* * Forward references. @@ -245,8 +245,9 @@ dns_sdlz_tolower(char *str) unsigned int i; for (i = 0; i < len; i++) { - if (str[i] >= 'A' && str[i] <= 'Z') + if (str[i] >= 'A' && str[i] <= 'Z') { str[i] += 32; + } } } @@ -279,8 +280,9 @@ rdatasetiter_first(dns_rdatasetiter_t *iterator) sdlz_rdatasetiter_t *sdlziterator = (sdlz_rdatasetiter_t *)iterator; dns_sdlznode_t * sdlznode = (dns_sdlznode_t *)iterator->node; - if (ISC_LIST_EMPTY(sdlznode->lists)) + if (ISC_LIST_EMPTY(sdlznode->lists)) { return (ISC_R_NOMORE); + } sdlziterator->current = ISC_LIST_HEAD(sdlznode->lists); return (ISC_R_SUCCESS); } @@ -291,10 +293,11 @@ rdatasetiter_next(dns_rdatasetiter_t *iterator) sdlz_rdatasetiter_t *sdlziterator = (sdlz_rdatasetiter_t *)iterator; sdlziterator->current = ISC_LIST_NEXT(sdlziterator->current, link); - if (sdlziterator->current == NULL) + if (sdlziterator->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static void @@ -401,8 +404,9 @@ newversion(dns_db_t *db, dns_dbversion_t **versionp) REQUIRE(VALID_SDLZDB(sdlz)); - if (sdlz->dlzimp->methods->newversion == NULL) + if (sdlz->dlzimp->methods->newversion == NULL) { return (ISC_R_NOTIMPLEMENTED); + } dns_name_format(&sdlz->common.origin, origin, sizeof(origin)); @@ -452,9 +456,10 @@ closeversion(dns_db_t *db, dns_dbversion_t **versionp, bool commit) sdlz->dlzimp->methods->closeversion(origin, commit, sdlz->dlzimp->driverarg, sdlz->dbdata, versionp); - if (*versionp != NULL) + if (*versionp != NULL) { sdlz_log(ISC_LOG_ERROR, "sdlz closeversion on origin %s failed", origin); + } sdlz->future_version = NULL; } @@ -556,24 +561,28 @@ getnodedata(dns_db_t *db, const dns_name_t *name, bool create, dns_name_init(&relname, NULL); dns_name_getlabelsequence(name, 0, labels, &relname); result = dns_name_totext(&relname, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } else { result = dns_name_totext(name, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } isc_buffer_putuint8(&b, 0); isc_buffer_init(&b2, zonestr, sizeof(zonestr)); result = dns_name_totext(&sdlz->common.origin, true, &b2); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_putuint8(&b2, 0); result = createnode(sdlz, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isorigin = dns_name_equal(name, &sdlz->common.origin); @@ -635,15 +644,17 @@ getnodedata(dns_db_t *db, const dns_name_t *name, bool create, result = sdlz->dlzimp->methods->lookup( zonestr, wildstr, sdlz->dlzimp->driverarg, sdlz->dbdata, node, methods, clientinfo); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } } } MAYBE_UNLOCK(sdlz->dlzimp); - if (result == ISC_R_NOTFOUND && (isorigin || create)) + if (result == ISC_R_NOTFOUND && (isorigin || create)) { result = ISC_R_SUCCESS; + } if (result != ISC_R_SUCCESS) { isc_refcount_decrement(&node->references); @@ -772,17 +783,20 @@ createiterator(dns_db_t *db, unsigned int options, dns_dbiterator_t **iteratorp) REQUIRE(VALID_SDLZDB(sdlz)); - if (sdlz->dlzimp->methods->allnodes == NULL) + if (sdlz->dlzimp->methods->allnodes == NULL) { return (ISC_R_NOTIMPLEMENTED); + } if ((options & DNS_DB_NSEC3ONLY) != 0 || - (options & DNS_DB_NONSEC3) != 0) + (options & DNS_DB_NONSEC3) != 0) { return (ISC_R_NOTIMPLEMENTED); + } isc_buffer_init(&b, zonestr, sizeof(zonestr)); result = dns_name_totext(&sdlz->common.origin, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_putuint8(&b, 0); sdlziter = isc_mem_get(sdlz->common.mctx, sizeof(sdlz_dbiterator_t)); @@ -835,17 +849,20 @@ findrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, UNUSED(now); UNUSED(sigrdataset); - if (type == dns_rdatatype_sig || type == dns_rdatatype_rrsig) + if (type == dns_rdatatype_sig || type == dns_rdatatype_rrsig) { return (ISC_R_NOTIMPLEMENTED); + } list = ISC_LIST_HEAD(sdlznode->lists); while (list != NULL) { - if (list->type == type) + if (list->type == type) { break; + } list = ISC_LIST_NEXT(list, link); } - if (list == NULL) + if (list == NULL) { return (ISC_R_NOTFOUND); + } list_tordataset(list, db, node, rdataset); @@ -875,8 +892,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, UNUSED(sdlz); - if (!dns_name_issubdomain(name, &db->origin)) + if (!dns_name_issubdomain(name, &db->origin)) { return (DNS_R_NXDOMAIN); + } olabels = dns_name_countlabels(&db->origin); nlabels = dns_name_countlabels(name); @@ -910,8 +928,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, if (result == ISC_R_NOTFOUND) { result = DNS_R_NXDOMAIN; continue; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { break; + } /* * Look for a DNAME at the current label, unless this is @@ -942,8 +961,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, result = DNS_R_ZONECUT; dns_rdataset_disassociate(rdataset); if (sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } break; } else if (result == ISC_R_SUCCESS) { result = DNS_R_DELEGATION; @@ -974,8 +994,9 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, */ result = findrdataset(db, node, version, type, 0, now, rdataset, sigrdataset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } /* * Look for a CNAME @@ -994,17 +1015,19 @@ findext(dns_db_t *db, const dns_name_t *name, dns_dbversion_t *version, break; } - if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset)) + if (rdataset == &xrdataset && dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (foundname != NULL) { dns_name_copynf(xname, foundname); } - if (nodep != NULL) + if (nodep != NULL) { *nodep = node; - else if (node != NULL) + } else if (node != NULL) { detachnode(db, &node); + } return (result); } @@ -1065,8 +1088,9 @@ modrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, REQUIRE(VALID_SDLZDB(sdlz)); - if (mod_function == NULL) + if (mod_function == NULL) { return (ISC_R_NOTIMPLEMENTED); + } sdlznode = (dns_sdlznode_t *)node; @@ -1080,13 +1104,15 @@ modrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, result = dns_master_stylecreate(&style, 0, 0, 0, 0, 0, 0, 1, 0xffffffff, mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_master_rdatasettotext(sdlznode->name, rdataset, style, NULL, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } if (isc_buffer_usedlength(buffer) < 1) { result = ISC_R_BADADDRESSFORM; @@ -1107,8 +1133,9 @@ modrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, cleanup: isc_buffer_free(&buffer); - if (style != NULL) + if (style != NULL) { dns_master_styledestroy(&style, mctx); + } return (result); } @@ -1125,8 +1152,9 @@ addrdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, UNUSED(addedrdataset); REQUIRE(VALID_SDLZDB(sdlz)); - if (sdlz->dlzimp->methods->addrdataset == NULL) + if (sdlz->dlzimp->methods->addrdataset == NULL) { return (ISC_R_NOTIMPLEMENTED); + } result = modrdataset(db, node, version, rdataset, options, sdlz->dlzimp->methods->addrdataset); @@ -1167,8 +1195,9 @@ deleterdataset(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, REQUIRE(VALID_SDLZDB(sdlz)); - if (sdlz->dlzimp->methods->delrdataset == NULL) + if (sdlz->dlzimp->methods->delrdataset == NULL) { return (ISC_R_NOTIMPLEMENTED); + } sdlznode = (dns_sdlznode_t *)node; dns_name_format(sdlznode->name, name, sizeof(name)); @@ -1230,14 +1259,16 @@ getoriginnode(dns_db_t *db, dns_dbnode_t **nodep) isc_result_t result; REQUIRE(VALID_SDLZDB(sdlz)); - if (sdlz->dlzimp->methods->newversion == NULL) + if (sdlz->dlzimp->methods->newversion == NULL) { return (ISC_R_NOTIMPLEMENTED); + } result = getnodedata(db, &sdlz->common.origin, false, 0, NULL, NULL, nodep); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { sdlz_log(ISC_LOG_ERROR, "sdlz getoriginnode failed: %s", isc_result_totext(result)); + } return (result); } @@ -1323,10 +1354,11 @@ dbiterator_first(dns_dbiterator_t *iterator) sdlz_dbiterator_t *sdlziter = (sdlz_dbiterator_t *)iterator; sdlziter->current = ISC_LIST_HEAD(sdlziter->nodelist); - if (sdlziter->current == NULL) + if (sdlziter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1335,10 +1367,11 @@ dbiterator_last(dns_dbiterator_t *iterator) sdlz_dbiterator_t *sdlziter = (sdlz_dbiterator_t *)iterator; sdlziter->current = ISC_LIST_TAIL(sdlziter->nodelist); - if (sdlziter->current == NULL) + if (sdlziter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1348,8 +1381,9 @@ dbiterator_seek(dns_dbiterator_t *iterator, const dns_name_t *name) sdlziter->current = ISC_LIST_HEAD(sdlziter->nodelist); while (sdlziter->current != NULL) { - if (dns_name_equal(sdlziter->current->name, name)) + if (dns_name_equal(sdlziter->current->name, name)) { return (ISC_R_SUCCESS); + } sdlziter->current = ISC_LIST_NEXT(sdlziter->current, link); } return (ISC_R_NOTFOUND); @@ -1361,10 +1395,11 @@ dbiterator_prev(dns_dbiterator_t *iterator) sdlz_dbiterator_t *sdlziter = (sdlz_dbiterator_t *)iterator; sdlziter->current = ISC_LIST_PREV(sdlziter->current, link); - if (sdlziter->current == NULL) + if (sdlziter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1373,10 +1408,11 @@ dbiterator_next(dns_dbiterator_t *iterator) sdlz_dbiterator_t *sdlziter = (sdlz_dbiterator_t *)iterator; sdlziter->current = ISC_LIST_NEXT(sdlziter->current, link); - if (sdlziter->current == NULL) + if (sdlziter->current == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } static isc_result_t @@ -1508,8 +1544,9 @@ dns_sdlzcreateDBP(isc_mem_t *mctx, void *driverarg, void *dbdata, /* initialize and set origin */ dns_name_init(&sdlzdb->common.origin, NULL); result = dns_name_dupwithoffsets(name, mctx, &sdlzdb->common.origin); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto mem_cleanup; + } /* set the rest of the database structure attributes */ sdlzdb->dlzimp = imp; @@ -1562,16 +1599,18 @@ dns_sdlzallowzonexfr(void *driverarg, void *dbdata, isc_mem_t *mctx, /* Convert DNS name to ascii text */ isc_buffer_init(&b, namestr, sizeof(namestr)); result = dns_name_totext(name, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_putuint8(&b, 0); /* convert client address to ascii text */ isc_buffer_init(&b2, clientstr, sizeof(clientstr)); isc_netaddr_fromsockaddr(&netaddr, clientaddr); result = isc_netaddr_totext(&netaddr, &b2); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_putuint8(&b2, 0); /* make sure strings are always lowercase */ @@ -1682,8 +1721,9 @@ dns_sdlzfindzone(void *driverarg, void *dbdata, isc_mem_t *mctx, /* Convert DNS name to ascii text */ isc_buffer_init(&b, namestr, sizeof(namestr)); result = dns_name_totext(name, true, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_buffer_putuint8(&b, 0); /* make sure strings are always lowercase */ @@ -1699,9 +1739,10 @@ dns_sdlzfindzone(void *driverarg, void *dbdata, isc_mem_t *mctx, * if zone is supported build a 'bind' database driver * structure to return */ - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_sdlzcreateDBP(mctx, driverarg, dbdata, name, rdclass, dbp); + } return (result); } @@ -1749,32 +1790,36 @@ dns_sdlzssumatch(const dns_name_t *signer, const dns_name_t *name, REQUIRE(driverarg != NULL); imp = (dns_sdlzimplementation_t *)driverarg; - if (imp->methods->ssumatch == NULL) + if (imp->methods->ssumatch == NULL) { return (false); + } /* * Format the request elements. sdlz operates on strings, not * structures */ - if (signer != NULL) + if (signer != NULL) { dns_name_format(signer, b_signer, sizeof(b_signer)); - else + } else { b_signer[0] = 0; + } dns_name_format(name, b_name, sizeof(b_name)); - if (tcpaddr != NULL) + if (tcpaddr != NULL) { isc_netaddr_format(tcpaddr, b_addr, sizeof(b_addr)); - else + } else { b_addr[0] = 0; + } dns_rdatatype_format(type, b_type, sizeof(b_type)); if (key != NULL) { dst_key_format(key, b_key, sizeof(b_key)); tkey_token = dst_key_tkeytoken(key); - } else + } else { b_key[0] = 0; + } if (tkey_token != NULL) { isc_buffer_region(tkey_token, &token_region); @@ -1823,13 +1868,15 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, r.base = type; r.length = strlen(type); result = dns_rdatatype_fromtext(&typeval, (void *)&r); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } rdatalist = ISC_LIST_HEAD(lookup->lists); while (rdatalist != NULL) { - if (rdatalist->type == typeval) + if (rdatalist->type == typeval) { break; + } rdatalist = ISC_LIST_NEXT(rdatalist, link); } @@ -1854,15 +1901,17 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, rdata = isc_mem_get(mctx, sizeof(dns_rdata_t)); dns_rdata_init(rdata); - if ((lookup->sdlz->dlzimp->flags & DNS_SDLZFLAG_RELATIVERDATA) != 0) + if ((lookup->sdlz->dlzimp->flags & DNS_SDLZFLAG_RELATIVERDATA) != 0) { origin = &lookup->sdlz->common.origin; - else + } else { origin = dns_rootname; + } lex = NULL; result = isc_lex_create(mctx, 64, &lex); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } size = initial_size(data); do { @@ -1870,8 +1919,9 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, isc_buffer_add(&b, strlen(data)); result = isc_lex_openbuffer(lex, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } rdatabuf = NULL; isc_buffer_allocate(mctx, &rdatabuf, size); @@ -1883,29 +1933,35 @@ dns_sdlz_putrr(dns_sdlzlookup_t *lookup, const char *type, dns_ttl_t ttl, isc_buffer_free(&rdatabuf); result = DNS_R_SERVFAIL; } - if (size >= 65535) + if (size >= 65535) { break; + } size *= 2; - if (size >= 65535) + if (size >= 65535) { size = 65535; + } } while (result == ISC_R_NOSPACE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } ISC_LIST_APPEND(rdatalist->rdata, rdata, link); ISC_LIST_APPEND(lookup->buffers, rdatabuf, link); - if (lex != NULL) + if (lex != NULL) { isc_lex_destroy(&lex); + } return (ISC_R_SUCCESS); failure: - if (rdatabuf != NULL) + if (rdatabuf != NULL) { isc_buffer_free(&rdatabuf); - if (lex != NULL) + } + if (lex != NULL) { isc_lex_destroy(&lex); + } isc_mem_put(mctx, rdata, sizeof(dns_rdata_t)); return (result); @@ -1926,16 +1982,18 @@ dns_sdlz_putnamedrr(dns_sdlzallnodes_t *allnodes, const char *name, newname = dns_fixedname_initname(&fnewname); - if ((sdlz->dlzimp->flags & DNS_SDLZFLAG_RELATIVERDATA) != 0) + if ((sdlz->dlzimp->flags & DNS_SDLZFLAG_RELATIVERDATA) != 0) { origin = &sdlz->common.origin; - else + } else { origin = dns_rootname; + } isc_buffer_constinit(&b, name, strlen(name)); isc_buffer_add(&b, strlen(name)); result = dns_name_fromtext(newname, &b, origin, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (allnodes->common.relative_names) { /* All names are relative to the root */ @@ -1947,15 +2005,17 @@ dns_sdlz_putnamedrr(dns_sdlzallnodes_t *allnodes, const char *name, if (sdlznode == NULL || !dns_name_equal(sdlznode->name, newname)) { sdlznode = NULL; result = createnode(sdlz, &sdlznode); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } sdlznode->name = isc_mem_get(mctx, sizeof(dns_name_t)); dns_name_init(sdlznode->name, NULL); dns_name_dup(newname, mctx, sdlznode->name); ISC_LIST_PREPEND(allnodes->nodelist, sdlznode, link); if (allnodes->origin == NULL && - dns_name_equal(newname, &sdlz->common.origin)) + dns_name_equal(newname, &sdlz->common.origin)) { allnodes->origin = sdlznode; + } } return (dns_sdlz_putrr(sdlznode, type, ttl, data)); } @@ -1973,8 +2033,9 @@ dns_sdlz_putsoa(dns_sdlzlookup_t *lookup, const char *mname, const char *rname, n = snprintf(str, sizeof str, "%s %s %u %u %u %u %u", mname, rname, serial, SDLZ_DEFAULT_REFRESH, SDLZ_DEFAULT_RETRY, SDLZ_DEFAULT_EXPIRE, SDLZ_DEFAULT_MINIMUM); - if (n >= (int)sizeof(str) || n < 0) + if (n >= (int)sizeof(str) || n < 0) { return (ISC_R_NOSPACE); + } return (dns_sdlz_putrr(lookup, "SOA", SDLZ_DEFAULT_TTL, str)); } @@ -2038,8 +2099,9 @@ dns_sdlzregister(const char *drivername, const dns_sdlzmethods_t *methods, &imp->dlz_imp); /* if registration fails, cleanup and get outta here. */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_mutex; + } *sdlzimp = imp; diff --git a/lib/dns/soa.c b/lib/dns/soa.c index 4910c4b6a3..26b9944523 100644 --- a/lib/dns/soa.c +++ b/lib/dns/soa.c @@ -90,27 +90,27 @@ dns_soa_buildrdata(const dns_name_t *origin, const dns_name_t *contact, uint32_t dns_soa_getserial(dns_rdata_t *rdata) { - return soa_get(rdata, 0); + return (soa_get(rdata, 0)); } uint32_t dns_soa_getrefresh(dns_rdata_t *rdata) { - return soa_get(rdata, 4); + return (soa_get(rdata, 4)); } uint32_t dns_soa_getretry(dns_rdata_t *rdata) { - return soa_get(rdata, 8); + return (soa_get(rdata, 8)); } uint32_t dns_soa_getexpire(dns_rdata_t *rdata) { - return soa_get(rdata, 12); + return (soa_get(rdata, 12)); } uint32_t dns_soa_getminimum(dns_rdata_t *rdata) { - return soa_get(rdata, 16); + return (soa_get(rdata, 16)); } static void diff --git a/lib/dns/spnego.c b/lib/dns/spnego.c index 67cfa75665..da81ecd516 100644 --- a/lib/dns/spnego.c +++ b/lib/dns/spnego.c @@ -181,7 +181,7 @@ typedef enum asn1_error_number { } asn1_error_number; #define ERROR_TABLE_BASE_asn1 1859794432 -#endif +#endif /* ifndef ERROR_TABLE_BASE_asn1 */ #define __asn1_common_definitions__ @@ -358,23 +358,28 @@ cmp_gss_type(gss_buffer_t token, gss_OID gssoid) unsigned char *p; size_t len; - if (token->length == 0U) + if (token->length == 0U) { return (GSS_S_DEFECTIVE_TOKEN); + } p = token->value; - if (*p++ != 0x60) + if (*p++ != 0x60) { return (GSS_S_DEFECTIVE_TOKEN); + } len = *p++; if (len & 0x80) { - if ((len & 0x7f) > 4U) + if ((len & 0x7f) > 4U) { return (GSS_S_DEFECTIVE_TOKEN); + } p += len & 0x7f; } - if (*p++ != 0x06) + if (*p++ != 0x06) { return (GSS_S_DEFECTIVE_TOKEN); + } - if (((OM_uint32)*p++) != gssoid->length) + if (((OM_uint32)*p++) != gssoid->length) { return (GSS_S_DEFECTIVE_TOKEN); + } return (!isc_safe_memequal(p, gssoid->elements, gssoid->length)); } @@ -409,8 +414,9 @@ code_NegTokenArg(OM_uint32 *minor_status, const NegTokenResp *resp, buf + buf_size - buf_len - 1, buf_size - buf_len, buf_len, ASN1_C_CONTEXT, CONS, 1, &tmp); - if (ret == 0) + if (ret == 0) { buf_len += tmp; + } } if (ret) { if (ret == ASN1_OVERFLOW) { @@ -467,8 +473,9 @@ send_reject(OM_uint32 *minor_status, gss_buffer_t output_token) (unsigned char **)&output_token->value, &output_token->length); free_NegTokenResp(&resp); - if (ret) + if (ret) { return (ret); + } return (GSS_S_BAD_MECH); } @@ -520,8 +527,9 @@ send_accept(OM_uint32 *minor_status, gss_buffer_t output_token, resp.responseToken = NULL; } free_NegTokenResp(&resp); - if (ret) + if (ret) { return (ret); + } return (GSS_S_COMPLETE); } @@ -555,12 +563,13 @@ gss_accept_sec_context_spnego(OM_uint32 * minor_status, * PDU. If not, dispatch to the GSSAPI library and get out. */ - if (cmp_gss_type(input_token_buffer, GSS_SPNEGO_MECH)) + if (cmp_gss_type(input_token_buffer, GSS_SPNEGO_MECH)) { return (gss_accept_sec_context( minor_status, context_handle, acceptor_cred_handle, input_token_buffer, input_chan_bindings, src_name, mech_type, output_token, ret_flags, time_rec, delegated_cred_handle)); + } /* * If we get here, it's SPNEGO. @@ -570,13 +579,15 @@ gss_accept_sec_context_spnego(OM_uint32 * minor_status, ret = gssapi_spnego_decapsulate(minor_status, input_token_buffer, &buf, &buf_size, GSS_SPNEGO_MECH); - if (ret) + if (ret) { return (ret); + } ret = der_match_tag_and_length(buf, buf_size, ASN1_C_CONTEXT, CONS, 0, &len, &taglen); - if (ret) + if (ret) { return (ret); + } ret = decode_NegTokenInit(buf + taglen, len, &init_token, &ni_len); if (ret) { @@ -607,8 +618,9 @@ gss_accept_sec_context_spnego(OM_uint32 * minor_status, mechbuf + sizeof(mechbuf) - mech_len, mech_len)) { found = 1; - if (i == 0) + if (i == 0) { pref = GSS_MSKRB5_MECH; + } break; } } @@ -635,8 +647,9 @@ gss_accept_sec_context_spnego(OM_uint32 * minor_status, } ret = send_accept(&minor_status2, output_token, ot, pref); free_NegTokenInit(&init_token); - if (ot != NULL && ot->length != 0U) + if (ot != NULL && ot->length != 0U) { gss_release_buffer(&minor_status2, ot); + } return (ret != GSS_S_COMPLETE ? (OM_uint32)ret : major_status); } @@ -650,24 +663,31 @@ gssapi_verify_mech_header(u_char **str, size_t total_len, const gss_OID mech) int e; u_char *p = *str; - if (total_len < 1U) + if (total_len < 1U) { return (GSS_S_DEFECTIVE_TOKEN); - if (*p++ != 0x60) + } + if (*p++ != 0x60) { return (GSS_S_DEFECTIVE_TOKEN); + } e = der_get_length(p, total_len - 1, &len, &len_len); - if (e || 1 + len_len + len != total_len) + if (e || 1 + len_len + len != total_len) { return (GSS_S_DEFECTIVE_TOKEN); + } p += len_len; - if (*p++ != 0x06) + if (*p++ != 0x06) { return (GSS_S_DEFECTIVE_TOKEN); + } e = der_get_length(p, total_len - 1 - len_len - 1, &mech_len, &foo); - if (e) + if (e) { return (GSS_S_DEFECTIVE_TOKEN); + } p += foo; - if (mech_len != mech->length) + if (mech_len != mech->length) { return (GSS_S_BAD_MECH); - if (!isc_safe_memequal(p, mech->elements, mech->length)) + } + if (!isc_safe_memequal(p, mech->elements, mech->length)) { return (GSS_S_BAD_MECH); + } p += mech_len; *str = p; return (GSS_S_COMPLETE); @@ -730,11 +750,13 @@ der_get_unsigned(const unsigned char *p, size_t len, unsigned *ret, unsigned val = 0; size_t oldlen = len; - while (len--) + while (len--) { val = val * 256 + *p++; + } *ret = val; - if (size) + if (size) { *size = oldlen; + } return (0); } @@ -746,12 +768,14 @@ der_get_int(const unsigned char *p, size_t len, int *ret, size_t *size) if (len > 0U) { val = (signed char)*p++; - while (--len) + while (--len) { val = val * 256 + *p++; + } } *ret = val; - if (size) + if (size) { *size = oldlen; + } return (0); } @@ -760,14 +784,16 @@ der_get_length(const unsigned char *p, size_t len, size_t *val, size_t *size) { size_t v; - if (len <= 0U) + if (len <= 0U) { return (ASN1_OVERRUN); + } --len; v = *p++; if (v < 128U) { *val = v; - if (size) + if (size) { *size = 1; + } } else { int e; size_t l; @@ -775,19 +801,23 @@ der_get_length(const unsigned char *p, size_t len, size_t *val, size_t *size) if (v == 0x80U) { *val = ASN1_INDEFINITE; - if (size) + if (size) { *size = 1; + } return (0); } v &= 0x7F; - if (len < v) + if (len < v) { return (ASN1_OVERRUN); + } e = der_get_unsigned(p, v, &tmp, &l); - if (e) + if (e) { return (e); + } *val = tmp; - if (size) + if (size) { *size = l + 1; + } } return (0); } @@ -799,13 +829,16 @@ der_get_octet_string(const unsigned char *p, size_t len, octet_string *data, data->length = len; if (len != 0U) { data->data = malloc(len); - if (data->data == NULL) + if (data->data == NULL) { return (ENOMEM); + } memmove(data->data, p, len); - } else + } else { data->data = NULL; - if (size) + } + if (size) { *size = len; + } return (0); } @@ -853,13 +886,15 @@ static int der_get_tag(const unsigned char *p, size_t len, Der_class *xclass, Der_type *type, int *tag, size_t *size) { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERRUN); + } *xclass = (Der_class)(((*p) >> 6) & 0x03); *type = (Der_type)(((*p) >> 5) & 0x01); *tag = (*p) & 0x1F; - if (size) + if (size) { *size = 1; + } return (0); } @@ -874,16 +909,21 @@ der_match_tag(const unsigned char *p, size_t len, Der_class xclass, int e; e = der_get_tag(p, len, &thisclass, &thistype, &thistag, &l); - if (e) + if (e) { return (e); - if (xclass != thisclass || type != thistype) + } + if (xclass != thisclass || type != thistype) { return (ASN1_BAD_ID); - if (tag > thistag) + } + if (tag > thistag) { return (ASN1_MISPLACED_FIELD); - if (tag < thistag) + } + if (tag < thistag) { return (ASN1_MISSING_FIELD); - if (size) + } + if (size) { *size = l; + } return (0); } @@ -896,20 +936,23 @@ der_match_tag_and_length(const unsigned char *p, size_t len, Der_class xclass, int e; e = der_match_tag(p, len, xclass, type, tag, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; e = der_get_length(p, len, length_ret, &l); - if (e) + if (e) { return (e); + } /* p += l; */ len -= l; POST(len); ret += l; - if (size) + if (size) { *size = ret; + } return (0); } @@ -921,27 +964,31 @@ decode_enumerated(const unsigned char *p, size_t len, void *num, size_t *size) int e; e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_Enumerated, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; e = der_get_length(p, len, &reallen, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; e = der_get_int(p, reallen, num, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; POST(p); POST(len); ret += l; - if (size) + if (size) { *size = ret; + } return (0); } @@ -958,31 +1005,36 @@ decode_octet_string(const unsigned char *p, size_t len, octet_string *k, k->length = 0; e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_OctetString, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; e = der_get_length(p, len, &slen, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; - if (len < slen) + if (len < slen) { return (ASN1_OVERRUN); + } e = der_get_octet_string(p, slen, k, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; POST(p); POST(len); ret += l; - if (size) + if (size) { *size = ret; + } return (0); } @@ -995,41 +1047,48 @@ decode_oid(const unsigned char *p, size_t len, oid *k, size_t *size) size_t slen; e = der_match_tag(p, len, ASN1_C_UNIV, PRIM, UT_OID, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; e = der_get_length(p, len, &slen, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; ret += l; - if (len < slen) + if (len < slen) { return (ASN1_OVERRUN); + } e = der_get_oid(p, slen, k, &l); - if (e) + if (e) { return (e); + } p += l; len -= l; POST(p); POST(len); ret += l; - if (size) + if (size) { *size = ret; + } return (0); } static int fix_dce(size_t reallen, size_t *len) { - if (reallen == ASN1_INDEFINITE) + if (reallen == ASN1_INDEFINITE) { return (1); - if (*len < reallen) + } + if (*len < reallen) { return (-1); + } *len = reallen; return (0); } @@ -1051,10 +1110,11 @@ len_unsigned(unsigned val) static size_t length_len(size_t len) { - if (len < 128U) + if (len < 128U) { return (1); - else + } else { return (len_unsigned((unsigned int)len) + 1); + } } /* der_put.c */ @@ -1077,15 +1137,15 @@ der_put_unsigned(unsigned char *p, size_t len, unsigned val, size_t *size) val /= 256; --len; } - if (val != 0) + if (val != 0) { return (ASN1_OVERFLOW); - else { + } else { *size = base - p; return (0); } - } else if (len < 1U) + } else if (len < 1U) { return (ASN1_OVERFLOW); - else { + } else { *p = 0; *size = 1; return (0); @@ -1099,15 +1159,17 @@ der_put_int(unsigned char *p, size_t len, int val, size_t *size) if (val >= 0) { do { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = val % 256; len--; val /= 256; } while (val); if (p[1] >= 128) { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = 0; len--; POST(len); @@ -1115,15 +1177,17 @@ der_put_int(unsigned char *p, size_t len, int val, size_t *size) } else { val = ~val; do { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = ~(val % 256); len--; val /= 256; } while (val); if (p[1] < 128) { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = 0xff; len--; POST(len); @@ -1136,8 +1200,9 @@ der_put_int(unsigned char *p, size_t len, int val, size_t *size) static int der_put_length(unsigned char *p, size_t len, size_t val, size_t *size) { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } if (val < 128U) { *p = (unsigned char)val; *size = 1; @@ -1147,8 +1212,9 @@ der_put_length(unsigned char *p, size_t len, size_t val, size_t *size) int e; e = der_put_unsigned(p, len - 1, (unsigned int)val, &l); - if (e) + if (e) { return (e); + } p -= l; *p = 0x80 | (unsigned char)l; *size = l + 1; @@ -1160,8 +1226,9 @@ static int der_put_octet_string(unsigned char *p, size_t len, const octet_string *data, size_t *size) { - if (len < data->length) + if (len < data->length) { return (ASN1_OVERFLOW); + } p -= data->length; len -= data->length; POST(len); @@ -1179,21 +1246,24 @@ der_put_oid(unsigned char *p, size_t len, const oid *data, size_t *size) for (n = data->length; n >= 3u; --n) { unsigned u = data->components[n - 1]; - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = u % 128; u /= 128; --len; while (u > 0) { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = 128 + u % 128; u /= 128; --len; } } - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p-- = 40 * data->components[0] + data->components[1]; *size = base - p; return (0); @@ -1203,8 +1273,9 @@ static int der_put_tag(unsigned char *p, size_t len, Der_class xclass, Der_type type, int tag, size_t *size) { - if (len < 1U) + if (len < 1U) { return (ASN1_OVERFLOW); + } *p = (xclass << 6) | (type << 5) | tag; /* XXX */ *size = 1; return (0); @@ -1219,14 +1290,16 @@ der_put_length_and_tag(unsigned char *p, size_t len, size_t len_val, int e; e = der_put_length(p, len, len_val, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; ret += l; e = der_put_tag(p, len, xclass, type, tag, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; POST(p); @@ -1245,15 +1318,17 @@ encode_enumerated(unsigned char *p, size_t len, const void *data, size_t *size) int e; e = der_put_int(p, len, num, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; ret += l; e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_Enumerated, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; POST(p); @@ -1272,15 +1347,17 @@ encode_octet_string(unsigned char *p, size_t len, const octet_string *k, int e; e = der_put_octet_string(p, len, k, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; ret += l; e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_OctetString, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; POST(p); @@ -1298,14 +1375,16 @@ encode_oid(unsigned char *p, size_t len, const oid *k, size_t *size) int e; e = der_put_oid(p, len, k, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; ret += l; e = der_put_length_and_tag(p, len, l, ASN1_C_UNIV, PRIM, UT_OID, &l); - if (e) + if (e) { return (e); + } p -= l; len -= l; POST(p); @@ -1339,8 +1418,9 @@ gssapi_mech_make_header(u_char *p, size_t len, const gss_OID mech) *p++ = 0x60; len_len = length_len(len); e = der_put_length(p + len_len - 1, len_len, len, &foo); - if (e || foo != len_len) + if (e || foo != len_len) { return (NULL); + } p += len_len; *p++ = 0x06; *p++ = mech->length; @@ -1371,8 +1451,9 @@ gssapi_spnego_encapsulate(OM_uint32 *minor_status, unsigned char *buf, } p = gssapi_mech_make_header(output_token->value, len, mech); if (p == NULL) { - if (output_token->length != 0U) + if (output_token->length != 0U) { gss_release_buffer(minor_status, output_token); + } return (GSS_S_FAILURE); } memmove(p, buf, buf_size); @@ -1392,14 +1473,16 @@ add_mech(MechTypeList *mech_list, gss_OID mech) int ret; tmp = realloc(mech_list->val, (mech_list->len + 1) * sizeof(*tmp)); - if (tmp == NULL) + if (tmp == NULL) { return (ENOMEM); + } mech_list->val = tmp; ret = der_get_oid(mech->elements, mech->length, &mech_list->val[mech_list->len], NULL); - if (ret) + if (ret) { return (ret); + } mech_list->len++; return (0); @@ -1418,19 +1501,24 @@ gssapi_krb5_get_mech(const u_char *ptr, size_t total_len, const u_char *p = ptr; int e; - if (total_len < 1U) + if (total_len < 1U) { return (-1); - if (*p++ != 0x60) + } + if (*p++ != 0x60) { return (-1); + } e = der_get_length(p, total_len - 1, &len, &len_len); - if (e || 1 + len_len + len != total_len) + if (e || 1 + len_len + len != total_len) { return (-1); + } p += len_len; - if (*p++ != 0x06) + if (*p++ != 0x06) { return (-1); + } e = der_get_length(p, total_len - 1 - len_len - 1, &mech_len, &foo); - if (e) + if (e) { return (-1); + } p += foo; *mech_ret = p; return (mech_len); @@ -1506,8 +1594,9 @@ spnego_initial(OM_uint32 * minor_status, ret = der_put_length_and_tag( buf + buf_size - len - 1, buf_size - len, len, ASN1_C_CONTEXT, CONS, 0, &tmp); - if (ret == 0) + if (ret == 0) { len += tmp; + } } if (ret) { if (ret == ASN1_OVERFLOW) { @@ -1531,8 +1620,9 @@ spnego_initial(OM_uint32 * minor_status, ret = gssapi_spnego_encapsulate(minor_status, buf + buf_size - len, len, output_token, GSS_SPNEGO_MECH); - if (ret == GSS_S_COMPLETE) + if (ret == GSS_S_COMPLETE) { ret = major_status; + } end: if (token_init.mechToken != NULL) { @@ -1540,10 +1630,12 @@ end: token_init.mechToken = NULL; } free_NegTokenInit(&token_init); - if (krb5_output_token.length != 0U) + if (krb5_output_token.length != 0U) { gss_release_buffer(&minor_status2, &krb5_output_token); - if (buf) + } + if (buf) { free(buf); + } return (ret); } @@ -1585,28 +1677,32 @@ spnego_reply(OM_uint32 *minor_status, const gss_cred_id_t initiator_cred_handle, buf = input_token->value; buf_size = input_token->length; } else if ((size_t)mech_len == GSS_KRB5_MECH->length && - isc_safe_memequal(GSS_KRB5_MECH->elements, p, mech_len)) + isc_safe_memequal(GSS_KRB5_MECH->elements, p, mech_len)) { return (gss_init_sec_context( minor_status, initiator_cred_handle, context_handle, target_name, GSS_KRB5_MECH, req_flags, time_req, input_chan_bindings, input_token, actual_mech_type, output_token, ret_flags, time_rec)); - else if ((size_t)mech_len == GSS_SPNEGO_MECH->length && - isc_safe_memequal(GSS_SPNEGO_MECH->elements, p, mech_len)) { + } else if ((size_t)mech_len == GSS_SPNEGO_MECH->length && + isc_safe_memequal(GSS_SPNEGO_MECH->elements, p, mech_len)) { ret = gssapi_spnego_decapsulate(minor_status, input_token, &buf, &buf_size, GSS_SPNEGO_MECH); - if (ret) + if (ret) { return (ret); - } else + } + } else { return (GSS_S_BAD_MECH); + } ret = der_match_tag_and_length(buf, buf_size, ASN1_C_CONTEXT, CONS, 1, &len, &taglen); - if (ret) + if (ret) { return (ret); + } - if (len > buf_size - taglen) + if (len > buf_size - taglen) { return (ASN1_OVERRUN); + } ret = decode_NegTokenResp(buf + taglen, len, &resp, NULL); if (ret) { @@ -1627,7 +1723,7 @@ spnego_reply(OM_uint32 *minor_status, const gss_cred_id_t initiator_cred_handle, !isc_safe_memequal(oidbuf + sizeof(oidbuf) - oidlen, GSS_KRB5_MECH->elements, oidlen)) { free_NegTokenResp(&resp); - return GSS_S_BAD_MECH; + return (GSS_S_BAD_MECH); } if (resp.responseToken != NULL) { @@ -1673,18 +1769,19 @@ gss_init_sec_context_spnego( /* Figure out whether we're starting over or processing a reply */ - if (input_token == GSS_C_NO_BUFFER || input_token->length == 0U) + if (input_token == GSS_C_NO_BUFFER || input_token->length == 0U) { return (spnego_initial(minor_status, initiator_cred_handle, context_handle, target_name, mech_type, req_flags, time_req, input_chan_bindings, input_token, actual_mech_type, output_token, ret_flags, time_rec)); - else + } else { return (spnego_reply(minor_status, initiator_cred_handle, context_handle, target_name, mech_type, req_flags, time_req, input_chan_bindings, input_token, actual_mech_type, output_token, ret_flags, time_rec)); + } } #endif /* GSSAPI */ diff --git a/lib/dns/spnego.h b/lib/dns/spnego.h index a7c5057542..2753dfc8c6 100644 --- a/lib/dns/spnego.h +++ b/lib/dns/spnego.h @@ -46,4 +46,4 @@ gss_accept_sec_context_spnego(OM_uint32 *, gss_ctx_id_t *, const gss_cred_id_t, gss_name_t *, gss_OID *, gss_buffer_t, OM_uint32 *, OM_uint32 *, gss_cred_id_t *); -#endif +#endif /* ifndef _SPNEGO_H_ */ diff --git a/lib/dns/spnego_asn1.c b/lib/dns/spnego_asn1.c index a0f8634013..f0b6f12ed6 100644 --- a/lib/dns/spnego_asn1.c +++ b/lib/dns/spnego_asn1.c @@ -53,7 +53,7 @@ typedef struct oid { } \ } while (0) -#endif +#endif /* ifndef __asn1_common_definitions__ */ /* * MechType ::= OBJECT IDENTIFIER @@ -169,14 +169,14 @@ free_NegTokenResp(NegTokenResp *); /* Generated from spnego.asn1 */ /* Do not edit */ -#define BACK \ - if (e) \ - return e; \ - p -= l; \ - len -= l; \ - ret += l; \ - POST(p); \ - POST(len); \ +#define BACK \ + if (e) \ + return (e); \ + p -= l; \ + len -= l; \ + ret += l; \ + POST(p); \ + POST(len); \ POST(ret) static int @@ -190,7 +190,7 @@ encode_MechType(unsigned char *p, size_t len, const MechType *data, e = encode_oid(p, len, data, &l); BACK; *size = ret; - return 0; + return (0); } #define FORW \ @@ -214,12 +214,13 @@ decode_MechType(const unsigned char *p, size_t len, MechType *data, memset(data, 0, sizeof(*data)); e = decode_oid(p, len, data, &l); FORW; - if (size) + if (size) { *size = ret; - return 0; + } + return (0); fail: free_MechType(data); - return e; + return (e); } static void @@ -254,7 +255,7 @@ encode_MechTypeList(unsigned char *p, size_t len, const MechTypeList *data, &l); BACK; *size = ret; - return 0; + return (0); } static int @@ -270,8 +271,9 @@ decode_MechTypeList(const unsigned char *p, size_t len, MechTypeList *data, e = der_match_tag_and_length(p, len, ASN1_C_UNIV, CONS, UT_Sequence, &reallen, &l); FORW; - if (len < reallen) - return ASN1_OVERRUN; + if (len < reallen) { + return (ASN1_OVERRUN); + } len = reallen; { size_t origlen = len; @@ -288,7 +290,7 @@ decode_MechTypeList(const unsigned char *p, size_t len, MechTypeList *data, if ((data)->val == NULL) { (data)->val = old; (data)->len--; - return ENOMEM; + return (ENOMEM); } e = decode_MechType(p, len, &(data)->val[(data)->len - 1], &l); @@ -297,12 +299,13 @@ decode_MechTypeList(const unsigned char *p, size_t len, MechTypeList *data, } ret += oldret; } - if (size) + if (size) { *size = ret; - return 0; + } + return (0); fail: free_MechTypeList(data); - return e; + return (e); } static void @@ -345,20 +348,27 @@ encode_ContextFlags(unsigned char *p, size_t len, const ContextFlags *data, len--; ret++; c = 0; - if (data->integFlag) + if (data->integFlag) { c |= 1 << 1; - if (data->confFlag) + } + if (data->confFlag) { c |= 1 << 2; - if (data->anonFlag) + } + if (data->anonFlag) { c |= 1 << 3; - if (data->sequenceFlag) + } + if (data->sequenceFlag) { c |= 1 << 4; - if (data->replayFlag) + } + if (data->replayFlag) { c |= 1 << 5; - if (data->mutualFlag) + } + if (data->mutualFlag) { c |= 1 << 6; - if (data->delegFlag) + } + if (data->delegFlag) { c |= 1 << 7; + } *p-- = c; *p-- = 0; len -= 2; @@ -369,7 +379,7 @@ encode_ContextFlags(unsigned char *p, size_t len, const ContextFlags *data, &l); BACK; *size = ret; - return 0; + return (0); } static int @@ -385,8 +395,9 @@ decode_ContextFlags(const unsigned char *p, size_t len, ContextFlags *data, e = der_match_tag_and_length(p, len, ASN1_C_UNIV, PRIM, UT_BitString, &reallen, &l); FORW; - if (len < reallen) - return ASN1_OVERRUN; + if (len < reallen) { + return (ASN1_OVERRUN); + } p++; len--; POST(len); @@ -400,12 +411,13 @@ decode_ContextFlags(const unsigned char *p, size_t len, ContextFlags *data, data->confFlag = (*p >> 2) & 1; data->integFlag = (*p >> 1) & 1; ret += reallen; - if (size) + if (size) { *size = ret; - return 0; + } + return (0); fail: free_ContextFlags(data); - return e; + return (e); } static void @@ -481,7 +493,7 @@ encode_NegTokenInit(unsigned char *p, size_t len, const NegTokenInit *data, &l); BACK; *size = ret; - return 0; + return (0); } static int @@ -528,8 +540,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -537,9 +550,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 1, &l); - if (e) + if (e) { (data)->reqFlags = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -568,8 +581,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -577,9 +591,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 2, &l); - if (e) + if (e) { (data)->mechToken = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -608,8 +622,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -617,9 +632,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 3, &l); - if (e) + if (e) { (data)->mechListMIC = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -649,8 +664,9 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -661,12 +677,13 @@ decode_NegTokenInit(const unsigned char *p, size_t len, NegTokenInit *data, FORW; } } - if (size) + if (size) { *size = ret; - return 0; + } + return (0); fail: free_NegTokenInit(data); - return e; + return (e); } static void @@ -749,7 +766,7 @@ encode_NegTokenResp(unsigned char *p, size_t len, const NegTokenResp *data, &l); BACK; *size = ret; - return 0; + return (0); } static int @@ -768,15 +785,16 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, FORW; { int dce_fix; - if ((dce_fix = fix_dce(reallen, &len)) < 0) - return ASN1_BAD_FORMAT; + if ((dce_fix = fix_dce(reallen, &len)) < 0) { + return (ASN1_BAD_FORMAT); + } { size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 0, &l); - if (e) + if (e) { (data)->negState = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -785,13 +803,15 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, { int mydce_fix; oldlen = len; - if ((mydce_fix = - fix_dce(newlen, &len)) < 0) - return ASN1_BAD_FORMAT; + if ((mydce_fix = fix_dce(newlen, + &len)) < 0) { + return (ASN1_BAD_FORMAT); + } (data)->negState = malloc( sizeof(*(data)->negState)); - if ((data)->negState == NULL) - return ENOMEM; + if ((data)->negState == NULL) { + return (ENOMEM); + } e = decode_enumerated( p, len, (data)->negState, &l); FORW; @@ -801,8 +821,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -810,9 +831,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 1, &l); - if (e) + if (e) { (data)->supportedMech = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -821,13 +842,15 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, { int mydce_fix; oldlen = len; - if ((mydce_fix = - fix_dce(newlen, &len)) < 0) - return ASN1_BAD_FORMAT; + if ((mydce_fix = fix_dce(newlen, + &len)) < 0) { + return (ASN1_BAD_FORMAT); + } (data)->supportedMech = malloc( sizeof(*(data)->supportedMech)); - if ((data)->supportedMech == NULL) - return ENOMEM; + if ((data)->supportedMech == NULL) { + return (ENOMEM); + } e = decode_MechType( p, len, (data)->supportedMech, &l); @@ -838,8 +861,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -847,9 +871,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 2, &l); - if (e) + if (e) { (data)->responseToken = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -858,13 +882,15 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, { int mydce_fix; oldlen = len; - if ((mydce_fix = - fix_dce(newlen, &len)) < 0) - return ASN1_BAD_FORMAT; + if ((mydce_fix = fix_dce(newlen, + &len)) < 0) { + return (ASN1_BAD_FORMAT); + } (data)->responseToken = malloc( sizeof(*(data)->responseToken)); - if ((data)->responseToken == NULL) - return ENOMEM; + if ((data)->responseToken == NULL) { + return (ENOMEM); + } e = decode_octet_string( p, len, (data)->responseToken, &l); @@ -875,8 +901,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -884,9 +911,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, size_t newlen, oldlen; e = der_match_tag(p, len, ASN1_C_CONTEXT, CONS, 3, &l); - if (e) + if (e) { (data)->mechListMIC = NULL; - else { + } else { p += l; len -= l; ret += l; @@ -895,13 +922,15 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, { int mydce_fix; oldlen = len; - if ((mydce_fix = - fix_dce(newlen, &len)) < 0) - return ASN1_BAD_FORMAT; + if ((mydce_fix = fix_dce(newlen, + &len)) < 0) { + return (ASN1_BAD_FORMAT); + } (data)->mechListMIC = malloc( sizeof(*(data)->mechListMIC)); - if ((data)->mechListMIC == NULL) - return ENOMEM; + if ((data)->mechListMIC == NULL) { + return (ENOMEM); + } e = decode_octet_string( p, len, (data)->mechListMIC, &l); @@ -912,8 +941,9 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, (Der_type)0, 0, &reallen, &l); FORW; - } else + } else { len = oldlen - newlen; + } } } } @@ -924,12 +954,13 @@ decode_NegTokenResp(const unsigned char *p, size_t len, NegTokenResp *data, FORW; } } - if (size) + if (size) { *size = ret; - return 0; + } + return (0); fail: free_NegTokenResp(data); - return e; + return (e); } static void diff --git a/lib/dns/ssu.c b/lib/dns/ssu.c index 3f84dfecc0..2dba4d6536 100644 --- a/lib/dns/ssu.c +++ b/lib/dns/ssu.c @@ -39,11 +39,12 @@ struct dns_ssurule { unsigned int magic; bool grant; /*%< is this a grant or a deny? */ - dns_ssumatchtype_t matchtype; /*%< which type of pattern match? */ - dns_name_t * identity; /*%< the identity to match */ - dns_name_t * name; /*%< the name being updated */ - unsigned int ntypes; /*%< number of data types covered */ - dns_rdatatype_t * types; /*%< the data types. Can include */ + dns_ssumatchtype_t matchtype; /*%< which type of pattern match? + * */ + dns_name_t * identity; /*%< the identity to match */ + dns_name_t * name; /*%< the name being updated */ + unsigned int ntypes; /*%< number of data types covered */ + dns_rdatatype_t *types; /*%< the data types. Can include */ /* ANY. if NULL, defaults to all */ /* types except SIG, SOA, and NS */ ISC_LINK(dns_ssurule_t) link; @@ -93,9 +94,10 @@ destroy(dns_ssutable_t *table) dns_name_free(rule->name, mctx); isc_mem_put(mctx, rule->name, sizeof(dns_name_t)); } - if (rule->types != NULL) + if (rule->types != NULL) { isc_mem_put(mctx, rule->types, rule->ntypes * sizeof(dns_rdatatype_t)); + } ISC_LIST_UNLINK(table->rules, rule, link); rule->magic = 0; isc_mem_put(mctx, rule, sizeof(dns_ssurule_t)); @@ -144,10 +146,12 @@ dns_ssutable_addrule(dns_ssutable_t *table, bool grant, REQUIRE(dns_name_isabsolute(identity)); REQUIRE(dns_name_isabsolute(name)); REQUIRE(matchtype <= dns_ssumatchtype_max); - if (matchtype == dns_ssumatchtype_wildcard) + if (matchtype == dns_ssumatchtype_wildcard) { REQUIRE(dns_name_iswildcard(name)); - if (ntypes > 0) + } + if (ntypes > 0) { REQUIRE(types != NULL); + } mctx = table->mctx; rule = isc_mem_get(mctx, sizeof(dns_ssurule_t)); @@ -173,8 +177,9 @@ dns_ssutable_addrule(dns_ssutable_t *table, bool grant, rule->types = isc_mem_get(mctx, ntypes * sizeof(dns_rdatatype_t)); memmove(rule->types, types, ntypes * sizeof(dns_rdatatype_t)); - } else + } else { rule->types = NULL; + } rule->magic = SSURULEMAGIC; ISC_LIST_INITANDAPPEND(table->rules, rule, link); @@ -303,8 +308,9 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, REQUIRE(dns_name_isabsolute(name)); REQUIRE(addr == NULL || env != NULL); - if (signer == NULL && addr == NULL) + if (signer == NULL && addr == NULL) { return (false); + } for (rule = ISC_LIST_HEAD(table->rules); rule != NULL; rule = ISC_LIST_NEXT(rule, link)) { @@ -316,15 +322,18 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, case dns_ssumatchtype_self: case dns_ssumatchtype_selfsub: case dns_ssumatchtype_selfwild: - if (signer == NULL) + if (signer == NULL) { continue; + } if (dns_name_iswildcard(rule->identity)) { if (!dns_name_matcheswildcard(signer, - rule->identity)) + rule->identity)) { continue; + } } else { - if (!dns_name_equal(signer, rule->identity)) + if (!dns_name_equal(signer, rule->identity)) { continue; + } } break; case dns_ssumatchtype_selfkrb5: @@ -333,13 +342,15 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, case dns_ssumatchtype_selfsubms: case dns_ssumatchtype_subdomainkrb5: case dns_ssumatchtype_subdomainms: - if (signer == NULL) + if (signer == NULL) { continue; + } break; case dns_ssumatchtype_tcpself: case dns_ssumatchtype_6to4self: - if (!tcp || addr == NULL) + if (!tcp || addr == NULL) { continue; + } break; case dns_ssumatchtype_external: case dns_ssumatchtype_dlz: @@ -348,12 +359,14 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, switch (rule->matchtype) { case dns_ssumatchtype_name: - if (!dns_name_equal(name, rule->name)) + if (!dns_name_equal(name, rule->name)) { continue; + } break; case dns_ssumatchtype_subdomain: - if (!dns_name_issubdomain(name, rule->name)) + if (!dns_name_issubdomain(name, rule->name)) { continue; + } break; case dns_ssumatchtype_local: if (addr == NULL) { @@ -379,25 +392,30 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, } break; case dns_ssumatchtype_wildcard: - if (!dns_name_matcheswildcard(name, rule->name)) + if (!dns_name_matcheswildcard(name, rule->name)) { continue; + } break; case dns_ssumatchtype_self: - if (!dns_name_equal(signer, name)) + if (!dns_name_equal(signer, name)) { continue; + } break; case dns_ssumatchtype_selfsub: - if (!dns_name_issubdomain(name, signer)) + if (!dns_name_issubdomain(name, signer)) { continue; + } break; case dns_ssumatchtype_selfwild: wildcard = dns_fixedname_initname(&fixed); result = dns_name_concatenate(dns_wildcardname, signer, wildcard, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; - if (!dns_name_matcheswildcard(name, wildcard)) + } + if (!dns_name_matcheswildcard(name, wildcard)) { continue; + } break; case dns_ssumatchtype_selfkrb5: if (dst_gssapi_identitymatchesrealmkrb5( @@ -419,20 +437,23 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, continue; case dns_ssumatchtype_selfsubms: if (dst_gssapi_identitymatchesrealmms( - signer, name, rule->identity, true)) + signer, name, rule->identity, true)) { break; + } continue; case dns_ssumatchtype_subdomainkrb5: - if (!dns_name_issubdomain(name, rule->name)) + if (!dns_name_issubdomain(name, rule->name)) { continue; + } if (dst_gssapi_identitymatchesrealmkrb5( signer, NULL, rule->identity, false)) { break; } continue; case dns_ssumatchtype_subdomainms: - if (!dns_name_issubdomain(name, rule->name)) + if (!dns_name_issubdomain(name, rule->name)) { continue; + } if (dst_gssapi_identitymatchesrealmms( signer, NULL, rule->identity, false)) { break; @@ -443,39 +464,47 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, reverse_from_address(tcpself, addr); if (dns_name_iswildcard(rule->identity)) { if (!dns_name_matcheswildcard(tcpself, - rule->identity)) + rule->identity)) { continue; + } } else { - if (!dns_name_equal(tcpself, rule->identity)) + if (!dns_name_equal(tcpself, rule->identity)) { continue; + } } - if (!dns_name_equal(tcpself, name)) + if (!dns_name_equal(tcpself, name)) { continue; + } break; case dns_ssumatchtype_6to4self: stfself = dns_fixedname_initname(&fixed); stf_from_address(stfself, addr); if (dns_name_iswildcard(rule->identity)) { if (!dns_name_matcheswildcard(stfself, - rule->identity)) + rule->identity)) { continue; + } } else { - if (!dns_name_equal(stfself, rule->identity)) + if (!dns_name_equal(stfself, rule->identity)) { continue; + } } - if (!dns_name_equal(stfself, name)) + if (!dns_name_equal(stfself, name)) { continue; + } break; case dns_ssumatchtype_external: if (!dns_ssu_external_match(rule->identity, signer, name, addr, type, key, - table->mctx)) + table->mctx)) { continue; + } break; case dns_ssumatchtype_dlz: if (!dns_dlz_ssumatch(table->dlzdatabase, signer, name, - addr, type, key)) + addr, type, key)) { continue; + } break; } @@ -486,16 +515,19 @@ dns_ssutable_checkrules(dns_ssutable_t *table, const dns_name_t *signer, * the type. */ if (rule->matchtype != dns_ssumatchtype_dlz && - !isusertype(type)) + !isusertype(type)) { continue; + } } else { for (i = 0; i < rule->ntypes; i++) { if (rule->types[i] == dns_rdatatype_any || - rule->types[i] == type) + rule->types[i] == type) { break; + } } - if (i == rule->ntypes) + if (i == rule->ntypes) { continue; + } } return (rule->grant); } @@ -572,8 +604,9 @@ dns_ssutable_createdlz(isc_mem_t *mctx, dns_ssutable_t **tablep, REQUIRE(tablep != NULL && *tablep == NULL); result = dns_ssutable_create(mctx, &table); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } table->dlzdatabase = dlzdatabase; diff --git a/lib/dns/ssu_external.c b/lib/dns/ssu_external.c index f980df25f5..1ba2eef4ed 100644 --- a/lib/dns/ssu_external.c +++ b/lib/dns/ssu_external.c @@ -23,7 +23,7 @@ #ifdef ISC_PLATFORM_HAVESYSUNH #include #include -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ #include #include @@ -96,7 +96,7 @@ ux_socket_connect(const char *path) close(fd); return (-1); } -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ return (fd); } @@ -148,14 +148,16 @@ dns_ssu_external_match(const dns_name_t *identity, const dns_name_t *signer, sock_path = &b_identity[6]; fd = ux_socket_connect(sock_path); - if (fd == -1) + if (fd == -1) { return (false); + } if (key != NULL) { dst_key_format(key, b_key, sizeof(b_key)); tkey_token = dst_key_tkeytoken(key); - } else + } else { b_key[0] = 0; + } if (tkey_token != NULL) { isc_buffer_region(tkey_token, &token_region); @@ -163,17 +165,19 @@ dns_ssu_external_match(const dns_name_t *identity, const dns_name_t *signer, } /* Format the request elements */ - if (signer != NULL) + if (signer != NULL) { dns_name_format(signer, b_signer, sizeof(b_signer)); - else + } else { b_signer[0] = 0; + } dns_name_format(name, b_name, sizeof(b_name)); - if (tcpaddr != NULL) + if (tcpaddr != NULL) { isc_netaddr_format(tcpaddr, b_addr, sizeof(b_addr)); - else + } else { b_addr[0] = 0; + } dns_rdatatype_format(type, b_type, sizeof(b_type)); @@ -208,8 +212,9 @@ dns_ssu_external_match(const dns_name_t *identity, const dns_name_t *signer, isc_buffer_putuint8(&buf, 0); isc_buffer_putuint32(&buf, token_len); - if (tkey_token && token_len != 0) + if (tkey_token && token_len != 0) { isc_buffer_putmem(&buf, token_region.base, token_len); + } ENSURE(isc_buffer_availablelength(&buf) == 0); diff --git a/lib/dns/stats.c b/lib/dns/stats.c index dd8bcc6fde..fa9cd652c5 100644 --- a/lib/dns/stats.c +++ b/lib/dns/stats.c @@ -167,8 +167,9 @@ create_stats(isc_mem_t *mctx, dns_statstype_t type, int ncounters, isc_refcount_init(&stats->references, 1); result = isc_stats_create(mctx, &stats->counters, ncounters); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto clean_mutex; + } stats->magic = DNS_STATS_MAGIC; stats->type = type; @@ -255,9 +256,9 @@ inline static isc_statscounter_t rdatatype2counter(dns_rdatatype_t type) { if (type > (dns_rdatatype_t)RDTYPECOUNTER_MAXTYPE) { - return 0; + return (0); } - return (isc_statscounter_t)type; + return ((isc_statscounter_t)type); } void @@ -347,8 +348,9 @@ dns_rcodestats_increment(dns_stats_t *stats, dns_rcode_t code) { REQUIRE(DNS_STATS_VALID(stats) && stats->type == dns_statstype_rcode); - if (code <= dns_rcode_badcookie) + if (code <= dns_rcode_badcookie) { isc_stats_increment(stats->counters, (isc_statscounter_t)code); + } } void @@ -539,10 +541,12 @@ dns_stats_alloccounters(isc_mem_t *mctx, uint64_t **ctrp) { int i; uint64_t *p = isc_mem_get(mctx, DNS_STATS_NCOUNTERS * sizeof(uint64_t)); - if (p == NULL) + if (p == NULL) { return (ISC_R_NOMEMORY); - for (i = 0; i < DNS_STATS_NCOUNTERS; i++) + } + for (i = 0; i < DNS_STATS_NCOUNTERS; i++) { p[i] = 0; + } *ctrp = p; return (ISC_R_SUCCESS); } diff --git a/lib/dns/tcpmsg.c b/lib/dns/tcpmsg.c index 5711749e11..403a25e388 100644 --- a/lib/dns/tcpmsg.c +++ b/lib/dns/tcpmsg.c @@ -25,9 +25,9 @@ #ifdef TCPMSG_DEBUG #include /* Required for printf. */ #define XDEBUG(x) printf x -#else +#else /* ifdef TCPMSG_DEBUG */ #define XDEBUG(x) -#endif +#endif /* ifdef TCPMSG_DEBUG */ #define TCPMSG_MAGIC ISC_MAGIC('T', 'C', 'P', 'm') #define VALID_TCPMSG(foo) ISC_MAGIC_VALID(foo, TCPMSG_MAGIC) @@ -186,8 +186,9 @@ dns_tcpmsg_readmessage(dns_tcpmsg_t *tcpmsg, isc_task_t *task, result = isc_socket_recv(tcpmsg->sock, ®ion, 0, tcpmsg->task, recv_length, tcpmsg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { tcpmsg->task = NULL; + } return (result); } @@ -216,14 +217,15 @@ void dns_tcpmsg_freebuffer(dns_tcpmsg_t *tcpmsg) { REQUIRE(VALID_TCPMSG(tcpmsg)); - if (tcpmsg->buffer.base == NULL) + if (tcpmsg->buffer.base == NULL) { return; + } isc_mem_put(tcpmsg->mctx, tcpmsg->buffer.base, tcpmsg->buffer.length); tcpmsg->buffer.base = NULL; tcpmsg->buffer.length = 0; } -#endif +#endif /* if 0 */ void dns_tcpmsg_invalidate(dns_tcpmsg_t *tcpmsg) diff --git a/lib/dns/tests/acl_test.c b/lib/dns/tests/acl_test.c index 7661e4e505..f6edc40d51 100644 --- a/lib/dns/tests/acl_test.c +++ b/lib/dns/tests/acl_test.c @@ -158,4 +158,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/db_test.c b/lib/dns/tests/db_test.c index 46518428e8..2547138336 100644 --- a/lib/dns/tests/db_test.c +++ b/lib/dns/tests/db_test.c @@ -430,4 +430,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/dbdiff_test.c b/lib/dns/tests/dbdiff_test.c index 730cbd0487..86ddaec84a 100644 --- a/lib/dns/tests/dbdiff_test.c +++ b/lib/dns/tests/dbdiff_test.c @@ -186,4 +186,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/dbiterator_test.c b/lib/dns/tests/dbiterator_test.c index 70fed7bafc..e150c9fb7b 100644 --- a/lib/dns/tests/dbiterator_test.c +++ b/lib/dns/tests/dbiterator_test.c @@ -123,8 +123,9 @@ test_walk(const char *filename, int nodes) for (result = dns_dbiterator_first(iter); result == ISC_R_SUCCESS; result = dns_dbiterator_next(iter)) { result = dns_dbiterator_current(iter, &node, name); - if (result == DNS_R_NEWORIGIN) + if (result == DNS_R_NEWORIGIN) { result = ISC_R_SUCCESS; + } assert_int_equal(result, ISC_R_SUCCESS); dns_db_detachnode(db, &node); i++; @@ -175,8 +176,9 @@ test_reverse(const char *filename) for (result = dns_dbiterator_last(iter); result == ISC_R_SUCCESS; result = dns_dbiterator_prev(iter)) { result = dns_dbiterator_current(iter, &node, name); - if (result == DNS_R_NEWORIGIN) + if (result == DNS_R_NEWORIGIN) { result = ISC_R_SUCCESS; + } assert_int_equal(result, ISC_R_SUCCESS); dns_db_detachnode(db, &node); i++; @@ -233,8 +235,9 @@ test_seek_node(const char *filename, int nodes) while (result == ISC_R_SUCCESS) { result = dns_dbiterator_current(iter, &node, name); - if (result == DNS_R_NEWORIGIN) + if (result == DNS_R_NEWORIGIN) { result = ISC_R_SUCCESS; + } assert_int_equal(result, ISC_R_SUCCESS); dns_db_detachnode(db, &node); result = dns_dbiterator_next(iter); @@ -407,4 +410,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/dbversion_test.c b/lib/dns/tests/dbversion_test.c index c7e212696e..8ebf73112d 100644 --- a/lib/dns/tests/dbversion_test.c +++ b/lib/dns/tests/dbversion_test.c @@ -510,4 +510,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/dh_test.c b/lib/dns/tests/dh_test.c index 200c8562f0..f6739897bc 100644 --- a/lib/dns/tests/dh_test.c +++ b/lib/dns/tests/dh_test.c @@ -101,9 +101,9 @@ main(void) }; return (cmocka_run_group_tests(tests, NULL, NULL)); -#else +#else /* if USE_OPENSSL */ print_message("1..0 # Skipped: dh test broken with PKCS11"); -#endif +#endif /* if USE_OPENSSL */ } #else /* HAVE_CMOCKA */ @@ -117,4 +117,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/dispatch_test.c b/lib/dns/tests/dispatch_test.c index d788227b89..e9329295cb 100644 --- a/lib/dns/tests/dispatch_test.c +++ b/lib/dns/tests/dispatch_test.c @@ -73,15 +73,17 @@ make_dispatchset(unsigned int ndisps) dns_dispatch_t *disp = NULL; result = dns_dispatchmgr_create(dt_mctx, &dispatchmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_sockaddr_any(&any); attrs = DNS_DISPATCHATTR_IPV4 | DNS_DISPATCHATTR_UDP; result = dns_dispatch_getudp(dispatchmgr, socketmgr, taskmgr, &any, 512, 6, 1024, 17, 19, attrs, attrs, &disp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_dispatchset_create(dt_mctx, socketmgr, taskmgr, disp, &dset, ndisps); @@ -200,8 +202,9 @@ nameserver(isc_task_t *task, isc_event_t *event) isc_socket_attach(sock, &dummy); result = isc_socket_sendto(sock, ®ion, task, senddone, sock, &ev->address, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_socket_detach(&dummy); + } /* * send nextitem message. @@ -212,8 +215,9 @@ nameserver(isc_task_t *task, isc_event_t *event) isc_socket_attach(sock, &dummy); result = isc_socket_sendto(sock, ®ion, task, senddone, sock, &ev->address, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_socket_detach(&dummy); + } isc_event_free(&event); } @@ -364,4 +368,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/dnstap_test.c b/lib/dns/tests/dnstap_test.c index 983a2b9838..86ce24c222 100644 --- a/lib/dns/tests/dnstap_test.c +++ b/lib/dns/tests/dnstap_test.c @@ -386,7 +386,7 @@ main(void) setenv("TZ", "PST8", 1); return (cmocka_run_group_tests(tests, NULL, NULL)); -#else +#else /* if HAVE_DNSTAP */ print_message("1..0 # Skip dnstap not enabled\n"); #endif /* HAVE_DNSTAP */ } diff --git a/lib/dns/tests/dnstest.c b/lib/dns/tests/dnstest.c index 54e61b768b..8696bc9ace 100644 --- a/lib/dns/tests/dnstest.c +++ b/lib/dns/tests/dnstest.c @@ -229,8 +229,9 @@ dns_test_makeview(const char *name, dns_view_t **viewp) return (ISC_R_SUCCESS); cleanup: - if (view != NULL) + if (view != NULL) { dns_view_detach(&view); + } return (result); } @@ -317,8 +318,9 @@ dns_test_managezone(dns_zone_t *zone) REQUIRE(zonemgr != NULL); result = dns_zonemgr_setsize(zonemgr, 1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_zonemgr_managezone(zonemgr, zone); return (result); @@ -354,13 +356,13 @@ dns_test_nap(uint32_t usec) nanosleep(&ts, NULL); #elif HAVE_USLEEP usleep(usec); -#else +#else /* ifdef HAVE_NANOSLEEP */ /* * No fractional-second sleep function is available, so we * round up to the nearest second and sleep instead */ sleep((usec / 1000000) + 1); -#endif +#endif /* ifdef HAVE_NANOSLEEP */ } isc_result_t @@ -374,13 +376,15 @@ dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, 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(dt_mctx, "rbt", name, dbtype, dns_rdataclass_in, 0, NULL, db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_load(*db, testfile, dns_masterformat_text, 0); return (result); @@ -389,12 +393,13 @@ dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, static int fromhex(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { return (c - '0'); - else if (c >= 'a' && c <= 'f') + } else if (c >= 'a' && c <= 'f') { return (c - 'a' + 10); - else if (c >= 'A' && c <= 'F') + } else if (c >= 'A' && c <= 'F') { return (c - 'A' + 10); + } printf("bad input format: %02x\n", c); exit(3); @@ -434,8 +439,9 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, int n; result = isc_stdio_open(file, "r", &f); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } bp = buf; while (fgets(s, sizeof(s), f) != NULL) { @@ -443,8 +449,9 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, wp = s; len = 0; while (*rp != '\0') { - if (*rp == '#') + if (*rp == '#') { break; + } if (*rp != ' ' && *rp != '\t' && *rp != '\r' && *rp != '\n') { *wp++ = *rp; @@ -452,12 +459,15 @@ dns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, } rp++; } - if (len == 0U) + if (len == 0U) { continue; - if (len % 2 != 0U) + } + if (len % 2 != 0U) { CHECK(ISC_R_UNEXPECTEDEND); - if (len > bufsiz * 2) + } + if (len > bufsiz * 2) { CHECK(ISC_R_NOSPACE); + } rp = s; for (i = 0; i < len; i += 2) { n = fromhex(*rp++); diff --git a/lib/dns/tests/dst_test.c b/lib/dns/tests/dst_test.c index 06153a2f91..7a4eb16b2e 100644 --- a/lib/dns/tests/dst_test.c +++ b/lib/dns/tests/dst_test.c @@ -306,4 +306,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/geoip_test.c b/lib/dns/tests/geoip_test.c index 02f45eeea9..f993cd6e2d 100644 --- a/lib/dns/tests/geoip_test.c +++ b/lib/dns/tests/geoip_test.c @@ -428,9 +428,9 @@ main(void) }; return (cmocka_run_group_tests(tests, _setup, _teardown)); -#else +#else /* if defined(HAVE_GEOIP2) */ print_message("1..0 # Skip GeoIP not enabled\n"); -#endif +#endif /* if defined(HAVE_GEOIP2) */ } #else /* HAVE_CMOCKA */ diff --git a/lib/dns/tests/keytable_test.c b/lib/dns/tests/keytable_test.c index 605e21611b..03f4b36725 100644 --- a/lib/dns/tests/keytable_test.c +++ b/lib/dns/tests/keytable_test.c @@ -731,4 +731,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/master_test.c b/lib/dns/tests/master_test.c index 22d8ade66c..f11ef4fb4a 100644 --- a/lib/dns/tests/master_test.c +++ b/lib/dns/tests/master_test.c @@ -657,4 +657,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/name_test.c b/lib/dns/tests/name_test.c index b4f30a770e..3fcd7e4492 100644 --- a/lib/dns/tests/name_test.c +++ b/lib/dns/tests/name_test.c @@ -642,7 +642,6 @@ getlabelsequence_test(void **state) { "c.d", 1, "a.b.c.d", 3, 1 }, { "a.b.c.d.e", 2, "c.d", 0, 2 }, { "a.b.c", 0, "a.b.c", 0, 3 }, - }; unsigned int i; @@ -811,4 +810,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/nsec3_test.c b/lib/dns/tests/nsec3_test.c index 09f39df77d..648ed943ed 100644 --- a/lib/dns/tests/nsec3_test.c +++ b/lib/dns/tests/nsec3_test.c @@ -200,4 +200,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/peer_test.c b/lib/dns/tests/peer_test.c index 51f19e40d5..91f08856ba 100644 --- a/lib/dns/tests/peer_test.c +++ b/lib/dns/tests/peer_test.c @@ -175,4 +175,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/private_test.c b/lib/dns/tests/private_test.c index 17db64adb0..9766b5b79f 100644 --- a/lib/dns/tests/private_test.c +++ b/lib/dns/tests/private_test.c @@ -243,4 +243,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/rbt_serialize_test.c b/lib/dns/tests/rbt_serialize_test.c index bd3ce6c0d4..45af262bbc 100644 --- a/lib/dns/tests/rbt_serialize_test.c +++ b/lib/dns/tests/rbt_serialize_test.c @@ -54,7 +54,7 @@ #ifndef MAP_FILE #define MAP_FILE 0 -#endif +#endif /* ifndef MAP_FILE */ /* Set to true (or use -v option) for verbose output */ static bool verbose = false; @@ -497,4 +497,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/rbt_test.c b/lib/dns/tests/rbt_test.c index 13ddaa7faa..486227b333 100644 --- a/lib/dns/tests/rbt_test.c +++ b/lib/dns/tests/rbt_test.c @@ -304,12 +304,14 @@ rbtnode_get_distance(void **state) while (node != NULL) { const size_t *distance = (const size_t *)node->data; - if (distance != NULL) + if (distance != NULL) { assert_int_equal(*distance, dns__rbtnode_getdistance(node)); + } result = dns_rbtnodechain_next(&chain, NULL, NULL); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { break; + } dns_rbtnodechain_current(&chain, NULL, NULL, &node); } @@ -378,8 +380,9 @@ rbt_check_distance_random(void **state) name = dns_fixedname_name(&fname); result = dns_rbt_addname(mytree, name, n); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } } } @@ -1225,8 +1228,9 @@ find_thread(void *arg) unsigned int start = 0; mytree = (dns_rbt_t *)arg; - while (start == 0) + while (start == 0) { start = random() % 4000000; + } /* Query 32 million random names from it in each thread */ for (j = 0; j < 8; j++) { @@ -1365,4 +1369,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/rdata_test.c b/lib/dns/tests/rdata_test.c index 7e8ac32b58..69ebbd1163 100644 --- a/lib/dns/tests/rdata_test.c +++ b/lib/dns/tests/rdata_test.c @@ -76,7 +76,7 @@ _teardown(void **state) typedef struct text_ok { const char *text_in; /* text passed to fromtext_*() */ const char *text_out; /* text expected from totext_*(); - NULL indicates text_in is invalid */ + * NULL indicates text_in is invalid */ } text_ok_t; /* @@ -2154,11 +2154,11 @@ sshfp(void **state) TEXT_VALID("0 0"), /* no finger print */ TEXT_VALID("0 0 AA"), /* reserved */ TEXT_INVALID("0 1 AA"), /* too short SHA 1 - digest */ + * digest */ TEXT_INVALID("0 2 AA"), /* too short SHA 256 - digest */ + * digest */ TEXT_VALID("0 3 AA"), /* unknown finger print - type */ + * type */ /* good length SHA 1 digest */ TEXT_VALID("1 1 " "00112233445566778899AABBCCDDEEFF171" @@ -2220,7 +2220,7 @@ sshfp(void **state) 0x31, 0x32, 0x33), /* unknown digest, * no fingerprint */ WIRE_VALID(0x00, 0x03), WIRE_VALID(0x00, 0x03, 0x00), /* unknown - digest + * digest */ WIRE_SENTINEL() }; @@ -2590,4 +2590,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/rdataset_test.c b/lib/dns/tests/rdataset_test.c index f5819818a2..dc1b46bde9 100644 --- a/lib/dns/tests/rdataset_test.c +++ b/lib/dns/tests/rdataset_test.c @@ -146,4 +146,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/rdatasetstats_test.c b/lib/dns/tests/rdatasetstats_test.c index 84b3e59ea2..cb167c7e14 100644 --- a/lib/dns/tests/rdatasetstats_test.c +++ b/lib/dns/tests/rdatasetstats_test.c @@ -125,7 +125,7 @@ verify_active_counters(dns_rdatastatstype_t which, uint64_t value, void *arg) unsigned int attributes; #if debug unsigned int type; -#endif +#endif /* if debug */ UNUSED(which); UNUSED(arg); @@ -141,7 +141,7 @@ verify_active_counters(dns_rdatastatstype_t which, uint64_t value, void *arg) ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_STALE) ? "#" : " ", ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ", type, (unsigned)value); -#endif +#endif /* if debug */ if ((attributes & DNS_RDATASTATSTYPE_ATTR_ANCIENT) == 0 && (attributes & DNS_RDATASTATSTYPE_ATTR_STALE) == 0) { assert_int_equal(value, 1); @@ -156,7 +156,7 @@ verify_stale_counters(dns_rdatastatstype_t which, uint64_t value, void *arg) unsigned int attributes; #if debug unsigned int type; -#endif +#endif /* if debug */ UNUSED(which); UNUSED(arg); @@ -172,7 +172,7 @@ verify_stale_counters(dns_rdatastatstype_t which, uint64_t value, void *arg) ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_STALE) ? "#" : " ", ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ", type, (unsigned)value); -#endif +#endif /* if debug */ if ((attributes & DNS_RDATASTATSTYPE_ATTR_STALE) != 0) { assert_int_equal(value, 1); } else { @@ -186,7 +186,7 @@ verify_ancient_counters(dns_rdatastatstype_t which, uint64_t value, void *arg) unsigned int attributes; #if debug unsigned int type; -#endif +#endif /* if debug */ UNUSED(which); UNUSED(arg); @@ -202,7 +202,7 @@ verify_ancient_counters(dns_rdatastatstype_t which, uint64_t value, void *arg) ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_STALE) ? "#" : " ", ATTRIBUTE_SET(DNS_RDATASTATSTYPE_ATTR_NXDOMAIN) ? "X" : " ", type, (unsigned)value); -#endif +#endif /* if debug */ if ((attributes & DNS_RDATASTATSTYPE_ATTR_ANCIENT) != 0) { assert_int_equal(value, 1); } else { @@ -320,4 +320,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/resolver_test.c b/lib/dns/tests/resolver_test.c index 9d8a0812de..1ab9c8a8b5 100644 --- a/lib/dns/tests/resolver_test.c +++ b/lib/dns/tests/resolver_test.c @@ -235,4 +235,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/result_test.c b/lib/dns/tests/result_test.c index 59ffef7cf3..7fcabc9fd8 100644 --- a/lib/dns/tests/result_test.c +++ b/lib/dns/tests/result_test.c @@ -128,4 +128,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/sigs_test.c b/lib/dns/tests/sigs_test.c index 8acbabc15b..cf2a0d707f 100644 --- a/lib/dns/tests/sigs_test.c +++ b/lib/dns/tests/sigs_test.c @@ -92,7 +92,8 @@ typedef struct { typedef struct { const char * description; /* test description */ const zonechange_t *changes; /* array of "raw" zone changes */ - const zonediff_t * zonediff; /* array of "processed" zone changes */ + const zonediff_t * zonediff; /* array of "processed" zone changes + * */ } updatesigs_test_params_t; /*% @@ -460,4 +461,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/time_test.c b/lib/dns/tests/time_test.c index 1a94d99cd4..5e6abcbdce 100644 --- a/lib/dns/tests/time_test.c +++ b/lib/dns/tests/time_test.c @@ -223,4 +223,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/tsig_test.c b/lib/dns/tests/tsig_test.c index 93c0830798..c93ad3edb5 100644 --- a/lib/dns/tests/tsig_test.c +++ b/lib/dns/tests/tsig_test.c @@ -617,4 +617,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/update_test.c b/lib/dns/tests/update_test.c index 2f3cb4afea..7a52ded1bf 100644 --- a/lib/dns/tests/update_test.c +++ b/lib/dns/tests/update_test.c @@ -342,4 +342,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/zonemgr_test.c b/lib/dns/tests/zonemgr_test.c index a92c09abb9..185942a40f 100644 --- a/lib/dns/tests/zonemgr_test.c +++ b/lib/dns/tests/zonemgr_test.c @@ -142,8 +142,9 @@ zonemgr_createzone(void **state) assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(zone); - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } dns_zonemgr_shutdown(myzonemgr); dns_zonemgr_detach(&myzonemgr); @@ -267,4 +268,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/tests/zt_test.c b/lib/dns/tests/zt_test.c index ca82e0f517..4028d96fb4 100644 --- a/lib/dns/tests/zt_test.c +++ b/lib/dns/tests/zt_test.c @@ -212,8 +212,9 @@ asyncload_zone(void **state) isc_app_onrun(dt_mctx, maintask, start_zone_asyncload, &args); isc_app_run(); - while (dns__zone_loadpending(zone) && i++ < 5000) + while (dns__zone_loadpending(zone) && i++ < 5000) { dns_test_nap(1000); + } assert_true(atomic_load(&done)); /* The zone should now be loaded; test it */ result = dns_zone_getdb(zone, &db); @@ -234,8 +235,9 @@ asyncload_zone(void **state) isc_app_run(); - while (dns__zone_loadpending(zone) && i++ < 5000) + while (dns__zone_loadpending(zone) && i++ < 5000) { dns_test_nap(1000); + } assert_true(atomic_load(&done)); /* The zone should now be loaded; test it */ result = dns_zone_getdb(zone, &db); @@ -250,16 +252,18 @@ asyncload_zone(void **state) isc_app_run(); - while (dns__zone_loadpending(zone) && i++ < 5000) + while (dns__zone_loadpending(zone) && i++ < 5000) { dns_test_nap(1000); + } assert_true(atomic_load(&done)); /* The zone should now be loaded; test it */ result = dns_zone_getdb(zone, &db); assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(db); - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } dns_test_releasezone(zone); dns_test_closezonemgr(); @@ -332,14 +336,16 @@ asyncload_zt(void **state) result = dns_zone_getdb(zone1, &db); assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(db); - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } result = dns_zone_getdb(zone2, &db); assert_int_equal(result, ISC_R_SUCCESS); assert_non_null(db); - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } dns_test_releasezone(zone3); dns_test_releasezone(zone2); @@ -377,4 +383,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/dns/time.c b/lib/dns/time.c index 27457a380c..523d304b01 100644 --- a/lib/dns/time.c +++ b/lib/dns/time.c @@ -47,8 +47,9 @@ dns_time64_totext(int64_t t, isc_buffer_t *target) tm.tm_year = 70; while (t < 0) { - if (tm.tm_year == 0) + if (tm.tm_year == 0) { return (ISC_R_RANGE); + } tm.tm_year--; secs = year_secs(tm.tm_year + 1900); t += secs; @@ -56,8 +57,9 @@ dns_time64_totext(int64_t t, isc_buffer_t *target) while ((secs = year_secs(tm.tm_year + 1900)) <= t) { t -= secs; tm.tm_year++; - if (tm.tm_year + 1900 > 9999) + if (tm.tm_year + 1900 > 9999) { return (ISC_R_RANGE); + } } tm.tm_mon = 0; while ((secs = month_secs(tm.tm_mon, tm.tm_year + 1900)) <= t) { @@ -88,8 +90,9 @@ dns_time64_totext(int64_t t, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(buf); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, buf, l); isc_buffer_add(target, l); @@ -111,10 +114,11 @@ dns_time64_from32(uint32_t value) */ isc_stdtime_get(&now); start = (int64_t)now; - if (isc_serial_gt(value, now)) + if (isc_serial_gt(value, now)) { t = start + (value - now); - else + } else { t = start - (now - value); + } return (t); } @@ -136,22 +140,25 @@ dns_time64_fromtext(const char *source, int64_t *target) #define RANGE(min, max, value) \ do { \ if (value < (min) || value > (max)) \ - return (ISC_R_RANGE); \ + return ((ISC_R_RANGE)); \ } while (0) - if (strlen(source) != 14U) + if (strlen(source) != 14U) { return (DNS_R_SYNTAX); + } /* * Confirm the source only consists digits. sscanf() allows some * minor exceptions. */ for (i = 0; i < 14; i++) { - if (!isdigit((unsigned char)source[i])) + if (!isdigit((unsigned char)source[i])) { return (DNS_R_SYNTAX); + } } if (sscanf(source, "%4d%2d%2d%2d%2d%2d", &year, &month, &day, &hour, - &minute, &second) != 6) + &minute, &second) != 6) { return (DNS_R_SYNTAX); + } RANGE(0, 9999, year); RANGE(1, 12, month); @@ -174,10 +181,12 @@ dns_time64_fromtext(const char *source, int64_t *target) * Note: this uses a idealized calendar. */ value = second + (60 * minute) + (3600 * hour) + ((day - 1) * 86400); - for (i = 0; i < (month - 1); i++) + for (i = 0; i < (month - 1); i++) { value += days[i] * 86400; - if (is_leap(year) && month > 2) + } + if (is_leap(year) && month > 2) { value += 86400; + } if (year < 1970) { for (i = 1969; i >= year; i--) { secs = (is_leap(i) ? 366 : 365) * 86400; @@ -200,8 +209,9 @@ dns_time32_fromtext(const char *source, uint32_t *target) int64_t value64; isc_result_t result; result = dns_time64_fromtext(source, &value64); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } *target = (uint32_t)value64; return (ISC_R_SUCCESS); diff --git a/lib/dns/tkey.c b/lib/dns/tkey.c index 8cd0ecdd17..be0c33007e 100644 --- a/lib/dns/tkey.c +++ b/lib/dns/tkey.c @@ -48,7 +48,7 @@ #if USE_PKCS11 #include -#endif +#endif /* if USE_PKCS11 */ #define RETERR(x) \ do { \ @@ -91,17 +91,19 @@ dumpmessage(dns_message_t *msg) continue; } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { tkey_log("%.*s", (int)isc_buffer_usedlength(&outbuf), (char *)isc_buffer_base(&outbuf)); - else + } else { tkey_log("Warning: dns_message_totext: %s", dns_result_totext(result)); + } break; } - if (output != NULL) + if (output != NULL) { isc_mem_put(msg->mctx, output, len); + } } isc_result_t @@ -136,18 +138,21 @@ dns_tkeyctx_destroy(dns_tkeyctx_t **tctxp) *tctxp = NULL; mctx = tctx->mctx; - if (tctx->dhkey != NULL) + if (tctx->dhkey != NULL) { dst_key_free(&tctx->dhkey); + } if (tctx->domain != NULL) { - if (dns_name_dynamic(tctx->domain)) + if (dns_name_dynamic(tctx->domain)) { dns_name_free(tctx->domain, mctx); + } isc_mem_put(mctx, tctx->domain, sizeof(dns_name_t)); } if (tctx->gssapi_keytab != NULL) { isc_mem_free(mctx, tctx->gssapi_keytab); } - if (tctx->gsscred != NULL) + if (tctx->gsscred != NULL) { dst_gssapi_releasecred(&tctx->gsscred); + } isc_mem_putanddetach(&mctx, tctx, sizeof(dns_tkeyctx_t)); } @@ -200,14 +205,16 @@ failure: } dns_message_puttemprdata(msg, &newrdata); } - if (newname != NULL) + if (newname != NULL) { dns_message_puttempname(msg, &newname); + } if (newset != NULL) { dns_rdataset_disassociate(newset); dns_message_puttemprdataset(msg, &newset); } - if (newlist != NULL) + if (newlist != NULL) { dns_message_puttemprdatalist(msg, &newlist); + } return (result); } @@ -383,8 +390,9 @@ process_dhtkey(dns_message_t *msg, dns_name_t *signer, dns_name_t *name, keyset = NULL; result = dns_message_findtype(keyname, dns_rdatatype_key, 0, &keyset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } for (result = dns_rdataset_first(keyset); result == ISC_R_SUCCESS && !found_key; @@ -402,8 +410,9 @@ process_dhtkey(dns_message_t *msg, dns_name_t *signer, dns_name_t *name, found_key = true; ttl = keyset->ttl; break; - } else + } else { found_incompatible = true; + } } dst_key_free(&pubkey); dns_rdata_reset(&keyrdata); @@ -476,14 +485,18 @@ process_dhtkey(dns_message_t *msg, dns_name_t *signer, dns_name_t *name, return (ISC_R_SUCCESS); failure: - if (!ISC_LIST_EMPTY(*namelist)) + if (!ISC_LIST_EMPTY(*namelist)) { free_namelist(msg, namelist); - if (shared != NULL) + } + if (shared != NULL) { isc_buffer_free(&shared); - if (pubkey != NULL) + } + if (pubkey != NULL) { dst_key_free(&pubkey); - if (randomdata != NULL) + } + if (randomdata != NULL) { isc_mem_put(tkeyout->mctx, randomdata, TKEY_RANDOM_AMOUNT); + } return (result); } @@ -531,8 +544,9 @@ process_gsstkey(dns_message_t *msg, dns_name_t *name, dns_rdata_tkey_t *tkeyin, intoken.length = tkeyin->keylen; result = dns_tsigkey_find(&tsigkey, name, &tkeyin->algorithm, ring); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { gss_ctx = dst_key_getgssctx(tsigkey->key); + } principal = dns_fixedname_initname(&fixed); @@ -543,15 +557,17 @@ process_gsstkey(dns_message_t *msg, dns_name_t *name, dns_rdata_tkey_t *tkeyin, &intoken, &outtoken, &gss_ctx, principal, tctx->mctx); if (result == DNS_R_INVALIDTKEY) { - if (tsigkey != NULL) + if (tsigkey != NULL) { dns_tsigkey_detach(&tsigkey); + } tkeyout->error = dns_tsigerror_badkey; tkey_log("process_gsstkey(): dns_tsigerror_badkey"); /* XXXSRA */ return (ISC_R_SUCCESS); } - if (result != DNS_R_CONTINUE && result != ISC_R_SUCCESS) + if (result != DNS_R_CONTINUE && result != ISC_R_SUCCESS) { goto failure; + } /* * XXXDCL Section 4.1.3: Limit GSS_S_CONTINUE_NEEDED to 10 times. */ @@ -565,7 +581,7 @@ process_gsstkey(dns_message_t *msg, dns_name_t *name, dns_rdata_tkey_t *tkeyin, } else if (tsigkey == NULL) { #ifdef GSSAPI OM_uint32 gret, minor, lifetime; -#endif +#endif /* ifdef GSSAPI */ uint32_t expire; RETERR(dst_key_fromgssapi(name, gss_ctx, ring->mctx, &dstkey, @@ -577,9 +593,10 @@ process_gsstkey(dns_message_t *msg, dns_name_t *name, dns_rdata_tkey_t *tkeyin, expire = now + 3600; #ifdef GSSAPI gret = gss_context_time(&minor, gss_ctx, &lifetime); - if (gret == GSS_S_COMPLETE && now + lifetime < expire) + if (gret == GSS_S_COMPLETE && now + lifetime < expire) { expire = now + lifetime; -#endif + } +#endif /* ifdef GSSAPI */ RETERR(dns_tsigkey_createfromkey( name, &tkeyin->algorithm, dstkey, true, principal, now, expire, ring->mctx, ring, &tsigkey)); @@ -623,14 +640,17 @@ process_gsstkey(dns_message_t *msg, dns_name_t *name, dns_rdata_tkey_t *tkeyin, return (ISC_R_SUCCESS); failure: - if (tsigkey != NULL) + if (tsigkey != NULL) { dns_tsigkey_detach(&tsigkey); + } - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_free(&dstkey); + } - if (outtoken != NULL) + if (outtoken != NULL) { isc_buffer_free(&outtoken); + } tkey_log("process_gsstkey(): %s", isc_result_totext(result)); /* XXXSRA */ @@ -701,8 +721,9 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, * Interpret the question section. */ result = dns_message_firstname(msg, DNS_SECTION_QUESTION); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (DNS_R_FORMERR); + } qname = NULL; dns_message_currentname(msg, DNS_SECTION_QUESTION, &qname); @@ -761,8 +782,9 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, result = DNS_R_FORMERR; goto failure; } - } else + } else { signer = &tsigner; + } tkeyout.common.rdclass = tkeyin.common.rdclass; tkeyout.common.rdtype = tkeyin.common.rdtype; @@ -822,21 +844,24 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, isc_buffer_init(&b, randomtext, sizeof(randomtext)); isc_buffer_add(&b, sizeof(randomtext)); result = dns_name_fromtext(keyname, &b, NULL, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } if (tkeyin.mode == DNS_TKEYMODE_GSSAPI) { /* Yup. This is a hack */ result = dns_name_concatenate(keyname, dns_rootname, keyname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } else { result = dns_name_concatenate(keyname, tctx->domain, keyname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } result = dns_tsigkey_find(&tsigkey, keyname, NULL, ring); @@ -845,10 +870,12 @@ dns_tkey_processquery(dns_message_t *msg, dns_tkeyctx_t *tctx, tkeyout.error = dns_tsigerror_badname; dns_tsigkey_detach(&tsigkey); goto failure_with_tkey; - } else if (result != ISC_R_NOTFOUND) + } else if (result != ISC_R_NOTFOUND) { goto failure; - } else + } + } else { keyname = qname; + } switch (tkeyin.mode) { case DNS_TKEYMODE_DIFFIEHELLMAN: @@ -887,12 +914,15 @@ failure_with_tkey: freetkeyin = false; } - if (tkeyout.key != NULL) + if (tkeyout.key != NULL) { isc_mem_put(tkeyout.mctx, tkeyout.key, tkeyout.keylen); - if (tkeyout.other != NULL) + } + if (tkeyout.other != NULL) { isc_mem_put(tkeyout.mctx, tkeyout.other, tkeyout.otherlen); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } RETERR(add_rdata_to_list(msg, keyname, &rdata, 0, &namelist)); @@ -910,10 +940,12 @@ failure_with_tkey: failure: - if (freetkeyin) + if (freetkeyin) { dns_rdata_freestruct(&tkeyin); - if (!ISC_LIST_EMPTY(namelist)) + } + if (!ISC_LIST_EMPTY(namelist)) { free_namelist(msg, &namelist); + } return (result); } @@ -974,29 +1006,35 @@ buildquery(dns_message_t *msg, const dns_name_t *name, dns_rdata_tkey_t *tkey, * Windows 2000 needs this in the answer section, not the additional * section where the RFC specifies. */ - if (win2k) + if (win2k) { dns_message_addname(msg, aname, DNS_SECTION_ANSWER); - else + } else { dns_message_addname(msg, aname, DNS_SECTION_ADDITIONAL); + } dns_message_takebuffer(msg, &anamebuf); return (ISC_R_SUCCESS); failure: - if (qname != NULL) + if (qname != NULL) { dns_message_puttempname(msg, &qname); - if (aname != NULL) + } + if (aname != NULL) { dns_message_puttempname(msg, &aname); + } if (question != NULL) { dns_rdataset_disassociate(question); dns_message_puttemprdataset(msg, &question); } - if (dynbuf != NULL) + if (dynbuf != NULL) { isc_buffer_free(&dynbuf); - if (qnamebuf != NULL) + } + if (qnamebuf != NULL) { isc_buffer_free(&qnamebuf); - if (anamebuf != NULL) + } + if (anamebuf != NULL) { isc_buffer_free(&anamebuf); + } return (result); } @@ -1032,9 +1070,9 @@ dns_tkey_builddhquery(dns_message_t *msg, dst_key_t *key, tkey.inception = now; tkey.expire = now + lifetime; tkey.mode = DNS_TKEYMODE_DIFFIEHELLMAN; - if (nonce != NULL) + if (nonce != NULL) { isc_buffer_usedregion(nonce, &r); - else { + } else { r.base = NULL; r.length = 0; } @@ -1070,8 +1108,9 @@ dns_tkey_builddhquery(dns_message_t *msg, dst_key_t *key, failure: - if (dynbuf != NULL) + if (dynbuf != NULL) { isc_buffer_free(&dynbuf); + } return (result); } @@ -1098,8 +1137,9 @@ dns_tkey_buildgssquery(dns_message_t *msg, const dns_name_t *name, isc_buffer_init(&token, array, sizeof(array)); result = dst_gssapi_initctx(gname, NULL, &token, context, mctx, err_message); - if (result != DNS_R_CONTINUE && result != ISC_R_SUCCESS) + if (result != DNS_R_CONTINUE && result != ISC_R_SUCCESS) { return (result); + } tkey.common.rdclass = dns_rdataclass_any; tkey.common.rdtype = dns_rdatatype_tkey; @@ -1107,10 +1147,11 @@ dns_tkey_buildgssquery(dns_message_t *msg, const dns_name_t *name, tkey.mctx = NULL; dns_name_init(&tkey.algorithm, NULL); - if (win2k) + if (win2k) { dns_name_clone(DNS_TSIG_GSSAPIMS_NAME, &tkey.algorithm); - else + } else { dns_name_clone(DNS_TSIG_GSSAPI_NAME, &tkey.algorithm); + } isc_stdtime_get(&now); tkey.inception = now; @@ -1164,15 +1205,17 @@ find_tkey(dns_message_t *msg, dns_name_t **name, dns_rdata_t *rdata, &tkeyset); if (result == ISC_R_SUCCESS) { result = dns_rdataset_first(tkeyset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_current(tkeyset, rdata); return (ISC_R_SUCCESS); } result = dns_message_nextname(msg, section); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { return (ISC_R_NOTFOUND); + } return (result); } @@ -1199,11 +1242,13 @@ dns_tkey_processdhresponse(dns_message_t *qmsg, dns_message_t *rmsg, REQUIRE(key != NULL); REQUIRE(dst_key_alg(key) == DNS_KEYALG_DH); REQUIRE(dst_key_isprivate(key)); - if (outkey != NULL) + if (outkey != NULL) { REQUIRE(*outkey == NULL); + } - if (rmsg->rcode != dns_rcode_noerror) + if (rmsg->rcode != dns_rcode_noerror) { return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); RETERR(dns_rdata_tostruct(&rtkeyrdata, &rtkey, NULL)); freertkey = true; @@ -1239,8 +1284,9 @@ dns_tkey_processdhresponse(dns_message_t *qmsg, dns_message_t *rmsg, theirkeyname = NULL; dns_message_currentname(rmsg, DNS_SECTION_ANSWER, &theirkeyname); - if (dns_name_equal(theirkeyname, ourkeyname)) + if (dns_name_equal(theirkeyname, ourkeyname)) { goto next; + } theirkeyset = NULL; result = dns_message_findtype(theirkeyname, dns_rdatatype_key, 0, &theirkeyset); @@ -1272,9 +1318,9 @@ dns_tkey_processdhresponse(dns_message_t *qmsg, dns_message_t *rmsg, r.base = rtkey.key; r.length = rtkey.keylen; - if (nonce != NULL) + if (nonce != NULL) { isc_buffer_usedregion(nonce, &r2); - else { + } else { r2.base = NULL; r2.length = 0; } @@ -1290,14 +1336,17 @@ dns_tkey_processdhresponse(dns_message_t *qmsg, dns_message_t *rmsg, return (result); failure: - if (shared != NULL) + if (shared != NULL) { isc_buffer_free(&shared); + } - if (theirkey != NULL) + if (theirkey != NULL) { dst_key_free(&theirkey); + } - if (freertkey) + if (freertkey) { dns_rdata_freestruct(&rtkey); + } return (result); } @@ -1321,11 +1370,13 @@ dns_tkey_processgssresponse(dns_message_t *qmsg, dns_message_t *rmsg, REQUIRE(rmsg != NULL); REQUIRE(gname != NULL); REQUIRE(ring != NULL); - if (outkey != NULL) + if (outkey != NULL) { REQUIRE(*outkey == NULL); + } - if (rmsg->rcode != dns_rcode_noerror) + if (rmsg->rcode != dns_rcode_noerror) { return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); RETERR(dns_rdata_tostruct(&rtkeyrdata, &rtkey, NULL)); @@ -1336,11 +1387,13 @@ dns_tkey_processgssresponse(dns_message_t *qmsg, dns_message_t *rmsg, */ result = find_tkey(qmsg, &tkeyname, &qtkeyrdata, DNS_SECTION_ADDITIONAL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = find_tkey(qmsg, &tkeyname, &qtkeyrdata, DNS_SECTION_ANSWER); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } RETERR(dns_rdata_tostruct(&qtkeyrdata, &qtkey, NULL)); @@ -1375,8 +1428,9 @@ failure: /* * XXXSRA This probably leaks memory from rtkey and qtkey. */ - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_free(&dstkey); + } return (result); } @@ -1393,8 +1447,9 @@ dns_tkey_processdeleteresponse(dns_message_t *qmsg, dns_message_t *rmsg, REQUIRE(qmsg != NULL); REQUIRE(rmsg != NULL); - if (rmsg->rcode != dns_rcode_noerror) + if (rmsg->rcode != dns_rcode_noerror) { return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); RETERR(dns_rdata_tostruct(&rtkeyrdata, &rtkey, NULL)); @@ -1451,22 +1506,25 @@ dns_tkey_gssnegotiate(dns_message_t *qmsg, dns_message_t *rmsg, REQUIRE(qmsg != NULL); REQUIRE(rmsg != NULL); REQUIRE(server != NULL); - if (outkey != NULL) + if (outkey != NULL) { REQUIRE(*outkey == NULL); + } - if (rmsg->rcode != dns_rcode_noerror) + if (rmsg->rcode != dns_rcode_noerror) { return (ISC_RESULTCLASS_DNSRCODE + rmsg->rcode); + } RETERR(find_tkey(rmsg, &tkeyname, &rtkeyrdata, DNS_SECTION_ANSWER)); RETERR(dns_rdata_tostruct(&rtkeyrdata, &rtkey, NULL)); freertkey = true; - if (win2k == true) + if (win2k == true) { RETERR(find_tkey(qmsg, &tkeyname, &qtkeyrdata, DNS_SECTION_ANSWER)); - else + } else { RETERR(find_tkey(qmsg, &tkeyname, &qtkeyrdata, DNS_SECTION_ADDITIONAL)); + } RETERR(dns_rdata_tostruct(&qtkeyrdata, &qtkey, NULL)); @@ -1484,8 +1542,9 @@ dns_tkey_gssnegotiate(dns_message_t *qmsg, dns_message_t *rmsg, result = dst_gssapi_initctx(server, &intoken, &outtoken, context, ring->mctx, err_message); - if (result != DNS_R_CONTINUE && result != ISC_R_SUCCESS) + if (result != DNS_R_CONTINUE && result != ISC_R_SUCCESS) { return (result); + } if (result == DNS_R_CONTINUE) { dns_fixedname_t fixed; @@ -1500,10 +1559,11 @@ dns_tkey_gssnegotiate(dns_message_t *qmsg, dns_message_t *rmsg, tkey.mctx = NULL; dns_name_init(&tkey.algorithm, NULL); - if (win2k) + if (win2k) { dns_name_clone(DNS_TSIG_GSSAPIMS_NAME, &tkey.algorithm); - else + } else { dns_name_clone(DNS_TSIG_GSSAPI_NAME, &tkey.algorithm); + } tkey.inception = qtkey.inception; tkey.expire = qtkey.expire; @@ -1541,9 +1601,11 @@ failure: /* * XXXSRA This probably leaks memory from qtkey. */ - if (freertkey) + if (freertkey) { dns_rdata_freestruct(&rtkey); - if (dstkey != NULL) + } + if (dstkey != NULL) { dst_key_free(&dstkey); + } return (result); } diff --git a/lib/dns/tsig.c b/lib/dns/tsig.c index 3f69730da4..979b7afa32 100644 --- a/lib/dns/tsig.c +++ b/lib/dns/tsig.c @@ -46,7 +46,7 @@ #ifndef DNS_TSIG_MAXGENERATEDKEYS #define DNS_TSIG_MAXGENERATEDKEYS 4096 -#endif +#endif /* ifndef DNS_TSIG_MAXGENERATEDKEYS */ #define is_response(msg) ((msg->flags & DNS_MESSAGEFLAG_QR) != 0) @@ -145,8 +145,9 @@ tsig_log(dns_tsigkey_t *key, int level, const char *fmt, ...) char namestr[DNS_NAME_FORMATSIZE]; char creatorstr[DNS_NAME_FORMATSIZE]; - if (isc_log_wouldlog(dns_lctx, level) == false) + if (isc_log_wouldlog(dns_lctx, level) == false) { return; + } if (key != NULL) { dns_name_format(&key->name, namestr, sizeof(namestr)); } else { @@ -234,8 +235,9 @@ keyring_add(dns_tsig_keyring_t *ring, const dns_name_t *name, * recently used key if there are too many keys on the list. */ ISC_LIST_APPEND(ring->lru, tkey, link); - if (ring->generated++ > ring->maxgenerated) + if (ring->generated++ > ring->maxgenerated) { remove_fromring(ISC_LIST_HEAD(ring->lru)); + } } RWUNLOCK(&ring->lock, isc_rwlocktype_write); @@ -295,18 +297,22 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm, tkey->creator = isc_mem_get(mctx, sizeof(dns_name_t)); dns_name_init(tkey->creator, NULL); dns_name_dup(creator, mctx, tkey->creator); - } else + } else { tkey->creator = NULL; + } tkey->key = NULL; - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_attach(dstkey, &tkey->key); + } tkey->ring = ring; - if (key != NULL) + if (key != NULL) { refs = 1; - if (ring != NULL) + } + if (ring != NULL) { refs++; + } isc_refcount_init(&tkey->refs, refs); @@ -321,8 +327,9 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm, if (ring != NULL) { ret = keyring_add(ring, name, tkey); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_refs; + } } /* @@ -338,8 +345,9 @@ dns_tsigkey_createfromkey(const dns_name_t *name, const dns_name_t *algorithm, namestr); } - if (key != NULL) + if (key != NULL) { *key = tkey; + } return (ISC_R_SUCCESS); @@ -350,8 +358,9 @@ cleanup_refs: } isc_refcount_destroy(&tkey->refs); - if (tkey->key != NULL) + if (tkey->key != NULL) { dst_key_free(&tkey->key); + } if (tkey->creator != NULL) { dns_name_free(tkey->creator, mctx); isc_mem_put(mctx, tkey->creator, sizeof(dns_name_t)); @@ -359,8 +368,9 @@ cleanup_refs: if (dns__tsig_algallocated(tkey->algorithm)) { dns_name_t *tmpname; DE_CONST(tkey->algorithm, tmpname); - if (dns_name_dynamic(tmpname)) + if (dns_name_dynamic(tmpname)) { dns_name_free(tmpname, mctx); + } isc_mem_put(mctx, tmpname, sizeof(dns_name_t)); } cleanup_name: @@ -508,50 +518,59 @@ restore_key(dns_tsig_keyring_t *ring, isc_stdtime_t now, FILE *fp) n = fscanf(fp, "%1023s %1023s %u %u %1023s %4095s\n", namestr, creatorstr, &inception, &expire, algorithmstr, keystr); - if (n == EOF) + if (n == EOF) { return (ISC_R_NOMORE); - if (n != 6) + } + if (n != 6) { return (ISC_R_FAILURE); + } - if (isc_serial_lt(expire, now)) + if (isc_serial_lt(expire, now)) { return (DNS_R_EXPIRED); + } name = dns_fixedname_initname(&fname); isc_buffer_init(&b, namestr, strlen(namestr)); isc_buffer_add(&b, strlen(namestr)); result = dns_name_fromtext(name, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } creator = dns_fixedname_initname(&fcreator); isc_buffer_init(&b, creatorstr, strlen(creatorstr)); isc_buffer_add(&b, strlen(creatorstr)); result = dns_name_fromtext(creator, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } algorithm = dns_fixedname_initname(&falgorithm); isc_buffer_init(&b, algorithmstr, strlen(algorithmstr)); isc_buffer_add(&b, strlen(algorithmstr)); result = dns_name_fromtext(algorithm, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dstalg = dns__tsig_algfromname(algorithm); - if (dstalg == 0) + if (dstalg == 0) { return (DNS_R_BADALG); + } result = dst_key_restore(name, dstalg, DNS_KEYOWNER_ENTITY, DNS_KEYPROTO_DNSSEC, dns_rdataclass_in, ring->mctx, keystr, &dstkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_tsigkey_createfromkey(name, algorithm, dstkey, true, creator, inception, expire, ring->mctx, ring, NULL); - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_free(&dstkey); + } return (result); } @@ -572,12 +591,14 @@ dump_key(dns_tsigkey_t *tkey, FILE *fp) dns_name_format(tkey->creator, creatorstr, sizeof(creatorstr)); dns_name_format(tkey->algorithm, algorithmstr, sizeof(algorithmstr)); result = dst_key_dump(tkey->key, tkey->mctx, &buffer, &length); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { fprintf(fp, "%s %s %u %u %s %.*s\n", namestr, creatorstr, tkey->inception, tkey->expire, algorithmstr, length, buffer); - if (buffer != NULL) + } + if (buffer != NULL) { isc_mem_put(tkey->mctx, buffer, length); + } } isc_result_t @@ -661,8 +682,9 @@ dns_tsigkey_create(const dns_name_t *name, const dns_name_t *algorithm, unsigned int dstalg = 0; REQUIRE(length >= 0); - if (length > 0) + if (length > 0) { REQUIRE(secret != NULL); + } dstalg = dns__tsig_algfromname(algorithm); if (dns__tsig_algvalid(dstalg)) { @@ -675,8 +697,9 @@ dns_tsigkey_create(const dns_name_t *name, const dns_name_t *algorithm, name, dstalg, DNS_KEYOWNER_ENTITY, DNS_KEYPROTO_DNSSEC, dns_rdataclass_in, &b, mctx, &dstkey); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } } else if (length > 0) { return (DNS_R_BADALG); @@ -685,8 +708,9 @@ dns_tsigkey_create(const dns_name_t *name, const dns_name_t *algorithm, result = dns_tsigkey_createfromkey(name, algorithm, dstkey, generated, creator, inception, expire, mctx, ring, key); - if (dstkey != NULL) + if (dstkey != NULL) { dst_key_free(&dstkey); + } return (result); } @@ -713,8 +737,9 @@ tsigkey_free(dns_tsigkey_t *key) dns_name_free(name, key->mctx); isc_mem_put(key->mctx, name, sizeof(dns_name_t)); } - if (key->key != NULL) + if (key->key != NULL) { dst_key_free(&key->key); + } if (key->creator != NULL) { dns_name_free(key->creator, key->mctx); isc_mem_put(key->mctx, key->creator, sizeof(dns_name_t)); @@ -799,10 +824,11 @@ dns_tsig_sign(dns_message_t *msg) isc_buffer_init(&databuf, data, sizeof(data)); - if (response) + if (response) { tsig.error = msg->querytsigstatus; - else + } else { tsig.error = dns_rcode_noerror; + } if (tsig.error != dns_tsigerror_badtime) { tsig.otherlen = 0; @@ -830,8 +856,9 @@ dns_tsig_sign(dns_message_t *msg) */ ret = dst_context_create(key->key, mctx, DNS_LOGCATEGORY_DNSSEC, true, 0, &ctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } /* * If this is a response, and if there was a TSIG in @@ -848,13 +875,15 @@ dns_tsig_sign(dns_message_t *msg) INSIST(msg->verified_sig); ret = dns_rdataset_first(msg->querytsig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } dns_rdataset_current(msg->querytsig, &querytsigrdata); ret = dns_rdata_tostruct(&querytsigrdata, &querytsig, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } isc_buffer_putuint16(&databuf, querytsig.siglen); if (isc_buffer_availablelength(&databuf) < querytsig.siglen) { @@ -865,8 +894,9 @@ dns_tsig_sign(dns_message_t *msg) querytsig.siglen); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } querytsig_ok = true; } @@ -877,8 +907,9 @@ dns_tsig_sign(dns_message_t *msg) dns_message_renderheader(msg, &headerbuf); isc_buffer_usedregion(&headerbuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest the remainder of the message. @@ -886,8 +917,9 @@ dns_tsig_sign(dns_message_t *msg) isc_buffer_usedregion(msg->buffer, &r); isc_region_consume(&r, DNS_MESSAGE_HEADERLEN); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } if (msg->tcp_continuation == 0) { /* @@ -895,21 +927,24 @@ dns_tsig_sign(dns_message_t *msg) */ dns_name_toregion(&key->name, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } isc_buffer_clear(&databuf); isc_buffer_putuint16(&databuf, dns_rdataclass_any); isc_buffer_putuint32(&databuf, 0); /* ttl */ isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } dns_name_toregion(&tsig.algorithm, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } } /* Digest the timesigned and fudge */ isc_buffer_clear(&databuf); @@ -920,8 +955,9 @@ dns_tsig_sign(dns_message_t *msg) isc_buffer_putuint16(&databuf, tsig.fudge); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } if (msg->tcp_continuation == 0) { /* @@ -933,8 +969,9 @@ dns_tsig_sign(dns_message_t *msg) isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest other data. @@ -943,44 +980,52 @@ dns_tsig_sign(dns_message_t *msg) r.length = tsig.otherlen; r.base = tsig.other; ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } } } ret = dst_key_sigsize(key->key, &sigsize); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } tsig.signature = isc_mem_get(mctx, sigsize); isc_buffer_init(&sigbuf, tsig.signature, sigsize); ret = dst_context_sign(ctx, &sigbuf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_signature; + } dst_context_destroy(&ctx); digestbits = dst_key_getbits(key->key); if (digestbits != 0) { unsigned int bytes = (digestbits + 7) / 8; - if (querytsig_ok && bytes < querytsig.siglen) + if (querytsig_ok && bytes < querytsig.siglen) { bytes = querytsig.siglen; - if (bytes > isc_buffer_usedlength(&sigbuf)) + } + if (bytes > isc_buffer_usedlength(&sigbuf)) { bytes = isc_buffer_usedlength(&sigbuf); + } tsig.siglen = bytes; - } else + } else { tsig.siglen = isc_buffer_usedlength(&sigbuf); + } } else { tsig.siglen = 0; tsig.signature = NULL; } ret = dns_message_gettemprdata(msg, &rdata); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_signature; + } isc_buffer_allocate(msg->mctx, &dynbuf, 512); ret = dns_rdata_fromstruct(rdata, dns_rdataclass_any, dns_rdatatype_tsig, &tsig, dynbuf); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_dynbuf; + } dns_message_takebuffer(msg, &dynbuf); @@ -991,19 +1036,22 @@ dns_tsig_sign(dns_message_t *msg) owner = NULL; ret = dns_message_gettempname(msg, &owner); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_rdata; + } dns_name_init(owner, NULL); dns_name_dup(&key->name, msg->mctx, owner); datalist = NULL; ret = dns_message_gettemprdatalist(msg, &datalist); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_owner; + } dataset = NULL; ret = dns_message_gettemprdataset(msg, &dataset); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_rdatalist; + } datalist->rdclass = dns_rdataclass_any; datalist->type = dns_rdatatype_tsig; ISC_LIST_APPEND(datalist->rdata, rdata, link); @@ -1027,11 +1075,13 @@ cleanup_dynbuf: cleanup_rdata: dns_message_puttemprdata(msg, &rdata); cleanup_signature: - if (tsig.signature != NULL) + if (tsig.signature != NULL) { isc_mem_put(mctx, tsig.signature, sigsize); + } cleanup_context: - if (ctx != NULL) + if (ctx != NULL) { dst_context_destroy(&ctx); + } return (ret); } @@ -1069,23 +1119,26 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, msg->tsigstatus = dns_tsigerror_badsig; if (msg->tcp_continuation) { - if (tsigkey == NULL || msg->querytsig == NULL) + if (tsigkey == NULL || msg->querytsig == NULL) { return (DNS_R_UNEXPECTEDTSIG); + } return (tsig_verify_tcp(source, msg)); } /* * There should be a TSIG record... */ - if (msg->tsig == NULL) + if (msg->tsig == NULL) { return (DNS_R_EXPECTEDTSIG); + } /* * If this is a response and there's no key or query TSIG, there * shouldn't be one on the response. */ - if (response && (tsigkey == NULL || msg->querytsig == NULL)) + if (response && (tsigkey == NULL || msg->querytsig == NULL)) { return (DNS_R_UNEXPECTEDTSIG); + } mctx = msg->mctx; @@ -1096,29 +1149,37 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, keyname = msg->tsigname; ret = dns_rdataset_first(msg->tsig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } dns_rdataset_current(msg->tsig, &rdata); ret = dns_rdata_tostruct(&rdata, &tsig, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } dns_rdata_reset(&rdata); if (response) { ret = dns_rdataset_first(msg->querytsig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } dns_rdataset_current(msg->querytsig, &rdata); ret = dns_rdata_tostruct(&rdata, &querytsig, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } } #if defined(__clang__) && (__clang_major__ < 3 || \ (__clang_major__ == 3 && __clang_minor__ < 2) || \ (__clang_major__ == 4 && __clang_minor__ < 2)) /* false positive: http://llvm.org/bugs/show_bug.cgi?id=14461 */ - else + else { memset(&querytsig, 0, sizeof(querytsig)); -#endif + } +#endif /* if defined(__clang__) && (__clang_major__ < 3 || (__clang_major__ == \ + * 3 \ + * && __clang_minor__ < 2) || (__clang_major__ == 4 && __clang_minor__ \ + * < 2)) */ /* * Do the key name and algorithm match that of the query? @@ -1142,19 +1203,22 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, */ if (tsigkey == NULL) { ret = ISC_R_NOTFOUND; - if (ring1 != NULL) + if (ring1 != NULL) { ret = dns_tsigkey_find(&tsigkey, keyname, &tsig.algorithm, ring1); - if (ret == ISC_R_NOTFOUND && ring2 != NULL) + } + if (ret == ISC_R_NOTFOUND && ring2 != NULL) { ret = dns_tsigkey_find(&tsigkey, keyname, &tsig.algorithm, ring2); + } if (ret != ISC_R_SUCCESS) { msg->tsigstatus = dns_tsigerror_badkey; ret = dns_tsigkey_create(keyname, &tsig.algorithm, NULL, 0, false, NULL, now, now, mctx, NULL, &msg->tsigkey); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } tsig_log(msg->tsigkey, 2, "unknown key"); return (DNS_R_TSIGVERIFYFAILURE); } @@ -1168,8 +1232,9 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, */ alg = dst_key_alg(key); ret = dst_key_sigsize(key, &siglen); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } if (dns__tsig_algvalid(alg)) { if (tsig.siglen > siglen) { tsig_log(msg->tsigkey, 2, "signature length too big"); @@ -1191,22 +1256,25 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, &ctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } if (response) { isc_buffer_init(&databuf, data, sizeof(data)); isc_buffer_putuint16(&databuf, querytsig.siglen); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } if (querytsig.siglen > 0) { r.length = querytsig.siglen; r.base = querytsig.signature; ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } } } @@ -1237,8 +1305,9 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, header_r.base = (unsigned char *)header; header_r.length = DNS_MESSAGE_HEADERLEN; ret = dst_context_adddata(ctx, &header_r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest all non-TSIG records. @@ -1247,32 +1316,36 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, r.base = source_r.base + DNS_MESSAGE_HEADERLEN; r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN; ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest the key name. */ dns_name_toregion(&tsigkey->name, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } isc_buffer_init(&databuf, data, sizeof(data)); isc_buffer_putuint16(&databuf, tsig.common.rdclass); isc_buffer_putuint32(&databuf, msg->tsig->ttl); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest the key algorithm. */ dns_name_toregion(tsigkey->algorithm, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } isc_buffer_clear(&databuf); isc_buffer_putuint48(&databuf, tsig.timesigned); @@ -1281,15 +1354,17 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, isc_buffer_putuint16(&databuf, tsig.otherlen); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } if (tsig.otherlen > 0) { r.base = tsig.other; r.length = tsig.otherlen; ret = dst_context_adddata(ctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } } ret = dst_context_verify(ctx, &sig_r); @@ -1352,10 +1427,11 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, if (tsig.error != dns_rcode_noerror) { msg->tsigstatus = tsig.error; - if (tsig.error == dns_tsigerror_badtime) + if (tsig.error == dns_tsigerror_badtime) { ret = DNS_R_CLOCKSKEW; - else + } else { ret = DNS_R_TSIGERRORSET; + } goto cleanup_context; } @@ -1363,8 +1439,9 @@ dns_tsig_verify(isc_buffer_t *source, dns_message_t *msg, ret = ISC_R_SUCCESS; cleanup_context: - if (ctx != NULL) + if (ctx != NULL) { dst_context_destroy(&ctx); + } return (ret); } @@ -1398,8 +1475,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) msg->verified_sig = 0; msg->tsigstatus = dns_tsigerror_badsig; - if (!is_response(msg)) + if (!is_response(msg)) { return (DNS_R_EXPECTEDRESPONSE); + } mctx = msg->mctx; @@ -1410,12 +1488,14 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) * Extract and parse the previous TSIG */ ret = dns_rdataset_first(msg->querytsig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } dns_rdataset_current(msg->querytsig, &rdata); ret = dns_rdata_tostruct(&rdata, &querytsig, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } dns_rdata_reset(&rdata); /* @@ -1426,12 +1506,14 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) keyname = msg->tsigname; ret = dns_rdataset_first(msg->tsig); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_querystruct; + } dns_rdataset_current(msg->tsig, &rdata); ret = dns_rdata_tostruct(&rdata, &tsig, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_querystruct; + } /* * Do the key name and algorithm match that of the query? @@ -1450,8 +1532,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) */ alg = dst_key_alg(key); ret = dst_key_sigsize(key, &siglen); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_querystruct; + } if (dns__tsig_algvalid(alg)) { if (tsig.siglen > siglen) { tsig_log(tsigkey, 2, @@ -1473,8 +1556,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) if (msg->tsigctx == NULL) { ret = dst_context_create(key, mctx, DNS_LOGCATEGORY_DNSSEC, false, 0, &msg->tsigctx); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_querystruct; + } /* * Digest the length of the query signature @@ -1483,8 +1567,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) isc_buffer_putuint16(&databuf, querytsig.siglen); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(msg->tsigctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest the data of the query signature @@ -1493,8 +1578,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) r.length = querytsig.siglen; r.base = querytsig.signature; ret = dst_context_adddata(msg->tsigctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } } } @@ -1534,21 +1620,24 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) header_r.base = (unsigned char *)header; header_r.length = DNS_MESSAGE_HEADERLEN; ret = dst_context_adddata(msg->tsigctx, &header_r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest all non-TSIG records. */ isc_buffer_usedregion(source, &source_r); r.base = source_r.base + DNS_MESSAGE_HEADERLEN; - if (has_tsig) + if (has_tsig) { r.length = msg->sigstart - DNS_MESSAGE_HEADERLEN; - else + } else { r.length = source_r.length - DNS_MESSAGE_HEADERLEN; + } ret = dst_context_adddata(msg->tsigctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } /* * Digest the time signed and fudge. @@ -1559,8 +1648,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) isc_buffer_putuint16(&databuf, tsig.fudge); isc_buffer_usedregion(&databuf, &r); ret = dst_context_adddata(msg->tsigctx, &r); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } sig_r.base = tsig.signature; sig_r.length = tsig.siglen; @@ -1617,8 +1707,9 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) alg = dst_key_alg(key); ret = dst_key_sigsize(key, &siglen); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto cleanup_context; + } if (dns__tsig_algvalid(alg)) { uint16_t digestbits = dst_key_getbits(key); @@ -1643,10 +1734,11 @@ tsig_verify_tcp(isc_buffer_t *source, dns_message_t *msg) if (tsig.error != dns_rcode_noerror) { msg->tsigstatus = tsig.error; - if (tsig.error == dns_tsigerror_badtime) + if (tsig.error == dns_tsigerror_badtime) { ret = DNS_R_CLOCKSKEW; - else + } else { ret = DNS_R_TSIGERRORSET; + } goto cleanup_context; } } @@ -1719,7 +1811,7 @@ dns_tsigkey_find(dns_tsigkey_t **tsigkey, const dns_name_t *name, adjust_lru(key); return (ISC_R_NOTFOUND); } -#endif +#endif /* if 0 */ isc_refcount_increment(&key->refs); RWUNLOCK(&ring->lock, isc_rwlocktype_read); adjust_lru(key); @@ -1738,8 +1830,9 @@ free_tsignode(void *node, void *_unused) key = node; if (key->generated) { - if (ISC_LINK_LINKED(key, link)) + if (ISC_LINK_LINKED(key, link)) { ISC_LIST_UNLINK(key->ring->lru, key, link); + } } dns_tsigkey_detach(&key); } @@ -1789,8 +1882,9 @@ dns_tsigkeyring_add(dns_tsig_keyring_t *ring, const dns_name_t *name, isc_result_t result; result = keyring_add(ring, name, tkey); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_refcount_increment(&tkey->refs); + } return (result); } @@ -1831,9 +1925,11 @@ dns_keyring_restore(dns_tsig_keyring_t *ring, FILE *fp) isc_stdtime_get(&now); do { result = restore_key(ring, now, fp); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { return; - if (result == DNS_R_BADALG || result == DNS_R_EXPIRED) + } + if (result == DNS_R_BADALG || result == DNS_R_EXPIRED) { result = ISC_R_SUCCESS; + } } while (result == ISC_R_SUCCESS); } diff --git a/lib/dns/ttl.c b/lib/dns/ttl.c index a2d15ae540..0b3b67ec19 100644 --- a/lib/dns/ttl.c +++ b/lib/dns/ttl.c @@ -32,7 +32,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) static isc_result_t @@ -49,16 +49,18 @@ ttlfmt(unsigned int t, const char *s, bool verbose, bool space, unsigned int len; isc_region_t region; - if (verbose) + if (verbose) { len = snprintf(tmp, sizeof(tmp), "%s%u %s%s", space ? " " : "", t, s, t == 1 ? "" : "s"); - else + } else { len = snprintf(tmp, sizeof(tmp), "%u%c", t, s[0]); + } INSIST(len + 1 <= sizeof(tmp)); isc_buffer_availableregion(target, ®ion); - if (len > region.length) + if (len > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, tmp, len); isc_buffer_add(target, len); @@ -140,8 +142,9 @@ dns_ttl_fromtext(isc_textregion_t *source, uint32_t *ttl) isc_result_t result; result = bind_ttl(source, ttl); - if (result != ISC_R_SUCCESS && result != ISC_R_RANGE) + if (result != ISC_R_SUCCESS && result != ISC_R_RANGE) { result = DNS_R_BADTTL; + } return (result); } @@ -158,8 +161,9 @@ bind_ttl(isc_textregion_t *source, uint32_t *ttl) * Copy the buffer as it may not be NULL terminated. * No legal counter / ttl is longer that 63 characters. */ - if (source->length > sizeof(buf) - 1) + if (source->length > sizeof(buf) - 1) { return (DNS_R_SYNTAX); + } /* Copy source->length bytes and NUL terminate. */ snprintf(buf, sizeof(buf), "%.*s", (int)source->length, source->base); s = buf; @@ -168,13 +172,15 @@ bind_ttl(isc_textregion_t *source, uint32_t *ttl) isc_result_t result; char *np = nbuf; - while (*s != '\0' && isdigit((unsigned char)*s)) + while (*s != '\0' && isdigit((unsigned char)*s)) { *np++ = *s++; + } *np++ = '\0'; INSIST(np - nbuf <= (int)sizeof(nbuf)); result = isc_parse_uint32(&n, nbuf, 10); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (DNS_R_SYNTAX); + } switch (*s) { case 'w': case 'W': @@ -203,8 +209,9 @@ bind_ttl(isc_textregion_t *source, uint32_t *ttl) break; case '\0': /* Plain number? */ - if (tmp != 0ULL) + if (tmp != 0ULL) { return (DNS_R_SYNTAX); + } tmp = n; break; default: @@ -212,8 +219,9 @@ bind_ttl(isc_textregion_t *source, uint32_t *ttl) } } while (*s != '\0'); - if (tmp > 0xffffffffULL) + if (tmp > 0xffffffffULL) { return (ISC_R_RANGE); + } *ttl = (uint32_t)(tmp & 0xffffffffUL); return (ISC_R_SUCCESS); diff --git a/lib/dns/update.c b/lib/dns/update.c index bd884c122e..f8e7301027 100644 --- a/lib/dns/update.c +++ b/lib/dns/update.c @@ -207,11 +207,13 @@ update_log(dns_update_log_t *callback, dns_zone_t *zone, int level, va_list ap; char message[4096]; - if (callback == NULL) + if (callback == NULL) { return; + } - if (isc_log_wouldlog(dns_lctx, level) == false) + if (isc_log_wouldlog(dns_lctx, level) == false) { return; + } va_start(ap, fmt); vsnprintf(message, sizeof(message), fmt, ap); @@ -270,8 +272,9 @@ update_one_rr(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff, dns_difftuple_t *tuple = NULL; isc_result_t result; result = dns_difftuple_create(diff->mctx, op, name, ttl, rdata, &tuple); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (do_one_tuple(&tuple, db, ver, diff)); } @@ -330,11 +333,13 @@ foreach_node_rr_action(void *data, dns_rdataset_t *rdataset) dns_rdataset_current(rdataset, &rr.rdata); rr.ttl = rdataset->ttl; result = (*ctx->rr_action)(ctx->rr_action_data, &rr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } return (ISC_R_SUCCESS); } @@ -355,15 +360,18 @@ foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, node = NULL; result = dns_db_findnode(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } iter = NULL; result = dns_db_allrdatasets(db, node, ver, (isc_stdtime_t)0, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(iter)) { @@ -375,11 +383,13 @@ foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = (*action)(action_data, &rdataset); dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iterator; + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup_iterator: dns_rdatasetiter_destroy(&iter); @@ -426,20 +436,24 @@ foreach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_dbnode_t * node; dns_rdataset_t rdataset; - if (type == dns_rdatatype_any) + if (type == dns_rdatatype_any) { return (foreach_node_rr(db, ver, name, rr_action, rr_action_data)); + } node = NULL; if (type == dns_rdatatype_nsec3 || - (type == dns_rdatatype_rrsig && covers == dns_rdatatype_nsec3)) + (type == dns_rdatatype_rrsig && covers == dns_rdatatype_nsec3)) { result = dns_db_findnsec3node(db, name, false, &node); - else + } else { result = dns_db_findnode(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + } + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, ver, type, covers, @@ -448,8 +462,9 @@ foreach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = ISC_R_SUCCESS; goto cleanup_node; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -457,11 +472,13 @@ foreach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_rdataset_current(&rdataset, &rr.rdata); rr.ttl = rdataset.ttl; result = (*rr_action)(rr_action_data, &rr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rdataset; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto cleanup_rdataset; + } result = ISC_R_SUCCESS; cleanup_rdataset: @@ -617,11 +634,13 @@ temp_order(const void *av, const void *bv) dns_difftuple_t const * b = *bp; int r; r = dns_name_compare(&a->name, &b->name); - if (r != 0) + if (r != 0) { return (r); + } r = (b->rdata.type - a->rdata.type); - if (r != 0) + if (r != 0) { return (r); + } r = dns_rdata_casecompare(&a->rdata, &b->rdata); return (r); } @@ -750,15 +769,18 @@ namelist_append_subdomain(dns_db_t *db, dns_name_t *name, dns_diff_t *affected) dns_dbnode_t *node = NULL; CHECK(dns_dbiterator_current(dbit, &node, child)); dns_db_detachnode(db, &node); - if (!dns_name_issubdomain(child, name)) + if (!dns_name_issubdomain(child, name)) { break; + } CHECK(namelist_append_name(affected, child)); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: - if (dbit != NULL) + if (dbit != NULL) { dns_dbiterator_destroy(&dbit); + } return (result); } @@ -773,8 +795,9 @@ is_non_nsec_action(void *data, dns_rdataset_t *rrset) rrset->type == dns_rdatatype_nsec3 || (rrset->type == dns_rdatatype_rrsig && (rrset->covers == dns_rdatatype_nsec || - rrset->covers == dns_rdatatype_nsec3)))) + rrset->covers == dns_rdatatype_nsec3)))) { return (ISC_R_EXISTS); + } return (ISC_R_SUCCESS); } @@ -820,8 +843,9 @@ uniqify_name_list(dns_diff_t *list) while (p != NULL) { do { q = ISC_LIST_NEXT(p, link); - if (q == NULL || !dns_name_equal(&p->name, &q->name)) + if (q == NULL || !dns_name_equal(&p->name, &q->name)) { break; + } ISC_LIST_UNLINK(list->tuples, q, link); dns_difftuple_free(&q); } while (1); @@ -845,8 +869,9 @@ is_active(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, bool *flag, if (result == ISC_R_SUCCESS || result == DNS_R_EMPTYNAME) { *flag = true; *cut = false; - if (unsecure != NULL) + if (unsecure != NULL) { *unsecure = false; + } return (ISC_R_SUCCESS); } else if (result == DNS_R_ZONECUT) { *flag = true; @@ -859,18 +884,20 @@ is_active(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, bool *flag, if (dns_db_find(db, name, ver, dns_rdatatype_ds, 0, (isc_stdtime_t)0, NULL, dns_fixedname_name(&foundname), NULL, - NULL) == DNS_R_NXRRSET) + NULL) == DNS_R_NXRRSET) { *unsecure = true; - else + } else { *unsecure = false; + } } return (ISC_R_SUCCESS); } else if (result == DNS_R_GLUE || result == DNS_R_DNAME || result == DNS_R_DELEGATION || result == DNS_R_NXDOMAIN) { *flag = false; *cut = false; - if (unsecure != NULL) + if (unsecure != NULL) { *unsecure = false; + } return (ISC_R_SUCCESS); } else { /* @@ -878,8 +905,9 @@ is_active(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, bool *flag, */ *flag = false; *cut = false; - if (unsecure != NULL) + if (unsecure != NULL) { *unsecure = false; + } return (result); } } @@ -907,18 +935,20 @@ next_active(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, do { dns_dbnode_t *node = NULL; - if (forward) + if (forward) { result = dns_dbiterator_next(dbit); - else + } else { result = dns_dbiterator_prev(dbit); + } if (result == ISC_R_NOMORE) { /* * Wrap around. */ - if (forward) + if (forward) { CHECK(dns_dbiterator_first(dbit)); - else + } else { CHECK(dns_dbiterator_last(dbit)); + } wraps++; if (wraps == 2) { update_log(log, zone, ISC_LOG_ERROR, @@ -954,13 +984,15 @@ next_active(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, dns_name_equal(newname, found))) { has_nsec = true; result = ISC_R_SUCCESS; - } else if (result != DNS_R_NXDOMAIN) + } else if (result != DNS_R_NXDOMAIN) { break; + } } } while (!has_nsec); failure: - if (dbit != NULL) + if (dbit != NULL) { dns_dbiterator_destroy(&dbit); + } return (result); } @@ -1011,8 +1043,9 @@ add_nsec(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, INSIST(tuple == NULL); failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1054,8 +1087,9 @@ find_zone_keys(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, directory, now, mctx, maxkeys, keys, nkeys)); failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1090,10 +1124,11 @@ add_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, isc_buffer_init(&buffer, data, sizeof(data)); /* Get the rdataset to sign. */ - if (type == dns_rdatatype_nsec3) + if (type == dns_rdatatype_nsec3) { CHECK(dns_db_findnsec3node(db, name, false, &node)); - else + } else { CHECK(dns_db_findnode(db, name, false, &node)); + } CHECK(dns_db_findrdataset(db, node, ver, type, 0, (isc_stdtime_t)0, &rdataset, NULL)); dns_db_detachnode(db, &node); @@ -1217,8 +1252,9 @@ add_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, if (type == dns_rdatatype_dnskey || type == dns_rdatatype_cdnskey || type == dns_rdatatype_cds) { - if (!KSK(keys[i]) && keyset_kskonly) + if (!KSK(keys[i]) && keyset_kskonly) { continue; + } } else if (KSK(keys[i])) { continue; } @@ -1251,10 +1287,12 @@ add_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1277,19 +1315,23 @@ del_keysigs(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_rdataset_init(&rdataset); result = dns_db_findnode(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_db_findrdataset(db, node, ver, dns_rdatatype_rrsig, dns_rdatatype_dnskey, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -1318,19 +1360,23 @@ del_keysigs(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, /* * If there is not a matching DNSKEY then delete the RRSIG. */ - if (!found) + if (!found) { result = update_one_rr(db, ver, diff, DNS_DIFFOP_DEL, name, rdataset.ttl, &rdata); + } dns_rdata_reset(&rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } dns_rdataset_disassociate(&rdataset); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1347,15 +1393,18 @@ add_exposed_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, node = NULL; result = dns_db_findnode(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } iter = NULL; result = dns_db_allrdatasets(db, node, ver, (isc_stdtime_t)0, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(iter)) { @@ -1373,24 +1422,28 @@ add_exposed_sigs(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, * as they are handled elsewhere. */ if ((type == dns_rdatatype_rrsig) || - (cut && type != dns_rdatatype_ds)) + (cut && type != dns_rdatatype_ds)) { continue; + } result = rrset_exists(db, ver, name, dns_rdatatype_rrsig, type, &flag); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iterator; - if (flag) + } + if (flag) { continue; - ; + } result = add_sigs(log, zone, db, ver, name, type, diff, keys, nkeys, inception, expire, check_ksk, keyset_kskonly); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iterator; + } (*sigs)++; } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup_iterator: dns_rdatasetiter_destroy(&iter); @@ -1559,8 +1612,9 @@ dns_update_signaturesinc(dns_update_log_t *log, dns_zone_t *zone, dns_db_t *db, CHECK(dns_diff_sort(diff, temp_order)); state->state = sign_updates; state->magic = STATE_MAGIC; - if (statep != NULL) + if (statep != NULL) { *statep = state; + } } else { REQUIRE(DNS_STATE_VALID(*statep)); state = *statep; @@ -1589,8 +1643,9 @@ next_state: */ /* Don't sign RRSIGs. */ - if (type == dns_rdatatype_rrsig) + if (type == dns_rdatatype_rrsig) { goto skip; + } /* * Delete all old RRSIGs covering this type, @@ -1600,16 +1655,17 @@ next_state: * Special case changes to the zone's DNSKEY * records to support offline KSKs. */ - if (type == dns_rdatatype_dnskey) + if (type == dns_rdatatype_dnskey) { del_keysigs(db, newver, name, &state->sig_diff, state->zone_keys, state->nkeys); - else + } else { CHECK(delete_if( true_p, db, newver, name, dns_rdatatype_rrsig, type, NULL, &state->sig_diff)); + } /* * If this RRset is still visible after the @@ -1648,14 +1704,15 @@ next_state: t = next; } } - if (state != &mystate && sigs > maxsigs) + if (state != &mystate && sigs > maxsigs) { return (DNS_R_CONTINUE); + } } ISC_LIST_APPENDLIST(diff->tuples, state->work.tuples, link); update_log(log, zone, ISC_LOG_DEBUG(3), "updated data signatures"); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case remove_orphaned: state->state = remove_orphaned; @@ -1686,7 +1743,7 @@ next_state: update_log(log, zone, ISC_LOG_DEBUG(3), "rebuilding NSEC chain"); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case build_chain: state->state = build_chain; /* @@ -1701,14 +1758,16 @@ next_state: prevname = dns_fixedname_initname(&fixedname); - if (oldver != NULL) + if (oldver != NULL) { CHECK(name_exists(db, oldver, &t->name, &existed)); - else + } else { existed = false; + } CHECK(name_exists(db, newver, &t->name, &exists)); - if (exists == existed) + if (exists == existed) { continue; + } /* * Find the predecessor. @@ -1736,26 +1795,29 @@ next_state: bool ns_existed, dname_existed; bool ns_exists, dname_exists; - if (oldver != NULL) + if (oldver != NULL) { CHECK(rrset_exists(db, oldver, &t->name, dns_rdatatype_ns, 0, &ns_existed)); - else + } else { ns_existed = false; - if (oldver != NULL) + } + if (oldver != NULL) { CHECK(rrset_exists(db, oldver, &t->name, dns_rdatatype_dname, 0, &dname_existed)); - else + } else { dname_existed = false; + } CHECK(rrset_exists(db, newver, &t->name, dns_rdatatype_ns, 0, &ns_exists)); CHECK(rrset_exists(db, newver, &t->name, dns_rdatatype_dname, 0, &dname_exists)); if ((ns_exists || dname_exists) == - (ns_existed || dname_existed)) + (ns_existed || dname_existed)) { continue; + } /* * There was a delegation change. Mark all subdomains * of t->name as potentially needing a NSEC update. @@ -1769,7 +1831,7 @@ next_state: CHECK(uniqify_name_list(&state->affected)); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case process_nsec: state->state = process_nsec; @@ -1785,8 +1847,9 @@ next_state: dns_name_t *name = &t->name; CHECK(name_exists(db, newver, name, &exists)); - if (!exists) + if (!exists) { goto unlink; + } CHECK(is_active(db, newver, name, &flag, &cut, NULL)); if (!flag) { /* @@ -1813,10 +1876,11 @@ next_state: CHECK(rrset_exists(db, newver, name, dns_rdatatype_nsec, 0, &flag)); - if (!flag) + if (!flag) { CHECK(add_placeholder_nsec( db, newver, name, diff)); + } } CHECK(add_exposed_sigs( log, zone, db, newver, name, cut, @@ -1828,8 +1892,9 @@ next_state: unlink: ISC_LIST_UNLINK(state->affected.tuples, t, link); ISC_LIST_APPEND(state->work.tuples, t, link); - if (state != &mystate && sigs > maxsigs) + if (state != &mystate && sigs > maxsigs) { return (DNS_R_CONTINUE); + } } ISC_LIST_APPENDLIST(state->affected.tuples, state->work.tuples, link); @@ -1881,7 +1946,7 @@ next_state: update_log(log, zone, ISC_LOG_DEBUG(3), "signing rebuilt NSEC chain"); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case sign_nsec: state->state = sign_nsec; /* Update RRSIG NSECs. */ @@ -1907,12 +1972,13 @@ next_state: } ISC_LIST_UNLINK(state->nsec_mindiff.tuples, t, link); ISC_LIST_APPEND(state->work.tuples, t, link); - if (state != &mystate && sigs > maxsigs) + if (state != &mystate && sigs > maxsigs) { return (DNS_R_CONTINUE); + } } ISC_LIST_APPENDLIST(state->nsec_mindiff.tuples, state->work.tuples, link); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case update_nsec3: state->state = update_nsec3; @@ -1966,18 +2032,20 @@ next_state: CHECK(namelist_append_name(&state->affected, name)); - if (oldver != NULL) + if (oldver != NULL) { CHECK(rrset_exists(db, oldver, name, dns_rdatatype_ns, 0, &ns_existed)); - else + } else { ns_existed = false; - if (oldver != NULL) + } + if (oldver != NULL) { CHECK(rrset_exists(db, oldver, name, dns_rdatatype_dname, 0, &dname_existed)); - else + } else { dname_existed = false; + } CHECK(rrset_exists(db, newver, name, dns_rdatatype_ns, 0, &ns_exists)); CHECK(rrset_exists(db, newver, name, @@ -1986,8 +2054,9 @@ next_state: exists = ns_exists || dname_exists; existed = ns_existed || dname_existed; - if (exists == existed) + if (exists == existed) { goto nextname; + } /* * There was a delegation change. Mark all subdomains * of t->name as potentially needing a NSEC3 update. @@ -1996,11 +2065,12 @@ next_state: &state->affected)); nextname: - while (t != NULL && dns_name_equal(&t->name, name)) + while (t != NULL && dns_name_equal(&t->name, name)) { t = ISC_LIST_NEXT(t, link); + } } - /* FALLTHROUGH */ + /* FALLTHROUGH */ case process_nsec3: state->state = process_nsec3; while ((t = ISC_LIST_HEAD(state->affected.tuples)) != NULL) { @@ -2031,8 +2101,9 @@ next_state: } ISC_LIST_UNLINK(state->affected.tuples, t, link); ISC_LIST_APPEND(state->work.tuples, t, link); - if (state != &mystate && sigs > maxsigs) + if (state != &mystate && sigs > maxsigs) { return (DNS_R_CONTINUE); + } } ISC_LIST_APPENDLIST(state->affected.tuples, state->work.tuples, link); @@ -2050,7 +2121,7 @@ next_state: update_log(log, zone, ISC_LOG_DEBUG(3), "signing rebuilt NSEC3 chain"); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case sign_nsec3: state->state = sign_nsec3; /* Update RRSIG NSEC3s. */ @@ -2076,8 +2147,9 @@ next_state: } ISC_LIST_UNLINK(state->nsec_mindiff.tuples, t, link); ISC_LIST_APPEND(state->work.tuples, t, link); - if (state != &mystate && sigs > maxsigs) + if (state != &mystate && sigs > maxsigs) { return (DNS_R_CONTINUE); + } } ISC_LIST_APPENDLIST(state->nsec_mindiff.tuples, state->work.tuples, link); @@ -2115,8 +2187,9 @@ failure: dns_diff_clear(&state->diffnames); dns_diff_clear(&state->work); - for (i = 0; i < state->nkeys; i++) + for (i = 0; i < state->nkeys; i++) { dst_key_free(&state->zone_keys[i]); + } if (state != &mystate && state != NULL) { *statep = NULL; @@ -2135,9 +2208,9 @@ epoch_to_yyyymmdd(time_t when) #if !defined(WIN32) struct tm tm0; tm = localtime_r(&when, &tm0); -#else +#else /* if !defined(WIN32) */ tm = localtime(&when); -#endif +#endif /* if !defined(WIN32) */ return (((tm->tm_year + 1900) * 10000) + ((tm->tm_mon + 1) * 100) + tm->tm_mday); } @@ -2153,22 +2226,25 @@ dns_update_soaserial(uint32_t serial, dns_updatemethod_t method) return (serial); case dns_updatemethod_unixtime: isc_stdtime_get(&now); - if (now != 0 && isc_serial_gt(now, serial)) + if (now != 0 && isc_serial_gt(now, serial)) { return (now); + } break; case dns_updatemethod_date: isc_stdtime_get(&now); new_serial = epoch_to_yyyymmdd((time_t)now) * 100; - if (new_serial != 0 && isc_serial_gt(new_serial, serial)) + if (new_serial != 0 && isc_serial_gt(new_serial, serial)) { return (new_serial); + } case dns_updatemethod_increment: break; } /* RFC1982 */ serial = (serial + 1) & 0xFFFFFFFF; - if (serial == 0) + if (serial == 0) { serial = 1; + } return (serial); } diff --git a/lib/dns/validator.c b/lib/dns/validator.c index 3f52b8cca5..dd3d4e5994 100644 --- a/lib/dns/validator.c +++ b/lib/dns/validator.c @@ -522,7 +522,7 @@ fetch_callback_ds(isc_task_t *task, isc_event_t *event) goto unexpected; } - /* FALLTHROUGH */ + /* FALLTHROUGH */ case ISC_R_SUCCESS: if (trustchain) { /* diff --git a/lib/dns/view.c b/lib/dns/view.c index 528af6a31f..0f4ad47123 100644 --- a/lib/dns/view.c +++ b/lib/dns/view.c @@ -17,7 +17,7 @@ #ifdef HAVE_LMDB #include -#endif +#endif /* ifdef HAVE_LMDB */ #include #include @@ -108,8 +108,9 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, const char *name, result = isc_file_sanitize(NULL, view->name, "nta", buffer, sizeof(buffer)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_name; + } view->nta_file = isc_mem_strdup(mctx, buffer); isc_mutex_init(&view->lock); @@ -158,8 +159,9 @@ dns_view_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, const char *name, view->matchdestinations = NULL; view->matchrecursiveonly = false; result = dns_tsigkeyring_create(view->mctx, &view->dynamickeys); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_weakrefs; + } view->peers = NULL; view->order = NULL; view->delonly = NULL; @@ -356,10 +358,12 @@ destroy(dns_view_t *view) isc_refcount_destroy(&view->references); isc_refcount_destroy(&view->weakrefs); - if (view->order != NULL) + if (view->order != NULL) { dns_order_detach(&view->order); - if (view->peers != NULL) + } + if (view->peers != NULL) { dns_peerlist_detach(&view->peers); + } if (view->dynamickeys != NULL) { isc_result_t result; @@ -381,29 +385,36 @@ destroy(dns_view_t *view) result = isc_file_sanitize( NULL, view->name, "tsigkeys", keyfile, sizeof(keyfile)); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = isc_file_rename( template, keyfile); + } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { (void)remove(template); + } } else { (void)fclose(fp); (void)remove(template); } } } - if (view->statickeys != NULL) + if (view->statickeys != NULL) { dns_tsigkeyring_detach(&view->statickeys); - if (view->adb != NULL) + } + if (view->adb != NULL) { dns_adb_detach(&view->adb); - if (view->resolver != NULL) + } + if (view->resolver != NULL) { dns_resolver_detach(&view->resolver); + } dns_rrl_view_destroy(view); - if (view->rpzs != NULL) + if (view->rpzs != NULL) { dns_rpz_detach_rpzs(&view->rpzs); - if (view->catzs != NULL) + } + if (view->catzs != NULL) { dns_catz_catzs_detach(&view->catzs); + } for (dlzdb = ISC_LIST_HEAD(view->dlz_searched); dlzdb != NULL; dlzdb = ISC_LIST_HEAD(view->dlz_searched)) { ISC_LIST_UNLINK(view->dlz_searched, dlzdb, link); @@ -414,54 +425,78 @@ destroy(dns_view_t *view) ISC_LIST_UNLINK(view->dlz_unsearched, dlzdb, link); dns_dlzdestroy(&dlzdb); } - if (view->requestmgr != NULL) + if (view->requestmgr != NULL) { dns_requestmgr_detach(&view->requestmgr); - if (view->task != NULL) + } + if (view->task != NULL) { isc_task_detach(&view->task); - if (view->hints != NULL) + } + if (view->hints != NULL) { dns_db_detach(&view->hints); - if (view->cachedb != NULL) + } + if (view->cachedb != NULL) { dns_db_detach(&view->cachedb); - if (view->cache != NULL) + } + if (view->cache != NULL) { dns_cache_detach(&view->cache); - if (view->nocasecompress != NULL) + } + if (view->nocasecompress != NULL) { dns_acl_detach(&view->nocasecompress); - if (view->matchclients != NULL) + } + if (view->matchclients != NULL) { dns_acl_detach(&view->matchclients); - if (view->matchdestinations != NULL) + } + if (view->matchdestinations != NULL) { dns_acl_detach(&view->matchdestinations); - if (view->cacheacl != NULL) + } + if (view->cacheacl != NULL) { dns_acl_detach(&view->cacheacl); - if (view->cacheonacl != NULL) + } + if (view->cacheonacl != NULL) { dns_acl_detach(&view->cacheonacl); - if (view->queryacl != NULL) + } + if (view->queryacl != NULL) { dns_acl_detach(&view->queryacl); - if (view->queryonacl != NULL) + } + if (view->queryonacl != NULL) { dns_acl_detach(&view->queryonacl); - if (view->recursionacl != NULL) + } + if (view->recursionacl != NULL) { dns_acl_detach(&view->recursionacl); - if (view->recursiononacl != NULL) + } + if (view->recursiononacl != NULL) { dns_acl_detach(&view->recursiononacl); - if (view->sortlist != NULL) + } + if (view->sortlist != NULL) { dns_acl_detach(&view->sortlist); - if (view->transferacl != NULL) + } + if (view->transferacl != NULL) { dns_acl_detach(&view->transferacl); - if (view->notifyacl != NULL) + } + if (view->notifyacl != NULL) { dns_acl_detach(&view->notifyacl); - if (view->updateacl != NULL) + } + if (view->updateacl != NULL) { dns_acl_detach(&view->updateacl); - if (view->upfwdacl != NULL) + } + if (view->upfwdacl != NULL) { dns_acl_detach(&view->upfwdacl); - if (view->denyansweracl != NULL) + } + if (view->denyansweracl != NULL) { dns_acl_detach(&view->denyansweracl); - if (view->pad_acl != NULL) + } + if (view->pad_acl != NULL) { dns_acl_detach(&view->pad_acl); - if (view->answeracl_exclude != NULL) + } + if (view->answeracl_exclude != NULL) { dns_rbt_destroy(&view->answeracl_exclude); - if (view->denyanswernames != NULL) + } + if (view->denyanswernames != NULL) { dns_rbt_destroy(&view->denyanswernames); - if (view->answernames_exclude != NULL) + } + if (view->answernames_exclude != NULL) { dns_rbt_destroy(&view->answernames_exclude); + } if (view->delonly != NULL) { dns_name_t *name; int i; @@ -497,28 +532,36 @@ destroy(dns_view_t *view) sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH); view->rootexclude = NULL; } - if (view->adbstats != NULL) + if (view->adbstats != NULL) { isc_stats_detach(&view->adbstats); - if (view->resstats != NULL) + } + if (view->resstats != NULL) { isc_stats_detach(&view->resstats); - if (view->resquerystats != NULL) + } + if (view->resquerystats != NULL) { dns_stats_detach(&view->resquerystats); - if (view->secroots_priv != NULL) + } + if (view->secroots_priv != NULL) { dns_keytable_detach(&view->secroots_priv); - if (view->ntatable_priv != NULL) + } + if (view->ntatable_priv != NULL) { dns_ntatable_detach(&view->ntatable_priv); + } for (dns64 = ISC_LIST_HEAD(view->dns64); dns64 != NULL; dns64 = ISC_LIST_HEAD(view->dns64)) { dns_dns64_unlink(&view->dns64, dns64); dns_dns64_destroy(&dns64); } - if (view->managed_keys != NULL) + if (view->managed_keys != NULL) { dns_zone_detach(&view->managed_keys); - if (view->redirect != NULL) + } + if (view->redirect != NULL) { dns_zone_detach(&view->redirect); + } #ifdef HAVE_DNSTAP - if (view->dtenv != NULL) + if (view->dtenv != NULL) { dns_dt_detach(&view->dtenv); + } #endif /* HAVE_DNSTAP */ dns_view_setnewzones(view, false, NULL, NULL, 0ULL); if (view->new_zone_file != NULL) { @@ -541,8 +584,9 @@ destroy(dns_view_t *view) #endif /* HAVE_LMDB */ dns_fwdtable_destroy(&view->fwdtable); dns_aclenv_destroy(&view->aclenv); - if (view->failcache != NULL) + if (view->failcache != NULL) { dns_badcache_destroy(&view->failcache); + } isc_mutex_destroy(&view->new_zone_lock); isc_mutex_destroy(&view->lock); isc_refcount_destroy(&view->references); @@ -611,8 +655,9 @@ view_flushanddetach(dns_view_t **viewp, bool flush) if (view->redirect != NULL) { rdzone = view->redirect; view->redirect = NULL; - if (view->flush) + if (view->flush) { dns_zone_flush(rdzone); + } } if (view->catzs != NULL) { dns_catz_catzs_detach(&view->catzs); @@ -766,8 +811,9 @@ dns_view_createresolver(dns_view_t *view, isc_taskmgr_t *taskmgr, REQUIRE(view->resolver == NULL); result = isc_task_create(taskmgr, 0, &view->task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } isc_task_setname(view->task, "view", view); result = dns_resolver_create(view, taskmgr, ntasks, ndisp, socketmgr, @@ -854,8 +900,9 @@ dns_view_setkeyring(dns_view_t *view, dns_tsig_keyring_t *ring) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(ring != NULL); - if (view->statickeys != NULL) + if (view->statickeys != NULL) { dns_tsigkeyring_detach(&view->statickeys); + } dns_tsigkeyring_attach(ring, &view->statickeys); } @@ -864,8 +911,9 @@ dns_view_setdynamickeyring(dns_view_t *view, dns_tsig_keyring_t *ring) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(ring != NULL); - if (view->dynamickeys != NULL) + if (view->dynamickeys != NULL) { dns_tsigkeyring_detach(&view->dynamickeys); + } dns_tsigkeyring_attach(ring, &view->dynamickeys); } @@ -874,8 +922,9 @@ dns_view_getdynamickeyring(dns_view_t *view, dns_tsig_keyring_t **ringp) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(ringp != NULL && *ringp == NULL); - if (view->dynamickeys != NULL) + if (view->dynamickeys != NULL) { dns_tsigkeyring_attach(view->dynamickeys, ringp); + } } void @@ -957,8 +1006,9 @@ dns_view_findzone(dns_view_t *view, const dns_name_t *name, dns_zone_t **zonep) dns_zone_detach(zonep); result = ISC_R_NOTFOUND; } - } else + } else { result = ISC_R_NOTFOUND; + } UNLOCK(&view->lock); return (result); @@ -1005,29 +1055,33 @@ dns_view_find(dns_view_t *view, const dns_name_t *name, dns_rdatatype_t type, is_staticstub_zone = false; zone = NULL; LOCK(&view->lock); - if (view->zonetable != NULL) + if (view->zonetable != NULL) { result = dns_zt_find(view->zonetable, name, DNS_ZTFIND_MIRROR, NULL, &zone); - else + } else { result = ISC_R_NOTFOUND; + } UNLOCK(&view->lock); if (zone != NULL && dns_zone_gettype(zone) == dns_zone_staticstub && - !use_static_stub) + !use_static_stub) { result = ISC_R_NOTFOUND; + } if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { result = dns_zone_getdb(zone, &db); - if (result != ISC_R_SUCCESS && view->cachedb != NULL) + if (result != ISC_R_SUCCESS && view->cachedb != NULL) { dns_db_attach(view->cachedb, &db); - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto cleanup; + } if (dns_zone_gettype(zone) == dns_zone_staticstub && dns_name_equal(name, dns_zone_getorigin(zone))) { is_staticstub_zone = true; } - } else if (result == ISC_R_NOTFOUND && view->cachedb != NULL) + } else if (result == ISC_R_NOTFOUND && view->cachedb != NULL) { dns_db_attach(view->cachedb, &db); - else + } else { goto cleanup; + } is_cache = dns_db_iscache(db); @@ -1039,13 +1093,16 @@ db_find: foundname, rdataset, sigrdataset); if (result == DNS_R_DELEGATION || result == ISC_R_NOTFOUND) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } if (!is_cache) { dns_db_detach(&db); if (view->cachedb != NULL && !is_staticstub_zone) { @@ -1068,12 +1125,14 @@ db_find: if (dns_rdataset_isassociated(&zrdataset)) { dns_rdataset_clone(&zrdataset, rdataset); if (sigrdataset != NULL && - dns_rdataset_isassociated(&zsigrdataset)) + dns_rdataset_isassociated(&zsigrdataset)) { dns_rdataset_clone(&zsigrdataset, sigrdataset); + } result = DNS_R_GLUE; - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } dns_db_attach(zdb, &db); dns_db_attachnode(db, znode, &node); goto cleanup; @@ -1111,14 +1170,17 @@ db_find: } if (result == ISC_R_NOTFOUND && use_hints && view->hints != NULL) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } if (db != NULL) { - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } dns_db_detach(&db); } result = dns_db_find(view->hints, name, NULL, type, options, @@ -1135,45 +1197,53 @@ db_find: } else if (result == DNS_R_NXRRSET) { dns_db_attach(view->hints, &db); result = DNS_R_HINTNXRRSET; - } else if (result == DNS_R_NXDOMAIN) + } else if (result == DNS_R_NXDOMAIN) { result = ISC_R_NOTFOUND; + } /* * Cleanup if non-standard hints are used. */ - if (db == NULL && node != NULL) + if (db == NULL && node != NULL) { dns_db_detachnode(view->hints, &node); + } } cleanup: if (dns_rdataset_isassociated(&zrdataset)) { dns_rdataset_disassociate(&zrdataset); - if (dns_rdataset_isassociated(&zsigrdataset)) + if (dns_rdataset_isassociated(&zsigrdataset)) { dns_rdataset_disassociate(&zsigrdataset); + } } if (zdb != NULL) { - if (znode != NULL) + if (znode != NULL) { dns_db_detachnode(zdb, &znode); + } dns_db_detach(&zdb); } if (db != NULL) { if (node != NULL) { - if (nodep != NULL) + if (nodep != NULL) { *nodep = node; - else + } else { dns_db_detachnode(db, &node); + } } - if (dbp != NULL) + if (dbp != NULL) { *dbp = db; - else + } else { dns_db_detach(&db); - } else + } + } else { INSIST(node == NULL); + } - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -1198,20 +1268,24 @@ dns_view_simplefind(dns_view_t *view, const dns_name_t *name, * foundname is not returned by this simplified API. We * disassociate them here to prevent any misuse by the caller. */ - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } } else if (result != ISC_R_SUCCESS && result != DNS_R_GLUE && result != DNS_R_HINT && result != DNS_R_NCACHENXDOMAIN && result != DNS_R_NCACHENXRRSET && result != DNS_R_NXRRSET && result != DNS_R_HINTNXRRSET && result != ISC_R_NOTFOUND) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } result = ISC_R_NOTFOUND; } @@ -1254,16 +1328,18 @@ dns_view_findzonecut(dns_view_t *view, const dns_name_t *name, zone = NULL; LOCK(&view->lock); if (view->zonetable != NULL) { - if ((options & DNS_DBFIND_NOEXACT) != 0) + if ((options & DNS_DBFIND_NOEXACT) != 0) { ztoptions |= DNS_ZTFIND_NOEXACT; + } result = dns_zt_find(view->zonetable, name, ztoptions, NULL, &zone); } else { result = ISC_R_NOTFOUND; } UNLOCK(&view->lock); - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { result = dns_zone_getdb(zone, &db); + } if (result == ISC_R_NOTFOUND) { /* * We're not directly authoritative for this query name, nor @@ -1300,10 +1376,11 @@ db_find: if (!is_cache) { result = dns_db_find(db, name, NULL, dns_rdatatype_ns, options, now, NULL, fname, rdataset, sigrdataset); - if (result == DNS_R_DELEGATION) + if (result == DNS_R_DELEGATION) { result = ISC_R_SUCCESS; - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { goto cleanup; + } if (use_cache && view->cachedb != NULL && db != view->hints) { /* @@ -1367,8 +1444,9 @@ finish: if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); if (sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } } dns_name_copynf(zfname, fname); if (dcname != NULL) { @@ -1376,8 +1454,9 @@ finish: } dns_rdataset_clone(&zrdataset, rdataset); if (sigrdataset != NULL && - dns_rdataset_isassociated(&zrdataset)) + dns_rdataset_isassociated(&zrdataset)) { dns_rdataset_clone(&zsigrdataset, sigrdataset); + } } else if (try_hints) { /* * We've found nothing so far, but we have hints. @@ -1390,8 +1469,9 @@ finish: * We can't even find the hints for the root * nameservers! */ - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } result = ISC_R_NOTFOUND; } else if (dcname != NULL) { dns_name_copynf(fname, dcname); @@ -1401,13 +1481,16 @@ finish: cleanup: if (dns_rdataset_isassociated(&zrdataset)) { dns_rdataset_disassociate(&zrdataset); - if (dns_rdataset_isassociated(&zsigrdataset)) + if (dns_rdataset_isassociated(&zsigrdataset)) { dns_rdataset_disassociate(&zsigrdataset); + } } - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); - if (zone != NULL) + } + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } @@ -1422,11 +1505,13 @@ dns_viewlist_find(dns_viewlist_t *list, const char *name, for (view = ISC_LIST_HEAD(*list); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (strcmp(view->name, name) == 0 && view->rdclass == rdclass) + if (strcmp(view->name, name) == 0 && view->rdclass == rdclass) { break; + } } - if (view == NULL) + if (view == NULL) { return (ISC_R_NOTFOUND); + } dns_view_attach(view, viewp); @@ -1448,8 +1533,9 @@ dns_viewlist_findzone(dns_viewlist_t *list, const dns_name_t *name, for (view = ISC_LIST_HEAD(*list); view != NULL; view = ISC_LIST_NEXT(view, link)) { - if (allclasses == false && view->rdclass != rdclass) + if (allclasses == false && view->rdclass != rdclass) { continue; + } /* * If the zone is defined in more than one view, @@ -1457,11 +1543,12 @@ dns_viewlist_findzone(dns_viewlist_t *list, const dns_name_t *name, */ zp = (zone1 == NULL) ? &zone1 : &zone2; LOCK(&view->lock); - if (view->zonetable != NULL) + if (view->zonetable != NULL) { result = dns_zt_find(view->zonetable, name, 0, NULL, zp); - else + } else { result = ISC_R_NOTFOUND; + } UNLOCK(&view->lock); INSIST(result == ISC_R_SUCCESS || result == ISC_R_NOTFOUND || result == DNS_R_PARTIALMATCH); @@ -1516,9 +1603,10 @@ dns_view_gettsig(dns_view_t *view, const dns_name_t *keyname, REQUIRE(keyp != NULL && *keyp == NULL); result = dns_tsigkey_find(keyp, keyname, NULL, view->statickeys); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = dns_tsigkey_find(keyp, keyname, NULL, view->dynamickeys); + } return (result); } @@ -1531,12 +1619,14 @@ dns_view_getpeertsig(dns_view_t *view, const isc_netaddr_t *peeraddr, dns_peer_t * peer = NULL; result = dns_peerlist_peerbyaddr(view->peers, peeraddr, &peer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_peer_getkey(peer, &keyname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_view_gettsig(view, keyname, keyp); return ((result == ISC_R_NOTFOUND) ? ISC_R_FAILURE : result); @@ -1563,8 +1653,9 @@ dns_view_dumpdbtostream(dns_view_t *view, FILE *fp) result = dns_master_dumptostream(view->mctx, view->cachedb, NULL, &dns_master_style_cache, dns_masterformat_text, NULL, fp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_adb_dump(view->adb, fp); dns_resolver_printbadcache(view->resolver, fp); dns_badcache_print(view->failcache, "SERVFAIL cache", fp); @@ -1578,19 +1669,23 @@ dns_view_flushcache(dns_view_t *view, bool fixuponly) REQUIRE(DNS_VIEW_VALID(view)); - if (view->cachedb == NULL) + if (view->cachedb == NULL) { return (ISC_R_SUCCESS); + } if (!fixuponly) { result = dns_cache_flush(view->cache); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } dns_db_detach(&view->cachedb); dns_cache_attachdb(view->cache, &view->cachedb); - if (view->resolver != NULL) + if (view->resolver != NULL) { dns_resolver_flushbadcache(view->resolver, NULL); - if (view->failcache != NULL) + } + if (view->failcache != NULL) { dns_badcache_flush(view->failcache); + } dns_adb_flush(view->adb); return (ISC_R_SUCCESS); @@ -1610,23 +1705,30 @@ dns_view_flushnode(dns_view_t *view, const dns_name_t *name, bool tree) REQUIRE(DNS_VIEW_VALID(view)); if (tree) { - if (view->adb != NULL) + if (view->adb != NULL) { dns_adb_flushnames(view->adb, name); - if (view->resolver != NULL) + } + if (view->resolver != NULL) { dns_resolver_flushbadnames(view->resolver, name); - if (view->failcache != NULL) + } + if (view->failcache != NULL) { dns_badcache_flushtree(view->failcache, name); + } } else { - if (view->adb != NULL) + if (view->adb != NULL) { dns_adb_flushname(view->adb, name); - if (view->resolver != NULL) + } + if (view->resolver != NULL) { dns_resolver_flushbadcache(view->resolver, name); - if (view->failcache != NULL) + } + if (view->failcache != NULL) { dns_badcache_flushname(view->failcache, name); + } } - if (view->cache != NULL) + if (view->cache != NULL) { result = dns_cache_flushnode(view->cache, name, tree); + } return (result); } @@ -1643,15 +1745,18 @@ dns_view_adddelegationonly(dns_view_t *view, const dns_name_t *name) view->delonly = isc_mem_get(view->mctx, sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH); - for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) + for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) { ISC_LIST_INIT(view->delonly[hash]); + } } hash = dns_name_hash(name, false) % DNS_VIEW_DELONLYHASH; item = ISC_LIST_HEAD(view->delonly[hash]); - while (item != NULL && !dns_name_equal(item, name)) + while (item != NULL && !dns_name_equal(item, name)) { item = ISC_LIST_NEXT(item, link); - if (item != NULL) + } + if (item != NULL) { return (ISC_R_SUCCESS); + } item = isc_mem_get(view->mctx, sizeof(*item)); dns_name_init(item, NULL); dns_name_dup(name, view->mctx, item); @@ -1671,15 +1776,18 @@ dns_view_excludedelegationonly(dns_view_t *view, const dns_name_t *name) view->rootexclude = isc_mem_get(view->mctx, sizeof(dns_namelist_t) * DNS_VIEW_DELONLYHASH); - for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) + for (hash = 0; hash < DNS_VIEW_DELONLYHASH; hash++) { ISC_LIST_INIT(view->rootexclude[hash]); + } } hash = dns_name_hash(name, false) % DNS_VIEW_DELONLYHASH; item = ISC_LIST_HEAD(view->rootexclude[hash]); - while (item != NULL && !dns_name_equal(item, name)) + while (item != NULL && !dns_name_equal(item, name)) { item = ISC_LIST_NEXT(item, link); - if (item != NULL) + } + if (item != NULL) { return (ISC_R_SUCCESS); + } item = isc_mem_get(view->mctx, sizeof(*item)); dns_name_init(item, NULL); dns_name_dup(name, view->mctx, item); @@ -1695,28 +1803,35 @@ dns_view_isdelegationonly(dns_view_t *view, const dns_name_t *name) REQUIRE(DNS_VIEW_VALID(view)); - if (!view->rootdelonly && view->delonly == NULL) + if (!view->rootdelonly && view->delonly == NULL) { return (false); + } hash = dns_name_hash(name, false) % DNS_VIEW_DELONLYHASH; if (view->rootdelonly && dns_name_countlabels(name) <= 2) { - if (view->rootexclude == NULL) + if (view->rootexclude == NULL) { return (true); + } item = ISC_LIST_HEAD(view->rootexclude[hash]); - while (item != NULL && !dns_name_equal(item, name)) + while (item != NULL && !dns_name_equal(item, name)) { item = ISC_LIST_NEXT(item, link); - if (item == NULL) + } + if (item == NULL) { return (true); + } } - if (view->delonly == NULL) + if (view->delonly == NULL) { return (false); + } item = ISC_LIST_HEAD(view->delonly[hash]); - while (item != NULL && !dns_name_equal(item, name)) + while (item != NULL && !dns_name_equal(item, name)) { item = ISC_LIST_NEXT(item, link); - if (item == NULL) + } + if (item == NULL) { return (false); + } return (true); } @@ -1759,8 +1874,9 @@ dns_view_getadbstats(dns_view_t *view, isc_stats_t **statsp) REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(statsp != NULL && *statsp == NULL); - if (view->adbstats != NULL) + if (view->adbstats != NULL) { isc_stats_attach(view->adbstats, statsp); + } } void @@ -1779,8 +1895,9 @@ dns_view_getresstats(dns_view_t *view, isc_stats_t **statsp) REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(statsp != NULL && *statsp == NULL); - if (view->resstats != NULL) + if (view->resstats != NULL) { isc_stats_attach(view->resstats, statsp); + } } void @@ -1799,8 +1916,9 @@ dns_view_getresquerystats(dns_view_t *view, dns_stats_t **statsp) REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(statsp != NULL && *statsp == NULL); - if (view->resquerystats != NULL) + if (view->resquerystats != NULL) { dns_stats_attach(view->resquerystats, statsp); + } } isc_result_t @@ -1808,8 +1926,9 @@ dns_view_initntatable(dns_view_t *view, isc_taskmgr_t *taskmgr, isc_timermgr_t *timermgr) { REQUIRE(DNS_VIEW_VALID(view)); - if (view->ntatable_priv != NULL) + if (view->ntatable_priv != NULL) { dns_ntatable_detach(&view->ntatable_priv); + } return (dns_ntatable_create(view, taskmgr, timermgr, &view->ntatable_priv)); } @@ -1819,8 +1938,9 @@ dns_view_getntatable(dns_view_t *view, dns_ntatable_t **ntp) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(ntp != NULL && *ntp == NULL); - if (view->ntatable_priv == NULL) + if (view->ntatable_priv == NULL) { return (ISC_R_NOTFOUND); + } dns_ntatable_attach(view->ntatable_priv, ntp); return (ISC_R_SUCCESS); } @@ -1829,8 +1949,9 @@ isc_result_t dns_view_initsecroots(dns_view_t *view, isc_mem_t *mctx) { REQUIRE(DNS_VIEW_VALID(view)); - if (view->secroots_priv != NULL) + if (view->secroots_priv != NULL) { dns_keytable_detach(&view->secroots_priv); + } return (dns_keytable_create(mctx, &view->secroots_priv)); } @@ -1839,8 +1960,9 @@ dns_view_getsecroots(dns_view_t *view, dns_keytable_t **ktp) { REQUIRE(DNS_VIEW_VALID(view)); REQUIRE(ktp != NULL && *ktp == NULL); - if (view->secroots_priv == NULL) + if (view->secroots_priv == NULL) { return (ISC_R_NOTFOUND); + } dns_keytable_attach(view->secroots_priv, ktp); return (ISC_R_SUCCESS); } @@ -1851,8 +1973,9 @@ dns_view_ntacovers(dns_view_t *view, isc_stdtime_t now, const dns_name_t *name, { REQUIRE(DNS_VIEW_VALID(view)); - if (view->ntatable_priv == NULL) + if (view->ntatable_priv == NULL) { return (false); + } return (dns_ntatable_covered(view->ntatable_priv, now, name, anchor)); } @@ -1992,11 +2115,11 @@ dns_view_setnewzones(dns_view_t *view, bool allow, void *cfgctx, #ifdef HAVE_LMDB MDB_env *env = NULL; int status; -#endif +#endif /* ifdef HAVE_LMDB */ #ifndef HAVE_LMDB UNUSED(mapsize); -#endif +#endif /* ifndef HAVE_LMDB */ REQUIRE(DNS_VIEW_VALID(view)); REQUIRE((cfgctx != NULL && cfg_destroy != NULL) || !allow); @@ -2167,8 +2290,9 @@ dns_view_searchdlz(dns_view_t *view, const dns_name_t *name, for (i = namelabels; i > minlabels && i > 1; i--) { if (i == namelabels) { dns_name_copynf(name, zonename); - } else + } else { dns_name_split(name, i, NULL, zonename); + } /* ask SDLZ driver if the zone is supported */ db = NULL; @@ -2179,20 +2303,23 @@ dns_view_searchdlz(dns_view_t *view, const dns_name_t *name, clientinfo, &db); if (result != ISC_R_NOTFOUND) { - if (best != NULL) + if (best != NULL) { dns_db_detach(&best); + } if (result == ISC_R_SUCCESS) { INSIST(db != NULL); dns_db_attach(db, &best); dns_db_detach(&db); minlabels = i; } else { - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } break; } - } else if (db != NULL) + } else if (db != NULL) { dns_db_detach(&db); + } } } @@ -2229,8 +2356,9 @@ dns_view_saventa(dns_view_t *view) REQUIRE(DNS_VIEW_VALID(view)); - if (view->nta_lifetime == 0) + if (view->nta_lifetime == 0) { return (ISC_R_SUCCESS); + } /* Open NTA save file for overwrite. */ CHECK(isc_stdio_open(view->nta_file, "w", &fp)); @@ -2240,8 +2368,9 @@ dns_view_saventa(dns_view_t *view) removefile = true; result = ISC_R_SUCCESS; goto cleanup; - } else + } else { CHECK(result); + } result = dns_ntatable_save(ntatable, fp); if (result == ISC_R_NOTFOUND) { @@ -2253,15 +2382,18 @@ dns_view_saventa(dns_view_t *view) } cleanup: - if (ntatable != NULL) + if (ntatable != NULL) { dns_ntatable_detach(&ntatable); + } - if (fp != NULL) + if (fp != NULL) { (void)isc_stdio_close(fp); + } /* Don't leave half-baked NTA save files lying around. */ - if (result != ISC_R_SUCCESS || removefile) + if (result != ISC_R_SUCCESS || removefile) { (void)isc_file_remove(view->nta_file); + } return (result); } @@ -2280,8 +2412,9 @@ dns_view_loadnta(dns_view_t *view) REQUIRE(DNS_VIEW_VALID(view)); - if (view->nta_lifetime == 0) + if (view->nta_lifetime == 0) { return (ISC_R_SUCCESS); + } CHECK(isc_lex_create(view->mctx, 1025, &lex)); CHECK(isc_lex_openfile(lex, view->nta_file)); @@ -2299,16 +2432,17 @@ dns_view_loadnta(dns_view_t *view) bool forced; CHECK(isc_lex_gettoken(lex, options, &token)); - if (token.type == isc_tokentype_eof) + if (token.type == isc_tokentype_eof) { break; - else if (token.type != isc_tokentype_string) + } else if (token.type != isc_tokentype_string) { CHECK(ISC_R_UNEXPECTEDTOKEN); + } name = TSTR(token); len = TLEN(token); - if (strcmp(name, ".") == 0) + if (strcmp(name, ".") == 0) { ntaname = dns_rootname; - else { + } else { dns_name_t *fname; fname = dns_fixedname_initname(&fn); @@ -2320,31 +2454,36 @@ dns_view_loadnta(dns_view_t *view) } CHECK(isc_lex_gettoken(lex, options, &token)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { CHECK(ISC_R_UNEXPECTEDTOKEN); + } type = TSTR(token); - if (strcmp(type, "regular") == 0) + if (strcmp(type, "regular") == 0) { forced = false; - else if (strcmp(type, "forced") == 0) + } else if (strcmp(type, "forced") == 0) { forced = true; - else + } else { CHECK(ISC_R_UNEXPECTEDTOKEN); + } CHECK(isc_lex_gettoken(lex, options, &token)); - if (token.type != isc_tokentype_string) + if (token.type != isc_tokentype_string) { CHECK(ISC_R_UNEXPECTEDTOKEN); + } timestamp = TSTR(token); CHECK(dns_time32_fromtext(timestamp, &t)); CHECK(isc_lex_gettoken(lex, options, &token)); if (token.type != isc_tokentype_eol && - token.type != isc_tokentype_eof) + token.type != isc_tokentype_eof) { CHECK(ISC_R_UNEXPECTEDTOKEN); + } if (now <= t) { - if (t > (now + 604800)) + if (t > (now + 604800)) { t = now + 604800; + } (void)dns_ntatable_add(ntatable, ntaname, forced, 0, t); } else { @@ -2354,11 +2493,12 @@ dns_view_loadnta(dns_view_t *view) DNS_LOGMODULE_NTA, ISC_LOG_INFO, "ignoring expired NTA at %s", nb); } - }; + } cleanup: - if (ntatable != NULL) + if (ntatable != NULL) { dns_ntatable_detach(&ntatable); + } if (lex != NULL) { isc_lex_close(lex); diff --git a/lib/dns/xfrin.c b/lib/dns/xfrin.c index f0f88d8c9d..082c2a028c 100644 --- a/lib/dns/xfrin.c +++ b/lib/dns/xfrin.c @@ -155,7 +155,7 @@ struct dns_xfrin_ctx { uint64_t nbytes; /*%< Number of bytes received */ unsigned int maxrecords; /*%< The maximum number of - records set for the zone */ + * records set for the zone */ isc_time_t start; /*%< Start time of the transfer */ isc_time_t end; /*%< End time of the transfer */ @@ -178,7 +178,6 @@ struct dns_xfrin_ctx { uint32_t request_serial; uint32_t current_serial; dns_journal_t *journal; - } ixfr; }; @@ -272,8 +271,9 @@ axfr_init(dns_xfrin_ctx_t *xfr) xfr->is_ixfr = false; - if (xfr->db != NULL) + if (xfr->db != NULL) { dns_db_detach(&xfr->db); + } CHECK(axfr_makedb(xfr, &xfr->db)); dns_rdatacallbacks_init(&xfr->axfr); @@ -308,15 +308,17 @@ axfr_putdata(dns_xfrin_ctx_t *xfr, dns_diffop_t op, dns_name_t *name, dns_difftuple_t *tuple = NULL; - if (rdata->rdclass != xfr->rdclass) + if (rdata->rdclass != xfr->rdclass) { return (DNS_R_BADCLASS); + } CHECK(dns_zone_checknames(xfr->zone, name, rdata)); CHECK(dns_difftuple_create(xfr->diff.mctx, op, name, ttl, rdata, &tuple)); dns_diff_append(&xfr->diff, &tuple); - if (++xfr->difflen > 100) + if (++xfr->difflen > 100) { CHECK(axfr_apply(xfr)); + } result = ISC_R_SUCCESS; failure: return (result); @@ -394,9 +396,10 @@ ixfr_init(dns_xfrin_ctx_t *xfr) xfr->difflen = 0; journalfile = dns_zone_getjournal(xfr->zone); - if (journalfile != NULL) + if (journalfile != NULL) { CHECK(dns_journal_open(xfr->mctx, journalfile, DNS_JOURNAL_CREATE, &xfr->ixfr.journal)); + } result = ISC_R_SUCCESS; failure: @@ -410,16 +413,19 @@ ixfr_putdata(dns_xfrin_ctx_t *xfr, dns_diffop_t op, dns_name_t *name, isc_result_t result; dns_difftuple_t *tuple = NULL; - if (rdata->rdclass != xfr->rdclass) + if (rdata->rdclass != xfr->rdclass) { return (DNS_R_BADCLASS); + } - if (op == DNS_DIFFOP_ADD) + if (op == DNS_DIFFOP_ADD) { CHECK(dns_zone_checknames(xfr->zone, name, rdata)); + } CHECK(dns_difftuple_create(xfr->diff.mctx, op, name, ttl, rdata, &tuple)); dns_diff_append(&xfr->diff, &tuple); - if (++xfr->difflen > 100) + if (++xfr->difflen > 100) { CHECK(ixfr_apply(xfr)); + } result = ISC_R_SUCCESS; failure: return (result); @@ -436,8 +442,9 @@ ixfr_apply(dns_xfrin_ctx_t *xfr) if (xfr->ver == NULL) { CHECK(dns_db_newversion(xfr->db, &xfr->ver)); - if (xfr->ixfr.journal != NULL) + if (xfr->ixfr.journal != NULL) { CHECK(dns_journal_begin_transaction(xfr->ixfr.journal)); + } } CHECK(dns_diff_apply(&xfr->diff, xfr->db, xfr->ver)); if (xfr->maxrecords != 0U) { @@ -449,8 +456,9 @@ ixfr_apply(dns_xfrin_ctx_t *xfr) } if (xfr->ixfr.journal != NULL) { result = dns_journal_writediff(xfr->ixfr.journal, &xfr->diff); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } dns_diff_clear(&xfr->diff); xfr->difflen = 0; @@ -468,8 +476,9 @@ ixfr_commit(dns_xfrin_ctx_t *xfr) if (xfr->ver != NULL) { CHECK(dns_zone_verifydb(xfr->zone, xfr->db, xfr->ver)); /* XXX enter ready-to-commit state here */ - if (xfr->ixfr.journal != NULL) + if (xfr->ixfr.journal != NULL) { CHECK(dns_journal_commit(xfr->ixfr.journal)); + } dns_db_closeversion(xfr->db, &xfr->ver, true); dns_zone_markdirty(xfr->zone); } @@ -495,8 +504,9 @@ xfr_rr(dns_xfrin_ctx_t *xfr, dns_name_t *name, uint32_t ttl, dns_rdata_t *rdata) xfr->nrecs++; if (rdata->type == dns_rdatatype_none || - dns_rdatatype_ismeta(rdata->type)) + dns_rdatatype_ismeta(rdata->type)) { FAIL(DNS_R_FORMERR); + } redo: switch (xfr->state) { @@ -549,8 +559,9 @@ redo: xfr->ixfr.request_serial, xfr->end_serial); FAIL(DNS_R_UPTODATE); } - if (xfr->reqtype == dns_rdatatype_axfr) + if (xfr->reqtype == dns_rdatatype_axfr) { xfr->checkid = false; + } xfr->state = XFRST_FIRSTDATA; break; @@ -616,8 +627,9 @@ redo: } } if (rdata->type == dns_rdatatype_ns && - dns_name_iswildcard(name)) + dns_name_iswildcard(name)) { FAIL(DNS_R_INVALIDNS); + } CHECK(ixfr_putdata(xfr, DNS_DIFFOP_ADD, name, ttl, rdata)); break; @@ -627,8 +639,9 @@ redo: */ if (rdata->type == dns_rdatatype_a && rdata->rdclass != xfr->rdclass && - xfr->rdclass != dns_rdataclass_in) + xfr->rdclass != dns_rdataclass_in) { break; + } CHECK(axfr_putdata(xfr, DNS_DIFFOP_ADD, name, ttl, rdata)); if (rdata->type == dns_rdatatype_soa) { CHECK(axfr_commit(xfr)); @@ -639,8 +652,8 @@ redo: case XFRST_AXFR_END: case XFRST_IXFR_END: FAIL(DNS_R_EXTRADATA); - /* NOTREACHED */ - /* FALLTHROUGH */ + /* NOTREACHED */ + /* FALLTHROUGH */ default: INSIST(0); ISC_UNREACHABLE(); @@ -667,8 +680,9 @@ dns_xfrin_create(dns_zone_t *zone, dns_rdatatype_t xfrtype, (void)dns_zone_getdb(zone, &db); - if (xfrtype == dns_rdatatype_soa || xfrtype == dns_rdatatype_ixfr) + if (xfrtype == dns_rdatatype_soa || xfrtype == dns_rdatatype_ixfr) { REQUIRE(db != NULL); + } CHECK(xfrin_create(mctx, zone, db, task, timermgr, socketmgr, zonename, dns_zone_getclass(zone), xfrtype, masteraddr, @@ -681,13 +695,15 @@ dns_xfrin_create(dns_zone_t *zone, dns_rdatatype_t xfrtype, CHECK(xfrin_start(xfr)); xfr->done = done; - if (xfr->done != NULL) + if (xfr->done != NULL) { xfr->refcount++; + } *xfrp = xfr; failure: - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } if (result != ISC_R_SUCCESS) { char zonetext[DNS_NAME_MAXTEXT + 32]; dns_zone_name(zone, zonetext, sizeof(zonetext)); @@ -700,8 +716,9 @@ failure: void dns_xfrin_shutdown(dns_xfrin_ctx_t *xfr) { - if (!xfr->shuttingdown) + if (!xfr->shuttingdown) { xfrin_fail(xfr, ISC_R_CANCELED, "shut down"); + } } void @@ -744,28 +761,33 @@ xfrin_reset(dns_xfrin_ctx_t *xfr) xfrin_cancelio(xfr); - if (xfr->socket != NULL) + if (xfr->socket != NULL) { isc_socket_detach(&xfr->socket); + } - if (xfr->lasttsig != NULL) + if (xfr->lasttsig != NULL) { isc_buffer_free(&xfr->lasttsig); + } dns_diff_clear(&xfr->diff); xfr->difflen = 0; - if (xfr->ixfr.journal != NULL) + if (xfr->ixfr.journal != NULL) { dns_journal_destroy(&xfr->ixfr.journal); + } - if (xfr->axfr.add_private != NULL) + if (xfr->axfr.add_private != NULL) { (void)dns_db_endload(xfr->db, &xfr->axfr); + } if (xfr->tcpmsg_valid) { dns_tcpmsg_invalidate(&xfr->tcpmsg); xfr->tcpmsg_valid = false; } - if (xfr->ver != NULL) + if (xfr->ver != NULL) { dns_db_closeversion(xfr->db, &xfr->ver, false); + } } static void @@ -774,16 +796,18 @@ xfrin_fail(dns_xfrin_ctx_t *xfr, isc_result_t result, const char *msg) if (result != DNS_R_UPTODATE && result != DNS_R_TOOMANYRECORDS) { xfrin_log(xfr, ISC_LOG_ERROR, "%s: %s", msg, isc_result_totext(result)); - if (xfr->is_ixfr) + if (xfr->is_ixfr) { /* Pass special result code to force AXFR retry */ result = DNS_R_BADIXFR; + } } xfrin_cancelio(xfr); /* * Close the journal. */ - if (xfr->ixfr.journal != NULL) + if (xfr->ixfr.journal != NULL) { dns_journal_destroy(&xfr->ixfr.journal); + } if (xfr->done != NULL) { (xfr->done)(xfr->zone, result); xfr->done = NULL; @@ -838,16 +862,18 @@ xfrin_create(isc_mem_t *mctx, dns_zone_t *zone, dns_db_t *db, isc_task_t *task, xfr->zone_had_db = false; xfr->db = NULL; - if (db != NULL) + if (db != NULL) { dns_db_attach(db, &xfr->db); + } xfr->ver = NULL; dns_diff_init(xfr->mctx, &xfr->diff); xfr->difflen = 0; - if (reqtype == dns_rdatatype_soa) + if (reqtype == dns_rdatatype_soa) { xfr->state = XFRST_SOAQUERY; - else + } else { xfr->state = XFRST_INITIALSOA; + } /* end_serial */ xfr->nmsg = 0; @@ -857,8 +883,9 @@ xfrin_create(isc_mem_t *mctx, dns_zone_t *zone, dns_db_t *db, isc_task_t *task, isc_time_now(&xfr->start); xfr->tsigkey = NULL; - if (tsigkey != NULL) + if (tsigkey != NULL) { dns_tsigkey_attach(tsigkey, &xfr->tsigkey); + } xfr->lasttsig = NULL; xfr->tsigctx = NULL; xfr->sincetsig = 0; @@ -895,14 +922,18 @@ xfrin_create(isc_mem_t *mctx, dns_zone_t *zone, dns_db_t *db, isc_task_t *task, return (ISC_R_SUCCESS); failure: - if (xfr->timer != NULL) + if (xfr->timer != NULL) { isc_timer_detach(&xfr->timer); - if (dns_name_dynamic(&xfr->name)) + } + if (dns_name_dynamic(&xfr->name)) { dns_name_free(&xfr->name, xfr->mctx); - if (xfr->tsigkey != NULL) + } + if (xfr->tsigkey != NULL) { dns_tsigkey_detach(&xfr->tsigkey); - if (xfr->db != NULL) + } + if (xfr->db != NULL) { dns_db_detach(&xfr->db); + } isc_task_detach(&xfr->task); dns_zone_idetach(&xfr->zone); isc_mem_putanddetach(&xfr->mctx, xfr, sizeof(*xfr)); @@ -921,7 +952,7 @@ xfrin_start(dns_xfrin_ctx_t *xfr) #ifndef BROKEN_TCP_BIND_BEFORE_CONNECT CHECK(isc_socket_bind(xfr->socket, &xfr->sourceaddr, ISC_SOCKET_REUSEADDRESS)); -#endif +#endif /* ifndef BROKEN_TCP_BIND_BEFORE_CONNECT */ isc_socket_dscp(xfr->socket, xfr->dscp); CHECK(isc_socket_connect(xfr->socket, &xfr->masteraddr, xfr->task, xfrin_connect_done, xfr)); @@ -951,8 +982,9 @@ render(dns_message_t *msg, isc_mem_t *mctx, isc_buffer_t *buf) CHECK(dns_message_renderend(msg)); result = ISC_R_SUCCESS; failure: - if (cleanup_cctx) + if (cleanup_cctx) { dns_compress_invalidate(&cctx); + } return (result); } @@ -992,9 +1024,10 @@ xfrin_connect_done(isc_task_t *task, isc_event_t *event) dns_zonemgr_unreachableadd(zmgr, &xfr->masteraddr, &xfr->sourceaddr, &now); goto failure; - } else + } else { dns_zonemgr_unreachabledel(zmgr, &xfr->masteraddr, &xfr->sourceaddr); + } } result = isc_socket_getsockname(xfr->socket, &sockaddr); @@ -1019,8 +1052,9 @@ xfrin_connect_done(isc_task_t *task, isc_event_t *event) CHECK(xfrin_send_request(xfr)); failure: - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { xfrin_fail(xfr, result, "failed to connect"); + } } /* @@ -1070,8 +1104,9 @@ failure: ISC_LIST_UNLINK(rdl->rdata, rdata, link); dns_message_puttemprdatalist(msg, &rdl); } - if (rdata != NULL) + if (rdata != NULL) { dns_message_puttemprdata(msg, &rdata); + } return (result); } @@ -1123,9 +1158,10 @@ xfrin_send_request(dns_xfrin_ctx_t *xfr) CHECK(tuple2msgname(soatuple, msg, &msgsoaname)); dns_message_addname(msg, msgsoaname, DNS_SECTION_AUTHORITY); - } else if (xfr->reqtype == dns_rdatatype_soa) + } else if (xfr->reqtype == dns_rdatatype_soa) { CHECK(dns_db_getsoaserial(xfr->db, NULL, &xfr->ixfr.request_serial)); + } xfr->checkid = true; xfr->id++; @@ -1134,16 +1170,18 @@ xfrin_send_request(dns_xfrin_ctx_t *xfr) xfr->nbytes = 0; isc_time_now(&xfr->start); msg->id = xfr->id; - if (xfr->tsigctx != NULL) + if (xfr->tsigctx != NULL) { dst_context_destroy(&xfr->tsigctx); + } CHECK(render(msg, xfr->mctx, &xfr->qbuffer)); /* * Free the last tsig, if there is one. */ - if (xfr->lasttsig != NULL) + if (xfr->lasttsig != NULL) { isc_buffer_free(&xfr->lasttsig); + } /* * Save the query TSIG and don't let message_destroy free it. @@ -1166,16 +1204,21 @@ xfrin_send_request(dns_xfrin_ctx_t *xfr) xfr->sends++; failure: - if (qname != NULL) + if (qname != NULL) { dns_message_puttempname(msg, &qname); - if (qrdataset != NULL) + } + if (qrdataset != NULL) { dns_message_puttemprdataset(msg, &qrdataset); - if (msg != NULL) + } + if (msg != NULL) { dns_message_destroy(&msg); - if (soatuple != NULL) + } + if (soatuple != NULL) { dns_difftuple_free(&soatuple); - if (ver != NULL) + } + if (ver != NULL) { dns_db_closeversion(xfr->db, &ver, false); + } return (result); } @@ -1201,8 +1244,9 @@ xfrin_send_done(isc_task_t *task, isc_event_t *event) xfr->recvs++; failure: isc_event_free(&event); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { xfrin_fail(xfr, result, "failed sending request data"); + } } static void @@ -1246,37 +1290,42 @@ xfrin_recv_done(isc_task_t *task, isc_event_t *ev) dns_message_setclass(msg, xfr->rdclass); - if (xfr->nmsg > 0) + if (xfr->nmsg > 0) { msg->tcp_continuation = 1; + } result = dns_message_parse(msg, &tcpmsg->buffer, DNS_MESSAGEPARSE_PRESERVEORDER); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_message_logpacket(msg, "received message from", &tcpmsg->address, DNS_LOGCATEGORY_XFER_IN, DNS_LOGMODULE_XFER_IN, ISC_LOG_DEBUG(10), xfr->mctx); - else + } else { xfrin_log(xfr, ISC_LOG_DEBUG(10), "dns_message_parse: %s", dns_result_totext(result)); + } if (result != ISC_R_SUCCESS || msg->rcode != dns_rcode_noerror || msg->opcode != dns_opcode_query || msg->rdclass != xfr->rdclass || (xfr->checkid && msg->id != xfr->id)) { - if (result == ISC_R_SUCCESS && msg->rcode != dns_rcode_noerror) + if (result == ISC_R_SUCCESS && + msg->rcode != dns_rcode_noerror) { result = ISC_RESULTCLASS_DNSRCODE + msg->rcode; /*XXX*/ - else if (result == ISC_R_SUCCESS && - msg->opcode != dns_opcode_query) + } else if (result == ISC_R_SUCCESS && + msg->opcode != dns_opcode_query) { result = DNS_R_UNEXPECTEDOPCODE; - else if (result == ISC_R_SUCCESS && - msg->rdclass != xfr->rdclass) + } else if (result == ISC_R_SUCCESS && + msg->rdclass != xfr->rdclass) { result = DNS_R_BADCLASS; - else if (result == ISC_R_SUCCESS || result == DNS_R_NOERROR) + } else if (result == ISC_R_SUCCESS || result == DNS_R_NOERROR) { result = DNS_R_UNEXPECTEDID; + } if (xfr->reqtype == dns_rdatatype_axfr || - xfr->reqtype == dns_rdatatype_soa) + xfr->reqtype == dns_rdatatype_soa) { goto failure; + } xfrin_log(xfr, ISC_LOG_DEBUG(3), "got %s, retrying with AXFR", isc_result_totext(result)); try_axfr: @@ -1332,8 +1381,9 @@ xfrin_recv_done(isc_task_t *task, isc_event_t *ev) } } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } if (dns_message_gettsig(msg, &tsigowner) != NULL) { /* @@ -1344,14 +1394,14 @@ xfrin_recv_done(isc_task_t *task, isc_event_t *ev) /* * Free the last tsig, if there is one. */ - if (xfr->lasttsig != NULL) + if (xfr->lasttsig != NULL) { isc_buffer_free(&xfr->lasttsig); + } /* * Update the last tsig pointer. */ CHECK(dns_message_getquerytsig(msg, xfr->mctx, &xfr->lasttsig)); - } else if (dns_message_gettsigkey(msg) != NULL) { xfr->sincetsig++; if (xfr->sincetsig > 100 || xfr->nmsg == 0 || @@ -1389,13 +1439,14 @@ xfrin_recv_done(isc_task_t *task, isc_event_t *ev) break; case XFRST_AXFR_END: CHECK(axfr_finalize(xfr)); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case XFRST_IXFR_END: /* * Close the journal. */ - if (xfr->ixfr.journal != NULL) + if (xfr->ixfr.journal != NULL) { dns_journal_destroy(&xfr->ixfr.journal); + } /* * Inform the caller we succeeded. @@ -1423,10 +1474,12 @@ xfrin_recv_done(isc_task_t *task, isc_event_t *ev) return; failure: - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { xfrin_fail(xfr, result, "failed while receiving responses"); + } } static void @@ -1455,8 +1508,9 @@ maybe_free(dns_xfrin_ctx_t *xfr) REQUIRE(VALID_XFRIN(xfr)); if (!xfr->shuttingdown || xfr->refcount != 0 || xfr->connects != 0 || - xfr->sends != 0 || xfr->recvs != 0) + xfr->sends != 0 || xfr->recvs != 0) { return; + } INSIST(!xfr->shuttingdown || xfr->shutdown_result != ISC_R_UNSET); @@ -1475,8 +1529,9 @@ maybe_free(dns_xfrin_ctx_t *xfr) */ isc_time_now(&xfr->end); msecs = isc_time_microdiff(&xfr->end, &xfr->start) / 1000; - if (msecs == 0) + if (msecs == 0) { msecs = 1; + } persec = (xfr->nbytes * 1000) / msecs; xfrin_log(xfr, ISC_LOG_INFO, "Transfer completed: %d messages, %d records, " @@ -1486,43 +1541,55 @@ maybe_free(dns_xfrin_ctx_t *xfr) (unsigned int)(msecs / 1000), (unsigned int)(msecs % 1000), (unsigned int)persec); - if (xfr->socket != NULL) + if (xfr->socket != NULL) { isc_socket_detach(&xfr->socket); + } - if (xfr->timer != NULL) + if (xfr->timer != NULL) { isc_timer_detach(&xfr->timer); + } - if (xfr->task != NULL) + if (xfr->task != NULL) { isc_task_detach(&xfr->task); + } - if (xfr->tsigkey != NULL) + if (xfr->tsigkey != NULL) { dns_tsigkey_detach(&xfr->tsigkey); + } - if (xfr->lasttsig != NULL) + if (xfr->lasttsig != NULL) { isc_buffer_free(&xfr->lasttsig); + } dns_diff_clear(&xfr->diff); - if (xfr->ixfr.journal != NULL) + if (xfr->ixfr.journal != NULL) { dns_journal_destroy(&xfr->ixfr.journal); + } - if (xfr->axfr.add_private != NULL) + if (xfr->axfr.add_private != NULL) { (void)dns_db_endload(xfr->db, &xfr->axfr); + } - if (xfr->tcpmsg_valid) + if (xfr->tcpmsg_valid) { dns_tcpmsg_invalidate(&xfr->tcpmsg); + } - if (xfr->tsigctx != NULL) + if (xfr->tsigctx != NULL) { dst_context_destroy(&xfr->tsigctx); + } - if ((xfr->name.attributes & DNS_NAMEATTR_DYNAMIC) != 0) + if ((xfr->name.attributes & DNS_NAMEATTR_DYNAMIC) != 0) { dns_name_free(&xfr->name, xfr->mctx); + } - if (xfr->ver != NULL) + if (xfr->ver != NULL) { dns_db_closeversion(xfr->db, &xfr->ver, false); + } - if (xfr->db != NULL) + if (xfr->db != NULL) { dns_db_detach(&xfr->db); + } if (xfr->zone != NULL) { if (!xfr->zone_had_db && xfr->shuttingdown && @@ -1570,8 +1637,9 @@ xfrin_log1(int level, const char *zonetext, const isc_sockaddr_t *masteraddr, { va_list ap; - if (isc_log_wouldlog(dns_lctx, level) == false) + if (isc_log_wouldlog(dns_lctx, level) == false) { return; + } va_start(ap, fmt); xfrin_logv(level, zonetext, masteraddr, fmt, ap); @@ -1588,8 +1656,9 @@ xfrin_log(dns_xfrin_ctx_t *xfr, int level, const char *fmt, ...) va_list ap; char zonetext[DNS_NAME_MAXTEXT + 32]; - if (isc_log_wouldlog(dns_lctx, level) == false) + if (isc_log_wouldlog(dns_lctx, level) == false) { return; + } dns_zone_name(xfr->zone, zonetext, sizeof(zonetext)); diff --git a/lib/dns/zone.c b/lib/dns/zone.c index d7f345f55d..a76de7753a 100644 --- a/lib/dns/zone.c +++ b/lib/dns/zone.c @@ -132,11 +132,11 @@ #ifndef DNS_MAX_EXPIRE #define DNS_MAX_EXPIRE 14515200 /*%< 24 weeks */ -#endif +#endif /* ifndef DNS_MAX_EXPIRE */ #ifndef DNS_DUMP_DELAY #define DNS_DUMP_DELAY 900 /*%< 15 minutes */ -#endif +#endif /* ifndef DNS_DUMP_DELAY */ typedef struct dns_notify dns_notify_t; typedef struct dns_stub dns_stub_t; @@ -175,7 +175,7 @@ typedef struct dns_include dns_include_t; (z)->locked = true; \ } \ } while (0) -#else +#else /* ifdef DNS_ZONE_CHECKLOCK */ #define LOCK_ZONE(z) LOCK(&(z)->lock) #define UNLOCK_ZONE(z) UNLOCK(&(z)->lock) #define LOCKED_ZONE(z) true @@ -183,7 +183,7 @@ typedef struct dns_include dns_include_t; do { \ result = isc_mutex_trylock(&(z)->lock); \ } while (0) -#endif +#endif /* ifdef DNS_ZONE_CHECKLOCK */ #define ZONEDB_INITLOCK(l) isc_rwlock_init((l), 0, 0) #define ZONEDB_DESTROYLOCK(l) isc_rwlock_destroy(l) @@ -192,7 +192,7 @@ typedef struct dns_include dns_include_t; #ifdef ENABLE_AFL extern bool dns_fuzzing_resolver; -#endif +#endif /* ifdef ENABLE_AFL */ struct dns_zone { /* Unlocked */ @@ -200,7 +200,7 @@ struct dns_zone { isc_mutex_t lock; #ifdef DNS_ZONE_CHECKLOCK bool locked; -#endif +#endif /* ifdef DNS_ZONE_CHECKLOCK */ isc_mem_t * mctx; isc_refcount_t erefs; @@ -515,7 +515,7 @@ typedef enum { typedef enum { DNS_ZONELOADFLAG_NOSTAT = 0x00000001U, /* Do not stat() master files */ DNS_ZONELOADFLAG_THAW = 0x00000002U, /* Thaw the zone on successful - load. */ + * load. */ } dns_zoneloadflag_t; #define UNREACH_CACHE_SIZE 10U @@ -941,8 +941,9 @@ struct ssevent { static inline void inc_stats(dns_zone_t *zone, isc_statscounter_t counter) { - if (zone->stats != NULL) + if (zone->stats != NULL) { isc_stats_increment(zone->stats, counter); + } } /*** @@ -975,7 +976,7 @@ dns_zone_create(dns_zone_t **zonep, isc_mem_t *mctx) /* XXX MPA check that all elements are initialised */ #ifdef DNS_ZONE_CHECKLOCK zone->locked = false; -#endif +#endif /* ifdef DNS_ZONE_CHECKLOCK */ zone->db = NULL; zone->zmgr = NULL; ISC_LINK_INIT(zone, link); @@ -1338,8 +1339,9 @@ static inline bool inline_secure(dns_zone_t *zone) { REQUIRE(DNS_ZONE_VALID(zone)); - if (zone->raw != NULL) + if (zone->raw != NULL) { return (true); + } return (false); } @@ -1351,8 +1353,9 @@ static inline bool inline_raw(dns_zone_t *zone) { REQUIRE(DNS_ZONE_VALID(zone)); - if (zone->secure != NULL) + if (zone->secure != NULL) { return (true); + } return (false); } @@ -1376,18 +1379,21 @@ dns_zone_setclass(dns_zone_t *zone, dns_rdataclass_t rdclass) zone->rdclass == rdclass); zone->rdclass = rdclass; - if (zone->strnamerd != NULL) + if (zone->strnamerd != NULL) { isc_mem_free(zone->mctx, zone->strnamerd); - if (zone->strrdclass != NULL) + } + if (zone->strrdclass != NULL) { isc_mem_free(zone->mctx, zone->strrdclass); + } zone_namerd_tostr(zone, namebuf, sizeof namebuf); zone->strnamerd = isc_mem_strdup(zone->mctx, namebuf); zone_rdclass_tostr(zone, namebuf, sizeof namebuf); zone->strrdclass = isc_mem_strdup(zone->mctx, namebuf); - if (inline_secure(zone)) + if (inline_secure(zone)) { dns_zone_setclass(zone->raw, rdclass); + } UNLOCK_ZONE(zone); } @@ -1424,10 +1430,12 @@ dns_zone_getserial(dns_zone_t *zone, uint32_t *serialp) result = zone_get_from_db(zone, zone->db, NULL, &soacount, serialp, NULL, NULL, NULL, NULL, NULL); - if (result == ISC_R_SUCCESS && soacount == 0) + if (result == ISC_R_SUCCESS && soacount == 0) { result = ISC_R_FAILURE; - } else + } + } else { result = DNS_R_NOTLOADED; + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); UNLOCK_ZONE(zone); @@ -1452,8 +1460,9 @@ dns_zone_settype(dns_zone_t *zone, dns_zonetype_t type) REQUIRE(zone->type == dns_zone_none || zone->type == type); zone->type = type; - if (zone->strnamerd != NULL) + if (zone->strnamerd != NULL) { isc_mem_free(zone->mctx, zone->strnamerd); + } zone_namerd_tostr(zone, namebuf, sizeof namebuf); zone->strnamerd = isc_mem_strdup(zone->mctx, namebuf); @@ -1467,8 +1476,9 @@ zone_freedbargs(dns_zone_t *zone) /* Free the old database argument list. */ if (zone->db_argv != NULL) { - for (i = 0; i < zone->db_argc; i++) + for (i = 0; i < zone->db_argc; i++) { isc_mem_free(zone->mctx, zone->db_argv[i]); + } isc_mem_put(zone->mctx, zone->db_argv, zone->db_argc * sizeof(*zone->db_argv)); } @@ -1490,8 +1500,9 @@ dns_zone_getdbtype(dns_zone_t *zone, char ***argv, isc_mem_t *mctx) LOCK_ZONE(zone); size = (zone->db_argc + 1) * sizeof(char *); - for (i = 0; i < zone->db_argc; i++) + for (i = 0; i < zone->db_argc; i++) { size += strlen(zone->db_argv[i]) + 1; + } mem = isc_mem_allocate(mctx, size); { tmp = mem; @@ -1597,8 +1608,9 @@ dns_zone_setviewcommit(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->prev_view != NULL) + if (zone->prev_view != NULL) { dns_view_weakdetach(&zone->prev_view); + } UNLOCK_ZONE(zone); } @@ -1632,10 +1644,12 @@ dns_zone_setorigin(dns_zone_t *zone, const dns_name_t *origin) } dns_name_dup(origin, zone->mctx, &zone->origin); - if (zone->strnamerd != NULL) + if (zone->strnamerd != NULL) { isc_mem_free(zone->mctx, zone->strnamerd); - if (zone->strname != NULL) + } + if (zone->strname != NULL) { isc_mem_free(zone->mctx, zone->strname); + } zone_namerd_tostr(zone, namebuf, sizeof namebuf); zone->strnamerd = isc_mem_strdup(zone->mctx, namebuf); @@ -1660,8 +1674,9 @@ dns_zone_setstring(dns_zone_t *zone, char **field, const char *value) copy = NULL; } - if (*field != NULL) + if (*field != NULL) { isc_mem_free(zone->mctx, *field); + } *field = copy; return (ISC_R_SUCCESS); @@ -1679,8 +1694,9 @@ dns_zone_setfile(dns_zone_t *zone, const char *file, dns_masterformat_t format, result = dns_zone_setstring(zone, &zone->masterfile, file); if (result == ISC_R_SUCCESS) { zone->masterformat = format; - if (format == dns_masterformat_text) + if (format == dns_masterformat_text) { zone->masterstyle = style; + } result = default_journal(zone); } UNLOCK_ZONE(zone); @@ -1740,8 +1756,9 @@ default_journal(dns_zone_t *zone) journal = NULL; } result = dns_zone_setstring(zone, &zone->journal, journal); - if (journal != NULL) + if (journal != NULL) { isc_mem_free(zone->mctx, journal); + } return (result); } @@ -1784,19 +1801,22 @@ dns_zone_isdynamic(dns_zone_t *zone, bool ignore_freeze) if (zone->type == dns_zone_slave || zone->type == dns_zone_mirror || zone->type == dns_zone_stub || zone->type == dns_zone_key || - (zone->type == dns_zone_redirect && zone->masters != NULL)) + (zone->type == dns_zone_redirect && zone->masters != NULL)) { return (true); + } /* Inline zones are always dynamic. */ - if (zone->type == dns_zone_master && zone->raw != NULL) + if (zone->type == dns_zone_master && zone->raw != NULL) { return (true); + } /* If !ignore_freeze, we need check whether updates are disabled. */ if (zone->type == dns_zone_master && (!zone->update_disabled || ignore_freeze) && ((zone->ssutable != NULL) || - (zone->update_acl != NULL && !dns_acl_isnone(zone->update_acl)))) + (zone->update_acl != NULL && !dns_acl_isnone(zone->update_acl)))) { return (true); + } return (false); } @@ -1815,10 +1835,12 @@ dns_zone_rpz_enable(dns_zone_t *zone, dns_rpz_zones_t *rpzs, * summary data and so can be policy zones. */ if (strcmp(zone->db_argv[0], "rbt") != 0 && - strcmp(zone->db_argv[0], "rbt64") != 0) + strcmp(zone->db_argv[0], "rbt64") != 0) { return (ISC_R_NOTIMPLEMENTED); - if (zone->masterformat == dns_masterformat_map) + } + if (zone->masterformat == dns_masterformat_map) { return (ISC_R_NOTIMPLEMENTED); + } /* * This must happen only once or be redundant. @@ -1944,15 +1966,17 @@ zone_touched(dns_zone_t *zone) result = isc_file_getmodtime(zone->masterfile, &modtime); if (result != ISC_R_SUCCESS || - isc_time_compare(&modtime, &zone->loadtime) > 0) + isc_time_compare(&modtime, &zone->loadtime) > 0) { return (true); + } for (include = ISC_LIST_HEAD(zone->includes); include != NULL; include = ISC_LIST_NEXT(include, link)) { result = isc_file_getmodtime(include->name, &modtime); if (result != ISC_R_SUCCESS || - isc_time_compare(&modtime, &include->filetime) > 0) + isc_time_compare(&modtime, &include->filetime) > 0) { return (true); + } } return (false); @@ -1974,8 +1998,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) REQUIRE(DNS_ZONE_VALID(zone)); - if (!locked) + if (!locked) { LOCK_ZONE(zone); + } INSIST(zone != zone->raw); hasraw = inline_secure(zone); @@ -2004,8 +2029,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) */ result = zone_load(zone->raw, flags, false); if (result != ISC_R_SUCCESS) { - if (!locked) + if (!locked) { UNLOCK_ZONE(zone); + } return (result); } LOCK_ZONE(zone->raw); @@ -2016,8 +2042,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) INSIST(zone->type != dns_zone_none); if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADING)) { - if ((flags & DNS_ZONELOADFLAG_THAW) != 0) + if ((flags & DNS_ZONELOADFLAG_THAW) != 0) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_THAW); + } result = DNS_R_CONTINUE; goto cleanup; } @@ -2043,10 +2070,11 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) * zone being reloaded. Do nothing - the database we already * have is guaranteed to be up-to-date. */ - if (zone->type == dns_zone_master && !hasraw) + if (zone->type == dns_zone_master && !hasraw) { result = DNS_R_DYNAMIC; - else + } else { result = ISC_R_SUCCESS; + } goto cleanup; } @@ -2092,8 +2120,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) */ result = isc_file_getmodtime(zone->masterfile, &filetime); if (result == ISC_R_SUCCESS && - isc_time_compare(&loadtime, &filetime) > 0) + isc_time_compare(&loadtime, &filetime) > 0) { loadtime = filetime; + } } /* @@ -2119,8 +2148,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) for (dlzdb = ISC_LIST_HEAD(zone->view->dlz_unsearched); dlzdb != NULL; dlzdb = ISC_LIST_NEXT(dlzdb, link)) { INSIST(DNS_DLZ_VALID(dlzdb)); - if (strcmp(zone->db_argv[1], dlzdb->dlzname) == 0) + if (strcmp(zone->db_argv[1], dlzdb->dlzname) == 0) { break; + } } if (dlzdb == NULL) { @@ -2141,8 +2171,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) zone->view->rdclass, &zone->origin, NULL, NULL, &db); if (result != ISC_R_NOTFOUND) { - if (zone->db != NULL) + if (zone->db != NULL) { zone_detachdb(zone); + } zone_attachdb(zone, db); dns_db_detach(&db); result = ISC_R_SUCCESS; @@ -2150,16 +2181,18 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_write); if (result == ISC_R_SUCCESS) { - if (dlzdb->configure_callback == NULL) + if (dlzdb->configure_callback == NULL) { goto cleanup; + } result = (*dlzdb->configure_callback)(zone->view, dlzdb, zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_zone_logc(zone, DNS_LOGCATEGORY_ZONELOAD, ISC_LOG_ERROR, "DLZ configuration callback: %s", isc_result_totext(result)); + } } goto cleanup; } @@ -2176,8 +2209,9 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) "no master file"); } zone->refreshtime = now; - if (zone->task != NULL) + if (zone->task != NULL) { zone_settimer(zone, &now); + } result = ISC_R_SUCCESS; goto cleanup; } @@ -2234,20 +2268,24 @@ zone_load(dns_zone_t *zone, unsigned int flags, bool locked) if (result == DNS_R_CONTINUE) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_LOADING); - if ((flags & DNS_ZONELOADFLAG_THAW) != 0) + if ((flags & DNS_ZONELOADFLAG_THAW) != 0) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_THAW); + } goto cleanup; } result = zone_postload(zone, db, loadtime, result); cleanup: - if (hasraw) + if (hasraw) { UNLOCK_ZONE(zone->raw); - if (!locked) + } + if (!locked) { UNLOCK_ZONE(zone); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); + } return (result); } @@ -2278,8 +2316,9 @@ zone_asyncload(isc_task_t *task, isc_event_t *event) UNLOCK_ZONE(zone); /* Inform the zone table we've finished loading */ - if (asl->loaded != NULL) + if (asl->loaded != NULL) { (asl->loaded)(asl->loaded_arg, zone, task); + } isc_mem_put(zone->mctx, asl, sizeof(*asl)); dns_zone_idetach(&zone); @@ -2336,10 +2375,11 @@ dns_zone_loadandthaw(dns_zone_t *zone) { isc_result_t result; - if (inline_raw(zone)) + if (inline_raw(zone)) { result = zone_load(zone->secure, DNS_ZONELOADFLAG_THAW, false); - else + } else { result = zone_load(zone, DNS_ZONELOADFLAG_THAW, false); + } switch (result) { case DNS_R_CONTINUE: @@ -2410,8 +2450,9 @@ zone_registerinclude(const char *filename, void *arg) REQUIRE(DNS_ZONE_VALID(zone)); - if (filename == NULL) + if (filename == NULL) { return; + } /* * Suppress duplicates. @@ -2420,7 +2461,6 @@ zone_registerinclude(const char *filename, void *arg) inc = ISC_LIST_NEXT(inc, link)) { if (strcmp(filename, inc->name) == 0) { return; - } } @@ -2429,8 +2469,9 @@ zone_registerinclude(const char *filename, void *arg) ISC_LINK_INIT(inc, link); result = isc_file_getmodtime(filename, &inc->filetime); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { isc_time_settoepoch(&inc->filetime); + } ISC_LIST_APPEND(zone->newincludes, inc, link); } @@ -2444,11 +2485,13 @@ zone_gotreadhandle(isc_task_t *task, isc_event_t *event) REQUIRE(DNS_LOAD_VALID(load)); - if ((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0) + if ((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0) { result = ISC_R_CANCELED; + } isc_event_free(&event); - if (result == ISC_R_CANCELED) + if (result == ISC_R_CANCELED) { goto fail; + } options = get_master_options(load->zone); @@ -2459,8 +2502,9 @@ zone_gotreadhandle(isc_task_t *task, isc_event_t *event) zone_registerinclude, load->zone, load->zone->mctx, load->zone->masterformat, load->zone->maxttl); if (result != ISC_R_SUCCESS && result != DNS_R_CONTINUE && - result != DNS_R_SEENINCLUDE) + result != DNS_R_SEENINCLUDE) { goto fail; + } return; fail: @@ -2478,8 +2522,9 @@ get_raw_serial(dns_zone_t *raw, dns_masterrawheader_t *rawdata) result = zone_get_from_db(raw, raw->db, NULL, &soacount, &rawdata->sourceserial, NULL, NULL, NULL, NULL, NULL); - if (result == ISC_R_SUCCESS && soacount > 0U) + if (result == ISC_R_SUCCESS && soacount > 0U) { rawdata->flags |= DNS_MASTERRAW_SOURCESERIALSET; + } } UNLOCK(&raw->lock); } @@ -2497,11 +2542,13 @@ zone_gotwritehandle(isc_task_t *task, isc_event_t *event) INSIST(task == zone->task); ENTER; - if ((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0) + if ((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0) { result = ISC_R_CANCELED; + } isc_event_free(&event); - if (result == ISC_R_CANCELED) + if (result == ISC_R_CANCELED) { goto fail; + } LOCK_ZONE(zone); INSIST(zone != zone->raw); @@ -2511,25 +2558,29 @@ zone_gotwritehandle(isc_task_t *task, isc_event_t *event) dns_db_currentversion(zone->db, &version); dns_master_initrawheader(&rawdata); - if (inline_secure(zone)) + if (inline_secure(zone)) { get_raw_serial(zone->raw, &rawdata); - if (zone->type == dns_zone_key) + } + if (zone->type == dns_zone_key) { output_style = &dns_master_style_keyzone; - else if (zone->masterstyle != NULL) + } else if (zone->masterstyle != NULL) { output_style = zone->masterstyle; - else + } else { output_style = &dns_master_style_default; + } result = dns_master_dumpinc( zone->mctx, zone->db, version, output_style, zone->masterfile, zone->task, dump_done, zone, &zone->dctx, zone->masterformat, &rawdata); dns_db_closeversion(zone->db, &version, false); - } else + } else { result = ISC_R_CANCELED; + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); UNLOCK_ZONE(zone); - if (result != DNS_R_CONTINUE) + if (result != DNS_R_CONTINUE) { goto fail; + } return; fail: @@ -2545,8 +2596,9 @@ fail: static void zone_setrawdata(dns_zone_t *zone, dns_masterrawheader_t *header) { - if ((header->flags & DNS_MASTERRAW_SOURCESERIALSET) == 0) + if ((header->flags & DNS_MASTERRAW_SOURCESERIALSET) == 0) { return; + } zone->sourceserial = header->sourceserial; zone->sourceserialset = true; @@ -2555,8 +2607,9 @@ zone_setrawdata(dns_zone_t *zone, dns_masterrawheader_t *header) void dns_zone_setrawdata(dns_zone_t *zone, dns_masterrawheader_t *header) { - if (zone == NULL) + if (zone == NULL) { return; + } LOCK_ZONE(zone); zone_setrawdata(zone, header); @@ -2663,43 +2716,49 @@ zone_check_mx(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, /* * "." means the services does not exist. */ - if (dns_name_equal(name, dns_rootname)) + if (dns_name_equal(name, dns_rootname)) { return (true); + } /* * Outside of zone. */ if (!dns_name_issubdomain(name, &zone->origin)) { - if (zone->checkmx != NULL) + if (zone->checkmx != NULL) { return ((zone->checkmx)(zone, name, owner)); + } return (true); } - if (zone->type == dns_zone_master) + if (zone->type == dns_zone_master) { level = ISC_LOG_ERROR; - else + } else { level = ISC_LOG_WARNING; + } foundname = dns_fixedname_initname(&fixed); result = dns_db_find(db, name, NULL, dns_rdatatype_a, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (true); + } if (result == DNS_R_NXRRSET) { result = dns_db_find(db, name, NULL, dns_rdatatype_aaaa, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (true); + } } dns_name_format(owner, ownerbuf, sizeof ownerbuf); dns_name_format(name, namebuf, sizeof namebuf); if (result == DNS_R_NXRRSET || result == DNS_R_NXDOMAIN || result == DNS_R_EMPTYNAME) { - if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKMXFAIL)) + if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKMXFAIL)) { level = ISC_LOG_WARNING; + } dns_zone_log(zone, level, "%s/MX '%s' has no address records (A or AAAA)", ownerbuf, namebuf); @@ -2708,19 +2767,22 @@ zone_check_mx(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, if (result == DNS_R_CNAME) { if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_WARNMXCNAME) || - DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) + DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) { level = ISC_LOG_WARNING; - if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) + } + if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) { dns_zone_log(zone, level, "%s/MX '%s' is a CNAME (illegal)", ownerbuf, namebuf); + } return ((level == ISC_LOG_WARNING) ? true : false); } if (result == DNS_R_DNAME) { if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_WARNMXCNAME) || - DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) + DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) { level = ISC_LOG_WARNING; + } if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNOREMXCNAME)) { dns_name_format(foundname, altbuf, sizeof altbuf); dns_zone_log(zone, level, @@ -2731,8 +2793,9 @@ zone_check_mx(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, return ((level == ISC_LOG_WARNING) ? true : false); } - if (zone->checkmx != NULL && result == DNS_R_DELEGATION) + if (zone->checkmx != NULL && result == DNS_R_DELEGATION) { return ((zone->checkmx)(zone, name, owner)); + } return (true); } @@ -2752,35 +2815,40 @@ zone_check_srv(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, /* * "." means the services does not exist. */ - if (dns_name_equal(name, dns_rootname)) + if (dns_name_equal(name, dns_rootname)) { return (true); + } /* * Outside of zone. */ if (!dns_name_issubdomain(name, &zone->origin)) { - if (zone->checksrv != NULL) + if (zone->checksrv != NULL) { return ((zone->checksrv)(zone, name, owner)); + } return (true); } - if (zone->type == dns_zone_master) + if (zone->type == dns_zone_master) { level = ISC_LOG_ERROR; - else + } else { level = ISC_LOG_WARNING; + } foundname = dns_fixedname_initname(&fixed); result = dns_db_find(db, name, NULL, dns_rdatatype_a, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (true); + } if (result == DNS_R_NXRRSET) { result = dns_db_find(db, name, NULL, dns_rdatatype_aaaa, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (true); + } } dns_name_format(owner, ownerbuf, sizeof ownerbuf); @@ -2796,19 +2864,22 @@ zone_check_srv(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, if (result == DNS_R_CNAME) { if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_WARNSRVCNAME) || - DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) + DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) { level = ISC_LOG_WARNING; - if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) + } + if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) { dns_zone_log(zone, level, "%s/SRV '%s' is a CNAME (illegal)", ownerbuf, namebuf); + } return ((level == ISC_LOG_WARNING) ? true : false); } if (result == DNS_R_DNAME) { if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_WARNSRVCNAME) || - DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) + DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) { level = ISC_LOG_WARNING; + } if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_IGNORESRVCNAME)) { dns_name_format(foundname, altbuf, sizeof altbuf); dns_zone_log(zone, level, @@ -2819,8 +2890,9 @@ zone_check_srv(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, return ((level == ISC_LOG_WARNING) ? true : false); } - if (zone->checksrv != NULL && result == DNS_R_DELEGATION) + if (zone->checksrv != NULL && result == DNS_R_DELEGATION) { return ((zone->checksrv)(zone, name, owner)); + } return (true); } @@ -2844,15 +2916,17 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, * Outside of zone. */ if (!dns_name_issubdomain(name, &zone->origin)) { - if (zone->checkns != NULL) + if (zone->checkns != NULL) { return ((zone->checkns)(zone, name, owner, NULL, NULL)); + } return (true); } - if (zone->type == dns_zone_master) + if (zone->type == dns_zone_master) { level = ISC_LOG_ERROR; - else + } else { level = ISC_LOG_WARNING; + } foundname = dns_fixedname_initname(&fixed); dns_rdataset_init(&a); @@ -2870,8 +2944,9 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, case DNS_R_CNAME: break; default: - if (dns_rdataset_isassociated(&a)) + if (dns_rdataset_isassociated(&a)) { dns_rdataset_disassociate(&a); + } result = dns_db_find(db, name, NULL, dns_rdatatype_a, DNS_DBFIND_GLUEOK, 0, NULL, foundname, &a, NULL); @@ -2879,8 +2954,9 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, if (result == ISC_R_SUCCESS) { dns_rdataset_disassociate(&a); return (true); - } else if (result == DNS_R_DELEGATION) + } else if (result == DNS_R_DELEGATION) { dns_rdataset_disassociate(&a); + } if (result == DNS_R_NXRRSET || result == DNS_R_DELEGATION || result == DNS_R_GLUE) { @@ -2888,24 +2964,29 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, DNS_DBFIND_GLUEOK, 0, NULL, foundname, &aaaa, NULL); if (tresult == ISC_R_SUCCESS) { - if (dns_rdataset_isassociated(&a)) + if (dns_rdataset_isassociated(&a)) { dns_rdataset_disassociate(&a); + } dns_rdataset_disassociate(&aaaa); return (true); } - if (tresult == DNS_R_DELEGATION || tresult == DNS_R_DNAME) + if (tresult == DNS_R_DELEGATION || tresult == DNS_R_DNAME) { dns_rdataset_disassociate(&aaaa); + } if (result == DNS_R_GLUE || tresult == DNS_R_GLUE) { /* * Check glue against child zone. */ - if (zone->checkns != NULL) + if (zone->checkns != NULL) { answer = (zone->checkns)(zone, name, owner, &a, &aaaa); - if (dns_rdataset_isassociated(&a)) + } + if (dns_rdataset_isassociated(&a)) { dns_rdataset_disassociate(&a); - if (dns_rdataset_isassociated(&aaaa)) + } + if (dns_rdataset_isassociated(&aaaa)) { dns_rdataset_disassociate(&aaaa); + } return (answer); } } @@ -2919,10 +3000,11 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, if (dns_name_issubdomain(name, owner)) { what = "REQUIRED GLUE "; required = true; - } else if (result == DNS_R_DELEGATION) + } else if (result == DNS_R_DELEGATION) { what = "SIBLING GLUE "; - else + } else { what = ""; + } if (result != DNS_R_DELEGATION || required || DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKSIBLING)) { @@ -2933,9 +3015,11 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, /* * Log missing address record. */ - if (result == DNS_R_DELEGATION && zone->checkns != NULL) + if (result == DNS_R_DELEGATION && + zone->checkns != NULL) { (void)(zone->checkns)(zone, name, owner, &a, &aaaa); + } /* XXX950 make fatal for 9.5.0. */ /* answer = false; */ } @@ -2953,10 +3037,12 @@ zone_check_glue(dns_zone_t *zone, dns_db_t *db, dns_name_t *name, /* answer = false; */ } - if (dns_rdataset_isassociated(&a)) + if (dns_rdataset_isassociated(&a)) { dns_rdataset_disassociate(&a); - if (dns_rdataset_isassociated(&aaaa)) + } + if (dns_rdataset_isassociated(&aaaa)) { dns_rdataset_disassociate(&aaaa); + } return (answer); } @@ -2973,8 +3059,9 @@ zone_rrset_check_dup(dns_zone_t *zone, dns_name_t *owner, char typebuf[DNS_RDATATYPE_FORMATSIZE]; unsigned int count1 = 0; - if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKDUPRRFAIL)) + if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKDUPRRFAIL)) { level = ISC_LOG_ERROR; + } dns_rdataset_init(&tmprdataset); for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -2990,8 +3077,9 @@ zone_rrset_check_dup(dns_zone_t *zone, dns_name_t *owner, result = dns_rdataset_next(&tmprdataset)) { dns_rdata_t rdata2 = DNS_RDATA_INIT; count2++; - if (count1 >= count2) + if (count1 >= count2) { continue; + } dns_rdataset_current(&tmprdataset, &rdata2); if (dns_rdata_casecompare(&rdata1, &rdata2) == 0) { if (format) { @@ -3006,14 +3094,16 @@ zone_rrset_check_dup(dns_zone_t *zone, dns_name_t *owner, "%s/%s has " "semantically identical records", ownerbuf, typebuf); - if (level == ISC_LOG_ERROR) + if (level == ISC_LOG_ERROR) { answer = false; + } break; } } dns_rdataset_disassociate(&tmprdataset); - if (!format) + if (!format) { break; + } } return (answer); } @@ -3034,33 +3124,38 @@ zone_check_dup(dns_zone_t *zone, dns_db_t *db) dns_rdataset_init(&rdataset); result = dns_db_createiterator(db, 0, &dbiterator); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (true); + } for (result = dns_dbiterator_first(dbiterator); result == ISC_R_SUCCESS; result = dns_dbiterator_next(dbiterator)) { result = dns_dbiterator_current(dbiterator, &node, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = dns_db_allrdatasets(db, node, NULL, 0, &rdsit); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } for (result = dns_rdatasetiter_first(rdsit); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(rdsit)) { dns_rdatasetiter_current(rdsit, &rdataset); - if (!zone_rrset_check_dup(zone, name, &rdataset)) + if (!zone_rrset_check_dup(zone, name, &rdataset)) { ok = false; + } dns_rdataset_disassociate(&rdataset); } dns_rdatasetiter_destroy(&rdsit); dns_db_detachnode(db, &node); } - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } dns_dbiterator_destroy(&dbiterator); return (ok); @@ -3078,20 +3173,23 @@ isspf(const dns_rdata_t *rdata) ++data; --rdl; INSIST(tl <= rdl); - if (len > sizeof(buf) - i - 1) + if (len > sizeof(buf) - i - 1) { len = sizeof(buf) - i - 1; + } memmove(buf + i, data, len); i += len; data += tl; rdl -= tl; } - if (i < 6U) + if (i < 6U) { return (false); + } buf[i] = 0; - if (strncmp(buf, "v=spf1", 6) == 0 && (buf[6] == 0 || buf[6] == ' ')) + if (strncmp(buf, "v=spf1", 6) == 0 && (buf[6] == 0 || buf[6] == ' ')) { return (true); + } return (false); } @@ -3118,33 +3216,38 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) dns_rdata_init(&rdata); result = dns_db_createiterator(db, 0, &dbiterator); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (true); + } result = dns_dbiterator_first(dbiterator); while (result == ISC_R_SUCCESS) { result = dns_dbiterator_current(dbiterator, &node, name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Is this name visible in the zone? */ if (!dns_name_issubdomain(name, &zone->origin) || (dns_name_countlabels(bottom) > 0 && - dns_name_issubdomain(name, bottom))) + dns_name_issubdomain(name, bottom))) { goto next; + } /* * Don't check the NS records at the origin. */ - if (dns_name_equal(name, &zone->origin)) + if (dns_name_equal(name, &zone->origin)) { goto checkfordname; + } result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_ns, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto checkfordname; + } /* * Remember bottom of zone due to NS. */ @@ -3155,8 +3258,9 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) dns_rdataset_current(&rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &ns, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (!zone_check_glue(zone, db, &ns.name, name)) + if (!zone_check_glue(zone, db, &ns.name, name)) { ok = false; + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&rdataset); } @@ -3177,34 +3281,39 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_mx, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto checksrv; + } result = dns_rdataset_first(&rdataset); while (result == ISC_R_SUCCESS) { dns_rdataset_current(&rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &mx, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (!zone_check_mx(zone, db, &mx.mx, name)) + if (!zone_check_mx(zone, db, &mx.mx, name)) { ok = false; + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&rdataset); } dns_rdataset_disassociate(&rdataset); checksrv: - if (zone->rdclass != dns_rdataclass_in) + if (zone->rdclass != dns_rdataclass_in) { goto next; + } result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_srv, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto checkspf; + } result = dns_rdataset_first(&rdataset); while (result == ISC_R_SUCCESS) { dns_rdataset_current(&rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &srv, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (!zone_check_srv(zone, db, &srv.target, name)) + if (!zone_check_srv(zone, db, &srv.target, name)) { ok = false; + } dns_rdata_reset(&rdata); result = dns_rdataset_next(&rdataset); } @@ -3215,10 +3324,12 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) * Check if there is a type SPF record without an * SPF-formatted type TXT record also being present. */ - if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKSPF)) + if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKSPF)) { goto next; - if (zone->rdclass != dns_rdataclass_in) + } + if (zone->rdclass != dns_rdataclass_in) { goto next; + } have_spf = have_txt = false; result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_spf, 0, 0, &rdataset, NULL); @@ -3228,15 +3339,17 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) } result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_txt, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto notxt; + } result = dns_rdataset_first(&rdataset); while (result == ISC_R_SUCCESS) { dns_rdataset_current(&rdataset, &rdata); have_txt = isspf(&rdata); dns_rdata_reset(&rdata); - if (have_txt) + if (have_txt) { break; + } result = dns_rdataset_next(&rdataset); } dns_rdataset_disassociate(&rdataset); @@ -3259,8 +3372,9 @@ integrity_checks(dns_zone_t *zone, dns_db_t *db) } cleanup: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } dns_dbiterator_destroy(&dbiterator); return (ok); @@ -3635,8 +3749,9 @@ resume_addnsec3chain(dns_zone_t *zone) INSIST(LOCKED_ZONE(zone)); - if (zone->privatetype == 0) + if (zone->privatetype == 0) { return; + } ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); if (zone->db != NULL) { @@ -3737,16 +3852,18 @@ set_resigntime(dns_zone_t *zone) if (!inline_secure(zone) && (zone->type != dns_zone_master || - (zone->ssutable == NULL && - (zone->update_acl == NULL || dns_acl_isnone(zone->update_acl))))) + (zone->ssutable == NULL && (zone->update_acl == NULL || + dns_acl_isnone(zone->update_acl))))) { return; + } dns_rdataset_init(&rdataset); dns_fixedname_init(&fixed); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_attach(zone->db, &db); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); if (db == NULL) { isc_time_settoepoch(&zone->resigntime); @@ -3839,11 +3956,12 @@ check_nsec3param(dns_zone_t *zone, dns_db_t *db) /* Stop second error message. */ ok = true; break; - } else + } else { dns_zone_log(zone, ISC_LOG_WARNING, "unsupported nsec3 hash " "algorithm: %u", nsec3param.hash); + } } else { ok = true; } @@ -3883,21 +4001,26 @@ set_refreshkeytimer(dns_zone_t *zone, dns_rdata_keydata_t *key, ENTER; then = key->refresh; - if (force) + if (force) { then = now; - if (key->addhd > now && key->addhd < then) + } + if (key->addhd > now && key->addhd < then) { then = key->addhd; - if (key->removehd > now && key->removehd < then) + } + if (key->removehd > now && key->removehd < then) { then = key->removehd; + } TIME_NOW(&timenow); - if (then > now) + if (then > now) { DNS_ZONE_TIME_ADD(&timenow, then - now, &timethen); - else + } else { timethen = timenow; + } if (isc_time_compare(&zone->refreshkeytime, &timenow) < 0 || - isc_time_compare(&timethen, &zone->refreshkeytime) < 0) + isc_time_compare(&timethen, &zone->refreshkeytime) < 0) { zone->refreshkeytime = timethen; + } isc_time_formattimestamp(&zone->refreshkeytime, timebuf, 80); dns_zone_log(zone, ISC_LOG_DEBUG(1), "next key refresh: %s", timebuf); @@ -3975,11 +4098,13 @@ delete_keydata(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff, dns_rdataset_current(rdataset, &rdata); uresult = update_one_rr(db, ver, diff, DNS_DIFFOP_DEL, name, 0, &rdata); - if (uresult != ISC_R_SUCCESS) + if (uresult != ISC_R_SUCCESS) { return (uresult); + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } return (result); } @@ -4180,8 +4305,9 @@ update_one_rr(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff, dns_difftuple_t *tuple = NULL; isc_result_t result; result = dns_difftuple_create(diff->mctx, op, name, ttl, rdata, &tuple); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (do_one_tuple(&tuple, db, ver, diff)); } @@ -4208,10 +4334,12 @@ update_soa_serial(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff, result = ISC_R_SUCCESS; failure: - if (addtuple != NULL) + if (addtuple != NULL) { dns_difftuple_free(&addtuple); - if (deltuple != NULL) + } + if (deltuple != NULL) { dns_difftuple_free(&deltuple); + } return (result); } @@ -4240,8 +4368,9 @@ zone_journal(dns_zone_t *zone, dns_diff_t *diff, uint32_t *sourceserial, return (result); } - if (sourceserial != NULL) + if (sourceserial != NULL) { dns_journal_set_sourceserial(journal, *sourceserial); + } result = dns_journal_write_transaction(journal, diff); if (result != ISC_R_SUCCESS) { @@ -4293,8 +4422,9 @@ add_soa(dns_zone_t *zone, dns_db_t *db) failure: dns_diff_clear(&diff); - if (ver != NULL) + if (ver != NULL) { dns_db_closeversion(db, &ver, (result == ISC_R_SUCCESS)); + } INSIST(ver == NULL); @@ -4531,13 +4661,15 @@ maybe_send_secure(dns_zone_t *zone) result = zone_get_from_db(zone->raw, zone->raw->db, NULL, &soacount, &serial, NULL, NULL, NULL, NULL, NULL); - if (result == ISC_R_SUCCESS && soacount > 0U) + if (result == ISC_R_SUCCESS && soacount > 0U) { zone_send_secureserial(zone->raw, serial); - } else + } + } else { zone_send_securedb(zone->raw, zone->raw->db); - - } else + } + } else { DNS_ZONE_SETFLAG(zone->raw, DNS_ZONEFLG_SENDSECURE); + } } static bool @@ -4549,8 +4681,9 @@ zone_unchanged(dns_db_t *db1, dns_db_t *db2, isc_mem_t *mctx) dns_diff_init(mctx, &diff); result = dns_db_diffx(&diff, db1, NULL, db2, NULL, NULL); - if (result == ISC_R_SUCCESS && ISC_LIST_EMPTY(diff.tuples)) + if (result == ISC_R_SUCCESS && ISC_LIST_EMPTY(diff.tuples)) { answer = true; + } dns_diff_clear(&diff); return (answer); } @@ -4616,8 +4749,9 @@ zone_postload(dns_zone_t *zone, dns_db_t *db, isc_time_t loadtime, } else { int level = ISC_LOG_ERROR; if (zone->type == dns_zone_key && - result == ISC_R_FILENOTFOUND) + result == ISC_R_FILENOTFOUND) { level = ISC_LOG_DEBUG(1); + } dns_zone_logc(zone, DNS_LOGCATEGORY_ZONELOAD, level, "loading from master file %s failed: %s", zone->masterfile, @@ -4783,8 +4917,9 @@ zone_postload(dns_zone_t *zone, dns_db_t *db, isc_time_t loadtime, if (zone->type != dns_zone_stub && zone->type != dns_zone_redirect) { result = check_nsec3param(zone, db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } if (zone->type == dns_zone_master && DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKINTEGRITY) && @@ -5167,26 +5302,30 @@ zone_check_ns(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *version, dns_name_t * foundname; int level; - if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_NOCHECKNS)) + if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_NOCHECKNS)) { return (true); + } - if (zone->type == dns_zone_master) + if (zone->type == dns_zone_master) { level = ISC_LOG_ERROR; - else + } else { level = ISC_LOG_WARNING; + } foundname = dns_fixedname_initname(&fixed); result = dns_db_find(db, name, version, dns_rdatatype_a, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (true); + } if (result == DNS_R_NXRRSET) { result = dns_db_find(db, name, version, dns_rdatatype_aaaa, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return (true); + } } if (result == DNS_R_NXRRSET || result == DNS_R_NXDOMAIN || @@ -5262,8 +5401,10 @@ zone_count_ns_rr(dns_zone_t *zone, dns_db_t *db, dns_dbnode_t *node, result = dns_rdata_tostruct(&rdata, &ns, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); if (dns_name_issubdomain(&ns.name, &zone->origin) && - !zone_check_ns(zone, db, version, &ns.name, logit)) + !zone_check_ns(zone, db, version, &ns.name, + logit)) { ecount++; + } } count++; result = dns_rdataset_next(&rdataset); @@ -5271,10 +5412,12 @@ zone_count_ns_rr(dns_zone_t *zone, dns_db_t *db, dns_dbnode_t *node, dns_rdataset_disassociate(&rdataset); success: - if (nscount != NULL) + if (nscount != NULL) { *nscount = count; - if (errors != NULL) + } + if (errors != NULL) { *errors = ecount; + } result = ISC_R_SUCCESS; @@ -5300,18 +5443,24 @@ zone_load_soa_rr(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, dns_rdatatype_none, 0, &rdataset, NULL); if (result == ISC_R_NOTFOUND) { INSIST(!dns_rdataset_isassociated(&rdataset)); - if (soacount != NULL) + if (soacount != NULL) { *soacount = 0; - if (serial != NULL) + } + if (serial != NULL) { *serial = 0; - if (refresh != NULL) + } + if (refresh != NULL) { *refresh = 0; - if (retry != NULL) + } + if (retry != NULL) { *retry = 0; - if (expire != NULL) + } + if (expire != NULL) { *expire = 0; - if (minimum != NULL) + } + if (minimum != NULL) { *minimum = 0; + } result = ISC_R_SUCCESS; goto invalidate_rdataset; } @@ -5336,33 +5485,45 @@ zone_load_soa_rr(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, } dns_rdataset_disassociate(&rdataset); - if (soacount != NULL) + if (soacount != NULL) { *soacount = count; + } if (count > 0) { - if (serial != NULL) + if (serial != NULL) { *serial = soa.serial; - if (refresh != NULL) + } + if (refresh != NULL) { *refresh = soa.refresh; - if (retry != NULL) + } + if (retry != NULL) { *retry = soa.retry; - if (expire != NULL) + } + if (expire != NULL) { *expire = soa.expire; - if (minimum != NULL) + } + if (minimum != NULL) { *minimum = soa.minimum; + } } else { - if (soacount != NULL) + if (soacount != NULL) { *soacount = 0; - if (serial != NULL) + } + if (serial != NULL) { *serial = 0; - if (refresh != NULL) + } + if (refresh != NULL) { *refresh = 0; - if (retry != NULL) + } + if (retry != NULL) { *retry = 0; - if (expire != NULL) + } + if (expire != NULL) { *expire = 0; - if (minimum != NULL) + } + if (minimum != NULL) { *minimum = 0; + } } result = ISC_R_SUCCESS; @@ -5392,20 +5553,27 @@ zone_get_from_db(dns_zone_t *zone, dns_db_t *db, unsigned int *nscount, dns_db_currentversion(db, &version); - if (nscount != NULL) + if (nscount != NULL) { *nscount = 0; - if (soacount != NULL) + } + if (soacount != NULL) { *soacount = 0; - if (serial != NULL) + } + if (serial != NULL) { *serial = 0; - if (refresh != NULL) + } + if (refresh != NULL) { *refresh = 0; - if (retry != NULL) + } + if (retry != NULL) { *retry = 0; - if (expire != NULL) + } + if (expire != NULL) { *expire = 0; - if (errors != NULL) + } + if (errors != NULL) { *errors = 0; + } node = NULL; result = dns_db_findnode(db, &zone->origin, false, &node); @@ -5417,16 +5585,18 @@ zone_get_from_db(dns_zone_t *zone, dns_db_t *db, unsigned int *nscount, if (nscount != NULL || errors != NULL) { result = zone_count_ns_rr(zone, db, node, version, nscount, errors, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { answer = result; + } } if (soacount != NULL || serial != NULL || refresh != NULL || retry != NULL || expire != NULL || minimum != NULL) { result = zone_load_soa_rr(db, node, version, soacount, serial, refresh, retry, expire, minimum); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { answer = result; + } } dns_db_detachnode(db, &node); @@ -5886,17 +6056,21 @@ same_keynames(dns_name_t *const *oldlist, dns_name_t *const *newlist, { unsigned int i; - if (oldlist == NULL && newlist == NULL) + if (oldlist == NULL && newlist == NULL) { return (true); - if (oldlist == NULL || newlist == NULL) + } + if (oldlist == NULL || newlist == NULL) { return (false); + } for (i = 0; i < count; i++) { - if (oldlist[i] == NULL && newlist[i] == NULL) + if (oldlist[i] == NULL && newlist[i] == NULL) { continue; + } if (oldlist[i] == NULL || newlist[i] == NULL || - !dns_name_equal(oldlist[i], newlist[i])) + !dns_name_equal(oldlist[i], newlist[i])) { return (false); + } } return (true); } @@ -5923,11 +6097,13 @@ clear_addresskeylist(isc_sockaddr_t **addrsp, isc_dscp_t **dscpsp, keynames = *keynamesp; *keynamesp = NULL; - if (addrs != NULL) + if (addrs != NULL) { isc_mem_put(mctx, addrs, count * sizeof(isc_sockaddr_t)); + } - if (dscps != NULL) + if (dscps != NULL) { isc_mem_put(mctx, dscps, count * sizeof(isc_dscp_t)); + } if (keynames != NULL) { unsigned int i; @@ -5964,13 +6140,15 @@ set_addrkeylist(unsigned int count, const isc_sockaddr_t *addrs, if (dscp != NULL) { newdscp = isc_mem_get(mctx, count * sizeof(*newdscp)); memmove(newdscp, dscp, count * sizeof(*newdscp)); - } else + } else { newdscp = NULL; + } if (names != NULL) { newnames = isc_mem_get(mctx, count * sizeof(*newnames)); - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { newnames[i] = NULL; + } for (i = 0; i < count; i++) { if (names[i] != NULL) { newnames[i] = @@ -5979,8 +6157,9 @@ set_addrkeylist(unsigned int count, const isc_sockaddr_t *addrs, dns_name_dup(names[i], mctx, newnames[i]); } } - } else + } else { newnames = NULL; + } *newdscpp = newdscp; *newaddrsp = newaddrs; @@ -6035,30 +6214,34 @@ dns_zone_setalsonotifydscpkeys(dns_zone_t *zone, const isc_sockaddr_t *notify, REQUIRE(DNS_ZONE_VALID(zone)); REQUIRE(count == 0 || notify != NULL); - if (keynames != NULL) + if (keynames != NULL) { REQUIRE(count != 0); + } LOCK_ZONE(zone); if (count == zone->notifycnt && same_addrs(zone->notify, notify, count) && - same_keynames(zone->notifykeynames, keynames, count)) + same_keynames(zone->notifykeynames, keynames, count)) { goto unlock; + } clear_addresskeylist(&zone->notify, &zone->notifydscp, &zone->notifykeynames, &zone->notifycnt, zone->mctx); - if (count == 0) + if (count == 0) { goto unlock; + } /* * Set up the notify and notifykey lists */ result = set_addrkeylist(count, notify, &newaddrs, dscps, &newdscps, keynames, &newnames, zone->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } /* * Everything is ok so attach to the zone. @@ -6109,10 +6292,12 @@ dns_zone_setmasterswithkeys(dns_zone_t *zone, const isc_sockaddr_t *masters, if (count != zone->masterscnt || !same_addrs(zone->masters, masters, count) || !same_keynames(zone->masterkeynames, keynames, count)) { - if (zone->request != NULL) + if (zone->request != NULL) { dns_request_cancel(zone->request); - } else + } + } else { goto unlock; + } /* * This needs to happen before clear_addresskeylist() sets @@ -6130,16 +6315,17 @@ dns_zone_setmasterswithkeys(dns_zone_t *zone, const isc_sockaddr_t *masters, * If count == 0, don't allocate any space for masters, mastersok or * keynames so internally, those pointers are NULL if count == 0 */ - if (count == 0) + if (count == 0) { goto unlock; + } /* * mastersok must contain count elements */ newok = isc_mem_get(zone->mctx, count * sizeof(*newok)); - ; - for (i = 0; i < count; i++) + for (i = 0; i < count; i++) { newok[i] = false; + } /* * Now set up the masters and masterkey lists @@ -6176,10 +6362,11 @@ dns_zone_getdb(dns_zone_t *zone, dns_db_t **dpb) REQUIRE(DNS_ZONE_VALID(zone)); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db == NULL) + if (zone->db == NULL) { result = DNS_R_NOTLOADED; - else + } else { dns_db_attach(zone->db, dpb); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); return (result); @@ -6250,11 +6437,13 @@ dns__zone_findkeys(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, result = dns_dnssec_findzonekeys(db, ver, node, dns_db_origin(db), directory, now, mctx, maxkeys, keys, nkeys); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; + } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -6264,12 +6453,14 @@ offline(dns_db_t *db, dns_dbversion_t *ver, dns__zonediff_t *zonediff, { isc_result_t result; - if ((rdata->flags & DNS_RDATA_OFFLINE) != 0) + if ((rdata->flags & DNS_RDATA_OFFLINE) != 0) { return (ISC_R_SUCCESS); + } result = update_one_rr(db, ver, zonediff->diff, DNS_DIFFOP_DELRESIGN, name, ttl, rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } rdata->flags |= DNS_RDATA_OFFLINE; result = update_one_rr(db, ver, zonediff->diff, DNS_DIFFOP_ADDRESIGN, name, ttl, rdata); @@ -6355,15 +6546,17 @@ delsig_ok(dns_rdata_rrsig_t *rrsig_ptr, dst_key_t **keys, unsigned int nkeys, } } - if (have_zsk && have_ksk && !have_pzsk) + if (have_zsk && have_ksk && !have_pzsk) { *warn = true; + } /* * It's okay to delete a signature if there is an active key * with the same algorithm to replace it. */ - if (have_pksk || have_pzsk) + if (have_pksk || have_pzsk) { return (true); + } /* * Failing that, it is *not* okay to delete a signature @@ -6371,8 +6564,9 @@ delsig_ok(dns_rdata_rrsig_t *rrsig_ptr, dst_key_t **keys, unsigned int nkeys, */ for (i = 0; i < nkeys; i++) { if ((rrsig_ptr->algorithm == dst_key_alg(keys[i])) && - (rrsig_ptr->keyid == dst_key_id(keys[i]))) + (rrsig_ptr->keyid == dst_key_id(keys[i]))) { return (false); + } } /* @@ -6400,14 +6594,17 @@ del_sigs(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_rdataset_init(&rdataset); - if (type == dns_rdatatype_nsec3) + if (type == dns_rdatatype_nsec3) { result = dns_db_findnsec3node(db, name, false, &node); - else + } else { result = dns_db_findnode(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + } + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_db_findrdataset(db, node, ver, dns_rdatatype_rrsig, type, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); @@ -6437,8 +6634,9 @@ del_sigs(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, DNS_DIFFOP_DELRESIGN, name, rdataset.ttl, &rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } deleted = true; } if (warn) { @@ -6455,8 +6653,9 @@ del_sigs(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = offline(db, ver, zonediff, name, rdataset.ttl, &rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } /* @@ -6503,19 +6702,23 @@ del_sigs(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, int64_t timeexpire = dns_time64_from32( rrsig.timeexpire); if (timewarn != 0 && - timewarn > timeexpire) + timewarn > timeexpire) { timewarn = timeexpire; + } if (rdata.flags & DNS_RDATA_OFFLINE) { if (timemaybe == 0 || - timemaybe > timeexpire) + timemaybe > timeexpire) { timemaybe = timeexpire; + } break; } - if (timewarn == 0) + if (timewarn == 0) { timewarn = timemaybe; + } if (timewarn == 0 || - timewarn > timeexpire) + timewarn > timeexpire) { timewarn = timeexpire; + } result = offline(db, ver, zonediff, name, rdataset.ttl, &rdata); @@ -6538,13 +6741,15 @@ del_sigs(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, DNS_DIFFOP_DELRESIGN, name, rdataset.ttl, &rdata); } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } dns_rdataset_disassociate(&rdataset); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } if (timewarn > 0) { isc_stdtime_t stdwarn = (isc_stdtime_t)timewarn; if (timewarn == stdwarn) { @@ -6556,8 +6761,9 @@ del_sigs(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, } } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -6586,14 +6792,17 @@ add_sigs(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_zone_t *zone, dns_rdataset_init(&rdataset); isc_buffer_init(&buffer, data, sizeof(data)); - if (type == dns_rdatatype_nsec3) + if (type == dns_rdatatype_nsec3) { result = dns_db_findnsec3node(db, name, false, &node); - else + } else { result = dns_db_findnode(db, name, false, &node); - if (result == ISC_R_NOTFOUND) + } + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_db_findrdataset(db, node, ver, type, 0, (isc_stdtime_t)0, &rdataset, NULL); dns_db_detachnode(db, &node); @@ -6716,8 +6925,9 @@ add_sigs(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_zone_t *zone, if (type == dns_rdatatype_dnskey || type == dns_rdatatype_cdnskey || type == dns_rdatatype_cds) { - if (!KSK(keys[i]) && keyset_kskonly) + if (!KSK(keys[i]) && keyset_kskonly) { continue; + } } else if (KSK(keys[i])) { continue; } @@ -6753,10 +6963,12 @@ add_sigs(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_zone_t *zone, } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -6879,8 +7091,9 @@ zone_resigninc(dns_zone_t *zone) */ /* XXXMPA increase number of RRsets signed pre call */ if (covers == dns_rdatatype_soa || i++ > zone->signatures || - resign > stop) + resign > stop) { break; + } result = del_sigs(zone, db, version, name, covers, &zonediff, zone_keys, nkeys, now, true); @@ -6913,15 +7126,17 @@ zone_resigninc(dns_zone_t *zone) result = ISC_R_SUCCESS; break; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_ERROR, "zone_resigninc:dns_db_getsigningtime -> " "%s", dns_result_totext(result)); + } } - if (result != ISC_R_NOMORE && result != ISC_R_SUCCESS) + if (result != ISC_R_NOMORE && result != ISC_R_SUCCESS) { goto failure; + } result = del_sigs(zone, db, version, &zone->origin, dns_rdatatype_soa, &zonediff, zone_keys, nkeys, now, true); @@ -6939,8 +7154,9 @@ zone_resigninc(dns_zone_t *zone) /* * Commit the changes if any key has been marked as offline. */ - if (zonediff.offline) + if (zonediff.offline) { dns_db_closeversion(db, &version, true); + } goto failure; } @@ -6976,13 +7192,15 @@ zone_resigninc(dns_zone_t *zone) failure: dns_diff_clear(&_sig_diff); - for (i = 0; i < nkeys; i++) + for (i = 0; i < nkeys; i++) { dst_key_free(&zone_keys[i]); + } if (version != NULL) { dns_db_closeversion(db, &version, false); dns_db_detach(&db); - } else if (db != NULL) + } else if (db != NULL) { dns_db_detach(&db); + } if (result == ISC_R_SUCCESS) { set_resigntime(zone); LOCK_ZONE(zone); @@ -7014,8 +7232,9 @@ next_active(dns_db_t *db, dns_dbversion_t *version, dns_name_t *oldname, CHECK(dns_dbiterator_seek(dbit, oldname)); do { result = dns_dbiterator_next(dbit); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { CHECK(dns_dbiterator_first(dbit)); + } CHECK(dns_dbiterator_current(dbit, &node, newname)); if (bottom && dns_name_issubdomain(newname, oldname) && !dns_name_equal(newname, oldname)) { @@ -7029,14 +7248,17 @@ next_active(dns_db_t *db, dns_dbversion_t *version, dns_name_t *oldname, result = dns_rdatasetiter_first(rdsit); dns_db_detachnode(db, &node); dns_rdatasetiter_destroy(&rdsit); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { break; + } } while (1); failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); - if (dbit != NULL) + } + if (dbit != NULL) { dns_dbiterator_destroy(&dbit); + } return (result); } @@ -7204,8 +7426,9 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, result = dns_db_allrdatasets(db, node, version, 0, &iterator); if (result != ISC_R_SUCCESS) { - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; + } return (result); } @@ -7215,22 +7438,25 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, for (result = dns_rdatasetiter_first(iterator); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(iterator)) { dns_rdatasetiter_current(iterator, &rdataset); - if (rdataset.type == dns_rdatatype_soa) + if (rdataset.type == dns_rdatatype_soa) { seen_soa = true; - else if (rdataset.type == dns_rdatatype_ns) + } else if (rdataset.type == dns_rdatatype_ns) { seen_ns = true; - else if (rdataset.type == dns_rdatatype_ds) + } else if (rdataset.type == dns_rdatatype_ds) { seen_ds = true; - else if (rdataset.type == dns_rdatatype_nsec) + } else if (rdataset.type == dns_rdatatype_nsec) { seen_nsec = true; - else if (rdataset.type == dns_rdatatype_nsec3) + } else if (rdataset.type == dns_rdatatype_nsec3) { seen_nsec3 = true; - if (rdataset.type != dns_rdatatype_rrsig) + } + if (rdataset.type != dns_rdatatype_rrsig) { seen_rr = true; + } dns_rdataset_disassociate(&rdataset); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } /* * Going from insecure to NSEC3. * Don't generate NSEC3 records for NSEC3 records. @@ -7325,13 +7551,16 @@ sign_a_node(dns_db_t *db, dns_zone_t *zone, dns_name_t *name, dns_rdataset_disassociate(&rdataset); result = dns_rdatasetiter_next(iterator); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (iterator != NULL) + } + if (iterator != NULL) { dns_rdatasetiter_destroy(&iterator); + } return (result); } @@ -7352,20 +7581,24 @@ updatesecure(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, result = dns_db_findrdataset( db, node, version, dns_rdatatype_nsec, dns_rdatatype_none, 0, &rdataset, NULL); - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (result == ISC_R_NOTFOUND) + } + if (result == ISC_R_NOTFOUND) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } } CHECK(delete_nsec(db, version, node, name, diff)); CHECK(add_nsec(db, version, name, node, minimum, false, diff)); success: result = ISC_R_SUCCESS; failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -7384,8 +7617,9 @@ updatesignwithkey(dns_zone_t *zone, dns_signing_t *signing, dns_rdataset_init(&rdataset); result = dns_db_getoriginnode(signing->db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_db_findrdataset(signing->db, node, version, zone->privatetype, dns_rdatatype_none, 0, @@ -7426,14 +7660,16 @@ updatesignwithkey(dns_zone_t *zone, dns_signing_t *signing, if (!signing->deleteit && rdata.data[4] != 0) { seen_done = true; have_rr = true; - } else + } else { CHECK(update_one_rr(signing->db, version, diff, DNS_DIFFOP_DEL, &zone->origin, rdataset.ttl, &rdata)); + } dns_rdata_reset(&rdata); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } if (!signing->deleteit && !seen_done) { /* * If we were signing then we need to indicate that we have @@ -7457,18 +7693,21 @@ updatesignwithkey(dns_zone_t *zone, dns_signing_t *signing, * Rebuild the NSEC/NSEC3 record for the origin as we no * longer have any private records. */ - if (build_nsec3) + if (build_nsec3) { CHECK(dns_nsec3_addnsec3s(signing->db, version, origin, minimum, false, diff)); + } CHECK(updatesecure(signing->db, version, origin, minimum, true, diff)); } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(signing->db, &node); + } return (result); } @@ -7517,10 +7756,12 @@ fixup_nsec3param(dns_db_t *db, dns_dbversion_t *ver, dns_nsec3chain_t *chain, RUNTIME_CHECK(result == ISC_R_SUCCESS); result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3param, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto try_private; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Preserve the existing ttl. @@ -7549,15 +7790,17 @@ fixup_nsec3param(dns_db_t *db, dns_dbversion_t *ver, dns_nsec3chain_t *chain, rdataset.ttl, &rdata)); dns_rdata_reset(&rdata); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } dns_rdataset_disassociate(&rdataset); try_private: - if (active) + if (active) { goto add; + } result = dns_nsec_nseconly(db, ver, &nseconly); nsec3ok = (result == ISC_R_SUCCESS && !nseconly); @@ -7567,10 +7810,12 @@ try_private: */ result = dns_db_findrdataset(db, node, ver, privatetype, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto add; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -7579,8 +7824,9 @@ try_private: dns_rdataset_current(&rdataset, &private); if (!dns_nsec3param_fromprivate(&private, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); if ((!nsec3ok && @@ -7598,8 +7844,9 @@ try_private: rdataset.ttl, &private)); dns_rdata_reset(&rdata); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } add: if ((chain->nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) { @@ -7623,8 +7870,9 @@ add: failure: dns_db_detachnode(db, &node); - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -7639,10 +7887,12 @@ delete_nsec(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { dns_rdata_t rdata = DNS_RDATA_INIT; @@ -7651,8 +7901,9 @@ delete_nsec(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, CHECK(update_one_rr(db, ver, diff, DNS_DIFFOP_DEL, name, rdataset.ttl, &rdata)); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: dns_rdataset_disassociate(&rdataset); return (result); @@ -7670,10 +7921,12 @@ deletematchingnsec3(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3, 0, 0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -7684,13 +7937,15 @@ deletematchingnsec3(dns_db_t *db, dns_dbversion_t *ver, dns_dbnode_t *node, if (nsec3.hash != param->hash || nsec3.iterations != param->iterations || nsec3.salt_length != param->salt_length || - memcmp(nsec3.salt, param->salt, nsec3.salt_length)) + memcmp(nsec3.salt, param->salt, nsec3.salt_length)) { continue; + } CHECK(update_one_rr(db, ver, diff, DNS_DIFFOP_DEL, name, rdataset.ttl, &rdata)); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: dns_rdataset_disassociate(&rdataset); return (result); @@ -7745,16 +8000,18 @@ need_nsec_chain(dns_db_t *db, dns_dbversion_t *ver, /* * Ignore any NSEC3PARAM removals. */ - if (NSEC3REMOVE(myparam.flags)) + if (NSEC3REMOVE(myparam.flags)) { continue; + } /* * Ignore the chain that we are in the process of deleting. */ if (myparam.hash == param->hash && myparam.iterations == param->iterations && myparam.salt_length == param->salt_length && - !memcmp(myparam.salt, param->salt, myparam.salt_length)) + !memcmp(myparam.salt, param->salt, myparam.salt_length)) { continue; + } /* * Found an active NSEC3 chain. */ @@ -7766,8 +8023,9 @@ need_nsec_chain(dns_db_t *db, dns_dbversion_t *ver, } failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } dns_db_detachnode(db, &node); return (result); } @@ -8040,8 +8298,9 @@ zone_nsec3chain(dns_zone_t *zone) } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); UNLOCK_ZONE(zone); - if (ISC_LIST_TAIL(cleanup) == nsec3chain) + if (ISC_LIST_TAIL(cleanup) == nsec3chain) { goto next_addchain; + } /* * Possible future db. @@ -8050,8 +8309,9 @@ zone_nsec3chain(dns_zone_t *zone) goto next_addchain; } - if (NSEC3REMOVE(nsec3chain->nsec3param.flags)) + if (NSEC3REMOVE(nsec3chain->nsec3param.flags)) { goto next_addchain; + } dns_dbiterator_current(nsec3chain->dbiterator, &node, name); @@ -8206,8 +8466,9 @@ zone_nsec3chain(dns_zone_t *zone) dns_dbiterator_current(nsec3chain->dbiterator, &node, nextname); dns_db_detachnode(db, &node); - if (!dns_name_issubdomain(nextname, name)) + if (!dns_name_issubdomain(nextname, name)) { break; + } } else { break; } @@ -8764,8 +9025,9 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, result = dns_db_allrdatasets(db, node, version, 0, &iterator); if (result != ISC_R_SUCCESS) { - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; + } return (result); } @@ -8784,8 +9046,9 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, DNS_DIFFOP_DEL, name, rdataset.ttl, &rdata)); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } dns_rdataset_disassociate(&rdataset); continue; } @@ -8811,8 +9074,9 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, rdataset.ttl, &rdata)); } dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { break; + } /* * After deleting, if there's still a signature for @@ -8824,8 +9088,9 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, alg_missed = true; } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } /* * Set `has_algp` if the algorithm was found in every RRset: @@ -8833,8 +9098,9 @@ del_sig(dns_db_t *db, dns_dbversion_t *version, dns_name_t *name, */ *has_algp = (alg_found && !alg_missed); failure: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } dns_rdatasetiter_destroy(&iterator); return (result); } @@ -9465,8 +9731,9 @@ normalize_key(dns_rdata_t *rr, dns_rdata_t *target, unsigned char *data, break; case dns_rdatatype_keydata: result = dns_rdata_tostruct(rr, &keydata, NULL); - if (result == ISC_R_UNEXPECTEDEND) + if (result == ISC_R_UNEXPECTEDEND) { return (result); + } RUNTIME_CHECK(result == ISC_R_SUCCESS); dns_keydata_todnskey(&keydata, &dnskey, NULL); dns_rdata_fromstruct(target, rr->rdclass, dns_rdatatype_dnskey, @@ -9502,18 +9769,21 @@ matchkey(dns_rdataset_t *rdset, dns_rdata_t *rr) dns_rdata_init(&rdata2); result = normalize_key(rr, &rdata1, data1, sizeof(data1)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } for (result = dns_rdataset_first(rdset); result == ISC_R_SUCCESS; result = dns_rdataset_next(rdset)) { dns_rdata_reset(&rdata); dns_rdataset_current(rdset, &rdata); result = normalize_key(&rdata, &rdata2, data2, sizeof(data2)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; - if (dns_rdata_compare(&rdata1, &rdata2) == 0) + } + if (dns_rdata_compare(&rdata1, &rdata2) == 0) { return (true); + } } return (false); @@ -9542,14 +9812,16 @@ refresh_time(dns_keyfetch_t *kfetch, bool retry) isc_stdtime_get(&now); - if (dns_rdataset_isassociated(&kfetch->dnskeysigset)) + if (dns_rdataset_isassociated(&kfetch->dnskeysigset)) { rdset = &kfetch->dnskeysigset; - else + } else { return (now + dns_zone_mkey_hour); + } result = dns_rdataset_first(rdset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (now + dns_zone_mkey_hour); + } dns_rdataset_current(rdset, &sigrr); result = dns_rdata_tostruct(&sigrr, &sig, NULL); @@ -9560,29 +9832,35 @@ refresh_time(dns_keyfetch_t *kfetch, bool retry) if (isc_serial_gt(sig.timeexpire, now)) { uint32_t exp = (sig.timeexpire - now) / 2; - if (t > exp) + if (t > exp) { t = exp; + } } - if (t > (15 * dns_zone_mkey_day)) + if (t > (15 * dns_zone_mkey_day)) { t = (15 * dns_zone_mkey_day); + } - if (t < dns_zone_mkey_hour) + if (t < dns_zone_mkey_hour) { t = dns_zone_mkey_hour; + } } else { t = sig.originalttl / 10; if (isc_serial_gt(sig.timeexpire, now)) { uint32_t exp = (sig.timeexpire - now) / 10; - if (t > exp) + if (t > exp) { t = exp; + } } - if (t > dns_zone_mkey_day) + if (t > dns_zone_mkey_day) { t = dns_zone_mkey_day; + } - if (t < dns_zone_mkey_hour) + if (t < dns_zone_mkey_hour) { t = dns_zone_mkey_hour; + } } return (now + t); @@ -9620,10 +9898,12 @@ minimal_update(dns_keyfetch_t *kfetch, dns_dbversion_t *ver, dns_diff_t *diff) /* Update refresh timer */ result = dns_rdata_tostruct(&rdata, &keydata, NULL); - if (result == ISC_R_UNEXPECTEDEND) + if (result == ISC_R_UNEXPECTEDEND) { continue; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } keydata.refresh = refresh_time(kfetch, true); set_refreshkeytimer(zone, &keydata, now, false); @@ -10498,7 +10778,7 @@ zone_refreshkeys(dns_zone_t *zone) #ifdef ENABLE_AFL if (dns_fuzzing_resolver == false) { -#endif +#endif /* ifdef ENABLE_AFL */ result = dns_resolver_createfetch( zone->view->resolver, kname, dns_rdatatype_dnskey, NULL, NULL, NULL, NULL, 0, @@ -10512,7 +10792,7 @@ zone_refreshkeys(dns_zone_t *zone) } else { result = ISC_R_FAILURE; } -#endif +#endif /* ifdef ENABLE_AFL */ if (result == ISC_R_SUCCESS) { fetching = true; } else { @@ -10601,8 +10881,9 @@ zone_maintenance(dns_zone_t *zone) * adb or resolver will be NULL, and we had better not try * to do further maintenance on it. */ - if (zone->view == NULL || zone->view->adb == NULL) + if (zone->view == NULL || zone->view->adb == NULL) { return; + } TIME_NOW(&now); @@ -10611,9 +10892,10 @@ zone_maintenance(dns_zone_t *zone) */ switch (zone->type) { case dns_zone_redirect: - if (zone->masters == NULL) + if (zone->masters == NULL) { break; - /* FALLTHROUGH */ + } + /* FALLTHROUGH */ case dns_zone_slave: case dns_zone_mirror: case dns_zone_stub: @@ -10634,15 +10916,17 @@ zone_maintenance(dns_zone_t *zone) */ switch (zone->type) { case dns_zone_redirect: - if (zone->masters == NULL) + if (zone->masters == NULL) { break; - /* FALLTHROUGH */ + } + /* FALLTHROUGH */ case dns_zone_slave: case dns_zone_mirror: case dns_zone_stub: if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH) && - isc_time_compare(&now, &zone->refreshtime) >= 0) + isc_time_compare(&now, &zone->refreshtime) >= 0) { dns_zone_refresh(zone); + } break; default: break; @@ -10654,8 +10938,9 @@ zone_maintenance(dns_zone_t *zone) if ((zone->type == dns_zone_slave || zone->type == dns_zone_mirror) && (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDNOTIFY) || DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDSTARTUPNOTIFY)) && - isc_time_compare(&now, &zone->notifytime) >= 0) + isc_time_compare(&now, &zone->notifytime) >= 0) { zone_notify(zone, &now); + } /* * Do we need to consolidate the backing store? @@ -10673,15 +10958,17 @@ zone_maintenance(dns_zone_t *zone) DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) && DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP)) { dumping = was_dumping(zone); - } else + } else { dumping = true; + } UNLOCK_ZONE(zone); if (!dumping) { result = zone_dump(zone, true); /* task locked */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_WARNING, "dump failed: %s", dns_result_totext(result)); + } } break; default: @@ -10696,8 +10983,9 @@ zone_maintenance(dns_zone_t *zone) case dns_zone_redirect: if ((DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDNOTIFY) || DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDSTARTUPNOTIFY)) && - isc_time_compare(&now, &zone->notifytime) >= 0) + isc_time_compare(&now, &zone->notifytime) >= 0) { zone_notify(zone, &now); + } default: break; } @@ -10717,8 +11005,9 @@ zone_maintenance(dns_zone_t *zone) case dns_zone_master: if (!isc_time_isepoch(&zone->refreshkeytime) && isc_time_compare(&now, &zone->refreshkeytime) >= 0 && - zone->rss_event == NULL) + zone->rss_event == NULL) { zone_rekey(zone); + } default: break; } @@ -10730,8 +11019,9 @@ zone_maintenance(dns_zone_t *zone) /* * Do we need to sign/resign some RRsets? */ - if (zone->rss_event != NULL) + if (zone->rss_event != NULL) { break; + } if (!isc_time_isepoch(&zone->signingtime) && isc_time_compare(&now, &zone->signingtime) >= 0) { zone_sign(zone); @@ -10746,9 +11036,10 @@ zone_maintenance(dns_zone_t *zone) * Do we need to issue a key expiry warning? */ if (!isc_time_isepoch(&zone->keywarntime) && - isc_time_compare(&now, &zone->keywarntime) >= 0) + isc_time_compare(&now, &zone->keywarntime) >= 0) { set_key_expiry_warning(zone, zone->key_expiry, isc_time_seconds(&now)); + } break; default: @@ -10791,19 +11082,23 @@ again: result = zone_get_from_db( zone, zone->db, NULL, &soacount, &serial, NULL, NULL, NULL, NULL, NULL); - } else + } else { result = DNS_R_NOTLOADED; + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); - if (result == ISC_R_SUCCESS && soacount > 0U) + if (result == ISC_R_SUCCESS && soacount > 0U) { zone_send_secureserial(zone, serial); + } } /* XXXMPA make separate call back */ - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { set_resigntime(zone); + } } - if (secure != NULL) + if (secure != NULL) { UNLOCK_ZONE(secure); + } zone_needdump(zone, DNS_DUMP_DELAY); UNLOCK_ZONE(zone); } @@ -10874,8 +11169,9 @@ dns_zone_refresh(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) { return; + } /* * Set DNS_ZONEFLG_REFRESH so that there is only one refresh operation @@ -10886,16 +11182,18 @@ dns_zone_refresh(dns_zone_t *zone) oldflags = atomic_load(&zone->flags); if (zone->masterscnt == 0) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NOMASTERS); - if ((oldflags & DNS_ZONEFLG_NOMASTERS) == 0) + if ((oldflags & DNS_ZONEFLG_NOMASTERS) == 0) { dns_zone_log(zone, ISC_LOG_ERROR, "cannot refresh: no masters"); + } goto unlock; } DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_REFRESH); DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NOEDNS); DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC); - if ((oldflags & (DNS_ZONEFLG_REFRESH | DNS_ZONEFLG_LOADING)) != 0) + if ((oldflags & (DNS_ZONEFLG_REFRESH | DNS_ZONEFLG_LOADING)) != 0) { goto unlock; + } /* * Set the next refresh time as if refresh check has failed. @@ -10905,22 +11203,25 @@ dns_zone_refresh(dns_zone_t *zone) isc_interval_set(&i, zone->retry - isc_random_uniform(zone->retry / 4), 0); result = isc_time_nowplusinterval(&zone->refreshtime, &i); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_WARNING, "isc_time_nowplusinterval() failed: %s", dns_result_totext(result)); + } /* * When lacking user-specified timer values from the SOA, * do exponential backoff of the retry time up to a * maximum of six hours. */ - if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_HAVETIMERS)) + if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_HAVETIMERS)) { zone->retry = ISC_MIN(zone->retry * 2, 6 * 3600); + } zone->curmaster = 0; - for (j = 0; j < zone->masterscnt; j++) + for (j = 0; j < zone->masterscnt; j++) { zone->mastersok[j] = false; + } /* initiate soa query */ queue_soa_query(zone); unlock: @@ -10936,8 +11237,9 @@ zone_journal_compact(dns_zone_t *zone, dns_db_t *db, uint32_t serial) uint64_t dbsize; INSIST(LOCKED_ZONE(zone)); - if (inline_raw(zone)) + if (inline_raw(zone)) { INSIST(LOCKED_ZONE(zone->secure)); + } journalsize = zone->journalsize; if (journalsize == -1) { @@ -10987,11 +11289,13 @@ dns_zone_flush(dns_zone_t *zone) zone->masterfile != NULL) { result = ISC_R_ALREADYRUNNING; dumping = was_dumping(zone); - } else + } else { dumping = true; + } UNLOCK_ZONE(zone); - if (!dumping) + if (!dumping) { result = zone_dump(zone, true); /* Unknown task. */ + } return (result); } @@ -11006,8 +11310,9 @@ dns_zone_dump(dns_zone_t *zone) LOCK_ZONE(zone); dumping = was_dumping(zone); UNLOCK_ZONE(zone); - if (!dumping) + if (!dumping) { result = zone_dump(zone, false); /* Unknown task. */ + } return (result); } @@ -11030,8 +11335,9 @@ zone_needdump(dns_zone_t *zone, unsigned int delay) * Do we have a place to dump to and are we loaded? */ if (zone->masterfile == NULL || - DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) == 0) + DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) == 0) { return; + } TIME_NOW(&now); /* add some noise */ @@ -11039,10 +11345,12 @@ zone_needdump(dns_zone_t *zone, unsigned int delay) DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NEEDDUMP); if (isc_time_isepoch(&zone->dumptime) || - isc_time_compare(&zone->dumptime, &dumptime) > 0) + isc_time_compare(&zone->dumptime, &dumptime) > 0) { zone->dumptime = dumptime; - if (zone->task != NULL) + } + if (zone->task != NULL) { zone_settimer(zone, &now); + } } static void @@ -11100,8 +11408,9 @@ dump_done(void *arg, isc_result_t result) mresult = dns_db_getsoaserial(zone->secure->db, NULL, &sserial); if (mresult == ISC_R_SUCCESS && - isc_serial_lt(sserial, serial)) + isc_serial_lt(sserial, serial)) { serial = sserial; + } } ZONEDB_UNLOCK(&secure->dblock, isc_rwlocktype_read); } @@ -11115,15 +11424,17 @@ dump_done(void *arg, isc_result_t result) compact = true; zone->compact_serial = serial; } - if (secure != NULL) + if (secure != NULL) { UNLOCK_ZONE(secure); + } UNLOCK_ZONE(zone); } LOCK_ZONE(zone); DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_DUMPING); - if (compact) + if (compact) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NEEDCOMPACT); + } if (result != ISC_R_SUCCESS && result != ISC_R_CANCELED) { /* * Try again in a short while. @@ -11137,15 +11448,18 @@ dump_done(void *arg, isc_result_t result) DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_DUMPING); isc_time_settoepoch(&zone->dumptime); again = true; - } else if (result == ISC_R_SUCCESS) + } else if (result == ISC_R_SUCCESS) { DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_FLUSH); + } - if (zone->dctx != NULL) + if (zone->dctx != NULL) { dns_dumpctx_detach(&zone->dctx); + } zonemgr_putio(&zone->writeio); UNLOCK_ZONE(zone); - if (again) + if (again) { (void)zone_dump(zone, false); + } dns_zone_idetach(&zone); } @@ -11169,8 +11483,9 @@ zone_dump(dns_zone_t *zone, bool compact) redo: ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_attach(zone->db, &db); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); LOCK_ZONE(zone); if (zone->masterfile != NULL) { @@ -11194,10 +11509,11 @@ redo: result = zonemgr_getio(zone->zmgr, false, zone->task, zone_gotwritehandle, zone, &zone->writeio); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { zone_idetach(&dummy); - else + } else { result = DNS_R_CONTINUE; + } UNLOCK_ZONE(zone); } else { const dns_master_style_t *output_style; @@ -11205,25 +11521,30 @@ redo: dns_masterrawheader_t rawdata; dns_db_currentversion(db, &version); dns_master_initrawheader(&rawdata); - if (inline_secure(zone)) + if (inline_secure(zone)) { get_raw_serial(zone->raw, &rawdata); - if (zone->type == dns_zone_key) + } + if (zone->type == dns_zone_key) { output_style = &dns_master_style_keyzone; - else + } else { output_style = &dns_master_style_default; + } result = dns_master_dump(zone->mctx, db, version, output_style, masterfile, masterformat, &rawdata); dns_db_closeversion(db, &version, false); } fail: - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); - if (masterfile != NULL) + } + if (masterfile != NULL) { isc_mem_free(zone->mctx, masterfile); + } masterfile = NULL; - if (result == DNS_R_CONTINUE) + if (result == DNS_R_CONTINUE) { return (ISC_R_SUCCESS); /* XXXMPA */ + } again = false; LOCK_ZONE(zone); @@ -11240,11 +11561,13 @@ fail: DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_DUMPING); isc_time_settoepoch(&zone->dumptime); again = true; - } else + } else { DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_FLUSH); + } UNLOCK_ZONE(zone); - if (again) + if (again) { goto redo; + } return (result); } @@ -11261,19 +11584,21 @@ dumptostream(dns_zone_t *zone, FILE *fd, const dns_master_style_t *style, REQUIRE(DNS_ZONE_VALID(zone)); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_attach(zone->db, &db); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); - if (db == NULL) + if (db == NULL) { return (DNS_R_NOTLOADED); + } dns_db_currentversion(db, &version); dns_master_initrawheader(&rawdata); - if (rawversion == 0) + if (rawversion == 0) { rawdata.flags |= DNS_MASTERRAW_COMPAT; - else if (inline_secure(zone)) + } else if (inline_secure(zone)) { get_raw_serial(zone->raw, &rawdata); - else if (zone->sourceserialset) { + } else if (zone->sourceserialset) { rawdata.flags = DNS_MASTERRAW_SOURCESERIALSET; rawdata.sourceserial = zone->sourceserial; } @@ -11315,10 +11640,12 @@ notify_cancel(dns_zone_t *zone) for (notify = ISC_LIST_HEAD(zone->notifies); notify != NULL; notify = ISC_LIST_NEXT(notify, link)) { - if (notify->find != NULL) + if (notify->find != NULL) { dns_adb_cancelfind(notify->find); - if (notify->request != NULL) + } + if (notify->request != NULL) { dns_request_cancel(notify->request); + } } } @@ -11335,8 +11662,9 @@ forward_cancel(dns_zone_t *zone) for (forward = ISC_LIST_HEAD(zone->forwards); forward != NULL; forward = ISC_LIST_NEXT(forward, link)) { - if (forward->request != NULL) + if (forward->request != NULL) { dns_request_cancel(forward->request); + } } } @@ -11351,11 +11679,13 @@ zone_unload(dns_zone_t *zone) if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FLUSH) || !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING)) { - if (zone->writeio != NULL) + if (zone->writeio != NULL) { zonemgr_cancelio(zone->writeio); + } - if (zone->dctx != NULL) + if (zone->dctx != NULL) { dns_dumpctx_cancel(zone->dctx); + } } ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_write); zone_detachdb(zone); @@ -11432,14 +11762,17 @@ notify_isqueued(dns_zone_t *zone, unsigned int flags, dns_name_t *name, for (notify = ISC_LIST_HEAD(zone->notifies); notify != NULL; notify = ISC_LIST_NEXT(notify, link)) { - if (notify->request != NULL) + if (notify->request != NULL) { continue; + } if (name != NULL && dns_name_dynamic(¬ify->ns) && - dns_name_equal(name, ¬ify->ns)) + dns_name_equal(name, ¬ify->ns)) { goto requeue; + } if (addr != NULL && isc_sockaddr_equal(addr, ¬ify->dst) && - notify->key == key) + notify->key == key) { goto requeue; + } } return (false); @@ -11454,8 +11787,9 @@ requeue: zmgr = notify->zone->zmgr; result = isc_ratelimiter_dequeue(zmgr->startupnotifyrl, notify->event); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (true); + } notify->flags &= ~DNS_NOTIFY_STARTUP; result = isc_ratelimiter_enqueue(notify->zone->zmgr->notifyrl, @@ -11480,8 +11814,9 @@ notify_isself(dns_zone_t *zone, isc_sockaddr_t *dst) isc_netaddr_t dstaddr; isc_result_t result; - if (zone->view == NULL || zone->isself == NULL) + if (zone->view == NULL || zone->isself == NULL) { return (false); + } switch (isc_sockaddr_pf(dst)) { case PF_INET: @@ -11500,17 +11835,20 @@ notify_isself(dns_zone_t *zone, isc_sockaddr_t *dst) * When sending from any the kernel will assign a source address * that matches the destination address. */ - if (isc_sockaddr_eqaddr(&any, &src)) + if (isc_sockaddr_eqaddr(&any, &src)) { src = *dst; + } isc_netaddr_fromsockaddr(&dstaddr, dst); result = dns_view_getpeertsig(zone->view, &dstaddr, &key); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { return (false); + } isself = (zone->isself)(zone->view, key, &src, dst, zone->rdclass, zone->isselfarg); - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); + } return (isself); } @@ -11522,26 +11860,34 @@ notify_destroy(dns_notify_t *notify, bool locked) REQUIRE(DNS_NOTIFY_VALID(notify)); if (notify->zone != NULL) { - if (!locked) + if (!locked) { LOCK_ZONE(notify->zone); + } REQUIRE(LOCKED_ZONE(notify->zone)); - if (ISC_LINK_LINKED(notify, link)) + if (ISC_LINK_LINKED(notify, link)) { ISC_LIST_UNLINK(notify->zone->notifies, notify, link); - if (!locked) + } + if (!locked) { UNLOCK_ZONE(notify->zone); - if (locked) + } + if (locked) { zone_idetach(¬ify->zone); - else + } else { dns_zone_idetach(¬ify->zone); + } } - if (notify->find != NULL) + if (notify->find != NULL) { dns_adb_destroyfind(¬ify->find); - if (notify->request != NULL) + } + if (notify->request != NULL) { dns_request_destroy(¬ify->request); - if (dns_name_dynamic(¬ify->ns)) + } + if (dns_name_dynamic(¬ify->ns)) { dns_name_free(¬ify->ns, notify->mctx); - if (notify->key != NULL) + } + if (notify->key != NULL) { dns_tsigkey_detach(¬ify->key); + } mctx = notify->mctx; isc_mem_put(notify->mctx, notify, sizeof(*notify)); isc_mem_detach(&mctx); @@ -11611,8 +11957,9 @@ notify_find_address(dns_notify_t *notify) options = DNS_ADBFIND_WANTEVENT | DNS_ADBFIND_INET | DNS_ADBFIND_INET6 | DNS_ADBFIND_RETURNLAME; - if (notify->zone->view->adb == NULL) + if (notify->zone->view->adb == NULL) { goto destroy; + } result = dns_adb_createfind( notify->zone->view->adb, notify->zone->task, process_adb_event, @@ -11620,12 +11967,14 @@ notify_find_address(dns_notify_t *notify) notify->zone->view->dstport, 0, NULL, ¬ify->find); /* Something failed? */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto destroy; + } /* More addresses pending? */ - if ((notify->find->options & DNS_ADBFIND_WANTEVENT) != 0) + if ((notify->find->options & DNS_ADBFIND_WANTEVENT) != 0) { return; + } /* We have as many addresses as we can get. */ LOCK_ZONE(notify->zone); @@ -11645,8 +11994,9 @@ notify_send_queue(dns_notify_t *notify, bool startup) INSIST(notify->event == NULL); e = isc_event_allocate(notify->mctx, NULL, DNS_EVENT_NOTIFYSENDTOADDR, notify_send_toaddr, notify, sizeof(isc_event_t)); - if (startup) + if (startup) { notify->event = e; + } e->ev_arg = notify; e->ev_sender = NULL; result = isc_ratelimiter_enqueue( @@ -11712,8 +12062,9 @@ notify_send_toaddr(isc_task_t *task, isc_event_t *event) } result = notify_createmessage(notify->zone, notify->flags, &message); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_sockaddr_format(¬ify->dst, addrbuf, sizeof(addrbuf)); if (notify->key != NULL) { @@ -11751,36 +12102,44 @@ notify_send_toaddr(isc_task_t *task, isc_event_t *event) &dstip, &peer); if (result == ISC_R_SUCCESS) { result = dns_peer_getnotifysource(peer, &src); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_notifysource = true; + } dns_peer_getnotifydscp(peer, &dscp); - if (dscp != -1) + if (dscp != -1) { have_notifydscp = true; + } result = dns_peer_getforcetcp(peer, &usetcp); - if (result == ISC_R_SUCCESS && usetcp) + if (result == ISC_R_SUCCESS && usetcp) { options |= DNS_FETCHOPT_TCP; + } } } switch (isc_sockaddr_pf(¬ify->dst)) { case PF_INET: - if (!have_notifysource) + if (!have_notifysource) { src = notify->zone->notifysrc4; - if (!have_notifydscp) + } + if (!have_notifydscp) { dscp = notify->zone->notifysrc4dscp; + } break; case PF_INET6: - if (!have_notifysource) + if (!have_notifysource) { src = notify->zone->notifysrc6; - if (!have_notifydscp) + } + if (!have_notifydscp) { dscp = notify->zone->notifysrc6dscp; + } break; default: result = ISC_R_NOTIMPLEMENTED; goto cleanup_key; } timeout = 15; - if (DNS_ZONE_FLAG(notify->zone, DNS_ZONEFLG_DIALNOTIFY)) + if (DNS_ZONE_FLAG(notify->zone, DNS_ZONEFLG_DIALNOTIFY)) { timeout = 30; + } result = dns_request_createvia( notify->zone->view->requestmgr, message, &src, ¬ify->dst, dscp, options, key, timeout * 3, timeout, 0, notify->zone->task, @@ -11796,15 +12155,17 @@ notify_send_toaddr(isc_task_t *task, isc_event_t *event) } cleanup_key: - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); + } cleanup_message: dns_message_destroy(&message); cleanup: UNLOCK_ZONE(notify->zone); isc_event_free(&event); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { notify_destroy(notify, false); + } } static void @@ -11823,35 +12184,41 @@ notify_send(dns_notify_t *notify) REQUIRE(DNS_NOTIFY_VALID(notify)); REQUIRE(LOCKED_ZONE(notify->zone)); - if (DNS_ZONE_FLAG(notify->zone, DNS_ZONEFLG_EXITING)) + if (DNS_ZONE_FLAG(notify->zone, DNS_ZONEFLG_EXITING)) { return; + } for (ai = ISC_LIST_HEAD(notify->find->list); ai != NULL; ai = ISC_LIST_NEXT(ai, publink)) { dst = ai->sockaddr; if (notify_isqueued(notify->zone, notify->flags, NULL, &dst, - NULL)) + NULL)) { continue; - if (notify_isself(notify->zone, &dst)) + } + if (notify_isself(notify->zone, &dst)) { continue; + } newnotify = NULL; flags = notify->flags & DNS_NOTIFY_NOSOA; result = notify_create(notify->mctx, flags, &newnotify); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } zone_iattach(notify->zone, &newnotify->zone); ISC_LIST_APPEND(newnotify->zone->notifies, newnotify, link); newnotify->dst = dst; startup = ((notify->flags & DNS_NOTIFY_STARTUP) != 0); result = notify_send_queue(newnotify, startup); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } newnotify = NULL; } cleanup: - if (newnotify != NULL) + if (newnotify != NULL) { notify_destroy(newnotify, true); + } } void @@ -11903,15 +12270,18 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) UNLOCK_ZONE(zone); if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING) || - !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED)) + !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED)) { return; + } - if (notifytype == dns_notifytype_no) + if (notifytype == dns_notifytype_no) { return; + } if (notifytype == dns_notifytype_masteronly && - zone->type != dns_zone_master) + zone->type != dns_zone_master) { return; + } origin = &zone->origin; @@ -11919,42 +12289,49 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) * If the zone is dialup we are done as we don't want to send * the current soa so as to force a refresh query. */ - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALNOTIFY)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALNOTIFY)) { flags |= DNS_NOTIFY_NOSOA; + } /* * Record that this was a notify due to starting up. */ - if (startup) + if (startup) { flags |= DNS_NOTIFY_STARTUP; + } /* * Get SOA RRset. */ ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_attach(zone->db, &zonedb); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); - if (zonedb == NULL) + if (zonedb == NULL) { return; + } dns_db_currentversion(zonedb, &version); result = dns_db_findnode(zonedb, origin, false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup1; + } dns_rdataset_init(&soardset); result = dns_db_findrdataset(zonedb, node, version, dns_rdatatype_soa, dns_rdatatype_none, 0, &soardset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup2; + } /* * Find serial and master server's name. */ dns_name_init(&master, NULL); result = dns_rdataset_first(&soardset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup3; + } dns_rdataset_current(&soardset, &rdata); result = dns_rdata_tostruct(&rdata, &soa, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -11980,15 +12357,17 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) dst = zone->notify[i]; if (notify_isqueued(zone, flags, NULL, &dst, key)) { - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); + } continue; } result = notify_create(zone->mctx, flags, ¬ify); if (result != ISC_R_SUCCESS) { - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); + } continue; } @@ -12004,8 +12383,9 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) ISC_LIST_APPEND(zone->notifies, notify, link); result = notify_send_queue(notify, startup); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { notify_destroy(notify, true); + } if (!loggednotify) { notify_log(zone, ISC_LOG_INFO, "sending notifies (serial %u)", serial); @@ -12014,8 +12394,9 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) } UNLOCK_ZONE(zone); - if (notifytype == dns_notifytype_explicit) + if (notifytype == dns_notifytype_explicit) { goto cleanup3; + } /* * Process NS RRset to generate notifies. @@ -12024,8 +12405,9 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) dns_rdataset_init(&nsrdset); result = dns_db_findrdataset(zonedb, node, version, dns_rdatatype_ns, dns_rdatatype_none, 0, &nsrdset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup3; + } result = dns_rdataset_first(&nsrdset); while (result == ISC_R_SUCCESS) { @@ -12059,8 +12441,9 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) continue; } result = notify_create(zone->mctx, flags, ¬ify); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } dns_zone_iattach(zone, ¬ify->zone); dns_name_dup(&ns.name, zone->mctx, ¬ify->ns); LOCK_ZONE(zone); @@ -12072,8 +12455,9 @@ zone_notify(dns_zone_t *zone, isc_time_t *now) dns_rdataset_disassociate(&nsrdset); cleanup3: - if (dns_name_dynamic(&master)) + if (dns_name_dynamic(&master)) { dns_name_free(&master, zone->mctx); + } cleanup2: dns_db_detachnode(zonedb, &node); cleanup1: @@ -12102,19 +12486,22 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, dns_db_t *db, result = dns_message_findname(message, DNS_SECTION_ANSWER, name, dns_rdatatype_ns, dns_rdatatype_none, NULL, &nsrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* * Add NS rdataset. */ result = dns_db_findnode(db, name, true, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = dns_db_addrdataset(db, node, version, 0, nsrdataset, 0, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* * Add glue rdatasets. */ @@ -12124,8 +12511,9 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, dns_db_t *db, result = dns_rdata_tostruct(&rdata, &ns, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); dns_rdata_reset(&rdata); - if (!dns_name_issubdomain(&ns.name, name)) + if (!dns_name_issubdomain(&ns.name, name)) { continue; + } rdataset = NULL; result = dns_message_findname(message, DNS_SECTION_ADDITIONAL, &ns.name, dns_rdatatype_aaaa, @@ -12133,13 +12521,15 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, dns_db_t *db, &rdataset); if (result == ISC_R_SUCCESS) { result = dns_db_findnode(db, &ns.name, true, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = dns_db_addrdataset(db, node, version, 0, rdataset, 0, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } rdataset = NULL; result = dns_message_findname( @@ -12147,17 +12537,20 @@ save_nsrrset(dns_message_t *message, dns_name_t *name, dns_db_t *db, dns_rdatatype_a, dns_rdatatype_none, NULL, &rdataset); if (result == ISC_R_SUCCESS) { result = dns_db_findnode(db, &ns.name, true, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = dns_db_addrdataset(db, node, version, 0, rdataset, 0, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto fail; + } return (ISC_R_SUCCESS); @@ -12224,12 +12617,14 @@ stub_callback(isc_task_t *task, isc_event_t *event) } result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto next_master; + } result = dns_request_getresponse(revent->request, msg, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto next_master; + } /* * Unexpected rcode. @@ -12326,8 +12721,9 @@ stub_callback(isc_task_t *task, isc_event_t *event) */ dns_db_closeversion(stub->db, &stub->version, true); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_write); - if (zone->db == NULL) + if (zone->db == NULL) { zone_attachdb(zone, stub->db); + } result = zone_get_from_db(zone, zone->db, NULL, &soacount, NULL, &refresh, &retry, &expire, NULL, NULL); if (result == ISC_R_SUCCESS && soacount > 0U) { @@ -12351,19 +12747,23 @@ stub_callback(isc_task_t *task, isc_event_t *event) isc_interval_set(&i, zone->expire, 0); DNS_ZONE_TIME_ADD(&now, zone->expire, &zone->expiretime); - if (zone->masterfile != NULL) + if (zone->masterfile != NULL) { zone_needdump(zone, 0); + } zone_settimer(zone, &now); goto free_stub; next_master: - if (stub->version != NULL) + if (stub->version != NULL) { dns_db_closeversion(stub->db, &stub->version, false); - if (stub->db != NULL) + } + if (stub->db != NULL) { dns_db_detach(&stub->db); - if (msg != NULL) + } + if (msg != NULL) { dns_message_destroy(&msg); + } isc_event_free(&event); dns_request_destroy(&zone->request); /* @@ -12390,16 +12790,18 @@ next_master: } } } - } else + } else { done = true; + } if (!done) { zone->curmaster = 0; /* * Find the next failed master. */ while (zone->curmaster < zone->masterscnt && - zone->mastersok[zone->curmaster]) + zone->mastersok[zone->curmaster]) { zone->curmaster++; + } DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC); } else { DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH); @@ -12412,8 +12814,9 @@ next_master: goto free_stub; same_master: - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); + } isc_event_free(&event); dns_request_destroy(&zone->request); ns_query(zone, NULL, stub); @@ -12450,8 +12853,9 @@ get_edns_expire(dns_zone_t *zone, dns_message_t *message, uint32_t *expirep) REQUIRE(expirep != NULL); REQUIRE(message != NULL); - if (message->opt == NULL) + if (message->opt == NULL) { return; + } result = dns_rdataset_first(message->opt); if (result == ISC_R_SUCCESS) { @@ -12474,8 +12878,9 @@ get_edns_expire(dns_zone_t *zone, dns_message_t *message, uint32_t *expirep) /* * Trim *expirep? */ - if (expire < *expirep) + if (expire < *expirep) { *expirep = expire; + } break; } } @@ -12493,29 +12898,33 @@ setmodtime(dns_zone_t *zone, isc_time_t *expiretime) isc_interval_set(&i, zone->expire, 0); result = isc_time_subtract(expiretime, &i, &when); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } result = ISC_R_FAILURE; - if (zone->journal != NULL) + if (zone->journal != NULL) { result = isc_file_settime(zone->journal, &when); + } if (result == ISC_R_SUCCESS && !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP) && - !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP)) + !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP)) { result = isc_file_settime(zone->masterfile, &when); - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { result = isc_file_settime(zone->masterfile, &when); + } /* * Someone removed the file from underneath us! */ if (result == ISC_R_FILENOTFOUND) { zone_needdump(zone, DNS_DUMP_DELAY); - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_ERROR, "refresh: could not set " "file modification time of '%s': %s", zone->masterfile, dns_result_totext(result)); + } } /* @@ -12599,18 +13008,20 @@ refresh_callback(isc_task_t *task, isc_event_t *event) "unreachable (cached)", master, source); } - } else + } else { dns_zone_log(zone, ISC_LOG_INFO, "refresh: failure trying master " "%s (source %s): %s", master, source, dns_result_totext(revent->result)); + } goto next_master; } result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto next_master; + } result = dns_request_getresponse(revent->request, msg, 0); if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_INFO, @@ -12790,9 +13201,10 @@ refresh_callback(isc_task_t *task, isc_event_t *event) RUNTIME_CHECK(dbsoacount > 0U); zone_debuglog(zone, me, 1, "serial: new %u, old %u", serial, oldserial); - } else + } else { zone_debuglog(zone, me, 1, "serial: new %u, old not loaded", serial); + } if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) || DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FORCEXFER) || @@ -12821,8 +13233,9 @@ refresh_callback(isc_task_t *task, isc_event_t *event) INSIST(zone->type == dns_zone_stub); ns_query(zone, rdataset, NULL); } - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); + } } else if (isc_serial_eq(soa.serial, oldserial)) { isc_time_t expiretime; uint32_t expire; @@ -12839,31 +13252,35 @@ refresh_callback(isc_task_t *task, isc_event_t *event) */ if (isc_time_compare(&expiretime, &zone->expiretime) > 0) { zone->expiretime = expiretime; - if (zone->masterfile != NULL) + if (zone->masterfile != NULL) { setmodtime(zone, &expiretime); + } } DNS_ZONE_JITTER_ADD(&now, zone->refresh, &zone->refreshtime); zone->mastersok[zone->curmaster] = true; goto next_master; } else { - if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_MULTIMASTER)) + if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_MULTIMASTER)) { dns_zone_log(zone, ISC_LOG_INFO, "serial number (%u) " "received from master %s < ours (%u)", soa.serial, master, oldserial); - else + } else { zone_debuglog(zone, me, 1, "ahead"); + } zone->mastersok[zone->curmaster] = true; goto next_master; } - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); + } goto detach; next_master: - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); + } isc_event_free(&event); dns_request_destroy(&zone->request); /* @@ -12889,8 +13306,9 @@ next_master: } } } - } else + } else { done = true; + } if (!done) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC); zone->curmaster = 0; @@ -12898,8 +13316,9 @@ next_master: * Find the next failed master. */ while (zone->curmaster < zone->masterscnt && - zone->mastersok[zone->curmaster]) + zone->mastersok[zone->curmaster]) { zone->curmaster++; + } goto requeue; } DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH); @@ -12917,16 +13336,18 @@ requeue: goto detach; same_master: - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); + } isc_event_free(&event); dns_request_destroy(&zone->request); queue_soa_query(zone); detach: UNLOCK_ZONE(zone); - if (do_queue_xfrin) + if (do_queue_xfrin) { queue_xfrin(zone); + } dns_zone_idetach(&zone); return; } @@ -12979,19 +13400,22 @@ create_query(dns_zone_t *zone, dns_rdatatype_t rdtype, dns_message_t **messagep) result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTRENDER, &message); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } message->opcode = dns_opcode_query; message->rdclass = zone->rdclass; result = dns_message_gettempname(message, &qname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdataset(message, &qrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Make question. @@ -13006,12 +13430,15 @@ create_query(dns_zone_t *zone, dns_rdatatype_t rdtype, dns_message_t **messagep) return (ISC_R_SUCCESS); cleanup: - 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); + } return (result); } @@ -13040,8 +13467,9 @@ add_opt(dns_message_t *message, uint16_t udpsize, bool reqnsid, bool reqexpire) } result = dns_message_buildopt(message, &rdataset, 0, udpsize, 0, ednsopts, count); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (dns_message_setopt(message, rdataset)); } @@ -13073,15 +13501,17 @@ soa_query(isc_task_t *task, isc_event_t *event) if (((event->ev_attributes & ISC_EVENTATTR_CANCELED) != 0) || DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING) || zone->view->requestmgr == NULL) { - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) { cancel = false; + } goto cleanup; } again: result = create_query(zone, dns_rdatatype_soa, &message); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } INSIST(zone->masterscnt > 0); INSIST(zone->curmaster < zone->masterscnt); @@ -13129,24 +13559,29 @@ again: &peer); if (result == ISC_R_SUCCESS) { result = dns_peer_getsupportedns(peer, &edns); - if (result == ISC_R_SUCCESS && !edns) + if (result == ISC_R_SUCCESS && !edns) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NOEDNS); + } result = dns_peer_gettransfersource(peer, &zone->sourceaddr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_xfrsource = true; + } (void)dns_peer_gettransferdscp(peer, &dscp); - if (dscp != -1) + if (dscp != -1) { have_xfrdscp = true; - if (zone->view->resolver != NULL) + } + if (zone->view->resolver != NULL) { udpsize = dns_resolver_getudpsize( zone->view->resolver); + } (void)dns_peer_getudpsize(peer, &udpsize); (void)dns_peer_getrequestnsid(peer, &reqnsid); (void)dns_peer_getrequestexpire(peer, &reqexpire); result = dns_peer_getforcetcp(peer, &usetcp); - if (result == ISC_R_SUCCESS && usetcp) + if (result == ISC_R_SUCCESS && usetcp) { options |= DNS_REQUESTOPT_TCP; + } } } @@ -13154,29 +13589,35 @@ again: case PF_INET: if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_USEALTXFRSRC)) { if (isc_sockaddr_equal(&zone->altxfrsource4, - &zone->xfrsource4)) + &zone->xfrsource4)) { goto skip_master; + } zone->sourceaddr = zone->altxfrsource4; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->altxfrsource4dscp; + } } else if (!have_xfrsource) { zone->sourceaddr = zone->xfrsource4; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->xfrsource4dscp; + } } break; case PF_INET6: if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_USEALTXFRSRC)) { if (isc_sockaddr_equal(&zone->altxfrsource6, - &zone->xfrsource6)) + &zone->xfrsource6)) { goto skip_master; + } zone->sourceaddr = zone->altxfrsource6; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->altxfrsource6dscp; + } } else if (!have_xfrsource) { zone->sourceaddr = zone->xfrsource6; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->xfrsource6dscp; + } } break; default: @@ -13186,16 +13627,18 @@ again: if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NOEDNS)) { result = add_opt(message, udpsize, reqnsid, reqexpire); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { zone_debuglog(zone, me, 1, "unable to add opt record: %s", dns_result_totext(result)); + } } zone_iattach(zone, &dummy); timeout = 15; - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)) { timeout = 30; + } result = dns_request_createvia( zone->view->requestmgr, message, &zone->sourceaddr, &zone->masteraddr, dscp, options, key, timeout * 3, timeout, 0, @@ -13207,30 +13650,36 @@ again: dns_result_totext(result)); goto skip_master; } else { - if (isc_sockaddr_pf(&zone->masteraddr) == PF_INET) + if (isc_sockaddr_pf(&zone->masteraddr) == PF_INET) { inc_stats(zone, dns_zonestatscounter_soaoutv4); - else + } else { inc_stats(zone, dns_zonestatscounter_soaoutv6); + } } cancel = false; cleanup: - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_REFRESH); - if (message != NULL) + } + if (message != NULL) { dns_message_destroy(&message); - if (cancel) + } + if (cancel) { cancel_refresh(zone); + } isc_event_free(&event); UNLOCK_ZONE(zone); dns_zone_idetach(&zone); return; skip_master: - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); + } dns_message_destroy(&message); /* * Skip to next failed / untried master. @@ -13239,8 +13688,9 @@ skip_master: zone->curmaster++; } while (zone->curmaster < zone->masterscnt && zone->mastersok[zone->curmaster]); - if (zone->curmaster < zone->masterscnt) + if (zone->curmaster < zone->masterscnt) { goto again; + } zone->curmaster = 0; goto cleanup; } @@ -13369,8 +13819,9 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) "unable to find key: %s", namebuf); } } - if (key == NULL) + if (key == NULL) { (void)dns_view_getpeertsig(zone->view, &masterip, &key); + } reqnsid = zone->view->requestnsid; if (zone->view->peers != NULL) { @@ -13380,28 +13831,33 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) &peer); if (result == ISC_R_SUCCESS) { result = dns_peer_getsupportedns(peer, &edns); - if (result == ISC_R_SUCCESS && !edns) + if (result == ISC_R_SUCCESS && !edns) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NOEDNS); + } result = dns_peer_gettransfersource(peer, &zone->sourceaddr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_xfrsource = true; + } result = dns_peer_gettransferdscp(peer, &dscp); - if (result == ISC_R_SUCCESS && dscp != -1) + if (result == ISC_R_SUCCESS && dscp != -1) { have_xfrdscp = true; - if (zone->view->resolver != NULL) + } + if (zone->view->resolver != NULL) { udpsize = dns_resolver_getudpsize( zone->view->resolver); + } (void)dns_peer_getudpsize(peer, &udpsize); (void)dns_peer_getrequestnsid(peer, &reqnsid); } } if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NOEDNS)) { result = add_opt(message, udpsize, reqnsid, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { zone_debuglog(zone, me, 1, "unable to add opt record: %s", dns_result_totext(result)); + } } /* @@ -13411,23 +13867,27 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) case PF_INET: if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_USEALTXFRSRC)) { zone->sourceaddr = zone->altxfrsource4; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->altxfrsource4dscp; + } } else if (!have_xfrsource) { zone->sourceaddr = zone->xfrsource4; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->xfrsource4dscp; + } } break; case PF_INET6: if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_USEALTXFRSRC)) { zone->sourceaddr = zone->altxfrsource6; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->altxfrsource6dscp; + } } else if (!have_xfrsource) { zone->sourceaddr = zone->xfrsource6; - if (!have_xfrdscp) + if (!have_xfrdscp) { dscp = zone->xfrsource6dscp; + } } break; default: @@ -13436,8 +13896,9 @@ ns_query(dns_zone_t *zone, dns_rdataset_t *soardataset, dns_stub_t *stub) goto cleanup; } timeout = 15; - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)) { timeout = 30; + } result = dns_request_createvia( zone->view->requestmgr, message, &zone->sourceaddr, &zone->masteraddr, dscp, DNS_REQUESTOPT_TCP, key, timeout * 3, @@ -13463,11 +13924,13 @@ cleanup: zone_idetach(&stub->zone); } isc_mem_put(stub->mctx, stub, sizeof(*stub)); - if (message != NULL) + if (message != NULL) { dns_message_destroy(&message); + } unlock: - if (key != NULL) + if (key != NULL) { dns_tsigkey_detach(&key); + } return; } @@ -13522,12 +13985,14 @@ zone_shutdown(isc_task_t *task, isc_event_t *event) /* * In task context, no locking required. See zone_xfrdone(). */ - if (zone->xfr != NULL) + if (zone->xfr != NULL) { dns_xfrin_shutdown(zone->xfr); + } /* Safe to release the zone now */ - if (zone->zmgr != NULL) + if (zone->zmgr != NULL) { dns_zonemgr_releasezone(zone->zmgr, zone); + } LOCK_ZONE(zone); INSIST(zone != zone->raw); @@ -13538,19 +14003,23 @@ zone_shutdown(isc_task_t *task, isc_event_t *event) dns_request_cancel(zone->request); } - if (zone->readio != NULL) + if (zone->readio != NULL) { zonemgr_cancelio(zone->readio); + } - if (zone->lctx != NULL) + if (zone->lctx != NULL) { dns_loadctx_cancel(zone->lctx); + } if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_FLUSH) || !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING)) { - if (zone->writeio != NULL) + if (zone->writeio != NULL) { zonemgr_cancelio(zone->writeio); + } - if (zone->dctx != NULL) + if (zone->dctx != NULL) { dns_dumpctx_cancel(zone->dctx); + } } notify_cancel(zone); @@ -13578,12 +14047,15 @@ zone_shutdown(isc_task_t *task, isc_event_t *event) zone->secure = NULL; } UNLOCK_ZONE(zone); - if (raw != NULL) + if (raw != NULL) { dns_zone_detach(&raw); - if (secure != NULL) + } + if (secure != NULL) { dns_zone_idetach(&secure); - if (free_needed) + } + if (free_needed) { zone_free(zone); + } } static void @@ -13613,55 +14085,67 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) REQUIRE(LOCKED_ZONE(zone)); ENTER; - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) { return; + } isc_time_settoepoch(&next); switch (zone->type) { case dns_zone_redirect: - if (zone->masters != NULL) + if (zone->masters != NULL) { goto treat_as_slave; + } /* FALLTHROUGH */ case dns_zone_master: if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDNOTIFY) || - DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDSTARTUPNOTIFY)) + DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDSTARTUPNOTIFY)) { next = zone->notifytime; + } if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP) && !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING)) { INSIST(!isc_time_isepoch(&zone->dumptime)); if (isc_time_isepoch(&next) || - isc_time_compare(&zone->dumptime, &next) < 0) + isc_time_compare(&zone->dumptime, &next) < 0) { next = zone->dumptime; + } } - if (zone->type == dns_zone_redirect) + if (zone->type == dns_zone_redirect) { break; + } if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_REFRESHING) && !isc_time_isepoch(&zone->refreshkeytime)) { if (isc_time_isepoch(&next) || - isc_time_compare(&zone->refreshkeytime, &next) < 0) + isc_time_compare(&zone->refreshkeytime, &next) < + 0) { next = zone->refreshkeytime; + } } if (!isc_time_isepoch(&zone->resigntime)) { if (isc_time_isepoch(&next) || - isc_time_compare(&zone->resigntime, &next) < 0) + isc_time_compare(&zone->resigntime, &next) < 0) { next = zone->resigntime; + } } if (!isc_time_isepoch(&zone->keywarntime)) { if (isc_time_isepoch(&next) || - isc_time_compare(&zone->keywarntime, &next) < 0) + isc_time_compare(&zone->keywarntime, &next) < 0) { next = zone->keywarntime; + } } if (!isc_time_isepoch(&zone->signingtime)) { if (isc_time_isepoch(&next) || - isc_time_compare(&zone->signingtime, &next) < 0) + isc_time_compare(&zone->signingtime, &next) < 0) { next = zone->signingtime; + } } if (!isc_time_isepoch(&zone->nsec3chaintime)) { if (isc_time_isepoch(&next) || - isc_time_compare(&zone->nsec3chaintime, &next) < 0) + isc_time_compare(&zone->nsec3chaintime, &next) < + 0) { next = zone->nsec3chaintime; + } } break; @@ -13669,8 +14153,9 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) case dns_zone_mirror: treat_as_slave: if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDNOTIFY) || - DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDSTARTUPNOTIFY)) + DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDSTARTUPNOTIFY)) { next = zone->notifytime; + } /* FALLTHROUGH */ case dns_zone_stub: @@ -13681,20 +14166,23 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADPENDING) && !isc_time_isepoch(&zone->refreshtime) && (isc_time_isepoch(&next) || - isc_time_compare(&zone->refreshtime, &next) < 0)) + isc_time_compare(&zone->refreshtime, &next) < 0)) { next = zone->refreshtime; + } if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) && !isc_time_isepoch(&zone->expiretime)) { if (isc_time_isepoch(&next) || - isc_time_compare(&zone->expiretime, &next) < 0) + isc_time_compare(&zone->expiretime, &next) < 0) { next = zone->expiretime; + } } if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NEEDDUMP) && !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING)) { INSIST(!isc_time_isepoch(&zone->dumptime)); if (isc_time_isepoch(&next) || - isc_time_compare(&zone->dumptime, &next) < 0) + isc_time_compare(&zone->dumptime, &next) < 0) { next = zone->dumptime; + } } break; @@ -13703,15 +14191,17 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DUMPING)) { INSIST(!isc_time_isepoch(&zone->dumptime)); if (isc_time_isepoch(&next) || - isc_time_compare(&zone->dumptime, &next) < 0) + isc_time_compare(&zone->dumptime, &next) < 0) { next = zone->dumptime; + } } if (!DNS_ZONE_FLAG(zone, DNS_ZONEFLG_REFRESHING)) { if (isc_time_isepoch(&next) || (!isc_time_isepoch(&zone->refreshkeytime) && isc_time_compare(&zone->refreshkeytime, &next) < - 0)) + 0)) { next = zone->refreshkeytime; + } } break; @@ -13723,19 +14213,22 @@ zone_settimer(dns_zone_t *zone, isc_time_t *now) zone_debuglog(zone, me, 10, "settimer inactive"); result = isc_timer_reset(zone->timer, isc_timertype_inactive, NULL, NULL, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_ERROR, "could not deactivate zone timer: %s", isc_result_totext(result)); + } } else { - if (isc_time_compare(&next, now) <= 0) + if (isc_time_compare(&next, now) <= 0) { next = *now; + } result = isc_timer_reset(zone->timer, isc_timertype_once, &next, NULL, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { dns_zone_log(zone, ISC_LOG_ERROR, "could not reset zone timer: %s", isc_result_totext(result)); + } } } @@ -13784,20 +14277,23 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags, result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTRENDER, &message); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } message->opcode = dns_opcode_notify; message->flags |= DNS_MESSAGEFLAG_AA; message->rdclass = zone->rdclass; result = dns_message_gettempname(message, &tempname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdataset(message, &temprdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Make question. @@ -13811,21 +14307,26 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags, tempname = NULL; temprdataset = NULL; - if ((flags & DNS_NOTIFY_NOSOA) != 0) + if ((flags & DNS_NOTIFY_NOSOA) != 0) { goto done; + } result = dns_message_gettempname(message, &tempname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } result = dns_message_gettemprdata(message, &temprdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } result = dns_message_gettemprdataset(message, &temprdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } result = dns_message_gettemprdatalist(message, &temprdatalist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); INSIST(zone->db != NULL); /* XXXJT: is this assumption correct? */ @@ -13836,17 +14337,20 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags, dns_name_clone(&zone->origin, tempname); dns_db_currentversion(zonedb, &version); result = dns_db_findnode(zonedb, tempname, false, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(zonedb, node, version, dns_rdatatype_soa, dns_rdatatype_none, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } result = dns_rdataset_first(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } dns_rdataset_current(&rdataset, &rdata); dns_rdata_toregion(&rdata, &r); isc_buffer_allocate(zone->mctx, &b, r.length); @@ -13857,16 +14361,18 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags, dns_message_takebuffer(message, &b); result = dns_rdataset_next(&rdataset); dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto soa_cleanup; + } temprdatalist->rdclass = rdata.rdclass; temprdatalist->type = rdata.type; temprdatalist->ttl = rdataset.ttl; ISC_LIST_APPEND(temprdatalist->rdata, temprdata, link); result = dns_rdatalist_tordataset(temprdatalist, temprdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto soa_cleanup; + } ISC_LIST_APPEND(tempname->list, temprdataset, link); dns_message_addname(message, tempname, DNS_SECTION_ANSWER); @@ -13876,30 +14382,39 @@ notify_createmessage(dns_zone_t *zone, unsigned int flags, tempname = NULL; soa_cleanup: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(zonedb, &node); - if (version != NULL) + } + if (version != NULL) { dns_db_closeversion(zonedb, &version, false); - if (zonedb != NULL) + } + if (zonedb != NULL) { dns_db_detach(&zonedb); - if (tempname != NULL) + } + if (tempname != NULL) { dns_message_puttempname(message, &tempname); - if (temprdata != NULL) + } + if (temprdata != NULL) { dns_message_puttemprdata(message, &temprdata); - if (temprdataset != NULL) + } + if (temprdataset != NULL) { dns_message_puttemprdataset(message, &temprdataset); - if (temprdatalist != NULL) + } + if (temprdatalist != NULL) { dns_message_puttemprdatalist(message, &temprdatalist); + } done: *messagep = message; return (ISC_R_SUCCESS); cleanup: - if (tempname != NULL) + if (tempname != NULL) { dns_message_puttempname(message, &tempname); - if (temprdataset != NULL) + } + if (temprdataset != NULL) { dns_message_puttemprdataset(message, &temprdataset); + } dns_message_destroy(&message); return (result); } @@ -13958,10 +14473,11 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from, /* * We only handle NOTIFY (SOA) at the present. */ - if (isc_sockaddr_pf(from) == PF_INET) + if (isc_sockaddr_pf(from) == PF_INET) { inc_stats(zone, dns_zonestatscounter_notifyinv4); - else + } else { inc_stats(zone, dns_zonestatscounter_notifyinv6); + } if (msg->counts[DNS_SECTION_QUESTION] == 0 || dns_message_findname(msg, DNS_SECTION_QUESTION, &zone->origin, dns_rdatatype_soa, dns_rdatatype_none, NULL, @@ -13989,16 +14505,18 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from, isc_netaddr_fromsockaddr(&netaddr, from); for (i = 0; i < zone->masterscnt; i++) { - if (isc_sockaddr_eqaddr(from, &zone->masters[i])) + if (isc_sockaddr_eqaddr(from, &zone->masters[i])) { break; + } if (zone->view->aclenv.match_mapped && IN6_IS_ADDR_V4MAPPED(&from->type.sin6.sin6_addr) && isc_sockaddr_pf(&zone->masters[i]) == AF_INET) { isc_netaddr_t na1, na2; isc_netaddr_fromv4mapped(&na1, &netaddr); isc_netaddr_fromsockaddr(&na2, &zone->masters[i]); - if (isc_netaddr_equal(&na1, &na2)) + if (isc_netaddr_equal(&na1, &na2)) { break; + } } } @@ -14034,8 +14552,9 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from, result = dns_message_findname( msg, DNS_SECTION_ANSWER, &zone->origin, dns_rdatatype_soa, dns_rdatatype_none, NULL, &rdataset); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_rdataset_first(rdataset); + } if (result == ISC_R_SUCCESS) { uint32_t oldserial; unsigned int soacount; @@ -14074,24 +14593,26 @@ dns_zone_notifyreceive(dns_zone_t *zone, isc_sockaddr_t *from, DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NEEDREFRESH); zone->notifyfrom = *from; UNLOCK_ZONE(zone); - if (have_serial) + if (have_serial) { dns_zone_log(zone, ISC_LOG_INFO, "notify from %s: serial %u: refresh in " "progress, refresh check queued", fromtext, serial); - else + } else { dns_zone_log(zone, ISC_LOG_INFO, "notify from %s: refresh in progress, " "refresh check queued", fromtext); + } return (ISC_R_SUCCESS); } - if (have_serial) + if (have_serial) { dns_zone_log(zone, ISC_LOG_INFO, "notify from %s: serial %u", fromtext, serial); - else + } else { dns_zone_log(zone, ISC_LOG_INFO, "notify from %s: no serial", fromtext); + } zone->notifyfrom = *from; UNLOCK_ZONE(zone); @@ -14108,8 +14629,9 @@ dns_zone_setnotifyacl(dns_zone_t *zone, dns_acl_t *acl) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->notify_acl != NULL) + if (zone->notify_acl != NULL) { dns_acl_detach(&zone->notify_acl); + } dns_acl_attach(acl, &zone->notify_acl); UNLOCK_ZONE(zone); } @@ -14120,8 +14642,9 @@ dns_zone_setqueryacl(dns_zone_t *zone, dns_acl_t *acl) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->query_acl != NULL) + if (zone->query_acl != NULL) { dns_acl_detach(&zone->query_acl); + } dns_acl_attach(acl, &zone->query_acl); UNLOCK_ZONE(zone); } @@ -14132,8 +14655,9 @@ dns_zone_setqueryonacl(dns_zone_t *zone, dns_acl_t *acl) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->queryon_acl != NULL) + if (zone->queryon_acl != NULL) { dns_acl_detach(&zone->queryon_acl); + } dns_acl_attach(acl, &zone->queryon_acl); UNLOCK_ZONE(zone); } @@ -14144,8 +14668,9 @@ dns_zone_setupdateacl(dns_zone_t *zone, dns_acl_t *acl) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->update_acl != NULL) + if (zone->update_acl != NULL) { dns_acl_detach(&zone->update_acl); + } dns_acl_attach(acl, &zone->update_acl); UNLOCK_ZONE(zone); } @@ -14156,8 +14681,9 @@ dns_zone_setforwardacl(dns_zone_t *zone, dns_acl_t *acl) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->forward_acl != NULL) + if (zone->forward_acl != NULL) { dns_acl_detach(&zone->forward_acl); + } dns_acl_attach(acl, &zone->forward_acl); UNLOCK_ZONE(zone); } @@ -14168,8 +14694,9 @@ dns_zone_setxfracl(dns_zone_t *zone, dns_acl_t *acl) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->xfr_acl != NULL) + if (zone->xfr_acl != NULL) { dns_acl_detach(&zone->xfr_acl); + } dns_acl_attach(acl, &zone->xfr_acl); UNLOCK_ZONE(zone); } @@ -14228,8 +14755,9 @@ dns_zone_clearupdateacl(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->update_acl != NULL) + if (zone->update_acl != NULL) { dns_acl_detach(&zone->update_acl); + } UNLOCK_ZONE(zone); } @@ -14239,8 +14767,9 @@ dns_zone_clearforwardacl(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->forward_acl != NULL) + if (zone->forward_acl != NULL) { dns_acl_detach(&zone->forward_acl); + } UNLOCK_ZONE(zone); } @@ -14250,8 +14779,9 @@ dns_zone_clearnotifyacl(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->notify_acl != NULL) + if (zone->notify_acl != NULL) { dns_acl_detach(&zone->notify_acl); + } UNLOCK_ZONE(zone); } @@ -14261,8 +14791,9 @@ dns_zone_clearqueryacl(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->query_acl != NULL) + if (zone->query_acl != NULL) { dns_acl_detach(&zone->query_acl); + } UNLOCK_ZONE(zone); } @@ -14272,8 +14803,9 @@ dns_zone_clearqueryonacl(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->queryon_acl != NULL) + if (zone->queryon_acl != NULL) { dns_acl_detach(&zone->queryon_acl); + } UNLOCK_ZONE(zone); } @@ -14283,8 +14815,9 @@ dns_zone_clearxfracl(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->xfr_acl != NULL) + if (zone->xfr_acl != NULL) { dns_acl_detach(&zone->xfr_acl); + } UNLOCK_ZONE(zone); } @@ -14362,15 +14895,18 @@ zone_namerd_tostr(dns_zone_t *zone, char *buf, size_t length) */ isc_buffer_init(&buffer, buf, (unsigned int)length - 1); if (zone->type != dns_zone_redirect && zone->type != dns_zone_key) { - if (dns_name_dynamic(&zone->origin)) + if (dns_name_dynamic(&zone->origin)) { result = dns_name_totext(&zone->origin, true, &buffer); + } if (result != ISC_R_SUCCESS && isc_buffer_availablelength(&buffer) >= - (sizeof("") - 1)) + (sizeof("") - 1)) { isc_buffer_putstr(&buffer, ""); + } - if (isc_buffer_availablelength(&buffer) > 0) + if (isc_buffer_availablelength(&buffer) > 0) { isc_buffer_putstr(&buffer, "/"); + } (void)dns_rdataclass_totext(zone->rdclass, &buffer); } @@ -14380,10 +14916,12 @@ zone_namerd_tostr(dns_zone_t *zone, char *buf, size_t length) isc_buffer_putstr(&buffer, "/"); isc_buffer_putstr(&buffer, zone->view->name); } - if (inline_secure(zone) && 9U < isc_buffer_availablelength(&buffer)) + if (inline_secure(zone) && 9U < isc_buffer_availablelength(&buffer)) { isc_buffer_putstr(&buffer, " (signed)"); - if (inline_raw(zone) && 11U < isc_buffer_availablelength(&buffer)) + } + if (inline_raw(zone) && 11U < isc_buffer_availablelength(&buffer)) { isc_buffer_putstr(&buffer, " (unsigned)"); + } buf[isc_buffer_usedlength(&buffer)] = '\0'; } @@ -14401,11 +14939,13 @@ zone_name_tostr(dns_zone_t *zone, char *buf, size_t length) * Leave space for terminating '\0'. */ isc_buffer_init(&buffer, buf, (unsigned int)length - 1); - if (dns_name_dynamic(&zone->origin)) + if (dns_name_dynamic(&zone->origin)) { result = dns_name_totext(&zone->origin, true, &buffer); + } if (result != ISC_R_SUCCESS && - isc_buffer_availablelength(&buffer) >= (sizeof("") - 1)) + isc_buffer_availablelength(&buffer) >= (sizeof("") - 1)) { isc_buffer_putstr(&buffer, ""); + } buf[isc_buffer_usedlength(&buffer)] = '\0'; } @@ -14568,8 +15108,9 @@ message_count(dns_message_t *msg, dns_section_t section, dns_rdatatype_t type) for (curr = ISC_LIST_TAIL(name->list); curr != NULL; curr = ISC_LIST_PREV(curr, link)) { - if (curr->type == type) + if (curr->type == type) { count++; + } } result = dns_message_nextname(msg, section); } @@ -14639,12 +15180,14 @@ dns_zone_settask(dns_zone_t *zone, isc_task_t *task) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->task != NULL) + if (zone->task != NULL) { isc_task_detach(&zone->task); + } isc_task_attach(task, &zone->task); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_settask(zone->db, zone->task); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); UNLOCK_ZONE(zone); } @@ -14661,8 +15204,9 @@ dns_zone_setidlein(dns_zone_t *zone, uint32_t idlein) { REQUIRE(DNS_ZONE_VALID(zone)); - if (idlein == 0) + if (idlein == 0) { idlein = DNS_DEFAULT_IDLEIN; + } zone->idlein = idlein; } @@ -14711,23 +15255,27 @@ notify_done(isc_task_t *task, isc_event_t *event) isc_sockaddr_format(¬ify->dst, addrbuf, sizeof(addrbuf)); result = revent->result; - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_message_create(notify->zone->mctx, DNS_MESSAGE_INTENTPARSE, &message); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { result = dns_request_getresponse(revent->request, message, DNS_MESSAGEPARSE_PRESERVEORDER); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { result = dns_rcode_totext(message->rcode, &buf); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { notify_log(notify->zone, ISC_LOG_DEBUG(3), "notify response from %s: %.*s", addrbuf, (int)buf.used, rcode); - else + } else { notify_log(notify->zone, ISC_LOG_DEBUG(2), "notify to %s failed: %s", addrbuf, dns_result_totext(result)); + } /* * Old bind's return formerr if they see a soa record. Retry w/o @@ -14742,16 +15290,19 @@ notify_done(isc_task_t *task, isc_event_t *event) dns_request_destroy(¬ify->request); startup = (notify->flags & DNS_NOTIFY_STARTUP); result = notify_send_queue(notify, startup); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { notify_destroy(notify, false); + } } else { - if (result == ISC_R_TIMEDOUT) + if (result == ISC_R_TIMEDOUT) { notify_log(notify->zone, ISC_LOG_DEBUG(1), "notify to %s: retries exceeded", addrbuf); + } notify_destroy(notify, false); } - if (message != NULL) + if (message != NULL) { dns_message_destroy(&message); + } } struct secure_event { @@ -14779,8 +15330,9 @@ sync_secure_journal(dns_zone_t *zone, dns_zone_t *raw, dns_journal_t *journal, REQUIRE(soatuplep != NULL); - if (start == end) + if (start == end) { return (DNS_R_UNCHANGED); + } CHECK(dns_journal_iter_init(journal, start, end)); for (result = dns_journal_first_rr(journal); result == ISC_R_SUCCESS; @@ -14796,14 +15348,16 @@ sync_secure_journal(dns_zone_t *zone, dns_zone_t *raw, dns_journal_t *journal, /* * Save the latest raw SOA record. */ - if (*soatuplep != NULL) + if (*soatuplep != NULL) { dns_difftuple_free(soatuplep); + } CHECK(dns_difftuple_create( diff->mctx, DNS_DIFFOP_ADD, name, ttl, rdata, soatuplep)); } - if (n_soa == 3) + if (n_soa == 3) { n_soa = 1; + } continue; } @@ -14815,15 +15369,18 @@ sync_secure_journal(dns_zone_t *zone, dns_zone_t *raw, dns_journal_t *journal, return (ISC_R_FAILURE); } - if (zone->privatetype != 0 && rdata->type == zone->privatetype) + if (zone->privatetype != 0 && + rdata->type == zone->privatetype) { continue; + } if (rdata->type == dns_rdatatype_nsec || rdata->type == dns_rdatatype_rrsig || rdata->type == dns_rdatatype_nsec3 || rdata->type == dns_rdatatype_dnskey || - rdata->type == dns_rdatatype_nsec3param) + rdata->type == dns_rdatatype_nsec3param) { continue; + } op = (n_soa == 1) ? DNS_DIFFOP_DEL : DNS_DIFFOP_ADD; @@ -14831,8 +15388,9 @@ sync_secure_journal(dns_zone_t *zone, dns_zone_t *raw, dns_journal_t *journal, &tuple)); dns_diff_appendminimal(diff, &tuple); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } failure: return (result); @@ -14853,8 +15411,9 @@ sync_secure_db(dns_zone_t *seczone, dns_zone_t *raw, dns_db_t *secdb, REQUIRE(DNS_ZONE_VALID(seczone)); REQUIRE(soatuple != NULL && *soatuple == NULL); - if (!seczone->sourceserialset) + if (!seczone->sourceserialset) { return (DNS_R_UNCHANGED); + } dns_db_attach(raw->db, &rawdb); dns_db_currentversion(rawdb, &rawver); @@ -14862,8 +15421,9 @@ sync_secure_db(dns_zone_t *seczone, dns_zone_t *raw, dns_db_t *secdb, dns_db_closeversion(rawdb, &rawver, false); dns_db_detach(&rawdb); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } for (tuple = ISC_LIST_HEAD(diff->tuples); tuple != NULL; tuple = next) { next = ISC_LIST_NEXT(tuple, link); @@ -14912,8 +15472,9 @@ sync_secure_db(dns_zone_t *seczone, dns_zone_t *raw, dns_db_t *secdb, } } - if (ISC_LIST_EMPTY(diff->tuples)) + if (ISC_LIST_EMPTY(diff->tuples)) { return (DNS_R_UNCHANGED); + } /* * If there are still SOA records in the diff they can now be removed @@ -15027,8 +15588,9 @@ nextevent: * that from the raw journal. */ if (dns_journal_get_sourceserial(sjournal, &serial)) { - if (isc_serial_gt(serial, start)) + if (isc_serial_gt(serial, start)) { start = serial; + } } dns_journal_destroy(&sjournal); } @@ -15225,15 +15787,17 @@ checkandaddsoa(dns_db_t *db, dns_dbnode_t *node, dns_dbversion_t *version, result = dns_rdata_tostruct(&rdata, &soa, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if (isc_serial_gt(soa.serial, oldserial)) + if (isc_serial_gt(soa.serial, oldserial)) { return (dns_db_addrdataset(db, node, version, 0, rdataset, 0, NULL)); + } /* * Always bump the serial. */ oldserial++; - if (oldserial == 0) + if (oldserial == 0) { oldserial++; + } soa.serial = oldserial; /* @@ -15295,8 +15859,9 @@ save_nsec3param(dns_zone_t *zone, nsec3paramlist_t *nsec3list) dns_rdatatype_nsec3param, dns_rdatatype_none, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto getprivate; + } /* * walk nsec3param rdataset making a list of parameters (note that @@ -15330,8 +15895,9 @@ save_nsec3param(dns_zone_t *zone, nsec3paramlist_t *nsec3list) getprivate: result = dns_db_findrdataset(db, node, version, zone->privatetype, dns_rdatatype_none, 0, &prdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } /* * walk private type records, converting them to nsec3 parameters @@ -15352,8 +15918,9 @@ getprivate: * Do we have a valid private record? */ if (!dns_nsec3param_fromprivate(&private, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } /* * Remove any NSEC3PARAM records scheduled to be removed. @@ -15394,20 +15961,26 @@ getprivate: } done: - if (result == ISC_R_NOMORE || result == ISC_R_NOTFOUND) + if (result == ISC_R_NOMORE || result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; + } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); - if (version != NULL) + } + if (version != NULL) { dns_db_closeversion(db, &version, false); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); - if (dns_rdataset_isassociated(&rdataset)) + } + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (dns_rdataset_isassociated(&prdataset)) + } + if (dns_rdataset_isassociated(&prdataset)) { dns_rdataset_disassociate(&prdataset); + } return (result); } @@ -15717,8 +16290,9 @@ again: ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_write); result = zone_replacedb(zone, db, dump); ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_write); - if (secure != NULL) + if (secure != NULL) { UNLOCK_ZONE(secure); + } UNLOCK_ZONE(zone); return (result); } @@ -15736,8 +16310,9 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, bool dump) */ REQUIRE(DNS_ZONE_VALID(zone)); REQUIRE(LOCKED_ZONE(zone)); - if (inline_raw(zone)) + if (inline_raw(zone)) { REQUIRE(LOCKED_ZONE(zone->secure)); + } result = zone_get_from_db(zone, db, &nscount, &soacount, NULL, NULL, NULL, NULL, NULL, NULL); @@ -15751,8 +16326,9 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, bool dump) dns_zone_log(zone, ISC_LOG_ERROR, "has no NS records"); result = DNS_R_BADZONE; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } else { dns_zone_log(zone, ISC_LOG_ERROR, "retrieving SOA and NS records failed: %s", @@ -15761,8 +16337,9 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, bool dump) } result = check_nsec3param(zone, db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } ver = NULL; dns_db_currentversion(db, &ver); @@ -15821,12 +16398,14 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, bool dump) strbuf); goto fallback; } - if (dump) + if (dump) { zone_needdump(zone, DNS_DUMP_DELAY); - else + } else { zone_journal_compact(zone, zone->db, serial); - if (zone->type == dns_zone_master && inline_raw(zone)) + } + if (zone->type == dns_zone_master && inline_raw(zone)) { zone_send_secureserial(zone, serial); + } } else { fallback: if (dump && zone->masterfile != NULL) { @@ -15845,10 +16424,11 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, bool dump) "'%s': '%s'", zone->masterfile, strbuf); } - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) == 0) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_LOADED) == 0) { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NODELAY); - else + } else { zone_needdump(zone, 0); + } } if (dump && zone->journal != NULL) { /* @@ -15877,16 +16457,18 @@ zone_replacedb(dns_zone_t *zone, dns_db_t *db, bool dump) } } - if (inline_raw(zone)) + if (inline_raw(zone)) { zone_send_securedb(zone, db); + } } dns_db_closeversion(db, &ver, false); dns_zone_log(zone, ISC_LOG_DEBUG(3), "replacing zone database"); - if (zone->db != NULL) + if (zone->db != NULL) { zone_detachdb(zone); + } zone_attachdb(zone, db); dns_db_settask(zone->db, zone->task); DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_LOADED | DNS_ZONEFLG_NEEDNOTIFY); @@ -15959,7 +16541,7 @@ again: switch (xfrresult) { case ISC_R_SUCCESS: DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_NEEDNOTIFY); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case DNS_R_UPTODATE: DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_FORCEXFER); /* @@ -15983,12 +16565,13 @@ again: &minimum, NULL); ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); if (result == ISC_R_SUCCESS) { - if (soacount != 1) + if (soacount != 1) { dns_zone_log(zone, ISC_LOG_ERROR, "transferred zone " "has %d SOA record%s", soacount, (soacount != 0) ? "s" : ""); + } if (nscount == 0) { dns_zone_log(zone, ISC_LOG_ERROR, "transferred zone " @@ -16035,13 +16618,15 @@ again: sizeof(namebuf)); snprintf(buf, sizeof(buf), ": TSIG '%s'", namebuf); - } else + } else { buf[0] = '\0'; + } dns_zone_logc(zone, DNS_LOGCATEGORY_XFER_IN, ISC_LOG_INFO, "transferred serial %u%s", serial, buf); - if (inline_raw(zone)) + if (inline_raw(zone)) { zone_send_secureserial(zone, serial); + } } /* @@ -16053,27 +16638,32 @@ again: unsigned int delay = DNS_DUMP_DELAY; result = ISC_R_FAILURE; - if (zone->journal != NULL) + if (zone->journal != NULL) { result = isc_file_settime(zone->journal, &now); - if (result != ISC_R_SUCCESS && zone->masterfile != NULL) + } + if (result != ISC_R_SUCCESS && + zone->masterfile != NULL) { result = isc_file_settime(zone->masterfile, &now); + } if ((DNS_ZONE_FLAG(zone, DNS_ZONEFLG_NODELAY) != 0) || - result == ISC_R_FILENOTFOUND) + result == ISC_R_FILENOTFOUND) { delay = 0; + } if ((result == ISC_R_SUCCESS || result == ISC_R_FILENOTFOUND) && - zone->masterfile != NULL) + zone->masterfile != NULL) { zone_needdump(zone, delay); - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { dns_zone_logc(zone, DNS_LOGCATEGORY_XFER_IN, ISC_LOG_ERROR, "transfer: could not set file " "modification time of '%s': %s", zone->masterfile, dns_result_totext(result)); + } } DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_NODELAY); inc_stats(zone, dns_zonestatscounter_xfrsuccess); @@ -16109,12 +16699,14 @@ again: DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC); while (zone->curmaster < zone->masterscnt && - zone->mastersok[zone->curmaster]) + zone->mastersok[zone->curmaster]) { zone->curmaster++; + } again = true; - } else + } else { DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_USEALTXFRSRC); + } } else { DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_REFRESH); again = true; @@ -16131,11 +16723,13 @@ again: * state. Since we are no longer responsible for shutting * it down, we can detach our reference. */ - if (zone->xfr != NULL) + if (zone->xfr != NULL) { dns_xfrin_detach(&zone->xfr); + } - if (zone->tsigkey != NULL) + if (zone->tsigkey != NULL) { dns_tsigkey_detach(&zone->tsigkey); + } /* * Handle any deferred journal compaction. @@ -16149,8 +16743,9 @@ again: } } - if (secure != NULL) + if (secure != NULL) { UNLOCK_ZONE(secure); + } /* * This transfer finishing freed up a transfer quota slot. * Let any other zones waiting for quota have it. @@ -16169,14 +16764,16 @@ again: /* * Retry with a different server if necessary. */ - if (again && !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) + if (again && !DNS_ZONE_FLAG(zone, DNS_ZONEFLG_EXITING)) { queue_soa_query(zone); + } isc_refcount_decrement(&zone->irefs); free_needed = exit_check(zone); UNLOCK_ZONE(zone); - if (free_needed) + if (free_needed) { zone_free(zone); + } } static void @@ -16204,8 +16801,9 @@ zone_loaddone(void *arg, isc_result_t result) tresult = dns_db_endload(load->db, &load->callbacks); if (tresult != ISC_R_SUCCESS && - (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE)) + (result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE)) { result = tresult; + } /* * Lock hierarchy: zmgr, zone, raw. @@ -16213,9 +16811,9 @@ zone_loaddone(void *arg, isc_result_t result) again: LOCK_ZONE(zone); INSIST(zone != zone->raw); - if (inline_secure(zone)) + if (inline_secure(zone)) { LOCK_ZONE(zone->raw); - else if (inline_raw(zone)) { + } else if (inline_raw(zone)) { secure = zone->secure; TRYLOCK_ZONE(tresult, secure); if (tresult != ISC_R_SUCCESS) { @@ -16233,19 +16831,22 @@ again: * Leave the zone frozen if the reload fails. */ if ((result == ISC_R_SUCCESS || result == DNS_R_SEENINCLUDE) && - DNS_ZONE_FLAG(zone, DNS_ZONEFLG_THAW)) + DNS_ZONE_FLAG(zone, DNS_ZONEFLG_THAW)) { zone->update_disabled = false; + } DNS_ZONE_CLRFLAG(zone, DNS_ZONEFLG_THAW); - if (inline_secure(zone)) + if (inline_secure(zone)) { UNLOCK_ZONE(zone->raw); - else if (secure != NULL) + } else if (secure != NULL) { UNLOCK_ZONE(secure); + } UNLOCK_ZONE(zone); load->magic = 0; dns_db_detach(&load->db); - if (load->zone->lctx != NULL) + if (load->zone->lctx != NULL) { dns_loadctx_detach(&load->zone->lctx); + } dns_zone_idetach(&load->zone); isc_mem_putanddetach(&load->mctx, load, sizeof(*load)); } @@ -16258,8 +16859,9 @@ dns_zone_getssutable(dns_zone_t *zone, dns_ssutable_t **table) REQUIRE(*table == NULL); LOCK_ZONE(zone); - if (zone->ssutable != NULL) + if (zone->ssutable != NULL) { dns_ssutable_attach(zone->ssutable, table); + } UNLOCK_ZONE(zone); } @@ -16269,10 +16871,12 @@ dns_zone_setssutable(dns_zone_t *zone, dns_ssutable_t *table) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->ssutable != NULL) + if (zone->ssutable != NULL) { dns_ssutable_detach(&zone->ssutable); - if (table != NULL) + } + if (table != NULL) { dns_ssutable_attach(table, &zone->ssutable); + } UNLOCK_ZONE(zone); } @@ -16409,8 +17013,9 @@ got_transfer_quota(isc_task_t *task, isc_event_t *event) isc_netaddr_fromsockaddr(&masterip, &zone->masteraddr); (void)dns_peerlist_peerbyaddr(zone->view->peers, &masterip, &peer); - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_SOABEFOREAXFR)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_SOABEFOREAXFR)) { soa_before = "SOA before "; + } /* * Decide whether we should request IXFR or AXFR. */ @@ -16441,20 +17046,23 @@ got_transfer_quota(isc_task_t *task, isc_event_t *event) UNLOCK_ZONE(zone); } else { bool use_ixfr = true; - if (peer != NULL) + if (peer != NULL) { result = dns_peer_getrequestixfr(peer, &use_ixfr); - if (peer == NULL || result != ISC_R_SUCCESS) + } + if (peer == NULL || result != ISC_R_SUCCESS) { use_ixfr = zone->requestixfr; + } if (use_ixfr == false) { dns_zone_logc(zone, DNS_LOGCATEGORY_XFER_IN, ISC_LOG_DEBUG(1), "IXFR disabled, " "requesting %sAXFR from %s", soa_before, master); - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_SOABEFOREAXFR)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_SOABEFOREAXFR)) { xfrtype = dns_rdatatype_soa; - else + } else { xfrtype = dns_rdatatype_axfr; + } } else { dns_zone_logc(zone, DNS_LOGCATEGORY_XFER_IN, ISC_LOG_DEBUG(1), @@ -16478,9 +17086,10 @@ got_transfer_quota(isc_task_t *task, isc_event_t *event) dns_name_t *keyname = zone->masterkeynames[zone->curmaster]; result = dns_view_gettsig(view, keyname, &zone->tsigkey); } - if (zone->tsigkey == NULL) + if (zone->tsigkey == NULL) { result = dns_view_getpeertsig(zone->view, &masterip, &zone->tsigkey); + } if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { dns_zone_logc(zone, DNS_LOGCATEGORY_XFER_IN, ISC_LOG_ERROR, @@ -16488,20 +17097,23 @@ got_transfer_quota(isc_task_t *task, isc_event_t *event) isc_result_totext(result)); } - if (zone->masterdscps != NULL) + if (zone->masterdscps != NULL) { dscp = zone->masterdscps[zone->curmaster]; + } LOCK_ZONE(zone); masteraddr = zone->masteraddr; sourceaddr = zone->sourceaddr; switch (isc_sockaddr_pf(&masteraddr)) { case PF_INET: - if (dscp == -1) + if (dscp == -1) { dscp = zone->xfrsource4dscp; + } break; case PF_INET6: - if (dscp == -1) + if (dscp == -1) { dscp = zone->xfrsource6dscp; + } break; default: INSIST(0); @@ -16516,15 +17128,17 @@ got_transfer_quota(isc_task_t *task, isc_event_t *event) if (result == ISC_R_SUCCESS) { LOCK_ZONE(zone); if (xfrtype == dns_rdatatype_axfr) { - if (isc_sockaddr_pf(&masteraddr) == PF_INET) + if (isc_sockaddr_pf(&masteraddr) == PF_INET) { inc_stats(zone, dns_zonestatscounter_axfrreqv4); - else + } else { inc_stats(zone, dns_zonestatscounter_axfrreqv6); + } } else if (xfrtype == dns_rdatatype_ixfr) { - if (isc_sockaddr_pf(&masteraddr) == PF_INET) + if (isc_sockaddr_pf(&masteraddr) == PF_INET) { inc_stats(zone, dns_zonestatscounter_ixfrreqv4); - else + } else { inc_stats(zone, dns_zonestatscounter_ixfrreqv6); + } } UNLOCK_ZONE(zone); } @@ -16534,8 +17148,9 @@ cleanup: * zone transfer. This ensures that we get removed from * zmgr->xfrin_in_progress. */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { zone_xfrdone(zone, result); + } isc_event_free(&event); } @@ -16548,14 +17163,17 @@ static void forward_destroy(dns_forward_t *forward) { forward->magic = 0; - if (forward->request != NULL) + if (forward->request != NULL) { dns_request_destroy(&forward->request); - if (forward->msgbuf != NULL) + } + if (forward->msgbuf != NULL) { isc_buffer_free(&forward->msgbuf); + } if (forward->zone != NULL) { LOCK(&forward->zone->lock); - if (ISC_LINK_LINKED(forward, link)) + if (ISC_LINK_LINKED(forward, link)) { ISC_LIST_UNLINK(forward->zone->forwards, forward, link); + } UNLOCK(&forward->zone->lock); dns_zone_idetach(&forward->zone); } @@ -16607,8 +17225,9 @@ sendtomaster(dns_forward_t *forward) 0, forward->zone->task, forward_callback, forward, &forward->request); if (result == ISC_R_SUCCESS) { - if (!ISC_LINK_LINKED(forward, link)) + if (!ISC_LINK_LINKED(forward, link)) { ISC_LIST_APPEND(forward->zone->forwards, forward, link); + } } unlock: @@ -16646,14 +17265,16 @@ forward_callback(isc_task_t *task, isc_event_t *event) } result = dns_message_create(zone->mctx, DNS_MESSAGE_INTENTPARSE, &msg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto next_master; + } result = dns_request_getresponse(revent->request, msg, DNS_MESSAGEPARSE_PRESERVEORDER | DNS_MESSAGEPARSE_CLONEBUFFER); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto next_master; + } switch (msg->rcode) { /* @@ -16710,8 +17331,9 @@ forward_callback(isc_task_t *task, isc_event_t *event) return; next_master: - if (msg != NULL) + if (msg != NULL) { dns_message_destroy(&msg); + } isc_event_free(&event); forward->which++; dns_request_destroy(&forward->request); @@ -16753,8 +17375,9 @@ dns_zone_forwardupdate(dns_zone_t *zone, dns_message_t *msg, * If we have a SIG(0) signed message we need to preserve the * query id as that is included in the SIG(0) computation. */ - if (msg->sig0 != NULL) + if (msg->sig0 != NULL) { forward->options |= DNS_REQUESTOPT_FIXEDID; + } mr = dns_message_getrawmessage(msg); if (mr == NULL) { @@ -16764,8 +17387,9 @@ dns_zone_forwardupdate(dns_zone_t *zone, dns_message_t *msg, isc_buffer_allocate(zone->mctx, &forward->msgbuf, mr->length); result = isc_buffer_copyregion(forward->msgbuf, mr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } isc_mem_attach(zone->mctx, &forward->mctx); dns_zone_iattach(zone, &forward->zone); @@ -16785,10 +17409,11 @@ dns_zone_next(dns_zone_t *zone, dns_zone_t **next) REQUIRE(next != NULL && *next == NULL); *next = ISC_LIST_NEXT(zone, link); - if (*next == NULL) + if (*next == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } isc_result_t @@ -16798,10 +17423,11 @@ dns_zone_first(dns_zonemgr_t *zmgr, dns_zone_t **first) REQUIRE(first != NULL && *first == NULL); *first = ISC_LIST_HEAD(zmgr->zones); - if (*first == NULL) + if (*first == NULL) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_SUCCESS); + } } /*** @@ -16836,42 +17462,49 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, ISC_LIST_INIT(zmgr->xfrin_in_progress); memset(zmgr->unreachable, 0, sizeof(zmgr->unreachable)); result = isc_rwlock_init(&zmgr->rwlock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_mem; + } zmgr->transfersin = 10; zmgr->transfersperns = 2; /* Unreachable lock. */ result = isc_rwlock_init(&zmgr->urlock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_rwlock; + } /* Create a single task for queueing of SOA queries. */ result = isc_task_create(taskmgr, 1, &zmgr->task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_urlock; + } isc_task_setname(zmgr->task, "zmgr", zmgr); result = isc_ratelimiter_create(mctx, timermgr, zmgr->task, &zmgr->notifyrl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_task; + } result = isc_ratelimiter_create(mctx, timermgr, zmgr->task, &zmgr->refreshrl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_notifyrl; + } result = isc_ratelimiter_create(mctx, timermgr, zmgr->task, &zmgr->startupnotifyrl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_refreshrl; + } result = isc_ratelimiter_create(mctx, timermgr, zmgr->task, &zmgr->startuprefreshrl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_startupnotifyrl; + } /* default to 20 refresh queries / notifies per second. */ setrl(zmgr->notifyrl, &zmgr->notifyrate, 20); @@ -16896,7 +17529,7 @@ dns_zonemgr_create(isc_mem_t *mctx, isc_taskmgr_t *taskmgr, #if 0 free_iolock: isc_mutex_destroy(&zmgr->iolock); -#endif +#endif /* if 0 */ free_startupnotifyrl: isc_ratelimiter_detach(&zmgr->startupnotifyrl); free_refreshrl: @@ -16926,19 +17559,22 @@ dns_zonemgr_createzone(dns_zonemgr_t *zmgr, dns_zone_t **zonep) REQUIRE(DNS_ZONEMGR_VALID(zmgr)); REQUIRE(zonep != NULL && *zonep == NULL); - if (zmgr->mctxpool == NULL) + if (zmgr->mctxpool == NULL) { return (ISC_R_FAILURE); + } item = isc_pool_get(zmgr->mctxpool); - if (item == NULL) + if (item == NULL) { return (ISC_R_FAILURE); + } isc_mem_attach((isc_mem_t *)item, &mctx); result = dns_zone_create(&zone, mctx); isc_mem_detach(&mctx); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *zonep = zone; + } return (result); } @@ -16951,8 +17587,9 @@ dns_zonemgr_managezone(dns_zonemgr_t *zmgr, dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); REQUIRE(DNS_ZONEMGR_VALID(zmgr)); - if (zmgr->zonetasks == NULL) + if (zmgr->zonetasks == NULL) { return (ISC_R_FAILURE); + } RWLOCK(&zmgr->rwlock, isc_rwlocktype_write); LOCK_ZONE(zone); @@ -16975,8 +17612,9 @@ dns_zonemgr_managezone(dns_zonemgr_t *zmgr, dns_zone_t *zone) NULL, zone->task, zone_timer, zone, &zone->timer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_tasks; + } /* * The timer "holds" a iref. @@ -17021,8 +17659,9 @@ dns_zonemgr_releasezone(dns_zonemgr_t *zmgr, dns_zone_t *zone) UNLOCK_ZONE(zone); RWUNLOCK(&zmgr->rwlock, isc_rwlocktype_write); - if (free_now) + if (free_now) { zonemgr_free(zmgr); + } ENSURE(zone->zmgr == NULL); } @@ -17100,14 +17739,18 @@ dns_zonemgr_shutdown(dns_zonemgr_t *zmgr) isc_ratelimiter_shutdown(zmgr->startupnotifyrl); isc_ratelimiter_shutdown(zmgr->startuprefreshrl); - if (zmgr->task != NULL) + if (zmgr->task != NULL) { isc_task_destroy(&zmgr->task); - if (zmgr->zonetasks != NULL) + } + if (zmgr->zonetasks != NULL) { isc_taskpool_destroy(&zmgr->zonetasks); - if (zmgr->loadtasks != NULL) + } + if (zmgr->loadtasks != NULL) { isc_taskpool_destroy(&zmgr->loadtasks); - if (zmgr->mctxpool != NULL) + } + if (zmgr->mctxpool != NULL) { isc_pool_destroy(&zmgr->mctxpool); + } RWLOCK(&zmgr->rwlock, isc_rwlocktype_read); for (zone = ISC_LIST_HEAD(zmgr->zones); zone != NULL; @@ -17163,30 +17806,36 @@ dns_zonemgr_setsize(dns_zonemgr_t *zmgr, int num_zones) * task per 100 zones. Similarly, for anything smaller than * 2000 zones we use 2 memory contexts, then scale at 1:1000. */ - if (ntasks < 10) + if (ntasks < 10) { ntasks = 10; - if (nmctx < 2) + } + if (nmctx < 2) { nmctx = 2; + } /* Create or resize the zone task pools. */ - if (zmgr->zonetasks == NULL) + if (zmgr->zonetasks == NULL) { result = isc_taskpool_create(zmgr->taskmgr, zmgr->mctx, ntasks, 2, &pool); - else + } else { result = isc_taskpool_expand(&zmgr->zonetasks, ntasks, &pool); + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { zmgr->zonetasks = pool; + } pool = NULL; - if (zmgr->loadtasks == NULL) + if (zmgr->loadtasks == NULL) { result = isc_taskpool_create(zmgr->taskmgr, zmgr->mctx, ntasks, 2, &pool); - else + } else { result = isc_taskpool_expand(&zmgr->loadtasks, ntasks, &pool); + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { zmgr->loadtasks = pool; + } /* * We always set all tasks in the zone-load task pool to @@ -17204,14 +17853,16 @@ dns_zonemgr_setsize(dns_zonemgr_t *zmgr, int num_zones) isc_taskpool_setprivilege(zmgr->loadtasks, true); /* Create or resize the zone memory context pool. */ - if (zmgr->mctxpool == NULL) + if (zmgr->mctxpool == NULL) { result = isc_pool_create(zmgr->mctx, nmctx, mctxfree, mctxinit, NULL, &mctxpool); - else + } else { result = isc_pool_expand(&zmgr->mctxpool, nmctx, &mctxpool); + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { zmgr->mctxpool = mctxpool; + } return (result); } @@ -17290,8 +17941,9 @@ zmgr_resume_xfrs(dns_zonemgr_t *zmgr, bool multi) next = ISC_LIST_NEXT(zone, statelink); result = zmgr_start_xfrin_ifquota(zmgr, zone); if (result == ISC_R_SUCCESS) { - if (multi) + if (multi) { continue; + } /* * We successfully filled the slot. We're done. */ @@ -17362,8 +18014,9 @@ zmgr_start_xfrin_ifquota(dns_zonemgr_t *zmgr, dns_zone_t *zone) */ maxtransfersin = zmgr->transfersin; maxtransfersperns = zmgr->transfersperns; - if (peer != NULL) + if (peer != NULL) { (void)dns_peer_gettransfers(peer, &maxtransfersperns); + } /* * Count the total number of transfers that are in progress, @@ -17381,16 +18034,19 @@ zmgr_start_xfrin_ifquota(dns_zonemgr_t *zmgr, dns_zone_t *zone) UNLOCK_ZONE(x); nxfrsin++; - if (isc_netaddr_equal(&xip, &masterip)) + if (isc_netaddr_equal(&xip, &masterip)) { nxfrsperns++; + } } /* Enforce quota. */ - if (nxfrsin >= maxtransfersin) + if (nxfrsin >= maxtransfersin) { return (ISC_R_QUOTA); + } - if (nxfrsperns >= maxtransfersperns) + if (nxfrsperns >= maxtransfersperns) { return (ISC_R_QUOTA); + } gotquota: /* @@ -17467,16 +18123,18 @@ zonemgr_getio(dns_zonemgr_t *zmgr, bool high, isc_task_t *task, zmgr->ioactive++; queue = (zmgr->ioactive > zmgr->iolimit); if (queue) { - if (io->high) + if (io->high) { ISC_LIST_APPEND(zmgr->high, io, link); - else + } else { ISC_LIST_APPEND(zmgr->low, io, link); + } } UNLOCK(&zmgr->iolock); *iop = io; - if (!queue) + if (!queue) { isc_task_send(io->task, &io->event); + } return (ISC_R_SUCCESS); } @@ -17504,18 +18162,21 @@ zonemgr_putio(dns_io_t **iop) INSIST(zmgr->ioactive > 0); zmgr->ioactive--; next = HEAD(zmgr->high); - if (next == NULL) + if (next == NULL) { next = HEAD(zmgr->low); + } if (next != NULL) { - if (next->high) + if (next->high) { ISC_LIST_UNLINK(zmgr->high, next, link); - else + } else { ISC_LIST_UNLINK(zmgr->low, next, link); + } INSIST(next->event != NULL); } UNLOCK(&zmgr->iolock); - if (next != NULL) + if (next != NULL) { isc_task_send(next->task, &next->event); + } } static void @@ -17530,10 +18191,11 @@ zonemgr_cancelio(dns_io_t *io) */ LOCK(&io->zmgr->iolock); if (ISC_LINK_LINKED(io, link)) { - if (io->high) + if (io->high) { ISC_LIST_UNLINK(io->zmgr->high, io, link); - else + } else { ISC_LIST_UNLINK(io->zmgr->low, io, link); + } send_event = true; INSIST(io->event != NULL); @@ -17557,12 +18219,14 @@ zone_saveunique(dns_zone_t *zone, const char *path, const char *templat) buf = isc_mem_get(zone->mctx, buflen); result = isc_file_template(path, templat, buf, buflen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_file_renameunique(path, buf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_zone_log(zone, ISC_LOG_WARNING, "unable to load from '%s'; " @@ -17582,8 +18246,9 @@ setrl(isc_ratelimiter_t *rl, unsigned int *rate, unsigned int value) uint32_t pertic; isc_result_t result; - if (value == 0) + if (value == 0) { value = 1; + } if (value == 1) { s = 1; @@ -17769,8 +18434,9 @@ dns_zone_forcereload(dns_zone_t *zone) REQUIRE(DNS_ZONE_VALID(zone)); if (zone->type == dns_zone_master || - (zone->type == dns_zone_redirect && zone->masters == NULL)) + (zone->type == dns_zone_redirect && zone->masters == NULL)) { return; + } LOCK_ZONE(zone); DNS_ZONE_SETFLAG(zone, DNS_ZONEFLG_FORCEXFER); @@ -17825,9 +18491,9 @@ dns_zone_setrequeststats(dns_zone_t *zone, isc_stats_t *stats) REQUIRE(DNS_ZONE_VALID(zone)); LOCK_ZONE(zone); - if (zone->requeststats_on && stats == NULL) + if (zone->requeststats_on && stats == NULL) { zone->requeststats_on = false; - else if (!zone->requeststats_on && stats != NULL) { + } else if (!zone->requeststats_on && stats != NULL) { if (zone->requeststats == NULL) { isc_stats_attach(stats, &zone->requeststats); zone->requeststats_on = true; @@ -17902,10 +18568,11 @@ dns_zone_getrequeststats(dns_zone_t *zone) * false, or some cannot be incremented just after the statistics are * installed, but it shouldn't matter much in practice. */ - if (zone->requeststats_on) + if (zone->requeststats_on) { return (zone->requeststats); - else + } else { return (NULL); + } } /* @@ -17915,10 +18582,11 @@ dns_zone_getrequeststats(dns_zone_t *zone) dns_stats_t * dns_zone_getrcvquerystats(dns_zone_t *zone) { - if (zone->requeststats_on) + if (zone->requeststats_on) { return (zone->rcvquerystats); - else + } else { return (NULL); + } } void @@ -17930,11 +18598,13 @@ dns_zone_dialup(dns_zone_t *zone) DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALNOTIFY), DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)); - if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALNOTIFY)) + if (DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALNOTIFY)) { dns_zone_notify(zone); + } if (zone->type != dns_zone_master && zone->masters != NULL && - DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)) + DNS_ZONE_FLAG(zone, DNS_ZONEFLG_DIALREFRESH)) { dns_zone_refresh(zone); + } } void @@ -18009,13 +18679,15 @@ dns_zonemgr_getcount(dns_zonemgr_t *zmgr, int state) switch (state) { case DNS_ZONESTATE_XFERRUNNING: for (zone = ISC_LIST_HEAD(zmgr->xfrin_in_progress); - zone != NULL; zone = ISC_LIST_NEXT(zone, statelink)) + zone != NULL; zone = ISC_LIST_NEXT(zone, statelink)) { count++; + } break; case DNS_ZONESTATE_XFERDEFERRED: for (zone = ISC_LIST_HEAD(zmgr->waiting_for_xfrin); - zone != NULL; zone = ISC_LIST_NEXT(zone, statelink)) + zone != NULL; zone = ISC_LIST_NEXT(zone, statelink)) { count++; + } break; case DNS_ZONESTATE_SOAQUERY: for (zone = ISC_LIST_HEAD(zmgr->zones); zone != NULL; @@ -18029,8 +18701,9 @@ dns_zonemgr_getcount(dns_zonemgr_t *zmgr, int state) for (zone = ISC_LIST_HEAD(zmgr->zones); zone != NULL; zone = ISC_LIST_NEXT(zone, link)) { dns_view_t *view = zone->view; - if (view != NULL && strcmp(view->name, "_bind") == 0) + if (view != NULL && strcmp(view->name, "_bind") == 0) { continue; + } count++; } break; @@ -18038,10 +18711,12 @@ dns_zonemgr_getcount(dns_zonemgr_t *zmgr, int state) for (zone = ISC_LIST_HEAD(zmgr->zones); zone != NULL; zone = ISC_LIST_NEXT(zone, link)) { dns_view_t *view = zone->view; - if (view != NULL && strcmp(view->name, "_bind") == 0) + if (view != NULL && strcmp(view->name, "_bind") == 0) { continue; - if (zone->automatic) + } + if (zone->automatic) { count++; + } } break; default: @@ -18069,8 +18744,9 @@ dns_zone_checknames(dns_zone_t *zone, const dns_name_t *name, REQUIRE(DNS_ZONE_VALID(zone)); if (!DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKNAMES) && - rdata->type != dns_rdatatype_nsec3) + rdata->type != dns_rdatatype_nsec3) { return (ISC_R_SUCCESS); + } if (DNS_ZONE_OPTION(zone, DNS_ZONEOPT_CHECKNAMESFAIL) || rdata->type == dns_rdatatype_nsec3) { @@ -18084,8 +18760,9 @@ dns_zone_checknames(dns_zone_t *zone, const dns_name_t *name, dns_rdatatype_format(rdata->type, typebuf, sizeof(typebuf)); dns_zone_log(zone, level, "%s/%s: %s", namebuf, typebuf, dns_result_totext(DNS_R_BADOWNERNAME)); - if (fail) + if (fail) { return (DNS_R_BADOWNERNAME); + } } dns_name_init(&bad, NULL); @@ -18096,8 +18773,9 @@ dns_zone_checknames(dns_zone_t *zone, const dns_name_t *name, dns_rdatatype_format(rdata->type, typebuf, sizeof(typebuf)); dns_zone_log(zone, level, "%s/%s: %s: %s ", namebuf, typebuf, namebuf2, dns_result_totext(DNS_R_BADNAME)); - if (fail) + if (fail) { return (DNS_R_BADNAME); + } } return (ISC_R_SUCCESS); @@ -18201,8 +18879,9 @@ dns_zone_setnodes(dns_zone_t *zone, uint32_t nodes) { REQUIRE(DNS_ZONE_VALID(zone)); - if (nodes == 0) + if (nodes == 0) { nodes = 1; + } zone->nodes = nodes; } @@ -18215,10 +18894,11 @@ dns_zone_setsignatures(dns_zone_t *zone, uint32_t signatures) * We treat signatures as a signed value so explicitly * limit its range here. */ - if (signatures > INT32_MAX) + if (signatures > INT32_MAX) { signatures = INT32_MAX; - else if (signatures == 0) + } else if (signatures == 0) { signatures = 1; + } zone->signatures = signatures; } @@ -18266,8 +18946,9 @@ zone_signwithkey(dns_zone_t *zone, dns_secalg_t algorithm, uint16_t keyid, TIME_NOW(&now); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_attach(zone->db, &db); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); if (db == NULL) { @@ -18282,38 +18963,44 @@ zone_signwithkey(dns_zone_t *zone, dns_secalg_t algorithm, uint16_t keyid, if (current->db == signing->db && current->algorithm == signing->algorithm && current->keyid == signing->keyid) { - if (current->deleteit != signing->deleteit) + if (current->deleteit != signing->deleteit) { current->done = true; - else + } else { goto cleanup; + } } } result = dns_db_createiterator(signing->db, 0, &signing->dbiterator); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = dns_dbiterator_first(signing->dbiterator); + } if (result == ISC_R_SUCCESS) { dns_dbiterator_pause(signing->dbiterator); ISC_LIST_INITANDAPPEND(zone->signing, signing, link); signing = NULL; if (isc_time_isepoch(&zone->signingtime)) { zone->signingtime = now; - if (zone->task != NULL) + if (zone->task != NULL) { zone_settimer(zone, &now); + } } } cleanup: if (signing != NULL) { - if (signing->db != NULL) + if (signing->db != NULL) { dns_db_detach(&signing->db); - if (signing->dbiterator != NULL) + } + if (signing->dbiterator != NULL) { dns_dbiterator_destroy(&signing->dbiterator); + } isc_mem_put(zone->mctx, signing, sizeof *signing); } - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } return (result); } @@ -18341,8 +19028,9 @@ next_keyevent(dst_key_t *key, isc_stdtime_t *timep) for (i = 0; i <= DST_MAX_TIMES; i++) { result = dst_key_gettime(key, i, &event); if (result == ISC_R_SUCCESS && event > now && - (then == 0 || event < then)) + (then == 0 || event < then)) { then = event; + } } if (then != 0) { @@ -18362,10 +19050,11 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, isc_result_t result; dns_rdataset_init(&rdataset); - if (rdata->type == dns_rdatatype_nsec3) + if (rdata->type == dns_rdatatype_nsec3) { CHECK(dns_db_findnsec3node(db, name, false, &node)); - else + } else { CHECK(dns_db_findnode(db, name, false, &node)); + } result = dns_db_findrdataset(db, node, ver, rdata->type, 0, (isc_stdtime_t)0, &rdataset, NULL); if (result == ISC_R_NOTFOUND) { @@ -18378,8 +19067,9 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = dns_rdataset_next(&rdataset)) { dns_rdata_t myrdata = DNS_RDATA_INIT; dns_rdataset_current(&rdataset, &myrdata); - if (!dns_rdata_compare(&myrdata, rdata)) + if (!dns_rdata_compare(&myrdata, rdata)) { break; + } } dns_rdataset_disassociate(&rdataset); if (result == ISC_R_SUCCESS) { @@ -18390,8 +19080,9 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -18660,16 +19351,19 @@ clean_nsec3param(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, result = dns_db_findrdataset(db, node, ver, dns_rdatatype_dnskey, dns_rdatatype_none, 0, &rdataset, NULL); - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_NOTFOUND) + } + if (result != ISC_R_NOTFOUND) { goto failure; + } result = dns_nsec3param_deletechains(db, ver, zone, true, diff); failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -18695,8 +19389,9 @@ signed_with_alg(dns_rdataset_t *rdataset, dns_secalg_t alg) result = dns_rdata_tostruct(&rdata, &rrsig, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); dns_rdata_reset(&rdata); - if (rrsig.algorithm == alg) + if (rrsig.algorithm == alg) { return (true); + } } return (false); @@ -18713,9 +19408,10 @@ add_chains(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *ver, origin = dns_db_origin(db); CHECK(dns_private_chains(db, ver, zone->privatetype, NULL, &build_nsec3)); - if (build_nsec3) + if (build_nsec3) { CHECK(dns_nsec3_addnsec3sx(db, ver, origin, zone->minimum, false, zone->privatetype, diff)); + } CHECK(updatesecure(db, ver, origin, zone->minimum, true, diff)); failure: @@ -18803,8 +19499,9 @@ zone_rekey(dns_zone_t *zone) /* Get the CDS rdataset */ result = dns_db_findrdataset(db, node, ver, dns_rdatatype_cds, dns_rdatatype_none, 0, &cdsset, NULL); - if (result != ISC_R_SUCCESS && dns_rdataset_isassociated(&cdsset)) + if (result != ISC_R_SUCCESS && dns_rdataset_isassociated(&cdsset)) { dns_rdataset_disassociate(&cdsset); + } /* Get the CDNSKEY rdataset */ result = dns_db_findrdataset(db, node, ver, dns_rdatatype_cdnskey, @@ -19180,8 +19877,9 @@ dns_zone_nscheck(dns_zone_t *zone, dns_db_t *db, dns_dbversion_t *version, REQUIRE(errors != NULL); result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = zone_count_ns_rr(zone, db, node, version, NULL, errors, false); dns_db_detachnode(db, &node); return (result); @@ -19430,9 +20128,9 @@ dns_zone_dlzpostload(dns_zone_t *zone, dns_db_t *db) again: LOCK_ZONE(zone); INSIST(zone != zone->raw); - if (inline_secure(zone)) + if (inline_secure(zone)) { LOCK_ZONE(zone->raw); - else if (inline_raw(zone)) { + } else if (inline_raw(zone)) { secure = zone->secure; TRYLOCK_ZONE(result, secure); if (result != ISC_R_SUCCESS) { @@ -19443,23 +20141,26 @@ again: } } result = zone_postload(zone, db, loadtime, ISC_R_SUCCESS); - if (inline_secure(zone)) + if (inline_secure(zone)) { UNLOCK_ZONE(zone->raw); - else if (secure != NULL) + } else if (secure != NULL) { UNLOCK_ZONE(secure); + } UNLOCK_ZONE(zone); - return result; + return (result); } isc_result_t dns_zone_setrefreshkeyinterval(dns_zone_t *zone, uint32_t interval) { REQUIRE(DNS_ZONE_VALID(zone)); - if (interval == 0) + if (interval == 0) { return (ISC_R_RANGE); + } /* Maximum value: 24 hours (3600 minutes) */ - if (interval > (24 * 60)) + if (interval > (24 * 60)) { interval = (24 * 60); + } /* Multiply by 60 for seconds */ zone->refreshkeyinterval = interval * 60; return (ISC_R_SUCCESS); @@ -19541,8 +20242,9 @@ dns_zone_link(dns_zone_t *zone, dns_zone_t *raw) result = isc_timer_create(zmgr->timermgr, isc_timertype_inactive, NULL, NULL, zone->task, zone_timer, raw, &raw->timer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto unlock; + } /* * The timer "holds" a iref. @@ -19578,8 +20280,9 @@ dns_zone_getraw(dns_zone_t *zone, dns_zone_t **raw) LOCK(&zone->lock); INSIST(zone != zone->raw); - if (zone->raw != NULL) + if (zone->raw != NULL) { dns_zone_attach(zone->raw, raw); + } UNLOCK(&zone->lock); } @@ -20170,8 +20873,9 @@ dns_zone_getincludes(dns_zone_t *zone, char ***includesp) REQUIRE(includesp != NULL && *includesp == NULL); LOCK_ZONE(zone); - if (zone->nincludes == 0) + if (zone->nincludes == 0) { goto done; + } array = isc_mem_allocate(zone->mctx, sizeof(char *) * zone->nincludes); for (include = ISC_LIST_HEAD(zone->includes); include != NULL; @@ -20225,19 +20929,22 @@ setserial(isc_task_t *task, isc_event_t *event) ENTER; - if (zone->update_disabled) + if (zone->update_disabled) { goto failure; + } desired = sse->serial; dns_diff_init(zone->mctx, &diff); ZONEDB_LOCK(&zone->dblock, isc_rwlocktype_read); - if (zone->db != NULL) + if (zone->db != NULL) { dns_db_attach(zone->db, &db); + } ZONEDB_UNLOCK(&zone->dblock, isc_rwlocktype_read); - if (db == NULL) + if (db == NULL) { goto failure; + } dns_db_currentversion(db, &oldver); result = dns_db_newversion(db, &newver); @@ -20254,15 +20961,17 @@ setserial(isc_task_t *task, isc_event_t *event) newtuple->op = DNS_DIFFOP_ADD; oldserial = dns_soa_getserial(&oldtuple->rdata); - if (desired == 0U) + if (desired == 0U) { desired = 1; + } if (!isc_serial_gt(desired, oldserial)) { - if (desired != oldserial) + if (desired != oldserial) { dns_zone_log(zone, ISC_LOG_INFO, "setserial: desired serial (%u) " "out of range (%u-%u)", desired, oldserial + 1, (oldserial + 0x7fffffff)); + } goto failure; } @@ -20271,8 +20980,9 @@ setserial(isc_task_t *task, isc_event_t *event) CHECK(do_one_tuple(&newtuple, db, newver, &diff)); result = dns_update_signatures(&log, zone, db, oldver, newver, &diff, zone->sigvalidityinterval); - if (result != ISC_R_NOTFOUND) + if (result != ISC_R_NOTFOUND) { CHECK(result); + } /* Write changes to journal file. */ CHECK(zone_journal(zone, &diff, NULL, "setserial")); @@ -20283,16 +20993,21 @@ setserial(isc_task_t *task, isc_event_t *event) UNLOCK_ZONE(zone); failure: - if (oldtuple != NULL) + if (oldtuple != NULL) { dns_difftuple_free(&oldtuple); - if (newtuple != NULL) + } + if (newtuple != NULL) { dns_difftuple_free(&newtuple); - if (oldver != NULL) + } + if (oldver != NULL) { dns_db_closeversion(db, &oldver, false); - if (newver != NULL) + } + if (newver != NULL) { dns_db_closeversion(db, &newver, commit); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); + } dns_diff_clear(&diff); isc_event_free(&event); dns_zone_idetach(&zone); @@ -20336,8 +21051,9 @@ dns_zone_setserial(dns_zone_t *zone, uint32_t serial) isc_task_send(zone->task, &e); failure: - if (e != NULL) + if (e != NULL) { isc_event_free(&e); + } UNLOCK_ZONE(zone); return (result); } diff --git a/lib/dns/zonekey.c b/lib/dns/zonekey.c index 7866b103ef..8e4d1b4c16 100644 --- a/lib/dns/zonekey.c +++ b/lib/dns/zonekey.c @@ -33,16 +33,20 @@ dns_zonekey_iszonekey(dns_rdata_t *keyrdata) REQUIRE(keyrdata != NULL); result = dns_rdata_tostruct(keyrdata, &key, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } - if ((key.flags & DNS_KEYTYPE_NOAUTH) != 0) + if ((key.flags & DNS_KEYTYPE_NOAUTH) != 0) { iszonekey = false; - if ((key.flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) + } + if ((key.flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) { iszonekey = false; + } if (key.protocol != DNS_KEYPROTO_DNSSEC && - key.protocol != DNS_KEYPROTO_ANY) + key.protocol != DNS_KEYPROTO_ANY) { iszonekey = false; + } return (iszonekey); } diff --git a/lib/dns/zoneverify.c b/lib/dns/zoneverify.c index ce27b5f76d..7000585298 100644 --- a/lib/dns/zoneverify.c +++ b/lib/dns/zoneverify.c @@ -1619,7 +1619,6 @@ check_dnskey(vctx_t *vctx) is_ksk = ((dnskey.flags & DNS_KEYFLAG_KSK) != 0); if ((dnskey.flags & DNS_KEYOWNER_ZONE) == 0) { - ; } else if ((dnskey.flags & DNS_KEYFLAG_REVOKE) != 0) { if ((dnskey.flags & DNS_KEYFLAG_KSK) != 0 && !dns_dnssec_selfsigns(&rdata, vctx->origin, diff --git a/lib/dns/zt.c b/lib/dns/zt.c index 2a69476429..1d3550dad2 100644 --- a/lib/dns/zt.c +++ b/lib/dns/zt.c @@ -85,12 +85,14 @@ dns_zt_create(isc_mem_t *mctx, dns_rdataclass_t rdclass, dns_zt_t **ztp) zt->table = NULL; result = dns_rbt_create(mctx, auto_detach, zt, &zt->table); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_zt; + } result = isc_rwlock_init(&zt->rwlock, 0, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rbt; + } zt->mctx = NULL; isc_mem_attach(mctx, &zt->mctx); @@ -129,8 +131,9 @@ dns_zt_mount(dns_zt_t *zt, dns_zone_t *zone) RWLOCK(&zt->rwlock, isc_rwlocktype_write); result = dns_rbt_addname(zt->table, name, zone); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { dns_zone_attach(zone, &dummy); + } RWUNLOCK(&zt->rwlock, isc_rwlocktype_write); @@ -166,8 +169,9 @@ dns_zt_find(dns_zt_t *zt, const dns_name_t *name, unsigned int options, REQUIRE(VALID_ZT(zt)); - if ((options & DNS_ZTFIND_NOEXACT) != 0) + if ((options & DNS_ZTFIND_NOEXACT) != 0) { rbtoptions |= DNS_RBTFIND_NOEXACT; + } RWLOCK(&zt->rwlock, isc_rwlocktype_read); @@ -400,8 +404,9 @@ dns_zt_freezezones(dns_zt_t *zt, bool freeze) RWLOCK(&zt->rwlock, isc_rwlocktype_read); result = dns_zt_apply(zt, false, &tresult, freezezones, &freeze); RWUNLOCK(&zt->rwlock, isc_rwlocktype_read); - if (tresult == ISC_R_NOTFOUND) + if (tresult == ISC_R_NOTFOUND) { tresult = ISC_R_SUCCESS; + } return ((result == ISC_R_SUCCESS) ? tresult : result); } @@ -420,33 +425,40 @@ freezezones(dns_zone_t *zone, void *uap) int level; dns_zone_getraw(zone, &raw); - if (raw != NULL) + if (raw != NULL) { zone = raw; + } if (dns_zone_gettype(zone) != dns_zone_master) { - if (raw != NULL) + if (raw != NULL) { dns_zone_detach(&raw); + } return (ISC_R_SUCCESS); } if (!dns_zone_isdynamic(zone, true)) { - if (raw != NULL) + if (raw != NULL) { dns_zone_detach(&raw); + } return (ISC_R_SUCCESS); } frozen = dns_zone_getupdatedisabled(zone); if (freeze) { - if (frozen) + if (frozen) { result = DNS_R_FROZEN; - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { result = dns_zone_flush(zone); - if (result == ISC_R_SUCCESS) + } + if (result == ISC_R_SUCCESS) { dns_zone_setupdatedisabled(zone, freeze); + } } else { if (frozen) { result = dns_zone_loadandthaw(zone); if (result == DNS_R_CONTINUE || - result == DNS_R_UPTODATE) + result == DNS_R_UPTODATE) { result = ISC_R_SUCCESS; + } } } view = dns_zone_getview(zone); @@ -466,8 +478,9 @@ freezezones(dns_zone_t *zone, void *uap) level, "%s zone '%s/%s'%s%s: %s", freeze ? "freezing" : "thawing", zonename, classstr, sep, vname, isc_result_totext(result)); - if (raw != NULL) + if (raw != NULL) { dns_zone_detach(&raw); + } return (result); } @@ -544,24 +557,28 @@ dns_zt_apply(dns_zt_t *zt, bool stop, isc_result_t *sub, result = dns_rbtnodechain_current(&chain, NULL, NULL, &node); if (result == ISC_R_SUCCESS) { zone = node->data; - if (zone != NULL) + if (zone != NULL) { result = (action)(zone, uap); + } if (result != ISC_R_SUCCESS && stop) { tresult = result; goto cleanup; /* don't break */ } else if (result != ISC_R_SUCCESS && - tresult == ISC_R_SUCCESS) + tresult == ISC_R_SUCCESS) { tresult = result; + } } result = dns_rbtnodechain_next(&chain, NULL, NULL); } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup: dns_rbtnodechain_invalidate(&chain); - if (sub != NULL) + if (sub != NULL) { *sub = tresult; + } return (result); } diff --git a/lib/irs/context.c b/lib/irs/context.c index c8fa51cb5e..a5e11755f2 100644 --- a/lib/irs/context.c +++ b/lib/irs/context.c @@ -35,12 +35,12 @@ #ifndef RESOLV_CONF /*% location of resolve.conf */ #define RESOLV_CONF "/etc/resolv.conf" -#endif +#endif /* ifndef RESOLV_CONF */ #ifndef DNS_CONF /*% location of dns.conf */ #define DNS_CONF "/etc/dns.conf" -#endif +#endif /* ifndef DNS_CONF */ ISC_THREAD_LOCAL irs_context_t *irs_context = NULL; @@ -65,20 +65,25 @@ static void ctxs_destroy(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp, isc_socketmgr_t **socketmgrp, isc_timermgr_t **timermgrp) { - if (taskmgrp != NULL) + if (taskmgrp != NULL) { isc_taskmgr_destroy(taskmgrp); + } - if (timermgrp != NULL) + if (timermgrp != NULL) { isc_timermgr_destroy(timermgrp); + } - if (socketmgrp != NULL) + if (socketmgrp != NULL) { isc_socketmgr_destroy(socketmgrp); + } - if (actxp != NULL) + if (actxp != NULL) { isc_appctx_destroy(actxp); + } - if (mctxp != NULL) + if (mctxp != NULL) { isc_mem_destroy(mctxp); + } } static isc_result_t @@ -90,20 +95,24 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp, isc_mem_create(mctxp); result = isc_appctx_create(*mctxp, actxp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_socketmgr_createinctx(*mctxp, socketmgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_timermgr_createinctx(*mctxp, timermgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } return (ISC_R_SUCCESS); @@ -149,12 +158,14 @@ irs_context_create(irs_context_t **contextp) isc_lib_register(); result = dns_lib_init(); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = ctxs_init(&mctx, &actx, &taskmgr, &socketmgr, &timermgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = isc_app_ctxstart(actx); if (result != ISC_R_SUCCESS) { @@ -173,39 +184,45 @@ irs_context_create(irs_context_t **contextp) context->dnsconf = NULL; context->task = NULL; result = isc_task_create(taskmgr, 0, &context->task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* Create a DNS client object */ result = dns_client_createx(mctx, actx, taskmgr, socketmgr, timermgr, 0, &client, NULL, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } context->dnsclient = client; /* Read resolver configuration file */ result = irs_resconf_load(mctx, RESOLV_CONF, &context->resconf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* Set nameservers */ nameservers = irs_resconf_getnameservers(context->resconf); result = dns_client_setservers(client, dns_rdataclass_in, NULL, nameservers); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* Read advanced DNS configuration (if any) */ result = irs_dnsconf_load(mctx, DNS_CONF, &context->dnsconf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } trustedkeys = irs_dnsconf_gettrustedkeys(context->dnsconf); for (trustedkey = ISC_LIST_HEAD(*trustedkeys); trustedkey != NULL; trustedkey = ISC_LIST_NEXT(trustedkey, link)) { result = dns_client_addtrustedkey( client, dns_rdataclass_in, dns_rdatatype_dnskey, trustedkey->keyname, trustedkey->keydatabuf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } } context->magic = IRS_CONTEXT_MAGIC; @@ -214,14 +231,18 @@ irs_context_create(irs_context_t **contextp) return (ISC_R_SUCCESS); fail: - if (context->task != NULL) + if (context->task != NULL) { isc_task_detach(&context->task); - if (context->resconf != NULL) + } + if (context->resconf != NULL) { irs_resconf_destroy(&context->resconf); - if (context->dnsconf != NULL) + } + if (context->dnsconf != NULL) { irs_dnsconf_destroy(&context->dnsconf); - if (client != NULL) + } + if (client != NULL) { dns_client_destroy(&client); + } ctxs_destroy(NULL, &actx, &taskmgr, &socketmgr, &timermgr); isc_mem_putanddetach(&mctx, context, sizeof(*context)); diff --git a/lib/irs/dnsconf.c b/lib/irs/dnsconf.c index 513280fced..0c8728b88c 100644 --- a/lib/irs/dnsconf.c +++ b/lib/irs/dnsconf.c @@ -226,32 +226,37 @@ irs_dnsconf_load(isc_mem_t *mctx, const char *filename, irs_dnsconf_t **confp) * If the specified file does not exist, we'll simply with an empty * configuration. */ - if (!isc_file_exists(filename)) + if (!isc_file_exists(filename)) { goto cleanup; + } result = cfg_parser_create(mctx, NULL, &parser); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = cfg_parse_file(parser, filename, &cfg_type_dnsconf, &cfgobj); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = configure_dnsseckeys(conf, cfgobj, dns_rdataclass_in); cleanup: if (parser != NULL) { - if (cfgobj != NULL) + if (cfgobj != NULL) { cfg_obj_destroy(parser, &cfgobj); + } cfg_parser_destroy(&parser); } conf->magic = IRS_DNSCONF_MAGIC; - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *confp = conf; - else + } else { irs_dnsconf_destroy(&conf); + } return (result); } diff --git a/lib/irs/gai_strerror.c b/lib/irs/gai_strerror.c index 115e418edb..d691a1311a 100644 --- a/lib/irs/gai_strerror.c +++ b/lib/irs/gai_strerror.c @@ -74,9 +74,9 @@ static const char *gai_messages[] = { "no error", */ #if defined _WIN32 char * -#else +#else /* if defined _WIN32 */ const char * -#endif +#endif /* if defined _WIN32 */ gai_strerror(int ecode) { union { @@ -85,9 +85,10 @@ gai_strerror(int ecode) } ptr; if ((ecode < 0) || - (ecode >= (int)(sizeof(gai_messages) / sizeof(*gai_messages)))) + (ecode >= (int)(sizeof(gai_messages) / sizeof(*gai_messages)))) { ptr.const_ptr = "invalid error code"; - else + } else { ptr.const_ptr = gai_messages[ecode]; + } return (ptr.deconst_ptr); } diff --git a/lib/irs/getaddrinfo.c b/lib/irs/getaddrinfo.c index 3208f59f88..df0aba1871 100644 --- a/lib/irs/getaddrinfo.c +++ b/lib/irs/getaddrinfo.c @@ -128,7 +128,7 @@ #include #include #include -#endif +#endif /* ifdef _WIN32 */ #include #include @@ -168,7 +168,7 @@ ai_concat(struct addrinfo *ai1, struct addrinfo *ai2), #ifdef AF_LOCAL static int get_local(const char *name, int socktype, struct addrinfo **res); -#endif +#endif /* ifdef AF_LOCAL */ static int resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, @@ -208,7 +208,7 @@ parse_scopeid(const char *src, uint32_t *dst) * handle numeric scopes, we do not simply return if it fails. */ scopeid = (uint32_t)if_nametoindex(src); -#endif +#endif /* ifdef HAVE_IF_NAMETOINDEX */ /* * Fall back to numeric scope processing if if_nametoindex() either @@ -249,13 +249,15 @@ getaddrinfo(const char *hostname, const char *servname, int (*net_order[FOUND_MAX + 1])(const char *, int, struct addrinfo **, int, int); - if (hostname == NULL && servname == NULL) + if (hostname == NULL && servname == NULL) { return (EAI_NONAME); + } proto = NULL; if (hints != NULL) { - if ((hints->ai_flags & ~(ISC_AI_MASK)) != 0) + if ((hints->ai_flags & ~(ISC_AI_MASK)) != 0) { return (EAI_BADFLAGS); + } if (hints->ai_addrlen || hints->ai_canonname || hints->ai_addr || hints->ai_next) { errno = EINVAL; @@ -306,7 +308,7 @@ getaddrinfo(const char *hostname, const char *servname, return (EAI_SOCKTYPE); } break; -#endif +#endif /* ifdef AF_LOCAL */ default: return (EAI_FAMILY); } @@ -325,13 +327,15 @@ getaddrinfo(const char *hostname, const char *servname, */ if (hostname != NULL && - (family == AF_LOCAL || (family == 0 && *hostname == '/'))) + (family == AF_LOCAL || (family == 0 && *hostname == '/'))) { return (get_local(hostname, socktype, res)); + } if (servname != NULL && - (family == AF_LOCAL || (family == 0 && *servname == '/'))) + (family == AF_LOCAL || (family == 0 && *servname == '/'))) { return (get_local(servname, socktype, res)); -#endif + } +#endif /* ifdef AF_LOCAL */ /* * Ok, only AF_INET and AF_INET6 left. @@ -366,13 +370,14 @@ getaddrinfo(const char *hostname, const char *servname, if (err != 0) { return (EAI_FAIL); } -#endif +#endif /* ifdef _WIN32 */ sp = getservbyname(servname, proto); - if (sp != NULL) + if (sp != NULL) { port = sp->s_port; + } #ifdef _WIN32 WSACleanup(); -#endif +#endif /* ifdef _WIN32 */ if (sp == NULL) { return (EAI_SERVICE); } @@ -395,8 +400,9 @@ getaddrinfo(const char *hostname, const char *servname, if (hostname == NULL && (flags & AI_PASSIVE) != 0) { if (family == AF_INET || family == 0) { ai = ai_alloc(AF_INET, sizeof(struct sockaddr_in)); - if (ai == NULL) + if (ai == NULL) { return (EAI_MEMORY); + } ai->ai_socktype = socktype; ai->ai_protocol = protocol; SIN(ai->ai_addr)->sin_port = port; @@ -471,15 +477,17 @@ getaddrinfo(const char *hostname, const char *servname, goto common; } else if (ntmp[0] != '\0' && inet_pton(AF_INET6, ntmp, abuf) == 1) { - if (family && family != AF_INET6) + if (family && family != AF_INET6) { return (EAI_NONAME); + } addrsize = sizeof(struct in6_addr); addroff = offsetof(struct sockaddr_in6, sin6_addr); family = AF_INET6; goto common; } else if (inet_pton(AF_INET6, hostname, abuf) == 1) { - if (family != 0 && family != AF_INET6) + if (family != 0 && family != AF_INET6) { return (EAI_NONAME); + } inet6_addr: addrsize = sizeof(struct in6_addr); addroff = offsetof(struct sockaddr_in6, sin6_addr); @@ -490,8 +498,9 @@ getaddrinfo(const char *hostname, const char *servname, ((family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in))); - if (ai == NULL) + if (ai == NULL) { return (EAI_MEMORY); + } ai_list = ai; ai->ai_socktype = socktype; SIN(ai->ai_addr)->sin_port = port; @@ -523,8 +532,9 @@ getaddrinfo(const char *hostname, const char *servname, if (hostname == NULL && (flags & AI_PASSIVE) == 0) { set_order(family, net_order); for (i = 0; i < FOUND_MAX; i++) { - if (net_order[i] == NULL) + if (net_order[i] == NULL) { break; + } err = (net_order[i])(hostname, flags, &ai_list, socktype, port); if (err != 0) { @@ -535,13 +545,15 @@ getaddrinfo(const char *hostname, const char *servname, break; } } - } else + } else { err = resolve_name(family, hostname, flags, &ai_list, socktype, port); + } if (ai_list == NULL) { - if (err == 0) + if (err == 0) { err = EAI_NONAME; + } return (err); } @@ -619,10 +631,12 @@ make_resstate(isc_mem_t *mctx, gai_statehead_t *head, const char *hostname, return (result); } - if (head->ai_family == AF_UNSPEC || head->ai_family == AF_INET) + if (head->ai_family == AF_UNSPEC || head->ai_family == AF_INET) { need_v4 = true; - if (head->ai_family == AF_UNSPEC || head->ai_family == AF_INET6) + } + if (head->ai_family == AF_UNSPEC || head->ai_family == AF_INET6) { need_v6 = true; + } state->trans6 = NULL; state->trans4 = NULL; @@ -663,8 +677,9 @@ make_resstates(isc_mem_t *mctx, const char *hostname, gai_statehead_t *head, resstate0 = NULL; result = make_resstate(mctx, head, hostname, ".", &resstate0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } searchlist = irs_resconf_getsearchlist(resconf); for (searchent = ISC_LIST_HEAD(*searchlist); searchent != NULL; @@ -673,8 +688,9 @@ make_resstates(isc_mem_t *mctx, const char *hostname, gai_statehead_t *head, result = make_resstate(mctx, head, hostname, (const char *)searchent->domain, &resstate); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } ISC_LIST_APPEND(head->resstates, resstate, link); head->activestates++; @@ -688,8 +704,9 @@ make_resstates(isc_mem_t *mctx, const char *hostname, gai_statehead_t *head, if (dns_name_countlabels(resstate0->qname) > irs_resconf_getndots(resconf) + 1) { ISC_LIST_PREPEND(head->resstates, resstate0, link); - } else + } else { ISC_LIST_APPEND(head->resstates, resstate0, link); + } head->activestates++; if (result != ISC_R_SUCCESS) { @@ -787,10 +804,12 @@ process_answer(isc_task_t *task, isc_event_t *event) for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { continue; - if (rdataset->type != qtype) + } + if (rdataset->type != qtype) { continue; + } for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -862,8 +881,9 @@ done: /* Make sure that error == 0 iff we have a non-empty list */ if (error == 0) { - if (trans->ai_sentinel.ai_next == NULL) + if (trans->ai_sentinel.ai_next == NULL) { error = EAI_NONAME; + } } else { if (trans->ai_sentinel.ai_next != NULL) { _freeaddrinfo(trans->ai_sentinel.ai_next); @@ -903,13 +923,15 @@ done: rest != NULL; rest = ISC_LIST_NEXT(rest, link)) { if (rest->trans4 != NULL && - rest->trans4->xid != NULL) + rest->trans4->xid != NULL) { dns_client_cancelresolve( rest->trans4->xid); + } if (rest->trans6 != NULL && - rest->trans6->xid != NULL) + rest->trans6->xid != NULL) { dns_client_cancelresolve( rest->trans6->xid); + } } } else { /* @@ -947,8 +969,9 @@ resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, /* get IRS context and the associated parameters */ irsctx = NULL; result = irs_context_get(&irsctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (EAI_FAIL); + } actx = irs_context_getappctx(irsctx); mctx = irs_context_getmctx(irsctx); @@ -984,8 +1007,9 @@ resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, if (result == ISC_R_SUCCESS) { resstate->trans4->is_inprogress = true; all_fail = false; - } else + } else { resstate->trans4->is_inprogress = false; + } } if (resstate->trans6 != NULL) { result = dns_client_startresolve( @@ -995,8 +1019,9 @@ resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, if (result == ISC_R_SUCCESS) { resstate->trans6->is_inprogress = true; all_fail = false; - } else + } else { resstate->trans6->is_inprogress = false; + } } } UNLOCK(&head.list_lock); @@ -1004,8 +1029,9 @@ resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, if (!all_fail) { /* Start all the events */ isc_app_ctxrun(actx); - } else + } else { error = EAI_FAIL; + } /* Cleanup */ while ((resstate = ISC_LIST_HEAD(head.resstates)) != NULL) { @@ -1052,10 +1078,11 @@ resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, * EAI_NONAME will be set below if no better code is found. */ if (terror == 0 || terror == EAI_NONAME) { - if (terror4 != 0 && terror4 != EAI_NONAME) + if (terror4 != 0 && terror4 != EAI_NONAME) { terror = terror4; - else if (terror6 != 0 && terror6 != EAI_NONAME) + } else if (terror6 != 0 && terror6 != EAI_NONAME) { terror = terror6; + } } isc_mem_put(mctx, resstate, sizeof(*resstate)); @@ -1063,14 +1090,15 @@ resolve_name(int family, const char *hostname, int flags, struct addrinfo **aip, if (*aip == NULL) { error = terror; - if (error == 0) + if (error == 0) { error = EAI_NONAME; + } } #if 1 /* XXX: enabled for finding leaks. should be cleaned up later. */ isc_app_ctxfinish(actx); irs_context_destroy(&irsctx); -#endif +#endif /* if 1 */ isc_mutex_destroy(&head.list_lock); return (error); @@ -1117,10 +1145,12 @@ set_order(int family, /* * Add in anything that we didn't find. */ - if ((found & FOUND_IPV4) == 0) + if ((found & FOUND_IPV4) == 0) { *net_order++ = add_ipv4; - if ((found & FOUND_IPV6) == 0) + } + if ((found & FOUND_IPV6) == 0) { *net_order++ = add_ipv6; + } } *net_order = NULL; return; @@ -1138,8 +1168,9 @@ add_ipv4(const char *hostname, int flags, struct addrinfo **aip, int socktype, UNUSED(flags); ai = ai_clone(*aip, AF_INET); /* don't use ai_clone() */ - if (ai == NULL) + if (ai == NULL) { return (EAI_MEMORY); + } *aip = ai; ai->ai_socktype = socktype; @@ -1161,8 +1192,9 @@ add_ipv6(const char *hostname, int flags, struct addrinfo **aip, int socktype, UNUSED(flags); ai = ai_clone(*aip, AF_INET6); /* don't use ai_clone() */ - if (ai == NULL) + if (ai == NULL) { return (EAI_MEMORY); + } *aip = ai; ai->ai_socktype = socktype; @@ -1186,10 +1218,12 @@ _freeaddrinfo(struct addrinfo *ai) while (ai != NULL) { ai_next = ai->ai_next; - if (ai->ai_addr != NULL) + if (ai->ai_addr != NULL) { free(ai->ai_addr); - if (ai->ai_canonname) + } + if (ai->ai_canonname) { free(ai->ai_canonname); + } free(ai); ai = ai_next; } @@ -1202,12 +1236,14 @@ get_local(const char *name, int socktype, struct addrinfo **res) struct addrinfo * ai; struct sockaddr_un *slocal; - if (socktype == 0) + if (socktype == 0) { return (EAI_SOCKTYPE); + } ai = ai_alloc(AF_LOCAL, sizeof(*slocal)); - if (ai == NULL) + if (ai == NULL) { return (EAI_MEMORY); + } slocal = SLOCAL(ai->ai_addr); strlcpy(slocal->sun_path, name, sizeof(slocal->sun_path)); @@ -1221,7 +1257,7 @@ get_local(const char *name, int socktype, struct addrinfo **res) *res = ai; return (0); } -#endif +#endif /* ifdef AF_LOCAL */ /*! * Allocate an addrinfo structure, and a sockaddr structure @@ -1239,8 +1275,9 @@ ai_alloc(int family, int addrlen) struct addrinfo *ai; ai = (struct addrinfo *)calloc(1, sizeof(*ai)); - if (ai == NULL) + if (ai == NULL) { return (NULL); + } ai->ai_addr = SA(calloc(1, addrlen)); if (ai->ai_addr == NULL) { @@ -1252,7 +1289,7 @@ ai_alloc(int family, int addrlen) ai->ai_addr->sa_family = family; #ifdef IRS_PLATFORM_HAVESALEN ai->ai_addr->sa_len = addrlen; -#endif +#endif /* ifdef IRS_PLATFORM_HAVESALEN */ return (ai); } @@ -1265,10 +1302,12 @@ ai_clone(struct addrinfo *oai, int family) ((family == AF_INET6) ? sizeof(struct sockaddr_in6) : sizeof(struct sockaddr_in))); - if (ai == NULL) + if (ai == NULL) { return (NULL); - if (oai == NULL) + } + if (oai == NULL) { return (ai); + } ai->ai_flags = oai->ai_flags; ai->ai_socktype = oai->ai_socktype; @@ -1305,14 +1344,15 @@ ai_concat(struct addrinfo *ai1, struct addrinfo *ai2) { struct addrinfo *ai_tmp; - if (ai1 == NULL) + if (ai1 == NULL) { return (ai2); - else if (ai2 == NULL) + } else if (ai2 == NULL) { return (ai1); + } for (ai_tmp = ai1; ai_tmp != NULL && ai_tmp->ai_next != NULL; - ai_tmp = ai_tmp->ai_next) - ; + ai_tmp = ai_tmp->ai_next) { + } ai_tmp->ai_next = ai2; diff --git a/lib/irs/getnameinfo.c b/lib/irs/getnameinfo.c index 3a735ba101..9964f774a5 100644 --- a/lib/irs/getnameinfo.c +++ b/lib/irs/getnameinfo.c @@ -146,28 +146,30 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, unsigned short port = 0; #ifdef IRS_PLATFORM_HAVESALEN size_t len; -#endif +#endif /* ifdef IRS_PLATFORM_HAVESALEN */ int family, i; const void *addr = NULL; char * p; #if 0 unsigned long v4a; unsigned char pfx; -#endif +#endif /* if 0 */ char numserv[sizeof("65000")]; char numaddr[sizeof("abcd:abcd:abcd:abcd:abcd:abcd:255.255.255.255") + 1 + sizeof("4294967295")]; const char *proto; int result = SUCCESS; - if (sa == NULL) + if (sa == NULL) { ERR(EAI_FAIL); + } #ifdef IRS_PLATFORM_HAVESALEN len = sa->sa_len; - if (len != salen) + if (len != salen) { ERR(EAI_FAIL); -#endif + } +#endif /* ifdef IRS_PLATFORM_HAVESALEN */ family = sa->sa_family; for (i = 0; afdl[i].a_af; i++) { @@ -181,8 +183,9 @@ getnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, ERR(EAI_FAMILY); found: - if (salen != afd->a_socklen) + if (salen != afd->a_socklen) { ERR(EAI_FAIL); + } switch (family) { case AF_INET: @@ -208,12 +211,14 @@ found: } else if ((flags & NI_NUMERICSERV) != 0 || (sp = getservbyport(port, proto)) == NULL) { snprintf(numserv, sizeof(numserv), "%d", ntohs(port)); - if ((strlen(numserv) + 1) > servlen) + if ((strlen(numserv) + 1) > servlen) { ERR(EAI_OVERFLOW); + } strlcpy(serv, numserv, servlen); } else { - if ((strlen(sp->s_name) + 1) > servlen) + if ((strlen(sp->s_name) + 1) > servlen) { ERR(EAI_OVERFLOW); + } strlcpy(serv, sp->s_name, servlen); } @@ -221,20 +226,23 @@ found: switch (sa->sa_family) { case AF_INET: v4a = ((struct sockaddr_in *)sa)->sin_addr.s_addr; - if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) + if (IN_MULTICAST(v4a) || IN_EXPERIMENTAL(v4a)) { flags |= NI_NUMERICHOST; + } v4a >>= IN_CLASSA_NSHIFT; - if (v4a == 0 || v4a == IN_LOOPBACKNET) + if (v4a == 0 || v4a == IN_LOOPBACKNET) { flags |= NI_NUMERICHOST; + } break; case AF_INET6: pfx = ((struct sockaddr_in6 *)sa)->sin6_addr.s6_addr[0]; - if (pfx == 0 || pfx == 0xfe || pfx == 0xff) + if (pfx == 0 || pfx == 0xfe || pfx == 0xff) { flags |= NI_NUMERICHOST; + } break; } -#endif +#endif /* if 0 */ if (host == NULL || hostlen == 0U) { /* @@ -245,8 +253,9 @@ found: */ } else if ((flags & NI_NUMERICHOST) != 0) { if (inet_ntop(afd->a_af, addr, numaddr, sizeof(numaddr)) == - NULL) + NULL) { ERR(EAI_SYSTEM); + } #if defined(IRS_HAVE_SIN6_SCOPE_ID) if (afd->a_af == AF_INET6 && ((const struct sockaddr_in6 *)sa)->sin6_scope_id) { @@ -258,7 +267,7 @@ found: * non-numeric scope identifier. */ stringscope = foo; -#endif +#endif /* ifdef VENDOR_SPECIFIC */ if (stringscope == NULL) { snprintf(p, sizeof(numaddr) - (p - numaddr), "%%%u", @@ -269,9 +278,10 @@ found: "%%%s", stringscope); } } -#endif - if (strlen(numaddr) + 1 > hostlen) +#endif /* if defined(IRS_HAVE_SIN6_SCOPE_ID) */ + if (strlen(numaddr) + 1 > hostlen) { ERR(EAI_OVERFLOW); + } strlcpy(host, numaddr, hostlen); } else { isc_netaddr_t netaddr; @@ -288,16 +298,18 @@ found: /* Get IRS context and the associated DNS client object */ iresult = irs_context_get(&irsctx); - if (iresult != ISC_R_SUCCESS) + if (iresult != ISC_R_SUCCESS) { ERR(EAI_FAIL); + } client = irs_context_getdnsclient(irsctx); /* Make query name */ isc_netaddr_fromsockaddr(&netaddr, (const isc_sockaddr_t *)sa); ptrname = dns_fixedname_initname(&ptrfname); iresult = dns_byaddr_createptrname(&netaddr, 0, ptrname); - if (iresult != ISC_R_SUCCESS) + if (iresult != ISC_R_SUCCESS) { ERR(EAI_FAIL); + } /* Get the PTR RRset */ ISC_LIST_INIT(answerlist); @@ -340,10 +352,12 @@ found: for (rdataset = ISC_LIST_HEAD(ptrname->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { continue; - if (rdataset->type != dns_rdatatype_ptr) + } + if (rdataset->type != dns_rdatatype_ptr) { continue; + } for (iresult = dns_rdataset_first(rdataset); iresult == ISC_R_SUCCESS; @@ -382,21 +396,26 @@ found: if (found) { if ((flags & NI_NOFQDN) != 0) { p = strchr(hoststr, '.'); - if (p) + if (p) { *p = '\0'; + } } - if (hostregion.length + 1 > hostlen) + if (hostregion.length + 1 > hostlen) { ERR(EAI_OVERFLOW); + } snprintf(host, hostlen, "%.*s", (int)hostregion.length, (char *)hostregion.base); } else { - if ((flags & NI_NAMEREQD) != 0) + if ((flags & NI_NAMEREQD) != 0) { ERR(EAI_NONAME); + } if (inet_ntop(afd->a_af, addr, numaddr, - sizeof(numaddr)) == NULL) + sizeof(numaddr)) == NULL) { ERR(EAI_SYSTEM); - if ((strlen(numaddr) + 1) > hostlen) + } + if ((strlen(numaddr) + 1) > hostlen) { ERR(EAI_OVERFLOW); + } strlcpy(host, numaddr, hostlen); } } diff --git a/lib/irs/resconf.c b/lib/irs/resconf.c index 92d84bad65..7526ce1d92 100644 --- a/lib/irs/resconf.c +++ b/lib/irs/resconf.c @@ -37,7 +37,7 @@ #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -64,11 +64,11 @@ #if !defined(NS_INADDRSZ) #define NS_INADDRSZ 4 -#endif +#endif /* if !defined(NS_INADDRSZ) */ #if !defined(NS_IN6ADDRSZ) #define NS_IN6ADDRSZ 16 -#endif +#endif /* if !defined(NS_IN6ADDRSZ) */ /*! * resolv.conf parameters @@ -92,11 +92,13 @@ struct irs_resconf { isc_mem_t * mctx; isc_sockaddrlist_t nameservers; - unsigned int numns; /*%< number of configured servers */ + unsigned int numns; /*%< number of configured servers + * */ char * domainname; char * search[RESCONFMAXSEARCH]; - uint8_t searchnxt; /*%< index for next free slot */ + uint8_t searchnxt; /*%< index for next free slot + * */ irs_resconf_searchlist_t searchlist; @@ -127,7 +129,7 @@ resconf_parseoption(irs_resconf_t *ctx, FILE *fp); #if HAVE_GET_WIN32_NAMESERVERS static isc_result_t get_win32_nameservers(irs_resconf_t *conf); -#endif +#endif /* if HAVE_GET_WIN32_NAMESERVERS */ /*! * Eat characters from FP until EOL or EOF. Returns EOF or '\n' @@ -138,8 +140,9 @@ eatline(FILE *fp) int ch; ch = fgetc(fp); - while (ch != '\n' && ch != EOF) + while (ch != '\n' && ch != EOF) { ch = fgetc(fp); + } return (ch); } @@ -155,11 +158,13 @@ eatwhite(FILE *fp) int ch; ch = fgetc(fp); - while (ch != '\n' && ch != EOF && isspace((unsigned char)ch)) + while (ch != '\n' && ch != EOF && isspace((unsigned char)ch)) { ch = fgetc(fp); + } - if (ch == ';' || ch == '#') + if (ch == ';' || ch == '#') { ch = eatline(fp); + } return (ch); } @@ -184,16 +189,18 @@ getword(FILE *fp, char *buffer, size_t size) ch = eatwhite(fp); - if (ch == EOF) + if (ch == EOF) { return (EOF); + } do { *p = '\0'; - if (ch == EOF || isspace((unsigned char)ch)) + if (ch == EOF || isspace((unsigned char)ch)) { break; - else if ((size_t)(p - buffer) == size - 1) + } else if ((size_t)(p - buffer) == size - 1) { return (EOF); /* Not enough space. */ + } *p++ = (char)ch; ch = fgetc(fp); @@ -218,8 +225,9 @@ add_server(isc_mem_t *mctx, const char *address_str, hints.ai_protocol = IPPROTO_UDP; hints.ai_flags = AI_NUMERICHOST; error = getaddrinfo(address_str, "53", &hints, &res); - if (error != 0) + if (error != 0) { return (ISC_R_BADADDRESSFORM); + } /* XXX: special case: treat all-0 IPv4 address as loopback */ if (res->ai_family == AF_INET) { @@ -228,8 +236,9 @@ add_server(isc_mem_t *mctx, const char *address_str, unsigned char loopaddress[] = { 127, 0, 0, 1 }; v4 = &((struct sockaddr_in *)res->ai_addr)->sin_addr; - if (memcmp(v4, zeroaddress, 4) == 0) + if (memcmp(v4, zeroaddress, 4) == 0) { memmove(v4, loopaddress, 4); + } } address = isc_mem_get(mctx, sizeof(*address)); @@ -259,8 +268,9 @@ create_addr(const char *buffer, isc_netaddr_t *addr, int convert_zero) if (convert_zero) { unsigned char zeroaddress[] = { 0, 0, 0, 0 }; unsigned char loopaddress[] = { 127, 0, 0, 1 }; - if (memcmp(&v4, zeroaddress, 4) == 0) + if (memcmp(&v4, zeroaddress, 4) == 0) { memmove(&v4, loopaddress, 4); + } } addr->family = AF_INET; memmove(&addr->type.in, &v4, NS_INADDRSZ); @@ -269,8 +279,9 @@ create_addr(const char *buffer, isc_netaddr_t *addr, int convert_zero) addr->family = AF_INET6; memmove(&addr->type.in6, &v6, NS_IN6ADDRSZ); addr->zone = 0; - } else + } else { return (ISC_R_BADADDRESSFORM); /* Unrecognised format. */ + } return (ISC_R_SUCCESS); } @@ -282,21 +293,25 @@ resconf_parsenameserver(irs_resconf_t *conf, FILE *fp) int cp; isc_result_t result; - if (conf->numns == RESCONFMAXNAMESERVERS) + if (conf->numns == RESCONFMAXNAMESERVERS) { return (ISC_R_SUCCESS); + } cp = getword(fp, word, sizeof(word)); - if (strlen(word) == 0U) + if (strlen(word) == 0U) { return (ISC_R_UNEXPECTEDEND); /* Nothing on line. */ - else if (cp == ' ' || cp == '\t') + } else if (cp == ' ' || cp == '\t') { cp = eatwhite(fp); + } - if (cp != EOF && cp != '\n') + if (cp != EOF && cp != '\n') { return (ISC_R_UNEXPECTEDTOKEN); /* Extra junk on line. */ + } result = add_server(conf->mctx, word, &conf->nameservers); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } conf->numns++; return (ISC_R_SUCCESS); @@ -310,16 +325,19 @@ resconf_parsedomain(irs_resconf_t *conf, FILE *fp) unsigned int i; res = getword(fp, word, sizeof(word)); - if (strlen(word) == 0U) + if (strlen(word) == 0U) { return (ISC_R_UNEXPECTEDEND); /* Nothing else on line. */ - else if (res == ' ' || res == '\t') + } else if (res == ' ' || res == '\t') { res = eatwhite(fp); + } - if (res != EOF && res != '\n') + if (res != EOF && res != '\n') { return (ISC_R_UNEXPECTEDTOKEN); /* Extra junk on line. */ + } - if (conf->domainname != NULL) + if (conf->domainname != NULL) { isc_mem_free(conf->mctx, conf->domainname); + } /* * Search and domain are mutually exclusive. @@ -364,13 +382,15 @@ resconf_parsesearch(irs_resconf_t *conf, FILE *fp) conf->searchnxt = 0; delim = getword(fp, word, sizeof(word)); - if (strlen(word) == 0U) + if (strlen(word) == 0U) { return (ISC_R_UNEXPECTEDEND); /* Nothing else on line. */ + } idx = 0; while (strlen(word) > 0U) { - if (conf->searchnxt == RESCONFMAXSEARCH) + if (conf->searchnxt == RESCONFMAXSEARCH) { goto ignore; /* Too many domains. */ + } INSIST(idx < sizeof(conf->search) / sizeof(conf->search[0])); conf->search[idx] = isc_mem_strdup(conf->mctx, word); @@ -378,10 +398,11 @@ resconf_parsesearch(irs_resconf_t *conf, FILE *fp) conf->searchnxt++; ignore: - if (delim == EOF || delim == '\n') + if (delim == EOF || delim == '\n') { break; - else + } else { delim = getword(fp, word, sizeof(word)); + } } return (ISC_R_SUCCESS); @@ -396,28 +417,33 @@ resconf_parsesortlist(irs_resconf_t *conf, FILE *fp) char * p; delim = getword(fp, word, sizeof(word)); - if (strlen(word) == 0U) + if (strlen(word) == 0U) { return (ISC_R_UNEXPECTEDEND); /* Empty line after keyword. */ + } while (strlen(word) > 0U) { - if (conf->sortlistnxt == RESCONFMAXSORTLIST) + if (conf->sortlistnxt == RESCONFMAXSORTLIST) { return (ISC_R_QUOTA); /* Too many values. */ + } p = strchr(word, '/'); - if (p != NULL) + if (p != NULL) { *p++ = '\0'; + } idx = conf->sortlistnxt; INSIST(idx < sizeof(conf->sortlist) / sizeof(conf->sortlist[0])); res = create_addr(word, &conf->sortlist[idx].addr, 1); - if (res != ISC_R_SUCCESS) + if (res != ISC_R_SUCCESS) { return (res); + } if (p != NULL) { res = create_addr(p, &conf->sortlist[idx].mask, 0); - if (res != ISC_R_SUCCESS) + if (res != ISC_R_SUCCESS) { return (res); + } } else { /* * Make up a mask. (XXX: is this correct?) @@ -429,10 +455,11 @@ resconf_parsesortlist(irs_resconf_t *conf, FILE *fp) conf->sortlistnxt++; - if (delim == EOF || delim == '\n') + if (delim == EOF || delim == '\n') { break; - else + } else { delim = getword(fp, word, sizeof(word)); + } } return (ISC_R_SUCCESS); @@ -447,25 +474,29 @@ resconf_parseoption(irs_resconf_t *conf, FILE *fp) char word[RESCONFMAXLINELEN]; delim = getword(fp, word, sizeof(word)); - if (strlen(word) == 0U) + if (strlen(word) == 0U) { return (ISC_R_UNEXPECTEDEND); /* Empty line after keyword. */ + } while (strlen(word) > 0U) { if (strcmp("debug", word) == 0) { conf->resdebug = 1; } else if (strncmp("ndots:", word, 6) == 0) { ndots = strtol(word + 6, &p, 10); - if (*p != '\0') /* Bad string. */ + if (*p != '\0') { /* Bad string. */ return (ISC_R_UNEXPECTEDTOKEN); - if (ndots < 0 || ndots > 0xff) /* Out of range. */ + } + if (ndots < 0 || ndots > 0xff) { /* Out of range. */ return (ISC_R_RANGE); + } conf->ndots = (uint8_t)ndots; } - if (delim == EOF || delim == '\n') + if (delim == EOF || delim == '\n') { break; - else + } else { delim = getword(fp, word, sizeof(word)); + } } return (ISC_R_SUCCESS); @@ -512,8 +543,9 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) conf->sortlistnxt = 0; conf->resdebug = 0; conf->ndots = 1; - for (i = 0; i < RESCONFMAXSEARCH; i++) + for (i = 0; i < RESCONFMAXSEARCH; i++) { conf->search[i] = NULL; + } errno = 0; if ((fp = fopen(filename, "r")) != NULL) { @@ -525,19 +557,19 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) break; } - if (strlen(word) == 0U) + if (strlen(word) == 0U) { rval = ISC_R_SUCCESS; - else if (strcmp(word, "nameserver") == 0) + } else if (strcmp(word, "nameserver") == 0) { rval = resconf_parsenameserver(conf, fp); - else if (strcmp(word, "domain") == 0) + } else if (strcmp(word, "domain") == 0) { rval = resconf_parsedomain(conf, fp); - else if (strcmp(word, "search") == 0) + } else if (strcmp(word, "search") == 0) { rval = resconf_parsesearch(conf, fp); - else if (strcmp(word, "sortlist") == 0) + } else if (strcmp(word, "sortlist") == 0) { rval = resconf_parsesortlist(conf, fp); - else if (strcmp(word, "options") == 0) + } else if (strcmp(word, "options") == 0) { rval = resconf_parseoption(conf, fp); - else { + } else { /* unrecognised word. Ignore entire line */ rval = ISC_R_SUCCESS; stopchar = eatline(fp); @@ -545,8 +577,9 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) break; } } - if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS) + if (ret == ISC_R_SUCCESS && rval != ISC_R_SUCCESS) { ret = rval; + } } while (1); fclose(fp); @@ -573,8 +606,9 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) } else if (conf->searchnxt > 0) { for (i = 0; i < conf->searchnxt; i++) { ret = add_search(conf, conf->search[i]); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { break; + } } } @@ -583,7 +617,7 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) if (ret != ISC_R_SUCCESS) { goto error; } -#endif +#endif /* if HAVE_GET_WIN32_NAMESERVERS */ /* If we don't find a nameserver fall back to localhost */ if (conf->numns == 0U) { @@ -597,11 +631,12 @@ irs_resconf_load(isc_mem_t *mctx, const char *filename, irs_resconf_t **confp) error: conf->magic = IRS_RESCONF_MAGIC; - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { irs_resconf_destroy(&conf); - else { - if (fp == NULL) + } else { + if (fp == NULL) { ret = ISC_R_FILENOTFOUND; + } *confp = conf; } @@ -631,12 +666,14 @@ irs_resconf_destroy(irs_resconf_t **confp) isc_mem_put(conf->mctx, address, sizeof(*address)); } - if (conf->domainname != NULL) + if (conf->domainname != NULL) { isc_mem_free(conf->mctx, conf->domainname); + } for (i = 0; i < RESCONFMAXSEARCH; i++) { - if (conf->search[i] != NULL) + if (conf->search[i] != NULL) { isc_mem_free(conf->mctx, conf->search[i]); + } } isc_mem_put(conf->mctx, conf, sizeof(*conf)); diff --git a/lib/irs/tests/resconf_test.c b/lib/irs/tests/resconf_test.c index 5a8dc2c41c..9aeed89d5f 100644 --- a/lib/irs/tests/resconf_test.c +++ b/lib/irs/tests/resconf_test.c @@ -84,7 +84,6 @@ irs_resconf_load_test(void **state) ISC_R_SUCCESS }, { "testdata/timeout.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS }, { "testdata/unknown.conf", ISC_R_SUCCESS, NULL, ISC_R_SUCCESS } - }; UNUSED(state); @@ -142,4 +141,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/irs/win32/include/irs/netdb.h b/lib/irs/win32/include/irs/netdb.h index 85c1580c66..ee2f884557 100644 --- a/lib/irs/win32/include/irs/netdb.h +++ b/lib/irs/win32/include/irs/netdb.h @@ -23,16 +23,17 @@ #ifdef ISC_IRS_NEEDADDRINFO struct addrinfo { - int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ - int ai_family; /* PF_xxx */ - int ai_socktype; /* SOCK_xxx */ - int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and + * IPv6 */ size_t ai_addrlen; /* Length of ai_addr */ char * ai_canonname; /* Canonical name for hostname */ struct sockaddr *ai_addr; /* Binary address */ struct addrinfo *ai_next; /* Next structure in linked list */ }; -#endif +#endif /* ifdef ISC_IRS_NEEDADDRINFO */ /* * Undefine all #defines we are interested in as may or may not have @@ -163,25 +164,25 @@ struct addrinfo { #ifdef getnameinfo #undef getnameinfo -#endif +#endif /* ifdef getnameinfo */ #define getnameinfo irs_getnameinfo #ifdef getaddrinfo #undef getaddrinfo -#endif +#endif /* ifdef getaddrinfo */ #define getaddrinfo irs_getaddrinfo #ifdef freeaddrinfo #undef freeaddrinfo -#endif +#endif /* ifdef freeaddrinfo */ #define freeaddrinfo irs_freeaddrinfo #ifdef gai_strerror #undef gai_strerror -#endif +#endif /* ifdef gai_strerror */ #define gai_strerror irs_gai_strerror -#endif +#endif /* ifdef IRS_NAMESPACE */ int getaddrinfo(const char *, const char *, const struct addrinfo *, diff --git a/lib/irs/win32/include/irs/platform.h b/lib/irs/win32/include/irs/platform.h index 7170a73f07..1520601c7d 100644 --- a/lib/irs/win32/include/irs/platform.h +++ b/lib/irs/win32/include/irs/platform.h @@ -15,14 +15,14 @@ #define IRS_PLATFORM_H 1 /***** - ***** Platform-dependent defines. - *****/ +***** Platform-dependent defines. +*****/ #ifdef LIBIRS_EXPORTS #define LIBIRS_EXTERNAL_DATA __declspec(dllexport) -#else +#else /* ifdef LIBIRS_EXPORTS */ #define LIBIRS_EXTERNAL_DATA __declspec(dllimport) -#endif +#endif /* ifdef LIBIRS_EXPORTS */ /* * Tell Emacs to use C mode on this file. diff --git a/lib/isc/aes.c b/lib/isc/aes.c index 3c24b2ba56..f98acd000e 100644 --- a/lib/isc/aes.c +++ b/lib/isc/aes.c @@ -24,7 +24,8 @@ #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) #define EVP_CIPHER_CTX_new() &(_context), EVP_CIPHER_CTX_init(&_context) #define EVP_CIPHER_CTX_free(c) RUNTIME_CHECK(EVP_CIPHER_CTX_cleanup(c) == 1) -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ void isc_aes128_crypt(const unsigned char *key, const unsigned char *in, @@ -32,7 +33,8 @@ isc_aes128_crypt(const unsigned char *key, const unsigned char *in, { #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) EVP_CIPHER_CTX _context; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ EVP_CIPHER_CTX *c; int len; @@ -52,7 +54,8 @@ isc_aes192_crypt(const unsigned char *key, const unsigned char *in, { #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) EVP_CIPHER_CTX _context; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ EVP_CIPHER_CTX *c; int len; @@ -72,7 +75,8 @@ isc_aes256_crypt(const unsigned char *key, const unsigned char *in, { #if OPENSSL_VERSION_NUMBER < 0x10100000L || defined(LIBRESSL_VERSION_NUMBER) EVP_CIPHER_CTX _context; -#endif +#endif /* if OPENSSL_VERSION_NUMBER < 0x10100000L || \ + * defined(LIBRESSL_VERSION_NUMBER) */ EVP_CIPHER_CTX *c; int len; diff --git a/lib/isc/app.c b/lib/isc/app.c index 18dee4f96c..2348265816 100644 --- a/lib/isc/app.c +++ b/lib/isc/app.c @@ -59,7 +59,7 @@ static atomic_bool is_running; * We need to remember which thread is the main thread... */ static isc_thread_t main_thread; -#endif +#endif /* ifdef WIN32 */ /* * The application context of this module. @@ -109,7 +109,7 @@ handle_signal(int sig, void (*handler)(int)) "handle_signal() %d setup: %s", sig, strbuf); } } -#endif +#endif /* ifndef WIN32 */ isc_result_t isc_app_ctxstart(isc_appctx_t *ctx) @@ -240,7 +240,7 @@ isc_app_ctxrun(isc_appctx_t *ctx) #ifdef WIN32 REQUIRE(main_thread == GetCurrentThread()); -#endif +#endif /* ifdef WIN32 */ if (atomic_compare_exchange_weak_acq_rel(&ctx->running, &exp_false, true) == true) { diff --git a/lib/isc/assertions.c b/lib/isc/assertions.c index 1de7a703a1..cbabec3a97 100644 --- a/lib/isc/assertions.c +++ b/lib/isc/assertions.c @@ -24,7 +24,7 @@ */ #ifndef BACKTRACE_MAXFRAME #define BACKTRACE_MAXFRAME 128 -#endif +#endif /* ifndef BACKTRACE_MAXFRAME */ /*% * Forward. @@ -53,10 +53,11 @@ isc_assertion_failed(const char *file, int line, isc_assertiontype_t type, void isc_assertion_setcallback(isc_assertioncallback_t cb) { - if (cb == NULL) + if (cb == NULL) { isc_assertion_failed_cb = default_callback; - else + } else { isc_assertion_failed_cb = cb; + } } /*% Type to Text */ diff --git a/lib/isc/backtrace.c b/lib/isc/backtrace.c index 8d188aaaee..56f0ad9210 100644 --- a/lib/isc/backtrace.c +++ b/lib/isc/backtrace.c @@ -15,7 +15,7 @@ #include #ifdef HAVE_LIBCTRACE #include -#endif +#endif /* ifdef HAVE_LIBCTRACE */ #include #include @@ -46,7 +46,7 @@ #define BACKTRACE_WIN32 #elif defined(__x86_64__) || defined(__i386__) #define BACKTRACE_X86STACK -#else +#else /* ifdef HAVE_LIBCTRACE */ #define BACKTRACE_DISABLED #endif /* HAVE_LIBCTRACE */ #else /* USE_BACKTRACE */ @@ -63,16 +63,18 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) * Validate the arguments: intentionally avoid using REQUIRE(). * See notes in backtrace.h. */ - if (addrs == NULL || nframes == NULL) + if (addrs == NULL || nframes == NULL) { return (ISC_R_FAILURE); + } /* * backtrace(3) includes this function itself in the address array, * which should be eliminated from the returned sequence. */ n = backtrace(addrs, maxaddrs); - if (n < 2) + if (n < 2) { return (ISC_R_NOTFOUND); + } n--; memmove(addrs, &addrs[1], sizeof(void *) * n); *nframes = n; @@ -96,13 +98,14 @@ btcallback(void *uc, void *opq) { trace_arg_t *arg = (trace_arg_t *)opq; - if (arg->skip_count > 0) + if (arg->skip_count > 0) { arg->skip_count--; - else + } else { arg->result[arg->count++] = (void *)_Unwind_GetIP(uc); - if (arg->count == arg->max_depth) + } + if (arg->count == arg->max_depth) { return (5); /* _URC_END_OF_STACK */ - + } return (0); /* _URC_NO_REASON */ } @@ -112,8 +115,9 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) trace_arg_t arg; /* Argument validation: see above. */ - if (addrs == NULL || nframes == NULL) + if (addrs == NULL || nframes == NULL) { return (ISC_R_FAILURE); + } arg.skip_count = 1; arg.result = addrs; @@ -132,7 +136,7 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) unsigned long ftc = (unsigned long)maxaddrs; *nframes = (int)CaptureStackBackTrace(1, ftc, addrs, NULL); - return ISC_R_SUCCESS; + return (ISC_R_SUCCESS); } #elif defined(BACKTRACE_X86STACK) #ifdef __x86_64__ @@ -141,7 +145,7 @@ getrbp(void) { __asm("movq %rbp, %rax\n"); } -#endif +#endif /* ifdef __x86_64__ */ static void ** getnextframeptr(void **sp) @@ -154,12 +158,14 @@ getnextframeptr(void **sp) */ /* prohibit the stack frames from growing downwards */ - if (newsp <= sp) + if (newsp <= sp) { return (NULL); + } /* A heuristics to reject "too large" frame: this actually happened. */ - if ((char *)newsp - (char *)sp > 100000) + if ((char *)newsp - (char *)sp > 100000) { return (NULL); + } /* * Not sure if other checks used in glog are needed at this moment. @@ -177,26 +183,28 @@ isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) void **sp; /* Argument validation: see above. */ - if (addrs == NULL || nframes == NULL) + if (addrs == NULL || nframes == NULL) { return (ISC_R_FAILURE); + } #ifdef __x86_64__ sp = (void **)getrbp(); - if (sp == NULL) + if (sp == NULL) { return (ISC_R_NOTFOUND); + } /* * sp is the frame ptr of this function itself due to the call to * getrbp(), so need to unwind one frame for consistency. */ sp = getnextframeptr(sp); -#else +#else /* ifdef __x86_64__ */ /* * i386: the frame pointer is stored 2 words below the address for the * first argument. Note that the body of this function cannot be * inlined since it depends on the address of the function argument. */ sp = (void **)&addrs - 2; -#endif +#endif /* ifdef __x86_64__ */ while (sp != NULL && i < maxaddrs) { addrs[i++] = *(sp + 1); @@ -212,14 +220,15 @@ isc_result_t isc_backtrace_gettrace(void **addrs, int maxaddrs, int *nframes) { /* Argument validation: see above. */ - if (addrs == NULL || nframes == NULL) + if (addrs == NULL || nframes == NULL) { return (ISC_R_FAILURE); + } UNUSED(maxaddrs); return (ISC_R_NOTIMPLEMENTED); } -#endif +#endif /* ifdef BACKTRACE_LIBC */ isc_result_t isc_backtrace_getsymbolfromindex(int idx, const void **addrp, @@ -228,8 +237,9 @@ isc_backtrace_getsymbolfromindex(int idx, const void **addrp, REQUIRE(addrp != NULL && *addrp == NULL); REQUIRE(symbolp != NULL && *symbolp == NULL); - if (idx < 0 || idx >= isc__backtrace_nsymbols) + if (idx < 0 || idx >= isc__backtrace_nsymbols) { return (ISC_R_RANGE); + } *addrp = isc__backtrace_symtable[idx].addr; *symbolp = isc__backtrace_symtable[idx].symbol; @@ -256,10 +266,11 @@ symtbl_compare(const void *addr, const void *entryarg) } /* entry + 1 is a valid entry from now on. */ - if (addr < entry->addr) + if (addr < entry->addr) { return (-1); - else if (addr >= (entry + 1)->addr) + } else if (addr >= (entry + 1)->addr) { return (1); + } return (0); } @@ -274,11 +285,13 @@ isc_backtrace_getsymbol(const void *addr, const char **symbolp, * Validate the arguments: intentionally avoid using REQUIRE(). * See notes in backtrace.h. */ - if (symbolp == NULL || *symbolp != NULL || offsetp == NULL) + if (symbolp == NULL || *symbolp != NULL || offsetp == NULL) { return (ISC_R_FAILURE); + } - if (isc__backtrace_nsymbols < 1) + if (isc__backtrace_nsymbols < 1) { return (ISC_R_NOTFOUND); + } /* * Search the table for the entry that meets: @@ -286,9 +299,9 @@ isc_backtrace_getsymbol(const void *addr, const char **symbolp, */ found = bsearch(addr, isc__backtrace_symtable, isc__backtrace_nsymbols, sizeof(isc__backtrace_symtable[0]), symtbl_compare); - if (found == NULL) + if (found == NULL) { result = ISC_R_NOTFOUND; - else { + } else { *symbolp = found->symbol; *offsetp = (unsigned long)((const char *)addr - (char *)found->addr); diff --git a/lib/isc/base32.c b/lib/isc/base32.c index f66423676e..a2942f16e0 100644 --- a/lib/isc/base32.c +++ b/lib/isc/base32.c @@ -24,7 +24,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) /*@{*/ @@ -52,8 +52,9 @@ base32_totext(isc_region_t *source, int wordlength, const char *wordbreak, char buf[9]; unsigned int loops = 0; - if (wordlength >= 0 && wordlength < 8) + if (wordlength >= 0 && wordlength < 8) { wordlength = 8; + } memset(buf, 0, sizeof(buf)); while (source->length > 0) { @@ -104,8 +105,9 @@ base32_totext(isc_region_t *source, int wordlength, const char *wordbreak, RETERR(str_totext(wordbreak, target)); } } - if (source->length > 0) + if (source->length > 0) { isc_region_consume(source, source->length); + } return (ISC_R_SUCCESS); } @@ -143,8 +145,9 @@ typedef struct { bool seen_end; /*%< True if "=" end marker seen */ int val[8]; const char * base; /*%< Which encoding we are using */ - int seen_32; /*%< Number of significant bytes if non zero */ - bool pad; /*%< Expect padding */ + int seen_32; /*%< Number of significant bytes if non + * zero */ + bool pad; /*%< Expect padding */ } base32_decode_ctx_t; static inline void @@ -166,65 +169,75 @@ base32_decode_char(base32_decode_ctx_t *ctx, int c) const char * s; unsigned int last; - if (ctx->seen_end) + if (ctx->seen_end) { return (ISC_R_BADBASE32); - if ((s = strchr(ctx->base, c)) == NULL) + } + if ((s = strchr(ctx->base, c)) == NULL) { return (ISC_R_BADBASE32); + } last = (unsigned int)(s - ctx->base); /* * Handle lower case. */ - if (last > 32) + if (last > 32) { last -= 33; + } /* * Check that padding is contiguous. */ - if (last != 32 && ctx->seen_32 != 0) + if (last != 32 && ctx->seen_32 != 0) { return (ISC_R_BADBASE32); + } /* * If padding is not permitted flag padding as a error. */ - if (last == 32 && !ctx->pad) + if (last == 32 && !ctx->pad) { return (ISC_R_BADBASE32); + } /* * Check that padding starts at the right place and that * bits that should be zero are. * Record how many significant bytes in answer (seen_32). */ - if (last == 32 && ctx->seen_32 == 0) + if (last == 32 && ctx->seen_32 == 0) { switch (ctx->digits) { case 0: case 1: return (ISC_R_BADBASE32); case 2: - if ((ctx->val[1] & 0x03) != 0) + if ((ctx->val[1] & 0x03) != 0) { return (ISC_R_BADBASE32); + } ctx->seen_32 = 1; break; case 3: return (ISC_R_BADBASE32); case 4: - if ((ctx->val[3] & 0x0f) != 0) + if ((ctx->val[3] & 0x0f) != 0) { return (ISC_R_BADBASE32); + } ctx->seen_32 = 3; break; case 5: - if ((ctx->val[4] & 0x01) != 0) + if ((ctx->val[4] & 0x01) != 0) { return (ISC_R_BADBASE32); + } ctx->seen_32 = 3; break; case 6: return (ISC_R_BADBASE32); case 7: - if ((ctx->val[6] & 0x07) != 0) + if ((ctx->val[6] & 0x07) != 0) { return (ISC_R_BADBASE32); + } ctx->seen_32 = 4; break; } + } /* * Zero fill pad values. @@ -248,10 +261,11 @@ base32_decode_char(base32_decode_ctx_t *ctx, int c) buf[4] = (ctx->val[6] << 5) | (ctx->val[7]); RETERR(mem_tobuffer(ctx->target, buf, n)); if (ctx->length >= 0) { - if (n > ctx->length) + if (n > ctx->length) { return (ISC_R_BADBASE32); - else + } else { ctx->length -= n; + } } ctx->digits = 0; } @@ -261,8 +275,9 @@ base32_decode_char(base32_decode_ctx_t *ctx, int c) static inline isc_result_t base32_decode_finish(base32_decode_ctx_t *ctx) { - if (ctx->length > 0) + if (ctx->length > 0) { return (ISC_R_UNEXPECTEDEND); + } /* * Add missing padding if required. */ @@ -272,8 +287,9 @@ base32_decode_finish(base32_decode_ctx_t *ctx) RETERR(base32_decode_char(ctx, '=')); } while (ctx->digits != 0); } - if (ctx->digits != 0) + if (ctx->digits != 0) { return (ISC_R_BADBASE32); + } return (ISC_R_SUCCESS); } @@ -348,10 +364,12 @@ base32_decodestring(const char *cstr, const char base[], bool pad, base32_decode_init(&ctx, -1, base, pad, target); for (;;) { int c = *cstr++; - if (c == '\0') + if (c == '\0') { break; - if (c == ' ' || c == '\t' || c == '\n' || c == '\r') + } + if (c == ' ' || c == '\t' || c == '\n' || c == '\r') { continue; + } RETERR(base32_decode_char(&ctx, c)); } RETERR(base32_decode_finish(&ctx)); @@ -419,8 +437,9 @@ str_totext(const char *source, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(source); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, source, l); isc_buffer_add(target, l); @@ -433,8 +452,9 @@ mem_tobuffer(isc_buffer_t *target, void *base, unsigned int length) isc_region_t tr; isc_buffer_availableregion(target, &tr); - if (length > tr.length) + if (length > tr.length) { return (ISC_R_NOSPACE); + } memmove(tr.base, base, length); isc_buffer_add(target, length); return (ISC_R_SUCCESS); diff --git a/lib/isc/base64.c b/lib/isc/base64.c index c20f3a32ee..b812a29360 100644 --- a/lib/isc/base64.c +++ b/lib/isc/base64.c @@ -23,7 +23,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) /*@{*/ @@ -48,8 +48,9 @@ isc_base64_totext(isc_region_t *source, int wordlength, const char *wordbreak, char buf[5]; unsigned int loops = 0; - if (wordlength < 4) + if (wordlength < 4) { wordlength = 4; + } memset(buf, 0, sizeof(buf)); while (source->length > 2) { @@ -112,46 +113,55 @@ base64_decode_char(base64_decode_ctx_t *ctx, int c) { const char *s; - if (ctx->seen_end) + if (ctx->seen_end) { return (ISC_R_BADBASE64); - if ((s = strchr(base64, c)) == NULL) + } + if ((s = strchr(base64, c)) == NULL) { return (ISC_R_BADBASE64); + } ctx->val[ctx->digits++] = (int)(s - base64); if (ctx->digits == 4) { int n; unsigned char buf[3]; - if (ctx->val[0] == 64 || ctx->val[1] == 64) + if (ctx->val[0] == 64 || ctx->val[1] == 64) { return (ISC_R_BADBASE64); - if (ctx->val[2] == 64 && ctx->val[3] != 64) + } + if (ctx->val[2] == 64 && ctx->val[3] != 64) { return (ISC_R_BADBASE64); + } /* * Check that bits that should be zero are. */ - if (ctx->val[2] == 64 && (ctx->val[1] & 0xf) != 0) + if (ctx->val[2] == 64 && (ctx->val[1] & 0xf) != 0) { return (ISC_R_BADBASE64); + } /* * We don't need to test for ctx->val[2] != 64 as * the bottom two bits of 64 are zero. */ - if (ctx->val[3] == 64 && (ctx->val[2] & 0x3) != 0) + if (ctx->val[3] == 64 && (ctx->val[2] & 0x3) != 0) { return (ISC_R_BADBASE64); + } n = (ctx->val[2] == 64) ? 1 : (ctx->val[3] == 64) ? 2 : 3; if (n != 3) { ctx->seen_end = true; - if (ctx->val[2] == 64) + if (ctx->val[2] == 64) { ctx->val[2] = 0; - if (ctx->val[3] == 64) + } + if (ctx->val[3] == 64) { ctx->val[3] = 0; + } } buf[0] = (ctx->val[0] << 2) | (ctx->val[1] >> 4); buf[1] = (ctx->val[1] << 4) | (ctx->val[2] >> 2); buf[2] = (ctx->val[2] << 6) | (ctx->val[3]); RETERR(mem_tobuffer(ctx->target, buf, n)); if (ctx->length >= 0) { - if (n > ctx->length) + if (n > ctx->length) { return (ISC_R_BADBASE64); - else + } else { ctx->length -= n; + } } ctx->digits = 0; } @@ -161,10 +171,12 @@ base64_decode_char(base64_decode_ctx_t *ctx, int c) static inline isc_result_t base64_decode_finish(base64_decode_ctx_t *ctx) { - if (ctx->length > 0) + if (ctx->length > 0) { return (ISC_R_UNEXPECTEDEND); - if (ctx->digits != 0) + } + if (ctx->digits != 0) { return (ISC_R_BADBASE64); + } return (ISC_R_SUCCESS); } @@ -219,10 +231,12 @@ isc_base64_decodestring(const char *cstr, isc_buffer_t *target) base64_decode_init(&ctx, -1, target); for (;;) { int c = *cstr++; - if (c == '\0') + if (c == '\0') { break; - if (c == ' ' || c == '\t' || c == '\n' || c == '\r') + } + if (c == ' ' || c == '\t' || c == '\n' || c == '\r') { continue; + } RETERR(base64_decode_char(&ctx, c)); } RETERR(base64_decode_finish(&ctx)); @@ -238,8 +252,9 @@ str_totext(const char *source, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(source); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, source, l); isc_buffer_add(target, l); @@ -252,8 +267,9 @@ mem_tobuffer(isc_buffer_t *target, void *base, unsigned int length) isc_region_t tr; isc_buffer_availableregion(target, &tr); - if (length > tr.length) + if (length > tr.length) { return (ISC_R_NOSPACE); + } memmove(tr.base, base, length); isc_buffer_add(target, length); return (ISC_R_SUCCESS); diff --git a/lib/isc/buffer.c b/lib/isc/buffer.c index f28b8364d6..3b90812364 100644 --- a/lib/isc/buffer.c +++ b/lib/isc/buffer.c @@ -279,10 +279,11 @@ isc_buffer_compact(isc_buffer_t *b) (void)memmove(b->base, src, (size_t)length); } - if (b->active > b->current) + if (b->active > b->current) { b->active -= b->current; - else + } else { b->active = 0; + } b->current = 0; b->used = length; } diff --git a/lib/isc/commandline.c b/lib/isc/commandline.c index f1e80b8ca2..6db7c5163f 100644 --- a/lib/isc/commandline.c +++ b/lib/isc/commandline.c @@ -96,8 +96,9 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) isc_commandline_reset = false; } - if (isc_commandline_progname == NULL) + if (isc_commandline_progname == NULL) { isc_commandline_progname = argv[0]; + } if (isc_commandline_index >= argc || *(place = argv[isc_commandline_index]) != '-') { @@ -128,13 +129,15 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) * distinguish ':' from the argument specifier in the options string. */ if (isc_commandline_option == ':' || option == NULL) { - if (*place == '\0') + if (*place == '\0') { isc_commandline_index++; + } - if (isc_commandline_errprint && *options != ':') + if (isc_commandline_errprint && *options != ':') { fprintf(stderr, "%s: illegal option -- %c\n", isc_commandline_progname, isc_commandline_option); + } return (BADOPT); } @@ -148,26 +151,24 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) /* * Skip to next argv if at the end of the current argv. */ - if (*place == '\0') + if (*place == '\0') { ++isc_commandline_index; - + } } else { /* * Option needs an argument. */ - if (*place != '\0') + if (*place != '\0') { /* * Option is in this argv, -D1 style. */ isc_commandline_argument = place; - - else if (argc > ++isc_commandline_index) + } else if (argc > ++isc_commandline_index) { /* * Option is next argv, -D 1 style. */ isc_commandline_argument = argv[isc_commandline_index]; - - else { + } else { /* * Argument needed, but no more argv. */ @@ -177,15 +178,17 @@ isc_commandline_parse(int argc, char *const *argv, const char *options) * Silent failure with "missing argument" return * when ':' starts options string, per historical spec. */ - if (*options == ':') + if (*options == ':') { return (BADARG); + } - if (isc_commandline_errprint) + if (isc_commandline_errprint) { fprintf(stderr, "%s: option requires an argument -- " "%c\n", isc_commandline_progname, isc_commandline_option); + } return (BADOPT); } @@ -209,8 +212,9 @@ isc_commandline_strtoargv(isc_mem_t *mctx, char *s, unsigned int *argcp, restart: /* Discard leading whitespace. */ - while (*s == ' ' || *s == '\t') + while (*s == ' ' || *s == '\t') { s++; + } if (*s == '\0') { /* We have reached the end of the string. */ @@ -245,13 +249,15 @@ restart: p++; } /* normal case, no "grouping" */ - } else if (*p != '\0') + } else if (*p != '\0') { *p++ = '\0'; + } result = isc_commandline_strtoargv(mctx, p, argcp, argvp, n + 1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } (*argvp)[n] = s; } diff --git a/lib/isc/error.c b/lib/isc/error.c index 9a4a8dea14..887c49c259 100644 --- a/lib/isc/error.c +++ b/lib/isc/error.c @@ -34,19 +34,21 @@ static isc_errorcallback_t fatal_callback = default_fatal_callback; void isc_error_setunexpected(isc_errorcallback_t cb) { - if (cb == NULL) + if (cb == NULL) { unexpected_callback = default_unexpected_callback; - else + } else { unexpected_callback = cb; + } } void isc_error_setfatal(isc_errorcallback_t cb) { - if (cb == NULL) + if (cb == NULL) { fatal_callback = default_fatal_callback; - else + } else { fatal_callback = cb; + } } void diff --git a/lib/isc/event.c b/lib/isc/event.c index 2d812cf306..97bcb0e756 100644 --- a/lib/isc/event.c +++ b/lib/isc/event.c @@ -91,6 +91,7 @@ isc_event_free(isc_event_t **eventp) REQUIRE(!ISC_LINK_LINKED(event, ev_link)); REQUIRE(!ISC_LINK_LINKED(event, ev_ratelink)); - if (event->ev_destroy != NULL) + if (event->ev_destroy != NULL) { (event->ev_destroy)(event); + } } diff --git a/lib/isc/fsaccess.c b/lib/isc/fsaccess.c index a00a1b32a7..f90d5fedde 100644 --- a/lib/isc/fsaccess.c +++ b/lib/isc/fsaccess.c @@ -35,14 +35,17 @@ isc_fsaccess_add(int trustee, int permission, isc_fsaccess_t *access) REQUIRE(trustee <= 0x7); REQUIRE(permission <= 0xFF); - if ((trustee & ISC_FSACCESS_OWNER) != 0) + if ((trustee & ISC_FSACCESS_OWNER) != 0) { *access |= permission; + } - if ((trustee & ISC_FSACCESS_GROUP) != 0) + if ((trustee & ISC_FSACCESS_GROUP) != 0) { *access |= (permission << GROUP); + } - if ((trustee & ISC_FSACCESS_OTHER) != 0) + if ((trustee & ISC_FSACCESS_OTHER) != 0) { *access |= (permission << OTHER); + } } void @@ -51,14 +54,17 @@ isc_fsaccess_remove(int trustee, int permission, isc_fsaccess_t *access) REQUIRE(trustee <= 0x7); REQUIRE(permission <= 0xFF); - if ((trustee & ISC_FSACCESS_OWNER) != 0) + if ((trustee & ISC_FSACCESS_OWNER) != 0) { *access &= ~permission; + } - if ((trustee & ISC_FSACCESS_GROUP) != 0) + if ((trustee & ISC_FSACCESS_GROUP) != 0) { *access &= ~(permission << GROUP); + } - if ((trustee & ISC_FSACCESS_OTHER) != 0) + if ((trustee & ISC_FSACCESS_OTHER) != 0) { *access &= ~(permission << OTHER); + } } static isc_result_t @@ -69,12 +75,13 @@ check_bad_bits(isc_fsaccess_t access, bool is_dir) /* * Check for disallowed user bits. */ - if (is_dir) + if (is_dir) { bits = ISC_FSACCESS_READ | ISC_FSACCESS_WRITE | ISC_FSACCESS_EXECUTE; - else + } else { bits = ISC_FSACCESS_CREATECHILD | ISC_FSACCESS_ACCESSCHILD | ISC_FSACCESS_DELETECHILD | ISC_FSACCESS_LISTDIRECTORY; + } /* * Set group bad bits. @@ -86,10 +93,11 @@ check_bad_bits(isc_fsaccess_t access, bool is_dir) bits |= bits << STEP; if ((access & bits) != 0) { - if (is_dir) + if (is_dir) { return (ISC_R_NOTFILE); - else + } else { return (ISC_R_NOTDIRECTORY); + } } return (ISC_R_SUCCESS); diff --git a/lib/isc/hash.c b/lib/isc/hash.c index 893260a942..aaceef5444 100644 --- a/lib/isc/hash.c +++ b/lib/isc/hash.c @@ -18,10 +18,10 @@ #include #if defined(WIN32) || defined(WIN64) #include -#endif +#endif /* if defined(WIN32) || defined(WIN64) */ #include "entropy_private.h" -#include "isc/hash.h" // IWYU pragma: keep +#include "isc/hash.h" /* IWYU pragma: keep */ #include "isc/likely.h" #include "isc/once.h" #include "isc/random.h" @@ -44,9 +44,9 @@ isc_hash_initialize(void) * Set a constant key to help in problem reproduction should * fuzzing find a crash or a hang. */ -#else +#else /* if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ isc_entropy_get(key, sizeof(key)); -#endif +#endif /* if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ memmove(isc_hash_key, key, sizeof(isc_hash_key)); hash_initialized = true; } diff --git a/lib/isc/heap.c b/lib/isc/heap.c index 52659a85d9..d2e5e4c486 100644 --- a/lib/isc/heap.c +++ b/lib/isc/heap.c @@ -73,9 +73,9 @@ heap_check(isc_heap_t *heap) INSIST(HEAPCONDITION(i)); } } -#else +#else /* ifdef ISC_HEAP_CHECK */ #define heap_check(x) (void)0 -#endif +#endif /* ifdef ISC_HEAP_CHECK */ isc_result_t isc_heap_create(isc_mem_t *mctx, isc_heapcompare_t compare, isc_heapindex_t idx, @@ -91,10 +91,11 @@ isc_heap_create(isc_mem_t *mctx, isc_heapcompare_t compare, isc_heapindex_t idx, heap->size = 0; heap->mctx = NULL; isc_mem_attach(mctx, &heap->mctx); - if (size_increment == 0) + if (size_increment == 0) { heap->size_increment = SIZE_INCREMENT; - else + } else { heap->size_increment = size_increment; + } heap->last = 0; heap->array = NULL; heap->compare = compare; @@ -115,9 +116,10 @@ isc_heap_destroy(isc_heap_t **heapp) *heapp = NULL; REQUIRE(VALID_HEAP(heap)); - if (heap->array != NULL) + if (heap->array != NULL) { isc_mem_put(heap->mctx, heap->array, heap->size * sizeof(void *)); + } heap->magic = 0; isc_mem_putanddetach(&heap->mctx, heap, sizeof(*heap)); } @@ -151,12 +153,14 @@ float_up(isc_heap_t *heap, unsigned int i, void *elt) for (p = heap_parent(i); i > 1 && heap->compare(elt, heap->array[p]); i = p, p = heap_parent(i)) { heap->array[i] = heap->array[p]; - if (heap->index != NULL) + if (heap->index != NULL) { (heap->index)(heap->array[i], i); + } } heap->array[i] = elt; - if (heap->index != NULL) + if (heap->index != NULL) { (heap->index)(heap->array[i], i); + } INSIST(HEAPCONDITION(i)); heap_check(heap); @@ -172,18 +176,22 @@ sink_down(isc_heap_t *heap, unsigned int i, void *elt) /* Find the smallest of the (at most) two children. */ j = heap_left(i); if (j < size && - heap->compare(heap->array[j + 1], heap->array[j])) + heap->compare(heap->array[j + 1], heap->array[j])) { j++; - if (heap->compare(elt, heap->array[j])) + } + if (heap->compare(elt, heap->array[j])) { break; + } heap->array[i] = heap->array[j]; - if (heap->index != NULL) + if (heap->index != NULL) { (heap->index)(heap->array[i], i); + } i = j; } heap->array[i] = elt; - if (heap->index != NULL) + if (heap->index != NULL) { (heap->index)(heap->array[i], i); + } INSIST(HEAPCONDITION(i)); heap_check(heap); @@ -199,8 +207,9 @@ isc_heap_insert(isc_heap_t *heap, void *elt) heap_check(heap); new_last = heap->last + 1; RUNTIME_CHECK(new_last > 0); /* overflow check */ - if (new_last >= heap->size && !resize(heap)) + if (new_last >= heap->size && !resize(heap)) { return (ISC_R_NOMEMORY); + } heap->last = new_last; float_up(heap, new_last, elt); @@ -218,8 +227,9 @@ isc_heap_delete(isc_heap_t *heap, unsigned int idx) REQUIRE(idx >= 1 && idx <= heap->last); heap_check(heap); - if (heap->index != NULL) + if (heap->index != NULL) { (heap->index)(heap->array[idx], 0); + } if (idx == heap->last) { heap->array[heap->last] = NULL; heap->last--; @@ -231,10 +241,11 @@ isc_heap_delete(isc_heap_t *heap, unsigned int idx) less = heap->compare(elt, heap->array[idx]); heap->array[idx] = elt; - if (less) + if (less) { float_up(heap, idx, heap->array[idx]); - else + } else { sink_down(heap, idx, heap->array[idx]); + } } } @@ -263,8 +274,9 @@ isc_heap_element(isc_heap_t *heap, unsigned int idx) REQUIRE(idx >= 1); heap_check(heap); - if (idx <= heap->last) + if (idx <= heap->last) { return (heap->array[idx]); + } return (NULL); } @@ -276,6 +288,7 @@ isc_heap_foreach(isc_heap_t *heap, isc_heapaction_t action, void *uap) REQUIRE(VALID_HEAP(heap)); REQUIRE(action != NULL); - for (i = 1; i <= heap->last; i++) + for (i = 1; i <= heap->last; i++) { (action)(heap->array[i], uap); + } } diff --git a/lib/isc/hex.c b/lib/isc/hex.c index c7519b6f63..b9a49cbff5 100644 --- a/lib/isc/hex.c +++ b/lib/isc/hex.c @@ -24,7 +24,7 @@ do { \ isc_result_t _r = (x); \ if (_r != ISC_R_SUCCESS) \ - return (_r); \ + return ((_r)); \ } while (0) /* @@ -45,8 +45,9 @@ isc_hex_totext(isc_region_t *source, int wordlength, const char *wordbreak, char buf[3]; unsigned int loops = 0; - if (wordlength < 2) + if (wordlength < 2) { wordlength = 2; + } memset(buf, 0, sizeof(buf)); while (source->length > 0) { @@ -88,8 +89,9 @@ hex_decode_char(hex_decode_ctx_t *ctx, int c) { const char *s; - if ((s = strchr(hex, toupper(c))) == NULL) + if ((s = strchr(hex, toupper(c))) == NULL) { return (ISC_R_BADHEX); + } ctx->val[ctx->digits++] = (int)(s - hex); if (ctx->digits == 2) { unsigned char num; @@ -97,10 +99,11 @@ hex_decode_char(hex_decode_ctx_t *ctx, int c) num = (ctx->val[0] << 4) + (ctx->val[1]); RETERR(mem_tobuffer(ctx->target, &num, 1)); if (ctx->length >= 0) { - if (ctx->length == 0) + if (ctx->length == 0) { return (ISC_R_BADHEX); - else + } else { ctx->length -= 1; + } } ctx->digits = 0; } @@ -110,10 +113,12 @@ hex_decode_char(hex_decode_ctx_t *ctx, int c) static inline isc_result_t hex_decode_finish(hex_decode_ctx_t *ctx) { - if (ctx->length > 0) + if (ctx->length > 0) { return (ISC_R_UNEXPECTEDEND); - if (ctx->digits != 0) + } + if (ctx->digits != 0) { return (ISC_R_BADHEX); + } return (ISC_R_SUCCESS); } @@ -168,10 +173,12 @@ isc_hex_decodestring(const char *cstr, isc_buffer_t *target) hex_decode_init(&ctx, -1, target); for (;;) { int c = *cstr++; - if (c == '\0') + if (c == '\0') { break; - if (c == ' ' || c == '\t' || c == '\n' || c == '\r') + } + if (c == ' ' || c == '\t' || c == '\n' || c == '\r') { continue; + } RETERR(hex_decode_char(&ctx, c)); } RETERR(hex_decode_finish(&ctx)); @@ -187,8 +194,9 @@ str_totext(const char *source, isc_buffer_t *target) isc_buffer_availableregion(target, ®ion); l = strlen(source); - if (l > region.length) + if (l > region.length) { return (ISC_R_NOSPACE); + } memmove(region.base, source, l); isc_buffer_add(target, l); @@ -201,8 +209,9 @@ mem_tobuffer(isc_buffer_t *target, void *base, unsigned int length) isc_region_t tr; isc_buffer_availableregion(target, &tr); - if (length > tr.length) + if (length > tr.length) { return (ISC_R_NOSPACE); + } memmove(tr.base, base, length); isc_buffer_add(target, length); return (ISC_R_SUCCESS); diff --git a/lib/isc/ht.c b/lib/isc/ht.c index 38c019a2f2..6ffa8a0625 100644 --- a/lib/isc/ht.c +++ b/lib/isc/ht.c @@ -159,8 +159,9 @@ isc_ht_find(const isc_ht_t *ht, const unsigned char *key, uint32_t keysize, while (node != NULL) { if (keysize == node->keysize && memcmp(key, node->key, keysize) == 0) { - if (valuep != NULL) + if (valuep != NULL) { *valuep = node->value; + } return (ISC_R_SUCCESS); } node = node->next; @@ -184,10 +185,11 @@ isc_ht_delete(isc_ht_t *ht, const unsigned char *key, uint32_t keysize) while (node != NULL) { if (keysize == node->keysize && memcmp(key, node->key, keysize) == 0) { - if (prev == NULL) + if (prev == NULL) { ht->table[hash & ht->mask] = node->next; - else + } else { prev->next = node->next; + } isc_mem_put(ht->mctx, node, offsetof(isc_ht_node_t, key) + node->keysize); @@ -241,11 +243,13 @@ isc_ht_iter_first(isc_ht_iter_t *it) REQUIRE(it != NULL); it->i = 0; - while (it->i < it->ht->size && it->ht->table[it->i] == NULL) + while (it->i < it->ht->size && it->ht->table[it->i] == NULL) { it->i++; + } - if (it->i == it->ht->size) + if (it->i == it->ht->size) { return (ISC_R_NOMORE); + } it->cur = it->ht->table[it->i]; @@ -263,8 +267,9 @@ isc_ht_iter_next(isc_ht_iter_t *it) do { it->i++; } while (it->i < it->ht->size && it->ht->table[it->i] == NULL); - if (it->i >= it->ht->size) + if (it->i >= it->ht->size) { return (ISC_R_NOMORE); + } it->cur = it->ht->table[it->i]; } @@ -290,10 +295,11 @@ isc_ht_iter_delcurrent_next(isc_ht_iter_t *it) do { it->i++; } while (it->i < ht->size && ht->table[it->i] == NULL); - if (it->i >= ht->size) + if (it->i >= ht->size) { result = ISC_R_NOMORE; - else + } else { it->cur = ht->table[it->i]; + } } hash = isc_hash_function(to_delete->key, to_delete->keysize, true); @@ -304,10 +310,11 @@ isc_ht_iter_delcurrent_next(isc_ht_iter_t *it) INSIST(node != NULL); } - if (prev == NULL) + if (prev == NULL) { ht->table[hash & ht->mask] = node->next; - else + } else { prev->next = node->next; + } isc_mem_put(ht->mctx, node, offsetof(isc_ht_node_t, key) + node->keysize); ht->count--; diff --git a/lib/isc/httpd.c b/lib/isc/httpd.c index 5d15b288fb..c502b046ad 100644 --- a/lib/isc/httpd.c +++ b/lib/isc/httpd.c @@ -28,7 +28,7 @@ #ifdef HAVE_ZLIB #include -#endif +#endif /* ifdef HAVE_ZLIB */ /*% * TODO: @@ -348,7 +348,7 @@ isc_httpdmgr_create(isc_mem_t *mctx, isc_socket_t *sock, isc_task_t *task, httpdmgr = isc_mem_get(mctx, sizeof(isc_httpdmgr_t)); *httpdmgr = (isc_httpdmgr_t){ .timermgr = tmgr, /* XXXMLG no attach - function? */ + * function? */ .client_ok = client_ok, .ondestroy = ondestroy, .cb_arg = cb_arg, @@ -493,29 +493,34 @@ have_header(isc_httpd_t *httpd, const char *header, const char *value, * Skip to next line; */ cr = strchr(h, '\r'); - if (cr != NULL && cr[1] == '\n') + if (cr != NULL && cr[1] == '\n') { cr++; + } nl = strchr(h, '\n'); /* last header? */ h = cr; - if (h == NULL || (nl != NULL && nl < h)) + if (h == NULL || (nl != NULL && nl < h)) { h = nl; - if (h == NULL) + } + if (h == NULL) { return (false); + } h++; continue; } - if (value == NULL) + if (value == NULL) { return (true); + } /* * Skip optional leading white space. */ h += hlen; - while (*h == ' ' || *h == '\t') + while (*h == ' ' || *h == '\t') { h++; + } /* * Terminate token search on NULL or EOL. */ @@ -523,19 +528,21 @@ have_header(isc_httpd_t *httpd, const char *header, const char *value, if (strncasecmp(h, value, vlen) == 0) { if (strchr(eov, h[vlen]) != NULL) { return (true); - /* - * Skip to next token. - */ + /* + * Skip to next token. + */ } } /* * Skip to next token. */ h += strcspn(h, eov); - if (h[0] == '\r' && h[1] == '\n') + if (h[0] == '\r' && h[1] == '\n') { h++; - if (h[0] != 0) + } + if (h[0] != 0) { h++; + } } return (false); } @@ -563,8 +570,9 @@ process_request(isc_httpd_t *httpd, int length) s = strstr(httpd->recvbuf, "\n\n"); delim = 1; } - if (s == NULL) + if (s == NULL) { return (ISC_R_NOTFOUND); + } /* * NUL terminate request at the blank line. @@ -594,12 +602,15 @@ process_request(isc_httpd_t *httpd, int length) */ s = p; while (LENGTHOK(s) && BUFLENOK(s) && - (*s != '\n' && *s != '\r' && *s != '\0' && *s != ' ')) + (*s != '\n' && *s != '\r' && *s != '\0' && *s != ' ')) { s++; - if (!LENGTHOK(s)) + } + if (!LENGTHOK(s)) { return (ISC_R_NOTFOUND); - if (!BUFLENOK(s)) + } + if (!BUFLENOK(s)) { return (ISC_R_NOMEMORY); + } *s = 0; /* @@ -607,20 +618,25 @@ process_request(isc_httpd_t *httpd, int length) */ if ((strncmp(p, "http:/", 6) == 0) || (strncmp(p, "https:/", 7) == 0)) { /* Skip first / */ - while (*p != '/' && *p != 0) + while (*p != '/' && *p != 0) { p++; - if (*p == 0) + } + if (*p == 0) { return (ISC_R_RANGE); + } p++; /* Skip second / */ - while (*p != '/' && *p != 0) + while (*p != '/' && *p != 0) { p++; - if (*p == 0) + } + if (*p == 0) { return (ISC_R_RANGE); + } p++; /* Find third / */ - while (*p != '/' && *p != 0) + while (*p != '/' && *p != 0) { p++; + } if (*p == 0) { p--; *p = '/'; @@ -646,54 +662,65 @@ process_request(isc_httpd_t *httpd, int length) * HTTP/1.0 or HTTP/1.1 for now. */ while (LENGTHOK(s) && BUFLENOK(s) && - (*s != '\n' && *s != '\r' && *s != '\0')) + (*s != '\n' && *s != '\r' && *s != '\0')) { s++; - if (!LENGTHOK(s)) + } + if (!LENGTHOK(s)) { return (ISC_R_NOTFOUND); - if (!BUFLENOK(s)) + } + if (!BUFLENOK(s)) { return (ISC_R_NOMEMORY); + } /* * Check that we have the expected eol delimiter. */ - if (strncmp(s, delim == 1 ? "\n" : "\r\n", delim) != 0) + if (strncmp(s, delim == 1 ? "\n" : "\r\n", delim) != 0) { return (ISC_R_RANGE); + } *s = 0; if ((strncmp(p, "HTTP/1.0", 8) != 0) && - (strncmp(p, "HTTP/1.1", 8) != 0)) + (strncmp(p, "HTTP/1.1", 8) != 0)) { return (ISC_R_RANGE); + } httpd->protocol = p; p = s + delim; /* skip past eol */ s = p; httpd->headers = s; - if (have_header(httpd, "Connection:", "close", ", \t\r\n")) + if (have_header(httpd, "Connection:", "close", ", \t\r\n")) { httpd->flags |= HTTPD_CLOSE; + } - if (have_header(httpd, "Host:", NULL, NULL)) + if (have_header(httpd, "Host:", NULL, NULL)) { httpd->flags |= HTTPD_FOUNDHOST; + } if (strncmp(httpd->protocol, "HTTP/1.0", 8) == 0) { - if (have_header(httpd, "Connection:", "Keep-Alive", ", \t\r\n")) + if (have_header(httpd, "Connection:", "Keep-Alive", + ", \t\r\n")) { httpd->flags |= HTTPD_KEEPALIVE; - else + } else { httpd->flags |= HTTPD_CLOSE; + } } /* * Check for Accept-Encoding: */ #ifdef HAVE_ZLIB - if (have_header(httpd, "Accept-Encoding:", "deflate", ";, \t\r\n")) + if (have_header(httpd, "Accept-Encoding:", "deflate", ";, \t\r\n")) { httpd->flags |= HTTPD_ACCEPT_DEFLATE; -#endif + } +#endif /* ifdef HAVE_ZLIB */ /* * Standards compliance hooks here. */ if (strcmp(httpd->protocol, "HTTP/1.1") == 0 && - ((httpd->flags & HTTPD_FOUNDHOST) == 0)) + ((httpd->flags & HTTPD_FOUNDHOST) == 0)) { return (ISC_R_RANGE); + } return (ISC_R_SUCCESS); } @@ -897,7 +924,7 @@ isc_httpd_compress(isc_httpd_t *httpd) inputlen = isc_buffer_usedlength(&httpd->bodybuffer); result = alloc_compspace(httpd, inputlen); if (result != ISC_R_SUCCESS) { - return result; + return (result); } isc_buffer_region(&httpd->compbuffer, &r); @@ -924,7 +951,7 @@ isc_httpd_compress(isc_httpd_t *httpd) return (ISC_R_FAILURE); } } -#endif +#endif /* ifdef HAVE_ZLIB */ static void isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) @@ -973,8 +1000,9 @@ isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) LOCK(&httpd->mgr->lock); url = ISC_LIST_HEAD(httpd->mgr->urls); while (url != NULL) { - if (strcmp(httpd->url, url->url) == 0) + if (strcmp(httpd->url, url->url) == 0) { break; + } url = ISC_LIST_NEXT(url, link); } UNLOCK(&httpd->mgr->lock); @@ -1006,7 +1034,7 @@ isc_httpd_recvdone(isc_task_t *task, isc_event_t *ev) is_compressed = true; } } -#endif +#endif /* ifdef HAVE_ZLIB */ isc_httpd_response(httpd); if ((httpd->flags & HTTPD_KEEPALIVE) != 0) { @@ -1104,8 +1132,9 @@ grow_headerspace(isc_httpd_t *httpd) isc_buffer_region(&httpd->headerbuffer, &r); newlen = r.length + HTTP_SENDGROW; - if (newlen > HTTP_SEND_MAXLEN) + if (newlen > HTTP_SEND_MAXLEN) { return (ISC_R_NOSPACE); + } newspace = isc_mem_get(httpd->mgr->mctx, newlen); @@ -1130,8 +1159,9 @@ isc_httpd_response(isc_httpd_t *httpd) while (isc_buffer_availablelength(&httpd->headerbuffer) < needlen) { result = grow_headerspace(httpd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (isc_buffer_printf(&httpd->headerbuffer, "%s %03u %s\r\n", @@ -1155,8 +1185,9 @@ isc_httpd_addheader(isc_httpd_t *httpd, const char *name, const char *val) while (isc_buffer_availablelength(&httpd->headerbuffer) < needlen) { result = grow_headerspace(httpd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } if (val != NULL) { @@ -1177,8 +1208,9 @@ isc_httpd_endheaders(isc_httpd_t *httpd) while (isc_buffer_availablelength(&httpd->headerbuffer) < 2) { result = grow_headerspace(httpd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (isc_buffer_printf(&httpd->headerbuffer, "\r\n")); @@ -1201,8 +1233,9 @@ isc_httpd_addheaderuint(isc_httpd_t *httpd, const char *name, int val) while (isc_buffer_availablelength(&httpd->headerbuffer) < needlen) { result = grow_headerspace(httpd); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (isc_buffer_printf(&httpd->headerbuffer, "%s: %s\r\n", name, diff --git a/lib/isc/include/isc/app.h b/lib/isc/include/isc/app.h index 4193191977..b66d8910ec 100644 --- a/lib/isc/include/isc/app.h +++ b/lib/isc/include/isc/app.h @@ -13,8 +13,8 @@ #define ISC_APP_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/app.h * \brief ISC Application Support diff --git a/lib/isc/include/isc/atomic.h b/lib/isc/include/isc/atomic.h index 4e20584021..809ee3e425 100644 --- a/lib/isc/include/isc/atomic.h +++ b/lib/isc/include/isc/atomic.h @@ -13,13 +13,13 @@ #ifdef ISC_MUTEX_ATOMICS #include -#else +#else /* ifdef ISC_MUTEX_ATOMICS */ #if HAVE_STDATOMIC_H #include -#else +#else /* if HAVE_STDATOMIC_H */ #include -#endif -#endif +#endif /* if HAVE_STDATOMIC_H */ +#endif /* ifdef ISC_MUTEX_ATOMICS */ /* * We define a few additional macros to make things easier diff --git a/lib/isc/include/isc/buffer.h b/lib/isc/include/isc/buffer.h index fd5c9a9a7e..5fb030e243 100644 --- a/lib/isc/include/isc/buffer.h +++ b/lib/isc/include/isc/buffer.h @@ -13,13 +13,13 @@ #define ISC_BUFFER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/buffer.h * * \brief A buffer is a region of memory, together with a set of related - *subregions. Buffers are used for parsing and I/O operations. + * subregions. Buffers are used for parsing and I/O operations. * * The 'used region' and the 'available' region are disjoint, and their * union is the buffer's region. The used region extends from the beginning @@ -526,7 +526,7 @@ uint16_t isc_buffer_getuint16(isc_buffer_t *b); /*!< * \brief Read an unsigned 16-bit integer in network byte order from 'b', - *convert it to host byte order, and return it. + * convert it to host byte order, and return it. * * Requires: * @@ -564,7 +564,7 @@ uint32_t isc_buffer_getuint32(isc_buffer_t *b); /*!< * \brief Read an unsigned 32-bit integer in network byte order from 'b', - *convert it to host byte order, and return it. + * convert it to host byte order, and return it. * * Requires: * @@ -1010,7 +1010,7 @@ ISC_LANG_ENDDECLS #define isc_buffer_putuint16 ISC__BUFFER_PUTUINT16 #define isc_buffer_putuint24 ISC__BUFFER_PUTUINT24 #define isc_buffer_putuint32 ISC__BUFFER_PUTUINT32 -#else +#else /* if defined(ISC_BUFFER_USEINLINE) */ #define isc_buffer_init isc__buffer_init #define isc_buffer_initnull isc__buffer_initnull #define isc_buffer_invalidate isc__buffer_invalidate @@ -1033,7 +1033,7 @@ ISC_LANG_ENDDECLS #define isc_buffer_putuint16 isc__buffer_putuint16 #define isc_buffer_putuint24 isc__buffer_putuint24 #define isc_buffer_putuint32 isc__buffer_putuint32 -#endif +#endif /* if defined(ISC_BUFFER_USEINLINE) */ #define isc_buffer_constinit(_b, _d, _l) \ do { \ diff --git a/lib/isc/include/isc/bufferlist.h b/lib/isc/include/isc/bufferlist.h index f245cb5deb..13e0a0d16c 100644 --- a/lib/isc/include/isc/bufferlist.h +++ b/lib/isc/include/isc/bufferlist.h @@ -13,18 +13,18 @@ #define ISC_BUFFERLIST_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/bufferlist.h * * *\brief Buffer lists have no synchronization. Clients must ensure - exclusive * access. + * exclusive * access. * * \li Reliability: * No anticipated impact. - + * * \li Security: * No anticipated impact. * @@ -63,7 +63,7 @@ unsigned int isc_bufferlist_availablecount(isc_bufferlist_t *bl); /*!< * \brief Return the length of the sum of all available regions of all buffers - *in the buffer list 'bl' + * in the buffer list 'bl' * * Requires: * diff --git a/lib/isc/include/isc/counter.h b/lib/isc/include/isc/counter.h index 28d9c794c6..852cc54b64 100644 --- a/lib/isc/include/isc/counter.h +++ b/lib/isc/include/isc/counter.h @@ -13,8 +13,8 @@ #define ISC_COUNTER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/counter.h * @@ -34,8 +34,8 @@ #include /***** - ***** Types. - *****/ +***** Types. +*****/ ISC_LANG_BEGINDECLS diff --git a/lib/isc/include/isc/deprecated.h b/lib/isc/include/isc/deprecated.h index 8d825cc0a2..ff7cd3d713 100644 --- a/lib/isc/include/isc/deprecated.h +++ b/lib/isc/include/isc/deprecated.h @@ -14,8 +14,8 @@ #if (__GNUC__ + 0) > 3 #define ISC_DEPRECATED __attribute__((deprecated)) -#else +#else /* if (__GNUC__ + 0) > 3 */ #define ISC_DEPRECATED /* none */ #endif /* __GNUC__ > 3*/ -#endif +#endif /* ifndef ISC_DEPRECATED_H */ diff --git a/lib/isc/include/isc/endian.h b/lib/isc/include/isc/endian.h index fd944ddbb8..d71ac0dae2 100644 --- a/lib/isc/include/isc/endian.h +++ b/lib/isc/include/isc/endian.h @@ -96,7 +96,8 @@ #include #include -#else +#else /* if defined(__DragonFly__) || defined(__FreeBSD__) || \ + * defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) */ #endif /* Specific platform support */ diff --git a/lib/isc/include/isc/event.h b/lib/isc/include/isc/event.h index a30f6d4e3e..b152f169e2 100644 --- a/lib/isc/include/isc/event.h +++ b/lib/isc/include/isc/event.h @@ -18,8 +18,8 @@ #include /***** - ***** Events. - *****/ +***** Events. +*****/ typedef void (*isc_eventdestructor_t)(isc_event_t *); diff --git a/lib/isc/include/isc/file.h b/lib/isc/include/isc/file.h index 6a63fdea3e..4503a968e6 100644 --- a/lib/isc/include/isc/file.h +++ b/lib/isc/include/isc/file.h @@ -66,7 +66,7 @@ isc_result_t isc_file_mktemplate(const char *path, char *buf, size_t buflen); /*!< * \brief Generate a template string suitable for use with - *isc_file_openunique(). + * isc_file_openunique(). * * Notes: *\li This function is intended to make creating temporary files diff --git a/lib/isc/include/isc/formatcheck.h b/lib/isc/include/isc/formatcheck.h index 892c3ccfd3..122529805e 100644 --- a/lib/isc/include/isc/formatcheck.h +++ b/lib/isc/include/isc/formatcheck.h @@ -27,8 +27,8 @@ #ifdef __GNUC__ #define ISC_FORMAT_PRINTF(fmt, args) \ __attribute__((__format__(__printf__, fmt, args))) -#else +#else /* ifdef __GNUC__ */ #define ISC_FORMAT_PRINTF(fmt, args) -#endif +#endif /* ifdef __GNUC__ */ #endif /* ISC_FORMATCHECK_H */ diff --git a/lib/isc/include/isc/ht.h b/lib/isc/include/isc/ht.h index fef955c37b..ef83250b75 100644 --- a/lib/isc/include/isc/ht.h +++ b/lib/isc/include/isc/ht.h @@ -181,4 +181,4 @@ isc_ht_iter_currentkey(isc_ht_iter_t *it, unsigned char **key, size_t *keysize); */ unsigned int isc_ht_count(isc_ht_t *ht); -#endif +#endif /* ifndef ISC_HT_H */ diff --git a/lib/isc/include/isc/interfaceiter.h b/lib/isc/include/isc/interfaceiter.h index 01bb02a935..7c5c307ca0 100644 --- a/lib/isc/include/isc/interfaceiter.h +++ b/lib/isc/include/isc/interfaceiter.h @@ -13,8 +13,8 @@ #define ISC_INTERFACEITER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/interfaceiter.h * \brief Iterates over the list of network interfaces. @@ -47,8 +47,9 @@ struct isc_interface { unsigned int af; /*%< Address family. */ isc_netaddr_t address; /*%< Local address. */ isc_netaddr_t netmask; /*%< Network mask. */ - isc_netaddr_t dstaddress; /*%< Destination address (point-to-point - only). */ + isc_netaddr_t dstaddress; /*%< Destination address + * (point-to-point + * only). */ uint32_t flags; /*%< Flags; see INTERFACE flags. */ }; diff --git a/lib/isc/include/isc/lang.h b/lib/isc/include/isc/lang.h index f3b56278f4..1e44bb7150 100644 --- a/lib/isc/include/isc/lang.h +++ b/lib/isc/include/isc/lang.h @@ -17,9 +17,9 @@ #ifdef __cplusplus #define ISC_LANG_BEGINDECLS extern "C" { #define ISC_LANG_ENDDECLS } -#else +#else /* ifdef __cplusplus */ #define ISC_LANG_BEGINDECLS #define ISC_LANG_ENDDECLS -#endif +#endif /* ifdef __cplusplus */ #endif /* ISC_LANG_H */ diff --git a/lib/isc/include/isc/lex.h b/lib/isc/include/isc/lex.h index 6eff2acc4f..0b863525b9 100644 --- a/lib/isc/include/isc/lex.h +++ b/lib/isc/include/isc/lex.h @@ -13,8 +13,8 @@ #define ISC_LEX_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/lex.h * \brief The "lex" module provides a lightweight tokenizer. It can operate diff --git a/lib/isc/include/isc/likely.h b/lib/isc/include/isc/likely.h index 74837fde86..772790113f 100644 --- a/lib/isc/include/isc/likely.h +++ b/lib/isc/include/isc/likely.h @@ -18,14 +18,14 @@ #ifdef CPPCHECK #define ISC_LIKELY(x) (x) #define ISC_UNLIKELY(x) (x) -#else +#else /* ifdef CPPCHECK */ #ifdef HAVE_BUILTIN_EXPECT #define ISC_LIKELY(x) __builtin_expect(!!(x), 1) #define ISC_UNLIKELY(x) __builtin_expect(!!(x), 0) -#else +#else /* ifdef HAVE_BUILTIN_EXPECT */ #define ISC_LIKELY(x) (x) #define ISC_UNLIKELY(x) (x) -#endif -#endif +#endif /* ifdef HAVE_BUILTIN_EXPECT */ +#endif /* ifdef CPPCHECK */ #endif /* ISC_LIKELY_H */ diff --git a/lib/isc/include/isc/list.h b/lib/isc/include/isc/list.h index 9223211736..d24bf9ccde 100644 --- a/lib/isc/include/isc/list.h +++ b/lib/isc/include/isc/list.h @@ -16,9 +16,9 @@ #ifdef ISC_LIST_CHECKINIT #define ISC_LINK_INSIST(x) ISC_INSIST(x) -#else +#else /* ifdef ISC_LIST_CHECKINIT */ #define ISC_LINK_INSIST(x) -#endif +#endif /* ifdef ISC_LIST_CHECKINIT */ #define ISC_LIST(type) \ struct { \ diff --git a/lib/isc/include/isc/log.h b/lib/isc/include/isc/log.h index 6220dd5fa6..542d017db6 100644 --- a/lib/isc/include/isc/log.h +++ b/lib/isc/include/isc/log.h @@ -125,9 +125,11 @@ struct isc_logmodule { * Setting maximum_size to zero implies no maximum. */ typedef struct isc_logfile { - FILE * stream; /*%< Initialized to NULL for #ISC_LOG_TOFILE. */ - const char *name; /*%< NULL for #ISC_LOG_TOFILEDESC. */ - int versions; /* >= 0, #ISC_LOG_ROLLNEVER, #ISC_LOG_ROLLINFINITE. */ + FILE *stream; /*%< Initialized to NULL for + * #ISC_LOG_TOFILE. */ + const char *name; /*%< NULL for #ISC_LOG_TOFILEDESC. */ + int versions; /* >= 0, #ISC_LOG_ROLLNEVER, + * #ISC_LOG_ROLLINFINITE. */ isc_log_rollsuffix_t suffix; /*% * stdio's ftell is standardized to return a long, which may well not diff --git a/lib/isc/include/isc/mem.h b/lib/isc/include/isc/mem.h index b1bb0bb6e3..dcb41b8493 100644 --- a/lib/isc/include/isc/mem.h +++ b/lib/isc/include/isc/mem.h @@ -34,7 +34,7 @@ typedef void (*isc_mem_water_t)(void *, int); */ #ifndef ISC_MEM_TRACKLINES #define ISC_MEM_TRACKLINES 1 -#endif +#endif /* ifndef ISC_MEM_TRACKLINES */ /*% * Define ISC_MEM_CHECKOVERRUN=1 to turn on checks for using memory outside @@ -46,10 +46,10 @@ typedef void (*isc_mem_water_t)(void *, int); #ifdef __COVERITY__ #undef ISC_MEM_CHECKOVERRUN #define ISC_MEM_CHECKOVERRUN 0 -#endif +#endif /* ifdef __COVERITY__ */ #ifndef ISC_MEM_CHECKOVERRUN #define ISC_MEM_CHECKOVERRUN 1 -#endif +#endif /* ifndef ISC_MEM_CHECKOVERRUN */ /*% * Define ISC_MEMPOOL_NAMES=1 to make memory pools store a symbolic @@ -58,7 +58,7 @@ typedef void (*isc_mem_water_t)(void *, int); */ #ifndef ISC_MEMPOOL_NAMES #define ISC_MEMPOOL_NAMES 1 -#endif +#endif /* ifndef ISC_MEMPOOL_NAMES */ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_debugging; LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; @@ -101,10 +101,10 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; #if ISC_MEM_TRACKLINES #define _ISC_MEM_FILELINE , __FILE__, __LINE__ #define _ISC_MEM_FLARG , const char *, unsigned int -#else +#else /* if ISC_MEM_TRACKLINES */ #define _ISC_MEM_FILELINE #define _ISC_MEM_FLARG -#endif +#endif /* if ISC_MEM_TRACKLINES */ /*! * Define ISC_MEM_USE_INTERNAL_MALLOC=1 to use the internal malloc() @@ -117,7 +117,7 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; #ifndef ISC_MEM_USE_INTERNAL_MALLOC #define ISC_MEM_USE_INTERNAL_MALLOC 1 -#endif +#endif /* ifndef ISC_MEM_USE_INTERNAL_MALLOC */ /* * Flags for isc_mem_create() calls. @@ -129,9 +129,9 @@ LIBISC_EXTERNAL_DATA extern unsigned int isc_mem_defaultflags; #if !ISC_MEM_USE_INTERNAL_MALLOC #define ISC_MEMFLAG_DEFAULT 0 -#else +#else /* if !ISC_MEM_USE_INTERNAL_MALLOC */ #define ISC_MEMFLAG_DEFAULT ISC_MEMFLAG_INTERNAL | ISC_MEMFLAG_FILL -#endif +#endif /* if !ISC_MEM_USE_INTERNAL_MALLOC */ /*% * isc_mem_putanddetach() is a convenience function for use where you diff --git a/lib/isc/include/isc/mutexatomic.h b/lib/isc/include/isc/mutexatomic.h index f6e700f8c9..bac34cab00 100644 --- a/lib/isc/include/isc/mutexatomic.h +++ b/lib/isc/include/isc/mutexatomic.h @@ -18,20 +18,20 @@ #if !defined(__has_feature) #define __has_feature(x) 0 -#endif +#endif /* if !defined(__has_feature) */ #if !defined(__has_extension) #define __has_extension(x) __has_feature(x) -#endif +#endif /* if !defined(__has_extension) */ #if !defined(__GNUC_PREREQ__) #if defined(__GNUC__) && defined(__GNUC_MINOR__) #define __GNUC_PREREQ__(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#else +#else /* if defined(__GNUC__) && defined(__GNUC_MINOR__) */ #define __GNUC_PREREQ__(maj, min) 0 -#endif -#endif +#endif /* if defined(__GNUC__) && defined(__GNUC_MINOR__) */ +#endif /* if !defined(__GNUC_PREREQ__) */ #if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS) #if __has_extension(c_atomic) || __has_extension(cxx_atomic) @@ -40,27 +40,27 @@ #define __GNUC_ATOMICS #elif !defined(__GNUC__) #error "isc/stdatomic.h does not support your compiler" -#endif -#endif +#endif /* if __has_extension(c_atomic) || __has_extension(cxx_atomic) */ +#endif /* if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS) */ #ifndef __ATOMIC_RELAXED #define __ATOMIC_RELAXED 0 -#endif +#endif /* ifndef __ATOMIC_RELAXED */ #ifndef __ATOMIC_CONSUME #define __ATOMIC_CONSUME 1 -#endif +#endif /* ifndef __ATOMIC_CONSUME */ #ifndef __ATOMIC_ACQUIRE #define __ATOMIC_ACQUIRE 2 -#endif +#endif /* ifndef __ATOMIC_ACQUIRE */ #ifndef __ATOMIC_RELEASE #define __ATOMIC_RELEASE 3 -#endif +#endif /* ifndef __ATOMIC_RELEASE */ #ifndef __ATOMIC_ACQ_REL #define __ATOMIC_ACQ_REL 4 -#endif +#endif /* ifndef __ATOMIC_ACQ_REL */ #ifndef __ATOMIC_SEQ_CST #define __ATOMIC_SEQ_CST 5 -#endif +#endif /* ifndef __ATOMIC_SEQ_CST */ enum memory_order { memory_order_relaxed = __ATOMIC_RELAXED, diff --git a/lib/isc/include/isc/netaddr.h b/lib/isc/include/isc/netaddr.h index 37622f4c1f..39129f8b54 100644 --- a/lib/isc/include/isc/netaddr.h +++ b/lib/isc/include/isc/netaddr.h @@ -24,7 +24,7 @@ #ifdef ISC_PLATFORM_HAVESYSUNH #include #include -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ ISC_LANG_BEGINDECLS @@ -35,7 +35,7 @@ struct isc_netaddr { struct in6_addr in6; #ifdef ISC_PLATFORM_HAVESYSUNH char un[sizeof(((struct sockaddr_un *)0)->sun_path)]; -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } type; uint32_t zone; }; diff --git a/lib/isc/include/isc/pool.h b/lib/isc/include/isc/pool.h index 4c2e3b56f5..52ff36566e 100644 --- a/lib/isc/include/isc/pool.h +++ b/lib/isc/include/isc/pool.h @@ -13,8 +13,8 @@ #define ISC_OBJPOOL_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/pool.h * \brief An object pool is a mechanism for sharing a small pool of @@ -37,8 +37,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Types. - *****/ +***** Types. +*****/ typedef void (*isc_pooldeallocator_t)(void **object); @@ -47,8 +47,8 @@ typedef isc_result_t (*isc_poolinitializer_t)(void **target, void *arg); typedef struct isc_pool isc_pool_t; /***** - ***** Functions. - *****/ +***** Functions. +*****/ isc_result_t isc_pool_create(isc_mem_t *mctx, unsigned int count, isc_pooldeallocator_t free, diff --git a/lib/isc/include/isc/quota.h b/lib/isc/include/isc/quota.h index 39a7d9779e..8ca1fdf6da 100644 --- a/lib/isc/include/isc/quota.h +++ b/lib/isc/include/isc/quota.h @@ -13,8 +13,8 @@ #define ISC_QUOTA_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/quota.h * @@ -35,8 +35,8 @@ #include /***** - ***** Types. - *****/ +***** Types. +*****/ ISC_LANG_BEGINDECLS diff --git a/lib/isc/include/isc/radix.h b/lib/isc/include/isc/radix.h index 1a2fcc909f..62f85f334b 100644 --- a/lib/isc/include/isc/radix.h +++ b/lib/isc/include/isc/radix.h @@ -42,8 +42,9 @@ } while (0) typedef struct isc_prefix { - isc_mem_t * mctx; - unsigned int family; /* AF_INET | AF_INET6, or AF_UNSPEC for "any" */ + isc_mem_t * mctx; + unsigned int family; /* AF_INET | AF_INET6, or AF_UNSPEC for + * "any" */ unsigned int bitlen; /* 0 for "any" */ isc_refcount_t refcount; union { @@ -85,13 +86,17 @@ typedef void (*isc_radix_processfunc_t)(isc_prefix_t *, void **); typedef struct isc_radix_node { isc_mem_t * mctx; - uint32_t bit; /* bit length of the prefix */ - isc_prefix_t * prefix; /* who we are in radix tree */ - struct isc_radix_node *l, *r; /* left and right children */ - struct isc_radix_node *parent; /* may be used */ - void *data[RADIX_FAMILIES]; /* pointers to IPv4 and IPV6 data */ - int node_num[RADIX_FAMILIES]; /* which node this was in the tree, - or -1 for glue nodes */ + uint32_t bit; /* bit length of the prefix */ + isc_prefix_t * prefix; /* who we are in radix tree */ + struct isc_radix_node *l, *r; /* left and right children */ + struct isc_radix_node *parent; /* may be used */ + void * data[RADIX_FAMILIES]; /* pointers to IPv4 + * and IPV6 data */ + int node_num[RADIX_FAMILIES]; /* which node + * this was in + * the tree, + * or -1 for glue + * nodes */ } isc_radix_node_t; #define RADIX_TREE_MAGIC ISC_MAGIC('R', 'd', 'x', 'T'); diff --git a/lib/isc/include/isc/ratelimiter.h b/lib/isc/include/isc/ratelimiter.h index 42733caa66..b92725b2da 100644 --- a/lib/isc/include/isc/ratelimiter.h +++ b/lib/isc/include/isc/ratelimiter.h @@ -13,8 +13,8 @@ #define ISC_RATELIMITER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/ratelimiter.h * \brief A rate limiter is a mechanism for dispatching events at a limited @@ -35,8 +35,8 @@ ISC_LANG_BEGINDECLS /***** - ***** Functions. - *****/ +***** Functions. +*****/ isc_result_t isc_ratelimiter_create(isc_mem_t *mctx, isc_timermgr_t *timermgr, diff --git a/lib/isc/include/isc/sockaddr.h b/lib/isc/include/isc/sockaddr.h index ac48420350..846c86cb26 100644 --- a/lib/isc/include/isc/sockaddr.h +++ b/lib/isc/include/isc/sockaddr.h @@ -21,7 +21,7 @@ #include #ifdef ISC_PLATFORM_HAVESYSUNH #include -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ struct isc_sockaddr { union { @@ -31,7 +31,7 @@ struct isc_sockaddr { struct sockaddr_storage ss; #ifdef ISC_PLATFORM_HAVESYSUNH struct sockaddr_un sunix; -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } type; unsigned int length; /* XXXRTH beginning? */ ISC_LINK(struct isc_sockaddr) link; diff --git a/lib/isc/include/isc/socket.h b/lib/isc/include/isc/socket.h index 164338b3ed..06eee560d7 100644 --- a/lib/isc/include/isc/socket.h +++ b/lib/isc/include/isc/socket.h @@ -13,8 +13,8 @@ #define ISC_SOCKET_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/socket.h * \brief Provides TCP and UDP sockets for network I/O. The sockets are event @@ -125,7 +125,7 @@ struct isc_socketevent { isc_time_t timestamp; /*%< timestamp of packet recv */ struct in6_pktinfo pktinfo; /*%< ipv6 pktinfo */ isc_sockeventattr_t attributes; /*%< see isc_sockeventattr_t - enum */ + * enum */ isc_eventdestructor_t destroy; /*%< original destructor */ unsigned int dscp; /*%< UDP dscp value */ }; @@ -209,7 +209,7 @@ struct isc_socketmgr { unsigned int impmagic; unsigned int magic; }; -#endif +#endif /* ifndef WIN32 */ #define ISCAPI_SOCKETMGR_MAGIC ISC_MAGIC('A', 's', 'm', 'g') #define ISCAPI_SOCKETMGR_VALID(m) \ @@ -224,7 +224,7 @@ struct isc_socket { unsigned int impmagic; unsigned int magic; }; -#endif +#endif /* ifndef WIN32 */ #define ISCAPI_SOCKET_MAGIC ISC_MAGIC('A', 's', 'c', 't') #define ISCAPI_SOCKET_VALID(s) \ diff --git a/lib/isc/include/isc/strerr.h b/lib/isc/include/isc/strerr.h index f8bad238cc..0b3e51f7ac 100644 --- a/lib/isc/include/isc/strerr.h +++ b/lib/isc/include/isc/strerr.h @@ -17,5 +17,5 @@ #if defined(strerror_r) #undef strerror_r -#endif +#endif /* if defined(strerror_r) */ #define strerror_r isc_string_strerror_r diff --git a/lib/isc/include/isc/string.h b/lib/isc/include/isc/string.h index 3599a796e2..0efbcdf9b3 100644 --- a/lib/isc/include/isc/string.h +++ b/lib/isc/include/isc/string.h @@ -28,7 +28,7 @@ strlcpy(char *dst, const char *src, size_t size); #if !defined(HAVE_STRLCAT) size_t strlcat(char *dst, const char *src, size_t size); -#endif +#endif /* if !defined(HAVE_STRLCAT) */ int isc_string_strerror_r(int errnum, char *buf, size_t buflen); diff --git a/lib/isc/include/isc/symtab.h b/lib/isc/include/isc/symtab.h index b581da1bbf..b0ae48f958 100644 --- a/lib/isc/include/isc/symtab.h +++ b/lib/isc/include/isc/symtab.h @@ -13,8 +13,8 @@ #define ISC_SYMTAB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/symtab.h * \brief Provides a simple memory-based symbol table. diff --git a/lib/isc/include/isc/task.h b/lib/isc/include/isc/task.h index e319f95ada..0e9e5c2d94 100644 --- a/lib/isc/include/isc/task.h +++ b/lib/isc/include/isc/task.h @@ -13,13 +13,13 @@ #define ISC_TASK_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/task.h * \brief The task system provides a lightweight execution context, which is * basically an event queue. - + * * When a task's event queue is non-empty, the * task is runnable. A small work crew of threads, typically one per CPU, * execute runnable tasks by dispatching the events on the tasks' event @@ -85,8 +85,8 @@ #define ISC_TASKEVENT_LASTEVENT (ISC_EVENTCLASS_TASK + 65535) /***** - ***** Tasks. - *****/ +***** Tasks. +*****/ ISC_LANG_BEGINDECLS @@ -424,7 +424,7 @@ isc_task_onshutdown(isc_task_t *task, isc_taskaction_t action, void *arg); *\li When the task is shutdown, shutdown events requested with * isc_task_onshutdown() will be appended to the task's event queue. * - + * * Returns: * *\li #ISC_R_SUCCESS @@ -637,8 +637,8 @@ isc_task_privilege(isc_task_t *task); */ /***** - ***** Task Manager. - *****/ +***** Task Manager. +*****/ isc_result_t isc_taskmgr_createinctx(isc_mem_t *mctx, unsigned int workers, @@ -770,14 +770,14 @@ isc_taskmgr_excltask(isc_taskmgr_t *mgr, isc_task_t **taskp); * * Requires: *\li 'manager' is a valid task manager. - + * *\li taskp != NULL && *taskp == NULL */ #ifdef HAVE_LIBXML2 int isc_taskmgr_renderxml(isc_taskmgr_t *mgr, void *writer0); -#endif +#endif /* ifdef HAVE_LIBXML2 */ #ifdef HAVE_JSON_C isc_result_t diff --git a/lib/isc/include/isc/taskpool.h b/lib/isc/include/isc/taskpool.h index 213e885573..885b5c4c2e 100644 --- a/lib/isc/include/isc/taskpool.h +++ b/lib/isc/include/isc/taskpool.h @@ -13,8 +13,8 @@ #define ISC_TASKPOOL_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/taskpool.h * \brief A task pool is a mechanism for sharing a small number of tasks @@ -40,14 +40,14 @@ ISC_LANG_BEGINDECLS /***** - ***** Types. - *****/ +***** Types. +*****/ typedef struct isc_taskpool isc_taskpool_t; /***** - ***** Functions. - *****/ +***** Functions. +*****/ isc_result_t isc_taskpool_create(isc_taskmgr_t *tmgr, isc_mem_t *mctx, unsigned int ntasks, diff --git a/lib/isc/include/isc/timer.h b/lib/isc/include/isc/timer.h index 87fd46f6df..d1962d2041 100644 --- a/lib/isc/include/isc/timer.h +++ b/lib/isc/include/isc/timer.h @@ -13,8 +13,8 @@ #define ISC_TIMER_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isc/timer.h * \brief Provides timers which are event sources in the task system. diff --git a/lib/isc/include/isc/types.h b/lib/isc/include/isc/types.h index cf98ca91a3..9d2ad6c718 100644 --- a/lib/isc/include/isc/types.h +++ b/lib/isc/include/isc/types.h @@ -34,7 +34,7 @@ typedef struct isc_astack isc_astack_t; /*%< Array-based fast stack */ typedef struct isc_appctx isc_appctx_t; /*%< Application context */ typedef struct isc_backtrace_symmap isc_backtrace_symmap_t; /*%< Symbol Table - Entry */ + * Entry */ typedef struct isc_buffer isc_buffer_t; /*%< Buffer */ typedef ISC_LIST(isc_buffer_t) isc_bufferlist_t; /*%< Buffer List */ typedef struct isc_constregion isc_constregion_t; /*%< Const region */ @@ -48,7 +48,7 @@ typedef unsigned int isc_eventtype_t; /*%< Event Type */ typedef uint32_t isc_fsaccess_t; /*%< FS Access */ typedef struct isc_hash isc_hash_t; /*%< Hash */ typedef struct isc_hp isc_hp_t; /*%< Hazard - pointer */ + * pointer */ typedef struct isc_httpd isc_httpd_t; /*%< HTTP client */ typedef void(isc_httpdfree_t)(isc_buffer_t *, void *); /*%< HTTP free function */ @@ -78,16 +78,17 @@ typedef uint64_t isc_resourcevalue_t; /*%< Resource Value */ typedef unsigned int isc_result_t; /*%< Result */ typedef struct isc_rwlock isc_rwlock_t; /*%< Read Write Lock */ typedef struct isc_sockaddr isc_sockaddr_t; /*%< Socket Address */ -typedef ISC_LIST(isc_sockaddr_t) isc_sockaddrlist_t; /*%< Socket Address List */ +typedef ISC_LIST(isc_sockaddr_t) isc_sockaddrlist_t; /*%< Socket Address List + * */ typedef struct isc_socket isc_socket_t; /*%< Socket */ typedef struct isc_socketevent isc_socketevent_t; /*%< Socket Event */ typedef struct isc_socketmgr isc_socketmgr_t; /*%< Socket Manager */ typedef struct isc_stats isc_stats_t; /*%< Statistics */ #if defined(_WIN32) && !defined(_WIN64) typedef int_fast32_t isc_statscounter_t; /*%< Statistics Counter */ -#else +#else /* if defined(_WIN32) && !defined(_WIN64) */ typedef int_fast64_t isc_statscounter_t; -#endif +#endif /* if defined(_WIN32) && !defined(_WIN64) */ typedef struct isc_symtab isc_symtab_t; /*%< Symbol Table */ typedef struct isc_task isc_task_t; /*%< Task */ typedef ISC_LIST(isc_task_t) isc_tasklist_t; /*%< Task List */ diff --git a/lib/isc/include/isc/util.h b/lib/isc/include/isc/util.h index 90874c629c..a23b8e2158 100644 --- a/lib/isc/include/isc/util.h +++ b/lib/isc/include/isc/util.h @@ -44,7 +44,7 @@ #if __GNUC__ >= 8 && !defined(__clang__) #define ISC_NONSTRING __attribute__((nonstring)) -#else +#else /* if __GNUC__ >= 8 && !defined(__clang__) */ #define ISC_NONSTRING #endif /* __GNUC__ */ @@ -92,9 +92,9 @@ #ifdef ISC_UTIL_TRACEON #define ISC_UTIL_TRACE(a) a #include /* Required for fprintf/stderr when tracing. */ -#else +#else /* ifdef ISC_UTIL_TRACEON */ #define ISC_UTIL_TRACE(a) -#endif +#endif /* ifdef ISC_UTIL_TRACEON */ #include /* Contractual promise. */ @@ -190,36 +190,36 @@ #ifdef HAVE_BUILTIN_UNREACHABLE #define ISC_UNREACHABLE() __builtin_unreachable(); -#else +#else /* ifdef HAVE_BUILTIN_UNREACHABLE */ #define ISC_UNREACHABLE() -#endif +#endif /* ifdef HAVE_BUILTIN_UNREACHABLE */ #if !defined(__has_feature) #define __has_feature(x) 0 -#endif +#endif /* if !defined(__has_feature) */ /* GCC defines __SANITIZE_ADDRESS__, so reuse the macro for clang */ #if __has_feature(address_sanitizer) #define __SANITIZE_ADDRESS__ 1 -#endif +#endif /* if __has_feature(address_sanitizer) */ #if __has_feature(thread_sanitizer) #define __SANITIZE_THREAD__ 1 -#endif +#endif /* if __has_feature(thread_sanitizer) */ #if __SANITIZE_THREAD__ #define ISC_NO_SANITIZE __attribute__((no_sanitize("thread"))) -#else +#else /* if __SANITIZE_THREAD__ */ #define ISC_NO_SANITIZE -#endif +#endif /* if __SANITIZE_THREAD__ */ #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) #elif __has_feature(c_static_assert) #define STATIC_ASSERT(cond, msg) _Static_assert(cond, msg) -#else +#else /* if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) */ #define STATIC_ASSERT(cond, msg) INSIST(cond) -#endif +#endif /* if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR >= 6) */ #ifdef UNIT_TESTING extern void @@ -316,11 +316,11 @@ mock_assert(const int result, const char *const expression, #ifndef CPPCHECK /*% Runtime Check */ #define RUNTIME_CHECK(cond) ISC_ERROR_RUNTIMECHECK(cond) -#else +#else /* ifndef CPPCHECK */ #define RUNTIME_CHECK(e) \ if (!(e)) \ abort() -#endif +#endif /* ifndef CPPCHECK */ #endif /* UNIT_TESTING */ @@ -334,9 +334,9 @@ mock_assert(const int result, const char *const expression, */ #ifdef __GNUC__ #define ISC_ALIGN(x, a) (((x) + (a)-1) & ~((typeof(x))(a)-1)) -#else +#else /* ifdef __GNUC__ */ #define ISC_ALIGN(x, a) (((x) + (a)-1) & ~((uintmax_t)(a)-1)) -#endif +#endif /* ifdef __GNUC__ */ /*% * Misc diff --git a/lib/isc/include/pk11/constants.h b/lib/isc/include/pk11/constants.h index 3dcd6e8fb9..b1eef95917 100644 --- a/lib/isc/include/pk11/constants.h +++ b/lib/isc/include/pk11/constants.h @@ -74,6 +74,6 @@ static CK_BYTE pk11_dh_bn1536[] = { 0x67, 0x0c, 0x35, 0x4e, 0x4a, 0xbc, 0x98, 0x04, 0xf1, 0x74, 0x6c, 0x08, 0xca, 0x23, 0x73, 0x27, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; -#endif +#endif /* ifdef WANT_DH_PRIMES */ #endif /* PK11_CONSTANTS_H */ diff --git a/lib/isc/include/pkcs11/eddsa.h b/lib/isc/include/pkcs11/eddsa.h index 9af4b5d4c7..611060739b 100644 --- a/lib/isc/include/pkcs11/eddsa.h +++ b/lib/isc/include/pkcs11/eddsa.h @@ -15,19 +15,19 @@ #ifndef CKK_EDDSA #ifdef PK11_SOFTHSMV2_FLAVOR #define CKK_EDDSA 0x00008003UL -#endif -#endif +#endif /* ifdef PK11_SOFTHSMV2_FLAVOR */ +#endif /* ifndef CKK_EDDSA */ #ifndef CKM_EDDSA_KEY_PAIR_GEN #ifdef PK11_SOFTHSMV2_FLAVOR #define CKM_EDDSA_KEY_PAIR_GEN 0x00009040UL -#endif -#endif +#endif /* ifdef PK11_SOFTHSMV2_FLAVOR */ +#endif /* ifndef CKM_EDDSA_KEY_PAIR_GEN */ #ifndef CKM_EDDSA #ifdef PK11_SOFTHSMV2_FLAVOR #define CKM_EDDSA 0x00009041UL -#endif -#endif +#endif /* ifdef PK11_SOFTHSMV2_FLAVOR */ +#endif /* ifndef CKM_EDDSA */ #endif /* _EDDSA_H_ */ diff --git a/lib/isc/include/pkcs11/pkcs11.h b/lib/isc/include/pkcs11/pkcs11.h index c24699f0a0..4f3bff7c98 100644 --- a/lib/isc/include/pkcs11/pkcs11.h +++ b/lib/isc/include/pkcs11/pkcs11.h @@ -1,76 +1,76 @@ /* pkcs11.h - Copyright 2006, 2007 g10 Code GmbH - Copyright 2006 Andreas Jellinghaus - Copyright 2017 Red Hat, Inc. - - This file is free software; as a special exception the author gives - unlimited permission to copy and/or distribute it, with or without - modifications, as long as this notice is preserved. - - This file is distributed in the hope that it will be useful, but - WITHOUT ANY WARRANTY, to the extent permitted by law; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. */ + * Copyright 2006, 2007 g10 Code GmbH + * Copyright 2006 Andreas Jellinghaus + * Copyright 2017 Red Hat, Inc. + * + * This file is free software; as a special exception the author gives + * unlimited permission to copy and/or distribute it, with or without + * modifications, as long as this notice is preserved. + * + * This file is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY, to the extent permitted by law; without even + * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + * PURPOSE. */ /* Please submit any changes back to the p11-kit project at - https://github.com/p11-glue/p11-kit/, so that - they can be picked up by other projects from there as well. */ + * https://github.com/p11-glue/p11-kit/, so that + * they can be picked up by other projects from there as well. */ /* This file is a modified implementation of the PKCS #11 standard by - OASIS group. It is mostly a drop-in replacement, with the - following change: - - This header file does not require any macro definitions by the user - (like CK_DEFINE_FUNCTION etc). In fact, it defines those macros - for you (if useful, some are missing, let me know if you need - more). - - There is an additional API available that does comply better to the - GNU coding standard. It can be switched on by defining - CRYPTOKI_GNU before including this header file. For this, the - following changes are made to the specification: - - All structure types are changed to a "struct ck_foo" where CK_FOO - is the type name in PKCS #11. - - All non-structure types are changed to ck_foo_t where CK_FOO is the - lowercase version of the type name in PKCS #11. The basic types - (CK_ULONG et al.) are removed without substitute. - - All members of structures are modified in the following way: Type - indication prefixes are removed, and underscore characters are - inserted before words. Then the result is lowercased. - - Note that function names are still in the original case, as they - need for ABI compatibility. - - CK_FALSE, CK_TRUE and NULL_PTR are removed without substitute. Use - . - - If CRYPTOKI_COMPAT is defined before including this header file, - then none of the API changes above take place, and the API is the - one defined by the PKCS #11 standard. */ + * OASIS group. It is mostly a drop-in replacement, with the + * following change: + * + * This header file does not require any macro definitions by the user + * (like CK_DEFINE_FUNCTION etc). In fact, it defines those macros + * for you (if useful, some are missing, let me know if you need + * more). + * + * There is an additional API available that does comply better to the + * GNU coding standard. It can be switched on by defining + * CRYPTOKI_GNU before including this header file. For this, the + * following changes are made to the specification: + * + * All structure types are changed to a "struct ck_foo" where CK_FOO + * is the type name in PKCS #11. + * + * All non-structure types are changed to ck_foo_t where CK_FOO is the + * lowercase version of the type name in PKCS #11. The basic types + * (CK_ULONG et al.) are removed without substitute. + * + * All members of structures are modified in the following way: Type + * indication prefixes are removed, and underscore characters are + * inserted before words. Then the result is lowercased. + * + * Note that function names are still in the original case, as they + * need for ABI compatibility. + * + * CK_FALSE, CK_TRUE and NULL_PTR are removed without substitute. Use + * . + * + * If CRYPTOKI_COMPAT is defined before including this header file, + * then none of the API changes above take place, and the API is the + * one defined by the PKCS #11 standard. */ #ifndef PKCS11_H #define PKCS11_H 1 #if defined(__cplusplus) extern "C" { -#endif +#endif /* if defined(__cplusplus) */ /* The version of cryptoki we implement. The revision is changed with - each modification of this file. */ + * each modification of this file. */ #define CRYPTOKI_VERSION_MAJOR 2 #define CRYPTOKI_VERSION_MINOR 40 #define P11_KIT_CRYPTOKI_VERSION_REVISION 0 /* Compatibility interface is default, unless CRYPTOKI_GNU is - given. */ + * given. */ #ifndef CRYPTOKI_GNU #ifndef CRYPTOKI_COMPAT #define CRYPTOKI_COMPAT 1 -#endif -#endif +#endif /* ifndef CRYPTOKI_COMPAT */ +#endif /* ifndef CRYPTOKI_GNU */ /* System dependencies. */ @@ -81,19 +81,19 @@ extern "C" { #ifdef CRYPTOKI_EXPORTS #define CK_SPEC __declspec(dllexport) -#else +#else /* ifdef CRYPTOKI_EXPORTS */ #define CK_SPEC __declspec(dllimport) -#endif +#endif /* ifdef CRYPTOKI_EXPORTS */ -#else +#else /* if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32) */ #define CK_SPEC -#endif +#endif /* if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32) */ #ifdef CRYPTOKI_COMPAT /* If we are in compatibility mode, switch all exposed names to the - PKCS #11 variant. There are corresponding #undefs below. */ + * PKCS #11 variant. There are corresponding #undefs below. */ #define ck_flags_t CK_FLAGS #define ck_version _CK_VERSION @@ -1467,11 +1467,11 @@ typedef void ** CK_VOID_PTR_PTR; #ifndef CK_DISABLE_TRUE_FALSE #ifndef FALSE #define FALSE 0 -#endif +#endif /* ifndef FALSE */ #ifndef TRUE #define TRUE 1 -#endif -#endif +#endif /* ifndef TRUE */ +#endif /* ifndef CK_DISABLE_TRUE_FALSE */ typedef struct ck_version CK_VERSION; typedef struct ck_version *CK_VERSION_PTR; @@ -1548,7 +1548,7 @@ typedef struct ck_aes_cbc_encrypt_data_params #ifndef NULL_PTR #define NULL_PTR NULL -#endif +#endif /* ifndef NULL_PTR */ /* Delete the helper macros defined at the top of the file. */ #undef ck_flags_t @@ -1644,10 +1644,10 @@ typedef struct ck_aes_cbc_encrypt_data_params /* System dependencies. */ #if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32) #pragma pack(pop, cryptoki) -#endif +#endif /* if defined(_WIN32) || defined(CRYPTOKI_FORCE_WIN32) */ #if defined(__cplusplus) } -#endif +#endif /* if defined(__cplusplus) */ #endif /* PKCS11_H */ diff --git a/lib/isc/lex.c b/lib/isc/lex.c index bae03023fa..f49762ef2a 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -69,8 +69,9 @@ grow_data(isc_lex_t *lex, size_t *remainingp, char **currp, char **prevp) tmp = isc_mem_get(lex->mctx, lex->max_token * 2 + 1); memmove(tmp, lex->data, lex->max_token + 1); *currp = tmp + (*currp - lex->data); - if (*prevp != NULL) + if (*prevp != NULL) { *prevp = tmp + (*prevp - lex->data); + } isc_mem_put(lex->mctx, lex->data, lex->max_token + 1); lex->data = tmp; *remainingp += lex->max_token; @@ -88,8 +89,9 @@ isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp) */ REQUIRE(lexp != NULL && *lexp == NULL); - if (max_token == 0U) + if (max_token == 0U) { max_token = 1; + } lex = isc_mem_get(mctx, sizeof(*lex)); lex->data = isc_mem_get(mctx, max_token + 1); @@ -124,10 +126,12 @@ isc_lex_destroy(isc_lex_t **lexp) *lexp = NULL; REQUIRE(VALID_LEX(lex)); - while (!EMPTY(lex->sources)) + while (!EMPTY(lex->sources)) { RUNTIME_CHECK(isc_lex_close(lex) == ISC_R_SUCCESS); - if (lex->data != NULL) + } + if (lex->data != NULL) { isc_mem_put(lex->mctx, lex->data, lex->max_token + 1); + } lex->magic = 0; isc_mem_put(lex->mctx, lex, sizeof(*lex)); } @@ -218,12 +222,14 @@ isc_lex_openfile(isc_lex_t *lex, const char *filename) REQUIRE(VALID_LEX(lex)); result = isc_stdio_open(filename, "r", &stream); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = new_source(lex, true, true, stream, filename); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { (void)fclose(stream); + } return (result); } @@ -271,14 +277,16 @@ isc_lex_close(isc_lex_t *lex) REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); - if (source == NULL) + if (source == NULL) { return (ISC_R_NOMORE); + } ISC_LIST_UNLINK(lex->sources, source, link); lex->last_was_eol = source->last_was_eol; if (source->is_file) { - if (source->need_close) + if (source->need_close) { (void)fclose((FILE *)(source->input)); + } } isc_mem_free(lex->mctx, source->name); isc_buffer_free(&source->pushback); @@ -311,8 +319,9 @@ pushback(inputsource *source, int c) return; } source->pushback->current--; - if (c == '\n') + if (c == '\n') { source->line--; + } } static isc_result_t @@ -371,8 +380,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) return (ISC_R_NOMORE); } - if (source->result != ISC_R_SUCCESS) + if (source->result != ISC_R_SUCCESS) { return (source->result); + } lex->saved_paren_count = lex->paren_count; source->saved_line = source->line; @@ -399,8 +409,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) isc_buffer_compact(source->pushback); saved_options = options; - if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 && lex->paren_count > 0) + if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 && lex->paren_count > 0) { options &= ~IWSEOL; + } curr = lex->data; *curr = '\0'; @@ -409,9 +420,10 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) remaining = lex->max_token; #ifdef HAVE_FLOCKFILE - if (source->is_file) + if (source->is_file) { flockfile(source->input); -#endif + } +#endif /* ifdef HAVE_FLOCKFILE */ do { if (isc_buffer_remaininglength(source->pushback) == 0) { @@ -420,9 +432,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) #if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED) c = getc_unlocked(stream); -#else +#else /* if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED) */ c = getc(stream); -#endif +#endif /* if defined(HAVE_FLOCKFILE) && defined(HAVE_GETC_UNLOCKED) */ if (c == EOF) { if (ferror(stream)) { source->result = ISC_R_IOERROR; @@ -453,17 +465,19 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) } if (!source->at_eof) { - if (state == lexstate_start) + if (state == lexstate_start) { /* Token has not started yet. */ source->ignored = isc_buffer_consumedlength( source->pushback); + } c = isc_buffer_getuint8(source->pushback); } else { c = EOF; } - if (c == '\n') + if (c == '\n') { source->line++; + } if (lex->comment_ok && !no_comments) { if (!escaped && c == ';' && @@ -529,8 +543,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) } lex->last_was_eol = true; } else if (c == '\r') { - if ((options & ISC_LEXOPT_EOL) != 0) + if ((options & ISC_LEXOPT_EOL) != 0) { state = lexstate_crlf; + } } else if (c == '"' && (options & ISC_LEXOPT_QSTRING) != 0) { lex->last_was_eol = false; @@ -541,8 +556,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) if ((c == '(' || c == ')') && (options & ISC_LEXOPT_DNSMULTILINE) != 0) { if (c == '(') { - if (lex->paren_count == 0) + if (lex->paren_count == 0) { options &= ~IWSEOL; + } lex->paren_count++; } else { if (lex->paren_count == 0) { @@ -551,8 +567,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) goto done; } lex->paren_count--; - if (lex->paren_count == 0) + if (lex->paren_count == 0) { options = saved_options; + } } continue; } else if (c == '{' && @@ -574,10 +591,11 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) (options & ISC_LEXOPT_NUMBER) != 0) { lex->last_was_eol = false; if ((options & ISC_LEXOPT_OCTAL) != 0 && - (c == '8' || c == '9')) + (c == '8' || c == '9')) { state = lexstate_string; - else + } else { state = lexstate_number; + } goto no_read; } else { lex->last_was_eol = false; @@ -586,8 +604,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) } break; case lexstate_crlf: - if (c != '\n') + if (c != '\n') { pushback(source, c); + } tokenp->type = isc_tokentype_eol; done = true; lex->last_was_eol = true; @@ -597,13 +616,14 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) if (c == ' ' || c == '\t' || c == '\r' || c == '\n' || c == EOF || lex->specials[c]) { int base; - if ((options & ISC_LEXOPT_OCTAL) != 0) + if ((options & ISC_LEXOPT_OCTAL) != 0) { base = 8; - else if ((options & - ISC_LEXOPT_CNUMBER) != 0) + } else if ((options & + ISC_LEXOPT_CNUMBER) != 0) { base = 0; - else + } else { base = 10; + } pushback(source, c); result = isc_parse_uint32( @@ -624,8 +644,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) v->as_textregion.length = (unsigned int)(lex->max_token - remaining); - } else + } else { goto done; + } done = true; continue; } else if ((options & ISC_LEXOPT_CNUMBER) == @@ -643,8 +664,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) if (remaining == 0U) { result = grow_data(lex, &remaining, &curr, &prev); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } } INSIST(remaining > 0U); *curr++ = c; @@ -672,14 +694,16 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) done = true; continue; } - if ((options & ISC_LEXOPT_ESCAPE) != 0) + if ((options & ISC_LEXOPT_ESCAPE) != 0) { escaped = (!escaped && c == '\\') ? true : false; + } if (remaining == 0U) { result = grow_data(lex, &remaining, &curr, &prev); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } } INSIST(remaining > 0U); *curr++ = c; @@ -707,8 +731,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) result = ISC_R_UNEXPECTEDEND; goto done; } - if (c == '*') + if (c == '*') { state = lexstate_ccommentend; + } break; case lexstate_ccommentend: if (c == EOF) { @@ -726,8 +751,9 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) no_comments = false; state = saved_state; goto no_read; - } else if (c != '*') + } else if (c != '*') { state = lexstate_ccomment; + } break; case lexstate_eatline: if ((c == '\n') || (c == EOF)) { @@ -767,15 +793,17 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) result = ISC_R_UNBALANCEDQUOTES; goto done; } - if (c == '\\' && !escaped) + if (c == '\\' && !escaped) { escaped = true; - else + } else { escaped = false; + } if (remaining == 0U) { result = grow_data(lex, &remaining, &curr, &prev); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } } INSIST(remaining > 0U); prev = curr; @@ -816,16 +844,18 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) } } - if (c == '\\' && !escaped) + if (c == '\\' && !escaped) { escaped = true; - else + } else { escaped = false; + } if (remaining == 0U) { result = grow_data(lex, &remaining, &curr, &prev); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } } INSIST(remaining > 0U); prev = curr; @@ -837,15 +867,15 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) FATAL_ERROR(__FILE__, __LINE__, "Unexpected state %d", state); } - } while (!done); result = ISC_R_SUCCESS; done: #ifdef HAVE_FLOCKFILE - if (source->is_file) + if (source->is_file) { funlockfile(source->input); -#endif + } +#endif /* ifdef HAVE_FLOCKFILE */ return (result); } @@ -857,29 +887,36 @@ isc_lex_getmastertoken(isc_lex_t *lex, isc_token_t *token, ISC_LEXOPT_DNSMULTILINE | ISC_LEXOPT_ESCAPE; isc_result_t result; - if (expect == isc_tokentype_qstring) + if (expect == isc_tokentype_qstring) { options |= ISC_LEXOPT_QSTRING; - else if (expect == isc_tokentype_number) + } else if (expect == isc_tokentype_number) { options |= ISC_LEXOPT_NUMBER; + } result = isc_lex_gettoken(lex, options, token); - if (result == ISC_R_RANGE) + if (result == ISC_R_RANGE) { isc_lex_ungettoken(lex, token); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } if (eol && ((token->type == isc_tokentype_eol) || - (token->type == isc_tokentype_eof))) + (token->type == isc_tokentype_eof))) { return (ISC_R_SUCCESS); + } if (token->type == isc_tokentype_string && - expect == isc_tokentype_qstring) + expect == isc_tokentype_qstring) { return (ISC_R_SUCCESS); + } if (token->type != expect) { isc_lex_ungettoken(lex, token); if (token->type == isc_tokentype_eol || - token->type == isc_tokentype_eof) + token->type == isc_tokentype_eof) { return (ISC_R_UNEXPECTEDEND); - if (expect == isc_tokentype_number) + } + if (expect == isc_tokentype_number) { return (ISC_R_BADNUMBER); + } return (ISC_R_UNEXPECTEDTOKEN); } return (ISC_R_SUCCESS); @@ -894,19 +931,23 @@ isc_lex_getoctaltoken(isc_lex_t *lex, isc_token_t *token, bool eol) isc_result_t result; result = isc_lex_gettoken(lex, options, token); - if (result == ISC_R_RANGE) + if (result == ISC_R_RANGE) { isc_lex_ungettoken(lex, token); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } if (eol && ((token->type == isc_tokentype_eol) || - (token->type == isc_tokentype_eof))) + (token->type == isc_tokentype_eof))) { return (ISC_R_SUCCESS); + } if (token->type != isc_tokentype_number) { isc_lex_ungettoken(lex, token); if (token->type == isc_tokentype_eol || - token->type == isc_tokentype_eof) + token->type == isc_tokentype_eof) { return (ISC_R_UNEXPECTEDEND); + } return (ISC_R_BADNUMBER); } return (ISC_R_SUCCESS); @@ -964,8 +1005,9 @@ isc_lex_getsourcename(isc_lex_t *lex) REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); - if (source == NULL) + if (source == NULL) { return (NULL); + } return (source->name); } @@ -978,8 +1020,9 @@ isc_lex_getsourceline(isc_lex_t *lex) REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); - if (source == NULL) + if (source == NULL) { return (0); + } return (source->line); } @@ -993,8 +1036,9 @@ isc_lex_setsourcename(isc_lex_t *lex, const char *name) REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); - if (source == NULL) + if (source == NULL) { return (ISC_R_NOTFOUND); + } newname = isc_mem_strdup(lex->mctx, name); isc_mem_free(lex->mctx, source->name); source->name = newname; @@ -1009,8 +1053,9 @@ isc_lex_setsourceline(isc_lex_t *lex, unsigned long line) REQUIRE(VALID_LEX(lex)); source = HEAD(lex->sources); - if (source == NULL) + if (source == NULL) { return (ISC_R_NOTFOUND); + } source->line = line; return (ISC_R_SUCCESS); @@ -1025,8 +1070,9 @@ isc_lex_isfile(isc_lex_t *lex) source = HEAD(lex->sources); - if (source == NULL) + if (source == NULL) { return (false); + } return (source->is_file); } diff --git a/lib/isc/lfsr.c b/lib/isc/lfsr.c index 5daeb5271d..e3c6215cdf 100644 --- a/lib/isc/lfsr.c +++ b/lib/isc/lfsr.c @@ -36,10 +36,12 @@ isc_lfsr_init(isc_lfsr_t *lfsr, uint32_t state, unsigned int bits, uint32_t tap, lfsr->reseed = reseed; lfsr->arg = arg; - if (count == 0 && reseed != NULL) + if (count == 0 && reseed != NULL) { reseed(lfsr, arg); - if (lfsr->state == 0) + } + if (lfsr->state == 0) { lfsr->state = 0xffffffffU >> (32 - lfsr->bits); + } } /*! @@ -56,10 +58,12 @@ lfsr_generate(isc_lfsr_t *lfsr) * still 0, set it to all ones. */ if (lfsr->state == 0) { - if (lfsr->reseed != NULL) + if (lfsr->reseed != NULL) { lfsr->reseed(lfsr, lfsr->arg); - if (lfsr->state == 0) + } + if (lfsr->state == 0) { lfsr->state = 0xffffffffU >> (32 - lfsr->bits); + } } if (lfsr->state & 0x01) { @@ -96,18 +100,20 @@ isc_lfsr_generate(isc_lfsr_t *lfsr, void *data, unsigned int count) } if (lfsr->count != 0 && lfsr->reseed != NULL) { - if (lfsr->count <= count * 8) + if (lfsr->count <= count * 8) { lfsr->reseed(lfsr, lfsr->arg); - else + } else { lfsr->count -= (count * 8); + } } } static inline uint32_t lfsr_skipgenerate(isc_lfsr_t *lfsr, unsigned int skip) { - while (skip--) + while (skip--) { (void)lfsr_generate(lfsr); + } (void)lfsr_generate(lfsr); @@ -122,8 +128,9 @@ isc_lfsr_skip(isc_lfsr_t *lfsr, unsigned int skip) { REQUIRE(VALID_LFSR(lfsr)); - while (skip--) + while (skip--) { (void)lfsr_generate(lfsr); + } } /* diff --git a/lib/isc/log.c b/lib/isc/log.c index 873b48c52a..6ec0e2d97b 100644 --- a/lib/isc/log.c +++ b/lib/isc/log.c @@ -167,8 +167,8 @@ static const int syslog_map[] = { LOG_DEBUG, LOG_INFO, LOG_NOTICE, */ LIBISC_EXTERNAL_DATA isc_logcategory_t isc_categories[] = { { "default", 0 }, /* "default" - must come - first. */ + * must come + * first. */ { "general", 0 }, { NULL, 0 } }; @@ -226,8 +226,8 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, /*@}*/ /**** - **** Public interfaces. - ****/ +**** Public interfaces. +****/ /* * Establish a new logging context, with default channels. @@ -269,25 +269,28 @@ isc_log_create(isc_mem_t *mctx, isc_log_t **lctxp, isc_logconfig_t **lcfgp) isc_log_registercategories(lctx, isc_categories); isc_log_registermodules(lctx, isc_modules); result = isc_logconfig_create(lctx, &lcfg); - - } else + } else { result = ISC_R_NOMEMORY; + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = sync_channellist(lcfg); + } if (result == ISC_R_SUCCESS) { lctx->logconfig = lcfg; *lctxp = lctx; - if (lcfgp != NULL) + if (lcfgp != NULL) { *lcfgp = lcfg; - + } } else { - if (lcfg != NULL) + if (lcfg != NULL) { isc_logconfig_destroy(&lcfg); - if (lctx != NULL) + } + if (lctx != NULL) { isc_log_destroy(&lctx); + } } return (result); @@ -386,8 +389,9 @@ isc_logconfig_use(isc_log_t *lctx, isc_logconfig_t *lcfg) * since any call to isc_log_registercategories. */ result = sync_channellist(lcfg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } LOCK(&lctx->lock); @@ -478,28 +482,32 @@ isc_logconfig_destroy(isc_logconfig_t **lcfgp) DE_CONST(FILE_NAME(channel), filename); isc_mem_free(mctx, filename); - if (FILE_STREAM(channel) != NULL) + if (FILE_STREAM(channel) != NULL) { (void)fclose(FILE_STREAM(channel)); + } } isc_mem_free(mctx, channel->name); isc_mem_put(mctx, channel, sizeof(*channel)); } - for (i = 0; i < lcfg->channellist_count; i++) + for (i = 0; i < lcfg->channellist_count; i++) { while ((item = ISC_LIST_HEAD(lcfg->channellists[i])) != NULL) { ISC_LIST_UNLINK(lcfg->channellists[i], item, link); isc_mem_put(mctx, item, sizeof(*item)); } + } - if (lcfg->channellist_count > 0) + if (lcfg->channellist_count > 0) { isc_mem_put(mctx, lcfg->channellists, lcfg->channellist_count * sizeof(ISC_LIST(isc_logchannellist_t))); + } lcfg->dynamic = false; - if (lcfg->tag != NULL) + if (lcfg->tag != NULL) { isc_mem_free(lcfg->lctx->mctx, lcfg->tag); + } lcfg->tag = NULL; lcfg->highest_level = 0; lcfg->duplicate_interval = 0; @@ -524,23 +532,24 @@ isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]) * It would need to do that if it had to allocate memory to store * pointers to each array passed in. */ - if (lctx->categories == NULL) + if (lctx->categories == NULL) { lctx->categories = categories; - - else { + } else { /* * Adjust the last (NULL) pointer of the already registered * categories to point to the incoming array. */ - for (catp = lctx->categories; catp->name != NULL;) - if (catp->id == UINT_MAX) + for (catp = lctx->categories; catp->name != NULL;) { + if (catp->id == UINT_MAX) { /* * The name pointer points to the next array. * Ick. */ DE_CONST(catp->name, catp); - else + } else { catp++; + } + } catp->name = (void *)categories; catp->id = UINT_MAX; @@ -549,8 +558,9 @@ isc_log_registercategories(isc_log_t *lctx, isc_logcategory_t categories[]) /* * Update the id number of the category with its new global id. */ - for (catp = categories; catp->name != NULL; catp++) + for (catp = categories; catp->name != NULL; catp++) { catp->id = lctx->category_count++; + } } isc_logcategory_t * @@ -561,18 +571,20 @@ isc_log_categorybyname(isc_log_t *lctx, const char *name) REQUIRE(VALID_CONTEXT(lctx)); REQUIRE(name != NULL); - for (catp = lctx->categories; catp->name != NULL;) - if (catp->id == UINT_MAX) + for (catp = lctx->categories; catp->name != NULL;) { + if (catp->id == UINT_MAX) { /* * catp is neither modified nor returned to the * caller, so removing its const qualifier is ok. */ DE_CONST(catp->name, catp); - else { - if (strcmp(catp->name, name) == 0) + } else { + if (strcmp(catp->name, name) == 0) { return (catp); + } catp++; } + } return (NULL); } @@ -593,23 +605,24 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]) * It would need to do that if it had to allocate memory to store * pointers to each array passed in. */ - if (lctx->modules == NULL) + if (lctx->modules == NULL) { lctx->modules = modules; - - else { + } else { /* * Adjust the last (NULL) pointer of the already registered * modules to point to the incoming array. */ - for (modp = lctx->modules; modp->name != NULL;) - if (modp->id == UINT_MAX) + for (modp = lctx->modules; modp->name != NULL;) { + if (modp->id == UINT_MAX) { /* * The name pointer points to the next array. * Ick. */ DE_CONST(modp->name, modp); - else + } else { modp++; + } + } modp->name = (void *)modules; modp->id = UINT_MAX; @@ -618,8 +631,9 @@ isc_log_registermodules(isc_log_t *lctx, isc_logmodule_t modules[]) /* * Update the id number of the module with its new global id. */ - for (modp = modules; modp->name != NULL; modp++) + for (modp = modules; modp->name != NULL; modp++) { modp->id = lctx->module_count++; + } } isc_logmodule_t * @@ -630,18 +644,20 @@ isc_log_modulebyname(isc_log_t *lctx, const char *name) REQUIRE(VALID_CONTEXT(lctx)); REQUIRE(name != NULL); - for (modp = lctx->modules; modp->name != NULL;) - if (modp->id == UINT_MAX) + for (modp = lctx->modules; modp->name != NULL;) { + if (modp->id == UINT_MAX) { /* * modp is neither modified nor returned to the * caller, so removing its const qualifier is ok. */ DE_CONST(modp->name, modp); - else { - if (strcmp(modp->name, name) == 0) + } else { + if (strcmp(modp->name, name) == 0) { return (modp); + } modp++; } + } return (NULL); } @@ -723,8 +739,9 @@ isc_log_createchannel(isc_logconfig_t *lcfg, const char *name, * If default_stderr was redefined, make the default category * point to the new default_stderr. */ - if (strcmp(name, "default_stderr") == 0) + if (strcmp(name, "default_stderr") == 0) { default_channel.channel = channel; + } return (ISC_R_SUCCESS); } @@ -751,26 +768,27 @@ isc_log_usechannel(isc_logconfig_t *lcfg, const char *name, channel = ISC_LIST_NEXT(channel, link)) { if (strcmp(name, channel->name) == 0) { break; - } } - if (channel == NULL) + if (channel == NULL) { return (ISC_R_NOTFOUND); + } - if (category != NULL) + if (category != NULL) { result = assignchannel(lcfg, category->id, module, channel); - - else + } else { /* * Assign to all categories. Note that this includes * the default channel. */ for (i = 0; i < lctx->category_count; i++) { result = assignchannel(lcfg, i, module, channel); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } + } return (result); } @@ -846,16 +864,19 @@ isc_log_setdebuglevel(isc_log_t *lctx, unsigned int level) /* * Close ISC_LOG_DEBUGONLY channels if level is zero. */ - if (lctx->debug_level == 0) + if (lctx->debug_level == 0) { for (channel = ISC_LIST_HEAD(lctx->logconfig->channels); channel != NULL; channel = ISC_LIST_NEXT(channel, link)) { - if (channel->type == ISC_LOG_TOFILE && (channel->flags & ISC_LOG_DEBUGONLY) != 0 && FILE_STREAM(channel) != NULL) { + if (channel->type == ISC_LOG_TOFILE && + (channel->flags & ISC_LOG_DEBUGONLY) != 0 && + FILE_STREAM(channel) != NULL) { { (void)fclose(FILE_STREAM(channel)); FILE_STREAM(channel) = NULL; } } } + } UNLOCK(&lctx->lock); } @@ -889,13 +910,14 @@ isc_log_settag(isc_logconfig_t *lcfg, const char *tag) REQUIRE(VALID_CONFIG(lcfg)); if (tag != NULL && *tag != '\0') { - if (lcfg->tag != NULL) + if (lcfg->tag != NULL) { isc_mem_free(lcfg->lctx->mctx, lcfg->tag); + } lcfg->tag = isc_mem_strdup(lcfg->lctx->mctx, tag); - } else { - if (lcfg->tag != NULL) + if (lcfg->tag != NULL) { isc_mem_free(lcfg->lctx->mctx, lcfg->tag); + } lcfg->tag = NULL; } @@ -927,8 +949,8 @@ isc_log_closefilelogs(isc_log_t *lctx) LOCK(&lctx->lock); for (channel = ISC_LIST_HEAD(lctx->logconfig->channels); channel != NULL; channel = ISC_LIST_NEXT(channel, link)) { - - if (channel->type == ISC_LOG_TOFILE && FILE_STREAM(channel) != NULL) { + if (channel->type == ISC_LOG_TOFILE && + FILE_STREAM(channel) != NULL) { { (void)fclose(FILE_STREAM(channel)); FILE_STREAM(channel) = NULL; @@ -939,8 +961,8 @@ isc_log_closefilelogs(isc_log_t *lctx) } /**** - **** Internal functions - ****/ +**** Internal functions +****/ static isc_result_t assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, @@ -962,8 +984,9 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, * Ensure lcfg->channellist_count == lctx->category_count. */ result = sync_channellist(lcfg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } new_item = isc_mem_get(lctx->mctx, sizeof(*new_item)); @@ -978,10 +1001,12 @@ assignchannel(isc_logconfig_t *lcfg, unsigned int category_id, * message is too high to be logged by any channel. */ if (channel->type != ISC_LOG_TONULL) { - if (lcfg->highest_level < channel->level) + if (lcfg->highest_level < channel->level) { lcfg->highest_level = channel->level; - if (channel->level == ISC_LOG_DYNAMIC) + } + if (channel->level == ISC_LOG_DYNAMIC) { lcfg->dynamic = true; + } } return (ISC_R_SUCCESS); @@ -1004,8 +1029,9 @@ sync_channellist(isc_logconfig_t *lcfg) REQUIRE(lctx->category_count != 0); - if (lctx->category_count == lcfg->channellist_count) + if (lctx->category_count == lcfg->channellist_count) { return (ISC_R_SUCCESS); + } bytes = lctx->category_count * sizeof(ISC_LIST(isc_logchannellist_t)); @@ -1038,7 +1064,7 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) char sep = '/'; #ifdef _WIN32 char *bname2; -#endif +#endif /* ifdef _WIN32 */ /* * It is safe to DE_CONST the file.name because it was copied @@ -1052,87 +1078,7 @@ greatest_version(isc_logfile_t *file, int versions, int *greatestp) bname = bname2; sep = '\\'; } -#endif - if (bname != NULL) { - *bname++ = '\0'; - dirname = file->name; - } else { - DE_CONST(file->name, bname); - dirname = "."; - } - bnamelen = strlen(bname); - - isc_dir_init(&dir); - result = isc_dir_open(&dir, dirname); - - /* - * Replace the file separator if it was taken out. - */ - if (bname != file->name) - *(bname - 1) = sep; - - /* - * Return if the directory open failed. - */ - if (result != ISC_R_SUCCESS) - return (result); - - while (isc_dir_read(&dir) == ISC_R_SUCCESS) { - if (dir.entry.length > bnamelen && - strncmp(dir.entry.name, bname, bnamelen) == 0 && - dir.entry.name[bnamelen] == '.') { - version = strtol(&dir.entry.name[bnamelen + 1], - &digit_end, 10); - /* - * Remove any backup files that exceed versions. - */ - if (*digit_end == '\0' && version >= versions) { - result = isc_file_remove(dir.entry.name); - if (result != ISC_R_SUCCESS && - result != ISC_R_FILENOTFOUND) - syslog(LOG_ERR, - "unable to remove " - "log file '%s': %s", - dir.entry.name, - isc_result_totext(result)); - } else if (*digit_end == '\0' && version > greatest) - greatest = version; - } - } - isc_dir_close(&dir); - - *greatestp = greatest; - - return (ISC_R_SUCCESS); -} - -static isc_result_t -remove_old_tsversions(isc_logfile_t *file, int versions) -{ - isc_result_t result; - char * bname, *digit_end; - const char * dirname; - int64_t version, last = INT64_MAX; - int64_t to_keep[ISC_LOG_MAX_VERSIONS]; - size_t bnamelen; - isc_dir_t dir; - char sep = '/'; -#ifdef _WIN32 - char *bname2; -#endif - /* - * It is safe to DE_CONST the file.name because it was copied - * with isc_mem_strdup(). - */ - bname = strrchr(file->name, sep); -#ifdef _WIN32 - bname2 = strrchr(file->name, '\\'); - if ((bname != NULL && bname2 != NULL && bname2 > bname) || - (bname == NULL && bname2 != NULL)) { - bname = bname2; - sep = '\\'; - } -#endif +#endif /* ifdef _WIN32 */ if (bname != NULL) { *bname++ = '\0'; dirname = file->name; @@ -1155,8 +1101,93 @@ remove_old_tsversions(isc_logfile_t *file, int versions) /* * Return if the directory open failed. */ - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } + + while (isc_dir_read(&dir) == ISC_R_SUCCESS) { + if (dir.entry.length > bnamelen && + strncmp(dir.entry.name, bname, bnamelen) == 0 && + dir.entry.name[bnamelen] == '.') { + version = strtol(&dir.entry.name[bnamelen + 1], + &digit_end, 10); + /* + * Remove any backup files that exceed versions. + */ + if (*digit_end == '\0' && version >= versions) { + result = isc_file_remove(dir.entry.name); + if (result != ISC_R_SUCCESS && + result != ISC_R_FILENOTFOUND) { + syslog(LOG_ERR, + "unable to remove " + "log file '%s': %s", + dir.entry.name, + isc_result_totext(result)); + } + } else if (*digit_end == '\0' && version > greatest) { + greatest = version; + } + } + } + isc_dir_close(&dir); + + *greatestp = greatest; + + return (ISC_R_SUCCESS); +} + +static isc_result_t +remove_old_tsversions(isc_logfile_t *file, int versions) +{ + isc_result_t result; + char * bname, *digit_end; + const char * dirname; + int64_t version, last = INT64_MAX; + int64_t to_keep[ISC_LOG_MAX_VERSIONS]; + size_t bnamelen; + isc_dir_t dir; + char sep = '/'; +#ifdef _WIN32 + char *bname2; +#endif /* ifdef _WIN32 */ + /* + * It is safe to DE_CONST the file.name because it was copied + * with isc_mem_strdup(). + */ + bname = strrchr(file->name, sep); +#ifdef _WIN32 + bname2 = strrchr(file->name, '\\'); + if ((bname != NULL && bname2 != NULL && bname2 > bname) || + (bname == NULL && bname2 != NULL)) { + bname = bname2; + sep = '\\'; + } +#endif /* ifdef _WIN32 */ + if (bname != NULL) { + *bname++ = '\0'; + dirname = file->name; + } else { + DE_CONST(file->name, bname); + dirname = "."; + } + bnamelen = strlen(bname); + + isc_dir_init(&dir); + result = isc_dir_open(&dir, dirname); + + /* + * Replace the file separator if it was taken out. + */ + if (bname != file->name) { + *(bname - 1) = sep; + } + + /* + * Return if the directory open failed. + */ + if (result != ISC_R_SUCCESS) { + return (result); + } if (versions > 0) { /* @@ -1209,12 +1240,13 @@ remove_old_tsversions(isc_logfile_t *file, int versions) if (*digit_end == '\0' && version < last) { result = isc_file_remove(dir.entry.name); if (result != ISC_R_SUCCESS && - result != ISC_R_FILENOTFOUND) + result != ISC_R_FILENOTFOUND) { syslog(LOG_ERR, "unable to remove " "log file '%s': %s", dir.entry.name, isc_result_totext(result)); + } } } } @@ -1364,9 +1396,10 @@ isc_logfile_roll(isc_logfile_t *file) return (ISC_R_SUCCESS); } else if (file->versions == 0) { result = isc_file_remove(file->name); - if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) + if (result != ISC_R_SUCCESS && result != ISC_R_FILENOTFOUND) { syslog(LOG_ERR, "unable to remove log file '%s': %s", file->name, isc_result_totext(result)); + } return (ISC_R_SUCCESS); } @@ -1407,20 +1440,23 @@ isc_log_open(isc_logchannel_t *channel) if ((FILE_MAXSIZE(channel) == 0 && FILE_VERSIONS(channel) != ISC_LOG_ROLLNEVER) || (FILE_MAXSIZE(channel) > 0 && - statbuf.st_size >= FILE_MAXSIZE(channel))) + statbuf.st_size >= FILE_MAXSIZE(channel))) { roll = regular_file; + } } else if (errno == ENOENT) { regular_file = true; POST(regular_file); - } else + } else { result = ISC_R_INVALIDFILE; + } /* * Version control. */ if (result == ISC_R_SUCCESS && roll) { - if (FILE_VERSIONS(channel) == ISC_LOG_ROLLNEVER) + if (FILE_VERSIONS(channel) == ISC_LOG_ROLLNEVER) { return (ISC_R_MAXSIZE); + } result = isc_logfile_roll(&channel->destination.file); if (result != ISC_R_SUCCESS) { if ((channel->flags & ISC_LOG_OPENERR) == 0) { @@ -1460,8 +1496,9 @@ isc_log_wouldlog(isc_log_t *lctx, int level) * dynamically changed. */ - if (lctx == NULL || lctx->logconfig == NULL) + if (lctx == NULL || lctx->logconfig == NULL) { return (false); + } return (level <= lctx->logconfig->highest_level || (lctx->logconfig->dynamic && level <= lctx->debug_level)); @@ -1498,14 +1535,16 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, * wanting to do any logging, thus the log context is allowed to * be non-existent. */ - if (lctx == NULL) + if (lctx == NULL) { return; + } REQUIRE(category->id < lctx->category_count); REQUIRE(module->id < lctx->module_count); - if (!isc_log_wouldlog(lctx, level)) + if (!isc_log_wouldlog(lctx, level)) { return; + } local_time[0] = '\0'; iso8601l_string[0] = '\0'; @@ -1528,25 +1567,28 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, * If the channel list end was reached and a match was made, * everything is finished. */ - if (category_channels == NULL && matched) + if (category_channels == NULL && matched) { break; + } if (category_channels == NULL && !matched && - category_channels != ISC_LIST_HEAD(lcfg->channellists[0])) + category_channels != ISC_LIST_HEAD(lcfg->channellists[0])) { /* * No category/module pair was explicitly configured. * Try the category named "default". */ category_channels = ISC_LIST_HEAD(lcfg->channellists[0]); + } - if (category_channels == NULL && !matched) + if (category_channels == NULL && !matched) { /* * No matching module was explicitly configured * for the category named "default". Use the internal * default channel. */ category_channels = &default_channel; + } if (category_channels->module != NULL && category_channels->module != module) { @@ -1561,14 +1603,17 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, category_channels = ISC_LIST_NEXT(category_channels, link); if (((channel->flags & ISC_LOG_DEBUGONLY) != 0) && - lctx->debug_level == 0) + lctx->debug_level == 0) { continue; + } if (channel->level == ISC_LOG_DYNAMIC) { - if (lctx->debug_level < level) + if (lctx->debug_level < level) { continue; - } else if (channel->level < level) + } + } else if (channel->level < level) { continue; + } if ((channel->flags & ISC_LOG_PRINTTIME) != 0 && local_time[0] == '\0') { @@ -1625,14 +1670,16 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, */ TIME_NOW(&oldest); if (isc_time_subtract(&oldest, &interval, - &oldest) != ISC_R_SUCCESS) + &oldest) != + ISC_R_SUCCESS) { /* * Can't effectively do the checking * without having a valid time. */ message = NULL; - else + } else { message = ISC_LIST_HEAD(lctx->messages); + } while (message != NULL) { if (isc_time_compare(&message->time, @@ -1725,8 +1772,9 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, } else { time_string = local_time; } - } else + } else { time_string = ""; + } switch (channel->type) { case ISC_LOG_TOFILE: @@ -1748,11 +1796,12 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, (void)fclose(FILE_STREAM(channel)); FILE_STREAM(channel) = NULL; FILE_MAXREACHED(channel) = false; - } else + } else { /* * Eh, skip it. */ break; + } } if (FILE_STREAM(channel) == NULL) { @@ -1766,8 +1815,9 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, isc_result_totext(result)); channel->flags |= ISC_LOG_OPENERR; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } channel->flags &= ~ISC_LOG_OPENERR; } /* FALLTHROUGH */ @@ -1785,8 +1835,9 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, printmodule ? ": " : "", printlevel ? level_string : "", lctx->buffer); - if (!buffered) + if (!buffered) { fflush(FILE_STREAM(channel)); + } /* * If the file now exceeds its maximum size @@ -1800,19 +1851,21 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, /* XXXDCL complain if fstat fails? */ if (fstat(fileno(FILE_STREAM(channel)), &statbuf) >= 0 && - statbuf.st_size > FILE_MAXSIZE(channel)) + statbuf.st_size > FILE_MAXSIZE(channel)) { FILE_MAXREACHED(channel) = true; + } } break; case ISC_LOG_TOSYSLOG: - if (level > 0) + if (level > 0) { syslog_level = LOG_DEBUG; - else if (level < ISC_LOG_CRITICAL) + } else if (level < ISC_LOG_CRITICAL) { syslog_level = LOG_CRIT; - else + } else { syslog_level = syslog_map[-level]; + } (void)syslog( FACILITY(channel) | syslog_level, @@ -1832,7 +1885,6 @@ isc_log_doit(isc_log_t *lctx, isc_logcategory_t *category, case ISC_LOG_TONULL: break; } - } while (1); UNLOCK(&lctx->lock); diff --git a/lib/isc/mem.c b/lib/isc/mem.c index 6939da5699..f4c12175cb 100644 --- a/lib/isc/mem.c +++ b/lib/isc/mem.c @@ -47,7 +47,7 @@ #ifndef ISC_MEM_DEBUGGING #define ISC_MEM_DEBUGGING 0 -#endif +#endif /* ifndef ISC_MEM_DEBUGGING */ LIBISC_EXTERNAL_DATA unsigned int isc_mem_debugging = ISC_MEM_DEBUGGING; LIBISC_EXTERNAL_DATA unsigned int isc_mem_defaultflags = ISC_MEMFLAG_DEFAULT; @@ -82,10 +82,10 @@ typedef ISC_LIST(debuglink_t) debuglist_t; #define FLARG_PASS , file, line #define FLARG , const char *file, unsigned int line -#else +#else /* if ISC_MEM_TRACKLINES */ #define FLARG_PASS #define FLARG -#endif +#endif /* if ISC_MEM_TRACKLINES */ typedef struct element element; struct element { @@ -173,7 +173,7 @@ struct isc__mem { #if ISC_MEM_TRACKLINES debuglist_t *debuglist; size_t debuglistcnt; -#endif +#endif /* if ISC_MEM_TRACKLINES */ ISC_LINK(isc__mem_t) link; }; @@ -201,7 +201,7 @@ struct isc__mempool { /*%< Debugging only. */ #if ISC_MEMPOOL_NAMES char name[16]; /*%< printed name in stats reports */ -#endif +#endif /* if ISC_MEMPOOL_NAMES */ }; /* @@ -212,7 +212,7 @@ struct isc__mempool { #define ADD_TRACE(a, b, c, d, e) #define DELETE_TRACE(a, b, c, d, e) #define ISC_MEMFUNC_SCOPE -#else +#else /* if !ISC_MEM_TRACKLINES */ #define TRACE_OR_RECORD (ISC_MEM_DEBUGTRACE | ISC_MEM_DEBUGRECORD) #define ADD_TRACE(a, b, c, d, e) \ do { \ @@ -269,8 +269,9 @@ add_trace_entry(isc__mem_t *mctx, const void *ptr, size_t size FLARG) ptr, size, file, line, mctx); } - if (mctx->debuglist == NULL) + if (mctx->debuglist == NULL) { return; + } hash = isc_hash_function(&ptr, sizeof(ptr), true); idx = hash % DEBUG_TABLE_COUNT; @@ -278,8 +279,9 @@ add_trace_entry(isc__mem_t *mctx, const void *ptr, size_t size FLARG) dl = malloc(sizeof(debuglink_t)); INSIST(dl != NULL); mctx->malloced += sizeof(debuglink_t); - if (mctx->malloced > mctx->maxmalloced) + if (mctx->malloced > mctx->maxmalloced) { mctx->maxmalloced = mctx->malloced; + } ISC_LINK_INIT(dl, link); dl->ptr = ptr; @@ -304,8 +306,9 @@ delete_trace_entry(isc__mem_t *mctx, const void *ptr, size_t size, ptr, size, file, line, mctx); } - if (mctx->debuglist == NULL) + if (mctx->debuglist == NULL) { return; + } hash = isc_hash_function(&ptr, sizeof(ptr), true); idx = hash % DEBUG_TABLE_COUNT; @@ -348,8 +351,9 @@ quantize(size_t size) * byte boundaries. */ - if (size == 0U) + if (size == 0U) { return (ALIGNMENT_SIZE); + } return ((size + ALIGNMENT_SIZE - 1) & (~(ALIGNMENT_SIZE - 1))); } @@ -369,8 +373,9 @@ more_basic_blocks(isc__mem_t *ctx) table_size = ctx->basic_table_size + TABLE_INCREMENT; table = (ctx->memalloc)(table_size * sizeof(unsigned char *)); ctx->malloced += table_size * sizeof(unsigned char *); - if (ctx->malloced > ctx->maxmalloced) + if (ctx->malloced > ctx->maxmalloced) { ctx->maxmalloced = ctx->malloced; + } if (ctx->basic_table_size != 0) { memmove(table, ctx->basic_table, ctx->basic_table_size * @@ -385,7 +390,6 @@ more_basic_blocks(isc__mem_t *ctx) tmp = (ctx->memalloc)(NUM_BASIC_BLOCKS * ctx->mem_target); ctx->total += NUM_BASIC_BLOCKS * ctx->mem_target; - ; ctx->basic_table[ctx->basic_table_count] = tmp; ctx->basic_table_count++; ctx->malloced += NUM_BASIC_BLOCKS * ctx->mem_target; @@ -484,8 +488,9 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) ctx->stats[ctx->max_size].gets++; ctx->stats[ctx->max_size].totalgets++; ctx->malloced += size; - if (ctx->malloced > ctx->maxmalloced) + if (ctx->malloced > ctx->maxmalloced) { ctx->maxmalloced = ctx->malloced; + } /* * If we don't set new_size to size, then the * ISC_MEMFLAG_FILL code might write over bytes we don't @@ -523,8 +528,9 @@ mem_getunlocked(isc__mem_t *ctx, size_t size) done: if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0) && - ISC_LIKELY(ret != NULL)) + ISC_LIKELY(ret != NULL)) { memset(ret, 0xbe, new_size); /* Mnemonic for "beef". */ + } return (ret); } @@ -543,7 +549,7 @@ check_overrun(void *mem, size_t size, size_t new_size) size++; } } -#endif +#endif /* if ISC_MEM_CHECKOVERRUN */ /* coverity[+free : arg-1] */ static inline void @@ -555,8 +561,9 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) /* * memput() called on something beyond our upper limit. */ - if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) + if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) { memset(mem, 0xde, size); /* Mnemonic for "dead". */ + } (ctx->memfree)(mem); INSIST(ctx->stats[ctx->max_size].gets != 0U); @@ -570,7 +577,7 @@ mem_putunlocked(isc__mem_t *ctx, void *mem, size_t size) if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) { #if ISC_MEM_CHECKOVERRUN check_overrun(mem, size, new_size); -#endif +#endif /* if ISC_MEM_CHECKOVERRUN */ memset(mem, 0xde, new_size); /* Mnemonic for "dead". */ } @@ -602,19 +609,21 @@ mem_get(isc__mem_t *ctx, size_t size) #if ISC_MEM_CHECKOVERRUN size += 1; -#endif +#endif /* if ISC_MEM_CHECKOVERRUN */ ret = (ctx->memalloc)(size); if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) { - if (ISC_LIKELY(ret != NULL)) + if (ISC_LIKELY(ret != NULL)) { memset(ret, 0xbe, size); /* Mnemonic for "beef". */ + } } #if ISC_MEM_CHECKOVERRUN else { - if (ISC_LIKELY(ret != NULL)) + if (ISC_LIKELY(ret != NULL)) { ret[size - 1] = 0xbe; + } } -#endif +#endif /* if ISC_MEM_CHECKOVERRUN */ return (ret); } @@ -629,9 +638,10 @@ mem_put(isc__mem_t *ctx, void *mem, size_t size) #if ISC_MEM_CHECKOVERRUN INSIST(((unsigned char *)mem)[size] == 0xbe); size += 1; -#endif - if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) +#endif /* if ISC_MEM_CHECKOVERRUN */ + if (ISC_UNLIKELY((ctx->flags & ISC_MEMFLAG_FILL) != 0)) { memset(mem, 0xde, size); /* Mnemonic for "dead". */ + } (ctx->memfree)(mem); } @@ -654,10 +664,11 @@ mem_getstats(isc__mem_t *ctx, size_t size) #if ISC_MEM_CHECKOVERRUN size += 1; -#endif +#endif /* if ISC_MEM_CHECKOVERRUN */ ctx->malloced += size; - if (ctx->malloced > ctx->maxmalloced) + if (ctx->malloced > ctx->maxmalloced) { ctx->maxmalloced = ctx->malloced; + } } /*! @@ -680,7 +691,7 @@ mem_putstats(isc__mem_t *ctx, void *ptr, size_t size) } #if ISC_MEM_CHECKOVERRUN size += 1; -#endif +#endif /* if ISC_MEM_CHECKOVERRUN */ ctx->malloced -= size; } @@ -777,7 +788,7 @@ mem_create(isc_mem_t **ctxp, unsigned int flags) #if ISC_MEM_TRACKLINES ctx->debuglist = NULL; ctx->debuglistcnt = 0; -#endif +#endif /* if ISC_MEM_TRACKLINES */ ISC_LIST_INIT(ctx->pools); ctx->poolcnt = 0; ctx->freelists = NULL; @@ -810,12 +821,13 @@ mem_create(isc_mem_t **ctxp, unsigned int flags) ctx->debuglist = (ctx->memalloc)( (DEBUG_TABLE_COUNT * sizeof(debuglist_t))); - for (i = 0; i < DEBUG_TABLE_COUNT; i++) + for (i = 0; i < DEBUG_TABLE_COUNT; i++) { ISC_LIST_INIT(ctx->debuglist[i]); + } ctx->malloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t); ctx->maxmalloced += DEBUG_TABLE_COUNT * sizeof(debuglist_t); } -#endif +#endif /* if ISC_MEM_TRACKLINES */ LOCK(&contextslock); ISC_LIST_INITANDAPPEND(contexts, ctx, link); @@ -846,22 +858,24 @@ destroy(isc__mem_t *ctx) #if ISC_MEM_TRACKLINES if (ISC_UNLIKELY(ctx->debuglist != NULL)) { debuglink_t *dl; - for (i = 0; i < DEBUG_TABLE_COUNT; i++) + for (i = 0; i < DEBUG_TABLE_COUNT; i++) { for (dl = ISC_LIST_HEAD(ctx->debuglist[i]); dl != NULL; dl = ISC_LIST_HEAD(ctx->debuglist[i])) { - if (ctx->checkfree && dl->ptr != NULL) + if (ctx->checkfree && dl->ptr != NULL) { print_active(ctx, stderr); + } INSIST(!ctx->checkfree || dl->ptr == NULL); ISC_LIST_UNLINK(ctx->debuglist[i], dl, link); free(dl); ctx->malloced -= sizeof(*dl); } + } (ctx->memfree)(ctx->debuglist); ctx->malloced -= DEBUG_TABLE_COUNT * sizeof(debuglist_t); } -#endif +#endif /* if ISC_MEM_TRACKLINES */ if (ctx->checkfree) { for (i = 0; i <= ctx->max_size; i++) { @@ -873,7 +887,7 @@ destroy(isc__mem_t *ctx) ctx, ctx->name, i, ctx->stats[i].gets); #if ISC_MEM_TRACKLINES print_active(ctx, stderr); -#endif +#endif /* if ISC_MEM_TRACKLINES */ INSIST(ctx->stats[i].gets == 0U); } } @@ -899,8 +913,9 @@ destroy(isc__mem_t *ctx) isc_mutex_destroy(&ctx->lock); ctx->malloced -= sizeof(*ctx); - if (ctx->checkfree) + if (ctx->checkfree) { INSIST(ctx->malloced == 0); + } (ctx->memfree)(ctx); } @@ -955,8 +970,9 @@ isc___mem_putanddetach(isc_mem_t **ctxp, void *ptr, size_t size FLARG) if ((isc_mem_debugging & ISC_MEM_DEBUGSIZE) != 0) { size_info *si = &(((size_info *)ptr)[-1]); size_t oldsize = si->u.size - ALIGNMENT_SIZE; - if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) + if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) { oldsize -= ALIGNMENT_SIZE; + } INSIST(oldsize == size); } isc__mem_free((isc_mem_t *)ctx, ptr FLARG_PASS); @@ -999,9 +1015,9 @@ isc_mem_destroy(isc_mem_t **ctxp) if (isc_refcount_decrement(&ctx->references) > 1) { print_active(ctx, stderr); } -#else +#else /* if ISC_MEM_TRACKLINES */ isc_refcount_decrement(&ctx->references); -#endif +#endif /* if ISC_MEM_TRACKLINES */ isc_refcount_destroy(&ctx->references); destroy(ctx); @@ -1018,8 +1034,9 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) bool call_water = false; if (ISC_UNLIKELY((isc_mem_debugging & - (ISC_MEM_DEBUGSIZE | ISC_MEM_DEBUGCTX)) != 0)) + (ISC_MEM_DEBUGSIZE | ISC_MEM_DEBUGCTX)) != 0)) { return (isc__mem_allocate(ctx0, size FLARG_PASS)); + } if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { MCTXLOCK(ctx); @@ -1027,28 +1044,32 @@ isc___mem_get(isc_mem_t *ctx0, size_t size FLARG) } else { ptr = mem_get(ctx, size); MCTXLOCK(ctx); - if (ptr != NULL) + if (ptr != NULL) { mem_getstats(ctx, size); + } } ADD_TRACE(ctx, ptr, size, file, line); if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water) { ctx->is_overmem = true; - if (!ctx->hi_called) + if (!ctx->hi_called) { call_water = true; + } } if (ctx->inuse > ctx->maxinuse) { ctx->maxinuse = ctx->inuse; if (ctx->hi_water != 0U && ctx->inuse > ctx->hi_water && - (isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) + (isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0) { fprintf(stderr, "maxinuse = %lu\n", (unsigned long)ctx->inuse); + } } MCTXUNLOCK(ctx); - if (call_water && (ctx->water != NULL)) + if (call_water && (ctx->water != NULL)) { (ctx->water)(ctx->water_arg, ISC_MEM_HIWATER); + } return (ptr); } @@ -1069,8 +1090,9 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) if ((isc_mem_debugging & ISC_MEM_DEBUGSIZE) != 0) { si = &(((size_info *)ptr)[-1]); oldsize = si->u.size - ALIGNMENT_SIZE; - if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) + if ((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0) { oldsize -= ALIGNMENT_SIZE; + } INSIST(oldsize == size); } isc__mem_free((isc_mem_t *)ctx, ptr FLARG_PASS); @@ -1095,14 +1117,16 @@ isc___mem_put(isc_mem_t *ctx0, void *ptr, size_t size FLARG) */ if ((ctx->inuse < ctx->lo_water) || (ctx->lo_water == 0U)) { ctx->is_overmem = false; - if (ctx->hi_called) + if (ctx->hi_called) { call_water = true; + } } MCTXUNLOCK(ctx); - if (call_water && (ctx->water != NULL)) + if (call_water && (ctx->water != NULL)) { (ctx->water)(ctx->water_arg, ISC_MEM_LOWATER); + } } void @@ -1113,10 +1137,11 @@ isc_mem_waterack(isc_mem_t *ctx0, int flag) isc__mem_t *ctx = (isc__mem_t *)ctx0; MCTXLOCK(ctx); - if (flag == ISC_MEM_LOWATER) + if (flag == ISC_MEM_LOWATER) { ctx->hi_called = false; - else if (flag == ISC_MEM_HIWATER) + } else if (flag == ISC_MEM_HIWATER) { ctx->hi_called = true; + } MCTXUNLOCK(ctx); } @@ -1155,7 +1180,7 @@ print_active(isc__mem_t *mctx, FILE *out) } } } -#endif +#endif /* if ISC_MEM_TRACKLINES */ /* * Print the stats[] on the stream "out" with suitable formatting. @@ -1175,15 +1200,17 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) for (i = 0; i <= ctx->max_size; i++) { s = &ctx->stats[i]; - if (s->totalgets == 0U && s->gets == 0U) + if (s->totalgets == 0U && s->gets == 0U) { continue; + } fprintf(out, "%s%5lu: %11lu gets, %11lu rem", (i == ctx->max_size) ? ">=" : " ", (unsigned long)i, s->totalgets, s->gets); if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0 && - (s->blocks != 0U || s->freefrags != 0U)) + (s->blocks != 0U || s->freefrags != 0U)) { fprintf(out, " (%lu bl, %lu ff)", s->blocks, s->freefrags); + } fputc('\n', out); } @@ -1205,9 +1232,9 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) fprintf(out, "%15s %10lu %10u %10u %10u %10u %10u %10u %s\n", #if ISC_MEMPOOL_NAMES pool->name, -#else +#else /* if ISC_MEMPOOL_NAMES */ "(not tracked)", -#endif +#endif /* if ISC_MEMPOOL_NAMES */ (unsigned long)pool->size, pool->maxalloc, pool->allocated, pool->freecount, pool->freemax, pool->fillcount, pool->gets, @@ -1217,7 +1244,7 @@ isc_mem_stats(isc_mem_t *ctx0, FILE *out) #if ISC_MEM_TRACKLINES print_active(ctx, out); -#endif +#endif /* if ISC_MEM_TRACKLINES */ MCTXUNLOCK(ctx); } @@ -1234,8 +1261,9 @@ mem_allocateunlocked(isc_mem_t *ctx0, size_t size) size_info * si; size += ALIGNMENT_SIZE; - if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)) + if (ISC_UNLIKELY((isc_mem_debugging & ISC_MEM_DEBUGCTX) != 0)) { size += ALIGNMENT_SIZE; + } if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { si = mem_getunlocked(ctx, size); @@ -1279,11 +1307,12 @@ isc___mem_allocate(isc_mem_t *ctx0, size_t size FLARG) } if (ctx->inuse > ctx->maxinuse) { ctx->maxinuse = ctx->inuse; - if (ISC_UNLIKELY(ctx->hi_water != 0U && - ctx->inuse > ctx->hi_water && - (isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0)) + if (ISC_UNLIKELY( + ctx->hi_water != 0U && ctx->inuse > ctx->hi_water && + (isc_mem_debugging & ISC_MEM_DEBUGUSAGE) != 0)) { fprintf(stderr, "maxinuse = %lu\n", (unsigned long)ctx->inuse); + } } MCTXUNLOCK(ctx); @@ -1328,8 +1357,9 @@ isc___mem_reallocate(isc_mem_t *ctx0, void *ptr, size_t size FLARG) memmove(new_ptr, ptr, copysize); isc__mem_free(ctx0, ptr FLARG_PASS); } - } else if (ptr != NULL) + } else if (ptr != NULL) { isc__mem_free(ctx0, ptr FLARG_PASS); + } return (new_ptr); } @@ -1379,13 +1409,15 @@ isc___mem_free(isc_mem_t *ctx0, void *ptr FLARG) (ctx->inuse < ctx->lo_water || ctx->lo_water == 0U)) { ctx->hi_called = false; - if (ctx->water != NULL) + if (ctx->water != NULL) { call_water = true; + } } MCTXUNLOCK(ctx); - if (call_water) + if (call_water) { (ctx->water)(ctx->water_arg, ISC_MEM_LOWATER); + } } /* @@ -1406,8 +1438,9 @@ isc___mem_strdup(isc_mem_t *mctx0, const char *s FLARG) ns = isc__mem_allocate((isc_mem_t *)mctx, len FLARG_PASS); - if (ns != NULL) + if (ns != NULL) { strlcpy(ns, s, len); + } return (ns); } @@ -1501,8 +1534,9 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, } else { if (ctx->hi_called && (ctx->water != water || ctx->water_arg != water_arg || - ctx->inuse < lowater || lowater == 0U)) + ctx->inuse < lowater || lowater == 0U)) { callwater = true; + } ctx->water = water; ctx->water_arg = water_arg; ctx->hi_water = hiwater; @@ -1510,8 +1544,9 @@ isc_mem_setwater(isc_mem_t *ctx0, isc_mem_water_t water, void *water_arg, } MCTXUNLOCK(ctx); - if (callwater && oldwater != NULL) + if (callwater && oldwater != NULL) { (oldwater)(oldwater_arg, ISC_MEM_LOWATER); + } } bool @@ -1549,8 +1584,9 @@ isc_mem_getname(isc_mem_t *ctx0) isc__mem_t *ctx = (isc__mem_t *)ctx0; - if (ctx->name[0] == 0) + if (ctx->name[0] == 0) { return (""); + } return (ctx->name); } @@ -1604,7 +1640,7 @@ isc_mempool_create(isc_mem_t *mctx0, size_t size, isc_mempool_t **mpctxp) mpctx->gets = 0; #if ISC_MEMPOOL_NAMES mpctx->name[0] = 0; -#endif +#endif /* if ISC_MEMPOOL_NAMES */ mpctx->items = NULL; *mpctxp = (isc_mempool_t *)mpctx; @@ -1624,17 +1660,19 @@ isc_mempool_setname(isc_mempool_t *mpctx0, const char *name) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; #if ISC_MEMPOOL_NAMES - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } strlcpy(mpctx->name, name, sizeof(mpctx->name)); - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); -#else + } +#else /* if ISC_MEMPOOL_NAMES */ UNUSED(mpctx); UNUSED(name); -#endif +#endif /* if ISC_MEMPOOL_NAMES */ } void @@ -1650,20 +1688,22 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) mpctx = (isc__mempool_t *)*mpctxp; #if ISC_MEMPOOL_NAMES - if (mpctx->allocated > 0) + if (mpctx->allocated > 0) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_mempool_destroy(): mempool %s " "leaked memory", mpctx->name); -#endif + } +#endif /* if ISC_MEMPOOL_NAMES */ REQUIRE(mpctx->allocated == 0); mctx = mpctx->mctx; lock = mpctx->lock; - if (lock != NULL) + if (lock != NULL) { LOCK(lock); + } /* * Return any items on the free list @@ -1697,8 +1737,9 @@ isc_mempool_destroy(isc_mempool_t **mpctxp) isc_mem_put((isc_mem_t *)mpctx->mctx, mpctx, sizeof(isc__mempool_t)); - if (lock != NULL) + if (lock != NULL) { UNLOCK(lock); + } *mpctxp = NULL; } @@ -1728,8 +1769,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) mctx = mpctx->mctx; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } /* * Don't let the caller go over quota @@ -1750,11 +1792,13 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) item = mem_getunlocked(mctx, mpctx->size); } else { item = mem_get(mctx, mpctx->size); - if (item != NULL) + if (item != NULL) { mem_getstats(mctx, mpctx->size); + } } - if (ISC_UNLIKELY(item == NULL)) + if (ISC_UNLIKELY(item == NULL)) { break; + } item->next = mpctx->items; mpctx->items = item; mpctx->freecount++; @@ -1766,8 +1810,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) * If we didn't get any items, return NULL. */ item = mpctx->items; - if (ISC_UNLIKELY(item == NULL)) + if (ISC_UNLIKELY(item == NULL)) { goto out; + } mpctx->items = item->next; INSIST(mpctx->freecount > 0); @@ -1776,8 +1821,9 @@ isc__mempool_get(isc_mempool_t *mpctx0 FLARG) mpctx->allocated++; out: - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } #if ISC_MEM_TRACKLINES if (ISC_UNLIKELY(((isc_mem_debugging & TRACE_OR_RECORD) != 0) && @@ -1802,8 +1848,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) isc__mem_t * mctx = mpctx->mctx; element * item; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } INSIST(mpctx->allocated > 0); mpctx->allocated--; @@ -1828,8 +1875,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) mem_put(mctx, mem, mpctx->size); } MCTXUNLOCK(mctx); - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } return; } @@ -1841,8 +1889,9 @@ isc__mempool_put(isc_mempool_t *mpctx0, void *mem FLARG) item->next = mpctx->items; mpctx->items = item; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } } /* @@ -1856,13 +1905,15 @@ isc_mempool_setfreemax(isc_mempool_t *mpctx0, unsigned int limit) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } mpctx->freemax = limit; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } } unsigned int @@ -1873,13 +1924,15 @@ isc_mempool_getfreemax(isc_mempool_t *mpctx0) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; unsigned int freemax; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } freemax = mpctx->freemax; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } return (freemax); } @@ -1892,13 +1945,15 @@ isc_mempool_getfreecount(isc_mempool_t *mpctx0) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; unsigned int freecount; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } freecount = mpctx->freecount; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } return (freecount); } @@ -1911,13 +1966,15 @@ isc_mempool_setmaxalloc(isc_mempool_t *mpctx0, unsigned int limit) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } mpctx->maxalloc = limit; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } } unsigned int @@ -1928,13 +1985,15 @@ isc_mempool_getmaxalloc(isc_mempool_t *mpctx0) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; unsigned int maxalloc; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } maxalloc = mpctx->maxalloc; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } return (maxalloc); } @@ -1947,13 +2006,15 @@ isc_mempool_getallocated(isc_mempool_t *mpctx0) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; unsigned int allocated; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } allocated = mpctx->allocated; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } return (allocated); } @@ -1966,13 +2027,15 @@ isc_mempool_setfillcount(isc_mempool_t *mpctx0, unsigned int limit) isc__mempool_t *mpctx = (isc__mempool_t *)mpctx0; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } mpctx->fillcount = limit; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } } unsigned int @@ -1984,13 +2047,15 @@ isc_mempool_getfillcount(isc_mempool_t *mpctx0) unsigned int fillcount; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { LOCK(mpctx->lock); + } fillcount = mpctx->fillcount; - if (mpctx->lock != NULL) + if (mpctx->lock != NULL) { UNLOCK(mpctx->lock); + } return (fillcount); } @@ -2018,7 +2083,7 @@ isc_mem_checkdestroyed(FILE *file) { #if !ISC_MEM_TRACKLINES UNUSED(file); -#endif +#endif /* if !ISC_MEM_TRACKLINES */ RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS); @@ -2028,7 +2093,7 @@ isc_mem_checkdestroyed(FILE *file) if (ISC_UNLIKELY((isc_mem_debugging & TRACE_OR_RECORD) != 0)) { print_contexts(file); } -#endif +#endif /* if ISC_MEM_TRACKLINES */ INSIST(0); ISC_UNREACHABLE(); } @@ -2088,7 +2153,7 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, xmlTextWriterPtr writer) DEBUG_TABLE_COUNT * sizeof(debuglist_t) + ctx->debuglistcnt * sizeof(debuglink_t); } -#endif +#endif /* if ISC_MEM_TRACKLINES */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "references")); TRY0(xmlTextWriterWriteFormatString( writer, "%" PRIuFAST32, @@ -2131,8 +2196,9 @@ xml_renderctx(isc__mem_t *ctx, summarystat_t *summary, xmlTextWriterPtr writer) writer, "%" PRIu64 "", (uint64_t)ctx->basic_table_count * NUM_BASIC_BLOCKS * ctx->mem_target)); - } else + } else { TRY0(xmlTextWriterWriteFormatString(writer, "%s", "-")); + } TRY0(xmlTextWriterEndElement(writer)); /* blocksize */ TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "pools")); @@ -2247,16 +2313,17 @@ json_renderctx(isc__mem_t *ctx, summarystat_t *summary, json_object *array) summary->total += ctx->total; summary->inuse += ctx->inuse; summary->malloced += ctx->malloced; - if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) + if ((ctx->flags & ISC_MEMFLAG_INTERNAL) != 0) { summary->blocksize += ctx->basic_table_count * NUM_BASIC_BLOCKS * ctx->mem_target; + } #if ISC_MEM_TRACKLINES if (ctx->debuglist != NULL) { summary->contextsize += DEBUG_TABLE_COUNT * sizeof(debuglist_t) + ctx->debuglistcnt * sizeof(debuglink_t); } -#endif +#endif /* if ISC_MEM_TRACKLINES */ ctxobj = json_object_new_object(); CHECKMEM(ctxobj); @@ -2380,8 +2447,9 @@ isc_mem_renderjson(void *memobj0) return (ISC_R_SUCCESS); error: - if (ctxarray != NULL) + if (ctxarray != NULL) { json_object_put(ctxarray); + } return (result); } #endif /* HAVE_JSON_C */ @@ -2458,8 +2526,8 @@ isc__mem_printactive(isc_mem_t *ctx0, FILE *file) isc__mem_t *ctx = (isc__mem_t *)ctx0; print_active(ctx, file); -#else +#else /* if ISC_MEM_TRACKLINES */ UNUSED(ctx0); UNUSED(file); -#endif +#endif /* if ISC_MEM_TRACKLINES */ } diff --git a/lib/isc/netaddr.c b/lib/isc/netaddr.c index f2ac5a5b3b..4a4d70456e 100644 --- a/lib/isc/netaddr.c +++ b/lib/isc/netaddr.c @@ -28,29 +28,34 @@ isc_netaddr_equal(const isc_netaddr_t *a, const isc_netaddr_t *b) { REQUIRE(a != NULL && b != NULL); - if (a->family != b->family) + if (a->family != b->family) { return (false); + } - if (a->zone != b->zone) + if (a->zone != b->zone) { return (false); + } switch (a->family) { case AF_INET: - if (a->type.in.s_addr != b->type.in.s_addr) + if (a->type.in.s_addr != b->type.in.s_addr) { return (false); + } break; case AF_INET6: if (memcmp(&a->type.in6, &b->type.in6, sizeof(a->type.in6)) != 0 || - a->zone != b->zone) + a->zone != b->zone) { return (false); + } break; #ifdef ISC_PLATFORM_HAVESYSUNH case AF_UNIX: - if (strcmp(a->type.un, b->type.un) != 0) + if (strcmp(a->type.un, b->type.un) != 0) { return (false); + } break; -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ default: return (false); } @@ -68,11 +73,13 @@ isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b, REQUIRE(a != NULL && b != NULL); - if (a->family != b->family) + if (a->family != b->family) { return (false); + } - if (a->zone != b->zone && b->zone != 0) + if (a->zone != b->zone && b->zone != 0) { return (false); + } switch (a->family) { case AF_INET: @@ -92,15 +99,17 @@ isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b, /* * Don't crash if we get a pattern like 10.0.0.1/9999999. */ - if (prefixlen > ipabytes * 8) + if (prefixlen > ipabytes * 8) { prefixlen = ipabytes * 8; + } nbytes = prefixlen / 8; nbits = prefixlen % 8; if (nbytes > 0) { - if (memcmp(pa, pb, nbytes) != 0) + if (memcmp(pa, pb, nbytes) != 0) { return (false); + } } if (nbits > 0) { unsigned int bytea, byteb, mask; @@ -109,8 +118,9 @@ isc_netaddr_eqprefix(const isc_netaddr_t *a, const isc_netaddr_t *b, bytea = pa[nbytes]; byteb = pb[nbytes]; mask = (0xFF << (8 - nbits)) & 0xFF; - if ((bytea & mask) != (byteb & mask)) + if ((bytea & mask) != (byteb & mask)) { return (false); + } } return (true); } @@ -137,19 +147,21 @@ isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target) #ifdef ISC_PLATFORM_HAVESYSUNH case AF_UNIX: alen = strlen(netaddr->type.un); - if (alen > isc_buffer_availablelength(target)) + if (alen > isc_buffer_availablelength(target)) { return (ISC_R_NOSPACE); + } isc_buffer_putmem(target, (const unsigned char *)(netaddr->type.un), alen); return (ISC_R_SUCCESS); -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ default: return (ISC_R_FAILURE); } r = inet_ntop(netaddr->family, type, abuf, sizeof(abuf)); - if (r == NULL) + if (r == NULL) { return (ISC_R_FAILURE); + } alen = strlen(abuf); INSIST(alen < sizeof(abuf)); @@ -157,13 +169,15 @@ isc_netaddr_totext(const isc_netaddr_t *netaddr, isc_buffer_t *target) zlen = 0; if (netaddr->family == AF_INET6 && netaddr->zone != 0) { zlen = snprintf(zbuf, sizeof(zbuf), "%%%u", netaddr->zone); - if (zlen < 0) + if (zlen < 0) { return (ISC_R_FAILURE); + } INSIST((unsigned int)zlen < sizeof(zbuf)); } - if (alen + zlen > isc_buffer_availablelength(target)) + if (alen + zlen > isc_buffer_availablelength(target)) { return (ISC_R_NOSPACE); + } isc_buffer_putmem(target, (unsigned char *)abuf, alen); isc_buffer_putmem(target, (unsigned char *)zbuf, (unsigned int)zlen); @@ -180,17 +194,19 @@ isc_netaddr_format(const isc_netaddr_t *na, char *array, unsigned int size) isc_buffer_init(&buf, array, size); result = isc_netaddr_totext(na, &buf); - if (size == 0) + if (size == 0) { return; + } /* * Null terminate. */ if (result == ISC_R_SUCCESS) { - if (isc_buffer_availablelength(&buf) >= 1) + if (isc_buffer_availablelength(&buf) >= 1) { isc_buffer_putuint8(&buf, 0); - else + } else { result = ISC_R_NOSPACE; + } } if (result != ISC_R_SUCCESS) { @@ -211,14 +227,16 @@ isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen) case AF_INET: p = (const unsigned char *)&na->type.in; ipbytes = 4; - if (prefixlen > 32) + if (prefixlen > 32) { return (ISC_R_RANGE); + } break; case AF_INET6: p = (const unsigned char *)&na->type.in6; ipbytes = 16; - if (prefixlen > 128) + if (prefixlen > 128) { return (ISC_R_RANGE); + } break; default: return (ISC_R_NOTIMPLEMENTED); @@ -227,13 +245,15 @@ isc_netaddr_prefixok(const isc_netaddr_t *na, unsigned int prefixlen) nbits = prefixlen % 8; if (nbits != 0) { INSIST(nbytes < ipbytes); - if ((p[nbytes] & (0xff >> nbits)) != 0U) + if ((p[nbytes] & (0xff >> nbits)) != 0U) { return (ISC_R_FAILURE); + } nbytes++; } if (nbytes < ipbytes && - memcmp(p + nbytes, zeros, ipbytes - nbytes) != 0) + memcmp(p + nbytes, zeros, ipbytes - nbytes) != 0) { return (ISC_R_FAILURE); + } return (ISC_R_SUCCESS); } @@ -256,8 +276,9 @@ isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp) return (ISC_R_NOTIMPLEMENTED); } for (i = 0; i < ipbytes; i++) { - if (p[i] != 0xFF) + if (p[i] != 0xFF) { break; + } } nbytes = i; if (i < ipbytes) { @@ -266,13 +287,15 @@ isc_netaddr_masktoprefixlen(const isc_netaddr_t *s, unsigned int *lenp) c <<= 1; nbits++; } - if ((c & 0xFF) != 0) + if ((c & 0xFF) != 0) { return (ISC_R_MASKNONCONTIG); + } i++; } for (; i < ipbytes; i++) { - if (p[i] != 0) + if (p[i] != 0) { return (ISC_R_MASKNONCONTIG); + } } *lenp = nbytes * 8 + nbits; return (ISC_R_SUCCESS); @@ -298,19 +321,20 @@ isc_result_t isc_netaddr_frompath(isc_netaddr_t *netaddr, const char *path) { #ifdef ISC_PLATFORM_HAVESYSUNH - if (strlen(path) > sizeof(netaddr->type.un) - 1) + if (strlen(path) > sizeof(netaddr->type.un) - 1) { return (ISC_R_NOSPACE); + } memset(netaddr, 0, sizeof(*netaddr)); netaddr->family = AF_UNIX; strlcpy(netaddr->type.un, path, sizeof(netaddr->type.un)); netaddr->zone = 0; return (ISC_R_SUCCESS); -#else +#else /* ifdef ISC_PLATFORM_HAVESYSUNH */ UNUSED(netaddr); UNUSED(path); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } void @@ -347,7 +371,7 @@ isc_netaddr_fromsockaddr(isc_netaddr_t *t, const isc_sockaddr_t *s) memmove(t->type.un, s->type.sunix.sun_path, sizeof(t->type.un)); t->zone = 0; break; -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ default: INSIST(0); ISC_UNREACHABLE(); diff --git a/lib/isc/netmgr/netmgr.c b/lib/isc/netmgr/netmgr.c index f4361575cc..57f29c745c 100644 --- a/lib/isc/netmgr/netmgr.c +++ b/lib/isc/netmgr/netmgr.c @@ -98,7 +98,7 @@ static const isc_statscounter_t unixstatsindex[] = { isc_sockstatscounter_unixrecvfail, isc_sockstatscounter_unixactive }; -#endif +#endif /* if 0 */ /* * libuv is not thread safe, but has mechanisms to pass messages @@ -412,9 +412,9 @@ isc_nm_destroy(isc_nm_t **mgr0) isc_nm_resume(mgr); #ifdef WIN32 _sleep(1000); -#else +#else /* ifdef WIN32 */ usleep(1000000); -#endif +#endif /* ifdef WIN32 */ } /* @@ -544,9 +544,9 @@ nm_thread(isc_threadarg_t worker0) */ #ifdef WIN32 _sleep(100); -#else +#else /* ifdef WIN32 */ usleep(100000); -#endif +#endif /* ifdef WIN32 */ } /* diff --git a/lib/isc/netmgr/udp.c b/lib/isc/netmgr/udp.c index a9c41ad9fa..5a105c7cbd 100644 --- a/lib/isc/netmgr/udp.c +++ b/lib/isc/netmgr/udp.c @@ -92,10 +92,10 @@ isc_nm_listenudp(isc_nm_t *mgr, isc_nmiface_t *iface, isc_nm_recv_cb_t cb, #ifdef WIN32 res = setsockopt(csock->fd, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int)); -#else +#else /* ifdef WIN32 */ res = setsockopt(csock->fd, SOL_SOCKET, SO_REUSEPORT, &(int){ 1 }, sizeof(int)); -#endif +#endif /* ifdef WIN32 */ RUNTIME_CHECK(res == 0); ievent = isc__nm_get_ievent(mgr, netievent_udplisten); diff --git a/lib/isc/netmgr/uv-compat.c b/lib/isc/netmgr/uv-compat.c index 50569e9aa9..fecf26d792 100644 --- a/lib/isc/netmgr/uv-compat.c +++ b/lib/isc/netmgr/uv-compat.c @@ -189,4 +189,4 @@ isc_uv_import(uv_stream_t *stream, isc_uv_stream_info_t *info) uv_tcp_t *tcp = (uv_tcp_t *)stream; return (uv_tcp_open(tcp, info->fd)); } -#endif +#endif /* ifdef WIN32 */ diff --git a/lib/isc/netmgr/uv-compat.h b/lib/isc/netmgr/uv-compat.h index c532edbf00..9b548a760e 100644 --- a/lib/isc/netmgr/uv-compat.h +++ b/lib/isc/netmgr/uv-compat.h @@ -25,15 +25,15 @@ uv_handle_get_data(const uv_handle_t *handle) { return (handle->data); } -#endif +#endif /* ifndef HAVE_UV_HANDLE_GET_DATA */ #ifndef HAVE_UV_HANDLE_SET_DATA static inline void uv_handle_set_data(uv_handle_t *handle, void *data) { handle->data = data; -}; -#endif +} +#endif /* ifndef HAVE_UV_HANDLE_SET_DATA */ /* * These functions are not available in libuv, but they're very internal @@ -53,9 +53,9 @@ struct isc_uv_stream_info_s { uv_handle_type type; #ifdef WIN32 WSAPROTOCOL_INFOW socket_info; -#else +#else /* ifdef WIN32 */ int fd; -#endif +#endif /* ifdef WIN32 */ }; int diff --git a/lib/isc/netscope.c b/lib/isc/netscope.c index 3c767e4784..0f863c6d02 100644 --- a/lib/isc/netscope.c +++ b/lib/isc/netscope.c @@ -26,40 +26,43 @@ isc_netscope_pton(int af, char *scopename, void *addr, uint32_t *zoneid) #ifdef HAVE_IF_NAMETOINDEX unsigned int ifid; struct in6_addr *in6; -#endif +#endif /* ifdef HAVE_IF_NAMETOINDEX */ uint32_t zone; uint64_t llz; /* at this moment, we only support AF_INET6 */ - if (af != AF_INET6) + if (af != AF_INET6) { return (ISC_R_FAILURE); + } - /* - * Basically, "names" are more stable than numeric IDs in terms - * of renumbering, and are more preferred. However, since there - * is no standard naming convention and APIs to deal with the - * names. Thus, we only handle the case of link-local - * addresses, for which we use interface names as link names, - * assuming one to one mapping between interfaces and links. - */ + /* + * Basically, "names" are more stable than numeric IDs in terms + * of renumbering, and are more preferred. However, since there + * is no standard naming convention and APIs to deal with the + * names. Thus, we only handle the case of link-local + * addresses, for which we use interface names as link names, + * assuming one to one mapping between interfaces and links. + */ #ifdef HAVE_IF_NAMETOINDEX in6 = (struct in6_addr *)addr; if (IN6_IS_ADDR_LINKLOCAL(in6) && - (ifid = if_nametoindex((const char *)scopename)) != 0) + (ifid = if_nametoindex((const char *)scopename)) != 0) { zone = (uint32_t)ifid; - else { -#endif + } else { +#endif /* ifdef HAVE_IF_NAMETOINDEX */ llz = strtoull(scopename, &ep, 10); - if (ep == scopename) + if (ep == scopename) { return (ISC_R_FAILURE); + } /* check overflow */ zone = (uint32_t)(llz & 0xffffffffUL); - if (zone != llz) + if (zone != llz) { return (ISC_R_FAILURE); + } #ifdef HAVE_IF_NAMETOINDEX } -#endif +#endif /* ifdef HAVE_IF_NAMETOINDEX */ *zoneid = zone; return (ISC_R_SUCCESS); diff --git a/lib/isc/openssl_shim.c b/lib/isc/openssl_shim.c index f70b72c8a4..ce6f33ce22 100644 --- a/lib/isc/openssl_shim.c +++ b/lib/isc/openssl_shim.c @@ -30,7 +30,7 @@ CRYPTO_zalloc(size_t size) } return (ret); } -#endif +#endif /* if !HAVE_CRYPTO_ZALLOC */ #if !HAVE_EVP_CIPHER_CTX_NEW EVP_CIPHER_CTX * @@ -39,7 +39,7 @@ EVP_CIPHER_CTX_new(void) EVP_CIPHER_CTX *ctx = OPENSSL_zalloc(sizeof(*ctx)); return (ctx); } -#endif +#endif /* if !HAVE_EVP_CIPHER_CTX_NEW */ #if !HAVE_EVP_CIPHER_CTX_FREE void @@ -50,7 +50,7 @@ EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx) OPENSSL_free(ctx); } } -#endif +#endif /* if !HAVE_EVP_CIPHER_CTX_FREE */ #if !HAVE_EVP_MD_CTX_NEW EVP_MD_CTX * @@ -62,7 +62,7 @@ EVP_MD_CTX_new(void) } return (ctx); } -#endif +#endif /* if !HAVE_EVP_MD_CTX_NEW */ #if !HAVE_EVP_MD_CTX_FREE void @@ -73,7 +73,7 @@ EVP_MD_CTX_free(EVP_MD_CTX *ctx) OPENSSL_free(ctx); } } -#endif +#endif /* if !HAVE_EVP_MD_CTX_FREE */ #if !HAVE_EVP_MD_CTX_RESET int @@ -81,7 +81,7 @@ EVP_MD_CTX_reset(EVP_MD_CTX *ctx) { return (EVP_MD_CTX_cleanup(ctx)); } -#endif +#endif /* if !HAVE_EVP_MD_CTX_RESET */ #if !HAVE_HMAC_CTX_NEW HMAC_CTX * @@ -96,7 +96,7 @@ HMAC_CTX_new(void) } return (ctx); } -#endif +#endif /* if !HAVE_HMAC_CTX_NEW */ #if !HAVE_HMAC_CTX_FREE void @@ -107,7 +107,7 @@ HMAC_CTX_free(HMAC_CTX *ctx) OPENSSL_free(ctx); } } -#endif +#endif /* if !HAVE_HMAC_CTX_FREE */ #if !HAVE_HMAC_CTX_RESET int @@ -116,12 +116,12 @@ HMAC_CTX_reset(HMAC_CTX *ctx) HMAC_CTX_cleanup(ctx); return (1); } -#endif +#endif /* if !HAVE_HMAC_CTX_RESET */ #if !HAVE_HMAC_CTX_GET_MD const EVP_MD * HMAC_CTX_get_md(const HMAC_CTX *ctx) { - return ctx->md; + return (ctx->md); } -#endif +#endif /* if !HAVE_HMAC_CTX_GET_MD */ diff --git a/lib/isc/openssl_shim.h b/lib/isc/openssl_shim.h index 9995184949..ad61852eb1 100644 --- a/lib/isc/openssl_shim.h +++ b/lib/isc/openssl_shim.h @@ -21,49 +21,49 @@ void * CRYPTO_zalloc(size_t size); #define OPENSSL_zalloc(num) CRYPTO_zalloc(num) -#endif +#endif /* if !HAVE_CRYPTO_ZALLOC */ #if !HAVE_EVP_CIPHER_CTX_NEW EVP_CIPHER_CTX * EVP_CIPHER_CTX_new(void); -#endif +#endif /* if !HAVE_EVP_CIPHER_CTX_NEW */ #if !HAVE_EVP_CIPHER_CTX_FREE void EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx); -#endif +#endif /* if !HAVE_EVP_CIPHER_CTX_FREE */ #if !HAVE_EVP_MD_CTX_NEW EVP_MD_CTX * EVP_MD_CTX_new(void); -#endif +#endif /* if !HAVE_EVP_MD_CTX_NEW */ #if !HAVE_EVP_MD_CTX_FREE void EVP_MD_CTX_free(EVP_MD_CTX *ctx); -#endif +#endif /* if !HAVE_EVP_MD_CTX_FREE */ #if !HAVE_EVP_MD_CTX_RESET int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); -#endif +#endif /* if !HAVE_EVP_MD_CTX_RESET */ #if !HAVE_HMAC_CTX_NEW HMAC_CTX * HMAC_CTX_new(void); -#endif +#endif /* if !HAVE_HMAC_CTX_NEW */ #if !HAVE_HMAC_CTX_FREE void HMAC_CTX_free(HMAC_CTX *ctx); -#endif +#endif /* if !HAVE_HMAC_CTX_FREE */ #if !HAVE_HMAC_CTX_RESET int HMAC_CTX_reset(HMAC_CTX *ctx); -#endif +#endif /* if !HAVE_HMAC_CTX_RESET */ #if !HAVE_HMAC_CTX_GET_MD const EVP_MD * HMAC_CTX_get_md(const HMAC_CTX *ctx); -#endif +#endif /* if !HAVE_HMAC_CTX_GET_MD */ diff --git a/lib/isc/parseint.c b/lib/isc/parseint.c index 042f1decf8..ea7e529b15 100644 --- a/lib/isc/parseint.c +++ b/lib/isc/parseint.c @@ -26,20 +26,23 @@ isc_parse_uint32(uint32_t *uip, const char *string, int base) unsigned long n; uint32_t r; char * e; - if (!isalnum((unsigned char)(string[0]))) + if (!isalnum((unsigned char)(string[0]))) { return (ISC_R_BADNUMBER); + } errno = 0; n = strtoul(string, &e, base); - if (*e != '\0') + if (*e != '\0') { return (ISC_R_BADNUMBER); + } /* * Where long is 64 bits we need to convert to 32 bits then test for * equality. This is a no-op on 32 bit machines and a good compiler * will optimise it away. */ r = (uint32_t)n; - if ((n == ULONG_MAX && errno == ERANGE) || (n != (unsigned long)r)) + if ((n == ULONG_MAX && errno == ERANGE) || (n != (unsigned long)r)) { return (ISC_R_RANGE); + } *uip = r; return (ISC_R_SUCCESS); } @@ -50,10 +53,12 @@ isc_parse_uint16(uint16_t *uip, const char *string, int base) uint32_t val; isc_result_t result; result = isc_parse_uint32(&val, string, base); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (val > 0xFFFF) + } + if (val > 0xFFFF) { return (ISC_R_RANGE); + } *uip = (uint16_t)val; return (ISC_R_SUCCESS); } @@ -64,10 +69,12 @@ isc_parse_uint8(uint8_t *uip, const char *string, int base) uint32_t val; isc_result_t result; result = isc_parse_uint32(&val, string, base); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (val > 0xFF) + } + if (val > 0xFF) { return (ISC_R_RANGE); + } *uip = (uint8_t)val; return (ISC_R_SUCCESS); } diff --git a/lib/isc/pk11.c b/lib/isc/pk11.c index caa269ade8..fee36ece76 100644 --- a/lib/isc/pk11.c +++ b/lib/isc/pk11.c @@ -38,11 +38,11 @@ /* was 32 octets, Petr Spacek suggested 1024, SoftHSMv2 uses 256... */ #ifndef PINLEN #define PINLEN 256 -#endif +#endif /* ifndef PINLEN */ #ifndef PK11_NO_LOGERR #define PK11_NO_LOGERR 1 -#endif +#endif /* ifndef PK11_NO_LOGERR */ LIBISC_EXTERNAL_DATA bool pk11_verbose_init = false; @@ -115,13 +115,13 @@ static CK_C_INITIALIZE_ARGS pk11_init_args = { #ifndef PK11_LIB_LOCATION #define PK11_LIB_LOCATION "unknown_provider" -#endif +#endif /* ifndef PK11_LIB_LOCATION */ #ifndef WIN32 static const char *lib_name = PK11_LIB_LOCATION; -#else +#else /* ifndef WIN32 */ static const char *lib_name = PK11_LIB_LOCATION ".dll"; -#endif +#endif /* ifndef WIN32 */ void pk11_set_lib_name(const char *name) @@ -144,8 +144,9 @@ initialize(void) isc_mutex_init(&sessionlock); pk11_provider = getenv("PKCS11_PROVIDER"); - if (pk11_provider != NULL) + if (pk11_provider != NULL) { lib_name = pk11_provider; + } } void * @@ -154,9 +155,9 @@ pk11_mem_get(size_t size) void *ptr; LOCK(&alloclock); - if (pk11_mctx != NULL) + if (pk11_mctx != NULL) { ptr = isc_mem_get(pk11_mctx, size); - else { + } else { ptr = malloc(size); if (ptr == NULL && size != 0) { char strbuf[ISC_STRERRORSIZE]; @@ -167,22 +168,25 @@ pk11_mem_get(size_t size) } UNLOCK(&alloclock); - if (ptr != NULL) + if (ptr != NULL) { memset(ptr, 0, size); + } return (ptr); } void pk11_mem_put(void *ptr, size_t size) { - if (ptr != NULL) + if (ptr != NULL) { memset(ptr, 0, size); + } LOCK(&alloclock); - if (pk11_mctx != NULL) + if (pk11_mctx != NULL) { isc_mem_put(pk11_mctx, ptr, size); - else { - if (ptr != NULL) + } else { + if (ptr != NULL) { allocsize -= (int)size; + } free(ptr); } UNLOCK(&alloclock); @@ -198,8 +202,9 @@ pk11_initialize(isc_mem_t *mctx, const char *engine) LOCK(&sessionlock); LOCK(&alloclock); - if ((mctx != NULL) && (pk11_mctx == NULL) && (allocsize == 0)) + if ((mctx != NULL) && (pk11_mctx == NULL) && (allocsize == 0)) { isc_mem_attach(mctx, &pk11_mctx); + } UNLOCK(&alloclock); if (initialized) { goto unlock; @@ -210,8 +215,9 @@ pk11_initialize(isc_mem_t *mctx, const char *engine) ISC_LIST_INIT(tokens); ISC_LIST_INIT(actives); - if (engine != NULL) + if (engine != NULL) { lib_name = engine; + } /* Initialize the CRYPTOKI library */ rv = pkcs_C_Initialize((CK_VOID_PTR)&pk11_init_args); @@ -260,8 +266,9 @@ pk11_finalize(void) pk11_mem_put(token, sizeof(*token)); token = next; } - if (pk11_mctx != NULL) + if (pk11_mctx != NULL) { isc_mem_detach(&pk11_mctx); + } initialized = false; return (ret); } @@ -281,8 +288,9 @@ pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype, bool need_services, ctx->session = CK_INVALID_HANDLE; ret = pk11_initialize(NULL, NULL); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { return (ret); + } LOCK(&sessionlock); /* wait for initialization to finish */ @@ -306,13 +314,15 @@ pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype, bool need_services, } break; } - if (token == NULL) + if (token == NULL) { return (ISC_R_NOTFOUND); + } /* Override the token's PIN */ if (logon && pin != NULL && *pin != '\0') { - if (strlen(pin) > PINLEN) + if (strlen(pin) > PINLEN) { return (ISC_R_RANGE); + } /* * We want to zero out the old pin before * overwriting with a new one. @@ -329,8 +339,9 @@ pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype, bool need_services, ISC_LIST_UNLINK(*freelist, sp, link); ISC_LIST_APPEND(actives, sp, link); UNLOCK(&sessionlock); - if (logon) + if (logon) { ret = token_login(sp); + } ctx->handle = sp; ctx->session = sp->session; return (ret); @@ -343,8 +354,9 @@ pk11_get_session(pk11_context_t *ctx, pk11_optype_t optype, bool need_services, sp->session = CK_INVALID_HANDLE; ISC_LINK_INIT(sp, link); ret = setup_session(sp, token, rw); - if ((ret == ISC_R_SUCCESS) && logon) + if ((ret == ISC_R_SUCCESS) && logon) { ret = token_login(sp); + } LOCK(&sessionlock); ISC_LIST_APPEND(actives, sp, link); UNLOCK(&sessionlock); @@ -358,8 +370,9 @@ pk11_return_session(pk11_context_t *ctx) { pk11_session_t *sp = (pk11_session_t *)ctx->handle; - if (sp == NULL) + if (sp == NULL) { return; + } ctx->handle = NULL; ctx->session = CK_INVALID_HANDLE; @@ -386,14 +399,16 @@ free_all_sessions(void) for (token = ISC_LIST_HEAD(tokens); token != NULL; token = ISC_LIST_NEXT(token, link)) { oret = free_session_list(&token->sessions); - if (oret != ISC_R_SUCCESS) + if (oret != ISC_R_SUCCESS) { ret = oret; + } } if (!ISC_LIST_EMPTY(actives)) { ret = ISC_R_ADDRINUSE; oret = free_session_list(&actives); - if (oret != ISC_R_SUCCESS) + if (oret != ISC_R_SUCCESS) { ret = oret; + } } return (ret); } @@ -413,8 +428,9 @@ free_session_list(pk11_sessionlist_t *slist) UNLOCK(&sessionlock); if (sp->session != CK_INVALID_HANDLE) { rv = pkcs_C_CloseSession(sp->session); - if (rv != CKR_OK) + if (rv != CKR_OK) { ret = DST_R_CRYPTOFAILURE; + } } LOCK(&sessionlock); pk11_mem_put(sp, sizeof(*sp)); @@ -430,13 +446,15 @@ setup_session(pk11_session_t *sp, pk11_token_t *token, bool rw) CK_RV rv; CK_FLAGS flags = CKF_SERIAL_SESSION; - if (rw) + if (rw) { flags += CKF_RW_SESSION; + } rv = pkcs_C_OpenSession(token->slotid, flags, NULL_PTR, NULL_PTR, &sp->session); - if (rv != CKR_OK) + if (rv != CKR_OK) { return (DST_R_CRYPTOFAILURE); + } return (ISC_R_SUCCESS); } @@ -456,11 +474,12 @@ token_login(pk11_session_t *sp) #if PK11_NO_LOGERR pk11_error_fatalcheck(__FILE__, __LINE__, "pkcs_C_Login", rv); -#else +#else /* if PK11_NO_LOGERR */ ret = ISC_R_NOPERM; -#endif - } else +#endif /* if PK11_NO_LOGERR */ + } else { token->logged = true; + } } UNLOCK(&sessionlock); return (ret); @@ -496,8 +515,9 @@ scan_slots(void) PK11_FATALCHECK(pkcs_C_GetSlotList, (CK_FALSE, NULL_PTR, &slotCount)); PK11_TRACE1("slotCount=%lu\n", slotCount); /* it's not an error if we didn't find any providers */ - if (slotCount == 0) + if (slotCount == 0) { return; + } slotList = pk11_mem_get(sizeof(CK_SLOT_ID) * slotCount); PK11_FATALCHECK(pkcs_C_GetSlotList, (CK_FALSE, slotList, &slotCount)); @@ -506,8 +526,9 @@ scan_slots(void) PK11_TRACE2("slot#%u=0x%lx\n", i, slot); rv = pkcs_C_GetTokenInfo(slot, &tokenInfo); - if (rv != CKR_OK) + if (rv != CKR_OK) { continue; + } token = pk11_mem_get(sizeof(*token)); token->magic = TOK_MAGIC; token->slotid = slot; @@ -613,7 +634,8 @@ scan_slots(void) best_eddsa_token = token; } } -#endif +#endif /* if defined(CKM_EDDSA_KEY_PAIR_GEN) && defined(CKM_EDDSA) && \ + * defined(CKK_EDDSA) */ } if (slotList != NULL) { @@ -648,8 +670,9 @@ pk11_numbits(CK_BYTE_PTR data, unsigned int bytecnt) unsigned int bitcnt, i; CK_BYTE top; - if (bytecnt == 0) + if (bytecnt == 0) { return (0); + } bitcnt = bytecnt * 8; for (i = 0; i < bytecnt; i++) { top = data[i]; @@ -657,22 +680,30 @@ pk11_numbits(CK_BYTE_PTR data, unsigned int bytecnt) bitcnt -= 8; continue; } - if (top & 0x80) + if (top & 0x80) { return (bitcnt); - if (top & 0x40) + } + if (top & 0x40) { return (bitcnt - 1); - if (top & 0x20) + } + if (top & 0x20) { return (bitcnt - 2); - if (top & 0x10) + } + if (top & 0x10) { return (bitcnt - 3); - if (top & 0x08) + } + if (top & 0x08) { return (bitcnt - 4); - if (top & 0x04) + } + if (top & 0x04) { return (bitcnt - 5); - if (top & 0x02) + } + if (top & 0x02) { return (bitcnt - 6); - if (top & 0x01) + } + if (top & 0x01) { return (bitcnt - 7); + } break; } INSIST(0); @@ -691,8 +722,9 @@ pk11_attribute_next(const pk11_object_t *obj, CK_ATTRIBUTE *attr) CK_ATTRIBUTE *next; next = attr + 1; - if ((next - obj->repr) >= obj->attrcnt) + if ((next - obj->repr) >= obj->attrcnt) { return (NULL); + } return (next); } @@ -805,8 +837,9 @@ pk11strcmp(const char *x, size_t lenx, const char *y, size_t leny) INSIST((leny == 32) || (leny == 16)); memset(buf, ' ', 32); - if (lenx > leny) + if (lenx > leny) { lenx = leny; + } memmove(buf, x, lenx); return (memcmp(buf, y, leny) == 0); } @@ -863,11 +896,13 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx, /* get the URI scheme */ p = strchr(uri, ':'); - if (p == NULL) + if (p == NULL) { DST_RET(PK11_R_NOPROVIDER); + } *p++ = '\0'; - if (strcmp(uri, "pkcs11") != 0) + if (strcmp(uri, "pkcs11") != 0) { DST_RET(PK11_R_NOPROVIDER); + } /* get attributes */ for (na = p; na != NULL;) { @@ -884,25 +919,29 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx, if (p != NULL) { *p++ = '\0'; v = p; - } else + } else { v = a; + } l = 0; v = percent_decode(v, &l); - if (v == NULL) + if (v == NULL) { DST_RET(PK11_R_NOPROVIDER); + } if ((a == v) || (strcmp(a, "object") == 0)) { /* object: CKA_LABEL */ attr = pk11_attribute_bytype(obj, CKA_LABEL); - if (attr != NULL) + if (attr != NULL) { DST_RET(PK11_R_NOPROVIDER); + } attr = push_attribute(obj, mctx, l); - if (attr == NULL) + if (attr == NULL) { DST_RET(ISC_R_NOMEMORY); + } attr->type = CKA_LABEL; memmove(attr->pValue, v, l); } else if (strcmp(a, "token") == 0) { /* token: CK_TOKEN_INFO label */ - if (token == NULL) + if (token == NULL) { for (token = ISC_LIST_HEAD(tokens); token != NULL; token = ISC_LIST_NEXT(token, link)) { @@ -910,36 +949,43 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx, break; } } + } } else if (strcmp(a, "manufacturer") == 0) { /* manufacturer: CK_TOKEN_INFO manufacturerID */ - if (token == NULL) + if (token == NULL) { for (token = ISC_LIST_HEAD(tokens); token != NULL; token = ISC_LIST_NEXT(token, link)) { - if (pk11strcmp(v, l, token->manuf, 32)) { + if (pk11strcmp(v, l, token->manuf, + 32)) { break; } } + } } else if (strcmp(a, "serial") == 0) { /* serial: CK_TOKEN_INFO serialNumber */ - if (token == NULL) + if (token == NULL) { for (token = ISC_LIST_HEAD(tokens); token != NULL; token = ISC_LIST_NEXT(token, link)) { - if (pk11strcmp(v, l, token->serial, 16)) { + if (pk11strcmp(v, l, token->serial, + 16)) { break; } } + } } else if (strcmp(a, "model") == 0) { /* model: CK_TOKEN_INFO model */ - if (token == NULL) + if (token == NULL) { for (token = ISC_LIST_HEAD(tokens); token != NULL; token = ISC_LIST_NEXT(token, link)) { - if (pk11strcmp(v, l, token->model, 16)) { + if (pk11strcmp(v, l, token->model, + 16)) { break; } } + } } else if (strcmp(a, "library-manufacturer") == 0) { /* ignored */ } else if (strcmp(a, "library-description") == 0) { @@ -949,41 +995,50 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx, } else if (strcmp(a, "object-type") == 0) { /* object-type: CKA_CLASS */ /* only private makes sense */ - if (strcmp(v, "private") != 0) + if (strcmp(v, "private") != 0) { DST_RET(PK11_R_NOPROVIDER); + } } else if (strcmp(a, "id") == 0) { /* id: CKA_ID */ attr = pk11_attribute_bytype(obj, CKA_ID); - if (attr != NULL) + if (attr != NULL) { DST_RET(PK11_R_NOPROVIDER); + } attr = push_attribute(obj, mctx, l); - if (attr == NULL) + if (attr == NULL) { DST_RET(ISC_R_NOMEMORY); + } attr->type = CKA_ID; memmove(attr->pValue, v, l); } else if (strcmp(a, "pin-source") == 0) { /* pin-source: PIN */ ret = isc_stdio_open(v, "r", &stream); - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } memset(pin, 0, PINLEN + 1); ret = isc_stdio_read(pin, 1, PINLEN + 1, stream, &l); - if ((ret != ISC_R_SUCCESS) && (ret != ISC_R_EOF)) + if ((ret != ISC_R_SUCCESS) && (ret != ISC_R_EOF)) { goto err; - if (l > PINLEN) + } + if (l > PINLEN) { DST_RET(ISC_R_RANGE); + } ret = isc_stdio_close(stream); stream = NULL; - if (ret != ISC_R_SUCCESS) + if (ret != ISC_R_SUCCESS) { goto err; + } gotpin = true; - } else + } else { DST_RET(PK11_R_NOPROVIDER); + } } if ((pk11_attribute_bytype(obj, CKA_LABEL) == NULL) && - (pk11_attribute_bytype(obj, CKA_ID) == NULL)) + (pk11_attribute_bytype(obj, CKA_ID) == NULL)) { DST_RET(ISC_R_NOTFOUND); + } if (token == NULL) { if (optype == OP_RSA) { @@ -994,8 +1049,9 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx, token = best_eddsa_token; } } - if (token == NULL) + if (token == NULL) { DST_RET(ISC_R_NOTFOUND); + } obj->slot = token->slotid; if (gotpin) { memmove(token->pin, pin, PINLEN + 1); @@ -1005,8 +1061,9 @@ pk11_parse_uri(pk11_object_t *obj, const char *label, isc_mem_t *mctx, ret = ISC_R_SUCCESS; err: - if (stream != NULL) + if (stream != NULL) { (void)isc_stdio_close(stream); + } isc_mem_put(mctx, uri, len); return (ret); } @@ -1046,8 +1103,9 @@ pk11_dump_tokens(void) printf("RSA"); } if (token->operations & (1 << OP_ECDSA)) { - if (!first) + if (!first) { printf(","); + } printf("EC"); } printf(")\n"); diff --git a/lib/isc/pool.c b/lib/isc/pool.c index 34dc70d1e6..abd0a1471b 100644 --- a/lib/isc/pool.c +++ b/lib/isc/pool.c @@ -67,8 +67,9 @@ isc_pool_create(isc_mem_t *mctx, unsigned int count, /* Allocate the pool structure */ result = alloc_pool(mctx, count, &pool); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } pool->free = release; pool->init = init; @@ -117,8 +118,9 @@ isc_pool_expand(isc_pool_t **sourcep, unsigned int count, isc_pool_t **targetp) /* Allocate a new pool structure */ result = alloc_pool(pool->mctx, count, &newpool); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } newpool->free = pool->free; newpool->init = pool->init; @@ -155,8 +157,9 @@ isc_pool_destroy(isc_pool_t **poolp) isc_pool_t * pool = *poolp; *poolp = NULL; for (i = 0; i < pool->count; i++) { - if (pool->free != NULL && pool->pool[i] != NULL) + if (pool->free != NULL && pool->pool[i] != NULL) { pool->free(&pool->pool[i]); + } } isc_mem_put(pool->mctx, pool->pool, pool->count * sizeof(void *)); isc_mem_putanddetach(&pool->mctx, pool, sizeof(*pool)); diff --git a/lib/isc/pthreads/condition.c b/lib/isc/pthreads/condition.c index 5c1b60bc0c..d86e0f4c01 100644 --- a/lib/isc/pthreads/condition.c +++ b/lib/isc/pthreads/condition.c @@ -38,10 +38,11 @@ isc_condition_waituntil(isc_condition_t *c, isc_mutex_t *m, isc_time_t *t) * If we have a range error ts.tv_sec is most probably a signed * 32 bit value. Set ts.tv_sec to INT_MAX. This is a kludge. */ - if (result == ISC_R_RANGE) + if (result == ISC_R_RANGE) { ts.tv_sec = INT_MAX; - else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { return (result); + } /*! * POSIX defines a timespec's tv_nsec as long. isc_time_nanoseconds @@ -52,13 +53,15 @@ isc_condition_waituntil(isc_condition_t *c, isc_mutex_t *m, isc_time_t *t) do { #if ISC_MUTEX_PROFILE presult = pthread_cond_timedwait(c, &m->mutex, &ts); -#else +#else /* if ISC_MUTEX_PROFILE */ presult = pthread_cond_timedwait(c, m, &ts); -#endif - if (presult == 0) +#endif /* if ISC_MUTEX_PROFILE */ + if (presult == 0) { return (ISC_R_SUCCESS); - if (presult == ETIMEDOUT) + } + if (presult == ETIMEDOUT) { return (ISC_R_TIMEDOUT); + } } while (presult == EINTR); strerror_r(presult, strbuf, sizeof(strbuf)); diff --git a/lib/isc/pthreads/include/isc/condition.h b/lib/isc/pthreads/include/isc/condition.h index 7d9c9443fc..4bb45d0e6e 100644 --- a/lib/isc/pthreads/include/isc/condition.h +++ b/lib/isc/pthreads/include/isc/condition.h @@ -39,11 +39,11 @@ typedef pthread_cond_t isc_condition_t; #define isc_condition_wait(cp, mp) \ ((pthread_cond_wait((cp), &((mp)->mutex)) == 0) ? ISC_R_SUCCESS \ : ISC_R_UNEXPECTED) -#else +#else /* if ISC_MUTEX_PROFILE */ #define isc_condition_wait(cp, mp) \ ((pthread_cond_wait((cp), (mp)) == 0) ? ISC_R_SUCCESS \ : ISC_R_UNEXPECTED) -#endif +#endif /* if ISC_MUTEX_PROFILE */ #define isc_condition_signal(cp) \ ((pthread_cond_signal((cp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED) diff --git a/lib/isc/pthreads/include/isc/mutex.h b/lib/isc/pthreads/include/isc/mutex.h index 1cc80824eb..d4488e2876 100644 --- a/lib/isc/pthreads/include/isc/mutex.h +++ b/lib/isc/pthreads/include/isc/mutex.h @@ -30,9 +30,11 @@ ISC_LANG_BEGINDECLS #if ISC_MUTEX_DEBUG && defined(__NetBSD__) && defined(PTHREAD_MUTEX_ERRORCHECK) extern pthread_mutexattr_t isc__mutex_attrs; #define ISC__MUTEX_ATTRS &isc__mutex_attrs -#else +#else /* if ISC_MUTEX_DEBUG && defined(__NetBSD__) && \ + * defined(PTHREAD_MUTEX_ERRORCHECK) */ #define ISC__MUTEX_ATTRS NULL -#endif +#endif /* if ISC_MUTEX_DEBUG && defined(__NetBSD__) && \ + * defined(PTHREAD_MUTEX_ERRORCHECK) */ /* XXX We could do fancier error handling... */ @@ -44,7 +46,7 @@ extern pthread_mutexattr_t isc__mutex_attrs; */ #ifndef ISC_MUTEX_PROFILE #define ISC_MUTEX_PROFILE 0 -#endif +#endif /* ifndef ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE typedef struct isc_mutexstats isc_mutexstats_t; @@ -53,57 +55,57 @@ typedef struct { pthread_mutex_t mutex; /*%< The actual mutex. */ isc_mutexstats_t *stats; /*%< Mutex statistics. */ } isc_mutex_t; -#else +#else /* if ISC_MUTEX_PROFILE */ typedef pthread_mutex_t isc_mutex_t; -#endif +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE #define isc_mutex_init(mp) isc_mutex_init_profile((mp), __FILE__, __LINE__) -#else +#else /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK) #define isc_mutex_init(mp) isc_mutex_init_errcheck((mp)) -#else +#else /* if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK) */ #define isc_mutex_init(mp) isc__mutex_init((mp), __FILE__, __LINE__) void isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line); -#endif -#endif +#endif /* if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK) */ +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE #define isc_mutex_lock(mp) isc_mutex_lock_profile((mp), __FILE__, __LINE__) -#else +#else /* if ISC_MUTEX_PROFILE */ #define isc_mutex_lock(mp) \ ((pthread_mutex_lock((mp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED) -#endif +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE #define isc_mutex_unlock(mp) isc_mutex_unlock_profile((mp), __FILE__, __LINE__) -#else +#else /* if ISC_MUTEX_PROFILE */ #define isc_mutex_unlock(mp) \ ((pthread_mutex_unlock((mp)) == 0) ? ISC_R_SUCCESS : ISC_R_UNEXPECTED) -#endif +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE #define isc_mutex_trylock(mp) \ ((pthread_mutex_trylock((&(mp)->mutex)) == 0) ? ISC_R_SUCCESS \ : ISC_R_LOCKBUSY) -#else +#else /* if ISC_MUTEX_PROFILE */ #define isc_mutex_trylock(mp) \ ((pthread_mutex_trylock((mp)) == 0) ? ISC_R_SUCCESS : ISC_R_LOCKBUSY) -#endif +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE #define isc_mutex_destroy(mp) \ RUNTIME_CHECK(pthread_mutex_destroy((&(mp)->mutex)) == 0) -#else +#else /* if ISC_MUTEX_PROFILE */ #define isc_mutex_destroy(mp) RUNTIME_CHECK(pthread_mutex_destroy((mp)) == 0) -#endif +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE #define isc_mutex_stats(fp) isc_mutex_statsprofile(fp); -#else +#else /* if ISC_MUTEX_PROFILE */ #define isc_mutex_stats(fp) -#endif +#endif /* if ISC_MUTEX_PROFILE */ #if ISC_MUTEX_PROFILE diff --git a/lib/isc/pthreads/include/isc/thread.h b/lib/isc/pthreads/include/isc/thread.h index ec1d08915b..79f3e96ce2 100644 --- a/lib/isc/pthreads/include/isc/thread.h +++ b/lib/isc/pthreads/include/isc/thread.h @@ -18,7 +18,7 @@ #if defined(HAVE_PTHREAD_NP_H) #include -#endif +#endif /* if defined(HAVE_PTHREAD_NP_H) */ #include #include diff --git a/lib/isc/pthreads/mutex.c b/lib/isc/pthreads/mutex.c index e25885115c..5545d55575 100644 --- a/lib/isc/pthreads/mutex.c +++ b/lib/isc/pthreads/mutex.c @@ -74,7 +74,7 @@ struct isc_mutexstats { #ifndef ISC_MUTEX_PROFTABLESIZE #define ISC_MUTEX_PROFTABLESIZE (1024 * 1024) -#endif +#endif /* ifndef ISC_MUTEX_PROFTABLESIZE */ static isc_mutexstats_t stats[ISC_MUTEX_PROFTABLESIZE]; static int stats_next = 0; static bool stats_init = false; @@ -94,8 +94,9 @@ isc_mutex_init_profile(isc_mutex_t *mp, const char *file, int line) RUNTIME_CHECK(pthread_mutex_lock(&statslock) == 0); - if (stats_init == false) + if (stats_init == false) { stats_init = true; + } /* * If all statistics entries have been used, give up and trigger an @@ -134,8 +135,9 @@ isc_mutex_lock_profile(isc_mutex_t *mp, const char *file, int line) gettimeofday(&prelock_t, NULL); - if (pthread_mutex_lock(&mp->mutex) != 0) + if (pthread_mutex_lock(&mp->mutex) != 0) { return (ISC_R_UNEXPECTED); + } gettimeofday(&postlock_t, NULL); mp->stats->lock_t = postlock_t; @@ -204,8 +206,9 @@ isc_mutex_statsprofile(FILE *fp) i); for (j = 0; j < ISC_MUTEX_MAX_LOCKERS; j++) { locker = &stats[i].lockers[j]; - if (locker->file == NULL) + if (locker->file == NULL) { continue; + } fprintf(fp, " %-11s %4d: %10u %lu.%06lu %lu.%06lu %5d\n", locker->file, locker->line, locker->count, @@ -250,14 +253,15 @@ isc_mutex_init_errcheck(isc_mutex_t *mp) strbuf); } } -#endif +#endif /* if ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK) */ #if ISC_MUTEX_DEBUG && defined(__NetBSD__) && defined(PTHREAD_MUTEX_ERRORCHECK) pthread_mutexattr_t isc__mutex_attrs = { PTHREAD_MUTEX_ERRORCHECK, /* m_type */ 0 /* m_flags, which appears to be unused. */ }; -#endif +#endif /* if ISC_MUTEX_DEBUG && defined(__NetBSD__) && \ + * defined(PTHREAD_MUTEX_ERRORCHECK) */ #if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)) && \ !ISC_MUTEX_PROFILE @@ -300,4 +304,5 @@ isc__mutex_init(isc_mutex_t *mp, const char *file, unsigned int line) strbuf); } } -#endif +#endif /* if !(ISC_MUTEX_DEBUG && defined(PTHREAD_MUTEX_ERRORCHECK)) && \ + * !ISC_MUTEX_PROFILE */ diff --git a/lib/isc/pthreads/thread.c b/lib/isc/pthreads/thread.c index da0b8da32f..d7e6e23ac2 100644 --- a/lib/isc/pthreads/thread.c +++ b/lib/isc/pthreads/thread.c @@ -13,18 +13,18 @@ #if defined(HAVE_SCHED_H) #include -#endif +#endif /* if defined(HAVE_SCHED_H) */ #if defined(HAVE_CPUSET_H) #include #include -#endif +#endif /* if defined(HAVE_CPUSET_H) */ #if defined(HAVE_SYS_PROCSET_H) #include #include #include -#endif +#endif /* if defined(HAVE_SYS_PROCSET_H) */ #include #include @@ -32,7 +32,7 @@ #ifndef THREAD_MINSTACKSIZE #define THREAD_MINSTACKSIZE (1024U * 1024) -#endif +#endif /* ifndef THREAD_MINSTACKSIZE */ #define _FATAL(r, f) \ { \ @@ -49,7 +49,8 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg, #if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \ defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) size_t stacksize; -#endif +#endif /* if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \ + * defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) */ int ret; pthread_attr_init(&attr); @@ -67,7 +68,8 @@ isc_thread_create(isc_threadfunc_t func, isc_threadarg_t arg, _FATAL(ret, "pthread_attr_setstacksize()"); } } -#endif +#endif /* if defined(HAVE_PTHREAD_ATTR_GETSTACKSIZE) && \ + * defined(HAVE_PTHREAD_ATTR_SETSTACKSIZE) */ ret = pthread_create(thread, &attr, func, arg); if (ret != 0) { @@ -90,7 +92,7 @@ isc_thread_join(isc_thread_t thread, isc_threadresult_t *result) #ifdef __NetBSD__ #define pthread_setconcurrency(a) (void)a /* nothing */ -#endif +#endif /* ifdef __NetBSD__ */ void isc_thread_setconcurrency(unsigned int level) @@ -108,15 +110,15 @@ isc_thread_setname(isc_thread_t thread, const char *name) */ #if defined(__NetBSD__) (void)pthread_setname_np(thread, name, NULL); -#else +#else /* if defined(__NetBSD__) */ (void)pthread_setname_np(thread, name); -#endif +#endif /* if defined(__NetBSD__) */ #elif defined(HAVE_PTHREAD_SET_NAME_NP) (void)pthread_set_name_np(thread, name); -#else +#else /* if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) */ UNUSED(thread); UNUSED(name); -#endif +#endif /* if defined(HAVE_PTHREAD_SETNAME_NP) && !defined(__APPLE__) */ } void @@ -128,7 +130,7 @@ isc_thread_yield(void) pthread_yield(); #elif defined(HAVE_PTHREAD_YIELD_NP) pthread_yield_np(); -#endif +#endif /* if defined(HAVE_SCHED_YIELD) */ } isc_result_t @@ -146,8 +148,9 @@ isc_thread_setaffinity(int cpu) #if defined(__NetBSD__) cpuset_t *cset; cset = cpuset_create(); - if (cset == NULL) + if (cset == NULL) { return (ISC_R_FAILURE); + } cpuset_set(cpu, cset); if (pthread_setaffinity_np(pthread_self(), cpuset_size(cset), cset) != 0) { @@ -168,8 +171,8 @@ isc_thread_setaffinity(int cpu) if (processor_bind(P_LWPID, P_MYID, cpu, NULL) != 0) { return (ISC_R_FAILURE); } -#else +#else /* if defined(HAVE_CPUSET_SETAFFINITY) */ UNUSED(cpu); -#endif +#endif /* if defined(HAVE_CPUSET_SETAFFINITY) */ return (ISC_R_SUCCESS); } diff --git a/lib/isc/radix.c b/lib/isc/radix.c index c1250c804b..216309707c 100644 --- a/lib/isc/radix.c +++ b/lib/isc/radix.c @@ -48,8 +48,9 @@ _new_prefix(isc_mem_t *mctx, isc_prefix_t **target, int family, void *dest, REQUIRE(target != NULL); - if (family != AF_INET6 && family != AF_INET && family != AF_UNSPEC) + if (family != AF_INET6 && family != AF_INET && family != AF_UNSPEC) { return (ISC_R_NOTIMPLEMENTED); + } prefix = isc_mem_get(mctx, sizeof(isc_prefix_t)); @@ -115,16 +116,18 @@ static int _comp_with_mask(void *addr, void *dest, u_int mask) { /* Mask length of zero matches everything */ - if (mask == 0) + if (mask == 0) { return (1); + } if (memcmp(addr, dest, mask / 8) == 0) { u_int n = mask / 8; u_int m = ((~0U) << (8 - (mask % 8))); if ((mask % 8) == 0 || - (((u_char *)addr)[n] & m) == (((u_char *)dest)[n] & m)) + (((u_char *)addr)[n] & m) == (((u_char *)dest)[n] & m)) { return (1); + } } return (0); } @@ -171,8 +174,9 @@ _clear_radix(isc_radix_tree_t *radix, isc_radix_destroyfunc_t func) if (Xrn->prefix != NULL) { _deref_prefix(Xrn->prefix); - if (func != NULL) + if (func != NULL) { func(Xrn->data); + } } else { INSIST(Xrn->data[RADIX_V4] == NULL && Xrn->data[RADIX_V6] == NULL); @@ -246,26 +250,32 @@ isc_radix_search(isc_radix_tree_t *radix, isc_radix_node_t **target, bitlen = prefix->bitlen; while (node->bit < bitlen) { - if (node->prefix) + if (node->prefix) { stack[cnt++] = node; + } - if (BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) + if (BIT_TEST(addr[node->bit >> 3], + 0x80 >> (node->bit & 0x07))) { node = node->r; - else + } else { node = node->l; + } - if (node == NULL) + if (node == NULL) { break; + } } - if (node && node->prefix) + if (node && node->prefix) { stack[cnt++] = node; + } while (cnt-- > 0) { node = stack[cnt]; - if (prefix->bitlen < node->bit) + if (prefix->bitlen < node->bit) { continue; + } if (_comp_with_mask(isc_prefix_tochar(node->prefix), isc_prefix_tochar(prefix), @@ -302,8 +312,9 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, REQUIRE(prefix != NULL || (source != NULL && source->prefix != NULL)); RUNTIME_CHECK(prefix == NULL || prefix->bitlen <= radix->maxbits); - if (prefix == NULL) + if (prefix == NULL) { prefix = source->prefix; + } INSIST(prefix != NULL); @@ -368,12 +379,14 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, if (node->bit < radix->maxbits && BIT_TEST(addr[node->bit >> 3], 0x80 >> (node->bit & 0x07))) { - if (node->r == NULL) + if (node->r == NULL) { break; + } node = node->r; } else { - if (node->l == NULL) + if (node->l == NULL) { break; + } node = node->l; } @@ -393,8 +406,9 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, } /* I know the better way, but for now. */ for (j = 0; j < 8; j++) { - if (BIT_TEST(r, (0x80 >> j))) + if (BIT_TEST(r, (0x80 >> j))) { break; + } } /* Must be found. */ INSIST(j < 8); @@ -402,8 +416,9 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, break; } - if (differ_bit > check_bit) + if (differ_bit > check_bit) { differ_bit = check_bit; + } parent = node->parent; while (parent != NULL && parent->bit >= differ_bit) { @@ -450,8 +465,9 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, } else { result = _ref_prefix(radix->mctx, &node->prefix, prefix); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } INSIST(node->data[RADIX_V4] == NULL && node->node_num[RADIX_V4] == -1 && @@ -491,9 +507,10 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, result = _ref_prefix(radix->mctx, &new_node->prefix, prefix); if (result != ISC_R_SUCCESS) { isc_mem_put(radix->mctx, new_node, sizeof(isc_radix_node_t)); - if (glue != NULL) + if (glue != NULL) { isc_mem_put(radix->mctx, glue, sizeof(isc_radix_node_t)); + } return (result); } new_node->parent = NULL; @@ -518,8 +535,9 @@ isc_radix_insert(isc_radix_tree_t *radix, isc_radix_node_t **target, int next = ++radix->num_added_node; if (fam == AF_UNSPEC) { /* "any" or "none" */ - for (i = 0; i < RADIX_FAMILIES; i++) + for (i = 0; i < RADIX_FAMILIES; i++) { new_node->node_num[i] = next; + } } else { new_node->node_num[ISC_RADIX_FAMILY(prefix)] = next; } @@ -609,8 +627,9 @@ isc_radix_remove(isc_radix_tree_t *radix, isc_radix_node_t *node) * This might be a placeholder node -- have to check and * make sure there is a prefix associated with it! */ - if (node->prefix != NULL) + if (node->prefix != NULL) { _deref_prefix(node->prefix); + } node->prefix = NULL; memset(node->data, 0, sizeof(node->data)); @@ -641,8 +660,9 @@ isc_radix_remove(isc_radix_tree_t *radix, isc_radix_node_t *node) isc_mem_put(radix->mctx, node, sizeof(*node)); radix->num_active_node--; - if (parent->prefix) + if (parent->prefix) { return; + } /* We need to remove parent too. */ if (parent->parent == NULL) { diff --git a/lib/isc/random.c b/lib/isc/random.c index 90b8e079b1..c8d87832c0 100644 --- a/lib/isc/random.c +++ b/lib/isc/random.c @@ -72,9 +72,9 @@ isc_random_initialize(void) * find a crash or a hang. The seed array must be non-zero else * xoshiro128starstar will generate an infinite series of zeroes. */ -#else +#else /* if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ isc_entropy_get(useed, sizeof(useed)); -#endif +#endif /* if FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION */ memmove(seed, useed, sizeof(seed)); } diff --git a/lib/isc/ratelimiter.c b/lib/isc/ratelimiter.c index 2a87fbdbc4..4b91baf8a4 100644 --- a/lib/isc/ratelimiter.c +++ b/lib/isc/ratelimiter.c @@ -75,8 +75,9 @@ isc_ratelimiter_create(isc_mem_t *mctx, isc_timermgr_t *timermgr, result = isc_timer_create(timermgr, isc_timertype_inactive, NULL, NULL, rl->task, ratelimiter_tick, rl, &rl->timer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto free_mutex; + } /* * Increment the reference count to indicate that we may @@ -123,8 +124,9 @@ isc_ratelimiter_setpertic(isc_ratelimiter_t *rl, uint32_t pertic) { REQUIRE(rl != NULL); - if (pertic == 0) + if (pertic == 0) { pertic = 1; + } rl->pertic = pertic; } @@ -154,10 +156,11 @@ isc_ratelimiter_enqueue(isc_ratelimiter_t *rl, isc_task_t *task, rl->state == isc_ratelimiter_stalled) { ev->ev_sender = task; *eventp = NULL; - if (rl->pushpop) + if (rl->pushpop) { ISC_LIST_PREPEND(rl->pending, ev, ev_ratelink); - else + } else { ISC_LIST_APPEND(rl->pending, ev, ev_ratelink); + } } else if (rl->state == isc_ratelimiter_idle) { result = isc_timer_reset(rl->timer, isc_timertype_ticker, NULL, &rl->interval, false); @@ -170,8 +173,9 @@ isc_ratelimiter_enqueue(isc_ratelimiter_t *rl, isc_task_t *task, result = ISC_R_SHUTTINGDOWN; } UNLOCK(&rl->lock); - if (*eventp != NULL && result == ISC_R_SUCCESS) + if (*eventp != NULL && result == ISC_R_SUCCESS) { isc_task_send(task, eventp); + } return (result); } @@ -187,8 +191,9 @@ isc_ratelimiter_dequeue(isc_ratelimiter_t *rl, isc_event_t *event) if (ISC_LINK_LINKED(event, ev_ratelink)) { ISC_LIST_UNLINK(rl->pending, event, ev_ratelink); event->ev_sender = NULL; - } else + } else { result = ISC_R_NOTFOUND; + } UNLOCK(&rl->lock); return (result); } @@ -323,7 +328,7 @@ isc_ratelimiter_stall(isc_ratelimiter_t *rl) result = isc_timer_reset(rl->timer, isc_timertype_inactive, NULL, NULL, false); RUNTIME_CHECK(result == ISC_R_SUCCESS); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case isc_ratelimiter_idle: case isc_ratelimiter_stalled: rl->state = isc_ratelimiter_stalled; @@ -350,10 +355,12 @@ isc_ratelimiter_release(isc_ratelimiter_t *rl) result = isc_timer_reset(rl->timer, isc_timertype_ticker, NULL, &rl->interval, false); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { rl->state = isc_ratelimiter_ratelimited; - } else + } + } else { rl->state = isc_ratelimiter_idle; + } break; case isc_ratelimiter_ratelimited: case isc_ratelimiter_idle: diff --git a/lib/isc/regex.c b/lib/isc/regex.c index c00aa1fa73..a0fe003ff0 100644 --- a/lib/isc/regex.c +++ b/lib/isc/regex.c @@ -22,9 +22,9 @@ reason = (x); \ goto error; \ } while (0) -#else +#else /* if VALREGEX_REPORT_REASON */ #define FAIL(x) goto error -#endif +#endif /* if VALREGEX_REPORT_REASON */ /* * Validate the regular expression 'C' locale. @@ -60,10 +60,11 @@ isc_regex_validate(const char *c) int range_start = 0; #if VALREGEX_REPORT_REASON const char *reason = ""; -#endif +#endif /* if VALREGEX_REPORT_REASON */ - if (c == NULL || *c == 0) + if (c == NULL || *c == 0) { FAIL("empty string"); + } while (c != NULL && *c != 0) { switch (state) { @@ -81,8 +82,9 @@ isc_regex_validate(const char *c) case '7': case '8': case '9': - if ((*c - '0') > sub) + if ((*c - '0') > sub) { FAIL("bad back reference"); + } have_atom = true; was_multiple = false; break; @@ -112,10 +114,12 @@ isc_regex_validate(const char *c) case '7': case '8': case '9': - if (!have_atom) + if (!have_atom) { FAIL("no atom"); - if (was_multiple) + } + if (was_multiple) { FAIL("was multiple"); + } seen_comma = false; seen_high = false; low = high = 0; @@ -139,17 +143,20 @@ isc_regex_validate(const char *c) ++c; break; case ')': /* group end */ - if (group && !have_atom && !empty_ok) + if (group && !have_atom && !empty_ok) { FAIL("empty alternative"); + } have_atom = true; was_multiple = false; - if (group != 0) + if (group != 0) { --group; + } ++c; break; case '|': /* alternative seperator */ - if (!have_atom) + if (!have_atom) { FAIL("no atom"); + } have_atom = false; empty_ok = false; was_multiple = false; @@ -164,10 +171,12 @@ isc_regex_validate(const char *c) case '+': case '*': case '?': - if (was_multiple) + if (was_multiple) { FAIL("was multiple"); - if (!have_atom) + } + if (!have_atom) { FAIL("no atom"); + } have_atom = true; was_multiple = true; ++c; @@ -195,19 +204,22 @@ isc_regex_validate(const char *c) case '9': if (!seen_comma) { low = low * 10 + *c - '0'; - if (low > 255) + if (low > 255) { FAIL("lower bound too big"); + } } else { seen_high = true; high = high * 10 + *c - '0'; - if (high > 255) + if (high > 255) { FAIL("upper bound too big"); + } } ++c; break; case ',': - if (seen_comma) + if (seen_comma) { FAIL("multiple commas"); + } seen_comma = true; ++c; break; @@ -215,8 +227,9 @@ isc_regex_validate(const char *c) case '{': FAIL("non digit/comma"); case '}': - if (seen_high && low > high) + if (seen_high && low > high) { FAIL("bad parse bound"); + } seen_comma = false; state = none; ++c; @@ -226,18 +239,22 @@ isc_regex_validate(const char *c) case parse_bracket: switch (*c) { case '^': - if (seen_char || neg) + if (seen_char || neg) { goto inside; + } neg = true; ++c; break; case '-': - if (range == 2) + if (range == 2) { goto inside; - if (!seen_char) + } + if (!seen_char) { goto inside; - if (range == 1) + } + if (range == 1) { FAIL("bad range"); + } range = 2; ++c; break; @@ -245,24 +262,27 @@ isc_regex_validate(const char *c) ++c; switch (*c) { case '.': /* collating element */ - if (range != 0) + if (range != 0) { --range; + } ++c; state = parse_ce; seen_ce = false; break; case '=': /* equivalence class */ - if (range == 2) + if (range == 2) { FAIL("equivalence class in " "range"); + } ++c; state = parse_ec; seen_ec = false; break; case ':': /* character class */ - if (range == 2) + if (range == 2) { FAIL("character class in " "range"); + } ccname = c; ++c; state = parse_cc; @@ -271,10 +291,12 @@ isc_regex_validate(const char *c) seen_char = true; break; case ']': - if (!c[1] && !seen_char) + if (!c[1] && !seen_char) { FAIL("unfinished brace"); - if (!seen_char) + } + if (!seen_char) { goto inside; + } ++c; range = 0; have_atom = true; @@ -283,14 +305,16 @@ isc_regex_validate(const char *c) default: inside: seen_char = true; - if (range == 2 && (*c & 0xff) < range_start) + if (range == 2 && (*c & 0xff) < range_start) { FAIL("out of order range"); - if (range != 0) + } + if (range != 0) { --range; + } range_start = *c & 0xff; ++c; break; - }; + } break; case parse_ce: switch (*c) { @@ -298,25 +322,28 @@ isc_regex_validate(const char *c) ++c; switch (*c) { case ']': - if (!seen_ce) + if (!seen_ce) { FAIL("empty ce"); + } ++c; state = parse_bracket; break; default: - if (seen_ce) + if (seen_ce) { range_start = 256; - else + } else { range_start = '.'; + } seen_ce = true; break; } break; default: - if (seen_ce) + if (seen_ce) { range_start = 256; - else + } else { range_start = *c; + } seen_ce = true; ++c; break; @@ -328,8 +355,9 @@ isc_regex_validate(const char *c) ++c; switch (*c) { case ']': - if (!seen_ec) + if (!seen_ec) { FAIL("no ec"); + } ++c; state = parse_bracket; break; @@ -358,14 +386,19 @@ isc_regex_validate(const char *c) unsigned int len; len = strlen(cc[i]); if (len != - (unsigned int)(c - ccname)) + (unsigned int)(c - + ccname)) { continue; - if (strncmp(cc[i], ccname, len)) + } + if (strncmp(cc[i], ccname, + len)) { continue; + } found = true; } - if (!found) + if (!found) { FAIL("unknown cc"); + } ++c; state = parse_bracket; break; @@ -381,17 +414,20 @@ isc_regex_validate(const char *c) break; } } - if (group != 0) + if (group != 0) { FAIL("group open"); - if (state != none) + } + if (state != none) { FAIL("incomplete"); - if (!have_atom) + } + if (!have_atom) { FAIL("no atom"); + } return (sub); error: #if VALREGEX_REPORT_REASON fprintf(stderr, "%s\n", reason); -#endif +#endif /* if VALREGEX_REPORT_REASON */ return (-1); } diff --git a/lib/isc/region.c b/lib/isc/region.c index f9f8364f7e..7dab5be033 100644 --- a/lib/isc/region.c +++ b/lib/isc/region.c @@ -28,10 +28,11 @@ isc_region_compare(isc_region_t *r1, isc_region_t *r2) l = (r1->length < r2->length) ? r1->length : r2->length; - if ((result = memcmp(r1->base, r2->base, l)) != 0) + if ((result = memcmp(r1->base, r2->base, l)) != 0) { return ((result < 0) ? -1 : 1); - else + } else { return ((r1->length == r2->length) ? 0 : (r1->length < r2->length) ? -1 : 1); + } } diff --git a/lib/isc/result.c b/lib/isc/result.c index ee99926a85..c0f7cdc81d 100644 --- a/lib/isc/result.c +++ b/lib/isc/result.c @@ -199,8 +199,9 @@ register_table(resulttable_list_t *tables, unsigned int base, * isc_result_totext() even if there is no memory context. */ table = malloc(sizeof(*table)); - if (table == NULL) + if (table == NULL) { return (ISC_R_NOMEMORY); + } table->base = base; table->last = base + nresults - 1; table->text = text; diff --git a/lib/isc/rwlock.c b/lib/isc/rwlock.c index 4310f4953f..bc48a5a680 100644 --- a/lib/isc/rwlock.c +++ b/lib/isc/rwlock.c @@ -17,7 +17,7 @@ #if defined(sun) && (defined(__sparc) || defined(__sparc__)) #include /* for smt_pause(3c) */ -#endif +#endif /* if defined(sun) && (defined(__sparc) || defined(__sparc__)) */ #include #include @@ -56,8 +56,8 @@ isc_rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) if (atomic_load_acquire(&rwl->downgrade)) { REQUIRE(pthread_rwlock_unlock(&rwl->rwlock) == 0); - while (atomic_load_acquire(&rwl->downgrade)) - ; + while (atomic_load_acquire(&rwl->downgrade)) { + } continue; } break; @@ -132,22 +132,22 @@ isc_rwlock_destroy(isc_rwlock_t *rwl) pthread_rwlock_destroy(&rwl->rwlock); } -#else +#else /* if USE_PTHREAD_RWLOCK */ #define RWLOCK_MAGIC ISC_MAGIC('R', 'W', 'L', 'k') #define VALID_RWLOCK(rwl) ISC_MAGIC_VALID(rwl, RWLOCK_MAGIC) #ifndef RWLOCK_DEFAULT_READ_QUOTA #define RWLOCK_DEFAULT_READ_QUOTA 4 -#endif +#endif /* ifndef RWLOCK_DEFAULT_READ_QUOTA */ #ifndef RWLOCK_DEFAULT_WRITE_QUOTA #define RWLOCK_DEFAULT_WRITE_QUOTA 4 -#endif +#endif /* ifndef RWLOCK_DEFAULT_WRITE_QUOTA */ #ifndef RWLOCK_MAX_ADAPTIVE_COUNT #define RWLOCK_MAX_ADAPTIVE_COUNT 100 -#endif +#endif /* ifndef RWLOCK_MAX_ADAPTIVE_COUNT */ #if defined(_MSC_VER) #include @@ -168,9 +168,9 @@ isc_rwlock_destroy(isc_rwlock_t *rwl) #elif defined(__ppc__) || defined(_ARCH_PPC) || defined(_ARCH_PWR) || \ defined(_ARCH_PWR2) || defined(_POWER) #define isc_rwlock_pause() __asm__ volatile("or 27,27,27") -#else +#else /* if defined(_MSC_VER) */ #define isc_rwlock_pause() -#endif +#endif /* if defined(_MSC_VER) */ static isc_result_t isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type); @@ -219,8 +219,9 @@ isc_rwlock_init(isc_rwlock_t *rwl, unsigned int read_quota, UNEXPECTED_ERROR(__FILE__, __LINE__, "read quota is not supported"); } - if (write_quota == 0) + if (write_quota == 0) { write_quota = RWLOCK_DEFAULT_WRITE_QUOTA; + } rwl->write_quota = write_quota; isc_mutex_init(&rwl->lock); @@ -323,7 +324,7 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) #ifdef ISC_RWLOCK_TRACE print_lock("prelock", rwl, type); -#endif +#endif /* ifdef ISC_RWLOCK_TRACE */ if (type == isc_rwlocktype_read) { if (atomic_load_acquire(&rwl->write_requests) != @@ -430,7 +431,7 @@ isc__rwlock_lock(isc_rwlock_t *rwl, isc_rwlocktype_t type) #ifdef ISC_RWLOCK_TRACE print_lock("postlock", rwl, type); -#endif +#endif /* ifdef ISC_RWLOCK_TRACE */ return (ISC_R_SUCCESS); } @@ -465,13 +466,14 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) #ifdef ISC_RWLOCK_TRACE print_lock("prelock", rwl, type); -#endif +#endif /* ifdef ISC_RWLOCK_TRACE */ if (type == isc_rwlocktype_read) { /* If a writer is waiting or working, we fail. */ if (atomic_load_acquire(&rwl->write_requests) != - atomic_load_acquire(&rwl->write_completions)) + atomic_load_acquire(&rwl->write_completions)) { return (ISC_R_LOCKBUSY); + } /* Otherwise, be ready for reading. */ cntflag = atomic_fetch_add_release(&rwl->cnt_and_flag, @@ -515,7 +517,7 @@ isc_rwlock_trylock(isc_rwlock_t *rwl, isc_rwlocktype_t type) #ifdef ISC_RWLOCK_TRACE print_lock("postlock", rwl, type); -#endif +#endif /* ifdef ISC_RWLOCK_TRACE */ return (ISC_R_SUCCESS); } @@ -544,8 +546,9 @@ isc_rwlock_tryupgrade(isc_rwlock_t *rwl) * Now jump into the head of the writer waiting queue. */ atomic_fetch_sub_release(&rwl->write_completions, 1); - } else + } else { return (ISC_R_LOCKBUSY); + } } return (ISC_R_SUCCESS); @@ -585,7 +588,7 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) #ifdef ISC_RWLOCK_TRACE print_lock("preunlock", rwl, type); -#endif +#endif /* ifdef ISC_RWLOCK_TRACE */ if (type == isc_rwlocktype_read) { prev_cnt = atomic_fetch_sub_release(&rwl->cnt_and_flag, @@ -645,7 +648,7 @@ isc_rwlock_unlock(isc_rwlock_t *rwl, isc_rwlocktype_t type) #ifdef ISC_RWLOCK_TRACE print_lock("postunlock", rwl, type); -#endif +#endif /* ifdef ISC_RWLOCK_TRACE */ return (ISC_R_SUCCESS); } diff --git a/lib/isc/serial.c b/lib/isc/serial.c index 58c5dfe328..f4e8a91e67 100644 --- a/lib/isc/serial.c +++ b/lib/isc/serial.c @@ -22,8 +22,9 @@ isc_serial_lt(uint32_t a, uint32_t b) /* * Undefined => false */ - if (a == (b ^ 0x80000000U)) + if (a == (b ^ 0x80000000U)) { return (false); + } return (((int32_t)(a - b) < 0) ? true : false); } diff --git a/lib/isc/siphash.c b/lib/isc/siphash.c index b669414a22..e5d77bc0d0 100644 --- a/lib/isc/siphash.c +++ b/lib/isc/siphash.c @@ -26,28 +26,26 @@ #include void -isc_siphash24(const uint8_t *k, - const uint8_t *in, const size_t inlen, - uint8_t *out) +isc_siphash24(const uint8_t*k,const uint8_t*in,const size_t inlen,uint8_t*out) { REQUIRE(k != NULL); REQUIRE(out != NULL); size_t outlen = 8; - EVP_PKEY_CTX *pctx = NULL; + EVP_PKEY_CTX*pctx = NULL; - EVP_MD_CTX *mctx = EVP_MD_CTX_new(); - EVP_PKEY *key = EVP_PKEY_new_raw_private_key(EVP_PKEY_SIPHASH, NULL, - k, 16); + EVP_MD_CTX*mctx = EVP_MD_CTX_new(); + EVP_PKEY*key = EVP_PKEY_new_raw_private_key(EVP_PKEY_SIPHASH,NULL, + k,16); RUNTIME_CHECK(mctx != NULL); RUNTIME_CHECK(key != NULL); - RUNTIME_CHECK(EVP_DigestSignInit(mctx, &pctx, NULL, NULL, key) == 1); - RUNTIME_CHECK(EVP_PKEY_CTX_ctrl(pctx, EVP_PKEY_SIPHASH, + RUNTIME_CHECK(EVP_DigestSignInit(mctx,&pctx,NULL,NULL,key) == 1); + RUNTIME_CHECK(EVP_PKEY_CTX_ctrl(pctx,EVP_PKEY_SIPHASH, EVP_PKEY_OP_SIGNCTX, - EVP_PKEY_CTRL_SET_DIGEST_SIZE, outlen, + EVP_PKEY_CTRL_SET_DIGEST_SIZE,outlen, NULL) == 1); - RUNTIME_CHECK(EVP_DigestSignUpdate(mctx, in, inlen) == 1); - RUNTIME_CHECK(EVP_DigestSignFinal(mctx, out, &outlen) == 1); + RUNTIME_CHECK(EVP_DigestSignUpdate(mctx,in,inlen) == 1); + RUNTIME_CHECK(EVP_DigestSignFinal(mctx,out,&outlen) == 1); ENSURE(outlen == 8); @@ -144,25 +142,25 @@ isc_siphash24(const uint8_t *k, const uint8_t *in, const size_t inlen, switch (left) { case 7: b |= ((uint64_t)in[6]) << 48; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 6: b |= ((uint64_t)in[5]) << 40; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 5: b |= ((uint64_t)in[4]) << 32; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 4: b |= ((uint64_t)in[3]) << 24; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 3: b |= ((uint64_t)in[2]) << 16; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 2: b |= ((uint64_t)in[1]) << 8; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 1: b |= ((uint64_t)in[0]); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 0: break; default: diff --git a/lib/isc/sockaddr.c b/lib/isc/sockaddr.c index 0a1f294f52..4f55152e1b 100644 --- a/lib/isc/sockaddr.c +++ b/lib/isc/sockaddr.c @@ -15,7 +15,7 @@ #include #if defined(WIN32) || defined(WIN64) #include -#endif +#endif /* if defined(WIN32) || defined(WIN64) */ #include #include @@ -48,31 +48,36 @@ isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, { REQUIRE(a != NULL && b != NULL); - if (a->length != b->length) + if (a->length != b->length) { return (false); + } /* * We don't just memcmp because the sin_zero field isn't always * zero. */ - if (a->type.sa.sa_family != b->type.sa.sa_family) + if (a->type.sa.sa_family != b->type.sa.sa_family) { return (false); + } switch (a->type.sa.sa_family) { case AF_INET: if ((flags & ISC_SOCKADDR_CMPADDR) != 0 && memcmp(&a->type.sin.sin_addr, &b->type.sin.sin_addr, - sizeof(a->type.sin.sin_addr)) != 0) + sizeof(a->type.sin.sin_addr)) != 0) { return (false); + } if ((flags & ISC_SOCKADDR_CMPPORT) != 0 && - a->type.sin.sin_port != b->type.sin.sin_port) + a->type.sin.sin_port != b->type.sin.sin_port) { return (false); + } break; case AF_INET6: if ((flags & ISC_SOCKADDR_CMPADDR) != 0 && memcmp(&a->type.sin6.sin6_addr, &b->type.sin6.sin6_addr, - sizeof(a->type.sin6.sin6_addr)) != 0) + sizeof(a->type.sin6.sin6_addr)) != 0) { return (false); + } /* * If ISC_SOCKADDR_CMPSCOPEZERO is set then don't return * false if one of the scopes in zero. @@ -81,15 +86,18 @@ isc_sockaddr_compare(const isc_sockaddr_t *a, const isc_sockaddr_t *b, a->type.sin6.sin6_scope_id != b->type.sin6.sin6_scope_id && ((flags & ISC_SOCKADDR_CMPSCOPEZERO) == 0 || (a->type.sin6.sin6_scope_id != 0 && - b->type.sin6.sin6_scope_id != 0))) + b->type.sin6.sin6_scope_id != 0))) { return (false); + } if ((flags & ISC_SOCKADDR_CMPPORT) != 0 && - a->type.sin6.sin6_port != b->type.sin6.sin6_port) + a->type.sin6.sin6_port != b->type.sin6.sin6_port) { return (false); + } break; default: - if (memcmp(&a->type, &b->type, a->length) != 0) + if (memcmp(&a->type, &b->type, a->length) != 0) { return (false); + } } return (true); } @@ -132,8 +140,9 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) #ifdef ISC_PLAFORM_HAVESYSUNH case AF_UNIX: plen = strlen(sockaddr->type.sunix.sun_path); - if (plen >= isc_buffer_availablelength(target)) + if (plen >= isc_buffer_availablelength(target)) { return (ISC_R_NOSPACE); + } isc_buffer_putmem(target, sockaddr->type.sunix.sun_path, plen); @@ -145,7 +154,7 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) avail.base[0] = '\0'; return (ISC_R_SUCCESS); -#endif +#endif /* ifdef ISC_PLAFORM_HAVESYSUNH */ default: return (ISC_R_FAILURE); } @@ -155,11 +164,13 @@ isc_sockaddr_totext(const isc_sockaddr_t *sockaddr, isc_buffer_t *target) isc_netaddr_fromsockaddr(&netaddr, sockaddr); result = isc_netaddr_totext(&netaddr, target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (1 + plen + 1 > isc_buffer_availablelength(target)) + if (1 + plen + 1 > isc_buffer_availablelength(target)) { return (ISC_R_NOSPACE); + } isc_buffer_putmem(target, (const unsigned char *)"#", 1); isc_buffer_putmem(target, (const unsigned char *)pbuf, plen); @@ -180,8 +191,9 @@ isc_sockaddr_format(const isc_sockaddr_t *sa, char *array, unsigned int size) isc_result_t result; isc_buffer_t buf; - if (size == 0U) + if (size == 0U) { return; + } isc_buffer_init(&buf, array, size); result = isc_sockaddr_totext(sa, &buf); @@ -218,8 +230,9 @@ isc_sockaddr_hash(const isc_sockaddr_t *sockaddr, bool address_only) if (IN6_IS_ADDR_V4MAPPED(in6)) { s += 12; length = sizeof(sockaddr->type.sin.sin_addr.s_addr); - } else + } else { length = sizeof(sockaddr->type.sin6.sin6_addr); + } p = ntohs(sockaddr->type.sin6.sin6_port); break; default: @@ -331,7 +344,7 @@ isc_sockaddr_pf(const isc_sockaddr_t *sockaddr) * Assume that PF_xxx == AF_xxx for all AF and PF. */ return (sockaddr->type.sa.sa_family); -#else +#else /* if (AF_INET == PF_INET && AF_INET6 == PF_INET6) */ switch (sockaddr->type.sa.sa_family) { case AF_INET: return (PF_INET); @@ -341,7 +354,7 @@ isc_sockaddr_pf(const isc_sockaddr_t *sockaddr) FATAL_ERROR(__FILE__, __LINE__, "unknown address family: %d", (int)sockaddr->type.sa.sa_family); } -#endif +#endif /* if (AF_INET == PF_INET && AF_INET6 == PF_INET6) */ } void @@ -470,19 +483,20 @@ isc_result_t isc_sockaddr_frompath(isc_sockaddr_t *sockaddr, const char *path) { #ifdef ISC_PLATFORM_HAVESYSUNH - if (strlen(path) >= sizeof(sockaddr->type.sunix.sun_path)) + if (strlen(path) >= sizeof(sockaddr->type.sunix.sun_path)) { return (ISC_R_NOSPACE); + } memset(sockaddr, 0, sizeof(*sockaddr)); sockaddr->length = sizeof(sockaddr->type.sunix); sockaddr->type.sunix.sun_family = AF_UNIX; strlcpy(sockaddr->type.sunix.sun_path, path, sizeof(sockaddr->type.sunix.sun_path)); return (ISC_R_SUCCESS); -#else +#else /* ifdef ISC_PLATFORM_HAVESYSUNH */ UNUSED(sockaddr); UNUSED(path); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } isc_result_t @@ -501,7 +515,7 @@ isc_sockaddr_fromsockaddr(isc_sockaddr_t *isa, const struct sockaddr *sa) case AF_UNIX: length = sizeof(isa->type.sunix); break; -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ default: return (ISC_R_NOTIMPLEMENTED); } diff --git a/lib/isc/stats.c b/lib/isc/stats.c index d15b4323ca..3efee40e5f 100644 --- a/lib/isc/stats.c +++ b/lib/isc/stats.c @@ -29,9 +29,9 @@ #if defined(_WIN32) && !defined(_WIN64) typedef atomic_int_fast32_t isc__atomic_statcounter_t; -#else +#else /* if defined(_WIN32) && !defined(_WIN64) */ typedef atomic_int_fast64_t isc__atomic_statcounter_t; -#endif +#endif /* if defined(_WIN32) && !defined(_WIN64) */ struct isc_stats { unsigned int magic; diff --git a/lib/isc/string.c b/lib/isc/string.c index 98c57901c6..bb255762ea 100644 --- a/lib/isc/string.c +++ b/lib/isc/string.c @@ -42,10 +42,10 @@ #ifdef _GNU_SOURCE #undef _GNU_SOURCE -#endif +#endif /* ifdef _GNU_SOURCE */ #include -#include // IWYU pragma: keep +#include /* IWYU pragma: keep */ #if !defined(HAVE_STRLCPY) size_t @@ -69,8 +69,8 @@ strlcpy(char *dst, const char *src, size_t size) if (size != 0U) { *d = '\0'; /* NUL-terminate dst */ } - while (*s++) - ; + while (*s++) { + } } return (s - src - 1); /* count does not include NUL */ @@ -114,7 +114,7 @@ isc_string_strerror_r(int errnum, char *buf, size_t buflen) { #if defined(_WIN32) || defined(_WIN64) return (strerror_s(buf, buflen, errnum)); -#else +#else /* if defined(_WIN32) || defined(_WIN64) */ return (strerror_r(errnum, buf, buflen)); -#endif +#endif /* if defined(_WIN32) || defined(_WIN64) */ } diff --git a/lib/isc/symtab.c b/lib/isc/symtab.c index 08f8fcdb8c..8f1a9738d7 100644 --- a/lib/isc/symtab.c +++ b/lib/isc/symtab.c @@ -62,8 +62,9 @@ isc_symtab_create(isc_mem_t *mctx, unsigned int size, symtab->mctx = NULL; isc_mem_attach(mctx, &symtab->mctx); symtab->table = isc_mem_get(mctx, size * sizeof(eltlist_t)); - for (i = 0; i < size; i++) + for (i = 0; i < size; i++) { INIT_LIST(symtab->table[i]); + } symtab->size = size; symtab->count = 0; symtab->maxload = size * 3 / 4; @@ -92,10 +93,11 @@ isc_symtab_destroy(isc_symtab_t **symtabp) for (i = 0; i < symtab->size; i++) { for (elt = HEAD(symtab->table[i]); elt != NULL; elt = nelt) { nelt = NEXT(elt, link); - if (symtab->undefine_action != NULL) + if (symtab->undefine_action != NULL) { (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); + } isc_mem_put(symtab->mctx, elt, sizeof(*elt)); } } @@ -160,11 +162,13 @@ isc_symtab_lookup(isc_symtab_t *symtab, const char *key, unsigned int type, FIND(symtab, key, type, bucket, elt); - if (elt == NULL) + if (elt == NULL) { return (ISC_R_NOTFOUND); + } - if (value != NULL) + if (value != NULL) { *value = elt->value; + } return (ISC_R_SUCCESS); } @@ -183,8 +187,9 @@ grow_table(isc_symtab_t *symtab) newtable = isc_mem_get(symtab->mctx, newsize * sizeof(eltlist_t)); - for (i = 0; i < newsize; i++) + for (i = 0; i < newsize; i++) { INIT_LIST(newtable[i]); + } for (i = 0; i < symtab->size; i++) { elt_t *elt, *nelt; @@ -222,14 +227,16 @@ isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type, FIND(symtab, key, type, bucket, elt); if (exists_policy != isc_symexists_add && elt != NULL) { - if (exists_policy == isc_symexists_reject) + if (exists_policy == isc_symexists_reject) { return (ISC_R_EXISTS); + } INSIST(exists_policy == isc_symexists_replace); UNLINK(symtab->table[bucket], elt, link); - if (symtab->undefine_action != NULL) + if (symtab->undefine_action != NULL) { (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); + } } else { elt = isc_mem_get(symtab->mctx, sizeof(*elt)); ISC_LINK_INIT(elt, link); @@ -252,8 +259,9 @@ isc_symtab_define(isc_symtab_t *symtab, const char *key, unsigned int type, */ PREPEND(symtab->table[bucket], elt, link); - if (symtab->count > symtab->maxload) + if (symtab->count > symtab->maxload) { grow_table(symtab); + } return (ISC_R_SUCCESS); } @@ -269,12 +277,14 @@ isc_symtab_undefine(isc_symtab_t *symtab, const char *key, unsigned int type) FIND(symtab, key, type, bucket, elt); - if (elt == NULL) + if (elt == NULL) { return (ISC_R_NOTFOUND); + } - if (symtab->undefine_action != NULL) + if (symtab->undefine_action != NULL) { (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); + } UNLINK(symtab->table[bucket], elt, link); isc_mem_put(symtab->mctx, elt, sizeof(*elt)); symtab->count--; diff --git a/lib/isc/task.c b/lib/isc/task.c index b5fee67ad0..ac2aa3af8d 100644 --- a/lib/isc/task.c +++ b/lib/isc/task.c @@ -46,7 +46,7 @@ #ifdef OPENSSL_LEAKS #include -#endif +#endif /* ifdef OPENSSL_LEAKS */ /* * Task manager is built around 'as little locking as possible' concept. @@ -68,11 +68,11 @@ fprintf(stderr, "task %p thread %lu: %s\n", (t), isc_thread_self(), (m)) #define XTHREADTRACE(m) \ fprintf(stderr, "thread %lu: %s\n", isc_thread_self(), (m)) -#else +#else /* ifdef ISC_TASK_TRACE */ #define XTRACE(m) #define XTTRACE(t, m) #define XTHREADTRACE(m) -#endif +#endif /* ifdef ISC_TASK_TRACE */ /*** *** Types. @@ -91,7 +91,7 @@ typedef enum { static const char *statenames[] = { "idle", "ready", "paused", "pausing", "running", "done", }; -#endif +#endif /* if defined(HAVE_LIBXML2) || defined(HAVE_JSON_C) */ #define TASK_MAGIC ISC_MAGIC('T', 'A', 'S', 'K') #define VALID_TASK(t) ISC_MAGIC_VALID(t, TASK_MAGIC) @@ -477,8 +477,9 @@ isc_task_detach(isc_task_t **taskp) was_idle = task_detach(task); UNLOCK(&task->lock); - if (was_idle) + if (was_idle) { task_ready(task); + } *taskp = NULL; } @@ -616,8 +617,9 @@ isc_task_sendtoanddetach(isc_task_t **taskp, isc_event_t **eventp, int c) */ INSIST(!(idle1 && idle2)); - if (idle1 || idle2) + if (idle1 || idle2) { task_ready(task); + } *taskp = NULL; } @@ -747,8 +749,9 @@ isc_task_purgeevent(isc_task_t *task0, isc_event_t *event) } UNLOCK(&task->lock); - if (curr_event == NULL) + if (curr_event == NULL) { return (false); + } isc_event_free(&curr_event); @@ -813,8 +816,9 @@ isc_task_onshutdown(isc_task_t *task0, isc_taskaction_t action, void *arg) UNLOCK(&task->lock); } - if (disallowed) + if (disallowed) { isc_mem_put(task->manager->mctx, event, sizeof(*event)); + } return (result); } @@ -835,8 +839,9 @@ isc_task_shutdown(isc_task_t *task0) was_idle = task_shutdown(task); UNLOCK(&task->lock); - if (was_idle) + if (was_idle) { task_ready(task); + } } void @@ -1250,8 +1255,9 @@ dispatch(isc__taskmgr_t *manager, unsigned int threadid) } while (!done); UNLOCK(&task->lock); - if (finished) + if (finished) { task_finished(task); + } RUNTIME_CHECK(atomic_fetch_sub_explicit( &manager->tasks_running, 1, @@ -1333,7 +1339,7 @@ dispatch(isc__taskmgr_t *manager, unsigned int threadid) static isc_threadresult_t #ifdef _WIN32 WINAPI -#endif +#endif /* ifdef _WIN32 */ run(void *queuep) { isc__taskqueue_t *tq = queuep; @@ -1349,7 +1355,7 @@ static isc_threadresult_t #ifdef OPENSSL_LEAKS ERR_remove_state(0); -#endif +#endif /* ifdef OPENSSL_LEAKS */ return ((isc_threadresult_t)0); } @@ -1476,8 +1482,9 @@ isc_taskmgr_destroy(isc_taskmgr_t **managerp) * Detach the exclusive task before acquiring the manager lock */ LOCK(&manager->excl_lock); - if (manager->excl != NULL) + if (manager->excl != NULL) { isc_task_detach((isc_task_t **)&manager->excl); + } UNLOCK(&manager->excl_lock); /* @@ -1608,8 +1615,9 @@ isc_taskmgr_setexcltask(isc_taskmgr_t *mgr0, isc_task_t *task0) REQUIRE(VALID_MANAGER(mgr)); REQUIRE(VALID_TASK(task)); LOCK(&mgr->excl_lock); - if (mgr->excl != NULL) + if (mgr->excl != NULL) { isc_task_detach((isc_task_t **)&mgr->excl); + } isc_task_attach(task0, (isc_task_t **)&mgr->excl); UNLOCK(&mgr->excl_lock); } @@ -1624,10 +1632,11 @@ isc_taskmgr_excltask(isc_taskmgr_t *mgr0, isc_task_t **taskp) REQUIRE(taskp != NULL && *taskp == NULL); LOCK(&mgr->excl_lock); - if (mgr->excl != NULL) + if (mgr->excl != NULL) { isc_task_attach((isc_task_t *)mgr->excl, taskp); - else + } else { result = ISC_R_NOTFOUND; + } UNLOCK(&mgr->excl_lock); return (result); @@ -1776,12 +1785,13 @@ isc_task_setprivilege(isc_task_t *task0, bool priv) newflags)); LOCK(&manager->queues[task->threadid].lock); - if (priv && ISC_LINK_LINKED(task, ready_link)) + if (priv && ISC_LINK_LINKED(task, ready_link)) { ENQUEUE(manager->queues[task->threadid].ready_priority_tasks, task, ready_priority_link); - else if (!priv && ISC_LINK_LINKED(task, ready_priority_link)) + } else if (!priv && ISC_LINK_LINKED(task, ready_priority_link)) { DEQUEUE(manager->queues[task->threadid].ready_priority_tasks, task, ready_priority_link); + } UNLOCK(&manager->queues[task->threadid].lock); } @@ -1903,8 +1913,9 @@ isc_taskmgr_renderxml(isc_taskmgr_t *mgr0, void *writer0) TRY0(xmlTextWriterEndElement(writer)); /* tasks */ error: - if (task != NULL) + if (task != NULL) { UNLOCK(&task->lock); + } UNLOCK(&mgr->lock); return (xmlrc); @@ -2008,16 +2019,18 @@ isc_taskmgr_renderjson(isc_taskmgr_t *mgr0, void *tasks0) result = ISC_R_SUCCESS; error: - if (array != NULL) + if (array != NULL) { json_object_put(array); + } - if (task != NULL) + if (task != NULL) { UNLOCK(&task->lock); + } UNLOCK(&mgr->lock); return (result); } -#endif +#endif /* ifdef HAVE_JSON_C */ isc_result_t isc_taskmgr_createinctx(isc_mem_t *mctx, unsigned int workers, diff --git a/lib/isc/taskpool.c b/lib/isc/taskpool.c index 111bcb085e..35a6f68d6b 100644 --- a/lib/isc/taskpool.c +++ b/lib/isc/taskpool.c @@ -149,8 +149,9 @@ isc_taskpool_destroy(isc_taskpool_t **poolp) isc_taskpool_t *pool = *poolp; *poolp = NULL; for (i = 0; i < pool->ntasks; i++) { - if (pool->tasks[i] != NULL) + if (pool->tasks[i] != NULL) { isc_task_detach(&pool->tasks[i]); + } } isc_mem_put(pool->mctx, pool->tasks, pool->ntasks * sizeof(isc_task_t *)); @@ -165,7 +166,8 @@ isc_taskpool_setprivilege(isc_taskpool_t *pool, bool priv) REQUIRE(pool != NULL); for (i = 0; i < pool->ntasks; i++) { - if (pool->tasks[i] != NULL) + if (pool->tasks[i] != NULL) { isc_task_setprivilege(pool->tasks[i], priv); + } } } diff --git a/lib/isc/tests/aes_test.c b/lib/isc/tests/aes_test.c index 5a136732b0..9a1e0b6d30 100644 --- a/lib/isc/tests/aes_test.c +++ b/lib/isc/tests/aes_test.c @@ -68,7 +68,7 @@ fromhexstr(const char *in, unsigned char *d) if (ret != ISC_R_SUCCESS) { return (0); } - return isc_buffer_usedlength(&b); + return (isc_buffer_usedlength(&b)); } typedef struct aes_testcase { @@ -251,4 +251,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/buffer_test.c b/lib/isc/tests/buffer_test.c index 1fe962ef12..873b1aab7f 100644 --- a/lib/isc/tests/buffer_test.c +++ b/lib/isc/tests/buffer_test.c @@ -354,4 +354,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/counter_test.c b/lib/isc/tests/counter_test.c index 54693947c7..9c0efb809b 100644 --- a/lib/isc/tests/counter_test.c +++ b/lib/isc/tests/counter_test.c @@ -105,4 +105,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/crc64_test.c b/lib/isc/tests/crc64_test.c index 5041ac57cc..94720d92e2 100644 --- a/lib/isc/tests/crc64_test.c +++ b/lib/isc/tests/crc64_test.c @@ -108,4 +108,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/errno_test.c b/lib/isc/tests/errno_test.c index 327157b37a..122983d194 100644 --- a/lib/isc/tests/errno_test.c +++ b/lib/isc/tests/errno_test.c @@ -46,42 +46,42 @@ testpair_t testpair[] = { { EPERM, ISC_R_NOPERM }, { ELOOP, ISC_R_INVALIDFILE }, #ifdef EOVERFLOW { EOVERFLOW, ISC_R_RANGE }, -#endif +#endif /* ifdef EOVERFLOW */ #ifdef EAFNOSUPPORT { EAFNOSUPPORT, ISC_R_FAMILYNOSUPPORT }, -#endif +#endif /* ifdef EAFNOSUPPORT */ #ifdef EADDRINUSE { EADDRINUSE, ISC_R_ADDRINUSE }, -#endif +#endif /* ifdef EADDRINUSE */ { EADDRNOTAVAIL, ISC_R_ADDRNOTAVAIL }, #ifdef ENETDOWN { ENETDOWN, ISC_R_NETDOWN }, -#endif +#endif /* ifdef ENETDOWN */ #ifdef ENETUNREACH { ENETUNREACH, ISC_R_NETUNREACH }, -#endif +#endif /* ifdef ENETUNREACH */ #ifdef ECONNABORTED { ECONNABORTED, ISC_R_CONNECTIONRESET }, -#endif +#endif /* ifdef ECONNABORTED */ #ifdef ECONNRESET { ECONNRESET, ISC_R_CONNECTIONRESET }, -#endif +#endif /* ifdef ECONNRESET */ #ifdef ENOBUFS { ENOBUFS, ISC_R_NORESOURCES }, -#endif +#endif /* ifdef ENOBUFS */ #ifdef ENOTCONN { ENOTCONN, ISC_R_NOTCONNECTED }, -#endif +#endif /* ifdef ENOTCONN */ #ifdef ETIMEDOUT { ETIMEDOUT, ISC_R_TIMEDOUT }, -#endif +#endif /* ifdef ETIMEDOUT */ { ECONNREFUSED, ISC_R_CONNREFUSED }, #ifdef EHOSTDOWN { EHOSTDOWN, ISC_R_HOSTDOWN }, -#endif +#endif /* ifdef EHOSTDOWN */ #ifdef EHOSTUNREACH { EHOSTUNREACH, ISC_R_HOSTUNREACH }, -#endif +#endif /* ifdef EHOSTUNREACH */ { 0, ISC_R_UNEXPECTED } }; /* convert errno to ISC result */ @@ -121,4 +121,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/file_test.c b/lib/isc/tests/file_test.c index 9000831ee6..c6c5004854 100644 --- a/lib/isc/tests/file_test.c +++ b/lib/isc/tests/file_test.c @@ -154,4 +154,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/hash_test.c b/lib/isc/tests/hash_test.c index 4a28c786c5..dd40440609 100644 --- a/lib/isc/tests/hash_test.c +++ b/lib/isc/tests/hash_test.c @@ -113,4 +113,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/heap_test.c b/lib/isc/tests/heap_test.c index 6fb7003c2f..5f1c4a2ae9 100644 --- a/lib/isc/tests/heap_test.c +++ b/lib/isc/tests/heap_test.c @@ -120,4 +120,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/hmac_test.c b/lib/isc/tests/hmac_test.c index 3d024b7e33..0c791ca4f6 100644 --- a/lib/isc/tests/hmac_test.c +++ b/lib/isc/tests/hmac_test.c @@ -178,7 +178,7 @@ isc_hmac_reset_test(void **state) #if 0 unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused)); unsigned int digestlen __attribute((unused)); -#endif +#endif /* if 0 */ assert_non_null(hmac); @@ -197,8 +197,8 @@ isc_hmac_reset_test(void **state) * so this could be only manually checked that the test will * segfault when called by hand */ - expect_assert_failure(isc_hmac_final(hmac, digest, &digestlen)); -#endif + expect_assert_failure(isc_hmac_final(hmac,digest,&digestlen)); +#endif /* if 0 */ } static void @@ -316,7 +316,7 @@ isc_hmac_md5_test(void **state) "Larger Than One Block-Size Data"), "E8E99D0F45237D786D6BBAA7965C7808BBFF1A91", 1); -#endif +#endif /* if 0 */ } static void @@ -373,7 +373,7 @@ isc_hmac_sha1_test(void **state) TEST_INPUT("Test With Truncation"), "4C1A03424B55E07FE7F27BE1", 1); -#endif +#endif /* if 0 */ /* Test 6 */ isc_hmac_test(hmac, TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -468,7 +468,7 @@ isc_hmac_sha224_test(void **state) TEST_INPUT("Test With Truncation"), "4C1A03424B55E07FE7F27BE1", 1); -#endif +#endif /* if 0 */ /* Test 6 */ isc_hmac_test(hmac, TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -593,7 +593,7 @@ isc_hmac_sha256_test(void **state) TEST_INPUT("Test With Truncation"), "4C1A03424B55E07FE7F27BE1", 1); -#endif +#endif /* if 0 */ /* Test 6 */ isc_hmac_test(hmac, TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -722,7 +722,7 @@ isc_hmac_sha384_test(void **state) TEST_INPUT("Test With Truncation"), "4C1A03424B55E07FE7F27BE1", 1); -#endif +#endif /* if 0 */ /* Test 6 */ isc_hmac_test(hmac, TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -854,7 +854,7 @@ isc_hmac_sha512_test(void **state) TEST_INPUT("Test With Truncation"), "4C1A03424B55E07FE7F27BE1", 1); -#endif +#endif /* if 0 */ /* Test 6 */ isc_hmac_test(hmac, TEST_INPUT("\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" @@ -962,4 +962,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/ht_test.c b/lib/isc/tests/ht_test.c index 2cb3d44916..2fc05a0087 100644 --- a/lib/isc/tests/ht_test.c +++ b/lib/isc/tests/ht_test.c @@ -364,4 +364,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/isctest.c b/lib/isc/tests/isctest.c index 2c6a2c78c6..a95ef8a697 100644 --- a/lib/isc/tests/isctest.c +++ b/lib/isc/tests/isctest.c @@ -184,11 +184,11 @@ isc_test_nap(uint32_t usec) nanosleep(&ts, NULL); #elif HAVE_USLEEP usleep(usec); -#else +#else /* ifdef HAVE_NANOSLEEP */ /* * No fractional-second sleep function is available, so we * round up to the nearest second and sleep instead */ sleep((usec / 1000000) + 1); -#endif +#endif /* ifdef HAVE_NANOSLEEP */ } diff --git a/lib/isc/tests/lex_test.c b/lib/isc/tests/lex_test.c index eebd9b37ea..3b23caeeea 100644 --- a/lib/isc/tests/lex_test.c +++ b/lib/isc/tests/lex_test.c @@ -145,4 +145,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/md_test.c b/lib/isc/tests/md_test.c index ed8ff0578d..5cef8c9f0a 100644 --- a/lib/isc/tests/md_test.c +++ b/lib/isc/tests/md_test.c @@ -166,7 +166,7 @@ isc_md_reset_test(void **state) #if 0 unsigned char digest[ISC_MAX_MD_SIZE] __attribute((unused)); unsigned int digestlen __attribute((unused)); -#endif +#endif /* if 0 */ assert_non_null(md); @@ -184,8 +184,8 @@ isc_md_reset_test(void **state) * so this could be only manually checked that the test will * segfault when called by hand */ - expect_assert_failure(isc_md_final(md, digest, &digestlen)); -#endif + expect_assert_failure(isc_md_final(md,digest,&digestlen)); +#endif /* if 0 */ } static void @@ -600,4 +600,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/mem_test.c b/lib/isc/tests/mem_test.c index 41e5fd66d7..27b0201db5 100644 --- a/lib/isc/tests/mem_test.c +++ b/lib/isc/tests/mem_test.c @@ -372,12 +372,12 @@ isc_mem_traceflag_test(void **state) isc_mem_debugging = ISC_MEM_DEBUGRECORD; } -#endif +#endif /* if ISC_MEM_TRACKLINES */ #if !defined(__SANITIZE_THREAD__) #define ITERS 512 -#define NUM_ITEMS 1024 // 768 +#define NUM_ITEMS 1024 /* 768 */ #define ITEM_SIZE 65534 static isc_threadresult_t @@ -533,7 +533,7 @@ main(void) */ cmocka_unit_test_setup_teardown(isc_mem_traceflag_test, _setup, _teardown), -#endif +#endif /* if ISC_MEM_TRACKLINES */ }; return (cmocka_run_group_tests(tests, NULL, NULL)); @@ -550,4 +550,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/netaddr_test.c b/lib/isc/tests/netaddr_test.c index 59b1c7de97..186cab769d 100644 --- a/lib/isc/tests/netaddr_test.c +++ b/lib/isc/tests/netaddr_test.c @@ -159,4 +159,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/parse_test.c b/lib/isc/tests/parse_test.c index 4a5b9539ea..10d4276296 100644 --- a/lib/isc/tests/parse_test.c +++ b/lib/isc/tests/parse_test.c @@ -96,4 +96,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/pool_test.c b/lib/isc/tests/pool_test.c index 0853205955..a946000f6a 100644 --- a/lib/isc/tests/pool_test.c +++ b/lib/isc/tests/pool_test.c @@ -59,8 +59,9 @@ poolinit(void **target, void *arg) isc_taskmgr_t *mgr = (isc_taskmgr_t *)arg; isc_task_t * task = NULL; result = isc_task_create(mgr, 0, &task); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } *target = (void *)task; return (ISC_R_SUCCESS); @@ -197,4 +198,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/radix_test.c b/lib/isc/tests/radix_test.c index 92b2da71e6..f80f183ba3 100644 --- a/lib/isc/tests/radix_test.c +++ b/lib/isc/tests/radix_test.c @@ -124,4 +124,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/random_test.c b/lib/isc/tests/random_test.c index 35326b17ef..e24508f023 100644 --- a/lib/isc/tests/random_test.c +++ b/lib/isc/tests/random_test.c @@ -105,11 +105,13 @@ igamc(double a, double x) double ans, ax, c, yc, r, t, y, z; double pk, pkm1, pkm2, qk, qkm1, qkm2; - if ((x <= 0) || (a <= 0)) + if ((x <= 0) || (a <= 0)) { return (1.0); + } - if ((x < 1.0) || (x < a)) + if ((x < 1.0) || (x < a)) { return (1.0 - igam(a, x)); + } ax = a * log(x) - x - lgamma(a); if (ax < -MAXLOG) { @@ -139,8 +141,9 @@ igamc(double a, double x) r = pk / qk; t = fabs((ans - r) / r); ans = r; - } else + } else { t = 1.0; + } pkm2 = pkm1; pkm1 = pk; @@ -163,11 +166,13 @@ igam(double a, double x) { double ans, ax, c, r; - if ((x <= 0) || (a <= 0)) + if ((x <= 0) || (a <= 0)) { return (0.0); + } - if ((x > 1.0) && (x > a)) + if ((x > 1.0) && (x > a)) { return (1.0 - igamc(a, x)); + } /* Compute x**a * exp(-x) / md_gamma(a) */ ax = a * log(x) - x - lgamma(a); @@ -205,10 +210,11 @@ scount_calculate(uint16_t n) uint16_t lsb; lsb = n & 1; - if (lsb != 0) + if (lsb != 0) { sc += 1; - else + } else { sc -= 1; + } n >>= 1; } @@ -227,8 +233,9 @@ bitcount_calculate(uint16_t n) uint16_t lsb; lsb = n & 1; - if (lsb != 0) + if (lsb != 0) { bc += 1; + } n >>= 1; } @@ -268,9 +275,9 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) while (rt >= cols || ((bits[i] >> rt) & 1) == 0) { i++; - if (i < rows) + if (i < rows) { continue; - else { + } else { rt++; if (rt < cols) { i = k; @@ -289,10 +296,11 @@ matrix_binaryrank(uint32_t *bits, size_t rows, size_t cols) } for (j = i + 1; j < rows; j++) { - if (((bits[j] >> rt) & 1) == 0) + if (((bits[j] >> rt) & 1) == 0) { continue; - else + } else { bits[j] ^= bits[k]; + } } rt++; @@ -452,8 +460,9 @@ monobit(isc_mem_t *mctx, uint16_t *values, size_t length) numbits = length * sizeof(*values) * 8; scount = 0; - for (i = 0; i < length; i++) + for (i = 0; i < length; i++) { scount += scounts_table[values[i]]; + } /* Preconditions (section 2.1.7 in NIST SP 800-22) */ assert_true(numbits >= 100); @@ -493,8 +502,9 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) numbits = length * sizeof(*values) * 8; bcount = 0; - for (i = 0; i < length; i++) + for (i = 0; i < length; i++) { bcount += bitcounts_table[values[i]]; + } if (verbose) { print_message("# numbits=%u, bcount=%u\n", numbits, bcount); @@ -511,8 +521,9 @@ runs(isc_mem_t *mctx, uint16_t *values, size_t length) * for some sequences, and the p-value is taken as 0 in these * cases. */ - if (fabs(pi - 0.5) >= tau) + if (fabs(pi - 0.5) >= tau) { return (0.0); + } /* Compute v_obs */ j = 0; @@ -594,8 +605,9 @@ blockfrequency(isc_mem_t *mctx, uint16_t *values, size_t length) /* Compute chi_square */ chi_square = 0.0; - for (i = 0; i < numblocks; i++) + for (i = 0; i < numblocks; i++) { chi_square += (pi[i] - 0.5) * (pi[i] - 0.5); + } chi_square *= 4 * mbits; @@ -670,12 +682,13 @@ binarymatrixrank(isc_mem_t *mctx, uint16_t *values, size_t length) rank = matrix_binaryrank(bits, matrix_m, matrix_q); - if (rank == matrix_m) + if (rank == matrix_m) { fm_0++; - else if (rank == (matrix_m - 1)) + } else if (rank == (matrix_m - 1)) { fm_1++; - else + } else { fm_rest++; + } } /* Compute chi_square */ @@ -906,4 +919,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/regex_test.c b/lib/isc/tests/regex_test.c index bc54956e63..461a379177 100644 --- a/lib/isc/tests/regex_test.c +++ b/lib/isc/tests/regex_test.c @@ -21,7 +21,7 @@ #ifdef HAVE_REGEX_H #include -#endif +#endif /* ifdef HAVE_REGEX_H */ #define UNIT_TESTING #include @@ -45,7 +45,8 @@ regex_validate(void **state) struct { const char *expression; int expect; - int exception; /* regcomp accepts but is disallowed. */ + int exception; /* regcomp accepts but is + * disallowed. */ } tests[] = { { "", -1, 0 }, { "*", -1, 0 }, @@ -2322,7 +2323,7 @@ regex_validate(void **state) regfree(&preg); } } -#endif +#endif /* ifdef HAVE_REGEX_H */ /* * Check if we get the expected response. @@ -2369,4 +2370,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/result_test.c b/lib/isc/tests/result_test.c index d9d5209d05..a29f873d8d 100644 --- a/lib/isc/tests/result_test.c +++ b/lib/isc/tests/result_test.c @@ -131,4 +131,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/safe_test.c b/lib/isc/tests/safe_test.c index 8e228f8e17..fc482c5eac 100644 --- a/lib/isc/tests/safe_test.c +++ b/lib/isc/tests/safe_test.c @@ -106,4 +106,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/siphash_test.c b/lib/isc/tests/siphash_test.c index e12bb52109..2356c85e62 100644 --- a/lib/isc/tests/siphash_test.c +++ b/lib/isc/tests/siphash_test.c @@ -41,13 +41,13 @@ openssl_isc_siphash24(const uint8_t *, const uint8_t *, const size_t, #include "../siphash.c" #undef isc_siphash24 -#else +#else /* if HAVE_OPENSSL_SIPHASH */ #define isc_siphash24 native_isc_siphash24 #include "../siphash.c" #undef isc_siphash24 -#endif +#endif /* if HAVE_OPENSSL_SIPHASH */ const uint8_t vectors[64][8] = { { @@ -709,7 +709,7 @@ openssl_isc_siphash24_test(void **state) assert_memory_equal(out, vectors[i], 8); } } -#endif +#endif /* if HAVE_OPENSSL_SIPHASH */ static void native_isc_siphash24_test(void **state) @@ -734,7 +734,7 @@ main(void) const struct CMUnitTest tests[] = { #if HAVE_OPENSSL_SIPHASH cmocka_unit_test(openssl_isc_siphash24_test), -#endif +#endif /* if HAVE_OPENSSL_SIPHASH */ cmocka_unit_test(native_isc_siphash24_test), }; @@ -752,4 +752,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/sockaddr_test.c b/lib/isc/tests/sockaddr_test.c index 755702198e..9e8439d821 100644 --- a/lib/isc/tests/sockaddr_test.c +++ b/lib/isc/tests/sockaddr_test.c @@ -190,4 +190,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/socket_test.c b/lib/isc/tests/socket_test.c index 6d64add291..fdd94acde1 100644 --- a/lib/isc/tests/socket_test.c +++ b/lib/isc/tests/socket_test.c @@ -110,7 +110,6 @@ event_done(isc_task_t *task, isc_event_t *event) if ((sev->attributes & ISC_SOCKEVENTATTR_DSCP) != 0) { recv_dscp = true; recv_dscp_value = sev->dscp; - ; } else { recv_dscp = false; } @@ -717,16 +716,16 @@ net_probedscp_test(void **state) } #if 0 - fprintf(stdout, "IPv4:%s%s%s\n", + fprintf(stdout,"IPv4:%s%s%s\n", (n & ISC_NET_DSCPSETV4) ? " set" : "none", (n & ISC_NET_DSCPPKTV4) ? " packet" : "", (n & ISC_NET_DSCPRECVV4) ? " receive" : ""); - fprintf(stdout, "IPv6:%s%s%s\n", + fprintf(stdout,"IPv6:%s%s%s\n", (n & ISC_NET_DSCPSETV6) ? " set" : "none", (n & ISC_NET_DSCPPKTV6) ? " packet" : "", (n & ISC_NET_DSCPRECVV6) ? " receive" : ""); -#endif +#endif /* if 0 */ } /* Test UDP truncation detection */ @@ -876,4 +875,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/symtab_test.c b/lib/isc/tests/symtab_test.c index fa657c764f..ee5d0c0585 100644 --- a/lib/isc/tests/symtab_test.c +++ b/lib/isc/tests/symtab_test.c @@ -93,8 +93,9 @@ symtab_grow(void **state) assert_non_null(value.as_pointer); result = isc_symtab_define(st, key, 1, value, policy); assert_int_equal(result, ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { undefine(key, 1, value, NULL); + } } /* @@ -171,4 +172,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/task_test.c b/lib/isc/tests/task_test.c index ddb40722e7..717daf3979 100644 --- a/lib/isc/tests/task_test.c +++ b/lib/isc/tests/task_test.c @@ -618,9 +618,9 @@ basic(void **state) #ifndef WIN32 sleep(2); -#else +#else /* ifndef WIN32 */ Sleep(2000); -#endif +#endif /* ifndef WIN32 */ for (i = 0; testarray[i] != NULL; i++) { /* @@ -647,9 +647,9 @@ basic(void **state) #ifndef WIN32 sleep(10); -#else +#else /* ifndef WIN32 */ Sleep(10000); -#endif +#endif /* ifndef WIN32 */ isc_timer_detach(&ti1); isc_timer_detach(&ti2); } @@ -1459,13 +1459,12 @@ pge_sde(isc_task_t *task, isc_event_t *event) static void try_purgeevent(bool purgeable) { - isc_result_t result; - isc_task_t * task = NULL; - bool purged; - isc_event_t *event1 = NULL; - isc_event_t *event2 = NULL; - isc_event_t *event2_clone = NULL; - ; + isc_result_t result; + isc_task_t * task = NULL; + bool purged; + isc_event_t * event1 = NULL; + isc_event_t * event2 = NULL; + isc_event_t * event2_clone = NULL; isc_time_t now; isc_interval_t interval; @@ -1615,4 +1614,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/taskpool_test.c b/lib/isc/tests/taskpool_test.c index cd751f29df..a1504f937c 100644 --- a/lib/isc/tests/taskpool_test.c +++ b/lib/isc/tests/taskpool_test.c @@ -212,4 +212,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/time_test.c b/lib/isc/tests/time_test.c index 51e2811f25..c82840f84a 100644 --- a/lib/isc/tests/time_test.c +++ b/lib/isc/tests/time_test.c @@ -251,4 +251,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/tests/timer_test.c b/lib/isc/tests/timer_test.c index 43ce290641..14c824e0d7 100644 --- a/lib/isc/tests/timer_test.c +++ b/lib/isc/tests/timer_test.c @@ -671,4 +671,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isc/timer.c b/lib/isc/timer.c index 674eef1024..d105365fcf 100644 --- a/lib/isc/timer.c +++ b/lib/isc/timer.c @@ -31,7 +31,7 @@ #ifdef OPENSSL_LEAKS #include -#endif +#endif /* ifdef OPENSSL_LEAKS */ #ifdef ISC_TIMER_TRACE #define XTRACE(s) fprintf(stderr, "%s\n", (s)) @@ -44,7 +44,7 @@ #define XTRACETIMER(s, t, d) \ fprintf(stderr, "%s %p %u.%09u\n", (s), (t), (d).seconds, \ (d).nanoseconds) -#else +#else /* ifdef ISC_TIMER_TRACE */ #define XTRACE(s) #define XTRACEID(s, t) #define XTRACETIME(s, d) @@ -120,20 +120,24 @@ schedule(isc__timer_t *timer, isc_time_t *now, bool signal_ok) */ if (timer->type != isc_timertype_once) { result = isc_time_add(now, &timer->interval, &due); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (timer->type == isc_timertype_limited && - isc_time_compare(&timer->expires, &due) < 0) + isc_time_compare(&timer->expires, &due) < 0) { due = timer->expires; + } } else { - if (isc_time_isepoch(&timer->idle)) + if (isc_time_isepoch(&timer->idle)) { due = timer->expires; - else if (isc_time_isepoch(&timer->expires)) + } else if (isc_time_isepoch(&timer->expires)) { due = timer->idle; - else if (isc_time_compare(&timer->idle, &timer->expires) < 0) + } else if (isc_time_compare(&timer->idle, &timer->expires) < + 0) { due = timer->idle; - else + } else { due = timer->expires; + } } /* @@ -196,8 +200,9 @@ deschedule(isc__timer_t *timer) manager = timer->manager; if (timer->index > 0) { - if (timer->index == 1) + if (timer->index == 1) { need_wakeup = true; + } isc_heap_delete(manager->heap, timer->index); timer->index = 0; INSIST(manager->nscheduled > 0); @@ -257,10 +262,12 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type, * in 'timerp'. */ manager = (isc__timermgr_t *)manager0; - if (expires == NULL) + if (expires == NULL) { expires = isc_time_epoch; - if (interval == NULL) + } + if (interval == NULL) { interval = isc_interval_zero; + } REQUIRE(type == isc_timertype_inactive || !(isc_time_isepoch(expires) && isc_interval_iszero(interval))); REQUIRE(timerp != NULL && *timerp == NULL); @@ -292,8 +299,9 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type, isc_mem_put(manager->mctx, timer, sizeof(*timer)); return (result); } - } else + } else { isc_time_settoepoch(&timer->idle); + } timer->type = type; timer->expires = *expires; @@ -325,10 +333,11 @@ isc_timer_create(isc_timermgr_t *manager0, isc_timertype_t type, * there are no external references to it yet. */ - if (type != isc_timertype_inactive) + if (type != isc_timertype_inactive) { result = schedule(timer, &now, true); - else + } else { result = ISC_R_SUCCESS; + } if (result == ISC_R_SUCCESS) { *timerp = (isc_timer_t *)timer; APPEND(manager->timers, timer, link); @@ -369,10 +378,12 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type, manager = timer->manager; REQUIRE(VALID_MANAGER(manager)); - if (expires == NULL) + if (expires == NULL) { expires = isc_time_epoch; - if (interval == NULL) + } + if (interval == NULL) { interval = isc_interval_zero; + } REQUIRE(type == isc_timertype_inactive || !(isc_time_isepoch(expires) && isc_interval_iszero(interval))); REQUIRE(type != isc_timertype_limited || @@ -395,10 +406,11 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type, LOCK(&manager->lock); LOCK(&timer->lock); - if (purge) + if (purge) { (void)isc_task_purgerange(timer->task, timer, ISC_TIMEREVENT_FIRSTEVENT, ISC_TIMEREVENT_LASTEVENT, NULL); + } timer->type = type; timer->expires = *expires; timer->interval = *interval; @@ -413,8 +425,9 @@ isc_timer_reset(isc_timer_t *timer0, isc_timertype_t type, if (type == isc_timertype_inactive) { deschedule(timer); result = ISC_R_SUCCESS; - } else + } else { result = schedule(timer, &now, true); + } } UNLOCK(&timer->lock); @@ -587,11 +600,12 @@ dispatch(isc__timermgr_t *manager, isc_time_t *now) event->due = timer->due; isc_task_send(timer->task, ISC_EVENT_PTR(&event)); - } else + } else { UNEXPECTED_ERROR(__FILE__, __LINE__, "%s", "couldn't allocate " "event"); + } } timer->index = 0; @@ -600,12 +614,13 @@ dispatch(isc__timermgr_t *manager, isc_time_t *now) if (need_schedule) { result = schedule(timer, now, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "%s: %u", "couldn't schedule " "timer", result); + } } } else { manager->due = timer->due; @@ -617,7 +632,7 @@ dispatch(isc__timermgr_t *manager, isc_time_t *now) static isc_threadresult_t #ifdef _WIN32 /* XXXDCL */ WINAPI -#endif +#endif /* ifdef _WIN32 */ run(void *uap) { isc__timermgr_t *manager = uap; @@ -648,7 +663,7 @@ static isc_threadresult_t #ifdef OPENSSL_LEAKS ERR_remove_state(0); -#endif +#endif /* ifdef OPENSSL_LEAKS */ return ((isc_threadresult_t)0); } @@ -663,8 +678,9 @@ sooner(void *v1, void *v2) REQUIRE(VALID_TIMER(t1)); REQUIRE(VALID_TIMER(t2)); - if (isc_time_compare(&t1->due, &t2->due) < 0) + if (isc_time_compare(&t1->due, &t2->due) < 0) { return (true); + } return (false); } diff --git a/lib/isc/tm.c b/lib/isc/tm.c index f6500f2953..8733f0b191 100644 --- a/lib/isc/tm.c +++ b/lib/isc/tm.c @@ -62,12 +62,12 @@ #define LEGAL_ALT(x) \ { \ if ((alt_format & ~(x)) != 0) \ - return (0); \ + return ((0)); \ } #ifndef TM_YEAR_BASE #define TM_YEAR_BASE 1900 -#endif +#endif /* ifndef TM_YEAR_BASE */ static const char *day[7] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }; @@ -90,8 +90,9 @@ conv_num(const char **buf, int *dest, int llim, int ulim) /* The limit also determines the number of valid digits. */ int rulim = ulim; - if (**buf < '0' || **buf > '9') + if (**buf < '0' || **buf > '9') { return (0); + } do { result *= 10; @@ -100,8 +101,9 @@ conv_num(const char **buf, int *dest, int llim, int ulim) } while ((result * 10 <= ulim) && rulim && **buf >= '0' && **buf <= '9'); - if (result < llim || result > ulim) + if (result < llim || result > ulim) { return (0); + } *dest = result; return (1); @@ -122,8 +124,9 @@ isc_tm_timegm(struct tm *tm) mdays[1] += leapday; yday = tm->tm_mday - 1; - for (i = 1; i <= tm->tm_mon; i++) + for (i = 1; i <= tm->tm_mon; i++) { yday += mdays[i - 1]; + } ret = tm->tm_sec + (60 * tm->tm_min) + (3600 * tm->tm_hour) + (86400 * (yday + ((tm->tm_year - 70) * 365) + ((tm->tm_year - 69) / 4) - @@ -153,22 +156,25 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) /* Eat up white-space. */ if (isspace((unsigned char)c)) { - while (isspace((unsigned char)*bp)) + while (isspace((unsigned char)*bp)) { bp++; + } fmt++; continue; } - if ((c = *fmt++) != '%') + if ((c = *fmt++) != '%') { goto literal; + } again: switch (c = *fmt++) { case '%': /* "%%" is converted to "%". */ literal: - if (c != *bp++) + if (c != *bp++) { return (0); + } break; /* @@ -190,44 +196,51 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) */ case 'c': /* Date and time, using the locale's format. */ LEGAL_ALT(ALT_E); - if (!(bp = isc_tm_strptime(bp, "%x %X", tm))) + if (!(bp = isc_tm_strptime(bp, "%x %X", tm))) { return (0); + } break; case 'D': /* The date as "%m/%d/%y". */ LEGAL_ALT(0); - if (!(bp = isc_tm_strptime(bp, "%m/%d/%y", tm))) + if (!(bp = isc_tm_strptime(bp, "%m/%d/%y", tm))) { return (0); + } break; case 'R': /* The time as "%H:%M". */ LEGAL_ALT(0); - if (!(bp = isc_tm_strptime(bp, "%H:%M", tm))) + if (!(bp = isc_tm_strptime(bp, "%H:%M", tm))) { return (0); + } break; case 'r': /* The time in 12-hour clock representation. */ LEGAL_ALT(0); - if (!(bp = isc_tm_strptime(bp, "%I:%M:%S %p", tm))) + if (!(bp = isc_tm_strptime(bp, "%I:%M:%S %p", tm))) { return (0); + } break; case 'T': /* The time as "%H:%M:%S". */ LEGAL_ALT(0); - if (!(bp = isc_tm_strptime(bp, "%H:%M:%S", tm))) + if (!(bp = isc_tm_strptime(bp, "%H:%M:%S", tm))) { return (0); + } break; case 'X': /* The time, using the locale's format. */ LEGAL_ALT(ALT_E); - if (!(bp = isc_tm_strptime(bp, "%H:%M:%S", tm))) + if (!(bp = isc_tm_strptime(bp, "%H:%M:%S", tm))) { return (0); + } break; case 'x': /* The date, using the locale's format. */ LEGAL_ALT(ALT_E); - if (!(bp = isc_tm_strptime(bp, "%m/%d/%y", tm))) + if (!(bp = isc_tm_strptime(bp, "%m/%d/%y", tm))) { return (0); + } break; /* @@ -239,18 +252,21 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) for (i = 0; i < 7; i++) { /* Full name. */ len = strlen(day[i]); - if (strncasecmp(day[i], bp, len) == 0) + if (strncasecmp(day[i], bp, len) == 0) { break; + } /* Abbreviated name. */ len = strlen(abday[i]); - if (strncasecmp(abday[i], bp, len) == 0) + if (strncasecmp(abday[i], bp, len) == 0) { break; + } } /* Nothing matched. */ - if (i == 7) + if (i == 7) { return (0); + } tm->tm_wday = i; bp += len; @@ -263,18 +279,21 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) for (i = 0; i < 12; i++) { /* Full name. */ len = strlen(mon[i]); - if (strncasecmp(mon[i], bp, len) == 0) + if (strncasecmp(mon[i], bp, len) == 0) { break; + } /* Abbreviated name. */ len = strlen(abmon[i]); - if (strncasecmp(abmon[i], bp, len) == 0) + if (strncasecmp(abmon[i], bp, len) == 0) { break; + } } /* Nothing matched. */ - if (i == 12) + if (i == 12) { return (0); + } tm->tm_mon = i; bp += len; @@ -282,8 +301,9 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) case 'C': /* The century number. */ LEGAL_ALT(ALT_E); - if (!(conv_num(&bp, &i, 0, 99))) + if (!(conv_num(&bp, &i, 0, 99))) { return (0); + } if (split_year) { tm->tm_year = (tm->tm_year % 100) + (i * 100); @@ -296,47 +316,54 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) case 'd': /* The day of month. */ case 'e': LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) + if (!(conv_num(&bp, &tm->tm_mday, 1, 31))) { return (0); + } break; case 'k': /* The hour (24-hour clock representation). */ LEGAL_ALT(0); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 'H': LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) + if (!(conv_num(&bp, &tm->tm_hour, 0, 23))) { return (0); + } break; case 'l': /* The hour (12-hour clock representation). */ LEGAL_ALT(0); - /* FALLTHROUGH */ + /* FALLTHROUGH */ case 'I': LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) + if (!(conv_num(&bp, &tm->tm_hour, 1, 12))) { return (0); - if (tm->tm_hour == 12) + } + if (tm->tm_hour == 12) { tm->tm_hour = 0; + } break; case 'j': /* The day of year. */ LEGAL_ALT(0); - if (!(conv_num(&bp, &i, 1, 366))) + if (!(conv_num(&bp, &i, 1, 366))) { return (0); + } tm->tm_yday = i - 1; break; case 'M': /* The minute. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_min, 0, 59))) + if (!(conv_num(&bp, &tm->tm_min, 0, 59))) { return (0); + } break; case 'm': /* The month. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &i, 1, 12))) + if (!(conv_num(&bp, &i, 1, 12))) { return (0); + } tm->tm_mon = i - 1; break; @@ -344,16 +371,18 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) LEGAL_ALT(0); /* AM? */ if (strcasecmp(am_pm[0], bp) == 0) { - if (tm->tm_hour > 11) + if (tm->tm_hour > 11) { return (0); + } bp += strlen(am_pm[0]); break; } /* PM? */ else if (strcasecmp(am_pm[1], bp) == 0) { - if (tm->tm_hour > 11) + if (tm->tm_hour > 11) { return (0); + } tm->tm_hour += 12; bp += strlen(am_pm[1]); @@ -365,8 +394,9 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) case 'S': /* The seconds. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) + if (!(conv_num(&bp, &tm->tm_sec, 0, 61))) { return (0); + } break; case 'U': /* The week of year, beginning on sunday. */ @@ -378,38 +408,43 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) * point to calculate a real value, so just check the * range for now. */ - if (!(conv_num(&bp, &i, 0, 53))) + if (!(conv_num(&bp, &i, 0, 53))) { return (0); + } break; case 'w': /* The day of week, beginning on sunday. */ LEGAL_ALT(ALT_O); - if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) + if (!(conv_num(&bp, &tm->tm_wday, 0, 6))) { return (0); + } break; case 'Y': /* The year. */ LEGAL_ALT(ALT_E); - if (!(conv_num(&bp, &i, 0, 9999))) + if (!(conv_num(&bp, &i, 0, 9999))) { return (0); + } tm->tm_year = i - TM_YEAR_BASE; break; case 'y': /* The year within 100 years of the epoch. */ LEGAL_ALT(ALT_E | ALT_O); - if (!(conv_num(&bp, &i, 0, 99))) + if (!(conv_num(&bp, &i, 0, 99))) { return (0); + } if (split_year) { tm->tm_year = ((tm->tm_year / 100) * 100) + i; break; } split_year = 1; - if (i <= 68) + if (i <= 68) { tm->tm_year = i + 2000 - TM_YEAR_BASE; - else + } else { tm->tm_year = i + 1900 - TM_YEAR_BASE; + } break; /* @@ -418,8 +453,9 @@ isc_tm_strptime(const char *buf, const char *fmt, struct tm *tm) case 'n': /* Any kind of white-space. */ case 't': LEGAL_ALT(0); - while (isspace((unsigned char)*bp)) + while (isspace((unsigned char)*bp)) { bp++; + } break; default: /* Unknown/unsupported conversion. */ diff --git a/lib/isc/unix/dir.c b/lib/isc/unix/dir.c index 8beabf5871..77b2e9edaf 100644 --- a/lib/isc/unix/dir.c +++ b/lib/isc/unix/dir.c @@ -70,8 +70,9 @@ isc_dir_open(isc_dir_t *dir, const char *dirname) * Append path separator, if needed, and "*". */ p = dir->dirname + strlen(dir->dirname); - if (dir->dirname < p && *(p - 1) != '/') + if (dir->dirname < p && *(p - 1) != '/') { *p++ = '/'; + } *p++ = '*'; *p = '\0'; @@ -89,7 +90,7 @@ isc_dir_open(isc_dir_t *dir, const char *dirname) /*! * \brief Return previously retrieved file or get next one. - + * * Unix's dirent has * separate open and read functions, but the Win32 and DOS interfaces open * the dir stream and reads the first file in one operation. @@ -106,14 +107,16 @@ isc_dir_read(isc_dir_t *dir) */ entry = readdir(dir->handle); - if (entry == NULL) + if (entry == NULL) { return (ISC_R_NOMORE); + } /* * Make sure that the space for the name is long enough. */ - if (sizeof(dir->entry.name) <= strlen(entry->d_name)) + if (sizeof(dir->entry.name) <= strlen(entry->d_name)) { return (ISC_R_UNEXPECTED); + } strlcpy(dir->entry.name, entry->d_name, sizeof(dir->entry.name)); @@ -159,8 +162,9 @@ isc_dir_chdir(const char *dirname) REQUIRE(dirname != NULL); - if (chdir(dirname) < 0) + if (chdir(dirname) < 0) { return (isc__errno2result(errno)); + } return (ISC_R_SUCCESS); } @@ -170,7 +174,7 @@ isc_dir_chroot(const char *dirname) { #ifdef HAVE_CHROOT void *tmp; -#endif +#endif /* ifdef HAVE_CHROOT */ REQUIRE(dirname != NULL); @@ -182,16 +186,18 @@ isc_dir_chroot(const char *dirname) * Do not report errors if it fails, we do not need any result now. */ tmp = getprotobyname("udp"); - if (tmp != NULL) + if (tmp != NULL) { (void)getservbyname("domain", "udp"); + } - if (chroot(dirname) < 0 || chdir("/") < 0) + if (chroot(dirname) < 0 || chdir("/") < 0) { return (isc__errno2result(errno)); + } return (ISC_R_SUCCESS); -#else +#else /* ifdef HAVE_CHROOT */ return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef HAVE_CHROOT */ } isc_result_t @@ -215,26 +221,28 @@ isc_dir_createunique(char *templet) * Replace trailing Xs with the process-id, zero-filled. */ for (x = templet + strlen(templet) - 1; *x == 'X' && x >= templet; - x--, pid /= 10) + x--, pid /= 10) { *x = pid % 10 + '0'; + } x++; /* Set x to start of ex-Xs. */ do { i = mkdir(templet, 0700); - if (i == 0 || errno != EEXIST) + if (i == 0 || errno != EEXIST) { break; + } /* * The BSD algorithm. */ p = x; while (*p != '\0') { - if (isdigit(*p & 0xff)) + if (isdigit(*p & 0xff)) { *p = 'a'; - else if (*p != 'z') + } else if (*p != 'z') { ++*p; - else { + } else { /* * Reset character and move to next. */ @@ -256,10 +264,11 @@ isc_dir_createunique(char *templet) } } while (1); - if (i == -1) + if (i == -1) { result = isc__errno2result(errno); - else + } else { result = ISC_R_SUCCESS; + } return (result); } diff --git a/lib/isc/unix/errno2result.c b/lib/isc/unix/errno2result.c index 71ff37000f..5e349c0dcb 100644 --- a/lib/isc/unix/errno2result.c +++ b/lib/isc/unix/errno2result.c @@ -57,57 +57,57 @@ isc___errno2result(int posixerrno, bool dolog, const char *file, #ifdef EDQUOT case EDQUOT: return (ISC_R_DISCQUOTA); -#endif +#endif /* ifdef EDQUOT */ case ENOSPC: return (ISC_R_DISCFULL); #ifdef EOVERFLOW case EOVERFLOW: return (ISC_R_RANGE); -#endif +#endif /* ifdef EOVERFLOW */ case EPIPE: #ifdef ECONNRESET case ECONNRESET: -#endif +#endif /* ifdef ECONNRESET */ #ifdef ECONNABORTED case ECONNABORTED: -#endif +#endif /* ifdef ECONNABORTED */ return (ISC_R_CONNECTIONRESET); #ifdef ENOTCONN case ENOTCONN: return (ISC_R_NOTCONNECTED); -#endif +#endif /* ifdef ENOTCONN */ #ifdef ETIMEDOUT case ETIMEDOUT: return (ISC_R_TIMEDOUT); -#endif +#endif /* ifdef ETIMEDOUT */ #ifdef ENOBUFS case ENOBUFS: return (ISC_R_NORESOURCES); -#endif +#endif /* ifdef ENOBUFS */ #ifdef EAFNOSUPPORT case EAFNOSUPPORT: return (ISC_R_FAMILYNOSUPPORT); -#endif +#endif /* ifdef EAFNOSUPPORT */ #ifdef ENETDOWN case ENETDOWN: return (ISC_R_NETDOWN); -#endif +#endif /* ifdef ENETDOWN */ #ifdef EHOSTDOWN case EHOSTDOWN: return (ISC_R_HOSTDOWN); -#endif +#endif /* ifdef EHOSTDOWN */ #ifdef ENETUNREACH case ENETUNREACH: return (ISC_R_NETUNREACH); -#endif +#endif /* ifdef ENETUNREACH */ #ifdef EHOSTUNREACH case EHOSTUNREACH: return (ISC_R_HOSTUNREACH); -#endif +#endif /* ifdef EHOSTUNREACH */ #ifdef EADDRINUSE case EADDRINUSE: return (ISC_R_ADDRINUSE); -#endif +#endif /* ifdef EADDRINUSE */ case EADDRNOTAVAIL: return (ISC_R_ADDRNOTAVAIL); case ECONNREFUSED: diff --git a/lib/isc/unix/file.c b/lib/isc/unix/file.c index 9fdba4b5be..7143ed704b 100644 --- a/lib/isc/unix/file.c +++ b/lib/isc/unix/file.c @@ -54,7 +54,7 @@ #ifdef HAVE_SYS_MMAN_H #include -#endif +#endif /* ifdef HAVE_SYS_MMAN_H */ #include #include @@ -86,8 +86,9 @@ file_stats(const char *file, struct stat *stats) REQUIRE(file != NULL); REQUIRE(stats != NULL); - if (stat(file, stats) != 0) + if (stat(file, stats) != 0) { result = isc__errno2result(errno); + } return (result); } @@ -99,8 +100,9 @@ fd_stats(int fd, struct stat *stats) REQUIRE(stats != NULL); - if (fstat(fd, stats) != 0) + if (fstat(fd, stats) != 0) { result = isc__errno2result(errno); + } return (result); } @@ -115,8 +117,9 @@ isc_file_getsizefd(int fd, off_t *size) result = fd_stats(fd, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *size = stats.st_size; + } return (result); } @@ -130,8 +133,9 @@ isc_file_mode(const char *file, mode_t *modep) REQUIRE(modep != NULL); result = file_stats(file, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *modep = (stats.st_mode & 07777); + } return (result); } @@ -147,12 +151,13 @@ isc_file_getmodtime(const char *file, isc_time_t *modtime) result = file_stats(file, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { #if defined(HAVE_STAT_NSEC) isc_time_set(modtime, stats.st_mtime, stats.st_mtim.tv_nsec); -#else +#else /* if defined(HAVE_STAT_NSEC) */ isc_time_set(modtime, stats.st_mtime, 0); -#endif +#endif /* if defined(HAVE_STAT_NSEC) */ + } return (result); } @@ -168,8 +173,9 @@ isc_file_getsize(const char *file, off_t *size) result = file_stats(file, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *size = stats.st_size; + } return (result); } @@ -197,8 +203,9 @@ isc_file_settime(const char *file, isc_time_t *when) * Here is the real check for the high bit being set. */ if ((times[0].tv_sec & - (1ULL << (sizeof(times[0].tv_sec) * CHAR_BIT - 1))) != 0) + (1ULL << (sizeof(times[0].tv_sec) * CHAR_BIT - 1))) != 0) { return (ISC_R_RANGE); + } /* * isc_time_nanoseconds guarantees a value that divided by 1000 will @@ -207,8 +214,9 @@ isc_file_settime(const char *file, isc_time_t *when) times[0].tv_usec = times[1].tv_usec = (int32_t)(isc_time_nanoseconds(when) / 1000); - if (utimes(file, times) < 0) + if (utimes(file, times) < 0) { return (isc__errno2result(errno)); + } return (ISC_R_SUCCESS); } @@ -231,26 +239,30 @@ isc_file_template(const char *path, const char *templet, char *buf, REQUIRE(templet != NULL); REQUIRE(buf != NULL); - if (path == NULL) + if (path == NULL) { path = ""; + } s = strrchr(templet, '/'); - if (s != NULL) + if (s != NULL) { templet = s + 1; + } s = strrchr(path, '/'); if (s != NULL) { size_t prefixlen = s - path + 1; - if ((prefixlen + strlen(templet) + 1) > buflen) + if ((prefixlen + strlen(templet) + 1) > buflen) { return (ISC_R_NOSPACE); + } /* Copy 'prefixlen' bytes and NUL terminate. */ strlcpy(buf, path, ISC_MIN(prefixlen + 1, buflen)); strlcat(buf, templet, buflen); } else { - if ((strlen(templet) + 1) > buflen) + if ((strlen(templet) + 1) > buflen) { return (ISC_R_NOSPACE); + } strlcpy(buf, templet, buflen); } @@ -271,10 +283,12 @@ isc_file_renameunique(const char *file, char *templet) REQUIRE(templet != NULL); cp = templet; - while (*cp != '\0') + while (*cp != '\0') { cp++; - if (cp == templet) + } + if (cp == templet) { return (ISC_R_FAILURE); + } x = cp--; while (cp >= templet && *cp == 'X') { @@ -282,16 +296,18 @@ isc_file_renameunique(const char *file, char *templet) x = cp--; } while (link(file, templet) == -1) { - if (errno != EEXIST) + if (errno != EEXIST) { return (isc__errno2result(errno)); + } for (cp = x;;) { const char *t; - if (*cp == '\0') + if (*cp == '\0') { return (ISC_R_FAILURE); + } t = strchr(alphnum, *cp); - if (t == NULL || *++t == '\0') + if (t == NULL || *++t == '\0') { *cp++ = alphnum[0]; - else { + } else { *cp = *t; break; } @@ -332,10 +348,12 @@ isc_file_openuniquemode(char *templet, int mode, FILE **fp) REQUIRE(fp != NULL && *fp == NULL); cp = templet; - while (*cp != '\0') + while (*cp != '\0') { cp++; - if (cp == templet) + } + if (cp == templet) { return (ISC_R_FAILURE); + } x = cp--; while (cp >= templet && *cp == 'X') { @@ -344,16 +362,18 @@ isc_file_openuniquemode(char *templet, int mode, FILE **fp) } while ((fd = open(templet, O_RDWR | O_CREAT | O_EXCL, mode)) == -1) { - if (errno != EEXIST) + if (errno != EEXIST) { return (isc__errno2result(errno)); + } for (cp = x;;) { char *t; - if (*cp == '\0') + if (*cp == '\0') { return (ISC_R_FAILURE); + } t = strchr(alphnum, *cp); - if (t == NULL || *++t == '\0') + if (t == NULL || *++t == '\0') { *cp++ = alphnum[0]; - else { + } else { *cp = *t; break; } @@ -368,8 +388,9 @@ isc_file_openuniquemode(char *templet, int mode, FILE **fp) "remove '%s': failed", templet); } (void)close(fd); - } else + } else { *fp = f; + } return (result); } @@ -402,10 +423,11 @@ isc_file_remove(const char *filename) REQUIRE(filename != NULL); r = unlink(filename); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -417,10 +439,11 @@ isc_file_rename(const char *oldname, const char *newname) REQUIRE(newname != NULL); r = rename(oldname, newname); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } bool @@ -442,11 +465,13 @@ isc_file_isplainfile(const char *filename) struct stat filestat; memset(&filestat, 0, sizeof(struct stat)); - if ((stat(filename, &filestat)) == -1) + if ((stat(filename, &filestat)) == -1) { return (isc__errno2result(errno)); + } - if (!S_ISREG(filestat.st_mode)) + if (!S_ISREG(filestat.st_mode)) { return (ISC_R_INVALIDFILE); + } return (ISC_R_SUCCESS); } @@ -460,11 +485,13 @@ isc_file_isplainfilefd(int fd) struct stat filestat; memset(&filestat, 0, sizeof(struct stat)); - if ((fstat(fd, &filestat)) == -1) + if ((fstat(fd, &filestat)) == -1) { return (isc__errno2result(errno)); + } - if (!S_ISREG(filestat.st_mode)) + if (!S_ISREG(filestat.st_mode)) { return (ISC_R_INVALIDFILE); + } return (ISC_R_SUCCESS); } @@ -479,11 +506,13 @@ isc_file_isdirectory(const char *filename) struct stat filestat; memset(&filestat, 0, sizeof(struct stat)); - if ((stat(filename, &filestat)) == -1) + if ((stat(filename, &filestat)) == -1) { return (isc__errno2result(errno)); + } - if (!S_ISDIR(filestat.st_mode)) + if (!S_ISDIR(filestat.st_mode)) { return (ISC_R_INVALIDFILE); + } return (ISC_R_SUCCESS); } @@ -506,10 +535,12 @@ bool isc_file_ischdiridempotent(const char *filename) { REQUIRE(filename != NULL); - if (isc_file_isabsolute(filename)) + if (isc_file_isabsolute(filename)) { return (true); - if (isc_file_iscurrentdir(filename)) + } + if (isc_file_iscurrentdir(filename)) { return (true); + } return (false); } @@ -521,8 +552,9 @@ isc_file_basename(const char *filename) REQUIRE(filename != NULL); s = strrchr(filename, '/'); - if (s == NULL) + if (s == NULL) { return (filename); + } return (s + 1); } @@ -539,8 +571,9 @@ isc_file_progname(const char *filename, char *buf, size_t buflen) base = isc_file_basename(filename); len = strlen(base) + 1; - if (len > buflen) + if (len > buflen) { return (ISC_R_NOSPACE); + } memmove(buf, base, len); return (ISC_R_SUCCESS); @@ -585,10 +618,12 @@ isc_file_absolutepath(const char *filename, char *path, size_t pathlen) { isc_result_t result; result = dir_current(path, pathlen); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (strlen(path) + strlen(filename) + 1 > pathlen) + } + if (strlen(path) + strlen(filename) + 1 > pathlen) { return (ISC_R_NOSPACE); + } strlcat(path, filename, pathlen); return (ISC_R_SUCCESS); } @@ -598,8 +633,9 @@ isc_file_truncate(const char *filename, isc_offset_t size) { isc_result_t result = ISC_R_SUCCESS; - if (truncate(filename, size) < 0) + if (truncate(filename, size) < 0) { result = isc__errno2result(errno); + } return (result); } @@ -617,17 +653,20 @@ isc_file_safecreate(const char *filename, FILE **fp) result = file_stats(filename, &sb); if (result == ISC_R_SUCCESS) { - if ((sb.st_mode & S_IFREG) == 0) + if ((sb.st_mode & S_IFREG) == 0) { return (ISC_R_INVALIDFILE); + } flags = O_WRONLY | O_TRUNC; } else if (result == ISC_R_FILENOTFOUND) { flags = O_WRONLY | O_CREAT | O_EXCL; - } else + } else { return (result); + } fd = open(filename, flags, S_IRUSR | S_IWUSR); - if (fd == -1) + if (fd == -1) { return (isc__errno2result(errno)); + } f = fdopen(fd, "w"); if (f == NULL) { @@ -647,8 +686,9 @@ isc_file_splitpath(isc_mem_t *mctx, const char *path, char **dirname, char * dir; const char *file, *slash; - if (path == NULL) + if (path == NULL) { return (ISC_R_INVALIDFILE); + } slash = strrchr(path, '/'); @@ -664,8 +704,9 @@ isc_file_splitpath(isc_mem_t *mctx, const char *path, char **dirname, dir = isc_mem_strdup(mctx, "."); } - if (dir == NULL) + if (dir == NULL) { return (ISC_R_NOMEMORY); + } if (*file == '\0') { isc_mem_free(mctx, dir); @@ -683,32 +724,34 @@ isc_file_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) { #ifdef HAVE_MMAP return (mmap(addr, len, prot, flags, fd, offset)); -#else - void *buf; - ssize_t ret; - off_t end; +#else /* ifdef HAVE_MMAP */ + void * buf; + ssize_t ret; + off_t end; - UNUSED(addr); - UNUSED(prot); - UNUSED(flags); + UNUSED(addr); + UNUSED(prot); + UNUSED(flags); - end = lseek(fd, 0, SEEK_END); - lseek(fd, offset, SEEK_SET); - if (end - offset < (off_t)len) - len = end - offset; + end = lseek(fd, 0, SEEK_END); + lseek(fd, offset, SEEK_SET); + if (end - offset < (off_t)len) { + len = end - offset; + } - buf = malloc(len); - if (buf == NULL) - return (NULL); + buf = malloc(len); + if (buf == NULL) { + return (NULL); + } - ret = read(fd, buf, len); - if (ret != (ssize_t)len) { - free(buf); - buf = NULL; - } + ret = read(fd, buf, len); + if (ret != (ssize_t)len) { + free(buf); + buf = NULL; + } - return (buf); -#endif + return (buf); +#endif /* ifdef HAVE_MMAP */ } int @@ -716,12 +759,12 @@ isc_file_munmap(void *addr, size_t len) { #ifdef HAVE_MMAP return (munmap(addr, len)); -#else - UNUSED(len); +#else /* ifdef HAVE_MMAP */ + UNUSED(len); - free(addr); - return (0); -#endif + free(addr); + return (0); +#endif /* ifdef HAVE_MMAP */ } #define DISALLOW "\\/ABCDEFGHIJKLMNOPQRSTUVWXYZ" @@ -762,16 +805,20 @@ isc_file_sanitize(const char *dir, const char *base, const char *ext, * allow room for a full sha256 hash (64 chars * plus null terminator) */ - if (l < 65U) + if (l < 65U) { l = 65; + } - if (dir != NULL) + if (dir != NULL) { l += strlen(dir) + 1; - if (ext != NULL) + } + if (ext != NULL) { l += strlen(ext) + 1; + } - if (l > length || l > (unsigned)PATH_MAX) + if (l > length || l > (unsigned)PATH_MAX) { return (ISC_R_NOSPACE); + } /* Check whether the full-length SHA256 hash filename exists */ err = isc_md(ISC_MD_SHA256, (const unsigned char *)base, strlen(base), diff --git a/lib/isc/unix/fsaccess.c b/lib/isc/unix/fsaccess.c index b3ff1da630..8acf65e927 100644 --- a/lib/isc/unix/fsaccess.c +++ b/lib/isc/unix/fsaccess.c @@ -32,17 +32,20 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) isc_fsaccess_t bits; isc_result_t result; - if (stat(path, &statb) != 0) + if (stat(path, &statb) != 0) { return (isc__errno2result(errno)); + } - if ((statb.st_mode & S_IFDIR) != 0) + if ((statb.st_mode & S_IFDIR) != 0) { is_dir = true; - else if ((statb.st_mode & S_IFREG) == 0) + } else if ((statb.st_mode & S_IFREG) == 0) { return (ISC_R_INVALIDFILE); + } result = check_bad_bits(access, is_dir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Done with checking bad bits. Set mode_t. @@ -76,8 +79,9 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) INSIST(access == 0); - if (chmod(path, mode) < 0) + if (chmod(path, mode) < 0) { return (isc__errno2result(errno)); + } return (ISC_R_SUCCESS); } diff --git a/lib/isc/unix/ifiter_getifaddrs.c b/lib/isc/unix/ifiter_getifaddrs.c index 4df7061bdd..cb3ee49f4d 100644 --- a/lib/isc/unix/ifiter_getifaddrs.c +++ b/lib/isc/unix/ifiter_getifaddrs.c @@ -26,7 +26,7 @@ #ifdef __linux static bool seenv6 = false; -#endif +#endif /* ifdef __linux */ /*% Iterator structure */ struct isc_interfaceiter { @@ -42,7 +42,7 @@ struct isc_interfaceiter { FILE * proc; char entry[ISC_IF_INET6_SZ]; isc_result_t valid; -#endif +#endif /* ifdef __linux */ }; isc_result_t @@ -67,12 +67,13 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) * Only open "/proc/net/if_inet6" if we have never seen a IPv6 * address returned by getifaddrs(). */ - if (!seenv6) + if (!seenv6) { iter->proc = fopen("/proc/net/if_inet6", "r"); - else + } else { iter->proc = NULL; + } iter->valid = ISC_R_FAILURE; -#endif +#endif /* ifdef __linux */ if (getifaddrs(&iter->ifaddrs) < 0) { strerror_r(errno, strbuf, sizeof(strbuf)); @@ -96,11 +97,13 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) failure: #ifdef __linux - if (iter->proc != NULL) + if (iter->proc != NULL) { fclose(iter->proc); -#endif - if (iter->ifaddrs != NULL) /* just in case */ + } +#endif /* ifdef __linux */ + if (iter->ifaddrs != NULL) { /* just in case */ freeifaddrs(iter->ifaddrs); + } isc_mem_put(mctx, iter, sizeof(*iter)); return (result); } @@ -124,57 +127,67 @@ internal_current(isc_interfaceiter_t *iter) ifa = iter->pos; #ifdef __linux - if (iter->pos == NULL) + if (iter->pos == NULL) { return (linux_if_inet6_current(iter)); -#endif + } +#endif /* ifdef __linux */ INSIST(ifa != NULL); INSIST(ifa->ifa_name != NULL); - if (ifa->ifa_addr == NULL) + if (ifa->ifa_addr == NULL) { return (ISC_R_IGNORE); + } family = ifa->ifa_addr->sa_family; - if (family != AF_INET && family != AF_INET6) + if (family != AF_INET && family != AF_INET6) { return (ISC_R_IGNORE); + } #ifdef __linux - if (family == AF_INET6) + if (family == AF_INET6) { seenv6 = true; -#endif + } +#endif /* ifdef __linux */ memset(&iter->current, 0, sizeof(iter->current)); namelen = strlen(ifa->ifa_name); - if (namelen > sizeof(iter->current.name) - 1) + if (namelen > sizeof(iter->current.name) - 1) { namelen = sizeof(iter->current.name) - 1; + } memset(iter->current.name, 0, sizeof(iter->current.name)); memmove(iter->current.name, ifa->ifa_name, namelen); iter->current.flags = 0; - if ((ifa->ifa_flags & IFF_UP) != 0) + if ((ifa->ifa_flags & IFF_UP) != 0) { iter->current.flags |= INTERFACE_F_UP; + } - if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0) + if ((ifa->ifa_flags & IFF_POINTOPOINT) != 0) { iter->current.flags |= INTERFACE_F_POINTTOPOINT; + } - if ((ifa->ifa_flags & IFF_LOOPBACK) != 0) + if ((ifa->ifa_flags & IFF_LOOPBACK) != 0) { iter->current.flags |= INTERFACE_F_LOOPBACK; + } iter->current.af = family; get_addr(family, &iter->current.address, ifa->ifa_addr, ifa->ifa_name); - if (ifa->ifa_netmask != NULL) + if (ifa->ifa_netmask != NULL) { get_addr(family, &iter->current.netmask, ifa->ifa_netmask, ifa->ifa_name); + } if (ifa->ifa_dstaddr != NULL && - (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) + (iter->current.flags & INTERFACE_F_POINTTOPOINT) != 0) { get_addr(family, &iter->current.dstaddress, ifa->ifa_dstaddr, ifa->ifa_name); + } return (ISC_R_SUCCESS); } @@ -189,13 +202,15 @@ internal_current(isc_interfaceiter_t *iter) static isc_result_t internal_next(isc_interfaceiter_t *iter) { - if (iter->pos != NULL) + if (iter->pos != NULL) { iter->pos = iter->pos->ifa_next; + } if (iter->pos == NULL) { #ifdef __linux - if (!seenv6) + if (!seenv6) { return (linux_if_inet6_next(iter)); -#endif + } +#endif /* ifdef __linux */ return (ISC_R_NOMORE); } @@ -206,12 +221,14 @@ static void internal_destroy(isc_interfaceiter_t *iter) { #ifdef __linux - if (iter->proc != NULL) + if (iter->proc != NULL) { fclose(iter->proc); + } iter->proc = NULL; -#endif - if (iter->ifaddrs) +#endif /* ifdef __linux */ + if (iter->ifaddrs) { freeifaddrs(iter->ifaddrs); + } iter->ifaddrs = NULL; } @@ -220,6 +237,6 @@ internal_first(isc_interfaceiter_t *iter) { #ifdef __linux linux_if_inet6_first(iter); -#endif +#endif /* ifdef __linux */ iter->pos = iter->ifaddrs; } diff --git a/lib/isc/unix/include/isc/align.h b/lib/isc/unix/include/isc/align.h index 3517f07db9..c627246a92 100644 --- a/lib/isc/unix/include/isc/align.h +++ b/lib/isc/unix/include/isc/align.h @@ -13,6 +13,6 @@ #ifdef HAVE_STDALIGN_H #include -#else +#else /* ifdef HAVE_STDALIGN_H */ #define alignas(x) __attribute__((__aligned__(x))) -#endif +#endif /* ifdef HAVE_STDALIGN_H */ diff --git a/lib/isc/unix/include/isc/net.h b/lib/isc/unix/include/isc/net.h index 982eb8caa0..2cfdaae5be 100644 --- a/lib/isc/unix/include/isc/net.h +++ b/lib/isc/unix/include/isc/net.h @@ -13,8 +13,8 @@ #define ISC_NET_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief @@ -87,15 +87,15 @@ } \ } \ } -#else +#else /* ifdef s6_addr */ #define IN6ADDR_LOOPBACK_INIT \ { \ { \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 \ } \ } -#endif -#endif +#endif /* ifdef s6_addr */ +#endif /* ifndef IN6ADDR_LOOPBACK_INIT */ #ifndef IN6ADDR_V4MAPPED_INIT #ifdef s6_addr @@ -109,22 +109,22 @@ } \ } \ } -#else +#else /* ifdef s6_addr */ #define IN6ADDR_V4MAPPED_INIT \ { \ { \ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0 \ } \ } -#endif -#endif +#endif /* ifdef s6_addr */ +#endif /* ifndef IN6ADDR_V4MAPPED_INIT */ #ifndef IN6_IS_ADDR_V4MAPPED /*% Is IPv6 address V4 mapped? */ #define IN6_IS_ADDR_V4MAPPED(x) \ (memcmp((x)->s6_addr, in6addr_any.s6_addr, 10) == 0 && \ (x)->s6_addr[10] == 0xff && (x)->s6_addr[11] == 0xff) -#endif +#endif /* ifndef IN6_IS_ADDR_V4MAPPED */ #ifndef IN6_IS_ADDR_V4COMPAT /*% Is IPv6 address V4 compatible? */ @@ -133,50 +133,50 @@ ((x)->s6_addr[12] != 0 || (x)->s6_addr[13] != 0 || \ (x)->s6_addr[14] != 0 || \ ((x)->s6_addr[15] != 0 && (x)->s6_addr[15] != 1))) -#endif +#endif /* ifndef IN6_IS_ADDR_V4COMPAT */ #ifndef IN6_IS_ADDR_MULTICAST /*% Is IPv6 address multicast? */ #define IN6_IS_ADDR_MULTICAST(a) ((a)->s6_addr[0] == 0xff) -#endif +#endif /* ifndef IN6_IS_ADDR_MULTICAST */ #ifndef IN6_IS_ADDR_LINKLOCAL /*% Is IPv6 address linklocal? */ #define IN6_IS_ADDR_LINKLOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) -#endif +#endif /* ifndef IN6_IS_ADDR_LINKLOCAL */ #ifndef IN6_IS_ADDR_SITELOCAL /*% is IPv6 address sitelocal? */ #define IN6_IS_ADDR_SITELOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) -#endif +#endif /* ifndef IN6_IS_ADDR_SITELOCAL */ #ifndef IN6_IS_ADDR_LOOPBACK /*% is IPv6 address loopback? */ #define IN6_IS_ADDR_LOOPBACK(x) \ (memcmp((x)->s6_addr, in6addr_loopback.s6_addr, 16) == 0) -#endif +#endif /* ifndef IN6_IS_ADDR_LOOPBACK */ #ifndef AF_INET6 /*% IPv6 */ #define AF_INET6 99 -#endif +#endif /* ifndef AF_INET6 */ #ifndef PF_INET6 /*% IPv6 */ #define PF_INET6 AF_INET6 -#endif +#endif /* ifndef PF_INET6 */ #ifndef INADDR_ANY /*% inaddr any */ #define INADDR_ANY 0x00000000UL -#endif +#endif /* ifndef INADDR_ANY */ #ifndef INADDR_LOOPBACK /*% inaddr loopback */ #define INADDR_LOOPBACK 0x7f000001UL -#endif +#endif /* ifndef INADDR_LOOPBACK */ #ifndef MSG_TRUNC /*% @@ -185,7 +185,7 @@ * faking code in socket.c. */ #define ISC_PLATFORM_RECVOVERFLOW -#endif +#endif /* ifndef MSG_TRUNC */ /*% IP address. */ #define ISC__IPADDR(x) ((uint32_t)htonl((uint32_t)(x))) diff --git a/lib/isc/unix/include/isc/netdb.h b/lib/isc/unix/include/isc/netdb.h index 4cd79a2005..6132857186 100644 --- a/lib/isc/unix/include/isc/netdb.h +++ b/lib/isc/unix/include/isc/netdb.h @@ -13,8 +13,8 @@ #define ISC_NETDB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief diff --git a/lib/isc/unix/include/isc/stat.h b/lib/isc/unix/include/isc/stat.h index 3f89be9f88..05b8f4100b 100644 --- a/lib/isc/unix/include/isc/stat.h +++ b/lib/isc/unix/include/isc/stat.h @@ -13,8 +13,8 @@ #define ISC_STAT_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /* * Portable support. diff --git a/lib/isc/unix/include/isc/stdatomic.h b/lib/isc/unix/include/isc/stdatomic.h index cc27ac33a7..3fb127334d 100644 --- a/lib/isc/unix/include/isc/stdatomic.h +++ b/lib/isc/unix/include/isc/stdatomic.h @@ -16,20 +16,20 @@ #if !defined(__has_feature) #define __has_feature(x) 0 -#endif +#endif /* if !defined(__has_feature) */ #if !defined(__has_extension) #define __has_extension(x) __has_feature(x) -#endif +#endif /* if !defined(__has_extension) */ #if !defined(__GNUC_PREREQ__) #if defined(__GNUC__) && defined(__GNUC_MINOR__) #define __GNUC_PREREQ__(maj, min) \ ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min)) -#else +#else /* if defined(__GNUC__) && defined(__GNUC_MINOR__) */ #define __GNUC_PREREQ__(maj, min) 0 -#endif -#endif +#endif /* if defined(__GNUC__) && defined(__GNUC_MINOR__) */ +#endif /* if !defined(__GNUC_PREREQ__) */ #if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS) #if __has_extension(c_atomic) || __has_extension(cxx_atomic) @@ -38,29 +38,29 @@ #define __GNUC_ATOMICS #elif !defined(__GNUC__) #error "isc/stdatomic.h does not support your compiler" -#endif -#endif +#endif /* if __has_extension(c_atomic) || __has_extension(cxx_atomic) */ +#endif /* if !defined(__CLANG_ATOMICS) && !defined(__GNUC_ATOMICS) */ #define ATOMIC_VAR_INIT(x) x #ifndef __ATOMIC_RELAXED #define __ATOMIC_RELAXED 0 -#endif +#endif /* ifndef __ATOMIC_RELAXED */ #ifndef __ATOMIC_CONSUME #define __ATOMIC_CONSUME 1 -#endif +#endif /* ifndef __ATOMIC_CONSUME */ #ifndef __ATOMIC_ACQUIRE #define __ATOMIC_ACQUIRE 2 -#endif +#endif /* ifndef __ATOMIC_ACQUIRE */ #ifndef __ATOMIC_RELEASE #define __ATOMIC_RELEASE 3 -#endif +#endif /* ifndef __ATOMIC_RELEASE */ #ifndef __ATOMIC_ACQ_REL #define __ATOMIC_ACQ_REL 4 -#endif +#endif /* ifndef __ATOMIC_ACQ_REL */ #ifndef __ATOMIC_SEQ_CST #define __ATOMIC_SEQ_CST 5 -#endif +#endif /* ifndef __ATOMIC_SEQ_CST */ enum memory_order { memory_order_relaxed = __ATOMIC_RELAXED, @@ -160,7 +160,7 @@ typedef uint_fast64_t atomic_uintptr_t; #define atomic_exchange_explicit(obj, desired, order) \ __sync_lock_test_and_set(obj, desired) -#endif +#endif /* if defined(__CLANG_ATOMICS) */ #define atomic_load(obj) atomic_load_explicit(obj, memory_order_seq_cst) #define atomic_store(obj, arg) \ diff --git a/lib/isc/unix/interfaceiter.c b/lib/isc/unix/interfaceiter.c index bb5a3a1001..a82476d607 100644 --- a/lib/isc/unix/interfaceiter.c +++ b/lib/isc/unix/interfaceiter.c @@ -15,7 +15,7 @@ #include #ifdef HAVE_SYS_SOCKIO_H #include /* Required for ifiter_ioctl.c. */ -#endif +#endif /* ifdef HAVE_SYS_SOCKIO_H */ #include #include @@ -38,7 +38,7 @@ /* Must follow . */ #ifdef HAVE_NET_IF6_H #include -#endif +#endif /* ifdef HAVE_NET_IF6_H */ #include /* Common utility functions */ @@ -60,7 +60,7 @@ get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src, #if !defined(HAVE_IF_NAMETOINDEX) UNUSED(ifname); -#endif +#endif /* if !defined(HAVE_IF_NAMETOINDEX) */ /* clear any remaining value for safety */ memset(dst, 0, sizeof(*dst)); @@ -75,9 +75,9 @@ get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src, sa6 = (struct sockaddr_in6 *)src; memmove(&dst->type.in6, &sa6->sin6_addr, sizeof(struct in6_addr)); - if (sa6->sin6_scope_id != 0) + if (sa6->sin6_scope_id != 0) { isc_netaddr_setzone(dst, sa6->sin6_scope_id); - else { + } else { /* * BSD variants embed scope zone IDs in the 128bit * address as a kernel internal form. Unfortunately, @@ -116,7 +116,7 @@ get_addr(unsigned int family, isc_netaddr_t *dst, struct sockaddr *src, isc_netaddr_setzone( dst, (uint32_t)zone); } -#endif +#endif /* ifdef HAVE_IF_NAMETOINDEX */ } } } @@ -141,7 +141,7 @@ static isc_result_t linux_if_inet6_current(isc_interfaceiter_t *); static void linux_if_inet6_first(isc_interfaceiter_t *iter); -#endif +#endif /* ifdef __linux */ #include "ifiter_getifaddrs.c" @@ -152,18 +152,20 @@ linux_if_inet6_first(isc_interfaceiter_t *iter) if (iter->proc != NULL) { rewind(iter->proc); (void)linux_if_inet6_next(iter); - } else + } else { iter->valid = ISC_R_NOMORE; + } } static isc_result_t linux_if_inet6_next(isc_interfaceiter_t *iter) { if (iter->proc != NULL && - fgets(iter->entry, sizeof(iter->entry), iter->proc) != NULL) + fgets(iter->entry, sizeof(iter->entry), iter->proc) != NULL) { iter->valid = ISC_R_SUCCESS; - else + } else { iter->valid = ISC_R_NOMORE; + } return (iter->valid); } @@ -177,8 +179,9 @@ linux_if_inet6_current(isc_interfaceiter_t *iter) int res; unsigned int i; - if (iter->valid != ISC_R_SUCCESS) + if (iter->valid != ISC_R_SUCCESS) { return (iter->valid); + } if (iter->proc == NULL) { isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_INTERFACE, ISC_LOG_ERROR, @@ -227,7 +230,7 @@ linux_if_inet6_current(isc_interfaceiter_t *iter) strlcpy(iter->current.name, name, sizeof(iter->current.name)); return (ISC_R_SUCCESS); } -#endif +#endif /* ifdef __linux */ /* * The remaining code is common to the sysctl and ioctl case. @@ -251,11 +254,13 @@ isc_interfaceiter_first(isc_interfaceiter_t *iter) internal_first(iter); for (;;) { result = internal_current(iter); - if (result != ISC_R_IGNORE) + if (result != ISC_R_IGNORE) { break; + } result = internal_next(iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } iter->result = result; return (result); @@ -271,11 +276,13 @@ isc_interfaceiter_next(isc_interfaceiter_t *iter) for (;;) { result = internal_next(iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } result = internal_current(iter); - if (result != ISC_R_IGNORE) + if (result != ISC_R_IGNORE) { break; + } } iter->result = result; return (result); @@ -291,8 +298,9 @@ isc_interfaceiter_destroy(isc_interfaceiter_t **iterp) REQUIRE(VALID_IFITER(iter)); internal_destroy(iter); - if (iter->buf != NULL) + if (iter->buf != NULL) { isc_mem_put(iter->mctx, iter->buf, iter->bufsize); + } iter->magic = 0; isc_mem_put(iter->mctx, iter, sizeof(*iter)); diff --git a/lib/isc/unix/meminfo.c b/lib/isc/unix/meminfo.c index ddb6d3f1bc..80f4116581 100644 --- a/lib/isc/unix/meminfo.c +++ b/lib/isc/unix/meminfo.c @@ -15,7 +15,7 @@ #include #if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux__) #include -#endif +#endif /* if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux__) */ uint64_t isc_meminfo_totalphys(void) @@ -27,14 +27,16 @@ isc_meminfo_totalphys(void) mib[1] = HW_MEMSIZE; #elif defined(HW_PHYSMEM64) mib[1] = HW_PHYSMEM64; -#endif +#endif /* if defined(HW_MEMSIZE) */ uint64_t size = 0; size_t len = sizeof(size); - if (sysctl(mib, 2, &size, &len, NULL, 0) == 0) + if (sysctl(mib, 2, &size, &len, NULL, 0) == 0) { return (size); -#endif + } +#endif /* if defined(CTL_HW) && (defined(HW_PHYSMEM64) || defined(HW_MEMSIZE)) \ + * */ #if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) return ((size_t)(sysconf(_SC_PHYS_PAGES) * sysconf(_SC_PAGESIZE))); -#endif +#endif /* if defined(_SC_PHYS_PAGES) && defined(_SC_PAGESIZE) */ return (0); } diff --git a/lib/isc/unix/net.c b/lib/isc/unix/net.c index 83b8d49767..0b349ba67e 100644 --- a/lib/isc/unix/net.c +++ b/lib/isc/unix/net.c @@ -16,9 +16,9 @@ #if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux__) #if defined(HAVE_SYS_PARAM_H) #include -#endif +#endif /* if defined(HAVE_SYS_PARAM_H) */ #include -#endif +#endif /* if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux__) */ #include #include #include @@ -35,7 +35,7 @@ #ifndef socklen_t #define socklen_t unsigned int -#endif +#endif /* ifndef socklen_t */ /*% * Definitions about UDP port range specification. This is a total mess of @@ -65,7 +65,8 @@ #define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.portrange.hilast" #define SYSCTL_V6PORTRANGE_LOW "net.inet.ip.portrange.hifirst" #define SYSCTL_V6PORTRANGE_HIGH "net.inet.ip.portrange.hilast" -#endif +#endif /* if defined(__FreeBSD__) || defined(__APPLE__) || \ + * defined(__DragonFly__) */ #ifdef __NetBSD__ #define USE_SYSCTL_PORTRANGE @@ -73,7 +74,7 @@ #define SYSCTL_V4PORTRANGE_HIGH "net.inet.ip.anonportmax" #define SYSCTL_V6PORTRANGE_LOW "net.inet6.ip6.anonportmin" #define SYSCTL_V6PORTRANGE_HIGH "net.inet6.ip6.anonportmax" -#endif +#endif /* ifdef __NetBSD__ */ #else /* !HAVE_SYSCTLBYNAME */ @@ -90,14 +91,14 @@ /* Same for IPv6 */ #define SYSCTL_V6PORTRANGE_LOW SYSCTL_V4PORTRANGE_LOW #define SYSCTL_V6PORTRANGE_HIGH SYSCTL_V4PORTRANGE_HIGH -#endif +#endif /* ifdef __OpenBSD__ */ #endif /* HAVE_SYSCTLBYNAME */ static isc_once_t once_ipv6only = ISC_ONCE_INIT; #ifdef __notyet__ static isc_once_t once_ipv6pktinfo = ISC_ONCE_INIT; -#endif +#endif /* ifdef __notyet__ */ #ifndef ISC_CMSG_IP_TOS #ifdef __APPLE__ @@ -129,16 +130,16 @@ try_proto(int domain) switch (errno) { #ifdef EAFNOSUPPORT case EAFNOSUPPORT: -#endif +#endif /* ifdef EAFNOSUPPORT */ #ifdef EPFNOSUPPORT case EPFNOSUPPORT: -#endif +#endif /* ifdef EPFNOSUPPORT */ #ifdef EPROTONOSUPPORT case EPROTONOSUPPORT: -#endif +#endif /* ifdef EPROTONOSUPPORT */ #ifdef EINVAL case EINVAL: -#endif +#endif /* ifdef EINVAL */ return (ISC_R_NOTFOUND); default: strerror_r(errno, strbuf, sizeof(strbuf)); @@ -167,9 +168,9 @@ try_proto(int domain) "IPv6 is not supported."); result = ISC_R_NOTFOUND; } else { - if (len == sizeof(struct sockaddr_in6)) + if (len == sizeof(struct sockaddr_in6)) { result = ISC_R_SUCCESS; - else { + } else { isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR, @@ -196,7 +197,7 @@ initialize_action(void) ipv6_result = try_proto(PF_INET6); #ifdef ISC_PLATFORM_HAVESYSUNH unix_result = try_proto(PF_UNIX); -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } static void @@ -232,7 +233,7 @@ try_ipv6only(void) #ifdef IPV6_V6ONLY int s, on; char strbuf[ISC_STRERRORSIZE]; -#endif +#endif /* ifdef IPV6_V6ONLY */ isc_result_t result; result = isc_net_probeipv6(); @@ -244,7 +245,7 @@ try_ipv6only(void) #ifndef IPV6_V6ONLY ipv6only_result = ISC_R_NOTFOUND; return; -#else +#else /* ifndef IPV6_V6ONLY */ /* check for TCP sockets */ s = socket(PF_INET6, SOCK_STREAM, 0); if (s == -1) { @@ -321,9 +322,9 @@ try_ipv6pktinfo(void) #ifdef IPV6_RECVPKTINFO optname = IPV6_RECVPKTINFO; -#else +#else /* ifdef IPV6_RECVPKTINFO */ optname = IPV6_PKTINFO; -#endif +#endif /* ifdef IPV6_RECVPKTINFO */ on = 1; if (setsockopt(s, IPPROTO_IPV6, optname, &on, sizeof(on)) < 0) { ipv6pktinfo_result = ISC_R_NOTFOUND; @@ -343,7 +344,7 @@ initialize_ipv6pktinfo(void) RUNTIME_CHECK(isc_once_do(&once_ipv6pktinfo, try_ipv6pktinfo) == ISC_R_SUCCESS); } -#endif +#endif /* ifdef __notyet__ */ isc_result_t isc_net_probe_ipv6only(void) @@ -366,7 +367,7 @@ isc_net_probe_ipv6pktinfo(void) */ #ifdef __notyet__ initialize_ipv6pktinfo(); -#endif +#endif /* ifdef __notyet__ */ return (ipv6pktinfo_result); } @@ -377,7 +378,7 @@ cmsg_len(socklen_t len) { #ifdef CMSG_LEN return (CMSG_LEN(len)); -#else +#else /* ifdef CMSG_LEN */ socklen_t hdrlen; /* @@ -386,7 +387,7 @@ cmsg_len(socklen_t len) */ hdrlen = (socklen_t)CMSG_DATA(((struct cmsghdr *)NULL)); return (hdrlen + len); -#endif +#endif /* ifdef CMSG_LEN */ } static inline socklen_t @@ -394,7 +395,7 @@ cmsg_space(socklen_t len) { #ifdef CMSG_SPACE return (CMSG_SPACE(len)); -#else +#else /* ifdef CMSG_SPACE */ struct msghdr msg; struct cmsghdr *cmsgp; /* @@ -411,11 +412,12 @@ cmsg_space(socklen_t len) cmsgp->cmsg_len = cmsg_len(len); cmsgp = CMSG_NXTHDR(&msg, cmsgp); - if (cmsgp != NULL) + if (cmsgp != NULL) { return ((char *)cmsgp - (char *)msg.msg_control); - else + } else { return (0); -#endif + } +#endif /* ifdef CMSG_SPACE */ } /* @@ -431,20 +433,20 @@ make_nonblock(int fd) int on = 1; ret = ioctl(fd, FIONBIO, (char *)&on); -#else +#else /* ifdef USE_FIONBIO_IOCTL */ flags = fcntl(fd, F_GETFL, 0); flags |= PORT_NONBLOCK; ret = fcntl(fd, F_SETFL, flags); -#endif +#endif /* ifdef USE_FIONBIO_IOCTL */ if (ret == -1) { strerror_r(errno, strbuf, sizeof(strbuf)); UNEXPECTED_ERROR(__FILE__, __LINE__, #ifdef USE_FIONBIO_IOCTL "ioctl(%d, FIONBIO, &on): %s", fd, -#else +#else /* ifdef USE_FIONBIO_IOCTL */ "fcntl(%d, F_SETFL, %d): %s", fd, flags, -#endif +#endif /* ifdef USE_FIONBIO_IOCTL */ strbuf); return (ISC_R_UNEXPECTED); @@ -510,7 +512,7 @@ cmsgsend(int s, int level, int type, struct addrinfo *res) *(unsigned char *)CMSG_DATA(cmsgp) = dscp; msg.msg_controllen += cmsg_space(sizeof(char)); break; -#endif +#endif /* ifdef IP_TOS */ #ifdef IPV6_TCLASS case IPV6_TCLASS: memset(cmsgp, 0, cmsg_space(sizeof(dscp))); @@ -520,7 +522,7 @@ cmsgsend(int s, int level, int type, struct addrinfo *res) memmove(CMSG_DATA(cmsgp), &dscp, sizeof(dscp)); msg.msg_controllen += cmsg_space(sizeof(dscp)); break; -#endif +#endif /* ifdef IPV6_TCLASS */ default: INSIST(0); ISC_UNREACHABLE(); @@ -532,10 +534,10 @@ cmsgsend(int s, int level, int type, struct addrinfo *res) switch (errno) { #ifdef ENOPROTOOPT case ENOPROTOOPT: -#endif +#endif /* ifdef ENOPROTOOPT */ #ifdef EOPNOTSUPP case EOPNOTSUPP: -#endif +#endif /* ifdef EOPNOTSUPP */ case EINVAL: case EPERM: break; @@ -575,12 +577,13 @@ cmsgsend(int s, int level, int type, struct addrinfo *res) msg.msg_controllen = 0; msg.msg_flags = 0; - if (recvmsg(s, &msg, 0) < 0) + if (recvmsg(s, &msg, 0) < 0) { return (false); + } return (true); } -#endif +#endif /* if ISC_CMSG_IP_TOS || defined(IPV6_TCLASS) */ static void try_dscp_v4(void) @@ -599,9 +602,9 @@ try_dscp_v4(void) hints.ai_protocol = IPPROTO_UDP; #ifdef AI_NUMERICHOST hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; -#else +#else /* ifdef AI_NUMERICHOST */ hints.ai_flags = AI_PASSIVE; -#endif +#endif /* ifdef AI_NUMERICHOST */ n = getaddrinfo("127.0.0.1", NULL, &hints, &res0); if (n != 0 || res0 == NULL) { @@ -622,18 +625,21 @@ try_dscp_v4(void) return; } - if (setsockopt(s, IPPROTO_IP, IP_TOS, &dscp, sizeof(dscp)) == 0) + if (setsockopt(s, IPPROTO_IP, IP_TOS, &dscp, sizeof(dscp)) == 0) { dscp_result |= ISC_NET_DSCPSETV4; + } #ifdef IP_RECVTOS on = 1; - if (setsockopt(s, IPPROTO_IP, IP_RECVTOS, &on, sizeof(on)) == 0) + if (setsockopt(s, IPPROTO_IP, IP_RECVTOS, &on, sizeof(on)) == 0) { dscp_result |= ISC_NET_DSCPRECVV4; + } #endif /* IP_RECVTOS */ #if ISC_CMSG_IP_TOS - if (cmsgsend(s, IPPROTO_IP, IP_TOS, res0)) + if (cmsgsend(s, IPPROTO_IP, IP_TOS, res0)) { dscp_result |= ISC_NET_DSCPPKTV4; + } #endif /* ISC_CMSG_IP_TOS */ freeaddrinfo(res0); @@ -659,9 +665,9 @@ try_dscp_v6(void) hints.ai_protocol = IPPROTO_UDP; #ifdef AI_NUMERICHOST hints.ai_flags = AI_PASSIVE | AI_NUMERICHOST; -#else +#else /* ifdef AI_NUMERICHOST */ hints.ai_flags = AI_PASSIVE; -#endif +#endif /* ifdef AI_NUMERICHOST */ n = getaddrinfo("::1", NULL, &hints, &res0); if (n != 0 || res0 == NULL) { @@ -680,17 +686,22 @@ try_dscp_v6(void) freeaddrinfo(res0); return; } - if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &dscp, sizeof(dscp)) == 0) + if (setsockopt(s, IPPROTO_IPV6, IPV6_TCLASS, &dscp, sizeof(dscp)) == + 0) { dscp_result |= ISC_NET_DSCPSETV6; + } #ifdef IPV6_RECVTCLASS on = 1; - if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVTCLASS, &on, sizeof(on)) == 0) + if (setsockopt(s, IPPROTO_IPV6, IPV6_RECVTCLASS, &on, sizeof(on)) == + 0) { dscp_result |= ISC_NET_DSCPRECVV6; + } #endif /* IPV6_RECVTCLASS */ - if (cmsgsend(s, IPPROTO_IPV6, IPV6_TCLASS, res0)) + if (cmsgsend(s, IPPROTO_IPV6, IPV6_TCLASS, res0)) { dscp_result |= ISC_NET_DSCPPKTV6; + } freeaddrinfo(res0); close(s); @@ -744,8 +755,9 @@ getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) 0) { return (ISC_R_FAILURE); } - if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0) + if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0) { return (ISC_R_RANGE); + } *low = (in_port_t)port_low; *high = (in_port_t)port_high; @@ -784,8 +796,9 @@ getudpportrange_sysctl(int af, in_port_t *low, in_port_t *high) return (ISC_R_FAILURE); } - if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0) + if ((port_low & ~0xffff) != 0 || (port_high & ~0xffff) != 0) { return (ISC_R_RANGE); + } *low = (in_port_t)port_low; *high = (in_port_t)port_high; @@ -801,7 +814,7 @@ isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) int result = ISC_R_FAILURE; #if !defined(USE_SYSCTL_PORTRANGE) && defined(__linux) FILE *fp; -#endif +#endif /* if !defined(USE_SYSCTL_PORTRANGE) && defined(__linux) */ REQUIRE(low != NULL && high != NULL); @@ -827,9 +840,9 @@ isc_net_getudpportrange(int af, in_port_t *low, in_port_t *high) } fclose(fp); } -#else +#else /* if defined(USE_SYSCTL_PORTRANGE) */ UNUSED(af); -#endif +#endif /* if defined(USE_SYSCTL_PORTRANGE) */ if (result != ISC_R_SUCCESS) { *low = ISC_NET_PORTRANGELOW; @@ -843,30 +856,34 @@ void isc_net_disableipv4(void) { initialize(); - if (ipv4_result == ISC_R_SUCCESS) + if (ipv4_result == ISC_R_SUCCESS) { ipv4_result = ISC_R_DISABLED; + } } void isc_net_disableipv6(void) { initialize(); - if (ipv6_result == ISC_R_SUCCESS) + if (ipv6_result == ISC_R_SUCCESS) { ipv6_result = ISC_R_DISABLED; + } } void isc_net_enableipv4(void) { initialize(); - if (ipv4_result == ISC_R_DISABLED) + if (ipv4_result == ISC_R_DISABLED) { ipv4_result = ISC_R_SUCCESS; + } } void isc_net_enableipv6(void) { initialize(); - if (ipv6_result == ISC_R_DISABLED) + if (ipv6_result == ISC_R_DISABLED) { ipv6_result = ISC_R_SUCCESS; + } } diff --git a/lib/isc/unix/os.c b/lib/isc/unix/os.c index fdc833a17d..76e945378d 100644 --- a/lib/isc/unix/os.c +++ b/lib/isc/unix/os.c @@ -19,12 +19,12 @@ static inline long sysconf_ncpus(void) { #if defined(_SC_NPROCESSORS_ONLN) - return sysconf((_SC_NPROCESSORS_ONLN)); + return (sysconf((_SC_NPROCESSORS_ONLN))); #elif defined(_SC_NPROC_ONLN) - return sysconf((_SC_NPROC_ONLN)); -#else + return (sysconf((_SC_NPROC_ONLN))); +#else /* if defined(_SC_NPROCESSORS_ONLN) */ return (0); -#endif +#endif /* if defined(_SC_NPROCESSORS_ONLN) */ } #endif /* HAVE_SYSCONF */ @@ -41,11 +41,12 @@ sysctl_ncpus(void) len = sizeof(ncpu); result = sysctlbyname("hw.ncpu", &ncpu, &len, 0, 0); - if (result != -1) + if (result != -1) { return (ncpu); + } return (0); } -#endif +#endif /* if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME) */ unsigned int isc_os_ncpus(void) @@ -54,13 +55,15 @@ isc_os_ncpus(void) #if defined(HAVE_SYSCONF) ncpus = sysconf_ncpus(); -#endif +#endif /* if defined(HAVE_SYSCONF) */ #if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME) - if (ncpus <= 0) + if (ncpus <= 0) { ncpus = sysctl_ncpus(); -#endif - if (ncpus <= 0) + } +#endif /* if defined(HAVE_SYS_SYSCTL_H) && defined(HAVE_SYSCTLBYNAME) */ + if (ncpus <= 0) { ncpus = 1; + } return ((unsigned int)ncpus); } diff --git a/lib/isc/unix/pk11_api.c b/lib/isc/unix/pk11_api.c index 9764f4e391..e07886e349 100644 --- a/lib/isc/unix/pk11_api.c +++ b/lib/isc/unix/pk11_api.c @@ -36,8 +36,9 @@ pkcs_C_Initialize(CK_VOID_PTR pReserved) { CK_C_Initialize sym; - if (hPK11 != NULL) + if (hPK11 != NULL) { return (CKR_CRYPTOKI_ALREADY_INITIALIZED); + } hPK11 = dlopen(pk11_get_lib_name(), RTLD_NOW); @@ -48,9 +49,10 @@ pkcs_C_Initialize(CK_VOID_PTR pReserved) return (CKR_LIBRARY_LOAD_FAILED); } sym = (CK_C_Initialize)dlsym(hPK11, "C_Initialize"); - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(pReserved); + } + return ((*sym)(pReserved)); } char * @@ -65,14 +67,17 @@ pkcs_C_Finalize(CK_VOID_PTR pReserved) CK_C_Finalize sym; CK_RV rv; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } sym = (CK_C_Finalize)dlsym(hPK11, "C_Finalize"); - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); + } rv = (*sym)(pReserved); - if ((rv == CKR_OK) && (dlclose(hPK11) != 0)) + if ((rv == CKR_OK) && (dlclose(hPK11) != 0)) { return (CKR_LIBRARY_LOAD_FAILED); + } hPK11 = NULL; return (rv); } @@ -84,15 +89,17 @@ pkcs_C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, static CK_C_GetSlotList sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GetSlotList)dlsym(hPK11, "C_GetSlotList"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(tokenPresent, pSlotList, pulCount); + } + return ((*sym)(tokenPresent, pSlotList, pulCount)); } CK_RV @@ -101,15 +108,17 @@ pkcs_C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) static CK_C_GetTokenInfo sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GetTokenInfo)dlsym(hPK11, "C_GetTokenInfo"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(slotID, pInfo); + } + return ((*sym)(slotID, pInfo)); } CK_RV @@ -119,15 +128,17 @@ pkcs_C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, static CK_C_GetMechanismInfo sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GetMechanismInfo)dlsym(hPK11, "C_GetMechanismInfo"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(slotID, type, pInfo); + } + return ((*sym)(slotID, type, pInfo)); } CK_RV @@ -140,8 +151,9 @@ pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, static CK_C_OpenSession sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { hPK11 = dlopen(pk11_get_lib_name(), RTLD_NOW); + } if (hPK11 == NULL) { snprintf(loaderrmsg, sizeof(loaderrmsg), "dlopen(\"%s\") failed: %s\n", pk11_get_lib_name(), @@ -152,9 +164,10 @@ pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, pPK11 = hPK11; sym = (CK_C_OpenSession)dlsym(hPK11, "C_OpenSession"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(slotID, flags, pApplication, Notify, phSession); + } + return ((*sym)(slotID, flags, pApplication, Notify, phSession)); } CK_RV @@ -163,15 +176,17 @@ pkcs_C_CloseSession(CK_SESSION_HANDLE hSession) static CK_C_CloseSession sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_CloseSession)dlsym(hPK11, "C_CloseSession"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession); + } + return ((*sym)(hSession)); } CK_RV @@ -181,15 +196,17 @@ pkcs_C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, static CK_C_Login sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_Login)dlsym(hPK11, "C_Login"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, userType, pPin, usPinLen); + } + return ((*sym)(hSession, userType, pPin, usPinLen)); } CK_RV @@ -198,15 +215,17 @@ pkcs_C_Logout(CK_SESSION_HANDLE hSession) static CK_C_Logout sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_Logout)dlsym(hPK11, "C_Logout"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession); + } + return ((*sym)(hSession)); } CK_RV @@ -216,15 +235,17 @@ pkcs_C_CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, static CK_C_CreateObject sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_CreateObject)dlsym(hPK11, "C_CreateObject"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pTemplate, usCount, phObject); + } + return ((*sym)(hSession, pTemplate, usCount, phObject)); } CK_RV @@ -233,15 +254,17 @@ pkcs_C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) static CK_C_DestroyObject sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_DestroyObject)dlsym(hPK11, "C_DestroyObject"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, hObject); + } + return ((*sym)(hSession, hObject)); } CK_RV @@ -251,16 +274,18 @@ pkcs_C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, static CK_C_GetAttributeValue sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GetAttributeValue)dlsym(hPK11, "C_" "GetAttributeValue"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, hObject, pTemplate, usCount); + } + return ((*sym)(hSession, hObject, pTemplate, usCount)); } CK_RV @@ -270,16 +295,18 @@ pkcs_C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, static CK_C_SetAttributeValue sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_SetAttributeValue)dlsym(hPK11, "C_" "SetAttributeValue"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, hObject, pTemplate, usCount); + } + return ((*sym)(hSession, hObject, pTemplate, usCount)); } CK_RV @@ -289,15 +316,17 @@ pkcs_C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, static CK_C_FindObjectsInit sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_FindObjectsInit)dlsym(hPK11, "C_FindObjectsInit"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pTemplate, usCount); + } + return ((*sym)(hSession, pTemplate, usCount)); } CK_RV @@ -307,15 +336,17 @@ pkcs_C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, static CK_C_FindObjects sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_FindObjects)dlsym(hPK11, "C_FindObjects"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount); + } + return ((*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount)); } CK_RV @@ -324,15 +355,17 @@ pkcs_C_FindObjectsFinal(CK_SESSION_HANDLE hSession) static CK_C_FindObjectsFinal sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_FindObjectsFinal)dlsym(hPK11, "C_FindObjectsFinal"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession); + } + return ((*sym)(hSession)); } CK_RV @@ -342,15 +375,17 @@ pkcs_C_EncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, static CK_C_EncryptInit sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_EncryptInit)dlsym(hPK11, "C_EncryptInit"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism, hKey); + } + return ((*sym)(hSession, pMechanism, hKey)); } CK_RV @@ -361,16 +396,18 @@ pkcs_C_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, static CK_C_Encrypt sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_Encrypt)dlsym(hPK11, "C_Encrypt"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pData, ulDataLen, pEncryptedData, - pulEncryptedDataLen); + } + return ((*sym)(hSession, pData, ulDataLen, pEncryptedData, + pulEncryptedDataLen)); } CK_RV @@ -379,15 +416,17 @@ pkcs_C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism) static CK_C_DigestInit sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_DigestInit)dlsym(hPK11, "C_DigestInit"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism); + } + return ((*sym)(hSession, pMechanism)); } CK_RV @@ -397,15 +436,17 @@ pkcs_C_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, static CK_C_DigestUpdate sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_DigestUpdate)dlsym(hPK11, "C_DigestUpdate"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pPart, ulPartLen); + } + return ((*sym)(hSession, pPart, ulPartLen)); } CK_RV @@ -415,15 +456,17 @@ pkcs_C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, static CK_C_DigestFinal sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_DigestFinal)dlsym(hPK11, "C_DigestFinal"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pDigest, pulDigestLen); + } + return ((*sym)(hSession, pDigest, pulDigestLen)); } CK_RV @@ -433,15 +476,17 @@ pkcs_C_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, static CK_C_SignInit sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_SignInit)dlsym(hPK11, "C_SignInit"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism, hKey); + } + return ((*sym)(hSession, pMechanism, hKey)); } CK_RV @@ -451,15 +496,18 @@ pkcs_C_Sign(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, static CK_C_Sign sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_Sign)dlsym(hPK11, "C_Sign"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pData, ulDataLen, pSignature, pulSignatureLen); + } + return ((*sym)(hSession, pData, ulDataLen, pSignature, + pulSignatureLen)); } CK_RV @@ -469,15 +517,17 @@ pkcs_C_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, static CK_C_SignUpdate sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_SignUpdate)dlsym(hPK11, "C_SignUpdate"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pPart, ulPartLen); + } + return ((*sym)(hSession, pPart, ulPartLen)); } CK_RV @@ -487,15 +537,17 @@ pkcs_C_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, static CK_C_SignFinal sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_SignFinal)dlsym(hPK11, "C_SignFinal"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pSignature, pulSignatureLen); + } + return ((*sym)(hSession, pSignature, pulSignatureLen)); } CK_RV @@ -505,15 +557,17 @@ pkcs_C_VerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, static CK_C_VerifyInit sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_VerifyInit)dlsym(hPK11, "C_VerifyInit"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism, hKey); + } + return ((*sym)(hSession, pMechanism, hKey)); } CK_RV @@ -523,15 +577,17 @@ pkcs_C_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, static CK_C_Verify sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_Verify)dlsym(hPK11, "C_Verify"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pData, ulDataLen, pSignature, ulSignatureLen); + } + return ((*sym)(hSession, pData, ulDataLen, pSignature, ulSignatureLen)); } CK_RV @@ -541,15 +597,17 @@ pkcs_C_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, static CK_C_VerifyUpdate sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_VerifyUpdate)dlsym(hPK11, "C_VerifyUpdate"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pPart, ulPartLen); + } + return ((*sym)(hSession, pPart, ulPartLen)); } CK_RV @@ -559,15 +617,17 @@ pkcs_C_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, static CK_C_VerifyFinal sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_VerifyFinal)dlsym(hPK11, "C_VerifyFinal"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pSignature, ulSignatureLen); + } + return ((*sym)(hSession, pSignature, ulSignatureLen)); } CK_RV @@ -578,15 +638,17 @@ pkcs_C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, static CK_C_GenerateKey sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GenerateKey)dlsym(hPK11, "C_GenerateKey"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism, pTemplate, ulCount, phKey); + } + return ((*sym)(hSession, pMechanism, pTemplate, ulCount, phKey)); } CK_RV @@ -601,17 +663,19 @@ pkcs_C_GenerateKeyPair(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, static CK_C_GenerateKeyPair sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GenerateKeyPair)dlsym(hPK11, "C_GenerateKeyPair"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism, pPublicKeyTemplate, - usPublicKeyAttributeCount, pPrivateKeyTemplate, - usPrivateKeyAttributeCount, phPrivateKey, phPublicKey); + } + return ((*sym)(hSession, pMechanism, pPublicKeyTemplate, + usPublicKeyAttributeCount, pPrivateKeyTemplate, + usPrivateKeyAttributeCount, phPrivateKey, phPublicKey)); } CK_RV @@ -622,16 +686,18 @@ pkcs_C_DeriveKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, static CK_C_DeriveKey sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_DeriveKey)dlsym(hPK11, "C_DeriveKey"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pMechanism, hBaseKey, pTemplate, - ulAttributeCount, phKey); + } + return ((*sym)(hSession, pMechanism, hBaseKey, pTemplate, + ulAttributeCount, phKey)); } CK_RV @@ -641,15 +707,17 @@ pkcs_C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, static CK_C_SeedRandom sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_SeedRandom)dlsym(hPK11, "C_SeedRandom"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, pSeed, ulSeedLen); + } + return ((*sym)(hSession, pSeed, ulSeedLen)); } CK_RV @@ -659,13 +727,15 @@ pkcs_C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR RandomData, static CK_C_GenerateRandom sym = NULL; static void * pPK11 = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_LOAD_FAILED); + } if ((sym == NULL) || (hPK11 != pPK11)) { pPK11 = hPK11; sym = (CK_C_GenerateRandom)dlsym(hPK11, "C_GenerateRandom"); } - if (sym == NULL) + if (sym == NULL) { return (CKR_FUNCTION_NOT_SUPPORTED); - return (*sym)(hSession, RandomData, ulRandomLen); + } + return ((*sym)(hSession, RandomData, ulRandomLen)); } diff --git a/lib/isc/unix/resource.c b/lib/isc/unix/resource.c index bf3b101f75..c7152c5586 100644 --- a/lib/isc/unix/resource.c +++ b/lib/isc/unix/resource.c @@ -23,7 +23,7 @@ #ifdef __linux__ #include /* To get the large NR_OPEN. */ -#endif +#endif /* ifdef __linux__ */ #include "errno2result.h" @@ -48,30 +48,30 @@ resource2rlim(isc_resource_t resource, int *rlim_resource) case isc_resource_lockedmemory: #ifdef RLIMIT_MEMLOCK *rlim_resource = RLIMIT_MEMLOCK; -#else +#else /* ifdef RLIMIT_MEMLOCK */ result = ISC_R_NOTIMPLEMENTED; -#endif +#endif /* ifdef RLIMIT_MEMLOCK */ break; case isc_resource_openfiles: #ifdef RLIMIT_NOFILE *rlim_resource = RLIMIT_NOFILE; -#else +#else /* ifdef RLIMIT_NOFILE */ result = ISC_R_NOTIMPLEMENTED; -#endif +#endif /* ifdef RLIMIT_NOFILE */ break; case isc_resource_processes: #ifdef RLIMIT_NPROC *rlim_resource = RLIMIT_NPROC; -#else +#else /* ifdef RLIMIT_NPROC */ result = ISC_R_NOTIMPLEMENTED; -#endif +#endif /* ifdef RLIMIT_NPROC */ break; case isc_resource_residentsize: #ifdef RLIMIT_RSS *rlim_resource = RLIMIT_RSS; -#else +#else /* ifdef RLIMIT_RSS */ result = ISC_R_NOTIMPLEMENTED; -#endif +#endif /* ifdef RLIMIT_RSS */ break; case isc_resource_stacksize: *rlim_resource = RLIMIT_STACK; @@ -101,13 +101,13 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) isc_result_t result; result = resource2rlim(resource, &unixresource); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (value == ISC_RESOURCE_UNLIMITED) + if (value == ISC_RESOURCE_UNLIMITED) { rlim_value = RLIM_INFINITY; - - else { + } else { /* * isc_resourcevalue_t was chosen as an unsigned 64 bit * integer so that it could contain the maximum range of @@ -118,13 +118,15 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) isc_resourcevalue_t rlim_max; bool rlim_t_is_signed = (((double)(rlim_t)-1) < 0); - if (rlim_t_is_signed) + if (rlim_t_is_signed) { rlim_max = ~((rlim_t)1 << (sizeof(rlim_t) * 8 - 1)); - else + } else { rlim_max = (rlim_t)-1; + } - if (value > rlim_max) + if (value > rlim_max) { value = rlim_max; + } rlim_value = value; } @@ -132,8 +134,9 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) rl.rlim_cur = rl.rlim_max = rlim_value; unixresult = setrlimit(unixresource, &rl); - if (unixresult == 0) + if (unixresult == 0) { return (ISC_R_SUCCESS); + } #if defined(OPEN_MAX) && defined(__APPLE__) /* @@ -145,13 +148,14 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) { rl.rlim_cur = OPEN_MAX; unixresult = setrlimit(unixresource, &rl); - if (unixresult == 0) + if (unixresult == 0) { return (ISC_R_SUCCESS); + } } #elif defined(__linux__) #ifndef NR_OPEN #define NR_OPEN (1024 * 1024) -#endif +#endif /* ifndef NR_OPEN */ /* * Some Linux kernels don't accept RLIM_INFINIT; the maximum @@ -160,16 +164,18 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) { rl.rlim_cur = rl.rlim_max = NR_OPEN; unixresult = setrlimit(unixresource, &rl); - if (unixresult == 0) + if (unixresult == 0) { return (ISC_R_SUCCESS); + } } -#endif +#endif /* if defined(OPEN_MAX) && defined(__APPLE__) */ if (resource == isc_resource_openfiles && rlim_value == RLIM_INFINITY) { if (getrlimit(unixresource, &rl) == 0) { rl.rlim_cur = rl.rlim_max; unixresult = setrlimit(unixresource, &rl); - if (unixresult == 0) + if (unixresult == 0) { return (ISC_R_SUCCESS); + } } } return (isc__errno2result(errno)); diff --git a/lib/isc/unix/socket.c b/lib/isc/unix/socket.c index abed749d3d..65e77a0f2e 100644 --- a/lib/isc/unix/socket.c +++ b/lib/isc/unix/socket.c @@ -20,14 +20,15 @@ #include #if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux__) #include -#endif +#endif /* if defined(HAVE_SYS_SYSCTL_H) && !defined(__linux__) */ #include #include #if defined(HAVE_LINUX_NETLINK_H) && defined(HAVE_LINUX_RTNETLINK_H) #include #include -#endif +#endif /* if defined(HAVE_LINUX_NETLINK_H) && defined(HAVE_LINUX_RTNETLINK_H) \ + */ #include #include @@ -60,18 +61,18 @@ #ifdef ISC_PLATFORM_HAVESYSUNH #include -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ #ifdef HAVE_KQUEUE #include -#endif +#endif /* ifdef HAVE_KQUEUE */ #ifdef HAVE_EPOLL_CREATE1 #include -#endif +#endif /* ifdef HAVE_EPOLL_CREATE1 */ #if defined(HAVE_SYS_DEVPOLL_H) #include #elif defined(HAVE_DEVPOLL_H) #include -#endif +#endif /* if defined(HAVE_SYS_DEVPOLL_H) */ #include "errno2result.h" @@ -79,7 +80,7 @@ #ifdef ENABLE_TCP_FASTOPEN #include -#endif +#endif /* ifdef ENABLE_TCP_FASTOPEN */ #ifdef HAVE_JSON_C #include @@ -102,7 +103,7 @@ typedef struct { unsigned int want_read : 1, want_write : 1; } pollinfo_t; -#else +#else /* if defined(HAVE_KQUEUE) */ #define USE_SELECT #endif /* HAVE_KQUEUE */ @@ -136,7 +137,7 @@ int isc_dscp_check_value = -1; #if defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL) #ifdef TUNE_LARGE #define ISC_SOCKET_MAXSOCKETS 21000 -#else +#else /* ifdef TUNE_LARGE */ #define ISC_SOCKET_MAXSOCKETS 4096 #endif /* TUNE_LARGE */ #elif defined(USE_SELECT) @@ -200,11 +201,12 @@ typedef enum { poll_idle, poll_active, poll_checking } pollstate_t; #ifndef ISC_SOCKET_MAXEVENTS #ifdef TUNE_LARGE #define ISC_SOCKET_MAXEVENTS 2048 -#else +#else /* ifdef TUNE_LARGE */ #define ISC_SOCKET_MAXEVENTS 64 #endif /* TUNE_LARGE */ -#endif -#endif +#endif /* ifndef ISC_SOCKET_MAXEVENTS */ +#endif /* if defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL) \ + * */ /*% * Some systems define the socket length argument as an int, some as size_t, @@ -212,7 +214,7 @@ typedef enum { poll_idle, poll_active, poll_checking } pollstate_t; */ #ifndef socklen_t #define socklen_t unsigned int -#endif +#endif /* ifndef socklen_t */ /*% * Define what the possible "soft" errors can be. These are non-fatal returns @@ -259,7 +261,7 @@ typedef isc_event_t intev_t; */ #ifndef USE_CMSG #define USE_CMSG 1 -#endif +#endif /* ifndef USE_CMSG */ /*% * NetBSD and FreeBSD can timestamp packets. XXXMLG Should we have @@ -269,8 +271,8 @@ typedef isc_event_t intev_t; #ifdef SO_TIMESTAMP #ifndef USE_CMSG #define USE_CMSG 1 -#endif -#endif +#endif /* ifndef USE_CMSG */ +#endif /* ifdef SO_TIMESTAMP */ /*% * The size to raise the receive buffer to (from BIND 8). @@ -279,11 +281,11 @@ typedef isc_event_t intev_t; #ifdef sun #define RCVBUFSIZE (1 * 1024 * 1024) #define SNDBUFSIZE (1 * 1024 * 1024) -#else +#else /* ifdef sun */ #define RCVBUFSIZE (16 * 1024 * 1024) #define SNDBUFSIZE (16 * 1024 * 1024) -#endif -#else +#endif /* ifdef sun */ +#else /* ifdef TUNE_LARGE */ #define RCVBUFSIZE (32 * 1024) #define SNDBUFSIZE (32 * 1024) #endif /* TUNE_LARGE */ @@ -296,21 +298,21 @@ typedef isc_event_t intev_t; */ #if defined(USE_CMSG) #define CMSG_SP_IN6PKT 40 -#else +#else /* if defined(USE_CMSG) */ #define CMSG_SP_IN6PKT 0 -#endif +#endif /* if defined(USE_CMSG) */ #if defined(USE_CMSG) && defined(SO_TIMESTAMP) #define CMSG_SP_TIMESTAMP 32 -#else +#else /* if defined(USE_CMSG) && defined(SO_TIMESTAMP) */ #define CMSG_SP_TIMESTAMP 0 -#endif +#endif /* if defined(USE_CMSG) && defined(SO_TIMESTAMP) */ #if defined(USE_CMSG) && (defined(IPV6_TCLASS) || defined(IP_TOS)) #define CMSG_SP_TCTOS 24 -#else +#else /* if defined(USE_CMSG) && (defined(IPV6_TCLASS) || defined(IP_TOS)) */ #define CMSG_SP_TCTOS 0 -#endif +#endif /* if defined(USE_CMSG) && (defined(IPV6_TCLASS) || defined(IP_TOS)) */ #define CMSG_SP_INT 24 @@ -359,14 +361,15 @@ struct isc__socket { isc_sockaddr_t peer_address; /* remote address */ unsigned int listener : 1, /* listener socket */ - connected : 1, connecting : 1, /* connect pending */ + connected : 1, connecting : 1, /* connect pending + * */ bound : 1, /* bound to local addr */ dupped : 1, active : 1, /* currently active */ pktdscp : 1; /* per packet dscp */ #ifdef ISC_PLATFORM_RECVOVERFLOW unsigned char overflow; /* used for MSG_TRUNC fake */ -#endif +#endif /* ifdef ISC_PLATFORM_RECVOVERFLOW */ unsigned int dscp; }; @@ -438,9 +441,9 @@ struct isc__socketthread { #define MAXSCATTERGATHER_SEND (ISC_SOCKET_MAXSCATTERGATHER) #ifdef ISC_PLATFORM_RECVOVERFLOW #define MAXSCATTERGATHER_RECV (ISC_SOCKET_MAXSCATTERGATHER + 1) -#else +#else /* ifdef ISC_PLATFORM_RECVOVERFLOW */ #define MAXSCATTERGATHER_RECV (ISC_SOCKET_MAXSCATTERGATHER) -#endif +#endif /* ifdef ISC_PLATFORM_RECVOVERFLOW */ static isc_result_t socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, @@ -584,8 +587,9 @@ manager_log(isc__socketmgr_t *sockmgr, isc_logcategory_t *category, char msgbuf[2048]; va_list ap; - if (!isc_log_wouldlog(isc_lctx, level)) + if (!isc_log_wouldlog(isc_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -632,8 +636,9 @@ socket_log(isc__socket_t *sock, const isc_sockaddr_t *address, char peerbuf[ISC_SOCKADDR_FORMATSIZE]; va_list ap; - if (!isc_log_wouldlog(isc_lctx, level)) + if (!isc_log_wouldlog(isc_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -657,8 +662,9 @@ inc_stats(isc_stats_t *stats, isc_statscounter_t counterid) { REQUIRE(counterid != -1); - if (stats != NULL) + if (stats != NULL) { isc_stats_increment(stats, counterid); + } } /*% @@ -669,8 +675,9 @@ dec_stats(isc_stats_t *stats, isc_statscounter_t counterid) { REQUIRE(counterid != -1); - if (stats != NULL) + if (stats != NULL) { isc_stats_decrement(stats, counterid); + } } static inline isc_result_t @@ -758,7 +765,7 @@ watch_fd(isc__socketthread_t *thread, int fd, int msg) UNLOCK(&thread->manager->lock); return (result); -#endif +#endif /* ifdef USE_KQUEUE */ } static inline isc_result_t @@ -853,7 +860,7 @@ unwatch_fd(isc__socketthread_t *thread, int fd, int msg) UNLOCK(&thread->manager->lock); return (result); -#endif +#endif /* ifdef USE_KQUEUE */ } /* @@ -950,7 +957,7 @@ select_poke(isc__socketmgr_t *mgr, int threadid, int fd, int msg) sleep(1); errno = EAGAIN; } -#endif +#endif /* ifdef ENOSR */ } while (cc < 0 && SOFT_ERROR(errno)); if (cc < 0) { @@ -976,8 +983,9 @@ select_readmsg(isc__socketthread_t *thread, int *fd, int *msg) if (cc < 0) { *msg = SELECT_POKE_NOTHING; *fd = -1; /* Silence compiler. */ - if (SOFT_ERROR(errno)) + if (SOFT_ERROR(errno)) { return; + } strerror_r(errno, strbuf, sizeof(strbuf)); FATAL_ERROR(__FILE__, __LINE__, @@ -999,26 +1007,26 @@ make_nonblock(int fd) char strbuf[ISC_STRERRORSIZE]; #ifdef USE_FIONBIO_IOCTL int on = 1; -#else +#else /* ifdef USE_FIONBIO_IOCTL */ int flags; -#endif +#endif /* ifdef USE_FIONBIO_IOCTL */ #ifdef USE_FIONBIO_IOCTL ret = ioctl(fd, FIONBIO, (char *)&on); -#else +#else /* ifdef USE_FIONBIO_IOCTL */ flags = fcntl(fd, F_GETFL, 0); flags |= PORT_NONBLOCK; ret = fcntl(fd, F_SETFL, flags); -#endif +#endif /* ifdef USE_FIONBIO_IOCTL */ if (ret == -1) { strerror_r(errno, strbuf, sizeof(strbuf)); UNEXPECTED_ERROR(__FILE__, __LINE__, #ifdef USE_FIONBIO_IOCTL "ioctl(%d, FIONBIO, &on): %s", fd, -#else +#else /* ifdef USE_FIONBIO_IOCTL */ "fcntl(%d, F_SETFL, %d): %s", fd, flags, -#endif +#endif /* ifdef USE_FIONBIO_IOCTL */ strbuf); return (ISC_R_UNEXPECTED); @@ -1040,7 +1048,7 @@ cmsg_len(socklen_t len) { #ifdef CMSG_LEN return (CMSG_LEN(len)); -#else +#else /* ifdef CMSG_LEN */ socklen_t hdrlen; /* @@ -1049,7 +1057,7 @@ cmsg_len(socklen_t len) */ hdrlen = (socklen_t)CMSG_DATA(((struct cmsghdr *)NULL)); return (hdrlen + len); -#endif +#endif /* ifdef CMSG_LEN */ } static inline socklen_t @@ -1057,7 +1065,7 @@ cmsg_space(socklen_t len) { #ifdef CMSG_SPACE return (CMSG_SPACE(len)); -#else +#else /* ifdef CMSG_SPACE */ struct msghdr msg; struct cmsghdr *cmsgp; /* @@ -1074,11 +1082,12 @@ cmsg_space(socklen_t len) cmsgp->cmsg_len = cmsg_len(len); cmsgp = CMSG_NXTHDR(&msg, cmsgp); - if (cmsgp != NULL) + if (cmsgp != NULL) { return ((char *)cmsgp - (char *)msg.msg_control); - else + } else { return (0); -#endif + } +#endif /* ifdef CMSG_SPACE */ } #endif /* USE_CMSG */ @@ -1093,8 +1102,8 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) struct in6_pktinfo *pktinfop; #ifdef SO_TIMESTAMP void *timevalp; -#endif -#endif +#endif /* ifdef SO_TIMESTAMP */ +#endif /* ifdef USE_CMSG */ /* * sock is used only when ISC_NET_BSD44MSGHDR and USE_CMSG are defined. @@ -1110,23 +1119,24 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) if ((msg->msg_flags & MSG_TRUNC) != 0) { dev->attributes |= ISC_SOCKEVENTATTR_TRUNC; } -#endif +#endif /* ifdef MSG_TRUNC */ #ifdef MSG_CTRUNC if ((msg->msg_flags & MSG_CTRUNC) != 0) { dev->attributes |= ISC_SOCKEVENTATTR_CTRUNC; } -#endif +#endif /* ifdef MSG_CTRUNC */ #ifndef USE_CMSG return; -#else - if (msg->msg_controllen == 0U || msg->msg_control == NULL) +#else /* ifndef USE_CMSG */ + if (msg->msg_controllen == 0U || msg->msg_control == NULL) { return; + } #ifdef SO_TIMESTAMP timevalp = NULL; -#endif +#endif /* ifdef SO_TIMESTAMP */ pktinfop = NULL; cmsgp = CMSG_FIRSTHDR(msg); @@ -1142,8 +1152,9 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) socket_log(sock, NULL, TRACE, "interface received on ifindex %u", dev->pktinfo.ipi6_ifindex); - if (IN6_IS_ADDR_MULTICAST(&pktinfop->ipi6_addr)) + if (IN6_IS_ADDR_MULTICAST(&pktinfop->ipi6_addr)) { dev->attributes |= ISC_SOCKEVENTATTR_MULTICAST; + } goto next; } @@ -1158,7 +1169,7 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) dev->attributes |= ISC_SOCKEVENTATTR_TIMESTAMP; goto next; } -#endif +#endif /* ifdef SO_TIMESTAMP */ #ifdef IPV6_TCLASS if (cmsgp->cmsg_level == IPPROTO_IPV6 && @@ -1168,21 +1179,21 @@ process_cmsg(isc__socket_t *sock, struct msghdr *msg, isc_socketevent_t *dev) dev->attributes |= ISC_SOCKEVENTATTR_DSCP; goto next; } -#endif +#endif /* ifdef IPV6_TCLASS */ #ifdef IP_TOS if (cmsgp->cmsg_level == IPPROTO_IP && (cmsgp->cmsg_type == IP_TOS #ifdef IP_RECVTOS || cmsgp->cmsg_type == IP_RECVTOS -#endif +#endif /* ifdef IP_RECVTOS */ )) { dev->dscp = (int)*(unsigned char *)CMSG_DATA(cmsgp); dev->dscp >>= 2; dev->attributes |= ISC_SOCKEVENTATTR_DSCP; goto next; } -#endif +#endif /* ifdef IP_TOS */ next: cmsgp = CMSG_NXTHDR(msg, cmsgp); } @@ -1265,13 +1276,14 @@ build_msghdr_send(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, cmsgp->cmsg_len = cmsg_len(sizeof(use_min_mtu)); memmove(CMSG_DATA(cmsgp), &use_min_mtu, sizeof(use_min_mtu)); } -#endif +#endif /* if defined(IPV6_USE_MIN_MTU) */ if (isc_dscp_check_value > -1) { - if (sock->type == isc_sockettype_udp) + if (sock->type == isc_sockettype_udp) { INSIST((int)dev->dscp == isc_dscp_check_value); - else if (sock->type == isc_sockettype_tcp) + } else if (sock->type == isc_sockettype_tcp) { INSIST((int)sock->dscp == isc_dscp_check_value); + } } #if defined(IP_TOS) || (defined(IPPROTO_IPV6) && defined(IPV6_TCLASS)) @@ -1306,7 +1318,7 @@ build_msghdr_send(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, sock->dscp = dscp; } } -#endif +#endif /* ifdef IP_TOS */ #if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) if (sock->pf == AF_INET6 && sock->pktdscp) { cmsgp = (struct cmsghdr *)(cmsgbuf + @@ -1332,18 +1344,21 @@ build_msghdr_send(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, sock->dscp = dscp; } } -#endif +#endif /* if defined(IPPROTO_IPV6) && defined(IPV6_TCLASS) */ if (msg->msg_controllen != 0 && msg->msg_controllen < SENDCMSGBUFLEN) { memset(cmsgbuf + msg->msg_controllen, 0, SENDCMSGBUFLEN - msg->msg_controllen); } } -#endif +#endif /* if defined(IP_TOS) || (defined(IPPROTO_IPV6) && \ + * defined(IPV6_TCLASS)) \ + * */ #endif /* USE_CMSG */ - if (write_countp != NULL) + if (write_countp != NULL) { *write_countp = write_count; + } } /* @@ -1392,7 +1407,7 @@ build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, iov[iovcount].iov_len = 1; iovcount++; } -#endif +#endif /* ifdef ISC_PLATFORM_RECVOVERFLOW */ msg->msg_iov = iov; msg->msg_iovlen = iovcount; @@ -1400,14 +1415,15 @@ build_msghdr_recv(isc__socket_t *sock, char *cmsgbuf, isc_socketevent_t *dev, #if defined(USE_CMSG) msg->msg_control = cmsgbuf; msg->msg_controllen = RECVCMSGBUFLEN; -#else +#else /* if defined(USE_CMSG) */ msg->msg_control = NULL; msg->msg_controllen = 0; #endif /* USE_CMSG */ msg->msg_flags = 0; - if (read_countp != NULL) + if (read_countp != NULL) { *read_countp = read_count; + } } static void @@ -1415,10 +1431,11 @@ set_dev_address(const isc_sockaddr_t *address, isc__socket_t *sock, isc_socketevent_t *dev) { if (sock->type == isc_sockettype_udp) { - if (address != NULL) + if (address != NULL) { dev->address = *address; - else + } else { dev->address = sock->peer_address; + } } else if (sock->type == isc_sockettype_tcp) { INSIST(address == NULL); dev->address = sock->peer_address; @@ -1471,7 +1488,7 @@ dump_msg(struct msghdr *msg) printf("\tcontrol %p, controllen %ld\n", msg->msg_control, (long)msg->msg_controllen); } -#endif +#endif /* if defined(ISC_SOCKET_DEBUG) */ #define DOIO_SUCCESS 0 /* i/o ok, event sent */ #define DOIO_SOFT 1 /* i/o ok, soft error, no event sent */ @@ -1493,18 +1510,19 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) #if defined(ISC_SOCKET_DEBUG) dump_msg(&msghdr); -#endif +#endif /* if defined(ISC_SOCKET_DEBUG) */ cc = recvmsg(sock->fd, &msghdr, 0); recv_errno = errno; #if defined(ISC_SOCKET_DEBUG) dump_msg(&msghdr); -#endif +#endif /* if defined(ISC_SOCKET_DEBUG) */ if (cc < 0) { - if (SOFT_ERROR(recv_errno)) + if (SOFT_ERROR(recv_errno)) { return (DOIO_SOFT); + } if (isc_log_wouldlog(isc_lctx, IOEVENT_LEVEL)) { strerror_r(recv_errno, strbuf, sizeof(strbuf)); @@ -1539,7 +1557,7 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) /* Should never get this one but it was seen. */ #ifdef ENOPROTOOPT SOFT_OR_HARD(ENOPROTOOPT, ISC_R_HOSTUNREACH); -#endif +#endif /* ifdef ENOPROTOOPT */ SOFT_OR_HARD(EINVAL, ISC_R_HOSTUNREACH); #undef SOFT_OR_HARD @@ -1559,8 +1577,9 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) switch (sock->type) { case isc_sockettype_tcp: case isc_sockettype_unix: - if (cc == 0) + if (cc == 0) { return (DOIO_EOF); + } break; case isc_sockettype_udp: case isc_sockettype_raw: @@ -1601,7 +1620,7 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) dev->attributes |= ISC_SOCKEVENTATTR_TRUNC; cc--; } -#endif +#endif /* ifdef ISC_PLATFORM_RECVOVERFLOW */ /* * If there are control messages attached, run through them and pull @@ -1618,8 +1637,9 @@ doio_recv(isc__socket_t *sock, isc_socketevent_t *dev) * If we read less than we expected, update counters, * and let the upper layer poke the descriptor. */ - if (((size_t)cc != read_count) && (dev->n < dev->minimum)) + if (((size_t)cc != read_count) && (dev->n < dev->minimum)) { return (DOIO_SOFT); + } /* * Full reads are posted, or partials if partials are ok. @@ -1658,22 +1678,25 @@ doio_send(isc__socket_t *sock, isc_socketevent_t *dev) resend: if (sock->type == isc_sockettype_udp && sock->manager->maxudp != 0 && - write_count > sock->manager->maxudp) + write_count > sock->manager->maxudp) { cc = write_count; - else + } else { cc = sendmsg(sock->fd, &msghdr, 0); + } send_errno = errno; /* * Check for error or block condition. */ if (cc < 0) { - if (send_errno == EINTR && ++attempts < NRETRIES) + if (send_errno == EINTR && ++attempts < NRETRIES) { goto resend; + } if (SOFT_ERROR(send_errno)) { - if (errno == EWOULDBLOCK || errno == EAGAIN) + if (errno == EWOULDBLOCK || errno == EAGAIN) { dev->result = ISC_R_WOULDBLOCK; + } return (DOIO_SOFT); } @@ -1702,7 +1725,7 @@ resend: ALWAYS_HARD(EHOSTUNREACH, ISC_R_HOSTUNREACH); #ifdef EHOSTDOWN ALWAYS_HARD(EHOSTDOWN, ISC_R_HOSTUNREACH); -#endif +#endif /* ifdef EHOSTDOWN */ ALWAYS_HARD(ENETUNREACH, ISC_R_NETUNREACH); SOFT_OR_HARD(ENOBUFS, ISC_R_NORESOURCES); ALWAYS_HARD(EPERM, ISC_R_HOSTUNREACH); @@ -1742,8 +1765,9 @@ resend: * If we write less than we expected, update counters, poke. */ dev->n += cc; - if ((size_t)cc != write_count) + if ((size_t)cc != write_count) { return (DOIO_SOFT); + } /* * Exactly what we wanted to write. We're done with this @@ -1968,8 +1992,9 @@ set_rcvbuf(void) break; } } - if (fd == -1) + if (fd == -1) { return; + } len = sizeof(min); if (getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (void *)&min, &len) == 0 && @@ -1985,8 +2010,9 @@ set_rcvbuf(void) rcvbuf = min; goto cleanup; } - } else + } else { min = rcvbuf; + } if (min != max) { rcvbuf = max; goto again; @@ -1995,7 +2021,7 @@ set_rcvbuf(void) cleanup: close(fd); } -#endif +#endif /* ifdef SO_RCVBUF */ #ifdef SO_SNDBUF static isc_once_t sndbuf_once = ISC_ONCE_INIT; @@ -2024,7 +2050,7 @@ set_sndbuf(void) break; } } -#endif +#endif /* if defined(ISC_PLATFORM_HAVEIPV6) */ if (fd == -1) { return; } @@ -2054,14 +2080,14 @@ set_sndbuf(void) cleanup: close(fd); } -#endif +#endif /* ifdef SO_SNDBUF */ static void use_min_mtu(isc__socket_t *sock) { #if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU) UNUSED(sock); -#endif +#endif /* if !defined(IPV6_USE_MIN_MTU) && !defined(IPV6_MTU) */ #ifdef IPV6_USE_MIN_MTU /* use minimum MTU */ if (sock->pf == AF_INET6) { @@ -2069,7 +2095,7 @@ use_min_mtu(isc__socket_t *sock) (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_USE_MIN_MTU, (void *)&on, sizeof(on)); } -#endif +#endif /* ifdef IPV6_USE_MIN_MTU */ #if defined(IPV6_MTU) /* * Use minimum MTU on IPv6 sockets. @@ -2079,17 +2105,18 @@ use_min_mtu(isc__socket_t *sock) (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_MTU, &mtu, sizeof(mtu)); } -#endif +#endif /* if defined(IPV6_MTU) */ } static void set_tcp_maxseg(isc__socket_t *sock, int size) { #ifdef TCP_MAXSEG - if (sock->type == isc_sockettype_tcp) + if (sock->type == isc_sockettype_tcp) { (void)setsockopt(sock->fd, IPPROTO_TCP, TCP_MAXSEG, (void *)&size, sizeof(size)); -#endif + } +#endif /* ifdef TCP_MAXSEG */ } static isc_result_t @@ -2102,11 +2129,11 @@ opensocket(isc__socketmgr_t *manager, isc__socket_t *sock, int tries = 0; #if defined(USE_CMSG) || defined(SO_NOSIGPIPE) int on = 1; -#endif +#endif /* if defined(USE_CMSG) || defined(SO_NOSIGPIPE) */ #if defined(SO_RCVBUF) || defined(SO_SNDBUF) socklen_t optlen; int size = 0; -#endif +#endif /* if defined(SO_RCVBUF) || defined(SO_SNDBUF) */ again: if (dup_socket == NULL) { @@ -2130,9 +2157,9 @@ again: #ifdef NETLINK_ROUTE sock->fd = socket(sock->pf, SOCK_RAW, NETLINK_ROUTE); -#else +#else /* ifdef NETLINK_ROUTE */ sock->fd = socket(sock->pf, SOCK_RAW, 0); -#endif +#endif /* ifdef NETLINK_ROUTE */ if (sock->fd != -1) { #ifdef NETLINK_ROUTE struct sockaddr_nl sa; @@ -2152,11 +2179,11 @@ again: close(sock->fd); sock->fd = -1; } -#endif +#endif /* ifdef NETLINK_ROUTE */ sock->bound = 1; } } -#endif +#endif /* if defined(PF_ROUTE) */ break; } } else { @@ -2190,7 +2217,7 @@ again: sock->fd = newfd; err = "isc_socket_create: fcntl"; } -#endif +#endif /* ifdef F_DUPFD */ if (sock->fd >= (int)manager->maxsocks) { (void)close(sock->fd); @@ -2210,7 +2237,7 @@ again: isc_log_write(isc_lctx, ISC_LOGCATEGORY_GENERAL, ISC_LOGMODULE_SOCKET, ISC_LOG_ERROR, "%s: %s", err, strbuf); - /* fallthrough */ + /* fallthrough */ case ENOBUFS: inc_stats(manager->stats, sock->statsindex[STATID_OPENFAIL]); @@ -2238,8 +2265,9 @@ again: } } - if (dup_socket != NULL) + if (dup_socket != NULL) { goto setup_done; + } result = make_nonblock(sock->fd); if (result != ISC_R_SUCCESS) { @@ -2257,7 +2285,7 @@ again: sock->fd, strbuf); /* Press on... */ } -#endif +#endif /* ifdef SO_NOSIGPIPE */ /* * Use minimum mtu if possible. @@ -2294,7 +2322,7 @@ again: "failed: %s", sock->fd, strbuf); } -#else +#else /* ifdef IPV6_RECVPKTINFO */ /* RFC 2292 */ if ((sock->pf == AF_INET6) && (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_PKTINFO, @@ -2316,7 +2344,7 @@ again: IPV6_MTU_DISCOVER, &action, sizeof(action)); } -#endif +#endif /* if defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DONT) */ #endif /* defined(USE_CMSG) */ #if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT) @@ -2331,16 +2359,16 @@ again: action = IP_PMTUDISC_OMIT; if (setsockopt(sock->fd, IPPROTO_IP, IP_MTU_DISCOVER, &action, sizeof(action)) < 0) { -#endif +#endif /* if defined(IP_PMTUDISC_OMIT) */ action = IP_PMTUDISC_DONT; (void)setsockopt(sock->fd, IPPROTO_IP, IP_MTU_DISCOVER, &action, sizeof(action)); #if defined(IP_PMTUDISC_OMIT) } -#endif +#endif /* if defined(IP_PMTUDISC_OMIT) */ } -#endif +#endif /* if defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DONT) */ #if defined(IP_DONTFRAG) /* * Turn off Path MTU discovery on IPv4/UDP sockets. @@ -2350,7 +2378,7 @@ again: (void)setsockopt(sock->fd, IPPROTO_IP, IP_DONTFRAG, &off, sizeof(off)); } -#endif +#endif /* if defined(IP_DONTFRAG) */ #if defined(SO_RCVBUF) optlen = sizeof(size); @@ -2368,7 +2396,7 @@ again: sock->fd, rcvbuf, strbuf); } } -#endif +#endif /* if defined(SO_RCVBUF) */ #if defined(SO_SNDBUF) optlen = sizeof(size); @@ -2386,7 +2414,7 @@ again: sock->fd, sndbuf, strbuf); } } -#endif +#endif /* if defined(SO_SNDBUF) */ } #ifdef IPV6_RECVTCLASS if ((sock->pf == AF_INET6) && @@ -2398,7 +2426,7 @@ again: "failed: %s", sock->fd, strbuf); } -#endif +#endif /* ifdef IPV6_RECVTCLASS */ #ifdef IP_RECVTOS if ((sock->pf == AF_INET) && (setsockopt(sock->fd, IPPROTO_IP, IP_RECVTOS, (void *)&on, @@ -2409,7 +2437,7 @@ again: "failed: %s", sock->fd, strbuf); } -#endif +#endif /* ifdef IP_RECVTOS */ #endif /* defined(USE_CMSG) || defined(SO_RCVBUF) || defined(SO_SNDBUF) */ setup_done: @@ -2442,8 +2470,9 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, REQUIRE(socketp != NULL && *socketp == NULL); result = allocate_socket(manager, type, &sock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } switch (sock->type) { case isc_sockettype_udp: @@ -2494,11 +2523,11 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, thread->fdstate[sock->fd] = MANAGED; #if defined(USE_EPOLL) thread->epoll_events[sock->fd] = 0; -#endif +#endif /* if defined(USE_EPOLL) */ #ifdef USE_DEVPOLL INSIST(thread->fdpollinfo[sock->fd].want_read == 0 && thread->fdpollinfo[sock->fd].want_write == 0); -#endif +#endif /* ifdef USE_DEVPOLL */ UNLOCK(&thread->fdlock[lockid]); LOCK(&manager->lock); @@ -2507,7 +2536,7 @@ socket_create(isc_socketmgr_t *manager0, int pf, isc_sockettype_t type, if (thread->maxfd < sock->fd) { thread->maxfd = sock->fd; } -#endif +#endif /* ifdef USE_SELECT */ UNLOCK(&manager->lock); socket_log(sock, NULL, CREATION, @@ -2576,19 +2605,20 @@ isc_socket_open(isc_socket_t *sock0) thread->fdstate[sock->fd] = MANAGED; #if defined(USE_EPOLL) thread->epoll_events[sock->fd] = 0; -#endif +#endif /* if defined(USE_EPOLL) */ #ifdef USE_DEVPOLL INSIST(thread->fdpollinfo[sock->fd].want_read == 0 && thread->fdpollinfo[sock->fd].want_write == 0); -#endif +#endif /* ifdef USE_DEVPOLL */ UNLOCK(&thread->fdlock[lockid]); #ifdef USE_SELECT LOCK(&sock->manager->lock); - if (thread->maxfd < sock->fd) + if (thread->maxfd < sock->fd) { thread->maxfd = sock->fd; + } UNLOCK(&sock->manager->lock); -#endif +#endif /* ifdef USE_SELECT */ } return (result); @@ -2719,8 +2749,9 @@ send_senddone_event(isc__socket_t *sock, isc_socketevent_t **dev) task = (*dev)->ev_sender; (*dev)->ev_sender = sock; - if (ISC_LINK_LINKED(*dev, ev_link)) + if (ISC_LINK_LINKED(*dev, ev_link)) { ISC_LIST_DEQUEUE(sock->send_list, *dev, ev_link); + } if (((*dev)->attributes & ISC_SOCKEVENTATTR_ATTACHED) != 0) { isc_task_sendtoanddetach(&task, (isc_event_t **)dev, @@ -2829,11 +2860,12 @@ internal_accept(isc__socket_t *sock) fd = newfd; err = "accept/fcntl"; } -#endif +#endif /* ifdef F_DUPFD */ if (fd < 0) { - if (SOFT_ERROR(errno)) + if (SOFT_ERROR(errno)) { goto soft_error; + } switch (errno) { case ENFILE: case EMFILE: @@ -2854,10 +2886,10 @@ internal_accept(isc__socket_t *sock) case ECONNREFUSED: #ifdef EPROTO case EPROTO: -#endif +#endif /* ifdef EPROTO */ #ifdef ENONET case ENONET: -#endif +#endif /* ifdef ENONET */ goto soft_error; default: break; @@ -2973,7 +3005,7 @@ internal_accept(isc__socket_t *sock) nthread->fdstate[fd] = MANAGED; #if defined(USE_EPOLL) nthread->epoll_events[fd] = 0; -#endif +#endif /* if defined(USE_EPOLL) */ if (!same_bucket) { UNLOCK(&nthread->fdlock[lockid]); } @@ -2981,9 +3013,10 @@ internal_accept(isc__socket_t *sock) LOCK(&manager->lock); #ifdef USE_SELECT - if (nthread->maxfd < fd) + if (nthread->maxfd < fd) { nthread->maxfd = fd; -#endif + } +#endif /* ifdef USE_SELECT */ socket_log(sock, &NEWCONNSOCK(dev)->peer_address, CREATION, "accepted connection, new socket %p", @@ -3214,8 +3247,9 @@ process_fds(isc__socketthread_t *thread, struct kevent *events, int nevents) process_fd(thread, events[i].ident, readable, writable); } - if (have_ctlevent) + if (have_ctlevent) { done = process_ctlfd(thread); + } return (done); } @@ -3258,8 +3292,9 @@ process_fds(isc__socketthread_t *thread, struct epoll_event *events, (events[i].events & EPOLLOUT) != 0); } - if (have_ctlevent) + if (have_ctlevent) { done = process_ctlfd(thread); + } return (done); } @@ -3289,8 +3324,9 @@ process_fds(isc__socketthread_t *thread, struct pollfd *events, int nevents) (events[i].events & POLLOUT) != 0); } - if (have_ctlevent) + if (have_ctlevent) { done = process_ctlfd(thread); + } return (done); } @@ -3304,13 +3340,14 @@ process_fds(isc__socketthread_t *thread, int maxfd, fd_set *readfds, REQUIRE(maxfd <= (int)thread->manager->maxsocks); for (i = 0; i < maxfd; i++) { - if (i == thread->pipe_fds[0] || i == thread->pipe_fds[1]) + if (i == thread->pipe_fds[0] || i == thread->pipe_fds[1]) { continue; + } process_fd(thread, i, FD_ISSET(i, readfds), FD_ISSET(i, writefds)); } } -#endif +#endif /* ifdef USE_KQUEUE */ static bool process_ctlfd(isc__socketthread_t *thread) @@ -3326,8 +3363,9 @@ process_ctlfd(isc__socketthread_t *thread) /* * Nothing to read? */ - if (msg == SELECT_POKE_NOTHING) + if (msg == SELECT_POKE_NOTHING) { break; + } /* * Handle shutdown message. We really should @@ -3335,8 +3373,9 @@ process_ctlfd(isc__socketthread_t *thread) * it doesn't matter if we have to do a little * more work first. */ - if (msg == SELECT_POKE_SHUTDOWN) + if (msg == SELECT_POKE_SHUTDOWN) { return (true); + } /* * This is a wakeup on a socket. Look @@ -3379,12 +3418,12 @@ netthread(void *uap) int pass; #if defined(ISC_SOCKET_USE_POLLWATCH) pollstate_t pollstate = poll_idle; -#endif +#endif /* if defined(ISC_SOCKET_USE_POLLWATCH) */ #elif defined(USE_SELECT) const char *fnname = "select()"; int maxfd; int ctlfd; -#endif +#endif /* ifdef USE_KQUEUE */ char strbuf[ISC_STRERRORSIZE]; #if defined(USE_SELECT) @@ -3392,7 +3431,7 @@ netthread(void *uap) * Get the control fd here. This will never change. */ ctlfd = thread->pipe_fds[0]; -#endif +#endif /* if defined(USE_SELECT) */ done = false; while (!done) { do { @@ -3423,7 +3462,7 @@ netthread(void *uap) } #ifndef ISC_SOCKET_USE_POLLWATCH dvp.dp_timeout = -1; -#else +#else /* ifndef ISC_SOCKET_USE_POLLWATCH */ if (pollstate == poll_idle) { dvp.dp_timeout = -1; } else { @@ -3495,7 +3534,7 @@ netthread(void *uap) } pollstate = poll_active; } -#endif +#endif /* if defined(USE_DEVPOLL) && defined(ISC_SOCKET_USE_POLLWATCH) */ } while (cc < 0); #if defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL) @@ -3510,7 +3549,8 @@ netthread(void *uap) if (FD_ISSET(ctlfd, thread->read_fds_copy)) { done = process_ctlfd(thread); } -#endif +#endif /* if defined(USE_KQUEUE) || defined(USE_EPOLL) || defined(USE_DEVPOLL) \ + * */ } thread_log(thread, TRACE, "watcher exiting"); @@ -3633,8 +3673,9 @@ setup_thread(isc__socketthread_t *thread) thread->nevents = ISC_SOCKET_MAXEVENTS; result = isc_resource_getcurlimit(isc_resource_openfiles, &thread->open_max); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { thread->open_max = 64; + } thread->calls = 0; thread->events = isc_mem_get(thread->manager->mctx, sizeof(struct pollfd) * thread->nevents); @@ -3682,9 +3723,9 @@ setup_thread(isc__socketthread_t *thread) */ thread->fd_bufsize = howmany(manager->maxsocks, NFDBITS) * sizeof(fd_mask); -#else +#else /* if ISC_SOCKET_MAXSOCKETS > FD_SETSIZE */ thread->fd_bufsize = sizeof(fd_set); -#endif +#endif /* if ISC_SOCKET_MAXSOCKETS > FD_SETSIZE */ thread->read_fds = isc_mem_get(thread->manager->mctx, thread->fd_bufsize); @@ -3753,7 +3794,7 @@ cleanup_thread(isc_mem_t *mctx, isc__socketthread_t *thread) #if defined(USE_EPOLL) isc_mem_put(thread->manager->mctx, thread->epoll_events, thread->manager->maxsocks * sizeof(uint32_t)); -#endif +#endif /* if defined(USE_EPOLL) */ isc_mem_put(thread->manager->mctx, thread->fds, thread->manager->maxsocks * sizeof(isc__socket_t *)); isc_mem_put(thread->manager->mctx, thread->fdstate, @@ -3783,8 +3824,9 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, REQUIRE(managerp != NULL && *managerp == NULL); - if (maxsocks == 0) + if (maxsocks == 0) { maxsocks = ISC_SOCKET_MAXSOCKETS; + } manager = isc_mem_get(mctx, sizeof(*manager)); @@ -4006,8 +4048,9 @@ isc_socket_recv(isc_socket_t *sock0, isc_region_t *region, unsigned int minimum, dev = allocate_socketevent(manager->mctx, sock, ISC_SOCKEVENT_RECVDONE, action, arg); - if (dev == NULL) + if (dev == NULL) { return (ISC_R_NOMEMORY); + } return (isc_socket_recv2(sock0, region, minimum, task, dev, 0)); } @@ -4029,13 +4072,14 @@ isc_socket_recv2(isc_socket_t *sock0, isc_region_t *region, /* * UDP sockets are always partial read. */ - if (sock->type == isc_sockettype_udp) + if (sock->type == isc_sockettype_udp) { event->minimum = 1; - else { - if (minimum == 0) + } else { + if (minimum == 0) { event->minimum = region->length; - else + } else { event->minimum = minimum; + } } return (socket_recv(sock, event, task, flags)); @@ -4174,8 +4218,9 @@ isc_socket_sendto(isc_socket_t *sock0, isc_region_t *region, isc_task_t *task, dev = allocate_socketevent(manager->mctx, sock, ISC_SOCKEVENT_SENDDONE, action, arg); - if (dev == NULL) + if (dev == NULL) { return (ISC_R_NOMEMORY); + } dev->region = *region; @@ -4192,8 +4237,9 @@ isc_socket_sendto2(isc_socket_t *sock0, isc_region_t *region, isc_task_t *task, REQUIRE(VALID_SOCKET(sock)); REQUIRE((flags & ~(ISC_SOCKFLAG_IMMEDIATE | ISC_SOCKFLAG_NORETRY)) == 0); - if ((flags & ISC_SOCKFLAG_NORETRY) != 0) + if ((flags & ISC_SOCKFLAG_NORETRY) != 0) { REQUIRE(sock->type == isc_sockettype_udp); + } event->ev_sender = sock; event->result = ISC_R_UNSET; event->region = *region; @@ -4212,37 +4258,39 @@ isc_socket_cleanunix(const isc_sockaddr_t *sockaddr, bool active) struct stat sb; char strbuf[ISC_STRERRORSIZE]; - if (sockaddr->type.sa.sa_family != AF_UNIX) + if (sockaddr->type.sa.sa_family != AF_UNIX) { return; + } #ifndef S_ISSOCK #if defined(S_IFMT) && defined(S_IFSOCK) #define S_ISSOCK(mode) ((mode & S_IFMT) == S_IFSOCK) #elif defined(_S_IFMT) && defined(S_IFSOCK) #define S_ISSOCK(mode) ((mode & _S_IFMT) == S_IFSOCK) -#endif -#endif +#endif /* if defined(S_IFMT) && defined(S_IFSOCK) */ +#endif /* ifndef S_ISSOCK */ #ifndef S_ISFIFO #if defined(S_IFMT) && defined(S_IFIFO) #define S_ISFIFO(mode) ((mode & S_IFMT) == S_IFIFO) #elif defined(_S_IFMT) && defined(S_IFIFO) #define S_ISFIFO(mode) ((mode & _S_IFMT) == S_IFIFO) -#endif -#endif +#endif /* if defined(S_IFMT) && defined(S_IFIFO) */ +#endif /* ifndef S_ISFIFO */ #if !defined(S_ISFIFO) && !defined(S_ISSOCK) /* cppcheck-suppress preprocessorErrorDirective */ -#error You need to define S_ISFIFO and S_ISSOCK as appropriate for your platform. See . -#endif +#error \ + You need to define S_ISFIFO and S_ISSOCK as appropriate for your platform. See . +#endif /* if !defined(S_ISFIFO) && !defined(S_ISSOCK) */ #ifndef S_ISFIFO #define S_ISFIFO(mode) 0 -#endif +#endif /* ifndef S_ISFIFO */ #ifndef S_ISSOCK #define S_ISSOCK(mode) 0 -#endif +#endif /* ifndef S_ISSOCK */ if (active) { if (stat(sockaddr->type.sunix.sun_path, &sb) < 0) { @@ -4329,10 +4377,10 @@ isc_socket_cleanunix(const isc_sockaddr_t *sockaddr, bool active) } cleanup: close(s); -#else +#else /* ifdef ISC_PLATFORM_HAVESYSUNH */ UNUSED(sockaddr); UNUSED(active); -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } isc_result_t @@ -4345,7 +4393,7 @@ isc_socket_permunix(const isc_sockaddr_t *sockaddr, uint32_t perm, char path[sizeof(sockaddr->type.sunix.sun_path)]; #ifdef NEED_SECURE_DIRECTORY char *slash; -#endif +#endif /* ifdef NEED_SECURE_DIRECTORY */ REQUIRE(sockaddr->type.sa.sa_family == AF_UNIX); INSIST(strlen(sockaddr->type.sunix.sun_path) < sizeof(path)); @@ -4362,7 +4410,7 @@ isc_socket_permunix(const isc_sockaddr_t *sockaddr, uint32_t perm, } else { strlcpy(path, ".", sizeof(path)); } -#endif +#endif /* ifdef NEED_SECURE_DIRECTORY */ if (chmod(path, perm) < 0) { strerror_r(errno, strbuf, sizeof(strbuf)); @@ -4381,13 +4429,13 @@ isc_socket_permunix(const isc_sockaddr_t *sockaddr, uint32_t perm, result = ISC_R_FAILURE; } return (result); -#else +#else /* ifdef ISC_PLATFORM_HAVESYSUNH */ UNUSED(sockaddr); UNUSED(perm); UNUSED(owner); UNUSED(group); return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* ifdef ISC_PLATFORM_HAVESYSUNH */ } isc_result_t @@ -4417,7 +4465,7 @@ isc_socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr, if (sock->pf == AF_UNIX) { goto bind_socket; } -#endif +#endif /* ifdef AF_UNIX */ if ((options & ISC_SOCKET_REUSEADDRESS) != 0 && isc_sockaddr_getport(sockaddr) != (in_port_t)0) { if (setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, (void *)&on, @@ -4437,12 +4485,12 @@ isc_socket_bind(isc_socket_t *sock0, const isc_sockaddr_t *sockaddr, UNEXPECTED_ERROR(__FILE__, __LINE__, "setsockopt(%d) failed", sock->fd); } -#endif +#endif /* if defined(__FreeBSD_kernel__) && defined(SO_REUSEPORT_LB) */ /* Press on... */ } #ifdef AF_UNIX bind_socket: -#endif +#endif /* ifdef AF_UNIX */ if (bind(sock->fd, &sockaddr->type.sa, sockaddr->length) < 0) { inc_stats(sock->manager->stats, sock->statsindex[STATID_BINDFAIL]); @@ -4486,10 +4534,10 @@ isc_socket_filter(isc_socket_t *sock0, const char *filter) #if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER) char strbuf[ISC_STRERRORSIZE]; struct accept_filter_arg afa; -#else +#else /* if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER) */ UNUSED(sock); UNUSED(filter); -#endif +#endif /* if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER) */ REQUIRE(VALID_SOCKET(sock)); @@ -4504,9 +4552,9 @@ isc_socket_filter(isc_socket_t *sock0, const char *filter) return (ISC_R_FAILURE); } return (ISC_R_SUCCESS); -#else +#else /* if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER) */ return (ISC_R_NOTIMPLEMENTED); -#endif +#endif /* if defined(SO_ACCEPTFILTER) && defined(ENABLE_ACCEPTFILTER) */ } /* @@ -4550,15 +4598,16 @@ set_tcp_fastopen(isc__socket_t *sock, unsigned int backlog) } return; } -#endif +#endif /* if defined(__FreeBSD__) && defined(HAVE_SYSCTLBYNAME) */ #ifdef __APPLE__ backlog = 1; -#else +#else /* ifdef __APPLE__ */ backlog = backlog / 2; - if (backlog == 0) + if (backlog == 0) { backlog = 1; -#endif + } +#endif /* ifdef __APPLE__ */ if (setsockopt(sock->fd, IPPROTO_TCP, TCP_FASTOPEN, (void *)&backlog, sizeof(backlog)) < 0) { strerror_r(errno, strbuf, sizeof(strbuf)); @@ -4567,10 +4616,10 @@ set_tcp_fastopen(isc__socket_t *sock, unsigned int backlog) sock->fd, strbuf); /* TCP_FASTOPEN is experimental so ignore failures */ } -#else +#else /* if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN) */ UNUSED(sock); UNUSED(backlog); -#endif +#endif /* if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN) */ } /* @@ -4598,8 +4647,9 @@ isc_socket_listen(isc_socket_t *sock0, unsigned int backlog) REQUIRE(sock->type == isc_sockettype_tcp || sock->type == isc_sockettype_unix); - if (backlog == 0) + if (backlog == 0) { backlog = SOMAXCONN; + } if (listen(sock->fd, (int)backlog) < 0) { UNLOCK(&sock->lock); @@ -4711,8 +4761,9 @@ isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr, REQUIRE(VALID_MANAGER(manager)); REQUIRE(addr != NULL); - if (isc_sockaddr_ismulticast(addr)) + if (isc_sockaddr_ismulticast(addr)) { return (ISC_R_MULTICAST); + } LOCK(&sock->lock); @@ -4757,8 +4808,9 @@ isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr, cc = 0; goto success; } - if (SOFT_ERROR(errno) || errno == EINPROGRESS) + if (SOFT_ERROR(errno) || errno == EINPROGRESS) { goto queue; + } switch (errno) { #define ERROR_MATCH(a, b) \ @@ -4772,7 +4824,7 @@ isc_socket_connect(isc_socket_t *sock0, const isc_sockaddr_t *addr, ERROR_MATCH(EHOSTUNREACH, ISC_R_HOSTUNREACH); #ifdef EHOSTDOWN ERROR_MATCH(EHOSTDOWN, ISC_R_HOSTUNREACH); -#endif +#endif /* ifdef EHOSTDOWN */ ERROR_MATCH(ENETUNREACH, ISC_R_NETUNREACH); ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES); ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH); @@ -4882,10 +4934,11 @@ internal_connect(isc__socket_t *sock) */ optlen = sizeof(cc); if (getsockopt(sock->fd, SOL_SOCKET, SO_ERROR, (void *)&cc, - (void *)&optlen) != 0) + (void *)&optlen) != 0) { cc = errno; - else + } else { errno = cc; + } if (errno != 0) { /* @@ -4915,7 +4968,7 @@ internal_connect(isc__socket_t *sock) ERROR_MATCH(EHOSTUNREACH, ISC_R_HOSTUNREACH); #ifdef EHOSTDOWN ERROR_MATCH(EHOSTDOWN, ISC_R_HOSTUNREACH); -#endif +#endif /* ifdef EHOSTDOWN */ ERROR_MATCH(ENETUNREACH, ISC_R_NETUNREACH); ERROR_MATCH(ENOBUFS, ISC_R_NORESOURCES); ERROR_MATCH(EPERM, ISC_R_HOSTUNREACH); @@ -5024,8 +5077,9 @@ isc_socket_cancel(isc_socket_t *sock0, isc_task_t *task, unsigned int how) * Quick exit if there is nothing to do. Don't even bother locking * in this case. */ - if (how == 0) + if (how == 0) { return; + } LOCK(&sock->lock); @@ -5151,10 +5205,10 @@ isc_socket_ipv6only(isc_socket_t *sock0, bool yes) isc__socket_t *sock = (isc__socket_t *)sock0; #if defined(IPV6_V6ONLY) int onoff = yes ? 1 : 0; -#else +#else /* if defined(IPV6_V6ONLY) */ UNUSED(yes); UNUSED(sock); -#endif +#endif /* if defined(IPV6_V6ONLY) */ REQUIRE(VALID_SOCKET(sock)); INSIST(!sock->dupped); @@ -5171,7 +5225,7 @@ isc_socket_ipv6only(isc_socket_t *sock0, bool yes) sock->fd, strbuf); } } -#endif +#endif /* ifdef IPV6_V6ONLY */ } static void @@ -5179,7 +5233,7 @@ setdscp(isc__socket_t *sock, isc_dscp_t dscp) { #if defined(IP_TOS) || defined(IPV6_TCLASS) int value = dscp << 2; -#endif +#endif /* if defined(IP_TOS) || defined(IPV6_TCLASS) */ sock->dscp = dscp; @@ -5195,7 +5249,7 @@ setdscp(isc__socket_t *sock, isc_dscp_t dscp) sock->fd, value >> 2, strbuf); } } -#endif +#endif /* ifdef IP_TOS */ #ifdef IPV6_TCLASS if (sock->pf == AF_INET6) { if (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_TCLASS, @@ -5208,7 +5262,7 @@ setdscp(isc__socket_t *sock, isc_dscp_t dscp) sock->fd, dscp >> 2, strbuf); } } -#endif +#endif /* ifdef IPV6_TCLASS */ } void @@ -5221,18 +5275,20 @@ isc_socket_dscp(isc_socket_t *sock0, isc_dscp_t dscp) #if !defined(IP_TOS) && !defined(IPV6_TCLASS) UNUSED(dscp); -#else - if (dscp < 0) +#else /* if !defined(IP_TOS) && !defined(IPV6_TCLASS) */ + if (dscp < 0) { return; + } /* The DSCP value must not be changed once it has been set. */ - if (isc_dscp_check_value != -1) + if (isc_dscp_check_value != -1) { INSIST(dscp == isc_dscp_check_value); -#endif + } +#endif /* if !defined(IP_TOS) && !defined(IPV6_TCLASS) */ #ifdef notyet REQUIRE(!sock->dupped); -#endif +#endif /* ifdef notyet */ setdscp(sock, dscp); } @@ -5313,17 +5369,18 @@ init_hasreuseport() #if defined(__FreeBSD_kernel__) } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT_LB, (void *)&yes, sizeof(yes)) < 0) -#else +#else /* if defined(__FreeBSD_kernel__) */ } else if (setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void *)&yes, sizeof(yes)) < 0) -#endif +#endif /* if defined(__FreeBSD_kernel__) */ { close(sock); return; } hasreuseport = true; close(sock); -#endif +#endif /* if (defined(SO_REUSEPORT) && defined(__linux__)) || \ + * (defined(SO_REUSEPORT_LB) && defined(__FreeBSD_kernel__)) */ } bool @@ -5349,7 +5406,7 @@ _socktype(isc_sockettype_t type) return ("not-initialized"); } } -#endif +#endif /* if defined(HAVE_LIBXML2) || defined(HAVE_JSON_C) */ #ifdef HAVE_LIBXML2 #define TRY0(a) \ @@ -5419,24 +5476,28 @@ isc_socketmgr_renderxml(isc_socketmgr_t *mgr0, void *writer0) } TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "states")); - if (sock->listener) + if (sock->listener) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "listener")); - if (sock->connected) + } + if (sock->connected) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "connecte" "d")); - if (sock->connecting) + } + if (sock->connecting) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "connectin" "g")); - if (sock->bound) + } + if (sock->bound) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "bound")); + } TRY0(xmlTextWriterEndElement(writer)); /* states */ @@ -5448,8 +5509,9 @@ isc_socketmgr_renderxml(isc_socketmgr_t *mgr0, void *writer0) TRY0(xmlTextWriterEndElement(writer)); /* sockets */ error: - if (sock != NULL) + if (sock != NULL) { UNLOCK(&sock->lock); + } UNLOCK(&mgr->lock); @@ -5565,11 +5627,13 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr0, void *stats0) result = ISC_R_SUCCESS; error: - if (array != NULL) + if (array != NULL) { json_object_put(array); + } - if (sock != NULL) + if (sock != NULL) { UNLOCK(&sock->lock); + } UNLOCK(&mgr->lock); diff --git a/lib/isc/unix/stdio.c b/lib/isc/unix/stdio.c index 22795030b2..0183bdae6c 100644 --- a/lib/isc/unix/stdio.c +++ b/lib/isc/unix/stdio.c @@ -24,8 +24,9 @@ isc_stdio_open(const char *filename, const char *mode, FILE **fp) FILE *f; f = fopen(filename, mode); - if (f == NULL) + if (f == NULL) { return (isc__errno2result(errno)); + } *fp = f; return (ISC_R_SUCCESS); } @@ -36,10 +37,11 @@ isc_stdio_close(FILE *f) int r; r = fclose(f); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -48,10 +50,11 @@ isc_stdio_seek(FILE *f, off_t offset, int whence) int r; r = fseeko(f, offset, whence); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -65,8 +68,9 @@ isc_stdio_tell(FILE *f, off_t *offsetp) if (r >= 0) { *offsetp = r; return (ISC_R_SUCCESS); - } else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -78,13 +82,15 @@ isc_stdio_read(void *ptr, size_t size, size_t nmemb, FILE *f, size_t *nret) clearerr(f); r = fread(ptr, size, nmemb, f); if (r != nmemb) { - if (feof(f)) + if (feof(f)) { result = ISC_R_EOF; - else + } else { result = isc__errno2result(errno); + } } - if (nret != NULL) + if (nret != NULL) { *nret = r; + } return (result); } @@ -97,10 +103,12 @@ isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f, clearerr(f); r = fwrite(ptr, size, nmemb, f); - if (r != nmemb) + if (r != nmemb) { result = isc__errno2result(errno); - if (nret != NULL) + } + if (nret != NULL) { *nret = r; + } return (result); } @@ -110,10 +118,11 @@ isc_stdio_flush(FILE *f) int r; r = fflush(f); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } /* @@ -121,7 +130,7 @@ isc_stdio_flush(FILE *f) */ #if defined(EOPNOTSUPP) && !defined(ENOTSUP) #define ENOTSUP EOPNOTSUPP -#endif +#endif /* if defined(EOPNOTSUPP) && !defined(ENOTSUP) */ isc_result_t isc_stdio_sync(FILE *f) @@ -129,18 +138,21 @@ isc_stdio_sync(FILE *f) struct stat buf; int r; - if (fstat(fileno(f), &buf) != 0) + if (fstat(fileno(f), &buf) != 0) { return (isc__errno2result(errno)); + } /* * Only call fsync() on regular files. */ - if ((buf.st_mode & S_IFMT) != S_IFREG) + if ((buf.st_mode & S_IFMT) != S_IFREG) { return (ISC_R_SUCCESS); + } r = fsync(fileno(f)); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } diff --git a/lib/isc/unix/stdtime.c b/lib/isc/unix/stdtime.c index 722b80ad09..aa28decddc 100644 --- a/lib/isc/unix/stdtime.c +++ b/lib/isc/unix/stdtime.c @@ -23,7 +23,7 @@ #ifndef ISC_FIX_TV_USEC #define ISC_FIX_TV_USEC 1 -#endif +#endif /* ifndef ISC_FIX_TV_USEC */ #define US_PER_S 1000000 @@ -49,11 +49,12 @@ fix_tv_usec(struct timeval *tv) /* * Call syslog directly as we are called from the logging functions. */ - if (fixed) + if (fixed) { (void)syslog(LOG_ERR, "gettimeofday returned bad tv_usec: " "corrected"); + } } -#endif +#endif /* if ISC_FIX_TV_USEC */ void isc_stdtime_get(isc_stdtime_t *t) @@ -72,9 +73,9 @@ isc_stdtime_get(isc_stdtime_t *t) #if ISC_FIX_TV_USEC fix_tv_usec(&tv); INSIST(tv.tv_usec >= 0); -#else +#else /* if ISC_FIX_TV_USEC */ INSIST(tv.tv_usec >= 0 && tv.tv_usec < US_PER_S); -#endif +#endif /* if ISC_FIX_TV_USEC */ *t = (unsigned int)tv.tv_sec; } diff --git a/lib/isc/unix/syslog.c b/lib/isc/unix/syslog.c index 2112a79019..154c6fbc67 100644 --- a/lib/isc/unix/syslog.c +++ b/lib/isc/unix/syslog.c @@ -31,19 +31,19 @@ static struct dsn_c_pvt_sfnt { { LOG_LPR, "lpr" }, #ifdef LOG_NEWS { LOG_NEWS, "news" }, -#endif +#endif /* ifdef LOG_NEWS */ #ifdef LOG_UUCP { LOG_UUCP, "uucp" }, -#endif +#endif /* ifdef LOG_UUCP */ #ifdef LOG_CRON { LOG_CRON, "cron" }, -#endif +#endif /* ifdef LOG_CRON */ #ifdef LOG_AUTHPRIV { LOG_AUTHPRIV, "authpriv" }, -#endif +#endif /* ifdef LOG_AUTHPRIV */ #ifdef LOG_FTP { LOG_FTP, "ftp" }, -#endif +#endif /* ifdef LOG_FTP */ { LOG_LOCAL0, "local0" }, { LOG_LOCAL1, "local1" }, { LOG_LOCAL2, "local2" }, diff --git a/lib/isc/unix/time.c b/lib/isc/unix/time.c index a78c710f92..ed2b21a4b2 100644 --- a/lib/isc/unix/time.c +++ b/lib/isc/unix/time.c @@ -39,9 +39,9 @@ #define CLOCKSOURCE CLOCK_REALTIME_COARSE #elif defined(CLOCK_REALTIME_FAST) #define CLOCKSOURCE CLOCK_REALTIME_FAST -#else +#else /* if defined(CLOCK_REALTIME_COARSE) */ #define CLOCKSOURCE CLOCK_REALTIME -#endif +#endif /* if defined(CLOCK_REALTIME_COARSE) */ /*% *** Intervals @@ -67,8 +67,9 @@ isc_interval_iszero(const isc_interval_t *i) REQUIRE(i != NULL); INSIST(i->nanoseconds < NS_PER_S); - if (i->seconds == 0 && i->nanoseconds == 0) + if (i->seconds == 0 && i->nanoseconds == 0) { return (true); + } return (false); } @@ -105,8 +106,9 @@ isc_time_isepoch(const isc_time_t *t) REQUIRE(t != NULL); INSIST(t->nanoseconds < NS_PER_S); - if (t->seconds == 0 && t->nanoseconds == 0) + if (t->seconds == 0 && t->nanoseconds == 0) { return (true); + } return (false); } @@ -133,8 +135,9 @@ isc_time_now(isc_time_t *t) * Ensure the tv_sec value fits in t->seconds. */ if (sizeof(ts.tv_sec) > sizeof(t->seconds) && - ((ts.tv_sec | (unsigned int)-1) ^ (unsigned int)-1) != 0U) + ((ts.tv_sec | (unsigned int)-1) ^ (unsigned int)-1) != 0U) { return (ISC_R_RANGE); + } t->seconds = ts.tv_sec; t->nanoseconds = ts.tv_nsec; @@ -169,8 +172,9 @@ isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) * and getting another 1 added below the result is UINT_MAX.) */ if ((ts.tv_sec > INT_MAX || i->seconds > INT_MAX) && - ((long long)ts.tv_sec + i->seconds > UINT_MAX)) + ((long long)ts.tv_sec + i->seconds > UINT_MAX)) { return (ISC_R_RANGE); + } t->seconds = ts.tv_sec + i->seconds; t->nanoseconds = ts.tv_nsec + i->nanoseconds; @@ -188,14 +192,18 @@ isc_time_compare(const isc_time_t *t1, const isc_time_t *t2) REQUIRE(t1 != NULL && t2 != NULL); INSIST(t1->nanoseconds < NS_PER_S && t2->nanoseconds < NS_PER_S); - if (t1->seconds < t2->seconds) + if (t1->seconds < t2->seconds) { return (-1); - if (t1->seconds > t2->seconds) + } + if (t1->seconds > t2->seconds) { return (1); - if (t1->nanoseconds < t2->nanoseconds) + } + if (t1->nanoseconds < t2->nanoseconds) { return (-1); - if (t1->nanoseconds > t2->nanoseconds) + } + if (t1->nanoseconds > t2->nanoseconds) { return (1); + } return (0); } @@ -212,8 +220,9 @@ isc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result) * and getting another 1 added below the result is UINT_MAX.) */ if ((t->seconds > INT_MAX || i->seconds > INT_MAX) && - ((long long)t->seconds + i->seconds > UINT_MAX)) + ((long long)t->seconds + i->seconds > UINT_MAX)) { return (ISC_R_RANGE); + } result->seconds = t->seconds + i->seconds; result->nanoseconds = t->nanoseconds + i->nanoseconds; @@ -234,13 +243,14 @@ isc_time_subtract(const isc_time_t *t, const isc_interval_t *i, if ((unsigned int)t->seconds < i->seconds || ((unsigned int)t->seconds == i->seconds && - t->nanoseconds < i->nanoseconds)) + t->nanoseconds < i->nanoseconds)) { return (ISC_R_RANGE); + } result->seconds = t->seconds - i->seconds; - if (t->nanoseconds >= i->nanoseconds) + if (t->nanoseconds >= i->nanoseconds) { result->nanoseconds = t->nanoseconds - i->nanoseconds; - else { + } else { result->nanoseconds = NS_PER_S - i->nanoseconds + t->nanoseconds; result->seconds--; @@ -260,8 +270,9 @@ isc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2) i1 = (uint64_t)t1->seconds * NS_PER_S + t1->nanoseconds; i2 = (uint64_t)t2->seconds * NS_PER_S + t2->nanoseconds; - if (i1 <= i2) + if (i1 <= i2) { return (0); + } i3 = i1 - i2; @@ -312,8 +323,9 @@ isc_time_secondsastimet(const isc_time_t *t, time_t *secondsp) INSIST(sizeof(unsigned int) == sizeof(uint32_t)); INSIST(sizeof(time_t) >= sizeof(uint32_t)); - if (t->seconds > (~0U >> 1) && seconds <= (time_t)(~0U >> 1)) + if (t->seconds > (~0U >> 1) && seconds <= (time_t)(~0U >> 1)) { return (ISC_R_RANGE); + } *secondsp = seconds; @@ -345,10 +357,10 @@ isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) now = (time_t)t->seconds; flen = strftime(buf, len, "%d-%b-%Y %X", localtime_r(&now, &tm)); INSIST(flen < len); - if (flen != 0) + if (flen != 0) { snprintf(buf + flen, len - flen, ".%03u", t->nanoseconds / NS_PER_MS); - else { + } else { strlcpy(buf, "99-Bad-9999 99:99:99.999", len); } } @@ -385,11 +397,13 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) REQUIRE(t != NULL); p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm); - if (p == NULL) + if (p == NULL) { return (ISC_R_UNEXPECTED); + } when = isc_tm_timegm(&t_tm); - if (when == -1) + if (when == -1) { return (ISC_R_UNEXPECTED); + } isc_time_set(t, when, 0); return (ISC_R_SUCCESS); } diff --git a/lib/isc/win32/condition.c b/lib/isc/win32/condition.c index ad4b48092d..29c415ad27 100644 --- a/lib/isc/win32/condition.c +++ b/lib/isc/win32/condition.c @@ -64,8 +64,9 @@ register_thread(unsigned long thrd, isc_condition_t *gblcond, REQUIRE(localcond != NULL && *localcond == NULL); newthread = malloc(sizeof(isc_condition_thread_t)); - if (newthread == NULL) + if (newthread == NULL) { return (ISC_R_NOMEMORY); + } /* * Create the thread-specific handle @@ -150,12 +151,14 @@ isc_condition_broadcast(isc_condition_t *cond) */ for (threadcond = ISC_LIST_HEAD(cond->threadlist); threadcond != NULL; threadcond = ISC_LIST_NEXT(threadcond, link)) { - if (!SetEvent(threadcond->handle[LBROADCAST])) + if (!SetEvent(threadcond->handle[LBROADCAST])) { failed = true; + } } - if (failed) + if (failed) { return (ISC_R_UNEXPECTED); + } return (ISC_R_SUCCESS); } @@ -206,8 +209,9 @@ wait(isc_condition_t *cond, isc_mutex_t *mutex, DWORD milliseconds) * Get the thread events needed for the wait */ tresult = find_thread_condition(isc_thread_self(), cond, &threadcond); - if (tresult != ISC_R_SUCCESS) + if (tresult != ISC_R_SUCCESS) { return (tresult); + } cond->waiters++; LeaveCriticalSection(mutex); @@ -219,8 +223,9 @@ wait(isc_condition_t *cond, isc_mutex_t *mutex, DWORD milliseconds) /* XXX */ return (ISC_R_UNEXPECTED); } - if (result == WAIT_TIMEOUT) + if (result == WAIT_TIMEOUT) { return (ISC_R_TIMEDOUT); + } return (ISC_R_SUCCESS); } @@ -245,10 +250,11 @@ isc_condition_waituntil(isc_condition_t *cond, isc_mutex_t *mutex, } microseconds = isc_time_microdiff(t, &now); - if (microseconds > 0xFFFFFFFFi64 * 1000) + if (microseconds > 0xFFFFFFFFi64 * 1000) { milliseconds = 0xFFFFFFFF; - else + } else { milliseconds = (DWORD)(microseconds / 1000); + } return (wait(cond, mutex, milliseconds)); } diff --git a/lib/isc/win32/dir.c b/lib/isc/win32/dir.c index 48eb822814..e6bd56b206 100644 --- a/lib/isc/win32/dir.c +++ b/lib/isc/win32/dir.c @@ -65,17 +65,19 @@ isc_dir_open(isc_dir_t *dir, const char *dirname) * Copy directory name. Need to have enough space for the name, * a possible path separator, the wildcard, and the final NUL. */ - if (strlen(dirname) + 3 > sizeof(dir->dirname)) + if (strlen(dirname) + 3 > sizeof(dir->dirname)) { /* XXXDCL ? */ return (ISC_R_NOSPACE); + } strlcpy(dir->dirname, dirname, sizeof(dir->dirname)); /* * Append path separator, if needed, and "*". */ p = dir->dirname + strlen(dir->dirname); - if (dir->dirname < p && *(p - 1) != '\\' && *(p - 1) != ':') + if (dir->dirname < p && *(p - 1) != '\\' && *(p - 1) != ':') { *p++ = '\\'; + } *p++ = '*'; *p = '\0'; @@ -97,27 +99,28 @@ isc_dir_read(isc_dir_t *dir) { REQUIRE(VALID_DIR(dir) && dir->search_handle != INVALID_HANDLE_VALUE); - if (dir->entry_filled) + if (dir->entry_filled) { /* * start_directory() already filled in the first entry. */ dir->entry_filled = false; - - else { + } else { /* * Fetch next file in directory. */ if (FindNextFile(dir->search_handle, &dir->entry.find_data) == - FALSE) + FALSE) { /* * Either the last file has been processed or * an error has occurred. The former is not * really an error, but the latter is. */ - if (GetLastError() == ERROR_NO_MORE_FILES) + if (GetLastError() == ERROR_NO_MORE_FILES) { return (ISC_R_NOMORE); - else + } else { return (ISC_R_UNEXPECTED); + } + } } /* @@ -226,8 +229,9 @@ isc_dir_chdir(const char *dirname) REQUIRE(dirname != NULL); - if (chdir(dirname) < 0) + if (chdir(dirname) < 0) { return (isc__errno2result(errno)); + } return (ISC_R_SUCCESS); } @@ -266,22 +270,24 @@ isc_dir_createunique(char *templet) do { i = mkdir(templet); - if (i == 0) + if (i == 0) { i = chmod(templet, 0700); + } - if (i == 0 || errno != EEXIST) + if (i == 0 || errno != EEXIST) { break; + } /* * The BSD algorithm. */ p = x; while (*p != '\0') { - if (isdigit(*p & 0xff)) + if (isdigit(*p & 0xff)) { *p = 'a'; - else if (*p != 'z') + } else if (*p != 'z') { ++*p; - else { + } else { /* * Reset character and move to next. */ @@ -303,10 +309,11 @@ isc_dir_createunique(char *templet) } } while (1); - if (i == -1) + if (i == -1) { result = isc__errno2result(errno); - else + } else { result = ISC_R_SUCCESS; + } return (result); } diff --git a/lib/isc/win32/errno2result.c b/lib/isc/win32/errno2result.c index 4b9d233285..14c8a696da 100644 --- a/lib/isc/win32/errno2result.c +++ b/lib/isc/win32/errno2result.c @@ -55,7 +55,7 @@ isc__errno2resultx(int posixerrno, bool dolog, const char *file, int line) #ifdef EOVERFLOW case EOVERFLOW: return (ISC_R_RANGE); -#endif +#endif /* ifdef EOVERFLOW */ case ENFILE: case EMFILE: case WSAEMFILE: diff --git a/lib/isc/win32/file.c b/lib/isc/win32/file.c index 7d6f1890b4..8cedbafda5 100644 --- a/lib/isc/win32/file.c +++ b/lib/isc/win32/file.c @@ -50,8 +50,9 @@ gettemp(char *path, bool binary, int *doopen) struct stat sbuf; int flags = O_CREAT | O_EXCL | O_RDWR; - if (binary) + if (binary) { flags |= _O_BINARY; + } trv = strrchr(path, 'X'); trv++; @@ -65,12 +66,14 @@ gettemp(char *path, bool binary, int *doopen) * doesn't exist this runs for a *very* long time. */ for (start = trv + 1;; --trv) { - if (trv <= path) + if (trv <= path) { break; + } if (*trv == '\\') { *trv = '\0'; - if (stat(path, &sbuf)) + if (stat(path, &sbuf)) { return (0); + } if (!S_ISDIR(sbuf.st_mode)) { errno = ENOTDIR; return (0); @@ -83,24 +86,29 @@ gettemp(char *path, bool binary, int *doopen) for (;;) { if (doopen) { if ((*doopen = open(path, flags, - _S_IREAD | _S_IWRITE)) >= 0) + _S_IREAD | _S_IWRITE)) >= 0) { return (1); - if (errno != EEXIST) + } + if (errno != EEXIST) { return (0); - } else if (stat(path, &sbuf)) + } + } else if (stat(path, &sbuf)) { return (errno == ENOENT ? 1 : 0); + } /* tricky little algorithm for backward compatibility */ for (trv = start;;) { - if (!*trv) + if (!*trv) { return (0); - if (*trv == 'z') + } + if (*trv == 'z') { *trv++ = 'a'; - else { - if (isdigit(*trv)) + } else { + if (isdigit(*trv)) { *trv = 'a'; - else + } else { ++*trv; + } break; } } @@ -132,8 +140,9 @@ file_stats(const char *file, struct stat *stats) REQUIRE(file != NULL); REQUIRE(stats != NULL); - if (stat(file, stats) != 0) + if (stat(file, stats) != 0) { result = isc__errno2result(errno); + } return (result); } @@ -145,8 +154,9 @@ fd_stats(int fd, struct stat *stats) REQUIRE(stats != NULL); - if (fstat(fd, stats) != 0) + if (fstat(fd, stats) != 0) { result = isc__errno2result(errno); + } return (result); } @@ -161,8 +171,9 @@ isc_file_getsizefd(int fd, off_t *size) result = fd_stats(fd, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *size = stats.st_size; + } return (result); } @@ -175,8 +186,9 @@ isc_file_mode(const char *file, mode_t *modep) REQUIRE(modep != NULL); result = file_stats(file, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *modep = (stats.st_mode & 07777); + } return (result); } @@ -212,8 +224,9 @@ isc_file_safemovefile(const char *oldname, const char *newname) strlcpy(buf, newname, sizeof(buf)); strlcat(buf, ".XXXXX", sizeof(buf)); tmpfd = mkstemp(buf, true); - if (tmpfd > 0) + if (tmpfd > 0) { _close(tmpfd); + } (void)DeleteFile(buf); _chmod(newname, _S_IREAD | _S_IWRITE); @@ -231,8 +244,9 @@ isc_file_safemovefile(const char *oldname, const char *newname) */ if (exists == TRUE) { filestatus = MoveFile(buf, newname); - if (filestatus == 0) + if (filestatus == 0) { errno = EACCES; + } } return (-1); } @@ -240,8 +254,9 @@ isc_file_safemovefile(const char *oldname, const char *newname) /* * Delete the backup file if it got created */ - if (exists == TRUE) + if (exists == TRUE) { (void)DeleteFile(buf); + } return (0); } @@ -253,8 +268,9 @@ isc_file_getmodtime(const char *file, isc_time_t *time) REQUIRE(file != NULL); REQUIRE(time != NULL); - if ((fh = open(file, _O_RDONLY | _O_BINARY)) < 0) + if ((fh = open(file, _O_RDONLY | _O_BINARY)) < 0) { return (isc__errno2result(errno)); + } if (!GetFileTime((HANDLE)_get_osfhandle(fh), NULL, NULL, &time->absolute)) { @@ -277,8 +293,9 @@ isc_file_getsize(const char *file, off_t *size) result = file_stats(file, &stats); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *size = stats.st_size; + } return (result); } @@ -290,8 +307,9 @@ isc_file_settime(const char *file, isc_time_t *time) REQUIRE(file != NULL && time != NULL); - if ((fh = open(file, _O_RDWR | _O_BINARY)) < 0) + if ((fh = open(file, _O_RDWR | _O_BINARY)) < 0) { return (isc__errno2result(errno)); + } /* * Set the date via the filedate system call and return. Failing @@ -327,26 +345,30 @@ isc_file_template(const char *path, const char *templet, char *buf, REQUIRE(templet != NULL); REQUIRE(buf != NULL); - if (path == NULL) + if (path == NULL) { path = ""; + } s = strrchr(templet, '\\'); - if (s != NULL) + if (s != NULL) { templet = s + 1; + } s = strrchr(path, '\\'); if (s != NULL) { size_t prefixlen = s - path + 1; - if ((prefixlen + strlen(templet) + 1) > buflen) + if ((prefixlen + strlen(templet) + 1) > buflen) { return (ISC_R_NOSPACE); + } /* Copy 'prefixlen' bytes and NUL terminate. */ strlcpy(buf, path, ISC_MIN(prefixlen + 1, buflen)); strlcat(buf, templet, buflen); } else { - if ((strlen(templet) + 1) > buflen) + if ((strlen(templet) + 1) > buflen) { return (ISC_R_NOSPACE); + } strlcpy(buf, templet, buflen); } @@ -364,10 +386,11 @@ isc_file_renameunique(const char *file, char *templet) REQUIRE(templet != NULL); fd = mkstemp(templet, true); - if (fd == -1) + if (fd == -1) { result = isc__errno2result(errno); - else + } else { close(fd); + } if (result == ISC_R_SUCCESS) { int res; @@ -395,21 +418,23 @@ openuniquemode(char *templet, int mode, bool binary, FILE **fp) */ fd = mkstemp(templet, binary); - if (fd == -1) + if (fd == -1) { result = isc__errno2result(errno); + } if (result == ISC_R_SUCCESS) { #if 1 UNUSED(mode); -#else +#else /* if 1 */ (void)fchmod(fd, mode); -#endif +#endif /* if 1 */ f = fdopen(fd, binary ? "wb+" : "w+"); if (f == NULL) { result = isc__errno2result(errno); (void)remove(templet); (void)close(fd); - } else + } else { *fp = f; + } } return (result); @@ -463,10 +488,11 @@ isc_file_remove(const char *filename) REQUIRE(filename != NULL); r = unlink(filename); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -478,10 +504,11 @@ isc_file_rename(const char *oldname, const char *newname) REQUIRE(newname != NULL); r = isc_file_safemovefile(oldname, newname); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } bool @@ -503,11 +530,13 @@ isc_file_isplainfile(const char *filename) struct stat filestat; memset(&filestat, 0, sizeof(struct stat)); - if ((stat(filename, &filestat)) == -1) + if ((stat(filename, &filestat)) == -1) { return (isc__errno2result(errno)); + } - if (!S_ISREG(filestat.st_mode)) + if (!S_ISREG(filestat.st_mode)) { return (ISC_R_INVALIDFILE); + } return (ISC_R_SUCCESS); } @@ -521,11 +550,13 @@ isc_file_isplainfilefd(int fd) struct stat filestat; memset(&filestat, 0, sizeof(struct stat)); - if ((fstat(fd, &filestat)) == -1) + if ((fstat(fd, &filestat)) == -1) { return (isc__errno2result(errno)); + } - if (!S_ISREG(filestat.st_mode)) + if (!S_ISREG(filestat.st_mode)) { return (ISC_R_INVALIDFILE); + } return (ISC_R_SUCCESS); } @@ -539,11 +570,13 @@ isc_file_isdirectory(const char *filename) struct stat filestat; memset(&filestat, 0, sizeof(struct stat)); - if ((stat(filename, &filestat)) == -1) + if ((stat(filename, &filestat)) == -1) { return (isc__errno2result(errno)); + } - if (!S_ISDIR(filestat.st_mode)) + if (!S_ISDIR(filestat.st_mode)) { return (ISC_R_INVALIDFILE); + } return (ISC_R_SUCCESS); } @@ -556,12 +589,15 @@ isc_file_isabsolute(const char *filename) * Look for c:\path\... style, c:/path/... or \\computer\shar\path... * the UNC style file specs */ - if ((filename[0] == '\\') && (filename[1] == '\\')) + if ((filename[0] == '\\') && (filename[1] == '\\')) { return (true); - if (isalpha(filename[0]) && filename[1] == ':' && filename[2] == '\\') + } + if (isalpha(filename[0]) && filename[1] == ':' && filename[2] == '\\') { return (true); - if (isalpha(filename[0]) && filename[1] == ':' && filename[2] == '/') + } + if (isalpha(filename[0]) && filename[1] == ':' && filename[2] == '/') { return (true); + } return (false); } @@ -577,14 +613,18 @@ isc_file_ischdiridempotent(const char *filename) { REQUIRE(filename != NULL); - if (isc_file_isabsolute(filename)) + if (isc_file_isabsolute(filename)) { return (true); - if (filename[0] == '\\') + } + if (filename[0] == '\\') { return (true); - if (filename[0] == '/') + } + if (filename[0] == '/') { return (true); - if (isc_file_iscurrentdir(filename)) + } + if (isc_file_iscurrentdir(filename)) { return (true); + } return (false); } @@ -596,8 +636,9 @@ isc_file_basename(const char *filename) REQUIRE(filename != NULL); s = strrchr(filename, '\\'); - if (s == NULL) + if (s == NULL) { return (filename); + } return (s + 1); } @@ -624,8 +665,9 @@ isc_file_progname(const char *filename, char *progname, size_t namelen) */ p = strchr(s, '.'); if (p == NULL) { - if (namelen <= strlen(s)) + if (namelen <= strlen(s)) { return (ISC_R_NOSPACE); + } strlcpy(progname, s, namelen); return (ISC_R_SUCCESS); @@ -635,8 +677,9 @@ isc_file_progname(const char *filename, char *progname, size_t namelen) * Copy the result to the buffer */ len = p - s; - if (len >= namelen) + if (len >= namelen) { return (ISC_R_NOSPACE); + } /* Copy up to 'len' bytes and NUL terminate. */ strlcpy(progname, s, ISC_MIN(len + 1, namelen)); @@ -655,11 +698,13 @@ isc_file_absolutepath(const char *filename, char *path, size_t pathlen) retval = GetFullPathName(filename, (DWORD)pathlen, path, &ptrname); /* Something went wrong in getting the path */ - if (retval == 0) + if (retval == 0) { return (ISC_R_NOTFOUND); + } /* Caller needs to provide a larger buffer to contain the string */ - if (retval >= pathlen) + if (retval >= pathlen) { return (ISC_R_NOSPACE); + } return (ISC_R_SUCCESS); } @@ -670,8 +715,9 @@ isc_file_truncate(const char *filename, isc_offset_t size) REQUIRE(filename != NULL && size >= 0); - if ((fh = open(filename, _O_RDWR | _O_BINARY)) < 0) + if ((fh = open(filename, _O_RDWR | _O_BINARY)) < 0) { return (isc__errno2result(errno)); + } if (_chsize(fh, size) != 0) { close(fh); @@ -696,17 +742,20 @@ isc_file_safecreate(const char *filename, FILE **fp) result = file_stats(filename, &sb); if (result == ISC_R_SUCCESS) { - if ((sb.st_mode & S_IFREG) == 0) + if ((sb.st_mode & S_IFREG) == 0) { return (ISC_R_INVALIDFILE); + } flags = O_WRONLY | O_TRUNC; } else if (result == ISC_R_FILENOTFOUND) { flags = O_WRONLY | O_CREAT | O_EXCL; - } else + } else { return (result); + } fd = open(filename, flags, S_IRUSR | S_IWUSR); - if (fd == -1) + if (fd == -1) { return (isc__errno2result(errno)); + } f = fdopen(fd, "w"); if (f == NULL) { @@ -731,8 +780,9 @@ isc_file_splitpath(isc_mem_t *mctx, const char *path, char **dirname, backslash = strrchr(path, '\\'); if ((slash != NULL && backslash != NULL && backslash > slash) || - (slash == NULL && backslash != NULL)) + (slash == NULL && backslash != NULL)) { slash = backslash; + } if (slash == path) { file = ++slash; @@ -746,8 +796,9 @@ isc_file_splitpath(isc_mem_t *mctx, const char *path, char **dirname, dir = isc_mem_strdup(mctx, "."); } - if (dir == NULL) + if (dir == NULL) { return (ISC_R_NOMEMORY); + } if (*file == '\0') { isc_mem_free(mctx, dir); @@ -773,12 +824,14 @@ isc_file_mmap(void *addr, size_t len, int prot, int flags, int fd, off_t offset) end = lseek(fd, 0, SEEK_END); lseek(fd, offset, SEEK_SET); - if (end - offset < (off_t)len) + if (end - offset < (off_t)len) { len = end - offset; + } buf = malloc(len); - if (buf == NULL) + if (buf == NULL) { return (NULL); + } ret = read(fd, buf, (unsigned int)len); if (ret != (ssize_t)len) { @@ -835,16 +888,20 @@ isc_file_sanitize(const char *dir, const char *base, const char *ext, * allow room for a full sha256 hash (64 chars * plus null terminator) */ - if (l < 65) + if (l < 65) { l = 65; + } - if (dir != NULL) + if (dir != NULL) { l += strlen(dir) + 1; - if (ext != NULL) + } + if (ext != NULL) { l += strlen(ext) + 1; + } - if (l > length || l > PATH_MAX) + if (l > length || l > PATH_MAX) { return (ISC_R_NOSPACE); + } /* Check whether the full-length SHA256 hash filename exists */ err = isc_md(ISC_MD_SHA256, (const unsigned char *)base, strlen(base), diff --git a/lib/isc/win32/fsaccess.c b/lib/isc/win32/fsaccess.c index c54e28c10a..f7d16e2491 100644 --- a/lib/isc/win32/fsaccess.c +++ b/lib/isc/win32/fsaccess.c @@ -83,16 +83,17 @@ is_ntfs(const char *file) strlcat(drive, "\\", sizeof(drive)); strlcat(drive, sharename, sizeof(drive)); strlcat(drive, "\\", sizeof(drive)); - - } else /* Not determinable */ + } else { /* Not determinable */ return (FALSE); + } GetVolumeInformation(drive, NULL, 0, NULL, 0, NULL, FSType, sizeof(FSType)); - if (strcmp(FSType, "NTFS") == 0) + if (strcmp(FSType, "NTFS") == 0) { return (TRUE); - else + } else { return (FALSE); + } } /* @@ -134,8 +135,9 @@ FAT_fsaccess_set(const char *path, isc_fsaccess_t access) INSIST(access == 0); - if (_chmod(path, mode) < 0) + if (_chmod(path, mode) < 0) { return (isc__errno2result(errno)); + } return (ISC_R_SUCCESS); } @@ -163,13 +165,16 @@ NTFS_Access_Control(const char *filename, const char *user, int access, int caccess; /* Initialize an ACL */ - if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) + if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) { return (ISC_R_NOPERM); - if (!InitializeAcl(pacl, sizeof(aclBuffer), ACL_REVISION)) + } + if (!InitializeAcl(pacl, sizeof(aclBuffer), ACL_REVISION)) { return (ISC_R_NOPERM); + } if (!LookupAccountName(0, user, psid, &sidBufferSize, domainBuffer, - &domainBufferSize, &snu)) + &domainBufferSize, &snu)) { return (ISC_R_NOPERM); + } domainBufferSize = sizeof(domainBuffer); if (!LookupAccountName(0, "Administrators", padminsid, &adminSidBufferSize, domainBuffer, @@ -215,8 +220,9 @@ NTFS_Access_Control(const char *filename, const char *user, int access, } if (NTFSbits == - (FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE)) + (FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE)) { NTFSbits |= FILE_ALL_ACCESS; + } /* * Owner and Administrator also get STANDARD_RIGHTS_ALL * to ensure that they have full control @@ -225,10 +231,12 @@ NTFS_Access_Control(const char *filename, const char *user, int access, NTFSbits |= STANDARD_RIGHTS_ALL; /* Add the ACE to the ACL */ - if (!AddAccessAllowedAce(pacl, ACL_REVISION, NTFSbits, psid)) + if (!AddAccessAllowedAce(pacl, ACL_REVISION, NTFSbits, psid)) { return (ISC_R_NOPERM); - if (!AddAccessAllowedAce(pacl, ACL_REVISION, NTFSbits, padminsid)) + } + if (!AddAccessAllowedAce(pacl, ACL_REVISION, NTFSbits, padminsid)) { return (ISC_R_NOPERM); + } /* * Group is ignored since we can be in multiple groups or no group @@ -270,11 +278,13 @@ NTFS_Access_Control(const char *filename, const char *user, int access, } } /* Add the ACE to the ACL */ - if (!AddAccessAllowedAce(pacl, ACL_REVISION, NTFSbits, pothersid)) + if (!AddAccessAllowedAce(pacl, ACL_REVISION, NTFSbits, pothersid)) { return (ISC_R_NOPERM); + } - if (!SetSecurityDescriptorDacl(&sd, TRUE, pacl, FALSE)) + if (!SetSecurityDescriptorDacl(&sd, TRUE, pacl, FALSE)) { return (ISC_R_NOPERM); + } if (!SetFileSecurity(filename, DACL_SECURITY_INFORMATION, &sd)) { return (ISC_R_NOPERM); } @@ -291,8 +301,9 @@ NTFS_fsaccess_set(const char *path, isc_fsaccess_t access, bool isdir) */ if (namelen == 0) { namelen = sizeof(username); - if (GetUserName(username, &namelen) == 0) + if (GetUserName(username, &namelen) == 0) { return (ISC_R_FAILURE); + } } return (NTFS_Access_Control(path, username, access, isdir)); } @@ -304,26 +315,30 @@ isc_fsaccess_set(const char *path, isc_fsaccess_t access) bool is_dir = false; isc_result_t result; - if (stat(path, &statb) != 0) + if (stat(path, &statb) != 0) { return (isc__errno2result(errno)); + } - if ((statb.st_mode & S_IFDIR) != 0) + if ((statb.st_mode & S_IFDIR) != 0) { is_dir = true; - else if ((statb.st_mode & S_IFREG) == 0) + } else if ((statb.st_mode & S_IFREG) == 0) { return (ISC_R_INVALIDFILE); + } result = check_bad_bits(access, is_dir); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Determine if this is a FAT or NTFS disk and * call the appropriate function to set the permissions */ - if (is_ntfs(path)) + if (is_ntfs(path)) { return (NTFS_fsaccess_set(path, access, is_dir)); - else + } else { return (FAT_fsaccess_set(path, access)); + } } isc_result_t @@ -346,33 +361,40 @@ isc_fsaccess_changeowner(const char *filename, const char *user) * FAT disks do not have ownership attributes so it's * a noop. */ - if (is_ntfs(filename) == FALSE) + if (is_ntfs(filename) == FALSE) { return (ISC_R_SUCCESS); + } - if (!InitializeSecurityDescriptor(&psd, SECURITY_DESCRIPTOR_REVISION)) + if (!InitializeSecurityDescriptor(&psd, SECURITY_DESCRIPTOR_REVISION)) { return (ISC_R_NOPERM); + } if (!LookupAccountName(0, user, psid, &sidBufferSize, domainBuffer, - &domainBufferSize, &snu)) + &domainBufferSize, &snu)) { return (ISC_R_NOPERM); + } /* Make sure administrators can get to it */ domainBufferSize = sizeof(domainBuffer); if (!LookupAccountName(0, "Administrators", pSidGroup, &groupBufferSize, - domainBuffer, &domainBufferSize, &snu)) + domainBuffer, &domainBufferSize, &snu)) { return (ISC_R_NOPERM); + } - if (!SetSecurityDescriptorOwner(&psd, psid, FALSE)) + if (!SetSecurityDescriptorOwner(&psd, psid, FALSE)) { return (ISC_R_NOPERM); + } - if (!SetSecurityDescriptorGroup(&psd, pSidGroup, FALSE)) + if (!SetSecurityDescriptorGroup(&psd, pSidGroup, FALSE)) { return (ISC_R_NOPERM); + } if (!SetFileSecurity(filename, OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION, - &psd)) + &psd)) { return (ISC_R_NOPERM); + } return (ISC_R_SUCCESS); } diff --git a/lib/isc/win32/include/isc/ipv6.h b/lib/isc/win32/include/isc/ipv6.h index 906fde5567..3b8b0eb0a0 100644 --- a/lib/isc/win32/include/isc/ipv6.h +++ b/lib/isc/win32/include/isc/ipv6.h @@ -13,8 +13,8 @@ #define ISC_IPV6_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /* * IPv6 definitions for systems which do not support IPv6. @@ -37,7 +37,7 @@ #if _MSC_VER < 1300 #define in6_addr in_addr6 -#endif +#endif /* if _MSC_VER < 1300 */ #ifndef IN6ADDR_ANY_INIT #define IN6ADDR_ANY_INIT \ @@ -46,7 +46,7 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 \ } \ } -#endif +#endif /* ifndef IN6ADDR_ANY_INIT */ #ifndef IN6ADDR_LOOPBACK_INIT #define IN6ADDR_LOOPBACK_INIT \ { \ @@ -54,7 +54,7 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 \ } \ } -#endif +#endif /* ifndef IN6ADDR_LOOPBACK_INIT */ #ifndef IN6ADDR_V4MAPPED_INIT #define IN6ADDR_V4MAPPED_INIT \ { \ @@ -62,7 +62,7 @@ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 0, 0, 0, 0 \ } \ } -#endif +#endif /* ifndef IN6ADDR_V4MAPPED_INIT */ LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_any; LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_loopback; @@ -76,7 +76,7 @@ LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_loopback; *((u_long *)((a)->s6_addr) + 1) == 0 && \ *((u_long *)((a)->s6_addr) + 2) == 0 && \ *((u_long *)((a)->s6_addr) + 3) == 0) -#endif +#endif /* ifndef IN6_IS_ADDR_UNSPECIFIED */ /* * Loopback @@ -87,7 +87,7 @@ LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_loopback; *((u_long *)((a)->s6_addr) + 1) == 0 && \ *((u_long *)((a)->s6_addr) + 2) == 0 && \ *((u_long *)((a)->s6_addr) + 3) == htonl(1)) -#endif +#endif /* ifndef IN6_IS_ADDR_LOOPBACK */ /* * IPv4 compatible @@ -118,11 +118,11 @@ LIBISC_EXTERNAL_DATA extern const struct in6_addr isc_in6addr_loopback; #ifndef IN6_IS_ADDR_LINKLOCAL #define IN6_IS_ADDR_LINKLOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0x80)) -#endif +#endif /* ifndef IN6_IS_ADDR_LINKLOCAL */ #ifndef IN6_IS_ADDR_SITELOCAL #define IN6_IS_ADDR_SITELOCAL(a) \ (((a)->s6_addr[0] == 0xfe) && (((a)->s6_addr[1] & 0xc0) == 0xc0)) -#endif +#endif /* ifndef IN6_IS_ADDR_SITELOCAL */ #endif /* ISC_IPV6_H */ diff --git a/lib/isc/win32/include/isc/net.h b/lib/isc/win32/include/isc/net.h index a85b367a80..45e4c0bb6c 100644 --- a/lib/isc/win32/include/isc/net.h +++ b/lib/isc/win32/include/isc/net.h @@ -13,8 +13,8 @@ #define ISC_NET_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /* * Basic Networking Types @@ -74,7 +74,7 @@ */ #ifndef _WINSOCKAPI_ #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ -#endif +#endif /* ifndef _WINSOCKAPI_ */ #include #include @@ -93,16 +93,16 @@ #ifndef INADDR_ANY #define INADDR_ANY 0x00000000UL -#endif +#endif /* ifndef INADDR_ANY */ #ifndef INADDR_LOOPBACK #define INADDR_LOOPBACK 0x7f000001UL -#endif +#endif /* ifndef INADDR_LOOPBACK */ #if _MSC_VER < 1300 #define in6addr_any isc_in6addr_any #define in6addr_loopback isc_in6addr_loopback -#endif +#endif /* if _MSC_VER < 1300 */ /* * Ensure type in_port_t is defined. @@ -116,7 +116,7 @@ typedef uint16_t in_port_t; */ #ifndef MSG_TRUNC #define ISC_PLATFORM_RECVOVERFLOW -#endif +#endif /* ifndef MSG_TRUNC */ #define ISC__IPADDR(x) ((uint32_t)htonl((uint32_t)(x))) @@ -178,109 +178,109 @@ typedef uint16_t in_port_t; #ifndef EWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK -#endif +#endif /* ifndef EWOULDBLOCK */ #ifndef EINPROGRESS #define EINPROGRESS WSAEINPROGRESS -#endif +#endif /* ifndef EINPROGRESS */ #ifndef EALREADY #define EALREADY WSAEALREADY -#endif +#endif /* ifndef EALREADY */ #ifndef ENOTSOCK #define ENOTSOCK WSAENOTSOCK -#endif +#endif /* ifndef ENOTSOCK */ #ifndef EDESTADDRREQ #define EDESTADDRREQ WSAEDESTADDRREQ -#endif +#endif /* ifndef EDESTADDRREQ */ #ifndef EMSGSIZE #define EMSGSIZE WSAEMSGSIZE -#endif +#endif /* ifndef EMSGSIZE */ #ifndef EPROTOTYPE #define EPROTOTYPE WSAEPROTOTYPE -#endif +#endif /* ifndef EPROTOTYPE */ #ifndef ENOPROTOOPT #define ENOPROTOOPT WSAENOPROTOOPT -#endif +#endif /* ifndef ENOPROTOOPT */ #ifndef EPROTONOSUPPORT #define EPROTONOSUPPORT WSAEPROTONOSUPPORT -#endif +#endif /* ifndef EPROTONOSUPPORT */ #ifndef ESOCKTNOSUPPORT #define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT -#endif +#endif /* ifndef ESOCKTNOSUPPORT */ #ifndef EOPNOTSUPP #define EOPNOTSUPP WSAEOPNOTSUPP -#endif +#endif /* ifndef EOPNOTSUPP */ #ifndef EPFNOSUPPORT #define EPFNOSUPPORT WSAEPFNOSUPPORT -#endif +#endif /* ifndef EPFNOSUPPORT */ #ifndef EAFNOSUPPORT #define EAFNOSUPPORT WSAEAFNOSUPPORT -#endif +#endif /* ifndef EAFNOSUPPORT */ #ifndef EADDRINUSE #define EADDRINUSE WSAEADDRINUSE -#endif +#endif /* ifndef EADDRINUSE */ #ifndef EADDRNOTAVAIL #define EADDRNOTAVAIL WSAEADDRNOTAVAIL -#endif +#endif /* ifndef EADDRNOTAVAIL */ #ifndef ENETDOWN #define ENETDOWN WSAENETDOWN -#endif +#endif /* ifndef ENETDOWN */ #ifndef ENETUNREACH #define ENETUNREACH WSAENETUNREACH -#endif +#endif /* ifndef ENETUNREACH */ #ifndef ENETRESET #define ENETRESET WSAENETRESET -#endif +#endif /* ifndef ENETRESET */ #ifndef ECONNABORTED #define ECONNABORTED WSAECONNABORTED -#endif +#endif /* ifndef ECONNABORTED */ #ifndef ECONNRESET #define ECONNRESET WSAECONNRESET -#endif +#endif /* ifndef ECONNRESET */ #ifndef ENOBUFS #define ENOBUFS WSAENOBUFS -#endif +#endif /* ifndef ENOBUFS */ #ifndef EISCONN #define EISCONN WSAEISCONN -#endif +#endif /* ifndef EISCONN */ #ifndef ENOTCONN #define ENOTCONN WSAENOTCONN -#endif +#endif /* ifndef ENOTCONN */ #ifndef ESHUTDOWN #define ESHUTDOWN WSAESHUTDOWN -#endif +#endif /* ifndef ESHUTDOWN */ #ifndef ETOOMANYREFS #define ETOOMANYREFS WSAETOOMANYREFS -#endif +#endif /* ifndef ETOOMANYREFS */ #ifndef ETIMEDOUT #define ETIMEDOUT WSAETIMEDOUT -#endif +#endif /* ifndef ETIMEDOUT */ #ifndef ECONNREFUSED #define ECONNREFUSED WSAECONNREFUSED -#endif +#endif /* ifndef ECONNREFUSED */ #ifndef ELOOP #define ELOOP WSAELOOP -#endif +#endif /* ifndef ELOOP */ #ifndef EHOSTDOWN #define EHOSTDOWN WSAEHOSTDOWN -#endif +#endif /* ifndef EHOSTDOWN */ #ifndef EHOSTUNREACH #define EHOSTUNREACH WSAEHOSTUNREACH -#endif +#endif /* ifndef EHOSTUNREACH */ #ifndef EPROCLIM #define EPROCLIM WSAEPROCLIM -#endif +#endif /* ifndef EPROCLIM */ #ifndef EUSERS #define EUSERS WSAEUSERS -#endif +#endif /* ifndef EUSERS */ #ifndef EDQUOT #define EDQUOT WSAEDQUOT -#endif +#endif /* ifndef EDQUOT */ #ifndef ESTALE #define ESTALE WSAESTALE -#endif +#endif /* ifndef ESTALE */ #ifndef EREMOTE #define EREMOTE WSAEREMOTE -#endif +#endif /* ifndef EREMOTE */ /*** *** Functions. diff --git a/lib/isc/win32/include/isc/netdb.h b/lib/isc/win32/include/isc/netdb.h index 02a8aeb5dc..697df4c81c 100644 --- a/lib/isc/win32/include/isc/netdb.h +++ b/lib/isc/win32/include/isc/netdb.h @@ -13,8 +13,8 @@ #define ISC_NETDB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /* * Portable netdb.h support. diff --git a/lib/isc/win32/include/isc/stat.h b/lib/isc/win32/include/isc/stat.h index fd7b4d68b2..dec3a4cca6 100644 --- a/lib/isc/win32/include/isc/stat.h +++ b/lib/isc/win32/include/isc/stat.h @@ -35,22 +35,22 @@ typedef unsigned short mode_t; #ifndef S_IFMT #define S_IFMT _S_IFMT -#endif +#endif /* ifndef S_IFMT */ #ifndef S_IFDIR #define S_IFDIR _S_IFDIR -#endif +#endif /* ifndef S_IFDIR */ #ifndef S_IFCHR #define S_IFCHR _S_IFCHR -#endif +#endif /* ifndef S_IFCHR */ #ifndef S_IFREG #define S_IFREG _S_IFREG -#endif +#endif /* ifndef S_IFREG */ #ifndef S_ISDIR #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR) -#endif +#endif /* ifndef S_ISDIR */ #ifndef S_ISREG #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG) -#endif +#endif /* ifndef S_ISREG */ #endif /* ISC_STAT_H */ diff --git a/lib/isc/win32/include/isc/stdatomic.h b/lib/isc/win32/include/isc/stdatomic.h index b1d1f8e45c..0ab679b142 100644 --- a/lib/isc/win32/include/isc/stdatomic.h +++ b/lib/isc/win32/include/isc/stdatomic.h @@ -29,22 +29,22 @@ #ifndef __ATOMIC_RELAXED #define __ATOMIC_RELAXED 0 -#endif +#endif /* ifndef __ATOMIC_RELAXED */ #ifndef __ATOMIC_CONSUME #define __ATOMIC_CONSUME 1 -#endif +#endif /* ifndef __ATOMIC_CONSUME */ #ifndef __ATOMIC_ACQUIRE #define __ATOMIC_ACQUIRE 2 -#endif +#endif /* ifndef __ATOMIC_ACQUIRE */ #ifndef __ATOMIC_RELEASE #define __ATOMIC_RELEASE 3 -#endif +#endif /* ifndef __ATOMIC_RELEASE */ #ifndef __ATOMIC_ACQ_REL #define __ATOMIC_ACQ_REL 4 -#endif +#endif /* ifndef __ATOMIC_ACQ_REL */ #ifndef __ATOMIC_SEQ_CST #define __ATOMIC_SEQ_CST 5 -#endif +#endif /* ifndef __ATOMIC_SEQ_CST */ enum memory_order { memory_order_relaxed = __ATOMIC_RELAXED, @@ -96,10 +96,10 @@ typedef uintptr_t volatile atomic_uintptr_t; (atomic_int_fast64_t *)obj, desired) \ : (void)InterlockedExchange64( \ (atomic_int_fast64_t *)obj, desired))) -#else +#else /* ifdef _WIN64 */ #define atomic_store_explicit64(obj, desired, order) \ (void)InterlockedExchange64((atomic_int_fast64_t *)obj, desired) -#endif +#endif /* ifdef _WIN64 */ static inline void atomic_store_abort() @@ -151,10 +151,10 @@ atomic_store_abort() : InterlockedOr64( \ (atomic_int_fast64_t *)obj, \ 0)))) -#else +#else /* ifdef _WIN64 */ #define atomic_load_explicit64(obj, order) \ InterlockedOr64((atomic_int_fast64_t *)obj, 0) -#endif +#endif /* ifdef _WIN64 */ static inline int8_t atomic_load_abort() @@ -213,10 +213,10 @@ atomic_load_abort() : InterlockedExchangeAdd64( \ (atomic_int_fast64_t *)obj, \ arg)))) -#else +#else /* ifdef _WIN64 */ #define atomic_fetch_add_explicit64(obj, arg, order) \ InterlockedExchangeAdd64((atomic_int_fast64_t *)obj, arg) -#endif +#endif /* ifdef _WIN64 */ static inline int8_t atomic_add_abort() @@ -275,10 +275,10 @@ atomic_add_abort() : InterlockedAnd64( \ (atomic_int_fast64_t *)obj, \ arg)))) -#else +#else /* ifdef _WIN64 */ #define atomic_fetch_and_explicit64(obj, arg, order) \ InterlockedAnd64((atomic_int_fast64_t *)obj, arg) -#endif +#endif /* ifdef _WIN64 */ static inline int8_t atomic_and_abort() @@ -331,10 +331,10 @@ atomic_and_abort() : InterlockedOr64( \ (atomic_int_fast64_t *)obj, \ arg)))) -#else +#else /* ifdef _WIN64 */ #define atomic_fetch_or_explicit64(obj, arg, order) \ InterlockedOr64((atomic_int_fast64_t *)obj, arg) -#endif +#endif /* ifdef _WIN64 */ static inline int8_t atomic_or_abort() @@ -442,10 +442,10 @@ atomic_compare_exchange_strong_explicit64(atomic_int_fast64_t *obj, desired, *expected); break; } -#else +#else /* ifdef _WIN64 */ __v = InterlockedCompareExchange64((atomic_int_fast64_t *)obj, desired, *expected); -#endif +#endif /* ifdef _WIN64 */ __r = (*(expected) == __v); if (!__r) { *(expected) = __v; diff --git a/lib/isc/win32/include/isc/thread.h b/lib/isc/win32/include/isc/thread.h index a116eb1456..7f1998f962 100644 --- a/lib/isc/win32/include/isc/thread.h +++ b/lib/isc/win32/include/isc/thread.h @@ -96,9 +96,9 @@ isc_thread_setaffinity(int cpu); #if HAVE___DECLSPEC_THREAD #define ISC_THREAD_LOCAL static __declspec(thread) -#else +#else /* if HAVE___DECLSPEC_THREAD */ #error "Thread-local storage support is required!" -#endif +#endif /* if HAVE___DECLSPEC_THREAD */ ISC_LANG_ENDDECLS diff --git a/lib/isc/win32/interfaceiter.c b/lib/isc/win32/interfaceiter.c index 2f5d8fd98d..a78234509f 100644 --- a/lib/isc/win32/interfaceiter.c +++ b/lib/isc/win32/interfaceiter.c @@ -134,8 +134,9 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) iter->socket = socket(AF_INET, SOCK_DGRAM, 0); if (iter->socket == INVALID_SOCKET) { error = WSAGetLastError(); - if (error == WSAEAFNOSUPPORT) + if (error == WSAEAFNOSUPPORT) { goto inet6_only; + } strerror_r(error, strbuf, sizeof(strbuf)); UNEXPECTED_ERROR(__FILE__, __LINE__, "making interface scan socket: %s", strbuf); @@ -177,8 +178,9 @@ isc_interfaceiter_create(isc_mem_t *mctx, isc_interfaceiter_t **iterp) * case and retry. */ if (bytesReturned > 0 && - (bytesReturned < iter->buf4size)) + (bytesReturned < iter->buf4size)) { break; + } } if (iter->buf4size >= IFCONF_SIZE_MAX * sizeof(INTERFACE_INFO)) { @@ -211,8 +213,9 @@ inet6_only: iter->socket = socket(AF_INET6, SOCK_DGRAM, 0); if (iter->socket == INVALID_SOCKET) { error = WSAGetLastError(); - if (error == WSAEAFNOSUPPORT) + if (error == WSAEAFNOSUPPORT) { goto inet_only; + } strerror_r(error, strbuf, sizeof(strbuf)); UNEXPECTED_ERROR(__FILE__, __LINE__, "making interface scan socket: %s", strbuf); @@ -246,8 +249,9 @@ inet6_only: /* * EINVAL. Retry with a bigger buffer. */ - } else + } else { break; + } if (iter->buf6size >= IFCONF_SIZE_MAX * sizeof(SOCKET_ADDRESS)) { @@ -274,10 +278,12 @@ ioctl6_failure: isc_mem_put(mctx, iter->buf6, iter->buf6size); ioctl_failure: - if (iter->buf4 != NULL) + if (iter->buf4 != NULL) { isc_mem_put(mctx, iter->buf4, iter->buf4size); - if (iter->socket != INVALID_SOCKET) + } + if (iter->socket != INVALID_SOCKET) { (void)closesocket(iter->socket); + } socket_failure: isc_mem_put(mctx, iter, sizeof(*iter)); @@ -314,8 +320,9 @@ internal_current(isc_interfaceiter_t *iter) iter->current.flags = 0; flags = iter->IFData.iiFlags; - if ((flags & IFF_UP) != 0) + if ((flags & IFF_UP) != 0) { iter->current.flags |= INTERFACE_F_UP; + } if ((flags & IFF_POINTTOPOINT) != 0) { iter->current.flags |= INTERFACE_F_POINTTOPOINT; @@ -339,9 +346,10 @@ internal_current(isc_interfaceiter_t *iter) (struct sockaddr *)&(iter->IFData.iiBroadcastAddress)); } - if (ifNamed == FALSE) + if (ifNamed == FALSE) { snprintf(iter->current.name, sizeof(iter->current.name), "TCP/IP Interface %d", iter->numIF); + } /* * Get the network mask. @@ -365,8 +373,9 @@ internal_current6(isc_interfaceiter_t *iter) iter->current.af = AF_INET6; if (!iter->pos6zero) { - if (iter->pos6 == 0U) + if (iter->pos6 == 0U) { iter->pos6zero = true; + } get_addr(AF_INET6, &iter->current.address, iter->buf6->Address[iter->pos6].lpSockaddr); @@ -382,8 +391,9 @@ internal_current6(isc_interfaceiter_t *iter) for (i = 0; i < 16; i++) iter->current.netmask.type.in6.s6_addr[i] = 0xff; iter->current.netmask.family = AF_INET6; - if (IN6_IS_ADDR_LOOPBACK(&iter->current.address.type.in6)) + if (IN6_IS_ADDR_LOOPBACK(&iter->current.address.type.in6)) { iter->v6loop = true; + } } else { /* * See if we can bind to the ::1 and if so return ::1. @@ -393,8 +403,9 @@ internal_current6(isc_interfaceiter_t *iter) iter->v6loop = true; /* So we don't loop forever. */ fd = socket(AF_INET6, SOCK_DGRAM, 0); - if (fd == INVALID_SOCKET) + if (fd == INVALID_SOCKET) { return (ISC_R_IGNORE); + } memset(&sin6, 0, sizeof(sin6)); sin6.sin6_family = AF_INET6; sin6.sin6_addr.s6_addr[15] = 1; @@ -408,10 +419,11 @@ internal_current6(isc_interfaceiter_t *iter) snprintf(iter->current.name, sizeof(iter->current.name), "TCP/IPv6 Loopback Interface"); for (i = 0; i < 16; i++) { - if (i != 15) + if (i != 15) { iter->current.address.type.in6.s6_addr[i] = 0; - else + } else { iter->current.address.type.in6.s6_addr[i] = 1; + } iter->current.netmask.type.in6.s6_addr[i] = 0xff; } iter->current.address.family = AF_INET6; @@ -430,8 +442,9 @@ internal_current6(isc_interfaceiter_t *iter) static isc_result_t internal_next(isc_interfaceiter_t *iter) { - if (iter->numIF >= iter->v4IF) + if (iter->numIF >= iter->v4IF) { return (ISC_R_NOMORE); + } /* * The first one needs to be set up to point to the last @@ -440,12 +453,14 @@ internal_next(isc_interfaceiter_t *iter) * the list in reverse order */ - if (iter->numIF == 0) + if (iter->numIF == 0) { iter->pos4 = (INTERFACE_INFO *)(iter->buf4 + (iter->v4IF)); + } iter->pos4--; - if (&(iter->pos4) < &(iter->buf4)) + if (&(iter->pos4) < &(iter->buf4)) { return (ISC_R_NOMORE); + } memset(&(iter->IFData), 0, sizeof(INTERFACE_INFO)); memmove(&(iter->IFData), iter->pos4, sizeof(INTERFACE_INFO)); @@ -457,10 +472,12 @@ internal_next(isc_interfaceiter_t *iter) static isc_result_t internal_next6(isc_interfaceiter_t *iter) { - if (iter->pos6 == 0U && iter->v6loop) + if (iter->pos6 == 0U && iter->v6loop) { return (ISC_R_NOMORE); - if (iter->pos6 != 0U) + } + if (iter->pos6 != 0U) { iter->pos6--; + } return (ISC_R_SUCCESS); } @@ -498,17 +515,21 @@ isc_interfaceiter_next(isc_interfaceiter_t *iter) result = internal_next(iter); if (result == ISC_R_NOMORE) { result = internal_next6(iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } result = internal_current6(iter); - if (result == ISC_R_IGNORE) + if (result == ISC_R_IGNORE) { continue; + } break; - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { break; + } result = internal_current(iter); - if (result != ISC_R_IGNORE) + if (result != ISC_R_IGNORE) { break; + } } iter->result = result; return (result); @@ -523,10 +544,12 @@ isc_interfaceiter_destroy(isc_interfaceiter_t **iterp) *iterp = NULL; REQUIRE(VALID_IFITER(iter)); - if (iter->buf4 != NULL) + if (iter->buf4 != NULL) { isc_mem_put(iter->mctx, iter->buf4, iter->buf4size); - if (iter->buf6 != NULL) + } + if (iter->buf6 != NULL) { isc_mem_put(iter->mctx, iter->buf6, iter->buf6size); + } iter->magic = 0; isc_mem_put(iter->mctx, iter, sizeof(*iter)); diff --git a/lib/isc/win32/libgen.h b/lib/isc/win32/libgen.h index d3f0da1d1a..b3b3e3d588 100644 --- a/lib/isc/win32/libgen.h +++ b/lib/isc/win32/libgen.h @@ -17,4 +17,4 @@ basename(const char *); char * dirname(const char *); -#endif +#endif /* ifndef LIBGEN_H */ diff --git a/lib/isc/win32/net.c b/lib/isc/win32/net.c index 5c00170730..8e500f1806 100644 --- a/lib/isc/win32/net.c +++ b/lib/isc/win32/net.c @@ -116,7 +116,7 @@ try_ipv6only(void) SOCKET s; int on; char strbuf[ISC_STRERRORSIZE]; -#endif +#endif /* ifdef IPV6_V6ONLY */ isc_result_t result; result = isc_net_probeipv6(); @@ -128,7 +128,7 @@ try_ipv6only(void) #ifndef IPV6_V6ONLY ipv6only_result = ISC_R_NOTFOUND; return; -#else +#else /* ifndef IPV6_V6ONLY */ /* check for TCP sockets */ s = socket(PF_INET6, SOCK_STREAM, 0); if (s == INVALID_SOCKET) { @@ -213,9 +213,9 @@ try_ipv6pktinfo(void) #ifdef IPV6_RECVPKTINFO optname = IPV6_RECVPKTINFO; -#else +#else /* ifdef IPV6_RECVPKTINFO */ optname = IPV6_PKTINFO; -#endif +#endif /* ifdef IPV6_RECVPKTINFO */ on = 1; if (setsockopt(s, IPPROTO_IPV6, optname, (const char *)&on, sizeof(on)) < 0) { @@ -275,32 +275,36 @@ void isc_net_disableipv4(void) { initialize(); - if (ipv4_result == ISC_R_SUCCESS) + if (ipv4_result == ISC_R_SUCCESS) { ipv4_result = ISC_R_DISABLED; + } } void isc_net_disableipv6(void) { initialize(); - if (ipv6_result == ISC_R_SUCCESS) + if (ipv6_result == ISC_R_SUCCESS) { ipv6_result = ISC_R_DISABLED; + } } void isc_net_enableipv4(void) { initialize(); - if (ipv4_result == ISC_R_DISABLED) + if (ipv4_result == ISC_R_DISABLED) { ipv4_result = ISC_R_SUCCESS; + } } void isc_net_enableipv6(void) { initialize(); - if (ipv6_result == ISC_R_DISABLED) + if (ipv6_result == ISC_R_DISABLED) { ipv6_result = ISC_R_SUCCESS; + } } unsigned int diff --git a/lib/isc/win32/netdb.h b/lib/isc/win32/netdb.h index 6d8e7ca767..28dea01210 100644 --- a/lib/isc/win32/netdb.h +++ b/lib/isc/win32/netdb.h @@ -21,16 +21,17 @@ #if _MSC_VER < 1600 struct addrinfo { - int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ - int ai_family; /* PF_xxx */ - int ai_socktype; /* SOCK_xxx */ - int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and IPv6 */ + int ai_flags; /* AI_PASSIVE, AI_CANONNAME */ + int ai_family; /* PF_xxx */ + int ai_socktype; /* SOCK_xxx */ + int ai_protocol; /* 0 or IPPROTO_xxx for IPv4 and + * IPv6 */ size_t ai_addrlen; /* Length of ai_addr */ char * ai_canonname; /* Canonical name for hostname */ struct sockaddr *ai_addr; /* Binary address */ struct addrinfo *ai_next; /* Next structure in linked list */ }; -#endif +#endif /* if _MSC_VER < 1600 */ /* * Undefine all \#defines we are interested in as may or may not have diff --git a/lib/isc/win32/ntgroups.c b/lib/isc/win32/ntgroups.c index 5adca79d28..5288668d8b 100644 --- a/lib/isc/win32/ntgroups.c +++ b/lib/isc/win32/ntgroups.c @@ -30,11 +30,11 @@ */ #define _CRT_SECURE_NO_DEPRECATE 1 -// clang-format off +/* clang-format off */ #include #include #include -// clang-format on +/* clang-format on */ #include #include @@ -136,8 +136,9 @@ isc_ntsecurity_getaccountgroups(char *username, char **GroupList, } /* Free the allocated memory. */ /* cppcheck-suppress duplicateCondition */ - if (pBuf != NULL) + if (pBuf != NULL) { NetApiBufferFree(pBuf); + } /* * Call the NetUserGetGroups function, specifying level 0. diff --git a/lib/isc/win32/ntpaths.c b/lib/isc/win32/ntpaths.c index dd3ef0e53d..3eaaf579f7 100644 --- a/lib/isc/win32/ntpaths.c +++ b/lib/isc/win32/ntpaths.c @@ -49,15 +49,17 @@ isc_ntpaths_init(void) memset(namedBase, 0, sizeof(namedBase)); if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, BIND_SUBKEY, 0, KEY_READ, &hKey) != - ERROR_SUCCESS) + ERROR_SUCCESS) { keyFound = FALSE; + } if (keyFound == TRUE) { /* Get the named directory */ if (RegQueryValueEx(hKey, "InstallDir", NULL, NULL, (LPBYTE)namedBase, - &baseLen) != ERROR_SUCCESS) + &baseLen) != ERROR_SUCCESS) { keyFound = FALSE; + } RegCloseKey(hKey); } @@ -106,8 +108,9 @@ isc_ntpaths_init(void) char * isc_ntpaths_get(int ind) { - if (!Initialized) + if (!Initialized) { isc_ntpaths_init(); + } switch (ind) { case NAMED_CONF_PATH: diff --git a/lib/isc/win32/os.c b/lib/isc/win32/os.c index 6106cf430b..97c5798c74 100644 --- a/lib/isc/win32/os.c +++ b/lib/isc/win32/os.c @@ -19,8 +19,9 @@ static SYSTEM_INFO SystemInfo; static void initialize_action(void) { - if (bInit) + if (bInit) { return; + } GetSystemInfo(&SystemInfo); bInit = TRUE; @@ -32,8 +33,9 @@ isc_os_ncpus(void) long ncpus; initialize_action(); ncpus = SystemInfo.dwNumberOfProcessors; - if (ncpus <= 0) + if (ncpus <= 0) { ncpus = 1; + } return ((unsigned int)ncpus); } diff --git a/lib/isc/win32/pk11_api.c b/lib/isc/win32/pk11_api.c index 9fca0d567e..21fa1dfc7a 100644 --- a/lib/isc/win32/pk11_api.c +++ b/lib/isc/win32/pk11_api.c @@ -45,8 +45,9 @@ getpass(const char *prompt) for (cnt = 0; cnt < sizeof(buf) - 1; cnt++) { ReadFile(h, buf + cnt, 1, &cc, NULL); - if (buf[cnt] == '\r') + if (buf[cnt] == '\r') { break; + } fputc('*', stdout); fflush(stderr); fflush(stdout); @@ -69,14 +70,17 @@ pkcs_C_Initialize(CK_VOID_PTR pReserved) CK_C_Initialize sym; const char * lib_name = pk11_get_lib_name(); - if (hPK11 != NULL) + if (hPK11 != NULL) { return (CKR_LIBRARY_ALREADY_INITIALIZED); + } - if (lib_name == NULL) + if (lib_name == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); + } /* Visual Studio convertion issue... */ - if (*lib_name == ' ') + if (*lib_name == ' ') { lib_name++; + } hPK11 = LoadLibraryA(lib_name); @@ -88,9 +92,10 @@ pkcs_C_Initialize(CK_VOID_PTR pReserved) return (CKR_LIBRARY_FAILED_TO_LOAD); } sym = (CK_C_Initialize)GetProcAddress(hPK11, "C_Initialize"); - if (sym == NULL) + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(pReserved); + } + return ((*sym)(pReserved)); } char * @@ -105,14 +110,17 @@ pkcs_C_Finalize(CK_VOID_PTR pReserved) CK_C_Finalize sym; CK_RV rv; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); + } sym = (CK_C_Finalize)GetProcAddress(hPK11, "C_Finalize"); - if (sym == NULL) + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); + } rv = (*sym)(pReserved); - if ((rv == CKR_OK) && (FreeLibrary(hPK11) == 0)) + if ((rv == CKR_OK) && (FreeLibrary(hPK11) == 0)) { return (CKR_LIBRARY_FAILED_TO_LOAD); + } hPK11 = NULL; return (rv); } @@ -123,13 +131,16 @@ pkcs_C_GetSlotList(CK_BBOOL tokenPresent, CK_SLOT_ID_PTR pSlotList, { static CK_C_GetSlotList sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GetSlotList)GetProcAddress(hPK11, "C_GetSlotList"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(tokenPresent, pSlotList, pulCount); + } + return ((*sym)(tokenPresent, pSlotList, pulCount)); } CK_RV @@ -137,14 +148,17 @@ pkcs_C_GetTokenInfo(CK_SLOT_ID slotID, CK_TOKEN_INFO_PTR pInfo) { static CK_C_GetTokenInfo sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GetTokenInfo)GetProcAddress(hPK11, "C_" "GetTokenInfo"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(slotID, pInfo); + } + return ((*sym)(slotID, pInfo)); } CK_RV @@ -153,15 +167,18 @@ pkcs_C_GetMechanismInfo(CK_SLOT_ID slotID, CK_MECHANISM_TYPE type, { static CK_C_GetMechanismInfo sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GetMechanismInfo)GetProcAddress(hPK11, "C_" "GetMechanis" "mInfo"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(slotID, type, pInfo); + } + return ((*sym)(slotID, type, pInfo)); } CK_RV @@ -173,8 +190,9 @@ pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, { static CK_C_OpenSession sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { hPK11 = LoadLibraryA(pk11_get_lib_name()); + } if (hPK11 == NULL) { const DWORD err = GetLastError(); snprintf(loaderrmsg, sizeof(loaderrmsg), @@ -182,11 +200,13 @@ pkcs_C_OpenSession(CK_SLOT_ID slotID, CK_FLAGS flags, CK_VOID_PTR pApplication, pk11_get_lib_name(), err); return (CKR_LIBRARY_FAILED_TO_LOAD); } - if (sym == NULL) + if (sym == NULL) { sym = (CK_C_OpenSession)GetProcAddress(hPK11, "C_OpenSession"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(slotID, flags, pApplication, Notify, phSession); + } + return ((*sym)(slotID, flags, pApplication, Notify, phSession)); } CK_RV @@ -194,14 +214,17 @@ pkcs_C_CloseSession(CK_SESSION_HANDLE hSession) { static CK_C_CloseSession sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_CloseSession)GetProcAddress(hPK11, "C_" "CloseSession"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession); + } + return ((*sym)(hSession)); } CK_RV @@ -210,13 +233,16 @@ pkcs_C_Login(CK_SESSION_HANDLE hSession, CK_USER_TYPE userType, { static CK_C_Login sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_Login)GetProcAddress(hPK11, "C_Login"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, userType, pPin, usPinLen); + } + return ((*sym)(hSession, userType, pPin, usPinLen)); } CK_RV @@ -224,13 +250,16 @@ pkcs_C_Logout(CK_SESSION_HANDLE hSession) { static CK_C_Logout sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_Logout)GetProcAddress(hPK11, "C_Logout"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession); + } + return ((*sym)(hSession)); } CK_RV @@ -239,14 +268,17 @@ pkcs_C_CreateObject(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, { static CK_C_CreateObject sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_CreateObject)GetProcAddress(hPK11, "C_" "CreateObject"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pTemplate, usCount, phObject); + } + return ((*sym)(hSession, pTemplate, usCount, phObject)); } CK_RV @@ -254,15 +286,18 @@ pkcs_C_DestroyObject(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject) { static CK_C_DestroyObject sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_DestroyObject)GetProcAddress(hPK11, "C_" "DestroyObjec" "t"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, hObject); + } + return ((*sym)(hSession, hObject)); } CK_RV @@ -271,15 +306,18 @@ pkcs_C_GetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, { static CK_C_GetAttributeValue sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GetAttributeValue)GetProcAddress(hPK11, "C_" "GetAttribu" "teValue"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, hObject, pTemplate, usCount); + } + return ((*sym)(hSession, hObject, pTemplate, usCount)); } CK_RV @@ -288,15 +326,18 @@ pkcs_C_SetAttributeValue(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE hObject, { static CK_C_SetAttributeValue sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_SetAttributeValue)GetProcAddress(hPK11, "C_" "SetAttribu" "teValue"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, hObject, pTemplate, usCount); + } + return ((*sym)(hSession, hObject, pTemplate, usCount)); } CK_RV @@ -305,15 +346,18 @@ pkcs_C_FindObjectsInit(CK_SESSION_HANDLE hSession, CK_ATTRIBUTE_PTR pTemplate, { static CK_C_FindObjectsInit sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_FindObjectsInit)GetProcAddress(hPK11, "C_" "FindObjectsI" "nit"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pTemplate, usCount); + } + return ((*sym)(hSession, pTemplate, usCount)); } CK_RV @@ -322,13 +366,16 @@ pkcs_C_FindObjects(CK_SESSION_HANDLE hSession, CK_OBJECT_HANDLE_PTR phObject, { static CK_C_FindObjects sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_FindObjects)GetProcAddress(hPK11, "C_FindObjects"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount); + } + return ((*sym)(hSession, phObject, usMaxObjectCount, pusObjectCount)); } CK_RV @@ -336,15 +383,18 @@ pkcs_C_FindObjectsFinal(CK_SESSION_HANDLE hSession) { static CK_C_FindObjectsFinal sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_FindObjectsFinal)GetProcAddress(hPK11, "C_" "FindObjects" "Final"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession); + } + return ((*sym)(hSession)); } CK_RV @@ -353,13 +403,16 @@ pkcs_C_EncryptInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, { static CK_C_EncryptInit sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_EncryptInit)GetProcAddress(hPK11, "C_EncryptInit"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism, hKey); + } + return ((*sym)(hSession, pMechanism, hKey)); } CK_RV @@ -369,14 +422,17 @@ pkcs_C_Encrypt(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, { static CK_C_Encrypt sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_Encrypt)GetProcAddress(hPK11, "C_Encrypt"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pData, ulDataLen, pEncryptedData, - pulEncryptedDataLen); + } + return ((*sym)(hSession, pData, ulDataLen, pEncryptedData, + pulEncryptedDataLen)); } CK_RV @@ -384,13 +440,16 @@ pkcs_C_DigestInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism) { static CK_C_DigestInit sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_DigestInit)GetProcAddress(hPK11, "C_DigestInit"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism); + } + return ((*sym)(hSession, pMechanism)); } CK_RV @@ -399,14 +458,17 @@ pkcs_C_DigestUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, { static CK_C_DigestUpdate sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_DigestUpdate)GetProcAddress(hPK11, "C_" "DigestUpdate"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pPart, ulPartLen); + } + return ((*sym)(hSession, pPart, ulPartLen)); } CK_RV @@ -415,13 +477,16 @@ pkcs_C_DigestFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pDigest, { static CK_C_DigestFinal sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_DigestFinal)GetProcAddress(hPK11, "C_DigestFinal"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pDigest, pulDigestLen); + } + return ((*sym)(hSession, pDigest, pulDigestLen)); } CK_RV @@ -430,13 +495,16 @@ pkcs_C_SignInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, { static CK_C_SignInit sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_SignInit)GetProcAddress(hPK11, "C_SignInit"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism, hKey); + } + return ((*sym)(hSession, pMechanism, hKey)); } CK_RV @@ -445,13 +513,17 @@ pkcs_C_Sign(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, { static CK_C_Sign sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_Sign)GetProcAddress(hPK11, "C_Sign"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pData, ulDataLen, pSignature, pulSignatureLen); + } + return ((*sym)(hSession, pData, ulDataLen, pSignature, + pulSignatureLen)); } CK_RV @@ -460,13 +532,16 @@ pkcs_C_SignUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, { static CK_C_SignUpdate sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_SignUpdate)GetProcAddress(hPK11, "C_SignUpdate"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pPart, ulPartLen); + } + return ((*sym)(hSession, pPart, ulPartLen)); } CK_RV @@ -475,13 +550,16 @@ pkcs_C_SignFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, { static CK_C_SignFinal sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_SignFinal)GetProcAddress(hPK11, "C_SignFinal"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pSignature, pulSignatureLen); + } + return ((*sym)(hSession, pSignature, pulSignatureLen)); } CK_RV @@ -490,13 +568,16 @@ pkcs_C_VerifyInit(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, { static CK_C_VerifyInit sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_VerifyInit)GetProcAddress(hPK11, "C_VerifyInit"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism, hKey); + } + return ((*sym)(hSession, pMechanism, hKey)); } CK_RV @@ -505,13 +586,16 @@ pkcs_C_Verify(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pData, CK_ULONG ulDataLen, { static CK_C_Verify sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_Verify)GetProcAddress(hPK11, "C_Verify"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pData, ulDataLen, pSignature, ulSignatureLen); + } + return ((*sym)(hSession, pData, ulDataLen, pSignature, ulSignatureLen)); } CK_RV @@ -520,14 +604,17 @@ pkcs_C_VerifyUpdate(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pPart, { static CK_C_VerifyUpdate sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_VerifyUpdate)GetProcAddress(hPK11, "C_" "VerifyUpdate"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pPart, ulPartLen); + } + return ((*sym)(hSession, pPart, ulPartLen)); } CK_RV @@ -536,13 +623,16 @@ pkcs_C_VerifyFinal(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSignature, { static CK_C_VerifyFinal sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_VerifyFinal)GetProcAddress(hPK11, "C_VerifyFinal"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pSignature, ulSignatureLen); + } + return ((*sym)(hSession, pSignature, ulSignatureLen)); } CK_RV @@ -552,13 +642,16 @@ pkcs_C_GenerateKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, { static CK_C_GenerateKey sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GenerateKey)GetProcAddress(hPK11, "C_GenerateKey"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism, pTemplate, ulCount, phKey); + } + return ((*sym)(hSession, pMechanism, pTemplate, ulCount, phKey)); } CK_RV @@ -572,17 +665,20 @@ pkcs_C_GenerateKeyPair(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, { static CK_C_GenerateKeyPair sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GenerateKeyPair)GetProcAddress(hPK11, "C_" "GenerateKeyP" "air"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism, pPublicKeyTemplate, - usPublicKeyAttributeCount, pPrivateKeyTemplate, - usPrivateKeyAttributeCount, phPrivateKey, phPublicKey); + } + return ((*sym)(hSession, pMechanism, pPublicKeyTemplate, + usPublicKeyAttributeCount, pPrivateKeyTemplate, + usPrivateKeyAttributeCount, phPrivateKey, phPublicKey)); } CK_RV @@ -592,14 +688,17 @@ pkcs_C_DeriveKey(CK_SESSION_HANDLE hSession, CK_MECHANISM_PTR pMechanism, { static CK_C_DeriveKey sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_DeriveKey)GetProcAddress(hPK11, "C_DeriveKey"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pMechanism, hBaseKey, pTemplate, - ulAttributeCount, phKey); + } + return ((*sym)(hSession, pMechanism, hBaseKey, pTemplate, + ulAttributeCount, phKey)); } CK_RV @@ -608,13 +707,16 @@ pkcs_C_SeedRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR pSeed, { static CK_C_SeedRandom sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_SeedRandom)GetProcAddress(hPK11, "C_SeedRandom"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, pSeed, ulSeedLen); + } + return ((*sym)(hSession, pSeed, ulSeedLen)); } CK_RV @@ -623,13 +725,16 @@ pkcs_C_GenerateRandom(CK_SESSION_HANDLE hSession, CK_BYTE_PTR RandomData, { static CK_C_GenerateRandom sym = NULL; - if (hPK11 == NULL) + if (hPK11 == NULL) { return (CKR_LIBRARY_FAILED_TO_LOAD); - if (sym == NULL) + } + if (sym == NULL) { sym = (CK_C_GenerateRandom)GetProcAddress(hPK11, "C_" "GenerateRando" "m"); - if (sym == NULL) + } + if (sym == NULL) { return (CKR_SYMBOL_RESOLUTION_FAILED); - return (*sym)(hSession, RandomData, ulRandomLen); + } + return ((*sym)(hSession, RandomData, ulRandomLen)); } diff --git a/lib/isc/win32/resource.c b/lib/isc/win32/resource.c index 6c09821839..4232efe93d 100644 --- a/lib/isc/win32/resource.c +++ b/lib/isc/win32/resource.c @@ -30,27 +30,31 @@ isc_resource_setlimit(isc_resource_t resource, isc_resourcevalue_t value) isc_resourcevalue_t rlim_value; int wresult; - if (resource != isc_resource_openfiles) + if (resource != isc_resource_openfiles) { return (ISC_R_NOTIMPLEMENTED); + } - if (value == ISC_RESOURCE_UNLIMITED) + if (value == ISC_RESOURCE_UNLIMITED) { rlim_value = WIN32_MAX_OPEN_FILES; - else + } else { rlim_value = min(value, WIN32_MAX_OPEN_FILES); + } wresult = _setmaxstdio((int)rlim_value); - if (wresult > 0) + if (wresult > 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t isc_resource_getlimit(isc_resource_t resource, isc_resourcevalue_t *value) { - if (resource != isc_resource_openfiles) + if (resource != isc_resource_openfiles) { return (ISC_R_NOTIMPLEMENTED); + } *value = WIN32_MAX_OPEN_FILES; return (ISC_R_SUCCESS); diff --git a/lib/isc/win32/socket.c b/lib/isc/win32/socket.c index 2817ead3a2..7c30060dc6 100644 --- a/lib/isc/win32/socket.c +++ b/lib/isc/win32/socket.c @@ -30,7 +30,7 @@ #ifndef _WINSOCKAPI_ #define _WINSOCKAPI_ /* Prevent inclusion of winsock.h in windows.h */ -#endif +#endif /* ifndef _WINSOCKAPI_ */ #include #include @@ -105,11 +105,11 @@ LPFN_GETACCEPTEXSOCKADDRS ISCGetAcceptExSockaddrs; */ #ifdef ISC_SOCKET_CONSISTENCY_CHECKS #define CONSISTENT(sock) consistent(sock) -#else +#else /* ifdef ISC_SOCKET_CONSISTENCY_CHECKS */ #define CONSISTENT(sock) \ do { \ } while (0) -#endif +#endif /* ifdef ISC_SOCKET_CONSISTENCY_CHECKS */ static void consistent(isc_socket_t *sock); @@ -122,7 +122,7 @@ consistent(isc_socket_t *sock); */ #ifndef SIO_UDP_CONNRESET #define SIO_UDP_CONNRESET _WSAIOW(IOC_VENDOR, 12) -#endif +#endif /* ifndef SIO_UDP_CONNRESET */ /* * Define what the possible "soft" errors can be. These are non-fatal returns @@ -192,7 +192,7 @@ enum { SOCK_INITIALIZED, /* Socket Initialized */ */ #ifndef USE_CMSG #define USE_CMSG 1 -#endif +#endif /* ifndef USE_CMSG */ /* * We really don't want to try and use these control messages. Win32 @@ -251,12 +251,15 @@ struct isc_socket { * calls. It also allows us to read-ahead in some cases. */ struct { - SOCKADDR_STORAGE from_addr; // UDP send/recv address - int from_addr_len; // length of the address - char * base; // the base of the buffer - char *consume_position; // where to start copying data from next - unsigned int len; // the actual size of this buffer - unsigned int remaining; // the number of bytes remaining + SOCKADDR_STORAGE from_addr; /* UDP send/recv address */ + int from_addr_len; /* length of the address */ + char * base; /* the base of the buffer */ + char * consume_position; /* where to start + * copying data from + * next */ + unsigned int len; /* the actual size of this buffer */ + unsigned int remaining; /* the number of bytes + * remaining */ } recvbuf; ISC_LIST(isc_socketevent_t) send_list; @@ -267,16 +270,22 @@ struct isc_socket { isc_sockaddr_t address; /* remote address */ unsigned int listener : 1, /* listener socket */ - connected : 1, pending_connect : 1, /* connect pending */ + connected : 1, pending_connect : 1, /* connect + * pending */ bound : 1, /* bound to local addr */ - dupped : 1; /* created by isc_socket_dup() */ - unsigned int pending_iocp; /* Should equal the counters below. Debug. */ - unsigned int pending_recv; /* Number of outstanding recv() calls. */ - unsigned int pending_send; /* Number of outstanding send() calls. */ - unsigned int pending_accept; /* Number of outstanding accept() calls. */ - unsigned int state; /* Socket state. Debugging and consistency checking. - */ - int state_lineno; /* line which last touched state */ + dupped : 1; /* created by isc_socket_dup() */ + unsigned int pending_iocp; /* Should equal the counters below. + * Debug. */ + unsigned int pending_recv; /* Number of outstanding recv() calls. + * */ + unsigned int pending_send; /* Number of outstanding send() calls. + * */ + unsigned int pending_accept; /* Number of outstanding accept() + * calls. */ + unsigned int state; /* Socket state. Debugging and consistency + * checking. + */ + int state_lineno; /* line which last touched state */ }; #define _set_state(sock, _state) \ @@ -397,17 +406,17 @@ sock_dump(isc_socket_t *sock) char socktext[ISC_SOCKADDR_FORMATSIZE]; isc_result_t result; - result = isc_socket_getpeername(sock, &addr); + result = isc_socket_getpeername(sock,&addr); if (result == ISC_R_SUCCESS) { - isc_sockaddr_format(&addr, socktext, sizeof(socktext)); - printf("Remote Socket: %s\n", socktext); + isc_sockaddr_format(&addr,socktext,sizeof(socktext)); + printf("Remote Socket: %s\n",socktext); } - result = isc_socket_getsockname(sock, &addr); + result = isc_socket_getsockname(sock,&addr); if (result == ISC_R_SUCCESS) { - isc_sockaddr_format(&addr, socktext, sizeof(socktext)); - printf("This Socket: %s\n", socktext); + isc_sockaddr_format(&addr,socktext,sizeof(socktext)); + printf("This Socket: %s\n",socktext); } -#endif +#endif /* if 0 */ printf("\n\t\tSock Dump\n"); printf("\t\tfd: %Iu\n", sock->fd); @@ -668,8 +677,9 @@ InitSockets(void) { RUNTIME_CHECK(isc_once_do(&initialise_once, initialise) == ISC_R_SUCCESS); - if (!initialised) + if (!initialised) { exit(1); + } } int @@ -711,10 +721,11 @@ internal_sendmsg(isc_socket_t *sock, IoCompletionInfo *lpo, sock->pending_send++; } - if (lpo != NULL) + if (lpo != NULL) { return (0); - else + } else { return (total_sent); + } } static void @@ -736,8 +747,9 @@ retry: * If we already have a receive pending, do nothing. */ if (sock->pending_recv > 0) { - if (lpo != NULL) + if (lpo != NULL) { HeapFree(hHeapHandle, 0, lpo); + } return; } @@ -745,8 +757,9 @@ retry: * If no one is waiting, do nothing. */ if (ISC_LIST_EMPTY(sock->recv_list)) { - if (lpo != NULL) + if (lpo != NULL) { HeapFree(hHeapHandle, 0, lpo); + } return; } @@ -761,8 +774,9 @@ retry: HEAP_ZERO_MEMORY, sizeof(IoCompletionInfo)); RUNTIME_CHECK(lpo != NULL); - } else + } else { ZeroMemory(lpo, sizeof(IoCompletionInfo)); + } lpo->request_type = SOCKET_RECV; sock->recvbuf.from_addr_len = sizeof(sock->recvbuf.from_addr); @@ -796,11 +810,12 @@ retry: default: isc_result = isc__errno2result(Error); - if (isc_result == ISC_R_UNEXPECTED) + if (isc_result == ISC_R_UNEXPECTED) { UNEXPECTED_ERROR(__FILE__, __LINE__, "WSARecvFrom: Windows error " "code: %d, isc result %d", Error, isc_result); + } send_recvdone_abort(sock, isc_result); HeapFree(hHeapHandle, 0, lpo); lpo = NULL; @@ -822,8 +837,9 @@ retry: CONSISTENT(sock); - if (need_retry) + if (need_retry) { goto retry; + } } static void @@ -833,8 +849,9 @@ manager_log(isc_socketmgr_t *sockmgr, isc_logcategory_t *category, char msgbuf[2048]; va_list ap; - if (!isc_log_wouldlog(isc_lctx, level)) + if (!isc_log_wouldlog(isc_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -853,8 +870,9 @@ socket_log(int lineno, isc_socket_t *sock, const isc_sockaddr_t *address, char peerbuf[256]; va_list ap; - if (!isc_log_wouldlog(isc_lctx, level)) + if (!isc_log_wouldlog(isc_lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -913,16 +931,16 @@ connection_reset_fix(SOCKET fd) BOOL bNewBehavior = FALSE; DWORD status; - if (isc_win32os_versioncheck(5, 0, 0, 0) < 0) + if (isc_win32os_versioncheck(5, 0, 0, 0) < 0) { return (ISC_R_SUCCESS); /* NT 4.0 has no problem */ - + } /* disable bad behavior using IOCTL: SIO_UDP_CONNRESET */ status = WSAIoctl(fd, SIO_UDP_CONNRESET, &bNewBehavior, sizeof(bNewBehavior), NULL, 0, &dwBytesReturned, NULL, NULL); - if (status != SOCKET_ERROR) + if (status != SOCKET_ERROR) { return (ISC_R_SUCCESS); - else { + } else { UNEXPECTED_ERROR(__FILE__, __LINE__, "WSAIoctl(SIO_UDP_CONNRESET, oldBehaviour) " "failed"); @@ -981,10 +999,11 @@ set_dev_address(const isc_sockaddr_t *address, isc_socket_t *sock, isc_socketevent_t *dev) { if (sock->type == isc_sockettype_udp) { - if (address != NULL) + if (address != NULL) { dev->address = *address; - else + } else { dev->address = sock->address; + } } else if (sock->type == isc_sockettype_tcp) { INSIST(address == NULL); dev->address = sock->address; @@ -1009,8 +1028,9 @@ allocate_socketevent(isc_mem_t *mctx, isc_socket_t *sock, ev = (isc_socketevent_t *)isc_event_allocate(mctx, sock, eventtype, action, arg, sizeof(*ev)); - ev->result = ISC_R_IOERROR; // XXXMLG temporary change to detect failure - // to set + ev->result = ISC_R_IOERROR; /* XXXMLG temporary change to detect failure + */ + /* to set */ ISC_LINK_INIT(ev, ev_link); ev->region.base = NULL; ev->n = 0; @@ -1036,7 +1056,7 @@ dump_msg(struct msghdr *msg, isc_socket_t *sock) printf("\t\t%u\tbase %p, len %u\n", i, msg->msg_iov[i].buf, msg->msg_iov[i].len); } -#endif +#endif /* if defined(ISC_SOCKET_DEBUG) */ /* * map the error code @@ -1049,65 +1069,73 @@ map_socket_error(isc_socket_t *sock, int windows_errno, int *isc_errno, switch (windows_errno) { case WSAECONNREFUSED: *isc_errno = ISC_R_CONNREFUSED; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case WSAENETUNREACH: case ERROR_NETWORK_UNREACHABLE: *isc_errno = ISC_R_NETUNREACH; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case ERROR_PORT_UNREACHABLE: case ERROR_HOST_UNREACHABLE: case WSAEHOSTUNREACH: *isc_errno = ISC_R_HOSTUNREACH; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case WSAENETDOWN: *isc_errno = ISC_R_NETDOWN; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case WSAEHOSTDOWN: *isc_errno = ISC_R_HOSTDOWN; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case WSAEACCES: *isc_errno = ISC_R_NOPERM; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case WSAECONNRESET: case WSAENETRESET: case WSAECONNABORTED: case WSAEDISCON: *isc_errno = ISC_R_CONNECTIONRESET; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case WSAENOTCONN: *isc_errno = ISC_R_NOTCONNECTED; - if (sock->connected) + if (sock->connected) { doreturn = DOIO_HARD; - else + } else { doreturn = DOIO_SOFT; + } break; case ERROR_OPERATION_ABORTED: case ERROR_CONNECTION_ABORTED: @@ -1194,8 +1222,9 @@ fill_recv(isc_socket_t *sock, isc_socketevent_t *dev) * 1k of space, we will toss the remaining 3k of data. TCP * will keep the extra data around and use it for later requests. */ - if (sock->type == isc_sockettype_udp) + if (sock->type == isc_sockettype_udp) { sock->recvbuf.remaining = 0; + } } /* @@ -1211,8 +1240,9 @@ completeio_recv(isc_socket_t *sock) * If we are in the process of filling our buffer, we cannot * touch it yet, so don't. */ - if (sock->pending_recv > 0) + if (sock->pending_recv > 0) { return; + } while (sock->recvbuf.remaining > 0 && !ISC_LIST_EMPTY(sock->recv_list)) { @@ -1254,8 +1284,9 @@ completeio_send(isc_socket_t *sock, isc_socketevent_t *dev, char strbuf[ISC_STRERRORSIZE]; if (send_errno != 0) { - if (SOFT_ERROR(send_errno)) + if (SOFT_ERROR(send_errno)) { return (DOIO_SOFT); + } return (map_socket_error(sock, send_errno, &dev->result, strbuf, sizeof(strbuf))); @@ -1265,8 +1296,9 @@ completeio_send(isc_socket_t *sock, isc_socketevent_t *dev, * If we write less than we expected, update counters, poke. */ dev->n += cc; - if (cc != messagehdr->msg_totallen) + if (cc != messagehdr->msg_totallen) { return (DOIO_SOFT); + } /* * Exactly what we wanted to write. We're done with this @@ -1353,9 +1385,9 @@ use_min_mtu(isc_socket_t *sock) (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_USE_MIN_MTU, (void *)&on, sizeof(on)); } -#else +#else /* ifdef IPV6_USE_MIN_MTU */ UNUSED(sock); -#endif +#endif /* ifdef IPV6_USE_MIN_MTU */ } static isc_result_t @@ -1391,15 +1423,15 @@ allocate_socket(isc_socketmgr_t *manager, isc_sockettype_t type, sock->pending_connect = 0; sock->bound = 0; sock->dupped = 0; - memset(sock->name, 0, sizeof(sock->name)); // zero the name field + memset(sock->name, 0, sizeof(sock->name)); /* zero the name field */ _set_state(sock, SOCK_INITIALIZED); sock->recvbuf.len = 65536; sock->recvbuf.consume_position = sock->recvbuf.base; sock->recvbuf.remaining = 0; sock->recvbuf.base = - isc_mem_get(manager->mctx, sock->recvbuf.len); // max buffer - // size + isc_mem_get(manager->mctx, sock->recvbuf.len); /* max buffer */ + /* size */ /* * Initialize the lock. @@ -1517,17 +1549,20 @@ free_socket(isc_socket_t **sockp, int lineno) sock->magic = 0; isc_mutex_destroy(&sock->lock); - if (sock->recvbuf.base != NULL) + if (sock->recvbuf.base != NULL) { isc_mem_put(manager->mctx, sock->recvbuf.base, sock->recvbuf.len); + } LOCK(&manager->lock); - if (ISC_LINK_LINKED(sock, link)) + if (ISC_LINK_LINKED(sock, link)) { ISC_LIST_UNLINK(manager->socklist, sock, link); + } isc_mem_put(manager->mctx, sock, sizeof(*sock)); - if (ISC_LIST_EMPTY(manager->socklist)) + if (ISC_LIST_EMPTY(manager->socklist)) { SIGNAL(&manager->shutdown_ok); + } UNLOCK(&manager->lock); } @@ -1545,11 +1580,11 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, isc_result_t result; #if defined(USE_CMSG) int on = 1; -#endif +#endif /* if defined(USE_CMSG) */ #if defined(SO_RCVBUF) socklen_t optlen; int size; -#endif +#endif /* if defined(SO_RCVBUF) */ int socket_errno; char strbuf[ISC_STRERRORSIZE]; @@ -1557,13 +1592,15 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, REQUIRE(socketp != NULL && *socketp == NULL); #ifndef SOCK_RAW - if (type == isc_sockettype_raw) + if (type == isc_sockettype_raw) { return (ISC_R_NOTIMPLEMENTED); -#endif + } +#endif /* ifndef SOCK_RAW */ result = allocate_socket(manager, type, &sock); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } sock->pf = pf; switch (type) { @@ -1594,11 +1631,12 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, case isc_sockettype_raw: sock->fd = socket(pf, SOCK_RAW, 0); #ifdef PF_ROUTE - if (pf == PF_ROUTE) + if (pf == PF_ROUTE) { sock->bound = 1; -#endif + } +#endif /* ifdef PF_ROUTE */ break; -#endif +#endif /* ifdef SOCK_RAW */ } if (sock->fd == INVALID_SOCKET) { @@ -1654,7 +1692,7 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, "failed: %s", sock->fd, strbuf); } -#else +#else /* ifdef IPV6_RECVPKTINFO */ /* 2292 */ if ((pf == AF_INET6) && (setsockopt(sock->fd, IPPROTO_IPV6, IPV6_PKTINFO, @@ -1676,7 +1714,7 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, (void)setsockopt(sock->fd, SOL_SOCKET, SO_RCVBUF, (char *)&size, sizeof(size)); } -#endif +#endif /* if defined(SO_RCVBUF) */ } #endif /* defined(USE_CMSG) || defined(SO_RCVBUF) */ @@ -1689,7 +1727,7 @@ socket_create(isc_socketmgr_t *manager, int pf, isc_sockettype_t type, if (dup_socket) { #ifndef ISC_ALLOW_MAPPED isc_socket_ipv6only(sock, true); -#endif +#endif /* ifndef ISC_ALLOW_MAPPED */ if (dup_socket->bound) { isc_sockaddr_t local; @@ -1826,8 +1864,9 @@ send_recvdone_event(isc_socket_t *sock, isc_socketevent_t **dev) task = (*dev)->ev_sender; (*dev)->ev_sender = sock; - if (ISC_LINK_LINKED(*dev, ev_link)) + if (ISC_LINK_LINKED(*dev, ev_link)) { ISC_LIST_DEQUEUE(sock->recv_list, *dev, ev_link); + } if (((*dev)->attributes & ISC_SOCKEVENTATTR_ATTACHED) != 0) { isc_task_sendanddetach(&task, (isc_event_t **)dev); @@ -1851,8 +1890,9 @@ send_senddone_event(isc_socket_t *sock, isc_socketevent_t **dev) task = (*dev)->ev_sender; (*dev)->ev_sender = sock; - if (ISC_LINK_LINKED(*dev, ev_link)) + if (ISC_LINK_LINKED(*dev, ev_link)) { ISC_LIST_DEQUEUE(sock->send_list, *dev, ev_link); + } if (((*dev)->attributes & ISC_SOCKEVENTATTR_ATTACHED) != 0) { isc_task_sendanddetach(&task, (isc_event_t **)dev); @@ -1876,8 +1916,9 @@ send_acceptdone_event(isc_socket_t *sock, isc_socket_newconnev_t **adev) task = (*adev)->ev_sender; (*adev)->ev_sender = sock; - if (ISC_LINK_LINKED(*adev, ev_link)) + if (ISC_LINK_LINKED(*adev, ev_link)) { ISC_LIST_DEQUEUE(sock->accept_list, *adev, ev_link); + } isc_task_sendanddetach(&task, (isc_event_t **)adev); @@ -1897,8 +1938,9 @@ send_connectdone_event(isc_socket_t *sock, isc_socket_connev_t **cdev) task = (*cdev)->ev_sender; (*cdev)->ev_sender = sock; - if (ISC_LINK_LINKED(*cdev, ev_link)) + if (ISC_LINK_LINKED(*cdev, ev_link)) { ISC_LIST_DEQUEUE(sock->connect_list, *cdev, ev_link); + } isc_task_sendanddetach(&task, (isc_event_t **)cdev); @@ -1942,8 +1984,9 @@ internal_accept(isc_socket_t *sock, IoCompletionInfo *lpo, int accept_errno) /* * If the event is no longer in the list we can just return. */ - if (!acceptdone_is_active(sock, adev)) + if (!acceptdone_is_active(sock, adev)) { goto done; + } nsock = adev->newsocket; @@ -2228,8 +2271,9 @@ internal_send(isc_socket_t *sock, isc_socketevent_t *dev, sock->pending_send--; /* If the event is no longer in the list we can just return */ - if (!senddone_is_active(sock, dev)) + if (!senddone_is_active(sock, dev)) { goto done; + } /* * Set the error code and send things on its way. @@ -2257,8 +2301,9 @@ senddone_is_active(isc_socket_t *sock, isc_socketevent_t *dev) isc_socketevent_t *ldev; ldev = ISC_LIST_HEAD(sock->send_list); - while (ldev != NULL && ldev != dev) + while (ldev != NULL && ldev != dev) { ldev = ISC_LIST_NEXT(ldev, ev_link); + } return (ldev == NULL ? false : true); } @@ -2269,8 +2314,9 @@ acceptdone_is_active(isc_socket_t *sock, isc_socket_newconnev_t *dev) isc_socket_newconnev_t *ldev; ldev = ISC_LIST_HEAD(sock->accept_list); - while (ldev != NULL && ldev != dev) + while (ldev != NULL && ldev != dev) { ldev = ISC_LIST_NEXT(ldev, ev_link); + } return (ldev == NULL ? false : true); } @@ -2281,32 +2327,34 @@ connectdone_is_active(isc_socket_t *sock, isc_socket_connev_t *dev) isc_socket_connev_t *cdev; cdev = ISC_LIST_HEAD(sock->connect_list); - while (cdev != NULL && cdev != dev) + while (cdev != NULL && cdev != dev) { cdev = ISC_LIST_NEXT(cdev, ev_link); + } return (cdev == NULL ? false : true); } -// -// The Windows network stack seems to have two very distinct paths depending -// on what is installed. Specifically, if something is looking at network -// connections (like an anti-virus or anti-malware application, such as -// McAfee products) Windows may return additional error conditions which -// were not previously returned. -// -// One specific one is when a TCP SYN scan is used. In this situation, -// Windows responds with the SYN-ACK, but the scanner never responds with -// the 3rd packet, the ACK. Windows consiers this a partially open connection. -// Most Unix networking stacks, and Windows without McAfee installed, will -// not return this to the caller. However, with this product installed, -// Windows returns this as a failed status on the Accept() call. Here, we -// will just re-issue the ISCAcceptEx() call as if nothing had happened. -// -// This code should only be called when the listening socket has received -// such an error. Additionally, the "parent" socket must be locked. -// Additionally, the lpo argument is re-used here, and must not be freed -// by the caller. -// +/* */ +/* The Windows network stack seems to have two very distinct paths depending */ +/* on what is installed. Specifically, if something is looking at network */ +/* connections (like an anti-virus or anti-malware application, such as */ +/* McAfee products) Windows may return additional error conditions which */ +/* were not previously returned. */ +/* */ +/* One specific one is when a TCP SYN scan is used. In this situation, */ +/* Windows responds with the SYN-ACK, but the scanner never responds with */ +/* the 3rd packet, the ACK. Windows consiers this a partially open connection. + */ +/* Most Unix networking stacks, and Windows without McAfee installed, will */ +/* not return this to the caller. However, with this product installed, */ +/* Windows returns this as a failed status on the Accept() call. Here, we */ +/* will just re-issue the ISCAcceptEx() call as if nothing had happened. */ +/* */ +/* This code should only be called when the listening socket has received */ +/* such an error. Additionally, the "parent" socket must be locked. */ +/* Additionally, the lpo argument is re-used here, and must not be freed */ +/* by the caller. */ +/* */ static isc_result_t restart_accept(isc_socket_t *parent, IoCompletionInfo *lpo) { @@ -2321,8 +2369,8 @@ restart_accept(isc_socket_t *parent, IoCompletionInfo *lpo) */ new_fd = socket(parent->pf, SOCK_STREAM, IPPROTO_TCP); if (nsock->fd == INVALID_SOCKET) { - return (ISC_R_FAILURE); // parent will ask windows for error - // message + return (ISC_R_FAILURE); /* parent will ask windows for error */ + /* message */ } closesocket(nsock->fd); nsock->fd = new_fd; @@ -2389,17 +2437,19 @@ SocketIoThread(LPVOID ThreadContext) bSuccess = GetQueuedCompletionStatus( manager->hIoCompletionPort, &nbytes, (PULONG_PTR)&sock, (LPWSAOVERLAPPED *)&lpo, INFINITE); - if (lpo == NULL) /* Received request to exit */ + if (lpo == NULL) { /* Received request to exit */ break; + } REQUIRE(VALID_SOCKET(sock)); request = lpo->request_type; - if (!bSuccess) + if (!bSuccess) { errstatus = GetLastError(); - else + } else { errstatus = 0; + } if (!bSuccess && errstatus != ERROR_MORE_DATA) { isc_result_t isc_result; @@ -2509,8 +2559,9 @@ SocketIoThread(LPVOID ThreadContext) } maybe_free_socket(&sock, __LINE__); - if (lpo != NULL) + if (lpo != NULL) { HeapFree(hHeapHandle, 0, lpo); + } continue; } @@ -2532,8 +2583,9 @@ SocketIoThread(LPVOID ThreadContext) break; } - if (lpo != NULL) + if (lpo != NULL) { HeapFree(hHeapHandle, 0, lpo); + } } /* @@ -2560,8 +2612,9 @@ isc_socketmgr_create2(isc_mem_t *mctx, isc_socketmgr_t **managerp, REQUIRE(managerp != NULL && *managerp == NULL); - if (maxsocks != 0) + if (maxsocks != 0) { return (ISC_R_NOTIMPLEMENTED); + } manager = isc_mem_get(mctx, sizeof(*manager)); @@ -2701,8 +2754,9 @@ socket_recv(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, dev->ev_sender = task; - if (sock->fd == INVALID_SOCKET) + if (sock->fd == INVALID_SOCKET) { return (ISC_R_EOF); + } /* * Queue our event on the list of things to do. Call our function to @@ -2711,8 +2765,9 @@ socket_recv(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, * here and tell our caller that we could not satisfy it immediately. */ queue_receive_event(sock, task, dev); - if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0) + if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0) { result = ISC_R_INPROGRESS; + } completeio_recv(sock); @@ -2791,13 +2846,14 @@ isc_socket_recv2(isc_socket_t *sock, isc_region_t *region, unsigned int minimum, /* * UDP sockets are always partial read. */ - if (sock->type == isc_sockettype_udp) + if (sock->type == isc_sockettype_udp) { event->minimum = 1; - else { - if (minimum == 0) + } else { + if (minimum == 0) { event->minimum = region->length; - else + } else { event->minimum = minimum; + } } ret = socket_recv(sock, event, task, flags); @@ -2859,8 +2915,9 @@ socket_send(isc_socket_t *sock, isc_socketevent_t *dev, isc_task_t *task, "socket_send: event %p -> task %p", dev, ntask); - if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0) + if ((flags & ISC_SOCKFLAG_IMMEDIATE) != 0) { result = ISC_R_INPROGRESS; + } break; } @@ -2937,8 +2994,9 @@ isc_socket_sendto2(isc_socket_t *sock, isc_region_t *region, isc_task_t *task, REQUIRE((flags & ~(ISC_SOCKFLAG_IMMEDIATE | ISC_SOCKFLAG_NORETRY)) == 0); - if ((flags & ISC_SOCKFLAG_NORETRY) != 0) + if ((flags & ISC_SOCKFLAG_NORETRY) != 0) { REQUIRE(sock->type == isc_sockettype_udp); + } event->ev_sender = sock; event->result = ISC_R_UNEXPECTED; /* @@ -3049,7 +3107,7 @@ isc_socket_listen(isc_socket_t *sock, unsigned int backlog) char strbuf[ISC_STRERRORSIZE]; #if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN) char on = 1; -#endif +#endif /* if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN) */ REQUIRE(VALID_SOCKET(sock)); @@ -3068,8 +3126,9 @@ isc_socket_listen(isc_socket_t *sock, unsigned int backlog) REQUIRE(sock->bound); REQUIRE(sock->type == isc_sockettype_tcp); - if (backlog == 0) + if (backlog == 0) { backlog = SOMAXCONN; + } if (listen(sock->fd, (int)backlog) < 0) { UNLOCK(&sock->lock); @@ -3089,7 +3148,7 @@ isc_socket_listen(isc_socket_t *sock, unsigned int backlog) sock->fd, strbuf); /* TCP_FASTOPEN is experimental so ignore failures */ } -#endif +#endif /* if defined(ENABLE_TCP_FASTOPEN) && defined(TCP_FASTOPEN) */ socket_log(__LINE__, sock, NULL, TRACE, "listening"); sock->listener = 1; @@ -3156,7 +3215,7 @@ isc_socket_accept(isc_socket_t *sock, isc_task_t *task, isc_taskaction_t action, free_socket(&nsock, __LINE__); isc_event_free((isc_event_t **)&adev); UNLOCK(&sock->lock); - return (ISC_R_FAILURE); // XXXMLG need real error message + return (ISC_R_FAILURE); /* XXXMLG need real error message */ } /* @@ -3236,8 +3295,9 @@ isc_socket_connect(isc_socket_t *sock, const isc_sockaddr_t *addr, REQUIRE(VALID_MANAGER(manager)); REQUIRE(addr != NULL); - if (isc_sockaddr_ismulticast(addr)) + if (isc_sockaddr_ismulticast(addr)) { return (ISC_R_MULTICAST); + } LOCK(&sock->lock); CONSISTENT(sock); @@ -3429,8 +3489,9 @@ isc_socket_cancel(isc_socket_t *sock, isc_task_t *task, unsigned int how) * Quick exit if there is nothing to do. Don't even bother locking * in this case. */ - if (how == 0) + if (how == 0) { return; + } LOCK(&sock->lock); CONSISTENT(sock); @@ -3574,9 +3635,9 @@ isc_socket_ipv6only(isc_socket_t *sock, bool yes) { #if defined(IPV6_V6ONLY) int onoff = yes ? 1 : 0; -#else +#else /* if defined(IPV6_V6ONLY) */ UNUSED(yes); -#endif +#endif /* if defined(IPV6_V6ONLY) */ REQUIRE(VALID_SOCKET(sock)); @@ -3585,7 +3646,7 @@ isc_socket_ipv6only(isc_socket_t *sock, bool yes) (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&onoff, sizeof(onoff)); } -#endif +#endif /* ifdef IPV6_V6ONLY */ } void @@ -3593,13 +3654,14 @@ isc_socket_dscp(isc_socket_t *sock, isc_dscp_t dscp) { #if !defined(IP_TOS) && !defined(IPV6_TCLASS) UNUSED(dscp); -#else - if (dscp < 0) +#else /* if !defined(IP_TOS) && !defined(IPV6_TCLASS) */ + if (dscp < 0) { return; + } dscp <<= 2; dscp &= 0xff; -#endif +#endif /* if !defined(IP_TOS) && !defined(IPV6_TCLASS) */ REQUIRE(VALID_SOCKET(sock)); @@ -3608,13 +3670,13 @@ isc_socket_dscp(isc_socket_t *sock, isc_dscp_t dscp) (void)setsockopt(sock->fd, IPPROTO_IP, IP_TOS, (char *)&dscp, sizeof(dscp)); } -#endif +#endif /* ifdef IP_TOS */ #ifdef IPV6_TCLASS if (sock->pf == AF_INET6) { (void)setsockopt(sock->fd, IPPROTO_IPV6, IPV6_TCLASS, (char *)&dscp, sizeof(dscp)); } -#endif +#endif /* ifdef IPV6_TCLASS */ } void @@ -3771,39 +3833,46 @@ isc_socketmgr_renderxml(isc_socketmgr_t *mgr, void *writer0) } TRY0(xmlTextWriterStartElement(writer, ISC_XMLCHAR "states")); - if (sock->pending_recv) + if (sock->pending_recv) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "pending-" "receive")); - if (sock->pending_send) + } + if (sock->pending_send) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "pending-" "send")); - if (sock->pending_accept) + } + if (sock->pending_accept) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "pending_" "accept")); - if (sock->listener) + } + if (sock->listener) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "listener")); - if (sock->connected) + } + if (sock->connected) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "connecte" "d")); - if (sock->pending_connect) + } + if (sock->pending_connect) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "connectin" "g")); - if (sock->bound) + } + if (sock->bound) { TRY0(xmlTextWriterWriteElement(writer, ISC_XMLCHAR "state", ISC_XMLCHAR "bound")); + } TRY0(xmlTextWriterEndElement(writer)); /* states */ @@ -3815,8 +3884,9 @@ isc_socketmgr_renderxml(isc_socketmgr_t *mgr, void *writer0) TRY0(xmlTextWriterEndElement(writer)); /* sockets */ error: - if (sock != NULL) + if (sock != NULL) { UNLOCK(&sock->lock); + } UNLOCK(&mgr->lock); @@ -3955,11 +4025,13 @@ isc_socketmgr_renderjson(isc_socketmgr_t *mgr, void *stats0) result = ISC_R_SUCCESS; error: - if (array != NULL) + if (array != NULL) { json_object_put(array); + } - if (sock != NULL) + if (sock != NULL) { UNLOCK(&sock->lock); + } UNLOCK(&mgr->lock); diff --git a/lib/isc/win32/stdio.c b/lib/isc/win32/stdio.c index 39ad6befd2..cf5431ad67 100644 --- a/lib/isc/win32/stdio.c +++ b/lib/isc/win32/stdio.c @@ -26,8 +26,9 @@ isc_stdio_open(const char *filename, const char *mode, FILE **fp) FILE *f; f = fopen(filename, mode); - if (f == NULL) + if (f == NULL) { return (isc__errno2result(errno)); + } *fp = f; return (ISC_R_SUCCESS); } @@ -38,10 +39,11 @@ isc_stdio_close(FILE *f) int r; r = fclose(f); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -51,13 +53,14 @@ isc_stdio_seek(FILE *f, off_t offset, int whence) #ifndef _WIN64 r = fseek(f, offset, whence); -#else +#else /* ifndef _WIN64 */ r = _fseeki64(f, offset, whence); -#endif - if (r == 0) +#endif /* ifndef _WIN64 */ + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -65,22 +68,23 @@ isc_stdio_tell(FILE *f, off_t *offsetp) { #ifndef _WIN64 long r; -#else +#else /* ifndef _WIN64 */ __int64 r; -#endif +#endif /* ifndef _WIN64 */ REQUIRE(offsetp != NULL); #ifndef _WIN64 r = ftell(f); -#else +#else /* ifndef _WIN64 */ r = _ftelli64(f); -#endif +#endif /* ifndef _WIN64 */ if (r >= 0) { *offsetp = r; return (ISC_R_SUCCESS); - } else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -92,13 +96,15 @@ isc_stdio_read(void *ptr, size_t size, size_t nmemb, FILE *f, size_t *nret) clearerr(f); r = fread(ptr, size, nmemb, f); if (r != nmemb) { - if (feof(f)) + if (feof(f)) { result = ISC_R_EOF; - else + } else { result = isc__errno2result(errno); + } } - if (nret != NULL) + if (nret != NULL) { *nret = r; + } return (result); } @@ -111,10 +117,12 @@ isc_stdio_write(const void *ptr, size_t size, size_t nmemb, FILE *f, clearerr(f); r = fwrite(ptr, size, nmemb, f); - if (r != nmemb) + if (r != nmemb) { result = isc__errno2result(errno); - if (nret != NULL) + } + if (nret != NULL) { *nret = r; + } return (result); } @@ -124,10 +132,11 @@ isc_stdio_flush(FILE *f) int r; r = fflush(f); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } isc_result_t @@ -136,18 +145,21 @@ isc_stdio_sync(FILE *f) struct _stat buf; int r; - if (_fstat(_fileno(f), &buf) != 0) + if (_fstat(_fileno(f), &buf) != 0) { return (isc__errno2result(errno)); + } /* * Only call _commit() on regular files. */ - if ((buf.st_mode & S_IFMT) != S_IFREG) + if ((buf.st_mode & S_IFMT) != S_IFREG) { return (ISC_R_SUCCESS); + } r = _commit(_fileno(f)); - if (r == 0) + if (r == 0) { return (ISC_R_SUCCESS); - else + } else { return (isc__errno2result(errno)); + } } diff --git a/lib/isc/win32/syslog.c b/lib/isc/win32/syslog.c index 1723f35993..0a1a1ecef9 100644 --- a/lib/isc/win32/syslog.c +++ b/lib/isc/win32/syslog.c @@ -36,19 +36,19 @@ static struct dsn_c_pvt_sfnt { { LOG_LPR, "lpr" }, #ifdef LOG_NEWS { LOG_NEWS, "news" }, -#endif +#endif /* ifdef LOG_NEWS */ #ifdef LOG_UUCP { LOG_UUCP, "uucp" }, -#endif +#endif /* ifdef LOG_UUCP */ #ifdef LOG_CRON { LOG_CRON, "cron" }, -#endif +#endif /* ifdef LOG_CRON */ #ifdef LOG_AUTHPRIV { LOG_AUTHPRIV, "authpriv" }, -#endif +#endif /* ifdef LOG_AUTHPRIV */ #ifdef LOG_FTP { LOG_FTP, "ftp" }, -#endif +#endif /* ifdef LOG_FTP */ { LOG_LOCAL0, "local0" }, { LOG_LOCAL1, "local1" }, { LOG_LOCAL2, "local2" }, diff --git a/lib/isc/win32/syslog.h b/lib/isc/win32/syslog.h index cdd32dfd57..00fd2bf353 100644 --- a/lib/isc/win32/syslog.h +++ b/lib/isc/win32/syslog.h @@ -65,4 +65,4 @@ NTReportError(const char *, const char *); */ #include -#endif +#endif /* ifndef _SYSLOG_H */ diff --git a/lib/isc/win32/time.c b/lib/isc/win32/time.c index 26439a61ee..deca723c71 100644 --- a/lib/isc/win32/time.c +++ b/lib/isc/win32/time.c @@ -68,8 +68,9 @@ bool isc_interval_iszero(const isc_interval_t *i) { REQUIRE(i != NULL); - if (i->interval == 0) + if (i->interval == 0) { return (true); + } return (false); } @@ -112,8 +113,9 @@ isc_time_isepoch(const isc_time_t *t) { REQUIRE(t != NULL); - if (t->absolute.dwLowDateTime == 0 && t->absolute.dwHighDateTime == 0) + if (t->absolute.dwLowDateTime == 0 && t->absolute.dwHighDateTime == 0) { return (true); + } return (false); } @@ -141,8 +143,9 @@ isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) i1.LowPart = t->absolute.dwLowDateTime; i1.HighPart = t->absolute.dwHighDateTime; - if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval) + if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval) { return (ISC_R_RANGE); + } /* cppcheck-suppress unreadVariable */ i1.QuadPart += i->interval; @@ -171,8 +174,9 @@ isc_time_add(const isc_time_t *t, const isc_interval_t *i, isc_time_t *result) i1.LowPart = t->absolute.dwLowDateTime; i1.HighPart = t->absolute.dwHighDateTime; - if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval) + if (UINT64_MAX - i1.QuadPart < (unsigned __int64)i->interval) { return (ISC_R_RANGE); + } /* cppcheck-suppress unreadVariable */ i1.QuadPart += i->interval; @@ -194,8 +198,9 @@ isc_time_subtract(const isc_time_t *t, const isc_interval_t *i, i1.LowPart = t->absolute.dwLowDateTime; i1.HighPart = t->absolute.dwHighDateTime; - if (i1.QuadPart < (unsigned __int64)i->interval) + if (i1.QuadPart < (unsigned __int64)i->interval) { return (ISC_R_RANGE); + } /* cppcheck-suppress unreadVariable */ i1.QuadPart -= i->interval; @@ -223,8 +228,9 @@ isc_time_microdiff(const isc_time_t *t1, const isc_time_t *t2) /* cppcheck-suppress unreadVariable */ i2.HighPart = t2->absolute.dwHighDateTime; - if (i1.QuadPart <= i2.QuadPart) + if (i1.QuadPart <= i2.QuadPart) { return (0); + } /* * Convert to microseconds. @@ -270,8 +276,9 @@ isc_time_secondsastimet(const isc_time_t *t, time_t *secondsp) INSIST(sizeof(unsigned int) == sizeof(uint32_t)); INSIST(sizeof(time_t) >= sizeof(uint32_t)); - if (isc_time_seconds(t) > (~0U >> 1) && seconds <= (time_t)(~0U >> 1)) + if (isc_time_seconds(t) > (~0U >> 1) && seconds <= (time_t)(~0U >> 1)) { return (ISC_R_RANGE); + } *secondsp = seconds; @@ -310,7 +317,6 @@ isc_time_formattimestamp(const isc_time_t *t, char *buf, unsigned int len) snprintf(buf, len, "%s %s.%03u", DateBuf, TimeBuf, st.wMilliseconds); - } else { strlcpy(buf, "99-Bad-9999 99:99:99.999", len); } @@ -353,11 +359,13 @@ isc_time_parsehttptimestamp(char *buf, isc_time_t *t) REQUIRE(t != NULL); p = isc_tm_strptime(buf, "%a, %d %b %Y %H:%M:%S", &t_tm); - if (p == NULL) + if (p == NULL) { return (ISC_R_UNEXPECTED); + } when = isc_tm_timegm(&t_tm); - if (when == -1) + if (when == -1) { return (ISC_R_UNEXPECTED); + } isc_time_set(t, (unsigned int)when, 0); return (ISC_R_SUCCESS); } diff --git a/lib/isc/win32/unistd.h b/lib/isc/win32/unistd.h index a2a60c5915..4332b8fea8 100644 --- a/lib/isc/win32/unistd.h +++ b/lib/isc/win32/unistd.h @@ -34,19 +34,19 @@ fcntl(int, int, ...); #include #ifndef F_OK #define F_OK 0 -#endif +#endif /* ifndef F_OK */ #ifndef X_OK #define X_OK 1 -#endif +#endif /* ifndef X_OK */ #ifndef W_OK #define W_OK 2 -#endif +#endif /* ifndef W_OK */ #ifndef R_OK #define R_OK 4 -#endif +#endif /* ifndef R_OK */ #define access _access diff --git a/lib/isc/win32/win32os.c b/lib/isc/win32/win32os.c index 95b291adeb..14a2c7224d 100644 --- a/lib/isc/win32/win32os.c +++ b/lib/isc/win32/win32os.c @@ -13,11 +13,11 @@ #ifndef TESTVERSION #include -#else +#else /* ifndef TESTVERSION */ #include #include -#endif +#endif /* ifndef TESTVERSION */ #include int @@ -50,8 +50,9 @@ isc_win32os_versioncheck(unsigned int major, unsigned int minor, typeMask |= VER_SERVICEPACKMINOR; conditionMask = VerSetConditionMask(conditionMask, VER_SERVICEPACKMINOR, VER_GREATER); - if (VerifyVersionInfo(&osVer, typeMask, conditionMask)) + if (VerifyVersionInfo(&osVer, typeMask, conditionMask)) { return (1); + } /* Failed: retry with equal */ conditionMask = 0; @@ -63,10 +64,11 @@ isc_win32os_versioncheck(unsigned int major, unsigned int minor, VER_EQUAL); conditionMask = VerSetConditionMask(conditionMask, VER_SERVICEPACKMINOR, VER_EQUAL); - if (VerifyVersionInfo(&osVer, typeMask, conditionMask)) + if (VerifyVersionInfo(&osVer, typeMask, conditionMask)) { return (0); - else + } else { return (-1); + } } #ifdef TESTVERSION @@ -108,4 +110,4 @@ main(int argc, char **argv) minor, spmajor, spminor); return (ret); } -#endif +#endif /* ifdef TESTVERSION */ diff --git a/lib/isc/xoshiro128starstar.c b/lib/isc/xoshiro128starstar.c index 939b956b07..7bf59227f0 100644 --- a/lib/isc/xoshiro128starstar.c +++ b/lib/isc/xoshiro128starstar.c @@ -39,7 +39,7 @@ ISC_THREAD_LOCAL uint32_t seed[4] = { 0 }; static inline uint32_t rotl(const uint32_t x, int k) { - return (x << k) | (x >> (32 - k)); + return ((x << k) | (x >> (32 - k))); } static inline uint32_t diff --git a/lib/isccc/alist.c b/lib/isccc/alist.c index bf9b116e53..2a38b2949c 100644 --- a/lib/isccc/alist.c +++ b/lib/isccc/alist.c @@ -52,8 +52,9 @@ isccc_alist_create(void) isccc_sexpr_t *alist, *tag; tag = isccc_sexpr_fromstring(ALIST_TAG); - if (tag == NULL) + if (tag == NULL) { return (NULL); + } alist = isccc_sexpr_cons(tag, NULL); if (alist == NULL) { isccc_sexpr_free(&tag); @@ -68,13 +69,16 @@ isccc_alist_alistp(isccc_sexpr_t *alist) { isccc_sexpr_t *car; - if (alist == NULL || alist->type != ISCCC_SEXPRTYPE_DOTTEDPAIR) + if (alist == NULL || alist->type != ISCCC_SEXPRTYPE_DOTTEDPAIR) { return (false); + } car = CAR(alist); - if (car == NULL || car->type != ISCCC_SEXPRTYPE_STRING) + if (car == NULL || car->type != ISCCC_SEXPRTYPE_STRING) { return (false); - if (strcmp(car->value.as_string, ALIST_TAG) != 0) + } + if (strcmp(car->value.as_string, ALIST_TAG) != 0) { return (false); + } return (true); } @@ -83,8 +87,9 @@ isccc_alist_emptyp(isccc_sexpr_t *alist) { REQUIRE(isccc_alist_alistp(alist)); - if (CDR(alist) == NULL) + if (CDR(alist) == NULL) { return (true); + } return (false); } @@ -114,8 +119,9 @@ isccc_alist_assq(isccc_sexpr_t *alist, const char *key) INSIST(car->type == ISCCC_SEXPRTYPE_DOTTEDPAIR); caar = CAR(car); if (caar->type == ISCCC_SEXPRTYPE_STRING && - strcmp(caar->value.as_string, key) == 0) + strcmp(caar->value.as_string, key) == 0) { return (car); + } alist = CDR(alist); } @@ -159,8 +165,9 @@ isccc_alist_define(isccc_sexpr_t *alist, const char *key, isccc_sexpr_t *value) * New association. */ k = isccc_sexpr_fromstring(key); - if (k == NULL) + if (k == NULL) { return (NULL); + } kv = isccc_sexpr_cons(k, value); if (kv == NULL) { isccc_sexpr_free(&kv); @@ -188,11 +195,13 @@ isccc_alist_definestring(isccc_sexpr_t *alist, const char *key, const char *str) isccc_sexpr_t *v, *kv; v = isccc_sexpr_fromstring(str); - if (v == NULL) + if (v == NULL) { return (NULL); + } kv = isccc_alist_define(alist, key, v); - if (kv == NULL) + if (kv == NULL) { isccc_sexpr_free(&v); + } return (kv); } @@ -204,11 +213,13 @@ isccc_alist_definebinary(isccc_sexpr_t *alist, const char *key, isccc_sexpr_t *v, *kv; v = isccc_sexpr_frombinary(r); - if (v == NULL) + if (v == NULL) { return (NULL); + } kv = isccc_alist_define(alist, key, v); - if (kv == NULL) + if (kv == NULL) { isccc_sexpr_free(&v); + } return (kv); } @@ -219,8 +230,9 @@ isccc_alist_lookup(isccc_sexpr_t *alist, const char *key) isccc_sexpr_t *kv; kv = isccc_alist_assq(alist, key); - if (kv != NULL) + if (kv != NULL) { return (CDR(kv)); + } return (NULL); } @@ -233,11 +245,13 @@ isccc_alist_lookupstring(isccc_sexpr_t *alist, const char *key, char **strp) if (kv != NULL) { v = CDR(kv); if (isccc_sexpr_stringp(v)) { - if (strp != NULL) + if (strp != NULL) { *strp = isccc_sexpr_tostring(v); + } return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_EXISTS); + } } return (ISC_R_NOTFOUND); @@ -253,11 +267,13 @@ isccc_alist_lookupbinary(isccc_sexpr_t *alist, const char *key, if (kv != NULL) { v = CDR(kv); if (isccc_sexpr_binaryp(v)) { - if (r != NULL) + if (r != NULL) { *r = isccc_sexpr_tobinary(v); + } return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_EXISTS); + } } return (ISC_R_NOTFOUND); @@ -281,8 +297,9 @@ isccc_alist_prettyprint(isccc_sexpr_t *sexpr, unsigned int indent, FILE *stream) fprintf(stream, "%.*s%s => ", (int)indent, spaces, isccc_sexpr_tostring(k)); isccc_alist_prettyprint(v, indent, stream); - if (CDR(elt) != NULL) + if (CDR(elt) != NULL) { fprintf(stream, ","); + } fprintf(stream, "\n"); } indent -= 4; @@ -293,12 +310,14 @@ isccc_alist_prettyprint(isccc_sexpr_t *sexpr, unsigned int indent, FILE *stream) for (elt = sexpr; elt != NULL; elt = CDR(elt)) { fprintf(stream, "%.*s", (int)indent, spaces); isccc_alist_prettyprint(CAR(elt), indent, stream); - if (CDR(elt) != NULL) + if (CDR(elt) != NULL) { fprintf(stream, ","); + } fprintf(stream, "\n"); } indent -= 4; fprintf(stream, "%.*s)", (int)indent, spaces); - } else + } else { isccc_sexpr_print(sexpr, stream); + } } diff --git a/lib/isccc/base64.c b/lib/isccc/base64.c index 0c02476d18..8f92a45676 100644 --- a/lib/isccc/base64.c +++ b/lib/isccc/base64.c @@ -48,8 +48,9 @@ isccc_base64_encode(isccc_region_t *source, int wordlength, (unsigned int)(target->rend - target->rstart)); result = isc_base64_totext(&sr, wordlength, wordbreak, &tb); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } source->rstart = source->rend; target->rstart = isc_buffer_used(&tb); return (ISC_R_SUCCESS); @@ -64,8 +65,9 @@ isccc_base64_decode(const char *cstr, isccc_region_t *target) isc_buffer_init(&b, target->rstart, (unsigned int)(target->rend - target->rstart)); result = isc_base64_decodestring(cstr, &b); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } target->rstart = isc_buffer_used(&b); return (ISC_R_SUCCESS); } diff --git a/lib/isccc/cc.c b/lib/isccc/cc.c index ab6e1e572c..d6c098feb3 100644 --- a/lib/isccc/cc.c +++ b/lib/isccc/cc.c @@ -111,22 +111,25 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) vr = isccc_sexpr_tobinary(elt); len = REGION_SIZE(*vr); result = isc_buffer_reserve(buffer, 1 + 4); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(*buffer, ISCCC_CCMSGTYPE_BINARYDATA); isc_buffer_putuint32(*buffer, len); result = isc_buffer_reserve(buffer, len); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putmem(*buffer, vr->rstart, len); } else if (isccc_alist_alistp(elt)) { unsigned int used; isc_buffer_t b; result = isc_buffer_reserve(buffer, 1 + 4); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(*buffer, ISCCC_CCMSGTYPE_TABLE); /* * Emit a placeholder length. @@ -138,8 +141,9 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) * Emit the table. */ result = table_towire(elt, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } len = (*buffer)->used - used; /* @@ -157,8 +161,9 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) isc_buffer_t b; result = isc_buffer_reserve(buffer, 1 + 4); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(*buffer, ISCCC_CCMSGTYPE_LIST); /* * Emit a placeholder length. @@ -170,8 +175,9 @@ value_towire(isccc_sexpr_t *elt, isc_buffer_t **buffer) * Emit the list. */ result = list_towire(elt, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } len = (*buffer)->used - used; /* @@ -209,16 +215,18 @@ table_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer) * Emit the key name. */ result = isc_buffer_reserve(buffer, 1 + len); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } isc_buffer_putuint8(*buffer, (uint8_t)len); isc_buffer_putmem(*buffer, (const unsigned char *)ks, len); /* * Emit the value. */ result = value_towire(v, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (ISC_R_SUCCESS); @@ -231,8 +239,9 @@ list_towire(isccc_sexpr_t *list, isc_buffer_t **buffer) while (list != NULL) { result = value_towire(ISCCC_SEXPR_CAR(list), buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } list = ISCCC_SEXPR_CDR(list); } @@ -286,12 +295,14 @@ sign(unsigned char *data, unsigned int length, unsigned char *hmac, target.rstart = digestb64; target.rend = digestb64 + sizeof(digestb64); result = isccc_base64_encode(&source, 64, "", &target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (algorithm == ISCCC_ALG_HMACMD5) + } + if (algorithm == ISCCC_ALG_HMACMD5) { PUT_MEM(digestb64, HMD5_LENGTH, hmac); - else + } else { PUT_MEM(digestb64, HSHA_LENGTH, hmac); + } return (ISC_R_SUCCESS); } @@ -306,8 +317,9 @@ isccc_cc_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer, uint32_t algorithm, isc_buffer_reserve(buffer, 4 + ((algorithm == ISCCC_ALG_HMACMD5) ? sizeof(auth_hmd5) : sizeof(auth_hsha))); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOSPACE); + } /* * Emit protocol version. @@ -334,8 +346,9 @@ isccc_cc_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer, uint32_t algorithm, sizeof(auth_hsha)); *hmac_alg = algorithm; } - } else + } else { hmac_base = 0; + } signed_base = (*buffer)->used; /* * Delete any existing _auth section so that we don't try @@ -346,13 +359,15 @@ isccc_cc_towire(isccc_sexpr_t *alist, isc_buffer_t **buffer, uint32_t algorithm, * Emit the message. */ result = table_towire(alist, buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); - if (secret != NULL) + } + if (secret != NULL) { return (sign((unsigned char *)(*buffer)->base + signed_base, (*buffer)->used - signed_base, (unsigned char *)(*buffer)->base + hmac_base, algorithm, secret)); + } return (ISC_R_SUCCESS); } @@ -373,14 +388,17 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length, * Extract digest. */ _auth = isccc_alist_lookup(alist, "_auth"); - if (!isccc_alist_alistp(_auth)) + if (!isccc_alist_alistp(_auth)) { return (ISC_R_FAILURE); - if (algorithm == ISCCC_ALG_HMACMD5) + } + if (algorithm == ISCCC_ALG_HMACMD5) { hmac = isccc_alist_lookup(_auth, "hmd5"); - else + } else { hmac = isccc_alist_lookup(_auth, "hsha"); - if (!isccc_sexpr_binaryp(hmac)) + } + if (!isccc_sexpr_binaryp(hmac)) { return (ISC_R_FAILURE); + } /* * Compute digest. */ @@ -420,8 +438,9 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length, target.rend = digestb64 + sizeof(digestb64); memset(digestb64, 0, sizeof(digestb64)); result = isccc_base64_encode(&source, 64, "", &target); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* * Verify. @@ -431,11 +450,13 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length, unsigned char * value; region = isccc_sexpr_tobinary(hmac); - if ((region->rend - region->rstart) != HMD5_LENGTH) + if ((region->rend - region->rstart) != HMD5_LENGTH) { return (ISCCC_R_BADAUTH); + } value = region->rstart; - if (!isc_safe_memequal(value, digestb64, HMD5_LENGTH)) + if (!isc_safe_memequal(value, digestb64, HMD5_LENGTH)) { return (ISCCC_R_BADAUTH); + } } else { isccc_region_t *region; unsigned char * value; @@ -447,13 +468,15 @@ verify(isccc_sexpr_t *alist, unsigned char *data, unsigned int length, * Note: with non-MD5 algorithms, there's an extra octet * to identify which algorithm is in use. */ - if ((region->rend - region->rstart) != HSHA_LENGTH + 1) + if ((region->rend - region->rstart) != HSHA_LENGTH + 1) { return (ISCCC_R_BADAUTH); + } value = region->rstart; GET8(valalg, value); if ((valalg != algorithm) || - !isc_safe_memequal(value, digestb64, HSHA_LENGTH)) + !isc_safe_memequal(value, digestb64, HSHA_LENGTH)) { return (ISCCC_R_BADAUTH); + } } return (ISC_R_SUCCESS); @@ -475,12 +498,14 @@ value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) isccc_region_t active; isc_result_t result; - if (REGION_SIZE(*source) < 1 + 4) + if (REGION_SIZE(*source) < 1 + 4) { return (ISC_R_UNEXPECTEDEND); + } GET8(msgtype, source->rstart); GET32(len, source->rstart); - if (REGION_SIZE(*source) < len) + if (REGION_SIZE(*source) < len) { return (ISC_R_UNEXPECTEDEND); + } active.rstart = source->rstart; active.rend = active.rstart + len; source->rstart = active.rend; @@ -489,14 +514,16 @@ value_fromwire(isccc_region_t *source, isccc_sexpr_t **valuep) if (value != NULL) { *valuep = value; result = ISC_R_SUCCESS; - } else + } else { result = ISC_R_NOMEMORY; - } else if (msgtype == ISCCC_CCMSGTYPE_TABLE) + } + } else if (msgtype == ISCCC_CCMSGTYPE_TABLE) { result = table_fromwire(&active, NULL, 0, valuep); - else if (msgtype == ISCCC_CCMSGTYPE_LIST) + } else if (msgtype == ISCCC_CCMSGTYPE_LIST) { result = list_fromwire(&active, valuep); - else + } else { result = ISCCC_R_SYNTAX; + } return (result); } @@ -517,8 +544,9 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret, checksum_rstart = NULL; first_tag = true; alist = isccc_alist_create(); - if (alist == NULL) + if (alist == NULL) { return (ISC_R_NOMEMORY); + } while (!REGION_EMPTY(*source)) { GET8(len, source->rstart); @@ -530,33 +558,38 @@ table_fromwire(isccc_region_t *source, isccc_region_t *secret, key[len] = '\0'; /* Ensure NUL termination. */ value = NULL; result = value_fromwire(source, &value); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto bad; + } if (isccc_alist_define(alist, key, value) == NULL) { result = ISC_R_NOMEMORY; goto bad; } - if (first_tag && secret != NULL && strcmp(key, "_auth") == 0) + if (first_tag && secret != NULL && strcmp(key, "_auth") == 0) { checksum_rstart = source->rstart; + } first_tag = false; } if (secret != NULL) { - if (checksum_rstart != NULL) + if (checksum_rstart != NULL) { result = verify( alist, checksum_rstart, (unsigned int)(source->rend - checksum_rstart), algorithm, secret); - else + } else { result = ISCCC_R_BADAUTH; - } else + } + } else { result = ISC_R_SUCCESS; + } bad: - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { *alistp = alist; - else + } else { isccc_sexpr_free(&alist); + } return (result); } @@ -595,11 +628,13 @@ isccc_cc_fromwire(isccc_region_t *source, isccc_sexpr_t **alistp, uint32_t version; size = REGION_SIZE(*source); - if (size < 4) + if (size < 4) { return (ISC_R_UNEXPECTEDEND); + } GET32(version, source->rstart); - if (version != 1) + if (version != 1) { return (ISCCC_R_UNKNOWNVERSION); + } return (table_fromwire(source, secret, algorithm, alistp)); } @@ -614,26 +649,30 @@ createmessage(uint32_t version, const char *from, const char *to, REQUIRE(alistp != NULL && *alistp == NULL); - if (version != 1) + if (version != 1) { return (ISCCC_R_UNKNOWNVERSION); + } alist = isccc_alist_create(); - if (alist == NULL) + if (alist == NULL) { return (ISC_R_NOMEMORY); + } result = ISC_R_NOMEMORY; _ctrl = isccc_alist_create(); - if (_ctrl == NULL) + if (_ctrl == NULL) { goto bad; + } if (isccc_alist_define(alist, "_ctrl", _ctrl) == NULL) { isccc_sexpr_free(&_ctrl); goto bad; } _data = isccc_alist_create(); - if (_data == NULL) + if (_data == NULL) { goto bad; + } if (isccc_alist_define(alist, "_data", _data) == NULL) { isccc_sexpr_free(&_data); goto bad; @@ -642,12 +681,16 @@ createmessage(uint32_t version, const char *from, const char *to, if (isccc_cc_defineuint32(_ctrl, "_ser", serial) == NULL || isccc_cc_defineuint32(_ctrl, "_tim", now) == NULL || (want_expires && - isccc_cc_defineuint32(_ctrl, "_exp", expires) == NULL)) + isccc_cc_defineuint32(_ctrl, "_exp", expires) == NULL)) { goto bad; - if (from != NULL && isccc_cc_definestring(_ctrl, "_frm", from) == NULL) + } + if (from != NULL && + isccc_cc_definestring(_ctrl, "_frm", from) == NULL) { goto bad; - if (to != NULL && isccc_cc_definestring(_ctrl, "_to", to) == NULL) + } + if (to != NULL && isccc_cc_definestring(_ctrl, "_to", to) == NULL) { goto bad; + } *alistp = alist; @@ -682,8 +725,9 @@ isccc_cc_createack(isccc_sexpr_t *message, bool ok, isccc_sexpr_t **ackp) _ctrl = isccc_alist_lookup(message, "_ctrl"); if (!isccc_alist_alistp(_ctrl) || isccc_cc_lookupuint32(_ctrl, "_ser", &serial) != ISC_R_SUCCESS || - isccc_cc_lookupuint32(_ctrl, "_tim", &t) != ISC_R_SUCCESS) + isccc_cc_lookupuint32(_ctrl, "_tim", &t) != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } /* * _frm and _to are optional. */ @@ -696,8 +740,9 @@ isccc_cc_createack(isccc_sexpr_t *message, bool ok, isccc_sexpr_t **ackp) */ ack = NULL; result = createmessage(1, _to, _frm, serial, t, 0, &ack, false); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } _ctrl = isccc_alist_lookup(ack, "_ctrl"); if (_ctrl == NULL) { @@ -725,10 +770,12 @@ isccc_cc_isack(isccc_sexpr_t *message) isccc_sexpr_t *_ctrl; _ctrl = isccc_alist_lookup(message, "_ctrl"); - if (!isccc_alist_alistp(_ctrl)) + if (!isccc_alist_alistp(_ctrl)) { return (false); - if (isccc_cc_lookupstring(_ctrl, "_ack", NULL) == ISC_R_SUCCESS) + } + if (isccc_cc_lookupstring(_ctrl, "_ack", NULL) == ISC_R_SUCCESS) { return (true); + } return (false); } @@ -738,10 +785,12 @@ isccc_cc_isreply(isccc_sexpr_t *message) isccc_sexpr_t *_ctrl; _ctrl = isccc_alist_lookup(message, "_ctrl"); - if (!isccc_alist_alistp(_ctrl)) + if (!isccc_alist_alistp(_ctrl)) { return (false); - if (isccc_cc_lookupstring(_ctrl, "_rpl", NULL) == ISC_R_SUCCESS) + } + if (isccc_cc_lookupstring(_ctrl, "_rpl", NULL) == ISC_R_SUCCESS) { return (true); + } return (false); } @@ -760,8 +809,9 @@ isccc_cc_createresponse(isccc_sexpr_t *message, isccc_time_t now, _data = isccc_alist_lookup(message, "_data"); if (!isccc_alist_alistp(_ctrl) || !isccc_alist_alistp(_data) || isccc_cc_lookupuint32(_ctrl, "_ser", &serial) != ISC_R_SUCCESS || - isccc_cc_lookupstring(_data, "type", &type) != ISC_R_SUCCESS) + isccc_cc_lookupstring(_data, "type", &type) != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } /* * _frm and _to are optional. */ @@ -775,8 +825,9 @@ isccc_cc_createresponse(isccc_sexpr_t *message, isccc_time_t now, alist = NULL; result = isccc_cc_createmessage(1, _to, _frm, serial, now, expires, &alist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } _ctrl = isccc_alist_lookup(alist, "_ctrl"); if (_ctrl == NULL) { @@ -844,11 +895,13 @@ isccc_cc_lookupstring(isccc_sexpr_t *alist, const char *key, char **strp) if (kv != NULL) { v = ISCCC_SEXPR_CDR(kv); if (isccc_sexpr_binaryp(v)) { - if (strp != NULL) + if (strp != NULL) { *strp = isccc_sexpr_tostring(v); + } return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_EXISTS); + } } return (ISC_R_NOTFOUND); @@ -863,12 +916,14 @@ isccc_cc_lookupuint32(isccc_sexpr_t *alist, const char *key, uint32_t *uintp) if (kv != NULL) { v = ISCCC_SEXPR_CDR(kv); if (isccc_sexpr_binaryp(v)) { - if (uintp != NULL) + if (uintp != NULL) { *uintp = (uint32_t)strtoul( isccc_sexpr_tostring(v), NULL, 10); + } return (ISC_R_SUCCESS); - } else + } else { return (ISC_R_EXISTS); + } } return (ISC_R_NOTFOUND); @@ -894,10 +949,12 @@ symtab_clean(char *key, unsigned int type, isccc_symvalue_t value, void *arg) now = arg; - if (*now < value.as_uinteger) + if (*now < value.as_uinteger) { return (false); - if ((*now - value.as_uinteger) < DUP_LIFETIME) + } + if ((*now - value.as_uinteger) < DUP_LIFETIME) { return (false); + } return (true); } @@ -919,11 +976,13 @@ has_whitespace(const char *str) { char c; - if (str == NULL) + if (str == NULL) { return (false); + } while ((c = *str++) != '\0') { - if (c == ' ' || c == '\t' || c == '\n') + if (c == ' ' || c == '\t' || c == '\n') { return (true); + } } return (false); } @@ -944,8 +1003,9 @@ isccc_cc_checkdup(isccc_symtab_t *symtab, isccc_sexpr_t *message, _ctrl = isccc_alist_lookup(message, "_ctrl"); if (!isccc_alist_alistp(_ctrl) || isccc_cc_lookupstring(_ctrl, "_ser", &_ser) != ISC_R_SUCCESS || - isccc_cc_lookupstring(_ctrl, "_tim", &_tim) != ISC_R_SUCCESS) + isccc_cc_lookupstring(_ctrl, "_tim", &_tim) != ISC_R_SUCCESS) { return (ISC_R_FAILURE); + } INSIST(_ser != NULL); INSIST(_tim != NULL); @@ -954,26 +1014,30 @@ isccc_cc_checkdup(isccc_symtab_t *symtab, isccc_sexpr_t *message, * _frm and _to are optional. */ tmp = NULL; - if (isccc_cc_lookupstring(_ctrl, "_frm", &tmp) != ISC_R_SUCCESS) + if (isccc_cc_lookupstring(_ctrl, "_frm", &tmp) != ISC_R_SUCCESS) { _frm = ""; - else + } else { _frm = tmp; + } tmp = NULL; - if (isccc_cc_lookupstring(_ctrl, "_to", &tmp) != ISC_R_SUCCESS) + if (isccc_cc_lookupstring(_ctrl, "_to", &tmp) != ISC_R_SUCCESS) { _to = ""; - else + } else { _to = tmp; + } /* * Ensure there is no newline in any of the strings. This is so * we can write them to a file later. */ if (has_whitespace(_frm) || has_whitespace(_to) || - has_whitespace(_ser) || has_whitespace(_tim)) + has_whitespace(_ser) || has_whitespace(_tim)) { return (ISC_R_FAILURE); + } len = strlen(_frm) + strlen(_to) + strlen(_ser) + strlen(_tim) + 4; key = malloc(len); - if (key == NULL) + if (key == NULL) { return (ISC_R_NOMEMORY); + } snprintf(key, len, "%s;%s;%s;%s", _frm, _to, _ser, _tim); value.as_uinteger = now; result = isccc_symtab_define(symtab, key, ISCCC_SYMTYPE_CCDUP, value, diff --git a/lib/isccc/ccmsg.c b/lib/isccc/ccmsg.c index d0cc1f7cea..a4c066312c 100644 --- a/lib/isccc/ccmsg.c +++ b/lib/isccc/ccmsg.c @@ -144,7 +144,8 @@ isccc_ccmsg_init(isc_mem_t *mctx, isc_socket_t *sock, isccc_ccmsg_t *ccmsg) ccmsg->task = NULL; /* None yet. */ ccmsg->result = ISC_R_UNEXPECTED; /* None yet. */ /* - * Should probably initialize the event here, but it can wait. + * Should probably initialize the + *event here, but it can wait. */ } @@ -187,8 +188,9 @@ isccc_ccmsg_readmessage(isccc_ccmsg_t *ccmsg, isc_task_t *task, result = isc_socket_recv(ccmsg->sock, ®ion, 0, ccmsg->task, recv_length, ccmsg); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { ccmsg->task = NULL; + } return (result); } @@ -203,17 +205,18 @@ isccc_ccmsg_cancelread(isccc_ccmsg_t *ccmsg) #if 0 void -isccc_ccmsg_freebuffer(isccc_ccmsg_t *ccmsg) { +isccc_ccmsg_freebuffer(isccc_ccmsg_t*ccmsg) { REQUIRE(VALID_CCMSG(ccmsg)); - if (ccmsg->buffer.base == NULL) + if (ccmsg->buffer.base == NULL) { return; + } - isc_mem_put(ccmsg->mctx, ccmsg->buffer.base, ccmsg->buffer.length); + isc_mem_put(ccmsg->mctx,ccmsg->buffer.base,ccmsg->buffer.length); ccmsg->buffer.base = NULL; ccmsg->buffer.length = 0; } -#endif +#endif /* if 0 */ void isccc_ccmsg_invalidate(isccc_ccmsg_t *ccmsg) diff --git a/lib/isccc/include/isccc/symtab.h b/lib/isccc/include/isccc/symtab.h index 672a532ab7..f3ee439d74 100644 --- a/lib/isccc/include/isccc/symtab.h +++ b/lib/isccc/include/isccc/symtab.h @@ -27,8 +27,8 @@ #define ISCCC_SYMTAB_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isccc/symtab.h * \brief diff --git a/lib/isccc/result.c b/lib/isccc/result.c index e0bed0ea8b..37a2fb1642 100644 --- a/lib/isccc/result.c +++ b/lib/isccc/result.c @@ -55,15 +55,17 @@ initialize_action(void) result = isc_result_register(ISC_RESULTCLASS_ISCCC, ISCCC_R_NRESULTS, text, ISCCC_RESULT_RESULTSET); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_result_register() failed: %u", result); + } result = isc_result_registerids(ISC_RESULTCLASS_ISCCC, ISCCC_R_NRESULTS, ids, ISCCC_RESULT_RESULTSET); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { UNEXPECTED_ERROR(__FILE__, __LINE__, "isc_result_registerids() failed: %u", result); + } } static void diff --git a/lib/isccc/sexpr.c b/lib/isccc/sexpr.c index 98b175ec41..fdaef77644 100644 --- a/lib/isccc/sexpr.c +++ b/lib/isccc/sexpr.c @@ -47,8 +47,9 @@ isccc_sexpr_cons(isccc_sexpr_t *car, isccc_sexpr_t *cdr) isccc_sexpr_t *sexpr; sexpr = malloc(sizeof(*sexpr)); - if (sexpr == NULL) + if (sexpr == NULL) { return (NULL); + } sexpr->type = ISCCC_SEXPRTYPE_DOTTEDPAIR; CAR(sexpr) = car; CDR(sexpr) = cdr; @@ -68,8 +69,9 @@ isccc_sexpr_fromstring(const char *str) isccc_sexpr_t *sexpr; sexpr = malloc(sizeof(*sexpr)); - if (sexpr == NULL) + if (sexpr == NULL) { return (NULL); + } sexpr->type = ISCCC_SEXPRTYPE_STRING; sexpr->value.as_string = strdup(str); if (sexpr->value.as_string == NULL) { @@ -87,8 +89,9 @@ isccc_sexpr_frombinary(const isccc_region_t *region) unsigned int region_size; sexpr = malloc(sizeof(*sexpr)); - if (sexpr == NULL) + if (sexpr == NULL) { return (NULL); + } sexpr->type = ISCCC_SEXPRTYPE_BINARY; region_size = REGION_SIZE(*region); /* @@ -122,19 +125,22 @@ isccc_sexpr_free(isccc_sexpr_t **sexprp) sexpr = *sexprp; *sexprp = NULL; - if (sexpr == NULL) + if (sexpr == NULL) { return; + } switch (sexpr->type) { case ISCCC_SEXPRTYPE_STRING: free(sexpr->value.as_string); break; case ISCCC_SEXPRTYPE_DOTTEDPAIR: item = CAR(sexpr); - if (item != NULL) + if (item != NULL) { isccc_sexpr_free(&item); + } item = CDR(sexpr); - if (item != NULL) + if (item != NULL) { isccc_sexpr_free(&item); + } break; case ISCCC_SEXPRTYPE_BINARY: free(sexpr->value.as_region.rstart); @@ -150,8 +156,9 @@ printable(isccc_region_t *r) curr = r->rstart; while (curr != r->rend) { - if (!isprint(*curr)) + if (!isprint(*curr)) { return (false); + } curr++; } @@ -201,8 +208,9 @@ isccc_sexpr_print(isccc_sexpr_t *sexpr, FILE *stream) fprintf(stream, "'%.*s'", (int)size, curr); } else { fprintf(stream, "0x"); - for (i = 0; i < size; i++) + for (i = 0; i < size; i++) { fprintf(stream, "%02x", *curr++); + } } break; default: @@ -253,14 +261,16 @@ isccc_sexpr_addtolist(isccc_sexpr_t **l1p, isccc_sexpr_t *l2) REQUIRE(l1 == NULL || l1->type == ISCCC_SEXPRTYPE_DOTTEDPAIR); elt = isccc_sexpr_cons(l2, NULL); - if (elt == NULL) + if (elt == NULL) { return (NULL); + } if (l1 == NULL) { *l1p = elt; return (elt); } - for (last = l1; CDR(last) != NULL; last = CDR(last)) - /* Nothing */; + for (last = l1; CDR(last) != NULL; last = CDR(last)) { + /* Nothing */ + } CDR(last) = elt; return (elt); @@ -269,32 +279,36 @@ isccc_sexpr_addtolist(isccc_sexpr_t **l1p, isccc_sexpr_t *l2) bool isccc_sexpr_listp(isccc_sexpr_t *sexpr) { - if (sexpr == NULL || sexpr->type == ISCCC_SEXPRTYPE_DOTTEDPAIR) + if (sexpr == NULL || sexpr->type == ISCCC_SEXPRTYPE_DOTTEDPAIR) { return (true); + } return (false); } bool isccc_sexpr_emptyp(isccc_sexpr_t *sexpr) { - if (sexpr == NULL) + if (sexpr == NULL) { return (true); + } return (false); } bool isccc_sexpr_stringp(isccc_sexpr_t *sexpr) { - if (sexpr != NULL && sexpr->type == ISCCC_SEXPRTYPE_STRING) + if (sexpr != NULL && sexpr->type == ISCCC_SEXPRTYPE_STRING) { return (true); + } return (false); } bool isccc_sexpr_binaryp(isccc_sexpr_t *sexpr) { - if (sexpr != NULL && sexpr->type == ISCCC_SEXPRTYPE_BINARY) + if (sexpr != NULL && sexpr->type == ISCCC_SEXPRTYPE_BINARY) { return (true); + } return (false); } @@ -304,8 +318,9 @@ isccc_sexpr_tostring(isccc_sexpr_t *sexpr) REQUIRE(sexpr != NULL && (sexpr->type == ISCCC_SEXPRTYPE_STRING || sexpr->type == ISCCC_SEXPRTYPE_BINARY)); - if (sexpr->type == ISCCC_SEXPRTYPE_BINARY) + if (sexpr->type == ISCCC_SEXPRTYPE_BINARY) { return ((char *)sexpr->value.as_region.rstart); + } return (sexpr->value.as_string); } diff --git a/lib/isccc/symtab.c b/lib/isccc/symtab.c index 665844ba0e..87829cfe42 100644 --- a/lib/isccc/symtab.c +++ b/lib/isccc/symtab.c @@ -71,15 +71,17 @@ isccc_symtab_create(unsigned int size, REQUIRE(size > 0); /* Should be prime. */ symtab = malloc(sizeof(*symtab)); - if (symtab == NULL) + if (symtab == NULL) { return (ISC_R_NOMEMORY); + } symtab->table = malloc(size * sizeof(eltlist_t)); if (symtab->table == NULL) { free(symtab); return (ISC_R_NOMEMORY); } - for (i = 0; i < size; i++) + for (i = 0; i < size; i++) { ISC_LIST_INIT(symtab->table[i]); + } symtab->size = size; symtab->undefine_action = undefine_action; symtab->undefine_arg = undefine_arg; @@ -95,9 +97,10 @@ static inline void free_elt(isccc_symtab_t *symtab, unsigned int bucket, elt_t *elt) { ISC_LIST_UNLINK(symtab->table[bucket], elt, link); - if (symtab->undefine_action != NULL) + if (symtab->undefine_action != NULL) { (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); + } free(elt); } @@ -192,11 +195,13 @@ isccc_symtab_lookup(isccc_symtab_t *symtab, const char *key, unsigned int type, FIND(symtab, key, type, bucket, elt); - if (elt == NULL) + if (elt == NULL) { return (ISC_R_NOTFOUND); + } - if (value != NULL) + if (value != NULL) { *value = elt->value; + } return (ISC_R_SUCCESS); } @@ -215,18 +220,21 @@ isccc_symtab_define(isccc_symtab_t *symtab, char *key, unsigned int type, FIND(symtab, key, type, bucket, elt); if (exists_policy != isccc_symexists_add && elt != NULL) { - if (exists_policy == isccc_symexists_reject) + if (exists_policy == isccc_symexists_reject) { return (ISC_R_EXISTS); + } INSIST(exists_policy == isccc_symexists_replace); ISC_LIST_UNLINK(symtab->table[bucket], elt, link); - if (symtab->undefine_action != NULL) + if (symtab->undefine_action != NULL) { (symtab->undefine_action)(elt->key, elt->type, elt->value, symtab->undefine_arg); + } } else { elt = malloc(sizeof(*elt)); - if (elt == NULL) + if (elt == NULL) { return (ISC_R_NOMEMORY); + } ISC_LINK_INIT(elt, link); } @@ -254,8 +262,9 @@ isccc_symtab_undefine(isccc_symtab_t *symtab, const char *key, FIND(symtab, key, type, bucket, elt); - if (elt == NULL) + if (elt == NULL) { return (ISC_R_NOTFOUND); + } free_elt(symtab, bucket, elt); @@ -276,8 +285,9 @@ isccc_symtab_foreach(isccc_symtab_t *symtab, isccc_symtabforeachaction_t action, for (elt = ISC_LIST_HEAD(symtab->table[i]); elt != NULL; elt = nelt) { nelt = ISC_LIST_NEXT(elt, link); - if ((action)(elt->key, elt->type, elt->value, arg)) + if ((action)(elt->key, elt->type, elt->value, arg)) { free_elt(symtab, i, elt); + } } } } diff --git a/lib/isccc/tests/result_test.c b/lib/isccc/tests/result_test.c index 077d554e23..1dd8d69899 100644 --- a/lib/isccc/tests/result_test.c +++ b/lib/isccc/tests/result_test.c @@ -81,4 +81,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isccfg/aclconf.c b/lib/isccfg/aclconf.c index 21d915db59..d482e4f38b 100644 --- a/lib/isccfg/aclconf.c +++ b/lib/isccfg/aclconf.c @@ -32,7 +32,7 @@ static const char *geoip_dbnames[] = { "country", "city", "asnum", "isp", "domain", NULL, }; -#endif +#endif /* if defined(HAVE_GEOIP2) */ isc_result_t cfg_aclconfctx_create(isc_mem_t *mctx, cfg_aclconfctx_t **ret) @@ -52,7 +52,7 @@ cfg_aclconfctx_create(isc_mem_t *mctx, cfg_aclconfctx_t **ret) #if defined(HAVE_GEOIP2) actx->geoip = NULL; -#endif +#endif /* if defined(HAVE_GEOIP2) */ *ret = actx; return (ISC_R_SUCCESS); @@ -100,8 +100,9 @@ get_acl_def(const cfg_obj_t *cctx, const char *name, const cfg_obj_t **ret) const cfg_listelt_t *elt; result = cfg_map_get(cctx, "acl", &acls); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } for (elt = cfg_list_first(acls); elt != NULL; elt = cfg_list_next(elt)) { const cfg_obj_t *acl = cfg_listelt_value(elt); @@ -163,8 +164,9 @@ convert_named_acl(const cfg_obj_t *nameobj, const cfg_obj_t *cctx, ISC_LIST_UNLINK(ctx->named_acl_cache, &loop, nextincache); loop.magic = 0; loop.name = NULL; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dacl->name = isc_mem_strdup(dacl->mctx, aclname); ISC_LIST_APPEND(ctx->named_acl_cache, dacl, nextincache); dns_acl_attach(dacl, target); @@ -215,8 +217,9 @@ count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx, REQUIRE(count != NULL); - if (has_negative != NULL) + if (has_negative != NULL) { *has_negative = false; + } for (elt = cfg_list_first(caml); elt != NULL; elt = cfg_list_next(elt)) { @@ -227,8 +230,9 @@ count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx, const cfg_obj_t *negated = cfg_tuple_get(ce, "negated"); if (!cfg_obj_isvoid(negated)) { ce = negated; - if (has_negative != NULL) + if (has_negative != NULL) { *has_negative = true; + } } } @@ -239,11 +243,13 @@ count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx, uint32_t sub; result = count_acl_elements(ce, cctx, lctx, ctx, mctx, &sub, &negative); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } n += sub; - if (negative) + if (negative) { n++; + } #if defined(HAVE_GEOIP2) } else if (cfg_obj_istuple(ce) && cfg_obj_isvoid(cfg_tuple_get(ce, "negated"))) { @@ -264,13 +270,15 @@ count_acl_elements(const cfg_obj_t *caml, const cfg_obj_t *cctx, result = convert_named_acl(ce, cctx, lctx, ctx, mctx, 0, &inneracl); if (result == ISC_R_SUCCESS) { - if (inneracl->has_negatives) + if (inneracl->has_negatives) { n++; - else + } else { n += inneracl->length; + } dns_acl_detach(&inneracl); - } else + } else { return (result); + } } } } @@ -425,8 +433,8 @@ geoip_can_answer(dns_aclelement_t *elt, cfg_aclconfctx_t *ctx) if (ctx->geoip->country != NULL) { return (true); } - /* city db can answer these too, so: */ - /* FALLTHROUGH */ + /* city db can answer these too, so: */ + /* FALLTHROUGH */ case dns_geoip_region: case dns_geoip_regionname: case dns_geoip_city_countrycode: @@ -637,8 +645,9 @@ cfg_acl_fromconfig2(const cfg_obj_t *caml, const cfg_obj_t *cctx, int new_nest_level = 0; bool setpos; - if (nest_level != 0) + if (nest_level != 0) { new_nest_level = nest_level - 1; + } REQUIRE(target != NULL); REQUIRE(*target == NULL || DNS_ACL_VALID(*target)); @@ -664,8 +673,9 @@ cfg_acl_fromconfig2(const cfg_obj_t *caml, const cfg_obj_t *cctx, if (nest_level == 0) { result = count_acl_elements(caml, cctx, lctx, ctx, mctx, &nelem, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } else { nelem = cfg_list_length(caml, false); } @@ -869,8 +879,9 @@ cfg_acl_fromconfig2(const cfg_obj_t *caml, const cfg_obj_t *cctx, de->type = dns_aclelementtype_localnets; de->negative = neg; } else { - if (inneracl != NULL) + if (inneracl != NULL) { dns_acl_detach(&inneracl); + } /* * This call should just find the cached * of the named acl. diff --git a/lib/isccfg/include/isccfg/aclconf.h b/lib/isccfg/include/isccfg/aclconf.h index 966a35ebdf..8bcc6bf65d 100644 --- a/lib/isccfg/include/isccfg/aclconf.h +++ b/lib/isccfg/include/isccfg/aclconf.h @@ -26,7 +26,7 @@ typedef struct cfg_aclconfctx { isc_mem_t *mctx; #if defined(HAVE_GEOIP2) dns_geoip_databases_t *geoip; -#endif +#endif /* if defined(HAVE_GEOIP2) */ isc_refcount_t references; } cfg_aclconfctx_t; diff --git a/lib/isccfg/include/isccfg/cfg.h b/lib/isccfg/include/isccfg/cfg.h index 43f16a8f52..b107961ff5 100644 --- a/lib/isccfg/include/isccfg/cfg.h +++ b/lib/isccfg/include/isccfg/cfg.h @@ -13,8 +13,8 @@ #define ISCCFG_CFG_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file isccfg/cfg.h * \brief @@ -505,9 +505,9 @@ cfg_printx(const cfg_obj_t *obj, unsigned int flags, #define CFG_PRINTER_ONELINE 0x2 /* print config as a single line */ #define CFG_PRINTER_ACTIVEONLY \ 0x4 /* print only active configuration \ - options, omitting ancient, \ - obsolete, nonimplemented, \ - and test-only options. */ + * options, omitting ancient, \ + * obsolete, nonimplemented, \ + * and test-only options. */ /*%< * Print the configuration object 'obj' by repeatedly calling the diff --git a/lib/isccfg/include/isccfg/grammar.h b/lib/isccfg/include/isccfg/grammar.h index ba4745af2e..5a79b2755e 100644 --- a/lib/isccfg/include/isccfg/grammar.h +++ b/lib/isccfg/include/isccfg/grammar.h @@ -143,10 +143,11 @@ typedef struct { } keyword_type_t; struct cfg_map { - cfg_obj_t *id; /*%< Used for 'named maps' like keys, zones, &c */ + cfg_obj_t *id; /*%< Used for 'named maps' like + * keys, zones, &c */ const cfg_clausedef_t *const *clausesets; /*%< The clauses that - can occur in this map; - used for printing */ + * can occur in this map; + * used for printing */ isc_symtab_t *symtab; }; diff --git a/lib/isccfg/namedconf.c b/lib/isccfg/namedconf.c index 2a5f712997..2cf33ac0a5 100644 --- a/lib/isccfg/namedconf.c +++ b/lib/isccfg/namedconf.c @@ -285,8 +285,9 @@ parse_matchname(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) if ((pctx->flags & CFG_PCTX_SKIP) != 0) { pctx->flags &= ~CFG_PCTX_SKIP; CHECK(cfg_parse_void(pctx, NULL, &obj)); - } else + } else { result = cfg_parse_astring(pctx, type, &obj); + } *ret = obj; cleanup: @@ -382,10 +383,11 @@ cleanup: static void print_updatepolicy(cfg_printer_t *pctx, const cfg_obj_t *obj) { - if (cfg_obj_isstring(obj)) + if (cfg_obj_isstring(obj)) { cfg_print_ustring(pctx, obj); - else + } else { cfg_print_bracketed_list(pctx, obj); + } } static void @@ -811,8 +813,9 @@ parse_qstringornone(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING)); if (pctx->token.type == isc_tokentype_string && - strcasecmp(TOKEN_STRING(pctx), "none") == 0) + strcasecmp(TOKEN_STRING(pctx), "none") == 0) { return (cfg_create_obj(pctx, &cfg_type_none, ret)); + } cfg_ungettoken(pctx); return (cfg_parse_qstring(pctx, type, ret)); cleanup: @@ -854,8 +857,9 @@ parse_boolorauto(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING)); if (pctx->token.type == isc_tokentype_string && - strcasecmp(TOKEN_STRING(pctx), "auto") == 0) + strcasecmp(TOKEN_STRING(pctx), "auto") == 0) { return (cfg_create_obj(pctx, &cfg_type_auto, ret)); + } cfg_ungettoken(pctx); return (cfg_parse_boolean(pctx, type, ret)); cleanup: @@ -865,12 +869,13 @@ cleanup: static void print_boolorauto(cfg_printer_t *pctx, const cfg_obj_t *obj) { - if (obj->type->rep == &cfg_rep_void) + if (obj->type->rep == &cfg_rep_void) { cfg_print_cstr(pctx, "auto"); - else if (obj->value.boolean) + } else if (obj->value.boolean) { cfg_print_cstr(pctx, "yes"); - else + } else { cfg_print_cstr(pctx, "no"); + } } static void @@ -909,13 +914,15 @@ parse_serverid(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) isc_result_t result; CHECK(cfg_gettoken(pctx, CFG_LEXOPT_QSTRING)); if (pctx->token.type == isc_tokentype_string && - strcasecmp(TOKEN_STRING(pctx), "none") == 0) + strcasecmp(TOKEN_STRING(pctx), "none") == 0) { return (cfg_create_obj(pctx, &cfg_type_none, ret)); + } if (pctx->token.type == isc_tokentype_string && strcasecmp(TOKEN_STRING(pctx), "hostname") == 0) { result = cfg_create_obj(pctx, &cfg_type_hostname, ret); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { (*ret)->value.boolean = true; + } return (result); } cfg_ungettoken(pctx); @@ -977,9 +984,9 @@ parse_portrange(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) UNUSED(type); CHECK(cfg_peektoken(pctx, ISC_LEXOPT_NUMBER | ISC_LEXOPT_CNUMBER)); - if (pctx->token.type == isc_tokentype_number) + if (pctx->token.type == isc_tokentype_number) { CHECK(parse_port(pctx, ret)); - else { + } else { CHECK(cfg_gettoken(pctx, 0)); if (pctx->token.type != isc_tokentype_string || strcasecmp(TOKEN_STRING(pctx), "range") != 0) { @@ -1004,8 +1011,9 @@ parse_portrange(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) } cleanup: - if (obj != NULL) + if (obj != NULL) { cfg_obj_destroy(pctx, &obj); + } return (result); } @@ -1138,13 +1146,13 @@ static cfg_clausedef_t options_clauses[] = { { "dnstap-output", &cfg_type_dnstapoutput, 0 }, { "dnstap-identity", &cfg_type_serverid, 0 }, { "dnstap-version", &cfg_type_qstringornone, 0 }, -#else +#else /* ifdef HAVE_DNSTAP */ { "dnstap-output", &cfg_type_dnstapoutput, CFG_CLAUSEFLAG_NOTCONFIGURED }, { "dnstap-identity", &cfg_type_serverid, CFG_CLAUSEFLAG_NOTCONFIGURED }, { "dnstap-version", &cfg_type_qstringornone, CFG_CLAUSEFLAG_NOTCONFIGURED }, -#endif +#endif /* ifdef HAVE_DNSTAP */ { "dscp", &cfg_type_uint32, 0 }, { "dump-file", &cfg_type_qstring, 0 }, { "fake-iquery", &cfg_type_boolean, CFG_CLAUSEFLAG_ANCIENT }, @@ -1158,7 +1166,7 @@ static cfg_clausedef_t options_clauses[] = { { "fstrm-set-output-queue-model", &cfg_type_fstrm_model, 0 }, { "fstrm-set-output-queue-size", &cfg_type_uint32, 0 }, { "fstrm-set-reopen-interval", &cfg_type_duration, 0 }, -#else +#else /* ifdef HAVE_DNSTAP */ { "fstrm-set-buffer-hint", &cfg_type_uint32, CFG_CLAUSEFLAG_NOTCONFIGURED }, { "fstrm-set-flush-timeout", &cfg_type_uint32, @@ -1176,7 +1184,7 @@ static cfg_clausedef_t options_clauses[] = { #endif /* HAVE_DNSTAP */ #if defined(HAVE_GEOIP2) { "geoip-directory", &cfg_type_qstringornone, 0 }, -#else +#else /* if defined(HAVE_GEOIP2) */ { "geoip-directory", &cfg_type_qstringornone, CFG_CLAUSEFLAG_NOTCONFIGURED }, #endif /* HAVE_GEOIP2 */ @@ -1448,12 +1456,15 @@ parse_dtout(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) } /* Create void objects for missing optional values. */ - if (obj->value.tuple[2] == NULL) + if (obj->value.tuple[2] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[2])); - if (obj->value.tuple[3] == NULL) + } + if (obj->value.tuple[3] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[3])); - if (obj->value.tuple[4] == NULL) + } + if (obj->value.tuple[4] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[4])); + } *ret = obj; return (ISC_R_SUCCESS); @@ -1539,8 +1550,9 @@ doc_rpz_policy(cfg_printer_t *pctx, const cfg_type_t *type) cfg_print_cstr(pctx, "( "); for (p = type->of; *p != NULL; p++) { cfg_print_cstr(pctx, *p); - if (p[1] != NULL) + if (p[1] != NULL) { cfg_print_cstr(pctx, " | "); + } } } @@ -1607,8 +1619,9 @@ cfg_parse_kv_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) for (;;) { CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING)); - if (pctx->token.type != isc_tokentype_string) + if (pctx->token.type != isc_tokentype_string) { break; + } for (fn = 1, f = &fields[1];; ++fn, ++f) { if (f->name == NULL) { @@ -1618,8 +1631,9 @@ cfg_parse_kv_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) goto cleanup; } if (obj->value.tuple[fn] == NULL && - strcasecmp(f->name, TOKEN_STRING(pctx)) == 0) + strcasecmp(f->name, TOKEN_STRING(pctx)) == 0) { break; + } } CHECK(cfg_gettoken(pctx, 0)); @@ -1627,9 +1641,10 @@ cfg_parse_kv_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) } for (fn = 1, f = &fields[1]; f->name != NULL; ++fn, ++f) { - if (obj->value.tuple[fn] == NULL) + if (obj->value.tuple[fn] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[fn])); + } } *ret = obj; @@ -1650,8 +1665,9 @@ cfg_print_kv_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj) fields = obj->type->of; for (f = fields, i = 0; f->name != NULL; f++, i++) { fieldobj = obj->value.tuple[i]; - if (fieldobj->type->print == cfg_print_void) + if (fieldobj->type->print == cfg_print_void) { continue; + } if (i != 0) { cfg_print_cstr(pctx, " "); cfg_print_cstr(pctx, f->name); @@ -1671,12 +1687,14 @@ cfg_doc_kv_tuple(cfg_printer_t *pctx, const cfg_type_t *type) if (f != fields) { cfg_print_cstr(pctx, " [ "); cfg_print_cstr(pctx, f->name); - if (f->type->doc != cfg_doc_void) + if (f->type->doc != cfg_doc_void) { cfg_print_cstr(pctx, " "); + } } cfg_doc_obj(pctx, f->type); - if (f != fields) + if (f != fields) { cfg_print_cstr(pctx, " ]"); + } } } @@ -1743,11 +1761,11 @@ static cfg_tuplefielddef_t rpz_fields[] = { #ifdef USE_DNSRPS { "dnsrps-enable", &cfg_type_boolean, 0 }, { "dnsrps-options", &cfg_type_bracketed_text, 0 }, -#else +#else /* ifdef USE_DNSRPS */ { "dnsrps-enable", &cfg_type_boolean, CFG_CLAUSEFLAG_NOTCONFIGURED }, { "dnsrps-options", &cfg_type_bracketed_text, CFG_CLAUSEFLAG_NOTCONFIGURED }, -#endif +#endif /* ifdef USE_DNSRPS */ { NULL, NULL, 0 } }; static cfg_type_t cfg_type_rpz = { "rpz", @@ -1827,10 +1845,11 @@ print_lookaside(cfg_printer_t *pctx, const cfg_obj_t *obj) const cfg_obj_t *domain = obj->value.tuple[0]; if (domain->value.string.length == 4 && - strncmp(domain->value.string.base, "auto", 4) == 0) + strncmp(domain->value.string.base, "auto", 4) == 0) { cfg_print_cstr(pctx, "auto"); - else + } else { cfg_print_tuple(pctx, obj); + } } static void @@ -1954,11 +1973,11 @@ static cfg_clausedef_t view_clauses[] = { #ifdef USE_DNSRPS { "dnsrps-enable", &cfg_type_boolean, 0 }, { "dnsrps-options", &cfg_type_bracketed_text, 0 }, -#else +#else /* ifdef USE_DNSRPS */ { "dnsrps-enable", &cfg_type_boolean, CFG_CLAUSEFLAG_NOTCONFIGURED }, { "dnsrps-options", &cfg_type_bracketed_text, CFG_CLAUSEFLAG_NOTCONFIGURED }, -#endif +#endif /* ifdef USE_DNSRPS */ { "dnssec-accept-expired", &cfg_type_boolean, 0 }, { "dnssec-enable", &cfg_type_boolean, CFG_CLAUSEFLAG_OBSOLETE }, { "dnssec-lookaside", &cfg_type_lookaside, @@ -1968,7 +1987,7 @@ static cfg_clausedef_t view_clauses[] = { { "dnssec-validation", &cfg_type_boolorauto, 0 }, #ifdef HAVE_DNSTAP { "dnstap", &cfg_type_dnstap, 0 }, -#else +#else /* ifdef HAVE_DNSTAP */ { "dnstap", &cfg_type_dnstap, CFG_CLAUSEFLAG_NOTCONFIGURED }, #endif /* HAVE_DNSTAP */ { "dual-stack-servers", &cfg_type_nameportiplist, 0 }, @@ -1988,9 +2007,9 @@ static cfg_clausedef_t view_clauses[] = { { "lame-ttl", &cfg_type_duration, 0 }, #ifdef HAVE_LMDB { "lmdb-mapsize", &cfg_type_sizeval, 0 }, -#else +#else /* ifdef HAVE_LMDB */ { "lmdb-mapsize", &cfg_type_sizeval, CFG_CLAUSEFLAG_NOOP }, -#endif +#endif /* ifdef HAVE_LMDB */ { "max-acache-size", &cfg_type_sizenodefault, CFG_CLAUSEFLAG_OBSOLETE }, { "max-cache-size", &cfg_type_sizeorpercent, 0 }, { "max-cache-ttl", &cfg_type_duration, 0 }, @@ -2532,8 +2551,9 @@ parse_unitstring(char *str, isc_resourcevalue_t *valuep) } len = strlen(str); - if (len < 2 || endp[1] != '\0') + if (len < 2 || endp[1] != '\0') { return (ISC_R_FAILURE); + } switch (str[len - 1]) { case 'k': @@ -3010,10 +3030,11 @@ parse_optional_class(cfg_parser_t *pctx, const cfg_type_t *type, isc_result_t result; UNUSED(type); CHECK(cfg_peektoken(pctx, 0)); - if (pctx->token.type == isc_tokentype_string) + if (pctx->token.type == isc_tokentype_string) { CHECK(cfg_parse_obj(pctx, &cfg_type_ustring, ret)); - else + } else { CHECK(cfg_parse_obj(pctx, &cfg_type_void, ret)); + } cleanup: return (result); } @@ -3085,8 +3106,9 @@ parse_querysource(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) "or 'dscp'"); return (ISC_R_UNEXPECTEDTOKEN); } - } else + } else { break; + } } if (have_address > 1 || have_port > 1 || have_address + have_port == 0) { @@ -3211,8 +3233,9 @@ parse_server_key_kludge(cfg_parser_t *pctx, const cfg_type_t *type, /* Skip semicolon if present. */ CHECK(cfg_peektoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special && - pctx->token.value.as_char == ';') + pctx->token.value.as_char == ';') { CHECK(cfg_gettoken(pctx, 0)); + } CHECK(cfg_parse_special(pctx, '}')); } @@ -3380,12 +3403,15 @@ parse_logfile(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) } /* Create void objects for missing optional values. */ - if (obj->value.tuple[1] == NULL) + if (obj->value.tuple[1] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[1])); - if (obj->value.tuple[2] == NULL) + } + if (obj->value.tuple[2] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[2])); - if (obj->value.tuple[3] == NULL) + } + if (obj->value.tuple[3] == NULL) { CHECK(cfg_parse_void(pctx, NULL, &obj->value.tuple[3])); + } *ret = obj; return (ISC_R_SUCCESS); @@ -3562,10 +3588,11 @@ parse_sockaddrnameport(cfg_parser_t *pctx, const cfg_type_t *type, CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING)); if (pctx->token.type == isc_tokentype_string || pctx->token.type == isc_tokentype_qstring) { - if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V6OK)) + if (cfg_lookingat_netaddr(pctx, + CFG_ADDR_V4OK | CFG_ADDR_V6OK)) { CHECK(cfg_parse_sockaddr(pctx, &cfg_type_sockaddr, ret)); - else { + } else { const cfg_tuplefielddef_t *fields = cfg_type_nameport.of; CHECK(cfg_create_tuple(pctx, &cfg_type_nameport, &obj)); @@ -3652,11 +3679,13 @@ parse_masterselement(cfg_parser_t *pctx, const cfg_type_t *type, CHECK(cfg_peektoken(pctx, CFG_LEXOPT_QSTRING)); if (pctx->token.type == isc_tokentype_string || pctx->token.type == isc_tokentype_qstring) { - if (cfg_lookingat_netaddr(pctx, CFG_ADDR_V4OK | CFG_ADDR_V6OK)) + if (cfg_lookingat_netaddr(pctx, + CFG_ADDR_V4OK | CFG_ADDR_V6OK)) { CHECK(cfg_parse_sockaddr(pctx, &cfg_type_sockaddr, ret)); - else + } else { CHECK(cfg_parse_astring(pctx, &cfg_type_astring, ret)); + } } else { cfg_parser_error(pctx, CFG_LOG_NEAR, "expected IP address or masters name"); diff --git a/lib/isccfg/parser.c b/lib/isccfg/parser.c index a3f794405e..5d51f3bdc9 100644 --- a/lib/isccfg/parser.c +++ b/lib/isccfg/parser.c @@ -174,9 +174,9 @@ cfg_print_chars(cfg_printer_t *pctx, const char *text, int len) static void print_open(cfg_printer_t *pctx) { - if ((pctx->flags & CFG_PRINTER_ONELINE) != 0) + if ((pctx->flags & CFG_PRINTER_ONELINE) != 0) { cfg_print_cstr(pctx, "{ "); - else { + } else { cfg_print_cstr(pctx, "{\n"); pctx->indent++; } @@ -216,8 +216,9 @@ cfg_parse_obj(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) REQUIRE(ret != NULL && *ret == NULL); result = type->parse(pctx, type, ret); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } ENSURE(*ret != NULL); return (ISC_R_SUCCESS); } @@ -268,20 +269,23 @@ cfg_create_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) fields = type->of; - for (f = fields; f->name != NULL; f++) + for (f = fields; f->name != NULL; f++) { nfields++; + } CHECK(cfg_create_obj(pctx, type, &obj)); obj->value.tuple = isc_mem_get(pctx->mctx, nfields * sizeof(cfg_obj_t *)); - for (f = fields, i = 0; f->name != NULL; f++, i++) + for (f = fields, i = 0; f->name != NULL; f++, i++) { obj->value.tuple[i] = NULL; + } *ret = obj; return (ISC_R_SUCCESS); cleanup: - if (obj != NULL) + if (obj != NULL) { isc_mem_put(pctx->mctx, obj, sizeof(*obj)); + } return (result); } @@ -301,8 +305,9 @@ cfg_parse_tuple(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) fields = type->of; CHECK(cfg_create_tuple(pctx, type, &obj)); - for (f = fields, i = 0; f->name != NULL; f++, i++) + for (f = fields, i = 0; f->name != NULL; f++, i++) { CHECK(cfg_parse_obj(pctx, f->type, &obj->value.tuple[i])); + } *ret = obj; return (ISC_R_SUCCESS); @@ -327,8 +332,9 @@ cfg_print_tuple(cfg_printer_t *pctx, const cfg_obj_t *obj) for (f = fields, i = 0; f->name != NULL; f++, i++) { const cfg_obj_t *fieldobj = obj->value.tuple[i]; - if (need_space && fieldobj->type->rep != &cfg_rep_void) + if (need_space && fieldobj->type->rep != &cfg_rep_void) { cfg_print_cstr(pctx, " "); + } cfg_print_obj(pctx, fieldobj); need_space = (need_space || fieldobj->type->print != cfg_print_void); @@ -348,8 +354,9 @@ cfg_doc_tuple(cfg_printer_t *pctx, const cfg_type_t *type) fields = type->of; for (f = fields; f->name != NULL; f++) { - if (need_space) + if (need_space) { cfg_print_cstr(pctx, " "); + } cfg_doc_obj(pctx, f->type); need_space = (f->type->print != cfg_print_void); } @@ -363,8 +370,9 @@ free_tuple(cfg_parser_t *pctx, cfg_obj_t *obj) const cfg_tuplefielddef_t *f; unsigned int nfields = 0; - if (obj->value.tuple == NULL) + if (obj->value.tuple == NULL) { return; + } for (f = fields, i = 0; f->name != NULL; f++, i++) { CLEANUP_OBJ(obj->value.tuple[i]); @@ -393,8 +401,9 @@ cfg_tuple_get(const cfg_obj_t *tupleobj, const char *name) fields = tupleobj->type->of; for (f = fields, i = 0; f->name != NULL; f++, i++) { - if (strcmp(f->name, name) == 0) + if (strcmp(f->name, name) == 0) { return (tupleobj->value.tuple[i]); + } } INSIST(0); ISC_UNREACHABLE(); @@ -409,8 +418,9 @@ cfg_parse_special(cfg_parser_t *pctx, int special) CHECK(cfg_gettoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special && - pctx->token.value.as_char == special) + pctx->token.value.as_char == special) { return (ISC_R_SUCCESS); + } cfg_parser_error(pctx, CFG_LOG_NEAR, "'%c' expected", special); return (ISC_R_UNEXPECTEDTOKEN); @@ -432,8 +442,9 @@ parse_semicolon(cfg_parser_t *pctx) CHECK(cfg_gettoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special && - pctx->token.value.as_char == ';') + pctx->token.value.as_char == ';') { return (ISC_R_SUCCESS); + } cfg_parser_error(pctx, CFG_LOG_BEFORE, "missing ';'"); cfg_ungettoken(pctx); @@ -451,8 +462,9 @@ parse_eof(cfg_parser_t *pctx) CHECK(cfg_gettoken(pctx, 0)); - if (pctx->token.type == isc_tokentype_eof) + if (pctx->token.type == isc_tokentype_eof) { return (ISC_R_SUCCESS); + } cfg_parser_error(pctx, CFG_LOG_NEAR, "syntax error"); return (ISC_R_UNEXPECTEDTOKEN); @@ -520,8 +532,9 @@ cfg_parser_create(isc_mem_t *mctx, isc_log_t *lctx, cfg_parser_t **ret) return (ISC_R_SUCCESS); cleanup: - if (pctx->lexer != NULL) + if (pctx->lexer != NULL) { isc_lex_destroy(&pctx->lexer); + } CLEANUP_OBJ(pctx->open_files); CLEANUP_OBJ(pctx->closed_files); isc_mem_putanddetach(&pctx->mctx, pctx, sizeof(*pctx)); @@ -580,8 +593,9 @@ cfg_parser_reset(cfg_parser_t *pctx) { REQUIRE(pctx != NULL); - if (pctx->lexer != NULL) + if (pctx->lexer != NULL) { isc_lex_close(pctx->lexer); + } pctx->seen_eof = false; pctx->ungotten = false; @@ -604,8 +618,9 @@ parse2(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) if (pctx->errors != 0) { /* Errors have been logged. */ - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = ISC_R_FAILURE; + } goto cleanup; } @@ -670,8 +685,9 @@ cfg_parse_buffer(cfg_parser_t *pctx, isc_buffer_t *buffer, const char *file, pctx->buf_name = file; pctx->flags = flags; - if (line != 0U) + if (line != 0U) { CHECK(isc_lex_setsourceline(pctx->lexer, line)); + } CHECK(parse2(pctx, type, ret)); pctx->buf_name = NULL; @@ -1153,17 +1169,17 @@ cfg_obj_asduration(const cfg_obj_t *obj) { REQUIRE(obj != NULL && obj->type->rep == &cfg_rep_duration); uint32_t duration = 0; - duration += obj->value.duration.parts[6]; // Seconds - duration += obj->value.duration.parts[5] * 60; // Minutes - duration += obj->value.duration.parts[4] * 3600; // Hours - duration += obj->value.duration.parts[3] * 86400; // Days - duration += obj->value.duration.parts[2] * 86400 * 7; // Weaks + duration += obj->value.duration.parts[6]; /* Seconds */ + duration += obj->value.duration.parts[5] * 60; /* Minutes */ + duration += obj->value.duration.parts[4] * 3600; /* Hours */ + duration += obj->value.duration.parts[3] * 86400; /* Days */ + duration += obj->value.duration.parts[2] * 86400 * 7; /* Weaks */ /* * The below additions are not entirely correct * because days may very per month and per year. */ - duration += obj->value.duration.parts[1] * 86400 * 31; // Months - duration += obj->value.duration.parts[0] * 86400 * 365; // Years + duration += obj->value.duration.parts[1] * 86400 * 31; /* Months */ + duration += obj->value.duration.parts[0] * 86400 * 365; /* Years */ return (duration); } @@ -1601,8 +1617,9 @@ cfg_is_enum(const char *s, const char *const *enums) REQUIRE(enums != NULL); for (p = enums; *p != NULL; p++) { - if (strcasecmp(*p, s) == 0) + if (strcasecmp(*p, s) == 0) { return (true); + } } return (false); } @@ -1612,8 +1629,9 @@ check_enum(cfg_parser_t *pctx, cfg_obj_t *obj, const char *const *enums) { const char *s = obj->value.string.base; - if (cfg_is_enum(s, enums)) + if (cfg_is_enum(s, enums)) { return (ISC_R_SUCCESS); + } cfg_parser_error(pctx, 0, "'%s' unexpected", s); return (ISC_R_UNEXPECTEDTOKEN); } @@ -1648,8 +1666,9 @@ cfg_doc_enum(cfg_printer_t *pctx, const cfg_type_t *type) cfg_print_cstr(pctx, "( "); for (p = type->of; *p != NULL; p++) { cfg_print_cstr(pctx, *p); - if (p[1] != NULL) + if (p[1] != NULL) { cfg_print_cstr(pctx, " | "); + } } cfg_print_cstr(pctx, " )"); } @@ -1728,10 +1747,12 @@ print_sstring(cfg_printer_t *pctx, const cfg_obj_t *obj) cfg_print_cstr(pctx, "\""); if ((pctx->flags & CFG_PRINTER_XKEY) != 0) { unsigned int len = obj->value.string.length; - while (len-- > 0) + while (len-- > 0) { cfg_print_cstr(pctx, "?"); - } else + } + } else { cfg_print_ustring(pctx, obj); + } cfg_print_cstr(pctx, "\""); } @@ -1901,12 +1922,12 @@ parse_addrmatchelt(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) #if defined(HAVE_GEOIP2) CHECK(cfg_gettoken(pctx, 0)); CHECK(cfg_parse_obj(pctx, &cfg_type_geoip, ret)); -#else +#else /* if defined(HAVE_GEOIP2) */ cfg_parser_error(pctx, CFG_LOG_NEAR, "'geoip' " "not supported in this build"); return (ISC_R_UNEXPECTEDTOKEN); -#endif +#endif /* if defined(HAVE_GEOIP2) */ } else { if (cfg_lookingat_netaddr( pctx, CFG_ADDR_V4OK | CFG_ADDR_V4PREFIXOK | @@ -2060,11 +2081,13 @@ cfg_parse_boolean(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) UNUSED(type); result = cfg_gettoken(pctx, 0); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (pctx->token.type != isc_tokentype_string) + if (pctx->token.type != isc_tokentype_string) { goto bad_boolean; + } if ((strcasecmp(TOKEN_STRING(pctx), "true") == 0) || (strcasecmp(TOKEN_STRING(pctx), "yes") == 0) || @@ -2097,10 +2120,11 @@ cfg_print_boolean(cfg_printer_t *pctx, const cfg_obj_t *obj) REQUIRE(pctx != NULL); REQUIRE(obj != NULL); - if (obj->value.boolean) + if (obj->value.boolean) { cfg_print_cstr(pctx, "yes"); - else + } else { cfg_print_cstr(pctx, "no"); + } } LIBISCCFG_EXTERNAL_DATA cfg_type_t cfg_type_boolean = { @@ -2142,8 +2166,9 @@ create_listelt(cfg_parser_t *pctx, cfg_listelt_t **eltp) static void free_listelt(cfg_parser_t *pctx, cfg_listelt_t *elt) { - if (elt->obj != NULL) + if (elt->obj != NULL) { cfg_obj_destroy(pctx, &elt->obj); + } isc_mem_put(pctx->mctx, elt, sizeof(*elt)); } @@ -2172,8 +2197,9 @@ cfg_parse_listelt(cfg_parser_t *pctx, const cfg_type_t *elttype, CHECK(create_listelt(pctx, &elt)); result = cfg_parse_obj(pctx, elttype, &value); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } elt->obj = value; @@ -2202,8 +2228,9 @@ parse_list(cfg_parser_t *pctx, const cfg_type_t *listtype, cfg_obj_t **ret) for (;;) { CHECK(cfg_peektoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special && - pctx->token.value.as_char == /*{*/ '}') + pctx->token.value.as_char == /*{*/ '}') { break; + } CHECK(cfg_parse_listelt(pctx, listof, &elt)); CHECK(parse_semicolon(pctx)); ISC_LIST_APPEND(listobj->value.list, elt, link); @@ -2213,8 +2240,9 @@ parse_list(cfg_parser_t *pctx, const cfg_type_t *listtype, cfg_obj_t **ret) return (ISC_R_SUCCESS); cleanup: - if (elt != NULL) + if (elt != NULL) { free_listelt(pctx, elt); + } CLEANUP_OBJ(listobj); return (result); } @@ -2303,8 +2331,9 @@ cfg_parse_spacelist(cfg_parser_t *pctx, const cfg_type_t *listtype, CHECK(cfg_peektoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special && - pctx->token.value.as_char == ';') + pctx->token.value.as_char == ';') { break; + } CHECK(cfg_parse_listelt(pctx, listof, &elt)); ISC_LIST_APPEND(listobj->value.list, elt, link); } @@ -2328,8 +2357,9 @@ cfg_print_spacelist(cfg_printer_t *pctx, const cfg_obj_t *obj) for (elt = ISC_LIST_HEAD(*list); elt != NULL; elt = ISC_LIST_NEXT(elt, link)) { cfg_print_obj(pctx, elt->obj); - if (ISC_LIST_NEXT(elt, link) != NULL) + if (ISC_LIST_NEXT(elt, link) != NULL) { cfg_print_cstr(pctx, " "); + } } } @@ -2344,8 +2374,9 @@ const cfg_listelt_t * cfg_list_first(const cfg_obj_t *obj) { REQUIRE(obj == NULL || obj->type->rep == &cfg_rep_list); - if (obj == NULL) + if (obj == NULL) { return (NULL); + } return (ISC_LIST_HEAD(obj->value.list)); } @@ -2366,8 +2397,9 @@ cfg_list_length(const cfg_obj_t *obj, bool recurse) const cfg_listelt_t *elt; unsigned int count = 0; - if (obj == NULL || !cfg_obj_islist(obj)) + if (obj == NULL || !cfg_obj_islist(obj)) { return (0U); + } for (elt = cfg_list_first(obj); elt != NULL; elt = cfg_list_next(elt)) { if (recurse && cfg_obj_islist(elt->obj)) { count += cfg_list_length(elt->obj, recurse); @@ -2461,8 +2493,9 @@ cfg_parse_mapbody(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) for (clause = *clauseset; clause->name != NULL; clause++) { if (strcasecmp(TOKEN_STRING(pctx), - clause->name) == 0) + clause->name) == 0) { goto done; + } } } done: @@ -2614,8 +2647,9 @@ parse_symtab_elt(cfg_parser_t *pctx, const char *name, cfg_type_t *elttype, CHECK(cfg_parse_obj(pctx, elttype, &obj)); - if (callback && pctx->callback != NULL) + if (callback && pctx->callback != NULL) { CHECK(pctx->callback(name, obj, pctx->callbackarg)); + } symval.as_pointer = obj; CHECK(isc_symtab_define(symtab, name, 1, symval, isc_symexists_reject)); @@ -2707,17 +2741,19 @@ cfg_parse_netprefix_map(cfg_parser_t *pctx, const cfg_type_t *type, static void print_symval(cfg_printer_t *pctx, const char *name, cfg_obj_t *obj) { - if ((pctx->flags & CFG_PRINTER_ONELINE) == 0) + if ((pctx->flags & CFG_PRINTER_ONELINE) == 0) { cfg_print_indent(pctx); + } cfg_print_cstr(pctx, name); cfg_print_cstr(pctx, " "); cfg_print_obj(pctx, obj); - if ((pctx->flags & CFG_PRINTER_ONELINE) == 0) + if ((pctx->flags & CFG_PRINTER_ONELINE) == 0) { cfg_print_cstr(pctx, ";\n"); - else + } else { cfg_print_cstr(pctx, "; "); + } } void @@ -2755,7 +2791,7 @@ cfg_print_mapbody(cfg_printer_t *pctx, const cfg_obj_t *obj) symobj); } } else if (result == ISC_R_NOTFOUND) { - ; /* do nothing */ + /* do nothing */ } else { INSIST(0); ISC_UNREACHABLE(); @@ -2787,10 +2823,11 @@ cfg_print_clauseflags(cfg_printer_t *pctx, unsigned int flags) bool first = true; for (p = flagtexts; p->flag != 0; p++) { if ((flags & p->flag) != 0) { - if (first) + if (first) { cfg_print_cstr(pctx, " // "); - else + } else { cfg_print_cstr(pctx, ", "); + } cfg_print_cstr(pctx, p->text); first = false; } @@ -2873,8 +2910,9 @@ cfg_doc_map(cfg_printer_t *pctx, const cfg_type_t *type) } cfg_print_indent(pctx); cfg_print_cstr(pctx, clause->name); - if (clause->type->print != cfg_print_void) + if (clause->type->print != cfg_print_void) { cfg_print_cstr(pctx, " "); + } cfg_doc_obj(pctx, clause->type); cfg_print_cstr(pctx, ";"); cfg_print_clauseflags(pctx, clause->flags); @@ -2905,8 +2943,9 @@ cfg_map_get(const cfg_obj_t *mapobj, const char *name, const cfg_obj_t **obj) map = &mapobj->value.map; result = isc_symtab_lookup(map->symtab, name, MAP_SYM, &val); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } *obj = val.as_pointer; return (ISC_R_SUCCESS); } @@ -2947,8 +2986,9 @@ cfg_map_firstclause(const cfg_type_t *map, const void **clauses, *idx = 0; while ((*clauseset)[*idx].name == NULL) { *clauses = (*++clauseset); - if (*clauses == NULL) + if (*clauses == NULL) { return (NULL); + } } return ((*clauseset)[*idx].name); } @@ -2972,8 +3012,9 @@ cfg_map_nextclause(const cfg_type_t *map, const void **clauses, while ((*clauseset)[*idx].name == NULL) { *idx = 0; *clauses = (*++clauseset); - if (*clauses == NULL) + if (*clauses == NULL) { return (NULL); + } } return ((*clauseset)[*idx].name); } @@ -3006,8 +3047,9 @@ parse_token(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) return (result); cleanup: - if (obj != NULL) + if (obj != NULL) { isc_mem_put(pctx->mctx, obj, sizeof(*obj)); + } return (result); } @@ -3035,11 +3077,11 @@ parse_unsupported(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) CHECK(cfg_peektoken(pctx, 0)); if (pctx->token.type == isc_tokentype_special) { - if (pctx->token.value.as_char == '{') + if (pctx->token.value.as_char == '{') { braces++; - else if (pctx->token.value.as_char == '}') + } else if (pctx->token.value.as_char == '}') { braces--; - else if (pctx->token.value.as_char == ';') { + } else if (pctx->token.value.as_char == ';') { if (braces == 0) { break; } @@ -3085,8 +3127,9 @@ token_addr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) struct in_addr in4a; struct in6_addr in6a; - if (pctx->token.type != isc_tokentype_string) + if (pctx->token.type != isc_tokentype_string) { return (ISC_R_UNEXPECTEDTOKEN); + } s = TOKEN_STRING(pctx); if ((flags & CFG_ADDR_WILDOK) != 0 && strcmp(s, "*") == 0) { @@ -3127,8 +3170,9 @@ token_addr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) strlcpy(buf, s, sizeof(buf)); d = strchr(buf, '%'); - if (d != NULL) + if (d != NULL) { *d = '\0'; + } if (inet_pton(AF_INET6, buf, &in6a) == 1) { if (d != NULL) { @@ -3136,8 +3180,9 @@ token_addr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) result = isc_netscope_pton( AF_INET6, d + 1, &in6a, &zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } isc_netaddr_fromin6(na, &in6a); @@ -3162,22 +3207,25 @@ cfg_parse_rawaddr(cfg_parser_t *pctx, unsigned int flags, isc_netaddr_t *na) CHECK(cfg_gettoken(pctx, 0)); result = token_addr(pctx, flags, na); if (result == ISC_R_UNEXPECTEDTOKEN) { - if ((flags & CFG_ADDR_WILDOK) != 0) + if ((flags & CFG_ADDR_WILDOK) != 0) { wild = " or '*'"; - if ((flags & CFG_ADDR_V4PREFIXOK) != 0) + } + if ((flags & CFG_ADDR_V4PREFIXOK) != 0) { wild = " or IPv4 prefix"; - if ((flags & CFG_ADDR_MASK) == CFG_ADDR_V4OK) + } + if ((flags & CFG_ADDR_MASK) == CFG_ADDR_V4OK) { cfg_parser_error(pctx, CFG_LOG_NEAR, "expected IPv4 address%s%s", prefix, wild); - else if ((flags & CFG_ADDR_MASK) == CFG_ADDR_V6OK) + } else if ((flags & CFG_ADDR_MASK) == CFG_ADDR_V6OK) { cfg_parser_error(pctx, CFG_LOG_NEAR, "expected IPv6 address%s%s", prefix, wild); - else + } else { cfg_parser_error(pctx, CFG_LOG_NEAR, "expected IP address%s%s", prefix, wild); + } } cleanup: return (result); @@ -3307,14 +3355,16 @@ cfg_doc_netaddr(cfg_printer_t *pctx, const cfg_type_t *type) n++; } if ((*flagp & CFG_ADDR_V6OK) != 0) { - if (n != 0) + if (n != 0) { cfg_print_cstr(pctx, " | "); + } cfg_print_cstr(pctx, ""); n++; } if ((*flagp & CFG_ADDR_WILDOK) != 0) { - if (n != 0) + if (n != 0) { cfg_print_cstr(pctx, " | "); + } cfg_print_cstr(pctx, "*"); n++; POST(n); @@ -3487,10 +3537,12 @@ parse_sockaddrsub(cfg_parser_t *pctx, const cfg_type_t *type, int flags, CHECK(cfg_gettoken(pctx, 0)); /* read "dscp" */ CHECK(cfg_parse_dscp(pctx, &dscp)); ++have_dscp; - } else + } else { break; - } else + } + } else { break; + } } if (have_port > 1) { cfg_parser_error(pctx, 0, "expected at most one port"); @@ -3581,14 +3633,16 @@ cfg_doc_sockaddr(cfg_printer_t *pctx, const cfg_type_t *type) n++; } if ((*flagp & CFG_ADDR_V6OK) != 0) { - if (n != 0) + if (n != 0) { cfg_print_cstr(pctx, " | "); + } cfg_print_cstr(pctx, ""); n++; } if ((*flagp & CFG_ADDR_WILDOK) != 0) { - if (n != 0) + if (n != 0) { cfg_print_cstr(pctx, " | "); + } cfg_print_cstr(pctx, "*"); n++; POST(n); @@ -3632,8 +3686,9 @@ cfg_gettoken(cfg_parser_t *pctx, int options) REQUIRE(pctx != NULL); - if (pctx->seen_eof) + if (pctx->seen_eof) { return (ISC_R_SUCCESS); + } options |= (ISC_LEXOPT_EOF | ISC_LEXOPT_NOMORE); @@ -3690,8 +3745,9 @@ cfg_ungettoken(cfg_parser_t *pctx) { REQUIRE(pctx != NULL); - if (pctx->seen_eof) + if (pctx->seen_eof) { return; + } isc_lex_ungettoken(pctx->lexer, &pctx->token); pctx->ungotten = true; } @@ -3719,8 +3775,9 @@ cfg_getstringtoken(cfg_parser_t *pctx) isc_result_t result; result = cfg_gettoken(pctx, CFG_LEXOPT_QSTRING); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (pctx->token.type != isc_tokentype_string && pctx->token.type != isc_tokentype_qstring) { @@ -3764,12 +3821,14 @@ static bool have_current_file(cfg_parser_t *pctx) { cfg_listelt_t *elt; - if (pctx->open_files == NULL) + if (pctx->open_files == NULL) { return (false); + } elt = ISC_LIST_TAIL(pctx->open_files->value.list); - if (elt == NULL) + if (elt == NULL) { return (false); + } return (true); } @@ -3781,12 +3840,14 @@ current_file(cfg_parser_t *pctx) cfg_listelt_t *elt; cfg_obj_t * fileobj; - if (!have_current_file(pctx)) + if (!have_current_file(pctx)) { return (none); + } elt = ISC_LIST_TAIL(pctx->open_files->value.list); - if (elt == NULL) /* shouldn't be possible, but... */ + if (elt == NULL) { /* shouldn't be possible, but... */ return (none); + } fileobj = elt->obj; INSIST(fileobj->type == &cfg_type_qstring); @@ -3804,15 +3865,17 @@ parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags, const char *prep = ""; size_t len; - if (is_warning) + if (is_warning) { level = ISC_LOG_WARNING; + } where[0] = '\0'; - if (have_current_file(pctx)) + if (have_current_file(pctx)) { snprintf(where, sizeof(where), "%s:%u: ", current_file(pctx), pctx->line); - else if (pctx->buf_name != NULL) + } else if (pctx->buf_name != NULL) { snprintf(where, sizeof(where), "%s: ", pctx->buf_name); + } len = vsnprintf(message, sizeof(message), format, args); #define ELIPSIS " ... " @@ -3824,8 +3887,9 @@ parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags, if ((flags & (CFG_LOG_NEAR | CFG_LOG_BEFORE | CFG_LOG_NOPREP)) != 0) { isc_region_t r; - if (pctx->ungotten) + if (pctx->ungotten) { (void)cfg_gettoken(pctx, 0); + } if (pctx->token.type == isc_tokentype_eof) { snprintf(tokenbuf, sizeof(tokenbuf), "end of file"); @@ -3834,12 +3898,13 @@ parser_complain(cfg_parser_t *pctx, bool is_warning, unsigned int flags, tokenbuf[0] = '\0'; } else { isc_lex_getlasttokentext(pctx->lexer, &pctx->token, &r); - if (r.length > MAX_LOG_TOKEN) + if (r.length > MAX_LOG_TOKEN) { snprintf(tokenbuf, sizeof(tokenbuf), "'%.*s...'", MAX_LOG_TOKEN, r.base); - else + } else { snprintf(tokenbuf, sizeof(tokenbuf), "'%.*s'", (int)r.length, r.base); + } } /* Choose a preposition. */ @@ -3867,8 +3932,9 @@ cfg_obj_log(const cfg_obj_t *obj, isc_log_t *lctx, int level, const char *fmt, REQUIRE(obj != NULL); REQUIRE(fmt != NULL); - if (!isc_log_wouldlog(lctx, level)) + if (!isc_log_wouldlog(lctx, level)) { return; + } va_start(ap, fmt); vsnprintf(msgbuf, sizeof(msgbuf), fmt, ap); @@ -3951,8 +4017,9 @@ create_map(cfg_parser_t *pctx, const cfg_type_t *type, cfg_obj_t **ret) return (ISC_R_SUCCESS); cleanup: - if (obj != NULL) + if (obj != NULL) { isc_mem_put(pctx->mctx, obj, sizeof(*obj)); + } return (result); } @@ -4071,8 +4138,9 @@ cfg_parser_mapadd(cfg_parser_t *pctx, cfg_obj_t *mapobj, cfg_obj_t *obj, } breakout: - if (clause == NULL || clause->name == NULL) + if (clause == NULL || clause->name == NULL) { return (ISC_R_FAILURE); + } result = isc_symtab_lookup(map->symtab, clausename, 0, &symval); if (result == ISC_R_NOTFOUND) { @@ -4083,8 +4151,9 @@ breakout: cfg_obj_attach(obj, &elt->obj); ISC_LIST_APPEND(destobj->value.list, elt, link); symval.as_pointer = destobj; - } else + } else { symval.as_pointer = obj; + } CHECK(isc_symtab_define(map->symtab, clausename, 1, symval, isc_symexists_reject)); @@ -4097,16 +4166,18 @@ breakout: CHECK(create_listelt(pctx, &elt)); cfg_obj_attach(obj, &elt->obj); ISC_LIST_APPEND(destobj2->value.list, elt, link); - } else + } else { result = ISC_R_EXISTS; + } } destobj = NULL; elt = NULL; cleanup: - if (elt != NULL) + if (elt != NULL) { free_listelt(pctx, elt); + } CLEANUP_OBJ(destobj); return (result); diff --git a/lib/isccfg/tests/duration_test.c b/lib/isccfg/tests/duration_test.c index bb748f675d..3c2ed5d919 100644 --- a/lib/isccfg/tests/duration_test.c +++ b/lib/isccfg/tests/duration_test.c @@ -202,4 +202,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/isccfg/tests/parser_test.c b/lib/isccfg/tests/parser_test.c index 455bff4a59..701e1f00b9 100644 --- a/lib/isccfg/tests/parser_test.c +++ b/lib/isccfg/tests/parser_test.c @@ -206,4 +206,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/ns/client.c b/lib/ns/client.c index 8c0e0fc945..c2a1c5b8ba 100644 --- a/lib/ns/client.c +++ b/lib/ns/client.c @@ -87,10 +87,10 @@ #define MTRACE(m) \ isc_log_write(ns_lctx, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_CLIENT, \ ISC_LOG_DEBUG(3), "clientmgr @%p: %s", manager, (m)) -#else +#else /* ifdef NS_CLIENT_TRACE */ #define CTRACE(m) ((void)(m)) #define MTRACE(m) ((void)(m)) -#endif +#endif /* ifdef NS_CLIENT_TRACE */ #define TCP_CLIENT(c) (((c)->attributes & NS_CLIENTATTR_TCP) != 0) @@ -110,13 +110,13 @@ */ #ifndef NS_CLIENT_DROPPORT #define NS_CLIENT_DROPPORT 1 -#endif +#endif /* ifndef NS_CLIENT_DROPPORT */ #if defined(_WIN32) && !defined(_WIN64) LIBNS_EXTERNAL_DATA atomic_uint_fast32_t ns_client_requests; -#else +#else /* if defined(_WIN32) && !defined(_WIN64) */ LIBNS_EXTERNAL_DATA atomic_uint_fast64_t ns_client_requests; -#endif +#endif /* if defined(_WIN32) && !defined(_WIN64) */ static void clientmgr_attach(ns_clientmgr_t *source, ns_clientmgr_t **targetp); @@ -203,7 +203,7 @@ ns_client_endrequest(ns_client_t *client) dns_cache_clean(client->view->cache, INT_MAX); dns_adb_flush(client->view->adb); } -#endif +#endif /* ifdef ENABLE_AFL */ dns_view_detach(&client->view); } if (client->opt != NULL) { @@ -319,16 +319,20 @@ client_allocsendbuf(ns_client_t *client, isc_buffer_t *buffer, } else { data = client->sendbuf; if ((client->attributes & NS_CLIENTATTR_HAVECOOKIE) == 0) { - if (client->view != NULL) + if (client->view != NULL) { bufsize = client->view->nocookieudp; - else + } else { bufsize = 512; - } else + } + } else { bufsize = client->udpsize; - if (bufsize > client->udpsize) + } + if (bufsize > client->udpsize) { bufsize = client->udpsize; - if (bufsize > NS_CLIENT_SEND_BUFFER_SIZE) + } + if (bufsize > NS_CLIENT_SEND_BUFFER_SIZE) { bufsize = NS_CLIENT_SEND_BUFFER_SIZE; + } if (length > bufsize) { result = ISC_R_NOSPACE; goto done; @@ -374,16 +378,18 @@ ns_client_sendraw(ns_client_t *client, dns_message_t *message) } result = client_allocsendbuf(client, &buffer, NULL, mr->length, &data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } /* * Copy message to buffer and fixup id. */ isc_buffer_availableregion(&buffer, &r); result = isc_buffer_copyregion(&buffer, mr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } r.base[0] = (client->message->id >> 8) & 0xff; r.base[1] = client->message->id & 0xff; @@ -440,26 +446,30 @@ ns_client_send(ns_client_t *client) CTRACE("send"); if (client->message->opcode == dns_opcode_query && - (client->attributes & NS_CLIENTATTR_RA) != 0) + (client->attributes & NS_CLIENTATTR_RA) != 0) { client->message->flags |= DNS_MESSAGEFLAG_RA; + } - if ((client->attributes & NS_CLIENTATTR_WANTDNSSEC) != 0) + if ((client->attributes & NS_CLIENTATTR_WANTDNSSEC) != 0) { render_opts = 0; - else + } else { render_opts = DNS_MESSAGERENDER_OMITDNSSEC; + } preferred_glue = 0; if (client->view != NULL) { - if (client->view->preferred_glue == dns_rdatatype_a) + if (client->view->preferred_glue == dns_rdatatype_a) { preferred_glue = DNS_MESSAGERENDER_PREFER_A; - else if (client->view->preferred_glue == dns_rdatatype_aaaa) + } else if (client->view->preferred_glue == dns_rdatatype_aaaa) { preferred_glue = DNS_MESSAGERENDER_PREFER_AAAA; + } } if (preferred_glue == 0) { - if (isc_sockaddr_pf(&client->peeraddr) == AF_INET) + if (isc_sockaddr_pf(&client->peeraddr) == AF_INET) { preferred_glue = DNS_MESSAGERENDER_PREFER_A; - else + } else { preferred_glue = DNS_MESSAGERENDER_PREFER_AAAA; + } } /* @@ -468,27 +478,31 @@ ns_client_send(ns_client_t *client) if ((client->attributes & NS_CLIENTATTR_WANTOPT) != 0) { result = ns_client_addopt(client, client->message, &client->opt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } } /* * XXXRTH The following doesn't deal with TCP buffer resizing. */ result = client_allocsendbuf(client, &buffer, &tcpbuffer, 0, &data); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } result = dns_compress_init(&cctx, -1, client->mctx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } if (client->peeraddr_valid && client->view != NULL) { isc_netaddr_t netaddr; dns_name_t * name = NULL; isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr); - if (client->message->tsigkey != NULL) + if (client->message->tsigkey != NULL) { name = &client->message->tsigkey->name; + } if (client->view->nocasecompress == NULL || !dns_acl_allowed(&netaddr, name, @@ -503,15 +517,17 @@ ns_client_send(ns_client_t *client) cleanup_cctx = true; result = dns_message_renderbegin(client->message, &cctx, &buffer); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } if (client->opt != NULL) { result = dns_message_setopt(client->message, client->opt); opt_included = true; client->opt = NULL; - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } } result = dns_message_rendersection(client->message, DNS_SECTION_QUESTION, 0); @@ -519,13 +535,15 @@ ns_client_send(ns_client_t *client) client->message->flags |= DNS_MESSAGEFLAG_TC; goto renderend; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } /* * Stop after the question if TC was set for rate limiting. */ - if ((client->message->flags & DNS_MESSAGEFLAG_TC) != 0) + if ((client->message->flags & DNS_MESSAGEFLAG_TC) != 0) { goto renderend; + } result = dns_message_rendersection(client->message, DNS_SECTION_ANSWER, DNS_MESSAGERENDER_PARTIAL | render_opts); @@ -533,8 +551,9 @@ ns_client_send(ns_client_t *client) client->message->flags |= DNS_MESSAGEFLAG_TC; goto renderend; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } result = dns_message_rendersection( client->message, DNS_SECTION_AUTHORITY, DNS_MESSAGERENDER_PARTIAL | render_opts); @@ -542,17 +561,20 @@ ns_client_send(ns_client_t *client) client->message->flags |= DNS_MESSAGEFLAG_TC; goto renderend; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } result = dns_message_rendersection(client->message, DNS_SECTION_ADDITIONAL, preferred_glue | render_opts); - if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE) + if (result != ISC_R_SUCCESS && result != ISC_R_NOSPACE) { goto done; + } renderend: result = dns_message_renderend(client->message); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto done; + } #ifdef HAVE_DNSTAP memset(&zr, 0, sizeof(zr)); @@ -564,8 +586,9 @@ renderend: isc_buffer_init(&b, zone, sizeof(zone)); dns_compress_setmethods(&cctx, DNS_COMPRESS_NONE); result = dns_name_towire(zo, &cctx, &b); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&b, &zr); + } } if (client->message->opcode == dns_opcode_update) { @@ -672,9 +695,10 @@ renderend: ns_stats_increment(client->sctx->nsstats, ns_statscounter_sig0out); } - if ((client->message->flags & DNS_MESSAGEFLAG_TC) != 0) + if ((client->message->flags & DNS_MESSAGEFLAG_TC) != 0) { ns_stats_increment(client->sctx->nsstats, ns_statscounter_truncatedresp); + } if (result == ISC_R_SUCCESS) { return; @@ -687,8 +711,9 @@ done: client->tcpbuf = NULL; } - if (cleanup_cctx) + if (cleanup_cctx) { dns_compress_invalidate(&cctx); + } } #if NS_CLIENT_DROPPORT @@ -718,7 +743,7 @@ ns_client_dropport(in_port_t port) } return (DROPPORT_NO); } -#endif +#endif /* if NS_CLIENT_DROPPORT */ void ns_client_error(ns_client_t *client, isc_result_t result) @@ -759,7 +784,7 @@ ns_client_error(ns_client_t *client, isc_result_t result) ns_client_drop(client, ISC_R_SUCCESS); return; } -#endif +#endif /* if NS_CLIENT_DROPPORT */ /* * Try to rate limit error responses. @@ -872,8 +897,9 @@ ns_client_error(ns_client_t *client, isc_result_t result) isc_interval_t i; uint32_t flags = 0; - if ((message->flags & DNS_MESSAGEFLAG_CD) != 0) + if ((message->flags & DNS_MESSAGEFLAG_CD) != 0) { flags = NS_FAILCACHE_CD; + } isc_interval_set(&i, client->view->fail_ttl, 0); result = isc_time_nowplusinterval(&expire, &i); @@ -912,10 +938,11 @@ ns_client_addopt(ns_client_t *client, dns_message_t *message, env = ns_interfacemgr_getaclenv(client->manager->interface->mgr); view = client->view; resolver = (view != NULL) ? view->resolver : NULL; - if (resolver != NULL) + if (resolver != NULL) { udpsize = dns_resolver_getudpsize(resolver); - else + } else { udpsize = client->sctx->udpsize; + } flags = client->extflags & DNS_MESSAGEEXTFLAG_REPLYPRESERVE; @@ -1017,8 +1044,9 @@ no_nsid: /* address */ if (addrl > 0) { /* Mask off last address byte */ - if ((plen % 8) != 0) + if ((plen % 8) != 0) { addr[addrl - 1] &= ~0U << (8 - (plen % 8)); + } isc_buffer_putmem(&buf, addr, (unsigned)addrl); } @@ -1075,7 +1103,6 @@ compute_cookie(ns_client_t *client, uint32_t when, uint32_t nonce, const unsigned char *secret, isc_buffer_t *buf) { unsigned char digest[ISC_MAX_MD_SIZE] ISC_NONSTRING = { 0 }; - ; STATIC_ASSERT(ISC_MAX_MD_SIZE >= ISC_SIPHASH24_TAG_LENGTH, "You need " "to " "increase " @@ -1204,12 +1231,13 @@ process_cookie(ns_client_t *client, isc_buffer_t *buf, size_t optlen) memmove(client->cookie, isc_buffer_current(buf), 8); isc_buffer_forward(buf, (unsigned int)optlen); - if (optlen == 8U) + if (optlen == 8U) { ns_stats_increment(client->sctx->nsstats, ns_statscounter_cookienew); - else + } else { ns_stats_increment(client->sctx->nsstats, ns_statscounter_cookiebadsize); + } return; } @@ -1366,8 +1394,9 @@ process_ecs(ns_client_t *client, isc_buffer_t *buf, size_t optlen) if ((addrlen % 8) != 0) { uint8_t bits = ~0U << (8 - (addrlen % 8)); bits &= paddr[addrbytes - 1]; - if (bits != paddr[addrbytes - 1]) + if (bits != paddr[addrbytes - 1]) { return (DNS_R_OPTERR); + } } } @@ -1421,8 +1450,9 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) * If the requested UDP buffer size is less than 512, * ignore it and use 512. */ - if (client->udpsize < 512) + if (client->udpsize < 512) { client->udpsize = 512; + } /* * Get the flags out of the OPT record. @@ -1440,8 +1470,9 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) ns_statscounter_badednsver); result = ns_client_addopt(client, client->message, &client->opt); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = DNS_R_BADVERS; + } ns_client_error(client, result); return (result); } @@ -1458,10 +1489,11 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) optlen = isc_buffer_getuint16(&optbuf); switch (optcode) { case DNS_OPT_NSID: - if (!WANTNSID(client)) + if (!WANTNSID(client)) { ns_stats_increment( client->sctx->nsstats, ns_statscounter_nsidopt); + } client->attributes |= NS_CLIENTATTR_WANTNSID; isc_buffer_forward(&optbuf, optlen); break; @@ -1469,10 +1501,11 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) process_cookie(client, &optbuf, optlen); break; case DNS_OPT_EXPIRE: - if (!WANTEXPIRE(client)) + if (!WANTEXPIRE(client)) { ns_stats_increment( client->sctx->nsstats, ns_statscounter_expireopt); + } client->attributes |= NS_CLIENTATTR_WANTEXPIRE; isc_buffer_forward(&optbuf, optlen); break; @@ -1486,10 +1519,11 @@ process_opt(ns_client_t *client, dns_rdataset_t *opt) ns_statscounter_ecsopt); break; case DNS_OPT_TCP_KEEPALIVE: - if (!USEKEEPALIVE(client)) + if (!USEKEEPALIVE(client)) { ns_stats_increment( client->sctx->nsstats, ns_statscounter_keepaliveopt); + } client->attributes |= NS_CLIENTATTR_USEKEEPALIVE; isc_buffer_forward(&optbuf, optlen); @@ -1628,7 +1662,7 @@ ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) dns_aclenv_t * env; #ifdef HAVE_DNSTAP dns_dtmsgtype_t dtmsgtype; -#endif +#endif /* ifdef HAVE_DNSTAP */ ifp = (ns_interface_t *)arg; mgr = ifp->clientmgr; @@ -1704,7 +1738,7 @@ ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) isc_task_unpause(client->task); return; } -#endif +#endif /* if NS_CLIENT_DROPPORT */ ns_client_log(client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(3), "%s request", @@ -1943,10 +1977,11 @@ ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) * If all the attempts fail (this can happen due to memory shortage, * etc), we regard this as an error for safety. */ - if ((client->manager->interface->flags & NS_INTERFACEFLAG_ANYADDR) == 0) + if ((client->manager->interface->flags & NS_INTERFACEFLAG_ANYADDR) == + 0) { isc_netaddr_fromsockaddr(&client->destaddr, &client->manager->interface->addr); - else { + } else { isc_sockaddr_t sockaddr = isc_nmhandle_localaddr(client->handle); isc_netaddr_fromsockaddr(&client->destaddr, &sockaddr); @@ -2125,10 +2160,12 @@ ns__client_request(isc_nmhandle_t *handle, isc_region_t *region, void *arg) uint16_t udpsize = client->view->maxudp; (void)dns_peerlist_peerbyaddr(client->view->peers, &netaddr, &peer); - if (peer != NULL) + if (peer != NULL) { dns_peer_getmaxudp(peer, &udpsize); - if (client->udpsize > udpsize) + } + if (client->udpsize > udpsize) { client->udpsize = udpsize; + } } /* @@ -2201,7 +2238,7 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) isc_mem_t *clientmctx; #if CLIENT_NMCTXS > 0 unsigned int nextmctx; -#endif +#endif /* if CLIENT_NMCTXS > 0 */ MTRACE("clientmctx"); @@ -2211,8 +2248,9 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) nextmctx = isc_nm_tid(); } else { nextmctx = manager->nextmctx++; - if (manager->nextmctx == CLIENT_NMCTXS) + if (manager->nextmctx == CLIENT_NMCTXS) { manager->nextmctx = 0; + } INSIST(nextmctx < CLIENT_NMCTXS); } @@ -2224,9 +2262,9 @@ get_clientmctx(ns_clientmgr_t *manager, isc_mem_t **mctxp) manager->mctxpool[nextmctx] = clientmctx; } UNLOCK(&manager->lock); -#else +#else /* if CLIENT_NMCTXS > 0 */ clientmctx = manager->mctx; -#endif +#endif /* if CLIENT_NMCTXS > 0 */ isc_mem_attach(clientmctx, mctxp); } @@ -2386,7 +2424,7 @@ clientmgr_destroy(ns_clientmgr_t *manager) { #if CLIENT_NMCTXS > 0 int i; -#endif +#endif /* if CLIENT_NMCTXS > 0 */ MTRACE("clientmgr_destroy"); @@ -2395,10 +2433,11 @@ clientmgr_destroy(ns_clientmgr_t *manager) #if CLIENT_NMCTXS > 0 for (i = 0; i < CLIENT_NMCTXS; i++) { - if (manager->mctxpool[i] != NULL) + if (manager->mctxpool[i] != NULL) { isc_mem_detach(&manager->mctxpool[i]); + } } -#endif +#endif /* if CLIENT_NMCTXS > 0 */ if (manager->interface != NULL) { ns_interface_detach(&manager->interface); @@ -2407,8 +2446,9 @@ clientmgr_destroy(ns_clientmgr_t *manager) isc_mutex_destroy(&manager->lock); isc_mutex_destroy(&manager->reclock); - if (manager->excl != NULL) + if (manager->excl != NULL) { isc_task_detach(&manager->excl); + } for (i = 0; i < CLIENT_NTASKS; i++) { if (manager->taskpool[i] != NULL) { @@ -2431,7 +2471,7 @@ ns_clientmgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_taskmgr_t *taskmgr, isc_result_t result; #if CLIENT_NMCTXS > 0 int i; -#endif +#endif /* if CLIENT_NMCTXS > 0 */ manager = isc_mem_get(mctx, sizeof(*manager)); *manager = (ns_clientmgr_t){ .magic = 0 }; @@ -2465,9 +2505,10 @@ ns_clientmgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_taskmgr_t *taskmgr, ISC_LIST_INIT(manager->recursing); #if CLIENT_NMCTXS > 0 manager->nextmctx = 0; - for (i = 0; i < CLIENT_NMCTXS; i++) + for (i = 0; i < CLIENT_NMCTXS; i++) { manager->mctxpool[i] = NULL; /* will be created on-demand */ -#endif + } +#endif /* if CLIENT_NMCTXS > 0 */ manager->magic = MANAGER_MAGIC; MTRACE("create"); @@ -2543,10 +2584,11 @@ ns_client_checkaclsilent(ns_client_t *client, isc_netaddr_t *netaddr, int match; if (acl == NULL) { - if (default_allow) + if (default_allow) { goto allow; - else + } else { goto deny; + } } if (netaddr == NULL) { @@ -2555,11 +2597,13 @@ ns_client_checkaclsilent(ns_client_t *client, isc_netaddr_t *netaddr, } result = dns_acl_match(netaddr, client->signer, acl, env, &match, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto deny; /* Internal error, already logged. */ + } - if (match > 0) + if (match > 0) { goto allow; + } goto deny; /* Negative match or no match. */ allow: @@ -2577,31 +2621,34 @@ ns_client_checkacl(ns_client_t *client, isc_sockaddr_t *sockaddr, isc_result_t result; isc_netaddr_t netaddr; - if (sockaddr != NULL) + if (sockaddr != NULL) { isc_netaddr_fromsockaddr(&netaddr, sockaddr); + } result = ns_client_checkaclsilent(client, sockaddr ? &netaddr : NULL, acl, default_allow); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { ns_client_log(client, DNS_LOGCATEGORY_SECURITY, NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(3), "%s approved", opname); - else + } else { ns_client_log(client, DNS_LOGCATEGORY_SECURITY, NS_LOGMODULE_CLIENT, log_level, "%s denied", opname); + } return (result); } static void ns_client_name(ns_client_t *client, char *peerbuf, size_t len) { - if (client->peeraddr_valid) + if (client->peeraddr_valid) { isc_sockaddr_format(&client->peeraddr, peerbuf, (unsigned int)len); - else + } else { snprintf(peerbuf, len, "@%p", client); + } } void @@ -2659,8 +2706,9 @@ ns_client_log(ns_client_t *client, isc_logcategory_t *category, { va_list ap; - if (!isc_log_wouldlog(ns_lctx, level)) + if (!isc_log_wouldlog(ns_lctx, level)) { return; + } va_start(ap, fmt); ns_client_logv(client, category, module, level, fmt, ap); @@ -2690,8 +2738,9 @@ ns_client_dumpmessage(ns_client_t *client, const char *reason) int len = 1024; isc_result_t result; - if (!isc_log_wouldlog(ns_lctx, ISC_LOG_DEBUG(1))) + if (!isc_log_wouldlog(ns_lctx, ISC_LOG_DEBUG(1))) { return; + } /* * Note that these are multiline debug messages. We want a newline @@ -2706,15 +2755,17 @@ ns_client_dumpmessage(ns_client_t *client, const char *reason) if (result == ISC_R_NOSPACE) { isc_mem_put(client->mctx, buf, len); len += 1024; - } else if (result == ISC_R_SUCCESS) + } else if (result == ISC_R_SUCCESS) { ns_client_log(client, NS_LOGCATEGORY_CLIENT, NS_LOGMODULE_CLIENT, ISC_LOG_DEBUG(1), "%s\n%.*s", reason, (int)isc_buffer_usedlength(&buffer), buf); + } } while (result == ISC_R_NOSPACE); - if (buf != NULL) + if (buf != NULL) { isc_mem_put(client->mctx, buf, len); + } } void @@ -2762,8 +2813,9 @@ ns_client_dumprecursing(FILE *f, ns_clientmgr_t *manager) original[0] = '\0'; } rdataset = ISC_LIST_HEAD(client->query.qname->list); - if (rdataset == NULL && client->query.origqname != NULL) + if (rdataset == NULL && client->query.origqname != NULL) { rdataset = ISC_LIST_HEAD(client->query.origqname->list); + } if (rdataset != NULL) { dns_rdatatype_format(rdataset->type, typebuf, sizeof(typebuf)); diff --git a/lib/ns/hooks.c b/lib/ns/hooks.c index 96675dcc8b..9d3bf09ad2 100644 --- a/lib/ns/hooks.c +++ b/lib/ns/hooks.c @@ -19,7 +19,7 @@ #include #elif _WIN32 #include -#endif +#endif /* if HAVE_DLFCN_H */ #include #include @@ -80,12 +80,12 @@ ns_plugin_expandpath(const char *src, char *dst, size_t dstsize) */ result = snprintf(dst, dstsize, "%s/%s", NAMED_PLUGINDIR, src); } -#else +#else /* ifndef WIN32 */ /* * On Windows, always copy 'src' do 'dst'. */ result = snprintf(dst, dstsize, "%s", src); -#endif +#endif /* ifndef WIN32 */ if (result < 0) { return (isc_errno_toresult(errno)); @@ -150,7 +150,7 @@ load_plugin(isc_mem_t *mctx, const char *modpath, ns_plugin_t **pluginp) flags = RTLD_LAZY | RTLD_LOCAL; #if defined(RTLD_DEEPBIND) && !__SANITIZE_ADDRESS__ flags |= RTLD_DEEPBIND; -#endif +#endif /* if defined(RTLD_DEEPBIND) && !__SANITIZE_ADDRESS__ */ handle = dlopen(modpath, flags); if (handle == NULL) { diff --git a/lib/ns/include/ns/client.h b/lib/ns/include/ns/client.h index c1dfe9be04..78b1475a31 100644 --- a/lib/ns/include/ns/client.h +++ b/lib/ns/include/ns/client.h @@ -13,8 +13,8 @@ #define NS_CLIENT_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief @@ -184,7 +184,7 @@ struct ns_clientmgr { /*%< mctx pool for clients. */ unsigned int nextmctx; isc_mem_t * mctxpool[CLIENT_NMCTXS]; -#endif +#endif /* if CLIENT_NMCTXS > 0 */ }; /*% nameserver client structure */ @@ -297,9 +297,9 @@ struct ns_client { #if defined(_WIN32) && !defined(_WIN64) LIBNS_EXTERNAL_DATA extern atomic_uint_fast32_t ns_client_requests; -#else +#else /* if defined(_WIN32) && !defined(_WIN64) */ LIBNS_EXTERNAL_DATA extern atomic_uint_fast64_t ns_client_requests; -#endif +#endif /* if defined(_WIN32) && !defined(_WIN64) */ /*** *** Functions diff --git a/lib/ns/include/ns/hooks.h b/lib/ns/include/ns/hooks.h index bd8bef0917..9dd808794f 100644 --- a/lib/ns/include/ns/hooks.h +++ b/lib/ns/include/ns/hooks.h @@ -260,7 +260,7 @@ LIBNS_EXTERNAL_DATA extern ns_hooktable_t *ns__hook_table; #ifndef NS_PLUGIN_VERSION #define NS_PLUGIN_VERSION 1 #define NS_PLUGIN_AGE 0 -#endif +#endif /* ifndef NS_PLUGIN_VERSION */ typedef isc_result_t ns_plugin_register_t(const char *parameters, const void *cfg, const char *file, diff --git a/lib/ns/include/ns/interfacemgr.h b/lib/ns/include/ns/interfacemgr.h index 368e354a61..962978e8fe 100644 --- a/lib/ns/include/ns/interfacemgr.h +++ b/lib/ns/include/ns/interfacemgr.h @@ -13,8 +13,8 @@ #define NS_INTERFACEMGR_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief @@ -64,7 +64,7 @@ #define NS_INTERFACEFLAG_ANYADDR 0x01U /*%< bound to "any" address */ #define MAX_UDP_DISPATCH \ 128 /*%< Maximum number of UDP dispatchers \ - to start per interface */ + * to start per interface */ /*% The nameserver interface structure */ struct ns_interface { unsigned int magic; /*%< Magic number. */ @@ -82,13 +82,13 @@ struct ns_interface { isc_nmsocket_t *tcplistensocket; isc_dscp_t dscp; /*%< "listen-on" DSCP value */ isc_refcount_t ntcpaccepting; /*%< Number of clients - ready to accept new - TCP connections on this - interface */ + * ready to accept new + * TCP connections on this + * interface */ isc_refcount_t ntcpactive; /*%< Number of clients - servicing TCP queries - (whether accepting or - connected) */ + * servicing TCP queries + * (whether accepting or + * connected) */ int nudpdispatch; /*%< Number of UDP dispatches */ ns_clientmgr_t *clientmgr; /*%< Client manager. */ ISC_LINK(ns_interface_t) link; diff --git a/lib/ns/include/ns/listenlist.h b/lib/ns/include/ns/listenlist.h index 23d8e7f0b3..ad19c58874 100644 --- a/lib/ns/include/ns/listenlist.h +++ b/lib/ns/include/ns/listenlist.h @@ -13,8 +13,8 @@ #define NS_LISTENLIST_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief diff --git a/lib/ns/include/ns/update.h b/lib/ns/include/ns/update.h index beb4fc748f..e3372c9a08 100644 --- a/lib/ns/include/ns/update.h +++ b/lib/ns/include/ns/update.h @@ -13,8 +13,8 @@ #define NS_UPDATE_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief diff --git a/lib/ns/include/ns/xfrout.h b/lib/ns/include/ns/xfrout.h index 1dd31d8549..2a7775f735 100644 --- a/lib/ns/include/ns/xfrout.h +++ b/lib/ns/include/ns/xfrout.h @@ -13,8 +13,8 @@ #define NS_XFROUT_H 1 /***** - ***** Module Info - *****/ +***** Module Info +*****/ /*! \file * \brief diff --git a/lib/ns/interfacemgr.c b/lib/ns/interfacemgr.c index 873e9cfe01..f66402fb54 100644 --- a/lib/ns/interfacemgr.c +++ b/lib/ns/interfacemgr.c @@ -37,8 +37,9 @@ #define ROUTE_SOCKET_PROTOCOL PF_ROUTE #define MSGHDR rt_msghdr #define MSGTYPE rtm_type -#endif -#endif +#endif /* if defined(RTM_VERSION) && defined(RTM_NEWADDR) && \ + * defined(RTM_DELADDR) */ +#endif /* ifdef HAVE_NET_ROUTE_H */ #if defined(HAVE_LINUX_NETLINK_H) && defined(HAVE_LINUX_RTNETLINK_H) #include @@ -48,12 +49,13 @@ #define ROUTE_SOCKET_PROTOCOL PF_NETLINK #define MSGHDR nlmsghdr #define MSGTYPE nlmsg_type -#endif -#endif +#endif /* if defined(RTM_NEWADDR) && defined(RTM_DELADDR) */ +#endif /* if defined(HAVE_LINUX_NETLINK_H) && defined(HAVE_LINUX_RTNETLINK_H) \ + */ #ifdef TUNE_LARGE #define UDPBUFFERS 32768 -#else +#else /* ifdef TUNE_LARGE */ #define UDPBUFFERS 1000 #endif /* TUNE_LARGE */ @@ -84,12 +86,13 @@ struct ns_interfacemgr { ISC_LIST(isc_sockaddr_t) listenon; int backlog; /*%< Listen queue size */ unsigned int udpdisp; /*%< UDP dispatch count */ - atomic_bool shuttingdown; /*%< Interfacemgr is shutting down */ + atomic_bool shuttingdown; /*%< Interfacemgr is shutting + * down */ #ifdef USE_ROUTE_SOCKET isc_task_t * task; isc_socket_t *route; unsigned char buf[2048]; -#endif +#endif /* ifdef USE_ROUTE_SOCKET */ }; static void @@ -116,11 +119,12 @@ route_event(isc_task_t *task, isc_event_t *event) sevent = (isc_socketevent_t *)event; if (sevent->result != ISC_R_SUCCESS) { - if (sevent->result != ISC_R_CANCELED) + if (sevent->result != ISC_R_CANCELED) { isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR, "automatic interface scanning " "terminated: %s", isc_result_totext(sevent->result)); + } ns_interfacemgr_detach(&mgr); isc_event_free(&event); return; @@ -138,13 +142,14 @@ route_event(isc_task_t *task, isc_event_t *event) isc_event_free(&event); return; } -#endif +#endif /* ifdef RTM_VERSION */ switch (rtm->MSGTYPE) { case RTM_NEWADDR: case RTM_DELADDR: - if (mgr->route != NULL && mgr->sctx->interface_auto) + if (mgr->route != NULL && mgr->sctx->interface_auto) { ns_interfacemgr_scan(mgr, false); + } break; default: break; @@ -159,17 +164,19 @@ route_event(isc_task_t *task, isc_event_t *event) r.length = sizeof(mgr->buf); result = isc_socket_recv(mgr->route, &r, 1, mgr->task, route_event, mgr); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { done = false; + } } UNLOCK(&mgr->lock); - if (done) + if (done) { ns_interfacemgr_detach(&mgr); + } isc_event_free(&event); return; } -#endif +#endif /* ifdef USE_ROUTE_SOCKET */ isc_result_t ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, @@ -184,7 +191,7 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, #ifndef USE_ROUTE_SOCKET UNUSED(task); -#endif +#endif /* ifndef USE_ROUTE_SOCKET */ REQUIRE(mctx != NULL); REQUIRE(mgrp != NULL); @@ -224,18 +231,20 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, * The listen-on lists are initially empty. */ result = ns_listenlist_create(mctx, &mgr->listenon4); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_ctx; + } ns_listenlist_attach(mgr->listenon4, &mgr->listenon6); result = dns_aclenv_init(mctx, &mgr->aclenv); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_listenon; + } #if defined(HAVE_GEOIP2) mgr->aclenv.geoip = geoip; -#else +#else /* if defined(HAVE_GEOIP2) */ UNUSED(geoip); -#endif +#endif /* if defined(HAVE_GEOIP2) */ #ifdef USE_ROUTE_SOCKET mgr->route = NULL; @@ -256,9 +265,9 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, isc_task_attach(task, &mgr->task); } isc_refcount_init(&mgr->references, (mgr->route != NULL) ? 2 : 1); -#else +#else /* ifdef USE_ROUTE_SOCKET */ isc_refcount_init(&mgr->references, 1); -#endif +#endif /* ifdef USE_ROUTE_SOCKET */ mgr->magic = IFMGR_MAGIC; *mgrp = mgr; @@ -274,13 +283,13 @@ ns_interfacemgr_create(isc_mem_t *mctx, ns_server_t *sctx, ns_interfacemgr_detach(&mgr); } } -#endif +#endif /* ifdef USE_ROUTE_SOCKET */ return (ISC_R_SUCCESS); #ifdef USE_ROUTE_SOCKET cleanup_aclenv: dns_aclenv_destroy(&mgr->aclenv); -#endif +#endif /* ifdef USE_ROUTE_SOCKET */ cleanup_listenon: ns_listenlist_detach(&mgr->listenon4); ns_listenlist_detach(&mgr->listenon6); @@ -300,20 +309,24 @@ ns_interfacemgr_destroy(ns_interfacemgr_t *mgr) isc_refcount_destroy(&mgr->references); #ifdef USE_ROUTE_SOCKET - if (mgr->route != NULL) + if (mgr->route != NULL) { isc_socket_detach(&mgr->route); - if (mgr->task != NULL) + } + if (mgr->task != NULL) { isc_task_detach(&mgr->task); -#endif + } +#endif /* ifdef USE_ROUTE_SOCKET */ dns_aclenv_destroy(&mgr->aclenv); ns_listenlist_detach(&mgr->listenon4); ns_listenlist_detach(&mgr->listenon6); clearlistenon(mgr); isc_mutex_destroy(&mgr->lock); - if (mgr->sctx != NULL) + if (mgr->sctx != NULL) { ns_server_detach(&mgr->sctx); - if (mgr->excl != NULL) + } + if (mgr->excl != NULL) { isc_task_detach(&mgr->excl); + } mgr->magic = 0; isc_mem_putanddetach(&mgr->mctx, mgr, sizeof(*mgr)); } @@ -375,7 +388,7 @@ ns_interfacemgr_shutdown(ns_interfacemgr_t *mgr) isc_task_detach(&mgr->task); } UNLOCK(&mgr->lock); -#endif +#endif /* ifdef USE_ROUTE_SOCKET */ purge_old_interfaces(mgr); } @@ -480,14 +493,15 @@ ns_interface_listentcp(ns_interface_t *ifp) #if 0 #ifndef ISC_ALLOW_MAPPED - isc_socket_ipv6only(ifp->tcpsocket, true); -#endif + isc_socket_ipv6only(ifp->tcpsocket,true); +#endif /* ifndef ISC_ALLOW_MAPPED */ - if (ifp->dscp != -1) - isc_socket_dscp(ifp->tcpsocket, ifp->dscp); + if (ifp->dscp != -1) { + isc_socket_dscp(ifp->tcpsocket,ifp->dscp); + } - (void)isc_socket_filter(ifp->tcpsocket, "dataready"); -#endif + (void)isc_socket_filter(ifp->tcpsocket,"dataready"); +#endif /* if 0 */ return (result); } @@ -502,15 +516,17 @@ ns_interface_setup(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr, REQUIRE(addr_in_use == NULL || *addr_in_use == false); result = ns_interface_create(mgr, addr, name, &ifp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } ifp->dscp = dscp; result = ns_interface_listenudp(ifp); if (result != ISC_R_SUCCESS) { - if ((result == ISC_R_ADDRINUSE) && (addr_in_use != NULL)) + if ((result == ISC_R_ADDRINUSE) && (addr_in_use != NULL)) { *addr_in_use = true; + } goto cleanup_interface; } @@ -519,8 +535,9 @@ ns_interface_setup(ns_interfacemgr_t *mgr, isc_sockaddr_t *addr, result = ns_interface_listentcp(ifp); if (result != ISC_R_SUCCESS) { if ((result == ISC_R_ADDRINUSE) && - (addr_in_use != NULL)) + (addr_in_use != NULL)) { *addr_in_use = true; + } /* * XXXRTH We don't currently have a way to easily stop @@ -661,8 +678,9 @@ clearacl(isc_mem_t *mctx, dns_acl_t **aclp) dns_acl_t * newacl = NULL; isc_result_t result; result = dns_acl_create(mctx, 0, &newacl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_acl_detach(aclp); dns_acl_attach(newacl, aclp); dns_acl_detach(&newacl); @@ -673,7 +691,7 @@ static bool listenon_is_ip6_any(ns_listenelt_t *elt) { REQUIRE(elt && elt->acl); - return dns_acl_isany(elt->acl); + return (dns_acl_isany(elt->acl)); } static isc_result_t @@ -689,15 +707,17 @@ setup_locals(ns_interfacemgr_t *mgr, isc_interface_t *interface) prefixlen = (netaddr->family == AF_INET) ? 32 : 128; result = dns_iptable_addprefix(mgr->aclenv.localhost->iptable, netaddr, prefixlen, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* Then add localnets prefix */ result = isc_netaddr_masktoprefixlen(&interface->netmask, &prefixlen); /* Non contiguous netmasks not allowed by IPv6 arch. */ - if (result != ISC_R_SUCCESS && netaddr->family == AF_INET6) + if (result != ISC_R_SUCCESS && netaddr->family == AF_INET6) { return (result); + } if (result != ISC_R_SUCCESS) { isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_WARNING, @@ -718,8 +738,9 @@ setup_locals(ns_interfacemgr_t *mgr, isc_interface_t *interface) result = dns_iptable_addprefix(mgr->aclenv.localnets->iptable, netaddr, prefixlen, true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (ISC_R_SUCCESS); } @@ -786,37 +807,40 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) bool tried_listening; bool all_addresses_in_use; - if (ext_listen != NULL) + if (ext_listen != NULL) { adjusting = true; + } - if (isc_net_probeipv6() == ISC_R_SUCCESS) + if (isc_net_probeipv6() == ISC_R_SUCCESS) { scan_ipv6 = true; - else if ((mgr->sctx->options & NS_SERVER_DISABLE6) == 0) + } else if ((mgr->sctx->options & NS_SERVER_DISABLE6) == 0) { isc_log_write(IFMGR_COMMON_LOGARGS, verbose ? ISC_LOG_INFO : ISC_LOG_DEBUG(1), "no IPv6 interfaces found"); + } - if (isc_net_probeipv4() == ISC_R_SUCCESS) + if (isc_net_probeipv4() == ISC_R_SUCCESS) { scan_ipv4 = true; - else if ((mgr->sctx->options & NS_SERVER_DISABLE4) == 0) + } else if ((mgr->sctx->options & NS_SERVER_DISABLE4) == 0) { isc_log_write(IFMGR_COMMON_LOGARGS, verbose ? ISC_LOG_INFO : ISC_LOG_DEBUG(1), "no IPv4 interfaces found"); + } - /* - * A special, but typical case; listen-on-v6 { any; }. - * When we can make the socket IPv6-only, open a single wildcard - * socket for IPv6 communication. Otherwise, make separate - * socket for each IPv6 address in order to avoid accepting IPv4 - * packets as the form of mapped addresses unintentionally - * unless explicitly allowed. - */ + /* + * A special, but typical case; listen-on-v6 { any; }. + * When we can make the socket IPv6-only, open a single wildcard + * socket for IPv6 communication. Otherwise, make separate + * socket for each IPv6 address in order to avoid accepting IPv4 + * packets as the form of mapped addresses unintentionally + * unless explicitly allowed. + */ #ifndef ISC_ALLOW_MAPPED if (scan_ipv6 == true && isc_net_probe_ipv6only() != ISC_R_SUCCESS) { ipv6only = false; log_explicit = true; } -#endif +#endif /* ifndef ISC_ALLOW_MAPPED */ if (scan_ipv6 == true && isc_net_probe_ipv6pktinfo() != ISC_R_SUCCESS) { ipv6pktinfo = false; log_explicit = true; @@ -826,8 +850,9 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) le = ISC_LIST_NEXT(le, link)) { struct in6_addr in6a; - if (!listenon_is_ip6_any(le)) + if (!listenon_is_ip6_any(le)) { continue; + } in6a = in6addr_any; isc_sockaddr_fromin6(&listen_addr, &in6a, le->port); @@ -835,9 +860,9 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) ifp = find_matching_interface(mgr, &listen_addr); if (ifp != NULL) { ifp->generation = mgr->generation; - if (le->dscp != -1 && ifp->dscp == -1) + if (le->dscp != -1 && ifp->dscp == -1) { ifp->dscp = le->dscp; - else if (le->dscp != ifp->dscp) { + } else if (le->dscp != ifp->dscp) { isc_sockaddr_format(&listen_addr, sabuf, sizeof(sabuf)); isc_log_write(IFMGR_COMMON_LOGARGS, @@ -855,13 +880,14 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) result = ns_interface_setup(mgr, &listen_addr, "", &ifp, true, le->dscp, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { ifp->flags |= NS_INTERFACEFLAG_ANYADDR; - else + } else { isc_log_write(IFMGR_COMMON_LOGARGS, ISC_LOG_ERROR, "listening on all IPv6 " "interfaces failed"); + } /* Continue. */ } } @@ -871,16 +897,19 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) isc_netaddr_any6(&zero_address6); result = isc_interfaceiter_create(mgr->mctx, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (adjusting == false) { result = clearacl(mgr->mctx, &mgr->aclenv.localhost); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iter; + } result = clearacl(mgr->mctx, &mgr->aclenv.localnets); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iter; + } clearlistenon(mgr); } @@ -893,16 +922,20 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) unsigned int family; result = isc_interfaceiter_current(iter, &interface); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } family = interface.address.family; - if (family != AF_INET && family != AF_INET6) + if (family != AF_INET && family != AF_INET6) { continue; - if (scan_ipv4 == false && family == AF_INET) + } + if (scan_ipv4 == false && family == AF_INET) { continue; - if (scan_ipv6 == false && family == AF_INET6) + } + if (scan_ipv6 == false && family == AF_INET6) { continue; + } /* * Test for the address being nonzero rather than testing @@ -932,8 +965,9 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) } result = setup_locals(mgr, &interface); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto ignore_interface; + } } listenon: @@ -983,8 +1017,9 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) * special considerations later, so remember it. */ if (family == AF_INET6 && ipv6only && ipv6pktinfo && - listenon_is_ip6_any(le)) + listenon_is_ip6_any(le)) { ipv6_wildcard = true; + } /* * When adjusting interfaces with extra a listening @@ -1011,16 +1046,17 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) match = 0; } } - if (ipv6_wildcard == true && match == 0) + if (ipv6_wildcard == true && match == 0) { continue; + } } ifp = find_matching_interface(mgr, &listen_sockaddr); if (ifp != NULL) { ifp->generation = mgr->generation; - if (le->dscp != -1 && ifp->dscp == -1) + if (le->dscp != -1 && ifp->dscp == -1) { ifp->dscp = le->dscp; - else if (le->dscp != ifp->dscp) { + } else if (le->dscp != ifp->dscp) { isc_sockaddr_format(&listen_sockaddr, sabuf, sizeof(sabuf)); @@ -1033,8 +1069,10 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) } else { bool addr_in_use = false; - if (adjusting == false && ipv6_wildcard == true) + if (adjusting == false && + ipv6_wildcard == true) { continue; + } if (log_explicit && family == AF_INET6 && !adjusting && listenon_is_ip6_any(le)) { @@ -1067,8 +1105,9 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) le->dscp, &addr_in_use); tried_listening = true; - if (!addr_in_use) + if (!addr_in_use) { all_addresses_in_use = false; + } if (result != ISC_R_SUCCESS) { isc_log_write(IFMGR_COMMON_LOGARGS, @@ -1095,14 +1134,15 @@ do_scan(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, bool verbose) interface.name, isc_result_totext(result)); continue; } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { UNEXPECTED_ERROR(__FILE__, __LINE__, "interface iteration failed: %s", isc_result_totext(result)); - else + } else { result = ((tried_listening && all_addresses_in_use) ? ISC_R_ADDRINUSE : ISC_R_SUCCESS); + } cleanup_iter: isc_interfaceiter_destroy(&iter); return (result); @@ -1120,8 +1160,9 @@ ns_interfacemgr_scan0(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, mgr->generation++; /* Increment the generation count. */ result = do_scan(mgr, ext_listen, verbose); - if ((result != ISC_R_SUCCESS) && (result != ISC_R_ADDRINUSE)) + if ((result != ISC_R_SUCCESS) && (result != ISC_R_ADDRINUSE)) { purge = false; + } /* * Now go through the interface list and delete anything that @@ -1129,8 +1170,9 @@ ns_interfacemgr_scan0(ns_interfacemgr_t *mgr, ns_listenlist_t *ext_listen, * how we catch interfaces that go away or change their * addresses. */ - if (purge) + if (purge) { purge_old_interfaces(mgr); + } /* * Warn if we are not listening on any interface. @@ -1163,13 +1205,15 @@ ns_interfacemgr_scan(ns_interfacemgr_t *mgr, bool verbose) * lock now will we need to relinquish it later. */ result = isc_task_beginexclusive(mgr->excl); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { unlock = true; + } result = ns_interfacemgr_scan0(mgr, NULL, verbose); - if (unlock) + if (unlock) { isc_task_endexclusive(mgr->excl); + } return (result); } @@ -1213,8 +1257,9 @@ ns_interfacemgr_dumprecursing(FILE *f, ns_interfacemgr_t *mgr) LOCK(&mgr->lock); interface = ISC_LIST_HEAD(mgr->interfaces); while (interface != NULL) { - if (interface->clientmgr != NULL) + if (interface->clientmgr != NULL) { ns_client_dumprecursing(f, interface->clientmgr); + } interface = ISC_LIST_NEXT(interface, link); } UNLOCK(&mgr->lock); diff --git a/lib/ns/lib.c b/lib/ns/lib.c index 0183df19e7..63d7158839 100644 --- a/lib/ns/lib.c +++ b/lib/ns/lib.c @@ -62,11 +62,13 @@ ns_lib_init(void) * abort, on any failure. */ result = isc_once_do(&init_once, initialize); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } - if (!initialize_done) + if (!initialize_done) { return (ISC_R_FAILURE); + } isc_refcount_increment0(&references); diff --git a/lib/ns/listenlist.c b/lib/ns/listenlist.c index 8b273f0cae..3e11f925d3 100644 --- a/lib/ns/listenlist.c +++ b/lib/ns/listenlist.c @@ -42,8 +42,9 @@ ns_listenelt_create(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp, void ns_listenelt_destroy(ns_listenelt_t *elt) { - if (elt->acl != NULL) + if (elt->acl != NULL) { dns_acl_detach(&elt->acl); + } isc_mem_put(elt->mctx, elt, sizeof(*elt)); } @@ -86,8 +87,9 @@ ns_listenlist_detach(ns_listenlist_t **listp) *listp = NULL; INSIST(list->refcount > 0); list->refcount--; - if (list->refcount == 0) + if (list->refcount == 0) { destroy(list); + } } isc_result_t @@ -100,20 +102,24 @@ ns_listenlist_default(isc_mem_t *mctx, in_port_t port, isc_dscp_t dscp, ns_listenlist_t *list = NULL; REQUIRE(target != NULL && *target == NULL); - if (enabled) + if (enabled) { result = dns_acl_any(mctx, &acl); - else + } else { result = dns_acl_none(mctx, &acl); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = ns_listenelt_create(mctx, port, dscp, acl, &elt); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_acl; + } result = ns_listenlist_create(mctx, &list); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_listenelt; + } ISC_LIST_APPEND(list->elts, elt, link); diff --git a/lib/ns/log.c b/lib/ns/log.c index 3fa90130c3..882a159ea3 100644 --- a/lib/ns/log.c +++ b/lib/ns/log.c @@ -18,7 +18,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 diff --git a/lib/ns/notify.c b/lib/ns/notify.c index 1e51a7f672..e6df2e991a 100644 --- a/lib/ns/notify.c +++ b/lib/ns/notify.c @@ -51,18 +51,20 @@ respond(ns_client_t *client, isc_result_t result) rcode = dns_result_torcode(result); msg_result = dns_message_reply(message, true); - if (msg_result != ISC_R_SUCCESS) + if (msg_result != ISC_R_SUCCESS) { msg_result = dns_message_reply(message, false); + } if (msg_result != ISC_R_SUCCESS) { ns_client_drop(client, msg_result); isc_nmhandle_unref(client->handle); return; } message->rcode = rcode; - if (rcode == dns_rcode_noerror) + if (rcode == dns_rcode_noerror) { message->flags |= DNS_MESSAGEFLAG_AA; - else + } else { message->flags &= ~DNS_MESSAGEFLAG_AA; + } ns_client_send(client); isc_nmhandle_unref(client->handle); @@ -135,8 +137,9 @@ ns_notify_start(ns_client_t *client) snprintf(tsigbuf, sizeof(tsigbuf), ": TSIG '%s'", namebuf); } - } else + } else { tsigbuf[0] = '\0'; + } dns_name_format(zonename, namebuf, sizeof(namebuf)); result = dns_zt_find(client->view->zonetable, zonename, 0, NULL, &zone); @@ -164,7 +167,8 @@ ns_notify_start(ns_client_t *client) result = DNS_R_NOTAUTH; done: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } respond(client, result); } diff --git a/lib/ns/query.c b/lib/ns/query.c index 7bffe0b8df..ce7ed42e46 100644 --- a/lib/ns/query.c +++ b/lib/ns/query.c @@ -77,7 +77,7 @@ * excluded addresses has a negative impact on those uses. */ #define dns64_bis_return_excluded_addresses 1 -#endif +#endif /* if 0 */ /*% * Maximum number of chained queries before we give up @@ -168,7 +168,7 @@ client_trace(ns_client_t *client, int level, const char *message) } #define CTRACE(l, m) client_trace(client, l, m) #define CCTRACE(l, m) client_trace(qctx->client, l, m) -#else +#else /* ifdef WANT_QUERYTRACE */ #define CTRACE(l, m) ((void)m) #define CCTRACE(l, m) ((void)m) #endif /* WANT_QUERYTRACE */ @@ -494,14 +494,16 @@ inc_stats(ns_client_t *client, isc_statscounter_t counter) ns_stats_increment(client->sctx->nsstats, counter); - if (zone == NULL) + if (zone == NULL) { return; + } /* Do regular response type stats */ zonestats = dns_zone_getrequeststats(zone); - if (zonestats != NULL) + if (zonestats != NULL) { isc_stats_increment(zonestats, counter); + } /* Do query type statistics * @@ -525,26 +527,30 @@ query_send(ns_client_t *client) { isc_statscounter_t counter; - if ((client->message->flags & DNS_MESSAGEFLAG_AA) == 0) + if ((client->message->flags & DNS_MESSAGEFLAG_AA) == 0) { inc_stats(client, ns_statscounter_nonauthans); - else + } else { inc_stats(client, ns_statscounter_authans); + } if (client->message->rcode == dns_rcode_noerror) { dns_section_t answer = DNS_SECTION_ANSWER; if (ISC_LIST_EMPTY(client->message->sections[answer])) { - if (client->query.isreferral) + if (client->query.isreferral) { counter = ns_statscounter_referral; - else + } else { counter = ns_statscounter_nxrrset; - } else + } + } else { counter = ns_statscounter_success; - } else if (client->message->rcode == dns_rcode_nxdomain) + } + } else if (client->message->rcode == dns_rcode_nxdomain) { counter = ns_statscounter_nxdomain; - else if (client->message->rcode == dns_rcode_badcookie) + } else if (client->message->rcode == dns_rcode_badcookie) { counter = ns_statscounter_badcookie; - else /* We end up here in case of YXDOMAIN, and maybe others */ + } else { /* We end up here in case of YXDOMAIN, and maybe others */ counter = ns_statscounter_failure; + } inc_stats(client, counter); ns_client_send(client); @@ -569,8 +575,9 @@ query_error(ns_client_t *client, isc_result_t result, int line) break; } - if ((client->sctx->options & NS_SERVER_LOGQUERIES) != 0) + if ((client->sctx->options & NS_SERVER_LOGQUERIES) != 0) { loglevel = ISC_LOG_INFO; + } log_queryerror(client, result, line, loglevel); @@ -658,15 +665,19 @@ query_reset(ns_client_t *client, bool everything) } ISC_LIST_INIT(client->query.activeversions); - if (client->query.authdb != NULL) + if (client->query.authdb != NULL) { dns_db_detach(&client->query.authdb); - if (client->query.authzone != NULL) + } + if (client->query.authzone != NULL) { dns_zone_detach(&client->query.authzone); + } - if (client->query.dns64_aaaa != NULL) + if (client->query.dns64_aaaa != NULL) { ns_client_putrdataset(client, &client->query.dns64_aaaa); - if (client->query.dns64_sigaaaa != NULL) + } + if (client->query.dns64_sigaaaa != NULL) { ns_client_putrdataset(client, &client->query.dns64_sigaaaa); + } if (client->query.dns64_aaaaok != NULL) { isc_mem_put(client->mctx, client->query.dns64_aaaaok, client->query.dns64_aaaaoklen * sizeof(bool)); @@ -677,13 +688,15 @@ query_reset(ns_client_t *client, bool everything) ns_client_putrdataset(client, &client->query.redirect.rdataset); ns_client_putrdataset(client, &client->query.redirect.sigrdataset); if (client->query.redirect.db != NULL) { - if (client->query.redirect.node != NULL) + if (client->query.redirect.node != NULL) { dns_db_detachnode(client->query.redirect.db, &client->query.redirect.node); + } dns_db_detach(&client->query.redirect.db); } - if (client->query.redirect.zone != NULL) + if (client->query.redirect.zone != NULL) { dns_zone_detach(&client->query.redirect.zone); + } query_freefreeversions(client, everything); @@ -837,7 +850,7 @@ query_checkcacheaccess(ns_client_t *client, const dns_name_t *name, result = ns_client_checkaclsilent( client, &client->destaddr, client->view->cacheonacl, true); - }; + } if (result == ISC_R_SUCCESS) { /* * We were allowed by the "allow-query-cache" ACL. @@ -939,11 +952,13 @@ query_validatezonedb(ns_client_t *client, const dns_name_t *name, return (DNS_R_SERVFAIL); } - if ((options & DNS_GETDB_IGNOREACL) != 0) + if ((options & DNS_GETDB_IGNOREACL) != 0) { goto approved; + } if (dbversion->acl_checked) { - if (!dbversion->queryok) + if (!dbversion->queryok) { return (DNS_R_REFUSED); + } goto approved; } @@ -1011,15 +1026,18 @@ query_validatezonedb(ns_client_t *client, const dns_name_t *name, /* If and only if we've gotten this far, check allow-query-on too */ if (result == ISC_R_SUCCESS) { queryonacl = dns_zone_getqueryonacl(zone); - if (queryonacl == NULL) + if (queryonacl == NULL) { queryonacl = client->view->queryonacl; + } result = ns_client_checkaclsilent(client, &client->destaddr, queryonacl, true); - if ((options & DNS_GETDB_NOLOG) == 0 && result != ISC_R_SUCCESS) + if ((options & DNS_GETDB_NOLOG) == 0 && + result != ISC_R_SUCCESS) { ns_client_log(client, DNS_LOGCATEGORY_SECURITY, NS_LOGMODULE_QUERY, ISC_LOG_INFO, "query-on denied"); + } } dbversion->acl_checked = true; @@ -1031,8 +1049,9 @@ query_validatezonedb(ns_client_t *client, const dns_name_t *name, approved: /* Transfer ownership, if necessary. */ - if (versionp != NULL) + if (versionp != NULL) { *versionp = dbversion->version; + } return (ISC_R_SUCCESS); } @@ -1061,33 +1080,40 @@ query_getzonedb(ns_client_t *client, const dns_name_t *name, result = dns_zt_find(client->view->zonetable, name, ztoptions, NULL, &zone); - if (result == DNS_R_PARTIALMATCH) + if (result == DNS_R_PARTIALMATCH) { partial = true; - if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) + } + if (result == ISC_R_SUCCESS || result == DNS_R_PARTIALMATCH) { result = dns_zone_getdb(zone, &db); + } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = query_validatezonedb(client, name, qtype, options, zone, db, versionp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } /* Transfer ownership. */ *zonep = zone; *dbp = db; - if (partial && (options & DNS_GETDB_PARTIAL) != 0) + if (partial && (options & DNS_GETDB_PARTIAL) != 0) { return (DNS_R_PARTIALMATCH); + } return (ISC_R_SUCCESS); fail: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); - if (db != NULL) + } + if (db != NULL) { dns_db_detach(&db); + } return (result); } @@ -1117,17 +1143,20 @@ rpz_log_rewrite(ns_client_t *client, bool disabled, dns_rpz_policy_t policy, } if (p_zone != NULL) { zonestats = dns_zone_getrequeststats(p_zone); - if (zonestats != NULL) + if (zonestats != NULL) { isc_stats_increment(zonestats, ns_statscounter_rpz_rewrites); + } } - if (!isc_log_wouldlog(ns_lctx, DNS_RPZ_INFO_LEVEL)) + if (!isc_log_wouldlog(ns_lctx, DNS_RPZ_INFO_LEVEL)) { return; + } st = client->query.rpz_st; - if ((st->popt.no_log & DNS_RPZ_ZBIT(rpz_num)) != 0) + if ((st->popt.no_log & DNS_RPZ_ZBIT(rpz_num)) != 0) { return; + } dns_name_format(client->query.qname, qname_buf, sizeof(qname_buf)); dns_name_format(p_name, p_name_buf, sizeof(p_name_buf)); @@ -1165,16 +1194,18 @@ rpz_log_fail_helper(ns_client_t *client, int level, dns_name_t *p_name, const char *rpztypestr1; const char *rpztypestr2; - if (!isc_log_wouldlog(ns_lctx, level)) + if (!isc_log_wouldlog(ns_lctx, level)) { return; + } /* * bin/tests/system/rpz/tests.sh looks for "rpz.*failed" for problems. */ - if (level <= DNS_RPZ_DEBUG_LEVEL1) + if (level <= DNS_RPZ_DEBUG_LEVEL1) { failed = " failed: "; - else + } else { failed = ": "; + } rpztypestr1 = dns_rpz_type2str(rpz_type1); if (rpz_type2 != DNS_RPZ_TYPE_BAD) { @@ -1335,15 +1366,17 @@ query_getdb(ns_client_t *client, dns_name_t *name, dns_rdatatype_t qtype, /* * If the previous search returned a zone, detach it. */ - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } /* * If the previous search returned a database, * detach it. */ - if (*dbp != NULL) + if (*dbp != NULL) { dns_db_detach(dbp); + } /* * If the previous search returned a version, clear it. @@ -1411,15 +1444,18 @@ query_isduplicate(ns_client_t *client, dns_name_t *name, dns_rdatatype_t type, /* * The name exists, but the rdataset does not. */ - if (section == DNS_SECTION_ADDITIONAL) + if (section == DNS_SECTION_ADDITIONAL) { break; - } else + } + } else { RUNTIME_CHECK(result == DNS_R_NXDOMAIN); + } mname = NULL; } - if (mnamep != NULL) + if (mnamep != NULL) { *mnamep = mname; + } CTRACE(ISC_LOG_DEBUG(3), "query_isduplicate: false: done"); return (false); @@ -1709,8 +1745,9 @@ query_additional_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype) if (!WANTDNSSEC(client)) { ns_client_putrdataset(client, &sigrdataset); } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { goto found; + } if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); @@ -2046,7 +2083,7 @@ query_setorder(query_ctx_t *qctx, dns_name_t *name, dns_rdataset_t *rdataset) order, name, rdataset->type, rdataset->rdclass); } rdataset->attributes |= DNS_RDATASETATTR_LOADORDER; -}; +} /* * Handle glue and fetch any other needed additional data for 'rdataset'. @@ -2210,8 +2247,9 @@ mark_secure(ns_client_t *client, dns_db_t *db, dns_name_t *name, * Save the updated secure state. Ignore failures. */ result = dns_db_findnodeext(db, name, true, &cm, &ci, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } isc_stdtime_get(&now); dns_rdataset_trimttl(rdataset, sigrdataset, rrsig, now, @@ -2246,22 +2284,26 @@ get_key(ns_client_t *client, dns_db_t *db, dns_rdata_rrsig_t *rrsig, if (!dns_rdataset_isassociated(keyrdataset)) { result = dns_db_findnodeext(db, &rrsig->signer, false, &cm, &ci, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } result = dns_db_findrdataset(db, node, NULL, dns_rdatatype_dnskey, 0, client->now, keyrdataset, NULL); dns_db_detachnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (false); + } - if (keyrdataset->trust != dns_trust_secure) + if (keyrdataset->trust != dns_trust_secure) { return (false); + } result = dns_rdataset_first(keyrdataset); - } else + } else { result = dns_rdataset_next(keyrdataset); + } for (; result == ISC_R_SUCCESS; result = dns_rdataset_next(keyrdataset)) { @@ -2273,8 +2315,9 @@ get_key(ns_client_t *client, dns_db_t *db, dns_rdata_rrsig_t *rrsig, isc_buffer_add(&b, rdata.length); result = dst_key_fromdns(&rrsig->signer, rdata.rdclass, &b, client->mctx, keyp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } if (rrsig->algorithm == (dns_secalg_t)dst_key_alg(*keyp) && rrsig->keyid == (dns_keytag_t)dst_key_id(*keyp) && dst_key_iszonekey(*keyp)) { @@ -2304,8 +2347,9 @@ again: ignore = true; goto again; } - if (result == ISC_R_SUCCESS || result == DNS_R_FROMWILDCARD) + if (result == ISC_R_SUCCESS || result == DNS_R_FROMWILDCARD) { return (true); + } return (false); } @@ -2322,8 +2366,9 @@ validate(ns_client_t *client, dns_db_t *db, dns_name_t *name, dst_key_t * key = NULL; dns_rdataset_t keyrdataset; - if (sigrdataset == NULL || !dns_rdataset_isassociated(sigrdataset)) + if (sigrdataset == NULL || !dns_rdataset_isassociated(sigrdataset)) { return (false); + } for (result = dns_rdataset_first(sigrdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(sigrdataset)) { @@ -2332,14 +2377,17 @@ validate(ns_client_t *client, dns_db_t *db, dns_name_t *name, result = dns_rdata_tostruct(&rdata, &rrsig, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); if (!dns_resolver_algorithm_supported(client->view->resolver, - name, rrsig.algorithm)) + name, rrsig.algorithm)) { continue; - if (!dns_name_issubdomain(name, &rrsig.signer)) + } + if (!dns_name_issubdomain(name, &rrsig.signer)) { continue; + } dns_rdataset_init(&keyrdataset); do { - if (!get_key(client, db, &rrsig, &keyrdataset, &key)) + if (!get_key(client, db, &rrsig, &keyrdataset, &key)) { break; + } if (verify(key, name, rdataset, &rdata, client)) { dst_key_free(&key); dns_rdataset_disassociate(&keyrdataset); @@ -2349,8 +2397,9 @@ validate(ns_client_t *client, dns_db_t *db, dns_name_t *name, } dst_key_free(&key); } while (1); - if (dns_rdataset_isassociated(&keyrdataset)) + if (dns_rdataset_isassociated(&keyrdataset)) { dns_rdataset_disassociate(&keyrdataset); + } } return (false); } @@ -2358,10 +2407,11 @@ validate(ns_client_t *client, dns_db_t *db, dns_name_t *name, static void fixrdataset(ns_client_t *client, dns_rdataset_t **rdataset) { - if (*rdataset == NULL) + if (*rdataset == NULL) { *rdataset = ns_client_newrdataset(client); - else if (dns_rdataset_isassociated(*rdataset)) + } else if (dns_rdataset_isassociated(*rdataset)) { dns_rdataset_disassociate(*rdataset); + } } static void @@ -2370,8 +2420,9 @@ fixfname(ns_client_t *client, dns_name_t **fname, isc_buffer_t **dbuf, { if (*fname == NULL) { *dbuf = ns_client_getnamebuf(client); - if (*dbuf == NULL) + if (*dbuf == NULL) { return; + } *fname = ns_client_newname(client, *dbuf, nbuf); } } @@ -2498,13 +2549,16 @@ rpz_clean(dns_zone_t **zonep, dns_db_t **dbp, dns_dbnode_t **nodep, REQUIRE(dbp != NULL && *dbp != NULL); dns_db_detachnode(*dbp, nodep); } - if (dbp != NULL && *dbp != NULL) + if (dbp != NULL && *dbp != NULL) { dns_db_detach(dbp); - if (zonep != NULL && *zonep != NULL) + } + if (zonep != NULL && *zonep != NULL) { dns_zone_detach(zonep); + } if (rdatasetp != NULL && *rdatasetp != NULL && - dns_rdataset_isassociated(*rdatasetp)) + dns_rdataset_isassociated(*rdatasetp)) { dns_rdataset_disassociate(*rdatasetp); + } } static inline void @@ -2591,7 +2645,7 @@ rpz_get_zbits(ns_client_t *client, dns_rdatatype_t ip_type, } return (0); } -#endif +#endif /* ifdef USE_DNSRPS */ switch (rpz_type) { case DNS_RPZ_TYPE_CLIENT_IP: @@ -2645,8 +2699,9 @@ rpz_get_zbits(ns_client_t *client, dns_rdatatype_t ip_type, /* * If the client wants recursion, allow only compatible policies. */ - if (!RECURSIONOK(client)) + if (!RECURSIONOK(client)) { zbits &= st->popt.no_rd_ok; + } return (zbits); } @@ -2661,8 +2716,9 @@ query_rpzfetch(ns_client_t *client, dns_name_t *qname, dns_rdatatype_t type) CTRACE(ISC_LOG_DEBUG(3), "query_rpzfetch"); - if (client->query.prefetch != NULL) + if (client->query.prefetch != NULL) { return; + } if (client->recursionquota == NULL) { result = isc_quota_attach(&client->sctx->recursionquota, @@ -2758,12 +2814,14 @@ rpz_rrset_find(ns_client_t *client, dns_name_t *name, dns_rdatatype_t type, rpz_log_fail(client, DNS_RPZ_ERROR_LEVEL, name, rpz_type, "rpz_rrset_find(2)", result); st->m.policy = DNS_RPZ_POLICY_ERROR; - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } return (result); } - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } } node = NULL; @@ -2863,8 +2921,9 @@ rpz_get_p_name(ns_client_t *client, dns_name_t *p_name, dns_rpz_zone_t *rpz, dns_name_getlabelsequence(trig_name, first, labels - first - 1, &prefix); result = dns_name_concatenate(&prefix, suffix, p_name, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { break; + } INSIST(result == DNS_R_NAMETOOLONG); /* * Trim the trigger name until the combination is not too long. @@ -2930,8 +2989,9 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, } *versionp = NULL; result = rpz_getdb(client, p_name, rpz_type, zonep, dbp, versionp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (DNS_R_NXDOMAIN); + } found = dns_fixedname_initname(&foundf); result = dns_db_findext(*dbp, p_name, *versionp, dns_rdatatype_any, 0, @@ -2970,8 +3030,9 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, result = dns_rdatasetiter_next(rdsiter)) { dns_rdatasetiter_current(rdsiter, *rdatasetp); if ((*rdatasetp)->type == dns_rdatatype_cname || - (*rdatasetp)->type == qtype) + (*rdatasetp)->type == qtype) { break; + } dns_rdataset_disassociate(*rdatasetp); } dns_rdatasetiter_destroy(&rdsiter); @@ -2988,18 +3049,20 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, * Ask again to get the right DNS_R_DNAME/NXRRSET/... * result if there is neither a CNAME nor target type. */ - if (dns_rdataset_isassociated(*rdatasetp)) + if (dns_rdataset_isassociated(*rdatasetp)) { dns_rdataset_disassociate(*rdatasetp); + } dns_db_detachnode(*dbp, nodep); if (qtype == dns_rdatatype_rrsig || - qtype == dns_rdatatype_sig) + qtype == dns_rdatatype_sig) { result = DNS_R_NXRRSET; - else + } else { result = dns_db_findext(*dbp, p_name, *versionp, qtype, 0, client->now, nodep, found, &cm, &ci, *rdatasetp, NULL); + } } } switch (result) { @@ -3012,8 +3075,9 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, if ((*policyp == DNS_RPZ_POLICY_RECORD || *policyp == DNS_RPZ_POLICY_WILDCNAME) && qtype != dns_rdatatype_cname && - qtype != dns_rdatatype_any) + qtype != dns_rdatatype_any) { return (DNS_R_CNAME); + } } return (ISC_R_SUCCESS); case DNS_R_NXRRSET: @@ -3024,16 +3088,16 @@ rpz_find_p(ns_client_t *client, dns_name_t *self_name, dns_rdatatype_t qtype, } return (result); case DNS_R_DNAME: - /* - * DNAME policy RRs have very few if any uses that are not - * better served with simple wildcards. Making them work would - * require complications to get the number of labels matched - * in the name or the found name to the main DNS_R_DNAME case - * in query_dname(). The domain also does not appear in the - * summary database at the right level, so this happens only - * with a single policy zone when we have no summary database. - * Treat it as a miss. - */ + /* + * DNAME policy RRs have very few if any uses that are not + * better served with simple wildcards. Making them work would + * require complications to get the number of labels matched + * in the name or the found name to the main DNS_R_DNAME case + * in query_dname(). The domain also does not appear in the + * summary database at the right level, so this happens only + * with a single policy zone when we have no summary database. + * Treat it as a miss. + */ case DNS_R_NXDOMAIN: case DNS_R_EMPTYNAME: return (DNS_R_NXDOMAIN); @@ -3376,7 +3440,7 @@ rpz_rewrite_ip(ns_client_t *client, const isc_netaddr_t *netaddr, return (dnsrps_rewrite_ip(client, netaddr, rpz_type, p_rdatasetp)); } -#endif +#endif /* ifdef USE_DNSRPS */ ip_name = dns_fixedname_initname(&ip_namef); @@ -3387,8 +3451,9 @@ rpz_rewrite_ip(ns_client_t *client, const isc_netaddr_t *netaddr, while (zbits != 0) { rpz_num = dns_rpz_find_ip(rpzs, rpz_type, zbits, netaddr, ip_name, &prefix); - if (rpz_num == DNS_RPZ_INVALID_NUM) + if (rpz_num == DNS_RPZ_INVALID_NUM) { break; + } zbits &= (DNS_RPZ_ZMASK(rpz_num) >> 1); /* @@ -3399,11 +3464,13 @@ rpz_rewrite_ip(ns_client_t *client, const isc_netaddr_t *netaddr, */ rpz = rpzs->zones[rpz_num]; if (st->m.policy != DNS_RPZ_POLICY_MISS) { - if (st->m.rpz->num < rpz->num) + if (st->m.rpz->num < rpz->num) { break; + } if (st->m.rpz->num == rpz->num && - (st->m.type < rpz_type || st->m.prefix > prefix)) + (st->m.type < rpz_type || st->m.prefix > prefix)) { break; + } } /* @@ -3412,8 +3479,9 @@ rpz_rewrite_ip(ns_client_t *client, const isc_netaddr_t *netaddr, */ p_name = dns_fixedname_initname(&p_namef); result = rpz_get_p_name(client, p_name, rpz, rpz_type, ip_name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = rpz_find_p(client, ip_name, qtype, p_name, rpz, rpz_type, &p_zone, &p_db, &p_version, &p_node, p_rdatasetp, &policy); @@ -3455,8 +3523,9 @@ rpz_rewrite_ip(ns_client_t *client, const isc_netaddr_t *netaddr, if (st->m.policy != DNS_RPZ_POLICY_MISS && rpz->num == st->m.rpz->num && (st->m.type == rpz_type && st->m.prefix == prefix && - 0 > dns_name_rdatacompare(st->p_name, p_name))) + 0 > dns_name_rdatacompare(st->p_name, p_name))) { break; + } /* * Stop checking after saving an enabled hit in this @@ -3505,8 +3574,9 @@ rpz_rewrite_ip_rrset(ns_client_t *client, dns_name_t *name, CTRACE(ISC_LOG_DEBUG(3), "rpz_rewrite_ip_rrset"); zbits = rpz_get_zbits(client, ip_type, rpz_type); - if (zbits == 0) + if (zbits == 0) { return (ISC_R_SUCCESS); + } /* * Get the A or AAAA rdataset. @@ -3572,8 +3642,9 @@ rpz_rewrite_ip_rrset(ns_client_t *client, dns_name_t *name, result = rpz_rewrite_ip(client, &netaddr, qtype, rpz_type, zbits, p_rdatasetp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } return (ISC_R_SUCCESS); @@ -3610,8 +3681,9 @@ rpz_rewrite_ip_rrsets(ns_client_t *client, dns_name_t *name, result = rpz_rewrite_ip_rrset( client, name, qtype, rpz_type, dns_rdatatype_a, &ip_db, ip_version, ip_rdatasetp, &p_rdataset, resuming); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { st->state |= DNS_RPZ_DONE_IPv4; + } } else { result = ISC_R_SUCCESS; } @@ -3627,8 +3699,9 @@ rpz_rewrite_ip_rrsets(ns_client_t *client, dns_name_t *name, ip_version, ip_rdatasetp, &p_rdataset, resuming); } - if (ip_db != NULL) + if (ip_db != NULL) { dns_db_detach(&ip_db); + } ns_client_putrdataset(client, &p_rdataset); return (result); } @@ -3662,7 +3735,7 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, #ifndef USE_DNSRPS UNUSED(recursed); -#endif +#endif /* ifndef USE_DNSRPS */ CTRACE(ISC_LOG_DEBUG(3), "rpz_rewrite_name"); @@ -3674,12 +3747,13 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, return (dnsrps_rewrite_name(client, trig_name, recursed, rpz_type, rdatasetp)); } -#endif +#endif /* ifdef USE_DNSRPS */ zbits = rpz_get_zbits(client, qtype, rpz_type); zbits &= allowed_zbits; - if (zbits == 0) + if (zbits == 0) { return (ISC_R_SUCCESS); + } /* * Use the summary database to find the bit mask of policy zones @@ -3688,8 +3762,9 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, * are matched correctly, and not into their parent. */ zbits = dns_rpz_find_name(rpzs, rpz_type, zbits, trig_name); - if (zbits == 0) + if (zbits == 0) { return (ISC_R_SUCCESS); + } p_name = dns_fixedname_initname(&p_namef); @@ -3706,8 +3781,9 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, * one policy zone. */ for (rpz_num = 0; zbits != 0; ++rpz_num, zbits >>= 1) { - if ((zbits & 1) == 0) + if ((zbits & 1) == 0) { continue; + } /* * Do not check policy zones that cannot replace a previously @@ -3715,10 +3791,13 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, */ rpz = rpzs->zones[rpz_num]; if (st->m.policy != DNS_RPZ_POLICY_MISS) { - if (st->m.rpz->num < rpz->num) + if (st->m.rpz->num < rpz->num) { break; - if (st->m.rpz->num == rpz->num && st->m.type < rpz_type) + } + if (st->m.rpz->num == rpz->num && + st->m.type < rpz_type) { break; + } } /* @@ -3726,8 +3805,9 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, */ result = rpz_get_p_name(client, p_name, rpz, rpz_type, trig_name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } result = rpz_find_p(client, trig_name, qtype, p_name, rpz, rpz_type, &p_zone, &p_db, &p_version, &p_node, rdatasetp, &policy); @@ -3760,8 +3840,9 @@ rpz_rewrite_name(ns_client_t *client, dns_name_t *trig_name, rpz->num == st->m.rpz->num && (st->m.type < rpz_type || (st->m.type == rpz_type && - 0 >= dns_name_compare(p_name, st->p_name)))) + 0 >= dns_name_compare(p_name, st->p_name)))) { continue; + } if (rpz->policy != DNS_RPZ_POLICY_DISABLED) { CTRACE(ISC_LOG_DEBUG(3), "rpz_rewrite_name: " @@ -3800,12 +3881,14 @@ rpz_rewrite_ns_skip(ns_client_t *client, dns_name_t *nsname, st = client->query.rpz_st; - if (str != NULL) + if (str != NULL) { rpz_log_fail_helper(client, level, nsname, DNS_RPZ_TYPE_NSIP, DNS_RPZ_TYPE_NSDNAME, str, result); + } if (st->r.ns_rdataset != NULL && - dns_rdataset_isassociated(st->r.ns_rdataset)) + dns_rdataset_isassociated(st->r.ns_rdataset)) { dns_rdataset_disassociate(st->r.ns_rdataset); + } st->r.label--; } @@ -3839,7 +3922,7 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, int rpz_ver; #ifdef USE_DNSRPS librpz_emsg_t emsg; -#endif +#endif /* ifdef USE_DNSRPS */ CTRACE(ISC_LOG_DEBUG(3), "rpz_rewrite"); @@ -3847,8 +3930,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, st = client->query.rpz_st; if (rpzs == NULL || - (st != NULL && (st->state & DNS_RPZ_REWRITTEN) != 0)) + (st != NULL && (st->state & DNS_RPZ_REWRITTEN) != 0)) { return (DNS_R_DISALLOWED); + } RWLOCK(&rpzs->search_lock, isc_rwlocktype_read); if ((rpzs->p.num_zones == 0 && !rpzs->p.dnsrps_enabled) || @@ -3864,7 +3948,7 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, #ifndef USE_DNSRPS INSIST(!popt.dnsrps_enabled); -#endif +#endif /* ifndef USE_DNSRPS */ if (st == NULL) { st = isc_mem_get(client->mctx, sizeof(*st)); @@ -3902,7 +3986,7 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, return (ISC_R_SUCCESS); } } -#endif +#endif /* ifdef USE_DNSRPS */ } /* @@ -3932,10 +4016,11 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, * If recursion is off, this the normal and only time we * can rewrite. */ - if (RECURSIONOK(client)) + if (RECURSIONOK(client)) { qresult_type = qresult_type_recurse; - else + } else { qresult_type = qresult_type_restart; + } break; case ISC_R_FAILURE: case ISC_R_TIMEDOUT: @@ -3987,8 +4072,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, result = rpz_rewrite_ip(client, &netaddr, qtype, DNS_RPZ_TYPE_CLIENT_IP, zbits, &rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } } } @@ -4002,8 +4088,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, result = rpz_rewrite_name(client, client->query.qname, qtype, DNS_RPZ_TYPE_QNAME, allowed, norec, &rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * Check IPv4 addresses in A RRs next. @@ -4026,8 +4113,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, * Do not bother saving the work from this attempt, * because recusion is so slow. */ - if (qresult_type == qresult_type_recurse) + if (qresult_type == qresult_type_recurse) { goto cleanup; + } /* * DNS_RPZ_DONE_QNAME but not DNS_RPZ_DONE_CLIENT_IP @@ -4049,8 +4137,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, result = rpz_rewrite_ip_rrsets(client, client->query.qname, qtype, DNS_RPZ_TYPE_IP, &rdataset, resuming); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* * We are finished checking the IP addresses for the qname. * Start with IPv4 if we will check NS IP addesses. @@ -4090,15 +4179,18 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, dns_rdatatype_ns, DNS_RPZ_TYPE_NSDNAME, &db, NULL, &st->r.ns_rdataset, resuming); - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); - if (st->m.policy == DNS_RPZ_POLICY_ERROR) + } + if (st->m.policy == DNS_RPZ_POLICY_ERROR) { goto cleanup; + } switch (result) { case ISC_R_SUCCESS: result = dns_rdataset_first(st->r.ns_rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } st->state &= ~(DNS_RPZ_DONE_NSDNAME | DNS_RPZ_DONE_IPv4); break; @@ -4175,8 +4267,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, DNS_RPZ_TYPE_NSIP, &rdataset, resuming); dns_rdata_freestruct(&ns); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } st->state &= ~(DNS_RPZ_DONE_NSDNAME | DNS_RPZ_DONE_IPv4); result = dns_rdataset_next(st->r.ns_rdataset); @@ -4187,8 +4280,9 @@ rpz_rewrite(ns_client_t *client, dns_rdatatype_t qtype, isc_result_t qresult, if (rpz_get_zbits(client, dns_rdatatype_any, DNS_RPZ_TYPE_NSDNAME) == 0 && rpz_get_zbits(client, dns_rdatatype_any, - DNS_RPZ_TYPE_NSIP) == 0) + DNS_RPZ_TYPE_NSIP) == 0) { break; + } } /* @@ -4205,19 +4299,21 @@ cleanup: DNS_RPZ_TYPE_BAD, emsg.c, DNS_R_SERVFAIL); st->m.policy = DNS_RPZ_POLICY_ERROR; } -#endif +#endif /* ifdef USE_DNSRPS */ if (st->m.policy != DNS_RPZ_POLICY_MISS && st->m.policy != DNS_RPZ_POLICY_ERROR && - st->m.rpz->policy != DNS_RPZ_POLICY_GIVEN) + st->m.rpz->policy != DNS_RPZ_POLICY_GIVEN) { st->m.policy = st->m.rpz->policy; + } if (st->m.policy == DNS_RPZ_POLICY_MISS || st->m.policy == DNS_RPZ_POLICY_PASSTHRU || st->m.policy == DNS_RPZ_POLICY_ERROR) { if (st->m.policy == DNS_RPZ_POLICY_PASSTHRU && - result != DNS_R_DELEGATION) + result != DNS_R_DELEGATION) { rpz_log_rewrite(client, false, st->m.policy, st->m.type, st->m.zone, st->p_name, NULL, st->m.rpz->num); + } rpz_match_clear(st); } if (st->m.policy == DNS_RPZ_POLICY_ERROR) { @@ -4226,8 +4322,9 @@ cleanup: result = DNS_R_SERVFAIL; } ns_client_putrdataset(client, &rdataset); - if ((st->state & DNS_RPZ_RECURSING) == 0) + if ((st->state & DNS_RPZ_RECURSING) == 0) { rpz_clean(NULL, &st->r.db, NULL, &st->r.ns_rdataset); + } return (result); } @@ -4248,39 +4345,46 @@ rpz_ck_dnssec(ns_client_t *client, isc_result_t qresult, CTRACE(ISC_LOG_DEBUG(3), "rpz_ck_dnssec"); - if (client->view->rpzs->p.break_dnssec || !WANTDNSSEC(client)) + if (client->view->rpzs->p.break_dnssec || !WANTDNSSEC(client)) { return (true); + } /* * We do not know if there are signatures if we have not recursed * for them. */ - if (qresult == DNS_R_DELEGATION || qresult == ISC_R_NOTFOUND) + if (qresult == DNS_R_DELEGATION || qresult == ISC_R_NOTFOUND) { return (false); + } - if (sigrdataset == NULL) + if (sigrdataset == NULL) { return (true); - if (dns_rdataset_isassociated(sigrdataset)) + } + if (dns_rdataset_isassociated(sigrdataset)) { return (false); + } /* * We are happy to rewrite nothing. */ - if (rdataset == NULL || !dns_rdataset_isassociated(rdataset)) + if (rdataset == NULL || !dns_rdataset_isassociated(rdataset)) { return (true); + } /* * Do not rewrite if there is any sign of signatures. */ if (rdataset->type == dns_rdatatype_nsec || rdataset->type == dns_rdatatype_nsec3 || - rdataset->type == dns_rdatatype_rrsig) + rdataset->type == dns_rdatatype_rrsig) { return (false); + } /* * Look for a signature in a negative cache rdataset. */ - if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) == 0) + if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) == 0) { return (true); + } found = dns_fixedname_initname(&fixed); dns_rdataset_init(&trdataset); for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -4289,8 +4393,9 @@ rpz_ck_dnssec(ns_client_t *client, isc_result_t qresult, type = trdataset.type; dns_rdataset_disassociate(&trdataset); if (type == dns_rdatatype_nsec || type == dns_rdatatype_nsec3 || - type == dns_rdatatype_rrsig) + type == dns_rdatatype_rrsig) { return (false); + } } return (true); } @@ -4398,8 +4503,9 @@ warn_rfc1918(ns_client_t *client, dns_name_t *fname, dns_rdataset_t *rdataset) result = dns_ncache_getrdataset( rdataset, &rfc1918names[i], dns_rdatatype_soa, &found); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } result = dns_rdataset_first(&found); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -4447,8 +4553,9 @@ query_findclosestnsec3(dns_name_t *qname, dns_db_t *db, salt_length = sizeof(salt); result = dns_db_getnsec3parameters(db, version, &hash, NULL, &iterations, salt, &salt_length); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } dns_name_init(&name, NULL); dns_name_clone(qname, &name); @@ -4459,16 +4566,18 @@ query_findclosestnsec3(dns_name_t *qname, dns_db_t *db, /* * Map unknown algorithm to known value. */ - if (hash == DNS_NSEC3_UNKNOWNALG) + if (hash == DNS_NSEC3_UNKNOWNALG) { hash = 1; + } again: dns_fixedname_init(&fixed); result = dns_nsec3_hashname(&fixed, NULL, NULL, &name, dns_db_origin(db), hash, iterations, salt, salt_length); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return; + } dboptions = client->query.dboptions | DNS_DBFIND_FORCENSEC3; result = dns_db_findext(db, dns_fixedname_name(&fixed), version, @@ -4489,8 +4598,9 @@ again: if (found != NULL && optout && dns_name_issubdomain(&name, dns_db_origin(db))) { dns_rdataset_disassociate(rdataset); - if (dns_rdataset_isassociated(sigrdataset)) + if (dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } skip++; dns_name_getlabelsequence(qname, skip, labels - skip, &name); @@ -4499,24 +4609,27 @@ again: "looking for closest provable encloser"); goto again; } - if (exact) + if (exact) { ns_client_log(client, DNS_LOGCATEGORY_DNSSEC, NS_LOGMODULE_QUERY, ISC_LOG_WARNING, "expected a exact match NSEC3, got " "a covering record"); - + } } else if (result != ISC_R_SUCCESS) { return; - } else if (!exact) + } else if (!exact) { ns_client_log(client, DNS_LOGCATEGORY_DNSSEC, NS_LOGMODULE_QUERY, ISC_LOG_WARNING, "expected covering NSEC3, got an exact match"); + } if (found == qname) { - if (skip != 0U) + if (skip != 0U) { dns_name_getlabelsequence(qname, skip, labels - skip, found); - } else if (found != NULL) + } + } else if (found != NULL) { dns_name_copynf(&name, found); + } return; } @@ -4533,16 +4646,19 @@ dns64_ttl(dns_db_t *db, dns_dbversion_t *version) dns_rdataset_init(&rdataset); result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_db_findrdataset(db, node, version, dns_rdatatype_soa, 0, 0, &rdataset, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_rdataset_first(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdataset_current(&rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &soa, NULL); @@ -4550,10 +4666,12 @@ dns64_ttl(dns_db_t *db, dns_dbversion_t *version) ttl = ISC_MIN(rdataset.ttl, soa.minimum); cleanup: - if (dns_rdataset_isassociated(&rdataset)) + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } return (ttl); } @@ -4574,15 +4692,18 @@ dns64_aaaaok(ns_client_t *client, dns_rdataset_t *rdataset, INSIST(client->query.dns64_aaaa == NULL); INSIST(client->query.dns64_sigaaaa == NULL); - if (dns64 == NULL) + if (dns64 == NULL) { return (true); + } - if (RECURSIONOK(client)) + if (RECURSIONOK(client)) { flags |= DNS_DNS64_RECURSIVE; + } if (WANTDNSSEC(client) && sigrdataset != NULL && - dns_rdataset_isassociated(sigrdataset)) + dns_rdataset_isassociated(sigrdataset)) { flags |= DNS_DNS64_DNSSEC; + } count = dns_rdataset_count(rdataset); aaaaok = isc_mem_get(client->mctx, sizeof(bool) * count); @@ -4597,12 +4718,14 @@ dns64_aaaaok(ns_client_t *client, dns_rdataset_t *rdataset, break; } } - if (aaaaok != NULL) + if (aaaaok != NULL) { isc_mem_put(client->mctx, aaaaok, sizeof(bool) * count); + } return (true); } - if (aaaaok != NULL) + if (aaaaok != NULL) { isc_mem_put(client->mctx, aaaaok, sizeof(bool) * count); + } return (false); } @@ -4632,8 +4755,9 @@ redirect(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, CTRACE(ISC_LOG_DEBUG(3), "redirect"); - if (client->view->redirect == NULL) + if (client->view->redirect == NULL) { return (ISC_R_NOTFOUND); + } found = dns_fixedname_initname(&fixed); dns_rdataset_init(&trdataset); @@ -4641,16 +4765,20 @@ redirect(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, dns_clientinfomethods_init(&cm, ns_client_sourceip); dns_clientinfo_init(&ci, client, NULL); - if (WANTDNSSEC(client) && dns_db_iszone(*dbp) && dns_db_issecure(*dbp)) + if (WANTDNSSEC(client) && dns_db_iszone(*dbp) && + dns_db_issecure(*dbp)) { return (ISC_R_NOTFOUND); + } if (WANTDNSSEC(client) && dns_rdataset_isassociated(rdataset)) { - if (rdataset->trust == dns_trust_secure) + if (rdataset->trust == dns_trust_secure) { return (ISC_R_NOTFOUND); + } if (rdataset->trust == dns_trust_ultimate && (rdataset->type == dns_rdatatype_nsec || - rdataset->type == dns_rdatatype_nsec3)) + rdataset->type == dns_rdatatype_nsec3)) { return (ISC_R_NOTFOUND); + } if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) { for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -4660,8 +4788,9 @@ redirect(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, dns_rdataset_disassociate(&trdataset); if (type == dns_rdatatype_nsec || type == dns_rdatatype_nsec3 || - type == dns_rdatatype_rrsig) + type == dns_rdatatype_rrsig) { return (ISC_R_NOTFOUND); + } } } } @@ -4669,12 +4798,14 @@ redirect(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, result = ns_client_checkaclsilent( client, NULL, dns_zone_getqueryacl(client->view->redirect), true); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } result = dns_zone_getdb(client->view->redirect, &db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } dbversion = ns_client_findversion(client, db); if (dbversion == NULL) { @@ -4689,31 +4820,37 @@ redirect(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, qtype, DNS_DBFIND_NOZONECUT, client->now, &node, found, &cm, &ci, &trdataset, NULL); if (result == DNS_R_NXRRSET || result == DNS_R_NCACHENXRRSET) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); - if (dns_rdataset_isassociated(&trdataset)) + } + if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_disassociate(&trdataset); + } goto nxrrset; } else if (result != ISC_R_SUCCESS) { - if (dns_rdataset_isassociated(&trdataset)) + if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_disassociate(&trdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } dns_db_detach(&db); return (ISC_R_NOTFOUND); } CTRACE(ISC_LOG_DEBUG(3), "redirect: found data: done"); dns_name_copynf(found, name); - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_clone(&trdataset, rdataset); dns_rdataset_disassociate(&trdataset); } nxrrset: - if (*nodep != NULL) + if (*nodep != NULL) { dns_db_detachnode(*dbp, nodep); + } dns_db_detach(dbp); dns_db_attachnode(db, node, nodep); dns_db_attach(db, dbp); @@ -4770,12 +4907,14 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, } if (WANTDNSSEC(client) && dns_rdataset_isassociated(rdataset)) { - if (rdataset->trust == dns_trust_secure) + if (rdataset->trust == dns_trust_secure) { return (ISC_R_NOTFOUND); + } if (rdataset->trust == dns_trust_ultimate && (rdataset->type == dns_rdatatype_nsec || - rdataset->type == dns_rdatatype_nsec3)) + rdataset->type == dns_rdatatype_nsec3)) { return (ISC_R_NOTFOUND); + } if ((rdataset->attributes & DNS_RDATASETATTR_NEGATIVE) != 0) { for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -4785,8 +4924,9 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, dns_rdataset_disassociate(&trdataset); if (type == dns_rdatatype_nsec || type == dns_rdatatype_nsec3 || - type == dns_rdatatype_rrsig) + type == dns_rdatatype_rrsig) { return (ISC_R_NOTFOUND); + } } } } @@ -4802,8 +4942,9 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, result = dns_name_concatenate(&prefix, client->view->redirectzone, redirectname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_NOTFOUND); + } } else { dns_name_copynf(redirectname, client->view->redirectzone); } @@ -4825,19 +4966,23 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, client->now, &node, found, &cm, &ci, &trdataset, NULL); if (result == DNS_R_NXRRSET || result == DNS_R_NCACHENXRRSET) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); - if (dns_rdataset_isassociated(&trdataset)) + } + if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_disassociate(&trdataset); + } goto nxrrset; } else if (result == ISC_R_NOTFOUND || result == DNS_R_DELEGATION) { /* * Cleanup. */ - if (dns_rdataset_isassociated(&trdataset)) + if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_disassociate(&trdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } dns_db_detach(&db); /* * Don't loop forever if the lookup failed last time. @@ -4855,10 +5000,12 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, } return (ISC_R_NOTFOUND); } else if (result != ISC_R_SUCCESS) { - if (dns_rdataset_isassociated(&trdataset)) + if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_disassociate(&trdataset); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(db, &node); + } dns_db_detach(&db); return (ISC_R_NOTFOUND); } @@ -4876,15 +5023,17 @@ redirect2(ns_client_t *client, dns_name_t *name, dns_rdataset_t *rdataset, RUNTIME_CHECK(result == ISC_R_SUCCESS); dns_name_copynf(found, name); - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } if (dns_rdataset_isassociated(&trdataset)) { dns_rdataset_clone(&trdataset, rdataset); dns_rdataset_disassociate(&trdataset); } nxrrset: - if (*nodep != NULL) + if (*nodep != NULL) { dns_db_detachnode(*dbp, nodep); + } dns_db_detach(dbp); dns_db_attachnode(db, node, nodep); dns_db_attach(db, dbp); @@ -5010,11 +5159,12 @@ query_trace(query_ctx_t *qctx) char mbuf[2 * DNS_NAME_FORMATSIZE]; char qbuf[DNS_NAME_FORMATSIZE]; - if (qctx->client->query.origqname != NULL) + if (qctx->client->query.origqname != NULL) { dns_name_format(qctx->client->query.origqname, qbuf, sizeof(qbuf)); - else + } else { snprintf(qbuf, sizeof(qbuf), ""); + } snprintf(mbuf, sizeof(mbuf) - 1, "client attr:0x%x, query attr:0x%X, restarts:%u, " @@ -5025,9 +5175,9 @@ query_trace(query_ctx_t *qctx) (int)qctx->client->query.authdbset, (int)qctx->client->query.isreferral); CCTRACE(ISC_LOG_DEBUG(3), mbuf); -#else +#else /* ifdef WANT_QUERYTRACE */ UNUSED(qctx); -#endif +#endif /* ifdef WANT_QUERYTRACE */ } /* @@ -5414,8 +5564,9 @@ query_lookup(query_ctx_t *qctx) dboptions = qctx->client->query.dboptions; if (!qctx->is_zone && qctx->findcoveringnsec && - (qctx->type != dns_rdatatype_null || !dns_name_istat(rpzqname))) + (qctx->type != dns_rdatatype_null || !dns_name_istat(rpzqname))) { dboptions |= DNS_DBFIND_COVERINGNSEC; + } result = dns_db_findext(qctx->db, rpzqname, qctx->version, qctx->type, dboptions, qctx->client->now, &qctx->node, @@ -5636,7 +5787,7 @@ last_init() atomic_init(&last_soft, 0); atomic_init(&last_hard, 0); } -#endif +#endif /* ifdef ISC_MUTEX_ATOMICS */ isc_result_t ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname, @@ -5686,7 +5837,7 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname, if (result == ISC_R_SOFTQUOTA) { #ifdef ISC_MUTEX_ATOMICS isc_once_do(&last_once, last_init); -#endif +#endif /* ifdef ISC_MUTEX_ATOMICS */ isc_stdtime_t now; isc_stdtime_get(&now); if (now != atomic_load_relaxed(&last_soft)) { @@ -5709,7 +5860,7 @@ ns_query_recurse(ns_client_t *client, dns_rdatatype_t qtype, dns_name_t *qname, } else if (result == ISC_R_QUOTA) { #ifdef ISC_MUTEX_ATOMICS isc_once_do(&last_once, last_init); -#endif +#endif /* ifdef ISC_MUTEX_ATOMICS */ isc_stdtime_t now; isc_stdtime_get(&now); if (now != atomic_load_relaxed(&last_hard)) { @@ -5802,7 +5953,7 @@ query_resume(query_ctx_t *qctx) char mbuf[4 * DNS_NAME_FORMATSIZE]; char qbuf[DNS_NAME_FORMATSIZE]; char tbuf[DNS_RDATATYPE_FORMATSIZE]; -#endif +#endif /* ifdef WANT_QUERYTRACE */ CCTRACE(ISC_LOG_DEBUG(3), "query_resume"); @@ -5818,24 +5969,27 @@ query_resume(query_ctx_t *qctx) { char pbuf[DNS_NAME_FORMATSIZE] = ""; char fbuf[DNS_NAME_FORMATSIZE] = ""; - if (qctx->rpz_st->r_name != NULL) + if (qctx->rpz_st->r_name != NULL) { dns_name_format(qctx->rpz_st->r_name, qbuf, sizeof(qbuf)); - else + } else { snprintf(qbuf, sizeof(qbuf), ""); - if (qctx->rpz_st->p_name != NULL) + } + if (qctx->rpz_st->p_name != NULL) { dns_name_format(qctx->rpz_st->p_name, pbuf, sizeof(pbuf)); - if (qctx->rpz_st->fname != NULL) + } + if (qctx->rpz_st->fname != NULL) { dns_name_format(qctx->rpz_st->fname, fbuf, sizeof(fbuf)); + } snprintf(mbuf, sizeof(mbuf) - 1, "rpz rname:%s, pname:%s, qctx->fname:%s", qbuf, pbuf, fbuf); CCTRACE(ISC_LOG_DEBUG(3), mbuf); } -#endif +#endif /* ifdef WANT_QUERYTRACE */ qctx->is_zone = qctx->rpz_st->q.is_zone; qctx->authoritative = qctx->rpz_st->q.authoritative; @@ -5846,8 +6000,9 @@ query_resume(query_ctx_t *qctx) RESTORE(qctx->sigrdataset, qctx->rpz_st->q.sigrdataset); qctx->qtype = qctx->rpz_st->q.qtype; - if (qctx->event->node != NULL) + if (qctx->event->node != NULL) { dns_db_detachnode(qctx->event->db, &qctx->event->node); + } SAVE(qctx->rpz_st->r.db, qctx->event->db); qctx->rpz_st->r.r_type = qctx->event->qtype; SAVE(qctx->rpz_st->r.r_rdataset, qctx->event->rdataset); @@ -5866,7 +6021,7 @@ query_resume(query_ctx_t *qctx) "redirect qctx->fname:%s, qtype:%s, auth:%d", qbuf, tbuf, qctx->client->query.redirect.authoritative); CCTRACE(ISC_LOG_DEBUG(3), mbuf); -#endif +#endif /* ifdef WANT_QUERYTRACE */ qctx->qtype = qctx->client->query.redirect.qtype; INSIST(qctx->client->query.redirect.rdataset != NULL); RESTORE(qctx->rdataset, qctx->client->query.redirect.rdataset); @@ -5883,10 +6038,12 @@ query_resume(query_ctx_t *qctx) */ ns_client_putrdataset(qctx->client, &qctx->event->rdataset); ns_client_putrdataset(qctx->client, &qctx->event->sigrdataset); - if (qctx->event->node != NULL) + if (qctx->event->node != NULL) { dns_db_detachnode(qctx->event->db, &qctx->event->node); - if (qctx->event->db != NULL) + } + if (qctx->event->db != NULL) { dns_db_detach(&qctx->event->db); + } } else { CCTRACE(ISC_LOG_DEBUG(3), "resume from normal recursion"); qctx->authoritative = false; @@ -6015,11 +6172,11 @@ ns__query_sfcache(query_ctx_t *qctx) qctx->view->failcache, qctx->client->query.qname, qctx->qtype, &flags, &qctx->client->tnow); } -#else +#else /* ifdef ENABLE_AFL */ failcache = dns_badcache_find(qctx->view->failcache, qctx->client->query.qname, qctx->qtype, &flags, &qctx->client->tnow); -#endif +#endif /* ifdef ENABLE_AFL */ if (failcache && (((flags & NS_FAILCACHE_CD) != 0) || ((qctx->client->message->flags & DNS_MESSAGEFLAG_CD) == 0))) { @@ -6112,8 +6269,9 @@ query_checkrrl(query_ctx_t *qctx, isc_result_t result) /* * Use the database origin name to rate limit NXDOMAIN */ - if (qctx->db != NULL) + if (qctx->db != NULL) { constname = dns_db_origin(qctx->db); + } resp_result = result; } else if (result == DNS_R_NCACHENXDOMAIN && qctx->rdataset != NULL && @@ -6308,9 +6466,10 @@ query_checkrpz(query_ctx_t *qctx, isc_result_t result) case DNS_RPZ_POLICY_TCP_ONLY: qctx->client->message->flags |= DNS_MESSAGEFLAG_TC; if (result == DNS_R_NXDOMAIN || - result == DNS_R_NCACHENXDOMAIN) + result == DNS_R_NCACHENXDOMAIN) { qctx->client->message->rcode = dns_rcode_nxdomain; + } rpz_log_rewrite(qctx->client, false, qctx->rpz_st->m.policy, qctx->rpz_st->m.type, qctx->zone, @@ -6332,7 +6491,7 @@ query_checkrpz(query_ctx_t *qctx, isc_result_t result) break; case DNS_RPZ_POLICY_NODATA: qctx->nxrewrite = true; - /* FALLTHROUGH */ + /* FALLTHROUGH */ case DNS_RPZ_POLICY_DNS64: result = DNS_R_NXRRSET; qctx->rpz = true; @@ -6346,9 +6505,10 @@ query_checkrpz(query_ctx_t *qctx, isc_result_t result) * the node by iterating later, * and set the TTL then. */ - if (dns_rdataset_isassociated(qctx->rdataset)) + if (dns_rdataset_isassociated(qctx->rdataset)) { dns_rdataset_disassociate( qctx->rdataset); + } } else { /* * We will add this rdataset. @@ -6369,8 +6529,9 @@ query_checkrpz(query_ctx_t *qctx, isc_result_t result) RUNTIME_CHECK(result == ISC_R_SUCCESS); dns_rdata_reset(&rdata); result = query_rpzcname(qctx, &cname.cname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_COMPLETE); + } qctx->fname = NULL; qctx->want_restart = true; return (ISC_R_COMPLETE); @@ -6382,8 +6543,9 @@ query_checkrpz(query_ctx_t *qctx, isc_result_t result) */ result = query_rpzcname(qctx, &qctx->rpz_st->m.rpz->cname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ISC_R_COMPLETE); + } qctx->fname = NULL; qctx->want_restart = true; return (ISC_R_COMPLETE); @@ -6701,8 +6863,9 @@ query_gotanswer(query_ctx_t *qctx, isc_result_t res) case DNS_R_NCACHENXDOMAIN: result = query_redirect(qctx); - if (result != ISC_R_COMPLETE) + if (result != ISC_R_COMPLETE) { return (result); + } return (query_ncache(qctx, DNS_R_NCACHENXDOMAIN)); case DNS_R_NCACHENXRRSET: @@ -6783,8 +6946,9 @@ query_addnoqnameproof(query_ctx_t *qctx) if (fname == NULL) { dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) + if (dbuf == NULL) { goto cleanup; + } fname = ns_client_newname(client, dbuf, &b); } @@ -6800,8 +6964,9 @@ query_addnoqnameproof(query_ctx_t *qctx) dns_rdataset_disassociate(negsig); } - if (fname == NULL || neg == NULL || negsig == NULL) + if (fname == NULL || neg == NULL || negsig == NULL) { goto cleanup; + } result = dns_rdataset_getclosest(qctx->noqname, fname, neg, negsig); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -6911,10 +7076,11 @@ query_respond_any(query_ctx_t *qctx) } qctx->rpz_st = qctx->client->query.rpz_st; - if (qctx->rpz_st != NULL) + if (qctx->rpz_st != NULL) { qctx->rdataset->ttl = ISC_MIN(qctx->rdataset->ttl, qctx->rpz_st->m.ttl); + } if (!qctx->is_zone && RECURSIONOK(qctx->client)) { dns_name_t *name; @@ -7110,8 +7276,9 @@ query_addanswer(query_ctx_t *qctx) if (result == ISC_R_NOMORE) { #ifndef dns64_bis_return_excluded_addresses if (qctx->dns64_exclude) { - if (!qctx->is_zone) + if (!qctx->is_zone) { return (ns_query_done(qctx)); + } /* * Add a fake SOA record. */ @@ -7119,7 +7286,7 @@ query_addanswer(query_ctx_t *qctx) DNS_SECTION_AUTHORITY); return (ns_query_done(qctx)); } -#endif +#endif /* ifndef dns64_bis_return_excluded_addresses */ if (qctx->is_zone) { return (query_nodata(qctx, DNS_R_NXDOMAIN)); } else { @@ -7335,32 +7502,37 @@ query_dns64(query_ctx_t *qctx) view->dns64cnt * 16 * dns_rdataset_count(qctx->rdataset)); result = dns_message_gettemprdataset(client->message, &dns64_rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdatalist(client->message, &dns64_rdatalist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdatalist_init(dns64_rdatalist); dns64_rdatalist->rdclass = dns_rdataclass_in; dns64_rdatalist->type = dns_rdatatype_aaaa; - if (client->query.dns64_ttl != UINT32_MAX) + if (client->query.dns64_ttl != UINT32_MAX) { dns64_rdatalist->ttl = ISC_MIN(qctx->rdataset->ttl, client->query.dns64_ttl); - else + } else { dns64_rdatalist->ttl = ISC_MIN(qctx->rdataset->ttl, 600); + } - if (RECURSIONOK(client)) + if (RECURSIONOK(client)) { flags |= DNS_DNS64_RECURSIVE; + } /* * We use the signatures from the A lookup to set DNS_DNS64_DNSSEC * as this provides a easy way to see if the answer was signed. */ if (WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL && - dns_rdataset_isassociated(qctx->sigrdataset)) + dns_rdataset_isassociated(qctx->sigrdataset)) { flags |= DNS_DNS64_DNSSEC; + } for (result = dns_rdataset_first(qctx->rdataset); result == ISC_R_SUCCESS; @@ -7382,8 +7554,9 @@ query_dns64(query_ctx_t *qctx) isc_buffer_forward(buffer, 16); result = dns_message_gettemprdata(client->message, &dns64_rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdata_init(dns64_rdata); dns_rdata_fromregion(dns64_rdata, dns_rdataclass_in, dns_rdatatype_aaaa, &r); @@ -7393,15 +7566,18 @@ query_dns64(query_ctx_t *qctx) dns_rdata_reset(&rdata); } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto cleanup; + } - if (ISC_LIST_EMPTY(dns64_rdatalist->rdata)) + if (ISC_LIST_EMPTY(dns64_rdatalist->rdata)) { goto cleanup; + } result = dns_rdatalist_tordataset(dns64_rdatalist, dns64_rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdataset_setownercase(dns64_rdataset, mname); client->query.attributes |= NS_QUERYATTR_NOADDITIONAL; dns64_rdataset->trust = qctx->rdataset->trust; @@ -7416,14 +7592,17 @@ query_dns64(query_ctx_t *qctx) result = ISC_R_SUCCESS; cleanup: - if (buffer != NULL) + if (buffer != NULL) { isc_buffer_free(&buffer); + } - if (dns64_rdata != NULL) + if (dns64_rdata != NULL) { dns_message_puttemprdata(client->message, &dns64_rdata); + } - if (dns64_rdataset != NULL) + if (dns64_rdataset != NULL) { dns_message_puttemprdataset(client->message, &dns64_rdataset); + } if (dns64_rdatalist != NULL) { for (dns64_rdata = ISC_LIST_HEAD(dns64_rdatalist->rdata); @@ -7499,11 +7678,13 @@ query_filter64(query_ctx_t *qctx) isc_buffer_allocate(client->mctx, &buffer, 16 * dns_rdataset_count(qctx->rdataset)); result = dns_message_gettemprdataset(client->message, &myrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdatalist(client->message, &myrdatalist); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdatalist_init(myrdatalist); myrdatalist->rdclass = dns_rdataclass_in; @@ -7514,16 +7695,18 @@ query_filter64(query_ctx_t *qctx) for (result = dns_rdataset_first(qctx->rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(qctx->rdataset)) { - if (!client->query.dns64_aaaaok[i++]) + if (!client->query.dns64_aaaaok[i++]) { continue; + } dns_rdataset_current(qctx->rdataset, &rdata); INSIST(rdata.length == 16); isc_buffer_putmem(buffer, rdata.data, rdata.length); isc_buffer_remainingregion(buffer, &r); isc_buffer_forward(buffer, rdata.length); result = dns_message_gettemprdata(client->message, &myrdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdata_init(myrdata); dns_rdata_fromregion(myrdata, dns_rdataclass_in, dns_rdatatype_aaaa, &r); @@ -7531,12 +7714,14 @@ query_filter64(query_ctx_t *qctx) myrdata = NULL; dns_rdata_reset(&rdata); } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto cleanup; + } result = dns_rdatalist_tordataset(myrdatalist, myrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_rdataset_setownercase(myrdataset, name); client->query.attributes |= NS_QUERYATTR_NOADDITIONAL; if (mname == name) { @@ -7556,14 +7741,17 @@ query_filter64(query_ctx_t *qctx) dns_message_takebuffer(client->message, &buffer); cleanup: - if (buffer != NULL) + if (buffer != NULL) { isc_buffer_free(&buffer); + } - if (myrdata != NULL) + if (myrdata != NULL) { dns_message_puttemprdata(client->message, &myrdata); + } - if (myrdataset != NULL) + if (myrdataset != NULL) { dns_message_puttemprdataset(client->message, &myrdataset); + } if (myrdatalist != NULL) { for (myrdata = ISC_LIST_HEAD(myrdatalist->rdata); @@ -7597,8 +7785,9 @@ query_notfound(query_ctx_t *qctx) INSIST(!qctx->is_zone); - if (qctx->db != NULL) + if (qctx->db != NULL) { dns_db_detach(&qctx->db); + } /* * If the cache doesn't even have the root NS, @@ -7750,10 +7939,12 @@ query_zone_delegation(query_ctx_t *qctx) qctx->client, qctx->client->query.qname, qctx->qtype, DNS_GETDB_PARTIAL, &tzone, &tdb, &tversion); if (result != ISC_R_SUCCESS) { - if (tdb != NULL) + if (tdb != NULL) { dns_db_detach(&tdb); - if (tzone != NULL) + } + if (tzone != NULL) { dns_zone_detach(&tzone); + } } else { qctx->options &= ~DNS_GETDB_NOEXACT; ns_client_putrdataset(qctx->client, &qctx->rdataset); @@ -7765,12 +7956,15 @@ query_zone_delegation(query_ctx_t *qctx) ns_client_releasename(qctx->client, &qctx->fname); } - if (qctx->node != NULL) + if (qctx->node != NULL) { dns_db_detachnode(qctx->db, &qctx->node); - if (qctx->db != NULL) + } + if (qctx->db != NULL) { dns_db_detach(&qctx->db); - if (qctx->zone != NULL) + } + if (qctx->zone != NULL) { dns_zone_detach(&qctx->zone); + } qctx->version = NULL; RESTORE(qctx->version, tversion); RESTORE(qctx->db, tdb); @@ -7989,8 +8183,9 @@ query_addds(query_ctx_t *qctx) */ rdataset = ns_client_newrdataset(client); sigrdataset = ns_client_newrdataset(client); - if (rdataset == NULL || sigrdataset == NULL) + if (rdataset == NULL || sigrdataset == NULL) { goto cleanup; + } /* * Look for the DS record, which may or may not be present. @@ -8001,15 +8196,18 @@ query_addds(query_ctx_t *qctx) /* * If we didn't find it, look for an NSEC. */ - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = dns_db_findrdataset( qctx->db, qctx->node, qctx->version, dns_rdatatype_nsec, 0, client->now, rdataset, sigrdataset); - if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) + } + if (result != ISC_R_SUCCESS && result != ISC_R_NOTFOUND) { goto addnsec3; + } if (!dns_rdataset_isassociated(rdataset) || - !dns_rdataset_isassociated(sigrdataset)) + !dns_rdataset_isassociated(sigrdataset)) { goto addnsec3; + } /* * We've already added the NS record, so if the name's not there, @@ -8017,14 +8215,16 @@ query_addds(query_ctx_t *qctx) * query_addrrset(). */ result = dns_message_firstname(client->message, DNS_SECTION_AUTHORITY); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } rname = NULL; dns_message_currentname(client->message, DNS_SECTION_AUTHORITY, &rname); result = dns_message_findtype(rname, dns_rdatatype_ns, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } ISC_LIST_APPEND(rname->list, rdataset, link); ISC_LIST_APPEND(rname->list, sigrdataset, link); @@ -8033,26 +8233,31 @@ query_addds(query_ctx_t *qctx) return; addnsec3: - if (!dns_db_iszone(qctx->db)) + if (!dns_db_iszone(qctx->db)) { goto cleanup; + } /* * Add the NSEC3 which proves the DS does not exist. */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) + if (dbuf == NULL) { goto cleanup; + } fname = ns_client_newname(client, dbuf, &b); dns_fixedname_init(&fixed); - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); - if (dns_rdataset_isassociated(sigrdataset)) + } + if (dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } name = dns_fixedname_name(&qctx->dsname); query_findclosestnsec3(name, qctx->db, qctx->version, client, rdataset, sigrdataset, fname, true, dns_fixedname_name(&fixed)); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { goto cleanup; + } query_addrrset(qctx, &fname, &rdataset, &sigrdataset, dbuf, DNS_SECTION_AUTHORITY); /* @@ -8067,13 +8272,15 @@ addnsec3: fixfname(client, &fname, &dbuf, &b); fixrdataset(client, &rdataset); fixrdataset(client, &sigrdataset); - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) + if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { goto cleanup; + } query_findclosestnsec3(dns_fixedname_name(&fixed), qctx->db, qctx->version, client, rdataset, sigrdataset, fname, false, NULL); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { goto cleanup; + } query_addrrset(qctx, &fname, &rdataset, &sigrdataset, dbuf, DNS_SECTION_AUTHORITY); } @@ -8104,18 +8311,20 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) #ifdef dns64_bis_return_excluded_addresses if (qctx->dns64) -#else +#else /* ifdef dns64_bis_return_excluded_addresses */ if (qctx->dns64 && !qctx->dns64_exclude) -#endif +#endif /* ifdef dns64_bis_return_excluded_addresses */ { isc_buffer_t b; /* * Restore the answers from the previous AAAA lookup. */ - if (qctx->rdataset != NULL) + if (qctx->rdataset != NULL) { ns_client_putrdataset(qctx->client, &qctx->rdataset); - if (qctx->sigrdataset != NULL) + } + if (qctx->sigrdataset != NULL) { ns_client_putrdataset(qctx->client, &qctx->sigrdataset); + } RESTORE(qctx->rdataset, qctx->client->query.dns64_aaaa); RESTORE(qctx->sigrdataset, qctx->client->query.dns64_sigaaaa); if (qctx->fname == NULL) { @@ -8126,7 +8335,6 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) "failed (3)"); QUERY_ERROR(qctx, ISC_R_NOMEMORY); return (ns_query_done(qctx)); - ; } qctx->fname = ns_client_newname(qctx->client, qctx->dbuf, &b); @@ -8136,7 +8344,6 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) "failed (3)"); QUERY_ERROR(qctx, ISC_R_NOMEMORY); return (ns_query_done(qctx)); - ; } } dns_name_copynf(qctx->client->query.qname, qctx->fname); @@ -8145,9 +8352,10 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) /* * Resume the diverted processing of the AAAA response? */ - if (qctx->dns64_exclude) + if (qctx->dns64_exclude) { return (query_prepresponse(qctx)); -#endif + } +#endif /* ifdef dns64_bis_return_excluded_addresses */ } else if ((result == DNS_R_NXRRSET || result == DNS_R_NCACHENXRRSET) && !ISC_LIST_EMPTY(qctx->view->dns64) && !qctx->nxrewrite && qctx->client->message->rdclass == dns_rdataclass_in && @@ -8168,8 +8376,10 @@ query_nodata(query_ctx_t *qctx, isc_result_t res) qctx->rdataset->ttl; break; } - if (dns_rdataset_first(qctx->rdataset) == ISC_R_SUCCESS) + if (dns_rdataset_first(qctx->rdataset) == + ISC_R_SUCCESS) { qctx->client->query.dns64_ttl = 0; + } break; case DNS_R_NXRRSET: qctx->client->query.dns64_ttl = @@ -8227,8 +8437,9 @@ query_sign_nodata(query_ctx_t *qctx) /* * Look for a NSEC3 record if we don't have a NSEC record. */ - if (qctx->redirected) + if (qctx->redirected) { return (ns_query_done(qctx)); + } if (!dns_rdataset_isassociated(qctx->rdataset) && WANTDNSSEC(qctx->client)) { if ((qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) == 0) { @@ -8419,8 +8630,9 @@ query_nxdomain(query_ctx_t *qctx, bool empty_wild) if (!empty_wild) { result = query_redirect(qctx); - if (result != ISC_R_COMPLETE) + if (result != ISC_R_COMPLETE) { return (result); + } } if (dns_rdataset_isassociated(qctx->rdataset)) { @@ -8467,20 +8679,22 @@ query_nxdomain(query_ctx_t *qctx, bool empty_wild) /* * Add NSEC record if we found one. */ - if (dns_rdataset_isassociated(qctx->rdataset)) + if (dns_rdataset_isassociated(qctx->rdataset)) { query_addrrset(qctx, &qctx->fname, &qctx->rdataset, &qctx->sigrdataset, NULL, DNS_SECTION_AUTHORITY); + } query_addwildcardproof(qctx, false, false); } /* * Set message rcode. */ - if (empty_wild) + if (empty_wild) { qctx->client->message->rcode = dns_rcode_noerror; - else + } else { qctx->client->message->rcode = dns_rcode_nxdomain; + } return (ns_query_done(qctx)); @@ -8604,10 +8818,12 @@ query_synthttl(dns_rdataset_t *soardataset, dns_rdataset_t *sigsoardataset, ttl = ISC_MIN(ttl, sigsoardataset->ttl); ttl = ISC_MIN(ttl, p1rdataset->ttl); ttl = ISC_MIN(ttl, sigp1rdataset->ttl); - if (p2rdataset != NULL) + if (p2rdataset != NULL) { ttl = ISC_MIN(ttl, p2rdataset->ttl); - if (sigp2rdataset != NULL) + } + if (sigp2rdataset != NULL) { ttl = ISC_MIN(ttl, sigp2rdataset->ttl); + } return (ttl); } @@ -9123,7 +9339,7 @@ query_coveringnsec(query_ctx_t *qctx) { goto cleanup; } - /* FALLTHROUGH */ + /* FALLTHROUGH */ case DNS_R_CNAME: if (!qctx->resuming && !STALE(&rdataset) && rdataset.ttl == 0 && RECURSIONOK(qctx->client)) { @@ -9368,8 +9584,9 @@ query_cname(query_ctx_t *qctx) /* * Add the CNAME to the answer section. */ - if (WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL) + if (WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL) { sigrdatasetp = &qctx->sigrdataset; + } if (WANTDNSSEC(qctx->client) && (qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) != 0) { @@ -9385,8 +9602,9 @@ query_cname(query_ctx_t *qctx) qctx->noqname = NULL; } - if (!qctx->is_zone && RECURSIONOK(qctx->client)) + if (!qctx->is_zone && RECURSIONOK(qctx->client)) { query_prefetch(qctx->client, qctx->fname, qctx->rdataset); + } query_addrrset(qctx, &qctx->fname, &qctx->rdataset, sigrdatasetp, qctx->dbuf, DNS_SECTION_ANSWER); @@ -9405,8 +9623,9 @@ query_cname(query_ctx_t *qctx) */ tname = NULL; result = dns_message_gettempname(qctx->client->message, &tname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ns_query_done(qctx)); + } result = dns_rdataset_first(trdataset); if (result != ISC_R_SUCCESS) { @@ -9425,8 +9644,9 @@ query_cname(query_ctx_t *qctx) dns_rdata_freestruct(&cname); ns_client_qnamereplace(qctx->client, tname); qctx->want_restart = true; - if (!WANTRECURSION(qctx->client)) + if (!WANTRECURSION(qctx->client)) { qctx->options |= DNS_GETDB_NOLOG; + } query_addauth(qctx); @@ -9477,8 +9697,9 @@ query_dname(query_ctx_t *qctx) /* * Add the DNAME to the answer section. */ - if (WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL) + if (WANTDNSSEC(qctx->client) && qctx->sigrdataset != NULL) { sigrdatasetp = &qctx->sigrdataset; + } if (WANTDNSSEC(qctx->client) && (qctx->fname->attributes & DNS_NAMEATTR_WILDCARD) != 0) { @@ -9488,8 +9709,9 @@ query_dname(query_ctx_t *qctx) qctx->need_wildcardproof = true; } - if (!qctx->is_zone && RECURSIONOK(qctx->client)) + if (!qctx->is_zone && RECURSIONOK(qctx->client)) { query_prefetch(qctx->client, qctx->fname, qctx->rdataset); + } query_addrrset(qctx, &qctx->fname, &qctx->rdataset, sigrdatasetp, qctx->dbuf, DNS_SECTION_ANSWER); @@ -9504,8 +9726,9 @@ query_dname(query_ctx_t *qctx) */ tname = NULL; result = dns_message_gettempname(qctx->client->message, &tname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ns_query_done(qctx)); + } result = dns_rdataset_first(trdataset); if (result != ISC_R_SUCCESS) { @@ -9546,10 +9769,12 @@ query_dname(query_ctx_t *qctx) * we should return YXDOMAIN if the constructed * name would be too long. */ - if (result == DNS_R_NAMETOOLONG) + if (result == DNS_R_NAMETOOLONG) { qctx->client->message->rcode = dns_rcode_yxdomain; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (ns_query_done(qctx)); + } ns_client_keepname(qctx->client, qctx->fname, qctx->dbuf); @@ -9568,8 +9793,9 @@ query_dname(query_ctx_t *qctx) * since the synthesized CNAME is NOT in the zone. */ result = query_addcname(qctx, trdataset->trust, trdataset->ttl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (ns_query_done(qctx)); + } /* * Switch to the new qname and restart. @@ -9577,8 +9803,9 @@ query_dname(query_ctx_t *qctx) ns_client_qnamereplace(qctx->client, qctx->fname); qctx->fname = NULL; qctx->want_restart = true; - if (!WANTRECURSION(qctx->client)) + if (!WANTRECURSION(qctx->client)) { qctx->options |= DNS_GETDB_NOLOG; + } query_addauth(qctx); @@ -9603,8 +9830,9 @@ query_addcname(query_ctx_t *qctx, dns_trust_t trust, dns_ttl_t ttl) isc_result_t result; result = dns_message_gettempname(client->message, &aname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_dup(client->query.qname, client->mctx, aname); result = dns_message_gettemprdatalist(client->message, &rdatalist); @@ -9646,12 +9874,14 @@ query_addcname(query_ctx_t *qctx, dns_trust_t trust, dns_ttl_t ttl) query_addrrset(qctx, &aname, &rdataset, NULL, NULL, DNS_SECTION_ANSWER); if (rdataset != NULL) { - if (dns_rdataset_isassociated(rdataset)) + if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } dns_message_puttemprdataset(client->message, &rdataset); } - if (aname != NULL) + if (aname != NULL) { dns_message_puttempname(client->message, &aname); + } return (ISC_R_SUCCESS); } @@ -9736,8 +9966,9 @@ query_addsoa(query_ctx_t *qctx, unsigned int override_ttl, * Get resources and make 'name' be the database origin. */ result = dns_message_gettempname(client->message, &name); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } dns_name_init(name, NULL); dns_name_clone(dns_db_origin(qctx->db), name); rdataset = ns_client_newrdataset(client); @@ -9796,38 +10027,46 @@ query_addsoa(query_ctx_t *qctx, unsigned int override_ttl, if (override_ttl != UINT32_MAX && override_ttl < rdataset->ttl) { rdataset->ttl = override_ttl; - if (sigrdataset != NULL) + if (sigrdataset != NULL) { sigrdataset->ttl = override_ttl; + } } /* * Add the SOA and its SIG to the response, with the * TTLs adjusted per RFC2308 section 3. */ - if (rdataset->ttl > soa.minimum) + if (rdataset->ttl > soa.minimum) { rdataset->ttl = soa.minimum; - if (sigrdataset != NULL && sigrdataset->ttl > soa.minimum) + } + if (sigrdataset != NULL && sigrdataset->ttl > soa.minimum) { sigrdataset->ttl = soa.minimum; + } - if (sigrdataset != NULL) + if (sigrdataset != NULL) { sigrdatasetp = &sigrdataset; - else + } else { sigrdatasetp = NULL; + } - if (section == DNS_SECTION_ADDITIONAL) + if (section == DNS_SECTION_ADDITIONAL) { rdataset->attributes |= DNS_RDATASETATTR_REQUIRED; + } query_addrrset(qctx, &name, &rdataset, sigrdatasetp, NULL, section); } cleanup: ns_client_putrdataset(client, &rdataset); - if (sigrdataset != NULL) + if (sigrdataset != NULL) { ns_client_putrdataset(client, &sigrdataset); - if (name != NULL) + } + if (name != NULL) { ns_client_releasename(client, &name); - if (node != NULL) + } + if (node != NULL) { dns_db_detachnode(qctx->db, &node); + } return (eresult); } @@ -9968,8 +10207,9 @@ query_addbestns(query_ctx_t *qctx) */ result = query_getdb(client, client->query.qname, dns_rdatatype_ns, 0, &zone, &db, &version, &is_zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } db_find: /* @@ -10227,19 +10467,22 @@ again: * We'll need some resources... */ dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) + if (dbuf == NULL) { goto cleanup; + } fname = ns_client_newname(client, dbuf, &b); rdataset = ns_client_newrdataset(client); sigrdataset = ns_client_newrdataset(client); - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) + if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { goto cleanup; + } result = dns_db_findext(qctx->db, name, qctx->version, dns_rdatatype_nsec, options, 0, &node, fname, &cm, &ci, rdataset, sigrdataset); - if (node != NULL) + if (node != NULL) { dns_db_detachnode(qctx->db, &node); + } if (!dns_rdataset_isassociated(rdataset)) { /* @@ -10255,8 +10498,9 @@ again: /* * Sanity check. */ - if (labels == 0U) + if (labels == 0U) { goto cleanup; + } dns_name_split(cname, labels, NULL, cname); result = dns_db_findext(qctx->db, cname, qctx->version, dns_rdatatype_nsec, options, 0, @@ -10269,96 +10513,112 @@ again: query_findclosestnsec3(cname, qctx->db, qctx->version, client, rdataset, sigrdataset, fname, true, cname); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { goto cleanup; - if (!ispositive) + } + if (!ispositive) { query_addrrset(qctx, &fname, &rdataset, &sigrdataset, dbuf, DNS_SECTION_AUTHORITY); + } /* * Replace resources which were consumed by query_addrrset. */ if (fname == NULL) { dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) + if (dbuf == NULL) { goto cleanup; + } fname = ns_client_newname(client, dbuf, &b); } - if (rdataset == NULL) + if (rdataset == NULL) { rdataset = ns_client_newrdataset(client); - else if (dns_rdataset_isassociated(rdataset)) + } else if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } - if (sigrdataset == NULL) + if (sigrdataset == NULL) { sigrdataset = ns_client_newrdataset(client); - else if (dns_rdataset_isassociated(sigrdataset)) + } else if (dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) + if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { goto cleanup; + } /* * Add no qname proof. */ labels = dns_name_countlabels(cname) + 1; - if (dns_name_countlabels(name) == labels) + if (dns_name_countlabels(name) == labels) { dns_name_copynf(name, wname); - else + } else { dns_name_split(name, labels, NULL, wname); + } query_findclosestnsec3(wname, qctx->db, qctx->version, client, rdataset, sigrdataset, fname, false, NULL); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { goto cleanup; + } query_addrrset(qctx, &fname, &rdataset, &sigrdataset, dbuf, DNS_SECTION_AUTHORITY); - if (ispositive) + if (ispositive) { goto cleanup; + } /* * Replace resources which were consumed by query_addrrset. */ if (fname == NULL) { dbuf = ns_client_getnamebuf(client); - if (dbuf == NULL) + if (dbuf == NULL) { goto cleanup; + } fname = ns_client_newname(client, dbuf, &b); } - if (rdataset == NULL) + if (rdataset == NULL) { rdataset = ns_client_newrdataset(client); - else if (dns_rdataset_isassociated(rdataset)) + } else if (dns_rdataset_isassociated(rdataset)) { dns_rdataset_disassociate(rdataset); + } - if (sigrdataset == NULL) + if (sigrdataset == NULL) { sigrdataset = ns_client_newrdataset(client); - else if (dns_rdataset_isassociated(sigrdataset)) + } else if (dns_rdataset_isassociated(sigrdataset)) { dns_rdataset_disassociate(sigrdataset); + } - if (fname == NULL || rdataset == NULL || sigrdataset == NULL) + if (fname == NULL || rdataset == NULL || sigrdataset == NULL) { goto cleanup; + } /* * Add the no wildcard proof. */ result = dns_name_concatenate(dns_wildcardname, cname, wname, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } query_findclosestnsec3(wname, qctx->db, qctx->version, client, rdataset, sigrdataset, fname, nodata, NULL); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { goto cleanup; + } query_addrrset(qctx, &fname, &rdataset, &sigrdataset, dbuf, DNS_SECTION_AUTHORITY); goto cleanup; } else if (result == DNS_R_NXDOMAIN) { - if (!ispositive) + if (!ispositive) { result = dns_rdataset_first(rdataset); + } if (result == ISC_R_SUCCESS) { dns_rdataset_current(rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &nsec, NULL); @@ -10371,17 +10631,20 @@ again: * Check for a pathological condition created when * serving some malformed signed zones and bail out. */ - if (dns_name_countlabels(name) == nlabels) + if (dns_name_countlabels(name) == nlabels) { goto cleanup; + } - if (olabels > nlabels) + if (olabels > nlabels) { dns_name_split(name, olabels, NULL, wname); - else + } else { dns_name_split(name, nlabels, NULL, wname); + } result = dns_name_concatenate(dns_wildcardname, wname, wname, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { have_wname = true; + } dns_rdata_freestruct(&nsec); } query_addrrset(qctx, &fname, &rdataset, &sigrdataset, dbuf, @@ -10446,8 +10709,9 @@ query_addauth(query_ctx_t *qctx) * Add NSEC records to the authority section if they're needed for * DNSSEC wildcard proofs. */ - if (qctx->need_wildcardproof && dns_db_issecure(qctx->db)) + if (qctx->need_wildcardproof && dns_db_issecure(qctx->db)) { query_addwildcardproof(qctx, true, false); + } } /* @@ -10460,8 +10724,9 @@ query_sortlist_order_2element(const dns_rdata_t *rdata, const void *arg) { isc_netaddr_t netaddr; - if (rdata_tonetaddr(rdata, &netaddr) != ISC_R_SUCCESS) + if (rdata_tonetaddr(rdata, &netaddr) != ISC_R_SUCCESS) { return (INT_MAX); + } return (ns_sortlist_addrorder2(&netaddr, arg)); } @@ -10474,8 +10739,9 @@ query_sortlist_order_1element(const dns_rdata_t *rdata, const void *arg) { isc_netaddr_t netaddr; - if (rdata_tonetaddr(rdata, &netaddr) != ISC_R_SUCCESS) + if (rdata_tonetaddr(rdata, &netaddr) != ISC_R_SUCCESS) { return (INT_MAX); + } return (ns_sortlist_addrorder1(&netaddr, arg)); } @@ -10741,8 +11007,9 @@ log_query(ns_client_t *client, unsigned int flags, unsigned int extflags) dns_rdataset_t *rdataset; int level = ISC_LOG_INFO; - if (!isc_log_wouldlog(ns_lctx, level)) + if (!isc_log_wouldlog(ns_lctx, level)) { return; + } rdataset = ISC_LIST_HEAD(client->query.qname->list); INSIST(rdataset != NULL); @@ -10751,9 +11018,10 @@ log_query(ns_client_t *client, unsigned int flags, unsigned int extflags) dns_rdatatype_format(rdataset->type, typebuf, sizeof(typebuf)); isc_netaddr_format(&client->destaddr, onbuf, sizeof(onbuf)); - if (client->ednsversion >= 0) + if (client->ednsversion >= 0) { snprintf(ednsbuf, sizeof(ednsbuf), "E(%hd)", client->ednsversion); + } if (HAVEECS(client)) { strlcpy(ecsbuf, " [ECS ", sizeof(ecsbuf)); @@ -10781,8 +11049,9 @@ log_queryerror(ns_client_t *client, isc_result_t result, int line, int level) const char * namep, *typep, *classp, *sep1, *sep2; dns_rdataset_t *rdataset; - if (!isc_log_wouldlog(ns_lctx, level)) + if (!isc_log_wouldlog(ns_lctx, level)) { return; + } namep = typep = classp = sep1 = sep2 = ""; @@ -10838,11 +11107,13 @@ ns_query_start(ns_client_t *client) */ client->cleanup = query_cleanup; - if ((message->flags & DNS_MESSAGEFLAG_RD) != 0) + if ((message->flags & DNS_MESSAGEFLAG_RD) != 0) { client->query.attributes |= NS_QUERYATTR_WANTRECURSION; + } - if ((client->extflags & DNS_MESSAGEEXTFLAG_DO) != 0) + if ((client->extflags & DNS_MESSAGEEXTFLAG_DO) != 0) { client->attributes |= NS_CLIENTATTR_WANTDNSSEC; + } switch (client->view->minimalresponses) { case dns_minimal_no: @@ -10855,8 +11126,9 @@ ns_query_start(ns_client_t *client) client->query.attributes |= NS_QUERYATTR_NOAUTHORITY; break; case dns_minimal_noauthrec: - if ((message->flags & DNS_MESSAGEFLAG_RD) != 0) + if ((message->flags & DNS_MESSAGEFLAG_RD) != 0) { client->query.attributes |= NS_QUERYATTR_NOAUTHORITY; + } break; } @@ -10913,8 +11185,9 @@ ns_query_start(ns_client_t *client) return; } - if ((client->sctx->options & NS_SERVER_LOGQUERIES) != 0) + if ((client->sctx->options & NS_SERVER_LOGQUERIES) != 0) { log_query(client, saved_flags, saved_extflags); + } /* * Check for meta-queries like IXFR and AXFR. @@ -10967,16 +11240,19 @@ ns_query_start(ns_client_t *client) * Maybe turn on minimal responses for ANY queries. */ if (qtype == dns_rdatatype_any && client->view->minimal_any && - !TCP(client)) + !TCP(client)) { client->query.attributes |= (NS_QUERYATTR_NOAUTHORITY | NS_QUERYATTR_NOADDITIONAL); + } /* * Turn on minimal responses for EDNS/UDP bufsize 512 queries. */ - if (client->ednsversion >= 0 && client->udpsize <= 512U && !TCP(client)) + if (client->ednsversion >= 0 && client->udpsize <= 512U && + !TCP(client)) { client->query.attributes |= (NS_QUERYATTR_NOAUTHORITY | NS_QUERYATTR_NOADDITIONAL); + } /* * If the client has requested that DNSSEC checking be disabled, @@ -11016,8 +11292,9 @@ ns_query_start(ns_client_t *client) * Set NS_CLIENTATTR_WANTAD if the client has set AD in the query. * This allows AD to be returned on queries without DO set. */ - if ((message->flags & DNS_MESSAGEFLAG_AD) != 0) + if ((message->flags & DNS_MESSAGEFLAG_AD) != 0) { client->attributes |= NS_CLIENTATTR_WANTAD; + } /* * This is an ordinary query. @@ -11035,15 +11312,17 @@ ns_query_start(ns_client_t *client) * If "-T noaa" has been set on the command line don't set * AA on authoritative answers. */ - if ((client->sctx->options & NS_SERVER_NOAA) == 0) + if ((client->sctx->options & NS_SERVER_NOAA) == 0) { message->flags |= DNS_MESSAGEFLAG_AA; + } /* * Set AD. We must clear it if we add non-validated data to a * response. */ - if (WANTDNSSEC(client) || WANTAD(client)) + if (WANTDNSSEC(client) || WANTAD(client)) { message->flags |= DNS_MESSAGEFLAG_AD; + } (void)query_setup(client, qtype); } diff --git a/lib/ns/sortlist.c b/lib/ns/sortlist.c index 9a4953af8a..ba7fc1d8e5 100644 --- a/lib/ns/sortlist.c +++ b/lib/ns/sortlist.c @@ -27,8 +27,9 @@ ns_sortlist_setup(dns_acl_t *acl, dns_aclenv_t *env, isc_netaddr_t *clientaddr, { unsigned int i; - if (acl == NULL) + if (acl == NULL) { goto dont_sort; + } for (i = 0; i < acl->length; i++) { /* @@ -43,16 +44,17 @@ ns_sortlist_setup(dns_acl_t *acl, dns_aclenv_t *env, isc_netaddr_t *clientaddr, if (e->type == dns_aclelementtype_nestedacl) { dns_acl_t *inner = e->nestedacl; - if (inner->length == 0) + if (inner->length == 0) { try_elt = e; - else if (inner->length > 2) + } else if (inner->length > 2) { goto dont_sort; - else if (inner->elements[0].negative) + } else if (inner->elements[0].negative) { goto dont_sort; - else { + } else { try_elt = &inner->elements[0]; - if (inner->length == 2) + if (inner->length == 2) { order_elt = &inner->elements[1]; + } } } else { /* diff --git a/lib/ns/tests/notify_test.c b/lib/ns/tests/notify_test.c index 6ef131e640..37ad0e47bf 100644 --- a/lib/ns/tests/notify_test.c +++ b/lib/ns/tests/notify_test.c @@ -143,7 +143,7 @@ notify_start(void **state) ns_test_cleanup_zone(); isc_nmhandle_unref(client->handle); } -#endif +#endif /* if defined(USE_LIBTOOL) || LD_WRAP */ int main(void) @@ -155,9 +155,9 @@ main(void) }; return (cmocka_run_group_tests(tests, NULL, NULL)); -#else +#else /* if defined(USE_LIBTOOL) || LD_WRAP */ print_message("1..0 # Skip notify_test requires libtool or LD_WRAP\n"); -#endif +#endif /* if defined(USE_LIBTOOL) || LD_WRAP */ } #else /* HAVE_CMOCKA && !__SANITIZE_ADDRESS__ */ diff --git a/lib/ns/tests/nstest.c b/lib/ns/tests/nstest.c index 35faaa44a5..ab26b6fc08 100644 --- a/lib/ns/tests/nstest.c +++ b/lib/ns/tests/nstest.c @@ -381,8 +381,9 @@ ns_test_makeview(const char *name, bool with_cache, dns_view_t **viewp) return (ISC_R_SUCCESS); cleanup: - if (view != NULL) + if (view != NULL) { dns_view_detach(&view); + } return (result); } @@ -406,14 +407,16 @@ ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, dns_fixedname_t fixorigin; dns_name_t * origin; - if (view == NULL) + if (view == NULL) { CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view)); - else if (!keepview) + } else if (!keepview) { keepview = true; + } zone = *zonep; - if (zone == NULL) + if (zone == NULL) { CHECK(dns_zone_create(&zone, mctx)); + } isc_buffer_constinit(&buffer, name, strlen(name)); isc_buffer_add(&buffer, strlen(name)); @@ -425,18 +428,21 @@ ns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view, dns_zone_setclass(zone, view->rdclass); dns_view_addzone(view, zone); - if (!keepview) + if (!keepview) { dns_view_detach(&view); + } *zonep = zone; return (ISC_R_SUCCESS); cleanup: - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); - if (view != NULL) + } + if (view != NULL) { dns_view_detach(&view); + } return (result); } @@ -458,8 +464,9 @@ ns_test_managezone(dns_zone_t *zone) REQUIRE(zonemgr != NULL); result = dns_zonemgr_setsize(zonemgr, 1); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_zonemgr_managezone(zonemgr, zone); return (result); @@ -888,13 +895,13 @@ ns_test_nap(uint32_t usec) nanosleep(&ts, NULL); #elif HAVE_USLEEP usleep(usec); -#else +#else /* ifdef HAVE_NANOSLEEP */ /* * No fractional-second sleep function is available, so we * round up to the nearest second and sleep instead */ sleep((usec / 1000000) + 1); -#endif +#endif /* ifdef HAVE_NANOSLEEP */ } isc_result_t @@ -908,13 +915,15 @@ ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, 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, dbtype, dns_rdataclass_in, 0, NULL, db); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_load(*db, testfile, dns_masterformat_text, 0); return (result); @@ -923,12 +932,13 @@ ns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin, static int fromhex(char c) { - if (c >= '0' && c <= '9') + if (c >= '0' && c <= '9') { return (c - '0'); - else if (c >= 'a' && c <= 'f') + } else if (c >= 'a' && c <= 'f') { return (c - 'a' + 10); - else if (c >= 'A' && c <= 'F') + } else if (c >= 'A' && c <= 'F') { return (c - 'A' + 10); + } printf("bad input format: %02x\n", c); exit(3); @@ -948,8 +958,9 @@ ns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, int n; result = isc_stdio_open(file, "r", &f); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } bp = buf; while (fgets(s, sizeof(s), f) != NULL) { @@ -957,8 +968,9 @@ ns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, wp = s; len = 0; while (*rp != '\0') { - if (*rp == '#') + if (*rp == '#') { break; + } if (*rp != ' ' && *rp != '\t' && *rp != '\r' && *rp != '\n') { *wp++ = *rp; @@ -966,12 +978,15 @@ ns_test_getdata(const char *file, unsigned char *buf, size_t bufsiz, } rp++; } - if (len == 0U) + if (len == 0U) { continue; - if (len % 2 != 0U) + } + if (len % 2 != 0U) { CHECK(ISC_R_UNEXPECTEDEND); - if (len > bufsiz * 2) + } + if (len > bufsiz * 2) { CHECK(ISC_R_NOSPACE); + } rp = s; for (i = 0; i < len; i += 2) { n = fromhex(*rp++); diff --git a/lib/ns/tests/plugin_test.c b/lib/ns/tests/plugin_test.c index eab070ddd7..0a0afe123f 100644 --- a/lib/ns/tests/plugin_test.c +++ b/lib/ns/tests/plugin_test.c @@ -66,8 +66,10 @@ _teardown(void **state) */ typedef struct { const ns_test_id_t id; /* libns test identifier */ - const char * input; /* source string - plugin name or path */ - size_t output_size; /* size of target char array to allocate */ + const char * input; /* source string - plugin name or path + * */ + size_t output_size; /* size of target char array to + * allocate */ isc_result_t result; /* expected return value */ const char * output; /* expected output string */ } ns_plugin_expandpath_test_params_t; @@ -149,9 +151,9 @@ ns_plugin_expandpath_test(void **state) .result = ISC_R_SUCCESS, #ifndef WIN32 .output = NAMED_PLUGINDIR "/foo.so", -#else +#else /* ifndef WIN32 */ .output = "foo.so", -#endif +#endif /* ifndef WIN32 */ }, { NS_TEST_ID("no space at all in target buffer"), @@ -178,7 +180,7 @@ ns_plugin_expandpath_test(void **state) .output_size = 7, .result = ISC_R_NOSPACE, }, -#endif +#endif /* ifndef WIN32 */ }; for (i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) { @@ -207,4 +209,4 @@ main(void) return (0); } -#endif +#endif /* if HAVE_CMOCKA */ diff --git a/lib/ns/tests/query_test.c b/lib/ns/tests/query_test.c index 87ba7a2b8a..ad6e7c4f55 100644 --- a/lib/ns/tests/query_test.c +++ b/lib/ns/tests/query_test.c @@ -59,22 +59,28 @@ _teardown(void **state) } /***** - ***** ns__query_sfcache() tests - *****/ +***** ns__query_sfcache() tests +*****/ /*% * Structure containing parameters for ns__query_sfcache_test(). */ typedef struct { - const ns_test_id_t id; /* libns test identifier */ - unsigned int qflags; /* query flags */ - bool cache_entry_present; /* whether a SERVFAIL cache entry - matching the query should be - present */ - uint32_t cache_entry_flags; /* NS_FAILCACHE_* flags to set for - the SERVFAIL cache entry */ - bool servfail_expected; /* whether a cached SERVFAIL is - expected to be returned */ + const ns_test_id_t id; /* libns test identifier */ + unsigned int qflags; /* query flags */ + bool cache_entry_present; /* whether a SERVFAIL + * cache entry + * matching the query + * should be + * present */ + uint32_t cache_entry_flags; /* NS_FAILCACHE_* flags to + * set for + * the SERVFAIL cache entry + * */ + bool servfail_expected; /* whether a cached + * SERVFAIL is + * expected to be returned + * */ } ns__query_sfcache_test_params_t; /*% @@ -247,8 +253,8 @@ ns__query_sfcache_test(void **state) } /***** - ***** ns__query_start() tests - *****/ +***** ns__query_start() tests +*****/ /*% * Structure containing parameters for ns__query_start_test(). @@ -258,24 +264,31 @@ typedef struct { const char * qname; /* QNAME */ dns_rdatatype_t qtype; /* QTYPE */ unsigned int qflags; /* query flags */ - bool disable_name_checks; /* if set to true, owner name - checks will be disabled for the - view created */ + bool disable_name_checks; /* if set to true, owner + * name + * checks will + * be disabled for the + * view created + * */ bool recursive_service; /* if set to true, the view - created will have a cache - database attached */ - const char *auth_zone_origin; /* origin name of the zone the - created view will be - authoritative for */ - const char *auth_zone_path; /* path to load the authoritative - zone from */ - enum { /* expected result: */ + * created will + * have a cache + * database + * attached */ + const char *auth_zone_origin; /* origin name of the zone + * the + * created view will be + * authoritative for */ + const char *auth_zone_path; /* path to load the + * authoritative + * zone from */ + enum { /* expected result: */ NS__QUERY_START_R_INVALID, NS__QUERY_START_R_REFUSE, /* query should be REFUSED */ NS__QUERY_START_R_CACHE, /* query should be answered from - cache */ + * cache */ NS__QUERY_START_R_AUTH, /* query should be answered using - authoritative data */ + * authoritative data */ } expected_result; } ns__query_start_test_params_t; @@ -593,7 +606,7 @@ ns__query_start_test(void **state) run_start_test(&tests[i]); } } -#endif +#endif /* if defined(USE_LIBTOOL) || LD_WRAP */ int main(void) @@ -607,9 +620,9 @@ main(void) }; return (cmocka_run_group_tests(tests, NULL, NULL)); -#else +#else /* if defined(USE_LIBTOOL) || LD_WRAP */ print_message("1..0 # Skip query_test requires libtool or LD_WRAP\n"); -#endif +#endif /* if defined(USE_LIBTOOL) || LD_WRAP */ } #else /* HAVE_CMOCKA && !__SANITIZE_ADDRESS__ */ diff --git a/lib/ns/update.c b/lib/ns/update.c index ba3cc2410d..f53fbeed0f 100644 --- a/lib/ns/update.c +++ b/lib/ns/update.c @@ -321,8 +321,9 @@ inc_stats(ns_client_t *client, dns_zone_t *zone, isc_statscounter_t counter) if (zone != NULL) { isc_stats_t *zonestats = dns_zone_getrequeststats(zone); - if (zonestats != NULL) + if (zonestats != NULL) { isc_stats_increment(zonestats, counter); + } } } @@ -496,8 +497,9 @@ update_one_rr(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff, dns_difftuple_t *tuple = NULL; isc_result_t result; result = dns_difftuple_create(diff->mctx, op, name, ttl, rdata, &tuple); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } return (do_one_tuple(&tuple, db, ver, diff)); } @@ -556,11 +558,13 @@ foreach_node_rr_action(void *data, dns_rdataset_t *rdataset) dns_rdataset_current(rdataset, &rr.rdata); rr.ttl = rdataset->ttl; result = (*ctx->rr_action)(ctx->rr_action_data, &rr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { return (result); + } return (ISC_R_SUCCESS); } @@ -594,15 +598,18 @@ foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, node = NULL; result = dns_db_findnodeext(db, name, false, &cm, &ci, &node); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } iter = NULL; result = dns_db_allrdatasets(db, node, ver, (isc_stdtime_t)0, &iter); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } for (result = dns_rdatasetiter_first(iter); result == ISC_R_SUCCESS; result = dns_rdatasetiter_next(iter)) { @@ -614,11 +621,13 @@ foreach_rrset(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = (*action)(action_data, &rdataset); dns_rdataset_disassociate(&rdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_iterator; + } } - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { result = ISC_R_SUCCESS; + } cleanup_iterator: dns_rdatasetiter_destroy(&iter); @@ -679,20 +688,24 @@ foreach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_clientinfo_init(&ci, NULL, (ver != oldver) ? ver : NULL); dns_db_closeversion(db, &oldver, false); - if (type == dns_rdatatype_any) + if (type == dns_rdatatype_any) { return (foreach_node_rr(db, ver, name, rr_action, rr_action_data)); + } node = NULL; if (type == dns_rdatatype_nsec3 || - (type == dns_rdatatype_rrsig && covers == dns_rdatatype_nsec3)) + (type == dns_rdatatype_rrsig && covers == dns_rdatatype_nsec3)) { result = dns_db_findnsec3node(db, name, false, &node); - else + } else { result = dns_db_findnodeext(db, name, false, &cm, &ci, &node); - if (result == ISC_R_NOTFOUND) + } + if (result == ISC_R_NOTFOUND) { return (ISC_R_SUCCESS); - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { return (result); + } dns_rdataset_init(&rdataset); result = dns_db_findrdataset(db, node, ver, type, covers, @@ -701,8 +714,9 @@ foreach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = ISC_R_SUCCESS; goto cleanup_node; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_node; + } if (rr_action == add_rr_prepare_action) { add_rr_prepare_ctx_t *ctx = rr_action_data; @@ -718,11 +732,13 @@ foreach_rr(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, dns_rdataset_current(&rdataset, &rr.rdata); rr.ttl = rdataset.ttl; result = (*rr_action)(rr_action_data, &rr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup_rdataset; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto cleanup_rdataset; + } result = ISC_R_SUCCESS; cleanup_rdataset: @@ -907,8 +923,9 @@ ssu_checkrule(void *data, dns_rdataset_t *rrset) * if we're normally not allowed to. */ if (rrset->type == dns_rdatatype_rrsig || - rrset->type == dns_rdatatype_nsec) + rrset->type == dns_rdatatype_nsec) { return (ISC_R_SUCCESS); + } result = dns_ssutable_checkrules( ssuinfo->table, ssuinfo->signer, ssuinfo->name, ssuinfo->addr, ssuinfo->tcp, ssuinfo->aclenv, rrset->type, ssuinfo->key); @@ -973,19 +990,22 @@ static isc_result_t temp_check_rrset(dns_difftuple_t *a, dns_difftuple_t *b) { for (;;) { - if (a == NULL || b == NULL) + if (a == NULL || b == NULL) { break; + } INSIST(a->op == DNS_DIFFOP_EXISTS && b->op == DNS_DIFFOP_EXISTS); INSIST(a->rdata.type == b->rdata.type); INSIST(dns_name_equal(&a->name, &b->name)); - if (dns_rdata_casecompare(&a->rdata, &b->rdata) != 0) + if (dns_rdata_casecompare(&a->rdata, &b->rdata) != 0) { return (DNS_R_NXRRSET); + } a = ISC_LIST_NEXT(a, link); b = ISC_LIST_NEXT(b, link); } - if (a != NULL || b != NULL) + if (a != NULL || b != NULL) { return (DNS_R_NXRRSET); + } return (ISC_R_SUCCESS); } @@ -1003,11 +1023,13 @@ temp_order(const void *av, const void *bv) dns_difftuple_t const * b = *bp; int r; r = dns_name_compare(&a->name, &b->name); - if (r != 0) + if (r != 0) { return (r); + } r = (b->rdata.type - a->rdata.type); - if (r != 0) + if (r != 0) { return (r); + } r = dns_rdata_casecompare(&a->rdata, &b->rdata); return (r); } @@ -1062,20 +1084,21 @@ temp_check(isc_mem_t *mctx, dns_diff_t *temp, dns_db_t *db, dns_rdatatype_t type, covers; dns_rdataset_t rdataset; dns_diff_t d_rrs; /* Database RRs with - this name and type */ + * this name and type */ dns_diff_t u_rrs; /* Update RRs with - this name and type */ + * this name and type */ *typep = type = t->rdata.type; if (type == dns_rdatatype_rrsig || - type == dns_rdatatype_sig) + type == dns_rdatatype_sig) { covers = dns_rdata_covers(&t->rdata); - else if (type == dns_rdatatype_any) { + } else if (type == dns_rdatatype_any) { dns_db_detachnode(db, &node); dns_diff_clear(&trash); return (DNS_R_NXRRSET); - } else + } else { covers = 0; + } /* * Collect all database RRs for this name and type @@ -1100,14 +1123,17 @@ temp_check(isc_mem_t *mctx, dns_diff_t *temp, dns_db_t *db, dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdataset_current(&rdataset, &rdata); result = temp_append(&d_rrs, name, &rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } result = dns_diff_sort(&d_rrs, temp_order); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } /* * Collect all update RRs for this name and type @@ -1125,8 +1151,9 @@ temp_check(isc_mem_t *mctx, dns_diff_t *temp, dns_db_t *db, /* Compare the two sorted lists. */ result = temp_check_rrset(ISC_LIST_HEAD(u_rrs.tuples), ISC_LIST_HEAD(d_rrs.tuples)); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } /* * We are done with the tuples, but we can't free @@ -1250,16 +1277,21 @@ replaces_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) dns_rdata_rrsig_t updatesig, dbsig; isc_result_t result; - if (db_rr->type != update_rr->type) + if (db_rr->type != update_rr->type) { return (false); - if (db_rr->type == dns_rdatatype_cname) + } + if (db_rr->type == dns_rdatatype_cname) { return (true); - if (db_rr->type == dns_rdatatype_dname) + } + if (db_rr->type == dns_rdatatype_dname) { return (true); - if (db_rr->type == dns_rdatatype_soa) + } + if (db_rr->type == dns_rdatatype_soa) { return (true); - if (db_rr->type == dns_rdatatype_nsec) + } + if (db_rr->type == dns_rdatatype_nsec) { return (true); + } if (db_rr->type == dns_rdatatype_rrsig) { /* * Replace existing RRSIG with the same keyid, @@ -1271,8 +1303,9 @@ replaces_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) RUNTIME_CHECK(result == ISC_R_SUCCESS); if (dbsig.keyid == updatesig.keyid && dbsig.covered == updatesig.covered && - dbsig.algorithm == updatesig.algorithm) + dbsig.algorithm == updatesig.algorithm) { return (true); + } } if (db_rr->type == dns_rdatatype_wks) { /* @@ -1287,8 +1320,9 @@ replaces_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) } if (db_rr->type == dns_rdatatype_nsec3param) { - if (db_rr->length != update_rr->length) + if (db_rr->length != update_rr->length) { return (false); + } INSIST(db_rr->length >= 4 && update_rr->length >= 4); /* * Replace NSEC3PARAM records that only differ by the @@ -1296,8 +1330,9 @@ replaces_p(dns_rdata_t *update_rr, dns_rdata_t *db_rr) */ if (db_rr->data[0] == update_rr->data[0] && memcmp(db_rr->data + 2, update_rr->data + 2, - update_rr->length - 2) == 0) + update_rr->length - 2) == 0) { return (true); + } } return (false); } @@ -1472,10 +1507,12 @@ update_soa_serial(dns_db_t *db, dns_dbversion_t *ver, dns_diff_t *diff, result = ISC_R_SUCCESS; failure: - if (addtuple != NULL) + if (addtuple != NULL) { dns_difftuple_free(&addtuple); - if (deltuple != NULL) + } + if (deltuple != NULL) { dns_difftuple_free(&deltuple); + } return (result); } @@ -1510,8 +1547,9 @@ check_soa_increment(dns_db_t *db, dns_dbversion_t *ver, update_serial = dns_soa_getserial(update_rdata); result = dns_db_getsoaserial(db, ver, &db_serial); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } if (DNS_SERIAL_GE(db_serial, update_serial)) { *ok = false; @@ -1558,8 +1596,9 @@ respond(ns_client_t *client, isc_result_t result) isc_result_t msg_result; msg_result = dns_message_reply(client->message, true); - if (msg_result != ISC_R_SUCCESS) + if (msg_result != ISC_R_SUCCESS) { goto msg_failure; + } client->message->rcode = dns_result_torcode(result); ns_client_send(client); @@ -1588,8 +1627,9 @@ ns_update_start(ns_client_t *client, isc_result_t sigresult) * Interpret the zone section. */ result = dns_message_firstname(request, DNS_SECTION_ZONE); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { FAILC(DNS_R_FORMERR, "update zone section empty"); + } /* * The zone section must contain exactly one "question", and @@ -1598,21 +1638,25 @@ ns_update_start(ns_client_t *client, isc_result_t sigresult) zonename = NULL; dns_message_currentname(request, DNS_SECTION_ZONE, &zonename); zone_rdataset = ISC_LIST_HEAD(zonename->list); - if (zone_rdataset->type != dns_rdatatype_soa) + if (zone_rdataset->type != dns_rdatatype_soa) { FAILC(DNS_R_FORMERR, "update zone section contains non-SOA"); - if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) + } + if (ISC_LIST_NEXT(zone_rdataset, link) != NULL) { FAILC(DNS_R_FORMERR, "update zone section contains multiple " "RRs"); + } /* The zone section must have exactly one name. */ result = dns_message_nextname(request, DNS_SECTION_ZONE); - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { FAILC(DNS_R_FORMERR, "update zone section contains multiple " "RRs"); + } result = dns_zt_find(client->view->zonetable, zonename, 0, NULL, &zone); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { FAILC(DNS_R_NOTAUTH, "not authoritative for update zone"); + } /* * If there is a raw (unsigned) zone associated with this @@ -1632,8 +1676,9 @@ ns_update_start(ns_client_t *client, isc_result_t sigresult) * We can now fail due to a bad signature as we now know * that we are the master. */ - if (sigresult != ISC_R_SUCCESS) + if (sigresult != ISC_R_SUCCESS) { FAIL(sigresult); + } CHECK(send_update_event(client, zone)); break; case dns_zone_slave: @@ -1660,8 +1705,9 @@ failure: * simply give an error response without switching tasks. */ respond(client, result); - if (zone != NULL) + if (zone != NULL) { dns_zone_detach(&zone); + } } /*% @@ -1685,13 +1731,15 @@ remove_orphaned_ds(dns_db_t *db, dns_dbversion_t *newver, dns_diff_t *diff) if (!((tupple->op == DNS_DIFFOP_DEL && tupple->rdata.type == dns_rdatatype_ns) || (tupple->op == DNS_DIFFOP_ADD && - tupple->rdata.type == dns_rdatatype_ds))) + tupple->rdata.type == dns_rdatatype_ds))) { continue; + } CHECK(rrset_exists(db, newver, &tupple->name, dns_rdatatype_ns, 0, &ns_exists)); if (ns_exists && - !dns_name_equal(&tupple->name, dns_db_origin(db))) + !dns_name_equal(&tupple->name, dns_db_origin(db))) { continue; + } CHECK(delete_if(true_p, db, newver, &tupple->name, dns_rdatatype_ds, 0, NULL, &temp_diff)); } @@ -1736,8 +1784,9 @@ check_mx(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, for (t = ISC_LIST_HEAD(diff->tuples); t != NULL; t = ISC_LIST_NEXT(t, link)) { if (t->op != DNS_DIFFOP_ADD || - t->rdata.type != dns_rdatatype_mx) + t->rdata.type != dns_rdatatype_mx) { continue; + } result = dns_rdata_tostruct(&t->rdata, &mx, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); @@ -1750,11 +1799,13 @@ check_mx(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, isaddress = false; if ((options & DNS_ZONEOPT_CHECKMX) != 0 && strlcpy(tmp, namebuf, sizeof(tmp)) < sizeof(tmp)) { - if (tmp[strlen(tmp) - 1] == '.') + if (tmp[strlen(tmp) - 1] == '.') { tmp[strlen(tmp) - 1] = '\0'; + } if (inet_pton(AF_INET, tmp, &addr) == 1 || - inet_pton(AF_INET6, tmp, &addr6) == 1) + inet_pton(AF_INET6, tmp, &addr6) == 1) { isaddress = true; + } } if (isaddress && (options & DNS_ZONEOPT_CHECKMXFAIL) != 0) { @@ -1772,19 +1823,22 @@ check_mx(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, /* * Check zone integrity checks. */ - if ((options & DNS_ZONEOPT_CHECKINTEGRITY) == 0) + if ((options & DNS_ZONEOPT_CHECKINTEGRITY) == 0) { continue; + } result = dns_db_find(db, &mx.mx, newver, dns_rdatatype_a, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { continue; + } if (result == DNS_R_NXRRSET) { result = dns_db_find(db, &mx.mx, newver, dns_rdatatype_aaaa, 0, 0, NULL, foundname, NULL, NULL); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { continue; + } } if (result == DNS_R_NXRRSET || result == DNS_R_NXDOMAIN) { @@ -1818,10 +1872,11 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, isc_result_t result; dns_rdataset_init(&rdataset); - if (rdata->type == dns_rdatatype_nsec3) + if (rdata->type == dns_rdatatype_nsec3) { CHECK(dns_db_findnsec3node(db, name, false, &node)); - else + } else { CHECK(dns_db_findnode(db, name, false, &node)); + } result = dns_db_findrdataset(db, node, ver, rdata->type, 0, (isc_stdtime_t)0, &rdataset, NULL); if (result == ISC_R_NOTFOUND) { @@ -1834,8 +1889,9 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, result = dns_rdataset_next(&rdataset)) { dns_rdata_t myrdata = DNS_RDATA_INIT; dns_rdataset_current(&rdataset, &myrdata); - if (!dns_rdata_casecompare(&myrdata, rdata)) + if (!dns_rdata_casecompare(&myrdata, rdata)) { break; + } } dns_rdataset_disassociate(&rdataset); if (result == ISC_R_SUCCESS) { @@ -1846,8 +1902,9 @@ rr_exists(dns_db_t *db, dns_dbversion_t *ver, dns_name_t *name, } failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); + } return (result); } @@ -1864,40 +1921,49 @@ get_iterations(dns_db_t *db, dns_dbversion_t *ver, dns_rdatatype_t privatetype, dns_rdataset_init(&rdataset); result = dns_db_getoriginnode(db, &node); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_db_findrdataset(db, node, ver, dns_rdatatype_nsec3param, 0, (isc_stdtime_t)0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto try_private; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { dns_rdata_t rdata = DNS_RDATA_INIT; dns_rdataset_current(&rdataset, &rdata); CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); - if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) + if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) { continue; - if (nsec3param.iterations > iterations) + } + if (nsec3param.iterations > iterations) { iterations = nsec3param.iterations; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } dns_rdataset_disassociate(&rdataset); try_private: - if (privatetype == 0) + if (privatetype == 0) { goto success; + } result = dns_db_findrdataset(db, node, ver, privatetype, 0, (isc_stdtime_t)0, &rdataset, NULL); - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { goto success; - if (result != ISC_R_SUCCESS) + } + if (result != ISC_R_SUCCESS) { goto failure; + } for (result = dns_rdataset_first(&rdataset); result == ISC_R_SUCCESS; result = dns_rdataset_next(&rdataset)) { @@ -1907,26 +1973,32 @@ try_private: dns_rdataset_current(&rdataset, &rdata); if (!dns_nsec3param_fromprivate(&private, &rdata, buf, - sizeof(buf))) + sizeof(buf))) { continue; + } CHECK(dns_rdata_tostruct(&rdata, &nsec3param, NULL)); - if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) + if ((nsec3param.flags & DNS_NSEC3FLAG_REMOVE) != 0) { continue; - if (nsec3param.iterations > iterations) + } + if (nsec3param.iterations > iterations) { iterations = nsec3param.iterations; + } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { goto failure; + } success: *iterationsp = iterations; result = ISC_R_SUCCESS; failure: - if (node != NULL) + if (node != NULL) { dns_db_detachnode(db, &node); - if (dns_rdataset_isassociated(&rdataset)) + } + if (dns_rdataset_isassociated(&rdataset)) { dns_rdataset_disassociate(&rdataset); + } return (result); } @@ -1947,8 +2019,9 @@ check_dnssec(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, /* Scan the tuples for an NSEC-only DNSKEY or an NSEC3PARAM */ for (tuple = ISC_LIST_HEAD(diff->tuples); tuple != NULL; tuple = ISC_LIST_NEXT(tuple, link)) { - if (tuple->op != DNS_DIFFOP_ADD) + if (tuple->op != DNS_DIFFOP_ADD) { continue; + } if (tuple->rdata.type == dns_rdatatype_dnskey) { uint8_t alg; @@ -1972,15 +2045,17 @@ check_dnssec(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, * will trigger a delayed change), so we can ignore * ISC_R_NOTFOUND here. */ - if (result == ISC_R_NOTFOUND) + if (result == ISC_R_NOTFOUND) { result = ISC_R_SUCCESS; + } CHECK(result); } /* Check existing DB for NSEC3 */ - if (!nsec3) + if (!nsec3) { CHECK(dns_nsec3_activex(db, ver, false, privatetype, &nsec3)); + } /* Refuse to allow NSEC3 with NSEC-only keys */ if (nseconly && nsec3) { @@ -2037,8 +2112,9 @@ add_nsec3param_records(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, next = ISC_LIST_NEXT(tuple, link); if (tuple->rdata.type != dns_rdatatype_nsec3param || - !dns_name_equal(name, &tuple->name)) + !dns_name_equal(name, &tuple->name)) { continue; + } ISC_LIST_UNLINK(diff->tuples, tuple, link); ISC_LIST_APPEND(temp_diff.tuples, tuple, link); } @@ -2093,8 +2169,9 @@ add_nsec3param_records(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, next = ISC_LIST_NEXT(tuple, link); ISC_LIST_UNLINK(temp_diff.tuples, tuple, link); ISC_LIST_APPEND(diff->tuples, tuple, link); - } else + } else { next = ISC_LIST_NEXT(tuple, link); + } } /* @@ -2185,8 +2262,9 @@ add_nsec3param_records(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, * are to be used later. */ result = dns_nsec_nseconly(db, ver, &nseconly); - if (result == ISC_R_NOTFOUND || nseconly) + if (result == ISC_R_NOTFOUND || nseconly) { buf[2] |= DNS_NSEC3FLAG_INITIAL; + } /* * See if this CREATE request already exists. @@ -2227,8 +2305,9 @@ add_nsec3param_records(ns_client_t *client, dns_zone_t *zone, dns_db_t *db, ISC_LIST_UNLINK(temp_diff.tuples, tuple, link); dns_diff_appendminimal(diff, &tuple); dns_rdata_reset(&rdata); - } else + } else { next = ISC_LIST_NEXT(tuple, link); + } } for (tuple = ISC_LIST_HEAD(temp_diff.tuples); tuple != NULL; @@ -2280,8 +2359,9 @@ rollback_private(dns_db_t *db, dns_rdatatype_t privatetype, isc_mem_t * mctx = diff->mctx; isc_result_t result; - if (privatetype == 0) + if (privatetype == 0) { return (ISC_R_SUCCESS); + } dns_diff_init(mctx, &temp_diff); @@ -2292,16 +2372,18 @@ rollback_private(dns_db_t *db, dns_rdatatype_t privatetype, next = ISC_LIST_NEXT(tuple, link); if (tuple->rdata.type != privatetype || - !dns_name_equal(name, &tuple->name)) + !dns_name_equal(name, &tuple->name)) { continue; + } /* * Allow records which indicate that a zone has been * signed with a DNSKEY to be removed. */ if (tuple->op == DNS_DIFFOP_DEL && tuple->rdata.length == 5 && - tuple->rdata.data[0] != 0 && tuple->rdata.data[4] != 0) + tuple->rdata.data[0] != 0 && tuple->rdata.data[4] != 0) { continue; + } ISC_LIST_UNLINK(diff->tuples, tuple, link); ISC_LIST_PREPEND(temp_diff.tuples, tuple, link); @@ -2351,8 +2433,9 @@ add_signing_records(dns_db_t *db, dns_rdatatype_t privatetype, for (tuple = ISC_LIST_HEAD(diff->tuples); tuple != NULL; tuple = next) { next = ISC_LIST_NEXT(tuple, link); - if (tuple->rdata.type != dns_rdatatype_dnskey) + if (tuple->rdata.type != dns_rdatatype_dnskey) { continue; + } ISC_LIST_UNLINK(diff->tuples, tuple, link); ISC_LIST_APPEND(temp_diff.tuples, tuple, link); @@ -2400,8 +2483,9 @@ add_signing_records(dns_db_t *db, dns_rdatatype_t privatetype, next = ISC_LIST_NEXT(tuple, link); ISC_LIST_UNLINK(temp_diff.tuples, tuple, link); ISC_LIST_APPEND(diff->tuples, tuple, link); - } else + } else { next = ISC_LIST_NEXT(tuple, link); + } } /* @@ -2414,9 +2498,11 @@ add_signing_records(dns_db_t *db, dns_rdatatype_t privatetype, result = dns_rdata_tostruct(&tuple->rdata, &dnskey, NULL); RUNTIME_CHECK(result == ISC_R_SUCCESS); - if ((dnskey.flags & (DNS_KEYFLAG_OWNERMASK | - DNS_KEYTYPE_NOAUTH)) != DNS_KEYOWNER_ZONE) + if ((dnskey.flags & + (DNS_KEYFLAG_OWNERMASK | DNS_KEYTYPE_NOAUTH)) != + DNS_KEYOWNER_ZONE) { continue; + } dns_rdata_toregion(&tuple->rdata, &r); @@ -2433,8 +2519,9 @@ add_signing_records(dns_db_t *db, dns_rdatatype_t privatetype, rdata.rdclass = tuple->rdata.rdclass; CHECK(rr_exists(db, ver, name, &rdata, &flag)); - if (flag) + if (flag) { continue; + } CHECK(dns_difftuple_create(diff->mctx, DNS_DIFFOP_ADD, name, 0, &rdata, &newtuple)); CHECK(do_one_tuple(&newtuple, db, ver, diff)); @@ -2464,8 +2551,9 @@ isdnssec(dns_db_t *db, dns_dbversion_t *ver, dns_rdatatype_t privatetype) isc_result_t result; bool build_nsec, build_nsec3; - if (dns_db_issecure(db)) + if (dns_db_issecure(db)) { return (true); + } result = dns_private_chains(db, ver, privatetype, &build_nsec, &build_nsec3); @@ -2545,20 +2633,23 @@ update_action(isc_task_t *task, isc_event_t *event) get_current_rr(request, DNS_SECTION_PREREQUISITE, zoneclass, &name, &rdata, &covers, &ttl, &update_class); - if (ttl != 0) + if (ttl != 0) { PREREQFAILC(DNS_R_FORMERR, "prerequisite TTL is not " "zero"); + } - if (!dns_name_issubdomain(name, zonename)) + if (!dns_name_issubdomain(name, zonename)) { PREREQFAILN(DNS_R_NOTZONE, name, "prerequisite name is out of zone"); + } if (update_class == dns_rdataclass_any) { - if (rdata.length != 0) + if (rdata.length != 0) { PREREQFAILC(DNS_R_FORMERR, "class ANY " "prerequisite " "RDATA is not " "empty"); + } if (rdata.type == dns_rdatatype_any) { CHECK(name_exists(db, ver, name, &flag)); if (!flag) { @@ -2581,11 +2672,12 @@ update_action(isc_task_t *task, isc_event_t *event) } } } else if (update_class == dns_rdataclass_none) { - if (rdata.length != 0) + if (rdata.length != 0) { PREREQFAILC(DNS_R_FORMERR, "class NONE " "prerequisite " "RDATA is not " "empty"); + } if (rdata.type == dns_rdatatype_any) { CHECK(name_exists(db, ver, name, &flag)); if (flag) { @@ -2620,8 +2712,9 @@ update_action(isc_task_t *task, isc_event_t *event) PREREQFAILC(DNS_R_FORMERR, "malformed prerequisite"); } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { FAIL(result); + } /* * Perform the final check of the "rrset exists (value dependent)" @@ -2635,16 +2728,18 @@ update_action(isc_task_t *task, isc_event_t *event) * type, and rdata. */ result = dns_diff_sort(&temp, temp_order); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { FAILC(result, "'RRset exists (value dependent)' " "prerequisite not satisfied"); + } tmpname = dns_fixedname_initname(&tmpnamefixed); result = temp_check(mctx, &temp, db, ver, tmpname, &type); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { FAILNT(result, tmpname, type, "'RRset exists (value dependent)' " "prerequisite not satisfied"); + } } update_log(client, zone, LOGLEVEL_DEBUG, "prerequisites are OK"); @@ -2653,17 +2748,19 @@ update_action(isc_task_t *task, isc_event_t *event) * Check Requestor's Permissions. It seems a bit silly to do this * only after prerequisite testing, but that is what RFC2136 says. */ - if (ssutable == NULL) + if (ssutable == NULL) { CHECK(checkupdateacl(client, dns_zone_getupdateacl(zone), "update", zonename, false, false)); - else if (client->signer == NULL && !TCPCLIENT(client)) + } else if (client->signer == NULL && !TCPCLIENT(client)) { CHECK(checkupdateacl(client, NULL, "update", zonename, false, true)); + } - if (dns_zone_getupdatedisabled(zone)) + if (dns_zone_getupdatedisabled(zone)) { FAILC(DNS_R_REFUSED, "dynamic update temporarily disabled " "because the zone is frozen. Use " "'rndc thaw' to re-enable updates."); + } /* * Perform the Update Section Prescan. @@ -2679,8 +2776,9 @@ update_action(isc_task_t *task, isc_event_t *event) get_current_rr(request, DNS_SECTION_UPDATE, zoneclass, &name, &rdata, &covers, &ttl, &update_class); - if (!dns_name_issubdomain(name, zonename)) + if (!dns_name_issubdomain(name, zonename)) { FAILC(DNS_R_NOTZONE, "update RR is outside zone"); + } if (update_class == zoneclass) { /* * Check for meta-RRs. The RFC2136 pseudocode says @@ -2691,16 +2789,19 @@ update_action(isc_task_t *task, isc_event_t *event) FAILC(DNS_R_FORMERR, "meta-RR in update"); } result = dns_zone_checknames(zone, name, &rdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { FAIL(DNS_R_REFUSED); + } } else if (update_class == dns_rdataclass_any) { if (ttl != 0 || rdata.length != 0 || (dns_rdatatype_ismeta(rdata.type) && - rdata.type != dns_rdatatype_any)) + rdata.type != dns_rdatatype_any)) { FAILC(DNS_R_FORMERR, "meta-RR in update"); + } } else if (update_class == dns_rdataclass_none) { - if (ttl != 0 || dns_rdatatype_ismeta(rdata.type)) + if (ttl != 0 || dns_rdatatype_ismeta(rdata.type)) { FAILC(DNS_R_FORMERR, "meta-RR in update"); + } } else { update_log(client, zone, ISC_LOG_WARNING, "update RR has incorrect class %d", @@ -2735,8 +2836,9 @@ update_action(isc_task_t *task, isc_event_t *event) dst_key_t * tsigkey = NULL; isc_netaddr_fromsockaddr(&netaddr, &client->peeraddr); - if (client->message->tsigkey != NULL) + if (client->message->tsigkey != NULL) { tsigkey = client->message->tsigkey->key; + } if (rdata.type != dns_rdatatype_any) { if (!dns_ssutable_checkrules( @@ -2756,8 +2858,9 @@ update_action(isc_task_t *task, isc_event_t *event) } } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { FAIL(result); + } update_log(client, zone, LOGLEVEL_DEBUG, "update section prescan OK"); @@ -2924,8 +3027,9 @@ update_action(isc_task_t *task, isc_event_t *event) "rdata_totext failed: %s]", dns_result_totext(result)); len = strlen(rdstr); - } else + } else { len = (int)isc_buffer_usedlength(&buf); + } update_log(client, zone, LOGLEVEL_PROTOCOL, "adding an RR at '%s' %s %.*s%s", namestr, typestr, len, rdstr, @@ -3060,16 +3164,18 @@ update_action(isc_task_t *task, isc_event_t *event) covers, &rdata, &diff)); } } - if (result != ISC_R_NOMORE) + if (result != ISC_R_NOMORE) { FAIL(result); + } /* * Check that any changes to DNSKEY/NSEC3PARAM records make sense. * If they don't then back out all changes to DNSKEY/NSEC3PARAM * records. */ - if (!ISC_LIST_EMPTY(diff.tuples)) + if (!ISC_LIST_EMPTY(diff.tuples)) { CHECK(check_dnssec(client, zone, db, ver, &diff)); + } if (!ISC_LIST_EMPTY(diff.tuples)) { unsigned int errors = 0; @@ -3091,8 +3197,9 @@ update_action(isc_task_t *task, isc_event_t *event) result = DNS_R_REFUSED; goto failure; } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } } /* @@ -3196,8 +3303,9 @@ update_action(isc_task_t *task, isc_event_t *event) journal = NULL; result = dns_journal_open(mctx, journalfile, DNS_JOURNAL_CREATE, &journal); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { FAILS(result, "journal open failed"); + } result = dns_journal_write_transaction(journal, &diff); if (result != ISC_R_SUCCESS) { @@ -3241,14 +3349,16 @@ update_action(isc_task_t *task, isc_event_t *event) dns_secalg_t algorithm; uint16_t keyid; - if (tuple->rdata.type != dns_rdatatype_dnskey) + if (tuple->rdata.type != dns_rdatatype_dnskey) { continue; + } dns_rdata_tostruct(&tuple->rdata, &dnskey, NULL); if ((dnskey.flags & (DNS_KEYFLAG_OWNERMASK | DNS_KEYTYPE_NOAUTH)) != - DNS_KEYOWNER_ZONE) + DNS_KEYOWNER_ZONE) { continue; + } dns_rdata_toregion(&tuple->rdata, &r); algorithm = dnskey.algorithm; @@ -3277,15 +3387,18 @@ update_action(isc_task_t *task, isc_event_t *event) dns_rdata_nsec3param_t nsec3param; if (tuple->rdata.type != privatetype || - tuple->op != DNS_DIFFOP_ADD) + tuple->op != DNS_DIFFOP_ADD) { continue; + } if (!dns_nsec3param_fromprivate(&tuple->rdata, &rdata, - buf, sizeof(buf))) + buf, sizeof(buf))) { continue; + } dns_rdata_tostruct(&rdata, &nsec3param, NULL); - if (nsec3param.flags == 0) + if (nsec3param.flags == 0) { continue; + } result = dns_zone_addnsec3chain(zone, &nsec3param); if (result != ISC_R_SUCCESS) { @@ -3314,19 +3427,23 @@ common: dns_diff_clear(&temp); dns_diff_clear(&diff); - if (oldver != NULL) + if (oldver != NULL) { dns_db_closeversion(db, &oldver, false); + } - if (db != NULL) + if (db != NULL) { dns_db_detach(&db); + } - if (ssutable != NULL) + if (ssutable != NULL) { dns_ssutable_detach(&ssutable); + } isc_task_detach(&task); uev->result = result; - if (zone != NULL) + if (zone != NULL) { INSIST(uev->zone == zone); /* we use this later */ + } uev->ev_type = DNS_EVENT_UPDATEDONE; uev->ev_action = updatedone_action; isc_task_send(client->task, &event); @@ -3358,8 +3475,9 @@ updatedone_action(isc_task_t *task, isc_event_t *event) inc_stats(client, uev->zone, ns_statscounter_updatefail); break; } - if (uev->zone != NULL) + if (uev->zone != NULL) { dns_zone_detach(&uev->zone); + } client->nupdates--; respond(client, uev->result); isc_event_free(&event); diff --git a/lib/ns/xfrout.c b/lib/ns/xfrout.c index 8d9a5a3d47..11b117d59e 100644 --- a/lib/ns/xfrout.c +++ b/lib/ns/xfrout.c @@ -113,8 +113,9 @@ inc_stats(ns_client_t *client, dns_zone_t *zone, isc_statscounter_t counter) ns_stats_increment(client->sctx->nsstats, counter); if (zone != NULL) { isc_stats_t *zonestats = dns_zone_getrequeststats(zone); - if (zonestats != NULL) + if (zonestats != NULL) { isc_stats_increment(zonestats, counter); + } } } @@ -137,10 +138,11 @@ log_rr(dns_name_t *name, dns_rdata_t *rdata, uint32_t ttl) rdl.rdclass = rdata->rdclass; rdl.ttl = ttl; if (rdata->type == dns_rdatatype_sig || - rdata->type == dns_rdatatype_rrsig) + rdata->type == dns_rdatatype_rrsig) { rdl.covers = dns_rdata_covers(rdata); - else + } else { rdl.covers = dns_rdatatype_none; + } dns_rdataset_init(&rds); dns_rdata_init(&rd); dns_rdata_clone(rdata, &rd); @@ -280,8 +282,9 @@ static void ixfr_rrstream_destroy(rrstream_t **rsp) { ixfr_rrstream_t *s = (ixfr_rrstream_t *)*rsp; - if (s->journal != NULL) + if (s->journal != NULL) { dns_journal_destroy(&s->journal); + } isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s)); } @@ -345,8 +348,9 @@ axfr_rrstream_first(rrstream_t *rs) axfr_rrstream_t *s = (axfr_rrstream_t *)rs; isc_result_t result; result = dns_rriterator_first(&s->it); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } /* Skip SOA records. */ for (;;) { dns_name_t * name_dummy = NULL; @@ -354,11 +358,13 @@ axfr_rrstream_first(rrstream_t *rs) dns_rdata_t *rdata = NULL; dns_rriterator_current(&s->it, &name_dummy, &ttl_dummy, NULL, &rdata); - if (rdata->type != dns_rdatatype_soa) + if (rdata->type != dns_rdatatype_soa) { break; + } result = dns_rriterator_next(&s->it); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } } return (result); } @@ -375,12 +381,14 @@ axfr_rrstream_next(rrstream_t *rs) uint32_t ttl_dummy; dns_rdata_t *rdata = NULL; result = dns_rriterator_next(&s->it); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { break; + } dns_rriterator_current(&s->it, &name_dummy, &ttl_dummy, NULL, &rdata); - if (rdata->type != dns_rdatatype_soa) + if (rdata->type != dns_rdatatype_soa) { break; + } } return (result); } @@ -404,8 +412,9 @@ static void axfr_rrstream_destroy(rrstream_t **rsp) { axfr_rrstream_t *s = (axfr_rrstream_t *)*rsp; - if (s->it_valid) + if (s->it_valid) { dns_rriterator_destroy(&s->it); + } isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s)); } @@ -487,8 +496,9 @@ static void soa_rrstream_destroy(rrstream_t **rsp) { soa_rrstream_t *s = (soa_rrstream_t *)*rsp; - if (s->soa_tuple != NULL) + if (s->soa_tuple != NULL) { dns_difftuple_free(&s->soa_tuple); + } isc_mem_putanddetach(&s->common.mctx, s, sizeof(*s)); } @@ -587,8 +597,9 @@ compound_rrstream_next(rrstream_t *rs) * are released before we switch streams. */ curstream->methods->pause(curstream); - if (s->state == 2) + if (s->state == 2) { return (ISC_R_NOMORE); + } s->state++; curstream = s->components[s->state]; s->result = curstream->methods->first(curstream); @@ -666,7 +677,7 @@ typedef struct { bool question_added; /* QUESTION section sent? */ bool end_of_stream; /* EOS has been reached */ isc_buffer_t buf; /* Buffer for message owner - names and rdatas */ + * names and rdatas */ isc_buffer_t txlenbuf; /* Transmit length buffer */ isc_buffer_t txbuf; /* Transmit message buffer */ size_t cbytes; /* Length of current message */ @@ -1198,8 +1209,9 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id, xfr->zone = NULL; xfr->db = NULL; xfr->ver = NULL; - if (zone != NULL) /* zone will be NULL if it's DLZ */ + if (zone != NULL) { /* zone will be NULL if it's DLZ */ dns_zone_attach(zone, &xfr->zone); + } dns_db_attach(db, &xfr->db); dns_db_attachversion(db, ver, &xfr->ver); xfr->question_added = false; @@ -1251,8 +1263,8 @@ xfrout_ctx_create(isc_mem_t *mctx, ns_client_t *client, unsigned int id, #if 0 CHECK(dns_timer_setidle(xfr->client->timer, - maxtime, idletime, false)); -#endif + maxtime,idletime,false)); +#endif /* if 0 */ /* * Register a shutdown callback with the client, so that we @@ -1323,12 +1335,14 @@ sendstream(xfrout_ctx_t *xfr) msg->id = xfr->id; msg->rcode = dns_rcode_noerror; msg->flags = DNS_MESSAGEFLAG_QR | DNS_MESSAGEFLAG_AA; - if ((xfr->client->attributes & NS_CLIENTATTR_RA) != 0) + if ((xfr->client->attributes & NS_CLIENTATTR_RA) != 0) { msg->flags |= DNS_MESSAGEFLAG_RA; + } CHECK(dns_message_settsigkey(msg, xfr->tsigkey)); CHECK(dns_message_setquerytsig(msg, xfr->lasttsig)); - if (xfr->lasttsig != NULL) + if (xfr->lasttsig != NULL) { isc_buffer_free(&xfr->lasttsig); + } msg->verified_sig = xfr->verified_tsig; /* @@ -1349,8 +1363,9 @@ sendstream(xfrout_ctx_t *xfr) /* * Account for reserved space. */ - if (xfr->tsigkey != NULL) + if (xfr->tsigkey != NULL) { INSIST(msg->reserved != 0U); + } isc_buffer_add(&xfr->buf, msg->reserved); /* @@ -1370,15 +1385,17 @@ sendstream(xfrout_ctx_t *xfr) qrdataset = NULL; result = dns_message_gettemprdataset(msg, &qrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } dns_rdataset_makequestion(qrdataset, xfr->client->message->rdclass, xfr->qtype); result = dns_message_gettempname(msg, &qname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } dns_name_init(qname, NULL); isc_buffer_availableregion(&xfr->buf, &r); INSIST(r.length >= xfr->qname->length); @@ -1445,12 +1462,14 @@ sendstream(xfrout_ctx_t *xfr) break; } - if (isc_log_wouldlog(ns_lctx, XFROUT_RR_LOGLEVEL)) + if (isc_log_wouldlog(ns_lctx, XFROUT_RR_LOGLEVEL)) { log_rr(name, rdata, ttl); /* XXX */ + } result = dns_message_gettempname(msg, &msgname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } dns_name_init(msgname, NULL); isc_buffer_availableregion(&xfr->buf, &r); INSIST(r.length >= name->length); @@ -1462,8 +1481,9 @@ sendstream(xfrout_ctx_t *xfr) isc_buffer_add(&xfr->buf, 10); result = dns_message_gettemprdata(msg, &msgrdata); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } isc_buffer_availableregion(&xfr->buf, &r); r.length = rdata->length; isc_buffer_putmem(&xfr->buf, rdata->data, rdata->length); @@ -1471,21 +1491,24 @@ sendstream(xfrout_ctx_t *xfr) dns_rdata_fromregion(msgrdata, rdata->rdclass, rdata->type, &r); result = dns_message_gettemprdatalist(msg, &msgrdl); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } msgrdl->type = rdata->type; msgrdl->rdclass = rdata->rdclass; msgrdl->ttl = ttl; if (rdata->type == dns_rdatatype_sig || - rdata->type == dns_rdatatype_rrsig) + rdata->type == dns_rdatatype_rrsig) { msgrdl->covers = dns_rdata_covers(rdata); - else + } else { msgrdl->covers = dns_rdatatype_none; + } ISC_LIST_APPEND(msgrdl->rdata, msgrdata, link); result = dns_message_gettemprdataset(msg, &msgrds); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto failure; + } result = dns_rdatalist_tordataset(msgrdl, msgrds); INSIST(result == ISC_R_SUCCESS); @@ -1503,8 +1526,9 @@ sendstream(xfrout_ctx_t *xfr) } CHECK(result); - if (!xfr->many_answers) + if (!xfr->many_answers) { break; + } /* * At this stage, at least 1 RR has been rendered into * the message. Check if we want to clamp this message @@ -1512,8 +1536,9 @@ sendstream(xfrout_ctx_t *xfr) */ if ((isc_buffer_usedlength(&xfr->buf) >= xfr->client->sctx->transfer_tcp_message_size) && - is_tcp) + is_tcp) { break; + } } if (is_tcp) { @@ -1552,32 +1577,37 @@ sendstream(xfrout_ctx_t *xfr) failure: if (msgname != NULL) { if (msgrds != NULL) { - if (dns_rdataset_isassociated(msgrds)) + if (dns_rdataset_isassociated(msgrds)) { dns_rdataset_disassociate(msgrds); + } dns_message_puttemprdataset(msg, &msgrds); } if (msgrdl != NULL) { ISC_LIST_UNLINK(msgrdl->rdata, msgrdata, link); dns_message_puttemprdatalist(msg, &msgrdl); } - if (msgrdata != NULL) + if (msgrdata != NULL) { dns_message_puttemprdata(msg, &msgrdata); + } dns_message_puttempname(msg, &msgname); } - if (tcpmsg != NULL) + if (tcpmsg != NULL) { dns_message_destroy(&tcpmsg); + } - if (cleanup_cctx) + if (cleanup_cctx) { dns_compress_invalidate(&cctx); + } /* * Make sure to release any locks held by database * iterators before returning from the event handler. */ xfr->stream->methods->pause(xfr->stream); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return; + } xfrout_fail(xfr, result, "sending zone data"); } @@ -1593,22 +1623,30 @@ xfrout_ctx_destroy(xfrout_ctx_t **xfrp) xfr->client->shutdown = NULL; xfr->client->shutdown_arg = NULL; - if (xfr->stream != NULL) + if (xfr->stream != NULL) { xfr->stream->methods->destroy(&xfr->stream); - if (xfr->buf.base != NULL) + } + if (xfr->buf.base != NULL) { isc_mem_put(xfr->mctx, xfr->buf.base, xfr->buf.length); - if (xfr->txmem != NULL) + } + if (xfr->txmem != NULL) { isc_mem_put(xfr->mctx, xfr->txmem, xfr->txmemlen); - if (xfr->lasttsig != NULL) + } + if (xfr->lasttsig != NULL) { isc_buffer_free(&xfr->lasttsig); - if (xfr->quota != NULL) + } + if (xfr->quota != NULL) { isc_quota_detach(&xfr->quota); - if (xfr->ver != NULL) + } + if (xfr->ver != NULL) { dns_db_closeversion(xfr->db, &xfr->ver, false); - if (xfr->zone != NULL) + } + if (xfr->zone != NULL) { dns_zone_detach(&xfr->zone); - if (xfr->db != NULL) + } + if (xfr->db != NULL) { dns_db_detach(&xfr->db); + } isc_mem_putanddetach(&xfr->mctx, xfr, sizeof(*xfr)); } @@ -1636,7 +1674,7 @@ xfrout_senddone(isc_nmhandle_t *handle, isc_result_t result, void *arg) #if 0 (void)isc_timer_touch(xfr->client->timer); -#endif +#endif /* if 0 */ if (xfr->shuttingdown == true) { xfrout_maybe_destroy(xfr); @@ -1690,16 +1728,16 @@ xfrout_maybe_destroy(xfrout_ctx_t *xfr) * If we are currently sending, cancel it and wait for * cancel event before destroying the context. */ - isc_socket_cancel(xfr->client->tcpsocket, xfr->client->task, + isc_socket_cancel(xfr->client->tcpsocket,xfr->client->task, ISC_SOCKCANCEL_SEND); } else { -#endif +#endif /* if 0 */ ns_client_drop(xfr->client, ISC_R_CANCELED); isc_nmhandle_unref(xfr->client->handle); xfrout_ctx_destroy(&xfr); #if 0 - } -#endif +} +#endif /* if 0 */ } static void diff --git a/lib/samples/nsprobe.c b/lib/samples/nsprobe.c index 5ff723ca16..3645a9abf3 100644 --- a/lib/samples/nsprobe.c +++ b/lib/samples/nsprobe.c @@ -15,7 +15,7 @@ #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -142,16 +142,19 @@ print_rdataset(dns_rdataset_t *rdataset, dns_name_t *owner) isc_region_t r; char t[4096]; - if (!debug_mode) + if (!debug_mode) { return (ISC_R_SUCCESS); + } isc_buffer_init(&target, t, sizeof(t)); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { return (ISC_R_SUCCESS); + } 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); @@ -171,8 +174,9 @@ print_name(dns_name_t *name) if (result == ISC_R_SUCCESS) { isc_buffer_usedregion(&target, &r); printf("%.*s", (int)r.length, (char *)r.base); - } else + } else { printf("(invalid name)"); + } return (result); } @@ -196,20 +200,25 @@ static void ctxs_destroy(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp, isc_socketmgr_t **socketmgrp, isc_timermgr_t **timermgrp) { - if (*taskmgrp != NULL) + if (*taskmgrp != NULL) { isc_taskmgr_destroy(taskmgrp); + } - if (*timermgrp != NULL) + if (*timermgrp != NULL) { isc_timermgr_destroy(timermgrp); + } - if (*socketmgrp != NULL) + if (*socketmgrp != NULL) { isc_socketmgr_destroy(socketmgrp); + } - if (*actxp != NULL) + if (*actxp != NULL) { isc_appctx_destroy(actxp); + } - if (*mctxp != NULL) + if (*mctxp != NULL) { isc_mem_destroy(mctxp); + } } static isc_result_t @@ -221,20 +230,24 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp, isc_mem_create(mctxp); result = isc_appctx_create(*mctxp, actxp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_socketmgr_createinctx(*mctxp, socketmgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_timermgr_createinctx(*mctxp, timermgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } return (ISC_R_SUCCESS); @@ -259,12 +272,14 @@ make_querymessage(dns_message_t *message, dns_name_t *qname0, message->rdclass = dns_rdataclass_in; result = dns_message_gettempname(message, &qname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdataset(message, &qrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_name_init(qname, NULL); dns_name_clone(qname0, qname); @@ -275,10 +290,12 @@ make_querymessage(dns_message_t *message, dns_name_t *qname0, return (ISC_R_SUCCESS); cleanup: - if (qname != NULL) + if (qname != NULL) { dns_message_puttempname(message, &qname); - if (qrdataset != NULL) + } + if (qrdataset != NULL) { dns_message_puttemprdataset(message, &qrdataset); + } return (result); } @@ -396,58 +413,67 @@ update_stat(struct probe_trans *trans) /* Update per domain statistics */ if (local_stat.ignore > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:ignore\n", trans->domain); + } increment_entry(&domain_stat.ignore); err_count++; } if (local_stat.nxdomain > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:nxdomain\n", trans->domain); + } increment_entry(&domain_stat.nxdomain); err_count++; } if (local_stat.othererr > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:othererr\n", trans->domain); + } increment_entry(&domain_stat.othererr); err_count++; } if (local_stat.multiplesoa > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:multiplesoa\n", trans->domain); + } increment_entry(&domain_stat.multiplesoa); err_count++; } if (local_stat.multiplecname > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:multiplecname\n", trans->domain); + } increment_entry(&domain_stat.multiplecname); err_count++; } if (local_stat.brokenanswer > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:brokenanswer\n", trans->domain); + } increment_entry(&domain_stat.brokenanswer); err_count++; } if (local_stat.lame > 0U) { - if (verbose_level > 0) + if (verbose_level > 0) { printf("%s:lame\n", trans->domain); + } increment_entry(&domain_stat.lame); err_count++; } - if (err_count > 1U) + if (err_count > 1U) { increment_entry(&multiple_error_domains); + } /* * We regard the domain as valid if and only if no authoritative server * has a problem and at least one server is known to be valid. */ if (local_stat.valid > 0U && err_count == 0U) { - if (verbose_level > 1) + if (verbose_level > 1) { printf("%s:valid\n", trans->domain); + } increment_entry(&domain_stat.valid); } @@ -456,8 +482,9 @@ update_stat(struct probe_trans *trans) * 'unknown' result, the domain's result is also regarded as unknown. */ if (local_stat.valid == 0U && err_count == 0U) { - if (verbose_level > 1) + if (verbose_level > 1) { printf("%s:unknown\n", trans->domain); + } increment_entry(&domain_stat.unknown); } } @@ -479,12 +506,12 @@ set_nextqname(struct probe_trans *trans) } if (strlcpy(buf, *trans->qlabel, sizeof(buf)) >= sizeof(buf)) { - return ISC_R_NOSPACE; + return (ISC_R_NOSPACE); } if ((domainlen = strlcat(buf, trans->domain, sizeof(buf))) >= sizeof(buf)) { - return ISC_R_NOSPACE; + return (ISC_R_NOSPACE); } isc_buffer_init(&b, buf, domainlen); @@ -529,13 +556,13 @@ request_done(isc_task_t *task, isc_event_t *event) } if (rev->result == ISC_R_SUCCESS) { - if ((rmessage->flags & DNS_MESSAGEFLAG_AA) == 0) + if ((rmessage->flags & DNS_MESSAGEFLAG_AA) == 0) { *resultp = lame; - else if (rmessage->rcode == dns_rcode_nxdomain) + } else if (rmessage->rcode == dns_rcode_nxdomain) { *resultp = nxdomain; - else if (rmessage->rcode != dns_rcode_noerror) + } else if (rmessage->rcode != dns_rcode_noerror) { *resultp = othererr; - else if (rmessage->counts[DNS_SECTION_ANSWER] == 0) { + } else if (rmessage->counts[DNS_SECTION_ANSWER] == 0) { /* no error but empty answer */ *resultp = notype; } else { @@ -629,9 +656,9 @@ request_done(isc_task_t *task, isc_event_t *event) rmessage, DNS_SECTION_AUTHORITY); } } - } else if (rev->result == ISC_R_TIMEDOUT) + } else if (rev->result == ISC_R_TIMEDOUT) { *resultp = timedout; - else { + } else { fprintf(stderr, "unexpected result: %u (domain=%s, server=", rev->result, trans->domain); print_address(stderr, &server->address); @@ -641,8 +668,9 @@ request_done(isc_task_t *task, isc_event_t *event) found: INSIST(*resultp != none); - if (type == dns_rdatatype_a && *resultp == exist) + if (type == dns_rdatatype_a && *resultp == exist) { trans->qname_found = true; + } dns_client_destroyreqtrans(&trans->reqid); isc_event_free(&event); @@ -693,8 +721,9 @@ found: */ reset_probe(trans); } - } else if (result != ISC_R_SUCCESS) + } else if (result != ISC_R_SUCCESS) { reset_probe(trans); /* XXX */ + } } static isc_result_t @@ -723,14 +752,16 @@ probe_name(struct probe_trans *trans, dns_rdatatype_t type) found: trans->current_ns = pns; - if (pns == NULL) + if (pns == NULL) { return (ISC_R_NOMORE); + } INSIST(pns->current_server != NULL); dns_message_reset(trans->qmessage, DNS_MESSAGE_INTENTRENDER); result = make_querymessage(trans->qmessage, trans->qname, type); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { return (result); + } result = dns_client_startrequest( client, trans->qmessage, trans->rmessage, &pns->current_server->address, 0, DNS_MESSAGEPARSE_BESTEFFORT, @@ -766,8 +797,9 @@ resolve_nsaddress(isc_task_t *task, isc_event_t *event) rdataset = ISC_LIST_NEXT(rdataset, link)) { (void)print_rdataset(rdataset, name); - if (rdataset->type != dns_rdatatype_a) + if (rdataset->type != dns_rdatatype_a) { continue; + } for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -778,8 +810,9 @@ resolve_nsaddress(isc_task_t *task, isc_event_t *event) dns_rdataset_current(rdataset, &rdata); result = dns_rdata_tostruct(&rdata, &rdata_a, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } server = isc_mem_get(mctx, sizeof(*server)); isc_sockaddr_fromin(&server->address, @@ -803,16 +836,19 @@ next_ns: dns_fixedname_invalidate(&trans->fixedname); trans->qname = NULL; result = set_nextqname(trans); - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { result = probe_name(trans, dns_rdatatype_a); + } } else { result = fetch_nsaddress(trans); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto next_ns; /* XXX: this is unlikely to succeed */ + } } - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { reset_probe(trans); + } } static isc_result_t @@ -848,11 +884,13 @@ reset_probe(struct probe_trans *trans) dns_message_reset(trans->rmessage, DNS_MESSAGE_INTENTPARSE); trans->inuse = false; - if (trans->domain != NULL) + if (trans->domain != NULL) { isc_mem_free(mctx, trans->domain); + } trans->domain = NULL; - if (trans->qname != NULL) + if (trans->qname != NULL) { dns_fixedname_invalidate(&trans->fixedname); + } trans->qname = NULL; trans->qlabel = qlabels; trans->qname_found = false; @@ -870,8 +908,9 @@ reset_probe(struct probe_trans *trans) outstanding_probes--; result = probe_domain(trans); - if (result == ISC_R_NOMORE && outstanding_probes == 0) + if (result == ISC_R_NOMORE && outstanding_probes == 0) { isc_app_ctxshutdown(actx); + } } static void @@ -895,8 +934,9 @@ resolve_ns(isc_task_t *task, isc_event_t *event) rdataset = ISC_LIST_NEXT(rdataset, link)) { (void)print_rdataset(rdataset, name); - if (rdataset->type != dns_rdatatype_ns) + if (rdataset->type != dns_rdatatype_ns) { continue; + } for (result = dns_rdataset_first(rdataset); result == ISC_R_SUCCESS; @@ -908,8 +948,9 @@ resolve_ns(isc_task_t *task, isc_event_t *event) * Extract the name from the NS record. */ result = dns_rdata_tostruct(&rdata, &ns, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { continue; + } pns = isc_mem_get(mctx, sizeof(*pns)); @@ -934,11 +975,13 @@ resolve_ns(isc_task_t *task, isc_event_t *event) /* Go get addresses of NSes */ trans->current_ns = ISC_LIST_HEAD(trans->nslist); result = fetch_nsaddress(trans); - } else + } else { result = ISC_R_FAILURE; + } - if (result == ISC_R_SUCCESS) + if (result == ISC_R_SUCCESS) { return; + } reset_probe(trans); } @@ -958,10 +1001,12 @@ probe_domain(struct probe_trans *trans) /* Construct domain */ cp = fgets(buf, sizeof(buf), input); - if (cp == NULL) + if (cp == NULL) { return (ISC_R_NOMORE); - if ((cp = strchr(buf, '\n')) != NULL) /* zap NL if any */ + } + if ((cp = strchr(buf, '\n')) != NULL) { /* zap NL if any */ *cp = '\0'; + } trans->domain = isc_mem_strdup(mctx, buf); /* Start getting NS for the domain */ @@ -970,13 +1015,15 @@ probe_domain(struct probe_trans *trans) isc_buffer_add(&b, domainlen); trans->qname = dns_fixedname_initname(&trans->fixedname); result = dns_name_fromtext(trans->qname, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_client_startresolve( client, trans->qname, dns_rdataclass_in, dns_rdatatype_ns, 0, probe_task, resolve_ns, trans, &trans->resid); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } trans->inuse = true; outstanding_probes++; @@ -1099,9 +1146,9 @@ main(int argc, char *argv[]) } /* Open input file */ - if (argc == 0) + if (argc == 0) { input = stdin; - else { + } else { input = fopen(argv[0], "r"); if (input == NULL) { fprintf(stderr, "failed to open input file: %s\n", @@ -1137,9 +1184,9 @@ main(int argc, char *argv[]) } for (i = 0; i < MAX_PROBES; i++) { result = probe_domain(&probes[i]); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { break; - else if (result != ISC_R_SUCCESS) { + } else if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to issue an initial probe\n"); exit(1); } diff --git a/lib/samples/resolve.c b/lib/samples/resolve.c index d62330a6f3..9c914d3ff3 100644 --- a/lib/samples/resolve.c +++ b/lib/samples/resolve.c @@ -17,7 +17,7 @@ #include #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -71,8 +71,9 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner) isc_buffer_init(&target, t, sizeof(t)); 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); @@ -121,14 +122,16 @@ set_key(dns_client_t *client, char *keynamestr, char *keystr, bool is_sep, fprintf(stderr, "failed to identify the algorithm\n"); exit(1); } - } else + } else { alg = DNS_KEYALG_RSASHA1; + } keystruct.common.rdclass = dns_rdataclass_in; keystruct.common.rdtype = dns_rdatatype_dnskey; keystruct.flags = DNS_KEYOWNER_ZONE; /* fixed */ - if (is_sep) + if (is_sep) { keystruct.flags |= DNS_KEYFLAG_KSK; + } keystruct.protocol = DNS_KEYPROTO_DNSSEC; /* fixed */ keystruct.algorithm = alg; @@ -338,8 +341,9 @@ main(int argc, char *argv[]) argc -= isc_commandline_index; argv += isc_commandline_index; - if (argc < 1) + if (argc < 1) { usage(); + } if (altserver != NULL) { char *cp; @@ -365,20 +369,25 @@ main(int argc, char *argv[]) isc_mem_create(&mctx); result = isc_appctx_create(mctx, &actx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_app_ctxstart(actx); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_taskmgr_createinctx(mctx, 1, 0, &taskmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_socketmgr_createinctx(mctx, &socketmgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = isc_timermgr_createinctx(mctx, &timermgr); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } clientopt = 0; result = dns_client_createx(mctx, actx, taskmgr, socketmgr, timermgr, @@ -415,8 +424,9 @@ main(int argc, char *argv[]) } /* Set the alternate nameserver (when specified) */ - if (altserver != NULL) + if (altserver != NULL) { addserver(client, altserveraddr, port, altservername); + } /* Install DNSSEC key (if given) */ if (keynamestr != NULL) { @@ -434,13 +444,15 @@ main(int argc, char *argv[]) isc_buffer_add(&b, namelen); qname = dns_fixedname_initname(&qname0); result = dns_name_fromtext(qname, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to convert qname: %u\n", result); + } /* Perform resolution */ resopt = DNS_CLIENTRESOPT_ALLOWRUN; - if (keynamestr == NULL) + if (keynamestr == NULL) { resopt |= DNS_CLIENTRESOPT_NODNSSEC; + } ISC_LIST_INIT(namelist); result = dns_client_resolve(client, qname, dns_rdataclass_in, type, resopt, &namelist); @@ -452,8 +464,9 @@ main(int argc, char *argv[]) name = ISC_LIST_NEXT(name, link)) { for (rdataset = ISC_LIST_HEAD(name->list); rdataset != NULL; rdataset = ISC_LIST_NEXT(rdataset, link)) { - if (printdata(rdataset, name) != ISC_R_SUCCESS) + if (printdata(rdataset, name) != ISC_R_SUCCESS) { fprintf(stderr, "print data failed\n"); + } } } @@ -463,18 +476,23 @@ main(int argc, char *argv[]) cleanup: 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); + } isc_mem_detach(&mctx); - if (keynamestr != NULL) + if (keynamestr != NULL) { isc_mem_destroy(&keymctx); + } dns_lib_shutdown(); return (0); diff --git a/lib/samples/sample-async.c b/lib/samples/sample-async.c index bd53c9f1bf..907b519b04 100644 --- a/lib/samples/sample-async.c +++ b/lib/samples/sample-async.c @@ -16,7 +16,7 @@ #include #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -72,20 +72,25 @@ static void ctxs_destroy(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp, isc_socketmgr_t **socketmgrp, isc_timermgr_t **timermgrp) { - if (*taskmgrp != NULL) + if (*taskmgrp != NULL) { isc_taskmgr_destroy(taskmgrp); + } - if (*timermgrp != NULL) + if (*timermgrp != NULL) { isc_timermgr_destroy(timermgrp); + } - if (*socketmgrp != NULL) + if (*socketmgrp != NULL) { isc_socketmgr_destroy(socketmgrp); + } - if (*actxp != NULL) + if (*actxp != NULL) { isc_appctx_destroy(actxp); + } - if (*mctxp != NULL) + if (*mctxp != NULL) { isc_mem_destroy(mctxp); + } } static isc_result_t @@ -97,20 +102,24 @@ ctxs_init(isc_mem_t **mctxp, isc_appctx_t **actxp, isc_taskmgr_t **taskmgrp, isc_mem_create(mctxp); result = isc_appctx_create(*mctxp, actxp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_taskmgr_createinctx(*mctxp, 1, 0, taskmgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_socketmgr_createinctx(*mctxp, socketmgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } result = isc_timermgr_createinctx(*mctxp, timermgrp); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } return (ISC_R_SUCCESS); @@ -130,11 +139,13 @@ printdata(dns_rdataset_t *rdataset, dns_name_t *owner) isc_buffer_init(&target, t, sizeof(t)); - if (!dns_rdataset_isassociated(rdataset)) + if (!dns_rdataset_isassociated(rdataset)) { return (ISC_R_SUCCESS); + } 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); @@ -156,9 +167,10 @@ process_answer(isc_task_t *task, isc_event_t *event) printf("answer[%2d]\n", trans->id); - if (rev->result != ISC_R_SUCCESS) + if (rev->result != ISC_R_SUCCESS) { printf(" failed: %u(%s)\n", rev->result, dns_result_totext(rev->result)); + } for (name = ISC_LIST_HEAD(rev->answerlist); name != NULL; name = ISC_LIST_NEXT(name, link)) { @@ -179,16 +191,18 @@ process_answer(isc_task_t *task, isc_event_t *event) outstanding_queries--; result = dispatch_query(trans); -#if 0 /* for cancel test */ +#if 0 /* for cancel test */ if (result == ISC_R_SUCCESS) { static int count = 0; - if ((++count) % 10 == 0) + if ((++count) % 10 == 0) { dns_client_cancelresolve(trans->xid); + } } -#endif - if (result == ISC_R_NOMORE && outstanding_queries == 0) +#endif /* if 0 */ + if (result == ISC_R_NOMORE && outstanding_queries == 0) { isc_app_ctxshutdown(query_actx); + } } static isc_result_t @@ -207,25 +221,29 @@ dispatch_query(struct query_trans *trans) /* Construct qname */ cp = fgets(buf, sizeof(buf), fp); - if (cp == NULL) + if (cp == NULL) { return (ISC_R_NOMORE); + } /* zap NL if any */ - if ((cp = strchr(buf, '\n')) != NULL) + if ((cp = strchr(buf, '\n')) != NULL) { *cp = '\0'; + } namelen = strlen(buf); isc_buffer_init(&b, buf, namelen); isc_buffer_add(&b, namelen); trans->qname = dns_fixedname_initname(&trans->fixedname); result = dns_name_fromtext(trans->qname, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } /* Start resolution */ result = dns_client_startresolve( client, trans->qname, dns_rdataclass_in, trans->type, 0, query_task, process_answer, trans, &trans->xid); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } trans->inuse = true; outstanding_queries++; @@ -296,8 +314,9 @@ main(int argc, char *argv[]) argc -= isc_commandline_index; argv += isc_commandline_index; - if (argc < 1) + if (argc < 1) { usage(); + } if (nservers == 0) { nservers = 1; @@ -372,16 +391,18 @@ main(int argc, char *argv[]) /* Dispatch initial queries */ for (i = 0; i < MAX_QUERIES; i++) { result = dispatch_query(&query_array[i]); - if (result == ISC_R_NOMORE) + if (result == ISC_R_NOMORE) { break; + } } /* Start event loop */ isc_app_ctxrun(query_actx); /* Sanity check */ - for (i = 0; i < MAX_QUERIES; i++) + for (i = 0; i < MAX_QUERIES; i++) { INSIST(query_array[i].inuse == false); + } /* Cleanup */ isc_task_detach(&query_task); diff --git a/lib/samples/sample-gai.c b/lib/samples/sample-gai.c index ba16065f4d..3016e2d997 100644 --- a/lib/samples/sample-gai.c +++ b/lib/samples/sample-gai.c @@ -40,11 +40,12 @@ do_gai(int family, char *hostname) error = getnameinfo(res->ai_addr, (socklen_t)res->ai_addrlen, addrbuf, sizeof(addrbuf), NULL, 0, NI_NUMERICHOST); - if (error == 0) + if (error == 0) { error = getnameinfo(res->ai_addr, (socklen_t)res->ai_addrlen, namebuf, sizeof(namebuf), servbuf, sizeof(servbuf), 0); + } if (error != 0) { fprintf(stderr, "getnameinfo failed: %s\n", gai_strerror(error)); @@ -60,8 +61,9 @@ do_gai(int family, char *hostname) int main(int argc, char *argv[]) { - if (argc < 2) + if (argc < 2) { exit(1); + } do_gai(AF_INET, argv[1]); do_gai(AF_INET6, argv[1]); diff --git a/lib/samples/sample-request.c b/lib/samples/sample-request.c index 26167d3e3a..bcd5f7b366 100644 --- a/lib/samples/sample-request.c +++ b/lib/samples/sample-request.c @@ -17,7 +17,7 @@ #include #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -91,12 +91,14 @@ make_querymessage(dns_message_t *message, const char *namestr, message->rdclass = dns_rdataclass_in; result = dns_message_gettempname(message, &qname); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } result = dns_message_gettemprdataset(message, &qrdataset); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto cleanup; + } dns_name_init(qname, NULL); dns_name_clone(qname0, qname); @@ -107,10 +109,12 @@ make_querymessage(dns_message_t *message, const char *namestr, return (ISC_R_SUCCESS); cleanup: - if (qname != NULL) + if (qname != NULL) { dns_message_puttempname(message, &qname); - if (qrdataset != NULL) + } + if (qrdataset != NULL) { dns_message_puttemprdataset(message, &qrdataset); + } dns_message_destroy(&message); return (result); } @@ -123,8 +127,9 @@ print_section(dns_message_t *message, int section, isc_buffer_t *buf) result = dns_message_sectiontotext(message, section, &dns_master_style_full, 0, buf); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { goto fail; + } isc_buffer_usedregion(buf, &r); printf("%.*s", (int)r.length, (char *)r.base); @@ -167,8 +172,9 @@ main(int argc, char *argv[]) argc -= isc_commandline_index; argv += isc_commandline_index; - if (argc < 2) + if (argc < 2) { usage(); + } isc_lib_register(); result = dns_lib_init(); @@ -206,7 +212,7 @@ main(int argc, char *argv[]) hints.ai_protocol = IPPROTO_UDP; #ifdef AI_NUMERICHOST hints.ai_flags = AI_NUMERICHOST; -#endif +#endif /* ifdef AI_NUMERICHOST */ gaierror = getaddrinfo(argv[0], "53", &hints, &res); if (gaierror != 0) { fprintf(stderr, "getaddrinfo failed: %s\n", diff --git a/lib/samples/sample-update.c b/lib/samples/sample-update.c index 1787d1cfe4..8e5f1fef4b 100644 --- a/lib/samples/sample-update.c +++ b/lib/samples/sample-update.c @@ -17,7 +17,7 @@ #include #include #include -#endif +#endif /* ifndef WIN32 */ #include #include @@ -108,10 +108,10 @@ DestroySockets(void) { WSACleanup(); } -#else +#else /* ifdef _WIN32 */ #define InitSockets() ((void)0) #define DestroySockets() ((void)0) -#endif +#endif /* ifdef _WIN32 */ static bool addserver(const char *server, isc_sockaddrlist_t *list, @@ -126,10 +126,10 @@ addserver(const char *server, isc_sockaddrlist_t *list, hints.ai_protocol = IPPROTO_UDP; #ifdef AI_NUMERICHOST hints.ai_flags |= AI_NUMERICHOST; -#endif +#endif /* ifdef AI_NUMERICHOST */ #ifdef AI_NUMERICSERV hints.ai_flags |= AI_NUMERICSERV; -#endif +#endif /* ifdef AI_NUMERICSERV */ InitSockets(); gaierror = getaddrinfo(server, port, &hints, &res); if (gaierror != 0) { @@ -185,8 +185,9 @@ main(int argc, char *argv[]) case 'a': if (nsa_auth < sizeof(sa_auth) / sizeof(*sa_auth) && addserver(isc_commandline_argument, &auth_servers, - &sa_auth[nsa_auth])) + &sa_auth[nsa_auth])) { nsa_auth++; + } break; case 'p': prereqstr = isc_commandline_argument; @@ -198,8 +199,9 @@ main(int argc, char *argv[]) if (nsa_recursive < sizeof(sa_recursive) / sizeof(*sa_recursive) && addserver(isc_commandline_argument, &rec_servers, - &sa_recursive[nsa_recursive])) + &sa_recursive[nsa_recursive])) { nsa_recursive++; + } break; case 's': sendtwice = true; @@ -214,15 +216,16 @@ main(int argc, char *argv[]) argc -= isc_commandline_index; argv += isc_commandline_index; - if (argc < 2) + if (argc < 2) { usage(); + } /* command line argument validation */ - if (strcmp(argv[0], "delete") == 0) + if (strcmp(argv[0], "delete") == 0) { isdelete = true; - else if (strcmp(argv[0], "add") == 0) + } else if (strcmp(argv[0], "add") == 0) { isdelete = false; - else { + } else { fprintf(stderr, "invalid update command: %s\n", argv[0]); exit(1); } @@ -260,9 +263,10 @@ main(int argc, char *argv[]) isc_buffer_add(&b, namelen); zname = dns_fixedname_initname(&zname0); result = dns_name_fromtext(zname, &b, dns_rootname, 0, NULL); - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fprintf(stderr, "failed to convert zone name: %u\n", result); + } } /* Construct prerequisite name (if given) */ @@ -280,11 +284,13 @@ main(int argc, char *argv[]) ISC_LIST_APPEND(updatelist, uname, link); /* Set up TSIG/SIG(0) key (if given) */ - if (keyfilename != NULL) + if (keyfilename != NULL) { setup_tsec(keyfilename, umctx); + } - if (ISC_LIST_HEAD(auth_servers) == NULL) + if (ISC_LIST_HEAD(auth_servers) == NULL) { auth_serversp = NULL; + } /* Perform update */ result = dns_client_update(client, default_rdataclass, /* XXX: fixed */ @@ -293,21 +299,23 @@ main(int argc, char *argv[]) if (result != ISC_R_SUCCESS) { fprintf(stderr, "update failed: %s\n", dns_result_totext(result)); - } else + } else { fprintf(stderr, "update succeeded\n"); + } if (sendtwice) { /* Perform 2nd update */ result = dns_client_update(client, default_rdataclass, /* XXX: - fixed + * fixed */ zname, prereqlistp, &updatelist, auth_serversp, tsec, 0); if (result != ISC_R_SUCCESS) { fprintf(stderr, "2nd update failed: %s\n", dns_result_totext(result)); - } else + } else { fprintf(stderr, "2nd update succeeded\n"); + } } /* Cleanup */ @@ -339,8 +347,9 @@ main(int argc, char *argv[]) ISC_LIST_UNLINK(usedbuffers, buf, link); isc_buffer_free(&buf); } - if (tsec != NULL) + if (tsec != NULL) { dns_tsec_destroy(&tsec); + } isc_mem_destroy(&umctx); dns_client_destroy(&client); dns_lib_shutdown(); @@ -362,17 +371,20 @@ nsu_strsep(char **stringp, const char *delim) const char *d; char sc, dc; - if (string == NULL) + if (string == NULL) { return (NULL); + } for (; *string != '\0'; string++) { sc = *string; for (d = delim; (dc = *d) != '\0'; d++) { - if (sc == dc) + if (sc == dc) { break; + } } - if (dc == 0) + if (dc == 0) { break; + } } for (s = string; *s != '\0'; s++) { @@ -404,8 +416,9 @@ fatal(const char *format, ...) static inline void check_result(isc_result_t result, const char *msg) { - if (result != ISC_R_SUCCESS) + if (result != ISC_R_SUCCESS) { fatal("%s: %s", msg, isc_result_totext(result)); + } } static void @@ -440,8 +453,9 @@ parse_rdata(isc_mem_t *mctx, char **cmdlinep, dns_rdataclass_t rdataclass, isc_result_t result; while (cmdline != NULL && *cmdline != 0 && - isspace((unsigned char)*cmdline)) + isspace((unsigned char)*cmdline)) { cmdline++; + } if (cmdline != NULL && *cmdline != 0) { dns_rdatacallbacks_init(&callbacks); @@ -528,9 +542,9 @@ update_addordelete(isc_mem_t *mctx, char *cmdline, bool isdelete, } } - if (isdelete) + if (isdelete) { ttl = 0; - else if (ttl > TTL_MAX) { + } else if (ttl > TTL_MAX) { fprintf(stderr, "ttl '%s' is out of range (0 to %u)\n", word, TTL_MAX); exit(1); @@ -594,10 +608,11 @@ parseclass: parse_rdata(mctx, &cmdline, rdataclass, rdatatype, rdata); if (isdelete) { - if ((rdata->flags & DNS_RDATA_UPDATE) != 0) + if ((rdata->flags & DNS_RDATA_UPDATE) != 0) { rdataclass = dns_rdataclass_any; - else + } else { rdataclass = dns_rdataclass_none; + } } else { if ((rdata->flags & DNS_RDATA_UPDATE) != 0) { fprintf(stderr, "could not read rdata\n"); @@ -678,27 +693,31 @@ make_prereq(isc_mem_t *mctx, char *cmdline, bool ispositive, bool isrrset, exit(1); } } - } else + } else { rdatatype = dns_rdatatype_any; + } rdata = isc_mem_get(mctx, sizeof(*rdata)); dns_rdata_init(rdata); - if (isrrset && ispositive) + if (isrrset && ispositive) { parse_rdata(mctx, &cmdline, rdataclass, rdatatype, rdata); - else + } else { rdata->flags = DNS_RDATA_UPDATE; + } rdatalist = isc_mem_get(mctx, sizeof(*rdatalist)); dns_rdatalist_init(rdatalist); rdatalist->type = rdatatype; if (ispositive) { - if (isrrset && rdata->data != NULL) + if (isrrset && rdata->data != NULL) { rdatalist->rdclass = rdataclass; - else + } else { rdatalist->rdclass = dns_rdataclass_any; - } else + } + } else { rdatalist->rdclass = dns_rdataclass_none; + } rdata->rdclass = rdatalist->rdclass; rdata->type = rdatatype; ISC_LIST_APPEND(rdatalist->rdata, rdata, link); @@ -758,10 +777,11 @@ setup_tsec(char *keyfile, isc_mem_t *mctx) exit(1); } - if (dst_key_alg(dstkey) == DST_ALG_HMACMD5) + if (dst_key_alg(dstkey) == DST_ALG_HMACMD5) { tsectype = dns_tsectype_tsig; - else + } else { tsectype = dns_tsectype_sig0; + } result = dns_tsec_create(mctx, tsectype, dstkey, &tsec); dst_key_free(&dstkey); diff --git a/util/models.c b/util/models.c index cc41b1f13e..6c2a26757a 100644 --- a/util/models.c +++ b/util/models.c @@ -23,38 +23,44 @@ int condition; void * isc__mem_get(void *mem, unsigned int size FLARG) { - if (!mem) + if (!mem) { __coverity_panic__(); + } __coverity_negative_sink__(size); - if (condition) + if (condition) { return (0); + } return (__coverity_alloc__(size)); } void isc__mem_put(void *mem, void *ptr, unsigned int size FLARG) { - if (!mem) + if (!mem) { __coverity_panic__(); + } __coverity_free__(ptr); } void isc__mem_putanddetach(void *mem, void *ptr, unsigned int size FLARG) { - if (!mem) + if (!mem) { __coverity_panic__(); + } __coverity_free__(ptr); } void * isc__mem_allocate(void *mem, unsigned int size FLARG) { - if (!mem) + if (!mem) { __coverity_panic__(); + } __coverity_negative_sink__(size); - if (condition) + if (condition) { return (0); + } return (__coverity_alloc__(size)); } @@ -67,8 +73,9 @@ isc__mem_reallocate(void *mem, void *ptr, size_t size FLARG) char * p = (char *)0; size_t l; - if (!mem) + if (!mem) { __coverity_panic__(); + } if (size > 0) { p = isc__mem_allocate(mem, size FLARG_PASS); if (p && ptr) { @@ -76,16 +83,18 @@ isc__mem_reallocate(void *mem, void *ptr, size_t size FLARG) memcpy(p, ptr, l); __coverity_free__(ptr); } - } else if (ptr) + } else if (ptr) { __coverity_free__(ptr); + } return (p); } void isc__mem_free(void *mem, void *ptr FLARG) { - if (!mem) + if (!mem) { __coverity_panic__(); + } __coverity_free__(ptr); } @@ -96,10 +105,12 @@ void * isc__mem_strdup(void *mem, char *s FLARG) { void *d; - if (!mem) + if (!mem) { __coverity_panic__(); - if (condition) + } + if (condition) { return (0); + } d = __coverity_alloc__(strlen(s) + 1); __coverity_writeall__(d); return (d); @@ -109,18 +120,21 @@ void * isc__mempool_get(void *mem FLARG) { unsigned int size; - if (!mem) + if (!mem) { __coverity_panic__(); - if (condition) + } + if (condition) { return (0); + } return (__coverity_alloc__(size)); } void isc__mempool_put(void *mem, void *ptr FLARG) { - if (!mem) + if (!mem) { __coverity_panic__(); + } __coverity_free__(ptr); } @@ -134,6 +148,7 @@ void _assert_true(const LargestIntegralType result, const char *const expression, const char *const file, const int line) { - if (!result) + if (!result) { __coverity_panic__(); + } }