summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyo Nakamura <upa@haeena.net>2022-11-05 22:46:02 +0900
committerRyo Nakamura <upa@haeena.net>2022-11-05 22:46:02 +0900
commit243bf1fa5710c0928e4a52ad4c5a0f0e73022554 (patch)
tree41f692ce8c03534e149841de6600dc84ec50e7ee
parent8cb5c81fcfc5a43224c1d2c0eed374d85667a0d8 (diff)
add -H option to disable host key check
tests use this option.
-rw-r--r--README.md9
-rw-r--r--src/main.c8
-rw-r--r--src/ssh.c2
-rw-r--r--src/ssh.h18
-rw-r--r--test/Makefile349
-rw-r--r--test/test_e2e.py20
6 files changed, 381 insertions, 25 deletions
diff --git a/README.md b/README.md
index 7d0545d..9b1bae6 100644
--- a/README.md
+++ b/README.md
@@ -60,10 +60,11 @@ make install
- Usage
```shell-session
-$ mscp -h
-mscp: copy files over multiple ssh connections
+$ mscp
+mscp v0.0.0: copy files over multiple ssh connections
-Usage: mscp [CvqDdh] [-n nr_conns] [-s min_chunk_sz] [-S max_chunk_sz]
+Usage: mscp [vqDCHdh] [-n nr_conns]
+ [-s min_chunk_sz] [-S max_chunk_sz]
[-b sftp_buf_sz] [-B io_buf_sz]
[-l login_name] [-p port] [-i identity_file]
[-c cipher_spec] source ... target
@@ -84,6 +85,7 @@ Usage: mscp [CvqDdh] [-n nr_conns] [-s min_chunk_sz] [-S max_chunk_sz]
-i IDENTITY identity file for publickey authentication
-c CIPHER cipher spec, see `ssh -Q cipher`
-C enable compression on libssh
+ -H disable hostkey check
-d increment ssh debug output level
-h print this help
```
@@ -94,7 +96,6 @@ Usage: mscp [CvqDdh] [-n nr_conns] [-s min_chunk_sz] [-S max_chunk_sz]
```shell-session
$ mscp /tmp/test.img 10.0.0.1:/tmp/
[===============================================================] 100% 8GB/8GB 3.02GB/s
-$
```
- `-v` options increment verbose output level.
diff --git a/src/main.c b/src/main.c
index 4524fd3..ed0b644 100644
--- a/src/main.c
+++ b/src/main.c
@@ -82,7 +82,7 @@ int list_count(struct list_head *head)
void usage(bool print_help) {
printf("mscp v" VERSION ": copy files over multiple ssh connections\n"
"\n"
- "Usage: mscp [CvqDdh] [-n nr_conns]\n"
+ "Usage: mscp [vqDCHdh] [-n nr_conns]\n"
" [-s min_chunk_sz] [-S max_chunk_sz]\n"
" [-b sftp_buf_sz] [-B io_buf_sz]\n"
" [-l login_name] [-p port] [-i identity_file]\n"
@@ -108,6 +108,7 @@ void usage(bool print_help) {
" -i IDENTITY identity file for publickey authentication\n"
" -c CIPHER cipher spec, see `ssh -Q cipher`\n"
" -C enable compression on libssh\n"
+ " -H disable hostkey check\n"
" -d increment ssh debug output level\n"
" -h print this help\n"
"\n");
@@ -178,7 +179,7 @@ int main(int argc, char **argv)
nr_threads = (int)(nr_cpus() / 2);
nr_threads = nr_threads == 0 ? 1 : nr_threads;
- while ((ch = getopt(argc, argv, "n:s:S:b:B:vqDl:p:i:c:Cdh")) != -1) {
+ while ((ch = getopt(argc, argv, "n:s:S:b:B:vqDl:p:i:c:CHdh")) != -1) {
switch (ch) {
case 'n':
nr_threads = atoi(optarg);
@@ -255,6 +256,9 @@ int main(int argc, char **argv)
case 'C':
opts.compress++;
break;
+ case 'H':
+ opts.no_hostkey_check = true;
+ break;
case 'd':
opts.debuglevel++;
break;
diff --git a/src/ssh.c b/src/ssh.c
index c5c53be..9ba7316 100644
--- a/src/ssh.c
+++ b/src/ssh.c
@@ -106,7 +106,7 @@ static ssh_session ssh_make_ssh_session(char *sshdst, struct ssh_opts *opts)
goto disconnect_out;
}
- if (ssh_verify_known_hosts(ssh) != 0) {
+ if (!opts->no_hostkey_check && ssh_verify_known_hosts(ssh) != 0) {
goto disconnect_out;
}
diff --git a/src/ssh.h b/src/ssh.h
index 2dd99f5..413fb6a 100644
--- a/src/ssh.h
+++ b/src/ssh.h
@@ -1,19 +1,21 @@
#ifndef _SSH_H_
#define _SSH_H_
+#include <stdbool.h>
#include <libssh/libssh.h>
#include <libssh/sftp.h>
struct ssh_opts {
- char *login_name; /* -l */
- char *port; /* -p */
- char *identity; /* -i */
- char *cipher; /* -c */
- int compress; /* -C */
- int debuglevel; /* -v */
-
- char *password; /* filled at the first connecting phase */
+ char *login_name; /* -l */
+ char *port; /* -p */
+ char *identity; /* -i */
+ char *cipher; /* -c */
+ int compress; /* -C */
+ int debuglevel; /* -v */
+ bool no_hostkey_check; /* -H */
+
+ char *password; /* filled at the first connecting phase */
};
/* ssh_make_sftp_session() creates sftp_session. sshdst accpets
diff --git a/test/Makefile b/test/Makefile
new file mode 100644
index 0000000..e3a8ee5
--- /dev/null
+++ b/test/Makefile
@@ -0,0 +1,349 @@
+# CMAKE generated file: DO NOT EDIT!
+# Generated by "Unix Makefiles" Generator, CMake Version 3.24
+
+# Default target executed when no arguments are given to make.
+default_target: all
+.PHONY : default_target
+
+# Allow only one "make -f Makefile2" at a time, but pass parallelism.
+.NOTPARALLEL:
+
+#=============================================================================
+# Special targets provided by cmake.
+
+# Disable implicit rules so canonical targets will work.
+.SUFFIXES:
+
+# Disable VCS-based implicit rules.
+% : %,v
+
+# Disable VCS-based implicit rules.
+% : RCS/%
+
+# Disable VCS-based implicit rules.
+% : RCS/%,v
+
+# Disable VCS-based implicit rules.
+% : SCCS/s.%
+
+# Disable VCS-based implicit rules.
+% : s.%
+
+.SUFFIXES: .hpux_make_needs_suffix_list
+
+# Command-line flag to silence nested $(MAKE).
+$(VERBOSE)MAKESILENT = -s
+
+#Suppress display of executed commands.
+$(VERBOSE).SILENT:
+
+# A target that is always out of date.
+cmake_force:
+.PHONY : cmake_force
+
+#=============================================================================
+# Set environment variables for the build.
+
+# The shell in which to execute make rules.
+SHELL = /bin/sh
+
+# The CMake executable.
+CMAKE_COMMAND = /usr/local/Cellar/cmake/3.24.2/bin/cmake
+
+# The command to remove a file.
+RM = /usr/local/Cellar/cmake/3.24.2/bin/cmake -E rm -f
+
+# Escaping for special characters.
+EQUALS = =
+
+# The top-level source directory on which CMake was run.
+CMAKE_SOURCE_DIR = /Users/upa/work/code/mscp
+
+# The top-level build directory on which CMake was run.
+CMAKE_BINARY_DIR = /Users/upa/work/code/mscp/test
+
+#=============================================================================
+# Targets provided globally by CMake.
+
+# Special rule for the target test
+test:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
+ /usr/local/Cellar/cmake/3.24.2/bin/ctest --force-new-ctest-process $(ARGS)
+.PHONY : test
+
+# Special rule for the target test
+test/fast: test
+.PHONY : test/fast
+
+# Special rule for the target edit_cache
+edit_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake cache editor..."
+ /usr/local/Cellar/cmake/3.24.2/bin/ccmake -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : edit_cache
+
+# Special rule for the target edit_cache
+edit_cache/fast: edit_cache
+.PHONY : edit_cache/fast
+
+# Special rule for the target rebuild_cache
+rebuild_cache:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake --regenerate-during-build -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
+.PHONY : rebuild_cache
+
+# Special rule for the target rebuild_cache
+rebuild_cache/fast: rebuild_cache
+.PHONY : rebuild_cache/fast
+
+# Special rule for the target list_install_components
+list_install_components:
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Available install components are: \"Unspecified\""
+.PHONY : list_install_components
+
+# Special rule for the target list_install_components
+list_install_components/fast: list_install_components
+.PHONY : list_install_components/fast
+
+# Special rule for the target install
+install: preinstall
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake -P cmake_install.cmake
+.PHONY : install
+
+# Special rule for the target install
+install/fast: preinstall/fast
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Install the project..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake -P cmake_install.cmake
+.PHONY : install/fast
+
+# Special rule for the target install/local
+install/local: preinstall
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
+.PHONY : install/local
+
+# Special rule for the target install/local
+install/local/fast: preinstall/fast
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing only the local directory..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake -DCMAKE_INSTALL_LOCAL_ONLY=1 -P cmake_install.cmake
+.PHONY : install/local/fast
+
+# Special rule for the target install/strip
+install/strip: preinstall
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
+.PHONY : install/strip
+
+# Special rule for the target install/strip
+install/strip/fast: preinstall/fast
+ @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Installing the project stripped..."
+ /usr/local/Cellar/cmake/3.24.2/bin/cmake -DCMAKE_INSTALL_DO_STRIP=1 -P cmake_install.cmake
+.PHONY : install/strip/fast
+
+# The main all target
+all: cmake_check_build_system
+ $(CMAKE_COMMAND) -E cmake_progress_start /Users/upa/work/code/mscp/test/CMakeFiles /Users/upa/work/code/mscp/test//CMakeFiles/progress.marks
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 all
+ $(CMAKE_COMMAND) -E cmake_progress_start /Users/upa/work/code/mscp/test/CMakeFiles 0
+.PHONY : all
+
+# The main clean target
+clean:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 clean
+.PHONY : clean
+
+# The main clean target
+clean/fast: clean
+.PHONY : clean/fast
+
+# Prepare targets for installation.
+preinstall: all
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall
+
+# Prepare targets for installation.
+preinstall/fast:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 preinstall
+.PHONY : preinstall/fast
+
+# clear depends
+depend:
+ $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
+.PHONY : depend
+
+#=============================================================================
+# Target rules for targets named mscp
+
+# Build rule for target.
+mscp: cmake_check_build_system
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/Makefile2 mscp
+.PHONY : mscp
+
+# fast build rule for target.
+mscp/fast:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/build
+.PHONY : mscp/fast
+
+src/file.o: src/file.c.o
+.PHONY : src/file.o
+
+# target to build an object file
+src/file.c.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/file.c.o
+.PHONY : src/file.c.o
+
+src/file.i: src/file.c.i
+.PHONY : src/file.i
+
+# target to preprocess a source file
+src/file.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/file.c.i
+.PHONY : src/file.c.i
+
+src/file.s: src/file.c.s
+.PHONY : src/file.s
+
+# target to generate assembly for a file
+src/file.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/file.c.s
+.PHONY : src/file.c.s
+
+src/main.o: src/main.c.o
+.PHONY : src/main.o
+
+# target to build an object file
+src/main.c.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/main.c.o
+.PHONY : src/main.c.o
+
+src/main.i: src/main.c.i
+.PHONY : src/main.i
+
+# target to preprocess a source file
+src/main.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/main.c.i
+.PHONY : src/main.c.i
+
+src/main.s: src/main.c.s
+.PHONY : src/main.s
+
+# target to generate assembly for a file
+src/main.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/main.c.s
+.PHONY : src/main.c.s
+
+src/platform.o: src/platform.c.o
+.PHONY : src/platform.o
+
+# target to build an object file
+src/platform.c.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/platform.c.o
+.PHONY : src/platform.c.o
+
+src/platform.i: src/platform.c.i
+.PHONY : src/platform.i
+
+# target to preprocess a source file
+src/platform.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/platform.c.i
+.PHONY : src/platform.c.i
+
+src/platform.s: src/platform.c.s
+.PHONY : src/platform.s
+
+# target to generate assembly for a file
+src/platform.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/platform.c.s
+.PHONY : src/platform.c.s
+
+src/pprint.o: src/pprint.c.o
+.PHONY : src/pprint.o
+
+# target to build an object file
+src/pprint.c.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/pprint.c.o
+.PHONY : src/pprint.c.o
+
+src/pprint.i: src/pprint.c.i
+.PHONY : src/pprint.i
+
+# target to preprocess a source file
+src/pprint.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/pprint.c.i
+.PHONY : src/pprint.c.i
+
+src/pprint.s: src/pprint.c.s
+.PHONY : src/pprint.s
+
+# target to generate assembly for a file
+src/pprint.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/pprint.c.s
+.PHONY : src/pprint.c.s
+
+src/ssh.o: src/ssh.c.o
+.PHONY : src/ssh.o
+
+# target to build an object file
+src/ssh.c.o:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/ssh.c.o
+.PHONY : src/ssh.c.o
+
+src/ssh.i: src/ssh.c.i
+.PHONY : src/ssh.i
+
+# target to preprocess a source file
+src/ssh.c.i:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/ssh.c.i
+.PHONY : src/ssh.c.i
+
+src/ssh.s: src/ssh.c.s
+.PHONY : src/ssh.s
+
+# target to generate assembly for a file
+src/ssh.c.s:
+ $(MAKE) $(MAKESILENT) -f CMakeFiles/mscp.dir/build.make CMakeFiles/mscp.dir/src/ssh.c.s
+.PHONY : src/ssh.c.s
+
+# Help Target
+help:
+ @echo "The following are some of the valid targets for this Makefile:"
+ @echo "... all (the default if no target is provided)"
+ @echo "... clean"
+ @echo "... depend"
+ @echo "... edit_cache"
+ @echo "... install"
+ @echo "... install/local"
+ @echo "... install/strip"
+ @echo "... list_install_components"
+ @echo "... rebuild_cache"
+ @echo "... test"
+ @echo "... mscp"
+ @echo "... src/file.o"
+ @echo "... src/file.i"
+ @echo "... src/file.s"
+ @echo "... src/main.o"
+ @echo "... src/main.i"
+ @echo "... src/main.s"
+ @echo "... src/platform.o"
+ @echo "... src/platform.i"
+ @echo "... src/platform.s"
+ @echo "... src/pprint.o"
+ @echo "... src/pprint.i"
+ @echo "... src/pprint.s"
+ @echo "... src/ssh.o"
+ @echo "... src/ssh.i"
+ @echo "... src/ssh.s"
+.PHONY : help
+
+
+
+#=============================================================================
+# Special targets to cleanup operation of make.
+
+# Special rule to run CMake to check the build system integrity.
+# No rule that depends on this can have commands that come from listfiles
+# because they might be regenerated.
+cmake_check_build_system:
+ $(CMAKE_COMMAND) -S$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
+.PHONY : cmake_check_build_system
+
diff --git a/test/test_e2e.py b/test/test_e2e.py
index bc06805..25a566d 100644
--- a/test/test_e2e.py
+++ b/test/test_e2e.py
@@ -49,7 +49,7 @@ param_single_copy = [
@pytest.mark.parametrize("src, dst", param_single_copy)
def test_single_copy_remote2local(mscp, src, dst):
src.make()
- run2ok([mscp, remote_prefix + src.path, dst.path])
+ run2ok([mscp, "-H", remote_prefix + src.path, dst.path])
assert check_same_md5sum(src, dst)
src.cleanup()
dst.cleanup()
@@ -57,7 +57,7 @@ def test_single_copy_remote2local(mscp, src, dst):
@pytest.mark.parametrize("src, dst", param_single_copy)
def test_single_copy_local2remote(mscp, src, dst):
src.make()
- run2ok([mscp, src.path, remote_prefix + dst.path])
+ run2ok([mscp, "-H", src.path, remote_prefix + dst.path])
assert check_same_md5sum(src, dst)
src.cleanup()
dst.cleanup()
@@ -92,11 +92,11 @@ def test_dir_copy_remote2local(mscp, src_dir, dst_dir, src, dst, twice):
for f in src:
f.make()
- run2ok([mscp, remote_prefix + src_dir, dst_dir])
+ run2ok([mscp, "-H", remote_prefix + src_dir, dst_dir])
for sf, df in zip(src, dst):
assert check_same_md5sum(sf, df)
- run2ok([mscp, remote_prefix + src_dir, dst_dir])
+ run2ok([mscp, "-H", remote_prefix + src_dir, dst_dir])
for sf, df in zip(src, twice):
assert check_same_md5sum(sf, df)
@@ -110,11 +110,11 @@ def test_dir_copy_local2remote(mscp, src_dir, dst_dir, src, dst, twice):
for f in src:
f.make()
- run2ok([mscp, src_dir, remote_prefix + dst_dir])
+ run2ok([mscp, "-H", src_dir, remote_prefix + dst_dir])
for sf, df in zip(src, dst):
assert check_same_md5sum(sf, df)
- run2ok([mscp, src_dir, remote_prefix + dst_dir])
+ run2ok([mscp, "-H", src_dir, remote_prefix + dst_dir])
for sf, df in zip(src, twice):
assert check_same_md5sum(sf, df)
@@ -133,7 +133,7 @@ def test_override_single_file(mscp, src_prefix, dst_prefix):
dst = File("dst", size = 128).make()
assert not check_same_md5sum(src, dst)
- run2ok([mscp, src_prefix + src.path, dst_prefix + dst.path])
+ run2ok([mscp, "-H", src_prefix + src.path, dst_prefix + dst.path])
assert check_same_md5sum(src, dst)
src.cleanup()
@@ -144,7 +144,7 @@ def test_min_chunk(mscp, src_prefix, dst_prefix):
src = File("src", size = 16 * 1024).make()
dst = File("dst")
- run2ok([mscp, "-s", 8192, src_prefix + src.path, dst_prefix + dst.path])
+ run2ok([mscp, "-H", "-s", 8192, src_prefix + src.path, dst_prefix + dst.path])
assert check_same_md5sum(src, dst)
src.cleanup()
@@ -155,7 +155,7 @@ def test_cannot_override_file_with_dir(mscp, src_prefix, dst_prefix):
src = File("src", size = 128).make()
dst = File("dst").make()
- run2ng([mscp, src_prefix + src.path, dst_prefix + "dst/src"])
+ run2ng([mscp, "-H", src_prefix + src.path, dst_prefix + "dst/src"])
src.cleanup()
dst.cleanup()
@@ -164,7 +164,7 @@ def test_cannot_override_file_with_dir(mscp, src_prefix, dst_prefix):
def test_transfer_zero_bytes(mscp, src_prefix, dst_prefix):
src = File("src", size = 0).make()
dst = File("dst")
- run2ok([mscp, src_prefix + src.path, dst_prefix + "dst"])
+ run2ok([mscp, "-H", src_prefix + src.path, dst_prefix + "dst"])
assert os.path.exists("dst")
src.cleanup()
dst.cleanup()