Index: nselib/stdnse.lua =================================================================== --- nselib/stdnse.lua (revision 28349) +++ nselib/stdnse.lua (working copy) @@ -52,6 +52,29 @@ -- sleep is a C function defined in nse_nmaplib.cc. +--- Creates a directory +-- +-- This function exposes the mkdir function to Lua making it possible to create +-- directories on local and remote file systems. The function requires any +-- parent directories to exists in order to complete succesfully. +-- @name make_dir +-- @class function +-- @param dir string containing the directory name to create +-- @return status true on success, false on failure +-- @return err string containing any error message on failure + +-- make_dir is a C function defined in nse_nmaplib.cc. + +--- Gets the correct path separator for the local OS ontop of which Nmap runs +-- +-- The function allows detecting the correct OS path separator, which differs +-- depeding on the OS on top of which Nmap runs. +-- @name get_path_separator +-- @class function +-- @return string containing the path separator + +-- get_path_separator is a C function defined in nse_nmaplib.cc. + --- -- Prints a formatted debug message if the current debugging level is greater -- than or equal to a given level. Index: nse_nmaplib.cc =================================================================== --- nse_nmaplib.cc (revision 28352) +++ nse_nmaplib.cc (working copy) @@ -987,12 +987,44 @@ return 1; } +int l_make_dir(lua_State *L) +{ + const char *path = luaL_checkstring(L, 1); +#ifdef WIN32 + int status = _mkdir(path); +#else + int status = mkdir(path, S_IRWXU | S_IRWXG); +#endif + + if (status!=0) + { + lua_pushboolean(L, false); + lua_pushstring(L, "failed to add new targets."); + return 2; + } + + lua_pushboolean(L, true); + return 1; +} + +int l_get_path_separator(lua_State *L) +{ +#ifdef WIN32 + lua_pushstring(L, "\\"); +#else + lua_pushstring(L, "/"); +#endif + return 1; +} + /* Register C functions that belong in the stdnse namespace. They are loaded from here in stdnse.lua. */ int luaopen_stdnse_c (lua_State *L) { static const luaL_reg stdnse_clib [] = { {"sleep", l_nsock_sleep}, + {"make_dir", l_make_dir}, + {"get_path_separator", l_get_path_separator}, {NULL, NULL} }; Index: mswin32/winclude.h =================================================================== --- mswin32/winclude.h (revision 28349) +++ mswin32/winclude.h (working copy) @@ -98,6 +98,7 @@ #include "nmap_winconfig.h" +#include #include #include