X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=recover-src%2Famrecover.c;h=b44724d12a4c42ee76f8faa8b54debaf76f442ab;hb=HEAD;hp=3ec633da6321ef45bde6e3cef4c066a35a06f851;hpb=fd48f3e498442f0cbff5f3606c7c403d0566150e;p=debian%2Famanda diff --git a/recover-src/amrecover.c b/recover-src/amrecover.c index 3ec633d..b44724d 100644 --- a/recover-src/amrecover.c +++ b/recover-src/amrecover.c @@ -1,6 +1,7 @@ /* * Amanda, The Advanced Maryland Automatic Network Disk Archiver * Copyright (c) 1991-1998, 2000 University of Maryland at College Park + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * All Rights Reserved. * * Permission to use, copy, modify, distribute, and sell this software and its @@ -41,6 +42,7 @@ #include "event.h" #include "security.h" #include "conffile.h" +#include "getopt.h" #define amrecover_debug(i, ...) do { \ if ((i) <= debug_amrecover) { \ @@ -48,13 +50,18 @@ } \ } while (0) +static struct option long_options[] = { + {"version" , 0, NULL, 1}, + {NULL, 0, NULL, 0} +}; + extern int process_line(char *line); int get_line(void); int grab_reply(int show); void sigint_handler(int signum); int main(int argc, char **argv); -#define USAGE _("Usage: amrecover [[-C] ] [-s ] [-t ] [-d ] [-o ]*\n") +#define USAGE _("Usage: amrecover [--version] [[-C] ] [-s ] [-t ] [-d ] [-o ]*\n") char *server_name = NULL; int server_socket; @@ -65,6 +72,7 @@ char *disk_name = NULL; /* disk we are restoring */ dle_t *dump_dle = NULL; char *mount_point = NULL; /* where disk was mounted */ char *disk_path = NULL; /* path relative to mount point */ +char *disk_tpath = NULL; /* translated path relative to mount point */ char dump_date[STR_SIZE]; /* date on which we are restoring */ int quit_prog; /* set when time to exit parser */ char *tape_server_name = NULL; @@ -137,6 +145,7 @@ get_line(void) server_line = newstralloc(server_line, mesg_buffer); amfree(mesg_buffer); mesg_buffer = newbuf; + amrecover_debug(1, "server_line: %s\n", server_line); amrecover_debug(1, "get: %s\n", mesg_buffer); return 0; } @@ -271,7 +280,7 @@ sigint_handler( } -void +char * clean_pathname( char * s) { @@ -289,6 +298,8 @@ clean_pathname( /* remove "/." at end of path */ if(strcmp(&(s[length-2]),"/.")==0) s[length-2]='\0'; + + return s; } @@ -300,8 +311,6 @@ quit(void) stop_amindexd(); } -char *localhost = NULL; - #ifdef DEFAULT_TAPE_SERVER # define DEFAULT_TAPE_SERVER_FAILOVER (DEFAULT_TAPE_SERVER) #else @@ -325,6 +334,7 @@ main( int response_error; struct tm *tm; config_overrides_t *cfg_ovr; + char *starting_hostname = NULL; /* * Configure program for internationalization: @@ -344,13 +354,6 @@ main( dbopen(DBG_SUBDIR_CLIENT); - localhost = alloc(MAX_HOSTNAME_LENGTH+1); - if (gethostname(localhost, MAX_HOSTNAME_LENGTH) != 0) { - error(_("cannot determine local host name\n")); - /*NOTREACHED*/ - } - localhost[MAX_HOSTNAME_LENGTH] = '\0'; - /* treat amrecover-specific command line options as the equivalent * -o command-line options to set configuration values */ cfg_ovr = new_config_overrides(argc/2); @@ -367,8 +370,12 @@ main( } /* now parse regular command-line '-' options */ - while ((i = getopt(argc, argv, "o:C:s:t:d:U")) != EOF) { + while ((i = getopt_long(argc, argv, "o:C:s:t:d:Uh:", long_options, NULL)) != EOF) { switch (i) { + case 1: + printf("amrecover-%s\n", VERSION); + return(0); + break; case 'C': add_config_override(cfg_ovr, "conf", optarg); break; @@ -389,6 +396,10 @@ main( add_config_override_opt(cfg_ovr, optarg); break; + case 'h': + starting_hostname = g_strdup(optarg); + break; + case 'U': case '?': (void)g_printf(USAGE); @@ -422,6 +433,15 @@ main( our_features = am_init_feature_set(); our_features_string = am_feature_to_string(our_features); + if (!starting_hostname) { + starting_hostname = alloc(MAX_HOSTNAME_LENGTH+1); + if (gethostname(starting_hostname, MAX_HOSTNAME_LENGTH) != 0) { + error(_("cannot determine local host name\n")); + /*NOTREACHED*/ + } + starting_hostname[MAX_HOSTNAME_LENGTH] = '\0'; + } + server_name = NULL; if (getconf_seen(CNF_INDEX_SERVER) == -2) { /* command line argument */ server_name = getconf_str(CNF_INDEX_SERVER); @@ -481,6 +501,7 @@ main( amfree(disk_name); amfree(mount_point); amfree(disk_path); + amfree(disk_tpath); dump_date[0] = '\0'; /* Don't die when child closes pipe */ @@ -584,7 +605,7 @@ main( if (server_happy()) { /* set host we are restoring to this host by default */ amfree(dump_hostname); - set_host(localhost); + set_host(starting_hostname); if (dump_hostname) g_printf(_("Use the setdisk command to choose dump disk to recover\n")); else @@ -825,3 +846,40 @@ stop_amindexd(void) } } } + + +char * +translate_octal( + char *line) +{ + char *s = line, *s1, *s2; + char *p = line; + int i; + + if (!translate_mode) + return strdup(line); + + while(*s != '\0') { + if ((s == line || *(s-1) != '\\') && *s == '\\') { + s++; + s1 = s+1; + s2 = s+2; + if (g_ascii_isdigit(*s) && *s1 != '\0' && + g_ascii_isdigit(*s1) && + g_ascii_isdigit(*s2)) { + i = ((*s)-'0')*64 + ((*s1)-'0')*8 + ((*s2)-'0'); + *p++ = i; + s += 3; + } else { + *p++ = *s++; + } + + } else { + *p++ = *s++; + } + } + *p = '\0'; + + return line; +} +