summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSitaram Chamarty <sitaramc@gmail.com>2019-12-30 17:58:25 +0530
committerSitaram Chamarty <sitaramc@gmail.com>2020-01-01 11:29:50 +0530
commit8268fc3a46f48d227dfeeb3de9305dd051382022 (patch)
treee357fe66b3a2bcb1797a0f08ac14e376c42faa43
parent1a2d8c9e26366b82c75960a58b37fc674b3b1aa5 (diff)
'config' user command needs to allow for space-separated config values
This command: ssh git@host config my/wild/repo --add gitweb.owner "Sitaram Chamarty" doesn't work. Sshd converts it to config my/wild/repo --add gitweb.owner Sitaram Chamarty so by the time src/commands/config sees this, that looks like two "values" ("Sitaram" and "Chamarty") instead of one. We can't do much about this in the general case; that's how sshd rolls. I suppose we could, in parse_soc() in src/gitolite-shell, use something like Text::ParseWords instead of a simple "split" (and then send in arguments with backslash-escaped spaces etc) but that's too big a change impacting too many things. Not going to happen for this simple need. The simplest way out is for src/commands/config to learn that multiple trailing arguments are actually one space-separated argument.
-rwxr-xr-xsrc/commands/config19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/commands/config b/src/commands/config
index 7851c11..214158b 100755
--- a/src/commands/config
+++ b/src/commands/config
@@ -63,8 +63,8 @@ usage() if not @ARGV or $ARGV[0] eq '-h';
my $repo = shift;
-my ($op, $key, $val) = @ARGV;
-usage() unless $op and exists $nargs{$op} and @ARGV == $nargs{$op};
+my $op = shift;
+usage() unless $op and exists $nargs{$op};
# ----------------------------------------------------------------------
# authorisation checks
@@ -81,15 +81,30 @@ die "sorry, you are not authorised\n" unless
# key validity checks
unless ($op eq '--list') {
+ my $key = shift;
+
+ my $val = '';
+ $val = join(" ", @ARGV) if @ARGV;
+ # values with spaces embedded get flattened by sshd when it passes
+ # SSH_ORIGINAL_COMMAND to gitolite. In this specific instance, we will
+ # pretend we know what the user meant, and join up the last 1+ args into
+ # one space-separated arg.
+
my $user_configs = option( $repo, 'user-configs' );
# this is a space separated list of allowed config keys
my @validkeys = split( ' ', ( $user_configs || '' ) );
my @matched = grep { $key =~ /^$_$/i } @validkeys;
_die "config '$key' not allowed\n" if ( @matched < 1 );
+
+ @ARGV = ($key);
+ push @ARGV, $val if $val;
}
# ----------------------------------------------------------------------
# go!
+unshift @ARGV, $op;
+usage() unless @ARGV == $nargs{$op};
+
_chdir("$rc{GL_REPO_BASE}/$repo.git");
_system( "git", "config", @ARGV );