* limitations under the License.
*/
-#include <stdlib.h>
#include <stdio.h>
+#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include "sysdeps.h"
#define TRACE_TAG TRACE_SERVICES
+#include "log.h"
+
#include "sdb.h"
#include "file_sync_service.h"
#include <termios.h>
#include <sys/ioctl.h>
+#include "sdbd_plugin.h"
+#include "plugin.h"
+
typedef struct stinfo stinfo;
struct stinfo {
static int is_support_interactive_shell()
{
- return (!strncmp(g_capabilities.intershell_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+ return (!strncmp(g_capabilities.intershell_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
}
#if 0
static int is_support_rootonoff()
{
- return (!strncmp(g_capabilities.rootonoff_support, SDBD_CAP_RET_ENABLED, strlen(SDBD_CAP_RET_ENABLED)));
+ return (!strncmp(g_capabilities.rootonoff_support, PLUGIN_RET_ENABLED, strlen(PLUGIN_RET_ENABLED)));
}
void rootshell_service(int fd, void *cookie)
if ( ifd < 0 ) {
D( "inotify_init failed\n");
+ sdb_close(fd);
return;
}
execve(cmd, argv, envp);
}
-static int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], char * const envp[])
+int create_subprocess(const char *cmd, pid_t *pid, char * const argv[], char * const envp[])
{
char devname[64];
int ptm;
}
if (should_drop_privileges()) {
- if (argv[2] != NULL && getuid() == 0 && request_plugin_verification(SDBD_CMD_VERIFY_ROOTCMD, argv[2])) {
+ if (argv[2] != NULL && getuid() == 0 && request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_ROOTCMD, argv[2])) {
// do nothing
D("sdb: executes root commands!!:%s\n", argv[2]);
} else {
- set_sdk_user_privileges();
+ if (getuid() != g_sdk_user_id && set_sdk_user_privileges() < 0) {
+ fprintf(stderr, "failed to set SDK user privileges\n");
+ exit(-1);
+ }
}
}
redirect_and_exec(pts, cmd, argv, envp);
}
#endif /* !SDB_HOST */
-#define SHELL_COMMAND "/bin/sh"
#define LOGIN_COMMAND "/bin/login"
#define SUPER_USER "root"
#define LOGIN_CONFIG "/etc/login.defs"
}
}
-static void get_env(char *key, char **env)
+void get_env(char *key, char **env)
{
FILE *fp;
char buf[1024];
e = buf + (strlen(buf) - 1);
// trim string
- while(*e == ' ' || *e == '\n' || *e == '\t') {
+ while( (e > s) && (*e == ' ' || *e == '\n' || *e == '\t')) {
e--;
}
*(e+1) ='\0';
char *value = NULL;
char *trim_value = NULL;
char path[PATH_MAX];
- memset(path, 0, sizeof(path));
char *envp[MAX_TOKENS];
int envp_cnt = 0;
+
+ memset(path, 0, sizeof(path));
+ memset(envp, 0, sizeof(envp));
+
envp[envp_cnt++] = strdup("TERM=linux");
envp[envp_cnt++] = strdup("DISPLAY=:0");
}
free(envp_plugin);
+ /* Last element of envp must be the NULL-terminator to prevent execvp fail */
+ envp[envp_cnt] = NULL;
+
if(name) { // in case of shell execution directly
// Check the shell command validation.
- if (!request_plugin_verification(SDBD_CMD_VERIFY_SHELLCMD, name)) {
+ if (!request_validity_to_plugin(PLUGIN_SYNC_CMD_VERIFY_SHELLCMD, name)) {
D("This shell command is invalid. (%s)\n", name);
return -1;
}
}
memset(new_cmd, 0, SDBD_SHELL_CMD_MAX);
- if(!request_plugin_cmd(SDBD_CMD_CONV_SHELLCMD, name, new_cmd, SDBD_SHELL_CMD_MAX)) {
+ if(!request_conversion_to_plugin(PLUGIN_SYNC_CMD_CONVERT_SHELLCMD, name, new_cmd, SDBD_SHELL_CMD_MAX)) {
D("Failed to convert the shell command. (%s)\n", name);
free(new_cmd);
return -1;
return ret_fd;
}
-
#endif
static void get_platforminfo(int fd, void *cookie) {
offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
"sockproto_support", g_capabilities.sockproto_support);
+ // Window size synchronization support
+ offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+ "syncwinsz_support", g_capabilities.syncwinsz_support);
+
// Root command support
offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
"rootonoff_support", g_capabilities.rootonoff_support);
offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
"vendor_name", g_capabilities.vendor_name);
+ // Target name of the launch possible
+ offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+ "can_launch", g_capabilities.can_launch);
+
// Platform version
offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
"platform_version", g_capabilities.platform_version);
offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
"sdbd_plugin_version", g_capabilities.sdbd_plugin_version);
- // Window size synchronization support
+ // Capability version
offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
- "syncwinsz_support", g_capabilities.syncwinsz_support);
+ "sdbd_cap_version", g_capabilities.sdbd_cap_version);
// Sdbd log enable
- offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
- "log_enable", g_capabilities.log_enable);
+ offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+ "log_enable", g_capabilities.log_enable);
// Sdbd log path
- offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
- "log_path", g_capabilities.log_path);
+ offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+ "log_path", g_capabilities.log_path);
+
+ // Application command support
+ offset += put_key_value_string(cap_buffer, offset, CAPBUF_SIZE,
+ "appcmd_support", g_capabilities.appcmd_support);
offset++; // for '\0' character
char* env_variable = NULL;
env_variable = strdup(name+14);
ret = create_service_thread(get_tzplatform_env, (void *)(env_variable));
+ } else if(!strncmp(name, "appcmd:", 7)){
+ ret = request_appcmd_to_plugin(name+7);
}
if (ret >= 0) {