* Getname / getuserid for those with no
* hashed passwd data base).
* Do not compile this module in if you DO have hashed
* passwd's -- this is slower.
* Also provided here is a getpw routine which can share
* the open file. This is used for the Version 6 getenv
static char *SccsId
= "@(#)getname.c 2.1 %G%";
static FILE *pwfile
= NULL
; /* Pw file held open */
static char *pwname
= "/etc/passwd"; /* Name of passwd file */
* Search the passwd file for a uid. Return name through ref parameter
* if found, indicating success with 0 return. Return -1 on error.
* If -1 is passed as the user id, close the passwd file.
if (pwfile
== NULL
&& (pwfile
= fopen(pwname
, "r")) == NULL
)
while (fgets(linebuf
, BUFSIZ
, pwfile
) != NULL
)
if (pweval(linebuf
) == uid
) {
for (cp
= linebuf
, cp2
= namebuf
; *cp
!= ':';
* Read the users password file line into the passed line
if (pwfile
== NULL
&& (pwfile
= fopen(pwname
, "r")) == NULL
)
while (fgets(linebuf
, BUFSIZ
, pwfile
) != NULL
)
if (pweval(linebuf
) == uid
) {
linebuf
[strlen(linebuf
)-1] = '\0';
* Look for passwd line belonging to 'name'
if (pwfile
== NULL
&& (pwfile
= fopen(pwname
, "r")) == NULL
) {
while (fgets(linebuf
, BUFSIZ
, pwfile
) != NULL
) {
if (*--cp
== ':' && *--cp2
== 0)
* Convert the passed name to a user id and return it. Return -1
* on error. Iff the name passed is -1 (yech) close the pwfile.
if (name
== (char *) -1) {
if (pwfile
== NULL
&& (pwfile
= fopen(pwname
, "r")) == NULL
)
while (fgets(linebuf
, BUFSIZ
, pwfile
) != NULL
) {
for (cp
= name
, cp2
= linebuf
; *cp
++ == *cp2
++;)
if (*--cp
== '\0' && *--cp2
== ':')
* Evaluate the user id of the passed passwd line and return it.
for (cp
= line
, i
= 0; i
< 2; i
+= (*cp
++ == ':'))
while (*cp
&& *cp
!= ':')