1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2018-2019 Bareos GmbH & Co. KG
5    Copyright (C) 2009 Free Software Foundation Europe e.V.
6 
7    This program is Free Software; you can redistribute it and/or
8    modify it under the terms of version three of the GNU Affero General Public
9    License as published by the Free Software Foundation and included
10    in the file LICENSE.
11 
12    This program is distributed in the hope that it will be useful, but
13    WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15    Affero General Public License for more details.
16 
17    You should have received a copy of the GNU Affero General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20    02110-1301, USA.
21 */
22 
23 #ifndef BAREOS_FILED_RESTORE_H_
24 #define BAREOS_FILED_RESTORE_H_
25 
26 #include "findlib/bfile.h"
27 
28 class alist;
29 
30 namespace filedaemon {
31 
32 struct DelayedDataStream {
33   int32_t stream;          /* stream less new bits */
34   char* content;           /* stream data */
35   uint32_t content_length; /* stream length */
36 };
37 
38 struct RestoreCipherContext {
39   CIPHER_CONTEXT* cipher;
40   uint32_t block_size;
41   POOLMEM* buf;       /* Pointer to descryption buffer */
42   int32_t buf_len;    /* Count of bytes currently in buf */
43   int32_t packet_len; /* Total bytes in packet */
44 };
45 
46 /* clang-format off */
47 struct r_ctx {
48   JobControlRecord* jcr{nullptr};
49   int32_t stream{0};           /* stream less new bits */
50   int32_t prev_stream{0};      /* previous stream */
51   int32_t full_stream{0};      /* full stream including new bits */
52   int32_t comp_stream{0};      /* last compressed stream found. needed only to
53                                   restore encrypted compressed backup */
54   BareosWinFilePacket bfd;     /* File content */
55   uint64_t fileAddr{0};        /* file write address */
56   uint32_t size{0};            /* Size of file */
57   char flags[FOPTS_BYTES]{};   /* Options for ExtractData() */
58   BareosWinFilePacket forkbfd; /* Alternative data stream */
59   uint64_t fork_addr{0};       /* Write address for alternative stream */
60   int64_t fork_size{0};        /* Size of alternate stream */
61   char fork_flags[FOPTS_BYTES]{0};    /* Options for ExtractData() */
62   int32_t type{0};                    /* file type FT_ */
63   Attributes* attr{nullptr};          /* Pointer to attributes */
64   bool extract{false};                /* set when extracting */
65   alist* delayed_streams{nullptr};    /* streams that should be restored as last */
66   SIGNATURE* sig{nullptr};            /* Cryptographic signature (if any) for file */
67   CRYPTO_SESSION* cs{nullptr};        /* Cryptographic session data (if any) for file */
68   RestoreCipherContext cipher_ctx{0}; /* Cryptographic restore context (if any) for file */
69   RestoreCipherContext fork_cipher_ctx{0}; /* Cryptographic restore context (if any)
70                                               for alternative stream */
71 };
72 /* clang-format on */
73 
74 void DoRestore(JobControlRecord* jcr);
75 void FreeSession(r_ctx& rctx);
76 int DoFileDigest(JobControlRecord* jcr,
77                  FindFilesPacket* ff_pkt,
78                  bool top_level);
79 bool SparseData(JobControlRecord* jcr,
80                 BareosWinFilePacket* bfd,
81                 uint64_t* addr,
82                 char** data,
83                 uint32_t* length);
84 bool StoreData(JobControlRecord* jcr,
85                BareosWinFilePacket* bfd,
86                char* data,
87                const int32_t length,
88                bool win32_decomp);
89 
90 } /* namespace filedaemon */
91 #endif
92