From 313e9f4a9beb877f7b87e747d7539de731edea9f Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Tue, 15 Jul 2014 20:37:55 +0000 Subject: [PATCH] HDFS-6456. Merging change r1610840 from trunk git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/branch-2@1610843 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/hadoop/nfs/NfsExports.java | 25 ++++++++++++++----- .../org/apache/hadoop/nfs/TestNfsExports.java | 12 +++++++++ hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt | 3 +++ 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java index bf77dcd43cb..96286865385 100644 --- a/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java +++ b/hadoop-common-project/hadoop-nfs/src/main/java/org/apache/hadoop/nfs/NfsExports.java @@ -71,7 +71,16 @@ public class NfsExports { private static final Pattern CIDR_FORMAT_LONG = Pattern.compile(SLASH_FORMAT_LONG); - + + // Hostnames are composed of series of 'labels' concatenated with dots. + // Labels can be between 1-63 characters long, and can only take + // letters, digits & hyphens. They cannot start and end with hyphens. For + // more details, refer RFC-1123 & http://en.wikipedia.org/wiki/Hostname + private static final String LABEL_FORMAT = + "[a-zA-Z0-9]([a-zA-Z0-9\\-]{0,61}[a-zA-Z0-9])?"; + private static final Pattern HOSTNAME_FORMAT = + Pattern.compile("^(" + LABEL_FORMAT + "\\.)*" + LABEL_FORMAT + "$"); + static class AccessCacheEntry implements LightWeightCache.Entry{ private final String hostAddr; private AccessPrivilege access; @@ -381,10 +390,14 @@ public class NfsExports { LOG.debug("Using Regex match for '" + host + "' and " + privilege); } return new RegexMatch(privilege, host); + } else if (HOSTNAME_FORMAT.matcher(host).matches()) { + if (LOG.isDebugEnabled()) { + LOG.debug("Using exact match for '" + host + "' and " + privilege); + } + return new ExactMatch(privilege, host); + } else { + throw new IllegalArgumentException("Invalid hostname provided '" + host + + "'"); } - if (LOG.isDebugEnabled()) { - LOG.debug("Using exact match for '" + host + "' and " + privilege); - } - return new ExactMatch(privilege, host); } -} \ No newline at end of file +} diff --git a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java index bf8a227c82e..349e82adbad 100644 --- a/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java +++ b/hadoop-common-project/hadoop-nfs/src/test/java/org/apache/hadoop/nfs/TestNfsExports.java @@ -194,4 +194,16 @@ public class TestNfsExports { } while ((System.nanoTime() - startNanos) / NanosPerMillis < 5000); Assert.assertEquals(AccessPrivilege.NONE, ap); } + + @Test(expected=IllegalArgumentException.class) + public void testInvalidHost() { + NfsExports matcher = new NfsExports(CacheSize, ExpirationPeriod, + "foo#bar"); + } + + @Test(expected=IllegalArgumentException.class) + public void testInvalidSeparator() { + NfsExports matcher = new NfsExports(CacheSize, ExpirationPeriod, + "foo ro : bar rw"); + } } diff --git a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt index 24dae1ceee2..334da0923c4 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt +++ b/hadoop-hdfs-project/hadoop-hdfs/CHANGES.txt @@ -59,6 +59,9 @@ Release 2.6.0 - UNRELEASED HDFS-5809. BlockPoolSliceScanner and high speed hdfs appending make datanode to drop into infinite loop (cmccabe) + HDFS-6456. NFS should throw error for invalid entry in + dfs.nfs.exports.allowed.hosts (Abhiraj Butala via brandonli) + Release 2.5.0 - UNRELEASED INCOMPATIBLE CHANGES