Bug 165604 - getpwuid() fails when linking with libbind and compat in nsswitch.conf
Summary: getpwuid() fails when linking with libbind and compat in nsswitch.conf
Alias: None
Product: Fedora
Classification: Fedora
Component: bind   
(Show other bugs)
Version: 4
Hardware: i386
OS: Linux
Target Milestone: ---
Assignee: Jason Vas Dias
QA Contact: Ben Levenson
Depends On:
TreeView+ depends on / blocked
Reported: 2005-08-10 18:53 UTC by Jacques Beigbeder
Modified: 2007-11-30 22:11 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2005-08-12 16:01:02 UTC
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)

Description Jacques Beigbeder 2005-08-10 18:53:29 UTC
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.7.10) Gecko/20050720 Fedora/1.0.6-1.1.fc3 Firefox/1.0.6

Description of problem:
/etc/nsswitch.conf contains:
passwd:     compat
Here is a.c:
----#include <unistd.h>
#include <sys/types.h>
#include <pwd.h>
    struct passwd *p;
    p = getpwuid(303);
    if (p != NULL)
        printf("%s\n",p -> pw_name);
    exit (0);
gcc -o a a.c; ./a   => correct (displays good username)
gcc -o a a.c -lbind; ./a => incorrect (no display)

Version-Release number of selected component (if applicable):

How reproducible:

Steps to Reproduce:
1. Use Fedora Core 3 or Fedora Core 4
2. Set up /etc/nsswitch.conf with 'passwd:compat'
3. Compile my program with ou without '-lbind'

Additional info:

Comment 1 Jason Vas Dias 2005-08-12 16:01:02 UTC
I cannot reproduce this problem.

Firstly, the bind-libbind package provides the BIND 8 resolver library
for applications that specifically require it, not as the system default

Unless you specifically require use of the BIND resolver, use the system

The system resolver is in glibc; you use it automatically with this compile:
# gcc -o a a.c
See man resolver(3)

Only the system resolver uses /etc/nsswitch.conf; libbind uses 
/etc/irs.conf (see man libbind-irs.conf).

In order to use libbind, you need to include the headers in 
/usr/include/bind BEFORE the system headers, and link with
libbind BEFORE glibc - ie. :
#include <bind/irs.h>
#include <bind/resolv.h>
#include <bind/arpa/inet.h>
#include <bind/arpa/nameser.h>
#include <unistd.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>

    struct passwd *p;
    p = getpwuid(25);
    if (p != NULL)
        printf("%s\n",p -> pw_name);
    exit (0);

This works fine on my system for local users:

# gcc -o a a.c -lbind
# ./a

You'd need to configure /etc/irs.conf to retrieve information about NIS,
NISPLUS, LDAP, or Hesiod users.
If you require to use the libbind library, and after having followed the
above steps to pick up the correct includes, and having configured irs.conf
if you need to resolve non-local users, you still have a problem, please
re-open this bug; I'm closing it as NOTABUG since I cannot reproduce it
with correct use of the libbind library.

Note You need to log in before you can comment on or make changes to this bug.