1 package Girocco
::Project
;
10 use Girocco
::HashUtil
;
11 use Girocco
::ProjPerm
;
13 use base
('Girocco::ProjPerm::'.$Girocco::Config
::permission_control
); # mwahaha
28 require Digest
::SHA
::PurePerl
;
29 Digest
::SHA
::PurePerl
->import(
32 die "One of Digest::SHA or Digest::SHA1 or Digest::SHA::PurePerl "
33 . "must be available\n";
36 our $metadata_fields = {
37 homepage
=> ['Homepage URL', 'hp', 'text'],
38 shortdesc
=> ['Short description', 'desc', 'text'],
39 README
=> ['README (HTML, lt 8kb)', 'README', 'textarea'],
40 notifymail
=> ['Commit notify - mail to', 'notifymail', 'text'],
41 notifyjson
=> ['Commit notify - <a href="http://help.github.com/post-receive-hooks/">POST JSON</a> at', 'notifyjson', 'text'],
42 notifycia
=> ['Commit notify - <a href="http://cia.vc/doc/">CIA project</a> name', 'notifycia', 'text'],
47 my @pelems = split('/', $self->{name
});
48 pop @pelems; # do not create dir for the project itself
49 my $path = $self->{base_path
};
50 foreach my $pelem (@pelems) {
52 (-d
"$path") or mkdir $path or die "mkdir $path: $!";
53 chmod 02775, $path; # ok if fails (dir may already exist and be owned by someone else)
57 # With a leading ':' get from config replacing ':' with 'gitweb.'
58 # With a leading '%' get from config after removing '%'
59 # Otherwise it's a file name to be loaded
60 # %propmapro entries are loaded but never written
65 desc
=> 'description',
66 README
=> 'README.html',
68 notifymail
=> '%hooks.mailinglist',
69 notifytag
=> '%hooks.announcelist',
70 notifyjson
=> '%hooks.jsonurl',
71 notifycia
=> '%hooks.cianame',
75 lastchange
=> ':lastchange',
76 lastactivity
=> 'info/lastactivity',
77 creationtime
=> '%girocco.creationtime',
78 origurl
=> ':baseurl',
81 # Projects with any of these names will be disallowed to avoid possible
82 # collisions with cgi script paths or chroot paths
83 our %reservedprojectnames = (
84 b
=> 1, # /b/ -> bundle.cgi
86 h
=> 1, # /h/ -> html.cgi
87 r
=> 1, # /r/ -> git http
88 w
=> 1, # /w/ -> gitweb
89 srv
=> 1, # /srv/git/ -> chroot ssh git repositories
93 system($Girocco::Config
::basedir
. '/gitweb/genindex.sh');
99 $self->{path
}.'/'.$name;
105 my $pname = $propmap{$name};
106 $pname = $propmapro{$name} unless $pname;
107 $pname or die "unknown property: $name";
108 if ($pname =~ s/^://) {
109 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.$pname"`;
112 } elsif ($pname =~ s/^%//) {
113 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "$pname"`;
118 open P
, '<', $self->_property_path($pname) or return undef;
121 my $value = join('', @value); chomp $value;
127 my ($name, $value) = @_;
128 my $pname = $propmap{$name};
129 $pname or die "unknown property: $name";
131 if ($pname =~ s/^://) {
132 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', "gitweb.$pname", $value);
134 } elsif ($pname =~ s/^%//) {
135 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', $pname, $value);
139 my $P = lock_file
($self->_property_path($pname));
140 $value ne '' and print $P "$value\n";
142 unlock_file
($self->_property_path($pname));
145 sub _properties_load
{
147 foreach my $prop (keys %propmap) {
148 $self->{$prop} = $self->_property_fget($prop);
150 foreach my $prop (keys %propmapro) {
151 $self->{$prop} = $self->_property_fget($prop);
153 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config --bool "gitweb.statusupdates" 2>/dev/null`;
155 $val = ($val eq 'false') ?
0 : 1;
156 $self->{statusupdates
} = $val;
157 delete $self->{auth
};
158 $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.repoauth"`;
160 if ($val =~ /^# ([A-Z]+)AUTH ([0-9a-f]+) (\d+)/) {
162 if (time < $expire) {
163 $self->{authtype
} = $1;
169 sub _properties_save
{
171 foreach my $prop (keys %propmap) {
172 $self->_property_fput($prop, $self->{$prop});
174 $self->{statusupdates
} = 1
175 unless defined($self->{statusupdates
}) && $self->{statusupdates
} =~ /^\d+$/;
176 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', '--bool',
177 "gitweb.statusupdates", $self->{statusupdates
});
178 if (defined($self->{origurl
}) && defined($self->{url
}) &&
179 $self->{origurl
} ne $self->{url
} && -e
$self->_property_path(".banged")) {
180 if (open(X
, '>', $self->_property_path(".bangagain"))) {
182 chmod(0664, $self->_property_path(".bangagain"));
189 $self->_property_path('.nofetch');
195 my $nf = $self->_nofetch_path;
197 open X
, '>', $nf or die "nofetch failed: $!";
200 unlink $nf or die "yesfetch failed: $!";
206 $self->_property_path('.clonelog');
209 sub _clonefail_path
{
211 $self->_property_path('.clone_failed');
216 $self->_property_path('.clone_in_progress');
222 my $np = $self->_clonep_path;
224 open X
, '>', $np or die "clonep failed: $!";
227 unlink $np or die "clonef failed: $!";
230 sub _alternates_setup
{
232 return unless $self->{name
} =~ m
#/#;
233 my $forkee_name = get_forkee_name
($self->{name
});
234 my $forkee_path = get_forkee_path
($self->{name
});
235 return unless -d
$forkee_path;
236 mkdir $self->{path
}.'/refs'; chmod 02775, $self->{path
}.'/refs';
237 mkdir $self->{path
}.'/objects'; chmod 02775, $self->{path
}.'/objects';
238 mkdir $self->{path
}.'/objects/info'; chmod 02775, $self->{path
}.'/objects/info';
240 # We set up both alternates and http_alternates since we cannot use
241 # relative path in alternates - that doesn't work recursively.
243 my $filename = $self->{path
}.'/objects/info/alternates';
244 open X
, '>', $filename or die "alternates failed: $!";
245 print X
"$forkee_path/objects\n";
247 chmod 0664, $filename or warn "cannot chmod $filename: $!";
249 if ($Girocco::Config
::httppullurl
) {
250 $filename = $self->{path
}.'/objects/info/http-alternates';
251 open X
, '>', $filename or die "http-alternates failed: $!";
252 my $upfork = $forkee_name;
253 do { print X
"$Girocco::Config::httppullurl/$upfork.git/objects\n"; } while ($upfork =~ s
#/?.+?$## and $upfork); #
255 chmod 0664, $filename or warn "cannot chmod $filename: $!";
258 # The symlink is problematic since git remote prune will traverse it.
259 #symlink "$forkee_path/refs", $self->{path}.'/refs/forkee';
261 # copy refs from parent project
262 system("'$Girocco::Config::git_bin' --git-dir='$forkee_path' show-ref > '$self->{path}/packed-refs'");
263 # initialize HEAD, hacky version
264 system("cp $forkee_path/HEAD $self->{path}/HEAD");
265 chmod 0664, "$self->{path}/packed-refs", "$self->{path}/HEAD";
270 my $perms = $Girocco::Config
::permission_control
eq 'Hooks' ?
02777 : 02775;
271 mkdir $self->{path
}.'/ctags'; chmod $perms, $self->{path
}.'/ctags';
277 $xtra .= join(',', @
{$self->{users
}});
278 filedb_atomic_append
(jailed_file
('/etc/group'),
279 join(':', $self->{name
}, $self->{crypt}, '\i', $xtra));
284 my $xtra = join(',', @
{$self->{users
}});
285 filedb_atomic_edit
(jailed_file
('/etc/group'),
289 if ($self->{name
} eq (split /:/)[0]) {
290 # preserve readonly flag
291 s/::([^:]*)$/:$1/ and $xtra = ":$xtra";
292 return join(':', $self->{name
}, $self->{crypt}, $self->{gid
}, $xtra)."\n";
302 filedb_atomic_edit
(jailed_file
('/etc/group'),
304 $self->{name
} ne (split /:/)[0] and return $_;
312 $self->{path
}.'/hooks/'.$name;
318 my $hooksdir = $self->{path
}.'/hooks';
319 -d
$hooksdir or mkdir $hooksdir or
320 die "hooks directory does not exist and unable to create it for project " . $self->{name
} . ": $!";
321 open SRC
, '<', "$Girocco::Config::basedir/hooks/$name" or die "cannot open hook $name: $!";
322 open DST
, '>', $self->_hook_path($name) or die "cannot open hook $name for writing: $!";
323 while (<SRC
>) { print DST
$_; }
326 chmod 0775, $self->_hook_path($name) or die "cannot chmod hook $name: $!";
331 foreach my $hook ('pre-receive', 'post-receive', 'update', 'post-update') {
332 $self->_hook_install($hook);
336 # private constructor, do not use
339 my ($name, $base_path, $path) = @_;
340 does_exist
($name,1) || valid_name
($name) or die "refusing to create project with invalid name ($name)!";
341 $path ||= "$base_path/$name.git";
342 my $proj = { name
=> $name, base_path
=> $base_path, path
=> $path };
347 # public constructor #0
348 # creates a virtual project not connected to disk image
349 # you can conjure() it later to disk
352 my ($name, $mirror) = @_;
353 my $self = $class->_new($name, $Girocco::Config
::reporoot
);
355 $self->{mirror
} = $mirror;
356 $self->{email
} = $self->{orig_email
} = '';
360 # public constructor #1
363 my $name = shift || '';
365 open F
, '<', jailed_file
("/etc/group") or die "project load failed: $!";
369 next unless (shift eq $name);
371 my $self = $class->_new($name, $Girocco::Config
::reporoot
);
372 (-d
$self->{path
}) or die "invalid path (".$self->{path
}.") for project ".$self->{name
};
375 ($self->{crypt}, $self->{gid
}, $ulist) = @_;
377 $self->{users
} = [split /,/, $ulist];
378 $self->{HEAD
} = $self->get_HEAD;
379 $self->{orig_HEAD
} = $self->{HEAD
};
380 $self->{orig_users
} = [@
{$self->{users
}}];
381 $self->{mirror
} = ! -e
$self->_nofetch_path;
382 $self->{clone_in_progress
} = -e
$self->_clonep_path;
383 $self->{clone_logged
} = -e
$self->_clonelog_path;
384 $self->{clone_failed
} = -e
$self->_clonefail_path;
385 $self->{ccrypt
} = $self->{crypt};
387 $self->_properties_load;
388 $self->{orig_email
} = $self->{email
};
389 $self->{loaded
} = 1; # indicates self was loaded from etc/group file
396 # $proj may not be in sane state if this returns false!
400 my $cgi = $gcgi->cgi;
402 my ($pwd, $pwd2) = ($cgi->param('pwd'), $cgi->param('pwd2'));
403 # in case passwords are disabled
404 defined($pwd) or $pwd = ''; defined($pwd2) or $pwd = '';
405 if ($Girocco::Config
::project_passwords
and not $self->{crypt} and $pwd eq '' and $pwd2 eq '') {
406 $gcgi->err("Empty passwords are not permitted.");
408 if ($pwd ne '' or not $self->{crypt}) {
409 $self->{crypt} = scrypt_sha1
($pwd);
411 if (($pwd ne '' || $pwd2 ne '') and $pwd ne $pwd2) {
412 $gcgi->err("Our high-paid security consultants have determined that the admin passwords you have entered do not match each other.");
415 $self->{cpwd
} = $cgi->param('cpwd');
417 my ($forkee,$project) = ($self->{name
} =~ m
#^(.*/)?([^/]+)$#);
418 my $newtype = $forkee ?
'fork' : 'project';
419 length($project) <= 64
420 or $gcgi->err("The $newtype name is longer than 64 characters. Do you really need that much?");
422 if ($Girocco::Config
::project_owners
eq 'email') {
423 $self->{email
} = $gcgi->wparam('email');
424 valid_email
($self->{email
})
425 or $gcgi->err("Your email sure looks weird...?");
426 length($self->{email
}) <= 96
427 or $gcgi->err("Your email is longer than 96 characters. Do you really need that much?");
430 $self->{url
} = $gcgi->wparam('url');
432 valid_repo_url
($self->{url
})
433 or $gcgi->err("Invalid URL. Note that only HTTP and Git protocols are supported. If the URL contains funny characters, contact me.");
434 if ($Girocco::Config
::restrict_mirror_hosts
) {
435 my $mh = extract_url_hostname
($self->{url
});
437 or $gcgi->err("Invalid URL. Note that only DNS names are allowed, not IP addresses.");
438 !is_our_hostname
($mh)
439 or $gcgi->err("Invalid URL. Mirrors from this host are not allowed, please create a fork instead.");
443 $self->{desc
} = $gcgi->wparam('desc');
444 length($self->{desc
}) <= 1024
445 or $gcgi->err("<b>Short</b> description length > 1kb!");
447 $self->{README
} = $gcgi->wparam('README');
448 length($self->{README
}) <= 8192
449 or $gcgi->err("README length > 8kb!");
451 $self->{hp
} = $gcgi->wparam('hp');
453 valid_web_url
($self->{hp
})
454 or $gcgi->err("Invalid homepage URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
459 foreach my $user ($cgi->param('user')) {
460 if (!exists($users{$user})) {
462 push(@users, $user) if Girocco
::User
::valid_name
($user) && Girocco
::User
::does_exist
($user)
465 $self->{users
} = \
@users;
467 $self->{HEAD
} = $cgi->param('HEAD') if $cgi->param('HEAD');
469 # schedule deletion of tags (will be committed by update() after auth)
470 $self->{tags_to_delete
} = [$cgi->param('tags')];
472 $self->{notifymail
} = $gcgi->wparam('notifymail');
473 if ($self->{notifymail
}) {
474 (valid_email_multi
($self->{notifymail
}) and length($self->{notifymail
}) <= 512)
475 or $gcgi->err("Invalid notify e-mail address. Use mail,mail to specify multiple addresses; total length must not exceed 512 characters, however.");
478 $self->{notifyjson
} = $gcgi->wparam('notifyjson');
479 if ($self->{notifyjson
}) {
480 valid_web_url
($self->{notifyjson
})
481 or $gcgi->err("Invalid JSON notify URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
484 $self->{notifycia
} = $gcgi->wparam('notifycia');
485 if ($self->{notifycia
}) {
486 $self->{notifycia
} =~ /^[a-zA-Z0-9._-]+$/
487 or $gcgi->err("Overly suspicious CIA notify project name. If it is actually valid, contact me.");
490 if ($cgi->param('setstatusupdates')) {
491 my $val = $gcgi->wparam('statusupdates') || '0';
492 $self->{statusupdates
} = $val ?
1 : 0;
495 not $gcgi->err_check;
501 name
=> $self->{name
},
502 email
=> $self->{email
},
504 desc
=> html_esc
($self->{desc
}),
505 README
=> html_esc
($self->{README
}),
507 users
=> $self->{users
},
508 notifymail
=> html_esc
($self->{notifymail
}),
509 notifyjson
=> html_esc
($self->{notifyjson
}),
510 notifycia
=> html_esc
($self->{notifycia
}),
514 # return true if $enc_passwd is a match for $plain_passwd
515 my $_check_passwd_match = sub {
516 my $enc_passwd = shift;
517 my $plain_passwd = shift;
518 defined($enc_passwd) or $enc_passwd = '';
519 defined($plain_passwd) or $plain_passwd = '';
520 # $enc_passwd may be crypt or crypt_sha1
521 if ($enc_passwd =~ m
(^\
$sha1\
$(\d
+)\
$([./0-9A-Za-z]{1,64})\$[./0-9A
-Za
-z
]{28}$)) {
522 # It's using sha1-crypt
523 return $enc_passwd eq crypt_sha1
($plain_passwd, $2, -(0+$1));
526 return $enc_passwd eq crypt($plain_passwd, $enc_passwd);
534 $self->{ccrypt
} or die "Can't authenticate against a project with no password";
535 defined($self->{cpwd
}) or $self->{cpwd
} = '';
536 unless ($_check_passwd_match->($self->{ccrypt
}, $self->{cpwd
})) {
537 $gcgi->err("Your admin password does not match!");
543 # return true if the password from the file is empty or consists of all the same
544 # character. However, if the project was NOT loaded from the group file
545 # (!self->{loaded}) then the password is never locked.
546 # This function does NOT check $Girocco::Config::project_passwords, the caller
547 # is responsible for doing so if desired. Same for $self->{email}.
548 sub is_password_locked
{
551 $self->{loaded
} or return 0;
552 my $testcrypt = $self->{ccrypt
}; # The value from the group file
553 defined($testcrypt) or $testcrypt = '';
554 $testcrypt ne '' or return 1; # No password at all
555 $testcrypt =~ /^(.)\1*$/ and return 1; # Bogus crypt value
556 return 0; # Not locked
560 use POSIX
qw(strftime);
564 $self->_mkdir_forkees;
566 mkdir($self->{path
}) or die "mkdir $self->{path} failed: $!";
567 if ($Girocco::Config
::owning_group
) {
568 my $gid = scalar(getgrnam($Girocco::Config
::owning_group
));
569 chown(-1, $gid, $self->{path
}) or die "chgrp $gid $self->{path} failed: $!";
570 chmod(02775, $self->{path
}) or die "chmod 02775 $self->{path} failed: $!";
572 chmod(02777, $self->{path
}) or die "chmod 02777 $self->{path} failed: $!";
574 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'init', '--bare', '--shared='.$self->shared_mode()) == 0
575 or die "git init $self->{path} failed: $?";
576 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'receive.denyNonFastforwards', 'false') == 0
577 or die "disabling receive.denyNonFastforwards failed: $?";
578 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'gc.auto', '0') == 0
579 or die "disabling gc.auto failed: $?";
580 my ($S,$M,$H,$d,$m,$y) = gmtime(time());
581 $self->{creationtime
} = strftime
("%Y-%m-%dT%H:%M:%SZ", $S, $M, $H, $d, $m, $y, -1, -1, -1);
582 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'girocco.creationtime', $self->{creationtime
}) == 0
583 or die "setting girocco.creationtime failed: $?";
584 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'repack.writebitmaps', 'true') == 0
585 or die "enabling repack.writebitmaps failed: $?";
587 # /info must have right permissions,
588 # and git init didn't do it for some reason.
589 # config must have correct permissions.
590 # and Git 2.1.0 - 2.2.1 incorrectly add +x for some reason.
591 if ($Girocco::Config
::owning_group
) {
592 chmod(02775, $self->{path
}."/info") or die "chmod 02775 $self->{path}/info failed: $!";
593 chmod(0664, $self->{path
}."/config") or die "chmod 0664 $self->{path}/config failed: $!";
595 chmod(02777, $self->{path
}."/info") or die "chmod 02777 $self->{path}/info failed: $!";
596 chmod(0666, $self->{path
}."/config") or die "chmod 0666 $self->{path}/config failed: $!";
599 $self->_properties_save;
600 $self->_alternates_setup;
602 $self->_group_remove;
603 $self->_group_add($pushers);
604 $self->_hooks_install;
605 #$self->perm_initialize;
606 $self->_update_index;
614 $self->perm_initialize;
622 if ($Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob") {
623 system("$Girocco::Config::basedir/bin/create-personal-mob-area", $self->{name
}) == 0
624 or die "create-personal-mob-area $self->{name} failed";
626 $self->perm_initialize;
632 unlink ($self->_clonefail_path()); # Ignore EEXIST error
633 unlink ($self->_clonelog_path()); # Ignore EEXIST error
636 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or die "cannot connect to taskd.socket: $!";
637 $sock->print("clone ".$self->{name
}."\n");
638 # Just ignore reply, we are going to succeed anyway and the I/O
639 # would apparently get quite hairy.
648 $self->_properties_save;
649 $self->_group_update;
651 if (exists($self->{tags_to_delete
})) {
652 $self->delete_ctag($_) foreach(@
{$self->{tags_to_delete
}});
655 $self->set_HEAD($self->{HEAD
}) unless $self->{orig_HEAD
} eq $self->{HEAD
};
657 my @users_add = grep { $a = $_; not scalar grep { $a eq $_ } $self->{orig_users
} } $self->{users
};
658 my @users_del = grep { $a = $_; not scalar grep { $a eq $_ } $self->{users
} } $self->{orig_users
};
659 $self->perm_user_add($_, Girocco
::User
::resolve_uid
($_)) foreach (@users_add);
660 $self->perm_user_del($_, Girocco
::User
::resolve_uid
($_)) foreach (@users_del);
662 $self->_update_index if $self->{email
} ne $self->{orig_email
};
663 $self->{orig_email
} = $self->{email
};
668 sub update_password
{
672 $self->{crypt} = scrypt_sha1
($pwd);
673 $self->_group_update;
676 # You can explicitly do this just on a ghost() repository too.
680 if (-d
$self->{path
}) {
681 system('rm', '-rf', $self->{path
}) == 0
682 or die "rm -rf $self->{path} failed: $?";
684 # attempt to clean up any empty fork directories by removing them
685 my @pelems = split('/', $self->{name
});
686 while (@pelems > 1) {
689 rmdir join('/', $Girocco::Config
::reporoot
, @pelems) or last;
691 $self->_group_remove;
692 $self->_update_index;
695 sub _contains_files
{
697 (-d
$dir) or return 0;
698 opendir(my $dh, $dir) or die "opendir $dir failed: $!";
699 while (my $entry = readdir($dh)) {
700 next if $entry eq '' || $entry eq '.' || $entry eq '..';
701 closedir($dh), return 1
702 if -f
"$dir/$entry" ||
703 -d
"$dir/$entry" && _contains_files
("$dir/$entry");
712 return _contains_files
($Girocco::Config
::reporoot
.'/'.$self->{name
});
716 # A project is considered empty if the git repository does not
717 # have any refs. This means packed-refs does not exist or is
718 # empty or only has lines starting with '#' AND there are no
719 # files in the refs subdirectory hierarchy (no matter how deep).
723 (-d
$self->{path
}) or return 0;
724 if (-e
$self->{path
}.'/packed-refs') {
725 open(my $pr, '<', $self->{path
}.'/packed-refs')
726 or die "open $self->{path}./packed-refs failed: $!";
728 while (my $ref = <$pr>) {
729 next if $ref =~ /^#/;
734 return 0 if $foundref;
736 (-d
$self->{path
}.'/refs') or return 1;
737 return !_contains_files
($self->{path
}.'/refs');
744 # sanity check, disallow filenames starting with . .. or /
745 unlink($self->{path
}.'/ctags/'.$ctag) if($ctag !~ m
|^(\
.\
.?
)/|);
751 opendir(my $dh, $self->{path
}.'/ctags')
753 @ctags = grep { -f
"$self->{path}/ctags/$_" } readdir($dh);
761 open($fh, '-|', "$Girocco::Config::git_bin --git-dir=$self->{path} show-ref --heads") or die "could not get list of heads";
765 next if !m
#^[0-9a-f]{40}\s+refs/heads/(.+)$ #x;
774 my $HEAD = `$Girocco::Config::git_bin --git-dir=$self->{path} symbolic-ref HEAD`;
776 die "could not get HEAD" if ($HEAD !~ m{^refs/heads/(.+)$});
783 # Cursory checks only -- if you want to break your HEAD, be my guest
784 if ($newHEAD =~ /^\/|['<>]|\.\.|\/$/) {
785 die "grossly invalid new HEAD: $newHEAD";
787 system($Girocco::Config::git_bin, "--git-dir=$self->{path}", 'symbolic
-ref', 'HEAD
', "refs/heads/$newHEAD");
788 die "could not set HEAD" if ($? >> 8);
789 ! -d "$self->{path}/mob" || $Girocco::Config::mob ne 'mob
'
790 or system('cp
', '-p
', '-f
', "$self->{path}/HEAD", "$self->{path}/mob/HEAD") == 0;
796 $type = 'REPO
' unless $type && $type =~ /^[A-Z]+$/;
798 $self->{authtype} = $type;
801 $self->{auth} = sha1_hex(time . $$ . rand() . join(':',%$self));
803 my $expire = time + 24 * 3600;
804 my $propval = "# ${type}AUTH $self->{auth} $expire";
805 system($Girocco::Config::git_bin, '--git
-dir
='.$self->{path}, 'config
', 'gitweb
.repoauth
', $propval);
812 delete $self->{auth};
813 delete $self->{authtype};
814 system($Girocco::Config::git_bin, '--git
-dir
='.$self->{path}, 'config
', '--unset
', 'gitweb
.repoauth
');
821 my $before_count = @{$self->{users}};
822 $self->{users} = [grep { $_ ne $username } @{$self->{users}}];
823 return @{$self->{users}} != $before_count;
828 sub get_forkee_name {
830 (m#^(.*)/.*?$#)[0]; #
833 sub get_forkee_path {
834 no warnings; # avoid silly 'unsuccessful
stat on filename with
\n' warning
835 my $forkee = $Girocco::Config::reporoot.'/'.get_forkee_name($_[0]).'.git
';
836 -d $forkee ? $forkee : '';
839 # Ultimately the full project/fork name could end up being part of a Git ref name
840 # when a project's forks are combined into one giant repository
for efficiency
.
841 # That means that the project/fork name must satisfy the Git ref name requirements:
843 # 1. Characters with an ASCII value less than or equal to 32 are not allowed
844 # 2. The character with an ASCII value of 0x7F is not allowed
845 # 3. The characters '~', '^', ':', '\', '*', '?', and '[' are not allowed
846 # 4. The character '/' is a separator and is not allowed within a name
847 # 5. The name may not start with '.' or end with '.'
848 # 6. The name may not end with '.lock'
849 # 7. The name may not contain the '..' sequence
850 # 8. The name may not contain the '@{' sequence
851 # 9. If multiple components are used (separated by '/'), no empty '' components
853 # We also prohibit a trailing '.git' on any path component and futher restrict
854 # the allowed characters to alphanumeric and [+._-] where names must start with
857 # The rules are relaxed slightly for existing projects (for now) to accomodate them.
859 sub _valid_name_characters
{
865 and (not m
#/[+._-]# or $relaxed)
867 and (not m
#\.$# or $relaxed)
870 and (not m
#\.lock/#i)
871 and (not m
#\.lock$#i)
873 and m
#^[a-zA-Z0-9/+._-]+$#;
877 no warnings
; # avoid silly 'unsuccessful stat on filename with \n' warning
879 _valid_name_characters
($_) and not exists($reservedprojectnames{$_})
880 and @
{[m
#/#g]} <= 5 # maximum fork depth is 5
881 and ((not m
#/#) or -d get_forkee_path($_)); # will also catch ^/
884 # It's possible that some forks have been kept but the forkee is gone.
885 # In this case the standard valid_name check is too strict.
887 no warnings
; # avoid silly 'unsuccessful stat on filename with \n' warning
888 my ($name, $nodie) = @_;
890 _valid_name_characters
($name, 1)
891 and ((not $name =~ m
#/#)
892 or -d get_forkee_path
($name)
893 or -d
$Girocco::Config
::reporoot
.'/'.get_forkee_name
($name)));
894 (!$okay && $nodie) and return undef;
895 !$okay and die "tried to query for project with invalid name $name!";
896 (-d
$Girocco::Config
::reporoot
."/$name.git");
903 open F
, '<', jailed_file
("/etc/group") or die "getting project list failed: $!";
907 next if ($_[2] < 65536);
909 push @projects, $_[0];