SET(INCLUDEDIR ${INCLUDE_INSTALL_DIR})
INCLUDE(FindPkgConfig)
-pkg_check_modules(privacy-guard-client REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util pkgmgr-info libtzplatform-config libpcre)
+pkg_check_modules(privacy-guard-client REQUIRED dlog sqlite3 dbus-1 dbus-glib-1 db-util libtzplatform-config libpcre)
FOREACH(flag ${pkgs_CFLAGS})
SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} ${flag}")
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/privacy-guard-client.pc DESTINATION ${LIB_INSTALL_DIR}/pkgconfig)
INSTALL(FILES ${PRIVACY_GUARD_CLIENT_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/privacy_guard/client)
INSTALL(FILES ${PRIVACY_GUARD_EXTERN_HEADERS} DESTINATION ${INCLUDE_INSTALL_DIR}/privacy_guard)
+
sqlite3* m_sqlHandler;
sqlite3_stmt* m_stmt;
bool m_bDBOpen;
-char m_applicationId[LEN_APPLICATION_ID] = { 0 };
-char m_applicationName[LEN_APPLICATION_NAME] = { 0 };
-char m_applicationVersion[LEN_APPLICATION_VERSION] = { 0 };
-char m_applicationIcon[LEN_APPLICATION_ICON] = { 0 };
-char m_packageId[LEN_PACKAGE_ID] = { 0 };
static PrivacyGuardClient* m_pInstance;
static const std::string INTERFACE_NAME;
* @brief add a list of leak logs to the database
*
* @param[in] userId The ID of the user running the application
+ * @param[in] pId The process ID of the application
* @param[in] destination The host which the data is to be sent to
* @param[in] rawPacket The data packet to be sent
* @param[in] len The length of the packet data in bytes
* @return An error code
* @since Tizen 4.0
*/
-int PgAddLeakLog(const int userId, const char *destination, const void *rawPacket, const size_t len, const std::list<leak_log_insert_data_s> &logList) const;
+int PgAddLeakLog(const int userId, const int pId, const char *destination, const void *rawPacket, const size_t len, const std::list<leak_log_insert_data_s> &logList) const;
/**
* @brief get all logs from leaked packets.
};
#endif // _PRIVACYGUARDCLIENT_H_
+
void*
DlpLogsManager::LeakLogSendThread()
{
+ uid_t pid = getpid();
uid_t uid = getuid();
for (;;) {
// with new entries, try to process them
m_logQueueMutex.lock();
- for (auto &it : m_logQueue) {
+ for (auto it = m_logQueue.begin(); it != m_logQueue.end(); it++) {
+ m_logQueueMutex.unlock();
// if packet has not been parsed yet, parse now
- if (!it.rlist.empty())
- ParseAndLogLeakNow(it);
+ if (!it->rlist.empty())
+ ParseAndLogLeakNow(*it);
- if (!it.llist.empty())
- m_privacyGuardClient->PgAddLeakLog(uid, it.hostname.c_str(), it.mem, it.len, it.llist);
+ if (!it->llist.empty())
+ m_privacyGuardClient->PgAddLeakLog(uid, pid, it->hostname.c_str(), it->mem, it->len, it->llist);
+
+ m_logQueueMutex.lock();
}
// all entries processed, call clear destroying each element from queue
}
return NULL;
}
+
#include <memory>
#include <fcntl.h>
#include <strings.h>
-#include <aul.h>
-#include <pkgmgr-info.h>
#include "Utils.h"
#include "DlpUtils.h"
#include "PrivacyGuardClient.h"
PrivacyGuardClient::PrivacyGuardClient(void):m_sqlHandler(NULL), m_stmt(NULL), m_bDBOpen(false)
{
- loadApplicationInfo();
int res = loadDlpCategories();
if (res != PRIV_GUARD_ERROR_SUCCESS) {
PG_LOGE("fail : loadDlpCategories (%d)", res);
return -1;
}
-void
-PrivacyGuardClient::loadApplicationInfo()
-{
- int ret;
- char *data = NULL;
- pkgmgrinfo_appinfo_h appinfo = NULL;
- pkgmgrinfo_pkginfo_h pkginfo = NULL;
-
- // load application ID
- ret = aul_app_get_appid_bypid(getpid(), m_applicationId, LEN_APPLICATION_ID);
- if (ret == 0) {
- // load application info
- ret = pkgmgrinfo_appinfo_get_usr_appinfo(m_applicationId, getuid(), &appinfo);
- if (ret == 0) {
- // load application name
- ret = pkgmgrinfo_appinfo_get_label(appinfo, &data);
- if (ret == 0)
- pg_strlcpy(m_applicationName, data, LEN_APPLICATION_NAME);
-
- // load package ID
- ret = pkgmgrinfo_appinfo_get_pkgid(appinfo, &data);
- if (ret == 0)
- pg_strlcpy(m_packageId, data, LEN_PACKAGE_ID);
-
- // load application icon
- ret = pkgmgrinfo_appinfo_get_icon(appinfo, &data);
- if (ret == 0)
- pg_strlcpy(m_applicationIcon, data, LEN_APPLICATION_ICON);
-
- // load package info
- ret = pkgmgrinfo_pkginfo_get_pkginfo(m_packageId, &pkginfo);
- if (ret == 0) {
- // load application version
- ret = pkgmgrinfo_pkginfo_get_version(pkginfo, &data);
- if (ret == 0)
- pg_strlcpy(m_applicationVersion, data, LEN_APPLICATION_VERSION);
-
- pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
- }
-
- pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
- }
- }
-}
-
/**
* @callgraph
*/
* @callgraph
*/
int
-PrivacyGuardClient::PgAddLeakLog(const int userId, const char *destination, const void *rawPacket, const size_t len, const std::list<leak_log_insert_data_s> &logList) const
+PrivacyGuardClient::PgAddLeakLog(const int userId, const int pId, const char *destination, const void *rawPacket, const size_t len, const std::list<leak_log_insert_data_s> &logList) const
{
if (destination == NULL || rawPacket == NULL)
return PRIV_GUARD_ERROR_INVALID_PARAMETER;
int res = socketClient.connect();
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
- res = socketClient.call("PgAddLeakLog", userId, (const char *)m_applicationId,
- (const char *)m_applicationName, (const char *)m_applicationVersion,
- (const char *)m_applicationIcon, (const char *)m_packageId,
- destination, packetData, logList, &result);
+ res = socketClient.call("PgAddLeakLog", userId, pId, destination, packetData, logList, &result);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, socketClient.disconnect(), "call : %d", res);
res = socketClient.disconnect();
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "connect : %d", res);
currentRules.clear();
- res = socketClient.call("PgGetDlpCurrentRules", userId, (const char *)m_applicationId,
- pId, &result, ¤tRules);
+ res = socketClient.call("PgGetDlpCurrentRules", userId, pId, &result, ¤tRules);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, socketClient.disconnect(), "call : %d", res);
res = socketClient.disconnect();
}
return result;
}
+
typedef struct _leak_log_insert_common_data_s {
int user_id;
- char application_id[LEN_APPLICATION_ID];
- char application_name[LEN_APPLICATION_NAME];
- char application_version[LEN_APPLICATION_VERSION];
- char application_icon[LEN_APPLICATION_ICON];
- char package_id[LEN_PACKAGE_ID];
+ int pid;
char destination[LEN_DESTINATION];
packet_data_s pkt_data;
} leak_log_insert_common_data_s;
typedef std::list<current_rules_s> current_rules_list;
+typedef struct _privacy_semaphore_app_info_s {
+ char application_id[LEN_APPLICATION_ID];
+ char application_name[LEN_APPLICATION_NAME];
+ char application_version[LEN_APPLICATION_VERSION];
+ char application_icon[LEN_APPLICATION_ICON];
+ char package_id[LEN_PACKAGE_ID];
+} privacy_semaphore_app_info_s;
+
typedef struct _privacy_semaphore_s {
int pid;
sem_t *sem;
+ privacy_semaphore_app_info_s app_info;
} privacy_semaphore_s;
typedef struct _custom_rule_s {
static const std::string DBUS_SIGNAL_PKG_REMOVED("privacy_pkg_removed");
#endif // _PRIVACYGUARDTYPES_H_
+
int res = read(&out.user_id);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "read : %d", res);
- // application ID
- res = read(out.application_id, LEN_APPLICATION_ID);
- TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "read : %d", res);
-
- // application name
- res = read(out.application_name, LEN_APPLICATION_NAME);
- TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "read : %d", res);
-
- // application version
- res = read(out.application_version, LEN_APPLICATION_VERSION);
- TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "read : %d", res);
-
- // application icon
- res = read(out.application_icon, LEN_APPLICATION_ICON);
- TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "read : %d", res);
-
- // package ID
- res = read(out.package_id, LEN_PACKAGE_ID);
+ // pid
+ res = read(&out.pid);
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "read : %d", res);
// destination
};
#endif // _SOCKETCONNECTION_H_
+
/**
* @brief add a new client to list of clients to inform about rule changes
* @param[in] pId The process id of the client to be added
+ * @param[in] userId The user id of the client to be added
*
* @return the result of operation (ERRORCODE : success, ....)
* @since Tizen 3.0
*/
- int addDlpClient(int pId);
+ int addDlpClient(int pId, int userId, char **appId);
+
+ /**
+ * @brief get the application info for the pid
+ * @param[in] pId The process id of the client look of info
+ * @param[out] pId The privacy_semaphore_app_info_s struct related to pid
+ *
+ * @return the result of operation (ERRORCODE : success, ....)
+ * @since Tizen 3.0
+ */
+ int getAppInfo(int pId, privacy_semaphore_app_info_s **app_info);
/**
* @brief send notification to all registered clients that a rule may have changed
};
#endif // _DLP_RULECHANGENOTIFICATION_H_
+
/**
* @brief get the list of current rules
* @param[in] userId The user ID to get the rules for
- * @param[in] AppId The application name (or empty string)
* @param[in] pId The process ID, to be added to the list of rule change notification clients
* @param[out] rules The rules which were retrieved
*
* @return the result of operation (ERRORCODE : success, ....)
* @since Tizen 4.0
*/
- int PgGetDlpCurrentRules(const int userId, const char *AppId, const int pId, std::list<current_rules_s> &rules);
+ int PgGetDlpCurrentRules(const int userId, const int pId, std::list<current_rules_s> &rules);
/**
* @brief retrieve the list of email addresses for the specified user
#endif // _PRIVACY_GUARD_DB_H_
+
#include <sys/types.h>
#include <signal.h>
#include <errno.h>
+#include <aul.h>
+#include <pkgmgr-info.h>
#include "DlpRuleChangeNotification.h"
#include "Utils.h"
}
int
-DlpRuleChangeNotification::addDlpClient(int pId)
+DlpRuleChangeNotification::addDlpClient(int pId, int userId, char **appId)
{
int res = PRIV_GUARD_ERROR_SUCCESS;
bool first_request_by_pid = true;
if (it->pid == pId) {
// Process found, no need to add it to sem list
first_request_by_pid = false;
+ *appId = it->app_info.application_id;
} else {
// Just checking if the process still exists, no signal is sent
if (kill(it->pid, 0) == -1 && errno == ESRCH) {
// First request from process, to add it to sem list
snprintf(sem_name, sizeof(PRIVACY_SEM_INITVAL)+5, PRIVACY_SEM_INITVAL, pId);
privacy_semaphore_s ps;
+ pkgmgrinfo_appinfo_h appinfo = NULL;
+ pkgmgrinfo_pkginfo_h pkginfo = NULL;
+ char *data = NULL;
+
+ // load application ID
+ ps.app_info.application_id[0] = 0;
+ *appId = ps.app_info.application_id;
+ int ret = aul_app_get_appid_bypid(pId, ps.app_info.application_id, LEN_APPLICATION_ID);
+ if (ret == 0) {
+ // load application info
+ ret = pkgmgrinfo_appinfo_get_usr_appinfo(ps.app_info.application_id, userId, &appinfo);
+ if (ret == 0) {
+ // load application name
+ ret = pkgmgrinfo_appinfo_get_label(appinfo, &data);
+ if (ret == 0)
+ pg_strlcpy(ps.app_info.application_name, data, LEN_APPLICATION_NAME);
+
+ // load package ID
+ ret = pkgmgrinfo_appinfo_get_pkgid(appinfo, &data);
+ if (ret == 0)
+ pg_strlcpy(ps.app_info.package_id, data, LEN_PACKAGE_ID);
+
+ // load application icon
+ ret = pkgmgrinfo_appinfo_get_icon(appinfo, &data);
+ if (ret == 0)
+ pg_strlcpy(ps.app_info.application_icon, data, LEN_APPLICATION_ICON);
+
+ // load package info
+ ret = pkgmgrinfo_pkginfo_get_pkginfo(ps.app_info.package_id, &pkginfo);
+ if (ret == 0) {
+ // load application version
+ ret = pkgmgrinfo_pkginfo_get_version(pkginfo, &data);
+ if (ret == 0)
+ pg_strlcpy(ps.app_info.application_version, data, LEN_APPLICATION_VERSION);
+
+ pkgmgrinfo_pkginfo_destroy_pkginfo(pkginfo);
+ }
+
+ pkgmgrinfo_appinfo_destroy_appinfo(appinfo);
+ }
+ }
+
ps.sem = sem_open(sem_name, 0);
if (ps.sem == SEM_FAILED) {
PG_LOGE("errro opening sem: %s - %s", sem_name, strerror_r(errno, buf, sizeof(buf)));
return res;
}
+int
+DlpRuleChangeNotification::getAppInfo(int pId, privacy_semaphore_app_info_s **app_info) {
+ for (auto &it: m_semaphore_list) {
+ if (it.pid == pId) {
+ *app_info = &(it.app_info);
+ return PRIV_GUARD_ERROR_SUCCESS;
+ }
+ }
+ return PRIV_GUARD_ERROR_NO_DATA;
+}
+
int
DlpRuleChangeNotification::notifyDlpClients()
{
return res;
}
+
const char *insertl = "INSERT INTO DlpLeakLog(REQUEST_ID, PATTERN_ID, ACTION, LEAK_OFFSET, LEAK_LEN) "
"VALUES(?, ?, ?, ?, ?)";
+ privacy_semaphore_app_info_s *app_info;
+ if(DlpRuleChangeNotification::getInstance() == NULL || PRIV_GUARD_ERROR_SUCCESS !=
+ DlpRuleChangeNotification::getInstance()->getAppInfo(data.pid, &app_info))
+ return PRIV_GUARD_ERROR_DB_ERROR;
+
m_dbMutex.lock();
// initialize
res = sqlite3_bind_int(m_stmt, 2, time(NULL));
TryCatchResLogReturn(res == SQLITE_OK, sqlite3_finalize(m_stmt); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_int : %d", res);
- res = sqlite3_bind_text(m_stmt, 3, data.application_name, -1, SQLITE_TRANSIENT);
+ res = sqlite3_bind_text(m_stmt, 3, app_info->application_name, -1, SQLITE_TRANSIENT);
TryCatchResLogReturn(res == SQLITE_OK, sqlite3_finalize(m_stmt); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
- res = sqlite3_bind_text(m_stmt, 4, data.application_icon, -1, SQLITE_TRANSIENT);
+ res = sqlite3_bind_text(m_stmt, 4, app_info->application_icon, -1, SQLITE_TRANSIENT);
TryCatchResLogReturn(res == SQLITE_OK, sqlite3_finalize(m_stmt); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
- res = sqlite3_bind_text(m_stmt, 5, data.application_id, -1, SQLITE_TRANSIENT);
+ res = sqlite3_bind_text(m_stmt, 5, app_info->application_id, -1, SQLITE_TRANSIENT);
TryCatchResLogReturn(res == SQLITE_OK, sqlite3_finalize(m_stmt); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
- res = sqlite3_bind_text(m_stmt, 6, data.application_version, -1, SQLITE_TRANSIENT);
+ res = sqlite3_bind_text(m_stmt, 6, app_info->application_version, -1, SQLITE_TRANSIENT);
TryCatchResLogReturn(res == SQLITE_OK, sqlite3_finalize(m_stmt); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
- res = sqlite3_bind_text(m_stmt, 7, data.package_id, -1, SQLITE_TRANSIENT);
+ res = sqlite3_bind_text(m_stmt, 7, app_info->package_id, -1, SQLITE_TRANSIENT);
TryCatchResLogReturn(res == SQLITE_OK, sqlite3_finalize(m_stmt); m_dbMutex.unlock(), PRIV_GUARD_ERROR_DB_ERROR, "sqlite3_bind_text : %d", res);
res = sqlite3_bind_text(m_stmt, 8, data.destination, -1, SQLITE_TRANSIENT);
}
int
-PrivacyGuardDb::PgGetDlpCurrentRules(const int userId, const char *appId, const int pId, std::list<current_rules_s> &rules)
+PrivacyGuardDb::PgGetDlpCurrentRules(const int userId, const int pId, std::list<current_rules_s> &rules)
{
int res = -1;
char query[256];
+ char *appId;
dlp_profile_s profile;
if(DlpRuleChangeNotification::getInstance() != NULL)
- DlpRuleChangeNotification::getInstance()->addDlpClient(pId);
+ DlpRuleChangeNotification::getInstance()->addDlpClient(pId, userId, &appId);
+ else
+ return PRIV_GUARD_ERROR_DB_ERROR;
// get current profile
PgGetDlpProfile(userId, profile);
return m_pInstance;
}
+
PrivacyInfoService::PgGetDlpCurrentRules(SocketConnection* pConnector)
{
int userId = 0;
- char appId[LEN_PACKAGE_ID];
int pId = 0;
std::list<current_rules_s> templateRules;
std::list<current_rules_s> rules;
pConnector->read(&userId);
- pConnector->read(appId, LEN_PACKAGE_ID);
pConnector->read(&pId);
- int result = PrivacyGuardDb::getInstance()->PgGetDlpCurrentRules(userId, appId, pId, templateRules);
+ int result = PrivacyGuardDb::getInstance()->PgGetDlpCurrentRules(userId, pId, templateRules);
// replace all rule templates
if (result == PRIV_GUARD_ERROR_SUCCESS)
pConnector->write(result, categories);
}
+