diff options
author | Thomas Haller <thaller@redhat.com> | 2023-05-02 11:08:19 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2023-05-02 11:42:55 +0200 |
commit | db3da65c6c3613f3ec8e3c8b2af991c4c9967ab0 (patch) | |
tree | 3ae04a6253ad84b8aad50ef70197d2417c88c7aa | |
parent | 4ddbf32f1bcc181b6e6a953bfcdfc39121692aa9 (diff) | |
download | NetworkManager-db3da65c6c3613f3ec8e3c8b2af991c4c9967ab0.tar.gz |
dns: refactor domain_is_valid() to combine #if blocks
-rw-r--r-- | src/core/dns/nm-dns-manager.c | 62 |
1 files changed, 32 insertions, 30 deletions
diff --git a/src/core/dns/nm-dns-manager.c b/src/core/dns/nm-dns-manager.c index 56c91aaa37..2eeb48f21a 100644 --- a/src/core/dns/nm-dns-manager.c +++ b/src/core/dns/nm-dns-manager.c @@ -177,40 +177,42 @@ domain_is_valid(const char *domain, gboolean reject_public_suffix, gboolean assume_any_tld_is_public) { -#if WITH_LIBPSL - /* ifdef to fall back to old API function on platforms with older LIBPSL */ -#ifdef PSL_TYPE_NO_STAR_RULE - int type = PSL_TYPE_ANY; -#endif -#endif - if (*domain == '\0') return FALSE; -#if WITH_LIBPSL - /* ifdef to fall back to old API function on platforms with older LIBPSL */ -#ifdef PSL_TYPE_NO_STAR_RULE - /* - * If we use PSL_TYPE_ANY, any TLD (top-level domain, i.e., domain - * with no dots) is considered *public* by the PSL library even if - * it is *not* on the official suffix list. This is the implicit - * behavior of the older API function psl_is_public_suffix(). - * To inhibit that and only deem TLDs explicitly listed in the PSL - * as public, we need to turn off the "prevailing star rule" with - * PSL_TYPE_NO_STAR_RULE. - * For documentation on psl_is_public_suffix2(), see: - * https://rockdaboot.github.io/libpsl/libpsl-Public-Suffix-List-functions.html#psl-is-public-suffix2 - * For more on the public suffix format, including wildcards: - * https://github.com/publicsuffix/list/wiki/Format#format - */ - if (!assume_any_tld_is_public) - type = PSL_TYPE_NO_STAR_RULE; - if (reject_public_suffix && psl_is_public_suffix2(psl_builtin(), domain, type)) - return FALSE; + + if (reject_public_suffix) { + int is_pub; + +#if !WITH_LIBPSL + /* Without libpsl, we cannot detect that the domain is a public suffix, we assume + * the domain is not and valid. */ + is_pub = FALSE; +#elif defined(PSL_TYPE_NO_STAR_RULE) + /* + * If we use PSL_TYPE_ANY, any TLD (top-level domain, i.e., domain + * with no dots) is considered *public* by the PSL library even if + * it is *not* on the official suffix list. This is the implicit + * behavior of the older API function psl_is_public_suffix(). + * To inhibit that and only deem TLDs explicitly listed in the PSL + * as public, we need to turn off the "prevailing star rule" with + * PSL_TYPE_NO_STAR_RULE. + * For documentation on psl_is_public_suffix2(), see: + * https://rockdaboot.github.io/libpsl/libpsl-Public-Suffix-List-functions.html#psl-is-public-suffix2 + * For more on the public suffix format, including wildcards: + * https://github.com/publicsuffix/list/wiki/Format#format + */ + is_pub = + psl_is_public_suffix2(psl_builtin(), + domain, + assume_any_tld_is_public ? PSL_TYPE_ANY : PSL_TYPE_NO_STAR_RULE); #else - if (reject_public_suffix && psl_is_public_suffix(psl_builtin(), domain)) - return FALSE; -#endif + is_pub = psl_is_public_suffix(psl_builtin(), domain); #endif + + if (is_pub) + return FALSE; + } + return TRUE; } |