From patchwork Mon Dec 14 22:15:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frank Sorenson X-Patchwork-Id: 7849331 Return-Path: X-Original-To: patchwork-linux-nfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 579D2BEEE1 for ; Mon, 14 Dec 2015 22:15:41 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8EFE920204 for ; Mon, 14 Dec 2015 22:15:40 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id A232B2021B for ; Mon, 14 Dec 2015 22:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932603AbbLNWPi (ORCPT ); Mon, 14 Dec 2015 17:15:38 -0500 Received: from mx6-phx2.redhat.com ([209.132.183.39]:57377 "EHLO mx6-phx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932273AbbLNWPi (ORCPT ); Mon, 14 Dec 2015 17:15:38 -0500 Received: from zmail22.collab.prod.int.phx2.redhat.com (zmail22.collab.prod.int.phx2.redhat.com [10.5.83.26]) by mx6-phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tBEMFb4I006933; Mon, 14 Dec 2015 17:15:37 -0500 Date: Mon, 14 Dec 2015 17:15:37 -0500 (EST) From: Frank Sorenson To: linux-nfs@vger.kernel.org Cc: Steve Dickson Message-ID: <371875408.30231785.1450131337790.JavaMail.zimbra@redhat.com> In-Reply-To: <1054854128.30230518.1450131093639.JavaMail.zimbra@redhat.com> Subject: fix mountd netgroup lookup for short hostnames MIME-Version: 1.0 X-Originating-IP: [10.10.116.28] X-Mailer: Zimbra 8.0.6_GA_5922 (ZimbraWebClient - GC42 (Linux)/8.0.6_GA_5922) Thread-Topic: fix mountd netgroup lookup for short hostnames Thread-Index: taGFnOQ6fep5MPQRcy20znwQJzr0CA== Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Commit 9a92ef6f194926904b1289e0ce1daecb42bd5e8b to add netgroup lookup of resolvable IP addresses inadvertently broke the netgroup check for short hostnames by clobbering the 'hname' variable. This patch fixes that breakage by changing the IP address lookup to use a separate variable. The 'hname' variable used in the short hostname lookup is now untouched in the IP lookup code. Author: Frank Sorenson Date: Mon Dec 14 15:50:30 2015 -0600 mountd: fix netgroup lookup for short hostnames Commit 9a92ef6f194926904b1289e0ce1daecb42bd5e8b to add netgroup lookup of resolvable IP addresses inadvertently broke the netgroup check for short hostnames. This patch fixes that breakage by changing the IP address lookup to use a separate variable. Signed-off-by: Frank Sorenson --- To unsubscribe from this list: send the line "unsubscribe linux-nfs" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/support/export/client.c b/support/export/client.c index af9e6bb..2346f99 100644 --- a/support/export/client.c +++ b/support/export/client.c @@ -639,7 +639,7 @@ check_netgroup(const nfs_client *clp, const struct addrinfo *ai) const char *netgroup = clp->m_hostname + 1; struct addrinfo *tmp = NULL; struct hostent *hp; - char *dot, *hname; + char *dot, *hname, *ip; int i, match; match = 0; @@ -687,19 +687,16 @@ check_netgroup(const nfs_client *clp, const struct addrinfo *ai) } /* check whether the IP itself is in the netgroup */ - for (tmp = (struct addrinfo *)ai ; tmp != NULL ; tmp = tmp->ai_next) { - free(hname); - hname = calloc(INET6_ADDRSTRLEN, 1); - - if (inet_ntop(tmp->ai_family, &(((struct sockaddr_in *)tmp->ai_addr)->sin_addr), hname, INET6_ADDRSTRLEN) != hname) { - xlog(D_GENERAL, " %s: unable to inet_ntop addrinfo %p: %m", __func__, tmp, errno); - goto out; - } - if (innetgr(netgroup, hname, NULL, NULL)) { + ip = calloc(INET6_ADDRSTRLEN, 1); + if (inet_ntop(ai->ai_family, &(((struct sockaddr_in *)ai->ai_addr)->sin_addr), ip, INET6_ADDRSTRLEN) == ip) { + if (innetgr(netgroup, ip, NULL, NULL)) { + free(hname); + hname = ip; match = 1; goto out; } } + free(ip); /* Okay, strip off the domain (if we have one) */ dot = strchr(hname, '.');