3 package IkiWiki::Receive;
10 my $user=(getpwuid($<))[0];
11 if (! defined $user) {
12 error("cannot determine username for $<");
19 return ! ref $config{untrusted_committers} ||
20 ! grep { $_ eq $user } @{$config{untrusted_committers}};
25 IkiWiki::rcs_test_receive();
27 # Dummy up a cgi environment to use when calling check_canedit
33 my $session=IkiWiki::cgi_getsession($cgi);
35 $session->param("name", $user);
36 $ENV{REMOTE_ADDR}='unknown' unless exists $ENV{REMOTE_ADDR};
43 foreach my $change (IkiWiki::rcs_receive()) {
44 # This untaint is safe because we check file_pruned and
46 my $file=$change->{file}=~/$config{wiki_file_regexp}/;
47 $file=possibly_foolish_untaint($file);
48 if (! defined $file || ! length $file ||
49 IkiWiki::file_pruned($file, $config{srcdir})) {
50 error(gettext("bad file name"));
53 my $type=pagetype($file);
54 my $page=pagename($file) if defined $type;
56 if ($change->{action} eq 'add') {
60 if ($change->{action} eq 'change' ||
61 $change->{action} eq 'add') {
63 if (IkiWiki->can("check_canedit") &&
64 IkiWiki::check_canedit($page, $cgi, $session)) {
69 if (IkiWiki::Plugin::attachment->can("check_canattach") &&
70 IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path})) {
75 elsif ($change->{action} eq 'remove') {
76 # check_canremove tests to see if the file is present
77 # on disk. This will fail is a single commit adds a
78 # file and then removes it again. Avoid the problem
79 # by not testing the removal in such pairs of changes.
80 # (The add is still tested, just to make sure that
81 # no data is added to the repo that a web edit
83 next if $newfiles{$file};
85 if (IkiWiki::Plugin::remove->can("check_canremove") &&
86 IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session)) {
91 error "unknown action ".$change->{action};
94 error sprintf(gettext("you are not allowed to change %s"), $file);