#define PRIVACY_DB_PATH tzplatform_mkpath(TZ_SYS_DB,".privacy_guard.db")
//#define CYNARA_BUFFER_SIZE 1024
-#define CYNARA_BUFFER_SIZE 10
+#define CYNARA_BUFFER_SIZE 100
typedef struct _privacy_data_s {
char *privacy_id;
for (k = privilege_list; k != NULL; k = k->next) {
char *privilege_id = (char*)k->data;
- PG_LOGD("(privacy, privilege): (%s, %s)", privacy_id, privilege_id);
+ //PG_LOGD("(privacy, privilege): (%s, %s)", privacy_id, privilege_id);
m_privilegeToPrivacyMap.insert(std::map< std::string, std::string >::value_type(std::string(privilege_id), std::string(privacy_id)));
}
}
static cynara_monitor_configuration *p_conf;
static cynara_monitor *p_cynara_monitor;
static cynara_monitor_entry **monitor_entries;
+static bool exit_flag;
CynaraService::CynaraService(void)
: m_signalToClose(-1)
TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "pthread_sigmask : %s", strerror_r(errno, buf, sizeof(buf)));
pthread_t cynaraThread;
+ PG_LOGD("starting new thread (getEntriesThread)");
res = pthread_create(&cynaraThread, NULL, &getEntriesThread, this);
TryReturn( res >= 0, PRIV_GUARD_ERROR_SYSTEM_ERROR, errno = res, "pthread_create : %s", strerror_r(errno, buf, sizeof(buf)));
+ PG_LOGD("new thread (getEntriesThread) started");
m_cynaraThread = cynaraThread;
- PG_LOGI("CynaraService started");
+ exit_flag = false;
+
+ PG_LOGD("CynaraService started");
return PRIV_GUARD_ERROR_SUCCESS;
}
void*
CynaraService::getEntriesThread(void* pData)
{
- pthread_detach(pthread_self());
PG_LOGD("[cynara_service] Running get entries thread");
-// pthread_t testThread;
-// int result = pthread_create(&testThread, NULL, &flushThread, NULL);
-// if(result){
-// PG_LOGE("pthread_create FAIL");
-// return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
-// }
+ int res = -1;
+ pthread_detach(pthread_self());
- // cynara_monitor_entries_get
- // returned when the cynara buffer is full or cynara_monitor_entries_flush() is called from another thread
- int res = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
- if(res != CYNARA_API_SUCCESS){
- PG_LOGE("cynara_monitor_entries_get FAIL");
- return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
- }
+ while (exit_flag == false) {
+ PG_LOGD("[cynara_service] waiting for monitor entries");
- res = CynaraService::updateDb(monitor_entries);
- if(res != PRIV_GUARD_ERROR_SUCCESS){
- PG_LOGE("updateDb FAIL");
- return (void*) res;
- }
+ // cynara_monitor_entries_get
+ // returned when the cynara buffer is full or cynara_monitor_entries_flush() is called from another thread
+ res = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
+ if(res != CYNARA_API_SUCCESS){
+ PG_LOGE("cynara_monitor_entries_get() is failed. [%d]", res);
+ return (void*) PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
+
+ res = CynaraService::updateDb(monitor_entries);
+ if(res != PRIV_GUARD_ERROR_SUCCESS){
+ PG_LOGE("updateDb FAIL");
+ return (void*) res;
+ }
-// pthread_join(testThread, NULL);
+ // pthread_join(testThread, NULL);
+
+ cynara_monitor_entries_free(monitor_entries);
+ }
cynara_monitor_entries_free(monitor_entries);
- return (void*) 0;
+ return (void*) PRIV_GUARD_ERROR_SUCCESS;
}
/*void*
int
CynaraService::updateDb(cynara_monitor_entry **monitor_entries)
{
- PG_LOGD("[cynara_service]");
+ PG_LOGD("[cynara_service] updateDb called");
cynara_monitor_entry **entryIter = monitor_entries;
- PG_LOGD("entryIter = %x", entryIter);
+ //PG_LOGD("entryIter = %x", entryIter);
// DB update
const char *user = NULL, *client = NULL, *privilege = NULL;
while (*entryIter != nullptr) {
user = cynara_monitor_entry_get_user(*entryIter);
TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "User Id in the entry is NULL");
+ PG_LOGD("@@ userid: [%s]", user);
client = cynara_monitor_entry_get_client(*entryIter);
TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Package Id in the entry is NULL");
+ PG_LOGD("@@ client: [%s]", client);
privilege = cynara_monitor_entry_get_privilege(*entryIter);
TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "Privilege Id in the entry is NULL");
+ PG_LOGD("@@ privilege: [%s]", privilege);
timestamp = cynara_monitor_entry_get_timestamp(*entryIter);
TryReturn(user != NULL, PRIV_GUARD_ERROR_SYSTEM_ERROR, , "timestamp in the entry is NULL");
userId = atoi(user);
- packageId = client;
+ PG_LOGD("## userId: [%d]", userId);
+ std::string tempPackageId = client;
+ if (tempPackageId.substr(0, 11).compare("User::App::") == 0) {
+ packageId = tempPackageId.substr(11, tempPackageId.length() - 11);
+ } else {
+ packageId = client;
+ }
+ PG_LOGD("## packageId: [%s]", packageId.c_str());
privilegeId = privilege;
+ PG_LOGD("## privilegeId: [%s]", privilegeId.c_str());
date = timestamp->tv_sec;
// add access log
char buf[BUF_SIZE];
int ret;
+ // set thread exit condition
+ exit_flag = true;
+
+ // [CYNARA] Fluch Entries
+ ret = cynara_monitor_entries_flush(p_cynara_monitor);
+ if(ret != CYNARA_API_SUCCESS){
+ if (ret == CYNARA_API_OPERATION_NOT_ALLOWED) {
+ PG_LOGD("There is no logs in the cynara buffer.");
+ } else {
+ PG_LOGE("cynara_monitor_entries_flush FAIL [%d]", ret);
+ return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
+ }
+
if((ret = pthread_kill(m_cynaraThread, m_signalToClose)) < 0)
{
//errno = ret;
}
// [CYNARA]
-/* PG_LOGD("calling pCynaraService->start()");
+ PG_LOGD("calling pCynaraService->start()");
if (pCynaraService == NULL)
return PRIV_GUARD_ERROR_NOT_INITIALIZED;
res = pCynaraService->start();
if(res != PRIV_GUARD_ERROR_SUCCESS){
PG_LOGE("FAIL");
}
-*/
+
return res;
}
int
PrivacyGuardDb::PgAddPrivacyAccessLogForCynara(const int userId, const std::string packageId, const std::string privilegeId, const time_t date)
{
+ PG_LOGD("start.");
+
if(userId < 0 || date <= 0) {
PG_LOGE("Invalid parameter: userId: [%d], date: [%d]", userId, date);
return PRIV_GUARD_ERROR_INVALID_PARAMETER;
int res = -1;
std::string privacyId;
+ PG_LOGD("getting privacy id from privilege [%s]", privilegeId.c_str());
+
// change from privilege to privacy
res = PrivacyIdInfo::getPrivacyIdFromPrivilege(privilegeId, privacyId);
if (res == PRIV_GUARD_ERROR_NO_DATA) {
}
TryReturn(res == PRIV_GUARD_ERROR_SUCCESS, res, , "getPrivacyIdFromPrivilege is failed: [%d]", res);
+ PG_LOGD("getting monitor policy");
+
// check monitor policy using userId, packageId, privacyId
int monitorPolicy;
res = PgGetMonitorPolicy(userId, packageId, privacyId, monitorPolicy);
return PRIV_GUARD_ERROR_SUCCESS;
}
+ PG_LOGD("## UserID[%d], PackageId[%s], PrivacyId[%s], Policy[%d]", userId, packageId.c_str(), privacyId.c_str(), monitorPolicy);
+
static const std::string QUERY_INSERT = std::string("INSERT INTO StatisticsMonitorInfo(USER_ID, PKG_ID, PRIVACY_ID, USE_DATE) VALUES(?, ?, ?, ?)");
m_dbMutex.lock();
int res = -1;
// [CYNARA] Fluch Entries
- int ret= cynara_monitor_entries_flush(p_cynara_monitor);
- if(ret != CYNARA_API_SUCCESS){
- PG_LOGE("cynara_monitor_entries_flush FAIL");
- return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ res = cynara_monitor_entries_flush(p_cynara_monitor);
+ if(res != CYNARA_API_SUCCESS){
+ if (res == CYNARA_API_OPERATION_NOT_ALLOWED) {
+ PG_LOGD("There is no logs in the cynara buffer.");
+ } else {
+ PG_LOGE("cynara_monitor_entries_flush FAIL [%d]", res);
+ return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
}
+
/* // [CYNARA] Get Entries
ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
if(ret != CYNARA_API_SUCCESS){
int res = -1;
// [CYNARA] Fluch Entries
- int ret= cynara_monitor_entries_flush(p_cynara_monitor);
- if(ret != CYNARA_API_SUCCESS){
- PG_LOGE("cynara_monitor_entries_flush FAIL");
- return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ res = cynara_monitor_entries_flush(p_cynara_monitor);
+ if(res != CYNARA_API_SUCCESS){
+ if (res == CYNARA_API_OPERATION_NOT_ALLOWED) {
+ PG_LOGD("There is no logs in the cynara buffer.");
+ } else {
+ PG_LOGE("cynara_monitor_entries_flush FAIL [%d]", res);
+ return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
}
+
/* // [CYNARA] Get Entries
ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
if(ret != CYNARA_API_SUCCESS){
int res = -1;
// [CYNARA] Fluch Entries
- int ret= cynara_monitor_entries_flush(p_cynara_monitor);
- if(ret != CYNARA_API_SUCCESS){
- PG_LOGE("cynara_monitor_entries_flush FAIL");
- return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ res = cynara_monitor_entries_flush(p_cynara_monitor);
+ if(res != CYNARA_API_SUCCESS){
+ if (res == CYNARA_API_OPERATION_NOT_ALLOWED) {
+ PG_LOGD("There is no logs in the cynara buffer.");
+ } else {
+ PG_LOGE("cynara_monitor_entries_flush FAIL [%d]", res);
+ return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
}
+
/* // [CYNARA] Get Entries
ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
if(ret != CYNARA_API_SUCCESS){
int res = -1;
// [CYNARA] Fluch Entries
- int ret= cynara_monitor_entries_flush(p_cynara_monitor);
- if(ret != CYNARA_API_SUCCESS){
- PG_LOGE("cynara_monitor_entries_flush FAIL");
- return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ res = cynara_monitor_entries_flush(p_cynara_monitor);
+ if(res != CYNARA_API_SUCCESS){
+ if (res == CYNARA_API_OPERATION_NOT_ALLOWED) {
+ PG_LOGD("There is no logs in the cynara buffer.");
+ } else {
+ PG_LOGE("cynara_monitor_entries_flush FAIL [%d]", res);
+ return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
}
+
/* // [CYNARA] Get Entries
ret = cynara_monitor_entries_get(p_cynara_monitor, &monitor_entries);
if(ret != CYNARA_API_SUCCESS){
date = localtime(&start_date);
PG_LOGD("start time [%d]: %4d/%2d/%2d %2d:%2d", start_date, date->tm_year + 1900, date->tm_mon + 1, date->tm_mday, date->tm_hour, date->tm_min);
+ // [CYNARA] Fluch Entries
+ res = cynara_monitor_entries_flush(p_cynara_monitor);
+ if(res != CYNARA_API_SUCCESS){
+ if (res == CYNARA_API_OPERATION_NOT_ALLOWED) {
+ PG_LOGD("There is no logs in the cynara buffer.");
+ } else {
+ PG_LOGE("cynara_monitor_entries_flush FAIL [%d]", res);
+ return PRIV_GUARD_ERROR_SYSTEM_ERROR;
+ }
+ }
+
m_dbMutex.lock();
// initialize
, m_signalToClose(-1)
, m_mainThread(-1)
{
- PG_LOGD("SocketService() called.");
+ //PG_LOGD("SocketService() called.");
}
SocketService::~SocketService(void)
{
- PG_LOGD("~SocketService() called.");
+ //PG_LOGD("~SocketService() called.");
}
int
SocketService::initialize(void)
{
- PG_LOGD("SocketService initializing");
+ //PG_LOGD("SocketService initializing");
char buf[BUF_SIZE];
m_listenFd = socket(AF_UNIX, SOCK_STREAM, 0);
umask(original_umask);
- PG_LOGI("SocketService initialized");
+ //PG_LOGI("SocketService initialized");
return PRIV_GUARD_ERROR_SUCCESS;
}
int
SocketService::start(void)
{
- PG_LOGI("SocketService starting");
+ //PG_LOGI("SocketService starting");
sigset_t sigset;
sigemptyset(&sigset);
m_mainThread = mainThread;
- PG_LOGI("SocketService started");
+ //PG_LOGI("SocketService started");
return PRIV_GUARD_ERROR_SUCCESS;
}
void*
SocketService::serverThread(void* pData)
{
- PG_LOGD("serverThread() called.");
+ //PG_LOGD("serverThread() called.");
pthread_detach(pthread_self());
SocketService &t = *static_cast< SocketService* > (pData);
- PG_LOGD("Running main thread");
+ //PG_LOGD("Running main thread");
int ret = t.mainloop();
if (ret < 0) {
return (void*) 1;
int
SocketService::mainloop(void)
{
- PG_LOGD("mainloop() called.");
+ //PG_LOGD("mainloop() called.");
char buf[BUF_SIZE];
void*
SocketService::connectionThread(void* pData)
{
- PG_LOGD("connectionThread() called.");
+ //PG_LOGD("connectionThread() called.");
pthread_detach(pthread_self());
std::unique_ptr<ConnectionInfo> connectionInfo (static_cast<ConnectionInfo *>(pData));
SocketService &t = *static_cast<SocketService *>(connectionInfo->pData);
- PG_LOGI("Starting connection thread");
+ //PG_LOGI("Starting connection thread");
int ret = t.connectionService(connectionInfo->connFd);
if (ret < 0)
{
close(connectionInfo->connFd);
return (void*)1;
}
- PG_LOGI("Client serviced");
+ //PG_LOGI("Client serviced");
return (void*)0;
}
int
SocketService::connectionService(int fd)
{
- PG_LOGD("connectionService() called.");
+ //PG_LOGD("connectionService() called.");
SocketConnection connector = SocketConnection(fd);
std::string interfaceName, methodName;
// }
// }
- PG_LOGI("Calling service");
+ //PG_LOGI("Calling service");
m_callbackMap[interfaceName][methodName]->serviceCallback(&connector);
- PG_LOGI("Removing client");
+ //PG_LOGI("Removing client");
removeClientSocket(fd);
close(fd);
- PG_LOGI("Call served");
+ //PG_LOGI("Call served");
return PRIV_GUARD_ERROR_SUCCESS;
}
int
SocketService::stop(void)
{
- PG_LOGD("Stopping");
+ //PG_LOGD("Stopping");
char buf[BUF_SIZE];
}
pthread_join(m_mainThread, NULL);
- PG_LOGD("Stopped");
+ //PG_LOGD("Stopped");
return PRIV_GUARD_ERROR_SUCCESS;
}
int
SocketService::shutdown(void)
{
- PG_LOGD("called");
+ //PG_LOGD("called");
return PRIV_GUARD_ERROR_SUCCESS;
}
int
SocketService::registerServiceCallback(const std::string &interfaceName, const std::string &methodName, socketServiceCallback callbackMethod)
{
- PG_LOGD("called");
+ //PG_LOGD("called");
if(NULL == callbackMethod)
{
void
SocketService::addClientSocket(int clientSocket)
{
- PG_LOGD("called");
+ //PG_LOGD("called");
std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
m_clientSocketList.push_back(clientSocket);
void
SocketService::removeClientSocket(int clientSocket)
{
- PG_LOGD("called");
+ //PG_LOGD("called");
std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
m_clientSocketList.remove(clientSocket);
bool
SocketService::popClientSocket(int * pClientSocket)
{
- PG_LOGD("called");
+ //PG_LOGD("called");
std::lock_guard<std::mutex> guard(m_clientSocketListMutex);
if(m_clientSocketList.empty())
void
SocketService::closeConnections(void)
{
- PG_LOGD("called");
+ //PG_LOGD("called");
int clientSocket;
char buf[BUF_SIZE];
}
}
- PG_LOGD("Connections closed");
+ //PG_LOGD("Connections closed");
}