X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffiled%2Frestore.c;h=d0ec052d3de0180488d75ce4526bf76cb66ec467;hb=dc8c95ac4206814f381d10c0a425d76f45d8bdc4;hp=951da3dc9a17f72e70d9c9aec655dcdb0ab47858;hpb=7db9e99fe4b7185a4ced26bac505ec4a570b96b7;p=bacula%2Fbacula diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 951da3dc9a..d0ec052d3d 100644 --- a/bacula/src/filed/restore.c +++ b/bacula/src/filed/restore.c @@ -7,7 +7,7 @@ * */ /* - Copyright (C) 2000-2005 Kern Sibbald + Copyright (C) 2000-2006 Kern Sibbald This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -28,18 +28,27 @@ #include #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, int flags, CIPHER_CONTEXT *cipher, uint32_t cipher_block_size); #define RETRY 10 /* retry wait time */ @@ -86,7 +95,7 @@ void do_restore(JCR *jcr) 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; @@ -151,15 +160,15 @@ void do_restore(JCR *jcr) } #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); + } /* * Get a record from the Storage daemon. We are guaranteed to @@ -342,7 +351,7 @@ void do_restore(JCR *jcr) Dmsg1(30, "Stream=Encrypted Session Data, size: %d\n", sd->msglen); /* 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 */ @@ -491,7 +500,7 @@ void do_restore(JCR *jcr) case STREAM_SIGNED_DIGEST: /* Save signature. */ - if ((sig = crypto_sign_decode(sd->msg, (size_t) sd->msglen)) == NULL) { + if ((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; @@ -628,7 +637,6 @@ ok_out: } -#ifdef HAVE_LIBZ /* * Convert ZLIB error code into an ASCII message */ @@ -654,10 +662,10 @@ static const char *zlib_strerror(int stat) 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)); } @@ -727,16 +735,16 @@ int verify_signature(JCR *jcr, SIGNATURE *sig) * 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) + uint64_t *addr, int flags, CIPHER_CONTEXT *cipher, uint32_t cipher_block_size) { 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 */ + const uint8_t *cipher_input; /* Decryption input */ + uint32_t cipher_input_len; /* Decryption input length */ + uint32_t decrypted_len = 0; /* Decryption output length */ if (flags & FO_SPARSE) { ser_declare; @@ -761,8 +769,8 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen, rsize = buflen; } wsize = rsize; - cipher_input = wbuf; - cipher_input_len = wsize; + cipher_input = (uint8_t *)wbuf; + cipher_input_len = (uint32_t)wsize; if (flags & FO_GZIP) { #ifdef HAVE_LIBZ @@ -782,7 +790,7 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen, } wbuf = jcr->compress_buf; wsize = compress_len; - cipher_input = jcr->compress_buf; /* decrypt decompressed data */ + cipher_input = (uint8_t *)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)); #else @@ -805,7 +813,7 @@ int32_t extract_data(JCR *jcr, BFILE *bfd, POOLMEM *buf, int32_t buflen, /* Encrypt the input block */ - if (!crypto_cipher_update(cipher, cipher_input, cipher_input_len, jcr->crypto_buf, &decrypted_len)) { + if (!crypto_cipher_update(cipher, cipher_input, cipher_input_len, (uint8_t *)jcr->crypto_buf, &decrypted_len)) { /* Decryption failed. Shouldn't happen. */ Jmsg(jcr, M_FATAL, 0, _("Decryption error\n")); return -1; @@ -856,14 +864,14 @@ ok: * 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, int flags, CIPHER_CONTEXT *cipher, uint32_t cipher_block_size) { - size_t decrypted_len; + uint32_t decrypted_len; /* Write out the remaining block and free the cipher context */ jcr->crypto_buf = check_pool_memory_size(jcr->crypto_buf, cipher_block_size); - if (!crypto_cipher_finalize(cipher, jcr->crypto_buf, &decrypted_len)) { + if (!crypto_cipher_finalize(cipher, (uint8_t *)jcr->crypto_buf, &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); }