refactor: drop dead weight (unused param, duplicate checks, dead code)

- tmux_party_setup_server took an unused name parameter; drop it.
- validate_party_name ran two separate case blocks with a length
  check between them; merge into one case now that the length check
  (which an empty name always passes) runs first.
- roster_read now applies the RR_GROUP fallback to TMUX_PARTY_GROUP
  once, so cmd_join, cmd_invite, and cmd_list no longer each repeat
  ${RR_GROUP:-$TMUX_PARTY_GROUP}.
- socket_path had no caller in party; remove it and its test.
This commit is contained in:
veg 2026-09-21 09:46:05 +00:00
parent bdcad47147
commit d51656c9e4
2 changed files with 22 additions and 28 deletions

45
party
View file

@ -103,16 +103,18 @@ EOF
# name as a flag, so such a party could never be addressed.
validate_party_name() {
name="$1"
case "$name" in
'' ) echo "party: name must not be empty" >&2; return 2 ;;
esac
# Length cap: 63 keeps the full socket path comfortably below the
# 108-char sun_path limit for typical USERs.
# 108-char sun_path limit for typical USERs. Runs before the empty/
# shape checks below; an empty name has length 0, so it always
# passes this check and falls through to the '' case there.
if [ "${#name}" -gt 63 ]; then
echo "party: name '$name' too long (max 63 chars)" >&2
return 2
fi
case "$name" in
'' )
echo "party: name must not be empty" >&2
return 2 ;;
-* )
echo "party: name must not start with '-'" >&2
return 2 ;;
@ -200,10 +202,6 @@ roster_record_path() {
printf '%s/roster\n' "$(party_dir_path "$1" "$2")"
}
socket_path() {
printf '%s/sock\n' "$(party_dir_path "$1" "$2")"
}
# Roster I/O
# ----------
#
@ -326,6 +324,10 @@ roster_read() {
'' | \#*) ;;
esac
done < "$rec"
# A roster written before --group existed (or otherwise missing
# GROUP=) gates on the default group; callers can rely on RR_GROUP
# always naming the party's actual perimeter.
[ -n "$RR_GROUP" ] || RR_GROUP=$TMUX_PARTY_GROUP
return 0
}
@ -565,7 +567,7 @@ party_self_path() {
# All commands run against -S "$sock". Every literal name embedded
# is shell-quoted to survive tmux's parser.
tmux_party_setup_server() {
sock="$1" name="$2"
sock="$1"
# Write a tiny notification helper next to the socket. The leading dot
# keeps it out of typical `ls` listings. The per-party private dir
@ -872,7 +874,7 @@ EOF
# apply_party_perms_file widens it AFTER server-access -aw runs.
"$PARTY_TMUX" -S "$sock" new-session -d -s "$name"
tmux_party_setup_server "$sock" "$name"
tmux_party_setup_server "$sock"
# Auth gate FIRST, server-access runs BEFORE we widen FS perms.
# This closes the connect-before-allowlist race: without this order,
@ -1192,7 +1194,7 @@ EOF
# segments.
: >> "$logfile"
chmod 0640 "$logfile"
chgrp "${RR_GROUP:-$TMUX_PARTY_GROUP}" "$logfile"
chgrp "$RR_GROUP" "$logfile"
# Filter to unpiped panes ourselves rather than trusting `-o` to
# skip them: on tmux 3.5a, `-o` toggles an existing pipe closed
@ -1253,10 +1255,9 @@ EOF
# FS perimeter on the per-party dir already blocks non-group readers
# at roster_list; this preflight just turns that into a friendlier
# error than "party not found" when membership is the actual cause.
party_group="${RR_GROUP:-$TMUX_PARTY_GROUP}"
if ! user_in_group "$USER" "$party_group"; then
if ! user_in_group "$USER" "$RR_GROUP"; then
cat >&2 <<EOF
party: '$RR_PARTY_NAME' uses group '$party_group'; you ($USER) are not a member.
party: '$RR_PARTY_NAME' uses group '$RR_GROUP'; you ($USER) are not a member.
Ask the host or your sysadmin to add you, then log out and back in.
EOF
@ -1469,12 +1470,11 @@ cmd_invite() {
# the guest sees a write(1) ping, but `party join` reports not-found.
# Warn-and-proceed (rather than hard-fail) so a later usermod -aG
# doesn't require a re-invite.
invite_group="${RR_GROUP:-$TMUX_PARTY_GROUP}"
if ! user_in_group "$user" "$invite_group"; then
if ! user_in_group "$user" "$RR_GROUP"; then
cat >&2 <<EOF
party invite: warning, '$user' is not in group '$invite_group'.
party invite: warning, '$user' is not in group '$RR_GROUP'.
They will not be able to discover or join until added.
Run: sudo usermod -aG $invite_group $user (and have them relog).
Run: sudo usermod -aG $RR_GROUP $user (and have them relog).
EOF
fi
@ -1576,15 +1576,14 @@ cmd_list() {
# metadata leak; it only stops `party list` from DISPLAYING parties
# whose group the caller isn't in. Confidentiality still rides on
# the FS perimeter alone.
list_group="${RR_GROUP:-$TMUX_PARTY_GROUP}"
printf '%s\n' "$_ls_groups" | grep -qx "$list_group" || continue
printf '%s\n' "$_ls_groups" | grep -qx "$RR_GROUP" || continue
# The group tag only earns its column when the visible parties
# disagree on it. Which group gates a party is decided per host
# (auto-selection), so there is no default to compare against:
# tag every line, then strip the tags below unless they differ.
[ -n "$first_group" ] || first_group="$list_group"
[ "$list_group" = "$first_group" ] || mixed=1
group_tag=" [group=$list_group]"
[ -n "$first_group" ] || first_group="$RR_GROUP"
[ "$RR_GROUP" = "$first_group" ] || mixed=1
group_tag=" [group=$RR_GROUP]"
if [ "$state" = ok ]; then
attendees=$("$PARTY_TMUX" -S "$RR_SOCKET" list-clients 2>/dev/null | wc -l | tr -d ' ')
line=$(printf '%-12s %-30s %s attendee(s)%s' \

View file

@ -17,11 +17,6 @@ setup() {
[ "$out" = "$PARTY_SOCKET_DIR/party-veg:debug-the-deploy.d" ]
}
@test "socket_path lives inside the per-party private dir" {
out=$(socket_path "veg" "debug-the-deploy")
[ "$out" = "$PARTY_SOCKET_DIR/party-veg:debug-the-deploy.d/sock" ]
}
@test "roster_write then roster_read round-trips all fields" {
ensure_party_dir "$USER" "rt-test"
rec=$(roster_record_path "$USER" "rt-test")