Xref: utzoo alt.sources:838 alt.sources.d:8 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!cs.utexas.edu!natinst!sequoia!rpp386!jfh From: jfh@rpp386.Dallas.TX.US (John F. Haugh II) Newsgroups: alt.sources,alt.sources.d Subject: Re: euser - display the effective user name, SysV-ish Message-ID: <16770@rpp386.Dallas.TX.US> Date: 8 Jul 89 05:49:46 GMT References: <14448@bfmny0.UUCP> Reply-To: jfh@rpp386.cactus.org (John F. Haugh II) Followup-To: alt.sources.d Organization: I am NOT the NRA Lines: 22 In article <14448@bfmny0.UUCP> tneff@bfmny0.UUCP (Tom Neff) writes: >If you need a FAST way to generate the name of your current effective >user (including the effects of su(1) etc), this works. It's not fancy. >Obviously it has to read /etc/passwd. Feel free to hack and pass >around. >X while (fgets(line, sizeof(line), pass) != NULL) This is not a very good idea. You make assumptions about the password file which probably won't be holding true for too many more releases of UNIX. getpwuid() is going to be your best bet. It should be hoped that your local software vendor took the time to implement getpwuid() in an efficient manner; such as using YP or ndbm or whatever services are available. In a distributed environment the password file may not even reside on your machine completely. -- John F. Haugh II +-Quote of the month club: ------------ VoiceNet: (512) 832-8832 Data: -8835 | "Computer security is to information InterNet: jfh@rpp386.cactus.org | control as a chastity belt is to UucpNet : !bigtex!rpp386!jfh +- birth control" -- Doug Steves --