network/tnfsd: Added (trivial network filesystem server).

Signed-off-by: Willy Sudiarto Raharjo <willysr@slackbuilds.org>
This commit is contained in:
B. Watson 2022-07-25 15:22:44 +07:00 committed by Willy Sudiarto Raharjo
parent f41d672514
commit 6b962c61dc
9 changed files with 505 additions and 0 deletions

41
network/tnfsd/COPYING Normal file
View file

@ -0,0 +1,41 @@
This information copied from the C sources.
License for all tnfsd source files except strlcat.c and strlcpy.c:
The MIT License
Copyright (c) 2010 Dylan Smith
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
License for strlcat.c and strlcpy.c:
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.

49
network/tnfsd/README Normal file
View file

@ -0,0 +1,49 @@
tnfsd (trivial network filesystem server)
TNFS is a simplified Internet file transfer protocol, designed for
limited resource usage and ease of implementation on small systems,
such as 8-bit computers. It's simpler than NFS, SMB, or FTP. It's
similar to TFTP, but has features TFTP lacks.
Since tnfsd has no access control other than file permissions, and
since we generally don't want clients to have write access, this
package uses a dedicated user/group for the daemon, and another group
to control local write access to the shared directory.
Before running this SlackBuild, you must create the tnfsd user and
the tnfsd and tnfs-files groups. Use these commands:
groupadd -g 375 tnfsd
groupadd -g 376 tnfs-files
useradd -u 375 -d /var/tnfs -c "TNFS Daemon User" \
-M -g tnfsd tnfsd -s /bin/false
After the package is installed, add any users you want to the tnfs-files
group. These users will be able to create files in the /var/tnfs
directory. Example:
usermod -a -G tnfs-files joeblow
After the above command, the user joeblow will have to log out and
back in, to join the new group. Once this is done, the user can
copy files to /var/tnfs (or ~tnfs) and they will be visible to TNFS
clients.
TNFS uses port 16384, UDP (for most 8-bit clients) and TCP (for the
Linux client), so make sure you allow incoming traffic if you have
firewall rules.
This package includes the server and an init script for running
tnfsd as a system daemon. To start tnfsd at boot, first edit
/etc/rc.d/rc.tnfsd, read the comments, and change the default user and
directory if needed. Then add this to /etc/rc.d/rc.local:
[ -x /etc/rc.d/rc.tnfsd ] && /etc/rc.d/rc.tnfsd start
Depending on how you're using tnfsd, it might make more sense to start
the service as needed, as an unprivileged user, instead of running it
as a system daemon.
Usage logging is a compile-time option. By default, it's enabled. If
you find it too chatty, you can rebuild this with USAGELOG=no set in
the environment.

22
network/tnfsd/doinst.sh Normal file
View file

@ -0,0 +1,22 @@
config() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
if [ ! -r $OLD ]; then
mv $NEW $OLD
elif [ "$(cat $OLD | md5sum)" = "$(cat $NEW | md5sum)" ]; then
rm $NEW
fi
}
preserve_perms() {
NEW="$1"
OLD="$(dirname $NEW)/$(basename $NEW .new)"
if [ -e $OLD ]; then
cp -a $OLD ${NEW}.incoming
cat $NEW > ${NEW}.incoming
mv ${NEW}.incoming $NEW
fi
config $NEW
}
preserve_perms etc/rc.d/rc.tnfsd.new

48
network/tnfsd/rc.tnfsd Normal file
View file

@ -0,0 +1,48 @@
#!/bin/sh
# rc.tnfsd, part of SBo tnfsd build, by B. Watson. WTFPL.
# To start tnfsd at boot, make this script executable, then add this code
# to /etc/rc.d/rc.local:
# [ -x /etc/rc.d/rc.tnfsd ] && /etc/rc.d/rc.tnfsd start
# tnfsd will chroot to $TNFS_ROOT and set its user ID to $TNFS_USER,
# and its group ID to $TNFS_USER's primary group. Since there's no
# other form of access control, make sure the $TNFS_USER can't wrote
# to $TNFS_ROOT, unless you want to allow everyone who can connect
# to write/delete/overwrite everything in $TNFS_ROOT. By default,
# /var/tnfs is owned by root:tnfs-files.
TNFS_USER=tnfsd
TNFS_ROOT=/var/tnfs
# Log gets overwritten on startup (no rotation).
TNFS_LOG=/var/log/tnfsd.log
# If you don't need the log at all. But if tnfsd fails to start, you
# won't see any error messages from it...
#TNFS_LOG=/dev/null
kill_tnfsd() {
/usr/bin/killall tnfsd && sleep 1
}
start_tnfsd() {
echo "Starting tnfsd."
kill_tnfsd &>/dev/null
/usr/bin/tnfsd "$TNFS_ROOT" -c "$TNFS_USER" >"$TNFS_LOG" </dev/null 2>&1 &
}
stop_tnfsd() {
echo "Stopping tnfsd."
kill_tnfsd
}
case "$1" in
""|start) start_tnfsd ;;
stop) stop_tnfsd ;;
restart) stop_tnfsd ; start_tnfsd ;;
*) echo "Usage: $0 stop|start|restart" 1&>2; exit 1 ;;
esac
exit 0

