[Eug-lug] Wrapping for Access Control

Bob Miller kbob at jogger-egg.com
Sun Jan 23 00:49:20 PST 2005


Jeff_W wrote:

> Yeah, I found something in the gopher list archives from the author
> stating that there was no built-in inetd/xnetd support.  I'm curious
> if there is a python module or flag that might change the character
> of a program so as to allow invocation via inetd. John Goerzen,
> PYG's author, appears to be somewhat of an authority on python coding
> for network services so maybe it's not a trivial task:

A non-inetd daemon opens a _socket_, _bind_s it to a well-known port,
and then _listen_s for incoming connections.  When it gets one, it
_accept_s the connection.  (Words delimited in underscores are the
names of the syscalls used.)  There are two sockets used -- the first
is the "listening socket", and the second is the "connection socket",
which is returned from accept().

An inetd aware daemon knows that when inetd invokes it, the listening
socket will have already been opened, bound, and listened on, and the
connection will have been accepted.  The connection socket will be
file descriptor 0 (standard input, though the socket is
bidirectional).

Somewhere in the gopherd source there should be code that listens on a
socket.  It looks like this.

	import socket
	s = socket.Socket(...)
	s.bind(...)
	s.listen(...)

And then somewhere else there is code like this.

	conn, address = s.accept()

You can remove the first snippet and replace the second snippet with this.

	conn = socket.fromfd(0)
	address = socket.getpeername()

If you can make that substitution, you can make your daemon
inetd-aware.  It won't work outside of inetd anymore, of course.

> Anyways, I've come across 'tcpserver' (part of ucspi-tcp by
> D. J. Bernstein, the Qmail guy) which might do the trick:

tcpserver won't help.  You'd still have to rewrite your daemon
to work with it.

-- 
Bob Miller                              K<bob>
kbobsoft software consulting
http://kbobsoft.com                     kbob at jogger-egg.com


More information about the EUGLUG mailing list