LCOV - code coverage report
Current view: top level - src/server/protocol2 - restore.c (source / functions) Hit Total Coverage
Test: burp-coverage-clean.info Lines: 0 59 0.0 %
Date: 2015-11-30 Functions: 0 3 0.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           0 : 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           0 :         switch(act)
      25             :         {
      26             :                 case ACTION_RESTORE:
      27           0 :                         iobuf_set(&wbuf, CMD_DATA, blk->data, blk->length);
      28           0 :                         if(asfd->write(asfd, &wbuf)) return -1;
      29           0 :                         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           0 :                                         break; // All OK.
      40             :                                 case 0:
      41             :                                 {
      42             :                                         char msg[256];
      43           0 :                                         snprintf(msg, sizeof(msg), "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           0 :                                         logw(asfd, cntr, msg);
      45           0 :                                         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           0 :                                         return -1;
      53             :                                 }
      54             :                         }
      55           0 :                         return 0;
      56             :                 default:
      57           0 :                         logp("unknown action in %s: %d\n", __func__, act);
      58           0 :                         return -1;
      59             :         }
      60             : }
      61             : 
      62           0 : int restore_sbuf_protocol2(struct asfd *asfd, struct sbuf *sb, enum action act,
      63             :         enum cntr_status cntr_status,
      64             :         struct cntr *cntr, struct sbuf *need_data)
      65             : {
      66           0 :         if(asfd->write(asfd, &sb->attr)
      67           0 :           || asfd->write(asfd, &sb->path))
      68           0 :                 return -1;
      69           0 :         if(sbuf_is_link(sb)
      70           0 :           && asfd->write(asfd, &sb->link))
      71           0 :                 return -1;
      72             : 
      73           0 :         if(sb->protocol2->bstart)
      74             :         {
      75             :                 // This will restore directory data on Windows.
      76           0 :                 struct blk *b=NULL;
      77           0 :                 struct blk *n=NULL;
      78           0 :                 b=sb->protocol2->bstart;
      79           0 :                 while(b)
      80             :                 {
      81           0 :                         if(send_data(asfd, b, act, need_data, cntr))
      82           0 :                                 return -1;
      83           0 :                         n=b->next;
      84           0 :                         blk_free(&b);
      85           0 :                         b=n;
      86             :                 }
      87           0 :                 sb->protocol2->bstart=sb->protocol2->bend=NULL;
      88             :         }
      89             : 
      90           0 :         if(sbuf_is_filedata(sb))
      91             :         {
      92           0 :                 iobuf_copy(&need_data->path, &sb->path);
      93           0 :                 sb->path.buf=NULL;
      94             :         }
      95             :         else
      96           0 :                 cntr_add(cntr, sb->path.cmd, 0);
      97           0 :         return 0;
      98             : }
      99             : 
     100           0 : int protocol2_extra_restore_stream_bits(struct asfd *asfd, struct blk *blk,
     101             :         struct slist *slist, enum action act,
     102             :         struct sbuf *need_data, int last_ent_was_dir, struct cntr *cntr)
     103             : {
     104           0 :         if(need_data->path.buf)
     105             :         {
     106           0 :                 if(send_data(asfd, blk, act, need_data, cntr)) return -1;
     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           0 :                         return -1;
     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             :         }
     128             :         else
     129             :         {
     130           0 :                 char msg[256]="";
     131             :                 snprintf(msg, sizeof(msg),
     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           0 :                 logw(asfd, cntr, msg);
     137             :         }
     138           0 :         blk->data=NULL;
     139           0 :         return 0;
     140             : }

Generated by: LCOV version 1.10