[comp.unix.programmer] Users on a remote machine

scc@rlgvax.Reston.ICL.COM (Stephen Carlson) (03/02/91)

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?

If you send E-mail I will summarize in a about a week.

Thanks.

-- 
Stephen Carlson         | ICL OFFICEPOWER Center    | In theory, theory and
scc@rlgvax.opcr.icl.com | 11490 Commerce Park Drive | practice are the same.
..!uunet!rlgvax!scc     | Reston, VA  22091         |

gill@boris.mscs.mu.edu (Vijay (Ender) Gill) (03/02/91)

In article <1991Mar1.232038.6962@rlgvax.Reston.ICL.COM> scc@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?
>
[--deleted--]

>Stephen Carlson         | ICL OFFICEPOWER Center    | In theory, theory and
>scc@rlgvax.opcr.icl.com | 11490 Commerce Park Drive | practice are the same.

The Unix finger command should work.  For specific code, see source
code at uunet.uu.net, in bsd-sources.  This should provide you with
the guts of the program, though you will have to work on it to fit
in with the rest of your program (I assume) you are writing.  It
would be too bad if you are rewriting finger :-).

cheers
-dicky gill (Violator)
-gill@boris.mscs.mu.edu

brnstnd@kramden.acf.nyu.edu (Dan Bernstein) (03/02/91)

In article <1991Mar1.232038.6962@rlgvax.Reston.ICL.COM> scc@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