19
network/tnfsd/slack-desc Normal file
View file

@ -0,0 +1,19 @@
# HOW TO EDIT THIS FILE:
# The "handy ruler" below makes it easier to edit a package description.
# Line up the first '|' above the ':' following the base package name, and
# the '|' on the right side marks the last column you can put a character in.
# You must make exactly 11 lines for the formatting to be correct. It's also
# customary to leave one space after the ':' except on otherwise blank lines.
|-----handy-ruler------------------------------------------------------|
tnfsd: tnfsd (trivial network filesystem server)
tnfsd:
tnfsd: TNFS is a simplified Internet file transfer protocol, designed for
tnfsd: simplicity and ease of implementation on small systems, such as 8-bit
tnfsd: computers. It's simpler than NFS, SMB, or FTP. It's similar to TFTP,
tnfsd: but has features TFTP lacks.
tnfsd:
tnfsd:
tnfsd:
tnfsd:
tnfsd:

105
network/tnfsd/tnfsd.1 Normal file
View file

@ -0,0 +1,105 @@
.\" Man page generated from reStructuredText.
.
.
.nr rst2man-indent-level 0
.
.de1 rstReportMargin
\\$1 \\n[an-margin]
level \\n[rst2man-indent-level]
level margin: \\n[rst2man-indent\\n[rst2man-indent-level]]
-
\\n[rst2man-indent0]
\\n[rst2man-indent1]
\\n[rst2man-indent2]
..
.de1 INDENT
.\" .rstReportMargin pre:
. RS \\$1
. nr rst2man-indent\\n[rst2man-indent-level] \\n[an-margin]
. nr rst2man-indent-level +1
.\" .rstReportMargin post:
..
.de UNINDENT
. RE
.\" indent \\n[an-margin]
.\" old: \\n[rst2man-indent\\n[rst2man-indent-level]]
.nr rst2man-indent-level -1
.\" new: \\n[rst2man-indent\\n[rst2man-indent-level]]
.in \\n[rst2man-indent\\n[rst2man-indent-level]]u
..
.TH "TNFSD" 1 "2022-07-22" "20201019" "SlackBuilds.org"
.SH NAME
tnfsd \- trivial network filesystem daemon
.\" RST source for tnfsd(1) man page. Convert with:
.
.\" rst2man.py tnfsd.rst > tnfsd.1
.
.\" rst2man.py comes from the SBo development/docutils package.
.
.SH SYNOPSIS
.sp
tnfsd \fBdirectory\fP [\fB\-c\fP \fIusername\fP]
.SH DESCRIPTION
.sp
TNFS is a simplified Internet file transfer protocol, designed for
simplicity and ease of implementation on small systems, such as 8\-bit
computers. It\(aqs simpler than NFS, SMB, or FTP. It\(aqs similar to TFTP,
but has features TFTP lacks.
.sp
\fBtnfsd\fP is the server for the TNFS protocol. It listens for clients
on UDP and TCP port 16384. Most 8\-bit clients use UDP, and the Linux
client \fBtnfs\-fuse\fP uses TCP.
.sp
The mandatory \fBdirectory\fP option is the root of the TNFS filesystem
tree.
.sp
The \fB\-c\fP \fIusername\fP option requires \fBtnfsd\fP to be run as
\fIroot\fP\&. If given, \fBtnfsd\fP will \fBchroot\fP(2) to the \fIdirectory\fP,
then drop its root privileges and run as the \fIusername\fP user instead.
.sp
Even without \fBchroot\fP, \fBtnfsd\fP will not deliberately allow access
to files outside the \fIdirectory\fP\&. The \fB\-c\fP option is a safety net,
in case there\(aqs a bug in \fBtnfsd\fP that allows such access (currently,
no such bug is known of).
.sp
Note that \fBtnfsd\fP can be started by a normal user, since it uses an
unprivileged UDP port. The \fB\-c\fP option won\(aqt work in this case.
.sp
\fBtnfsd\fP logs various information to standard error. If compiled with
\fI\-DUSAGE_LOG\fP, the log includes all mount, umount, and file transfer
requests including the client IP addresses.
.SH LIMITATIONS
.sp
\fBtnfsd\fP is designed to be simple, so the following list of
limitations should not be read as complaints or feature requests.
.sp
There is no way to run multiple \fBtnfsd\fP instances on the same
host, not even on a multi\-homed host. The default UDP port cannot
be changed; neither can the IP address used for binding (which is
\fI0.0.0.0\fP, aka \fIINADDR_ANY\fP). Also, there\(aqs no concept of virtual
hosts. If you \fIreally\fP want to run multiple instances, use containers
or virtual machines.
.sp
There\(aqs no way to limit which hosts may access \fBtnfsd\fP using any
mechanism such as \fBtcpd\fP(8). Firewall rules may be used instead,
e.g. \fBiptables\fP(8).
.sp
There isn\(aqt a way to share a directory read\-only with the current
\fBtnfsd\fP implementation. However, filesystem permissions can be used
to prevent the daemon from writing to the shared directory.
.SH COPYRIGHT
.sp
See the file /usr/doc/tnfsd\-20201019/COPYING for license information.
.SH AUTHORS
.sp
tnfsd was written by Dylan Smith.
.sp
This man page written for the SlackBuilds.org project
by B. Watson, and is licensed under the WTFPL.
.SH SEE ALSO
.sp
\fBtnfs\-fuse\fP(1), \fBfujinet\-pc\fP(1)
.sp
/usr/doc/tnfsd\-20201019/tnfs\-protocol.md
.\" Generated by docutils manpage writer.
.

View file

@ -0,0 +1,115 @@
#!/bin/bash
# Slackware build script for tnfsd
# Written by B. Watson (urchlay@slackware.uk)
# Licensed under the WTFPL. See http://www.wtfpl.net/txt/copying/ for details.
cd $(dirname $0) ; CWD=$(pwd)
PRGNAM=tnfsd
VERSION=${VERSION:-20201019}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
PKGTYPE=${PKGTYPE:-tgz}
SRCNAM="spectranet"
SRCVER="TNFSD-$( echo $VERSION | sed 's,\(....\)\(..\)\(..\),\1-\2-\3,' )"
if [ -z "$ARCH" ]; then
case "$( uname -m )" in
i?86) ARCH=i586 ;;
arm*) ARCH=arm ;;
*) ARCH=$( uname -m ) ;;
esac
fi
if [ ! -z "${PRINT_PACKAGE_NAME}" ]; then
echo "$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE"
exit 0
fi
uid_gid_err() {
cat <<EOF
Before running this SlackBuild, you must create the tnfsd user and
the tnfsd and tnfs-files groups. Use these commands:
groupadd -g 375 tnfsd
groupadd -g 376 tnfs-files
useradd -u 375 -d /var/tnfs -c "TNFS Daemon User" \
-M -g tnfsd tnfsd -s /bin/false
EOF
exit 1
}
getent group tnfsd &>/dev/null || uid_gid_err
getent group tnfs-files &>/dev/null || uid_gid_err
getent passwd tnfsd &>/dev/null || uid_gid_err
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}
if [ "$ARCH" = "i586" ]; then
SLKCFLAGS="-O2 -march=i586 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "i686" ]; then
SLKCFLAGS="-O2 -march=i686 -mtune=i686"
LIBDIRSUFFIX=""
elif [ "$ARCH" = "x86_64" ]; then
SLKCFLAGS="-O2 -fPIC"
LIBDIRSUFFIX="64"
else
SLKCFLAGS="-O2"
LIBDIRSUFFIX=""
fi
set -e
rm -rf $PKG
mkdir -p $TMP $PKG $OUTPUT
cd $TMP
rm -rf $SRCNAM-$SRCVER
tar xvf $CWD/$SRCNAM-$SRCVER.tar.gz --wildcards '*/tnfs/*'
cd $SRCNAM-$SRCVER/tnfs
chown -R root:root .
find -L . -perm /111 -a \! -perm 755 -a -exec chmod 755 {} \+ -o \
\! -perm /111 -a \! -perm 644 -a -exec chmod 644 {} \+
# this printf causes tnfsd to log something like 13GB of data in 5
# minutes, if anyone ever connects to it with TCP. No thank you.
sed -i '/printf.*DEBUG/d' tnfsd/datagram.c
[ "${USAGELOG:-yes}" = "yes" ] && SLKCFLAGS+=" -DUSAGELOG"
sed -i "s,-Wall,& $SLKCFLAGS," tnfsd/Makefile
make -C tnfsd OS=LINUX
PKGDOC=$PKG/usr/doc/$PRGNAM-$VERSION
PKGBIN=$PKG/usr/bin
PKGMAN1=$PKG/usr/man/man1
PKGRCD=$PKG/etc/rc.d
PKGVAR=$PKG/var/tnfs
mkdir -p $PKGDOC $PKGBIN $PKGMAN1 $PKGRCD $PKGVAR
install -s -m0755 tnfsd/bin/tnfsd $PKGBIN/tnfsd
cp -a *.md *.txt $PKGDOC
cat $CWD/$PRGNAM.SlackBuild > $PKGDOC/$PRGNAM.SlackBuild
mkdir -p $PKGVAR
chown root:tnfs-files $PKGVAR
chmod 1775 $PKGVAR
# upstream license only exists in C comments, so I included this:
cat $CWD/COPYING > $PKGDOC/COPYING
# man page written for this SlackBuild.
gzip -9c < $CWD/$PRGNAM.1 > $PKGMAN1/$PRGNAM.1.gz
install -oroot -groot -m0755 $CWD/rc.$PRGNAM $PKGRCD/rc.$PRGNAM.new
mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc
cat $CWD/doinst.sh > $PKG/install/doinst.sh
cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.$PKGTYPE

10
network/tnfsd/tnfsd.info Normal file
View file

@ -0,0 +1,10 @@
PRGNAM="tnfsd"
VERSION="20201019"
HOMEPAGE="https://github.com/FujiNetWIFI/spectranet/"
DOWNLOAD="https://github.com/FujiNetWIFI/spectranet/archive/TNFSD-2020-10-19/spectranet-TNFSD-2020-10-19.tar.gz"
MD5SUM="052e01e46bdf91f403060e126373e8b3"
DOWNLOAD_x86_64=""
MD5SUM_x86_64=""
REQUIRES=""
MAINTAINER="B. Watson"
EMAIL="urchlay@slackware.uk"

96
network/tnfsd/tnfsd.rst Normal file
View file

@ -0,0 +1,96 @@
.. RST source for tnfsd(1) man page. Convert with:
.. rst2man.py tnfsd.rst > tnfsd.1
.. rst2man.py comes from the SBo development/docutils package.
.. |version| replace:: 20201019
.. |date| date::
=====
tnfsd
=====
---------------------------------
trivial network filesystem daemon
---------------------------------
:Manual section: 1
:Manual group: SlackBuilds.org
:Date: |date|
:Version: |version|
SYNOPSIS
========
tnfsd **directory** [**-c** *username*]
DESCRIPTION
===========
TNFS is a simplified Internet file transfer protocol, designed for
simplicity and ease of implementation on small systems, such as 8-bit
computers. It's simpler than NFS, SMB, or FTP. It's similar to TFTP,
but has features TFTP lacks.
**tnfsd** is the server for the TNFS protocol. It listens for clients
on UDP and TCP port 16384. Most 8-bit clients use UDP, and the Linux
client **tnfs-fuse** uses TCP.
The mandatory **directory** option is the root of the TNFS filesystem
tree.
The **-c** *username* option requires **tnfsd** to be run as
*root*. If given, **tnfsd** will **chroot**\(2) to the *directory*,
then drop its root privileges and run as the *username* user instead.
Even without **chroot**, **tnfsd** will not deliberately allow access
to files outside the *directory*. The **-c** option is a safety net,
in case there's a bug in **tnfsd** that allows such access (currently,
no such bug is known of).
Note that **tnfsd** can be started by a normal user, since it uses an
unprivileged UDP port. The **-c** option won't work in this case.
**tnfsd** logs various information to standard error. If compiled with
*-DUSAGE_LOG*, the log includes all mount, umount, and file transfer
requests including the client IP addresses.
LIMITATIONS
===========
**tnfsd** is designed to be simple, so the following list of
limitations should not be read as complaints or feature requests.
There is no way to run multiple **tnfsd** instances on the same
host, not even on a multi-homed host. The default UDP port cannot
be changed; neither can the IP address used for binding (which is
*0.0.0.0*, aka *INADDR_ANY*). Also, there's no concept of virtual
hosts. If you *really* want to run multiple instances, use containers
or virtual machines.
There's no way to limit which hosts may access **tnfsd** using any
mechanism such as **tcpd**\(8). Firewall rules may be used instead,
e.g. **iptables**\(8).
There isn't a way to share a directory read-only with the current
**tnfsd** implementation. However, filesystem permissions can be used
to prevent the daemon from writing to the shared directory.
COPYRIGHT
=========
See the file /usr/doc/tnfsd-|version|/COPYING for license information.
AUTHORS
=======
tnfsd was written by Dylan Smith.
This man page written for the SlackBuilds.org project
by B. Watson, and is licensed under the WTFPL.
SEE ALSO
========
**tnfs-fuse**\(1), **fujinet-pc**\(1)
/usr/doc/tnfsd-|version|/tnfs-protocol.md