Skip to content

Commit

Permalink
Merge pull request proftpd#1293 from proftpd/rewrite-libidn2-issue1286
Browse files Browse the repository at this point in the history
Issue proftpd#1286: Add support for libidn2, an alternative to libidna, for …
  • Loading branch information
Castaglia authored Aug 19, 2021
2 parents 20e4878 + 5f61ac0 commit 97c6642
Show file tree
Hide file tree
Showing 5 changed files with 100 additions and 8 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ jobs:
yum install -y GeoIP-devel
# for mod_ldap
yum install -y openldap-devel cyrus-sasl-devel
# for mod_rewrite
yum install -y libidn2-devel
# for memcache support
yum install -y libmemcached-devel
# for redis support
Expand Down Expand Up @@ -133,6 +135,8 @@ jobs:
apt-get install -y libldap2-dev libsasl2-dev
# for mod_ldap runtime support for SCRAM
apt-get install -y libsasl2-modules-gssapi-mit
# for mod_rewrite
apt-get install -y libidn2-dev
# for memcache support
apt-get install -y libmemcached-dev
# for redis support
Expand Down
6 changes: 6 additions & 0 deletions config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@
/* Define if you have the iconv function. */
#undef HAVE_ICONV

/* Define if you have the idn2_to_ascii_8z function. */
#undef HAVE_IDN2_TO_ASCII_8Z

/* Define if you have the idna_to_ascii_8z function. */
#undef HAVE_IDNA_TO_ASCII_8Z

Expand Down Expand Up @@ -693,6 +696,9 @@
/* Define if you have the <iconv.h> header file. */
#undef HAVE_ICONV_H

/* Define if you have the <idn2.h> header file. */
#undef HAVE_IDN2_H

/* Define if you have the <idna.h> header file. */
#undef HAVE_IDNA_H

Expand Down
43 changes: 42 additions & 1 deletion configure
Original file line number Diff line number Diff line change
Expand Up @@ -19758,7 +19758,7 @@ fi
done


for ac_header in netinet/tcp.h arpa/inet.h idna.h libintl.h
for ac_header in netinet/tcp.h arpa/inet.h idn2.h idna.h libintl.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
Expand Down Expand Up @@ -21285,6 +21285,47 @@ fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for idn2_to_ascii_8z" >&5
$as_echo_n "checking for idn2_to_ascii_8z... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */

#include <sys/types.h>
#ifdef HAVE_IDN2_H
# include <idn2.h>
#endif

int
main ()
{

int flags = 0, res = 0;
const char *input = NULL;
char *output = NULL;
res = idn2_to_ascii_8z(input, &output, flags);

;
return 0;
}
_ACEOF
if ac_fn_c_try_compile "$LINENO"; then :

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
$as_echo "yes" >&6; }

$as_echo "#define HAVE_IDN2_TO_ASCII_8Z 1" >>confdefs.h

MAIN_LIBS="$MAIN_LIBS -lidn2"

else

{ $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
$as_echo "no" >&6; }


fi
rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext

{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for idna_to_ascii_8z" >&5
$as_echo_n "checking for idna_to_ascii_8z... " >&6; }
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
Expand Down
26 changes: 25 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -1715,7 +1715,7 @@ AC_CHECK_HEADERS(netinet/ip.h,,,
]
])

AC_CHECK_HEADERS(netinet/tcp.h arpa/inet.h idna.h libintl.h)
AC_CHECK_HEADERS(netinet/tcp.h arpa/inet.h idn2.h idna.h libintl.h)
AC_CHECK_HEADERS(regex.h sys/stat.h errno.h sys/termios.h sys/termio.h)
AC_CHECK_HEADERS(sys/statfs.h sys/statvfs.h sys/un.h sys/vfs.h sys/select.h)
AC_CHECK_HEADERS(termios.h dirent.h ndir.h sys/ndir.h sys/dir.h vmsdir.h)
Expand Down Expand Up @@ -1952,6 +1952,30 @@ AC_TRY_LINK(
]
)

