From b5abdd3a92965264e92a402a1c4cb767467c3e20 Mon Sep 17 00:00:00 2001 From: "jounsun.beak" Date: Fri, 1 Dec 2017 21:35:29 +0900 Subject: [PATCH] plugin: add verify_path to check valid path for push Change-Id: I0ae896d25fc4fb9c8bbf89fee16f3f04b3f70160 Signed-off-by: jounsun.beak --- src/default_plugin.h | 1 + src/default_plugin_basic.c | 24 ++++++++++++++++++++++++ src/default_plugin_main.c | 2 ++ src/file_sync_service.c | 6 ++++++ src/sdbd_plugin.h | 1 + 5 files changed, 34 insertions(+) diff --git a/src/default_plugin.h b/src/default_plugin.h index 0c8b5b9..9420d7c 100644 --- a/src/default_plugin.h +++ b/src/default_plugin.h @@ -27,6 +27,7 @@ int verify_sdbd_launch ( parameters* in, parameters* out ); int verify_root_cmd ( parameters* in, parameters* out ); int get_lock_state ( parameters* in, parameters* out ); int get_shell_env ( parameters* in, parameters* out ); +int verify_push ( parameters* in, parameters* out ); int auth_support ( parameters* in, parameters* out ); int auth_get_key_file_paths ( parameters* in, parameters* out ); diff --git a/src/default_plugin_basic.c b/src/default_plugin_basic.c index 0354377..18fed8a 100644 --- a/src/default_plugin_basic.c +++ b/src/default_plugin_basic.c @@ -250,3 +250,27 @@ int get_shell_env ( parameters* in, parameters* out ) return PLUGIN_CMD_SUCCESS; } +int verify_push ( parameters* in, parameters* out ) +{ + if ( in == NULL || in->number_of_parameter != 1 || in->array_of_parameter == NULL + || in->array_of_parameter[0].type != type_string ) { + D ( "Invalid argument\n" ); + return PLUGIN_CMD_FAIL; + } + + if ( out == NULL ) { + D ( "Invalid argument\n" ); + return PLUGIN_CMD_FAIL; + } + + out->number_of_parameter = 1; + out->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) ); + if (out->array_of_parameter == NULL) { + D("failed to allocate memory for the parameter\n"); + return PLUGIN_CMD_FAIL; + } + out->array_of_parameter[0].type = type_int32; + out->array_of_parameter[0].v_int32 = PLUGIN_RET_VALID; + + return PLUGIN_CMD_SUCCESS; +} \ No newline at end of file diff --git a/src/default_plugin_main.c b/src/default_plugin_main.c index 37e5f54..9195449 100644 --- a/src/default_plugin_main.c +++ b/src/default_plugin_main.c @@ -58,6 +58,8 @@ int default_plugin_sync_proc ( int cmd, parameters* in, parameters* out ) ret = get_lock_state ( in, out ); } else if ( cmd == PLUGIN_SYNC_CMD_GET_SHELL_ENV ) { ret = get_shell_env ( in, out ); + } else if ( cmd == PLUGIN_SYNC_CMD_VERITY_PUSH ) { + ret = verify_push ( in, out ); } else { ret = PLUGIN_CMD_NOT_SUPPORT; } diff --git a/src/file_sync_service.c b/src/file_sync_service.c index f2da4c1..ec03f03 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -38,6 +38,7 @@ #include "sdktools.h" #include "sdbd_plugin.h" #include "utils.h" +#include "plugin.h" #define SYNC_TIMEOUT 15 @@ -467,6 +468,11 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) return -1; } + if (!request_validity_to_plugin(PLUGIN_SYNC_CMD_VERITY_PUSH, path)) { + fail_message(s, "You cannot push files to this path."); + return -1; + } + tmp = strrchr(path,','); if(tmp) { *tmp = 0; diff --git a/src/sdbd_plugin.h b/src/sdbd_plugin.h index 0a9287a..d8cb702 100644 --- a/src/sdbd_plugin.h +++ b/src/sdbd_plugin.h @@ -34,6 +34,7 @@ #define PLUGIN_SYNC_CMD_AUTH_GET_KEY_FILEPATHS 1007 #define PLUGIN_SYNC_CMD_GET_LOCK_STATE 1008 #define PLUGIN_SYNC_CMD_GET_SHELL_ENV 1009 +#define PLUGIN_SYNC_CMD_VERITY_PUSH 1010 #define PLUGIN_SYNC_CMD_SEC_INIT 1100 #define PLUGIN_SYNC_CMD_SEC_DEINIT 1101 -- 2.7.4