Add user log related APIs 30/172730/5
authorSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 15 Mar 2018 11:54:26 +0000 (20:54 +0900)
committerSungbae Yoo <sungbae.yoo@samsung.com>
Thu, 22 Mar 2018 08:42:05 +0000 (17:42 +0900)
Signed-off-by: Sungbae Yoo <sungbae.yoo@samsung.com>
Change-Id: I2407a82bf6a273bc38cbde7342e8874853050ff5

lib/audit-trail/user-log.cpp
lib/audit-trail/user-log.h
tools/cli/audit-trail-admin-cli.cpp

index 0bf14ad25b21a65c5034840d63cb82669ffa2fde..41df96d81fae05dca29aacf10499537cfedaac7d 100644 (file)
@@ -29,6 +29,53 @@ static inline UserLog& GetUserLog(void* handle)
        return *reinterpret_cast<UserLog*>(handle);
 }
 
+int audit_user_log_get_time(audit_user_log_h handle,
+                                                       time_t *time, unsigned short *ms)
+{
+       RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(time, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(ms, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+
+       const auto &log = GetUserLog(handle).log;
+       *time = log.time.time;
+       *ms = log.time.millisec;
+
+       return AUDIT_TRAIL_ERROR_NONE;
+}
+
+int audit_user_log_get_pid(audit_user_log_h handle, pid_t *pid)
+{
+       RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(pid, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+
+       const auto &log = GetUserLog(handle).log;
+       *pid = log.log.pid;
+
+       return AUDIT_TRAIL_ERROR_NONE;
+}
+
+int audit_user_log_get_type(audit_user_log_h handle, int *type)
+{
+       RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(type, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+
+       const auto &log = GetUserLog(handle).log;
+       *type = log.log.type;
+
+       return AUDIT_TRAIL_ERROR_NONE;
+}
+
+int audit_user_log_get_text(audit_user_log_h handle, const char **text)
+{
+       RET_ON_FAILURE(handle, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+       RET_ON_FAILURE(text, AUDIT_TRAIL_ERROR_INVALID_PARAMETER);
+
+       const auto &log = GetUserLog(handle).log;
+       *text = ::strdup(log.log.text.c_str());
+
+       return AUDIT_TRAIL_ERROR_NONE;
+}
+
 int audit_trail_foreach_user_log(audit_trail_h handle,
                                                        audit_user_log_cb callback, void *user_data)
 {
index 07b5380cf1fd9faa31ac08ede8cafc76036ed884..a70df169855bd2249dcc1d11f4e20268501f4257 100644 (file)
@@ -49,6 +49,65 @@ extern "C" {
  */
 typedef void* audit_user_log_h;
 
+/**
+ * @brief       Get the time of the user audit log
+ * @details     This API can be used to get when the user audit log occured from *              its handle
+ * @since_tizen 5.0
+ * @param[in]   handle The user audit log handle
+ * @param[out]  time The time as UNIX epoch timestamp
+ * @param[out]  ms milliseconds of the time
+ * @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_user_log_get_time(audit_user_log_h handle,
+                                                                                       time_t *time, unsigned short *ms);
+
+/**
+ * @brief       Get the ID of process who sent the user audit log
+ * @details     This API can be used to get a process ID of the user audit log
+ *              from its handle.
+ * @since_tizen 5.0
+ * @param[in]   handle The user audit log handle
+ * @param[out]  type The 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_user_log_get_pid(audit_user_log_h handle, pid_t *pid);
+
+/**
+ * @brief       Get the type number of the user audit log
+ * @details     This API can be used to get a type number of the user audit log
+ *              from its handle.
+ * @since_tizen 5.0
+ * @param[in]   handle The user audit log handle
+ * @param[out]  type The number indicating a log type
+ * @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_user_log_get_type(audit_user_log_h handle, int *type);
+
+/**
+ * @brief       Get the user audit log as a text
+ * @details     This API can be used to get a content of the user audit log
+ *              from its handle. The text should be freed when it is no longer
+ *              required.
+ * @since_tizen 5.0
+ * @param[in]   handle The user audit log handle
+ * @param[out]  text The text content of the log
+ * @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        text should be freed by free()
+ */
+AUDIT_TRAIL_API int audit_user_log_get_text(audit_user_log_h handle, const char **text);
+
 /**
  * @brief       Called to get a audit logs from user processes as an array.
  *              This function is called with user audit log handles, which can
index a5ea207a273ef4a8e3e37789a5df51f37a4c94b4..09c0e7438d3b380c062acdf975939fa4ad2e6f28 100644 (file)
@@ -61,9 +61,31 @@ std::string printUserLog(audit_user_log_h log)
        std::stringstream str;
 
        str << "time={";
+       {
+               time_t time;
+               unsigned short millisec;
+               audit_user_log_get_time(log, &time, &millisec);
+               struct tm *local = localtime(&time);
+
+               str << local->tm_hour << ":" << local->tm_min << ":" << local->tm_sec
+                       << "." << millisec;
+       }
 
        str << "},log={";
+       {
+               const char *text;
+               pid_t pid;
+               int type;
+
+               audit_user_log_get_pid(log, &pid);
+               str << "pid=" << pid;
 
+               audit_user_log_get_type(log, &type);
+               str << ",type=" << type;
+
+               audit_user_log_get_text(log, &text);
+               str << ",text=" << text;
+       }
        str << "}";
 
        return str.str();