Now:
#!/usr/bin/perl
print("Content-Type: text/html; charset=ascii\r\n\r\n");
print("a"); # works
# no error but not found in file system after the script finished
open(my $fh, ">", "/var/www/foo/out");
print($fh "foo");
close($fh);
print("b");
"foo" is writable by all:
# ls -l /var/www/
total 40
drwxr-xr-x 2 root daemon 512 Apr 1 2017 acme
drwxr-xr-x 2 root daemon 512 Apr 1 2017 bin
drwx-----T 2 www daemon 512 Apr 1 2017 cache
drwxr-xr-x 2 root daemon 512 Aug 9 17:56 cgi-bin
drwxr-xr-x 2 root daemon 512 Aug 28 2017 conf
drwxrwxrwx 2 root daemon 512 Aug 9 17:34 foo
drwxr-xr-x 4 root daemon 512 Apr 15 04:26 htdocs
drwxr-xr-x 2 root daemon 512 Jul 1 00:00 logs
drwxr-xr-x 2 root daemon 512 Aug 9 19:39 run
drwxr-xr-x 5 root daemon 512 Apr 15 11:17 usr
# chroot -u www /var/www/ cgi-bin/test.pl
Content-Type: text/html; charset=ascii
ab#
# ls -l /var/www/cgi-bin/test.pl
-rwxrwxrwx 1 755 www 244 Aug 9 19:32 /var/www/cgi-bin/test.pl
# slowcgi -d
slowcgi: socket: /var/www/run/slowcgi.sock
slowcgi: slowcgi_user: www
slowcgi: chroot: /var/www
slowcgi: inflight incremented, now 1
slowcgi: version: 1
slowcgi: type: 1
slowcgi: requestId: 1
slowcgi: contentLength: 8
slowcgi: paddingLength: 0
slowcgi: reserved: 0
slowcgi: role 1
slowcgi: flags 0
slowcgi: version: 1
slowcgi: type: 4
slowcgi: requestId: 1
slowcgi: contentLength: 808
slowcgi: paddingLength: 0
slowcgi: reserved: 0
slowcgi: env[0], PATH_INFO=
slowcgi: env[1], SCRIPT_NAME=/cgi-bin/test.pl
slowcgi: env[2], SCRIPT_FILENAME=//cgi-bin/test.pl
slowcgi: env[3], QUERY_STRING=
slowcgi: env[4], DOCUMENT_ROOT=/
slowcgi: env[5], DOCUMENT_URI=/cgi-bin/test.pl
slowcgi: env[6], GATEWAY_INTERFACE=CGI/1.1
slowcgi: env[7],
HTTP_ACCEPT=text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8
slowcgi: env[8], HTTP_ACCEPT_ENCODING=gzip, deflate
slowcgi: env[9], HTTP_ACCEPT_LANGUAGE=de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
slowcgi: env[10], HTTP_CACHE_CONTROL=max-age=0
slowcgi: env[11], HTTP_CONNECTION=keep-alive
slowcgi: env[12], HTTP_HOST=192.168.178.43
slowcgi: env[13], HTTP_UPGRADE_INSECURE_REQUESTS=1
slowcgi: env[14], HTTP_USER_AGENT=Mozilla/5.0 (Windows NT 10.0; Win64; x64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
slowcgi: env[15], REMOTE_ADDR=192.168.178.29
slowcgi: env[16], REMOTE_PORT=56472
slowcgi: env[17], REQUEST_METHOD=GET
slowcgi: env[18], REQUEST_URI=/cgi-bin/test.pl
slowcgi: env[19], SERVER_ADDR=192.168.178.43
slowcgi: env[20], SERVER_PORT=80
slowcgi: env[21], SERVER_NAME=127.0.0.1
slowcgi: env[22], SERVER_PROTOCOL=HTTP/1.1
slowcgi: env[23], SERVER_SOFTWARE=OpenBSD httpd
slowcgi: version: 1
slowcgi: type: 4
slowcgi: requestId: 1
slowcgi: contentLength: 0
slowcgi: paddingLength: 0
slowcgi: reserved: 0
slowcgi: fork: //cgi-bin/test.pl
slowcgi: version: 1
slowcgi: type: 5
slowcgi: requestId: 1
slowcgi: contentLength: 0
slowcgi: paddingLength: 0
slowcgi: reserved: 0
slowcgi: resp version: 1
slowcgi: resp type: 6
slowcgi: resp requestId: 1
slowcgi: resp contentLength: 44
slowcgi: resp paddingLength: 4
slowcgi: resp reserved: 0
slowcgi: wait: //cgi-bin/test.pl
slowcgi: resp version: 1
slowcgi: resp type: 6
slowcgi: resp requestId: 1
slowcgi: resp contentLength: 0
slowcgi: resp paddingLength: 0
slowcgi: resp reserved: 0
slowcgi: resp version: 1
slowcgi: resp type: 7
slowcgi: resp requestId: 1
slowcgi: resp contentLength: 0
slowcgi: resp paddingLength: 0
slowcgi: resp reserved: 0
slowcgi: resp version: 1
slowcgi: resp type: 3
slowcgi: resp requestId: 1
slowcgi: resp contentLength: 8
slowcgi: resp paddingLength: 0
slowcgi: resp reserved: 0
slowcgi: resp appStatus: 0
slowcgi: resp protocolStatus: 0
# httpd -d -vv
socket_rlimit: max open files 1024
startup
server_privinit: adding server 127.0.0.1
socket_rlimit: max open files 1024
socket_rlimit: max open files 1024
server_launch: configuring server 127.0.0.1
server_launch: running server 127.0.0.1
server_launch: configuring server 127.0.0.1
server_launch: running server 127.0.0.1
server_launch: configuring server 127.0.0.1
server_launch: running server 127.0.0.1
127.0.0.1 192.168.178.29 - - [09/Aug/2018:19:39:13 +0200] "GET /cgi-bin/test.pl
HTTP/1.1" 200 0
# cat /etc/httpd.conf
server "127.0.0.1" {
listen on * port 80
location "/cgi-bin/*" {
fastcgi
root "/"
}
}
# ls -l /var/www/usr/bin/
total 20
-rwxr-xr-x 1 root daemon 9296 Apr 15 11:19 perl
# ls -l /var/www/usr/lib/
total 15576
-r--r--r-- 1 root daemon 2862990 Apr 15 11:19 libc.so.89.3
-r--r--r-- 1 root daemon 463356 Apr 15 11:19 libm.so.10.0
-r--r--r-- 1 root daemon 4293077 Apr 15 11:20 libperl.so.18.0
-r--r--r-- 1 root daemon 146552 Apr 15 11:20 libpthread.so.23.0
-r--r--r-- 1 root daemon 125877 Apr 15 11:20 libutil.so.12.1
# ls -l /var/www/usr/libexec/
total 372
-r--r--r-- 1 root daemon 189764 Apr 15 11:21 ld.so
Still no error but no written file as well.
Am 11.08.2018 um 21:13 schrieb Hiltjo Posthuma:
> On Sat, Aug 11, 2018 at 07:58:02PM +0200, Toru Okada wrote:
>> Hi:
>>
>> I want to write a file out from within a perl cgi script. This is obviously
>> not possible in the standard configuration of httpd. The normal output works
>> perfectly. What is to do?
>>
>> #!/usr/bin/perl
>>
>> print("Content-Type: text/html; charset=ascii\n\n");
>
> Unrelated but the line-endings should be "\r\n" for these headers.
> https://www.w3.org/Protocols/rfc2616/rfc2616-sec2.html#sec2.2
>
>> print("hello world"); # works
>> # no error but not found in file system after the script finished
>> open(my $fh, ">", "out") or die $!;
>
> Maybe some permission/work directory issue? Try writing to an absolute path.
> slowcgi is chrooted by default, so maybe it tries to write to /var/www/out and
> it has no permissions for that?
>
> Running httpd -d -vv and slowcgi -d can help to debug too.
>
>> print($fh "foo");
>> close($fh);
>>
>> OpenBSD 6.1
>>
>> Many thanks in advance.
>>
>