Ticket #4232: drop comatibility with native FISH protocol and FISH server.

Does anybody know any implementation of FISH server?

Should we keep the compatibility with unimplemented server?

Let's forget about the compatibility with FISH command formats. Let's
just send shell scripts with arguments that are convenient for us to the
remote host and get results of script work. The part of FISH protocol
relative to remote host answers will be used as is.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
This commit is contained in:
Andrew Borodin 2021-04-18 14:32:10 +03:00
parent 3e44333776
commit 3f42309a5d
19 changed files with 141 additions and 172 deletions

View File

@ -3227,8 +3227,7 @@ The latter specifies the full path of the tar archive.
.SH " FIle transfer over SHell filesystem"
The fish file system is a network based file system that allows you to
manipulate the files in a remote machine as if they were local. To use
this, the other side has to either run fish server, or has to have
bash\-compatible shell.
this, the other side has to have bash\-compatible shell.
.PP
To connect to a remote machine, you just need to chdir
into a special directory which name is in the following

View File

@ -3730,8 +3730,7 @@ tar\-файлов, то есть обычно для получения спис
Файловая система fish \- это сетевая файловая система, которая позволяет
работать с файлами на удалённом компьютере так, как если бы они были
расположены на вашем диске. Для того чтобы это было возможно, на
удалённом компьютере должен быть запущен fish\-сервер, или
bash\-совместимая оболочка shell.
удалённом компьютере должна быть запущена bash\-совместимая оболочка shell.
.PP
Для соединения с удалённым компьютером нужно выполнить команду
перехода в каталог (chdir), имя которого задаётся в следующем формате:

View File

