Blame SOURCES/freeradius-fixes-to-python3-module-since-v3.0.20.patch

71fb5d
From 322f3b0d94f32e01e2db0c76fd38409eddf392ce Mon Sep 17 00:00:00 2001
71fb5d
From: Jorge Pereira <jpereiran@gmail.com>
71fb5d
Date: Thu, 5 Dec 2019 16:02:18 -0300
71fb5d
Subject: [PATCH] Fix rlm_python3 build
71fb5d
71fb5d
Just backporting from the master branch.
71fb5d
71fb5d
Backport from rlm_python (#3184) changes to rlm_python3
71fb5d
71fb5d
Brief:
71fb5d
71fb5d
We should append the 'python_path' to sys.path #3180
71fb5d
71fb5d
we should append 'python_path' paths in 'sys.path', due to PySys_SetPath()
71fb5d
reset the entire python path causing problems to use the existing libraries
71fb5d
71fb5d
Remove unnecessary src/modules/rlm_python3/radiusd_test.py
71fb5d
71fb5d
Don't call if 'instantiate' and 'detach' are not declared.
71fb5d
71fb5d
It's related to the discussion in #3185.
71fb5d
71fb5d
Fix missing destroy for some statements
71fb5d
71fb5d
Fix Py_SetProgramName() use (#3196)
71fb5d
71fb5d
As the documentation says, the use of Py_SetProgramName() with wchar_t*
71fb5d
should be only from Python >= 3.5.x
71fb5d
71fb5d
References:
71fb5d
71fb5d
Python <= 3.4.x https://docs.python.org/3.4/extending/embedding.html#very-high-level-embedding
71fb5d
Python >= 3.5.x https://docs.python.org/3.5/extending/embedding.html#very-high-level-embedding
71fb5d
71fb5d
Add missing 'ifdef WITH_PROXY' checks (#3198)
71fb5d
71fb5d
Clean up (#3197)
71fb5d
71fb5d
don't try and build rlm_python3 if we can't configure it
71fb5d
71fb5d
Just call Py_DECREF() (#3199)
71fb5d
71fb5d
Fix libpython3 cross platform load (#3284)
71fb5d
71fb5d
Python3 fixes (#3350)
71fb5d
71fb5d
* python3-config for Python 3.8 requires --embed parameter
71fb5d
71fb5d
As described in https://bugs.python.org/issue36721, python3-config now
71fb5d
requires --embed for embedded interpreters. Otherwise, -lpython3.8 is
71fb5d
not included in ldflags
71fb5d
71fb5d
* Python 3.8 has removed the "m" suffix in the library name
71fb5d
71fb5d
As discussed in: https://bugs.python.org/issue36707
71fb5d
71fb5d
* Use dl_iterate_phdr to find the appropriate python library
71fb5d
71fb5d
Otherwise, installation of the libpython3-dev packages is required
71fb5d
in most distributions
71fb5d
71fb5d
* Update configure file for rlm_python3
71fb5d
71fb5d
* Use AX_COMPARE_VERSION to check Python version
71fb5d
71fb5d
Keep the module directory in python_path
71fb5d
---
71fb5d
 raddb/mods-available/python             |    2 +-
71fb5d
 raddb/mods-available/python3            |    2 +-
71fb5d
 src/include/conf.h                      |    8 +
71fb5d
 src/main/modules.c                      |    8 -
71fb5d
 src/modules/rlm_python3/configure       | 1008 ++++++++---------------
71fb5d
 src/modules/rlm_python3/configure.ac    |  163 ++--
71fb5d
 src/modules/rlm_python3/radiusd_test.py |   63 --
71fb5d
 src/modules/rlm_python3/rlm_python3.c   |  188 ++---
71fb5d
 8 files changed, 516 insertions(+), 926 deletions(-)
71fb5d
 delete mode 100644 src/modules/rlm_python3/radiusd_test.py
71fb5d
71fb5d
diff --git a/raddb/mods-available/python b/raddb/mods-available/python
71fb5d
index bd172dca05..c19ddcd87e 100644
71fb5d
--- a/raddb/mods-available/python
71fb5d
+++ b/raddb/mods-available/python
71fb5d
@@ -13,7 +13,7 @@ python {
71fb5d
 	#  item is GLOBAL TO THE SERVER.  That is, you cannot have two
71fb5d
 	#  instances of the python module, each with a different path.
71fb5d
 	#
71fb5d
-#        python_path="/path/to/python/files:/another_path/to/python_files/"
71fb5d
+#        python_path="${modconfdir}/${.:name}:/path/to/python/files:/another_path/to/python_files/"
71fb5d
 
71fb5d
 	module = example
71fb5d
 
71fb5d
diff --git a/raddb/mods-available/python3 b/raddb/mods-available/python3
71fb5d
index 246dfd74ce..0593c69f1a 100644
71fb5d
--- a/raddb/mods-available/python3
71fb5d
+++ b/raddb/mods-available/python3
71fb5d
@@ -13,7 +13,7 @@ python3 {
71fb5d
 	#  item is GLOBAL TO THE SERVER.  That is, you cannot have two
71fb5d
 	#  instances of the python module, each with a different path.
71fb5d
 	#
71fb5d
-#        python_path="/path/to/python/files:/another_path/to/python_files/"
71fb5d
+#	python_path="${modconfdir}/${.:name}:/another_path/to/python_files"
71fb5d
 
71fb5d
 	module = example
71fb5d
 
71fb5d
diff --git a/src/include/conf.h b/src/include/conf.h
71fb5d
index 758a332b6e..95005d545f 100644
71fb5d
--- a/src/include/conf.h
71fb5d
+++ b/src/include/conf.h
71fb5d
@@ -13,3 +13,11 @@
71fb5d
 #define SRADUTMP		LOGDIR "/sradutmp"
71fb5d
 #define RADWTMP			LOGDIR "/radwtmp"
71fb5d
 #define SRADWTMP		LOGDIR "/sradwtmp"
71fb5d
+
71fb5d
+#ifdef __APPLE__
71fb5d
+#  define LT_SHREXT ".dylib"
71fb5d
+#elif defined (WIN32)
71fb5d
+#  define LT_SHREXT ".dll"
71fb5d
+#else
71fb5d
+#  define LT_SHREXT ".so"
71fb5d
+#endif
71fb5d
diff --git a/src/main/modules.c b/src/main/modules.c
71fb5d
index 319879c870..c05aa5bf67 100644
71fb5d
--- a/src/main/modules.c
71fb5d
+++ b/src/main/modules.c
71fb5d
@@ -95,14 +95,6 @@ const section_type_value_t section_type_value[MOD_COUNT] = {
71fb5d
 #define RTLD_LOCAL (0)
71fb5d
 #endif
71fb5d
 
71fb5d
-#ifdef __APPLE__
71fb5d
-#  define LT_SHREXT ".dylib"
71fb5d
-#elif defined (WIN32)
71fb5d
-#  define LT_SHREXT ".dll"
71fb5d
-#else
71fb5d
-#  define LT_SHREXT ".so"
71fb5d
-#endif
71fb5d
-
71fb5d
 /** Check if the magic number in the module matches the one in the library
71fb5d
  *
71fb5d
  * This is used to detect potential ABI issues caused by running with modules which
71fb5d
diff --git a/src/modules/rlm_python3/configure b/src/modules/rlm_python3/configure
71fb5d
index ff89a16149..05907f12c3 100755
71fb5d
--- a/src/modules/rlm_python3/configure
71fb5d
+++ b/src/modules/rlm_python3/configure
71fb5d
@@ -588,7 +588,17 @@ LIBOBJS
71fb5d
 targetname
71fb5d
 mod_cflags
71fb5d
 mod_ldflags
71fb5d
-PYTHON3_BIN
71fb5d
+AWK
71fb5d
+PYTHON3_CONFIG_BIN
71fb5d
+pkgpyexecdir
71fb5d
+pyexecdir
71fb5d
+pkgpythondir
71fb5d
+pythondir
71fb5d
+PYTHON_PLATFORM
71fb5d
+PYTHON_EXEC_PREFIX
71fb5d
+PYTHON_PREFIX
71fb5d
+PYTHON_VERSION
71fb5d
+PYTHON
71fb5d
 CPP
71fb5d
 OBJEXT
71fb5d
 EXEEXT
71fb5d
@@ -638,9 +648,7 @@ SHELL'
71fb5d
 ac_subst_files=''
71fb5d
 ac_user_opts='
71fb5d
 enable_option_checking
71fb5d
-with_rlm_python3_bin
71fb5d
-with_rlm_python3_lib_dir
71fb5d
-with_rlm_python3_include_dir
71fb5d
+with_rlm_python3_config_bin
71fb5d
 '
71fb5d
       ac_precious_vars='build_alias
71fb5d
 host_alias
71fb5d
@@ -650,7 +658,8 @@ CFLAGS
71fb5d
 LDFLAGS
71fb5d
 LIBS
71fb5d
 CPPFLAGS
71fb5d
-CPP'
71fb5d
+CPP
71fb5d
+PYTHON'
71fb5d
 
71fb5d
 
71fb5d
 # Initialize some variables set by options.
71fb5d
@@ -1257,9 +1266,7 @@ if test -n "$ac_init_help"; then
71fb5d
 Optional Packages:
71fb5d
   --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
71fb5d
   --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
71fb5d
-  --with-rlm-python3-bin=PATH   Path to python3 binary
71fb5d
-  --with-rlm-python3-lib-dir=DIR       Directory for Python library files
71fb5d
-  --with-rlm-python3-include-dir=DIR   Directory for Python include files
71fb5d
+  --with-rlm-python3-config-bin=PATH   Path to python-config3 binary
71fb5d
 
71fb5d
 Some influential environment variables:
71fb5d
   CC          C compiler command
71fb5d
@@ -1270,6 +1277,7 @@ Some influential environment variables:
71fb5d
   CPPFLAGS    (Objective) C/C++ preprocessor flags, e.g. -I<include dir> if
71fb5d
               you have headers in a nonstandard directory <include dir>
71fb5d
   CPP         C preprocessor
71fb5d
+  PYTHON      the Python interpreter
71fb5d
 
71fb5d
 Use these variables to override the choices made by `configure' or to help
71fb5d
 it to find libraries and programs with nonstandard names/locations.
71fb5d
@@ -2822,46 +2830,92 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
71fb5d
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
71fb5d
 
71fb5d
 
71fb5d
-		PYTHON3_BIN=
71fb5d
 
71fb5d
-# Check whether --with-rlm-python3-bin was given.
71fb5d
-if test "${with_rlm_python3_bin+set}" = set; then :
71fb5d
-  withval=$with_rlm_python3_bin;  case "$withval" in
71fb5d
-	    no)
71fb5d
-		as_fn_error $? "Need rlm-python3-bin" "$LINENO" 5
71fb5d
-		;;
71fb5d
-	    yes)
71fb5d
-		;;
71fb5d
-	    *)
71fb5d
-		PYTHON3_BIN="$withval"
71fb5d
-		;;
71fb5d
-	  esac
71fb5d
 
71fb5d
-fi
71fb5d
 
71fb5d
 
71fb5d
-	if test "x$PYTHON3_BIN" = x; then
71fb5d
-		for ac_prog in  python3
71fb5d
-do
71fb5d
-  # Extract the first word of "$ac_prog", so it can be a program name with args.
71fb5d
-set dummy $ac_prog; ac_word=$2
71fb5d
+
71fb5d
+        if test -n "$PYTHON"; then
71fb5d
+      # If the user set $PYTHON, use it and don't search something else.
71fb5d
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether $PYTHON version is >= 3.0" >&5
71fb5d
+$as_echo_n "checking whether $PYTHON version is >= 3.0... " >&6; }
71fb5d
+      prog="import sys
71fb5d
+# split strings by '.' and convert to numeric.  Append some zeros
71fb5d
+# because we need at least 4 digits for the hex conversion.
71fb5d
+# map returns an iterator in Python 3.0 and a list in 2.x
71fb5d
+minver = list(map(int, '3.0'.split('.'))) + [0, 0, 0]
71fb5d
+minverhex = 0
71fb5d
+# xrange is not present in Python 3.0 and range returns an iterator
71fb5d
+for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[i]
71fb5d
+sys.exit(sys.hexversion < minverhex)"
71fb5d
+  if { echo "$as_me:$LINENO: $PYTHON -c "$prog"" >&5
71fb5d
+   ($PYTHON -c "$prog") >&5 2>&5
71fb5d
+   ac_status=$?
71fb5d
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
71fb5d
+   (exit $ac_status); }; then :
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
+$as_echo "yes" >&6; }
71fb5d
+else
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
+$as_echo "no" >&6; }
71fb5d
+			       as_fn_error $? "Python interpreter is too old" "$LINENO" 5
71fb5d
+fi
71fb5d
+      am_display_PYTHON=$PYTHON
71fb5d
+    else
71fb5d
+      # Otherwise, try each interpreter until we find one that satisfies
71fb5d
+      # VERSION.
71fb5d
+      { $as_echo "$as_me:${as_lineno-$LINENO}: checking for a Python interpreter with version >= 3.0" >&5
71fb5d
+$as_echo_n "checking for a Python interpreter with version >= 3.0... " >&6; }
71fb5d
+if ${am_cv_pathless_PYTHON+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
+else
71fb5d
+
71fb5d
+	for am_cv_pathless_PYTHON in python python2 python3  python3.9 python3.8 python3.7 python3.6 python3.5 python3.4 python3.3  python3.2 python3.1 python3.0  python2.7 python2.6 python2.5 python2.4 python2.3 python2.2 python2.1  python2.0 none; do
71fb5d
+	  test "$am_cv_pathless_PYTHON" = none && break
71fb5d
+	  prog="import sys
71fb5d
+# split strings by '.' and convert to numeric.  Append some zeros
71fb5d
+# because we need at least 4 digits for the hex conversion.
71fb5d
+# map returns an iterator in Python 3.0 and a list in 2.x
71fb5d
+minver = list(map(int, '3.0'.split('.'))) + [0, 0, 0]
71fb5d
+minverhex = 0
71fb5d
+# xrange is not present in Python 3.0 and range returns an iterator
71fb5d
+for i in list(range(0, 4)): minverhex = (minverhex << 8) + minver[i]
71fb5d
+sys.exit(sys.hexversion < minverhex)"
71fb5d
+  if { echo "$as_me:$LINENO: $am_cv_pathless_PYTHON -c "$prog"" >&5
71fb5d
+   ($am_cv_pathless_PYTHON -c "$prog") >&5 2>&5
71fb5d
+   ac_status=$?
71fb5d
+   echo "$as_me:$LINENO: \$? = $ac_status" >&5
71fb5d
+   (exit $ac_status); }; then :
71fb5d
+  break
71fb5d
+fi
71fb5d
+	done
71fb5d
+fi
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_pathless_PYTHON" >&5
71fb5d
+$as_echo "$am_cv_pathless_PYTHON" >&6; }
71fb5d
+      # Set $PYTHON to the absolute path of $am_cv_pathless_PYTHON.
71fb5d
+      if test "$am_cv_pathless_PYTHON" = none; then
71fb5d
+	PYTHON=:
71fb5d
+      else
71fb5d
+        # Extract the first word of "$am_cv_pathless_PYTHON", so it can be a program name with args.
71fb5d
+set dummy $am_cv_pathless_PYTHON; ac_word=$2
71fb5d
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
71fb5d
 $as_echo_n "checking for $ac_word... " >&6; }
71fb5d
-if ${ac_cv_prog_PYTHON3_BIN+:} false; then :
71fb5d
+if ${ac_cv_path_PYTHON+:} false; then :
71fb5d
   $as_echo_n "(cached) " >&6
71fb5d
 else
71fb5d
-  if test -n "$PYTHON3_BIN"; then
71fb5d
-  ac_cv_prog_PYTHON3_BIN="$PYTHON3_BIN" # Let the user override the test.
71fb5d
-else
71fb5d
-as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
71fb5d
-as_dummy="${PATH}:/usr/bin:/usr/local/bin"
71fb5d
-for as_dir in $as_dummy
71fb5d
+  case $PYTHON in
71fb5d
+  [\\/]* | ?:[\\/]*)
71fb5d
+  ac_cv_path_PYTHON="$PYTHON" # Let the user override the test with a path.
71fb5d
+  ;;
71fb5d
+  *)
71fb5d
+  as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
71fb5d
+for as_dir in $PATH
71fb5d
 do
71fb5d
   IFS=$as_save_IFS
71fb5d
   test -z "$as_dir" && as_dir=.
71fb5d
     for ac_exec_ext in '' $ac_executable_extensions; do
71fb5d
   if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
71fb5d
-    ac_cv_prog_PYTHON3_BIN="$ac_prog"
71fb5d
+    ac_cv_path_PYTHON="$as_dir/$ac_word$ac_exec_ext"
71fb5d
     $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
71fb5d
     break 2
71fb5d
   fi
71fb5d
@@ -2869,708 +2923,358 @@ done
71fb5d
   done
71fb5d
 IFS=$as_save_IFS
71fb5d
 
71fb5d
+  ;;
71fb5d
+esac
71fb5d
 fi
71fb5d
-fi
71fb5d
-PYTHON3_BIN=$ac_cv_prog_PYTHON3_BIN
71fb5d
-if test -n "$PYTHON3_BIN"; then
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON3_BIN" >&5
71fb5d
-$as_echo "$PYTHON3_BIN" >&6; }
71fb5d
+PYTHON=$ac_cv_path_PYTHON
71fb5d
+if test -n "$PYTHON"; then
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON" >&5
71fb5d
+$as_echo "$PYTHON" >&6; }
71fb5d
 else
71fb5d
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
 $as_echo "no" >&6; }
71fb5d
 fi
71fb5d
 
71fb5d
 
71fb5d
-  test -n "$PYTHON3_BIN" && break
71fb5d
-done
71fb5d
-test -n "$PYTHON3_BIN" || PYTHON3_BIN="not-found"
71fb5d
-
71fb5d
-	fi
71fb5d
-
71fb5d
-	if test "x$PYTHON3_BIN" = "xnot-found"; then
71fb5d
-		fail="python-binary"
71fb5d
-	fi
71fb5d
-
71fb5d
-		PY_LIB_DIR=
71fb5d
-
71fb5d
-# Check whether --with-rlm-python3-lib-dir was given.
71fb5d
-if test "${with_rlm_python3_lib_dir+set}" = set; then :
71fb5d
-  withval=$with_rlm_python3_lib_dir;  case "$withval" in
71fb5d
-	    no)
71fb5d
-		as_fn_error $? "Need rlm-python3-lib-dir" "$LINENO" 5
71fb5d
-		;;
71fb5d
-	    yes)
71fb5d
-		;;
71fb5d
-	    *)
71fb5d
-		PY_LIB_DIR="$withval"
71fb5d
-		;;
71fb5d
-	  esac
71fb5d
-
71fb5d
-fi
71fb5d
+      fi
71fb5d
+      am_display_PYTHON=$am_cv_pathless_PYTHON
71fb5d
+    fi
71fb5d
 
71fb5d
 
71fb5d
-		PY_INC_DIR=
71fb5d
+  if test "$PYTHON" = :; then
71fb5d
+      :
71fb5d
+  else
71fb5d
 
71fb5d
-# Check whether --with-rlm-python3-include-dir was given.
71fb5d
-if test "${with_rlm_python3_include_dir+set}" = set; then :
71fb5d
-  withval=$with_rlm_python3_include_dir;  case "$withval" in
71fb5d
-	    no)
71fb5d
-		as_fn_error $? "Need rlm-python3-include-dir" "$LINENO" 5
71fb5d
-		;;
71fb5d
-	    yes)
71fb5d
-		;;
71fb5d
-	    *)
71fb5d
-		PY_INC_DIR="$withval"
71fb5d
-		;;
71fb5d
-	  esac
71fb5d
 
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON version" >&5
71fb5d
+$as_echo_n "checking for $am_display_PYTHON version... " >&6; }
71fb5d
+if ${am_cv_python_version+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
+else
71fb5d
+  am_cv_python_version=`$PYTHON -c "import sys; sys.stdout.write(sys.version[:3])"`
71fb5d
 fi
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_version" >&5
71fb5d
+$as_echo "$am_cv_python_version" >&6; }
71fb5d
+  PYTHON_VERSION=$am_cv_python_version
71fb5d
 
71fb5d
 
71fb5d
-	if test x$fail = x; then
71fb5d
-		PY_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.prefix)'`
71fb5d
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: Python sys.prefix \"${PY_PREFIX}\"" >&5
71fb5d
-$as_echo "$as_me: Python sys.prefix \"${PY_PREFIX}\"" >&6;}
71fb5d
-
71fb5d
-		PY_EXEC_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.exec_prefix)'`
71fb5d
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"" >&5
71fb5d
-$as_echo "$as_me: Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"" >&6;}
71fb5d
-
71fb5d
-		PY_SYS_VERSION=`${PYTHON3_BIN} -c 'import sys ; print(sys.version[0:3])'`
71fb5d
-		{ $as_echo "$as_me:${as_lineno-$LINENO}: Python sys.version \"${PY_SYS_VERSION}\"" >&5
71fb5d
-$as_echo "$as_me: Python sys.version \"${PY_SYS_VERSION}\"" >&6;}
71fb5d
-
71fb5d
-		if test "x$PY_LIB_DIR" = "x"; then
71fb5d
-			PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
71fb5d
-			PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
71fb5d
-		fi
71fb5d
-
71fb5d
-		PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config/Makefile"
71fb5d
-		if test -f ${PY_MAKEFILE}; then
71fb5d
-			PY_LOCAL_MOD_LIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/^ *//;s/ *$//'`
71fb5d
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"" >&5
71fb5d
-$as_echo "$as_me: Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"" >&6;}
71fb5d
-
71fb5d
-			PY_BASE_MOD_LIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/^ *//;s/ *$//'`
71fb5d
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"" >&5
71fb5d
-$as_echo "$as_me: Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"" >&6;}
71fb5d
-
71fb5d
-			PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
71fb5d
-			PY_OTHER_LDFLAGS=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[:blank:]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
71fb5d
-			{ $as_echo "$as_me:${as_lineno-$LINENO}: Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"" >&5
71fb5d
-$as_echo "$as_me: Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"" >&6;}
71fb5d
-		fi
71fb5d
-		PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASE_MOD_LIBS $PY_OTHER_LIBS"
71fb5d
-
71fb5d
-		old_CFLAGS=$CFLAGS
71fb5d
-		CFLAGS="$CFLAGS $PY_CFLAGS"
71fb5d
-		smart_try_dir="$PY_PREFIX/include/python$PY_SYS_VERSION"
71fb5d
-
71fb5d
 
71fb5d
+  PYTHON_PREFIX='${prefix}'
71fb5d
 
71fb5d
-ac_safe=`echo "Python.h" | sed 'y%./+-%__pm%'`
71fb5d
-old_CPPFLAGS="$CPPFLAGS"
71fb5d
-smart_include=
71fb5d
-smart_include_dir="/usr/local/include /opt/include"
71fb5d
+  PYTHON_EXEC_PREFIX='${exec_prefix}'
71fb5d
 
71fb5d
-_smart_try_dir=
71fb5d
-_smart_include_dir=
71fb5d
 
71fb5d
-for _prefix in $smart_prefix ""; do
71fb5d
-  for _dir in $smart_try_dir; do
71fb5d
-    _smart_try_dir="${_smart_try_dir} ${_dir}/${_prefix}"
71fb5d
-  done
71fb5d
-
71fb5d
-  for _dir in $smart_include_dir; do
71fb5d
-    _smart_include_dir="${_smart_include_dir} ${_dir}/${_prefix}"
71fb5d
-  done
71fb5d
-done
71fb5d
-
71fb5d
-if test "x$_smart_try_dir" != "x"; then
71fb5d
-  for try in $_smart_try_dir; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python.h in $try" >&5
71fb5d
-$as_echo_n "checking for Python.h in $try... " >&6; }
71fb5d
-    CPPFLAGS="-isystem $try $old_CPPFLAGS"
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-
71fb5d
-		    #include <Python.h>
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-int a = 1;
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_compile "$LINENO"; then :
71fb5d
-
71fb5d
-		     smart_include="-isystem $try"
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		     break
71fb5d
 
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON platform" >&5
71fb5d
+$as_echo_n "checking for $am_display_PYTHON platform... " >&6; }
71fb5d
+if ${am_cv_python_platform+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
 else
71fb5d
-
71fb5d
-		     smart_include=
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
-
71fb5d
-fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
71fb5d
-  done
71fb5d
-  CPPFLAGS="$old_CPPFLAGS"
71fb5d
-fi
71fb5d
-
71fb5d
-if test "x$smart_include" = "x"; then
71fb5d
-  for _prefix in $smart_prefix; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for ${_prefix}/Python.h" >&5
71fb5d
-$as_echo_n "checking for ${_prefix}/Python.h... " >&6; }
71fb5d
-
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-
71fb5d
-		    #include <Python.h>
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-int a = 1;
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_compile "$LINENO"; then :
71fb5d
-
71fb5d
-		     smart_include="-isystem ${_prefix}/"
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		     break
71fb5d
-
71fb5d
+  am_cv_python_platform=`$PYTHON -c "import sys; sys.stdout.write(sys.platform)"`
71fb5d
+fi
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_platform" >&5
71fb5d
+$as_echo "$am_cv_python_platform" >&6; }
71fb5d
+  PYTHON_PLATFORM=$am_cv_python_platform
71fb5d
+
71fb5d
+
71fb5d
+  # Just factor out some code duplication.
71fb5d
+  am_python_setup_sysconfig="\
71fb5d
+import sys
71fb5d
+# Prefer sysconfig over distutils.sysconfig, for better compatibility
71fb5d
+# with python 3.x.  See automake bug#10227.
71fb5d
+try:
71fb5d
+    import sysconfig
71fb5d
+except ImportError:
71fb5d
+    can_use_sysconfig = 0
71fb5d
+else:
71fb5d
+    can_use_sysconfig = 1
71fb5d
+# Can't use sysconfig in CPython 2.7, since it's broken in virtualenvs:
71fb5d
+# <https://github.com/pypa/virtualenv/issues/118>
71fb5d
+try:
71fb5d
+    from platform import python_implementation
71fb5d
+    if python_implementation() == 'CPython' and sys.version[:3] == '2.7':
71fb5d
+        can_use_sysconfig = 0
71fb5d
+except ImportError:
71fb5d
+    pass"
71fb5d
+
71fb5d
+
71fb5d
+            { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON script directory" >&5
71fb5d
+$as_echo_n "checking for $am_display_PYTHON script directory... " >&6; }
71fb5d
+if ${am_cv_python_pythondir+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
 else
71fb5d
+  if test "x$prefix" = xNONE
71fb5d
+     then
71fb5d
+       am_py_prefix=$ac_default_prefix
71fb5d
+     else
71fb5d
+       am_py_prefix=$prefix
71fb5d
+     fi
71fb5d
+     am_cv_python_pythondir=`$PYTHON -c "
71fb5d
+$am_python_setup_sysconfig
71fb5d
+if can_use_sysconfig:
71fb5d
+    sitedir = sysconfig.get_path('purelib', vars={'base':'$am_py_prefix'})
71fb5d
+else:
71fb5d
+    from distutils import sysconfig
71fb5d
+    sitedir = sysconfig.get_python_lib(0, 0, prefix='$am_py_prefix')
71fb5d
+sys.stdout.write(sitedir)"`
71fb5d
+     case $am_cv_python_pythondir in
71fb5d
+     $am_py_prefix*)
71fb5d
+       am__strip_prefix=`echo "$am_py_prefix" | sed 's|.|.|g'`
71fb5d
+       am_cv_python_pythondir=`echo "$am_cv_python_pythondir" | sed "s,^$am__strip_prefix,$PYTHON_PREFIX,"`
71fb5d
+       ;;
71fb5d
+     *)
71fb5d
+       case $am_py_prefix in
71fb5d
+         /usr|/System*) ;;
71fb5d
+         *)
71fb5d
+	  am_cv_python_pythondir=$PYTHON_PREFIX/lib/python$PYTHON_VERSION/site-packages
71fb5d
+	  ;;
71fb5d
+       esac
71fb5d
+       ;;
71fb5d
+     esac
71fb5d
 
71fb5d
-		     smart_include=
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
-
71fb5d
-fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
71fb5d
-  done
71fb5d
 fi
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_pythondir" >&5
71fb5d
+$as_echo "$am_cv_python_pythondir" >&6; }
71fb5d
+  pythondir=$am_cv_python_pythondir
71fb5d
 
71fb5d
-if test "x$smart_include" = "x"; then
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python.h" >&5
71fb5d
-$as_echo_n "checking for Python.h... " >&6; }
71fb5d
 
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
 
71fb5d
-		    #include <Python.h>
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-int a = 1;
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_compile "$LINENO"; then :
71fb5d
+  pkgpythondir=\${pythondir}/$PACKAGE
71fb5d
 
71fb5d
-		     smart_include=" "
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		     break
71fb5d
 
71fb5d
+        { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $am_display_PYTHON extension module directory" >&5
71fb5d
+$as_echo_n "checking for $am_display_PYTHON extension module directory... " >&6; }
71fb5d
+if ${am_cv_python_pyexecdir+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
 else
71fb5d
-
71fb5d
-		     smart_include=
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
+  if test "x$exec_prefix" = xNONE
71fb5d
+     then
71fb5d
+       am_py_exec_prefix=$am_py_prefix
71fb5d
+     else
71fb5d
+       am_py_exec_prefix=$exec_prefix
71fb5d
+     fi
71fb5d
+     am_cv_python_pyexecdir=`$PYTHON -c "
71fb5d
+$am_python_setup_sysconfig
71fb5d
+if can_use_sysconfig:
71fb5d
+    sitedir = sysconfig.get_path('platlib', vars={'platbase':'$am_py_prefix'})
71fb5d
+else:
71fb5d
+    from distutils import sysconfig
71fb5d
+    sitedir = sysconfig.get_python_lib(1, 0, prefix='$am_py_prefix')
71fb5d
+sys.stdout.write(sitedir)"`
71fb5d
+     case $am_cv_python_pyexecdir in
71fb5d
+     $am_py_exec_prefix*)
71fb5d
+       am__strip_prefix=`echo "$am_py_exec_prefix" | sed 's|.|.|g'`
71fb5d
+       am_cv_python_pyexecdir=`echo "$am_cv_python_pyexecdir" | sed "s,^$am__strip_prefix,$PYTHON_EXEC_PREFIX,"`
71fb5d
+       ;;
71fb5d
+     *)
71fb5d
+       case $am_py_exec_prefix in
71fb5d
+         /usr|/System*) ;;
71fb5d
+         *)
71fb5d
+	   am_cv_python_pyexecdir=$PYTHON_EXEC_PREFIX/lib/python$PYTHON_VERSION/site-packages
71fb5d
+	   ;;
71fb5d
+       esac
71fb5d
+       ;;
71fb5d
+     esac
71fb5d
 
