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(DUMP_RETURNS_1)
238 #if defined(USE_POSIX_FCNTL)
240 #elif defined(USE_FLOCK)
242 #elif defined(USE_LOCKF)
244 #elif defined(USE_LNLOCK)
252 #if defined(STATFS_BSD)
259 #if defined(STATFS_OSF1)
266 #if defined(STATFS_ULTRIX)
273 #if defined(ASSERTIONS)
280 #if defined(BSD_SECURITY)
287 #if defined(USE_AMANDAHOSTS)
294 #if defined(USE_RUNDUMP)
301 #if defined(CHECK_USERID)
307 { "USE_VERSION_SUFFIXES",
308 #if defined(USE_VERSION_SUFFIXES)
315 #if defined(HAVE_GZIP)
323 #if defined(KRB4_SECURITY)
329 { "SERVER_HOST_PRINCIPAL",
330 #if defined(KRB4_SECURITY)
331 SERVER_HOST_PRINCIPAL
336 { "SERVER_HOST_PRINCIPLE", /* backward-compatibility (spelling error) */
337 #if defined(KRB4_SECURITY)
338 SERVER_HOST_PRINCIPAL
343 { "SERVER_HOST_INSTANCE",
344 #if defined(KRB4_SECURITY)
350 { "SERVER_HOST_KEY_FILE",
351 #if defined(KRB4_SECURITY)
357 { "CLIENT_HOST_PRINCIPAL",
358 #if defined(KRB4_SECURITY)
359 CLIENT_HOST_PRINCIPAL
364 { "CLIENT_HOST_PRINCIPLE", /* backward-compatibility (spelling error) */
365 #if defined(KRB4_SECURITY)
366 CLIENT_HOST_PRINCIPAL
371 { "CLIENT_HOST_INSTANCE",
372 #if defined(KRB4_SECURITY)
378 { "CLIENT_HOST_KEY_FILE",
379 #if defined(KRB4_SECURITY)
387 #if defined(COMPRESS_SUFFIX)
393 { "COMPRESS_FAST_OPT",
394 #if defined(COMPRESS_FAST_OPT)
400 { "COMPRESS_BEST_OPT",
401 #if defined(COMPRESS_BEST_OPT)
408 #if defined(UNCOMPRESS_OPT)
425 char *parmname = NULL;
428 char number[NUM_STR_SIZE];
430 config_overwrites_t *cfg_ovr = NULL;
431 char *cfg_opt = NULL;
435 * Configure program for internationalization:
436 * 1) Only set the message locale for now.
437 * 2) Set textdomain for all amanda related programs to "amanda"
438 * We don't want to be forced to support dozens of message catalogs.
440 setlocale(LC_MESSAGES, "C");
441 textdomain("amanda");
445 cfg_ovr = extract_commandline_config_overwrites(&argc, &argv);
447 if((pgm = strrchr(argv[0], '/')) == NULL) {
454 /* Don't die when child closes pipe */
455 signal(SIGPIPE, SIG_IGN);
458 g_fprintf(stderr, _("Usage: %s [config] [--list] <parmname> [-o configoption]*\n"), pgm);
464 if (strcmp(argv[1],"--list") == 0) {
467 } else if (argc > 2 && strcmp(argv[2],"--list") == 0) {
470 } else if (argc > 2) {
474 if (myarg > asklist + 1)
478 error(_("Must specify a parameter"));
480 parmname = argv[myarg];
482 /* do the config_init() now, although the result isn't checked until the end,
483 * when we try to look up config parameters */
484 cfg_ok = config_init(CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_USE_CWD, cfg_opt);
485 if (cfg_ok) apply_config_overwrites(cfg_ovr);
487 safe_cd(); /* call this *after* config_init() */
489 /* Note that we dont use check_running_as(..) here, because we may not have a configuration
490 * (e.g., when we're examining build parameters). If folks run this as the wrong user, that's
491 * their own problem. */
494 * Fill in the build values that need runtime help.
496 build_info[0].value = stralloc(version());
497 #if defined(AMANDA_DEBUG_DAYS)
498 i = AMANDA_DEBUG_DAYS;
502 g_snprintf(number, SIZEOF(number), "%ld", (long)i);
503 build_info[1].value = stralloc(number);
504 #if defined(KRB4_SECURITY)
509 g_snprintf(number, SIZEOF(number), "%ld", (long)i);
510 build_info[2].value = stralloc(number);
515 if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
519 t = stralloc(parmname + SIZEOF(p) - 1);
520 for(i = 0; (s = build_info[i].symbol) != NULL; i++) {
521 if(strcasecmp(s, t) == 0) {
528 result = build_info[i].value;
529 result = stralloc(result ? result : "");
535 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
539 if((pname = strrchr(parmname + SIZEOF(p) - 1, '/')) == NULL) {
540 pname = parmname + SIZEOF(p) - 1;
545 dbopen(DBG_SUBDIR_SERVER);
546 if((dbname = dbfn()) == NULL) {
547 result = stralloc("/dev/null");
549 result = stralloc(dbname);
552 * Note that we deliberately do *not* call dbclose to prevent
553 * the end line from being added to the file.
559 } else if(strncmp(parmname, p, SIZEOF(p) - 1) == 0) {
564 t = stralloc(parmname + SIZEOF(p) - 1);
565 if((dbname = strchr(t, ':')) == NULL) {
566 error(_("cannot parse %s"), parmname);
570 if((pname = strrchr(t, '/')) == NULL) {
577 dbreopen(dbname, NULL);
579 result = stralloc(dbname);
583 /* *now* we check the result of config_init */
586 error(_("errors processing conf file \"%s\""), cfg_opt);
589 error(_("errors processing conf file in current directory."));
594 dbrename(config_name, DBG_SUBDIR_SERVER);
596 GSList *list = getconf_list(parmname);
598 result = stralloc("");
600 for (iter = list; iter != NULL; iter = iter->next) {
601 result = newvstralloc(result, result, iter->data, "\n", NULL);
606 val_t *val = getconf_byname(parmname);
608 char **dispstrs = val_t_display_strs(val, FALSE);
609 result = g_strjoinv("\n", dispstrs);
610 g_strfreev(dispstrs);
615 if (result == NULL) {
616 g_fprintf(stderr, _("%s: no such parameter \"%s\"\n"),
617 get_pname(), parmname);
621 fputs(result, stdout); /* don't add a '\n' */
623 puts(result); /* add a '\n' */
627 for(i = 0; i < 3; i++) {
628 amfree(build_info[i].value);