From patchwork Wed Aug 24 15:34:23 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chuck Lever X-Patchwork-Id: 1093112 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p7OFXmUJ002448 for ; Wed, 24 Aug 2011 15:34:31 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751655Ab1HXPe0 (ORCPT ); Wed, 24 Aug 2011 11:34:26 -0400 Received: from mail-ew0-f46.google.com ([209.85.215.46]:42819 "EHLO mail-ew0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751802Ab1HXPeZ (ORCPT ); Wed, 24 Aug 2011 11:34:25 -0400 Received: by mail-ew0-f46.google.com with SMTP id 4so527255ewy.19 for ; Wed, 24 Aug 2011 08:34:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=sender:from:subject:to:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; bh=SmnpxxZGoj9VnUllgqp35qHFv84s/Sq170a/KRaX4yY=; b=r2AGK/oWiEGyuQz4oEIi+ODKVtd4NreWaRpul8Mxgovq3Y+d3Ax1VMWFZgolcTvuNu b6kKHj02RPVMbmYRu9sN9EIKcSIq1dpSz2swMj9rfvDsgNCVNV61Pm6HWegT5GJxsCCS Za4ZPHDchNVnrnOkwfFkxm/4v88fVfsx5bLHQ= Received: by 10.213.31.82 with SMTP id x18mr1804736ebc.54.1314200065232; Wed, 24 Aug 2011 08:34:25 -0700 (PDT) Received: from matisse.1015granger.net (adsl-99-26-161-222.dsl.sfldmi.sbcglobal.net [99.26.161.222]) by mx.google.com with ESMTPS id 35sm764346eex.15.2011.08.24.08.34.24 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 24 Aug 2011 08:34:24 -0700 (PDT) From: Chuck Lever Subject: [PATCH 4/5] exportfs: matchhostname() doesn't handle localhost properly To: linux-nfs@vger.kernel.org Date: Wed, 24 Aug 2011 11:34:23 -0400 Message-ID: <20110824153422.3138.49458.stgit@matisse.1015granger.net> In-Reply-To: <20110824153024.3138.63294.stgit@matisse.1015granger.net> References: <20110824153024.3138.63294.stgit@matisse.1015granger.net> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: linux-nfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 24 Aug 2011 15:34:31 +0000 (UTC) Same change as statd_matchhostname() is necessary for the logic in exportfs. Recall that these are "separate but nearly equal" because the exportfs version requires extra expensive string checking that would be onerous for statd. Signed-off-by: Chuck Lever --- utils/exportfs/exportfs.c | 34 ++++++++++++++++++++++++++++++++-- 1 files changed, 32 insertions(+), 2 deletions(-) -- 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/utils/exportfs/exportfs.c b/utils/exportfs/exportfs.c index b107c7c..12e8bf1 100644 --- a/utils/exportfs/exportfs.c +++ b/utils/exportfs/exportfs.c @@ -448,6 +448,36 @@ is_hostname(const char *sp) return true; } +/* + * Take care to perform an explicit reverse lookup on presentation + * addresses. Otherwise we don't get a real canonical name or a + * complete list of addresses. + */ +static struct addrinfo * +address_list(const char *hostname) +{ + struct addrinfo *ai; + char *cname; + + ai = host_pton(hostname); + if (ai != NULL) { + /* @hostname was a presentation address */ + cname = host_canonname(ai->ai_addr); + freeaddrinfo(ai); + if (cname != NULL) + goto out; + } + /* @hostname was a hostname or had no reverse mapping */ + cname = strdup(hostname); + if (cname == NULL) + return NULL; + +out: + ai = host_addrinfo(cname); + free(cname); + return ai; +} + static int matchhostname(const char *hostname1, const char *hostname2) { @@ -464,10 +494,10 @@ matchhostname(const char *hostname1, const char *hostname2) if (!is_hostname(hostname1) || !is_hostname(hostname2)) return 0; - results1 = host_addrinfo(hostname1); + results1 = address_list(hostname1); if (results1 == NULL) goto out; - results2 = host_addrinfo(hostname2); + results2 = address_list(hostname2); if (results2 == NULL) goto out;