71fb5d
 fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
71fb5d
-fi
71fb5d
-
71fb5d
-if test "x$smart_include" = "x"; then
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $am_cv_python_pyexecdir" >&5
71fb5d
+$as_echo "$am_cv_python_pyexecdir" >&6; }
71fb5d
+  pyexecdir=$am_cv_python_pyexecdir
71fb5d
 
71fb5d
-  for prefix in $smart_prefix; do
71fb5d
 
71fb5d
 
71fb5d
-if test "x$LOCATE" != "x"; then
71fb5d
-        DIRS=
71fb5d
-  file="${_prefix}/${1}"
71fb5d
+  pkgpyexecdir=\${pyexecdir}/$PACKAGE
71fb5d
 
71fb5d
-  for x in `${LOCATE} $file 2>/dev/null`; do
71fb5d
-                                        base=`echo $x | sed "s%/${file}%%"`
71fb5d
-    if test "x$x" = "x$base"; then
71fb5d
-      continue;
71fb5d
-    fi
71fb5d
-
71fb5d
-    dir=`${DIRNAME} $x 2>/dev/null`
71fb5d
-                exclude=`echo ${dir} | ${GREP} /home`
71fb5d
-    if test "x$exclude" != "x"; then
71fb5d
-      continue
71fb5d
-    fi
71fb5d
-
71fb5d
-                    already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}`
71fb5d
-    if test "x$already" = "x"; then
71fb5d
-      DIRS="$DIRS $dir"
71fb5d
-    fi
71fb5d
-  done
71fb5d
-fi
71fb5d
 
71fb5d
-eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\""
71fb5d
 
71fb5d
-  done
71fb5d
+  fi
71fb5d
 
71fb5d
 
71fb5d
-if test "x$LOCATE" != "x"; then
71fb5d
-        DIRS=
71fb5d
-  file=Python.h
71fb5d
 
71fb5d
-  for x in `${LOCATE} $file 2>/dev/null`; do
71fb5d
-                                        base=`echo $x | sed "s%/${file}%%"`
71fb5d
-    if test "x$x" = "x$base"; then
71fb5d
-      continue;
71fb5d
-    fi
71fb5d
+		PYTHON3_CONFIG_BIN=
71fb5d
 
71fb5d
-    dir=`${DIRNAME} $x 2>/dev/null`
71fb5d
-                exclude=`echo ${dir} | ${GREP} /home`
71fb5d
-    if test "x$exclude" != "x"; then
71fb5d
-      continue
71fb5d
-    fi
71fb5d
+# Check whether --with-rlm-python3-config-bin was given.
71fb5d
+if test "${with_rlm_python3_config_bin+set}" = set; then :
71fb5d
+  withval=$with_rlm_python3_config_bin;  case "$withval" in
71fb5d
+	    no)
71fb5d
+		as_fn_error $? "Need rlm-python3-config-bin" "$LINENO" 5
71fb5d
+		;;
71fb5d
+	    yes)
71fb5d
+		;;
71fb5d
+	    *)
71fb5d
+		PYTHON3_CONFIG_BIN="$withval"
71fb5d
+		;;
71fb5d
+	  esac
71fb5d
 
71fb5d
-                    already=`echo \$_smart_include_dir ${DIRS} | ${GREP} ${dir}`
71fb5d
-    if test "x$already" = "x"; then
71fb5d
-      DIRS="$DIRS $dir"
71fb5d
-    fi
71fb5d
-  done
71fb5d
 fi
71fb5d
 
71fb5d
-eval "_smart_include_dir=\"\$_smart_include_dir $DIRS\""
71fb5d
-
71fb5d
-
71fb5d
-  for try in $_smart_include_dir; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Python.h in $try" >&5
71fb5d
-$as_echo_n "checking for Python.h in $try... " >&6; }
71fb5d
-    CPPFLAGS="-isystem $try $old_CPPFLAGS"
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-
71fb5d
-		    #include <Python.h>
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-int a = 1;
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_compile "$LINENO"; then :
71fb5d
-
71fb5d
-		     smart_include="-isystem $try"
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		     break
71fb5d
 
71fb5d
+	if test "x$PYTHON3_CONFIG_BIN" = x; then
71fb5d
+		for ac_prog in  python3-config
71fb5d
+do
71fb5d
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
71fb5d
+set dummy $ac_prog; ac_word=$2
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
71fb5d
+$as_echo_n "checking for $ac_word... " >&6; }
71fb5d
+if ${ac_cv_prog_PYTHON3_CONFIG_BIN+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
 else
71fb5d
-
71fb5d
-		     smart_include=
71fb5d
-		     { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
-
71fb5d
-fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext
71fb5d
+  if test -n "$PYTHON3_CONFIG_BIN"; then
71fb5d
+  ac_cv_prog_PYTHON3_CONFIG_BIN="$PYTHON3_CONFIG_BIN" # Let the user override the test.
71fb5d
+else
71fb5d
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
71fb5d
+as_dummy="${PATH}:/usr/bin:/usr/local/bin"
71fb5d
+for as_dir in $as_dummy
71fb5d
+do
71fb5d
+  IFS=$as_save_IFS
71fb5d
+  test -z "$as_dir" && as_dir=.
71fb5d
+    for ac_exec_ext in '' $ac_executable_extensions; do
71fb5d
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
71fb5d
+    ac_cv_prog_PYTHON3_CONFIG_BIN="$ac_prog"
71fb5d
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
71fb5d
+    break 2
71fb5d
+  fi
71fb5d
+done
71fb5d
   done
71fb5d
-  CPPFLAGS="$old_CPPFLAGS"
71fb5d
-fi
71fb5d
-
71fb5d
-if test "x$smart_include" != "x"; then
71fb5d
-  eval "ac_cv_header_$ac_safe=yes"
71fb5d
-  CPPFLAGS="$smart_include $old_CPPFLAGS"
71fb5d
-  SMART_CPPFLAGS="$smart_include $SMART_CPPFLAGS"
71fb5d
-fi
71fb5d
-
71fb5d
-smart_prefix=
71fb5d
-
71fb5d
-		CFLAGS=$old_CFLAGS
71fb5d
-
71fb5d
-		if test "x$ac_cv_header_Python_h" = "xyes"; then
71fb5d
-			mod_cflags="$SMART_CPPFLAGS"
71fb5d
-		else
71fb5d
-			fail="$fail Python.h"
71fb5d
-			targetname=
71fb5d
-		fi
71fb5d
-
71fb5d
-		old_LIBS=$LIBS
71fb5d
-		LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
71fb5d
-		smart_try_dir=$PY_LIB_DIR
71fb5d
-
71fb5d
-
71fb5d
-sm_lib_safe=`echo "python${PY_SYS_VERSION}" | sed 'y%./+-%__p_%'`
71fb5d
-sm_func_safe=`echo "Py_Initialize" | sed 'y%./+-%__p_%'`
71fb5d
-
71fb5d
-old_LIBS="$LIBS"
71fb5d
-old_CPPFLAGS="$CPPFLAGS"
71fb5d
-smart_lib=
71fb5d
-smart_ldflags=
71fb5d
-smart_lib_dir=
71fb5d
-
71fb5d
-if test "x$smart_try_dir" != "x"; then
71fb5d
-  for try in $smart_try_dir; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try" >&5
71fb5d
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try... " >&6; }
71fb5d
-    LIBS="-lpython${PY_SYS_VERSION} $old_LIBS"
71fb5d
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-extern char Py_Initialize();
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-Py_Initialize()
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_link "$LINENO"; then :
71fb5d
-
71fb5d
-		 smart_lib="-lpython${PY_SYS_VERSION}"
71fb5d
-		 smart_ldflags="-L$try -Wl,-rpath,$try"
71fb5d
-		 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		 break
71fb5d
+IFS=$as_save_IFS
71fb5d
 
71fb5d
-else
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
 fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext \
71fb5d
-    conftest$ac_exeext conftest.$ac_ext
71fb5d
-  done
71fb5d
-  LIBS="$old_LIBS"
71fb5d
-  CPPFLAGS="$old_CPPFLAGS"
71fb5d
 fi
71fb5d
-
71fb5d
-if test "x$smart_lib" = "x"; then
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}" >&5
71fb5d
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}... " >&6; }
71fb5d
-  LIBS="-lpython${PY_SYS_VERSION} $old_LIBS"
71fb5d
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-extern char Py_Initialize();
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-Py_Initialize()
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_link "$LINENO"; then :
71fb5d
-
71fb5d
-	        smart_lib="-lpython${PY_SYS_VERSION}"
71fb5d
-	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-
71fb5d
+PYTHON3_CONFIG_BIN=$ac_cv_prog_PYTHON3_CONFIG_BIN
71fb5d
+if test -n "$PYTHON3_CONFIG_BIN"; then
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $PYTHON3_CONFIG_BIN" >&5
71fb5d
+$as_echo "$PYTHON3_CONFIG_BIN" >&6; }
71fb5d
 else
71fb5d
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
 $as_echo "no" >&6; }
71fb5d
 fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext \
71fb5d
-    conftest$ac_exeext conftest.$ac_ext
71fb5d
-  LIBS="$old_LIBS"
71fb5d
-fi
71fb5d
 
71fb5d
-if test "x$smart_lib" = "x"; then
71fb5d
 
71fb5d
+  test -n "$PYTHON3_CONFIG_BIN" && break
71fb5d
+done
71fb5d
+test -n "$PYTHON3_CONFIG_BIN" || PYTHON3_CONFIG_BIN="not-found"
71fb5d
 
71fb5d
-if test "x$LOCATE" != "x"; then
71fb5d
-        DIRS=
71fb5d
-  file=libpython${PY_SYS_VERSION}${libltdl_cv_shlibext}
71fb5d
-
71fb5d
-  for x in `${LOCATE} $file 2>/dev/null`; do
71fb5d
-                                        base=`echo $x | sed "s%/${file}%%"`
71fb5d
-    if test "x$x" = "x$base"; then
71fb5d
-      continue;
71fb5d
-    fi
71fb5d
-
71fb5d
-    dir=`${DIRNAME} $x 2>/dev/null`
71fb5d
-                exclude=`echo ${dir} | ${GREP} /home`
71fb5d
-    if test "x$exclude" != "x"; then
71fb5d
-      continue
71fb5d
-    fi
71fb5d
-
71fb5d
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
71fb5d
-    if test "x$already" = "x"; then
71fb5d
-      DIRS="$DIRS $dir"
71fb5d
-    fi
71fb5d
-  done
71fb5d
-fi
71fb5d
-
71fb5d
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
71fb5d
-
71fb5d
-
71fb5d
-
71fb5d
-if test "x$LOCATE" != "x"; then
71fb5d
-        DIRS=
71fb5d
-  file=libpython${PY_SYS_VERSION}.a
71fb5d
-
71fb5d
-  for x in `${LOCATE} $file 2>/dev/null`; do
71fb5d
-                                        base=`echo $x | sed "s%/${file}%%"`
71fb5d
-    if test "x$x" = "x$base"; then
71fb5d
-      continue;
71fb5d
-    fi
71fb5d
-
71fb5d
-    dir=`${DIRNAME} $x 2>/dev/null`
71fb5d
-                exclude=`echo ${dir} | ${GREP} /home`
71fb5d
-    if test "x$exclude" != "x"; then
71fb5d
-      continue
71fb5d
-    fi
71fb5d
-
71fb5d
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
71fb5d
-    if test "x$already" = "x"; then
71fb5d
-      DIRS="$DIRS $dir"
71fb5d
-    fi
71fb5d
-  done
71fb5d
-fi
71fb5d
-
71fb5d
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
71fb5d
-
71fb5d
-
71fb5d
-  for try in $smart_lib_dir /usr/local/lib /opt/lib; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try" >&5
71fb5d
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION} in $try... " >&6; }
71fb5d
-    LIBS="-lpython${PY_SYS_VERSION} $old_LIBS"
71fb5d
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-extern char Py_Initialize();
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-Py_Initialize()
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_link "$LINENO"; then :
71fb5d
-
71fb5d
-		  smart_lib="-lpython${PY_SYS_VERSION}"
71fb5d
-		  smart_ldflags="-L$try -Wl,-rpath,$try"
71fb5d
-		  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		  break
71fb5d
+	fi
71fb5d
 
71fb5d
+	if test "x$PYTHON3_CONFIG_BIN" = xnot-found; then
71fb5d
+		fail="$fail python3-config"
71fb5d
+	else
71fb5d
+								old_CFLAGS="$CFLAGS"
71fb5d
+		unset CFLAGS
71fb5d
+
71fb5d
+		python3_cflags=`${PYTHON3_CONFIG_BIN} --cflags`
71fb5d
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: ${PYTHON3_CONFIG_BIN}'s cflags were \"${python3_cflags}\"" >&5
71fb5d
+$as_echo "$as_me: ${PYTHON3_CONFIG_BIN}'s cflags were \"${python3_cflags}\"" >&6;}
71fb5d
+
71fb5d
+																mod_cflags=`echo $python3_cflags | sed -e '\
71fb5d
+			s/-I/-isystem/g;\
71fb5d
+			s/-isysroot[ =]\{0,1\}[^-]*//g;\
71fb5d
+			s/-O[^[[:blank:]]]*//g;\
71fb5d
+			s/-Wp,-D_FORTIFY_SOURCE=[[:digit:]]//g;\
71fb5d
+			s/-g[^ ]*//g;\
71fb5d
+			s/-W[^ ]*//g;\
71fb5d
+			s/-DNDEBUG[[:blank:]]*//g;
71fb5d
+			'`
71fb5d
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: Sanitized cflags were \"${mod_cflags}\"" >&5
71fb5d
+$as_echo "$as_me: Sanitized cflags were \"${mod_cflags}\"" >&6;}
71fb5d
+
71fb5d
+						for ac_prog in gawk mawk nawk awk
71fb5d
+do
71fb5d
+  # Extract the first word of "$ac_prog", so it can be a program name with args.
71fb5d
+set dummy $ac_prog; ac_word=$2
71fb5d
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5
71fb5d
+$as_echo_n "checking for $ac_word... " >&6; }
71fb5d
+if ${ac_cv_prog_AWK+:} false; then :
71fb5d
+  $as_echo_n "(cached) " >&6
71fb5d
 else
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
-fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext \
71fb5d
-    conftest$ac_exeext conftest.$ac_ext
71fb5d
+  if test -n "$AWK"; then
71fb5d
+  ac_cv_prog_AWK="$AWK" # Let the user override the test.
71fb5d
+else
71fb5d
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
71fb5d
+for as_dir in $PATH
71fb5d
+do
71fb5d
+  IFS=$as_save_IFS
71fb5d
+  test -z "$as_dir" && as_dir=.
71fb5d
+    for ac_exec_ext in '' $ac_executable_extensions; do
71fb5d
+  if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then
71fb5d
+    ac_cv_prog_AWK="$ac_prog"
71fb5d
+    $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5
71fb5d
+    break 2
71fb5d
+  fi
71fb5d
+done
71fb5d
   done
