Users on a remote machine

Dan Bernstein brnstnd at kramden.acf.nyu.edu
Sat Mar 2 16:34:43 AEST 1991


In article <1991Mar1.232038.6962 at rlgvax.Reston.ICL.COM> scc at rlgvax.OPCR.ICL.COM (Stephen Carlson) writes:
> Does anybody know a straightforward and fairly protable way to determine
> from a C program whether a certain user exists on a certain remote machine?

The question is ill-defined. There are many concepts of ``user'', and
even if a machine has one type of user it may not tell you about it. You
haven't said what you mean by ``remote''; the answer will be different
depending on the type of communication your machine has with the remote
machine. And there are very few ways portable between BSD and System V
(with various networking extensions from various vendors).

Now you probably mean either mailbox or ``finger-box,'' on the Internet,
under BSD. Read the RFCs on SMTP or the finger protocol to determine
what you should ask the remote machine; read the BSD socket manuals to
figure out how you should do it.

If you have authtcp (c.s.unix volume 22), for example:

  authtcp "$HOST" smtp sh -c \
  'echo vrfy "$MBOX">&6;echo quit>&6;grep '\''^.50'\''<&6'

will test for a mailbox. (Well, it assumes that the remote side batches,
and it doesn't print an initial HELO the way some paranoid servers want,
but I wouldn't worry about synchronization for this kind of problem.) It
should print either a line beginning with 550 meaning no user, or one or
more lines beginning with 250. All but the last line will begin 250-;
the last will begin 250<space>. After the hyphen or space will be a
supposedly valid mailing address.

You can invoke this from a C program with popen() after putting the
appropriate HOST and MBOX into your environment; make sure to combine
both lines into one and remove the backslash. Don't worry about quoting
HOST or MBOX.

---Dan



More information about the Comp.unix.programmer mailing list