LCOV - code coverage report
Current view: top level - src/server/protocol2 - restore.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 20 47 42.6 %
Date: 2016-05-30 Functions: 3 3 100.0 %

          Line data    Source code
       1             : #include "../../burp.h"
       2             : #include "../../action.h"
       3             : #include "../../asfd.h"
       4             : #include "../../async.h"
       5             : #include "../../cmd.h"
       6             : #include "../../cntr.h"
       7             : #include "../../hexmap.h"
       8             : #include "../../log.h"
       9             : #include "../../prepend.h"
      10             : #include "../../protocol2/blk.h"
      11             : #include "../../regexp.h"
      12             : #include "../../server/protocol1/restore.h"
      13             : #include "../../slist.h"
      14             : #include "../manio.h"
      15             : #include "../restore.h"
      16             : #include "../sdirs.h"
      17             : #include "champ_chooser/hash.h"
      18             : 
      19         316 : static int send_data(struct asfd *asfd, struct blk *blk,
      20             :         enum action act, struct sbuf *need_data, struct cntr *cntr)
      21             : {
      22             :         struct iobuf wbuf;
      23             : 
      24         316 :         switch(act)
      25             :         {
      26             :                 case ACTION_RESTORE:
      27         316 :                         iobuf_set(&wbuf, CMD_DATA, blk->data, blk->length);
      28         316 :                         if(asfd->write(asfd, &wbuf)) return -1;
      29             :                         return 0;
      30             :                 case ACTION_VERIFY:
      31             :                         // Need to check that the block has the correct
      32             :                         // checksums.
      33           0 :                         switch(blk_verify(blk))
      34             :                         {
      35             :                                 case 1:
      36           0 :                                         iobuf_set(&wbuf, CMD_DATA, (char *)"0", 1);
      37           0 :                                         if(asfd->write(asfd, &wbuf)) return -1;
      38           0 :                                         cntr_add(cntr, CMD_DATA, 0);
      39             :                                         break; // All OK.
      40             :                                 case 0:
      41             :                                 {
      42           0 :                                         logw(asfd, cntr, "Checksum mismatch in block for %c:%s:%s\n", need_data->path.cmd, need_data->path.buf, uint64_to_savepathstr_with_sig(blk->savepath));
      43             :                                         break;
      44             :                 
      45             :                                 }
      46             :                                 default:
      47             :                                 {
      48             :                                         char msg[256];
      49           0 :                                         snprintf(msg, sizeof(msg), "Error when attempting  to verify block for %c:%s:%s\n", need_data->path.cmd, need_data->path.buf, uint64_to_savepathstr_with_sig(blk->savepath));
      50             :                                         return -1;
      51             :                                 }
      52             :                         }
      53             :                         return 0;
      54             :                 default:
      55           0 :                         logp("unknown action in %s: %d\n", __func__, act);
      56             :                         return -1;
      57             :         }
      58             : }
      59             : 
      60          32 : int restore_sbuf_protocol2(struct asfd *asfd, struct sbuf *sb, enum action act,
      61             :         enum cntr_status cntr_status,
      62             :         struct cntr *cntr, struct sbuf *need_data)
      63             : {
      64          64 :         if(asfd->write(asfd, &sb->attr)
      65          32 :           || asfd->write(asfd, &sb->path))
      66             :                 return -1;
      67          64 :         if(sbuf_is_link(sb)
      68          32 :           && asfd->write(asfd, &sb->link))
      69             :                 return -1;
      70             : 
      71          32 :         if(sb->protocol2->bstart)
      72             :         {
      73             :                 // This will restore directory data on Windows.
      74           0 :                 struct blk *b=NULL;
      75           0 :                 struct blk *n=NULL;
      76           0 :                 b=sb->protocol2->bstart;
      77           0 :                 while(b)
      78             :                 {
      79           0 :                         if(send_data(asfd, b, act, need_data, cntr))
      80           0 :                                 return -1;
      81           0 :                         n=b->next;
      82           0 :                         blk_free(&b);
      83           0 :                         b=n;
      84             :                 }
      85           0 :                 sb->protocol2->bstart=sb->protocol2->bend=NULL;
      86             :         }
      87             : 
      88          32 :         if(sbuf_is_filedata(sb))
      89             :         {
      90          21 :                 iobuf_copy(&need_data->path, &sb->path);
      91          21 :                 sb->path.buf=NULL;
      92             :         }
      93             :         else
      94          11 :                 cntr_add(cntr, sb->path.cmd, 0);
      95             :         return 0;
      96             : }
      97             : 
      98         316 : int protocol2_extra_restore_stream_bits(struct asfd *asfd, struct blk *blk,
      99             :         struct slist *slist, enum action act,
     100             :         struct sbuf *need_data, int last_ent_was_dir, struct cntr *cntr)
     101             : {
     102         316 :         int ret=-1;
     103         316 :         if(need_data->path.buf)
     104             :         {
     105         316 :                 ret=send_data(asfd, blk, act, need_data, cntr);
     106             :         }
     107           0 :         else if(last_ent_was_dir)
     108             :         {
     109             :                 // Careful, blk is not allocating blk->data and the data there
     110             :                 // can get changed if we try to keep it for later. So, need to
     111             :                 // allocate new space and copy the bytes.
     112             :                 struct blk *nblk;
     113             :                 struct sbuf *xb;
     114           0 :                 if(!(nblk=blk_alloc_with_data(blk->length)))
     115             :                         goto end;
     116           0 :                 nblk->length=blk->length;
     117           0 :                 memcpy(nblk->data, blk->data, blk->length);
     118           0 :                 xb=slist->head;
     119           0 :                 if(!xb->protocol2->bstart)
     120           0 :                         xb->protocol2->bstart=xb->protocol2->bend=nblk;
     121             :                 else
     122             :                 {
     123           0 :                         xb->protocol2->bend->next=nblk;
     124           0 :                         xb->protocol2->bend=nblk;
     125             :                 }
     126             :                 ret=0;
     127             :         }
     128             :         else
     129             :         {
     130             :                 logw(asfd, cntr,
     131             :                         "Unexpected signature in manifest: %016"PRIX64 "%s%s\n",
     132             :                         blk->fingerprint,
     133             :                         bytes_to_md5str(blk->md5sum),
     134           0 :                         uint64_to_savepathstr_with_sig(blk->savepath));
     135             :         }
     136             : end:
     137         316 :         blk->data=NULL;
     138         316 :         return ret;
     139             : }

Generated by: LCOV version 1.10