Bug 165604 - getpwuid() fails when linking with libbind and compat in nsswitch.conf
getpwuid() fails when linking with libbind and compat in nsswitch.conf
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: bind (Show other bugs)
4
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Jason Vas Dias
Ben Levenson
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2005-08-10 14:53 EDT by Jacques Beigbeder
Modified: 2007-11-30 17:11 EST (History)
0 users

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


Attachments (Terms of Use)

  None (edit)
Description Jacques Beigbeder 2005-08-10 14:53:29 EDT
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>
main()
{
    struct passwd *p;
    p = getpwuid(303);
    if (p != NULL)
        printf("%s\n",p -> pw_name);
    exit (0);
}
---
Output:
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):
bind-libs-9.3.1-4

How reproducible:
Always

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 12:01:02 EDT
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
resolver. 

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

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>

main()
{
    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
named

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.