71fb5d
-  LIBS="$old_LIBS"
71fb5d
-  CPPFLAGS="$old_CPPFLAGS"
71fb5d
-fi
71fb5d
-
71fb5d
-if test "x$smart_lib" != "x"; then
71fb5d
-  eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
71fb5d
-  LIBS="$smart_ldflags $smart_lib $old_LIBS"
71fb5d
-  SMART_LIBS="$smart_ldflags $smart_lib $SMART_LIBS"
71fb5d
-fi
71fb5d
-
71fb5d
-		LIBS=$old_LIBS
71fb5d
-
71fb5d
-		eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
71fb5d
-		if test "x$t" = "xyes"; then
71fb5d
-			mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
71fb5d
-			targetname=rlm_python3
71fb5d
-		else
71fb5d
-
71fb5d
-
71fb5d
-sm_lib_safe=`echo "python${PY_SYS_VERSION}m" | sed 'y%./+-%__p_%'`
71fb5d
-sm_func_safe=`echo "Py_Initialize" | sed 'y%./+-%__p_%'`
71fb5d
-
71fb5d
-old_LIBS="$LIBS"
71fb5d
-old_CPPFLAGS="$CPPFLAGS"
71fb5d
-smart_lib=
71fb5d
-smart_ldflags=
71fb5d
-smart_lib_dir=
71fb5d
-
71fb5d
-if test "x$smart_try_dir" != "x"; then
71fb5d
-  for try in $smart_try_dir; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try" >&5
71fb5d
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try... " >&6; }
71fb5d
-    LIBS="-lpython${PY_SYS_VERSION}m $old_LIBS"
71fb5d
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-extern char Py_Initialize();
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-Py_Initialize()
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_link "$LINENO"; then :
71fb5d
-
71fb5d
-		 smart_lib="-lpython${PY_SYS_VERSION}m"
71fb5d
-		 smart_ldflags="-L$try -Wl,-rpath,$try"
71fb5d
-		 { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		 break
71fb5d
+IFS=$as_save_IFS
71fb5d
 
71fb5d
-else
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
 fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext \
71fb5d
-    conftest$ac_exeext conftest.$ac_ext
71fb5d
-  done
71fb5d
-  LIBS="$old_LIBS"
71fb5d
-  CPPFLAGS="$old_CPPFLAGS"
71fb5d
 fi
71fb5d
-
71fb5d
-if test "x$smart_lib" = "x"; then
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}m" >&5
71fb5d
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}m... " >&6; }
71fb5d
-  LIBS="-lpython${PY_SYS_VERSION}m $old_LIBS"
71fb5d
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-extern char Py_Initialize();
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-Py_Initialize()
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_link "$LINENO"; then :
71fb5d
-
71fb5d
-	        smart_lib="-lpython${PY_SYS_VERSION}m"
71fb5d
-	        { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-
71fb5d
+AWK=$ac_cv_prog_AWK
71fb5d
+if test -n "$AWK"; then
71fb5d
+  { $as_echo "$as_me:${as_lineno-$LINENO}: result: $AWK" >&5
71fb5d
+$as_echo "$AWK" >&6; }
71fb5d
 else
71fb5d
   { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
 $as_echo "no" >&6; }
71fb5d
 fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext \
71fb5d
-    conftest$ac_exeext conftest.$ac_ext
71fb5d
-  LIBS="$old_LIBS"
71fb5d
-fi
71fb5d
 
71fb5d
-if test "x$smart_lib" = "x"; then
71fb5d
 
71fb5d
+  test -n "$AWK" && break
71fb5d
+done
71fb5d
 
71fb5d
-if test "x$LOCATE" != "x"; then
71fb5d
-        DIRS=
71fb5d
-  file=libpython${PY_SYS_VERSION}m${libltdl_cv_shlibext}
71fb5d
 
71fb5d
-  for x in `${LOCATE} $file 2>/dev/null`; do
71fb5d
-                                        base=`echo $x | sed "s%/${file}%%"`
71fb5d
-    if test "x$x" = "x$base"; then
71fb5d
-      continue;
71fb5d
-    fi
71fb5d
 
71fb5d
-    dir=`${DIRNAME} $x 2>/dev/null`
71fb5d
-                exclude=`echo ${dir} | ${GREP} /home`
71fb5d
-    if test "x$exclude" != "x"; then
71fb5d
-      continue
71fb5d
-    fi
71fb5d
 
71fb5d
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
71fb5d
-    if test "x$already" = "x"; then
71fb5d
-      DIRS="$DIRS $dir"
71fb5d
-    fi
71fb5d
-  done
71fb5d
-fi
71fb5d
+  # Used to indicate true or false condition
71fb5d
+  ax_compare_version=false
71fb5d
 
71fb5d
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
71fb5d
+  # Convert the two version strings to be compared into a format that
71fb5d
+  # allows a simple string comparison.  The end result is that a version
71fb5d
+  # string of the form 1.12.5-r617 will be converted to the form
71fb5d
+  # 0001001200050617.  In other words, each number is zero padded to four
71fb5d
+  # digits, and non digits are removed.
71fb5d
 
71fb5d
+  ax_compare_version_A=`echo "${PYTHON_VERSION}" | sed -e 's/\([0-9]*\)/Z\1Z/g' \
71fb5d
+                     -e 's/Z\([0-9]\)Z/Z0\1Z/g' \
71fb5d
+                     -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \
71fb5d
+                     -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \
71fb5d
+                     -e 's/[^0-9]//g'`
71fb5d
 
71fb5d
 
71fb5d
-if test "x$LOCATE" != "x"; then
71fb5d
-        DIRS=
71fb5d
-  file=libpython${PY_SYS_VERSION}m.a
71fb5d
+  ax_compare_version_B=`echo "3.8" | sed -e 's/\([0-9]*\)/Z\1Z/g' \
71fb5d
+                     -e 's/Z\([0-9]\)Z/Z0\1Z/g' \
71fb5d
+                     -e 's/Z\([0-9][0-9]\)Z/Z0\1Z/g' \
71fb5d
+                     -e 's/Z\([0-9][0-9][0-9]\)Z/Z0\1Z/g' \
71fb5d
+                     -e 's/[^0-9]//g'`
71fb5d
 
71fb5d
-  for x in `${LOCATE} $file 2>/dev/null`; do
71fb5d
-                                        base=`echo $x | sed "s%/${file}%%"`
71fb5d
-    if test "x$x" = "x$base"; then
71fb5d
-      continue;
71fb5d
-    fi
71fb5d
 
71fb5d
-    dir=`${DIRNAME} $x 2>/dev/null`
71fb5d
-                exclude=`echo ${dir} | ${GREP} /home`
71fb5d
-    if test "x$exclude" != "x"; then
71fb5d
-      continue
71fb5d
-    fi
71fb5d
+    ax_compare_version=`echo "x$ax_compare_version_A
71fb5d
+x$ax_compare_version_B" | sed 's/^ *//' | sort -r | sed "s/x${ax_compare_version_A}/true/;s/x${ax_compare_version_B}/false/;1q"`
71fb5d
 
71fb5d
-                    already=`echo \$smart_lib_dir ${DIRS} | ${GREP} ${dir}`
71fb5d
-    if test "x$already" = "x"; then
71fb5d
-      DIRS="$DIRS $dir"
71fb5d
-    fi
71fb5d
-  done
71fb5d
-fi
71fb5d
 
71fb5d
-eval "smart_lib_dir=\"\$smart_lib_dir $DIRS\""
71fb5d
 
71fb5d
+    if test "$ax_compare_version" = "true" ; then
71fb5d
+    EMBED="--embed"
71fb5d
+      fi
71fb5d
 
71fb5d
-  for try in $smart_lib_dir /usr/local/lib /opt/lib; do
71fb5d
-    { $as_echo "$as_me:${as_lineno-$LINENO}: checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try" >&5
71fb5d
-$as_echo_n "checking for Py_Initialize in -lpython${PY_SYS_VERSION}m in $try... " >&6; }
71fb5d
-    LIBS="-lpython${PY_SYS_VERSION}m $old_LIBS"
71fb5d
-    CPPFLAGS="-L$try -Wl,-rpath,$try $old_CPPFLAGS"
71fb5d
-    cat confdefs.h - <<_ACEOF >conftest.$ac_ext
71fb5d
-/* end confdefs.h.  */
71fb5d
-extern char Py_Initialize();
71fb5d
-int
71fb5d
-main ()
71fb5d
-{
71fb5d
-Py_Initialize()
71fb5d
-  ;
71fb5d
-  return 0;
71fb5d
-}
71fb5d
-_ACEOF
71fb5d
-if ac_fn_c_try_link "$LINENO"; then :
71fb5d
 
71fb5d
-		  smart_lib="-lpython${PY_SYS_VERSION}m"
71fb5d
-		  smart_ldflags="-L$try -Wl,-rpath,$try"
71fb5d
-		  { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
71fb5d
-$as_echo "yes" >&6; }
71fb5d
-		  break
71fb5d
+		python3_ldflags=`${PYTHON3_CONFIG_BIN} --ldflags $EMBED`
71fb5d
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: ${PYTHON3_CONFIG_BIN}'s ldflags were \"$python3_ldflags}\"" >&5
71fb5d
+$as_echo "$as_me: ${PYTHON3_CONFIG_BIN}'s ldflags were \"$python3_ldflags}\"" >&6;}
71fb5d
 
