build scp as a separate executable

sigsegv_dump
Greg Alexander 10 years ago
parent 226a02ff38
commit 7f0a8a63c0

@ -1 +1 @@
ndk-build -j8 && ant debug && cat bin/SimpleSSHD-debug.apk | ssh roach 'cat > /sdcard/buh.apk; source .profile; pm install -r /sdcard/buh.apk' ndk-build -j8 && mv libs/armeabi/scp libs/armeabi/libscp.so && ant debug && cat bin/SimpleSSHD-debug.apk | ssh roach 'cat > /sdcard/buh.apk; source .profile; pm install -r /sdcard/buh.apk'

@ -574,29 +574,19 @@ int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
* re-enabled SIGPIPE. If cmd is NULL, will run a login shell. * re-enabled SIGPIPE. If cmd is NULL, will run a login shell.
*/ */
void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell) { void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell) {
char * argv[100]; char * argv[4];
char * baseshell = NULL; char * baseshell = NULL;
unsigned int i; unsigned int i;
/* Re-enable SIGPIPE for the executed process */ baseshell = basename(usershell);
if (signal(SIGPIPE, SIG_DFL) == SIG_ERR) {
dropbear_exit("signal() error");
}
/* close file descriptors except stdin/stdout/stderr
* Need to be sure FDs are closed here to avoid reading files as root */
for (i = 3; i <= maxfd; i++) {
m_close(i);
}
if (cmd && !strncmp(cmd, "scp ", 4)) { if (cmd && !strncmp(cmd, "scp ", 4)) {
int argc = split_cmd(cmd, argv, sizeof argv/sizeof argv[0]); char *t = malloc(strlen(cmd)+strlen(NDK_EXECUTABLES_PATH)+80);
scp_main(argc, argv); sprintf(t, "%s/lib%s.so %s", NDK_EXECUTABLES_PATH, "scp",
exit(0); cmd+4);
cmd = t;
} }
baseshell = basename(usershell);
if (cmd != NULL) { if (cmd != NULL) {
argv[0] = baseshell; argv[0] = baseshell;
} else { } else {
@ -615,6 +605,17 @@ void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell) {
argv[1] = NULL; argv[1] = NULL;
} }
/* Re-enable SIGPIPE for the executed process */
if (signal(SIGPIPE, SIG_DFL) == SIG_ERR) {
dropbear_exit("signal() error");
}
/* close file descriptors except stdin/stdout/stderr
* Need to be sure FDs are closed here to avoid reading files as root */
for (i = 3; i <= maxfd; i++) {
m_close(i);
}
execv(usershell, argv); execv(usershell, argv);
} }

@ -302,7 +302,6 @@ void tolocal(int, char *[]);
void toremote(char *, int, char *[]); void toremote(char *, int, char *[]);
void usage(void); void usage(void);
#if defined(DBMULTI_scp) || !defined(DROPBEAR_MULTI)
#if defined(DBMULTI_scp) && defined(DROPBEAR_MULTI) #if defined(DBMULTI_scp) && defined(DROPBEAR_MULTI)
int scp_main(int argc, char **argv) int scp_main(int argc, char **argv)
#else #else
@ -453,7 +452,6 @@ main(int argc, char **argv)
} }
exit(errs != 0); exit(errs != 0);
} }
#endif /* DBMULTI_scp stuff */
void void
toremote(char *targ, int argc, char **argv) toremote(char *targ, int argc, char **argv)

@ -5,7 +5,7 @@ include $(CLEAR_VARS)
LOCAL_CFLAGS := LOCAL_CFLAGS :=
LOCAL_MODULE := simplesshd-jni LOCAL_MODULE := simplesshd-jni
DROPBEAR_PATH := ../dropbear/ DROPBEAR_PATH := ../dropbear
DROPBEAR_SRCS := $(DROPBEAR_PATH)/atomicio.c \ DROPBEAR_SRCS := $(DROPBEAR_PATH)/atomicio.c \
$(DROPBEAR_PATH)/bignum.c \ $(DROPBEAR_PATH)/bignum.c \
$(DROPBEAR_PATH)/buffer.c \ $(DROPBEAR_PATH)/buffer.c \
@ -449,8 +449,6 @@ DROPBEAR_SRCS := $(DROPBEAR_PATH)/atomicio.c \
$(DROPBEAR_PATH)/progressmeter.c \ $(DROPBEAR_PATH)/progressmeter.c \
$(DROPBEAR_PATH)/queue.c \ $(DROPBEAR_PATH)/queue.c \
$(DROPBEAR_PATH)/rsa.c \ $(DROPBEAR_PATH)/rsa.c \
$(DROPBEAR_PATH)/scp.c \
$(DROPBEAR_PATH)/scpmisc.c \
$(DROPBEAR_PATH)/signkey.c \ $(DROPBEAR_PATH)/signkey.c \
$(DROPBEAR_PATH)/sshpty.c \ $(DROPBEAR_PATH)/sshpty.c \
$(DROPBEAR_PATH)/svr-agentfwd.c \ $(DROPBEAR_PATH)/svr-agentfwd.c \
@ -473,3 +471,20 @@ LOCAL_C_INCLUDES:= dropbear dropbear/libtomcrypt/src/headers dropbear/libtommath
# LOCAL_LDLIBS := # LOCAL_LDLIBS :=
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)
# build separate scp executable
include $(CLEAR_VARS)
LOCAL_CFLAGS :=
LOCAL_MODULE := scp
DROPBEAR_PATH := ../dropbear
LOCAL_SRC_FILES := $(DROPBEAR_PATH)/scp.c \
$(DROPBEAR_PATH)/scpmisc.c \
$(DROPBEAR_PATH)/atomicio.c
LOCAL_C_INCLUDES:= dropbear dropbear/libtomcrypt/src/headers dropbear/libtommath
# LOCAL_LDLIBS :=
include $(BUILD_EXECUTABLE)

@ -19,6 +19,7 @@
#define HAVE_BASENAME 1 #define HAVE_BASENAME 1
#define HAVE_NETINET_TCP_H 1 #define HAVE_NETINET_TCP_H 1
#define HAVE_LIBGEN_H 1
#define USE_DEV_PTMX 1 #define USE_DEV_PTMX 1
#define DISABLE_ZLIB 1 #define DISABLE_ZLIB 1
@ -27,17 +28,16 @@
#define DROPBEAR_SERVER 1 #define DROPBEAR_SERVER 1
#define DBMULTI_dropbear 1 #define DBMULTI_dropbear 1
#define DBMULTI_scp 1
#define DROPBEAR_MULTI 1 #define DROPBEAR_MULTI 1
#define NDK_EXECUTABLES_PATH "/data/data/org.galexander.sshd/lib"
/* in jni/interface.c: */ /* in jni/interface.c: */
extern const char *conf_path; extern const char *conf_path;
extern const char *conf_shell; extern const char *conf_shell;
extern const char *conf_home; extern const char *conf_home;
const char *conf_path_file(const char *fn); const char *conf_path_file(const char *fn);
int split_cmd(const char *in, char **argv, int max_argc);
#endif /* __CONFIG_H__ */ #endif /* __CONFIG_H__ */

@ -54,7 +54,7 @@ jni_init(JNIEnv *env_)
} }
/* split str into argv entries, honoring " and \ (but nothing else) */ /* split str into argv entries, honoring " and \ (but nothing else) */
int static int
split_cmd(const char *in, char **argv, int max_argc) split_cmd(const char *in, char **argv, int max_argc)
{ {
char curr[1000]; char curr[1000];

Loading…
Cancel
Save