diff options
author | Renato Botelho <renato@netgate.com> | 2015-09-21 17:45:06 -0300 |
---|---|---|
committer | Renato Botelho <renato@netgate.com> | 2015-09-21 17:45:06 -0300 |
commit | 841e800d7def5ff6ca12b7ab5da8e7878e20e55b (patch) | |
tree | 2f838f478c6805f4cf437c5634b2af4c6f5a3931 /src/etc | |
parent | 66fd7b47679187ddcfaf5852a55b2af15394f341 (diff) | |
parent | cc882a8b0cfee277ccef76f8964dd75adb481377 (diff) | |
download | pfsense-841e800d7def5ff6ca12b7ab5da8e7878e20e55b.zip pfsense-841e800d7def5ff6ca12b7ab5da8e7878e20e55b.tar.gz |
Merge pull request #1902 from dachande/feature/certmanager_san_wildcard_hostname
Diffstat (limited to 'src/etc')
-rw-r--r-- | src/etc/inc/util.inc | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/etc/inc/util.inc b/src/etc/inc/util.inc index b2c797b..627e6e8 100644 --- a/src/etc/inc/util.inc +++ b/src/etc/inc/util.inc @@ -830,12 +830,12 @@ function is_unqualified_hostname($hostname) { } /* returns true if $hostname is a valid hostname, with or without being a fully-qualified domain name. */ -function is_hostname($hostname) { +function is_hostname($hostname, $allow_wildcard=false) { if (!is_string($hostname)) { return false; } - if (is_domain($hostname)) { + if (is_domain($hostname, $allow_wildcard)) { if ((substr_count($hostname, ".") == 1) && ($hostname[strlen($hostname)-1] == ".")) { /* Only a single dot at the end like "test." - hosts cannot be directly in the root domain. */ return false; @@ -848,12 +848,17 @@ function is_hostname($hostname) { } /* returns true if $domain is a valid domain name */ -function is_domain($domain) { +function is_domain($domain, $allow_wildcard=false) { if (!is_string($domain)) { return false; } + if ($allow_wildcard) { + $domain_regex = '/^(?:(?:[a-z_0-9\*]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9])\.)*(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9\.])$/i'; + } else { + $domain_regex = '/^(?:(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9])\.)*(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9\.])$/i'; + } - if (preg_match('/^(?:(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9])\.)*(?:[a-z_0-9]|[a-z_0-9][a-z_0-9\-]*[a-z_0-9\.])$/i', $domain)) { + if (preg_match($domain_regex, $domain)) { return true; } else { return false; |