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

Generated by: LCOV version 1.10