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

Enable SSH server for pocketbook devices #1559

Merged
merged 1 commit into from
Dec 4, 2022
Merged
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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ all: $(OUTPUT_DIR)/libs $(if $(ANDROID),,$(LUAJIT)) \
$(if $(WIN32),,$(OUTPUT_DIR)/sdcv) \
$(if $(MACOS),$(OUTPUT_DIR)/koreader,) \
$(if $(MACOS),$(SDL2_LIB),) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/dropbear,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/sftp-server,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK)),$(OUTPUT_DIR)/dropbear,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK)),$(OUTPUT_DIR)/sftp-server,) \
$(if $(or $(ANDROID),$(DARWIN),$(WIN32)),,$(OUTPUT_DIR)/tar) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK),$(REMARKABLE)),$(OUTPUT_DIR)/fbink,) \
$(if $(KOBO),$(OUTPUT_DIR)/data/KoboUSBMS.tar.gz,) \
Expand All @@ -44,8 +44,8 @@ ifeq ($(DO_STRIP),1)
STRIP_FILES="\
$(if $(WIN32),,$(OUTPUT_DIR)/sdcv) \
$(if $(or $(ANDROID),$(DARWIN),$(WIN32)),,$(OUTPUT_DIR)/tar) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/dropbear,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO)),$(OUTPUT_DIR)/sftp-server,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK)),$(OUTPUT_DIR)/dropbear,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK)),$(OUTPUT_DIR)/sftp-server,) \
$(if $(or $(KINDLE),$(KOBO)),$(OUTPUT_DIR)/scp,) \
$(if $(or $(CERVANTES),$(KINDLE),$(KOBO),$(POCKETBOOK),$(REMARKABLE)),$(OUTPUT_DIR)/fbink,) \
$(if $(REMARKABLE),$(OUTPUT_DIR)/button-listen,) \
Expand Down
2 changes: 2 additions & 0 deletions thirdparty/dropbear/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ elseif($ENV{KINDLE})
set(PATCH_CMD7 "${KO_PATCH} ${CMAKE_CURRENT_SOURCE_DIR}/dropbear-2018.76-scp-command-hack-kindle.patch")
elseif($ENV{CERVANTES})
set(PATCH_CMD7 "${KO_PATCH} ${CMAKE_CURRENT_SOURCE_DIR}/dropbear-2018.76-scp-command-hack-cervantes.patch")
elseif($ENV{POCKETBOOK})
set(PATCH_CMD7 "${KO_PATCH} ${CMAKE_CURRENT_SOURCE_DIR}/dropbear-2018.76-scp-command-hack-pocketbook.patch")
endif()
set(PATCH_CMD8 sh -c "autoreconf -fi")

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
diff --git a/default_options.h b/default_options.h
index 7d28085..c1a14ef 100644
--- a/default_options.h
+++ b/default_options.h
@@ -13,7 +13,7 @@ Options can also be defined with -DDROPBEAR_XXX=[0,1] in Makefile CFLAGS

IMPORTANT: Some options will require "make clean" after changes */

-#define DROPBEAR_DEFPORT "22"
+#define DROPBEAR_DEFPORT "2222"

/* Listen on all interfaces */
#define DROPBEAR_DEFADDRESS ""
@@ -34,7 +34,7 @@ IMPORTANT: Some options will require "make clean" after changes */
* Both of these flags can be defined at once, don't compile without at least
* one of them. */
#define NON_INETD_MODE 1
-#define INETD_MODE 1
+#define INETD_MODE 0

/* Include verbose debug output, enabled with -v at runtime.
* This will add a reasonable amount to your executable size. */
@@ -250,7 +250,10 @@ Homedir is prepended unless path begins with / */
* OpenSSH), set the path below and set DROPBEAR_SFTPSERVER.
* The sftp-server program is not provided by Dropbear itself */
#define DROPBEAR_SFTPSERVER 1
-#define SFTPSERVER_PATH "/usr/libexec/sftp-server"
+#define SFTPSERVER_PATH "/mnt/ext1/applications/koreader/sftp-server"
+
+// Hack! Absolute path, no trailing slash...
+#define DBSCP_PATH "/mnt/ext1/applications/koreader"

/* 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 */
@@ -259,6 +262,7 @@ Homedir is prepended unless path begins with / */
/* Whether to log commands executed by a client. This only logs the
* (single) command sent to the server, not what a user did in a
* shell/sftp session etc. */
+// NOTE: Consider setting this to 1 to debug our crazy scp/sftp hack...
#define LOG_COMMANDS 0

/* Window size limits. These tend to be a trade-off between memory
diff --git a/svr-chansession.c b/svr-chansession.c
index faf62e5..08f3ca3 100644
--- a/svr-chansession.c
+++ b/svr-chansession.c
@@ -661,6 +661,15 @@ static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
/* TODO - send error - too long ? */
return DROPBEAR_FAILURE;
}
+
+ // HACK. This is terrible. Truly, truly awful.
+ if (strncmp(chansess->cmd, "scp", 3) == 0) {
+ char* mangled_cmd = m_malloc(cmdlen + sizeof(DBSCP_PATH));
+ snprintf(mangled_cmd, cmdlen + sizeof(DBSCP_PATH) + 1, "%s/%s", DBSCP_PATH, chansess->cmd);
+ m_free(chansess->cmd);
+ chansess->cmd = m_strdup(mangled_cmd);
+ m_free(mangled_cmd);
+ }
}
if (issubsys) {
#if DROPBEAR_SFTPSERVER