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 48 41.7 %
Date: 2016-07-31 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->fingerprint, blk->md5sum,
      34           0 :                                 blk->data, blk->length))
      35             :                         {
      36             :                                 case 1:
      37           0 :                                         iobuf_set(&wbuf, CMD_DATA, (char *)"0", 1);
      38           0 :                                         if(asfd->write(asfd, &wbuf)) return -1;
      39           0 :                                         cntr_add(cntr, CMD_DATA, 0);
      40             :                                         break; // All OK.
      41             :                                 case 0:
      42             :                                 {
      43           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));
      44             :                                         break;
      45             :                 
      46             :                                 }
      47             :                                 default:
      48             :                                 {
      49             :                                         char msg[256];
      50           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));
      51             :                                         return -1;
      52             :                                 }
      53             :                         }
      54             :                         return 0;
      55             :                 default:
      56           0 :                         logp("unknown action in %s: %d\n", __func__, act);
      57             :                         return -1;
      58             :         }
      59             : }
      60             : 
      61          32 : int restore_sbuf_protocol2(struct asfd *asfd, struct sbuf *sb, enum action act,
      62             :         enum cntr_status cntr_status,
      63             :         struct cntr *cntr, struct sbuf *need_data)
      64             : {
      65          64 :         if(asfd->write(asfd, &sb->attr)
      66          32 :           || asfd->write(asfd, &sb->path))
      67             :                 return -1;
      68          64 :         if(sbuf_is_link(sb)
      69          32 :           && asfd->write(asfd, &sb->link))
      70             :                 return -1;
      71             : 
      72          32 :         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          32 :         if(sbuf_is_filedata(sb))
      90             :         {
      91          21 :                 iobuf_copy(&need_data->path, &sb->path);
      92          21 :                 sb->path.buf=NULL;
      93             :         }
      94             :         else
      95          11 :                 cntr_add(cntr, sb->path.cmd, 0);
      96             :         return 0;
      97             : }
      98             : 
      99         316 : int protocol2_extra_restore_stream_bits(struct asfd *asfd, struct blk *blk,
     100             :         struct slist *slist, enum action act,
     101             :         struct sbuf *need_data, int last_ent_was_dir, struct cntr *cntr)
     102             : {
     103         316 :         int ret=-1;
     104         316 :         if(need_data->path.buf)
     105             :         {
     106         316 :                 ret=send_data(asfd, blk, act, need_data, cntr);
     107             :         }
     108           0 :         else if(last_ent_was_dir)
     109             :         {
     110             :                 // Careful, blk is not allocating blk->data and the data there
     111             :                 // can get changed if we try to keep it for later. So, need to
     112             :                 // allocate new space and copy the bytes.
     113             :                 struct blk *nblk;
     114             :                 struct sbuf *xb;
     115           0 :                 if(!(nblk=blk_alloc_with_data(blk->length)))
     116             :                         goto end;
     117           0 :                 nblk->length=blk->length;
     118           0 :                 memcpy(nblk->data, blk->data, blk->length);
     119           0 :                 xb=slist->head;
     120           0 :                 if(!xb->protocol2->bstart)
     121           0 :                         xb->protocol2->bstart=xb->protocol2->bend=nblk;
     122             :                 else
     123             :                 {
     124           0 :                         xb->protocol2->bend->next=nblk;
     125           0 :                         xb->protocol2->bend=nblk;
     126             :                 }
     127             :                 ret=0;
     128             :         }
     129             :         else
     130             :         {
     131             :                 logw(asfd, cntr,
     132             :                         "Unexpected signature in manifest: %016" PRIX64 "%s%s\n",
     133             :                         blk->fingerprint,
     134             :                         bytes_to_md5str(blk->md5sum),
     135           0 :                         uint64_to_savepathstr_with_sig(blk->savepath));
     136             :         }
     137             : end:
     138         316 :         blk->data=NULL;
     139         316 :         return ret;
     140             : }

Generated by: LCOV version 1.10