extern "C" {
#endif
+typedef void* audit_trail_mac_h;
+
/**
* @addtogroup CAPI_AUDIT_TRAIL_MODULE
* @{
* @see audit_trail_remove_log_cb
* @see audit_trail_foreach_smack
*/
-typedef void (*audit_trail_string_cb)(const char* log, void* user_data);
+typedef void (*audit_trail_string_cb)(audit_trail_mac_h handle, void* user_data);
/**
* @}
extern "C" {
#endif
+
/**
* @brief Retrieves all MAC logs that occured in system.
* @details This API calls audit_trail_string_cb() once for each MAC
*/
AUDIT_TRAIL_API int audit_trail_is_enabled_mac(audit_trail_h handle, bool *en);
+AUDIT_TRAIL_API int audit_trail_get_mac_time(audit_trail_mac_h handle, time_t *time, unsigned short *ms);
+
+/**
+ * @brief Get the subject name of the MAC log
+ * @details This API can be used to get the subject names in each MAC logs.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] name The subject name
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post The subject name must not be freed.
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_subject_name(audit_trail_mac_h handle, const char **name);
+
+/**
+ * @brief Get the subject label of the MAC log
+ * @details This API can be used to get the subject labels in each MAC logs.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] label The subject label
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post The subject label must not be freed.
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_subject_label(audit_trail_mac_h handle, const char **label);
+
+/**
+ * @brief Get the subject process ID of the MAC log
+ * @details This API can be used to get the subject process ID in
+ * each MAC logs.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] pid The subject process ID
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_subject_pid(audit_trail_mac_h handle, pid_t *pid);
+
+/**
+ * @brief Get the object name of the MAC log
+ * @details This API can be used to get the object names in each MAC logs.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] name The object name
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post The object name must not be freed.
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_object_name(audit_trail_mac_h handle, const char **name);
+
+/**
+ * @brief Get the object label of the MAC log
+ * @details This API can be used to get the object labels in each MAC logs.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] label The object label
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post The object label must not be freed.
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_object_label(audit_trail_mac_h handle, const char **label);
+
+/**
+ * @brief Get the function name of the MAC log
+ * @details This API can be used to get the function that causes a MAC log.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] syscall the system call number
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post The function name must not be freed.
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_action_syscall(audit_trail_mac_h handle, unsigned int *syscall);
+
+/**
+ * @brief Get what operation is requested by the function of the MAC log
+ * @details This API can be used to get what operation such as rwx (Read,
+ * Write, eXcute) is requested by the function that causes a NAC
+ * log.
+ * @since_tizen 5.0
+ * @param[in] handle The audit-trail MAC log handle
+ * @param[out] req The requested operation
+ * @return #AUDIT_TRAIL_ERROR_NONE on success, otherwise a negative value
+ * @retval #AUDIT_TRAIL_ERROR_NONE Successful
+ * @retval #AUDIT_TRAIL_ERROR_TIMED_OUT Time out
+ * @retval #AUDIT_TRAIL_ERROR_INVALID_PARAMETER Invalid parameter
+ * @post The requested operation must not be freed.
+ */
+AUDIT_TRAIL_API int audit_trail_get_mac_action_request(audit_trail_mac_h handle, const char **req);
+
/**
* @}
*/
namespace NMD
{
-void macLogCallback(const char* log, void* user_data)
+void macLogCallback(audit_trail_mac_h handle, void* user_data)
{
- assert(log);
assert(user_data);
- LOG_D(TAG, "MAC log callback: %s", log);
AuditTrailClient* client = reinterpret_cast<AuditTrailClient*>(user_data);
assert(client);
- client->m_proxy_thread->addDefferedTask(&AuditTrailClient::sendReport, client, std::string{"smack"}, std::string{log});
+ time_t time;
+ unsigned short ms;
+ pid_t pid;
+ unsigned int syscall;
+ const char* subj_name;
+ const char* subj_label;
+ const char* obj_name;
+ const char* obj_label;
+ const char* req;
+ int result;
+
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_time(handle, &time, &ms))) {
+ LOG_E(TAG, "audit_trail_get_mac_time error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_subject_name(handle, &subj_name))) {
+ LOG_E(TAG, "audit_trail_get_mac_subject_name error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_subject_label(handle, &subj_label))) {
+ LOG_E(TAG, "audit_trail_get_mac_subject_label error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_subject_pid(handle, &pid))) {
+ LOG_E(TAG, "audit_trail_get_mac_subject_pid error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_object_name(handle, &obj_name))) {
+ LOG_E(TAG, "audit_trail_get_mac_object_name error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_object_label(handle, &obj_label))) {
+ LOG_E(TAG, "audit_trail_get_mac_object_label error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_action_syscall(handle, &syscall))) {
+ LOG_E(TAG, "audit_trail_get_mac_action_syscall error %d", result);
+ }
+ if (AUDIT_TRAIL_ERROR_NONE != (result = audit_trail_get_mac_action_request(handle, &req))) {
+ LOG_E(TAG, "audit_trail_get_mac_action_request error %d", result);
+ }
+
+ std::ostringstream os;
+ os << "[MAC] audit(" << time << '.' << ms << ":0) lsm=SMACK comm=" << subj_name << " subject=" << subj_label << " "
+ << "path=" << obj_name << " object=" << obj_label << " requested=" << req << " pid=" << pid << " ino=" << syscall;
+ LOG_D(TAG, "MAC log callback: %s", os.str().c_str());
+
+ client->m_proxy_thread->addDefferedTask(&AuditTrailClient::sendReport, client, std::string{"smack"}, os.str());
}
-void dacLogCallback(const char* log, void* user_data)
+void dacLogCallback(audit_trail_dac_h handle, void* user_data)
{
- assert(log);
- assert(user_data);
- LOG_D(TAG, "DAC log callback: %s", log);
+// assert(log);
+// assert(user_data);
+// LOG_D(TAG, "DAC log callback: %s", log);
- AuditTrailClient* client = reinterpret_cast<AuditTrailClient*>(user_data);
- assert(client);
- client->m_proxy_thread->addDefferedTask(&AuditTrailClient::sendReport, client, std::string{"dac"}, std::string{log});
+// AuditTrailClient* client = reinterpret_cast<AuditTrailClient*>(user_data);
+// assert(client);
+// client->m_proxy_thread->addDefferedTask(&AuditTrailClient::sendReport, client, std::string{"dac"}, std::string{log});
}
-void sysCallLogCallback(const char* log, void* user_data)
+void sysCallLogCallback(audit_trail_syscall_h handle, void* user_data)
{
- assert(log);
- assert(user_data);
+// assert(log);
+// assert(user_data);
- AuditTrailClient* client = reinterpret_cast<AuditTrailClient*>(user_data);
- assert(client);
- client->m_proxy_thread->addDefferedTask(&AuditTrailClient::sendReport, client, std::string{"syscall"}, std::string{log});
+// AuditTrailClient* client = reinterpret_cast<AuditTrailClient*>(user_data);
+// assert(client);
+// client->m_proxy_thread->addDefferedTask(&AuditTrailClient::sendReport, client, std::string{"syscall"}, std::string{log});
}
AuditTrailClient::AuditTrailClient(const std::string& device_id, ProxyThread* proxy_thread,
* @param[in] log
* @param[in] user_data
*/
- friend void macLogCallback(const char* log, void* user_data);
+ friend void macLogCallback(audit_trail_mac_h handle, void* user_data);
/**
* @brief DAC log callback
* @param[in] log
* @param[in] user_data
*/
- friend void dacLogCallback(const char* log, void* user_data);
+ friend void dacLogCallback(audit_trail_dac_h handle, void* user_data);
/**
* @brief System calls log callback
* @param[in] log
* @param[in] user_data
*/
- friend void sysCallLogCallback(const char* log, void* user_data);
+ friend void sysCallLogCallback(audit_trail_syscall_h handle, void* user_data);
public:
/**
../nmdaemon/dpm/*.cpp
../iotivity_lib/src/*.cpp
../ctrl_app_lib/src/*.cpp
- ../mock/*.cpp
+# ../mock/*.cpp
+ ../mock/sd-daemon-stub.cpp
+ ../mock/device-policy-manager.cpp
)
FILE(GLOB NMDAEMON_MAIN ../nmdaemon/main.cpp)
+FILE(GLOB NMDAEMON_MAIN_THREAD ../nmdaemon/main_thread.cpp)
+FILE(GLOB NMDAEMON_ATRAIL_CLIENT ../nmdaemon/audit_trail_client.cpp)
list(REMOVE_ITEM SRCS ${NMDAEMON_MAIN})
+list(REMOVE_ITEM SRCS ${NMDAEMON_MAIN_THREAD})
+list(REMOVE_ITEM SRCS ${NMDAEMON_ATRAIL_CLIENT})
add_executable (${PROJECT_NAME} ${SRCS})
+#if 0
+
#include "audit_trail_client.h"
#include "audit-trail-mock.h"
EXPECT_FALSE(aclient.start_dac_auditing());
EXPECT_FALSE(aclient.start_dac_auditing());
}
+
+#endif
+#if 0
+
#include "audit-trail-stub.h"
#include "audit-trail-mock.h"
EXPECT_EQ(0, impl.audit_trail_is_enabled_syscall(&en));
EXPECT_TRUE(en);
}
+
+#endif