From: Andrzej Popowski Date: Mon, 29 Feb 2016 08:55:56 +0000 (+0100) Subject: [Filesystem] - Remove double privilege checking from JS code X-Git-Tag: submit/tizen/20160302.021255~1^2^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=b6c994dbd200417125427ade30f2bb2de57b09db;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git [Filesystem] - Remove double privilege checking from JS code Change-Id: I4a61f05c7b374746985eea4685d51eedcb14c9ef Signed-off-by: Andrzej Popowski --- diff --git a/src/filesystem/filesystem_instance.cc b/src/filesystem/filesystem_instance.cc index af691722..df1d003a 100644 --- a/src/filesystem/filesystem_instance.cc +++ b/src/filesystem/filesystem_instance.cc @@ -22,11 +22,18 @@ #include "common/logger.h" #include "common/platform_exception.h" #include "common/task-queue.h" +#include "common/tools.h" #include "filesystem_manager.h" namespace extension { namespace filesystem { +namespace { +// The privileges that required in Filesystem API +const std::string kPrivilegeFilesystemRead = "http://tizen.org/privilege/systemsettings.admin"; +const std::string kPrivilegeFilesystemWrite = "http://tizen.org/privilege/systemsettings.admin"; +} + using namespace common; using namespace extension::filesystem; @@ -82,6 +89,7 @@ FilesystemInstance::~FilesystemInstance() { void FilesystemInstance::FileCreateSync(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) const std::string& location = args.get("location").get(); @@ -102,6 +110,7 @@ void FilesystemInstance::FileCreateSync(const picojson::value& args, picojson::o void FilesystemInstance::FileRename(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "callbackId", out) CHECK_EXIST(args, "oldPath", out) CHECK_EXIST(args, "newPath", out) @@ -177,6 +186,7 @@ void FilesystemInstance::FileRead(const picojson::value& args, void FilesystemInstance::FileReadSync(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "offset", out) CHECK_EXIST(args, "length", out) @@ -244,6 +254,7 @@ void FilesystemInstance::FileWrite(const picojson::value& args, void FilesystemInstance::FileWriteSync(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) CHECK_EXIST(args, "data", out) CHECK_EXIST(args, "offset", out) @@ -269,6 +280,7 @@ void FilesystemInstance::FileWriteSync(const picojson::value& args, void FilesystemInstance::FileStat(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "callbackId", out) CHECK_EXIST(args, "location", out) @@ -301,6 +313,7 @@ void FilesystemInstance::FileStat(const picojson::value& args, void FilesystemInstance::FileStatSync(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "location", out) const std::string& location = args.get("location").get(); @@ -365,6 +378,7 @@ void FilesystemInstance::StartListening( const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); FilesystemManager::GetInstance().StartListening(); ReportSuccess(out); } @@ -373,6 +387,7 @@ void FilesystemInstance::StopListening( const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); FilesystemManager::GetInstance().StopListening(); ReportSuccess(out); } @@ -432,6 +447,7 @@ void FilesystemInstance::FileSystemManagerMakeDirectorySync( const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "location", out) const std::string& location = args.get("location").get(); @@ -450,6 +466,7 @@ void FilesystemInstance::FileSystemManagerMakeDirectorySync( void FilesystemInstance::ReadDir(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemRead, &out); CHECK_EXIST(args, "pathToDir", out) CHECK_EXIST(args, "callbackId", out) @@ -488,6 +505,7 @@ void FilesystemInstance::ReadDir(const picojson::value& args, void FilesystemInstance::UnlinkFile(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "pathToFile", out) double callback_id = args.get("callbackId").get(); @@ -520,6 +538,7 @@ void FilesystemInstance::UnlinkFile(const picojson::value& args, void FilesystemInstance::RemoveDirectory(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "pathToDelete", out) double callback_id = args.get("callbackId").get(); @@ -552,6 +571,7 @@ void FilesystemInstance::RemoveDirectory(const picojson::value& args, void FilesystemInstance::CopyTo(const picojson::value& args, picojson::object& out) { LoggerD("enter"); + CHECK_PRIVILEGE_ACCESS(kPrivilegeFilesystemWrite, &out); CHECK_EXIST(args, "callbackId", out) CHECK_EXIST(args, "originFilePath", out) CHECK_EXIST(args, "destinationFilePath", out) diff --git a/src/filesystem/js/file.js b/src/filesystem/js/file.js index 8ff33d96..973b3c0c 100644 --- a/src/filesystem/js/file.js +++ b/src/filesystem/js/file.js @@ -60,7 +60,7 @@ function File(data) { } function toURI() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); + xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_READ); return 'file://' + commonFS_.toRealPath(this.fullPath); } @@ -160,8 +160,6 @@ function checkFile(file, fileFilter) { } function listFiles() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}, @@ -243,8 +241,6 @@ function _checkEncoding(encoding) { } function openStream() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ {name: 'mode', type: types_.ENUM, values: ['r', 'rw', 'w', 'a']}, {name: 'onsuccess', type: types_.FUNCTION}, @@ -296,8 +292,6 @@ File.prototype.openStream = function() { }; function readAsText() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true}, @@ -357,8 +351,6 @@ File.prototype.readAsText = function() { }; function copyTo() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'originFilePath', type: types_.STRING}, {name: 'destinationFilePath', type: types_.STRING}, @@ -499,8 +491,6 @@ File.prototype.copyTo = function() { }; function moveTo() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'originFilePath', type: types_.STRING}, {name: 'destinationFilePath', type: types_.STRING}, @@ -604,8 +594,6 @@ File.prototype.moveTo = function() { }; function createDirectory() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'dirPath', type: types_.STRING} ]); @@ -661,8 +649,6 @@ File.prototype.createDirectory = function() { } function createFile() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'relativeFilePath', type: types_.STRING} ]); @@ -710,8 +696,6 @@ File.prototype.createFile = function() { }; function resolveFile() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ {name: 'filePath', type: types_.STRING} ]); @@ -751,8 +735,6 @@ File.prototype.resolve = function() { }; function deleteDirectory() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'directoryPath', type: types_.STRING}, {name: 'recursive', type: types_.BOOLEAN}, @@ -841,8 +823,6 @@ File.prototype.deleteDirectory = function() { }; function deleteFile() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'filePath', type: types_.STRING}, {name: 'onsuccess', type: types_.FUNCTION, optional: true, nullable: true}, @@ -910,4 +890,4 @@ function deleteFile() { File.prototype.deleteFile = function() { deleteFile.apply(this, arguments); -}; \ No newline at end of file +}; diff --git a/src/filesystem/js/file_stream.js b/src/filesystem/js/file_stream.js index 94b3ed21..2036254b 100644 --- a/src/filesystem/js/file_stream.js +++ b/src/filesystem/js/file_stream.js @@ -79,7 +79,6 @@ function _checkClosed(stream) { } function closeFileStream() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); this._closed = true; }; @@ -100,8 +99,6 @@ function _checkWriteAccess(mode) { } function read() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ { name: 'charCount', @@ -147,8 +144,6 @@ FileStream.prototype.read = function() { }; function readBytes() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ { name: 'byteCount', @@ -186,8 +181,6 @@ FileStream.prototype.readBytes = function() { }; function readBase64() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ { name: 'byteCount', @@ -237,8 +230,6 @@ FileStream.prototype.readBase64 = function() { } function write() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'stringData', @@ -275,8 +266,6 @@ FileStream.prototype.write = function() { }; function writeBytes() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'byteData', @@ -319,8 +308,6 @@ function _isBase64(str) { } function writeBase64() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ { name: 'base64Data', diff --git a/src/filesystem/js/file_system_manager.js b/src/filesystem/js/file_system_manager.js index 70a4a3a3..8f88862c 100755 --- a/src/filesystem/js/file_system_manager.js +++ b/src/filesystem/js/file_system_manager.js @@ -31,8 +31,6 @@ function FileSystemManager() { } function resolve() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - var args = validator_.validateArgs(arguments, [ {name: 'location', type: types_.STRING}, {name: 'onsuccess', type: types_.FUNCTION}, @@ -108,8 +106,7 @@ FileSystemManager.prototype.resolve = function() { }; function getStorage() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - + xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_READ); var args = validator_.validateArgs(arguments, [ {name: 'label', type: types_.STRING}, {name: 'onsuccess', type: types_.FUNCTION}, @@ -133,8 +130,7 @@ FileSystemManager.prototype.getStorage = function() { }; function listStorages() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_READ); - + xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.FILESYSTEM_READ); var args = validator_.validateArgs(arguments, [ {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true} @@ -171,8 +167,6 @@ function _StorageStateChangeListener(result) { } function addStorageStateChangeListener() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'onsuccess', type: types_.FUNCTION}, {name: 'onerror', type: types_.FUNCTION, optional: true, nullable: true} @@ -203,8 +197,6 @@ FileSystemManager.prototype.addStorageStateChangeListener = function() { }; function removeStorageStateChangeListener() { - privUtils_.checkPrivilegeAccess(privilege_.FILESYSTEM_WRITE); - var args = validator_.validateArgs(arguments, [ {name: 'watchId', type: types_.LONG} ]);