I change the tabs to spaces and remove the redundant spaces.
Change-Id: Iaed7c815f2d9e04582b1a68bc65d678261824378
Signed-off-by: Sooyoung Ha <yoosah.ha@samsung.com>
*/
/*
- * Android config -- "CYGWIN_NT-5.1".
+ * Android config -- "CYGWIN_NT-5.1".
*
* Cygwin has pthreads, but GDB seems to get confused if you use it to
* create threads. By "confused", I mean it freezes up the first time the
}
int parse_sdbd_commandline(SdbdCommandlineArgs *sdbd_args, int argc, char *argv[]) {
- int split_retval;
-
- int opt;
- int long_index = 0;
-
- static struct option long_options[] = {
- { ARG_EMULATOR_VM_NAME, required_argument, NULL, ARG_S_EMULATOR_VM_NAME },
- { ARG_SENSORS, required_argument, NULL, ARG_S_SENSORS },
- { ARG_SDB, required_argument, NULL, ARG_S_SDB },
- { ARG_SDBD_LISTEN_PORT, required_argument, NULL, ARG_S_SDBD_LISTEN_PORT },
- { ARG_HELP, no_argument, NULL, ARG_S_HELP },
- { ARG_USAGE, no_argument, NULL, ARG_S_USAGE },
- { NULL, 0, NULL, 0 }
- };
-
- optind = 1; /* the index of the next element to be processed in argv */
-
- while ((opt = getopt_long(argc, argv, "", long_options, &long_index)) != -1) {
- switch (opt) {
- case ARG_S_EMULATOR_VM_NAME:
- split_retval = split_host_port(optarg,
- &sdbd_args->emulator.host,
- &sdbd_args->emulator.port);
- if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
- return split_retval;
- }
- /* if we are on emulator we listen using local transport
- * so we should set port to default value but this can
- * be overwritten by command line options */
- if (sdbd_args->sdbd_port < 0) {
- sdbd_args->sdbd_port = DEFAULT_SDB_LOCAL_TRANSPORT_PORT;
- }
- print_sdbd_command(stdout, sdbd_args);
- break;
- case ARG_S_SENSORS:
- split_retval = split_host_port(optarg,
- &sdbd_args->sensors.host,
- &sdbd_args->sensors.port);
- if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
- return split_retval;
- }
- print_sdbd_command(stdout, sdbd_args);
- break;
- case ARG_S_SDB:
- split_retval = split_host_port(optarg,
- &sdbd_args->sdb.host,
- &sdbd_args->sdb.port);
- if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
- return split_retval;
- }
- print_sdbd_command(stdout, sdbd_args);
- break;
- case ARG_S_SDBD_LISTEN_PORT:
- if (sscanf(optarg, "%d", &sdbd_args->sdbd_port) < 1) {
- return SDBD_COMMANDLINE_FAILURE;
- }
- print_sdbd_command(stdout, sdbd_args);
- break;
- case ARG_S_HELP:
- return SDBD_COMMANDLINE_HELP;
- case ARG_S_USAGE:
- return SDBD_COMMANDLINE_USAGE;
- case 1:
- return SDBD_COMMANDLINE_FAILURE_UNKNOWN_OPT;
- case '?':
- return SDBD_COMMANDLINE_FAILURE_UNKNOWN_OPT;
- default:
- return SDBD_COMMANDLINE_FAILURE;
- }
- }
-
- print_sdbd_command(stdout, sdbd_args);
-
- return SDBD_COMMANDLINE_SUCCESS;
+ int split_retval;
+
+ int opt;
+ int long_index = 0;
+
+ static struct option long_options[] = {
+ { ARG_EMULATOR_VM_NAME, required_argument, NULL, ARG_S_EMULATOR_VM_NAME },
+ { ARG_SENSORS, required_argument, NULL, ARG_S_SENSORS },
+ { ARG_SDB, required_argument, NULL, ARG_S_SDB },
+ { ARG_SDBD_LISTEN_PORT, required_argument, NULL, ARG_S_SDBD_LISTEN_PORT },
+ { ARG_HELP, no_argument, NULL, ARG_S_HELP },
+ { ARG_USAGE, no_argument, NULL, ARG_S_USAGE },
+ { NULL, 0, NULL, 0 }
+ };
+
+ optind = 1; /* the index of the next element to be processed in argv */
+
+ while ((opt = getopt_long(argc, argv, "", long_options, &long_index)) != -1) {
+ switch (opt) {
+ case ARG_S_EMULATOR_VM_NAME:
+ split_retval = split_host_port(optarg,
+ &sdbd_args->emulator.host,
+ &sdbd_args->emulator.port);
+ if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
+ return split_retval;
+ }
+ /* if we are on emulator we listen using local transport
+ * so we should set port to default value but this can
+ * be overwritten by command line options */
+ if (sdbd_args->sdbd_port < 0) {
+ sdbd_args->sdbd_port = DEFAULT_SDB_LOCAL_TRANSPORT_PORT;
+ }
+ print_sdbd_command(stdout, sdbd_args);
+ break;
+ case ARG_S_SENSORS:
+ split_retval = split_host_port(optarg,
+ &sdbd_args->sensors.host,
+ &sdbd_args->sensors.port);
+ if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
+ return split_retval;
+ }
+ print_sdbd_command(stdout, sdbd_args);
+ break;
+ case ARG_S_SDB:
+ split_retval = split_host_port(optarg,
+ &sdbd_args->sdb.host,
+ &sdbd_args->sdb.port);
+ if (split_retval != SDBD_COMMANDLINE_SUCCESS) {
+ return split_retval;
+ }
+ print_sdbd_command(stdout, sdbd_args);
+ break;
+ case ARG_S_SDBD_LISTEN_PORT:
+ if (sscanf(optarg, "%d", &sdbd_args->sdbd_port) < 1) {
+ return SDBD_COMMANDLINE_FAILURE;
+ }
+ print_sdbd_command(stdout, sdbd_args);
+ break;
+ case ARG_S_HELP:
+ return SDBD_COMMANDLINE_HELP;
+ case ARG_S_USAGE:
+ return SDBD_COMMANDLINE_USAGE;
+ case 1:
+ return SDBD_COMMANDLINE_FAILURE_UNKNOWN_OPT;
+ case '?':
+ return SDBD_COMMANDLINE_FAILURE_UNKNOWN_OPT;
+ default:
+ return SDBD_COMMANDLINE_FAILURE;
+ }
+ }
+
+ print_sdbd_command(stdout, sdbd_args);
+
+ return SDBD_COMMANDLINE_SUCCESS;
}
void apply_sdbd_commandline_defaults(SdbdCommandlineArgs *sdbd_args) {
- sdbd_args->emulator.port = -1;
+ sdbd_args->emulator.port = -1;
- sdbd_args->sensors.host = strdup(QEMU_FORWARD_IP);
- sdbd_args->sensors.port = DEFAULT_SENSORS_LOCAL_TRANSPORT_PORT;
+ sdbd_args->sensors.host = strdup(QEMU_FORWARD_IP);
+ sdbd_args->sensors.port = DEFAULT_SENSORS_LOCAL_TRANSPORT_PORT;
- sdbd_args->sdb.host = strdup(QEMU_FORWARD_IP);
- sdbd_args->sdb.port = DEFAULT_SDB_PORT;
+ sdbd_args->sdb.host = strdup(QEMU_FORWARD_IP);
+ sdbd_args->sdb.port = DEFAULT_SDB_PORT;
- // by default don't listen on local transport
- sdbd_args->sdbd_port = -1;
+ // by default don't listen on local transport
+ sdbd_args->sdbd_port = -1;
}
int split_host_port(const char *optarg, char **host, int *port) {
- const char *colon = strchr(optarg, ':');
- char *old_val = NULL;
-
- if (colon) {
- old_val = *host;
- *host = strndup(optarg, colon - optarg);
- if (sscanf(colon + 1, "%d", port) < 1) {
- return SDBD_COMMANDLINE_FAILURE;
- }
- } else {
- return SDBD_COMMANDLINE_FAILURE;
- }
-
- if (old_val) {
- free(old_val);
- }
- return SDBD_COMMANDLINE_SUCCESS;
+ const char *colon = strchr(optarg, ':');
+ char *old_val = NULL;
+
+ if (colon) {
+ old_val = *host;
+ *host = strndup(optarg, colon - optarg);
+ if (sscanf(colon + 1, "%d", port) < 1) {
+ return SDBD_COMMANDLINE_FAILURE;
+ }
+ } else {
+ return SDBD_COMMANDLINE_FAILURE;
+ }
+
+ if (old_val) {
+ free(old_val);
+ }
+ return SDBD_COMMANDLINE_SUCCESS;
}
free(sdbd_args->sensors.host);
sdbd_args->sensors.host = NULL;
- memset(sdbd_args, 0, sizeof(SdbdCommandlineArgs));
+ memset(sdbd_args, 0, sizeof(SdbdCommandlineArgs));
}
* @brief A simple host:port tuple
*/
typedef struct {
- char *host;
- int port;
+ char *host;
+ int port;
} HostPort;
/*!
* @brief Contains all values, which are read from commandline.
*/
typedef struct {
- HostPort emulator; ///< emulator name and forward port
- HostPort sdb; ///< sdb address
- HostPort sensors; ///< sensors address
- int sdbd_port; ///< Port to listen on in tcp mode
+ HostPort emulator; ///< emulator name and forward port
+ HostPort sdb; ///< sdb address
+ HostPort sensors; ///< sensors address
+ int sdbd_port; ///< Port to listen on in tcp mode
} SdbdCommandlineArgs;
#include <stdio.h>
int auth_get_key_file_paths ( parameters* in, parameters* out )
{
return PLUGIN_CMD_FAIL;
-
}
int confirm_public_key( parameters* in, int out_fd )
*/
void fdevent_loop();
-struct fdevent
-{
+struct fdevent {
fdevent *next;
fdevent *prev;
#define _FILE_SYNC_SERVICE_H_
#ifdef HAVE_BIG_ENDIAN
-static inline unsigned __swap_uint32(unsigned x)
+static inline unsigned __swap_uint32(unsigned x)
{
return (((x) & 0xFF000000) >> 24)
| (((x) & 0x00FF0000) >> 8)
struct {
unsigned id;
unsigned msglen;
- } status;
+ } status;
} syncmsg;
void init_sdk_sync_permit_rule_regx(void);
void set_smackmnt(const char *mnt)
{
- smack_mnt = strdup(mnt);
+ smack_mnt = strdup(mnt);
}
/* Verify the mount point for smack file system has a smackfs.
*/
static int verify_smackmnt(const char *mnt)
{
- struct statfs sfbuf;
- int rc;
-
- do {
- rc = statfs(mnt, &sfbuf);
- } while (rc < 0 && errno == EINTR);
-
- if (rc == 0) {
- if ((uint32_t)sfbuf.f_type == (uint32_t)SMACK_MAGIC) {
- struct statvfs vfsbuf;
- rc = statvfs(mnt, &vfsbuf);
- if (rc == 0) {
- if (!(vfsbuf.f_flag & ST_RDONLY)) {
- set_smackmnt(mnt);
- }
- return 0;
- }
- }
- }
-
- return -1;
+ struct statfs sfbuf;
+ int rc;
+
+ do {
+ rc = statfs(mnt, &sfbuf);
+ } while (rc < 0 && errno == EINTR);
+
+ if (rc == 0) {
+ if ((uint32_t)sfbuf.f_type == (uint32_t)SMACK_MAGIC) {
+ struct statvfs vfsbuf;
+ rc = statvfs(mnt, &vfsbuf);
+ if (rc == 0) {
+ if (!(vfsbuf.f_flag & ST_RDONLY)) {
+ set_smackmnt(mnt);
+ }
+ return 0;
+ }
+ }
+ }
+
+ return -1;
}
int smackfs_exists(void)
{
- int exists = 0;
- FILE *fp = NULL;
- char *buf = NULL;
- size_t len;
- ssize_t num;
-
- fp = fopen("/proc/filesystems", "r");
- if (!fp)
- return 1; /* Fail as if it exists */
-
- __fsetlocking(fp, FSETLOCKING_BYCALLER);
-
- num = getline(&buf, &len, fp);
- while (num != -1) {
- if (strstr(buf, SMACKFS)) {
- exists = 1;
- break;
- }
- num = getline(&buf, &len, fp);
- }
-
- free(buf);
- fclose(fp);
- return exists;
+ int exists = 0;
+ FILE *fp = NULL;
+ char *buf = NULL;
+ size_t len;
+ ssize_t num;
+
+ fp = fopen("/proc/filesystems", "r");
+ if (!fp)
+ return 1; /* Fail as if it exists */
+
+ __fsetlocking(fp, FSETLOCKING_BYCALLER);
+
+ num = getline(&buf, &len, fp);
+ while (num != -1) {
+ if (strstr(buf, SMACKFS)) {
+ exists = 1;
+ break;
+ }
+ num = getline(&buf, &len, fp);
+ }
+
+ free(buf);
+ fclose(fp);
+ return exists;
}
static void init_smackmnt(void)
{
- char *buf=NULL, *p;
- FILE *fp=NULL;
- size_t len;
- ssize_t num;
-
- if (smack_mnt)
- return;
-
- if (verify_smackmnt(SMACKFSMNT) == 0)
- return;
-
- if (verify_smackmnt(OLDSMACKFSMNT) == 0)
- return;
-
- /* Drop back to detecting it the long way. */
- if (!smackfs_exists())
- goto out;
-
- /* At this point, the usual spot doesn't have an smackfs so
- * we look around for it */
- fp = fopen("/proc/mounts", "r");
- if (!fp)
- goto out;
-
- __fsetlocking(fp, FSETLOCKING_BYCALLER);
- while ((num = getline(&buf, &len, fp)) != -1) {
- char *tmp;
- p = strchr(buf, ' ');
- if (!p)
- goto out;
- p++;
-
- tmp = strchr(p, ' ');
- if (!tmp)
- goto out;
-
- if (!strncmp(tmp + 1, SMACKFS" ", strlen(SMACKFS)+1)) {
- *tmp = '\0';
- break;
- }
- }
-
- /* If we found something, dup it */
- if (num > 0)
- verify_smackmnt(p);
+ char *buf=NULL, *p;
+ FILE *fp=NULL;
+ size_t len;
+ ssize_t num;
+
+ if (smack_mnt)
+ return;
+
+ if (verify_smackmnt(SMACKFSMNT) == 0)
+ return;
+
+ if (verify_smackmnt(OLDSMACKFSMNT) == 0)
+ return;
+
+ /* Drop back to detecting it the long way. */
+ if (!smackfs_exists())
+ goto out;
+
+ /* At this point, the usual spot doesn't have an smackfs so
+ * we look around for it */
+ fp = fopen("/proc/mounts", "r");
+ if (!fp)
+ goto out;
+
+ __fsetlocking(fp, FSETLOCKING_BYCALLER);
+ while ((num = getline(&buf, &len, fp)) != -1) {
+ char *tmp;
+ p = strchr(buf, ' ');
+ if (!p)
+ goto out;
+ p++;
+
+ tmp = strchr(p, ' ');
+ if (!tmp)
+ goto out;
+
+ if (!strncmp(tmp + 1, SMACKFS" ", strlen(SMACKFS)+1)) {
+ *tmp = '\0';
+ break;
+ }
+ }
+
+ /* If we found something, dup it */
+ if (num > 0)
+ verify_smackmnt(p);
out:
- free(buf);
- if (fp)
- fclose(fp);
- return;
+ free(buf);
+ if (fp)
+ fclose(fp);
+ return;
}
void fini_smackmnt(void)
{
- free(smack_mnt);
- smack_mnt = NULL;
+ free(smack_mnt);
+ smack_mnt = NULL;
}
static void init_lib(void) __attribute__ ((constructor));
static void init_lib(void)
{
- init_smackmnt();
+ init_smackmnt();
}
static void fini_lib(void) __attribute__ ((destructor));
static void fini_lib(void)
{
- fini_smackmnt();
+ fini_smackmnt();
}
-\r
-#include <string.h>\r
-\r
-//#define LOG_TAG "SDBD"\r
-//#include <dlog.h>\r
-#define TRACE_TAG TRACE_SDB\r
-#include "log.h"\r
-\r
-#include "plugin.h"\r
-#include "plugin_encrypt.h"\r
-#include "parameter.h"\r
-#include "sdbd_plugin.h"\r
-\r
-#define SAKEP_AKE_MSG_RECORD_FIXED_LEN 36\r
-#define SAKEP_AES_ECB_ADDED_PADDING_SIZE 16\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_init(const int nSessionID, const char* pUserID)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- if (pUserID == NULL) {\r
- in.number_of_parameter = 1;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
- } else {\r
- in.number_of_parameter = 2;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
- in.array_of_parameter[1].type = type_string;\r
- in.array_of_parameter[1].v_string.length = strlen(pUserID);\r
- in.array_of_parameter[1].v_string.data = strdup(pUserID);\r
- }\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_INIT, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_deinit(const int nSessionID)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 1;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DEINIT, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_parse_server_hello(const int nSessionID, apacket* pApacket)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 2;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
- in.array_of_parameter[1].type = type_chunk;\r
- in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
- in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_HELLO, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- // avoid to free\r
- in.array_of_parameter[1].v_chunk.data = NULL;\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_gen_client_hello(const int nSessionID, apacket* pApacket)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 1;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_HELLO, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
- pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_parse_server_ack(const int nSessionID, apacket* pApacket)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 2;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
- in.array_of_parameter[1].type = type_chunk;\r
- in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
- in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_ACK, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- // avoid to free\r
- in.array_of_parameter[1].v_chunk.data = NULL;\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_gen_client_ack(const int nSessionID, apacket* pApacket)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 1;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_ACK, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
- pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_encrypt(const int nSessionID, apacket* pApacket)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 2;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
- in.array_of_parameter[1].type = type_chunk;\r
- in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
- in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_ENCRYPT, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
- pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- // avoid to free\r
- in.array_of_parameter[1].v_chunk.data = NULL;\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
-// return 1 if success\r
-// return 0 otherwise\r
-int security_decrypt(const int nSessionID, apacket* pApacket)\r
-{\r
- int success = 0;\r
- int ret;\r
- parameters in, out;\r
-\r
- in.number_of_parameter = 2;\r
- in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );\r
- in.array_of_parameter[0].type = type_int32;\r
- in.array_of_parameter[0].v_int32 = nSessionID;\r
- in.array_of_parameter[1].type = type_chunk;\r
- in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;\r
- in.array_of_parameter[1].v_chunk.data = pApacket->data;\r
-\r
- ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DECRYPT, &in, &out );\r
- if ( ret == PLUGIN_CMD_SUCCESS ) {\r
- memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);\r
- pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;\r
- success = 1;\r
- release_parameters ( &out );\r
- }\r
-\r
- // avoid to free\r
- in.array_of_parameter[1].v_chunk.data = NULL;\r
- release_parameters ( &in );\r
- return success;\r
-}\r
-\r
+
+#include <string.h>
+
+//#define LOG_TAG "SDBD"
+//#include <dlog.h>
+#define TRACE_TAG TRACE_SDB
+#include "log.h"
+
+#include "plugin.h"
+#include "plugin_encrypt.h"
+#include "parameter.h"
+#include "sdbd_plugin.h"
+
+#define SAKEP_AKE_MSG_RECORD_FIXED_LEN 36
+#define SAKEP_AES_ECB_ADDED_PADDING_SIZE 16
+
+// return 1 if success
+// return 0 otherwise
+int security_init(const int nSessionID, const char* pUserID)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ if (pUserID == NULL) {
+ in.number_of_parameter = 1;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+ } else {
+ in.number_of_parameter = 2;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+ in.array_of_parameter[1].type = type_string;
+ in.array_of_parameter[1].v_string.length = strlen(pUserID);
+ in.array_of_parameter[1].v_string.data = strdup(pUserID);
+ }
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_INIT, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_deinit(const int nSessionID)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 1;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DEINIT, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_parse_server_hello(const int nSessionID, apacket* pApacket)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 2;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+ in.array_of_parameter[1].type = type_chunk;
+ in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;
+ in.array_of_parameter[1].v_chunk.data = pApacket->data;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_HELLO, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ // avoid to free
+ in.array_of_parameter[1].v_chunk.data = NULL;
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_gen_client_hello(const int nSessionID, apacket* pApacket)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 1;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_HELLO, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);
+ pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_parse_server_ack(const int nSessionID, apacket* pApacket)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 2;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+ in.array_of_parameter[1].type = type_chunk;
+ in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;
+ in.array_of_parameter[1].v_chunk.data = pApacket->data;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_PARSE_SERVER_ACK, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ // avoid to free
+ in.array_of_parameter[1].v_chunk.data = NULL;
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_gen_client_ack(const int nSessionID, apacket* pApacket)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 1;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_GEN_CLIENT_ACK, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);
+ pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_encrypt(const int nSessionID, apacket* pApacket)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 2;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+ in.array_of_parameter[1].type = type_chunk;
+ in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;
+ in.array_of_parameter[1].v_chunk.data = pApacket->data;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_ENCRYPT, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);
+ pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ // avoid to free
+ in.array_of_parameter[1].v_chunk.data = NULL;
+ release_parameters ( &in );
+ return success;
+}
+
+// return 1 if success
+// return 0 otherwise
+int security_decrypt(const int nSessionID, apacket* pApacket)
+{
+ int success = 0;
+ int ret;
+ parameters in, out;
+
+ in.number_of_parameter = 2;
+ in.array_of_parameter = ( parameter* ) malloc ( sizeof (parameter) * in.number_of_parameter );
+ in.array_of_parameter[0].type = type_int32;
+ in.array_of_parameter[0].v_int32 = nSessionID;
+ in.array_of_parameter[1].type = type_chunk;
+ in.array_of_parameter[1].v_chunk.size = pApacket->msg.data_length;
+ in.array_of_parameter[1].v_chunk.data = pApacket->data;
+
+ ret = request_sync_cmd ( PLUGIN_SYNC_CMD_SEC_DECRYPT, &in, &out );
+ if ( ret == PLUGIN_CMD_SUCCESS ) {
+ memcpy(pApacket->data, out.array_of_parameter[0].v_chunk.data, out.array_of_parameter[0].v_chunk.size);
+ pApacket->msg.data_length = out.array_of_parameter[0].v_chunk.size;
+ success = 1;
+ release_parameters ( &out );
+ }
+
+ // avoid to free
+ in.array_of_parameter[1].v_chunk.data = NULL;
+ release_parameters ( &in );
+ return success;
+}
+
-#ifndef __TRANSPORT_SECURITY_H__\r
-#define __TRANSPORT_SECURITY_H__\r
-\r
-#include "sdb.h"\r
-\r
-int security_init(const int nID, const char* pUserID);\r
-int security_deinit(const int nSessionID);\r
-int security_parse_server_hello(const int nSessionID, apacket* pApacket);\r
-int security_gen_client_hello(const int nSessionID, apacket* pApacket);\r
-int security_parse_server_ack(const int nSessionID, apacket* pApacket);\r
-int security_gen_client_ack(const int nSessionID, apacket* pApacket);\r
-int security_encrypt(const int nID, apacket* pApacket);\r
-int security_decrypt(const int nID, apacket* pApacket);\r
-\r
-#endif\r
+#ifndef __TRANSPORT_SECURITY_H__
+#define __TRANSPORT_SECURITY_H__
+
+#include "sdb.h"
+
+int security_init(const int nID, const char* pUserID);
+int security_deinit(const int nSessionID);
+int security_parse_server_hello(const int nSessionID, apacket* pApacket);
+int security_gen_client_hello(const int nSessionID, apacket* pApacket);
+int security_parse_server_ack(const int nSessionID, apacket* pApacket);
+int security_gen_client_ack(const int nSessionID, apacket* pApacket);
+int security_encrypt(const int nID, apacket* pApacket);
+int security_decrypt(const int nID, apacket* pApacket);
+
+#endif
/*
desc. : 암호화 실패 메시지 전송
parameter : [in] apacket* p : sdbd로 들어온 메시지
- [in] atransport *t : 현재 연결에 대한 atransport
- [in] unsigned failed_value : 실패 값
+ [in] atransport *t : 현재 연결에 대한 atransport
+ [in] unsigned failed_value : 실패 값
*/
void send_encr_fail(apacket* p, atransport *t, unsigned failed_value){
- apacket* enc_p;
- enc_p = get_apacket();
- enc_p->msg.command = A_ENCR; // 암호화 메시지
- enc_p->msg.arg0 = failed_value; // 실패값
- enc_p->msg.arg1 = p->msg.arg1;
- send_packet(enc_p, t);
- //put_apacket(enc_p);
+ apacket* enc_p;
+ enc_p = get_apacket();
+ enc_p->msg.command = A_ENCR; // 암호화 메시지
+ enc_p->msg.arg0 = failed_value; // 실패값
+ enc_p->msg.arg1 = p->msg.arg1;
+ send_packet(enc_p, t);
+ //put_apacket(enc_p);
}
/*
desc. : 암호화 메시지 핸들링
parameter : [in] apacket* p : sdbd로 들어온 메시지
- [in/out] atransport *t : 현재 연결에 대한 atransport
+ [in/out] atransport *t : 현재 연결에 대한 atransport
ret : 0 : 정상적으로 메시지 전송
- -1: 메시지 전송 실패
+ -1: 메시지 전송 실패
*/
int handle_encr_packet(apacket* p, atransport *t){
- static int sessionID = 0;
- int retVal = 0;
+ static int sessionID = 0;
+ int retVal = 0;
apacket* enc_p = NULL;
- if(p->msg.arg0 == ENCR_SET_ON_REQ){ // hello 메시지인 경우
- t->sessionID = sessionID;
- if((retVal = security_init(t->sessionID, NULL)) == 1){ // 암호화 handshaking을 위한 init
- if(security_parse_server_hello(t->sessionID, p) == 1){ // hello 메시지 파싱
- D("security_parse_server_hello success\n");
+ if(p->msg.arg0 == ENCR_SET_ON_REQ){ // hello 메시지인 경우
+ t->sessionID = sessionID;
+ if((retVal = security_init(t->sessionID, NULL)) == 1){ // 암호화 handshaking을 위한 init
+ if(security_parse_server_hello(t->sessionID, p) == 1){ // hello 메시지 파싱
+ D("security_parse_server_hello success\n");
enc_p = get_apacket();
- if(security_gen_client_hello(t->sessionID, enc_p) == 1){ // hello 메시지 생성
- D("security_gen_client_hello success\n");
- enc_p->msg.command = A_ENCR;
- enc_p->msg.arg0 = ENCR_SET_ON_REQ;
- enc_p->msg.arg1 = p->msg.arg1;
- sessionID++;
- send_packet(enc_p, t);
- }
- else { // hello 메시지 생성 실패
- D("security_gen_client_hello error\n");
- send_encr_fail(p, t, ENCR_ON_FAIL); // 암호화 on 실패 메시지 전송
- t->encryption = ENCR_OFF; // 암호화 모드는 off
- security_deinit(t->sessionID);
- return -1;
- }
- }
- else{ // hello 메시지 파싱 실패
- D("security_parse_server_hello error\n");
- send_encr_fail(p, t, ENCR_ON_FAIL);
- t->encryption = ENCR_OFF;
- security_deinit(t->sessionID);
-
- return -1;
- }
- } else { // init 실패
- D("security_init error\n");
- send_encr_fail(p, t, ENCR_ON_FAIL);
- t->encryption = ENCR_OFF;
- if (retVal == -1)
- {
- security_deinit(t->sessionID);
- }
- //here!! do security_deinit(), but when plugin pointer is null -> not deinit
- return -1;
- }
- }
- else if(p->msg.arg0 == ENCR_SET_ON_OK){ // ack 메시지인 경우
- if(security_parse_server_ack(t->sessionID, p) == 1){ // ack 메시지 파싱
+ if(security_gen_client_hello(t->sessionID, enc_p) == 1){ // hello 메시지 생성
+ D("security_gen_client_hello success\n");
+ enc_p->msg.command = A_ENCR;
+ enc_p->msg.arg0 = ENCR_SET_ON_REQ;
+ enc_p->msg.arg1 = p->msg.arg1;
+ sessionID++;
+ send_packet(enc_p, t);
+ }
+ else { // hello 메시지 생성 실패
+ D("security_gen_client_hello error\n");
+ send_encr_fail(p, t, ENCR_ON_FAIL); // 암호화 on 실패 메시지 전송
+ t->encryption = ENCR_OFF; // 암호화 모드는 off
+ security_deinit(t->sessionID);
+ return -1;
+ }
+ }
+ else{ // hello 메시지 파싱 실패
+ D("security_parse_server_hello error\n");
+ send_encr_fail(p, t, ENCR_ON_FAIL);
+ t->encryption = ENCR_OFF;
+ security_deinit(t->sessionID);
+
+ return -1;
+ }
+ } else { // init 실패
+ D("security_init error\n");
+ send_encr_fail(p, t, ENCR_ON_FAIL);
+ t->encryption = ENCR_OFF;
+ if (retVal == -1)
+ {
+ security_deinit(t->sessionID);
+ }
+ //here!! do security_deinit(), but when plugin pointer is null -> not deinit
+ return -1;
+ }
+ }
+ else if(p->msg.arg0 == ENCR_SET_ON_OK){ // ack 메시지인 경우
+ if(security_parse_server_ack(t->sessionID, p) == 1){ // ack 메시지 파싱
enc_p = get_apacket();
- if(security_gen_client_ack(t->sessionID, enc_p) == 1){ // ack 메시지 생성
- D("security_gen_client_ack success\n");
- enc_p->msg.command = A_ENCR;
- enc_p->msg.arg0 = ENCR_SET_ON_OK;
- enc_p->msg.arg1 = p->msg.arg1;
- t->encryption = ENCR_ON;
- send_packet(enc_p, t);
- }
- else { // ack 메시지 생성에 실패한 경우
- D("security_gen_client_ack error\n");
- send_encr_fail(p, t, ENCR_ON_FAIL);
- t->encryption = ENCR_OFF;
- security_deinit(t->sessionID);
- return -1;
- }
- }
- else { // ack 메시지 파싱에 실패한 경우
- D("security_parse_server_ack error\n");
- send_encr_fail(p, t, ENCR_ON_FAIL);
- t->encryption = ENCR_OFF;
- security_deinit(t->sessionID);
- return -1;
- }
- }
- else if(p->msg.arg0 == ENCR_SET_OFF){ // 암호화 모드 off 요청 메시지
- if(t->encryption == ENCR_ON && security_deinit(t->sessionID) == 1){ // 현재 암호화 모드가 on 상태인 경우
- enc_p = get_apacket();
- t->encryption = ENCR_OFF; // 현재 연결에 대한 암호화 모드 off
- enc_p->msg.command = A_ENCR;
- enc_p->msg.arg0 = ENCR_SET_OFF;
- enc_p->msg.arg1 = p->msg.arg1;
- send_packet(enc_p, t);
- }
- else { // 암호화 모드 off에 실패한 경우
- D("security_deinit error\n");
- send_encr_fail(p, t, ENCR_OFF_FAIL); // 암호화 모드 off 실패 메시지 전송
- return -1;
- }
- }
- else if(p->msg.arg0 == ENCR_GET){ // 암호화 모드의 상태 요청 메시지인 경우
- enc_p = get_apacket();
- enc_p->msg.command = A_ENCR;
- enc_p->msg.arg0 = ENCR_GET; // 암호화 모드 status get메시지
- enc_p->msg.arg1 = p->msg.arg1;
- if(t->encryption == ENCR_ON){ // 암호화 모드가 on인 경우
- enc_p->msg.data_length = 13;
- strncpy((char*)enc_p->data, "encryption:on", enc_p->msg.data_length); // encryption:on 메시지 전송
- } else if(t->encryption == ENCR_OFF){ // 암호화 모드가 off인 경우
- enc_p->msg.data_length = 14;
- strncpy((char*)enc_p->data, "encryption:off", enc_p->msg.data_length); // encryption:off 메시지 전송
- }
- send_packet(enc_p, t);
- }
- else if (p->msg.arg0 == ENCR_ON_FAIL) // 암호화 모드를 on 하는 도중 실패한 경우 받는 메시지
- {
- t->encryption = ENCR_OFF; // 암호화 모드를 다시 off
- D("encryption on failed\n");
- }
- else if (p->msg.arg0 == ENCR_OFF_FAIL) // 암호화 모드를 off하는 도중 실패한 경우 받는 메시지
- {
- //t->encryption = ENCR_ON;
- D("encryption off failed\n");
- }
- //put_apacket(enc_p);
- return 0;
+ if(security_gen_client_ack(t->sessionID, enc_p) == 1){ // ack 메시지 생성
+ D("security_gen_client_ack success\n");
+ enc_p->msg.command = A_ENCR;
+ enc_p->msg.arg0 = ENCR_SET_ON_OK;
+ enc_p->msg.arg1 = p->msg.arg1;
+ t->encryption = ENCR_ON;
+ send_packet(enc_p, t);
+ }
+ else { // ack 메시지 생성에 실패한 경우
+ D("security_gen_client_ack error\n");
+ send_encr_fail(p, t, ENCR_ON_FAIL);
+ t->encryption = ENCR_OFF;
+ security_deinit(t->sessionID);
+ return -1;
+ }
+ }
+ else { // ack 메시지 파싱에 실패한 경우
+ D("security_parse_server_ack error\n");
+ send_encr_fail(p, t, ENCR_ON_FAIL);
+ t->encryption = ENCR_OFF;
+ security_deinit(t->sessionID);
+ return -1;
+ }
+ }
+ else if(p->msg.arg0 == ENCR_SET_OFF){ // 암호화 모드 off 요청 메시지
+ if(t->encryption == ENCR_ON && security_deinit(t->sessionID) == 1){ // 현재 암호화 모드가 on 상태인 경우
+ enc_p = get_apacket();
+ t->encryption = ENCR_OFF; // 현재 연결에 대한 암호화 모드 off
+ enc_p->msg.command = A_ENCR;
+ enc_p->msg.arg0 = ENCR_SET_OFF;
+ enc_p->msg.arg1 = p->msg.arg1;
+ send_packet(enc_p, t);
+ }
+ else { // 암호화 모드 off에 실패한 경우
+ D("security_deinit error\n");
+ send_encr_fail(p, t, ENCR_OFF_FAIL); // 암호화 모드 off 실패 메시지 전송
+ return -1;
+ }
+ }
+ else if(p->msg.arg0 == ENCR_GET){ // 암호화 모드의 상태 요청 메시지인 경우
+ enc_p = get_apacket();
+ enc_p->msg.command = A_ENCR;
+ enc_p->msg.arg0 = ENCR_GET; // 암호화 모드 status get메시지
+ enc_p->msg.arg1 = p->msg.arg1;
+ if(t->encryption == ENCR_ON){ // 암호화 모드가 on인 경우
+ enc_p->msg.data_length = 13;
+ strncpy((char*)enc_p->data, "encryption:on", enc_p->msg.data_length); // encryption:on 메시지 전송
+ } else if(t->encryption == ENCR_OFF){ // 암호화 모드가 off인 경우
+ enc_p->msg.data_length = 14;
+ strncpy((char*)enc_p->data, "encryption:off", enc_p->msg.data_length); // encryption:off 메시지 전송
+ }
+ send_packet(enc_p, t);
+ }
+ else if (p->msg.arg0 == ENCR_ON_FAIL) // 암호화 모드를 on 하는 도중 실패한 경우 받는 메시지
+ {
+ t->encryption = ENCR_OFF; // 암호화 모드를 다시 off
+ D("encryption on failed\n");
+ }
+ else if (p->msg.arg0 == ENCR_OFF_FAIL) // 암호화 모드를 off하는 도중 실패한 경우 받는 메시지
+ {
+ //t->encryption = ENCR_ON;
+ D("encryption off failed\n");
+ }
+ //put_apacket(enc_p);
+ return 0;
}
#endif
}
break;
#ifdef SUPPORT_ENCRYPT
- case A_ENCR: // 암호화 메시지인 경우
- if(t->connection_state != CS_OFFLINE) {
- handle_encr_packet(p, t);
- }
- break;
+ case A_ENCR: // 암호화 메시지인 경우
+ if(t->connection_state != CS_OFFLINE) {
+ handle_encr_packet(p, t);
+ }
+ break;
#endif
default:
#define SDBD_BOOT_INFO_FILE "/tmp/sdbd_boot_info"
static DBusHandlerResult __sdbd_dbus_signal_filter(DBusConnection *conn,
- DBusMessage *message, void *user_data) {
- D("got dbus message\n");
- const char *interface;
-
- DBusError error;
- dbus_error_init(&error);
-
- interface = dbus_message_get_interface(message);
- if (interface == NULL) {
- D("reject by security issue - no interface\n");
- return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
- }
-
- if (dbus_message_is_signal(message, DEVICED_CORE_INTERFACE,
- BOOTING_DONE_SIGNAL)) {
- booting_done = 1;
- if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) {
- D("booting is done before\n");
- } else {
- FILE *f = fopen(SDBD_BOOT_INFO_FILE, "w");
- if (f != NULL) {
- fprintf(f, "%d", 1);
- fclose(f);
- }
- }
- D("booting is done\n");
- }
-
- D("handled dbus message\n");
- return DBUS_HANDLER_RESULT_HANDLED;
+ DBusMessage *message, void *user_data) {
+ D("got dbus message\n");
+ const char *interface;
+
+ DBusError error;
+ dbus_error_init(&error);
+
+ interface = dbus_message_get_interface(message);
+ if (interface == NULL) {
+ D("reject by security issue - no interface\n");
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
+
+ if (dbus_message_is_signal(message, DEVICED_CORE_INTERFACE,
+ BOOTING_DONE_SIGNAL)) {
+ booting_done = 1;
+ if (access(SDBD_BOOT_INFO_FILE, F_OK) == 0) {
+ D("booting is done before\n");
+ } else {
+ FILE *f = fopen(SDBD_BOOT_INFO_FILE, "w");
+ if (f != NULL) {
+ fprintf(f, "%d", 1);
+ fclose(f);
+ }
+ }
+ D("booting is done\n");
+ }
+
+ D("handled dbus message\n");
+ return DBUS_HANDLER_RESULT_HANDLED;
}
static void *bootdone_cb(void *x) {
- int MAX_LOCAL_BUFSZ = 128;
- DBusError error;
- DBusConnection *bus;
- char rule[MAX_LOCAL_BUFSZ];
- GMainLoop *mainloop;
+ int MAX_LOCAL_BUFSZ = 128;
+ DBusError error;
+ DBusConnection *bus;
+ char rule[MAX_LOCAL_BUFSZ];
+ GMainLoop *mainloop;
/* g_type_init() is deprecated for glib version 2.35.0 or greater, */
#if !GLIB_CHECK_VERSION(2,35,0)
- g_type_init();
+ g_type_init();
#endif
- dbus_error_init(&error);
- bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
- if (!bus) {
- D("Failed to connect to the D-BUS daemon: %s", error.message);
- dbus_error_free(&error);
- return NULL;
- }
- dbus_connection_setup_with_g_main(bus, NULL);
-
- snprintf(rule, MAX_LOCAL_BUFSZ, "type='signal',interface='%s'",
- DEVICED_CORE_INTERFACE);
- /* listening to messages */
- dbus_bus_add_match(bus, rule, &error);
- if (dbus_error_is_set(&error)) {
- D("Fail to rule set: %s", error.message);
- dbus_error_free(&error);
- return NULL;
- }
-
- if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL)
- == FALSE)
- return NULL;
-
- D("booting signal initialized\n");
- mainloop = g_main_loop_new(NULL, FALSE);
- g_main_loop_run(mainloop);
-
- D("dbus loop exited");
+ dbus_error_init(&error);
+ bus = dbus_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (!bus) {
+ D("Failed to connect to the D-BUS daemon: %s", error.message);
+ dbus_error_free(&error);
+ return NULL;
+ }
+ dbus_connection_setup_with_g_main(bus, NULL);
+
+ snprintf(rule, MAX_LOCAL_BUFSZ, "type='signal',interface='%s'",
+ DEVICED_CORE_INTERFACE);
+ /* listening to messages */
+ dbus_bus_add_match(bus, rule, &error);
+ if (dbus_error_is_set(&error)) {
+ D("Fail to rule set: %s", error.message);
+ dbus_error_free(&error);
+ return NULL;
+ }
+
+ if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL)
+ == FALSE)
+ return NULL;
+
+ D("booting signal initialized\n");
+ mainloop = g_main_loop_new(NULL, FALSE);
+ g_main_loop_run(mainloop);
+
+ D("dbus loop exited");
dbus_connection_unref(bus);
- return NULL;
+ return NULL;
}
void register_bootdone_cb() {
- D("registerd bootdone callback\n");
+ D("registerd bootdone callback\n");
- sdb_thread_t t;
- if (sdb_thread_create(&t, bootdone_cb, NULL)) {
- D("cannot create service thread\n");
- return;
- }
+ sdb_thread_t t;
+ if (sdb_thread_create(&t, bootdone_cb, NULL)) {
+ D("cannot create service thread\n");
+ return;
+ }
}
static int sdbd_set_groups(const char *name, int gid, struct group_info default_groups[], int default_groups_size) {
/* socket-type-specific extradata */
void *extra;
- /* A socket is bound to atransport */
+ /* A socket is bound to atransport */
atransport *transport;
};
size_t max_payload;
#ifdef SUPPORT_ENCRYPT
- unsigned encryption; // 해당 연결이 암호화 모드인지 확인하는 flag , 0 = no-encryption / 1 = encryption
- int sessionID; // 암호화 세션 ID, 암호화 map에 대한 key
+ unsigned encryption; // 해당 연결이 암호화 모드인지 확인하는 flag , 0 = no-encryption / 1 = encryption
+ int sessionID; // 암호화 세션 ID, 암호화 map에 대한 key
#endif
};
writex(fd, buf, strlen(buf));
}
} else {
- snprintf(buf, sizeof(buf), "Unknown command option : %s\n", mode);
+ snprintf(buf, sizeof(buf), "Unknown command option : %s\n", mode);
writex(fd, buf, strlen(buf));
}
D("set rootshell to %s\n", rootshell_mode == 1 ? "root" : SDK_USER_NAME);
if (ret < 0) {
close(s);
- return -1;
+ return -1;
}
}
#ifndef __SOCKET_LOCAL_H
#define __SOCKET_LOCAL_H
-#define FILESYSTEM_SOCKET_PREFIX "/tmp/"
+#define FILESYSTEM_SOCKET_PREFIX "/tmp/"
#define ANDROID_RESERVED_SOCKET_PREFIX "/dev/socket/"
/*
* socklen_t is set to indicate the final length. This function
* will fail if the namespace is invalid (not one of the indicated
* constants) or if the name is too long.
- *
+ *
* @return 0 on success or -1 on failure
- */
-int socket_make_sockaddr_un(const char *name, int namespaceId,
+ */
+int socket_make_sockaddr_un(const char *name, int namespaceId,
struct sockaddr_un *p_addr, socklen_t *alen);
#endif
}
-/** Open a server-side UNIX domain datagram socket in the Linux non-filesystem
+/** Open a server-side UNIX domain datagram socket in the Linux non-filesystem
* namespace
*
* Returns fd on success, -1 on fail
{
int err;
int s;
-
+
s = socket(AF_LOCAL, type, 0);
if (s < 0) return -1;
if (ret < 0) {
sdb_close(s);
- return -1;
+ return -1;
}
}
apacket *p = get_apacket();
unsigned char *x = p->data;
#ifdef SUPPORT_ENCRYPT
- // sdb.c:536에서 sdb server의 패킷은 MAX_PAYLOAD-100으로 정하여서,
- // sdb server에서 패킷 데이터의 크기를 MAX_PAYLOAD-100보다 작은 지를 체크함.
- // sdbd에서 패킷 데이터를 MAX_PAYLOAD - 200로 잡아서 암호화 하게되면
- // 최대 MAX_PAYLOAD - 100 크기의 패킷을 생성하게 됨.
- const size_t max_payload = asock_get_max_payload(s) - 200;
+ // sdb.c:536에서 sdb server의 패킷은 MAX_PAYLOAD-100으로 정하여서,
+ // sdb server에서 패킷 데이터의 크기를 MAX_PAYLOAD-100보다 작은 지를 체크함.
+ // sdbd에서 패킷 데이터를 MAX_PAYLOAD - 200로 잡아서 암호화 하게되면
+ // 최대 MAX_PAYLOAD - 100 크기의 패킷을 생성하게 됨.
+ const size_t max_payload = asock_get_max_payload(s) - 200;
#else
const size_t max_payload = asock_get_max_payload(s);
#endif
#include <sys/socket.h>
#endif
-#define ANDROID_SOCKET_ENV_PREFIX "ANDROID_SOCKET_"
-#define ANDROID_SOCKET_DIR "/dev/socket"
+#define ANDROID_SOCKET_ENV_PREFIX "ANDROID_SOCKET_"
+#define ANDROID_SOCKET_DIR "/dev/socket"
#ifdef __cplusplus
extern "C" {
*/
static inline int android_get_control_socket(const char *name)
{
- char key[64] = ANDROID_SOCKET_ENV_PREFIX;
- const char *val;
- int fd;
+ char key[64] = ANDROID_SOCKET_ENV_PREFIX;
+ const char *val;
+ int fd;
- /* build our environment variable, counting cycles like a wolf ... */
+ /* build our environment variable, counting cycles like a wolf ... */
#if HAVE_STRLCPY
- strlcpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1,
- name,
- sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX));
-#else /* for the host, which may lack the almightly strncpy ... */
- strncpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1,
- name,
- sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX));
- key[sizeof(key)-1] = '\0';
+ strlcpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1,
+ name,
+ sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX));
+#else /* for the host, which may lack the almightly strncpy ... */
+ strncpy(key + sizeof(ANDROID_SOCKET_ENV_PREFIX) - 1,
+ name,
+ sizeof(key) - sizeof(ANDROID_SOCKET_ENV_PREFIX));
+ key[sizeof(key)-1] = '\0';
#endif
- val = getenv(key);
- if (!val)
- return -1;
+ val = getenv(key);
+ if (!val)
+ return -1;
- errno = 0;
- fd = strtol(val, NULL, 10);
- if (errno)
- return -1;
+ errno = 0;
+ fd = strtol(val, NULL, 10);
+ if (errno)
+ return -1;
- return fd;
+ return fd;
}
/*
t->serial);
#ifdef SUPPORT_ENCRYPT
- if (t->encryption == ENCR_ON && p->msg.command != A_ENCR) // 현재 연결이 암호화 모드이고, 암호화 관련 메시지가 아닌 경우, 메시지 복호화
- {
- security_decrypt(t->sessionID, p);
- }
+ if (t->encryption == ENCR_ON && p->msg.command != A_ENCR) // 현재 연결이 암호화 모드이고, 암호화 관련 메시지가 아닌 경우, 메시지 복호화
+ {
+ security_decrypt(t->sessionID, p);
+ }
#endif
D("%s: transport got packet, sending to remote, state(%s)\n", t->serial, statename(t));
#ifdef SUPPORT_ENCRYPT
- if (t->encryption == ENCR_ON && p->msg.command != A_ENCR) // 현재 연결이 암호화 모드이고, 암호화 관련 메시지가 아닌 경우, 메시지를 암호화
- {
- security_encrypt(t->sessionID, p);
- }
- else if(t->encryption == ENCR_OFF)
- {
+ if (t->encryption == ENCR_ON && p->msg.command != A_ENCR) // 현재 연결이 암호화 모드이고, 암호화 관련 메시지가 아닌 경우, 메시지를 암호화
+ {
+ security_encrypt(t->sessionID, p);
+ }
+ else if(t->encryption == ENCR_OFF)
+ {
- }
+ }
#endif
apacket* ap = get_apacket();
copy_packet(ap, p);
send_packet(ap, t);
-
+
if (ap->msg.command == A_STAT && ap->msg.arg1 == 0) {
// lock state message
if (ap->msg.arg0 == 0) {
#include "plugin.h"
#ifdef HAVE_BIG_ENDIAN
-#define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
+#define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
static inline void fix_endians(apacket *p)
{
p->msg.command = H4(p->msg.command);
}
if (get_emulator_guestip(guest_ip, sizeof guest_ip) == -1) {
- D("failed to get emulator guest ip\n");
- goto sleep_and_continue;
- }
+ D("failed to get emulator guest ip\n");
+ goto sleep_and_continue;
+ }
// tell qemu sdbd is just started with udp
if (send_msg_to_localhost_from_guest(host_ip, sensors_port, "2\n", 1) < 0) {
#include "sdb.h"
#ifdef HAVE_BIG_ENDIAN
-#define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
+#define H4(x) (((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8) | (((x) & 0x0000FF00) << 8) | (((x) & 0x000000FF) << 24)
static inline void fix_endians(apacket *p)
{
p->msg.command = H4(p->msg.command);
#include "sdb.h"
-#define MAX_PACKET_SIZE_FS 64
-#define MAX_PACKET_SIZE_HS 512
+#define MAX_PACKET_SIZE_FS 64
+#define MAX_PACKET_SIZE_HS 512
#define cpu_to_le16(x) htole16(x)
#define cpu_to_le32(x) htole32(x)
sdb_mutex_unlock(&usb->lock);
D("[ usb_thread - registering device ]\n");
- register_usb_transport(usb, NULL, 1); /* writable transport */
+ register_usb_transport(usb, NULL, 1); /* writable transport */
while (1) {
/* wait until the USB device needs reset */
sdb_mutex_unlock(&usb->lock);
D("[ usb_thread - registering device ]\n");
- register_usb_transport(usb, NULL, 1); /* writable transport */
+ register_usb_transport(usb, NULL, 1); /* writable transport */
}
/* never gets here */
}
/* dispatch read event */
- switch (read_event.type) {
- case FUNCTIONFS_RESUME:
- case FUNCTIONFS_ENABLE:
- D("FFSEvent %s\n", names[read_event.type]);
- sdb_mutex_lock(&usb->lock);
- usb->ffs_enabled = 1;
- sdb_cond_signal(&usb->notify);
- sdb_mutex_unlock(&usb->lock);
- break;
-
- case FUNCTIONFS_SUSPEND:
- case FUNCTIONFS_DISABLE:
- D("FFSEvent %s\n", names[read_event.type]);
- sdb_mutex_lock(&usb->lock);
- usb->ffs_enabled = 0;
- sdb_mutex_unlock(&usb->lock);
- break;
-
- case FUNCTIONFS_BIND:
- case FUNCTIONFS_UNBIND:
- case FUNCTIONFS_SETUP:
- D("FFSEvent %s\n", names[read_event.type]);
- break;
-
- default:
- D("FFSEvent event (type=%d) is unknown -- ignored\n", read_event.type);
- break;
- }
+ switch (read_event.type) {
+ case FUNCTIONFS_RESUME:
+ case FUNCTIONFS_ENABLE:
+ D("FFSEvent %s\n", names[read_event.type]);
+ sdb_mutex_lock(&usb->lock);
+ usb->ffs_enabled = 1;
+ sdb_cond_signal(&usb->notify);
+ sdb_mutex_unlock(&usb->lock);
+ break;
+
+ case FUNCTIONFS_SUSPEND:
+ case FUNCTIONFS_DISABLE:
+ D("FFSEvent %s\n", names[read_event.type]);
+ sdb_mutex_lock(&usb->lock);
+ usb->ffs_enabled = 0;
+ sdb_mutex_unlock(&usb->lock);
+ break;
+
+ case FUNCTIONFS_BIND:
+ case FUNCTIONFS_UNBIND:
+ case FUNCTIONFS_SETUP:
+ D("FFSEvent %s\n", names[read_event.type]);
+ break;
+
+ default:
+ D("FFSEvent event (type=%d) is unknown -- ignored\n", read_event.type);
+ break;
+ }
return ret;
}
if (errno != EINTR) {
return ret;
}
- } else {
+ } else {
count += ret;
- }
+ }
} while (count < length);
*/
static int ep0_exists()
{
- struct stat statb;
- return stat(ep0_path, &statb) == 0;
+ struct stat statb;
+ return stat(ep0_path, &statb) == 0;
}
return -ENODEV;
}
- h->EP0_NAME = ep0_path;
- h->EP_OUT_NAME = ep1_path;
- h->EP_IN_NAME = ep2_path;
+ h->EP0_NAME = ep0_path;
+ h->EP_OUT_NAME = ep1_path;
+ h->EP_IN_NAME = ep2_path;
return 0;
}
}
char *str_trim(char *str) {
- size_t len = 0;
- char *frontp = str;
- char *endp = NULL;
-
- if (str == NULL) {
- return NULL;
- }
- if (str[0] == '\0') {
- return str;
- }
-
- len = strlen(str);
- endp = str + len;
-
- while (isspace(*frontp)) {
- ++frontp;
- }
- if (endp != frontp) {
- while (isspace(*(--endp)) && endp != frontp) {
- }
- }
-
- if (str + len - 1 != endp)
- *(endp + 1) = '\0';
- else if (frontp != str && endp == frontp)
- *str = '\0';
-
- endp = str;
- if (frontp != str) {
- while (*frontp) {
- *endp++ = *frontp++;
- }
- *endp = '\0';
- }
- return str;
+ size_t len = 0;
+ char *frontp = str;
+ char *endp = NULL;
+
+ if (str == NULL) {
+ return NULL;
+ }
+ if (str[0] == '\0') {
+ return str;
+ }
+
+ len = strlen(str);
+ endp = str + len;
+
+ while (isspace(*frontp)) {
+ ++frontp;
+ }
+ if (endp != frontp) {
+ while (isspace(*(--endp)) && endp != frontp) {
+ }
+ }
+
+ if (str + len - 1 != endp)
+ *(endp + 1) = '\0';
+ else if (frontp != str && endp == frontp)
+ *str = '\0';
+
+ endp = str;
+ if (frontp != str) {
+ while (*frontp) {
+ *endp++ = *frontp++;
+ }
+ *endp = '\0';
+ }
+ return str;
}
int spawn(const char* program, char* const arg_list[])
}
char** str_split(char* a_str, const char a_delim) {
- char** result = 0;
- size_t count = 0;
- char* tmp = a_str;
- char* last_comma = 0;
- char delim[2];
- delim[0] = a_delim;
- delim[1] = 0;
- char *ptr;
-
- /* Count how many elements will be extracted. */
- while (*tmp) {
- if (a_delim == *tmp) {
- count++;
- last_comma = tmp;
- }
- tmp++;
- }
-
- /* Add space for trailing token. */
- count += last_comma < (a_str + strlen(a_str) - 1);
-
- /* Add space for terminating null string so caller
- knows where the list of returned strings ends. */
- count++;
-
- result = malloc(sizeof(char*) * count);
-
- if (result) {
- size_t idx = 0;
- char* token = strtok_r(a_str, delim, &ptr);
-
- while (token) {
- //assert(idx < count);
- *(result + idx++) = strdup(token);
- token = strtok_r(0, delim, &ptr);
- }
- //assert(idx == count - 1);
- *(result + idx) = 0;
- }
-
- return result;
+ char** result = 0;
+ size_t count = 0;
+ char* tmp = a_str;
+ char* last_comma = 0;
+ char delim[2];
+ delim[0] = a_delim;
+ delim[1] = 0;
+ char *ptr;
+
+ /* Count how many elements will be extracted. */
+ while (*tmp) {
+ if (a_delim == *tmp) {
+ count++;
+ last_comma = tmp;
+ }
+ tmp++;
+ }
+
+ /* Add space for trailing token. */
+ count += last_comma < (a_str + strlen(a_str) - 1);
+
+ /* Add space for terminating null string so caller
+ knows where the list of returned strings ends. */
+ count++;
+
+ result = malloc(sizeof(char*) * count);
+
+ if (result) {
+ size_t idx = 0;
+ char* token = strtok_r(a_str, delim, &ptr);
+
+ while (token) {
+ //assert(idx < count);
+ *(result + idx++) = strdup(token);
+ token = strtok_r(0, delim, &ptr);
+ }
+ //assert(idx == count - 1);
+ *(result + idx) = 0;
+ }
+
+ return result;
}
int keep_alive(int fd, int onoff, int cnt, int idle, int interval)