Skip to content

Commit

Permalink
NetRocks: SHELL (aka FISH) protocol initial implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
elfmz committed Sep 24, 2023
1 parent 7ea048f commit cb20bee
Show file tree
Hide file tree
Showing 26 changed files with 2,583 additions and 276 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,8 @@ install(DIRECTORY "${INSTALL_DIR}/" DESTINATION "lib/far2l" USE_SOURCE_PERMISSIO
PATTERN "far2l_gui.so"
PATTERN "far2l_ttyx.broker"
PATTERN "plug/*.far-plug-*"
PATTERN "plug/*.broker")
PATTERN "plug/*.broker"
)

install(DIRECTORY "${INSTALL_DIR}/" DESTINATION "share/far2l" USE_SOURCE_PERMISSIONS COMPONENT base FILES_MATCHING
PATTERN "${EXECUTABLE_NAME}" EXCLUDE
Expand All @@ -534,7 +535,8 @@ install(DIRECTORY "${INSTALL_DIR}/" DESTINATION "share/far2l" USE_SOURCE_PERMISS
PATTERN "*.far-plug-*" EXCLUDE
PATTERN "*.broker" EXCLUDE
PATTERN "python/plug/python" EXCLUDE
PATTERN "*")
PATTERN "*"
)

# setup some symlinks and remove deprecated stuff from previous installation
execute_process(COMMAND ${CMAKE_COMMAND} -E create_symlink ../../bin/far2l ${PROJECT_BINARY_DIR}/far2l/far2l_askpass)
Expand Down
27 changes: 25 additions & 2 deletions NetRocks/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ src/Erroring.cpp
src/Host/HostRemoteBroker.cpp
)


add_executable (NetRocks-FILE
${PROTOCOL_SOURCES}
src/Protocol/File/ProtocolFile.cpp
src/Host/HostLocal.cpp
)

add_executable (NetRocks-SHELL
${PROTOCOL_SOURCES}
src/Protocol/SHELL/ProtocolSHELL.cpp
src/Protocol/SHELL/ProtocolSHELL_ExecCmd.cpp
src/Protocol/SHELL/ClientApp.cpp
src/Protocol/SHELL/Parse.cpp
src/Protocol/ShellParseUtils.cpp
)

# get rid of warning: dynamic exception specifications are deprecated in C++11
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-deprecated")

Expand All @@ -77,6 +85,21 @@ set_target_properties(NetRocks-FILE
SUFFIX ".broker")
target_compile_options(NetRocks-FILE PUBLIC -DNETROCKS_PROTOCOL)

target_link_libraries(NetRocks-SHELL utils)
target_include_directories(NetRocks-SHELL PRIVATE src)
set_target_properties(NetRocks-SHELL
PROPERTIES
RUNTIME_OUTPUT_DIRECTORY "${INSTALL_DIR}/Plugins/NetRocks/plug"
PREFIX ""
SUFFIX ".broker")
target_compile_options(NetRocks-SHELL PUBLIC -DNETROCKS_PROTOCOL)

add_custom_command(TARGET NetRocks-SHELL POST_BUILD
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/src/Protocol/SHELL/Helpers
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/src/Protocol/SHELL/Helpers "${INSTALL_DIR}/Plugins/NetRocks/plug/SHELL"
)


if (LIBSSH_FOUND AND ((NOT DEFINED NR_SFTP) OR NR_SFTP))
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DHAVE_SFTP")
add_executable (NetRocks-SFTP
Expand All @@ -85,6 +108,7 @@ if (LIBSSH_FOUND AND ((NOT DEFINED NR_SFTP) OR NR_SFTP))
src/Protocol/SSH/ProtocolSFTP.cpp
src/Protocol/SSH/ProtocolSCP.cpp
src/Protocol/FileStatsOverride.cpp
src/Protocol/ShellParseUtils.cpp
)
target_link_libraries(NetRocks-SFTP utils ${LIBSSH_LIBRARIES})
target_include_directories(NetRocks-SFTP PRIVATE src ${LIBSSH_INCLUDE_DIRS})
Expand Down Expand Up @@ -185,4 +209,3 @@ set_target_properties(NetRocks
add_custom_command(TARGET NetRocks POST_BUILD
DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/configs
COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_SOURCE_DIR}/configs "${INSTALL_DIR}/Plugins/NetRocks")

1 change: 0 additions & 1 deletion NetRocks/src/BackgroundTasks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,3 @@ void AbortBackgroundTask(unsigned long id)
if ( it != g_background_tasks.end())
it->second->Abort();
}

19 changes: 13 additions & 6 deletions NetRocks/src/Host/HostRemote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,16 +252,23 @@ void HostRemote::ReInitialize()
char keep_alive_arg[32];
sprintf(keep_alive_arg, "%d", sc_options.GetInt("KeepAlive", 0));

