problem solved (was: Re: fnord returns empty page when asked for CGI)

Joost van Baal <[email protected]> Thu, 3 Jan 2008 12:13:26 +0100
Newsgroups gmane.comp.web.fnord
Message-ID <[email protected]>
--udzYTtuEmHLUHegf
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Hi,

Op Mon 31 Dec 2007 om 03:50:58 +0100 schreef [email protected]:
> Am Sonntag, 30. Dezember 2007 12:54 schrieb Joost van Baal:
> >  root@stegun:~# cat /var/www/doc.mdcc.cx/cgi-bin/foo.cgi
> >  #!/bin/sh
> >
> >  echo Content-type: text/plain
> >  echo
> >  echo foobar
> >
> > /var/www/doc.mdcc.cx:80 is a symlink to /var/www/doc.mdcc.cx
>=20
> have you compiled fnord with chroot? In that case you should use
> relative symlinks. Also, make sure /bin/sh plus required libs
> are in your chroot environment.

Indeed my fnord was running chroot-ed.

My fnord-problems are solved (for now :).  For the benefit of other
people struggling with this cgi-and-chroot stuff; I'll summarize my
solution.

I've used this really very quick and dirty trick to be sure about that:

While this:

 root@stegun:/proc# while sleep 1; do date; \
  ls -ld */task | grep www-data | while read d d d d d d d p; \
  do pid=3D$(echo $p | sed 's+/..*$++'); ls -ld $pid/root; done; done

is running, perform:

joostvb@stegun:~% { echo GET /cgi-bin/foo.cgi HTTP/1.0; \
 echo Host: doc.mdcc.cx; sleep 4; echo } | nc localhost 80; echo

Output of first command was:

 Thu Jan  3 11:32:53 CET 2008
 lrwxrwxrwx 1 root root 0 2008-01-03 11:32 8524/root -> /var/www/
 lrwxrwxrwx 1 root root 0 2008-01-03 11:32 8525/root -> /var/www/
 Thu Jan  3 11:32:54 CET 2008
 lrwxrwxrwx 1 root root 0 2008-01-03 11:32 8524/root -> /var/www/
 lrwxrwxrwx 1 root root 0 2008-01-03 11:32 8525/root -> /var/www/

I now run _2_ fnords: one on port 80, chrooted.  I've created the
symlink:

 /var/www/doc.mdcc.cx:80 -> http://doc.mdcc.cx:8080/

The other one has

 root@stegun:~# cat /var/service/fnord-8080/run
 #!/bin/sh
 cd /var/www
 exec chpst -m2000000 -uwww-data -e/etc/fnord/env \
  tcpsvd -l0 0 8080 fnord-cgi 2>&1

That's a -u, not a -U.  That one is _not_ running chrooted.  Since it's
started as user www-data, it can't bind to port 80.

Benefit: no recompile without chroot-support needed: the Debian supplied
binary packages do just fine.  Drawback: two fnord's running, some more
complexity.

Peter: Thanks for your helpful reply!

Bye,

Joost


--udzYTtuEmHLUHegf
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: Digital signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)

iQIVAwUBR3zDVallOfYkUl6eAQIQ4hAAp/jpX5AdVJZ+A9SAMmxgmfDRBc5nR45N
O65dSDegmcbl0zsUW6rxa1LoKh295Xtzq0y3O25AW0ag0QNm7HLsJ3yUR+51sCxu
/c785Kjiz7F4JTGe0jsO4WCvg/+IfMkGvJna+oEURtlVp2D1XSol/HVoPV7svuNz
vQ8ZOXP4DQJFNpcZDMlx+2mgAG1i5ZMN1Du0iBX+6gSFhbzNF89eylaDYc3oPX6q
MFpDVmTYBdnHgRvg7weeJu6nrWclTXlHLqIeLFgDIjGEBt8QrW/ENMhdeEObvHSJ
ZWJbkNsr5T1wcruebJ4LABhDGDOqlC9gobrkILd5GQJy2EusiNDsVGxJhNcQqYz7
TCDhv8dEqVr0CQ8ltexQ7jlrht8SQZzIMRHcSH0biuu9EevtrajhfYvxCCOuZyoP
wR9W5pr3QSVybX8m/oeGzhf1M7hSQPGb0akscx2Bgzs14i4btNWTGaxXbY+it+Xs
WMiwts4I5wqTOXIPytTXZ834YCkm4ViZTxZH0CBmRTZ2/bzBrBSIkZ0P+6XZDVuZ
I1Wbq9i+Ec9jLNFOVE5r070Lfc7lYxko/VsObsGbPaZU9qzLZTO5C+V9zGVILWXw
5phaa1e2rB4Q7sPGKtZMWMsn2bz0KZClVZVsXQytBr7/wZ7HTEM/emH9cdMPLypz
JhzRd3JXZr4=
=cEE+
-----END PGP SIGNATURE-----

--udzYTtuEmHLUHegf--