-From 72e66d0e42f3bb6efd689ce33b1df407d94b3c60 Mon Sep 17 00:00:00 2001
+From 6c96a39ba7a7763ccd47e379dbfd8d376164985f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jos=C3=A9=20Bollo?= <jose.bollo@iot.bzh>
Date: Mon, 16 Nov 2015 14:26:25 +0100
-Subject: [PATCH] Removing tizen-platform-config
+Subject: [PATCH 13/14] Removing tizen-platform-config
Change-Id: Ic832a2b75229517b09faba969c27fb1a4b490121
---
- policy/security-manager-policy-reload | 2 +-
- src/common/file-lock.cpp | 4 +---
- src/common/include/file-lock.h | 1 -
- src/common/include/privilege_db.h | 3 +--
- src/common/service_impl.cpp | 39 +++++++++++------------------------
- src/common/smack-rules.cpp | 12 ++++-------
- 6 files changed, 19 insertions(+), 42 deletions(-)
+ CMakeLists.txt | 16 +++++++-
+ db/CMakeLists.txt | 2 +-
+ policy/CMakeLists.txt | 1 +
+ ...load => security-manager-policy-reload.in} | 4 +-
+ src/common/file-lock.cpp | 4 +-
+ src/common/include/file-lock.h | 1 -
+ src/common/include/privilege_db.h | 3 +-
+ src/common/service_impl.cpp | 39 ++++++-------------
+ src/common/smack-rules.cpp | 12 ++----
+ 9 files changed, 37 insertions(+), 45 deletions(-)
+ rename policy/{security-manager-policy-reload => security-manager-policy-reload.in} (94%)
-diff --git a/policy/security-manager-policy-reload b/policy/security-manager-policy-reload
-index 6f211c6..ed8047a 100755
+diff --git a/CMakeLists.txt b/CMakeLists.txt
+index 28790d8..37a43cc 100644
+--- a/CMakeLists.txt
++++ b/CMakeLists.txt
+@@ -49,7 +49,7 @@ ADD_DEFINITIONS("-Wall") # Generate all warnings
+ ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings
+
+ STRING(REGEX MATCH "([^.]*)" API_VERSION "${VERSION}")
+-ADD_DEFINITIONS("-DAPI_VERSION=\"$(API_VERSION)\"")
++ADD_DEFINITIONS("-DAPI_VERSION=\"${API_VERSION}\"")
+
+ ADD_DEFINITIONS("-DSMACK_ENABLED")
+
+@@ -58,6 +58,20 @@ IF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
+ ADD_DEFINITIONS("-DBUILD_TYPE_DEBUG")
+ ENDIF (CMAKE_BUILD_TYPE MATCHES "DEBUG")
+
++SET(DATADIR "/usr/share/security-manager" CACHE STRING "path to data directory")
++SET(SMACKRULESDIR "/etc/smack/accesses.d" CACHE STRING "path to Smack rules directory")
++SET(LOCKDIR "/var/run/lock" CACHE STRING "path to lock directory")
++SET(DB_INSTALL_DIR "/var/db/security-manager" CACHE STRING "path to database directory")
++SET(DB_FILENAME ".security-manager.db" CACHE STRING "basename of database")
++SET(GLOBALUSER "userapp" CACHE STRING "name of the global user")
++
++ADD_DEFINITIONS("-DDATADIR=\"${DATADIR}\"")
++ADD_DEFINITIONS("-DSMACKRULESDIR=\"${SMACKRULESDIR}\"")
++ADD_DEFINITIONS("-DLOCKDIR=\"${LOCKDIR}\"")
++ADD_DEFINITIONS("-DDB_INSTALL_DIR=\"${DB_INSTALL_DIR}\"")
++ADD_DEFINITIONS("-DDB_FILENAME=\"${DB_FILENAME}\"")
++ADD_DEFINITIONS("-DGLOBALUSER=\"${GLOBALUSER}\"")
++
+ ADD_SUBDIRECTORY(src)
+ ADD_SUBDIRECTORY(pc)
+ ADD_SUBDIRECTORY(systemd)
+diff --git a/db/CMakeLists.txt b/db/CMakeLists.txt
+index 9e8ffcc..d7af1a0 100644
+--- a/db/CMakeLists.txt
++++ b/db/CMakeLists.txt
+@@ -1,4 +1,4 @@
+-SET(TARGET_DB ".security-manager.db")
++SET(TARGET_DB "$(DB_FILENAME)")
+
+ ADD_CUSTOM_COMMAND(
+ OUTPUT ${TARGET_DB} ${TARGET_DB}-journal
+diff --git a/policy/CMakeLists.txt b/policy/CMakeLists.txt
+index bd08edc..626a2bd 100644
+--- a/policy/CMakeLists.txt
++++ b/policy/CMakeLists.txt
+@@ -1,4 +1,5 @@
+ FILE(GLOB USERTYPE_POLICY_FILES usertype-*.profile)
++CONFIGURE_FILE(security-manager-policy-reload.in security-manager-policy-reload @ONLY)
+ INSTALL(FILES ${USERTYPE_POLICY_FILES} DESTINATION ${SHARE_INSTALL_PREFIX}/security-manager/policy)
+ INSTALL(FILES "app-rules-template.smack" DESTINATION ${SHARE_INSTALL_PREFIX}/security-manager/policy)
+ INSTALL(FILES "privilege-group.list" DESTINATION ${SHARE_INSTALL_PREFIX}/security-manager/policy)
+diff --git a/policy/security-manager-policy-reload b/policy/security-manager-policy-reload.in
+similarity index 94%
+rename from policy/security-manager-policy-reload
+rename to policy/security-manager-policy-reload.in
+index 6f211c6..c1bc4e2 100755
--- a/policy/security-manager-policy-reload
-+++ b/policy/security-manager-policy-reload
-@@ -2,7 +2,7 @@
++++ b/policy/security-manager-policy-reload.in
+@@ -1,8 +1,8 @@
+ #!/bin/sh -e
- POLICY_PATH=/usr/share/security-manager/policy
+-POLICY_PATH=/usr/share/security-manager/policy
++POLICY_PATH=@DATADIR@/policy
PRIVILEGE_GROUP_MAPPING=$POLICY_PATH/privilege-group.list
-DB_FILE=`tzplatform-get TZ_SYS_DB | cut -d= -f2`/.security-manager.db
-+DB_FILE=/usr/dbspace/.security-manager.db
++DB_FILE=@DB_INSTALL_DIR@/@DB_FILENAME@
# Create default buckets
while read bucket default_policy
diff --git a/src/common/file-lock.cpp b/src/common/file-lock.cpp
-index 6f3996c..1dada17 100644
+index 6f3996c..88d2092 100644
--- a/src/common/file-lock.cpp
+++ b/src/common/file-lock.cpp
@@ -30,9 +30,7 @@
-char const * const SERVICE_LOCK_FILE = tzplatform_mkpath3(TZ_SYS_RUN,
- "lock",
- "security-manager.lock");
-+char const * const SERVICE_LOCK_FILE = "/var/run/lock/security-manager.lock";
++char const * const SERVICE_LOCK_FILE = LOCKDIR "/security-manager.lock";
FileLocker::FileLocker(const std::string &lockFile, bool blocking)
{
namespace SecurityManager {
diff --git a/src/common/include/privilege_db.h b/src/common/include/privilege_db.h
-index 4d73d90..03c6680 100644
+index 08fb9d6..3344987 100644
--- a/src/common/include/privilege_db.h
+++ b/src/common/include/privilege_db.h
-@@ -34,14 +34,13 @@
- #include <string>
+@@ -35,14 +35,13 @@
+ #include <vector>
#include <dpl/db/sql_connection.h>
-#include <tzplatform_config.h>
namespace SecurityManager {
-const char *const PRIVILEGE_DB_PATH = tzplatform_mkpath(TZ_SYS_DB, ".security-manager.db");
-+const char *const PRIVILEGE_DB_PATH = "/usr/dbspace/.security-manager.db";
++const char *const PRIVILEGE_DB_PATH = DB_INSTALL_DIR "/" DB_FILENAME;
enum class QueryType {
EGetPkgPrivileges,
diff --git a/src/common/service_impl.cpp b/src/common/service_impl.cpp
-index ae305d3..65cc8b5 100644
+index ae305d3..42150fe 100644
--- a/src/common/service_impl.cpp
+++ b/src/common/service_impl.cpp
@@ -32,7 +32,6 @@
+ if (!globaluid) {
+ struct passwd pw, *p;
+ char buf[4096];
-+ int rc = getpwnam_r("userapp", &pw, buf, sizeof buf, &p);
++ int rc = getpwnam_r(GLOBALUSER, &pw, buf, sizeof buf, &p);
+ globaluid = (rc || p == NULL) ? 555 : p->pw_uid;
+ }
return globaluid;
std::stringstream correctPath;
diff --git a/src/common/smack-rules.cpp b/src/common/smack-rules.cpp
-index d834e42..8b5728b 100644
+index 922a56f..c2e0041 100644
--- a/src/common/smack-rules.cpp
+++ b/src/common/smack-rules.cpp
@@ -34,7 +34,6 @@
const char *const SMACK_APP_LABEL_TEMPLATE = "~APP~";
const char *const SMACK_PKG_LABEL_TEMPLATE = "~PKG~";
-const char *const APP_RULES_TEMPLATE_FILE_PATH = tzplatform_mkpath4(TZ_SYS_SHARE, "security-manager", "policy", "app-rules-template.smack");
-+const char *const APP_RULES_TEMPLATE_FILE_PATH = "/usr/share/security-manager/policy/app-rules-template.smack";
++const char *const APP_RULES_TEMPLATE_FILE_PATH = DATADIR "/policy/app-rules-template.smack";
const char *const SMACK_APP_IN_PACKAGE_PERMS = "rwxat";
SmackRules::SmackRules()
{
- std::string path(tzplatform_mkpath3(TZ_SYS_SMACK, "accesses.d", ("pkg_" + pkgId).c_str()));
- return path;
-+ return "/etc/smack/accesses.d/pkg_" + pkgId;
++ return SMACKRULESDIR "/pkg_" + pkgId;
}
std::string SmackRules::getApplicationRulesFilePath(const std::string &appId)
{
- std::string path(tzplatform_mkpath3(TZ_SYS_SMACK, "accesses.d", ("app_" + appId).c_str()));
- return path;
-+ return "/etc/smack/accesses.d/app_" + appId;
++ return SMACKRULESDIR "/app_" + appId;
}
void SmackRules::installApplicationPrivilegesRules(const std::string &appId, const std::string &pkgId,
const std::vector<std::string> &pkgContents, const std::vector<std::string> &privileges)
continue;
- std::string fprivilege ( privilege + "-template.smack");
- std::string path(tzplatform_mkpath4(TZ_SYS_SHARE, "security-manager", "policy", fprivilege.c_str()));
-+ std::string path = "/usr/share/security-manager/policy/" + privilege + "-template.smack";
- if( stat(path.c_str(), &buffer) == 0)
++ std::string path = DATADIR "/policy/" + privilege + "-template.smack";
+ if( stat(path.c_str(), &buffer) == 0)
smackRules.addFromTemplateFile(appId, pkgId, path);
}
--
-2.1.4
+2.21.0