diff --git a/tests/auth/authcon-t.c b/tests/auth/authcon-t.c index bdfd2568be..2ea6c4716f 100644 --- a/tests/auth/authcon-t.c +++ b/tests/auth/authcon-t.c @@ -52,13 +52,17 @@ main(int argc, char **argv) struct afsconf_typedKey *key; int code = 0; struct afsconf_bsso_info bsso; + struct afstest_configinfo bct; memset(&bsso, 0, sizeof(bsso)); + memset(&bct, 0, sizeof(bct)); afstest_SkipTestsIfBadHostname(); plan(8); - dirname = afstest_BuildTestConfig(); + + bct.skipkeys = 1; + dirname = afstest_BuildTestConfig(&bct); dir = afsconf_Open(dirname); if (dir == NULL) { diff --git a/tests/auth/keys-t.c b/tests/auth/keys-t.c index e814080b41..b36abb54fa 100644 --- a/tests/auth/keys-t.c +++ b/tests/auth/keys-t.c @@ -109,6 +109,7 @@ int main(int argc, char **argv) struct rx_opaque *keyMaterial; struct afsconf_typedKey *typedKey; struct afsconf_typedKeyList *typedKeyList; + struct afstest_configinfo bct; char *dirname; char *keyfile; char *keyfilesrc; @@ -116,13 +117,16 @@ int main(int argc, char **argv) int code; int i; + memset(&bct, 0, sizeof(bct)); + afstest_SkipTestsIfBadHostname(); plan(134); /* Create a temporary afs configuration directory */ - dirname = afstest_BuildTestConfig(); + bct.skipkeys = 1; + dirname = afstest_BuildTestConfig(&bct); keyfile = afstest_asprintf("%s/KeyFile", dirname); @@ -566,7 +570,7 @@ int main(int argc, char **argv) free(keyfile); /* Start a new test configuration */ - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(&bct); dir = afsconf_Open(dirname); ok(dir != NULL, "Sucessfully opened brand new config directory"); if (dir == NULL) diff --git a/tests/auth/realms-t.c b/tests/auth/realms-t.c index 23290d50f3..7acbe672d1 100644 --- a/tests/auth/realms-t.c +++ b/tests/auth/realms-t.c @@ -251,7 +251,7 @@ test_edges(void) char *dirname; /* run edge case tests */ - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); dir = afsconf_Open(dirname); if (dir == NULL) { fprintf(stderr, "Unable to configure directory.\n"); @@ -268,7 +268,7 @@ test_no_config_files(void) char *dirname; /* run tests without config files */ - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); dir = afsconf_Open(dirname); if (dir == NULL) { fprintf(stderr, "Unable to configure directory.\n"); @@ -285,7 +285,7 @@ test_with_config_files(void) char *dirname; /* run tests with config files */ - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); write_krb_conf(dirname, "MY.REALM.ORG MY.OTHER.REALM.ORG"); write_krb_excl(dirname); dir = afsconf_Open(dirname); @@ -309,7 +309,7 @@ test_set_local_realms(void) ok(afsconf_SetLocalRealm("MY.OTHER.REALM.ORG") == 0, "set local realm MY.OTHER.REALM.ORG"); /* run tests without config files */ - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); dir = afsconf_Open(dirname); if (dir == NULL) { fprintf(stderr, "Unable to configure directory.\n"); @@ -328,7 +328,7 @@ test_update_config_files(void) char *dirname; afs_int32 local = -1; - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); write_krb_conf(dirname, "SOME.REALM.ORG"); dir = afsconf_Open(dirname); if (dir == NULL) { diff --git a/tests/auth/superuser-t.c b/tests/auth/superuser-t.c index 52c1902d2a..bf41f8a033 100644 --- a/tests/auth/superuser-t.c +++ b/tests/auth/superuser-t.c @@ -399,7 +399,6 @@ int main(int argc, char **argv) struct afsconf_dir *dir; char *dirname; int serverPid, clientPid, waited, stat; - int code; int ret = 0; sigset_t set; char *argv0 = afstest_GetProgname(argv); @@ -430,7 +429,7 @@ int main(int argc, char **argv) sigaddset(&set, SIGUSR1); opr_Verify(sigprocmask(SIG_BLOCK, &set, NULL) == 0); - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); dir = afsconf_Open(dirname); if (dir == NULL) { @@ -439,13 +438,6 @@ int main(int argc, char **argv) goto out; } - code = afstest_AddDESKeyFile(dir); - if (code) { - afs_com_err(argv0, code, "while adding new key\n"); - ret = 1; - goto out; - } - printf("Config directory is %s\n", dirname); serverPid = fork(); if (serverPid == -1) { diff --git a/tests/auth/writekeyfile.c b/tests/auth/writekeyfile.c index 918bb2ad7c..362b473414 100644 --- a/tests/auth/writekeyfile.c +++ b/tests/auth/writekeyfile.c @@ -23,8 +23,13 @@ main(int argc, char **argv) char *keyfile = NULL; int in, out; size_t len; + struct afstest_configinfo bct; - dirname = afstest_BuildTestConfig(); + memset(&bct, 0, sizeof(bct)); + + bct.skipkeys = 1; + + dirname = afstest_BuildTestConfig(&bct); if (dirname == NULL) { fprintf(stderr, "Unable to create tmp config dir\n"); exit(1); diff --git a/tests/common/common.h b/tests/common/common.h index 213ab879dc..d2f69a1882 100644 --- a/tests/common/common.h +++ b/tests/common/common.h @@ -23,7 +23,12 @@ */ /* config.c */ -extern char *afstest_BuildTestConfig(void); + +struct afstest_configinfo { + /* Skip adding keys to the created conf dir. */ + int skipkeys; +}; +extern char *afstest_BuildTestConfig(struct afstest_configinfo *info); struct afsconf_dir; extern int afstest_AddDESKeyFile(struct afsconf_dir *dir); diff --git a/tests/common/config.c b/tests/common/config.c index 3603b0035a..0cddd0a71c 100644 --- a/tests/common/config.c +++ b/tests/common/config.c @@ -51,25 +51,35 @@ openConfigFile(char *dirname, char *filename) { /*! * Build a test configuration directory, containing a CellServDB and ThisCell - * file for the "example.org" cell + * file for the "example.org" cell. Also populates the KeyFile unless + * info->skipkeys is set. * + * @param[in] info Various details for how to create the config dir. If NULL, + * use a default zeroed struct. * @return * The path to the configuration directory. This should be freed by the caller * using free() - * */ - char * -afstest_BuildTestConfig(void) { +afstest_BuildTestConfig(struct afstest_configinfo *info) +{ char *dir = NULL; FILE *file; + struct afsconf_dir *confdir = NULL; + struct afstest_configinfo info_defaults; struct in_addr iaddr; + int code; + memset(&info_defaults, 0, sizeof(info_defaults)); memset(&iaddr, 0, sizeof(iaddr)); + if (info == NULL) { + info = &info_defaults; + } + dir = afstest_mkdtemp(); if (dir == NULL) { - goto fail; + goto error; } /* Work out which IP address to use in our CellServDB. We figure this out @@ -87,11 +97,31 @@ afstest_BuildTestConfig(void) { fprintf(file, "example.org"); fclose(file); + if (!info->skipkeys) { + confdir = afsconf_Open(dir); + if (confdir == NULL) { + goto error; + } + + code = afstest_AddDESKeyFile(confdir); + if (code != 0) { + goto error; + } + + afsconf_Close(confdir); + confdir = NULL; + } + return dir; -fail: - if (dir) + error: + if (confdir != NULL) { + afsconf_Close(confdir); + } + if (dir != NULL) { + afstest_rmdtemp(dir); free(dir); + } return NULL; } diff --git a/tests/volser/vos-t.c b/tests/volser/vos-t.c index f00fdbf2c8..813e568e05 100644 --- a/tests/volser/vos-t.c +++ b/tests/volser/vos-t.c @@ -96,17 +96,10 @@ main(int argc, char **argv) code = rx_Init(0); - dirname = afstest_BuildTestConfig(); + dirname = afstest_BuildTestConfig(NULL); dir = afsconf_Open(dirname); - code = afstest_AddDESKeyFile(dir); - if (code) { - afs_com_err(argv0, code, "while adding test DES keyfile"); - ret = 1; - goto out; - } - code = afstest_StartVLServer(dirname, &serverPid); if (code) { afs_com_err(argv0, code, "while starting the vlserver");