/* * Utility functions for tests that use Kerberos. * * Currently only provides kerberos_setup(), which assumes a particular set of * data files in either the SOURCE or BUILD directories and, using those, * obtains Kerberos credentials, sets up a ticket cache, and sets the * environment variable pointing to the Kerberos keytab to use for testing. * * Copyright 2006, 2007, 2009, 2010 * Board of Trustees, Leland Stanford Jr. University * * See LICENSE for licensing terms. */ #include #include #include #include #include #include /* * Given the partial path to a file, look under BUILD and then SOURCE for the * file and return the full path to the file in newly-allocated memory. * Returns NULL if the file doesn't exist. */ static char * find_file(const char *file) { char *base; char *path = NULL; const char *envs[] = { "BUILD", "SOURCE", NULL }; int i; for (i = 0; envs[i] != NULL; i++) { base = getenv(envs[i]); if (base == NULL) continue; path = concatpath(base, file); if (access(path, R_OK) == 0) break; free(path); path = NULL; } return path; } /* * Obtain Kerberos tickets for the principal specified in test.principal using * the keytab specified in test.keytab, both of which are presumed to be in * tests/data in either the build or the source tree. * * Returns the contents of test.principal in newly allocated memory or NULL if * Kerberos tests are apparently not configured. If Kerberos tests are * configured but something else fails, calls bail(). */ char * kerberos_setup(void) { static const char format1[] = "kinit -k -t %s %s >/dev/null 2>&1