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
61 # And dummy up a session object.
63 my $session=IkiWiki::cgi_getsession($cgi);
64 $session->param("name", getuser());
65 # Make sure whatever user was authed is in the
67 require IkiWiki::UserInfo;
68 if (! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
69 IkiWiki::userinfo_setall($session->param("name"), {
73 }) || error("failed adding user");
76 test_changes(cgi => $cgi,
78 changes => [IkiWiki::rcs_receive()]
85 my $cgi = $params{cgi};
86 my $session = $params{session};
87 my @changes = @{$params{changes}};
90 foreach my $change (@changes) {
91 # This untaint is safe because we check file_pruned and
93 my ($file)=$change->{file}=~/$config{wiki_file_regexp}/;
94 $file=IkiWiki::possibly_foolish_untaint($file);
95 if (! defined $file || ! length $file ||
96 IkiWiki::file_pruned($file)) {
97 error(gettext("bad file name %s"), $file);
100 my $type=pagetype($file);
101 my $page=pagename($file) if defined $type;
103 if ($change->{action} eq 'add') {
107 if ($change->{action} eq 'change' ||
108 $change->{action} eq 'add') {
110 IkiWiki::check_canedit($page, $cgi, $session);
114 if (IkiWiki::Plugin::attachment->can("check_canattach")) {
115 IkiWiki::Plugin::attachment::check_canattach($session, $file, $change->{path});
116 IkiWiki::check_canedit($file, $cgi, $session);
121 die "fall through test_changes add: " . Data::Dumper::Dumper($change);
125 elsif ($change->{action} eq 'remove') {
126 # check_canremove tests to see if the file is present
127 # on disk. This will fail when a single commit adds a
128 # file and then removes it again. Avoid the problem
129 # by not testing the removal in such pairs of changes.
130 # (The add is still tested, just to make sure that
131 # no data is added to the repo that a web edit
133 next if $newfiles{$file};
135 if (IkiWiki::Plugin::remove->can("check_canremove")) {
136 IkiWiki::Plugin::remove::check_canremove(defined $page ? $page : $file, $cgi, $session);
137 IkiWiki::check_canedit(defined $page ? $page : $file, $cgi, $session);
142 error "unknown action ".$change->{action};
145 error sprintf(gettext("you are not allowed to change %s"), $file);