Skip to content

Commit

Permalink
make sftp-server portable
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Sep 21, 2023
1 parent 96f7e40 commit 73cac55
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
21 changes: 11 additions & 10 deletions tools/build-binaries.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
set -e -x

NDK_PATH="${NDK_PATH:-/opt/ndk}"
BUILD_ROOT="${BUILD_ROOT:-/tmp/dropbear-build}"
SRC_ROOT="${SRC_ROOT:-$(realpath -e -s -- "$(dirname -- "${0}")/..")}"
PATCH_DIR="${PATCH_DIR:-${SRC_ROOT}/tools/patches}"
TARGET_DIR="${TARGET_DIR:-${SRC_ROOT}/services/bin}"
Expand All @@ -25,7 +26,7 @@ install_ndk() {
# Download and checksum a src
download() {
local src="/tmp/${1}.tar.gz"
local srcdir="/opt/${1}-src"
local srcdir="${BUILD_ROOT}/${1}-src"
rm -r -f -- "${srcdir}"
mkdir -p -- "${srcdir}"
wget -O "${src}" -- "${2}"
Expand All @@ -35,31 +36,31 @@ download() {
}

build_dropbear() {
cd /opt/dropbear-src
cd "${BUILD_ROOT}/dropbear-src"
patch -N -p 1 -i "${PATCH_DIR}/dropbear-2022.83-dynamic_crypt-v1.patch"
cp -v -- "${PATCH_DIR}/dropbear-localoptions.h" localoptions.h
./configure --host arm-webos-linux-gnueabi --disable-lastlog --enable-dynamic-crypt
./configure ${CONFIGURE_FLAGS} --disable-lastlog --enable-dynamic-crypt
local programs='dropbear scp'
make ${MAKEOPTS} -- PROGRAMS="${programs}"
arm-webos-linux-gnueabi-strip -- ${programs}
${STRIP} -- ${programs}
cp -v -v -t "${TARGET_DIR}" -- ${programs}
}

build_rsync() {
cd /opt/rsync-src
./configure --host arm-webos-linux-gnueabi \
cd "${BUILD_ROOT}/rsync-src"
./configure ${CONFIGURE_FLAGS} \
--disable-simd --disable-debug --with-included-popt=yes --with-included-zlib=yes \
--disable-lz4 --disable-zstd --disable-xxhash --disable-md2man --disable-acl-support
make ${MAKEOPTS}
arm-webos-linux-gnueabi-strip -- rsync
${STRIP} -- rsync
cp -v -t "${TARGET_DIR}" -- rsync
}

build_sftp() {
cd /opt/openssh-src
./configure --host=arm-webos-linux-gnueabi --without-openssl
cd "${BUILD_ROOT}/openssh-src"
./configure ${CONFIGURE_FLAGS} --without-openssl --without-zlib-version-check
make ${MAKEOPTS} -- sftp-server
arm-webos-linux-gnueabi-strip -- sftp-server
${STRIP} -- sftp-server
cp -v -t "${TARGET_DIR}" -- sftp-server
}

Expand Down
27 changes: 26 additions & 1 deletion tools/patches/dropbear-localoptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,29 @@
#define DEFAULT_PATH "/home/root/.local/bin:/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin:/usr/bin:/bin"
#define DEFAULT_ROOT_PATH "/home/root/.local/bin:/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin:/usr/sbin:/usr/bin:/sbin:/bin"
#define DROPBEAR_SFTPSERVER 1
#define SFTPSERVER_PATH "/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin/sftp-server"

#define SFTPSERVER_PATH_FALLBACK "/media/developer/apps/usr/palm/services/org.webosbrew.hbchannel.service/bin/sftp-server"

#include <string.h>
#include <stdlib.h>

static const char* get_sftp_server_path() {
static char path[4096] = "";
if (path[0] == '\0') {
char* dropbear_path = realpath("/proc/self/exe", path);
char *last_slash;
if (dropbear_path == NULL) {
strncpy(path, SFTPSERVER_PATH_FALLBACK, sizeof(path));
return path;
}
last_slash = strrchr(path, '/');
if (last_slash == NULL) {
strncpy(path, SFTPSERVER_PATH_FALLBACK, sizeof(path));
return path;
}
strcpy(last_slash + 1, "sftp-server");
}
return path;
}

#define SFTPSERVER_PATH get_sftp_server_path()

0 comments on commit 73cac55

Please sign in to comment.