Use clang-format to reformat the source files

This commit is contained in:
Ondřej Surý
2020-02-12 13:59:18 +01:00
parent 4c3b063ef8
commit f50b1e0685
966 changed files with 75914 additions and 74245 deletions

View File

@@ -11,13 +11,12 @@
#if HAVE_CMOCKA
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <inttypes.h>
#include <sched.h> /* IWYU pragma: keep */
#include <setjmp.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
@@ -39,12 +38,13 @@
#include <dns/rootns.h>
#include <dns/view.h>
#include <dst/dst.h>
#include "dnstest.h"
#include <dst/dst.h>
static int
_setup(void **state) {
_setup(void **state)
{
isc_result_t result;
UNUSED(state);
@@ -56,7 +56,8 @@ _setup(void **state) {
}
static int
_teardown(void **state) {
_teardown(void **state)
{
UNUSED(state);
dns_test_end();
@@ -67,9 +68,19 @@ _teardown(void **state) {
dns_keytable_t *keytable = NULL;
dns_ntatable_t *ntatable = NULL;
static const char *keystr1 = "BQEAAAABok+vaUC9neRv8yeT/FEGgN7svR8s7VBUVSBd8NsAiV8AlaAg O5FHar3JQd95i/puZos6Vi6at9/JBbN8qVmO2AuiXxVqfxMKxIcy+LEB 0Vw4NaSJ3N3uaVREso6aTSs98H/25MjcwLOr7SFfXA7bGhZatLtYY/xu kp6Km5hMfkE=";
static const char *keystr1 = "BQEAAAABok+vaUC9neRv8yeT/"
"FEGgN7svR8s7VBUVSBd8NsAiV8AlaAg "
"O5FHar3JQd95i/puZos6Vi6at9/"
"JBbN8qVmO2AuiXxVqfxMKxIcy+LEB "
"0Vw4NaSJ3N3uaVREso6aTSs98H/"
"25MjcwLOr7SFfXA7bGhZatLtYY/xu kp6Km5hMfkE=";
static const char *keystr2 = "BQEAAAABwuHz9Cem0BJ0JQTO7C/a3McR6hMaufljs1dfG/inaJpYv7vH XTrAOm/MeKp+/x6eT4QLru0KoZkvZJnqTI8JyaFTw2OM/ItBfh/hL2lm Cft2O7n3MfeqYtvjPnY7dWghYW4sVfH7VVEGm958o9nfi79532Qeklxh x8pXWdeAaRU=";
static const char *keystr2 = "BQEAAAABwuHz9Cem0BJ0JQTO7C/a3McR6hMaufljs1dfG/"
"inaJpYv7vH "
"XTrAOm/MeKp+/x6eT4QLru0KoZkvZJnqTI8JyaFTw2OM/"
"ItBfh/hL2lm "
"Cft2O7n3MfeqYtvjPnY7dWghYW4sVfH7VVEGm958o9nfi7953"
"2Qeklxh x8pXWdeAaRU=";
static dns_view_t *view = NULL;
@@ -85,30 +96,31 @@ static dns_view_t *view = NULL;
* static data, and so is not thread safe.
*/
static dns_name_t *
str2name(const char *namestr) {
str2name(const char *namestr)
{
static dns_fixedname_t fname;
static dns_name_t *name;
static isc_buffer_t namebuf;
void *deconst_namestr;
static dns_name_t * name;
static isc_buffer_t namebuf;
void * deconst_namestr;
name = dns_fixedname_initname(&fname);
DE_CONST(namestr, deconst_namestr); /* OK, since we don't modify it */
isc_buffer_init(&namebuf, deconst_namestr, strlen(deconst_namestr));
isc_buffer_add(&namebuf, strlen(namestr));
assert_int_equal(dns_name_fromtext(name, &namebuf, dns_rootname,
0, NULL),
ISC_R_SUCCESS);
assert_int_equal(
dns_name_fromtext(name, &namebuf, dns_rootname, 0, NULL),
ISC_R_SUCCESS);
return (name);
}
static void
create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg,
const char *keystr, dns_rdata_dnskey_t *keystruct)
create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg, const char *keystr,
dns_rdata_dnskey_t *keystruct)
{
unsigned char keydata[4096];
isc_buffer_t keydatabuf;
isc_region_t r;
unsigned char keydata[4096];
isc_buffer_t keydatabuf;
isc_region_t r;
const dns_rdataclass_t rdclass = dns_rdataclass_in;
keystruct->common.rdclass = rdclass;
@@ -129,14 +141,14 @@ create_keystruct(uint16_t flags, uint8_t proto, uint8_t alg,
}
static void
create_dsstruct(dns_name_t *name, uint16_t flags,
uint8_t proto, uint8_t alg, const char *keystr,
unsigned char *digest, dns_rdata_ds_t *dsstruct)
create_dsstruct(dns_name_t *name, uint16_t flags, uint8_t proto, uint8_t alg,
const char *keystr, unsigned char *digest,
dns_rdata_ds_t *dsstruct)
{
isc_result_t result;
unsigned char rrdata[4096];
isc_buffer_t rrdatabuf;
dns_rdata_t rdata = DNS_RDATA_INIT;
isc_result_t result;
unsigned char rrdata[4096];
isc_buffer_t rrdatabuf;
dns_rdata_t rdata = DNS_RDATA_INIT;
dns_rdata_dnskey_t dnskey;
/*
@@ -149,15 +161,15 @@ create_dsstruct(dns_name_t *name, uint16_t flags,
*/
isc_buffer_init(&rrdatabuf, rrdata, sizeof(rrdata));
result = dns_rdata_fromstruct(&rdata, dnskey.common.rdclass,
dnskey.common.rdtype,
&dnskey, &rrdatabuf);
dnskey.common.rdtype, &dnskey,
&rrdatabuf);
assert_int_equal(result, ISC_R_SUCCESS);
/*
* Build DS rdata struct.
*/
result = dns_ds_fromkeyrdata(name, &rdata, DNS_DSDIGEST_SHA256,
digest, dsstruct);
result = dns_ds_fromkeyrdata(name, &rdata, DNS_DSDIGEST_SHA256, digest,
dsstruct);
assert_int_equal(result, ISC_R_SUCCESS);
dns_rdata_freestruct(&dnskey);
@@ -165,21 +177,23 @@ create_dsstruct(dns_name_t *name, uint16_t flags,
/* Common setup: create a keytable and ntatable to test with a few keys */
static void
create_tables() {
isc_result_t result;
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
create_tables()
{
isc_result_t result;
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
dns_fixedname_t fn;
dns_name_t *keyname = dns_fixedname_name(&fn);
isc_stdtime_t now;
dns_name_t * keyname = dns_fixedname_name(&fn);
isc_stdtime_t now;
result = dns_test_makeview("view", &view);
assert_int_equal(result, ISC_R_SUCCESS);
assert_int_equal(dns_keytable_create(dt_mctx, &keytable),
ISC_R_SUCCESS);
assert_int_equal(dns_ntatable_create(view, taskmgr, timermgr,
&ntatable), ISC_R_SUCCESS);
assert_int_equal(
dns_ntatable_create(view, taskmgr, timermgr, &ntatable),
ISC_R_SUCCESS);
/* Add a normal key */
dns_test_namefromstring("example.com", &fn);
@@ -194,20 +208,21 @@ create_tables() {
ISC_R_SUCCESS);
/* Add a null key */
assert_int_equal(dns_keytable_marksecure(keytable,
str2name("null.example")),
assert_int_equal(dns_keytable_marksecure(keytable, str2name("null."
"example")),
ISC_R_SUCCESS);
/* Add a negative trust anchor, duration 1 hour */
isc_stdtime_get(&now);
assert_int_equal(dns_ntatable_add(ntatable,
str2name("insecure.example"),
false, now, 3600),
str2name("insecure.example"), false,
now, 3600),
ISC_R_SUCCESS);
}
static void
destroy_tables() {
destroy_tables()
{
if (ntatable != NULL) {
dns_ntatable_detach(&ntatable);
}
@@ -220,13 +235,14 @@ destroy_tables() {
/* add keys to the keytable */
static void
add_test(void **state) {
dns_keynode_t *keynode = NULL;
dns_keynode_t *null_keynode = NULL;
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
add_test(void **state)
{
dns_keynode_t * keynode = NULL;
dns_keynode_t * null_keynode = NULL;
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
dns_fixedname_t fn;
dns_name_t *keyname = dns_fixedname_name(&fn);
dns_name_t * keyname = dns_fixedname_name(&fn);
UNUSED(state);
@@ -235,9 +251,9 @@ add_test(void **state) {
/*
* Getting the keynode for the example.com key should succeed.
*/
assert_int_equal(dns_keytable_find(keytable, str2name("example.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("example.com"), &keynode),
ISC_R_SUCCESS);
/*
* Try to add the same key. This should have no effect but
@@ -248,18 +264,18 @@ add_test(void **state) {
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds),
ISC_R_SUCCESS);
dns_keytable_detachkeynode(keytable, &keynode);
assert_int_equal(dns_keytable_find(keytable, str2name("example.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("example.com"), &keynode),
ISC_R_SUCCESS);
/* Add another key (different keydata) */
dns_keytable_detachkeynode(keytable, &keynode);
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("example.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("example.com"), &keynode),
ISC_R_SUCCESS);
dns_keytable_detachkeynode(keytable, &keynode);
/*
@@ -267,9 +283,9 @@ add_test(void **state) {
* retrieved key is an initializing key, then mark it as trusted using
* dns_keynode_trust() and ensure the latter works as expected.
*/
assert_int_equal(dns_keytable_find(keytable, str2name("managed.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("managed.com"), &keynode),
ISC_R_SUCCESS);
assert_int_equal(dns_keynode_initial(keynode), true);
dns_keynode_trust(keynode);
assert_int_equal(dns_keynode_initial(keynode), false);
@@ -284,9 +300,9 @@ add_test(void **state) {
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("managed.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("managed.com"), &keynode),
ISC_R_SUCCESS);
assert_int_equal(dns_keynode_initial(keynode), false);
dns_keytable_detachkeynode(keytable, &keynode);
@@ -298,9 +314,9 @@ add_test(void **state) {
*/
assert_int_equal(dns_keytable_add(keytable, true, false, keyname, &ds),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("managed.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("managed.com"), &keynode),
ISC_R_SUCCESS);
assert_int_equal(dns_keynode_initial(keynode), false);
dns_keytable_detachkeynode(keytable, &keynode);
@@ -312,9 +328,9 @@ add_test(void **state) {
create_dsstruct(keyname, 257, 3, 5, keystr1, digest, &ds);
assert_int_equal(dns_keytable_add(keytable, true, true, keyname, &ds),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("two.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("two.com"), &keynode),
ISC_R_SUCCESS);
assert_int_equal(dns_keynode_initial(keynode), true);
dns_keytable_detachkeynode(keytable, &keynode);
@@ -327,9 +343,9 @@ add_test(void **state) {
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
assert_int_equal(dns_keytable_add(keytable, true, false, keyname, &ds),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("two.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("two.com"), &keynode),
ISC_R_SUCCESS);
assert_int_equal(dns_keynode_initial(keynode), true);
dns_keytable_detachkeynode(keytable, &keynode);
@@ -344,9 +360,9 @@ add_test(void **state) {
create_dsstruct(keyname, 257, 3, 5, keystr2, digest, &ds);
assert_int_equal(dns_keytable_add(keytable, false, false, keyname, &ds),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("null.example"), &keynode),
ISC_R_SUCCESS);
assert_int_equal(keynode, null_keynode); /* should be the same node */
dns_keytable_detachkeynode(keytable, &null_keynode);
@@ -356,8 +372,8 @@ add_test(void **state) {
* (Note: this and above checks confirm that if a name has a null key
* that's the only key for the name).
*/
assert_int_equal(dns_keytable_marksecure(keytable,
str2name("null.example")),
assert_int_equal(dns_keytable_marksecure(keytable, str2name("null."
"example")),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_find(keytable, str2name("null.example"),
&null_keynode),
@@ -371,30 +387,29 @@ add_test(void **state) {
/* delete keys from the keytable */
static void
delete_test(void **state) {
delete_test(void **state)
{
UNUSED(state);
create_tables();
/* dns_keytable_delete requires exact match */
assert_int_equal(dns_keytable_delete(keytable,
str2name("example.org")),
assert_int_equal(dns_keytable_delete(keytable, str2name("example.org")),
ISC_R_NOTFOUND);
assert_int_equal(dns_keytable_delete(keytable,
str2name("s.example.com")),
assert_int_equal(dns_keytable_delete(keytable, str2name("s.example."
"com")),
ISC_R_NOTFOUND);
assert_int_equal(dns_keytable_delete(keytable,
str2name("example.com")),
assert_int_equal(dns_keytable_delete(keytable, str2name("example.com")),
ISC_R_SUCCESS);
/* works also for nodes with a null key */
assert_int_equal(dns_keytable_delete(keytable,
str2name("null.example")),
assert_int_equal(dns_keytable_delete(keytable, str2name("null."
"example")),
ISC_R_SUCCESS);
/* or a negative trust anchor */
assert_int_equal(dns_ntatable_delete(ntatable,
str2name("insecure.example")),
assert_int_equal(dns_ntatable_delete(ntatable, str2name("insecure."
"example")),
ISC_R_SUCCESS);
destroy_tables();
@@ -402,10 +417,11 @@ delete_test(void **state) {
/* delete key nodes from the keytable */
static void
deletekey_test(void **state) {
deletekey_test(void **state)
{
dns_rdata_dnskey_t dnskey;
dns_fixedname_t fn;
dns_name_t *keyname = dns_fixedname_name(&fn);
dns_fixedname_t fn;
dns_name_t * keyname = dns_fixedname_name(&fn);
UNUSED(state);
@@ -447,8 +463,7 @@ deletekey_test(void **state) {
* after deleting the node, any deletekey or delete attempt should
* result in NOTFOUND.
*/
assert_int_equal(dns_keytable_delete(keytable, keyname),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_delete(keytable, keyname), ISC_R_SUCCESS);
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
ISC_R_NOTFOUND);
dns_rdata_freestruct(&dnskey);
@@ -461,8 +476,7 @@ deletekey_test(void **state) {
create_keystruct(257, 3, 5, keystr1, &dnskey);
assert_int_equal(dns_keytable_deletekey(keytable, keyname, &dnskey),
DNS_R_PARTIALMATCH);
assert_int_equal(dns_keytable_delete(keytable, keyname),
ISC_R_SUCCESS);
assert_int_equal(dns_keytable_delete(keytable, keyname), ISC_R_SUCCESS);
dns_rdata_freestruct(&dnskey);
destroy_tables();
@@ -470,10 +484,11 @@ deletekey_test(void **state) {
/* check find-variant operations */
static void
find_test(void **state) {
dns_keynode_t *keynode = NULL;
find_test(void **state)
{
dns_keynode_t * keynode = NULL;
dns_fixedname_t fname;
dns_name_t *name;
dns_name_t * name;
UNUSED(state);
@@ -483,22 +498,20 @@ find_test(void **state) {
* dns_keytable_find() requires exact name match. It matches node
* that has a null key, too.
*/
assert_int_equal(dns_keytable_find(keytable, str2name("example.org"),
&keynode),
ISC_R_NOTFOUND);
assert_int_equal(
dns_keytable_find(keytable, str2name("example.org"), &keynode),
ISC_R_NOTFOUND);
assert_int_equal(dns_keytable_find(keytable,
str2name("sub.example.com"),
&keynode),
ISC_R_NOTFOUND);
assert_int_equal(dns_keytable_find(keytable,
str2name("example.com"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("example.com"), &keynode),
ISC_R_SUCCESS);
dns_keytable_detachkeynode(keytable, &keynode);
assert_int_equal(dns_keytable_find(keytable,
str2name("null.example"),
&keynode),
ISC_R_SUCCESS);
assert_int_equal(
dns_keytable_find(keytable, str2name("null.example"), &keynode),
ISC_R_SUCCESS);
dns_keytable_detachkeynode(keytable, &keynode);
/*
@@ -506,23 +519,19 @@ find_test(void **state) {
* nodes with a null key.
*/
name = dns_fixedname_initname(&fname);
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
str2name("example.com"),
name),
assert_int_equal(dns_keytable_finddeepestmatch(
keytable, str2name("example.com"), name),
ISC_R_SUCCESS);
assert_true(dns_name_equal(name, str2name("example.com")));
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
str2name("s.example.com"),
name),
assert_int_equal(dns_keytable_finddeepestmatch(
keytable, str2name("s.example.com"), name),
ISC_R_SUCCESS);
assert_true(dns_name_equal(name, str2name("example.com")));
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
str2name("example.org"),
name),
assert_int_equal(dns_keytable_finddeepestmatch(
keytable, str2name("example.org"), name),
ISC_R_NOTFOUND);
assert_int_equal(dns_keytable_finddeepestmatch(keytable,
str2name("null.example"),
name),
assert_int_equal(dns_keytable_finddeepestmatch(
keytable, str2name("null.example"), name),
ISC_R_SUCCESS);
assert_true(dns_name_equal(name, str2name("null.example")));
@@ -531,11 +540,12 @@ find_test(void **state) {
/* check issecuredomain() */
static void
issecuredomain_test(void **state) {
bool issecure;
issecuredomain_test(void **state)
{
bool issecure;
const char **n;
const char *names[] = {"example.com", "sub.example.com",
"null.example", "sub.null.example", NULL};
const char * names[] = { "example.com", "sub.example.com",
"null.example", "sub.null.example", NULL };
UNUSED(state);
create_tables();
@@ -548,8 +558,7 @@ issecuredomain_test(void **state) {
*/
for (n = names; *n != NULL; n++) {
assert_int_equal(dns_keytable_issecuredomain(keytable,
str2name(*n),
NULL,
str2name(*n), NULL,
&issecure),
ISC_R_SUCCESS);
assert_true(issecure);
@@ -561,8 +570,7 @@ issecuredomain_test(void **state) {
*/
assert_int_equal(dns_keytable_issecuredomain(keytable,
str2name("example.org"),
NULL,
&issecure),
NULL, &issecure),
ISC_R_SUCCESS);
assert_false(issecure);
@@ -571,7 +579,8 @@ issecuredomain_test(void **state) {
/* check dns_keytable_dump() */
static void
dump_test(void **state) {
dump_test(void **state)
{
FILE *f = fopen("/dev/null", "w");
UNUSED(state);
@@ -590,15 +599,16 @@ dump_test(void **state) {
/* check negative trust anchors */
static void
nta_test(void **state) {
isc_result_t result;
bool issecure, covered;
nta_test(void **state)
{
isc_result_t result;
bool issecure, covered;
dns_fixedname_t fn;
dns_name_t *keyname = dns_fixedname_name(&fn);
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
dns_view_t *myview = NULL;
isc_stdtime_t now;
dns_name_t * keyname = dns_fixedname_name(&fn);
unsigned char digest[ISC_MAX_MD_SIZE];
dns_rdata_ds_t ds;
dns_view_t * myview = NULL;
isc_stdtime_t now;
UNUSED(state);
@@ -624,22 +634,22 @@ nta_test(void **state) {
assert_int_equal(result, ISC_R_SUCCESS);
isc_stdtime_get(&now);
result = dns_ntatable_add(ntatable, str2name("insecure.example"),
false, now, 1);
result = dns_ntatable_add(ntatable, str2name("insecure.example"), false,
now, 1);
assert_int_equal(result, ISC_R_SUCCESS);
/* Should be secure */
result = dns_view_issecuredomain(myview,
str2name("test.secure.example"),
now, true, &covered, &issecure);
str2name("test.secure.example"), now,
true, &covered, &issecure);
assert_int_equal(result, ISC_R_SUCCESS);
assert_false(covered);
assert_true(issecure);
/* Should not be secure */
result = dns_view_issecuredomain(myview,
str2name("test.insecure.example"),
now, true, &covered, &issecure);
str2name("test.insecure.example"), now,
true, &covered, &issecure);
assert_int_equal(result, ISC_R_SUCCESS);
assert_true(covered);
assert_false(issecure);
@@ -669,8 +679,8 @@ nta_test(void **state) {
assert_false(covered);
assert_true(issecure);
result = dns_ntatable_add(ntatable, str2name("new.example"),
false, now, 3600);
result = dns_ntatable_add(ntatable, str2name("new.example"), false, now,
3600);
assert_int_equal(result, ISC_R_SUCCESS);
result = dns_view_issecuredomain(myview, str2name("test.new.example"),
@@ -695,7 +705,8 @@ nta_test(void **state) {
}
int
main(void) {
main(void)
{
const struct CMUnitTest tests[] = {
cmocka_unit_test(add_test),
cmocka_unit_test(delete_test),
@@ -714,7 +725,8 @@ main(void) {
#include <stdio.h>
int
main(void) {
main(void)
{
printf("1..0 # Skipped: cmocka not available\n");
return (0);
}