Blame oldrecover-src/set_commands.c

Packit 23ab03
/*
Packit 23ab03
 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
Packit 23ab03
 * Copyright (c) 1991-1998, 2000 University of Maryland at College Park
Packit 23ab03
 * Copyright (c) 2007-2012 Zmanda, Inc.  All Rights Reserved.
Packit 23ab03
 * Copyright (c) 2013-2016 Carbonite, Inc.  All Rights Reserved.
Packit 23ab03
 * All Rights Reserved.
Packit 23ab03
 *
Packit 23ab03
 * Permission to use, copy, modify, distribute, and sell this software and its
Packit 23ab03
 * documentation for any purpose is hereby granted without fee, provided that
Packit 23ab03
 * the above copyright notice appear in all copies and that both that
Packit 23ab03
 * copyright notice and this permission notice appear in supporting
Packit 23ab03
 * documentation, and that the name of U.M. not be used in advertising or
Packit 23ab03
 * publicity pertaining to distribution of the software without specific,
Packit 23ab03
 * written prior permission.  U.M. makes no representations about the
Packit 23ab03
 * suitability of this software for any purpose.  It is provided "as is"
Packit 23ab03
 * without express or implied warranty.
Packit 23ab03
 *
Packit 23ab03
 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
Packit 23ab03
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
Packit 23ab03
 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
Packit 23ab03
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
Packit 23ab03
 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
Packit 23ab03
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
Packit 23ab03
 *
Packit 23ab03
 * Authors: the Amanda Development Team.  Its members are listed in a
Packit 23ab03
 * file named AUTHORS, in the root directory of this distribution.
Packit 23ab03
 */
Packit 23ab03
/*
Packit 23ab03
 * $Id: set_commands.c,v 1.3 2006/07/05 13:14:58 martinea Exp $
Packit 23ab03
 *
Packit 23ab03
 * implements the "set" commands in amrecover
Packit 23ab03
 */
Packit 23ab03
Packit 23ab03
#include "amanda.h"
Packit 23ab03
#include "match.h"
Packit 23ab03
#include "amutil.h"
Packit 23ab03
#include "amrecover.h"
Packit 23ab03
Packit 23ab03
#ifdef SAMBA_CLIENT
Packit 23ab03
extern unsigned short samba_extract_method;
Packit 23ab03
#endif /* SAMBA_CLIENT */
Packit 23ab03
Packit 23ab03
/* sets a date, mapping given date into standard form if needed */
Packit 23ab03
int
Packit 23ab03
set_date(
Packit 23ab03
    char *	date)
