Subject: Re: getpwent(3) funcs return static structure
To: der Mouse <mouse@Rodents.Montreal.QC.CA>
From: Don Lewis <>
List: current-users
Date: 04/03/1997 05:04:53
On Apr 3,  7:48am, der Mouse wrote:
} Subject: Re: getpwent(3) funcs return static structure
} For the r* utilities, what I have normally done is something like
} 	user = getenv("USER")
} 	if user!=0 and (pw=getpwnam(user))!=0
} 		if getuid()==0 or getuid()==pw->pw_uid
} 			use pw

But this allows you to "su" to any of the other users with the same
uid by just altering your USER environment variable ...

Also, if you su to root, then rsh, this code will use the old value of
USER, unless you "su -l" which updates USER.  This could occasionally
be suprising.

} 	pw = getpwnam(getuid())
} 		if pw!=0
} 			use pw
} 	give "who are you" error and die

} One could argue it should also call getlogin(), but the only cases
} where getlogin() will succeed and getenv("USER") fail are when
} something is severely broken or someone is trying to get fancy with the
} code; in neither case do I consider it a major problem for the code to
} fall back to getpwuid(getuid()) instead.

Getlogin() doesn't help anyway if you're not a decendent of login
(for instance cron or rshd).

			---  Truck