X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=bacula%2Fsrc%2Ffiled%2Frestore.c;h=d0ec052d3de0180488d75ce4526bf76cb66ec467;hb=dc8c95ac4206814f381d10c0a425d76f45d8bdc4;hp=4aed75c9b6f41d4e278fc7b0ff0b962ad8e899eb;hpb=bdd1db9d6798e595690c1cbcfe497af71e108492;p=bacula%2Fbacula diff --git a/bacula/src/filed/restore.c b/bacula/src/filed/restore.c index 4aed75c9b6..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; @@ -127,15 +136,39 @@ void do_restore(JCR *jcr) } jcr->buf_size = sd->msglen; -#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; +#ifdef stbernard_implemented +/ #if defined(HAVE_WIN32) + bool bResumeOfmOnExit = FALSE; + if (isOpenFileManagerRunning()) { + if ( pauseOpenFileManager() ) { + Jmsg(jcr, M_INFO, 0, _("Open File Manager paused\n") ); + bResumeOfmOnExit = TRUE; + } + else { + Jmsg(jcr, M_ERROR, 0, _("FAILED to pause Open File Manager\n") ); + } + } + { + char username[UNLEN+1]; + DWORD usize = sizeof(username); + int privs = enable_backup_privileges(NULL, 1); + if (GetUserName(username, &usize)) { + Jmsg2(jcr, M_INFO, 0, _("Running as '%s'. Privmask=%#08x\n"), username, + } else { + Jmsg(jcr, M_WARNING, 0, _("Failed to retrieve current UserName\n")); + } + } #endif -#ifdef HAVE_CRYPTO - jcr->crypto_buf = get_memory(CRYPTO_CIPHER_MAX_BLOCK_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; + } + + if (have_crypto) { + jcr->crypto_buf = get_memory(CRYPTO_CIPHER_MAX_BLOCK_SIZE); + } /* * Get a record from the Storage daemon. We are guaranteed to @@ -289,10 +322,11 @@ void do_restore(JCR *jcr) extract = true; /* FALLTHROUGH */ case CF_CREATED: /* File created, but there is no content */ - P(jcr->mutex); + jcr->lock(); pm_strcpy(jcr->last_fname, attr->ofname); - V(jcr->mutex); + jcr->last_type = attr->type; jcr->JobFiles++; + jcr->unlock(); fileAddr = 0; print_ls_output(jcr, attr); #ifdef HAVE_DARWIN_OS @@ -317,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 */ @@ -466,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; @@ -603,7 +637,6 @@ ok_out: } -#ifdef HAVE_LIBZ /* * Convert ZLIB error code into an ASCII message */ @@ -629,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)); } @@ -702,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; @@ -736,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 @@ -757,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 @@ -780,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; @@ -831,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); }