Esempio n. 1
0
static int restore_file_or_get_meta(struct asfd *asfd, BFILE *bfd,
	struct sbuf *sb, const char *fname, enum action act,
	char **metadata, size_t *metalen, int vss_restore,
	struct cntr *cntr, const char *encyption_password)
{
	int ret=0;
	char *rpath=NULL;

	if(act==ACTION_VERIFY)
	{
		cntr_add(cntr, sb->path.cmd, 1);
		goto end;
	}

	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, cntr, PROTO_1))
			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
		switch(open_for_restore(asfd,
			bfd, rpath, sb, vss_restore, cntr, PROTO_1))
		{
			case OFR_OK: break;
			case OFR_CONTINUE: goto end;
			default: ret=-1; goto end;
		}
#ifndef HAVE_WIN32
	}
#endif

	if(!(ret=do_restore_file_or_get_meta(asfd, bfd, sb, fname,
		metadata, metalen, cntr, rpath, encyption_password)))
			cntr_add(cntr, sb->path.cmd, 1);
end:
	free_w(&rpath);
	if(ret) logp("restore_file error\n");
	return ret;
}
Esempio n. 2
0
static int start_restore_file(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 cntr *cntr)
{
	int ret=-1;
	char *rpath=NULL;

	if(act==ACTION_VERIFY)
	{
		cntr_add(cntr, sb->path.cmd, 1);
		goto end;
	}

	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, cntr, PROTO_2))
			goto error;
		goto end; // Try to carry on with other files.
	}

	switch(open_for_restore(asfd, bfd, rpath, sb, vss_restore, cntr,
		PROTO_2))
	{
		case OFR_OK: break;
		case OFR_CONTINUE: goto end;
		default: goto error;
	}

	cntr_add(cntr, sb->path.cmd, 1);

end:
	ret=0;
error:
	free_w(&rpath);
	return ret;
}
Esempio n. 3
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;
}