summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBaptiste DURAND <baptiste.durand@gmail.com>2015-01-09 10:01:53 +0100
committerBaptiste DURAND <baptiste.durand@open.eurogiciel.org>2015-01-09 10:04:31 +0100
commit6dfcab4e7cf57a0cb96da6f2b6e95a8ed6b5ff19 (patch)
treea160923d81ad317f81eb11967e5826fdf932c200
parent19baeb3cdc026c400eef251ab4df53d2c3c05cf9 (diff)
downloadalarm-manager-6dfcab4e7cf57a0cb96da6f2b6e95a8ed6b5ff19.tar.gz
alarm-manager-6dfcab4e7cf57a0cb96da6f2b6e95a8ed6b5ff19.tar.bz2
alarm-manager-6dfcab4e7cf57a0cb96da6f2b6e95a8ed6b5ff19.zip
Fix App svc API Call
Retreive the uid from the owner of PID proc file. This permits to get the user that launched the app Signed-off-by: Baptiste DURAND <baptiste.durand@open.eurogiciel.org> Change-Id: I6863537bdb105618bcd7b9c648f2cad7e333f6c4
-rw-r--r--alarm-manager.c60
-rw-r--r--include/alarm-internal.h2
2 files changed, 57 insertions, 5 deletions
diff --git a/alarm-manager.c b/alarm-manager.c
index 0e3b187..f6aef71 100644
--- a/alarm-manager.c
+++ b/alarm-manager.c
@@ -682,7 +682,7 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
char caller_appid[512];
bundle_raw *b_data = NULL;
int datalen = 0;
-
+ uid_t uid;
__alarm_info_t *__alarm_info = NULL;
__alarm_info = malloc(sizeof(__alarm_info_t));
@@ -693,9 +693,19 @@ static bool __alarm_create_appsvc(alarm_info_t *alarm_info, alarm_id_t *alarm_id
failed internally. */
return false;
}
+ uid = _proc_get_usr_bypid(pid);
__alarm_info->pid = pid;
__alarm_info->alarm_id = -1;
-
+ if( uid < 0 ){ /* failure */
+ ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
+ "killed, so we failed to get proc owner and do not create "
+ "alarm_info\n", pid);
+ *error_code = -1; /*-1 means that system failed
+ internally.*/
+ free(__alarm_info);
+ return false;
+ } else
+ __alarm_info->uid = uid;
/* we should consider to check whether pid is running or Not
*/
@@ -840,6 +850,7 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
char app_name[256] = { 0 };
char *word = NULL;
char *proc_name_ptr = NULL;
+ uid_t uid;
__alarm_info_t *__alarm_info = NULL;
@@ -851,9 +862,19 @@ static bool __alarm_create(alarm_info_t *alarm_info, alarm_id_t *alarm_id,
failed internally. */
return false;
}
+ uid = _proc_get_usr_bypid(pid);
__alarm_info->pid = pid;
__alarm_info->alarm_id = -1;
-
+ if( uid < 0 ){ /* failure */
+ ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
+ "killed, so we failed to get proc owner and do not create "
+ "alarm_info\n", pid);
+ *error_code = -1; /*-1 means that system failed
+ internally.*/
+ free(__alarm_info);
+ return false;
+ } else
+ __alarm_info->uid = uid;
/* we should consider to check whether pid is running or Not
*/
memset(process_name, '\0', 512);
@@ -999,6 +1020,7 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
{
time_t current_time;
time_t due_time;
+ uid_t uid;
__alarm_info_t *__alarm_info = NULL;
bool result = false;
@@ -1011,10 +1033,21 @@ static bool __alarm_update(int pid, char *app_service_name, alarm_id_t alarm_id,
internally.*/
return false;
}
-
+ uid = _proc_get_usr_bypid(pid);
__alarm_info->pid = pid;
__alarm_info->alarm_id = alarm_id;
+ if( uid < 0 ){ /* failure */
+ ALARM_MGR_EXCEPTION_PRINT("Caution!! app_pid(%d) seems to be "
+ "killed, so we failed to get proc owner and do not create "
+ "alarm_info\n", pid);
+ *error_code = -1; /*-1 means that system failed
+ internally.*/
+ free(__alarm_info);
+ return false;
+ } else
+ __alarm_info->uid = uid;
+
/* we should consider to check whether pid is running or Not
*/
@@ -1446,7 +1479,7 @@ static void __alarm_expired()
}
else
{
- if ( appsvc_run_service(b, 0, NULL, NULL) < 0)
+ if ( appsvc_run_service(b, 0, NULL, NULL, __alarm_info->uid) < 0)
{
ALARM_MGR_EXCEPTION_PRINT("Unable to run app svc\n");
}
@@ -2920,6 +2953,23 @@ static bool __check_false_alarm()
}
#endif
+
+uid_t _proc_get_usr_bypid(int pid)
+{
+ char buf[255];
+ int ret;
+ uid_t uid;
+ struct stat dir_stats;
+ snprintf(buf, sizeof(buf), "/proc/%d", pid);
+ ret = stat(buf, &dir_stats);
+ if (ret < 0)
+ uid = (uid_t)-1;
+ else
+ uid = dir_stats.st_uid;
+ return uid;
+}
+
+
int main()
{
GMainLoop *mainloop = NULL;
diff --git a/include/alarm-internal.h b/include/alarm-internal.h
index 4f65c1f..62ae476 100644
--- a/include/alarm-internal.h
+++ b/include/alarm-internal.h
@@ -154,6 +154,7 @@ typedef struct {
int alarm_id;
int pid;
+ uid_t uid;
GQuark quark_app_unique_name; /*the fullpath of application's pid is
converted to quark value.*/
GQuark quark_app_service_name; /*dbus_service_name is converted to
@@ -219,6 +220,7 @@ int _set_sys_time(time_t _time);
int _set_time(time_t _time);
time_t _alarm_time(time_t *tp);
+uid_t _proc_get_usr_bypid(int pid);
#ifdef _DEBUG_MODE_