${COMMON_PATH}/smack-check.cpp
${COMMON_PATH}/service_impl.cpp
${COMMON_PATH}/tzplatform-config.cpp
+ ${COMMON_PATH}/utils.cpp
${COMMON_PATH}/worker.cpp
${COMMON_PATH}/privilege-info.cpp
${COMMON_PATH}/privilege-gids.cpp
/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Rafal Krypa <r.krypa@samsung.com>
*
NOOP = 0x90,
};
+// returns stringified name of return call type
+const char * SecurityModuleCallToString(SecurityModuleCall call_num);
+
} // namespace SecurityManager
struct policy_entry : ISerializable {
/*
- * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2016 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Rafal Krypa <r.krypa@samsung.com>
*
* @file utils.h
* @author Rafal Krypa <r.krypa@samsung.com>
* @version 1.0
- * @brief Utility macros and templates
+ * @brief Utility functions, macros and templates
*/
#pragma once
#include <functional>
#include <memory>
#include <sys/wait.h>
+#include <time.h>
#include <type_traits>
#include <unistd.h>
#include <vector>
+#include <string>
+
+#include <credentials.h>
namespace SecurityManager {
+time_t monotonicNow();
+
+// Used for measuring function/method/scope execution time
+class ScopedTimeStamper {
+public:
+ ScopedTimeStamper(const std::string & location, const Credentials & creds);
+ virtual ~ScopedTimeStamper();
+
+private:
+ struct timespec m_start;
+ std::string m_locationStr;
+};
+
+#ifdef BUILD_TYPE_DEBUG
+#define LOG_EXECUTION_TIME(location, creds) ScopedTimeStamper __stamper(location, creds)
+#else
+#define LOG_EXECUTION_TIME(location, creds) do {} while (0)
+#endif
+
// Pointer
template<typename T>
std::unique_ptr<T> makeUnique(T *ptr)
/*
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Rafal Krypa <r.krypa@samsung.com>
*
char const * const SERVICE_SOCKET =
SOCKET_PATH_PREFIX "security-manager.socket";
+#define SM_CODE_DESCRIBE(name) case name: return #name
+const char * SecurityModuleCallToString(SecurityModuleCall call_num) {
+ switch (call_num) {
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_INSTALL);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_UPDATE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_UNINSTALL);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_GET_PKG_NAME);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_APPLY_PRIVATE_SHARING);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_DROP_PRIVATE_SHARING);
+ SM_CODE_DESCRIBE(SecurityModuleCall::USER_ADD);
+ SM_CODE_DESCRIBE(SecurityModuleCall::USER_DELETE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::POLICY_UPDATE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_POLICY);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_CONF_POLICY_ADMIN);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_CONF_POLICY_SELF);
+ SM_CODE_DESCRIBE(SecurityModuleCall::POLICY_GET_DESCRIPTIONS);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GROUPS_GET);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_HAS_PRIVILEGE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::PATHS_REGISTER);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GROUPS_FOR_UID);
+ SM_CODE_DESCRIBE(SecurityModuleCall::LABEL_FOR_PROCESS);
+ SM_CODE_DESCRIBE(SecurityModuleCall::SHM_APP_NAME);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_PROVIDER);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_APP_DEFINED_PRIVILEGE_LICENSE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_CLIENT_PRIVILEGE_LICENSE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_SETUP_NAMESPACE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::APP_CLEAN_NAMESPACE);
+ SM_CODE_DESCRIBE(SecurityModuleCall::GET_APP_MANIFEST_POLICY);
+ SM_CODE_DESCRIBE(SecurityModuleCall::NOOP);
+ default: return "Code not defined";
+ }
+}
+#undef SM_CODE_DESCRIBE
+
} // namespace SecurityManager
--- /dev/null
+/*
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Contact: Tomasz Swierczek <t.swierczek@samsung.com>
+ *
+ * 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 utils.cpp
+ * @author Tomasz Swierczek <t.swierczek@samsung.com>
+ * @version 1.0
+ * @brief Implementation of utility functions
+ */
+
+#include <utils.h>
+
+#include <dpl/log/log.h>
+#include <dpl/errno_string.h>
+
+namespace SecurityManager {
+
+time_t monotonicNow() {
+ struct timespec now;
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) {
+ int err = errno;
+ LogError("Can't access monotonic clock, error: " << GetErrnoString(err));
+ return 0;
+ }
+ return now.tv_sec;
+}
+
+ScopedTimeStamper::ScopedTimeStamper(const std::string & location, const Credentials & creds)
+{
+ m_locationStr = location +
+ ", caller uid = " + std::to_string(creds.uid) +
+ ", caller pid = " + std::to_string(creds.pid) +
+ ", caller label = " + creds.label;
+
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &m_start) == -1) {
+ int err = errno;
+ LogError("Can't access monotonic clock, error: " << GetErrnoString(err));
+ }
+}
+
+ScopedTimeStamper::~ScopedTimeStamper()
+{
+ struct timespec end;
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &end) == -1) {
+ int err = errno;
+ LogError("Can't access monothonic clock, error: " << GetErrnoString(err));
+ }
+ long ndiff = (end.tv_nsec - m_start.tv_nsec ) + (end.tv_sec - m_start.tv_sec ) * 1E9;
+ float sec(ndiff);
+ sec *= 0.000000001;
+ LogDebug("Execution of " << m_locationStr << " took " << sec << " seconds");
+}
+
+} /* namespace SecurityManager */
void NotifyMe(void);
void CloseSocket(int sock);
- time_t monotonicNow();
-
struct SocketDescription {
bool isListen;
bool isOpen;
#include <credentials.h>
#include <smack-check.h>
#include <socket-manager.h>
+#include <utils.h>
namespace {
LogDebug("Closing socket: " << sock << " finished..");
}
-time_t SocketManager::monotonicNow() {
- struct timespec now;
- if (clock_gettime(CLOCK_MONOTONIC_RAW, &now) == -1) {
- int err = errno;
- LogError("Can't access monothonic clock, error: " << GetErrnoString(err));
- return 0;
- }
- return now.tv_sec;
-}
-
} // namespace SecurityManager
/*
- * Copyright (c) 2000 - 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Rafal Krypa <r.krypa@samsung.com>
*
#include "protocols.h"
#include "service.h"
#include "service_impl.h"
+#include "utils.h"
namespace SecurityManager {
int call_type_int;
Deserialization::Deserialize(buffer, call_type_int);
SecurityModuleCall call_type = static_cast<SecurityModuleCall>(call_type_int);
-
+ LOG_EXECUTION_TIME(SecurityModuleCallToString(call_type), creds);
switch (call_type) {
case SecurityModuleCall::NOOP:
LogDebug("call_type: SecurityModuleCall::NOOP");
${PROJECT_SOURCE_DIR}/src/common/smack-rules.cpp
${PROJECT_SOURCE_DIR}/src/common/filesystem.cpp
${PROJECT_SOURCE_DIR}/src/common/tzplatform-config.cpp
+ ${PROJECT_SOURCE_DIR}/src/common/utils.cpp
${GEN_PATH}/db.h
)