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
94 system("$Girocco::Config::basedir/gitweb/genindex.sh", $self->{name
});
100 $self->{path
}.'/'.$name;
106 my $pname = $propmap{$name};
107 $pname = $propmapro{$name} unless $pname;
108 $pname or die "unknown property: $name";
109 if ($pname =~ s/^://) {
110 my $val = get_git
("--git-dir=$self->{path}", 'config', "gitweb.$pname");
111 defined($val) or $val = '';
114 } elsif ($pname =~ s/^%//) {
115 my $val = get_git
("--git-dir=$self->{path}", 'config', $pname);
116 defined($val) or $val = '';
121 open my $p, '<', $self->_property_path($pname) or return undef;
124 my $value = join('', @value); chomp $value;
130 my ($name, $value) = @_;
131 my $pname = $propmap{$name};
132 $pname or die "unknown property: $name";
134 if ($pname =~ s/^://) {
135 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', "gitweb.$pname", $value);
137 } elsif ($pname =~ s/^%//) {
138 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', $pname, $value);
142 my $P = lock_file
($self->_property_path($pname));
143 $value ne '' and print $P "$value\n";
145 unlock_file
($self->_property_path($pname));
148 sub _properties_load
{
150 foreach my $prop (keys %propmap) {
151 $self->{$prop} = $self->_property_fget($prop);
153 foreach my $prop (keys %propmapro) {
154 $self->{$prop} = $self->_property_fget($prop);
156 my $val = get_git
("--git-dir=$self->{path}", 'config', '--bool', 'gitweb.statusupdates');
157 defined($val) or $val = '';
159 $val = ($val eq 'false') ?
0 : 1;
160 $self->{statusupdates
} = $val;
161 delete $self->{auth
};
162 $val = get_git
("--git-dir=$self->{path}", 'config', 'gitweb.repoauth');
163 defined($val) or $val = '';
165 if ($val =~ /^# ([A-Z]+)AUTH ([0-9a-f]+) (\d+)/) {
167 if (time < $expire) {
168 $self->{authtype
} = $1;
174 sub _properties_save
{
177 foreach my $prop (keys %propmap) {
178 $self->_property_fput($prop, $self->{$prop});
180 $self->{statusupdates
} = 1
181 unless defined($self->{statusupdates
}) && $self->{statusupdates
} =~ /^\d+$/;
182 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', '--bool',
183 "gitweb.statusupdates", $self->{statusupdates
});
184 if (defined($self->{origurl
}) && defined($self->{url
}) &&
185 $self->{origurl
} ne $self->{url
} && -e
$self->_property_path(".banged")) {
186 if (open($fd, '>', $self->_property_path(".bangagain"))) {
188 chmod(0664, $self->_property_path(".bangagain"));
191 open $fd, '>', "$self->{path}/htmlcache/changed" and close $fd;
196 $self->_property_path('.nofetch');
202 my $nf = $self->_nofetch_path;
204 open my $x, '>', $nf or die "nofetch failed: $!";
207 unlink $nf or die "yesfetch failed: $!";
213 $self->_property_path('.clonelog');
216 sub _clonefail_path
{
218 $self->_property_path('.clone_failed');
223 $self->_property_path('.clone_in_progress');
229 my $np = $self->_clonep_path;
231 open my $x, '>', $np or die "clonep failed: $!";
234 unlink $np or die "clonef failed: $!";
237 sub _alternates_setup
{
239 return unless $self->{name
} =~ m
#/#;
240 my $forkee_name = get_forkee_name
($self->{name
});
241 my $forkee_path = get_forkee_path
($self->{name
});
242 return unless -d
$forkee_path;
243 mkdir $self->{path
}.'/refs'; chmod 02775, $self->{path
}.'/refs';
244 mkdir $self->{path
}.'/objects'; chmod 02775, $self->{path
}.'/objects';
245 mkdir $self->{path
}.'/objects/info'; chmod 02775, $self->{path
}.'/objects/info';
247 # We set up both alternates and http_alternates since we cannot use
248 # relative path in alternates - that doesn't work recursively.
250 my $filename = $self->{path
}.'/objects/info/alternates';
251 open my $x, '>', $filename or die "alternates failed: $!";
252 print $x "$forkee_path/objects\n";
254 chmod 0664, $filename or warn "cannot chmod $filename: $!";
256 if ($Girocco::Config
::httppullurl
) {
257 $filename = $self->{path
}.'/objects/info/http-alternates';
258 open my $x, '>', $filename or die "http-alternates failed: $!";
259 my $upfork = $forkee_name;
260 do { print $x "$Girocco::Config::httppullurl/$upfork.git/objects\n"; } while ($upfork =~ s
#/?.+?$## and $upfork); #
262 chmod 0664, $filename or warn "cannot chmod $filename: $!";
265 # copy refs from parent project
266 open(SAVEOUT
, ">&STDOUT") || die "couldn't dup STDOUT: $!";
267 my $result = open(STDOUT
, '>', "$self->{path}/packed-refs");
270 open(STDOUT
, ">&SAVEOUT") || die "couldn't dup SAVEOUT to STDOUT: $!";
271 close(SAVEOUT
) or die "couldn't close SAVEOUT: $!";
272 die "could not write fork's packed-refs file: $resultstr";
274 system($Girocco::Config
::git_bin
, "--git-dir=$forkee_path", 'for-each-ref', '--format=%(objectname) %(refname)');
275 $result = close(STDOUT
);
277 open(STDOUT
, ">&SAVEOUT") || die "couldn't dup SAVEOUT to STDOUT: $!";
278 close(SAVEOUT
) or die "couldn't close SAVEOUT: $!";
279 $result or die "could not close fork's packed-refs file: $resultstr";
282 my $HEAD = get_git
("--git-dir=$forkee_path", 'symbolic-ref', 'HEAD');
283 defined($HEAD) && $HEAD =~ m
,^refs
/heads
/., or $HEAD = 'refs/heads/master';
285 system($Girocco::Config
::git_bin
, "--git-dir=$self->{path}", 'symbolic-ref', 'HEAD', $HEAD);
286 chmod 0664, "$self->{path}/packed-refs", "$self->{path}/HEAD";
291 my $perms = $Girocco::Config
::permission_control
eq 'Hooks' ?
02777 : 02775;
292 mkdir $self->{path
}.'/ctags'; chmod $perms, $self->{path
}.'/ctags';
298 $xtra .= join(',', @
{$self->{users
}});
299 filedb_atomic_append
(jailed_file
('/etc/group'),
300 join(':', $self->{name
}, $self->{crypt}, '\i', $xtra));
305 my $xtra = join(',', @
{$self->{users
}});
306 filedb_atomic_edit
(jailed_file
('/etc/group'),
310 if ($self->{name
} eq (split /:/)[0]) {
311 # preserve readonly flag
312 s/::([^:]*)$/:$1/ and $xtra = ":$xtra";
313 return join(':', $self->{name
}, $self->{crypt}, $self->{gid
}, $xtra)."\n";
323 filedb_atomic_edit
(jailed_file
('/etc/group'),
325 $self->{name
} ne (split /:/)[0] and return $_;
333 $self->{path
}.'/hooks/'.$name;
339 my $hooksdir = $self->{path
}.'/hooks';
340 my $oldmask = umask();
341 umask($oldmask & ~0070);
342 -d
$hooksdir or mkdir $hooksdir or
343 die "hooks directory does not exist and unable to create it for project " . $self->{name
} . ": $!";
345 open my $src, '<', "$Girocco::Config::basedir/hooks/$name" or die "cannot open hook $name: $!";
346 open my $dst, '>', $self->_hook_path($name) or die "cannot open hook $name for writing: $!";
347 while (<$src>) { print $dst $_; }
350 chmod 0775, $self->_hook_path($name) or die "cannot chmod hook $name: $!";
355 foreach my $hook ('pre-receive', 'post-receive', 'update') {
356 $self->_hook_install($hook);
360 # private constructor, do not use
363 my ($name, $base_path, $path) = @_;
364 does_exist
($name,1) || valid_name
($name) or die "refusing to create project with invalid name ($name)!";
365 $path ||= "$base_path/$name.git";
366 my $proj = { name
=> $name, base_path
=> $base_path, path
=> $path };
371 # public constructor #0
372 # creates a virtual project not connected to disk image
373 # you can conjure() it later to disk
376 my ($name, $mirror) = @_;
377 my $self = $class->_new($name, $Girocco::Config
::reporoot
);
379 $self->{mirror
} = $mirror;
380 $self->{email
} = $self->{orig_email
} = '';
384 # public constructor #1
387 my $name = shift || '';
389 open my $fd, '<', jailed_file
("/etc/group") or die "project load failed: $!";
390 my $r = qr/^\Q$name\E:/;
391 foreach (grep /$r/, <$fd>) {
394 my $self = $class->_new($name, $Girocco::Config
::reporoot
);
395 (-d
$self->{path
}) or die "invalid path (".$self->{path
}.") for project ".$self->{name
};
398 (undef, $self->{crypt}, $self->{gid
}, $ulist) = split /:/;
400 $self->{users
} = [split /,/, $ulist];
401 $self->{HEAD
} = $self->get_HEAD;
402 $self->{orig_HEAD
} = $self->{HEAD
};
403 $self->{orig_users
} = [@
{$self->{users
}}];
404 $self->{mirror
} = ! -e
$self->_nofetch_path;
405 $self->{clone_in_progress
} = -e
$self->_clonep_path;
406 $self->{clone_logged
} = -e
$self->_clonelog_path;
407 $self->{clone_failed
} = -e
$self->_clonefail_path;
408 $self->{ccrypt
} = $self->{crypt};
410 $self->_properties_load;
411 $self->{orig_email
} = $self->{email
};
412 $self->{loaded
} = 1; # indicates self was loaded from etc/group file
420 # $proj may not be in sane state if this returns false!
424 my $cgi = $gcgi->cgi;
426 my ($pwd, $pwd2) = ($cgi->param('pwd'), $cgi->param('pwd2'));
427 # in case passwords are disabled
428 defined($pwd) or $pwd = ''; defined($pwd2) or $pwd = '';
429 if ($Girocco::Config
::project_passwords
and not $self->{crypt} and $pwd eq '' and $pwd2 eq '') {
430 $gcgi->err("Empty passwords are not permitted.");
432 if ($pwd ne '' or not $self->{crypt}) {
433 $self->{crypt} = scrypt_sha1
($pwd);
435 if (($pwd ne '' || $pwd2 ne '') and $pwd ne $pwd2) {
436 $gcgi->err("Our high-paid security consultants have determined that the admin passwords you have entered do not match each other.");
439 $self->{cpwd
} = $cgi->param('cpwd');
441 my ($forkee,$project) = ($self->{name
} =~ m
#^(.*/)?([^/]+)$#);
442 my $newtype = $forkee ?
'fork' : 'project';
443 length($project) <= 64
444 or $gcgi->err("The $newtype name is longer than 64 characters. Do you really need that much?");
446 if ($Girocco::Config
::project_owners
eq 'email') {
447 $self->{email
} = $gcgi->wparam('email');
448 valid_email
($self->{email
})
449 or $gcgi->err("Your email sure looks weird...?");
450 length($self->{email
}) <= 96
451 or $gcgi->err("Your email is longer than 96 characters. Do you really need that much?");
454 $self->{url
} = $gcgi->wparam('url');
456 valid_repo_url
($self->{url
})
457 or $gcgi->err("Invalid URL. Note that only HTTP and Git protocols are supported. If the URL contains funny characters, contact me.");
458 if ($Girocco::Config
::restrict_mirror_hosts
) {
459 my $mh = extract_url_hostname
($self->{url
});
461 or $gcgi->err("Invalid URL. Note that only DNS names are allowed, not IP addresses.");
462 !is_our_hostname
($mh)
463 or $gcgi->err("Invalid URL. Mirrors from this host are not allowed, please create a fork instead.");
467 $self->{desc
} = $gcgi->wparam('desc');
468 length($self->{desc
}) <= 1024
469 or $gcgi->err("<b>Short</b> description length > 1kb!");
471 $self->{README
} = $gcgi->wparam('README');
472 length($self->{README
}) <= 8192
473 or $gcgi->err("README length > 8kb!");
475 $self->{hp
} = $gcgi->wparam('hp');
477 valid_web_url
($self->{hp
})
478 or $gcgi->err("Invalid homepage URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
483 foreach my $user ($cgi->param('user')) {
484 if (!exists($users{$user})) {
486 push(@users, $user) if Girocco
::User
::valid_name
($user) && Girocco
::User
::does_exist
($user)
489 $self->{users
} = \
@users;
491 $self->{HEAD
} = $cgi->param('HEAD') if $cgi->param('HEAD');
493 # schedule deletion of tags (will be committed by update() after auth)
494 $self->{tags_to_delete
} = [$cgi->param('tags')];
496 $self->{notifymail
} = $gcgi->wparam('notifymail');
497 if ($self->{notifymail
}) {
498 (valid_email_multi
($self->{notifymail
}) and length($self->{notifymail
}) <= 512)
499 or $gcgi->err("Invalid notify e-mail address. Use mail,mail to specify multiple addresses; total length must not exceed 512 characters, however.");
502 $self->{notifyjson
} = $gcgi->wparam('notifyjson');
503 if ($self->{notifyjson
}) {
504 valid_web_url
($self->{notifyjson
})
505 or $gcgi->err("Invalid JSON notify URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
508 $self->{notifycia
} = $gcgi->wparam('notifycia');
509 if ($self->{notifycia
}) {
510 $self->{notifycia
} =~ /^[a-zA-Z0-9._-]+$/
511 or $gcgi->err("Overly suspicious CIA notify project name. If it is actually valid, contact me.");
514 if ($cgi->param('setstatusupdates')) {
515 my $val = $gcgi->wparam('statusupdates') || '0';
516 $self->{statusupdates
} = $val ?
1 : 0;
519 not $gcgi->err_check;
525 name
=> $self->{name
},
526 email
=> $self->{email
},
528 desc
=> html_esc
($self->{desc
}),
529 README
=> html_esc
($self->{README
}),
531 users
=> $self->{users
},
532 notifymail
=> html_esc
($self->{notifymail
}),
533 notifyjson
=> html_esc
($self->{notifyjson
}),
534 notifycia
=> html_esc
($self->{notifycia
}),
538 # return true if $enc_passwd is a match for $plain_passwd
539 my $_check_passwd_match = sub {
540 my $enc_passwd = shift;
541 my $plain_passwd = shift;
542 defined($enc_passwd) or $enc_passwd = '';
543 defined($plain_passwd) or $plain_passwd = '';
544 # $enc_passwd may be crypt or crypt_sha1
545 if ($enc_passwd =~ m
(^\
$sha1\
$(\d
+)\
$([./0-9A-Za-z]{1,64})\$[./0-9A
-Za
-z
]{28}$)) {
546 # It's using sha1-crypt
547 return $enc_passwd eq crypt_sha1
($plain_passwd, $2, -(0+$1));
550 return $enc_passwd eq crypt($plain_passwd, $enc_passwd);
558 $self->{ccrypt
} or die "Can't authenticate against a project with no password";
559 defined($self->{cpwd
}) or $self->{cpwd
} = '';
560 unless ($_check_passwd_match->($self->{ccrypt
}, $self->{cpwd
})) {
561 $gcgi->err("Your admin password does not match!");
567 # return true if the password from the file is empty or consists of all the same
568 # character. However, if the project was NOT loaded from the group file
569 # (!self->{loaded}) then the password is never locked.
570 # This function does NOT check $Girocco::Config::project_passwords, the caller
571 # is responsible for doing so if desired. Same for $self->{email}.
572 sub is_password_locked
{
575 $self->{loaded
} or return 0;
576 my $testcrypt = $self->{ccrypt
}; # The value from the group file
577 defined($testcrypt) or $testcrypt = '';
578 $testcrypt ne '' or return 1; # No password at all
579 $testcrypt =~ /^(.)\1*$/ and return 1; # Bogus crypt value
580 return 0; # Not locked
584 use POSIX
qw(strftime);
589 $self->_mkdir_forkees;
592 mkdir($self->{path
}) or die "mkdir $self->{path} failed: $!";
593 if ($Girocco::Config
::owning_group
) {
594 $gid = scalar(getgrnam($Girocco::Config
::owning_group
));
595 chown(-1, $gid, $self->{path
}) or die "chgrp $gid $self->{path} failed: $!";
596 chmod(02775, $self->{path
}) or die "chmod 02775 $self->{path} failed: $!";
598 chmod(02777, $self->{path
}) or die "chmod 02777 $self->{path} failed: $!";
600 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'init', '--quiet', '--bare', '--shared='.$self->shared_mode()) == 0
601 or die "git init $self->{path} failed: $?";
602 -d
$self->{path
}."/info" or mkdir $self->{path
}."/info"
603 or die "info directory does not exist and unable to create it: $!";
604 -d
$self->{path
}."/hooks" or mkdir $self->{path
}."/hooks"
605 or die "hooks directory does not exist and unable to create it: $!";
606 # clean out any kruft that may have come in from the initial template directory
607 if (opendir my $hooksdir, $self->{path
}."/hooks") {
608 unlink map "$self->{path}/$_", grep { $_ ne '.' && $_ ne '..' } readdir $hooksdir;
611 if ($Girocco::Config
::owning_group
) {
612 chown(-1, $gid, $self->{path
}."/hooks") or die "chgrp $gid $self->{path}/hooks failed: $!";
614 # hooks never world writable
615 chmod 02775, $self->{path
}."/hooks" or die "chmod 02775 $self->{path}/hooks failed: $!";
616 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'receive.denyNonFastforwards', 'false') == 0
617 or die "disabling receive.denyNonFastforwards failed: $?";
618 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'gc.auto', '0') == 0
619 or die "disabling gc.auto failed: $?";
620 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'receive.autogc', '0') == 0
621 or die "disabling receive.autogc failed: $?";
622 my ($S,$M,$H,$d,$m,$y) = gmtime(time());
623 $self->{creationtime
} = strftime
("%Y-%m-%dT%H:%M:%SZ", $S, $M, $H, $d, $m, $y, -1, -1, -1);
624 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'girocco.creationtime', $self->{creationtime
}) == 0
625 or die "setting girocco.creationtime failed: $?";
626 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'receive.updateserverinfo', 'true') == 0
627 or die "enabling receive.updateserverinfo failed: $?";
628 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'repack.writebitmaps', 'true') == 0
629 or die "enabling repack.writebitmaps failed: $?";
630 -d
$self->{path
}."/htmlcache" or mkdir $self->{path
}."/htmlcache"
631 or die "htmlcache directory does not exist and unable to create it: $!";
632 if (open $fd, '>', $self->{path
}."/info/lastactivity") {
634 chmod 0664, $self->{path
}."/info/lastactivity";
637 # /info must have right permissions,
638 # and git init didn't do it for some reason.
639 # config must have correct permissions.
640 # and Git 2.1.0 - 2.2.1 incorrectly add +x for some reason.
641 # also make sure /refs, /objects and /htmlcache are correct too.
642 my ($dmode, $dmodestr, $fmode, $fmodestr);
643 if ($Girocco::Config
::owning_group
) {
644 ($dmode, $dmodestr) = (02775, '02775');
645 ($fmode, $fmodestr) = (0664, '0664');
647 ($dmode, $dmodestr) = (02777, '02777');
648 ($fmode, $fmodestr) = (0666, '0666');
650 foreach my $dir (qw(info refs objects htmlcache)) {
651 chmod($dmode, $self->{path
}."/$dir") or die "chmod $dmodestr $self->{path}/$dir failed: $!";
653 foreach my $file (qw(config)) {
654 chmod($fmode, $self->{path
}."/$file") or die "chmod $fmodestr $self->{path}/$file failed: $!";
656 # these ones are probably not strictly required but are nice to have
657 foreach my $dir (qw(refs/heads refs/tags objects/info objects/pack)) {
658 -d
$self->{path
}."/$dir" or mkdir $self->{path
}."/$dir";
659 chmod($dmode, $self->{path
}."/$dir");
662 $self->_properties_save;
663 $self->_alternates_setup;
665 $self->_group_remove;
666 $self->_group_add($pushers);
667 $self->_hooks_install;
668 #$self->perm_initialize;
669 $self->_update_index;
677 $self->perm_initialize;
685 if ($Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob") {
686 system("$Girocco::Config::basedir/bin/create-personal-mob-area", $self->{name
}) == 0
687 or die "create-personal-mob-area $self->{name} failed";
689 $self->perm_initialize;
695 unlink ($self->_clonefail_path()); # Ignore EEXIST error
696 unlink ($self->_clonelog_path()); # Ignore EEXIST error
699 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or die "cannot connect to taskd.socket: $!";
700 $sock->print("clone ".$self->{name
}."\n");
701 # Just ignore reply, we are going to succeed anyway and the I/O
702 # would apparently get quite hairy.
711 $self->_properties_save;
712 $self->_group_update;
714 if (exists($self->{tags_to_delete
})) {
715 $self->delete_ctag($_) foreach(@
{$self->{tags_to_delete
}});
718 $self->set_HEAD($self->{HEAD
}) unless $self->{orig_HEAD
} eq $self->{HEAD
};
720 my @users_add = grep { $a = $_; not scalar grep { $a eq $_ } $self->{orig_users
} } $self->{users
};
721 my @users_del = grep { $a = $_; not scalar grep { $a eq $_ } $self->{users
} } $self->{orig_users
};
722 $self->perm_user_add($_, Girocco
::User
::resolve_uid
($_)) foreach (@users_add);
723 $self->perm_user_del($_, Girocco
::User
::resolve_uid
($_)) foreach (@users_del);
725 $self->_update_index if $self->{email
} ne $self->{orig_email
};
726 $self->{orig_email
} = $self->{email
};
731 sub update_password
{
735 $self->{crypt} = scrypt_sha1
($pwd);
736 $self->_group_update;
739 # You can explicitly do this just on a ghost() repository too.
743 if (-d
$self->{path
}) {
744 system('rm', '-rf', $self->{path
}) == 0
745 or die "rm -rf $self->{path} failed: $?";
747 # attempt to clean up any empty fork directories by removing them
748 my @pelems = split('/', $self->{name
});
749 while (@pelems > 1) {
752 rmdir join('/', $Girocco::Config
::reporoot
, @pelems) or last;
754 $self->_group_remove;
755 $self->_update_index;
758 sub _contains_files
{
760 (-d
$dir) or return 0;
761 opendir(my $dh, $dir) or die "opendir $dir failed: $!";
762 while (my $entry = readdir($dh)) {
763 next if $entry eq '' || $entry eq '.' || $entry eq '..';
764 closedir($dh), return 1
765 if -f
"$dir/$entry" ||
766 -d
"$dir/$entry" && _contains_files
("$dir/$entry");
775 return _contains_files
($Girocco::Config
::reporoot
.'/'.$self->{name
});
779 # A project is considered empty if the git repository does not
780 # have any refs. This means packed-refs does not exist or is
781 # empty or only has lines starting with '#' AND there are no
782 # files in the refs subdirectory hierarchy (no matter how deep).
786 (-d
$self->{path
}) or return 0;
787 if (-e
$self->{path
}.'/packed-refs') {
788 open(my $pr, '<', $self->{path
}.'/packed-refs')
789 or die "open $self->{path}./packed-refs failed: $!";
791 while (my $ref = <$pr>) {
792 next if $ref =~ /^#/;
797 return 0 if $foundref;
799 (-d
$self->{path
}.'/refs') or return 1;
800 return !_contains_files
($self->{path
}.'/refs');
807 # sanity check, disallow filenames starting with . .. or /
808 unlink($self->{path
}.'/ctags/'.$ctag) if($ctag !~ m
|^(\
.\
.?
)/|);
814 opendir(my $dh, $self->{path
}.'/ctags')
816 @ctags = grep { -f
"$self->{path}/ctags/$_" } readdir($dh);
824 my $heads = get_git
("--git-dir=$self->{path}", 'for-each-ref', '--format=%(objectname) %(refname)', 'refs/heads');
825 defined($heads) or $heads = '';
828 foreach (split(/\n/, $heads)) {
830 next if !m
#^[0-9a-f]{40}\s+refs/heads/(.+)$ #x;
838 my $HEAD = get_git
("--git-dir=$self->{path}", 'symbolic-ref', 'HEAD');
839 defined($HEAD) or $HEAD = '';
841 die "could not get HEAD" if ($HEAD !~ m{^refs/heads/(.+)$});
848 # Cursory checks only -- if you want to break your HEAD, be my guest
849 if ($newHEAD =~ /^\/|['<>]|\.\.|\/$/) {
850 die "grossly invalid new HEAD: $newHEAD";
852 system($Girocco::Config::git_bin, "--git-dir=$self->{path}", 'symbolic
-ref', 'HEAD
', "refs/heads/$newHEAD");
853 die "could not set HEAD" if ($? >> 8);
854 ! -d "$self->{path}/mob" || $Girocco::Config::mob ne 'mob
'
855 or system('cp
', '-p
', '-f
', "$self->{path}/HEAD", "$self->{path}/mob/HEAD") == 0;
861 $type = 'REPO
' unless $type && $type =~ /^[A-Z]+$/;
863 $self->{authtype} = $type;
866 $self->{auth} = sha1_hex(time . $$ . rand() . join(':',%$self));
868 my $expire = time + 24 * 3600;
869 my $propval = "# ${type}AUTH $self->{auth} $expire";
870 system($Girocco::Config::git_bin, '--git
-dir
='.$self->{path}, 'config
', 'gitweb
.repoauth
', $propval);
877 delete $self->{auth};
878 delete $self->{authtype};
879 system($Girocco::Config::git_bin, '--git
-dir
='.$self->{path}, 'config
', '--unset
', 'gitweb
.repoauth
');
886 my $before_count = @{$self->{users}};
887 $self->{users} = [grep { $_ ne $username } @{$self->{users}}];
888 return @{$self->{users}} != $before_count;
893 sub get_forkee_name {
895 (m#^(.*)/.*?$#)[0]; #
898 sub get_forkee_path {
899 no warnings; # avoid silly 'unsuccessful
stat on filename with
\n' warning
900 my $forkee = $Girocco::Config::reporoot.'/'.get_forkee_name($_[0]).'.git
';
901 -d $forkee ? $forkee : '';
904 # Ultimately the full project/fork name could end up being part of a Git ref name
905 # when a project's forks are combined into one giant repository
for efficiency
.
906 # That means that the project/fork name must satisfy the Git ref name requirements:
908 # 1. Characters with an ASCII value less than or equal to 32 are not allowed
909 # 2. The character with an ASCII value of 0x7F is not allowed
910 # 3. The characters '~', '^', ':', '\', '*', '?', and '[' are not allowed
911 # 4. The character '/' is a separator and is not allowed within a name
912 # 5. The name may not start with '.' or end with '.'
913 # 6. The name may not end with '.lock'
914 # 7. The name may not contain the '..' sequence
915 # 8. The name may not contain the '@{' sequence
916 # 9. If multiple components are used (separated by '/'), no empty '' components
918 # We also prohibit a trailing '.git' on any path component and futher restrict
919 # the allowed characters to alphanumeric and [+._-] where names must start with
922 sub _valid_name_characters
{
932 and (not m
#\.lock/#i)
933 and (not m
#\.lock$#i)
935 and m
#^[a-zA-Z0-9/+._-]+$#;
939 no warnings
; # avoid silly 'unsuccessful stat on filename with \n' warning
941 _valid_name_characters
($_) and not exists($reservedprojectnames{lc($_)})
942 and @
{[m
#/#g]} <= 5 # maximum fork depth is 5
943 and ((not m
#/#) or -d get_forkee_path($_)); # will also catch ^/
946 # It's possible that some forks have been kept but the forkee is gone.
947 # In this case the standard valid_name check is too strict.
949 no warnings
; # avoid silly 'unsuccessful stat on filename with \n' warning
950 my ($name, $nodie) = @_;
952 _valid_name_characters
($name)
953 and ((not $name =~ m
#/#)
954 or -d get_forkee_path
($name)
955 or -d
$Girocco::Config
::reporoot
.'/'.get_forkee_name
($name)));
956 (!$okay && $nodie) and return undef;
957 !$okay and die "tried to query for project with invalid name $name!";
958 (-d
$Girocco::Config
::reporoot
."/$name.git");
962 open my $fd, '<', jailed_file
("/etc/group") or die "getting project list failed: $!";
963 my @projects = map {/^([^:_\s#][^:\s#]*):[^:]*:\d{5,}:/ ?
$1 : ()} <$fd>;