2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1998 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: getconf.c,v 1.8.4.2.2.2.2.4 2003/12/16 22:36:45 martinea Exp $
30 * a little wrapper to extract config variables for shell scripts
34 #include "genversion.h"
37 #define HOSTNAME_INSTANCE "host_inst"
39 int main P((int argc, char **argv));
41 static struct build_info {
45 { "VERSION", "" }, /* must be [0] */
46 { "AMANDA_DEBUG_DAYS", "" }, /* must be [1] */
47 { "TICKET_LIFETIME", "" }, /* must be [2] */
50 { "sbindir", sbindir },
51 { "libexecdir", libexecdir },
53 { "AMANDA_TMPDIR", AMANDA_TMPDIR },
54 { "CONFIG_DIR", CONFIG_DIR },
56 { "DEFAULT_SERVER", DEFAULT_SERVER },
57 { "DEFAULT_CONFIG", DEFAULT_CONFIG },
58 { "DEFAULT_TAPE_SERVER", DEFAULT_TAPE_SERVER },
59 { "DEFAULT_TAPE_DEVICE", DEFAULT_TAPE_SERVER },
62 #if defined(BUILT_DATE)
67 #if defined(BUILT_MACH)
78 #if defined(AMANDA_DBGDIR)
83 #if defined(DEV_PREFIX)
88 #if defined(RDEV_PREFIX)
132 #if defined(SAMBA_CLIENT)
142 #if defined(COMPRESS_PATH)
147 #if defined(UNCOMPRESS_PATH)
152 #if defined(GNUTAR_LISTED_INCREMENTAL_DIR)
153 GNUTAR_LISTED_INCREMENTAL_DIR
156 { "GNUTAR_LISTED_INCREMENTAL_DIR",
157 #if defined(GNUTAR_LISTED_INCREMENTAL_DIR)
158 GNUTAR_LISTED_INCREMENTAL_DIR
163 #if defined(AIX_BACKUP)
168 #if defined(AIX_TAPEIO)
173 #if defined(DUMP_RETURNS_1)
179 #if defined(USE_POSIX_FCNTL)
181 #elif defined(USE_FLOCK)
183 #elif defined(USE_LOCKF)
185 #elif defined(USE_LNLOCK)
193 #if defined(STATFS_BSD)
198 #if defined(STATFS_OSF1)
203 #if defined(STATFS_ULTRIX)
208 #if defined(ASSERTIONS)
213 #if defined(DEBUG_CODE)
218 #if defined(BSD_SECURITY)
223 #if defined(USE_AMANDAHOSTS)
228 #if defined(USE_RUNDUMP)
233 #if defined(FORCE_USERID)
237 { "USE_VERSION_SUFFIXES",
238 #if defined(USE_VERSION_SUFFIXES)
243 #if defined(HAVE_GZIP)
249 #if defined(KRB4_SECURITY)
253 { "SERVER_HOST_PRINCIPLE",
254 #if defined(KRB4_SECURITY)
255 SERVER_HOST_PRINCIPLE
258 { "SERVER_HOST_INSTANCE",
259 #if defined(KRB4_SECURITY)
263 { "SERVER_HOST_KEY_FILE",
264 #if defined(KRB4_SECURITY)
268 { "CLIENT_HOST_PRINCIPLE",
269 #if defined(KRB4_SECURITY)
270 CLIENT_HOST_PRINCIPLE
273 { "CLIENT_HOST_INSTANCE",
274 #if defined(KRB4_SECURITY)
278 { "CLIENT_HOST_KEY_FILE",
279 #if defined(KRB4_SECURITY)
285 #if defined(COMPRESS_SUFFIX)
289 { "COMPRESS_FAST_OPT",
290 #if defined(COMPRESS_FAST_OPT)
294 { "COMPRESS_BEST_OPT",
295 #if defined(COMPRESS_BEST_OPT)
300 #if defined(UNCOMPRESS_OPT)
314 unsigned long malloc_hist_1, malloc_size_1;
315 unsigned long malloc_hist_2, malloc_size_2;
320 char number[NUM_STR_SIZE];
322 for(fd = 3; fd < FD_SETSIZE; fd++) {
324 * Make sure nobody spoofs us with a lot of extra open files
325 * that would cause an open we do to get a very high file
326 * descriptor, which in turn might be used as an index into
327 * an array (e.g. an fd_set).
332 malloc_size_1 = malloc_inuse(&malloc_hist_1);
334 if((pgm = strrchr(argv[0], '/')) == NULL) {
342 fprintf(stderr, "Usage: %s [config] <parmname>\n", pgm);
347 config_name = stralloc(argv[1]);
348 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
351 char my_cwd[STR_SIZE];
353 if (getcwd(my_cwd, sizeof(my_cwd)) == NULL) {
354 error("cannot determine current working directory");
356 config_dir = stralloc2(my_cwd, "/");
357 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
358 config_name = stralloc(config_name + 1);
365 conffile = stralloc2(config_dir, CONFFILE_NAME);
366 if(read_conffile(conffile)) {
367 error("errors processing config file \"%s\"", conffile);
372 * Fill in the build values that need runtime help.
374 build_info[0].value = stralloc(version());
375 #if defined(AMANDA_DEBUG_DAYS)
376 i = AMANDA_DEBUG_DAYS;
380 ap_snprintf(number, sizeof(number), "%ld", (long)i);
381 build_info[1].value = stralloc(number);
382 #if defined(KRB4_SECURITY)
387 ap_snprintf(number, sizeof(number), "%ld", (long)i);
388 build_info[2].value = stralloc(number);
393 if(strncmp(parmname, p, sizeof(p) - 1) == 0) {
397 t = stralloc(parmname + sizeof(p) - 1);
398 for(i = 0; (s = build_info[i].symbol) != NULL; i++) {
399 if(strcasecmp(s, t) == 0) {
406 result = build_info[i].value;
407 result = stralloc(result ? result : "");
413 } else if(strncmp(parmname, p, sizeof(p) - 1) == 0) {
417 if((pname = strrchr(parmname + sizeof(p) - 1, '/')) == NULL) {
418 pname = parmname + sizeof(p) - 1;
424 if((dbname = dbfn()) == NULL) {
425 result = stralloc("/dev/null");
427 result = stralloc(dbname);
433 } else if(strncmp(parmname, p, sizeof(p) - 1) == 0) {
440 t = stralloc(parmname + sizeof(p) - 1);
441 if((dbname = strchr(t, ':')) == NULL) {
442 error("cannot parse %s", parmname);
445 if((pname = strrchr(t, '/')) == NULL) {
451 if((old_fd2 = dup(2)) < 0) {
452 error("cannot dup2 fd2");
455 if((new_fd2 = open(dbname, O_RDWR|O_APPEND, 0600)) != 2) {
456 int save_errno = errno;
459 if((f = fdopen(old_fd2, "a")) == NULL) {
463 fprintf(f, "%s: cannot open %s: ", get_pname(), dbname);
465 fputs(strerror(save_errno), f);
467 fprintf(f, "got %d instead of 2", new_fd2);
473 * Because we have not called dbopen(), dbclose() will write the
474 * end line to stderr, which we just redirected to the file on
479 result = stralloc(dbname);
483 result = getconf_byname(parmname);
486 result = stralloc("BUGGY");
487 fprintf(stderr, "%s: no such parameter \"%s\"\n",
488 get_pname(), parmname);
497 for(i = 0; i < 3; i++) {
498 amfree(build_info[i].value);
501 malloc_size_2 = malloc_inuse(&malloc_hist_2);
503 if(malloc_size_1 != malloc_size_2) {
504 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);