Commit cdc1071b authored by Tigran Mkrtchyan's avatar Tigran Mkrtchyan
Browse files

nfs4: don't use InetAddresses.forString with catch block to validate IP address

as there is a corresponding  InetAddresses#isInetAddress. Drop extra
methods isValidIpAddress  and isValidHostName in favor of direct calling
corresponding methods from guava library.

Acked-by: Lea Morschel
Acked-by: Paul Millar
Target: master
parent c798bc1a
/* /*
* Copyright (c) 2009 - 2017 Deutsches Elektronen-Synchroton, * Copyright (c) 2009 - 2020 Deutsches Elektronen-Synchroton,
* Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
* *
* This library is free software; you can redistribute it and/or modify * This library is free software; you can redistribute it and/or modify
...@@ -515,25 +515,12 @@ public class FsExport { ...@@ -515,25 +515,12 @@ public class FsExport {
mask = s.substring(maskIdx + 1); mask = s.substring(maskIdx + 1);
} }
return (isValidIpAddress(host) && isValidNetmask(mask)) return (InetAddresses.isInetAddress(host) && isValidNetmask(mask))
|| (isValidHostName(host) || isValidWildcard(host)); || (InternetDomainName.isValid(host) || isValidWildcard(host));
}
private static boolean isValidIpAddress(String s) {
try {
InetAddresses.forString(s);
return true;
} catch (IllegalArgumentException e) {
}
return false;
}
private static boolean isValidHostName(String s) {
return InternetDomainName.isValid(s);
} }
private static boolean isValidWildcard(String s) { private static boolean isValidWildcard(String s) {
return isValidHostName(s.replace('?', 'a').replace('*', 'a')); return InternetDomainName.isValid(s.replace('?', 'a').replace('*', 'a'));
} }
private static boolean isValidNetmask(String s) { private static boolean isValidNetmask(String s) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment