2011-09-13 11:41:51 +02:00
|
|
|
#!/usr/bin/perl
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use warnings;
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# BEGIN site-local changes
|
|
|
|
|
|
|
|
# the original login shell your users had (or) the shell to forward
|
|
|
|
# non-gitolite commands to
|
|
|
|
my $shell = "/usr/bin/passwd";
|
|
|
|
|
|
|
|
# exceptions...
|
|
|
|
my %shells = (
|
|
|
|
'some.one' => '/bin/bash',
|
|
|
|
);
|
|
|
|
|
|
|
|
# the gitolite host you want to forward git commands to. Typically this will
|
|
|
|
# be 'git' or perhaps 'gitolite', but actually could be anything. Don't
|
|
|
|
# forget to change the host part if needed and mind the quotes!
|
|
|
|
my $gl_host = 'git@server2';
|
|
|
|
|
|
|
|
# ADCs...
|
|
|
|
# either list all the ADCs you wish to allow forwarding to (SPACE-separated):
|
|
|
|
my $ADC_list = "";
|
|
|
|
# -- OR --
|
|
|
|
# if you upgraded to the new 'help' adc with the '-list' option, set this to 1:
|
|
|
|
my $detect_ADCs = 0;
|
|
|
|
# if you do neither, ADCs are not forwarded
|
|
|
|
|
|
|
|
# END site-local changes
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# change the user's default shell if he is an 'exception'
|
|
|
|
$shell= $shells{$ENV{USER}} if $shells{$ENV{USER}};
|
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# no arguments? nothing to forward
|
2011-11-15 12:47:16 +01:00
|
|
|
exec($shell) if (not @ARGV and not $ENV{SSH_ORIGINAL_COMMAND});
|
|
|
|
|
|
|
|
# note: we attempt to work the same whether invoked via 'command=' of authkeys
|
|
|
|
# (in which case SSH_ORIGINAL_COMMAND is set) or via us being the login shell
|
|
|
|
# (chsh). Only the latter has been *tested* though.
|
|
|
|
|
|
|
|
# massage SSHOC into @ARGV shape for ease of parsing
|
|
|
|
@ARGV = ("-c", $ENV{SSH_ORIGINAL_COMMAND}) if $ENV{SSH_ORIGINAL_COMMAND};
|
|
|
|
# we ignore SSHOC from now on...
|
|
|
|
|
|
|
|
# ------------------------------------------------------------------------------
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# forward normal git ops
|
|
|
|
forward(@ARGV) if
|
|
|
|
$ARGV[0] eq '-c' and
|
|
|
|
$ARGV[1] =~ /^(git-receive-pack|git-upload-pack|git-upload-archive) '(\S+)'$/ and
|
|
|
|
( not -d "$2" );
|
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# forward gitolite special commands
|
|
|
|
forward(@ARGV) if $ARGV[0] eq '-c' and $ARGV[1] =~ /^(info|expand|((set|get)(perms|desc)))( |$)/;
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# forward ADCs
|
|
|
|
if ($ADC_list or $detect_ADCs) {
|
2011-11-15 12:47:16 +01:00
|
|
|
$ADC_list ||= `ssh $gl_host help -list`;
|
2011-09-15 17:53:51 +02:00
|
|
|
$ADC_list =~ s/\s+/ /g;
|
|
|
|
|
|
|
|
# find the command he's running
|
|
|
|
my $cmd = $1 if $ARGV[1] =~ /^(\S+)/;
|
|
|
|
# forward if the command appears somewhere in the ADC list
|
|
|
|
forward(@ARGV) if $ARGV[0] eq '-c' and $cmd and $ADC_list =~ /(^| )$cmd( |$)/;
|
|
|
|
}
|
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# at this point it's back to local processing
|
|
|
|
exec($shell, @ARGV);
|
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# ------------------------------------------------------------------------------
|
2011-09-15 17:53:51 +02:00
|
|
|
# ------------------------------------------------------------------------------
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-11-15 12:47:16 +01:00
|
|
|
# forward to the gitolite host
|
2011-09-15 17:53:51 +02:00
|
|
|
sub forward {
|
|
|
|
# this message is important in debugging and trouble shooting; see
|
|
|
|
# documentation
|
2011-11-15 12:47:16 +01:00
|
|
|
print STDERR "[forwarding to $gl_host]\n";
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
# but first we check for rsa key
|
|
|
|
-f ".ssh/id_rsa" or die "ask your admin to add you to gitolite";
|
2011-09-13 11:41:51 +02:00
|
|
|
|
2011-09-15 17:53:51 +02:00
|
|
|
shift if $_[0] eq '-c';
|
2011-11-15 12:47:16 +01:00
|
|
|
exec("ssh", "$gl_host", @_);
|
2011-09-15 17:53:51 +02:00
|
|
|
}
|