Add better debug logs to libprivilege-control
authorLukasz Kostyra <l.kostyra@partner.samsung.com>
Thu, 18 Jul 2013 07:33:14 +0000 (09:33 +0200)
committerRafal Krypa <r.krypa@samsung.com>
Mon, 19 Aug 2013 12:13:59 +0000 (14:13 +0200)
[Issue#]        SSDWSSP-406
[Feature]       Adds debug logs which log additional useful informations in libprivilege-control. Create additional defines for SECURE_SLOG*
                logs to allow disabling specific types of SECURE logs.
[Cause]         Many functions in libprivilege-control didn't log useful information - input parameters, files used or switch branches taken.
[Solution]      Add macros which log such information. Additional defines wrapping SECURE_SLOG* log macros are now defined as SECURE_C_LOG*.
[Verification]  Run libprivilege-control-test from security-tests package and check using dlogutil whether functions log their input
                parameters, files used and switch branches taken. Make sure to enable definition DLOG_DEBUG_ENABLED in CMakeLists.txt
                before building the package.

Change-Id: Ifec47d04b7a5aef806caab85fe3709e36aae8afe

include/common.h
src/access-db.c
src/common.c
src/privilege-control.c
src/slp-su.c

index a0a8a76..5c88e65 100644 (file)
 // conditional log macro for dlogutil (debug)
 #ifdef DLOG_DEBUG_ENABLED
 #define C_LOGD(...) SLOGD(__VA_ARGS__)
+#define SECURE_C_LOGD(...) SECURE_SLOGD(__VA_ARGS__)
 #else
 #define C_LOGD(...) do { } while(0)
+#define SECURE_C_LOGD(...) do { } while(0)
 #endif //DDLOG_DEBUG_ENABLED
 
 // conditional log macro for dlogutil (warning)
 #ifdef DLOG_WARN_ENABLED
 #define C_LOGW(...) SLOGW(__VA_ARGS__)
+#define SECURE_C_LOGW(...) SECURE_SLOGW(__VA_ARGS__)
 #else
 #define C_LOGW(...) do { } while(0)
+#define SECURE_C_LOGW(...) do { } while(0)
 #endif //DLOG_WARN_ENABLED
 
 // conditional log macro for dlogutil (error)
 #ifdef DLOG_ERROR_ENABLED
 #define C_LOGE(...) SLOGE(__VA_ARGS__)
+#define SECURE_C_LOGE(...) SECURE_SLOGE(__VA_ARGS__)
 #else
 #define C_LOGE(...) do { } while(0)
+#define SECURE_C_LOGE(...) do { } while(0)
 #endif //DLOG_ERROR_ENABLED
 
 /* for SECURE_LOG* purpose */
index ec6c2a4..3bc26a5 100644 (file)
@@ -58,7 +58,8 @@ typedef struct element_s {
 
 static element_t* add_element (element_t* elem, const char* value)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: value=%s",
+                               __func__, value);
 
        if (NULL == elem)
                return NULL;
@@ -83,7 +84,7 @@ static element_t* add_element (element_t* elem, const char* value)
 
 static int remove_list(element_t* first_elem)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s.", __func__);
 
        element_t* current = NULL;
 
@@ -99,18 +100,21 @@ static int remove_list(element_t* first_elem)
 
 static int add_id_to_database_internal(const char * id, db_app_type_t app_type)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: id=%s",
+                               __func__, id);
+
        FILE* file_db AUTO_FCLOSE;
        const char* db_file_name = db_file_names[app_type];
 
