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_PRINCIPAL is defined as HOSTNAME_INSTANCE
44 * then local host is the client host principal.
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 },
65 { "amlibexecdir", amlibexecdir },
67 { "AMANDA_TMPDIR", AMANDA_TMPDIR },
68 { "CONFIG_DIR", CONFIG_DIR },
72 { "DEFAULT_SERVER", DEFAULT_SERVER },
73 { "DEFAULT_CONFIG", DEFAULT_CONFIG },
74 { "DEFAULT_TAPE_SERVER", DEFAULT_TAPE_SERVER },
75 #ifdef DEFAULT_TAPE_DEVICE
76 { "DEFAULT_TAPE_DEVICE", DEFAULT_TAPE_DEVICE },
78 { "CLIENT_LOGIN", CLIENT_LOGIN },
81 #if defined(BUILT_DATE)
88 #if defined(BUILT_MACH)
103 #if defined(AMANDA_DBGDIR)
110 #if defined(DEV_PREFIX)
117 #if defined(RDEV_PREFIX)
180 #if defined(SAMBA_CLIENT)
194 #if defined(COMPRESS_PATH)
201 #if defined(UNCOMPRESS_PATH)
208 #if defined(GNUTAR_LISTED_INCREMENTAL_DIR)
209 GNUTAR_LISTED_INCREMENTAL_DIR
214 { "GNUTAR_LISTED_INCREMENTAL_DIR",
215 #if defined(GNUTAR_LISTED_INCREMENTAL_DIR)
216 GNUTAR_LISTED_INCREMENTAL_DIR
223 #if defined(AIX_BACKUP)
230 #if defined(AIX_TAPEIO)
237 #if defined(DUMP_RETURNS_1)
245 #if defined(USE_POSIX_FCNTL)
247 #elif defined(USE_FLOCK)
249 #elif defined(USE_LOCKF)
251 #elif defined(USE_LNLOCK)
259 #if defined(STATFS_BSD)
266 #if defined(STATFS_OSF1)
273 #if defined(STATFS_ULTRIX)
280 #if defined(ASSERTIONS)
287 #if defined(DEBUG_CODE)
294 #if defined(BSD_SECURITY)
301 #if defined(USE_AMANDAHOSTS)
308 #if defined(USE_RUNDUMP)
315 #if defined(CHECK_USERID)
321 { "USE_VERSION_SUFFIXES",
322 #if defined(USE_VERSION_SUFFIXES)
329 #if defined(HAVE_GZIP)
337 #if defined(KRB4_SECURITY)
343 { "SERVER_HOST_PRINCIPAL",
344 #if defined(KRB4_SECURITY)
345 SERVER_HOST_PRINCIPAL
350 { "SERVER_HOST_PRINCIPLE", /* backward-compatibility (spelling error) */
351 #if defined(KRB4_SECURITY)
352 SERVER_HOST_PRINCIPAL
357 { "SERVER_HOST_INSTANCE",
358 #if defined(KRB4_SECURITY)
364 { "SERVER_HOST_KEY_FILE",
365 #if defined(KRB4_SECURITY)
371 { "CLIENT_HOST_PRINCIPAL",
372 #if defined(KRB4_SECURITY)
373 CLIENT_HOST_PRINCIPAL
378 { "CLIENT_HOST_PRINCIPLE", /* backward-compatibility (spelling error) */
379 #if defined(KRB4_SECURITY)
380 CLIENT_HOST_PRINCIPAL
385 { "CLIENT_HOST_INSTANCE",
386 #if defined(KRB4_SECURITY)
392 { "CLIENT_HOST_KEY_FILE",
393 #if defined(KRB4_SECURITY)
401 #if defined(COMPRESS_SUFFIX)
407 { "COMPRESS_FAST_OPT",
408 #if defined(COMPRESS_FAST_OPT)
414 { "COMPRESS_BEST_OPT",
415 #if defined(COMPRESS_BEST_OPT)
422 #if defined(UNCOMPRESS_OPT)
439 char *parmname = NULL;
442 char number[NUM_STR_SIZE];
444 config_overwrites_t *cfg_ovr = NULL;
445 char *cfg_opt = NULL;
449 * Configure program for internationalization:
450 * 1) Only set the message locale for now.
451 * 2) Set textdomain for all amanda related programs to "amanda"
452 * We don't want to be forced to support dozens of message catalogs.
454 setlocale(LC_MESSAGES, "C");
455 textdomain("amanda");
459 cfg_ovr = extract_commandline_config_overwrites(&argc, &argv);
461 if((pgm = strrchr(my_argv[0], '/')) == NULL) {
468 /* Don't die when child closes pipe */
469 signal(SIGPIPE, SIG_IGN);
472 g_fprintf(stderr, _("Usage: %s [config] [--list] <parmname> [-o configoption]*\n"), pgm);
478 if (strcmp(argv[1],"--list") == 0) {
481 } else if (argc > 2 && strcmp(argv[2],"--list") == 0) {
484 } else if (argc > 2) {
488 if (myarg > asklist + 1)
492 error(_("Must specify a parameter"));
494 parmname = argv[myarg];
496 /* do the config_init() now, although the result isn't checked until the end,
497 * when we try to look up config parameters */
498 cfg_ok = config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
499 if (cfg_ok) apply_config_overwrites(cfg_ovr);
501 safe_cd(); /* call this *after* config_init() */
503 /* Note that we dont use check_running_as(..) here, because we may not have a configuration
504 * (e.g., when we're examining build parameters). If folks run this as the wrong user, that's
505 * their own problem. */
508 * Fill in the build values that need runtime help.
510 build_info[0].value = stralloc(version());
511 #if defined(AMANDA_DEBUG_DAYS)
512 i = AMANDA_DEBUG_DAYS;
516 g_snprintf(number, SIZEOF(number), "%ld", (long)i);
517 build_info[1].value = stralloc(number);
518 #if defined(KRB4_SECURITY)
523 g_snprintf(number, SIZEOF(number), "%ld", (long)i);
524 build_info[2].value = stralloc(number);
529 if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
533 t = stralloc(parmname + SIZEOF(p) - 1);
534 for(i = 0; (s = build_info[i].symbol) != NULL; i++) {
535 if(strcasecmp(s, t) == 0) {
542 result = build_info[i].value;
543 result = stralloc(result ? result : "");
549 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
553 if((pname = strrchr(parmname + SIZEOF(p) - 1, '/')) == NULL) {
554 pname = parmname + SIZEOF(p) - 1;
559 dbopen(DBG_SUBDIR_SERVER);
560 if((dbname = dbfn()) == NULL) {
561 result = stralloc("/dev/null");
563 result = stralloc(dbname);
566 * Note that we deliberately do *not* call dbclose to prevent
567 * the end line from being added to the file.
573 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
578 t = stralloc(parmname + SIZEOF(p) - 1);
579 if((dbname = strchr(t, ':')) == NULL) {
580 error(_("cannot parse %s"), parmname);
584 if((pname = strrchr(t, '/')) == NULL) {
591 dbreopen(dbname, NULL);
593 result = stralloc(dbname);
597 /* *now* we check the result of config_init */
600 error(_("errors processing conf file \"%s\""), cfg_opt);
603 error(_("errors processing conf file in current directory."));
608 dbrename(config_name, DBG_SUBDIR_SERVER);
610 GSList *list = getconf_list(parmname);
612 result = stralloc("");
614 for (iter = list; iter != NULL; iter = iter->next) {
615 result = newvstralloc(result, result, iter->data, "\n", NULL);
620 val_t *val = getconf_byname(parmname);
622 char **dispstrs = val_t_display_strs(val, FALSE);
623 result = g_strjoinv("\n", dispstrs);
624 g_strfreev(dispstrs);
629 if (result == NULL) {
630 g_fprintf(stderr, _("%s: no such parameter \"%s\"\n"),
631 get_pname(), parmname);
635 fputs(result, stdout); /* don't add a '\n' */
637 puts(result); /* add a '\n' */
641 for(i = 0; i < 3; i++) {
642 amfree(build_info[i].value);