LCOV - code coverage report
Current view: top level - src/client/protocol2 - restore.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 14 22 63.6 %
Date: 2016-02-29 Functions: 2 2 100.0 %

          Line data    Source code
       1             : #include "../../burp.h"
       2             : #include "../../alloc.h"
       3             : #include "../../asfd.h"
       4             : #include "../../async.h"
       5             : #include "../../bfile.h"
       6             : #include "../../cmd.h"
       7             : #include "../../cntr.h"
       8             : #include "../../fsops.h"
       9             : #include "../../log.h"
      10             : #include "../../sbuf.h"
      11             : #include "../restore.h"
      12             : 
      13          14 : static int start_restore_file(struct asfd *asfd,
      14             :         BFILE *bfd,
      15             :         struct sbuf *sb,
      16             :         const char *fname,
      17             :         enum action act,
      18             :         const char *encpassword,
      19             :         char **metadata,
      20             :         size_t *metalen,
      21             :         int vss_restore,
      22             :         struct cntr *cntr)
      23             : {
      24          14 :         int ret=-1;
      25          14 :         char *rpath=NULL;
      26             : 
      27          14 :         if(act==ACTION_VERIFY)
      28             :         {
      29           0 :                 cntr_add(cntr, sb->path.cmd, 1);
      30             :                 goto end;
      31             :         }
      32             : 
      33          14 :         if(build_path(fname, "", &rpath, NULL))
      34             :         {
      35           0 :                 char msg[256]="";
      36             :                 // Failed - do a warning.
      37             :                 snprintf(msg, sizeof(msg), "build path failed: %s", fname);
      38           0 :                 if(restore_interrupt(asfd, sb, msg, cntr, PROTO_2))
      39             :                         goto error;
      40           0 :                 goto end; // Try to carry on with other files.
      41             :         }
      42             : 
      43          14 :         switch(open_for_restore(asfd, bfd, rpath, sb, vss_restore, cntr,
      44          14 :                 PROTO_2))
      45             :         {
      46             :                 case OFR_OK: break;
      47             :                 case OFR_CONTINUE: goto end;
      48             :                 default: goto error;
      49             :         }
      50             : 
      51          14 :         cntr_add(cntr, sb->path.cmd, 1);
      52             : 
      53             : end:
      54             :         ret=0;
      55             : error:
      56          14 :         free_w(&rpath);
      57          14 :         return ret;
      58             : }
      59             : 
      60             : /*
      61             : static int restore_metadata(
      62             : #ifdef HAVE_WIN32
      63             :         BFILE *bfd,
      64             : #endif
      65             :         struct sbuf *sb,
      66             :         const char *fname,
      67             :         enum action act,
      68             :         const char *encpassword,
      69             :         int vss_restore,
      70             :         struct conf **confs)
      71             : {
      72             :         // If it is directory metadata, try to make sure the directory
      73             :         // exists. Pass in NULL as the cntr, so no counting is done.
      74             :         // The actual directory entry will be coming after the metadata,
      75             :         // annoyingly. This is because of the way that the server is queuing
      76             :         // up directories to send after file data, so that the stat info on
      77             :         // them gets set correctly.
      78             :         if(act==ACTION_RESTORE)
      79             :         {
      80             :                 size_t metalen=0;
      81             :                 char *metadata=NULL;
      82             :                 if(S_ISDIR(sb->statp.st_mode)
      83             :                   && restore_dir(asfd, sb, fname, act, confs))
      84             :                         return -1;
      85             : 
      86             :                 // Read in the metadata...
      87             :                 if(restore_file_or_get_meta(bfd, sb, fname, act, encpassword,
      88             :                         &metadata, &metalen, vss_restore, confs))
      89             :                                 return -1;
      90             :                 if(metadata)
      91             :                 {
      92             :                         if(set_extrameta(bfd, fname, sb->path.cmd,
      93             :                                 &(sb->statp), metadata, metalen, confs))
      94             :                         {
      95             :                                 free_w(&metadata);
      96             :                                 // carry on if we could not do it
      97             :                                 return 0;
      98             :                         }
      99             :                         free_w(&metadata);
     100             : #ifndef HAVE_WIN32
     101             :                         // set attributes again, since we just diddled with
     102             :                         // the file
     103             :                         attribs_set(fname, &(sb->statp), sb->winattr, confs);
     104             : #endif
     105             :                         cntr_add(get_cntr(confs), sb->path.cmd, 1);
     106             :                 }
     107             :         }
     108             :         else cntr_add(get_cntr(confs), sb->cmd, 1);
     109             :         return 0;
     110             : }
     111             : */
     112             : 
     113          14 : int restore_switch_protocol2(struct asfd *asfd, struct sbuf *sb,
     114             :         const char *fullpath, enum action act,
     115             :         BFILE *bfd, int vss_restore, struct cntr *cntr)
     116             : {
     117          14 :         switch(sb->path.cmd)
     118             :         {
     119             :                 case CMD_FILE:
     120             :                         // Have it a separate statement to the
     121             :                         // encrypted version so that encrypted and not
     122             :                         // encrypted files can be restored at the
     123             :                         // same time.
     124          14 :                         if(start_restore_file(asfd,
     125             :                                 bfd, sb, fullpath, act,
     126             :                                 NULL, NULL, NULL,
     127          14 :                                 vss_restore, cntr))
     128             :                         {
     129           0 :                                 logp("restore_file error\n");
     130           0 :                                 goto error;
     131             :                         }
     132             :                         break;
     133             : /* FIX THIS: Encryption currently not working in protocol2
     134             :                 case CMD_ENC_FILE:
     135             :                         if(start_restore_file(asfd,
     136             :                                 bfd, sb, fullpath, act,
     137             :                                 get_string(confs[OPT_ENCRYPTION_PASSWORD]),
     138             :                                 NULL, NULL, vss_restore, confs))
     139             :                         {
     140             :                                 logp("restore_file error\n");
     141             :                                 goto error;
     142             :                         }
     143             :                         break;
     144             : */
     145             : /* FIX THIS: Metadata and EFS not supported yet.
     146             :                 case CMD_METADATA:
     147             :                         if(restore_metadata(
     148             :                                 bfd, sb, fullpath, act,
     149             :                                 NULL, vss_restore, confs))
     150             :                                         goto error;
     151             :                         break;
     152             :                 case CMD_ENC_METADATA:
     153             :                         if(restore_metadata(
     154             :                                 bfd, sb, fullpath, act,
     155             :                                 get_string(confs[OPT_ENCRYPTION_PASSWORD]),
     156             :                                 vss_restore, confs))
     157             :                                         goto error;
     158             :                         break;
     159             :                 case CMD_EFS_FILE:
     160             :                         if(start_restore_file(asfd,
     161             :                                 bfd, sb,
     162             :                                 fullpath, act,
     163             :                                 NULL,
     164             :                                 NULL, NULL, vss_restore, confs))
     165             :                         {
     166             :                                 logp("restore_file error\n");
     167             :                                 goto error;
     168             :                         }
     169             :                         break;
     170             : */
     171             :                 default:
     172           0 :                         logp("unknown cmd: %c\n", sb->path.cmd);
     173           0 :                         goto error;
     174             :         }
     175             :         return 0;
     176             : error:
     177             :         return -1;
     178             : }

Generated by: LCOV version 1.10