Nmap Development mailing list archives

[NSE][PATCH] patch for datafiles.lua to use nmap.fetchfile() directly


From: Sven Klemm <sven () c3d2 de>
Date: Sun, 07 Sep 2008 17:41:50 +0200

Hi,

currently datafiles.parsefile() looks for the passed filename in the directory where it finds nmap-rpc,nmap-services or nmap-protocols. The attached patch makes datafiles use nmap.fetchfile directly so the file will be searched in multiple locations instead of only one.

This might be a candidate for inclusion before the release. Currently only rpcinfo.nse uses datafiles.lua and with the patch applied rpcinfo.nse still works fine.


Cheers,
Sven

--
Sven Klemm
http://cthulhu.c3d2.de/~sven/

Index: nselib/datafiles.lua
===================================================================
--- nselib/datafiles.lua        (revision 10017)
+++ nselib/datafiles.lua        (working copy)
@@ -125,10 +125,10 @@
     data_struct = t
   end
 
-  -- get path to file - no checking done here
-  local status, filepath = get_filepath( filename )
-  if not status then
-    return false, ( "Error in datafiles.parse_file: %s." ):format( filepath ) -- error from get_filepath
+  -- get path to file
+  local filepath = nmap.fetchfile( filename )
+  if not filepath then
+    return false, ( "Error in nmap.fetchfile: Could not find file %s." ):format( filename )
   end
 
   -- get a table of lines
@@ -270,16 +270,3 @@
 
 end
 
-
----
--- Gets the path to filename.
-function get_filepath( filename )
-  local ff = { "nmap-rpc", "nmap-services", "nmap-protocols" }
-  for _, f in pairs( ff ) do
-    local path = nmap.fetchfile( f )
-    if path then
-      return true, ( path:sub( 1, #path - #f ) .. filename )
-    end
-  end
-  return false, "Error in datafiles.get_filepath: Can't find nmap datafiles" -- ?
-end
\ No newline at end of file

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org

Current thread: