aboutsummaryrefslogtreecommitdiff
path: root/IkiWiki/Wrapper.pm
diff options
context:
space:
mode:
authorjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-23 06:51:15 +0000
committerjoey <joey@0fa5a96a-9a0e-0410-b3b2-a0fd24251071>2006-03-23 06:51:15 +0000
commit6c8cf5dd571662f981227489f7c4652a1a1f10cd (patch)
tree778453ccf0d85720f37579f6e3c95624fdb5f960 /IkiWiki/Wrapper.pm
parent7b0346bf8234100f608aa7f24684becc952e8956 (diff)
downloadikiwiki-6c8cf5dd571662f981227489f7c4652a1a1f10cd.tar
ikiwiki-6c8cf5dd571662f981227489f7c4652a1a1f10cd.tar.gz
Major code reoganisation, splitting up the single big file. The two goals
kept in mind during this are a) to reduce load time for common cases like cgi and post-commit and b) make the code easier to navigate. This also modularises RCS support to the extent that it should be possible to drop in a module for some RCS other than svn, add a switch for it, and it pretty much just work. High chance I missed an edge case that breaks something, this is only barely tested at this point.
Diffstat (limited to 'IkiWiki/Wrapper.pm')
-rw-r--r--IkiWiki/Wrapper.pm96
1 files changed, 96 insertions, 0 deletions
diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm
new file mode 100644
index 000000000..8e513c1f6
--- /dev/null
+++ b/IkiWiki/Wrapper.pm
@@ -0,0 +1,96 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+package IkiWiki;
+
+sub gen_wrapper () { #{{{
+ eval q{use Cwd 'abs_path'};
+ $config{srcdir}=abs_path($config{srcdir});
+ $config{destdir}=abs_path($config{destdir});
+ my $this=abs_path($0);
+ if (! -x $this) {
+ error("$this doesn't seem to be executable");
+ }
+
+ if ($config{setup}) {
+ error("cannot create a wrapper that uses a setup file");
+ }
+
+ my @params=($config{srcdir}, $config{destdir},
+ "--wikiname=$config{wikiname}",
+ "--templatedir=$config{templatedir}");
+ push @params, "--verbose" if $config{verbose};
+ push @params, "--rebuild" if $config{rebuild};
+ push @params, "--nosvn" if !$config{svn};
+ push @params, "--cgi" if $config{cgi};
+ push @params, "--url=$config{url}" if length $config{url};
+ push @params, "--cgiurl=$config{cgiurl}" if length $config{cgiurl};
+ push @params, "--historyurl=$config{historyurl}" if length $config{historyurl};
+ push @params, "--diffurl=$config{diffurl}" if length $config{diffurl};
+ push @params, "--anonok" if $config{anonok};
+ push @params, "--adminuser=$_" foreach @{$config{adminuser}};
+ my $params=join(" ", @params);
+ my $call='';
+ foreach my $p ($this, $this, @params) {
+ $call.=qq{"$p", };
+ }
+ $call.="NULL";
+
+ my @envsave;
+ push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
+ CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
+ HTTP_COOKIE} if $config{cgi};
+ my $envsave="";
+ foreach my $var (@envsave) {
+ $envsave.=<<"EOF"
+ if ((s=getenv("$var")))
+ asprintf(&newenviron[i++], "%s=%s", "$var", s);
+EOF
+ }
+
+ open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");;
+ print OUT <<"EOF";
+/* A wrapper for ikiwiki, can be safely made suid. */
+#define _GNU_SOURCE
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+
+extern char **environ;
+
+int main (int argc, char **argv) {
+ /* Sanitize environment. */
+ char *s;
+ char *newenviron[$#envsave+3];
+ int i=0;
+$envsave
+ newenviron[i++]="HOME=$ENV{HOME}";
+ newenviron[i]=NULL;
+ environ=newenviron;
+
+ if (argc == 2 && strcmp(argv[1], "--params") == 0) {
+ printf("$params\\n");
+ exit(0);
+ }
+
+ execl($call);
+ perror("failed to run $this");
+ exit(1);
+}
+EOF
+ close OUT;
+ if (system("gcc", "ikiwiki-wrap.c", "-o", possibly_foolish_untaint($config{wrapper})) != 0) {
+ error("failed to compile ikiwiki-wrap.c");
+ }
+ unlink("ikiwiki-wrap.c");
+ if (defined $config{wrappermode} &&
+ ! chmod(oct($config{wrappermode}), possibly_foolish_untaint($config{wrapper}))) {
+ error("chmod $config{wrapper}: $!");
+ }
+ print "successfully generated $config{wrapper}\n";
+} #}}}
+
+1