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}};
26 # Dummy up a cgi environment to use when calling check_canedit
32 my $session=IkiWiki::cgi_getsession($cgi);
33 $session->param("name", getuser());
34 $ENV{REMOTE_ADDR}='unknown' unless exists $ENV{REMOTE_ADDR};
36 # Wiki is not locked because we lack permission to do so.
37 # So, relying on atomic index file updates to avoid trouble.
42 foreach my $change (IkiWiki::rcs_receive()) {
43 # This untaint is safe because we check file_pruned and
45 my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
46 $file=IkiWiki::possibly_foolish_untaint($file);
47 if (! defined $file || ! length $file ||
48 IkiWiki::file_pruned($file, $config{srcdir})) {
49 error(gettext("bad file name %s"), $file);
52 my $type=pagetype($file);
53 my $page=pagename($file) if defined $type;
55 if ($change->{action} eq 'add') {
59 if ($change->{action} eq 'change' ||
60 $change->{action} eq 'add') {
62 if (IkiWiki->can("check_canedit")) {
63 IkiWiki::check_canedit($page, $cgi, $session);
68 if (IkiWiki::Plugin::attachment->can("check_canattach")) {
69 IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path});
74 elsif ($change->{action} eq 'remove') {
75 # check_canremove tests to see if the file is present
76 # on disk. This will fail is a single commit adds a
77 # file and then removes it again. Avoid the problem
78 # by not testing the removal in such pairs of changes.
79 # (The add is still tested, just to make sure that
80 # no data is added to the repo that a web edit
82 next if $newfiles{$file};
84 if (IkiWiki::Plugin::remove->can("check_canremove")) {
85 IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session);
90 error "unknown action ".$change->{action};
93 error sprintf(gettext("you are not allowed to change %s"), $file);