src/default_plugin_main.c
src/default_plugin_event.c
src/default_plugin_appcmd.c
+ src/default_plugin_shellcmd.c
src/hashtable.c
src/plugin.c
src/plugin_encrypt.c
int confirm_public_key ( parameters* in, int out_fd );
int appcmd_service ( parameters* in, int out_fd );
+int shellcmd_service ( parameters* in, int out_fd );
void create_pwlock_thread();
return PLUGIN_CMD_SUCCESS;
}
+
+int verify_handle_by_plugin ( 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;
+ }
+
+ D ( "shell command : %s\n", in->array_of_parameter[0].v_string.data );
+
+ 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;
+ }
+ if(!strncmp(in->array_of_parameter[0].v_string.data, "sample-echo", 11)) {
+ out->array_of_parameter[0].type = type_int32;
+ out->array_of_parameter[0].v_int32 = PLUGIN_RET_HANDLE;
+ }
+ else {
+ out->array_of_parameter[0].type = type_int32;
+ out->array_of_parameter[0].v_int32 = PLUGIN_RET_NOT_HANDLE;
+ }
+
+ return PLUGIN_CMD_SUCCESS;
+}
ret = get_shell_env ( in, out );
} else if ( cmd == PLUGIN_SYNC_CMD_VERITY_PUSH ) {
ret = verify_push ( in, out );
+ } else if ( cmd == PLUGIN_SYNC_CMD_HANDLE_BY_PLUGIN ) {
+ ret = verify_handle_by_plugin ( in, out );
} else {
ret = PLUGIN_CMD_NOT_SUPPORT;
}
ret = confirm_public_key ( in, out_fd );
} else if ( cmd == PLUGIN_ASYNC_CMD_APPCMD_SERVICE ) {
ret = appcmd_service ( in, out_fd );
+ } else if ( cmd == PLUGIN_ASYNC_CMD_HANDLEBYPLUGIN_SERVICE ) {
+ ret = shellcmd_service ( in, out_fd );
} else {
ret = PLUGIN_CMD_NOT_SUPPORT;
}
--- /dev/null
+/*
+ * Copyright (c) 2011 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.
+ */
+
+//#define TRACE_TAG TRACE_SHELLCMD
+#define LOG_TAG "SDBD_TRACE_SHELLCMD"
+
+#include "log.h"
+#include "parameter.h"
+#include "sdbd_plugin.h"
+
+#define SHELLCMD_RESULT_BUFSIZE (4096)
+
+
+int shellcmd_service( parameters* in, int out_fd ) {
+ char result_buf[SHELLCMD_RESULT_BUFSIZE] = {0,};
+ char* command = NULL;
+
+ 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;
+ }
+
+ command = in->array_of_parameter[0].v_string.data;
+ D("command=%s(FD:%d)\n", command, out_fd);
+
+ if(!strncmp(command, "sample-echo", 11)) {
+ D("command arg: %s\n", command+12);
+ snprintf(result_buf, sizeof(result_buf), "%s\n", command+12);
+ writex(out_fd, result_buf, strlen(result_buf)+1);
+ return PLUGIN_CMD_SUCCESS;
+ }
+
+ return PLUGIN_CMD_FAIL;
+}
return result;
}
+// return 1 if shell command handled by plugin (handle)
+// return 0 if shell command not handled by plugin (not handle)
+int request_handlecmd_to_plugin ( int cmd, const char* in_buf )
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ if ( in_buf != NULL ) {
+ in.number_of_parameter = 1;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+ if (in.array_of_parameter == NULL) {
+ D("failed to allocate memory for the parameter\n");
+ return success;
+ }
+ in.array_of_parameter[0].type = type_string;
+ in.array_of_parameter[0].v_string.length = strlen ( in_buf );
+ in.array_of_parameter[0].v_string.data = strdup ( in_buf );
+ } else {
+ in.number_of_parameter = 0;
+ in.array_of_parameter = NULL;
+ }
+
+ D ("requested command handling : %d, %s\n", cmd, in_buf);
+
+ ret = request_sync_cmd ( cmd, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ success = ( out.array_of_parameter[0].v_int32 == PLUGIN_RET_HANDLE ) ? 1 : 0;
+ release_parameters ( &out );
+
+ D ("request command handling success : %d\n", success);
+ }
+
+ release_parameters ( &in );
+ return success;
+}
+
+int request_shellcmd_to_plugin ( const char* in_buf )
+{
+ parameters* in;
+ int fd;
+
+ in = (parameters*)malloc(sizeof(parameters));
+ if (in == NULL) {
+ E("failed to allocate memory for the parameters\n");
+ return -1;
+ }
+
+ if ( in_buf != NULL ) {
+ in->number_of_parameter = 1;
+ in->array_of_parameter = ( parameter* ) malloc ( sizeof ( parameter ) );
+ if (in->array_of_parameter == NULL) {
+ free(in);
+ E("failed to allocate memory for the parameter\n");
+ return -1;
+ }
+ in->array_of_parameter[0].type = type_string;
+ in->array_of_parameter[0].v_string.length = strlen ( in_buf );
+ in->array_of_parameter[0].v_string.data = strdup ( in_buf );
+ } else {
+ in->number_of_parameter = 0;
+ in->array_of_parameter = NULL;
+ }
+
+ fd = create_async_proc_thread( PLUGIN_ASYNC_CMD_HANDLEBYPLUGIN_SERVICE, in );
+
+ return fd;
+}
+
// return nonnegative integer that is a socket descriptor for communication
// with async proc thread if success to create async proc thread
// return -1 if failed to create async proc thread
#define PLUGIN_SYNC_CMD_GET_SHELL_ENV 1009
#define PLUGIN_SYNC_CMD_VERITY_PUSH 1010
#define PLUGIN_SYNC_CMD_VERIFY_PEERIPV6 1011
+#define PLUGIN_SYNC_CMD_HANDLE_BY_PLUGIN 1012
#define PLUGIN_SYNC_CMD_SEC_INIT 1100
#define PLUGIN_SYNC_CMD_SEC_DEINIT 1101
// asynchronous command
#define PLUGIN_ASYNC_CMD_AUTH_CONFIRM_PUBLIC 2000
#define PLUGIN_ASYNC_CMD_APPCMD_SERVICE 2001
+#define PLUGIN_ASYNC_CMD_HANDLEBYPLUGIN_SERVICE 2002
// event
#define PLUGIN_EVENT_PWLOCK 3000
#define PLUGIN_RET_OFF 11
#define PLUGIN_RET_VALID 12
#define PLUGIN_RET_INVALID 13
+#define PLUGIN_RET_HANDLE 14
+#define PLUGIN_RET_NOT_HANDLE 15
#define PLUGIN_CMD_SUCCESS 101
#define PLUGIN_CMD_FAIL 102
#define PLUGIN_CMD_NOT_SUPPORT 103
ret = create_service_thread(log_service, get_log_file_path(name + 4));
}*/ else if(!HOST && !strncmp(name, "shell:", 6)) {
if(name[6]) {
- ret = create_subproc_thread(name + 6, 0, 0);
+ if (request_handlecmd_to_plugin(PLUGIN_SYNC_CMD_HANDLE_BY_PLUGIN, name+6)) {
+ D("This shell command is handled by plugin. (%s)\n", name+6);
+ ret = request_shellcmd_to_plugin(name+6);
+ }
+ else {
+ ret = create_subproc_thread(name + 6, 0, 0);
+ }
} else {
ret = create_subproc_thread(NULL, 0, 0);
}