1
0
mirror of https://github.com/nmap/nmap.git synced 2026-01-27 08:39:02 +00:00

Revert to r32212.

My recent changes are causing problems when I try to integrate them into
the ncat-sa-take2 branch.
This commit is contained in:
david
2013-09-06 06:16:13 +00:00
parent 4fdde97639
commit 502339c92c
6 changed files with 25 additions and 48 deletions

View File

@@ -204,10 +204,6 @@ void options_init(void)
o.proxy_auth = NULL;
o.proxytype = NULL;
#ifdef HAVE_LUA
o.lua_exec_state = NULL;
#endif
#ifdef HAVE_OPENSSL
o.ssl = 0;
o.sslcert = NULL;

View File

@@ -126,10 +126,6 @@
#include "util.h"
#include "sockaddr_u.h"
#ifdef HAVE_LUA
#include "ncat_lua.h"
#endif
/* Maximum size of the srcaddrs array. In this case two because we can only have
a IPV4 INADDR_ANY and a IPV6 in6addr_any at most or a user defined address */
#define NUM_LISTEN_ADDRS 2
@@ -202,10 +198,6 @@ struct options {
char *proxy_auth;
char *proxytype;
#ifdef HAVE_LUA
lua_State *lua_exec_state;
#endif
int ssl;
char *sslcert;
char *sslkey;

View File

@@ -124,7 +124,10 @@
#include "ncat.h"
#include "ncat_lua.h"
static void report(lua_State *L, char *prefix)
static lua_State *L;
static int last_function_number;
static void report(char *prefix)
{
const char *errormsg;
errormsg = lua_tostring(L, -1);
@@ -148,41 +151,32 @@ static int traceback (lua_State *L)
return 1;
}
lua_State *lua_setup(const char *filename)
void lua_setup(void)
{
lua_State *L;
ncat_assert(filename != NULL);
ncat_assert(o.cmdexec != NULL);
L = luaL_newstate();
luaL_openlibs(L);
if (luaL_loadfile(L, filename) != 0)
report(L, "Error loading the Lua script");
if (luaL_loadfile(L, o.cmdexec) != 0)
report("Error loading the Lua script");
return L;
/* install the traceback function */
last_function_number = lua_gettop(L);
lua_pushcfunction(L, traceback);
lua_insert(L, last_function_number);
}
void lua_run(lua_State *L)
void lua_run(void)
{
if (lua_call_traceback(L, 0, 0) != LUA_OK && !lua_isnil(L, -1)) {
report(L, "Error running the Lua script");
if (lua_pcall(L, 0, 0, last_function_number) != LUA_OK && !lua_isnil(L, -1)) {
/* handle the error; the code below is taken from lua.c, Lua source code */
lua_remove(L, last_function_number);
report("Error running the Lua script");
} else {
if (o.debug)
logdebug("Lua script returned successfully.\n");
logdebug("%s returned successfully.\n", o.cmdexec);
lua_close(L);
exit(EXIT_SUCCESS);
}
}
/* Returns the value of a lua_pcall of the chunk on top of the stack, with an
error handler that prints a traceback. */
int lua_call_traceback(lua_State *L, int nargs, int nresults)
{
/* The chunk to run is on top of the stack. Put the traceback function
before it and run it. */
lua_pushcfunction(L, traceback);
lua_insert(L, -2);
return lua_pcall(L, nargs, nresults, -2);
}

View File

@@ -124,8 +124,6 @@
#ifndef _NCAT_LUA_H
#define _NCAT_LUA_H
#include "ncat.h"
#ifdef __cplusplus
extern "C" {
#endif
@@ -138,8 +136,7 @@ extern "C" {
}
#endif
lua_State *lua_setup(const char *filename);
void lua_run(lua_State *L);
int lua_call_traceback(lua_State *L, int nargs, int nresults);
void lua_setup(void);
void lua_run(void);
#endif

View File

@@ -535,8 +535,6 @@ int main(int argc, char *argv[])
forking in POSIX builds, Windows does not have the fork() system
call and thus requires this workaround. More info here:
http://seclists.org/nmap-dev/2013/q2/492 */
lua_State *L;
#ifdef WIN32
if (o.debug)
logdebug("Enabling binary stdout for the Lua output.\n");
@@ -545,9 +543,9 @@ int main(int argc, char *argv[])
perror("Cannot set mode");
#endif
ncat_assert(argc == 3);
L = lua_setup(argv[2]);
ncat_assert(L != NULL);
lua_run(L);
o.cmdexec = argv[2];
lua_setup();
lua_run();
}
#endif
break;
@@ -871,7 +869,7 @@ connection brokering should work.");
#ifdef HAVE_LUA
if (o.execmode == EXEC_LUA)
o.lua_exec_state = lua_setup(o.cmdexec);
lua_setup();
#endif
if (o.listen)

View File

@@ -234,7 +234,7 @@ void netexec(struct fdinfo *info, char *cmdexec)
break;
#ifdef HAVE_LUA
case EXEC_LUA:
lua_run(o.lua_exec_state);
lua_run();
break;
#endif
default: