Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make sftp-server portable #153

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(dropbear_path, '/');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use dirname()?

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()