Re: [mituc@xxxxxxxxxxxxxx: pam limits drops privileges]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 12 Sep 2001, Thorsten Kukuk wrote:

> > Is the following ok for a first implementation, or do you have more ambitious
> > plans?  I believe you mentioned providing a wrapper for systems that don't
> > have getpwnam_r(), but I'm personally quite content with this.

> You should not allocate a static buffer for use with getpwnam_r.
> Instead query the return code and if errno = ERANGE (I think this was
> the value) increase the buffer and try it again.
> Else the result will be worse then the current situation, longer entries
> will fail.

Gotcha.  Take two, then.  Certainly clumsier than a single call to getpwnam(),
but hopefully this gets us started in the right direction.

I've committed this particular change already on the head CVS branch, in
modules/pam_unix/support.c -- which coincidentally doesn't include
_pam_aconf.h, and therefore doesn't see the HAVE_GETPWNAM_R define yet.

Further corrections are welcome.

Steve Langasek
postmodern programmer

    struct passwd *pwd = NULL;
#if HAVE_GETPWNAM_R
    char *buf = NULL;
    int bufsize = 0;
    struct passwd pwd_buf;

    pwd = &pwd_buf;
#endif

...

#if HAVE_GETPWNAM_R
    bufsize = 1024;
    buf = malloc(bufsize);

    if ((retval = getpwnam_r(name, pwd, buf, bufsize, &pwd))) {
        pwd = NULL;
    }
    while (retval == ERANGE) {
        bufsize += 1024;
        buf = realloc(buf, bufsize);
        if ((retval = getpwnam_r(name, pwd, buf, bufsize, &pwd))) {
            pwd = NULL;
        }
    }
#else
    pwd = getpwnam(name);
#endif

...

#if HAVE_GETPWNAM_R
    if (buf)
        free (buf);
#endif
    return;





[Index of Archives]     [Fedora Users]     [Kernel]     [Red Hat Install]     [Linux for the blind]     [Gimp]

  Powered by Linux