3 package IkiWiki::Receive;
10 # CALLER_UID is set by the suid wrapper, to the original uid
11 my $user=(getpwuid(exists $ENV{CALLER_UID} ? $ENV{CALLER_UID} : $<))[0];
12 if (! defined $user) {
13 error("cannot determine username for $<");
20 return ! ref $config{untrusted_committers} ||
21 ! grep { $_ eq $user } @{$config{untrusted_committers}};
30 # Dummy up a cgi environment to use when calling check_canedit
35 $ENV{REMOTE_ADDR}='unknown' unless exists $ENV{REMOTE_ADDR};
37 # And dummy up a session object.
39 my $session=IkiWiki::cgi_getsession($cgi);
40 $session->param("name", getuser());
41 # Make sure whatever user was authed is in the
43 require IkiWiki::UserInfo;
44 if (! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
45 IkiWiki::userinfo_setall($session->param("name"), {
49 }) || error("failed adding user");
54 foreach my $change (IkiWiki::rcs_receive()) {
55 # This untaint is safe because we check file_pruned and
57 my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
58 $file=IkiWiki::possibly_foolish_untaint($file);
59 if (! defined $file || ! length $file ||
60 IkiWiki::file_pruned($file, $config{srcdir})) {
61 error(gettext("bad file name %s"), $file);
64 my $type=pagetype($file);
65 my $page=pagename($file) if defined $type;
67 if ($change->{action} eq 'add') {
71 if ($change->{action} eq 'change' ||
72 $change->{action} eq 'add') {
74 if (IkiWiki->can("check_canedit")) {
75 IkiWiki::check_canedit($page, $cgi, $session);
80 if (IkiWiki::Plugin::attachment->can("check_canattach")) {
81 IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path});
86 elsif ($change->{action} eq 'remove') {
87 # check_canremove tests to see if the file is present
88 # on disk. This will fail is a single commit adds a
89 # file and then removes it again. Avoid the problem
90 # by not testing the removal in such pairs of changes.
91 # (The add is still tested, just to make sure that
92 # no data is added to the repo that a web edit
94 next if $newfiles{$file};
96 if (IkiWiki::Plugin::remove->can("check_canremove")) {
97 IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session);
102 error "unknown action ".$change->{action};
105 error sprintf(gettext("you are not allowed to change %s"), $file);