From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25019 invoked by alias); 18 May 2006 14:39:51 -0000 Received: (qmail 24991 invoked by uid 22791); 18 May 2006 14:39:50 -0000 X-Spam-Check-By: sourceware.org Received: from sunsite.ms.mff.cuni.cz (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org (qpsmtpd/0.31) with ESMTP; Thu, 18 May 2006 14:39:46 +0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id k4IEdXg6028011; Thu, 18 May 2006 16:39:33 +0200 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id k4IEdXmS028005; Thu, 18 May 2006 16:39:33 +0200 Date: Thu, 18 May 2006 14:39:00 -0000 From: Jakub Jelinek To: Ulrich Drepper Cc: Glibc hackers Subject: [PATCH] Fix nss_compat Message-ID: <20060518143932.GQ4651@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4.1i Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2006-05/txt/msg00020.txt.bz2 Hi! Before the SETENT_BATCH_READ addition, both NIS and NIS+ setpwent hook always returned NSS_STATUS_SUCCESS, even when NIS or NIS+ wasn't reachable (well, NIS+ could return NSS_STATUS_TRYAGAIN on memory allocation failure). But, with SETENT_BATCH_READ, NIS/NIS+ setpwent hook returns NSS_STATUS_UNAVAIL if NIS/NIS+ isn't reachable. When nss_compat setpwent hook is called, we unfortunately check if /etc/passwd (etc.) is available (if not, fail, which is IMHO correct), but if it is available, return whatever the chained NSS module's setpwent hook returns. But, nss_compat is supposed to work even when the chained NSS module isn't working (e.g. with passwd: compat passwd_compat: nis in /etc/nsswitch.conf during bootup before NIS is started, it is expected that only users in /etc/passwd will be used and not NIS only users). The following patch fixes this, by returning NSS_STATUS_SUCCESS if the file could be opened, but the chained set*ent hook returned NSS_STATUS_UNAVAIL. In case of memory failure we would still return NSS_STATUS_TRYAGAIN, but pretending no error happened would be weird. The compat-initgroups.c change is unrelated, I noticed unused variables... 2006-05-18 Jakub Jelinek * nis/nss_compat/compat-pwd.c (internal_setpwent): If nss_set*ent returned NSS_STATUS_UNAVAIL, still return NSS_STATUS_SUCCESS. * nis/nss_compat/compat-spwd.c (internal_setspent): Likewise. * nis/nss_compat/compat-grp.c (internal_setgrent): Likewise. * nis/nss_compat/compat-initgroups.c (nss_setgrent, nss_endgrent): Removed. (init_nss_interface): Remove initialization of these variables. --- libc/nis/nss_compat/compat-pwd.c.jj 2005-09-12 09:29:04.000000000 +0200 +++ libc/nis/nss_compat/compat-pwd.c 2006-05-18 16:05:55.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-1999,2001-2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk , 1996. @@ -258,7 +258,11 @@ internal_setpwent (ent_t *ent, int stayo give_pwd_free (&ent->pwd); if (status == NSS_STATUS_SUCCESS && nss_setpwent) - return nss_setpwent (stayopen); + { + status = nss_setpwent (stayopen); + if (status == NSS_STATUS_UNAVAIL) + status = NSS_STATUS_SUCCESS; + } return status; } --- libc/nis/nss_compat/compat-spwd.c.jj 2005-09-12 09:29:04.000000000 +0200 +++ libc/nis/nss_compat/compat-spwd.c 2006-05-18 16:10:15.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-1999,2001-2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk , 1996. @@ -212,7 +212,11 @@ internal_setspent (ent_t *ent, int stayo give_spwd_free (&ent->pwd); if (status == NSS_STATUS_SUCCESS && nss_setspent) - return nss_setspent (stayopen); + { + status = nss_setspent (stayopen); + if (status == NSS_STATUS_UNAVAIL) + status = NSS_STATUS_SUCCESS; + } return status; } --- libc/nis/nss_compat/compat-grp.c.jj 2005-09-12 09:29:04.000000000 +0200 +++ libc/nis/nss_compat/compat-grp.c 2006-05-18 16:07:30.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1996-1999,2001-2004,2005 Free Software Foundation, Inc. +/* Copyright (C) 1996-1999,2001-2005,2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk , 1996. @@ -138,7 +138,11 @@ internal_setgrent (ent_t *ent, int stayo rewind (ent->stream); if (status == NSS_STATUS_SUCCESS && nss_setgrent) - return nss_setgrent (stayopen); + { + status = nss_setgrent (stayopen); + if (status == NSS_STATUS_UNAVAIL) + status = NSS_STATUS_SUCCESS; + } return status; } --- libc/nis/nss_compat/compat-initgroups.c.jj 2004-09-14 00:32:49.000000000 +0200 +++ libc/nis/nss_compat/compat-initgroups.c 2006-05-18 16:09:36.000000000 +0200 @@ -1,4 +1,4 @@ -/* Copyright (C) 1998-2003, 2004 Free Software Foundation, Inc. +/* Copyright (C) 1998-2003, 2004, 2006 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Thorsten Kukuk , 1998. @@ -36,7 +36,6 @@ static service_user *ni; static enum nss_status (*nss_initgroups_dyn) (const char *, gid_t, long int *, long int *, gid_t **, long int, int *); -static enum nss_status (*nss_setgrent) (int stayopen); static enum nss_status (*nss_getgrnam_r) (const char *name, struct group * grp, char *buffer, size_t buflen, int *errnop); @@ -45,7 +44,6 @@ static enum nss_status (*nss_getgrgid_r) int *errnop); static enum nss_status (*nss_getgrent_r) (struct group * grp, char *buffer, size_t buflen, int *errnop); -static enum nss_status (*nss_endgrent) (void); /* Protect global state against multiple changers. */ __libc_lock_define_initialized (static, lock) @@ -92,11 +90,9 @@ init_nss_interface (void) && __nss_database_lookup ("group_compat", NULL, "nis", &ni) >= 0) { nss_initgroups_dyn = __nss_lookup_function (ni, "initgroups_dyn"); - nss_setgrent = __nss_lookup_function (ni, "setgrent"); nss_getgrnam_r = __nss_lookup_function (ni, "getgrnam_r"); nss_getgrgid_r = __nss_lookup_function (ni, "getgrgid_r"); nss_getgrent_r = __nss_lookup_function (ni, "getgrent_r"); - nss_endgrent = __nss_lookup_function (ni, "endgrent"); } __libc_lock_unlock (lock); Jakub