Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: sql/connection.cc

Issue 5125579611308032: [sql] Allow restricting database to user read access. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments about posix-specificness. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sql/connection.cc
diff --git a/sql/connection.cc b/sql/connection.cc
index f2164ec395be3b2d103ab4105447ccad1f026ec8..1b49f7eb5c8c75b8b1cc74ec365f025c215572c8 100644
--- a/sql/connection.cc
+++ b/sql/connection.cc
@@ -168,6 +168,7 @@ Connection::Connection()
page_size_(0),
cache_size_(0),
exclusive_locking_(false),
+ restrict_to_user_(false),
transaction_nesting_(0),
needs_rollback_(false),
in_memory_(false),
@@ -728,6 +729,30 @@ bool Connection::OpenInternal(const std::string& file_name) {
return false;
}
+ // TODO(shess): OS_WIN support?
+#if defined(OS_POSIX)
+ if (restrict_to_user_) {
+ DCHECK_NE(file_name, std::string(":memory"));
+ base::FilePath file_path(file_name);
+ int mode = 0;
+ // TODO(shess): Arguably, failure to retrieve and change
+ // permissions should be fatal if the file exists.
+ if (file_util::GetPosixFilePermissions(file_path, &mode)) {
+ mode &= file_util::FILE_PERMISSION_USER_MASK;
+ file_util::SetPosixFilePermissions(file_path, mode);
+
+ // SQLite sets the permissions on these files from the main
+ // database on create. Set them here in case they already exist
+ // at this point. Failure to set these permissions should not
+ // be fatal unless the file doesn't exist.
+ base::FilePath journal_path(file_name + FILE_PATH_LITERAL("-journal"));
+ base::FilePath wal_path(file_name + FILE_PATH_LITERAL("-wal"));
+ file_util::SetPosixFilePermissions(journal_path, mode);
+ file_util::SetPosixFilePermissions(wal_path, mode);
+ }
+ }
+#endif // defined(OS_POSIX)
+
// SQLite uses a lookaside buffer to improve performance of small mallocs.
// Chromium already depends on small mallocs being efficient, so we disable
// this to avoid the extra memory overhead.
« no previous file with comments | « sql/connection.h ('k') | sql/connection_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698