2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-30 22:15:20 +00:00

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

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

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

View File

@@ -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);
}