fprintf(stderr, "NetRocks: starting broker '%s' '%s' '%s'\n",
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w);
std::string work_path = broker_path;
TranslateInstallPath_Lib2Share(work_path);

fprintf(stderr, "NetRocks: starting broker '%s' '%s' '%s' in '%s'\n",
broker_pathname.c_str(), ipc_fd.broker_arg_r, ipc_fd.broker_arg_w, work_path.c_str());
const bool use_tsocks = G.GetGlobalConfigBool("UseProxy", false);

pid_t pid = fork();
if (pid == 0) {
// avoid holding arbitrary dir for broker's whole runtime
if (chdir(broker_path.c_str()) == -1) {
fprintf(stderr, "chdir '%s' error %u\n", broker_path.c_str(), errno);
if (chdir("/tmp") == -1) {
fprintf(stderr, "chdir '/tmp' error %u\n", errno);
if (chdir(work_path.c_str()) == -1) {
fprintf(stderr, "chdir '%s' error %u\n", work_path.c_str(), errno);
if (chdir(broker_path.c_str()) == -1) {
fprintf(stderr, "chdir '%s' error %u\n", broker_path.c_str(), errno);
if (chdir("/tmp") == -1) {
fprintf(stderr, "chdir '/tmp' error %u\n", errno);
}
}
}
if (use_tsocks) {
Expand Down
20 changes: 14 additions & 6 deletions NetRocks/src/Op/OpXfer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@ void OpXfer::Transfer()

if (S_ISLNK(e.second.mode)) {
if (existing || SymlinkCopy(e.first, path_dst)) {
if (_kind == XK_MOVE && !existing) {
FileDelete(e.first);
}
ProgressStateUpdate psu(_state);
_state.stats.count_complete++;
continue;
Expand Down Expand Up @@ -400,12 +403,7 @@ void OpXfer::Transfer()
if (FileCopyLoop(e.first, path_dst, e.second)) {
CopyAttributes(path_dst, e.second);
if (_kind == XK_MOVE) {
WhatOnErrorWrap<WEK_REMOVE>(_wea_state, _state, _base_host.get(), e.first,
[&] () mutable
{
_base_host->FileDelete(e.first);
}
);
FileDelete(e.first);
}
}
}
Expand Down Expand Up @@ -434,6 +432,16 @@ void OpXfer::Transfer()
}
}

void OpXfer::FileDelete(const std::string &path)
{
WhatOnErrorWrap<WEK_REMOVE>(_wea_state, _state, _base_host.get(), path,
[&] () mutable
{
_base_host->FileDelete(path);
}
);
}

void OpXfer::CopyAttributes(const std::string &path_dst, const FileInformation &info)
{
WhatOnErrorWrap<WEK_SETTIMES>(_wea_state, _state, _dst_host.get(), path_dst,
Expand Down
1 change: 1 addition & 0 deletions NetRocks/src/Op/OpXfer.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class OpXfer : protected OpBase, public IBackgroundTask
void Rename(const std::set<std::string> &items);
void EnsureDstDirExists();
void Transfer();
void FileDelete(const std::string &path);
void DirectoryCopy(const std::string &path_dst, const FileInformation &info);
bool SymlinkCopy(const std::string &path_src, const std::string &path_dst);
bool FileCopyLoop(const std::string &path_src, const std::string &path_dst, FileInformation &info);
Expand Down
6 changes: 6 additions & 0 deletions NetRocks/src/Protocol/Protocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,26 @@ static ProtocolInfo s_protocols[] = {
{ "sftp", "NetRocks-SFTP", 22, true, true, true, ConfigureProtocolSFTP},
{ "scp", "NetRocks-SFTP", 22, true, true, true, ConfigureProtocolSCP},
#endif
{ "shell", "NetRocks-SHELL", 22, true, true, true, nullptr},

{ "ftp", "NetRocks-FTP", 21, true, true, true, ConfigureProtocolFTP},
#ifdef HAVE_OPENSSL
{ "ftps", "NetRocks-FTP", 990, true, true, true, ConfigureProtocolFTPS},
#endif

#ifdef HAVE_SMB
{ "smb", "NetRocks-SMB", -1, false, true, false, ConfigureProtocolSMB},
#endif

#ifdef HAVE_NFS
{ "nfs", "NetRocks-NFS", -1, false, false, false, ConfigureProtocolNFS},
#endif

#ifdef HAVE_WEBDAV
{ "dav", "NetRocks-WebDAV", 80, true, true, true, ConfigureProtocolWebDAV},
{ "davs", "NetRocks-WebDAV", 443, true, true, true, ConfigureProtocolWebDAVs},
#endif

{ "file", "NetRocks-FILE", 0, false, true, false, nullptr},
{ }
};
Expand Down
Loading

1 comment on commit cb20bee

@unxed
Copy link
Contributor

@unxed unxed commented on cb20bee Sep 25, 2023

Choose a reason for hiding this comment

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

Closes #1819

Please sign in to comment.