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)
60 desc
=> 'description',
61 README
=> 'README.html',
63 notifymail
=> '%hooks.mailinglist',
64 notifytag
=> '%hooks.announcelist',
65 notifyjson
=> '%hooks.jsonurl',
66 notifycia
=> '%hooks.cianame',
70 lastchange
=> ':lastchange',
71 lastactivity
=> 'info/lastactivity',
74 # Projects with any of these names will be disallowed to avoid possible
75 # collisions with cgi script paths or chroot paths
76 our %reservedprojectnames = (
78 h
=> 1, # /h/ -> html.cgi
79 r
=> 1, # /r/ -> git http
80 w
=> 1, # /w/ -> gitweb
81 srv
=> 1, # /srv/git/ -> chroot ssh git repositories
85 system($Girocco::Config
::basedir
. '/gitweb/genindex.sh');
91 $self->{path
}.'/'.$name;
97 my $pname = $propmap{$name};
98 $pname = $propmapro{$name} unless $pname;
99 $pname or die "unknown property: $name";
100 if ($pname =~ s/^://) {
101 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.$pname"`;
104 } elsif ($pname =~ s/^%//) {
105 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "$pname"`;
110 open P
, '<', $self->_property_path($pname) or return undef;
113 my $value = join('', @value); chomp $value;
119 my ($name, $value) = @_;
120 my $pname = $propmap{$name};
121 $pname or die "unknown property: $name";
123 if ($pname =~ s/^://) {
124 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', "gitweb.$pname", $value);
126 } elsif ($pname =~ s/^%//) {
127 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', $pname, $value);
131 my $P = lock_file
($self->_property_path($pname));
132 $value ne '' and print $P "$value\n";
134 unlock_file
($self->_property_path($pname));
137 sub _properties_load
{
139 foreach my $prop (keys %propmap) {
140 $self->{$prop} = $self->_property_fget($prop);
142 foreach my $prop (keys %propmapro) {
143 $self->{$prop} = $self->_property_fget($prop);
145 my $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config --bool "gitweb.statusupdates" 2>/dev/null`;
147 $val = ($val eq 'false') ?
0 : 1;
148 $self->{statusupdates
} = $val;
149 delete $self->{auth
};
150 $val = `"$Girocco::Config::git_bin" --git-dir="$self->{path}" config "gitweb.repoauth"`;
152 if ($val =~ /^# ([A-Z]+)AUTH ([0-9a-f]+) (\d+)/) {
154 if (time < $expire) {
155 $self->{authtype
} = $1;
161 sub _properties_save
{
163 foreach my $prop (keys %propmap) {
164 $self->_property_fput($prop, $self->{$prop});
166 $self->{statusupdates
} = 1
167 unless defined($self->{statusupdates
}) && $self->{statusupdates
} =~ /^\d+$/;
168 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', '--bool',
169 "gitweb.statusupdates", $self->{statusupdates
});
174 $self->_property_path('.nofetch');
180 my $nf = $self->_nofetch_path;
182 open X
, '>', $nf or die "nofetch failed: $!";
185 unlink $nf or die "yesfetch failed: $!";
191 $self->_property_path('.clonelog');
194 sub _clonefail_path
{
196 $self->_property_path('.clone_failed');
201 $self->_property_path('.clone_in_progress');
207 my $np = $self->_clonep_path;
209 open X
, '>', $np or die "clonep failed: $!";
212 unlink $np or die "clonef failed: $!";
215 sub _alternates_setup
{
217 return unless $self->{name
} =~ m
#/#;
218 my $forkee_name = get_forkee_name
($self->{name
});
219 my $forkee_path = get_forkee_path
($self->{name
});
220 return unless -d
$forkee_path;
221 mkdir $self->{path
}.'/refs'; chmod 02775, $self->{path
}.'/refs';
222 mkdir $self->{path
}.'/objects'; chmod 02775, $self->{path
}.'/objects';
223 mkdir $self->{path
}.'/objects/info'; chmod 02775, $self->{path
}.'/objects/info';
225 # We set up both alternates and http_alternates since we cannot use
226 # relative path in alternates - that doesn't work recursively.
228 my $filename = $self->{path
}.'/objects/info/alternates';
229 open X
, '>', $filename or die "alternates failed: $!";
230 print X
"$forkee_path/objects\n";
232 chmod 0664, $filename or warn "cannot chmod $filename: $!";
234 if ($Girocco::Config
::httppullurl
) {
235 $filename = $self->{path
}.'/objects/info/http-alternates';
236 open X
, '>', $filename or die "http-alternates failed: $!";
237 my $upfork = $forkee_name;
238 do { print X
"$Girocco::Config::httppullurl/$upfork.git/objects\n"; } while ($upfork =~ s
#/?.+?$## and $upfork); #
240 chmod 0664, $filename or warn "cannot chmod $filename: $!";
243 # The symlink is problematic since git remote prune will traverse it.
244 #symlink "$forkee_path/refs", $self->{path}.'/refs/forkee';
246 # copy refs from parent project
247 # ownership information is changed by a root cronjob
248 system("cp -pR $forkee_path/refs $self->{path}/");
249 # initialize HEAD, hacky version
250 system("cp $forkee_path/HEAD $self->{path}/HEAD");
255 my $perms = $Girocco::Config
::permission_control
eq 'Hooks' ?
02777 : 02775;
256 mkdir $self->{path
}.'/ctags'; chmod $perms, $self->{path
}.'/ctags';
262 $xtra .= join(',', @
{$self->{users
}});
263 filedb_atomic_append
(jailed_file
('/etc/group'),
264 join(':', $self->{name
}, $self->{crypt}, '\i', $xtra));
269 my $xtra = join(',', @
{$self->{users
}});
270 filedb_atomic_edit
(jailed_file
('/etc/group'),
274 if ($self->{name
} eq (split /:/)[0]) {
275 # preserve readonly flag
276 s/::([^:]*)$/:$1/ and $xtra = ":$xtra";
277 return join(':', $self->{name
}, $self->{crypt}, $self->{gid
}, $xtra)."\n";
287 filedb_atomic_edit
(jailed_file
('/etc/group'),
289 $self->{name
} ne (split /:/)[0] and return $_;
297 $self->{path
}.'/hooks/'.$name;
303 open SRC
, '<', "$Girocco::Config::basedir/hooks/$name" or die "cannot open hook $name: $!";
304 open DST
, '>', $self->_hook_path($name) or die "cannot open hook $name for writing: $!";
305 while (<SRC
>) { print DST
$_; }
308 chmod 0775, $self->_hook_path($name) or die "cannot chmod hook $name: $!";
313 foreach my $hook ('pre-receive', 'post-receive', 'update', 'post-update') {
314 $self->_hook_install($hook);
318 # private constructor, do not use
321 my ($name, $base_path, $path) = @_;
322 does_exist
($name,1) || valid_name
($name) or die "refusing to create project with invalid name ($name)!";
323 $path ||= "$base_path/$name.git";
324 my $proj = { name
=> $name, base_path
=> $base_path, path
=> $path };
329 # public constructor #0
330 # creates a virtual project not connected to disk image
331 # you can conjure() it later to disk
334 my ($name, $mirror) = @_;
335 my $self = $class->_new($name, $Girocco::Config
::reporoot
);
337 $self->{mirror
} = $mirror;
338 $self->{email
} = $self->{orig_email
} = '';
342 # public constructor #1
345 my $name = shift || '';
347 open F
, '<', jailed_file
("/etc/group") or die "project load failed: $!";
351 next unless (shift eq $name);
353 my $self = $class->_new($name, $Girocco::Config
::reporoot
);
354 (-d
$self->{path
}) or die "invalid path (".$self->{path
}.") for project ".$self->{name
};
357 ($self->{crypt}, $self->{gid
}, $ulist) = @_;
359 $self->{users
} = [split /,/, $ulist];
360 $self->{HEAD
} = $self->get_HEAD;
361 $self->{orig_HEAD
} = $self->{HEAD
};
362 $self->{orig_users
} = [@
{$self->{users
}}];
363 $self->{mirror
} = ! -e
$self->_nofetch_path;
364 $self->{clone_in_progress
} = -e
$self->_clonep_path;
365 $self->{clone_logged
} = -e
$self->_clonelog_path;
366 $self->{clone_failed
} = -e
$self->_clonefail_path;
367 $self->{ccrypt
} = $self->{crypt};
369 $self->_properties_load;
370 $self->{orig_email
} = $self->{email
};
371 $self->{loaded
} = 1; # indicates self was loaded from etc/group file
378 # $proj may not be in sane state if this returns false!
382 my $cgi = $gcgi->cgi;
384 my ($pwd, $pwd2) = ($cgi->param('pwd'), $cgi->param('pwd2'));
385 # in case passwords are disabled
386 defined($pwd) or $pwd = ''; defined($pwd2) or $pwd = '';
387 if ($Girocco::Config
::project_passwords
and not $self->{crypt} and $pwd eq '' and $pwd2 eq '') {
388 $gcgi->err("Empty passwords are not permitted.");
390 if ($pwd ne '' or not $self->{crypt}) {
391 $self->{crypt} = scrypt_sha1
($pwd);
393 if (($pwd ne '' || $pwd2 ne '') and $pwd ne $pwd2) {
394 $gcgi->err("Our high-paid security consultants have determined that the admin passwords you have entered do not match each other.");
397 $self->{cpwd
} = $cgi->param('cpwd');
399 my ($forkee,$project) = ($self->{name
} =~ m
#^(.*/)?([^/]+)$#);
400 my $newtype = $forkee ?
'fork' : 'project';
401 length($project) <= 64
402 or $gcgi->err("The $newtype name is longer than 64 characters. Do you really need that much?");
404 if ($Girocco::Config
::project_owners
eq 'email') {
405 $self->{email
} = $gcgi->wparam('email');
406 valid_email
($self->{email
})
407 or $gcgi->err("Your email sure looks weird...?");
408 length($self->{email
}) <= 96
409 or $gcgi->err("Your email is longer than 96 characters. Do you really need that much?");
412 $self->{url
} = $gcgi->wparam('url');
414 valid_repo_url
($self->{url
})
415 or $gcgi->err("Invalid URL. Note that only HTTP and Git protocol is supported. If the URL contains funny characters, contact me.");
416 if ($Girocco::Config
::restrict_mirror_hosts
) {
417 my $mh = extract_url_hostname
($self->{url
});
419 or $gcgi->err("Invalid URL. Note that only DNS names are allowed, not IP addresses.");
420 !is_our_hostname
($mh)
421 or $gcgi->err("Invalid URL. Mirrors from this host are not allowed, please create a fork instead.");
425 $self->{desc
} = $gcgi->wparam('desc');
426 length($self->{desc
}) <= 1024
427 or $gcgi->err("<b>Short</b> description length > 1kb!");
429 $self->{README
} = $gcgi->wparam('README');
430 length($self->{README
}) <= 8192
431 or $gcgi->err("README length > 8kb!");
433 $self->{hp
} = $gcgi->wparam('hp');
435 valid_web_url
($self->{hp
})
436 or $gcgi->err("Invalid homepage URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
439 $self->{users
} = [grep { Girocco
::User
::valid_name
($_) && Girocco
::User
::does_exist
($_) } $cgi->param('user')];
441 $self->{HEAD
} = $cgi->param('HEAD') if $cgi->param('HEAD');
443 # schedule deletion of tags (will be committed by update() after auth)
444 $self->{tags_to_delete
} = [$cgi->param('tags')];
446 $self->{notifymail
} = $gcgi->wparam('notifymail');
447 if ($self->{notifymail
}) {
448 (valid_email_multi
($self->{notifymail
}) and length($self->{notifymail
}) <= 512)
449 or $gcgi->err("Invalid notify e-mail address. Use mail,mail to specify multiple addresses; total length must not exceed 512 characters, however.");
452 $self->{notifyjson
} = $gcgi->wparam('notifyjson');
453 if ($self->{notifyjson
}) {
454 valid_web_url
($self->{notifyjson
})
455 or $gcgi->err("Invalid JSON notify URL. Note that only HTTP protocol is supported. If the URL contains funny characters, contact me.");
458 $self->{notifycia
} = $gcgi->wparam('notifycia');
459 if ($self->{notifycia
}) {
460 $self->{notifycia
} =~ /^[a-zA-Z0-9._-]+$/
461 or $gcgi->err("Overly suspicious CIA notify project name. If it is actually valid, contact me.");
464 if ($cgi->param('setstatusupdates')) {
465 my $val = $gcgi->wparam('statusupdates') || '0';
466 $self->{statusupdates
} = $val ?
1 : 0;
469 not $gcgi->err_check;
475 name
=> $self->{name
},
476 email
=> $self->{email
},
478 desc
=> html_esc
($self->{desc
}),
479 README
=> html_esc
($self->{README
}),
481 users
=> $self->{users
},
482 notifymail
=> html_esc
($self->{notifymail
}),
483 notifyjson
=> html_esc
($self->{notifyjson
}),
484 notifycia
=> html_esc
($self->{notifycia
}),
488 # return true if $enc_passwd is a match for $plain_passwd
489 my $_check_passwd_match = sub {
490 my $enc_passwd = shift;
491 my $plain_passwd = shift;
492 defined($enc_passwd) or $enc_passwd = '';
493 defined($plain_passwd) or $plain_passwd = '';
494 # $enc_passwd may be crypt or crypt_sha1
495 if ($enc_passwd =~ m
(^\
$sha1\
$(\d
+)\
$([./0-9A-Za-z]{1,64})\$[./0-9A
-Za
-z
]{28}$)) {
496 # It's using sha1-crypt
497 return $enc_passwd eq crypt_sha1
($plain_passwd, $2, -(0+$1));
500 return $enc_passwd eq crypt($plain_passwd, $enc_passwd);
508 $self->{ccrypt
} or die "Can't authenticate against a project with no password";
509 defined($self->{cpwd
}) or $self->{cpwd
} = '';
510 unless ($_check_passwd_match->($self->{ccrypt
}, $self->{cpwd
})) {
511 $gcgi->err("Your admin password does not match!");
517 # return true if the password from the file is empty or consists of all the same
518 # character. However, if the project was NOT loaded from the group file
519 # (!self->{loaded}) then the password is never locked.
520 # This function does NOT check $Girocco::Config::project_passwords, the caller
521 # is responsible for doing so if desired. Same for $self->{email}.
522 sub is_password_locked
{
525 $self->{loaded
} or return 0;
526 my $testcrypt = $self->{ccrypt
}; # The value from the group file
527 defined($testcrypt) or $testcrypt = '';
528 $testcrypt ne '' or return 1; # No password at all
529 $testcrypt =~ /^(.)\1*$/ and return 1; # Bogus crypt value
530 return 0; # Not locked
537 $self->_mkdir_forkees;
539 mkdir($self->{path
}) or die "mkdir $self->{path} failed: $!";
540 if ($Girocco::Config
::owning_group
) {
541 my $gid = scalar(getgrnam($Girocco::Config
::owning_group
));
542 chown(-1, $gid, $self->{path
}) or die "chgrp $gid $self->{path} failed: $!";
543 chmod(02775, $self->{path
}) or die "chmod 02775 $self->{path} failed: $!";
545 chmod(02777, $self->{path
}) or die "chmod 02777 $self->{path} failed: $!";
547 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'init', '--bare', '--shared='.$self->shared_mode()) == 0
548 or die "git init $self->{path} failed: $?";
549 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'receive.denyNonFastforwards', 'false') == 0
550 or die "disabling receive.denyNonFastforwards failed: $?";
551 system($Girocco::Config
::git_bin
, '--git-dir='.$self->{path
}, 'config', 'gc.auto', '0') == 0
552 or die "disabling gc.auto failed: $?";
554 # /info must have right permissions,
555 # and git init didn't do it for some reason.
556 if ($Girocco::Config
::owning_group
) {
557 chmod(02775, $self->{path
}."/info") or die "chmod 02775 $self->{path}/info failed: $!";
559 chmod(02777, $self->{path
}."/info") or die "chmod 02777 $self->{path}/info failed: $!";
562 $self->_properties_save;
563 $self->_alternates_setup;
565 $self->_group_remove;
566 $self->_group_add($pushers);
567 $self->_hooks_install;
568 #$self->perm_initialize;
569 $self->_update_index;
577 $self->perm_initialize;
585 if ($Girocco::Config
::mob
&& $Girocco::Config
::mob
eq "mob") {
586 system("$Girocco::Config::basedir/bin/create-personal-mob-area", $self->{name
}) == 0
587 or die "create-personal-mob-area $self->{name} failed";
589 $self->perm_initialize;
595 unlink ($self->_clonefail_path()); # Ignore EEXIST error
596 unlink ($self->_clonelog_path()); # Ignore EEXIST error
599 my $sock = IO
::Socket
::UNIX
->new($Girocco::Config
::chroot.'/etc/taskd.socket') or die "cannot connect to taskd.socket: $!";
600 $sock->print("clone ".$self->{name
}."\n");
601 # Just ignore reply, we are going to succeed anyway and the I/O
602 # would apparently get quite hairy.
611 $self->_properties_save;
612 $self->_group_update;
614 if (exists($self->{tags_to_delete
})) {
615 $self->delete_ctag($_) foreach(@
{$self->{tags_to_delete
}});
618 $self->set_HEAD($self->{HEAD
}) unless $self->{orig_HEAD
} eq $self->{HEAD
};
620 my @users_add = grep { $a = $_; not scalar grep { $a eq $_ } $self->{orig_users
} } $self->{users
};
621 my @users_del = grep { $a = $_; not scalar grep { $a eq $_ } $self->{users
} } $self->{orig_users
};
622 $self->perm_user_add($_, Girocco
::User
::resolve_uid
($_)) foreach (@users_add);
623 $self->perm_user_del($_, Girocco
::User
::resolve_uid
($_)) foreach (@users_del);
625 $self->_update_index if $self->{email
} ne $self->{orig_email
};
626 $self->{orig_email
} = $self->{email
};
631 sub update_password
{
635 $self->{crypt} = scrypt_sha1
($pwd);
636 $self->_group_update;
639 # You can explicitly do this just on a ghost() repository too.
643 if (-d
$self->{path
}) {
644 system('rm', '-rf', $self->{path
}) == 0
645 or die "rm -rf $self->{path} failed: $?";
647 # attempt to clean up any empty fork directories by removing them
648 my @pelems = split('/', $self->{name
});
649 while (@pelems > 1) {
652 rmdir join('/', $Girocco::Config
::reporoot
, @pelems) or last;
654 $self->_group_remove;
655 $self->_update_index;
658 sub _contains_files
{
660 (-d
$dir) or return 0;
661 opendir(my $dh, $dir) or die "opendir $dir failed: $!";
662 while (my $entry = readdir($dh)) {
663 next if $entry eq '' || $entry eq '.' || $entry eq '..';
664 closedir($dh), return 1
665 if -f
"$dir/$entry" ||
666 -d
"$dir/$entry" && _contains_files
("$dir/$entry");
675 return _contains_files
($Girocco::Config
::reporoot
.'/'.$self->{name
});
679 # A project is considered empty if the git repository does not
680 # have any refs. This means packed-refs does not exist or is
681 # empty or only has lines starting with '#' AND there are no
682 # files in the refs subdirectory hierarchy (no matter how deep).
686 (-d
$self->{path
}) or return 0;
687 if (-e
$self->{path
}.'/packed-refs') {
688 open(my $pr, '<', $self->{path
}.'/packed-refs')
689 or die "open $self->{path}./packed-refs failed: $!";
691 while (my $ref = <$pr>) {
692 next if $ref =~ /^#/;
697 return 0 if $foundref;
699 (-d
$self->{path
}.'/refs') or return 1;
700 return !_contains_files
($self->{path
}.'/refs');
707 # sanity check, disallow filenames starting with . .. or /
708 unlink($self->{path
}.'/ctags/'.$ctag) if($ctag !~ m
|^(\
.\
.?
)/|);
714 opendir(my $dh, $self->{path
}.'/ctags')
716 @ctags = grep { -f
"$self->{path}/ctags/$_" } readdir($dh);
724 open($fh, '-|', "$Girocco::Config::git_bin --git-dir=$self->{path} show-ref --heads") or die "could not get list of heads";
728 next if !m
#^[0-9a-f]{40}\s+refs/heads/(.+)$ #x;
737 my $HEAD = `$Girocco::Config::git_bin --git-dir=$self->{path} symbolic-ref HEAD`;
739 die "could not get HEAD" if ($HEAD !~ m{^refs/heads/(.+)$});
746 # Cursory checks only -- if you want to break your HEAD, be my guest
747 if ($newHEAD =~ /^\/|['<>]|\.\.|\/$/) {
748 die "grossly invalid new HEAD: $newHEAD";
750 system($Girocco::Config::git_bin, "--git-dir=$self->{path}", 'symbolic
-ref', 'HEAD
', "refs/heads/$newHEAD");
751 die "could not set HEAD" if ($? >> 8);
752 ! -d "$self->{path}/mob" || $Girocco::Config::mob ne 'mob
'
753 or system('cp
', '-p
', '-f
', "$self->{path}/HEAD", "$self->{path}/mob/HEAD") == 0;
759 $type = 'REPO
' unless $type && $type =~ /^[A-Z]+$/;
761 $self->{authtype} = $type;
764 $self->{auth} = sha1_hex(time . $$ . rand() . join(':',%$self));
766 my $expire = time + 24 * 3600;
767 my $propval = "# ${type}AUTH $self->{auth} $expire";
768 system($Girocco::Config::git_bin, '--git
-dir
='.$self->{path}, 'config
', 'gitweb
.repoauth
', $propval);
775 delete $self->{auth};
776 delete $self->{authtype};
777 system($Girocco::Config::git_bin, '--git
-dir
='.$self->{path}, 'config
', '--unset
', 'gitweb
.repoauth
');
784 my $before_count = @{$self->{users}};
785 $self->{users} = [grep { $_ ne $username } @{$self->{users}}];
786 return @{$self->{users}} != $before_count;
791 sub get_forkee_name {
793 (m#^(.*)/.*?$#)[0]; #
796 sub get_forkee_path {
797 no warnings; # avoid silly 'unsuccessful
stat on filename with
\n' warning
798 my $forkee = $Girocco::Config::reporoot.'/'.get_forkee_name($_[0]).'.git
';
799 -d $forkee ? $forkee : '';
802 # Ultimately the full project/fork name could end up being part of a Git ref name
803 # when a project's forks are combined into one giant repository
for efficiency
.
804 # That means that the project/fork name must satisfy the Git ref name requirements:
806 # 1. Characters with an ASCII value less than or equal to 32 are not allowed
807 # 2. The character with an ASCII value of 0x7F is not allowed
808 # 3. The characters '~', '^', ':', '\', '*', '?', and '[' are not allowed
809 # 4. The character '/' is a separator and is not allowed within a name
810 # 5. The name may not start with '.' or end with '.'
811 # 6. The name may not end with '.lock'
812 # 7. The name may not contain the '..' sequence
813 # 8. The name may not contain the '@{' sequence
814 # 9. If multiple components are used (separated by '/'), no empty '' components
816 # We also prohibit a trailing '.git' on any path component and futher restrict
817 # the allowed characters to alphanumeric and [+._-] where names must start with
820 # The rules are relaxed slightly for existing projects (for now) to accomodate them.
822 sub _valid_name_characters
{
828 and (not m
#/[+._-]# or $relaxed)
830 and (not m
#\.$# or $relaxed)
833 and (not m
#\.lock/#i)
834 and (not m
#\.lock$#i)
836 and m
#^[a-zA-Z0-9/+._-]+$#;
840 no warnings
; # avoid silly 'unsuccessful stat on filename with \n' warning
842 _valid_name_characters
($_) and not exists($reservedprojectnames{$_})
843 and @
{[m
#/#g]} <= 5 # maximum fork depth is 5
844 and ((not m
#/#) or -d get_forkee_path($_)); # will also catch ^/
847 # It's possible that some forks have been kept but the forkee is gone.
848 # In this case the standard valid_name check is too strict.
850 no warnings
; # avoid silly 'unsuccessful stat on filename with \n' warning
851 my ($name, $nodie) = @_;
853 _valid_name_characters
($name, 1)
854 and ((not $name =~ m
#/#)
855 or -d get_forkee_path
($name)
856 or -d
$Girocco::Config
::reporoot
.'/'.get_forkee_name
($name)));
857 (!$okay && $nodie) and return undef;
858 !$okay and die "tried to query for project with invalid name $name!";
859 (-d
$Girocco::Config
::reporoot
."/$name.git");
866 open F
, '<', jailed_file
("/etc/group") or die "getting project list failed: $!";
870 next if ($_[2] < 65536);
872 push @projects, $_[0];