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};
41 foreach my $change (IkiWiki::rcs_receive()) {
42 # This untaint is safe because we check file_pruned and
44 my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
45 $file=IkiWiki::possibly_foolish_untaint($file);
46 if (! defined $file || ! length $file ||
47 IkiWiki::file_pruned($file, $config{srcdir})) {
48 error(gettext("bad file name %s"), $file);
51 my $type=pagetype($file);
52 my $page=pagename($file) if defined $type;
54 if ($change->{action} eq 'add') {
58 if ($change->{action} eq 'change' ||
59 $change->{action} eq 'add') {
61 if (IkiWiki->can("check_canedit")) {
62 IkiWiki::check_canedit($page, $cgi, $session);
67 if (IkiWiki::Plugin::attachment->can("check_canattach")) {
68 IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path});
73 elsif ($change->{action} eq 'remove') {
74 # check_canremove tests to see if the file is present
75 # on disk. This will fail is a single commit adds a
76 # file and then removes it again. Avoid the problem
77 # by not testing the removal in such pairs of changes.
78 # (The add is still tested, just to make sure that
79 # no data is added to the repo that a web edit
81 next if $newfiles{$file};
83 if (IkiWiki::Plugin::remove->can("check_canremove")) {
84 IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session);
89 error "unknown action ".$change->{action};
92 error sprintf(gettext("you are not allowed to change %s"), $file);