71fb5d
-else
71fb5d
-  { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
71fb5d
-$as_echo "no" >&6; }
71fb5d
-fi
71fb5d
-rm -f core conftest.err conftest.$ac_objext \
71fb5d
-    conftest$ac_exeext conftest.$ac_ext
71fb5d
-  done
71fb5d
-  LIBS="$old_LIBS"
71fb5d
-  CPPFLAGS="$old_CPPFLAGS"
71fb5d
-fi
71fb5d
+										mod_ldflags=`echo $python3_ldflags | sed -e '\
71fb5d
+			s/-Wl,-O[[:digit:]][[:blank:]]*//g;\
71fb5d
+			s/-Wl,-Bsymbolic-functions[[:blank:]]*//g;\
71fb5d
+			s/-Xlinker -export-dynamic//g;\
71fb5d
+			s/-Wl,-stack_size,[[:digit:]]*[[:blank:]]//g;
71fb5d
+			'`
71fb5d
+		{ $as_echo "$as_me:${as_lineno-$LINENO}: Sanitized ldflags were \"${mod_ldflags}\"" >&5
71fb5d
+$as_echo "$as_me: Sanitized ldflags were \"${mod_ldflags}\"" >&6;}
71fb5d
 
71fb5d
-if test "x$smart_lib" != "x"; then
71fb5d
-  eval "ac_cv_lib_${sm_lib_safe}_${sm_func_safe}=yes"
71fb5d
-  LIBS="$smart_ldflags $smart_lib $old_LIBS"
71fb5d
-  SMART_LIBS="$smart_ldflags $smart_lib $SMART_LIBS"
71fb5d
-fi
71fb5d
+		CFLAGS=$old_CFLAGS
71fb5d
 
