HDFS-6456. NFS should throw error for invalid entry in dfs.nfs.exports.allowed.hosts. Contributed by Abhiraj Butala
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1610840 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4dcc08b656
commit
fb1f5bc618
@ -71,7 +71,16 @@ public static synchronized NfsExports getInstance(Configuration conf) {
|
||||
|
||||
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 @@ private static Match getMatch(String line) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -194,4 +194,16 @@ public void testMultiMatchers() throws Exception {
|
||||
} 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");
|
||||
}
|
||||
}
|
||||
|
@ -309,6 +309,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
|
||||
|
Loading…
Reference in New Issue
Block a user