From fb37c0555ff6473009a447fdfcb062e77b93ab42 Mon Sep 17 00:00:00 2001 From: "seolhee, kim" Date: Mon, 4 Jul 2016 20:20:50 +0900 Subject: [PATCH 01/16] Add setup-wizard password verify button callback Change-Id: Ifc4910e2d440cb46563f90259758c57f6aac5823 Signed-off-by: seolhee, kim --- tools/apps/setup-wizard/res/edje/security.edc | 10 ++++ tools/apps/setup-wizard/src/security.c | 66 ++++++++++++++++++++++++--- 2 files changed, 70 insertions(+), 6 deletions(-) diff --git a/tools/apps/setup-wizard/res/edje/security.edc b/tools/apps/setup-wizard/res/edje/security.edc index 03cf068..3cdb12d 100644 --- a/tools/apps/setup-wizard/res/edje/security.edc +++ b/tools/apps/setup-wizard/res/edje/security.edc @@ -48,5 +48,15 @@ group { name: "security_layout"; rel2 { relative: 1.0 1.0; to: "entry"; offset: 0 2;} } } + part { name: "entry_info"; + type: TEXT; + scale: 0; + description { state: "default" 0.0; + color: 140 140 140 255; + rel1 { relative: 0.0 0.3; to: "bg"; offset: 45 22;} + rel2 { relative: 1.0 0.3; to: "bg"; offset: -45 62;} + text { font: "Tizen:style=Regular"; size: "32"; align: 0.0 0.5; } + } + } } } diff --git a/tools/apps/setup-wizard/src/security.c b/tools/apps/setup-wizard/src/security.c index 75d11ce..80fe455 100644 --- a/tools/apps/setup-wizard/src/security.c +++ b/tools/apps/setup-wizard/src/security.c @@ -48,6 +48,7 @@ static unsigned int security_passphrase_mode = PASSPHRASE_STATE_UNDEFINED; static int security_lock_type_selected = 0; static void create_password_setup_view(appdata_s *ad); +static void security_password_entry_changed_cb(void *data, Evas_Object *obj, void *event_info); static char *security_multiline_text_get(void *data, Evas_Object *obj, const char *part) { @@ -134,34 +135,59 @@ static void security_lock_type_select_cb(void *data, Evas_Object *obj, void *eve security_lock_type_selected = locktype->index; } -static Eina_Bool security_pop_cb(void *data, Elm_Object_Item *it) +static Eina_Bool security_view_pop_cb(void *data, Elm_Object_Item *it) { elm_object_signal_emit(ud.conform, "elm,state,indicator,overlap", "elm"); return EINA_TRUE; } -static void security_previous_view_cb(void *data, Evas_Object *obj, void *event_info) +static Eina_Bool password_view_pop_cb(void *data, Elm_Object_Item *it) { if (security_passphrase_mode != PASSPHRASE_STATE_UNDEFINED) { - security_passphrase_mode--; - } + Evas_Object *entry = (Evas_Object *)evas_object_data_get(ud.nf, "setup_entry"); + evas_object_smart_callback_add(entry, "changed", security_password_entry_changed_cb, NULL); + security_passphrase_mode--; + } + return EINA_TRUE; +} + +static void delete_object_data(void) +{ + evas_object_data_del(ud.nf, "setup_entry"); + evas_object_data_del(ud.nf, "setup_button"); + evas_object_data_del(ud.nf, "verify_entry"); + evas_object_data_del(ud.nf, "verify_button"); +} + +static void security_previous_view_cb(void *data, Evas_Object *obj, void *event_info) +{ elm_naviframe_item_pop(ud.nf); } static void security_password_setup_cb(void *data, Evas_Object *obj, void *event_info) { appdata_s *ad = (appdata_s *)data; + Evas_Object *entry; if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY) { security_passphrase_mode++; + entry = (Evas_Object *)evas_object_data_get(ud.nf, "setup_entry"); + evas_object_smart_callback_del(entry, "changed", security_password_entry_changed_cb); create_password_setup_view(ad); return; } if (strcmp(security_password_setup_data, security_password_verify_data) != 0) { + entry = (Evas_Object *)evas_object_data_get(ud.nf, "verify_entry"); + elm_entry_entry_set(entry, ""); + elm_entry_input_panel_hide(entry); + + Evas_Object *layout = (Evas_Object *)evas_object_data_get(ud.nf, "layout"); + elm_object_part_text_set(layout, "entry_info", "Password do not matched."); dlog_print(DLOG_ERROR, LOG_TAG, "Password not matched"); return; } + delete_object_data(); ad->zone_password = security_password_setup_data; @@ -179,6 +205,22 @@ static void security_password_entry_unfocused_cb(void *data, Evas_Object *obj, v *password = strdup(elm_entry_entry_get(obj)); } +static void security_password_entry_changed_cb(void *data, Evas_Object *obj, void *event_info) +{ + Evas_Object *button; + const char *entry_data = elm_entry_entry_get(obj); + + if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY) + button = (Evas_Object *)evas_object_data_get(ud.nf, "setup_button"); + else + button = (Evas_Object *)evas_object_data_get(ud.nf, "verify_button"); + + if (strlen(entry_data) > 1) + elm_object_disabled_set(button, EINA_FALSE); + else + elm_object_disabled_set(button, EINA_TRUE); +} + static Evas_Object *security_password_setup_content_get(void *data, Evas_Object *obj, const char *part) { if (!strcmp(part, "elm.swallow.content")) { @@ -190,6 +232,15 @@ static Evas_Object *security_password_setup_content_get(void *data, Evas_Object elm_object_part_text_set(layout, "title", "Enter password"); elm_object_part_content_set(layout, "entry", entry); evas_object_smart_callback_add(entry, "unfocused", security_password_entry_unfocused_cb, data); + evas_object_smart_callback_add(entry, "changed", security_password_entry_changed_cb, NULL); + elm_entry_input_panel_return_key_disabled_set(entry, EINA_TRUE); + + if (security_passphrase_mode < PASSPHRASE_STATE_VERIFY) + evas_object_data_set(ud.nf, "setup_entry", entry); + else + evas_object_data_set(ud.nf, "verify_entry", entry); + + evas_object_data_set(ud.nf, "layout", layout); return layout; } @@ -213,16 +264,18 @@ static void create_password_setup_view(appdata_s *ad) left_button = _create_button(layout, PREV_BUTTON, security_previous_view_cb, NULL); right_button = _create_button(layout, NEXT_BUTTON, security_password_setup_cb, ad); + elm_object_disabled_set(right_button, EINA_TRUE); - //elm_object_disabled_set(right_button, EINA_TRUE); _create_two_button_layout(layout, left_button, right_button); if (security_passphrase_mode == 1) { entry = &security_password_setup_data; title = "Setup Password"; + evas_object_data_set(ud.nf, "setup_button", right_button); } else { entry = &security_password_verify_data; title = "Verify Password"; + evas_object_data_set(ud.nf, "verify_button", right_button); } itc = _create_genlist_item_class("full", NULL, security_password_setup_content_get); @@ -230,6 +283,7 @@ static void create_password_setup_view(appdata_s *ad) item = elm_naviframe_item_push(ud.nf, title, NULL, NULL, layout, NULL); elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE); + elm_naviframe_item_pop_cb_set(item, password_view_pop_cb, NULL); } void _create_security_view(appdata_s *ad) @@ -281,5 +335,5 @@ void _create_security_view(appdata_s *ad) item = elm_naviframe_item_push(ud.nf, "Krate Security", NULL, NULL, layout, NULL); elm_naviframe_item_title_enabled_set(item, EINA_TRUE, EINA_TRUE); - elm_naviframe_item_pop_cb_set(item, security_pop_cb, NULL); + elm_naviframe_item_pop_cb_set(item, security_view_pop_cb, NULL); } -- 2.7.4 From dcc39e6148164d1b870297ae60b35a5fde2dae62 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Thu, 7 Jul 2016 21:47:12 +0900 Subject: [PATCH 02/16] Fix crashes when app is terminated with loading apps list Change-Id: Ia620828326d2f524f07e331c860c0896c7b5e6d9 Signed-off-by: Sungbae Yoo --- tools/apps/kaskit/include/kaskit.h | 1 + tools/apps/kaskit/src/main.c | 1 + tools/apps/kaskit/src/ui.c | 10 +++++++--- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/tools/apps/kaskit/include/kaskit.h b/tools/apps/kaskit/include/kaskit.h index da05681..1b55224 100644 --- a/tools/apps/kaskit/include/kaskit.h +++ b/tools/apps/kaskit/include/kaskit.h @@ -52,6 +52,7 @@ typedef struct { void _create_kaskit_window(); void _set_kaskit_window_title(const char *title); +void _set_kaskit_window_exit_cb(); void _create_app_icon(const char* pkg_id, const char* app_id, const char* label, const char* icon, bool removable); void _destroy_app_icon(const char* pkg_id); diff --git a/tools/apps/kaskit/src/main.c b/tools/apps/kaskit/src/main.c index 4312f3f..8b1018c 100644 --- a/tools/apps/kaskit/src/main.c +++ b/tools/apps/kaskit/src/main.c @@ -127,6 +127,7 @@ static void __create_icon_thread(void* data, Ecore_Thread* thread) { if (data != NULL) { free(data); } + _set_kaskit_window_exit_cb(); } static void __pkg_event_cb(const char* type, diff --git a/tools/apps/kaskit/src/ui.c b/tools/apps/kaskit/src/ui.c index d78d61e..700062d 100644 --- a/tools/apps/kaskit/src/ui.c +++ b/tools/apps/kaskit/src/ui.c @@ -97,9 +97,6 @@ void _create_kaskit_window() ud.conform = _create_conformant(ud.win); ud.layout = _create_layout(ud.conform, ud.edj_path, "main_window"); elm_object_content_set(ud.conform, ud.layout); - eext_object_event_callback_add(ud.win, EEXT_CALLBACK_BACK, __back_key_cb, NULL); - - elm_object_signal_callback_add(ud.layout, "bg_clicked", "layout", __block_clicked_cb, NULL); __set_kaskit_layout(); @@ -108,6 +105,13 @@ void _create_kaskit_window() return; } +void _set_kaskit_window_exit_cb() +{ + eext_object_event_callback_add(ud.win, EEXT_CALLBACK_BACK, __back_key_cb, NULL); + + elm_object_signal_callback_add(ud.layout, "bg_clicked", "layout", __block_clicked_cb, NULL); +} + static Eina_Bool __app_icon_long_press_cb(void *data) { Evas_Object* icon; -- 2.7.4 From 2cfed7a8fc7e3e5a509237c9ea1473f62a219904 Mon Sep 17 00:00:00 2001 From: "seolhee, kim" Date: Thu, 7 Jul 2016 20:11:23 +0900 Subject: [PATCH 03/16] Add setup-wizard container fail event Change-Id: I90643fa486ea455d0a1e24bb81cadeb5dde2369e Signed-off-by: seolhee, kim --- tools/apps/setup-wizard/include/krate-setup.h | 2 ++ tools/apps/setup-wizard/include/setup-text.h | 5 ++++ tools/apps/setup-wizard/include/widget.h | 1 + tools/apps/setup-wizard/src/main.c | 6 +++- tools/apps/setup-wizard/src/ui.c | 41 ++++++++++++++++++++------- tools/apps/setup-wizard/src/widget.c | 18 ++++++++++-- 6 files changed, 60 insertions(+), 13 deletions(-) diff --git a/tools/apps/setup-wizard/include/krate-setup.h b/tools/apps/setup-wizard/include/krate-setup.h index 66fa072..a003d41 100644 --- a/tools/apps/setup-wizard/include/krate-setup.h +++ b/tools/apps/setup-wizard/include/krate-setup.h @@ -61,6 +61,7 @@ typedef struct { } appdata_s; typedef struct { + Evas_Object *win; Evas_Object *conform; Evas_Object *nf; char *edj_path; @@ -74,5 +75,6 @@ void _create_two_button_layout(Evas_Object *parent, Evas_Object *left_button, Ev int _send_zone_create_request(appdata_s *ad); int _send_zone_remove_request(appdata_s *ad); void _create_notification(app_control_h app_control); +void *zone_request_fail(void *ad); #endif /* __ZONE_SETUP_H__ */ diff --git a/tools/apps/setup-wizard/include/setup-text.h b/tools/apps/setup-wizard/include/setup-text.h index 4e8b7e6..7d96ad8 100644 --- a/tools/apps/setup-wizard/include/setup-text.h +++ b/tools/apps/setup-wizard/include/setup-text.h @@ -50,4 +50,9 @@ #define PREV_BUTTON "Previous" #define REMOVE_BUTTON "Remove" +#define OK_BUTTON "OK" +#define SETUP_POPUP_HEADER "Setup Wizard" +#define BODY_ZONE_CREATE_ERROR "Failed to create the Separated Zone." +#define BODY_ZONE_REMOVE_ERROR "Failed to remove the Separated Zone." + #endif /*__SETUP_TEXT_H__*/ diff --git a/tools/apps/setup-wizard/include/widget.h b/tools/apps/setup-wizard/include/widget.h index 040c969..de65535 100644 --- a/tools/apps/setup-wizard/include/widget.h +++ b/tools/apps/setup-wizard/include/widget.h @@ -32,6 +32,7 @@ Evas_Object *_create_button(Evas_Object *parent, const char *text, Evas_Smart_Cb Evas_Object *_create_textblock(Evas_Object *parent, const char *text, char *style); Evas_Object *_create_progressbar(Evas_Object *parent, const char *style); Evas_Object *_create_entry(Evas_Object *parent); +Evas_Object *_create_popup(Evas_Object *parent, const char *title, const char *body); Elm_Genlist_Item_Class *_create_genlist_item_class(char *style, Elm_Genlist_Item_Text_Get_Cb text_func, Elm_Genlist_Item_Content_Get_Cb content_func); Elm_Object_Item *_append_genlist_item(Evas_Object *genlist, Elm_Genlist_Item_Class *itc, Elm_Object_Select_Mode select_mode, void* data); diff --git a/tools/apps/setup-wizard/src/main.c b/tools/apps/setup-wizard/src/main.c index a3b3ff0..658ed80 100644 --- a/tools/apps/setup-wizard/src/main.c +++ b/tools/apps/setup-wizard/src/main.c @@ -19,7 +19,7 @@ #include "krate-setup.h" #include "widget.h" -static void __launch_zone_app(zone_manager_h zone_mgr, const char* zone_name, app_control_h app_control) +static void __launch_zone_app(zone_manager_h zone_mgr, const char *zone_name, app_control_h app_control) { zone_app_proxy_h zone_app; @@ -34,6 +34,10 @@ static void __zone_request_done(const char *from, const char *info, void *user_d char uri[PATH_MAX]; appdata_s *ad = (appdata_s *) user_data; + if (!strcmp(info, "Error")) { + ecore_main_loop_thread_safe_call_sync(zone_request_fail, ad); + return; + } if (!strcmp(ad->mode, "create")) { zone_manager_reset_zone_password(ad->zone_manager, ad->zone_name, ad->zone_password); diff --git a/tools/apps/setup-wizard/src/ui.c b/tools/apps/setup-wizard/src/ui.c index 0189711..c8a4937 100644 --- a/tools/apps/setup-wizard/src/ui.c +++ b/tools/apps/setup-wizard/src/ui.c @@ -33,7 +33,7 @@ static Eina_Bool __naviframe_pop_cb(void *data, Elm_Object_Item *it) return EINA_FALSE; } -static void __welcome_cancel_cb(void *data, Evas_Object *obj, void *event_info) +static void setup_wizard_cancel_cb(void *data, Evas_Object *obj, void *event_info) { appdata_s *ad = (appdata_s *)data; @@ -43,15 +43,17 @@ static void __welcome_cancel_cb(void *data, Evas_Object *obj, void *event_info) return; } -static void __welcome_next_cb(void *data, Evas_Object *obj, void *event_info) +static void setup_wizard_next_cb(void *data, Evas_Object *obj, void *event_info) { appdata_s *ad = (appdata_s *)data; if (!strcmp(ad->mode, "create")) { _create_security_view(ad); } else { - if (_send_zone_remove_request(ad) != 0) - ui_app_exit(); + if (_send_zone_remove_request(ad) != 0) { + ecore_main_loop_thread_safe_call_sync(zone_request_fail, ad); + return; + } _create_setup_view(ad); } @@ -94,9 +96,28 @@ static Eina_Bool __progressbar_timer_cb(void *data) return ECORE_CALLBACK_RENEW; } +void *zone_request_fail(void *user_data) +{ + Evas_Object *popup = NULL; + appdata_s *ad = (appdata_s *)user_data; + + if (!strcmp(ad->mode, "create")) + popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_ZONE_CREATE_ERROR); + else + popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_ZONE_REMOVE_ERROR); + + Evas_Object *btn = elm_button_add(popup); + elm_object_style_set(btn, "popup"); + elm_object_text_set(btn, OK_BUTTON); + evas_object_smart_callback_add(btn, "clicked", setup_wizard_cancel_cb, ad); + elm_object_part_content_set(popup, "button1", btn); + evas_object_show(popup); + + return NULL; +} + void _create_base_window(appdata_s *ad) { - Evas_Object *win; Evas_Object *layout; char edj_path[PATH_MAX] = "\0"; @@ -117,8 +138,8 @@ void _create_base_window(appdata_s *ad) free(res_path); /* Create main UI widget */ - win = _create_win(PACKAGE); - ud.conform = _create_conformant(win); + ud.win = _create_win(PACKAGE); + ud.conform = _create_conformant(ud.win); layout = _create_layout(ud.conform, NULL, NULL); elm_object_content_set(ud.conform, layout); ud.nf = elm_naviframe_add(layout); @@ -130,7 +151,7 @@ void _create_base_window(appdata_s *ad) elm_object_part_content_set(layout, "elm.swallow.content", ud.nf); eext_object_event_callback_add(ud.nf, EEXT_CALLBACK_BACK, eext_naviframe_back_cb, NULL); - evas_object_show(win); + evas_object_show(ud.win); return; } @@ -165,8 +186,8 @@ static void __create_welcome_view(appdata_s *ad) elm_object_part_content_set(layout, "content_layout", welcome_layout); - left_button = _create_button(layout, text[2], __welcome_cancel_cb, ad); - right_button = _create_button(layout, text[3], __welcome_next_cb, ad); + left_button = _create_button(layout, text[2], setup_wizard_cancel_cb, ad); + right_button = _create_button(layout, text[3], setup_wizard_next_cb, ad); _create_two_button_layout(layout, left_button, right_button); diff --git a/tools/apps/setup-wizard/src/widget.c b/tools/apps/setup-wizard/src/widget.c index 75b8ee9..426a404 100644 --- a/tools/apps/setup-wizard/src/widget.c +++ b/tools/apps/setup-wizard/src/widget.c @@ -16,7 +16,6 @@ * limitations under the License. * */ - #include "widget.h" static void __win_delete_request_cb(void *data , Evas_Object *obj , void *event_info) @@ -30,7 +29,9 @@ Evas_Object *_create_win(const char *package) elm_app_base_scale_set(1.8); - win = elm_win_util_standard_add(package, package); + win = elm_win_add(NULL, package, ELM_WIN_BASIC); + elm_win_indicator_mode_set(win, ELM_WIN_INDICATOR_SHOW); + elm_win_conformant_set(win, EINA_TRUE); elm_win_autodel_set(win, EINA_TRUE); elm_win_alpha_set(win, EINA_TRUE); @@ -158,3 +159,16 @@ Evas_Object *_create_entry(Evas_Object *parent) evas_object_show(entry); return entry; } + +Evas_Object *_create_popup(Evas_Object *parent, const char *title, const char *body) +{ + Evas_Object *popup = elm_popup_add(parent); + + evas_object_size_hint_weight_set(popup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); + elm_object_style_set(popup, "default"); + elm_object_part_text_set(popup, "title,text", title); + elm_object_item_part_text_translatable_set(popup, "title,text", EINA_TRUE); + elm_object_text_set(popup, body); + + return popup; +} -- 2.7.4 From 6f9f0b83f4781317e9908d13bf6782fb7f5e6697 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Wed, 20 Jul 2016 16:05:01 +0900 Subject: [PATCH 04/16] Move PAM module, volume manager from device-policy-manager git Change-Id: Ib93d3ffdf839eaf5b1bb644b3328809a2d1d9fb2 Signed-off-by: Sungbae Yoo --- CMakeLists.txt | 11 +- .../DefaultManifest.xml | 0 .../indicator_icon.png | Bin .../notification_sub_icon.png | Bin module/CMakeLists.txt | 41 +- module/krate-builder.cpp | 75 +++ module/{zone-builder.h => krate-builder.h} | 35 +- module/{zone-guard.h => krate-guard.h} | 65 +- module/krate.cpp | 105 ++++ .../pam.d/{systemd-user-zone => systemd-user.in} | 2 +- module/session.cpp | 65 +- module/session.h | 10 +- module/zone-builder.cpp | 76 --- module/zone.cpp | 105 ---- packaging/krate.spec | 23 +- server/CMakeLists.txt | 7 + tools/CMakeLists.txt | 2 + tools/cli/CMakeLists.txt | 37 +- tools/cli/krate-admin-cli.cpp | 673 ++++++++++----------- .../{20_pam-krate-add.post => 20_krate-add.post} | 0 ..._pam-krate-remove.post => 20_krate-remove.post} | 0 volume/CMakeLists.txt | 33 + volume/ecryptfs.h | 107 ++++ volume/kernel-keyring.cpp | 46 ++ volume/kernel-keyring.h | 42 ++ volume/key-generator.cpp | 322 ++++++++++ volume/key-generator.h | 54 ++ volume/key-manager.cpp | 92 +++ volume/key-manager.h | 35 ++ volume/main.cpp | 194 ++++++ 30 files changed, 1593 insertions(+), 664 deletions(-) rename module/data/DefaultZoneManifest.xml => data/DefaultManifest.xml (100%) rename module/data/zone_indicator_icon.png => data/indicator_icon.png (100%) rename module/data/zone_noti_list_sub_icon.png => data/notification_sub_icon.png (100%) create mode 100644 module/krate-builder.cpp rename module/{zone-builder.h => krate-builder.h} (53%) rename module/{zone-guard.h => krate-guard.h} (50%) create mode 100644 module/krate.cpp rename module/pam.d/{systemd-user-zone => systemd-user.in} (68%) delete mode 100644 module/zone-builder.cpp delete mode 100644 module/zone.cpp rename tools/gumd-scripts/{20_pam-krate-add.post => 20_krate-add.post} (100%) rename tools/gumd-scripts/{20_pam-krate-remove.post => 20_krate-remove.post} (100%) create mode 100644 volume/CMakeLists.txt create mode 100755 volume/ecryptfs.h create mode 100755 volume/kernel-keyring.cpp create mode 100755 volume/kernel-keyring.h create mode 100755 volume/key-generator.cpp create mode 100755 volume/key-generator.h create mode 100755 volume/key-manager.cpp create mode 100644 volume/key-manager.h create mode 100755 volume/main.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index df3adf8..f3f02d5 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,13 +28,13 @@ IF(NOT CMAKE_BUILD_TYPE) SET(CMAKE_BUILD_TYPE "DEBUG") ENDIF(NOT CMAKE_BUILD_TYPE) -SET(KRATE_COMMON ${PROJECT_SOURCE_DIR}/common) SET(KRATE_API ${PROJECT_SOURCE_DIR}/api) SET(KRATE_LIB ${PROJECT_SOURCE_DIR}/lib) SET(KRATE_SERVER ${PROJECT_SOURCE_DIR}/server) -SET(KRATE_VOLUME ${PROJECT_SOURCE_DIR}/volume) +SET(KRATE_DATA ${PROJECT_SOURCE_DIR}/data) SET(KRATE_TOOLS ${PROJECT_SOURCE_DIR}/tools) SET(KRATE_MODULE ${PROJECT_SOURCE_DIR}/module) +SET(KRATE_VOLUME ${PROJECT_SOURCE_DIR}/volume) IF("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU" AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.7) SET(CXX_STD "c++0x") @@ -86,11 +86,10 @@ ENDIF(NOT DEFINED CONF_DIR) ADD_DEFINITIONS(-DUG_WAYLAND) -#ADD_SUBDIRECTORY(${KRATE_COMMON}) -ADD_SUBDIRECTORY(${KRATE_SERVER}) -#ADD_SUBDIRECTORY(${KRATE_VOLUME}) #ADD_SUBDIRECTORY(${KRATE_LIB}) -#ADD_SUBDIRECTORY(${KRATE_MODULE}) +ADD_SUBDIRECTORY(${KRATE_SERVER}) +ADD_SUBDIRECTORY(${KRATE_MODULE}) +ADD_SUBDIRECTORY(${KRATE_VOLUME}) IF("${TIZEN_PROFILE_NAME}" STREQUAL "mobile") ADD_SUBDIRECTORY(${KRATE_TOOLS}) ENDIF() diff --git a/module/data/DefaultZoneManifest.xml b/data/DefaultManifest.xml similarity index 100% rename from module/data/DefaultZoneManifest.xml rename to data/DefaultManifest.xml diff --git a/module/data/zone_indicator_icon.png b/data/indicator_icon.png similarity index 100% rename from module/data/zone_indicator_icon.png rename to data/indicator_icon.png diff --git a/module/data/zone_noti_list_sub_icon.png b/data/notification_sub_icon.png similarity index 100% rename from module/data/zone_noti_list_sub_icon.png rename to data/notification_sub_icon.png diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index d7ef612..be7a884 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -13,40 +13,39 @@ # See the License for the specific language governing permissions and # limitations under the License. # - -PROJECT(zone-provider) - -FILE(GLOB ZONE_PAM_SRCS zone-builder.cpp - session.cpp - zone.cpp +FILE(GLOB PAM_SRCS krate.cpp + session.cpp + krate-builder.cpp ) SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") -SET(ZONE_PAM_NAME "pam_zone") -ADD_LIBRARY(${ZONE_PAM_NAME} MODULE ${ZONE_PAM_SRCS}) -SET_TARGET_PROPERTIES(${ZONE_PAM_NAME} PROPERTIES PREFIX "" - COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/zone" - COMPILE_FLAGS "-fvisibility=hidden" +ADD_LIBRARY(pam_${PROJECT_NAME} MODULE ${PAM_SRCS}) +SET_TARGET_PROPERTIES(pam_${PROJECT_NAME} PROPERTIES PREFIX "" + COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/krate" + COMPILE_FLAGS "-fvisibility=hidden" ) FIND_PATH(PAM_INCLUDE_DIR NAMES security/pam_appl.h security/pam_ext.h security/pam_modules.h - HINTS ${PAM_ROOT_DIR} PATH_SUFFIXES include) + HINTS ${PAM_ROOT_DIR} PATH_SUFFIXES include) FIND_LIBRARY(PAM_LIBRARY pam HINTS ${PAM_ROOT_DIR} PATH_SUFFIXES ${LIB_INSTALL_DIR}) MARK_AS_ADVANCED(PAM_INCLUDE_DIR PAM_LIBRARY) INCLUDE(FindPackageHandleStandardArgs) FIND_PACKAGE_HANDLE_STANDARD_ARGS(PAM DEFAULT_MSG PAM_LIBRARY PAM_INCLUDE_DIR) -INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR} ${DPM_COMMON}) -TARGET_LINK_LIBRARIES(${ZONE_PAM_NAME} ${PAM_LIBRARY} dpm-common pthread) +PKG_CHECK_MODULES(PAM_DEPS REQUIRED + klay +) -TARGET_COMPILE_DEFINITIONS(${ZONE_PAM_NAME} PRIVATE - CONF_PATH="${CONF_INSTALL_DIR}" +INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR} ${PAM_DEPS_INCLUDE_DIRS}) +TARGET_LINK_LIBRARIES(pam_${PROJECT_NAME} ${PAM_LIBRARY} ${PAM_DEPS_LIBRARIES} pthread) + +TARGET_COMPILE_DEFINITIONS(pam_${PROJECT_NAME} PRIVATE + CONF_PATH="${CONF_INSTALL_DIR}" ) -INSTALL(TARGETS ${ZONE_PAM_NAME} DESTINATION ${LIB_INSTALL_DIR}/security) -INSTALL(FILES data/DefaultZoneManifest.xml DESTINATION ${CONF_INSTALL_DIR}/zone RENAME owner.xml) -INSTALL(FILES data/zone_indicator_icon.png DESTINATION /opt/data/dpm) -INSTALL(FILES data/zone_noti_list_sub_icon.png DESTINATION /opt/data/dpm) -INSTALL(FILES pam.d/systemd-user-zone DESTINATION ${PAMD_INSTALL_DIR}) +CONFIGURE_FILE(pam.d/systemd-user.in pam.d/systemd-user-${PROJECT_NAME}) + +INSTALL(TARGETS pam_${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/security) +INSTALL(FILES pam.d/systemd-user-${PROJECT_NAME} DESTINATION ${PAMD_DIR}) diff --git a/module/krate-builder.cpp b/module/krate-builder.cpp new file mode 100644 index 0000000..bbb8797 --- /dev/null +++ b/module/krate-builder.cpp @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include +#include +#include +#include +#include + +#include "krate-builder.h" + +#include +#include + +KrateBuilder::KrateBuilder(const runtime::User& user, const std::string& manifestPath) : + name(user.getName()), uid(user.getUid()), gid(user.getGid()) +{ + manifest.reset(xml::Parser::parseFile(manifestPath)); +} + +KrateBuilder::~KrateBuilder() +{ +} + +void KrateBuilder::bindFilesystemNode(const std::string& source, const std::string& target, + const std::string& type, const std::string& options, + bool create) +{ + if (create) { + runtime::File dir(target); + if (!dir.exists()) { + dir.makeDirectory(true, uid, gid); + } + } + + runtime::Mount::mountEntry(source, target, type, options); +} + +void KrateBuilder::containerize(bool create) +{ + int nsFlags = CLONE_NEWIPC | CLONE_NEWNS; + + if (::unshare(nsFlags)) { + throw runtime::Exception("Failed to unshare namespace"); + } + + if (::mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) { + throw runtime::Exception("Failed to mount root filesystem"); + } + + xml::Node::NodeList entries = manifest->evaluate("/manifest/filesystem/entry"); + for (const xml::Node& entry : entries) { + bindFilesystemNode(entry.getProp("source"), entry.getProp("target"), + entry.getProp("type"), entry.getProp("options")); + } + + bindFilesystemNode("/home/" + name, + "/home/" + name + "/.krate/" + name, + "none", "rw,bind"); + + bindFilesystemNode("/home/" + name + "/.krate", "/home", + "none", "rw,rbind"); +} diff --git a/module/zone-builder.h b/module/krate-builder.h similarity index 53% rename from module/zone-builder.h rename to module/krate-builder.h index 52b02a4..094b747 100644 --- a/module/zone-builder.h +++ b/module/krate-builder.h @@ -13,34 +13,33 @@ * See the License for the specific language governing permissions and * limitations under the License */ - - #ifndef __ZONE_BUILDER_H__ - #define __ZONE_BUILDER_H__ +#ifndef __KRATE_BUILDER_H__ +#define __KRATE_BUILDER_H__ #include #include #include -#include "xml/parser.h" -#include "xml/document.h" -#include "auth/user.h" +#include +#include +#include -class ZoneBuilder { +class KrateBuilder { public: - ZoneBuilder(const runtime::User& user, const std::string& manifestPath); - virtual ~ZoneBuilder(); + KrateBuilder(const runtime::User& user, const std::string& manifestPath); + virtual ~KrateBuilder(); - void containerize(bool create = true); + void containerize(bool create = true); protected: - void bindFilesystemNode(const std::string& source, const std::string& target, - const std::string& type, const std::string& options, - bool create = true); + void bindFilesystemNode(const std::string& source, const std::string& target, + const std::string& type, const std::string& options, + bool create = true); private: - std::string name; - uid_t uid; - gid_t gid; - std::unique_ptr manifest; + std::string name; + uid_t uid; + gid_t gid; + std::unique_ptr manifest; }; - #endif //!__ZONE_BUILDER_H__ +#endif //!__KRATE_BUILDER_H__ diff --git a/module/zone-guard.h b/module/krate-guard.h similarity index 50% rename from module/zone-guard.h rename to module/krate-guard.h index ded6ba2..8e09748 100644 --- a/module/zone-guard.h +++ b/module/krate-guard.h @@ -15,49 +15,48 @@ * */ -#ifndef __ZONE_GUARD_H__ -#define __ZONE_GUARD_H__ +#ifndef __KRATE_GUARD_H__ +#define __KRATE_GUARD_H__ -#include #include #include #include +#include #include -#include "exception.h" +#include -class ZoneGuard { +class KrateGuard { public: - ZoneGuard(const std::string& name) : - zoneName(name), - semaphore(nullptr) - { - semaphore = ::sem_open(zoneName.c_str(), O_CREAT, 0700, 1); - if (semaphore == nullptr) { - throw runtime::Exception("Filed to create semaphore for zone guard"); - } - } - - ~ZoneGuard() - { - if (semaphore == nullptr) { - return; - } - - ::sem_post(semaphore); - ::sem_close(semaphore); - ::sem_unlink(zoneName.c_str()); - } - - void wait() - { - while ((::sem_wait(semaphore) == -1) && (errno == EINTR)); - } + KrateGuard(const std::string& name) : + krateName(name), semaphore(nullptr) + { + semaphore = ::sem_open(krateName.c_str(), O_CREAT, 0700, 1); + if (semaphore == nullptr) { + throw runtime::Exception("Filed to create semaphore for krate guard"); + } + } + + ~KrateGuard() + { + if (semaphore == nullptr) { + return; + } + + ::sem_post(semaphore); + ::sem_close(semaphore); + ::sem_unlink(krateName.c_str()); + } + + void wait() + { + while ((::sem_wait(semaphore) == -1) && (errno == EINTR)); + } private: - std::string zoneName; - sem_t* semaphore; + std::string krateName; + sem_t* semaphore; }; -#endif //!__ZONE_GUARD_H__ +#endif //!__KRATE_GUARD_H__ diff --git a/module/krate.cpp b/module/krate.cpp new file mode 100644 index 0000000..06fea56 --- /dev/null +++ b/module/krate.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include +#include + +#include +#include + +#include "session.h" +#include "krate-guard.h" +#include "krate-builder.h" + +#include +#include +#include +#include + +#define KRATE_MANIFEST_DIR CONF_PATH "/krate/" + +std::string buildKrateManifestPath(const std::string& name) +{ + return KRATE_MANIFEST_DIR + name + ".xml"; +} + +std::string getKrateName(pam_handle_t* handle) +{ + const void* retItem; + int error = ::pam_get_item(handle, PAM_USER, &retItem); + if (error != PAM_SUCCESS) { + throw runtime::Exception("Failed to get user"); + } + + return static_cast(retItem); +} + +void openKrateSession(const std::string& name) +{ + auto sessionBuilder = [](const runtime::User& user) { + KrateBuilder builder(user, buildKrateManifestPath(user.getName())); + builder.containerize(); + }; + + createSession(runtime::User(name), sessionBuilder); +} + +void closeKrateSession(const std::string& name) +{ + destroySession(runtime::User(name)); +} + +extern "C" { +PAM_EXTERN __attribute__((visibility("default"))) +int pam_sm_open_session(pam_handle_t* pamh, int flags, int argc, const char* argv[]) +{ + try { + std::string name = getKrateName(pamh); + KrateGuard krateGuard(name); + krateGuard.wait(); + + openKrateSession(name); + } catch (runtime::Exception& e) { + ::pam_syslog(pamh, LOG_ERR, "%s", e.what()); + return PAM_SESSION_ERR; + } + + return PAM_SUCCESS; +} + +PAM_EXTERN __attribute__((visibility("default"))) +int pam_sm_close_session(pam_handle_t* pamh, int flags, int argc, const char* argv[]) +{ + try { + std::string name = getKrateName(pamh); + KrateGuard krateGuard(name); + krateGuard.wait(); + + closeKrateSession(name); + } catch (runtime::Exception& e) { + ::pam_syslog(pamh, LOG_ERR, "%s", e.what()); + return PAM_SESSION_ERR; + } + + return PAM_SUCCESS; +} + +#ifdef PAM_MODULE_ENTRY +PAM_MODULE_ENTRY("pam_krate"); +#endif + +} diff --git a/module/pam.d/systemd-user-zone b/module/pam.d/systemd-user.in similarity index 68% rename from module/pam.d/systemd-user-zone rename to module/pam.d/systemd-user.in index 2245de4..1d5e242 100644 --- a/module/pam.d/systemd-user-zone +++ b/module/pam.d/systemd-user.in @@ -1,4 +1,4 @@ account include system-auth session include system-auth session optional pam_systemd.so -session required pam_zone.so +session required pam_${PROJECT_NAME}.so diff --git a/module/session.cpp b/module/session.cpp index 24b71ae..4fcd9df 100644 --- a/module/session.cpp +++ b/module/session.cpp @@ -13,60 +13,59 @@ * See the License for the specific language governing permissions and * limitations under the License */ - -#include +#include #include -#include -#include #include -#include #include +#include +#include #include "session.h" -#include "exception.h" -#include "filesystem.h" + +#include +#include bool isValidSessionLeader(pid_t pid) { - runtime::File proc("/proc/" + std::to_string(pid)); - return proc.exists(); + runtime::File proc("/proc/" + std::to_string(pid)); + return proc.exists(); } void createSession(const runtime::User& user, const SessionBuilder& sessionBuilder) { - runtime::File file("/var/run/zone/" + user.getName()); - if (file.exists()) { - if (isValidSessionLeader(getSessionLeader(user))) { - throw runtime::Exception("Session already opened"); - } - file.remove(); - } else { - file.makeBaseDirectory(); - } + runtime::File file("/var/run/krate/" + user.getName()); + if (file.exists()) { + if (isValidSessionLeader(getSessionLeader(user))) { + throw runtime::Exception("Session already opened"); + } + file.remove(); + } else { + file.makeBaseDirectory(); + } - sessionBuilder(user); + sessionBuilder(user); - file.create(0600); - file.lock(); - file.chown(user.getUid(), user.getGid()); - pid_t pid = ::getpid(); - file.write(&pid, sizeof(pid_t)); - file.unlock(); + file.create(0600); + file.lock(); + file.chown(user.getUid(), user.getGid()); + pid_t pid = ::getpid(); + file.write(&pid, sizeof(pid_t)); + file.unlock(); } pid_t getSessionLeader(const runtime::User& user) { - runtime::File file("/var/run/zone/" + user.getName(), O_RDONLY); - file.lock(); - pid_t pid = -1; - file.read(&pid, sizeof(pid_t)); - file.unlock(); + runtime::File file("/var/run/krate/" + user.getName(), O_RDONLY); + file.lock(); + pid_t pid = -1; + file.read(&pid, sizeof(pid_t)); + file.unlock(); - return pid; + return pid; } void destroySession(const runtime::User& user) { - std::string path = "/var/run/zone/" + user.getName(); - ::unlink(path.c_str()); + std::string path = "/var/run/krate/" + user.getName(); + ::unlink(path.c_str()); } diff --git a/module/session.h b/module/session.h index df01173..ebb053e 100644 --- a/module/session.h +++ b/module/session.h @@ -14,16 +14,16 @@ * limitations under the License */ -#ifndef __ZONE_SESSION_ENV_H__ -#define __ZONE_SESSION_ENV_H__ +#ifndef __KRATE_SESSION_ENV_H__ +#define __KRATE_SESSION_ENV_H__ -#include #include +#include #include #include -#include "auth/user.h" +#include typedef std::function SessionBuilder; @@ -32,4 +32,4 @@ void createSession(const runtime::User& user, const SessionBuilder& sessionBuild pid_t getSessionLeader(const runtime::User& user); void destroySession(const runtime::User& user); -#endif //!__ZONE_SESSION_ENV_H__ +#endif //!__KRATE_SESSION_ENV_H__ diff --git a/module/zone-builder.cpp b/module/zone-builder.cpp deleted file mode 100644 index c36e9da..0000000 --- a/module/zone-builder.cpp +++ /dev/null @@ -1,76 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - #include - #include - #include - #include - #include - #include - -#include "zone-builder.h" - -#include "exception.h" -#include "filesystem.h" - -ZoneBuilder::ZoneBuilder(const runtime::User& user, const std::string& manifestPath) : - name(user.getName()), uid(user.getUid()), gid(user.getGid()) -{ - manifest.reset(xml::Parser::parseFile(manifestPath)); -} - -ZoneBuilder::~ZoneBuilder() -{ -} - -void ZoneBuilder::bindFilesystemNode(const std::string& source, const std::string& target, - const std::string& type, const std::string& options, - bool create) -{ - if (create) { - runtime::File dir(target); - if (!dir.exists()) { - dir.makeDirectory(true, uid, gid); - } - } - - runtime::Mount::mountEntry(source, target, type, options); -} - -void ZoneBuilder::containerize(bool create) -{ - int nsFlags = CLONE_NEWIPC | CLONE_NEWNS; - - if (::unshare(nsFlags)) { - throw runtime::Exception("Failed to unshare namespace"); - } - - if (::mount(NULL, "/", NULL, MS_SLAVE | MS_REC, NULL) == -1) { - throw runtime::Exception("Failed to mount root filesystem"); - } - - xml::Node::NodeList entries = manifest->evaluate("/manifest/filesystem/entry"); - for (const xml::Node& entry : entries) { - bindFilesystemNode(entry.getProp("source"), entry.getProp("target"), - entry.getProp("type"), entry.getProp("options")); - } - - bindFilesystemNode("/home/" + name, - "/home/" + name + "/.zone/" + name, - "none", "rw,bind"); - - bindFilesystemNode("/home/" + name + "/.zone", "/home", - "none", "rw,rbind"); -} diff --git a/module/zone.cpp b/module/zone.cpp deleted file mode 100644 index 99b9699..0000000 --- a/module/zone.cpp +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License - */ - -#include -#include -#include - -#include -#include - -#include "zone-guard.h" -#include "zone-builder.h" -#include "session.h" - -#include "exception.h" -#include "filesystem.h" -#include "xml/parser.h" -#include "xml/document.h" - -#define ZONE_MANIFEST_DIR CONF_PATH "/zone/" - -std::string buildZoneManifestPath(const std::string& name) -{ - return ZONE_MANIFEST_DIR + name + ".xml"; -} - -std::string getZoneName(pam_handle_t* handle) -{ - const void* retItem; - int error = ::pam_get_item(handle, PAM_USER, &retItem); - if (error != PAM_SUCCESS) { - throw runtime::Exception("Failed to get user"); - } - - return static_cast(retItem); -} - -void openZoneSession(const std::string& name) -{ - auto sessionBuilder = [](const runtime::User& user) { - ZoneBuilder builder(user, buildZoneManifestPath(user.getName())); - builder.containerize(); - }; - - createSession(runtime::User(name), sessionBuilder); -} - -void closeZoneSession(const std::string& name) -{ - destroySession(runtime::User(name)); -} - -extern "C" { -PAM_EXTERN __attribute__((visibility("default"))) -int pam_sm_open_session(pam_handle_t* pamh, int flags, int argc, const char* argv[]) -{ - try { - std::string name = getZoneName(pamh); - ZoneGuard zoneGuard(name); - zoneGuard.wait(); - - openZoneSession(name); - } catch (runtime::Exception& e) { - ::pam_syslog(pamh, LOG_ERR, "%s", e.what()); - return PAM_SESSION_ERR; - } - - return PAM_SUCCESS; -} - -PAM_EXTERN __attribute__((visibility("default"))) -int pam_sm_close_session(pam_handle_t* pamh, int flags, int argc, const char* argv[]) -{ - try { - std::string name = getZoneName(pamh); - ZoneGuard zoneGuard(name); - zoneGuard.wait(); - - closeZoneSession(name); - } catch (runtime::Exception& e) { - ::pam_syslog(pamh, LOG_ERR, "%s", e.what()); - return PAM_SESSION_ERR; - } - - return PAM_SUCCESS; -} - -#ifdef PAM_MODULE_ENTRY -PAM_MODULE_ENTRY("pam_zone"); -#endif - -} diff --git a/packaging/krate.spec b/packaging/krate.spec index 36f2523..a6e952e 100644 --- a/packaging/krate.spec +++ b/packaging/krate.spec @@ -7,8 +7,8 @@ Summary: Tizen Krate Manager Group: Security/Other BuildRequires: gcc BuildRequires: cmake -BuildRequires: pam-devel BuildRequires: gettext-tools +BuildRequires: pkgconfig(klay) BuildRequires: pkgconfig(glib-2.0) BuildRequires: pkgconfig(libxml-2.0) BuildRequires: pkgconfig(bundle) @@ -32,10 +32,16 @@ krates. %files %manifest krate.manifest %defattr(644,root,root,755) -#%attr(700,root,root) %{_sbindir}/zone-volume-manager #%attr(755,root,root) %{_bindir}/krate +%attr(700,root,root) %{_sbindir}/krate-volume-manager %{_unitdir}/krate.service #%{_unitdir}/multi-user.target.wants/krate.service +%attr(700,root,root) /etc/gumd/useradd.d/20_krate-add.post +%attr(700,root,root) /etc/gumd/userdel.d/20_krate-remove.post +%attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/indicator_icon.png +%attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/notification_sub_icon.png +%attr(700,root,root) %dir %{TZ_SYS_ETC}/krate +%attr(600,root,root) %config %{TZ_SYS_ETC}/krate/owner.xml %prep %setup -q @@ -119,11 +125,14 @@ developing the krate client program. %{_includedir}/krate %{_libdir}/pkgconfig/krate.pc +%endif + ## PAM Plugin Package ######################################################## %package -n dpm-pam-krate Summary: PAM Plugin for zone policy in device policy manager Group: Development/Libraries Requires: systemd +BuildRequires: pam-devel %description -n dpm-pam-krate PAM Plugin for zone policy in device policy manager and CLI tool @@ -139,17 +148,9 @@ mv /etc/pam.d/systemd-user.keep /etc/pam.d/systemd-user %manifest krate.manifest %defattr(600,root,root,700) %attr(700,root,root) %{_libdir}/security/pam_*.so -%attr(700,root,root) %{_sbindir}/krate-admin-cli -%attr(700,root,root) %dir %{TZ_SYS_ETC}/krate -%attr(600,root,root) %config %{TZ_SYS_ETC}/krate/owner.xml -%attr(700,root,root) /etc/gumd/useradd.d/20_pam-krate-add.post -%attr(700,root,root) /etc/gumd/userdel.d/20_pam-krate-remove.post -%attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/indicator_icon.png -%attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/noti_list_sub_icon.png +#%attr(700,root,root) %{_sbindir}/zone-admin-cli %config /etc/pam.d/* -%endif - ## Begin of mobile feature ################################################### %if "%{profile}" == "mobile" diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 7b5f240..48b71a3 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -19,3 +19,10 @@ SET(TARGET ${PROJECT_NAME}) CONFIGURE_FILE(systemd/krate.service.in systemd/krate.service) INSTALL(FILES systemd/krate.service DESTINATION ${SYSTEMD_UNIT_DIR}) + +INSTALL(FILES ${KRATE_TOOLS}/gumd-scripts/20_krate-add.post DESTINATION /etc/gumd/useradd.d) +INSTALL(FILES ${KRATE_TOOLS}/gumd-scripts/20_krate-remove.post DESTINATION /etc/gumd/userdel.d) + +INSTALL(FILES ${KRATE_DATA}/DefaultManifest.xml DESTINATION ${CONF_DIR} RENAME owner.xml) +INSTALL(FILES ${KRATE_DATA}/indicator_icon.png DESTINATION ${APP_ICON_DIR_PREFIX}/krate) +INSTALL(FILES ${KRATE_DATA}/notification_sub_icon.png DESTINATION ${APP_ICON_DIR_PREFIX}/krate) diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index baa8c10..2ce3d84 100755 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -15,5 +15,7 @@ # SET(KRATE_APPS ${KRATE_TOOLS}/apps) +#SET(KRATE_CLI ${KRATE_TOOLS}/cli) ADD_SUBDIRECTORY(${KRATE_APPS}) +#ADD_SUBDIRECTORY(${KRATE_CLI}) diff --git a/tools/cli/CMakeLists.txt b/tools/cli/CMakeLists.txt index d458cee..67a843a 100644 --- a/tools/cli/CMakeLists.txt +++ b/tools/cli/CMakeLists.txt @@ -14,29 +14,30 @@ # limitations under the License. # -PROJECT(krate-admin-cli) - -FILE(GLOB KRATE_ADMIN_CLI_SRCS krate-admin-cli.cpp - ${KRATE_MODULE}/session.cpp - ${KRATE_MODULE}/zone-builder.cpp +FILE(GLOB CLI_SRCS krate-admin-cli.cpp + ${KRATE_MODULE}/session.cpp + ${KRATE_MODULE}/krate-builder.cpp ) -SET(KRATE_ADMIN_CLI_NAME "zone-admin-cli") +SET(CLI_NAME "zone-admin-cli") -ADD_EXECUTABLE(${ZONE_CLI_NAME} ${ZONE_CLI_SRCS}) -SET_TARGET_PROPERTIES(${ZONE_CLI_NAME} PROPERTIES PREFIX "" - COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/zone" - COMPILE_FLAGS "-fPIE" - LINK_FLAGS "-pie" +ADD_EXECUTABLE(${CLI_NAME} ${CLI_SRCS}) +SET_TARGET_PROPERTIES(${CLI_NAME} PROPERTIES PREFIX "" + COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_DIR}/krate" + COMPILE_FLAGS "-fPIE" + LINK_FLAGS "-pie" ) -PKG_CHECK_MODULES(ZONE_CLI_DEPS REQUIRED - glib-2.0 - capi-appfw-package-manager - capi-appfw-app-manager +PKG_CHECK_MODULES(CLI_DEPS REQUIRED + klay + glib-2.0 + libxml-2.0 + capi-appfw-package-manager + capi-appfw-app-manager + zone ) -INCLUDE_DIRECTORIES(SYSTEM ${ZONE_CLI_DEPS_INCLUDE_DIRS} ${DPM_COMMON} ${ZONE_MODULE} ${ZONE_LIBS}) -TARGET_LINK_LIBRARIES(${ZONE_CLI_NAME} ${ZONE_CLI_DEPS_LIBRARIES} dpm-common zone) +INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${KRATE_MODULE}) +TARGET_LINK_LIBRARIES(${CLI_NAME} ${CLI_DEPS_LIBRARIES}) -INSTALL(TARGETS ${ZONE_CLI_NAME} DESTINATION sbin) +INSTALL(TARGETS ${CLI_NAME} DESTINATION sbin) diff --git a/tools/cli/krate-admin-cli.cpp b/tools/cli/krate-admin-cli.cpp index 9fe5157..e46e45b 100644 --- a/tools/cli/krate-admin-cli.cpp +++ b/tools/cli/krate-admin-cli.cpp @@ -22,457 +22,456 @@ * @author Sungbae Yoo (sungbae.yoo@samsung.com) * @brief CLI tool to attach to existing namespace by pam-attach.so */ + #define _XOPEN_SOURCE +#include #include +#include +#include +#include #include #include #include #include -#include -#include -#include -#include -#include - +#include #include #include -#include #include +#include + +#include +#include +#include -#include #include +#include #include "session.h" -#include "error.h" -#include "exception.h" -#include "filesystem.h" -#include "auth/user.h" - #define DEFAULT_SHELL "/bin/bash" typedef std::pair NamespacePair; std::vector namespaces = { - {"mnt", CLONE_NEWNS}, - {"net", CLONE_NEWNET}, - {"uts", CLONE_NEWUTS}, - {"user", CLONE_NEWUSER}, - {"ipc", CLONE_NEWIPC}, - {"pid", CLONE_NEWPID} + {"mnt", CLONE_NEWNS}, + {"net", CLONE_NEWNET}, + {"uts", CLONE_NEWUTS}, + {"user", CLONE_NEWUSER}, + {"ipc", CLONE_NEWIPC}, + {"pid", CLONE_NEWPID} }; extern char** environ; static inline void usage(const std::string name) { - std::cout << "Usage: " << name << " [Option] -- COMMAND" << std::endl - << "Run a program in the zone" << std::endl - << std::endl - << "Options :" << std::endl - << " -a, --attach=zone execute command in the zone" << std::endl - << " -p, --pkginfo=zone show all packages in the zone" << std::endl - << " -q, --appinfo=zone show all applications in the zone" << std::endl - << " -m, --zone-monitor monitor all zone events" << std::endl - << " -n, --pkg-monitor monitor all package events in the zone" << std::endl - << " -l, --list show all zone instances" << std::endl - << " -h, --help show this" << std::endl - << std::endl; + std::cout << "Usage: " << name << " [Option] -- COMMAND" << std::endl + << "Run a program in the krate" << std::endl + << std::endl + << "Options :" << std::endl + << " -a, --attach=krate execute command in the krate" << std::endl + << " -p, --pkginfo=krate show all packages in the krate" << std::endl + << " -q, --appinfo=krate show all applications in the krate" << std::endl + << " -m, --krate-monitor monitor all krate events" << std::endl + << " -n, --pkg-monitor monitor all package events in the krate" << std::endl + << " -l, --list show all krate instances" << std::endl + << " -h, --help show this" << std::endl + << std::endl; } -int showZoneInstances() +int showKrateInstances() { - try { - runtime::DirectoryIterator iter(runtime::Path("/var/run/zone")), end; - - while (iter != end) { - const std::string& path = (*iter).getPath(); - size_t name = path.rfind('/') + 1; - std::cout << path.substr(name) << std::endl; - ++iter; - } - } catch (runtime::Exception& e) { - std::cerr << e.what() << std::endl; - return -1; - } - - return 0; + try { + runtime::DirectoryIterator iter("/var/run/krate"), end; + + while (iter != end) { + const std::string& path = (*iter).getPath(); + size_t name = path.rfind('/') + 1; + std::cout << path.substr(name) << std::endl; + ++iter; + } + } catch (runtime::Exception& e) { + std::cerr << e.what() << std::endl; + return -1; + } + + return 0; } void attachNamespaces(pid_t pid) { - int fd; - for (const NamespacePair& ns : namespaces) { - std::string nspath = "/proc/" + std::to_string(pid) + "/ns/" + ns.first; - - do { - fd = ::open(nspath.c_str(), O_RDONLY); - } while (fd == -1 && errno == EINTR); - - if (fd == -1) { - if (errno != ENOENT) { - throw runtime::Exception("Failed to open namesapce: " + nspath); - } - } else { - if (::setns(fd, ns.second)) { - ::close(fd); - throw runtime::Exception("Failed to attach namespace: " + nspath); - } - ::close(fd); - } - } + int fd; + for (const NamespacePair& ns : namespaces) { + std::string nspath = "/proc/" + std::to_string(pid) + "/ns/" + ns.first; + + do { + fd = ::open(nspath.c_str(), O_RDONLY); + } while (fd == -1 && errno == EINTR); + + if (fd == -1) { + if (errno != ENOENT) { + throw runtime::Exception("Failed to open namesapce: " + nspath); + } + } else { + if (::setns(fd, ns.second)) { + ::close(fd); + throw runtime::Exception("Failed to attach namespace: " + nspath); + } + ::close(fd); + } + } } void launchProcess(runtime::User& user, char** args) { - int status; - - pid_t pid = ::fork(); - if (pid == -1) { - throw runtime::Exception("Failed to create child process"); - } - - if (pid != 0) { - ::waitpid(pid, &status, 0); - if (WEXITSTATUS(status) != EXIT_SUCCESS) { - throw runtime::Exception("Child process terminated abnormally"); - } - return; - } - - if (::initgroups(user.getName().c_str(), user.getGid()) == -1) { - std::cerr << "Failed to initgroups()" << std::endl; - ::exit(EXIT_FAILURE); - } - - if (::setgid(user.getGid()) == -1) { - std::cerr << "Failed to setgid()" << std::endl; - ::exit(EXIT_FAILURE); - } - - if (::setuid(user.getUid()) == -1) { - std::cerr << "Failed to setuid()" << std::endl; - ::exit(EXIT_FAILURE); - } - - char *default_args[2]; - default_args[0] = ::strdup(DEFAULT_SHELL); - default_args[1] = NULL; - - if (args == NULL) { - args = default_args; - } - - ::execve(*args, args, environ); - std::cerr << "Failed to execute " << args[0] << std::endl; - - ::free(default_args[0]); - - ::exit(EXIT_FAILURE); + int status; + + pid_t pid = ::fork(); + if (pid == -1) { + throw runtime::Exception("Failed to create child process"); + } + + if (pid != 0) { + ::waitpid(pid, &status, 0); + if (WEXITSTATUS(status) != EXIT_SUCCESS) { + throw runtime::Exception("Child process terminated abnormally"); + } + return; + } + + if (::initgroups(user.getName().c_str(), user.getGid()) == -1) { + std::cerr << "Failed to initgroups()" << std::endl; + ::exit(EXIT_FAILURE); + } + + if (::setgid(user.getGid()) == -1) { + std::cerr << "Failed to setgid()" << std::endl; + ::exit(EXIT_FAILURE); + } + + if (::setuid(user.getUid()) == -1) { + std::cerr << "Failed to setuid()" << std::endl; + ::exit(EXIT_FAILURE); + } + + char *default_args[2]; + default_args[0] = ::strdup(DEFAULT_SHELL); + default_args[1] = NULL; + + if (args == NULL) { + args = default_args; + } + + ::execve(*args, args, environ); + std::cerr << "Failed to execute " << args[0] << std::endl; + + ::free(default_args[0]); + + ::exit(EXIT_FAILURE); } -int attachToZone(const std::string& name, char* args[]) +int attachToKrate(const std::string& name, char* args[]) { - try { - runtime::User user(name); + try { + runtime::User user(name); - attachNamespaces(getSessionLeader(user)); - launchProcess(user, args); - } catch (runtime::Exception& e) { - std::cerr << e.what() << std::endl; - return -1; - } + attachNamespaces(getSessionLeader(user)); + launchProcess(user, args); + } catch (runtime::Exception& e) { + std::cerr << e.what() << std::endl; + return -1; + } - return 0; + return 0; } bool packgeListCallback(package_info_h info, void *user_data) { - bool checked; - char *val; - - std::cout << "Package #" << (*(int*)user_data)++ << " :" << std::endl; - - package_info_get_package(info, &val); - std::cout << val; - free(val); - - package_info_get_version(info, &val); - std::cout << " (" << val << ")" << std::endl; - free(val); - - package_info_get_type(info, &val); - std::cout << " Type : " << val << " ("; - free(val); - - package_info_is_system_package(info, &checked); - if (checked) { - std::cout <<" System "; - } - package_info_is_removable_package(info, &checked); - if (checked) { - std::cout <<" Removable "; - } - package_info_is_preload_package(info, &checked); - if (checked) { - std::cout <<" Preload "; - } - std::cout << ")" << std::endl; - - package_info_get_label(info, &val); - std::cout << " Label : " << val << std::endl; - free(val); - - package_info_get_icon(info, &val); - std::cout << " Icon : " << val << std::endl; - free(val); - - std::cout << std::endl; - - return true; + bool checked; + char *val; + + std::cout << "Package #" << (*(int*)user_data)++ << " :" << std::endl; + + package_info_get_package(info, &val); + std::cout << val; + free(val); + + package_info_get_version(info, &val); + std::cout << " (" << val << ")" << std::endl; + free(val); + + package_info_get_type(info, &val); + std::cout << " Type : " << val << " ("; + free(val); + + package_info_is_system_package(info, &checked); + if (checked) { + std::cout <<" System "; + } + package_info_is_removable_package(info, &checked); + if (checked) { + std::cout <<" Removable "; + } + package_info_is_preload_package(info, &checked); + if (checked) { + std::cout <<" Preload "; + } + std::cout << ")" << std::endl; + + package_info_get_label(info, &val); + std::cout << " Label : " << val << std::endl; + free(val); + + package_info_get_icon(info, &val); + std::cout << " Icon : " << val << std::endl; + free(val); + + std::cout << std::endl; + + return true; } int showPkgInfo(const std::string& name) { - int num = 0; + int num = 0; - zone_manager_h zoneMgr; - zone_package_proxy_h pkgProxy; + zone_manager_h krateMgr; + zone_package_proxy_h pkgProxy; - zone_manager_create(&zoneMgr); - zone_package_proxy_create(zoneMgr, name.c_str(), &pkgProxy); - zone_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num); - std::cout << num << " packages are found" << std::endl; - zone_package_proxy_destroy(pkgProxy); - zone_manager_destroy(zoneMgr); + zone_manager_create(&krateMgr); + zone_package_proxy_create(krateMgr, name.c_str(), &pkgProxy); + zone_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num); + std::cout << num << " packages are found" << std::endl; + zone_package_proxy_destroy(pkgProxy); + zone_manager_destroy(krateMgr); - return 0; + return 0; } bool applicationListCallback(app_info_h info, void *user_data) { - bool checked; - char *val; + bool checked; + char *val; - std::cout << "Application #" << (*(int*)user_data)++ << " :" << std::endl; + std::cout << "Application #" << (*(int*)user_data)++ << " :" << std::endl; - app_info_get_app_id(info, &val); - std::cout << val; - free(val); + app_info_get_app_id(info, &val); + std::cout << val; + free(val); - app_info_get_package(info, &val); - std::cout << " (" << val << ")" << std::endl; - free(val); + app_info_get_package(info, &val); + std::cout << " (" << val << ")" << std::endl; + free(val); - app_info_get_type(info, &val); - std::cout << " Type : " << val << " ("; - free(val); + app_info_get_type(info, &val); + std::cout << " Type : " << val << " ("; + free(val); - app_info_is_nodisplay(info, &checked); - if (checked) { - std::cout <<" NoDisplay "; - } - std::cout << ")"<< std::endl; + app_info_is_nodisplay(info, &checked); + if (checked) { + std::cout <<" NoDisplay "; + } + std::cout << ")"<< std::endl; - app_info_get_label(info, &val); - std::cout << " Label : " << val << std::endl; - free(val); + app_info_get_label(info, &val); + std::cout << " Label : " << val << std::endl; + free(val); - if (app_info_get_icon(info, &val) == APP_MANAGER_ERROR_NONE) { - std::cout << " Icon : " << val << std::endl; - free(val); - } else { - std::cout << "App Manager error" << std::endl; - } + if (app_info_get_icon(info, &val) == APP_MANAGER_ERROR_NONE) { + std::cout << " Icon : " << val << std::endl; + free(val); + } else { + std::cout << "App Manager error" << std::endl; + } - std::cout << std::endl; + std::cout << std::endl; - return true; + return true; } int showAppInfo(const std::string& name) { - int num = 0; + int num = 0; - zone_manager_h zoneMgr; - zone_app_proxy_h appMgr; + zone_manager_h krateMgr; + zone_app_proxy_h appMgr; - zone_manager_create(&zoneMgr); - zone_app_proxy_create(zoneMgr, name.c_str(), &appMgr); - zone_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num); - std::cout << num << " applications are found" << std::endl; - zone_app_proxy_destroy(appMgr); - zone_manager_destroy(zoneMgr); + zone_manager_create(&krateMgr); + zone_app_proxy_create(krateMgr, name.c_str(), &appMgr); + zone_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num); + std::cout << num << " applications are found" << std::endl; + zone_app_proxy_destroy(appMgr); + zone_manager_destroy(krateMgr); - return 0; + return 0; } GMainLoop *gmainloop = NULL; void monitorSigHandler(int sig) { - g_main_loop_quit(gmainloop); + g_main_loop_quit(gmainloop); } -void zoneCallback(const char* name, const char* object, void *user_data) +void krateCallback(const char* name, const char* object, void *user_data) { - std::cout << "--- Zone event ---" << std::endl; - std::cout << "Type : " << (char*)user_data << std::endl; - std::cout << "Name : " << name <= argc ? NULL : argv + optind); - break; - case 'p': - ret = showPkgInfo(optarg); - break; - case 'q': - ret = showAppInfo(optarg); - break; - case 'm': - ret = monitorEvent(); - break; - case 'n': - ret = monitorPkgEvent(optarg); - break; - case 'l': - ret = showZoneInstances(); - break; - case 'h': - usage(argv[0]); - break; - default: - usage(argv[0]); - ret = -1; - } - } - - return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; + int opt = 0, index, ret = 0; + + struct option options[] = { + {"attach", required_argument, 0, 'a'}, + {"list", no_argument, 0, 'l'}, + {"pkginfo", required_argument, 0, 'p'}, + {"appinfo", required_argument, 0, 'q'}, + {"krate-monitor", no_argument, 0, 'm'}, + {"pkg-monitor", no_argument, 0, 'n'}, + {"help", no_argument, 0, 'h'}, + {0, 0, 0, 0} + }; + + if (argc <= 1) { + usage(argv[0]); + return EXIT_SUCCESS; + } + + while ((opt = getopt_long(argc, argv, "a:p:q:mn:lh", options, &index)) != -1) { + switch (opt) { + case 'a': + ret = attachToKrate(optarg, optind >= argc ? NULL : argv + optind); + break; + case 'p': + ret = showPkgInfo(optarg); + break; + case 'q': + ret = showAppInfo(optarg); + break; + case 'm': + ret = monitorEvent(); + break; + case 'n': + ret = monitorPkgEvent(optarg); + break; + case 'l': + ret = showKrateInstances(); + break; + case 'h': + usage(argv[0]); + break; + default: + usage(argv[0]); + ret = -1; + } + } + + return ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE; } diff --git a/tools/gumd-scripts/20_pam-krate-add.post b/tools/gumd-scripts/20_krate-add.post similarity index 100% rename from tools/gumd-scripts/20_pam-krate-add.post rename to tools/gumd-scripts/20_krate-add.post diff --git a/tools/gumd-scripts/20_pam-krate-remove.post b/tools/gumd-scripts/20_krate-remove.post similarity index 100% rename from tools/gumd-scripts/20_pam-krate-remove.post rename to tools/gumd-scripts/20_krate-remove.post diff --git a/volume/CMakeLists.txt b/volume/CMakeLists.txt new file mode 100644 index 0000000..0ae5e95 --- /dev/null +++ b/volume/CMakeLists.txt @@ -0,0 +1,33 @@ +# +# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +SET(VOLUME_MANAGER_SRCS key-manager.cpp + key-generator.cpp + kernel-keyring.cpp + main.cpp +) + +PKG_CHECK_MODULES(VOLUME_MANAGER_DEPS REQUIRED + klay + key-manager +) + +INCLUDE_DIRECTORIES(SYSTEM ${VOLUME_MANAGER_DEPS_INCLUDE_DIRS}) + +ADD_EXECUTABLE(${PROJECT_NAME}-volume-manager ${VOLUME_MANAGER_SRCS}) + +TARGET_LINK_LIBRARIES(${PROJECT_NAME}-volume-manager ${VOLUME_MANAGER_DEPS_LIBRARIES}) + +INSTALL(TARGETS ${PROJECT_NAME}-volume-manager DESTINATION sbin) diff --git a/volume/ecryptfs.h b/volume/ecryptfs.h new file mode 100755 index 0000000..9962e34 --- /dev/null +++ b/volume/ecryptfs.h @@ -0,0 +1,107 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __ECRYPTFS_H__ +#define __ECRYPTFS_H__ + +#include +#include + +// this is versions of ecryptfs module +#define ECRYPTFS_MAJOR_VERSION 0x00 +#define ECRYPTFS_MINOR_VERSION 0x04 +#define ECRYPTFS_VERSION ((ECRYPTFS_MAJOR_VERSION << 8) | ECRYPTFS_MINOR_VERSION) + +#define ECRYPTFS_MAX_PKI_NAME_BYTES 16 +#define ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET 0x02 + +#define PGP_DIGEST_ALGO_SHA512 10 + +#define ECRYPTFS_FEK_CIPHER "aes" +#define ECRYPTFS_MOUNT_DEVICE "ecryptfs" + +#define ECRYPTFS_MAX_OPTIONS 1024 + +#define ECRYPTFS_MAX_SIG_SIZE 8 +#define ECRYPTFS_MAX_SIG_HEX (ECRYPTFS_MAX_SIG_SIZE*2) +#define ECRYPTFS_PASSWORD_SIG_SIZE ECRYPTFS_MAX_SIG_HEX + +#define ECRYPTFS_MAX_KEY_SIZE 32 +#define ECRYPTFS_MAX_KEY_HEX (ECRYPTFS_MAX_KEY_SIZE * 2) + +#define ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES 512 +#define ECRYPTFS_MAX_PKI_NAME_BYTES 16 + +#define ECRYPTFS_MAX_SALT_SIZE 4 +#define ECRYPTFS_MAX_SALT_HEX 8 + +#define ECRYPTFS_PWD_PAYLOAD_TYPE 0 // password + +struct ecryptfs_session_key { +#define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_DECRYPT 0x00000001 +#define ECRYPTFS_USERSPACE_SHOULD_TRY_TO_ENCRYPT 0x00000002 +#define ECRYPTFS_CONTAINS_DECRYPTED_KEY 0x00000004 +#define ECRYPTFS_CONTAINS_ENCRYPTED_KEY 0x00000008 + int32_t flags; + int32_t encrypted_key_size; + int32_t decrypted_key_size; + u_int8_t encrypted_key[ECRYPTFS_MAX_ENCRYPTED_KEY_BYTES]; + u_int8_t decrypted_key[ECRYPTFS_MAX_KEY_HEX]; +}; + +struct ecryptfs_password { + int32_t password_bytes; + int32_t hash_algo; + int32_t hash_iterations; + int32_t session_key_encryption_key_bytes; +#define ECRYPTFS_PERSISTENT_PASSWORD 0x01 +#define ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET 0x02 + u_int32_t flags; + /* Iterated-hash concatenation of salt and passphrase */ + u_int8_t session_key_encryption_key[ECRYPTFS_MAX_KEY_HEX]; + u_int8_t signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1]; + /* Always in expanded hex */ + u_int8_t salt[ECRYPTFS_MAX_SALT_SIZE]; +}; + +enum ecryptfs_token_types { + ECRYPTFS_PASSWORD, + ECRYPTFS_PRIVATE_KEY +}; + +struct ecryptfs_private_key { + u_int32_t key_size; + u_int32_t data_len; + u_int8_t signature[ECRYPTFS_PASSWORD_SIG_SIZE + 1]; + char pki_type[ECRYPTFS_MAX_PKI_NAME_BYTES + 1]; + u_int8_t data[]; +}; + +struct ecryptfs_auth_tok { + u_int16_t version; /* 8-bit major and 8-bit minor */ + u_int16_t token_type; +#define ECRYPTFS_ENCRYPT_ONLY 0x00000001 + u_int32_t flags; + struct ecryptfs_session_key session_key; + u_int8_t reserved[32]; + union { + struct ecryptfs_password password; + struct ecryptfs_private_key private_key; + } token; +} __attribute__((packed)); + +typedef struct ecryptfs_auth_tok ecryptfs_payload; +#endif diff --git a/volume/kernel-keyring.cpp b/volume/kernel-keyring.cpp new file mode 100755 index 0000000..11d2373 --- /dev/null +++ b/volume/kernel-keyring.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include +#include +#include + +#include "kernel-keyring.h" + +#ifndef KEYCTL_SEARCH +#define KEYCTL_SEARCH 10 +#endif + +KeySerial KernelKeyRing::add(const char *type, const char* description, const void* payload, size_t plen, KeySerial ringid) +{ + return ::syscall(__NR_add_key, type, description, payload, plen, ringid); +} + +long KernelKeyRing::search(KeySerial ringid, const char* type, const char* description, KeySerial destringid) +{ + return ::syscall(__NR_keyctl, KEYCTL_SEARCH, ringid, type, description, destringid); +} + +long KernelKeyRing::link(KeySerial keyid, KeySerial ringid) +{ + return ::syscall(__NR_keyctl, KEYCTL_LINK, keyid, ringid); +} + +long KernelKeyRing::unlink(KeySerial keyid, KeySerial ringid) +{ + return ::syscall(__NR_keyctl, KEYCTL_UNLINK, keyid, ringid); +} diff --git a/volume/kernel-keyring.h b/volume/kernel-keyring.h new file mode 100755 index 0000000..c23d70f --- /dev/null +++ b/volume/kernel-keyring.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KERNEL_KEY_RING_H__ +#define __KERNEL_KEY_RING_H__ + +#include +#include + +#include + +typedef int32_t KeySerial; + +class KernelKeyRing { +public: + KernelKeyRing() = delete; + KernelKeyRing(const KernelKeyRing&) = delete; + KernelKeyRing(KernelKeyRing&&) = delete; + + KernelKeyRing& operator=(const KernelKeyRing&) = delete; + KernelKeyRing& operator=(KernelKeyRing&&) = delete; + + static KeySerial add(const char* type, const char* description, const void* payload, size_t plen, KeySerial ringid); + static long search(KeySerial ringid, const char* type, const char* description, KeySerial destringid); + static long link(KeySerial keyid, KeySerial ringid); + static long unlink(KeySerial keyid, KeySerial ringid); +}; + +#endif //!__KERNEL_KEY_RING_H__ diff --git a/volume/key-generator.cpp b/volume/key-generator.cpp new file mode 100755 index 0000000..d6440f6 --- /dev/null +++ b/volume/key-generator.cpp @@ -0,0 +1,322 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + + +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "key-generator.h" + +#define RAND_READ_BYTES 8 +#define PBKDF2_ITERATION 1000 +#define SHA_BLOCKSIZE 64 + +#define rol(value, bits) (((value) << (bits)) | ((value) >> (32 - (bits)))) + +#if defined (BYTE_ORDER) && defined(BIG_ENDIAN) && (BYTE_ORDER == BIG_ENDIAN) +#define WORDS_BIGENDIAN 1 +#endif +#ifdef _BIG_ENDIAN +#define WORDS_BIGENDIAN 1 +#endif + +#ifdef WORDS_BIGENDIAN +#define blk0(i) block->l[i] +#else +#define blk0(i) (block->l[i] = (rol(block->l[i], 24)&0xff00ff00) \ + |(rol(block->l[i], 8)&0x00ff00ff)) +#endif +#define blk(i) (block->l[i&15] = rol(block->l[(i+13)&15]^block->l[(i+8)&15] \ + ^block->l[(i+2)&15]^block->l[i&15], 1)) + +/* (R0+R1), R2, R3, R4 are the different operations used in SHA1 */ +#define R0(v, w, x, y, z, i) \ + z+=((w&(x^y))^y)+blk0(i)+0x5a827999+rol(v, 5);w=rol(w, 30); +#define R1(v, w, x, y, z, i) \ + z+=((w&(x^y))^y)+blk(i)+0x5a827999+rol(v, 5);w=rol(w, 30); +#define R2(v, w, x, y, z, i) \ + z+=(w^x^y)+blk(i)+0x6ed9eba1+rol(v, 5);w=rol(w, 30); +#define R3(v, w, x, y, z, i) \ + z+=(((w|x)&y)|(w&x))+blk(i)+0x8f1bbcdc+rol(v, 5);w=rol(w, 30); +#define R4(v, w, x, y, z, i) \ + z+=(w^x^y)+blk(i)+0xca62c1d6+rol(v, 5);w=rol(w, 30); + +#define __min__(a, b) (((a) < (b)) ? (a) : (b)) + +std::string KeyGenerator::hexConvert(unsigned char* src, int srcLen) +{ + std::ostringstream ss; + + for (int i = 0; i state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; + context->state[4] = 0xc3d2e1f0; + context->count[0] = context->count[1] = 0; +} + +void KeyGenerator::sha1Update(SHA1_CTX* context, const void* p, unsigned int len) +{ + const unsigned char* data = (unsigned char*)p; + unsigned int i, j; + + j = (context->count[0] >> 3) & 63; + if ((context->count[0] += (len << 3)) < (len << 3)) { + context->count[1]++; + } + context->count[1] += (len >> 29); + if ((j + len) > 63) { + ::memcpy(&context->buffer[j], data, (i = 64 - j)); + sha1Transform(context->state, context->buffer); + for (; i + 63 < len; i += 64) { + sha1Transform(context->state, data + i); + } + j = 0; + } else { + i = 0; + } + + ::memcpy(&context->buffer[j], &data[i], len - i); +} + +void KeyGenerator::sha1Final(unsigned char digest[SHA1_DIGEST_SIZE], SHA1_CTX* context) +{ + unsigned int i; + unsigned char finalcount[8]; + for (i = 0; i < 8; i++) { + finalcount[i] = (unsigned char) ((context->count[(i >= 4 ? 0 : 1)] + >> ((3 - (i & 3)) * 8)) & 255); + } + sha1Update(context, (unsigned char*) "\200", 1); + while ((context->count[0] & 504) != 448) { + sha1Update(context, (unsigned char*) "\0", 1); + } + sha1Update(context, finalcount, 8); + /* Should cause SHA1_Transform */ + for (i = 0; i < SHA1_DIGEST_SIZE; i++) { + digest[i] = (unsigned char) + ((context->state[i >> 2] >> ((3 - (i & 3)) * 8)) & 255); + } + /* Wipe variables */ + i = 0; + ::memset(context->buffer, 0, 64); + ::memset(context->state, 0, 20); + ::memset(context->count, 0, 8); + ::memset(finalcount, 0, 8); /* SWR */ + +#ifdef SHA1HANDSOFF /* make SHA1Transform overwrite its own static vars */ + transform(context->state, context->buffer); +#endif +} + +void KeyGenerator::sha1Transform(unsigned int state[5], const unsigned char buffer[64]) +{ + uint32_t a, b, c, d, e; + typedef union { + unsigned char c[64]; + unsigned int l[16]; + } CHAR64LONG16; + CHAR64LONG16 *block; + +#ifdef SHA1HANDSOFF + CHAR64LONG16 workspace; + block = &workspace; + ::memcpy(block, buffer, 64); +#else + block = (CHAR64LONG16*)buffer; +#endif + + a = state[0]; + b = state[1]; + c = state[2]; + d = state[3]; + e = state[4]; + + /* 4 rounds of 20 operations each. Loop unrolled. */ + R0(a, b, c, d, e, 0); R0(e, a, b, c, d, 1); R0(d, e, a, b, c, 2); R0(c, d, e, a, b, 3); + R0(b, c, d, e, a, 4); R0(a, b, c, d, e, 5); R0(e, a, b, c, d, 6); R0(d, e, a, b, c, 7); + R0(c, d, e, a, b, 8); R0(b, c, d, e, a, 9); R0(a, b, c, d, e, 10); R0(e, a, b, c, d, 11); + R0(d, e, a, b, c, 12); R0(c, d, e, a, b, 13); R0(b, c, d, e, a, 14); R0(a, b, c, d, e, 15); + R1(e, a, b, c, d, 16); R1(d, e, a, b, c, 17); R1(c, d, e, a, b, 18); R1(b, c, d, e, a, 19); + R2(a, b, c, d, e, 20); R2(e, a, b, c, d, 21); R2(d, e, a, b, c, 22); R2(c, d, e, a, b, 23); + R2(b, c, d, e, a, 24); R2(a, b, c, d, e, 25); R2(e, a, b, c, d, 26); R2(d, e, a, b, c, 27); + R2(c, d, e, a, b, 28); R2(b, c, d, e, a, 29); R2(a, b, c, d, e, 30); R2(e, a, b, c, d, 31); + R2(d, e, a, b, c, 32); R2(c, d, e, a, b, 33); R2(b, c, d, e, a, 34); R2(a, b, c, d, e, 35); + R2(e, a, b, c, d, 36); R2(d, e, a, b, c, 37); R2(c, d, e, a, b, 38); R2(b, c, d, e, a, 39); + R3(a, b, c, d, e, 40); R3(e, a, b, c, d, 41); R3(d, e, a, b, c, 42); R3(c, d, e, a, b, 43); + R3(b, c, d, e, a, 44); R3(a, b, c, d, e, 45); R3(e, a, b, c, d, 46); R3(d, e, a, b, c, 47); + R3(c, d, e, a, b, 48); R3(b, c, d, e, a, 49); R3(a, b, c, d, e, 50); R3(e, a, b, c, d, 51); + R3(d, e, a, b, c, 52); R3(c, d, e, a, b, 53); R3(b, c, d, e, a, 54); R3(a, b, c, d, e, 55); + R3(e, a, b, c, d, 56); R3(d, e, a, b, c, 57); R3(c, d, e, a, b, 58); R3(b, c, d, e, a, 59); + R4(a, b, c, d, e, 60); R4(e, a, b, c, d, 61); R4(d, e, a, b, c, 62); R4(c, d, e, a, b, 63); + R4(b, c, d, e, a, 64); R4(a, b, c, d, e, 65); R4(e, a, b, c, d, 66); R4(d, e, a, b, c, 67); + R4(c, d, e, a, b, 68); R4(b, c, d, e, a, 69); R4(a, b, c, d, e, 70); R4(e, a, b, c, d, 71); + R4(d, e, a, b, c, 72); R4(c, d, e, a, b, 73); R4(b, c, d, e, a, 74); R4(a, b, c, d, e, 75); + R4(e, a, b, c, d, 76); R4(d, e, a, b, c, 77); R4(c, d, e, a, b, 78); R4(b, c, d, e, a, 79); + + /* Add the working vars back into context.state[] */ + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + + /* Wipe variables */ + a = b = c = d = e = 0; +} + +void KeyGenerator::sha1Hmac(const unsigned char* key, int keyLen, const unsigned char* data, int dataLen, unsigned char out[SHA1_DIGEST_SIZE]) +{ + SHA1_CTX ctx; + unsigned char buf[SHA_BLOCKSIZE], outPad[SHA_BLOCKSIZE], inPad[SHA_BLOCKSIZE]; + unsigned char tempKey[SHA1_DIGEST_SIZE]; + int i; + + ::memset(buf, 0, SHA_BLOCKSIZE); + + if (keyLen > SHA_BLOCKSIZE) { + sha1Init(&ctx); + sha1Update(&ctx, key, keyLen); + sha1Final(tempKey, &ctx); + key = tempKey; + keyLen = SHA1_DIGEST_SIZE; + } + + ::memcpy(buf, key, keyLen); + ::memset(inPad, 0, SHA_BLOCKSIZE); + ::memset(outPad, 0, SHA_BLOCKSIZE); + + for (i = 0; i < SHA_BLOCKSIZE; i++) { + outPad[i] = buf[i] ^ 0x5c; + inPad[i]= buf[i] ^ 0x36; + } + + sha1Init(&ctx); + sha1Update(&ctx, inPad, SHA_BLOCKSIZE); + sha1Update(&ctx, data, dataLen); + sha1Final(out, &ctx); + + sha1Init(&ctx); + sha1Update(&ctx, outPad, SHA_BLOCKSIZE); + sha1Update(&ctx, out, SHA1_DIGEST_SIZE); + sha1Final(out, &ctx); +} + +int KeyGenerator::pbkdf2(const char * pass, int passLen, const unsigned char* salt, int saltLen, int iter, int keyLen, unsigned char* out) +{ + unsigned char digtmp1[SHA1_DIGEST_SIZE], digtmp2[SHA1_DIGEST_SIZE], itmp[saltLen + 4]; + int j, k; + int genKeyLen = 0, toWriteLen; + unsigned long i = 1; + + if (passLen <= 0 || saltLen <= 0 || iter <= 0 || keyLen <= 0) + return -1; + + ::memcpy(itmp, salt, saltLen); + while (genKeyLen < keyLen) { + itmp[saltLen + 0] = (unsigned char)((i >> 24) & 0xff); + itmp[saltLen + 1] = (unsigned char)((i >> 16) & 0xff); + itmp[saltLen + 2] = (unsigned char)((i >> 8) & 0xff); + itmp[saltLen + 3] = (unsigned char)(i & 0xff); + + sha1Hmac((unsigned char*)pass, passLen, itmp, saltLen+4, digtmp1); + ::memcpy(digtmp2, digtmp1, SHA1_DIGEST_SIZE); + + for (j = 1; j < iter; j++) { + sha1Hmac((unsigned char*)pass, passLen, digtmp1, SHA1_DIGEST_SIZE, digtmp1); + for (k = 0; k < SHA1_DIGEST_SIZE; k++) { + digtmp2[k] ^= digtmp1[k]; + } + } + toWriteLen = __min__((keyLen - genKeyLen), SHA1_DIGEST_SIZE); + ::memcpy(out+genKeyLen, digtmp2, toWriteLen); + genKeyLen += toWriteLen; + ++i; + } + + return 1; +} diff --git a/volume/key-generator.h b/volume/key-generator.h new file mode 100755 index 0000000..e0d9796 --- /dev/null +++ b/volume/key-generator.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __VOLUME_MANAGER_KEY_GENERATOR_H__ +#define __VOLUME_MANAGER_KEY_GENERATOR_H__ + +#include "ecryptfs.h" + +#define SHA1_DIGEST_SIZE 20 + +typedef struct { + unsigned int state[5]; + unsigned int count[2]; + unsigned char buffer[64]; +} SHA1_CTX; + +class KeyGenerator { +public: + KeyGenerator() = delete; + KeyGenerator(const KeyGenerator&) = delete; + KeyGenerator(KeyGenerator&&) = delete; + + KeyGenerator& operator=(const KeyGenerator&) = delete; + KeyGenerator& operator=(KeyGenerator&&) = delete; + + static std::string wrapKey(const std::string& decrypted, const std::string& salt, int len); + static std::string generateKey(int len); + static void generateToken(char* key, ecryptfs_payload** outToken); + +private: + static void sha1Init(SHA1_CTX* context); + static void sha1Update(SHA1_CTX* context, const void* p, unsigned int len); + static void sha1Final(unsigned char digsest[SHA1_DIGEST_SIZE], SHA1_CTX* context); + static void sha1Transform(unsigned int state[5], const unsigned char buffer[64]); + static void sha1Hmac(const unsigned char* key, int keyLen, const unsigned char* data, int dataLen, unsigned char out[SHA1_DIGEST_SIZE]); + + static int pbkdf2(const char* pass, int passLen, const unsigned char* salt, int saltLen, int iter, int keyLen, unsigned char* out); + static std::string hexConvert(unsigned char* src, int srcLen); +}; + +#endif //!__VOLUME_MANAGER_KEY_GENERATOR_H__ diff --git a/volume/key-manager.cpp b/volume/key-manager.cpp new file mode 100755 index 0000000..d143c31 --- /dev/null +++ b/volume/key-manager.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include + +#include +#include + +#include "key-manager.h" + + +#define addAliasPrefix(alias) \ + (ckmcIdSystem + ckmcIdSeperator + alias) + +namespace { + +const std::string ckmcIdSystem = ckmc_owner_id_system; +const std::string ckmcIdSeperator = ckmc_owner_id_separator; + +} //namespace + +bool KeyManager::isKeyExist(const std::string& keyName) +{ + int ret; + ckmc_raw_buffer_s* keyData = NULL; + std::string ckmAlias = addAliasPrefix(keyName); + + ret = ::ckmc_get_data(ckmAlias.c_str(), NULL, &keyData); + ::ckmc_buffer_free(keyData); + + return (ret != CKMC_ERROR_DB_ALIAS_UNKNOWN); +} + +void KeyManager::addKey(const std::string& keyName, const std::string& data) +{ + int ret; + const std::string ckmAlias = addAliasPrefix(keyName); + ckmc_raw_buffer_s keyData; + ckmc_policy_s keyPolicy; + + keyData.data = (unsigned char*)data.c_str(); + keyData.size = data.size(); + + keyPolicy.password = NULL; + keyPolicy.extractable = true; + + ret = ::ckmc_save_data(ckmAlias.c_str(), keyData, keyPolicy); + if (ret != 0) { + throw runtime::Exception("Failed to add key data"); + } +} + +std::string KeyManager::getKey(const std::string& keyName) +{ + int ret; + const std::string ckmAlias = addAliasPrefix(keyName); + ckmc_raw_buffer_s* keyData; + std::string result; + + ret = ::ckmc_get_data(ckmAlias.c_str(), NULL, &keyData); + if (ret != CKMC_ERROR_NONE) { + throw runtime::Exception("Failed to get key data"); + } + + result = std::string(reinterpret_cast(keyData->data), keyData->size); + + ::ckmc_buffer_free(keyData); + + return result; +} + +void KeyManager::removeKey(const std::string& keyName) +{ + const std::string ckmAlias = addAliasPrefix(keyName); + + if (::ckmc_remove_data(ckmAlias.c_str()) != 0) { + throw runtime::Exception("Failed to remove key data"); + } +} diff --git a/volume/key-manager.h b/volume/key-manager.h new file mode 100644 index 0000000..48bcdc8 --- /dev/null +++ b/volume/key-manager.h @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KEY_MANAGER_H__ +#define __KEY_MANAGER_H__ + +class KeyManager { +public: + KeyManager() = delete; + KeyManager(const KeyManager&) = delete; + KeyManager(KeyManager&&) = delete; + + KeyManager& operator=(const KeyManager&) = delete; + KeyManager& operator=(KeyManager&&) = delete; + + static bool isKeyExist(const std::string& keyName); + static void addKey(const std::string& keyName, const std::string& data); + static std::string getKey(const std::string& keyName); + static void removeKey(const std::string& keyName); +}; + +#endif //!__KEY_MANAGER_H__*/ diff --git a/volume/main.cpp b/volume/main.cpp new file mode 100755 index 0000000..4de5260 --- /dev/null +++ b/volume/main.cpp @@ -0,0 +1,194 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#include +#include +#include + +#include "ecryptfs.h" +#include "kernel-keyring.h" +#include "key-manager.h" +#include "key-generator.h" + +int generateKey(const std::string& keyName) +{ + if (KeyManager::isKeyExist(keyName)) { + ERROR("Key already registered"); + return -1; + } + + try { + std::string pass = KeyGenerator::generateKey(ECRYPTFS_MAX_KEY_SIZE); + std::string salt = KeyGenerator::generateKey(ECRYPTFS_MAX_SALT_SIZE); + std::string wrappedKey = KeyGenerator::wrapKey(pass, salt, ECRYPTFS_MAX_KEY_SIZE); + + KeyManager::addKey(keyName, wrappedKey); + } catch (runtime::Exception& e) { + ERROR(e.what()); + return -1; + } + + return 0; +} + +ecryptfs_payload* generateToken(char* key) +{ + struct ecryptfs_password* tokenKey; + + unsigned char keyBuffer[ECRYPTFS_MAX_KEY_SIZE+1]; + + ecryptfs_payload* authToken = (ecryptfs_payload *)::malloc(sizeof(ecryptfs_payload)); + if (authToken == NULL) { + return NULL; + } + + ::memset(authToken, 0, sizeof(ecryptfs_payload)); + ::strncpy((char*)keyBuffer, key, ECRYPTFS_MAX_KEY_SIZE); + keyBuffer[ECRYPTFS_MAX_KEY_SIZE] = '\0'; + + tokenKey = &authToken->token.password; + + authToken->version = ECRYPTFS_VERSION; + authToken->token_type = ECRYPTFS_PWD_PAYLOAD_TYPE; + tokenKey->session_key_encryption_key_bytes = ECRYPTFS_MAX_KEY_SIZE; + tokenKey->flags = ECRYPTFS_SESSION_KEY_ENCRYPTION_KEY_SET; + ::memcpy(tokenKey->session_key_encryption_key, keyBuffer, ECRYPTFS_MAX_KEY_SIZE); + ::memcpy(tokenKey->signature, keyBuffer, ECRYPTFS_MAX_SIG_HEX); + + return authToken; +} + +int mountEcryptfs(const std::string& src, const std::string& keyName) +{ + int rc; + char ecryptfsOpts[1024]; + ecryptfs_payload* authTok = NULL; + + std::string key; + try { + key = KeyManager::getKey(keyName); + } catch (runtime::Exception& e) { + ERROR(e.what()); + return -1; + } + + if (KernelKeyRing::link(KEY_SPEC_USER_KEYRING, KEY_SPEC_SESSION_KEYRING) != 0) { + ERROR("Failed to link key"); + return -1; + } + + if ((authTok = generateToken((char*)key.c_str())) == NULL) { + ERROR("Failed to generate Token"); + return -1; + } + + const char* signature = (const char*)authTok->token.password.signature; + rc = KernelKeyRing::search(KEY_SPEC_USER_KEYRING, + "user", + signature, + 0); + if (rc == -1 && errno != ENOKEY) { + ERROR("Failed to find key"); + return -1; + } + if (rc == -1) { + rc = KernelKeyRing::add("user", + signature, + (void*)authTok, + sizeof(ecryptfs_payload), + KEY_SPEC_USER_KEYRING); + if (rc == -1) { + ERROR("Failed to add key"); + return -1; + } + } + + ::snprintf(ecryptfsOpts, 1024, + "ecryptfs_passthrough," + "ecryptfs_cipher=aes," + "ecryptfs_key_bytes=%d," + "ecryptfs_sig=%s," + "smackfsroot=*,smackfsdef=*", + ECRYPTFS_MAX_KEY_SIZE, signature); + + rc = ::mount(src.c_str(), src.c_str(), "ecryptfs", MS_NODEV, ecryptfsOpts); + if (rc != 0) { + ERROR(runtime::GetSystemErrorMessage()); + return -1; + } + + return 0; +} + +int mountEcryptfsToAll() +{ + return 0; +} + +void usage(const std::string& prog) +{ + std::cout << "Usage: " << prog << std::endl + << "-a : Automount" << std::endl + << "-g name : Generate key for krate" << std::endl + << "-m name : Apply filesystem encrytion to krate" << std::endl; +} + +int main(int argc, char* argv[]) +{ + int opt, index, ret = -1; + struct option options[] = { + {"automount", no_argument, 0, 'a'}, + {"generate", required_argument, 0, 'g'}, + {"mount", required_argument, 0, 'm'}, + {0, 0, 0, 0} + }; + + while ((opt = getopt_long(argc, argv, "ag:m:", options, &index)) != -1) { + switch (opt) { + case 'a': + ret = mountEcryptfsToAll(); + break; + case 'g': + ret = generateKey(optarg); + break; + case 'm': + ret = mountEcryptfs("/home/" + std::string(optarg), optarg); + break; + default: + std::cerr << "unknown" << std::endl; + usage(argv[0]); + break; + } + } + + if (ret != 0) { + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; +} -- 2.7.4 From a0143cea85671ffb6b0550f67f4bce12a1ad7c5e Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Wed, 3 Aug 2016 15:10:27 +0900 Subject: [PATCH 05/16] Move krate service and library from device-policy-manager git Change-Id: I41078b9ba27da5947fa2d4b30b7edf94c540bf69 Signed-off-by: Jaemin Ryu Signed-off-by: Sungbae Yoo --- CMakeLists.txt | 2 +- krate.manifest | 3 + lib/CMakeLists.txt | 59 +++ lib/app-proxy.cpp | 105 ++++ lib/client.cpp | 80 +++ lib/client.h | 59 +++ lib/context.h | 24 + lib/krate.pc.in | 12 + lib/krate/app-info-internal.h | 115 +++++ lib/krate/app-proxy.cpp | 258 ++++++++++ lib/krate/app-proxy.h | 235 +++++++++ lib/krate/debug.h | 26 + lib/krate/krate.cpp | 156 ++++++ lib/krate/krate.h | 309 ++++++++++++ lib/krate/package-info-internal.h | 106 ++++ lib/krate/package-proxy.cpp | 316 ++++++++++++ lib/krate/package-proxy.h | 254 ++++++++++ lib/manager.cpp | 94 ++++ lib/package-proxy.cpp | 63 +++ module/CMakeLists.txt | 19 +- module/krate.cpp | 4 +- packaging/krate.spec | 65 +-- rmi/app-proxy.h | 90 ++++ rmi/manager.h | 50 ++ rmi/package-proxy.h | 74 +++ server/CMakeLists.txt | 51 +- server/app-bundle.cpp | 51 ++ server/app-bundle.h | 55 ++ server/app-proxy.cpp | 255 ++++++++++ server/context.h | 24 + server/launchpad.cpp | 67 +++ server/launchpad.h | 40 ++ server/main.cpp | 50 ++ server/manager.cpp | 701 ++++++++++++++++++++++++++ server/package-proxy.cpp | 126 +++++ server/packman.cpp | 427 ++++++++++++++++ server/packman.h | 115 +++++ server/server.cpp | 102 ++++ server/server.h | 78 +++ server/systemd/krate.service.in | 7 +- tools/CMakeLists.txt | 4 +- tools/apps/kaskit/src/main.c | 8 +- tools/apps/kaskit/src/widget.c | 2 +- tools/apps/keyguard/CMakeLists.txt | 5 +- tools/apps/keyguard/include/keyguard.h | 12 +- tools/apps/keyguard/include/widget.h | 2 +- tools/apps/keyguard/res/edje/keyguard.edc | 2 +- tools/apps/keyguard/src/main.c | 49 +- tools/apps/keyguard/src/ui.c | 2 +- tools/apps/keyguard/src/widget.c | 2 +- tools/apps/setup-wizard/CMakeLists.txt | 5 +- tools/apps/setup-wizard/include/krate-setup.h | 26 +- tools/apps/setup-wizard/include/setup-text.h | 14 +- tools/apps/setup-wizard/include/widget.h | 2 +- tools/apps/setup-wizard/res/edje/layout.edc | 2 +- tools/apps/setup-wizard/res/edje/setup.edc | 2 +- tools/apps/setup-wizard/res/edje/welcome.edc | 4 +- tools/apps/setup-wizard/src/main.c | 44 +- tools/apps/setup-wizard/src/security.c | 6 +- tools/apps/setup-wizard/src/ui.c | 12 +- tools/apps/setup-wizard/src/util.c | 28 +- tools/apps/setup-wizard/src/widget.c | 2 +- tools/cli/CMakeLists.txt | 7 +- tools/cli/krate-admin-cli.cpp | 62 +-- tools/gumd-scripts/20_krate-add.post | 2 +- tools/gumd-scripts/20_krate-remove.post | 2 +- 66 files changed, 4819 insertions(+), 216 deletions(-) create mode 100755 lib/CMakeLists.txt create mode 100644 lib/app-proxy.cpp create mode 100644 lib/client.cpp create mode 100644 lib/client.h create mode 100644 lib/context.h create mode 100644 lib/krate.pc.in create mode 100644 lib/krate/app-info-internal.h create mode 100644 lib/krate/app-proxy.cpp create mode 100644 lib/krate/app-proxy.h create mode 100644 lib/krate/debug.h create mode 100644 lib/krate/krate.cpp create mode 100644 lib/krate/krate.h create mode 100644 lib/krate/package-info-internal.h create mode 100644 lib/krate/package-proxy.cpp create mode 100644 lib/krate/package-proxy.h create mode 100644 lib/manager.cpp create mode 100644 lib/package-proxy.cpp create mode 100644 rmi/app-proxy.h create mode 100644 rmi/manager.h create mode 100644 rmi/package-proxy.h create mode 100644 server/app-bundle.cpp create mode 100644 server/app-bundle.h create mode 100644 server/app-proxy.cpp create mode 100644 server/context.h create mode 100644 server/launchpad.cpp create mode 100644 server/launchpad.h create mode 100644 server/main.cpp create mode 100644 server/manager.cpp create mode 100644 server/package-proxy.cpp create mode 100644 server/packman.cpp create mode 100644 server/packman.h create mode 100644 server/server.cpp create mode 100644 server/server.h diff --git a/CMakeLists.txt b/CMakeLists.txt index f3f02d5..5fb2706 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -86,7 +86,7 @@ ENDIF(NOT DEFINED CONF_DIR) ADD_DEFINITIONS(-DUG_WAYLAND) -#ADD_SUBDIRECTORY(${KRATE_LIB}) +ADD_SUBDIRECTORY(${KRATE_LIB}) ADD_SUBDIRECTORY(${KRATE_SERVER}) ADD_SUBDIRECTORY(${KRATE_MODULE}) ADD_SUBDIRECTORY(${KRATE_VOLUME}) diff --git a/krate.manifest b/krate.manifest index a76fdba..1badf9e 100644 --- a/krate.manifest +++ b/krate.manifest @@ -2,4 +2,7 @@ + + + diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt new file mode 100755 index 0000000..f205925 --- /dev/null +++ b/lib/CMakeLists.txt @@ -0,0 +1,59 @@ +# +# Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +SET(LIB_VERSION "${VERSION}") +SET(LIB_SOVERSION "0") + +SET(PC_FILE "${PROJECT_NAME}.pc") + +SET(SOURCES client.cpp + manager.cpp + app-proxy.cpp + package-proxy.cpp + krate/krate.cpp + krate/app-proxy.cpp + krate/package-proxy.cpp +) + +SET(CAPI_INCLUDE_FILES krate/krate.h + krate/app-proxy.h + krate/package-proxy.h +) + + +SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") + +PKG_CHECK_MODULES(LIBS_DEPS REQUIRED + klay + glib-2.0 + capi-appfw-package-manager + capi-appfw-app-manager + capi-appfw-app-control + libtzplatform-config +) + +ADD_LIBRARY(${PROJECT_NAME} SHARED ${SOURCES}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES COMPILE_FLAGS "-fvisibility=hidden") +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES SOVERSION ${LIB_SOVERSION}) +SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES VERSION ${LIB_VERSION}) + +INCLUDE_DIRECTORIES(SYSTEM ${LIBS_DEPS_INCLUDE_DIRS} ${DPM_POLICY} ${KRATE_LIB} ${PROJECT_SOURCE_DIR}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${LIBS_DEPS_LIBRARIES} pthread) + +CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_BINARY_DIR}/${PC_FILE} @ONLY) + +INSTALL(FILES ${CMAKE_BINARY_DIR}/${PC_FILE} DESTINATION ${LIB_INSTALL_DIR}/pkgconfig) +INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR} COMPONENT RuntimeLibraries) +INSTALL(FILES ${CAPI_INCLUDE_FILES} DESTINATION ${INCLUDE_INSTALL_DIR}/krate) diff --git a/lib/app-proxy.cpp b/lib/app-proxy.cpp new file mode 100644 index 0000000..112e673 --- /dev/null +++ b/lib/app-proxy.cpp @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include "rmi/app-proxy.h" + +namespace Krate { + +AppProxy::AppProxy(KrateControlContext& ctx) + : context(ctx) +{ +} + +AppProxy::~AppProxy() +{ +} + +AppProxy::AppInfo AppProxy::getAppInfo(const std::string& name, const std::string& appid) +{ + try { + return context->methodCall("AppProxy::getAppInfo", name, appid); + } catch (runtime::Exception& e) {} + return AppProxy::AppInfo(); +} + +int AppProxy::createIterator(const std::string& krate) +{ + try { + return context->methodCall("AppProxy::createIterator", krate); + } catch (runtime::Exception& e) {} + return -1; +} + +AppProxy::AppInfo AppProxy::getIteratorValue(int iterator) +{ + try { + return context->methodCall("AppProxy::getIteratorValue", iterator); + } catch (runtime::Exception& e) {} + return AppProxy::AppInfo(); +} + +bool AppProxy::nextIterator(int iterator) +{ + try { + return context->methodCall("AppProxy::nextIterator", iterator); + } catch (runtime::Exception& e) {} + return false; +} + +int AppProxy::destroyIterator(int iterator) +{ + try { + return context->methodCall("AppProxy::destroyIterator", iterator); + } catch (runtime::Exception& e) {} + return -1; +} + +int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle) +{ + try { + return context->methodCall("AppProxy::launch", name, bundle); + } catch (runtime::Exception& e) { + return -1; + } +} + +int AppProxy::resume(const std::string& name, const std::string& appid) +{ + try { + return context->methodCall("AppProxy::resume", name, appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int AppProxy::terminate(const std::string& name, const std::string& appid) +{ + try { + return context->methodCall("AppProxy::terminate", name, appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +bool AppProxy::isRunning(const std::string& name, const std::string& appid) +{ + try { + return context->methodCall("AppProxy::isRunning", name, appid); + } catch (runtime::Exception& e) { + return -1; + } +} + +} // namespace Krate diff --git a/lib/client.cpp b/lib/client.cpp new file mode 100644 index 0000000..3e3bc58 --- /dev/null +++ b/lib/client.cpp @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include "client.h" + +namespace { + +const std::string SUBSCRIBER_REGISTER = "Server::registerNotificationSubscriber"; +const std::string SUBSCRIBER_UNREGISTER = "Server::unregisterNotificationSubscriber"; + +const std::string KRATE_MANAGER_ADDRESS = "/tmp/.krate.sock"; + +} // namespace + + +KrateContext::KrateContext() noexcept +{ +} + +KrateContext::~KrateContext() noexcept +{ + disconnect(); +} + +int KrateContext::connect(const std::string& address) noexcept +{ + try { + client.reset(new rmi::Client(address)); + client->connect(); + } catch (runtime::Exception& e) { + return -1; + } + + return 0; +} + +int KrateContext::connect() noexcept +{ + return connect(KRATE_MANAGER_ADDRESS); +} + +void KrateContext::disconnect() noexcept +{ + client.reset(); +} + +int KrateContext::subscribeSignal(const std::string& name, + const SignalListener& listener, + void* data) +{ + auto listenerDispatcher = [listener, data](std::string &name, std::string &from, std::string &object) { + listener(from.c_str(), object.c_str(), data); + }; + + try { + return client->subscribe(SUBSCRIBER_REGISTER, + name, listenerDispatcher); + } catch (runtime::Exception& e) { + std::cout << e.what() << std::endl; + return -1; + } +} + +int KrateContext::unsubscribeSignal(int subscriberId) +{ + return client->unsubscribe(SUBSCRIBER_UNREGISTER, subscriberId); +} diff --git a/lib/client.h b/lib/client.h new file mode 100644 index 0000000..f8d1678 --- /dev/null +++ b/lib/client.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __POLICY_CLIENT_H__ +#define __POLICY_CLIENT_H__ + +#include +#include +#include + +#include + +typedef std::function KrateChangeListener; +typedef std::function SignalListener; + +class KrateContext { +public: + typedef std::unique_ptr KrateControlContext; + + KrateContext() noexcept; + ~KrateContext() noexcept; + + int connect() noexcept; + int connect(const std::string& address) noexcept; + void disconnect() noexcept; + + int subscribeSignal(const std::string& name, const SignalListener& listener, void* data); + int unsubscribeSignal(int subscriberId); + + template + Krate createKrateInterface(Args&&... args) noexcept + { + return Krate(getKrateControlContext(), std::forward(args)...); + } + +private: + KrateControlContext& getKrateControlContext() + { + return client; + } + + KrateControlContext client; +}; + +KrateContext& GetKrateContext(void* handle); +#endif //__POLICY_CLIENT_H__ diff --git a/lib/context.h b/lib/context.h new file mode 100644 index 0000000..f1908d1 --- /dev/null +++ b/lib/context.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KRATE_CONTEXT__ +#define __KRATE_CONTEXT__ + +#include "client.h" + +using KrateControlContext = ::KrateContext::KrateControlContext; + +#endif //!__KRATE_CONTEXT__ diff --git a/lib/krate.pc.in b/lib/krate.pc.in new file mode 100644 index 0000000..175f23b --- /dev/null +++ b/lib/krate.pc.in @@ -0,0 +1,12 @@ +# Package Information for pkg-config + +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=@CMAKE_INSTALL_PREFIX@ +libdir=@LIB_INSTALL_DIR@ +includedir=@INCLUDE_INSTALL_DIR@ + +Name: @PROJECT_NAME@ +Description: Tizen @PROJECT_NAME@ Client library +Version: @VERSION@ +Libs: -L${libdir} -l@PROJECT_NAME@ +Cflags: -I${includedir}/@PROJECT_NAME@ diff --git a/lib/krate/app-info-internal.h b/lib/krate/app-info-internal.h new file mode 100644 index 0000000..96f1a7a --- /dev/null +++ b/lib/krate/app-info-internal.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __DPM_APP_INFO_INTERNAL_H__ +#define __DPM_APP_INFO_INTERNAL_H__ + +#include + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct icon_x { + char *text; + char *lang; + char *section; + char *size; + char *resolution; + char *dpi; +} icon_x; + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct label_x { + char *name; + char *text; + char *lang; +} label_x; + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct application_x { + char *appid; /*attr*/ + char *exec; /*attr*/ + char *nodisplay; /*attr, default: "false"*/ + char *multiple; /*attr, default: "false"*/ + char *taskmanage; /*attr, default: "true"*/ + char *enabled; /*attr, default: "true"*/ + char *type; /*attr*/ + char *categories; /*attr*/ + char *extraid; /*attr*/ + char *hwacceleration; /*attr, default: "default"*/ + char *screenreader; /*attr, default: "use-system-setting"*/ + char *mainapp; /*attr, default: "false"*/ + char *package; /*set from package_x*/ + char *recentimage; /*attr, default: "false"*/ + char *launchcondition; /*attr, default: "false"*/ + char *indicatordisplay; /*attr, default: "true"*/ + char *portraitimg; /*attr*/ + char *landscapeimg; /*attr*/ + char *effectimage_type; /*attr, default: "image"*/ + char *guestmode_visibility; /*attr, default: "true"*/ + char *component; /*no xml part*/ + char *permission_type; /*attr, default: "normal"*/ + char *component_type; /*attr, default: "uiapp"*/ + char *preload; /*no xml part*/ + char *submode; /*attr, default: "false"*/ + char *submode_mainid; /*attr, default: "false"*/ + char *process_pool; /*attr, default: "false"*/ + char *installed_storage; + char *autorestart; /*attr, default: "false"*/ + char *onboot; /*attr, default: "false"*/ + char *support_disable; /*set from package_x*/ + char *ui_gadget; /*attr, default: "false"*/ + char *launch_mode; /*attr, default: "single"*/ + char *ambient_support; /*attr, default: "false"*/ + char *alias_appid; /*attr*/ + char *effective_appid; /*attr*/ + char *package_type; /*set from package_x*/ + char *tep_name; /*set from package_x*/ + char *zip_mount_file; /*set from package_x*/ + char *root_path; /*set from package_x*/ + char *api_version; /*set from package_x*/ + char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only, no xml part*/ + char *is_disabled; /**< Flag that indicates if the application is disabled or not, no xml part*/ + char *splash_screen_display; /*attr, default: "true"*/ + GList *label; /*element*/ + GList *icon; /*element*/ + GList *image; /*element*/ + GList *category; /*element*/ + GList *metadata; /*element*/ + GList *permission; /*element*/ + GList *launchconditions; /*element*/ + GList *notification; /*element*/ + GList *datashare; /*element*/ + GList *datacontrol; /*element*/ + GList *background_category; /*element*/ + GList *appcontrol; /*element*/ + GList *splashscreens; /*element*/ +} application_x; + +// pkgmgr-info : include/pkgmgrinfo_private.h +typedef struct _pkgmgr_appinfo_x { + const char *package; + char *locale; + int app_component; + application_x *app_info; +} pkgmgr_appinfo_x; + +// app-manager : src/app_info.c +typedef struct app_info_s { + char *app_id; + pkgmgr_appinfo_x *pkg_app_info; +} app_info_s; + + +#endif //__DPM_APP_INFO_INTERNAL_H__ diff --git a/lib/krate/app-proxy.cpp b/lib/krate/app-proxy.cpp new file mode 100644 index 0000000..449520d --- /dev/null +++ b/lib/krate/app-proxy.cpp @@ -0,0 +1,258 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include + +#include "debug.h" +#include "krate.h" +#include "app-proxy.h" +#include "app-info-internal.h" + +#include "client.h" +#include "rmi/app-proxy.h" + +using namespace Krate; + +struct krate_app_proxy_s { + Krate::AppProxy proxy; + std::string krateName; +}; + +static inline krate_app_proxy_s* getInstance(krate_app_proxy_h handle) +{ + return reinterpret_cast(handle); +} + +static app_info_h make_app_info_handle(const Krate::AppProxy::AppInfo& info) +{ + if (info.id.empty()) { + return NULL; + } + + application_x* app = (application_x*)::malloc(sizeof(application_x)); + pkgmgr_appinfo_x* pkgappinfo = (pkgmgr_appinfo_x*)::malloc(sizeof(pkgmgr_appinfo_x)); + app_info_s* appinfo = (app_info_s*)::malloc(sizeof(struct app_info_s)); + + ::memset(appinfo, 0, sizeof(app_info_s)); + appinfo->app_id = ::strdup(info.id.c_str()); + appinfo->pkg_app_info = pkgappinfo; + + ::memset(pkgappinfo, 0, sizeof(pkgmgr_appinfo_x)); + pkgappinfo->package = ::strdup(info.package.c_str()); + pkgappinfo->locale = ::strdup(info.locale.c_str()); + pkgappinfo->app_component = info.componentType; + pkgappinfo->app_info = app; + + ::memset(app, 0, sizeof(application_x)); + app->appid = ::strdup(info.id.c_str()); + app->nodisplay = ::strdup(info.isNoDisplayed? "true":"false"); + app->taskmanage = ::strdup(info.isTaskManaged? "true":"false"); + app->type = ::strdup(info.type.c_str()); + + icon_x* icon = (icon_x*)::calloc(1, sizeof(icon_x)); + icon->text = ::strdup(info.icon.c_str()); + icon->lang = ::strdup(info.locale.c_str()); + app->icon = ::g_list_append(NULL, icon); + + label_x* label = (label_x*)::calloc(1, sizeof(label_x)); + label->text = ::strdup(info.label.c_str()); + label->lang = ::strdup(info.locale.c_str()); + app->label = ::g_list_append(NULL, label); + + return reinterpret_cast(appinfo); +} + +int krate_app_proxy_create(krate_manager_h manager, const char* name, krate_app_proxy_h *handle) +{ + RET_ON_FAILURE(manager, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + krate_app_proxy_s* instance = new krate_app_proxy_s { + GetKrateContext(manager).createKrateInterface(), + name + }; + + *handle = reinterpret_cast(instance); + return KRATE_ERROR_NONE; +} + +int krate_app_proxy_destroy(krate_app_proxy_h handle) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + delete reinterpret_cast(handle); + + return KRATE_ERROR_NONE; +} + +int krate_app_proxy_get_app_info(krate_app_proxy_h handle, const char* app_id, app_info_h* app_info) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(app_info, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + const auto info = proxy.getAppInfo(name, app_id); + app_info_h ret = make_app_info_handle(info); + if (ret == NULL) { + return KRATE_ERROR_INVALID_PARAMETER; + } + + *app_info = ret; + + return KRATE_ERROR_NONE; +} + +int krate_app_proxy_foreach_app_info(krate_app_proxy_h handle, app_manager_app_info_cb callback, void *user_data) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + int iter = proxy.createIterator(name); + do { + app_info_h info = make_app_info_handle(proxy.getIteratorValue(iter)); + int ret = callback(info, user_data); + app_info_destroy(info); + if (!ret) { + break; + } + } while (proxy.nextIterator(iter)); + proxy.destroyIterator(iter); + + return KRATE_ERROR_NONE; +} + +static bool appExtraCallback(app_control_h app_control, const char *key, void *user_data) +{ + Krate::AppProxy::Bundle *bundle = reinterpret_cast(user_data); + Krate::AppProxy::Bundle::Extra extra; + bool isArray; + + extra.key = key; + + app_control_is_extra_data_array(app_control, key, &isArray); + if (isArray) { + char **values; + int length = 0; + app_control_get_extra_data_array(app_control, key, &values, &length); + for (int i = 0; i < length; i++) { + extra.value.push_back(values[i]); + free(values[i]); + } + free(values); + } else { + char *value; + app_control_get_extra_data(app_control, key, &value); + extra.value.push_back(value); + free(value); + } + bundle->extraData.push_back(extra); + + return true; +} + +int krate_app_proxy_send_launch_request(krate_app_proxy_h handle, app_control_h app_control) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(app_control, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + char *str; + + Krate::AppProxy::Bundle bundle; + app_control_get_operation(app_control, &str); + if (str != NULL) { + bundle.operation = str; + free(str); + str = NULL; + } + app_control_get_uri(app_control, &str); + if (str != NULL) { + bundle.uri = str; + free(str); + str = NULL; + } + app_control_get_mime(app_control, &str); + if (str != NULL) { + bundle.mime = str; + free(str); + str = NULL; + } + app_control_get_category(app_control, &str); + if (str != NULL) { + bundle.category = str; + free(str); + str = NULL; + } + app_control_get_app_id(app_control, &str); + if (str != NULL) { + bundle.appId = str; + free(str); + str = NULL; + } + app_control_foreach_extra_data(app_control, appExtraCallback, &bundle); + + return proxy.launch(name, bundle); +} + +int krate_app_proxy_terminate(krate_app_proxy_h handle, const char* app_id) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + return proxy.terminate(name, app_id); +} + +int krate_app_proxy_resume(krate_app_proxy_h handle, const char* app_id) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + return proxy.resume(name, app_id); +} + +int krate_app_proxy_is_running(krate_app_proxy_h handle, const char* app_id, int *result) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(app_id, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(result, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + *result = proxy.isRunning(name, app_id); + return KRATE_ERROR_NONE; +} diff --git a/lib/krate/app-proxy.h b/lib/krate/app-proxy.h new file mode 100644 index 0000000..02ec714 --- /dev/null +++ b/lib/krate/app-proxy.h @@ -0,0 +1,235 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __CAPI_KRATE_APP_PROXY_H__ +#define __CAPI_KRATE_APP_PROXY_H__ + +#include +#include +#include + +#include + +/** + * @file app-info.h + * @brief This file provides APIs to get the information of applications in the krate + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_KRATE_APPLICATION_INFO_MODULE + * @{ + */ + +/** + * @brief The krate application manager handle + * @since_tizen 3.0 + * @see krate_app_proxy_create() + * @see krate_app_proxy_destroy() + */ +typedef void* krate_app_proxy_h; + +/** + * @brief Acquires the krate application manager handle + * @details This API acquires krate application manager handle required to call + * the krate application manager APIs. + * @since_tizen 3.0 + * @param[in] manager The krate manager handle + * @param[in] name The krate name + * @param[out] handle The krate app proxy handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_CONNECTION_REFUSED Connection refused + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @see krate_manager_create() + * @see krate_app_proxy_create() + * @see get_last_result() + */ +KRATE_API int krate_app_proxy_create(krate_manager_h manager, const char* name, krate_app_proxy_h* handle); + +/** + * @brief Releases the krate application manager handle + * @details This API must be called if interaction with the krate application + * manager handle is no longer required. + * @since_tizen 3.0 + * @param[in] context The device policy manager context + * @param[in] handle The krate application manager handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_app_proxy_create() + * @see krate_app_proxy_create() + */ +KRATE_API int krate_app_proxy_destroy(krate_app_proxy_h handle); + +/** + * @brief Gets the application information for the given application in the krate. + * @details This API gets application information handle required to get + * information of the application in the krate + * @since_tizen 3.0 + * @param[in] handle The krate application manager handle + * @param[in] appid The application ID + * @return Krate application handle on success, otherwise NULL + * @remark The specific error code can be obtained by using the + * get_last_result() method. Error codes are described in + * exception section. + * @exception #KRATE_ERROR_NONE No error + * @exception #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #KRATE_ERROR_TIMED_OUT Time out + * @see krate_app_proxy_create() + * @see krate_app_proxy_create() + * @see krate_application_release() + * @see application_manager_get_application_info() + * @see get_last_result() + */ +KRATE_API int krate_app_proxy_get_app_info(krate_app_proxy_h handle, const char* appid, app_info_h* app_info); + +/** + * @brief Retrieves all the handles of the application in the krate. + * @details This API calls app_manager_app_info_cb() once for each application + * ID with traversing the installed application list in the krate. + * @since_tizen 3.0 + * @param[in] handle The krate application manager handle + * @param[in] callback The iteration callback function + * @param[in] user_data The user data passed to the callback function + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The handle must be created by krate_app_proxy_create(). + * @see krate_app_proxy_create() + * @see krate_app_proxy_create() + * @see application_manager_foreach_app_info() + */ +KRATE_API int krate_app_proxy_foreach_app_info(krate_app_proxy_h handle, app_manager_app_info_cb callback, void *user_data); + +/** + * @brief Launch the application located at the given path into the krate. + * @details Administrator can use this API to launch the application in the + * krate. + * @since_tizen 3.0 + * @param[in] handle The krate application manager handle + * @param[in] app_control The app_control handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_NO_SUCH_FILE No such application file + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API or the caller is not the owner + * of the krate + * @pre The handle must be created by krate_app_proxy_create(). + * @pre The krate corresponding to the given name must be + * created before use of this API. + * @see krate_app_proxy_create() + * @see krate_app_proxy_destroy() + * @see krate_app_proxy_resume() + * @see krate_app_proxy_terminate() + * @see krate_is_running_app() + * @see app_control_send_launch_request() + */ +KRATE_API int krate_app_proxy_send_launch_request(krate_app_proxy_h handle, app_control_h app_control); + +/** + * @brief Terminate the application located at the given path into the krate. + * @details Administrator can use this API to terminate the application in + * the krate. + * @since_tizen 3.0 + * @param[in] handle The krate application manager handle + * @param[in] appid The application ID to be terminated + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_NO_SUCH_FILE No such application file + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API or the caller is not the owner + * of the krate + * @pre The handle must be created by krate_app_proxy_create(). + * @pre The krate corresponding to the given name must be + * created before use of this API. + * @see krate_app_proxy_create() + * @see krate_app_proxy_destroy() + * @see krate_app_proxy_resume() + * @see krate_app_proxy_send_launch_request() + * @see krate_is_running_app() + * @see app_control_send_terminate_request() + * @see app_manager_send_terminate_bt_app() + */ +KRATE_API int krate_app_proxy_terminate(krate_app_proxy_h handle, const char* appid); + +/** + * @brief Resume the application located at the given path into the krate. + * @details Administrator can use this API to resume the application in the + * krate. + * @since_tizen 3.0 + * @param[in] handle The krate application manager handle + * @param[in] appid The application ID to be resumed + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_NO_SUCH_FILE No such application file + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API or the caller is not the owner + * of the krate + * @pre The handle must be created by krate_app_proxy_create(). + * @pre The krate corresponding to the given name must be + * created before use of this API. + * @see krate_app_proxy_create() + * @see krate_app_proxy_destroy() + * @see krate_app_proxy_send_launch_request() + * @see krate_app_proxy_terminate() + * @see app_manager_resume_app() + */ +KRATE_API int krate_app_proxy_resume(krate_app_proxy_h handle, const char* appid); + +/** + * @brief Checks whether the application in the krate is running. + * @details This API can be used to check whether the application in the krate + * is running. + * @since_tizen 3.0 + * @param[in] handle The krate application manager handle + * @param[in] appid The application ID + * @param[out] result true if the application is running, + * otherwise false if the application is not running + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_NO_DATA No such pacakge to check + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_app_proxy_create(). + * @see krate_app_proxy_create() + * @see krate_app_proxy_destroy() + * @see krate_app_proxy_send_launch_request() + * @see krate_app_proxy_terminate() + * @see app_manager_is_running_app() + */ +KRATE_API int krate_app_proxy_is_running(krate_app_proxy_h handle, const char* appid, int* result); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __CAPI_KRATE_APP_PROXY_H__ */ diff --git a/lib/krate/debug.h b/lib/krate/debug.h new file mode 100644 index 0000000..719e478 --- /dev/null +++ b/lib/krate/debug.h @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __CAPI_KRATE_ASSERT_H__ +#define __CAPI_KRATE_ASSERT_H__ + +#define RET_ON_FAILURE(cond, ret) \ +{ \ + if (!(cond)) \ + return (ret); \ +} + +#endif //! __CAPI_KRATE_ASSERT_H__ diff --git a/lib/krate/krate.cpp b/lib/krate/krate.cpp new file mode 100644 index 0000000..6f428f3 --- /dev/null +++ b/lib/krate/krate.cpp @@ -0,0 +1,156 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include "debug.h" +#include "krate.h" + +#include "client.h" +#include "rmi/manager.h" + + +using namespace Krate; + +KrateContext& GetKrateContext(void* handle) +{ + return *reinterpret_cast(handle); +} + +int krate_manager_create(krate_manager_h* handle) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext* client = new(std::nothrow) KrateContext(); + + RET_ON_FAILURE(handle, KRATE_ERROR_CONNECTION_REFUSED); + + if (client->connect() < 0) { + delete client; + RET_ON_FAILURE(handle, KRATE_ERROR_CONNECTION_REFUSED); + } + + *handle = reinterpret_cast(client); + + return KRATE_ERROR_NONE; +} + +int krate_manager_destroy(krate_manager_h handle) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + delete &GetKrateContext(handle); + + return KRATE_ERROR_NONE; +} + +int krate_manager_add_event_cb(krate_manager_h handle, const char* event, krate_event_cb callback, void* user_data, int *id) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(event, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext &context = GetKrateContext(handle); + int ret = context.subscribeSignal(std::string("Manager::") + event, + callback, user_data); + if (ret < 0) + return KRATE_ERROR_INVALID_PARAMETER; + + *id = ret; + return KRATE_ERROR_NONE; +} + +int krate_manager_remove_event_cb(krate_manager_h handle, int callback_id) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(callback_id >= 0, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext &context = GetKrateContext(handle); + int ret = context.unsubscribeSignal(callback_id); + if (ret) + return KRATE_ERROR_INVALID_PARAMETER; + + return KRATE_ERROR_NONE; +} + +int krate_manager_create_krate(krate_manager_h handle, const char* name, const char* manifest) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(manifest, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext &client = GetKrateContext(handle); + Krate::Manager krate = client.createKrateInterface(); + return krate.createKrate(name, manifest); +} + +int krate_manager_destroy_krate(krate_manager_h handle, const char* name) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext &client = GetKrateContext(handle); + Krate::Manager krate = client.createKrateInterface(); + return krate.removeKrate(name); +} + +int krate_manager_get_krate_state(krate_manager_h handle, const char* name, krate_state_e *state) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext &client = GetKrateContext(handle); + Krate::Manager krate = client.createKrateInterface(); + + int result = krate.getKrateState(name); + if (result == 0) { + return KRATE_ERROR_NO_DATA; + } + + *state = (krate_state_e)result; + return KRATE_ERROR_NONE; +} + +int krate_manager_foreach_name(krate_manager_h handle, krate_state_e state, + krate_manager_foreach_cb callback, void* user_data) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER); + + KrateContext &client = GetKrateContext(handle); + Krate::Manager krate = client.createKrateInterface(); + std::vector list = krate.getKrateList(state); + for (std::vector::iterator it = list.begin(); + it != list.end(); it++) { + if (!callback((*it).c_str(), user_data)) + break; + } + + return KRATE_ERROR_NONE; +} + +int krate_manager_reset_krate_password(krate_manager_h handle, const char* name, const char* new_password) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER); + + if (new_password == NULL) { + new_password = ""; + } + + KrateContext &client = GetKrateContext(handle); + Krate::Manager krate = client.createKrateInterface(); + + return krate.resetKratePassword(name, new_password); +} diff --git a/lib/krate/krate.h b/lib/krate/krate.h new file mode 100644 index 0000000..15aa135 --- /dev/null +++ b/lib/krate/krate.h @@ -0,0 +1,309 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KRATE_KRATE_MANAGER_H__ +#define __KRATE_KRATE_MANAGER_H__ + +#include + +/** + * @file krate.h + * @brief This file defines common data types required to krate APIs. + */ + +#ifndef KRATE_API +#define KRATE_API __attribute__((visibility("default"))) +#endif // API + +#ifndef TRUE +#define TRUE 1 +#endif + +#ifndef FALSE +#define FALSE 0 +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_KRATE_KRATE_MANAGER_MODULE + * @{ + */ + +/** + * @brief Enumeration of device policy API errors + * @since_tizen 3.0 + */ +typedef enum { + KRATE_ERROR_NONE = TIZEN_ERROR_NONE, /**< The operation was successful */ + KRATE_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER, /**< Invalid parameter */ + KRATE_ERROR_CONNECTION_REFUSED = TIZEN_ERROR_CONNECTION_REFUSED, /**< Connection refused */ + KRATE_ERROR_TIMED_OUT = TIZEN_ERROR_TIMED_OUT, /**< Time out */ + KRATE_ERROR_PERMISSION_DENIED = TIZEN_ERROR_PERMISSION_DENIED, /**< Access privilege is not sufficient */ + KRATE_ERROR_NOT_SUPPORTED = TIZEN_ERROR_NOT_SUPPORTED, /**< Operation is not supported */ + KRATE_ERROR_NO_SUCH_FILE = TIZEN_ERROR_NO_SUCH_FILE, /**< No such file or directory */ + KRATE_ERROR_FILE_EXISTS = TIZEN_ERROR_FILE_EXISTS, /**< File exists */ + KRATE_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, /**< Out of memory */ + KRATE_ERROR_NO_DATA = TIZEN_ERROR_NO_DATA /**< No Data */ +} krate_error_type_e; + +/** + * @brief The krate manager handle + * @details The krate manager handle is an abstraction of the + * logical connection between the krate manager and it's client. + * The krate manager handle must be created by using + * krate_manager_create() before attempting to use almost any of + * the krate related APIs, and it should be freed when interaction + * with the krate manager is no longer required. + * To release the handle, use krate_manager_destroy(). + * @since_tizen 3.0 + * @see krate_manager_create() + * @see krate_manager_destroy() + */ +typedef void* krate_manager_h; + +/** + * @brief Creates the krate manager handle. + * @details This API creates krate manager handle required to + * the krate related APIs. + * This API is also used to verify whether caller is authorized + * or not. + * @since_tizen 3.0 + * @param[out] handle The krate manager handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_CONNECTION_REFUSED Connection refused + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @see krate_manager_destroy() + * @see get_last_result() + */ +KRATE_API int krate_manager_create(krate_manager_h *handle); + +/** + * @brief Releases the krate manager handle. + * @details This API must be called if interaction with the krate manager is + * no longer required. + * @since_tizen 3.0 + * @param[in] handle The krate manager handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The handle must be created by krate_manager_create() + * @see krate_manager_create() + */ +KRATE_API int krate_manager_destroy(krate_manager_h handle); + +/** + * @brief Called when a krate raises a event. + * @since_tizen 3.0 + * @param[in] name The krate name + * @param[in] object The object name triggered the event + * @param[in] user_data The user data passed from krate_manager_add_event_cb + * @see krate_manager_add_event_cb() + * @see krate_manager_remove_event_cb() + */ +typedef void(*krate_event_cb)(const char* name, const char* object, void* user_data); + +/** + * @brief Adds krate event callback. + * @details This API can be used to receive events sent by krate + * The callback specified to this function is automatically called when + * the krate is created or removed. + * @since_tizen 3.0 + * @param[in] context The krate_manager handle + * @param[in] event The event name to receive + * @param[in] callback The event callback + * @param[in] user_data The user data passed to the callback function + * @param[out] id Signal identifier + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_manager_create(). + * @see krate_manager_create() + * @see krate_manager_destroy() + * @see krate_manager_remove_event_cb() + */ +KRATE_API int krate_manager_add_event_cb(krate_manager_h handle, + const char* event, + krate_event_cb callback, void* user_data, + int* id); + +/** + * @brief Removes krate event callback. + * @details This API removes krate event callback + * @since_tizen 3.0 + * @param[in] context The krate manager handle + * @param[in] id Signal identifier + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The context must be created by krate_manager_create(). + * @see krate_manager_create() + * @see krate_manager_destroy() + * @see krate_manager_add_event_cb() + */ +KRATE_API int krate_manager_remove_event_cb(krate_manager_h handle, int id); + +/** + * @brief Creates a new krate. + * @details This API creates a container. All file system objects neeeded + * will be also created. manifest XML passed by parameter will be + * used when the krate is running. + * @since_tizen 3.0 + * @param[in] handle The krate manager handle + * @param[in] name The krate name to be created + * @param[in] manifest The manifest XML to be used when the krate is runned. + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API + * @pre The handle must be created by krate_manager_create(). + * @see krate_manager_create() + * @see krate_manager_destroy() + * @see krate_manager_destroy_krate() + * @see krate_manager_create_krate_iterator() + */ +KRATE_API int krate_manager_create_krate(krate_manager_h handle, + const char* name, + const char* manifest); + +/** + * @brief Removes existing krate. + * @details This removes krate. All file system objects created for the krate + * will be also erased. + * @since_tizen 3.0 + * @param[in] handle The krate manager handle + * @param[in] name The krate name to be removed + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API or the caller is not the owner + * of the krate + * @pre The handle must be created by krate_manager_create(). + * @pre The krate corresponding to the given name must be + * created before use of this API. + * @see krate_manager_create() + * @see krate_manager_destroy() + * @see krate_manager_create_krate() + * @see krate_manager_create_krate_iterator() + */ +KRATE_API int krate_manager_destroy_krate(krate_manager_h handle, + const char* name); + +/* + * @brief Enumeration for krate state + * @since_tizen 3.0 + */ +typedef enum { + KRATE_STATE_LOCKED = 0x01, /**< Krate has been defined, but it can not start. */ + KRATE_STATE_RUNNING = 0x02, /**< Krate has been started. */ + KRATE_STATE_ALL = 0xff /**< This presents all of the state */ +} krate_state_e; + +/** + * @brief Gets the krate state. + * @details This API can be used to get the state of the krate. The krate can + * have one of the three states(running, locked). + * @since_tizen 3.0 + * @param[in] handle The krate policy handle + * @param[in] name The krate name + * @param[out] state The krate state + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_NO_DATA No such krate to get state + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_manager_create(). + * @see krate_manager_create() + * @see krate_manager_destroy() + * @see krate_manager_create_krate() + * @see krate_manager_destroy_krate() + */ +KRATE_API int krate_manager_get_krate_state(krate_manager_h handle, + const char* name, + krate_state_e* state); + +/** + * @brief Called to get all the name of created krates. + * @since_tizen 3.0 + * @param[in] name The krate name + * @param[in] user_data The user data passed from krate_manager_foreach_name + * @return true to continue with the next iteration of the loop, otherwise false to break out out the loop + * @see krate_manager_foreach_name() + */ +typedef bool(*krate_manager_foreach_cb)(const char* name, void* user_data); + +/** + * @brief Retrieves all the name of created krates + * @details This API calls krate_manager_foreach_cb() once for each krate name + * with traversing the created krates list. + * @since_tizen 3.0 + * @param[in] handle The krate policy handle + * @param[in] state a combination of the krate state to look + * @param[in] callback The iteration callback function + * @param[in] user_data The user data passed to the callback function + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The handle must be created by krate_manager_create(). + * @see krate_manager_create() + * @see krate_manager_destroy() + * @see krate_manager_create_krate() + * @see krate_manager_destroy_krate() + */ +KRATE_API int krate_manager_foreach_name(krate_manager_h handle, + krate_state_e state, + krate_manager_foreach_cb callback, + void* user_data); + +/** + * @brief Reset password for the krate. + * @details This API can be used to set password for the krate. The password + * of the krate can be used for authenticating user. + * @since_tizen 3.0 + * @param[in] handle The krate policy handle + * @param[in] name The krate name + * @param[out] new_password new password if NULL, existing password will be removed + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_NO_DATA No such krate to get state + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_manager_create(). + * @see krate_manager_create() + * @see krate_manager_destroy() + */ +KRATE_API int krate_manager_reset_krate_password(krate_manager_h handle, + const char* name, const char* new_password); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __KRATE_KRATE_MANAGER_H__ */ diff --git a/lib/krate/package-info-internal.h b/lib/krate/package-info-internal.h new file mode 100644 index 0000000..d84fa79 --- /dev/null +++ b/lib/krate/package-info-internal.h @@ -0,0 +1,106 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KRATE_PACKAGE_INFO_INTERNAL_H__ +#define __KRATE_PACKAGE_INFO_INTERNAL_H__ + +#include + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct icon_x { + char *text; + char *lang; + char *section; + char *size; + char *resolution; + char *dpi; +} icon_x; + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct description_x { + char *name; + char *text; + char *lang; +} description_x; + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct label_x { + char *name; + char *text; + char *lang; +} label_x; + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct author_x { + char *email; + char *href; + char *text; + char *lang; +} author_x; + +// pkgmgr-info : include/pkgmgrinfo_basic.h +typedef struct package_x { + char *for_all_users; /**< Flag that indicates if the package is available for everyone or for current user only, no xml part*/ + char *package; /**< package name, attr*/ + char *version; /**< package version, attr*/ + char *installlocation; /**< package install location, attr, default: "internal-only"*/ + char *ns; /** +#include +#include + +#include +#include +#include +#include + +#include "debug.h" +#include "krate.h" +#include "package-proxy.h" +#include "package-info-internal.h" + +#include "client.h" +#include "rmi/package-proxy.h" + +using namespace Krate; + +struct krate_package_proxy_s { + PackageProxy proxy; + std::string krateName; + pkgmgr_client* pNativeHandle; + package_manager_event_cb pCallback; + void *pCallbackUserData; +}; + +static inline krate_package_proxy_s* getInstance(krate_package_proxy_h handle) +{ + return reinterpret_cast(handle); +} + +static int packageEventHandler(uid_t target_uid, int req_id, + const char *pkg_type, const char *pkg_name, + const char *key, const char *val, + const void *pmsg, void *data) +{ + static auto event_type = (package_manager_event_type_e)-1; + auto event_state = PACKAGE_MANAGER_EVENT_STATE_FAILED; + auto instance = getInstance(data); + std::string keystr = key; + int progress = 0; + + if (target_uid != tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) { + try { + runtime::User pkgOwner(target_uid); + if (pkgOwner.getName() != instance->krateName) { + return PACKAGE_MANAGER_ERROR_NONE; + } + } catch (runtime::Exception &e) { + return PACKAGE_MANAGER_ERROR_NONE; + } + } + + std::transform(keystr.begin(), keystr.end(), keystr.begin(), ::tolower); + + if (keystr == "start") { + if (val == NULL) { + return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER; + } + + std::string valstr = val; + std::transform(valstr.begin(), valstr.end(), valstr.begin(), ::tolower); + if (valstr == "install") { + event_type = PACKAGE_MANAGER_EVENT_TYPE_INSTALL; + } else if (valstr == "uninstall") { + event_type = PACKAGE_MANAGER_EVENT_TYPE_UNINSTALL; + } else if (valstr == "update") { + event_type = PACKAGE_MANAGER_EVENT_TYPE_UPDATE; + } else { + return PACKAGE_MANAGER_ERROR_INVALID_PARAMETER; + } + + event_state = PACKAGE_MANAGER_EVENT_STATE_STARTED; + } else if (keystr == "install_percent" || + keystr == "progress_percent") { + event_state = PACKAGE_MANAGER_EVENT_STATE_PROCESSING; + progress = std::stoi(val); + } else if (keystr == "error") { + event_state = PACKAGE_MANAGER_EVENT_STATE_FAILED; + } else if (keystr == "end" || + keystr == "ok") { + event_state = PACKAGE_MANAGER_EVENT_STATE_COMPLETED; + progress = 100; + } + + instance->pCallback(pkg_type, pkg_name, + event_type, event_state, progress, + PACKAGE_MANAGER_ERROR_NONE, + instance->pCallbackUserData); + + + return PACKAGE_MANAGER_ERROR_NONE; +} + +static package_info_h make_package_info_handle(const PackageProxy::PackageInfo& info) +{ + uid_t krate_uid; + + if (info.id.empty()) { + return NULL; + } + + try { + runtime::User pkgOwner(info.krate); + krate_uid = pkgOwner.getUid(); + } catch (runtime::Exception &e) { + return NULL; + } + + package_x* package = (package_x*)::calloc(1, sizeof(package_x)); + pkgmgr_pkginfo_x* pkginfo = (pkgmgr_pkginfo_x*)::calloc(1, sizeof(pkgmgr_pkginfo_x)); + package_info_s* packageinfo = (package_info_s*)::calloc(1, sizeof(package_info_s)); + + packageinfo->package = ::strdup(info.id.c_str()); + packageinfo->pkgmgr_pkginfo = pkginfo; + + pkginfo->uid = krate_uid; + pkginfo->locale = ::strdup(info.locale.c_str()); + pkginfo->pkg_info = package; + + package->for_all_users = ::strdup("false"); + package->package = ::strdup(info.id.c_str()); + package->version = ::strdup(info.version.c_str()); + package->removable = ::strdup(info.isRemovable? "true":"false"); + package->preload = ::strdup(info.isPreload? "true":"false"); + package->system = ::strdup(info.isSystem? "true":"false"); + package->type = ::strdup(info.type.c_str()); + package->mainapp_id = ::strdup(info.mainAppId.c_str()); + package->api_version = ::strdup(info.apiVersion.c_str()); + + icon_x* icon = (icon_x*)::calloc(1, sizeof(icon_x)); + icon->text = ::strdup(info.icon.c_str()); + icon->lang = ::strdup(info.locale.c_str()); + package->icon = ::g_list_append(NULL, icon); + + label_x* label = (label_x*)::calloc(1, sizeof(label_x)); + label->text = ::strdup(info.label.c_str()); + label->lang = ::strdup(info.locale.c_str()); + package->label = ::g_list_append(NULL, label); + + description_x* desc = (description_x*)::calloc(1, sizeof(description_x)); + desc->text = ::strdup(info.description.c_str()); + desc->lang = ::strdup(info.locale.c_str()); + package->description = ::g_list_append(NULL, desc); + + author_x* author = (author_x*)::calloc(1, sizeof(author_x)); + author->text = ::strdup(info.author.name.c_str()); + author->email = ::strdup(info.author.email.c_str()); + author->href = ::strdup(info.author.href.c_str()); + author->lang = ::strdup(info.locale.c_str()); + package->author = ::g_list_append(NULL, author); + + return reinterpret_cast(packageinfo); +} + +int krate_package_proxy_create(krate_manager_h manager, const char* name, krate_package_proxy_h *handle) +{ + RET_ON_FAILURE(manager, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(name, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + krate_package_proxy_s* instance = new krate_package_proxy_s { + GetKrateContext(manager). + createKrateInterface(), + name, ::pkgmgr_client_new(PC_LISTENING), NULL, NULL + }; + + *handle = reinterpret_cast(instance); + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_destroy(krate_package_proxy_h handle) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + krate_package_proxy_s* instance = getInstance(handle); + + ::pkgmgr_client_free(instance->pNativeHandle); + + delete instance; + + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_get_package_info(krate_package_proxy_h handle, const char* package_id, package_info_h* package_info) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(package_id, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(package_info, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + const auto& info = proxy.getPackageInfo(name, package_id); + package_info_h ret = make_package_info_handle(info); + + if (ret == NULL) { + return KRATE_ERROR_INVALID_PARAMETER; + } + + *package_info = ret; + + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_foreach_package_info(krate_package_proxy_h handle, package_manager_package_info_cb callback, void *user_data) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + for (const auto& pkgid : proxy.getPackageList(name)) { + package_info_h info_h = make_package_info_handle(proxy.getPackageInfo(name, pkgid)); + int ret = callback(info_h, user_data); + package_info_destroy(info_h); + if (!ret) { + break; + } + } + + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_set_event_status(krate_package_proxy_h handle, int status_type) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + + int ret; + ret = pkgmgrinfo_client_set_status_type(instance->pNativeHandle, status_type); + + if (ret != PACKAGE_MANAGER_ERROR_NONE) + return KRATE_ERROR_INVALID_PARAMETER; + + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_set_event_cb(krate_package_proxy_h handle, package_manager_event_cb callback, void *user_data) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(callback, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + + instance->pCallback = callback; + instance->pCallbackUserData = user_data; + + int ret; + ret = pkgmgr_client_listen_status(instance->pNativeHandle, packageEventHandler, handle); + + if (ret < 0) + return KRATE_ERROR_INVALID_PARAMETER; + + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_unset_event_cb(krate_package_proxy_h handle) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + + int ret; + ret = pkgmgr_client_remove_listen_status(instance->pNativeHandle); + + if (ret < 0) + return KRATE_ERROR_INVALID_PARAMETER; + + return KRATE_ERROR_NONE; +} + +int krate_package_proxy_install(krate_package_proxy_h handle, const char* package_path) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(package_path, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + return proxy.install(name, package_path); +} + +int krate_package_proxy_uninstall(krate_package_proxy_h handle, const char* package_id) +{ + RET_ON_FAILURE(handle, KRATE_ERROR_INVALID_PARAMETER); + RET_ON_FAILURE(package_id, KRATE_ERROR_INVALID_PARAMETER); + + auto instance = getInstance(handle); + auto& proxy = instance->proxy; + const std::string& name = instance->krateName; + + return proxy.uninstall(name, package_id); +} diff --git a/lib/krate/package-proxy.h b/lib/krate/package-proxy.h new file mode 100644 index 0000000..5dda76a --- /dev/null +++ b/lib/krate/package-proxy.h @@ -0,0 +1,254 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __CAPI_KRATE_PACKAGE_INFO_H__ +#define __CAPI_KRATE_PACKAGE_INFO_H__ + +#include +#include + +#include + +/** + * @file package-info.h + * @brief This file provides APIs to get the information of packages in the krate + */ + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @addtogroup CAPI_KRATE_KRATE_PACKAGE_INFO_MODULE + * @{ + */ + +/** + * @brief The krate package proxy handle + * @since_tizen 3.0 + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + */ +typedef void* krate_package_proxy_h; + +/** + * @brief Acquires the krate package proxy handle. + * @details This API acquires krate package proxy handle required to call + * the krate package_manager APIs. + * @since_tizen 3.0 + * @param[in] manager The krate manager handle + * @param[in] name The krate name + * @param[out] handle The krate package proxy handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_CONNECTION_REFUSED Connection refused + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @see krate_manager_create() + * @see krate_package_proxy_destroy() + * @see get_last_result() + */ +KRATE_API int krate_package_proxy_create(krate_manager_h manager, const char* name, krate_package_proxy_h *handle); + +/** + * @brief Releases the krate package proxy handle. + * @details This API must be called if interaction with the krate package + * manager handle is no longer required. + * @since_tizen 3.0 + * @param[in] handle The krate package proxy handle + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_package_proxy_create() + * @see krate_package_proxy_create() + */ +KRATE_API int krate_package_proxy_destroy(krate_package_proxy_h handle); + +/** + * @brief Gets the package information for the given package in the krate. + * @details This API gets package information handle required to get + * information of the pacakge in the krate. + * @since_tizen 3.0 + * @param[in] handle The krate package proxy handle + * @param[in] pakcage_id The package ID + * @return Krate package information handle on success, otherwise NULL + * @remark The specific error code can be obtained by using the + * get_last_result() method. Error codes are described in + * exception section. + * @remark The handle should be destroyed using package_info_destroy(). + * @exception #KRATE_ERROR_NONE No error + * @exception #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @exception #KRATE_ERROR_TIMED_OUT Time out + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see package_manager_get_package_info() + * @see package_manager_destroy() + * @see get_last_result() + */ +KRATE_API int krate_package_proxy_get_package_info(krate_package_proxy_h handle, const char* pakcage_id, package_info_h* package_info); + +/** + * @brief Retrieves all the IDs of the installed package in the krate. + * @details This API calls package_manager_package_info_cb() once for + * each package information handle with traversing the installed + * package list in the krate. + * @since_tizen 3.0 + * @param[in] handle The krate package proxy handle + * @param[in] callback The iteration callback function + * @param[in] user_data The user data passed to the callback function + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @pre The handle must be created by krate_package_proxy_create(). + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see package_manager_foreach_package_info() + */ +KRATE_API int krate_package_proxy_foreach_package_info(krate_package_proxy_h handle, package_manager_package_info_cb callback, void *user_data); + +/** + * @brief Installs the package located at the given path into the krate. + * @details Administrator can use this API to install the package into the + * krate. + * @since_tizen 3.0 + * @param[in] handle The krate package proxy handle + * @param[in] name The krate name + * @param[in] package_path The absolute path to the package to be installed + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_NO_SUCH_FILE No such package file + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API or the caller is not the owner + * of the krate + * @pre The handle must be created by krate_package_proxy_create(). + * @pre The krate corresponding to the given name must be + * created before use of this API. + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see krate_package_proxy_uninstall() + * @see package_manager_request_install() + */ +KRATE_API int krate_package_proxy_install(krate_package_proxy_h handle, const char* package_path); + +/** + * @brief Uinstalls the package with the given ID from the krate. + * @details Administrator can use this API to uninstall the package from the + * krate. + * @since_tizen 3.0 + * @param[in] handle The krate package proxy handle + * @param[in] name The krate name + * @param[in] pakcage_id The pakcage ID + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @retval #KRATE_ERROR_NO_DATA No such pacakge to unintall + * @retval #KRATE_ERROR_PERMISSION_DENIED The application does not have + * the privilege to call this API or the caller is not the owner + * of the krate + * @pre The handle must be created by krate_package_proxy_create(). + * @pre The krate corresponding to the given name must be + * created before use of this API. + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see krate_package_proxy_install() + * @see package_manager_request_uninstall() + */ +KRATE_API int krate_package_proxy_uninstall(krate_package_proxy_h handle, const char* pakcage_id); + +/** + * @brief Sets the event status that presents the package has been + * installed, uninstalled or updated in the krate. + * @details This API sets the event status of the package for monitoring + * whether the package has been installed, uninstalled or updated. + * event status can be combined multiple status using OR operation. + * @since_tizen 3.0 + * @param[in] handle The krate package proxy handle + * @param[in] status_type The status of the package + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre The handle must be created by krate_package_proxy_create(). + * @pre the krate corresponding to the given name must be + * created before use of this api. + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see krate_package_proxy_uninstall() + * @see krate_package_proxy_set_event_cb() + * @see krate_package_proxy_unset_event_cb() + * @see package_manager_set_event_status() + */ +KRATE_API int krate_package_proxy_set_event_status(krate_package_proxy_h handle, int status_type); + +/** + * @brief Registers a callback function for package event. + * @details This API sets a callback function to be invoked when the package + * has been installed, uninstalled or updated. + * @since_tizen 3.0 + * @param[in] handle the krate package proxy handle + * @param[in] callback The callback function to be registered + * @param[in] user_data The user data to be passed to the callback function + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre the handle must be created by krate_package_proxy_create(). + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see krate_package_proxy_uninstall() + * @see krate_package_proxy_set_event_status() + * @see krate_package_proxy_unset_event_cb() + * @see package_manager_event_cb() + * @see package_manager_set_event_cb() + */ +KRATE_API int krate_package_proxy_set_event_cb(krate_package_proxy_h handle, package_manager_event_cb callback, void *user_data); + +/** + * @brief Unregisters the callback function. + * @details This API unsets the callback funtion not to be invoked by + * package event status + * @since_tizen 3.0 + * @param[in] handle the krate package proxy handle + * @param[in] name the krate name + * @return #KRATE_ERROR_NONE on success, otherwise a negative value + * @retval #KRATE_ERROR_NONE Successful + * @retval #KRATE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #KRATE_ERROR_TIMED_OUT Time out + * @pre the handle must be created by krate_package_proxy_create(). + * created before use of this api. + * @see krate_package_proxy_create() + * @see krate_package_proxy_destroy() + * @see krate_package_proxy_uninstall() + * @see krate_package_proxy_set_event_status() + * @see krate_package_proxy_set_event_cb() + * @see package_manager_unset_event_cb() + */ +KRATE_API int krate_package_proxy_unset_event_cb(krate_package_proxy_h handle); + + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif + +#endif /* __CAPI_KRATE_PACKAGE_INFO_H__ */ diff --git a/lib/manager.cpp b/lib/manager.cpp new file mode 100644 index 0000000..57a5264 --- /dev/null +++ b/lib/manager.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include "rmi/manager.h" + +namespace Krate { + +Manager::Manager(KrateControlContext& ctx) : + context(ctx) +{ +} + +Manager::~Manager() +{ +} + +int Manager::createKrate(const std::string& name, const std::string& setupWizAppid) +{ + try { + return context->methodCall("Manager::createKrate", name, setupWizAppid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Manager::removeKrate(const std::string& name) +{ + try { + return context->methodCall("Manager::removeKrate", name); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Manager::lockKrate(const std::string& name) +{ + try { + return context->methodCall("Manager::lockKrate", name); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Manager::unlockKrate(const std::string& name) +{ + try { + return context->methodCall("Manager::unlockKrate", name); + } catch (runtime::Exception& e) { + return -1; + } +} + +int Manager::getKrateState(const std::string& name) +{ + try { + return context->methodCall("Manager::getKrateState", name); + } catch (runtime::Exception& e) { + return -1; + } +} + +std::vector Manager::getKrateList(int state) +{ + std::vector empty; + try { + return context->methodCall>("Manager::getKrateList", state); + } catch (runtime::Exception& e) { + return empty; + } +} + +int Manager::resetKratePassword(const std::string& name, const std::string& newPassword) +{ + try { + return context->methodCall("Manager::resetKratePassword", name, newPassword); + } catch (runtime::Exception& e) { + return -1; + } +} + +} // namespace Krate diff --git a/lib/package-proxy.cpp b/lib/package-proxy.cpp new file mode 100644 index 0000000..0a58e34 --- /dev/null +++ b/lib/package-proxy.cpp @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include "rmi/package-proxy.h" + +namespace Krate { + +PackageProxy::PackageProxy(KrateControlContext& ctx) : + context(ctx) +{ +} + +PackageProxy::~PackageProxy() +{ +} + +PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, const std::string& pkgid) +{ + try { + return context->methodCall("PackageProxy::getPackageInfo", name, pkgid); + } catch (runtime::Exception& e) {} + return PackageProxy::PackageInfo(); +} + +std::vector PackageProxy::getPackageList(const std::string& krate) +{ + try { + return context->methodCall>("PackageProxy::getPackageList", krate); + } catch (runtime::Exception& e) {} + return std::vector();; +} + +int PackageProxy::install(const std::string& name, const std::string& pkgid) +{ + try { + return context->methodCall("PackageProxy::install", name, pkgid); + } catch (runtime::Exception& e) { + return -1; + } +} + +int PackageProxy::uninstall(const std::string& name, const std::string& pkgid) +{ + try { + return context->methodCall("PackageProxy::uninstall", name, pkgid); + } catch (runtime::Exception& e) { + return -1; + } +} + +} // namespace Krate diff --git a/module/CMakeLists.txt b/module/CMakeLists.txt index be7a884..ab4f5e3 100644 --- a/module/CMakeLists.txt +++ b/module/CMakeLists.txt @@ -1,7 +1,7 @@ # # Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved # -# Licensed under the Apache License, Version 2.0 (the "License"); +# Licensed under the Apache License, Version 2.0(the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # @@ -18,10 +18,12 @@ FILE(GLOB PAM_SRCS krate.cpp krate-builder.cpp ) -SET (CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") +SET(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-z,noexecstack") -ADD_LIBRARY(pam_${PROJECT_NAME} MODULE ${PAM_SRCS}) -SET_TARGET_PROPERTIES(pam_${PROJECT_NAME} PROPERTIES PREFIX "" +SET(PAM_NAME pam_${PROJECT_NAME}) + +ADD_LIBRARY(${PAM_NAME} MODULE ${PAM_SRCS}) +SET_TARGET_PROPERTIES(${PAM_NAME} PROPERTIES PREFIX "" COMPILE_DEFINITIONS PID_FILE_PATH="${RUN_INSTALL_DIR}/krate" COMPILE_FLAGS "-fvisibility=hidden" ) @@ -36,16 +38,17 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(PAM DEFAULT_MSG PAM_LIBRARY PAM_INCLUDE_DIR) PKG_CHECK_MODULES(PAM_DEPS REQUIRED klay + libxml-2.0 ) INCLUDE_DIRECTORIES(${PAM_INCLUDE_DIR} ${PAM_DEPS_INCLUDE_DIRS}) -TARGET_LINK_LIBRARIES(pam_${PROJECT_NAME} ${PAM_LIBRARY} ${PAM_DEPS_LIBRARIES} pthread) +TARGET_LINK_LIBRARIES(${PAM_NAME} ${PAM_LIBRARY} ${PAM_DEPS_LIBRARIES} pthread) -TARGET_COMPILE_DEFINITIONS(pam_${PROJECT_NAME} PRIVATE - CONF_PATH="${CONF_INSTALL_DIR}" +TARGET_COMPILE_DEFINITIONS(${PAM_NAME} PRIVATE + CONF_PATH="${CONF_DIR}" ) CONFIGURE_FILE(pam.d/systemd-user.in pam.d/systemd-user-${PROJECT_NAME}) -INSTALL(TARGETS pam_${PROJECT_NAME} DESTINATION ${LIB_INSTALL_DIR}/security) +INSTALL(TARGETS ${PAM_NAME} DESTINATION ${LIB_INSTALL_DIR}/security) INSTALL(FILES pam.d/systemd-user-${PROJECT_NAME} DESTINATION ${PAMD_DIR}) diff --git a/module/krate.cpp b/module/krate.cpp index 06fea56..84496cf 100644 --- a/module/krate.cpp +++ b/module/krate.cpp @@ -30,11 +30,9 @@ #include #include -#define KRATE_MANIFEST_DIR CONF_PATH "/krate/" - std::string buildKrateManifestPath(const std::string& name) { - return KRATE_MANIFEST_DIR + name + ".xml"; + return CONF_PATH "/" + name + ".xml"; } std::string getKrateName(pam_handle_t* handle) diff --git a/packaging/krate.spec b/packaging/krate.spec index a6e952e..e132b27 100644 --- a/packaging/krate.spec +++ b/packaging/krate.spec @@ -5,6 +5,8 @@ License: Apache-2.0 Source0: file://%{name}-%{version}.tar.gz Summary: Tizen Krate Manager Group: Security/Other +Requires: systemd +BuildRequires: pam-devel BuildRequires: gcc BuildRequires: cmake BuildRequires: gettext-tools @@ -17,13 +19,13 @@ BuildRequires: pkgconfig(pkgmgr-info) BuildRequires: pkgconfig(aul) BuildRequires: pkgconfig(appsvc) BuildRequires: pkgconfig(libtzplatform-config) -BuildRequires: pkgconfig(security-privilege-manager) -BuildRequires: pkgconfig(capi-base-common) -BuildRequires: pkgconfig(capi-system-info) BuildRequires: pkgconfig(capi-system-system-settings) BuildRequires: pkgconfig(notification) BuildRequires: pkgconfig(key-manager) BuildRequires: pkgconfig(auth-fw-admin) +BuildRequires: pkgconfig(cynara-client) +BuildRequires: pkgconfig(cynara-session) +BuildRequires: pkgconfig(libgum) %description The krate package provides a daemon which is responsible for managing each of @@ -32,16 +34,19 @@ krates. %files %manifest krate.manifest %defattr(644,root,root,755) -#%attr(755,root,root) %{_bindir}/krate +%attr(755,root,root) %{_bindir}/krated %attr(700,root,root) %{_sbindir}/krate-volume-manager %{_unitdir}/krate.service -#%{_unitdir}/multi-user.target.wants/krate.service +%{_unitdir}/multi-user.target.wants/krate.service %attr(700,root,root) /etc/gumd/useradd.d/20_krate-add.post %attr(700,root,root) /etc/gumd/userdel.d/20_krate-remove.post %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/indicator_icon.png %attr(644,root,root) %{TZ_SYS_RO_ICONS}/krate/notification_sub_icon.png %attr(700,root,root) %dir %{TZ_SYS_ETC}/krate %attr(600,root,root) %config %{TZ_SYS_ETC}/krate/owner.xml +%attr(700,root,root) %{_libdir}/security/pam_*.so +%attr(700,root,root) %{_sbindir}/krate-admin-cli +%config /etc/pam.d/* %prep %setup -q @@ -65,16 +70,20 @@ krates. -DSYSTEMD_UNIT_DIR=%{_unitdir} \ -DPAMD_DIR=/etc/pam.d \ -DCONF_DIR=%{TZ_SYS_ETC}/krate \ + -DICON_DIR="%{TZ_SYS_RO_ICONS}/krate" \ -DAPP_INSTALL_PREFIX="%{TZ_SYS_RO_APP}" \ - -DAPP_ICON_DIR_PREFIX="%{TZ_SYS_RO_ICONS}" \ -DAPP_SHARE_PACKAGES_DIR="%{TZ_SYS_RO_PACKAGES}" make %{?jobs:-j%jobs} %install %make_install -#mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants -#ln -s ../krate.service %{buildroot}/%{_unitdir}/multi-user.target.wants/krate.service +mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants +ln -s ../krate.service %{buildroot}/%{_unitdir}/multi-user.target.wants/krate.service + +%post +mv /etc/pam.d/systemd-user /etc/pam.d/systemd-user.keep +cp /etc/pam.d/systemd-user-krate /etc/pam.d/systemd-user %clean rm -rf %{buildroot} @@ -82,8 +91,8 @@ rm -rf %{buildroot} %preun %postun +mv /etc/pam.d/systemd-user.keep /etc/pam.d/systemd-user -%if 0 ## Krate Client Package ######################################################## %package -n libkrate Summary: Tizen Krate Client library @@ -91,7 +100,7 @@ Group: Development/Libraries BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(capi-appfw-package-manager) BuildRequires: pkgconfig(libtzplatform-config) -Requires: %{name} = %{version}-%{release} +#Requires: %{name} = %{version}-%{release} Requires(post): /sbin/ldconfig Requires(postun): /sbin/ldconfig @@ -125,48 +134,19 @@ developing the krate client program. %{_includedir}/krate %{_libdir}/pkgconfig/krate.pc -%endif - -## PAM Plugin Package ######################################################## -%package -n dpm-pam-krate -Summary: PAM Plugin for zone policy in device policy manager -Group: Development/Libraries -Requires: systemd -BuildRequires: pam-devel - -%description -n dpm-pam-krate -PAM Plugin for zone policy in device policy manager and CLI tool - -%post -n dpm-pam-krate -mv /etc/pam.d/systemd-user /etc/pam.d/systemd-user.keep -cp /etc/pam.d/systemd-user-zone /etc/pam.d/systemd-user - -%postun -n dpm-pam-krate -mv /etc/pam.d/systemd-user.keep /etc/pam.d/systemd-user - -%files -n dpm-pam-krate -%manifest krate.manifest -%defattr(600,root,root,700) -%attr(700,root,root) %{_libdir}/security/pam_*.so -#%attr(700,root,root) %{_sbindir}/zone-admin-cli -%config /etc/pam.d/* - -## Begin of mobile feature ################################################### -%if "%{profile}" == "mobile" - ## Krate Setup Wizard Package ################################################# %package -n org.tizen.krate-setup-wizard Summary: Tizen Krate setup wizard Interface Group: Security/Other +Requires: libkrate = %{version}-%{release} BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(capi-appfw-application) BuildRequires: pkgconfig(evas) BuildRequires: pkgconfig(notification) -BuildRequires: pkgconfig(zone) %description -n org.tizen.krate-setup-wizard -Tizen Krate setup wizard interface for zone +Tizen Krate setup wizard interface %define setup_home %{TZ_SYS_RO_APP}/org.tizen.krate-setup-wizard @@ -205,6 +185,7 @@ Tizen Krate launcher interface %package -n org.tizen.keyguard Summary: Tizen Krate keyguard Interface Group: Security/Other +Requires: libkrate = %{version}-%{release} BuildRequires: pkgconfig(efl-extension) BuildRequires: pkgconfig(elementary) BuildRequires: pkgconfig(capi-appfw-application) @@ -224,5 +205,3 @@ Tizen Krate keyguard interface %{keyguard_home}/bin/* %{keyguard_home}/res/* %{TZ_SYS_RO_PACKAGES}/org.tizen.keyguard.xml - -%endif diff --git a/rmi/app-proxy.h b/rmi/app-proxy.h new file mode 100644 index 0000000..927a8dc --- /dev/null +++ b/rmi/app-proxy.h @@ -0,0 +1,90 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __APP_PROXY_H__ +#define __APP_PROXY_H__ + +#include "context.h" + +namespace Krate { + +/** + * This class provides APIs to create/remove and manage names. + */ + +class AppProxy { +public: + AppProxy(KrateControlContext& ctxt); + ~AppProxy(); + + //application information + struct AppInfo { + std::string krate; + std::string id; + std::string locale; + std::string package; + std::string type; + std::string icon; + std::string label; + int componentType; + bool isNoDisplayed; + bool isTaskManaged; + + REFLECTABLE + ( + krate, id, locale, package, type, icon, label, + componentType, isNoDisplayed, isTaskManaged + ); + }; + + AppInfo getAppInfo(const std::string& name, const std::string& appid); + + int createIterator(const std::string& name); + AppInfo getIteratorValue(int iterator); + bool nextIterator(int iterator); + int destroyIterator(int iterator); + + //application bundle + struct Bundle { + std::string operation; + std::string uri; + std::string mime; + std::string category; + std::string appId; + struct Extra { + std::string key; + std::vector value; + REFLECTABLE(key, value); + }; + std::vector extraData; + + REFLECTABLE + ( + operation, uri, mime, category, appId, extraData + ); + }; + + int launch(const std::string& name, const Bundle& bundle); + int resume(const std::string& name, const std::string& appid); + int terminate(const std::string& name, const std::string& appid); + bool isRunning(const std::string& name, const std::string& appid); + +private: + KrateControlContext& context; +}; + +} // namespace Krate +#endif // __APP_PROXY_H__ diff --git a/rmi/manager.h b/rmi/manager.h new file mode 100644 index 0000000..53005f7 --- /dev/null +++ b/rmi/manager.h @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __MANAGER_H__ +#define __MANAGER_H__ + +#include "context.h" + +namespace Krate { + +class Manager { +public: + enum State { + Locked = 0x01, + Running = 0x02, + }; + + Manager(KrateControlContext& ctxt); + ~Manager(); + + int createKrate(const std::string& name, const std::string& manifest); + int removeKrate(const std::string& name); + int lockKrate(const std::string& name); + int unlockKrate(const std::string& name); + + int getKrateState(const std::string& name); + + std::vector getKrateList(int state); + + int resetKratePassword(const std::string& name, const std::string& newPassword); + +private: + KrateControlContext& context; +}; + +} // namespace Krate +#endif // __MANAGER_H__ diff --git a/rmi/package-proxy.h b/rmi/package-proxy.h new file mode 100644 index 0000000..300d609 --- /dev/null +++ b/rmi/package-proxy.h @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __PACKAGE_PROXY_H__ +#define __PACKAGE_PROXY_H__ + +#include "context.h" + +namespace Krate { + +/** + * This class provides APIs to control packages in the krates. + */ + +class PackageProxy { +public: + PackageProxy(KrateControlContext& ctxt); + ~PackageProxy(); + + //package information + struct PackageInfo { + std::string krate; + std::string id; + std::string locale; + std::string type; + std::string icon; + std::string label; + std::string description; + struct { + std::string name; + std::string email; + std::string href; + REFLECTABLE(name, email, href); + } author; + std::string version; + std::string apiVersion; + std::string mainAppId; + bool isSystem; + bool isRemovable; + bool isPreload; + + REFLECTABLE + ( + krate, id, locale, type, icon, label, description, author, + version, apiVersion, mainAppId, isSystem, isRemovable, isPreload + ); + }; + + PackageInfo getPackageInfo(const std::string& name, const std::string& pkgid); + std::vector getPackageList(const std::string& name); + + //package manager request + int install(const std::string& name, const std::string& pkgpath); + int uninstall(const std::string& name, const std::string& pkgid); + +private: + KrateControlContext& context; +}; + +} // namespace Krate +#endif // __PACKAGE_PROXY_H__ diff --git a/server/CMakeLists.txt b/server/CMakeLists.txt index 48b71a3..942f7e0 100644 --- a/server/CMakeLists.txt +++ b/server/CMakeLists.txt @@ -13,16 +13,61 @@ # See the License for the specific language governing permissions and # limitations under the License. # +SET(SERVER_SRCS main.cpp + server.cpp + packman.cpp + launchpad.cpp + app-bundle.cpp + manager.cpp + app-proxy.cpp + package-proxy.cpp +) -SET(TARGET ${PROJECT_NAME}) +SET(DEPENDENCY klay + glib-2.0 + gio-2.0 + libxml-2.0 + bundle + aul + appsvc + pkgmgr + pkgmgr-info + libtzplatform-config + capi-system-system-settings + notification + libgum + cynara-client + cynara-session + auth-fw-admin +) + +SET(SERVER_NAME ${PROJECT_NAME}d) + +ADD_EXECUTABLE(${SERVER_NAME} ${SERVER_SRCS}) + +PKG_CHECK_MODULES(SERVER_DEPS REQUIRED ${DEPENDENCY}) + +INCLUDE_DIRECTORIES(SYSTEM ${SERVER_DEPS_INCLUDE_DIRS} ${KRATE_SERVER} ${PROJECT_SOURCE_DIR}) + +TARGET_LINK_LIBRARIES(${SERVER_NAME} ${SERVER_DEPS_LIBRARIES} pthread) + +SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES COMPILE_FLAGS "-fPIE") +SET_TARGET_PROPERTIES(${SERVER_NAME} PROPERTIES LINK_FLAGS "-pie") + +TARGET_COMPILE_DEFINITIONS(${SERVER_NAME} PRIVATE + CONF_PATH="${CONF_DIR}" + RUN_PATH="${RUN_DIR}" + ICON_PATH="${ICON_DIR}" +) CONFIGURE_FILE(systemd/krate.service.in systemd/krate.service) +INSTALL(TARGETS ${SERVER_NAME} DESTINATION ${BIN_DIR}) INSTALL(FILES systemd/krate.service DESTINATION ${SYSTEMD_UNIT_DIR}) INSTALL(FILES ${KRATE_TOOLS}/gumd-scripts/20_krate-add.post DESTINATION /etc/gumd/useradd.d) INSTALL(FILES ${KRATE_TOOLS}/gumd-scripts/20_krate-remove.post DESTINATION /etc/gumd/userdel.d) INSTALL(FILES ${KRATE_DATA}/DefaultManifest.xml DESTINATION ${CONF_DIR} RENAME owner.xml) -INSTALL(FILES ${KRATE_DATA}/indicator_icon.png DESTINATION ${APP_ICON_DIR_PREFIX}/krate) -INSTALL(FILES ${KRATE_DATA}/notification_sub_icon.png DESTINATION ${APP_ICON_DIR_PREFIX}/krate) +INSTALL(FILES ${KRATE_DATA}/indicator_icon.png DESTINATION ${ICON_DIR}) +INSTALL(FILES ${KRATE_DATA}/notification_sub_icon.png DESTINATION ${ICON_DIR}) diff --git a/server/app-bundle.cpp b/server/app-bundle.cpp new file mode 100644 index 0000000..518e36f --- /dev/null +++ b/server/app-bundle.cpp @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include + +#include + +#include "app-bundle.h" + +Bundle::Bundle() : + handle(nullptr) +{ + handle = ::bundle_create(); + if (handle == nullptr) { + throw runtime::Exception("Failed to create bundle"); + } +} + +Bundle::~Bundle() +{ + ::bundle_free(handle); +} + +void Bundle::addInternal(const std::string& key, const std::string& value) +{ + ::bundle_add_str(handle, key.c_str(), value.c_str()); +} + +void Bundle::addArrayInternal(const std::string& key, const std::vector& array) +{ + std::unique_ptr arrayptr(new const char*[array.size()]); + + int index = 0; + for (const std::string& data : array) { + arrayptr.get()[index++] = data.c_str(); + } + + ::bundle_add_str_array(handle, key.c_str(), arrayptr.get(), array.size()); +} diff --git a/server/app-bundle.h b/server/app-bundle.h new file mode 100644 index 0000000..9ce75ee --- /dev/null +++ b/server/app-bundle.h @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __APP_BUNDLE_H__ +#define __APP_BUNDLE_H__ + +#include +#include + +#include + +class Bundle { +public: + Bundle(); + ~Bundle(); + + template + void add(const std::string& key, const std::vector& value) + { + addArrayInternal(key, value); + } + + template + void add(const std::string& key, const T& value) + { + addInternal(key, value); + } + + bundle* get() const + { + return handle; + } + +private: + void addInternal(const std::string& key, const std::string& value); + void addArrayInternal(const std::string& key, const std::vector& array); + +private: + bundle* handle; +}; + +#endif //__APP_BUNDLE_H__ diff --git a/server/app-proxy.cpp b/server/app-proxy.cpp new file mode 100644 index 0000000..38b6e16 --- /dev/null +++ b/server/app-proxy.cpp @@ -0,0 +1,255 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include + +#include + +#include +#include +#include + +#include "packman.h" +#include "launchpad.h" + +#include "rmi/app-proxy.h" + +namespace Krate { + +namespace { + +struct IteratorData { + std::string krate; + std::vector list; + unsigned int current; +}; + +std::unordered_map iteratorMap; +int newIteratorId = 0; + +} // namespace + +AppProxy::AppProxy(KrateControlContext& ctx) : + context(ctx) +{ + context.registerParametricMethod(this, "", (AppProxy::AppInfo)(AppProxy::getAppInfo)(std::string, std::string)); + + context.registerParametricMethod(this, "", (int)(AppProxy::createIterator)(std::string)); + context.registerParametricMethod(this, "", (AppProxy::AppInfo)(AppProxy::getIteratorValue)(int)); + context.registerParametricMethod(this, "", (bool)(AppProxy::nextIterator)(int)); + context.registerParametricMethod(this, "", (int)(AppProxy::destroyIterator)(int)); + + context.registerParametricMethod(this, "", (int)(AppProxy::launch)(std::string, AppProxy::Bundle)); + context.registerParametricMethod(this, "", (int)(AppProxy::resume)(std::string, std::string)); + context.registerParametricMethod(this, "", (int)(AppProxy::terminate)(std::string, std::string)); + context.registerParametricMethod(this, "", (int)(AppProxy::isRunning)(std::string, std::string)); +} + +AppProxy::~AppProxy() +{ +} + +AppProxy::AppInfo AppProxy::getAppInfo(const std::string& name, const std::string& appid) +{ + AppInfo appInfo; + + try { + runtime::User user(name); + ApplicationInfo appinfo(appid, user.getUid()); + char* locale; + + system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); + if (locale == NULL) { + appInfo.locale = "No locale"; + } else { + appInfo.locale = locale; + free(locale); + } + + appInfo.krate = name; + appInfo.id = appid; + appInfo.package = appinfo.getPackage(); + appInfo.type = appinfo.getType(); + appInfo.icon = appinfo.getIcon(); + appInfo.label = appinfo.getLabel(); + appInfo.componentType = appinfo.getComponentType(); + appInfo.isNoDisplayed = appinfo.isNoDisplayed(); + appInfo.isTaskManaged = appinfo.isTaskManaged(); + } catch (runtime::Exception& e) { + ERROR("Failed to retrieve application info installed in the krate: " + appid); + } + + return appInfo; +} + +int AppProxy::createIterator(const std::string& name) +{ + int iteratorId = -1; + try { + PackageManager& packman = PackageManager::instance(); + runtime::User user(name); + IteratorData data; + + iteratorId = newIteratorId; + + data.krate = name; + data.list = packman.getAppList(user.getUid()); + data.current = 0; + + iteratorMap.insert(std::make_pair(iteratorId, data)); + + if (++newIteratorId < 0) { + newIteratorId = 0; + } + } catch (runtime::Exception& e) { + ERROR("Failed to retrieve package info installed in the krate"); + } + return iteratorId; +} + +AppProxy::AppInfo AppProxy::getIteratorValue(int iterator) +{ + AppInfo appInfo; + + auto it = iteratorMap.find(iterator); + if (it == iteratorMap.end()) { + return appInfo; + } + if (it->second.current >= it->second.list.size()) { + return appInfo; + } + + const ApplicationInfo& appinfo = it->second.list.at(it->second.current); + char* locale; + + system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); + if (locale == NULL) { + appInfo.locale = "No locale"; + } else { + appInfo.locale = locale; + free(locale); + } + + appInfo.krate = it->second.krate; + appInfo.id = appinfo.getId(); + appInfo.package = appinfo.getPackage(); + appInfo.type = appinfo.getType(); + appInfo.icon = appinfo.getIcon(); + appInfo.label = appinfo.getLabel(); + appInfo.componentType = appinfo.getComponentType(); + appInfo.isNoDisplayed = appinfo.isNoDisplayed(); + appInfo.isTaskManaged = appinfo.isTaskManaged(); + + return appInfo; +} + +bool AppProxy::nextIterator(int iterator) +{ + auto it = iteratorMap.find(iterator); + if (it != iteratorMap.end()) { + if (++it->second.current < it->second.list.size()) { + return true; + } + } + return false; +} + +int AppProxy::destroyIterator(int iterator) +{ + auto it = iteratorMap.find(iterator); + if (it != iteratorMap.end()) { + iteratorMap.erase(it); + return 0; + } + return -1; +} + +int AppProxy::launch(const std::string& name, const AppProxy::Bundle& bundle) +{ + try { + runtime::User user(name); + ::Bundle b; + + if (!bundle.operation.empty()) { + b.add("__APP_SVC_OP_TYPE__", bundle.operation); + } + if (!bundle.uri.empty()) { + b.add("__APP_SVC_URI__", bundle.uri); + } + if (!bundle.mime.empty()) { + b.add("__APP_SVC_MIME__", bundle.mime); + } + if (!bundle.category.empty()) { + b.add("__APP_SVC_CATEGORY__", bundle.category); + } + + for (Bundle::Extra extra : bundle.extraData) { + if (extra.value.size() > 1) { + b.add(extra.key, extra.value); + } else if (extra.value.size() == 1) { + b.add(extra.key, extra.value.at(0)); + } + } + + Launchpad launchpad(user.getUid()); + launchpad.launch(bundle.appId, b); + } catch (runtime::Exception& e) { + ERROR("Failed to launch app in the krate"); + return -1; + } + return 0; +} + +int AppProxy::resume(const std::string& name, const std::string& appid) +{ + try { + runtime::User user(name); + Launchpad launchpad(user.getUid()); + launchpad.resume(appid); + } catch (runtime::Exception& e) { + ERROR("Failed to terminate app in the krate"); + return -1; + } + return 0; +} + +int AppProxy::terminate(const std::string& name, const std::string& appid) +{ + try { + runtime::User user(name); + Launchpad launchpad(user.getUid()); + launchpad.terminate(appid); + } catch (runtime::Exception& e) { + ERROR("Failed to terminate app in the krate"); + return -1; + } + return 0; +} + +bool AppProxy::isRunning(const std::string& name, const std::string& appid) +{ + try { + runtime::User user(name); + Launchpad launchpad(user.getUid()); + return launchpad.isRunning(appid); + } catch (runtime::Exception& e) { + ERROR("Failed to get app running state in the krate"); + } + return false; +} + +} // namespace Krate diff --git a/server/context.h b/server/context.h new file mode 100644 index 0000000..ab771d9 --- /dev/null +++ b/server/context.h @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KRATE_CONTEXT_H__ +#define __KRATE_CONTEXT_H__ + +#include "server.h" + +using KrateControlContext = Server; + +#endif //__KRATE_CONTEXT_H__ diff --git a/server/launchpad.cpp b/server/launchpad.cpp new file mode 100644 index 0000000..d0a1dbf --- /dev/null +++ b/server/launchpad.cpp @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include +#include +#include + +#include +#include +#include + +#include "launchpad.h" + +Launchpad::Launchpad(const uid_t uid) : + user(uid) +{ + if (user == 0) { + throw runtime::Exception("No logined user for launching app"); + } +} + +bool Launchpad::isRunning(const std::string& appid) +{ + return ::aul_app_is_running_for_uid(appid.c_str(), user); +} + +void Launchpad::launch(const std::string& appid) +{ + launch(appid, Bundle()); +} + +void Launchpad::launch(const std::string& appid, const Bundle& bundle) +{ + if (::aul_launch_app_for_uid(appid.c_str(), bundle.get(), user) < 0) { + throw runtime::Exception("Failed to launch app " + appid); + } +} + +void Launchpad::resume(const std::string& appid) +{ + if (::aul_resume_app_for_uid(appid.c_str(), user) < 0) { + throw runtime::Exception("Failed to resume app " + appid); + } +} + +void Launchpad::terminate(const std::string& appid) +{ + int pid = ::aul_app_get_pid_for_uid(appid.c_str(), user); + if (pid > 0) { + if (::aul_terminate_pid_for_uid(pid, user) < 0) { + WARN("Failed to terminate app PID=" + std::to_string(pid)); + ::kill(pid, SIGKILL); + } + } +} diff --git a/server/launchpad.h b/server/launchpad.h new file mode 100644 index 0000000..c3120ed --- /dev/null +++ b/server/launchpad.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __LAUNCHPAD_H__ +#define __LAUNCHPAD_H__ + +#include + +#include "app-bundle.h" + +class Launchpad { +public: + Launchpad(const uid_t uid = 0); + Launchpad(const Launchpad&) = delete; + Launchpad(Launchpad&&) = delete; + + void launch(const std::string& appid); + void launch(const std::string& appid, const Bundle& bundle); + void resume(const std::string& appid); + bool isRunning(const std::string& appid); + void terminate(const std::string& appid); + +private: + uid_t user; +}; + +#endif //__LAUNCHPAD_H__ diff --git a/server/main.cpp b/server/main.cpp new file mode 100644 index 0000000..448df58 --- /dev/null +++ b/server/main.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include "server.h" + +void signalHandler(int signum) +{ + exit(0); +} + +int main(int argc, char *argv[]) +{ + ::signal(SIGINT, signalHandler); + + ::umask(0); + + try { + Server server; + server.run(); + } catch (std::exception &e) { + std::cerr << e.what() << std::endl; + return 1; + } + + return 0; +} diff --git a/server/manager.cpp b/server/manager.cpp new file mode 100644 index 0000000..5d6bc03 --- /dev/null +++ b/server/manager.cpp @@ -0,0 +1,701 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "packman.h" +#include "launchpad.h" + +#include "rmi/manager.h" + +#define KRATE_DELEGATOR_APP "org.tizen.keyguard" +#define NOTIFICATION_SUB_ICON_PATH ICON_PATH "/notification_sub_icon.png" + +namespace Krate { + +namespace { + +const std::vector defaultGroups = { + "audio", + "video", + "display", + "log" +}; + +const std::vector unitsToMask = { + "starter.service", + "scim.service" +}; + +const std::string KRATE_SKEL_PATH = "/etc/skel"; +const std::string KRATE_CREATE_HOOK_PATH = "/etc/gumd/useradd.d"; +const std::string KRATE_REMOVE_HOOK_PATH = "/etc/gumd/userdel.d"; + +const std::string KRATE_DEFAULT_OWNER = "owner"; + +const std::string KRATE_GROUP = "users"; + +std::list createdKrateList; +static std::atomic isKrateForeground(false); + +std::unordered_map notiHandleMap; + +inline void maskUserServices(const runtime::User& user) +{ + ::tzplatform_set_user(user.getUid()); + std::string pivot(::tzplatform_getenv(TZ_USER_HOME)); + ::tzplatform_reset_user(); + + runtime::File unitbase(pivot + "/.config/systemd/user"); + unitbase.makeDirectory(true); + unitbase.chmod(S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + + for (const std::string& unit : unitsToMask) { + std::string target = unitbase.getPath() + "/" + unit; + if (::symlink("/dev/null", target.c_str()) == -1) { + throw runtime::Exception(runtime::GetSystemErrorMessage()); + } + } +} + +inline void setKrateState(uid_t id, int state) +{ + dbus::Connection& systemDBus = dbus::Connection::getSystem(); + systemDBus.methodcall("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "SetUserLinger", + -1, "", "(ubb)", id, state, 1); +} + +inline const std::string convertPathForOwner(const std::string& path, const runtime::User& user, const runtime::User& owner) +{ + ::tzplatform_set_user(owner.getUid()); + std::string ownerHome(::tzplatform_getenv(TZ_USER_HOME)); + ::tzplatform_reset_user(); + ownerHome += "/.krate"; + + ::tzplatform_set_user(user.getUid()); + std::string userHome(::tzplatform_getenv(TZ_USER_HOME)); + ::tzplatform_reset_user(); + + std::string userHomeForOwner(ownerHome + "/" + user.getName()); + + std::string convertedPath(path); + + if (convertedPath.compare(0, userHome.size(), userHome) == 0) { + convertedPath.replace(0, userHome.size(), userHomeForOwner); + } + + return convertedPath; +} + +inline void prepareFileForOwner(const std::string path, const runtime::User& pkgUser, const runtime::User& owner) +{ + std::string pathLink = convertPathForOwner(path, pkgUser, owner); + + if (path != pathLink) { + runtime::File linkFile(pathLink); + linkFile.makeBaseDirectory(pkgUser.getUid(), pkgUser.getGid()); + if (linkFile.exists()) { + linkFile.remove(); + } + + int ret = ::link(path.c_str(), pathLink.c_str()); + if (ret != 0) { + //TODO: copy the icon instead of linking + throw runtime::Exception("Failed to link from " + path + + " to " + pathLink); + } + } +} + +int packageEventHandler(uid_t target_uid, int req_id, + const char *pkg_type, const char *pkgid, + const char *key, const char *val, + const void *pmsg, void *data) +{ + static std::string type; + std::string keystr = key; + + if (target_uid == tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)) { + return 0; + } + + std::transform(keystr.begin(), keystr.end(), keystr.begin(), ::tolower); + if (keystr == "start") { + type = val; + std::transform(type.begin(), type.end(), type.begin(), ::tolower); + return 0; + } else if (keystr != "end" && keystr != "ok") { + return 0; + } + + try { + runtime::User owner(KRATE_DEFAULT_OWNER), pkgUser(target_uid); + + if (type == "install" || type == "update") { + PackageInfo pkg(pkgid, pkgUser.getUid()); + std::string icon = pkg.getIcon(); + prepareFileForOwner(icon, pkgUser, owner); + + for (const ApplicationInfo& app : pkg.getAppList()) { + std::string icon = app.getIcon(); + prepareFileForOwner(icon, pkgUser, owner); + } + } else { + ::tzplatform_set_user(pkgUser.getUid()); + std::string pkgPath(::tzplatform_getenv(TZ_USER_APP)); + pkgPath = pkgPath + "/" + pkgid; + ::tzplatform_reset_user(); + + runtime::File pkgDirForOwner(convertPathForOwner(pkgPath, pkgUser, owner)); + pkgDirForOwner.remove(true); + } + } catch (runtime::Exception &e) { + ERROR(e.what()); + } + + return 0; +} + +void initializeCreatedKrateList() { + try { + runtime::DirectoryIterator iter(CONF_PATH "/"), end; + + while (iter != end) { + const std::string& file = iter->getName(); + const std::string& name(file.substr(0, file.rfind(".xml"))); + createdKrateList.push_back(name); + ++iter; + } + } catch (runtime::Exception& e) {} +} + +#define NT_TITLE NOTIFICATION_TEXT_TYPE_TITLE +#define NT_CONTENT NOTIFICATION_TEXT_TYPE_CONTENT +#define NT_ICON NOTIFICATION_IMAGE_TYPE_ICON +#define NT_INDICATOR NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR +#define NT_NONE NOTIFICATION_VARIABLE_TYPE_NONE +#define NT_EVENT NOTIFICATION_LY_ONGOING_PROGRESS +#define NT_APP NOTIFICATION_DISPLAY_APP_INDICATOR + +#define NT_ICON_PATH ICON_PATH "/indicator_icon.png" +#define NT_TEXT "Container Mode" +#define NT_APPINFO "Krate Application" + +#define NT_ERROR_NONE NOTIFICATION_ERROR_NONE + +void krateProcessCallback(GDBusConnection *connection, + const gchar *sender, const gchar *objectPath, + const gchar *interface, const gchar *signalName, + GVariant *params, gpointer userData) +{ + static runtime::User owner(KRATE_DEFAULT_OWNER); + int pid, status; + +// notification_h noti = reinterpret_cast(userData); + + g_variant_get(params, "(ii)", &status, &pid); + + if (status != 5) { + return; + } + + struct stat st; + std::string proc("/proc/" + std::to_string(pid)); + if (::stat(proc.c_str(), &st) != 0) { + return; + } + + // this will have been commented until notification_delete_for_uid can work + /* + if (owner.getUid() != st.st_uid) { + if (!isKrateForeground) { + notification_set_text(noti, NT_CONTENT, NT_APPINFO, NULL, NT_NONE); + notification_post_for_uid(noti, owner.getUid()); + isKrateForeground = true; + } + } else { + if (isKrateForeground) { + notification_delete_for_uid(noti, owner.getUid()); + isKrateForeground = false; + } + }*/ +} + +notification_h createNotification() +{ + notification_h noti = notification_create(NOTIFICATION_TYPE_ONGOING); + if (noti == NULL) { + return NULL; + } + + if (notification_set_text(noti, NT_TITLE, NT_TEXT, NULL, NT_NONE) != NT_ERROR_NONE) { + notification_free(noti); + return NULL; + } + if (notification_set_image(noti, NT_ICON, NT_ICON_PATH) != NT_ERROR_NONE) { + notification_free(noti); + return NULL; + } + + if (notification_set_image(noti, NT_INDICATOR, NT_ICON_PATH) != NT_ERROR_NONE) { + notification_free(noti); + return NULL; + } + + if (notification_set_layout(noti, NT_EVENT) != NT_ERROR_NONE) { + notification_free(noti); + return NULL; + } + + if (notification_set_display_applist(noti, NT_APP) != NT_ERROR_NONE) { + notification_free(noti); + return NULL; + } + + return noti; +} + +void krateProcessMonitor() +{ + GError *error = NULL; + GDBusConnection* connection; + connection = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &error); + if (connection == NULL) { + ERROR("GBus Connection failed"); + g_error_free(error); + return; + } + + notification_h noti = createNotification(); + if (noti == NULL) { + ERROR("Failed to created notification"); + return; + } + + g_dbus_connection_signal_subscribe(connection, + NULL, + "org.tizen.resourced.process", + "ProcStatus", + "/Org/Tizen/ResourceD/Process", + NULL, + G_DBUS_SIGNAL_FLAGS_NONE, + krateProcessCallback, + reinterpret_cast(noti), + NULL); +} + +void notiProxyInsert(const runtime::User& owner, const runtime::User& user, int privId, notification_h noti) +{ + std::string krateLauncherUri; + notification_h newNoti; + app_control_h appControl; + char* pkgId; + + notification_clone(noti, &newNoti); + + notification_get_pkgname(noti, &pkgId); + PackageInfo pkg(pkgId, user.getUid()); + notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON, pkg.getIcon().c_str()); + notification_set_image(newNoti, NOTIFICATION_IMAGE_TYPE_ICON_SUB, NOTIFICATION_SUB_ICON_PATH); + + notification_get_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, (void *)&appControl); + if (appControl != NULL) { + char* appId = NULL, *uri = NULL; + + app_control_get_app_id(appControl, &appId); + if (appId == NULL) { + appId = strdup(""); + } + + krateLauncherUri = "krate://enter/" + user.getName() + "/" + appId; + + app_control_get_uri(appControl, &uri); + if (uri != NULL) { + krateLauncherUri += "?uri="; + krateLauncherUri += uri; + free(uri); + } + + free(appId); + app_control_set_app_id(appControl, KRATE_DELEGATOR_APP); + app_control_set_uri(appControl, krateLauncherUri.c_str()); + notification_set_launch_option(newNoti, NOTIFICATION_LAUNCH_OPTION_APP_CONTROL, appControl); + } + + notification_post_for_uid(newNoti, owner.getUid()); + notiHandleMap.insert(std::make_pair(privId, newNoti)); +} + +void notiProxyDelete(const runtime::User& owner, int privId) +{ + std::unordered_map::iterator it; + + it = notiHandleMap.find(privId); + if (it == notiHandleMap.end()) { + return; + } + notification_delete_for_uid(it->second, owner.getUid()); + notification_free(it->second); + notiHandleMap.erase(it); +} + +void notiProxyUpdate(const runtime::User& owner, const runtime::User& user, int privId, notification_h noti) { + std::unordered_map::iterator it; + double progress; + char *str; + + it = notiHandleMap.find(privId); + if (it == notiHandleMap.end()) { + return; + } + + notification_image_type_e imageTypes[] = { + NOTIFICATION_IMAGE_TYPE_ICON, + NOTIFICATION_IMAGE_TYPE_ICON_FOR_INDICATOR, + NOTIFICATION_IMAGE_TYPE_ICON_FOR_LOCK, + NOTIFICATION_IMAGE_TYPE_THUMBNAIL, + NOTIFICATION_IMAGE_TYPE_THUMBNAIL_FOR_LOCK, + NOTIFICATION_IMAGE_TYPE_ICON_SUB, + NOTIFICATION_IMAGE_TYPE_BACKGROUND, + NOTIFICATION_IMAGE_TYPE_LIST_1, + NOTIFICATION_IMAGE_TYPE_LIST_2, + NOTIFICATION_IMAGE_TYPE_LIST_3, + NOTIFICATION_IMAGE_TYPE_LIST_4, + NOTIFICATION_IMAGE_TYPE_LIST_5, + NOTIFICATION_IMAGE_TYPE_BUTTON_1, + NOTIFICATION_IMAGE_TYPE_BUTTON_2, + NOTIFICATION_IMAGE_TYPE_BUTTON_3, + NOTIFICATION_IMAGE_TYPE_BUTTON_4, + NOTIFICATION_IMAGE_TYPE_BUTTON_5, + NOTIFICATION_IMAGE_TYPE_BUTTON_6 + }; + + for (notification_image_type_e type : imageTypes) { + notification_get_image(noti, type, &str); + notification_set_image(it->second, type, str); + } + + notification_text_type_e textTypes[] = { + NOTIFICATION_TEXT_TYPE_TITLE, + NOTIFICATION_TEXT_TYPE_CONTENT, + NOTIFICATION_TEXT_TYPE_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + NOTIFICATION_TEXT_TYPE_EVENT_COUNT, + NOTIFICATION_TEXT_TYPE_INFO_1, + NOTIFICATION_TEXT_TYPE_INFO_SUB_1, + NOTIFICATION_TEXT_TYPE_INFO_2, + NOTIFICATION_TEXT_TYPE_INFO_SUB_2, + NOTIFICATION_TEXT_TYPE_INFO_3, + NOTIFICATION_TEXT_TYPE_INFO_SUB_3, + NOTIFICATION_TEXT_TYPE_GROUP_TITLE, + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT, + NOTIFICATION_TEXT_TYPE_GROUP_CONTENT_FOR_DISPLAY_OPTION_IS_OFF, + NOTIFICATION_TEXT_TYPE_BUTTON_1, + NOTIFICATION_TEXT_TYPE_BUTTON_2, + NOTIFICATION_TEXT_TYPE_BUTTON_3, + NOTIFICATION_TEXT_TYPE_BUTTON_4, + NOTIFICATION_TEXT_TYPE_BUTTON_5, + NOTIFICATION_TEXT_TYPE_BUTTON_6, + }; + + for (notification_text_type_e type : textTypes) { + notification_get_text(noti, type, &str); + notification_set_text(it->second, type, str, NULL, NOTIFICATION_VARIABLE_TYPE_NONE); + } + + notification_get_size(noti, &progress); + notification_set_size(it->second, progress); + + notification_get_progress(noti, &progress); + notification_set_progress(it->second, progress); + + notification_update_for_uid(it->second, owner.getUid()); +} + +void notiProxyCallback(void *data, notification_type_e type, notification_op *op_list, int num_op) +{ + static runtime::User owner(KRATE_DEFAULT_OWNER); + runtime::User user(*reinterpret_cast(data)); + + if (user.getName() == owner.getName()) { + // TODO : should remove noti in the krate when related-krate is removed + // This will be imlemented when notification bug is fixed + return; + } + + for (int i = 0; i < num_op; i++) { + notification_h noti = NULL; + int opType, privId; + + notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_TYPE, &opType); + notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_PRIV_ID, &privId); + + switch (opType) { + case NOTIFICATION_OP_INSERT: + notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_NOTI, ¬i); + notiProxyInsert(owner, user, privId, noti); + break; + case NOTIFICATION_OP_DELETE: + notiProxyDelete(owner, privId); + break; + case NOTIFICATION_OP_UPDATE: + notification_op_get_data(op_list + i, NOTIFICATION_OP_DATA_NOTI, ¬i); + notiProxyUpdate(owner, user, privId, noti); + break; + } + } +} + +} // namespace + +Manager::Manager(KrateControlContext& ctx) : + context(ctx) +{ + context.registerParametricMethod(this, "", (int)(Manager::createKrate)(std::string, std::string)); + context.registerParametricMethod(this, "", (int)(Manager::removeKrate)(std::string)); + context.registerParametricMethod(this, "", (int)(Manager::lockKrate)(std::string)); + context.registerParametricMethod(this, "", (int)(Manager::unlockKrate)(std::string)); + context.registerParametricMethod(this, "", (int)(Manager::getKrateState)(std::string)); + context.registerParametricMethod(this, "", (std::vector)(Manager::getKrateList)(int)); + context.registerParametricMethod(this, "", (int)(Manager::resetKratePassword)(std::string, std::string)); + + context.createNotification("Manager::created"); + context.createNotification("Manager::removed"); + + PackageManager& packageManager = PackageManager::instance(); + packageManager.setEventCallback(packageEventHandler, this); + + krateProcessMonitor(); + + initializeCreatedKrateList(); + for (std::string& name : createdKrateList) { + runtime::User krate(name); + notification_register_detailed_changed_cb_for_uid(notiProxyCallback, &name, krate.getUid()); + } +} + +Manager::~Manager() +{ +} + +int Manager::createKrate(const std::string& name, const std::string& manifest) +{ + auto provisioningWorker = [name, manifest, this]() { + std::unique_ptr manifestFile; + + try { + //create krate user by gumd + GumUser* guser = NULL; + while (guser == NULL) { + guser = gum_user_create_sync(FALSE); + } + g_object_set(G_OBJECT(guser), "username", name.c_str(), + "usertype", GUM_USERTYPE_SECURITY, NULL); + gboolean ret = gum_user_add_sync(guser); + g_object_unref(guser); + + if (!ret) { + throw runtime::Exception("Failed to remove user (" + name + ") by gumd"); + } + + runtime::User user(name); + + maskUserServices(user); + + manifestFile.reset(xml::Parser::parseString(manifest)); + manifestFile->write(CONF_PATH "/" + name + ".xml", "UTF-8", true); + + //TODO: write container owner info + + //unlock the user + setKrateState(user.getUid(), 1); + + //wait for launchpad in the krate + sleep(1); + + auto it = createdKrateList.insert(createdKrateList.end(), name); + notification_register_detailed_changed_cb_for_uid(notiProxyCallback, &(*it), user.getUid()); + context.notify("Manager::created", name, ""); + } catch (runtime::Exception& e) { + ERROR(e.what()); + context.notify("Manager::created", name, "Error"); + } + }; + + std::thread asyncWork(provisioningWorker); + asyncWork.detach(); + + return 0; +} + +int Manager::removeKrate(const std::string& name) +{ + if (lockKrate(name) != 0) { + return -1; + } + + auto remove = [name, this] { + //wait for krate session close + sleep(1); + + try { + runtime::User user(name); + + //umount TZ_USER_CONTENT + ::tzplatform_set_user(user.getUid()); + ::umount2(::tzplatform_getenv(TZ_USER_CONTENT), MNT_FORCE); + ::tzplatform_reset_user(); + + //remove krate user + GumUser* guser = NULL; + while (guser == NULL) { + guser = gum_user_get_sync(user.getUid(), FALSE); + } + gboolean ret = gum_user_delete_sync(guser, TRUE); + g_object_unref(guser); + + if (!ret) { + throw runtime::Exception("Failed to remove user " + name + "(" + std::to_string(user.getUid()) + ") by gumd"); + } + + auto it = createdKrateList.begin(); + for (; it != createdKrateList.end(); it++) { + if (*it == name) { + break; + } + } + createdKrateList.erase(it); + + notification_unregister_detailed_changed_cb_for_uid(notiProxyCallback, NULL, user.getUid()); + context.notify("Manager::removed", name, ""); + } catch (runtime::Exception& e) { + ERROR(e.what()); + context.notify("Manager::removed", name, "Error"); + return; + } + }; + + std::thread asyncWork(remove); + asyncWork.detach(); + + return 0; +} + +int Manager::lockKrate(const std::string& name) +{ + try { + runtime::User user(name); + setKrateState(user.getUid(), 0); + } catch (runtime::Exception& e) { + ERROR(e.what()); + return -1; + } + + return 0; +} + +int Manager::unlockKrate(const std::string& name) +{ + try { + runtime::User user(name); + setKrateState(user.getUid(), 1); + } catch (runtime::Exception& e) { + ERROR(e.what()); + return -1; + } + + return 0; +} + +int Manager::getKrateState(const std::string& name) +{ + auto it = std::find(createdKrateList.begin(), createdKrateList.end(), name); + if (it == createdKrateList.end()) { + return 0; + } + + try { + runtime::User user(name); + try { + dbus::Connection& systemDBus = dbus::Connection::getSystem(); + const dbus::Variant& var = systemDBus.methodcall + ("org.freedesktop.login1", + "/org/freedesktop/login1", + "org.freedesktop.login1.Manager", + "GetUser", + -1, "(o)", "(u)", user.getUid()); + return Manager::State::Running; + } catch (runtime::Exception& e) { + return Manager::State::Locked; + } + } catch (runtime::Exception& e) { + ERROR(e.what()); + return 0; + } + + return 0; +} + +std::vector Manager::getKrateList(int state) +{ + std::vector list; + + for (const std::string& name : createdKrateList) { + if (getKrateState(name) & state) { + list.push_back(name); + } + } + return list; +} + +int Manager::resetKratePassword(const std::string& name, const std::string& newPassword) +{ + try { + runtime::User user(name); + int ret = auth_passwd_reset_passwd(AUTH_PWD_NORMAL, user.getUid(), newPassword.c_str()); + if (ret != AUTH_PASSWD_API_SUCCESS) { + throw runtime::Exception("Failed to reset password for " + name); + } + } catch (runtime::Exception& e) { + ERROR(e.what()); + return -1; + } + + return 0; +} + +} // namespace Krate diff --git a/server/package-proxy.cpp b/server/package-proxy.cpp new file mode 100644 index 0000000..44513d4 --- /dev/null +++ b/server/package-proxy.cpp @@ -0,0 +1,126 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include +#include + +#include +#include +#include + +#include "packman.h" + +#include "rmi/package-proxy.h" + +namespace Krate { + +PackageProxy::PackageProxy(KrateControlContext& ctx) : + context(ctx) +{ + context.registerParametricMethod(this, "", (PackageProxy::PackageInfo)(PackageProxy::getPackageInfo)(std::string, std::string)); + context.registerParametricMethod(this, "", (std::vector)(PackageProxy::getPackageList)(std::string)); + + context.registerParametricMethod(this, "", (int)(PackageProxy::install)(std::string, std::string)); + context.registerParametricMethod(this, "", (int)(PackageProxy::uninstall)(std::string, std::string)); +} + +PackageProxy::~PackageProxy() +{ +} + +PackageProxy::PackageInfo PackageProxy::getPackageInfo(const std::string& name, const std::string& pkgid) +{ + PackageProxy::PackageInfo package; + char* locale = NULL; + + system_settings_get_value_string(SYSTEM_SETTINGS_KEY_LOCALE_LANGUAGE, &locale); + if (locale == NULL) { + locale = strdup("No locale"); + } + + package.krate = name; + package.id = pkgid; + package.locale = locale; + + free(locale); + + try { + runtime::User user(name); + ::PackageInfo pkginfo(pkgid, user.getUid()); + + package.type = pkginfo.getType(); + package.icon = pkginfo.getIcon(); + package.label = pkginfo.getLabel(); + package.description = pkginfo.getDescription(); + + package.author.name = pkginfo.getAuthorName(); + package.author.email = pkginfo.getAuthorEmail(); + package.author.href = pkginfo.getAuthorHref(); + + package.version = pkginfo.getVersion(); + package.apiVersion = pkginfo.getApiVersion(); + package.mainAppId = pkginfo.getMainAppId(); + + package.isSystem = pkginfo.isSystem(); + package.isRemovable = pkginfo.isRemovable(); + package.isPreload = pkginfo.isPreload(); + } catch (runtime::Exception& e) { + ERROR("Failed to retrieve package info installed in the krate"); + } + + return package; +} + +std::vector PackageProxy::getPackageList(const std::string& name) +{ + try { + runtime::User user(name); + PackageManager& packman = PackageManager::instance(); + return packman.getPackageList(user.getUid()); + } catch (runtime::Exception& e) { + ERROR("Failed to retrieve package info installed in the krate"); + } + return std::vector(); +} + + +int PackageProxy::install(const std::string& name, const std::string& pkgpath) +{ + try { + runtime::User user(name); + PackageManager& packman = PackageManager::instance(); + packman.installPackage(pkgpath, user.getUid()); + } catch (runtime::Exception& e) { + ERROR("Failed to install package in the krate"); + return -1; + } + + return 0; +} + +int PackageProxy::uninstall(const std::string& name, const std::string& pkgid) +{ + try { + runtime::User user(name); + PackageManager& packman = PackageManager::instance(); + packman.uninstallPackage(pkgid, user.getUid()); + } catch (runtime::Exception& e) { + ERROR("Failed to uninstall package of pkgid in the krate"); + return -1; + } + return 0; +} + +} // namespace Krate diff --git a/server/packman.cpp b/server/packman.cpp new file mode 100644 index 0000000..8739dce --- /dev/null +++ b/server/packman.cpp @@ -0,0 +1,427 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include +#include + +#include "packman.h" + +namespace { + +int PackageEventCallback(uid_t uid, int id, const char* type, const char* name, + const char* key, const char* val, const void* msg, void* data) +{ + return 0; +} + +int AppListCallback(pkgmgrinfo_appinfo_h handle, void *data) +{ + std::vector* appList = static_cast*>(data); + appList->push_back(ApplicationInfo(handle)); + + return 0; +} + +int PackageListCallback(pkgmgrinfo_pkginfo_h handle, void *data) +{ + char* pkgid = nullptr; + ::pkgmgrinfo_pkginfo_get_pkgid(handle, &pkgid); + + std::vector* packageList = static_cast*>(data); + packageList->push_back(pkgid); + + return 0; +} + +} // namespace + +PackageInfo::PackageInfo(const std::string& pkgid, uid_t uid) : + user(uid), handle(nullptr) +{ + if (uid == 0) { + uid = getuid(); + } + + if (::pkgmgrinfo_pkginfo_get_usr_pkginfo(pkgid.c_str(), user, &handle) != PMINFO_R_OK) { + throw runtime::Exception("Invalid Package Id"); + } +} + +PackageInfo::~PackageInfo() +{ + ::pkgmgrinfo_pkginfo_destroy_pkginfo(handle); +} + +std::vector PackageInfo::getAppList() const +{ + std::vector appList; + + if (::pkgmgrinfo_appinfo_get_usr_list(handle, PMINFO_ALL_APP, AppListCallback, &appList, user) != PMINFO_R_OK) { + ERROR("Error in pkgmgrinfo_appinfo_get_usr_list"); + } + + return appList; +} + +std::string PackageInfo::getType() const +{ + char *pkgtype; + if (::pkgmgrinfo_pkginfo_get_type(handle, &pkgtype) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return pkgtype; +} + +std::string PackageInfo::getLabel() const +{ + char *label; + if (::pkgmgrinfo_pkginfo_get_label(handle, &label) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return label; +} + +std::string PackageInfo::getIcon() const +{ + char *icon; + if (::pkgmgrinfo_pkginfo_get_icon(handle, &icon) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return icon; +} + +std::string PackageInfo::getDescription() const +{ + char *desc; + if (::pkgmgrinfo_pkginfo_get_description(handle, &desc) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return desc; +} + +std::string PackageInfo::getAuthorName() const +{ + char *name; + if (::pkgmgrinfo_pkginfo_get_author_name(handle, &name) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return name; +} + +std::string PackageInfo::getAuthorEmail() const +{ + char *email; + if (::pkgmgrinfo_pkginfo_get_author_email(handle, &email) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return email; +} + +std::string PackageInfo::getAuthorHref() const +{ + char *href; + if (::pkgmgrinfo_pkginfo_get_author_name(handle, &href) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return href; +} + +std::string PackageInfo::getVersion() const +{ + char *version; + if (::pkgmgrinfo_pkginfo_get_version(handle, &version) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return version; +} + +std::string PackageInfo::getApiVersion() const +{ + char *api; + if (::pkgmgrinfo_pkginfo_get_api_version(handle, &api) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return api; +} + +std::string PackageInfo::getMainAppId() const +{ + char *mainappid; + if (::pkgmgrinfo_pkginfo_get_mainappid(handle, &mainappid) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return mainappid; +} + +bool PackageInfo::isSystem() const +{ + bool ret; + if (::pkgmgrinfo_pkginfo_is_system(handle, &ret) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return ret; +} + +bool PackageInfo::isRemovable() const +{ + bool ret; + if (::pkgmgrinfo_pkginfo_is_removable(handle, &ret) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return ret; +} + +bool PackageInfo::isPreload() const +{ + bool ret; + if (::pkgmgrinfo_pkginfo_is_preload(handle, &ret) != PMINFO_R_OK) { + throw runtime::Exception("Invalid operation"); + } + + return ret; +} + +ApplicationInfo::ApplicationInfo(const std::string& aid, uid_t uid) +{ + pkgmgrinfo_appinfo_h handle; + + if (::pkgmgrinfo_appinfo_get_usr_appinfo(aid.c_str(), uid, &handle) != PMINFO_R_OK) { + throw runtime::Exception("Invalid App Id"); + } + + load(handle); + + ::pkgmgrinfo_appinfo_destroy_appinfo(handle); +} + +ApplicationInfo::ApplicationInfo(pkgmgrinfo_appinfo_h handle) +{ + load(handle); +} + + +ApplicationInfo::~ApplicationInfo() +{ +} + +void ApplicationInfo::load(pkgmgrinfo_appinfo_h handle) { + pkgmgrinfo_app_component comp; + char* str; + int ret; + + ret = ::pkgmgrinfo_appinfo_get_appid(handle, &str); + if (ret == PMINFO_R_OK) { + id = str; + } + + ret = ::pkgmgrinfo_appinfo_get_pkgid(handle, &str); + if (ret == PMINFO_R_OK) { + package = str; + } + + ret = ::pkgmgrinfo_appinfo_get_apptype(handle, &str); + if (ret == PMINFO_R_OK) { + type = str; + } + + ret = ::pkgmgrinfo_appinfo_get_icon(handle, &str); + if (ret == PMINFO_R_OK) { + icon = str; + } + + ret = ::pkgmgrinfo_appinfo_get_label(handle, &str); + if (ret == PMINFO_R_OK) { + label = str; + } + + ret = ::pkgmgrinfo_appinfo_get_component(handle, &comp); + if (ret == PMINFO_R_OK) { + componentType = static_cast(comp); + } + + ::pkgmgrinfo_appinfo_is_nodisplay(handle, &noDisplayed); + ::pkgmgrinfo_appinfo_is_taskmanage(handle, &taskManaged); +} + +const std::string& ApplicationInfo::getId() const +{ + return id; +} + +const std::string& ApplicationInfo::getPackage() const +{ + return package; +} + +const std::string& ApplicationInfo::getType() const +{ + return type; +} + +const std::string& ApplicationInfo::getIcon() const +{ + return icon; +} + +const std::string& ApplicationInfo::getLabel() const +{ + return label; +} + +int ApplicationInfo::getComponentType() const +{ + return componentType; +} + +bool ApplicationInfo::isNoDisplayed() const +{ + return noDisplayed; +} + +bool ApplicationInfo::isTaskManaged() const +{ + return taskManaged; +} + +PackageManager::PackageManager() : + nativeRequestHandle(nullptr), nativeListenHandle(nullptr) +{ + nativeRequestHandle = ::pkgmgr_client_new(PC_REQUEST); + if (nativeRequestHandle == nullptr) { + throw runtime::Exception("No package manager request instance"); + } + + nativeListenHandle = ::pkgmgr_client_new(PC_LISTENING); + if (nativeListenHandle == nullptr) { + ::pkgmgr_client_free(nativeRequestHandle); + throw runtime::Exception("No package manager listening instance"); + } +} + +PackageManager::~PackageManager() +{ + ::pkgmgr_client_free(nativeRequestHandle); + ::pkgmgr_client_free(nativeListenHandle); +} + +PackageManager& PackageManager::instance() +{ + static PackageManager __instance__; + return __instance__; +} + +void PackageManager::setEventCallback(pkgmgrinfo_handler callback, void* user_data) +{ + int ret; + ret = ::pkgmgr_client_listen_status(nativeListenHandle, callback, user_data); + if (ret < 0) { + throw runtime::Exception("Failed to set package event callback"); + } +} + +void PackageManager::unsetEventCallback() +{ + int ret; + ret = ::pkgmgr_client_remove_listen_status(nativeListenHandle); + if (ret < 0) { + throw runtime::Exception("Failed to unset package event callback"); + } +} + +void PackageManager::installPackage(const std::string& pkgpath, const uid_t user) +{ + int ret = ::pkgmgr_client_usr_install(nativeRequestHandle, NULL, NULL, pkgpath.c_str(), NULL, PM_QUIET, PackageEventCallback, nullptr, user); + if (ret < PKGMGR_R_OK) { + throw runtime::Exception("Package installation failed"); + } +} + +void PackageManager::uninstallPackage(const std::string& pkgid, const uid_t user) +{ + std::string pkgtype; + + PackageInfo pkgInfo(pkgid, user); + pkgtype = pkgInfo.getType(); + + int ret = ::pkgmgr_client_usr_uninstall(nativeRequestHandle, pkgtype.c_str(), pkgid.c_str(), PM_QUIET, PackageEventCallback, nullptr, user); + if (ret < PKGMGR_R_OK) { + ERROR("Error in pkgmgr_client_uninstall"); + throw runtime::Exception("Package manager exception"); + } +} + +std::vector PackageManager::getPackageList(const uid_t user) +{ + std::vector packageList; + + if (::pkgmgrinfo_pkginfo_get_usr_list(PackageListCallback, &packageList, user) != PMINFO_R_OK) { + ERROR("Error in pkgmgrinfo_pkginfo_get_list"); + } + + return packageList; +} + +std::vector PackageManager::getAppList(const uid_t user) +{ + std::vector appList; + + if (::pkgmgrinfo_appinfo_get_usr_installed_list(AppListCallback, user, &appList) != PMINFO_R_OK) { + ERROR("Error in pkgmgrinfo_appinfo_get_installed_list"); + } + + return appList; +} + +void PackageManager::setModeRestriction(int mode, uid_t user) +{ + if (::pkgmgr_client_usr_set_restriction_mode(nativeRequestHandle, + mode, + user) != PKGMGR_R_OK) { + throw runtime::Exception("Failed to set package restriction mode"); + } +} + +void PackageManager::unsetModeRestriction(int mode, uid_t user) +{ + if (::pkgmgr_client_usr_unset_restriction_mode(nativeRequestHandle, + mode, + user) != PKGMGR_R_OK) { + throw runtime::Exception("Failed to unset package mode restriction"); + } +} + +int PackageManager::getModeRestriction(uid_t user) +{ + int mode; + if (::pkgmgr_client_usr_get_restriction_mode(nativeRequestHandle, + &mode, + user) != PKGMGR_R_OK) { + throw runtime::Exception("Failed to get package restriction mode"); + } + + return mode; +} diff --git a/server/packman.h b/server/packman.h new file mode 100644 index 0000000..0609538 --- /dev/null +++ b/server/packman.h @@ -0,0 +1,115 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __PACKMAN_H__ +#define __PACKMAN_H__ + +#include +#include + +#include +#include + +#include +#include + +class ApplicationInfo { +public: + ApplicationInfo(const std::string& aid, uid_t uid = 0); + ApplicationInfo(pkgmgrinfo_appinfo_h handle); + ~ApplicationInfo(); + + const std::string& getId() const; + const std::string& getPackage() const; + const std::string& getType() const; + const std::string& getIcon() const; + const std::string& getLabel() const; + int getComponentType() const; + bool isNoDisplayed() const; + bool isTaskManaged() const; + +private: + void load(pkgmgrinfo_appinfo_h handle); + + std::string id; + std::string package; + std::string type; + std::string icon; + std::string label; + int componentType; + bool noDisplayed; + bool taskManaged; +}; + +class PackageInfo { +public: + PackageInfo(const std::string& pkgid, uid_t uid = 0); + ~PackageInfo(); + + std::vector getAppList() const; + + std::string getType() const; + std::string getIcon() const; + std::string getLabel() const; + std::string getDescription() const; + + std::string getAuthorName() const; + std::string getAuthorEmail() const; + std::string getAuthorHref() const; + + std::string getVersion() const; + std::string getApiVersion() const; + std::string getMainAppId() const; + + bool isSystem() const; + bool isRemovable() const; + bool isPreload() const; + +private: + uid_t user; + pkgmgrinfo_pkginfo_h handle; +}; + +class PackageManager { +public: + void installPackage(const std::string& pkgpath, const uid_t user); + void uninstallPackage(const std::string& pkgid, const uid_t user); + + std::vector getPackageList(const uid_t user); + std::vector getAppList(const uid_t user); + + void setEventCallback(pkgmgrinfo_handler callback, void* user_data); + void unsetEventCallback(); + + void setModeRestriction(int mode, uid_t user); + void unsetModeRestriction(int mode, uid_t user); + int getModeRestriction(uid_t user); + + void setPackageRestriction(const std::string& pkgid, int mode, uid_t user); + void unsetPackageRestriction(const std::string& pkgid, int mode, uid_t user); + int getPackageRestriction(const std::string& pkgid, uid_t user); + + static PackageManager& instance(); + +private: + PackageManager(); + ~PackageManager(); + +private: + pkgmgr_client *nativeRequestHandle, *nativeListenHandle; +}; + +#endif // __PACKMAN_H__ diff --git a/server/server.cpp b/server/server.cpp new file mode 100644 index 0000000..4db963d --- /dev/null +++ b/server/server.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ +#include + +#include +#include + +#include "server.h" + +#include "rmi/manager.h" +#include "rmi/app-proxy.h" +#include "rmi/package-proxy.h" + +using namespace std::placeholders; + +namespace { + +const std::string KRATE_MANAGER_ADDRESS = "/tmp/.krate.sock"; + +std::unique_ptr manager; +std::unique_ptr appProxy; +std::unique_ptr packageProxy; + +} // namespace + +Server::Server() +{ + service.reset(new rmi::Service(KRATE_MANAGER_ADDRESS)); + + service->setPrivilegeChecker(std::bind(&Server::checkPeerPrivilege, this, _1, _2)); + + service->registerParametricMethod(this, "", (runtime::FileDescriptor)(Server::registerNotificationSubscriber)(std::string)); + service->registerParametricMethod(this, "", (int)(Server::unregisterNotificationSubscriber)(std::string, int)); + + manager.reset(new Krate::Manager(*this)); + appProxy.reset(new Krate::AppProxy(*this)); + packageProxy.reset(new Krate::PackageProxy(*this)); +} + +Server::~Server() +{ +} + +void Server::run() +{ + // Prepare execution environment + service->start(true); +} + +void Server::terminate() +{ + service->stop(); +} + +runtime::FileDescriptor Server::registerNotificationSubscriber(const std::string& name) +{ + return runtime::FileDescriptor(service->subscribeNotification(name), true); +} + +int Server::unregisterNotificationSubscriber(const std::string& name, int id) +{ + return service->unsubscribeNotification(name, id); +} + +bool Server::checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege) +{ + cynara *p_cynara; + + if (privilege.empty()) { + return true; + } + + if (::cynara_initialize(&p_cynara, NULL) != CYNARA_API_SUCCESS) { + ERROR("Failure in cynara API"); + return false; + } + + if (::cynara_check(p_cynara, cred.security.c_str(), "", + std::to_string(cred.uid).c_str(), + privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) { + ::cynara_finish(p_cynara); + ERROR("Access denied: " + cred.security + " : " + privilege); + return false; + } + + ::cynara_finish(p_cynara); + + return true; +} diff --git a/server/server.h b/server/server.h new file mode 100644 index 0000000..95bc9fc --- /dev/null +++ b/server/server.h @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +#ifndef __KRATE_SERVER_H__ +#define __KRATE_SERVER_H__ + +#include +#include + +#include +#include +#include + +class Server { +public: + Server(); + ~Server(); + + void run(); + void terminate(); + + template + void setMethodHandler(const std::string& privilege, const std::string& method, + const typename rmi::MethodHandler::type& handler) + { + service->setMethodHandler(privilege, method, handler); + } + + template + void notify(const std::string& name, Args&&... args) + { + service->notify(name, std::forward(args)...); + } + + uid_t getPeerUid() const + { + return service->getPeerUid(); + } + + gid_t getPeerGid() const + { + return service->getPeerGid(); + } + + pid_t getPeerPid() const + { + return service->getPeerPid(); + } + + void createNotification(const std::string& name) + { + service->createNotification(name); + } + + runtime::FileDescriptor registerNotificationSubscriber(const std::string& name); + int unregisterNotificationSubscriber(const std::string& name, int id); + + bool checkPeerPrivilege(const rmi::Credentials& cred, const std::string& privilege); + +private: + std::string securityLabel; + std::unique_ptr service; +}; + +#endif //__KRATE_SERVER_H__ diff --git a/server/systemd/krate.service.in b/server/systemd/krate.service.in index 1e9d228..1680489 100644 --- a/server/systemd/krate.service.in +++ b/server/systemd/krate.service.in @@ -1,11 +1,14 @@ [Unit] -Description=Krate +Description=@PROJECT_NAME@ management daemon [Service] Type=simple -ExecStart=${TZ_SYS_BIN}/krate +SmackProcessLabel=System +ExecStart=@BIN_DIR@/@PROJECT_NAME@d Restart=on-failure ExecReload=/bin/kill -HUP $MAINPID +CapabilityBoundingSet=~CAP_MAC_ADMIN +CapabilityBoundingSet=~CAP_MAC_OVERRIDE [Install] WantedBy=multi-user.target diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index 2ce3d84..813d2e7 100755 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -15,7 +15,7 @@ # SET(KRATE_APPS ${KRATE_TOOLS}/apps) -#SET(KRATE_CLI ${KRATE_TOOLS}/cli) +SET(KRATE_CLI ${KRATE_TOOLS}/cli) ADD_SUBDIRECTORY(${KRATE_APPS}) -#ADD_SUBDIRECTORY(${KRATE_CLI}) +ADD_SUBDIRECTORY(${KRATE_CLI}) diff --git a/tools/apps/kaskit/src/main.c b/tools/apps/kaskit/src/main.c index 8b1018c..42ca637 100644 --- a/tools/apps/kaskit/src/main.c +++ b/tools/apps/kaskit/src/main.c @@ -150,7 +150,7 @@ static void __badge_changed_cb(unsigned int action, const char *app_id, unsigned } -static char* __get_current_zone_name() { +static char* __get_current_krate_name() { struct passwd pwd, *result; int bufsize; @@ -192,9 +192,9 @@ void _icon_uninstalled_cb(const char *pkg_id) static void __show_launcher() { - char *zone_name = __get_current_zone_name(); + char *krate_name = __get_current_krate_name(); - _set_kaskit_window_title(zone_name); + _set_kaskit_window_title(krate_name); package_manager_set_event_status(__pkg_mgr, PACKAGE_MANAGER_STATUS_TYPE_INSTALL | @@ -205,7 +205,7 @@ static void __show_launcher() ecore_thread_run(__create_icon_thread, NULL, NULL, NULL); - free(zone_name); + free(krate_name); } static bool __app_create(void *data) diff --git a/tools/apps/kaskit/src/widget.c b/tools/apps/kaskit/src/widget.c index b6bf05a..5df7275 100644 --- a/tools/apps/kaskit/src/widget.c +++ b/tools/apps/kaskit/src/widget.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/keyguard/CMakeLists.txt b/tools/apps/keyguard/CMakeLists.txt index f60c758..b119716 100644 --- a/tools/apps/keyguard/CMakeLists.txt +++ b/tools/apps/keyguard/CMakeLists.txt @@ -7,10 +7,9 @@ FIND_PACKAGE(PkgConfig REQUIRED) PKG_CHECK_MODULES(KEYGUARD REQUIRED auth-fw shortcut - zone ) -INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${KEYGUARD_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${KEYGUARD_INCLUDE_DIRS} ${KRATE_LIB}) LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${KEYGUARD_LIBRARY_DIRS}) SET(PROJECT_SRC src/main.c @@ -23,7 +22,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") ADD_EXECUTABLE(${PROJECT_NAME} ${PROJECT_SRC}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${KEYGUARD_LIBRARIES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${KEYGUARD_LIBRARIES} krate) ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images diff --git a/tools/apps/keyguard/include/keyguard.h b/tools/apps/keyguard/include/keyguard.h index 2ff94be..6ae44a0 100644 --- a/tools/apps/keyguard/include/keyguard.h +++ b/tools/apps/keyguard/include/keyguard.h @@ -1,5 +1,5 @@ /* - * Tizen Zone Keyguard application + * Tizen Krate Keyguard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -16,8 +16,8 @@ * limitations under the License. * */ -#ifndef __ZONE_KEYGUARD_H__ -#define __ZONE_KEYGUARD_H__ +#ifndef __KRATE_KEYGUARD_H__ +#define __KRATE_KEYGUARD_H__ #include #include @@ -31,8 +31,8 @@ #include #include #include -#include -#include +#include +#include #ifdef LOG_TAG #undef LOG_TAG @@ -53,4 +53,4 @@ bool _has_password(void); bool _check_password(const char* password); unsigned int _get_left_attempts(void); -#endif /* __ZONE_KEYGUARD_H__ */ +#endif /* __KRATE_KEYGUARD_H__ */ diff --git a/tools/apps/keyguard/include/widget.h b/tools/apps/keyguard/include/widget.h index 85496d9..4d6237b 100644 --- a/tools/apps/keyguard/include/widget.h +++ b/tools/apps/keyguard/include/widget.h @@ -1,5 +1,5 @@ /* - * Tizen Zone Keyguard application + * Tizen Krate Keyguard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/keyguard/res/edje/keyguard.edc b/tools/apps/keyguard/res/edje/keyguard.edc index dd82199..4fd6bf4 100644 --- a/tools/apps/keyguard/res/edje/keyguard.edc +++ b/tools/apps/keyguard/res/edje/keyguard.edc @@ -1,5 +1,5 @@ /* - * Tizen Zone Keyguard Layout + * Tizen Krate Keyguard Layout * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/keyguard/src/main.c b/tools/apps/keyguard/src/main.c index 48f4a5b..25b272c 100644 --- a/tools/apps/keyguard/src/main.c +++ b/tools/apps/keyguard/src/main.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Keyguard application + * Tizen Krate Keyguard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -60,24 +60,24 @@ unsigned int _get_left_attempts() return max_attempt - attempt; } -static void __launch_zone_app(const char* zone_name, app_control_h app_control) +static void __launch_krate_app(const char* krate_name, app_control_h app_control) { - zone_manager_h zone_mgr; - zone_app_proxy_h zone_app; - - zone_manager_create(&zone_mgr); - zone_app_proxy_create(zone_mgr, zone_name, &zone_app); - zone_app_proxy_send_launch_request(zone_app, app_control); - zone_app_proxy_destroy(zone_app); - zone_manager_destroy(zone_mgr); + krate_manager_h krate_mgr; + krate_app_proxy_h krate_app; + + krate_manager_create(&krate_mgr); + krate_app_proxy_create(krate_mgr, krate_name, &krate_app); + krate_app_proxy_send_launch_request(krate_app, app_control); + krate_app_proxy_destroy(krate_app); + krate_manager_destroy(krate_mgr); } -static void __add_shortcut(const char* zone_name) +static void __add_shortcut(const char* krate_name) { char uri[PATH_MAX]; - snprintf(uri, sizeof(uri), "zone://enter/%s", zone_name); - shortcut_add_to_home(zone_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL); + snprintf(uri, sizeof(uri), "krate://enter/%s", krate_name); + shortcut_add_to_home(krate_name, LAUNCH_BY_URI, uri, "", 0, NULL, NULL); } static bool __app_create(void *data) @@ -112,28 +112,28 @@ static void __app_control(app_control_h app_control, void *data) return; } - if (strncmp(uri, "zone://", sizeof("zone://") - 1) != 0) { + if (strncmp(uri, "krate://", sizeof("krate://") - 1) != 0) { dlog_print(DLOG_ERROR, LOG_TAG, "Mismatched URI"); free(uri); ui_app_exit(); return; } - tmp = uri + sizeof("zone://") - 1; + tmp = uri + sizeof("krate://") - 1; if (strncmp(tmp, "setup/", sizeof("setup/") - 1) == 0) { - char *zone_name; + char *krate_name; - zone_name = tmp + sizeof("setup/") - 1; - __add_shortcut(zone_name); + krate_name = tmp + sizeof("setup/") - 1; + __add_shortcut(krate_name); ui_app_exit(); return; } else if (strncmp(tmp, "enter/", sizeof("enter/") - 1) == 0) { - char* zone_name, *launch_parameter; + char* krate_name, *launch_parameter; char new_uri[PATH_MAX]; - zone_name = tmp + sizeof("enter/") - 1; - launch_parameter = strchr(zone_name, '/'); + krate_name = tmp + sizeof("enter/") - 1; + launch_parameter = strchr(krate_name, '/'); if (launch_parameter != NULL) { *(launch_parameter++) = '\0'; if (launch_parameter[0] == '\0') { @@ -142,16 +142,15 @@ static void __app_control(app_control_h app_control, void *data) } else { launch_parameter = KASKIT_PACKAGE; } - snprintf(new_uri, PATH_MAX, "zone://launch/%s", launch_parameter); + snprintf(new_uri, PATH_MAX, "krate://launch/%s", launch_parameter); app_control_set_uri(app_control, new_uri); app_control_set_app_id(app_control, PACKAGE); - dlog_print(DLOG_ERROR, LOG_TAG, "Wow"); dlog_print(DLOG_ERROR, LOG_TAG, PACKAGE); dlog_print(DLOG_ERROR, LOG_TAG, new_uri); - dlog_print(DLOG_ERROR, LOG_TAG, zone_name); + dlog_print(DLOG_ERROR, LOG_TAG, krate_name); - __launch_zone_app(zone_name, app_control); + __launch_krate_app(krate_name, app_control); ui_app_exit(); return; }else if (strncmp(tmp, "launch/", sizeof("launch/") - 1) == 0) { diff --git a/tools/apps/keyguard/src/ui.c b/tools/apps/keyguard/src/ui.c index 27c812f..45a649c 100644 --- a/tools/apps/keyguard/src/ui.c +++ b/tools/apps/keyguard/src/ui.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Keyguard application + * Tizen Krate Keyguard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/keyguard/src/widget.c b/tools/apps/keyguard/src/widget.c index 8d6c682..c92b902 100644 --- a/tools/apps/keyguard/src/widget.c +++ b/tools/apps/keyguard/src/widget.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Keyguard application + * Tizen Krate Keyguard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/setup-wizard/CMakeLists.txt b/tools/apps/setup-wizard/CMakeLists.txt index eea89ca..e495026 100644 --- a/tools/apps/setup-wizard/CMakeLists.txt +++ b/tools/apps/setup-wizard/CMakeLists.txt @@ -6,10 +6,9 @@ INCLUDE_DIRECTORIES(./include) FIND_PACKAGE(PkgConfig REQUIRED) PKG_CHECK_MODULES(SETUP_WIZARD REQUIRED notification - zone ) -INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${SETUP_WIZARD_INCLUDE_DIRS}) +INCLUDE_DIRECTORIES(${EFL_APP_INCLUDE_DIRS} ${SETUP_WIZARD_INCLUDE_DIRS} ${KRATE_LIB}) LINK_DIRECTORIES(${EFL_APP_LIBRARY_DIRS} ${SETUP_WIZARD_LIBRARY_DIRS}) SET(PACKAGE_SRC src/main.c @@ -24,7 +23,7 @@ SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pie") ADD_EXECUTABLE(${PROJECT_NAME} ${PACKAGE_SRC}) INSTALL(TARGETS ${PROJECT_NAME} DESTINATION ${APP_INSTALL_PREFIX}/${PROJECT_NAME}/bin) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${SETUP_WIZARD_LIBRARIES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${EFL_APP_LIBRARIES} ${SETUP_WIZARD_LIBRARIES} krate) ADD_CUSTOM_TARGET(${PROJECT_NAME}.edj COMMAND edje_cc -no-save -id ${CMAKE_CURRENT_SOURCE_DIR}/res/images diff --git a/tools/apps/setup-wizard/include/krate-setup.h b/tools/apps/setup-wizard/include/krate-setup.h index a003d41..2828c3b 100644 --- a/tools/apps/setup-wizard/include/krate-setup.h +++ b/tools/apps/setup-wizard/include/krate-setup.h @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -16,8 +16,8 @@ * limitations under the License. * */ -#ifndef __ZONE_SETUP_H__ -#define __ZONE_SETUP_H__ +#ifndef __KRATE_SETUP_H__ +#define __KRATE_SETUP_H__ #include #include @@ -29,8 +29,8 @@ #include #include #include -#include -#include +#include +#include #include "setup-text.h" @@ -50,11 +50,11 @@ typedef struct { char *mode; - char *zone_name; - char *zone_password; + char *krate_name; + char *krate_password; - zone_manager_h zone_manager; - int zone_event_cb_id; + krate_manager_h krate_manager; + int krate_event_cb_id; bool request_done; app_control_h app_control; @@ -72,9 +72,9 @@ void _create_security_view(appdata_s *data); void _create_setup_view(appdata_s *data); void _create_two_button_layout(Evas_Object *parent, Evas_Object *left_button, Evas_Object *right_button); -int _send_zone_create_request(appdata_s *ad); -int _send_zone_remove_request(appdata_s *ad); +int _send_krate_create_request(appdata_s *ad); +int _send_krate_remove_request(appdata_s *ad); void _create_notification(app_control_h app_control); -void *zone_request_fail(void *ad); +void *krate_request_fail(void *ad); -#endif /* __ZONE_SETUP_H__ */ +#endif /* __KRATE_SETUP_H__ */ diff --git a/tools/apps/setup-wizard/include/setup-text.h b/tools/apps/setup-wizard/include/setup-text.h index 7d96ad8..ca4a792 100644 --- a/tools/apps/setup-wizard/include/setup-text.h +++ b/tools/apps/setup-wizard/include/setup-text.h @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -38,11 +38,11 @@ #define DELETE_ONGOING_TITLE "Deleting a folder..." #define DELETE_ONGOING_CONTENT "The folder will be removed from
your personal home screen." -#define NOTI_CREATE_ZONE "Separated zone creation" -#define NOTI_BODY_CREATE_ZONE "Tap heare to create Separated Zone." +#define NOTI_CREATE_KRATE "Separated krate creation" +#define NOTI_BODY_CREATE_KRATE "Tap heare to create Separated Krate." -#define NOTI_REMOVE_ZONE "Separated Zone deletion" -#define NOTI_BODY_REMOVE_ZONE "Tap here to delete Separated Zone." +#define NOTI_REMOVE_KRATE "Separated Krate deletion" +#define NOTI_BODY_REMOVE_KRATE "Tap here to delete Separated Krate." #define CANCEL_BUTTON "Cancel" #define NEXT_BUTTON "Next" @@ -52,7 +52,7 @@ #define OK_BUTTON "OK" #define SETUP_POPUP_HEADER "Setup Wizard" -#define BODY_ZONE_CREATE_ERROR "Failed to create the Separated Zone." -#define BODY_ZONE_REMOVE_ERROR "Failed to remove the Separated Zone." +#define BODY_KRATE_CREATE_ERROR "Failed to create the Separated Krate." +#define BODY_KRATE_REMOVE_ERROR "Failed to remove the Separated Krate." #endif /*__SETUP_TEXT_H__*/ diff --git a/tools/apps/setup-wizard/include/widget.h b/tools/apps/setup-wizard/include/widget.h index de65535..febca3c 100644 --- a/tools/apps/setup-wizard/include/widget.h +++ b/tools/apps/setup-wizard/include/widget.h @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/setup-wizard/res/edje/layout.edc b/tools/apps/setup-wizard/res/edje/layout.edc index ca1448d..8b521cf 100644 --- a/tools/apps/setup-wizard/res/edje/layout.edc +++ b/tools/apps/setup-wizard/res/edje/layout.edc @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard Layout + * Tizen Krate Setup-Wizard Layout * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/apps/setup-wizard/res/edje/setup.edc b/tools/apps/setup-wizard/res/edje/setup.edc index 8c6ecbd..6262019 100644 --- a/tools/apps/setup-wizard/res/edje/setup.edc +++ b/tools/apps/setup-wizard/res/edje/setup.edc @@ -19,7 +19,7 @@ group { name: "setup_layout"; color: 0 0 0 255; rel1 { relative: 0.0 0.0; to: "bg"; offset: 22 150;} rel2 { relative: 1.0 0.0; to: "bg"; offset: -22 300;} - text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Zone";} + text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Krate";} } } part { name: "icon_base"; diff --git a/tools/apps/setup-wizard/res/edje/welcome.edc b/tools/apps/setup-wizard/res/edje/welcome.edc index 632f95c..382e402 100644 --- a/tools/apps/setup-wizard/res/edje/welcome.edc +++ b/tools/apps/setup-wizard/res/edje/welcome.edc @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard Layout + * Tizen Krate Setup-Wizard Layout * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -40,7 +40,7 @@ group { name: "welcome_layout"; color3: 85 88 88 255; rel1 { relative: 0.0 0.0; to: "bg"; offset: 22 150;} rel2 { relative: 1.0 0.0; to: "bg"; offset: -22 300;} - text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Zone";} + text { font: "Tizen:style=Regular"; size: "48"; align: 0.5 0.5; text: "Separated Krate";} } } part { name: "icon_base"; diff --git a/tools/apps/setup-wizard/src/main.c b/tools/apps/setup-wizard/src/main.c index 658ed80..20c0bb2 100644 --- a/tools/apps/setup-wizard/src/main.c +++ b/tools/apps/setup-wizard/src/main.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -19,39 +19,39 @@ #include "krate-setup.h" #include "widget.h" -static void __launch_zone_app(zone_manager_h zone_mgr, const char *zone_name, app_control_h app_control) +static void __launch_krate_app(krate_manager_h krate_mgr, const char *krate_name, app_control_h app_control) { - zone_app_proxy_h zone_app; + krate_app_proxy_h krate_app; - zone_app_proxy_create(zone_mgr, zone_name, &zone_app); - zone_app_proxy_send_launch_request(zone_app, app_control); - zone_app_proxy_destroy(zone_app); + krate_app_proxy_create(krate_mgr, krate_name, &krate_app); + krate_app_proxy_send_launch_request(krate_app, app_control); + krate_app_proxy_destroy(krate_app); } -static void __zone_request_done(const char *from, const char *info, void *user_data) +static void __krate_request_done(const char *from, const char *info, void *user_data) { app_control_h app_control; char uri[PATH_MAX]; appdata_s *ad = (appdata_s *) user_data; if (!strcmp(info, "Error")) { - ecore_main_loop_thread_safe_call_sync(zone_request_fail, ad); + ecore_main_loop_thread_safe_call_sync(krate_request_fail, ad); return; } if (!strcmp(ad->mode, "create")) { - zone_manager_reset_zone_password(ad->zone_manager, ad->zone_name, ad->zone_password); + krate_manager_reset_krate_password(ad->krate_manager, ad->krate_name, ad->krate_password); app_control_create(&app_control); app_control_set_app_id(app_control, KEYGUARD_PACKAGE); - snprintf(uri, sizeof(uri), "zone://setup/%s", ad->zone_name); + snprintf(uri, sizeof(uri), "krate://setup/%s", ad->krate_name); app_control_set_uri(app_control, uri); app_control_send_launch_request(app_control, NULL, NULL); app_control_destroy(app_control); app_control_create(&app_control); app_control_set_app_id(app_control, KASKIT_PACKAGE); - __launch_zone_app(ad->zone_manager, ad->zone_name, app_control); + __launch_krate_app(ad->krate_manager, ad->krate_name, app_control); app_control_destroy(app_control); } @@ -62,8 +62,8 @@ static bool __app_create(void *data) { appdata_s *ad = (appdata_s *) data; - if (zone_manager_create(&ad->zone_manager) != ZONE_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "failed to get zone manager handle"); + if (krate_manager_create(&ad->krate_manager) != KRATE_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "failed to get krate manager handle"); ui_app_exit(); return false; } @@ -81,7 +81,7 @@ static void __app_resume(void *data) static void __free_data(appdata_s *ad) { - free(ad->zone_name); + free(ad->krate_name); free(ad->mode); } @@ -89,15 +89,15 @@ static void __app_terminate(void *data) { appdata_s *ad = (appdata_s *) data; - zone_manager_remove_event_cb(ad->zone_manager, ad->zone_event_cb_id); - zone_manager_destroy(ad->zone_manager); + krate_manager_remove_event_cb(ad->krate_manager, ad->krate_event_cb_id); + krate_manager_destroy(ad->krate_manager); __free_data(ad); return ; } -static void __set_zone_callback(appdata_s *ad) +static void __set_krate_callback(appdata_s *ad) { char *cb_event_list[2] = {"created", "removed"}; char *cb_event = NULL; @@ -107,8 +107,8 @@ static void __set_zone_callback(appdata_s *ad) else cb_event = cb_event_list[1]; - if (zone_manager_add_event_cb(ad->zone_manager, cb_event, __zone_request_done, ad, &ad->zone_event_cb_id) != ZONE_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add zone signal callback"); + if (krate_manager_add_event_cb(ad->krate_manager, cb_event, __krate_request_done, ad, &ad->krate_event_cb_id) != KRATE_ERROR_NONE) { + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to add krate signal callback"); ui_app_exit(); } @@ -133,14 +133,14 @@ static void __app_control(app_control_h app_control, void *data) return; } - ret = app_control_get_extra_data(app_control, "zone", &ad->zone_name); + ret = app_control_get_extra_data(app_control, "krate", &ad->krate_name); if (ret != APP_CONTROL_ERROR_NONE) { - dlog_print(DLOG_ERROR, LOG_TAG, "failed to get zone name"); + dlog_print(DLOG_ERROR, LOG_TAG, "failed to get krate name"); ui_app_exit(); return; } - __set_zone_callback(ad); + __set_krate_callback(ad); if (app_control_clone(&ad->app_control, app_control) != APP_CONTROL_ERROR_NONE) { dlog_print(DLOG_ERROR, LOG_TAG, "Failed to clone app control handler"); diff --git a/tools/apps/setup-wizard/src/security.c b/tools/apps/setup-wizard/src/security.c index 80fe455..c80dc54 100644 --- a/tools/apps/setup-wizard/src/security.c +++ b/tools/apps/setup-wizard/src/security.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -189,9 +189,9 @@ static void security_password_setup_cb(void *data, Evas_Object *obj, void *event } delete_object_data(); - ad->zone_password = security_password_setup_data; + ad->krate_password = security_password_setup_data; - if (_send_zone_create_request(ad) != 0) { + if (_send_krate_create_request(ad) != 0) { ui_app_exit(); } diff --git a/tools/apps/setup-wizard/src/ui.c b/tools/apps/setup-wizard/src/ui.c index c8a4937..30be539 100644 --- a/tools/apps/setup-wizard/src/ui.c +++ b/tools/apps/setup-wizard/src/ui.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -50,8 +50,8 @@ static void setup_wizard_next_cb(void *data, Evas_Object *obj, void *event_info) if (!strcmp(ad->mode, "create")) { _create_security_view(ad); } else { - if (_send_zone_remove_request(ad) != 0) { - ecore_main_loop_thread_safe_call_sync(zone_request_fail, ad); + if (_send_krate_remove_request(ad) != 0) { + ecore_main_loop_thread_safe_call_sync(krate_request_fail, ad); return; } _create_setup_view(ad); @@ -96,15 +96,15 @@ static Eina_Bool __progressbar_timer_cb(void *data) return ECORE_CALLBACK_RENEW; } -void *zone_request_fail(void *user_data) +void *krate_request_fail(void *user_data) { Evas_Object *popup = NULL; appdata_s *ad = (appdata_s *)user_data; if (!strcmp(ad->mode, "create")) - popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_ZONE_CREATE_ERROR); + popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_KRATE_CREATE_ERROR); else - popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_ZONE_REMOVE_ERROR); + popup = _create_popup(ud.win, SETUP_POPUP_HEADER, BODY_KRATE_REMOVE_ERROR); Evas_Object *btn = elm_button_add(popup); elm_object_style_set(btn, "popup"); diff --git a/tools/apps/setup-wizard/src/util.c b/tools/apps/setup-wizard/src/util.c index 7ad63ee..8112db2 100644 --- a/tools/apps/setup-wizard/src/util.c +++ b/tools/apps/setup-wizard/src/util.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * @@ -19,9 +19,9 @@ #include #include "krate-setup.h" -#define ZONE_METADATA_PATH "data/KrateManifest.xml" +#define KRATE_METADATA_PATH "data/KrateManifest.xml" -static char *__get_zone_metadata(void) +static char *__get_krate_metadata(void) { FILE *fp = NULL; char *res_path = NULL; @@ -35,7 +35,7 @@ static char *__get_zone_metadata(void) dlog_print(DLOG_ERROR, LOG_TAG, "failed to get resource path"); return NULL; } - snprintf(metadata_path, PATH_MAX, "%s%s", res_path, ZONE_METADATA_PATH); + snprintf(metadata_path, PATH_MAX, "%s%s", res_path, KRATE_METADATA_PATH); free(res_path); fp = fopen(metadata_path, "r"); @@ -81,31 +81,31 @@ static char *__get_zone_metadata(void) return metadata; } -int _send_zone_create_request(appdata_s *ad) +int _send_krate_create_request(appdata_s *ad) { int ret; char *metadata = NULL; - metadata = __get_zone_metadata(); + metadata = __get_krate_metadata(); if (metadata == NULL) { - dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get zone metadata"); + dlog_print(DLOG_ERROR, LOG_TAG, "Failed to get krate metadata"); return -1; } - ret = zone_manager_create_zone(ad->zone_manager, ad->zone_name, metadata); - if (ret != ZONE_ERROR_NONE) { + ret = krate_manager_create_krate(ad->krate_manager, ad->krate_name, metadata); + if (ret != KRATE_ERROR_NONE) { return -1; } return 0; } -int _send_zone_remove_request(appdata_s *ad) +int _send_krate_remove_request(appdata_s *ad) { int ret; - ret = zone_manager_destroy_zone(ad->zone_manager, ad->zone_name); - if (ret != ZONE_ERROR_NONE) { + ret = krate_manager_destroy_krate(ad->krate_manager, ad->krate_name); + if (ret != KRATE_ERROR_NONE) { return -1; } @@ -117,8 +117,8 @@ static int __set_notification(notification_h noti_handle, app_control_h app_cont int ret = 0; char *mode = NULL; char *noti_text[2][2] = { - {NOTI_CREATE_ZONE, NOTI_BODY_CREATE_ZONE}, - {NOTI_REMOVE_ZONE, NOTI_BODY_REMOVE_ZONE} + {NOTI_CREATE_KRATE, NOTI_BODY_CREATE_KRATE}, + {NOTI_REMOVE_KRATE, NOTI_BODY_REMOVE_KRATE} }; char **text = NULL; diff --git a/tools/apps/setup-wizard/src/widget.c b/tools/apps/setup-wizard/src/widget.c index 426a404..6a94dc4 100644 --- a/tools/apps/setup-wizard/src/widget.c +++ b/tools/apps/setup-wizard/src/widget.c @@ -1,5 +1,5 @@ /* - * Tizen Zone Setup-Wizard application + * Tizen Krate Setup-Wizard application * * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved * diff --git a/tools/cli/CMakeLists.txt b/tools/cli/CMakeLists.txt index 67a843a..75023dd 100644 --- a/tools/cli/CMakeLists.txt +++ b/tools/cli/CMakeLists.txt @@ -19,7 +19,7 @@ FILE(GLOB CLI_SRCS krate-admin-cli.cpp ${KRATE_MODULE}/krate-builder.cpp ) -SET(CLI_NAME "zone-admin-cli") +SET(CLI_NAME ${PROJECT_NAME}-admin-cli) ADD_EXECUTABLE(${CLI_NAME} ${CLI_SRCS}) SET_TARGET_PROPERTIES(${CLI_NAME} PROPERTIES PREFIX "" @@ -34,10 +34,9 @@ PKG_CHECK_MODULES(CLI_DEPS REQUIRED libxml-2.0 capi-appfw-package-manager capi-appfw-app-manager - zone ) -INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${KRATE_MODULE}) -TARGET_LINK_LIBRARIES(${CLI_NAME} ${CLI_DEPS_LIBRARIES}) +INCLUDE_DIRECTORIES(SYSTEM ${CLI_DEPS_INCLUDE_DIRS} ${KRATE_MODULE} ${KRATE_LIB}) +TARGET_LINK_LIBRARIES(${CLI_NAME} ${CLI_DEPS_LIBRARIES} krate) INSTALL(TARGETS ${CLI_NAME} DESTINATION sbin) diff --git a/tools/cli/krate-admin-cli.cpp b/tools/cli/krate-admin-cli.cpp index e46e45b..45b7ea2 100644 --- a/tools/cli/krate-admin-cli.cpp +++ b/tools/cli/krate-admin-cli.cpp @@ -44,8 +44,8 @@ #include #include -#include -#include +#include +#include #include "session.h" @@ -237,15 +237,15 @@ int showPkgInfo(const std::string& name) { int num = 0; - zone_manager_h krateMgr; - zone_package_proxy_h pkgProxy; + krate_manager_h krateMgr; + krate_package_proxy_h pkgProxy; - zone_manager_create(&krateMgr); - zone_package_proxy_create(krateMgr, name.c_str(), &pkgProxy); - zone_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num); + krate_manager_create(&krateMgr); + krate_package_proxy_create(krateMgr, name.c_str(), &pkgProxy); + krate_package_proxy_foreach_package_info(pkgProxy, packgeListCallback, &num); std::cout << num << " packages are found" << std::endl; - zone_package_proxy_destroy(pkgProxy); - zone_manager_destroy(krateMgr); + krate_package_proxy_destroy(pkgProxy); + krate_manager_destroy(krateMgr); return 0; } @@ -295,15 +295,15 @@ int showAppInfo(const std::string& name) { int num = 0; - zone_manager_h krateMgr; - zone_app_proxy_h appMgr; + krate_manager_h krateMgr; + krate_app_proxy_h appMgr; - zone_manager_create(&krateMgr); - zone_app_proxy_create(krateMgr, name.c_str(), &appMgr); - zone_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num); + krate_manager_create(&krateMgr); + krate_app_proxy_create(krateMgr, name.c_str(), &appMgr); + krate_app_proxy_foreach_app_info(appMgr, applicationListCallback, &num); std::cout << num << " applications are found" << std::endl; - zone_app_proxy_destroy(appMgr); - zone_manager_destroy(krateMgr); + krate_app_proxy_destroy(appMgr); + krate_manager_destroy(krateMgr); return 0; } @@ -326,12 +326,12 @@ void krateCallback(const char* name, const char* object, void *user_data) int monitorEvent() { int krateCallbackId[2]; - zone_manager_h krateMgr; - zone_manager_create(&krateMgr); + krate_manager_h krateMgr; + krate_manager_create(&krateMgr); - zone_manager_add_event_cb(krateMgr, "created", krateCallback, + krate_manager_add_event_cb(krateMgr, "created", krateCallback, (void*)"created", &krateCallbackId[0]); - zone_manager_add_event_cb(krateMgr, "removed", krateCallback, + krate_manager_add_event_cb(krateMgr, "removed", krateCallback, (void*)"removed", &krateCallbackId[1]); std::cout << "=== Monitoring start ===" << std::endl << std::endl; @@ -342,12 +342,12 @@ int monitorEvent() g_main_loop_run(gmainloop); g_main_loop_unref(gmainloop); - zone_manager_remove_event_cb(krateMgr, krateCallbackId[0]); - zone_manager_remove_event_cb(krateMgr, krateCallbackId[1]); + krate_manager_remove_event_cb(krateMgr, krateCallbackId[0]); + krate_manager_remove_event_cb(krateMgr, krateCallbackId[1]); std::cout << "=== Monitoring end ===" << std::endl; - zone_manager_destroy(krateMgr); + krate_manager_destroy(krateMgr); return 0; } @@ -398,13 +398,13 @@ void packageEventCallback(const char *type, int monitorPkgEvent(const std::string& name) { - zone_manager_h krateMgr; - zone_package_proxy_h pkgProxy; + krate_manager_h krateMgr; + krate_package_proxy_h pkgProxy; - zone_manager_create(&krateMgr); - zone_package_proxy_create(krateMgr, name.c_str(), &pkgProxy); + krate_manager_create(&krateMgr); + krate_package_proxy_create(krateMgr, name.c_str(), &pkgProxy); - zone_package_proxy_set_event_cb(pkgProxy, packageEventCallback, NULL); + krate_package_proxy_set_event_cb(pkgProxy, packageEventCallback, NULL); std::cout << "=== Monitoring start ===" << std::endl << std::endl; @@ -414,12 +414,12 @@ int monitorPkgEvent(const std::string& name) g_main_loop_run(gmainloop); g_main_loop_unref(gmainloop); - zone_package_proxy_unset_event_cb(pkgProxy); + krate_package_proxy_unset_event_cb(pkgProxy); std::cout << "=== Monitoring end ===" << std::endl; - zone_package_proxy_destroy(pkgProxy); - zone_manager_destroy(krateMgr); + krate_package_proxy_destroy(pkgProxy); + krate_manager_destroy(krateMgr); return 0; } diff --git a/tools/gumd-scripts/20_krate-add.post b/tools/gumd-scripts/20_krate-add.post index 1d30527..fcaf715 100644 --- a/tools/gumd-scripts/20_krate-add.post +++ b/tools/gumd-scripts/20_krate-add.post @@ -1,4 +1,4 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin export `tzplatform-get TZ_SYS_ETC` -cp ${TZ_SYS_ETC}/dpm/zone/owner.xml ${TZ_SYS_ETC}/dpm/zone/${1}.xml +cp ${TZ_SYS_ETC}/krate/owner.xml ${TZ_SYS_ETC}/krate/${1}.xml diff --git a/tools/gumd-scripts/20_krate-remove.post b/tools/gumd-scripts/20_krate-remove.post index 48bfabe..73112eb 100644 --- a/tools/gumd-scripts/20_krate-remove.post +++ b/tools/gumd-scripts/20_krate-remove.post @@ -1,4 +1,4 @@ PATH=/bin:/usr/bin:/sbin:/usr/sbin export `tzplatform-get TZ_SYS_ETC` -rm ${TZ_SYS_ETC}/dpm/zone/${1}.xml +rm ${TZ_SYS_ETC}/krate/${1}.xml -- 2.7.4 From 9532c768fd35ee584ee13cb72f263167900219b4 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Tue, 9 Aug 2016 16:23:57 +0900 Subject: [PATCH 06/16] Remove build feature Change-Id: I1278e6ead5463b4af7e4735407c2d19f6aa0248b Signed-off-by: Sungbae Yoo --- CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5fb2706..c7e3422 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,6 +90,4 @@ ADD_SUBDIRECTORY(${KRATE_LIB}) ADD_SUBDIRECTORY(${KRATE_SERVER}) ADD_SUBDIRECTORY(${KRATE_MODULE}) ADD_SUBDIRECTORY(${KRATE_VOLUME}) -IF("${TIZEN_PROFILE_NAME}" STREQUAL "mobile") ADD_SUBDIRECTORY(${KRATE_TOOLS}) -ENDIF() -- 2.7.4 From 963bafdae7597f7ecc9703a38323aa4f2d851c31 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Wed, 10 Aug 2016 21:32:10 +0900 Subject: [PATCH 07/16] Package-proxy : description value can be NULL Signed-off-by: Sungbae Yoo Change-Id: I5ede0b20251d614ebf17f36abb1ad43c99e5f951 --- server/packman.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/packman.cpp b/server/packman.cpp index 8739dce..1a80e12 100644 --- a/server/packman.cpp +++ b/server/packman.cpp @@ -112,6 +112,9 @@ std::string PackageInfo::getDescription() const throw runtime::Exception("Invalid operation"); } + if (desc == NULL) + return ""; + return desc; } -- 2.7.4 From ecdd2a249e448b382892a8830c3d4de65ebc2a5f Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Wed, 17 Aug 2016 14:35:07 +0900 Subject: [PATCH 08/16] Add final classifier to classes not to be inherited Signed-off-by: Sungbae Yoo Change-Id: Ibc5e4131ac2e5307d91e915d9f019e944938a7fe --- lib/client.h | 2 +- module/krate-builder.h | 2 +- module/krate-guard.h | 2 +- rmi/app-proxy.h | 2 +- rmi/manager.h | 2 +- rmi/package-proxy.h | 2 +- server/app-bundle.h | 2 +- server/launchpad.h | 2 +- server/packman.h | 6 +++--- server/server.h | 2 +- volume/kernel-keyring.h | 2 +- volume/key-generator.h | 2 +- volume/key-manager.h | 2 +- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/lib/client.h b/lib/client.h index f8d1678..c64d34f 100644 --- a/lib/client.h +++ b/lib/client.h @@ -26,7 +26,7 @@ typedef std::function KrateChangeListener; typedef std::function SignalListener; -class KrateContext { +class KrateContext final { public: typedef std::unique_ptr KrateControlContext; diff --git a/module/krate-builder.h b/module/krate-builder.h index 094b747..1e03ef8 100644 --- a/module/krate-builder.h +++ b/module/krate-builder.h @@ -24,7 +24,7 @@ #include #include -class KrateBuilder { +class KrateBuilder final { public: KrateBuilder(const runtime::User& user, const std::string& manifestPath); virtual ~KrateBuilder(); diff --git a/module/krate-guard.h b/module/krate-guard.h index 8e09748..a19781a 100644 --- a/module/krate-guard.h +++ b/module/krate-guard.h @@ -27,7 +27,7 @@ #include -class KrateGuard { +class KrateGuard final { public: KrateGuard(const std::string& name) : krateName(name), semaphore(nullptr) diff --git a/rmi/app-proxy.h b/rmi/app-proxy.h index 927a8dc..61c0f64 100644 --- a/rmi/app-proxy.h +++ b/rmi/app-proxy.h @@ -25,7 +25,7 @@ namespace Krate { * This class provides APIs to create/remove and manage names. */ -class AppProxy { +class AppProxy final { public: AppProxy(KrateControlContext& ctxt); ~AppProxy(); diff --git a/rmi/manager.h b/rmi/manager.h index 53005f7..97701ca 100644 --- a/rmi/manager.h +++ b/rmi/manager.h @@ -21,7 +21,7 @@ namespace Krate { -class Manager { +class Manager final { public: enum State { Locked = 0x01, diff --git a/rmi/package-proxy.h b/rmi/package-proxy.h index 300d609..271d838 100644 --- a/rmi/package-proxy.h +++ b/rmi/package-proxy.h @@ -25,7 +25,7 @@ namespace Krate { * This class provides APIs to control packages in the krates. */ -class PackageProxy { +class PackageProxy final { public: PackageProxy(KrateControlContext& ctxt); ~PackageProxy(); diff --git a/server/app-bundle.h b/server/app-bundle.h index 9ce75ee..ca53719 100644 --- a/server/app-bundle.h +++ b/server/app-bundle.h @@ -22,7 +22,7 @@ #include -class Bundle { +class Bundle final { public: Bundle(); ~Bundle(); diff --git a/server/launchpad.h b/server/launchpad.h index c3120ed..07f179e 100644 --- a/server/launchpad.h +++ b/server/launchpad.h @@ -21,7 +21,7 @@ #include "app-bundle.h" -class Launchpad { +class Launchpad final { public: Launchpad(const uid_t uid = 0); Launchpad(const Launchpad&) = delete; diff --git a/server/packman.h b/server/packman.h index 0609538..ab54341 100644 --- a/server/packman.h +++ b/server/packman.h @@ -26,7 +26,7 @@ #include #include -class ApplicationInfo { +class ApplicationInfo final { public: ApplicationInfo(const std::string& aid, uid_t uid = 0); ApplicationInfo(pkgmgrinfo_appinfo_h handle); @@ -54,7 +54,7 @@ private: bool taskManaged; }; -class PackageInfo { +class PackageInfo final { public: PackageInfo(const std::string& pkgid, uid_t uid = 0); ~PackageInfo(); @@ -83,7 +83,7 @@ private: pkgmgrinfo_pkginfo_h handle; }; -class PackageManager { +class PackageManager final { public: void installPackage(const std::string& pkgpath, const uid_t user); void uninstallPackage(const std::string& pkgid, const uid_t user); diff --git a/server/server.h b/server/server.h index 95bc9fc..6d07bbe 100644 --- a/server/server.h +++ b/server/server.h @@ -24,7 +24,7 @@ #include #include -class Server { +class Server final { public: Server(); ~Server(); diff --git a/volume/kernel-keyring.h b/volume/kernel-keyring.h index c23d70f..b32668d 100755 --- a/volume/kernel-keyring.h +++ b/volume/kernel-keyring.h @@ -24,7 +24,7 @@ typedef int32_t KeySerial; -class KernelKeyRing { +class KernelKeyRing final { public: KernelKeyRing() = delete; KernelKeyRing(const KernelKeyRing&) = delete; diff --git a/volume/key-generator.h b/volume/key-generator.h index e0d9796..d6bf6f8 100755 --- a/volume/key-generator.h +++ b/volume/key-generator.h @@ -27,7 +27,7 @@ typedef struct { unsigned char buffer[64]; } SHA1_CTX; -class KeyGenerator { +class KeyGenerator final { public: KeyGenerator() = delete; KeyGenerator(const KeyGenerator&) = delete; diff --git a/volume/key-manager.h b/volume/key-manager.h index 48bcdc8..7ca79eb 100644 --- a/volume/key-manager.h +++ b/volume/key-manager.h @@ -17,7 +17,7 @@ #ifndef __KEY_MANAGER_H__ #define __KEY_MANAGER_H__ -class KeyManager { +class KeyManager final { public: KeyManager() = delete; KeyManager(const KeyManager&) = delete; -- 2.7.4 From e914edce4c6067470fc19d828c10930fbef61c6c Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Wed, 17 Aug 2016 21:21:37 +0900 Subject: [PATCH 09/16] Add error handlings when *alloc returns NULL Signed-off-by: Sungbae Yoo Change-Id: I1a820dc052f447fe5ad41dd81230f6cdd9801e49 --- lib/krate/app-proxy.cpp | 39 +++++++++++++++++++++++----------- lib/krate/package-proxy.cpp | 50 +++++++++++++++++++++++++++++++------------- tools/apps/kaskit/src/main.c | 4 ++++ volume/main.cpp | 16 +++++++++----- 4 files changed, 78 insertions(+), 31 deletions(-) diff --git a/lib/krate/app-proxy.cpp b/lib/krate/app-proxy.cpp index 449520d..137cc50 100644 --- a/lib/krate/app-proxy.cpp +++ b/lib/krate/app-proxy.cpp @@ -43,35 +43,50 @@ static app_info_h make_app_info_handle(const Krate::AppProxy::AppInfo& info) return NULL; } - application_x* app = (application_x*)::malloc(sizeof(application_x)); - pkgmgr_appinfo_x* pkgappinfo = (pkgmgr_appinfo_x*)::malloc(sizeof(pkgmgr_appinfo_x)); - app_info_s* appinfo = (app_info_s*)::malloc(sizeof(struct app_info_s)); + application_x* app = (application_x*)::calloc(1, sizeof(application_x)); + if (app == NULL) { + return NULL; + } + + pkgmgr_appinfo_x* pkgappinfo = (pkgmgr_appinfo_x*)::calloc(1, sizeof(pkgmgr_appinfo_x)); + if (pkgappinfo == NULL) { + free(app); + return NULL; + } + + app_info_s* appinfo = (app_info_s*)::calloc(1, sizeof(struct app_info_s)); + if (appinfo == NULL) { + free(app); + free(pkgappinfo); + return NULL; + } - ::memset(appinfo, 0, sizeof(app_info_s)); appinfo->app_id = ::strdup(info.id.c_str()); appinfo->pkg_app_info = pkgappinfo; - ::memset(pkgappinfo, 0, sizeof(pkgmgr_appinfo_x)); pkgappinfo->package = ::strdup(info.package.c_str()); pkgappinfo->locale = ::strdup(info.locale.c_str()); pkgappinfo->app_component = info.componentType; pkgappinfo->app_info = app; - ::memset(app, 0, sizeof(application_x)); app->appid = ::strdup(info.id.c_str()); app->nodisplay = ::strdup(info.isNoDisplayed? "true":"false"); app->taskmanage = ::strdup(info.isTaskManaged? "true":"false"); app->type = ::strdup(info.type.c_str()); icon_x* icon = (icon_x*)::calloc(1, sizeof(icon_x)); - icon->text = ::strdup(info.icon.c_str()); - icon->lang = ::strdup(info.locale.c_str()); - app->icon = ::g_list_append(NULL, icon); + if (icon != NULL) { + icon->text = ::strdup(info.icon.c_str()); + icon->lang = ::strdup(info.locale.c_str()); + app->icon = ::g_list_append(NULL, icon); + } label_x* label = (label_x*)::calloc(1, sizeof(label_x)); - label->text = ::strdup(info.label.c_str()); - label->lang = ::strdup(info.locale.c_str()); - app->label = ::g_list_append(NULL, label); + if (label != NULL) { + label->text = ::strdup(info.label.c_str()); + label->lang = ::strdup(info.locale.c_str()); + app->label = ::g_list_append(NULL, label); + } return reinterpret_cast(appinfo); } diff --git a/lib/krate/package-proxy.cpp b/lib/krate/package-proxy.cpp index 690397e..a78db06 100644 --- a/lib/krate/package-proxy.cpp +++ b/lib/krate/package-proxy.cpp @@ -125,8 +125,22 @@ static package_info_h make_package_info_handle(const PackageProxy::PackageInfo& } package_x* package = (package_x*)::calloc(1, sizeof(package_x)); + if (package == NULL) { + return NULL; + } + pkgmgr_pkginfo_x* pkginfo = (pkgmgr_pkginfo_x*)::calloc(1, sizeof(pkgmgr_pkginfo_x)); + if (pkginfo == NULL) { + free(package); + return NULL; + } + package_info_s* packageinfo = (package_info_s*)::calloc(1, sizeof(package_info_s)); + if (packageinfo == NULL) { + free(package); + free(pkginfo); + return NULL; + } packageinfo->package = ::strdup(info.id.c_str()); packageinfo->pkgmgr_pkginfo = pkginfo; @@ -146,26 +160,34 @@ static package_info_h make_package_info_handle(const PackageProxy::PackageInfo& package->api_version = ::strdup(info.apiVersion.c_str()); icon_x* icon = (icon_x*)::calloc(1, sizeof(icon_x)); - icon->text = ::strdup(info.icon.c_str()); - icon->lang = ::strdup(info.locale.c_str()); - package->icon = ::g_list_append(NULL, icon); + if (icon != NULL) { + icon->text = ::strdup(info.icon.c_str()); + icon->lang = ::strdup(info.locale.c_str()); + package->icon = ::g_list_append(NULL, icon); + } label_x* label = (label_x*)::calloc(1, sizeof(label_x)); - label->text = ::strdup(info.label.c_str()); - label->lang = ::strdup(info.locale.c_str()); - package->label = ::g_list_append(NULL, label); + if (label != NULL) { + label->text = ::strdup(info.label.c_str()); + label->lang = ::strdup(info.locale.c_str()); + package->label = ::g_list_append(NULL, label); + } description_x* desc = (description_x*)::calloc(1, sizeof(description_x)); - desc->text = ::strdup(info.description.c_str()); - desc->lang = ::strdup(info.locale.c_str()); - package->description = ::g_list_append(NULL, desc); + if (desc != NULL) { + desc->text = ::strdup(info.description.c_str()); + desc->lang = ::strdup(info.locale.c_str()); + package->description = ::g_list_append(NULL, desc); + } author_x* author = (author_x*)::calloc(1, sizeof(author_x)); - author->text = ::strdup(info.author.name.c_str()); - author->email = ::strdup(info.author.email.c_str()); - author->href = ::strdup(info.author.href.c_str()); - author->lang = ::strdup(info.locale.c_str()); - package->author = ::g_list_append(NULL, author); + if (author != NULL) { + author->text = ::strdup(info.author.name.c_str()); + author->email = ::strdup(info.author.email.c_str()); + author->href = ::strdup(info.author.href.c_str()); + author->lang = ::strdup(info.locale.c_str()); + package->author = ::g_list_append(NULL, author); + } return reinterpret_cast(packageinfo); } diff --git a/tools/apps/kaskit/src/main.c b/tools/apps/kaskit/src/main.c index 42ca637..172fb7a 100644 --- a/tools/apps/kaskit/src/main.c +++ b/tools/apps/kaskit/src/main.c @@ -161,6 +161,10 @@ static char* __get_current_krate_name() { char* ret, *buf = malloc(bufsize * sizeof(char)); + if (buf == NULL) { + return NULL; + } + getpwuid_r(getuid(), &pwd, buf, bufsize, &result); if (result == NULL) { ret = NULL; diff --git a/volume/main.cpp b/volume/main.cpp index 4de5260..d277009 100755 --- a/volume/main.cpp +++ b/volume/main.cpp @@ -62,7 +62,7 @@ ecryptfs_payload* generateToken(char* key) unsigned char keyBuffer[ECRYPTFS_MAX_KEY_SIZE+1]; - ecryptfs_payload* authToken = (ecryptfs_payload *)::malloc(sizeof(ecryptfs_payload)); + ecryptfs_payload* authToken = new ecryptfs_payload(); if (authToken == NULL) { return NULL; } @@ -112,16 +112,20 @@ int mountEcryptfs(const std::string& src, const std::string& keyName) "user", signature, 0); - if (rc == -1 && errno != ENOKEY) { - ERROR("Failed to find key"); - return -1; - } + if (rc == -1) { + if (errno != ENOKEY) { + ERROR("Failed to find key"); + delete authTok; + return -1; + } + rc = KernelKeyRing::add("user", signature, (void*)authTok, sizeof(ecryptfs_payload), KEY_SPEC_USER_KEYRING); + if (rc == -1) { ERROR("Failed to add key"); return -1; @@ -136,6 +140,8 @@ int mountEcryptfs(const std::string& src, const std::string& keyName) "smackfsroot=*,smackfsdef=*", ECRYPTFS_MAX_KEY_SIZE, signature); + delete authTok; + rc = ::mount(src.c_str(), src.c_str(), "ecryptfs", MS_NODEV, ecryptfsOpts); if (rc != 0) { ERROR(runtime::GetSystemErrorMessage()); -- 2.7.4 From cc65641be1a3e0a8538e6c414518a8ac360f56d9 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Thu, 18 Aug 2016 18:33:00 +0900 Subject: [PATCH 10/16] Fix an use of key-manager deprecated API Signed-off-by: Sungbae Yoo Change-Id: I0904f03232117b9fd9bebe3134752328f0e7fc77 --- volume/key-manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/volume/key-manager.cpp b/volume/key-manager.cpp index d143c31..b45c563 100755 --- a/volume/key-manager.cpp +++ b/volume/key-manager.cpp @@ -86,7 +86,7 @@ void KeyManager::removeKey(const std::string& keyName) { const std::string ckmAlias = addAliasPrefix(keyName); - if (::ckmc_remove_data(ckmAlias.c_str()) != 0) { + if (::ckmc_remove_alias(ckmAlias.c_str()) != 0) { throw runtime::Exception("Failed to remove key data"); } } -- 2.7.4 From 02781665b94915d7b752350325f53c0f41426bd2 Mon Sep 17 00:00:00 2001 From: Sungbae Yoo Date: Mon, 22 Aug 2016 13:41:11 +0900 Subject: [PATCH 11/16] Remove installing /etc/pam.d/systemd-user Change-Id: I384028a4dd6d2a979fbfccf38c3dc81007db4dd6 Signed-off-by: Sungbae Yoo --- packaging/krate.spec | 2 -- 1 file changed, 2 deletions(-) diff --git a/packaging/krate.spec b/packaging/krate.spec index e132b27..2ee7289 100644 --- a/packaging/krate.spec +++ b/packaging/krate.spec @@ -82,8 +82,6 @@ mkdir -p %{buildroot}/%{_unitdir}/multi-user.target.wants ln -s ../krate.service %{buildroot}/%{_unitdir}/multi-user.target.wants/krate.service %post -mv /etc/pam.d/systemd-user /etc/pam.d/systemd-user.keep -cp /etc/pam.d/systemd-user-krate /etc/pam.d/systemd-user %clean rm -rf %{buildroot} -- 2.7.4 From eb4e45e5f16ce0cb778a6b6bbfe3343e695a1a33 Mon Sep 17 00:00:00 2001 From: "seolheui,kim" Date: Fri, 26 Aug 2016 09:35:06 +0900 Subject: [PATCH 12/16] Fix warning of krate applications Change-Id: Ie8d51b4efd9752147e493baa0366b5be76dfd540 Signed-off-by: seolheui,kim --- tools/apps/kaskit/res/edje/app_icon.edc | 1 + tools/apps/kaskit/res/images/app_press_117.png | Bin 3104 -> 1998 bytes tools/apps/kaskit/res/images/btn_delete_nor.png | Bin 3701 -> 3289 bytes tools/apps/kaskit/res/images/btn_delete_press.png | Bin 3742 -> 3267 bytes tools/apps/kaskit/res/images/core_check_bg.png | Bin 1128 -> 419 bytes .../kaskit/res/images/core_check_bg_stroke.png | Bin 1141 -> 427 bytes tools/apps/kaskit/res/images/core_check_icon.png | Bin 1325 -> 605 bytes tools/apps/kaskit/res/images/default_app_icon.png | Bin 12850 -> 15273 bytes tools/apps/kaskit/res/images/folder_appicon_bg.png | Bin 6266 -> 6730 bytes .../kaskit/res/images/icon_badge_container.png | Bin 883 -> 957 bytes tools/apps/kaskit/res/images/popup_bg.png | Bin 1261 -> 559 bytes tools/apps/kaskit/res/images/sub_badge.png | Bin 6199 -> 3761 bytes tools/apps/keyguard/res/images/icon.png | Bin 23271 -> 21496 bytes tools/apps/keyguard/res/images/theme_bg.png | Bin 1311561 -> 1313962 bytes tools/apps/setup-wizard/res/images/icon.png | Bin 57662 -> 16736 bytes tools/apps/setup-wizard/res/images/theme_bg.png | Bin 6894 -> 5302 bytes 16 files changed, 1 insertion(+) diff --git a/tools/apps/kaskit/res/edje/app_icon.edc b/tools/apps/kaskit/res/edje/app_icon.edc index 9189df4..3af232f 100644 --- a/tools/apps/kaskit/res/edje/app_icon.edc +++ b/tools/apps/kaskit/res/edje/app_icon.edc @@ -156,6 +156,7 @@ group { name: "icon"; text_class: "ATO002"; min: 1 1; max: 1 1; + ellipsis: -1; } } description { diff --git a/tools/apps/kaskit/res/images/app_press_117.png b/tools/apps/kaskit/res/images/app_press_117.png index 5acae9d0ff39341450f2e0959cc91e8984ce0f35..75266daf31d4d4514dd58f351ea411524fb3ef63 100644 GIT binary patch delta 1960 zcmV;Z2Uqx@7|sun8Gi%-007zzW;Xx;00d`2O+f$vv5yP0Dy!50Qvv`0D$NK0Cg|`0P0`>06Lfe02gqax=}m;0007FOGiWi z|A&vvzW@LL32;bRa{vGUNB{r;NB~C3Yd!z~2BJwsK~#9!?SGx?R^zx5Mz_kc9Va1h zI?(g}uQyHT1`-n6vUGmP&W+qVfGy@@Efxe~ys1*DT)HVfLaP3ViHXr9#AqS}g+fp` zDlA~Bs3<8gl$4aX`r`v`>iUXENlDP?8qj~1<-Y*HE}<+Hrv7X&6y)SoZAMjSGzlp^ zGE!m$miBRb-+#6Km8B$S&Vrl*gSno4uZ60J=rdqIMpU~gsI?n)2j08-%F)=nV$O^i zZ&cU8y$))h8+!EWHc8#qF1tYmwUZl43KlGQ-fA2*w;R?PUrD+TuRQB!Uikr5MdU4Lu7zefdBl+1bInf$WLL>Ij) z=9VAaaYORKm|hNtkdP9SAa$So;iy87J07?r<|AD85HQ3HNCAsI_ivwzD%|qG4>IHv zAy-leF&Qb2;yl>%P*cW?8Ii!{;o&dk5MmM%BFs5C)#<2;K0kP%k2>FZt_xGHlRR z?z(&?6&)DT*@ej8|pODO7 z4>l$u-v_%7HDSz{xb?2PE=NR+-B*I!jVg?}C;94ozd%BQWxmT3qn*D#V$7hWJ?Syj z2-zKrccJ$9$;}r%q+LTX!u;l()x3y5Htmg z!+)qLV{SW;G#rvch^Sa>M&eCW;YVFF>b_(<5^n~dgb{tZ?7UtM=+}jzov4~2y$(m- zO$j}Q=+z7B4xDjMzr~Mh=SrbitkT4F8)gjAop;_w4$Y8k^+JQH=rcqIWK&;g8QOZV;ttgtPL;zEGw{8u)Z|$}-OMJeCi5OE_<2T`4Jmg+HJ_kJ>2<6uD3(eln*J2M*f6#(n1*``nz!3FsyRuu`VaCS&amWx5cmO}Z}FX2ml zGY1Ym`ZjX%#dCW<4HPQ@)(Ll`x^L#dA&t}Qlg0WqE1^eWg{2bAH?gW|P(!w>YEaAT zum5eKDoQzTSx#qFVT6JzX!iwBRDTpgi6Q*9YAA*B*h+=~WGN|y3KKZ2rNmGPP>|z- zbzy}grvSl`GY=efPVUqFoJHWM3y%ubM{Fa~BGr7pFj_Fj1Zh`=VNL-Js$oVMVC_($ zD4F>s3m&y%=E(z8!OS;Lk7}8}U%?QBEID&e)(m18-dGS;f~bH6Z_SFE)qi-+lo>9l z@f*Q0W4ij*%kjqanj1N_Kn}x{w}xrmigTs`bvX*dl=L}2pM4hv%0&<>s+SO(5o?qxF5VFqADHRM8CcAgm+BcQ5qC%5&XsV?`Fg)|Py~g|) zs^9T5?#%Krg~Ia8zx#J5J!G{KizewrA1hd1c-+j7PDgEE)7HZZj(=As+xgKssE!g_ zZ+_WUDFnxqM_vw>c#nl0OHsqNRSKB$i$BL|*~cTSqr}kG<5Vd@Qc^e$_c02sU)Xr&4as70Uw#{%69)26-o-KdWG3n zJ_-mz#gqxZ_hm+Zi+>6gb1GE5SJhWY)g!_$On5qP8}oAmjjKoP^!n~7pDM>2k4%`I zTktzSraBA-1%~KTS6(S1d~xiFXY%tK&}Fx3S&-MK9LR@1*ZKoQ{QmpDd18850r$Us z_fOV0IZa`uZ*fM(>N?-#GykM|7T!B#<5T^0laDcIX# z38Fb*^_7+sef`%~+!almdDbpGBHNo6MCJe>43+H#fbE%NAAkUmsUgQZ0TU2t4TR?8 z!gIkLL{r#ID0vkF4QBd_*dUOJd9Xj3!T@++FTjV!GKI|4H$lKOswsqo#KCd?R)8qr9Dx8E8bT2UNJB%!Ua%e@hq5_7Fa!#PTGi0g(-k3fxgjhbIars)-TFfT3vekM znm>=mW`S1~$zJRLo+(6>=|5Ls`u~(=ale;IR4`aD*&l|0!dI{K1Bk=@e<+jr6V2rj zfPeG-pTbB@2#t${Lxk%fXriaoY-u?A63NrvUzN-FWVn%MKlEO zBGFh>b`W>>H#`o9wr6p9WEKUm$C^S!3Q!u2iiYn)?L&#`i!n07A`sRFC~E}V#?lfa z8hTh!;eT+kY)SwVVDWx%ssD2If5~070@Gg<84GY|fdJKp!)AiNT^UXLbuRE<>V4-@ zf1L~Bmt2@A8Q5xL|EtkIjzsQRUH-JKX!Fzf088X{j>y*6KZgJykaU_o7UL8woX%F@ z_8(mTyHV{ni=$PpWiLK`4NP{`J@w(jd6VDf#=H|%#J7z@r+Y`#%DnD)d|ZHrDSh6G z0ouH%-msIzsh1;oeDOPf}PNbbURyxm`M~A!kg)=-LW!<&hvKv0as| z8j4~v=biELMrCeu0>MQ!hSrrx(##%Zbzky2BTDQWwP(I@A5|2(F<{MT75J;Hs^*3L zAehS3_)?WH@aE>*YFob?K}tlT7%pBWG{B}_jq9H+B;fW!bi?YWeSV)6QKvHT7i-AFbQ$L;|h2wcvbR)?i3&R*j%Ufg#IS)Kf#%< zpElCvd#WvF#`ROzMNml-C>5o!b8iF}w89jTvB`Ji0-wIPPf)bb)ayZvbXi~@mS<51 z#PA=pa>#V6I!zfY9;tljLn%(cwA28DLM^aa@kI-Ktj&EHo3h47)$_ck@t&`*UEsSF z*hSqRLge50ZPH*6L|!KO`u20jLZ*JRhD`PGp{|*y%^7=74_{JMDTmCvF|S(I$uu1uN14%Evrr!QFzcU+C!IE{S{>N1P~ad#dVg3g#JzZ{%I4sx zl!UMtB4~{N=v3DMdKJCorjY)Oy#1})?LheN3XWiU# zxkrbIyA4g^4Qz0g=9mGGc4?V~O|