static int parse_cmd(struct iobuf *rbuf, struct blk *blk) { int ret=-1; printf("%c%04X", rbuf->cmd, (unsigned int)rbuf->len); switch(rbuf->cmd) { case CMD_SIG: if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf)) goto end; printf("%016" PRIX64 "%s%s\n", blk->fingerprint, bytes_to_md5str(blk->md5sum), uint64_to_savepathstr_with_sig(blk->savepath)); break; case CMD_FINGERPRINT: if(blk_set_from_iobuf_fingerprint(blk, rbuf)) goto end; printf("%016" PRIX64 "\n", blk->fingerprint); break; case CMD_SAVE_PATH: if(blk_set_from_iobuf_savepath(blk, rbuf)) goto end; printf("%s\n", uint64_to_savepathstr(blk->savepath)); break; case CMD_DATA: logp("\n%s looks like a data file\n", path); goto end; /* FIX THIS - give a flag to tell it to decode attributes. case CMD_ATTRIBS: memcpy(&sb->attr, rbuf, sizeof(struct iobuf)); attribs_decode(sb); printf("compression: %d\n", sb->compression); break; */ default: printf("%s\n", rbuf->buf); break; } ret=0; end: return ret; }
static int parse_cmd(struct iobuf *rbuf, struct blk *blk) { int ret=-1; printf("%c%04lX", rbuf->cmd, rbuf->len); switch(rbuf->cmd) { case CMD_SIG: if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf)) goto end; printf("%016"PRIX64"%s%s\n", blk->fingerprint, bytes_to_md5str(blk->md5sum), uint64_to_savepathstr_with_sig(blk->savepath)); break; case CMD_FINGERPRINT: if(blk_set_from_iobuf_fingerprint(blk, rbuf)) goto end; printf("%016"PRIX64"\n", blk->fingerprint); break; case CMD_SAVE_PATH: if(blk_set_from_iobuf_savepath(blk, rbuf)) goto end; printf("%s\n", uint64_to_savepathstr(blk->savepath)); break; case CMD_DATA: logp("\n%s looks like a data file\n", path); goto end; default: printf("%s\n", rbuf->buf); break; } ret=0; end: return ret;; }
static enum parse_ret parse_cmd(struct sbuf *sb, struct asfd *asfd, struct iobuf *rbuf, struct blk *blk, struct cntr *cntr) { switch(rbuf->cmd) { case CMD_ATTRIBS: if(sb->protocol2) sbuf_free_content(sb); else { if(sb->protocol1->datapth.buf) // protocol 1 phase 2+ file data // starts with datapth. iobuf_free_content(&sb->attr); else // protocol 1 phase 1 or non file data // starts with attribs sbuf_free_content(sb); } iobuf_move(&sb->attr, rbuf); attribs_decode(sb); return PARSE_RET_NEED_MORE; case CMD_FILE: case CMD_DIRECTORY: case CMD_SOFT_LINK: case CMD_HARD_LINK: case CMD_SPECIAL: // Stuff not currently supported in burp-2, but OK // to find in burp-1. case CMD_ENC_FILE: case CMD_METADATA: case CMD_ENC_METADATA: case CMD_EFS_FILE: case CMD_VSS: case CMD_ENC_VSS: case CMD_VSS_T: case CMD_ENC_VSS_T: if(!sb->attr.buf) { log_and_send(asfd, "read cmd with no attribs"); return PARSE_RET_ERROR; } if(sb->flags & SBUF_NEED_LINK) { if(cmd_is_link(rbuf->cmd)) { iobuf_free_content(&sb->link); iobuf_move(&sb->link, rbuf); sb->flags &= ~SBUF_NEED_LINK; return PARSE_RET_COMPLETE; } else { log_and_send(asfd, "got non-link after link in manifest"); return PARSE_RET_NEED_MORE; } } else { iobuf_free_content(&sb->path); iobuf_move(&sb->path, rbuf); if(cmd_is_link(rbuf->cmd)) { sb->flags |= SBUF_NEED_LINK; return PARSE_RET_NEED_MORE; } else if(sb->protocol1 && sb->protocol1->datapth.buf) { // Protocol1 client restore reads // CMD_APPEND and CMD_END_FILE in the // calling function, so pretend it is // complete if we have the hack flag. if(sb->flags & SBUF_CLIENT_RESTORE_HACK) return PARSE_RET_COMPLETE; return PARSE_RET_NEED_MORE; } return PARSE_RET_COMPLETE; } #ifndef HAVE_WIN32 case CMD_SIG: // Fill in the sig/block, if the caller provided // a pointer for one. Server only. if(!blk) return PARSE_RET_NEED_MORE; // Just fill in the sig details. if(blk_set_from_iobuf_sig_and_savepath(blk, rbuf)) return PARSE_RET_ERROR; blk->got_save_path=1; iobuf_free_content(rbuf); return PARSE_RET_COMPLETE; #endif case CMD_DATA: // Need to write the block to disk. // Client only. if(!blk) return PARSE_RET_NEED_MORE; blk->data=rbuf->buf; blk->length=rbuf->len; rbuf->buf=NULL; return PARSE_RET_COMPLETE; case CMD_MESSAGE: case CMD_WARNING: log_recvd(rbuf, cntr, 1); return PARSE_RET_NEED_MORE; case CMD_GEN: if(!strcmp(rbuf->buf, "restoreend") || !strcmp(rbuf->buf, "phase1end") || !strcmp(rbuf->buf, "backupphase2") // Think these are protocol1 things. || !strcmp(rbuf->buf, "backupend") || !strcmp(rbuf->buf, "estimateend")) return PARSE_RET_FINISHED; iobuf_log_unexpected(rbuf, __func__); return PARSE_RET_ERROR; case CMD_FINGERPRINT: if(blk && blk_set_from_iobuf_fingerprint(blk, rbuf)) return PARSE_RET_ERROR; // Fall through. case CMD_MANIFEST: iobuf_free_content(&sb->path); iobuf_move(&sb->path, rbuf); return PARSE_RET_COMPLETE; case CMD_ERROR: logp("got error: %s\n", rbuf->buf); return PARSE_RET_ERROR; case CMD_DATAPTH: if(!sb->protocol1) { iobuf_log_unexpected(rbuf, __func__); return PARSE_RET_ERROR; } if(sb->flags & SBUF_CLIENT_RESTORE_HACK) { sbuf_free_content(sb); sb->flags |= SBUF_CLIENT_RESTORE_HACK; } else sbuf_free_content(sb); iobuf_move(&sb->protocol1->datapth, rbuf); return PARSE_RET_NEED_MORE; case CMD_END_FILE: iobuf_free_content(&sb->endfile); iobuf_move(&sb->endfile, rbuf); if(sb->protocol1) { if(!sb->attr.buf || !sb->protocol1->datapth.buf || (!sbuf_is_filedata(sb) && !sbuf_is_vssdata(sb))) { logp("got unexpected cmd_endfile"); return PARSE_RET_ERROR; } } return PARSE_RET_COMPLETE; default: iobuf_log_unexpected(rbuf, __func__); return PARSE_RET_ERROR; } logp("Fell out of switch unexpectedly in %s()\n", __func__); return PARSE_RET_ERROR; }