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.26 2006/07/25 19:00:56 martinea Exp $
30 * a little wrapper to extract config variables for shell scripts
34 #include "genversion.h"
37 int main(int argc, char **argv);
40 * HOSTNAME_INSTANCE may not be defined at this point.
41 * We define it locally if it is needed...
43 * If CLIENT_HOST_PRINCIPLE is defined as HOSTNAME_INSTANCE
44 * then local host is the client host principle.
46 #ifndef HOSTNAME_INSTANCE
47 # define HOSTNAME_INSTANCE "localhost"
51 # define KEYFILE "id_rsa"
54 static struct build_info {
58 { "VERSION", "" }, /* must be [0] */
59 { "AMANDA_DEBUG_DAYS", "" }, /* must be [1] */
60 { "TICKET_LIFETIME", "" }, /* must be [2] */
63 { "sbindir", sbindir },
64 { "libexecdir", libexecdir },
66 { "AMANDA_TMPDIR", AMANDA_TMPDIR },
67 { "CONFIG_DIR", CONFIG_DIR },
69 { "DEFAULT_SERVER", DEFAULT_SERVER },
70 { "DEFAULT_CONFIG", DEFAULT_CONFIG },
71 { "DEFAULT_TAPE_SERVER", DEFAULT_TAPE_SERVER },
72 #ifdef DEFAULT_TAPE_DEVICE
73 { "DEFAULT_TAPE_DEVICE", DEFAULT_TAPE_DEVICE },
75 { "CLIENT_LOGIN", CLIENT_LOGIN },
78 #if defined(BUILT_DATE)
85 #if defined(BUILT_MACH)
100 #if defined(AMANDA_DBGDIR)
107 #if defined(DEV_PREFIX)
114 #if defined(RDEV_PREFIX)
177 #if defined(SAMBA_CLIENT)
191 #if defined(COMPRESS_PATH)
198 #if defined(UNCOMPRESS_PATH)
205 #if defined(GNUTAR_LISTED_INCREMENTAL_DIR)
206 GNUTAR_LISTED_INCREMENTAL_DIR
211 { "GNUTAR_LISTED_INCREMENTAL_DIR",
212 #if defined(GNUTAR_LISTED_INCREMENTAL_DIR)
213 GNUTAR_LISTED_INCREMENTAL_DIR
220 #if defined(AIX_BACKUP)
227 #if defined(AIX_TAPEIO)
234 #if defined(DUMP_RETURNS_1)
242 #if defined(USE_POSIX_FCNTL)
244 #elif defined(USE_FLOCK)
246 #elif defined(USE_LOCKF)
248 #elif defined(USE_LNLOCK)
256 #if defined(STATFS_BSD)
263 #if defined(STATFS_OSF1)
270 #if defined(STATFS_ULTRIX)
277 #if defined(ASSERTIONS)
284 #if defined(DEBUG_CODE)
291 #if defined(BSD_SECURITY)
298 #if defined(USE_AMANDAHOSTS)
305 #if defined(USE_RUNDUMP)
312 #if defined(FORCE_USERID)
318 { "USE_VERSION_SUFFIXES",
319 #if defined(USE_VERSION_SUFFIXES)
326 #if defined(HAVE_GZIP)
334 #if defined(KRB4_SECURITY)
340 { "SERVER_HOST_PRINCIPLE",
341 #if defined(KRB4_SECURITY)
342 SERVER_HOST_PRINCIPLE
347 { "SERVER_HOST_INSTANCE",
348 #if defined(KRB4_SECURITY)
354 { "SERVER_HOST_KEY_FILE",
355 #if defined(KRB4_SECURITY)
361 { "CLIENT_HOST_PRINCIPLE",
362 #if defined(KRB4_SECURITY)
363 CLIENT_HOST_PRINCIPLE
368 { "CLIENT_HOST_INSTANCE",
369 #if defined(KRB4_SECURITY)
375 { "CLIENT_HOST_KEY_FILE",
376 #if defined(KRB4_SECURITY)
384 #if defined(COMPRESS_SUFFIX)
390 { "COMPRESS_FAST_OPT",
391 #if defined(COMPRESS_FAST_OPT)
397 { "COMPRESS_BEST_OPT",
398 #if defined(COMPRESS_BEST_OPT)
405 #if defined(UNCOMPRESS_OPT)
421 unsigned long malloc_hist_1, malloc_size_1;
422 unsigned long malloc_hist_2, malloc_size_2;
428 char number[NUM_STR_SIZE];
429 int new_argc, my_argc;
430 char **new_argv, **my_argv;
435 malloc_size_1 = malloc_inuse(&malloc_hist_1);
437 parse_conf(argc, argv, &new_argc, &new_argv);
441 if((pgm = strrchr(my_argv[0], '/')) == NULL) {
448 /* Don't die when child closes pipe */
449 signal(SIGPIPE, SIG_IGN);
452 fprintf(stderr, "Usage: %s [config] [--list] <parmname> [-o configoption]*\n", pgm);
458 if (strcmp(my_argv[1],"--list") == 0) {
461 } else if (my_argc > 2 && strcmp(my_argv[2],"--list") == 0) {
464 } else if (my_argc > 2) {
468 if (myarg > asklist+1) {
469 config_name = stralloc(my_argv[1]);
470 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
472 char my_cwd[STR_SIZE];
474 if (getcwd(my_cwd, SIZEOF(my_cwd)) == NULL) {
475 error("cannot determine current working directory");
478 config_dir = stralloc2(my_cwd, "/");
479 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
480 config_name = stralloc(config_name + 1);
483 if (myarg >= my_argc) {
484 error("Must specify a parameter");
486 parmname = my_argv[myarg];
491 * Fill in the build values that need runtime help.
493 build_info[0].value = stralloc(version());
494 #if defined(AMANDA_DEBUG_DAYS)
495 i = AMANDA_DEBUG_DAYS;
499 snprintf(number, SIZEOF(number), "%ld", (long)i);
500 build_info[1].value = stralloc(number);
501 #if defined(KRB4_SECURITY)
506 snprintf(number, SIZEOF(number), "%ld", (long)i);
507 build_info[2].value = stralloc(number);
512 if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
516 t = stralloc(parmname + SIZEOF(p) - 1);
517 for(i = 0; (s = build_info[i].symbol) != NULL; i++) {
518 if(strcasecmp(s, t) == 0) {
525 result = build_info[i].value;
526 result = stralloc(result ? result : "");
532 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
536 if((pname = strrchr(parmname + SIZEOF(p) - 1, '/')) == NULL) {
537 pname = parmname + SIZEOF(p) - 1;
542 dbopen(DBG_SUBDIR_SERVER);
543 if((dbname = dbfn()) == NULL) {
544 result = stralloc("/dev/null");
546 result = stralloc(dbname);
549 * Note that we deliberately do *not* call dbclose to prevent
550 * the end line from being added to the file.
556 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
561 t = stralloc(parmname + SIZEOF(p) - 1);
562 if((dbname = strchr(t, ':')) == NULL) {
563 error("cannot parse %s", parmname);
567 if((pname = strrchr(t, '/')) == NULL) {
574 dbreopen(dbname, NULL);
576 result = stralloc(dbname);
580 conffile = stralloc2(config_dir, CONFFILE_NAME);
581 if(read_conffile(conffile)) {
582 error("errors processing config file \"%s\"", conffile);
586 dbrename(config_name, DBG_SUBDIR_SERVER);
587 report_bad_conf_arg();
589 result = getconf_list(parmname);
591 result = getconf_byname(parmname);
595 if (result == NULL) {
596 fprintf(stderr, "%s: no such parameter \"%s\"\n",
597 get_pname(), parmname);
601 fputs(result, stdout); /* don't add a '\n' */
603 puts(result); /* add a '\n' */
606 free_new_argv(new_argc, new_argv);
607 free_server_config();
611 for(i = 0; i < 3; i++) {
612 amfree(build_info[i].value);
615 malloc_size_2 = malloc_inuse(&malloc_hist_2);
617 if(malloc_size_1 != malloc_size_2) {
618 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);