summaryrefslogtreecommitdiff
path: root/IkiWiki/Receive.pm
blob: 225f2b9abf33ab995f94576a8a735db9c67fb80b (plain)
  1. #!/usr/bin/perl
  2. package IkiWiki::Receive;
  3. use warnings;
  4. use strict;
  5. use IkiWiki;
  6. sub getuser () {
  7. my $user=(getpwuid(exists $ENV{CALLER_UID} ? $ENV{CALLER_UID} : $<))[0];
  8. if (! defined $user) {
  9. error("cannot determine username for $<");
  10. }
  11. return $user;
  12. }
  13. sub trusted () {
  14. my $user=getuser();
  15. return ! ref $config{untrusted_committers} ||
  16. ! grep { $_ eq $user } @{$config{untrusted_committers}};
  17. }
  18. sub genwrapper () {
  19. # Test for commits from untrusted committers in the wrapper, to
  20. # avoid starting ikiwiki proper at all for trusted commits.
  21. my $ret=<<"EOF";
  22. {
  23. int u=getuid();
  24. EOF
  25. $ret.="\t\tif ( ".
  26. join("&&", map {
  27. my $uid=getpwnam($_);
  28. if (! defined $uid) {
  29. error(sprintf(gettext("cannot determine id of untrusted committer %s"), $_));
  30. }
  31. "u != $uid";
  32. } @{$config{untrusted_committers}}).
  33. ") exit(0);\n";
  34. $ret.=<<"EOF";
  35. asprintf(&s, "CALLER_UID=%i", u);
  36. newenviron[i++]=s;
  37. }
  38. EOF
  39. return $ret;
  40. }
  41. sub test () {
  42. exit 0 if trusted();
  43. IkiWiki::lockwiki();
  44. IkiWiki::loadindex();
  45. # Dummy up a cgi environment to use when calling check_canedit
  46. # and friends.
  47. eval q{use CGI};
  48. error($@) if $@;
  49. my $cgi=CGI->new;
  50. # And dummy up a session object.
  51. require IkiWiki::CGI;
  52. my $session=IkiWiki::cgi_getsession($cgi);
  53. $session->param("name", getuser());
  54. # Make sure whatever user was authed is in the
  55. # userinfo db.
  56. require IkiWiki::UserInfo;
  57. if (! IkiWiki::userinfo_get($session->param("name"), "regdate")) {
  58. IkiWiki::userinfo_setall($session->param("name"), {
  59. email => "",
  60. password => "",
  61. regdate => time,
  62. }) || error("failed adding user");
  63. }
  64. check_canchange(
  65. cgi => $cgi,
  66. session => $session,
  67. changes => [IkiWiki::rcs_receive()]
  68. );
  69. exit 0;
  70. }
  71. 1