1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Fix inclusion of Lua headers. See #1355

We will need to do something similar for Ncat.
This commit is contained in:
dmiller
2018-10-16 05:18:31 +00:00
parent f836c164e0
commit a0f55317f3
19 changed files with 166 additions and 260 deletions

View File

@@ -1,5 +1,8 @@
#Nmap Changelog ($Id$); -*-text-*-
o [GH#1355] When searching for Lua header files, actually use them where they
are found instead of forcing /usr/include. [Fabrice Fontaine, Daniel Miller]
o [NSE][GH#1331] Script traceroute-geolocation no longer crashes when
www.GeoPlugin.net returns null coordinates [Michal Kubenka, nnposter]

View File

@@ -21,7 +21,6 @@ export NSOCKDIR=@NSOCKDIR@
export LIBLUADIR = @LIBLUADIR@
export LIBLINEARDIR = @LIBLINEARDIR@
export NDIR=$(shell pwd)
export LIBLUA_LIBS = @LIBLUA_LIBS@
export LIBLINEAR_LIBS = @LIBLINEAR_LIBS@
export NCATDIR=@NCATDIR@
CC = @CC@
@@ -91,7 +90,7 @@ UNINSTALLZENMAP=@UNINSTALLZENMAP@
UNINSTALLNDIFF=@UNINSTALLNDIFF@
UNINSTALLNPING=@UNINSTALLNPING@
ifneq (@LIBLUA_LIBS@,)
ifneq (@NOLUA@,yes)
NSE_SRC=nse_main.cc nse_utility.cc nse_nsock.cc nse_dnet.cc nse_fs.cc nse_nmaplib.cc nse_debug.cc nse_pcrelib.cc nse_lpeg.cc
NSE_HDRS=nse_main.h nse_utility.h nse_nsock.h nse_dnet.h nse_fs.h nse_nmaplib.h nse_debug.h nse_pcrelib.h nse_lpeg.h
NSE_OBJS=nse_main.o nse_utility.o nse_nsock.o nse_dnet.o nse_fs.o nse_nmaplib.o nse_debug.o nse_pcrelib.o nse_lpeg.o

269
configure vendored
View File

@@ -653,6 +653,7 @@ LUA_CLEAN
LUA_BUILD
LIBLUADIR
LIBLUA_LIBS
NOLUA
DNET_DIST_CLEAN
DNET_CLEAN
DNET_BUILD
@@ -2014,48 +2015,6 @@ $as_echo "$ac_res" >&6; }
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
} # ac_fn_c_check_func
# ac_fn_cxx_try_run LINENO
# ------------------------
# Try to link conftest.$ac_ext, and return whether this succeeded. Assumes
# that executables *can* be run.
ac_fn_cxx_try_run ()
{
as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack
if { { ac_try="$ac_link"
case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_link") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; } && { ac_try='./conftest$ac_exeext'
{ { case "(($ac_try" in
*\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
*) ac_try_echo=$ac_try;;
esac
eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\""
$as_echo "$ac_try_echo"; } >&5
(eval "$ac_try") 2>&5
ac_status=$?
$as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5
test $ac_status = 0; }; }; then :
ac_retval=0
else
$as_echo "$as_me: program exited with status $ac_status" >&5
$as_echo "$as_me: failed program was:" >&5
sed 's/^/| /' conftest.$ac_ext >&5
ac_retval=$ac_status
fi
rm -rf conftest.dSYM conftest_ipa8_conftest.oo
eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno
as_fn_set_status $ac_retval
} # ac_fn_cxx_try_run
cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
@@ -7079,6 +7038,8 @@ if test "${with_liblua+set}" = set; then :
LUA_DIST_CLEAN="distclean-lua"
have_lua="yes"
$as_echo "#define LUA_INCLUDED 1" >>confdefs.h
;;
no)
no_lua="yes"
@@ -7154,7 +7115,7 @@ fi
if test "$no_lua" = "yes"; then
trace_no_use="$trace_no_use lua"
CPPFLAGS="-DNOLUA $CPPFLAGS"
LIBLUA_LIBS=""
NOLUA="yes"
LUA_BUILD=""
LUA_CLEAN=""
LUA_DIST_CLEAN=""
@@ -7173,149 +7134,93 @@ if eval test \"x\$"$as_ac_Header"\" = x"yes"; then :
cat >>confdefs.h <<_ACEOF
#define `$as_echo "HAVE_$ac_header" | $as_tr_cpp` 1
_ACEOF
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lua_isyieldable in -llua5.3" >&5
$as_echo_n "checking for lua_isyieldable in -llua5.3... " >&6; }
if ${ac_cv_lib_lua5_3_lua_isyieldable+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-llua5.3 -lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char lua_isyieldable ();
int
main ()
{
return lua_isyieldable ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_lua5_3_lua_isyieldable=yes
else
ac_cv_lib_lua5_3_lua_isyieldable=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lua5_3_lua_isyieldable" >&5
$as_echo "$ac_cv_lib_lua5_3_lua_isyieldable" >&6; }
if test "x$ac_cv_lib_lua5_3_lua_isyieldable" = xyes; then :
have_lua=yes; LIBLUA_LIBS="-llua5.3"; CPPFLAGS="-I/usr/include/lua5.3 $CPPFLAGS"; break
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lua_isyieldable in -llua53" >&5
$as_echo_n "checking for lua_isyieldable in -llua53... " >&6; }
if ${ac_cv_lib_lua53_lua_isyieldable+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-llua53 -lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char lua_isyieldable ();
int
main ()
{
return lua_isyieldable ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_lua53_lua_isyieldable=yes
else
ac_cv_lib_lua53_lua_isyieldable=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lua53_lua_isyieldable" >&5
$as_echo "$ac_cv_lib_lua53_lua_isyieldable" >&6; }
if test "x$ac_cv_lib_lua53_lua_isyieldable" = xyes; then :
have_lua=yes; LIBLUA_LIBS="-llua53"; CPPFLAGS="-I/usr/include/lua53 $CPPFLAGS"; break
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lua_isyieldable in -llua" >&5
$as_echo_n "checking for lua_isyieldable in -llua... " >&6; }
if ${ac_cv_lib_lua_lua_isyieldable+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_check_lib_save_LIBS=$LIBS
LIBS="-llua -lm $LIBS"
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char lua_isyieldable ();
int
main ()
{
return lua_isyieldable ();
;
return 0;
}
_ACEOF
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_lib_lua_lua_isyieldable=yes
else
ac_cv_lib_lua_lua_isyieldable=no
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext conftest.$ac_ext
LIBS=$ac_check_lib_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_lua_lua_isyieldable" >&5
$as_echo "$ac_cv_lib_lua_lua_isyieldable" >&6; }
if test "x$ac_cv_lib_lua_lua_isyieldable" = xyes; then :
have_lua=yes; LIBLUA_LIBS="-llua"; CPPFLAGS="-I/usr/include/lua $CPPFLAGS"; break
fi
break
fi
done
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for library containing lua_isyieldable" >&5
$as_echo_n "checking for library containing lua_isyieldable... " >&6; }
if ${ac_cv_search_lua_isyieldable+:} false; then :
$as_echo_n "(cached) " >&6
else
ac_func_search_save_LIBS=$LIBS
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CXX -o conftest$ac_exeext $CXXFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_cxx_compiler_gnu
/* Override any GCC internal prototype to avoid an error.
Use char because int might match the return type of a GCC
builtin and then its argument prototype would still apply. */
#ifdef __cplusplus
extern "C"
#endif
char lua_isyieldable ();
int
main ()
{
return lua_isyieldable ();
;
return 0;
}
_ACEOF
for ac_lib in '' lua5.3 lua53 lua; do
if test -z "$ac_lib"; then
ac_res="none required"
else
ac_res=-l$ac_lib
LIBS="-l$ac_lib -lm $ac_func_search_save_LIBS"
fi
if ac_fn_c_try_link "$LINENO"; then :
ac_cv_search_lua_isyieldable=$ac_res
fi
rm -f core conftest.err conftest.$ac_objext \
conftest$ac_exeext
if ${ac_cv_search_lua_isyieldable+:} false; then :
break
fi
done
if ${ac_cv_search_lua_isyieldable+:} false; then :
# We need Lua 5.2 exactly
else
ac_cv_search_lua_isyieldable=no
fi
rm conftest.$ac_ext
LIBS=$ac_func_search_save_LIBS
fi
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_search_lua_isyieldable" >&5
$as_echo "$ac_cv_search_lua_isyieldable" >&6; }
ac_res=$ac_cv_search_lua_isyieldable
if test "$ac_res" != no; then :
test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
have_lua=yes
fi
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS >&5'
ac_compiler_gnu=$ac_cv_c_compiler_gnu
# We need Lua 5.3 exactly
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for lua version == 503" >&5
$as_echo_n "checking for lua version == 503... " >&6; }
if test "$cross_compiling" = yes; then :
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: cross-compiling -- assuming yes" >&5
$as_echo "cross-compiling -- assuming yes" >&6; }; have_lua=yes
else
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
/* end confdefs.h. */
#include <lua.h>
#ifdef HAVE_LUA5_3_LUA_H
#include <lua5.3/lua.h>
#elif defined HAVE_LUA_5_3_LUA_H
#include <lua/5.3/lua.h>
#elif defined HAVE_LUA_H || defined LUA_INCLUDED
#include <lua.h>
#elif defined HAVE_LUA_LUA_H
#include <lua/lua.h>
#endif
#if (LUA_VERSION_NUM != 503)
#error Incorrect Lua version
#endif
int
main ()
{
@@ -7323,16 +7228,14 @@ if(LUA_VERSION_NUM != 503) return 1;
;
return 0;
}
_ACEOF
if ac_fn_cxx_try_run "$LINENO"; then :
if ac_fn_c_try_cpp "$LINENO"; then :
have_lua=yes
else
have_lua=no
fi
rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
conftest.$ac_objext conftest.beam conftest.$ac_ext
fi
rm -f conftest.err conftest.i conftest.$ac_ext
ac_ext=c
ac_cpp='$CPP $CPPFLAGS'
ac_compile='$CC -c $CFLAGS $CPPFLAGS conftest.$ac_ext >&5'
@@ -7377,6 +7280,7 @@ fi
LIBLINEARDIR=liblinear
have_liblinear=no
@@ -7896,6 +7800,7 @@ fi
done
ac_ext=cpp
ac_cpp='$CXXCPP $CPPFLAGS'
ac_compile='$CXX -c $CXXFLAGS $CPPFLAGS conftest.$ac_ext >&5'

