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/ThreadSafeRefCounted.h"
35 #include "wtf/text/StringHash.h"
36 #include "wtf/text/WTFString.h"
40 extern const int SQLAuthAllow;
41 extern const int SQLAuthDeny;
43 class DatabaseAuthorizer : public ThreadSafeRefCountedWillBeGarbageCollectedFinalized<DatabaseAuthorizer> {
48 ReadOnlyMask = 1 << 1,
52 static PassRefPtrWillBeRawPtr<DatabaseAuthorizer> create(const String& databaseInfoTableName);
53 void trace(Visitor*) { }
55 int createTable(const String& tableName);
56 int createTempTable(const String& tableName);
57 int dropTable(const String& tableName);
58 int dropTempTable(const String& tableName);
59 int allowAlterTable(const String& databaseName, const String& tableName);
61 int createIndex(const String& indexName, const String& tableName);
62 int createTempIndex(const String& indexName, const String& tableName);
63 int dropIndex(const String& indexName, const String& tableName);
64 int dropTempIndex(const String& indexName, const String& tableName);
66 int createTrigger(const String& triggerName, const String& tableName);
67 int createTempTrigger(const String& triggerName, const String& tableName);
68 int dropTrigger(const String& triggerName, const String& tableName);
69 int dropTempTrigger(const String& triggerName, const String& tableName);
71 int createView(const String& viewName);
72 int createTempView(const String& viewName);
73 int dropView(const String& viewName);
74 int dropTempView(const String& viewName);
76 int createVTable(const String& tableName, const String& moduleName);
77 int dropVTable(const String& tableName, const String& moduleName);
79 int allowDelete(const String& tableName);
80 int allowInsert(const String& tableName);
81 int allowUpdate(const String& tableName, const String& columnName);
82 int allowTransaction();
84 int allowSelect() { return SQLAuthAllow; }
85 int allowRead(const String& tableName, const String& columnName);
87 int allowReindex(const String& indexName);
88 int allowAnalyze(const String& tableName);
89 int allowFunction(const String& functionName);
90 int allowPragma(const String& pragmaName, const String& firstArgument);
92 int allowAttach(const String& filename);
93 int allowDetach(const String& databaseName);
97 void setPermissions(int permissions);
102 bool lastActionWasInsert() const { return m_lastActionWasInsert; }
103 bool lastActionChangedDatabase() const { return m_lastActionChangedDatabase; }
104 bool hadDeletes() const { return m_hadDeletes; }
107 explicit DatabaseAuthorizer(const String& databaseInfoTableName);
108 void addWhitelistedFunctions();
109 int denyBasedOnTableName(const String&) const;
110 int updateDeletesBasedOnTableName(const String&);
114 bool m_securityEnabled : 1;
115 bool m_lastActionWasInsert : 1;
116 bool m_lastActionChangedDatabase : 1;
117 bool m_hadDeletes : 1;
119 const String m_databaseInfoTableName;
121 HashSet<String, CaseFoldingHash> m_whitelistedFunctions;
126 #endif // DatabaseAuthorizer_h