Library ncp
A tiny implementation of the Netware Core Protocol (NCP). While NCP was originally a Netware only protocol it's now present on both Linux and Windows platforms running Novell eDirectory.
The library implements a small amount of NCP functions based on various packet dumps generated by Novell software, such as the Novell Client and Console One. The functions are mainly used for enumeration and discovery
The library implements a number of different classes where the Helper is the one that should be the easiest to use from scripts.
The following classes exist:
- Packet
- ResponseParser
- Response
- NCP
- Socket
- Helper
- Util
The following example code illustrates how to use the Helper class from a script. The example queries the server for all User objects from the root.
local helper = ncp.Helper:new(host,port)
local status, resp = helper:connect()
status, resp = helper:search("[Root]", "User", "*")
status = helper:close()
Source: http://nmap.org/svn/nselib/ncp.lua
Functions
| [NCPFunction.EnumerateNetworkAddress] (resp) |
Decodes a EnumerateNetworkAddress response |
| [NCPFunction.GetFileServerInfo] (resp) |
Decodes a GetFileServerInfo response |
| [NCPFunction.GetMountVolumeList] (resp) |
Decodes a GetMountVolumeList response |
| __tostring (self) |
"Serializes" the Response instance to a string |
| __tostring (self) |
"Serializes" the Response instance to a string |
| close (self) |
Closes an open connection. |
| close (self) |
Closes an open connection. |
| connect (self, hostid, port, protocol) |
Establishes a connection. |
| connect (self, hostid, port, protocol) |
Establishes a connection. |
| CreateConnect (self) |
Creates a connection to the NCP server |
| DestroyConnect (self) |
Destroys a connection established with the NCP server |
| EntryDecoder (data, pos) |
The EntryDecoder is used by the Search and List function, for decoding the returned entries. |
| EnumerateNetworkAddress (self) |
Enumerates the IP addresses associated with the server |
| Exch (self, p) |
Handles sending and receiving a NCP message |
| fromSocket (socket) |
Creates a Response instance from the data read of the socket |
| FromWideChar (wstr) |
Concerts a wide string to string |
| getConnNo (self) |
Gets the connection number |
| getConnNo (self) |
Gets the connection number |
| getData (self) |
Gets the data portion of the response |
| getData (self) |
Gets the data portion of the response |
| GetFileServerInfo (self) |
Gets file server information |
| getFunc (self) |
Gets the NCP packet function |
| getHeader (self) |
Gets the header portion of the response |
| GetMountVolumeList (self) |
Gets a list of volumes from the server |
| getNCPLength (self) |
Gets the NCP packet length |
| getSeqNo (self) |
Gets the sequence number |
| getSeqNo (self) |
Gets the sequence number |
| getServerInfo (self) |
Retrieves some information from the server using the following NCP
functions:
|
| getSubFunc (self) |
Gets the NCP sub function |
| getType (self) |
Gets the NCP packet type |
| hasErrors (self) |
Returns true if there are any errors |
| List (self, entry) |
Lists the contents of entry |
| List (self, entry) |
Lists the contents of entry |
| new (self, host, port) |
Creates a new Helper instance |
| new (self, host, port) |
Creates a new Helper instance |
| new (self, host, port) |
Creates a new Helper instance |
| new (self, host, port) |
Creates a new Helper instance |
| parse (self) |
Parses the Response |
| parse (self) |
Parses the Response |
| Ping (self) |
Sends a PING to the server which responds with the tree name |
| Ping (self) |
Sends a PING to the server which responds with the tree name |
| recv (self, count) |
Opposed to the |
| Resolve (resp) |
Decodes a Resolve response |
| ResolveName (self, name) |
Resolves an directory entry id from a name |
| Search (self, base, class, name, options) |
Searches the directory |
| search (self, base, class, name, options) |
Performs a directory search |
| Search (self, base, class, name, options) |
Searches the directory |
| send (self, data) |
Sends data over the socket |
| SendPacket (self, p) |
Sends a packet to the server |
| set_timeout (self, tm) |
Sets the socket timeout (@see nmap.set_timeout) |
| setConnNo (self, n, conn) |
Sets the NCP connection number |
| setData (self, data) |
Sets the packet data |
| setFunc (self, f, t) |
Sets the NCP packet function |
| setLength (self, n, len) |
Sets the packet length |
| setNCPLength (self, n) |
Sets the NCP packet length |
| setNCPReplyBuf (self, n) |
Sets the NCP Reply buffer size |
| setSeqNo (self, n, seqno) |
Sets the NCP sequence number |
| setSubFunc (self, n, subfunc) |
Sets the NCP sub function |
| setTask (self, task) |
Sets the packet task |
| setType (self, t) |
Sets the NCP packet type |
| ToWideChar (str) |
Converts a string to a wide string |
| ZeroPad (str, len) |
Pads a string with zeroes |
Functions
- [NCPFunction.EnumerateNetworkAddress] (resp)
-
Decodes a EnumerateNetworkAddress response
Parameters
- resp: string containing the response as received from the server
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
ip,portandproto - error message (if status is false)
- [NCPFunction.GetFileServerInfo] (resp)
-
Decodes a GetFileServerInfo response
Parameters
- resp: string containing the response as received from the server
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
srvnameos_majoros_minorconns_supportedconns_inusevols_supportedos_revsft_supporttts_levelconns_max_useacct_versionvap_versionqms_versionprint_versioninternet_bridge_vermixed_mode_pathlocal_login_infoproduct_majorproduct_minorproduct_revos_lang_idsupport_64_bit - error message (if status is false)
- [NCPFunction.GetMountVolumeList] (resp)
-
Decodes a GetMountVolumeList response
Parameters
- resp: string containing the response as received from the server
Return values:
- status true on success, false on failure
- response table of vol entries (if status is true)
Each vol entry is a table containing the following fields:
vol_noandvol_name - error message (if status is false)
- __tostring (self)
-
"Serializes" the Response instance to a string
Parameters
- self:
- __tostring (self)
-
"Serializes" the Response instance to a string
Parameters
- self:
- close (self)
-
Closes an open connection.
Parameters
- self:
Return values:
- Status (true or false).
- Error code (if status is false).
- close (self)
-
Closes an open connection.
Parameters
- self:
Return values:
- Status (true or false).
- Error code (if status is false).
- connect (self, hostid, port, protocol)
-
Establishes a connection.
Parameters
- self:
- hostid: Hostname or IP address.
- port: Port number.
-
protocol:
"tcp","udp", or
Return values:
- Status (true or false).
- Error code (if status is false).
- connect (self, hostid, port, protocol)
-
Establishes a connection.
Parameters
- self:
- hostid: Hostname or IP address.
- port: Port number.
-
protocol:
"tcp","udp", or
Return values:
- Status (true or false).
- Error code (if status is false).
- CreateConnect (self)
-
Creates a connection to the NCP server
Parameters
- self:
Return value:
status true on success, false on failure - DestroyConnect (self)
-
Destroys a connection established with the NCP server
Parameters
- self:
Return value:
status true on success, false on failure - EntryDecoder (data, pos)
-
The EntryDecoder is used by the Search and List function, for decoding the returned entries.
Parameters
- data: containing the response as returned by the server
- pos: number containing the offset into data to start decoding
Return values:
- pos number containing the new offset after decoding
- entry table containing the decoded entry, currently it contains
one or more of the following fields:
flagsmod_timesub_countbaseclassrdnname
- EnumerateNetworkAddress (self)
-
Enumerates the IP addresses associated with the server
Parameters
- self:
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
ip,portandproto - error message (if status is false)
- Exch (self, p)
-
Handles sending and receiving a NCP message
Parameters
- self:
- p: Packet containing the request to send to the server
Return values:
- status true on success false on failure
- response table (if status is true) containing the parsed response
- error string (if status is false) containing the error
- fromSocket (socket)
-
Creates a Response instance from the data read of the socket
Parameters
- socket: socket connected to server and ready to receive data
Return value:
Response containing a new Response instance - FromWideChar (wstr)
-
Concerts a wide string to string
Parameters
- wstr: containing the wide string to convert
Return value:
string with every other character removed - getConnNo (self)
-
Gets the connection number
Parameters
- self:
Return value:
conn number - getConnNo (self)
-
Gets the connection number
Parameters
- self:
Return value:
conn number - getData (self)
-
Gets the data portion of the response
Parameters
- self:
Return value:
data string - getData (self)
-
Gets the data portion of the response
Parameters
- self:
Return value:
data string - GetFileServerInfo (self)
-
Gets file server information
Parameters
- self:
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
srvnameos_majoros_minorconns_supportedconns_inusevols_supportedos_revsft_supporttts_levelconns_max_useacct_versionvap_versionqms_versionprint_versioninternet_bridge_vermixed_mode_pathlocal_login_infoproduct_majorproduct_minorproduct_revos_lang_idsupport_64_bit - error message (if status is false)
- getFunc (self)
-
Gets the NCP packet function
Parameters
- self:
Return value:
func number containing the NCP packet function - getHeader (self)
-
Gets the header portion of the response
Parameters
- self:
- GetMountVolumeList (self)
-
Gets a list of volumes from the server
Parameters
- self:
Return values:
- status true on success, false on failure
- response table of vol entries (if status is true)
Each vol entry is a table containing the following fields:
vol_noandvol_name - error message (if status is false)
- getNCPLength (self)
-
Gets the NCP packet length
Parameters
- self:
Return value:
n number containing the NCP length - getSeqNo (self)
-
Gets the sequence number
Parameters
- self:
Return value:
seqno number - getSeqNo (self)
-
Gets the sequence number
Parameters
- self:
Return value:
seqno number - getServerInfo (self)
-
Retrieves some information from the server using the following NCP functions:
GetFileServerInfoPingEnumerateNetworkAddressGetMountVolumeListThe result contains the Tree name, product versions and mountsParameters
- self:
- getSubFunc (self)
-
Gets the NCP sub function
Parameters
- self:
Return value:
subfunc number containing the subfunction - getType (self)
-
Gets the NCP packet type
Parameters
- self:
Return value:
type number containing the NCP packet type - hasErrors (self)
-
Returns true if there are any errors
Parameters
- self:
Return value:
error true if the response error code is anything else than OK - List (self, entry)
-
Lists the contents of entry
Parameters
- self:
-
entry:
entry as resolved by
Resolve
Return values:
- status true on success false on failure
- entries table (if status is true) as return by:
ResponseDecoder.EntryDecoder - error string (if status is false) containing the error
- List (self, entry)
-
Lists the contents of entry
Parameters
- self:
-
entry:
entry as resolved by
Resolve
Return values:
- status true on success false on failure
- entries table (if status is true) as return by:
ResponseDecoder.EntryDecoder - error string (if status is false) containing the error
- new (self, host, port)
-
Creates a new Helper instance
Parameters
- self:
- host:
- port:
Return value:
a new Helper instance - new (self, host, port)
-
Creates a new Helper instance
Parameters
- self:
- host:
- port:
Return value:
a new Helper instance - new (self, host, port)
-
Creates a new Helper instance
Parameters
- self:
- host:
- port:
Return value:
a new Helper instance - new (self, host, port)
-
Creates a new Helper instance
Parameters
- self:
- host:
- port:
Return value:
a new Helper instance - parse (self)
-
Parses the Response
Parameters
- self:
- parse (self)
-
Parses the Response
Parameters
- self:
- Ping (self)
-
Sends a PING to the server which responds with the tree name
Parameters
- self:
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
tree_name - error message (if status is false)
- Ping (self)
-
Sends a PING to the server which responds with the tree name
Parameters
- self:
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
tree_name - error message (if status is false)
- recv (self, count)
-
Opposed to the
socket:receive_bytesfunction, that returns at least x bytes, this function returns the amount of bytes requested.Parameters
- self:
- count: of bytes to read
Return values:
- true on success, false on failure
- data containing bytes read from the socket err containing error message if status is false
- Resolve (resp)
-
Decodes a Resolve response
Parameters
- resp: string containing the response as received from the server
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
tagandid - error message (if status is false)
- ResolveName (self, name)
-
Resolves an directory entry id from a name
Parameters
- self:
- name: string containing the name to resolve
Return values:
- status true on success, false on failure
- response table (if status is true) containing:
tagandid - error message (if status is false)
- Search (self, base, class, name, options)
-
Searches the directory
Parameters
- self:
-
base:
entry as resolved by
Resolve - class: string containing a class name (or * wildcard)
- name: string containing a entry name (or * wildcard)
-
options:
table containing one or more of the following
numobjs
Return values:
- status true on success false on failure
- entries table (if status is true) as return by:
ResponseDecoder.EntryDecoder - error string (if status is false) containing the error
- search (self, base, class, name, options)
-
Performs a directory search
Parameters
- self:
- base: string containing the name of the base to search
- class: string containing the type of class to search
- name: string containing the name of the object to find
-
options:
table containing on or more of the following
numobjs- number of objects to limit the search to
- Search (self, base, class, name, options)
-
Searches the directory
Parameters
- self:
-
base:
entry as resolved by
Resolve - class: string containing a class name (or * wildcard)
- name: string containing a entry name (or * wildcard)
-
options:
table containing one or more of the following
numobjs
Return values:
- status true on success false on failure
- entries table (if status is true) as return by:
ResponseDecoder.EntryDecoder - error string (if status is false) containing the error
- send (self, data)
-
Sends data over the socket
Parameters
- self:
- data:
Return values:
- Status (true or false).
- Error code (if status is false).
- SendPacket (self, p)
-
Sends a packet to the server
Parameters
- self:
- p: Packet to be sent to the server
Return values:
- status true on success, false on failure
- err string containing the error message on failure
- set_timeout (self, tm)
-
Sets the socket timeout (@see nmap.set_timeout)
Parameters
- self:
- tm: number containing the socket timeout in ms
- setConnNo (self, n, conn)
-
Sets the NCP connection number
Parameters
- self:
- n:
- conn: number containing the connection number
- setData (self, data)
-
Sets the packet data
Parameters
- self:
- data: string containing the packet data
- setFunc (self, f, t)
-
Sets the NCP packet function
Parameters
- self:
- f:
- t: number containing the NCP function
- setLength (self, n, len)
-
Sets the packet length
Parameters
- self:
- n:
- len: number containing the packet length
- setNCPLength (self, n)
-
Sets the NCP packet length
Parameters
- self:
- n: number containing the length
- setNCPReplyBuf (self, n)
-
Sets the NCP Reply buffer size
Parameters
- self:
- n: number containing the buffer size
- setSeqNo (self, n, seqno)
-
Sets the NCP sequence number
Parameters
- self:
- n:
- seqno: number containing the sequence number
- setSubFunc (self, n, subfunc)
-
Sets the NCP sub function
Parameters
- self:
- n:
- subfunc: number containing the subfunction
- setTask (self, task)
-
Sets the packet task
Parameters
- self:
- task: number containing the packet number
- setType (self, t)
-
Sets the NCP packet type
Parameters
- self:
- t: number containing the NCP packet type
- ToWideChar (str)
-
Converts a string to a wide string
Parameters
- str: string to be converted
Return value:
string containing a two byte representation of str where a zero byte character has been tagged on to each character. - ZeroPad (str, len)
-
Pads a string with zeroes
Parameters
- str: string containing the string to be padded
- len: number containing the length of the new string
Return value:
str string containing the new string


