1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef SC_TAB_PROTECTION_HXX 25 #define SC_TAB_PROTECTION_HXX 26 27 #include "sal/types.h" 28 #include <com/sun/star/uno/Sequence.hxx> 29 30 #include "global.hxx" 31 #include <vector> 32 #include <boost/shared_ptr.hpp> 33 34 #define ENABLE_SHEET_PROTECTION 1 35 36 class ScDocument; 37 class ScTableProtectionImpl; 38 39 enum ScPasswordHash 40 { 41 PASSHASH_OOO = 0, // ODF hash: SHA-1 (20 bytes) or SHA-256 of the UTF-8 password (32 bytes) 42 PASSHASH_XL, 43 PASSHASH_SHA256 // only requested from getPasswordHash(); never stored as the tag 44 }; 45 46 class ScPassHashHelper 47 { 48 public: 49 /** Check for the compatibility of all password hashes. If there is at 50 least one hash that needs to be regenerated, it returns true. If all 51 hash values are compatible with the specified hash type, then it 52 returns false. */ 53 static bool needsPassHashRegen(const ScDocument& rDoc, ScPasswordHash eHash); 54 55 private: 56 ScPassHashHelper(); 57 ~ScPassHashHelper(); 58 }; 59 60 // ============================================================================ 61 62 class SAL_NO_VTABLE ScPassHashProtectable 63 { 64 public: 65 virtual ~ScPassHashProtectable() = 0; 66 67 virtual bool isProtected() const = 0; 68 virtual bool isProtectedWithPass() const = 0; 69 virtual void setProtected(bool bProtected) = 0; 70 71 virtual bool isPasswordEmpty() const = 0; 72 virtual bool hasPasswordHash(ScPasswordHash eHash) const = 0; 73 virtual void setPassword(const String& aPassText) = 0; 74 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const = 0; 75 virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 76 ScPasswordHash eHash = PASSHASH_OOO) = 0; 77 virtual bool verifyPassword(const String& aPassText) const = 0; 78 }; 79 80 // ============================================================================ 81 82 class SC_DLLPUBLIC ScDocProtection : public ScPassHashProtectable 83 { 84 public: 85 enum Option 86 { 87 STRUCTURE = 0, 88 WINDOWS, 89 CONTENT, 90 NONE // last item - used to resize the vector 91 }; 92 93 explicit ScDocProtection(); 94 explicit ScDocProtection(const ScDocProtection& r); 95 virtual ~ScDocProtection(); 96 97 virtual bool isProtected() const; 98 virtual bool isProtectedWithPass() const; 99 virtual void setProtected(bool bProtected); 100 101 virtual bool isPasswordEmpty() const; 102 virtual bool hasPasswordHash(ScPasswordHash eHash) const; 103 virtual void setPassword(const String& aPassText); 104 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const; 105 virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 106 ScPasswordHash eHash = PASSHASH_OOO); 107 virtual bool verifyPassword(const String& aPassText) const; 108 109 bool isOptionEnabled(Option eOption) const; 110 void setOption(Option eOption, bool bEnabled); 111 112 private: 113 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl; 114 }; 115 116 // ============================================================================ 117 118 /** sheet protection state container 119 120 This class stores sheet's protection state: 1) whether the protection 121 is on, 2) password and/or password hash, and 3) any associated 122 protection options. This class is also used as a protection state 123 container for the undo/redo stack, in which case the password, hash and 124 the options need to be preserved even when the protection flag is 125 off. */ 126 class SC_DLLPUBLIC ScTableProtection : public ScPassHashProtectable 127 { 128 public: 129 enum Option 130 { 131 AUTOFILTER = 0, 132 DELETE_COLUMNS, 133 DELETE_ROWS, 134 FORMAT_CELLS, 135 FORMAT_COLUMNS, 136 FORMAT_ROWS, 137 INSERT_COLUMNS, 138 INSERT_HYPERLINKS, 139 INSERT_ROWS, 140 OBJECTS, 141 PIVOT_TABLES, 142 SCENARIOS, 143 SELECT_LOCKED_CELLS, 144 SELECT_UNLOCKED_CELLS, 145 SHEET, 146 SORT, 147 NONE // last item - used to resize the vector 148 }; 149 150 explicit ScTableProtection(); 151 explicit ScTableProtection(const ScTableProtection& r); 152 virtual ~ScTableProtection(); 153 154 virtual bool isProtected() const; 155 virtual bool isProtectedWithPass() const; 156 virtual void setProtected(bool bProtected); 157 158 virtual bool isPasswordEmpty() const; 159 virtual bool hasPasswordHash(ScPasswordHash eHash) const; 160 virtual void setPassword(const String& aPassText); 161 virtual ::com::sun::star::uno::Sequence<sal_Int8> getPasswordHash(ScPasswordHash eHash) const; 162 virtual void setPasswordHash(const ::com::sun::star::uno::Sequence<sal_Int8>& aPassword, 163 ScPasswordHash eHash = PASSHASH_OOO); 164 virtual bool verifyPassword(const String& aPassText) const; 165 166 bool isOptionEnabled(Option eOption) const; 167 void setOption(Option eOption, bool bEnabled); 168 169 private: 170 ::boost::shared_ptr<ScTableProtectionImpl> mpImpl; 171 }; 172 173 174 #endif 175