1 /* 2 * Copyright (C) 2007 Apple Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of 14 * its contributors may be used to endorse or promote products derived 15 * from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 #ifndef DatabaseAuthorizer_h 29 #define DatabaseAuthorizer_h 30 31 #include <wtf/PassRefPtr.h> 32 #include <wtf/Threading.h> 33 34 namespace WebCore { 35 36 class String; 37 38 extern const int SQLAuthAllow; 39 extern const int SQLAuthIgnore; 40 extern const int SQLAuthDeny; 41 42 class DatabaseAuthorizer : public ThreadSafeShared<DatabaseAuthorizer> { 43 public: create()44 static PassRefPtr<DatabaseAuthorizer> create() { return adoptRef(new DatabaseAuthorizer); } 45 46 int createTable(const String& tableName); 47 int createTempTable(const String& tableName); 48 int dropTable(const String& tableName); 49 int dropTempTable(const String& tableName); 50 int allowAlterTable(const String& databaseName, const String& tableName); 51 52 int createIndex(const String& indexName, const String& tableName); 53 int createTempIndex(const String& indexName, const String& tableName); 54 int dropIndex(const String& indexName, const String& tableName); 55 int dropTempIndex(const String& indexName, const String& tableName); 56 57 int createTrigger(const String& triggerName, const String& tableName); 58 int createTempTrigger(const String& triggerName, const String& tableName); 59 int dropTrigger(const String& triggerName, const String& tableName); 60 int dropTempTrigger(const String& triggerName, const String& tableName); 61 createView(const String &)62 int createView(const String& /*viewName*/) { return SQLAuthAllow; } createTempView(const String &)63 int createTempView(const String& /*viewName*/) { return SQLAuthAllow; } dropView(const String &)64 int dropView(const String& /*viewName*/) { return SQLAuthAllow; } dropTempView(const String &)65 int dropTempView(const String& /*viewName*/) { return SQLAuthAllow; } 66 67 int createVTable(const String& tableName, const String& moduleName); 68 int dropVTable(const String& tableName, const String& moduleName); 69 70 int allowDelete(const String& tableName); 71 int allowInsert(const String& tableName); 72 int allowUpdate(const String& tableName, const String& columnName); 73 int allowTransaction(); 74 allowSelect()75 int allowSelect() { return SQLAuthAllow; } 76 int allowRead(const String& tableName, const String& columnName); 77 allowReindex(const String &)78 int allowReindex(const String& /*indexName*/) { return SQLAuthAllow; } 79 int allowAnalyze(const String& tableName); 80 int allowFunction(const String& functionName); 81 int allowPragma(const String& pragmaName, const String& firstArgument); 82 83 int allowAttach(const String& filename); 84 int allowDetach(const String& databaseName); 85 86 void disable(); 87 void enable(); 88 void setReadOnly(); 89 90 void reset(); 91 lastActionWasInsert()92 bool lastActionWasInsert() const { return m_lastActionWasInsert; } lastActionChangedDatabase()93 bool lastActionChangedDatabase() const { return m_lastActionChangedDatabase; } 94 95 private: 96 DatabaseAuthorizer(); 97 int denyBasedOnTableName(const String&); 98 99 bool m_securityEnabled : 1; 100 bool m_lastActionWasInsert : 1; 101 bool m_lastActionChangedDatabase : 1; 102 bool m_readOnly : 1; 103 }; 104 105 } // namespace WebCore 106 107 #endif // DatabaseAuthorizer_h 108