@ -385,7 +385,7 @@ fish_free_archive (struct vfs_class *me, struct vfs_s_super *super)
if (fish_super->sockw != -1)
{
fish_command (me, super, NONE, "#BYE\nexit\n", -1);
fish_command (me, super, NONE, "exit\n", -1);
close (fish_super->sockw);
fish_super->sockw = -1;
}
@ -630,19 +630,6 @@ fish_open_archive_int (struct vfs_class *me, struct vfs_s_super *super)
ERRNOR (E_PROTO, -1);
vfs_print_message ("%s", _("fish: Sending initial line..."));
/*
* Run 'start_fish_server'. If it doesn't exist - no problem,
* we'll talk directly to the shell.
*/
if (fish_command
(me, super, WAIT_REPLY, "#FISH\necho; start_fish_server 2>&1; echo '### 200'\n",
-1) != COMPLETE)
ERRNOR (E_PROTO, -1);
vfs_print_message ("%s", _("fish: Handshaking version..."));
if (fish_command (me, super, WAIT_REPLY, "#VER 0.0.3\necho '### 000'\n", -1) != COMPLETE)
ERRNOR (E_PROTO, -1);
/* Set up remote locale to C, otherwise dates cannot be recognized */
if (fish_command

View File

@ -11,7 +11,6 @@
/* default 'ls' script */
#define FISH_LS_DEF_CONTENT "" \
"#LIST /${FISH_FILENAME}\n" \
"export LC_TIME=C\n" \
"ls -Qlan \"/${FISH_FILENAME}\" 2>/dev/null | grep '^[^cbt]' | (\n" \
"while read p l u g s m d y n; do\n" \
@ -35,13 +34,11 @@
/* default file exists script */
#define FISH_EXISTS_DEF_CONTENT "" \
"#ISEXISTS $FISH_FILENAME\n" \
"ls -l \"/${FISH_FILENAME}\" >/dev/null 2>/dev/null\n" \
"echo '### '$?\n"
/* default 'mkdir' script */
#define FISH_MKDIR_DEF_CONTENT "" \
"#MKD $FISH_FILENAME\n" \
"if mkdir \"/${FISH_FILENAME}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
@ -50,15 +47,14 @@
/* default 'unlink' script */
#define FISH_UNLINK_DEF_CONTENT "" \
"#DELE $FISH_FILENAME\n" \
"if rm -f \"/${FISH_FILENAME}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
" echo \"### 500\"\n" \
"fi\n"
/* default 'chown' script */
#define FISH_CHOWN_DEF_CONTENT "" \
"#CHOWN $FISH_FILEOWNER:$FISH_FILEGROUP $FISH_FILENAME\n" \
"if chown ${FISH_FILEOWNER}:${FISH_FILEGROUP} \"/${FISH_FILENAME}\"; then\n"\
" echo \"### 000\"\n" \
"else\n" \
@ -67,7 +63,6 @@
/* default 'chmod' script */
#define FISH_CHMOD_DEF_CONTENT "" \
"#CHMOD $FISH_FILEMODE $FISH_FILENAME\n" \
"if chmod ${FISH_FILEMODE} \"/${FISH_FILENAME}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
@ -93,7 +88,6 @@
/* default 'rmdir' script */
#define FISH_RMDIR_DEF_CONTENT "" \
"#RMD $FISH_FILENAME\n" \
"if rmdir \"/${FISH_FILENAME}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
@ -102,7 +96,6 @@
/* default 'ln -s' symlink script */
#define FISH_LN_DEF_CONTENT "" \
"#SYMLINK $FISH_FILEFROM $FISH_FILETO\n" \
"if ln -s \"/${FISH_FILEFROM}\" \"/${FISH_FILETO}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
@ -111,7 +104,6 @@
/* default 'mv' script */
#define FISH_MV_DEF_CONTENT "" \
"#RENAME $FISH_FILEFROM $FISH_FILETO\n" \
"if mv \"/${FISH_FILEFROM}\" \"/${FISH_FILETO}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
@ -120,7 +112,6 @@
/* default 'ln' hardlink script */
#define FISH_HARDLINK_DEF_CONTENT "" \
"#LINK $FISH_FILEFROM $FISH_FILETO\n" \
"if ln \"/${FISH_FILEFROM}\" \"/${FISH_FILETO}\" 2>/dev/null; then\n" \
" echo \"### 000\"\n" \
"else\n" \
@ -130,7 +121,6 @@
/* default 'retr' script */
#define FISH_GET_DEF_CONTENT "" \
"export LC_TIME=C\n" \
"#RETR $FISH_FILENAME\n" \
"if dd if=\"/${FISH_FILENAME}\" of=/dev/null bs=1 count=1 2>/dev/null ; then\n" \
" ls -ln \"/${FISH_FILENAME}\" 2>/dev/null | (\n" \
" read p l u g s r\n" \
@ -147,7 +137,6 @@
#define FISH_SEND_DEF_CONTENT "" \
"FILENAME=\"/${FISH_FILENAME}\"\n" \
"FILESIZE=${FISH_FILESIZE}\n" \
"#STOR $FILESIZE $FILENAME\n" \
"echo \"### 001\"\n" \
"{\n" \
" while [ $FILESIZE -gt 0 ]; do\n" \
@ -161,7 +150,6 @@
#define FISH_APPEND_DEF_CONTENT "" \
"FILENAME=\"/${FISH_FILENAME}\"\n" \
"FILESIZE=${FISH_FILESIZE}\n" \
"#APPE $FILESIZE $FILENAME\n" \
"echo \"### 001\"\n" \
"res=`exec 3>&1\n" \
"(\n" \

View File

@ -1,32 +1,21 @@
FIles transferred over SHell protocol (V 0.0.3)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
FIles transferred over SSH
~~~~~~~~~~~~~~~~~~~~~~~~~~
This protocol was designed for transferring files over a remote shell
connection (rsh and compatibles). It can be as well used for transfers over
connection (rsh and compatibles). It can be as well used for transfers over
rsh, and there may be other uses.
Client sends requests of following form:
Since version 4.8.31 Midnight Commander doesn't support FISH commands with form
#FISH_COMMAND
equivalent shell commands,
which may be multiline
#FISH_COMMAND [arg1] [arg2] ... [argN]
Only fish commands are defined here, shell equivalents are for your
information only and will probably vary from implementation to
implementation. Fish commands always have priority: server is
expected to execute fish command if it understands it. If it does not,
however, it can try the luck and execute shell command.
and sends requests as shell scripts only.
Since version 4.7.3, the scripts that FISH sends to host machines after
a command is transmitted are no longer hardwired in the Midnight
Commander source code.
First, mc looks for system-wide set of scripts, then it checks whether
current user has host-specific overrides in his per-user mc
configuration directory. User-defined overrides take priority over
sytem-wide scripts if they exist. The order in which the directories are
traversed is as follows:
First, MC looks for system-wide set of scripts, then it checks whether
current user has host-specific overrides in his per-user MC configuration
directory. User-defined overrides take priority over sytem-wide scripts
if they exist. The order in which the directories are traversed is as follows:
/usr/libexec/mc/fish
~/.local/share/mc/fish/<hostname>/
@ -46,54 +35,37 @@ success, if they were, it marks failure.
001 don't know; if there were no previous lines, this marks
PRELIMinary success, if they were, it marks failure
Connecting
~~~~~~~~~~
Client uses "echo FISH:;/bin/sh" as command executed on remote
machine. This should make it possible for server to distinguish FISH
connections from normal rsh/ssh.
Connecting
~~~~~~~~~~
MC uses "echo FISH:;/bin/sh" as command executed on remote machine.
Commands
~~~~~~~~
#FISH
echo; start_fish_server; echo '### 200'
Actions
~~~~~~~
This command is sent at the beginning. It marks that client wishes to
talk via FISH protocol. #VER command must follow. If server
understands FISH protocol, it has option to put FISH server somewhere
on system path and name it start_fish_server.
Get info about host into $result
#VER 0.0.2 <feature1> <feature2> <...>
echo '### 000'
echo $result
echo '### 200'
This command is the second one. It sends client version and extensions
to the server. Server should reply with protocol version to be used,
and list of extensions accepted.
Script: info
VER 0.0.0 <feature2>
### 200
--------------------------------------------------------------------------------
#PWD
pwd; echo '### 200'
List directory or get status information about single file.
Server should reply with current directory (in form /abc/def/ghi)
followed by line indicating success.
ls -lLa $1 | grep '^[^cbt]' | ( while read p x u g s m d y n; do echo "P$p $u.$g
S$s
d$m $d $y
:$n
"; done )
ls -lLa $1 | grep '^[cb]' | ( while read p x u g a i m d y n; do echo "P$p $u.$g
E$a$i
dD$m $d $y
:$n
"; done )
echo '### 200'
#LIST /directory
ls -lLa $1 | grep '^[^cbt]' | ( while read p x u g s m d y n; do echo "P$p $u.$g
S$s
d$m $d $y
:$n
"; done )
ls -lLa $1 | grep '^[cb]' | ( while read p x u g a i m d y n; do echo "P$p $u.$g
E$a$i
dD$m $d $y
:$n
"; done )
echo '### 200'
This allows client to list directory or get status information about
single file. Output is in following form (any line except :<filename>
may be omitted):
Output is in following form (any line except :<filename> may be omitted):
P<unix permissions> <owner>.<group>
S<size>
@ -104,94 +76,131 @@ E<major-of-device>,<minor>
L<filename symlink points to>
<blank line to separate items>
Unix permissions are of form X--------- where X is type of
file. Currently, '-' means regular file, 'd' means directory, 'c', 'b'
means character and block device, 'l' means symbolic link, 'p' means
FIFO and 's' means socket.
Unix permissions are of form X---------
where X is type of file:
'-' a regular file
'd' a directory
'c' a character device
'b' a block device
'l' a symbolic link
'p' a FIFO
's' a socket.
'd' has three fields: month (one of strings Jan Feb Mar Apr May Jun
Jul Aug Sep Oct Nov Dec), day of month, and third is either single
number indicating year, or HH:MM field (assume current year in such
case). As you've probably noticed, this is pretty broken; it is for
compatibility with ls listing.
'd' has three fields:
month (one of strings Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec)
day of month
single number indicating year, or HH:MM field (assume current year in such
case). As you've probably noticed, this is pretty broken; it is for
compatibility with ls listing.
#RETR /some/name
ls -l /some/name | ( read a b c d x e; echo $x ); echo '### 100'; cat /some/name; echo '### 200'
Script: ls
--------------------------------------------------------------------------------
Get file
ls -l /some/name | ( read a b c d x e; echo $x ); echo '### 100'; cat /some/name; echo '### 200'
Server sends line with filesize on it, followed by line with ### 100
indicating partial success, then it sends binary data (exactly
filesize bytes) and follows them with (with no preceding newline) ###
200.
indicating partial success, then it sends binary data (exactly filesize bytes)
and follows them with (with no preceding newline) ### 200.
Note that there's no way to abort running RETR command - except
closing the connection.
Note that there's no way to abort running RETR command - except closing
the connection.
#STOR <size> /file/name
> /file/name; echo '### 001'; ( dd bs=4096 count=<size/4096>; dd bs=<size%4096> count=1 ) 2>/dev/null | ( cat > %s; cat > /dev/null ); echo '### 200'
Script: get
This command is for storing /file/name, which is exactly size bytes
big. You probably think I went crazy. Well, I did not: that strange
cat > /dev/null has purpose to discard any extra data which was not
written to disk (due to for example out of space condition).
--------------------------------------------------------------------------------
Put file
> /file/name; echo '### 001'; ( dd bs=4096 count=<size/4096>; dd bs=<size%4096> count=1 ) 2>/dev/null | ( cat > %s; cat > /dev/null ); echo '### 200'
This command is for storing /file/name, which is exactly size bytes big.
You probably think I went crazy. Well, I did not: that strange cat > /dev/null
has purpose to discard any extra data which was not written to disk (due to for
example out of space condition).
[Why? Imagine uploading file with "rm -rf /" line in it.]
#CWD /somewhere
cd /somewhere; echo '### 000'
Script: send
It is specified here, but I'm not sure how wise idea is to use this
one: it breaks stateless-ness of the protocol.
--------------------------------------------------------------------------------
Following commands should be rather self-explanatory:
Change directory
#CHMOD 1234 file
chmod 1234 file; echo '### 000'
cd /somewhere; echo '### 000'
#DELE /some/path
rm -f /some/path; echo '### 000'
It is specified here, but I'm not sure how wise idea is to use this one:
it breaks stateless-ness of the protocol.
#MKD /some/path
mkdir /some/path; echo '### 000'
--------------------------------------------------------------------------------
#RMD /some/path
rmdir /some/path; echo '### 000'
Change mode
#RENAME /path/a /path/b
mv /path/a /path/b; echo '### 000'
chmod 1234 file; echo '### 000'
#LINK /path/a /path/b
ln /path/a /path/b; echo '### 000'
Script: chmod
#SYMLINK /path/a /path/b
ln -s /path/a /path/b; echo '### 000'
--------------------------------------------------------------------------------
#CHOWN user /file/name
chown user /file/name; echo '### 000'
Change own
#CHGRP group /file/name
chgrp group /file/name; echo '### 000'
chown user /file/name; echo '### 000'
#INFO
...collect info about host into $result ...
echo $result
echo '### 200'
Script: chown
#READ <offset> <size> /path/and/filename
cat /path/and/filename | ( dd bs=4096 count=<offset/4096> > /dev/null;
dd bs=<offset%4096> count=1 > /dev/null;
dd bs=4096 count=<offset/4096>;
dd bs=<offset%4096> count=1; )
--------------------------------------------------------------------------------
Returns ### 200 on successful exit, ### 291 on successful exit when
reading ended at eof, ### 292 on successful exit when reading did not
end at eof.
Remove file
#WRITE <offset> <size> /path/and/filename
rm -f /some/path; echo '### 000'
Hmm, shall we define these ones if we know our client is not going to
use them?
Sctipt: unlink
you can use follow parameters:
--------------------------------------------------------------------------------
Make directory:
mkdir /some/path; echo '### 000'
Script: mkdir
--------------------------------------------------------------------------------
Remove directory
rmdir /some/path; echo '### 000'
Script: rmdir
--------------------------------------------------------------------------------
Rename/move file
mv /path/a /path/b; echo '### 000'
Script: mv
--------------------------------------------------------------------------------
Make link
ln /path/a /path/b; echo '### 000'
Script: hardlink
--------------------------------------------------------------------------------
Make symbolic link:
ln -s /path/a /path/b; echo '### 000'
Script: ln
--------------------------------------------------------------------------------
You can use following parameters:
FISH_FILESIZE
FISH_FILENAME
FISH_FILEMODE
@ -201,11 +210,11 @@ FISH_FILEFROM
FISH_FILETO
NB:
'FISH_FILESIZE' used if we operate with single file name in 'unlink', 'rmdir', 'chmod', etc...
'FISH_FILEFROM','FISH_FILETO' used if we operate with two files in 'ln', 'hardlink', 'mv' etc...
'FISH_FILEOWNER', 'FISH_FILEGROUPE' is a new user/group in chown
'FISH_FILESIZE' is used if we operate with single file name in 'unlink', 'rmdir', 'chmod', etc...
'FISH_FILEFROM','FISH_FILETO' are used if we operate with two files in 'ln', 'hardlink', 'mv' etc...
'FISH_FILEOWNER', 'FISH_FILEGROUPE' are a new user/group in chown
also flags:
and flags:
FISH_HAVE_HEAD
FISH_HAVE_SED
FISH_HAVE_AWK
@ -214,4 +223,5 @@ FISH_HAVE_LSQ
FISH_HAVE_DATE_MDYT
That's all, folks!
pavel@ucw.cz
pavel@ucw.cz
aborodin@vmail.ru

View File

@ -1,4 +1,3 @@
#APPE $FISH_FILESIZE $FISH_FILENAME
FILENAME="/${FISH_FILENAME}"
echo "### 001"
{

View File

@ -1,4 +1,3 @@
#CHMOD $FISH_FILEMODE $FISH_FILENAME
if chmod ${FISH_FILEMODE} "/${FISH_FILENAME}" 2>/dev/null; then
echo "### 000"
else

View File

@ -1,4 +1,3 @@
#CHOWN $FISH_FILEOWNER:$FISH_FILEGROUP $FISH_FILENAME
if chown ${FISH_FILEOWNER}:${FISH_FILEGROUP} "/${FISH_FILENAME}" ; then
echo "### 000"
else

View File

@ -1,3 +1,2 @@
#ISEXISTS $FISH_FILENAME
ls -l "/${FISH_FILENAME}" >/dev/null 2>/dev/null
echo '### '$?

View File

@ -1,4 +1,3 @@
#RETR $FISH_FILENAME $FISH_START_OFFSET
LC_TIME=C
export LC_TIME
fish_get_perl ()

View File

@ -1,4 +1,3 @@
#LINK $FISH_FILEFROM $FISH_FILETO
FILEFROM="/${FISH_FILEFROM}"
FILETO="/${FISH_FILETO}"
if ln "${FILEFROM}" "${FILETO}" 2>/dev/null; then

View File

@ -1,4 +1,3 @@
#SYMLINK $FISH_FILEFROM $FISH_FILETO
FILEFROM="${FISH_FILEFROM}"
FILETO="/${FISH_FILETO}"
if ln -s "${FILEFROM}" "${FILETO}" 2>/dev/null; then

View File

@ -1,4 +1,3 @@
#LIST /${FISH_DIR}
LC_TIME=C
export LC_TIME
perl_res="1"

View File

@ -1,4 +1,3 @@
#MKD $FISH_FILENAME
if mkdir "/$FISH_FILENAME" 2>/dev/null; then
echo "### 000"
else

View File

@ -1,4 +1,3 @@
#RENAME $FISH_FILEFROM $FISH_FILETO
if mv "/${FISH_FILEFROM}" "/${FISH_FILETO}" 2>/dev/null; then
echo "### 000"
else

View File

@ -1,4 +1,3 @@
#RMD $FISH_FILENAME
if rmdir "/${FISH_FILENAME}" 2>/dev/null; then
echo "### 000"
else

View File

@ -1,4 +1,3 @@
#STOR $FISH_FILESIZE $FISH_FILENAME
FILENAME="/${FISH_FILENAME}"
echo "### 001"
{

View File

@ -1,4 +1,3 @@
#DELE $FISH_FILENAME
if rm -f "/${FISH_FILENAME}" 2>/dev/null; then
echo "### 000"
else

View File

@ -1,4 +1,3 @@
#UTIME "$FISH_TOUCHATIME_W_NSEC" "$FISH_TOUCHMTIME_W_NSEC" "$FISH_FILENAME"
if TZ=UTC touch -h -m -d "$FISH_TOUCHMTIME_W_NSEC" "/${FISH_FILENAME}" 2>/dev/null && \
TZ=UTC touch -h -a -d "$FISH_TOUCHATIME_W_NSEC" "/${FISH_FILENAME}" 2>/dev/null; then
echo "### 000"