From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1543 invoked by alias); 1 Jul 2011 10:29:37 -0000 Received: (qmail 1527 invoked by uid 22791); 1 Jul 2011 10:29:36 -0000 X-SWARE-Spam-Status: No, hits=-6.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_HI,SPF_HELO_PASS,TW_PW,TW_TP,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 01 Jul 2011 10:29:19 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id p61ATIxr023063 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Fri, 1 Jul 2011 06:29:19 -0400 Received: from hase (ovpn01.gateway.prod.ext.phx2.redhat.com [10.5.9.1]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id p61ATHue018511 for ; Fri, 1 Jul 2011 06:29:18 -0400 From: Andreas Schwab To: libc-hacker@sourceware.org Subject: [PATCH] nss_compat: query NIS domain only when needed X-Yow: Is this an out-take from the ``BRADY BUNCH''? Date: Fri, 01 Jul 2011 10:29:00 -0000 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Mailing-List: contact libc-hacker-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sourceware.org X-SW-Source: 2011-07/txt/msg00000.txt.bz2 2011-07-01 Andreas Schwab * nis/nss_compat/compat-pwd.c (getpwent_next_nss_netgr): Query NIS domain only when needed. --- nis/nss_compat/compat-pwd.c | 27 +++++++++++++++------------ nis/nss_compat/compat-spwd.c | 27 +++++++++++++++------------ 2 files changed, 30 insertions(+), 24 deletions(-) diff --git a/nis/nss_compat/compat-pwd.c b/nis/nss_compat/compat-pwd.c index 6462a85..5107f51 100644 --- a/nis/nss_compat/compat-pwd.c +++ b/nis/nss_compat/compat-pwd.c @@ -361,7 +361,7 @@ getpwent_next_nss_netgr (const char *name, struct passwd *result, ent_t *ent, char *group, char *buffer, size_t buflen, int *errnop) { - char *curdomain, *host, *user, *domain, *p2; + char *curdomain = NULL, *host, *user, *domain, *p2; int status; size_t p2len; @@ -370,15 +370,7 @@ getpwent_next_nss_netgr (const char *name, struct passwd *result, ent_t *ent, if (!nss_getpwnam_r) return NSS_STATUS_UNAVAIL; - if (yp_get_default_domain (&curdomain) != YPERR_SUCCESS) - { - ent->netgroup = false; - ent->first = false; - give_pwd_free (&ent->pwd); - return NSS_STATUS_UNAVAIL; - } - - if (ent->first == true) + if (ent->first) { memset (&ent->netgrdata, 0, sizeof (struct __netgrent)); __internal_setnetgrent (group, &ent->netgrdata); @@ -401,8 +393,19 @@ getpwent_next_nss_netgr (const char *name, struct passwd *result, ent_t *ent, if (user == NULL || user[0] == '-') continue; - if (domain != NULL && strcmp (curdomain, domain) != 0) - continue; + if (domain != NULL) + { + if (curdomain == NULL + && yp_get_default_domain (&curdomain) != YPERR_SUCCESS) + { + __internal_endnetgrent (&ent->netgrdata); + ent->netgroup = false; + give_pwd_free (&ent->pwd); + return NSS_STATUS_UNAVAIL; + } + if (strcmp (curdomain, domain) != 0) + continue; + } /* If name != NULL, we are called from getpwnam. */ if (name != NULL) diff --git a/nis/nss_compat/compat-spwd.c b/nis/nss_compat/compat-spwd.c index 6699259..f33dd3e 100644 --- a/nis/nss_compat/compat-spwd.c +++ b/nis/nss_compat/compat-spwd.c @@ -318,7 +318,7 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent, char *group, char *buffer, size_t buflen, int *errnop) { - char *curdomain, *host, *user, *domain, *p2; + char *curdomain = NULL, *host, *user, *domain, *p2; size_t p2len; if (!nss_getspnam_r) @@ -328,15 +328,7 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent, if (ent->setent_status != NSS_STATUS_SUCCESS) return ent->setent_status; - if (yp_get_default_domain (&curdomain) != YPERR_SUCCESS) - { - ent->netgroup = false; - ent->first = false; - give_spwd_free (&ent->pwd); - return NSS_STATUS_UNAVAIL; - } - - if (ent->first == true) + if (ent->first) { memset (&ent->netgrdata, 0, sizeof (struct __netgrent)); __internal_setnetgrent (group, &ent->netgrdata); @@ -361,8 +353,19 @@ getspent_next_nss_netgr (const char *name, struct spwd *result, ent_t *ent, if (user == NULL || user[0] == '-') continue; - if (domain != NULL && strcmp (curdomain, domain) != 0) - continue; + if (domain != NULL) + { + if (curdomain == NULL + && yp_get_default_domain (&curdomain) != YPERR_SUCCESS) + { + __internal_endnetgrent (&ent->netgrdata); + ent->netgroup = false; + give_spwd_free (&ent->pwd); + return NSS_STATUS_UNAVAIL; + } + if (strcmp (curdomain, domain) != 0) + continue; + } /* If name != NULL, we are called from getpwnam */ if (name != NULL) -- 1.7.6 -- Andreas Schwab, schwab@redhat.com GPG Key fingerprint = D4E8 DBE3 3813 BB5D FA84 5EC7 45C6 250E 6F00 984E "And now for something completely different."