From 43d409a5d97d954b249133fc64c469bb1eaad33e Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 25 Nov 2023 13:40:21 +0000 Subject: [PATCH] prisonparty accepts user/group names --- README.md | 6 +++--- bin/prisonparty.sh | 19 +++++++++++++------ contrib/package/arch/prisonparty.service | 12 +++++++----- contrib/systemd/prisonparty.service | 10 ++++++---- 4 files changed, 29 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 7ba95763..0a8ebe4b 100644 --- a/README.md +++ b/README.md @@ -119,8 +119,8 @@ just run **[copyparty-sfx.py](https://github.com/9001/copyparty/releases/latest/ enable thumbnails (images/audio/video), media indexing, and audio transcoding by installing some recommended deps: * **Alpine:** `apk add py3-pillow ffmpeg` -* **Debian:** `apt install python3-pil ffmpeg` -* **Fedora:** `dnf install python3-pillow ffmpeg` +* **Debian:** `apt install --no-install-recommends python3-pil ffmpeg` +* **Fedora:** rpmfusion + `dnf install python3-pillow ffmpeg` * **FreeBSD:** `pkg install py39-sqlite3 py39-pillow ffmpeg` * **MacOS:** `port install py-Pillow ffmpeg` * **MacOS** (alternative): `brew install pillow ffmpeg` @@ -1366,7 +1366,7 @@ now [available on copr-pypi](https://copr.fedorainfracloud.org/coprs/g/copr/PyPI ```bash dnf copr enable @copr/PyPI dnf install python3-copyparty # just a minimal install, or... -dnf install python3-{copyparty,pillow,argon2-cffi,pyftpdlib,pyOpenSSL} ffmpeg-free # with recommended deps +dnf install python3-{copyparty,pillow,argon2-cffi,pyftpdlib,pyOpenSSL} ffmpeg # with recommended deps ``` this *may* also work on RHEL but [I'm not paying IBM to verify that](https://www.jeffgeerling.com/blog/2023/dear-red-hat-are-you-dumb) diff --git a/bin/prisonparty.sh b/bin/prisonparty.sh index 2f74f548..e5be4832 100755 --- a/bin/prisonparty.sh +++ b/bin/prisonparty.sh @@ -12,13 +12,13 @@ done help() { cat <<'EOF' usage: - ./prisonparty.sh [VOLDIR [VOLDIR...]] -- python3 copyparty-sfx.py [...] + ./prisonparty.sh [VOLDIR [VOLDIR...]] -- python3 copyparty-sfx.py [...] example: - ./prisonparty.sh /var/lib/copyparty-jail 1000 1000 /mnt/nas/music -- python3 copyparty-sfx.py -v /mnt/nas/music::rwmd + ./prisonparty.sh /var/lib/copyparty-jail cpp cpp /mnt/nas/music -- python3 copyparty-sfx.py -v /mnt/nas/music::rwmd example for running straight from source (instead of using an sfx): - PYTHONPATH=$PWD ./prisonparty.sh /var/lib/copyparty-jail 1000 1000 /mnt/nas/music -- python3 -um copyparty -v /mnt/nas/music::rwmd + PYTHONPATH=$PWD ./prisonparty.sh /var/lib/copyparty-jail cpp cpp /mnt/nas/music -- python3 -um copyparty -v /mnt/nas/music::rwmd note that if you have python modules installed as --user (such as bpm/key detectors), you should add /home/foo/.local as a VOLDIR @@ -68,11 +68,18 @@ cpp="$1"; shift } trap - EXIT +usr="$(getent passwd $uid | cut -d: -f1)" +[ "$usr" ] || { echo "ERROR invalid username/uid $uid"; exit 1; } +uid="$(getent passwd $uid | cut -d: -f3)" + +grp="$(getent group $gid | cut -d: -f1)" +[ "$grp" ] || { echo "ERROR invalid groupname/gid $gid"; exit 1; } +gid="$(getent group $gid | cut -d: -f3)" # debug/vis echo echo "chroot-dir = $jail" -echo "user:group = $uid:$gid" +echo "user:group = $uid:$gid ($usr:$grp)" echo " copyparty = $cpp" echo printf '\033[33m%s\033[0m\n' "copyparty can access these folders and all their subdirectories:" @@ -139,8 +146,8 @@ chmod 777 "$jail/tmp" # run copyparty -export HOME=$(getent passwd $uid | cut -d: -f6) -export USER=$(getent passwd $uid | cut -d: -f1) +export HOME="$(getent passwd $uid | cut -d: -f6)" +export USER="$usr" export LOGNAME="$USER" #echo "pybin [$pybin]" #echo "pyarg [$pyarg]" diff --git a/contrib/package/arch/prisonparty.service b/contrib/package/arch/prisonparty.service index de2d702b..cd35ba99 100644 --- a/contrib/package/arch/prisonparty.service +++ b/contrib/package/arch/prisonparty.service @@ -1,11 +1,11 @@ # this will start `/usr/bin/copyparty-sfx.py` -# in a chroot, preventing accidental access elsewhere -# and read config from `/etc/copyparty.d/*.conf` +# in a chroot, preventing accidental access elsewhere, +# and read copyparty config from `/etc/copyparty.d/*.conf` # # expose additional filesystem locations to copyparty -# by listing them between the last `1000` and `--` +# by listing them between the last `cpp` and `--` # -# `1000 1000` = what user to run copyparty as +# `cpp cpp` = user/group to run copyparty as; can be IDs (1000 1000) # # unless you add -q to disable logging, you may want to remove the # following line to allow buffering (slightly better performance): @@ -24,7 +24,9 @@ ExecReload=/bin/kill -s USR1 $MAINPID ExecStartPre=+/bin/bash -c 'mkdir -p /run/tmpfiles.d/ && echo "x /tmp/pe-copyparty*" > /run/tmpfiles.d/copyparty.conf' # run copyparty -ExecStart=/bin/bash /usr/bin/prisonparty /var/lib/copyparty-jail 1000 1000 /etc/copyparty.d -- \ +ExecStart=/bin/bash /usr/bin/prisonparty /var/lib/copyparty-jail cpp cpp \ + /etc/copyparty.d \ + -- \ /usr/bin/python3 /usr/bin/copyparty -c /etc/copyparty.d/init [Install] diff --git a/contrib/systemd/prisonparty.service b/contrib/systemd/prisonparty.service index 8a310753..4b81303d 100644 --- a/contrib/systemd/prisonparty.service +++ b/contrib/systemd/prisonparty.service @@ -1,5 +1,5 @@ # this will start `/usr/local/bin/copyparty-sfx.py` -# in a chroot, preventing accidental access elsewhere +# in a chroot, preventing accidental access elsewhere, # and share '/mnt' with anonymous read+write # # installation: @@ -7,9 +7,9 @@ # 2) cp -pv prisonparty.service /etc/systemd/system && systemctl enable --now prisonparty # # expose additional filesystem locations to copyparty -# by listing them between the last `1000` and `--` +# by listing them between the last `cpp` and `--` # -# `1000 1000` = what user to run copyparty as +# `cpp cpp` = user/group to run copyparty as; can be IDs (1000 1000) # # you may want to: # change '/mnt::rw' to another location or permission-set @@ -32,7 +32,9 @@ ExecReload=/bin/kill -s USR1 $MAINPID ExecStartPre=+/bin/bash -c 'mkdir -p /run/tmpfiles.d/ && echo "x /tmp/pe-copyparty*" > /run/tmpfiles.d/copyparty.conf' # run copyparty -ExecStart=/bin/bash /usr/local/bin/prisonparty.sh /var/lib/copyparty-jail 1000 1000 /mnt -- \ +ExecStart=/bin/bash /usr/local/bin/prisonparty.sh /var/lib/copyparty-jail cpp cpp \ + /mnt \ + -- \ /usr/bin/python3 /usr/local/bin/copyparty-sfx.py -q -v /mnt::rw [Install]