From 48408744548c0e054927141f3c43e537d7cae331 Mon Sep 17 00:00:00 2001 From: "Kyle J. McKay" Date: Sat, 29 Jun 2013 16:55:19 -0700 Subject: [PATCH] Switch ref-change to take username instead of uid The $UID variable is not available in the standard /bin/sh. Even though jailsetup.sh copies /bin/sh into the jail, reop.or.cz was running with /bin/bash copied into the jail as bin/sh. This allowed repo.or.cz to work correctly with a post-receive hook that passes on $UID, but not new installations that depend on jailsetup.sh to build the chroot bin directory. Since $LOGNAME is readily available in the chroot bin/sh shell, it is passed to ref-change instead of trying to convert to a uid. When post-receive is called from outside the chroot jail (currently only possible with https push), the name of the push user will be passed instead of $LOGNAME. Where jobd/update.sh used to pass "-1" to indicate the project, it now passes the project name between a pair of '%' characters. Since '%' is not allowed in user names there can be no confusion in taskd.pl. --- hooks/post-receive | 10 +++++++++- jobd/update.sh | 6 +++--- taskd/taskd.pl | 10 +++++----- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/hooks/post-receive b/hooks/post-receive index ebf450d..103ecc6 100755 --- a/hooks/post-receive +++ b/hooks/post-receive @@ -8,6 +8,7 @@ set -e sockpath=/etc/taskd.socket reporoot=/@jailreporoot@ +authuser="$LOGNAME" cwd="$(pwd)" if [ -x /usr/bin/perl ]; then # Not in chroot... @@ -15,13 +16,20 @@ if [ -x /usr/bin/perl ]; then sockpath="$cfg_chroot$sockpath" reporoot="$cfg_reporoot" + + # authuser needs to be set if not running in the chroot. + # Currently that can only be the case with https push in + # which case REMOTE_USER will contain the user name (possibly prefixed + # with "/UID="). Fallback is the mirror_user if REMOTE_USER is not set. + authuser="${REMOTE_USER#/UID=}" + [ -n authuser ] || authuser="$cfg_mirror_user" fi projname="${cwd#$reporoot/}" [ -S "$sockpath" ] || exit 0 while read line; do - echo "ref-change $UID ${projname%.git} $line" | /bin/nc.openbsd -w 1 -U "$sockpath" + echo "ref-change $authuser ${projname%.git} $line" | /bin/nc.openbsd -w 1 -U "$sockpath" done exit diff --git a/jobd/update.sh b/jobd/update.sh index f40afba..878e919 100755 --- a/jobd/update.sh +++ b/jobd/update.sh @@ -82,15 +82,15 @@ if [ -S "$sockpath" ] && ! cmp -s .refs-before .refs-after; then join -j 1 .refs-before .refs-after | while read ref old new; do [ "$old" != "$new" ] || continue - echo "ref-change -1 $proj $old $new $ref" | nc.openbsd -w 1 -U "$sockpath" + echo "ref-change %$proj% $proj $old $new $ref" | nc.openbsd -w 1 -U "$sockpath" done join -j 1 -v 1 .refs-before .refs-after | while read ref old; do - echo "ref-change -1 $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd -w 1 -U "$sockpath" + echo "ref-change %$proj% $proj $old 0000000000000000000000000000000000000000 $ref" | nc.openbsd -w 1 -U "$sockpath" done join -j 1 -v 2 .refs-before .refs-after | while read ref new; do - echo "ref-change -1 $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd -w 1 -U "$sockpath" + echo "ref-change %$proj% $proj 0000000000000000000000000000000000000000 $new $ref" | nc.openbsd -w 1 -U "$sockpath" done fi diff --git a/taskd/taskd.pl b/taskd/taskd.pl index c595713..15d6251 100755 --- a/taskd/taskd.pl +++ b/taskd/taskd.pl @@ -96,18 +96,18 @@ sub clone { sub ref_change { my ($arg) = @_; - my ($uid, $name, $oldrev, $newrev, $ref) = split(/\s+/, $arg); + my ($username, $name, $oldrev, $newrev, $ref) = split(/\s+/, $arg); my $proj = Girocco::Project->load($name); $proj or die "failed to load project $name"; my $user; - if ($uid >= 0) { - $user = Girocco::User->load_by_uid($uid); - $user or die "failed to load user $uid"; + if ($username && $username !~ /^%.*%$/) { + $user = Girocco::User->load($username); + $user or die "failed to load user $username"; } - print STDERR "ref-change $uid $name ($ref: $oldrev -> $newrev)\n"; + print STDERR "ref-change $username $name ($ref: $oldrev -> $newrev)\n"; open STDIN, "