Esempio n. 1
0
static int restore_link(struct asfd *asfd, struct sbuf *sb,
	const char *fname, enum action act, struct cntr *cntr,
	enum protocol protocol, const char *restore_prefix)
{
	int ret=0;

	if(act==ACTION_RESTORE)
	{
		char *rpath=NULL;
		if(build_path(fname, "", &rpath, NULL))
		{
			ret=warn_and_interrupt(asfd, sb, cntr, protocol,
				"build path failed: %s", fname);
			goto end;
		}
		else if(make_link(asfd,
			fname, sb->link.buf, sb->link.cmd,
			cntr, restore_prefix))
		{
			ret=warn_and_interrupt(asfd, sb, cntr, protocol,
				"could not create link", "");
			goto end;
		}
		else if(!ret)
		{
			attribs_set(asfd, fname,
				&(sb->statp), sb->winattr, cntr);
			cntr_add(cntr, sb->path.cmd, 1);
		}
		free_w(&rpath);
	}
	else cntr_add(cntr, sb->path.cmd, 1);
end:
	return ret;
}
Esempio n. 2
0
int restore_dir(struct asfd *asfd, struct sbuf *sb,
	const char *dname, enum action act, struct cntr *cntr,
	enum protocol protocol)
{
	int ret=0;
	char *rpath=NULL;
	if(act==ACTION_RESTORE)
	{
		if(build_path(dname, "", &rpath, NULL))
		{
			ret=warn_and_interrupt(asfd, sb, cntr, protocol,
				"build path failed: %s", dname);
			goto end;
		}
		else if(is_dir_lstat(rpath)<=0)
		{
			if(mkdir(rpath, 0777))
			{
				ret=warn_and_interrupt(asfd, sb, cntr, protocol,
					"mkdir error: %s", strerror(errno));
				goto end;
			}
		}
		attribs_set(asfd, rpath, &(sb->statp), sb->winattr, cntr);
		if(!ret) cntr_add(cntr, sb->path.cmd, 1);
	}
	else cntr_add(cntr, sb->path.cmd, 1);
end:
	free_w(&rpath);
	return ret;
}
Esempio n. 3
0
static int restore_link(struct asfd *asfd, struct sbuf *sb,
	const char *fname, enum action act, struct conf **confs)
{
	int ret=0;

	if(act==ACTION_RESTORE)
	{
		char *rpath=NULL;
		if(build_path(fname, "", &rpath, NULL))
		{
			ret=warn_and_interrupt(asfd, sb, confs,
				"build path failed: %s", fname);
			goto end;
		}
		else if(make_link(asfd,
			fname, sb->link.buf, sb->link.cmd, confs))
		{
			ret=warn_and_interrupt(asfd, sb, confs,
				"could not create link", "");
			goto end;
		}
		else if(!ret)
		{
			attribs_set(asfd, fname,
				&(sb->statp), sb->winattr, confs);
			cntr_add(get_cntr(confs[OPT_CNTR]), sb->path.cmd, 1);
		}
		if(rpath) free(rpath);
	}
	else cntr_add(get_cntr(confs[OPT_CNTR]), sb->path.cmd, 1);
end:
	return ret;
}
Esempio n. 4
0
int restore_dir(struct asfd *asfd,
	struct sbuf *sb, const char *dname, enum action act, struct conf **confs)
{
	int ret=0;
	char *rpath=NULL;
	if(act==ACTION_RESTORE)
	{
		if(build_path(dname, "", &rpath, NULL))
		{
			ret=warn_and_interrupt(asfd, sb, confs,
				"build path failed: %s", dname);
			goto end;
		}
		else if(!is_dir_lstat(rpath))
		{
			if(mkdir(rpath, 0777))
			{
				ret=warn_and_interrupt(asfd, sb, confs,
					"mkdir error: %s", strerror(errno));
				goto end;
			}
		}
		attribs_set(asfd, rpath, &(sb->statp), sb->winattr, confs);
		if(!ret) cntr_add(get_cntr(confs[OPT_CNTR]), sb->path.cmd, 1);
	}
	else cntr_add(get_cntr(confs[OPT_CNTR]), sb->path.cmd, 1);
end:
	if(rpath) free(rpath);
	return ret;
}
Esempio n. 5
0
static int restore_metadata(struct asfd *asfd, BFILE *bfd, struct sbuf *sb,
	const char *fname, enum action act,
	int vss_restore, struct cntr *cntr, const char *encryption_password)
{
	int ret=-1;
	size_t metalen=0;
	char *metadata=NULL;
	
	// If it is directory metadata, try to make sure the directory
	// exists. Pass in NULL as the cntr, so no counting is done.
	// The actual directory entry will be coming after the metadata,
	// annoyingly. This is because of the way that the server is queuing
	// up directories to send after file data, so that the stat info on
	// them gets set correctly.
	if(act==ACTION_VERIFY)
	{
		cntr_add(cntr, sb->path.cmd, 1);
		ret=0;
		goto end;
	}

	if(S_ISDIR(sb->statp.st_mode)
	  && restore_dir(asfd, sb, fname, act, cntr, PROTO_1))
		goto end;

	// Read in the metadata...
	if(restore_file_or_get_meta(asfd, bfd, sb, fname, act,
		&metadata, &metalen, vss_restore, cntr, encryption_password))
			goto end;
	if(metadata)
	{
		
		if(!set_extrameta(asfd, bfd, fname,
			sb, metadata, metalen, cntr))
		{
#ifndef HAVE_WIN32
			// Set attributes again, since we just diddled with the
			// file.
			attribs_set(asfd, fname,
				&(sb->statp), sb->winattr, cntr);
			cntr_add(cntr, sb->path.cmd, 1);
#endif
		}
		// Carry on if we could not set_extrameta.
	}
	ret=0;
end:
	free_w(&metadata);
	return ret;
}
Esempio n. 6
0
static int restore_metadata(struct asfd *asfd, BFILE *bfd, struct sbuf *sb,
                            const char *fname, enum action act, const char *encpassword,
                            int vss_restore, struct conf *conf)
{
    // If it is directory metadata, try to make sure the directory
    // exists. Pass in NULL as the cntr, so no counting is done.
    // The actual directory entry will be coming after the metadata,
    // annoyingly. This is because of the way that the server is queuing
    // up directories to send after file data, so that the stat info on
    // them gets set correctly.
    if(act==ACTION_RESTORE)
    {
        size_t metalen=0;
        char *metadata=NULL;
        if(S_ISDIR(sb->statp.st_mode)
                && restore_dir(asfd, sb, fname, act, NULL))
            return -1;

        // Read in the metadata...
        if(restore_file_or_get_meta(asfd, bfd, sb,
                                    fname, act, encpassword,
                                    &metadata, &metalen, vss_restore, conf))
            return -1;
        if(metadata)
        {

            if(set_extrameta(asfd,
#ifdef HAVE_WIN32
                             bfd,
#endif
                             fname, sb->path.cmd,
                             &(sb->statp), metadata, metalen, conf))
            {
                free(metadata);
                // carry on if we could not do it
                return 0;
            }
            free(metadata);
#ifndef HAVE_WIN32
            // set attributes again, since we just diddled with
            // the file
            attribs_set(asfd, fname, &(sb->statp), sb->winattr, conf);
#endif
            cntr_add(conf->cntr, sb->path.cmd, 1);
        }
    }
    else cntr_add(conf->cntr, sb->path.cmd, 1);
    return 0;
}
Esempio n. 7
0
static int restore_link(struct asfd *asfd, struct sbuf *sb, const char *fname,
                        const char *restoreprefix, enum action act, struct conf *conf)
{
    int ret=0;

    if(act==ACTION_RESTORE)
    {
        char *rpath=NULL;
        if(build_path(fname, "", &rpath, NULL))
        {
            char msg[256]="";
            // failed - do a warning
            snprintf(msg, sizeof(msg), "build path failed: %s",
                     fname);
            if(restore_interrupt(asfd, sb, msg, conf))
                ret=-1;
            goto end;
        }
        else if(make_link(asfd, fname, sb->link.buf, sb->link.cmd,
                          restoreprefix, conf))
        {
            // failed - do a warning
            if(restore_interrupt(asfd, sb,
                                 "could not create link", conf))
                ret=-1;
            goto end;
        }
        else if(!ret)
        {
            attribs_set(asfd, fname, &(sb->statp), sb->winattr, conf);
            cntr_add(conf->cntr, sb->path.cmd, 1);
        }
        if(rpath) free(rpath);
    }
    else cntr_add(conf->cntr, sb->path.cmd, 1);
end:
    return ret;
}
Esempio n. 8
0
static int restore_dir(struct asfd *asfd, struct sbuf *sb,
                       const char *dname, enum action act, struct conf *conf)
{
    int ret=0;
    char *rpath=NULL;
    if(act==ACTION_RESTORE)
    {
        if(build_path(dname, "", &rpath, NULL))
        {
            char msg[256]="";
            // failed - do a warning
            snprintf(msg, sizeof(msg),
                     "build path failed: %s", dname);
            if(restore_interrupt(asfd, sb, msg, conf))
                ret=-1;
            goto end;
        }
        else if(!is_dir_lstat(rpath))
        {
            if(mkdir(rpath, 0777))
            {
                char msg[256]="";
                snprintf(msg, sizeof(msg), "mkdir error: %s",
                         strerror(errno));
                // failed - do a warning
                if(restore_interrupt(asfd, sb, msg, conf))
                    ret=-1;
                goto end;
            }
        }
        attribs_set(asfd, rpath, &(sb->statp), sb->winattr, conf);
        if(!ret) cntr_add(conf->cntr, sb->path.cmd, 1);
    }
    else cntr_add(conf->cntr, sb->path.cmd, 1);
end:
    if(rpath) free(rpath);
    return ret;
}
Esempio n. 9
0
static int do_restore_file_or_get_meta(struct asfd *asfd, BFILE *bfd,
	struct sbuf *sb, const char *fname,
	char **metadata, size_t *metalen,
	struct cntr *cntr, const char *rpath,
	const char *encryption_password)
{
	int ret=-1;
	int enccompressed=0;
	uint64_t rcvdbytes=0;
	uint64_t sentbytes=0;
	const char *encpassword=NULL;

	if(sbuf_is_encrypted(sb))
		encpassword=encryption_password;
	enccompressed=dpth_protocol1_is_compressed(sb->compression,
		sb->protocol1->datapth.buf);
/*
	printf("%s \n", fname);
	if(encpassword && !enccompressed)
		printf("encrypted and not compressed\n");
	else if(!encpassword && enccompressed)
		printf("not encrypted and compressed\n");
	else if(!encpassword && !enccompressed)
		printf("not encrypted and not compressed\n");
	else if(encpassword && enccompressed)
		printf("encrypted and compressed\n");
*/

	if(metadata)
	{
		ret=transfer_gzfile_inl(asfd, sb, fname, NULL,
			&rcvdbytes, &sentbytes, encpassword, enccompressed,
			cntr, metadata);
		*metalen=sentbytes;
		// skip setting cntr, as we do not actually
		// restore until a bit later
		goto end;
	}
	else
	{
		ret=transfer_gzfile_inl(asfd, sb, fname, bfd,
			&rcvdbytes, &sentbytes,
			encpassword, enccompressed, cntr, NULL);
#ifndef HAVE_WIN32
		if(bfd && bfd->close(bfd, asfd))
		{
			logp("error closing %s in %s\n",
				fname, __func__);
			goto end;
		}
#endif
		if(!ret) attribs_set(asfd, rpath,
			&sb->statp, sb->winattr, cntr);
	}

	ret=0;
end:
	if(ret)
	{
		char msg[256]="";
		snprintf(msg, sizeof(msg),
			"Could not transfer file in: %s", rpath);
		if(restore_interrupt(asfd, sb, msg, cntr, PROTO_1))
			ret=-1;
	}
	return ret;
}
Esempio n. 10
0
static int restore_special(struct asfd *asfd, struct sbuf *sb,
                           const char *fname, enum action act, struct conf *conf)
{
    int ret=0;
    char *rpath=NULL;
#ifdef HAVE_WIN32
    logw(asfd, conf, "Cannot restore special files to Windows: %s\n", fname);
    goto end;
#else
    struct stat statp=sb->statp;

    if(act==ACTION_VERIFY)
    {
        cntr_add(conf->cntr, CMD_SPECIAL, 1);
        return 0;
    }

    if(build_path(fname, "", &rpath, NULL))
    {
        char msg[256]="";
        // failed - do a warning
        snprintf(msg, sizeof(msg), "build path failed: %s", fname);
        if(restore_interrupt(asfd, sb, msg, conf))
            ret=-1;
        goto end;
    }
    if(S_ISFIFO(statp.st_mode))
    {
        if(mkfifo(rpath, statp.st_mode) && errno!=EEXIST)
        {
            char msg[256]="";
            snprintf(msg, sizeof(msg),
                     "Cannot make fifo: %s\n", strerror(errno));
            logw(asfd, conf, "%s", msg);
        }
        else
        {
            attribs_set(asfd, rpath, &statp, sb->winattr, conf);
            cntr_add(conf->cntr, CMD_SPECIAL, 1);
        }
        /*
        	}
        	else if(S_ISSOCK(statp.st_mode)) {
        		char msg[256]="";
        		snprintf(msg, sizeof(msg),
        			"Skipping restore of socket: %s\n", fname);
        		logw(conf, "%s", msg);
        */
#ifdef S_IFDOOR     // Solaris high speed RPC mechanism
    } else if (S_ISDOOR(statp.st_mode)) {
        char msg[256]="";
        snprintf(msg, sizeof(msg),
                 "Skipping restore of door file: %s\n", fname);
        logw(conf, "%s", msg);
#endif
#ifdef S_IFPORT     // Solaris event port for handling AIO
    } else if (S_ISPORT(statp.st_mode)) {
        char msg[256]="";
        snprintf(msg, sizeof(msg),
                 "Skipping restore of event port file: %s\n", fname);
        logw(conf, "%s", msg);
#endif
    } else {
        if(mknod(fname, statp.st_mode, statp.st_rdev) && errno!=EEXIST)
        {
            char msg[256]="";
            snprintf(msg, sizeof(msg),
                     "Cannot make node: %s\n", strerror(errno));
            logw(asfd, conf, "%s", msg);
        }
        else
        {
            attribs_set(asfd, rpath, &statp, sb->winattr, conf);
            cntr_add(conf->cntr, CMD_SPECIAL, 1);
        }
    }
#endif
end:
    if(rpath) free(rpath);
    return ret;
}
Esempio n. 11
0
static int restore_file_or_get_meta(struct asfd *asfd, BFILE *bfd,
                                    struct sbuf *sb, const char *fname, enum action act,
                                    const char *encpassword, char **metadata, size_t *metalen,
                                    int vss_restore, struct conf *conf)
{
    int ret=0;
    char *rpath=NULL;
    FILE *fp=NULL;

    if(act==ACTION_VERIFY)
    {
        cntr_add(conf->cntr, sb->path.cmd, 1);
        return 0;
    }

    if(build_path(fname, "", &rpath, NULL))
    {
        char msg[256]="";
        // failed - do a warning
        snprintf(msg, sizeof(msg), "build path failed: %s", fname);
        if(restore_interrupt(asfd, sb, msg, conf))
            ret=-1;
        goto end;
    }

#ifndef HAVE_WIN32
    // We always want to open the file if it is on Windows. Otherwise,
    // only open it if we are not doing metadata.
    if(!metadata)
    {
#endif
        if(open_for_restore(asfd, bfd, &fp,
                            rpath, sb, vss_restore, conf))
        {
            ret=-1;
            goto end;
        }
#ifndef HAVE_WIN32
    }
#endif

    if(!ret)
    {
        int enccompressed=0;
        unsigned long long rcvdbytes=0;
        unsigned long long sentbytes=0;

        enccompressed=dpthl_is_compressed(sb->compression, sb->burp1->datapth.buf);
        /*
        		printf("%s \n", fname);
        		if(encpassword && !enccompressed)
        			printf("encrypted and not compressed\n");
        		else if(!encpassword && enccompressed)
        			printf("not encrypted and compressed\n");
        		else if(!encpassword && !enccompressed)
        			printf("not encrypted and not compressed\n");
        		else if(encpassword && enccompressed)
        			printf("encrypted and compressed\n");
        */

        if(metadata)
        {
            ret=transfer_gzfile_inl(asfd, sb, fname, NULL, NULL,
                                    &rcvdbytes, &sentbytes,
                                    encpassword, enccompressed,
                                    conf->cntr, metadata);
            *metalen=sentbytes;
            // skip setting cntr, as we do not actually
            // restore until a bit later
            goto end;
        }
        else
        {
            int c=0;
#ifdef HAVE_WIN32
            ret=transfer_gzfile_inl(asfd, sb, fname, bfd, NULL,
                                    &rcvdbytes, &sentbytes,
                                    encpassword, enccompressed, conf->cntr, NULL);
            //c=bclose(bfd);
#else
            ret=transfer_gzfile_inl(asfd, sb, fname, NULL, fp,
                                    &rcvdbytes, &sentbytes,
                                    encpassword, enccompressed, conf->cntr, NULL);
            c=close_fp(&fp);
#endif
            if(c)
            {
                logp("error closing %s in restore_file_or_get_meta\n", fname);
                ret=-1;
            }
            if(!ret) attribs_set(asfd, rpath,
                                     &(sb->statp), sb->winattr, conf);
        }
        if(ret)
        {
            char msg[256]="";
            snprintf(msg, sizeof(msg),
                     "Could not transfer file in: %s",
                     rpath);
            if(restore_interrupt(asfd, sb, msg, conf))
                ret=-1;
            goto end;
        }
    }
    if(!ret) cntr_add(conf->cntr, sb->path.cmd, 1);
end:
    if(rpath) free(rpath);
    return ret;
}
Esempio n. 12
0
static int restore_special(struct asfd *asfd, struct sbuf *sb,
	const char *fname, enum action act, struct cntr *cntr,
	enum protocol protocol)
{
	int ret=0;
	char *rpath=NULL;
#ifdef HAVE_WIN32
	logw(asfd, cntr, "Cannot restore special files to Windows: %s\n", fname);
	goto end;
#else
	struct stat statp=sb->statp;

