diff --git a/Makefile.in b/Makefile.in
index cc2b635c2..7daeca1ea 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -60,9 +60,9 @@ BUILDUMIT=@BUILDUMIT@
INSTALLUMIT=@INSTALLUMIT@
ifneq (@LIBLUA_LIBS@,)
-NSE_SRC=nse_main.cc nse_auxiliar.cc nse_nsock.cc nse_init.cc nse_nmaplib.cc nse_debug.cc nse_string.cc
-NSE_HDRS=nse_main.h nse_auxiliar.h nse_nsock.h nse_init.h nse_nmaplib.h nse_debug.h nse_macros.h nse_string.h
-NSE_OBJS=nse_main.o nse_auxiliar.o nse_nsock.o nse_init.o nse_nmaplib.o nse_debug.o nse_string.o
+NSE_SRC=nse_main.cc nse_auxiliar.cc nse_nsock.cc nse_init.cc nse_nmaplib.cc nse_debug.cc nse_pcrelib.cc nse_string.cc
+NSE_HDRS=nse_main.h nse_auxiliar.h nse_nsock.h nse_init.h nse_nmaplib.h nse_debug.h nse_macros.h nse_pcrelib.h nse_string.h
+NSE_OBJS=nse_main.o nse_auxiliar.o nse_nsock.o nse_init.o nse_nmaplib.o nse_debug.o nse_pcrelib.o nse_string.o
NSESTDLIB=nsestdlib
endif
diff --git a/mswin32/nmap.vcproj b/mswin32/nmap.vcproj
index 42ab54a3f..ee68e9e3e 100644
--- a/mswin32/nmap.vcproj
+++ b/mswin32/nmap.vcproj
@@ -285,6 +285,10 @@
RelativePath="..\nse_nsock.cc"
>
+
+
@@ -470,6 +474,10 @@
RelativePath="..\nse_nsock.h"
>
+
+
diff --git a/nse_init.cc b/nse_init.cc
index 35e604b0e..ecdb262b7 100644
--- a/nse_init.cc
+++ b/nse_init.cc
@@ -4,6 +4,7 @@
#include "nse_debug.h"
// 3rd Party libs
+#include "nse_pcrelib.h"
#include "nbase.h"
@@ -45,6 +46,7 @@ int init_lua(lua_State* l) {
{LUA_STRLIBNAME, luaopen_string},
{LUA_MATHLIBNAME, luaopen_math},
{LUA_DBLIBNAME, luaopen_debug},
+ {NSE_PCRELIBNAME, luaopen_pcrelib},
{NULL, NULL}
};
diff --git a/nselib/pcre.c b/nse_pcrelib.cc
similarity index 90%
rename from nselib/pcre.c
rename to nse_pcrelib.cc
index afcc22021..f6b68d5e0 100644
--- a/nselib/pcre.c
+++ b/nse_pcrelib.cc
@@ -6,37 +6,19 @@
#include
#include
#include
-#include
-#ifdef __cplusplus
extern "C" {
-#endif
#include "lua.h"
#include "lauxlib.h"
-
-#ifdef __cplusplus
}
-#endif
#include
#include
-#include "pcre.h"
+#include "nbase.h"
+#include "nmap_error.h"
-static int Snprintf(char *s, size_t n, const char *fmt, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, fmt);
- ret = vsnprintf(s, n, fmt, ap);
- va_end(ap);
-
- if (ret < 0 || (unsigned) ret >= n)
- s[n - 1] = '\0';
-
- return ret;
-}
+#include "nse_pcrelib.h"
static void L_lua_error(lua_State *L, const char *message)
{
@@ -52,7 +34,7 @@ static int get_startoffset(lua_State *L, int stackpos, size_t len)
if(startoffset > 0)
startoffset--;
else if(startoffset < 0) {
- startoffset += (int) len;
+ startoffset += len;
if(startoffset < 0)
startoffset = 0;
}
@@ -66,11 +48,11 @@ static int udata_tostring (lua_State *L, const char* type_handle,
void *udata = luaL_checkudata(L, 1, type_handle);
if(udata) {
- (void)Snprintf(buf, 255, "%s (%p)", type_name, udata);
+ (void)snprintf(buf, 255, "%s (%p)", type_name, udata);
lua_pushstring(L, buf);
}
else {
- (void)Snprintf(buf, 255, "must be userdata of type '%s'", type_name);
+ (void)snprintf(buf, 255, "must be userdata of type '%s'", type_name);
(void)luaL_argerror(L, 1, buf);
}
@@ -156,7 +138,7 @@ static int Lpcre_comp(lua_State *L)
ud->pr = pcre_compile(pattern, cflags, &error, &erroffset, tables);
if(!ud->pr) {
- (void)Snprintf(buf, 255, "%s (pattern offset: %d)", error, erroffset+1);
+ (void)snprintf(buf, 255, "%s (pattern offset: %d)", error, erroffset+1);
/* show offset 1-based as it's common in Lua */
L_lua_error(L, buf);
}
@@ -165,17 +147,9 @@ static int Lpcre_comp(lua_State *L)
if(error) L_lua_error(L, error);
pcre_fullinfo(ud->pr, ud->extra, PCRE_INFO_CAPTURECOUNT, &ud->ncapt);
- /* since some platforms have problems with nbase and exporting symbols we
- * emulate it
- */
- if(((ud->ncapt + 1) * 3 * sizeof(int))<0){
- L_lua_error(L, "PCRE: negative argument to malloc");
- }
/* need (2 ints per capture, plus one for substring match) * 3/2 */
- ud->match = (int *) malloc((ud->ncapt + 1) * 3 * sizeof(int));
- if(ud->match==NULL){
- L_lua_error(L, "PCRE: malloc failed!");
- }
+ ud->match = (int *) safe_malloc((ud->ncapt + 1) * 3 * sizeof(int));
+
return 1;
}
@@ -388,7 +362,7 @@ static const luaL_reg pcrelib[] = {
{NULL, NULL}
};
-LUALIB_API int luaopen_pcre(lua_State *L)
+LUALIB_API int luaopen_pcrelib(lua_State *L)
{
createmeta(L, pcre_handle);
luaL_openlib(L, NULL, pcremeta, 0);
diff --git a/nse_pcrelib.h b/nse_pcrelib.h
new file mode 100644
index 000000000..512d2a85a
--- /dev/null
+++ b/nse_pcrelib.h
@@ -0,0 +1,9 @@
+#ifndef NSE_PCRELIB
+#define NSE_PCRELIB
+
+#define NSE_PCRELIBNAME "pcre"
+
+LUALIB_API int luaopen_pcrelib (lua_State *L);
+
+#endif
+
diff --git a/nselib/Makefile.in b/nselib/Makefile.in
index c32d618b9..30ce5b83b 100644
--- a/nselib/Makefile.in
+++ b/nselib/Makefile.in
@@ -12,21 +12,15 @@ INSTALL = $(SHTOOL) install
LIBTOOL= ./libtool
LTFLAGS = --tag=CC --silent
-all: bit.so pcre.so
+all: bit.so
bit.so: bit.c @LIBTOOL_DEPS@
$(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) @LUAINCLUDE@ $(CFLAGS) -c bit.c
$(LIBTOOL) $(LTFLAGS) --mode=link $(CC) -avoid-version -module -rpath /usr/local/lib -o bit.la bit.lo
mv .libs/bit.so bit.so
-pcre.so: pcre.c @LIBTOOL_DEPS@
- $(LIBTOOL) $(LTFLAGS) --mode=compile $(CC) @PCRE_INCLUDE@ @LUAINCLUDE@ $(CFLAGS) -c pcre.c
- $(LIBTOOL) $(LTFLAGS) --mode=link $(CC) @PCRE_LD@ @PCRE_LIBS@ -avoid-version -module -rpath /usr/local/lib -o pcre.la pcre.lo
- mv .libs/pcre.so pcre.so
-
-
clean:
- rm -f bit.so pcre.so *.la *.lo
+ rm -f bit.so *.la *.lo
rm -rf .libs
distclean: clean
diff --git a/nselib/configure b/nselib/configure
index 7a1c804df..ab5d01b34 100755
--- a/nselib/configure
+++ b/nselib/configure
@@ -837,9 +837,6 @@ ac_ct_F77
LIBTOOL
LIBTOOL_DEPS
LUAINCLUDE
-PCRE_INCLUDE
-PCRE_LD
-PCRE_LIBS
LIBOBJS
LTLIBOBJS'
ac_subst_files=''
@@ -1443,9 +1440,6 @@ Optional Packages:
--with-pic try to use only PIC/non-PIC objects [default=use
both]
--with-tags[=TAGS] include additional configurations [automatic]
- --with-libpcre=DIR Use an existing (compiled) pcre lib from DIR/include
- and DIR/lib.
- --with-libpcre=included Always use the version included with Nmap
Some influential environment variables:
CC C compiler command
@@ -3637,7 +3631,7 @@ ia64-*-hpux*)
;;
*-*-irix6*)
# Find out which ABI we are using.
- echo '#line 3640 "configure"' > conftest.$ac_ext
+ echo '#line 3634 "configure"' > conftest.$ac_ext
if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
(eval $ac_compile) 2>&5
ac_status=$?
@@ -6259,11 +6253,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:6262: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:6256: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:6266: \$? = $ac_status" >&5
+ echo "$as_me:6260: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -6527,11 +6521,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:6530: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:6524: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:6534: \$? = $ac_status" >&5
+ echo "$as_me:6528: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -6631,11 +6625,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:6634: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:6628: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:6638: \$? = $ac_status" >&5
+ echo "$as_me:6632: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -8928,7 +8922,7 @@ else
lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
lt_status=$lt_dlunknown
cat > conftest.$ac_ext < conftest.$ac_ext <&5)
+ (eval echo "\"\$as_me:11365: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:11375: \$? = $ac_status" >&5
+ echo "$as_me:11369: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -11472,11 +11466,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:11475: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:11469: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:11479: \$? = $ac_status" >&5
+ echo "$as_me:11473: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -13033,11 +13027,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:13036: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:13030: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:13040: \$? = $ac_status" >&5
+ echo "$as_me:13034: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -13137,11 +13131,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:13140: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:13134: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:13144: \$? = $ac_status" >&5
+ echo "$as_me:13138: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -15328,11 +15322,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15331: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15325: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:15335: \$? = $ac_status" >&5
+ echo "$as_me:15329: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -15596,11 +15590,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15599: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15593: $lt_compile\"" >&5)
(eval "$lt_compile" 2>conftest.err)
ac_status=$?
cat conftest.err >&5
- echo "$as_me:15603: \$? = $ac_status" >&5
+ echo "$as_me:15597: \$? = $ac_status" >&5
if (exit $ac_status) && test -s "$ac_outfile"; then
# The compiler can only warn and ignore the option if not recognized
# So say no if there are warnings other than the usual output.
@@ -15700,11 +15694,11 @@ else
-e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
-e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
-e 's:$: $lt_compiler_flag:'`
- (eval echo "\"\$as_me:15703: $lt_compile\"" >&5)
+ (eval echo "\"\$as_me:15697: $lt_compile\"" >&5)
(eval "$lt_compile" 2>out/conftest.err)
ac_status=$?
cat out/conftest.err >&5
- echo "$as_me:15707: \$? = $ac_status" >&5
+ echo "$as_me:15701: \$? = $ac_status" >&5
if (exit $ac_status) && test -s out/conftest2.$ac_objext
then
# The compiler can only warn and ignore the option if not recognized
@@ -18529,39 +18523,6 @@ fi
-#needed for pcre - libpcre
-
-# First we test whether they specified libpcre explicitly
-
-# Check whether --with-libpcre was given.
-if test "${with_libpcre+set}" = set; then
- withval=$with_libpcre; case "$with_libpcre" in
- yes)
- ;;
- included)
- PCRE_INCLUDE_DIR="../libpcre"
- PCRE_LD_DIR="../libpcre"
- ;;
- *)
- PCRE_INCLUDE_DIR="$with_libpcre/include"
- PCRE_LD_DIR="$with_libpcre/lib"
- ;;
- esac
-else
- PCRE_INCLUDE_DIR="../libpcre";PCRE_LD_DIR="../libpcre"
-
-fi
-
-PCRE_INCLUDE="-I$PCRE_INCLUDE_DIR"
-PCRE_LD="-L$PCRE_LD_DIR"
-PCRE_LIBS="-lpcre"
-
-# AC_SUBST(PCREDIR)
-
-
-
-
-
ac_config_files="$ac_config_files Makefile"
cat >confcache <<\_ACEOF
@@ -19262,14 +19223,11 @@ ac_ct_F77!$ac_ct_F77$ac_delim
LIBTOOL!$LIBTOOL$ac_delim
LIBTOOL_DEPS!$LIBTOOL_DEPS$ac_delim
LUAINCLUDE!$LUAINCLUDE$ac_delim
-PCRE_INCLUDE!$PCRE_INCLUDE$ac_delim
-PCRE_LD!$PCRE_LD$ac_delim
-PCRE_LIBS!$PCRE_LIBS$ac_delim
LIBOBJS!$LIBOBJS$ac_delim
LTLIBOBJS!$LTLIBOBJS$ac_delim
_ACEOF
- if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 75; then
+ if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 72; then
break
elif $ac_last_try; then
{ { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
diff --git a/nselib/configure.ac b/nselib/configure.ac
index 691b52d13..e97d1ac15 100644
--- a/nselib/configure.ac
+++ b/nselib/configure.ac
@@ -19,36 +19,6 @@ AC_CANONICAL_HOST
AC_CHECK_HEADER([lua.h],,[AC_MSG_NOTICE(using lua-includefiles provided with nmap);[LUAINCLUDE=-I../liblua/]],)
AC_SUBST(LUAINCLUDE)
-#needed for pcre - libpcre
-
-# First we test whether they specified libpcre explicitly
-AC_ARG_WITH(libpcre,
-AC_HELP_STRING([--with-libpcre=DIR], [Use an existing (compiled) pcre lib from DIR/include and DIR/lib.])
-AC_HELP_STRING([--with-libpcre=included], [Always use the version included with Nmap]),
-[ case "$with_libpcre" in
- yes)
- ;;
- included)
- PCRE_INCLUDE_DIR="../libpcre"
- PCRE_LD_DIR="../libpcre"
- ;;
- *)
- PCRE_INCLUDE_DIR="$with_libpcre/include"
- PCRE_LD_DIR="$with_libpcre/lib"
- ;;
- esac],
-[PCRE_INCLUDE_DIR="../libpcre";PCRE_LD_DIR="../libpcre"]
-)
-PCRE_INCLUDE="-I$PCRE_INCLUDE_DIR"
-PCRE_LD="-L$PCRE_LD_DIR"
-PCRE_LIBS="-lpcre"
-
-# AC_SUBST(PCREDIR)
-AC_SUBST(PCRE_INCLUDE)
-AC_SUBST(PCRE_LD)
-AC_SUBST(PCRE_LIBS)
-
-
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
diff --git a/nselib/pcre.h b/nselib/pcre.h
deleted file mode 100644
index 95f0a5b15..000000000
--- a/nselib/pcre.h
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef PCRE_H
-#define PCRE_H
-
-#ifdef WIN32
-#define _CRT_SECURE_NO_DEPRECATE 1
-#define _CRT_SECURE_NO_WARNINGS 1 /* otherwise msvc++ complains even for
-safe operations, and request us to use their str*_s() functions */
-#pragma warning(disable: 4996)
-#define vsnprintf _vsnprintf
-#define strdup _strdup
-#endif /* WIN32 */
-#define NSE_PCRELIBNAME "pcre"
-
-LUALIB_API int luaopen_pcre(lua_State *L);
-
-#endif
-
diff --git a/scripts/ircServerInfo.nse b/scripts/ircServerInfo.nse
index 9fb6ef08d..b77cd8b5d 100644
--- a/scripts/ircServerInfo.nse
+++ b/scripts/ircServerInfo.nse
@@ -10,7 +10,6 @@ categories = {"discovery"}
require("stdnse")
require "shortport"
-require "pcre"
portrule = shortport.port_or_service(6667, "irc")