AC_MSG_CHECKING([for idn2_to_ascii_8z])
AC_TRY_COMPILE(
[
#include <sys/types.h>
#ifdef HAVE_IDN2_H
# include <idn2.h>
#endif
],
[
int flags = 0, res = 0;
const char *input = NULL;
char *output = NULL;
res = idn2_to_ascii_8z(input, &output, flags);
],
[
AC_MSG_RESULT(yes)
AC_DEFINE(HAVE_IDN2_TO_ASCII_8Z, 1, [Define if you have idn2_to_ascii_8z])
MAIN_LIBS="$MAIN_LIBS -lidn2"
],
[
AC_MSG_RESULT(no)
]
)

AC_MSG_CHECKING([for idna_to_ascii_8z])
AC_TRY_COMPILE(
[
Expand Down
29 changes: 23 additions & 6 deletions contrib/mod_rewrite.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* ProFTPD: mod_rewrite -- a module for rewriting FTP commands
* Copyright (c) 2001-2020 TJ Saunders
* Copyright (c) 2001-2021 TJ Saunders
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -27,11 +27,15 @@
#include "conf.h"
#include "privs.h"

#ifdef HAVE_IDNA_H
#if defined(HAVE_IDNA_H)
# include <idna.h>
#endif /* HAVE_IDNA_H */

#define MOD_REWRITE_VERSION "mod_rewrite/1.0"
#if defined(HAVE_IDN2_H)
# include <idn2.h>
#endif /* HAVE_IDN2_H */

#define MOD_REWRITE_VERSION "mod_rewrite/1.1"

/* Make sure the version of proftpd is as necessary. */
#if PROFTPD_VERSION_NUMBER < 0x0001030701
Expand Down Expand Up @@ -2034,7 +2038,8 @@ static char *rewrite_map_int_utf8trans(pool *map_pool, char *key) {
return NULL;
}

#if defined(HAVE_IDNA_H) && defined(HAVE_IDNA_TO_ASCII_8Z)
#if (defined(HAVE_IDNA_H) && defined(HAVE_IDNA_TO_ASCII_8Z)) || \
(defined(HAVE_IDN2_H) && defined(HAVE_IDN2_TO_ASCII_8Z))
static char *rewrite_map_int_idnatrans(pool *map_pool, char *key) {
int flags = 0, res;
char *ascii_val = NULL, *map_val = NULL;
Expand All @@ -2045,6 +2050,16 @@ static char *rewrite_map_int_idnatrans(pool *map_pool, char *key) {
return NULL;
}

# if defined(HAVE_IDN2_H) && defined(HAVE_IDN2_TO_ASCII_8Z)
flags = IDN2_NFC_INPUT|IDN2_NONTRANSITIONAL;
res = idn2_to_ascii_8z(key, &ascii_val, flags);
if (res != IDN2_OK) {
rewrite_log("rewrite_map_int_idnatrans(): failed transforming IDN2 "
"'%s' to ASCII: %s", key, idn2_strerror(res));
return NULL;
}

# elif defined(HAVE_IDNA_H) && defined(HAVE_IDNA_TO_ASCII_8Z)
/* TODO: Should we enforce the use of e.g. the IDNA_USE_STD3_ASCII_RULES
* flag?
*/
Expand All @@ -2054,13 +2069,14 @@ static char *rewrite_map_int_idnatrans(pool *map_pool, char *key) {
"'%s' to ASCII: %s", key, idna_strerror(res));
return NULL;
}
# endif /* IDNA support. */

map_val = pstrdup(map_pool, ascii_val);
free(ascii_val);

return map_val;
}
#endif /* IDNA support */
#endif /* IDNA or IDN2 support */

/* Rewrite logging functions */

Expand Down Expand Up @@ -2440,7 +2456,8 @@ MODRET set_rewritemap(cmd_rec *cmd) {
map = (void *) rewrite_map_int_utf8trans;

} else if (strcmp(mapsrc, "idnatrans") == 0) {
#if defined(HAVE_IDNA_H) && defined(HAVE_IDNA_TO_ASCII_8Z)
#if (defined(HAVE_IDNA_H) && defined(HAVE_IDNA_TO_ASCII_8Z)) || \
(defined(HAVE_IDN2_H) && defined(HAVE_IDN2_TO_ASCII_8Z))
map = (void *) rewrite_map_int_idnatrans;
#else
CONF_ERROR(cmd, pstrcat(cmd->tmp_pool,
Expand Down

0 comments on commit 97c6642

Please sign in to comment.