	if(act==ACTION_VERIFY)
	{
		cntr_add(cntr, CMD_SPECIAL, 1);
		return 0;
	}

	if(build_path(fname, "", &rpath, NULL))
	{
		// failed - do a warning
		if(restore_interrupt(asfd, sb,
			build_msg("build path failed: %s", fname),
			cntr, protocol))
				ret=-1;
		goto end;
	}
	if(S_ISFIFO(statp.st_mode))
	{
		if(mkfifo(rpath, statp.st_mode) && errno!=EEXIST)
			do_logw(asfd, cntr,
				"Cannot make fifo: %s\n", strerror(errno));
		else
		{
			attribs_set(asfd, rpath, &statp, sb->winattr, cntr);
			cntr_add(cntr, CMD_SPECIAL, 1);
		}
	}
	else if(S_ISSOCK(statp.st_mode))
	{
		if(mksock(rpath))
			do_logw(asfd, cntr,
				"Cannot make socket: %s\n", strerror(errno));
		else
		{
			attribs_set(asfd, rpath, &statp, sb->winattr, cntr);
			cntr_add(cntr, CMD_SPECIAL, 1);
		}
	}
#ifdef S_IFDOOR     // Solaris high speed RPC mechanism
	else if (S_ISDOOR(statp.st_mode))
		do_logw(asfd, cntr,
			"Skipping restore of door file: %s\n", fname);
#endif
#ifdef S_IFPORT     // Solaris event port for handling AIO
	else if (S_ISPORT(statp.st_mode))
		do_logw(asfd, cntr,
			"Skipping restore of event port file: %s\n", fname);
#endif
	else if(mknod(fname, statp.st_mode, statp.st_rdev) && errno!=EEXIST)
		do_logw(asfd, cntr, "Cannot make node: %s\n", strerror(errno));
	else
	{
		attribs_set(asfd, rpath, &statp, sb->winattr, cntr);
		cntr_add(cntr, CMD_SPECIAL, 1);
	}
#endif
end:
	free_w(&rpath);
	return ret;
}