*
*/
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Bacula® - The Network Backup Solution
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- version 2 as amended with additional clauses defined in the
- file LICENSE in the main source directory.
+ Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- the file LICENSE for additional details.
+ The main author of Bacula is Kern Sibbald, with contributions from
+ many others, a complete list can be found in the file AUTHORS.
+ This program is Free Software; you can redistribute it and/or
+ modify it under the terms of version two of the GNU General Public
+ License as published by the Free Software Foundation plus additions
+ that are listed in the file LICENSE.
- */
+ This program is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ 02110-1301, USA.
+
+ Bacula® is a registered trademark of John Walker.
+ The licensor of Bacula is the Free Software Foundation Europe
+ (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
+ Switzerland, email:ftf@fsfeurope.org.
+*/
#include "bacula.h"
#include "filed.h"
#include <sys/attr.h>
#endif
+#if defined(HAVE_CRYPTO)
+const bool have_crypto = true;
+#else
+const bool have_crypto = false;
+#endif
+
/* Data received from Storage Daemon */
static char rec_header[] = "rechdr %ld %ld %ld %ld %ld";
/* Forward referenced functions */
-#ifdef HAVE_LIBZ
+#if defined(HAVE_LIBZ)
static const char *zlib_strerror(int stat);
+const bool have_libz = true;
+#else
+const bool have_libz = false;
#endif
int verify_signature(JCR *jcr, SIGNATURE *sig);
int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
- uint64_t *addr, int flags, CIPHER_CONTEXT *cipher, size_t cipher_block_size);
-bool flush_cipher(JCR *jcr, BFILE *bfd, int flags, CIPHER_CONTEXT *cipher, size_t cipher_block_size);
+ uint64_t *addr, int flags, CIPHER_CONTEXT *cipher, uint32_t cipher_block_size);
+bool flush_cipher(JCR *jcr, BFILE *bfd, uint64_t *addr, int flags, CIPHER_CONTEXT *cipher,
+ uint32_t cipher_block_size);
#define RETRY 10 /* retry wait time */
* Close a bfd check that we are at the expected file offset.
* Makes some code in set_attributes().
*/
-int bclose_chksize(JCR *jcr, BFILE *bfd, off_t osize)
+int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize)
{
char ec1[50], ec2[50];
- off_t fsize;
+ boffset_t fsize;
fsize = blseek(bfd, 0, SEEK_CUR);
bclose(bfd); /* first close file */
bool extract = false;
int32_t file_index;
char ec1[50]; /* Buffer printing huge values */
-
BFILE bfd; /* File content */
uint64_t fileAddr = 0; /* file write address */
uint32_t size; /* Size of file */
SIGNATURE *sig = NULL; /* Cryptographic signature (if any) for file */
CRYPTO_SESSION *cs = NULL; /* Cryptographic session data (if any) for file */
CIPHER_CONTEXT *cipher_ctx = NULL; /* Cryptographic cipher context (if any) for file */
- size_t cipher_block_size = 0; /* Cryptographic algorithm block size for file */
+ uint32_t cipher_block_size = 0; /* Cryptographic algorithm block size for file */
int flags = 0; /* Options for extract_data() */
int stat;
ATTR *attr;
}
#endif
-#ifdef HAVE_LIBZ
- uint32_t compress_buf_size = jcr->buf_size + 12 + ((jcr->buf_size+999) / 1000) + 100;
- jcr->compress_buf = (char *)bmalloc(compress_buf_size);
- jcr->compress_buf_size = compress_buf_size;
-#endif
+ if (have_libz) {
+ uint32_t compress_buf_size = jcr->buf_size + 12 + ((jcr->buf_size+999) / 1000) + 100;
+ jcr->compress_buf = (char *)bmalloc(compress_buf_size);
+ jcr->compress_buf_size = compress_buf_size;
+ }
-#ifdef HAVE_CRYPTO
- jcr->crypto_buf = get_memory(CRYPTO_CIPHER_MAX_BLOCK_SIZE);
-#endif
+ if (have_crypto) {
+ jcr->crypto_buf = get_memory(CRYPTO_CIPHER_MAX_BLOCK_SIZE);
+ jcr->crypto_buf_len = 0;
+ jcr->crypto_packet_len = 0;
+ }
/*
* Get a record from the Storage daemon. We are guaranteed to
Jmsg1(jcr, M_FATAL, 0, _("Record header scan error: %s\n"), sd->msg);
goto bail_out;
}
- Dmsg2(30, "Got hdr: FilInx=%d Stream=%d.\n", file_index, stream);
+ Dmsg4(30, "Got hdr: Files=%d FilInx=%d Stream=%d, %s.\n",
+ jcr->JobFiles, file_index, stream, stream_to_ascii(stream));
/* * Now we expect the Stream Data */
if (bget_msg(sd) < 0) {
Jmsg2(jcr, M_FATAL, 0, _("Actual data size %d not same as header %d\n"), sd->msglen, size);
goto bail_out;
}
- Dmsg1(30, "Got stream data, len=%d\n", sd->msglen);
+ Dmsg3(30, "Got stream: %s len=%d extract=%d\n", stream_to_ascii(stream),
+ sd->msglen, extract);
/* If we change streams, close and reset alternate data streams */
if (prev_stream != stream) {
switch (stream) {
case STREAM_UNIX_ATTRIBUTES:
case STREAM_UNIX_ATTRIBUTES_EX:
- Dmsg1(30, "Stream=Unix Attributes. extract=%d\n", extract);
/*
* If extracting, it was from previous stream, so
* close the output file and validate the signature.
}
/* Flush and deallocate previous stream's cipher context */
if (cipher_ctx && prev_stream != STREAM_ENCRYPTED_SESSION_DATA) {
- flush_cipher(jcr, &bfd, flags, cipher_ctx, cipher_block_size);
+ flush_cipher(jcr, &bfd, &fileAddr, flags, cipher_ctx, cipher_block_size);
crypto_cipher_free(cipher_ctx);
cipher_ctx = NULL;
}
case CF_CREATED: /* File created, but there is no content */
jcr->lock();
pm_strcpy(jcr->last_fname, attr->ofname);
+ jcr->last_type = attr->type;
jcr->JobFiles++;
jcr->unlock();
fileAddr = 0;
case STREAM_ENCRYPTED_SESSION_DATA:
crypto_error_t cryptoerr;
- Dmsg1(30, "Stream=Encrypted Session Data, size: %d\n", sd->msglen);
+ /* Do we have any keys at all? */
+ if (!jcr->pki_recipients) {
+ Jmsg(jcr, M_ERROR, 0, _("No private decryption keys have been defined to decrypt encrypted backup data.\n"));
+ extract = false;
+ bclose(&bfd);
+ break;
+ }
/* Decode and save session keys. */
- cryptoerr = crypto_session_decode(sd->msg, (size_t) sd->msglen, jcr->pki_recipients, &cs);
+ cryptoerr = crypto_session_decode((uint8_t *)sd->msg, (uint32_t)sd->msglen, jcr->pki_recipients, &cs);
switch(cryptoerr) {
case CRYPTO_ERROR_NONE:
/* Success */
break;
case CRYPTO_ERROR_NORECIPIENT:
- Jmsg(jcr, M_ERROR, 0, _("Missing private key required to decrypt encrypted backup data."));
+ Jmsg(jcr, M_ERROR, 0, _("Missing private key required to decrypt encrypted backup data.\n"));
break;
case CRYPTO_ERROR_DECRYPTION:
- Jmsg(jcr, M_ERROR, 0, _("Decrypt of the session key failed."));
+ Jmsg(jcr, M_ERROR, 0, _("Decrypt of the session key failed.\n"));
break;
default:
/* Shouldn't happen */
- Jmsg1(jcr, M_ERROR, 0, _("An error occured while decoding encrypted session data stream: %s"), crypto_strerror(cryptoerr));
+ Jmsg1(jcr, M_ERROR, 0, _("An error occured while decoding encrypted session data stream: %s\n"), crypto_strerror(cryptoerr));
break;
}
bclose(&bfd);
continue;
}
+
break;
case STREAM_FILE_DATA:
flags |= FO_WIN32DECOMP; /* "decompose" BackupWrite data */
}
- if (extract_data(jcr, &bfd, sd->msg, sd->msglen, &fileAddr, flags, cipher_ctx, cipher_block_size) < 0) {
+ if (extract_data(jcr, &bfd, sd->msg, sd->msglen, &fileAddr, flags,
+ cipher_ctx, cipher_block_size) < 0) {
extract = false;
bclose(&bfd);
continue;
Dmsg0(30, "Restoring resource fork\n");
}
flags = 0;
- if (extract_data(jcr, &altbfd, sd->msg, sd->msglen, &alt_addr, flags, cipher_ctx, cipher_block_size) < 0) {
+ if (extract_data(jcr, &altbfd, sd->msg, sd->msglen, &alt_addr, flags,
+ cipher_ctx, cipher_block_size) < 0) {
extract = false;
bclose(&altbfd);
continue;
case STREAM_SIGNED_DIGEST:
/* Save signature. */
- if ((sig = crypto_sign_decode(sd->msg, (size_t) sd->msglen)) == NULL) {
+ if (extract && (sig = crypto_sign_decode((uint8_t *)sd->msg, (uint32_t)sd->msglen)) == NULL) {
Jmsg1(jcr, M_ERROR, 0, _("Failed to decode message signature for %s\n"), jcr->last_fname);
}
break;
}
/* Flush and deallocate cipher context */
if (cipher_ctx) {
- flush_cipher(jcr, &bfd, flags, cipher_ctx, cipher_block_size);
+ flush_cipher(jcr, &bfd, &fileAddr, flags, cipher_ctx, cipher_block_size);
crypto_cipher_free(cipher_ctx);
cipher_ctx = NULL;
}
if (extract) {
/* Flush and deallocate cipher context */
if (cipher_ctx) {
- flush_cipher(jcr, &bfd, flags, cipher_ctx, cipher_block_size);
+ flush_cipher(jcr, &bfd, &fileAddr, flags, cipher_ctx, cipher_block_size);
crypto_cipher_free(cipher_ctx);
cipher_ctx = NULL;
}
}
-#ifdef HAVE_LIBZ
/*
* Convert ZLIB error code into an ASCII message
*/
return _("*none*");
}
}
-#endif
-static int do_file_digest(FF_PKT *ff_pkt, void *pkt, bool top_level) {
- JCR *jcr = (JCR *) pkt;
+static int do_file_digest(FF_PKT *ff_pkt, void *pkt, bool top_level)
+{
+ JCR *jcr = (JCR *)pkt;
return (digest_file(jcr, ff_pkt, jcr->digest));
}
return false;
}
-/*
- * In the context of jcr, write data to bfd.
- * We write buflen bytes in buf at addr. addr is updated in place.
- * The flags specify whether to use sparse files or compression.
- * Return value is the number of bytes written, or -1 on errors.
- */
-int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
- uint64_t *addr, int flags, CIPHER_CONTEXT *cipher, size_t cipher_block_size)
+bool sparse_data(JCR *jcr, BFILE *bfd, uint64_t *addr, char **data, uint32_t *length)
{
- int stat;
- char *wbuf; /* write buffer */
- uint32_t wsize; /* write size */
- uint32_t rsize; /* read size */
- char ec1[50]; /* Buffer printing huge values */
- const void *cipher_input; /* Decryption input */
- size_t cipher_input_len; /* Decryption input length */
- size_t decrypted_len = 0; /* Decryption output length */
-
- if (flags & FO_SPARSE) {
- ser_declare;
+ unser_declare;
uint64_t faddr;
char ec1[50];
- wbuf = buf + SPARSE_FADDR_SIZE;
- rsize = buflen - SPARSE_FADDR_SIZE;
- ser_begin(buf, SPARSE_FADDR_SIZE);
+ unser_begin(*data, SPARSE_FADDR_SIZE);
unser_uint64(faddr);
if (*addr != faddr) {
*addr = faddr;
- if (blseek(bfd, (off_t)*addr, SEEK_SET) < 0) {
+ if (blseek(bfd, (boffset_t)*addr, SEEK_SET) < 0) {
berrno be;
Jmsg3(jcr, M_ERROR, 0, _("Seek to %s error on %s: ERR=%s\n"),
edit_uint64(*addr, ec1), jcr->last_fname,
be.strerror(bfd->berrno));
- return -1;
+ return false;
}
}
- } else {
- wbuf = buf;
- rsize = buflen;
- }
- wsize = rsize;
- cipher_input = wbuf;
- cipher_input_len = wsize;
+ *data += SPARSE_FADDR_SIZE;
+ *length -= SPARSE_FADDR_SIZE;
+ return true;
+}
- if (flags & FO_GZIP) {
+bool decompress_data(JCR *jcr, char **data, uint32_t *length)
+{
#ifdef HAVE_LIBZ
- uLong compress_len;
- /*
- * NOTE! We only use uLong and Byte because they are
- * needed by the zlib routines, they should not otherwise
- * be used in Bacula.
- */
- compress_len = jcr->compress_buf_size;
- Dmsg2(100, "Comp_len=%d msglen=%d\n", compress_len, wsize);
- if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len,
- (const Byte *)wbuf, (uLong)rsize)) != Z_OK) {
- Qmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"),
- jcr->last_fname, zlib_strerror(stat));
- return -1;
- }
- wbuf = jcr->compress_buf;
- wsize = compress_len;
- cipher_input = jcr->compress_buf; /* decrypt decompressed data */
- cipher_input_len = compress_len;
- Dmsg2(100, "Write uncompressed %d bytes, total before write=%s\n", compress_len, edit_uint64(jcr->JobBytes, ec1));
+ uLong compress_len;
+ int stat;
+ char ec1[50]; /* Buffer printing huge values */
+
+ /*
+ * NOTE! We only use uLong and Byte because they are
+ * needed by the zlib routines, they should not otherwise
+ * be used in Bacula.
+ */
+ compress_len = jcr->compress_buf_size;
+ Dmsg2(100, "Comp_len=%d msglen=%d\n", compress_len, *length);
+ if ((stat=uncompress((Byte *)jcr->compress_buf, &compress_len,
+ (const Byte *)*data, (uLong)*length)) != Z_OK) {
+ Qmsg(jcr, M_ERROR, 0, _("Uncompression error on file %s. ERR=%s\n"),
+ jcr->last_fname, zlib_strerror(stat));
+ return false;
+ }
+ *data = jcr->compress_buf;
+ *length = compress_len;
+ Dmsg2(100, "Write uncompressed %d bytes, total before write=%s\n", compress_len, edit_uint64(jcr->JobBytes, ec1));
+ return true;
#else
- Qmsg(jcr, M_ERROR, 0, _("GZIP data stream found, but GZIP not configured!\n"));
- return -1;
+ Qmsg(jcr, M_ERROR, 0, _("GZIP data stream found, but GZIP not configured!\n"));
+ return false;
#endif
- } else {
- Dmsg2(30, "Write %u bytes, total before write=%s\n", wsize, edit_uint64(jcr->JobBytes, ec1));
+}
+
+static void unser_crypto_packet_len(JCR *jcr)
+{
+ unser_declare;
+ if (jcr->crypto_packet_len == 0 && jcr->crypto_buf_len >= CRYPTO_LEN_SIZE) {
+ unser_begin(&jcr->crypto_buf[0], CRYPTO_LEN_SIZE);
+ unser_uint32(jcr->crypto_packet_len);
+ jcr->crypto_packet_len += CRYPTO_LEN_SIZE;
+ }
+}
+
+bool store_data(JCR *jcr, BFILE *bfd, char *data, const int32_t length, bool win32_decomp)
+{
+ if (win32_decomp) {
+ if (!processWin32BackupAPIBlock(bfd, data, length)) {
+ berrno be;
+ Jmsg2(jcr, M_ERROR, 0, _("Write error in Win32 Block Decomposition on %s: %s\n"),
+ jcr->last_fname, be.strerror(bfd->berrno));
+ return false;
+ }
+ } else if (bwrite(bfd, data, length) != (ssize_t)length) {
+ berrno be;
+ Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"),
+ jcr->last_fname, be.strerror(bfd->berrno));
+ return false;
}
+ return true;
+}
+
+/*
+ * In the context of jcr, write data to bfd.
+ * We write buflen bytes in buf at addr. addr is updated in place.
+ * The flags specify whether to use sparse files or compression.
+ * Return value is the number of bytes written, or -1 on errors.
+ */
+int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen,
+ uint64_t *addr, int flags, CIPHER_CONTEXT *cipher, uint32_t cipher_block_size)
+{
+ char *wbuf; /* write buffer */
+ uint32_t wsize; /* write size */
+ uint32_t rsize; /* read size */
+ uint32_t decrypted_len = 0; /* Decryption output length */
+ char ec1[50]; /* Buffer printing huge values */
+
+ rsize = buflen;
+ jcr->ReadBytes += rsize;
+ wsize = rsize;
+ wbuf = buf;
+
if (flags & FO_ENCRYPT) {
ASSERT(cipher);
+ /* NOTE: We must implement block preserving semantics for the
+ * non-streaming compression and sparse code. */
+
/*
* Grow the crypto buffer, if necessary.
* crypto_cipher_update() will process only whole blocks,
* buffering the remaining input.
*/
- jcr->crypto_buf = check_pool_memory_size(jcr->crypto_buf, cipher_input_len + cipher_block_size);
-
-
- /* Encrypt the input block */
- if (!crypto_cipher_update(cipher, cipher_input, cipher_input_len, jcr->crypto_buf, &decrypted_len)) {
+ jcr->crypto_buf = check_pool_memory_size(jcr->crypto_buf,
+ jcr->crypto_buf_len + wsize + cipher_block_size);
+
+ /* Decrypt the input block */
+ if (!crypto_cipher_update(cipher,
+ (const u_int8_t *)wbuf,
+ wsize,
+ (u_int8_t *)&jcr->crypto_buf[jcr->crypto_buf_len],
+ &decrypted_len)) {
/* Decryption failed. Shouldn't happen. */
Jmsg(jcr, M_FATAL, 0, _("Decryption error\n"));
return -1;
}
if (decrypted_len == 0) {
- /* No full block of data available, write more data */
- goto ok;
+ /* No full block of encrypted data available, write more data */
+ return 0;
}
- Dmsg2(400, "decrypted len=%d undecrypted len=%d\n",
- decrypted_len, cipher_input_len);
- wsize = decrypted_len;
- wbuf = jcr->crypto_buf; /* Decrypted, possibly decompressed output here. */
+ Dmsg2(100, "decrypted len=%d encrypted len=%d\n", decrypted_len, wsize);
+
+ jcr->crypto_buf_len += decrypted_len;
+ wbuf = jcr->crypto_buf;
+
+ /* If one full preserved block is available, write it to disk,
+ * and then buffer any remaining data. This should be effecient
+ * as long as Bacula's block size is not significantly smaller than the
+ * encryption block size (extremely unlikely!) */
+ unser_crypto_packet_len(jcr);
+ Dmsg1(500, "Crypto unser block size=%d\n", jcr->crypto_packet_len - CRYPTO_LEN_SIZE);
+
+ if (jcr->crypto_packet_len == 0 || jcr->crypto_buf_len < jcr->crypto_packet_len) {
+ /* No full preserved block is available. */
+ return 0;
+ }
+
+ /* We have one full block, set up the filter input buffers */
+ wsize = jcr->crypto_packet_len - CRYPTO_LEN_SIZE;
+ wbuf = &wbuf[CRYPTO_LEN_SIZE]; /* Skip the block length header */
+ jcr->crypto_buf_len -= jcr->crypto_packet_len;
+ Dmsg2(30, "Encryption writing full block, %u bytes, remaining %u bytes in buffer\n", wsize, jcr->crypto_buf_len);
}
+ if (flags & FO_SPARSE) {
+ if (!sparse_data(jcr, bfd, addr, &wbuf, &wsize)) {
+ return -1;
+ }
+ }
- if (flags & FO_WIN32DECOMP) {
- if (!processWin32BackupAPIBlock(bfd, wbuf, wsize)) {
- berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Write error in Win32 Block Decomposition on %s: %s\n"),
- jcr->last_fname, be.strerror(bfd->berrno));
+ if (flags & FO_GZIP) {
+ if (!decompress_data(jcr, &wbuf, &wsize)) {
return -1;
}
- } else if (bwrite(bfd, wbuf, wsize) != (ssize_t)wsize) {
- berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"),
- jcr->last_fname, be.strerror(bfd->berrno));
- return -1;
+ } else {
+ Dmsg2(30, "Write %u bytes, total before write=%s\n", wsize, edit_uint64(jcr->JobBytes, ec1));
}
- if (decrypted_len && decrypted_len > wsize) {
- /* If more than wsize is output, it was previously buffered
- * and reported, and should not be reported again */
- wsize = wsize - decrypted_len;
+ if (!store_data(jcr, bfd, wbuf, wsize, (flags & FO_WIN32DECOMP) != 0)) {
+ return -1;
}
-ok:
jcr->JobBytes += wsize;
- jcr->ReadBytes += rsize;
*addr += wsize;
+ /* Clean up crypto buffers */
+ if (flags & FO_ENCRYPT) {
+ /* Move any remaining data to start of buffer */
+ if (jcr->crypto_buf_len > 0) {
+ Dmsg1(30, "Moving %u buffered bytes to start of buffer\n", jcr->crypto_buf_len);
+ memmove(jcr->crypto_buf, &jcr->crypto_buf[jcr->crypto_packet_len],
+ jcr->crypto_buf_len);
+ }
+ /* The packet was successfully written, reset the length so that the next
+ * packet length may be re-read by unser_crypto_packet_len() */
+ jcr->crypto_packet_len = 0;
+ }
+
return wsize;
}
* writing it to bfd.
* Return value is true on success, false on failure.
*/
-bool flush_cipher(JCR *jcr, BFILE *bfd, int flags, CIPHER_CONTEXT *cipher, size_t cipher_block_size)
+bool flush_cipher(JCR *jcr, BFILE *bfd, uint64_t *addr, int flags, CIPHER_CONTEXT *cipher,
+ uint32_t cipher_block_size)
{
- size_t decrypted_len;
+ uint32_t decrypted_len;
+ char *wbuf; /* write buffer */
+ uint32_t wsize; /* write size */
+ char ec1[50]; /* Buffer printing huge values */
/* Write out the remaining block and free the cipher context */
- jcr->crypto_buf = check_pool_memory_size(jcr->crypto_buf, cipher_block_size);
+ jcr->crypto_buf = check_pool_memory_size(jcr->crypto_buf, jcr->crypto_buf_len +
+ cipher_block_size);
- if (!crypto_cipher_finalize(cipher, jcr->crypto_buf, &decrypted_len)) {
+ if (!crypto_cipher_finalize(cipher, (uint8_t *)&jcr->crypto_buf[jcr->crypto_buf_len],
+ &decrypted_len)) {
/* Writing out the final, buffered block failed. Shouldn't happen. */
Jmsg1(jcr, M_FATAL, 0, _("Decryption error for %s\n"), jcr->last_fname);
}
- if (flags & FO_WIN32DECOMP) {
- if (!processWin32BackupAPIBlock(bfd, jcr->crypto_buf, decrypted_len)) {
- berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Write error in Win32 Block Decomposition on %s: %s\n"),
- jcr->last_fname, be.strerror(bfd->berrno));
+ /* If nothing new was decrypted, and our output buffer is empty, return */
+ if (decrypted_len == 0 && jcr->crypto_buf_len == 0) {
+ return true;
+ }
+
+ jcr->crypto_buf_len += decrypted_len;
+
+ unser_crypto_packet_len(jcr);
+ Dmsg1(500, "Crypto unser block size=%d\n", jcr->crypto_packet_len - CRYPTO_LEN_SIZE);
+ wsize = jcr->crypto_packet_len - CRYPTO_LEN_SIZE;
+ wbuf = &jcr->crypto_buf[CRYPTO_LEN_SIZE]; /* Decrypted, possibly decompressed output here. */
+
+ if (jcr->crypto_buf_len != jcr->crypto_packet_len) {
+ Jmsg2(jcr, M_FATAL, 0,
+ _("Unexpected number of bytes remaining at end of file, received %u, expected %u\n"),
+ jcr->crypto_packet_len, jcr->crypto_buf_len);
+ return false;
+ }
+
+ jcr->crypto_buf_len = 0;
+ jcr->crypto_packet_len = 0;
+
+ if (flags & FO_SPARSE) {
+ if (!sparse_data(jcr, bfd, addr, &wbuf, &wsize)) {
return false;
}
- } else if (bwrite(bfd, jcr->crypto_buf, decrypted_len) != (ssize_t)decrypted_len) {
- berrno be;
- Jmsg2(jcr, M_ERROR, 0, _("Write error on %s: %s\n"),
- jcr->last_fname, be.strerror(bfd->berrno));
+ }
+
+ if (flags & FO_GZIP) {
+ decompress_data(jcr, &wbuf, &wsize);
+ } else {
+ Dmsg2(30, "Write %u bytes, total before write=%s\n", wsize, edit_uint64(jcr->JobBytes, ec1));
+ }
+
+ if (!store_data(jcr, bfd, wbuf, wsize, (flags & FO_WIN32DECOMP) != 0)) {
return false;
}
+ jcr->JobBytes += wsize;
+
return true;
}