* file named AUTHORS, in the root directory of this distribution.
*/
/*
- * $Id: extract_list.c,v 1.6 2006/08/24 01:57:15 paddy_s Exp $
+ * $Id$
*
* implements the "extract" command in amrecover
*/
#include "amanda.h"
+#include "match.h"
#include "conffile.h"
-#include "version.h"
#include "amrecover.h"
#include "fileheader.h"
#include "dgram.h"
EXTRACT_LIST * tape_list)
{
EXTRACT_LIST_ITEM *this, *next;
-
+
this = tape_list->files;
while (this != NULL)
/* add this in date increasing order */
/* because restore must be done in this order */
/* add at begining */
- if(extract_list==NULL || strcmp(this->date,extract_list->date) < 0)
+ if(extract_list==NULL || strcmp(this->date,extract_list->date) < 0)
{
this->next = extract_list;
extract_list = this;
char *err = NULL;
int i;
ssize_t j;
- char *dir, *dir_undo, dir_undo_ch = '\0';
+ char *dir_undo, dir_undo_ch = '\0';
char *ditem_path = NULL;
char *l = NULL;
int added;
path_on_disk = stralloc2("/", regex);
}
} else {
- char *clean_disk_path = clean_regex(disk_path);
+ char *clean_disk_path = clean_regex(disk_path, 0);
path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
amfree(clean_disk_path);
}
err = _("bad reply: missing directory field");
continue;
}
- dir = s - 1;
skip_quoted_string(s, ch);
dir_undo = s - 1;
dir_undo_ch = *dir_undo;
char *tape, *tape_undo, tape_undo_ch = '\0';
char *dir_undo, dir_undo_ch = '\0';
int level = 0;
- off_t fileno;
char *ditem_path = NULL;
char *l = NULL;
int deleted;
path_on_disk = stralloc2("/", regex);
}
} else {
- char *clean_disk_path = clean_regex(disk_path);
+ char *clean_disk_path = clean_regex(disk_path, 0);
path_on_disk = vstralloc(clean_disk_path, "/", regex, NULL);
amfree(clean_disk_path);
}
err = _("bad reply: cannot parse fileno field");
continue;
}
- fileno = (off_t)fileno_;
skip_integer(s, ch);
}
nread = read(tape_control_sock, buffer, sizeof(buffer));
if (nread <= 0) {
- error(_("Could not read from control socket: %s\n"),
+ error(_("Could not read from control socket: %s\n"),
strerror(errno));
/*NOTREACHED*/
}
}
amfree(our_feature_string);
-
+
line = get_security();
send_to_tape_server(tape_data_sock, line);
EXTRACT_LIST * elist)
{
int save_errno;
- int extra_params = 0;
- int i,j=0;
- char **restore_args = NULL;
+ int i;
+ guint j;
+ GPtrArray *argv_ptr = g_ptr_array_new();
int files_off_tape;
EXTRACT_LIST_ITEM *fn;
enum dumptypes dumptype = IS_UNKNOWN;
dumpfile_t file;
size_t len_program;
char *cmd = NULL;
- int passwd_field = -1;
+ guint passwd_field = 999999999;
#ifdef SAMBA_CLIENT
char *domain = NULL, *smbpass = NULL;
#endif
/* form the arguments to restore */
files_off_tape = length_of_tape_list(elist);
- switch (dumptype) {
- case IS_SAMBA:
-#ifdef SAMBA_CLIENT
- extra_params = 10;
- break;
-#endif
- case IS_TAR:
- case IS_GNUTAR:
- extra_params = 4;
- break;
- case IS_SAMBA_TAR:
- extra_params = 3;
- break;
- case IS_UNKNOWN:
- case IS_DUMP:
-#ifdef AIX_BACKUP
- extra_params = 2;
-#else
-#if defined(XFSDUMP)
- if (strcmp(file.program, XFSDUMP) == 0) {
- extra_params = 4 + files_off_tape;
- } else
-#endif
- {
- extra_params = 4;
- }
-#endif
- break;
- }
-
- restore_args = (char **)alloc((size_t)((extra_params + files_off_tape + 1)
- * sizeof(char *)));
switch(dumptype) {
case IS_SAMBA:
#ifdef SAMBA_CLIENT
- restore_args[j++] = stralloc("smbclient");
- smbpass = findpass(file.disk, &domain);
- if (smbpass) {
- restore_args[j++] = stralloc(file.disk);
- passwd_field=j;
- restore_args[j++] = stralloc("-U");
- restore_args[j++] = smbpass;
- if (domain) {
- restore_args[j++] = stralloc("-W");
- restore_args[j++] = stralloc(domain);
- } else
- extra_params -= 2;
- } else
- extra_params -= 6;
- restore_args[j++] = stralloc("-d0");
- restore_args[j++] = stralloc("-Tx");
- restore_args[j++] = stralloc("-"); /* data on stdin */
- break;
+ g_ptr_array_add(argv_ptr, stralloc("smbclient"));
+ smbpass = findpass(file.disk, &domain);
+ if (smbpass) {
+ g_ptr_array_add(argv_ptr, stralloc(file.disk));
+ g_ptr_array_add(argv_ptr, stralloc("-U"));
+ passwd_field = argv_ptr->len;
+ g_ptr_array_add(argv_ptr, stralloc(smbpass));
+ if (domain) {
+ g_ptr_array_add(argv_ptr, stralloc("-W"));
+ g_ptr_array_add(argv_ptr, stralloc(domain));
+ }
+ }
+ g_ptr_array_add(argv_ptr, stralloc("-d0"));
+ g_ptr_array_add(argv_ptr, stralloc("-Tx"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
+ break;
#endif
case IS_TAR:
case IS_GNUTAR:
- restore_args[j++] = stralloc("tar");
- restore_args[j++] = stralloc("--numeric-owner");
- restore_args[j++] = stralloc("-xpGvf");
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("tar"));
+ g_ptr_array_add(argv_ptr, stralloc("--numeric-owner"));
+ g_ptr_array_add(argv_ptr, stralloc("-xpGvf"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
break;
case IS_SAMBA_TAR:
- restore_args[j++] = stralloc("tar");
- restore_args[j++] = stralloc("-xpvf");
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("tar"));
+ g_ptr_array_add(argv_ptr, stralloc("-xpvf"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
break;
case IS_UNKNOWN:
case IS_DUMP:
- restore_args[j++] = stralloc("restore");
+ g_ptr_array_add(argv_ptr, stralloc("restore"));
#ifdef AIX_BACKUP
- restore_args[j++] = stralloc("-xB");
+ g_ptr_array_add(argv_ptr, stralloc("-xB"));
#else
#if defined(XFSDUMP)
if (strcmp(file.program, XFSDUMP) == 0) {
- restore_args[j++] = stralloc("-v");
- restore_args[j++] = stralloc("silent");
+ g_ptr_array_add(argv_ptr, stralloc("-v"));
+ g_ptr_array_add(argv_ptr, stralloc("silent"));
} else
#endif
#if defined(VDUMP)
if (strcmp(file.program, VDUMP) == 0) {
- restore_args[j++] = stralloc("xf");
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("xf"));
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
} else
#endif
{
- restore_args[j++] = stralloc("xbf");
- restore_args[j++] = stralloc("2"); /* read in units of 1K */
- restore_args[j++] = stralloc("-"); /* data on stdin */
+ g_ptr_array_add(argv_ptr, stralloc("xbf"));
+ g_ptr_array_add(argv_ptr, stralloc("2")); /* read in units of 1K */
+ g_ptr_array_add(argv_ptr, stralloc("-")); /* data on stdin */
}
#endif
}
-
+
for (i = 0, fn = elist->files; i < files_off_tape; i++, fn = fn->next)
{
switch (dumptype) {
- case IS_TAR:
- case IS_GNUTAR:
- case IS_SAMBA_TAR:
- case IS_SAMBA:
+ case IS_TAR:
+ case IS_GNUTAR:
+ case IS_SAMBA_TAR:
+ case IS_SAMBA:
if (strcmp(fn->path, "/") == 0)
- restore_args[j++] = stralloc(".");
+ g_ptr_array_add(argv_ptr, stralloc("."));
else
- restore_args[j++] = stralloc2(".", fn->path);
+ g_ptr_array_add(argv_ptr, stralloc2(".", fn->path));
break;
case IS_UNKNOWN:
case IS_DUMP:
* xfsrestore needs a -s option before each file to be
* restored, and also wants them to be relative paths.
*/
- restore_args[j++] = stralloc("-s");
- restore_args[j++] = stralloc(fn->path + 1);
+ g_ptr_array_add(argv_ptr, stralloc("-s"));
+ g_ptr_array_add(argv_ptr, stralloc(fn->path + 1));
} else
#endif
{
- restore_args[j++] = stralloc(fn->path);
+ g_ptr_array_add(argv_ptr, stralloc(fn->path));
}
- }
+ }
}
#if defined(XFSDUMP)
if (strcmp(file.program, XFSDUMP) == 0) {
- restore_args[j++] = stralloc("-");
- restore_args[j++] = stralloc(".");
+ g_ptr_array_add(argv_ptr, stralloc("-"));
+ g_ptr_array_add(argv_ptr, stralloc("."));
}
#endif
- restore_args[j] = NULL;
+ g_ptr_array_add(argv_ptr, NULL);
switch (dumptype) {
case IS_SAMBA:
#ifdef SAMBA_CLIENT
- cmd = stralloc(SAMBA_CLIENT);
- break;
+ cmd = stralloc(SAMBA_CLIENT);
+ break;
#else
/* fall through to ... */
#endif
#else
cmd = stralloc(GNUTAR);
#endif
- break;
+ break;
case IS_UNKNOWN:
case IS_DUMP:
cmd = NULL;
#if defined(DUMP)
if (strcmp(file.program, DUMP) == 0) {
- cmd = stralloc(RESTORE);
+ cmd = stralloc(RESTORE);
}
#endif
#if defined(VDUMP)
if (strcmp(file.program, VDUMP) == 0) {
- cmd = stralloc(VRESTORE);
+ cmd = stralloc(VRESTORE);
}
#endif
#if defined(VXDUMP)
if (strcmp(file.program, VXDUMP) == 0) {
- cmd = stralloc(VXRESTORE);
+ cmd = stralloc(VXRESTORE);
}
#endif
#if defined(XFSDUMP)
if (strcmp(file.program, XFSDUMP) == 0) {
- cmd = stralloc(XFSRESTORE);
+ cmd = stralloc(XFSRESTORE);
}
#endif
if (cmd == NULL) {
}
if (cmd) {
dbprintf(_("Exec'ing %s with arguments:\n"), cmd);
- for (i = 0; i < j; i++) {
- if( i == passwd_field)
+ for (j = 0; j < argv_ptr->len - 1; j++) {
+ if( j == passwd_field)
dbprintf("\tXXXXX\n");
else
- dbprintf("\t%s\n", restore_args[i]);
+ dbprintf("\t%s\n", (char *)g_ptr_array_index(argv_ptr, j));
}
safe_fd(-1, 0);
- (void)execv(cmd, restore_args);
+ (void)execv(cmd, (char **)argv_ptr->pdata);
/* only get here if exec failed */
save_errno = errno;
- for (i = 0; i < j; i++) {
- amfree(restore_args[i]);
- }
- amfree(restore_args);
+ g_ptr_array_free_full(argv_ptr);
errno = save_errno;
perror(_("amrecover couldn't exec"));
g_fprintf(stderr, _(" problem executing %s\n"), cmd);
timeout.tv_sec = READ_TIMEOUT;
timeout.tv_usec = 0;
FD_COPY(&readset, &selectset);
-
+
nfound = select(max_fd, &selectset, NULL, NULL,
&timeout);
if(nfound < 0) {
g_fprintf(stderr,_("select error: %s\n"), strerror(errno));
break;
}
-
+
if (nfound == 0) { /* timeout */
g_fprintf(stderr, _("timeout waiting %d seconds for restore\n"),
READ_TIMEOUT);
g_fprintf(stderr, _("increase READ_TIMEOUT in recover-src/extract_list.c if your tape is slow\n"));
break;
}
-
+
if(FD_ISSET(ctl_fd, &selectset)) {
bytes_read = read(ctl_fd, buffer, sizeof(buffer)-1);
switch(bytes_read) {
FD_CLR(ctl_fd, &readset);
}
break;
-
+
case 0:
FD_CLR(ctl_fd, &readset);
break;
-
+
default: {
char desired_tape[MAX_TAPE_LABEL_BUF];
-
+
buffer[bytes_read] = '\0';
/* if prompted for a tape, relay said prompt to the user */
if(sscanf(buffer, "FEEDME %132s\n", desired_tape) == 1) {
g_printf(_("Please insert tape %s. Continue? [Y|n]: "),
desired_tape);
fflush(stdout);
-
+
input = agets(stdin); /* strips \n */
- if (strcasecmp("", input) == 0||
- strcasecmp("y", input) == 0||
+ if (strcasecmp("", input) == 0||
+ strcasecmp("y", input) == 0||
strcasecmp("yes", input) == 0) {
send_to_tape_server(tape_control_sock, "OK");
done = 1;
- } else if (strcasecmp("n", input) == 0||
+ } else if (strcasecmp("n", input) == 0||
strcasecmp("no", input) == 0) {
send_to_tape_server(tape_control_sock, "ERROR");
/* Abort!
} else {
g_fprintf(stderr, _("Strange message from tape server: %s"), buffer);
break;
- }
+ }
}
}
}
FD_CLR(data_fd, &readset);
}
break;
-
+
case 0:
FD_CLR(data_fd, &readset);
break;
-
+
default:
/*
* spit what we got from the server to the child
}
else
g_printf(" ");
- tlist = unmarshal_tapelist_str(elist->tape);
+ tlist = unmarshal_tapelist_str(elist->tape);
for( ; tlist != NULL; tlist = tlist->next)
g_printf(" %s", tlist->label);
g_printf("\n");
}
else
g_printf(" ");
- tlist = unmarshal_tapelist_str(elist->tape);
+ tlist = unmarshal_tapelist_str(elist->tape);
for( ; tlist != NULL; tlist = tlist->next)
g_printf(" %s", tlist->label);
g_printf("\n");
if(elist->tape[0]=='/') {
dump_device_name = newstralloc(dump_device_name, elist->tape);
g_printf(_("Extracting from file "));
- tlist = unmarshal_tapelist_str(dump_device_name);
+ tlist = unmarshal_tapelist_str(dump_device_name);
for( ; tlist != NULL; tlist = tlist->next)
g_printf(" %s", tlist->label);
g_printf("\n");
else {
g_printf(_("Extracting files using tape drive %s on host %s.\n"),
tape_device_name, tape_server_name);
- tlist = unmarshal_tapelist_str(elist->tape);
+ tlist = unmarshal_tapelist_str(elist->tape);
g_printf(_("Load tape %s now\n"), tlist->label);
amfree(tlist);
otc = okay_to_continue(1,1,0);