From fcbb656cf7b29b2f03592f3b56556e18b173092a Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Fri, 25 Feb 2011 01:23:38 +0000 Subject: [PATCH] auth: Correctly write empty keyfiles The new key handling code was creating empty keyfiles that were 0 bytes in length. The correct format for an empty keyfile is a file containing a single 0 word (the number of keys in the file). Update the code to write this form of empty KeyFile. Change-Id: I93bf23f6044a70a74f52b94c4656cbd4bc4fc35b Reviewed-on: http://gerrit.openafs.org/4051 Tested-by: BuildBot Reviewed-by: Derrick Brashear --- src/auth/keys.c | 11 +++++++---- tests/auth/keys-t.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/src/auth/keys.c b/src/auth/keys.c index aa265f10c..0a3723f62 100644 --- a/src/auth/keys.c +++ b/src/auth/keys.c @@ -415,14 +415,17 @@ _writeOriginalKeyFile(struct afsconf_dir *dir, char *fileName) return AFSCONF_FAILURE; typeEntry = findByType(dir, afsconf_rxkad); - if (typeEntry == NULL) - goto out; - - nkeys = opr_queue_Count(&typeEntry->kvnoList); + if (typeEntry) + nkeys = opr_queue_Count(&typeEntry->kvnoList); + else + nkeys = 0; if (writeWord(fd, nkeys)) goto fail; + if (typeEntry == NULL) + goto out; + for (opr_queue_Scan(&typeEntry->kvnoList, cursor)) { struct kvnoList *kvnoEntry; struct subTypeList *subEntry; diff --git a/tests/auth/keys-t.c b/tests/auth/keys-t.c index 2e32946fb..2e3dc6cca 100644 --- a/tests/auth/keys-t.c +++ b/tests/auth/keys-t.c @@ -105,7 +105,7 @@ int main(int argc, char **argv) int code; int i; - plan(123); + plan(127); /* Create a temporary afs configuration directory */ @@ -527,6 +527,33 @@ int main(int argc, char **argv) " ... with the right key in slot 1"); afsconf_PutTypedKeyList(&typedKeyList); + afsconf_Close(dir); + + unlinkTestConfig(dirname); + free(dirname); + free(keyfile); + + /* Start a new test configuration */ + dirname = buildTestConfig(); + dir = afsconf_Open(dirname); + ok(dir != NULL, "Sucessfully opened brand new config directory"); + if (dir == NULL) + goto out; + + /* Check that directories with just new style keys work */ + keyMaterial = rx_opaque_new("\x02\x03", 2); + typedKey = afsconf_typedKey_new(1, 2, 1, keyMaterial); + code = afsconf_AddTypedKey(dir, typedKey, 0); + afsconf_typedKey_put(&typedKey); + is_int(0, code, + "afsconf_AddTypedKey can add keys with different sub type"); + + /* Check the GetKeyByTypes returns one of the keys */ + code = afsconf_GetKeyByTypes(dir, 1, 2, 1, &typedKey); + is_int(0, code, "afsconf_GetKeyByTypes returns it"); + ok(keyMatches(typedKey, 1, 2, 1, "\x02\x03", 2), + " ... with the right key"); + out: unlinkTestConfig(dirname); -- 2.39.5