Mailing List Archive

Sockets and lemon curry
No, no, I don't know where the lemon curry fits in... with a melon?

I'm trying to implement an rshd server in Python. The problem seems to be
with establishing the secondary socket for stderr. I'm using a Linux 2.0
box as client, and a Windows machine as server (ultimately, this is to
support rmt access to the Windows box's tape drive). In experimenting, I've
gotten things to work with utilities that don't require the second socket
(e.g. rcp). But the moment I try to establish the secondary socket, the
client says, "protocol violation" and gives up. Ideas?

In more detail, here's what I'm doing (without error handling, etc.):

s = socket(AF_INET, SOCK_STREAM)
s.bind('', 514) # RSH well-known port
s.listen(1)
conn, addr = s.listen() # blocks for client request
response = conn.recv(1024) # this response has the secondary port number
...do some string stuff to get the port number into integer type as 'port2'
s2 = socket(AF_INET, SOCK_STREAM)
s2.connect(addr[0], port2) #addr tuple is host, port for conn

...and that's where the client says, "Pining for the fjords???" and gives
up. I've done network tracing and can't find anything odd going on. This
seems like a simple handshake, and if I use (for instance) the Windows
machine as a client against the Linux server (and do a network trace),
everything works and looks great.

Any ideas? TIA - Ian

Ian King
iking@killthewabbit.org
Sockets and lemon curry [ In reply to ]
Ian King writes:

> I'm trying to implement an rshd server in Python. The problem seems
> to be with establishing the secondary socket for stderr. I'm using
> a Linux 2.0 box as client, and a Windows machine as server

> ... In experimenting, I've gotten things to work with utilities
> that don't require the second socket (e.g. rcp). But the moment I
> try to establish the secondary socket, the client says, "protocol
> violation" and gives up. Ideas?

/snip code/

> ... This seems like a simple handshake, and if I use (for
> instance) the Windows machine as a client against the Linux server
> (and do a network trace), everything works and looks great.

Yes. On *nix, it takes root authority to create sockets on ports
below 1024. No such limit on NT. You didn't say what 'port2' was, but
it sure fits the symptoms...

- Gordon
Sockets and lemon curry [ In reply to ]
"Ian King" <iking@killthewabbit.org> writes:

> I'm trying to implement an rshd server in Python. The problem seems to be
> with establishing the secondary socket for stderr.

[snip]

> s2 = socket(AF_INET, SOCK_STREAM)
> s2.connect(addr[0], port2) #addr tuple is host, port for conn
>
> ....and that's where the client says, "Pining for the fjords???" and gives
> up.

I think you've missed something. The OS will assign the local port
for this socket from 1024 up. However, rsh requires that the remote
port that connects to it for stderr is less than 1024, to prove that
it's not just another user on the box pretending to be rshd, but a
process running as root.

You'll have to have the Python server bind() to a reserved port before
trying to connect back to rsh. Something like the following code may
be appropriate, and acts like the code the real rshd uses.

------------------------------------------------------------
import exceptions
import socket
import errno
import types

class RResvPortError(exceptions.Exception):
def __str__(self):
return 'No reserved ports available'

def rresvport():
port = 1023
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
while port >= 1:
try:
s.bind('', port)
except socket.error, detail:
if type(detail) is not types.TupleType \
or detail[0] != errno.EADDRINUSE:
raise
else:
return s
port = port - 1

raise RResvPortError
------------------------------------------------------------

--
Carey Evans http://home.clear.net.nz/pages/c.evans/

"I'm not a god. I've just been misquoted."
Sockets and lemon curry [ In reply to ]
From: Gordon McMillan <gmcm@hypernet.com>
To: Ian King <iking@killthewabbit.org>; <python-list@python.org>
Sent: Saturday, June 05, 1999 8:14 PM
Subject: Re: Sockets and lemon curry


> Ian King writes:
>
> > I'm trying to implement an rshd server in Python. The problem seems
> > to be with establishing the secondary socket for stderr. I'm using
> > a Linux 2.0 box as client, and a Windows machine as server
[snip]
>
> Yes. On *nix, it takes root authority to create sockets on ports
> below 1024. No such limit on NT. You didn't say what 'port2' was, but
> it sure fits the symptoms...
>
> - Gordon
>
This sounded right on, but as I played with it, I realized: the secondary
port (which is, yes, a reserved port) is created on the Linux box; the NT
machine is simply doing a connect() (and there are no problems as Python
under NT creates *its* socket). Nonetheless, I played with .rhosts and
such, to create as benign (and dangerous!) an environment as possible on the
client, to no avail. Besides, if I couldn't connect() to reserved ports,
that would pretty much preclude most Internet services! :-)