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;
427 char number[NUM_STR_SIZE];
428 int new_argc, my_argc;
429 char **new_argv, **my_argv;
433 malloc_size_1 = malloc_inuse(&malloc_hist_1);
435 parse_server_conf(argc, argv, &new_argc, &new_argv);
439 if((pgm = strrchr(my_argv[0], '/')) == NULL) {
446 /* Don't die when child closes pipe */
447 signal(SIGPIPE, SIG_IGN);
450 fprintf(stderr, "Usage: %s [config] <parmname> [-o configoption]*\n", pgm);
455 config_name = stralloc(my_argv[1]);
456 config_dir = vstralloc(CONFIG_DIR, "/", config_name, "/", NULL);
457 parmname = my_argv[2];
459 char my_cwd[STR_SIZE];
461 if (getcwd(my_cwd, SIZEOF(my_cwd)) == NULL) {
462 error("cannot determine current working directory");
465 config_dir = stralloc2(my_cwd, "/");
466 if ((config_name = strrchr(my_cwd, '/')) != NULL) {
467 config_name = stralloc(config_name + 1);
469 parmname = my_argv[1];
475 * Fill in the build values that need runtime help.
477 build_info[0].value = stralloc(version());
478 #if defined(AMANDA_DEBUG_DAYS)
479 i = AMANDA_DEBUG_DAYS;
483 snprintf(number, SIZEOF(number), "%ld", (long)i);
484 build_info[1].value = stralloc(number);
485 #if defined(KRB4_SECURITY)
490 snprintf(number, SIZEOF(number), "%ld", (long)i);
491 build_info[2].value = stralloc(number);
496 if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
500 t = stralloc(parmname + SIZEOF(p) - 1);
501 for(i = 0; (s = build_info[i].symbol) != NULL; i++) {
502 if(strcasecmp(s, t) == 0) {
509 result = build_info[i].value;
510 result = stralloc(result ? result : "");
516 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
520 if((pname = strrchr(parmname + SIZEOF(p) - 1, '/')) == NULL) {
521 pname = parmname + SIZEOF(p) - 1;
526 dbopen(DBG_SUBDIR_SERVER);
527 if((dbname = dbfn()) == NULL) {
528 result = stralloc("/dev/null");
530 result = stralloc(dbname);
533 * Note that we deliberately do *not* call dbclose to prevent
534 * the end line from being added to the file.
540 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
545 t = stralloc(parmname + SIZEOF(p) - 1);
546 if((dbname = strchr(t, ':')) == NULL) {
547 error("cannot parse %s", parmname);
551 if((pname = strrchr(t, '/')) == NULL) {
558 dbreopen(dbname, NULL);
560 result = stralloc(dbname);
564 conffile = stralloc2(config_dir, CONFFILE_NAME);
565 if(read_conffile(conffile)) {
566 error("errors processing config file \"%s\"", conffile);
570 dbrename(config_name, DBG_SUBDIR_SERVER);
571 report_bad_conf_arg();
572 result = getconf_byname(parmname);
575 if (result == NULL) {
576 fprintf(stderr, "%s: no such parameter \"%s\"\n",
577 get_pname(), parmname);
583 free_new_argv(new_argc, new_argv);
584 free_server_config();
588 for(i = 0; i < 3; i++) {
589 amfree(build_info[i].value);
592 malloc_size_2 = malloc_inuse(&malloc_hist_2);
594 if(malloc_size_1 != malloc_size_2) {
595 malloc_list(fileno(stderr), malloc_hist_1, malloc_hist_2);