2 * Copyright (C) 2007 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
28 #ifndef DatabaseAuthorizer_h
29 #define DatabaseAuthorizer_h
31 #include "platform/heap/Handle.h"
32 #include "wtf/Forward.h"
33 #include "wtf/HashSet.h"
34 #include "wtf/text/StringHash.h"
35 #include "wtf/text/WTFString.h"
39 extern const int SQLAuthAllow;
40 extern const int SQLAuthDeny;
42 class DatabaseAuthorizer : public GarbageCollectedFinalized<DatabaseAuthorizer> {
47 ReadOnlyMask = 1 << 1,
51 static DatabaseAuthorizer* create(const String& databaseInfoTableName);
52 void trace(Visitor*) { }
54 int createTable(const String& tableName);
55 int createTempTable(const String& tableName);
56 int dropTable(const String& tableName);
57 int dropTempTable(const String& tableName);
58 int allowAlterTable(const String& databaseName, const String& tableName);
60 int createIndex(const String& indexName, const String& tableName);
61 int createTempIndex(const String& indexName, const String& tableName);
62 int dropIndex(const String& indexName, const String& tableName);
63 int dropTempIndex(const String& indexName, const String& tableName);
65 int createTrigger(const String& triggerName, const String& tableName);
66 int createTempTrigger(const String& triggerName, const String& tableName);
67 int dropTrigger(const String& triggerName, const String& tableName);
68 int dropTempTrigger(const String& triggerName, const String& tableName);
70 int createView(const String& viewName);
71 int createTempView(const String& viewName);
72 int dropView(const String& viewName);
73 int dropTempView(const String& viewName);
75 int createVTable(const String& tableName, const String& moduleName);
76 int dropVTable(const String& tableName, const String& moduleName);
78 int allowDelete(const String& tableName);
79 int allowInsert(const String& tableName);
80 int allowUpdate(const String& tableName, const String& columnName);
81 int allowTransaction();
83 int allowSelect() { return SQLAuthAllow; }
84 int allowRead(const String& tableName, const String& columnName);
86 int allowReindex(const String& indexName);
87 int allowAnalyze(const String& tableName);
88 int allowFunction(const String& functionName);
89 int allowPragma(const String& pragmaName, const String& firstArgument);
91 int allowAttach(const String& filename);
92 int allowDetach(const String& databaseName);
96 void setPermissions(int permissions);
101 bool lastActionWasInsert() const { return m_lastActionWasInsert; }
102 bool lastActionChangedDatabase() const { return m_lastActionChangedDatabase; }
103 bool hadDeletes() const { return m_hadDeletes; }
106 explicit DatabaseAuthorizer(const String& databaseInfoTableName);
107 void addWhitelistedFunctions();
108 int denyBasedOnTableName(const String&) const;
109 int updateDeletesBasedOnTableName(const String&);
113 bool m_securityEnabled : 1;
114 bool m_lastActionWasInsert : 1;
115 bool m_lastActionChangedDatabase : 1;
116 bool m_hadDeletes : 1;
118 const String m_databaseInfoTableName;
120 HashSet<String, CaseFoldingHash> m_whitelistedFunctions;
125 #endif // DatabaseAuthorizer_h