implementation of getpwnam_r
Tim Robbins
tjr at FreeBSD.ORG
Mon Mar 31 05:47:45 PST 2003
On Sun, Mar 30, 2003 at 06:06:20PM -0600, David Leimbach wrote:
> It seems this already exists in src/contrib/bind/lib/getpwent_r.c
>
> int getpwnam_r(const char * login, struct passwd *pwptr, char * buf,
> size_t buflen,
> struct passwd ** result)
> {
>
> struct passwd *pw = getpwnam(login);
> int res;
>
> if (pw == NULL) {
> *result = NULL;
> return (0);
> }
>
> res = copy_passwd(pw,pwptr,buf,buflen);
> *result = res ? NULL : pwptr;
> return (res);
> }
>
> Is this sufficient? copy_passwd is also in the bind library?
There is a race between the getpwnam() call and when the data is
copied to the user-supplied buffer. In addition to this, I don't
think that getpwnam_r() is allowed to modify the static storage
used by getpwnam(). The current passwd code is truly awful, and
I think someone is working on a replacement for it. It might be
worth waiting to see what happens there before investing too much
energy in implementing the *_r() functions in the current code.
Tim
More information about the freebsd-standards
mailing list