71fb5d
-			eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
71fb5d
-			if test "x$t" = "xyes"; then
71fb5d
-				mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
71fb5d
-				targetname=rlm_python3
71fb5d
-			else
71fb5d
-				targetname=
71fb5d
-				fail="$fail libpython$PY_SYS_VERSION"
71fb5d
-			fi
71fb5d
-		fi
71fb5d
+		targetname="rlm_python3"
71fb5d
 	fi
71fb5d
 
71fb5d
-	for ac_func in dl_iterate_phdr
71fb5d
+for ac_func in dl_iterate_phdr
71fb5d
 do :
71fb5d
   ac_fn_c_check_func "$LINENO" "dl_iterate_phdr" "ac_cv_func_dl_iterate_phdr"
71fb5d
 if test "x$ac_cv_func_dl_iterate_phdr" = xyes; then :
71fb5d
@@ -3603,11 +3307,7 @@ ac_config_headers="$ac_config_headers config.h"
71fb5d
 
71fb5d
 
71fb5d
 
71fb5d
-
71fb5d
-  unset ac_cv_env_LIBS_set
71fb5d
-  unset ac_cv_env_LIBS_value
71fb5d
-
71fb5d
-  ac_config_files="$ac_config_files all.mk"
71fb5d
+ac_config_files="$ac_config_files all.mk"
71fb5d
 
71fb5d
 cat >confcache <<\_ACEOF
71fb5d
 # This file is a shell script that caches the results of configure
71fb5d
@@ -4187,6 +3887,7 @@ gives unlimited permission to copy, distribute and modify it."
71fb5d
 
71fb5d
 ac_pwd='$ac_pwd'
71fb5d
 srcdir='$srcdir'
