--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/**
+ * @file client_security_support.cpp
+ * @author Jihoon Chung (jihoon.chung@samsung.com)
+ */
+
+#include "client_security_support.h"
+
+#include <string>
+
+#include <ail.h>
+#include <privilege-control.h>
+
+#include <dpl/exception.h>
+#include <dpl/log/secure_log.h>
+
+namespace ClientModule {
+namespace {
+class Exception
+{
+public:
+ DECLARE_EXCEPTION_TYPE(DPL::Exception, Base)
+ DECLARE_EXCEPTION_TYPE(Base, GetAppInfoFailed)
+ DECLARE_EXCEPTION_TYPE(Base, GetAppInfoStrFailed)
+ DECLARE_EXCEPTION_TYPE(Base, SetPrivilegeFailed)
+};
+
+// Function declare
+void destroyAppInfoHandle(ail_appinfo_h handle);
+void getAppInfo(const std::string& tizenAppId, ail_appinfo_h* handle);
+char* getExePath(ail_appinfo_h handle);
+char* getPackageId(ail_appinfo_h handle);
+char* getPackageType(ail_appinfo_h handle);
+
+void destroyAppInfoHandle(ail_appinfo_h handle)
+{
+ if (handle != NULL)
+ ail_destroy_appinfo(handle);
+}
+
+void getAppInfo(const std::string& tizenAppId, ail_appinfo_h* handle)
+{
+ ail_error_e ret = ail_get_appinfo(tizenAppId.c_str(), handle);
+ if (ret != AIL_ERROR_OK) {
+ _E("error ail_get_appinfo : %d", ret);
+ Throw(Exception::GetAppInfoFailed);
+ }
+}
+
+char* getExePath(ail_appinfo_h handle)
+{
+ char* str = NULL;
+ ail_error_e ret = ail_appinfo_get_str(handle, AIL_PROP_X_SLP_EXE_PATH, &str);
+ if (ret != AIL_ERROR_OK) {
+ _E("error ail_appinfo_get_str(%s) : %d", AIL_PROP_X_SLP_EXE_PATH, ret);
+ Throw(Exception::GetAppInfoStrFailed);
+ }
+ return str;
+}
+
+char* getPackageId(ail_appinfo_h handle)
+{
+ char* str = NULL;
+ ail_error_e ret = ail_appinfo_get_str(handle, AIL_PROP_X_SLP_PKGID_STR, &str);
+ if (ret != AIL_ERROR_OK) {
+ _E("error ail_appinfo_get_str(%s) : %d", AIL_PROP_X_SLP_PKGID_STR, ret);
+ Throw(Exception::GetAppInfoStrFailed);
+ }
+ return str;
+}
+
+char* getPackageType(ail_appinfo_h handle)
+{
+ char* str = NULL;
+ ail_error_e ret = ail_appinfo_get_str(handle, AIL_PROP_X_SLP_PACKAGETYPE_STR, &str);
+ if (ret != AIL_ERROR_OK) {
+ _E("error ail_appinfo_get_str(%s) : %d", AIL_PROP_X_SLP_PACKAGETYPE_STR, ret);
+ Throw(Exception::GetAppInfoStrFailed);
+ }
+ return str;
+}
+} // namespace anonymous
+
+bool SecuritySupport::setAppPrivilege(const std::string& tizenAppId)
+{
+ ail_appinfo_h handle = NULL;
+ Try
+ {
+ getAppInfo(tizenAppId, &handle);
+ char* path = getExePath(handle);
+ char* pkgId = getPackageId(handle);
+ char* type = getPackageType(handle);
+
+ _D("Package ID : %s", pkgId);
+ _D("Package TYPE : %s", type);
+ _D("Package PATH : %s", path);
+
+ int ret = perm_app_set_privilege(pkgId, type, path);
+ if (ret != PC_OPERATION_SUCCESS) {
+ _E("error perm_app_set_privilege : (%d)", ret);
+ Throw(Exception::SetPrivilegeFailed);
+ }
+ }
+ Catch(Exception::Base)
+ {
+ destroyAppInfoHandle(handle);
+ return false;
+ }
+
+ destroyAppInfoHandle(handle);
+ return true;
+}
+} // ClientModule
--- /dev/null
+/*
+ * Copyright (c) 2013 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+ /**
+ * @file client_security_support.h
+ * @author Jihoon Chung (jihoon.chung@samsung.com)
+ */
+#ifndef CLIENT_SECURITY_SUPPORT_H_
+#define CLIENT_SECURITY_SUPPORT_H_
+
+#include <string>
+
+namespace ClientModule {
+namespace SecuritySupport {
+bool setAppPrivilege(const std::string& tizenAppId);
+} // namespace SecuritySupport
+} // namespace ClientModule
+#endif // CLIENT_SECURITY_SUPPORT_H_
\ No newline at end of file
#include "client_command_line_parser.h"
#include "client_ide_support.h"
+#include "client_security_support.h"
#include "client_service_support.h"
#include "client_submode_support.h"
char const* const ELM_SWALLOW_CONTENT = "elm.swallow.content";
const char* const BUNDLE_PATH = LIBDIR_PREFIX "/usr/lib/libwrt-injected-bundle.so";
const char* const MESSAGE_NAME_INITIALIZE = "ToInjectedBundle::INIT";
+const unsigned int UID_ROOT = 0;
// process pool
const char* const DUMMY_PROCESS_PATH = "/usr/bin/wrt_launchpad_daemon_candidate";
ClientModule::CommandLineParser::getTizenId(argc, argv);
if (!tizenId.empty()) {
+ if (UID_ROOT == getuid()) {
+ // Drop root permission
+ // Only launch web application by console command case has root permission
+ if (!ClientModule::SecuritySupport::setAppPrivilege(tizenId)) {
+ LogError("Fail to set app privilege : [" << tizenId << "]");
+ exit(-1);
+ }
+ }
+
LogDebug("Launching by fork mode");
// Language env setup
appcore_set_i18n("wrt-client", NULL);