10 sub gen_wrapper () { #{{{
11 $config{srcdir}=abs_path($config{srcdir});
12 $config{destdir}=abs_path($config{destdir});
13 my $this=abs_path($0);
15 error("$this doesn't seem to be executable");
19 error("cannot create a wrapper that uses a setup file");
21 my $wrapper=possibly_foolish_untaint($config{wrapper});
22 delete $config{wrapper};
25 push @envsave, qw{REMOTE_ADDR QUERY_STRING REQUEST_METHOD REQUEST_URI
26 CONTENT_TYPE CONTENT_LENGTH GATEWAY_INTERFACE
27 HTTP_COOKIE} if $config{cgi};
29 foreach my $var (@envsave) {
31 if ((s=getenv("$var")))
32 asprintf(&newenviron[i++], "%s=%s", "$var", s);
36 $Data::Dumper::Indent=0; # no newlines
37 my $configstring=Data::Dumper->Dump([\%config], ['*config']);
38 $configstring=~s/\\/\\\\/g;
39 $configstring=~s/"/\\"/g;
41 open(OUT, ">$wrapper.c") || error("failed to write $wrapper.c: $!");;
43 /* A wrapper for ikiwiki, can be safely made suid. */
50 extern char **environ;
52 int main (int argc, char **argv) {
53 /* Sanitize environment. */
55 char *newenviron[$#envsave+4];
58 newenviron[i++]="HOME=$ENV{HOME}";
59 newenviron[i++]="WRAPPED_OPTIONS=$configstring";
63 execl("$this", "$this", NULL);
64 perror("failed to run $this");
69 if (system("gcc", "$wrapper.c", "-o", $wrapper) != 0) {
70 error("failed to compile $wrapper.c");
73 if (defined $config{wrappermode} &&
74 ! chmod(oct($config{wrappermode}), $wrapper)) {
75 error("chmod $wrapper: $!");
77 print "successfully generated $wrapper\n";