~ubuntu-branches/ubuntu/vivid/gitolite3/vivid-proposed

« back to all changes in this revision

Viewing changes to src/lib/Gitolite/Triggers/Kindergarten.pm

  • Committer: Package Import Robot
  • Author(s): David Bremner
  • Date: 2014-10-06 12:30:00 UTC
  • mfrom: (1.1.4)
  • Revision ID: package-import@ubuntu.com-20141006123000-pzkzr0u220sjmpg7
Tags: 3.6.1-1
New upstream release (Closes: #755784)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package Gitolite::Triggers::Kindergarten;
 
2
 
 
3
# http://www.great-quotes.com/quote/424177
 
4
#   "Doctor, it hurts when I do this."
 
5
#   "Then don't do that!"
 
6
 
 
7
# Prevent various things that sensible people shouldn't be doing anyway. List
 
8
# of things it prevents is at the end of the program.
 
9
 
 
10
# If you were forced to enable this module because someone is *constantly*
 
11
# doing things that need to be caught, consider getting rid of that person.
 
12
# Because, really, who knows what *else* he/she is doing that can't be caught
 
13
# with some clever bit of code?
 
14
 
 
15
use Gitolite::Rc;
 
16
use Gitolite::Common;
 
17
 
 
18
use strict;
 
19
use warnings;
 
20
 
 
21
my %active;
 
22
sub active {
 
23
    # in rc, you either see just 'Kindergarten' to activate all features, or
 
24
    # 'Kindergarten U0 CREATOR' (i.e., a space sep list of features after the
 
25
    # word Kindergarten) to activate only those named features.
 
26
 
 
27
    # no features specifically activated; implies all of them are active
 
28
    return 1 if not %active;
 
29
    # else check if this specific feature is active
 
30
    return 1 if $active{ +shift };
 
31
 
 
32
    return 0;
 
33
}
 
34
 
 
35
my ( $verb, $repo, $cmd, $args );
 
36
sub input {
 
37
    # get the features to be activated, if supplied
 
38
    while ( $_[0] ne 'INPUT' ) {
 
39
        $active{ +shift } = 1;
 
40
    }
 
41
 
 
42
    # generally fill up variables you might use later
 
43
    my $git_commands = "git-upload-pack|git-receive-pack|git-upload-archive";
 
44
    if ( $ENV{SSH_ORIGINAL_COMMAND} =~ /($git_commands) '\/?(\S+)'$/ ) {
 
45
        $verb = $1;
 
46
        $repo = $2;
 
47
    } elsif ( $ENV{SSH_ORIGINAL_COMMAND} =~ /^(\S+) (.*)$/ ) {
 
48
        $cmd  = $1;
 
49
        $args = $2;
 
50
    }
 
51
 
 
52
    prevent_CREATOR($repo) if active('CREATOR') and $verb;
 
53
    prevent_0(@ARGV)       if active('U0')      and @ARGV;
 
54
}
 
55
 
 
56
sub prevent_CREATOR {
 
57
    my $repo = shift;
 
58
    _die "'CREATOR' not allowed as part of reponame" if $repo =~ /\bCREATOR\b/;
 
59
}
 
60
 
 
61
sub prevent_0 {
 
62
    my $user = shift;
 
63
    _die "'0' is not a valid username" if $user eq '0';
 
64
}
 
65
 
 
66
1;
 
67
 
 
68
__END__
 
69
 
 
70
CREATOR
 
71
 
 
72
    prevent literal 'CREATOR' from being part of a repo name
 
73
 
 
74
    a quirk deep inside gitolite would let this config
 
75
 
 
76
        repo foo/CREATOR/..*
 
77
            C   =   ...
 
78
 
 
79
    allow the creation of repos like "foo/CREATOR/bar", i.e., the word CREATOR is
 
80
    literally used.
 
81
 
 
82
    I consider this a totally pathological situation to check for.  The worst that
 
83
    can happen is someone ends up cluttering the server with useless repos.
 
84
 
 
85
    One solution could be to prevent this only for wild repos, but I can't be
 
86
    bothered to fine tune this, so this module prevents even normal repos from
 
87
    having the literal CREATOR in them.
 
88
 
 
89
    See https://groups.google.com/forum/#!topic/gitolite/cS34Vxix0Us for more.
 
90
 
 
91
U0
 
92
 
 
93
    prevent a user from being called literal '0'
 
94
 
 
95
    Ideally we should prevent keydir/0.pub (or variants) from being created,
 
96
    but for "Then don't do that" purposes it's enough to prevent the user from
 
97
    logging in.
 
98
 
 
99
    See https://groups.google.com/forum/#!topic/gitolite/F1IBenuSTZo for more.