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 - Implements functions for creating and serializing a NCP packet

  • ResponseParser - A static class containing a bunch of functions to decode server responses

  • Response - Class responsible for decoding NCP responses

  • NCP - Contains the "native" NCP functions sending the actual request to the server.

  • Helper - The preferred script interface to the library containing functions that wrap functions from the NCP class using more descriptive names and easier interface.

  • Util - A class containing mostly decoding and helper functions

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: https://svn.nmap.org/nmap/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 the helper connection

connect (self)

Connect the socket and creates a NCP 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

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

Resolve (resp)

Decodes a Resolve response

ResolveName (self, name)

Resolves an directory entry id from a name

search (self, base, class, name, options)

Performs a directory search

Search (self, base, class, name, options)

Searches the directory

Search (self, base, class, name, options)

Searches the directory

SendPacket (self, p)

Sends a packet to the server

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

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:

  1. status true on success, false on failure
  2. response table (if status is true) containing: ip, port and proto
  3. 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:

  1. status true on success, false on failure
  2. response table (if status is true) containing: srvname os_major os_minor conns_supported conns_inuse vols_supported os_rev sft_support tts_level conns_max_use acct_version vap_version qms_version print_version internet_bridge_ver mixed_mode_path local_login_info product_major product_minor product_rev os_lang_id support_64_bit
  3. 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:

  1. status true on success, false on failure
  2. response table of vol entries (if status is true) Each vol entry is a table containing the following fields: vol_no and vol_name
  3. 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 the helper connection

Parameters

self
 
connect (self)

Connect the socket and creates a NCP connection

Parameters

self
 

Return value:

true on success false on failure
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:

  1. pos number containing the new offset after decoding
  2. entry table containing the decoded entry, currently it contains one or more of the following fields: flags mod_time sub_count baseclass rdn name
EnumerateNetworkAddress (self)

Enumerates the IP addresses associated with the server

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. response table (if status is true) containing: ip, port and proto
  3. 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:

  1. status true on success false on failure
  2. response table (if status is true) containing the parsed response
  3. 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
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:

  1. status true on success, false on failure
  2. response table (if status is true) containing: srvname os_major os_minor conns_supported conns_inuse vols_supported os_rev sft_support tts_level conns_max_use acct_version vap_version qms_version print_version internet_bridge_ver mixed_mode_path local_login_info product_major product_minor product_rev os_lang_id support_64_bit
  3. 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:

  1. status true on success, false on failure
  2. response table of vol entries (if status is true) Each vol entry is a table containing the following fields: vol_no and vol_name
  3. 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:

* GetFileServerInfo * Ping * EnumerateNetworkAddress * GetMountVolumeList

The result contains the Tree name, product versions and mounts

Parameters

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:

  1. status true on success false on failure
  2. entries table (if status is true) as return by: ResponseDecoder.EntryDecoder
  3. 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:

  1. status true on success false on failure
  2. entries table (if status is true) as return by: ResponseDecoder.EntryDecoder
  3. 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:

  1. status true on success, false on failure
  2. response table (if status is true) containing: tree_name
  3. error message (if status is false)
Ping (self)

Sends a PING to the server which responds with the tree name

Parameters

self
 

Return values:

  1. status true on success, false on failure
  2. response table (if status is true) containing: tree_name
  3. 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:

  1. status true on success, false on failure
  2. response table (if status is true) containing: tag and id
  3. 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:

  1. status true on success, false on failure
  2. response table (if status is true) containing: tag and id
  3. error message (if status is false)

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

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:

  1. status true on success false on failure
  2. entries table (if status is true) as return by: ResponseDecoder.EntryDecoder
  3. error string (if status is false) containing the error

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:

  1. status true on success false on failure
  2. entries table (if status is true) as return by: ResponseDecoder.EntryDecoder
  3. error string (if status is false) containing the error
SendPacket (self, p)

Sends a packet to the server

Parameters

self
 
p
Packet to be sent to the server

Return values:

  1. status true on success, false on failure
  2. err string containing the error message on failure
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
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