1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
|
/*
* Utility functions for tests that use remctl.
*
* Provides functions to start and stop a remctl daemon that uses the test
* Kerberos environment and runs on port 14373 instead of the default 4373.
*
* The canonical version of this file is maintained in the rra-c-util package,
* which can be found at <https://www.eyrie.org/~eagle/software/rra-c-util/>.
*
* Written by Russ Allbery <eagle@eyrie.org>
* Copyright 2018, 2020 Russ Allbery <eagle@eyrie.org>
* Copyright 2006-2007, 2009, 2011-2014
* The Board of Trustees of the Leland Stanford Junior University
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
*
* SPDX-License-Identifier: MIT
*/
#include <config.h>
#include <portable/system.h>
#include <tests/tap/basic.h>
#include <tests/tap/kerberos.h>
#include <tests/tap/macros.h>
#include <tests/tap/process.h>
#include <tests/tap/remctl.h>
#include <tests/tap/string.h>
#include <util/vector.h>
/* May be defined by the build system. */
#ifndef PATH_REMCTLD
# define PATH_REMCTLD ""
#endif
/*
* Internal helper function for remctld_start and remctld_start_fakeroot.
*
* Takes the Kerberos test configuration (the keytab principal is used as the
* server principal), the configuration file to use (found via
* test_file_path), and then any additional arguments to pass to remctld,
* ending with a NULL. Returns the PID of the running remctld process. If
* anything fails, calls bail.
*
* The path to remctld is obtained from the PATH_REMCTLD #define. If this is
* not set, remctld_start_internal calls skip_all.
*/
static struct process *
remctld_start_internal(struct kerberos_config *krbconf, const char *config,
va_list args, bool fakeroot)
{
va_list args_copy;
char *tmpdir, *pidfile, *confpath;
const char *valgrind;
struct vector *valgrind_args = NULL;
size_t i, length;
const char *arg, **argv;
struct process *process;
const char *path_remctld = PATH_REMCTLD;
/* Check prerequisites. */
if (path_remctld[0] == '\0')
skip_all("remctld not found");
/* Determine the location of the PID file and remove any old ones. */
tmpdir = test_tmpdir();
basprintf(&pidfile, "%s/remctld.pid", tmpdir);
if (access(pidfile, F_OK) == 0)
bail("remctld may already be running: %s exists", pidfile);
/* If valgrind testing is configured, get the options to valgrind. */
length = 0;
valgrind = getenv("C_TAP_VALGRIND");
if (valgrind != NULL) {
valgrind_args = vector_split_space(valgrind, NULL);
length += valgrind_args->count;
}
/* Build the argv used to run remctld. */
confpath = test_file_path(config);
if (confpath == NULL)
bail("cannot find remctld config %s", config);
length += 11;
va_copy(args_copy, args);
while (va_arg(args_copy, const char *) != NULL)
length++;
va_end(args_copy);
argv = bcalloc(length, sizeof(const char *));
i = 0;
if (valgrind_args != NULL)
for (i = 0; i < valgrind_args->count; i++)
argv[i] = valgrind_args->strings[i];
argv[i++] = path_remctld;
argv[i++] = "-mdSF";
argv[i++] = "-p";
argv[i++] = "14373";
argv[i++] = "-s";
argv[i++] = krbconf->principal;
argv[i++] = "-P";
argv[i++] = pidfile;
argv[i++] = "-f";
argv[i++] = confpath;
while ((arg = va_arg(args, const char *)) != NULL)
argv[i++] = arg;
argv[i] = NULL;
/* Start remctld using process_start or process_start_fakeroot. */
if (fakeroot)
process = process_start_fakeroot(argv, pidfile);
else
process = process_start(argv, pidfile);
/* Clean up and return. */
vector_free(valgrind_args);
test_file_path_free(confpath);
free(pidfile);
test_tmpdir_free(tmpdir);
free(argv);
return process;
}
/*
* Just calls remctld_start_internal without enabling fakeroot support.
*/
struct process *
remctld_start(struct kerberos_config *krbconf, const char *config, ...)
{
va_list args;
struct process *process;
va_start(args, config);
process = remctld_start_internal(krbconf, config, args, false);
va_end(args);
return process;
}
/*
* Just calls remctld_start_internal with fakeroot enabled.
*/
struct process *
remctld_start_fakeroot(struct kerberos_config *krbconf, const char *config,
...)
{
va_list args;
struct process *process;
va_start(args, config);
process = remctld_start_internal(krbconf, config, args, true);
va_end(args);
return process;
}
|