1 /*********************************************************************/ 2 // dar - disk archive - a backup/restoration program 3 // Copyright (C) 2002-2052 Denis Corbin 4 // 5 // This program is free software; you can redistribute it and/or 6 // modify it under the terms of the GNU General Public License 7 // as published by the Free Software Foundation; either version 2 8 // of the License, or (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful, 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU General Public License for more details. 14 // 15 // You should have received a copy of the GNU General Public License 16 // along with this program; if not, write to the Free Software 17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 // 19 // to contact the author : http://dar.linux.free.fr/email.html 20 /*********************************************************************/ 21 22 /// \file header_version.hpp 23 /// \brief archive global header/trailer structure is defined here 24 /// \ingroup Private 25 26 #ifndef HEADER_VERSION_HPP 27 #define HEADER_VERSION_HPP 28 29 #include "../my_config.h" 30 #include "infinint.hpp" 31 #include "generic_file.hpp" 32 #include "tools.hpp" 33 #include "archive_version.hpp" 34 #include "on_pool.hpp" 35 #include "crypto.hpp" 36 #include "slice_layout.hpp" 37 #include "compressor.hpp" 38 39 namespace libdar 40 { 41 42 /// \addtogroup Private 43 /// @{ 44 45 /// manages the archive header and trailer 46 class header_version : public on_pool 47 { 48 public: 49 header_version(); header_version(const header_version & ref)50 header_version(const header_version & ref) { copy_from(ref); }; operator =(const header_version & ref)51 const header_version & operator = (const header_version & ref) { detruit(); copy_from(ref); return * this; }; ~header_version()52 ~header_version() { detruit(); }; 53 54 /// read the header or trailer from the archive 55 void read(generic_file &f, user_interaction & dialog, bool lax_mode); 56 57 /// write down the object to the archive (as header if wrote at the beginning of the archive, as trailer is at the end) 58 void write(generic_file &f) const; 59 60 // settings 61 set_edition(const archive_version & ed)62 void set_edition(const archive_version & ed) { edition = ed; }; set_compression_algo(const compression & zip)63 void set_compression_algo(const compression & zip) { algo_zip = zip; }; set_command_line(const std::string & line)64 void set_command_line(const std::string & line) { cmd_line = line; }; set_initial_offset(const infinint & offset)65 void set_initial_offset(const infinint & offset) { initial_offset = offset; }; set_sym_crypto_algo(const crypto_algo & algo)66 void set_sym_crypto_algo(const crypto_algo & algo) { sym = algo; }; 67 68 /// the object pointed to by key passes to the responsibility of this header_version object set_crypted_key(memory_file * key)69 void set_crypted_key(memory_file *key) { if(key == nullptr) throw SRC_BUG; clear_crypted_key(); crypted_key = key; }; clear_crypted_key()70 void clear_crypted_key() { if(crypted_key != nullptr) { delete crypted_key; crypted_key = nullptr; } }; 71 72 /// the object pointed to by layout is passed under the responsibility of this header_version object set_slice_layout(slice_layout * layout)73 void set_slice_layout(slice_layout *layout) { if(layout == nullptr) throw SRC_BUG; clear_slice_layout(); ref_layout = layout; }; clear_slice_layout()74 void clear_slice_layout() { if(ref_layout != nullptr) { delete ref_layout; ref_layout = nullptr; } }; 75 set_tape_marks(bool presence)76 void set_tape_marks(bool presence) { has_tape_marks = presence; }; set_signed(bool is_signed)77 void set_signed(bool is_signed) { arch_signed = is_signed; }; 78 79 // gettings 80 get_edition() const81 const archive_version & get_edition() const { return edition; }; get_compression_algo() const82 compression get_compression_algo() const { return algo_zip; }; get_command_line() const83 const std::string & get_command_line() const { return cmd_line; }; get_initial_offset() const84 const infinint & get_initial_offset() const { return initial_offset; }; 85 is_ciphered() const86 bool is_ciphered() const { return ciphered || sym != crypto_none; }; is_signed() const87 bool is_signed() const { return arch_signed; }; get_sym_crypto_algo() const88 crypto_algo get_sym_crypto_algo() const { return sym; }; get_crypted_key() const89 memory_file *get_crypted_key() const { return crypted_key; }; get_slice_layout() const90 const slice_layout *get_slice_layout() const { return ref_layout; }; get_tape_marks() const91 bool get_tape_marks() const { return has_tape_marks; }; 92 93 // display 94 95 void display(user_interaction & dialg) const; 96 97 private: 98 archive_version edition; //< archive format 99 compression algo_zip; //< compression algorithm used 100 std::string cmd_line; //< used long ago to store cmd_line, then abandonned, then recycled as a user comment field 101 infinint initial_offset; //< defines at which offset starts the archive (passed the archive header), this field is obiously only used in the trailer not in the header 102 // has to be set to zero when it is unknown, in that case this field is not dump to archive 103 crypto_algo sym; //< strong encryption algorithm used for symmetrical encryption 104 memory_file *crypted_key;//< optional field containing the asymmetrically ciphered key used for strong encryption ciphering 105 slice_layout *ref_layout;//< optional field used in isolated catalogues to record the slicing layout of their archive of reference 106 bool has_tape_marks; //< whether the archive contains tape marks aka escape marks aka sequence marks 107 108 bool ciphered; // whether the archive is ciphered, even if we do not know its crypto algorithm (old archives) 109 bool arch_signed; // whether the archive is signed 110 111 void copy_from(const header_version & ref); 112 void detruit(); 113 114 // FLAG VALUES 115 116 static const U_I FLAG_SAVED_EA_ROOT = 0x80; //< no more used since version "05" 117 static const U_I FLAG_SAVED_EA_USER = 0x40; //< no more used since version "05" 118 static const U_I FLAG_SCRAMBLED = 0x20; //< scrambled or strong encryption used 119 static const U_I FLAG_SEQUENCE_MARK = 0x10; //< escape sequence marks present for sequential reading 120 static const U_I FLAG_INITIAL_OFFSET = 0x08; //< whether the header contains the initial offset (size of clear data before encrypted) NOTE : This value is set internally by header_version, no need to set flag with it! But that's OK to set it or not, it will be updated according to initial_offset's value. 121 static const U_I FLAG_HAS_CRYPTED_KEY = 0x04; //< the header contains a symmetrical key encrypted with asymmetrical algorithm 122 static const U_I FLAG_HAS_REF_SLICING = 0x02; //< the header contains the slicing information of the archive of reference (used for isolated catalogue) 123 static const U_I FLAG_HAS_AN_EXTENDED_SIZE = 0x01; //< the flag is two bytes length 124 static const U_I FLAG_ARCHIVE_IS_SIGNED = 0x0200; //< archive is signed 125 static const U_I FLAG_HAS_AN_SECOND_EXTENDED_SIZE = 0x0101; //< reserved for future use 126 }; 127 128 } // end of namespace 129 130 #endif 131