Date: Mon, 3 Dec 2012 17:54:24 -0600 From: Dan Lists <lists.dan@gmail.com> To: freebsd-questions <freebsd-questions@freebsd.org> Subject: getpwnam_r returns EINVAL on FreeBSD 8.3 Message-ID: <CAPW8bZ3DzxyNy27uYHL78wzgXjACES3K94bOuW0JPXPhjgr=rg@mail.gmail.com>
next in thread | raw e-mail | index | archive | help
After upgrading a server from FreeBSD 7.3 to FreeBSD 8.3 I noticed this bug. Since upgrading, getpwnam_r is acting inconsistently. If I look up a user that does not exist and the name is 16 characters or less, getpwnam_r returns 0 and the result is NULL. If the name is more than 16 characters, getpwnam_r returns EINVAL. Everything works correctly for users that exist. This only happens when the nsswitch.conf passwd: line contains files. You need to use files if you are using another module such as msql or ldap. The problem exists without the other modules listed. For example: passwd: files Below is a simple test program. Set passwd: to files in nsswitch.conf and run the program. Any idea how to fix this bug with getpwnam_r? #include <stdio.h> #include <sys/types.h> #include <pwd.h> main() { lookup("doesnotexistXXXX"); lookup("doesnotexistXXXXy"); } int lookup( char *name) { struct passwd pwd; char buffer[1024]; struct passwd *result; int err; printf("\nLooking up: %s\n", name); err = getpwnam_r(name, &pwd, buffer, sizeof(buffer), &result); if( err != 0 ){ printf("Return code: %d\n", err); }else if( result == 0 ){ printf("Returned no result!\n"); }else{ printf("Returned: %s (%d)\n", result->pw_name, result->pw_uid); } }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAPW8bZ3DzxyNy27uYHL78wzgXjACES3K94bOuW0JPXPhjgr=rg>