Imported Upstream version 3.1.0
[debian/amanda] / common-src / amgetconf.pl
index 86870e1e3e1633c3178ab0b7926ab15968459c62..1b519a390062187b53dffba8f859157fbcbfdb9d 100644 (file)
@@ -1,5 +1,5 @@
 #! @PERL@
-# Copyright (c) 2005-2008 Zmanda Inc.  All Rights Reserved.
+# Copyright (c) 2008,2009 Zmanda, Inc.  All Rights Reserved.
 #
 # This program is free software; you can redistribute it and/or modify it
 # under the terms of the GNU General Public License version 2 as published
@@ -14,7 +14,7 @@
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-# Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
+# Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
 
 use lib '@amperldir@';
@@ -58,7 +58,8 @@ values in subsections are specified in the form TYPE:NAME:PARAMETER.
 With --list, PARAM can be one of
 EOF
     for my $name (keys %Amanda::Config::subsection_names) {
-       print "    $name\n";
+       print "    $name\n"
+           if $Amanda::Config::subsection_names{$name};
     }
     exit(1);
 }
@@ -101,7 +102,7 @@ my %build_info = (
     'cc' => $Amanda::Constants::CC,
     'version' => $Amanda::Constants::VERSION,
     'assertions' => $Amanda::Constants::ASSERTIONS,
-    'use_version_suffixes' => $Amanda::Constants::USE_VERSION_SUFFIXES,
+    'use_version_suffixes' => 'no', # for backward compatibility
     'locking' => $Amanda::Constants::LOCKING,
 
     # executable paths
@@ -127,7 +128,6 @@ my %build_info = (
     'bsd_security' => $Amanda::Constants::BSD_SECURITY,
     'bsdudp_security' => $Amanda::Constants::BSDUDP_SECURITY,
     'bsdtcp_security' => $Amanda::Constants::BSDTCP_SECURITY,
-    'krb4_security' => $Amanda::Constants::KRB4_SECURITY,
     'krb5_security' => $Amanda::Constants::KRB5_SECURITY,
     'ssh_security' => $Amanda::Constants::SSH_SECURITY,
     'rsh_security' => $Amanda::Constants::RSH_SECURITY,
@@ -193,18 +193,32 @@ sub build_param {
 sub db_param {
     my ($parameter, $opt_list) = @_;
     my ($appname, $filename);
+
+    # copy amgetconf pname and pcontext
+    my $pname = Amanda::Util::get_pname();
+    my $pcontext = Amanda::Util::get_pcontext();
+
     if (($appname) = $parameter =~ /^dbopen\.(.*)/) {
        $appname =~ s/[^[:alnum:]]/_/g;
-       Amanda::Util::setup_application($appname, "server", $CONTEXT_CMDLINE);
+       # set pname and pcontext for the application
+       Amanda::Util::set_pname($appname);
+       Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
+       Amanda::Debug::dbopen("server");
        print Amanda::Debug::dbfn(), "\n";
     } elsif (($appname, $filename) = $parameter =~ /^dbclose\.([^:]*):(.*)/) {
        fail("debug file $filename does not exist") unless (-f $filename);
+       # set pname and pcontext for the application
+       Amanda::Util::set_pname($appname);
+       Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
        Amanda::Debug::dbreopen($filename, '');
        Amanda::Debug::dbclose();
        print "$filename\n";
     } else {
        fail("cannot parse $parameter");
     }
+    # reset pname and pcontext for amgetconf
+    Amanda::Util::set_pcontext($pcontext);
+    Amanda::Util::set_pname($pname);
 }
 
 ## regular configuration parameters
@@ -236,13 +250,13 @@ sub conf_param {
 ## Command-line parsing
 
 my $opt_list = '';
-my $config_overwrites = new_config_overwrites($#ARGV+1);
+my $config_overrides = new_config_overrides($#ARGV+1);
 my $execute_where = undef;
 
 Getopt::Long::Configure(qw{bundling});
 GetOptions(
     'list|l' => \$opt_list,
-    'o=s' => sub { add_config_overwrite_opt($config_overwrites, $_[1]); },
+    'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
     'execute-where=s' => sub {
         my $where = lc($_[1]);
         fail("Invalid value ($_[1]) for --execute-where. Must be client or server.") 
@@ -276,20 +290,25 @@ if (@ARGV == 1) {
 
 ## Now start looking at the parameter.
 
+Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
+
 if ($parameter =~ /^build(?:\..*)?/) {
+    config_init(0|$execute_where, undef);
     build_param($parameter, $opt_list);
+    Amanda::Util::finish_application();
     exit(0);
 } 
 
 if ($parameter =~ /^db(open|close)\./) {
+    config_init(0|$execute_where, undef);
     db_param($parameter, $opt_list);
+    Amanda::Util::finish_application();
     exit(0);
 }
 
 # finally, finish up the application startup procedure
-Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
+set_config_overrides($config_overrides);
 config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
-apply_config_overwrites($config_overwrites);
 my ($cfgerr_level, @cfgerr_errors) = config_errors();
 if ($cfgerr_level >= $CFGERR_WARNINGS) {
     config_print_errors();
@@ -301,3 +320,5 @@ if ($cfgerr_level >= $CFGERR_WARNINGS) {
 Amanda::Util::finish_setup($RUNNING_AS_ANY);
 
 conf_param($parameter, $opt_list);
+
+Amanda::Util::finish_application();