mirror of
https://github.com/upa/mscp.git
synced 2026-02-05 03:54:44 +08:00
Compare commits
102 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58d7d085b0 | ||
|
|
deda8ca74c | ||
|
|
5fad665c39 | ||
|
|
1b655b61c9 | ||
|
|
c16b981d5d | ||
|
|
1c787e562f | ||
|
|
248f932a99 | ||
|
|
1636f2a965 | ||
|
|
31e011f85c | ||
|
|
006bd30424 | ||
|
|
60f442689e | ||
|
|
404f025765 | ||
|
|
235ba41c5b | ||
|
|
675126a836 | ||
|
|
ef2dd55572 | ||
|
|
ab6649f29e | ||
|
|
7c5314ea11 | ||
|
|
01fe30efc7 | ||
|
|
61199acc7b | ||
|
|
dd99bc0ac9 | ||
|
|
a5bca0ebe0 | ||
|
|
6373e24753 | ||
|
|
b1dbf62695 | ||
|
|
7b5e38e811 | ||
|
|
4ce62079cf | ||
|
|
e47d5b76e6 | ||
|
|
76a57b2f93 | ||
|
|
94563c3166 | ||
|
|
a1b9afefe5 | ||
|
|
bf7e2c3ae3 | ||
|
|
f2f0dab515 | ||
|
|
c9fe3993aa | ||
|
|
59b90d80bd | ||
|
|
00fa2c7277 | ||
|
|
d44a670b49 | ||
|
|
a281dfd9e9 | ||
|
|
67b51f75af | ||
|
|
d7cdece541 | ||
|
|
2bfd599ad9 | ||
|
|
9b8ba69a61 | ||
|
|
262a715e5e | ||
|
|
07a6cbf039 | ||
|
|
433f155cd3 | ||
|
|
40cf231e9a | ||
|
|
11a48bbe09 | ||
|
|
63fb5a7474 | ||
|
|
5dbc9e5bce | ||
|
|
d03ae9f592 | ||
|
|
0d248c5f6b | ||
|
|
9d02fc9122 | ||
|
|
0e80f089be | ||
|
|
f3a24e0047 | ||
|
|
dfdad6bca5 | ||
|
|
fc0ced1828 | ||
|
|
0695c1e2e4 | ||
|
|
692ea1d4e4 | ||
|
|
19c73af09d | ||
|
|
5f628b64e3 | ||
|
|
2f9c2c0f10 | ||
|
|
f71c7a145a | ||
|
|
4e895bb72e | ||
|
|
f152236844 | ||
|
|
ce376beeb9 | ||
|
|
b756654f6e | ||
|
|
a828ca3f5a | ||
|
|
d65a49768c | ||
|
|
00b5c64e27 | ||
|
|
d6f437bcb1 | ||
|
|
bfc955a9a7 | ||
|
|
d2e061fd97 | ||
|
|
c5afb99d67 | ||
|
|
45ba6b077e | ||
|
|
d819f715c8 | ||
|
|
22150c268d | ||
|
|
f8f8cf1994 | ||
|
|
758c5e92b3 | ||
|
|
2ef4267f72 | ||
|
|
1d8d853b30 | ||
|
|
b2628b54fb | ||
|
|
a9c59f744a | ||
|
|
96084004b6 | ||
|
|
5119d5ae26 | ||
|
|
93f155cffe | ||
|
|
4f0669f8f8 | ||
|
|
76892a69f9 | ||
|
|
a7f8ad948b | ||
|
|
ff45d9d71b | ||
|
|
9908fb309d | ||
|
|
c95e6a4fff | ||
|
|
304e71d5a0 | ||
|
|
ec663cc966 | ||
|
|
d57ed4149d | ||
|
|
7f5fcc617c | ||
|
|
36e45cd5f3 | ||
|
|
25207cf865 | ||
|
|
306a00ced5 | ||
|
|
65025b9022 | ||
|
|
bbc2fbdacf | ||
|
|
331bab6b41 | ||
|
|
1e375abb88 | ||
|
|
7ab5cc3ce9 | ||
|
|
60977a8e7a |
747
.clang-format
Normal file
747
.clang-format
Normal file
@@ -0,0 +1,747 @@
|
||||
# SPDX-License-Identifier: GPL-2.0
|
||||
#
|
||||
# clang-format configuration file. Intended for clang-format >= 11.
|
||||
#
|
||||
# For more information, see:
|
||||
#
|
||||
# Documentation/process/clang-format.rst
|
||||
# https://clang.llvm.org/docs/ClangFormat.html
|
||||
# https://clang.llvm.org/docs/ClangFormatStyleOptions.html
|
||||
#
|
||||
|
||||
# clang-format configuration for Linux kernel, except that ColumnLimit is 90
|
||||
---
|
||||
AccessModifierOffset: -4
|
||||
AlignAfterOpenBracket: Align
|
||||
AlignConsecutiveAssignments: false
|
||||
AlignConsecutiveDeclarations: false
|
||||
AlignEscapedNewlines: Left
|
||||
AlignOperands: true
|
||||
AlignTrailingComments: false
|
||||
AllowAllParametersOfDeclarationOnNextLine: false
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
AlwaysBreakAfterDefinitionReturnType: None
|
||||
AlwaysBreakAfterReturnType: None
|
||||
AlwaysBreakBeforeMultilineStrings: false
|
||||
AlwaysBreakTemplateDeclarations: false
|
||||
BinPackArguments: true
|
||||
BinPackParameters: true
|
||||
BraceWrapping:
|
||||
AfterClass: false
|
||||
AfterControlStatement: false
|
||||
AfterEnum: false
|
||||
AfterFunction: true
|
||||
AfterNamespace: true
|
||||
AfterObjCDeclaration: false
|
||||
AfterStruct: false
|
||||
AfterUnion: false
|
||||
AfterExternBlock: false
|
||||
BeforeCatch: false
|
||||
BeforeElse: false
|
||||
IndentBraces: false
|
||||
SplitEmptyFunction: true
|
||||
SplitEmptyRecord: true
|
||||
SplitEmptyNamespace: true
|
||||
BreakBeforeBinaryOperators: None
|
||||
BreakBeforeBraces: Custom
|
||||
BreakBeforeInheritanceComma: false
|
||||
BreakBeforeTernaryOperators: false
|
||||
BreakConstructorInitializersBeforeComma: false
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakAfterJavaFieldAnnotations: false
|
||||
BreakStringLiterals: false
|
||||
ColumnLimit: 90
|
||||
CommentPragmas: '^ IWYU pragma:'
|
||||
CompactNamespaces: false
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: false
|
||||
ConstructorInitializerIndentWidth: 8
|
||||
ContinuationIndentWidth: 8
|
||||
Cpp11BracedListStyle: false
|
||||
DerivePointerAlignment: false
|
||||
DisableFormat: false
|
||||
ExperimentalAutoDetectBinPacking: false
|
||||
FixNamespaceComments: false
|
||||
|
||||
# Taken from:
|
||||
# git grep -h '^#define [^[:space:]]*for_each[^[:space:]]*(' include/ tools/ \
|
||||
# | sed "s,^#define \([^[:space:]]*for_each[^[:space:]]*\)(.*$, - '\1'," \
|
||||
# | LC_ALL=C sort -u
|
||||
ForEachMacros:
|
||||
- '__ata_qc_for_each'
|
||||
- '__bio_for_each_bvec'
|
||||
- '__bio_for_each_segment'
|
||||
- '__evlist__for_each_entry'
|
||||
- '__evlist__for_each_entry_continue'
|
||||
- '__evlist__for_each_entry_from'
|
||||
- '__evlist__for_each_entry_reverse'
|
||||
- '__evlist__for_each_entry_safe'
|
||||
- '__for_each_mem_range'
|
||||
- '__for_each_mem_range_rev'
|
||||
- '__for_each_thread'
|
||||
- '__hlist_for_each_rcu'
|
||||
- '__map__for_each_symbol_by_name'
|
||||
- '__pci_bus_for_each_res0'
|
||||
- '__pci_bus_for_each_res1'
|
||||
- '__pci_dev_for_each_res0'
|
||||
- '__pci_dev_for_each_res1'
|
||||
- '__perf_evlist__for_each_entry'
|
||||
- '__perf_evlist__for_each_entry_reverse'
|
||||
- '__perf_evlist__for_each_entry_safe'
|
||||
- '__rq_for_each_bio'
|
||||
- '__shost_for_each_device'
|
||||
- '__sym_for_each'
|
||||
- 'apei_estatus_for_each_section'
|
||||
- 'ata_for_each_dev'
|
||||
- 'ata_for_each_link'
|
||||
- 'ata_qc_for_each'
|
||||
- 'ata_qc_for_each_raw'
|
||||
- 'ata_qc_for_each_with_internal'
|
||||
- 'ax25_for_each'
|
||||
- 'ax25_uid_for_each'
|
||||
- 'bio_for_each_bvec'
|
||||
- 'bio_for_each_bvec_all'
|
||||
- 'bio_for_each_folio_all'
|
||||
- 'bio_for_each_integrity_vec'
|
||||
- 'bio_for_each_segment'
|
||||
- 'bio_for_each_segment_all'
|
||||
- 'bio_list_for_each'
|
||||
- 'bip_for_each_vec'
|
||||
- 'bond_for_each_slave'
|
||||
- 'bond_for_each_slave_rcu'
|
||||
- 'bpf_for_each'
|
||||
- 'bpf_for_each_reg_in_vstate'
|
||||
- 'bpf_for_each_reg_in_vstate_mask'
|
||||
- 'bpf_for_each_spilled_reg'
|
||||
- 'bpf_object__for_each_map'
|
||||
- 'bpf_object__for_each_program'
|
||||
- 'btree_for_each_safe128'
|
||||
- 'btree_for_each_safe32'
|
||||
- 'btree_for_each_safe64'
|
||||
- 'btree_for_each_safel'
|
||||
- 'card_for_each_dev'
|
||||
- 'cgroup_taskset_for_each'
|
||||
- 'cgroup_taskset_for_each_leader'
|
||||
- 'cpu_aggr_map__for_each_idx'
|
||||
- 'cpufreq_for_each_efficient_entry_idx'
|
||||
- 'cpufreq_for_each_entry'
|
||||
- 'cpufreq_for_each_entry_idx'
|
||||
- 'cpufreq_for_each_valid_entry'
|
||||
- 'cpufreq_for_each_valid_entry_idx'
|
||||
- 'css_for_each_child'
|
||||
- 'css_for_each_descendant_post'
|
||||
- 'css_for_each_descendant_pre'
|
||||
- 'damon_for_each_region'
|
||||
- 'damon_for_each_region_from'
|
||||
- 'damon_for_each_region_safe'
|
||||
- 'damon_for_each_scheme'
|
||||
- 'damon_for_each_scheme_safe'
|
||||
- 'damon_for_each_target'
|
||||
- 'damon_for_each_target_safe'
|
||||
- 'damos_for_each_filter'
|
||||
- 'damos_for_each_filter_safe'
|
||||
- 'data__for_each_file'
|
||||
- 'data__for_each_file_new'
|
||||
- 'data__for_each_file_start'
|
||||
- 'device_for_each_child_node'
|
||||
- 'displayid_iter_for_each'
|
||||
- 'dma_fence_array_for_each'
|
||||
- 'dma_fence_chain_for_each'
|
||||
- 'dma_fence_unwrap_for_each'
|
||||
- 'dma_resv_for_each_fence'
|
||||
- 'dma_resv_for_each_fence_unlocked'
|
||||
- 'do_for_each_ftrace_op'
|
||||
- 'drm_atomic_crtc_for_each_plane'
|
||||
- 'drm_atomic_crtc_state_for_each_plane'
|
||||
- 'drm_atomic_crtc_state_for_each_plane_state'
|
||||
- 'drm_atomic_for_each_plane_damage'
|
||||
- 'drm_client_for_each_connector_iter'
|
||||
- 'drm_client_for_each_modeset'
|
||||
- 'drm_connector_for_each_possible_encoder'
|
||||
- 'drm_exec_for_each_locked_object'
|
||||
- 'drm_exec_for_each_locked_object_reverse'
|
||||
- 'drm_for_each_bridge_in_chain'
|
||||
- 'drm_for_each_connector_iter'
|
||||
- 'drm_for_each_crtc'
|
||||
- 'drm_for_each_crtc_reverse'
|
||||
- 'drm_for_each_encoder'
|
||||
- 'drm_for_each_encoder_mask'
|
||||
- 'drm_for_each_fb'
|
||||
- 'drm_for_each_legacy_plane'
|
||||
- 'drm_for_each_plane'
|
||||
- 'drm_for_each_plane_mask'
|
||||
- 'drm_for_each_privobj'
|
||||
- 'drm_gem_for_each_gpuva'
|
||||
- 'drm_gem_for_each_gpuva_safe'
|
||||
- 'drm_gpuva_for_each_op'
|
||||
- 'drm_gpuva_for_each_op_from_reverse'
|
||||
- 'drm_gpuva_for_each_op_safe'
|
||||
- 'drm_gpuvm_for_each_va'
|
||||
- 'drm_gpuvm_for_each_va_range'
|
||||
- 'drm_gpuvm_for_each_va_range_safe'
|
||||
- 'drm_gpuvm_for_each_va_safe'
|
||||
- 'drm_mm_for_each_hole'
|
||||
- 'drm_mm_for_each_node'
|
||||
- 'drm_mm_for_each_node_in_range'
|
||||
- 'drm_mm_for_each_node_safe'
|
||||
- 'dsa_switch_for_each_available_port'
|
||||
- 'dsa_switch_for_each_cpu_port'
|
||||
- 'dsa_switch_for_each_cpu_port_continue_reverse'
|
||||
- 'dsa_switch_for_each_port'
|
||||
- 'dsa_switch_for_each_port_continue_reverse'
|
||||
- 'dsa_switch_for_each_port_safe'
|
||||
- 'dsa_switch_for_each_user_port'
|
||||
- 'dsa_tree_for_each_cpu_port'
|
||||
- 'dsa_tree_for_each_user_port'
|
||||
- 'dsa_tree_for_each_user_port_continue_reverse'
|
||||
- 'dso__for_each_symbol'
|
||||
- 'dsos__for_each_with_build_id'
|
||||
- 'elf_hash_for_each_possible'
|
||||
- 'elf_symtab__for_each_symbol'
|
||||
- 'evlist__for_each_cpu'
|
||||
- 'evlist__for_each_entry'
|
||||
- 'evlist__for_each_entry_continue'
|
||||
- 'evlist__for_each_entry_from'
|
||||
- 'evlist__for_each_entry_reverse'
|
||||
- 'evlist__for_each_entry_safe'
|
||||
- 'flow_action_for_each'
|
||||
- 'for_each_acpi_consumer_dev'
|
||||
- 'for_each_acpi_dev_match'
|
||||
- 'for_each_active_dev_scope'
|
||||
- 'for_each_active_drhd_unit'
|
||||
- 'for_each_active_iommu'
|
||||
- 'for_each_active_route'
|
||||
- 'for_each_aggr_pgid'
|
||||
- 'for_each_and_bit'
|
||||
- 'for_each_andnot_bit'
|
||||
- 'for_each_available_child_of_node'
|
||||
- 'for_each_bench'
|
||||
- 'for_each_bio'
|
||||
- 'for_each_board_func_rsrc'
|
||||
- 'for_each_btf_ext_rec'
|
||||
- 'for_each_btf_ext_sec'
|
||||
- 'for_each_bvec'
|
||||
- 'for_each_card_auxs'
|
||||
- 'for_each_card_auxs_safe'
|
||||
- 'for_each_card_components'
|
||||
- 'for_each_card_dapms'
|
||||
- 'for_each_card_pre_auxs'
|
||||
- 'for_each_card_prelinks'
|
||||
- 'for_each_card_rtds'
|
||||
- 'for_each_card_rtds_safe'
|
||||
- 'for_each_card_widgets'
|
||||
- 'for_each_card_widgets_safe'
|
||||
- 'for_each_cgroup_storage_type'
|
||||
- 'for_each_child_of_node'
|
||||
- 'for_each_clear_bit'
|
||||
- 'for_each_clear_bit_from'
|
||||
- 'for_each_clear_bitrange'
|
||||
- 'for_each_clear_bitrange_from'
|
||||
- 'for_each_cmd'
|
||||
- 'for_each_cmsghdr'
|
||||
- 'for_each_collection'
|
||||
- 'for_each_comp_order'
|
||||
- 'for_each_compatible_node'
|
||||
- 'for_each_component_dais'
|
||||
- 'for_each_component_dais_safe'
|
||||
- 'for_each_conduit'
|
||||
- 'for_each_console'
|
||||
- 'for_each_console_srcu'
|
||||
- 'for_each_cpu'
|
||||
- 'for_each_cpu_and'
|
||||
- 'for_each_cpu_andnot'
|
||||
- 'for_each_cpu_or'
|
||||
- 'for_each_cpu_wrap'
|
||||
- 'for_each_dapm_widgets'
|
||||
- 'for_each_dedup_cand'
|
||||
- 'for_each_dev_addr'
|
||||
- 'for_each_dev_scope'
|
||||
- 'for_each_dma_cap_mask'
|
||||
- 'for_each_dpcm_be'
|
||||
- 'for_each_dpcm_be_rollback'
|
||||
- 'for_each_dpcm_be_safe'
|
||||
- 'for_each_dpcm_fe'
|
||||
- 'for_each_drhd_unit'
|
||||
- 'for_each_dss_dev'
|
||||
- 'for_each_efi_memory_desc'
|
||||
- 'for_each_efi_memory_desc_in_map'
|
||||
- 'for_each_element'
|
||||
- 'for_each_element_extid'
|
||||
- 'for_each_element_id'
|
||||
- 'for_each_endpoint_of_node'
|
||||
- 'for_each_event'
|
||||
- 'for_each_event_tps'
|
||||
- 'for_each_evictable_lru'
|
||||
- 'for_each_fib6_node_rt_rcu'
|
||||
- 'for_each_fib6_walker_rt'
|
||||
- 'for_each_free_mem_pfn_range_in_zone'
|
||||
- 'for_each_free_mem_pfn_range_in_zone_from'
|
||||
- 'for_each_free_mem_range'
|
||||
- 'for_each_free_mem_range_reverse'
|
||||
- 'for_each_func_rsrc'
|
||||
- 'for_each_gpiochip_node'
|
||||
- 'for_each_group_evsel'
|
||||
- 'for_each_group_evsel_head'
|
||||
- 'for_each_group_member'
|
||||
- 'for_each_group_member_head'
|
||||
- 'for_each_hstate'
|
||||
- 'for_each_if'
|
||||
- 'for_each_inject_fn'
|
||||
- 'for_each_insn'
|
||||
- 'for_each_insn_prefix'
|
||||
- 'for_each_intid'
|
||||
- 'for_each_iommu'
|
||||
- 'for_each_ip_tunnel_rcu'
|
||||
- 'for_each_irq_nr'
|
||||
- 'for_each_lang'
|
||||
- 'for_each_link_codecs'
|
||||
- 'for_each_link_cpus'
|
||||
- 'for_each_link_platforms'
|
||||
- 'for_each_lru'
|
||||
- 'for_each_matching_node'
|
||||
- 'for_each_matching_node_and_match'
|
||||
- 'for_each_media_entity_data_link'
|
||||
- 'for_each_mem_pfn_range'
|
||||
- 'for_each_mem_range'
|
||||
- 'for_each_mem_range_rev'
|
||||
- 'for_each_mem_region'
|
||||
- 'for_each_member'
|
||||
- 'for_each_memory'
|
||||
- 'for_each_migratetype_order'
|
||||
- 'for_each_missing_reg'
|
||||
- 'for_each_mle_subelement'
|
||||
- 'for_each_mod_mem_type'
|
||||
- 'for_each_net'
|
||||
- 'for_each_net_continue_reverse'
|
||||
- 'for_each_net_rcu'
|
||||
- 'for_each_netdev'
|
||||
- 'for_each_netdev_continue'
|
||||
- 'for_each_netdev_continue_rcu'
|
||||
- 'for_each_netdev_continue_reverse'
|
||||
- 'for_each_netdev_dump'
|
||||
- 'for_each_netdev_feature'
|
||||
- 'for_each_netdev_in_bond_rcu'
|
||||
- 'for_each_netdev_rcu'
|
||||
- 'for_each_netdev_reverse'
|
||||
- 'for_each_netdev_safe'
|
||||
- 'for_each_new_connector_in_state'
|
||||
- 'for_each_new_crtc_in_state'
|
||||
- 'for_each_new_mst_mgr_in_state'
|
||||
- 'for_each_new_plane_in_state'
|
||||
- 'for_each_new_plane_in_state_reverse'
|
||||
- 'for_each_new_private_obj_in_state'
|
||||
- 'for_each_new_reg'
|
||||
- 'for_each_node'
|
||||
- 'for_each_node_by_name'
|
||||
- 'for_each_node_by_type'
|
||||
- 'for_each_node_mask'
|
||||
- 'for_each_node_state'
|
||||
- 'for_each_node_with_cpus'
|
||||
- 'for_each_node_with_property'
|
||||
- 'for_each_nonreserved_multicast_dest_pgid'
|
||||
- 'for_each_numa_hop_mask'
|
||||
- 'for_each_of_allnodes'
|
||||
- 'for_each_of_allnodes_from'
|
||||
- 'for_each_of_cpu_node'
|
||||
- 'for_each_of_pci_range'
|
||||
- 'for_each_old_connector_in_state'
|
||||
- 'for_each_old_crtc_in_state'
|
||||
- 'for_each_old_mst_mgr_in_state'
|
||||
- 'for_each_old_plane_in_state'
|
||||
- 'for_each_old_private_obj_in_state'
|
||||
- 'for_each_oldnew_connector_in_state'
|
||||
- 'for_each_oldnew_crtc_in_state'
|
||||
- 'for_each_oldnew_mst_mgr_in_state'
|
||||
- 'for_each_oldnew_plane_in_state'
|
||||
- 'for_each_oldnew_plane_in_state_reverse'
|
||||
- 'for_each_oldnew_private_obj_in_state'
|
||||
- 'for_each_online_cpu'
|
||||
- 'for_each_online_node'
|
||||
- 'for_each_online_pgdat'
|
||||
- 'for_each_or_bit'
|
||||
- 'for_each_path'
|
||||
- 'for_each_pci_bridge'
|
||||
- 'for_each_pci_dev'
|
||||
- 'for_each_pcm_streams'
|
||||
- 'for_each_physmem_range'
|
||||
- 'for_each_populated_zone'
|
||||
- 'for_each_possible_cpu'
|
||||
- 'for_each_present_blessed_reg'
|
||||
- 'for_each_present_cpu'
|
||||
- 'for_each_prime_number'
|
||||
- 'for_each_prime_number_from'
|
||||
- 'for_each_probe_cache_entry'
|
||||
- 'for_each_process'
|
||||
- 'for_each_process_thread'
|
||||
- 'for_each_prop_codec_conf'
|
||||
- 'for_each_prop_dai_codec'
|
||||
- 'for_each_prop_dai_cpu'
|
||||
- 'for_each_prop_dlc_codecs'
|
||||
- 'for_each_prop_dlc_cpus'
|
||||
- 'for_each_prop_dlc_platforms'
|
||||
- 'for_each_property_of_node'
|
||||
- 'for_each_reg'
|
||||
- 'for_each_reg_filtered'
|
||||
- 'for_each_reloc'
|
||||
- 'for_each_reloc_from'
|
||||
- 'for_each_requested_gpio'
|
||||
- 'for_each_requested_gpio_in_range'
|
||||
- 'for_each_reserved_mem_range'
|
||||
- 'for_each_reserved_mem_region'
|
||||
- 'for_each_rtd_codec_dais'
|
||||
- 'for_each_rtd_components'
|
||||
- 'for_each_rtd_cpu_dais'
|
||||
- 'for_each_rtd_dais'
|
||||
- 'for_each_sband_iftype_data'
|
||||
- 'for_each_script'
|
||||
- 'for_each_sec'
|
||||
- 'for_each_set_bit'
|
||||
- 'for_each_set_bit_from'
|
||||
- 'for_each_set_bit_wrap'
|
||||
- 'for_each_set_bitrange'
|
||||
- 'for_each_set_bitrange_from'
|
||||
- 'for_each_set_clump8'
|
||||
- 'for_each_sg'
|
||||
- 'for_each_sg_dma_page'
|
||||
- 'for_each_sg_page'
|
||||
- 'for_each_sgtable_dma_page'
|
||||
- 'for_each_sgtable_dma_sg'
|
||||
- 'for_each_sgtable_page'
|
||||
- 'for_each_sgtable_sg'
|
||||
- 'for_each_sibling_event'
|
||||
- 'for_each_sta_active_link'
|
||||
- 'for_each_subelement'
|
||||
- 'for_each_subelement_extid'
|
||||
- 'for_each_subelement_id'
|
||||
- 'for_each_sublist'
|
||||
- 'for_each_subsystem'
|
||||
- 'for_each_supported_activate_fn'
|
||||
- 'for_each_supported_inject_fn'
|
||||
- 'for_each_sym'
|
||||
- 'for_each_test'
|
||||
- 'for_each_thread'
|
||||
- 'for_each_token'
|
||||
- 'for_each_unicast_dest_pgid'
|
||||
- 'for_each_valid_link'
|
||||
- 'for_each_vif_active_link'
|
||||
- 'for_each_vma'
|
||||
- 'for_each_vma_range'
|
||||
- 'for_each_vsi'
|
||||
- 'for_each_wakeup_source'
|
||||
- 'for_each_zone'
|
||||
- 'for_each_zone_zonelist'
|
||||
- 'for_each_zone_zonelist_nodemask'
|
||||
- 'func_for_each_insn'
|
||||
- 'fwnode_for_each_available_child_node'
|
||||
- 'fwnode_for_each_child_node'
|
||||
- 'fwnode_for_each_parent_node'
|
||||
- 'fwnode_graph_for_each_endpoint'
|
||||
- 'gadget_for_each_ep'
|
||||
- 'genradix_for_each'
|
||||
- 'genradix_for_each_from'
|
||||
- 'genradix_for_each_reverse'
|
||||
- 'hash_for_each'
|
||||
- 'hash_for_each_possible'
|
||||
- 'hash_for_each_possible_rcu'
|
||||
- 'hash_for_each_possible_rcu_notrace'
|
||||
- 'hash_for_each_possible_safe'
|
||||
- 'hash_for_each_rcu'
|
||||
- 'hash_for_each_safe'
|
||||
- 'hashmap__for_each_entry'
|
||||
- 'hashmap__for_each_entry_safe'
|
||||
- 'hashmap__for_each_key_entry'
|
||||
- 'hashmap__for_each_key_entry_safe'
|
||||
- 'hctx_for_each_ctx'
|
||||
- 'hists__for_each_format'
|
||||
- 'hists__for_each_sort_list'
|
||||
- 'hlist_bl_for_each_entry'
|
||||
- 'hlist_bl_for_each_entry_rcu'
|
||||
- 'hlist_bl_for_each_entry_safe'
|
||||
- 'hlist_for_each'
|
||||
- 'hlist_for_each_entry'
|
||||
- 'hlist_for_each_entry_continue'
|
||||
- 'hlist_for_each_entry_continue_rcu'
|
||||
- 'hlist_for_each_entry_continue_rcu_bh'
|
||||
- 'hlist_for_each_entry_from'
|
||||
- 'hlist_for_each_entry_from_rcu'
|
||||
- 'hlist_for_each_entry_rcu'
|
||||
- 'hlist_for_each_entry_rcu_bh'
|
||||
- 'hlist_for_each_entry_rcu_notrace'
|
||||
- 'hlist_for_each_entry_safe'
|
||||
- 'hlist_for_each_entry_srcu'
|
||||
- 'hlist_for_each_safe'
|
||||
- 'hlist_nulls_for_each_entry'
|
||||
- 'hlist_nulls_for_each_entry_from'
|
||||
- 'hlist_nulls_for_each_entry_rcu'
|
||||
- 'hlist_nulls_for_each_entry_safe'
|
||||
- 'i3c_bus_for_each_i2cdev'
|
||||
- 'i3c_bus_for_each_i3cdev'
|
||||
- 'idr_for_each_entry'
|
||||
- 'idr_for_each_entry_continue'
|
||||
- 'idr_for_each_entry_continue_ul'
|
||||
- 'idr_for_each_entry_ul'
|
||||
- 'in_dev_for_each_ifa_rcu'
|
||||
- 'in_dev_for_each_ifa_rtnl'
|
||||
- 'inet_bind_bucket_for_each'
|
||||
- 'interval_tree_for_each_span'
|
||||
- 'intlist__for_each_entry'
|
||||
- 'intlist__for_each_entry_safe'
|
||||
- 'kcore_copy__for_each_phdr'
|
||||
- 'key_for_each'
|
||||
- 'key_for_each_safe'
|
||||
- 'klp_for_each_func'
|
||||
- 'klp_for_each_func_safe'
|
||||
- 'klp_for_each_func_static'
|
||||
- 'klp_for_each_object'
|
||||
- 'klp_for_each_object_safe'
|
||||
- 'klp_for_each_object_static'
|
||||
- 'kunit_suite_for_each_test_case'
|
||||
- 'kvm_for_each_memslot'
|
||||
- 'kvm_for_each_memslot_in_gfn_range'
|
||||
- 'kvm_for_each_vcpu'
|
||||
- 'libbpf_nla_for_each_attr'
|
||||
- 'list_for_each'
|
||||
- 'list_for_each_codec'
|
||||
- 'list_for_each_codec_safe'
|
||||
- 'list_for_each_continue'
|
||||
- 'list_for_each_entry'
|
||||
- 'list_for_each_entry_continue'
|
||||
- 'list_for_each_entry_continue_rcu'
|
||||
- 'list_for_each_entry_continue_reverse'
|
||||
- 'list_for_each_entry_from'
|
||||
- 'list_for_each_entry_from_rcu'
|
||||
- 'list_for_each_entry_from_reverse'
|
||||
- 'list_for_each_entry_lockless'
|
||||
- 'list_for_each_entry_rcu'
|
||||
- 'list_for_each_entry_reverse'
|
||||
- 'list_for_each_entry_safe'
|
||||
- 'list_for_each_entry_safe_continue'
|
||||
- 'list_for_each_entry_safe_from'
|
||||
- 'list_for_each_entry_safe_reverse'
|
||||
- 'list_for_each_entry_srcu'
|
||||
- 'list_for_each_from'
|
||||
- 'list_for_each_prev'
|
||||
- 'list_for_each_prev_safe'
|
||||
- 'list_for_each_rcu'
|
||||
- 'list_for_each_reverse'
|
||||
- 'list_for_each_safe'
|
||||
- 'llist_for_each'
|
||||
- 'llist_for_each_entry'
|
||||
- 'llist_for_each_entry_safe'
|
||||
- 'llist_for_each_safe'
|
||||
- 'lwq_for_each_safe'
|
||||
- 'map__for_each_symbol'
|
||||
- 'map__for_each_symbol_by_name'
|
||||
- 'maps__for_each_entry'
|
||||
- 'maps__for_each_entry_safe'
|
||||
- 'mas_for_each'
|
||||
- 'mci_for_each_dimm'
|
||||
- 'media_device_for_each_entity'
|
||||
- 'media_device_for_each_intf'
|
||||
- 'media_device_for_each_link'
|
||||
- 'media_device_for_each_pad'
|
||||
- 'media_entity_for_each_pad'
|
||||
- 'media_pipeline_for_each_entity'
|
||||
- 'media_pipeline_for_each_pad'
|
||||
- 'mlx5_lag_for_each_peer_mdev'
|
||||
- 'msi_domain_for_each_desc'
|
||||
- 'msi_for_each_desc'
|
||||
- 'mt_for_each'
|
||||
- 'nanddev_io_for_each_page'
|
||||
- 'netdev_for_each_lower_dev'
|
||||
- 'netdev_for_each_lower_private'
|
||||
- 'netdev_for_each_lower_private_rcu'
|
||||
- 'netdev_for_each_mc_addr'
|
||||
- 'netdev_for_each_synced_mc_addr'
|
||||
- 'netdev_for_each_synced_uc_addr'
|
||||
- 'netdev_for_each_uc_addr'
|
||||
- 'netdev_for_each_upper_dev_rcu'
|
||||
- 'netdev_hw_addr_list_for_each'
|
||||
- 'nft_rule_for_each_expr'
|
||||
- 'nla_for_each_attr'
|
||||
- 'nla_for_each_nested'
|
||||
- 'nlmsg_for_each_attr'
|
||||
- 'nlmsg_for_each_msg'
|
||||
- 'nr_neigh_for_each'
|
||||
- 'nr_neigh_for_each_safe'
|
||||
- 'nr_node_for_each'
|
||||
- 'nr_node_for_each_safe'
|
||||
- 'of_for_each_phandle'
|
||||
- 'of_property_for_each_string'
|
||||
- 'of_property_for_each_u32'
|
||||
- 'pci_bus_for_each_resource'
|
||||
- 'pci_dev_for_each_resource'
|
||||
- 'pcl_for_each_chunk'
|
||||
- 'pcl_for_each_segment'
|
||||
- 'pcm_for_each_format'
|
||||
- 'perf_config_items__for_each_entry'
|
||||
- 'perf_config_sections__for_each_entry'
|
||||
- 'perf_config_set__for_each_entry'
|
||||
- 'perf_cpu_map__for_each_cpu'
|
||||
- 'perf_cpu_map__for_each_idx'
|
||||
- 'perf_evlist__for_each_entry'
|
||||
- 'perf_evlist__for_each_entry_reverse'
|
||||
- 'perf_evlist__for_each_entry_safe'
|
||||
- 'perf_evlist__for_each_evsel'
|
||||
- 'perf_evlist__for_each_mmap'
|
||||
- 'perf_hpp_list__for_each_format'
|
||||
- 'perf_hpp_list__for_each_format_safe'
|
||||
- 'perf_hpp_list__for_each_sort_list'
|
||||
- 'perf_hpp_list__for_each_sort_list_safe'
|
||||
- 'perf_tool_event__for_each_event'
|
||||
- 'plist_for_each'
|
||||
- 'plist_for_each_continue'
|
||||
- 'plist_for_each_entry'
|
||||
- 'plist_for_each_entry_continue'
|
||||
- 'plist_for_each_entry_safe'
|
||||
- 'plist_for_each_safe'
|
||||
- 'pnp_for_each_card'
|
||||
- 'pnp_for_each_dev'
|
||||
- 'protocol_for_each_card'
|
||||
- 'protocol_for_each_dev'
|
||||
- 'queue_for_each_hw_ctx'
|
||||
- 'radix_tree_for_each_slot'
|
||||
- 'radix_tree_for_each_tagged'
|
||||
- 'rb_for_each'
|
||||
- 'rbtree_postorder_for_each_entry_safe'
|
||||
- 'rdma_for_each_block'
|
||||
- 'rdma_for_each_port'
|
||||
- 'rdma_umem_for_each_dma_block'
|
||||
- 'resort_rb__for_each_entry'
|
||||
- 'resource_list_for_each_entry'
|
||||
- 'resource_list_for_each_entry_safe'
|
||||
- 'rhl_for_each_entry_rcu'
|
||||
- 'rhl_for_each_rcu'
|
||||
- 'rht_for_each'
|
||||
- 'rht_for_each_entry'
|
||||
- 'rht_for_each_entry_from'
|
||||
- 'rht_for_each_entry_rcu'
|
||||
- 'rht_for_each_entry_rcu_from'
|
||||
- 'rht_for_each_entry_safe'
|
||||
- 'rht_for_each_from'
|
||||
- 'rht_for_each_rcu'
|
||||
- 'rht_for_each_rcu_from'
|
||||
- 'rq_for_each_bvec'
|
||||
- 'rq_for_each_segment'
|
||||
- 'rq_list_for_each'
|
||||
- 'rq_list_for_each_safe'
|
||||
- 'sample_read_group__for_each'
|
||||
- 'scsi_for_each_prot_sg'
|
||||
- 'scsi_for_each_sg'
|
||||
- 'sctp_for_each_hentry'
|
||||
- 'sctp_skb_for_each'
|
||||
- 'sec_for_each_insn'
|
||||
- 'sec_for_each_insn_continue'
|
||||
- 'sec_for_each_insn_from'
|
||||
- 'sec_for_each_sym'
|
||||
- 'shdma_for_each_chan'
|
||||
- 'shost_for_each_device'
|
||||
- 'sk_for_each'
|
||||
- 'sk_for_each_bound'
|
||||
- 'sk_for_each_bound_bhash2'
|
||||
- 'sk_for_each_entry_offset_rcu'
|
||||
- 'sk_for_each_from'
|
||||
- 'sk_for_each_rcu'
|
||||
- 'sk_for_each_safe'
|
||||
- 'sk_nulls_for_each'
|
||||
- 'sk_nulls_for_each_from'
|
||||
- 'sk_nulls_for_each_rcu'
|
||||
- 'snd_array_for_each'
|
||||
- 'snd_pcm_group_for_each_entry'
|
||||
- 'snd_soc_dapm_widget_for_each_path'
|
||||
- 'snd_soc_dapm_widget_for_each_path_safe'
|
||||
- 'snd_soc_dapm_widget_for_each_sink_path'
|
||||
- 'snd_soc_dapm_widget_for_each_source_path'
|
||||
- 'strlist__for_each_entry'
|
||||
- 'strlist__for_each_entry_safe'
|
||||
- 'sym_for_each_insn'
|
||||
- 'sym_for_each_insn_continue_reverse'
|
||||
- 'symbols__for_each_entry'
|
||||
- 'tb_property_for_each'
|
||||
- 'tcf_act_for_each_action'
|
||||
- 'tcf_exts_for_each_action'
|
||||
- 'ttm_resource_manager_for_each_res'
|
||||
- 'twsk_for_each_bound_bhash2'
|
||||
- 'udp_portaddr_for_each_entry'
|
||||
- 'udp_portaddr_for_each_entry_rcu'
|
||||
- 'usb_hub_for_each_child'
|
||||
- 'v4l2_device_for_each_subdev'
|
||||
- 'v4l2_m2m_for_each_dst_buf'
|
||||
- 'v4l2_m2m_for_each_dst_buf_safe'
|
||||
- 'v4l2_m2m_for_each_src_buf'
|
||||
- 'v4l2_m2m_for_each_src_buf_safe'
|
||||
- 'virtio_device_for_each_vq'
|
||||
- 'while_for_each_ftrace_op'
|
||||
- 'xa_for_each'
|
||||
- 'xa_for_each_marked'
|
||||
- 'xa_for_each_range'
|
||||
- 'xa_for_each_start'
|
||||
- 'xas_for_each'
|
||||
- 'xas_for_each_conflict'
|
||||
- 'xas_for_each_marked'
|
||||
- 'xbc_array_for_each_value'
|
||||
- 'xbc_for_each_key_value'
|
||||
- 'xbc_node_for_each_array_value'
|
||||
- 'xbc_node_for_each_child'
|
||||
- 'xbc_node_for_each_key_value'
|
||||
- 'xbc_node_for_each_subkey'
|
||||
- 'zorro_for_each_dev'
|
||||
- 'pool_iter_for_each'
|
||||
- 'pool_for_each'
|
||||
|
||||
IncludeBlocks: Preserve
|
||||
IncludeCategories:
|
||||
- Regex: '.*'
|
||||
Priority: 1
|
||||
IncludeIsMainRegex: '(Test)?$'
|
||||
IndentCaseLabels: false
|
||||
IndentGotoLabels: false
|
||||
IndentPPDirectives: None
|
||||
IndentWidth: 8
|
||||
IndentWrappedFunctionNames: false
|
||||
JavaScriptQuotes: Leave
|
||||
JavaScriptWrapImports: true
|
||||
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||
MacroBlockBegin: ''
|
||||
MacroBlockEnd: ''
|
||||
MaxEmptyLinesToKeep: 1
|
||||
NamespaceIndentation: None
|
||||
ObjCBinPackProtocolList: Auto
|
||||
ObjCBlockIndentWidth: 8
|
||||
ObjCSpaceAfterProperty: true
|
||||
ObjCSpaceBeforeProtocolList: true
|
||||
|
||||
# Taken from git's rules
|
||||
PenaltyBreakAssignment: 10
|
||||
PenaltyBreakBeforeFirstCallParameter: 30
|
||||
PenaltyBreakComment: 10
|
||||
PenaltyBreakFirstLessLess: 0
|
||||
PenaltyBreakString: 10
|
||||
PenaltyExcessCharacter: 100
|
||||
PenaltyReturnTypeOnItsOwnLine: 60
|
||||
|
||||
PointerAlignment: Right
|
||||
ReflowComments: false
|
||||
SortIncludes: false
|
||||
SortUsingDeclarations: false
|
||||
SpaceAfterCStyleCast: false
|
||||
SpaceAfterTemplateKeyword: true
|
||||
SpaceBeforeAssignmentOperators: true
|
||||
SpaceBeforeCtorInitializerColon: true
|
||||
SpaceBeforeInheritanceColon: true
|
||||
SpaceBeforeParens: ControlStatementsExceptForEachMacros
|
||||
SpaceBeforeRangeBasedForLoopColon: true
|
||||
SpaceInEmptyParentheses: false
|
||||
SpacesBeforeTrailingComments: 1
|
||||
SpacesInAngles: false
|
||||
SpacesInContainerLiterals: false
|
||||
SpacesInCStyleCastParentheses: false
|
||||
SpacesInParentheses: false
|
||||
SpacesInSquareBrackets: false
|
||||
Standard: Cpp03
|
||||
TabWidth: 8
|
||||
UseTab: Always
|
||||
...
|
||||
27
.github/workflows/build-freebsd.yml
vendored
Normal file
27
.github/workflows/build-freebsd.yml
vendored
Normal file
@@ -0,0 +1,27 @@
|
||||
name: build on FreeBSD
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ "main", "dev" ]
|
||||
pull_request:
|
||||
branches: [ "main", "dev" ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: Build in FreeBSD
|
||||
uses: vmactions/freebsd-vm@v1
|
||||
with:
|
||||
prepare: |
|
||||
pkg install -y git cmake
|
||||
run: |
|
||||
patch -d libssh -p1 < patch/libssh-0.10.6-2-g6f1b1e76.patch
|
||||
cmake -B build -DCMAKE_BUILD_TYPE=Release
|
||||
cmake --build build
|
||||
build/mscp -h
|
||||
4
.github/workflows/build-macos.yml
vendored
4
.github/workflows/build-macos.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
runs-on: macos-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
@@ -35,7 +35,7 @@ jobs:
|
||||
- name: Configure CMake
|
||||
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
|
||||
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DOPENSSL_ROOT_DIR=${{steps.brew-prefix.outputs.HOMEBREW_PREFIX}}/opt/openssl@1.1
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DOPENSSL_ROOT_DIR=${{steps.brew-prefix.outputs.HOMEBREW_PREFIX}}/opt/openssl@3
|
||||
|
||||
- name: Build
|
||||
# Build your program with the given configuration
|
||||
|
||||
2
.github/workflows/build-ubuntu.yml
vendored
2
.github/workflows/build-ubuntu.yml
vendored
@@ -18,7 +18,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
|
||||
8
.github/workflows/codeql.yml
vendored
8
.github/workflows/codeql.yml
vendored
@@ -38,7 +38,7 @@ jobs:
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
@@ -52,7 +52,7 @@ jobs:
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v2
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
@@ -65,7 +65,7 @@ jobs:
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v2
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
|
||||
@@ -78,6 +78,6 @@ jobs:
|
||||
# ./location_of_script_within_repo/buildscript.sh
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v2
|
||||
uses: github/codeql-action/analyze@v3
|
||||
with:
|
||||
category: "/language:${{matrix.language}}"
|
||||
|
||||
24
.github/workflows/release.yml
vendored
24
.github/workflows/release.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
build-and-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
@@ -27,33 +27,19 @@ jobs:
|
||||
- name: Configure Cmake
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||
|
||||
- name: Build Containers
|
||||
run: make -C ${{github.workspace}}/build docker-build-all
|
||||
|
||||
- name: Test
|
||||
run: make -C ${{github.workspace}}/build docker-test-all
|
||||
|
||||
- name: Retrieve packages from containers
|
||||
run: make -C ${{github.workspace}}/build docker-pkg-all
|
||||
|
||||
- name: Copy mscp single binary built inside Alpine
|
||||
run: cp ${{github.workspace}}/build/mscp_alpine-3.17-x86_64.static ${{github.workspace}}/build/mscp.linux.x86.static
|
||||
- name: Build single binary mscp
|
||||
run: make -C ${{github.workspace}}/build build-single-binary
|
||||
|
||||
- name: Release
|
||||
uses: softprops/action-gh-release@v1
|
||||
with:
|
||||
files: |
|
||||
${{github.workspace}}/build/mscp_ubuntu-20.04-x86_64.deb
|
||||
${{github.workspace}}/build/mscp_ubuntu-22.04-x86_64.deb
|
||||
${{github.workspace}}/build/mscp_rocky-8.8-x86_64.rpm
|
||||
${{github.workspace}}/build/mscp_almalinux-8.8-x86_64.rpm
|
||||
${{github.workspace}}/build/mscp_alpine-3.17-x86_64.static
|
||||
${{github.workspace}}/build/mscp.linux.x86.static
|
||||
${{github.workspace}}/build/mscp.linux.x86_64.static
|
||||
|
||||
source-release:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
|
||||
20
.github/workflows/test.yml
vendored
20
.github/workflows/test.yml
vendored
@@ -12,15 +12,27 @@ env:
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
index: # see DIST_IDS and DIST_VERS lists in CMakeLists.txt
|
||||
- ubuntu-20.04
|
||||
- ubuntu-22.04
|
||||
- ubuntu-24.04
|
||||
- rocky-8.9
|
||||
- rocky-9.3
|
||||
- almalinux-9.3
|
||||
- alpine-3.19
|
||||
- arch-base
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: true
|
||||
|
||||
- name: patch to libssh
|
||||
run: patch -d libssh -p1 < patch/libssh-0.10.6-2-g6f1b1e76.patch
|
||||
|
||||
# TODO: just building docker does not require libssh. fix CMakeLists
|
||||
# TODO: just building docker images does not require libssh. fix CMakeLists
|
||||
- name: install build dependency
|
||||
run: |
|
||||
sudo apt-get update
|
||||
@@ -30,7 +42,7 @@ jobs:
|
||||
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}}
|
||||
|
||||
- name: Build Containers
|
||||
run: make -C ${{github.workspace}}/build docker-build-all
|
||||
run: make -C ${{github.workspace}}/build docker-build-${{ matrix.index }}
|
||||
|
||||
- name: Run Test
|
||||
run: make -C ${{github.workspace}}/build docker-test-all
|
||||
run: make -C ${{github.workspace}}/build docker-test-${{ matrix.index }}
|
||||
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -5,7 +5,3 @@ CMakeUserPresets.json
|
||||
.*.swp
|
||||
|
||||
include/mscp_version.h
|
||||
|
||||
dist
|
||||
*.egg-info
|
||||
__pycache__
|
||||
|
||||
214
CMakeLists.txt
214
CMakeLists.txt
@@ -11,7 +11,7 @@ find_package(Git)
|
||||
if (Git_FOUND)
|
||||
# based on https://github.com/nocnokneo/cmake-git-versioning-example
|
||||
execute_process(
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags --dirty --match "v*"
|
||||
COMMAND ${GIT_EXECUTABLE} describe --tags --match "v*"
|
||||
OUTPUT_VARIABLE GIT_DESCRIBE_VERSION
|
||||
RESULT_VARIABLE GIT_DESCRIBE_ERROR_CODE
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
@@ -51,8 +51,13 @@ if (BUILD_STATIC)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
|
||||
option(INSTALL_EXECUTABLE_ONLY OFF) # do not install libmscp
|
||||
option(USE_PODMAN OFF) # use podman instread of docker
|
||||
if(USE_PODMAN)
|
||||
message(STATUS "Use podman instead of docker")
|
||||
set(CE podman) # CE means Container Engine
|
||||
else()
|
||||
set(CE docker)
|
||||
endif()
|
||||
|
||||
|
||||
# add libssh static library
|
||||
@@ -71,12 +76,12 @@ add_subdirectory(libssh EXCLUDE_FROM_ALL)
|
||||
|
||||
|
||||
# setup mscp compile options
|
||||
set(MSCP_COMPILE_OPTS -iquote ${CMAKE_CURRENT_BINARY_DIR}/libssh/include)
|
||||
set(MSCP_BUILD_INCLUDE_DIRS
|
||||
list(APPEND MSCP_COMPILE_OPTS -iquote ${CMAKE_CURRENT_BINARY_DIR}/libssh/include)
|
||||
list(APPEND MSCP_BUILD_INCLUDE_DIRS
|
||||
${mscp_SOURCE_DIR}/src
|
||||
${CMAKE_CURRENT_BINARY_DIR}/libssh/include)
|
||||
|
||||
set(MSCP_LINK_LIBS ssh-static)
|
||||
list(APPEND MSCP_LINK_LIBS ssh-static)
|
||||
if(BUILD_CONAN)
|
||||
find_package(ZLIB REQUIRED)
|
||||
find_package(OpenSSL REQUIRED)
|
||||
@@ -85,33 +90,27 @@ if(BUILD_CONAN)
|
||||
endif()
|
||||
|
||||
|
||||
# generate version header file
|
||||
configure_file(
|
||||
${mscp_SOURCE_DIR}/include/mscp_version.h.in
|
||||
${mscp_SOURCE_DIR}/include/mscp_version.h)
|
||||
|
||||
|
||||
# libmscp.so
|
||||
set(LIBMSCP_SRC
|
||||
src/mscp.c src/ssh.c src/fileops.c src/path.c src/platform.c src/message.c)
|
||||
add_library(mscp-shared SHARED ${LIBMSCP_SRC})
|
||||
target_include_directories(mscp-shared
|
||||
PUBLIC $<BUILD_INTERFACE:${mscp_SOURCE_DIR}/include>
|
||||
$<INSTALL_INTERFACE:include>
|
||||
PRIVATE ${MSCP_BUILD_INCLUDE_DIRS})
|
||||
target_compile_options(mscp-shared PRIVATE ${MSCP_COMPILE_OPTS})
|
||||
target_link_libraries(mscp-shared PRIVATE ${MSCP_LINK_LIBS})
|
||||
set_target_properties(mscp-shared
|
||||
PROPERTIES
|
||||
OUTPUT_NAME mscp
|
||||
PUBLIC_HEADER ${mscp_SOURCE_DIR}/include/mscp.h)
|
||||
|
||||
if(!INSTALL_EXECUTABLE_ONLY)
|
||||
install(TARGETS mscp-shared)
|
||||
# Symbol check
|
||||
check_symbol_exists(htonll arpa/inet.h HAVE_HTONLL)
|
||||
check_symbol_exists(ntohll arpa/inet.h HAVE_NTOHLL)
|
||||
check_symbol_exists(strlcat string.h HAVE_STRLCAT)
|
||||
if (NOT HAVE_STRLCAT)
|
||||
list(APPEND OPENBSD_COMPAT_SRC src/openbsd-compat/strlcat.c)
|
||||
endif()
|
||||
|
||||
|
||||
# generate config.h in build dir
|
||||
configure_file(
|
||||
${mscp_SOURCE_DIR}/include/config.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/config.h)
|
||||
list(APPEND MSCP_BUILD_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/include)
|
||||
|
||||
|
||||
# libmscp.a
|
||||
set(LIBMSCP_SRC
|
||||
src/mscp.c src/ssh.c src/fileops.c src/path.c src/checkpoint.c
|
||||
src/bwlimit.c src/platform.c src/print.c src/pool.c src/strerrno.c
|
||||
${OPENBSD_COMPAT_SRC})
|
||||
add_library(mscp-static STATIC ${LIBMSCP_SRC})
|
||||
target_include_directories(mscp-static
|
||||
PRIVATE ${MSCP_BUILD_INCLUDE_DIRS} ${mscp_SOURCE_DIR}/include)
|
||||
@@ -121,11 +120,6 @@ set_target_properties(mscp-static
|
||||
PROPERTIES
|
||||
OUTPUT_NAME mscp)
|
||||
|
||||
if(!INSTALL_EXECUTABLE_ONLY)
|
||||
install(TARGETS mscp-static)
|
||||
endif()
|
||||
|
||||
|
||||
# mscp executable
|
||||
list(APPEND MSCP_LINK_LIBS m pthread)
|
||||
|
||||
@@ -147,7 +141,7 @@ configure_file(
|
||||
${mscp_SOURCE_DIR}/doc/mscp.1.in
|
||||
${PROJECT_BINARY_DIR}/mscp.1)
|
||||
|
||||
add_custom_target(update-mscp-rst
|
||||
add_custom_target(update-rst
|
||||
COMMENT "Update doc/mscp.rst from mscp.1.in"
|
||||
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}
|
||||
COMMAND
|
||||
@@ -167,98 +161,128 @@ enable_testing()
|
||||
|
||||
|
||||
|
||||
# CPACK Rules
|
||||
#set(CPACK_SET_DESTDIR true)
|
||||
set(CPACK_PACKAGE_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PACKAGE_CONTACT "Ryo Nakamura <upa@haeena.net>")
|
||||
set(CPACK_PACKAGE_DESCRIPTION
|
||||
"mscp, copy files over multiple ssh connections")
|
||||
|
||||
execute_process(COMMAND uname -m
|
||||
OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
if(UNIX AND NOT APPLE) # on linux
|
||||
execute_process(COMMAND
|
||||
bash "-c" "cat /etc/os-release|grep '^ID='|cut -d '=' -f 2|tr -d '\"'"
|
||||
OUTPUT_VARIABLE DIST_NAME OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND
|
||||
bash "-c" "cat /etc/os-release|grep '^VERSION_ID='|cut -d '=' -f 2|tr -d '\"'"
|
||||
OUTPUT_VARIABLE DIST_VER OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
execute_process(COMMAND
|
||||
bash "-c" "${mscp_SOURCE_DIR}/scripts/print-install-deps.sh ${DIST_NAME}-${DIST_VER}"
|
||||
OUTPUT_VARIABLE DIST_DEP OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
set(PACKAGE_FILE_NAME
|
||||
${PROJECT_NAME}_${DIST_NAME}-${DIST_VER}-${ARCH})
|
||||
|
||||
set(CPACK_DEBIAN_FILE_NAME ${PACKAGE_FILE_NAME}.deb)
|
||||
set(CPACK_DEBIAN_PACKAGE_DEPENDS ${DIST_DEP})
|
||||
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/upa/mscp")
|
||||
|
||||
set(CPACK_RPM_FILE_NAME ${PACKAGE_FILE_NAME}.rpm)
|
||||
set(CPACK_RPM_PACKAGE_REQUIRES ${DIST_DEP})
|
||||
set(CPACK_RPM_PACKAGE_HOMEPAGE "https://github.com/upa/mscp")
|
||||
set(CPACK_RPM_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION})
|
||||
set(CPACK_RPM_PACKAGE_LICENSE "GPLv3")
|
||||
endif() # on linux
|
||||
|
||||
include(CPack)
|
||||
|
||||
|
||||
|
||||
# Custom targets to build and test mscp in docker containers.
|
||||
# foreach(IN ZIP_LISTS) (cmake >= 3.17) can shorten the following lists.
|
||||
# However, ubuntu 20.04 has cmake 3.16.3. So this is a roundabout trick.
|
||||
list(APPEND DIST_NAMES ubuntu ubuntu rocky almalinux alpine)
|
||||
list(APPEND DIST_VERS 20.04 22.04 8.8 8.8 3.17)
|
||||
list(APPEND DIST_PKGS deb deb rpm rpm static)
|
||||
#
|
||||
# When edit DIST_IDS and DIST_VERS, also edit .github/workflows/test.yaml
|
||||
list(APPEND DIST_IDS ubuntu ubuntu ubuntu rocky rocky almalinux alpine arch)
|
||||
list(APPEND DIST_VERS 20.04 22.04 24.04 8.9 9.3 9.3 3.19 base)
|
||||
|
||||
list(LENGTH DIST_NAMES _DIST_LISTLEN)
|
||||
list(LENGTH DIST_IDS _DIST_LISTLEN)
|
||||
math(EXPR DIST_LISTLEN "${_DIST_LISTLEN} - 1")
|
||||
|
||||
foreach(x RANGE ${DIST_LISTLEN})
|
||||
list(GET DIST_NAMES ${x} DIST_NAME)
|
||||
list(GET DIST_IDS ${x} DIST_ID)
|
||||
list(GET DIST_VERS ${x} DIST_VER)
|
||||
list(GET DIST_PKGS ${x} DIST_PKG)
|
||||
|
||||
set(DOCKER_IMAGE mscp-${DIST_NAME}:${DIST_VER})
|
||||
set(DOCKER_INDEX ${DIST_NAME}-${DIST_VER})
|
||||
set(PKG_FILE_NAME
|
||||
mscp_${DIST_NAME}-${DIST_VER}-${ARCH}.${DIST_PKG})
|
||||
set(DOCKER_IMAGE mscp-${DIST_ID}:${DIST_VER})
|
||||
set(DOCKER_INDEX ${DIST_ID}-${DIST_VER})
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
|
||||
--dont-install --platform Linux-${DIST_ID}
|
||||
OUTPUT_VARIABLE REQUIREDPKGS
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
add_custom_target(docker-build-${DOCKER_INDEX}
|
||||
COMMENT "Build mscp in ${DOCKER_IMAGE} container"
|
||||
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
|
||||
COMMAND
|
||||
docker build -t ${DOCKER_IMAGE} -f docker/${DOCKER_INDEX}.Dockerfile .)
|
||||
${CE} build --build-arg REQUIREDPKGS=${REQUIREDPKGS}
|
||||
-t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
|
||||
|
||||
add_custom_target(docker-build-${DOCKER_INDEX}-no-cache
|
||||
COMMENT "Build mscp in ${DOCKER_IMAGE} container"
|
||||
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
|
||||
COMMAND
|
||||
docker build --no-cache -t ${DOCKER_IMAGE} -f docker/${DOCKER_INDEX}.Dockerfile .)
|
||||
${CE} build --build-arg REQUIREDPKGS=${REQUIREDPKGS} --no-cache
|
||||
-t ${DOCKER_IMAGE} -f Dockerfile/${DOCKER_INDEX}.Dockerfile .)
|
||||
|
||||
add_custom_target(docker-test-${DOCKER_INDEX}
|
||||
COMMENT "Test mscp in ${DOCKER_IMAGE} container"
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
COMMAND
|
||||
docker run --init --rm --sysctl net.ipv6.conf.all.disable_ipv6=0
|
||||
${CE} run --init --rm --privileged
|
||||
--sysctl net.ipv6.conf.all.disable_ipv6=0
|
||||
--add-host=ip6-localhost:::1
|
||||
${DOCKER_IMAGE} /mscp/scripts/test-in-container.sh)
|
||||
|
||||
add_custom_target(docker-pkg-${DOCKER_INDEX}
|
||||
COMMENT "Retrieve mscp package from ${DOCKER_IMAGE} container"
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
|
||||
COMMAND
|
||||
docker run --rm -v ${CMAKE_BINARY_DIR}:/out ${DOCKER_IMAGE}
|
||||
cp /mscp/build/${PKG_FILE_NAME} /out/)
|
||||
|
||||
list(APPEND DOCKER_BUILDS docker-build-${DOCKER_INDEX})
|
||||
list(APPEND DOCKER_BUILDS_NO_CACHE docker-build-${DOCKER_INDEX}-no-cache)
|
||||
list(APPEND DOCKER_TESTS docker-test-${DOCKER_INDEX})
|
||||
list(APPEND DOCKER_PKGS docker-pkg-${DOCKER_INDEX})
|
||||
endforeach()
|
||||
|
||||
add_custom_target(docker-build-all DEPENDS ${DOCKER_BUILDS})
|
||||
add_custom_target(docker-build-all-no-cache DEPENDS ${DOCKER_BUILDS_NO_CACHE})
|
||||
add_custom_target(docker-test-all DEPENDS ${DOCKER_TESTS})
|
||||
add_custom_target(docker-pkg-all DEPENDS ${DOCKER_PKGS})
|
||||
|
||||
|
||||
### debuild-related definitions
|
||||
|
||||
set(DEBBUILDCONTAINER mscp-build-deb)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
|
||||
--dont-install --platform Linux-ubuntu
|
||||
OUTPUT_VARIABLE REQUIREDPKGS_DEB
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
add_custom_target(build-deb
|
||||
COMMENT "build mscp deb files inside a container"
|
||||
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
|
||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/debbuild
|
||||
COMMAND
|
||||
${CE} build --build-arg REQUIREDPKGS=${REQUIREDPKGS_DEB}
|
||||
-t ${DEBBUILDCONTAINER} -f Dockerfile/build-deb.Dockerfile .
|
||||
COMMAND
|
||||
${CE} run --rm -v ${CMAKE_BINARY_DIR}:/out ${DEBBUILDCONTAINER}
|
||||
cp -r /debbuild /out/)
|
||||
|
||||
|
||||
### rpmbuild-related definitions
|
||||
|
||||
# generate files for rpmbuild
|
||||
configure_file(
|
||||
${mscp_SOURCE_DIR}/rpm/mscp.spec.in
|
||||
${mscp_SOURCE_DIR}/rpm/mscp.spec
|
||||
@ONLY)
|
||||
#configure_file(
|
||||
# ${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile.in
|
||||
# ${mscp_SOURCE_DIR}/Dockerfile/build-srpm.Dockerfile
|
||||
# @ONLY)
|
||||
|
||||
# Custom target to build mscp as a src.rpm in docker.
|
||||
set(RPMBUILDCONTAINER mscp-build-srpm)
|
||||
execute_process(
|
||||
COMMAND ${CMAKE_SOURCE_DIR}/scripts/install-build-deps.sh
|
||||
--dont-install --platform Linux-rocky
|
||||
OUTPUT_VARIABLE REQUIREDPKGS_RPM
|
||||
OUTPUT_STRIP_TRAILING_WHITESPACE)
|
||||
|
||||
add_custom_target(build-srpm
|
||||
COMMENT "Build mscp src.rpm inside a container"
|
||||
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
|
||||
COMMAND
|
||||
${CE} build --build-arg REQUIREDPKGS=${REQUIREDPKGS_RPM}
|
||||
--build-arg MSCP_VERSION=${MSCP_VERSION}
|
||||
-t ${RPMBUILDCONTAINER} -f Dockerfile/build-srpm.Dockerfile .
|
||||
COMMAND
|
||||
${CE} run --rm -v ${CMAKE_BINARY_DIR}:/out ${RPMBUILDCONTAINER}
|
||||
bash -c "cp /root/rpmbuild/SRPMS/mscp-*.src.rpm /out/")
|
||||
|
||||
### single-binary-build-related definitions
|
||||
|
||||
# Custom target to get single binary mscp
|
||||
set(SINGLEBINARYFILE mscp.linux.${CMAKE_SYSTEM_PROCESSOR}.static)
|
||||
add_custom_target(build-single-binary
|
||||
COMMENT "Build mscp as a single binary in alpine conatiner"
|
||||
WORKING_DIRECTORY ${mscp_SOURCE_DIR}
|
||||
BYPRODUCTS ${CMAKE_BINARY_DIR}/${SINGLEBINARYFILE}
|
||||
DEPENDS docker-build-alpine-3.19
|
||||
COMMAND
|
||||
${CE} run --rm -v ${CMAKE_BINARY_DIR}:/out mscp-alpine:3.19
|
||||
cp /mscp/build/mscp /out/${SINGLEBINARYFILE})
|
||||
|
||||
|
||||
add_custom_target(build-pkg-all
|
||||
DEPENDS build-deb build-srpm build-single-binary)
|
||||
|
||||
7
Dockerfile/README.md
Normal file
7
Dockerfile/README.md
Normal file
@@ -0,0 +1,7 @@
|
||||
|
||||
Dockerfiles for building and testing mscp.
|
||||
|
||||
cmake provides custom targets to build and test mscp in the containers
|
||||
See `make docker-*` targets. `make docker-build-all` builds all
|
||||
container images, and `make docker-test-all` runs the test in all
|
||||
container images.
|
||||
40
Dockerfile/almalinux-9.3.Dockerfile
Normal file
40
Dockerfile/almalinux-9.3.Dockerfile
Normal file
@@ -0,0 +1,40 @@
|
||||
FROM almalinux:9.3
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
# install pytest, sshd for test, and rpm-build
|
||||
RUN set -ex && yum -y install \
|
||||
${REQUIREDPKGS} python3 python3-pip python3-devel \
|
||||
openssh openssh-server openssh-clients rpm-build
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
RUN rm -rf /run/nologin
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
50
Dockerfile/alpine-3.19.Dockerfile
Normal file
50
Dockerfile/alpine-3.19.Dockerfile
Normal file
@@ -0,0 +1,50 @@
|
||||
FROM alpine:3.19
|
||||
|
||||
# do not use REQUIREDPKGS build argument because
|
||||
# this Dockerfile compiles mscp with conan,so we do not need
|
||||
# libssl-dev and zlib-dev
|
||||
|
||||
# Build mscp with conan to create single binary mscp
|
||||
|
||||
RUN apk add --no-cache \
|
||||
gcc make cmake libc-dev \
|
||||
linux-headers openssh bash perl \
|
||||
python3 py3-pip python3-dev py3-pytest g++
|
||||
|
||||
RUN pip3 install --break-system-packages conan
|
||||
|
||||
# preparation for sshd
|
||||
RUN ssh-keygen -A \
|
||||
&& mkdir /var/run/sshd \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN addgroup -S test \
|
||||
&& adduser -S test -G test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
|
||||
# Build mscp as a single binary
|
||||
RUN conan profile detect --force
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& conan install . --output-folder=build --build=missing \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
|
||||
-DBUILD_CONAN=ON -DBUILD_STATIC=ON \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
|
||||
36
Dockerfile/arch-base.Dockerfile
Normal file
36
Dockerfile/arch-base.Dockerfile
Normal file
@@ -0,0 +1,36 @@
|
||||
FROM archlinux:base
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
# install pyest and openssh for test
|
||||
RUN set -ex && pacman -Syy && pacman --noconfirm -S ${REQUIREDPKGS} openssh python-pytest
|
||||
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# disable PerSourcePenaltie, which would distrub test:
|
||||
# https://undeadly.org/cgi?action=article;sid=20240607042157
|
||||
RUN echo "PerSourcePenalties=no" > /etc/ssh/sshd_config.d/90-mscp-test.conf
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
20
Dockerfile/build-deb.Dockerfile
Normal file
20
Dockerfile/build-deb.Dockerfile
Normal file
@@ -0,0 +1,20 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
|
||||
${REQUIREDPKGS} ca-certificates \
|
||||
build-essential devscripts debhelper gcc make cmake
|
||||
|
||||
ARG mscpdir="/debbuild/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& debuild -us -uc -S \
|
||||
&& mv ${mscpdir} /
|
||||
|
||||
# Then all debuild output files exsit at /debbuild
|
||||
|
||||
22
Dockerfile/build-srpm.Dockerfile
Normal file
22
Dockerfile/build-srpm.Dockerfile
Normal file
@@ -0,0 +1,22 @@
|
||||
FROM rockylinux:9
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
ARG MSCP_VERSION
|
||||
|
||||
# install pytest, sshd for test, and rpm-build
|
||||
RUN set -ex && yum -y install ${REQUIREDPKGS} rpm-build rpmdevtools
|
||||
|
||||
ARG mscpdir="/mscp-${MSCP_VERSION}"
|
||||
ARG mscptgz="mscp-${MSCP_VERSION}.tar.gz"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# prepare rpmbuild
|
||||
RUN rpmdev-setuptree \
|
||||
&& rm -rf ${mscpdir}/build \
|
||||
&& tar zcvf /${mscptgz} --exclude-vcs ${mscpdir} \
|
||||
&& cp /${mscptgz} ~/rpmbuild/SOURCES/ \
|
||||
&& cp ${mscpdir}/rpm/mscp.spec ~/rpmbuild/SPECS/
|
||||
|
||||
# build rpm and src.rpm
|
||||
RUN rpmbuild -ba ~/rpmbuild/SPECS/mscp.spec
|
||||
42
Dockerfile/rocky-8.9.Dockerfile
Normal file
42
Dockerfile/rocky-8.9.Dockerfile
Normal file
@@ -0,0 +1,42 @@
|
||||
FROM rockylinux:8.9
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
# install pytest, sshd for test, and rpm-build
|
||||
RUN set -ex && yum -y install \
|
||||
${REQUIREDPKGS} \
|
||||
python3 python3-pip python3-devel \
|
||||
openssh openssh-server openssh-clients rpm-build
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
RUN rm -rf /run/nologin
|
||||
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
42
Dockerfile/rocky-9.3.Dockerfile
Normal file
42
Dockerfile/rocky-9.3.Dockerfile
Normal file
@@ -0,0 +1,42 @@
|
||||
FROM rockylinux:9.3
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
# install pytest, sshd for test, and rpm-build
|
||||
RUN set -ex && yum -y install \
|
||||
${REQUIREDPKGS} \
|
||||
python3 python3-pip python3-devel \
|
||||
openssh openssh-server openssh-clients rpm-build
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
RUN rm -rf /run/nologin
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
|
||||
38
Dockerfile/ubuntu-20.04.Dockerfile
Normal file
38
Dockerfile/ubuntu-20.04.Dockerfile
Normal file
@@ -0,0 +1,38 @@
|
||||
FROM ubuntu:20.04
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
|
||||
${REQUIREDPKGS} ca-certificates python3 python3-pip python3-dev openssh-server
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
|
||||
37
Dockerfile/ubuntu-22.04.Dockerfile
Normal file
37
Dockerfile/ubuntu-22.04.Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
|
||||
${REQUIREDPKGS} ca-certificates python3 python3-pip python3-dev openssh-server
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
37
Dockerfile/ubuntu-24.04.Dockerfile
Normal file
37
Dockerfile/ubuntu-24.04.Dockerfile
Normal file
@@ -0,0 +1,37 @@
|
||||
FROM ubuntu:24.04
|
||||
|
||||
ARG REQUIREDPKGS
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
|
||||
${REQUIREDPKGS} ca-certificates openssh-server vim-tiny \
|
||||
python3 python3-pip python3-dev python3-pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& cat /root/.ssh/id_rsa.pub > /root/.ssh/authorized_keys
|
||||
|
||||
# create test user
|
||||
RUN useradd -m -d /home/test test \
|
||||
&& echo "test:userpassword" | chpasswd \
|
||||
&& mkdir -p /home/test/.ssh \
|
||||
&& ssh-keygen -f /home/test/.ssh/id_rsa_test -N "keypassphrase" \
|
||||
&& cat /home/test/.ssh/id_rsa_test.pub >> /home/test/.ssh/authorized_keys \
|
||||
&& chown -R test:test /home/test \
|
||||
&& chown -R test:test /home/test/.ssh
|
||||
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make -j 2 \
|
||||
&& make install
|
||||
2
Doxyfile
2
Doxyfile
@@ -9,5 +9,5 @@ GENERATE_MAN = NO
|
||||
|
||||
SOURCE_BROWSER = YES
|
||||
|
||||
INPUT = src include mscp
|
||||
INPUT = src include
|
||||
|
||||
|
||||
39
README.md
39
README.md
@@ -1,6 +1,10 @@
|
||||
# mscp: multi-threaded scp
|
||||
|
||||
[](https://github.com/upa/mscp/actions/workflows/build-ubuntu.yml) [](https://github.com/upa/mscp/actions/workflows/build-macos.yml) [](https://github.com/upa/mscp/actions/workflows/test.yml)
|
||||
[](https://github.com/upa/mscp/actions/workflows/build-ubuntu.yml)
|
||||
[](https://github.com/upa/mscp/actions/workflows/build-macos.yml)
|
||||
[](https://github.com/upa/mscp/actions/workflows/build-freebsd.yml)
|
||||
[](https://github.com/upa/mscp/actions/workflows/test.yml)
|
||||
|
||||
|
||||
|
||||
`mscp`, a variant of `scp`, copies files over multiple SSH (SFTP)
|
||||
@@ -11,7 +15,7 @@ transfer time for a lot of/large files over networks.
|
||||
You can use `mscp` like `scp`, for example:
|
||||
|
||||
```shell-session
|
||||
$ mscp user@example.com:srcfile /tmp/dstfile
|
||||
$ mscp srcfile user@example.com:dstfile
|
||||
```
|
||||
|
||||
Remote hosts only need to run standard `sshd` supporting the SFTP
|
||||
@@ -23,10 +27,11 @@ https://github.com/upa/mscp/assets/184632/19230f57-be7f-4ef0-98dd-cb4c460f570d
|
||||
|
||||
--------------------------------------------------------------------
|
||||
|
||||
Differences from `scp` on usage:
|
||||
Major differences from `scp` on usage:
|
||||
|
||||
- Remote-to-remote copy is not supported.
|
||||
- `-r` option is not needed to transfer directories.
|
||||
- Checkpointing for resuming failed transfer is supported.
|
||||
- and any other differences I have not implemented and noticed.
|
||||
|
||||
Paper:
|
||||
@@ -37,7 +42,11 @@ Paper:
|
||||
- macOS
|
||||
|
||||
```console
|
||||
# Homebrew
|
||||
brew install upa/tap/mscp
|
||||
|
||||
# MacPorts
|
||||
sudo port install mscp
|
||||
```
|
||||
|
||||
- Ubuntu
|
||||
@@ -46,19 +55,15 @@ sudo add-apt-repository ppa:upaa/mscp
|
||||
sudo apt-get install mscp
|
||||
```
|
||||
|
||||
- Rocky 8.8
|
||||
- RHEL-based distributions
|
||||
```console
|
||||
yum install https://github.com/upa/mscp/releases/latest/download/mscp_rocky-8.8-x86_64.rpm
|
||||
sudo dnf copr enable upaaa/mscp
|
||||
sudo dnf install mscp
|
||||
```
|
||||
|
||||
- Alma 8.8
|
||||
- Single binary `mscp` for x86_64 (not optimal performance)
|
||||
```console
|
||||
yum install https://github.com/upa/mscp/releases/latest/download/mscp_almalinux-8.8-x86_64.rpm
|
||||
```
|
||||
|
||||
- Linux with single binary `mscp` (x86_64 only, and not optimal performance)
|
||||
```console
|
||||
wget https://github.com/upa/mscp/releases/latest/download/mscp.linux.x86.static -O /usr/local/bin/mscp
|
||||
wget https://github.com/upa/mscp/releases/latest/download/mscp.linux.x86_64.static -O /usr/local/bin/mscp
|
||||
chmod 755 /usr/local/bin/mscp
|
||||
```
|
||||
|
||||
@@ -70,7 +75,9 @@ patch introduces asynchronous SFTP Write, which is derived from
|
||||
https://github.com/limes-datentechnik-gmbh/libssh (see [Re: SFTP Write
|
||||
async](https://archive.libssh.org/libssh/2020-06/0000004.html)).
|
||||
|
||||
Currently macOS and Linux (Ubuntu, Rocky and Alma) are supported.
|
||||
We test building mscp on Linux (Ubuntu, Rocky, Alma, and Alpine),
|
||||
macOS, and FreeBSD.
|
||||
|
||||
|
||||
```console
|
||||
# clone this repository
|
||||
@@ -89,7 +96,7 @@ mkdir build && cd build
|
||||
cmake ..
|
||||
|
||||
# in macOS, you may need OPENSSL_ROOT_DIR for cmake:
|
||||
# cmake .. -DOPENSSL_ROOT_DIR=$(brew --prefix)/opt/openssl@1.1
|
||||
# cmake .. -DOPENSSL_ROOT_DIR=$(brew --prefix)/opt/openssl@3
|
||||
|
||||
# build
|
||||
make
|
||||
@@ -99,10 +106,10 @@ make install
|
||||
```
|
||||
|
||||
Source tar balls (`mscp-X.X.X.tar.gz`, not `Source code`) in
|
||||
[Releases page](https://github.com/upa/mscp/releases) contains the patched version
|
||||
[Releases page](https://github.com/upa/mscp/releases) contain the patched version
|
||||
of libssh. So you can start from cmake with it.
|
||||
|
||||
|
||||
## Documentation
|
||||
|
||||
[manpage](/doc/mscp.rst) is available.
|
||||
[manpage](/doc/mscp.rst) is available.
|
||||
|
||||
@@ -1,325 +0,0 @@
|
||||
# - Try to find GSSAPI
|
||||
# Once done this will define
|
||||
#
|
||||
# KRB5_CONFIG - Path to krb5-config
|
||||
# GSSAPI_ROOT_DIR - Set this variable to the root installation of GSSAPI
|
||||
#
|
||||
# Read-Only variables:
|
||||
# GSSAPI_FLAVOR_MIT - set to TURE if MIT Kerberos has been found
|
||||
# GSSAPI_FLAVOR_HEIMDAL - set to TRUE if Heimdal Keberos has been found
|
||||
# GSSAPI_FOUND - system has GSSAPI
|
||||
# GSSAPI_INCLUDE_DIR - the GSSAPI include directory
|
||||
# GSSAPI_LIBRARIES - Link these to use GSSAPI
|
||||
# GSSAPI_DEFINITIONS - Compiler switches required for using GSSAPI
|
||||
#
|
||||
#=============================================================================
|
||||
# Copyright (c) 2013 Andreas Schneider <asn@cryptomilk.org>
|
||||
#
|
||||
# Distributed under the OSI-approved BSD License (the "License");
|
||||
# see accompanying file Copyright.txt for details.
|
||||
#
|
||||
# This software is distributed WITHOUT ANY WARRANTY; without even the
|
||||
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
# See the License for more information.
|
||||
#=============================================================================
|
||||
#
|
||||
|
||||
find_path(GSSAPI_ROOT_DIR
|
||||
NAMES
|
||||
include/gssapi.h
|
||||
include/gssapi/gssapi.h
|
||||
HINTS
|
||||
${_GSSAPI_ROOT_HINTS}
|
||||
PATHS
|
||||
${_GSSAPI_ROOT_PATHS}
|
||||
)
|
||||
mark_as_advanced(GSSAPI_ROOT_DIR)
|
||||
|
||||
if (UNIX)
|
||||
find_program(KRB5_CONFIG
|
||||
NAMES
|
||||
krb5-config
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/bin
|
||||
/opt/local/bin)
|
||||
mark_as_advanced(KRB5_CONFIG)
|
||||
|
||||
if (KRB5_CONFIG)
|
||||
# Check if we have MIT KRB5
|
||||
execute_process(
|
||||
COMMAND
|
||||
${KRB5_CONFIG} --vendor
|
||||
RESULT_VARIABLE
|
||||
_GSSAPI_VENDOR_RESULT
|
||||
OUTPUT_VARIABLE
|
||||
_GSSAPI_VENDOR_STRING)
|
||||
|
||||
if ((_GSSAPI_VENDOR_STRING MATCHES ".*Massachusetts.*") OR (_GSSAPI_VENDOR_STRING
|
||||
MATCHES ".*MITKerberosShim.*"))
|
||||
set(GSSAPI_FLAVOR_MIT TRUE)
|
||||
else()
|
||||
execute_process(
|
||||
COMMAND
|
||||
${KRB5_CONFIG} --libs gssapi
|
||||
RESULT_VARIABLE
|
||||
_GSSAPI_LIBS_RESULT
|
||||
OUTPUT_VARIABLE
|
||||
_GSSAPI_LIBS_STRING)
|
||||
|
||||
if (_GSSAPI_LIBS_STRING MATCHES ".*roken.*")
|
||||
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# Get the include dir
|
||||
execute_process(
|
||||
COMMAND
|
||||
${KRB5_CONFIG} --cflags gssapi
|
||||
RESULT_VARIABLE
|
||||
_GSSAPI_INCLUDE_RESULT
|
||||
OUTPUT_VARIABLE
|
||||
_GSSAPI_INCLUDE_STRING)
|
||||
string(REGEX REPLACE "(\r?\n)+$" "" _GSSAPI_INCLUDE_STRING "${_GSSAPI_INCLUDE_STRING}")
|
||||
string(REGEX REPLACE " *-I" "" _GSSAPI_INCLUDEDIR "${_GSSAPI_INCLUDE_STRING}")
|
||||
endif()
|
||||
|
||||
if (NOT GSSAPI_FLAVOR_MIT AND NOT GSSAPI_FLAVOR_HEIMDAL)
|
||||
# Check for HEIMDAL
|
||||
find_package(PkgConfig)
|
||||
if (PKG_CONFIG_FOUND)
|
||||
pkg_check_modules(_GSSAPI heimdal-gssapi)
|
||||
endif (PKG_CONFIG_FOUND)
|
||||
|
||||
if (_GSSAPI_FOUND)
|
||||
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
|
||||
else()
|
||||
find_path(_GSSAPI_ROKEN
|
||||
NAMES
|
||||
roken.h
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/include
|
||||
${_GSSAPI_INCLUDEDIR})
|
||||
if (_GSSAPI_ROKEN)
|
||||
set(GSSAPI_FLAVOR_HEIMDAL TRUE)
|
||||
endif()
|
||||
endif ()
|
||||
endif()
|
||||
endif (UNIX)
|
||||
|
||||
find_path(GSSAPI_INCLUDE_DIR
|
||||
NAMES
|
||||
gssapi.h
|
||||
gssapi/gssapi.h
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/include
|
||||
${_GSSAPI_INCLUDEDIR}
|
||||
)
|
||||
|
||||
if (GSSAPI_FLAVOR_MIT)
|
||||
find_library(GSSAPI_LIBRARY
|
||||
NAMES
|
||||
gssapi_krb5
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(KRB5_LIBRARY
|
||||
NAMES
|
||||
krb5
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(K5CRYPTO_LIBRARY
|
||||
NAMES
|
||||
k5crypto
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(COM_ERR_LIBRARY
|
||||
NAMES
|
||||
com_err
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
if (GSSAPI_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${GSSAPI_LIBRARY}
|
||||
)
|
||||
endif (GSSAPI_LIBRARY)
|
||||
|
||||
if (KRB5_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${KRB5_LIBRARY}
|
||||
)
|
||||
endif (KRB5_LIBRARY)
|
||||
|
||||
if (K5CRYPTO_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${K5CRYPTO_LIBRARY}
|
||||
)
|
||||
endif (K5CRYPTO_LIBRARY)
|
||||
|
||||
if (COM_ERR_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${COM_ERR_LIBRARY}
|
||||
)
|
||||
endif (COM_ERR_LIBRARY)
|
||||
endif (GSSAPI_FLAVOR_MIT)
|
||||
|
||||
if (GSSAPI_FLAVOR_HEIMDAL)
|
||||
find_library(GSSAPI_LIBRARY
|
||||
NAMES
|
||||
gssapi
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(KRB5_LIBRARY
|
||||
NAMES
|
||||
krb5
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(HCRYPTO_LIBRARY
|
||||
NAMES
|
||||
hcrypto
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(COM_ERR_LIBRARY
|
||||
NAMES
|
||||
com_err
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(HEIMNTLM_LIBRARY
|
||||
NAMES
|
||||
heimntlm
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(HX509_LIBRARY
|
||||
NAMES
|
||||
hx509
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(ASN1_LIBRARY
|
||||
NAMES
|
||||
asn1
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(WIND_LIBRARY
|
||||
NAMES
|
||||
wind
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
find_library(ROKEN_LIBRARY
|
||||
NAMES
|
||||
roken
|
||||
PATHS
|
||||
${GSSAPI_ROOT_DIR}/lib
|
||||
${_GSSAPI_LIBDIR}
|
||||
)
|
||||
|
||||
if (GSSAPI_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${GSSAPI_LIBRARY}
|
||||
)
|
||||
endif (GSSAPI_LIBRARY)
|
||||
|
||||
if (KRB5_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${KRB5_LIBRARY}
|
||||
)
|
||||
endif (KRB5_LIBRARY)
|
||||
|
||||
if (HCRYPTO_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${HCRYPTO_LIBRARY}
|
||||
)
|
||||
endif (HCRYPTO_LIBRARY)
|
||||
|
||||
if (COM_ERR_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${COM_ERR_LIBRARY}
|
||||
)
|
||||
endif (COM_ERR_LIBRARY)
|
||||
|
||||
if (HEIMNTLM_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${HEIMNTLM_LIBRARY}
|
||||
)
|
||||
endif (HEIMNTLM_LIBRARY)
|
||||
|
||||
if (HX509_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${HX509_LIBRARY}
|
||||
)
|
||||
endif (HX509_LIBRARY)
|
||||
|
||||
if (ASN1_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${ASN1_LIBRARY}
|
||||
)
|
||||
endif (ASN1_LIBRARY)
|
||||
|
||||
if (WIND_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${WIND_LIBRARY}
|
||||
)
|
||||
endif (WIND_LIBRARY)
|
||||
|
||||
if (ROKEN_LIBRARY)
|
||||
set(GSSAPI_LIBRARIES
|
||||
${GSSAPI_LIBRARIES}
|
||||
${WIND_LIBRARY}
|
||||
)
|
||||
endif (ROKEN_LIBRARY)
|
||||
endif (GSSAPI_FLAVOR_HEIMDAL)
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
find_package_handle_standard_args(GSSAPI DEFAULT_MSG GSSAPI_LIBRARIES GSSAPI_INCLUDE_DIR)
|
||||
|
||||
if (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
|
||||
set(GSSAPI_FOUND TRUE)
|
||||
endif (GSSAPI_INCLUDE_DIRS AND GSSAPI_LIBRARIES)
|
||||
|
||||
# show the GSSAPI_INCLUDE_DIRS and GSSAPI_LIBRARIES variables only in the advanced view
|
||||
mark_as_advanced(GSSAPI_INCLUDE_DIRS GSSAPI_LIBRARIES)
|
||||
62
debian/changelog
vendored
62
debian/changelog
vendored
@@ -1,4 +1,64 @@
|
||||
mscp (0.1.3) UNRELEASED; urgency=medium
|
||||
mscp (0.2.2) UNRELEASED; urgency=medium
|
||||
|
||||
* bump cmake_minimum_version on libssh (#32)
|
||||
* fix quiet mode (#30)
|
||||
* use openssl@3 on macOS (#29)
|
||||
* add archlinux support (#28)
|
||||
|
||||
-- Ryo Nakamura <upa@haeena.net> Wed, 16 Apr 2025 17:01:17 +0900
|
||||
|
||||
mscp (0.2.1) unstable; urgency=medium
|
||||
|
||||
* fix broken checkpoint files when copying multiple files (#16)
|
||||
* fix broken password inputs for resume transfers (#17 and #18)
|
||||
* add support [kKmMgG] units for -s, -S, and -b options (#20)
|
||||
* change the default min chunk size to 16MB (#20)
|
||||
* change the default max chunk size to filesize / (nr_conn * 4) (#20)
|
||||
* -s and -S accept integers other than multiples of page sizes (#20)
|
||||
* help now shows available ciphers and HMACs (#20)
|
||||
|
||||
-- Ryo Nakamura <upa@haeena.net> Sat, 11 May 2024 14:49:52 +0900
|
||||
|
||||
mscp (0.2.0) unstable; urgency=medium
|
||||
|
||||
* add -J DESTINATION option for ProxyJump (#15)
|
||||
* add -o SSH_OPTION option
|
||||
* add -L LIMIT_BITRATE option (#14)
|
||||
* add keyboard interactive authentication support. Also, we have manually
|
||||
tested that mscp works with cisco DUO MFA (#2)
|
||||
* remove -H disable host key check option (ssh_config or -o option can do
|
||||
this instead)
|
||||
* fix copying files of permission r--r--r--
|
||||
* update github actions: checkout v3 to v4, and codeql from v2 to v3
|
||||
* add ubuntu 24.04 test
|
||||
|
||||
-- Ryo Nakamura <upa@haeena.net> Mon, 15 Apr 2024 00:05:20 +0900
|
||||
|
||||
mscp (0.1.5) unstable; urgency=medium
|
||||
|
||||
* add support for resuming failed transfer (#5 and #10)
|
||||
* remove the list structure derived from the linux kernel and refactoring
|
||||
for this change.
|
||||
* add and fix test cases (changing port number and number of connections)
|
||||
|
||||
-- Ryo Nakamura <upa@haeena.net> Thu, 14 Mar 2024 12:51:23 +0900
|
||||
|
||||
mscp (0.1.4) unstable; urgency=medium
|
||||
|
||||
* add a test for builds on FreeBSD
|
||||
* updat container images for tests
|
||||
* dropp support for Python bindings
|
||||
* clean up error message handling
|
||||
* add MSCP_SSH_AUTH_PASSWORD/PASSPHRASE environment variables
|
||||
to pass passwords to MSCP without interactive input (issue #9)
|
||||
* add a -p option to preserve timestamps
|
||||
* add -4 and -6 options to use IPv4 or IPv6, respectively
|
||||
* introduc .clang-format, which is derived from the Linux kernel
|
||||
* fix the manpage
|
||||
|
||||
-- Ryo Nakamura <upa@haeena.net> Wed, 07 Feb 2024 15:56:58 +0900
|
||||
|
||||
mscp (0.1.3) unstable; urgency=medium
|
||||
|
||||
* add -I option for inserting intervals between SSH attempts (issue #7)
|
||||
* add -P option, equivalent to -p (just for compatibility)
|
||||
|
||||
4
debian/rules
vendored
4
debian/rules
vendored
@@ -4,10 +4,6 @@
|
||||
dh $@
|
||||
|
||||
|
||||
override_dh_auto_configure:
|
||||
dh_auto_configure -- \
|
||||
-DINSTALL_EXECUTABLE_ONLY=ON
|
||||
|
||||
override_dh_auto_test:
|
||||
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
|
||||
# Document
|
||||
|
||||
The base file of documents is `mscp.1.in`. The manpage of mscp and
|
||||
`doc/mscp.rst` are generated from `mscp.1.in`.
|
||||
|
||||
When `mscp.1.in` is changed, update `doc/mscp.rst` by:
|
||||
|
||||
1. `cd build`
|
||||
2. `cmake ..`
|
||||
3. `make update-mscp-rst`
|
||||
74
doc/RELEASE.md
Normal file
74
doc/RELEASE.md
Normal file
@@ -0,0 +1,74 @@
|
||||
|
||||
|
||||
## Build mscp as deb package
|
||||
|
||||
`make build-deb` produces a mscp deb package and related files. This
|
||||
target builds mscp with `debuild` inside a docker container
|
||||
(Dockerfile is `docker/build-deb.Docerfile`).
|
||||
|
||||
|
||||
```console
|
||||
mkdir build && cd build && cmake ..
|
||||
make build-deb
|
||||
```
|
||||
|
||||
After that:
|
||||
|
||||
```console
|
||||
$ ls debbuild
|
||||
mscp_0.1.4.dsc mscp_0.1.4_source.buildinfo mscp_0.1.4.tar.xz
|
||||
mscp_0.1.4_source.build mscp_0.1.4_source.changes
|
||||
```
|
||||
|
||||
### To publush mscp in launchpad PPA:
|
||||
|
||||
1. write changes in `debian/changelog` at main branch (the date
|
||||
command needed here is `date -R`)
|
||||
2. switch to `ppa-focal` or `ppa-jammy` branch
|
||||
3. rebase to the `main` branch and modify `debian/changes`:
|
||||
* change `mscp (X.X.X) UNRELEASED;` to `mscp (X.X.X-1~RELEASENAME) RELEASENAME;`
|
||||
where `RELEASENAME` is `focal` or `jammy`.
|
||||
4. run `make build-deb` at the build directory and `cd debbuild`
|
||||
5. sign the files with `debsign -k [GPGKEYID] mscp_X.X.X~X_source.changes`
|
||||
5. upload the files with `dput ppa:upaa/mscp mscp_X.X.X~X_source.changes`
|
||||
|
||||
|
||||
## Build mscp as (source) rpm package
|
||||
|
||||
`make build-srpm` produces a mscp src.rpm package. This target builts
|
||||
mscp with `rpmbuild` inside a docker container (Dockerfile is
|
||||
`docker/build-srpm.Dockerfile`, generated from
|
||||
`build-srpm.Dockerfile.in` by cmake).
|
||||
|
||||
```console
|
||||
mkdir build && cd build && cmake ..
|
||||
make build-srpm
|
||||
```
|
||||
|
||||
After that:
|
||||
|
||||
```console
|
||||
$ ls *.rpm
|
||||
mscp-0.1.3-1.el9.src.rpm
|
||||
```
|
||||
|
||||
### To publish mscp in COPR:
|
||||
|
||||
1. update `rpm/mscp.spec.in`, the `changelog` section (the date
|
||||
command needed here is `date "+%a %b %d %Y"`)
|
||||
2. run `make build-srpm`
|
||||
3. download `mscp-X.X.X-1.yyy.src.rpm`
|
||||
4. upload the src.rpm to Build page at COPR.
|
||||
|
||||
|
||||
|
||||
## Update Document
|
||||
|
||||
The docuemnt is `doc/mscp.rst` (at present). When `mscp.1.in` is
|
||||
modified, run `make update-rst` to make it up to date.
|
||||
|
||||
```console
|
||||
mkdir build cd build && cmake ..
|
||||
make update-rst
|
||||
```
|
||||
|
||||
187
doc/mscp.1.in
187
doc/mscp.1.in
@@ -6,7 +6,7 @@ mscp \- copy files over multiple SSH connections
|
||||
.SH SYNOPSIS
|
||||
|
||||
.B mscp
|
||||
.RB [ \-vqDHdNh ]
|
||||
.RB [ \-46vqDpdNh ]
|
||||
[\c
|
||||
.BI \-n \ NR_CONNECTIONS\c
|
||||
]
|
||||
@@ -20,6 +20,12 @@ mscp \- copy files over multiple SSH connections
|
||||
.BI \-I \ INTERVAL\c
|
||||
]
|
||||
[\c
|
||||
.BI \-W \ CHECKPOINT\c
|
||||
]
|
||||
[\c
|
||||
.BI \-R \ CHECKPOINT\c
|
||||
]
|
||||
[\c
|
||||
.BI \-s \ MIN_CHUNK_SIZE\c
|
||||
]
|
||||
[\c
|
||||
@@ -32,19 +38,27 @@ mscp \- copy files over multiple SSH connections
|
||||
.BI \-b \ BUF_SIZE\c
|
||||
]
|
||||
[\c
|
||||
.BI \-L \ LIMIT_BITRATE\c
|
||||
]
|
||||
[\c
|
||||
.BI \-l \ LOGIN_NAME\c
|
||||
]
|
||||
[\c
|
||||
.BR \-p |\c
|
||||
.BI \-P \ PORT\c
|
||||
]
|
||||
[\c
|
||||
.BI \-F \ CONFIG\c
|
||||
.BI \-F \ SSH_CONFIG\c
|
||||
]
|
||||
[\c
|
||||
.BI \-o \ SSH_OPTION\c
|
||||
]
|
||||
[\c
|
||||
.BI \-i \ IDENTITY\c
|
||||
]
|
||||
[\c
|
||||
.BI \-J \ DESTINATION\c
|
||||
]
|
||||
[\c
|
||||
.BI \-c \ CIPHER\c
|
||||
]
|
||||
[\c
|
||||
@@ -53,6 +67,9 @@ mscp \- copy files over multiple SSH connections
|
||||
[\c
|
||||
.BI \-C \ COMPRESS\c
|
||||
]
|
||||
[\c
|
||||
.BI \-g \ CONGESTION\c
|
||||
]
|
||||
.I source ... target
|
||||
|
||||
.SH DESCRIPTION
|
||||
@@ -67,7 +84,7 @@ of/large files over networks.
|
||||
.PP
|
||||
The usage of
|
||||
.B mscp
|
||||
imitates the
|
||||
follows the
|
||||
.B scp
|
||||
command of
|
||||
.I OpenSSH,
|
||||
@@ -106,12 +123,15 @@ formula: floor(log(nr_cores)*2)+1.
|
||||
|
||||
.TP
|
||||
.B \-m \fICOREMASK\fR
|
||||
Configures CPU cores to be used by the hexadecimal bitmask. All CPU
|
||||
cores are used by default.
|
||||
Configures CPU cores to be used by the hexadecimal bitmask. For
|
||||
example, -m 0x25 pins threads onto CPU cores 0, 2, and 5. The default
|
||||
value is not specified: all CPU cores are used and no threads are
|
||||
pinned to any cores.
|
||||
|
||||
.TP
|
||||
.B \-u \fIMAX_STARTUPS\fR
|
||||
Specifies the number of concurrent outgoing SSH connections.
|
||||
Specifies the number of concurrent unauthenticated SSH connection
|
||||
attempts.
|
||||
.B sshd
|
||||
limits the number of simultaneous SSH connection attempts by
|
||||
.I MaxStartups
|
||||
@@ -129,16 +149,60 @@ single source IP address for a short period as a brute force attack.
|
||||
This option inserts intervals between the attempts to avoid being
|
||||
determined as an attack. The default value is 0.
|
||||
|
||||
.TP
|
||||
.B \-W \fICHECKPOINT\fR
|
||||
Specifies a checkpoint file to save the state of a failed
|
||||
transfer. When transferring fails due to, for example, connection
|
||||
disruption or user interrupt,
|
||||
.B mscp
|
||||
writes the information about the remaining files and chunks to the
|
||||
specified checkpoint file.
|
||||
.B \-W
|
||||
option with
|
||||
.B \-D
|
||||
(dry-run mode) only writes a checkpoint file and exits.
|
||||
|
||||
|
||||
.TP
|
||||
.B \-R \fICHECKPOINT\fR
|
||||
Specifies a checkpoint file to resume a transfer. When a checkpoint
|
||||
file is passed,
|
||||
.B mscp
|
||||
reads the checkpoint to load a remote host, copy direction, and files
|
||||
and their chunks to be transferred. Namely,
|
||||
.B mscp
|
||||
can resume a past failed transfer from the checkpoint. Resuming with a
|
||||
checkpoint does not require
|
||||
.I source ... target
|
||||
arguments. Other SSH connection options, such as port number and
|
||||
config file, should be specified as with the failed run. In addition,
|
||||
checkpoint files have file paths as relative paths. Thus, you must run
|
||||
.B mscp
|
||||
in the same working directory as the failed run. You can see the
|
||||
contents of a checkpoint file with the
|
||||
.B mscp \-vv \-D \-R CHECKPOINT
|
||||
command (Dry-run mode). Note that the checkpoint file is not
|
||||
automatically removed after the resumed transfer ends
|
||||
successfully. Users should check the return value of
|
||||
.B mscp
|
||||
and remove the checkpoint if it returns 0.
|
||||
|
||||
|
||||
.TP
|
||||
.B \-s \fIMIN_CHUNK_SIZE\fR
|
||||
Specifies the minimum chunk size.
|
||||
.B mscp
|
||||
divides a file into chunks and copies the chunks in parallel.
|
||||
divides a single file into chunks and copies the chunks in
|
||||
parallel. The default value is 16M bytes.
|
||||
|
||||
.TP
|
||||
.B \-S \fIMAX_CHUNK_SIZE\fR
|
||||
Specifies the maximum chunk size. The default is file size divided by
|
||||
the number of connections.
|
||||
the number of connections and devided by 4. If the calculated value
|
||||
is smarller than the
|
||||
.B MIN_CHUNK_SIZE
|
||||
value,
|
||||
MIN_CHUNK_SIZE is used.
|
||||
|
||||
.TP
|
||||
.B \-a \fINR_AHEAD\fR
|
||||
@@ -151,6 +215,19 @@ Specifies the buffer size for I/O and transfer over SFTP. The default
|
||||
value is 16384. Note that the SSH specification restricts buffer size
|
||||
delivered over SSH. Changing this value is not recommended at present.
|
||||
|
||||
.TP
|
||||
.B \-L \fILIMIT_BITRATE\fR
|
||||
Limits the bitrate, specified with k (K), m (M), and g (G), e.g., 100m
|
||||
indicates 100 Mbps.
|
||||
|
||||
.TP
|
||||
.B \-4
|
||||
Uses IPv4 addresses only.
|
||||
|
||||
.TP
|
||||
.B \-6
|
||||
Uses IPv6 addresses only.
|
||||
|
||||
.TP
|
||||
.B \-v
|
||||
Increments the verbose output level.
|
||||
@@ -162,10 +239,9 @@ Quiet mode: turns off all outputs.
|
||||
.TP
|
||||
.B \-D
|
||||
Dry-run mode: it scans source files to be copied, calculates chunks,
|
||||
and resolves destination file paths. Dry-run mode with
|
||||
resolves destination file paths, and exits. Dry-run mode with
|
||||
.B -vv
|
||||
option enables confirming files to be copied and their destination
|
||||
paths.
|
||||
option can confirm files to be copied and their destination paths.
|
||||
|
||||
.TP
|
||||
.B \-r
|
||||
@@ -180,24 +256,48 @@ Specifies the username to log in on the remote machine as with
|
||||
.I ssh(1).
|
||||
|
||||
.TP
|
||||
.B \-p,\-P \fIPORT\fR
|
||||
.B \-P \fIPORT\fR
|
||||
Specifies the port number to connect to on the remote machine as with
|
||||
ssh(1) and scp(1).
|
||||
.I scp(1).
|
||||
|
||||
.TP
|
||||
.B \-F \fICONFIG\fR
|
||||
.B \-F \fISSH_CONFIG\fR
|
||||
Specifies an alternative per-user ssh configuration file. Note that
|
||||
acceptable options in the configuration file are what
|
||||
.I libssh
|
||||
supports.
|
||||
|
||||
.TP
|
||||
.B \-o \fISSH_OPTION\fR
|
||||
Specifies ssh options in the format used in ssh_config. Note that
|
||||
acceptable options are what
|
||||
.I libssh
|
||||
supports.
|
||||
|
||||
.TP
|
||||
.B \-i \fIIDENTITY\fR
|
||||
Specifies the identity file for public key authentication.
|
||||
|
||||
.TP
|
||||
.B \-J \fIDESTINATION\fR
|
||||
A shortcut to define a
|
||||
.B ProxyJump
|
||||
configuration directive. Each SFTP session of
|
||||
.B mscp
|
||||
connects to the target host by first making an
|
||||
.B ssh
|
||||
connection to the jump host described by
|
||||
.I destination.
|
||||
|
||||
|
||||
|
||||
.TP
|
||||
.B \-c \fICIPHER\fR
|
||||
Selects the cipher to use for encrypting the data transfer. See
|
||||
.B mscp -h
|
||||
or
|
||||
.B Ciphers
|
||||
in
|
||||
.UR https://\:www\:.libssh\:.org/\:features/
|
||||
libssh features
|
||||
.UE .
|
||||
@@ -205,6 +305,10 @@ libssh features
|
||||
.TP
|
||||
.B \-M \fIHMAC\fR
|
||||
Specifies MAC hash algorithms. See
|
||||
.B mscp -h
|
||||
or
|
||||
.B MAC hashes
|
||||
in
|
||||
.UR https://\:www\:.libssh\:.org/\:features/
|
||||
libssh features
|
||||
.UE .
|
||||
@@ -218,8 +322,16 @@ libssh features
|
||||
.UE .
|
||||
|
||||
.TP
|
||||
.B \-H
|
||||
Disables hostkey checking.
|
||||
.B \-g \fICONGESTION\fR
|
||||
Specifies the TCP congestion control algorithm to use (Linux only).
|
||||
See
|
||||
.B sysctl net.ipv4.tcp_allowed_congestion_control
|
||||
for available values.
|
||||
|
||||
.TP
|
||||
.B \-p
|
||||
Preserves modification times and access times (file mode bits are
|
||||
preserved by default).
|
||||
|
||||
.TP
|
||||
.B \-d
|
||||
@@ -236,6 +348,24 @@ Prints help.
|
||||
.SH EXIT STATUS
|
||||
Exit status is 0 on success, and >0 if an error occurs.
|
||||
|
||||
.SH ENVIRONMENT
|
||||
|
||||
.PP
|
||||
.B mscp
|
||||
recognizes the following environment variables.
|
||||
|
||||
.TP
|
||||
.B MSCP_SSH_AUTH_PASSWORD
|
||||
This environment variable passes a password for password
|
||||
authentication to establish SSH connections.
|
||||
|
||||
.TP
|
||||
.B MSCP_SSH_AUTH_PASSPHRASE
|
||||
This environment variable passes a passphrase for public-key
|
||||
authentication for establishing SSH connections.
|
||||
|
||||
|
||||
|
||||
.SH NOTES
|
||||
|
||||
.PP
|
||||
@@ -269,6 +399,24 @@ Copy a local file and a directory to /tmp at a remote host:
|
||||
$ mscp ~/src-file dir1 10.0.0.1:/tmp
|
||||
.fi
|
||||
|
||||
.PP
|
||||
Save a checkpoint if transfer fails:
|
||||
|
||||
.nf
|
||||
$ mscp -W mscp.checkpoint many-large-files 10.0.0.1:dst/
|
||||
.fi
|
||||
|
||||
.PP
|
||||
Check the remaining files and chunks, and resume the failed transfer:
|
||||
|
||||
.nf
|
||||
# Dump the content of a checkpoint and exit (dry-run mode)
|
||||
$ mscp -vv -D -R mscp.checkpoint
|
||||
|
||||
# resume transferring from the checkpoint
|
||||
$ mscp -R mscp.checkpoint
|
||||
.fi
|
||||
|
||||
.PP
|
||||
In a long fat network, following options might improve performance:
|
||||
|
||||
@@ -287,7 +435,6 @@ will be faster than the default chacha20-poly1305 cipher, particularly
|
||||
on hosts that support AES-NI.
|
||||
|
||||
|
||||
|
||||
.SH "SEE ALSO"
|
||||
.BR scp (1),
|
||||
.BR ssh (1),
|
||||
@@ -305,9 +452,9 @@ DOI
|
||||
.UE .
|
||||
|
||||
|
||||
.SH CONTACT INFROMATION
|
||||
.SH CONTACT INFORMATION
|
||||
.PP
|
||||
For pathces, bug reports, or feature requests, please open an issue on
|
||||
For patches, bug reports, or feature requests, please open an issue on
|
||||
.UR https://\:github\:.com/\:upa/\:mscp
|
||||
GitHub
|
||||
.UE .
|
||||
|
||||
144
doc/mscp.rst
144
doc/mscp.rst
@@ -2,7 +2,7 @@
|
||||
MSCP
|
||||
====
|
||||
|
||||
:Date: v0.1.2-14-g24617d2
|
||||
:Date: v0.2.1
|
||||
|
||||
NAME
|
||||
====
|
||||
@@ -12,13 +12,14 @@ mscp - copy files over multiple SSH connections
|
||||
SYNOPSIS
|
||||
========
|
||||
|
||||
**mscp** [**-vqDHdNh**] [ **-n**\ *NR_CONNECTIONS* ] [
|
||||
**-m**\ *COREMASK* ] [ **-u**\ *MAX_STARTUPS* ] [ **-I**\ *INTERVAL* ] [
|
||||
**-s**\ *MIN_CHUNK_SIZE* ] [ **-S**\ *MAX_CHUNK_SIZE* ] [
|
||||
**-a**\ *NR_AHEAD* ] [ **-b**\ *BUF_SIZE* ] [ **-l**\ *LOGIN_NAME* ] [
|
||||
**-p**\ \| **-P**\ *PORT* ] [ **-F**\ *CONFIG* ] [ **-i**\ *IDENTITY* ]
|
||||
[ **-c**\ *CIPHER* ] [ **-M**\ *HMAC* ] [ **-C**\ *COMPRESS* ] *source
|
||||
... target*
|
||||
**mscp** [**-46vqDpdNh**] [ **-n** *NR_CONNECTIONS* ] [ **-m**
|
||||
*COREMASK* ] [ **-u** *MAX_STARTUPS* ] [ **-I** *INTERVAL* ] [ **-W**
|
||||
*CHECKPOINT* ] [ **-R** *CHECKPOINT* ] [ **-s** *MIN_CHUNK_SIZE* ] [
|
||||
**-S** *MAX_CHUNK_SIZE* ] [ **-a** *NR_AHEAD* ] [ **-b** *BUF_SIZE* ] [
|
||||
**-L** *LIMIT_BITRATE* ] [ **-l** *LOGIN_NAME* ] [ **-P** *PORT* ] [
|
||||
**-F** *SSH_CONFIG* ] [ **-o** *SSH_OPTION* ] [ **-i** *IDENTITY* ] [
|
||||
**-J** *DESTINATION* ] [ **-c** *CIPHER* ] [ **-M** *HMAC* ] [ **-C**
|
||||
*COMPRESS* ] [ **-g** *CONGESTION* ] *source ... target*
|
||||
|
||||
DESCRIPTION
|
||||
===========
|
||||
@@ -28,7 +29,7 @@ threads. It enables transferring (1) multiple files simultaneously and
|
||||
(2) a large file in parallel, reducing the transfer time for a lot
|
||||
of/large files over networks.
|
||||
|
||||
The usage of **mscp** imitates the **scp** command of *OpenSSH,* for
|
||||
The usage of **mscp** follows the **scp** command of *OpenSSH,* for
|
||||
example:
|
||||
|
||||
::
|
||||
@@ -53,14 +54,16 @@ OPTIONS
|
||||
following formula: floor(log(nr_cores)*2)+1.
|
||||
|
||||
**-m COREMASK**
|
||||
Configures CPU cores to be used by the hexadecimal bitmask. All CPU
|
||||
cores are used by default.
|
||||
Configures CPU cores to be used by the hexadecimal bitmask. For
|
||||
example, -m 0x25 pins threads onto CPU cores 0, 2, and 5. The default
|
||||
value is not specified: all CPU cores are used and no threads are
|
||||
pinned to any cores.
|
||||
|
||||
**-u MAX_STARTUPS**
|
||||
Specifies the number of concurrent outgoing SSH connections. **sshd**
|
||||
limits the number of simultaneous SSH connection attempts by
|
||||
*MaxStartups* in *sshd_config.* The default *MaxStartups* is 10;
|
||||
thus, we set the default MAX_STARTUPS 8.
|
||||
Specifies the number of concurrent unauthenticated SSH connection
|
||||
attempts. **sshd** limits the number of simultaneous SSH connection
|
||||
attempts by *MaxStartups* in *sshd_config.* The default *MaxStartups*
|
||||
is 10; thus, we set the default MAX_STARTUPS 8.
|
||||
|
||||
**-I INTERVAL**
|
||||
Specifies the interval (in seconds) between SSH connection attempts.
|
||||
@@ -69,13 +72,39 @@ OPTIONS
|
||||
option inserts intervals between the attempts to avoid being
|
||||
determined as an attack. The default value is 0.
|
||||
|
||||
**-W CHECKPOINT**
|
||||
Specifies a checkpoint file to save the state of a failed transfer.
|
||||
When transferring fails due to, for example, connection disruption or
|
||||
user interrupt, **mscp** writes the information about the remaining
|
||||
files and chunks to the specified checkpoint file. **-W** option with
|
||||
**-D** (dry-run mode) only writes a checkpoint file and exits.
|
||||
|
||||
**-R CHECKPOINT**
|
||||
Specifies a checkpoint file to resume a transfer. When a checkpoint
|
||||
file is passed, **mscp** reads the checkpoint to load a remote host,
|
||||
copy direction, and files and their chunks to be transferred. Namely,
|
||||
**mscp** can resume a past failed transfer from the checkpoint.
|
||||
Resuming with a checkpoint does not require *source ... target*
|
||||
arguments. Other SSH connection options, such as port number and
|
||||
config file, should be specified as with the failed run. In addition,
|
||||
checkpoint files have file paths as relative paths. Thus, you must
|
||||
run **mscp** in the same working directory as the failed run. You can
|
||||
see the contents of a checkpoint file with the **mscp -vv -D -R
|
||||
CHECKPOINT** command (Dry-run mode). Note that the checkpoint file is
|
||||
not automatically removed after the resumed transfer ends
|
||||
successfully. Users should check the return value of **mscp** and
|
||||
remove the checkpoint if it returns 0.
|
||||
|
||||
**-s MIN_CHUNK_SIZE**
|
||||
Specifies the minimum chunk size. **mscp** divides a file into chunks
|
||||
and copies the chunks in parallel.
|
||||
Specifies the minimum chunk size. **mscp** divides a single file into
|
||||
chunks and copies the chunks in parallel. The default value is 16M
|
||||
bytes.
|
||||
|
||||
**-S MAX_CHUNK_SIZE**
|
||||
Specifies the maximum chunk size. The default is file size divided by
|
||||
the number of connections.
|
||||
the number of connections and devided by 4. If the calculated value
|
||||
is smarller than the **MIN_CHUNK_SIZE** value, MIN_CHUNK_SIZE is
|
||||
used.
|
||||
|
||||
**-a NR_AHEAD**
|
||||
Specifies the number of inflight SFTP commands. The default value is
|
||||
@@ -87,6 +116,16 @@ OPTIONS
|
||||
delivered over SSH. Changing this value is not recommended at
|
||||
present.
|
||||
|
||||
**-L LIMIT_BITRATE**
|
||||
Limits the bitrate, specified with k (K), m (M), and g (G), e.g.,
|
||||
100m indicates 100 Mbps.
|
||||
|
||||
**-4**
|
||||
Uses IPv4 addresses only.
|
||||
|
||||
**-6**
|
||||
Uses IPv6 addresses only.
|
||||
|
||||
**-v**
|
||||
Increments the verbose output level.
|
||||
|
||||
@@ -95,8 +134,8 @@ OPTIONS
|
||||
|
||||
**-D**
|
||||
Dry-run mode: it scans source files to be copied, calculates chunks,
|
||||
and resolves destination file paths. Dry-run mode with **-vv** option
|
||||
enables confirming files to be copied and their destination paths.
|
||||
resolves destination file paths, and exits. Dry-run mode with **-vv**
|
||||
option can confirm files to be copied and their destination paths.
|
||||
|
||||
**-r**
|
||||
No effect. **mscp** copies recursively if a source path is a
|
||||
@@ -106,32 +145,48 @@ OPTIONS
|
||||
Specifies the username to log in on the remote machine as with
|
||||
*ssh(1).*
|
||||
|
||||
**-p,-P PORT**
|
||||
**-P PORT**
|
||||
Specifies the port number to connect to on the remote machine as with
|
||||
ssh(1) and scp(1).
|
||||
*scp(1).*
|
||||
|
||||
**-F CONFIG**
|
||||
**-F SSH_CONFIG**
|
||||
Specifies an alternative per-user ssh configuration file. Note that
|
||||
acceptable options in the configuration file are what *libssh*
|
||||
supports.
|
||||
|
||||
**-o SSH_OPTION**
|
||||
Specifies ssh options in the format used in ssh_config. Note that
|
||||
acceptable options are what *libssh* supports.
|
||||
|
||||
**-i IDENTITY**
|
||||
Specifies the identity file for public key authentication.
|
||||
|
||||
**-J DESTINATION**
|
||||
A shortcut to define a **ProxyJump** configuration directive. Each
|
||||
SFTP session of **mscp** connects to the target host by first making
|
||||
an **ssh** connection to the jump host described by *destination.*
|
||||
|
||||
**-c CIPHER**
|
||||
Selects the cipher to use for encrypting the data transfer. See
|
||||
`libssh features <https://www.libssh.org/features/>`__.
|
||||
**mscp -h** or **Ciphers** in `libssh
|
||||
features <https://www.libssh.org/features/>`__.
|
||||
|
||||
**-M HMAC**
|
||||
Specifies MAC hash algorithms. See `libssh
|
||||
features <https://www.libssh.org/features/>`__.
|
||||
Specifies MAC hash algorithms. See **mscp -h** or **MAC hashes** in
|
||||
`libssh features <https://www.libssh.org/features/>`__.
|
||||
|
||||
**-C COMPRESS**
|
||||
Enables compression: yes, no, zlib, zlib@openssh.com. The default is
|
||||
none. See `libssh features <https://www.libssh.org/features/>`__.
|
||||
|
||||
**-H**
|
||||
Disables hostkey checking.
|
||||
**-g CONGESTION**
|
||||
Specifies the TCP congestion control algorithm to use (Linux only).
|
||||
See **sysctl net.ipv4.tcp_allowed_congestion_control** for available
|
||||
values.
|
||||
|
||||
**-p**
|
||||
Preserves modification times and access times (file mode bits are
|
||||
preserved by default).
|
||||
|
||||
**-d**
|
||||
Increments the ssh debug output level.
|
||||
@@ -147,6 +202,19 @@ EXIT STATUS
|
||||
|
||||
Exit status is 0 on success, and >0 if an error occurs.
|
||||
|
||||
ENVIRONMENT
|
||||
===========
|
||||
|
||||
**mscp** recognizes the following environment variables.
|
||||
|
||||
**MSCP_SSH_AUTH_PASSWORD**
|
||||
This environment variable passes a password for password
|
||||
authentication to establish SSH connections.
|
||||
|
||||
**MSCP_SSH_AUTH_PASSPHRASE**
|
||||
This environment variable passes a passphrase for public-key
|
||||
authentication for establishing SSH connections.
|
||||
|
||||
NOTES
|
||||
=====
|
||||
|
||||
@@ -173,6 +241,22 @@ Copy a local file and a directory to /tmp at a remote host:
|
||||
|
||||
$ mscp ~/src-file dir1 10.0.0.1:/tmp
|
||||
|
||||
Save a checkpoint if transfer fails:
|
||||
|
||||
::
|
||||
|
||||
$ mscp -W mscp.checkpoint many-large-files 10.0.0.1:dst/
|
||||
|
||||
Check the remaining files and chunks, and resume the failed transfer:
|
||||
|
||||
::
|
||||
|
||||
# Dump the content of a checkpoint and exit (dry-run mode)
|
||||
$ mscp -vv -D -R mscp.checkpoint
|
||||
|
||||
# resume transferring from the checkpoint
|
||||
$ mscp -R mscp.checkpoint
|
||||
|
||||
In a long fat network, following options might improve performance:
|
||||
|
||||
::
|
||||
@@ -198,10 +282,10 @@ File Transfer over SSH. In Practice and Experience in Advanced Research
|
||||
Computing (PEARC '23). Association for Computing Machinery, New York,
|
||||
NY, USA, 320–323. `DOI <https://doi.org/10.1145/3569951.3597582>`__.
|
||||
|
||||
CONTACT INFROMATION
|
||||
CONTACT INFORMATION
|
||||
===================
|
||||
|
||||
For pathces, bug reports, or feature requests, please open an issue on
|
||||
For patches, bug reports, or feature requests, please open an issue on
|
||||
`GitHub <https://github.com/upa/mscp>`__.
|
||||
|
||||
AUTHORS
|
||||
|
||||
@@ -1,37 +0,0 @@
|
||||
|
||||
Build docker containers.
|
||||
|
||||
```console
|
||||
cd ..
|
||||
|
||||
docker build -t mscp-ubuntu:20.04 -f docker/ubuntu-20.04.Dockerfile .
|
||||
|
||||
docker build -t mscp-ubuntu:22.04 -f docker/ubuntu-22.04.Dockerfile .
|
||||
|
||||
docker build -t mscp-rocky:8.8 -f docker/rocky-8.Dockerfile .
|
||||
```
|
||||
|
||||
Test `mscp` in the containers.
|
||||
|
||||
```console
|
||||
docker run --init --rm mscp-ubuntu:20.04 /mscp/scripts/test-in-container.sh
|
||||
|
||||
docker run --init --rm mscp-ubuntu:22.04 /mscp/scripts/test-in-container.sh
|
||||
|
||||
docker run --init --rm mscp-rocky:8.9 /mscp/scripts/test-in-container.sh
|
||||
```
|
||||
|
||||
Retrieve deb/rpm packages.
|
||||
|
||||
```console
|
||||
docker run --rm -v (pwd):/out mscp-ubuntu:20.04 \
|
||||
cp /mscp/build/mscp_ubuntu-20.04-x86_64.deb /out/
|
||||
|
||||
docker run --rm -v (pwd):/out mscp-ubuntu:22.04 \
|
||||
cp /mscp/build/mscp_ubuntu-22.04-x86_64.deb /out/
|
||||
|
||||
docker run --rm -v (pwd):/out mscp-rocky:8.8 \
|
||||
cp /mscp/build/mscp_rocky-8.8-x86_64.rpm /out/
|
||||
```
|
||||
|
||||
I don't know whether these are good way.
|
||||
@@ -1,39 +0,0 @@
|
||||
FROM almalinux:8.8
|
||||
|
||||
# install pytest, sshd for test, and rpm-build
|
||||
RUN set -ex && \
|
||||
rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux && \
|
||||
yum -y install \
|
||||
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# install build dependency
|
||||
RUN ${mscpdir}/scripts/install-build-deps.sh
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make \
|
||||
&& cpack -G RPM CPackConfig.cmake \
|
||||
&& rpm -iv *.rpm
|
||||
|
||||
# install mscp python module
|
||||
RUN cd ${mscpdir} \
|
||||
&& python3 pysetup.py install --user \
|
||||
&& ldconfig
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
FROM alpine:3.17
|
||||
|
||||
# Build mscp with conan to create single binary mscp
|
||||
|
||||
RUN apk add --no-cache \
|
||||
gcc make cmake python3 py3-pip perl linux-headers libc-dev \
|
||||
openssh bash python3-dev g++
|
||||
|
||||
RUN pip3 install conan pytest
|
||||
|
||||
# preparation for sshd
|
||||
RUN ssh-keygen -A
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||
|
||||
|
||||
# Build mscp as a single binary
|
||||
RUN conan profile detect --force
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& conan install . --output-folder=build --build=missing \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& cmake .. \
|
||||
-DCMAKE_BUILD_TYPE=Release \
|
||||
-DCMAKE_TOOLCHAIN_FILE=conan_toolchain.cmake \
|
||||
-DBUILD_CONAN=ON -DBUILD_STATIC=ON \
|
||||
&& make \
|
||||
&& cp mscp /usr/bin/ \
|
||||
&& cp mscp /mscp/build/mscp_alpine-3.17-x86_64.static
|
||||
# copy mscp to PKG FILE NAME because this build doesn't use CPACK
|
||||
|
||||
# install mscp python module
|
||||
RUN cd ${mscpdir} \
|
||||
&& python3 pysetup.py install --user
|
||||
@@ -1,36 +0,0 @@
|
||||
FROM rockylinux:8.8
|
||||
|
||||
# install pytest, sshd for test, and rpm-build
|
||||
RUN set -ex && yum -y install \
|
||||
python3 python3-pip python3-devel openssh openssh-server openssh-clients rpm-build
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -A \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# install build dependency
|
||||
RUN ${mscpdir}/scripts/install-build-deps.sh
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make \
|
||||
&& cpack -G RPM CPackConfig.cmake \
|
||||
&& rpm -iv *.rpm
|
||||
|
||||
# install mscp python module
|
||||
RUN cd ${mscpdir} \
|
||||
&& python3 pysetup.py install --user \
|
||||
&& ldconfig
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
FROM ubuntu:20.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates
|
||||
|
||||
# install pytest, and sshd for test
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
python3 python3-pip python3-dev openssh-server
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# install build dependency
|
||||
RUN ${mscpdir}/scripts/install-build-deps.sh
|
||||
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make \
|
||||
&& cpack -G DEB CPackConfig.cmake \
|
||||
&& dpkg -i *.deb
|
||||
|
||||
# install mscp python module
|
||||
RUN cd ${mscpdir} \
|
||||
&& python3 pysetup.py install --user \
|
||||
&& ldconfig
|
||||
@@ -1,40 +0,0 @@
|
||||
FROM ubuntu:22.04
|
||||
|
||||
ARG DEBIAN_FRONTEND=noninteractive
|
||||
RUN set -ex && apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates
|
||||
|
||||
# install pytest, and sshd for test
|
||||
RUN apt-get install -y --no-install-recommends \
|
||||
python3 python3-pip python3-dev openssh-server
|
||||
|
||||
RUN python3 -m pip install pytest
|
||||
|
||||
|
||||
# preparation for sshd
|
||||
RUN mkdir /var/run/sshd \
|
||||
&& ssh-keygen -f /root/.ssh/id_rsa -N "" \
|
||||
&& mv /root/.ssh/id_rsa.pub /root/.ssh/authorized_keys
|
||||
|
||||
ARG mscpdir="/mscp"
|
||||
|
||||
COPY . ${mscpdir}
|
||||
|
||||
# install build dependency
|
||||
RUN ${mscpdir}/scripts/install-build-deps.sh
|
||||
|
||||
|
||||
# build
|
||||
RUN cd ${mscpdir} \
|
||||
&& rm -rf build \
|
||||
&& cmake -B build \
|
||||
&& cd ${mscpdir}/build \
|
||||
&& make \
|
||||
&& cpack -G DEB CPackConfig.cmake \
|
||||
&& dpkg -i *.deb
|
||||
|
||||
# install mscp python module
|
||||
RUN cd ${mscpdir} \
|
||||
&& python3 pysetup.py install --user \
|
||||
&& ldconfig
|
||||
|
||||
3
examples/.gitignore
vendored
3
examples/.gitignore
vendored
@@ -1,3 +0,0 @@
|
||||
simple-copy-dest
|
||||
*.img
|
||||
.ipynb_checkpoints
|
||||
@@ -1,226 +0,0 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "ccda9e3a-35de-43fc-9b6e-02475c763f6b",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# mscp python binding example"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 60,
|
||||
"id": "df04d655-a082-47eb-9a1e-154ebc2a5655",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"import glob\n",
|
||||
"import time\n",
|
||||
"import os\n",
|
||||
"\n",
|
||||
"import mscp"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 53,
|
||||
"id": "e9ed4519-c3fd-4639-89a5-1c1cdffd9519",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"this_dir = os.getcwd()"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "fee75bf8-df40-45f4-81d1-113069c34f13",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Simple copy"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 54,
|
||||
"id": "2b06e6d3-30cc-47be-bd4f-af27eb141c8c",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['../src/ssh.c',\n",
|
||||
" '../src/mscp.c',\n",
|
||||
" '../src/platform.c',\n",
|
||||
" '../src/pymscp.c',\n",
|
||||
" '../src/main.c',\n",
|
||||
" '../src/path.c',\n",
|
||||
" '../src/message.c',\n",
|
||||
" '../src/fileops.c']"
|
||||
]
|
||||
},
|
||||
"execution_count": 54,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# preparing files to be transferred\n",
|
||||
"c_sources = glob.glob(\"../src/*.c\")\n",
|
||||
"c_sources"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 55,
|
||||
"id": "89bb4558-9472-4d26-9af3-24f426b15edc",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# copy files using mscp\n",
|
||||
"dst_dir = this_dir + \"/simple-copy-dest\"\n",
|
||||
"m = mscp.mscp(\"localhost\", mscp.LOCAL2REMOTE)\n",
|
||||
"m.copy(c_sources, dst_dir)"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 56,
|
||||
"id": "6daf2c98-8905-4039-b82a-a593df3107fe",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"text/plain": [
|
||||
"['ssh.c',\n",
|
||||
" 'mscp.c',\n",
|
||||
" 'platform.c',\n",
|
||||
" 'pymscp.c',\n",
|
||||
" 'main.c',\n",
|
||||
" 'path.c',\n",
|
||||
" 'message.c',\n",
|
||||
" 'fileops.c']"
|
||||
]
|
||||
},
|
||||
"execution_count": 56,
|
||||
"metadata": {},
|
||||
"output_type": "execute_result"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"os.listdir(\"simple-copy-dest\")"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"id": "f4a3869a-878e-43b0-9758-a049eaf8b5bd",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"## Simple Copy with Python Rich ProgressBar"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 64,
|
||||
"id": "e7cb7cd6-b845-4d26-93ed-aee8ed3983ab",
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"# make a 256MB file\n",
|
||||
"src = \"example-256MB-src.img\"\n",
|
||||
"with open(src, \"wb\") as f:\n",
|
||||
" f.seek(128 * 1024 * 1024 -1, 0)\n",
|
||||
" f.write(b'1')"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 69,
|
||||
"id": "878607ed-5c06-4b15-81ac-9845dad0c9c6",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"data": {
|
||||
"application/vnd.jupyter.widget-view+json": {
|
||||
"model_id": "b700e9fc00464969a22a26300404dc35",
|
||||
"version_major": 2,
|
||||
"version_minor": 0
|
||||
},
|
||||
"text/plain": [
|
||||
"Output()"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"></pre>\n"
|
||||
],
|
||||
"text/plain": []
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
},
|
||||
{
|
||||
"data": {
|
||||
"text/html": [
|
||||
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">\n",
|
||||
"</pre>\n"
|
||||
],
|
||||
"text/plain": [
|
||||
"\n"
|
||||
]
|
||||
},
|
||||
"metadata": {},
|
||||
"output_type": "display_data"
|
||||
}
|
||||
],
|
||||
"source": [
|
||||
"# copy the 256MB file while ploting progress bar using python rich\n",
|
||||
"dst = this_dir + \"/example-256MB-dst.img\"\n",
|
||||
"\n",
|
||||
"kw = {\"nr_threads\": 1, \"nr_ahead\": 1} # slow mscp to watch the progress bar\n",
|
||||
"\n",
|
||||
"m = mscp.mscp(\"localhost\", mscp.LOCAL2REMOTE, **kw)\n",
|
||||
"m.copy(src, dst, nonblock = True)\n",
|
||||
"\n",
|
||||
"# m.stats() returns total bytes to be transferred, bytes transferred (done), and finished (bool).\n",
|
||||
"total, done, finished = m.stats()\n",
|
||||
"with Progress() as progress:\n",
|
||||
"\n",
|
||||
" task = progress.add_task(f\"[green]Copying {src}\", total = total)\n",
|
||||
"\n",
|
||||
" while not progress.finished:\n",
|
||||
" total, done, finished = m.stats()\n",
|
||||
" progress.update(task, completed = done)\n",
|
||||
" time.sleep(0.5)\n",
|
||||
"\n",
|
||||
"m.join()\n",
|
||||
"m.cleanup()"
|
||||
]
|
||||
}
|
||||
],
|
||||
"metadata": {
|
||||
"kernelspec": {
|
||||
"display_name": "Python 3 (ipykernel)",
|
||||
"language": "python",
|
||||
"name": "python3"
|
||||
},
|
||||
"language_info": {
|
||||
"codemirror_mode": {
|
||||
"name": "ipython",
|
||||
"version": 3
|
||||
},
|
||||
"file_extension": ".py",
|
||||
"mimetype": "text/x-python",
|
||||
"name": "python",
|
||||
"nbconvert_exporter": "python",
|
||||
"pygments_lexer": "ipython3",
|
||||
"version": "3.11.4"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 5
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
#!/usr/bin/env python3
|
||||
"""mscp.py
|
||||
|
||||
An example python script running mscp
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import time
|
||||
import sys
|
||||
|
||||
from rich.progress import Progress
|
||||
|
||||
import mscp
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-f", "--from", dest = "fr",
|
||||
metavar = "REMOTE", default = None,
|
||||
help = "copy a file from this remote host")
|
||||
parser.add_argument("-t", "--to", metavar = "REMOTE", default = None,
|
||||
help = "copy a file to this remote host")
|
||||
parser.add_argument("source", help = "path to source file to be copied")
|
||||
parser.add_argument("destination", help = "path of copy destination")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.fr and args.to:
|
||||
print("-f and -t are exclusive", file = sys.stderr)
|
||||
sys.exit(1)
|
||||
elif args.fr:
|
||||
d = mscp.REMOTE2LOCAL
|
||||
remote = args.fr
|
||||
elif args.to:
|
||||
d = mscp.LOCAL2REMOTE
|
||||
remote = args.to
|
||||
else:
|
||||
print("-f or -t must be specified", file = sys.stderr)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
m = mscp.mscp(remote, d)
|
||||
m.connect()
|
||||
m.add_src_path(args.source)
|
||||
m.set_dst_path(args.destination)
|
||||
m.scan()
|
||||
m.start()
|
||||
|
||||
total, done, finished = m.stats()
|
||||
with Progress() as progress:
|
||||
|
||||
task = progress.add_task("[green]Copying...", total = total)
|
||||
|
||||
while not progress.finished:
|
||||
total, done, finished = m.stats()
|
||||
progress.update(task, completed = done)
|
||||
time.sleep(0.5)
|
||||
|
||||
m.join()
|
||||
m.cleanup()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
18
include/config.h.in
Normal file
18
include/config.h.in
Normal file
@@ -0,0 +1,18 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _CONFIG_H_
|
||||
#define _CONFIG_H_
|
||||
|
||||
#define MSCP_VERSION "@MSCP_VERSION@"
|
||||
#define MSCP_BUILD_VERSION "@MSCP_BUILD_VERSION@"
|
||||
|
||||
|
||||
/* Define to 1 if you have the strlcat function. */
|
||||
#cmakedefine HAVE_STRLCAT 1
|
||||
|
||||
/* Define to 1 if you have the htonll function. */
|
||||
#cmakedefine HAVE_HTONLL 1
|
||||
|
||||
/* Define to 1 if you have the ntohll function. */
|
||||
#cmakedefine HAVE_NTOHLL 1
|
||||
|
||||
#endif /* _CONFIG_H_ */
|
||||
152
include/mscp.h
152
include/mscp.h
@@ -16,13 +16,14 @@
|
||||
* libmscp is follows:
|
||||
*
|
||||
* 1. create mscp instance with mscp_init()
|
||||
* 2. connect to remote host with mscp_connect()
|
||||
* 3. add path to source files with mscp_add_src_path()
|
||||
* 4. set path to destination with mscp_set_dst_path()
|
||||
* 5. start to scan source files with mscp_scan()
|
||||
* 6. start copy with mscp_start()
|
||||
* 7. wait for copy finished with mscp_join()
|
||||
* 8. cleanup mscp instance with mscp_cleanup() and mscp_free()
|
||||
* 2. set remote host and copy direction with mscp_set_remote()
|
||||
* 3. connect to remote host with mscp_connect()
|
||||
* 4. add path to source files with mscp_add_src_path()
|
||||
* 5. set path to destination with mscp_set_dst_path()
|
||||
* 6. start to scan source files with mscp_scan()
|
||||
* 7. start copy with mscp_start()
|
||||
* 8. wait for copy finished with mscp_join()
|
||||
* 9. cleanup mscp instance with mscp_cleanup() and mscp_free()
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
@@ -31,8 +32,6 @@
|
||||
#define MSCP_DIRECTION_L2R 1 /** Indicates local to remote copy */
|
||||
#define MSCP_DIRECTION_R2L 2 /** Indicates remote to local copy */
|
||||
|
||||
#define MSCP_MAX_COREMASK_STR 64
|
||||
|
||||
/**
|
||||
* @struct mscp_opts
|
||||
* @brief Structure configuring mscp.
|
||||
@@ -43,24 +42,14 @@ struct mscp_opts {
|
||||
size_t min_chunk_sz; /** minimum chunk size (default 64MB) */
|
||||
size_t max_chunk_sz; /** maximum chunk size (default file size/nr_threads) */
|
||||
size_t buf_sz; /** buffer size, default 16k. */
|
||||
char coremask[MSCP_MAX_COREMASK_STR]; /** hex to specifiy usable cpu cores */
|
||||
size_t bitrate; /** bits-per-seconds to limit bandwidth */
|
||||
char *coremask; /** hex to specifiy usable cpu cores */
|
||||
int max_startups; /** sshd MaxStartups concurrent connections */
|
||||
int interval; /** interval between SSH connection attempts */
|
||||
|
||||
bool preserve_ts; /** preserve file timestamps */
|
||||
int severity; /** messaging severity. set MSCP_SERVERITY_* */
|
||||
int msg_fd; /** fd to output message. default STDOUT (0),
|
||||
* and -1 disables output */
|
||||
};
|
||||
|
||||
#define MSCP_SSH_MAX_LOGIN_NAME 64
|
||||
#define MSCP_SSH_MAX_PORT_STR 32
|
||||
#define MSCP_SSH_MAX_IDENTITY_PATH PATH_MAX
|
||||
#define MSCP_SSH_MAX_CIPHER_STR 32
|
||||
#define MSCP_SSH_MAX_HMAC_STR 32
|
||||
#define MSCP_SSH_MAX_COMP_STR 32 /* yes, no, zlib, zlib@openssh.com, none */
|
||||
#define MSCP_SSH_MAX_CCALGO_STR 16
|
||||
#define MSCP_SSH_MAX_PASSWORD 128
|
||||
#define MSCP_SSH_MAX_PASSPHRASE 128
|
||||
|
||||
/**
|
||||
* @struct mscp_ssh_opts
|
||||
@@ -68,23 +57,36 @@ struct mscp_opts {
|
||||
*/
|
||||
struct mscp_ssh_opts {
|
||||
/* ssh options */
|
||||
char login_name[MSCP_SSH_MAX_LOGIN_NAME]; /** ssh username */
|
||||
char port[MSCP_SSH_MAX_PORT_STR]; /** ssh port */
|
||||
char config[PATH_MAX]; /** path to ssh_config, default ~/.ssh/config*/
|
||||
char identity[MSCP_SSH_MAX_IDENTITY_PATH]; /** path to private key */
|
||||
char cipher[MSCP_SSH_MAX_CIPHER_STR]; /** cipher spec */
|
||||
char hmac[MSCP_SSH_MAX_HMAC_STR]; /** hmacp spec */
|
||||
char compress[MSCP_SSH_MAX_COMP_STR]; /** yes, no, zlib@openssh.com */
|
||||
char ccalgo[MSCP_SSH_MAX_CCALGO_STR]; /** TCP cc algorithm */
|
||||
char *login_name; /** ssh username */
|
||||
char *port; /** ssh port */
|
||||
int ai_family; /** address family */
|
||||
char *config; /** path to ssh_config, default ~/.ssh/config*/
|
||||
char **options; /** array of ssh_config options, terminated by NULL */
|
||||
char *identity; /** path to private key */
|
||||
char *proxyjump; /** ProxyJump configuration directive (shortcut) */
|
||||
char *cipher; /** cipher spec */
|
||||
char *hmac; /** hmacp spec */
|
||||
char *compress; /** yes, no, zlib@openssh.com */
|
||||
char *ccalgo; /** TCP cc algorithm */
|
||||
|
||||
char password[MSCP_SSH_MAX_PASSWORD]; /** password auth passowrd */
|
||||
char passphrase[MSCP_SSH_MAX_PASSPHRASE]; /** passphrase for private key */
|
||||
char *password; /** password auth passowrd */
|
||||
char *passphrase; /** passphrase for private key */
|
||||
|
||||
int debug_level; /** inclirement libssh debug output level */
|
||||
bool no_hostkey_check; /** do not check host keys */
|
||||
bool enable_nagle; /** enable Nagle's algorithm if true */
|
||||
};
|
||||
|
||||
/** @def
|
||||
* Environment variable that passes password for ssh password auth
|
||||
*/
|
||||
#define ENV_SSH_AUTH_PASSWORD "MSCP_SSH_AUTH_PASSWORD"
|
||||
|
||||
/** @def
|
||||
* Environment vraible that passes passphrase for private key
|
||||
*/
|
||||
#define ENV_SSH_AUTH_PASSPHRASE "MSCP_SSH_AUTH_PASSPHRASE"
|
||||
|
||||
|
||||
/**
|
||||
* @struct mscp_stats
|
||||
* @brief Structure to get mscp statistics
|
||||
@@ -92,7 +94,6 @@ struct mscp_ssh_opts {
|
||||
struct mscp_stats {
|
||||
size_t total; /** total bytes to be transferred */
|
||||
size_t done; /** total bytes transferred */
|
||||
bool finished; /** true when all copy threads finished */
|
||||
};
|
||||
|
||||
|
||||
@@ -102,15 +103,22 @@ struct mscp;
|
||||
/**
|
||||
* @brief Creates a new mscp instance.
|
||||
*
|
||||
* @param remote_host remote host for file transer.
|
||||
* @param direction copy direction, `MSCP_DIRECTION_L2R` or `MSCP_DIRECTION_R2L`
|
||||
* @param o options for configuring mscp.
|
||||
* @param s options for configuring ssh connections.
|
||||
*
|
||||
* @retrun A new mscp instance or NULL on error.
|
||||
*/
|
||||
struct mscp *mscp_init(const char *remote_host, int direction,
|
||||
struct mscp_opts *o, struct mscp_ssh_opts *s);
|
||||
struct mscp *mscp_init(struct mscp_opts *o, struct mscp_ssh_opts *s);
|
||||
|
||||
/**
|
||||
* @brief Set remote host and copy direction.
|
||||
*
|
||||
* @param remote_host remote host for file transer.
|
||||
* @param direction copy direction, `MSCP_DIRECTION_L2R` or `MSCP_DIRECTION_R2L`
|
||||
*
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
*/
|
||||
int mscp_set_remote(struct mscp *m, const char *remote_host, int direction);
|
||||
|
||||
/**
|
||||
* @brief Connect the first SSH connection. mscp_connect connects to
|
||||
@@ -121,7 +129,6 @@ struct mscp *mscp_init(const char *remote_host, int direction,
|
||||
* @param m mscp instance.
|
||||
*
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*/
|
||||
int mscp_connect(struct mscp *m);
|
||||
|
||||
@@ -129,29 +136,23 @@ int mscp_connect(struct mscp *m);
|
||||
|
||||
/**
|
||||
* @brief Add a source file path to be copied. The path indicates
|
||||
* either a file or directory. The path can be `user@host:path`
|
||||
* notation. In this case, `dst_path` for mscp_set_dst_path() must
|
||||
* not contain remote host notation.
|
||||
* either a file or directory.
|
||||
*
|
||||
* @param m mscp instance.
|
||||
* @param src_path source file path to be copied.
|
||||
*
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*/
|
||||
int mscp_add_src_path(struct mscp *m, const char *src_path);
|
||||
|
||||
/**
|
||||
* @brief Set the destination file path. The path indicates either a
|
||||
* file, directory, or nonexistent path. The path can be
|
||||
* `user@host:path` notation. In this case, all source paths appended
|
||||
* by mscp_set_src_path() must not contain remote host notation.
|
||||
* file, directory, or nonexistent path.
|
||||
*
|
||||
* @param m mscp instance.
|
||||
* @param dst_path destination path to which source files copied.
|
||||
*
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*/
|
||||
int mscp_set_dst_path(struct mscp *m, const char *dst_path);
|
||||
|
||||
@@ -166,21 +167,54 @@ int mscp_set_dst_path(struct mscp *m, const char *dst_path);
|
||||
* @param m mscp instance.
|
||||
*
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*/
|
||||
int mscp_scan(struct mscp *m);
|
||||
|
||||
/**
|
||||
* @brief Join scna thread invoked by mscp_scan(). mscp_join()
|
||||
* involves this, so that mscp_scan_join() should be called when
|
||||
* mscp_scan() is called by mscp_start() is not.
|
||||
* @brief Join scan thread invoked by mscp_scan() if it
|
||||
* runs. mscp_join() involves mscp_can_join(). Thus, there is no need
|
||||
* to call this function alone.
|
||||
*
|
||||
* @param m mscp instance.
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*/
|
||||
int mscp_scan_join(struct mscp *m);
|
||||
|
||||
/**
|
||||
* @brief get information about remote host and copy direction from a
|
||||
* checkpoint file specified by *pathname. This functions returns
|
||||
* remote host name to *renote, and the copy direction into *dir.
|
||||
* Thus, you can call mscp_init with those values.
|
||||
*
|
||||
* @param pathname path to a checkpoint file.
|
||||
* @param remote char buffer to which remote hostname is stored.
|
||||
* @param len length of *remote.
|
||||
* @param dir int to which the copy direction is stored.
|
||||
*/
|
||||
int mscp_checkpoint_get_remote(const char *pathname, char *remote, size_t len, int *dir);
|
||||
|
||||
/**
|
||||
* @brief load information about untransferred files and chunks at the
|
||||
* last transfer . mscp_checkpoint_load() loads files and associated
|
||||
* chunks from the checkpoint file pointed by pathname. If you call
|
||||
* mscp_checkpoint_load(), do not call mscp_scan().
|
||||
*
|
||||
* @param m mscp instance.
|
||||
* @param pathname path to a checkpoint file.
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
*/
|
||||
int mscp_checkpoint_load(struct mscp *m, const char *pathname);
|
||||
|
||||
/**
|
||||
* @brief save information about untransferred files and chunks to a
|
||||
* checkpoint file.
|
||||
*
|
||||
* @param m mscp instance.
|
||||
* @param pathname path to a checkpoint file.
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
*/
|
||||
int mscp_checkpoint_save(struct mscp *m, const char *pathname);
|
||||
|
||||
/**
|
||||
* @brief Start to copy files. mscp_start() returns immediately. You
|
||||
* can get statistics via mscp_get_stats() or messages via pipe set by
|
||||
@@ -190,7 +224,6 @@ int mscp_scan_join(struct mscp *m);
|
||||
* @param m mscp instance.
|
||||
*
|
||||
* @return number of threads on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*
|
||||
* @see mscp_join()
|
||||
*/
|
||||
@@ -212,7 +245,6 @@ void mscp_stop(struct mscp *m);
|
||||
* @param m mscp instance.
|
||||
*
|
||||
* @return 0 on success, < 0 if an error occured.
|
||||
* mscp_get_error() can be used to retrieve error message.
|
||||
*/
|
||||
int mscp_join(struct mscp *m);
|
||||
|
||||
@@ -262,15 +294,15 @@ enum {
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @brief Return available ciphers.
|
||||
*/
|
||||
const char **mscp_ssh_ciphers(void);
|
||||
|
||||
/**
|
||||
* @brief Get the recent error message from libmscp. Note that this
|
||||
* function is not thread-safe.
|
||||
*
|
||||
* @return pointer to the message.
|
||||
* @brief Return available hmacs.
|
||||
*/
|
||||
const char *mscp_get_error(void);
|
||||
|
||||
const char **mscp_ssh_hmacs(void);
|
||||
|
||||
|
||||
#endif /* _MSCP_H_ */
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _MSCP_VERSION_H_
|
||||
#define _MSCP_VERSION_H_
|
||||
|
||||
#define MSCP_VERSION "@MSCP_VERSION@"
|
||||
#define MSCP_BUILD_VERSION "@MSCP_BUILD_VERSION@"
|
||||
|
||||
#endif /* _MSCP_VERSION_H_ */
|
||||
@@ -1 +0,0 @@
|
||||
from mscp.mscp import *
|
||||
187
mscp/mscp.py
187
mscp/mscp.py
@@ -1,187 +0,0 @@
|
||||
|
||||
_retry_import_pymscp = False
|
||||
|
||||
try:
|
||||
import pymscp
|
||||
except ImportError:
|
||||
_retry_import_pymscp = True
|
||||
|
||||
if _retry_import_pymscp:
|
||||
""" libmscp.so is not installed on system library paths. So retry
|
||||
to import libmscp.so installed on the mscp python module
|
||||
directory.
|
||||
"""
|
||||
import os
|
||||
import sys
|
||||
import ctypes
|
||||
|
||||
if sys.platform == "linux":
|
||||
libmscp = "libmscp.so"
|
||||
elif sys.platform == "darwin":
|
||||
libmscp = "libmscp.dylib"
|
||||
|
||||
mscp_dir = os.path.dirname(__file__)
|
||||
ctypes.cdll.LoadLibrary("{}/{}".format(mscp_dir, libmscp))
|
||||
import pymscp
|
||||
|
||||
|
||||
# inherit static values from pymscp
|
||||
LOCAL2REMOTE = pymscp.LOCAL2REMOTE
|
||||
REMOTE2LOCAL = pymscp.REMOTE2LOCAL
|
||||
SEVERITY_NONE = pymscp.SEVERITY_NONE
|
||||
SEVERITY_ERR = pymscp.SEVERITY_ERR
|
||||
SEVERITY_WARN = pymscp.SEVERITY_WARN
|
||||
SEVERITY_NOTICE = pymscp.SEVERITY_NOTICE
|
||||
SEVERITY_INFO = pymscp.SEVERITY_INFO
|
||||
SEVERITY_DEBUG = pymscp.SEVERITY_DEBUG
|
||||
|
||||
STATE_INIT = 0
|
||||
STATE_CONNECTED = 1
|
||||
STATE_SCANNED = 2
|
||||
STATE_RUNNING = 3
|
||||
STATE_STOPPED = 4
|
||||
STATE_JOINED = 5
|
||||
STATE_CLEANED = 6
|
||||
STATE_RELEASED = 7
|
||||
|
||||
_state_str = {
|
||||
STATE_INIT: "init",
|
||||
STATE_CONNECTED: "connected",
|
||||
STATE_SCANNED: "scanned",
|
||||
STATE_RUNNING: "running",
|
||||
STATE_STOPPED: "stopped",
|
||||
STATE_JOINED: "joined",
|
||||
STATE_CLEANED: "cleaned",
|
||||
STATE_RELEASED: "released",
|
||||
}
|
||||
|
||||
|
||||
class mscp:
|
||||
|
||||
|
||||
def __init__(self, remote: str, direction: int, **kwargs):
|
||||
self.remote = remote
|
||||
self.direction = direction
|
||||
kwargs["remote"] = remote
|
||||
kwargs["direction"] = direction
|
||||
self.m = pymscp.mscp_init(**kwargs)
|
||||
|
||||
self.src_paths = []
|
||||
self.dst_path = None
|
||||
self.state = STATE_INIT
|
||||
|
||||
def __str__(self):
|
||||
if not hasattr(self, "state"):
|
||||
# this instance failed on mscp_init
|
||||
return "mscp:{}:init-failed"
|
||||
return "mscp:{}:{}".format(self.remote, self.__state2str())
|
||||
|
||||
def __repr__(self):
|
||||
return "<{}>".format(str(self))
|
||||
|
||||
def __del__(self):
|
||||
|
||||
if not hasattr(self, "state"):
|
||||
return # this instance failed on mscp_init
|
||||
|
||||
if self.state == STATE_RUNNING:
|
||||
self.stop()
|
||||
if self.state == STATE_STOPPED:
|
||||
self.join()
|
||||
|
||||
self.cleanup()
|
||||
self.release()
|
||||
|
||||
def __state2str(self):
|
||||
return _state_str[self.state]
|
||||
|
||||
|
||||
def connect(self):
|
||||
if not (self.state == STATE_INIT or state.state == STATE_CLEANED):
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
pymscp.mscp_connect(m = self.m)
|
||||
self.state = STATE_CONNECTED
|
||||
|
||||
def add_src_path(self, src_path: str):
|
||||
if type(src_path) != str:
|
||||
raise ValueError("src_path must be str: {}".format(src_path))
|
||||
self.src_paths.append(src_path)
|
||||
pymscp.mscp_add_src_path(m = self.m, src_path = src_path)
|
||||
|
||||
def set_dst_path(self, dst_path: str):
|
||||
if type(dst_path) != str:
|
||||
raise ValueError("dst_path must be str: {}".format(dst_path))
|
||||
self.dst_path = dst_path
|
||||
pymscp.mscp_set_dst_path(m = self.m, dst_path = dst_path);
|
||||
|
||||
def scan(self):
|
||||
if self.state == STATE_SCANNED:
|
||||
return
|
||||
if self.state != STATE_CONNECTED:
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
if not self.src_paths:
|
||||
raise RuntimeError("src path list is empty")
|
||||
if self.dst_path == None:
|
||||
raise RuntimeError("dst path is not set")
|
||||
|
||||
pymscp.mscp_scan(m = self.m)
|
||||
self.state = STATE_SCANNED
|
||||
|
||||
def start(self):
|
||||
if self.state != STATE_SCANNED:
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
|
||||
pymscp.mscp_start(m = self.m)
|
||||
self.state = STATE_RUNNING
|
||||
|
||||
def stop(self):
|
||||
if self.state != STATE_RUNNING:
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
pymscp.mscp_stop(m = self.m)
|
||||
self.state = STATE_STOPPED
|
||||
|
||||
def join(self):
|
||||
if self.state == STATE_JOINED:
|
||||
return
|
||||
if not (self.state == STATE_RUNNING or self.state == STATE_STOPPED):
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
pymscp.mscp_join(m = self.m)
|
||||
self.state = STATE_JOINED
|
||||
|
||||
def stats(self):
|
||||
return pymscp.mscp_get_stats(m = self.m)
|
||||
|
||||
def cleanup(self):
|
||||
if self.state == STATE_RUNNING:
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
pymscp.mscp_cleanup(m = self.m)
|
||||
self.state = STATE_CLEANED
|
||||
|
||||
def release(self):
|
||||
if self.state != STATE_CLEANED:
|
||||
raise RuntimeError("invalid mscp state: {}".format(self.__state2str()))
|
||||
pymscp.mscp_free(m = self.m)
|
||||
self.state = STATE_RELEASED
|
||||
|
||||
# Simple interface: mscp.copy(src, dst)
|
||||
def copy(self, src, dst, nonblock = False):
|
||||
if self.state < STATE_CONNECTED:
|
||||
self.connect()
|
||||
|
||||
if type(src) == list:
|
||||
for path in src:
|
||||
self.add_src_path(path)
|
||||
elif type(src) == str:
|
||||
self.add_src_path(src)
|
||||
else:
|
||||
raise ValueError("src must be str of list: '{}'".format(src))
|
||||
|
||||
self.set_dst_path(dst)
|
||||
|
||||
self.scan()
|
||||
self.start()
|
||||
if nonblock:
|
||||
return
|
||||
|
||||
self.join()
|
||||
self.cleanup()
|
||||
@@ -1,3 +1,13 @@
|
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index a64b7708..c6344a5a 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -1,4 +1,4 @@
|
||||
-cmake_minimum_required(VERSION 3.3.0)
|
||||
+cmake_minimum_required(VERSION 3.13.0)
|
||||
cmake_policy(SET CMP0048 NEW)
|
||||
|
||||
# Specify search path for CMake modules to be loaded by include()
|
||||
diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
|
||||
index 9de10225..0f3d20ed 100644
|
||||
--- a/ConfigureChecks.cmake
|
||||
@@ -37,10 +47,18 @@ index 1fce7b76..b64d1455 100644
|
||||
int ssh_buffer_validate_length(struct ssh_buffer_struct *buffer, size_t len);
|
||||
|
||||
diff --git a/include/libssh/libssh.h b/include/libssh/libssh.h
|
||||
index 669a0a96..b6a93ac7 100644
|
||||
index 669a0a96..26b20f3f 100644
|
||||
--- a/include/libssh/libssh.h
|
||||
+++ b/include/libssh/libssh.h
|
||||
@@ -402,6 +402,7 @@ enum ssh_options_e {
|
||||
@@ -368,6 +368,7 @@ enum ssh_options_e {
|
||||
SSH_OPTIONS_HOST,
|
||||
SSH_OPTIONS_PORT,
|
||||
SSH_OPTIONS_PORT_STR,
|
||||
+ SSH_OPTIONS_AI_FAMILY,
|
||||
SSH_OPTIONS_FD,
|
||||
SSH_OPTIONS_USER,
|
||||
SSH_OPTIONS_SSH_DIR,
|
||||
@@ -402,6 +403,7 @@ enum ssh_options_e {
|
||||
SSH_OPTIONS_GSSAPI_AUTH,
|
||||
SSH_OPTIONS_GLOBAL_KNOWNHOSTS,
|
||||
SSH_OPTIONS_NODELAY,
|
||||
@@ -48,7 +66,7 @@ index 669a0a96..b6a93ac7 100644
|
||||
SSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES,
|
||||
SSH_OPTIONS_PROCESS_CONFIG,
|
||||
SSH_OPTIONS_REKEY_DATA,
|
||||
@@ -833,6 +834,7 @@ LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
|
||||
@@ -833,6 +835,7 @@ LIBSSH_API const char* ssh_get_hmac_in(ssh_session session);
|
||||
LIBSSH_API const char* ssh_get_hmac_out(ssh_session session);
|
||||
|
||||
LIBSSH_API ssh_buffer ssh_buffer_new(void);
|
||||
@@ -56,20 +74,31 @@ index 669a0a96..b6a93ac7 100644
|
||||
LIBSSH_API void ssh_buffer_free(ssh_buffer buffer);
|
||||
#define SSH_BUFFER_FREE(x) \
|
||||
do { if ((x) != NULL) { ssh_buffer_free(x); x = NULL; } } while(0)
|
||||
@@ -843,6 +845,8 @@ LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer);
|
||||
@@ -843,6 +846,11 @@ LIBSSH_API void *ssh_buffer_get(ssh_buffer buffer);
|
||||
LIBSSH_API uint32_t ssh_buffer_get_len(ssh_buffer buffer);
|
||||
LIBSSH_API int ssh_session_set_disconnect_message(ssh_session session, const char *message);
|
||||
|
||||
+typedef ssize_t (*ssh_add_func) (void *ptr, size_t max_bytes, void *userdata);
|
||||
+
|
||||
+LIBSSH_API const char **ssh_ciphers(void);
|
||||
+LIBSSH_API const char **ssh_hmacs(void);
|
||||
+
|
||||
#ifndef LIBSSH_LEGACY_0_4
|
||||
#include "libssh/legacy.h"
|
||||
#endif
|
||||
diff --git a/include/libssh/session.h b/include/libssh/session.h
|
||||
index 97936195..e4a7f80c 100644
|
||||
index 97936195..e4fc4fce 100644
|
||||
--- a/include/libssh/session.h
|
||||
+++ b/include/libssh/session.h
|
||||
@@ -258,6 +258,7 @@ struct ssh_session_struct {
|
||||
@@ -249,6 +249,7 @@ struct ssh_session_struct {
|
||||
unsigned long timeout; /* seconds */
|
||||
unsigned long timeout_usec;
|
||||
uint16_t port;
|
||||
+ int ai_family;
|
||||
socket_t fd;
|
||||
int StrictHostKeyChecking;
|
||||
char compressionlevel;
|
||||
@@ -258,6 +259,7 @@ struct ssh_session_struct {
|
||||
int flags;
|
||||
int exp_flags;
|
||||
int nodelay;
|
||||
@@ -204,9 +233,27 @@ index 8991e006..e0414801 100644
|
||||
* @brief Ensure the buffer has at least a certain preallocated size.
|
||||
*
|
||||
diff --git a/src/connect.c b/src/connect.c
|
||||
index 15cae644..e7520f40 100644
|
||||
index 15cae644..02ef43b4 100644
|
||||
--- a/src/connect.c
|
||||
+++ b/src/connect.c
|
||||
@@ -114,7 +114,7 @@ static int ssh_connect_socket_close(socket_t s)
|
||||
#endif
|
||||
}
|
||||
|
||||
-static int getai(const char *host, int port, struct addrinfo **ai)
|
||||
+static int getai(const char *host, int port, int ai_family, struct addrinfo **ai)
|
||||
{
|
||||
const char *service = NULL;
|
||||
struct addrinfo hints;
|
||||
@@ -123,7 +123,7 @@ static int getai(const char *host, int port, struct addrinfo **ai)
|
||||
ZERO_STRUCT(hints);
|
||||
|
||||
hints.ai_protocol = IPPROTO_TCP;
|
||||
- hints.ai_family = PF_UNSPEC;
|
||||
+ hints.ai_family = ai_family > 0 ? ai_family : PF_UNSPEC;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
||||
if (port == 0) {
|
||||
@@ -156,6 +156,20 @@ static int set_tcp_nodelay(socket_t socket)
|
||||
sizeof(opt));
|
||||
}
|
||||
@@ -228,6 +275,24 @@ index 15cae644..e7520f40 100644
|
||||
/**
|
||||
* @internal
|
||||
*
|
||||
@@ -173,7 +187,7 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
|
||||
struct addrinfo *ai = NULL;
|
||||
struct addrinfo *itr = NULL;
|
||||
|
||||
- rc = getai(host, port, &ai);
|
||||
+ rc = getai(host, port, session->opts.ai_family, &ai);
|
||||
if (rc != 0) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Failed to resolve hostname %s (%s)",
|
||||
@@ -199,7 +213,7 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
|
||||
|
||||
SSH_LOG(SSH_LOG_PACKET, "Resolving %s", bind_addr);
|
||||
|
||||
- rc = getai(bind_addr, 0, &bind_ai);
|
||||
+ rc = getai(bind_addr, 0, session->opts.ai_family, &bind_ai);
|
||||
if (rc != 0) {
|
||||
ssh_set_error(session, SSH_FATAL,
|
||||
"Failed to resolve bind address %s (%s)",
|
||||
@@ -256,6 +270,18 @@ socket_t ssh_connect_host_nonblocking(ssh_session session, const char *host,
|
||||
}
|
||||
}
|
||||
@@ -247,8 +312,62 @@ index 15cae644..e7520f40 100644
|
||||
errno = 0;
|
||||
rc = connect(s, itr->ai_addr, itr->ai_addrlen);
|
||||
if (rc == -1 && (errno != 0) && (errno != EINPROGRESS)) {
|
||||
diff --git a/src/misc.c b/src/misc.c
|
||||
index 7081f12a..e3879fe4 100644
|
||||
--- a/src/misc.c
|
||||
+++ b/src/misc.c
|
||||
@@ -71,6 +71,8 @@
|
||||
#include "libssh/priv.h"
|
||||
#include "libssh/misc.h"
|
||||
#include "libssh/session.h"
|
||||
+#include "libssh/wrapper.h"
|
||||
+#include "libssh/crypto.h"
|
||||
|
||||
#ifdef HAVE_LIBGCRYPT
|
||||
#define GCRYPT_STRING "/gnutls"
|
||||
@@ -2074,4 +2076,40 @@ int ssh_check_hostname_syntax(const char *hostname)
|
||||
return SSH_OK;
|
||||
}
|
||||
|
||||
+/**
|
||||
+ * @brief Return supported cipher names
|
||||
+ * @return The list of cipher names.
|
||||
+ */
|
||||
+const char **ssh_ciphers(void)
|
||||
+{
|
||||
+ struct ssh_cipher_struct *tab=ssh_get_ciphertab();
|
||||
+ static const char *ciphers[32];
|
||||
+ int n;
|
||||
+
|
||||
+ memset(ciphers, 0, sizeof(*ciphers));
|
||||
+
|
||||
+ for (n = 0; tab[n].name != NULL; n++) {
|
||||
+ ciphers[n] = tab[n].name;
|
||||
+ }
|
||||
+ return ciphers;
|
||||
+}
|
||||
+
|
||||
+/**
|
||||
+ * @brief Return supported hmac names
|
||||
+ * @return The list of hmac names.
|
||||
+ */
|
||||
+const char **ssh_hmacs(void)
|
||||
+{
|
||||
+ struct ssh_hmac_struct *tab=ssh_get_hmactab();
|
||||
+ static const char *hmacs[32];
|
||||
+ int n;
|
||||
+
|
||||
+ memset(hmacs, 0, sizeof(*hmacs));
|
||||
+
|
||||
+ for (n = 0; tab[n].name != NULL; n++) {
|
||||
+ hmacs[n] = tab[n].name;
|
||||
+ }
|
||||
+ return hmacs;
|
||||
+}
|
||||
+
|
||||
/** @} */
|
||||
diff --git a/src/options.c b/src/options.c
|
||||
index b3ecffe1..fb966fa1 100644
|
||||
index b3ecffe1..8de24ed6 100644
|
||||
--- a/src/options.c
|
||||
+++ b/src/options.c
|
||||
@@ -217,6 +217,7 @@ int ssh_options_copy(ssh_session src, ssh_session *dest)
|
||||
@@ -259,7 +378,17 @@ index b3ecffe1..fb966fa1 100644
|
||||
new->opts.config_processed = src->opts.config_processed;
|
||||
new->common.log_verbosity = src->common.log_verbosity;
|
||||
new->common.callbacks = src->common.callbacks;
|
||||
@@ -458,6 +459,10 @@ int ssh_options_set_algo(ssh_session session,
|
||||
@@ -268,6 +269,9 @@ int ssh_options_set_algo(ssh_session session,
|
||||
* - SSH_OPTIONS_PORT_STR:
|
||||
* The port to connect to (const char *).
|
||||
*
|
||||
+ * - SSH_OPTIONS_AI_FAMILY:
|
||||
+ * The address family for connecting (int *).
|
||||
+ *
|
||||
* - SSH_OPTIONS_FD:
|
||||
* The file descriptor to use (socket_t).\n
|
||||
* \n
|
||||
@@ -458,6 +462,10 @@ int ssh_options_set_algo(ssh_session session,
|
||||
* Set it to disable Nagle's Algorithm (TCP_NODELAY) on the
|
||||
* session socket. (int, 0=false)
|
||||
*
|
||||
@@ -270,7 +399,29 @@ index b3ecffe1..fb966fa1 100644
|
||||
* - SSH_OPTIONS_PROCESS_CONFIG
|
||||
* Set it to false to disable automatic processing of per-user
|
||||
* and system-wide OpenSSH configuration files. LibSSH
|
||||
@@ -1017,6 +1022,20 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||
@@ -571,6 +579,21 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||
session->opts.port = i & 0xffffU;
|
||||
}
|
||||
break;
|
||||
+ case SSH_OPTIONS_AI_FAMILY:
|
||||
+ if (value == NULL) {
|
||||
+ session->opts.ai_family = 0;
|
||||
+ ssh_set_error_invalid(session);
|
||||
+ return -1;
|
||||
+ } else {
|
||||
+ int *x = (int *) value;
|
||||
+ if (*x < 0) {
|
||||
+ session->opts.ai_family = 0;
|
||||
+ ssh_set_error_invalid(session);
|
||||
+ return -1;
|
||||
+ }
|
||||
+ session->opts.ai_family = *x;
|
||||
+ }
|
||||
+ break;
|
||||
case SSH_OPTIONS_FD:
|
||||
if (value == NULL) {
|
||||
session->opts.fd = SSH_INVALID_SOCKET;
|
||||
@@ -1017,6 +1040,20 @@ int ssh_options_set(ssh_session session, enum ssh_options_e type,
|
||||
session->opts.nodelay = (*x & 0xff) > 0 ? 1 : 0;
|
||||
}
|
||||
break;
|
||||
@@ -292,10 +443,14 @@ index b3ecffe1..fb966fa1 100644
|
||||
if (value == NULL) {
|
||||
ssh_set_error_invalid(session);
|
||||
diff --git a/src/session.c b/src/session.c
|
||||
index 8c509699..88602b6a 100644
|
||||
index 8c509699..307388e5 100644
|
||||
--- a/src/session.c
|
||||
+++ b/src/session.c
|
||||
@@ -108,6 +108,7 @@ ssh_session ssh_new(void)
|
||||
@@ -105,9 +105,11 @@ ssh_session ssh_new(void)
|
||||
/* OPTIONS */
|
||||
session->opts.StrictHostKeyChecking = 1;
|
||||
session->opts.port = 22;
|
||||
+ session->opts.ai_family = 0;
|
||||
session->opts.fd = -1;
|
||||
session->opts.compressionlevel = 7;
|
||||
session->opts.nodelay = 0;
|
||||
|
||||
37
pysetup.py
37
pysetup.py
@@ -1,37 +0,0 @@
|
||||
from setuptools import setup, Extension, find_packages
|
||||
import sys
|
||||
import os
|
||||
|
||||
mypackage_root_dir = os.path.dirname(__file__)
|
||||
with open(os.path.join(mypackage_root_dir, 'VERSION')) as version_file:
|
||||
version = version_file.read().strip()
|
||||
|
||||
if sys.platform == "linux":
|
||||
libmscp = "libmscp.so"
|
||||
elif sys.platform == "darwin":
|
||||
libmscp = "libmscp.dylib"
|
||||
|
||||
data_dir = sys.prefix + "/lib"
|
||||
libmscp = "build/" + libmscp
|
||||
|
||||
setup(
|
||||
name='mscp',
|
||||
version = version,
|
||||
description = "libmscp python binding",
|
||||
author = "Ryo Nakamura",
|
||||
author_email = "upa@haeena.net",
|
||||
url = "https://github.com/upa/mscp",
|
||||
packages = find_packages("mscp"),
|
||||
package_dir = {"": "mscp"},
|
||||
data_files = [ (data_dir, [libmscp])],
|
||||
py_modules = [ "mscp" ],
|
||||
ext_modules = [
|
||||
Extension(
|
||||
'pymscp',
|
||||
['src/pymscp.c'],
|
||||
library_dirs = ['build'],
|
||||
libraries = ['mscp'],
|
||||
include_dirs = ['include']
|
||||
)
|
||||
]
|
||||
)
|
||||
3
rpm/.gitignore
vendored
Normal file
3
rpm/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
|
||||
# generated by cmake
|
||||
mscp.spec
|
||||
57
rpm/mscp.spec.in
Normal file
57
rpm/mscp.spec.in
Normal file
@@ -0,0 +1,57 @@
|
||||
Name: mscp
|
||||
Version: @MSCP_VERSION@
|
||||
Release: 1%{?dist}
|
||||
Summary: mscp, fast file transfer over multiple SSH connections
|
||||
|
||||
Group: Applications/Internet
|
||||
License: GPLv3
|
||||
URL: https://github.com/upa/mscp
|
||||
Source0: %{name}-%{version}.tar.gz
|
||||
|
||||
BuildRequires: gcc make cmake zlib-devel openssl-devel
|
||||
Requires: glibc crypto-policies krb5-libs openssl-libs libcom_err
|
||||
|
||||
%description
|
||||
mscp transfers files over multiple SSH connections. Multiple threads
|
||||
and connections in mscp transfer (1) multiple files simultaneously
|
||||
and (2) a large file in parallel. It would shorten the waiting time
|
||||
for transferring a lot of/large files over networks.
|
||||
|
||||
|
||||
%global debug_package %{nil}
|
||||
|
||||
%prep
|
||||
%setup -q
|
||||
|
||||
|
||||
%build
|
||||
cmake -S . -B build -DINSTALL_EXECUTABLE_ONLY=ON
|
||||
make -C build %{?_smp_mflags}
|
||||
|
||||
|
||||
%install
|
||||
make -C build install DESTDIR=%{buildroot}
|
||||
|
||||
%files
|
||||
/usr/local/bin/mscp
|
||||
/usr/local/share/man/man1/mscp.1
|
||||
|
||||
|
||||
%changelog
|
||||
* Wed Apr 16 2025 Ryo Nakamura <upa@haeena.net> - 0.2.2-1
|
||||
- RPM release for v0.2.2
|
||||
|
||||
* Sat May 11 2024 Ryo Nakamura <upa@haeena.net> - 0.2.1-1
|
||||
- RPM release for v0.2.1
|
||||
|
||||
* Mon Apr 15 2024 Ryo Nakamura <upa@haeena.net> - 0.2.0-1
|
||||
- RPM release for v0.2.0
|
||||
|
||||
* Thu Mar 14 2024 Ryo Nakamura <upa@haeena.net> - 0.1.5-0
|
||||
- RPM release for v0.1.5
|
||||
|
||||
* Wed Feb 07 2024 Ryo Nakamura <upa@haeena.net> - 0.1.4-0
|
||||
- RPM release for v0.1.4
|
||||
|
||||
* Sat Feb 03 2024 Ryo Nakamura <upa@haeena.net> - 0.1.3-0
|
||||
- Initial release for rpm packaging
|
||||
@@ -1,30 +1,77 @@
|
||||
#!/bin/bash -eu
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Install build dpenedencies.
|
||||
|
||||
set -e
|
||||
#set -u
|
||||
|
||||
function print_help() {
|
||||
echo "$0 [options]"
|
||||
echo " --dont-install Print required packages."
|
||||
echo " --platform [PLATFORM] PLATFORM is Kernel-ID, e.g., Linux-ubuntu."
|
||||
echo " Automatically detected if not specified."
|
||||
}
|
||||
|
||||
platform=$(uname -s)
|
||||
doinstall=1
|
||||
|
||||
if [ -e /etc/os-release ]; then
|
||||
source /etc/os-release
|
||||
platform=${platform}-${ID}
|
||||
fi
|
||||
|
||||
set -x
|
||||
while getopts h-: opt; do
|
||||
optarg="${!OPTIND}"
|
||||
[[ "$opt" = - ]] && opt="-$OPTARG"
|
||||
case "-${opt}" in
|
||||
--dont-install)
|
||||
doinstall=0
|
||||
;;
|
||||
--platform)
|
||||
platform=$optarg
|
||||
shift
|
||||
;;
|
||||
-h)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
print_help
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
case $platform in
|
||||
Darwin)
|
||||
brew install openssl@1.1
|
||||
cmd="brew install"
|
||||
pkgs="openssl@3"
|
||||
;;
|
||||
Linux-ubuntu*)
|
||||
apt-get install -y \
|
||||
gcc make cmake zlib1g-dev libssl-dev libkrb5-dev
|
||||
cmd="apt-get install --no-install-recommends -y"
|
||||
pkgs="gcc make cmake zlib1g-dev libssl-dev libkrb5-dev"
|
||||
;;
|
||||
Linux-centos* | Linux-rhel* | Linux-rocky* | Linux-almalinux)
|
||||
yum install -y \
|
||||
gcc make cmake zlib-devel openssl-devel rpm-build
|
||||
cmd="yum install -y"
|
||||
pkgs="gcc make cmake zlib-devel openssl-devel rpm-build"
|
||||
;;
|
||||
Linux-arch*)
|
||||
cmd="pacman --no-confirm -S"
|
||||
pkgs="gcc make cmake"
|
||||
;;
|
||||
FreeBSD-freebsd)
|
||||
cmd="pkg install"
|
||||
pkgs="cmake"
|
||||
;;
|
||||
*)
|
||||
echo "unsupported platform: $platform"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
if [ $doinstall -gt 0 ]; then
|
||||
echo do "$cmd $pkgs"
|
||||
$cmd $pkgs
|
||||
else
|
||||
echo $pkgs
|
||||
fi
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
#!/bin/bash -e
|
||||
#
|
||||
# Print install dpenedencies on Linux. CMake runs this script to obtain deps for CPACK.
|
||||
# mscp dependes on packages on which libssh depends.
|
||||
|
||||
source /etc/os-release
|
||||
|
||||
release=$1
|
||||
|
||||
case $release in
|
||||
ubuntu-20.04*)
|
||||
echo "libc6 (>= 2.27), libgssapi-krb5-2 (>= 1.17), libssl1.1 (>= 1.1.1), zlib1g (>= 1:1.1.4)"
|
||||
;;
|
||||
ubuntu-22.04*)
|
||||
echo "libc6 (>= 2.33), libgssapi-krb5-2 (>= 1.17), libssl3 (>= 3.0.0~~alpha1), zlib1g (>= 1:1.1.4)"
|
||||
;;
|
||||
centos* | rhel* | rocky* | almalinux*)
|
||||
echo "glibc crypto-policies krb5-libs openssl-libs libcom_err"
|
||||
;;
|
||||
*)
|
||||
echo "$(basename $0): unsupported install dependency: $release"
|
||||
exit 1
|
||||
esac
|
||||
@@ -8,13 +8,25 @@ cd $script_dir
|
||||
|
||||
set -x
|
||||
|
||||
# sshd Linsten on 22 and 8022
|
||||
echo "Port 22" >> /etc/ssh/sshd_config
|
||||
echo "Port 8022" >> /etc/ssh/sshd_config
|
||||
|
||||
## Alpine default sshd disables TcpForwarding, which is required for proxyjump test
|
||||
sed -i -e 's/AllowTcpForwarding no/AllowTcpForwarding yes/' /etc/ssh/sshd_config
|
||||
|
||||
# Run sshd
|
||||
if [ ! -e /var/run/sshd.pid ]; then
|
||||
/usr/sbin/sshd
|
||||
/usr/sbin/sshd -E /tmp/sshd.log
|
||||
sleep 1
|
||||
fi
|
||||
|
||||
ssh-keyscan localhost >> ${HOME}/.ssh/known_hosts
|
||||
for port in 22 8022; do
|
||||
ssh-keyscan -p $port localhost >> ${HOME}/.ssh/known_hosts
|
||||
ssh-keyscan -p $port ip6-localhost >> ${HOME}/.ssh/known_hosts
|
||||
ssh-keyscan -p $port 127.0.0.1 >> ${HOME}/.ssh/known_hosts
|
||||
ssh-keyscan -p $port ::1 >> ${HOME}/.ssh/known_hosts
|
||||
done
|
||||
|
||||
# Run test
|
||||
python3 -m pytest ../test -v
|
||||
python3 -m pytest -v ../test
|
||||
|
||||
26
src/atomic.h
26
src/atomic.h
@@ -6,8 +6,6 @@
|
||||
#include <assert.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <message.h>
|
||||
|
||||
typedef int refcnt;
|
||||
|
||||
static inline void refcnt_inc(refcnt *cnt)
|
||||
@@ -20,7 +18,6 @@ static inline refcnt refcnt_dec(refcnt *cnt)
|
||||
return __sync_sub_and_fetch(cnt, 1);
|
||||
}
|
||||
|
||||
|
||||
/* mutex */
|
||||
|
||||
typedef pthread_mutex_t lock;
|
||||
@@ -47,14 +44,11 @@ static inline void lock_release_via_cleanup(void *l)
|
||||
lock_release(l);
|
||||
}
|
||||
|
||||
#define LOCK_ACQUIRE(l) \
|
||||
lock_acquire(l); \
|
||||
#define LOCK_ACQUIRE(l) \
|
||||
lock_acquire(l); \
|
||||
pthread_cleanup_push(lock_release_via_cleanup, l)
|
||||
|
||||
#define LOCK_RELEASE() \
|
||||
pthread_cleanup_pop(1)
|
||||
|
||||
|
||||
#define LOCK_RELEASE() pthread_cleanup_pop(1)
|
||||
|
||||
/* read/write lock */
|
||||
typedef pthread_rwlock_t rwlock;
|
||||
@@ -87,18 +81,14 @@ static inline void rwlock_release_via_cleanup(void *rw)
|
||||
rwlock_release(rw);
|
||||
}
|
||||
|
||||
#define RWLOCK_READ_ACQUIRE(rw) \
|
||||
rwlock_read_acquire(rw); \
|
||||
#define RWLOCK_READ_ACQUIRE(rw) \
|
||||
rwlock_read_acquire(rw); \
|
||||
pthread_cleanup_push(rwlock_release_via_cleanup, rw)
|
||||
|
||||
#define RWLOCK_WRITE_ACQUIRE(rw) \
|
||||
rwlock_write_acquire(rw); \
|
||||
#define RWLOCK_WRITE_ACQUIRE(rw) \
|
||||
rwlock_write_acquire(rw); \
|
||||
pthread_cleanup_push(rwlock_release_via_cleanup, rw)
|
||||
|
||||
|
||||
#define RWLOCK_RELEASE() \
|
||||
pthread_cleanup_pop(1)
|
||||
|
||||
|
||||
#define RWLOCK_RELEASE() pthread_cleanup_pop(1)
|
||||
|
||||
#endif /* _ATOMIC_H_ */
|
||||
|
||||
94
src/bwlimit.c
Normal file
94
src/bwlimit.c
Normal file
@@ -0,0 +1,94 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#include <errno.h>
|
||||
|
||||
#include <bwlimit.h>
|
||||
#include <platform.h>
|
||||
|
||||
#define timespeczerorize(ts) \
|
||||
do { \
|
||||
ts.tv_sec = 0; \
|
||||
ts.tv_nsec = 0; \
|
||||
} while (0)
|
||||
|
||||
int bwlimit_init(struct bwlimit *bw, uint64_t bps, uint64_t win)
|
||||
{
|
||||
if (!(bw->sem = sem_create(1)))
|
||||
return -1;
|
||||
|
||||
bw->bps = bps;
|
||||
bw->win = win; /* msec window */
|
||||
bw->amt = (double)bps / 8 / 1000 * win; /* bytes in a window (msec) */
|
||||
bw->credit = bw->amt;
|
||||
timespeczerorize(bw->wstart);
|
||||
timespeczerorize(bw->wend);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define timespecisset(ts) ((ts).tv_sec || (ts).tv_nsec)
|
||||
|
||||
#define timespecmsadd(a, msec, r) \
|
||||
do { \
|
||||
(r).tv_sec = (a).tv_sec; \
|
||||
(r).tv_nsec = (a).tv_nsec + (msec * 1000000); \
|
||||
if ((r).tv_nsec > 1000000000) { \
|
||||
(r).tv_sec += (r.tv_nsec) / 1000000000L; \
|
||||
(r).tv_nsec = (r.tv_nsec) % 1000000000L; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define timespecsub(a, b, r) \
|
||||
do { \
|
||||
(r).tv_sec = (a).tv_sec - (b).tv_sec; \
|
||||
(r).tv_nsec = (a).tv_nsec - (b).tv_nsec; \
|
||||
if ((r).tv_nsec < 0) { \
|
||||
(r).tv_sec -= 1; \
|
||||
(r).tv_nsec += 1000000000; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define timespeccmp(a, b, expr) \
|
||||
((a.tv_sec * 1000000000 + a.tv_nsec) expr(b.tv_sec * 1000000000 + b.tv_nsec))
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int bwlimit_wait(struct bwlimit *bw, size_t nr_bytes)
|
||||
{
|
||||
struct timespec now, end, rq, rm;
|
||||
|
||||
if (bw->bps == 0)
|
||||
return 0; /* no bandwidth limit */
|
||||
|
||||
if (sem_wait(bw->sem) < 0)
|
||||
return -1;
|
||||
|
||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||
|
||||
if (!timespecisset(bw->wstart)) {
|
||||
bw->wstart = now;
|
||||
timespecmsadd(bw->wstart, bw->win, bw->wend);
|
||||
}
|
||||
|
||||
bw->credit -= nr_bytes;
|
||||
|
||||
if (bw->credit < 0) {
|
||||
/* no more credit on this window. sleep until the end
|
||||
* of this window + additional time for the remaining
|
||||
* bytes. */
|
||||
uint64_t addition = (double)(bw->credit * -1) / (bw->bps / 8);
|
||||
timespecmsadd(bw->wend, addition * 1000, end);
|
||||
if (timespeccmp(end, now, >)) {
|
||||
timespecsub(end, now, rq);
|
||||
while (nanosleep(&rq, &rm) == -1) {
|
||||
if (errno != EINTR)
|
||||
break;
|
||||
rq = rm;
|
||||
}
|
||||
}
|
||||
bw->credit = bw->amt;
|
||||
timespeczerorize(bw->wstart);
|
||||
}
|
||||
|
||||
sem_post(bw->sem);
|
||||
return 0;
|
||||
}
|
||||
28
src/bwlimit.h
Normal file
28
src/bwlimit.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _BWLIMIT_H_
|
||||
#define _BWLIMIT_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <sys/types.h>
|
||||
#include <time.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
struct bwlimit {
|
||||
sem_t *sem; /* semaphore */
|
||||
uint64_t bps; /* limit bit-rate (bps) */
|
||||
uint64_t win; /* window size (msec) */
|
||||
size_t amt; /* amount of bytes can be sent in a window */
|
||||
|
||||
ssize_t credit; /* remaining bytes can be sent in a window */
|
||||
struct timespec wstart, wend; /* window start time and end time */
|
||||
};
|
||||
|
||||
int bwlimit_init(struct bwlimit *bw, uint64_t bps, uint64_t win);
|
||||
/* if bps is 0, it means that bwlimit is not active. If so,
|
||||
* bwlimit_wait() returns immediately. */
|
||||
|
||||
int bwlimit_wait(struct bwlimit *bw, size_t nr_bytes);
|
||||
|
||||
|
||||
#endif /* _BWLIMIT_H_ */
|
||||
505
src/checkpoint.c
Normal file
505
src/checkpoint.c
Normal file
@@ -0,0 +1,505 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#include <fcntl.h>
|
||||
#include <sys/uio.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
#include <path.h>
|
||||
#include <print.h>
|
||||
#include <platform.h>
|
||||
#include <strerrno.h>
|
||||
#include <openbsd-compat/openbsd-compat.h>
|
||||
|
||||
#include <checkpoint.h>
|
||||
|
||||
#define MSCP_CHECKPOINT_MAGIC 0x7063736dUL /* mscp in ascii */
|
||||
#define MSCP_CHECKPOINT_VERSION 0x1
|
||||
|
||||
/**
|
||||
* mscp checkpoint file format. All values are network byte order.
|
||||
*
|
||||
* The file starts with the File header:
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +---------------------------------------------------------------+
|
||||
* | Magic Code |
|
||||
* +---------------+-----------------------------------------------+
|
||||
* | Version |
|
||||
* +---------------+
|
||||
*
|
||||
* Magic code: 0x7063736dUL
|
||||
*
|
||||
* Version: 1.
|
||||
*
|
||||
*
|
||||
* Each object in a checkpoint always starts with an object header:
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Type | rsv | Length |
|
||||
* +---------------+---------------+-------------------------------+
|
||||
*
|
||||
* Type: 0x0A (meta), 0x0B (path), or 0x0C (chunk)
|
||||
*
|
||||
* Rsv: reserved
|
||||
*
|
||||
* Length: Length of this object including the object header.
|
||||
*
|
||||
*
|
||||
* Meta object provides generaic information for the failed copy:
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Type | rsv | Length |
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Direction | Remote string ...
|
||||
* +---------------+------------------
|
||||
*
|
||||
* Direction: 1 (Local-to-Remote copy) or 2 (Remote-to-Local copy)
|
||||
*
|
||||
* Remote string: Remote host, e.g., user@hostname and IP address,
|
||||
* string including '\0'.
|
||||
*
|
||||
*
|
||||
* Path object represnts a file with sourcen and destination paths:
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Type | rsv | Length |
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Index |
|
||||
* +-------------------------------+-------------------------------+
|
||||
* | Source offset | Destination offset |
|
||||
* +-------------------------------+-------------------------------+
|
||||
* // //
|
||||
* // Source path string //
|
||||
* // //
|
||||
* +---------------------------------------------------------------+
|
||||
* // //
|
||||
* // Destination path string //
|
||||
* // //
|
||||
* +---------------------------------------------------------------+
|
||||
*
|
||||
* Index: 32-bit unsigned int indicating this path (used by chunks)
|
||||
*
|
||||
* Source offset: Offset of the Source path string from the head of
|
||||
* this object. It is identical to the end of the Destination offset
|
||||
* filed.
|
||||
*
|
||||
* Destination offset: Offset of the Destnation path string from the
|
||||
* head of this object. It also indicates the end of the Source path
|
||||
* string.
|
||||
*
|
||||
* Source path string: String of copy source path (including '\0').
|
||||
*
|
||||
* Destination path string: string of copy destination path (including
|
||||
* '\0').
|
||||
*
|
||||
*
|
||||
* Chunk object represents a chunk associated with a path object:
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Type | rsv | Length |
|
||||
* +---------------+---------------+-------------------------------+
|
||||
* | Index |
|
||||
* +---------------------------------------------------------------+
|
||||
* | Chunk |
|
||||
* | offset |
|
||||
* +---------------------------------------------------------------+
|
||||
* | Chunk |
|
||||
* | length |
|
||||
* +---------------------------------------------------------------+
|
||||
*
|
||||
* Index: 32 bit unsigned int indicating the index of a path object
|
||||
* this chunk associated with.
|
||||
*
|
||||
* Chunk offset: 64 bit unsigned int indicating the offset of this
|
||||
* chunk from the head of the associating a file.
|
||||
*
|
||||
* Chunk length: 64 bit unsigned int indicating the length (bytes) of
|
||||
* this chunk.
|
||||
*/
|
||||
|
||||
enum {
|
||||
OBJ_TYPE_META = 0x0A,
|
||||
OBJ_TYPE_PATH = 0x0B,
|
||||
OBJ_TYPE_CHUNK = 0x0C,
|
||||
};
|
||||
|
||||
struct checkpoint_file_hdr {
|
||||
uint32_t magic;
|
||||
uint8_t version;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct checkpoint_obj_hdr {
|
||||
uint8_t type;
|
||||
uint8_t rsv;
|
||||
uint16_t len; /* length of an object including this hdr */
|
||||
} __attribute__((packed));
|
||||
|
||||
struct checkpoint_obj_meta {
|
||||
struct checkpoint_obj_hdr hdr;
|
||||
uint8_t direction; /* L2R or R2L */
|
||||
|
||||
char remote[0];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct checkpoint_obj_path {
|
||||
struct checkpoint_obj_hdr hdr;
|
||||
|
||||
uint32_t idx;
|
||||
uint16_t src_off; /* offset to the src path string (including
|
||||
* \0) from the head of this object. */
|
||||
uint16_t dst_off; /* offset to the dst path string (including
|
||||
* \0) from the head of this object */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define obj_path_src(o) ((char *)(o) + ntohs(o->src_off))
|
||||
#define obj_path_dst(o) ((char *)(o) + ntohs(o->dst_off))
|
||||
|
||||
#define obj_path_src_len(o) (ntohs(o->dst_off) - ntohs(o->src_off))
|
||||
#define obj_path_dst_len(o) (ntohs(o->hdr.len) - ntohs(o->dst_off))
|
||||
|
||||
#define obj_path_validate(o) \
|
||||
((ntohs(o->hdr.len) > ntohs(o->dst_off)) && \
|
||||
(ntohs(o->dst_off) > ntohs(o->src_off)) && \
|
||||
(obj_path_src_len(o) < PATH_MAX) && \
|
||||
(obj_path_dst_len(o) < PATH_MAX))
|
||||
|
||||
struct checkpoint_obj_chunk {
|
||||
struct checkpoint_obj_hdr hdr;
|
||||
|
||||
uint32_t idx; /* index indicating associating path */
|
||||
uint64_t off;
|
||||
uint64_t len;
|
||||
} __attribute__((packed));
|
||||
|
||||
#define CHECKPOINT_OBJ_MAXLEN (sizeof(struct checkpoint_obj_path) + PATH_MAX * 2)
|
||||
|
||||
static int checkpoint_write_path(int fd, struct path *p, unsigned int idx)
|
||||
{
|
||||
char buf[CHECKPOINT_OBJ_MAXLEN];
|
||||
struct checkpoint_obj_path *path = (struct checkpoint_obj_path *)buf;
|
||||
size_t src_len, dst_len;
|
||||
struct iovec iov[3];
|
||||
|
||||
p->data = idx; /* save idx to be pointed by chunks */
|
||||
|
||||
src_len = strlen(p->path) + 1;
|
||||
dst_len = strlen(p->dst_path) + 1;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
path->hdr.type = OBJ_TYPE_PATH;
|
||||
path->hdr.len = htons(sizeof(*path) + src_len + dst_len);
|
||||
|
||||
path->idx = htonl(idx);
|
||||
path->src_off = htons(sizeof(*path));
|
||||
path->dst_off = htons(sizeof(*path) + src_len);
|
||||
|
||||
iov[0].iov_base = path;
|
||||
iov[0].iov_len = sizeof(*path);
|
||||
iov[1].iov_base = p->path;
|
||||
iov[1].iov_len = src_len;
|
||||
iov[2].iov_base = p->dst_path;
|
||||
iov[2].iov_len = dst_len;
|
||||
|
||||
if (writev(fd, iov, 3) < 0) {
|
||||
priv_set_errv("writev: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int checkpoint_write_chunk(int fd, struct chunk *c)
|
||||
{
|
||||
struct checkpoint_obj_chunk chunk;
|
||||
|
||||
memset(&chunk, 0, sizeof(chunk));
|
||||
chunk.hdr.type = OBJ_TYPE_CHUNK;
|
||||
chunk.hdr.len = htons(sizeof(chunk));
|
||||
|
||||
chunk.idx = htonl(c->p->data); /* index stored by checkpoint_write_path */
|
||||
chunk.off = htonll(c->off);
|
||||
chunk.len = htonll(c->len);
|
||||
|
||||
if (write(fd, &chunk, sizeof(chunk)) < 0) {
|
||||
priv_set_errv("writev: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int checkpoint_save(const char *pathname, int dir, const char *user, const char *remote,
|
||||
pool *path_pool, pool *chunk_pool)
|
||||
{
|
||||
struct checkpoint_file_hdr hdr;
|
||||
struct checkpoint_obj_meta meta;
|
||||
struct iovec iov[3];
|
||||
struct chunk *c;
|
||||
struct path *p;
|
||||
char buf[1024];
|
||||
unsigned int i, nr_paths, nr_chunks;
|
||||
int fd, ret;
|
||||
|
||||
fd = open(pathname, O_WRONLY | O_CREAT | O_TRUNC,
|
||||
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH);
|
||||
if (fd < 0) {
|
||||
priv_set_errv("open: %s: %s", pathname, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* write file hdr */
|
||||
hdr.magic = htonl(MSCP_CHECKPOINT_MAGIC);
|
||||
hdr.version = MSCP_CHECKPOINT_VERSION;
|
||||
|
||||
/* write meta */
|
||||
if (user)
|
||||
ret = snprintf(buf, sizeof(buf), "%s@%s", user, remote);
|
||||
else
|
||||
ret = snprintf(buf, sizeof(buf), "%s", remote);
|
||||
if (ret >= sizeof(buf)) {
|
||||
priv_set_errv("too long username and/or remote");
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&meta, 0, sizeof(meta));
|
||||
meta.hdr.type = OBJ_TYPE_META;
|
||||
meta.hdr.len = htons(sizeof(meta) + strlen(buf) + 1);
|
||||
meta.direction = dir;
|
||||
|
||||
iov[0].iov_base = &hdr;
|
||||
iov[0].iov_len = sizeof(hdr);
|
||||
iov[1].iov_base = &meta;
|
||||
iov[1].iov_len = sizeof(meta);
|
||||
iov[2].iov_base = buf;
|
||||
iov[2].iov_len = strlen(buf) + 1;
|
||||
|
||||
if (writev(fd, iov, 3) < 0) {
|
||||
priv_set_errv("writev: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* write paths */
|
||||
nr_paths = 0;
|
||||
pool_for_each(path_pool, p, i) {
|
||||
if (p->state == FILE_STATE_DONE)
|
||||
continue;
|
||||
if (checkpoint_write_path(fd, p, nr_paths) < 0)
|
||||
return -1;
|
||||
nr_paths++;
|
||||
}
|
||||
|
||||
/* write chunks */
|
||||
nr_chunks = 0;
|
||||
pool_for_each(chunk_pool, c, i) {
|
||||
if (c->state == CHUNK_STATE_DONE)
|
||||
continue;
|
||||
if (checkpoint_write_chunk(fd, c) < 0)
|
||||
return -1;
|
||||
nr_chunks++;
|
||||
}
|
||||
|
||||
pr_notice("checkpoint: %u paths and %u chunks saved", nr_paths, nr_chunks);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int checkpoint_load_meta(struct checkpoint_obj_hdr *hdr, char *remote, size_t len,
|
||||
int *dir)
|
||||
{
|
||||
struct checkpoint_obj_meta *meta = (struct checkpoint_obj_meta *)hdr;
|
||||
|
||||
if (len < ntohs(hdr->len) - sizeof(*meta)) {
|
||||
priv_set_errv("too short buffer");
|
||||
return -1;
|
||||
}
|
||||
snprintf(remote, len, "%s", meta->remote);
|
||||
*dir = meta->direction;
|
||||
|
||||
pr_notice("checkpoint: remote=%s direction=%s", meta->remote,
|
||||
meta->direction == MSCP_DIRECTION_L2R ? "local-to-remote" :
|
||||
meta->direction == MSCP_DIRECTION_R2L ? "remote-to-local" :
|
||||
"invalid");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int checkpoint_load_path(struct checkpoint_obj_hdr *hdr, pool *path_pool)
|
||||
{
|
||||
struct checkpoint_obj_path *path = (struct checkpoint_obj_path *)hdr;
|
||||
struct path *p;
|
||||
char *s, *d;
|
||||
|
||||
if (!obj_path_validate(path)) {
|
||||
priv_set_errv("invalid path object");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(s = strndup(obj_path_src(path), obj_path_src_len(path)))) {
|
||||
priv_set_errv("strdup: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(d = strndup(obj_path_dst(path), obj_path_dst_len(path)))) {
|
||||
priv_set_errv("strdup: %s", strerrno());
|
||||
free(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(p = alloc_path(s, d))) {
|
||||
free(s);
|
||||
free(d);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (pool_push(path_pool, p) < 0) {
|
||||
priv_set_errv("pool_push: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pr_info("checkpoint:file: idx=%u %s -> %s", ntohl(path->idx),
|
||||
p->path, p->dst_path);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int checkpoint_load_chunk(struct checkpoint_obj_hdr *hdr, pool *path_pool,
|
||||
pool *chunk_pool)
|
||||
{
|
||||
struct checkpoint_obj_chunk *chunk = (struct checkpoint_obj_chunk *)hdr;
|
||||
struct chunk *c;
|
||||
struct path *p;
|
||||
|
||||
if (!(p = pool_get(path_pool, ntohl(chunk->idx)))) {
|
||||
/* we assumes all paths are already loaded in the order */
|
||||
priv_set_errv("path index %u not found", ntohl(chunk->idx));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!(c = alloc_chunk(p, ntohll(chunk->off), ntohll(chunk->len))))
|
||||
return -1;
|
||||
|
||||
if (pool_push(chunk_pool, c) < 0) {
|
||||
priv_set_errv("pool_push: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
pr_debug("checkpoint:chunk: idx=%u %s 0x%lx-0x%lx", ntohl(chunk->idx),
|
||||
p->path, c->off, c->off + c->len);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int checkpoint_read_obj(int fd, void *buf, size_t count)
|
||||
{
|
||||
struct checkpoint_obj_hdr *hdr = (struct checkpoint_obj_hdr *)buf;
|
||||
ssize_t ret, objlen, objbuflen;
|
||||
|
||||
memset(buf, 0, count);
|
||||
|
||||
if (count < sizeof(*hdr)) {
|
||||
priv_set_errv("too short buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = read(fd, hdr, sizeof(*hdr));
|
||||
if (ret == 0)
|
||||
return 0; /* no more objects */
|
||||
if (ret < 0)
|
||||
return -1;
|
||||
|
||||
objlen = ntohs(hdr->len) - sizeof(*hdr);
|
||||
objbuflen = count - sizeof(*hdr);
|
||||
if (objbuflen < objlen) {
|
||||
priv_set_errv("too short buffer");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = read(fd, buf + sizeof(*hdr), objlen);
|
||||
if (ret < objlen) {
|
||||
priv_set_errv("checkpoint truncated");
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int checkpoint_read_file_hdr(int fd)
|
||||
{
|
||||
struct checkpoint_file_hdr hdr;
|
||||
ssize_t ret;
|
||||
|
||||
ret = read(fd, &hdr, sizeof(hdr));
|
||||
if (ret < 0) {
|
||||
priv_set_errv("read: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
if (ret < sizeof(hdr)) {
|
||||
priv_set_errv("checkpoint truncated");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (ntohl(hdr.magic) != MSCP_CHECKPOINT_MAGIC) {
|
||||
priv_set_errv("checkpoint: invalid megic code");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (hdr.version != MSCP_CHECKPOINT_VERSION) {
|
||||
priv_set_errv("checkpoint: unknown version %u", hdr.version);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int checkpoint_load(const char *pathname, char *remote, size_t len, int *dir,
|
||||
pool *path_pool, pool *chunk_pool)
|
||||
{
|
||||
char buf[CHECKPOINT_OBJ_MAXLEN];
|
||||
struct checkpoint_obj_hdr *hdr;
|
||||
int fd, ret;
|
||||
|
||||
if ((fd = open(pathname, O_RDONLY)) < 0) {
|
||||
priv_set_errv("open: %s: %s", pathname, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (checkpoint_read_file_hdr(fd) < 0)
|
||||
return -1;
|
||||
|
||||
hdr = (struct checkpoint_obj_hdr *)buf;
|
||||
while ((ret = checkpoint_read_obj(fd, buf, sizeof(buf))) > 0) {
|
||||
switch (hdr->type) {
|
||||
case OBJ_TYPE_META:
|
||||
if (!remote || !dir)
|
||||
break;
|
||||
if (checkpoint_load_meta(hdr, remote, len, dir) < 0)
|
||||
return -1;
|
||||
if (!path_pool || !chunk_pool)
|
||||
goto out;
|
||||
break;
|
||||
case OBJ_TYPE_PATH:
|
||||
if (!path_pool)
|
||||
break;
|
||||
if (checkpoint_load_path(hdr, path_pool) < 0)
|
||||
return -1;
|
||||
break;
|
||||
case OBJ_TYPE_CHUNK:
|
||||
if (!path_pool)
|
||||
break;
|
||||
if (checkpoint_load_chunk(hdr, path_pool, chunk_pool) < 0)
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
priv_set_errv("unknown obj type %u", hdr->type);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
out:
|
||||
close(fd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int checkpoint_load_remote(const char *pathname, char *remote, size_t len, int *dir)
|
||||
{
|
||||
return checkpoint_load(pathname, remote, len, dir, NULL, NULL);
|
||||
}
|
||||
|
||||
int checkpoint_load_paths(const char *pathname, pool *path_pool, pool *chunk_pool)
|
||||
{
|
||||
return checkpoint_load(pathname, NULL, 0, NULL, path_pool, chunk_pool);
|
||||
}
|
||||
21
src/checkpoint.h
Normal file
21
src/checkpoint.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _CHECKPOINT_H_
|
||||
#define _CHECKPOINT_H_
|
||||
|
||||
#include <pool.h>
|
||||
|
||||
/* checkpoint_save() stores states to a checkponint file (pathname) */
|
||||
int checkpoint_save(const char *pathname, int dir, const char *user, const char *remote,
|
||||
pool *path_pool, pool *chunk_pool);
|
||||
|
||||
/* checkpoint_load_meta() reads a checkpoint file (pathname) and returns
|
||||
* remote host string to *remote and transfer direction to *dir.
|
||||
*/
|
||||
int checkpoint_load_remote(const char *pathname, char *remote, size_t len, int *dir);
|
||||
|
||||
/* checkpoint_load_paths() reads a checkpoint file (pathname) and
|
||||
* fills path_pool and chunk_pool.
|
||||
*/
|
||||
int checkpoint_load_paths(const char *pathname, pool *path_pool, pool *chunk_pool);
|
||||
|
||||
#endif /* _CHECKPOINT_H_ */
|
||||
@@ -4,11 +4,13 @@
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/times.h>
|
||||
#include <utime.h>
|
||||
|
||||
#include <fileops.h>
|
||||
#include <ssh.h>
|
||||
#include <message.h>
|
||||
|
||||
#include <print.h>
|
||||
#include <platform.h>
|
||||
|
||||
sftp_session __thread tls_sftp;
|
||||
/* tls_sftp is used *_wrapped() functions */
|
||||
@@ -22,7 +24,7 @@ static void sftp_err_to_errno(sftp_session sftp)
|
||||
{
|
||||
int sftperr = sftp_get_error(sftp);
|
||||
|
||||
switch (sftperr){
|
||||
switch (sftperr) {
|
||||
case SSH_FX_OK:
|
||||
case SSH_FX_EOF:
|
||||
errno = 0;
|
||||
@@ -60,11 +62,10 @@ static void sftp_err_to_errno(sftp_session sftp)
|
||||
errno = ENODEV;
|
||||
break;
|
||||
default:
|
||||
mpr_warn(stderr, "unkown SSH_FX response %d", sftperr);
|
||||
pr_warn("unkown SSH_FX response %d", sftperr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
MDIR *mscp_opendir(const char *path, sftp_session sftp)
|
||||
{
|
||||
MDIR *md;
|
||||
@@ -109,7 +110,6 @@ void mscp_closedir(MDIR *md)
|
||||
free(md);
|
||||
}
|
||||
|
||||
|
||||
struct dirent __thread tls_dirent;
|
||||
/* tls_dirent contains dirent converted from sftp_attributes returned
|
||||
* from sftp_readdir(). This trick is derived from openssh's
|
||||
@@ -158,14 +158,25 @@ int mscp_mkdir(const char *path, mode_t mode, sftp_session sftp)
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
static void sftp_attr_to_stat(sftp_attributes attr, struct stat *st)
|
||||
{
|
||||
memset(st, 0, sizeof(*st));
|
||||
st->st_size = attr->size;
|
||||
st->st_uid = attr->uid;
|
||||
st->st_gid = attr->gid;
|
||||
st->st_mode = attr->permissions;
|
||||
memset(st, 0, sizeof(*st));
|
||||
st->st_size = attr->size;
|
||||
st->st_uid = attr->uid;
|
||||
st->st_gid = attr->gid;
|
||||
st->st_mode = attr->permissions;
|
||||
|
||||
#if defined(__APPLE__)
|
||||
#define st_atim st_atimespec
|
||||
#define st_mtim st_mtimespec
|
||||
#define st_ctim st_ctimespec
|
||||
#endif
|
||||
st->st_atim.tv_sec = attr->atime;
|
||||
st->st_atim.tv_nsec = attr->atime_nseconds;
|
||||
st->st_mtim.tv_sec = attr->mtime;
|
||||
st->st_mtim.tv_nsec = attr->mtime_nseconds;
|
||||
st->st_ctim.tv_sec = attr->createtime;
|
||||
st->st_ctim.tv_nsec = attr->createtime_nseconds;
|
||||
|
||||
switch (attr->type) {
|
||||
case SSH_FILEXFER_TYPE_REGULAR:
|
||||
@@ -184,18 +195,17 @@ static void sftp_attr_to_stat(sftp_attributes attr, struct stat *st)
|
||||
st->st_mode |= S_IFIFO; /* really? */
|
||||
break;
|
||||
default:
|
||||
mpr_warn(stderr, "unkown SSH_FILEXFER_TYPE %d", attr->type);
|
||||
pr_warn("unkown SSH_FILEXFER_TYPE %d", attr->type);
|
||||
}
|
||||
|
||||
/* ToDo: convert atime, ctime, and mtime */
|
||||
}
|
||||
|
||||
|
||||
int mscp_stat(const char *path, struct stat *st, sftp_session sftp)
|
||||
{
|
||||
sftp_attributes attr;
|
||||
int ret = 0;
|
||||
|
||||
memset(st, 0, sizeof(*st));
|
||||
|
||||
if (sftp) {
|
||||
attr = sftp_stat(sftp, path);
|
||||
sftp_err_to_errno(sftp);
|
||||
@@ -241,7 +251,6 @@ int mscp_lstat_wrapped(const char *path, struct stat *st)
|
||||
return mscp_lstat(path, st, tls_sftp);
|
||||
}
|
||||
|
||||
|
||||
mf *mscp_open(const char *path, int flags, mode_t mode, sftp_session sftp)
|
||||
{
|
||||
mf *f;
|
||||
@@ -292,22 +301,35 @@ off_t mscp_lseek(mf *f, off_t off)
|
||||
return ret;
|
||||
}
|
||||
|
||||
int mscp_setstat(const char *path, mode_t mode, size_t size, sftp_session sftp)
|
||||
int mscp_setstat(const char *path, struct stat *st, bool preserve_ts, sftp_session sftp)
|
||||
{
|
||||
int ret;
|
||||
|
||||
if (sftp) {
|
||||
struct sftp_attributes_struct attr;
|
||||
memset(&attr, 0, sizeof(attr));
|
||||
attr.permissions = mode;
|
||||
attr.size = size;
|
||||
attr.flags = (SSH_FILEXFER_ATTR_PERMISSIONS|SSH_FILEXFER_ATTR_SIZE);
|
||||
attr.permissions = st->st_mode;
|
||||
attr.size = st->st_size;
|
||||
attr.flags = (SSH_FILEXFER_ATTR_PERMISSIONS | SSH_FILEXFER_ATTR_SIZE);
|
||||
if (preserve_ts) {
|
||||
attr.atime = st->st_atim.tv_sec;
|
||||
attr.atime_nseconds = st->st_atim.tv_nsec;
|
||||
attr.mtime = st->st_mtim.tv_sec;
|
||||
attr.mtime_nseconds = st->st_mtim.tv_nsec;
|
||||
attr.flags |= (SSH_FILEXFER_ATTR_ACCESSTIME |
|
||||
SSH_FILEXFER_ATTR_MODIFYTIME |
|
||||
SSH_FILEXFER_ATTR_SUBSECOND_TIMES);
|
||||
}
|
||||
ret = sftp_setstat(sftp, path, &attr);
|
||||
sftp_err_to_errno(sftp);
|
||||
} else {
|
||||
if ((ret = chmod(path, mode)) < 0)
|
||||
if ((ret = truncate(path, st->st_size)) < 0)
|
||||
return ret;
|
||||
if ((ret = truncate(path, size)) < 0)
|
||||
if (preserve_ts) {
|
||||
if ((ret = setutimes(path, st->st_atim, st->st_mtim)) < 0)
|
||||
return ret;
|
||||
}
|
||||
if ((ret = chmod(path, st->st_mode)) < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -329,9 +351,9 @@ int mscp_glob(const char *pattern, int flags, glob_t *pglob, sftp_session sftp)
|
||||
#else
|
||||
flags |= GLOB_ALTDIRFUNC;
|
||||
set_tls_sftp_session(sftp);
|
||||
#ifdef __APPLE__
|
||||
#if defined(__APPLE__) || defined(__FreeBSD__)
|
||||
pglob->gl_opendir = (void *(*)(const char *))mscp_opendir_wrapped;
|
||||
pglob->gl_readdir = (struct dirent *(*)(void *))mscp_readdir;
|
||||
pglob->gl_readdir = (struct dirent * (*)(void *)) mscp_readdir;
|
||||
pglob->gl_closedir = (void (*)(void *))mscp_closedir;
|
||||
pglob->gl_lstat = mscp_lstat_wrapped;
|
||||
pglob->gl_stat = mscp_stat_wrapped;
|
||||
|
||||
@@ -19,7 +19,6 @@ struct mdir_struct {
|
||||
};
|
||||
typedef struct mdir_struct MDIR;
|
||||
|
||||
|
||||
MDIR *mscp_opendir(const char *path, sftp_session sftp);
|
||||
MDIR *mscp_opendir_wrapped(const char *path);
|
||||
void mscp_closedir(MDIR *md);
|
||||
@@ -34,7 +33,6 @@ int mscp_stat_wrapped(const char *path, struct stat *st);
|
||||
int mscp_lstat(const char *path, struct stat *st, sftp_session sftp);
|
||||
int mscp_lstat_wrapped(const char *path, struct stat *st);
|
||||
|
||||
|
||||
/* file operations */
|
||||
|
||||
struct mf_struct {
|
||||
@@ -50,7 +48,7 @@ off_t mscp_lseek(mf *f, off_t off);
|
||||
/* mscp_setstat() involves chmod and truncate. It executes both at
|
||||
* once via a single SFTP command (sftp_setstat()).
|
||||
*/
|
||||
int mscp_setstat(const char *path, mode_t mode, size_t size, sftp_session sftp);
|
||||
int mscp_setstat(const char *path, struct stat *st, bool preserve_ts, sftp_session sftp);
|
||||
|
||||
/* remote glob */
|
||||
int mscp_glob(const char *pattern, int flags, glob_t *pglob, sftp_session sftp);
|
||||
|
||||
573
src/list.h
573
src/list.h
@@ -1,573 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* I grub it from linux kernel source code and fix it for user space
|
||||
* program. Of course, this is a GPL licensed header file.
|
||||
*
|
||||
* Here is a recipe to cook list.h for user space program
|
||||
*
|
||||
* 1. copy list.h from linux/include/list.h
|
||||
* 2. remove
|
||||
* - #ifdef __KERNE__ and its #endif
|
||||
* - all #include line
|
||||
* - prefetch() and rcu related functions
|
||||
* 3. add macro offsetof() and container_of
|
||||
*
|
||||
* - kazutomo@mcs.anl.gov
|
||||
*/
|
||||
#ifndef _LINUX_LIST_H
|
||||
#define _LINUX_LIST_H
|
||||
|
||||
/**
|
||||
* @name from other kernel headers
|
||||
*/
|
||||
/*@{*/
|
||||
|
||||
/**
|
||||
* Get offset of a member
|
||||
*/
|
||||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
|
||||
/**
|
||||
* Casts a member of a structure out to the containing structure
|
||||
* @param ptr the pointer to the member.
|
||||
* @param type the type of the container struct this is embedded in.
|
||||
* @param member the name of the member within the struct.
|
||||
*
|
||||
*/
|
||||
#define container_of(ptr, type, member) ({ \
|
||||
const typeof( ((type *)0)->member ) *__mptr = (ptr); \
|
||||
(type *)( (char *)__mptr - offsetof(type,member) );})
|
||||
/*@}*/
|
||||
|
||||
|
||||
/*
|
||||
* These are non-NULL pointers that will result in page faults
|
||||
* under normal circumstances, used to verify that nobody uses
|
||||
* non-initialized list entries.
|
||||
*/
|
||||
#define LIST_POISON1 ((void *) 0x00100100)
|
||||
#define LIST_POISON2 ((void *) 0x00200200)
|
||||
|
||||
/**
|
||||
* Simple doubly linked list implementation.
|
||||
*
|
||||
* Some of the internal functions ("__xxx") are useful when
|
||||
* manipulating whole lists rather than single entries, as
|
||||
* sometimes we already know the next/prev entries and we can
|
||||
* generate better code by using them directly rather than
|
||||
* using the generic single-entry routines.
|
||||
*/
|
||||
struct list_head {
|
||||
struct list_head *next, *prev;
|
||||
};
|
||||
|
||||
#define LIST_HEAD_INIT(name) { &(name), &(name) }
|
||||
|
||||
#define LIST_HEAD(name) \
|
||||
struct list_head name = LIST_HEAD_INIT(name)
|
||||
|
||||
#define INIT_LIST_HEAD(ptr) do { \
|
||||
(ptr)->next = (ptr); (ptr)->prev = (ptr); \
|
||||
} while (0)
|
||||
|
||||
/*
|
||||
* Insert a new entry between two known consecutive entries.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_add(struct list_head *new,
|
||||
struct list_head *prev,
|
||||
struct list_head *next)
|
||||
{
|
||||
next->prev = new;
|
||||
new->next = next;
|
||||
new->prev = prev;
|
||||
prev->next = new;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it after
|
||||
*
|
||||
* Insert a new entry after the specified head.
|
||||
* This is good for implementing stacks.
|
||||
*/
|
||||
static inline void list_add(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head, head->next);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_add_tail - add a new entry
|
||||
* @new: new entry to be added
|
||||
* @head: list head to add it before
|
||||
*
|
||||
* Insert a new entry before the specified head.
|
||||
* This is useful for implementing queues.
|
||||
*/
|
||||
static inline void list_add_tail(struct list_head *new, struct list_head *head)
|
||||
{
|
||||
__list_add(new, head->prev, head);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Delete a list entry by making the prev/next entries
|
||||
* point to each other.
|
||||
*
|
||||
* This is only for internal list manipulation where we know
|
||||
* the prev/next entries already!
|
||||
*/
|
||||
static inline void __list_del(struct list_head * prev, struct list_head * next)
|
||||
{
|
||||
next->prev = prev;
|
||||
prev->next = next;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_del - deletes entry from list.
|
||||
* @entry: the element to delete from the list.
|
||||
* Note: list_empty on entry does not return true after this, the entry is
|
||||
* in an undefined state.
|
||||
*/
|
||||
static inline void list_del(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
entry->next = LIST_POISON1;
|
||||
entry->prev = LIST_POISON2;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* list_del_init - deletes entry from list and reinitialize it.
|
||||
* @entry: the element to delete from the list.
|
||||
*/
|
||||
static inline void list_del_init(struct list_head *entry)
|
||||
{
|
||||
__list_del(entry->prev, entry->next);
|
||||
INIT_LIST_HEAD(entry);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move - delete from one list and add as another's head
|
||||
* @list: the entry to move
|
||||
* @head: the head that will precede our entry
|
||||
*/
|
||||
static inline void list_move(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_move_tail - delete from one list and add as another's tail
|
||||
* @list: the entry to move
|
||||
* @head: the head that will follow our entry
|
||||
*/
|
||||
static inline void list_move_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
__list_del(list->prev, list->next);
|
||||
list_add_tail(list, head);
|
||||
}
|
||||
|
||||
/**
|
||||
* list_empty - tests whether a list is empty
|
||||
* @head: the list to test.
|
||||
*/
|
||||
static inline int list_empty(const struct list_head *head)
|
||||
{
|
||||
return head->next == head;
|
||||
}
|
||||
|
||||
static inline void __list_splice(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->next;
|
||||
|
||||
first->prev = head;
|
||||
head->next = first;
|
||||
|
||||
last->next = at;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice(list, head);
|
||||
}
|
||||
|
||||
static inline void __list_splice_tail(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
struct list_head *first = list->next;
|
||||
struct list_head *last = list->prev;
|
||||
struct list_head *at = head->prev;
|
||||
|
||||
first->prev = at;
|
||||
at->next = first;
|
||||
|
||||
last->next = head;
|
||||
at->prev = last;
|
||||
}
|
||||
|
||||
/**
|
||||
* list_splice_tail - join two lists
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*/
|
||||
static inline void list_splice_tail(struct list_head *list, struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list))
|
||||
__list_splice_tail(list, head);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list_splice_init - join two lists and reinitialise the emptied list.
|
||||
* @list: the new list to add.
|
||||
* @head: the place to add it in the first list.
|
||||
*
|
||||
* The list at @list is reinitialised
|
||||
*/
|
||||
static inline void list_splice_init(struct list_head *list,
|
||||
struct list_head *head)
|
||||
{
|
||||
if (!list_empty(list)) {
|
||||
__list_splice(list, head);
|
||||
INIT_LIST_HEAD(list);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* list_entry - get the struct for this entry
|
||||
* @ptr: the &struct list_head pointer.
|
||||
* @type: the type of the struct this is embedded in.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_entry(ptr, type, member) \
|
||||
container_of(ptr, type, member)
|
||||
|
||||
/**
|
||||
* list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
|
||||
#define list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* __list_for_each - iterate over a list
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*
|
||||
* This variant differs from list_for_each() in that it's the
|
||||
* simplest possible list iteration code, no prefetching is done.
|
||||
* Use this for code that knows the list to be very short (empty
|
||||
* or 1 entry) most of the time.
|
||||
*/
|
||||
#define __list_for_each(pos, head) \
|
||||
for (pos = (head)->next; pos != (head); pos = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_prev - iterate over a list backwards
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_prev(pos, head) \
|
||||
for (pos = (head)->prev; prefetch(pos->prev), pos != (head); \
|
||||
pos = pos->prev)
|
||||
|
||||
/**
|
||||
* list_for_each_safe - iterate over a list safe against removal of list entry
|
||||
* @pos: the &struct list_head to use as a loop counter.
|
||||
* @n: another &struct list_head to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
*/
|
||||
#define list_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->next, n = pos->next; pos != (head); \
|
||||
pos = n, n = pos->next)
|
||||
|
||||
/**
|
||||
* list_for_each_entry - iterate over list of given type
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry(pos, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_reverse - iterate backwards over list of given type.
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_reverse(pos, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.prev, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_prepare_entry - prepare a pos entry for use as a start point in
|
||||
* list_for_each_entry_continue
|
||||
* @pos: the type * to use as a start point
|
||||
* @head: the head of the list
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_prepare_entry(pos, head, member) \
|
||||
((pos) ? : list_entry(head, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_continue - iterate over list of given type
|
||||
* continuing after existing point
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_continue(pos, head, member) \
|
||||
for (pos = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = list_entry(pos->member.next, typeof(*pos), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_continue - iterate over list of given type
|
||||
* continuing after existing point safe against removal of list entry
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe_continue(pos, n, head, member) \
|
||||
for (pos = list_entry(pos->member.next, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.next, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.next, typeof(*n), member))
|
||||
|
||||
/**
|
||||
* list_for_each_entry_safe_reverse - iterate backwards over list of given type safe against
|
||||
* removal of list entry
|
||||
* @pos: the type * to use as a loop counter.
|
||||
* @n: another type * to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the list_struct within the struct.
|
||||
*/
|
||||
#define list_for_each_entry_safe_reverse(pos, n, head, member) \
|
||||
for (pos = list_entry((head)->prev, typeof(*pos), member), \
|
||||
n = list_entry(pos->member.prev, typeof(*pos), member); \
|
||||
&pos->member != (head); \
|
||||
pos = n, n = list_entry(n->member.prev, typeof(*n), member))
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Double linked lists with a single pointer list head.
|
||||
* Mostly useful for hash tables where the two pointer list head is
|
||||
* too wasteful.
|
||||
* You lose the ability to access the tail in O(1).
|
||||
*/
|
||||
|
||||
struct hlist_head {
|
||||
struct hlist_node *first;
|
||||
};
|
||||
|
||||
struct hlist_node {
|
||||
struct hlist_node *next, **pprev;
|
||||
};
|
||||
|
||||
#define HLIST_HEAD_INIT { .first = NULL }
|
||||
#define HLIST_HEAD(name) struct hlist_head name = { .first = NULL }
|
||||
#define INIT_HLIST_HEAD(ptr) ((ptr)->first = NULL)
|
||||
#define INIT_HLIST_NODE(ptr) ((ptr)->next = NULL, (ptr)->pprev = NULL)
|
||||
|
||||
static inline int hlist_unhashed(const struct hlist_node *h)
|
||||
{
|
||||
return !h->pprev;
|
||||
}
|
||||
|
||||
static inline int hlist_empty(const struct hlist_head *h)
|
||||
{
|
||||
return !h->first;
|
||||
}
|
||||
|
||||
static inline void __hlist_del(struct hlist_node *n)
|
||||
{
|
||||
struct hlist_node *next = n->next;
|
||||
struct hlist_node **pprev = n->pprev;
|
||||
*pprev = next;
|
||||
if (next)
|
||||
next->pprev = pprev;
|
||||
}
|
||||
|
||||
static inline void hlist_del(struct hlist_node *n)
|
||||
{
|
||||
__hlist_del(n);
|
||||
n->next = LIST_POISON1;
|
||||
n->pprev = LIST_POISON2;
|
||||
}
|
||||
|
||||
|
||||
static inline void hlist_del_init(struct hlist_node *n)
|
||||
{
|
||||
if (n->pprev) {
|
||||
__hlist_del(n);
|
||||
INIT_HLIST_NODE(n);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void hlist_add_head(struct hlist_node *n, struct hlist_head *h)
|
||||
{
|
||||
struct hlist_node *first = h->first;
|
||||
n->next = first;
|
||||
if (first)
|
||||
first->pprev = &n->next;
|
||||
h->first = n;
|
||||
n->pprev = &h->first;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* next must be != NULL */
|
||||
static inline void hlist_add_before(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
n->pprev = next->pprev;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
*(n->pprev) = n;
|
||||
}
|
||||
|
||||
static inline void hlist_add_after(struct hlist_node *n,
|
||||
struct hlist_node *next)
|
||||
{
|
||||
next->next = n->next;
|
||||
n->next = next;
|
||||
next->pprev = &n->next;
|
||||
|
||||
if(next->next)
|
||||
next->next->pprev = &next->next;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#define hlist_entry(ptr, type, member) container_of(ptr,type,member)
|
||||
|
||||
#define hlist_for_each(pos, head) \
|
||||
for (pos = (head)->first; pos && ({ prefetch(pos->next); 1; }); \
|
||||
pos = pos->next)
|
||||
|
||||
#define hlist_for_each_safe(pos, n, head) \
|
||||
for (pos = (head)->first; pos && ({ n = pos->next; 1; }); \
|
||||
pos = n)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry - iterate over list of given type
|
||||
* @tpos: the type * to use as a loop counter.
|
||||
* @pos: the &struct hlist_node to use as a loop counter.
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry(tpos, pos, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_continue - iterate over a hlist continuing after existing point
|
||||
* @tpos: the type * to use as a loop counter.
|
||||
* @pos: the &struct hlist_node to use as a loop counter.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_continue(tpos, pos, member) \
|
||||
for (pos = (pos)->next; \
|
||||
pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_from - iterate over a hlist continuing from existing point
|
||||
* @tpos: the type * to use as a loop counter.
|
||||
* @pos: the &struct hlist_node to use as a loop counter.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_from(tpos, pos, member) \
|
||||
for (; pos && ({ prefetch(pos->next); 1;}) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = pos->next)
|
||||
|
||||
/**
|
||||
* hlist_for_each_entry_safe - iterate over list of given type safe against removal of list entry
|
||||
* @tpos: the type * to use as a loop counter.
|
||||
* @pos: the &struct hlist_node to use as a loop counter.
|
||||
* @n: another &struct hlist_node to use as temporary storage
|
||||
* @head: the head for your list.
|
||||
* @member: the name of the hlist_node within the struct.
|
||||
*/
|
||||
#define hlist_for_each_entry_safe(tpos, pos, n, head, member) \
|
||||
for (pos = (head)->first; \
|
||||
pos && ({ n = pos->next; 1; }) && \
|
||||
({ tpos = hlist_entry(pos, typeof(*tpos), member); 1;}); \
|
||||
pos = n)
|
||||
|
||||
|
||||
/**
|
||||
* list_count - return length of list
|
||||
* @head the head for your list.
|
||||
*/
|
||||
static inline int list_count(struct list_head *head)
|
||||
{
|
||||
int n = 0;
|
||||
struct list_head *p;
|
||||
|
||||
list_for_each(p, head) n++;
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* list_free_f - free items in a list with a function
|
||||
* @head the heaf for your list.
|
||||
* @f function that releases an item in the list.
|
||||
*/
|
||||
static inline void list_free_f(struct list_head *head, void (*f)(struct list_head *))
|
||||
{
|
||||
struct list_head *p, *n;
|
||||
|
||||
list_for_each_safe(p, n, head) {
|
||||
list_del(p);
|
||||
f(p);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
590
src/main.c
590
src/main.c
@@ -2,6 +2,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
@@ -9,21 +10,28 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <poll.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <mscp.h>
|
||||
#include <mscp_version.h>
|
||||
#include <util.h>
|
||||
#include <minmax.h>
|
||||
#include <strerrno.h>
|
||||
#include <print.h>
|
||||
|
||||
#include <config.h>
|
||||
|
||||
void usage(bool print_help) {
|
||||
printf("mscp " MSCP_BUILD_VERSION ": copy files over multiple ssh connections\n"
|
||||
void usage(bool print_help)
|
||||
{
|
||||
printf("mscp " MSCP_BUILD_VERSION ": copy files over multiple SSH connections\n"
|
||||
"\n"
|
||||
"Usage: mscp [vqDHdNh] [-n nr_conns] [-m coremask]\n"
|
||||
" [-u max_startups] [-I interval]\n"
|
||||
" [-s min_chunk_sz] [-S max_chunk_sz] [-a nr_ahead] [-b buf_sz]\n"
|
||||
" [-l login_name] [-p port] [-F ssh_config] [-i identity_file]\n"
|
||||
" [-c cipher_spec] [-M hmac_spec] [-C compress] [-g congestion]\n"
|
||||
"Usage: mscp [-46vqDpdNh] [-n nr_conns] [-m coremask] [-u max_startups]\n"
|
||||
" [-I interval] [-W checkpoint] [-R checkpoint]\n"
|
||||
" [-s min_chunk_sz] [-S max_chunk_sz] [-a nr_ahead]\n"
|
||||
" [-b buf_sz] [-L limit_bitrate]\n"
|
||||
" [-l login_name] [-P port] [-F ssh_config] [-o ssh_option]\n"
|
||||
" [-i identity_file] [-J destination] [-c cipher_spec] [-M hmac_spec]\n"
|
||||
" [-C compress] [-g congestion]\n"
|
||||
" source ... target\n"
|
||||
"\n");
|
||||
|
||||
@@ -33,34 +41,61 @@ void usage(bool print_help) {
|
||||
printf(" -n NR_CONNECTIONS number of connections "
|
||||
"(default: floor(log(cores)*2)+1)\n"
|
||||
" -m COREMASK hex value to specify cores where threads pinned\n"
|
||||
" -u MAX_STARTUPS number of concurrent SSH connection attempts "
|
||||
" -u MAX_STARTUPS number of concurrent unauthed SSH attempts "
|
||||
"(default: 8)\n"
|
||||
" -I INTERVAL interval between SSH connection attempts (default: 0)\n"
|
||||
" -W CHECKPOINT write states to the checkpoint if transfer fails\n"
|
||||
" -R CHECKPOINT resume transferring from the checkpoint\n"
|
||||
"\n"
|
||||
" -s MIN_CHUNK_SIZE min chunk size (default: 64MB)\n"
|
||||
" -S MAX_CHUNK_SIZE max chunk size (default: filesize/nr_conn)\n"
|
||||
" -s MIN_CHUNK_SIZE min chunk size (default: 16M bytes)\n"
|
||||
" -S MAX_CHUNK_SIZE max chunk size (default: filesize/nr_conn/4)\n"
|
||||
" -a NR_AHEAD number of inflight SFTP commands (default: 32)\n"
|
||||
" -b BUF_SZ buffer size for i/o and transfer\n"
|
||||
" -L LIMIT_BITRATE Limit the bitrate, n[KMG] (default: 0, no limit)\n"
|
||||
"\n"
|
||||
" -4 use IPv4\n"
|
||||
" -6 use IPv6\n"
|
||||
" -v increment verbose output level\n"
|
||||
" -q disable output\n"
|
||||
" -D dry run. check copy destinations with -vvv\n"
|
||||
" -r no effect\n"
|
||||
"\n"
|
||||
" -l LOGIN_NAME login name\n"
|
||||
" -p/-P PORT port number\n"
|
||||
" -F CONFIG path to user ssh config (default ~/.ssh/config)\n"
|
||||
" -P PORT port number\n"
|
||||
" -F SSH_CONFIG path to user ssh config (default ~/.ssh/config)\n"
|
||||
" -o SSH_OPTION ssh_config option\n"
|
||||
" -i IDENTITY identity file for public key authentication\n"
|
||||
" -J DESTINATION ProxyJump destination\n"
|
||||
" -c CIPHER cipher spec\n"
|
||||
" -M HMAC hmac spec\n"
|
||||
" -C COMPRESS enable compression: "
|
||||
"yes, no, zlib, zlib@openssh.com\n"
|
||||
" -g CONGESTION specify TCP congestion control algorithm\n"
|
||||
" -H disable hostkey check\n"
|
||||
" -p preserve timestamps of files\n"
|
||||
" -d increment ssh debug output level\n"
|
||||
" -N enable Nagle's algorithm (default disabled)\n"
|
||||
" -h print this help\n"
|
||||
"\n");
|
||||
|
||||
const char **ciphers = mscp_ssh_ciphers();
|
||||
const char **hmacs = mscp_ssh_hmacs();
|
||||
int n;
|
||||
|
||||
printf("Available ciphers: ");
|
||||
for (n = 0; ciphers[n] != NULL; n++) {
|
||||
printf("%s", ciphers[n]);
|
||||
if (ciphers[n + 1])
|
||||
printf(", ");
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("Available hmacs: ");
|
||||
for (n = 0; hmacs[n] != NULL; n++) {
|
||||
printf("%s", hmacs[n]);
|
||||
if (hmacs[n + 1])
|
||||
printf(", ");
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
char *strip_brackets(char *s)
|
||||
@@ -78,7 +113,7 @@ char *split_user_host_path(const char *s, char **userp, char **hostp, char **pat
|
||||
bool inbrackets = false;
|
||||
|
||||
if (!(tmp = strdup(s))) {
|
||||
fprintf(stderr, "stdrup: %s\n", strerror(errno));
|
||||
pr_err("stdrup: %s", strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -173,17 +208,19 @@ struct target *validate_targets(char **arg, int len)
|
||||
int n;
|
||||
|
||||
if ((t = calloc(len, sizeof(struct target))) == NULL) {
|
||||
fprintf(stderr, "calloc: %s\n", strerror(errno));
|
||||
pr_err("calloc: %s", strerrno());
|
||||
return NULL;
|
||||
}
|
||||
memset(t, 0, len * sizeof(struct target));
|
||||
|
||||
/* split remote:path into remote and path */
|
||||
for (n = 0; n < len; n++) {
|
||||
t[n].copy = split_user_host_path(arg[n], &t[n].user,
|
||||
&t[n].host, &t[n].path);
|
||||
if (!t[n].copy)
|
||||
t[n].copy =
|
||||
split_user_host_path(arg[n], &t[n].user, &t[n].host, &t[n].path);
|
||||
if (!t[n].copy) {
|
||||
pr_err("failed to parse '%s'", arg[n]);
|
||||
goto free_target_out;
|
||||
}
|
||||
}
|
||||
|
||||
/* check all user@host are identical. t[len - 1] is destination,
|
||||
@@ -197,23 +234,24 @@ struct target *validate_targets(char **arg, int len)
|
||||
|
||||
/* check inconsistent remote position in args */
|
||||
if (t[0].host == NULL && t[len - 1].host == NULL) {
|
||||
fprintf(stderr, "no remote host given\n");
|
||||
pr_err("no remote host given");
|
||||
goto free_split_out;
|
||||
}
|
||||
|
||||
if (t[0].host != NULL && t[len - 1].host != NULL) {
|
||||
fprintf(stderr, "no local path given\n");
|
||||
pr_err("no local path given");
|
||||
goto free_split_out;
|
||||
}
|
||||
|
||||
return t;
|
||||
|
||||
invalid_remotes:
|
||||
fprintf(stderr, "invalid remote host notation\n");
|
||||
pr_err("invalid remote host notation");
|
||||
|
||||
free_split_out:
|
||||
for (n = 0; n < len; n++)
|
||||
if (t[n].copy) free(t[n].copy);
|
||||
if (t[n].copy)
|
||||
free(t[n].copy);
|
||||
|
||||
free_target_out:
|
||||
free(t);
|
||||
@@ -221,11 +259,12 @@ free_target_out:
|
||||
}
|
||||
|
||||
struct mscp *m = NULL;
|
||||
int msg_fd = 0;
|
||||
pthread_t tid_stat = 0;
|
||||
bool interrupted = false;
|
||||
|
||||
void sigint_handler(int sig)
|
||||
{
|
||||
interrupted = true;
|
||||
mscp_stop(m);
|
||||
}
|
||||
|
||||
@@ -233,13 +272,64 @@ void *print_stat_thread(void *arg);
|
||||
|
||||
void print_cli(const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
va_list va;
|
||||
va_start(va, fmt);
|
||||
vfprintf(stdout, fmt, va);
|
||||
fflush(stdout);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
void print_stat(bool final);
|
||||
|
||||
long atol_with_unit(char *value, bool i)
|
||||
{
|
||||
/* value must be "\d+[kKmMgG]?" */
|
||||
|
||||
char *u = value + (strlen(optarg) - 1);
|
||||
long k = i ? 1024 : 1000;
|
||||
long factor = 1;
|
||||
long v;
|
||||
|
||||
switch (*u) {
|
||||
case 'k':
|
||||
case 'K':
|
||||
factor = k;
|
||||
*u = '\0';
|
||||
break;
|
||||
case 'm':
|
||||
case 'M':
|
||||
factor = k * k;
|
||||
*u = '\0';
|
||||
break;
|
||||
case 'g':
|
||||
case 'G':
|
||||
factor = k * k * k;
|
||||
*u = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
v = atol(value);
|
||||
return v * factor;
|
||||
}
|
||||
|
||||
int to_dev_null(int fd)
|
||||
{
|
||||
int nfd = open("/dev/null", O_WRONLY);
|
||||
if (nfd < 0) {
|
||||
pr_err("open /dev/null: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (dup2(nfd, fd) < 0) {
|
||||
pr_err("dup2: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
close(nfd);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
struct mscp_ssh_opts s;
|
||||
@@ -248,26 +338,26 @@ int main(int argc, char **argv)
|
||||
int pipe_fd[2];
|
||||
int ch, n, i, ret;
|
||||
int direction = 0;
|
||||
char *remote;
|
||||
bool dryrun = false;
|
||||
char *remote = NULL, *checkpoint_save = NULL, *checkpoint_load = NULL;
|
||||
bool quiet = false, dryrun = false, resume = false;
|
||||
int nr_options = 0;
|
||||
|
||||
memset(&s, 0, sizeof(s));
|
||||
memset(&o, 0, sizeof(o));
|
||||
o.severity = MSCP_SEVERITY_WARN;
|
||||
|
||||
while ((ch = getopt(argc, argv,
|
||||
"n:m:u:I:s:S:a:b:vqDrl:P:p:i:F:c:M:C:g:HdNh")) != -1) {
|
||||
#define mscpopts "n:m:u:I:W:R:s:S:a:b:L:46vqDrl:P:F:o:i:J:c:M:C:g:pdNh"
|
||||
while ((ch = getopt(argc, argv, mscpopts)) != -1) {
|
||||
switch (ch) {
|
||||
case 'n':
|
||||
o.nr_threads = atoi(optarg);
|
||||
if (o.nr_threads < 1) {
|
||||
fprintf(stderr, "invalid number of connections: %s\n",
|
||||
optarg);
|
||||
pr_err("invalid number of connections: %s", optarg);
|
||||
return 1;
|
||||
}
|
||||
break;
|
||||
case 'm':
|
||||
strncpy(o.coremask, optarg, sizeof(o.coremask));
|
||||
o.coremask = optarg;
|
||||
break;
|
||||
case 'u':
|
||||
o.max_startups = atoi(optarg);
|
||||
@@ -275,23 +365,39 @@ int main(int argc, char **argv)
|
||||
case 'I':
|
||||
o.interval = atoi(optarg);
|
||||
break;
|
||||
case 'W':
|
||||
checkpoint_save = optarg;
|
||||
break;
|
||||
case 'R':
|
||||
checkpoint_load = optarg;
|
||||
resume = true;
|
||||
break;
|
||||
case 's':
|
||||
o.min_chunk_sz = atoi(optarg);
|
||||
o.min_chunk_sz = atol_with_unit(optarg, true);
|
||||
break;
|
||||
case 'S':
|
||||
o.max_chunk_sz = atoi(optarg);
|
||||
o.max_chunk_sz = atol_with_unit(optarg, true);
|
||||
break;
|
||||
case 'a':
|
||||
o.nr_ahead = atoi(optarg);
|
||||
break;
|
||||
case 'b':
|
||||
o.buf_sz = atoi(optarg);
|
||||
o.buf_sz = atol_with_unit(optarg, true);
|
||||
break;
|
||||
case 'L':
|
||||
o.bitrate = atol_with_unit(optarg, false);
|
||||
break;
|
||||
case '4':
|
||||
s.ai_family = AF_INET;
|
||||
break;
|
||||
case '6':
|
||||
s.ai_family = AF_INET6;
|
||||
break;
|
||||
case 'v':
|
||||
o.severity++;
|
||||
break;
|
||||
case 'q':
|
||||
o.severity = MSCP_SEVERITY_NONE;
|
||||
quiet = true;
|
||||
break;
|
||||
case 'D':
|
||||
dryrun = true;
|
||||
@@ -300,61 +406,44 @@ int main(int argc, char **argv)
|
||||
/* for compatibility with scp */
|
||||
break;
|
||||
case 'l':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_LOGIN_NAME - 1) {
|
||||
fprintf(stderr, "long login name: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.login_name, optarg, MSCP_SSH_MAX_LOGIN_NAME - 1);
|
||||
s.login_name = optarg;
|
||||
break;
|
||||
case 'P':
|
||||
/* fallthough for compatibility with scp */
|
||||
case 'p':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_PORT_STR - 1) {
|
||||
fprintf(stderr, "long port string: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.port, optarg, MSCP_SSH_MAX_PORT_STR);
|
||||
s.port = optarg;
|
||||
break;
|
||||
case 'F':
|
||||
strncpy(s.config, optarg, PATH_MAX - 1);
|
||||
s.config = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
nr_options++;
|
||||
s.options = realloc(s.options, sizeof(char *) * (nr_options + 1));
|
||||
if (!s.options) {
|
||||
pr_err("realloc: %s", strerrno());
|
||||
return 1;
|
||||
}
|
||||
s.options[nr_options - 1] = optarg;
|
||||
s.options[nr_options] = NULL;
|
||||
break;
|
||||
case 'i':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_IDENTITY_PATH - 1) {
|
||||
fprintf(stderr, "long identity path: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.identity, optarg, MSCP_SSH_MAX_IDENTITY_PATH);
|
||||
s.identity = optarg;
|
||||
break;
|
||||
case 'J':
|
||||
s.proxyjump = optarg;
|
||||
break;
|
||||
case 'c':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_CIPHER_STR - 1) {
|
||||
fprintf(stderr, "long cipher string: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.cipher, optarg, MSCP_SSH_MAX_CIPHER_STR);
|
||||
s.cipher = optarg;
|
||||
break;
|
||||
case 'M':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_HMAC_STR - 1) {
|
||||
fprintf(stderr, "long hmac string: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.hmac, optarg, MSCP_SSH_MAX_HMAC_STR);
|
||||
s.hmac = optarg;
|
||||
break;
|
||||
case 'C':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_COMP_STR - 1) {
|
||||
fprintf(stderr, "long compress string: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.compress, optarg, MSCP_SSH_MAX_COMP_STR);
|
||||
s.compress = optarg;
|
||||
break;
|
||||
case 'g':
|
||||
if (strlen(optarg) > MSCP_SSH_MAX_CCALGO_STR - 1) {
|
||||
fprintf(stderr, "long ccalgo string: %s\n", optarg);
|
||||
return -1;
|
||||
}
|
||||
strncpy(s.ccalgo, optarg, MSCP_SSH_MAX_CCALGO_STR);
|
||||
s.ccalgo = optarg;
|
||||
break;
|
||||
case 'H':
|
||||
s.no_hostkey_check = true;
|
||||
case 'p':
|
||||
o.preserve_ts = true;
|
||||
break;
|
||||
case 'd':
|
||||
s.debug_level++;
|
||||
@@ -371,65 +460,99 @@ int main(int argc, char **argv)
|
||||
}
|
||||
}
|
||||
|
||||
if (argc - optind < 2) {
|
||||
/* mscp needs at lease 2 (src and target) argument */
|
||||
usage(false);
|
||||
return 1;
|
||||
}
|
||||
i = argc - optind;
|
||||
if (quiet)
|
||||
to_dev_null(STDOUT_FILENO);
|
||||
|
||||
if ((t = validate_targets(argv + optind, i)) == NULL)
|
||||
s.password = getenv(ENV_SSH_AUTH_PASSWORD);
|
||||
s.passphrase = getenv(ENV_SSH_AUTH_PASSPHRASE);
|
||||
|
||||
if ((m = mscp_init(&o, &s)) == NULL) {
|
||||
pr_err("mscp_init: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (t[0].host) {
|
||||
/* copy remote to local */
|
||||
direction = MSCP_DIRECTION_R2L;
|
||||
remote = t[0].host;
|
||||
if (t[0].user != NULL && s.login_name[0] == '\0')
|
||||
strncpy(s.login_name, t[0].user, MSCP_SSH_MAX_LOGIN_NAME - 1);
|
||||
if (!resume) {
|
||||
/* normal transfer (not resume) */
|
||||
if (argc - optind < 2) {
|
||||
/* mscp needs at lease 2 (src and target) argument */
|
||||
usage(false);
|
||||
return 1;
|
||||
}
|
||||
i = argc - optind;
|
||||
|
||||
if ((t = validate_targets(argv + optind, i)) == NULL)
|
||||
return -1;
|
||||
|
||||
if (t[0].host) {
|
||||
/* copy remote to local */
|
||||
direction = MSCP_DIRECTION_R2L;
|
||||
remote = t[0].host;
|
||||
s.login_name = s.login_name ? s.login_name : t[0].user;
|
||||
} else {
|
||||
/* copy local to remote */
|
||||
direction = MSCP_DIRECTION_L2R;
|
||||
remote = t[i - 1].host;
|
||||
s.login_name = s.login_name ? s.login_name : t[i - 1].user;
|
||||
}
|
||||
|
||||
if (mscp_set_remote(m, remote, direction) < 0) {
|
||||
pr_err("mscp_set_remote: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mscp_connect(m) < 0) {
|
||||
pr_err("mscp_connect: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (n = 0; n < i - 1; n++) {
|
||||
if (mscp_add_src_path(m, t[n].path) < 0) {
|
||||
pr_err("mscp_add_src_path: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mscp_set_dst_path(m, t[i - 1].path) < 0) {
|
||||
pr_err("mscp_set_dst_path: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* start to scan source files and resolve their destination paths */
|
||||
if (mscp_scan(m) < 0) {
|
||||
pr_err("mscp_scan: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
} else {
|
||||
/* copy local to remote */
|
||||
direction = MSCP_DIRECTION_L2R;
|
||||
remote = t[i - 1].host;
|
||||
if (t[i - 1].user != NULL && s.login_name[0] == '\0')
|
||||
strncpy(s.login_name, t[i - 1].user,
|
||||
MSCP_SSH_MAX_LOGIN_NAME - 1);
|
||||
}
|
||||
|
||||
if (!dryrun) {
|
||||
if (pipe(pipe_fd) < 0) {
|
||||
fprintf(stderr, "pipe: %s\n", strerror(errno));
|
||||
/* resume a transfer from the specified checkpoint */
|
||||
char r[512];
|
||||
int d;
|
||||
if (mscp_checkpoint_get_remote(checkpoint_load, r, sizeof(r), &d) < 0) {
|
||||
pr_err("mscp_checkpoint_get_remote: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
msg_fd = pipe_fd[0];
|
||||
o.msg_fd = pipe_fd[1];
|
||||
}
|
||||
|
||||
if ((m = mscp_init(remote, direction, &o, &s)) == NULL) {
|
||||
fprintf(stderr, "mscp_init: %s\n", mscp_get_error());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mscp_connect(m) < 0) {
|
||||
fprintf(stderr, "mscp_connect: %s\n", mscp_get_error());
|
||||
return -1;
|
||||
}
|
||||
|
||||
for (n = 0; n < i - 1; n++) {
|
||||
if (mscp_add_src_path(m, t[n].path) < 0) {
|
||||
fprintf(stderr, "mscp_add_src_path: %s\n", mscp_get_error());
|
||||
if (mscp_set_remote(m, r, d) < 0) {
|
||||
pr_err("mscp_set_remote: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (mscp_set_dst_path(m, t[i - 1].path) < 0) {
|
||||
fprintf(stderr, "mscp_set_dst_path: %s\n", mscp_get_error());
|
||||
return -1;
|
||||
}
|
||||
/* load paths and chunks to be transferred from checkpoint */
|
||||
if (mscp_checkpoint_load(m, checkpoint_load) < 0) {
|
||||
pr_err("mscp_checkpoint_load: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (mscp_scan(m) < 0) {
|
||||
fprintf(stderr, "mscp_scan: %s\n", mscp_get_error());
|
||||
return -1;
|
||||
if (dryrun)
|
||||
goto out;
|
||||
|
||||
/* create the first ssh connection to get password or
|
||||
* passphrase. The sftp session over it will be not
|
||||
* used for resume transfer in actuality. ToDo:
|
||||
* connectin managemnet should be improved. */
|
||||
if (mscp_connect(m) < 0) {
|
||||
pr_err("mscp_connect: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (dryrun) {
|
||||
@@ -438,79 +561,87 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
if (pthread_create(&tid_stat, NULL, print_stat_thread, NULL) < 0) {
|
||||
fprintf(stderr, "pthread_create: %s\n", strerror(errno));
|
||||
pr_err("pthread_create: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (signal(SIGINT, sigint_handler) == SIG_ERR) {
|
||||
fprintf(stderr, "signal: %s\n", strerror(errno));
|
||||
pr_err("signal: %s", strerror(errno));
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = mscp_start(m);
|
||||
if (ret < 0)
|
||||
fprintf(stderr, "mscp_start: %s\n", mscp_get_error());
|
||||
pr_err("mscp_start: %s", priv_get_err());
|
||||
|
||||
ret = mscp_join(m);
|
||||
if (ret != 0)
|
||||
fprintf(stderr, "mscp_join: %s\n", mscp_get_error());
|
||||
|
||||
pthread_cancel(tid_stat);
|
||||
pthread_join(tid_stat, NULL);
|
||||
|
||||
print_stat(true);
|
||||
print_cli("\n"); /* final output */
|
||||
out:
|
||||
if (interrupted)
|
||||
ret = 1;
|
||||
|
||||
if ((dryrun || ret != 0) && checkpoint_save) {
|
||||
print_cli("save checkpoint to %s\n", checkpoint_save);
|
||||
if (mscp_checkpoint_save(m, checkpoint_save) < 0) {
|
||||
pr_err("mscp_checkpoint_save: %s", priv_get_err());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
mscp_cleanup(m);
|
||||
mscp_free(m);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* progress bar-related functions */
|
||||
|
||||
double calculate_timedelta(struct timeval *b, struct timeval *a)
|
||||
{
|
||||
double sec, usec;
|
||||
double sec, usec;
|
||||
|
||||
if (a->tv_usec < b->tv_usec) {
|
||||
a->tv_usec += 1000000;
|
||||
a->tv_sec--;
|
||||
}
|
||||
if (a->tv_usec < b->tv_usec) {
|
||||
a->tv_usec += 1000000;
|
||||
a->tv_sec--;
|
||||
}
|
||||
|
||||
sec = a->tv_sec - b->tv_sec;
|
||||
usec = a->tv_usec - b->tv_usec;
|
||||
sec += usec / 1000000;
|
||||
sec = a->tv_sec - b->tv_sec;
|
||||
usec = a->tv_usec - b->tv_usec;
|
||||
sec += usec / 1000000;
|
||||
|
||||
return sec;
|
||||
return sec;
|
||||
}
|
||||
|
||||
|
||||
double calculate_bps(size_t diff, struct timeval *b, struct timeval *a)
|
||||
{
|
||||
return (double)diff / calculate_timedelta(b, a);
|
||||
return (double)diff / calculate_timedelta(b, a);
|
||||
}
|
||||
|
||||
|
||||
char *calculate_eta(size_t remain, size_t diff, struct timeval *b, struct timeval *a,
|
||||
bool final)
|
||||
{
|
||||
static char buf[16];
|
||||
static char buf[16];
|
||||
|
||||
#define bps_window_size 16
|
||||
static double bps_window[bps_window_size];
|
||||
static size_t sum, idx, count;
|
||||
double elapsed = calculate_timedelta(b, a);
|
||||
double elapsed = calculate_timedelta(b, a);
|
||||
double bps = diff / elapsed;
|
||||
double avg, eta;
|
||||
|
||||
/* early return when diff == 0 (stalled) or final output */
|
||||
if (diff == 0) {
|
||||
snprintf(buf, sizeof(buf), "--:-- ETA");
|
||||
if (diff == 0) {
|
||||
snprintf(buf, sizeof(buf), "--:-- ETA");
|
||||
return buf;
|
||||
}
|
||||
if (final) {
|
||||
snprintf(buf, sizeof(buf), "%02d:%02d ",
|
||||
(int)(floor(elapsed / 60)), (int)round(elapsed) % 60);
|
||||
snprintf(buf, sizeof(buf), "%02d:%02d ", (int)(floor(elapsed / 60)),
|
||||
(int)round(elapsed) % 60);
|
||||
return buf;
|
||||
}
|
||||
|
||||
@@ -524,156 +655,131 @@ char *calculate_eta(size_t remain, size_t diff, struct timeval *b, struct timeva
|
||||
/* calcuate ETA from avg of recent bps values */
|
||||
avg = sum / min(count, bps_window_size);
|
||||
eta = remain / avg;
|
||||
snprintf(buf, sizeof(buf), "%02d:%02d ETA",
|
||||
(int)floor(eta / 60), (int)round(eta) % 60);
|
||||
snprintf(buf, sizeof(buf), "%02d:%02d ETA", (int)floor(eta / 60),
|
||||
(int)round(eta) % 60);
|
||||
|
||||
return buf;
|
||||
return buf;
|
||||
}
|
||||
|
||||
void print_progress_bar(double percent, char *suffix)
|
||||
{
|
||||
int n, thresh, bar_width;
|
||||
struct winsize ws;
|
||||
char buf[128];
|
||||
int n, thresh, bar_width;
|
||||
struct winsize ws;
|
||||
char buf[128];
|
||||
|
||||
/*
|
||||
/*
|
||||
* [=======> ] XX% SUFFIX
|
||||
*/
|
||||
|
||||
buf[0] = '\0';
|
||||
buf[0] = '\0';
|
||||
|
||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
|
||||
return; /* XXX */
|
||||
bar_width = min(sizeof(buf), ws.ws_col) - strlen(suffix) - 7;
|
||||
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0)
|
||||
return; /* XXX */
|
||||
bar_width = min(sizeof(buf), ws.ws_col) - strlen(suffix) - 7;
|
||||
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (bar_width > 8) {
|
||||
thresh = floor(bar_width * (percent / 100)) - 1;
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (bar_width > 8) {
|
||||
thresh = floor(bar_width * (percent / 100)) - 1;
|
||||
|
||||
for (n = 1; n < bar_width - 1; n++) {
|
||||
if (n <= thresh)
|
||||
buf[n] = '=';
|
||||
else
|
||||
buf[n] = ' ';
|
||||
}
|
||||
buf[thresh] = '>';
|
||||
buf[0] = '[';
|
||||
buf[bar_width - 1] = ']';
|
||||
snprintf(buf + bar_width, sizeof(buf) - bar_width,
|
||||
" %3d%% ", (int)floor(percent));
|
||||
}
|
||||
for (n = 1; n < bar_width - 1; n++) {
|
||||
if (n <= thresh)
|
||||
buf[n] = '=';
|
||||
else
|
||||
buf[n] = ' ';
|
||||
}
|
||||
buf[thresh] = '>';
|
||||
buf[0] = '[';
|
||||
buf[bar_width - 1] = ']';
|
||||
snprintf(buf + bar_width, sizeof(buf) - bar_width, " %3d%% ",
|
||||
(int)floor(percent));
|
||||
}
|
||||
|
||||
print_cli("\r\033[K" "%s%s", buf, suffix);
|
||||
print_cli("\r\033[K"
|
||||
"%s%s",
|
||||
buf, suffix);
|
||||
}
|
||||
|
||||
void print_progress(struct timeval *b, struct timeval *a,
|
||||
size_t total, size_t last, size_t done, bool final)
|
||||
void print_progress(struct timeval *b, struct timeval *a, size_t total, size_t last,
|
||||
size_t done, bool final)
|
||||
{
|
||||
char *bps_units[] = { "B/s ", "KB/s", "MB/s", "GB/s" };
|
||||
char *byte_units[] = { "B ", "KB", "MB", "GB", "TB", "PB" };
|
||||
char suffix[128];
|
||||
int bps_u, byte_tu, byte_du;
|
||||
double total_round, done_round;
|
||||
int percent;
|
||||
double bps;
|
||||
char *bps_units[] = { "B/s ", "KB/s", "MB/s", "GB/s" };
|
||||
char *byte_units[] = { "B ", "KB", "MB", "GB", "TB", "PB" };
|
||||
char suffix[128];
|
||||
int bps_u, byte_tu, byte_du;
|
||||
double total_round, done_round;
|
||||
int percent;
|
||||
double bps;
|
||||
|
||||
#define array_size(a) (sizeof(a) / sizeof(a[0]))
|
||||
|
||||
if (total <= 0) {
|
||||
print_cli("\r\033[K" "total 0 byte transferred");
|
||||
return; /* copy 0-byte file(s) */
|
||||
}
|
||||
if (total <= 0) {
|
||||
print_cli("\r\033[K"
|
||||
"total 0 byte transferred");
|
||||
return; /* copy 0-byte file(s) */
|
||||
}
|
||||
|
||||
total_round = total;
|
||||
for (byte_tu = 0; total_round > 1000 && byte_tu < array_size(byte_units) - 1;
|
||||
byte_tu++)
|
||||
total_round /= 1024;
|
||||
total_round = total;
|
||||
for (byte_tu = 0; total_round > 1000 && byte_tu < array_size(byte_units) - 1;
|
||||
byte_tu++)
|
||||
total_round /= 1024;
|
||||
|
||||
bps = calculate_bps(done - last, b, a);
|
||||
for (bps_u = 0; bps > 1000 && bps_u < array_size(bps_units); bps_u++)
|
||||
bps /= 1000;
|
||||
bps = calculate_bps(done - last, b, a);
|
||||
for (bps_u = 0; bps > 1000 && bps_u < array_size(bps_units); bps_u++)
|
||||
bps /= 1000;
|
||||
|
||||
percent = floor(((double)(done) / (double)total) * 100);
|
||||
percent = floor(((double)(done) / (double)total) * 100);
|
||||
|
||||
done_round = done;
|
||||
for (byte_du = 0; done_round > 1024 && byte_du < array_size(byte_units) - 1;
|
||||
byte_du++)
|
||||
done_round /= 1024;
|
||||
done_round = done;
|
||||
for (byte_du = 0; done_round > 1024 && byte_du < array_size(byte_units) - 1;
|
||||
byte_du++)
|
||||
done_round /= 1024;
|
||||
|
||||
snprintf(suffix, sizeof(suffix), "%4.1lf%s/%.1lf%s %6.1f%s %s",
|
||||
done_round, byte_units[byte_du], total_round, byte_units[byte_tu],
|
||||
bps, bps_units[bps_u],
|
||||
calculate_eta(total - done, done - last, b, a, final));
|
||||
snprintf(suffix, sizeof(suffix), "%4.1lf%s/%.1lf%s %6.1f%s %s", done_round,
|
||||
byte_units[byte_du], total_round, byte_units[byte_tu], bps,
|
||||
bps_units[bps_u], calculate_eta(total - done, done - last, b, a, final));
|
||||
|
||||
print_progress_bar(percent, suffix);
|
||||
print_progress_bar(percent, suffix);
|
||||
}
|
||||
|
||||
|
||||
struct xfer_stat {
|
||||
struct timeval start, before, after;
|
||||
size_t total;
|
||||
size_t last;
|
||||
size_t done;
|
||||
struct timeval start, before, after;
|
||||
size_t total;
|
||||
size_t last;
|
||||
size_t done;
|
||||
};
|
||||
struct xfer_stat x;
|
||||
|
||||
void print_stat(bool final)
|
||||
{
|
||||
struct pollfd pfd = { .fd = msg_fd, .events = POLLIN };
|
||||
struct mscp_stats s;
|
||||
char buf[8192];
|
||||
int timeout;
|
||||
|
||||
if (poll(&pfd, 1, !final ? 100 : 0) < 0) {
|
||||
fprintf(stderr, "poll: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
|
||||
if (pfd.revents & POLLIN) {
|
||||
memset(buf, 0, sizeof(buf));
|
||||
if (read(msg_fd, buf, sizeof(buf)) < 0) {
|
||||
fprintf(stderr, "read: %s\n", strerror(errno));
|
||||
return;
|
||||
}
|
||||
print_cli("\r\033[K" "%s", buf);
|
||||
}
|
||||
|
||||
gettimeofday(&x.after, NULL);
|
||||
if (calculate_timedelta(&x.before, &x.after) > 1 || final) {
|
||||
mscp_get_stats(m, &s);
|
||||
x.total = s.total;
|
||||
x.done = s.done;
|
||||
print_progress(!final ? &x.before : &x.start, &x.after,
|
||||
x.total, !final ? x.last : 0, x.done, final);
|
||||
print_progress(!final ? &x.before : &x.start, &x.after, x.total,
|
||||
!final ? x.last : 0, x.done, final);
|
||||
x.before = x.after;
|
||||
x.last = x.done;
|
||||
}
|
||||
}
|
||||
|
||||
void print_stat_thread_cleanup(void *arg)
|
||||
{
|
||||
print_stat(true);
|
||||
print_cli("\n"); /* final output */
|
||||
}
|
||||
|
||||
void *print_stat_thread(void *arg)
|
||||
{
|
||||
struct pollfd pfd = { .fd = msg_fd, .events = POLLIN };
|
||||
struct mscp_stats s;
|
||||
char buf[8192];
|
||||
|
||||
memset(&x, 0, sizeof(x));
|
||||
gettimeofday(&x.start, NULL);
|
||||
x.before = x.start;
|
||||
|
||||
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
|
||||
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
|
||||
pthread_cleanup_push(print_stat_thread_cleanup, NULL);
|
||||
gettimeofday(&x.start, NULL);
|
||||
x.before = x.start;
|
||||
|
||||
while (true) {
|
||||
print_stat(false);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
pthread_cleanup_pop(1);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <limits.h>
|
||||
#include <pthread.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <message.h>
|
||||
|
||||
/* strerror_r wrapper */
|
||||
__thread char thread_strerror[128];
|
||||
|
||||
/* mscp error message buffer */
|
||||
#define MSCP_ERRMSG_SIZE (PATH_MAX * 2)
|
||||
|
||||
static char errmsg[MSCP_ERRMSG_SIZE];
|
||||
|
||||
void _mscp_set_error(const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
|
||||
memset(errmsg, 0, sizeof(errmsg));
|
||||
va_start(va, fmt);
|
||||
vsnprintf(errmsg, sizeof(errmsg) - 1, fmt, va);
|
||||
va_end(va);
|
||||
}
|
||||
|
||||
const char *mscp_get_error()
|
||||
{
|
||||
return errmsg;
|
||||
}
|
||||
|
||||
|
||||
/* message print functions */
|
||||
|
||||
static int mprint_severity = MSCP_SEVERITY_WARN;
|
||||
|
||||
void mprint_set_severity(int serverity)
|
||||
{
|
||||
if (serverity < 0)
|
||||
mprint_severity = -1; /* no print */
|
||||
mprint_severity = serverity;
|
||||
}
|
||||
|
||||
int mprint_get_severity()
|
||||
{
|
||||
return mprint_severity;
|
||||
}
|
||||
|
||||
@@ -1,57 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _MESSAGE_H_
|
||||
#define _MESSAGE_H_
|
||||
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <mscp.h>
|
||||
|
||||
/* message print. printed messages are passed to application via msg_fd */
|
||||
void mprint_set_severity(int severity);
|
||||
int mprint_get_severity();
|
||||
|
||||
#define mprint(fp, severity, fmt, ...) \
|
||||
do { \
|
||||
if (fp && severity <= mprint_get_severity()) { \
|
||||
fprintf(fp, fmt, ##__VA_ARGS__); \
|
||||
fflush(fp); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define mpr_err(fp, fmt, ...) \
|
||||
mprint(fp, MSCP_SEVERITY_ERR, fmt, ##__VA_ARGS__)
|
||||
#define mpr_warn(fp, fmt, ...) \
|
||||
mprint(fp, MSCP_SEVERITY_WARN, fmt, ##__VA_ARGS__)
|
||||
#define mpr_notice(fp, fmt, ...) \
|
||||
mprint(fp, MSCP_SEVERITY_NOTICE, fmt, ##__VA_ARGS__)
|
||||
#define mpr_info(fp, fmt, ...) \
|
||||
mprint(fp, MSCP_SEVERITY_INFO, fmt, ##__VA_ARGS__)
|
||||
#define mpr_debug(fp, fmt, ...) \
|
||||
mprint(fp, MSCP_SEVERITY_DEBUG, fmt, ##__VA_ARGS__)
|
||||
|
||||
|
||||
/* errorno wrapper */
|
||||
extern __thread char thread_strerror[128];
|
||||
|
||||
#ifdef _GNU_SOURCE
|
||||
/* GNU strerror_r */
|
||||
#define strerrno() \
|
||||
strerror_r(errno, thread_strerror, sizeof(thread_strerror))
|
||||
#else
|
||||
/* this macro assumes that strerror_r never fails. any good way? */
|
||||
#define strerrno() \
|
||||
(strerror_r(errno, thread_strerror, sizeof(thread_strerror)) \
|
||||
? thread_strerror : thread_strerror)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* error message buffer */
|
||||
#define mscp_set_error(fmt, ...) \
|
||||
_mscp_set_error("%s:%d:%s: " fmt "\0", \
|
||||
basename(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
|
||||
|
||||
void _mscp_set_error(const char *fmt, ...);
|
||||
|
||||
#endif /* _MESSAGE_H_ */
|
||||
8
src/minmax.h
Normal file
8
src/minmax.h
Normal file
@@ -0,0 +1,8 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _MINMAX_H_
|
||||
#define _MINMAX_H_
|
||||
|
||||
#define min(a, b) (((a) > (b)) ? (b) : (a))
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
#endif /* _MINMAX_H_ */
|
||||
729
src/mscp.c
729
src/mscp.c
File diff suppressed because it is too large
Load Diff
10
src/openbsd-compat/openbsd-compat.h
Normal file
10
src/openbsd-compat/openbsd-compat.h
Normal file
@@ -0,0 +1,10 @@
|
||||
#ifndef _OPENBSD_COMPAT_H
|
||||
#define _OPENBSD_COMPAT_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifndef HAVE_STRLCAT
|
||||
size_t strlcat(char *dst, const char *src, size_t siz);
|
||||
#endif
|
||||
|
||||
#endif /* _OPENBSD_COMPAT_H_ */
|
||||
62
src/openbsd-compat/strlcat.c
Normal file
62
src/openbsd-compat/strlcat.c
Normal file
@@ -0,0 +1,62 @@
|
||||
/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
||||
*
|
||||
* Permission to use, copy, modify, and distribute this software for any
|
||||
* purpose with or without fee is hereby granted, provided that the above
|
||||
* copyright notice and this permission notice appear in all copies.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
*/
|
||||
|
||||
/* OPENBSD ORIGINAL: lib/libc/string/strlcat.c */
|
||||
|
||||
#include "config.h"
|
||||
#ifndef HAVE_STRLCAT
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Appends src to string dst of size siz (unlike strncat, siz is the
|
||||
* full size of dst, not space left). At most siz-1 characters
|
||||
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
||||
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
|
||||
* If retval >= siz, truncation occurred.
|
||||
*/
|
||||
size_t
|
||||
strlcat(char *dst, const char *src, size_t siz)
|
||||
{
|
||||
char *d = dst;
|
||||
const char *s = src;
|
||||
size_t n = siz;
|
||||
size_t dlen;
|
||||
|
||||
/* Find the end of dst and adjust bytes left but don't go past end */
|
||||
while (n-- != 0 && *d != '\0')
|
||||
d++;
|
||||
dlen = d - dst;
|
||||
n = siz - dlen;
|
||||
|
||||
if (n == 0)
|
||||
return(dlen + strlen(s));
|
||||
while (*s != '\0') {
|
||||
if (n != 1) {
|
||||
*d++ = *s;
|
||||
n--;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
*d = '\0';
|
||||
|
||||
return(dlen + (s - src)); /* count does not include NUL */
|
||||
}
|
||||
|
||||
#endif /* !HAVE_STRLCAT */
|
||||
666
src/path.c
666
src/path.c
@@ -7,105 +7,27 @@
|
||||
#include <assert.h>
|
||||
|
||||
#include <ssh.h>
|
||||
#include <util.h>
|
||||
#include <minmax.h>
|
||||
#include <fileops.h>
|
||||
#include <list.h>
|
||||
#include <atomic.h>
|
||||
#include <path.h>
|
||||
#include <message.h>
|
||||
|
||||
/* chunk pool operations */
|
||||
#define CHUNK_POOL_STATE_FILLING 0
|
||||
#define CHUNK_POOL_STATE_FILLED 1
|
||||
|
||||
void chunk_pool_init(struct chunk_pool *cp)
|
||||
{
|
||||
memset(cp, 0, sizeof(*cp));
|
||||
INIT_LIST_HEAD(&cp->list);
|
||||
lock_init(&cp->lock);
|
||||
cp->state = CHUNK_POOL_STATE_FILLING;
|
||||
}
|
||||
|
||||
static void chunk_pool_add(struct chunk_pool *cp, struct chunk *c)
|
||||
{
|
||||
LOCK_ACQUIRE(&cp->lock);
|
||||
list_add_tail(&c->list, &cp->list);
|
||||
cp->count += 1;
|
||||
LOCK_RELEASE();
|
||||
}
|
||||
|
||||
void chunk_pool_set_filled(struct chunk_pool *cp)
|
||||
{
|
||||
cp->state = CHUNK_POOL_STATE_FILLED;
|
||||
}
|
||||
|
||||
bool chunk_pool_is_filled(struct chunk_pool *cp)
|
||||
{
|
||||
return (cp->state == CHUNK_POOL_STATE_FILLED);
|
||||
}
|
||||
|
||||
size_t chunk_pool_size(struct chunk_pool *cp)
|
||||
{
|
||||
return cp->count;
|
||||
}
|
||||
|
||||
bool chunk_pool_is_empty(struct chunk_pool *cp)
|
||||
{
|
||||
return list_empty(&cp->list);
|
||||
}
|
||||
|
||||
struct chunk *chunk_pool_pop(struct chunk_pool *cp)
|
||||
{
|
||||
struct list_head *first;
|
||||
struct chunk *c = NULL;
|
||||
|
||||
LOCK_ACQUIRE(&cp->lock);
|
||||
first = cp->list.next;
|
||||
if (list_empty(&cp->list)) {
|
||||
if (!chunk_pool_is_filled(cp))
|
||||
c = CHUNK_POP_WAIT;
|
||||
else
|
||||
c = NULL; /* no more chunks */
|
||||
} else {
|
||||
c = list_entry(first, struct chunk, list);
|
||||
list_del(first);
|
||||
}
|
||||
LOCK_RELEASE();
|
||||
|
||||
/* return CHUNK_POP_WAIT would be a rare case, because it
|
||||
* means copying over SSH is faster than traversing
|
||||
* local/remote file paths.
|
||||
*/
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
static void chunk_free(struct list_head *list)
|
||||
{
|
||||
struct chunk *c;
|
||||
c = list_entry(list, typeof(*c), list);
|
||||
free(c);
|
||||
}
|
||||
|
||||
void chunk_pool_release(struct chunk_pool *cp)
|
||||
{
|
||||
list_free_f(&cp->list, chunk_free);
|
||||
}
|
||||
#include <strerrno.h>
|
||||
#include <print.h>
|
||||
|
||||
/* paths of copy source resoltion */
|
||||
static char *resolve_dst_path(const char *src_file_path, struct path_resolve_args *a)
|
||||
{
|
||||
char copy[PATH_MAX + 1], dst_file_path[PATH_MAX + 1];
|
||||
char *prefix;
|
||||
int offset;
|
||||
char copy[PATH_MAX + 1], dst_file_path[PATH_MAX + 1];
|
||||
char *prefix;
|
||||
int offset;
|
||||
int ret;
|
||||
|
||||
strncpy(copy, a->src_path, PATH_MAX);
|
||||
prefix = dirname(copy);
|
||||
if (!prefix) {
|
||||
mscp_set_error("dirname: %s", strerrno());
|
||||
return NULL;
|
||||
}
|
||||
strncpy(copy, a->src_path, PATH_MAX);
|
||||
prefix = dirname(copy);
|
||||
if (!prefix) {
|
||||
pr_err("dirname: %s", strerrno());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
offset = strlen(prefix) + 1;
|
||||
if (strlen(prefix) == 1) { /* corner cases */
|
||||
@@ -119,93 +41,95 @@ static char *resolve_dst_path(const char *src_file_path, struct path_resolve_arg
|
||||
}
|
||||
}
|
||||
|
||||
if (!a->src_path_is_dir && !a->dst_path_is_dir) {
|
||||
/* src path is file. dst path is (1) file, or (2) does not exist.
|
||||
if (!a->src_path_is_dir && !a->dst_path_is_dir) {
|
||||
/* src path is file. dst path is (1) file, or (2) does not exist.
|
||||
* In the second case, we need to put src under the dst.
|
||||
*/
|
||||
if (a->dst_path_should_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s",
|
||||
a->dst_path, a->src_path + offset);
|
||||
else
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s", a->dst_path);
|
||||
}
|
||||
if (a->dst_path_should_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s", a->dst_path,
|
||||
a->src_path + offset);
|
||||
else
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s", a->dst_path);
|
||||
}
|
||||
|
||||
/* src is file, and dst is dir */
|
||||
if (!a->src_path_is_dir && a->dst_path_is_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s",
|
||||
a->dst_path, a->src_path + offset);
|
||||
/* src is file, and dst is dir */
|
||||
if (!a->src_path_is_dir && a->dst_path_is_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s", a->dst_path,
|
||||
a->src_path + offset);
|
||||
|
||||
/* both are directory */
|
||||
if (a->src_path_is_dir && a->dst_path_is_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s",
|
||||
a->dst_path, src_file_path + offset);
|
||||
/* both are directory */
|
||||
if (a->src_path_is_dir && a->dst_path_is_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s", a->dst_path,
|
||||
src_file_path + offset);
|
||||
|
||||
/* dst path does not exist. change dir name to dst_path */
|
||||
if (a->src_path_is_dir && !a->dst_path_is_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s",
|
||||
a->dst_path, src_file_path + strlen(a->src_path) + 1);
|
||||
/* dst path does not exist. change dir name to dst_path */
|
||||
if (a->src_path_is_dir && !a->dst_path_is_dir)
|
||||
ret = snprintf(dst_file_path, PATH_MAX, "%s/%s", a->dst_path,
|
||||
src_file_path + strlen(a->src_path) + 1);
|
||||
|
||||
if (ret >= PATH_MAX) {
|
||||
mpr_warn(a->msg_fp, "Too long path: %s\n", dst_file_path);
|
||||
pr_warn("Too long path: %s", dst_file_path);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mpr_debug(a->msg_fp, "file: %s -> %s\n", src_file_path, dst_file_path);
|
||||
pr_debug("file: %s -> %s", src_file_path, dst_file_path);
|
||||
|
||||
return strndup(dst_file_path, PATH_MAX);
|
||||
return strndup(dst_file_path, PATH_MAX);
|
||||
}
|
||||
|
||||
/* chunk preparation */
|
||||
static struct chunk *alloc_chunk(struct path *p)
|
||||
struct chunk *alloc_chunk(struct path *p, size_t off, size_t len)
|
||||
{
|
||||
struct chunk *c;
|
||||
struct chunk *c;
|
||||
|
||||
if (!(c = malloc(sizeof(*c)))) {
|
||||
mscp_set_error("malloc %s", strerrno());
|
||||
return NULL;
|
||||
}
|
||||
memset(c, 0, sizeof(*c));
|
||||
if (!(c = malloc(sizeof(*c)))) {
|
||||
pr_err("malloc %s", strerrno());
|
||||
return NULL;
|
||||
}
|
||||
memset(c, 0, sizeof(*c));
|
||||
|
||||
c->p = p;
|
||||
c->off = 0;
|
||||
c->len = 0;
|
||||
refcnt_inc(&p->refcnt);
|
||||
return c;
|
||||
c->p = p;
|
||||
c->off = off;
|
||||
c->len = len;
|
||||
c->state = CHUNK_STATE_INIT;
|
||||
refcnt_inc(&p->refcnt);
|
||||
return c;
|
||||
}
|
||||
|
||||
static int resolve_chunk(struct path *p, struct path_resolve_args *a)
|
||||
static int resolve_chunk(struct path *p, size_t size, struct path_resolve_args *a)
|
||||
{
|
||||
struct chunk *c;
|
||||
size_t chunk_sz;
|
||||
size_t size;
|
||||
struct chunk *c;
|
||||
size_t chunk_sz, off, len;
|
||||
size_t remaind;
|
||||
|
||||
if (p->size <= a->min_chunk_sz)
|
||||
chunk_sz = p->size;
|
||||
else if (a->max_chunk_sz)
|
||||
chunk_sz = a->max_chunk_sz;
|
||||
else {
|
||||
chunk_sz = (p->size - (p->size % a->nr_conn)) / a->nr_conn;
|
||||
chunk_sz &= ~a->chunk_align; /* align with page_sz */
|
||||
if (chunk_sz <= a->min_chunk_sz)
|
||||
chunk_sz = a->min_chunk_sz;
|
||||
}
|
||||
if (a->max_chunk_sz)
|
||||
chunk_sz = a->max_chunk_sz;
|
||||
else {
|
||||
chunk_sz = (size / (a->nr_conn * 4)) & a->chunk_align;
|
||||
if (chunk_sz <= a->min_chunk_sz)
|
||||
chunk_sz = a->min_chunk_sz;
|
||||
}
|
||||
|
||||
/* for (size = f->size; size > 0;) does not create a file
|
||||
* (chunk) when file size is 0. This do {} while (size > 0)
|
||||
* creates just open/close a 0-byte file.
|
||||
/* for (size = size; size > 0;) does not create a file (chunk)
|
||||
* when file size is 0. This do {} while (remaind > 0) creates
|
||||
* just open/close a 0-byte file.
|
||||
*/
|
||||
size = p->size;
|
||||
do {
|
||||
c = alloc_chunk(p);
|
||||
if (!c)
|
||||
return -1;
|
||||
c->off = p->size - size;
|
||||
c->len = size < chunk_sz ? size : chunk_sz;
|
||||
size -= c->len;
|
||||
chunk_pool_add(a->cp, c);
|
||||
} while (size > 0);
|
||||
remaind = size;
|
||||
do {
|
||||
off = size - remaind;
|
||||
len = remaind < chunk_sz ? remaind : chunk_sz;
|
||||
c = alloc_chunk(p, off, len);
|
||||
if (!c)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
remaind -= len;
|
||||
if (pool_push_lock(a->chunk_pool, c) < 0) {
|
||||
pr_err("pool_push_lock: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
} while (remaind > 0);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void free_path(struct path *p)
|
||||
@@ -217,36 +141,54 @@ void free_path(struct path *p)
|
||||
free(p);
|
||||
}
|
||||
|
||||
static int append_path(sftp_session sftp, const char *path, struct stat st,
|
||||
struct list_head *path_list, struct path_resolve_args *a)
|
||||
struct path *alloc_path(char *path, char *dst_path)
|
||||
{
|
||||
struct path *p;
|
||||
|
||||
if (!(p = malloc(sizeof(*p)))) {
|
||||
mscp_set_error("failed to allocate memory: %s", strerrno());
|
||||
pr_err("malloc: %s", strerrno());
|
||||
return NULL;
|
||||
}
|
||||
memset(p, 0, sizeof(*p));
|
||||
|
||||
p->path = path;
|
||||
p->dst_path = dst_path;
|
||||
p->state = FILE_STATE_INIT;
|
||||
lock_init(&p->lock);
|
||||
p->data = 0;
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
static int append_path(sftp_session sftp, const char *path, struct stat st,
|
||||
struct path_resolve_args *a)
|
||||
{
|
||||
struct path *p;
|
||||
char *src, *dst;
|
||||
|
||||
if (!(src = strdup(path))) {
|
||||
pr_err("strdup: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(p, 0, sizeof(*p));
|
||||
INIT_LIST_HEAD(&p->list);
|
||||
p->path = strndup(path, PATH_MAX);
|
||||
if (!p->path)
|
||||
goto free_out;
|
||||
p->size = st.st_size;
|
||||
p->mode = st.st_mode;
|
||||
p->state = FILE_STATE_INIT;
|
||||
lock_init(&p->lock);
|
||||
if (!(dst = resolve_dst_path(src, a))) {
|
||||
free(src);
|
||||
return -1;
|
||||
}
|
||||
|
||||
p->dst_path = resolve_dst_path(p->path, a);
|
||||
if (!p->dst_path)
|
||||
goto free_out;
|
||||
if (!(p = alloc_path(src, dst)))
|
||||
return -1;
|
||||
|
||||
if (resolve_chunk(p, a) < 0)
|
||||
if (resolve_chunk(p, st.st_size, a) < 0)
|
||||
return -1; /* XXX: do not free path becuase chunk(s)
|
||||
* was added to chunk pool already */
|
||||
|
||||
list_add_tail(&p->list, path_list);
|
||||
*a->total_bytes += p->size;
|
||||
if (pool_push_lock(a->path_pool, p) < 0) {
|
||||
pr_err("pool_push: %s", strerrno());
|
||||
goto free_out;
|
||||
}
|
||||
|
||||
*a->total_bytes += st.st_size;
|
||||
|
||||
return 0;
|
||||
|
||||
@@ -256,17 +198,17 @@ free_out:
|
||||
}
|
||||
|
||||
static bool check_path_should_skip(const char *path)
|
||||
{
|
||||
int len = strlen(path);
|
||||
if ((len == 1 && strncmp(path, ".", 1) == 0) ||
|
||||
(len == 2 && strncmp(path, "..", 2) == 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
{
|
||||
int len = strlen(path);
|
||||
if ((len == 1 && strncmp(path, ".", 1) == 0) ||
|
||||
(len == 2 && strncmp(path, "..", 2) == 0)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static int walk_path_recursive(sftp_session sftp, const char *path,
|
||||
struct list_head *path_list, struct path_resolve_args *a)
|
||||
struct path_resolve_args *a)
|
||||
{
|
||||
char next_path[PATH_MAX + 1];
|
||||
struct dirent *e;
|
||||
@@ -275,13 +217,13 @@ static int walk_path_recursive(sftp_session sftp, const char *path,
|
||||
int ret;
|
||||
|
||||
if (mscp_stat(path, &st, sftp) < 0) {
|
||||
mpr_warn(a->msg_fp, "%s: %s\n", strerrno(), path);
|
||||
pr_err("stat: %s: %s", path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (S_ISREG(st.st_mode)) {
|
||||
/* this path is regular file. it is to be copied */
|
||||
return append_path(sftp, path, st, path_list, a);
|
||||
return append_path(sftp, path, st, a);
|
||||
}
|
||||
|
||||
if (!S_ISDIR(st.st_mode))
|
||||
@@ -289,23 +231,27 @@ static int walk_path_recursive(sftp_session sftp, const char *path,
|
||||
|
||||
/* ok, this path is a directory. walk through it. */
|
||||
if (!(d = mscp_opendir(path, sftp))) {
|
||||
mpr_warn(a->msg_fp, "%s: %s\n", strerrno(), path);
|
||||
pr_err("opendir: %s: %s", path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
for (e = mscp_readdir(d); e; e = mscp_readdir(d)) {
|
||||
if (check_path_should_skip(e->d_name))
|
||||
continue;
|
||||
|
||||
|
||||
ret = snprintf(next_path, PATH_MAX, "%s/%s", path, e->d_name);
|
||||
if (ret >= PATH_MAX) {
|
||||
mpr_warn(a->msg_fp, "Too long path: %s/%s\n", path, e->d_name);
|
||||
pr_warn("Too long path: %s/%s", path, e->d_name);
|
||||
continue;
|
||||
}
|
||||
|
||||
walk_path_recursive(sftp, next_path, path_list, a);
|
||||
walk_path_recursive(sftp, next_path, a);
|
||||
/* do not stop even when walk_path_recursive returns
|
||||
* -1 due to an unreadable file. go to a next file. */
|
||||
* -1 due to an unreadable file. go to a next
|
||||
* file. Thus, do not pass error messages via
|
||||
* priv_set_err() under walk_path_recursive. Print
|
||||
* the error with pr_err immediately.
|
||||
*/
|
||||
}
|
||||
|
||||
mscp_closedir(d);
|
||||
@@ -314,74 +260,64 @@ static int walk_path_recursive(sftp_session sftp, const char *path,
|
||||
}
|
||||
|
||||
int walk_src_path(sftp_session src_sftp, const char *src_path,
|
||||
struct list_head *path_list, struct path_resolve_args *a)
|
||||
struct path_resolve_args *a)
|
||||
{
|
||||
return walk_path_recursive(src_sftp, src_path, path_list, a);
|
||||
return walk_path_recursive(src_sftp, src_path, a);
|
||||
}
|
||||
|
||||
void path_dump(struct list_head *path_list)
|
||||
{
|
||||
struct path *p;
|
||||
|
||||
list_for_each_entry(p, path_list, list) {
|
||||
printf("src: %s %lu-byte\n", p->path, p->size);
|
||||
printf("dst: %s\n", p->dst_path);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* based on
|
||||
* https://stackoverflow.com/questions/2336242/recursive-mkdir-system-call-on-unix */
|
||||
static int touch_dst_path(struct path *p, sftp_session sftp)
|
||||
{
|
||||
/* XXX: should reflect the permission of the original directory? */
|
||||
mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
/* XXX: should reflect the permission of the original directory? */
|
||||
mode_t mode = S_IRWXU | S_IRWXG | S_IRWXO;
|
||||
struct stat st;
|
||||
char path[PATH_MAX];
|
||||
char *needle;
|
||||
int ret;
|
||||
char path[PATH_MAX];
|
||||
char *needle;
|
||||
int ret;
|
||||
mf *f;
|
||||
|
||||
strncpy(path, p->dst_path, sizeof(path));
|
||||
strncpy(path, p->dst_path, sizeof(path));
|
||||
|
||||
/* mkdir -p.
|
||||
/* mkdir -p.
|
||||
* XXX: this may be slow when dst is the remote side. need speed-up. */
|
||||
for (needle = strchr(path + 1, '/'); needle; needle = strchr(needle + 1, '/')) {
|
||||
*needle = '\0';
|
||||
for (needle = strchr(path + 1, '/'); needle; needle = strchr(needle + 1, '/')) {
|
||||
*needle = '\0';
|
||||
|
||||
if (mscp_stat(path, &st, sftp) == 0) {
|
||||
if (S_ISDIR(st.st_mode))
|
||||
goto next; /* directory exists. go deeper */
|
||||
else
|
||||
else {
|
||||
priv_set_errv("mscp_stat %s: not a directory", path);
|
||||
return -1; /* path exists, but not directory. */
|
||||
}
|
||||
}
|
||||
|
||||
if (errno == ENOENT) {
|
||||
/* no file on the path. create directory. */
|
||||
if (mscp_mkdir(path, mode, sftp) < 0) {
|
||||
mscp_set_error("mscp_mkdir %s: %s", path, strerrno());
|
||||
priv_set_errv("mscp_mkdir %s: %s", path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
next:
|
||||
*needle = '/';
|
||||
}
|
||||
next:
|
||||
*needle = '/';
|
||||
}
|
||||
|
||||
/* Do not set O_TRUNC here. Instead, do mscp_setstat() at the
|
||||
* end. see https://bugzilla.mindrot.org/show_bug.cgi?id=3431 */
|
||||
f = mscp_open(p->dst_path, O_WRONLY|O_CREAT, S_IRUSR|S_IWUSR, sftp);
|
||||
f = mscp_open(p->dst_path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR, sftp);
|
||||
if (!f) {
|
||||
mscp_set_error("mscp_open %s: %s\n", p->dst_path, strerrno());
|
||||
priv_set_errv("mscp_open %s: %s", p->dst_path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mscp_close(f);
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int prepare_dst_path(FILE *msg_fp, struct path *p, sftp_session dst_sftp)
|
||||
static int prepare_dst_path(struct path *p, sftp_session dst_sftp)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
@@ -392,7 +328,7 @@ static int prepare_dst_path(FILE *msg_fp, struct path *p, sftp_session dst_sftp)
|
||||
goto out;
|
||||
}
|
||||
p->state = FILE_STATE_OPENED;
|
||||
mpr_info(msg_fp, "copy start: %s\n", p->path);
|
||||
pr_info("copy start: %s", p->path);
|
||||
}
|
||||
|
||||
out:
|
||||
@@ -400,161 +336,164 @@ out:
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/* functions for copy */
|
||||
|
||||
static ssize_t read_to_buf(void *ptr, size_t len, void *userdata)
|
||||
{
|
||||
int fd = *((int *)userdata);
|
||||
return read(fd, ptr, len);
|
||||
int fd = *((int *)userdata);
|
||||
return read(fd, ptr, len);
|
||||
}
|
||||
|
||||
static int copy_chunk_l2r(struct chunk *c, int fd, sftp_file sf,
|
||||
int nr_ahead, int buf_sz, size_t *counter)
|
||||
static int copy_chunk_l2r(struct chunk *c, int fd, sftp_file sf, int nr_ahead, int buf_sz,
|
||||
struct bwlimit *bw, size_t *counter)
|
||||
{
|
||||
ssize_t read_bytes, remaind, thrown;
|
||||
int idx, ret;
|
||||
struct {
|
||||
uint32_t id;
|
||||
ssize_t len;
|
||||
} reqs[nr_ahead];
|
||||
ssize_t read_bytes, remaind, thrown;
|
||||
int idx, ret;
|
||||
struct {
|
||||
uint32_t id;
|
||||
ssize_t len;
|
||||
} reqs[nr_ahead];
|
||||
|
||||
if (c->len == 0)
|
||||
return 0;
|
||||
if (c->len == 0)
|
||||
return 0;
|
||||
|
||||
remaind = thrown = c->len;
|
||||
for (idx = 0; idx < nr_ahead && thrown > 0; idx++) {
|
||||
reqs[idx].len = min(thrown, buf_sz);
|
||||
reqs[idx].len = sftp_async_write(sf, read_to_buf, reqs[idx].len, &fd,
|
||||
&reqs[idx].id);
|
||||
if (reqs[idx].len < 0) {
|
||||
mscp_set_error("sftp_async_write: %s or %s",
|
||||
sftp_get_ssh_error(sf->sftp), strerrno());
|
||||
return -1;
|
||||
}
|
||||
thrown -= reqs[idx].len;
|
||||
}
|
||||
remaind = thrown = c->len;
|
||||
for (idx = 0; idx < nr_ahead && thrown > 0; idx++) {
|
||||
reqs[idx].len = min(thrown, buf_sz);
|
||||
reqs[idx].len = sftp_async_write(sf, read_to_buf, reqs[idx].len, &fd,
|
||||
&reqs[idx].id);
|
||||
if (reqs[idx].len < 0) {
|
||||
priv_set_errv("sftp_async_write: %s",
|
||||
sftp_get_ssh_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
thrown -= reqs[idx].len;
|
||||
bwlimit_wait(bw, reqs[idx].len);
|
||||
}
|
||||
|
||||
for (idx = 0; remaind > 0; idx = (idx + 1) % nr_ahead) {
|
||||
ret = sftp_async_write_end(sf, reqs[idx].id, 1);
|
||||
if (ret != SSH_OK) {
|
||||
mscp_set_error("sftp_async_write_end: %s",
|
||||
sftp_get_ssh_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
for (idx = 0; remaind > 0; idx = (idx + 1) % nr_ahead) {
|
||||
ret = sftp_async_write_end(sf, reqs[idx].id, 1);
|
||||
if (ret != SSH_OK) {
|
||||
priv_set_errv("sftp_async_write_end: %s",
|
||||
sftp_get_ssh_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
|
||||
*counter += reqs[idx].len;
|
||||
remaind -= reqs[idx].len;
|
||||
*counter += reqs[idx].len;
|
||||
remaind -= reqs[idx].len;
|
||||
|
||||
if (remaind <= 0)
|
||||
break;
|
||||
if (remaind <= 0)
|
||||
break;
|
||||
|
||||
if (thrown <= 0)
|
||||
continue;
|
||||
if (thrown <= 0)
|
||||
continue;
|
||||
|
||||
reqs[idx].len = min(thrown, buf_sz);
|
||||
reqs[idx].len = sftp_async_write(sf, read_to_buf, reqs[idx].len, &fd,
|
||||
&reqs[idx].id);
|
||||
if (reqs[idx].len < 0) {
|
||||
mscp_set_error("sftp_async_write: %s or %s",
|
||||
sftp_get_ssh_error(sf->sftp), strerrno());
|
||||
return -1;
|
||||
}
|
||||
thrown -= reqs[idx].len;
|
||||
}
|
||||
reqs[idx].len = min(thrown, buf_sz);
|
||||
reqs[idx].len = sftp_async_write(sf, read_to_buf, reqs[idx].len, &fd,
|
||||
&reqs[idx].id);
|
||||
if (reqs[idx].len < 0) {
|
||||
priv_set_errv("sftp_async_write: %s",
|
||||
sftp_get_ssh_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
thrown -= reqs[idx].len;
|
||||
bwlimit_wait(bw, reqs[idx].len);
|
||||
}
|
||||
|
||||
if (remaind < 0) {
|
||||
mscp_set_error("invalid remaind bytes %ld. "
|
||||
"last async_write_end bytes %lu.",
|
||||
remaind, reqs[idx].len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
if (remaind < 0) {
|
||||
priv_set_errv("invalid remaind bytes %ld. "
|
||||
"last async_write_end bytes %lu.",
|
||||
remaind, reqs[idx].len);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int copy_chunk_r2l(struct chunk *c, sftp_file sf, int fd,
|
||||
int nr_ahead, int buf_sz, size_t *counter)
|
||||
static int copy_chunk_r2l(struct chunk *c, sftp_file sf, int fd, int nr_ahead, int buf_sz,
|
||||
struct bwlimit *bw, size_t *counter)
|
||||
{
|
||||
ssize_t read_bytes, write_bytes, remaind, thrown;
|
||||
char buf[buf_sz];
|
||||
int idx;
|
||||
struct {
|
||||
int id;
|
||||
ssize_t len;
|
||||
} reqs[nr_ahead];
|
||||
ssize_t read_bytes, write_bytes, remaind, thrown;
|
||||
char buf[buf_sz];
|
||||
int idx;
|
||||
struct {
|
||||
int id;
|
||||
ssize_t len;
|
||||
} reqs[nr_ahead];
|
||||
|
||||
if (c->len == 0)
|
||||
return 0;
|
||||
if (c->len == 0)
|
||||
return 0;
|
||||
|
||||
remaind = thrown = c->len;
|
||||
remaind = thrown = c->len;
|
||||
|
||||
for (idx = 0; idx < nr_ahead && thrown > 0; idx++) {
|
||||
reqs[idx].len = min(thrown, sizeof(buf));
|
||||
reqs[idx].id = sftp_async_read_begin(sf, reqs[idx].len);
|
||||
if (reqs[idx].id < 0) {
|
||||
mscp_set_error("sftp_async_read_begin: %d",
|
||||
sftp_get_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
thrown -= reqs[idx].len;
|
||||
}
|
||||
for (idx = 0; idx < nr_ahead && thrown > 0; idx++) {
|
||||
reqs[idx].len = min(thrown, sizeof(buf));
|
||||
reqs[idx].id = sftp_async_read_begin(sf, reqs[idx].len);
|
||||
if (reqs[idx].id < 0) {
|
||||
priv_set_errv("sftp_async_read_begin: %d",
|
||||
sftp_get_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
thrown -= reqs[idx].len;
|
||||
bwlimit_wait(bw, reqs[idx].len);
|
||||
}
|
||||
|
||||
for (idx = 0; remaind > 0; idx = (idx + 1) % nr_ahead) {
|
||||
read_bytes = sftp_async_read(sf, buf, reqs[idx].len, reqs[idx].id);
|
||||
if (read_bytes == SSH_ERROR) {
|
||||
mscp_set_error("sftp_async_read: %d",
|
||||
sftp_get_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
for (idx = 0; remaind > 0; idx = (idx + 1) % nr_ahead) {
|
||||
read_bytes = sftp_async_read(sf, buf, reqs[idx].len, reqs[idx].id);
|
||||
if (read_bytes == SSH_ERROR) {
|
||||
priv_set_errv("sftp_async_read: %d", sftp_get_error(sf->sftp));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (thrown > 0) {
|
||||
reqs[idx].len = min(thrown, sizeof(buf));
|
||||
reqs[idx].id = sftp_async_read_begin(sf, reqs[idx].len);
|
||||
thrown -= reqs[idx].len;
|
||||
}
|
||||
if (thrown > 0) {
|
||||
reqs[idx].len = min(thrown, sizeof(buf));
|
||||
reqs[idx].id = sftp_async_read_begin(sf, reqs[idx].len);
|
||||
thrown -= reqs[idx].len;
|
||||
bwlimit_wait(bw, reqs[idx].len);
|
||||
}
|
||||
|
||||
write_bytes = write(fd, buf, read_bytes);
|
||||
if (write_bytes < 0) {
|
||||
mscp_set_error("write: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
write_bytes = write(fd, buf, read_bytes);
|
||||
if (write_bytes < 0) {
|
||||
priv_set_errv("write: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (write_bytes < read_bytes) {
|
||||
mscp_set_error("failed to write full bytes");
|
||||
return -1;
|
||||
}
|
||||
if (write_bytes < read_bytes) {
|
||||
priv_set_errv("failed to write full bytes");
|
||||
return -1;
|
||||
}
|
||||
|
||||
*counter += write_bytes;
|
||||
remaind -= read_bytes;
|
||||
}
|
||||
*counter += write_bytes;
|
||||
remaind -= read_bytes;
|
||||
}
|
||||
|
||||
if (remaind < 0) {
|
||||
mscp_set_error("invalid remaind bytes %ld. last async_read bytes %ld. "
|
||||
"last write bytes %ld",
|
||||
remaind, read_bytes, write_bytes);
|
||||
return -1;
|
||||
}
|
||||
if (remaind < 0) {
|
||||
priv_set_errv("invalid remaind bytes %ld. last async_read bytes %ld. "
|
||||
"last write bytes %ld",
|
||||
remaind, read_bytes, write_bytes);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _copy_chunk(struct chunk *c, mf *s, mf *d,
|
||||
int nr_ahead, int buf_sz, size_t *counter)
|
||||
static int _copy_chunk(struct chunk *c, mf *s, mf *d, int nr_ahead, int buf_sz,
|
||||
struct bwlimit *bw, size_t *counter)
|
||||
{
|
||||
if (s->local && d->remote) /* local to remote copy */
|
||||
return copy_chunk_l2r(c, s->local, d->remote, nr_ahead, buf_sz, counter);
|
||||
else if (s->remote && d->local) /* remote to local copy */
|
||||
return copy_chunk_r2l(c, s->remote, d->local, nr_ahead, buf_sz, counter);
|
||||
return copy_chunk_l2r(c, s->local, d->remote, nr_ahead, buf_sz, bw,
|
||||
counter);
|
||||
else if (s->remote && d->local) /* remote to local copy */
|
||||
return copy_chunk_r2l(c, s->remote, d->local, nr_ahead, buf_sz, bw,
|
||||
counter);
|
||||
|
||||
assert(false);
|
||||
return -1; /* not reached */
|
||||
}
|
||||
|
||||
int copy_chunk(FILE *msg_fp, struct chunk *c,
|
||||
sftp_session src_sftp, sftp_session dst_sftp,
|
||||
int nr_ahead, int buf_sz, size_t *counter)
|
||||
int copy_chunk(struct chunk *c, sftp_session src_sftp, sftp_session dst_sftp,
|
||||
int nr_ahead, int buf_sz, bool preserve_ts, struct bwlimit *bw,
|
||||
size_t *counter)
|
||||
{
|
||||
mode_t mode;
|
||||
int flags;
|
||||
@@ -563,44 +502,40 @@ int copy_chunk(FILE *msg_fp, struct chunk *c,
|
||||
|
||||
assert((src_sftp && !dst_sftp) || (!src_sftp && dst_sftp));
|
||||
|
||||
if (prepare_dst_path(msg_fp, c->p, dst_sftp) < 0)
|
||||
if (prepare_dst_path(c->p, dst_sftp) < 0)
|
||||
return -1;
|
||||
|
||||
/* open src */
|
||||
flags = O_RDONLY;
|
||||
mode = S_IRUSR;
|
||||
s = mscp_open(c->p->path, flags, mode, src_sftp);
|
||||
if (!s) {
|
||||
mscp_set_error("mscp_open: %s: %s", c->p->path, strerrno());
|
||||
flags = O_RDONLY;
|
||||
mode = S_IRUSR;
|
||||
if (!(s = mscp_open(c->p->path, flags, mode, src_sftp))) {
|
||||
priv_set_errv("mscp_open: %s: %s", c->p->path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
if (mscp_lseek(s, c->off) < 0) {
|
||||
mscp_set_error("mscp_lseek: %s: %s", c->p->path, strerrno());
|
||||
priv_set_errv("mscp_lseek: %s: %s", c->p->path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* open dst */
|
||||
flags = O_WRONLY;
|
||||
mode = S_IRUSR|S_IWUSR;
|
||||
d = mscp_open(c->p->dst_path, flags, mode, dst_sftp);
|
||||
if (!d) {
|
||||
flags = O_WRONLY;
|
||||
mode = S_IRUSR | S_IWUSR;
|
||||
if (!(d = mscp_open(c->p->dst_path, flags, mode, dst_sftp))) {
|
||||
mscp_close(s);
|
||||
mscp_set_error("mscp_open: %s: %s", c->p->dst_path, strerrno());
|
||||
priv_set_errv("mscp_open: %s: %s", c->p->dst_path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
if (mscp_lseek(d, c->off) < 0) {
|
||||
mscp_set_error("mscp_lseek: %s: %s", c->p->dst_path, strerrno());
|
||||
priv_set_errv("mscp_lseek: %s: %s", c->p->dst_path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
mpr_debug(msg_fp, "copy chunk start: %s 0x%lx-0x%lx\n",
|
||||
c->p->path, c->off, c->off + c->len);
|
||||
c->state = CHUNK_STATE_COPING;
|
||||
pr_debug("copy chunk start: %s 0x%lx-0x%lx", c->p->path, c->off, c->off + c->len);
|
||||
|
||||
ret = _copy_chunk(c, s, d, nr_ahead, buf_sz, counter);
|
||||
|
||||
mpr_debug(msg_fp, "copy chunk done: %s 0x%lx-0x%lx\n",
|
||||
c->p->path, c->off, c->off + c->len);
|
||||
ret = _copy_chunk(c, s, d, nr_ahead, buf_sz, bw, counter);
|
||||
|
||||
pr_debug("copy chunk done: %s 0x%lx-0x%lx", c->p->path, c->off, c->off + c->len);
|
||||
|
||||
mscp_close(d);
|
||||
mscp_close(s);
|
||||
@@ -608,12 +543,23 @@ int copy_chunk(FILE *msg_fp, struct chunk *c,
|
||||
return ret;
|
||||
|
||||
if (refcnt_dec(&c->p->refcnt) == 0) {
|
||||
struct stat st;
|
||||
c->p->state = FILE_STATE_DONE;
|
||||
if (mscp_setstat(c->p->dst_path, c->p->mode, c->p->size, dst_sftp) < 0)
|
||||
mpr_err(msg_fp, "failed to chmod and truncate %s: %s\n",
|
||||
c->p->path, strerrno());
|
||||
mpr_info(msg_fp, "copy done: %s\n", c->p->path);
|
||||
|
||||
/* sync stat */
|
||||
if (mscp_stat(c->p->path, &st, src_sftp) < 0) {
|
||||
priv_set_errv("mscp_stat: %s: %s", c->p->path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
if (mscp_setstat(c->p->dst_path, &st, preserve_ts, dst_sftp) < 0) {
|
||||
priv_set_errv("mscp_setstat: %s: %s", c->p->path, strerrno());
|
||||
return -1;
|
||||
}
|
||||
pr_info("copy done: %s", c->p->path);
|
||||
}
|
||||
|
||||
if (ret == 0)
|
||||
c->state = CHUNK_STATE_DONE;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
113
src/path.h
113
src/path.h
@@ -6,103 +6,68 @@
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/stat.h>
|
||||
|
||||
#include <list.h>
|
||||
#include <pool.h>
|
||||
#include <atomic.h>
|
||||
#include <ssh.h>
|
||||
#include <message.h>
|
||||
#include <bwlimit.h>
|
||||
|
||||
struct path {
|
||||
struct list_head list; /* mscp->path_list */
|
||||
char *path; /* file path */
|
||||
char *dst_path; /* copy dst path */
|
||||
|
||||
char *path; /* file path */
|
||||
size_t size; /* size of file on this path */
|
||||
mode_t mode; /* permission */
|
||||
refcnt refcnt; /* number of associated chunks */
|
||||
lock lock;
|
||||
int state;
|
||||
#define FILE_STATE_INIT 0
|
||||
#define FILE_STATE_OPENED 1
|
||||
#define FILE_STATE_DONE 2
|
||||
|
||||
char *dst_path; /* copy dst path */
|
||||
|
||||
int state;
|
||||
lock lock;
|
||||
refcnt refcnt;
|
||||
uint64_t data; /* used by other components, i.e., checkpoint */
|
||||
};
|
||||
#define FILE_STATE_INIT 0
|
||||
#define FILE_STATE_OPENED 1
|
||||
#define FILE_STATE_DONE 2
|
||||
|
||||
struct path *alloc_path(char *path, char *dst_path);
|
||||
|
||||
struct chunk {
|
||||
struct list_head list; /* chunk_pool->list */
|
||||
|
||||
struct path *p;
|
||||
size_t off; /* offset of this chunk on the file on path p */
|
||||
size_t len; /* length of this chunk */
|
||||
size_t done; /* copied bytes for this chunk by a thread */
|
||||
size_t off; /* offset of this chunk on the file on path p */
|
||||
size_t len; /* length of this chunk */
|
||||
int state;
|
||||
#define CHUNK_STATE_INIT 0
|
||||
#define CHUNK_STATE_COPING 1
|
||||
#define CHUNK_STATE_DONE 2
|
||||
};
|
||||
|
||||
struct chunk_pool {
|
||||
struct list_head list; /* list of struct chunk */
|
||||
size_t count;
|
||||
lock lock;
|
||||
int state;
|
||||
};
|
||||
|
||||
|
||||
/* initialize chunk pool */
|
||||
void chunk_pool_init(struct chunk_pool *cp);
|
||||
|
||||
/* acquire a chunk from pool. return value is NULL indicates no more
|
||||
* chunk, GET_CHUNK_WAIT means caller should waits until a chunk is
|
||||
* added, or pointer to chunk.
|
||||
*/
|
||||
struct chunk *chunk_pool_pop(struct chunk_pool *cp);
|
||||
#define CHUNK_POP_WAIT ((void *) -1)
|
||||
|
||||
/* set and check fillingchunks to this pool has finished */
|
||||
void chunk_pool_set_filled(struct chunk_pool *cp);
|
||||
bool chunk_pool_is_filled(struct chunk_pool *cp);
|
||||
|
||||
/* return number of chunks in the pool */
|
||||
size_t chunk_pool_size(struct chunk_pool *cp);
|
||||
|
||||
/* return true if chunk pool is empty (all chunks are already poped) */
|
||||
bool chunk_pool_is_empty(struct chunk_pool *cp);
|
||||
|
||||
/* free chunks in the chunk_pool */
|
||||
void chunk_pool_release(struct chunk_pool *cp);
|
||||
|
||||
|
||||
struct chunk *alloc_chunk(struct path *p, size_t off, size_t len);
|
||||
|
||||
struct path_resolve_args {
|
||||
FILE *msg_fp;
|
||||
size_t *total_bytes;
|
||||
size_t *total_bytes;
|
||||
|
||||
/* args to resolve src path to dst path */
|
||||
const char *src_path;
|
||||
const char *dst_path;
|
||||
bool src_path_is_dir;
|
||||
bool dst_path_is_dir;
|
||||
bool dst_path_should_dir;
|
||||
/* args to resolve src path to dst path */
|
||||
const char *src_path;
|
||||
const char *dst_path;
|
||||
bool src_path_is_dir;
|
||||
bool dst_path_is_dir;
|
||||
bool dst_path_should_dir;
|
||||
|
||||
/* args to resolve chunks for a path */
|
||||
struct chunk_pool *cp;
|
||||
int nr_conn;
|
||||
size_t min_chunk_sz;
|
||||
size_t max_chunk_sz;
|
||||
size_t chunk_align;
|
||||
/* args to resolve chunks for a path */
|
||||
pool *path_pool;
|
||||
pool *chunk_pool;
|
||||
int nr_conn;
|
||||
size_t min_chunk_sz;
|
||||
size_t max_chunk_sz;
|
||||
size_t chunk_align;
|
||||
};
|
||||
|
||||
/* recursivly walk through src_path and fill path_list for each file */
|
||||
/* walk src_path recursivly and fill a->path_pool with found files */
|
||||
int walk_src_path(sftp_session src_sftp, const char *src_path,
|
||||
struct list_head *path_list, struct path_resolve_args *a);
|
||||
struct path_resolve_args *a);
|
||||
|
||||
/* free struct path */
|
||||
void free_path(struct path *p);
|
||||
|
||||
/* copy a chunk. either src_sftp or dst_sftp is not null, and another is null */
|
||||
int copy_chunk(FILE *msg_fp, struct chunk *c,
|
||||
sftp_session src_sftp, sftp_session dst_sftp,
|
||||
int nr_ahead, int buf_sz, size_t *counter);
|
||||
|
||||
/* just print contents. just for debugging */
|
||||
void path_dump(struct list_head *path_list);
|
||||
int copy_chunk(struct chunk *c, sftp_session src_sftp, sftp_session dst_sftp,
|
||||
int nr_ahead, int buf_sz, bool preserve_ts, struct bwlimit *bw,
|
||||
size_t *counter);
|
||||
|
||||
#endif /* _PATH_H_ */
|
||||
|
||||
@@ -2,19 +2,30 @@
|
||||
#ifdef __APPLE__
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/sysctl.h>
|
||||
#elif linux
|
||||
#define _GNU_SOURCE
|
||||
#include <sched.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <sched.h>
|
||||
#elif __FreeBSD__
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <pthread_np.h>
|
||||
#else
|
||||
#error unsupported platform
|
||||
#endif
|
||||
|
||||
#include <util.h>
|
||||
#include <config.h>
|
||||
#include <platform.h>
|
||||
#include <message.h>
|
||||
|
||||
#include <strerrno.h>
|
||||
#include <print.h>
|
||||
|
||||
#ifdef __APPLE__
|
||||
int nr_cpus()
|
||||
@@ -23,7 +34,7 @@ int nr_cpus()
|
||||
size_t size = sizeof(n);
|
||||
|
||||
if (sysctlbyname("machdep.cpu.core_count", &n, &size, NULL, 0) != 0) {
|
||||
mscp_set_error("failed to get number of cpu cores: %s", strerrno());
|
||||
priv_set_errv("failed to get number of cpu cores: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -32,21 +43,35 @@ int nr_cpus()
|
||||
|
||||
int set_thread_affinity(pthread_t tid, int core)
|
||||
{
|
||||
pr_warn("setting thread afinity is not implemented on apple\n");
|
||||
pr_warn("setting thread afinity is not implemented on apple");
|
||||
return 0;
|
||||
}
|
||||
|
||||
int setutimes(const char *path, struct timespec atime, struct timespec mtime)
|
||||
{
|
||||
struct timeval tv[2] = {
|
||||
{
|
||||
.tv_sec = atime.tv_sec,
|
||||
.tv_usec = atime.tv_nsec * 1000,
|
||||
},
|
||||
{
|
||||
.tv_sec = mtime.tv_sec,
|
||||
.tv_usec = mtime.tv_nsec * 1000,
|
||||
},
|
||||
};
|
||||
return utimes(path, tv);
|
||||
}
|
||||
|
||||
static void random_string(char *buf, size_t size)
|
||||
{
|
||||
char chars[] = "abcdefhijklmnopqrstuvwxyz1234567890";
|
||||
int n, x;
|
||||
char chars[] = "abcdefhijklmnopqrstuvwxyz1234567890";
|
||||
int n, x;
|
||||
|
||||
for (n = 0; n < size - 1; n++) {
|
||||
x = arc4random() % (sizeof(chars) - 1);
|
||||
buf[n] = chars[x];
|
||||
}
|
||||
buf[size - 1] = '\0';
|
||||
for (n = 0; n < size - 1; n++) {
|
||||
x = arc4random() % (sizeof(chars) - 1);
|
||||
buf[n] = chars[x];
|
||||
}
|
||||
buf[size - 1] = '\0';
|
||||
}
|
||||
|
||||
sem_t *sem_create(int value)
|
||||
@@ -55,10 +80,10 @@ sem_t *sem_create(int value)
|
||||
sem_t *sem;
|
||||
int n;
|
||||
|
||||
n = strlen(sem_name);
|
||||
random_string(sem_name + n, sizeof(sem_name) - n - 1);
|
||||
if ((sem = sem_open(sem_name, O_CREAT, 600, value)) == SEM_FAILED)
|
||||
return NULL;
|
||||
n = strlen(sem_name);
|
||||
random_string(sem_name + n, sizeof(sem_name) - n - 1);
|
||||
if ((sem = sem_open(sem_name, O_CREAT, 600, value)) == SEM_FAILED)
|
||||
return NULL;
|
||||
|
||||
return sem;
|
||||
}
|
||||
@@ -78,6 +103,17 @@ int nr_cpus()
|
||||
return CPU_COUNT(&cpu_set);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
int nr_cpus()
|
||||
{
|
||||
long nr_cpus = sysconf(_SC_NPROCESSORS_ONLN);
|
||||
return nr_cpus;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(linux) || defined(__FreeBSD__)
|
||||
|
||||
int set_thread_affinity(pthread_t tid, int core)
|
||||
{
|
||||
@@ -88,8 +124,21 @@ int set_thread_affinity(pthread_t tid, int core)
|
||||
CPU_SET(core, &target_cpu_set);
|
||||
ret = pthread_setaffinity_np(tid, sizeof(target_cpu_set), &target_cpu_set);
|
||||
if (ret < 0)
|
||||
mscp_set_error("failed to set thread/cpu affinity for core %d: %s",
|
||||
core, strerrno());
|
||||
priv_set_errv("failed to set thread/cpu affinity for core %d: %s", core,
|
||||
strerrno());
|
||||
return ret;
|
||||
}
|
||||
|
||||
int setutimes(const char *path, struct timespec atime, struct timespec mtime)
|
||||
{
|
||||
struct timespec ts[2] = { atime, mtime };
|
||||
int fd = open(path, O_WRONLY);
|
||||
int ret;
|
||||
|
||||
if (fd < 0)
|
||||
return -1;
|
||||
ret = futimens(fd, ts);
|
||||
close(fd);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@@ -115,4 +164,3 @@ int sem_release(sem_t *sem)
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -2,11 +2,15 @@
|
||||
#ifndef _PLATFORM_H_
|
||||
#define _PLATFORM_H_
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <pthread.h>
|
||||
#include <semaphore.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int nr_cpus(void);
|
||||
int set_thread_affinity(pthread_t tid, int core);
|
||||
int setutimes(const char *path, struct timespec atime, struct timespec mtime);
|
||||
|
||||
/*
|
||||
* macOS does not support sem_init(). macOS (seems to) releases the
|
||||
@@ -19,4 +23,25 @@ int set_thread_affinity(pthread_t tid, int core);
|
||||
sem_t *sem_create(int value);
|
||||
int sem_release(sem_t *sem);
|
||||
|
||||
#ifdef HAVE_HTONLL
|
||||
#include <arpa/inet.h> /* Apple has htonll and ntohll in arpa/inet.h */
|
||||
#endif
|
||||
|
||||
/* copied from libssh: libssh/include/libssh/priv.h */
|
||||
#ifndef HAVE_HTONLL
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define htonll(x) (x)
|
||||
#else
|
||||
#define htonll(x) (((uint64_t)htonl((x)&0xFFFFFFFF) << 32) | htonl((x) >> 32))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifndef HAVE_NTOHLL
|
||||
#ifdef WORDS_BIGENDIAN
|
||||
#define ntohll(x) (x)
|
||||
#else
|
||||
#define ntohll(x) (((uint64_t)ntohl((x)&0xFFFFFFFF) << 32) | ntohl((x) >> 32))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#endif /* _PLATFORM_H_ */
|
||||
|
||||
123
src/pool.c
Normal file
123
src/pool.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <pool.h>
|
||||
|
||||
#define DEFAULT_START_SIZE 16
|
||||
|
||||
pool *pool_new(void)
|
||||
{
|
||||
pool *p;
|
||||
p = malloc(sizeof(*p));
|
||||
if (!p)
|
||||
return NULL;
|
||||
memset(p, 0, sizeof(*p));
|
||||
|
||||
p->array = calloc(DEFAULT_START_SIZE, sizeof(void *));
|
||||
if (!p->array) {
|
||||
free(p);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
p->len = DEFAULT_START_SIZE;
|
||||
p->num = 0;
|
||||
lock_init(&p->lock);
|
||||
return p;
|
||||
}
|
||||
|
||||
void pool_free(pool *p)
|
||||
{
|
||||
if (p->array) {
|
||||
free(p->array);
|
||||
p->array = NULL;
|
||||
}
|
||||
free(p);
|
||||
}
|
||||
|
||||
void pool_zeroize(pool *p, pool_map_f f)
|
||||
{
|
||||
void *v;
|
||||
pool_iter_for_each(p, v) {
|
||||
f(v);
|
||||
}
|
||||
p->num = 0;
|
||||
}
|
||||
|
||||
void pool_destroy(pool *p, pool_map_f f)
|
||||
{
|
||||
pool_zeroize(p, f);
|
||||
pool_free(p);
|
||||
}
|
||||
|
||||
int pool_push(pool *p, void *v)
|
||||
{
|
||||
if (p->num == p->len) {
|
||||
/* expand array */
|
||||
size_t newlen = p->len * 2;
|
||||
void *new = realloc(p->array, newlen * sizeof(void *));
|
||||
if (new == NULL)
|
||||
return -1;
|
||||
p->len = newlen;
|
||||
p->array = new;
|
||||
}
|
||||
p->array[p->num] = v;
|
||||
__sync_synchronize();
|
||||
p->num++;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int pool_push_lock(pool *p, void *v)
|
||||
{
|
||||
int ret = -1;
|
||||
pool_lock(p);
|
||||
ret = pool_push(p, v);
|
||||
pool_unlock(p);
|
||||
return ret;
|
||||
}
|
||||
|
||||
void *pool_pop(pool *p)
|
||||
{
|
||||
return p->num == 0 ? NULL : p->array[--p->num];
|
||||
}
|
||||
|
||||
void *pool_pop_lock(pool *p)
|
||||
{
|
||||
void *v;
|
||||
pool_lock(p);
|
||||
v = pool_pop(p);
|
||||
pool_unlock(p);
|
||||
return v;
|
||||
}
|
||||
|
||||
void *pool_get(pool *p, unsigned int idx)
|
||||
{
|
||||
return p->num <= idx ? NULL : p->array[idx];
|
||||
}
|
||||
|
||||
void *pool_iter_next(pool *p)
|
||||
{
|
||||
if (p->num <= p->idx)
|
||||
return NULL;
|
||||
|
||||
void *v = p->array[p->idx];
|
||||
p->idx++;
|
||||
return v;
|
||||
}
|
||||
|
||||
void *pool_iter_next_lock(pool *p)
|
||||
{
|
||||
void *v = NULL;
|
||||
pool_lock(p);
|
||||
v = pool_iter_next(p);
|
||||
pool_unlock(p);
|
||||
return v;
|
||||
}
|
||||
|
||||
bool pool_iter_has_next_lock(pool *p)
|
||||
{
|
||||
bool next_exist;
|
||||
pool_lock(p);
|
||||
next_exist = (p->idx < p->num);
|
||||
pool_unlock(p);
|
||||
return next_exist;
|
||||
}
|
||||
94
src/pool.h
Normal file
94
src/pool.h
Normal file
@@ -0,0 +1,94 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _POOL_H_
|
||||
#define _POOL_H_
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <atomic.h>
|
||||
|
||||
/* A pool like a stack with an iterator walking from the bottom to the
|
||||
* top. The memory foot print for a pool never shrinks. Thus this is
|
||||
* not suitable for long-term uses. */
|
||||
|
||||
struct pool_struct {
|
||||
void **array;
|
||||
size_t len; /* length of array */
|
||||
size_t num; /* number of items in the array */
|
||||
size_t idx; /* index used dy iter */
|
||||
lock lock;
|
||||
};
|
||||
|
||||
typedef struct pool_struct pool;
|
||||
|
||||
/* allocate a new pool */
|
||||
pool *pool_new(void);
|
||||
|
||||
/* func type applied to each item in a pool */
|
||||
typedef void (*pool_map_f)(void *v);
|
||||
|
||||
/* apply f, which free an item, to all items and set num to 0 */
|
||||
void pool_zeroize(pool *p, pool_map_f f);
|
||||
|
||||
/* free pool->array and pool */
|
||||
void pool_free(pool *p);
|
||||
|
||||
/* free pool->array and pool after applying f to all items in p->array */
|
||||
void pool_destroy(pool *p, pool_map_f f);
|
||||
|
||||
#define pool_lock(p) LOCK_ACQUIRE(&(p->lock))
|
||||
#define pool_unlock(p) LOCK_RELEASE()
|
||||
|
||||
/*
|
||||
* pool_push() pushes *v to pool *p. pool_push_lock() does this while
|
||||
* locking *p.
|
||||
*/
|
||||
int pool_push(pool *p, void *v);
|
||||
int pool_push_lock(pool *p, void *v);
|
||||
|
||||
/*
|
||||
* pool_pop() pops the last *v pushed to *p. pool_pop_lock() does this
|
||||
* while locking *p.
|
||||
*/
|
||||
void *pool_pop(pool *p);
|
||||
void *pool_pop_lock(pool *p);
|
||||
|
||||
/* pool_get() returns value indexed by idx */
|
||||
void *pool_get(pool *p, unsigned int idx);
|
||||
|
||||
#define pool_size(p) ((p)->num)
|
||||
#define pool_is_empty(p) (pool_size(p) == 0)
|
||||
|
||||
/*
|
||||
* pool->idx indicates next *v in an iteration. This has two
|
||||
* use-cases.
|
||||
*
|
||||
* (1) A simple list: just a single thread has a pool, and the thread
|
||||
* can call pool_iter_for_each() for the pool (not thread safe).
|
||||
*
|
||||
* (2) A thread-safe queue: one thread initializes the iterator for a
|
||||
* pool by pool_iter_init(). Then, multiple threads get a next *v
|
||||
* concurrently by pool_iter_next_lock(), which means dequeuing. At
|
||||
* this time, other thread can add new *v by pool_push_lock(), which
|
||||
* means enqueuing. During this, other threads must not intercept the
|
||||
* pool by pool_iter_* functions.
|
||||
*/
|
||||
|
||||
#define pool_iter_init(p) (p->idx = 0)
|
||||
void *pool_iter_next(pool *p);
|
||||
void *pool_iter_next_lock(pool *p);
|
||||
|
||||
/* pool_iter_has_next_lock() returns true if pool_iter_next(_lock)
|
||||
* function will retrun a next value, otherwise false, which means
|
||||
* there is no more values in this iteration. */
|
||||
bool pool_iter_has_next_lock(pool *p);
|
||||
|
||||
#define pool_iter_for_each(p, v) \
|
||||
pool_iter_init(p); \
|
||||
for (v = pool_iter_next(p); v != NULL; v = pool_iter_next(p))
|
||||
|
||||
#define pool_for_each(p, v, idx) \
|
||||
idx = 0; \
|
||||
for (v = pool_get(p, idx); v != NULL; v = pool_get(p, ++idx))
|
||||
|
||||
#endif /* _POOL_H_ */
|
||||
18
src/print.c
Normal file
18
src/print.c
Normal file
@@ -0,0 +1,18 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
|
||||
#include <print.h>
|
||||
|
||||
/* message print functions */
|
||||
static int __print_severity = MSCP_SEVERITY_WARN;
|
||||
|
||||
void set_print_severity(int serverity)
|
||||
{
|
||||
if (serverity < 0)
|
||||
__print_severity = -1; /* no print */
|
||||
__print_severity = serverity;
|
||||
}
|
||||
|
||||
int get_print_severity()
|
||||
{
|
||||
return __print_severity;
|
||||
}
|
||||
30
src/print.h
Normal file
30
src/print.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _PRINT_H_
|
||||
#define _PRINT_H_
|
||||
|
||||
#include <libgen.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <mscp.h>
|
||||
|
||||
/* message print. printed messages are passed to application via msg_fd */
|
||||
void set_print_severity(int severity);
|
||||
int get_print_severity();
|
||||
|
||||
#define __print(fp, severity, fmt, ...) \
|
||||
do { \
|
||||
if (severity <= get_print_severity()) { \
|
||||
fprintf(fp, "\r\033[K" fmt "\n", ##__VA_ARGS__); \
|
||||
fflush(fp); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define pr_err(fmt, ...) __print(stderr, MSCP_SEVERITY_ERR, fmt, ##__VA_ARGS__)
|
||||
#define pr_warn(fmt, ...) __print(stderr, MSCP_SEVERITY_WARN, fmt, ##__VA_ARGS__)
|
||||
#define pr_notice(fmt, ...) __print(stdout, MSCP_SEVERITY_NOTICE, fmt, ##__VA_ARGS__)
|
||||
#define pr_info(fmt, ...) __print(stdout, MSCP_SEVERITY_INFO, fmt, ##__VA_ARGS__)
|
||||
#define pr_debug(fmt, ...) __print(stdout, MSCP_SEVERITY_DEBUG, fmt, ##__VA_ARGS__)
|
||||
|
||||
#endif /* _PRINT_H_ */
|
||||
499
src/pymscp.c
499
src/pymscp.c
@@ -1,499 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#define PY_SSIZE_T_CLEAN
|
||||
#include <Python.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <mscp.h>
|
||||
|
||||
/*
|
||||
* This is a wrapper for python binding of libmscp. setup.py builds
|
||||
* pymscp.c after libmscp was built, and setup.py installs pymscp
|
||||
* modlue and mscp python module (mscp/mscp.py), which is a warpper
|
||||
* for pymscp.
|
||||
*/
|
||||
|
||||
#define MAX_MSCP_INSTS 64
|
||||
|
||||
/* XXX: cut corners */
|
||||
struct instance {
|
||||
struct mscp_opts mo;
|
||||
struct mscp_ssh_opts so;
|
||||
struct mscp *m;
|
||||
};
|
||||
|
||||
struct instance *insts[MAX_MSCP_INSTS];
|
||||
|
||||
static int add_instance(struct instance *i)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < MAX_MSCP_INSTS; n++) {
|
||||
if (insts[n] == NULL) {
|
||||
insts[n] = i;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
return -1; /* full of mscp instances */
|
||||
}
|
||||
|
||||
static struct instance *get_instance(unsigned long long addr)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < MAX_MSCP_INSTS; n++) {
|
||||
if (insts[n] == (void *)addr)
|
||||
return insts[n];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static struct mscp *get_mscp(unsigned long long addr)
|
||||
{
|
||||
struct instance *i = get_instance(addr);
|
||||
|
||||
if (!i)
|
||||
return NULL;
|
||||
return i->m;
|
||||
}
|
||||
|
||||
static int release_instance(struct instance *i)
|
||||
{
|
||||
int n;
|
||||
for (n = 0; n < MAX_MSCP_INSTS; n++) {
|
||||
if (insts[n] == i) {
|
||||
insts[n] = NULL;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
free(i);
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
/* wrapper functions */
|
||||
|
||||
static PyObject *wrap_mscp_init(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
/*
|
||||
* Initialize struct mscp with options. wrap_mscp_init
|
||||
* receives all the arguments with keywords.
|
||||
*/
|
||||
|
||||
char *remote;
|
||||
char *keywords[] = {
|
||||
"remote", /* const char * */
|
||||
"direction", /* int, MSCP_DIRECTION_L2R or MSCP_DIRECTION_R2L */
|
||||
|
||||
/* mscp_opts */
|
||||
"nr_threads", /* int */
|
||||
"nr_ahead", /* int */
|
||||
|
||||
"min_chunk_sz", /* unsigned long */
|
||||
"max_chunk_sz", /* unsigned long */
|
||||
"buf_sz", /* unsigned long */
|
||||
|
||||
"coremask", /* const char * */
|
||||
|
||||
"max_startups", /* int */
|
||||
"interval", /* int */
|
||||
"severity", /* int, MSCP_SERVERITY_* */
|
||||
"msg_fd", /* int */
|
||||
|
||||
/* mscp_ssh_opts */
|
||||
"login_name", /* const char * */
|
||||
"port", /* const char * */
|
||||
"config", /* const char * */
|
||||
"identity", /* const char * */
|
||||
|
||||
"cipher", /* const char * */
|
||||
"hmac", /* const char * */
|
||||
"compress", /* const char * */
|
||||
"ccalgo", /* const char * */
|
||||
"password", /* const char * */
|
||||
"passphrase", /* const char * */
|
||||
|
||||
"debug_level", /* int */
|
||||
"no_hostkey_check", /* bool */
|
||||
"enable_nagle", /* bool */
|
||||
NULL,
|
||||
};
|
||||
const char *fmt = "si" "|" "ii" "kkk" "s" "iiii" "ssss" "ssssss" "ipp";
|
||||
char *coremask = NULL;
|
||||
char *login_name = NULL, *port = NULL, *config = NULL, *identity = NULL;
|
||||
char *cipher = NULL, *hmac = NULL, *compress = NULL, *ccalgo = NULL;
|
||||
char *password = NULL, *passphrase = NULL;
|
||||
|
||||
struct instance *i;
|
||||
int direction;
|
||||
int ret;
|
||||
|
||||
i = malloc(sizeof(*i));
|
||||
if (!i) {
|
||||
PyErr_Format(PyExc_RuntimeError, strerror(errno));
|
||||
return NULL;
|
||||
}
|
||||
|
||||
memset(i, 0, sizeof(*i));
|
||||
|
||||
ret = PyArg_ParseTupleAndKeywords(args, kw, fmt, keywords,
|
||||
&remote,
|
||||
&direction,
|
||||
&i->mo.nr_threads,
|
||||
&i->mo.nr_ahead,
|
||||
&i->mo.min_chunk_sz,
|
||||
&i->mo.max_chunk_sz,
|
||||
&i->mo.buf_sz,
|
||||
&coremask,
|
||||
&i->mo.max_startups,
|
||||
&i->mo.interval,
|
||||
&i->mo.severity,
|
||||
&i->mo.msg_fd,
|
||||
&login_name,
|
||||
&port,
|
||||
&config,
|
||||
&identity,
|
||||
&cipher,
|
||||
&hmac,
|
||||
&compress,
|
||||
&ccalgo,
|
||||
&password,
|
||||
&passphrase,
|
||||
&i->so.debug_level,
|
||||
&i->so.no_hostkey_check,
|
||||
&i->so.enable_nagle);
|
||||
|
||||
if (!ret)
|
||||
return NULL;
|
||||
|
||||
if (coremask)
|
||||
strncpy(i->mo.coremask, coremask, MSCP_MAX_COREMASK_STR - 1);
|
||||
if (login_name)
|
||||
strncpy(i->so.login_name, login_name, MSCP_SSH_MAX_LOGIN_NAME - 1);
|
||||
if (port)
|
||||
strncpy(i->so.port, port, MSCP_SSH_MAX_PORT_STR - 1);
|
||||
if (config)
|
||||
strncpy(i->so.config, config, PATH_MAX - 1);
|
||||
if (identity)
|
||||
strncpy(i->so.identity, identity, MSCP_SSH_MAX_IDENTITY_PATH - 1);
|
||||
if (cipher)
|
||||
strncpy(i->so.cipher, cipher, MSCP_SSH_MAX_CIPHER_STR - 1);
|
||||
if (hmac)
|
||||
strncpy(i->so.hmac, hmac, MSCP_SSH_MAX_HMAC_STR - 1);
|
||||
if (compress)
|
||||
strncpy(i->so.compress, compress, MSCP_SSH_MAX_COMP_STR - 1);
|
||||
if (ccalgo)
|
||||
strncpy(i->so.ccalgo, ccalgo, MSCP_SSH_MAX_CCALGO_STR - 1);
|
||||
if (password)
|
||||
strncpy(i->so.password, password, MSCP_SSH_MAX_PASSWORD - 1);
|
||||
if (passphrase)
|
||||
strncpy(i->so.passphrase, passphrase, MSCP_SSH_MAX_PASSPHRASE - 1);
|
||||
|
||||
i->m = mscp_init(remote, direction, &i->mo, &i->so);
|
||||
if (!i->m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "%s", mscp_get_error());
|
||||
free(i);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (add_instance(i) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, "too many mscp isntances");
|
||||
mscp_free(i->m);
|
||||
free(i);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("K", (unsigned long long)i);
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_connect(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mscp_connect(m) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, mscp_get_error());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_add_src_path(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", "src_path", NULL };
|
||||
unsigned long long addr;
|
||||
char *src_path;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "Ks", keywords, &addr, &src_path))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mscp_add_src_path(m, src_path) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, mscp_get_error());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_set_dst_path(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", "dst_path", NULL };
|
||||
unsigned long long addr;
|
||||
char *dst_path;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "Ks", keywords, &addr, &dst_path))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mscp_set_dst_path(m, dst_path) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, mscp_get_error());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_scan(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mscp_scan(m) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, mscp_get_error());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_start(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mscp_start(m) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, mscp_get_error());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_stop(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mscp_stop(m);
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_join(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (mscp_join(m) < 0) {
|
||||
PyErr_Format(PyExc_RuntimeError, mscp_get_error());
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_get_stats(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp_stats s;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mscp_get_stats(m, &s);
|
||||
|
||||
return Py_BuildValue("KKO", s.total, s.done, PyBool_FromLong(s.finished));
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_cleanup(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct mscp *m;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
m = get_mscp(addr);
|
||||
if (!m) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mscp_cleanup(m);
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyObject *wrap_mscp_free(PyObject *self, PyObject *args, PyObject *kw)
|
||||
{
|
||||
char *keywords[] = { "m", NULL };
|
||||
unsigned long long addr;
|
||||
struct instance *i;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kw, "K", keywords, &addr))
|
||||
return NULL;
|
||||
|
||||
i = get_instance(addr);
|
||||
if (!i) {
|
||||
PyErr_Format(PyExc_RuntimeError, "invalid mscp instance address");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
mscp_free(i->m);
|
||||
release_instance(i);
|
||||
|
||||
return Py_BuildValue("");
|
||||
}
|
||||
|
||||
static PyMethodDef pymscpMethods[] = {
|
||||
{
|
||||
"mscp_init", (PyCFunction)wrap_mscp_init,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_connect", (PyCFunction)wrap_mscp_connect,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_add_src_path", (PyCFunction)wrap_mscp_add_src_path,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_set_dst_path", (PyCFunction)wrap_mscp_set_dst_path,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_scan", (PyCFunction)wrap_mscp_scan,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_start", (PyCFunction)wrap_mscp_start,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_stop", (PyCFunction)wrap_mscp_stop,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_join", (PyCFunction)wrap_mscp_join,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_get_stats", (PyCFunction)wrap_mscp_get_stats,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_cleanup", (PyCFunction)wrap_mscp_cleanup,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{
|
||||
"mscp_free", (PyCFunction)wrap_mscp_free,
|
||||
METH_VARARGS | METH_KEYWORDS, NULL
|
||||
},
|
||||
{ NULL, NULL, 0, NULL },
|
||||
};
|
||||
|
||||
static PyModuleDef pymscpModule = {
|
||||
PyModuleDef_HEAD_INIT, "pymscp", NULL, -1, pymscpMethods,
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit_pymscp(void) {
|
||||
PyObject *mod = PyModule_Create(&pymscpModule);
|
||||
|
||||
PyModule_AddIntConstant(mod, "LOCAL2REMOTE", MSCP_DIRECTION_L2R);
|
||||
PyModule_AddIntConstant(mod, "REMOTE2LOCAL", MSCP_DIRECTION_R2L);
|
||||
PyModule_AddIntConstant(mod, "SEVERITY_NONE", MSCP_SEVERITY_NONE);
|
||||
PyModule_AddIntConstant(mod, "SEVERITY_ERR", MSCP_SEVERITY_ERR);
|
||||
PyModule_AddIntConstant(mod, "SEVERITY_WARN", MSCP_SEVERITY_WARN);
|
||||
PyModule_AddIntConstant(mod, "SEVERITY_NOTICE", MSCP_SEVERITY_NOTICE);
|
||||
PyModule_AddIntConstant(mod, "SEVERITY_INFO", MSCP_SEVERITY_INFO);
|
||||
PyModule_AddIntConstant(mod, "SEVERITY_DEBUG", MSCP_SEVERITY_DEBUG);
|
||||
|
||||
return mod;
|
||||
}
|
||||
|
||||
211
src/ssh.c
211
src/ssh.c
@@ -4,70 +4,73 @@
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "libssh/callbacks.h"
|
||||
|
||||
#include <ssh.h>
|
||||
#include <util.h>
|
||||
#include <message.h>
|
||||
#include <mscp.h>
|
||||
#include <strerrno.h>
|
||||
|
||||
#include "libssh/callbacks.h"
|
||||
#include "libssh/options.h"
|
||||
|
||||
static int ssh_verify_known_hosts(ssh_session session);
|
||||
|
||||
|
||||
#define is_specified(s) (strlen(s) > 0)
|
||||
static int ssh_authenticate_kbdint(ssh_session session);
|
||||
|
||||
static int ssh_set_opts(ssh_session ssh, struct mscp_ssh_opts *opts)
|
||||
{
|
||||
ssh_set_log_level(opts->debug_level);
|
||||
|
||||
if (is_specified(opts->login_name) &&
|
||||
if (opts->login_name &&
|
||||
ssh_options_set(ssh, SSH_OPTIONS_USER, opts->login_name) < 0) {
|
||||
mscp_set_error("failed to set login name");
|
||||
priv_set_errv("failed to set login name");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_specified(opts->port) &&
|
||||
ssh_options_set(ssh, SSH_OPTIONS_PORT_STR, opts->port) < 0) {
|
||||
mscp_set_error("failed to set port number");
|
||||
if (opts->port && ssh_options_set(ssh, SSH_OPTIONS_PORT_STR, opts->port) < 0) {
|
||||
priv_set_errv("failed to set port number");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_specified(opts->identity) &&
|
||||
if (opts->ai_family &&
|
||||
ssh_options_set(ssh, SSH_OPTIONS_AI_FAMILY, &opts->ai_family) < 0) {
|
||||
priv_set_errv("failed to set address family");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (opts->identity &&
|
||||
ssh_options_set(ssh, SSH_OPTIONS_IDENTITY, opts->identity) < 0) {
|
||||
mscp_set_error("failed to set identity");
|
||||
priv_set_errv("failed to set identity");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_specified(opts->cipher)) {
|
||||
if (opts->cipher) {
|
||||
if (ssh_options_set(ssh, SSH_OPTIONS_CIPHERS_C_S, opts->cipher) < 0) {
|
||||
mscp_set_error("failed to set cipher for client to server");
|
||||
priv_set_errv("failed to set cipher for client to server");
|
||||
return -1;
|
||||
}
|
||||
if (ssh_options_set(ssh, SSH_OPTIONS_CIPHERS_S_C, opts->cipher) < 0) {
|
||||
mscp_set_error("failed to set cipher for server to client");
|
||||
priv_set_errv("failed to set cipher for server to client");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_specified(opts->hmac)) {
|
||||
if (opts->hmac) {
|
||||
if (ssh_options_set(ssh, SSH_OPTIONS_HMAC_C_S, opts->hmac) < 0) {
|
||||
mscp_set_error("failed to set hmac for client to server");
|
||||
priv_set_errv("failed to set hmac for client to server");
|
||||
return -1;
|
||||
}
|
||||
if (ssh_options_set(ssh, SSH_OPTIONS_HMAC_S_C, opts->hmac) < 0) {
|
||||
mscp_set_error("failed to set hmac for server to client");
|
||||
priv_set_errv("failed to set hmac for server to client");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_specified(opts->compress) &&
|
||||
if (opts->compress &&
|
||||
ssh_options_set(ssh, SSH_OPTIONS_COMPRESSION, opts->compress) < 0) {
|
||||
mscp_set_error("failed to enable ssh compression");
|
||||
priv_set_errv("failed to enable ssh compression");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (is_specified(opts->ccalgo) &&
|
||||
ssh_options_set(ssh, SSH_OPTIONS_CCALGO, opts->ccalgo) < 0) {
|
||||
mscp_set_error("failed to set cclago");
|
||||
if (opts->ccalgo && ssh_options_set(ssh, SSH_OPTIONS_CCALGO, opts->ccalgo) < 0) {
|
||||
priv_set_errv("failed to set cclago");
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -75,17 +78,37 @@ static int ssh_set_opts(ssh_session ssh, struct mscp_ssh_opts *opts)
|
||||
if (!opts->enable_nagle) {
|
||||
int v = 1;
|
||||
if (ssh_options_set(ssh, SSH_OPTIONS_NODELAY, &v) < 0) {
|
||||
mscp_set_error("failed to set TCP_NODELAY");
|
||||
priv_set_errv("failed to set TCP_NODELAY");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_specified(opts->config) &&
|
||||
ssh_options_parse_config(ssh, opts->config) < 0) {
|
||||
mscp_set_error("failed to parse ssh_config: %s", opts->config);
|
||||
if (opts->config && ssh_options_parse_config(ssh, opts->config) < 0) {
|
||||
priv_set_errv("failed to parse ssh_config: %s", opts->config);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (opts->proxyjump) {
|
||||
char buf[256];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
snprintf(buf, sizeof(buf), "proxyjump=%s", opts->proxyjump);
|
||||
if (ssh_config_parse_string(ssh, buf) != SSH_OK) {
|
||||
priv_set_errv("failed to set ssh option: %s", buf);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (opts->options) {
|
||||
int n;
|
||||
for (n = 0; opts->options[n]; n++) {
|
||||
if (ssh_config_parse_string(ssh, opts->options[n]) != SSH_OK) {
|
||||
priv_set_errv("failed to set ssh option: %s",
|
||||
opts->options[n]);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -100,21 +123,27 @@ static int ssh_authenticate(ssh_session ssh, struct mscp_ssh_opts *opts)
|
||||
return 0;
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_NONE &&
|
||||
ssh_userauth_none(ssh, NULL) == SSH_AUTH_SUCCESS)
|
||||
return 0;
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_PUBLICKEY) {
|
||||
char *p = is_specified(opts->passphrase) ? opts->passphrase : NULL;
|
||||
char *p = opts->passphrase ? opts->passphrase : NULL;
|
||||
if (ssh_userauth_publickey_auto(ssh, NULL, p) == SSH_AUTH_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_PASSWORD) {
|
||||
if (!is_specified(opts->password)) {
|
||||
if (ssh_getpass("Password: ", opts->password,
|
||||
MSCP_SSH_MAX_PASSWORD, 0, 0) < 0) {
|
||||
if (!opts->password) {
|
||||
char buf[128] = {};
|
||||
if (ssh_getpass("Password: ", buf, sizeof(buf), 0, 0) < 0) {
|
||||
priv_set_errv("ssh_getpass failed");
|
||||
return -1;
|
||||
}
|
||||
if (!(opts->password = strndup(buf, sizeof(buf)))) {
|
||||
priv_set_errv("strndup: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -123,6 +152,12 @@ static int ssh_authenticate(ssh_session ssh, struct mscp_ssh_opts *opts)
|
||||
return 0;
|
||||
}
|
||||
|
||||
auth_bit_mask = ssh_userauth_list(ssh, NULL);
|
||||
if (auth_bit_mask & SSH_AUTH_METHOD_INTERACTIVE) {
|
||||
if (ssh_authenticate_kbdint(ssh) == SSH_AUTH_SUCCESS)
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -136,15 +171,21 @@ static int ssh_cache_passphrase(const char *prompt, char *buf, size_t len, int e
|
||||
* second time or after because cached passphrase is passed
|
||||
* to ssh_userauth_publickey_auto(). */
|
||||
|
||||
/* ToDo: use
|
||||
* ssh_userauth_publickey_auto_get_current_identity() to print
|
||||
* id for which we ask passphrase */
|
||||
|
||||
if (ssh_getpass("Passphrase: ", buf, len, echo, verify) < 0)
|
||||
return -1;
|
||||
|
||||
/* cache the passphrase */
|
||||
if (strlen(buf) > MSCP_SSH_MAX_PASSPHRASE - 1) {
|
||||
pr_warn("sorry, passphrase is too long to cache...\n");
|
||||
return 0;
|
||||
if (opts->passphrase)
|
||||
free(opts->passphrase);
|
||||
|
||||
if (!(opts->passphrase = strndup(buf, len))) {
|
||||
priv_set_errv("strndup: %s", strerrno());
|
||||
return -1;
|
||||
}
|
||||
strncpy(opts->passphrase, buf, MSCP_SSH_MAX_PASSPHRASE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -163,7 +204,7 @@ static ssh_session ssh_init_session(const char *sshdst, struct mscp_ssh_opts *op
|
||||
ssh_set_callbacks(ssh, &cb);
|
||||
|
||||
if (ssh_options_set(ssh, SSH_OPTIONS_HOST, sshdst) != SSH_OK) {
|
||||
mscp_set_error("failed to set destination host");
|
||||
priv_set_errv("failed to set destination host");
|
||||
goto free_out;
|
||||
}
|
||||
|
||||
@@ -171,16 +212,17 @@ static ssh_session ssh_init_session(const char *sshdst, struct mscp_ssh_opts *op
|
||||
goto free_out;
|
||||
|
||||
if (ssh_connect(ssh) != SSH_OK) {
|
||||
mscp_set_error("failed to connect ssh server: %s", ssh_get_error(ssh));
|
||||
priv_set_errv("failed to connect ssh server: %s", ssh_get_error(ssh));
|
||||
goto free_out;
|
||||
}
|
||||
|
||||
if (ssh_authenticate(ssh, opts) != 0) {
|
||||
mscp_set_error("authentication failed: %s", ssh_get_error(ssh));
|
||||
priv_set_errv("authentication failed: %s", ssh_get_error(ssh));
|
||||
goto disconnect_out;
|
||||
}
|
||||
|
||||
if (!opts->no_hostkey_check && ssh_verify_known_hosts(ssh) != 0) {
|
||||
if (ssh_verify_known_hosts(ssh) != 0) {
|
||||
priv_set_errv("ssh_veriy_known_hosts failed");
|
||||
goto disconnect_out;
|
||||
}
|
||||
|
||||
@@ -198,20 +240,18 @@ sftp_session ssh_init_sftp_session(const char *sshdst, struct mscp_ssh_opts *opt
|
||||
sftp_session sftp;
|
||||
ssh_session ssh = ssh_init_session(sshdst, opts);
|
||||
|
||||
if (!ssh) {
|
||||
if (!ssh)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
sftp = sftp_new(ssh);
|
||||
if (!sftp) {
|
||||
mscp_set_error("failed to allocate sftp session: %s",
|
||||
ssh_get_error(ssh));
|
||||
priv_set_errv("failed to allocate sftp session: %s", ssh_get_error(ssh));
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
if (sftp_init(sftp) != SSH_OK) {
|
||||
mscp_set_error("failed to initialize sftp session: err code %d",
|
||||
sftp_get_error(sftp));
|
||||
priv_set_errv("failed to initialize sftp session: err code %d",
|
||||
sftp_get_error(sftp));
|
||||
goto err_out;
|
||||
}
|
||||
|
||||
@@ -222,7 +262,6 @@ err_out:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
/* copied from https://api.libssh.org/stable/libssh_tutor_guided_tour.html*/
|
||||
static int ssh_verify_known_hosts(ssh_session session)
|
||||
{
|
||||
@@ -241,10 +280,7 @@ static int ssh_verify_known_hosts(ssh_session session)
|
||||
return -1;
|
||||
}
|
||||
|
||||
rc = ssh_get_publickey_hash(srv_pubkey,
|
||||
SSH_PUBLICKEY_HASH_SHA1,
|
||||
&hash,
|
||||
&hlen);
|
||||
rc = ssh_get_publickey_hash(srv_pubkey, SSH_PUBLICKEY_HASH_SHA1, &hash, &hlen);
|
||||
ssh_key_free(srv_pubkey);
|
||||
if (rc < 0) {
|
||||
return -1;
|
||||
@@ -265,8 +301,9 @@ static int ssh_verify_known_hosts(ssh_session session)
|
||||
return -1;
|
||||
case SSH_KNOWN_HOSTS_OTHER:
|
||||
fprintf(stderr, "The host key for this server was not found but an other"
|
||||
"type of key exists.\n");
|
||||
fprintf(stderr, "An attacker might change the default server key to"
|
||||
"type of key exists.\n");
|
||||
fprintf(stderr,
|
||||
"An attacker might change the default server key to"
|
||||
"confuse your client into thinking the key does not exist\n");
|
||||
ssh_clean_pubkey_hash(&hash);
|
||||
|
||||
@@ -274,7 +311,7 @@ static int ssh_verify_known_hosts(ssh_session session)
|
||||
case SSH_KNOWN_HOSTS_NOT_FOUND:
|
||||
fprintf(stderr, "Could not find known host file.\n");
|
||||
fprintf(stderr, "If you accept the host key here, the file will be"
|
||||
"automatically created.\n");
|
||||
"automatically created.\n");
|
||||
|
||||
/* FALL THROUGH to SSH_SERVER_NOT_KNOWN behavior */
|
||||
|
||||
@@ -297,13 +334,13 @@ static int ssh_verify_known_hosts(ssh_session session)
|
||||
|
||||
rc = ssh_session_update_known_hosts(session);
|
||||
if (rc < 0) {
|
||||
fprintf(stderr, "Error %s\n", strerror(errno));
|
||||
priv_set_errv("%s", ssh_get_error(session));
|
||||
return -1;
|
||||
}
|
||||
|
||||
break;
|
||||
case SSH_KNOWN_HOSTS_ERROR:
|
||||
fprintf(stderr, "Error %s", ssh_get_error(session));
|
||||
fprintf(stderr, "known hosts error: %s", ssh_get_error(session));
|
||||
ssh_clean_pubkey_hash(&hash);
|
||||
return -1;
|
||||
}
|
||||
@@ -312,6 +349,54 @@ static int ssh_verify_known_hosts(ssh_session session)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ssh_authenticate_kbdint(ssh_session ssh)
|
||||
{
|
||||
/* Copied and bit modified from
|
||||
* https://api.libssh.org/stable/libssh_tutor_authentication.html */
|
||||
int rc;
|
||||
|
||||
rc = ssh_userauth_kbdint(ssh, NULL, NULL);
|
||||
while (rc == SSH_AUTH_INFO) {
|
||||
const char *name, *instruction;
|
||||
int nprompts, iprompt;
|
||||
|
||||
name = ssh_userauth_kbdint_getname(ssh);
|
||||
instruction = ssh_userauth_kbdint_getinstruction(ssh);
|
||||
nprompts = ssh_userauth_kbdint_getnprompts(ssh);
|
||||
|
||||
if (strlen(name) > 0)
|
||||
printf("%s\n", name);
|
||||
if (strlen(instruction) > 0)
|
||||
printf("%s\n", instruction);
|
||||
for (iprompt = 0; iprompt < nprompts; iprompt++) {
|
||||
const char *prompt;
|
||||
char echo;
|
||||
|
||||
prompt = ssh_userauth_kbdint_getprompt(ssh, iprompt, &echo);
|
||||
if (echo) {
|
||||
char buf[128], *ptr;
|
||||
|
||||
printf("%s", prompt);
|
||||
if (fgets(buf, sizeof(buf), stdin) == NULL)
|
||||
return SSH_AUTH_ERROR;
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
if ((ptr = strchr(buf, '\n')) != NULL)
|
||||
*ptr = '\0';
|
||||
if (ssh_userauth_kbdint_setanswer(ssh, iprompt, buf) < 0)
|
||||
return SSH_AUTH_ERROR;
|
||||
memset(buf, 0, strlen(buf));
|
||||
} else {
|
||||
char *ptr;
|
||||
ptr = getpass(prompt);
|
||||
if (ssh_userauth_kbdint_setanswer(ssh, iprompt, ptr) < 0)
|
||||
return SSH_AUTH_ERROR;
|
||||
}
|
||||
}
|
||||
rc = ssh_userauth_kbdint(ssh, NULL, NULL);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
||||
void ssh_sftp_close(sftp_session sftp)
|
||||
{
|
||||
ssh_session ssh = sftp_ssh(sftp);
|
||||
@@ -322,3 +407,13 @@ void ssh_sftp_close(sftp_session sftp)
|
||||
ssh_disconnect(ssh);
|
||||
ssh_free(ssh);
|
||||
}
|
||||
|
||||
const char **mscp_ssh_ciphers(void)
|
||||
{
|
||||
return ssh_ciphers();
|
||||
}
|
||||
|
||||
const char **mscp_ssh_hmacs(void)
|
||||
{
|
||||
return ssh_hmacs();
|
||||
}
|
||||
|
||||
36
src/strerrno.c
Normal file
36
src/strerrno.c
Normal file
@@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <strerrno.h>
|
||||
|
||||
#define STRERRNO_TLS_BUFSIZ 128
|
||||
__thread char tls_strerrno_buf[STRERRNO_TLS_BUFSIZ];
|
||||
|
||||
const char *strerrno(void)
|
||||
{
|
||||
snprintf(tls_strerrno_buf, sizeof(tls_strerrno_buf), "%s", "strerror_r error");
|
||||
strerror_r(errno, tls_strerrno_buf, sizeof(tls_strerrno_buf));
|
||||
return tls_strerrno_buf;
|
||||
}
|
||||
|
||||
#define PRIV_ERR_BUFSIZ (1 << 12)
|
||||
__thread char priv_err_buf[PRIV_ERR_BUFSIZ], internal[PRIV_ERR_BUFSIZ];
|
||||
|
||||
void priv_set_err(const char *fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
memset(internal, 0, sizeof(internal));
|
||||
va_start(va, fmt);
|
||||
vsnprintf(internal, sizeof(internal), fmt, va);
|
||||
va_end(va);
|
||||
snprintf(priv_err_buf, sizeof(priv_err_buf), "%s", internal);
|
||||
}
|
||||
|
||||
const char *priv_get_err()
|
||||
{
|
||||
return priv_err_buf;
|
||||
}
|
||||
36
src/strerrno.h
Normal file
36
src/strerrno.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _STRERRNO_
|
||||
#define _STRERRNO_
|
||||
|
||||
#include <libgen.h> /* basename() */
|
||||
|
||||
/**
|
||||
* strerrno() returns error message string corresponding to errno.
|
||||
* strerrno() is thread safe.
|
||||
*/
|
||||
const char *strerrno(void);
|
||||
|
||||
/**
|
||||
* priv_set_err() sets an error message into a thread-local private
|
||||
* buffer. This error message can be accessed via priv_get_err().
|
||||
*
|
||||
* The top-level function in a thread should print errors using
|
||||
* priv_get_err(), while lower-level functions should set error
|
||||
* messages using priv_set_err().
|
||||
*/
|
||||
void priv_set_err(const char *fmt, ...);
|
||||
|
||||
/**
|
||||
* priv_set_errv(), a wrapper for priv_set_err(), just adds filename,
|
||||
* line, and function name to the error message.
|
||||
*/
|
||||
#define priv_set_errv(fmt, ...) \
|
||||
priv_set_err("[%s:%d:%s] " fmt "\0", basename(__FILE__), __LINE__, __func__, \
|
||||
##__VA_ARGS__)
|
||||
|
||||
/**
|
||||
* priv_get_err() gets the error message sotred in the thread-local private buffer.
|
||||
*/
|
||||
const char *priv_get_err();
|
||||
|
||||
#endif /* _STRERRNO_ */
|
||||
39
src/util.h
39
src/util.h
@@ -1,39 +0,0 @@
|
||||
/* SPDX-License-Identifier: GPL-3.0-only */
|
||||
#ifndef _UTIL_H_
|
||||
#define _UTIL_H_
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
|
||||
|
||||
#define pr(fmt, ...) fprintf(stderr, fmt, ##__VA_ARGS__)
|
||||
|
||||
#define pr_info(fmt, ...) fprintf(stderr, "INFO:%s(): " fmt, \
|
||||
__func__, ##__VA_ARGS__)
|
||||
|
||||
#define pr_warn(fmt, ...) fprintf(stderr, "\x1b[1m\x1b[33m" \
|
||||
"WARN:%s():\x1b[0m " fmt, \
|
||||
__func__, ##__VA_ARGS__)
|
||||
|
||||
#define pr_err(fmt, ...) fprintf(stderr, "\x1b[1m\x1b[31m" \
|
||||
"ERR:%s:%d:%s():\x1b[0m " fmt, \
|
||||
basename(__FILE__), __LINE__, __func__, ##__VA_ARGS__)
|
||||
|
||||
#ifdef DEBUG
|
||||
#define pr_debug(fmt, ...) fprintf(stderr, "\x1b[1m\x1b[33m" \
|
||||
"DEBUG:%s():\x1b[0m " fmt, \
|
||||
__func__, ##__VA_ARGS__);
|
||||
#else
|
||||
#define pr_debug(fmt, ...)
|
||||
#endif
|
||||
|
||||
|
||||
#define min(a, b) (((a) > (b)) ? (b) : (a))
|
||||
#define max(a, b) (((a) > (b)) ? (a) : (b))
|
||||
|
||||
#endif /* _UTIL_H_ */
|
||||
361
test/test_e2e.py
361
test/test_e2e.py
@@ -6,22 +6,30 @@ test_e2e.py: End-to-End test for mscp executable.
|
||||
import platform
|
||||
import pytest
|
||||
import getpass
|
||||
import datetime
|
||||
import time
|
||||
import os
|
||||
import shutil
|
||||
|
||||
from subprocess import check_call, CalledProcessError, PIPE
|
||||
from subprocess import check_call, CalledProcessError
|
||||
from util import File, check_same_md5sum
|
||||
|
||||
|
||||
def run2ok(args):
|
||||
def run2ok(args, env = None, quiet = False):
|
||||
cmd = list(map(str, args))
|
||||
print("cmd: {}".format(" ".join(cmd)))
|
||||
check_call(cmd)
|
||||
if not quiet:
|
||||
print("cmd: {}".format(" ".join(cmd)))
|
||||
check_call(cmd, env = env)
|
||||
|
||||
def run2ng(args):
|
||||
def run2ng(args, env = None, timeout = None, quiet = False):
|
||||
if timeout:
|
||||
args = ["timeout", "-s", "INT", timeout] + args
|
||||
cmd = list(map(str, args))
|
||||
print("cmd: {}".format(" ".join(cmd)))
|
||||
with pytest.raises(CalledProcessError) as e:
|
||||
check_call(cmd)
|
||||
if not quiet:
|
||||
print("cmd: {}".format(" ".join(cmd)))
|
||||
with pytest.raises(CalledProcessError):
|
||||
check_call(cmd, env = env)
|
||||
|
||||
|
||||
|
||||
""" usage test """
|
||||
@@ -62,7 +70,7 @@ param_single_copy = [
|
||||
@pytest.mark.parametrize("src, dst", param_single_copy)
|
||||
def test_single_copy(mscp, src_prefix, dst_prefix, src, dst):
|
||||
src.make()
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src.path, dst_prefix + dst.path])
|
||||
run2ok([mscp, "-vvv", src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
@@ -71,7 +79,7 @@ def test_single_copy(mscp, src_prefix, dst_prefix, src, dst):
|
||||
def test_failed_to_copy_nonexistent_file(mscp, src_prefix, dst_prefix):
|
||||
src = "nonexistent_src"
|
||||
dst = "nonexistent_dst"
|
||||
run2ng([mscp, "-H", "-vvv", src_prefix + src, dst_prefix + dst])
|
||||
run2ng([mscp, "-vvv", src_prefix + src, dst_prefix + dst])
|
||||
|
||||
param_double_copy = [
|
||||
(File("src1", size = 1024 * 1024), File("src2", size = 1024 * 1024),
|
||||
@@ -83,7 +91,7 @@ param_double_copy = [
|
||||
def test_double_copy(mscp, src_prefix, dst_prefix, s1, s2, d1, d2):
|
||||
s1.make()
|
||||
s2.make()
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + s1.path, src_prefix + s2.path, dst_prefix + "dst"])
|
||||
run2ok([mscp, "-vvv", src_prefix + s1.path, src_prefix + s2.path, dst_prefix + "dst"])
|
||||
assert check_same_md5sum(s1, d1)
|
||||
assert check_same_md5sum(s2, d2)
|
||||
s1.cleanup()
|
||||
@@ -101,7 +109,7 @@ param_remote_v6_prefix = [
|
||||
def test_double_copy_with_ipv6_notation(mscp, src_prefix, dst_prefix, s1, s2, d1, d2):
|
||||
s1.make()
|
||||
s2.make()
|
||||
run2ok([mscp, "-H", "-vvv",
|
||||
run2ok([mscp, "-vvv",
|
||||
src_prefix + s1.path, src_prefix + s2.path, dst_prefix + "dst"])
|
||||
assert check_same_md5sum(s1, d1)
|
||||
assert check_same_md5sum(s2, d2)
|
||||
@@ -121,7 +129,7 @@ def test_double_copy_with_user_and_ipv6_notation(mscp, src_prefix, dst_prefix,
|
||||
s1, s2, d1, d2):
|
||||
s1.make()
|
||||
s2.make()
|
||||
run2ok([mscp, "-H", "-vvv",
|
||||
run2ok([mscp, "-vvv",
|
||||
src_prefix + s1.path, src_prefix + s2.path, dst_prefix + "dst"])
|
||||
assert check_same_md5sum(s1, d1)
|
||||
assert check_same_md5sum(s2, d2)
|
||||
@@ -161,11 +169,11 @@ def test_dir_copy(mscp, src_prefix, dst_prefix, src_dir, dst_dir, src, dst, twic
|
||||
for f in src:
|
||||
f.make()
|
||||
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src_dir, dst_prefix + dst_dir])
|
||||
run2ok([mscp, "-vvv", src_prefix + src_dir, dst_prefix + dst_dir])
|
||||
for sf, df in zip(src, dst):
|
||||
assert check_same_md5sum(sf, df)
|
||||
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src_dir, dst_prefix + dst_dir])
|
||||
run2ok([mscp, "-vvv", src_prefix + src_dir, dst_prefix + dst_dir])
|
||||
for sf, df in zip(src, twice):
|
||||
assert check_same_md5sum(sf, df)
|
||||
|
||||
@@ -186,7 +194,7 @@ param_dir_copy_single = [
|
||||
def test_dir_copy_single(mscp, src_prefix, dst_prefix, src_dir, dst_dir, src, dst):
|
||||
src.make()
|
||||
os.mkdir(dst_dir)
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src_dir, dst_prefix + dst_dir])
|
||||
run2ok([mscp, "-vvv", src_prefix + src_dir, dst_prefix + dst_dir])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
@@ -197,7 +205,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, "-H", "-vvv", src_prefix + src.path, dst_prefix + dst.path])
|
||||
run2ok([mscp, "-vvv", src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
|
||||
src.cleanup()
|
||||
@@ -212,7 +220,7 @@ def test_copy_file_under_root_to_dir(mscp, src_prefix, dst_prefix):
|
||||
src = File("/mscp-test-src", size = 1024).make()
|
||||
dst = File("/tmp/mscp-test-src")
|
||||
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src.path,
|
||||
run2ok([mscp, "-vvv", src_prefix + src.path,
|
||||
dst_prefix + os.path.dirname(dst.path)])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
@@ -224,7 +232,7 @@ def test_min_chunk(mscp, src_prefix, dst_prefix):
|
||||
src = File("src", size = 16 * 1024).make()
|
||||
dst = File("dst")
|
||||
|
||||
run2ok([mscp, "-H", "-vvv", "-s", 32768, src_prefix + src.path, dst_prefix + dst.path])
|
||||
run2ok([mscp, "-vvv", "-s", 32768, src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
|
||||
src.cleanup()
|
||||
@@ -261,7 +269,7 @@ def test_glob_src_path(mscp, src_prefix, dst_prefix,
|
||||
for src in srcs:
|
||||
src.make(size = 1024 * 1024)
|
||||
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src_glob_path, dst_prefix + dst_path])
|
||||
run2ok([mscp, "-vvv", src_prefix + src_glob_path, dst_prefix + dst_path])
|
||||
for src, dst in zip(srcs, dsts):
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
@@ -272,7 +280,7 @@ def test_thread_affinity(mscp, src_prefix, dst_prefix):
|
||||
src = File("src", size = 64 * 1024).make()
|
||||
dst = File("dst")
|
||||
|
||||
run2ok([mscp, "-H", "-vvv", "-n", 4, "-m", "0x01",
|
||||
run2ok([mscp, "-vvv", "-n", 4, "-m", "0x01",
|
||||
src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
|
||||
@@ -284,7 +292,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, "-H", "-vvv", src_prefix + src.path, dst_prefix + "dst/src"])
|
||||
run2ng([mscp, "-vvv", src_prefix + src.path, dst_prefix + "dst/src"])
|
||||
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
@@ -293,7 +301,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, "-H", "-vvv", src_prefix + src.path, dst_prefix + "dst"])
|
||||
run2ok([mscp, "-vvv", src_prefix + src.path, dst_prefix + "dst"])
|
||||
assert os.path.exists("dst")
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
@@ -302,7 +310,7 @@ def test_transfer_zero_bytes(mscp, src_prefix, dst_prefix):
|
||||
def test_override_dst_having_larger_size(mscp, src_prefix, dst_prefix):
|
||||
src = File("src", size = 1024 * 1024).make()
|
||||
dst = File("dst", size = 1024 * 1024 * 2).make()
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + src.path, dst_prefix + "dst"])
|
||||
run2ok([mscp, "-vvv", src_prefix + src.path, dst_prefix + "dst"])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
@@ -311,18 +319,118 @@ def test_override_dst_having_larger_size(mscp, src_prefix, dst_prefix):
|
||||
def test_dont_truncate_dst(mscp, src_prefix, dst_prefix):
|
||||
f = File("srcanddst", size = 1024 * 1024 * 128).make()
|
||||
md5_before = f.md5sum()
|
||||
run2ok([mscp, "-H", "-vvv", src_prefix + f.path, dst_prefix + f.path])
|
||||
run2ok([mscp, "-vvv", src_prefix + f.path, dst_prefix + f.path])
|
||||
md5_after = f.md5sum()
|
||||
assert md5_before == md5_after
|
||||
f.cleanup()
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
@pytest.mark.parametrize("src, dst", param_single_copy)
|
||||
def test_set_port(mscp, src_prefix, dst_prefix, src, dst):
|
||||
src.make()
|
||||
run2ng([mscp, "-H", "-vvv", "-p", 21, src_prefix + src.path, dst_prefix + dst.path])
|
||||
run2ng([mscp, "-H", "-vvv", "-P", 21, src_prefix + src.path, dst_prefix + dst.path])
|
||||
def test_copy_readonly_file(mscp, src_prefix, dst_prefix):
|
||||
"""When a source file permission is r--r--r--, if chmod(r--r--r--)
|
||||
runs first on the remote side, following truncate() and setutime()
|
||||
fail due to permission deneid. So, run chmod() after truncate()
|
||||
and setutime()
|
||||
|
||||
"""
|
||||
src = File("src", size = 1024 * 1024 * 128, perm = 0o444).make()
|
||||
dst = File("dst")
|
||||
run2ok([mscp, "-vvv", src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_dont_make_conns_more_than_chunks(mscp, src_prefix, dst_prefix):
|
||||
# copy 100 files with -n 20 -I 1 options. if mscp creates 20 SSH
|
||||
# connections although all files have been copied, it is error.
|
||||
srcs = []
|
||||
dsts = []
|
||||
for n in range(100):
|
||||
srcs.append(File("src/src-{:06d}".format(n), size=1024).make())
|
||||
dsts.append(File("dst/src-{:06d}".format(n)))
|
||||
start = time.time()
|
||||
run2ok([mscp, "-v", "-n", "20", "-I", "1",
|
||||
src_prefix + "src", dst_prefix + "dst"])
|
||||
end = time.time()
|
||||
for s, d in zip(srcs, dsts):
|
||||
assert check_same_md5sum(s, d)
|
||||
shutil.rmtree("src")
|
||||
shutil.rmtree("dst")
|
||||
assert((end - start) < 10)
|
||||
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_bwlimit(mscp, src_prefix, dst_prefix):
|
||||
"""Copy 100MB file with 100Mbps bitrate, this requires 8 seconds."""
|
||||
src = File("src", size = 100 * 1024 * 1024).make()
|
||||
dst = File("dst")
|
||||
|
||||
start = datetime.datetime.now().timestamp()
|
||||
run2ok([mscp, "-vvv", "-L", "100m", src_prefix + "src", dst_prefix + "dst"])
|
||||
end = datetime.datetime.now().timestamp()
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
assert end - start > 7
|
||||
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
@pytest.mark.parametrize("src, dst", param_single_copy)
|
||||
def test_set_port_ng(mscp, src_prefix, dst_prefix, src, dst):
|
||||
src.make()
|
||||
run2ng([mscp, "-vvv", "-P", 21, src_prefix + src.path, dst_prefix + dst.path])
|
||||
src.cleanup()
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
@pytest.mark.parametrize("src, dst", param_single_copy)
|
||||
def test_set_port_ok(mscp, src_prefix, dst_prefix, src, dst):
|
||||
src.make()
|
||||
run2ok([mscp, "-vvv", "-P", 8022, src_prefix + src.path, dst_prefix + dst.path])
|
||||
src.cleanup()
|
||||
|
||||
def test_v4only(mscp):
|
||||
src = File("src", size = 1024).make()
|
||||
dst = File("dst")
|
||||
dst_prefix = "localhost:{}/".format(os.getcwd())
|
||||
run2ok([mscp, "-vvv", "-4", src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
def test_v6only(mscp):
|
||||
src = File("src", size = 1024).make()
|
||||
dst = File("dst")
|
||||
dst_prefix = "ip6-localhost:{}/".format(os.getcwd())
|
||||
run2ok([mscp, "-vvv", "-6", src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
def test_v4_to_v6_should_fail(mscp):
|
||||
src = File("src", size = 1024).make()
|
||||
dst = File("dst")
|
||||
dst_prefix = "[::1]:{}/".format(os.getcwd())
|
||||
run2ng([mscp, "-vvv", "-4", src.path, dst_prefix + dst.path])
|
||||
src.cleanup()
|
||||
|
||||
def test_v6_to_v4_should_fail(mscp):
|
||||
src = File("src", size = 1024).make()
|
||||
dst = File("dst")
|
||||
dst_prefix = "127.0.0.1:{}/".format(os.getcwd())
|
||||
run2ng([mscp, "-vvv", "-6", src.path, dst_prefix + dst.path])
|
||||
src.cleanup()
|
||||
|
||||
def test_quiet_mode(capsys, mscp):
|
||||
src = File("src", size = 1024).make()
|
||||
dst = File("dst")
|
||||
dst_prefix = "127.0.0.1:{}/".format(os.getcwd())
|
||||
run2ok([mscp, "-vvv", "-q", src.path, dst_prefix + dst.path], quiet=True)
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
captured = capsys.readouterr()
|
||||
assert not captured.out
|
||||
assert not captured.err
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_set_conn_interval(mscp, src_prefix, dst_prefix):
|
||||
@@ -331,7 +439,7 @@ def test_set_conn_interval(mscp, src_prefix, dst_prefix):
|
||||
for x in range(500):
|
||||
srcs.append(File("src/file{}".format(x), size = 128).make())
|
||||
dsts.append(File("dst/file{}".format(x)))
|
||||
run2ok([mscp, "-H", "-vvv", "-I", 1, src_prefix + "src", dst_prefix + "dst"])
|
||||
run2ok([mscp, "-vvv", "-I", 1, src_prefix + "src", dst_prefix + "dst"])
|
||||
|
||||
for src, dst in zip(srcs, dsts):
|
||||
assert check_same_md5sum(src, dst)
|
||||
@@ -344,7 +452,7 @@ compressions = ["yes", "no", "none"]
|
||||
def test_compression(mscp, src_prefix, dst_prefix, compress):
|
||||
src = File("src", size = 1024 * 1024).make()
|
||||
dst = File("dst", size = 1024 * 1024 * 2).make()
|
||||
run2ok([mscp, "-H", "-vvv", "-C", compress, src_prefix + src.path, dst_prefix + "dst"])
|
||||
run2ok([mscp, "-vvv", "-C", compress, src_prefix + src.path, dst_prefix + "dst"])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
@@ -362,7 +470,7 @@ def test_ccalgo(mscp, src_prefix, dst_prefix):
|
||||
with open("/proc/sys/net/ipv4/tcp_allowed_congestion_control", "r") as f:
|
||||
algo = f.read().strip().split().pop()
|
||||
run = run2ok
|
||||
run([mscp, "-H", "-vvv", "-g", algo, src_prefix + src.path, dst_prefix + "dst"])
|
||||
run([mscp, "-vvv", "-g", algo, src_prefix + src.path, dst_prefix + "dst"])
|
||||
|
||||
|
||||
testhost = "mscptestlocalhost"
|
||||
@@ -379,7 +487,7 @@ def test_config_ok(mscp, src_prefix, dst_prefix):
|
||||
|
||||
src = File("src", size = 1024 * 1024).make()
|
||||
dst = File("dst", size = 1024 * 1024 * 2).make()
|
||||
run2ok([mscp, "-H", "-vvv", "-F", config,
|
||||
run2ok([mscp, "-vvv", "-F", config,
|
||||
src_prefix + src.path, dst_prefix + "dst"])
|
||||
|
||||
os.remove(config)
|
||||
@@ -395,9 +503,192 @@ def test_config_ng(mscp, src_prefix, dst_prefix):
|
||||
|
||||
src = File("src", size = 1024 * 1024).make()
|
||||
dst = File("dst", size = 1024 * 1024 * 2).make()
|
||||
run2ng([mscp, "-H", "-vvv", "-F", config,
|
||||
run2ng([mscp, "-vvv", "-F", config,
|
||||
src_prefix + src.path, dst_prefix + "dst"])
|
||||
|
||||
os.remove(config)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
|
||||
param_valid_option_ok = [
|
||||
[ "-o", "Port=8022" ],
|
||||
[ "-o", "Port=8022", "-o", "User=root" ],
|
||||
[ "-o", "unknown-option-is-silently-ignored" ],
|
||||
]
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
@pytest.mark.parametrize("option", param_valid_option_ok)
|
||||
def test_inline_option_ok(mscp, src_prefix, dst_prefix, option):
|
||||
""" change port number with -o option. it should be ok. """
|
||||
src = File("src", size = 1024 * 1024).make()
|
||||
dst = File("dst")
|
||||
run2ok([mscp, "-vvv"] + option +
|
||||
[src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
|
||||
param_valid_option_ng = [
|
||||
[ "-o", "Port=8023" ],
|
||||
[ "-o", "User=invaliduser" ],
|
||||
]
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
@pytest.mark.parametrize("option", param_valid_option_ng)
|
||||
def test_inline_option_ng(mscp, src_prefix, dst_prefix, option):
|
||||
""" change port number with -o option. it should be ng. """
|
||||
src = File("src", size = 1024 * 1024).make()
|
||||
dst = File("dst")
|
||||
run2ng([mscp, "-vvv"] + option +
|
||||
[src_prefix + src.path, dst_prefix + dst.path])
|
||||
src.cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_porxyjump_ok(mscp, src_prefix, dst_prefix):
|
||||
""" test -J proxyjump option"""
|
||||
src = File("src", size = 10 * 1024 * 1024).make()
|
||||
dst = File("dst")
|
||||
# use small min-chunk-size to use multiple connections
|
||||
run2ok([mscp, "-n", 4, "-s", 1024 * 1024, "-vvv",
|
||||
"-J", "localhost:8022",
|
||||
src_prefix + src.path, dst_prefix + dst.path])
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_porxyjump_ng(mscp, src_prefix, dst_prefix):
|
||||
""" test -J proxyjump option, invalid jump node causes fail"""
|
||||
src = File("src", size = 10 * 1024 * 1024).make()
|
||||
dst = File("dst")
|
||||
# use small min-chunk-size to use multiple connections
|
||||
run2ng([mscp, "-n", 4, "-s", 1024 * 1024, "-vvv",
|
||||
"-J", "invaliduser@localhost:8022",
|
||||
src_prefix + src.path, dst_prefix + dst.path])
|
||||
src.cleanup()
|
||||
|
||||
# username test assumes that this test runs inside a container, see Dockerfiles
|
||||
def test_specify_passphrase_via_env(mscp):
|
||||
src = File(os.getcwd() + "/src", size = 1024).make()
|
||||
dst = File("/home/test/dst")
|
||||
env = os.environ
|
||||
env["MSCP_SSH_AUTH_PASSPHRASE"] = "keypassphrase"
|
||||
run2ok([mscp, "-vvv", "-l", "test", "-i", "/home/test/.ssh/id_rsa_test",
|
||||
src.path, "localhost:" + dst.path], env = env)
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
def test_specify_invalid_passphrase_via_env(mscp):
|
||||
src = File(os.getcwd() + "/src", size = 1024).make()
|
||||
dst = File("/home/test/dst")
|
||||
env = os.environ
|
||||
env["MSCP_SSH_AUTH_PASSPHRASE"] = "invalid-keypassphrase"
|
||||
run2ng([mscp, "-vvv", "-l", "test", "-i", "/home/test/.ssh/id_rsa_test",
|
||||
src.path, "localhost:" + dst.path], env = env)
|
||||
src.cleanup()
|
||||
|
||||
def test_specify_password_via_env(mscp):
|
||||
src = File(os.getcwd() + "/src", size = 1024).make()
|
||||
dst = File("/home/test/dst")
|
||||
env = os.environ
|
||||
env["MSCP_SSH_AUTH_PASSWORD"] = "userpassword"
|
||||
run2ok([mscp, "-vvv", "-l", "test",
|
||||
src.path, "localhost:" + dst.path], env = env)
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
def test_specify_invalid_password_via_env(mscp):
|
||||
src = File(os.getcwd() + "/src", size = 1024).make()
|
||||
dst = File("/home/test/dst")
|
||||
env = os.environ
|
||||
env["MSCP_SSH_AUTH_PASSWORD"] = "invalid-userpassword"
|
||||
run2ng([mscp, "-vvv", "-l", "test",
|
||||
src.path, "localhost:" + dst.path], env = env)
|
||||
src.cleanup()
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_10k_files(mscp, src_prefix, dst_prefix):
|
||||
srcs = []
|
||||
dsts = []
|
||||
for n in range(10000):
|
||||
srcs.append(File("src/src-{:06d}".format(n), size=1024).make())
|
||||
dsts.append(File("dst/src-{:06d}".format(n)))
|
||||
run2ok([mscp, "-v", src_prefix + "src", dst_prefix + "dst"])
|
||||
for s, d in zip(srcs, dsts):
|
||||
assert check_same_md5sum(s, d)
|
||||
shutil.rmtree("src")
|
||||
shutil.rmtree("dst")
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_checkpoint_dump_and_resume(mscp, src_prefix, dst_prefix):
|
||||
src1 = File("src1", size = 64 * 1024 * 1024).make()
|
||||
src2 = File("src2", size = 64 * 1024 * 1024).make()
|
||||
dst1 = File("dst/src1")
|
||||
dst2 = File("dst/src2")
|
||||
run2ok([mscp, "-vvv", "-W", "checkpoint", "-D",
|
||||
src_prefix + "src1", src_prefix + "src2", dst_prefix + "dst"])
|
||||
assert os.path.exists("checkpoint")
|
||||
|
||||
run2ok([mscp, "-vvv", "-R", "checkpoint"])
|
||||
assert check_same_md5sum(src1, dst1)
|
||||
assert check_same_md5sum(src2, dst2)
|
||||
src1.cleanup()
|
||||
src2.cleanup()
|
||||
dst1.cleanup()
|
||||
dst2.cleanup()
|
||||
os.remove("checkpoint")
|
||||
|
||||
@pytest.mark.parametrize("timeout", [ 1, 2, 3, 4, 5 ])
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_checkpoint_interrupt_large_file(mscp, timeout, src_prefix, dst_prefix):
|
||||
"""Copy two 100MB files with 200Mbps -> 4 sec + 4 sec """
|
||||
src1 = File("src1", size = 100 * 1024 * 1024).make()
|
||||
src2 = File("src2", size = 100 * 1024 * 1024).make()
|
||||
dst1 = File("dst/src1")
|
||||
dst2 = File("dst/src2")
|
||||
run2ng([mscp, "-vv", "-W", "checkpoint", "-L", "200m",
|
||||
src_prefix + "src1", src_prefix + "src2", dst_prefix + "dst"],
|
||||
timeout = timeout)
|
||||
assert os.path.exists("checkpoint")
|
||||
|
||||
run2ok([mscp, "-vv", "-R", "checkpoint"])
|
||||
assert check_same_md5sum(src1, dst1)
|
||||
assert check_same_md5sum(src2, dst2)
|
||||
src1.cleanup()
|
||||
src2.cleanup()
|
||||
dst1.cleanup()
|
||||
dst2.cleanup()
|
||||
os.remove("checkpoint")
|
||||
|
||||
@pytest.mark.parametrize("timeout", [ 1, 2, 3, 4, 5 ])
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix", param_remote_prefix)
|
||||
def test_checkpoint_interrupt_many_files(mscp, timeout, src_prefix, dst_prefix):
|
||||
"""Copy 100 1-MB files with 4 connections, and interrupt and
|
||||
resume the transfer
|
||||
"""
|
||||
|
||||
files = []
|
||||
for x in range(100):
|
||||
files.append((
|
||||
File("src/{:03d}".format(x), size = 1024 * 1024).make(),
|
||||
File("dst/{:03d}".format(x))
|
||||
))
|
||||
|
||||
run2ng([mscp, "-vv", "-W", "checkpoint", "-L", "80m", "-n", 4,
|
||||
src_prefix + "src", dst_prefix + "dst"],
|
||||
timeout = timeout)
|
||||
assert os.path.exists("checkpoint")
|
||||
|
||||
run2ok([mscp, "-vv", "-R", "checkpoint"])
|
||||
|
||||
for src, dst in files:
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
os.remove("checkpoint")
|
||||
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
|
||||
"""
|
||||
test_python.py: Testing libmscp through the mscp python binding.
|
||||
"""
|
||||
|
||||
import pytest
|
||||
import mscp
|
||||
import os
|
||||
from util import File, check_same_md5sum
|
||||
|
||||
def test_create_and_release():
|
||||
m = mscp.mscp("localhost", mscp.LOCAL2REMOTE)
|
||||
m.cleanup()
|
||||
|
||||
|
||||
""" copy test """
|
||||
|
||||
remote = "localhost"
|
||||
remote_prefix = "{}/".format(os.getcwd()) # use current dir
|
||||
param_remote_prefix_and_direction = [
|
||||
("", remote_prefix, mscp.LOCAL2REMOTE), (remote_prefix, "", mscp.REMOTE2LOCAL)
|
||||
]
|
||||
|
||||
|
||||
param_single_copy = [
|
||||
(File("src", size = 64), File("dst")),
|
||||
(File("src", size = 4096 * 1), File("dst")),
|
||||
(File("src", size = 128 * 1024 * 1024), File("dst")),
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix, direction",
|
||||
param_remote_prefix_and_direction)
|
||||
@pytest.mark.parametrize("src, dst", param_single_copy)
|
||||
def test_single_copy(src_prefix, dst_prefix, direction, src, dst):
|
||||
src.make()
|
||||
m = mscp.mscp(remote, direction)
|
||||
m.copy(src_prefix + src.path, dst_prefix + dst.path)
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
|
||||
param_double_copy = [
|
||||
(File("src1", size = 1024 * 1024), File("src2", size = 1024 * 1024),
|
||||
File("dst/src1"), File("dst/src2")
|
||||
)
|
||||
]
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix, direction",
|
||||
param_remote_prefix_and_direction)
|
||||
@pytest.mark.parametrize("s1, s2, d1, d2", param_double_copy)
|
||||
def test_double_copy(src_prefix, dst_prefix, direction, s1, s2, d1, d2):
|
||||
s1.make()
|
||||
s2.make()
|
||||
mscp.mscp(remote, direction).copy([src_prefix + s1.path, src_prefix + s2.path],
|
||||
dst_prefix + "dst")
|
||||
assert check_same_md5sum(s1, d1)
|
||||
assert check_same_md5sum(s2, d2)
|
||||
s1.cleanup()
|
||||
s2.cleanup()
|
||||
d1.cleanup()
|
||||
d2.cleanup()
|
||||
|
||||
|
||||
param_single_copy = [
|
||||
(File("src", size = 1024 * 1024 * 4), File("dst")),
|
||||
]
|
||||
|
||||
param_kwargs = [
|
||||
{ "nr_threads": 6 },
|
||||
{ "nr_ahead": 64 },
|
||||
{ "min_chunk_sz": 1 * 1024 * 1024 },
|
||||
{ "max_chunk_sz": 64 * 1024 * 1024 },
|
||||
{ "coremask": "0x0f" },
|
||||
{ "max_startups": 5 },
|
||||
{ "severity": mscp.SEVERITY_NONE },
|
||||
{ "cipher": "aes128-gcm@openssh.com" },
|
||||
{ "compress": "yes" },
|
||||
{ "no_hostkey_check": True },
|
||||
{ "enable_nagle": True },
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("src_prefix, dst_prefix, direction",
|
||||
param_remote_prefix_and_direction)
|
||||
@pytest.mark.parametrize("src, dst", param_single_copy)
|
||||
@pytest.mark.parametrize("kw", param_kwargs)
|
||||
def test_kwargs(src_prefix, dst_prefix, direction, src, dst, kw):
|
||||
src.make()
|
||||
m = mscp.mscp(remote, direction, **kw)
|
||||
m.copy(src_prefix + src.path, dst_prefix + dst.path)
|
||||
assert check_same_md5sum(src, dst)
|
||||
src.cleanup()
|
||||
dst.cleanup()
|
||||
|
||||
def test_login_failed():
|
||||
m = mscp.mscp("asdfasdf@" + remote, mscp.LOCAL2REMOTE)
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
m.connect()
|
||||
|
||||
m = mscp.mscp(remote, mscp.LOCAL2REMOTE, login_name = "asdfadsf")
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
m.connect()
|
||||
|
||||
m = mscp.mscp(remote, mscp.LOCAL2REMOTE, port = "65534")
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
m.connect()
|
||||
|
||||
def test_get_stat_before_copy_start():
|
||||
m = mscp.mscp("localhost", mscp.LOCAL2REMOTE)
|
||||
m.connect()
|
||||
(total, done, finished) = m.stats()
|
||||
assert total == 0 and done == 0
|
||||
|
||||
|
||||
param_invalid_kwargs = [
|
||||
{ "nr_threads": -1 },
|
||||
{ "nr_ahead": -1 },
|
||||
{ "min_chunk_sz": 1 },
|
||||
{ "max_chunk_sz": 1 },
|
||||
{ "coremask": "xxxxx" },
|
||||
{ "max_startups": -1 },
|
||||
{ "cipher": "invalid" },
|
||||
{ "hmac": "invalid"},
|
||||
{ "compress": "invalid"},
|
||||
{ "ccalgo": "invalid"},
|
||||
]
|
||||
|
||||
@pytest.mark.parametrize("kw", param_invalid_kwargs)
|
||||
def test_invalid_options(kw):
|
||||
with pytest.raises(RuntimeError) as e:
|
||||
m = mscp.mscp("localhost", mscp.LOCAL2REMOTE, **kw)
|
||||
m.connect()
|
||||
Reference in New Issue
Block a user