+       SECURE_C_LOGD("Opening database file %s.", db_file_name);
        file_db = fopen(db_file_name, "a");
        if (NULL == file_db) {
-               SECURE_SLOGE("Error while opening database file: %s", db_file_name);
+               SECURE_C_LOGE("Error while opening database file: %s", db_file_name);
                return PC_ERR_FILE_OPERATION;
        }
 
        if (0 > fprintf(file_db, "%s\n", id)) {
-               SECURE_SLOGE("Write label %s to database failed: %s", id, strerror(errno));
+               SECURE_C_LOGE("Write label %s to database failed (error: %s)", id, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -119,15 +123,18 @@ static int add_id_to_database_internal(const char * id, db_app_type_t app_type)
 
 static int get_all_ids_internal (char *** ids, int * len, db_app_type_t app_type)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        int ret;
        FILE* file_db AUTO_FCLOSE;
        const char* db_file_name = db_file_names[app_type];
        char smack_label[SMACK_LABEL_LEN + 1];
        element_t* begin_of_list = NULL;
 
+       SECURE_C_LOGD("Opening database file %s.", db_file_name);
        file_db = fopen(db_file_name, "r");
        if (NULL == file_db) {
-               SECURE_SLOGE("Error while opening database file: %s", db_file_name);
+               SECURE_C_LOGE("Error while opening database file: %s", db_file_name);
                ret = PC_ERR_FILE_OPERATION;
                goto out;
        }
@@ -149,15 +156,15 @@ static int get_all_ids_internal (char *** ids, int * len, db_app_type_t app_type
        while (fscanf(file_db, "%" TOSTRING(SMACK_LABEL_LEN) "s\n", smack_label) == 1) {
                smack_label[SMACK_LABEL_LEN] = '\0';
                if (!smack_label_is_valid(smack_label)) {
-                       C_LOGD("Found entry in database, but it's not correct SMACK label: \"%s\"", smack_label);
+                       SECURE_C_LOGD("Found entry in database, but it's not correct SMACK label: \"%s\"", smack_label);
                        continue;
                }
-               C_LOGD("Found installed label: \"%s\"", smack_label);
+               SECURE_C_LOGD("Found installed label: \"%s\"", smack_label);
                ++(*len);
                current = add_element(current, smack_label);
                if (NULL == current) {
                        *len = 0;
-                       C_LOGE("Error while adding smack label to the list");
+                       C_LOGE("Error while adding smack label to the list.");
                        ret = PC_ERR_MEM_OPERATION;
                        goto out;
                }
@@ -168,7 +175,7 @@ static int get_all_ids_internal (char *** ids, int * len, db_app_type_t app_type
                *ids = malloc((*len) * sizeof(char*));
                if (NULL == *ids) {
                        *len = 0;
-                       C_LOGE("Error while allocating memory for list of labels");
+                       C_LOGE("Error while allocating memory for list of labels.");
                        ret = PC_ERR_MEM_OPERATION;
                        goto out;
                }
@@ -209,6 +216,8 @@ out:
 
 int get_all_apps_ids (char *** apps_ids, int * len)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        if (get_all_ids_internal(apps_ids, len, DB_APP_TYPE_APPLICATION))
                return PC_ERR_DB_OPERATION;
 
@@ -217,6 +226,8 @@ int get_all_apps_ids (char *** apps_ids, int * len)
 
 int get_all_settings_dir_ids(char ***apps_ids, int *len)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        if (get_all_ids_internal(apps_ids, len, DB_APP_TYPE_SETTING_DIR))
                return PC_ERR_DB_OPERATION;
 
@@ -225,6 +236,8 @@ int get_all_settings_dir_ids(char ***apps_ids, int *len)
 
 int get_all_appsetting_ids(char ***apps_ids, int *len)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        if (get_all_ids_internal(apps_ids, len, DB_APP_TYPE_APPSETTING))
                return PC_ERR_DB_OPERATION;
 
@@ -233,6 +246,8 @@ int get_all_appsetting_ids(char ***apps_ids, int *len)
 
 int get_all_avs_ids (char *** av_ids, int * len)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        if (get_all_ids_internal(av_ids, len, DB_APP_TYPE_ANTIVIRUS))
                return PC_ERR_DB_OPERATION;
 
@@ -241,7 +256,8 @@ int get_all_avs_ids (char *** av_ids, int * len)
 
 int add_app_id_to_databse(const char * app_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
 
        if (add_id_to_database_internal(app_id, DB_APP_TYPE_APPLICATION))
                return PC_ERR_DB_OPERATION;
@@ -251,7 +267,8 @@ int add_app_id_to_databse(const char * app_id)
 
 int add_av_id_to_databse (const char * av_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: av_id=%s",
+                               __func__, av_id);
 
        if (add_id_to_database_internal(av_id, DB_APP_TYPE_ANTIVIRUS))
                return PC_ERR_DB_OPERATION;
@@ -261,7 +278,8 @@ int add_av_id_to_databse (const char * av_id)
 
 int add_appsetting_id_to_databse(const char *appsetting_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: appsetting_id=%s",
+                               __func__, appsetting_id);
 
        if (add_id_to_database_internal(appsetting_id, DB_APP_TYPE_APPSETTING))
                return PC_ERR_DB_OPERATION;
@@ -271,7 +289,8 @@ int add_appsetting_id_to_databse(const char *appsetting_id)
 
 int add_setting_dir_id_to_databse(const char *setting_dir_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: setting_dir_id=%s",
+                               __func__, setting_dir_id);
 
        if (add_id_to_database_internal(
                        setting_dir_id, DB_APP_TYPE_SETTING_DIR))
@@ -282,13 +301,18 @@ int add_setting_dir_id_to_databse(const char *setting_dir_id)
 
 int add_app_gid(const char *app_id, unsigned gid)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s, gid=%u",
+                               __func__, app_id, gid);
+
        char *field = NULL;
        int ret;
 
        ret = asprintf(&field, "%u:%s", gid, app_id);
        if (ret == -1)
+       {
+               C_LOGE("asprintf failed.");
                return PC_ERR_MEM_OPERATION;
+       }
 
        ret = add_id_to_database_internal(field, DB_APP_TYPE_GROUPS);
        free(field);
@@ -298,12 +322,18 @@ int add_app_gid(const char *app_id, unsigned gid)
 
 int get_app_gids(const char *app_id, unsigned **gids, int *len)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        char** fields AUTO_FREE;
        int len_tmp, ret, i;
 
        ret = get_all_ids_internal(&fields, &len_tmp, DB_APP_TYPE_GROUPS);
        if (ret != PC_OPERATION_SUCCESS)
+       {
+               C_LOGE("get_all_ids_internal failed.");
                return ret;
+       }
 
        *len = 0;
        *gids = NULL;
@@ -327,7 +357,7 @@ int get_app_gids(const char *app_id, unsigned **gids, int *len)
                }
 
                if (!app_id_tmp) {
-                       C_LOGE("No group id found");
+                       C_LOGE("No group id found.");
                        ret = PC_ERR_FILE_OPERATION;
                        goto out;
                }
@@ -340,7 +370,7 @@ int get_app_gids(const char *app_id, unsigned **gids, int *len)
                if (!strcmp(app_id, app_id_tmp)) {
                        unsigned *gids_realloc = realloc(*gids, sizeof(unsigned) * (*len + 1));
                        if (gids_realloc == NULL) {
-                               C_LOGE("Memory allocation failed");
+                               C_LOGE("Memory allocation failed.");
                                ret = PC_ERR_MEM_OPERATION;
                                goto out;
                        }
@@ -364,20 +394,27 @@ out:
 
 int db_add_public_dir(const char *dir_label)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: dir_label=%s",
+                               __func__, dir_label);
 
        if (add_id_to_database_internal(dir_label, DB_APP_TYPE_PUBLIC_DIRS))
+       {
+               C_LOGE("add_id_to_database_internal failed.");
                return PC_ERR_DB_OPERATION;
+       }
 
        return PC_OPERATION_SUCCESS;
 }
 
 int db_get_public_dirs(char ***dir_labels, int *len)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s.", __func__);
 
        if (get_all_ids_internal(dir_labels, len, DB_APP_TYPE_PUBLIC_DIRS))
+       {
+               C_LOGE("get_all_ids_internal failed.");
                return PC_ERR_DB_OPERATION;
+       }
 
        return PC_OPERATION_SUCCESS;
 }
index 1d18ca0..2478ad4 100644 (file)
@@ -34,7 +34,9 @@
 /* TODO: implement such function in libsmack instead */
 int smack_label_is_valid(const char* smack_label)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: smack_label=%s",
+                               __func__, smack_label);
+
        int i;
 
        if (!smack_label || smack_label[0] == '\0' || smack_label[0] == '-')
@@ -42,7 +44,7 @@ int smack_label_is_valid(const char* smack_label)
 
        for (i = 0; smack_label[i]; ++i) {
                if (i >= SMACK_LABEL_LEN)
-                       return 0;
+                       goto err;
                switch (smack_label[i]) {
                case '~':
                case ' ':
@@ -58,7 +60,7 @@ int smack_label_is_valid(const char* smack_label)
 
        return 1;
 err:
-       C_LOGD("Invalid Smack label: %s", smack_label);
+       SECURE_C_LOGE("Invalid SMACK label %s", smack_label);
        return 0;
 }
 
@@ -102,7 +104,8 @@ void fts_closep(FTS **f)
  */
 int check_if_rules_were_loaded(const char *app_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
        int ret;
        char *path AUTO_FREE;
 
@@ -120,29 +123,35 @@ int check_if_rules_were_loaded(const char *app_id)
  */
 void mark_rules_as_loaded(const char *app_id)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        struct stat s;
        char *path AUTO_FREE;
        FILE *file = NULL;
 
        if(smack_mark_file_name(app_id, &path)) {
-               C_LOGE("Error in smack_mark_file_name");
+               C_LOGE("smack_mark_file_name failed.");
                return;
        }
 
        if (-1 == stat(SMACK_LOADED_APP_RULES, &s)) {
                if (ENOENT == errno) {
-                       C_LOGD("Creating dir %s", SMACK_LOADED_APP_RULES);
+                       C_LOGD("Creating dir %s.", SMACK_LOADED_APP_RULES);
                        mkdir(SMACK_LOADED_APP_RULES, S_IRWXU | S_IRWXG | S_IRWXO);
                }
        }
 
+       SECURE_C_LOGD("Creating file %s.", path);
        file = fopen(path, "w");
        fclose(file);
 }
 
 int add_app_first_run_rules(const char *app_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        int ret;
        int fd AUTO_CLOSE;
        char *smack_path AUTO_FREE;
@@ -154,7 +163,7 @@ int add_app_first_run_rules(const char *app_id)
                return ret;
        }
        if (have_smack() && smack_accesses_apply(smack)) {
-               C_LOGE("smack_accesses_apply failed");
+               C_LOGE("smack_accesses_apply failed.");
                return PC_ERR_INVALID_OPERATION;
        }
 
@@ -168,13 +177,15 @@ static int load_smack_from_file_generic(const char* app_id, struct smack_accesse
         * It's because all of the "early rules" (for all apps) should
         * be in one common file: SMACK_STARTUP_RULES_FILE
         */
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        int ret;
 
        if (is_early) {
                if (0 > asprintf(path, "%s", SMACK_STARTUP_RULES_FILE)) {
                        *path = NULL;
-                       C_LOGE("asprintf failed");
+                       C_LOGE("asprintf failed.");
                        return PC_ERR_MEM_OPERATION;
                }
        }
@@ -185,13 +196,13 @@ static int load_smack_from_file_generic(const char* app_id, struct smack_accesse
        }
 
        if (smack_accesses_new(smack)) {
-               C_LOGE("smack_accesses_new failed");
+               C_LOGE("smack_accesses_new failed.");
                return PC_ERR_MEM_OPERATION;
        }
 
        *fd = open(*path, O_CREAT|O_RDWR, 0644);
        if (*fd == -1) {
-               C_LOGE("file open failed: %s", strerror(errno));
+               C_LOGE("file open failed (error: %s)", strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -201,13 +212,13 @@ static int load_smack_from_file_generic(const char* app_id, struct smack_accesse
        }
 
        if (smack_accesses_add_from_file(*smack, *fd)) {
-               C_LOGE("smack_accesses_add_from_file failed");
+               C_LOGE("smack_accesses_add_from_file failed.");
                return PC_ERR_INVALID_OPERATION;
        }
 
        /* Rewind the file */
        if (lseek(*fd, 0, SEEK_SET) == -1) {
-               C_LOGE("lseek failed");
+               C_LOGE("lseek failed.");
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -216,18 +227,27 @@ static int load_smack_from_file_generic(const char* app_id, struct smack_accesse
 
 int load_smack_from_file(const char* app_id, struct smack_accesses** smack, int *fd, char** path)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        return load_smack_from_file_generic(app_id, smack, fd, path, 0);
 }
 
 int load_smack_from_file_early(const char* app_id, struct smack_accesses** smack, int *fd, char** path)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        return load_smack_from_file_generic(app_id, smack, fd, path, 1);
 }
 
 int smack_mark_file_name(const char *app_id, char **path)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        if (asprintf(path, SMACK_LOADED_APP_RULES "/%s", app_id) == -1) {
-               C_LOGE("asprintf failed");
+               C_LOGE("asprintf failed.");
                *path = NULL;
                return PC_ERR_MEM_OPERATION;
        }
@@ -236,6 +256,10 @@ int smack_mark_file_name(const char *app_id, char **path)
 }
 
 bool file_exists(const char* path) {
+       SECURE_C_LOGD("Entering function: %s. Params: path=%s",
+                               __func__, path);
+
+       SECURE_C_LOGD("Opening file %s.", path);
        FILE* file = fopen(path, "r");
        if (file) {
                fclose(file);
@@ -246,8 +270,11 @@ bool file_exists(const char* path) {
 
 int smack_file_name(const char* app_id, char** path)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        if (asprintf(path, SMACK_RULES_DIR "/%s", app_id) == -1) {
-               C_LOGE("asprintf failed");
+               C_LOGE("asprintf failed.");
                *path = NULL;
                return PC_ERR_MEM_OPERATION;
        }
@@ -257,11 +284,13 @@ int smack_file_name(const char* app_id, char** path)
 
 inline int have_smack(void)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        static int have_smack = -1;
 
        if (-1 == have_smack) {
                if (NULL == smack_smackfs_path()) {
-                       C_LOGD("Libprivilage-control: no smack found on phone");
+                       C_LOGD("Libprivilege-control: no smack found on phone");
                        have_smack = 0;
                } else {
                        C_LOGD("Libprivilege-control: found smack on phone");
index 8486250..a34e046 100644 (file)
@@ -97,14 +97,17 @@ enum {
 
 API int control_privilege(void)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        if(getuid() == APP_UID) // current user is 'app'
                return PC_OPERATION_SUCCESS;
 
        if(perm_app_set_privilege("org.tizen.", NULL, NULL) == PC_OPERATION_SUCCESS)
                return PC_OPERATION_SUCCESS;
-       else
+       else {
+               C_LOGE("perm_app_set_privilege failed (not permitted).");
                return PC_ERR_NOT_PERMITTED;
+       }
 }
 
 /**
@@ -112,13 +115,15 @@ API int control_privilege(void)//deprecated
  */
 API int get_smack_label_from_process(pid_t pid, char smack_label[SMACK_LABEL_LEN + 1])
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pid=%i", __func__, pid);
+
        int ret;
        int fd AUTO_CLOSE;
        int PATH_MAX_LEN = 64;
        char path[PATH_MAX_LEN + 1];
 
        if (pid < 0) {
+               C_LOGE("invalid param pid.");
                ret = PC_ERR_INVALID_PARAM;
                goto out;
        }
@@ -130,8 +135,8 @@ API int get_smack_label_from_process(pid_t pid, char smack_label[SMACK_LABEL_LEN
        }
 
        bzero(smack_label, SMACK_LABEL_LEN + 1);
-       if (!have_smack()) { // If no smack found just return success and empty label
-               C_LOGD("No SMACK. Return empty label");
+       if (!have_smack()) { // If no smack just return success with empty label
+               C_LOGD("No SMACK. Returning empty label");
                ret = PC_OPERATION_SUCCESS;
                goto out;
        }
@@ -140,18 +145,20 @@ API int get_smack_label_from_process(pid_t pid, char smack_label[SMACK_LABEL_LEN
        snprintf(path, PATH_MAX_LEN, "/proc/%d/attr/current", pid);
        fd = open(path, O_RDONLY);
        if (fd < 0) {
-               C_LOGE("cannot open file %s (errno: %s)", path, strerror(errno));
+               SECURE_C_LOGE("Cannot open file %s (errno: %s)", path, strerror(errno));
                ret = PC_ERR_FILE_OPERATION;
                goto out;
        }
 
        ret = read(fd, smack_label, SMACK_LABEL_LEN);
        if (ret < 0) {
-               C_LOGE("cannot read from file %s", path);
+               SECURE_C_LOGE("Cannot read from file %s", path);
                ret = PC_ERR_FILE_OPERATION;
                goto out;
        }
 
+       SECURE_C_LOGD("smack_label=%s", smack_label);
+
        ret = PC_OPERATION_SUCCESS;
 
 out:
@@ -162,7 +169,9 @@ API int smack_pid_have_access(pid_t pid,
                                                                const char* object,
                                                                const char *access_type)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pid=%i, object=%s, access_type=%s",
+                               __func__, pid, object, access_type);
+
        int ret;
        char pid_subject_label[SMACK_LABEL_LEN + 1];
        cap_t cap;
@@ -191,16 +200,16 @@ API int smack_pid_have_access(pid_t pid,
        //get SMACK label of process
        ret = get_smack_label_from_process(pid, pid_subject_label);
        if (PC_OPERATION_SUCCESS != ret) {
-               C_LOGE("get_smack_label_from_process %d failed: %d", pid, ret);
+               SECURE_C_LOGE("get_smack_label_from_process %d failed: %d", pid, ret);
                return -1;
        }
-       C_LOGD("pid %d have label: %s", pid, pid_subject_label);
+       SECURE_C_LOGD("pid %d has label: %s", pid, pid_subject_label);
 
        // do not call smack_have_access() if label is empty
        if (pid_subject_label[0] != '\0') {
                ret = smack_have_access(pid_subject_label, object, access_type);
                if ( -1 == ret) {
-                       C_LOGE("smack_have_access failed");
+                       C_LOGE("smack_have_access failed.");
                        return -1;
                }
                if ( 1 == ret ) { // smack_have_access return 1 (access granted)
@@ -234,7 +243,9 @@ API int smack_pid_have_access(pid_t pid,
 
 static int set_dac(const char *smack_label, const char *pkg_name)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: smack_label=%s, pkg_name=%s",
+                               __func__, smack_label, pkg_name);
+
        FILE* fp_group = NULL;  // /etc/group
        uid_t t_uid = -1;               // uid of current process
        gid_t *glist = NULL;    // group list
@@ -249,7 +260,7 @@ static int set_dac(const char *smack_label, const char *pkg_name)
        /*
         * initialize user structure
         */
-       C_LOGD("initialize user structure");
+       C_LOGD("Initialize user structure");
        memset(usr.user_name, 0x00, 10);
        memset(usr.home_dir, 0x00, 64);
        memset(usr.group_list, 0x00, 64);
@@ -281,10 +292,11 @@ static int set_dac(const char *smack_label, const char *pkg_name)
                /*
                 * get group information
                 */
-               C_LOGD("get group information");
+               C_LOGD("Get group information");
+               SECURE_C_LOGD("Opening file %s.", usr.group_list);
                if(!(fp_group = fopen(usr.group_list, "r")))
                {
-                       C_LOGE("File open error: %s", usr.group_list);
+                       C_LOGE("fopen failed.");
                        result = PC_ERR_FILE_OPERATION; // return -1
                        goto error;
                }
@@ -342,9 +354,9 @@ static int set_dac(const char *smack_label, const char *pkg_name)
                 */
                C_LOGD("Adding process to the following groups:");
                for(i=0; i<glist_cnt; ++i) {
-                       C_LOGD("glist [ %d ] = %d", i, glist[i]);
+                       SECURE_C_LOGD("glist [ %d ] = %d", i, glist[i]);
                }
-               C_LOGD("setgroups()");
+               C_LOGD("Calling setgroups()");
                if(setgroups(glist_cnt, glist) != 0)
                {
                        C_LOGE("setgroups failed");
@@ -374,7 +386,7 @@ static int set_dac(const char *smack_label, const char *pkg_name)
                        goto error;
                }
 
-               SECURE_SLOGD("setenv(): USER = %s, HOME = %s", usr.user_name, usr.home_dir);
+               SECURE_C_LOGD("setenv(): USER = %s, HOME = %s", usr.user_name, usr.home_dir);
                if(setenv("USER", usr.user_name, 1) != 0)       //fail
                {
                        C_LOGE("Failed to execute setenv() [USER].");
@@ -416,11 +428,10 @@ error:
  */
 static int get_smack_from_binary(char **smack_label, const char* path, app_type_t type)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: path=%s, type=%d",
+                               __func__, path, type);
        int ret;
 
-       C_LOGD("Path: %s", path);
-
        *smack_label = NULL;
        if (type == APP_TYPE_WGT
        || type == APP_TYPE_WGT_PARTNER
@@ -447,16 +458,17 @@ static int get_smack_from_binary(char **smack_label, const char* path, app_type_
  */
 static int set_smack_for_self (char *smack_label)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: smack_label=%s",
+                               __func__, smack_label);
        int ret;
 
        if (smack_label == NULL) {
                /* No label to set, just return with success */
-               C_LOGD("No label to set, just return with success");
+               C_LOGD("No label to set, just return with success.");
                ret = PC_OPERATION_SUCCESS;
        }
        else {
-               C_LOGD("label = %s", smack_label);
+               SECURE_C_LOGD("smack_label=%s", smack_label);
                if (have_smack()) {
                        ret = smack_set_label_for_self(smack_label);
                        C_LOGD("smack_set_label_for_self returned %d", ret);
@@ -469,7 +481,8 @@ static int set_smack_for_self (char *smack_label)
 
 static int is_widget(const char* path)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: path=%s",
+                               __func__, path);
        char buf[sizeof(WRT_CLIENT_PATH)];
        int ret;
 
@@ -481,7 +494,7 @@ static int is_widget(const char* path)
        if (ret == -1 || ret == sizeof(WRT_CLIENT_PATH))
                return 0;
        buf[ret] = '\0';
-       C_LOGD("buf = %s", buf);
+       C_LOGD("buf=%s", buf);
 
        ret = !strcmp(WRT_CLIENT_PATH, buf);
        C_LOGD("%s is %s widget", path, ret ? "a" : "not a");
@@ -501,7 +514,9 @@ static int is_widget(const char* path)
  */
 static app_type_t verify_app_type(const char* type, const char* path)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: type=%s, path=%s",
+                               __func__, type, path);
+
        /* TODO: this should actually be treated as error, but until the old
         * set_privilege API is removed, it must be ignored */
        if (path == NULL) {
@@ -537,13 +552,18 @@ static app_type_t verify_app_type(const char* type, const char* path)
 
 API int set_app_privilege(const char* name, const char* type, const char* path)//deprecated
 {
-    return perm_app_set_privilege(name, type, path);
+       SECURE_C_LOGD("Entering function: %s. Params: name=%s, type=%s, path=%s",
+                               __func__, name, type, path);
+
+       return perm_app_set_privilege(name, type, path);
 }
 
 API int perm_app_set_privilege(const char* name, const char* type, const char* path)
 {
-       C_LOGD("Enter function: %s", __func__);
-       SECURE_SLOGD("Function params: name = %s, type = %s, path = %s", name, type, path);
+       SECURE_C_LOGD("Entering function: %s. Params: name=%s, type=%s, path=%s",
+                               __func__, name, type, path);
+
+       //SECURE_C_LOGD("Function params: name = %s, type = %s, path = %s", name, type, path);
        int ret = PC_OPERATION_SUCCESS;
        int were_rules_loaded = 0;
        char *smack_label AUTO_FREE;
@@ -560,14 +580,14 @@ API int perm_app_set_privilege(const char* name, const char* type, const char* p
 
                were_rules_loaded = check_if_rules_were_loaded(smack_label);
                if (were_rules_loaded < 0) {
-                       C_LOGE("Error while check_if_rules_was_loaded");
+                       C_LOGE("check_if_rules_was_loaded failed.");
                        return PC_ERR_INVALID_OPERATION;
                }
                if (!were_rules_loaded) { // first run of application
-                       C_LOGD("This is first run of this application. Adding SMACK rules");
+                       C_LOGD("This is first run of this application. Adding SMACK rules.");
                        ret = add_app_first_run_rules(smack_label);
                        if (ret != PC_OPERATION_SUCCESS ) {
-                               C_LOGW("Warning: add_app_first_run_rules failed");
+                               C_LOGW("add_app_first_run_rules failed");
                                // should we return here with error code?
                        }
                        mark_rules_as_loaded(smack_label);
@@ -589,42 +609,59 @@ API int perm_app_set_privilege(const char* name, const char* type, const char* p
 
 API int set_privilege(const char* pkg_name)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_name=%s",
+                               __func__, pkg_name);
+
        return perm_app_set_privilege(pkg_name, NULL, NULL);
 }
 
 static inline const char* app_type_name(app_type_t app_type)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d",
+                               __func__, app_type);
+
        switch (app_type) {
        case APP_TYPE_WGT:
+               C_LOGD("App type = APP_TYPE_WGT");
                return "WRT";
        case APP_TYPE_OSP:
+               C_LOGD("App type = APP_TYPE_OSP");
                return "OSP";
        case APP_TYPE_WGT_PARTNER:
+               C_LOGD("App type = APP_TYPE_WGT_PARTNER");
                return "WRT_partner";
        case APP_TYPE_WGT_PLATFORM:
+               C_LOGD("App type = APP_TYPE_WGT_PLATFORM");
                return "WRT_platform";
        case APP_TYPE_OSP_PARTNER:
+               C_LOGD("App type = APP_TYPE_OSP_PARTNER");
                return "OSP_partner";
        case APP_TYPE_OSP_PLATFORM:
+               C_LOGD("App type = APP_TYPE_OSP_PLATFORM");
                return "OSP_platform";
        case APP_TYPE_EFL:
                return "EFL";
        default:
+               C_LOGD("App type = other");
                return NULL;
        }
 }
 
 static inline const char* app_type_group_name(app_type_t app_type)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d",
+                               __func__, app_type);
+
        switch (app_type) {
        case APP_TYPE_WGT:
        case APP_TYPE_WGT_PARTNER:
        case APP_TYPE_WGT_PLATFORM:
+               C_LOGD("App type group name = WRT");
                return "WRT";
        case APP_TYPE_OSP:
        case APP_TYPE_OSP_PARTNER:
        case APP_TYPE_OSP_PLATFORM:
+               C_LOGD("App type group name = OST");
                return "OSP";
        case APP_TYPE_EFL:
                return "EFL";
@@ -639,7 +676,11 @@ static inline const char* app_type_group_name(app_type_t app_type)
  * created basename : org.tizen.privilege.contact.read
  */
 
-static int base_name_from_perm(const char *perm, char **name) {
+static int base_name_from_perm(const char *perm, char **name)
+{
+       SECURE_C_LOGD("Entering function: %s. Params: perm=%s",
+                               __func__, perm);
+
        iri_t *ip = NULL;
        char *host_dot = NULL;
        char *rest_slash = NULL;
@@ -647,7 +688,7 @@ static int base_name_from_perm(const char *perm, char **name) {
 
        ip = iri_parse(perm);
        if (ip == NULL || ip->host == NULL) {
-               C_LOGE("Bad permission format : %s", perm);
+               SECURE_C_LOGE("Bad permission format : %s", perm);
                iri_destroy(ip);
                return PC_ERR_INVALID_PARAM;
        }
@@ -684,12 +725,15 @@ static int base_name_from_perm(const char *perm, char **name) {
 
 static int perm_file_path(char** path, app_type_t app_type, const char* perm, const char *suffix, bool is_early)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d, perm=%s, suffix=%s, is_early=%d",
+                               __func__, app_type, perm, suffix, is_early);
+
        const char* app_type_prefix = NULL;
        char* perm_basename = NULL;
        int ret = 0;
 
        if (perm == NULL || strlen(perm) == 0) {
-               C_LOGE("empty permission name");
+               C_LOGE("Empty permission name.");
                return PC_ERR_INVALID_PARAM;
        }
 
@@ -697,7 +741,7 @@ static int perm_file_path(char** path, app_type_t app_type, const char* perm, co
 
        ret = base_name_from_perm(perm, &perm_basename);
        if (ret != PC_OPERATION_SUCCESS) {
-               C_LOGE("Couldn't get permission basename");
+               C_LOGE("Couldn't get permission basename.");
                return ret;
        }
 
@@ -712,11 +756,11 @@ static int perm_file_path(char** path, app_type_t app_type, const char* perm, co
                perm_basename, suffix);
        }
        if (ret == -1) {
-               C_LOGE("asprintf failed");
+               C_LOGE("asprintf failed.");
                return PC_ERR_MEM_OPERATION;
        }
 
-       C_LOGD("Path : %s", *path);
+       C_LOGD("Path=%s", *path);
 
        return PC_OPERATION_SUCCESS;
 }
@@ -726,17 +770,18 @@ static int perm_to_smack_from_file(struct smack_accesses* smack,
                                           const char* app_label_template,
                                           const char* rules_file_path)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_label=%s, app_label_template=%s, rules_file_path=%s",
+                               __func__, app_label, app_label_template, rules_file_path);
 
        char smack_subject[SMACK_LABEL_LEN + 1];
        char smack_object[SMACK_LABEL_LEN + 1];
        char smack_accesses[ACC_LEN + 1];
        FILE* file AUTO_FCLOSE;
 
+       SECURE_C_LOGD("Opening file %s.", rules_file_path);
        file = fopen(rules_file_path, "r");
-       C_LOGD("path = %s", rules_file_path);
        if (file == NULL) {
-               C_LOGW("fopen failed [%s] %s", rules_file_path, strerror(errno));
+               SECURE_C_LOGW("fopen failed [%s] %s", rules_file_path, strerror(errno));
                return PC_OPERATION_SUCCESS;
        }
 
@@ -753,7 +798,7 @@ static int perm_to_smack_from_file(struct smack_accesses* smack,
 
                C_LOGD("smack_accesses_add_modify (subject: %s, object: %s, access: %s)", smack_subject, smack_object, smack_accesses);
                if (smack_accesses_add_modify(smack, smack_subject, smack_object, smack_accesses, "") != 0) {
-                       C_LOGE("smack_accesses_add_modify failed");
+                       C_LOGE("smack_accesses_add_modify failed.");
                        return PC_ERR_INVALID_OPERATION;
                }
        }
@@ -785,21 +830,25 @@ static int perm_to_smack_generic(struct smack_accesses* smack, const char* app_l
 
 static int perm_to_smack_early(struct smack_accesses* smack, const char* app_label, app_type_t app_type, const char* perm)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_label=%s, app_type=%d, perm=%s",
+                               __func__, app_label, app_type, perm);
 
        return perm_to_smack_generic(smack, app_label, app_type, perm, 1);
 }
 
 static int perm_to_smack(struct smack_accesses* smack, const char* app_label, app_type_t app_type, const char* perm)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_label=%s, app_type=%d, perm=%s",
+                               __func__, app_label, app_type, perm);
 
        return perm_to_smack_generic(smack, app_label, app_type, perm, 0);
 }
 
 static int perm_to_dac(const char* app_label, app_type_t app_type, const char* perm)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_label=%s, app_type=%d, perm=%s",
+                               __func__, app_label, app_type, perm);
+
        int ret;
        char* path AUTO_FREE;
        FILE* file AUTO_FCLOSE;
@@ -811,18 +860,18 @@ static int perm_to_dac(const char* app_label, app_type_t app_type, const char* p
                return ret;
        }
 
+       SECURE_C_LOGD("Opening file %s.", path);
        file = fopen(path, "r");
-       C_LOGD("path = %s", path);
        if (file == NULL) {
-               C_LOGW("fopen failed");
+               C_LOGW("fopen failed.");
                return PC_OPERATION_SUCCESS;
        }
 
        while (fscanf(file, "%d\n", &gid) == 1) {
-               SECURE_SLOGD("Adding app_id %s to group %d", app_label, gid);
+               SECURE_C_LOGD("Adding app_id %s to group %d", app_label, gid);
                ret = add_app_gid(app_label, gid);
                if (ret != PC_OPERATION_SUCCESS) {
-                       C_LOGE("sadd_app_gid failed");
+                       C_LOGE("add_app_gid failed");
                        return ret;
                }
        }
@@ -832,12 +881,16 @@ static int perm_to_dac(const char* app_label, app_type_t app_type, const char* p
 
 static int label_all(const FTSENT* ftsent)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        return DECISION_LABEL;
 }
 
 static int label_execs(const FTSENT* ftsent)
 {
-       C_LOGD("Mode: %d", ftsent->fts_statp->st_mode);
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
+       C_LOGD("Mode = %d", ftsent->fts_statp->st_mode);
        // label only regular executable files
        if (S_ISREG(ftsent->fts_statp->st_mode) && (ftsent->fts_statp->st_mode & S_IXUSR))
                return DECISION_LABEL;
@@ -846,6 +899,8 @@ static int label_execs(const FTSENT* ftsent)
 
 static int label_dirs(const FTSENT* ftsent)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        // label only directories
        if (S_ISDIR(ftsent->fts_statp->st_mode))
                return DECISION_LABEL;
@@ -854,6 +909,8 @@ static int label_dirs(const FTSENT* ftsent)
 
 static int label_links_to_execs(const FTSENT* ftsent)
 {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
+
        struct stat buf;
        char* target AUTO_FREE;
 
@@ -863,16 +920,16 @@ static int label_links_to_execs(const FTSENT* ftsent)
 
        target = realpath(ftsent->fts_path, NULL);
        if (!target) {
-               C_LOGE("Getting link target for %s failed. Error %s", ftsent->fts_path, strerror(errno));
+               SECURE_C_LOGE("Getting link target for %s failed (Error = %s)", ftsent->fts_path, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
        if (-1 == stat(target, &buf)) {
-               C_LOGE("stat failed for %s, error: %s",target, strerror(errno));
+               SECURE_C_LOGE("stat failed for %s (Error = %s", target, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
        // skip if link target is not a regular executable file
        if (buf.st_mode != (buf.st_mode | S_IXUSR | S_IFREG)) {
-               C_LOGD("%s is not a regular executable file. Skipping.", target);
+               SECURE_C_LOGD("%s is not a regular executable file. Skipping.", target);
                return DECISION_SKIP;
        }
 
@@ -882,7 +939,9 @@ static int label_links_to_execs(const FTSENT* ftsent)
 static int dir_set_smack_r(const char *path, const char* label,
                enum smack_label_type type, label_decision_fn fn)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: path=%s, label=%s, type=%d",
+                               __func__, path, label, type);
+
        const char* path_argv[] = {path, NULL};
        FTS *fts AUTO_FTS_CLOSE;
        FTSENT *ftsent;
@@ -890,7 +949,7 @@ static int dir_set_smack_r(const char *path, const char* label,
 
        fts = fts_open((char * const *) path_argv, FTS_PHYSICAL | FTS_NOCHDIR, NULL);
        if (fts == NULL) {
-               C_LOGE("fts_open failed");
+               C_LOGE("fts_open failed.");
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -903,13 +962,14 @@ static int dir_set_smack_r(const char *path, const char* label,
 
                ret = fn(ftsent);
                if (ret < 0) {
+                       C_LOGE("fn(ftsent) failed.");
                        return ret;
                }
 
                if (ret == DECISION_LABEL) {
                        C_LOGD("smack_lsetlabel (label: %s (type: %d), path: %s)", label, type, ftsent->fts_path);
                        if (smack_lsetlabel(ftsent->fts_path, label, type) != 0) {
-                               C_LOGE("smack_lsetlabel failed");
+                               C_LOGE("smack_lsetlabel failed.");
                                return PC_ERR_FILE_OPERATION;
                        }
                }
@@ -917,7 +977,7 @@ static int dir_set_smack_r(const char *path, const char* label,
 
        /* If last call to fts_read() set errno, we need to return error. */
        if (errno != 0) {
-               C_LOGE("Last errno: %s", strerror(errno));
+               C_LOGE("Last errno from fts_read: %s", strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
        return PC_OPERATION_SUCCESS;
@@ -925,14 +985,21 @@ static int dir_set_smack_r(const char *path, const char* label,
 
 API char* app_id_from_socket(int sockfd)//deprecated
 {
+       SECURE_C_LOGD("Entering function: %s. Params: sockfd=%d",
+                               __func__, sockfd);
+
     return perm_app_id_from_socket(sockfd);
 }
 
 API char* perm_app_id_from_socket(int sockfd)
 {
-       C_LOGD("Enter function: %s", __func__);
-       if (!have_smack())
+       SECURE_C_LOGD("Entering function: %s. Params: sockfd=%d",
+                               __func__, sockfd);
+
+       if (!have_smack()) {
+               C_LOGD("No SMACK. Returning NULL.");
                return NULL;
+       }
 
        char* app_id;
        int ret;
@@ -943,14 +1010,16 @@ API char* perm_app_id_from_socket(int sockfd)
                return NULL;
        }
 
-       SECURE_SLOGD("app_id: %s", app_id);
+       SECURE_C_LOGD("app_id = %s", app_id);
 
        return app_id;
 }
 
 static int app_add_rule(const char *app_id, const char *object, const char *perm)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s, object=%s, perm=%s",
+                               __func__, app_id, object, perm);
+
        int ret;
        int fd AUTO_CLOSE;
        char *smack_path AUTO_FREE;
@@ -958,23 +1027,23 @@ static int app_add_rule(const char *app_id, const char *object, const char *perm
 
        ret = load_smack_from_file(app_id, &smack, &fd, &smack_path);
        if (ret != PC_OPERATION_SUCCESS) {
-               C_LOGE("load_smack_from_file failed");
+               C_LOGE("load_smack_from_file failed.");
                return ret;
        }
 
        ret = smack_accesses_add_modify(smack, app_id, object, perm, "");
        if (ret == -1) {
-               C_LOGE("smack_accesses_add_modify failed");
+               C_LOGE("smack_accesses_add_modify failed.");
                return PC_ERR_INVALID_OPERATION;
        }
 
        if (have_smack() && smack_accesses_apply(smack)) {
-               C_LOGE("smack_accesses_apply failed");
+               C_LOGE("smack_accesses_apply failed.");
                return PC_ERR_INVALID_OPERATION;
        }
 
        if (smack_accesses_save(smack, fd)) {
-               C_LOGE("smack_accesses_save failed");
+               C_LOGE("smack_accesses_save failed.");
                return PC_ERR_INVALID_OPERATION;
        }
 
@@ -985,7 +1054,9 @@ static int app_add_rule(const char *app_id, const char *object, const char *perm
 static int
 app_register_appsetting(const char *app_id, struct smack_accesses *smack)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        int ret;
        int i;
 
@@ -994,9 +1065,10 @@ app_register_appsetting(const char *app_id, struct smack_accesses *smack)
        int app_list_len = 0;
        int dir_list_len = 0;
 
-       if (!smack_label_is_valid(app_id))
+       if (!smack_label_is_valid(app_id)) {
+               C_LOGE("Invalid param app_id.");
                return PC_ERR_INVALID_PARAM;
-
+       }
 
        /* writing appsetting_id (app_id) to "database"*/
        ret = add_appsetting_id_to_databse(app_id);
@@ -1016,7 +1088,7 @@ app_register_appsetting(const char *app_id, struct smack_accesses *smack)
                C_LOGD("Appsetting: applying rx rule for %s", label_app_list[i]);
                if (smack_accesses_add_modify(smack, app_id,
                                label_app_list[i], "rx", "") == -1) {
-                       C_LOGE("smack_accesses_add_modify failed");
+                       C_LOGE("smack_accesses_add_modify failed.");
                        ret = PC_ERR_INVALID_OPERATION;
                        goto out;
                }
@@ -1034,7 +1106,7 @@ app_register_appsetting(const char *app_id, struct smack_accesses *smack)
                C_LOGD("Appsetting: applying rwx rule for %s", label_dir_list[i]);
                if (smack_accesses_add_modify(smack, app_id,
                                label_dir_list[i], "rwx", "") == -1) {
-                       C_LOGE("smack_accesses_add_modify failed");
+                       C_LOGE("smack_accesses_add_modify failed.");
                        ret = PC_ERR_INVALID_OPERATION;
                        goto out;
                        /* Should we abort adding rules if
@@ -1055,15 +1127,24 @@ app_register_appsetting(const char *app_id, struct smack_accesses *smack)
 
 static int app_register_av_internal(const char *app_av_id, struct smack_accesses* smack)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_av_id=%s.",
+                               __func__, app_av_id);
+
        int ret;
        int i;
 
        char** smack_label_app_list AUTO_FREE;
        int smack_label_app_list_len = 0;
 
-       if (!smack_label_is_valid(app_av_id) || NULL == smack)
+       if (!smack_label_is_valid(app_av_id)) {
+               C_LOGE("Invalid param app_av_id.");
                return PC_ERR_INVALID_PARAM;
+       }
+
+       if(smack == NULL) {
+               C_LOGE("Invalid param smack (NULL).");
+               return PC_ERR_INVALID_PARAM;
+       }
 
        // writing anti_virus_id (app_av_id) to "database"
        ret = add_av_id_to_databse(app_av_id);
@@ -1073,13 +1154,13 @@ static int app_register_av_internal(const char *app_av_id, struct smack_accesses
        // Reading labels of all installed apps from "database"
        ret = get_all_apps_ids(&smack_label_app_list, &smack_label_app_list_len);
        if (ret != PC_OPERATION_SUCCESS ) {
-               C_LOGE("Error while geting data from database");
+               C_LOGE("Error while geting data from database.");
                goto out;
        }
        for (i = 0; i < smack_label_app_list_len; ++i) {
-               C_LOGD("Applying rwx rule for %s", smack_label_app_list[i]);
+               SECURE_C_LOGD("Applying rwx rule for %s", smack_label_app_list[i]);
                if (smack_accesses_add_modify(smack, app_av_id, smack_label_app_list[i], "wrx", "") == -1) {
-                       C_LOGE("smack_accesses_add_modify failed");
+                       C_LOGE("smack_accesses_add_modify failed.");
                        ret = PC_ERR_INVALID_OPERATION;
                        goto out;
                        // Should we abort adding rules once smack_accesses_add_modify will fail?
@@ -1101,6 +1182,9 @@ out:
  */
 static int register_app_for_av(const char * app_id)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s.",
+                               __func__, app_id);
+
        int ret, i;
        char** smack_label_av_list AUTO_FREE;
        int smack_label_av_list_len = 0;
@@ -1108,20 +1192,20 @@ static int register_app_for_av(const char * app_id)
        // Reading labels of all installed anti viruses from "database"
        ret = get_all_avs_ids(&smack_label_av_list, &smack_label_av_list_len);
        if (ret != PC_OPERATION_SUCCESS) {
-               C_LOGE("Error while geting data from database");
+               C_LOGE("Error while geting data from database.");
                return ret;
        }
 
        // for each anti-virus label put rule: "anti_virus_label app_id rwx"
        for (i = 0; i < smack_label_av_list_len; ++i) {
-               SECURE_SLOGD("Antivirus: app_add_rule (%s, %s rx)", smack_label_av_list[i], app_id);
+               SECURE_C_LOGD("Antivirus: app_add_rule (%s, %s rx)", smack_label_av_list[i], app_id);
                if (strcmp(app_id, smack_label_av_list[i])==0) {
-                       SECURE_SLOGW("Trying to add antivirus rule for self. Skipping");
+                       SECURE_C_LOGW("Trying to add antivirus rule for self. Skipping");
                        continue;
                }
                ret = app_add_rule(smack_label_av_list[i], app_id, "wrx");
                if (ret != PC_OPERATION_SUCCESS) {
-                       C_LOGE("app_add_rule failed");
+                       C_LOGE("app_add_rule failed.");
                        goto out;
                }
 
@@ -1147,7 +1231,9 @@ out:
  */
 static int register_app_for_appsetting(const char *app_id)
 {
-       C_LOGD("Enter function: %s",__func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        int ret, i;
        char **smack_label_list AUTO_FREE;
        int smack_label_list_len = 0;
@@ -1155,16 +1241,16 @@ static int register_app_for_appsetting(const char *app_id)
        /* Reading labels of all installed setting managers from "database"*/
        ret = get_all_appsetting_ids(&smack_label_list, &smack_label_list_len);
        if (ret != PC_OPERATION_SUCCESS) {
-               C_LOGE("Error while geting data from database");
+               C_LOGE("Error while geting data from database.");
                return ret;
        }
 
        /* for each appsetting put rule: "appsetting_id app_id rx"*/
        for (i = 0; i < smack_label_list_len; ++i) {
 
-               SECURE_SLOGD("Appsetting: app_add_rule (%s, %s rx)", smack_label_list[i], app_id);
+               SECURE_C_LOGD("Appsetting: app_add_rule (%s, %s rx)", smack_label_list[i], app_id);
                if (strcmp(app_id, smack_label_list[i])==0) {
-                       SECURE_SLOGW("Trying to add setting rule for self. Skipping");
+                       SECURE_C_LOGW("Trying to add setting rule for self. Skipping");
                        continue;
                }
                ret = app_add_rule(smack_label_list[i], app_id, "rx");
@@ -1196,7 +1282,8 @@ out:
  */
 static int register_app_for_public_dirs(const char *app_id, struct smack_accesses *smack)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
        int ret, i;
        char **public_dirs AUTO_FREE;
        int public_dirs_cnt = 0;
@@ -1208,7 +1295,7 @@ static int register_app_for_public_dirs(const char *app_id, struct smack_accesse
        }
 
        for (i = 0; i < public_dirs_cnt; ++i) {
-               SECURE_SLOGD("Allowing app %s to access public path %s", app_id, public_dirs[i]);
+               SECURE_C_LOGD("Allowing app %s to access public path %s", app_id, public_dirs[i]);
                if (smack_accesses_add_modify(smack, app_id, public_dirs[i], "rx", "")) {
                        C_LOGE("app_add_rule_modify failed");
                        while (i < public_dirs_cnt)
@@ -1223,7 +1310,9 @@ static int register_app_for_public_dirs(const char *app_id, struct smack_accesse
 
 static int app_add_permissions_internal(const char* app_id, app_type_t app_type, const char** perm_list, int permanent)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s, app_type=%d, permanent=%d",
+                               __func__, app_id, app_type, permanent);
+
        int i, ret;
        char* smack_path AUTO_FREE;
        char* smack_path_early AUTO_FREE;
@@ -1233,8 +1322,10 @@ static int app_add_permissions_internal(const char* app_id, app_type_t app_type,
        struct smack_accesses *smack_early AUTO_SMACK_FREE;
        const char* base_perm = NULL;
 
-       if (!smack_label_is_valid(app_id))
+       if (!smack_label_is_valid(app_id)) {
+               C_LOGE("Invalid param app_id.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        if(perm_list == NULL) {
                C_LOGE("Invalid perm_list (NULL).");
@@ -1256,7 +1347,7 @@ static int app_add_permissions_internal(const char* app_id, app_type_t app_type,
        /* Implicitly enable base permission for an app_type */
        base_perm = app_type_name(app_type);
        if (base_perm) {
-               SECURE_SLOGD("perm_to_smack params: app_id: %s, %s", app_id, base_perm);
+               SECURE_C_LOGD("perm_to_smack params: app_id: %s, %s", app_id, base_perm);
                ret = perm_to_smack(smack, app_id, APP_TYPE_OTHER, base_perm);
                if (ret != PC_OPERATION_SUCCESS){
                        C_LOGE("perm_to_smack failed");
@@ -1264,7 +1355,7 @@ static int app_add_permissions_internal(const char* app_id, app_type_t app_type,
                }
 
                // Add early permission - such permissions should be enabled right after system boot
-               SECURE_SLOGD("perm_to_smack params: app_id: %s, %s", app_id, base_perm);
+               SECURE_C_LOGD("perm_to_smack params: app_id: %s, %s", app_id, base_perm);
                ret = perm_to_smack_early(smack_early, app_id, APP_TYPE_OTHER, base_perm);
                if (ret != PC_OPERATION_SUCCESS){
                        C_LOGE("perm_to_smack failed");
@@ -1273,7 +1364,7 @@ static int app_add_permissions_internal(const char* app_id, app_type_t app_type,
 
        }
        for (i = 0; perm_list[i] != NULL; ++i) {
-               SECURE_SLOGD("perm_to_smack params: app_id: %s, perm_list[%d]: %s", app_id, i, perm_list[i]);
+               SECURE_C_LOGD("perm_to_smack params: app_id: %s, perm_list[%d]: %s", app_id, i, perm_list[i]);
                if (strcmp(perm_list[i], TIZEN_PRIVILEGE_ANTIVIRUS) == 0) {
                        ret = app_register_av_internal(app_id, smack);
                        if (ret != PC_OPERATION_SUCCESS) {
@@ -1333,66 +1424,83 @@ static int app_add_permissions_internal(const char* app_id, app_type_t app_type,
 
 API int app_add_permissions(const char* app_id, const char** perm_list)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        return app_add_permissions_internal(app_id, APP_TYPE_OTHER, perm_list, 1);
 }
 
 API int app_add_volatile_permissions(const char* app_id, const char** perm_list)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
+
        return app_add_permissions_internal(app_id, APP_TYPE_OTHER, perm_list, 0);
 }
 
 API int app_enable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list, bool persistent)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, app_type=%d, persistent=%d",
+                               __func__, pkg_id, app_type, persistent);
+
        return app_add_permissions_internal(pkg_id, app_type, perm_list, persistent);
 }
 
 API int perm_app_enable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list, bool persistent)
 {
-    C_LOGD("Enter function: %s", __func__);
-    return app_add_permissions_internal(pkg_id, app_type, perm_list, persistent);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, app_type=%d, persistent=%d",
+                               __func__, pkg_id, app_type, persistent);
+
+       return app_add_permissions_internal(pkg_id, app_type, perm_list, persistent);
 }
 
 API int app_disable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list)//deprecated
 {
-    return perm_app_disable_permissions(pkg_id, app_type, perm_list);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, app_type=%d",
+                               __func__, pkg_id, app_type);
+
+       return perm_app_disable_permissions(pkg_id, app_type, perm_list);
 }
 
 /* FIXME: this function is only a stub */
 API int perm_app_disable_permissions(const char* pkg_id, app_type_t app_type, const char** perm_list)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, app_type=%d",
+                               __func__, pkg_id, app_type);
+
        return PC_OPERATION_SUCCESS;
 }
 
 static int app_revoke_permissions_internal(const char* app_id, bool persistent)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s, persistent=%d",
+                               __func__, app_id, persistent);
+
        char* smack_path AUTO_FREE;
        int ret;
        int fd AUTO_CLOSE;
        struct smack_accesses *smack AUTO_SMACK_FREE;
 
-       if (!smack_label_is_valid(app_id))
+       if (!smack_label_is_valid(app_id)) {
+               C_LOGE("Invalid param app_id.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        ret = load_smack_from_file(app_id, &smack, &fd, &smack_path);
        if (ret != PC_OPERATION_SUCCESS) {
-               C_LOGE("load_smack_from_file failed");
+               C_LOGE("load_smack_from_file failed.");
                return ret;
        }
 
        if (have_smack() && smack_accesses_clear(smack)) {
                ret = PC_ERR_INVALID_OPERATION;
-               C_LOGE("smack_accesses_clear failed");
+               C_LOGE("smack_accesses_clear failed.");
                return ret;
        }
 
        if (have_smack() && smack_revoke_subject(app_id)) {
                ret = PC_ERR_INVALID_OPERATION;
-               C_LOGE("smack_revoke_subject failed");
+               C_LOGE("smack_revoke_subject failed.");
                return ret;
        }
 
@@ -1404,42 +1512,52 @@ static int app_revoke_permissions_internal(const char* app_id, bool persistent)
 
 API int app_revoke_permissions(const char* pkg_id)//deprecated
 {
-    return perm_app_revoke_permissions(pkg_id);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s", __func__, pkg_id);
+       return perm_app_revoke_permissions(pkg_id);
 }
 
 API int perm_app_revoke_permissions(const char* pkg_id)
 {
-    C_LOGD("Enter function: %s", __func__);
-    int ret;
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s", __func__, pkg_id);
+       int ret;
 
-    if (!smack_label_is_valid(pkg_id))
-        return PC_ERR_INVALID_PARAM;
+       if (!smack_label_is_valid(pkg_id)) {
+               C_LOGE("Invalid param app_id.");
+               return PC_ERR_INVALID_PARAM;
+       }
 
-    ret = app_revoke_permissions_internal(pkg_id, true);
-    if (ret) {
-        C_LOGE("Revoking permissions failed");
-        return ret;
-    }
+       ret = app_revoke_permissions_internal(pkg_id, true);
+       if (ret) {
+               C_LOGE("Revoking permissions failed.");
+               return ret;
+       }
 
-    return PC_OPERATION_SUCCESS;
+       return PC_OPERATION_SUCCESS;
 }
 
 API int app_reset_permissions(const char* pkg_id)//deprecated
 {
-    return perm_app_reset_permissions(pkg_id);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s",
+                               __func__, pkg_id);
+
+       return perm_app_reset_permissions(pkg_id);
 }
 
 API int perm_app_reset_permissions(const char* pkg_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s",
+                               __func__, pkg_id);
+
        int ret;
 
-       if (!smack_label_is_valid(pkg_id))
+       if (!smack_label_is_valid(pkg_id)) {
+               C_LOGE("Invalid param pkg_id.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        ret = app_revoke_permissions_internal(pkg_id, false);
        if (ret) {
-               C_LOGE("Revoking permissions failed");
+               C_LOGE("Revoking permissions failed.");
                return ret;
        }
 
@@ -1449,7 +1567,8 @@ API int perm_app_reset_permissions(const char* pkg_id)
 
 API int app_label_dir(const char* label, const char* path)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: label=%s, path=%s",
+                               __func__, label, path);
 
        int ret = PC_OPERATION_SUCCESS;
 
@@ -1458,18 +1577,26 @@ API int app_label_dir(const char* label, const char* path)//deprecated
                return PC_ERR_INVALID_PARAM;
        }
 
-       if (!smack_label_is_valid(label))
+       if (!smack_label_is_valid(label)) {
+               C_LOGE("Invalid param label.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        //setting access label on everything in given directory and below
        ret = dir_set_smack_r(path, label, SMACK_LABEL_ACCESS, &label_all);
        if (PC_OPERATION_SUCCESS != ret)
+       {
+               C_LOGE("dir_set_smack_r failed.");
                return ret;
+       }
 
        //setting execute label for everything with permission to execute
        ret = dir_set_smack_r(path, label, SMACK_LABEL_EXEC, &label_execs);
        if (PC_OPERATION_SUCCESS != ret)
+       {
+               C_LOGE("dir_set_smack_r failed.");
                return ret;
+       }
 
        //setting execute label for everything with permission to execute
        ret = dir_set_smack_r(path, label, SMACK_LABEL_EXEC, &label_links_to_execs);
@@ -1478,18 +1605,35 @@ API int app_label_dir(const char* label, const char* path)//deprecated
 
 int smack_get_access_new(const char* subject, const char* object, char** label)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: subject=%s, object=%s",
+                               __func__, subject, object);
+       
        char buff[ACC_LEN] = {'r', 'w', 'x', 'a', 't', 'l'};
        char perm[2] = {'-'};
        int i;
 
-       if(!smack_label_is_valid(subject) || !smack_label_is_valid(object) || !label)
+       if(!smack_label_is_valid(subject)) {
+               C_LOGE("Invalid param subject.");
                return PC_ERR_INVALID_PARAM;
+       }
+
+       if(!smack_label_is_valid(object)) {
+               C_LOGE("Invalid param object.");
+               return PC_ERR_INVALID_PARAM;
+       }
+
+       if(!label) {
+               C_LOGE("Invalid param label (NULL).");
+               return PC_ERR_INVALID_PARAM;
+       }
 
        for (i=0; i<ACC_LEN; ++i) {
                perm[0] = buff[i];
                int ret = smack_have_access(subject, object, perm);
-               if (-1 == ret)
+               if (-1 == ret) {
+                       C_LOGE("smack_have_access failed during %c check.", perm[0]);
                        return PC_ERR_INVALID_OPERATION;
+               }
                if (0 == ret)
                        buff[i] = '-';
        }
@@ -1505,7 +1649,8 @@ int smack_get_access_new(const char* subject, const char* object, char** label)
 
 static int app_uninstall_remove_early_rules(const char *app_id)
 {
-       C_LOGD("Enter function: %s(%s)", __func__, app_id);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s",
+                               __func__, app_id);
 
        int ret;
        int fd AUTO_CLOSE;
@@ -1516,20 +1661,21 @@ static int app_uninstall_remove_early_rules(const char *app_id)
        char subject[SMACK_LABEL_LEN + 1];
        char object[SMACK_LABEL_LEN + 1];
 
+       SECURE_C_LOGD("Opening file %s.", SMACK_STARTUP_RULES_FILE);
        fd = open(SMACK_STARTUP_RULES_FILE, O_RDWR);
        if (fd < 0) {
-               C_LOGE("Unable to open file %s: %s", SMACK_STARTUP_RULES_FILE, strerror(errno));
+               SECURE_C_LOGE("Unable to open file %s: %s", SMACK_STARTUP_RULES_FILE, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
        if (flock(fd, LOCK_EX)) {
-               C_LOGE("flock failed, error %s", strerror(errno));
+               SECURE_C_LOGE("flock failed, error %s", strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
        size = lseek(fd, 0, SEEK_END);
        if (size < 0) {
-               C_LOGE("Unable to read file %s: %s", SMACK_STARTUP_RULES_FILE, strerror(errno));
+               SECURE_C_LOGE("Unable to read file %s: %s", SMACK_STARTUP_RULES_FILE, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -1538,7 +1684,7 @@ static int app_uninstall_remove_early_rules(const char *app_id)
 
        data = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
        if (data == MAP_FAILED) {
-               C_LOGE("Unable to read file %s: %s", SMACK_STARTUP_RULES_FILE, strerror(errno));
+               SECURE_C_LOGE("Unable to read file %s: %s", SMACK_STARTUP_RULES_FILE, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
        data_end = data + size;
@@ -1551,7 +1697,7 @@ static int app_uninstall_remove_early_rules(const char *app_id)
 
                tmp = *line_end;
                *line_end = '\0';
-               C_LOGD("Considering early rule: %s", line_begin);
+               SECURE_C_LOGD("Considering early rule: %s", line_begin);
 
                ret = sscanf(line_begin, "%" TOSTRING(SMACK_LABEL_LEN) "s %" TOSTRING(SMACK_LABEL_LEN) "s", subject, object);
                if (ret != 2) {
@@ -1578,7 +1724,7 @@ static int app_uninstall_remove_early_rules(const char *app_id)
        munmap(data, size);
        ret = ftruncate(fd, write_pos - data);
        if (ret < 0) {
-               C_LOGE("Unable to truncate file %s to %d bytes: %s", SMACK_STARTUP_RULES_FILE, write_pos, strerror(errno));
+               SECURE_C_LOGE("Unable to truncate file %s to %d bytes: %s", SMACK_STARTUP_RULES_FILE, write_pos, strerror(errno));
 
                return PC_ERR_FILE_OPERATION;
        }
@@ -1588,17 +1734,24 @@ static int app_uninstall_remove_early_rules(const char *app_id)
 
 API int app_label_shared_dir(const char* app_label, const char* shared_label, const char* path)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_label=%s, shared_label=%s, path=%s",
+                               __func__, app_label, shared_label, path);
        int ret;
 
-       if(path == NULL)
-       {
+       if(path == NULL) {
                C_LOGE("Invalid param path.");
                return PC_ERR_INVALID_PARAM;
        }
 
-       if (!smack_label_is_valid(app_label) || !smack_label_is_valid(shared_label))
+       if(!smack_label_is_valid(app_label)) {
+               C_LOGE("Invalid param app_label");
                return PC_ERR_INVALID_PARAM;
+       }
+
+       if(!smack_label_is_valid(shared_label)) {
+               C_LOGE("Invalid param shared_label");
+               return PC_ERR_INVALID_PARAM;
+       }
 
        if (strcmp(app_label, shared_label) == 0) {
                C_LOGE("app_label equals shared_label");
@@ -1608,7 +1761,7 @@ API int app_label_shared_dir(const char* app_label, const char* shared_label, co
        //setting label on everything in given directory and below
        ret = dir_set_smack_r(path, shared_label, SMACK_LABEL_ACCESS, label_all);
        if(ret != PC_OPERATION_SUCCESS){
-               C_LOGE("dir_set_smack_r failed");
+               C_LOGE("dir_set_smack_r failed.");
                return ret;
        }
 
@@ -1630,7 +1783,8 @@ API int app_label_shared_dir(const char* app_label, const char* shared_label, co
 
 API int add_shared_dir_readers(const char* shared_label, const char** app_list)//deprecated
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: shared_label=%s",
+                               __func__, shared_label);
        int ret;
        int i;
 
@@ -1639,17 +1793,20 @@ API int add_shared_dir_readers(const char* shared_label, const char** app_list)/
                return PC_ERR_INVALID_PARAM;
        }
 
-       if (!smack_label_is_valid(shared_label))
-                               return PC_ERR_INVALID_PARAM;
+       if (!smack_label_is_valid(shared_label)) {
+               C_LOGE("Invalid param shared_label.");
+               return PC_ERR_INVALID_PARAM;
+       }
 
        for (i = 0; app_list[i] != NULL; i++) {
-
-               if (!smack_label_is_valid(app_list[i]))
-                                       return PC_ERR_INVALID_PARAM;
+               if (!smack_label_is_valid(app_list[i])) {
+                       C_LOGE("Invalid %d element from param app_list.", i);
+                       return PC_ERR_INVALID_PARAM;
+               }
 
                ret = app_add_rule(app_list[i], shared_label, "rx");
                if (ret != PC_OPERATION_SUCCESS) {
-                       C_LOGE("app_add_rule failed");
+                       C_LOGE("app_add_rule failed.");
                        return ret;
                }
        }
@@ -1659,7 +1816,9 @@ API int add_shared_dir_readers(const char* shared_label, const char** app_list)/
 
 static char* smack_label_for_path(const char *app_id, const char *path)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_id=%s, path=%s",
+                               __func__, app_id, path);
+
        char *salt AUTO_FREE;
        char *label;
        char *x;
@@ -1735,7 +1894,8 @@ static int add_other_apps_rules_for_shared_dir(const char *pkg_id, const char *t
 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
 static int perm_app_setup_path_internal(const char* pkg_id, const char* path, app_path_type_t app_path_type, va_list ap)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, path=%s, app_path_type=%d",
+                               __func__, pkg_id, path, app_path_type);
 
        if(path == NULL) {
                C_LOGE("Invalid argument path.");
@@ -1743,27 +1903,30 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
        }
 
        if (!smack_label_is_valid(pkg_id)) {
-               SECURE_SLOGE("Invalid app_id %s", pkg_id);
+               C_LOGE("Invalid pkg_id.");
+               SECURE_C_LOGE("Invalid pkg_id %s", pkg_id);
                return PC_ERR_INVALID_PARAM;
        }
 
        switch (app_path_type) {
        case APP_PATH_PRIVATE:
+               C_LOGD("app_path_type is APP_PATH_PRIVATE.");
                return app_label_dir(pkg_id, path);
 
        case APP_PATH_GROUP_RW: {
-               const char *shared_label;
+               C_LOGD("app_path_type is APP_PATH_GROUP_RW.");
                int ret;
+               const char *shared_label;
 
                shared_label = va_arg(ap, const char *);
 
                if (!smack_label_is_valid(shared_label)) {
-                       C_LOGE("Invalid shared_label %s", shared_label);
+                       C_LOGE("Invalid shared_label.");
                        return PC_ERR_INVALID_PARAM;
                }
 
                if (strcmp(pkg_id, shared_label) == 0) {
-                       C_LOGE("app_id equals shared_label");
+                       C_LOGE("pkg_id equals shared_label.");
                        return PC_ERR_INVALID_PARAM;
                }
 
@@ -1777,6 +1940,7 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
        }
 
        case APP_PATH_PUBLIC_RO: {
+               C_LOGD("app_path_type is APP_PATH_PUBLIC_RO.");
                char **app_ids AUTO_FREE;
                int app_ids_cnt = 0;
                const char *label;
@@ -1784,25 +1948,33 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
 
                C_LOGD("New public RO path %s", path);
                label = smack_label_for_path(pkg_id, path);
-               if (label == NULL)
+               if (label == NULL) {
+                       C_LOGE("smack_label_for_path failed.");
                        return PC_ERR_INVALID_OPERATION;
+               }
 
                C_LOGD("Generated label '%s' for public RO path %s", label, path);
                ret = app_label_shared_dir(pkg_id, label, path);
-               if (ret != PC_OPERATION_SUCCESS)
+               if (ret != PC_OPERATION_SUCCESS) {
+                       C_LOGE("app_label_shared_dir failed.");
                        return ret;
+               }
 
                /* FIXME: This should be in some kind of transaction/lock */
                ret = db_add_public_dir(label);
-               if (ret != PC_OPERATION_SUCCESS)
+               if (ret != PC_OPERATION_SUCCESS) {
+                       C_LOGE("db_add_public_dir failed.");
                        return ret;
+               }
 
                ret = get_all_apps_ids(&app_ids, &app_ids_cnt);
-               if (ret != PC_OPERATION_SUCCESS)
+               if (ret != PC_OPERATION_SUCCESS) {
+                       C_LOGE("get_all_aps_ids failed.");
                        return ret;
+               }
 
                for (i = 0; i < app_ids_cnt; ++i) {
-                       SECURE_SLOGD("Allowing app %s to access public path %s", app_ids[i], path);
+                       SECURE_C_LOGD("Allowing app %s to access public path %s", app_ids[i], path);
                        ret = app_add_rule(app_ids[i], label, "rx");
                        if (ret != PC_OPERATION_SUCCESS) {
                                C_LOGE("smack_accesses_new failed");
@@ -1818,6 +1990,7 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
 
        case APP_PATH_SETTINGS_RW:
        {
+               C_LOGD("app_path_type is APP_PATH_SETTINGS_RW.");
                char **app_ids AUTO_FREE;
                int app_ids_cnt = 0;
                const char *label;
@@ -1826,8 +1999,10 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
 
                /*get path id*/
                label = smack_label_for_path(pkg_id, path);
-               if (label == NULL)
+               if (label == NULL) {
+                       C_LOGE("smack_label_for_path failed.");
                        return PC_ERR_INVALID_OPERATION;
+               }
 
                /*set id for path and all subfolders*/
                C_LOGD("Appsetting: generated label '%s' for setting path %s", label, path);
@@ -1872,12 +2047,14 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
        }
 
        case APP_PATH_ANY_LABEL: {
+               C_LOGD("app_path_type is APP_PATH_ANY_LABEL.");
                const char *label = NULL;
                label = va_arg(ap, const char *);
                return app_label_dir(label, path);
        }
 
        default:
+               C_LOGE("app_path_type is invalid.");
                return PC_ERR_INVALID_PARAM;
        }
 
@@ -1888,17 +2065,23 @@ static int perm_app_setup_path_internal(const char* pkg_id, const char* path, ap
 
 API int app_setup_path(const char* pkg_id, const char* path, app_path_type_t app_path_type, ...)//deprecated
 {
-    va_list ap;
-    int ret;
-    va_start( ap, app_path_type );
-    ret = perm_app_setup_path_internal( pkg_id, path, app_path_type, ap );
-    va_end( ap );
-    return ret;
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, path=%s, app_path_type=%d",
+                               __func__, pkg_id, path, app_path_type);
+
+       va_list ap;
+       int ret;
+       va_start( ap, app_path_type );
+       ret = perm_app_setup_path_internal( pkg_id, path, app_path_type, ap );
+       va_end( ap );
+       return ret;
 }
 
 
 API int perm_app_setup_path(const char* pkg_id, const char* path, app_path_type_t app_path_type, ...)
 {
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s, path=%s, app_path_type=%d",
+                               __func__, pkg_id, path, app_path_type);
+
        va_list ap;
        int ret;
        va_start( ap, app_path_type );
@@ -1907,20 +2090,25 @@ API int perm_app_setup_path(const char* pkg_id, const char* path, app_path_type_
        return ret;
 }
 
-
-
 API int app_add_friend(const char* pkg_id1, const char* pkg_id2)//deprecated
 {
-    return perm_app_add_friend(pkg_id1, pkg_id2);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id1=%s, pkg_id2=%s",
+                               __func__, pkg_id1, pkg_id2);
+
+       return perm_app_add_friend(pkg_id1, pkg_id2);
 }
 
 API int perm_app_add_friend(const char* pkg_id1, const char* pkg_id2)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id1=%s, pkg_id2=%s",
+                               __func__, pkg_id1, pkg_id2);
+
        int ret;
 
-       if (!smack_label_is_valid(pkg_id1) || !smack_label_is_valid(pkg_id2))
+       if (!smack_label_is_valid(pkg_id1) || !smack_label_is_valid(pkg_id2)) {
+               C_LOGE("Invalid pkg_id1 or pkg_id2.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        ret = app_add_rule(pkg_id1, pkg_id2, "rwxat");
        if (ret != PC_OPERATION_SUCCESS) {
@@ -1939,23 +2127,32 @@ API int perm_app_add_friend(const char* pkg_id1, const char* pkg_id2)
 
 API int app_install(const char* pkg_id)//deprecated
 {
-    return perm_app_install(pkg_id);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s",
+                               __func__, pkg_id);
+
+       return perm_app_install(pkg_id);
 }
 
 API int perm_app_install(const char* pkg_id)
 {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s",
+                               __func__, pkg_id);
+
        int ret;
        int fd AUTO_CLOSE;
        char* smack_path AUTO_FREE;
        struct smack_accesses *smack AUTO_SMACK_FREE;
 
-       if (!smack_label_is_valid(pkg_id))
+       if (!smack_label_is_valid(pkg_id)) {
+               C_LOGE("Invalid param pkg_id.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        ret = smack_file_name(pkg_id, &smack_path);
-       if (ret != PC_OPERATION_SUCCESS)
+       if (ret != PC_OPERATION_SUCCESS) {
+               C_LOGE("smack_file_name failed.");
                return ret;
+       }
 
        ret = load_smack_from_file(pkg_id, &smack, &fd, &smack_path);
        if (ret != PC_OPERATION_SUCCESS) {
@@ -1965,25 +2162,25 @@ API int perm_app_install(const char* pkg_id)
 
        ret = add_app_id_to_databse(pkg_id);
        if (ret != PC_OPERATION_SUCCESS ) {
-               SECURE_SLOGE("Error while adding app %s to database: %s ", pkg_id, strerror(errno));
+               SECURE_C_LOGE("Error while adding app %s to database: %s ", pkg_id, strerror(errno));
                return ret;
        }
 
        ret = register_app_for_av(pkg_id);
        if (ret != PC_OPERATION_SUCCESS) {
-               SECURE_SLOGE("Error while adding rules for anti viruses to app %s: %s ", pkg_id, strerror(errno));
+               SECURE_C_LOGE("Error while adding rules for anti viruses to app %s: %s ", pkg_id, strerror(errno));
                return ret;
        }
 
        ret = register_app_for_appsetting(pkg_id);
        if (ret != PC_OPERATION_SUCCESS) {
-               SECURE_SLOGE("Error while adding rules for setting managers to app %s: %s ", pkg_id, strerror(errno));
+               SECURE_C_LOGE("Error while adding rules for setting managers to app %s: %s ", pkg_id, strerror(errno));
                return ret;
        }
 
        ret = register_app_for_public_dirs(pkg_id, smack);
        if (ret != PC_OPERATION_SUCCESS) {
-               SECURE_SLOGE("Error while adding rules for access to public dirs for app %s: %s ", pkg_id, strerror(errno));
+               SECURE_C_LOGE("Error while adding rules for access to public dirs for app %s: %s ", pkg_id, strerror(errno));
                return ret;
        }
 
@@ -2002,7 +2199,10 @@ API int perm_app_install(const char* pkg_id)
 
 API int app_uninstall(const char* pkg_id)//deprecated
 {
-    return perm_app_uninstall(pkg_id);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s",
+                               __func__, pkg_id);
+
+       return perm_app_uninstall(pkg_id);
 }
 
 API int perm_app_uninstall(const char* pkg_id)
@@ -2010,33 +2210,40 @@ API int perm_app_uninstall(const char* pkg_id)
        // TODO: When real database will be used, then this function should remove app_id
        //       from database.
        //       It also should remove rules like: "anti_virus_label app_id rwx".
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: pkg_id=%s", __func__, pkg_id);
        char* smack_path AUTO_FREE;
        int ret;
 
-       if (!smack_label_is_valid(pkg_id))
+       if (!smack_label_is_valid(pkg_id)) {
+               C_LOGE("Invalid param pkg_id.");
                return PC_ERR_INVALID_PARAM;
+       }
 
        ret = smack_file_name(pkg_id, &smack_path);
-       if (ret != PC_OPERATION_SUCCESS)
+       if (ret != PC_OPERATION_SUCCESS) {
+               C_LOGE("smack_file_name failed.");
                return ret;
+       }
 
        if (unlink(smack_path)) {
-               C_LOGE("unlink failed", strerror(errno));
+               C_LOGE("unlink failed (error: %s)", strerror(errno));
                return PC_OPERATION_SUCCESS;
        }
 
        ret = app_uninstall_remove_early_rules(pkg_id);
-       if (ret != PC_OPERATION_SUCCESS)
+       if (ret != PC_OPERATION_SUCCESS) {
+               C_LOGE("app_uninstall_remove_early_rules failed.");
                return ret;
-
+       }
 
        return PC_OPERATION_SUCCESS;
 }
 
 static int save_rules(int fd, struct smack_accesses* accesses) {
+       SECURE_C_LOGD("Entering function: %s. Params: fd=%d", __func__, fd);
+
        if (flock(fd, LOCK_EX)) {
-               C_LOGE("flock failed, error %s", strerror(errno));
+               C_LOGE("flock failed (error: %s)", strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -2048,6 +2255,9 @@ static int save_rules(int fd, struct smack_accesses* accesses) {
 }
 
 static int validate_and_add_rule(char* rule, struct smack_accesses* accesses) {
+       SECURE_C_LOGD("Entering function: %s. Params: rule=%s",
+                               __func__, rule);
+
        const char* subject = NULL;
        const char* object = NULL;
        const char* access = NULL;
@@ -2078,6 +2288,9 @@ static int validate_and_add_rule(char* rule, struct smack_accesses* accesses) {
 
 static int parse_and_save_rules(const char** smack_rules,
                struct smack_accesses* accesses, const char* feature_file) {
+       SECURE_C_LOGD("Entering function: %s. Params: feature_file=%s",
+                               __func__, feature_file);
+
        size_t i = 0;
        int fd = 0;
        int ret = PC_OPERATION_SUCCESS;
@@ -2098,7 +2311,7 @@ static int parse_and_save_rules(const char** smack_rules,
        // save to file
        fd = open(feature_file, O_CREAT | O_WRONLY, 0644);
        if (fd == -1) {
-               C_LOGE("Unable to create file %s. Error: %s", feature_file, strerror(errno));
+               SECURE_C_LOGE("Unable to create file %s. (error: %s)", feature_file, strerror(errno));
                return PC_ERR_FILE_OPERATION;
        }
 
@@ -2108,6 +2321,7 @@ static int parse_and_save_rules(const char** smack_rules,
 }
 
 static int save_gids(FILE* file, const gid_t* list_of_db_gids, size_t list_size) {
+       SECURE_C_LOGD("Entering function: %s.", __func__);
        int ret = PC_OPERATION_SUCCESS;
        int written = 0;
        size_t i = 0;
@@ -2139,6 +2353,9 @@ API int add_api_feature(app_type_t app_type,
                         const gid_t* list_of_db_gids,
                         size_t list_size)//deprecated
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d, api_feature_name=%s",
+                               __func__, app_type, api_feature_name);
+
     return perm_add_api_feature(app_type, api_feature_name, smack_rules, list_of_db_gids, list_size);
 }
 
@@ -2147,7 +2364,8 @@ API int perm_add_api_feature(app_type_t app_type,
                                                const char** smack_rules,
                                                const gid_t* list_of_db_gids,
                                                size_t list_size) {
-       C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s. Params: app_type=%d, api_feature_name=%s",
+                               __func__, app_type, api_feature_name);
 
        int ret = PC_OPERATION_SUCCESS;
        char* smack_file AUTO_FREE;
@@ -2160,6 +2378,7 @@ API int perm_add_api_feature(app_type_t app_type,
        // get feature SMACK file name
        ret = perm_file_path(&smack_file, app_type, api_feature_name, ".smack", 0);
        if (ret != PC_OPERATION_SUCCESS || !smack_file ) {
+               C_LOGE("perm_file_path failed.");
                return ret;
        }
 
@@ -2174,6 +2393,7 @@ API int perm_add_api_feature(app_type_t app_type,
                // get feature DAC file name
                ret = perm_file_path(&dac_file, app_type, api_feature_name, ".dac", 0);
                if (ret != PC_OPERATION_SUCCESS || !dac_file ) {
+                       C_LOGE("perm_file_path failed.");
                        return ret;
                }
 
@@ -2198,6 +2418,7 @@ API int perm_add_api_feature(app_type_t app_type,
        // go through gid list
        if (ret == PC_OPERATION_SUCCESS && list_of_db_gids && list_size > 0) {
                // save to file
+               SECURE_C_LOGD("Opening file %s.", dac_file);
                file = fopen(dac_file, "w+");
                ret = save_gids(file, list_of_db_gids, list_size);
                fclose(file);
@@ -2219,6 +2440,9 @@ API int perm_add_api_feature(app_type_t app_type,
  */
 API int app_register_av(const char* app_av_id)//deprecated
 {
+       SECURE_C_LOGD("Entering function: %s. Params: app_av_id=%s",
+                               __func__, app_av_id);
+
        int ret;
        int fd AUTO_CLOSE;
        char* smack_path AUTO_FREE;
@@ -2267,5 +2491,5 @@ API int app_register_av(const char* app_av_id)//deprecated
                return ret;
        }
 
-    return ret;
+       return ret;
 }
index d8147de..78598bd 100644 (file)
 // conditional log macro for dlogutil (debug)
 #ifdef DLOG_DEBUG_ENABLED
 #define C_LOGD(...) SLOGD(__VA_ARGS__)
+#define SECURE_C_LOGD(...) SECURE_SLOGD(__VA_ARGS__)
 #else
 #define C_LOGD(...) do { } while(0)
+#define SECURE_C_LOGD(...) do { } while(0)
 #endif //DLOG_DEBUG_ENABLED
 
 // conditional log macro for dlogutil (error)
 #ifdef DLOG_ERROR_ENABLED
 #define C_LOGE(...) SLOGE(__VA_ARGS__)
+#define SECURE_C_LOGE(...) SECURE_SLOGE(__VA_ARGS__)
 #else
 #define C_LOGE(...) do { } while(0)
+#define SECURE_C_LOGE(...) do { } while(0)
 #endif //DLOG_ERROR_ENABLED
 
 void print_usage(void)
 {
-    C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s.", __func__);
        printf("%s", "Usage: slp-su [PKG_NAME]\n\n");
        printf("%s", "Execute new shell which be belonged to user related with PKG_NAME\n\n");
 }
 
 int main(int argc, char* argv[])
 {
-    C_LOGD("Enter function: %s", __func__);
+       SECURE_C_LOGD("Entering function: %s.", __func__);
        pid_t pid = -1;
        char* buf = NULL;