From patchwork Wed Mar 26 09:50:42 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddhesh Poyarekar X-Patchwork-Id: 292 Return-Path: X-Original-To: siddhesh@wilcox.dreamhost.com Delivered-To: siddhesh@wilcox.dreamhost.com Received: from homiemail-mx23.g.dreamhost.com (caibbdcaabja.dreamhost.com [208.113.200.190]) by wilcox.dreamhost.com (Postfix) with ESMTP id 558F93600A6 for ; Wed, 26 Mar 2014 02:50:05 -0700 (PDT) Received: by homiemail-mx23.g.dreamhost.com (Postfix, from userid 14307373) id 1745862BBA81A; Wed, 26 Mar 2014 02:50:05 -0700 (PDT) X-Original-To: glibc@patchwork.siddhesh.in Delivered-To: x14307373@homiemail-mx23.g.dreamhost.com Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by homiemail-mx23.g.dreamhost.com (Postfix) with ESMTPS id DEB2562BBA8F1 for ; Wed, 26 Mar 2014 02:50:04 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; q=dns; s=default; b=oC+my6Pj/7g3pkIQxQO6Z17mMWbj8 ntJXZM0Ignxg6Hi/t2SffpH9D+27apKbulFBJEQI86TYkK20CEPmgCJWj43GoFBd A7dXj0p7auHKevShNIWyLRwHFNKKZcldviQ1PYX6gAHmaRpvfVQ8zrqGrOxIQfDM VyzkoatbiA5/qo= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:date:from:to:subject:message-id:mime-version :content-type; s=default; bh=aVv/BRajvZy7jbmcJzP1xRDm8Yw=; b=bhL eXmM2j60tMj/g5FIMQAo4RQ3RqK6F/8TaO02yPtbiKKPRu0sV4RhOJzvIiWJHnOs gLClEO23aBNEnUZdxUIC7NWNBGYBTw3/JduG9vjR9F2tVHmCkunc9mctBx3iy7P/ CJUK3P/hSq2Qc2pX5j7n/Zo3PmBeLjykGVZpZFU4= Received: (qmail 20394 invoked by alias); 26 Mar 2014 09:50:03 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 20385 invoked by uid 89); 26 Mar 2014 09:50:02 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.9 required=5.0 tests=AWL, BAYES_00, RP_MATCHES_RCVD, SPF_HELO_PASS, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mx1.redhat.com Date: Wed, 26 Mar 2014 15:20:42 +0530 From: Siddhesh Poyarekar To: libc-alpha@sourceware.org Subject: [PATCH] Return NULL for wildcard values in getnetgrent from nscd (BZ #16759) Message-ID: <20140326095041.GA9937@spoyarek.pnq.redhat.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.22.1-rc1 (2013-10-16) X-DH-Original-To: glibc@patchwork.siddhesh.in getnetgrent is supposed to return NULL for values that are wildcards in the (host, user, domain) triplet. This works correctly with nscd disabled, but with it enabled, it returns a blank ("") instead of a NULL. This is easily seen with the output of `getent netgroup foonet` for a netgroup foonet defined as follows in /etc/netgroup: foonet (,foo,) The output with nscd disabled is: foonet ( ,foo,) while with nscd enabled, it is: foonet (,foo,) The extra space with nscd disabled is due to the fact that `getent netgroup` adds it if the return value from getnetgrent is NULL for either host or user. Tested on x86_64. Siddhesh [BZ #16759] * inet/getnetgrent_r.c (get_nonempty_val): New function. (nscd_getnetgrent): Use it. --- inet/getnetgrent_r.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/inet/getnetgrent_r.c b/inet/getnetgrent_r.c index 62cdfda..f6d064d 100644 --- a/inet/getnetgrent_r.c +++ b/inet/getnetgrent_r.c @@ -235,6 +235,14 @@ endnetgrent (void) } #ifdef USE_NSCD +static const char * +get_nonempty_val (const char *in) +{ + if (*in == '\0') + return NULL; + return in; +} + static enum nss_status nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen, int *errnop) @@ -243,11 +251,11 @@ nscd_getnetgrent (struct __netgrent *datap, char *buffer, size_t buflen, return NSS_STATUS_UNAVAIL; datap->type = triple_val; - datap->val.triple.host = datap->cursor; + datap->val.triple.host = get_nonempty_val (datap->cursor); datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1; - datap->val.triple.user = datap->cursor; + datap->val.triple.user = get_nonempty_val (datap->cursor); datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1; - datap->val.triple.domain = datap->cursor; + datap->val.triple.domain = get_nonempty_val (datap->cursor); datap->cursor = (char *) __rawmemchr (datap->cursor, '\0') + 1; return NSS_STATUS_SUCCESS;