From f71e433440041a74a3e72903dcd3e4478d310300 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Mon, 11 Apr 2016 13:33:49 +0900 Subject: [PATCH 01/16] Fixed sdk_launch script - Supported multi user feature Change-Id: I2c092c8ad4f332571353f12f91f50638416dc3f6 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- script/sdk_launch | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 4b562e1..0a7d9aa 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.8 +Version: 3.0.9 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/script/sdk_launch b/script/sdk_launch index 6206e59..b914363 100755 --- a/script/sdk_launch +++ b/script/sdk_launch @@ -132,7 +132,7 @@ then if [ "" != "$attach_id" ] #debug attach then - cmd="/usr/bin/launch_debug $launch_app_arg1 __AUL_SDK__ ATTACH __DLP_ATTACH_ARG__ --attach,:$port,$attach_id" + cmd="/usr/bin/launch_debug $launch_app_arg1 __AUL_SDK__ ATTACH __DLP_GDBSERVER_PATH__ ${SDK_TOOLS_PATH}/gdbserver/gdbserver __DLP_ATTACH_ARG__ --attach,:$port,$attach_id" #debug else if [ "" != "$result_mode" ] @@ -141,7 +141,7 @@ then else result_mode="DEBUG" fi - cmd="/usr/bin/launch_app $launch_app_arg1 __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode $args" + cmd="/usr/bin/app_launcher -s $launch_app_arg1 __AUL_SDK__ $result_mode __DLP_DEBUG_ARG__ :$port $launch_app_mode $args __DLP_GDBSERVER_PATH__ ${SDK_TOOLS_PATH}/gdbserver/gdbserver" # cmd="$COV_TEST_PREFIX ${TZ_SDK_TOOLS}/gdbserver/gdbserver :$port ${TZ_SYS_RW_APP}/$pkgid/bin/$exe" fi else -- 2.7.4 From 2f4a9d9c1670bbe26286b8cf69169cbb7041e9db Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Mon, 18 Apr 2016 18:17:05 +0900 Subject: [PATCH 02/16] Fixed build warnings. Change-Id: I1063d7ae01b6b28699cd90d82f9fe88c1737a34a Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- src/file_sync_service.c | 55 ++++++++++++++++++++------------ src/sdb.c | 17 ++++++---- src/sdb.h | 8 ++--- src/sdktools.c | 4 +-- src/sdktools.h | 2 +- src/services.c | 14 ++++---- src/transport.c | 14 +++----- src/transport_local.c | 85 ++----------------------------------------------- src/usb_funcfs_client.c | 4 +-- src/usb_libusb.c | 2 +- src/usb_linux.c | 2 +- src/usb_linux_client.c | 2 +- src/utils.c | 4 +-- src/utils.h | 2 +- 15 files changed, 74 insertions(+), 143 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 0a7d9aa..a05aff7 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.9 +Version: 3.0.10 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 0e97ab4..d142ff1 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -39,13 +39,10 @@ #define SYNC_TIMEOUT 15 -#define APP_INSTALL_PATH_PREFIX1 tzplatform_getenv(TZ_SYS_RW_APP) -#define APP_INSTALL_PATH_PREFIX2 tzplatform_mkpath(TZ_SDK_HOME, "apps_rw") - struct sync_permit_rule { const char *name; - const char *regx; + char *regx; int mode; // 0:push, 1: pull, 2: push&push }; @@ -63,9 +60,19 @@ struct sync_permit_rule sdk_sync_permit_rule[] = { void init_sdk_sync_permit_rule_regx(void) { - asprintf(&sdk_sync_permit_rule[0].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); - asprintf(&sdk_sync_permit_rule[1].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); - asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); + int ret; + ret = asprintf(&sdk_sync_permit_rule[0].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); + if(ret < 0) { + D("failed to run asprintf for unittest\n"); + } + ret = asprintf(&sdk_sync_permit_rule[1].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); + if (ret < 0) { + D("failed to run asprintf for codecoverage\n"); + } + ret = asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); + if (ret < 0) { + D("failed to run asprintf for da\n"); + } } static void set_syncfile_smack_label(char *src) { @@ -285,11 +292,12 @@ static int fail_message(int s, const char *reason) static int fail_errno(int s) { - char buf[512]; + char* ret_str; + char buf[512]; - strerror_r(s, buf, sizeof(buf)); + ret_str = strerror_r(s, buf, sizeof(buf)); - return fail_message(s, buf); + return fail_message(s, (const char*)ret_str); } // FIXME: should get the following paths with api later but, do it for simple and not having dependency on other packages @@ -310,16 +318,16 @@ static void sync_mediadb(char *path) { } if (strstr(path, MEDIA_CONTENTS_PATH1) != NULL) { - char *arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH1, NULL}; - spawn(CMD_MEDIADB_UPDATE, arg_list); + const char * const arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH1, NULL}; + spawn(CMD_MEDIADB_UPDATE, (char * const*)arg_list); D("media db update done to %s\n", MEDIA_CONTENTS_PATH1); } else if (strstr(path, MEDIA_CONTENTS_PATH2) != NULL) { - char *arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH2, NULL}; - spawn(CMD_MEDIADB_UPDATE, arg_list); + const char * const arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH2, NULL}; + spawn(CMD_MEDIADB_UPDATE, (char * const*)arg_list); D("media db update done to %s\n", MEDIA_CONTENTS_PATH2); } else if (strstr(path, MEDIA_CONTENTS_PATH3) != NULL) { - char *arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH3, NULL}; - spawn(CMD_MEDIADB_UPDATE, arg_list); + const char * const arg_list[] = {CMD_MEDIADB_UPDATE, "-r", MEDIA_CONTENTS_PATH3, NULL}; + spawn(CMD_MEDIADB_UPDATE, (char * const*)arg_list); D("media db update done to %s\n", MEDIA_CONTENTS_PATH3); } return; @@ -475,7 +483,10 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) { char *tmp; mode_t mode; - int is_link, ret; + int ret; +#ifdef HAVE_SYMLINKS + int is_link; +#endif // Check the capability for file push support. if(!is_support_push()) { @@ -488,9 +499,7 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) *tmp = 0; errno = 0; mode = strtoul(tmp + 1, NULL, 0); -#ifndef HAVE_SYMLINKS - is_link = 0; -#else +#ifdef HAVE_SYMLINKS is_link = S_ISLNK(mode); #endif // extracts file permission from stat.mode. (ex 100644 & 0777 = 644); @@ -499,11 +508,15 @@ static int do_send(int s, int noti_fd, char *path, char *buffer) } if(!tmp || errno) { mode = 0644; // set default permission value in most of unix system. +#ifdef HAVE_SYMLINKS is_link = 0; +#endif } if (is_pkg_file_path(path)) { mode = 0644; +#ifdef HAVE_SYMLINKS is_link = 0; +#endif } // sdb does not allow to check that file exists or not. After deleting old file and creating new file again unconditionally. @@ -601,7 +614,7 @@ static int verify_sync_rule(const char* path) { } } regfree(®ex); - for (i = 0; i <= 3; i++){ + for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++){ free(sdk_sync_permit_rule[i].regx); } return 0; diff --git a/src/sdb.c b/src/sdb.c index ac5f2ad..61b5bc4 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -92,7 +92,7 @@ static int is_support_sockproto(); void (*usb_init)() = NULL; void (*usb_cleanup)() = NULL; int (*usb_write)(usb_handle *h, const void *data, int len) = NULL; -int (*usb_read)(usb_handle *h, void *data, int len) = NULL; +int (*usb_read)(usb_handle *h, void *data, size_t len) = NULL; int (*usb_close)(usb_handle *h) = NULL; void (*usb_kick)(usb_handle *h) = NULL; @@ -128,7 +128,7 @@ void handle_sig_term(int sig) { if (access(SDB_PIDPATH, F_OK) == 0) sdb_unlink(SDB_PIDPATH); #endif - char *cmd1_args[] = {"/usr/bin/killall", "/usr/bin/debug_launchpad_preloading_preinitializing_daemon", NULL}; + char * const cmd1_args[] = {"/usr/bin/killall", "/usr/bin/debug_launchpad_preloading_preinitializing_daemon", NULL}; spawn("/usr/bin/killall", cmd1_args); sdb_sleep_ms(1000); } @@ -1361,14 +1361,17 @@ static void *bootdone_cb(void *x) { 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(); +#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 -1; + return NULL; } dbus_connection_setup_with_g_main(bus, NULL); @@ -1379,12 +1382,12 @@ static void *bootdone_cb(void *x) { if (dbus_error_is_set(&error)) { D("Fail to rule set: %s", error.message); dbus_error_free(&error); - return -1; + return NULL; } if (dbus_connection_add_filter(bus, __sdbd_dbus_signal_filter, NULL, NULL) == FALSE) - return -1; + return NULL; D("booting signal initialized\n"); mainloop = g_main_loop_new(NULL, FALSE); @@ -1392,7 +1395,7 @@ static void *bootdone_cb(void *x) { D("dbus loop exited"); - return 0; + return NULL; } void register_bootdone_cb() { @@ -1499,7 +1502,7 @@ int set_sdk_user_privileges() { } static void execute_required_process() { - char *cmd_args[] = {"/usr/bin/debug_launchpad_preloading_preinitializing_daemon",NULL}; + char * const cmd_args[] = {"/usr/bin/debug_launchpad_preloading_preinitializing_daemon",NULL}; spawn("/usr/bin/debug_launchpad_preloading_preinitializing_daemon", cmd_args); } diff --git a/src/sdb.h b/src/sdb.h index 21056b6..dd0fe23 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -521,7 +521,7 @@ int local_connect_arbitrary_ports(int console_port, int sdb_port, const char *d void usb_init(); void usb_cleanup(); int usb_write(usb_handle *h, const void *data, int len); -int usb_read(usb_handle *h, void *data, int len); +int usb_read(usb_handle *h, void *data, size_t len); int usb_close(usb_handle *h); void usb_kick(usb_handle *h); #else @@ -529,7 +529,7 @@ void usb_kick(usb_handle *h); extern void (*usb_init)(); extern void (*usb_cleanup)(); extern int (*usb_write)(usb_handle *h, const void *data, int len); -extern int (*usb_read)(usb_handle *h, void *data, int len); +extern int (*usb_read)(usb_handle *h, void *data, size_t len); extern int (*usb_close)(usb_handle *h); extern void (*usb_kick)(usb_handle *h); @@ -537,7 +537,7 @@ extern void (*usb_kick)(usb_handle *h); void ffs_usb_init(); void ffs_usb_cleanup(); int ffs_usb_write(usb_handle *h, const void *data, int len); -int ffs_usb_read(usb_handle *h, void *data, int len); +int ffs_usb_read(usb_handle *h, void *data, size_t len); int ffs_usb_close(usb_handle *h); void ffs_usb_kick(usb_handle *h); @@ -545,7 +545,7 @@ void ffs_usb_kick(usb_handle *h); void linux_usb_init(); void linux_usb_cleanup(); int linux_usb_write(usb_handle *h, const void *data, int len); -int linux_usb_read(usb_handle *h, void *data, unsigned len); +int linux_usb_read(usb_handle *h, void *data, size_t len); int linux_usb_close(usb_handle *h); void linux_usb_kick(usb_handle *h); diff --git a/src/sdktools.c b/src/sdktools.c index f24bccc..7780101 100644 --- a/src/sdktools.c +++ b/src/sdktools.c @@ -32,10 +32,10 @@ struct sudo_command root_commands[] = { } }, /* end */ - { NULL, NULL, NULL } + { NULL, NULL, {NULL} } }; -static struct command_suffix +struct command_suffix { const char *name; // comments for human const char *suffix; //pattern diff --git a/src/sdktools.h b/src/sdktools.h index 50b68de..9027970 100644 --- a/src/sdktools.h +++ b/src/sdktools.h @@ -26,7 +26,7 @@ struct arg_permit_rule #define SDK_LAUNCH_PATH "/usr/sbin/sdk_launch" #define APP_INSTALL_PATH_PREFIX1 tzplatform_getenv(TZ_SYS_RW_APP) -#define APP_INSTALL_PATH_PREFIX2 tzplatform_getenv(TZ_USER_APP) +#define APP_INSTALL_PATH_PREFIX2 tzplatform_mkpath(TZ_SDK_HOME, "apps_rw") #define DEV_INSTALL_PATH_PREFIX tzplatform_getenv(TZ_SDK_TOOLS) #define GDBSERVER_PATH tzplatform_mkpath(TZ_SDK_TOOLS,"gdbserver/gdbserver") #define GDBSERVER_PLATFORM_PATH tzplatform_mkpath(TZ_SDK_TOOLS,"gdbserver-platform/gdbserver") diff --git a/src/services.c b/src/services.c index 9607462..dc19c14 100644 --- a/src/services.c +++ b/src/services.c @@ -387,7 +387,7 @@ static int create_service_thread(void (*func)(int, void *), void *cookie) #if !SDB_HOST -static void redirect_and_exec(int pts, const char *cmd, const char *argv[], const char *envp[]) +static void redirect_and_exec(int pts, const char *cmd, char * const argv[], char * const envp[]) { dup2(pts, 0); dup2(pts, 1); @@ -398,7 +398,7 @@ static void redirect_and_exec(int pts, const char *cmd, const char *argv[], cons execve(cmd, argv, envp); } -static int create_subprocess(const char *cmd, pid_t *pid, const char *argv[], const char *envp[]) +static int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], char * const envp[]) { char devname[64]; int ptm; @@ -517,7 +517,6 @@ static void get_env(char *key, char **env) { FILE *fp; char buf[1024]; - int i; char *s, *e, *value; fp = fopen (LOGIN_CONFIG, "r"); @@ -641,7 +640,7 @@ static int create_subproc_thread(const char *name, int lines, int columns) }; args[2] = new_cmd; - ret_fd = create_subprocess(SHELL_COMMAND, &pid, args, envp); + ret_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp); free(new_cmd); } else { // in case of shell interactively // Check the capability for interactive shell support. @@ -650,12 +649,12 @@ static int create_subproc_thread(const char *name, int lines, int columns) return -1; } - char *args[] = { + char * const args[] = { SHELL_COMMAND, "-", NULL, }; - ret_fd = create_subprocess(SHELL_COMMAND, &pid, args, envp); + ret_fd = create_subprocess(SHELL_COMMAND, &pid, (char * const*)args, (char * const*)envp); #if 0 // FIXME: should call login command instead of /bin/sh if (should_drop_privileges()) { char *args[] = { @@ -950,7 +949,6 @@ static void sync_windowsize(int fd, void *cookie) { const unsigned COMMAND_TIMEOUT = 10000; void get_boot(int fd, void *cookie) { char buf[2] = { 0, }; - char *mode = (char*) cookie; int time = 0; int interval = 1000; while (time < COMMAND_TIMEOUT) { @@ -1076,7 +1074,7 @@ int service_to_fd(const char *name) } } else if(!strncmp(name, "shellconf:", 10)){ if(!strncmp(name+10, "syncwinsz:", 10)){ - ret = create_service_thread(sync_windowsize, name+20); + ret = create_service_thread(sync_windowsize, (void *)name+20); } } diff --git a/src/transport.c b/src/transport.c index c4b64d7..a697eee 100644 --- a/src/transport.c +++ b/src/transport.c @@ -524,7 +524,7 @@ static int transport_read_action(int fd, struct tmsg* m) { char *p = (char*)m; - int len = sizeof(*m); + size_t len = sizeof(*m); int r; while(len > 0) { @@ -546,7 +546,7 @@ static int transport_write_action(int fd, struct tmsg* m) { char *p = (char*)m; - int len = sizeof(*m); + size_t len = sizeof(*m); int r; while(len > 0) { @@ -745,7 +745,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s { atransport *t; atransport *result = NULL; - int ambiguous = 0; if (error_out) *error_out = "device not found"; @@ -769,7 +768,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s if (result) { if (error_out) *error_out = "more than one device"; - ambiguous = 1; result = NULL; break; } @@ -778,7 +776,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s if (result) { if (error_out) *error_out = "more than one emulator"; - ambiguous = 1; result = NULL; break; } @@ -787,7 +784,6 @@ atransport *acquire_one_transport(int state, transport_type ttype, const char* s if (result) { if (error_out) *error_out = "more than one device and emulator"; - ambiguous = 1; result = NULL; break; } @@ -1058,9 +1054,9 @@ int readx(int fd, void *ptr, size_t len) char *p = ptr; int r; #if SDB_TRACE - int len0 = len; + size_t len0 = len; #endif - D("readx: fd=%d wanted=%d\n", fd, (int)len); + D("readx: fd=%d wanted=%d\n", fd, len); while(len > 0) { r = sdb_read(fd, p, len); if(r > 0) { @@ -1091,7 +1087,7 @@ int writex(int fd, const void *ptr, size_t len) int r; #if SDB_TRACE - D("writex: fd=%d len=%d: ", fd, (int)len); + D("writex: fd=%d len=%d: ", fd, len); dump_hex( ptr, len ); #endif while(len > 0) { diff --git a/src/transport_local.c b/src/transport_local.c index 1daa143..527e1f5 100644 --- a/src/transport_local.c +++ b/src/transport_local.c @@ -415,85 +415,6 @@ static const char _ok_resp[] = "ok"; #endif // !SDB_HOST #endif -/*! - * static int send_msg_to_host_from_guest(const char *hostname, int host_port, char *request, int sock_type) - * @brief Sends \c request to host using specified protocol - * - * @param hostname Hostname -- could be domain name or IP - * @param host_port Host port - * @param request Message to be sent to host - * @param protocol IP protocol to be used: IPPROTO_TCP or IPPROTO_UDP - * - * @returns 0 on success, -1 otherwise - * - * @note SOCK_STREAM will be used for IPPROTO_TCP as socket type - * and SOCK_DGRAM for IPPROTO_UDP - */ -static int send_msg_to_host_from_guest(const char *hostname, int host_port, char *request, int protocol) { - int sock = -1; - int PORT_SIZE = 32; - char port[PORT_SIZE]; /* string decimal representation for getaddrinfo */ - struct addrinfo hints = {0}; - struct addrinfo *addresses, *curr_addr; - int getaddr_ret; - const char *protocol_name = "unknown"; /* for debug message */ - - switch(protocol) { - case IPPROTO_TCP: - protocol_name = "tcp"; - hints.ai_socktype = SOCK_STREAM; - break; - case IPPROTO_UDP: - protocol_name = "udp"; - hints.ai_socktype = SOCK_DGRAM; - break; - default: - D("unsupported protocol: %d", protocol); - return -1; - } - - D("try to send notification to host(%s:%d) using %s:[%s]\n", hostname, host_port, protocol_name, request); - - hints.ai_family = AF_INET; - - snprintf(port, PORT_SIZE, "%d", host_port); - getaddr_ret = getaddrinfo(hostname, port, &hints, &addresses); - - if (getaddr_ret != 0) { - D("could not resolve %s\n", hostname); - return -1; - } - - for(curr_addr = addresses; curr_addr != NULL; curr_addr = curr_addr->ai_next) { - sock = socket(curr_addr->ai_family, curr_addr->ai_socktype, curr_addr->ai_protocol); - if (sock == -1) - continue; - - if (connect(sock, curr_addr->ai_addr, curr_addr->ai_addrlen) != -1) - break; /* Success */ - - sdb_close(sock); - } - - if(curr_addr == NULL) { /* No address succeeded */ - freeaddrinfo(addresses); - D("could not connect to server\n"); - return -1; - } - - freeaddrinfo(addresses); - - if (sdb_write(sock, request, strlen(request)) < 0) { - D("could not send notification request to host\n"); - sdb_close(sock); - return -1; - } - sdb_close(sock); - D("sent notification request to host\n"); - - return 0; -} - int connect_nonb(int sockfd, const struct sockaddr *saptr, socklen_t salen, int nsec) { int flags, n, error; @@ -588,7 +509,7 @@ static int send_msg_to_localhost_from_guest(const char *host_ip, int local_port, } // send the "emulator" request to sdbserver -static void notify_sdbd_startup_thread() { +static void* notify_sdbd_startup_thread(void* ptr) { char buffer[512]; char request[512]; @@ -605,11 +526,11 @@ static void notify_sdbd_startup_thread() { int time = 0; //int try_limit_time = -1; // try_limit_time < 0 if unlimited if (sensors_port < 0 || emulator_port < 0 || r < 0) { - return; + return NULL; } if (get_emulator_hostip(host_ip, sizeof host_ip) == -1) { D("failed to get emulator host ip\n"); - return; + return NULL; } // XXX: Known issue - log collision while (1) { diff --git a/src/usb_funcfs_client.c b/src/usb_funcfs_client.c index ef28284..75d90aa 100644 --- a/src/usb_funcfs_client.c +++ b/src/usb_funcfs_client.c @@ -297,7 +297,7 @@ static int read_control(struct usb_handle *usb) /* Read events from control endpoint Fortunately, FunctionFS guarantees reading of full event (or nothing), so we're not bothered with ret < sizeof(read_event) */ - ret = sdb_read(usb->control, &read_event, sizeof(read_event)); + ret = sdb_read(usb->control, (void *)&read_event, sizeof(read_event)); if (ret < 0) { /* EAGAIN support will be useful, when non-blocking ep0 reads are supported in FunctionFS */ @@ -548,7 +548,7 @@ int ffs_usb_write(usb_handle *h, const void *data, int len) * * @returns 0 on success and -1 on failure (errno is set) */ -int ffs_usb_read(usb_handle *h, void *data, int len) +int ffs_usb_read(usb_handle *h, void *data, size_t len) { int n; diff --git a/src/usb_libusb.c b/src/usb_libusb.c index 8d12ea7..fc3596f 100644 --- a/src/usb_libusb.c +++ b/src/usb_libusb.c @@ -171,7 +171,7 @@ usb_write(struct usb_handle *uh, const void *_data, int len) } int -usb_read(struct usb_handle *uh, void *_data, int len) +usb_read(struct usb_handle *uh, void *_data, size_t len) { unsigned char *data = (unsigned char*) _data; int n; diff --git a/src/usb_linux.c b/src/usb_linux.c index d7e8399..95f2ee9 100644 --- a/src/usb_linux.c +++ b/src/usb_linux.c @@ -454,7 +454,7 @@ int usb_write(usb_handle *h, const void *_data, int len) return 0; } -int usb_read(usb_handle *h, void *_data, int len) +int usb_read(usb_handle *h, void *_data, size_t len) { unsigned char *data = (unsigned char*) _data; int n; diff --git a/src/usb_linux_client.c b/src/usb_linux_client.c index d2af0c4..ec8c159 100644 --- a/src/usb_linux_client.c +++ b/src/usb_linux_client.c @@ -94,7 +94,7 @@ int linux_usb_write(usb_handle *h, const void *data, int len) return 0; } -int linux_usb_read(usb_handle *h, void *data, unsigned len) +int linux_usb_read(usb_handle *h, void *data, size_t len) { int n; diff --git a/src/utils.c b/src/utils.c index ae7d51d..acf8c5a 100644 --- a/src/utils.c +++ b/src/utils.c @@ -151,7 +151,7 @@ char *str_trim(char *str) { return str; } -int spawn(char* program, char** arg_list) +int spawn(const char* program, char* const arg_list[]) { pid_t pid; int ret; @@ -167,7 +167,7 @@ int spawn(char* program, char** arg_list) // init takes the process, and the process is not able to be zombie exit(0); } - execvp (program, arg_list); + execvp(program, arg_list); fprintf(stderr, "failed to spawn: never reach here!:%s\n", program); exit(0); } diff --git a/src/utils.h b/src/utils.h index 11a63c8..ce17442 100644 --- a/src/utils.h +++ b/src/utils.h @@ -72,7 +72,7 @@ char *str_trim(char* string); * spawn a process and returns the process id of the new spawned process. * it is working as async. */ -int spawn(char* program, char** arg_list); +int spawn(const char* program, char * const arg_list[]); char** str_split(char* a_str, const char a_delim); -- 2.7.4 From 7c2595d0822b22221af68a47be06e5691fbedf20 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 26 Apr 2016 20:57:37 +0900 Subject: [PATCH 03/16] Fixed a bug where sdbd shows incorrect error message Change-Id: I1107e20525547327f7f97431c581c647aa6570d9 Signed-off-by: shingil.kang --- src/file_sync_service.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/file_sync_service.c b/src/file_sync_service.c index d142ff1..5fc6642 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -276,12 +276,13 @@ done: static int fail_message(int s, const char *reason) { syncmsg msg; - int len = strlen(reason); + size_t len = strlen(reason); D("sync: failure: %s\n", reason); msg.data.id = ID_FAIL; msg.data.size = htoll(len); + if(writex(s, &msg.data, sizeof(msg.data)) || writex(s, reason, len)) { return -1; @@ -290,14 +291,14 @@ static int fail_message(int s, const char *reason) } } -static int fail_errno(int s) +static int fail_errno(int fd, int err_no) { char* ret_str; - char buf[512]; + char buf[512] = {0, }; - ret_str = strerror_r(s, buf, sizeof(buf)); + ret_str = strerror_r(err_no, buf, sizeof(buf)); - return fail_message(s, (const char*)ret_str); + return fail_message(fd, (const char*)ret_str); } // FIXME: should get the following paths with api later but, do it for simple and not having dependency on other packages @@ -348,7 +349,7 @@ static int handle_send_file(int s, int noti_fd, char *path, mode_t mode, char *b fd = sdb_open_mode(path, O_WRONLY, mode); } if(fd < 0) { - if(fail_errno(s)) + if(fail_errno(s, errno)) return -1; fd = -1; } @@ -385,7 +386,7 @@ static int handle_send_file(int s, int noti_fd, char *path, mode_t mode, char *b sdb_unlink(path); fd = -1; errno = saved_errno; - if(fail_errno(s)) return -1; + if(fail_errno(s, errno)) return -1; } } @@ -446,7 +447,7 @@ static int handle_send_link(int s, int noti_fd, char *path, char *buffer) ret = symlink(buffer, path); } if(ret) { - fail_errno(s); + fail_errno(s, errno); return -1; } @@ -556,7 +557,7 @@ static int do_recv(int s, const char *path, char *buffer) fd = sdb_open(path, O_RDONLY); if(fd < 0) { - if(fail_errno(s)) return -1; + if(fail_errno(s, errno)) return -1; return 0; } @@ -566,7 +567,7 @@ static int do_recv(int s, const char *path, char *buffer) if(r <= 0) { if(r == 0) break; if(errno == EINTR) continue; - r = fail_errno(s); + r = fail_errno(s, errno); sdb_close(fd); return r; } -- 2.7.4 From 7d6427a05082be14e01e0620d2955300e392925a Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Wed, 27 Apr 2016 14:51:55 +0900 Subject: [PATCH 04/16] Modify the sdk groups routine for sdb shell/sync service. - Add the groups for sdbd shell/sync default group. ("priv_externalstorage", "priv_externalstorage_appdata", "priv_mediastorage") - Modify the sdk group init routine that receives group infomation from platform. Change-Id: I7273df2e05f65a62953e7e4f6003e3bc928aaae4 Signed-off-by: Kim Gunsoo --- src/sdb.c | 115 ++++++++++++++++++++++++++++++++++++++++---------------------- src/sdb.h | 3 ++ 2 files changed, 77 insertions(+), 41 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 61b5bc4..793d8ec 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -77,7 +77,13 @@ struct group_info const char *name; gid_t gid; }; -struct group_info g_default_groups[] = { {"log", -1}, {NULL, -1}}; +struct group_info g_default_groups[] = { + {"priv_externalstorage", -1}, + {"priv_externalstorage_appdata", -1}, + {"priv_mediastorage", -1}, + {"log", -1}, + {NULL, -1} +}; #define SDB_DEFAULT_GROUPS_CNT ((sizeof(g_default_groups)/sizeof(g_default_groups[0]))-1) int is_init_sdk_userinfo = 0; @@ -1435,7 +1441,7 @@ static int sdbd_set_groups() { break; } } - if (group_match == 0) { + if (group_match == 0 && g_default_groups[i].gid != -1) { group_ids[ngroups + added_group_cnt] = g_default_groups[i].gid; added_group_cnt ++; } @@ -1462,7 +1468,25 @@ static int sdbd_get_user_pwd(const char* user_name, struct passwd* pwd, char* bu D("Not found passwd : username(%s)\n", user_name); } else { errno = ret; - D("failed to getpwuid_r\n"); + D("failed to getpwnam_r\n"); + } + return -1; + } + + return 0; +} + +static int sdbd_get_group(const char* group_name, struct group* grp, char* buf, size_t bufsize) { + struct group *result = NULL; + int ret = 0; + + ret = getgrnam_r(group_name, grp, buf, bufsize, &result); + if (result == NULL) { + if (ret == 0) { + D("Not found group : groupname(%s)\n", group_name); + } else { + errno = ret; + D("failed to getgrnam_r\n"); } return -1; } @@ -1478,26 +1502,25 @@ int set_sdk_user_privileges() { if (sdbd_set_groups() < 0) { D("set groups failed (errno: %d)\n", errno); - return -1; } if (setgid(g_sdk_group_id) != 0) { D("set group id failed (errno: %d)\n", errno); - return -1; } if (setuid(g_sdk_user_id) != 0) { D("set user id failed (errno: %d)\n", errno); - return -1; } if (chdir(g_sdk_home_dir) < 0) { D("unable to change working directory to %s\n", g_sdk_home_dir); - return -1; } // TODO: use pam later - putenv(g_sdk_home_dir_env); + if (g_sdk_home_dir_env) { + putenv(g_sdk_home_dir_env); + } + return 0; } @@ -1721,38 +1744,48 @@ static void load_sdbd_plugin() { D("using sdbd plugin interface.(%s)\n", SDBD_PLUGIN_PATH); } +#define SDB_PW_GR_DEFAULT_SIZE (16*1024) static long get_passwd_bufsize() { long bufsize = 0; bufsize = sysconf(_SC_GETPW_R_SIZE_MAX); if(bufsize < 0) { - bufsize = (16*1024); + bufsize = SDB_PW_GR_DEFAULT_SIZE; + } + + return bufsize; +} + +static long get_group_bufsize() { + long bufsize = 0; + + bufsize = sysconf(_SC_GETGR_R_SIZE_MAX); + if(bufsize < 0) { + bufsize = SDB_PW_GR_DEFAULT_SIZE; } return bufsize; } static int init_sdb_default_groups() { - struct passwd pwd; + struct group grp; char *buf = NULL; long bufsize = 0; int i = 0; - bufsize = get_passwd_bufsize(); + bufsize = get_group_bufsize(); buf = malloc(bufsize); if (buf == NULL) { - D("failed to allocate passwd buf(%ld)\n", bufsize); + D("failed to allocate gruop buf(%ld)\n", bufsize); return -1; } for (i = 0; g_default_groups[i].name != NULL; i++) { memset(buf, 0, bufsize); - if (sdbd_get_user_pwd(g_default_groups[i].name, &pwd, buf, bufsize) == 0) { - g_default_groups[i].gid = pwd.pw_gid; + if (sdbd_get_group(g_default_groups[i].name, &grp, buf, bufsize) == 0) { + g_default_groups[i].gid = grp.gr_gid; } else { - D("get user passwd info.(errno: %d)\n", errno); - free(buf); - return -1; + D("failed get group info.(errno: %d)\n", errno); } } @@ -1760,6 +1793,12 @@ static int init_sdb_default_groups() { return 0; } +static void set_static_userinfo() { + g_sdk_user_id = STATIC_SDK_USER_ID; + g_sdk_group_id = STATIC_SDK_GROUP_ID; + g_sdk_home_dir = STATIC_SDK_HOME_DIR; +} + static int init_sdk_userinfo() { struct passwd pwd; char *buf = NULL; @@ -1769,42 +1808,36 @@ static int init_sdk_userinfo() { return 0; } + if (init_sdb_default_groups() < 0) { + D("failed to initialize default groups.\n"); + } + bufsize = get_passwd_bufsize(); buf = malloc(bufsize); if (buf == NULL) { D("failed to allocate passwd buf(%ld)\n", bufsize); - return -1; - } + set_static_userinfo(); + } else { + if (sdbd_get_user_pwd(SDK_USER_NAME, &pwd, buf, bufsize) < 0) { + D("get user passwd info.(errno: %d)\n", errno); + set_static_userinfo(); + } else { + D("username=%s, uid=%d, gid=%d, dir=%s\n", pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_dir); - if (sdbd_get_user_pwd(SDK_USER_NAME, &pwd, buf, bufsize) < 0) { - D("get user passwd info.(errno: %d)\n", errno); + g_sdk_user_id = pwd.pw_uid; + g_sdk_group_id = pwd.pw_gid; + g_sdk_home_dir = strdup(pwd.pw_dir); + } free(buf); - return -1; - } - D("username=%s, uid=%d, gid=%d, dir=%s\n", pwd.pw_name, pwd.pw_uid, pwd.pw_gid, pwd.pw_dir); - - g_sdk_user_id = pwd.pw_uid; - g_sdk_group_id = pwd.pw_gid; - g_sdk_home_dir = strdup(pwd.pw_dir); - - free(buf); - - if (init_sdb_default_groups() < 0) { - D("failed to initialize default groups.\n"); - free(g_sdk_home_dir); - g_sdk_home_dir = NULL; - return -1; } int env_size = strlen("HOME=") + strlen(g_sdk_home_dir) + 1; g_sdk_home_dir_env = malloc(env_size); - if(g_sdk_home_dir_env == 0) { + if(g_sdk_home_dir_env == NULL) { D("failed to allocate for home dir env string\n"); - free(g_sdk_home_dir); - g_sdk_home_dir = NULL; - return -1; + } else { + snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir); } - snprintf(g_sdk_home_dir_env, env_size, "HOME=%s", g_sdk_home_dir); is_init_sdk_userinfo = 1; return 0; diff --git a/src/sdb.h b/src/sdb.h index dd0fe23..7e3d1f1 100644 --- a/src/sdb.h +++ b/src/sdb.h @@ -385,6 +385,9 @@ int booting_done; // 0: platform booting is in progess 1: platform booting is do #define SDK_USER_NAME tzplatform_getenv(TZ_SDK_USER_NAME) #define SDK_TOOL_PATH tzplatform_getenv(TZ_SDK_TOOLS) +#define STATIC_SDK_USER_ID 5001 +#define STATIC_SDK_GROUP_ID 100 +#define STATIC_SDK_HOME_DIR "/home/owner" extern uid_t g_sdk_user_id; extern gid_t g_sdk_group_id; extern char* g_sdk_home_dir; -- 2.7.4 From 7dff08909ee26b253d7465803ae2820783e87cb3 Mon Sep 17 00:00:00 2001 From: "yoonki.park" Date: Tue, 10 May 2016 17:37:32 +0900 Subject: [PATCH 05/16] Added to check validation of pointer - If packet pointer has invalid address then restart SDBD. Change-Id: Ieff9343bba35dcfe5122c18ddea60eec615bac76 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 +- src/fdevent.c | 2 +- src/sdb.c | 7 +++++++ src/transport.c | 8 ++++++++ 5 files changed, 18 insertions(+), 3 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index a05aff7..826c4f0 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.10 +Version: 3.0.11 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index e83b1f7..4fe803f 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -7,7 +7,7 @@ After=tmp.mount Type=forking EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid -RemainAfterExit=yes +Restart=on-failure ExecStart=/usr/sbin/sdbd [Install] diff --git a/src/fdevent.c b/src/fdevent.c index ca1bf3c..2e8a45a 100644 --- a/src/fdevent.c +++ b/src/fdevent.c @@ -50,7 +50,7 @@ static void fatal(const char *fn, const char *fmt, ...) fprintf(stderr, "%s:", fn); vfprintf(stderr, fmt, ap); va_end(ap); - abort(); + exit(-1); } #define FATAL(x...) fatal(__FUNCTION__, x) diff --git a/src/sdb.c b/src/sdb.c index 793d8ec..1fbd885 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -630,6 +630,13 @@ void parse_banner(char *banner, atransport *t) void handle_packet(apacket *p, atransport *t) { + // Verify pointer p + int result = access((const char *) p, F_OK); + if ((result == -1) && (errno == EFAULT)) { + D("Invalid apacket = [0x%x]", p); + fatal("Invalid apacket = [0x%x]", p); + } + asocket *s; D("handle_packet() %c%c%c%c\n", ((char*) (&(p->msg.command)))[0], diff --git a/src/transport.c b/src/transport.c index a697eee..1fe4b9d 100644 --- a/src/transport.c +++ b/src/transport.c @@ -323,6 +323,14 @@ static void *input_thread(void *_t) t->serial, t->fd ); break; } + + // Verify pointer p + int result = access((const char *) p, F_OK); + if ((result == -1) && (errno == EFAULT)) { + D("Invalid apacket = [0x%x]", p); + fatal("Invalid apacket = [0x%x]", p); + } + if(p->msg.command == A_SYNC){ if(p->msg.arg0 == 0) { D("%s: transport SYNC offline\n", t->serial); -- 2.7.4 From 98350bb2861dd178c159f3ab00310d77038942c0 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Mon, 18 Apr 2016 13:21:57 +0900 Subject: [PATCH 06/16] Change the routine for determining whether the emulator or device. - Determined to look at kernel parameters that includes the vm_name in case of emulator. Change-Id: I06734a63eb3afcb9b9638bc1044275e5291fc5eb Signed-off-by: Kim Gunsoo --- src/sdb.c | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/src/sdb.c b/src/sdb.c index 1fbd885..4f9040b 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -102,11 +102,18 @@ int (*usb_read)(usb_handle *h, void *data, size_t len) = NULL; int (*usb_close)(usb_handle *h) = NULL; void (*usb_kick)(usb_handle *h) = NULL; +int g_is_emulator = -1; int is_emulator(void) { #if SDB_HOST - return 0; + return 0; #else - return sdbd_commandline_args.emulator.host != NULL; + if (g_is_emulator >= 0) { + return g_is_emulator; + } else { + D("failed to initialize check emulator\n"); + } + + return sdbd_commandline_args.emulator.host != NULL; #endif } @@ -2112,9 +2119,33 @@ static int is_support_sockproto() return (!strncmp(g_capabilities.sockproto_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED))); } +#define EMULATOR_MODEL_NAME "Emulator" +static check_emulator_or_device() +{ + char model_name[256]={0,}; + int ret = -1; + + // Get the model name from model_config.xml + ret = get_device_name(model_name, sizeof model_name); + if (ret == 0) { + if(!strncmp(model_name, EMULATOR_MODEL_NAME, sizeof(EMULATOR_MODEL_NAME))){ + g_is_emulator = 1; + D("This target type is Emulator\n"); + } else { + g_is_emulator = 0; + D("This target type is Device\n"); + } + } else { + g_is_emulator = -1; + D("failed to get the model name.\n"); + } +} + int sdb_main(int is_daemon, int server_port) { #if !SDB_HOST + check_emulator_or_device(); + load_sdbd_plugin(); init_capabilities(); -- 2.7.4 From c0cc4c69e65107bb2b0f955c2589ca53551c6940 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Wed, 27 Apr 2016 17:43:11 +0900 Subject: [PATCH 07/16] Modify modules that need root permission. - Removed to permit root permission for push/pull(unitest, codecoverage, DA) - Changed uid/gid of SDBD into sdk Change-Id: Idd874377159afa3d387c9abb59aada2a9d34dbc3 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 ++ packaging/sdbd_emulator.service | 2 ++ src/file_sync_service.c | 64 +---------------------------------------- 4 files changed, 6 insertions(+), 64 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 826c4f0..6e1ba42 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.11 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index 4fe803f..5aaac68 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -4,6 +4,8 @@ Requires=tizen-system-env.service After=tmp.mount [Service] +User=sdk +Group=sdk Type=forking EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 1a2f298..01d3d04 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -5,6 +5,8 @@ After=tmp.mount dbus.service #DefaultDependencies=false [Service] +User=sdk +Group=sdk Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid diff --git a/src/file_sync_service.c b/src/file_sync_service.c index 5fc6642..c15ae10 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -39,42 +39,11 @@ #define SYNC_TIMEOUT 15 -struct sync_permit_rule -{ - const char *name; - char *regx; - int mode; // 0:push, 1: pull, 2: push&push -}; - -struct sync_permit_rule sdk_sync_permit_rule[] = { - /* 0 */ {"unitest", "", 1}, - /* 1 */ {"codecoverage", "", 1}, - /* 2 */ {"da", "", 1}, - /* end */ {NULL, NULL, 0} -}; - /* The typical default value for the umask is S_IWGRP | S_IWOTH (octal 022). * Before use the DIR_PERMISSION, the process umask value should be set 0 using umask(). */ #define DIR_PERMISSION 0777 -void init_sdk_sync_permit_rule_regx(void) -{ - int ret; - ret = asprintf(&sdk_sync_permit_rule[0].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); - if(ret < 0) { - D("failed to run asprintf for unittest\n"); - } - ret = asprintf(&sdk_sync_permit_rule[1].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); - if (ret < 0) { - D("failed to run asprintf for codecoverage\n"); - } - ret = asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); - if (ret < 0) { - D("failed to run asprintf for da\n"); - } -} - static void set_syncfile_smack_label(char *src) { char *label_transmuted = NULL; char *label = NULL; @@ -589,37 +558,6 @@ static int do_recv(int s, const char *path, char *buffer) return 0; } -static int verify_sync_rule(const char* path) { - regex_t regex; - int ret; - char buf[PATH_MAX]; - int i=0; - - init_sdk_sync_permit_rule_regx(); - for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++) { - ret = regcomp(®ex, sdk_sync_permit_rule[i].regx, REG_EXTENDED); - if(ret){ - return 0; - } - // execute regular expression - ret = regexec(®ex, path, 0, NULL, 0); - if(!ret){ - regfree(®ex); - D("found matched rule(%s) from %s path\n", sdk_sync_permit_rule[i].name, path); - return 1; - } else if( ret == REG_NOMATCH ){ - // do nothin - } else{ - regerror(ret, ®ex, buf, sizeof(buf)); - D("regex match failed(%s): %s\n",sdk_sync_permit_rule[i].name, buf); - } - } - regfree(®ex); - for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++){ - free(sdk_sync_permit_rule[i].regx); - } - return 0; -} void file_sync_service(int fd, void *cookie) { @@ -684,7 +622,7 @@ void file_sync_service(int fd, void *cookie) D("sync: '%s' '%s'\n", (char*) &msg.req, name); - if (should_drop_privileges() && !verify_sync_rule(name)) { + if (should_drop_privileges()) { set_sdk_user_privileges(); } -- 2.7.4 From 7038519e1a244ae6d26ac00ec520b211ad62e085 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Wed, 25 May 2016 13:18:15 +0900 Subject: [PATCH 08/16] Fixed SVACE issue. - Invalid function definition. Change-Id: I9b3367185add114459359d25422985ab9599d4c7 Signed-off-by: Kim Gunsoo --- src/sdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sdb.c b/src/sdb.c index 4f9040b..4c3009f 100644 --- a/src/sdb.c +++ b/src/sdb.c @@ -2120,7 +2120,7 @@ static int is_support_sockproto() } #define EMULATOR_MODEL_NAME "Emulator" -static check_emulator_or_device() +static void check_emulator_or_device() { char model_name[256]={0,}; int ret = -1; -- 2.7.4 From ff03cf6d6131893619b03875c15b5039901dcd32 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Thu, 26 May 2016 17:11:31 +0900 Subject: [PATCH 09/16] Added sdbd service to emulator_preinit.target - Sdbd needs to be booted early for debugging. - Moved the target of sdbd service to emulator_preinit.target from emulator.target Change-Id: I55708052dd8b831684a0a83139935cd14e96af98 Signed-off-by: shingil.kang --- packaging/sdbd.spec | 8 ++++---- packaging/sdbd_emulator.service | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 826c4f0..6a3da0b 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.11 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -59,8 +59,8 @@ mkdir -p %{buildroot}%{_libdir}/systemd/system mkdir -p %{buildroot}%{_unitdir} %ifarch %{ix86} install -m 0644 %SOURCE1002 %{buildroot}%{_libdir}/systemd/system/sdbd.service -mkdir -p %{buildroot}/%{_libdir}/systemd/system/emulator.target.wants -ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/emulator.target.wants/ +mkdir -p %{buildroot}/%{_libdir}/systemd/system/emulator_preinit.target.wants +ln -s %{_libdir}/systemd/system/sdbd.service %{buildroot}/%{_libdir}/systemd/system/emulator_preinit.target.wants/ %else install -m 0644 %SOURCE1001 %{buildroot}%{_unitdir}/sdbd.service install -m 0644 %SOURCE1004 %{buildroot}%{_unitdir}/sdbd_tcp.service @@ -94,7 +94,7 @@ fi %attr(0755, root, root) %{_sysconfdir}/init.d/sdbd %{_unitdir}/sdbd.service %ifarch %{ix86} -%{_libdir}/systemd/system/emulator.target.wants/sdbd.service +%{_libdir}/systemd/system/emulator_preinit.target.wants/sdbd.service %else %{_unitdir}/sdbd_tcp.service %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 1a2f298..3db25cf 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -14,5 +14,5 @@ SmackProcessLabel=User ExecStart=/bin/sh -c "/usr/sbin/sdbd `/usr/bin/awk '{match($0, /sdb_port=([0-9]+)/,port_match); match($0, /vm_name=([^, ]*)/,vm_match); print \"--emulator=\" vm_match[1] \":\" port_match[1] \" --connect-to=10.0.2.2:26099\" \" --sensors=10.0.2.2:\"port_match[1]+3 }' /proc/cmdline`" [Install] -WantedBy=emulator.target +WantedBy=emulator_preinit.target -- 2.7.4 From 935e0b600c01ef6c81e22053453fe32e2c53995c Mon Sep 17 00:00:00 2001 From: Taeyoung Kim Date: Thu, 26 May 2016 14:27:32 +0900 Subject: [PATCH 10/16] sdb: change group and owner of sdb device node - The owner and group of sdbd are changed from "root "to "sdk". Thus the udev rule is changed for it. - Previous: bash-3.2# ls -alZ /dev/samsung_sdb crw------- 1 root root * 10, 15 Jan 1 23:41 /dev/samsung_sdb bash-3.2# - Now: bash-3.2# ls -alZ /dev/samsung_sdb crw-rw---- 1 sdk sdk * 10, 15 Jan 2 04:09 /dev/samsung_sdb bash-3.2# Change-Id: Ifef41987d391bc544cd8792fc21458624306ce29 Signed-off-by: Taeyoung Kim --- packaging/sdbd.spec | 8 +++++++- rules/99-sdbd.rules | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 rules/99-sdbd.rules diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 6a3da0b..22f6be6 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.12 +Version: 3.0.13 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -74,6 +74,11 @@ install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/ mkdir -p %{buildroot}%{TZ_SYS_BIN} install -m 755 script/profile_command %{buildroot}%{TZ_SYS_BIN}/ +%ifnarch %{ix86} +mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d/ +install -m 644 rules/99-sdbd.rules %{buildroot}%{_prefix}/lib/udev/rules.d/ +%endif + %post . %{_sysconfdir}/tizen-platform.conf if ! getent passwd "${TZ_SDK_USER_NAME}" > /dev/null; then @@ -98,6 +103,7 @@ fi %else %{_unitdir}/sdbd_tcp.service %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service +%{_prefix}/lib/udev/rules.d/99-sdbd.rules %endif /usr/share/license/%{name} %{TZ_SYS_BIN}/profile_command diff --git a/rules/99-sdbd.rules b/rules/99-sdbd.rules new file mode 100644 index 0000000..c441d87 --- /dev/null +++ b/rules/99-sdbd.rules @@ -0,0 +1 @@ +KERNEL=="samsung_sdb", OWNER="sdk", GROUP="sdk", SECLABEL{smack}="*" -- 2.7.4 From 45bfe8e57fd16c8bc2ad8073afeb3a842c3eb810 Mon Sep 17 00:00:00 2001 From: Sangjin Kim Date: Tue, 31 May 2016 01:40:09 -0700 Subject: [PATCH 11/16] Revert "sdb: change group and owner of sdb device node" This reverts commit 935e0b600c01ef6c81e22053453fe32e2c53995c. Change-Id: I4d6b1fcf839d8b4e222a1c50f2267bb03b7f8e23 --- packaging/sdbd.spec | 8 +------- rules/99-sdbd.rules | 1 - 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 rules/99-sdbd.rules diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 22f6be6..6a3da0b 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.13 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon @@ -74,11 +74,6 @@ install -m 755 script/sdk_launch %{buildroot}%{_prefix}/sbin/ mkdir -p %{buildroot}%{TZ_SYS_BIN} install -m 755 script/profile_command %{buildroot}%{TZ_SYS_BIN}/ -%ifnarch %{ix86} -mkdir -p %{buildroot}%{_prefix}/lib/udev/rules.d/ -install -m 644 rules/99-sdbd.rules %{buildroot}%{_prefix}/lib/udev/rules.d/ -%endif - %post . %{_sysconfdir}/tizen-platform.conf if ! getent passwd "${TZ_SDK_USER_NAME}" > /dev/null; then @@ -103,7 +98,6 @@ fi %else %{_unitdir}/sdbd_tcp.service %{_libdir}/systemd/system/multi-user.target.wants/sdbd.service -%{_prefix}/lib/udev/rules.d/99-sdbd.rules %endif /usr/share/license/%{name} %{TZ_SYS_BIN}/profile_command diff --git a/rules/99-sdbd.rules b/rules/99-sdbd.rules deleted file mode 100644 index c441d87..0000000 --- a/rules/99-sdbd.rules +++ /dev/null @@ -1 +0,0 @@ -KERNEL=="samsung_sdb", OWNER="sdk", GROUP="sdk", SECLABEL{smack}="*" -- 2.7.4 From 9395230cf70cc07bfd036f8aa374f5f9443c7983 Mon Sep 17 00:00:00 2001 From: Sangjin Kim Date: Tue, 31 May 2016 01:39:53 -0700 Subject: [PATCH 12/16] Revert "Modify modules that need root permission." This reverts commit c0cc4c69e65107bb2b0f955c2589ca53551c6940. Change-Id: I669f55ba15c9757ef34e5c041b85585633d3a0e8 --- packaging/sdbd.spec | 2 +- packaging/sdbd_device.service | 2 -- packaging/sdbd_emulator.service | 2 -- src/file_sync_service.c | 64 ++++++++++++++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 6a3da0b..7bde2d9 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.12 +Version: 3.0.11 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_device.service b/packaging/sdbd_device.service index 5aaac68..4fe803f 100644 --- a/packaging/sdbd_device.service +++ b/packaging/sdbd_device.service @@ -4,8 +4,6 @@ Requires=tizen-system-env.service After=tmp.mount [Service] -User=sdk -Group=sdk Type=forking EnvironmentFile=-/run/tizen-system-env PIDFile=/tmp/.sdbd.pid diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 995d546..3db25cf 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -5,8 +5,6 @@ After=tmp.mount dbus.service #DefaultDependencies=false [Service] -User=sdk -Group=sdk Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid diff --git a/src/file_sync_service.c b/src/file_sync_service.c index c15ae10..5fc6642 100644 --- a/src/file_sync_service.c +++ b/src/file_sync_service.c @@ -39,11 +39,42 @@ #define SYNC_TIMEOUT 15 +struct sync_permit_rule +{ + const char *name; + char *regx; + int mode; // 0:push, 1: pull, 2: push&push +}; + +struct sync_permit_rule sdk_sync_permit_rule[] = { + /* 0 */ {"unitest", "", 1}, + /* 1 */ {"codecoverage", "", 1}, + /* 2 */ {"da", "", 1}, + /* end */ {NULL, NULL, 0} +}; + /* The typical default value for the umask is S_IWGRP | S_IWOTH (octal 022). * Before use the DIR_PERMISSION, the process umask value should be set 0 using umask(). */ #define DIR_PERMISSION 0777 +void init_sdk_sync_permit_rule_regx(void) +{ + int ret; + ret = asprintf(&sdk_sync_permit_rule[0].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/[a-zA-Z0-9_\\-]{1,50}\\.xml$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); + if(ret < 0) { + D("failed to run asprintf for unittest\n"); + } + ret = asprintf(&sdk_sync_permit_rule[1].regx, "^((/tmp)|(%s)|(%s))/[a-zA-Z0-9]{10}/data/+(.)*\\.gcda$", APP_INSTALL_PATH_PREFIX1, APP_INSTALL_PATH_PREFIX2); + if (ret < 0) { + D("failed to run asprintf for codecoverage\n"); + } + ret = asprintf(&sdk_sync_permit_rule[2].regx, "^(/tmp/da/)*+[a-zA-Z0-9_\\-\\.]{1,50}\\.png$"); + if (ret < 0) { + D("failed to run asprintf for da\n"); + } +} + static void set_syncfile_smack_label(char *src) { char *label_transmuted = NULL; char *label = NULL; @@ -558,6 +589,37 @@ static int do_recv(int s, const char *path, char *buffer) return 0; } +static int verify_sync_rule(const char* path) { + regex_t regex; + int ret; + char buf[PATH_MAX]; + int i=0; + + init_sdk_sync_permit_rule_regx(); + for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++) { + ret = regcomp(®ex, sdk_sync_permit_rule[i].regx, REG_EXTENDED); + if(ret){ + return 0; + } + // execute regular expression + ret = regexec(®ex, path, 0, NULL, 0); + if(!ret){ + regfree(®ex); + D("found matched rule(%s) from %s path\n", sdk_sync_permit_rule[i].name, path); + return 1; + } else if( ret == REG_NOMATCH ){ + // do nothin + } else{ + regerror(ret, ®ex, buf, sizeof(buf)); + D("regex match failed(%s): %s\n",sdk_sync_permit_rule[i].name, buf); + } + } + regfree(®ex); + for (i=0; sdk_sync_permit_rule[i].regx != NULL; i++){ + free(sdk_sync_permit_rule[i].regx); + } + return 0; +} void file_sync_service(int fd, void *cookie) { @@ -622,7 +684,7 @@ void file_sync_service(int fd, void *cookie) D("sync: '%s' '%s'\n", (char*) &msg.req, name); - if (should_drop_privileges()) { + if (should_drop_privileges() && !verify_sync_rule(name)) { set_sdk_user_privileges(); } -- 2.7.4 From 33654ea3464ae548f366eefe9de4f08df304e34d Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 7 Jun 2016 18:08:36 +0900 Subject: [PATCH 13/16] Get the path where crash file is generated by using TZ_SYS_CRASH environment variable. Change-Id: I954a722b617b90ed8741b6080ed7fa1d20365ee0 Signed-off-by: shingil.kang --- src/services.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/services.c b/src/services.c index dc19c14..2672394 100644 --- a/src/services.c +++ b/src/services.c @@ -264,7 +264,7 @@ void reboot_service(int fd, void *arg) #if !SDB_HOST #define EVENT_SIZE ( sizeof (struct inotify_event) ) #define BUF_LEN ( 1024 * ( EVENT_SIZE + 16 ) ) -#define CS_PATH tzplatform_mkpath(TZ_USER_SHARE,"crash/report") +#define CS_PATH tzplatform_getenv(TZ_SYS_CRASH) void inoti_service(int fd, void *arg) { @@ -281,6 +281,12 @@ void inoti_service(int fd, void *arg) } wd = inotify_add_watch( ifd, CS_PATH, IN_CREATE); + if ( wd < 0 ) { + D("inotify_add_watch failed (errno :%d)\n", errno); + sdb_close(ifd); + sdb_close(fd); + return; + } for ( ; ; ) { int length, i = 0; -- 2.7.4 From 2146e6e0df3f4a1d46115653a4eed2313c3a693b Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Tue, 7 Jun 2016 18:16:57 +0900 Subject: [PATCH 14/16] Added the new protocol to get the value of environment variable. - 'env:{environment_variable}' prototol is used to get the value of {environment_variable} Change-Id: Ie96c2318665c45950c7c17d156da378b62b1ea1e Signed-off-by: shingil.kang --- src/services.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/services.c b/src/services.c index 2672394..94558c6 100644 --- a/src/services.c +++ b/src/services.c @@ -219,6 +219,23 @@ void rootshell_service(int fd, void *cookie) sdb_close(fd); } +void get_tzplatform_env(int fd, void *cookie) { + char buf[PATH_MAX] = { 0, }; + char *env_name = (char*) cookie; + D("environment variable name: %s\n", env_name); + enum tzplatform_variable env_id = tzplatform_getid(env_name); + if (env_id != _TZPLATFORM_VARIABLES_INVALID_) { + char *env_value = tzplatform_getenv(env_id); + if (env_value) { + D("environment value : %s\n", env_value); + snprintf(buf, sizeof(buf), env_value); + writex(fd, buf, strlen(buf)); + } + } + free(env_name); + sdb_close(fd); +} + void restart_usb_service(int fd, void *cookie) { char buf[100]; @@ -1082,6 +1099,10 @@ int service_to_fd(const char *name) if(!strncmp(name+10, "syncwinsz:", 10)){ ret = create_service_thread(sync_windowsize, (void *)name+20); } + } else if(!strncmp(name, "tzplatformenv:", 14)) { + char* env_variable = NULL; + env_variable = strdup(name+14); + ret = create_service_thread(get_tzplatform_env, (void *)(env_variable)); } if (ret >= 0) { -- 2.7.4 From e6f8c1ddc5d7d940e89f69860f3015304e60b769 Mon Sep 17 00:00:00 2001 From: "shingil.kang" Date: Fri, 10 Jun 2016 14:58:36 +0900 Subject: [PATCH 15/16] Returns error code when it fails to get the value of tzplatform envrionment variable. - return 0 when succeeded - return 1 when error is occured while getting the value of tzplatform environment variable. - return 2 when tzplatform environment variable is not valid. Change-Id: Ie4530148c43d757f69a3e8457777cbf25cb4dc3d Signed-off-by: shingil.kang --- src/services.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/services.c b/src/services.c index 94558c6..a1c0008 100644 --- a/src/services.c +++ b/src/services.c @@ -219,6 +219,12 @@ void rootshell_service(int fd, void *cookie) sdb_close(fd); } +enum tzplatform_get_env_error_status { + NO_ERROR_TZPLATFORM_ENV = 0, + ERROR_TZPLATFORM_ENV_GENERAL = 1, + ERROR_TZPLATFORM_ENV_INVALID_VARIABLES = 2, +}; + void get_tzplatform_env(int fd, void *cookie) { char buf[PATH_MAX] = { 0, }; char *env_name = (char*) cookie; @@ -228,10 +234,16 @@ void get_tzplatform_env(int fd, void *cookie) { char *env_value = tzplatform_getenv(env_id); if (env_value) { D("environment value : %s\n", env_value); - snprintf(buf, sizeof(buf), env_value); - writex(fd, buf, strlen(buf)); + snprintf(buf, sizeof(buf), "%d%s", NO_ERROR_TZPLATFORM_ENV, env_value); + } else { + D("failed to get environment value using tzplatform_getenv"); + snprintf(buf, sizeof(buf), "%d", ERROR_TZPLATFORM_ENV_GENERAL); } + } else { + D("environment name (%s) is invalid\n", env_name); + snprintf(buf, sizeof(buf), "%d", ERROR_TZPLATFORM_ENV_INVALID_VARIABLES); } + writex(fd, buf, strlen(buf)); free(env_name); sdb_close(fd); } -- 2.7.4 From 2622cb18c0871fd97c8235d308362fe4b97b05d4 Mon Sep 17 00:00:00 2001 From: Kim Gunsoo Date: Mon, 13 Jun 2016 18:04:58 +0900 Subject: [PATCH 16/16] Remove unnecessary smack label for running sdbd. - The label(User) of the running sdbd no longer needed. Change-Id: I6b4918d332e73d6db71a584c6a1d37906b8f6a8d Signed-off-by: Kim Gunsoo --- packaging/sdbd.spec | 2 +- packaging/sdbd_emulator.service | 1 - packaging/sdbd_tcp.service | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/packaging/sdbd.spec b/packaging/sdbd.spec index 7bde2d9..6a3da0b 100644 --- a/packaging/sdbd.spec +++ b/packaging/sdbd.spec @@ -2,7 +2,7 @@ Name: sdbd Summary: SDB daemon -Version: 3.0.11 +Version: 3.0.12 Release: 0 License: Apache-2.0 Summary: SDB daemon diff --git a/packaging/sdbd_emulator.service b/packaging/sdbd_emulator.service index 3db25cf..b477d5a 100644 --- a/packaging/sdbd_emulator.service +++ b/packaging/sdbd_emulator.service @@ -9,7 +9,6 @@ Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid RemainAfterExit=yes -SmackProcessLabel=User #ExecStartPre=/bin/bash -c "/bin/echo '10.0.2.15/32 system::debugging_network' >> /smack/netlabel" ExecStart=/bin/sh -c "/usr/sbin/sdbd `/usr/bin/awk '{match($0, /sdb_port=([0-9]+)/,port_match); match($0, /vm_name=([^, ]*)/,vm_match); print \"--emulator=\" vm_match[1] \":\" port_match[1] \" --connect-to=10.0.2.2:26099\" \" --sensors=10.0.2.2:\"port_match[1]+3 }' /proc/cmdline`" diff --git a/packaging/sdbd_tcp.service b/packaging/sdbd_tcp.service index 4ded27c..46b4266 100644 --- a/packaging/sdbd_tcp.service +++ b/packaging/sdbd_tcp.service @@ -7,5 +7,4 @@ Type=forking Environment=DISPLAY=:0 PIDFile=/tmp/.sdbd.pid RemainAfterExit=yes -SmackProcessLabel=User ExecStart=/usr/sbin/sdbd --listen-port=26101 -- 2.7.4