Improve PSL cookie checking

* configure.ac: Add --with-psl-file to set a PSL file
* src/cookies.c (check_domain_match): Load PSL_FILE with
  fallback to built-in data.

This change allows package maintainers to make Wget use the latest
PSL (DAFSA or plain text), without updating libpsl itself.

E.g. Debian now comes with a DAFSA binary within the 'publicsuffix'
package which allows very fast loading (no parsing or processing needed).
This commit is contained in:
Tim Rühsen 2016-08-11 15:16:24 +02:00
parent f4aeb41899
commit 262baeb113
2 changed files with 45 additions and 7 deletions

View File

@ -329,6 +329,11 @@ AS_IF([test "x$with_libpsl" != xno], [
]) ])
]) ])
# Check for custom PSL file
AC_ARG_WITH(psl-file,
AC_HELP_STRING([--with-psl-file=[PATH]], [path to PSL file (plain text or DAFSA)]),
PSL_FILE=$withval AC_DEFINE_UNQUOTED([PSL_FILE], ["$PSL_FILE"], [path to PSL file (plain text or DAFSA)]))
AS_IF([test x"$with_zlib" != xno], [ AS_IF([test x"$with_zlib" != xno], [
with_zlib=yes with_zlib=yes
PKG_CHECK_MODULES([ZLIB], zlib, [ PKG_CHECK_MODULES([ZLIB], zlib, [
@ -823,7 +828,7 @@ AC_MSG_NOTICE([Summary of build options:
Libs: $LIBS Libs: $LIBS
SSL: $with_ssl SSL: $with_ssl
Zlib: $with_zlib Zlib: $with_zlib
PSL: $with_libpsl PSL: $with_libpsl $PSL_FILE
Digest: $ENABLE_DIGEST Digest: $ENABLE_DIGEST
NTLM: $ENABLE_NTLM NTLM: $ENABLE_NTLM
OPIE: $ENABLE_OPIE OPIE: $ENABLE_OPIE

View File

@ -526,19 +526,52 @@ check_domain_match (const char *cookie_domain, const char *host)
{ {
#ifdef HAVE_LIBPSL #ifdef HAVE_LIBPSL
static int init_psl;
static const psl_ctx_t *psl;
char *cookie_domain_lower = NULL; char *cookie_domain_lower = NULL;
char *host_lower = NULL; char *host_lower = NULL;
const psl_ctx_t *psl;
int is_acceptable; int is_acceptable;
DEBUGP (("cdm: 1")); DEBUGP (("cdm: 1"));
if (!(psl = psl_builtin())) if (!init_psl)
{ {
DEBUGP (("\nlibpsl not built with a public suffix list. " init_psl = 1;
"Falling back to simple heuristics.\n"));
goto no_psl;
}
#ifdef PSL_FILE
/* If PSL_FILE is a DAFSA file, loading is very fast */
if ((psl = psl_load_file (PSL_FILE)))
goto have_psl;
DEBUGP (("\nPSL: %s not found or not readable. "
"Falling back to built-in data.\n", quote (PSL_FILE)));
#endif
if ((psl = psl_builtin ()) && !psl_builtin_outdated ())
goto have_psl;
DEBUGP (("\nPSL: built-in data outdated. "
"Trying to load data from %s.\n",
quote (psl_builtin_filename ())));
if ((psl = psl_load_file (psl_builtin_filename ())))
goto have_psl;
DEBUGP (("\nPSL: %s not found or not readable. "
"Falling back to built-in data.\n",
quote (psl_builtin_filename ())));
if (!(psl = psl_builtin ()))
{
DEBUGP (("\nPSL: libpsl not built with a public suffix list. "
"Falling back to simple heuristics.\n"));
goto no_psl;
}
}
else if (!psl)
goto no_psl;
have_psl:
if (psl_str_to_utf8lower (cookie_domain, NULL, NULL, &cookie_domain_lower) == PSL_SUCCESS && if (psl_str_to_utf8lower (cookie_domain, NULL, NULL, &cookie_domain_lower) == PSL_SUCCESS &&
psl_str_to_utf8lower (host, NULL, NULL, &host_lower) == PSL_SUCCESS) psl_str_to_utf8lower (host, NULL, NULL, &host_lower) == PSL_SUCCESS)
{ {