From owner-freebsd-questions@FreeBSD.ORG Mon Dec 3 23:54:26 2012 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 189A86C0 for ; Mon, 3 Dec 2012 23:54:26 +0000 (UTC) (envelope-from lists.dan@gmail.com) Received: from mail-ia0-f182.google.com (mail-ia0-f182.google.com [209.85.210.182]) by mx1.freebsd.org (Postfix) with ESMTP id CE96A8FC15 for ; Mon, 3 Dec 2012 23:54:25 +0000 (UTC) Received: by mail-ia0-f182.google.com with SMTP id x2so3174211iad.13 for ; Mon, 03 Dec 2012 15:54:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:date:message-id:subject:from:to:content-type; bh=U9/B/VVErl3JlD5uUrYECOZKhPLd+1zQZuee+U3Qd0E=; b=IgOOxxM5I+TiatHBvTEePAhrBh0++TuLb4Or+MtfGahiHcDd4kFPvxsQzUJbc+uYag n9qMSwLT+GTBtFeEcdqc/svhzZ168fbiV0vH9BWswjapWdLzqekmJ3S0OSAkbm7SCaQu CfXQ3FqJmrJjHGsLPC8on5HtBHw0gnmnnKiV5A0nFLjhvT4cVlRtyPO0Ve1HzpQsmUNz E1gY77MfgWNuvZvmfsU4vJ2LYapXgOQEHXNG9Tea4mpma07WLClNGBTrJQNO+R8nSMei gXCEVu/8KLh7BIQLr2TcXwQjrpvPm7YW0iqG4LGAbn0XBgx2kujjheWGo77SY9PIFzVY kIlw== MIME-Version: 1.0 Received: by 10.42.139.74 with SMTP id f10mr9401481icu.4.1354578865036; Mon, 03 Dec 2012 15:54:25 -0800 (PST) Received: by 10.64.13.194 with HTTP; Mon, 3 Dec 2012 15:54:24 -0800 (PST) Date: Mon, 3 Dec 2012 17:54:24 -0600 Message-ID: Subject: getpwnam_r returns EINVAL on FreeBSD 8.3 From: Dan Lists To: freebsd-questions Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 03 Dec 2012 23:54:26 -0000 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 #include #include 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); } }