Packit 23ab03
{
Packit 23ab03
    char *cmd = NULL;
Packit 23ab03
Packit 23ab03
    clear_dir_list();
Packit 23ab03
Packit 23ab03
    cmd = g_strconcat("DATE ", date, NULL);
Packit 23ab03
    if (converse(cmd) == -1)
Packit 23ab03
	exit(1);
Packit 23ab03
Packit 23ab03
    /* if a host/disk/directory is set, then check if that directory
Packit 23ab03
       is still valid at the new date, and if not set directory to
Packit 23ab03
       mount_point */
Packit 23ab03
    if (disk_path != NULL) {
Packit 23ab03
	g_free(cmd);
Packit 23ab03
	cmd = g_strconcat("OISD ", disk_path, NULL);
Packit 23ab03
	if (exchange(cmd) == -1)
Packit 23ab03
	    exit(1);
Packit 23ab03
	if (server_happy())
Packit 23ab03
	{
Packit 23ab03
	    suck_dir_list_from_server();
Packit 23ab03
	}
Packit 23ab03
	else
Packit 23ab03
	{
Packit 23ab03
	    g_printf(_("No index records for cwd on new date\n"));
Packit 23ab03
	    g_printf(_("Setting cwd to mount point\n"));
Packit 23ab03
	    g_free(disk_path);
Packit 23ab03
	    disk_path = g_strdup("/");	/* fake it */
Packit 23ab03
	    clear_dir_list();
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
    amfree(cmd);
Packit 23ab03
    return 0;
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
set_host(
Packit 23ab03
    const char *	host)
Packit 23ab03
{
Packit 23ab03
    char *cmd = NULL;
Packit 23ab03
    struct hostent *hp;
Packit 23ab03
    char **hostp;
Packit 23ab03
    int found_host = 0;
Packit 23ab03
    char *uqhost;
Packit 23ab03
Packit 23ab03
    if (is_extract_list_nonempty())
Packit 23ab03
    {
Packit 23ab03
	g_printf(_("Must clear extract list before changing host\n"));
Packit 23ab03
	return;
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    uqhost = unquote_string(host);
Packit 23ab03
    cmd = g_strconcat("HOST ", uqhost, NULL);
Packit 23ab03
    if (converse(cmd) == -1)
Packit 23ab03
	exit(1);
Packit 23ab03
    if (server_happy())
Packit 23ab03
    {
Packit 23ab03
	found_host = 1;
Packit 23ab03
    }
Packit 23ab03
    else
Packit 23ab03
    {
Packit 23ab03
	/*
Packit 23ab03
	 * Try converting the given host to a fully qualified name
Packit 23ab03
	 * and then try each of the aliases.
Packit 23ab03
	 */
Packit 23ab03
	if ((hp = gethostbyname(uqhost)) != NULL) {
Packit 23ab03
	    host = hp->h_name;
Packit 23ab03
	    g_printf(_("Trying host %s ...\n"), host);
Packit 23ab03
	    g_free(cmd);
Packit 23ab03
	    cmd = g_strconcat("HOST ", host, NULL);
Packit 23ab03
	    if (converse(cmd) == -1)
Packit 23ab03
		exit(1);
Packit 23ab03
	    if(server_happy())
Packit 23ab03
	    {
Packit 23ab03
		found_host = 1;
Packit 23ab03
	    }
Packit 23ab03
	    else
Packit 23ab03
	    {
Packit 23ab03
	        for (hostp = hp->h_aliases; (host = *hostp) != NULL; hostp++)
Packit 23ab03
	        {
Packit 23ab03
		    g_printf(_("Trying host %s ...\n"), host);
Packit 23ab03
		    g_free(cmd);
Packit 23ab03
		    cmd = g_strconcat("HOST ", host, NULL);
Packit 23ab03
		    if (converse(cmd) == -1)
Packit 23ab03
		        exit(1);
Packit 23ab03
		    if(server_happy())
Packit 23ab03
		    {
Packit 23ab03
		        found_host = 1;
Packit 23ab03
		        break;
Packit 23ab03
		    }
Packit 23ab03
		}
Packit 23ab03
	    }
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
    if(found_host)
Packit 23ab03
    {
Packit 23ab03
	g_free(dump_hostname);
Packit 23ab03
	dump_hostname = g_strdup(host);
Packit 23ab03
	amfree(disk_name);
Packit 23ab03
	amfree(mount_point);
Packit 23ab03
	amfree(disk_path);
Packit 23ab03
	clear_dir_list();
Packit 23ab03
    }
Packit 23ab03
    amfree(cmd);
Packit 23ab03
    amfree(uqhost);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
list_host(void)
Packit 23ab03
{
Packit 23ab03
    char *cmd = NULL;
Packit 23ab03
Packit 23ab03
    cmd = g_strdup("LISTHOST");
Packit 23ab03
    if (converse(cmd) == -1)
Packit 23ab03
        exit(1);
Packit 23ab03
    amfree(cmd);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
set_disk(
Packit 23ab03
    char *	dsk,
Packit 23ab03
    char *	mtpt)
Packit 23ab03
{
Packit 23ab03
    char *cmd = NULL;
Packit 23ab03
    char *uqdsk;
Packit 23ab03
    char *uqmtpt = NULL;
Packit 23ab03
Packit 23ab03
    if (is_extract_list_nonempty())
Packit 23ab03
    {
Packit 23ab03
	g_printf(_("Must clear extract list before changing disk\n"));
Packit 23ab03
	return;
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    /* if mount point specified, check it is valid */
Packit 23ab03
    if (mtpt != NULL) {
Packit 23ab03
	uqmtpt = unquote_string(mtpt);
Packit 23ab03
	if (*mtpt != '/') {
Packit 23ab03
	    g_printf(_("Mount point \"%s\" invalid - must start with /\n"), uqmtpt);
Packit 23ab03
	    amfree(uqmtpt);
Packit 23ab03
	    return;
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    clear_dir_list();
Packit 23ab03
    uqdsk = unquote_string(dsk);
Packit 23ab03
    cmd = g_strconcat("DISK ", uqdsk, NULL);
Packit 23ab03
    if (converse(cmd) == -1)
Packit 23ab03
	exit(1);
Packit 23ab03
    amfree(cmd);
Packit 23ab03
Packit 23ab03
    if (!server_happy()) {
Packit 23ab03
	amfree(uqdsk);
Packit 23ab03
	amfree(uqmtpt);
Packit 23ab03
	return;
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    g_free(disk_name);
Packit 23ab03
    disk_name = g_strdup(uqdsk);
Packit 23ab03
    if (mtpt == NULL)
Packit 23ab03
    {
Packit 23ab03
	/* mount point not specified */
Packit 23ab03
	if (*uqdsk == '/')
Packit 23ab03
	{
Packit 23ab03
	    /* disk specified by mount point, hence use it */
Packit 23ab03
	    g_free(mount_point);
Packit 23ab03
	    mount_point = g_strdup(uqdsk);
Packit 23ab03
	}
Packit 23ab03
	else
Packit 23ab03
	{
Packit 23ab03
	    /* device name given, use '/' because nothing better */
Packit 23ab03
	    g_free(mount_point);
Packit 23ab03
	    mount_point = g_strdup("/");
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
    else
Packit 23ab03
    {
Packit 23ab03
	/* mount point specified */
Packit 23ab03
	g_free(mount_point);
Packit 23ab03
	mount_point = g_strdup(uqmtpt);
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    /* set the working directory to the mount point */
Packit 23ab03
    /* there is the possibility that there are no index records for the
Packit 23ab03
       disk for the given date, hence setting the directory to the
Packit 23ab03
       mount point will fail. Preempt this by checking first so we can write
Packit 23ab03
       a more informative message. */
Packit 23ab03
    if (exchange("OISD /") == -1)
Packit 23ab03
	exit(1);
Packit 23ab03
    if (server_happy())
Packit 23ab03
    {
Packit 23ab03
	g_free(disk_path);
Packit 23ab03
	disk_path = g_strdup("/");
Packit 23ab03
	suck_dir_list_from_server();	/* get list of directory contents */
Packit 23ab03
    }
Packit 23ab03
    else
Packit 23ab03
    {
Packit 23ab03
	g_printf(_("No index records for disk for specified date\n"));
Packit 23ab03
	g_printf(_("If date correct, notify system administrator\n"));
Packit 23ab03
	g_free(disk_path);
Packit 23ab03
	disk_path = g_strdup("/");	/* fake it */
Packit 23ab03
	clear_dir_list();
Packit 23ab03
    }
Packit 23ab03
    amfree(uqmtpt);
Packit 23ab03
    amfree(uqdsk);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
list_disk(
Packit 23ab03
    char *	amdevice)
Packit 23ab03
{
Packit 23ab03
    char *cmd = NULL;
Packit 23ab03
    char *uqamdevice;
Packit 23ab03
Packit 23ab03
    if(amdevice) {
Packit 23ab03
	uqamdevice = unquote_string(amdevice);
Packit 23ab03
	cmd = g_strconcat("LISTDISK ", uqamdevice, NULL);
Packit 23ab03
	amfree(uqamdevice);
Packit 23ab03
	if (converse(cmd) == -1)
Packit 23ab03
	    exit(1);
Packit 23ab03
	amfree(cmd);
Packit 23ab03
    }
Packit 23ab03
    else {
Packit 23ab03
	cmd = g_strdup("LISTDISK");
Packit 23ab03
	if (converse(cmd) == -1)
Packit 23ab03
	    exit(1);
Packit 23ab03
	amfree(cmd);
Packit 23ab03
    }
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
local_cd(
Packit 23ab03
    char *dir)
Packit 23ab03
{
Packit 23ab03
    char *uqdir = unquote_string(dir);
Packit 23ab03
    if (chdir(uqdir) == -1) {
Packit 23ab03
	perror(uqdir);
Packit 23ab03
    }
Packit 23ab03
    amfree(uqdir);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
cd_glob(
Packit 23ab03
    char *	glob)
Packit 23ab03
{
Packit 23ab03
    char *regex;
Packit 23ab03
    char *regex_path;
Packit 23ab03
    char *s;
Packit 23ab03
    char *uqglob;
Packit 23ab03
Packit 23ab03
    char *path_on_disk = NULL;
Packit 23ab03
Packit 23ab03
    if (disk_name == NULL) {
Packit 23ab03
	g_printf(_("Must select disk before changing directory\n"));
Packit 23ab03
	return;
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    uqglob = unquote_string(glob);
Packit 23ab03
    regex = glob_to_regex(uqglob);
Packit 23ab03
    dbprintf(_("cd_glob (%s) -> %s\n"), uqglob, regex);
Packit 23ab03
    if ((s = validate_regexp(regex)) != NULL) {
Packit 23ab03
        g_printf(_("\"%s\" is not a valid shell wildcard pattern: "), glob);
Packit 23ab03
        puts(s);
Packit 23ab03
	amfree(regex);
Packit 23ab03
	amfree(uqglob);
Packit 23ab03
        return;
Packit 23ab03
    }
Packit 23ab03
    /*
Packit 23ab03
     * glob_to_regex() anchors the beginning of the pattern with ^,
Packit 23ab03
     * but we will be tacking it onto the end of the current directory
Packit 23ab03
     * in add_file, so strip that off.  Also, it anchors the end with
Packit 23ab03
     * $, but we need to match a trailing /, add it if it is not there
Packit 23ab03
     */
Packit 23ab03
    regex_path = g_strdup(regex + 1);
Packit 23ab03
    amfree(regex);
Packit 23ab03
    if(regex_path[strlen(regex_path) - 2] != '/' ) {
Packit 23ab03
	regex_path[strlen(regex_path) - 1] = '\0';
Packit 23ab03
	strappend(regex_path, "/$");
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    /* convert path (assumed in cwd) to one on disk */
Packit 23ab03
    if (g_str_equal(disk_path, "/"))
Packit 23ab03
        path_on_disk = g_strconcat("/", regex_path, NULL);
Packit 23ab03
    else {
Packit 23ab03
        char *clean_disk_path = clean_regex(disk_path, 0);
Packit 23ab03
        path_on_disk = g_strjoin(NULL, clean_disk_path, "/", regex_path, NULL);
Packit 23ab03
        amfree(clean_disk_path);
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    cd_dir(path_on_disk, uqglob);
Packit 23ab03
Packit 23ab03
    amfree(regex_path);
Packit 23ab03
    amfree(path_on_disk);
Packit 23ab03
    amfree(uqglob);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
cd_regex(
Packit 23ab03
    char *	regex)
Packit 23ab03
{
Packit 23ab03
    char *s;
Packit 23ab03
    char *uqregex;
Packit 23ab03
Packit 23ab03
    char *path_on_disk = NULL;
Packit 23ab03
Packit 23ab03
    if (disk_name == NULL) {
Packit 23ab03
	g_printf(_("Must select disk before changing directory\n"));
Packit 23ab03
	return;
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    uqregex = unquote_string(regex);
Packit 23ab03
    if ((s = validate_regexp(uqregex)) != NULL) {
Packit 23ab03
	g_printf(_("\"%s\" is not a valid regular expression: "), uqregex);
Packit 23ab03
	amfree(uqregex);
Packit 23ab03
	puts(s);
Packit 23ab03
	return;
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    /* convert path (assumed in cwd) to one on disk */
Packit 23ab03
    if (g_str_equal(disk_path, "/"))
Packit 23ab03
        path_on_disk = g_strconcat("/", regex, NULL);
Packit 23ab03
    else {
Packit 23ab03
        char *clean_disk_path = clean_regex(disk_path, 0);
Packit 23ab03
        path_on_disk = g_strjoin(NULL, clean_disk_path, "/", regex, NULL);
Packit 23ab03
        amfree(clean_disk_path);
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    cd_dir(path_on_disk, uqregex);
Packit 23ab03
Packit 23ab03
    amfree(path_on_disk);
Packit 23ab03
    amfree(uqregex);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
cd_dir(
Packit 23ab03
    char *	path_on_disk,
Packit 23ab03
    char *	default_dir)
Packit 23ab03
{
Packit 23ab03
    char *path_on_disk_slash = NULL;
Packit 23ab03
    char *dir = NULL;
Packit 23ab03
Packit 23ab03
    int nb_found;
Packit 23ab03
    size_t i;
Packit 23ab03
Packit 23ab03
    DIR_ITEM *ditem;
Packit 23ab03
Packit 23ab03
    path_on_disk_slash = g_strconcat(path_on_disk, "/", NULL);
Packit 23ab03
Packit 23ab03
    nb_found = 0;
Packit 23ab03
Packit 23ab03
    for (ditem=get_dir_list(); ditem!=NULL && nb_found <= 1; 
Packit 23ab03
			       ditem=get_next_dir_item(ditem))
Packit 23ab03
    {
Packit 23ab03
	if (match(path_on_disk, ditem->path)
Packit 23ab03
	    || match(path_on_disk_slash, ditem->path))
Packit 23ab03
	{
Packit 23ab03
	    i = strlen(ditem->path);
Packit 23ab03
	    if((i > 0 && ditem->path[i-1] == '/')
Packit 23ab03
               || (i > 1 && ditem->path[i-2] == '/' && ditem->path[i-1] == '.'))
Packit 23ab03
            {   /* It is a directory */
Packit 23ab03
		char *dir1, *dir2;
Packit 23ab03
		nb_found++;
Packit 23ab03
		g_free(dir);
Packit 23ab03
		dir = g_strdup(ditem->path);
Packit 23ab03
		if(dir[strlen(dir)-1] == '/')
Packit 23ab03
		    dir[strlen(dir)-1] = '\0'; /* remove last / */
Packit 23ab03
		/* remove everything before the last / */
Packit 23ab03
		dir1 = strrchr(dir,'/');
Packit 23ab03
		if (dir1) {
Packit 23ab03
		    dir1++;
Packit 23ab03
		    dir2 = g_strdup(dir1);
Packit 23ab03
		    amfree(dir);
Packit 23ab03
		    dir = dir2;
Packit 23ab03
		}
Packit 23ab03
	    }
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
    amfree(path_on_disk_slash);
Packit 23ab03
Packit 23ab03
    if(nb_found==0) {
Packit 23ab03
	set_directory(default_dir);
Packit 23ab03
    }
Packit 23ab03
    else if(nb_found==1) {
Packit 23ab03
	set_directory(dir);
Packit 23ab03
    }
Packit 23ab03
    else {
Packit 23ab03
	g_printf(_("Too many directory\n"));
Packit 23ab03
    }
Packit 23ab03
    amfree(dir);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
set_directory(
Packit 23ab03
    char *	dir)
Packit 23ab03
{
Packit 23ab03
    char *cmd = NULL;
Packit 23ab03
    char *new_dir = NULL;
Packit 23ab03
    char *dp, *de;
Packit 23ab03
    char *ldir = NULL;
Packit 23ab03
Packit 23ab03
    /* do nothing if "." */
Packit 23ab03
    if(g_str_equal(dir, ".")) {
Packit 23ab03
	show_directory();		/* say where we are */
Packit 23ab03
	return;
Packit 23ab03
	/*NOTREACHED*/
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    if (disk_name == NULL) {
Packit 23ab03
	g_printf(_("Must select disk before setting directory\n"));
Packit 23ab03
	return;
Packit 23ab03
	/*NOTREACHED*/
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    ldir = g_strdup(dir);
Packit 23ab03
    clean_pathname(ldir);
Packit 23ab03
Packit 23ab03
    /* convert directory into absolute path relative to disk mount point */
Packit 23ab03
    if (ldir[0] == '/')
Packit 23ab03
    {
Packit 23ab03
	/* absolute path specified, must start with mount point */
Packit 23ab03
	if (g_str_equal(mount_point, "/"))
Packit 23ab03
	{
Packit 23ab03
	    new_dir = g_strdup(ldir);
Packit 23ab03
	}
Packit 23ab03
	else
Packit 23ab03
	{
Packit 23ab03
	    if (strncmp(mount_point, ldir, strlen(mount_point)) != 0)
Packit 23ab03
	    {
Packit 23ab03
		g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
Packit 23ab03
		       mount_point);
Packit 23ab03
		amfree(ldir);
Packit 23ab03
		return;
Packit 23ab03
		/*NOTREACHED*/
Packit 23ab03
	    }
Packit 23ab03
	    new_dir = g_strdup(ldir+strlen(mount_point));
Packit 23ab03
	    if (strlen(new_dir) == 0) {
Packit 23ab03
		g_free(new_dir);
Packit 23ab03
		new_dir = g_strdup("/");
Packit 23ab03
					/* i.e. ldir == mount_point */
Packit 23ab03
	    }
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
    else
Packit 23ab03
    {
Packit 23ab03
	new_dir = g_strdup(disk_path);
Packit 23ab03
	dp = ldir;
Packit 23ab03
	/* strip any leading ..s */
Packit 23ab03
	while (g_str_has_prefix(dp, "../"))
Packit 23ab03
	{
Packit 23ab03
	    de = strrchr(new_dir, '/');	/* always at least 1 */
Packit 23ab03
	    if (de == new_dir)
Packit 23ab03
	    {
Packit 23ab03
		/* at top of disk */
Packit 23ab03
		*(de + 1) = '\0';
Packit 23ab03
		dp = dp + 3;
Packit 23ab03
	    }
Packit 23ab03
	    else
Packit 23ab03
	    {
Packit 23ab03
		*de = '\0';
Packit 23ab03
		dp = dp + 3;
Packit 23ab03
	    }
Packit 23ab03
	}
Packit 23ab03
	if (g_str_equal(dp, "..")) {
Packit 23ab03
	    if (g_str_equal(new_dir, "/")) {
Packit 23ab03
		/* at top of disk */
Packit 23ab03
		g_printf(_("Invalid directory - Can't cd outside mount point \"%s\"\n"),
Packit 23ab03
		       mount_point);
Packit 23ab03
		/*@ignore@*/
Packit 23ab03
		amfree(new_dir);
Packit 23ab03
		/*@end@*/
Packit 23ab03
		amfree(ldir);
Packit 23ab03
		return;
Packit 23ab03
		/*NOTREACHED*/
Packit 23ab03
	    }
Packit 23ab03
	    de = strrchr(new_dir, '/');	/* always at least 1 */
Packit 23ab03
	    if (de == new_dir)
Packit 23ab03
	    {
Packit 23ab03
		/* at top of disk */
Packit 23ab03
		*(de+1) = '\0';
Packit 23ab03
	    }
Packit 23ab03
	    else
Packit 23ab03
	    {
Packit 23ab03
		*de = '\0';
Packit 23ab03
 	    }
Packit 23ab03
	} else {
Packit 23ab03
	    /*@ignore@*/
Packit 23ab03
	    if (!g_str_equal(new_dir, "/")) {
Packit 23ab03
		strappend(new_dir, "/");
Packit 23ab03
	    }
Packit 23ab03
	    strappend(new_dir, ldir);
Packit 23ab03
	    /*@end@*/
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    cmd = g_strconcat("OISD ", new_dir, NULL);
Packit 23ab03
    if (exchange(cmd) == -1) {
Packit 23ab03
	exit(1);
Packit 23ab03
	/*NOTREACHED*/
Packit 23ab03
    }
Packit 23ab03
    amfree(cmd);
Packit 23ab03
Packit 23ab03
    if (server_happy())
Packit 23ab03
    {
Packit 23ab03
	g_free(disk_path);
Packit 23ab03
	disk_path = g_strdup(new_dir);
Packit 23ab03
	suck_dir_list_from_server();	/* get list of directory contents */
Packit 23ab03
	show_directory();		/* say where we moved to */
Packit 23ab03
    }
Packit 23ab03
    else
Packit 23ab03
    {
Packit 23ab03
	g_printf(_("Invalid directory - %s\n"), dir);
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    /*@ignore@*/
Packit 23ab03
    amfree(new_dir);
Packit 23ab03
    amfree(ldir);
Packit 23ab03
    /*@end@*/
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
Packit 23ab03
/* prints the current working directory */
Packit 23ab03
void
Packit 23ab03
show_directory(void)
Packit 23ab03
{
Packit 23ab03
    if (mount_point == NULL || disk_path == NULL)
Packit 23ab03
        g_printf(_("Must select disk first\n"));
Packit 23ab03
    else if (g_str_equal(mount_point, "/"))
Packit 23ab03
	g_printf("%s\n", disk_path);
Packit 23ab03
    else if (g_str_equal(disk_path, "/"))
Packit 23ab03
	g_printf("%s\n", mount_point);
Packit 23ab03
    else
Packit 23ab03
	g_printf("%s%s\n", mount_point, disk_path);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
Packit 23ab03
/* set the tape server and device */
Packit 23ab03
void
Packit 23ab03
set_tape(
Packit 23ab03
    char *	tape)
Packit 23ab03
{
Packit 23ab03
    char *uqtape = unquote_string(tape);
Packit 23ab03
    char *tapedev = strchr(uqtape, ':');
Packit 23ab03
Packit 23ab03
    if (tapedev)
Packit 23ab03
    {
Packit 23ab03
	if (tapedev != uqtape) {
Packit 23ab03
	    if((strchr(tapedev+1, ':') == NULL) &&
Packit 23ab03
	       (g_str_has_prefix(uqtape, "null:") ||
Packit 23ab03
		g_str_has_prefix(uqtape, "rait:") ||
Packit 23ab03
		g_str_has_prefix(uqtape, "file:") ||
Packit 23ab03
		g_str_has_prefix(uqtape, "tape:"))) {
Packit 23ab03
		tapedev = uqtape;
Packit 23ab03
	    }
Packit 23ab03
	    else {
Packit 23ab03
		*tapedev = '\0';
Packit 23ab03
		g_free(tape_server_name);
Packit 23ab03
		tape_server_name = g_strdup(uqtape);
Packit 23ab03
		++tapedev;
Packit 23ab03
	    }
Packit 23ab03
	} else { /* reset server_name if start with : */
Packit 23ab03
	    amfree(tape_server_name);
Packit 23ab03
	    ++tapedev;
Packit 23ab03
	}
Packit 23ab03
    } else
Packit 23ab03
	tapedev = uqtape;
Packit 23ab03
Packit 23ab03
    if (tapedev[0])
Packit 23ab03
    {
Packit 23ab03
	if (g_str_equal(tapedev, "default"))
Packit 23ab03
	    amfree(tape_device_name);
Packit 23ab03
	else {
Packit 23ab03
	        g_free(tape_device_name);
Packit 23ab03
	        tape_device_name = g_strdup(tapedev);
Packit 23ab03
	}
Packit 23ab03
    }
Packit 23ab03
Packit 23ab03
    if (tape_device_name)
Packit 23ab03
	g_printf (_("Using tape \"%s\""), tape_device_name);
Packit 23ab03
    else
Packit 23ab03
	g_printf (_("Using default tape"));
Packit 23ab03
Packit 23ab03
    if (tape_server_name)
Packit 23ab03
	g_printf (_(" from server %s.\n"), tape_server_name);
Packit 23ab03
    else
Packit 23ab03
	g_printf (_(".\nTape server unspecified, assumed to be %s.\n"),
Packit 23ab03
		server_name);
Packit 23ab03
    amfree(uqtape);
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
set_mode(
Packit 23ab03
    int		mode)
Packit 23ab03
{
Packit 23ab03
#ifdef SAMBA_CLIENT
Packit 23ab03
  if (mode == SAMBA_SMBCLIENT) {
Packit 23ab03
    g_printf (_("SAMBA dumps will be extracted using smbclient\n"));
Packit 23ab03
    samba_extract_method = SAMBA_SMBCLIENT;
Packit 23ab03
  } else {
Packit 23ab03
    if (mode == SAMBA_TAR) {
Packit 23ab03
      g_printf (_("SAMBA dumps will be extracted as TAR dumps\n"));
Packit 23ab03
      samba_extract_method = SAMBA_TAR;
Packit 23ab03
    }
Packit 23ab03
  }
Packit 23ab03
#else
Packit 23ab03
  (void)mode;	/* Quiet unused parameter warning */
Packit 23ab03
#endif /* SAMBA_CLIENT */
Packit 23ab03
}
Packit 23ab03
Packit 23ab03
void
Packit 23ab03
show_mode(void) 
Packit 23ab03
{
Packit 23ab03
#ifdef SAMBA_CLIENT
Packit 23ab03
  g_printf (_("SAMBA dumps are extracted "));
Packit 23ab03
Packit 23ab03
  if (samba_extract_method == SAMBA_TAR) {
Packit 23ab03
    g_printf (_(" as TAR dumps\n"));
Packit 23ab03
  } else {
Packit 23ab03
    g_printf (_("using smbclient\n"));
Packit 23ab03
  }
Packit 23ab03
#endif /* SAMBA_CLIENT */
Packit 23ab03
}