From 5971d0f2262b30a6cbbac2aec17057bbd791f38d Mon Sep 17 00:00:00 2001 From: Clayton Craft Date: Sun, 28 Dec 2025 12:57:36 +0100 Subject: [PATCH] main/postmarketos-usb-moded: use a generator to configure UID/GID for umtprd MTP transfers write files to the home folder of the user. If no GID and UID are specified, uMTP-responder will use the GID/UID under which it is running at the time of the file transfer. This causes users to not be able to access the files on the device after transfering. This patch adds a systemd generator that: 1) reads /etc/default_user, and appends config to /etc/umtprd/umtprd.conf to set the MTP default user/group. If this file doesn't exist, 10000:10000 is the fallback uid:gid. 2) installs this config to /run/umtprd/umptrd.conf 3) adds a unit override to /run for umtprd.service that runs the daemon with this modified config The generator is used instead of hardcoding a uid and gid in umtprd.conf so that this can support immutable installs or situations where the default UID/GID is not 10000. Co-authored-by: Dylan Van Assche Signed-off-by: Clayton Craft Part-of: --- .ci/shellcheck.sh | 1 + main/postmarketos-usb-moded/APKBUILD | 4 +- ...-system-generators-umtprd-config-generator | 39 +++++++++++++++++++ 3 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 main/postmarketos-usb-moded/rootfs-usr-lib-systemd-system-generators-umtprd-config-generator diff --git a/.ci/shellcheck.sh b/.ci/shellcheck.sh index 26094a505..46445137c 100755 --- a/.ci/shellcheck.sh +++ b/.ci/shellcheck.sh @@ -21,6 +21,7 @@ sh_files=" ./main/postmarketos-initramfs/init_functions.sh ./main/postmarketos-mkinitfs-hook-netboot/netboot.sh ./main/postmarketos-ui-os-installer/rootfs-usr-bin-pmos_setup.sh + ./main/postmarketos-usb-moded/rootfs-usr-lib-systemd-system-generators-umtprd-config-generator ./main/ttyescape/*.post-install ./main/unl0kr/unlock.sh ./device/community/soc-qcom/call_audio_idle_suspend_workaround.sh diff --git a/main/postmarketos-usb-moded/APKBUILD b/main/postmarketos-usb-moded/APKBUILD index ebc757762..8c24a8a91 100644 --- a/main/postmarketos-usb-moded/APKBUILD +++ b/main/postmarketos-usb-moded/APKBUILD @@ -1,6 +1,6 @@ # Maintainer: Clayton Craft pkgname=postmarketos-usb-moded -pkgver=1 +pkgver=2 pkgrel=0 pkgdesc="Meta package for configuring usb-moded on postmarketOS" url="https://postmarketos.org" @@ -31,6 +31,7 @@ _source644=" _source755=" usr/bin/usb-moded-developer-mode usr/bin/usb-moded-tethering-mode + usr/lib/systemd/system-generators/umtprd-config-generator " # Avoid filename based checksum conflicts by including the whole path. @@ -99,4 +100,5 @@ af41dc4ceb7255dbb88273916306c6e7e66c879bb67523c9571f9e812c9b36ab00ea666ade49369c 79dc304cc5d455135f929a0ba60487f03b1b66d09245d972f685ee5ddabc8414f74159e47bbb13bff862163fa07dd9497a30ab7e32074bff95f2189685d851a2 rootfs-usr-lib-systemd-system-usb-moded.service.d-override.conf 9aab1a91a817e2337320ee0fa1bf6133e65e9269631560c1860c3b777adb336d036cebbc2510d1df35a82bf4396d553ff9e2edd0004027c7a3130168f7f50d90 rootfs-usr-bin-usb-moded-developer-mode 5cc40b1a0c86904d824f8f03e3f44900aaf407c5c462902f4f58cd58c603be1c5919651b91320983e21da42f5891e29df504bf4f1bddef64fedc68c2accdccbc rootfs-usr-bin-usb-moded-tethering-mode +ca4b82b0cccbbb498b8898c4e360142136c46687e97bce85553dc1793bf8ae2e0f509c2a1acdf96b08dc7c6b69f098b56181f9033ad669cabbf5a159ad8efbaa rootfs-usr-lib-systemd-system-generators-umtprd-config-generator " diff --git a/main/postmarketos-usb-moded/rootfs-usr-lib-systemd-system-generators-umtprd-config-generator b/main/postmarketos-usb-moded/rootfs-usr-lib-systemd-system-generators-umtprd-config-generator new file mode 100644 index 000000000..4bb6fe7a7 --- /dev/null +++ b/main/postmarketos-usb-moded/rootfs-usr-lib-systemd-system-generators-umtprd-config-generator @@ -0,0 +1,39 @@ +#!/bin/sh +# systemd generator for uMTP-Responder configuration +# Generates config with user UID/GID in /run + +set -e + +late_dir="$3" + +# fallback UID/GID +uid=10000 +gid=10000 + +user_file="/etc/default_user" +if [ -f "$user_file" ]; then + user=$(cat "$user_file") + if [ -n "$user" ]; then + # Get UID/GID, fall back to defaults on failure + uid=$(id -u "$user" 2>/dev/null || echo 10000) + gid=$(id -g "$user" 2>/dev/null || echo 10000) + fi +fi + +mkdir -p /run/umtprd + +cat /etc/umtprd/umtprd.conf > /run/umtprd/umtprd.conf +cat << EOF >> /run/umtprd/umtprd.conf + +# GID/UID for file operations (generated) +default_uid $uid +default_gid $gid +EOF + +# unit override to use generated config +mkdir -p "${late_dir}/umtprd.service.d" +cat << EOF > "${late_dir}/umtprd.service.d/10-config-path.conf" +[Service] +ExecStart= +ExecStart=/usr/bin/umtprd -conf /run/umtprd/umtprd.conf +EOF