2 package IkiWiki::Receive;
9 my $user=(getpwuid(exists $ENV{CALLER_UID} ? $ENV{CALLER_UID} : $<))[0];
10 if (! defined $user) {
11 error("cannot determine username for $<");
18 return ! ref $config{untrusted_committers} ||
19 ! grep { $_ eq $user } @{$config{untrusted_committers}};
23 # Test for commits from untrusted committers in the wrapper, to
24 # avoid starting ikiwiki proper at all for trusted commits.
34 error(sprintf(gettext("cannot determine id of untrusted committer %s"), $_));
37 } @{$config{untrusted_committers}}).
42 asprintf(&s, "CALLER_UID=%i", u);
55 # Dummy up a cgi environment to use when calling check_canedit
60 $ENV{REMOTE_ADDR}='unknown' unless exists $ENV{REMOTE_ADDR};
62 # And dummy up a session object.
64 my $session=IkiWiki::cgi_getsession($cgi);
65 $session->param("name", getuser());
66 # Make sure whatever user was authed is in the
68 require IkiWiki::UserInfo;
69 if (! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
70 IkiWiki::userinfo_setall($session->param("name"), {
74 }) || error("failed adding user");
79 foreach my $change (IkiWiki::rcs_receive()) {
80 # This untaint is safe because we check file_pruned and
82 my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
83 $file=IkiWiki::possibly_foolish_untaint($file);
84 if (! defined $file || ! length $file ||
85 IkiWiki::file_pruned($file, $config{srcdir})) {
86 error(gettext("bad file name %s"), $file);
89 my $type=pagetype($file);
90 my $page=pagename($file) if defined $type;
92 if ($change->{action} eq 'add') {
96 if ($change->{action} eq 'change' ||
97 $change->{action} eq 'add') {
99 if (IkiWiki->can("check_canedit")) {
100 IkiWiki::check_canedit($page, $cgi, $session);
105 if (IkiWiki::Plugin::attachment->can("check_canattach")) {
106 IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path});
111 elsif ($change->{action} eq 'remove') {
112 # check_canremove tests to see if the file is present
113 # on disk. This will fail is a single commit adds a
114 # file and then removes it again. Avoid the problem
115 # by not testing the removal in such pairs of changes.
116 # (The add is still tested, just to make sure that
117 # no data is added to the repo that a web edit
119 next if $newfiles{$file};
121 if (IkiWiki::Plugin::remove->can("check_canremove")) {
122 IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session);
127 error "unknown action ".$change->{action};
130 error sprintf(gettext("you are not allowed to change %s"), $file);