From e9cc3fc4054994fc1fe500ab78d453e0372abd4c Mon Sep 17 00:00:00 2001 From: Junkyeong Kim Date: Fri, 4 Nov 2016 15:17:24 +0900 Subject: [PATCH] screenshot: add privilege checking rule Change-Id: If7c08c36877f592b5f938c7e3eca4d8c4c8d09a9 Signed-off-by: Junkyeong Kim --- src/efl_util.c | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 99 insertions(+), 14 deletions(-) diff --git a/src/efl_util.c b/src/efl_util.c index 9d7f1a4..d564633 100644 --- a/src/efl_util.c +++ b/src/efl_util.c @@ -107,8 +107,10 @@ typedef struct _Efl_Util_Data struct { struct screenshooter *screenshooter; + struct tizen_screenshooter *tz_screenshooter; struct wayland_tbm_client *tbm_client; Eina_List *output_list; + uint32_t noti; } shot; struct { @@ -135,7 +137,7 @@ static Efl_Util_Data _eflutil = EINA_FALSE, NULL, NULL, { NULL, NULL, NULL }, /* tizen_policy protocol */ - { NULL, NULL, NULL }, /* screenshooter protocol */ + { NULL, NULL, NULL, NULL, 0 }, /* screenshooter protocol */ { NULL, -1 } /* tizen_input_device_manager protocol */ }, { @@ -151,6 +153,8 @@ static Efl_Util_Callback_Info *_cb_info_find_by_win(Evas_Object *win, int idx); static Eina_Bool _wl_init(void); static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version); static void _cb_wl_reg_global_remove(void *data, struct wl_registry *reg, unsigned int name); +static void _cb_wl_reg_screenshooter_global(void *data, struct wl_registry *reg, unsigned int name, const char *interface, unsigned int version); +static void _cb_wl_reg_screenshooter_global_remove(void *data, struct wl_registry *reg, unsigned int name); static Efl_Util_Callback_Info *_cb_info_find_by_wlsurf(void *wlsurf, int idx); static void _cb_wl_tz_policy_conformant(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t is_conformant); static void _cb_wl_tz_policy_conformant_area(void *data, struct tizen_policy *tizen_policy, struct wl_surface *surface, uint32_t conformant_part, uint32_t state, int32_t x, int32_t y, int32_t w, int32_t h); @@ -175,6 +179,12 @@ static const struct wl_registry_listener _wl_reg_listener = _cb_wl_reg_global_remove }; +static const struct wl_registry_listener _wl_reg_screenshooter_listener = +{ + _cb_wl_reg_screenshooter_global, + _cb_wl_reg_screenshooter_global_remove +}; + struct tizen_policy_listener _wl_tz_policy_listener = { _cb_wl_tz_policy_conformant, @@ -363,6 +373,23 @@ static const struct screenshooter_listener screenshooter_listener = }; static void +_cb_tz_screenshot_format(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t format) +{ +} + +static void +_cb_tz_screenshot_noti(void *data, struct tizen_screenshooter *tz_screenshooter, uint32_t noti) +{ + _eflutil.wl.shot.noti = noti; +} + +static const struct tizen_screenshooter_listener tz_screenshooter_listener = +{ + _cb_tz_screenshot_format, + _cb_tz_screenshot_noti +}; + +static void _cb_wl_reg_global(void *data, struct wl_registry *reg, unsigned int name, @@ -396,11 +423,6 @@ _cb_wl_reg_global(void *data, output->output = wl_registry_bind(reg, name, &wl_output_interface, version); wl_output_add_listener(output->output, &output_listener, output); } - else if (strcmp(interface, "screenshooter") == 0) - { - _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version); - screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL); - } else if (strcmp(interface, "tizen_input_device_manager") == 0) { _eflutil.wl.devmgr.devicemgr = wl_registry_bind(reg, name, &tizen_input_device_manager_interface, version); @@ -432,6 +454,34 @@ _cb_wl_reg_global_remove(void *data, _eflutil.wl.display_policy.proto = NULL; eina_hash_free(_eflutil.wl.display_policy.hash_brightness); } +/* LCOV_EXCL_STOP */ + +static void +_cb_wl_reg_screenshooter_global(void *data, + struct wl_registry *reg, + unsigned int name, + const char *interface, + unsigned int version) +{ + if (strcmp(interface, "screenshooter") == 0) + { + _eflutil.wl.shot.screenshooter = wl_registry_bind(reg, name, &screenshooter_interface, version); + screenshooter_add_listener(_eflutil.wl.shot.screenshooter, &screenshooter_listener, NULL); + } + else if (strcmp(interface, "tizen_screenshooter") == 0) + { + _eflutil.wl.shot.tz_screenshooter = wl_registry_bind(reg, name, &tizen_screenshooter_interface, version); + tizen_screenshooter_add_listener(_eflutil.wl.shot.tz_screenshooter, &tz_screenshooter_listener, NULL); + } +} + +/* LCOV_EXCL_START */ +static void +_cb_wl_reg_screenshooter_global_remove(void *data, + struct wl_registry *reg, + unsigned int name) +{ +} static Efl_Util_Callback_Info * _cb_info_find_by_wlsurf(void *wlsurf, @@ -1403,21 +1453,44 @@ API efl_util_screenshot_h efl_util_screenshot_initialize(int width, int height) { efl_util_screenshot_h screenshot = NULL; + struct wl_display *display_wrapper = NULL; + struct wl_registry *reg = NULL; + int ret = 0; + + EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param); + EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param); if (!_eflutil.wl.shot.screenshooter) { - int ret = 0; _wl_init(); - while (!_eflutil.wl.shot.screenshooter && ret != -1) - ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + display_wrapper = wl_proxy_create_wrapper(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(display_wrapper, fail_init); + + wl_proxy_set_queue((struct wl_proxy *)display_wrapper, _eflutil.wl.queue); + + reg = wl_display_get_registry(display_wrapper); + EINA_SAFETY_ON_NULL_GOTO(reg, fail_init); + + wl_registry_add_listener(reg, &_wl_reg_screenshooter_listener, NULL); + + ret = wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + EINA_SAFETY_ON_TRUE_GOTO(ret == -1, fail_init); EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.screenshooter, fail_init); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tz_screenshooter, fail_init); - _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy); - EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init); + _eflutil.wl.shot.tbm_client = wayland_tbm_client_init(_eflutil.wl.dpy); + EINA_SAFETY_ON_NULL_GOTO(_eflutil.wl.shot.tbm_client, fail_init); } - EINA_SAFETY_ON_FALSE_GOTO(width > 0, fail_param); - EINA_SAFETY_ON_FALSE_GOTO(height > 0, fail_param); + wl_display_dispatch_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + wl_display_roundtrip_queue(_eflutil.wl.dpy, _eflutil.wl.queue); + + if (_eflutil.wl.shot.noti == 0) + { + fprintf(stderr, "[screenshot] fail: privilege error\n"); /* LCOV_EXCL_LINE */ + goto fail_init; + } if (g_screenshot) { @@ -1451,12 +1524,16 @@ fail_param: return NULL; fail_memory: /* LCOV_EXCL_START */ + if (display_wrapper) + wl_proxy_wrapper_destroy(display_wrapper); set_last_result(EFL_UTIL_ERROR_OUT_OF_MEMORY); return NULL; /* LCOV_EXCL_STOP */ fail_init: if (screenshot) efl_util_screenshot_deinitialize(screenshot); + if (display_wrapper) + wl_proxy_wrapper_destroy(display_wrapper); set_last_result(EFL_UTIL_ERROR_SCREENSHOT_INIT_FAIL); return NULL; } @@ -1471,7 +1548,15 @@ efl_util_screenshot_deinitialize(efl_util_screenshot_h screenshot) g_screenshot = NULL; if (_eflutil.wl.shot.screenshooter) - screenshooter_set_user_data(_eflutil.wl.shot.screenshooter, NULL); + { + screenshooter_destroy(_eflutil.wl.shot.screenshooter); + _eflutil.wl.shot.screenshooter = NULL; + } + if (_eflutil.wl.shot.tz_screenshooter) + { + tizen_screenshooter_destroy(_eflutil.wl.shot.tz_screenshooter); + _eflutil.wl.shot.tz_screenshooter = NULL; + } return EFL_UTIL_ERROR_NONE; } -- 2.7.4