Find native lib directory the correct way, using

Context.getApplicationInfo().nativeLibraryDir.
sigsegv_dump
Greg Alexander 5 years ago
parent 7db95c7815
commit 22d7993e23

@ -698,15 +698,12 @@ Anyways, there's a bunch of stuff remaining to do, and then I will
release it.
XXX - find location of native libs (it no longer updates the lib-> symlink!)
XXX - call checkSelfPermission/requestPermission to get WRITE_EXTERNAL_STORAGE (it only works now because it's grandfathered in)
XXX - fix color problem with newest API (override all colors, i think only the STOP/START button remains?)
XXX - upgrade to newest dropbear
XXX - reference lib dir by files dir /../lib, test it by logging in as "Guest"
XXX - figure out what pie does to the boot event receiver
XXX - see if settings looks better with SDK26, if not, hack it so that the ones with strings have their states shown

@ -20,6 +20,7 @@ public class SimpleSSHDService extends Service {
private static long sshd_when = 0;
private static long sshd_duration = 0;
private static boolean foregrounded = false;
private static String libdir = null;
public void onCreate() {
super.onCreate();
@ -32,6 +33,7 @@ public class SimpleSSHDService extends Service {
}
public int onStartCommand(Intent intent, int flags, int startId) {
libdir = getApplicationInfo().nativeLibraryDir;
if ((intent == null) ||
(!intent.getBooleanExtra("stop", false))) {
do_start();
@ -130,7 +132,7 @@ public class SimpleSSHDService extends Service {
Prefs.get_path(), Prefs.get_shell(),
Prefs.get_home(), Prefs.get_extra(),
(Prefs.get_rsyncbuffer() ? 1 : 0),
Prefs.get_env());
Prefs.get_env(), libdir);
long now = System.currentTimeMillis();
if (pid != 0) {
@ -179,7 +181,7 @@ public class SimpleSSHDService extends Service {
private static native int start_sshd(int port, String path,
String shell, String home, String extra,
int rsyncbuffer, String env);
int rsyncbuffer, String env, String lib);
private static native void kill(int pid);
private static native int waitpid(int pid);
static {

@ -613,6 +613,8 @@ install_environment(void)
m_free(v);
}
}
setenv("SSHD_LIBDIR", conf_lib, /*overwrite=*/1);
}
@ -627,18 +629,16 @@ void run_shell_command(const char* cmd, unsigned int maxfd, char* usershell) {
baseshell = basename(usershell);
if (cmd && !strncmp(cmd, "scp ", 4)) {
char *t = m_malloc(strlen(cmd)+strlen(NDK_EXECUTABLES_PATH)+80);
sprintf(t, "%s/lib%s.so %s", NDK_EXECUTABLES_PATH, "scp",
cmd+4);
char *t = m_malloc(strlen(cmd)+strlen(conf_lib)+80);
sprintf(t, "%s/lib%s.so %s", conf_lib, "scp", cmd+4);
cmd = t;
} else if (cmd && !strncmp(cmd, "rsync ", 6)) {
char *t = m_malloc(strlen(cmd)+strlen(NDK_EXECUTABLES_PATH)+80);
char *t = m_malloc(strlen(cmd)+strlen(conf_lib)+80);
char *x = "rsync";
if (conf_rsyncbuffer) {
x = "buffersu";
}
sprintf(t, "%s/lib%s.so %s", NDK_EXECUTABLES_PATH, x,
cmd+6);
sprintf(t, "%s/lib%s.so %s", conf_lib, x, cmd+6);
cmd = t;
}

@ -263,7 +263,7 @@ much traffic. */
* "-q" for quiet */
#undef XAUTH_COMMAND
#define SFTPSERVER_PATH NDK_EXECUTABLES_PATH "/libsftp-server.so"
#define SFTPSERVER_PATH "%s/libsftp-server.so" /*, conf_lib */
/* This is used by the scp binary when used as a client binary. If you're
* not using the Dropbear client, you'll need to change it */

@ -663,7 +663,8 @@ static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
#ifdef SFTPSERVER_PATH
if ((cmdlen == 4) && strncmp(chansess->cmd, "sftp", 4) == 0) {
m_free(chansess->cmd);
chansess->cmd = m_strdup(SFTPSERVER_PATH);
chansess->cmd = m_malloc(strlen(SFTPSERVER_PATH) + strlen(conf_lib) + 2);
sprintf(chansess->cmd, SFTPSERVER_PATH, conf_lib);
} else
#endif
{

@ -7,7 +7,7 @@
#include <fcntl.h>
#include <sys/wait.h>
#define WRAPPED_CMD "/data/data/org.galexander.sshd/lib/librsync.so"
#define WRAPPED_CMD "%s/librsync.so"
#define WRAPPED_ARG0 "rsync"
#define MAX_BUFSZ (1024*1024)
@ -133,10 +133,18 @@ buf_write(struct buf *b, int fd)
int
main(int argc, char **argv)
{
char *libdir;
char *wrapped_cmd;
int p0[2], p1[2];
pid_t pid;
pipe(p0);
pipe(p1);
libdir = getenv("SSHD_LIBDIR");
if (!libdir) { libdir = "SSHD_LIBDIR_not_set"; }
wrapped_cmd = malloc(strlen(libdir) + strlen(WRAPPED_CMD) + 2);
sprintf(wrapped_cmd, WRAPPED_CMD, libdir);
if ((pid=fork())) {
/* parent */
fd_set ifds, ofds;
@ -225,7 +233,7 @@ T(ofd)
memcpy(child_argv, argv, argc*sizeof *child_argv);
child_argv[0] = WRAPPED_ARG0;
child_argv[argc] = NULL;
execv(WRAPPED_CMD, child_argv);
execv(wrapped_cmd, child_argv);
perror("execv");
return -1;
}

@ -32,8 +32,6 @@
#define DBMULTI_dropbear 1
#define DROPBEAR_MULTI 1
#define NDK_EXECUTABLES_PATH "/data/data/org.galexander.sshd/lib"
/* in jni/interface.c: */
extern const char *conf_path;
@ -42,6 +40,7 @@ extern const char *conf_home;
const char *conf_path_file(const char *fn);
extern int conf_rsyncbuffer;
extern const char *conf_env;
extern const char *conf_lib;
#endif /* __CONFIG_H__ */

@ -9,7 +9,8 @@
#include <fcntl.h>
#include <ctype.h>
const char *conf_path = "", *conf_shell = "", *conf_home = "", *conf_env = "";
const char *conf_path = "", *conf_shell = "", *conf_home = "", *conf_env = "",
*conf_lib = "";
int conf_rsyncbuffer = 0;
/* NB - this will leak memory like crazy if called often.... */
@ -103,6 +104,9 @@ static const char *
from_java_string(jobject s)
{
const char *ret, *t;
if (!s) {
return "";
}
t = (*env)->GetStringUTFChars(env, s, NULL);
if (!t) {
return "";
@ -116,7 +120,7 @@ JNIEXPORT jint JNICALL
Java_org_galexander_sshd_SimpleSSHDService_start_1sshd(JNIEnv *env_,
jclass cl,
jint port, jobject jpath, jobject jshell, jobject jhome, jobject jextra,
jint rsyncbuffer, jobject jenv)
jint rsyncbuffer, jobject jenv, jobject jlib)
{
pid_t pid;
const char *extra;
@ -130,6 +134,7 @@ Java_org_galexander_sshd_SimpleSSHDService_start_1sshd(JNIEnv *env_,
extra = from_java_string(jextra);
conf_rsyncbuffer = rsyncbuffer;
conf_env = from_java_string(jenv);
conf_lib = from_java_string(jlib);
pid = fork();
if (pid == 0) {

Loading…
Cancel
Save