internals.doc 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. internals.txt, 8 May 1996
  2. Written by David Chappell <David.Chappell@mail.trincoll.edu>.
  3. This document describes some of the internal functions which must be
  4. understood by anyone wishing to add features to Samba.
  5. =============================================================================
  6. This section describes the macros defined in byteorder.h. These macros
  7. are used extensively in the Samba code.
  8. -----------------------------------------------------------------------------
  9. CVAL(buf,pos)
  10. returns the byte at offset pos within buffer buf as an unsigned character.
  11. -----------------------------------------------------------------------------
  12. PVAL(buf,pos)
  13. returns the value of CVAL(buf,pos) cast to type unsigned integer.
  14. -----------------------------------------------------------------------------
  15. SCVAL(buf,pos,val)
  16. sets the byte at offset pos within buffer buf to value val.
  17. -----------------------------------------------------------------------------
  18. SVAL(buf,pos)
  19. returns the value of the unsigned short (16 bit) little-endian integer at
  20. offset pos within buffer buf. An integer of this type is sometimes
  21. refered to as "USHORT".
  22. -----------------------------------------------------------------------------
  23. IVAL(buf,pos)
  24. returns the value of the unsigned 32 bit little-endian integer at offset
  25. pos within buffer buf.
  26. -----------------------------------------------------------------------------
  27. SVALS(buf,pos)
  28. returns the value of the signed short (16 bit) little-endian integer at
  29. offset pos within buffer buf.
  30. -----------------------------------------------------------------------------
  31. IVALS(buf,pos)
  32. returns the value of the signed 32 bit little-endian integer at offset pos
  33. within buffer buf.
  34. -----------------------------------------------------------------------------
  35. SSVAL(buf,pos,val)
  36. sets the unsigned short (16 bit) little-endian integer at offset pos within
  37. buffer buf to value val.
  38. -----------------------------------------------------------------------------
  39. SIVAL(buf,pos,val)
  40. sets the unsigned 32 bit little-endian integer at offset pos within buffer
  41. buf to the value val.
  42. -----------------------------------------------------------------------------
  43. SSVALS(buf,pos,val)
  44. sets the short (16 bit) signed little-endian integer at offset pos within
  45. buffer buf to the value val.
  46. -----------------------------------------------------------------------------
  47. SIVALS(buf,pos,val)
  48. sets the signed 32 bit little-endian integer at offset pos withing buffer
  49. buf to the value val.
  50. -----------------------------------------------------------------------------
  51. RSVAL(buf,pos)
  52. returns the value of the unsigned short (16 bit) big-endian integer at
  53. offset pos within buffer buf.
  54. -----------------------------------------------------------------------------
  55. RIVAL(buf,pos)
  56. returns the value of the unsigned 32 bit big-endian integer at offset
  57. pos within buffer buf.
  58. -----------------------------------------------------------------------------
  59. RSSVAL(buf,pos,val)
  60. sets the value of the unsigned short (16 bit) big-endian integer at
  61. offset pos within buffer buf to value val.
  62. refered to as "USHORT".
  63. -----------------------------------------------------------------------------
  64. RSIVAL(buf,pos,val)
  65. sets the value of the unsigned 32 bit big-endian integer at offset
  66. pos within buffer buf to value val.
  67. =============================================================================
  68. This section describes the functions need to make a LAN Manager RPC call.
  69. This information had been obtained by examining the Samba code and the LAN
  70. Manager 2.0 API documentation. It should not be considered entirely
  71. reliable.
  72. -----------------------------------------------------------------------------
  73. call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt,
  74. char *param, char *data, char **rparam, char **rdata);
  75. This function is defined in client.c. It uses an SMB transaction to call a
  76. remote api.
  77. The parameters are as follows:
  78. prcnt: the number of bytes of parameters begin sent.
  79. drcnt: the number of bytes of data begin sent.
  80. mprcnt: the maximum number of bytes of parameters which should be returned
  81. mdrcnt: the maximum number of bytes of data which should be returned
  82. param: a pointer to the parameters to be sent.
  83. data: a pointer to the data to be sent.
  84. rparam: a pointer to a pointer which will be set to point to the returned
  85. paramters. The caller of call_api() must deallocate this memory.
  86. rdata: a pointer to a pointer which will be set to point to the returned
  87. data. The caller of call_api() must deallocate this memory.
  88. -----------------------------------------------------------------------------
  89. These are the parameters which you ought to send, in the order of their
  90. appearance in the parameter block:
  91. * An unsigned 16 bit integer API number. You should set this value with
  92. SSVAL(). I do not know where these numbers are described.
  93. * An ASCIIZ string describing the parameters to the API function as defined
  94. in the LAN Manager documentation. The first parameter, which is the server
  95. name, is omitted. This string is based uppon the API function as described
  96. in the manual, not the data which is actually passed.
  97. * An ASCIIZ string describing the data structure which ought to be returned.
  98. * Any parameters which appear in the function call, as defined in the LAN
  99. Manager API documentation, after the "Server" and up to and including the
  100. "uLevel" parameters.
  101. * An unsigned 16 bit integer which gives the size in bytes of the buffer we
  102. will use to receive the returned array of data structures. Presumably this
  103. should be the same as mdrcnt. This value should be set with SSVAL().
  104. * An ASCIIZ string describing substructures which should be returned. If no
  105. substructures apply, this string is of zero length.
  106. -----------------------------------------------------------------------------
  107. The code in client.c always calls call_api() with no data. It is unclear
  108. when a non-zero length data buffer would be sent.
  109. -----------------------------------------------------------------------------
  110. The returned parameters (pointed to by rparam), in their order of appearance
  111. are:
  112. * An unsigned 16 bit integer which contains the API function's return code.
  113. This value should be read with SVAL().
  114. * An adjustment which tells the amount by which pointers in the returned
  115. data should be adjusted. This value should be read with SVAL(). Basically,
  116. the address of the start of the returned data buffer should have the returned
  117. pointer value added to it and then have this value subtracted from it in
  118. order to obtain the currect offset into the returned data buffer.
  119. * A count of the number of elements in the array of structures returned.
  120. It is also possible that this may sometimes be the number of bytes returned.
  121. -----------------------------------------------------------------------------
  122. When call_api() returns, rparam points to the returned parameters. The
  123. first if these is the result code. It will be zero if the API call
  124. suceeded. This value by be read with "SVAL(rparam,0)".
  125. The second parameter may be read as "SVAL(rparam,2)". It is a 16 bit offset
  126. which indicates what the base address of the returned data buffer was when
  127. it was built on the server. It should be used to correct pointer before
  128. use.
  129. The returned data buffer contains the array of returned data structures.
  130. Note that all pointers must be adjusted before use. The function
  131. fix_char_ptr() in client.c can be used for this purpose.
  132. The third parameter (which may be read as "SVAL(rparam,4)") has something to
  133. do with indicating the amount of data returned or possibly the amount of
  134. data which can be returned if enough buffer space is allowed.
  135. -----------------------------------------------------------------------------
  136. Certain data structures are described by means of ASCIIz strings containing
  137. code characters. These are the code characters:
  138. W a type byte little-endian unsigned integer
  139. N a count of substructures which follow
  140. D a four byte little-endian unsigned integer
  141. B a byte (with optional count expressed as trailing ASCII digits)
  142. z a four byte offset to a NULL terminated string
  143. l a four byte offset to non-string user data
  144. b an offset to data (with count expressed as trailing ASCII digits)
  145. r pointer to returned data buffer???
  146. L length in bytes of returned data buffer???
  147. h number of bytes of information available???
  148. ----------------------------------------------------------------------------