View File

@@ -821,7 +821,7 @@ AC_SEARCH_LIBS(dlopen, dl)
if test "$no_lua" = "yes"; then
trace_no_use="$trace_no_use lua"
CPPFLAGS="-DNOLUA $CPPFLAGS"
LIBLUA_LIBS=""
NOLUA="yes"
LUA_BUILD=""
LUA_CLEAN=""
LUA_DIST_CLEAN=""
@@ -832,20 +832,30 @@ else
# If they didn't specify it, we try to find it
if test $have_lua != yes; then
AC_CHECK_HEADERS([lua5.3/lua.h lua/5.3/lua.h lua.h lua/lua.h],
AC_CHECK_LIB(lua5.3, lua_isyieldable, [have_lua=yes; LIBLUA_LIBS="-llua5.3"; CPPFLAGS="-I/usr/include/lua5.3 $CPPFLAGS"; break],, [-lm])
AC_CHECK_LIB(lua53, lua_isyieldable, [have_lua=yes; LIBLUA_LIBS="-llua53"; CPPFLAGS="-I/usr/include/lua53 $CPPFLAGS"; break],, [-lm])
AC_CHECK_LIB(lua, lua_isyieldable, [have_lua=yes; LIBLUA_LIBS="-llua"; CPPFLAGS="-I/usr/include/lua $CPPFLAGS"; break],, [-lm])
)
AC_LANG_PUSH(C++)
# We need Lua 5.2 exactly
AC_CHECK_HEADERS([lua5.3/lua.h lua/5.3/lua.h lua.h lua/lua.h], [break])
AC_SEARCH_LIBS(lua_isyieldable, [lua5.3 lua53 lua], [have_lua=yes],, [-lm])
AC_LANG_PUSH(C)
# We need Lua 5.3 exactly
AC_MSG_CHECKING([for lua version == 503])
AC_RUN_IFELSE([ AC_LANG_PROGRAM(
[[#include <lua.h>]],
[[if(LUA_VERSION_NUM != 503) return 1;]])],
have_lua=yes, have_lua=no, AC_MSG_RESULT(cross-compiling -- assuming yes); have_lua=yes)
AC_LANG_POP(C++)
AC_PREPROC_IFELSE([ AC_LANG_PROGRAM( [[
#ifdef HAVE_LUA5_3_LUA_H
#include <lua5.3/lua.h>
#elif defined HAVE_LUA_5_3_LUA_H
#include <lua/5.3/lua.h>
#elif defined HAVE_LUA_H || defined LUA_INCLUDED
#include <lua.h>
#elif defined HAVE_LUA_LUA_H
#include <lua/lua.h>
#endif
#if (LUA_VERSION_NUM != 503)
#error Incorrect Lua version
#endif
]],
[[if(LUA_VERSION_NUM != 503) return 1;]])
],
[have_lua=yes], [have_lua=no])
AC_LANG_POP(C)
LUA_BUILD=""
LUA_CLEAN=""
@@ -869,6 +879,7 @@ else
NSE_CHECK="check-nse"
fi
AC_SUBST(NOLUA)
AC_SUBST(LIBLUA_LIBS)
AC_SUBST(LIBLUADIR)
AC_SUBST(LUA_BUILD)

12
lpeg.c
View File

@@ -16,8 +16,6 @@
#include <assert.h>
#include <limits.h>
#include "lua.h"
#define VERSION "0.12"
@@ -332,8 +330,6 @@ void checkrule (lua_State *L, Instruction *op, int from, int to,
#if !defined(lpcode_h)
#define lpcode_h
#include "lua.h"
int tocharset (TTree *tree, Charset *cs);
int checkaux (TTree *tree, int pred);
@@ -394,8 +390,6 @@ void printcaplist (Capture *cap, Capture *limit);
** Copyright 2007, Lua.org & PUC-Rio (see 'lpeg.html' for license)
*/
#include "lua.h"
#include "lauxlib.h"
@@ -932,8 +926,6 @@ int getcaptures (lua_State *L, const char *s, const char *r, int ptop) {
#include <limits.h>
#include "lua.h"
#include "lauxlib.h"
@@ -2136,8 +2128,6 @@ void printktable (lua_State *L, int idx) {
#include <string.h>
#include "lua.h"
#include "lauxlib.h"
@@ -3362,8 +3352,6 @@ LUALIB_API int luaopen_lpeg (lua_State *L) {
#include <string.h>
#include "lua.h"
#include "lauxlib.h"

View File

@@ -257,4 +257,10 @@ extern "C" int gethostname (char *, unsigned int);
#undef PCAP_NETMASK_UNKNOWN
#undef HAVE_PCAP_SET_IMMEDIATE_MODE
/* Various possibilities for lua.h */
#undef HAVE_LUA5_3_LUA_H
#undef HAVE_LUA_5_3_LUA_H
#undef HAVE_LUA_H
#undef HAVE_LUA_LUA_H
#endif /* CONFIG_H */

View File

@@ -1,9 +1,5 @@
extern "C" {
#include "lua.h"
#include "lauxlib.h"
}
#include "nse_lua.h"
#include "nse_debug.h"
#include "output.h"
#undef NDEBUG

View File

@@ -9,11 +9,7 @@
#include "struct_ip.h"
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include "nse_lua.h"
#include <assert.h>

View File

@@ -26,10 +26,7 @@
*
**/
extern "C" {
#include "lauxlib.h"
#include "lua.h"
}
#include "nse_lua.h"
#include "nmap.h"
#include "nse_fs.h"

View File

@@ -8,10 +8,9 @@
*/
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "libssh2.h"
}
#include "nse_lua.h"
#include "nse_debug.h"
#include "nse_nsock.h"

View File

@@ -1,7 +1,4 @@
extern "C" {
#include "lauxlib.h"
#include "lua.h"
}
#include "nse_lua.h"
/* Lua 5.3 support */
#define luaL_checkint luaL_checkinteger

32
nse_lua.h Normal file
View File

@@ -0,0 +1,32 @@
#ifndef NSE_LUA_H
#define NSE_LUA_H
#include "nmap_config.h"
#ifdef __cplusplus
extern "C" {
#endif
#ifdef HAVE_LUA5_3_LUA_H
#include <lua5.3/lua.h>
#include <lua5.3/lauxlib.h>
#include <lua5.3/lualib.h>
#elif defined HAVE_LUA_5_3_LUA_H
#include <lua/5.3/lua.h>
#include <lua/5.3/lauxlib.h>
#include <lua/5.3/lualib.h>
#elif defined HAVE_LUA_H || defined LUA_INCLUDED
#include <lua.h>
#include <lauxlib.h>
#include <lualib.h>
#elif defined HAVE_LUA_LUA_H
#include <lua/lua.h>
#include <lua/lauxlib.h>
#include <lua/lualib.h>
#endif
#ifdef __cplusplus
} /* End of 'extern "C"' */
#endif
#endif /* NSE_LUA_H */

View File

@@ -5,11 +5,7 @@
#include <list>
#include <string>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include "nse_lua.h"
#include "scan_lists.h"

View File

@@ -1,9 +1,5 @@
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"
}
#include "nse_lua.h"
#include <math.h>

View File

@@ -1,9 +1,7 @@
#ifndef NMAP_LUA_NSOCK_H
#define NMAP_LUA_NSOCK_H
extern "C" {
#include "lua.h"
}
#include "nse_lua.h"
LUALIB_API int luaopen_nsock (lua_State *);

View File

@@ -36,14 +36,11 @@
#define PASS_EVP_CTX(ctx) (&(ctx))
#endif
extern "C" {
#include "lua.h"
#include "lauxlib.h"
#include "nse_lua.h"
#if OPENSSL_API_COMPAT >= 0x10100000L
/* Needed for get_random_bytes, since RAND_pseudo_bytes is gone */
#include <nbase.h>
#endif
}
#include "nse_openssl.h"

View File

@@ -7,10 +7,7 @@
#include <stdlib.h>
#include <string.h>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
}
#include "nse_lua.h"
#include <locale.h>

View File

@@ -159,11 +159,7 @@
#endif
extern "C"
{
#include "lua.h"
#include "lauxlib.h"
}
#include "nse_lua.h"
#include "nse_nsock.h"

View File

@@ -25,10 +25,7 @@
#include <stdlib.h>
#include <string.h>
extern "C" {
#include "lua.h"
#include "lauxlib.h"
}
#include "nse_lua.h"
#include <zlib.h>