71fb5d
+AWK='$AWK'
71fb5d
 test -n "\$AWK" || AWK=awk
71fb5d
 _ACEOF
71fb5d
 
71fb5d
@@ -4881,4 +4582,3 @@ if test -n "$ac_unrecognized_opts" && test "$enable_option_checking" != no; then
71fb5d
 $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2;}
71fb5d
 fi
71fb5d
 
71fb5d
-
71fb5d
diff --git a/src/modules/rlm_python3/configure.ac b/src/modules/rlm_python3/configure.ac
71fb5d
index a00320fda4..698a8c1d18 100644
71fb5d
--- a/src/modules/rlm_python3/configure.ac
71fb5d
+++ b/src/modules/rlm_python3/configure.ac
71fb5d
@@ -7,128 +7,81 @@ if test x$with_[]modname != xno; then
71fb5d
 
71fb5d
 	AC_PROG_CC
71fb5d
 	AC_PROG_CPP
71fb5d
+	AM_PATH_PYTHON([3.0],, [:])
71fb5d
 
71fb5d
-	dnl extra argument: --with-rlm-python3-bin
71fb5d
-	PYTHON3_BIN=
71fb5d
-	AC_ARG_WITH(rlm-python3-bin,
71fb5d
-	[  --with-rlm-python3-bin=PATH   Path to python3 binary []],
71fb5d
+	dnl extra argument: --with-rlm-python3-config-bin
71fb5d
+	PYTHON3_CONFIG_BIN=
71fb5d
+	AC_ARG_WITH(rlm-python3-config-bin,
71fb5d
+	[  --with-rlm-python3-config-bin=PATH   Path to python-config3 binary []],
71fb5d
 	[ case "$withval" in
71fb5d
 	    no)
71fb5d
-		AC_MSG_ERROR(Need rlm-python3-bin)
71fb5d
+		AC_MSG_ERROR(Need rlm-python3-config-bin)
71fb5d
 		;;
71fb5d
 	    yes)
71fb5d
 		;;
71fb5d
 	    *)
71fb5d
-		PYTHON3_BIN="$withval"
71fb5d
+		PYTHON3_CONFIG_BIN="$withval"
71fb5d
 		;;
71fb5d
 	  esac ]
71fb5d
 	)
71fb5d
 
71fb5d
-	if test "x$PYTHON3_BIN" = x; then
71fb5d
-		AC_CHECK_PROGS(PYTHON3_BIN, [ python3 ], not-found, [${PATH}:/usr/bin:/usr/local/bin])
71fb5d
+	if test "x$PYTHON3_CONFIG_BIN" = x; then
71fb5d
+		AC_CHECK_PROGS(PYTHON3_CONFIG_BIN, [ python3-config ], not-found, [${PATH}:/usr/bin:/usr/local/bin])
71fb5d
 	fi
71fb5d
 
