MCPcopy Create free account
hub / github.com/MariaDB/server / hostname_requires_resolving

Function hostname_requires_resolving

sql/sql_acl.cc:4742–4788  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4740*/
4741
4742bool hostname_requires_resolving(const char *hostname)
4743{
4744 if (!hostname)
4745 return FALSE;
4746
4747 /* Check if hostname is the localhost. */
4748
4749 if (hostname == my_localhost ||
4750 Lex_ident_host(Lex_cstring_strlen(hostname)).
4751 streq(Lex_cstring_strlen(my_localhost)))
4752 {
4753 return FALSE;
4754 }
4755
4756 /*
4757 If the string contains any of {':', '%', '_', '/'}, it is definitely
4758 not a host name:
4759 - ':' means that the string is an IPv6 address;
4760 - '%' or '_' means that the string is a pattern;
4761 - '/' means that the string is an IPv4 network address;
4762 */
4763
4764 for (const char *p= hostname; *p; ++p)
4765 {
4766 switch (*p) {
4767 case ':':
4768 case '%':
4769 case '_':
4770 case '/':
4771 return FALSE;
4772 }
4773 }
4774
4775 /*
4776 Now we have to tell a host name (ab.cd, 12.ab) from an IPv4 address
4777 (12.34.56.78). The assumption is that if the string contains only
4778 digits and dots, it is an IPv4 address. Otherwise -- a host name.
4779 */
4780
4781 for (const char *p= hostname; *p; ++p)
4782 {
4783 if (*p != '.' && !my_isdigit(&my_charset_latin1, *p))
4784 return TRUE; /* a "letter" has been found. */
4785 }
4786
4787 return FALSE; /* all characters are either dots or digits. */
4788}
4789
4790
4791/**

Callers 4

check_validityMethod · 0.85
acl_loadFunction · 0.85
grant_loadFunction · 0.85

Calls 3

Lex_ident_hostClass · 0.85
Lex_cstring_strlenClass · 0.85
streqMethod · 0.45

Tested by

no test coverage detected