Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!helios!bcm!rice!uupsi!cmcl2!kramden.acf.nyu.edu!brnstnd From: brnstnd@kramden.acf.nyu.edu (Dan Bernstein) Newsgroups: comp.unix.programmer Subject: Re: Users on a remote machine Message-ID: <8877:Mar205:34:4391@kramden.acf.nyu.edu> Date: 2 Mar 91 05:34:43 GMT References: <1991Mar1.232038.6962@rlgvax.Reston.ICL.COM> Organization: IR Lines: 35 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. 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