#! /usr/bin/env perl
# See the legal notice at the end of this file.
# This script uses the undocumented P4Broker REWRITE function to
# change any 'login' command into a 'login -a'. Add it to the
# depot with the '+k' filetype to include version information in
# the error output.
use strict;
use warnings FATAL => 'all';
use open qw / :std :utf8 /;
my $ver = join '@', map { m/^\$\S+: (.*) \$$/ }
'$File: //guest/jason_gibson/misc/triggers/broker_rewrite_login-a.pl $',
'$Change: 8673 $';
sub err { print "action:REJECT\nmessage:Broker trigger error ($ver): @_" }
sub BEGIN { $SIG{ __DIE__ } = $SIG{ __WARN__ } = \ *err }
use Getopt::Long 'GetOptionsFromArray';
my %info = map { /(.*?)\s*:\s*(.*)/ } <STDIN>;
my @args = map { $info{ $_ } } sort grep { /^Arg\d+$/ } keys %info;
my $orig_args = join "\n", map { "arg:$_" } @args;
my ( $print, $status, $host, $all, $explain ) = ( 0 ) x 5;
Getopt::Long::Configure 'bundling';
GetOptionsFromArray \ @args, 'p|print' => \ $print, 's|status' => \ $status,
'h|host=s' => \ $host , 'a|all' => \ $all,
'explain' => \ $explain
or err 'getopt?';
print "action:PASS\n" and exit if $all or $explain or $status;
print "action:REWRITE\ncommand:login\narg:-a\n$orig_args";
__END__
Some debugging code:
use Data::Dumper;
$Data::Dumper::Quotekeys = 0;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Terse = 1;
print "action:PASS\nmessage:\"" . Dumper( \ %info ) .
" print $print status $status host $host all $all, oa '$orig_args'\n\"";
exit;
################################################################################
Copyright (c) 2014, Perforce Software, Inc. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL PERFORCE SOFTWARE, INC. BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
User contributed content on the Perforce Public Depot is not supported by
Perforce, although it may be supported by its author. This applies to all
contributions even those submitted by Perforce employees.