2011-01-15 16:39:56 +01:00
# lots of common routines
package gitolite ;
use Exporter 'import' ;
@ EXPORT = qw(
can_read
check_access
check_ref
check_repo_write_enabled
cli_repo_rights
dbg
(minor) setperms and DOS users
Supporting git on DOS may be a fact of life, but it felt good to make
them use the "right" editor (hint: starts with v, ends with m, has three
letters), or at least something equivalent, to produce their setperms
input files.
I'd say "yes Fred I know. However, Unix doesn't work like that, and
when talking to a big, important, OS like Unix from your little
single-user workstation, you do have to go the extra mile. It's not
that different from going into a meeting with the CEO you know -- you
dress up a little for that meeting don't you?". And Fred would nod, a
little awed by the analogy. Maybe the awe was tinged with a wee bit of
anger but not much; he knows there's a hierarchy among OSs, just like
among people, and he knows where his OS stands in that hierarchy...
----
For the humour impaired, that was a joke. To start with, I don't know
anyone called Fred.
It *is* true that I tend to ignore DOS if at all possible, especially in
my *code*. But since I don't really use wildrepos at work, this issue
would never have come up for me, even in the DOS projects I manage.
In this case someone who's contributed a heck of a lot to the evolution
of gitolite asked, so here it is.
----
oh and in case you were wondering, DOS stands for "dominant operating
system" ;-)
2011-07-23 02:32:12 +02:00
dos2unix
2011-01-15 16:39:56 +01:00
list_phy_repos
ln_sf
log_it
new_repo
new_wild_repo
repo_rights
run_custom_command
setup_authkeys
setup_daemon_access
setup_git_configs
setup_gitweb_access
shell_out
2011-08-12 18:29:10 +02:00
slurp
2011-01-15 16:39:56 +01:00
special_cmd
try_adc
wrap_chdir
wrap_open
wrap_print
2011-08-12 18:29:10 +02:00
mirror_mode
mirror_listslaves
mirror_redirectOK
2011-01-15 16:39:56 +01:00
) ;
@ EXPORT_OK = qw(
% repos
% groups
% git_configs
% split_conf
) ;
2010-02-04 10:46:47 +01:00
use strict ;
2011-01-15 16:39:56 +01:00
use warnings ;
2010-05-10 08:16:47 +02:00
use Data::Dumper ;
$ Data:: Dumper:: Deepcopy = 1 ;
2010-08-19 16:49:16 +02:00
$| + + ;
2010-05-10 08:16:47 +02:00
2011-01-15 16:39:56 +01:00
# ----------------------------------------------------------------------------
# find the rc file, then pull the libraries
# ----------------------------------------------------------------------------
2009-10-25 03:59:52 +01:00
2011-01-15 16:39:56 +01:00
BEGIN {
die "ENV GL_RC not set\n" unless $ ENV { GL_RC } ;
die "ENV GL_BINDIR not set\n" unless $ ENV { GL_BINDIR } ;
}
2009-10-25 03:59:52 +01:00
2011-03-05 03:11:29 +01:00
# ----------------------------------------------------------------------------
# register signal handlers to log any problems
# ----------------------------------------------------------------------------
BEGIN {
$ SIG { __DIE__ } = sub {
my $ msg = join ( ' ' , "Die generated at line" , ( caller ) [ 2 ] , "in" , ( caller ) [ 1 ] , ":" , @ _ , "\n" ) ;
$ msg =~ s/[\n\r]+/<<newline>>/g ;
2011-06-08 08:13:07 +02:00
log_it ( $ msg ) if $ ENV { GL_LOG } ;
2011-03-05 03:11:29 +01:00
} ;
$ SIG { __WARN__ } = sub {
my $ msg = join ( ' ' , "Warn generated at line" , ( caller ) [ 2 ] , "in" , ( caller ) [ 1 ] , ":" , @ _ , "\n" ) ;
$ msg =~ s/[\n\r]+/<<newline>>/g ;
2011-06-08 08:13:07 +02:00
log_it ( $ msg ) if $ ENV { GL_LOG } ;
2011-03-05 03:11:29 +01:00
warn @ _ ;
} ;
}
2011-01-15 16:39:56 +01:00
use lib $ ENV { GL_BINDIR } ;
use gitolite_rc ;
2009-10-25 03:59:52 +01:00
2009-12-04 05:21:22 +01:00
# ----------------------------------------------------------------------------
2011-01-15 16:39:56 +01:00
# the big data structures we care about
2009-12-04 05:21:22 +01:00
# ----------------------------------------------------------------------------
2010-02-04 10:46:47 +01:00
our % repos ;
2010-05-10 08:16:47 +02:00
our % groups ;
2011-01-01 07:02:58 +01:00
our % git_configs ;
2011-01-15 16:39:56 +01:00
our % split_conf ;
2010-05-21 10:38:05 +02:00
our $ data_version ;
2009-12-04 05:21:22 +01:00
2011-01-01 10:44:54 +01:00
# the following are read in from individual repo's gl-conf files, if present
2011-01-15 16:39:56 +01:00
our % one_repo ; # corresponds to what goes into %repos
our % one_git_config ; # ditto for %git_configs
2011-01-01 10:44:54 +01:00
2009-12-04 05:21:22 +01:00
# ----------------------------------------------------------------------------
# convenience subs
# ----------------------------------------------------------------------------
sub wrap_chdir {
chdir ( $ _ [ 0 ] ) or die "$ABRT chdir $_[0] failed: $! at " , ( caller ) [ 1 ] , " line " , ( caller ) [ 2 ] , "\n" ;
}
sub wrap_open {
open ( my $ fh , $ _ [ 0 ] , $ _ [ 1 ] ) or die "$ABRT open $_[1] failed: $! at " , ( caller ) [ 1 ] , " line " , ( caller ) [ 2 ] , "\n" .
( $ _ [ 2 ] || '' ) ; # suffix custom error message if given
return $ fh ;
}
2010-08-20 17:25:23 +02:00
sub wrap_print {
2011-03-08 01:48:59 +01:00
my ( $ file , @ text ) = @ _ ;
2011-05-24 16:54:42 +02:00
my $ fh = wrap_open ( ">" , "$file.$$" ) ;
2011-03-08 01:48:59 +01:00
print $ fh @ text ;
close ( $ fh ) or die "$ABRT close $file failed: $! at " , ( caller ) [ 1 ] , " line " , ( caller ) [ 2 ] , "\n" ;
2011-05-24 16:54:42 +02:00
rename "$file.$$" , $ file ;
2011-03-08 01:48:59 +01:00
}
sub slurp {
local $/ = undef ;
my $ fh = wrap_open ( "<" , $ _ [ 0 ] ) ;
return <$fh> ;
2010-08-20 17:25:23 +02:00
}
2010-08-20 19:17:34 +02:00
sub add_del_line {
my ( $ line , $ file , $ flag ) = @ _ ;
my $ contents ;
local $/ = undef ;
my $ fh = wrap_open ( "<" , $ file ) ;
$ contents = <$fh> ;
$ contents =~ s/\s+$/\n/ ;
if ( $ flag and $ contents !~ /^\Q$line\E$/m ) {
# add line if it doesn't exist
$ contents . = "$line\n" ;
wrap_print ( $ file , $ contents ) ;
}
if ( not $ flag and $ contents =~ /^\Q$line\E$/m ) {
$ contents =~ s/^\Q$line\E(\n|$)//m ;
wrap_print ( $ file , $ contents ) ;
}
}
2010-07-20 09:09:06 +02:00
sub dbg {
2011-01-15 16:39:56 +01:00
use Data::Dumper ;
2010-07-20 09:09:06 +02:00
for my $ i ( @ _ ) {
2011-01-15 16:39:56 +01:00
print STDERR "DBG: " . Dumper ( $ i ) ;
2010-07-20 09:09:06 +02:00
}
}
(minor) setperms and DOS users
Supporting git on DOS may be a fact of life, but it felt good to make
them use the "right" editor (hint: starts with v, ends with m, has three
letters), or at least something equivalent, to produce their setperms
input files.
I'd say "yes Fred I know. However, Unix doesn't work like that, and
when talking to a big, important, OS like Unix from your little
single-user workstation, you do have to go the extra mile. It's not
that different from going into a meeting with the CEO you know -- you
dress up a little for that meeting don't you?". And Fred would nod, a
little awed by the analogy. Maybe the awe was tinged with a wee bit of
anger but not much; he knows there's a hierarchy among OSs, just like
among people, and he knows where his OS stands in that hierarchy...
----
For the humour impaired, that was a joke. To start with, I don't know
anyone called Fred.
It *is* true that I tend to ignore DOS if at all possible, especially in
my *code*. But since I don't really use wildrepos at work, this issue
would never have come up for me, even in the DOS projects I manage.
In this case someone who's contributed a heck of a lot to the evolution
of gitolite asked, so here it is.
----
oh and in case you were wondering, DOS stands for "dominant operating
system" ;-)
2011-07-23 02:32:12 +02:00
sub dos2unix {
# WARNING: when calling this, make sure you supply a list context
s/\r\n/\n/g for @ _ ;
return @ _ ;
}
2010-01-31 18:40:12 +01:00
sub log_it {
2010-06-16 03:50:12 +02:00
my ( $ ip , $ logmsg ) ;
2010-01-31 18:40:12 +01:00
open my $ log_fh , ">>" , $ ENV { GL_LOG } or die "open log failed: $!\n" ;
2010-06-16 03:50:12 +02:00
# first space sep field is client ip, per "man ssh"
2011-02-25 16:01:11 +01:00
( $ ip = $ ENV { SSH_CONNECTION } || '(no-IP)' ) =~ s/ .*// ;
2010-06-16 03:50:12 +02:00
# the first part of logmsg is the actual command used; it's either passed
# in via arg1, or picked up from SSH_ORIGINAL_COMMAND
$ logmsg = $ _ [ 0 ] || $ ENV { SSH_ORIGINAL_COMMAND } ; shift ;
# the rest of it upto the caller; we just dump it into the logfile
$ logmsg . = "\t@_" if @ _ ;
2011-03-05 01:11:21 +01:00
# erm... this is hard to explain so just see the commit message ok?
2011-03-05 03:11:29 +01:00
$ logmsg =~ s/([\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\xFF]+)/sprintf "<<hex(%*v02X)>>","",$1/ge ;
2010-06-16 03:50:12 +02:00
print $ log_fh "$ENV{GL_TS}\t$ENV{GL_USER}\t$ip\t$logmsg\n" ;
2010-01-31 18:40:12 +01:00
close $ log_fh or die "close log failed: $!\n" ;
}
2010-02-05 02:19:07 +01:00
# ln -sf :-)
sub ln_sf
{
my ( $ srcdir , $ glob , $ dstdir ) = @ _ ;
for my $ hook ( glob ( "$srcdir/$glob" ) ) {
$ hook =~ s/$srcdir\/// ;
unlink "$dstdir/$hook" ;
2010-10-19 11:56:16 +02:00
symlink "$srcdir/$hook" , "$dstdir/$hook" or die "could not symlink $srcdir/$hook to $dstdir\n" ;
2010-02-05 02:19:07 +01:00
}
}
2011-01-01 10:44:54 +01:00
# list physical repos
sub list_phy_repos
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
{
2011-01-01 10:44:54 +01:00
my @ phy_repos ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
wrap_chdir ( $ REPO_BASE ) ;
2011-01-28 00:10:29 +01:00
for my $ repo ( `find . -type d -name "*.git" -prune` ) {
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
chomp ( $ repo ) ;
$ repo =~ s(\./(.*) \ . g i t $)($ 1 ) ;
2011-01-01 10:44:54 +01:00
push @ phy_repos , $ repo ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
}
2011-01-01 10:44:54 +01:00
return @ phy_repos ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
}
2009-10-25 03:59:52 +01:00
# ----------------------------------------------------------------------------
2011-01-15 16:39:56 +01:00
# serious logic subs (as opposed to just "convenience" subs)
2009-10-25 03:59:52 +01:00
# ----------------------------------------------------------------------------
2011-01-15 16:39:56 +01:00
# check one ref
sub check_ref {
2009-10-25 03:59:52 +01:00
2011-01-15 16:39:56 +01:00
# normally, the $ref will be whatever ref the commit is trying to update
# (like refs/heads/master or whatever). At least one of the refexes that
# pertain to this user must match this ref **and** the corresponding
# permission must also match the action (W/+, or C/D if used) being
# attempted. If none of them match, the access is denied.
2010-09-05 15:17:10 +02:00
2011-01-15 16:39:56 +01:00
# NOTE: the function DIES when access is denied, unless arg 5 is true
2010-09-05 15:17:10 +02:00
2011-01-15 16:39:56 +01:00
my ( $ allowed_refs , $ repo , $ ref , $ perm , $ dry_run ) = @ _ ;
my @ allowed_refs = sort { $ a - > [ 0 ] <=> $ b - > [ 0 ] } @ { $ allowed_refs } ;
for my $ ar ( @ allowed_refs ) {
my $ refex = $ ar - > [ 1 ] ;
# refex? sure -- a regex to match a ref against :)
next unless $ ref =~ /^$refex/ ;
return "DENIED by $refex" if $ ar - > [ 2 ] eq '-' and $ dry_run ;
die "$perm $ref $ENV{GL_USER} DENIED by $refex\n" if $ ar - > [ 2 ] eq '-' ;
2010-09-05 15:17:10 +02:00
2011-01-15 16:39:56 +01:00
# as far as *this* ref is concerned we're ok
return $ refex if ( $ ar - > [ 2 ] =~ /\Q$perm/ ) ;
2010-12-28 09:28:53 +01:00
}
2011-01-15 16:39:56 +01:00
return "DENIED by fallthru" if $ dry_run ;
die "$perm $ref $repo $ENV{GL_USER} DENIED by fallthru\n" ;
2009-10-25 03:59:52 +01:00
}
2009-12-04 05:21:22 +01:00
# ----------------------------------------------------------------------------
# create a new repository
# ----------------------------------------------------------------------------
2009-11-26 17:00:59 +01:00
# NOTE: this sub will change your cwd; caller beware!
sub new_repo
{
2010-04-25 19:09:27 +02:00
my ( $ repo , $ hooks_dir , $ creator ) = @ _ ;
2009-11-26 17:00:59 +01:00
umask ( $ REPO_UMASK ) ;
2010-04-25 19:09:27 +02:00
die "wildrepos disabled, can't set creator $creator on new repo $repo\n"
if $ creator and not $ GL_WILDREPOS ;
2009-11-26 17:00:59 +01:00
system ( "mkdir" , "-p" , "$repo.git" ) and die "$ABRT mkdir $repo.git failed: $!\n" ;
# erm, note that's "and die" not "or die" as is normal in perl
wrap_chdir ( "$repo.git" ) ;
system ( "git --bare init >&2" ) ;
2010-04-25 19:09:27 +02:00
if ( $ creator ) {
2011-03-08 01:48:59 +01:00
wrap_print ( "gl-creater" , $ creator ) ;
2010-04-25 19:09:27 +02:00
system ( "git" , "config" , "gitweb.owner" , $ creator ) ;
2010-02-03 18:11:09 +01:00
}
2009-11-26 17:00:59 +01:00
# propagate our own, plus any local admin-defined, hooks
2010-02-05 02:19:07 +01:00
ln_sf ( $ hooks_dir , "*" , "hooks" ) ;
2010-02-10 11:49:20 +01:00
# in case of package install, GL_ADMINDIR is no longer the top cop;
# override with the package hooks
ln_sf ( "$GL_PACKAGE_HOOKS/common" , "*" , "hooks" ) if $ GL_PACKAGE_HOOKS ;
2009-11-26 17:00:59 +01:00
chmod 0755 , "hooks/update" ;
2010-09-24 12:49:33 +02:00
# run gitolite's post-init hook if you can. GL_REPO will be correct on a
# wildcard create but on a normal (config file) create it will actually be
# set to "gitolite-admin", so we need to make sure that for the duration
# of the hook it is set correctly.
2011-03-08 01:48:59 +01:00
system ( "env" , "GL_REPO=$repo" , "hooks/gl-post-init" ) if - x "hooks/gl-post-init" ;
2009-11-26 17:00:59 +01:00
}
2011-01-15 16:39:56 +01:00
sub new_wild_repo {
my ( $ repo , $ user ) = @ _ ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
wrap_chdir ( $ REPO_BASE ) ;
2011-01-15 16:39:56 +01:00
new_repo ( $ repo , "$GL_ADMINDIR/hooks/common" , $ user ) ;
# note pwd is now the bare "repo.git"; new_repo does that...
wrap_print ( "gl-perms" , "$GL_WILDREPOS_DEFPERMS\n" ) if $ GL_WILDREPOS_DEFPERMS ;
setup_git_configs ( $ repo , \ % git_configs ) ;
setup_daemon_access ( $ repo ) ;
add_del_line ( "$repo.git" , $ PROJECTS_LIST , setup_gitweb_access ( $ repo , '' , '' ) ) ;
wrap_chdir ( $ ENV { HOME } ) ;
}
2009-12-05 18:09:56 +01:00
# ----------------------------------------------------------------------------
2011-01-15 16:39:56 +01:00
# wild_repo_rights
2009-12-05 18:09:56 +01:00
# ----------------------------------------------------------------------------
{
2011-01-11 17:57:22 +01:00
# the following subs need some persistent data, so we make a closure
2010-08-21 06:26:11 +02:00
my $ cache_filled = 0 ;
my % cached_groups ;
2011-01-11 17:57:22 +01:00
sub fill_cache {
2010-08-21 06:26:11 +02:00
# pull in basic group info
unless ( $ cache_filled ) {
local ( % repos , % groups ) ;
2010-10-28 16:04:46 +02:00
local $^W = 0 ;
2010-08-21 06:26:11 +02:00
# read group info from compiled config. At the time we're called
# this info has not yet been pulled in by the rest of the code, so
# we need to do this specially here. However, the info we're
# looking for is not subject to variable substitutions so we don't
# really care; we just pull it in once and save it for the rest of
# the run
do $ GL_CONF_COMPILED ;
% cached_groups = % groups ;
$ cache_filled + + ;
}
2011-01-11 17:57:22 +01:00
}
# "who created this repo", "am I on the R list", and "am I on the RW list"?
sub wild_repo_rights
{
# set default categories
$ GL_WILDREPOS_PERM_CATS || = "READERS WRITERS" ;
my ( $ repo , $ user ) = @ _ ;
2010-08-21 06:26:11 +02:00
# creator
my $ c = '' ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
if ( - f "$REPO_BASE/$repo.git/gl-creater" ) {
my $ fh = wrap_open ( "<" , "$REPO_BASE/$repo.git/gl-creater" ) ;
2010-08-21 06:26:11 +02:00
chomp ( $ c = <$fh> ) ;
}
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# now get the permission categories (used to be just R and RW. Now
# there can be any others that the admin defines in the RC file via
# $GL_WILDREPOS_PERM_CATS variable (space separated list)
# For instance, if the user is "foo", and gl-perms has "R bar", "RW
# foo baz", and "TESTERS frob @all", this hash will then contain
# "WRITERS=>foo" and "TESTERS=>@all"
my % perm_cats ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
if ( $ user and - f "$REPO_BASE/$repo.git/gl-perms" ) {
(minor) setperms and DOS users
Supporting git on DOS may be a fact of life, but it felt good to make
them use the "right" editor (hint: starts with v, ends with m, has three
letters), or at least something equivalent, to produce their setperms
input files.
I'd say "yes Fred I know. However, Unix doesn't work like that, and
when talking to a big, important, OS like Unix from your little
single-user workstation, you do have to go the extra mile. It's not
that different from going into a meeting with the CEO you know -- you
dress up a little for that meeting don't you?". And Fred would nod, a
little awed by the analogy. Maybe the awe was tinged with a wee bit of
anger but not much; he knows there's a hierarchy among OSs, just like
among people, and he knows where his OS stands in that hierarchy...
----
For the humour impaired, that was a joke. To start with, I don't know
anyone called Fred.
It *is* true that I tend to ignore DOS if at all possible, especially in
my *code*. But since I don't really use wildrepos at work, this issue
would never have come up for me, even in the DOS projects I manage.
In this case someone who's contributed a heck of a lot to the evolution
of gitolite asked, so here it is.
----
oh and in case you were wondering, DOS stands for "dominant operating
system" ;-)
2011-07-23 02:32:12 +02:00
my ( $ perms ) = dos2unix ( slurp ( "$REPO_BASE/$repo.git/gl-perms" ) ) ;
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# discard comments
$ perms =~ s/#.*//g ;
# convert R and RW to the actual category names in the config file
$ perms =~ s/^\s*R /READERS /mg ;
$ perms =~ s/^\s*RW /WRITERS /mg ;
# $perms is say "READERS alice @foo @bar\nRW bob @baz" (the entire gl-perms
2010-08-21 06:26:11 +02:00
# file). We replace each @foo with $user if $cached_groups{'@foo'}{$user}
# exists (i.e., $user is a member of @foo)
for my $ g ( $ perms =~ /\s(\@\S+)/g ) {
2011-01-11 17:57:22 +01:00
fill_cache ( ) ; # get %cached_groups
2010-08-21 06:26:11 +02:00
$ perms =~ s/ $g(?!\S)/ $user/ if $ cached_groups { $ g } { $ user } ;
}
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# now setup the perm_cats hash to be returned
2010-08-21 06:26:11 +02:00
if ( $ perms ) {
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# let's say our user is "foo". gl-perms has "CAT bar @all",
# you add CAT => @all to the hash. similarly, if gl-perms has
# "DOG bar foo baz", you add DOG => foo to the hash. And
# since specific perms must override @all, we do @all first.
2010-11-18 08:16:34 +01:00
$ perm_cats { $ 1 } = '@all' while ( $ perms =~ /^[ \t]*(\S+)(?=[ \t]).*[ \t]\@all([ \t]|$)/mg ) ;
2011-01-15 16:39:56 +01:00
$ perm_cats { $ 1 } = $ user while ( $ perms =~ /^[ \t]*(\S+)(?=[ \t]).*[ \t]$user([ \t]|$)/mg ) ;
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# validate the categories being sent back
for ( sort keys % perm_cats ) {
die "invalid permission category $_\n" unless $ GL_WILDREPOS_PERM_CATS =~ /(^|\s)$_(\s|$)/ ;
}
2010-08-21 06:26:11 +02:00
}
2009-12-05 18:09:56 +01:00
}
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
return ( $ c , % perm_cats ) ;
2010-08-21 06:26:11 +02:00
}
2009-12-05 18:09:56 +01:00
}
2009-12-06 10:09:40 +01:00
# ----------------------------------------------------------------------------
# getperms and setperms
# ----------------------------------------------------------------------------
sub get_set_perms
{
2010-06-29 07:25:36 +02:00
my ( $ repo , $ verb , $ user ) = @ _ ;
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# set default categories
$ GL_WILDREPOS_PERM_CATS || = "READERS WRITERS" ;
2011-01-15 16:39:56 +01:00
my ( $ creator , $ dummy , $ dummy2 ) = wild_repo_rights ( $ repo , "" ) ;
2010-04-25 19:09:27 +02:00
die "$repo doesnt exist or is not yours\n" unless $ user eq $ creator ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
wrap_chdir ( $ REPO_BASE ) ;
2009-12-06 10:09:40 +01:00
wrap_chdir ( "$repo.git" ) ;
if ( $ verb eq 'getperms' ) {
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
return unless - f "gl-perms" ;
2011-03-08 01:48:59 +01:00
my $ perms = slurp ( "gl-perms" ) ;
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# convert R and RW to the actual category names in the config file
$ perms =~ s/^\s*R /READERS /mg ;
$ perms =~ s/^\s*RW /WRITERS /mg ;
print $ perms ;
2009-12-06 10:09:40 +01:00
} else {
2011-03-08 01:48:59 +01:00
wrap_print ( "gl-perms" , < > ) ; # eqvt to: system("cat > gl-perms");
my $ perms = slurp ( "gl-perms" ) ;
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# convert R and RW to the actual category names in the config file
$ perms =~ s/^\s*R /READERS /mg ;
$ perms =~ s/^\s*RW /WRITERS /mg ;
for my $ g ( $ perms =~ /^\s*(\S+)/g ) {
die "invalid permission category $g\n" unless $ GL_WILDREPOS_PERM_CATS =~ /(^|\s)$g(\s|$)/ ;
}
2010-01-08 13:05:11 +01:00
print "New perms are:\n" ;
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
print $ perms ;
2010-08-20 17:25:23 +02:00
# gitweb and daemon
setup_daemon_access ( $ repo ) ;
2010-08-20 19:17:34 +02:00
# add or delete line (arg1) from file (arg2) depending on arg3
2011-01-15 16:39:56 +01:00
add_del_line ( "$repo.git" , $ PROJECTS_LIST , setup_gitweb_access ( $ repo , '' , '' ) ) ;
2009-12-06 10:09:40 +01:00
}
}
2010-02-04 22:40:13 +01:00
# ----------------------------------------------------------------------------
# getdesc and setdesc
# ----------------------------------------------------------------------------
sub get_set_desc
{
2010-06-29 07:25:36 +02:00
my ( $ repo , $ verb , $ user ) = @ _ ;
2011-01-15 16:39:56 +01:00
my ( $ creator , $ dummy , $ dummy2 ) = wild_repo_rights ( $ repo , "" ) ;
2010-04-25 19:09:27 +02:00
die "$repo doesnt exist or is not yours\n" unless $ user eq $ creator ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
wrap_chdir ( $ REPO_BASE ) ;
2010-02-04 22:40:13 +01:00
wrap_chdir ( "$repo.git" ) ;
if ( $ verb eq 'getdesc' ) {
2011-03-08 01:48:59 +01:00
print slurp ( "description" ) if - f "description" ;
2010-02-04 22:40:13 +01:00
} else {
2011-03-08 01:48:59 +01:00
wrap_print ( "description" , < > ) ;
2010-02-04 22:40:13 +01:00
print "New description is:\n" ;
2011-03-08 01:48:59 +01:00
print slurp ( "description" ) ;
2009-12-06 10:09:40 +01:00
}
}
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
# ----------------------------------------------------------------------------
# IMPORTANT NOTE: next 3 subs (setup_*) assume $PWD is the bare repo itself
# ----------------------------------------------------------------------------
2010-06-25 20:06:15 +02:00
# ----------------------------------------------------------------------------
2011-01-01 07:02:58 +01:00
# set/unset git configs
2010-06-25 20:06:15 +02:00
# ----------------------------------------------------------------------------
2011-01-01 07:02:58 +01:00
sub setup_git_configs
2010-06-25 20:06:15 +02:00
{
2011-01-01 07:02:58 +01:00
my ( $ repo , $ git_configs_p ) = @ _ ;
2010-06-25 20:06:15 +02:00
2011-01-01 07:02:58 +01:00
while ( my ( $ key , $ value ) = each ( % { $ git_configs_p - > { $ repo } } ) ) {
2011-02-06 02:26:19 +01:00
if ( $ value ne "" ) {
2010-06-25 20:06:15 +02:00
$ value =~ s/^"(.*)"$/$1/ ;
system ( "git" , "config" , $ key , $ value ) ;
} else {
system ( "git" , "config" , "--unset-all" , $ key ) ;
}
}
}
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
# ----------------------------------------------------------------------------
# set/unset daemon access
# ----------------------------------------------------------------------------
2010-07-19 13:17:38 +02:00
# does not return anything; just touch/unlink the appropriate file
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
my $ export_ok = "git-daemon-export-ok" ;
sub setup_daemon_access
{
2010-07-19 13:17:38 +02:00
my $ repo = shift ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
2011-01-15 16:39:56 +01:00
if ( can_read ( $ repo , 'daemon' ) ) {
2011-02-22 08:55:56 +01:00
wrap_print ( $ export_ok , "" ) ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
} else {
unlink ( $ export_ok ) ;
}
}
# ----------------------------------------------------------------------------
# set/unset gitweb access
# ----------------------------------------------------------------------------
2010-07-19 13:17:38 +02:00
# returns 1 if gitweb access has happened; this is to allow the caller to add
# an entry to the projects.list file
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
my $ desc_file = "description" ;
sub setup_gitweb_access
# this also sets "owner" for gitweb, by the way
{
2010-07-19 13:17:38 +02:00
my ( $ repo , $ desc , $ owner ) = @ _ ;
2010-08-20 17:25:23 +02:00
my $ is_wild = - f "gl-creater" ;
# we may override but we do not remove gitweb.owner and description
# for wild repos
if ( $ desc ) {
open ( DESC , ">" , $ desc_file ) ;
print DESC $ desc . "\n" ;
close DESC ;
} else {
unlink $ desc_file unless $ is_wild ;
}
if ( $ owner ) {
system ( "git" , "config" , "gitweb.owner" , $ owner ) ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
} else {
2010-08-20 17:25:23 +02:00
system ( "git config --unset-all gitweb.owner 2>/dev/null" ) unless $ is_wild ;
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
}
# if there are no gitweb.* keys set, remove the section to keep the config file clean
my $ keys = `git config --get-regexp '^gitweb\\.' 2>/dev/null` ;
if ( length ( $ keys ) == 0 ) {
system ( "git config --remove-section gitweb 2>/dev/null" ) ;
}
2010-07-19 13:17:38 +02:00
2011-01-15 16:39:56 +01:00
return ( $ desc or can_read ( $ repo , 'gitweb' ) ) ;
2010-08-20 17:25:23 +02:00
# this return value is used by the caller to write to projects.list
gitweb/daemon now work for wild repos also
(thanks to Kevin Fleming for the need/use case)
TODO: tests
TODO: proper documentation; meanwhile, just read this:
- you can give gitweb and daemon read rights to wild card repos also,
and it'll all just work -- when a new repo is 'C'reated, it'll pick
up those rights etc
- you can assign descriptions (and owners) to individual repos as
before, except now you can assign them to repos that actually were
created from wild card patterns. So for example, you can define
rules for
repo foo/..*
and then assign descriptions like
foo/repo1 = "repo one"
foo/repo2 = "repo two"
foo/dil "scott" = "scott's dilbert repo"
However, this only works for repos that already exist, and only when
you push the admin repo.
Thumb rule: have the user create his wild repo, *then* add and push
the admin config file with the description. Not the other way
around.
implementation notes:
- wildcard support for git config revamped, refactored...
it's not just git config that needs wildcard support. daemon and
gitweb access also will be needing it soon, so we start by factoring
out the part that finds the "pattern" given a "real" repo name.
- GL_NO_DAEMON_NO_GITWEB now gates more than just those two things;
see doc/big-config.mkd for details
- we trawl through $GL_REPO_BASE_ABS *once* only, collecting repo
names and tying them to either the same name or to a wild pattern
that the repo name was created from
- nice little subs to setup gitweb, daemon, and git config
- god bless $GL_REPOPATT and the day I decided to set that env var
whenever a user hits a wild repo in any way :-)
- the code in gl-compile-conf is very simple now. Much nicer than
before
2010-07-16 19:31:34 +02:00
}
2009-12-04 05:21:22 +01:00
# ----------------------------------------------------------------------------
# print a report of $user's basic permissions
# ----------------------------------------------------------------------------
2010-04-16 15:49:50 +02:00
sub report_version {
2011-01-15 16:39:56 +01:00
my ( $ user ) = @ _ ;
2010-04-16 15:49:50 +02:00
print "hello $user, the gitolite version here is " ;
2011-03-08 01:48:59 +01:00
print slurp ( ( $ GL_PACKAGE_CONF || "$GL_ADMINDIR/conf" ) . "/VERSION" ) ;
2010-04-16 15:49:50 +02:00
}
2010-08-24 10:04:27 +02:00
sub perm_code {
# print the permission code
my ( $ all , $ super , $ user , $ x ) = @ _ ;
return " " unless $ all or $ super or $ user ;
return " $x " unless $ all or $ super ; # only $user (explicit access) was given
my $ ret ;
$ ret = " \@$x" if $ all ; # prefix @ if repo allows access for @all users
$ ret = " \#$x" if $ super ; # prefix # if user has access to @all repos (sort of like a super user)
$ ret = " \&$x" if $ all and $ super ; # prefix & if both the above
$ ret . = ( $ user ? " " : "_" ) ; # suffix _ if no explicit access else <space>
return $ ret ;
}
2009-12-04 05:21:22 +01:00
# basic means wildcards will be shown as wildcards; this is pretty much what
# got parsed by the compile script
sub report_basic
{
2011-01-15 16:39:56 +01:00
my ( $ repo , $ user ) = @ _ ;
2009-12-04 05:21:22 +01:00
2010-06-19 08:39:04 +02:00
# XXX The correct way is actually to give parse_acl another argument
# (defaulting to $ENV{GL_USER}, the value being used now). But for now
# this will do, even though it's a bit of a kludge to get the basic access
# rights for some other user this way
local $ ENV { GL_USER } = $ user ;
2011-01-15 16:39:56 +01:00
parse_acl ( "" , "CREATOR" ) ;
2011-01-01 10:44:54 +01:00
# all we need is for 'keys %repos' to come up with all the names, so:
@ repos { keys % split_conf } = values % split_conf if % split_conf ;
2009-12-04 05:21:22 +01:00
# send back some useful info if no command was given
2011-01-15 16:39:56 +01:00
report_version ( $ user ) ;
2010-04-16 15:49:50 +02:00
print "\rthe gitolite config gives you the following access:\r\n" ;
2010-07-30 17:54:39 +02:00
my $ count = 0 ;
2009-12-04 05:21:22 +01:00
for my $ r ( sort keys % repos ) {
2010-07-30 17:54:39 +02:00
next unless $ r =~ /$repo/i ;
2011-03-24 02:45:35 +01:00
# if $GL_BIG_CONFIG is on, limit the number of output lines
next if $ GL_BIG_CONFIG and $ count + + >= $ BIG_INFO_CAP ;
2010-06-12 05:46:32 +02:00
if ( $ r =~ $ REPONAME_PATT and $ r !~ /\bCREAT[EO]R\b/ ) {
2011-01-15 16:39:56 +01:00
parse_acl ( $ r , "NOBODY" ) ;
2010-05-10 08:16:47 +02:00
} else {
2010-06-12 05:46:32 +02:00
$ r =~ s/\bCREAT[EO]R\b/$user/g ;
2011-01-15 16:39:56 +01:00
parse_acl ( $ r , $ ENV { GL_USER } ) ;
2010-05-10 08:16:47 +02:00
}
2010-03-23 17:50:34 +01:00
# @all repos; meaning of read/write flags:
2010-04-24 11:24:31 +02:00
# @R => @all users are allowed access to this repo
# #R => you're a super user and can see @all repos
# R => normal access
my $ perm . = ( $ repos { $ r } { C } { '@all' } ? ' @C' : ( $ repos { $ r } { C } { $ user } ? ' C' : ' ' ) ) ;
2011-01-15 16:39:56 +01:00
$ perm . = perm_code ( $ repos { $ r } { R } { '@all' } , $ repos { '@all' } { R } { $ user } , $ repos { $ r } { R } { $ user } , 'R' ) ;
$ perm . = perm_code ( $ repos { $ r } { W } { '@all' } , $ repos { '@all' } { W } { $ user } , $ repos { $ r } { W } { $ user } , 'W' ) ;
2010-03-12 06:38:51 +01:00
print "$perm\t$r\r\n" if $ perm =~ /\S/ ;
2009-12-04 05:21:22 +01:00
}
2011-03-24 02:45:35 +01:00
print "only $BIG_INFO_CAP out of $count candidate repos examined\r\nplease use a partial reponame or regex pattern to limit output\r\n" if $ GL_BIG_CONFIG and $ count > $ BIG_INFO_CAP ;
2010-10-04 10:58:58 +02:00
print "$GL_SITE_INFO\n" if $ GL_SITE_INFO ;
2009-12-04 05:21:22 +01:00
}
2009-12-05 18:09:56 +01:00
2009-12-06 10:56:53 +01:00
# ----------------------------------------------------------------------------
2011-01-15 16:39:56 +01:00
# print a report of $user's expanded permissions
2009-12-06 10:56:53 +01:00
# ----------------------------------------------------------------------------
sub expand_wild
{
2011-01-15 16:39:56 +01:00
my ( $ repo , $ user ) = @ _ ;
2009-12-06 10:56:53 +01:00
2011-01-15 16:39:56 +01:00
report_version ( $ user ) ;
2010-04-16 15:49:50 +02:00
print "\ryou have access to the following repos on the server:\r\n" ;
2009-12-21 12:37:31 +01:00
# this is for convenience; he can copy-paste the output of the basic
2010-04-25 19:09:27 +02:00
# access report instead of having to manually change CREATOR to his name
2009-12-21 12:37:31 +01:00
$ repo =~ s/\bCREAT[EO]R\b/$user/g ;
2009-12-06 10:56:53 +01:00
# display matching repos (from *all* the repos in the system) that $user
# has at least "R" access to
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
chdir ( $ REPO_BASE ) or die "chdir $REPO_BASE failed: $!\n" ;
2010-07-30 17:54:39 +02:00
my $ count = 0 ;
2011-01-28 00:10:29 +01:00
for my $ actual_repo ( `find . -type d -name "*.git" -prune|sort` ) {
2009-12-06 10:56:53 +01:00
chomp ( $ actual_repo ) ;
$ actual_repo =~ s/^\.\/// ;
$ actual_repo =~ s/\.git$// ;
2010-02-10 21:00:43 +01:00
# actual_repo has to match the pattern being expanded
2010-07-30 17:54:39 +02:00
next unless $ actual_repo =~ /$repo/i ;
2011-03-24 02:45:35 +01:00
next if $ GL_BIG_CONFIG and $ count + + >= $ BIG_INFO_CAP ;
2010-04-24 09:47:37 +02:00
2011-01-15 16:39:56 +01:00
my ( $ perm , $ creator , $ wild ) = repo_rights ( $ actual_repo ) ;
2010-04-24 09:47:37 +02:00
next unless $ perm =~ /\S/ ;
2010-04-25 19:09:27 +02:00
print "$perm\t$creator\t$actual_repo\n" ;
2009-12-06 10:56:53 +01:00
}
2011-03-24 02:45:35 +01:00
print "only $BIG_INFO_CAP out of $count candidate repos examined\nplease use a partial reponame or regex pattern to limit output\n" if $ GL_BIG_CONFIG and $ count > $ BIG_INFO_CAP ;
2010-10-04 10:58:58 +02:00
print "$GL_SITE_INFO\n" if $ GL_SITE_INFO ;
2009-12-06 10:56:53 +01:00
}
2011-01-15 16:39:56 +01:00
# ----------------------------------------------------------------------------
# parse the compiled acl
# ----------------------------------------------------------------------------
sub parse_acl
{
# IMPLEMENTATION NOTE: a wee bit of this is duplicated in the update hook;
# please update that also if the interface or the env vars change
my ( $ repo , $ c , % perm_cats ) = @ _ ;
my $ perm_cats_sig = '' ; # a "signature" of the perm_cats hash
map { $ perm_cats_sig . = "$_.$perm_cats{$_}," } sort keys % perm_cats ;
$ c = "NOBODY" unless $ GL_WILDREPOS ;
# set up the variables for a parse to interpolate stuff from the dumped
# hash (remember the selective conversion of single to double quotes?).
# if they're not passed in, then we look for an env var of that name, else
# we default to "NOBODY" (we hope there isn't a real user called NOBODY!)
# And in any case, we set those env vars so level 2 can redo the last
# parse without any special code
our $ creator = $ ENV { GL_CREATOR } = $ c || $ ENV { GL_CREATOR } || "NOBODY" ;
our $ gl_user = $ ENV { GL_USER } ;
# these need to persist across calls to this function, so "our"
our $ saved_crwu ;
our ( % saved_repos , % saved_groups ) ;
if ( $ saved_crwu and $ saved_crwu eq "$creator,$perm_cats_sig,$gl_user" ) {
% repos = % saved_repos ; % groups = % saved_groups ;
} else {
die "parse $GL_CONF_COMPILED failed: " . ( $! or $@ ) unless do $ GL_CONF_COMPILED ;
}
unless ( defined ( $ data_version ) and $ data_version eq $ current_data_version ) {
# this cannot happen for 'easy-install' cases, by the way...
2011-03-08 02:06:23 +01:00
warn "(INTERNAL: $data_version -> $current_data_version; running gl-setup)\n" ;
2011-02-24 11:28:29 +01:00
system ( "$ENV{SHELL} -l -c gl-setup >&2" ) ;
2011-01-15 16:39:56 +01:00
die "parse $GL_CONF_COMPILED failed: " . ( $! or $@ ) unless do $ GL_CONF_COMPILED ;
}
$ saved_crwu = "$creator,$perm_cats_sig,$gl_user" ;
% saved_repos = % repos ; % saved_groups = % groups ;
add_repo_conf ( $ repo ) if $ repo ;
# basic access reporting doesn't send $repo, and doesn't need to; you just
# want the config dumped as is, really
return unless $ repo ;
my ( $ wild , @ repo_plus , @ user_plus ) ;
# expand $repo and $gl_user into all possible matching values
( $ wild , @ repo_plus ) = get_memberships ( $ repo , 1 ) ;
( @ user_plus ) = get_memberships ( $ gl_user , 0 ) ;
# the old "convenience copy" thing. Now on steroids :)
# note that when copying the @all entry, we retain the destination name as
2011-08-06 05:13:24 +02:00
# @all; we dont change it to $repo or $gl_user. We need to maintain this
# distinction to be able to print the @/#/& prefixes in the report output
# (see doc/report-output.mkd)
2011-01-15 16:39:56 +01:00
for my $ r ( '@all' , @ repo_plus ) {
my $ dr = $ repo ; $ dr = '@all' if $ r eq '@all' ;
$ repos { $ dr } { DELETE_IS_D } = 1 if $ repos { $ r } { DELETE_IS_D } ;
$ repos { $ dr } { CREATE_IS_C } = 1 if $ repos { $ r } { CREATE_IS_C } ;
$ repos { $ dr } { NAME_LIMITS } = 1 if $ repos { $ r } { NAME_LIMITS } ;
2011-08-06 05:13:24 +02:00
# this needs to copy the key-value pairs from RHS to LHS, not just
# assign RHS to LHS! However, we want to roll in '@all' configs also
# into the actual $repo; there's no need to preserve the distinction
map { $ git_configs { $ repo } { $ _ } = $ git_configs { $ r } { $ _ } } keys % { $ git_configs { $ r } } if $ git_configs { $ r } ;
2011-01-15 16:39:56 +01:00
for my $ u ( '@all' , "$gl_user - wild" , @ user_plus , keys % perm_cats ) {
my $ du = $ gl_user ; $ du = '@all' if $ u eq '@all' or ( $ perm_cats { $ u } || '' ) eq '@all' ;
$ repos { $ dr } { C } { $ du } = 1 if $ repos { $ r } { C } { $ u } ;
$ repos { $ dr } { R } { $ du } = 1 if $ repos { $ r } { R } { $ u } ;
$ repos { $ dr } { W } { $ du } = 1 if $ repos { $ r } { W } { $ u } ;
next if $ r eq $ dr and $ u eq $ du ; # no point duplicating those refexes
push @ { $ repos { $ dr } { $ du } } , @ { $ repos { $ r } { $ u } }
if exists $ repos { $ r } { $ u } and ref ( $ repos { $ r } { $ u } ) eq 'ARRAY' ;
}
}
return ( $ wild ) ;
}
# add repo conf from repo.git/gl-conf
sub add_repo_conf
{
my ( $ repo ) = shift ;
return unless $ split_conf { $ repo } ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
do "$REPO_BASE/$repo.git/gl-conf" or return ;
2011-01-15 16:39:56 +01:00
$ repos { $ repo } = $ one_repo { $ repo } ;
$ git_configs { $ repo } = $ one_git_config { $ repo } ;
}
# ----------------------------------------------------------------------------
# repo_rights
# ----------------------------------------------------------------------------
2010-04-24 09:20:54 +02:00
# there will be multiple calls to repo_rights; better to use a closure. We
# might even be called from outside (see the admin-defined-commands docs for
# how/why). Regardless of how we're called, we assume $ENV{GL_USER} is
# already defined
{
2010-05-10 08:16:47 +02:00
my $ last_repo = '' ;
2010-04-24 09:20:54 +02:00
sub repo_rights {
my $ repo = shift ;
$ repo =~ s/^\.\/// ;
$ repo =~ s/\.git$// ;
# we get passed an actual repo name. It may be a normal
# (non-wildcard) repo, in which case it is assumed to exist. If it's
# a wildrepo, it may or may not exist. If it doesn't exist, the "C"
# perms are also filled in, else that column is left blank
2010-05-10 08:16:47 +02:00
unless ( $ REPO_BASE ) {
# means we've been called from outside; see doc/admin-defined-commands.mkd
2011-01-15 16:39:56 +01:00
where_is_rc ( ) ;
2010-05-10 08:16:47 +02:00
die "parse $ENV{GL_RC} failed: " . ( $! or $@ ) unless do $ ENV { GL_RC } ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
# fix up REPO_BASE
$ REPO_BASE = "$ENV{HOME}/$REPO_BASE" unless $ REPO_BASE =~ m (^/) ;
2010-04-24 09:20:54 +02:00
}
my $ perm = ' ' ;
2010-05-10 08:16:47 +02:00
my $ creator ;
2010-04-24 09:20:54 +02:00
2010-05-10 08:16:47 +02:00
# get basic info about the repo and fill %repos
my $ wild = '' ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
my $ exists = - d "$REPO_BASE/$repo.git" ;
2010-05-10 08:16:47 +02:00
if ( $ exists ) {
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
# the list of permission categories within gl-perms that this user is a member
# of, or that specify @all as a member. See comments in
# "wild_repo_rights" sub for nuances.
my ( % perm_cats ) ;
2010-05-10 08:16:47 +02:00
# these will be empty if it's not a wildcard repo anyway
2011-01-15 16:39:56 +01:00
( $ creator , % perm_cats ) = wild_repo_rights ( $ repo , $ ENV { GL_USER } ) ;
2010-04-24 09:20:54 +02:00
# get access list with these substitutions
2011-01-15 16:39:56 +01:00
$ wild = parse_acl ( $ repo , $ creator || "NOBODY" , % perm_cats ) ;
2010-05-10 08:16:47 +02:00
} else {
2011-01-15 16:39:56 +01:00
$ wild = parse_acl ( $ repo , $ ENV { GL_USER } ) ;
2010-05-10 08:16:47 +02:00
}
2010-08-08 18:38:46 +02:00
if ( $ exists ) {
if ( $ creator and $ wild ) {
$ creator = "($creator)" ;
} elsif ( $ creator and not $ wild ) {
# was created wild but then someone (a) removed the pattern
# from, and (b) added the actual reponame to, the config
$ creator = "<was_$creator>"
} else {
$ creator = "<gitolite>" ;
}
2010-04-24 09:20:54 +02:00
} else {
2010-05-10 08:16:47 +02:00
# repo didn't exist; C perms need to be filled in
2010-04-24 09:20:54 +02:00
$ perm = ( $ repos { $ repo } { C } { '@all' } ? ' @C' : ( $ repos { $ repo } { C } { $ ENV { GL_USER } } ? ' =C' : ' ' ) ) if $ GL_WILDREPOS ;
# if you didn't have perms to create it, delete the "convenience"
# copy of the ACL that parse_acl makes
2010-07-30 02:14:29 +02:00
delete $ repos { $ repo } if $ perm !~ /C/ and $ wild ;
2010-05-10 08:16:47 +02:00
$ creator = "<notfound>" ;
2010-04-24 09:20:54 +02:00
}
2011-01-15 16:39:56 +01:00
$ perm . = perm_code ( $ repos { $ repo } { R } { '@all' } , $ repos { '@all' } { R } { $ ENV { GL_USER } } , $ repos { $ repo } { R } { $ ENV { GL_USER } } , 'R' ) ;
$ perm . = perm_code ( $ repos { $ repo } { W } { '@all' } , $ repos { '@all' } { W } { $ ENV { GL_USER } } , $ repos { $ repo } { W } { $ ENV { GL_USER } } , 'W' ) ;
2010-05-10 08:16:47 +02:00
# set up for caching %repos
$ last_repo = $ repo ;
return ( $ perm , $ creator , $ wild ) ;
2010-04-24 09:20:54 +02:00
}
}
2011-01-15 16:39:56 +01:00
# ----------------------------------------------------------------------------
# helpers...
# ----------------------------------------------------------------------------
2010-04-24 14:46:13 +02:00
# helper/convenience routine to get rights and ownership from a shell command
sub cli_repo_rights {
2010-12-24 04:22:13 +01:00
# check_access does a lot more, so just call it. Since it returns perms
# and creator separately, just space-join them and print it.
2011-01-15 16:39:56 +01:00
print join ( " " , check_access ( $ _ [ 0 ] ) ) , "\n" ;
2010-04-24 14:46:13 +02:00
}
2010-07-19 13:17:38 +02:00
sub can_read {
my $ repo = shift ;
my $ user = shift || $ ENV { GL_USER } ;
local $ ENV { GL_USER } = $ user ;
2011-01-15 16:39:56 +01:00
my ( $ perm , $ creator , $ wild ) = repo_rights ( $ repo ) ;
2010-08-24 13:47:41 +02:00
return ( ( $ GL_ALL_INCLUDES_SPECIAL || $ user !~ /^(gitweb|daemon)$/ )
? $ perm =~ /R/
: $ perm =~ /R /
) ;
2010-07-19 13:17:38 +02:00
}
2010-11-16 15:39:45 +01:00
# helper to manage "disabling" a repo or the whole site for "W" access
sub check_repo_write_enabled {
my ( $ repo ) = shift ;
make REPO_BASE absolute early
$ENV{GL_REPO_BASE_ABS} is meant to point to the same directory as
$REPO_BASE, except it is meant to be passed to hooks, ADCs and other
child programs. And since you can't be sure where the child program
starts in, this became an absolute path.
Gradually, however, I started using it wherever I needed an absolute
path (mostly in code that jumps around various directories to do stuff).
Which is silly, because there's no reason $REPO_BASE cannot also be made
an absolute, even if the rc file has a relative path.
So that's what I did now: made $REPO_BASE absolute very early on, and
then systematically changed all uses of the longer form to the shorter
form when appropriate. And so the only thing we now use the longer one
for is to pass to child programs.
(Implementation note: The actual change is not very big, but while I was
about it I decided to make the test suite able to test with an absolute
REPO_BASE also, which is why the commit seems so large.)
----
This all started with a complaint from Damien Regad. He had an
extremely odd setup where his bashrc changed PWD to something other than
$HOME before anything else ran. This caused those two variables to
beceom inconsistent, and he had a 1-line fix he wanted me to apply.
I generally don't like making special fixes for for non-standard setups,
and anyway all he had to do was set the full path to REPO_BASE in the rc
file to get around this. Which is what I told him and he very politely
left it at that.
However, this did get me thinking, and I soon realised I was needlessly
conflating "relative versus absolute" with "able to be passed to child
programs". Fixing that solved his problem also, as a side-effect.
So I guess this is all thanks to Damien!
2011-03-18 06:29:52 +01:00
for my $ d ( "$ENV{HOME}/.gitolite.down" , "$REPO_BASE/$repo.git/.gitolite.down" ) {
2010-11-16 15:39:45 +01:00
next unless - f $ d ;
2011-03-11 23:48:53 +01:00
die $ ABRT . slurp ( $ d ) if - s $ d ;
2010-11-16 15:39:45 +01:00
die $ ABRT . "writes are currently disabled\n" ;
}
}
2011-01-15 16:39:56 +01:00
# ----------------------------------------------------------------------------
# get memberships
# ----------------------------------------------------------------------------
# given a plain reponame or username, return:
# - the name itself if it's a user
# - the name itself if it's a repo and the repo exists in the config
# plus, if $GL_BIG_CONFIG is set:
# - all the groups the name belongs to
# plus, for repos:
# - all the wildcards matching it
# plus, if $GL_BIG_CONFIG is set:
# - all the groups those wildcards belong to
# A name can normally appear (repo example) (user example)
# - directly (repo foo) (RW = bob)
# - (only for repos) as a direct wildcard (repo foo/.*)
# but if $GL_BIG_CONFIG is set, it can also appear:
# - indirectly (@g = foo; repo @g) (@ug = bob; RW = @ug))
# - (only for repos) as an indirect wildcard (@g = foo/.*; repo @g).
# note: the wildcard stuff does not apply to username memberships
our % extgroups_cache ;
sub get_memberships {
my $ base = shift ; # reponame or username
my $ is_repo = shift ; # some true value means a repo name has been passed
my $ wild = '' ; # will be a space-sep list of matching patterns
my @ ret ; # list of matching groups/patterns
# direct
push @ ret , $ base if not $ is_repo or exists $ repos { $ base } ;
if ( $ is_repo and $ GL_WILDREPOS ) {
for my $ i ( sort keys % repos ) {
next if $ i eq $ base ; # "direct" name already done; skip
# direct wildcard
if ( $ base =~ /^$i$/ ) {
push @ ret , $ i ;
$ wild = ( $ wild ? "$wild $i" : $ i ) ;
}
}
}
if ( $ GL_BIG_CONFIG ) {
for my $ g ( sort keys % groups ) {
for my $ i ( sort keys % { $ groups { $ g } } ) {
if ( $ base eq $ i ) {
# indirect
push @ ret , $ g ;
} elsif ( $ is_repo and $ GL_WILDREPOS and $ base =~ /^$i$/ ) {
# indirect wildcard
push @ ret , $ g ;
$ wild = ( $ wild ? "$wild $i" : $ i ) ;
}
}
}
}
# deal with returning user info first
unless ( $ is_repo ) {
# bring in group membership info stored externally, by running
# $GL_GET_MEMBERSHIPS_PGM if it is defined
if ( $ extgroups_cache { $ base } ) {
push @ ret , @ { $ extgroups_cache { $ base } } ;
} elsif ( $ GL_GET_MEMBERSHIPS_PGM ) {
my @ extgroups = map { s/^/@/ ; $ _ ; } split ' ' , `$GL_GET_MEMBERSHIPS_PGM $base` ;
$ extgroups_cache { $ base } = \ @ extgroups ;
push @ ret , @ extgroups ;
}
return ( @ ret ) ;
}
# note that there is an extra return value when called for repos (as
# opposed to being called for usernames)
return ( $ wild , @ ret ) ;
}
# ----------------------------------------------------------------------------
# generic check access routine
# ----------------------------------------------------------------------------
sub check_access
{
my ( $ repo , $ ref , $ aa , $ dry_run ) = @ _ ;
# aa = attempted access
my ( $ perm , $ creator , $ wild ) = repo_rights ( $ repo ) ;
$ perm =~ s/ /_/g ;
$ creator =~ s/^\(|\)$//g ;
return ( $ perm , $ creator ) unless $ ref ;
# until I do some major refactoring (which will bloat the update hook a
# bit, sadly), this code duplicates stuff in the current update hook.
my @ allowed_refs ;
# user+repo specific perms override everything else, so they come first.
# Then perms given to specific user for @all repos, and finally perms
# given to @all users for specific repo
push @ allowed_refs , @ { $ repos { $ repo } { $ ENV { GL_USER } } || [] } ;
push @ allowed_refs , @ { $ repos { '@all' } { $ ENV { GL_USER } } || [] } ;
push @ allowed_refs , @ { $ repos { $ repo } { '@all' } || [] } ;
if ( $ dry_run ) {
return check_ref ( \ @ allowed_refs , $ repo , $ ref , $ aa , $ dry_run ) ;
} else {
check_ref ( \ @ allowed_refs , $ repo , $ ref , $ aa ) ;
}
}
2010-07-25 17:25:32 +02:00
# ----------------------------------------------------------------------------
# setup the ~/.ssh/authorized_keys file
# ----------------------------------------------------------------------------
sub setup_authkeys
{
# ARGUMENTS
2011-01-15 16:39:56 +01:00
my ( $ GL_KEYDIR , $ user_list_p ) = @ _ ;
2010-07-25 17:25:32 +02:00
# calling from outside the normal compile script may mean that argument 2
# may not be passed; so make sure it's a valid hashref, even if empty
$ user_list_p = { } unless $ user_list_p ;
2011-01-15 16:39:56 +01:00
# LOCAL CONSTANTS
2010-07-25 17:25:32 +02:00
# command and options for authorized_keys
2011-01-15 16:39:56 +01:00
my $ AUTH_COMMAND = "$ENV{GL_BINDIR}/gl-auth-command" ;
$ AUTH_COMMAND = "$ENV{GL_BINDIR}/gl-time $ENV{GL_BINDIR}/gl-auth-command" if $ GL_PERFLOGT ;
2011-05-31 17:18:27 +02:00
# set default authentication options
$ AUTH_OPTIONS || = "no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty" ;
2010-07-25 17:25:32 +02:00
# START
my $ authkeys_fh = wrap_open ( "<" , $ ENV { HOME } . "/.ssh/authorized_keys" ,
"\tFor security reasons, gitolite will not *create* this file if it does\n" .
"\tnot already exist. Please see the \"admin\" document for details\n" ) ;
my $ newkeys_fh = wrap_open ( ">" , $ ENV { HOME } . "/.ssh/new_authkeys" ) ;
# save existing authkeys minus the GL-added stuff
while ( <$authkeys_fh> )
{
print $ newkeys_fh $ _ unless ( /^# gito(sis-)?lite start/ .. /^# gito(sis-)?lite end/ ) ;
}
# add our "start" line, each key on its own line (prefixed by command and
# options, in the standard ssh authorized_keys format), then the "end" line.
print $ newkeys_fh "# gitolite start\n" ;
wrap_chdir ( $ GL_KEYDIR ) ;
my @ not_in_config ; # pubkeys exist but users don't appear in the config file
2010-10-26 16:26:51 +02:00
for my $ pubkey ( `find . -type f | sort` )
2010-07-25 17:25:32 +02:00
{
chomp ( $ pubkey ) ; $ pubkey =~ s(^\./) () ;
# security check (thanks to divVerent for catching this)
unless ( $ pubkey =~ $ REPONAME_PATT ) {
2011-03-08 02:06:23 +01:00
warn "$pubkey contains some unsavoury characters; ignored...\n" ;
2010-07-25 17:25:32 +02:00
next ;
}
# lint check 1
unless ( $ pubkey =~ /\.pub$/ )
{
print STDERR "WARNING: pubkey files should end with \".pub\", ignoring $pubkey\n" ;
next ;
}
my $ user = $ pubkey ;
$ user =~ s(.*/) () ; # foo/bar/baz.pub -> baz.pub
$ user =~ s/(\@[^.]+)?\.pub$// ; # baz.pub, baz@home.pub -> baz
# lint check 2 -- don't print right now; just collect the messages
push @ not_in_config , "$user($pubkey)" if %$ user_list_p and not $ user_list_p - > { $ user } ;
$ user_list_p - > { $ user } = 'has pubkey' if %$ user_list_p ;
# apparently some pubkeys don't end in a newline...
my $ pubkey_content ;
{
local $/ = undef ;
local @ ARGV = ( $ pubkey ) ;
$ pubkey_content = < > ;
}
$ pubkey_content =~ s/\s*$/\n/ ;
# don't trust files with multiple lines (i.e., something after a newline)
if ( $ pubkey_content =~ /\n./ )
{
2011-03-08 02:06:23 +01:00
warn "WARNING: a pubkey file can only have one line (key); ignoring $pubkey\n" .
" If you want to add multiple public keys for a single user, use\n" .
" \"user\@host.pub\" file names. See the \"one user, many keys\"\n" .
" section in doc/3-faq-tips-etc.mkd for details.\n" ;
2010-07-25 17:25:32 +02:00
next ;
}
print $ newkeys_fh "command=\"$AUTH_COMMAND $user\",$AUTH_OPTIONS " ;
print $ newkeys_fh $ pubkey_content ;
}
# lint check 2 -- print less noisily
if ( @ not_in_config > 10 ) {
print STDERR "$WARN You have " . scalar ( @ not_in_config ) . " pubkeys that do not appear to be used in the config\n" ;
} elsif ( @ not_in_config ) {
print STDERR "$WARN the following users (pubkey files in parens) do not appear in the config file:\n" , join ( "," , sort @ not_in_config ) , "\n" ;
}
# lint check 3; a little more severe than the first two I guess...
{
my @ no_pubkey =
custom perm categories in setperms (WARNING: PLEASE READ FULL COMMIT MESSAGE)
THE COMPILED CONFIG FILE FORMAT CHANGES WITH THIS VERSION. PLEASE DO
NOT MIX VERSIONS OR DOWNGRADE. Upgrading using normal gitolite upgrade
means should be fine, though.
Originally, we only allowed "R" and "RW" as categories of users supplied
to the `setperms` command. These map respectively to "READERS" and
"WRITERS" in the access rules.
Now:
- we prefer READERS instead of R and WRITERS instead of RW
- we allow the admin to define other categories as she wishes
(example: MANAGERS, TESTERS, etc). These do not have abbreviations,
however, so they must be supplied in full.
PLEASE, *PLEASE*, read the section in doc/wildcard-repositories.mkd for
more info. This is a VERY powerful feature and if you're not careful
you could mess up the ACLs nicely.
Backward compat note: you can continue to use the "R" and "RW"
categories when running the "setperms" command, and gitolite will
internally convert them to READERS and WRITERS categories.
----
implementation notes:
- new RC var called GL_WILDREPOS_PERM_CATS that is a space-sep list of
the allowed categories in a gl-perms file; defaults to "R RW" if not
specified
- wild_repo_rights no longer returns $c, $r, $wC, where $r = $user if
"R $user", $r = '@all' if "R @all", and similarly with $w and "RW".
Instead it returns $c and a new hash that effectively gives the same
info, but expanded to include any other valid categories (listed in
GL_WILDREPOS_PERM_CATS)
- consequently, the arguments that parse_acl takes also change the
same way
- (side note: R and RW are quietly converted to READERS and WRITERS;
however, new categories that you define yourself do not have
abbreviations)
- setperms validates perms to make sure only allowed categories are
used; however even if someone changed them behind the scenes,
wild_repo_rights will also check. This is necessary in case the
admin tightened up GL_WILDREPOS_PERM_CATS after someone had already
setperms-d his repos.
- as a bonus, we eliminate all the post-Dumper shenanigans, at least
for READERS and WRITERS. Those two now look, to the compile script,
just like any other usernames.
2010-11-06 06:16:17 +01:00
grep { $ _ !~ /^(gitweb|daemon|\@.*|~\$creator)$/ }
2010-07-25 17:25:32 +02:00
grep { $ user_list_p - > { $ _ } ne 'has pubkey' }
2010-12-24 06:36:05 +01:00
grep { $ GL_WILDREPOS_PERM_CATS !~ /(^|\s)$_(\s|$)/ }
keys % { $ user_list_p } ;
2010-07-25 17:25:32 +02:00
if ( @ no_pubkey > 10 ) {
print STDERR "$WARN You have " . scalar ( @ no_pubkey ) . " users WITHOUT pubkeys...!\n" ;
} elsif ( @ no_pubkey ) {
print STDERR "$WARN the following users have no pubkeys:\n" , join ( "," , sort @ no_pubkey ) , "\n" ;
}
}
print $ newkeys_fh "# gitolite end\n" ;
close $ newkeys_fh or die "$ABRT close newkeys failed: $!\n" ;
revert part of 9ad7ea4
Fix a problem with authkeys perms when REPO_UMASK is too loose.
(To duplicate it, run a fresh, non-root install, and when gl-setup pops
up an editor, change the REPO_UMASK to 0007 (from the default 0077).
You'll find that ~/.ssh/authorized_keys now has g+w set, causing sshd to
refuse key-based access.)
And before you ask, even though gl-setup does it, I won't fiddle with
the permissions of an existing file in *this* code. (gl-setup is run
manually by the admin, this one gets run on every push).
----
Side note: 9ad7ea4 was somewhat forced on me, and I didn't really agree
with parts of it. I have no idea why I gave in so easily, but it won't
happen again!
2011-05-31 18:24:18 +02:00
# all done; overwrite the file (use cat to avoid perm changes)
system ( "cat $ENV{HOME}/.ssh/authorized_keys > $ENV{HOME}/.ssh/old_authkeys" ) ;
system ( "cat $ENV{HOME}/.ssh/new_authkeys > $ENV{HOME}/.ssh/authorized_keys" )
and die "couldn't write authkeys file\n" ;
system ( "rm $ENV{HOME}/.ssh/new_authkeys" ) ;
2010-07-25 17:25:32 +02:00
}
2010-01-31 15:54:36 +01:00
# ----------------------------------------------------------------------------
2010-02-01 11:07:35 +01:00
# S P E C I A L C O M M A N D S
2010-01-31 15:54:36 +01:00
# ----------------------------------------------------------------------------
2010-02-01 11:07:35 +01:00
sub special_cmd
2010-01-31 15:54:36 +01:00
{
2011-01-15 16:39:56 +01:00
my ( $ shell_allowed ) = @ _ ;
2010-02-01 11:07:35 +01:00
my $ cmd = $ ENV { SSH_ORIGINAL_COMMAND } ;
my $ user = $ ENV { GL_USER } ;
# check each special command we know about and call it if enabled
if ( $ cmd eq 'info' ) {
2011-01-15 16:39:56 +01:00
report_basic ( '^' , $ user ) ;
2010-03-12 06:38:51 +01:00
print "you also have shell access\r\n" if $ shell_allowed ;
2010-02-07 14:40:53 +01:00
} elsif ( $ cmd =~ /^info\s+(.+)$/ ) {
my @ otherusers = split ' ' , $ 1 ;
2010-07-30 17:54:39 +02:00
# the first argument is assumed to be a repo pattern, like in the
# expand command
my $ repo = shift ( @ otherusers ) ;
die "$repo has invalid characters" unless "x$repo" =~ $ REPOPATT_PATT ;
print STDERR "(treating $repo as pattern to limit output)\n" ;
# set up the list of users being queried; it's either a list passed in
# (allowed only for admin pushers) or just $user
if ( @ otherusers ) {
2011-01-15 16:39:56 +01:00
my ( $ perm , $ creator , $ wild ) = repo_rights ( 'gitolite-admin' ) ;
2010-07-30 17:54:39 +02:00
die "you can't ask for others' permissions\n" unless $ perm =~ /W/ ;
}
push @ otherusers , $ user unless @ otherusers ;
2010-06-19 08:39:04 +02:00
2011-01-15 16:39:56 +01:00
parse_acl ( ) ;
2010-02-07 14:40:53 +01:00
for my $ otheruser ( @ otherusers ) {
warn ( "ignoring illegal username $otheruser\n" ) , next unless $ otheruser =~ $ USERNAME_PATT ;
2011-01-15 16:39:56 +01:00
report_basic ( $ repo , $ otheruser ) ;
2010-02-07 14:40:53 +01:00
}
2010-02-01 11:07:35 +01:00
} elsif ( $ HTPASSWD_FILE and $ cmd eq 'htpasswd' ) {
2011-01-15 16:39:56 +01:00
ext_cmd_htpasswd ( $ HTPASSWD_FILE ) ;
2010-02-01 11:07:35 +01:00
} elsif ( $ RSYNC_BASE and $ cmd =~ /^rsync / ) {
2011-01-15 16:39:56 +01:00
ext_cmd_rsync ( $ GL_CONF_COMPILED , $ RSYNC_BASE , $ cmd ) ;
2010-05-09 17:04:54 +02:00
} elsif ( $ SVNSERVE and $ cmd eq 'svnserve -t' ) {
2011-01-15 16:39:56 +01:00
ext_cmd_svnserve ( $ SVNSERVE ) ;
2010-01-31 15:54:36 +01:00
} else {
2010-02-01 11:07:35 +01:00
# if the user is allowed a shell, just run the command
2011-01-15 16:39:56 +01:00
log_it ( ) ;
2010-02-01 11:07:35 +01:00
exec $ ENV { SHELL } , "-c" , $ cmd if $ shell_allowed ;
2010-01-31 15:54:36 +01:00
die "bad command: $cmd\n" ;
}
}
2011-01-15 16:39:56 +01:00
sub run_custom_command {
my $ user = shift ;
2010-05-10 08:16:47 +02:00
2011-01-15 16:39:56 +01:00
my $ cmd = $ ENV { SSH_ORIGINAL_COMMAND } ;
my ( $ verb , $ repo ) = ( $ cmd =~ /^\s*(\S+)(?:\s+'?\/?(.*?)(?:\.git)?'?)?$/ ) ;
# deal with "no argument" cases
$ verb eq 'expand' ? $ repo = '^' : die "$verb needs an argument\n" unless $ repo ;
if ( $ repo =~ $ REPONAME_PATT and $ verb =~ /getperms|setperms/ ) {
# with an actual reponame, you can "getperms" or "setperms"
get_set_perms ( $ repo , $ verb , $ user ) ;
2010-05-10 08:16:47 +02:00
}
2011-01-15 16:39:56 +01:00
elsif ( $ repo =~ $ REPONAME_PATT and $ verb =~ /(get|set)desc/ ) {
# with an actual reponame, you can "getdesc" or "setdesc"
get_set_desc ( $ repo , $ verb , $ user ) ;
2010-05-10 08:16:47 +02:00
}
2011-01-15 16:39:56 +01:00
elsif ( $ verb eq 'expand' ) {
# with a wildcard, you can "expand" it to see what repos actually match
die "$repo has invalid characters" unless "x$repo" =~ $ REPOPATT_PATT ;
expand_wild ( $ repo , $ user ) ;
} else {
die "$cmd doesn't make sense to me\n" ;
2010-05-14 13:05:37 +02:00
}
2010-05-10 08:16:47 +02:00
}
2011-01-15 16:39:56 +01:00
sub shell_out {
my $ shell = $ ENV { SHELL } ;
$ shell =~ s/.*\//-/ ; # change "/bin/bash" to "-bash"
log_it ( $ shell ) ;
exec { $ ENV { SHELL } } $ shell ;
}
2010-01-31 15:54:36 +01:00
2011-01-15 16:39:56 +01:00
sub try_adc {
my ( $ cmd , @ args ) = split ' ' , $ ENV { SSH_ORIGINAL_COMMAND } ;
if ( - x "$GL_ADC_PATH/$cmd" ) {
2011-02-13 03:32:34 +01:00
die "I don't like $cmd\n" if $ cmd =~ /\.\./ ;
2011-01-15 16:39:56 +01:00
# yes this is rather strict, sorry.
2011-05-19 05:24:23 +02:00
do { die "I don't like $_\n" unless $ _ =~ $ ADC_CMD_ARGS_PATT and $ _ !~ m (\.\./) } for ( $ cmd , @ args ) ;
2011-01-15 16:39:56 +01:00
log_it ( "$GL_ADC_PATH/$ENV{SSH_ORIGINAL_COMMAND}" ) ;
exec ( "$GL_ADC_PATH/$cmd" , @ args ) ;
2010-12-24 04:22:13 +01:00
}
2010-01-31 15:54:36 +01:00
}
# ----------------------------------------------------------------------------
# external command helper: rsync
# ----------------------------------------------------------------------------
sub ext_cmd_rsync
{
my ( $ GL_CONF_COMPILED , $ RSYNC_BASE , $ cmd ) = @ _ ;
# test the command patterns; reject if they don't fit. Rsync sends
# commands that looks like one of these to the server (the first one is
# for a read, the second for a write)
# rsync --server --sender -some.flags . some/path
# rsync --server -some.flags . some/path
die "bad rsync command: $cmd"
2010-01-31 16:39:05 +01:00
unless $ cmd =~ /^rsync --server( --sender)? -[\w.]+(?: --(?:delete|partial))* \. (\S+)$/ ;
2010-01-31 15:54:36 +01:00
my $ perm = "W" ;
$ perm = "R" if $ 1 ;
my $ path = $ 2 ;
2010-11-28 15:31:39 +01:00
die "I dont like some of the characters in $path\n" unless $ path =~ $ REPONAME_PATT ;
2010-02-06 01:13:16 +01:00
# XXX make a better pattern for this if people complain ;-)
2010-01-31 15:54:36 +01:00
die "I dont like absolute paths in $cmd\n" if $ path =~ /^\// ;
die "I dont like '..' paths in $cmd\n" if $ path =~ /\.\./ ;
# ok now check if we're permitted to execute a $perm action on $path
# (taken as a refex) using rsync.
2011-01-15 16:39:56 +01:00
check_access ( 'EXTCMD/rsync' , "NAME/$path" , $ perm ) ;
2010-01-31 15:54:36 +01:00
# that should "die" if there's a problem
wrap_chdir ( $ RSYNC_BASE ) ;
2011-01-15 16:39:56 +01:00
log_it ( ) ;
2010-01-31 15:54:36 +01:00
exec $ ENV { SHELL } , "-c" , $ ENV { SSH_ORIGINAL_COMMAND } ;
}
2010-02-01 11:07:35 +01:00
# ----------------------------------------------------------------------------
# external command helper: htpasswd
# ----------------------------------------------------------------------------
sub ext_cmd_htpasswd
{
my $ HTPASSWD_FILE = shift ;
die "$HTPASSWD_FILE doesn't exist or is not writable\n" unless - w $ HTPASSWD_FILE ;
$| + + ;
print << EOFhtp ;
Please type in your new htpasswd at the prompt . You only have to type it once .
NOTE THAT THE PASSWORD WILL BE ECHOED , so please make sure no one is
shoulder - surfing , and make sure you clear your screen as well as scrollback
history after you ' re done ( or close your terminal instance ) .
EOFhtp
print "new htpasswd:" ;
my $ password = < > ;
$ password =~ s/[\n\r]*$// ;
2010-02-14 05:21:51 +01:00
die "empty passwords are not allowed\n" unless $ password ;
2011-05-24 03:00:55 +02:00
my $ rc = system ( "htpasswd" , "-mb" , $ HTPASSWD_FILE , $ ENV { GL_USER } , $ password ) ;
2010-02-01 11:07:35 +01:00
die "htpasswd command seems to have failed with $rc return code...\n" if $ rc ;
}
2010-01-31 15:54:36 +01:00
2010-05-09 17:04:54 +02:00
# ----------------------------------------------------------------------------
# external command helper: svnserve
# ----------------------------------------------------------------------------
sub ext_cmd_svnserve
{
my $ SVNSERVE = shift ;
$ SVNSERVE =~ s/%u/$ENV{GL_USER}/g ;
exec $ SVNSERVE ;
die "svnserve exec failed\n" ;
}
2011-08-12 18:29:10 +02:00
# ----------------------------------------------------------------------------
# MIRRORING HELPERS
# ----------------------------------------------------------------------------
sub mirror_mode {
my $ repo = shift ;
# 'local' is the default if the config is empty or not set
my $ gmm = `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.master` || 'local' ;
chomp $ gmm ;
return 'local' if $ gmm eq 'local' ;
return 'master' if $ gmm eq ( $ GL_HOSTNAME || '' ) ;
return "slave of $gmm" ;
}
sub mirror_listslaves {
my $ repo = shift ;
return ( `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.slaves` || '' ) ;
}
2011-08-13 10:09:07 +02:00
# is a redirect ok for this repo from this slave?
2011-08-12 18:29:10 +02:00
sub mirror_redirectOK {
my $ repo = shift ;
2011-08-13 10:09:07 +02:00
my $ slave = shift || return 0 ;
# if we don't know who's asking, the answer is "no"
2011-08-12 18:29:10 +02:00
my $ gmrOK = `git config --file $REPO_BASE/$repo.git/config --get gitolite.mirror.redirectOK` || '' ;
chomp $ gmrOK ;
my $ slavelist = mirror_listslaves ( $ repo ) ;
# if gmrOK is 'true', any valid slave can redirect
return 1 if $ gmrOK eq 'true' and $ slavelist =~ /(^|\s)$slave(\s|$)/ ;
# otherwise, gmrOK is a list of slaves who can redirect
return 1 if $ gmrOK =~ /(^|\s)$slave(\s|$)/ ;
return 0 ;
# LATER/NEVER: include a call to an external program to override a 'true',
# based on, say, the time of day or network load etc. Cons: shelling out,
# deciding the name of the program (yet another rc var?)
}
2011-01-15 16:39:56 +01:00
# ------------------------------------------------------------------------------
# per perl rules, this should be the last line in such a file:
2009-12-06 10:56:53 +01:00
1 ;