diff options
Diffstat (limited to 'IkiWiki/Wrapper.pm')
-rw-r--r-- | IkiWiki/Wrapper.pm | 48 |
1 files changed, 16 insertions, 32 deletions
diff --git a/IkiWiki/Wrapper.pm b/IkiWiki/Wrapper.pm index 8e513c1f6..62d284eb6 100644 --- a/IkiWiki/Wrapper.pm +++ b/IkiWiki/Wrapper.pm @@ -2,11 +2,12 @@ use warnings; use strict; +use Cwd q{abs_path}; +use Data::Dumper; 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); @@ -17,26 +18,8 @@ sub gen_wrapper () { #{{{ 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 $wrapper=possibly_foolish_untaint($config{wrapper}); + delete $config{wrapper}; my @envsave; push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI @@ -50,6 +33,11 @@ sub gen_wrapper () { #{{{ EOF } + $Data::Dumper::Indent=0; + my $configstring=Data::Dumper->Dump([\%config], ['*config']); + $configstring=~s/\\/\\\\/g; + $configstring=~s/"/\\"/g; + open(OUT, ">ikiwiki-wrap.c") || error("failed to write ikiwiki-wrap.c: $!");; print OUT <<"EOF"; /* A wrapper for ikiwiki, can be safely made suid. */ @@ -64,33 +52,29 @@ extern char **environ; int main (int argc, char **argv) { /* Sanitize environment. */ char *s; - char *newenviron[$#envsave+3]; + char *newenviron[$#envsave+4]; int i=0; $envsave newenviron[i++]="HOME=$ENV{HOME}"; + newenviron[i++]="WRAPPED_OPTIONS=$configstring"; newenviron[i]=NULL; environ=newenviron; - if (argc == 2 && strcmp(argv[1], "--params") == 0) { - printf("$params\\n"); - exit(0); - } - - execl($call); + execl("$this", "$this", NULL); perror("failed to run $this"); exit(1); } EOF close OUT; - if (system("gcc", "ikiwiki-wrap.c", "-o", possibly_foolish_untaint($config{wrapper})) != 0) { + if (system("gcc", "ikiwiki-wrap.c", "-o", $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}: $!"); + ! chmod(oct($config{wrappermode}), $wrapper)) { + error("chmod $wrapper: $!"); } - print "successfully generated $config{wrapper}\n"; + print "successfully generated $wrapper\n"; } #}}} 1 |