71fb5d
-	if test "x$PYTHON3_BIN" = "xnot-found"; then
71fb5d
-		fail="python-binary"
71fb5d
-	fi
71fb5d
-
71fb5d
-	dnl extra argument: --with-rlm-python3-lib-dir
71fb5d
-	PY_LIB_DIR=
71fb5d
-	AC_ARG_WITH(rlm-python3-lib-dir,
71fb5d
-	[  --with-rlm-python3-lib-dir=DIR       Directory for Python library files []],
71fb5d
-	[ case "$withval" in
71fb5d
-	    no)
71fb5d
-		AC_MSG_ERROR(Need rlm-python3-lib-dir)
71fb5d
-		;;
71fb5d
-	    yes)
71fb5d
-		;;
71fb5d
-	    *)
71fb5d
-		PY_LIB_DIR="$withval"
71fb5d
-		;;
71fb5d
-	  esac ]
71fb5d
-	)
71fb5d
-
71fb5d
-	dnl extra argument: --with-rlm-python3-include-dir
71fb5d
-	PY_INC_DIR=
71fb5d
-	AC_ARG_WITH(rlm-python3-include-dir,
71fb5d
-	[  --with-rlm-python3-include-dir=DIR   Directory for Python include files []],
71fb5d
-	[ case "$withval" in
71fb5d
-	    no)
71fb5d
-		AC_MSG_ERROR(Need rlm-python3-include-dir)
71fb5d
-		;;
71fb5d
-	    yes)
71fb5d
-		;;
71fb5d
-	    *)
71fb5d
-		PY_INC_DIR="$withval"
71fb5d
-		;;
71fb5d
-	  esac ]
71fb5d
-	)
71fb5d
-
71fb5d
-	if test x$fail = x; then
71fb5d
-		PY_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.prefix)'`
71fb5d
-		AC_MSG_NOTICE([Python sys.prefix \"${PY_PREFIX}\"])
71fb5d
-
71fb5d
-		PY_EXEC_PREFIX=`${PYTHON3_BIN} -c 'import sys ; print(sys.exec_prefix)'`
71fb5d
-		AC_MSG_NOTICE([Python sys.exec_prefix \"${PY_EXEC_PREFIX}\"])
71fb5d
-
71fb5d
-		PY_SYS_VERSION=`${PYTHON3_BIN} -c 'import sys ; print(sys.version[[0:3]])'`
71fb5d
-		AC_MSG_NOTICE([Python sys.version \"${PY_SYS_VERSION}\"])
71fb5d
-
71fb5d
-		if test "x$PY_LIB_DIR" = "x"; then
71fb5d
-			PY_LIB_DIR="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
71fb5d
-			PY_LIB_LOC="-L$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config"
71fb5d
-		fi
71fb5d
-
71fb5d
-		PY_MAKEFILE="$PY_EXEC_PREFIX/lib/python${PY_SYS_VERSION}/config/Makefile"
71fb5d
-		if test -f ${PY_MAKEFILE}; then
71fb5d
-			PY_LOCAL_MOD_LIBS=`sed -n -e 's/^LOCALMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/^ *//;s/ *$//'`
71fb5d
-			AC_MSG_NOTICE([Python local_mod_libs \"${PY_LOCAL_MOD_LIBS}\"])
71fb5d
-
71fb5d
-			PY_BASE_MOD_LIBS=`sed -n -e 's/^BASEMODLIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/^ *//;s/ *$//'`
71fb5d
-			AC_MSG_NOTICE([Python base_mod_libs \"${PY_BASE_MOD_LIBS}\"])
71fb5d
-
71fb5d
-			PY_OTHER_LIBS=`sed -n -e 's/^LIBS=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
71fb5d
-			PY_OTHER_LDFLAGS=`sed -n -e 's/^LINKFORSHARED=\(.*\)/\1/p' $PY_MAKEFILE | sed -e 's/[[[:blank:]]]/ /g;s/  / /g;s/^ *//;s/ *$//'`
71fb5d
-			AC_MSG_NOTICE([Python other_libs \"${PY_OTHER_LDFLAGS} ${PY_OTHER_LIBS}\"])
71fb5d
-		fi
71fb5d
-		PY_EXTRA_LIBS="$PY_LOCALMODLIBS $PY_BASE_MOD_LIBS $PY_OTHER_LIBS"
71fb5d
+	if test "x$PYTHON3_CONFIG_BIN" = xnot-found; then
71fb5d
+		fail="$fail python3-config"
71fb5d
+	else
71fb5d
+		dnl #
71fb5d
+		dnl # It is necessary due to a weird behavior with 'python3-config'
71fb5d
+		dnl #
71fb5d
+		old_CFLAGS="$CFLAGS"
71fb5d
+		unset CFLAGS
71fb5d
+
71fb5d
+		python3_cflags=`${PYTHON3_CONFIG_BIN} --cflags`
71fb5d
+		AC_MSG_NOTICE([${PYTHON3_CONFIG_BIN}'s cflags were \"${python3_cflags}\"])
71fb5d
+
71fb5d
+		dnl # Convert -I to -isystem to get rid of warnings about issues in Python headers
71fb5d
+		dnl # Strip -systemroot
71fb5d
+		dnl # Strip optimisation flags (-O[0-9]?). We decide our optimisation level, not python.
71fb5d
+		dnl # -D_FORTIFY_SOURCE needs -O.
71fb5d
+		dnl # Strip debug symbol flags (-g[0-9]?). We decide on debugging symbols, not python
71fb5d
+		dnl # Strip -W*, we decide what warnings are important
71fb5d
+		dnl # Strip -DNDEBUG
71fb5d
+		mod_cflags=`echo $python3_cflags | sed -e '\
71fb5d
+			s/-I/-isystem/g;\
71fb5d
+			s/-isysroot[[ =]]\{0,1\}[[^-]]*//g;\
71fb5d
+			s/-O[[^[[:blank:]]]]*//g;\
71fb5d
+			s/-Wp,-D_FORTIFY_SOURCE=[[[:digit:]]]//g;\
71fb5d
+			s/-g[[^ ]]*//g;\
71fb5d
+			s/-W[[^ ]]*//g;\
71fb5d
+			s/-DNDEBUG[[[:blank:]]]*//g;
71fb5d
+			'`
71fb5d
+		AC_MSG_NOTICE([Sanitized cflags were \"${mod_cflags}\"])
71fb5d
+
71fb5d
+		dnl # From python 3.8, --embed is required
71fb5d
+		dnl # https://bugs.python.org/issue36721
71fb5d
+		AX_COMPARE_VERSION(${PYTHON_VERSION}, [ge], [3.8], [EMBED="--embed"], [])
71fb5d
+
71fb5d
+		python3_ldflags=`${PYTHON3_CONFIG_BIN} --ldflags $EMBED`
71fb5d
+		AC_MSG_NOTICE([${PYTHON3_CONFIG_BIN}'s ldflags were \"$python3_ldflags}\"])
71fb5d
+
71fb5d
+		dnl # Strip -Wl,-O1... Is -O even a valid linker flag??
71fb5d
+		dnl # Strip -Wl,-Bsymbolic-functions as thats not always supported or required
71fb5d
+		dnl # Strip -Xlinker -export-dynamic as it causes weird linking issues on Linux
71fb5d
+		dnl #   See: https://bugs.python.org/issue36508
71fb5d
+		mod_ldflags=`echo $python3_ldflags | sed -e '\
71fb5d
+			s/-Wl,-O[[[:digit:]]][[[:blank:]]]*//g;\
71fb5d
+			s/-Wl,-Bsymbolic-functions[[[:blank:]]]*//g;\
71fb5d
+			s/-Xlinker -export-dynamic//g;\
71fb5d
+			s/-Wl,-stack_size,[[[:digit:]]]*[[[:blank:]]]//g;
71fb5d
+			'`
71fb5d
+		AC_MSG_NOTICE([Sanitized ldflags were \"${mod_ldflags}\"])
71fb5d
 
71fb5d
-		old_CFLAGS=$CFLAGS
71fb5d
-		CFLAGS="$CFLAGS $PY_CFLAGS"
71fb5d
-		smart_try_dir="$PY_PREFIX/include/python$PY_SYS_VERSION"
71fb5d
-		FR_SMART_CHECK_INCLUDE(Python.h)
71fb5d
 		CFLAGS=$old_CFLAGS
71fb5d
 
71fb5d
-		if test "x$ac_cv_header_Python_h" = "xyes"; then
71fb5d
-			mod_cflags="$SMART_CPPFLAGS"
71fb5d
-		else
71fb5d
-			fail="$fail Python.h"
71fb5d
-			targetname=
71fb5d
-		fi
71fb5d
-
71fb5d
-		old_LIBS=$LIBS
71fb5d
-		LIBS="$LIBS $PY_LIB_LOC $PY_EXTRA_LIBS -lm"
71fb5d
-		smart_try_dir=$PY_LIB_DIR
71fb5d
-		FR_SMART_CHECK_LIB(python${PY_SYS_VERSION}, Py_Initialize)
71fb5d
-		LIBS=$old_LIBS
71fb5d
-
71fb5d
-		eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
71fb5d
-		if test "x$t" = "xyes"; then
71fb5d
-			mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
71fb5d
-			targetname=modname
71fb5d
-		else
71fb5d
-			FR_SMART_CHECK_LIB(python${PY_SYS_VERSION}m, Py_Initialize)
71fb5d
-			eval t=\${ac_cv_lib_${sm_lib_safe}_${sm_func_safe}}
71fb5d
-			if test "x$t" = "xyes"; then
71fb5d
-				mod_ldflags="$PY_LIB_LOC $PY_EXTRA_LIBS $SMART_LIBS -lm"
71fb5d
-				targetname=modname
71fb5d
-			else
71fb5d
-				targetname=
71fb5d
-				fail="$fail libpython$PY_SYS_VERSION"
71fb5d
-			fi
71fb5d
-		fi
71fb5d
+		targetname="rlm_python3"
71fb5d
 	fi
71fb5d
-
71fb5d
 	AC_CHECK_FUNCS([dl_iterate_phdr])
71fb5d
 else
71fb5d
 	targetname=
71fb5d
diff --git a/src/modules/rlm_python3/radiusd_test.py b/src/modules/rlm_python3/radiusd_test.py
71fb5d
deleted file mode 100644
71fb5d
index 8582716ccb..0000000000
71fb5d
--- a/src/modules/rlm_python3/radiusd_test.py
71fb5d
+++ /dev/null
71fb5d
@@ -1,63 +0,0 @@
71fb5d
-#! /usr/bin/env python3
71fb5d
-#
71fb5d
-# Python module test
71fb5d
-# Miguel A.L. Paraz <mparaz@mparaz.com>
71fb5d
-#
71fb5d
-# $Id: 8582716ccbf340be00ce081ecf5ab078e93d1183 $
71fb5d
-
71fb5d
-import radiusd
71fb5d
-
71fb5d
-def instantiate(p):
71fb5d
-  print "*** instantiate ***"
71fb5d
-  print p
71fb5d
-
71fb5d
-def authorize(p):
71fb5d
-  print "*** authorize ***"
71fb5d
-  print
71fb5d
-  radiusd.radlog(radiusd.L_INFO, '*** radlog call in authorize ***')
71fb5d
-  print
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def preacct(p):
71fb5d
-  print "*** preacct ***"
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def accounting(p):
71fb5d
-  print "*** accounting ***"
71fb5d
-  radiusd.radlog(radiusd.L_INFO, '*** radlog call in accounting (0) ***')
71fb5d
-  print
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def pre_proxy(p):
71fb5d
-  print "*** pre_proxy ***"
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def post_proxy(p):
71fb5d
-  print "*** post_proxy ***"
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def post_auth(p):
71fb5d
-  print "*** post_auth ***"
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def recv_coa(p):
71fb5d
-  print "*** recv_coa ***"
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-def send_coa(p):
71fb5d
-  print "*** send_coa ***"
71fb5d
-  print p 
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
-
71fb5d
-def detach():
71fb5d
-  print "*** goodbye from radiusd_test.py ***"
71fb5d
-  return radiusd.RLM_MODULE_OK
71fb5d
-
71fb5d
diff --git a/src/modules/rlm_python3/rlm_python3.c b/src/modules/rlm_python3/rlm_python3.c
71fb5d
index 06187e4ffa..5da23f4d71 100644
71fb5d
--- a/src/modules/rlm_python3/rlm_python3.c
71fb5d
+++ b/src/modules/rlm_python3/rlm_python3.c
71fb5d
@@ -41,8 +41,17 @@ RCSID("$Id$")
71fb5d
 #include <link.h>
71fb5d
 #endif
71fb5d
 
71fb5d
+/*
71fb5d
+ * Since version 3.8, the "m" suffix is no longer available.
71fb5d
+ * https://bugs.python.org/issue36707
71fb5d
+ */
71fb5d
+#if PY_MINOR_VERSION >= 8
71fb5d
 #define LIBPYTHON_LINKER_NAME \
71fb5d
-	"libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) "m.so"
71fb5d
+	"libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) LT_SHREXT
71fb5d
+#else
71fb5d
+#define LIBPYTHON_LINKER_NAME \
71fb5d
+	"libpython" STRINGIFY(PY_MAJOR_VERSION) "." STRINGIFY(PY_MINOR_VERSION) "m" LT_SHREXT
71fb5d
+#endif
71fb5d
 
71fb5d
 static uint32_t		python_instances = 0;
71fb5d
 static void		*python_dlhandle;
71fb5d
@@ -67,8 +76,10 @@ static CONF_PARSER module_config[] = {
71fb5d
 	A(preacct)
71fb5d
 	A(accounting)
71fb5d
 	A(checksimul)
71fb5d
+#ifdef WITH_PROXY
71fb5d
 	A(pre_proxy)
71fb5d
 	A(post_proxy)
71fb5d
+#endif
71fb5d
 	A(post_auth)
71fb5d
 #ifdef WITH_COA
71fb5d
 	A(recv_coa)
71fb5d
@@ -98,7 +109,9 @@ static struct {
71fb5d
 	A(L_AUTH)
71fb5d
 	A(L_INFO)
71fb5d
 	A(L_ERR)
71fb5d
+#ifdef WITH_PROXY
71fb5d
 	A(L_PROXY)
71fb5d
+#endif
71fb5d
 	A(L_ACCT)
71fb5d
 	A(L_DBG_WARN)
71fb5d
 	A(L_DBG_ERR)
71fb5d
@@ -186,18 +199,16 @@ static void python_error_log(void)
71fb5d
 
71fb5d
 	if (!pExcType || !pExcValue) {
71fb5d
 		ERROR("%s:%d, Unknown error", __func__, __LINE__);
71fb5d
-		if (pExcType) {
71fb5d
-			Py_DecRef(pExcType);
71fb5d
-		}
71fb5d
-		if (pExcValue) {
71fb5d
-			Py_DecRef(pExcValue);
71fb5d
-		}
71fb5d
+		Py_XDECREF(pExcType);
71fb5d
+		Py_XDECREF(pExcValue);
71fb5d
 		return;
71fb5d
 	}
71fb5d
 
71fb5d
 	if (((pStr1 = PyObject_Str(pExcType)) != NULL) && 
71fb5d
 	    ((pStr2 = PyObject_Str(pExcValue)) != NULL)) {
71fb5d
 		ERROR("%s:%d, Exception type: %s, Exception value: %s", __func__, __LINE__, PyUnicode_AsUTF8(pStr1), PyUnicode_AsUTF8(pStr2));
71fb5d
+		Py_DECREF(pStr1);
71fb5d
+		Py_DECREF(pStr2);
71fb5d
 	} 
71fb5d
 
71fb5d
 	if (pExcTraceback) {
71fb5d
@@ -217,46 +228,23 @@ static void python_error_log(void)
71fb5d
 				char *str = PyBytes_AsString(pTraceString);
71fb5d
 				ERROR("%s:%d, full_backtrace: %s", __func__, __LINE__, str);
71fb5d
 
71fb5d
-				if (pyth_val) {
71fb5d
-					Py_DecRef(pyth_val);
71fb5d
-				}
71fb5d
-				if (pystr) {
71fb5d
-					Py_DecRef(pystr);
71fb5d
-				}
71fb5d
-				if (pTraceString) {
71fb5d
-					Py_DecRef(pTraceString);
71fb5d
-				}
71fb5d
+				Py_DECREF(pyth_val);
71fb5d
+				Py_DECREF(pystr);
71fb5d
+				Py_DECREF(pTraceString);
71fb5d
+				Py_DECREF(pyth_func);
71fb5d
 			}
71fb5d
-			if (pyth_func) {
71fb5d
-				Py_DecRef(pyth_func);
71fb5d
-			}
71fb5d
-			Py_DecRef(pyth_module);
71fb5d
+			Py_DECREF(pyth_module);
71fb5d
 		} else {
71fb5d
 			ERROR("%s:%d, py_module is null, name: %p", __func__, __LINE__, module_name);
71fb5d
 		}
71fb5d
 
71fb5d
-		if (module_name) {
71fb5d
-			Py_DecRef(module_name);
71fb5d
-		}
71fb5d
-
71fb5d
-		Py_DecRef(pRepr);
71fb5d
+		Py_DECREF(module_name);
71fb5d
+		Py_DECREF(pRepr);
71fb5d
+		Py_DECREF(pExcTraceback);
71fb5d
 	}
71fb5d
 
71fb5d
-	if (pExcType) {
71fb5d
-		Py_DecRef(pExcType);
71fb5d
-	}
71fb5d
-	if (pExcValue) {
71fb5d
-		Py_DecRef(pExcValue);
71fb5d
-	}
71fb5d
-	if (pExcTraceback) {
71fb5d
-		Py_DecRef(pExcTraceback);
71fb5d
-	}
71fb5d
-	if (pStr1) {
71fb5d
-		Py_DecRef(pStr1);
71fb5d
-	}
71fb5d
-	if (pStr2) {
71fb5d
-		Py_DecRef(pStr2);
71fb5d
-	}
71fb5d
+	Py_DECREF(pExcType);
71fb5d
+	Py_DECREF(pExcValue);
71fb5d
 }
71fb5d
 
71fb5d
 static void mod_vptuple(TALLOC_CTX *ctx, REQUEST *request, VALUE_PAIR **vps, PyObject *pValue,
71fb5d
@@ -510,6 +498,7 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
71fb5d
 			goto finish;
71fb5d
 		}
71fb5d
 
71fb5d
+#ifdef WITH_PROXY
71fb5d
 		/* fill proxy vps */
71fb5d
 		if (request->proxy) {
71fb5d
 			if (!mod_populate_vps(pArgs, 4, request->proxy->vps)) {
71fb5d
@@ -517,10 +506,13 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
71fb5d
 				ret = RLM_MODULE_FAIL;
71fb5d
 				goto finish;
71fb5d
 			}
71fb5d
-		} else {
71fb5d
+		} else
71fb5d
+#endif
71fb5d
+		{
71fb5d
 			mod_populate_vps(pArgs, 4, NULL);
71fb5d
 		}
71fb5d
 
71fb5d
+#ifdef WITH_PROXY
71fb5d
 		/* fill proxy_reply vps */
71fb5d
 		if (request->proxy_reply) {
71fb5d
 			if (!mod_populate_vps(pArgs, 5, request->proxy_reply->vps)) {
71fb5d
@@ -528,7 +520,9 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
71fb5d
 				ret = RLM_MODULE_FAIL;
71fb5d
 				goto finish;
71fb5d
 			}
71fb5d
-		} else {
71fb5d
+		} else
71fb5d
+#endif
71fb5d
+		{
71fb5d
 			mod_populate_vps(pArgs, 5, NULL);
71fb5d
 		}
71fb5d
 
71fb5d
@@ -550,9 +544,14 @@ static rlm_rcode_t do_python_single(REQUEST *request, PyObject *pFunc, char cons
71fb5d
 		    PyDict_SetItemString(pDictInput, "request", PyTuple_GET_ITEM(pArgs, 0)) ||
71fb5d
 		    PyDict_SetItemString(pDictInput, "reply", PyTuple_GET_ITEM(pArgs, 1)) ||
71fb5d
 		    PyDict_SetItemString(pDictInput, "config", PyTuple_GET_ITEM(pArgs, 2)) ||
71fb5d
-		    PyDict_SetItemString(pDictInput, "session-state", PyTuple_GET_ITEM(pArgs, 3)) ||
71fb5d
+		    PyDict_SetItemString(pDictInput, "session-state", PyTuple_GET_ITEM(pArgs, 3))
71fb5d
+#ifdef WITH_PROXY
71fb5d
+		    ||
71fb5d
 		    PyDict_SetItemString(pDictInput, "proxy-request", PyTuple_GET_ITEM(pArgs, 4)) ||
71fb5d
-		    PyDict_SetItemString(pDictInput, "proxy-reply", PyTuple_GET_ITEM(pArgs, 5))) {
71fb5d
+		    PyDict_SetItemString(pDictInput, "proxy-reply", PyTuple_GET_ITEM(pArgs, 5))
71fb5d
+#endif
71fb5d
+		    ) {
71fb5d
+
71fb5d
 			ERROR("%s:%d, %s - PyDict_SetItemString failed", __func__, __LINE__, funcname);
71fb5d
 			ret = RLM_MODULE_FAIL;
71fb5d
 			goto finish;
71fb5d
@@ -819,8 +818,10 @@ MOD_FUNC(authorize)
71fb5d
 MOD_FUNC(preacct)
71fb5d
 MOD_FUNC(accounting)
71fb5d
 MOD_FUNC(checksimul)
71fb5d
+#ifdef WITH_PROXY
71fb5d
 MOD_FUNC(pre_proxy)
71fb5d
 MOD_FUNC(post_proxy)
71fb5d
+#endif
71fb5d
 MOD_FUNC(post_auth)
71fb5d
 #ifdef WITH_COA
71fb5d
 MOD_FUNC(recv_coa)
71fb5d
@@ -1102,7 +1103,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
71fb5d
 		python_dlhandle = dlopen_libpython(RTLD_NOW | RTLD_GLOBAL);
71fb5d
 		if (!python_dlhandle) WARN("Failed loading libpython symbols into global symbol table");
71fb5d
 
71fb5d
-#if PY_VERSION_HEX > 0x03050000
71fb5d
+#if PY_VERSION_HEX >= 0x03050000
71fb5d
 		{
71fb5d
 			wchar_t  *name;
71fb5d
 
71fb5d
@@ -1110,13 +1111,6 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
71fb5d
 			Py_SetProgramName(name);		/* The value of argv[0] as a wide char string */
71fb5d
 			PyMem_RawFree(name);
71fb5d
 		}
71fb5d
-#elif PY_VERSION_HEX > 0x0300000
71fb5d
-		{
71fb5d
-			wchar_t *name;
71fb5d
-
71fb5d
-			MEM(name = _Py_char2wchar(main_config.name, NULL));
71fb5d
-			Py_SetProgramName(inst->wide_name);		/* The value of argv[0] as a wide char string */
71fb5d
-		}
71fb5d
 #else
71fb5d
 		{
71fb5d
 			char *name;
71fb5d
@@ -1163,37 +1157,34 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
71fb5d
 		 *	the lifetime of the module.
71fb5d
 		 */
71fb5d
 		if (inst->python_path) {
71fb5d
+			char *p, *path;
71fb5d
+			PyObject *sys = PyImport_ImportModule("sys");
71fb5d
+			PyObject *sys_path = PyObject_GetAttrString(sys, "path");
71fb5d
+
71fb5d
+			memcpy(&p, &inst->python_path, sizeof(path));
71fb5d
+
71fb5d
+			for (path = strtok(p, ":"); path != NULL; path = strtok(NULL, ":")) {
71fb5d
 #if PY_VERSION_HEX > 0x03050000
71fb5d
-			{
71fb5d
-				wchar_t *path;
71fb5d
-				PyObject* sys = PyImport_ImportModule("sys");
71fb5d
-				PyObject* sys_path = PyObject_GetAttrString(sys,"path");
71fb5d
-
71fb5d
-				MEM(path = Py_DecodeLocale(inst->python_path, NULL));
71fb5d
-				PyList_Append(sys_path, PyUnicode_FromWideChar(path,-1));				
71fb5d
-				PyObject_SetAttrString(sys,"path",sys_path);
71fb5d
-				PyMem_RawFree(path);
71fb5d
-			}
71fb5d
+				wchar_t *py_path;
71fb5d
+
71fb5d
+				MEM(py_path = Py_DecodeLocale(path, NULL));
71fb5d
+				PyList_Append(sys_path, PyUnicode_FromWideChar(py_path, -1));
71fb5d
+				PyMem_RawFree(py_path);
71fb5d
 #elif PY_VERSION_HEX > 0x03000000
71fb5d
-			{
71fb5d
-				wchar_t *path;
71fb5d
-				PyObject* sys = PyImport_ImportModule("sys");
71fb5d
-				PyObject* sys_path = PyObject_GetAttrString(sys,"path");
71fb5d
-
71fb5d
-				MEM(path = _Py_char2wchar(inst->python_path, NULL));
71fb5d
-				PyList_Append(sys_path, PyUnicode_FromWideChar(path,-1));				
71fb5d
-				PyObject_SetAttrString(sys,"path",sys_path);
71fb5d
-			}
71fb5d
-#else
71fb5d
-			{
71fb5d
-				char *path;
71fb5d
+				wchar_t *py_path;
71fb5d
 
71fb5d
-				memcpy(&path, &inst->python_path, sizeof(path));
71fb5d
-				Py_SetPath(path);
71fb5d
-			}
71fb5d
+				MEM(py_path = _Py_char2wchar(path, NULL));
71fb5d
+				PyList_Append(sys_path, PyUnicode_FromWideChar(py_path, -1));
71fb5d
+				PyMem_RawFree(py_path);
71fb5d
+#else
71fb5d
+				PyList_Append(sys_path, PyLong_FromString(path));
71fb5d
 #endif
71fb5d
-		}
71fb5d
+			}
71fb5d
 
71fb5d
+			PyObject_SetAttrString(sys, "path", sys_path);
71fb5d
+			Py_DecRef(sys);
71fb5d
+			Py_DecRef(sys_path);
71fb5d
+		}
71fb5d
 	} else {
71fb5d
 		inst->module = main_module;
71fb5d
 		Py_IncRef(inst->module);
71fb5d
@@ -1220,7 +1211,7 @@ static int python_interpreter_init(rlm_python_t *inst, CONF_SECTION *conf)
71fb5d
 static int mod_instantiate(CONF_SECTION *conf, void *instance)
71fb5d
 {
71fb5d
 	rlm_python_t	*inst = instance;
71fb5d
-	int		code = 0;
71fb5d
+	int		code = RLM_MODULE_OK;
71fb5d
 
71fb5d
 	inst->name = cf_section_name2(conf);
71fb5d
 	if (!inst->name) inst->name = cf_section_name1(conf);
71fb5d
@@ -1245,8 +1236,10 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
71fb5d
 	PYTHON_FUNC_LOAD(preacct);
71fb5d
 	PYTHON_FUNC_LOAD(accounting);
71fb5d
 	PYTHON_FUNC_LOAD(checksimul);
71fb5d
+#ifdef WITH_PROXY
71fb5d
 	PYTHON_FUNC_LOAD(pre_proxy);
71fb5d
 	PYTHON_FUNC_LOAD(post_proxy);
71fb5d
+#endif
71fb5d
 	PYTHON_FUNC_LOAD(post_auth);
71fb5d
 #ifdef WITH_COA
71fb5d
 	PYTHON_FUNC_LOAD(recv_coa);
71fb5d
@@ -1257,12 +1250,14 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
71fb5d
 	/*
71fb5d
 	 *	Call the instantiate function.
71fb5d
 	 */
71fb5d
-	code = do_python_single(NULL, inst->instantiate.function, "instantiate", inst->pass_all_vps, inst->pass_all_vps_dict);
71fb5d
-	if (code < 0) {
71fb5d
-	error:
71fb5d
-		python_error_log();	/* Needs valid thread with GIL */
71fb5d
-		PyEval_SaveThread();
71fb5d
-		return -1;
71fb5d
+	if (inst->instantiate.function) {
71fb5d
+		code = do_python_single(NULL, inst->instantiate.function, "instantiate", inst->pass_all_vps, inst->pass_all_vps_dict);
71fb5d
+		if (code < 0) {
71fb5d
+		error:
71fb5d
+			python_error_log();	/* Needs valid thread with GIL */
71fb5d
+			PyEval_SaveThread();
71fb5d
+			return -1;
71fb5d
+		}
71fb5d
 	}
71fb5d
 	PyEval_SaveThread();
71fb5d
 
71fb5d
@@ -1272,22 +1267,31 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
71fb5d
 static int mod_detach(void *instance)
71fb5d
 {
71fb5d
 	rlm_python_t *inst = instance;
71fb5d
-	int	     ret;
71fb5d
+	int	     ret = RLM_MODULE_OK;
71fb5d
 
71fb5d
 	/*
71fb5d
 	 *	Call module destructor
71fb5d
 	 */
71fb5d
 	PyEval_RestoreThread(inst->sub_interpreter);
71fb5d
 
71fb5d
-	ret = do_python_single(NULL, inst->detach.function, "detach", inst->pass_all_vps, inst->pass_all_vps_dict);
71fb5d
+	if (inst->detach.function) ret = do_python_single(NULL, inst->detach.function, "detach", inst->pass_all_vps, inst->pass_all_vps_dict);
71fb5d
 
71fb5d
 #define PYTHON_FUNC_DESTROY(_x) python_function_destroy(&inst->_x)
71fb5d
 	PYTHON_FUNC_DESTROY(instantiate);
71fb5d
-	PYTHON_FUNC_DESTROY(authorize);
71fb5d
 	PYTHON_FUNC_DESTROY(authenticate);
71fb5d
+	PYTHON_FUNC_DESTROY(authorize);
71fb5d
 	PYTHON_FUNC_DESTROY(preacct);
71fb5d
 	PYTHON_FUNC_DESTROY(accounting);
71fb5d
 	PYTHON_FUNC_DESTROY(checksimul);
71fb5d
+#ifdef WITH_PROXY
71fb5d
+	PYTHON_FUNC_DESTROY(pre_proxy);
71fb5d
+	PYTHON_FUNC_DESTROY(post_proxy);
71fb5d
+#endif
71fb5d
+	PYTHON_FUNC_DESTROY(post_auth);
71fb5d
+#ifdef WITH_COA
71fb5d
+	PYTHON_FUNC_DESTROY(recv_coa);
71fb5d
+	PYTHON_FUNC_DESTROY(send_coa);
71fb5d
+#endif
71fb5d
 	PYTHON_FUNC_DESTROY(detach);
71fb5d
 
71fb5d
 	Py_DecRef(inst->pythonconf_dict);
71fb5d
@@ -1313,14 +1317,8 @@ static int mod_detach(void *instance)
71fb5d
 		PyThreadState_Swap(main_interpreter); /* Swap to the main thread */
71fb5d
 		Py_Finalize();
71fb5d
 		dlclose(python_dlhandle);
71fb5d
-
71fb5d
-#if PY_VERSION_HEX > 0x03050000
71fb5d
-		//if (inst->wide_name) PyMem_RawFree(inst->wide_name);
71fb5d
-		//if (inst->wide_path) PyMem_RawFree(inst->wide_path);
71fb5d
-#endif
71fb5d
 	}
71fb5d
 
71fb5d
-
71fb5d
 	return ret;
71fb5d
 }
71fb5d
 
71fb5d
@@ -1348,8 +1346,10 @@ module_t rlm_python3 = {
71fb5d
 		[MOD_PREACCT]		= mod_preacct,
71fb5d
 		[MOD_ACCOUNTING]	= mod_accounting,
71fb5d
 		[MOD_SESSION]		= mod_checksimul,
71fb5d
+#ifdef WITH_PROXY
71fb5d
 		[MOD_PRE_PROXY]		= mod_pre_proxy,
71fb5d
 		[MOD_POST_PROXY]	= mod_post_proxy,
71fb5d
+#endif
71fb5d
 		[MOD_POST_AUTH]		= mod_post_auth,
71fb5d
 #ifdef WITH_COA
71fb5d
 		[MOD_RECV_COA]		= mod_recv_coa,
71fb5d
-- 
71fb5d
2.26.2
71fb5d