DragonFly BSD
DragonFly kernel List (threaded) for 2003-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: LibC status and others...

From: Matthew Dillon <dillon@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 10 Dec 2003 17:08:52 -0800 (PST)

:well, it took me less than 30 minutes...
:but it was really simple and is most likely not correct.
:but maybe it is, and this way, we could concentrate on something different.
:btw: if this looks right, i may tackle the other _r's tomorrow.

    That's not going to quite work, but it was a good try!

    The issue is that the supplied buffer must be used to hold auxillary
    data... the pointers to pw_name, pw_passwd, and so forth in the
    struct passwd.

    This means that __hashpw() in the same file must be adjusted.  It
    uses a static u_int max and static char *line at the moment... instead
    the buffer and buffer size must be passed to hashpw() and it must
    properly return an error if the buffer is not large enough.

    getpwnam() must allocate a sufficiently sized buffer and deal with
    ERANGE.  ERANGE must be returned if the buffer is not sufficient.

    This is how FreeBSD-current deals with it.  I'm not saying copy this,
    because it's rather messy code, but just to demonstrate the problem...

        if (pwd_storage == NULL) {
                pwd_storage = malloc(PWD_STORAGE_INITIAL);
                if (pwd_storage == NULL)
                        return (NULL);
                pwd_storage_size = PWD_STORAGE_INITIAL;
        do {
                rv = fn(key, &pwd, pwd_storage, pwd_storage_size, &res);
                if (res == NULL && rv == ERANGE) {
                        if ((pwd_storage_size << 1) > PWD_STORAGE_MAX) {
                                pwd_storage = NULL;
                                return (NULL);
                        pwd_storage_size <<= 1;
                        pwd_storage = malloc(pwd_storage_size);
                        if (pwd_storage == NULL)
                                return (NULL);
        } while (res == NULL && rv == ERANGE);

    Would you like to try again?

					Matthew Dillon 

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