Regenerate docs
[samba.git] / docs / htmldocs / Samba-Developers-Guide.html
1 <html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>SAMBA Developers Guide</title><link rel="stylesheet" href="samba.css" type="text/css"><meta name="generator" content="DocBook XSL Stylesheets V1.60.1"><meta name="description" content="
2 Last Update : Fri Jun  6 00:45:54 CEST 2003
3  
4 This book is a collection of documents that might be useful for 
5 people developing samba or those interested in doing so.
6 It's nothing more than a collection of documents written by samba developers about 
7 the internals of various parts of samba and the SMB protocol. It's still incomplete.
8 The most recent version of this document
9 can be found at http://devel.samba.org/.
10 Please send updates to Jelmer Vernooij.
11  
12 This documentation is distributed under the GNU General Public License (GPL) 
13 version 2.  A copy of the license is included with the Samba source
14 distribution.  A copy can be found on-line at http://www.fsf.org/licenses/gpl.txt
15 "></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en"><div class="titlepage"><div><div><h1 class="title"><a name="Samba-Developers-Guide"></a>SAMBA Developers Guide</h1></div><div><div class="abstract"><p class="title"><b>Abstract</b></p><p>
16 <span class="emphasis"><em>Last Update</em></span> : Fri Jun  6 00:45:54 CEST 2003
17 </p><p>
18 This book is a collection of documents that might be useful for 
19 people developing samba or those interested in doing so.
20 It's nothing more than a collection of documents written by samba developers about 
21 the internals of various parts of samba and the SMB protocol. It's still incomplete.
22 The most recent version of this document
23 can be found at <a href="http://devel.samba.org/" target="_top">http://devel.samba.org/</a>.
24 Please send updates to <a href="mailto:jelmer@samba.org" target="_top">Jelmer Vernooij</a>.
25 </p><p>
26 This documentation is distributed under the GNU General Public License (GPL) 
27 version 2.  A copy of the license is included with the Samba source
28 distribution.  A copy can be found on-line at <a href="http://www.fsf.org/licenses/gpl.txt" target="_top">http://www.fsf.org/licenses/gpl.txt</a>
29 </p></div></div></div><div></div><hr></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2865348">Attributions</a></dt><dt>1. <a href="#netbios">Definition of NetBIOS Protocol and Name Resolution Modes</a></dt><dd><dl><dt><a href="#id2797071">NETBIOS</a></dt><dt><a href="#id2797155">BROADCAST NetBIOS</a></dt><dt><a href="#id2797186">NBNS NetBIOS</a></dt></dl></dd><dt>2. <a href="#architecture">Samba Architecture</a></dt><dd><dl><dt><a href="#id2797301">Introduction</a></dt><dt><a href="#id2797354">Multithreading and Samba</a></dt><dt><a href="#id2797393">Threading smbd</a></dt><dt><a href="#id2797467">Threading nmbd</a></dt><dt><a href="#id2797529">nbmd Design</a></dt></dl></dd><dt>3. <a href="#debug">The samba DEBUG system</a></dt><dd><dl><dt><a href="#id2797614">New Output Syntax</a></dt><dt><a href="#id2797749">The DEBUG() Macro</a></dt><dt><a href="#id2799885">The DEBUGADD() Macro</a></dt><dt><a href="#id2799932">The DEBUGLVL() Macro</a></dt><dt><a href="#id2800044">New Functions</a></dt><dd><dl><dt><a href="#id2800051">dbgtext()</a></dt><dt><a href="#id2800071">dbghdr()</a></dt><dt><a href="#id2800094">format_debug_text()</a></dt></dl></dd></dl></dd><dt>4. <a href="#CodingSuggestions">Coding Suggestions</a></dt><dt>5. <a href="#internals">Samba Internals</a></dt><dd><dl><dt><a href="#id2800556">Character Handling</a></dt><dt><a href="#id2800582">The new functions</a></dt><dt><a href="#id2800742">Macros in byteorder.h</a></dt><dd><dl><dt><a href="#id2800755">CVAL(buf,pos)</a></dt><dt><a href="#id2800769">PVAL(buf,pos)</a></dt><dt><a href="#id2800783">SCVAL(buf,pos,val)</a></dt><dt><a href="#id2800795">SVAL(buf,pos)</a></dt><dt><a href="#id2800815">IVAL(buf,pos)</a></dt><dt><a href="#id2800829">SVALS(buf,pos)</a></dt><dt><a href="#id2800844">IVALS(buf,pos)</a></dt><dt><a href="#id2800858">SSVAL(buf,pos,val)</a></dt><dt><a href="#id2800872">SIVAL(buf,pos,val)</a></dt><dt><a href="#id2800887">SSVALS(buf,pos,val)</a></dt><dt><a href="#id2800901">SIVALS(buf,pos,val)</a></dt><dt><a href="#id2800916">RSVAL(buf,pos)</a></dt><dt><a href="#id2800930">RIVAL(buf,pos)</a></dt><dt><a href="#id2800944">RSSVAL(buf,pos,val)</a></dt><dt><a href="#id2866314">RSIVAL(buf,pos,val)</a></dt></dl></dd><dt><a href="#id2866329">LAN Manager Samba API</a></dt><dd><dl><dt><a href="#id2866366">Parameters</a></dt><dt><a href="#id2866517">Return value</a></dt></dl></dd><dt><a href="#id2866617">Code character table</a></dt></dl></dd><dt>6. <a href="#parsing">The smb.conf file</a></dt><dd><dl><dt><a href="#id2866736">Lexical Analysis</a></dt><dd><dl><dt><a href="#id2866826">Handling of Whitespace</a></dt><dt><a href="#id2866883">Handling of Line Continuation</a></dt><dt><a href="#id2866948">Line Continuation Quirks</a></dt></dl></dd><dt><a href="#id2867044">Syntax</a></dt><dd><dl><dt><a href="#id2867117">About params.c</a></dt></dl></dd></dl></dd><dt>7. <a href="#unix-smb">NetBIOS in a Unix World</a></dt><dd><dl><dt><a href="#id2867166">Introduction</a></dt><dt><a href="#id2867191">Usernames</a></dt><dt><a href="#id2867277">File Ownership</a></dt><dt><a href="#id2867326">Passwords</a></dt><dt><a href="#id2867388">Locking</a></dt><dt><a href="#id2867458">Deny Modes</a></dt><dt><a href="#id2867499">Trapdoor UIDs</a></dt><dt><a href="#id2867526">Port numbers</a></dt><dt><a href="#id2867572">Protocol Complexity</a></dt></dl></dd><dt>8. <a href="#tracing">Tracing samba system calls</a></dt><dt>9. <a href="#windows-debug">Finding useful information on windows</a></dt><dd><dl><dt><a href="#id2867998">Netlogon debugging output</a></dt></dl></dd><dt>10. <a href="#ntdomain">NT Domain RPC's</a></dt><dd><dl><dt><a href="#id2868139">Introduction</a></dt><dd><dl><dt><a href="#id2868342">Sources</a></dt><dt><a href="#id2868377">Credits</a></dt></dl></dd><dt><a href="#id2868416">Notes and Structures</a></dt><dd><dl><dt><a href="#id2868423">Notes</a></dt><dt><a href="#id2868506">Enumerations</a></dt><dt><a href="#id2868718">Structures</a></dt></dl></dd><dt><a href="#id2871669">MSRPC over Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2871682">MSRPC Pipes</a></dt><dt><a href="#id2871787">Header</a></dt><dt><a href="#id2872660">Tail</a></dt><dt><a href="#id2872706">RPC Bind / Bind Ack</a></dt><dt><a href="#id2872896">NTLSA Transact Named Pipe</a></dt><dt><a href="#id2873062">LSA Open Policy</a></dt><dt><a href="#id2873187">LSA Query Info Policy</a></dt><dt><a href="#id2873296">LSA Enumerate Trusted Domains</a></dt><dt><a href="#id2873387">LSA Open Secret</a></dt><dt><a href="#id2873498">LSA Close</a></dt><dt><a href="#id2873564">LSA Lookup SIDS</a></dt><dt><a href="#id2873773">LSA Lookup Names</a></dt></dl></dd><dt><a href="#id2873999">NETLOGON rpc Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2874162">LSA Request Challenge</a></dt><dt><a href="#id2874296">LSA Authenticate 2</a></dt><dt><a href="#id2874444">LSA Server Password Set</a></dt><dt><a href="#id2874559">LSA SAM Logon</a></dt><dt><a href="#id2874662">LSA SAM Logoff</a></dt></dl></dd><dt><a href="#id2874755">\\MAILSLOT\NET\NTLOGON</a></dt><dd><dl><dt><a href="#id2874774">Query for PDC</a></dt><dt><a href="#id2875034">SAM Logon</a></dt></dl></dd><dt><a href="#id2875360">SRVSVC Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2875405">Net Share Enum</a></dt><dt><a href="#id2875625">Net Server Get Info</a></dt></dl></dd><dt><a href="#id2875741">Cryptographic side of NT Domain Authentication</a></dt><dd><dl><dt><a href="#id2875749">Definitions</a></dt><dt><a href="#id2875911">Protocol</a></dt><dt><a href="#id2876010">Comments</a></dt></dl></dd><dt><a href="#id2876057">SIDs and RIDs</a></dt><dd><dl><dt><a href="#id2876097">Well-known SIDs</a></dt><dt><a href="#id2876412">Well-known RIDS</a></dt></dl></dd></dl></dd><dt>11. <a href="#printing">Samba Printing Internals</a></dt><dd><dl><dt><a href="#id2876697">Abstract</a></dt><dt><a href="#id2876713">
30 Printing Interface to Various Back ends
31 </a></dt><dt><a href="#id2876809">
32 Print Queue TDB's
33 </a></dt><dt><a href="#id2877031">
34 ChangeID and Client Caching of Printer Information
35 </a></dt><dt><a href="#id2877045">
36 Windows NT/2K Printer Change Notify
37 </a></dt></dl></dd><dt>12. <a href="#wins">Samba WINS Internals</a></dt><dd><dl><dt><a href="#id2877426">WINS Failover</a></dt></dl></dd><dt>13. <a href="#sam">The Upcoming SAM System</a></dt><dd><dl><dt><a href="#id2877582">Security in the 'new SAM'</a></dt><dt><a href="#id2877712">Standalone from UNIX</a></dt><dt><a href="#id2877739">Handles and Races in the new SAM</a></dt><dt><a href="#id2877808">Layers</a></dt><dd><dl><dt><a href="#id2877815">Application</a></dt><dt><a href="#id2877831">SAM Interface</a></dt><dt><a href="#id2877859">SAM Modules</a></dt></dl></dd><dt><a href="#id2877880">SAM Modules</a></dt><dd><dl><dt><a href="#id2877888">Special Module: sam_passdb</a></dt><dt><a href="#id2877906">sam_ads</a></dt></dl></dd><dt><a href="#id2877935">Memory Management</a></dt><dt><a href="#id2878035">Testing</a></dt></dl></dd><dt>14. <a href="#pwencrypt">LanMan and NT Password Encryption</a></dt><dd><dl><dt><a href="#id2878174">Introduction</a></dt><dt><a href="#id2878193">How does it work?</a></dt><dt><a href="#id2878320">The smbpasswd file</a></dt></dl></dd><dt>15. <a href="#modules">Modules</a></dt><dd><dl><dt><a href="#id2878688">Advantages</a></dt><dt><a href="#id2878737">Loading modules</a></dt><dd><dl><dt><a href="#id2878771">Static modules</a></dt><dt><a href="#id2878811">Shared modules</a></dt></dl></dd><dt><a href="#id2878839">Writing modules</a></dt><dd><dl><dt><a href="#id2878904">Static/Shared selection in configure.in</a></dt></dl></dd></dl></dd><dt>16. <a href="#rpc-plugin">RPC Pluggable Modules</a></dt><dd><dl><dt><a href="#id2879098">About</a></dt><dt><a href="#id2879116">General Overview</a></dt></dl></dd><dt>17. <a href="#vfs">VFS Modules</a></dt><dd><dl><dt><a href="#id2879326">The Samba (Posix) VFS layer</a></dt><dd><dl><dt><a href="#id2879332">The general interface</a></dt><dt><a href="#id2879448">Possible VFS operation layers</a></dt></dl></dd><dt><a href="#id2879520">The Interaction between the Samba VFS subsystem and the modules</a></dt><dd><dl><dt><a href="#id2879528">Initialization and registration</a></dt><dt><a href="#id2879720">How the Modules handle per connection data</a></dt></dl></dd><dt><a href="#id2879963">Upgrading to the New VFS Interface</a></dt><dd><dl><dt><a href="#id2879970">Upgrading from 2.2.* and 3.0aplha modules</a></dt></dl></dd><dt><a href="#id2880501">Some Notes</a></dt><dd><dl><dt><a href="#id2880508">Implement TRANSPARENT functions</a></dt><dt><a href="#id2880533">Implement OPAQUE functions</a></dt></dl></dd></dl></dd><dt>18. <a href="#Packaging">Notes to packagers</a></dt><dd><dl><dt><a href="#id2880600">Versioning</a></dt><dt><a href="#id2880635">Modules</a></dt></dl></dd><dt>19. <a href="#contributing">Contributing code</a></dt></dl></div><div class="preface" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="id2865348"></a>Attributions</h2></div></div><div></div></div><p><a href="#netbios" title="Chapter 1. Definition of NetBIOS Protocol and Name Resolution Modes">Definition of NetBIOS Protocol and Name Resolution Modes</a></p><div class="itemizedlist"><ul type="disc"><li><p>Luke Leighton</p></li></ul></div><p><a href="#architecture" title="Chapter 2. Samba Architecture">Samba Architecture</a></p><div class="itemizedlist"><ul type="disc"><li><p>Dan Shearer</p></li></ul></div><p><a href="#debug" title="Chapter 3. The samba DEBUG system">The samba DEBUG system</a></p><div class="itemizedlist"><ul type="disc"><li><p>Chris Hertel</p></li></ul></div><p><a href="#CodingSuggestions" title="Chapter 4. Coding Suggestions">Coding Suggestions</a></p><div class="itemizedlist"><ul type="disc"><li><p>Steve French</p></li><li><p>Simo Sorce</p></li><li><p>Andrew Bartlett</p></li><li><p>Tim Potter</p></li><li><p>Martin Pool</p></li></ul></div><p><a href="#internals" title="Chapter 5. Samba Internals">Samba Internals</a></p><div class="itemizedlist"><ul type="disc"><li><p>David Chappell &lt;<a href="mailto:David.Chappell@mail.trincoll.edu" target="_top">David.Chappell@mail.trincoll.edu</a>&gt;</p></li></ul></div><p><a href="#parsing" title="Chapter 6. The smb.conf file">The smb.conf file</a></p><div class="itemizedlist"><ul type="disc"><li><p>Chris Hertel</p></li></ul></div><p><a href="#unix-smb" title="Chapter 7. NetBIOS in a Unix World">NetBIOS in a Unix World</a></p><div class="itemizedlist"><ul type="disc"><li><p>Andrew Tridgell</p></li></ul></div><p><a href="#tracing" title="Chapter 8. Tracing samba system calls">Tracing samba system calls</a></p><div class="itemizedlist"><ul type="disc"><li><p>Andrew Tridgell</p></li></ul></div><p><a href="#windows-debug" title="Chapter 9. Finding useful information on windows">Finding useful information on windows</a></p><div class="itemizedlist"><ul type="disc"><li><p>Jelmer R.  Vernooij &lt;<a href="mailto:jelmer@samba.org" target="_top">jelmer@samba.org</a>&gt;</p></li><li><p>Andrew Tridgell &lt;<a href="mailto:tridge@samba.org" target="_top">tridge@samba.org</a>&gt;</p></li></ul></div><p><a href="#ntdomain" title="Chapter 10. NT Domain RPC's">NT Domain RPC's</a></p><div class="itemizedlist"><ul type="disc"><li><p>Luke Leighton &lt;<a href="mailto:lkcl@switchboard.net" target="_top">lkcl@switchboard.net</a>&gt;</p></li><li><p>Paul Ashton &lt;<a href="mailto:paul@argo.demon.co.uk" target="_top">paul@argo.demon.co.uk</a>&gt;</p></li><li><p>Duncan Stansfield &lt;<a href="mailto:duncans@sco.com" target="_top">duncans@sco.com</a>&gt;</p></li></ul></div><p><a href="#printing" title="Chapter 11. Samba Printing Internals">Samba Printing Internals</a></p><div class="itemizedlist"><ul type="disc"><li><p>Gerald Carter</p></li></ul></div><p><a href="#wins" title="Chapter 12. Samba WINS Internals">Samba WINS Internals</a></p><div class="itemizedlist"><ul type="disc"><li><p>Gerald Carter</p></li></ul></div><p><a href="#sam" title="Chapter 13. The Upcoming SAM System">The Upcoming SAM System</a></p><div class="itemizedlist"><ul type="disc"><li><p>Andrew Bartlett</p></li></ul></div><p><a href="#pwencrypt" title="Chapter 14. LanMan and NT Password Encryption">LanMan and NT Password Encryption</a></p><div class="itemizedlist"><ul type="disc"><li><p>Jeremy Allison &lt;<a href="mailto:samba@samba.org" target="_top">samba@samba.org</a>&gt;</p></li></ul></div><p><a href="#modules" title="Chapter 15. Modules">Modules</a></p><div class="itemizedlist"><ul type="disc"><li><p>Jelmer Vernooij &lt;<a href="mailto:jelmer@samba.org" target="_top">jelmer@samba.org</a>&gt;</p></li></ul></div><p><a href="#rpc-plugin" title="Chapter 16. RPC Pluggable Modules">RPC Pluggable Modules</a></p><div class="itemizedlist"><ul type="disc"><li><p>Anthony Liguori &lt;<a href="mailto:aliguor@us.ibm.com" target="_top">aliguor@us.ibm.com</a>&gt;</p></li><li><p>Jelmer Vernooij &lt;<a href="mailto:jelmer@samba.org" target="_top">jelmer@samba.org</a>&gt;</p></li></ul></div><p><a href="#vfs" title="Chapter 17. VFS Modules">VFS Modules</a></p><div class="itemizedlist"><ul type="disc"><li><p>Alexander Bokovoy &lt;<a href="mailto:ab@samba.org" target="_top">ab@samba.org</a>&gt;</p></li><li><p>Stefan Metzmacher &lt;<a href="mailto:metze@metzemix.de" target="_top">metze@metzemix.de</a>&gt;</p></li></ul></div><p><a href="#Packaging" title="Chapter 18. Notes to packagers">Notes to packagers</a></p><div class="itemizedlist"><ul type="disc"><li><p>Jelmer Vernooij</p></li></ul></div><p><a href="#contributing" title="Chapter 19. Contributing code">Contributing code</a></p><div class="itemizedlist"><ul type="disc"><li><p>Jelmer R.  Vernooij &lt;<a href="mailto:jelmer@samba.org" target="_top">jelmer@samba.org</a>&gt;</p></li></ul></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="netbios"></a>Chapter 1. Definition of NetBIOS Protocol and Name Resolution Modes</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Luke</span> <span class="surname">Leighton</span></h3></div></div><div><p class="pubdate">12 June 1997</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2797071">NETBIOS</a></dt><dt><a href="#id2797155">BROADCAST NetBIOS</a></dt><dt><a href="#id2797186">NBNS NetBIOS</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797071"></a>NETBIOS</h2></div></div><div></div></div><p>
38 NetBIOS runs over the following tranports: TCP/IP; NetBEUI and IPX/SPX.
39 Samba only uses NetBIOS over TCP/IP.  For details on the TCP/IP NetBIOS 
40 Session Service NetBIOS Datagram Service, and NetBIOS Names, see
41 rfc1001.txt and rfc1002.txt.
42 </p><p> 
43 NetBEUI is a raw NetBIOS frame protocol implementation that allows NetBIOS
44 datagrams to be sent out over the 'wire' embedded within LLC frames.
45 NetBEUI is not required when using NetBIOS over TCP/IP protocols and it
46 is preferable NOT to install NetBEUI if it can be avoided.
47 </p><p> 
48 IPX/SPX is also not required when using NetBIOS over TCP/IP, and it is
49 preferable NOT to install the IPX/SPX transport unless you are using Novell
50 servers.  At the very least, it is recommended that you do not install
51 'NetBIOS over IPX/SPX'.
52 </p><p>
53 [When installing Windows 95, you will find that NetBEUI and IPX/SPX are
54 installed as the default protocols.  This is because they are the simplest
55 to manage: no Windows 95 user-configuration is required].
56 </p><p> 
57 NetBIOS applications (such as samba) offer their services (for example,
58 SMB file and print sharing) on a NetBIOS name.  They must claim this name
59 on the network before doing so.  The NetBIOS session service will then
60 accept connections on the application's behalf (on the NetBIOS name
61 claimed by the application).  A NetBIOS session between the application
62 and the client can then commence.
63 </p><p> 
64 NetBIOS names consist of 15 characters plus a 'type' character.  This is
65 similar, in concept, to an IP address and a TCP port number, respectively.
66 A NetBIOS-aware application on a host will offer different services under
67 different NetBIOS name types, just as a host will offer different TCP/IP
68 services on different port numbers.
69 </p><p> 
70 NetBIOS names must be claimed on a network, and must be defended.  The use
71 of NetBIOS names is most suitable on a single subnet; a Local Area Network
72 or a Wide Area Network.
73 </p><p> 
74 NetBIOS names are either UNIQUE or GROUP.  Only one application can claim a
75 UNIQUE NetBIOS name on a network.
76 </p><p>
77 There are two kinds of NetBIOS Name resolution: Broadcast and Point-to-Point.
78 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797155"></a>BROADCAST NetBIOS</h2></div></div><div></div></div><p> 
79 Clients can claim names, and therefore offer services on successfully claimed
80 names, on their broadcast-isolated subnet.  One way to get NetBIOS services
81 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
82 SMB file/print sharing: see cifs4.txt) working on a LAN or WAN is to make
83 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.
84 </p><p> 
85 This, however, is not recommended.  If you have a large LAN or WAN, you will
86 find that some of your hosts spend 95 percent of their time dealing with
87 broadcast traffic.  [If you have IPX/SPX on your LAN or WAN, you will find
88 that this is already happening: a packet analyzer will show, roughly
89 every twelve minutes, great swathes of broadcast traffic!].
90 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797186"></a>NBNS NetBIOS</h2></div></div><div></div></div><p>
91 rfc1001.txt describes, amongst other things, the implementation and use
92 of, a 'NetBIOS Name Service'.  NT/AS offers 'Windows Internet Name Service'
93 which is fully rfc1001/2 compliant, but has had to take specific action
94 with certain NetBIOS names in order to make it useful.  (for example, it
95 deals with the registration of &lt;1c&gt; &lt;1d&gt; &lt;1e&gt; names all in different ways.
96 I recommend the reading of the Microsoft WINS Server Help files for full
97 details).
98 </p><p> 
99 The use of a WINS server cuts down on broadcast network traffic for
100 NetBIOS name resolution.  It has the effect of pulling all the broadcast
101 isolated subnets together into a single NetBIOS scope, across your LAN
102 or WAN, while avoiding the use of TCP/IP broadcast packets.
103 </p><p>
104 When you have a WINS server on your LAN, WINS clients will be able to
105 contact the WINS server to resolve NetBIOS names.  Note that only those
106 WINS clients that have registered with the same WINS server will be
107 visible.  The WINS server _can_ have static NetBIOS entries added to its
108 database (usually for security reasons you might want to consider putting
109 your domain controllers or other important servers as static entries,
110 but you should not rely on this as your sole means of security), but for
111 the most part, NetBIOS names are registered dynamically.
112 </p><p>
113 This provides some confusion for lots of people, and is worth mentioning
114 here:  a Browse Server is NOT a WINS Server, even if these services are
115 implemented in the same application.  A Browse Server _needs_ a WINS server
116 because a Browse Server is a WINS client, which is _not_ the same thing].
117 </p><p>
118 Clients can claim names, and therefore offer services on successfully claimed
119 names, on their broadcast-isolated subnet.  One way to get NetBIOS services
120 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
121 SMB file/print sharing: see cifs6.txt) working on a LAN or WAN is to make
122 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.
123 You will find, however, if you do this on a large LAN or a WAN, that your
124 network is completely swamped by NetBIOS and browsing packets, which is why
125 WINS was developed to minimise the necessity of broadcast traffic.
126 </p><p> 
127 WINS Clients therefore claim names from the WINS server.  If the WINS
128 server allows them to register a name, the client's NetBIOS session service
129 can then offer services on this name.  Other WINS clients will then
130 contact the WINS server to resolve a NetBIOS name.
131 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="architecture"></a>Chapter 2. Samba Architecture</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Dan</span> <span class="surname">Shearer</span></h3></div></div><div><p class="pubdate"> November 1997</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2797301">Introduction</a></dt><dt><a href="#id2797354">Multithreading and Samba</a></dt><dt><a href="#id2797393">Threading smbd</a></dt><dt><a href="#id2797467">Threading nmbd</a></dt><dt><a href="#id2797529">nbmd Design</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797301"></a>Introduction</h2></div></div><div></div></div><p>
132 This document gives a general overview of how Samba works
133 internally. The Samba Team has tried to come up with a model which is
134 the best possible compromise between elegance, portability, security
135 and the constraints imposed by the very messy SMB and CIFS
136 protocol. 
137 </p><p>
138 It also tries to answer some of the frequently asked questions such as:
139 </p><div class="orderedlist"><ol type="1"><li><p>
140         Is Samba secure when running on Unix? The xyz platform?
141         What about the root priveliges issue?
142 </p></li><li><p>Pros and cons of multithreading in various parts of Samba</p></li><li><p>Why not have a separate process for name resolution, WINS, and browsing?</p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797354"></a>Multithreading and Samba</h2></div></div><div></div></div><p>
143 People sometimes tout threads as a uniformly good thing. They are very
144 nice in their place but are quite inappropriate for smbd. nmbd is
145 another matter, and multi-threading it would be very nice. 
146 </p><p>
147 The short version is that smbd is not multithreaded, and alternative
148 servers that take this approach under Unix (such as Syntax, at the
149 time of writing) suffer tremendous performance penalties and are less
150 robust. nmbd is not threaded either, but this is because it is not
151 possible to do it while keeping code consistent and portable across 35
152 or more platforms. (This drawback also applies to threading smbd.)
153 </p><p>
154 The longer versions is that there are very good reasons for not making
155 smbd multi-threaded.  Multi-threading would actually make Samba much
156 slower, less scalable, less portable and much less robust. The fact
157 that we use a separate process for each connection is one of Samba's
158 biggest advantages.
159 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797393"></a>Threading smbd</h2></div></div><div></div></div><p>
160 A few problems that would arise from a threaded smbd are:
161 </p><div class="orderedlist"><ol type="1"><li><p>
162         It's not only to create threads instead of processes, but you
163         must care about all variables if they have to be thread specific
164         (currently they would be global).
165 </p></li><li><p>
166         if one thread dies (eg. a seg fault) then all threads die. We can
167         immediately throw robustness out the window.
168 </p></li><li><p>
169         many of the system calls we make are blocking. Non-blocking
170         equivalents of many calls are either not available or are awkward (and
171         slow) to use. So while we block in one thread all clients are
172         waiting. Imagine if one share is a slow NFS filesystem and the others 
173         are fast, we will end up slowing all clients to the speed of NFS.
174 </p></li><li><p>
175         you can't run as a different uid in different threads. This means
176         we would have to switch uid/gid on _every_ SMB packet. It would be
177         horrendously slow.
178 </p></li><li><p>
179         the per process file descriptor limit would mean that we could only
180         support a limited number of clients.
181 </p></li><li><p>
182         we couldn't use the system locking calls as the locking context of
183         fcntl() is a process, not a thread.
184 </p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797467"></a>Threading nmbd</h2></div></div><div></div></div><p>
185 This would be ideal, but gets sunk by portability requirements.
186 </p><p>
187 Andrew tried to write a test threads library for nmbd that used only
188 ansi-C constructs (using setjmp and longjmp). Unfortunately some OSes
189 defeat this by restricting longjmp to calling addresses that are
190 shallower than the current address on the stack (apparently AIX does
191 this). This makes a truly portable threads library impossible. So to
192 support all our current platforms we would have to code nmbd both with
193 and without threads, and as the real aim of threads is to make the
194 code clearer we would not have gained anything. (it is a myth that
195 threads make things faster. threading is like recursion, it can make
196 things clear but the same thing can always be done faster by some
197 other method)
198 </p><p>
199 Chris tried to spec out a general design that would abstract threading
200 vs separate processes (vs other methods?) and make them accessible
201 through some general API. This doesn't work because of the data
202 sharing requirements of the protocol (packets in the future depending
203 on packets now, etc.) At least, the code would work but would be very
204 clumsy, and besides the fork() type model would never work on Unix. (Is there an OS that it would work on, for nmbd?)
205 </p><p>
206 A fork() is cheap, but not nearly cheap enough to do on every UDP
207 packet that arrives. Having a pool of processes is possible but is
208 nasty to program cleanly due to the enormous amount of shared data (in
209 complex structures) between the processes. We can't rely on each
210 platform having a shared memory system.
211 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797529"></a>nbmd Design</h2></div></div><div></div></div><p>
212 Originally Andrew used recursion to simulate a multi-threaded
213 environment, which use the stack enormously and made for really
214 confusing debugging sessions. Luke Leighton rewrote it to use a
215 queuing system that keeps state information on each packet.  The
216 first version used a single structure which was used by all the
217 pending states.  As the initialisation of this structure was
218 done by adding arguments, as the functionality developed, it got
219 pretty messy.  So, it was replaced with a higher-order function
220 and a pointer to a user-defined memory block.  This suddenly
221 made things much simpler: large numbers of functions could be
222 made static, and modularised.  This is the same principle as used
223 in NT's kernel, and achieves the same effect as threads, but in
224 a single process.
225 </p><p>
226 Then Jeremy rewrote nmbd. The packet data in nmbd isn't what's on the
227 wire. It's a nice format that is very amenable to processing but still
228 keeps the idea of a distinct packet. See &quot;struct packet_struct&quot; in
229 nameserv.h.  It has all the detail but none of the on-the-wire
230 mess. This makes it ideal for using in disk or memory-based databases
231 for browsing and WINS support. 
232 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="debug"></a>Chapter 3. The samba DEBUG system</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Chris</span> <span class="surname">Hertel</span></h3></div></div><div><p class="pubdate">July 1998</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2797614">New Output Syntax</a></dt><dt><a href="#id2797749">The DEBUG() Macro</a></dt><dt><a href="#id2799885">The DEBUGADD() Macro</a></dt><dt><a href="#id2799932">The DEBUGLVL() Macro</a></dt><dt><a href="#id2800044">New Functions</a></dt><dd><dl><dt><a href="#id2800051">dbgtext()</a></dt><dt><a href="#id2800071">dbghdr()</a></dt><dt><a href="#id2800094">format_debug_text()</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797614"></a>New Output Syntax</h2></div></div><div></div></div><p>
233    The syntax of a debugging log file is represented as:
234 </p><pre class="programlisting">
235   &gt;debugfile&lt; :== { &gt;debugmsg&lt; }
236
237   &gt;debugmsg&lt;  :== &gt;debughdr&lt; '\n' &gt;debugtext&lt;
238
239   &gt;debughdr&lt;  :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'
240
241   &gt;debugtext&lt; :== { &gt;debugline&lt; }
242
243   &gt;debugline&lt; :== TEXT '\n'
244 </pre><p>
245 TEXT is a string of characters excluding the newline character.
246 </p><p>
247 LEVEL is the DEBUG level of the message (an integer in the range
248                 0..10).
249 </p><p>
250 TIME is a timestamp.
251 </p><p>
252 FILE is the name of the file from which the debug message was
253 generated.
254 </p><p>
255 FUNCTION is the function from which the debug message was generated.
256 </p><p>
257 LINE is the line number of the debug statement that generated the
258 message.
259 </p><p>Basically, what that all means is:</p><div class="orderedlist"><ol type="1"><li><p>
260 A debugging log file is made up of debug messages.
261 </p></li><li><p>
262 Each debug message is made up of a header and text. The header is
263 separated from the text by a newline.
264 </p></li><li><p>
265 The header begins with the timestamp and debug level of the
266 message enclosed in brackets. The filename, function, and line
267 number at which the message was generated follow. The filename is
268 terminated by a colon, and the function name is terminated by the
269 parenthesis which contain the line number. Depending upon the
270 compiler, the function name may be missing (it is generated by the
271 __FUNCTION__ macro, which is not universally implemented, dangit).
272 </p></li><li><p>
273 The message text is made up of zero or more lines, each terminated
274 by a newline.
275 </p></li></ol></div><p>Here's some example output:</p><pre class="programlisting">
276     [1998/08/03 12:55:25, 1] nmbd.c:(659)
277       Netbios nameserver version 1.9.19-prealpha started.
278       Copyright Andrew Tridgell 1994-1997
279     [1998/08/03 12:55:25, 3] loadparm.c:(763)
280       Initializing global parameters
281 </pre><p>
282 Note that in the above example the function names are not listed on
283 the header line. That's because the example above was generated on an
284 SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.
285 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2797749"></a>The DEBUG() Macro</h2></div></div><div></div></div><p>
286 Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
287 The first is the message level, the second is the body of a function
288 call to the Debug1() function.
289 </p><p>That's confusing.</p><p>Here's an example which may help a bit. If you would write</p><pre class="programlisting">
290 printf( &quot;This is a %s message.\n&quot;, &quot;debug&quot; );
291 </pre><p>
292 to send the output to stdout, then you would write
293 </p><pre class="programlisting">
294 DEBUG( 0, ( &quot;This is a %s message.\n&quot;, &quot;debug&quot; ) );
295 </pre><p>
296 to send the output to the debug file.  All of the normal printf()
297 formatting escapes work.
298 </p><p>
299 Note that in the above example the DEBUG message level is set to 0.
300 Messages at level 0 always print.  Basically, if the message level is
301 less than or equal to the global value DEBUGLEVEL, then the DEBUG
302 statement is processed.
303 </p><p>
304 The output of the above example would be something like:
305 </p><pre class="programlisting">
306     [1998/07/30 16:00:51, 0] file.c:function(128)
307       This is a debug message.
308 </pre><p>
309 Each call to DEBUG() creates a new header *unless* the output produced
310 by the previous call to DEBUG() did not end with a '\n'. Output to the
311 debug file is passed through a formatting buffer which is flushed
312 every time a newline is encountered. If the buffer is not empty when
313 DEBUG() is called, the new input is simply appended.
314 </p><p>
315 ...but that's really just a Kludge. It was put in place because
316 DEBUG() has been used to write partial lines. Here's a simple (dumb)
317 example of the kind of thing I'm talking about:
318 </p><pre class="programlisting">
319     DEBUG( 0, (&quot;The test returned &quot; ) );
320     if( test() )
321       DEBUG(0, (&quot;True&quot;) );
322     else
323       DEBUG(0, (&quot;False&quot;) );
324     DEBUG(0, (&quot;.\n&quot;) );
325 </pre><p>
326 Without the format buffer, the output (assuming test() returned true)
327 would look like this:
328 </p><pre class="programlisting">
329     [1998/07/30 16:00:51, 0] file.c:function(256)
330       The test returned
331     [1998/07/30 16:00:51, 0] file.c:function(258)
332       True
333     [1998/07/30 16:00:51, 0] file.c:function(261)
334       .
335 </pre><p>Which isn't much use. The format buffer kludge fixes this problem.
336 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2799885"></a>The DEBUGADD() Macro</h2></div></div><div></div></div><p>
337 In addition to the kludgey solution to the broken line problem
338 described above, there is a clean solution. The DEBUGADD() macro never
339 generates a header. It will append new text to the current debug
340 message even if the format buffer is empty. The syntax of the
341 DEBUGADD() macro is the same as that of the DEBUG() macro.
342 </p><pre class="programlisting">
343     DEBUG( 0, (&quot;This is the first line.\n&quot; ) );
344     DEBUGADD( 0, (&quot;This is the second line.\nThis is the third line.\n&quot; ) );
345 </pre><p>Produces</p><pre class="programlisting">
346     [1998/07/30 16:00:51, 0] file.c:function(512)
347       This is the first line.
348       This is the second line.
349       This is the third line.
350 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2799932"></a>The DEBUGLVL() Macro</h2></div></div><div></div></div><p>
351 One of the problems with the DEBUG() macro was that DEBUG() lines
352 tended to get a bit long. Consider this example from
353 nmbd_sendannounce.c:
354 </p><pre class="programlisting">
355   DEBUG(3,(&quot;send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n&quot;,
356             type, global_myname, subrec-&gt;subnet_name, work-&gt;work_group));
357 </pre><p>
358 One solution to this is to break it down using DEBUG() and DEBUGADD(),
359 as follows:
360 </p><pre class="programlisting">
361   DEBUG( 3, ( &quot;send_local_master_announcement: &quot; ) );
362   DEBUGADD( 3, ( &quot;type %x for name %s &quot;, type, global_myname ) );
363   DEBUGADD( 3, ( &quot;on subnet %s &quot;, subrec-&gt;subnet_name ) );
364   DEBUGADD( 3, ( &quot;for workgroup %s\n&quot;, work-&gt;work_group ) );
365 </pre><p>
366 A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
367 This macro returns True if the message level is less than or equal to
368 the global DEBUGLEVEL value, so:
369 </p><pre class="programlisting">
370   if( DEBUGLVL( 3 ) )
371     {
372     dbgtext( &quot;send_local_master_announcement: &quot; );
373     dbgtext( &quot;type %x for name %s &quot;, type, global_myname );
374     dbgtext( &quot;on subnet %s &quot;, subrec-&gt;subnet_name );
375     dbgtext( &quot;for workgroup %s\n&quot;, work-&gt;work_group );
376     }
377 </pre><p>(The dbgtext() function is explained below.)</p><p>There are a few advantages to this scheme:</p><div class="orderedlist"><ol type="1"><li><p>
378 The test is performed only once.
379 </p></li><li><p>
380 You can allocate variables off of the stack that will only be used
381 within the DEBUGLVL() block.
382 </p></li><li><p>
383 Processing that is only relevant to debug output can be contained
384 within the DEBUGLVL() block.
385 </p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2800044"></a>New Functions</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800051"></a>dbgtext()</h3></div></div><div></div></div><p>
386 This function prints debug message text to the debug file (and
387 possibly to syslog) via the format buffer. The function uses a
388 variable argument list just like printf() or Debug1(). The
389 input is printed into a buffer using the vslprintf() function,
390 and then passed to format_debug_text().
391
392 If you use DEBUGLVL() you will probably print the body of the
393 message using dbgtext(). 
394 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800071"></a>dbghdr()</h3></div></div><div></div></div><p>
395 This is the function that writes a debug message header.
396 Headers are not processed via the format buffer. Also note that
397 if the format buffer is not empty, a call to dbghdr() will not
398 produce any output. See the comments in dbghdr() for more info.
399 </p><p>
400 It is not likely that this function will be called directly. It
401 is used by DEBUG() and DEBUGADD().
402 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800094"></a>format_debug_text()</h3></div></div><div></div></div><p>
403 This is a static function in debug.c. It stores the output text
404 for the body of the message in a buffer until it encounters a
405 newline. When the newline character is found, the buffer is
406 written to the debug file via the Debug1() function, and the
407 buffer is reset. This allows us to add the indentation at the
408 beginning of each line of the message body, and also ensures
409 that the output is written a line at a time (which cleans up
410 syslog output).
411 </p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="CodingSuggestions"></a>Chapter 4. Coding Suggestions</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Steve</span> <span class="surname">French</span></h3></div></div><div><div class="author"><h3 class="author"><span class="firstname">Simo</span> <span class="surname">Sorce</span></h3></div></div><div><div class="author"><h3 class="author"><span class="firstname">Andrew</span> <span class="surname">Bartlett</span></h3></div></div><div><div class="author"><h3 class="author"><span class="firstname">Tim</span> <span class="surname">Potter</span></h3></div></div><div><div class="author"><h3 class="author"><span class="firstname">Martin</span> <span class="surname">Pool</span></h3></div></div></div><div></div></div><p>
412 So you want to add code to Samba ...
413 </p><p>
414 One of the daunting tasks facing a programmer attempting to write code for
415 Samba is understanding the various coding conventions used by those most
416 active in the project.  These conventions were mostly unwritten and helped
417 improve either the portability, stability or consistency of the code. This
418 document will attempt to document a few of the more important coding
419 practices used at this time on the Samba project.  The coding practices are
420 expected to change slightly over time, and even to grow as more is learned
421 about obscure portability considerations.  Two existing documents
422 <tt class="filename">samba/source/internals.doc</tt> and 
423 <tt class="filename">samba/source/architecture.doc</tt> provide
424 additional information.
425 </p><p>
426 The loosely related question of coding style is very personal and this
427 document does not attempt to address that subject, except to say that I
428 have observed that eight character tabs seem to be preferred in Samba
429 source.  If you are interested in the topic of coding style, two oft-quoted
430 documents are:
431 </p><p>
432 <a href="http://lxr.linux.no/source/Documentation/CodingStyle" target="_top">http://lxr.linux.no/source/Documentation/CodingStyle</a>
433 </p><p>
434 <a href="http://www.fsf.org/prep/standards_toc.html" target="_top">http://www.fsf.org/prep/standards_toc.html</a>
435 </p><p>
436 But note that coding style in Samba varies due to the many different
437 programmers who have contributed.
438 </p><p>
439 Following are some considerations you should use when adding new code to
440 Samba.  First and foremost remember that:
441 </p><p>
442 Portability is a primary consideration in adding function, as is network
443 compatability with de facto, existing, real world CIFS/SMB implementations.
444 There are lots of platforms that Samba builds on so use caution when adding
445 a call to a library function that is not invoked in existing Samba code.
446 Also note that there are many quite different SMB/CIFS clients that Samba
447 tries to support, not all of which follow the SNIA CIFS Technical Reference
448 (or the earlier Microsoft reference documents or the X/Open book on the SMB
449 Standard) perfectly.
450 </p><p>
451 Here are some other suggestions:
452 </p><div class="orderedlist"><ol type="1"><li><p>
453         use d_printf instead of printf for display text
454         reason: enable auto-substitution of translated language text 
455 </p></li><li><p>
456         use SAFE_FREE instead of free
457         reason: reduce traps due to null pointers
458 </p></li><li><p>
459         don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
460         reason: not POSIX
461 </p></li><li><p>
462         don't use strcpy and strlen (use safe_* equivalents)
463         reason: to avoid traps due to buffer overruns
464 </p></li><li><p>
465         don't use getopt_long, use popt functions instead
466         reason: portability
467 </p></li><li><p>
468         explicitly add const qualifiers on parm passing in functions where parm
469         is input only (somewhat controversial but const can be #defined away)
470 </p></li><li><p>
471         when passing a va_list as an arg, or assigning one to another
472         please use the VA_COPY() macro
473         reason: on some platforms, va_list is a struct that must be 
474         initialized in each function...can SEGV if you don't.
475 </p></li><li><p>
476         discourage use of threads
477         reason: portability (also see architecture.doc)
478 </p></li><li><p>
479         don't explicitly include new header files in C files - new h files 
480         should be included by adding them once to includes.h
481         reason: consistency
482 </p></li><li><p>
483         don't explicitly extern functions (they are autogenerated by 
484         &quot;make proto&quot; into proto.h)
485         reason: consistency
486 </p></li><li><p>
487         use endian safe macros when unpacking SMBs (see byteorder.h and
488         internals.doc)
489         reason: not everyone uses Intel
490 </p></li><li><p>
491         Note Unicode implications of charset handling (see internals.doc).  See
492         pull_*  and push_* and convert_string functions.
493         reason: Internationalization
494 </p></li><li><p>
495         Don't assume English only
496         reason: See above
497 </p></li><li><p>
498         Try to avoid using in/out parameters (functions that return data which
499         overwrites input parameters)
500         reason: Can cause stability problems
501 </p></li><li><p>
502         Ensure copyright notices are correct, don't append Tridge's name to code
503         that he didn't write.  If you did not write the code, make sure that it
504         can coexist with the rest of the Samba GPLed code.
505 </p></li><li><p>
506         Consider usage of DATA_BLOBs for length specified byte-data.
507         reason: stability
508 </p></li><li><p>
509         Take advantage of tdbs for database like function
510         reason: consistency
511 </p></li><li><p>
512         Don't access the SAM_ACCOUNT structure directly, they should be accessed
513         via pdb_get...() and pdb_set...() functions.
514         reason: stability, consistency
515 </p></li><li><p>
516         Don't check a password directly against the passdb, always use the
517         check_password() interface.
518         reason: long term pluggability
519 </p></li><li><p>
520         Try to use asprintf rather than pstrings and fstrings where possible
521 </p></li><li><p>
522         Use normal C comments / * instead of C++ comments // like
523         this.  Although the C++ comment format is part of the C99
524         standard, some older vendor C compilers do not accept it.
525 </p></li><li><p>
526         Try to write documentation for API functions and structures
527         explaining the point of the code, the way it should be used, and
528         any special conditions or results.  Mark these with a double-star
529         comment start / ** so that they can be picked up by Doxygen, as in
530         this file.
531 </p></li><li><p>
532         Keep the scope narrow. This means making functions/variables
533         static whenever possible. We don't want our namespace
534         polluted. Each module should have a minimal number of externally
535         visible functions or variables.
536 </p></li><li><p>
537         Use function pointers to keep knowledge about particular pieces of
538         code isolated in one place. We don't want a particular piece of
539         functionality to be spread out across lots of places - that makes
540         for fragile, hand to maintain code. Instead, design an interface
541         and use tables containing function pointers to implement specific
542         functionality. This is particularly important for command
543         interpreters. 
544 </p></li><li><p>
545         Think carefully about what it will be like for someone else to add
546         to and maintain your code. If it would be hard for someone else to
547         maintain then do it another way. 
548 </p></li></ol></div><p>
549 The suggestions above are simply that, suggestions, but the information may
550 help in reducing the routine rework done on new code.  The preceeding list
551 is expected to change routinely as new support routines and macros are
552 added.
553 </p></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="internals"></a>Chapter 5. Samba Internals</h2></div><div><div class="author"><h3 class="author"><span class="firstname">David</span> <span class="surname">Chappell</span></h3><div class="affiliation"><div class="address"><p><tt class="email">&lt;<a href="mailto:David.Chappell@mail.trincoll.edu">David.Chappell@mail.trincoll.edu</a>&gt;</tt></p></div></div></div></div><div><p class="pubdate">8 May 1996</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2800556">Character Handling</a></dt><dt><a href="#id2800582">The new functions</a></dt><dt><a href="#id2800742">Macros in byteorder.h</a></dt><dd><dl><dt><a href="#id2800755">CVAL(buf,pos)</a></dt><dt><a href="#id2800769">PVAL(buf,pos)</a></dt><dt><a href="#id2800783">SCVAL(buf,pos,val)</a></dt><dt><a href="#id2800795">SVAL(buf,pos)</a></dt><dt><a href="#id2800815">IVAL(buf,pos)</a></dt><dt><a href="#id2800829">SVALS(buf,pos)</a></dt><dt><a href="#id2800844">IVALS(buf,pos)</a></dt><dt><a href="#id2800858">SSVAL(buf,pos,val)</a></dt><dt><a href="#id2800872">SIVAL(buf,pos,val)</a></dt><dt><a href="#id2800887">SSVALS(buf,pos,val)</a></dt><dt><a href="#id2800901">SIVALS(buf,pos,val)</a></dt><dt><a href="#id2800916">RSVAL(buf,pos)</a></dt><dt><a href="#id2800930">RIVAL(buf,pos)</a></dt><dt><a href="#id2800944">RSSVAL(buf,pos,val)</a></dt><dt><a href="#id2866314">RSIVAL(buf,pos,val)</a></dt></dl></dd><dt><a href="#id2866329">LAN Manager Samba API</a></dt><dd><dl><dt><a href="#id2866366">Parameters</a></dt><dt><a href="#id2866517">Return value</a></dt></dl></dd><dt><a href="#id2866617">Code character table</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2800556"></a>Character Handling</h2></div></div><div></div></div><p>
554 This section describes character set handling in Samba, as implemented in
555 Samba 3.0 and above
556 </p><p>
557 In the past Samba had very ad-hoc character set handling. Scattered
558 throughout the code were numerous calls which converted particular
559 strings to/from DOS codepages. The problem is that there was no way of
560 telling if a particular char* is in dos codepage or unix
561 codepage. This led to a nightmare of code that tried to cope with
562 particular cases without handlingt the general case.
563 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2800582"></a>The new functions</h2></div></div><div></div></div><p>
564 The new system works like this:
565 </p><div class="orderedlist"><ol type="1"><li><p>
566         all char* strings inside Samba are &quot;unix&quot; strings. These are
567         multi-byte strings that are in the charset defined by the &quot;unix
568         charset&quot; option in smb.conf. 
569 </p></li><li><p>
570         there is no single fixed character set for unix strings, but any
571         character set that is used does need the following properties:
572         </p><div class="orderedlist"><ol type="a"><li><p>
573                 must not contain NULLs except for termination
574         </p></li><li><p>
575                 must be 7-bit compatible with C strings, so that a constant
576                 string or character in C will be byte-for-byte identical to the
577                 equivalent string in the chosen character set. 
578         </p></li><li><p>
579                 when you uppercase or lowercase a string it does not become
580                 longer than the original string
581         </p></li><li><p>
582                 must be able to correctly hold all characters that your client
583                 will throw at it
584         </p></li></ol></div><p>
585         For example, UTF-8 is fine, and most multi-byte asian character sets
586         are fine, but UCS2 could not be used for unix strings as they
587         contain nulls.
588         </p></li><li><p>
589         when you need to put a string into a buffer that will be sent on the
590         wire, or you need a string in a character set format that is
591         compatible with the clients character set then you need to use a
592         pull_ or push_ function. The pull_ functions pull a string from a
593         wire buffer into a (multi-byte) unix string. The push_ functions
594         push a string out to a wire buffer. 
595 </p></li><li><p>
596         the two main pull_ and push_ functions you need to understand are
597         pull_string and push_string. These functions take a base pointer
598         that should point at the start of the SMB packet that the string is
599         in. The functions will check the flags field in this packet to
600         automatically determine if the packet is marked as a unicode packet,
601         and they will choose whether to use unicode for this string based on
602         that flag. You may also force this decision using the STR_UNICODE or
603         STR_ASCII flags. For use in smbd/ and libsmb/ there are wrapper
604         functions clistr_ and srvstr_ that call the pull_/push_ functions
605         with the appropriate first argument.
606         </p><p>
607         You may also call the pull_ascii/pull_ucs2 or push_ascii/push_ucs2
608         functions if you know that a particular string is ascii or
609         unicode. There are also a number of other convenience functions in
610         charcnv.c that call the pull_/push_ functions with particularly
611         common arguments, such as pull_ascii_pstring()
612         </p></li><li><p>
613         The biggest thing to remember is that internal (unix) strings in Samba
614         may now contain multi-byte characters. This means you cannot assume
615         that characters are always 1 byte long. Often this means that you will
616         have to convert strings to ucs2 and back again in order to do some
617         (seemingly) simple task. For examples of how to do this see functions
618         like strchr_m(). I know this is very slow, and we will eventually
619         speed it up but right now we want this stuff correct not fast.
620 </p></li><li><p>
621         all lp_ functions now return unix strings. The magic &quot;DOS&quot; flag on
622         parameters is gone.
623 </p></li><li><p>
624         all vfs functions take unix strings. Don't convert when passing to them
625 </p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2800742"></a>Macros in byteorder.h</h2></div></div><div></div></div><p>
626 This section describes the macros defined in byteorder.h.  These macros 
627 are used extensively in the Samba code.
628 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800755"></a>CVAL(buf,pos)</h3></div></div><div></div></div><p>
629 returns the byte at offset pos within buffer buf as an unsigned character.
630 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800769"></a>PVAL(buf,pos)</h3></div></div><div></div></div><p>returns the value of CVAL(buf,pos) cast to type unsigned integer.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800783"></a>SCVAL(buf,pos,val)</h3></div></div><div></div></div><p>sets the byte at offset pos within buffer buf to value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800795"></a>SVAL(buf,pos)</h3></div></div><div></div></div><p>
631         returns the value of the unsigned short (16 bit) little-endian integer at 
632         offset pos within buffer buf.  An integer of this type is sometimes
633         refered to as &quot;USHORT&quot;.
634 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800815"></a>IVAL(buf,pos)</h3></div></div><div></div></div><p>returns the value of the unsigned 32 bit little-endian integer at offset 
635 pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800829"></a>SVALS(buf,pos)</h3></div></div><div></div></div><p>returns the value of the signed short (16 bit) little-endian integer at 
636 offset pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800844"></a>IVALS(buf,pos)</h3></div></div><div></div></div><p>returns the value of the signed 32 bit little-endian integer at offset pos
637 within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800858"></a>SSVAL(buf,pos,val)</h3></div></div><div></div></div><p>sets the unsigned short (16 bit) little-endian integer at offset pos within 
638 buffer buf to value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800872"></a>SIVAL(buf,pos,val)</h3></div></div><div></div></div><p>sets the unsigned 32 bit little-endian integer at offset pos within buffer 
639 buf to the value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800887"></a>SSVALS(buf,pos,val)</h3></div></div><div></div></div><p>sets the short (16 bit) signed little-endian integer at offset pos within 
640 buffer buf to the value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800901"></a>SIVALS(buf,pos,val)</h3></div></div><div></div></div><p>sets the signed 32 bit little-endian integer at offset pos withing buffer
641 buf to the value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800916"></a>RSVAL(buf,pos)</h3></div></div><div></div></div><p>returns the value of the unsigned short (16 bit) big-endian integer at 
642 offset pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800930"></a>RIVAL(buf,pos)</h3></div></div><div></div></div><p>returns the value of the unsigned 32 bit big-endian integer at offset 
643 pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2800944"></a>RSSVAL(buf,pos,val)</h3></div></div><div></div></div><p>sets the value of the unsigned short (16 bit) big-endian integer at 
644 offset pos within buffer buf to value val.
645 refered to as &quot;USHORT&quot;.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2866314"></a>RSIVAL(buf,pos,val)</h3></div></div><div></div></div><p>sets the value of the unsigned 32 bit big-endian integer at offset 
646 pos within buffer buf to value val.</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2866329"></a>LAN Manager Samba API</h2></div></div><div></div></div><p>
647 This section describes the functions need to make a LAN Manager RPC call.
648 This information had been obtained by examining the Samba code and the LAN
649 Manager 2.0 API documentation.  It should not be considered entirely
650 reliable.
651 </p><p>
652 </p><pre class="programlisting">
653 call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt, 
654         char *param, char *data, char **rparam, char **rdata);
655 </pre><p>
656 </p><p>
657 This function is defined in client.c.  It uses an SMB transaction to call a
658 remote api.
659 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2866366"></a>Parameters</h3></div></div><div></div></div><p>The parameters are as follows:</p><div class="orderedlist"><ol type="1"><li><p>
660         prcnt: the number of bytes of parameters begin sent.
661 </p></li><li><p>
662         drcnt:   the number of bytes of data begin sent.
663 </p></li><li><p>
664         mprcnt:  the maximum number of bytes of parameters which should be returned
665 </p></li><li><p>
666         mdrcnt:  the maximum number of bytes of data which should be returned
667 </p></li><li><p>
668         param:   a pointer to the parameters to be sent.
669 </p></li><li><p>
670         data:    a pointer to the data to be sent.
671 </p></li><li><p>
672         rparam:  a pointer to a pointer which will be set to point to the returned
673         paramters.  The caller of call_api() must deallocate this memory.
674 </p></li><li><p>
675         rdata:   a pointer to a pointer which will be set to point to the returned 
676         data.  The caller of call_api() must deallocate this memory.
677 </p></li></ol></div><p>
678 These are the parameters which you ought to send, in the order of their
679 appearance in the parameter block:
680 </p><div class="orderedlist"><ol type="1"><li><p>
681 An unsigned 16 bit integer API number.  You should set this value with
682 SSVAL().  I do not know where these numbers are described.
683 </p></li><li><p>
684 An ASCIIZ string describing the parameters to the API function as defined
685 in the LAN Manager documentation.  The first parameter, which is the server
686 name, is ommited.  This string is based uppon the API function as described
687 in the manual, not the data which is actually passed.
688 </p></li><li><p>
689 An ASCIIZ string describing the data structure which ought to be returned.
690 </p></li><li><p>
691 Any parameters which appear in the function call, as defined in the LAN
692 Manager API documentation, after the &quot;Server&quot; and up to and including the
693 &quot;uLevel&quot; parameters.
694 </p></li><li><p>
695 An unsigned 16 bit integer which gives the size in bytes of the buffer we
696 will use to receive the returned array of data structures.  Presumably this
697 should be the same as mdrcnt.  This value should be set with SSVAL().
698 </p></li><li><p>
699 An ASCIIZ string describing substructures which should be returned.  If no 
700 substructures apply, this string is of zero length.
701 </p></li></ol></div><p>
702 The code in client.c always calls call_api() with no data.  It is unclear
703 when a non-zero length data buffer would be sent.
704 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2866517"></a>Return value</h3></div></div><div></div></div><p>
705 The returned parameters (pointed to by rparam), in their order of appearance
706 are:</p><div class="orderedlist"><ol type="1"><li><p>
707 An unsigned 16 bit integer which contains the API function's return code. 
708 This value should be read with SVAL().
709 </p></li><li><p>
710 An adjustment which tells the amount by which pointers in the returned
711 data should be adjusted.  This value should be read with SVAL().  Basically, 
712 the address of the start of the returned data buffer should have the returned
713 pointer value added to it and then have this value subtracted from it in
714 order to obtain the currect offset into the returned data buffer.
715 </p></li><li><p>
716 A count of the number of elements in the array of structures returned. 
717 It is also possible that this may sometimes be the number of bytes returned.
718 </p></li></ol></div><p>
719 When call_api() returns, rparam points to the returned parameters.  The
720 first if these is the result code.  It will be zero if the API call
721 suceeded.  This value by be read with &quot;SVAL(rparam,0)&quot;.
722 </p><p>
723 The second parameter may be read as &quot;SVAL(rparam,2)&quot;.  It is a 16 bit offset
724 which indicates what the base address of the returned data buffer was when
725 it was built on the server.  It should be used to correct pointer before
726 use.
727 </p><p>
728 The returned data buffer contains the array of returned data structures. 
729 Note that all pointers must be adjusted before use.  The function
730 fix_char_ptr() in client.c can be used for this purpose.
731 </p><p>
732 The third parameter (which may be read as &quot;SVAL(rparam,4)&quot;) has something to
733 do with indicating the amount of data returned or possibly the amount of
734 data which can be returned if enough buffer space is allowed.
735 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2866617"></a>Code character table</h2></div></div><div></div></div><p>
736 Certain data structures are described by means of ASCIIz strings containing
737 code characters.  These are the code characters:
738 </p><div class="orderedlist"><ol type="1"><li><p>
739 W       a type byte little-endian unsigned integer
740 </p></li><li><p>
741 N       a count of substructures which follow
742 </p></li><li><p>
743 D       a four byte little-endian unsigned integer
744 </p></li><li><p>
745 B       a byte (with optional count expressed as trailing ASCII digits)
746 </p></li><li><p>
747 z       a four byte offset to a NULL terminated string
748 </p></li><li><p>
749 l       a four byte offset to non-string user data
750 </p></li><li><p>
751 b       an offset to data (with count expressed as trailing ASCII digits)
752 </p></li><li><p>
753 r       pointer to returned data buffer???
754 </p></li><li><p>
755 L       length in bytes of returned data buffer???
756 </p></li><li><p>
757 h       number of bytes of information available???
758 </p></li></ol></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="parsing"></a>Chapter 6. The smb.conf file</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Chris</span> <span class="surname">Hertel</span></h3></div></div><div><p class="pubdate">November 1997</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2866736">Lexical Analysis</a></dt><dd><dl><dt><a href="#id2866826">Handling of Whitespace</a></dt><dt><a href="#id2866883">Handling of Line Continuation</a></dt><dt><a href="#id2866948">Line Continuation Quirks</a></dt></dl></dd><dt><a href="#id2867044">Syntax</a></dt><dd><dl><dt><a href="#id2867117">About params.c</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2866736"></a>Lexical Analysis</h2></div></div><div></div></div><p>
759 Basically, the file is processed on a line by line basis.  There are
760 four types of lines that are recognized by the lexical analyzer
761 (params.c):
762 </p><div class="orderedlist"><ol type="1"><li><p>
763 Blank lines - Lines containing only whitespace.
764 </p></li><li><p>
765 Comment lines - Lines beginning with either a semi-colon or a
766 pound sign (';' or '#').
767 </p></li><li><p>
768 Section header lines - Lines beginning with an open square bracket ('[').
769 </p></li><li><p>
770 Parameter lines - Lines beginning with any other character.
771 (The default line type.)
772 </p></li></ol></div><p>
773 The first two are handled exclusively by the lexical analyzer, which
774 ignores them.  The latter two line types are scanned for
775 </p><div class="orderedlist"><ol type="1"><li><p>
776   - Section names
777 </p></li><li><p>
778   - Parameter names
779 </p></li><li><p>
780   - Parameter values
781 </p></li></ol></div><p>
782 These are the only tokens passed to the parameter loader
783 (loadparm.c).  Parameter names and values are divided from one
784 another by an equal sign: '='.
785 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2866826"></a>Handling of Whitespace</h3></div></div><div></div></div><p>
786 Whitespace is defined as all characters recognized by the isspace()
787 function (see ctype(3C)) except for the newline character ('\n')
788 The newline is excluded because it identifies the end of the line.
789 </p><div class="orderedlist"><ol type="1"><li><p>
790 The lexical analyzer scans past white space at the beginning of a line.
791 </p></li><li><p>
792 Section and parameter names may contain internal white space.  All
793 whitespace within a name is compressed to a single space character. 
794 </p></li><li><p>
795 Internal whitespace within a parameter value is kept verbatim with 
796 the exception of carriage return characters ('\r'), all of which
797 are removed.
798 </p></li><li><p>
799 Leading and trailing whitespace is removed from names and values.
800 </p></li></ol></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2866883"></a>Handling of Line Continuation</h3></div></div><div></div></div><p>
801 Long section header and parameter lines may be extended across
802 multiple lines by use of the backslash character ('\\').  Line
803 continuation is ignored for blank and comment lines.
804 </p><p>
805 If the last (non-whitespace) character within a section header or on
806 a parameter line is a backslash, then the next line will be
807 (logically) concatonated with the current line by the lexical
808 analyzer.  For example:
809 </p><pre class="programlisting">
810         param name = parameter value string \
811         with line continuation.
812 </pre><p>Would be read as</p><pre class="programlisting">
813     param name = parameter value string     with line continuation.
814 </pre><p>
815 Note that there are five spaces following the word 'string',
816 representing the one space between 'string' and '\\' in the top
817 line, plus the four preceeding the word 'with' in the second line.
818 (Yes, I'm counting the indentation.)
819 </p><p>
820 Line continuation characters are ignored on blank lines and at the end
821 of comments.  They are *only* recognized within section and parameter
822 lines.
823 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2866948"></a>Line Continuation Quirks</h3></div></div><div></div></div><p>Note the following example:</p><pre class="programlisting">
824         param name = parameter value string \
825     \
826     with line continuation.
827 </pre><p>
828 The middle line is *not* parsed as a blank line because it is first
829 concatonated with the top line.  The result is
830 </p><pre class="programlisting">
831 param name = parameter value string         with line continuation.
832 </pre><p>The same is true for comment lines.</p><pre class="programlisting">
833         param name = parameter value string \
834         ; comment \
835     with a comment.
836 </pre><p>This becomes:</p><pre class="programlisting">
837 param name = parameter value string     ; comment     with a comment.
838 </pre><p>
839 On a section header line, the closing bracket (']') is considered a
840 terminating character, and the rest of the line is ignored.  The lines
841 </p><pre class="programlisting">
842         [ section   name ] garbage \
843     param  name  = value
844 </pre><p>are read as</p><pre class="programlisting">
845         [section name]
846     param name = value
847 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867044"></a>Syntax</h2></div></div><div></div></div><p>The syntax of the smb.conf file is as follows:</p><pre class="programlisting">
848   &lt;file&gt;            :==  { &lt;section&gt; } EOF
849   &lt;section&gt;         :==  &lt;section header&gt; { &lt;parameter line&gt; }
850   &lt;section header&gt;  :==  '[' NAME ']'
851   &lt;parameter line&gt;  :==  NAME '=' VALUE NL
852 </pre><p>Basically, this means that</p><div class="orderedlist"><ol type="1"><li><p>
853         a file is made up of zero or more sections, and is terminated by
854         an EOF (we knew that).
855 </p></li><li><p>
856         A section is made up of a section header followed by zero or more
857         parameter lines.
858 </p></li><li><p>
859         A section header is identified by an opening bracket and
860         terminated by the closing bracket.  The enclosed NAME identifies
861         the section.
862 </p></li><li><p>
863         A parameter line is divided into a NAME and a VALUE.  The *first*
864         equal sign on the line separates the NAME from the VALUE.  The
865         VALUE is terminated by a newline character (NL = '\n').
866 </p></li></ol></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2867117"></a>About params.c</h3></div></div><div></div></div><p>
867 The parsing of the config file is a bit unusual if you are used to
868 lex, yacc, bison, etc.  Both lexical analysis (scanning) and parsing
869 are performed by params.c.  Values are loaded via callbacks to
870 loadparm.c.
871 </p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="unix-smb"></a>Chapter 7. NetBIOS in a Unix World</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Andrew</span> <span class="surname">Tridgell</span></h3></div></div><div><p class="pubdate">April 1995</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2867166">Introduction</a></dt><dt><a href="#id2867191">Usernames</a></dt><dt><a href="#id2867277">File Ownership</a></dt><dt><a href="#id2867326">Passwords</a></dt><dt><a href="#id2867388">Locking</a></dt><dt><a href="#id2867458">Deny Modes</a></dt><dt><a href="#id2867499">Trapdoor UIDs</a></dt><dt><a href="#id2867526">Port numbers</a></dt><dt><a href="#id2867572">Protocol Complexity</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867166"></a>Introduction</h2></div></div><div></div></div><p>
872 This is a short document that describes some of the issues that
873 confront a SMB implementation on unix, and how Samba copes with
874 them. They may help people who are looking at unix&lt;-&gt;PC
875 interoperability.
876 </p><p>
877 It was written to help out a person who was writing a paper on unix to
878 PC connectivity.
879 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867191"></a>Usernames</h2></div></div><div></div></div><p>
880 The SMB protocol has only a loose username concept. Early SMB
881 protocols (such as CORE and COREPLUS) have no username concept at
882 all. Even in later protocols clients often attempt operations
883 (particularly printer operations) without first validating a username
884 on the server.
885 </p><p>
886 Unix security is based around username/password pairs. A unix box
887 should not allow clients to do any substantive operation without some
888 sort of validation. 
889 </p><p>
890 The problem mostly manifests itself when the unix server is in &quot;share
891 level&quot; security mode. This is the default mode as the alternative
892 &quot;user level&quot; security mode usually forces a client to connect to the
893 server as the same user for each connected share, which is
894 inconvenient in many sites.
895 </p><p>
896 In &quot;share level&quot; security the client normally gives a username in the
897 &quot;session setup&quot; protocol, but does not supply an accompanying
898 password. The client then connects to resources using the &quot;tree
899 connect&quot; protocol, and supplies a password. The problem is that the
900 user on the PC types the username and the password in different
901 contexts, unaware that they need to go together to give access to the
902 server. The username is normally the one the user typed in when they
903 &quot;logged onto&quot; the PC (this assumes Windows for Workgroups). The
904 password is the one they chose when connecting to the disk or printer.
905 </p><p>
906 The user often chooses a totally different username for their login as
907 for the drive connection. Often they also want to access different
908 drives as different usernames. The unix server needs some way of
909 divining the correct username to combine with each password.
910 </p><p>
911 Samba tries to avoid this problem using several methods. These succeed
912 in the vast majority of cases. The methods include username maps, the
913 service%user syntax, the saving of session setup usernames for later
914 validation and the derivation of the username from the service name
915 (either directly or via the user= option).
916 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867277"></a>File Ownership</h2></div></div><div></div></div><p>
917 The commonly used SMB protocols have no way of saying &quot;you can't do
918 that because you don't own the file&quot;. They have, in fact, no concept
919 of file ownership at all.
920 </p><p>
921 This brings up all sorts of interesting problems. For example, when
922 you copy a file to a unix drive, and the file is world writeable but
923 owned by another user the file will transfer correctly but will
924 receive the wrong date. This is because the utime() call under unix
925 only succeeds for the owner of the file, or root, even if the file is
926 world writeable. For security reasons Samba does all file operations
927 as the validated user, not root, so the utime() fails. This can stuff
928 up shared development diectories as programs like &quot;make&quot; will not get
929 file time comparisons right.
930 </p><p>
931 There are several possible solutions to this problem, including
932 username mapping, and forcing a specific username for particular
933 shares.
934 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867326"></a>Passwords</h2></div></div><div></div></div><p>
935 Many SMB clients uppercase passwords before sending them. I have no
936 idea why they do this. Interestingly WfWg uppercases the password only
937 if the server is running a protocol greater than COREPLUS, so
938 obviously it isn't just the data entry routines that are to blame.
939 </p><p>
940 Unix passwords are case sensitive. So if users use mixed case
941 passwords they are in trouble.
942 </p><p>
943 Samba can try to cope with this by either using the &quot;password level&quot;
944 option which causes Samba to try the offered password with up to the
945 specified number of case changes, or by using the &quot;password server&quot;
946 option which allows Samba to do its validation via another machine
947 (typically a WinNT server).
948 </p><p>
949 Samba supports the password encryption method used by SMB
950 clients. Note that the use of password encryption in Microsoft
951 networking leads to password hashes that are &quot;plain text equivalent&quot;.
952 This means that it is *VERY* important to ensure that the Samba
953 smbpasswd file containing these password hashes is only readable
954 by the root user. See the documentation ENCRYPTION.txt for more
955 details.
956 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867388"></a>Locking</h2></div></div><div></div></div><p>
957 Since samba 2.2, samba supports other types of locking as well. This 
958 section is outdated.
959 </p><p>
960 The locking calls available under a DOS/Windows environment are much
961 richer than those available in unix. This means a unix server (like
962 Samba) choosing to use the standard fcntl() based unix locking calls
963 to implement SMB locking has to improvise a bit.
964 </p><p>
965 One major problem is that dos locks can be in a 32 bit (unsigned)
966 range. Unix locking calls are 32 bits, but are signed, giving only a 31
967 bit range. Unfortunately OLE2 clients use the top bit to select a
968 locking range used for OLE semaphores.
969 </p><p>
970 To work around this problem Samba compresses the 32 bit range into 31
971 bits by appropriate bit shifting. This seems to work but is not
972 ideal. In a future version a separate SMB lockd may be added to cope
973 with the problem.
974 </p><p>
975 It also doesn't help that many unix lockd daemons are very buggy and
976 crash at the slightest provocation. They normally go mostly unused in
977 a unix environment because few unix programs use byte range
978 locking. The stress of huge numbers of lock requests from dos/windows
979 clients can kill the daemon on some systems.
980 </p><p>
981 The second major problem is the &quot;opportunistic locking&quot; requested by
982 some clients. If a client requests opportunistic locking then it is
983 asking the server to notify it if anyone else tries to do something on
984 the same file, at which time the client will say if it is willing to
985 give up its lock. Unix has no simple way of implementing
986 opportunistic locking, and currently Samba has no support for it.
987 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867458"></a>Deny Modes</h2></div></div><div></div></div><p>
988 When a SMB client opens a file it asks for a particular &quot;deny mode&quot; to
989 be placed on the file. These modes (DENY_NONE, DENY_READ, DENY_WRITE,
990 DENY_ALL, DENY_FCB and DENY_DOS) specify what actions should be
991 allowed by anyone else who tries to use the file at the same time. If
992 DENY_READ is placed on the file, for example, then any attempt to open
993 the file for reading should fail.
994 </p><p>
995 Unix has no equivalent notion. To implement this Samba uses either lock
996 files based on the files inode and placed in a separate lock
997 directory or a shared memory implementation. The lock file method 
998 is clumsy and consumes processing and file resources,
999 the shared memory implementation is vastly prefered and is turned on
1000 by default for those systems that support it.
1001 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867499"></a>Trapdoor UIDs</h2></div></div><div></div></div><p>
1002 A SMB session can run with several uids on the one socket. This
1003 happens when a user connects to two shares with different
1004 usernames. To cope with this the unix server needs to switch uids
1005 within the one process. On some unixes (such as SCO) this is not
1006 possible. This means that on those unixes the client is restricted to
1007 a single uid.
1008 </p><p>
1009 Note that you can also get the &quot;trapdoor uid&quot; message for other
1010 reasons. Please see the FAQ for details.
1011 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867526"></a>Port numbers</h2></div></div><div></div></div><p>
1012 There is a convention that clients on sockets use high &quot;unprivilaged&quot;
1013 port numbers (&gt;1000) and connect to servers on low &quot;privilaged&quot; port
1014 numbers. This is enforced in Unix as non-root users can't open a
1015 socket for listening on port numbers less than 1000.
1016 </p><p>
1017 Most PC based SMB clients (such as WfWg and WinNT) don't follow this
1018 convention completely. The main culprit is the netbios nameserving on
1019 udp port 137. Name query requests come from a source port of 137. This
1020 is a problem when you combine it with the common firewalling technique
1021 of not allowing incoming packets on low port numbers. This means that
1022 these clients can't query a netbios nameserver on the other side of a
1023 low port based firewall.
1024 </p><p>
1025 The problem is more severe with netbios node status queries. I've
1026 found that WfWg, Win95 and WinNT3.5 all respond to netbios node status
1027 queries on port 137 no matter what the source port was in the
1028 request. This works between machines that are both using port 137, but
1029 it means it's not possible for a unix user to do a node status request
1030 to any of these OSes unless they are running as root. The answer comes
1031 back, but it goes to port 137 which the unix user can't listen
1032 on. Interestingly WinNT3.1 got this right - it sends node status
1033 responses back to the source port in the request.
1034 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867572"></a>Protocol Complexity</h2></div></div><div></div></div><p>
1035 There are many &quot;protocol levels&quot; in the SMB protocol. It seems that
1036 each time new functionality was added to a Microsoft operating system,
1037 they added the equivalent functions in a new protocol level of the SMB
1038 protocol to &quot;externalise&quot; the new capabilities.
1039 </p><p>
1040 This means the protocol is very &quot;rich&quot;, offering many ways of doing
1041 each file operation. This means SMB servers need to be complex and
1042 large. It also means it is very difficult to make them bug free. It is
1043 not just Samba that suffers from this problem, other servers such as
1044 WinNT don't support every variation of every call and it has almost
1045 certainly been a headache for MS developers to support the myriad of
1046 SMB calls that are available.
1047 </p><p>
1048 There are about 65 &quot;top level&quot; operations in the SMB protocol (things
1049 like SMBread and SMBwrite). Some of these include hundreds of
1050 sub-functions (SMBtrans has at least 120 sub-functions, like
1051 DosPrintQAdd and NetSessionEnum). All of them take several options
1052 that can change the way they work. Many take dozens of possible
1053 &quot;information levels&quot; that change the structures that need to be
1054 returned. Samba supports all but 2 of the &quot;top level&quot; functions. It
1055 supports only 8 (so far) of the SMBtrans sub-functions. Even NT
1056 doesn't support them all.
1057 </p><p>
1058 Samba currently supports up to the &quot;NT LM 0.12&quot; protocol, which is the
1059 one preferred by Win95 and WinNT3.5. Luckily this protocol level has a
1060 &quot;capabilities&quot; field which specifies which super-duper new-fangled
1061 options the server suports. This helps to make the implementation of
1062 this protocol level much easier.
1063 </p><p>
1064 There is also a problem with the SMB specications. SMB is a X/Open
1065 spec, but the X/Open book is far from ideal, and fails to cover many
1066 important issues, leaving much to the imagination. Microsoft recently
1067 renamed the SMB protocol CIFS (Common Internet File System) and have 
1068 published new specifications. These are far superior to the old 
1069 X/Open documents but there are still undocumented calls and features. 
1070 This specification is actively being worked on by a CIFS developers 
1071 mailing list hosted by Microsft.
1072 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="tracing"></a>Chapter 8. Tracing samba system calls</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Andrew</span> <span class="surname">Tridgell</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span></div></div></div></div><div></div></div><p>
1073 This file describes how to do a system call trace on Samba to work out
1074 what its doing wrong. This is not for the faint of heart, but if you
1075 are reading this then you are probably desperate.
1076 </p><p>
1077 Actually its not as bad as the the above makes it sound, just don't
1078 expect the output to be very pretty :-)
1079 </p><p>
1080 Ok, down to business. One of the big advantages of unix systems is
1081 that they nearly all come with a system trace utility that allows you
1082 to monitor all system calls that a program is making. This is
1083 extremely using for debugging and also helps when trying to work out
1084 why something is slower than you expect. You can use system tracing
1085 without any special compilation options. 
1086 </p><p>
1087 The system trace utility is called different things on different
1088 systems. On Linux systems its called strace. Under SunOS 4 its called
1089 trace. Under SVR4 style systems (including solaris) its called
1090 truss. Under many BSD systems its called ktrace. 
1091 </p><p>
1092 The first thing you should do is read the man page for your native
1093 system call tracer. In the discussion below I'll assume its called
1094 strace as strace is the only portable system tracer (its available for
1095 free for many unix types) and its also got some of the nicest
1096 features.
1097 </p><p>
1098 Next, try using strace on some simple commands. For example, <b class="command">strace
1099 ls</b> or <b class="command">strace echo hello</b>.
1100 </p><p> 
1101 You'll notice that it produces a LOT of output. It is showing you the
1102 arguments to every system call that the program makes and the
1103 result. Very little happens in a program without a system call so you
1104 get lots of output. You'll also find that it produces a lot of
1105 &quot;preamble&quot; stuff showing the loading of shared libraries etc. Ignore
1106 this (unless its going wrong!)
1107 </p><p>
1108 For example, the only line that really matters in the <b class="command">strace echo
1109 hello</b> output is:
1110 </p><pre class="programlisting">
1111 write(1, &quot;hello\n&quot;, 6)                  = 6
1112 </pre><p>all the rest is just setting up to run the program.</p><p>
1113 Ok, now you're familiar with strace. To use it on Samba you need to
1114 strace the running smbd daemon. The way I tend ot use it is to first
1115 login from my Windows PC to the Samba server, then use smbstatus to
1116 find which process ID that client is attached to, then as root I do
1117 <b class="command">strace -p PID</b> to attach to that process. I normally redirect the
1118 stderr output from this command to a file for later perusal. For
1119 example, if I'm using a csh style shell:
1120 </p><p><b class="command">strace -f -p 3872 &gt;&amp; strace.out</b></p><p>or with a sh style shell:</p><p><b class="command">strace -f -p 3872 &gt; strace.out 2&gt;&amp;1</b></p><p>
1121 Note the &quot;-f&quot; option. This is only available on some systems, and
1122 allows you to trace not just the current process, but any children it
1123 forks. This is great for finding printing problems caused by the
1124 &quot;print command&quot; being wrong.
1125 </p><p>
1126 Once you are attached you then can do whatever it is on the client
1127 that is causing problems and you will capture all the system calls
1128 that smbd makes. 
1129 </p><p>
1130 So how do you interpret the results? Generally I search through the
1131 output for strings that I know will appear when the problem
1132 happens. For example, if I am having touble with permissions on a file
1133 I would search for that files name in the strace output and look at
1134 the surrounding lines. Another trick is to match up file descriptor
1135 numbers and &quot;follow&quot; what happens to an open file until it is closed.
1136 </p><p>
1137 Beyond this you will have to use your initiative. To give you an idea
1138 of what you are looking for here is a piece of strace output that
1139 shows that <tt class="filename">/dev/null</tt> is not world writeable, which
1140 causes printing to fail with Samba:
1141 </p><pre class="programlisting">
1142 [pid 28268] open(&quot;/dev/null&quot;, O_RDWR)   = -1 EACCES (Permission denied)
1143 [pid 28268] open(&quot;/dev/null&quot;, O_WRONLY) = -1 EACCES (Permission denied)
1144 </pre><p>
1145 The process is trying to first open <tt class="filename">/dev/null</tt> read-write 
1146 then read-only. Both fail. This means <tt class="filename">/dev/null</tt> has 
1147 incorrect permissions.
1148 </p></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="windows-debug"></a>Chapter 9. Finding useful information on windows</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Jelmer</span> <span class="othername">R.</span> <span class="surname">Vernooij</span></h3><div class="affiliation"><span class="orgname">The Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:jelmer@samba.org">jelmer@samba.org</a>&gt;</tt></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Andrew</span> <span class="surname">Tridgell</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:tridge@samba.org">tridge@samba.org</a>&gt;</tt></p></div></div></div></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2867998">Netlogon debugging output</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2867998"></a>Netlogon debugging output</h2></div></div><div></div></div><div class="procedure"><ol type="1"><li><p>stop netlogon service on PDC</p></li><li><p>rename original netlogon.dll to netlogon.dll.original</p></li><li><p>copy checked version of netlogon.dll to system32 directory</p></li><li><p>set HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters\DBFlag to 0x20000004</p></li><li><p>start netlogon service on PDC</p></li></ol></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="ntdomain"></a>Chapter 10. NT Domain RPC's</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Luke</span> <span class="surname">Leighton</span></h3><div class="affiliation"><div class="address"><p><tt class="email">&lt;<a href="mailto:lkcl@switchboard.net">lkcl@switchboard.net</a>&gt;</tt></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Paul</span> <span class="surname">Ashton</span></h3><div class="affiliation"><div class="address"><p><tt class="email">&lt;<a href="mailto:paul@argo.demon.co.uk">paul@argo.demon.co.uk</a>&gt;</tt></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Duncan</span> <span class="surname">Stansfield</span></h3><div class="affiliation"><div class="address"><p><tt class="email">&lt;<a href="mailto:duncans@sco.com">duncans@sco.com</a>&gt;</tt></p></div></div></div></div><div><p class="pubdate">01 November 97(version 0.0.24)</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2868139">Introduction</a></dt><dd><dl><dt><a href="#id2868342">Sources</a></dt><dt><a href="#id2868377">Credits</a></dt></dl></dd><dt><a href="#id2868416">Notes and Structures</a></dt><dd><dl><dt><a href="#id2868423">Notes</a></dt><dt><a href="#id2868506">Enumerations</a></dt><dt><a href="#id2868718">Structures</a></dt></dl></dd><dt><a href="#id2871669">MSRPC over Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2871682">MSRPC Pipes</a></dt><dt><a href="#id2871787">Header</a></dt><dt><a href="#id2872660">Tail</a></dt><dt><a href="#id2872706">RPC Bind / Bind Ack</a></dt><dt><a href="#id2872896">NTLSA Transact Named Pipe</a></dt><dt><a href="#id2873062">LSA Open Policy</a></dt><dt><a href="#id2873187">LSA Query Info Policy</a></dt><dt><a href="#id2873296">LSA Enumerate Trusted Domains</a></dt><dt><a href="#id2873387">LSA Open Secret</a></dt><dt><a href="#id2873498">LSA Close</a></dt><dt><a href="#id2873564">LSA Lookup SIDS</a></dt><dt><a href="#id2873773">LSA Lookup Names</a></dt></dl></dd><dt><a href="#id2873999">NETLOGON rpc Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2874162">LSA Request Challenge</a></dt><dt><a href="#id2874296">LSA Authenticate 2</a></dt><dt><a href="#id2874444">LSA Server Password Set</a></dt><dt><a href="#id2874559">LSA SAM Logon</a></dt><dt><a href="#id2874662">LSA SAM Logoff</a></dt></dl></dd><dt><a href="#id2874755">\\MAILSLOT\NET\NTLOGON</a></dt><dd><dl><dt><a href="#id2874774">Query for PDC</a></dt><dt><a href="#id2875034">SAM Logon</a></dt></dl></dd><dt><a href="#id2875360">SRVSVC Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2875405">Net Share Enum</a></dt><dt><a href="#id2875625">Net Server Get Info</a></dt></dl></dd><dt><a href="#id2875741">Cryptographic side of NT Domain Authentication</a></dt><dd><dl><dt><a href="#id2875749">Definitions</a></dt><dt><a href="#id2875911">Protocol</a></dt><dt><a href="#id2876010">Comments</a></dt></dl></dd><dt><a href="#id2876057">SIDs and RIDs</a></dt><dd><dl><dt><a href="#id2876097">Well-known SIDs</a></dt><dt><a href="#id2876412">Well-known RIDS</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2868139"></a>Introduction</h2></div></div><div></div></div><p>
1149 This document contains information to provide an NT workstation with login
1150 services, without the need for an NT server. It is the sgml version of <a href="http://mailhost.cb1.com/~lkcl/cifsntdomain.txt" target="_top">http://mailhost.cb1.com/~lkcl/cifsntdomain.txt</a>, controlled by Luke.
1151 </p><p>
1152 It should be possible to select a domain instead of a workgroup (in the NT
1153 workstation's TCP/IP settings) and after the obligatory reboot, type in a
1154 username, password, select a domain and successfully log in.  I would
1155 appreciate any feedback on your experiences with this process, and any
1156 comments, corrections and additions to this document.
1157 </p><p>
1158 The packets described here can be easily derived from (and are probably
1159 better understood using) Netmon.exe.  You will need to use the version
1160 of Netmon that matches your system, in order to correctly decode the
1161 NETLOGON, lsarpc and srvsvc Transact pipes.  This document is derived from
1162 NT Service Pack 1 and its corresponding version of Netmon.  It is intended
1163 that an annotated packet trace be produced, which will likely be more
1164 instructive than this document.
1165 </p><p>
1166 Also needed, to fully implement NT Domain Login Services, is the 
1167 document describing the cryptographic part of the NT authentication.
1168 This document is available from comp.protocols.smb; from the ntsecurity.net
1169 digest and from the samba digest, amongst other sources.
1170 </p><p>
1171 A copy is available from:
1172 </p><p><a href="http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935" target="_top">http://ntbugtraq.rc.on.ca/SCRIPTS/WA.EXE?A2=ind9708;L=ntbugtraq;O=A;P=2935</a></p><p><a href="http://mailhost.cb1.com/~lkcl/crypt.html" target="_top">http://mailhost.cb1.com/~lkcl/crypt.html</a></p><p>
1173 A c-code implementation, provided by <a href="mailto:linus@incolumitas.se" target="_top">Linus Nordberg</a>
1174 of this protocol is available from:
1175 </p><p><a href="http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html" target="_top">http://samba.org/cgi-bin/mfs/01/digest/1997/97aug/0391.html</a></p><p><a href="http://mailhost.cb1.com/~lkcl/crypt.txt" target="_top">http://mailhost.cb1.com/~lkcl/crypt.txt</a></p><p>
1176 Also used to provide debugging information is the Check Build version of
1177 NT workstation, and enabling full debugging in NETLOGON.  This is
1178 achieved by setting the following REG_SZ registry key to 0x1ffffff:
1179 </p><p><tt class="filename">HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters</tt></p><p><span class="emphasis"><em>Incorrect direct editing of the registry can cause your
1180 machine to fail. Then again, so can incorrect implementation of this 
1181 protocol. See &quot;Liability:&quot; above.</em></span></p><p>
1182 Bear in mind that each packet over-the-wire will have its origin in an
1183 API call.  Therefore, there are likely to be structures, enumerations
1184 and defines that are usefully documented elsewhere.
1185 </p><p>
1186 This document is by no means complete or authoritative.  Missing sections
1187 include, but are not limited to:
1188 </p><div class="orderedlist"><ol type="1"><li><p>Mappings of RIDs to usernames (and vice-versa).</p></li><li><p>What a User ID is and what a Group ID is.</p></li><li><p>The exact meaning/definition of various magic constants or enumerations.</p></li><li><p>The reply error code and use of that error code when a
1189 workstation becomes a member of a domain (to be described later).  
1190 Failure to return this error code will make the workstation report 
1191 that it is already a member of the domain.</p></li><li><p>the cryptographic side of the NetrServerPasswordSet command, 
1192 which would allow the workstation to change its password.  This password is
1193 used to generate the long-term session key.  [It is possible to reject this
1194 command, and keep the default workstation password].</p></li></ol></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2868342"></a>Sources</h3></div></div><div></div></div><table class="simplelist" border="0" summary="Simple list"><tr><td>cket Traces from Netmonitor (Service Pack 1 and above)</td></tr><tr><td>ul Ashton and Luke Leighton's other &quot;NT Domain&quot; doc.</td></tr><tr><td>FS documentation - cifs6.txt</td></tr><tr><td>FS documentation - cifsrap2.txt</td></tr></table></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2868377"></a>Credits</h3></div></div><div></div></div><table class="simplelist" border="0" summary="Simple list"><tr><td>Paul Ashton: loads of work with Net Monitor; understanding the NT authentication system; reference implementation of the NT domain support on which this document is originally based.</td></tr><tr><td>Duncan Stansfield: low-level analysis of MSRPC Pipes.</td></tr><tr><td>Linus Nordberg: producing c-code from Paul's crypto spec.</td></tr><tr><td>Windows Sourcer development team</td></tr></table></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2868416"></a>Notes and Structures</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2868423"></a>Notes</h3></div></div><div></div></div><div class="orderedlist"><ol type="1"><li><p>
1195 In the SMB Transact pipes, some &quot;Structures&quot;, described here, appear to be
1196 4-byte aligned with the SMB header, at their start.  Exactly which
1197 &quot;Structures&quot; need aligning is not precisely known or documented.
1198 </p></li><li><p>
1199 In the UDP NTLOGON Mailslots, some &quot;Structures&quot;, described here, appear to be
1200 2-byte aligned with the start of the mailslot, at their start.
1201 </p></li><li><p>
1202 Domain SID is of the format S-revision-version-auth1-auth2...authN.
1203 e.g S-1-5-123-456-789-123-456.  the 5 could be a sub-revision.
1204 </p></li><li><p>
1205 any undocumented buffer pointers must be non-zero if the string buffer it
1206 refers to contains characters.  exactly what value they should be is unknown.
1207 0x0000 0002 seems to do the trick to indicate that the buffer exists.  a
1208 NULL buffer pointer indicates that the string buffer is of zero length.
1209 If the buffer pointer is NULL, then it is suspected that the structure it
1210 refers to is NOT put into (or taken out of) the SMB data stream.  This is
1211 empirically derived from, for example, the LSA SAM Logon response packet,
1212 where if the buffer pointer is NULL, the user information is not inserted
1213 into the data stream.  Exactly what happens with an array of buffer pointers
1214 is not known, although an educated guess can be made.
1215 </p></li><li><p>
1216 an array of structures (a container) appears to have a count and a pointer.
1217 if the count is zero, the pointer is also zero.  no further data is put
1218 into or taken out of the SMB data stream.  if the count is non-zero, then
1219 the pointer is also non-zero.  immediately following the pointer is the
1220 count again, followed by an array of container sub-structures.  the count
1221 appears a third time after the last sub-structure.
1222 </p></li></ol></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2868506"></a>Enumerations</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868513"></a>MSRPC Header type</h4></div></div><div></div></div><p>command number in the msrpc packet header</p><div class="variablelist"><dl><dt><span class="term">MSRPC_Request:</span></dt><dd><p>0x00</p></dd><dt><span class="term">MSRPC_Response:</span></dt><dd><p>0x02</p></dd><dt><span class="term">MSRPC_Bind:</span></dt><dd><p>0x0B</p></dd><dt><span class="term">MSRPC_BindAck:</span></dt><dd><p>0x0C</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868587"></a>MSRPC Packet info</h4></div></div><div></div></div><p>The meaning of these flags is undocumented</p><div class="variablelist"><dl><dt><span class="term">FirstFrag:</span></dt><dd><p>0x01 </p></dd><dt><span class="term">LastFrag:</span></dt><dd><p>0x02 </p></dd><dt><span class="term">NotaFrag:</span></dt><dd><p>0x04  </p></dd><dt><span class="term">RecRespond:</span></dt><dd><p>0x08  </p></dd><dt><span class="term">NoMultiplex:</span></dt><dd><p>0x10  </p></dd><dt><span class="term">NotForIdemp:</span></dt><dd><p>0x20  </p></dd><dt><span class="term">NotforBcast:</span></dt><dd><p>0x40  </p></dd><dt><span class="term">NoUuid:</span></dt><dd><p>0x80 </p></dd></dl></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2868718"></a>Structures</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868725"></a>VOID *</h4></div></div><div></div></div><p>sizeof VOID* is 32 bits.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868737"></a>char</h4></div></div><div></div></div><p>sizeof char is 8 bits.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868748"></a>UTIME</h4></div></div><div></div></div><p>UTIME is 32 bits, indicating time in seconds since 01jan1970.  documented in cifs6.txt (section 3.5 page, page 30).</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868761"></a>NTTIME</h4></div></div><div></div></div><p>NTTIME is 64 bits.  documented in cifs6.txt (section 3.5 page, page 30).</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868774"></a>DOM_SID (domain SID structure)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>num of sub-authorities in domain SID</p></dd><dt><span class="term">UINT8</span></dt><dd><p>SID revision number</p></dd><dt><span class="term">UINT8</span></dt><dd><p>num of sub-authorities in domain SID</p></dd><dt><span class="term">UINT8[6]</span></dt><dd><p>6 bytes for domain SID - Identifier Authority.</p></dd><dt><span class="term">UINT16[n_subauths]</span></dt><dd><p>domain SID sub-authorities</p></dd></dl></div><p><span class="emphasis"><em>Note: the domain SID is documented elsewhere.</em></span>
1223 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868867"></a>STR (string)</h4></div></div><div></div></div><p>STR (string) is a char[] : a null-terminated string of ascii characters.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868880"></a>UNIHDR (unicode string header) </h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16</span></dt><dd><p>length of unicode string</p></dd><dt><span class="term">UINT16</span></dt><dd><p>max length of unicode string</p></dd><dt><span class="term">UINT32</span></dt><dd><p>4 - undocumented.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868937"></a>UNIHDR2 (unicode string header plus buffer pointer)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UNIHDR</span></dt><dd><p>unicode string header</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2868979"></a>UNISTR (unicode string)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16[]</span></dt><dd><p>null-terminated string of unicode characters.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869007"></a>NAME (length-indicated unicode string)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>length of unicode string</p></dd><dt><span class="term">UINT16[]</span></dt><dd><p>null-terminated string of unicode characters.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869049"></a>UNISTR2 (aligned unicode string)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT8[]</span></dt><dd><p>padding to get unicode string 4-byte aligned with the start of the SMB header.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>max length of unicode string</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd><dt><span class="term">UINT32</span></dt><dd><p>length of unicode string</p></dd><dt><span class="term">UINT16[]</span></dt><dd><p>string of uncode characters</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869135"></a>OBJ_ATTR (object attributes)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>0x18 - length (in bytes) including the length field.</p></dd><dt><span class="term">VOID*</span></dt><dd><p>0 - root directory (pointer)</p></dd><dt><span class="term">VOID*</span></dt><dd><p>0 - object name (pointer)</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - attributes (undocumented)</p></dd><dt><span class="term">VOID*</span></dt><dd><p>0 - security descriptior (pointer)</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - security quality of service</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869228"></a>POL_HND (LSA policy handle)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">char[20]</span></dt><dd><p>policy handle</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869255"></a>DOM_SID2 (domain SID structure, SIDS stored in unicode)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>5 - SID type</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd><dt><span class="term">UNIHDR2</span></dt><dd><p>domain SID unicode string header</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>domain SID unicode string</p></dd></dl></div><p><span class="emphasis"><em>Note:      there is a conflict between the unicode string header and the unicode string itself as to which to use to indicate string length.  this will need to be resolved.</em></span></p><p><span class="emphasis"><em>Note:    the SID type indicates, for example, an alias; a well-known group etc. this is documented somewhere.</em></span></p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869341"></a>DOM_RID (domain RID structure)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>5 - well-known SID.  1 - user SID (see ShowACLs)</p></dd><dt><span class="term">UINT32</span></dt><dd><p>5 - undocumented</p></dd><dt><span class="term">UINT32</span></dt><dd><p>domain RID </p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - domain index out of above reference domains</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869411"></a>LOG_INFO (server, account, client structure)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note:        logon server name starts with two '\' characters and is upper case.</em></span></p><p><span class="emphasis"><em>Note:  account name is the logon client name from the LSA Request Challenge, with a $ on the end of it, in upper case.</em></span></p><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon server unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>account name unicode string</p></dd><dt><span class="term">UINT16</span></dt><dd><p>sec_chan - security channel type</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon client machine unicode string</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869511"></a>CLNT_SRV (server, client names structure)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note: logon server name starts with two '\' characters and is upper case.</em></span></p><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon server unicode string</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon client machine unicode string</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869588"></a>CREDS (credentials + time stamp)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">char[8]</span></dt><dd><p>credentials</p></dd><dt><span class="term">UTIME</span></dt><dd><p>time stamp</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869629"></a>CLNT_INFO2 (server, client structure, client credentials)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note: whenever this structure appears in a request, you must take a copy of the client-calculated credentials received, because they will beused in subsequent credential checks.  the presumed intention is to
1224         maintain an authenticated request/response trail.</em></span></p><div class="variablelist"><dl><dt><span class="term">CLNT_SRV</span></dt><dd><p>client and server names</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>???? padding, for 4-byte alignment with SMB header.</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to client credentials.</p></dd><dt><span class="term">CREDS</span></dt><dd><p>client-calculated credentials + client time</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869711"></a>CLNT_INFO (server, account, client structure, client credentials)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note: whenever this structure appears in a request, you must take a copy of the client-calculated credentials received, because they will be used in subsequent credential checks.  the presumed intention is to maintain an authenticated request/response trail.</em></span></p><div class="variablelist"><dl><dt><span class="term">LOG_INFO</span></dt><dd><p>logon account info</p></dd><dt><span class="term">CREDS</span></dt><dd><p>client-calculated credentials + client time</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869764"></a>ID_INFO_1 (id info structure, auth level 1)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>ptr_id_info_1</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>domain name unicode header</p></dd><dt><span class="term">UINT32</span></dt><dd><p>param control</p></dd><dt><span class="term">UINT64</span></dt><dd><p>logon ID</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>user name unicode header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>workgroup name unicode header</p></dd><dt><span class="term">char[16]</span></dt><dd><p>arc4 LM OWF Password</p></dd><dt><span class="term">char[16]</span></dt><dd><p>arc4 NT OWF Password</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>domain name unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>user name unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>workstation name unicode string</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2869934"></a>SAM_INFO (sam logon/logoff id info structure)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note: presumably, the return credentials is supposedly for the server to verify that the credential chain hasn't been compromised.</em></span></p><div class="variablelist"><dl><dt><span class="term">CLNT_INFO2</span></dt><dd><p>client identification/authentication info</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to return credentials.</p></dd><dt><span class="term">CRED</span></dt><dd><p>return credentials - ignored.</p></dd><dt><span class="term">UINT16</span></dt><dd><p>logon level</p></dd><dt><span class="term">UINT16</span></dt><dd><p>switch value</p></dd></dl></div><pre class="programlisting">
1225         switch (switch_value)
1226         case 1:
1227         {
1228             ID_INFO_1     id_info_1;
1229         }
1230 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2870038"></a>GID (group id info)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>group id</p></dd><dt><span class="term">UINT32</span></dt><dd><p>user attributes (only used by NT 3.1 and 3.51)</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2870077"></a>DOM_REF (domain reference info)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num referenced domains?</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain name buffer pointer.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>32 - max number of entries</p></dd><dt><span class="term">UINT32</span></dt><dd><p>4 - num referenced domains?</p></dd><dt><span class="term">UNIHDR2</span></dt><dd><p>domain name unicode string header</p></dd><dt><span class="term">UNIHDR2[num_ref_doms-1]</span></dt><dd><p>referenced domain unicode string headers</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>domain name unicode string</p></dd><dt><span class="term">DOM_SID[num_ref_doms]</span></dt><dd><p>referenced domain SIDs</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2870220"></a>DOM_INFO (domain info, levels 3 and 5 are the same))</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT8[]</span></dt><dd><p>??? padding to get 4-byte alignment with start of SMB header</p></dd><dt><span class="term">UINT16</span></dt><dd><p>domain name string length * 2</p></dd><dt><span class="term">UINT16</span></dt><dd><p>domain name string length * 2</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain name string buffer pointer</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain SID string buffer pointer</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>domain name (unicode string)</p></dd><dt><span class="term">DOM_SID</span></dt><dd><p>domain SID</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2870333"></a>USER_INFO (user logon info)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note: it would be nice to know what the 16 byte user session key is for.</em></span></p><div class="variablelist"><dl><dt><span class="term">NTTIME</span></dt><dd><p>logon time</p></dd><dt><span class="term">NTTIME</span></dt><dd><p>logoff time</p></dd><dt><span class="term">NTTIME</span></dt><dd><p>kickoff time</p></dd><dt><span class="term">NTTIME</span></dt><dd><p>password last set time</p></dd><dt><span class="term">NTTIME</span></dt><dd><p>password can change time</p></dd><dt><span class="term">NTTIME</span></dt><dd><p>password must change time</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>username unicode string header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>user's full name unicode string header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>logon script unicode string header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>profile path unicode string header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>home directory unicode string header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>home directory drive unicode string header</p></dd><dt><span class="term">UINT16</span></dt><dd><p>logon count</p></dd><dt><span class="term">UINT16</span></dt><dd><p>bad password count</p></dd><dt><span class="term">UINT32</span></dt><dd><p>User ID</p></dd><dt><span class="term">UINT32</span></dt><dd><p>Group ID</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num groups</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer to groups.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>user flags</p></dd><dt><span class="term">char[16]</span></dt><dd><p>user session key</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>logon server unicode string header</p></dd><dt><span class="term">UNIHDR</span></dt><dd><p>logon domain unicode string header</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented logon domain id pointer</p></dd><dt><span class="term">char[40]</span></dt><dd><p>40 undocumented padding bytes.  future expansion?</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - num_other_sids?</p></dd><dt><span class="term">VOID*</span></dt><dd><p>NULL - undocumented pointer to other domain SIDs.</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>username unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>user's full name unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon script unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>profile path unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>home directory unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>home directory drive unicode string</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num groups</p></dd><dt><span class="term">GID[num_groups]</span></dt><dd><p>group info</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon server unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon domain unicode string</p></dd><dt><span class="term">DOM_SID</span></dt><dd><p>domain SID</p></dd><dt><span class="term">DOM_SID[num_sids]</span></dt><dd><p>other domain SIDs?</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2870896"></a>SH_INFO_1_PTR (pointers to level 1 share info strings)</h4></div></div><div></div></div><p><span class="emphasis"><em>Note:       see cifsrap2.txt section5, page 10.</em></span></p><table class="simplelist" border="0" summary="Simple list"><tr><td>0 for shi1_type indicates a  Disk.</td></tr><tr><td>1 for shi1_type indicates a  Print Queue.</td></tr><tr><td>2 for shi1_type indicates a  Device.</td></tr><tr><td>3 for shi1_type indicates an IPC pipe.</td></tr><tr><td>0x8000 0000 (top bit set in shi1_type) indicates a hidden share.</td></tr></table><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>shi1_netname - pointer to net name</p></dd><dt><span class="term">UINT32</span></dt><dd><p>shi1_type    - type of share.  0 - undocumented.</p></dd><dt><span class="term">VOID*</span></dt><dd><p>shi1_remark  - pointer to comment.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2870991"></a>SH_INFO_1_STR (level 1 share info strings)</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UNISTR2</span></dt><dd><p>shi1_netname - unicode string of net name</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>shi1_remark  - unicode string of comment.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2871033"></a>SHARE_INFO_1_CTR</h4></div></div><div></div></div><p>share container with 0 entries:</p><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>0 - EntriesRead</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - Buffer</p></dd></dl></div><p>share container with &gt; 0 entries:</p><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>EntriesRead</p></dd><dt><span class="term">UINT32</span></dt><dd><p>non-zero - Buffer</p></dd><dt><span class="term">UINT32</span></dt><dd><p>EntriesRead</p></dd><dt><span class="term">SH_INFO_1_PTR[EntriesRead]</span></dt><dd><p>share entry pointers</p></dd><dt><span class="term">SH_INFO_1_STR[EntriesRead]</span></dt><dd><p>share entry strings</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>padding to get unicode string 4-byte aligned with start of the SMB header.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>EntriesRead</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - padding</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2871203"></a>SERVER_INFO_101</h4></div></div><div></div></div><p><span class="emphasis"><em>Note:     see cifs6.txt section 6.4 - the fields described therein will be of assistance here.  for example, the type listed below is the         same as fServerType, which is described in 6.4.1. </em></span></p><div class="variablelist"><dl><dt><span class="term">SV_TYPE_WORKSTATION</span></dt><dd><p>0x00000001  All workstations</p></dd><dt><span class="term">SV_TYPE_SERVER</span></dt><dd><p>0x00000002  All servers</p></dd><dt><span class="term">SV_TYPE_SQLSERVER</span></dt><dd><p>0x00000004  Any server running with SQL server</p></dd><dt><span class="term">SV_TYPE_DOMAIN_CTRL</span></dt><dd><p>0x00000008  Primary domain controller</p></dd><dt><span class="term">SV_TYPE_DOMAIN_BAKCTRL</span></dt><dd><p>0x00000010  Backup domain controller</p></dd><dt><span class="term">SV_TYPE_TIME_SOURCE</span></dt><dd><p>0x00000020  Server running the timesource service</p></dd><dt><span class="term">SV_TYPE_AFP</span></dt><dd><p>0x00000040  Apple File Protocol servers</p></dd><dt><span class="term">SV_TYPE_NOVELL</span></dt><dd><p>0x00000080  Novell servers</p></dd><dt><span class="term">SV_TYPE_DOMAIN_MEMBER</span></dt><dd><p>0x00000100  Domain Member</p></dd><dt><span class="term">SV_TYPE_PRINTQ_SERVER</span></dt><dd><p>0x00000200  Server sharing print queue</p></dd><dt><span class="term">SV_TYPE_DIALIN_SERVER</span></dt><dd><p>0x00000400  Server running dialin service.</p></dd><dt><span class="term">SV_TYPE_XENIX_SERVER</span></dt><dd><p>0x00000800  Xenix server</p></dd><dt><span class="term">SV_TYPE_NT</span></dt><dd><p>0x00001000  NT server</p></dd><dt><span class="term">SV_TYPE_WFW</span></dt><dd><p>0x00002000  Server running Windows for </p></dd><dt><span class="term">SV_TYPE_SERVER_NT</span></dt><dd><p>0x00008000  Windows NT non DC server</p></dd><dt><span class="term">SV_TYPE_POTENTIAL_BROWSER</span></dt><dd><p>0x00010000  Server that can run the browser service</p></dd><dt><span class="term">SV_TYPE_BACKUP_BROWSER</span></dt><dd><p>0x00020000  Backup browser server</p></dd><dt><span class="term">SV_TYPE_MASTER_BROWSER</span></dt><dd><p>0x00040000  Master browser server</p></dd><dt><span class="term">SV_TYPE_DOMAIN_MASTER</span></dt><dd><p>0x00080000  Domain Master Browser server</p></dd><dt><span class="term">SV_TYPE_LOCAL_LIST_ONLY</span></dt><dd><p>0x40000000  Enumerate only entries marked &quot;local&quot;</p></dd><dt><span class="term">SV_TYPE_DOMAIN_ENUM</span></dt><dd><p>0x80000000  Enumerate Domains. The pszServer and pszDomain parameters must be NULL.</p></dd></dl></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>500 - platform_id</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to name</p></dd><dt><span class="term">UINT32</span></dt><dd><p>5 - major version</p></dd><dt><span class="term">UINT32</span></dt><dd><p>4 - minor version</p></dd><dt><span class="term">UINT32</span></dt><dd><p>type (SV_TYPE_... bit field)</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to comment</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>sv101_name - unicode string of server name</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>sv_101_comment  - unicode string of server comment.</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>padding to get unicode string 4-byte aligned with start of the SMB header.</p></dd></dl></div></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2871669"></a>MSRPC over Transact Named Pipe</h2></div></div><div></div></div><p>For details on the SMB Transact Named Pipe, see cifs6.txt</p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2871682"></a>MSRPC Pipes</h3></div></div><div></div></div><p>
1231 The MSRPC is conducted over an SMB Transact Pipe with a name of 
1232 <tt class="filename">\PIPE\</tt>.  You must first obtain a 16 bit file handle, by
1233 sending a SMBopenX with the pipe name <tt class="filename">\PIPE\srvsvc</tt> for
1234 example.  You can then perform an SMB Trans,
1235 and must carry out an SMBclose on the file handle once you are finished.
1236 </p><p>
1237 Trans Requests must be sent with two setup UINT16s, no UINT16 params (none
1238 known about), and UINT8 data parameters sufficient to contain the MSRPC
1239 header, and MSRPC data.  The first UINT16 setup parameter must be either
1240 0x0026 to indicate an RPC, or 0x0001 to indicate Set Named Pipe Handle
1241 state.  The second UINT16 parameter must be the file handle for the pipe,
1242 obtained above.
1243 </p><p>
1244 The Data section for an API Command of 0x0026 (RPC pipe) in the Trans
1245 Request is the RPC Header, followed by the RPC Data.  The Data section for
1246 an API Command of 0x0001 (Set Named Pipe Handle state) is two bytes.  The
1247 only value seen for these two bytes is 0x00 0x43.
1248 </p><p>
1249 MSRPC Responses are sent as response data inside standard SMB Trans
1250 responses, with the MSRPC Header, MSRPC Data and MSRPC tail.
1251 </p><p>
1252 It is suspected that the Trans Requests will need to be at least 2-byte
1253 aligned (probably 4-byte).  This is standard practice for SMBs.  It is also
1254 independent of the observed 4-byte alignments with the start of the MSRPC
1255 header, including the 4-byte alignment between the MSRPC header and the
1256 MSRPC data.
1257 </p><p>
1258 First, an SMBtconX connection is made to the IPC$ share.  The connection
1259 must be made using encrypted passwords, not clear-text.  Then, an SMBopenX
1260 is made on the pipe.  Then, a Set Named Pipe Handle State must be sent,
1261 after which the pipe is ready to accept API commands.  Lastly, and SMBclose
1262 is sent.
1263 </p><p>
1264 To be resolved:
1265 </p><p>
1266 lkcl/01nov97 there appear to be two additional bytes after the null-terminated \PIPE\ name for the RPC pipe.  Values seen so far are
1267 listed below:</p><pre class="programlisting">
1268         initial SMBopenX request:         RPC API command 0x26 params:
1269         &quot;\\PIPE\\lsarpc&quot;                  0x65 0x63; 0x72 0x70; 0x44 0x65;
1270         &quot;\\PIPE\\srvsvc&quot;                  0x73 0x76; 0x4E 0x00; 0x5C 0x43;
1271 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2871787"></a>Header</h3></div></div><div></div></div><p>[section to be rewritten, following receipt of work by Duncan Stansfield]</p><p>Interesting note: if you set packed data representation to 0x0100 0000
1272 then all 4-byte and 2-byte word ordering is turned around!</p><p>The start of each of the NTLSA and NETLOGON named pipes begins with:</p><div class="segmentedlist"><p><b>offset: </b>00</p><p><b>Variable type: </b>UINT8</p><p><b>Variable data: </b>5 - RPC major version</p><p><b>offset: </b>01</p><p><b>Variable type: </b>UINT8</p><p><b>Variable data: </b>0 - RPC minor version</p><p><b>offset: </b>02</p><p><b>Variable type: </b>UINT8</p><p><b>Variable data: </b>2 - RPC response packet</p><p><b>offset: </b>03</p><p><b>Variable type: </b>UINT8</p><p><b>Variable data: </b>3 - (FirstFrag bit-wise or with LastFrag)</p><p><b>offset: </b>04</p><p><b>Variable type: </b>UINT32</p><p><b>Variable data: </b>0x1000 0000 - packed data representation</p><p><b>offset: </b>08</p><p><b>Variable type: </b>UINT16</p><p><b>Variable data: </b>fragment length - data size (bytes) inc header and tail.</p><p><b>offset: </b>0A</p><p><b>Variable type: </b>UINT16</p><p><b>Variable data: </b>0 - authentication length </p><p><b>offset: </b>0C</p><p><b>Variable type: </b>UINT32</p><p><b>Variable data: </b>call identifier. matches 12th UINT32 of incoming RPC data.</p><p><b>offset: </b>10</p><p><b>Variable type: </b>UINT32</p><p><b>Variable data: </b>allocation hint - data size (bytes) minus header and tail.</p><p><b>offset: </b>14</p><p><b>Variable type: </b>UINT16</p><p><b>Variable data: </b>0 - presentation context identifier</p><p><b>offset: </b>16</p><p><b>Variable type: </b>UINT8</p><p><b>Variable data: </b>0 - cancel count</p><p><b>offset: </b>17</p><p><b>Variable type: </b>UINT8</p><p><b>Variable data: </b>in replies: 0 - reserved; in requests: opnum - see #defines.</p><p><b>offset: </b>18</p><p><b>Variable type: </b>......</p><p><b>Variable data: </b>start of data (goes on for allocation_hint bytes)</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2871976"></a>RPC_Packet for request, response, bind and bind acknowledgement</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT8 versionmaj</span></dt><dd><p>reply same as request (0x05)</p></dd><dt><span class="term">UINT8 versionmin</span></dt><dd><p>reply same as request (0x00)</p></dd><dt><span class="term">UINT8 type</span></dt><dd><p>one of the MSRPC_Type enums</p></dd><dt><span class="term">UINT8 flags</span></dt><dd><p>reply same as request (0x00 for Bind, 0x03 for Request)</p></dd><dt><span class="term">UINT32 representation</span></dt><dd><p>reply same as request (0x00000010)</p></dd><dt><span class="term">UINT16 fraglength</span></dt><dd><p>the length of the data section of the SMB trans packet</p></dd><dt><span class="term">UINT16 authlength</span></dt><dd><p></p></dd><dt><span class="term">UINT32 callid</span></dt><dd><p>call identifier. (e.g. 0x00149594)</p></dd><dt><span class="term">* stub USE TvPacket</span></dt><dd><p>the remainder of the packet depending on the &quot;type&quot;</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872110"></a>Interface identification</h4></div></div><div></div></div><p>the interfaces are numbered. as yet I haven't seen more than one interface used on the same pipe name srvsvc</p><pre class="programlisting">
1273 abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
1274 transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)
1275 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872138"></a>RPC_Iface RW</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT8 byte[16]</span></dt><dd><p>16 bytes of number</p></dd><dt><span class="term">UINT32 version</span></dt><dd><p>the interface number</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872175"></a>RPC_ReqBind RW</h4></div></div><div></div></div><p>the remainder of the packet after the header if &quot;type&quot; was Bind in the response header, &quot;type&quot; should be BindAck</p><div class="variablelist"><dl><dt><span class="term">UINT16 maxtsize</span></dt><dd><p>maximum transmission fragment size (0x1630)</p></dd><dt><span class="term">UINT16 maxrsize</span></dt><dd><p>max receive fragment size (0x1630)</p></dd><dt><span class="term">UINT32 assocgid</span></dt><dd><p>associated group id (0x0)</p></dd><dt><span class="term">UINT32 numelements</span></dt><dd><p>the number of elements (0x1)</p></dd><dt><span class="term">UINT16 contextid</span></dt><dd><p>presentation context identifier (0x0)</p></dd><dt><span class="term">UINT8 numsyntaxes</span></dt><dd><p>the number of syntaxes (has always been 1?)(0x1)</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>4-byte alignment padding, against SMB header</p></dd><dt><span class="term">* abstractint USE RPC_Iface</span></dt><dd><p>num and vers. of interface client is using</p></dd><dt><span class="term">* transferint USE RPC_Iface</span></dt><dd><p>num and vers. of interface to use for replies</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872318"></a>RPC_Address RW</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16 length</span></dt><dd><p>length of the string including null terminator</p></dd><dt><span class="term">* port USE string</span></dt><dd><p>the string above in single byte, null terminated form</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872358"></a>RPC_ResBind RW</h4></div></div><div></div></div><p>the response to place after the header in the reply packet</p><div class="variablelist"><dl><dt><span class="term">UINT16 maxtsize</span></dt><dd><p>same as request</p></dd><dt><span class="term">UINT16 maxrsize</span></dt><dd><p>same as request</p></dd><dt><span class="term">UINT32 assocgid</span></dt><dd><p>zero</p></dd><dt><span class="term">* secondaddr USE RPC_Address</span></dt><dd><p>the address string, as described earlier</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>4-byte alignment padding, against SMB header</p></dd><dt><span class="term">UINT8 numresults</span></dt><dd><p>the number of results (0x01)</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>4-byte alignment padding, against SMB header</p></dd><dt><span class="term">UINT16 result</span></dt><dd><p>result (0x00 = accept)</p></dd><dt><span class="term">UINT16 reason</span></dt><dd><p>reason (0x00 = no reason specified)</p></dd><dt><span class="term">* transfersyntax USE RPC_Iface</span></dt><dd><p>the transfer syntax from the request</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872508"></a>RPC_ReqNorm RW</h4></div></div><div></div></div><p>the remainder of the packet after the header for every other other request</p><div class="variablelist"><dl><dt><span class="term">UINT32 allochint</span></dt><dd><p>the size of the stub data in bytes</p></dd><dt><span class="term">UINT16 prescontext</span></dt><dd><p>presentation context identifier (0x0)</p></dd><dt><span class="term">UINT16 opnum</span></dt><dd><p>operation number (0x15)</p></dd><dt><span class="term">* stub USE TvPacket</span></dt><dd><p>a packet dependent on the pipe name (probably the interface) and the op number)</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2872580"></a>RPC_ResNorm RW</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32 allochint</span></dt><dd><p># size of the stub data in bytes</p></dd><dt><span class="term">UINT16 prescontext</span></dt><dd><p># presentation context identifier (same as request)</p></dd><dt><span class="term">UINT8 cancelcount</span></dt><dd><p># cancel count? (0x0)</p></dd><dt><span class="term">UINT8 reserved</span></dt><dd><p># 0 - one byte padding</p></dd><dt><span class="term">* stub USE TvPacket</span></dt><dd><p># the remainder of the reply</p></dd></dl></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2872660"></a>Tail</h3></div></div><div></div></div><p>The end of each of the NTLSA and NETLOGON named pipes ends with:</p><div class="variablelist"><dl><dt><span class="term">......</span></dt><dd><p>end of data</p></dd><dt><span class="term">UINT32</span></dt><dd><p>return code</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2872706"></a>RPC Bind / Bind Ack</h3></div></div><div></div></div><p>
1276 RPC Binds are the process of associating an RPC pipe (e.g \PIPE\lsarpc)
1277 with a &quot;transfer syntax&quot; (see RPC_Iface structure).  The purpose for doing
1278 this is unknown.
1279 </p><p><span class="emphasis"><em>Note: The RPC_ResBind SMB Transact request is sent with two uint16 setup parameters.  The first is 0x0026; the second is the file handle
1280         returned by the SMBopenX Transact response.</em></span></p><p><span class="emphasis"><em>Note:  The RPC_ResBind members maxtsize, maxrsize and assocgid are the same in the response as the same members in the RPC_ReqBind.  The
1281         RPC_ResBind member transfersyntax is the same in the response as
1282         the</em></span></p><p><span class="emphasis"><em>Note:  The RPC_ResBind response member secondaddr contains the name of what is presumed to be the service behind the RPC pipe.  The
1283         mapping identified so far is:</em></span></p><div class="variablelist"><dl><dt><span class="term">initial SMBopenX request:</span></dt><dd><p>RPC_ResBind response:</p></dd><dt><span class="term">&quot;\\PIPE\\srvsvc&quot;</span></dt><dd><p>&quot;\\PIPE\\ntsvcs&quot;</p></dd><dt><span class="term">&quot;\\PIPE\\samr&quot;</span></dt><dd><p>&quot;\\PIPE\\lsass&quot;</p></dd><dt><span class="term">&quot;\\PIPE\\lsarpc&quot;</span></dt><dd><p>&quot;\\PIPE\\lsass&quot;</p></dd><dt><span class="term">&quot;\\PIPE\\wkssvc&quot;</span></dt><dd><p>&quot;\\PIPE\\wksvcs&quot;</p></dd><dt><span class="term">&quot;\\PIPE\\NETLOGON&quot;</span></dt><dd><p>&quot;\\PIPE\\NETLOGON&quot;</p></dd></dl></div><p><span class="emphasis"><em>Note:   The RPC_Packet fraglength member in both the Bind Request and Bind Acknowledgment must contain the length of the entire RPC data, including the RPC_Packet header.</em></span></p><p>Request:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>RPC_Packet</td></tr><tr><td>RPC_ReqBind</td></tr></table><p>Response:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>RPC_Packet</td></tr><tr><td>RPC_ResBind</td></tr></table></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2872896"></a>NTLSA Transact Named Pipe</h3></div></div><div></div></div><p>The sequence of actions taken on this pipe are:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>Establish a connection to the IPC$ share (SMBtconX).  use encrypted passwords.</td></tr><tr><td>Open an RPC Pipe with the name &quot;\\PIPE\\lsarpc&quot;.  Store the file handle.</td></tr><tr><td>Using the file handle, send a Set Named Pipe Handle state to 0x4300.</td></tr><tr><td>Send an LSA Open Policy request.  Store the Policy Handle.</td></tr><tr><td>Using the Policy Handle, send LSA Query Info Policy requests, etc.</td></tr><tr><td>Using the Policy Handle, send an LSA Close.</td></tr><tr><td>Close the IPC$ share.</td></tr></table><p>Defines for this pipe, identifying the query are:</p><div class="variablelist"><dl><dt><span class="term">LSA Open Policy:</span></dt><dd><p>0x2c</p></dd><dt><span class="term">LSA Query Info Policy:</span></dt><dd><p>0x07</p></dd><dt><span class="term">LSA Enumerate Trusted Domains:</span></dt><dd><p>0x0d</p></dd><dt><span class="term">LSA Open Secret:</span></dt><dd><p>0xff</p></dd><dt><span class="term">LSA Lookup SIDs:</span></dt><dd><p>0xfe</p></dd><dt><span class="term">LSA Lookup Names:</span></dt><dd><p>0xfd</p></dd><dt><span class="term">LSA Close:</span></dt><dd><p>0x00</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873062"></a>LSA Open Policy</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:    The policy handle can be anything you like.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873076"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>buffer pointer</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>server name - unicode string starting with two '\'s</p></dd><dt><span class="term">OBJ_ATTR</span></dt><dd><p>object attributes</p></dd><dt><span class="term">UINT32</span></dt><dd><p>1 - desired access</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873146"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">POL_HND</span></dt><dd><p>LSA policy handle</p></dd><dt><span class="term">return</span></dt><dd><p>0 - indicates success</p></dd></dl></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873187"></a>LSA Query Info Policy</h3></div></div><div></div></div><p><span class="emphasis"><em>Note: The info class in response must be the same as that in the request.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873202"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">POL_HND</span></dt><dd><p>LSA policy handle</p></dd><dt><span class="term">UINT16</span></dt><dd><p>info class (also a policy handle?)</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873241"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UINT16</span></dt><dd><p>info class (same as info class in request).</p></dd></dl></div><pre class="programlisting">
1284 switch (info class)
1285 case 3:
1286 case 5:
1287 {
1288 DOM_INFO domain info, levels 3 and 5 (are the same).
1289 }
1290
1291 return    0 - indicates success
1292 </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873296"></a>LSA Enumerate Trusted Domains</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873304"></a>Request</h4></div></div><div></div></div><p>no extra data</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873316"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>0 - enumeration context</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - entries read</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - trust information</p></dd><dt><span class="term">return</span></dt><dd><p>0x8000 001a - &quot;no trusted domains&quot; success code</p></dd></dl></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873387"></a>LSA Open Secret</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873394"></a>Request</h4></div></div><div></div></div><p>no extra data</p></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873406"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd><dt><span class="term">UINT32</span></dt><dd><p>0 - undocumented</p></dd></dl></div><p>return    0x0C00 0034 - &quot;no such secret&quot; success code</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873498"></a>LSA Close</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873505"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">POL_HND</span></dt><dd><p>policy handle to be closed</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873532"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">POL_HND</span></dt><dd><p>0s - closed policy handle (all zeros)</p></dd></dl></div><p>return    0 - indicates success</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873564"></a>LSA Lookup SIDS</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:       num_entries in response must be same as num_entries in request.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873577"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">POL_HND</span></dt><dd><p>LSA policy handle</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain SID buffer pointer</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain name buffer pointer</p></dd><dt><span class="term">VOID*[num_entries] undocumented domain SID pointers to be looked up.
1293 </span></dt><dd><p>DOM_SID[num_entries] domain SIDs to be looked up.</p></dd><dt><span class="term">char[16]</span></dt><dd><p>completely undocumented 16 bytes.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873677"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">DOM_REF</span></dt><dd><p>domain reference response</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries (listed above)</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries (listed above)</p></dd><dt><span class="term">DOM_SID2[num_entries]</span></dt><dd><p>domain SIDs (from Request, listed above).</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries (listed above)</p></dd></dl></div><p>return                0 - indicates success</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2873773"></a>LSA Lookup Names</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:        num_entries in response must be same as num_entries in request.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873787"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">POL_HND</span></dt><dd><p>LSA policy handle</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain SID buffer pointer</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented domain name buffer pointer</p></dd><dt><span class="term">NAME[num_entries]</span></dt><dd><p>names to be looked up.</p></dd><dt><span class="term">char[]</span></dt><dd><p>undocumented bytes - falsely translated SID structure?</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2873901"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">DOM_REF</span></dt><dd><p>domain reference response</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries (listed above)</p></dd><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries (listed above)</p></dd><dt><span class="term">DOM_RID[num_entries]</span></dt><dd><p>domain SIDs (from Request, listed above).</p></dd><dt><span class="term">UINT32</span></dt><dd><p>num_entries (listed above)</p></dd></dl></div><p>return                0 - indicates success</p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2873999"></a>NETLOGON rpc Transact Named Pipe</h2></div></div><div></div></div><p>The sequence of actions taken on this pipe are:</p><table class="simplelist" border="0" summary="Simple list"><tr><td>tablish a connection to the IPC$ share (SMBtconX).  use encrypted passwords.</td></tr><tr><td>en an RPC Pipe with the name &quot;\\PIPE\\NETLOGON&quot;.  Store the file handle.</td></tr><tr><td>ing the file handle, send a Set Named Pipe Handle state to 0x4300.</td></tr><tr><td>eate Client Challenge. Send LSA Request Challenge.  Store Server Challenge.</td></tr><tr><td>lculate Session Key.  Send an LSA Auth 2 Challenge.  Store Auth2 Challenge.</td></tr><tr><td>lc/Verify Client Creds.  Send LSA Srv PW Set.  Calc/Verify Server Creds.</td></tr><tr><td>lc/Verify Client Creds.  Send LSA SAM Logon .  Calc/Verify Server Creds.</td></tr><tr><td>lc/Verify Client Creds.  Send LSA SAM Logoff.  Calc/Verify Server Creds.</td></tr><tr><td>ose the IPC$ share.</td></tr></table><p>Defines for this pipe, identifying the query are</p><div class="variablelist"><dl><dt><span class="term">LSA Request Challenge:</span></dt><dd><p>0x04</p></dd><dt><span class="term">LSA Server Password Set:</span></dt><dd><p>0x06</p></dd><dt><span class="term">LSA SAM Logon:</span></dt><dd><p>0x02</p></dd><dt><span class="term">LSA SAM Logoff:</span></dt><dd><p>0x03</p></dd><dt><span class="term">LSA Auth 2:</span></dt><dd><p>0x0f</p></dd><dt><span class="term">LSA Logon Control:</span></dt><dd><p>0x0e</p></dd></dl></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2874162"></a>LSA Request Challenge</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:    logon server name starts with two '\' characters and is upper case.</em></span></p><p><span class="emphasis"><em>Note:  logon client is the machine, not the user.</em></span></p><p><span class="emphasis"><em>Note:   the initial LanManager password hash, against which the challenge is issued, is the machine name itself (lower case).  there will becalls issued (LSA Server Password Set) which will change this, later. refusing these calls allows you to always deal with the same password (i.e the LM# of the machine name in lower case).</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874194"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon server unicode string</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>logon client unicode string</p></dd><dt><span class="term">char[8]</span></dt><dd><p>client challenge</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874264"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">char[8]</span></dt><dd><p>server challenge</p></dd></dl></div><p>return    0 - indicates success</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2874296"></a>LSA Authenticate 2</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:   in between request and response, calculate the client credentials, and check them against the client-calculated credentials (this process uses the previously received client credentials).</em></span></p><p><span class="emphasis"><em>Note:  neg_flags in the response is the same as that in the request.</em></span></p><p><span class="emphasis"><em>Note:        you must take a copy of the client-calculated credentials received      here, because they will be used in subsequent authentication packets.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874327"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">LOG_INFO</span></dt><dd><p>client identification info</p></dd><dt><span class="term">char[8]</span></dt><dd><p>client-calculated credentials</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>padding to 4-byte align with start of SMB header.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>neg_flags - negotiated flags (usual value is 0x0000 01ff)</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874396"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">char[8]</span></dt><dd><p>server credentials.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>neg_flags - same as neg_flags in request.</p></dd></dl></div><p>return    0 - indicates success.  failure value unknown.</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2874444"></a>LSA Server Password Set</h3></div></div><div></div></div><p><span class="emphasis"><em>Note: the new password is suspected to be a DES encryption using the old password to generate the key.</em></span></p><p><span class="emphasis"><em>Note: in between request and response, calculate the client credentials, and check them against the client-calculated credentials (this process uses the previously received client credentials).</em></span></p><p><span class="emphasis"><em>Note: the server credentials are constructed from the client-calculated credentials and the client time + 1 second.</em></span></p><p><span class="emphasis"><em>Note: you must take a copy of the client-calculated credentials received here, because they will be used in subsequent authentication packets.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874483"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">CLNT_INFO</span></dt><dd><p>client identification/authentication info</p></dd><dt><span class="term">char[]</span></dt><dd><p>new password - undocumented.</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874525"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">CREDS</span></dt><dd><p>server credentials.  server time stamp appears to be ignored.</p></dd></dl></div><p>return    0 - indicates success; 0xC000 006a indicates failure</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2874559"></a>LSA SAM Logon</h3></div></div><div></div></div><p><span class="emphasis"><em>
1294 Note:   valid_user is True iff the username and password hash are valid for
1295         the requested domain.
1296 </em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874574"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">SAM_INFO</span></dt><dd><p>sam_id structure</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874601"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">CREDS</span></dt><dd><p>server credentials.  server time stamp appears to be ignored.</p></dd></dl></div><pre class="programlisting">
1297 if (valid_user)
1298 {
1299         UINT16      3 - switch value indicating USER_INFO structure.
1300     VOID*     non-zero - pointer to USER_INFO structure
1301     USER_INFO user logon information
1302
1303     UINT32    1 - Authoritative response; 0 - Non-Auth?
1304
1305     return    0 - indicates success
1306 }
1307 else
1308 {
1309         UINT16    0 - switch value.  value to indicate no user presumed.
1310     VOID*     0x0000 0000 - indicates no USER_INFO structure.
1311
1312     UINT32    1 - Authoritative response; 0 - Non-Auth?
1313
1314     return    0xC000 0064 - NT_STATUS_NO_SUCH_USER.
1315 }
1316 </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2874662"></a>LSA SAM Logoff</h3></div></div><div></div></div><p><span class="emphasis"><em>
1317 Note:   presumably, the SAM_INFO structure is validated, and a (currently
1318         undocumented) error code returned if the Logoff is invalid.
1319 </em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874677"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">SAM_INFO</span></dt><dd><p>sam_id structure</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874705"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>undocumented buffer pointer</p></dd><dt><span class="term">CREDS</span></dt><dd><p>server credentials.  server time stamp appears to be ignored.</p></dd></dl></div><p>return      0 - indicates success.  undocumented failure indication.</p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2874755"></a>\\MAILSLOT\NET\NTLOGON</h2></div></div><div></div></div><p><span class="emphasis"><em>
1320 Note:   mailslots will contain a response mailslot, to which the response
1321         should be sent.  the target NetBIOS name is REQUEST_NAME&lt;20&gt;, where
1322         REQUEST_NAME is the name of the machine that sent the request.
1323 </em></span></p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2874774"></a>Query for PDC</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:      NTversion, LMNTtoken, LM20token in response are the same as those       given in the request.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874787"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16</span></dt><dd><p>0x0007 - Query for PDC</p></dd><dt><span class="term">STR</span></dt><dd><p>machine name</p></dd><dt><span class="term">STR</span></dt><dd><p>response mailslot</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>padding to 2-byte align with start of mailslot.</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>machine name</p></dd><dt><span class="term">UINT32</span></dt><dd><p>NTversion</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LMNTtoken</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LM20token</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2874913"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16</span></dt><dd><p>0x000A - Respose to Query for PDC</p></dd><dt><span class="term">STR</span></dt><dd><p>machine name (in uppercase)</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>padding to 2-byte align with start of mailslot.</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>machine name</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>domain name</p></dd><dt><span class="term">UINT32</span></dt><dd><p>NTversion (same as received in request)</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LMNTtoken (same as received in request)</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LM20token (same as received in request)</p></dd></dl></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2875034"></a>SAM Logon</h3></div></div><div></div></div><p><span class="emphasis"><em>Note: machine name in response is preceded by two '\' characters.</em></span></p><p><span class="emphasis"><em>Note:      NTversion, LMNTtoken, LM20token in response are the same as those given in the request.</em></span></p><p><span class="emphasis"><em>Note:      user name in the response is presumably the same as that in the request.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2875062"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16</span></dt><dd><p>0x0012 - SAM Logon</p></dd><dt><span class="term">UINT16</span></dt><dd><p>request count</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>machine name</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>user name</p></dd><dt><span class="term">STR</span></dt><dd><p>response mailslot</p></dd><dt><span class="term">UINT32</span></dt><dd><p>alloweable account</p></dd><dt><span class="term">UINT32</span></dt><dd><p>domain SID size</p></dd><dt><span class="term">char[sid_size]</span></dt><dd><p>domain SID, of sid_size bytes.</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>???? padding to 4? 2? -byte align with start of mailslot.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>NTversion</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LMNTtoken</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LM20token</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2875246"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT16</span></dt><dd><p>0x0013 - Response to SAM Logon</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>machine name</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>user name - workstation trust account</p></dd><dt><span class="term">UNISTR</span></dt><dd><p>domain name </p></dd><dt><span class="term">UINT32</span></dt><dd><p>NTversion</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LMNTtoken</p></dd><dt><span class="term">UINT16</span></dt><dd><p>LM20token</p></dd></dl></div></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2875360"></a>SRVSVC Transact Named Pipe</h2></div></div><div></div></div><p>Defines for this pipe, identifying the query are:</p><div class="variablelist"><dl><dt><span class="term">Net Share Enum</span></dt><dd><p>0x0f</p></dd><dt><span class="term">Net Server Get Info</span></dt><dd><p>0x15</p></dd></dl></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2875405"></a>Net Share Enum</h3></div></div><div></div></div><p><span class="emphasis"><em>Note: share level and switch value in the response are presumably the same as those in the request.</em></span></p><p><span class="emphasis"><em>Note:        cifsrap2.txt (section 5) may be of limited assistance here.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2875426"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">VOID*</span></dt><dd><p>pointer (to server name?)</p></dd><dt><span class="term">UNISTR2</span></dt><dd><p>server name</p></dd><dt><span class="term">UINT8[]</span></dt><dd><p>padding to get unicode string 4-byte aligned with the start of the SMB header.</p></dd><dt><span class="term">UINT32</span></dt><dd><p>share level</p></dd><dt><span class="term">UINT32</span></dt><dd><p>switch value</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to SHARE_INFO_1_CTR</p></dd><dt><span class="term">SHARE_INFO_1_CTR</span></dt><dd><p>share info with 0 entries</p></dd><dt><span class="term">UINT32</span></dt><dd><p>preferred maximum length (0xffff ffff)</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2875550"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>share level</p></dd><dt><span class="term">UINT32</span></dt><dd><p>switch value</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to SHARE_INFO_1_CTR</p></dd><dt><span class="term">SHARE_INFO_1_CTR</span></dt><dd><p>share info (only added if share info ptr is non-zero)</p></dd></dl></div><p>return            0 - indicates success</p></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2875625"></a>Net Server Get Info</h3></div></div><div></div></div><p><span class="emphasis"><em>Note:       level is the same value as in the request.</em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2875638"></a>Request</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UNISTR2</span></dt><dd><p>server name</p></dd><dt><span class="term">UINT32</span></dt><dd><p>switch level</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2875679"></a>Response</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">UINT32</span></dt><dd><p>switch level</p></dd><dt><span class="term">VOID*</span></dt><dd><p>pointer to SERVER_INFO_101</p></dd><dt><span class="term">SERVER_INFO_101</span></dt><dd><p>server info (only added if server info ptr is non-zero)</p></dd></dl></div><p>return            0 - indicates success</p></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2875741"></a>Cryptographic side of NT Domain Authentication</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2875749"></a>Definitions</h3></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Add(A1,A2)</span></dt><dd><p>Intel byte ordered addition of corresponding 4 byte words in arrays A1 and A2</p></dd><dt><span class="term">E(K,D)</span></dt><dd><p>DES ECB encryption of 8 byte data D using 7 byte key K</p></dd><dt><span class="term">lmowf()</span></dt><dd><p>Lan man hash</p></dd><dt><span class="term">ntowf()</span></dt><dd><p>NT hash</p></dd><dt><span class="term">PW</span></dt><dd><p>md4(machine_password) == md4(lsadump $machine.acc) ==
1324 pwdump(machine$) (initially) == md4(lmowf(unicode(machine)))
1325 </p></dd><dt><span class="term">ARC4(K,Lk,D,Ld)</span></dt><dd><p>ARC4 encryption of data D of length Ld with key K of length Lk</p></dd><dt><span class="term">v[m..n(,l)]</span></dt><dd><p>subset of v from bytes m to n, optionally padded with zeroes to length l</p></dd><dt><span class="term">Cred(K,D)</span></dt><dd><p>E(K[7..7,7],E(K[0..6],D)) computes a credential</p></dd><dt><span class="term">Time()</span></dt><dd><p>4 byte current time</p></dd><dt><span class="term">Cc,Cs</span></dt><dd><p>8 byte client and server challenges Rc,Rs: 8 byte client and server credentials</p></dd></dl></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2875911"></a>Protocol</h3></div></div><div></div></div><pre class="programlisting">
1326 C-&gt;S ReqChal,Cc
1327 S-&gt;C Cs
1328 </pre><pre class="programlisting">
1329 C &amp; S compute session key Ks = E(PW[9..15],E(PW[0..6],Add(Cc,Cs)))
1330 </pre><pre class="programlisting">
1331 C: Rc = Cred(Ks,Cc)
1332 C-&gt;S Authenticate,Rc
1333 S: Rs = Cred(Ks,Cs), assert(Rc == Cred(Ks,Cc))
1334 S-&gt;C Rs
1335 C: assert(Rs == Cred(Ks,Cs))
1336 </pre><p>
1337 On joining the domain the client will optionally attempt to change its
1338 password and the domain controller may refuse to update it depending
1339 on registry settings. This will also occur weekly afterwards.
1340 </p><pre class="programlisting">
1341 C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc)
1342 C-&gt;S ServerPasswordSet,Rc',Tc,arc4(Ks[0..7,16],lmowf(randompassword())
1343 C: Rc = Cred(Ks,Rc+Tc+1)
1344 S: assert(Rc' == Cred(Ks,Rc+Tc)), Ts = Time()
1345 S: Rs' = Cred(Ks,Rs+Tc+1)
1346 S-&gt;C Rs',Ts
1347 C: assert(Rs' == Cred(Ks,Rs+Tc+1))
1348 S: Rs = Rs'
1349 </pre><p>
1350 User: U with password P wishes to login to the domain (incidental data
1351 such as workstation and domain omitted)
1352 </p><pre class="programlisting">
1353 C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc)
1354 C-&gt;S NetLogonSamLogon,Rc',Tc,U,arc4(Ks[0..7,16],16,ntowf(P),16), arc4(Ks[0..7,16],16,lmowf(P),16)
1355 S: assert(Rc' == Cred(Ks,Rc+Tc)) assert(passwords match those in SAM)
1356 S: Ts = Time()
1357 </pre><pre class="programlisting">
1358 S-&gt;C Cred(Ks,Cred(Ks,Rc+Tc+1)),userinfo(logon script,UID,SIDs,etc)
1359 C: assert(Rs == Cred(Ks,Cred(Rc+Tc+1))
1360 C: Rc = Cred(Ks,Rc+Tc+1)
1361 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2876010"></a>Comments</h3></div></div><div></div></div><p>
1362 On first joining the domain the session key could be computed by
1363 anyone listening in on the network as the machine password has a well
1364 known value. Until the machine is rebooted it will use this session
1365 key to encrypt NT and LM one way functions of passwords which are
1366 password equivalents. Any user who logs in before the machine has been
1367 rebooted a second time will have their password equivalent exposed. Of
1368 course the new machine password is exposed at this time anyway.
1369 </p><p>
1370 None of the returned user info such as logon script, profile path and
1371 SIDs *appear* to be protected by anything other than the TCP checksum.
1372 </p><p>
1373 The server time stamps appear to be ignored.
1374 </p><p>
1375 The client sends a ReturnAuthenticator in the SamLogon request which I
1376 can't find a use for.  However its time is used as the timestamp
1377 returned by the server.
1378 </p><p>
1379 The password OWFs should NOT be sent over the network reversibly
1380 encrypted. They should be sent using ARC4(Ks,md4(owf)) with the server
1381 computing the same function using the owf values in the SAM.
1382 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2876057"></a>SIDs and RIDs</h2></div></div><div></div></div><p>
1383 SIDs and RIDs are well documented elsewhere.
1384 </p><p>
1385 A SID is an NT Security ID (see DOM_SID structure).  They are of the form:
1386 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>revision-NN-SubAuth1-SubAuth2-SubAuth3... </td></tr><tr><td>revision-0xNNNNNNNNNNNN-SubAuth1-SubAuth2-SubAuth3...</td></tr></table><p>
1387 currently, the SID revision is 1.
1388 The Sub-Authorities are known as Relative IDs (RIDs).
1389 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2876097"></a>Well-known SIDs</h3></div></div><div></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2876104"></a>Universal well-known SIDs</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">Null SID</span></dt><dd><p>S-1-0-0</p></dd><dt><span class="term">World</span></dt><dd><p>S-1-1-0</p></dd><dt><span class="term">Local</span></dt><dd><p>S-1-2-0</p></dd><dt><span class="term">Creator Owner ID</span></dt><dd><p>S-1-3-0</p></dd><dt><span class="term">Creator Group ID</span></dt><dd><p>S-1-3-1</p></dd><dt><span class="term">Creator Owner Server ID</span></dt><dd><p>S-1-3-2</p></dd><dt><span class="term">Creator Group Server ID</span></dt><dd><p>S-1-3-3</p></dd><dt><span class="term">(Non-unique IDs)</span></dt><dd><p>S-1-4</p></dd></dl></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2876231"></a>NT well-known SIDs</h4></div></div><div></div></div><div class="variablelist"><dl><dt><span class="term">NT Authority</span></dt><dd><p>S-1-5</p></dd><dt><span class="term">Dialup</span></dt><dd><p>S-1-5-1</p></dd><dt><span class="term">Network</span></dt><dd><p>S-1-5-2</p></dd><dt><span class="term">Batch</span></dt><dd><p>S-1-5-3</p></dd><dt><span class="term">Interactive</span></dt><dd><p>S-1-5-4</p></dd><dt><span class="term">Service</span></dt><dd><p>S-1-5-6</p></dd><dt><span class="term">AnonymousLogon(aka null logon session)</span></dt><dd><p>S-1-5-7</p></dd><dt><span class="term">Proxy</span></dt><dd><p>S-1-5-8</p></dd><dt><span class="term">ServerLogon(aka domain controller account)</span></dt><dd><p>S-1-5-8</p></dd><dt><span class="term">(Logon IDs)</span></dt><dd><p>S-1-5-5-X-Y</p></dd><dt><span class="term">(NT non-unique IDs)</span></dt><dd><p>S-1-5-0x15-...</p></dd><dt><span class="term">(Built-in domain)</span></dt><dd><p>s-1-5-0x20</p></dd></dl></div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2876412"></a>Well-known RIDS</h3></div></div><div></div></div><p>
1390 A RID is a sub-authority value, as part of either a SID, or in the case
1391 of Group RIDs, part of the DOM_GID structure, in the USER_INFO_1
1392 structure, in the LSA SAM Logon response.
1393 </p><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2876426"></a>Well-known RID users</h4></div></div><div></div></div><div class="segmentedlist"><p><b>Groupname: </b>DOMAIN_USER_RID_ADMIN</p><p><b>????: </b>0x0000</p><p><b>RID: </b>01F4</p><p><b>Groupname: </b>DOMAIN_USER_RID_GUEST</p><p><b>????: </b>0x0000</p><p><b>RID: </b>01F5</p></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2876474"></a>Well-known RID groups</h4></div></div><div></div></div><div class="segmentedlist"><p><b>Groupname: </b>  DOMAIN_GROUP_RID_ADMINS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0200</p><p><b>Groupname: </b>       DOMAIN_GROUP_RID_USERS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0201</p><p><b>Groupname: </b>        DOMAIN_GROUP_RID_GUESTS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0202</p></div></div><div class="sect3" lang="en"><div class="titlepage"><div><div><h4 class="title"><a name="id2876534"></a>Well-known RID aliases</h4></div></div><div></div></div><div class="segmentedlist"><p><b>Groupname: </b>        DOMAIN_ALIAS_RID_ADMINS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0220</p><p><b>Groupname: </b>       DOMAIN_ALIAS_RID_USERS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0221</p><p><b>Groupname: </b>        DOMAIN_ALIAS_RID_GUESTS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0222</p><p><b>Groupname: </b>       DOMAIN_ALIAS_RID_POWER_USERS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0223</p><p><b>Groupname: </b>  DOMAIN_ALIAS_RID_ACCOUNT_OPS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0224</p><p><b>Groupname: </b>  DOMAIN_ALIAS_RID_SYSTEM_OPS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0225</p><p><b>Groupname: </b>   DOMAIN_ALIAS_RID_PRINT_OPS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0226</p><p><b>Groupname: </b>    DOMAIN_ALIAS_RID_BACKUP_OPS</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0227</p><p><b>Groupname: </b>   DOMAIN_ALIAS_RID_REPLICATOR</p><p><b>????: </b>0x0000</p><p><b>RID: </b>0228</p></div></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="printing"></a>Chapter 11. Samba Printing Internals</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Gerald</span> <span class="surname">Carter</span></h3></div></div><div><p class="pubdate">October 2002</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2876697">Abstract</a></dt><dt><a href="#id2876713">
1394 Printing Interface to Various Back ends
1395 </a></dt><dt><a href="#id2876809">
1396 Print Queue TDB's
1397 </a></dt><dt><a href="#id2877031">
1398 ChangeID and Client Caching of Printer Information
1399 </a></dt><dt><a href="#id2877045">
1400 Windows NT/2K Printer Change Notify
1401 </a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2876697"></a>Abstract</h2></div></div><div></div></div><p>
1402 The purpose of this document is to provide some insight into
1403 Samba's printing functionality and also to describe the semantics
1404 of certain features of Windows client printing.
1405 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2876713"></a>
1406 Printing Interface to Various Back ends
1407 </h2></div></div><div></div></div><p>
1408 Samba uses a table of function pointers to seven functions.  The
1409 function prototypes are defined in the <tt class="varname">printif</tt> structure declared
1410 in <tt class="filename">printing.h</tt>.
1411 </p><div class="itemizedlist"><ul type="disc"><li><p>retrieve the contents of a print queue</p></li><li><p>pause the print queue</p></li><li><p>resume a paused print queue</p></li><li><p>delete a job from the queue</p></li><li><p>pause a job in the print queue</p></li><li><p>result a paused print job in the queue</p></li><li><p>submit a job to the print queue</p></li></ul></div><p>
1412 Currently there are only two printing back end implementations
1413 defined.
1414 </p><div class="itemizedlist"><ul type="disc"><li><p>a generic set of functions for working with standard UNIX
1415         printing subsystems</p></li><li><p>a set of CUPS specific functions (this is only enabled if
1416         the CUPS libraries were located at compile time).</p></li></ul></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2876809"></a>
1417 Print Queue TDB's
1418 </h2></div></div><div></div></div><p>
1419 Samba provides periodic caching of the output from the &quot;lpq command&quot;
1420 for performance reasons.  This cache time is configurable in seconds.
1421 Obviously the longer the cache time the less often smbd will be
1422 required to exec a copy of lpq.  However, the accuracy of the print
1423 queue contents displayed to clients will be diminished as well.
1424 </p><p>
1425 The list of currently opened print queue TDB's can be found
1426 be examining the list of tdb_print_db structures ( see print_db_head
1427 in printing.c ). A queue TDB is opened using the wrapper function
1428 printing.c:get_print_db_byname().  The function ensures that smbd
1429 does not open more than MAX_PRINT_DBS_OPEN in an effort to prevent
1430 a large print server from exhausting all available file descriptors.
1431 If the number of open queue TDB's exceeds the MAX_PRINT_DBS_OPEN
1432 limit, smbd falls back to a most recently used algorithm for maintaining
1433 a list of open TDB's.
1434 </p><p>
1435 There are two ways in which a a print job can be entered into
1436 a print queue's TDB.  The first is to submit the job from a Windows
1437 client which will insert the job information directly into the TDB.
1438 The second method is to have the print job picked up by executing the
1439 &quot;lpq command&quot;.
1440 </p><pre class="programlisting">
1441 /* included from printing.h */
1442 struct printjob {
1443         pid_t pid; /* which process launched the job */
1444         int sysjob; /* the system (lp) job number */
1445         int fd; /* file descriptor of open file if open */
1446         time_t starttime; /* when the job started spooling */
1447         int status; /* the status of this job */
1448         size_t size; /* the size of the job so far */
1449         int page_count; /* then number of pages so far */
1450         BOOL spooled; /* has it been sent to the spooler yet? */
1451         BOOL smbjob; /* set if the job is a SMB job */
1452         fstring filename; /* the filename used to spool the file */
1453         fstring jobname; /* the job name given to us by the client */
1454         fstring user; /* the user who started the job */
1455         fstring queuename; /* service number of printer for this job */
1456         NT_DEVICEMODE *nt_devmode;
1457 };
1458 </pre><p>
1459 The current manifestation of the printjob structure contains a field
1460 for the UNIX job id returned from the &quot;lpq command&quot; and a Windows job
1461 ID (32-bit bounded by PRINT_MAX_JOBID).  When a print job is returned
1462 by the &quot;lpq command&quot; that does not match an existing job in the queue's
1463 TDB, a 32-bit job ID above the &lt;*vance doesn't know what word is missing here*&gt; is generating by adding UNIX_JOB_START to
1464 the id reported by lpq.
1465 </p><p>
1466 In order to match a 32-bit Windows jobid onto a 16-bit lanman print job
1467 id, smbd uses an in memory TDB to match the former to a number appropriate
1468 for old lanman clients.
1469 </p><p>
1470 When updating a print queue, smbd will perform the following
1471 steps ( refer to <tt class="filename">print.c:print_queue_update()</tt> ):
1472 </p><div class="orderedlist"><ol type="1"><li><p>Check to see if another smbd is currently in 
1473         the process of updating the queue contents by checking the pid 
1474         stored in <tt class="constant">LOCK/<i class="replaceable"><tt>printer_name</tt></i></tt>.  
1475         If so, then do not update the TDB.</p></li><li><p>Lock the mutex entry in the TDB and store our own pid.
1476         Check that this succeeded, else fail.</p></li><li><p>Store the updated time stamp for the new cache
1477         listing</p></li><li><p>Retrieve the queue listing via &quot;lpq command&quot;</p></li><li><pre class="programlisting">
1478         foreach job in the queue
1479         {
1480                 if the job is a UNIX job, create a new entry;
1481                 if the job has a Windows based jobid, then
1482                 {
1483                         Lookup the record by the jobid;
1484                         if the lookup failed, then
1485                                 treat it as a UNIX job;
1486                         else
1487                                 update the job status only
1488                 }
1489         }</pre></li><li><p>Delete any jobs in the TDB that are not
1490         in the in the lpq listing</p></li><li><p>Store the print queue status in the TDB</p></li><li><p>update the cache time stamp again</p></li></ol></div><p>
1491 Note that it is the contents of this TDB that is returned to Windows
1492 clients and not the actual listing from the &quot;lpq command&quot;.
1493 </p><p>
1494 The NT_DEVICEMODE stored as part of the printjob structure is used to
1495 store a pointer to a non-default DeviceMode associated with the print
1496 job.  The pointer will be non-null when the client included a Device
1497 Mode in the OpenPrinterEx() call and subsequently submitted a job for
1498 printing on that same handle.  If the client did not include a Device
1499 Mode in the OpenPrinterEx() request, the nt_devmode field is NULL
1500 and the job has the printer's device mode associated with it by default.
1501 </p><p>
1502 Only non-default Device Mode are stored with print jobs in the print
1503 queue TDB.  Otherwise, the Device Mode is obtained from the printer
1504 object when the client issues a GetJob(level == 2) request.
1505 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877031"></a>
1506 ChangeID and Client Caching of Printer Information
1507 </h2></div></div><div></div></div><p>
1508 [To be filled in later]
1509 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877045"></a>
1510 Windows NT/2K Printer Change Notify
1511 </h2></div></div><div></div></div><p>
1512 When working with Windows NT+ clients, it is possible for a
1513 print server to use RPC to send asynchronous change notification
1514 events to clients for certain printer and print job attributes.
1515 This can be useful when the client needs to know that a new
1516 job has been added to the queue for a given printer or that the
1517 driver for a printer has been changed.  Note that this is done
1518 entirely orthogonal to cache updates based on a new ChangeID for
1519 a printer object.
1520 </p><p>
1521 The basic set of RPC's used to implement change notification are
1522 </p><div class="itemizedlist"><ul type="disc"><li><p>RemoteFindFirstPrinterChangeNotifyEx ( RFFPCN )</p></li><li><p>RemoteFindNextPrinterChangeNotifyEx ( RFNPCN )</p></li><li><p>FindClosePrinterChangeNotify( FCPCN )</p></li><li><p>ReplyOpenPrinter</p></li><li><p>ReplyClosePrinter</p></li><li><p>RouteRefreshPrinterChangeNotify ( RRPCN )</p></li></ul></div><p>
1523 One additional RPC is available to a server, but is never used by the
1524 Windows spooler service:
1525 </p><div class="itemizedlist"><ul type="disc"><li><p>RouteReplyPrinter()</p></li></ul></div><p>
1526 The opnum for all of these RPC's are defined in include/rpc_spoolss.h
1527 </p><p>
1528 Windows NT print servers use a bizarre method of sending print
1529 notification event to clients.  The process of registering a new change
1530 notification handle is as follows.  The 'C' is for client and the
1531 'S' is for server.  All error conditions have been eliminated.
1532 </p><pre class="programlisting">
1533 C:      Obtain handle to printer or to the printer
1534         server via the standard OpenPrinterEx() call.
1535 S:      Respond with a valid handle to object
1536
1537 C:      Send a RFFPCN request with the previously obtained
1538         handle with either (a) set of flags for change events
1539         to monitor, or (b) a PRINTER_NOTIFY_OPTIONS structure
1540         containing the event information to monitor.  The windows
1541         spooler has only been observed to use (b).
1542 S:      The &lt;* another missing word*&gt; opens a new TCP session to the client (thus requiring
1543         all print clients to be CIFS servers as well) and sends
1544         a ReplyOpenPrinter() request to the client.
1545 C:      The client responds with a printer handle that can be used to
1546         send event notification messages.
1547 S:      The server replies success to the RFFPCN request.
1548
1549 C:      The windows spooler follows the RFFPCN with a RFNPCN
1550         request to fetch the current values of all monitored
1551         attributes.
1552 S:      The server replies with an array SPOOL_NOTIFY_INFO_DATA
1553         structures (contained in a SPOOL_NOTIFY_INFO structure).
1554
1555 C:      If the change notification handle is ever released by the
1556         client via a FCPCN request, the server sends a ReplyClosePrinter()
1557         request back to the client first.  However a request of this
1558         nature from the client is often an indication that the previous
1559         notification event was not marshalled correctly by the server
1560         or a piece of data was wrong.
1561 S:      The server closes the internal change notification handle
1562         (POLICY_HND) and does not send any further change notification
1563         events to the client for that printer or job.
1564 </pre><p>
1565 The current list of notification events supported by Samba can be
1566 found by examining the internal tables in srv_spoolss_nt.c
1567 </p><div class="itemizedlist"><ul type="disc"><li><p>printer_notify_table[]</p></li><li><p>job_notify_table[]</p></li></ul></div><p>
1568 When an event occurs that could be monitored, smbd sends a message
1569 to itself about the change.  The list of events to be transmitted
1570 are queued by the smbd process sending the message to prevent an
1571 overload of TDB usage and the internal message is sent during smbd's
1572 idle loop (refer to printing/notify.c and the functions
1573 send_spoolss_notify2_msg() and print_notify_send_messages() ).
1574 </p><p>
1575 The decision of whether or not the change is to be sent to connected
1576 clients is made by the routine which actually sends the notification.
1577 ( refer to srv_spoolss_nt.c:recieve_notify2_message() ).
1578 </p><p>
1579 Because it possible to receive a listing of multiple changes for
1580 multiple printers, the notification events must be split into
1581 categories by the printer name.  This makes it possible to group
1582 multiple change events to be sent in a single RPC according to the
1583 printer handle obtained via a ReplyOpenPrinter().
1584 </p><p>
1585 The actual change notification is performed using the RRPCN request
1586 RPC.  This packet contains
1587 </p><div class="itemizedlist"><ul type="disc"><li><p>the printer handle registered with the
1588 client's spooler on which the change occurred</p></li><li><p>The change_low value which was sent as part
1589 of the last RFNPCN request from the client</p></li><li><p>The SPOOL_NOTIFY_INFO container with the event
1590 information</p></li></ul></div><p>
1591 A <tt class="varname">SPOOL_NOTIFY_INFO</tt> contains:
1592 </p><div class="itemizedlist"><ul type="disc"><li><p>the version and flags field are predefined
1593 and should not be changed</p></li><li><p>The count field is the number of entries
1594 in the SPOOL_NOTIFY_INFO_DATA array</p></li></ul></div><p>
1595 The <tt class="varname">SPOOL_NOTIFY_INFO_DATA</tt> entries contain:
1596 </p><div class="itemizedlist"><ul type="disc"><li><p>The type defines whether or not this event
1597 is for a printer or a print job</p></li><li><p>The field is the flag identifying the event</p></li><li><p>the notify_data union contains the new valuie of the
1598 attribute</p></li><li><p>The enc_type defines the size of the structure for marshalling
1599 and unmarshalling</p></li><li><p>(a) the id must be 0 for a printer event on a printer handle.
1600 (b) the id must be the job id for an event on a printer job
1601 (c) the id must be the matching number of the printer index used
1602 in the response packet to the RFNPCN when using a print server
1603 handle for notification.  Samba currently uses the snum of
1604 the printer for this which can break if the list of services
1605 has been modified since the notification handle was registered.</p></li><li><p>The size is either (a) the string length in UNICODE for strings,
1606 (b) the size in bytes of the security descriptor, or (c) 0 for
1607 data values.</p></li></ul></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="wins"></a>Chapter 12. Samba WINS Internals</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Gerald</span> <span class="surname">Carter</span></h3></div></div><div><p class="pubdate">October 2002</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2877426">WINS Failover</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877426"></a>WINS Failover</h2></div></div><div></div></div><p>
1608 The current Samba codebase possesses the capability to use groups of WINS
1609 servers that share a common namespace for NetBIOS name registration and 
1610 resolution.  The formal parameter syntax is
1611 </p><pre class="programlisting">
1612         WINS_SERVER_PARAM       = SERVER [ SEPARATOR SERVER_LIST ]
1613         WINS_SERVER_PARAM       = &quot;wins server&quot;
1614         SERVER                  = ADDR[:TAG]
1615         ADDR                    = ip_addr | fqdn
1616         TAG                     = string
1617         SEPARATOR               = comma | \s+
1618         SERVER_LIST             = SERVER [ SEPARATOR SERVER_LIST ]
1619 </pre><p>
1620 A simple example of a valid wins server setting is
1621 </p><pre class="programlisting">
1622 [global]
1623         wins server = 192.168.1.2 192.168.1.3
1624 </pre><p>
1625 In the event that no TAG is defined in for a SERVER in the list, smbd assigns a default
1626 TAG of &quot;*&quot;.  A TAG is used to group servers of a shared NetBIOS namespace together.  Upon
1627 startup, nmbd will attempt to register the netbios name value with one server in each
1628 tagged group.
1629 </p><p>
1630 An example using tags to group WINS servers together is show here.  Note that the use of
1631 interface names in the tags is only by convention and is not a technical requirement.
1632 </p><pre class="programlisting">
1633 [global]
1634         wins server = 192.168.1.2:eth0 192.168.1.3:eth0 192.168.2.2:eth1
1635 </pre><p>
1636 Using this configuration, nmbd would attempt to register the server's NetBIOS name 
1637 with one WINS server in each group.  Because the &quot;eth0&quot; group has two servers, the 
1638 second server would only be used when a registration (or resolution) request to 
1639 the first server in that group timed out.
1640 </p><p>
1641 NetBIOS name resolution follows a similar pattern as name registration.  When resolving 
1642 a NetBIOS name via WINS, smbd and other Samba programs will attempt to query a single WINS 
1643 server in a tagged group until either a positive response is obtained at least once or 
1644 until a server from every tagged group has responded negatively to the name query request.
1645 If a timeout occurs when querying a specific WINS server, that server is marked as down to 
1646 prevent further timeouts and the next server in the WINS group is contacted.  Once marked as 
1647 dead, Samba will not attempt to contact that server for name registration/resolution queries 
1648 for a period of 10 minutes.
1649 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="sam"></a>Chapter 13. The Upcoming SAM System</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Andrew</span> <span class="surname">Bartlett</span></h3></div></div><div><p class="pubdate">1 October 2002</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2877582">Security in the 'new SAM'</a></dt><dt><a href="#id2877712">Standalone from UNIX</a></dt><dt><a href="#id2877739">Handles and Races in the new SAM</a></dt><dt><a href="#id2877808">Layers</a></dt><dd><dl><dt><a href="#id2877815">Application</a></dt><dt><a href="#id2877831">SAM Interface</a></dt><dt><a href="#id2877859">SAM Modules</a></dt></dl></dd><dt><a href="#id2877880">SAM Modules</a></dt><dd><dl><dt><a href="#id2877888">Special Module: sam_passdb</a></dt><dt><a href="#id2877906">sam_ads</a></dt></dl></dd><dt><a href="#id2877935">Memory Management</a></dt><dt><a href="#id2878035">Testing</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877582"></a>Security in the 'new SAM'</h2></div></div><div></div></div><p>One of the biggest problems with passdb is it's implementation of
1650 'security'.  Access control is on a 'are you root at the moment' basis,
1651 and it has no concept of NT ACLs.  Things like ldapsam had to add
1652 'magic' 'are you root' checks.</p><p>We took this very seriously when we started work, and the new structure
1653 is designed with this in mind, from the ground up.  Each call to the SAM
1654 has a NT_TOKEN and (if relevant) an 'access desired'.  This is either
1655 provided as a parameter, or implicitly supplied by the object being
1656 accessed.</p><p>
1657 For example, when you call 
1658 </p><pre class="programlisting">
1659 NTSTATUS sam_get_account_by_name(const SAM_CONTEXT *context, const
1660 NT_USER_TOKEN *access_token, uint32 access_desired, const char *domain,
1661 const char *name, SAM_ACCOUNT_HANDLE **account)
1662 </pre><p>
1663 The context can be NULL (and is used to allow import/export by setting
1664 up 2 contexts, and allowing calls on both simultaneously)
1665 </p><p>
1666 The access token *must* be specified.  Normally the user's token out of
1667 current_user, this can also be a global 'system' context.
1668 </p><p>
1669 The access desired is as per the ACL, for passing to the seaccess stuff.
1670 </p><p>
1671 The domain/username are standard.  Even if we only have one domain,
1672 keeping this ensures that we don't get 'unqualified' usernames (same
1673 problem as we had with unqualified SIDs).
1674 </p><p>
1675 We return a 'handle'.  This is opaque to the rest of Samba, but is
1676 operated on by get/set routines, all of which return NTSTATUS.
1677 </p><p>
1678 The access checking is done by the SAM module.   The reason it is not
1679 done 'above' the interface is to ensure a 'choke point'.  I put a lot of
1680 effort into the auth subsystem to ensure we never 'accidentally' forgot
1681 to check for null passwords, missed a restriction etc.  I intend the SAM
1682 to be written with the same caution.
1683 </p><p>
1684 The reason the access checking is not handled by the interface itself is
1685 due to the different implementations it make take on.  For example, on
1686 ADS, you cannot set a password over a non-SSL connection.  Other
1687 backends may have similar requirements - we need to leave this policy up
1688 to the modules.  They will naturally have access to 'helper' procedures
1689 and good examples to avoid mishaps.
1690 </p><p>
1691 (Furthermore, some backends my actually chose to push the whole ACL
1692 issue to the remote server, and - assuming ldap for this example - bind
1693 as the user directly)
1694 </p><p>
1695 Each returned handle has an internal 'access permitted', which allows
1696 the 'get' and 'set' routines to return 'ACCESS_DENIED' for things that
1697 were not able to be retrieved from the backend.  This removes the need
1698 to specify the NT_TOKEN on every operation, and allows for 'object not
1699 present' to be easily distinguished from 'access denied'.
1700 </p><p>
1701 When you 'set' an object (calling sam_update_account) the internal
1702 details are again used.  Each change that has been made to the object
1703 has been flagged, so as to avoid race conditions (on unmodified
1704 components) and to avoid violating any extra ACL requirements on the
1705 actual data store (like the LDAP server).
1706 </p><p>
1707 Finally, we have generic get_sec_desc() and set_sec_desc() routines to
1708 allow external ACL manipulation.  These do lookups based on SID.
1709 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877712"></a>Standalone from UNIX</h2></div></div><div></div></div><p>
1710 One of the primary tenants of the 'new SAM' is that it would not attempt
1711 to deal with 'what unix id for that'.  This would be left to the 'SMS'
1712 (Sid Mapping System') or SID farm, and probably administered via
1713 winbind.  We have had constructive discussion on how 'basic' unix
1714 accounts like 'root' would be handled, and we think this can work.  
1715 Accounts not preexisting in unix would be served up via winbind.
1716 </p><p>
1717 This is an *optional* part, and my preferred end-game.  We have a fare
1718 way to go before things like winbind up to it however.
1719 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877739"></a>Handles and Races in the new SAM</h2></div></div><div></div></div><p>
1720 One of the things that the 'new SAM' work has tried to face is both
1721 compatibility with existing code, and a closer alignment to the SAMR
1722 interface.  I consider SAMR to be a 'primary customer' to the this work,
1723 because if we get alignment with that wrong, things get more, rather
1724 than less complex.  Also, most other parts of Samba are much more
1725 flexible with what they can allow.
1726 </p><p>
1727 In any case, that was a decision taken as to how the general design
1728 would progress.  BTW, my understanding of SAMR may be completely flawed.
1729 </p><p>
1730 One of the most race-prone areas of the new code is the conflicting
1731 update problem.  We have taken two approaches:  
1732 </p><div class="itemizedlist"><ul type="disc"><li><p>'Not conflicting' conflicts.  Due to the way usrmgr operates, it will
1733 open a user, display all the properties and *save* them all, even if you
1734 don't change any.
1735 </p><p>
1736 For this, see what I've done in rpc_server/srv_samr_util.c.  I intend
1737 to take this one step further, and operate on the 'handle' that the
1738 values were read from.  This should mean that we only update things that
1739 have *really* changed.
1740 </p></li><li><p>
1741 'conflicting' updates:  Currently we don't deal with this (in passdb
1742 or the new sam stuff), but the design is sufficiently flexible to 'deny'
1743 a second update.  I don't foresee locking records however.
1744 </p></li></ul></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877808"></a>Layers</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2877815"></a>Application</h3></div></div><div></div></div><p>
1745 This is where smbd, samtest and whatever end-user replacement we have
1746 for pdbedit sits.  They use only the SAM interface, and do not get
1747 'special knowledge' of what is below them.
1748 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2877831"></a>SAM Interface</h3></div></div><div></div></div><p>
1749 This level 'owns' the various handle structures, the get/set routines on
1750 those structures and provides the public interface.  The application
1751 layer may initialize a 'context' to be passed to all interface routines,
1752 else a default, self-initialising context will be supplied.  This layser
1753 finds the appropriate backend module for the task, and tries very hard
1754 not to need to much 'knowledge'.  It should just provide the required
1755 abstraction to the modules below, and arrange for their initial loading.
1756 </p><p>
1757 We could possibly add ACL checking at this layer, to avoid discrepancies
1758 in implementation modules.
1759 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2877859"></a>SAM Modules</h3></div></div><div></div></div><p>
1760 These do not communicate with the application directly, only by setting
1761 values in the handles, and receiving requests from the interface.  These
1762 modules are responsible for translating values from the handle's
1763 .private into (say) an LDAP modification list.  The module is expected
1764 to 'know' things like it's own domain SID, domain name, and any other
1765 state attached to the SAM.  Simpler modules may call back to some helper
1766 routine.
1767 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877880"></a>SAM Modules</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2877888"></a>Special Module: sam_passdb</h3></div></div><div></div></div><p>
1768 In order for there to be a smooth transition, kai is writing a module
1769 that reads existing passdb backends, and translates them into SAM
1770 replies.  (Also pulling data from the account policy DB etc).  We also
1771 intend to write a module that does the reverse - gives the SAM a passdb
1772 interface.
1773 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2877906"></a>sam_ads</h3></div></div><div></div></div><p>
1774 This is the first of the SAM modules to be committed to the tree -
1775 mainly because I needed to coordinate work with metze (who authored most
1776 of it).  This module aims to use Samba's libads code to provide an
1777 Active Directory LDAP client, suitable for use on a mixed-mode DC. 
1778 While it is currently being tested against Win2k servers (with a
1779 password in the smb.conf file) it is expected to eventually use a
1780 (possibly modified) OpenLDAP server.  We hope that this will assist in
1781 the construction of an Samba AD DC.
1782 </p><p>
1783 We also intend to construct a Samba 2.2/3.0 compatible ldap module,
1784 again using libads code.
1785 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2877935"></a>Memory Management</h2></div></div><div></div></div><p> 
1786 The 'new SAM' development effort also concerned itself with getting a
1787 sane implementation of memory management.  It was decided that we would
1788 be (as much as possible) talloc based, using an 'internal talloc
1789 context' on many objects.  That is, the creation of an object would
1790 initiate it's own internal talloc context, and this would be used for
1791 all operations on that object.  Much of this is already implemented in
1792 passdb.  Also, like passdb, it will be possible to specify that some
1793 object actually be created on a specified context.  
1794 </p><p>
1795 Memory management is important here because the APIs in the 'new SAM' do
1796 not use 'pdb_init()' or an equivalent.  They always allocate new
1797 objects.  Enumeration's are slightly different, and occur on a supplied
1798 context that 'owns' the entire list, rather than per-element.  (the
1799 enumeration functions return an array of all elements - not full handles
1800 just basic (and public) info)  Likewise for things that fill in a char
1801 **.
1802 </p><p>For example:</p><pre class="programlisting">
1803 NTSTATUS sam_lookup_sid(const SAM_CONTEXT *context, const NT_USER_TOKEN
1804 *access_token, TALLOC_CTX *mem_ctx, const DOM_SID *sid, char **name,
1805 uint32 *type)
1806 </pre><p>Takes a context to allocate the 'name' on, while:</p><pre class="programlisting">
1807 NTSTATUS sam_get_account_by_sid(const SAM_CONTEXT *context, const
1808 NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID
1809 *accountsid, SAM_ACCOUNT_HANDLE **account)
1810 </pre><p>Allocates a handle and stores the allocation context on that handle.</p><p>I think that the following:</p><pre class="programlisting">
1811 NTSTATUS sam_enum_accounts(const SAM_CONTEXT *context, const
1812 NT_USER_TOKEN *access_token, const DOM_SID *domainsid, uint16 acct_ctrl,
1813 int32 *account_count, SAM_ACCOUNT_ENUM **accounts)
1814 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878035"></a>Testing</h2></div></div><div></div></div><p>
1815 Testing is vital in any piece of software, and Samba is certainly no
1816 exception. In designing this new subsystem, we have taken care to ensure
1817 it is easily tested, independent of outside protocols.
1818 </p><p>
1819 To this end, Jelmer has constructed 'samtest'.  
1820 </p><p>
1821 This utility (see torture/samtest.c) is structured like rpcclient, but
1822 instead operates on the SAM subsystem.  It creates a 'custom' SAM
1823 context, that may be distinct from the default values used by the rest
1824 of the system, and can load a separate configuration file.  
1825 </p><p>
1826 A small number of commands are currently implemented, but these have
1827 already proved vital in testing.   I expect SAM module authors will find
1828 it particularly valuable.
1829 </p><p>Example useage:</p><p><tt class="prompt">$</tt> <b class="command">bin/samtest</b></p><pre class="programlisting">
1830 &gt; context ads:ldap://192.168.1.96
1831 </pre><p>
1832 (this loads a new context, using the new ADS module.  The parameter is
1833 the 'location' of the ldap server)
1834 </p><pre class="programlisting">
1835 &gt; lookup_name DOMAIN abartlet
1836 </pre><p>
1837 (returns a sid).
1838 </p><p>
1839 Because the 'new SAM' is NT ACL based, there will be a command to
1840 specify an arbitrary NT ACL, but for now it uses 'system' by default.
1841 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="pwencrypt"></a>Chapter 14. LanMan and NT Password Encryption</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Jeremy</span> <span class="surname">Allison</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><br>
1842                                 <tt class="email">&lt;<a href="mailto:samba@samba.org">samba@samba.org</a>&gt;</tt><br>
1843                         </p></div></div></div></div><div><p class="pubdate">19 Apr 1999</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2878174">Introduction</a></dt><dt><a href="#id2878193">How does it work?</a></dt><dt><a href="#id2878320">The smbpasswd file</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878174"></a>Introduction</h2></div></div><div></div></div><p>With the development of LanManager and Windows NT 
1844         compatible password encryption for Samba, it is now able 
1845         to validate user connections in exactly the same way as 
1846         a LanManager or Windows NT server.</p><p>This document describes how the SMB password encryption 
1847         algorithm works and what issues there are in choosing whether 
1848         you want to use it. You should read it carefully, especially 
1849         the part about security and the &quot;PROS and CONS&quot; section.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878193"></a>How does it work?</h2></div></div><div></div></div><p>LanManager encryption is somewhat similar to UNIX 
1850         password encryption. The server uses a file containing a 
1851         hashed value of a user's password.  This is created by taking 
1852         the user's plaintext password, capitalising it, and either 
1853         truncating to 14 bytes or padding to 14 bytes with null bytes. 
1854         This 14 byte value is used as two 56 bit DES keys to encrypt 
1855         a 'magic' eight byte value, forming a 16 byte value which is 
1856         stored by the server and client. Let this value be known as 
1857         the &quot;hashed password&quot;.</p><p>Windows NT encryption is a higher quality mechanism, 
1858         consisting of doing an MD4 hash on a Unicode version of the user's 
1859         password. This also produces a 16 byte hash value that is 
1860         non-reversible.</p><p>When a client (LanManager, Windows for WorkGroups, Windows 
1861         95 or Windows NT) wishes to mount a Samba drive (or use a Samba 
1862         resource), it first requests a connection and negotiates the 
1863         protocol that the client and server will use. In the reply to this 
1864         request the Samba server generates and appends an 8 byte, random 
1865         value - this is stored in the Samba server after the reply is sent 
1866         and is known as the &quot;challenge&quot;.  The challenge is different for 
1867         every client connection.</p><p>The client then uses the hashed password (16 byte values 
1868         described above), appended with 5 null bytes, as three 56 bit 
1869         DES keys, each of which is used to encrypt the challenge 8 byte 
1870         value, forming a 24 byte value known as the &quot;response&quot;.</p><p>In the SMB call SMBsessionsetupX (when user level security 
1871         is selected) or the call SMBtconX (when share level security is 
1872         selected), the 24 byte response is returned by the client to the 
1873         Samba server.  For Windows NT protocol levels the above calculation 
1874         is done on both hashes of the user's password and both responses are 
1875         returned in the SMB call, giving two 24 byte values.</p><p>The Samba server then reproduces the above calculation, using 
1876         its own stored value of the 16 byte hashed password (read from the 
1877         <tt class="filename">smbpasswd</tt> file - described later) and the challenge 
1878         value that it kept from the negotiate protocol reply. It then checks 
1879         to see if the 24 byte value it calculates matches the 24 byte value 
1880         returned to it from the client.</p><p>If these values match exactly, then the client knew the 
1881         correct password (or the 16 byte hashed value - see security note 
1882         below) and is thus allowed access. If not, then the client did not 
1883         know the correct password and is denied access.</p><p>Note that the Samba server never knows or stores the cleartext 
1884         of the user's password - just the 16 byte hashed values derived from 
1885         it. Also note that the cleartext password or 16 byte hashed values 
1886         are never transmitted over the network - thus increasing security.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878320"></a>The smbpasswd file</h2></div></div><div></div></div><a name="SMBPASSWDFILEFORMAT"></a><p>In order for Samba to participate in the above protocol 
1887         it must be able to look up the 16 byte hashed values given a user name.
1888         Unfortunately, as the UNIX password value is also a one way hash
1889         function (ie. it is impossible to retrieve the cleartext of the user's
1890         password given the UNIX hash of it), a separate password file
1891         containing this 16 byte value must be kept. To minimise problems with
1892         these two password files, getting out of sync, the UNIX <tt class="filename">
1893         /etc/passwd</tt> and the <tt class="filename">smbpasswd</tt> file, 
1894         a utility, <b class="command">mksmbpasswd.sh</b>, is provided to generate
1895         a smbpasswd file from a UNIX <tt class="filename">/etc/passwd</tt> file.
1896         </p><p>To generate the smbpasswd file from your <tt class="filename">/etc/passwd
1897         </tt> file use the following command:</p><p><tt class="prompt">$ </tt><b class="userinput"><tt>cat /etc/passwd | mksmbpasswd.sh
1898         &gt; /usr/local/samba/private/smbpasswd</tt></b></p><p>If you are running on a system that uses NIS, use</p><p><tt class="prompt">$ </tt><b class="userinput"><tt>ypcat passwd | mksmbpasswd.sh
1899         &gt; /usr/local/samba/private/smbpasswd</tt></b></p><p>The <b class="command">mksmbpasswd.sh</b> program is found in 
1900         the Samba source directory. By default, the smbpasswd file is 
1901         stored in :</p><p><tt class="filename">/usr/local/samba/private/smbpasswd</tt></p><p>The owner of the <tt class="filename">/usr/local/samba/private/</tt> 
1902         directory should be set to root, and the permissions on it should 
1903         be set to 0500 (<b class="command">chmod 500 /usr/local/samba/private</b>).
1904         </p><p>Likewise, the smbpasswd file inside the private directory should 
1905         be owned by root and the permissions on is should be set to 0600
1906         (<b class="command">chmod 600 smbpasswd</b>).</p><p>The format of the smbpasswd file is (The line has been 
1907         wrapped here. It should appear as one entry per line in 
1908         your smbpasswd file.)</p><pre class="programlisting">
1909 username:uid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
1910         [Account type]:LCT-&lt;last-change-time&gt;:Long name
1911         </pre><p>Although only the <i class="replaceable"><tt>username</tt></i>, 
1912         <i class="replaceable"><tt>uid</tt></i>, <i class="replaceable"><tt>
1913         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</tt></i>,
1914         [<i class="replaceable"><tt>Account type</tt></i>] and <i class="replaceable"><tt>
1915         last-change-time</tt></i> sections are significant 
1916         and are looked at in the Samba code.</p><p>It is <span class="emphasis"><em>VITALLY</em></span> important that there by 32 
1917         'X' characters between the two ':' characters in the XXX sections - 
1918         the smbpasswd and Samba code will fail to validate any entries that 
1919         do not have 32 characters  between ':' characters. The first XXX 
1920         section is for the Lanman password hash, the second is for the 
1921         Windows NT version.</p><p>When the password file is created all users have password entries
1922         consisting of 32 'X' characters. By default this disallows any access
1923         as this user. When a user has a password set, the 'X' characters change
1924         to 32 ascii hexadecimal digits (0-9, A-F). These are an ascii
1925         representation of the 16 byte hashed value of a user's password.</p><p>To set a user to have no password (not recommended), edit the file
1926         using vi, and replace the first 11 characters with the ascii text
1927         <tt class="constant">&quot;NO PASSWORD&quot;</tt> (minus the quotes).</p><p>For example, to clear the password for user bob, his smbpasswd file 
1928         entry would look like :</p><pre class="programlisting">
1929 bob:100:NO PASSWORDXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
1930         [U          ]:LCT-00000000:Bob's full name:/bobhome:/bobshell
1931         </pre><p>If you are allowing users to use the smbpasswd command to set 
1932         their own passwords, you may want to give users NO PASSWORD initially 
1933         so they do not have to enter a previous password when changing to their 
1934         new password (not recommended). In order for you to allow this the
1935         <b class="command">smbpasswd</b> program must be able to connect to the 
1936         <b class="command">smbd</b> daemon as that user with no password. Enable this 
1937         by adding the line :</p><p><b class="command">null passwords = yes</b></p><p>to the [global] section of the smb.conf file (this is why 
1938         the above scenario is not recommended). Preferably, allocate your
1939         users a default password to begin with, so you do not have
1940         to enable this on your server.</p><p><span class="emphasis"><em>Note : </em></span>This file should be protected very 
1941         carefully. Anyone with access to this file can (with enough knowledge of 
1942         the protocols) gain access to your SMB server. The file is thus more 
1943         sensitive than a normal unix <tt class="filename">/etc/passwd</tt> file.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="modules"></a>Chapter 15. Modules</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Jelmer</span> <span class="surname">Vernooij</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:jelmer@samba.org">jelmer@samba.org</a>&gt;</tt></p></div></div></div></div><div><p class="pubdate"> 19 March 2003 </p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2878688">Advantages</a></dt><dt><a href="#id2878737">Loading modules</a></dt><dd><dl><dt><a href="#id2878771">Static modules</a></dt><dt><a href="#id2878811">Shared modules</a></dt></dl></dd><dt><a href="#id2878839">Writing modules</a></dt><dd><dl><dt><a href="#id2878904">Static/Shared selection in configure.in</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878688"></a>Advantages</h2></div></div><div></div></div><p>
1944 The new modules system has the following advantages:
1945 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>Transparent loading of static and shared modules (no need 
1946 for a subsystem to know about modules)</td></tr><tr><td>Simple selection between shared and static modules at configure time</td></tr><tr><td>&quot;preload modules&quot; option for increasing performance for stable modules</td></tr><tr><td>No nasty #define stuff anymore</td></tr><tr><td>All backends are available as plugin now (including pdb_ldap and pdb_tdb)</td></tr></table></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878737"></a>Loading modules</h2></div></div><div></div></div><p>
1947 Some subsystems in samba use different backends. These backends can be 
1948 either statically linked in to samba or available as a plugin. A subsystem 
1949 should have a function that allows a module to register itself. For example, 
1950 the passdb subsystem has: 
1951 </p><pre class="programlisting">
1952 NTSTATUS smb_register_passdb(int version, const char *name, pdb_init_function init);
1953 </pre><p>
1954 This function will be called by the initialisation function of the module to 
1955 register itself. 
1956 </p><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2878771"></a>Static modules</h3></div></div><div></div></div><p>
1957 The modules system compiles a list of initialisation functions for the 
1958 static modules of each subsystem. This is a define. For example, 
1959 it is here currently (from <tt class="filename">include/config.h</tt>): 
1960 </p><pre class="programlisting">
1961 /* Static init functions */
1962 #define static_init_pdb { pdb_mysql_init(); pdb_ldap_init(); pdb_smbpasswd_init(); pdb_tdbsam_init(); pdb_guest_init();}
1963 </pre><p>
1964 These functions should be called before the subsystem is used. That 
1965 should be done when the subsystem is initialised or first used. 
1966 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2878811"></a>Shared modules</h3></div></div><div></div></div><p>
1967 If a subsystem needs a certain backend, it should check if it has 
1968 already been registered. If the backend hasn't been registered already, 
1969 the subsystem should call smb_probe_module(char *subsystem, char *backend).
1970 This function tries to load the correct module from a certain path
1971 ($LIBDIR/subsystem/backend.so). If the first character in 'backend' 
1972 is a slash, smb_probe_module() tries to load the module from the 
1973 absolute path specified in 'backend'.
1974 </p><p>After smb_probe_module() has been executed, the subsystem 
1975 should check again if the module has been registered. 
1976 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2878839"></a>Writing modules</h2></div></div><div></div></div><p>
1977 Each module has an initialisation function. For modules that are 
1978 included with samba this name is '<i class="replaceable"><tt>subsystem</tt></i>_<i class="replaceable"><tt>backend</tt></i>_init'. For external modules (that will never be built-in, but only available as a module) this name is always 'init_module'. (In the case of modules included with samba, the configure system will add a #define subsystem_backend_init() init_module()).
1979 The prototype for these functions is:
1980 </p><pre class="programlisting">
1981 NTSTATUS init_module(void);
1982 </pre><p>This function should call one or more 
1983 registration functions. The function should return NT_STATUS_OK on success and  
1984 NT_STATUS_UNSUCCESSFUL or a more useful nt error code on failure.</p><p>For example, pdb_ldap_init() contains: </p><pre class="programlisting">
1985 NTSTATUS pdb_ldap_init(void)
1986 {
1987 smb_register_passdb(PASSDB_INTERFACE_VERSION, &quot;ldapsam&quot;, pdb_init_ldapsam);
1988 smb_register_passdb(PASSDB_INTERFACE_VERSION, &quot;ldapsam_nua&quot;, pdb_init_ldapsam_nua);
1989         return NT_STATUS_OK;
1990 }
1991 </pre><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2878904"></a>Static/Shared selection in configure.in</h3></div></div><div></div></div><p>
1992 Some macros in configure.in generate the various defines and substs that 
1993 are necessary for the system to work correct. All modules that should 
1994 be built by default have to be added to the variable 'default_modules'. 
1995 For example, if ldap is found, pdb_ldap is added to this variable.
1996 </p><p>
1997 On the bottom of configure.in, SMB_MODULE() should be called 
1998 for each module and SMB_SUBSYSTEM() for each subsystem.
1999 </p><p>Syntax:</p><pre class="programlisting">
2000 SMB_MODULE(<i class="replaceable"><tt>subsystem</tt></i>_<i class="replaceable"><tt>backend</tt></i>, <i class="replaceable"><tt>object files</tt></i>, <i class="replaceable"><tt>plugin name</tt></i>, <i class="replaceable"><tt>subsystem name</tt></i>, <i class="replaceable"><tt>static_action</tt></i>, <i class="replaceable"><tt>shared_action</tt></i>)
2001 SMB_SUBSYSTEM(<i class="replaceable"><tt>subsystem</tt></i>,<i class="replaceable"><tt>depfile</tt></i>)
2002 </pre><p>The depfile for a certain subsystem is the file that calls the 
2003 initialisation functions for the statically built in modules.</p><p>
2004 <i class="replaceable"><tt>@SUBSYSTEM_MODULES@</tt></i> in Makefile.in will 
2005 be replaced with the names of the plugins to build.
2006 </p><p>You must make sure all .c files that contain defines that can 
2007 be changed by ./configure are rebuilded in the 'modules_clean' make target. 
2008 Practically, this means all c files that contain <b class="command">static_init_subsystem;</b> calls need to be rebuilded.
2009 </p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>
2010 There currently also is a configure.in command called SMB_MODULE_PROVIVES().
2011 This is used for modules that register multiple things. It should not 
2012 be used as probing will most likely disappear in the future.</p></div></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="rpc-plugin"></a>Chapter 16. RPC Pluggable Modules</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Anthony</span> <span class="surname">Liguori</span></h3><div class="affiliation"><span class="orgname">IBM<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:aliguor@us.ibm.com">aliguor@us.ibm.com</a>&gt;</tt></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Jelmer</span> <span class="surname">Vernooij</span></h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:jelmer@samba.org">jelmer@samba.org</a>&gt;</tt></p></div></div></div></div><div><p class="pubdate">January 2003</p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2879098">About</a></dt><dt><a href="#id2879116">General Overview</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2879098"></a>About</h2></div></div><div></div></div><p>
2013 This document describes how to make use the new RPC Pluggable Modules features
2014 of Samba 3.0.  This architecture was added to increase the maintainability of
2015 Samba allowing RPC Pipes to be worked on separately from the main CVS branch.
2016 The RPM architecture will also allow third-party vendors to add functionality
2017 to Samba through plug-ins.
2018 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2879116"></a>General Overview</h2></div></div><div></div></div><p>
2019 When an RPC call is sent to smbd, smbd tries to load a shared library by the
2020 name <tt class="filename">librpc_&lt;pipename&gt;.so</tt> to handle the call if
2021 it doesn't know how to handle the call internally.  For instance, LSA calls
2022 are handled by <tt class="filename">librpc_lsass.so</tt>..
2023 These shared libraries should be located in the <tt class="filename">&lt;sambaroot&gt;/lib/rpc</tt>.  smbd then attempts to call the init_module function within
2024 the shared library. Check the chapter on modules for more information.
2025 </p><p>
2026 In the init_module function, the library should call 
2027 rpc_pipe_register_commands().  This function takes the following arguments:
2028 </p><pre class="programlisting">
2029 NTSTATUS rpc_pipe_register_commands(int version, const char *clnt, const char *srv,
2030                                const struct api_struct *cmds, int size);
2031 </pre><div class="variablelist"><dl><dt><span class="term">version</span></dt><dd><p>Version number of the RPC interface. Use the define <span class="emphasis"><em>SMB_RPC_INTERFACE_VERSION</em></span> for this 
2032 argument.</p></dd><dt><span class="term">clnt</span></dt><dd><p>the Client name of the named pipe</p></dd><dt><span class="term">srv</span></dt><dd><p>the Server name of the named pipe</p></dd><dt><span class="term">cmds</span></dt><dd><p>a list of api_structs that map RPC ordinal numbers to function calls</p></dd><dt><span class="term">size</span></dt><dd><p>the number of api_structs contained in cmds</p></dd></dl></div><p>
2033 See rpc_server/srv_reg.c and rpc_server/srv_reg_nt.c for a small example of
2034 how to use this library.
2035 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="vfs"></a>Chapter 17. VFS Modules</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Alexander</span> <span class="surname">Bokovoy</span></h3><div class="affiliation"><div class="address"><p><tt class="email">&lt;<a href="mailto:ab@samba.org">ab@samba.org</a>&gt;</tt></p></div></div></div></div><div><div class="author"><h3 class="author"><span class="firstname">Stefan</span> <span class="surname">Metzmacher</span></h3><div class="affiliation"><div class="address"><p><tt class="email">&lt;<a href="mailto:metze@metzemix.de">metze@metzemix.de</a>&gt;</tt></p></div></div></div></div><div><p class="pubdate"> 27 May 2003 </p></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2879326">The Samba (Posix) VFS layer</a></dt><dd><dl><dt><a href="#id2879332">The general interface</a></dt><dt><a href="#id2879448">Possible VFS operation layers</a></dt></dl></dd><dt><a href="#id2879520">The Interaction between the Samba VFS subsystem and the modules</a></dt><dd><dl><dt><a href="#id2879528">Initialization and registration</a></dt><dt><a href="#id2879720">How the Modules handle per connection data</a></dt></dl></dd><dt><a href="#id2879963">Upgrading to the New VFS Interface</a></dt><dd><dl><dt><a href="#id2879970">Upgrading from 2.2.* and 3.0aplha modules</a></dt></dl></dd><dt><a href="#id2880501">Some Notes</a></dt><dd><dl><dt><a href="#id2880508">Implement TRANSPARENT functions</a></dt><dt><a href="#id2880533">Implement OPAQUE functions</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2879326"></a>The Samba (Posix) VFS layer</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2879332"></a>The general interface</h3></div></div><div></div></div><p>
2036 Each VFS operation has a vfs_op_type, a function pointer and a handle pointer in the
2037 struct vfs_ops and tree macros to make it easier to call the operations.
2038 (Take a look at <tt class="filename">include/vfs.h</tt> and <tt class="filename">include/vfs_macros.h</tt>.)
2039 </p><pre class="programlisting">
2040 typedef enum _vfs_op_type {
2041         SMB_VFS_OP_NOOP = -1,
2042
2043         ...
2044
2045         /* File operations */
2046
2047         SMB_VFS_OP_OPEN,
2048         SMB_VFS_OP_CLOSE,
2049         SMB_VFS_OP_READ,
2050         SMB_VFS_OP_WRITE,
2051         SMB_VFS_OP_LSEEK,
2052         SMB_VFS_OP_SENDFILE,
2053
2054         ...
2055
2056         SMB_VFS_OP_LAST
2057 } vfs_op_type;
2058 </pre><p>This struct contains the function and handle pointers for all operations.</p><pre class="programlisting">
2059 struct vfs_ops {
2060         struct vfs_fn_pointers {
2061                 ...
2062                 
2063                 /* File operations */
2064                 
2065                 int (*open)(struct vfs_handle_struct *handle,
2066                         struct connection_struct *conn,
2067                         const char *fname, int flags, mode_t mode);
2068                 int (*close)(struct vfs_handle_struct *handle,
2069                         struct files_struct *fsp, int fd);
2070                 ssize_t (*read)(struct vfs_handle_struct *handle, 
2071                         struct files_struct *fsp, int fd, void *data, size_t n);
2072                 ssize_t (*write)(struct vfs_handle_struct *handle, 
2073                         struct files_struct *fsp, int fd, 
2074                         const void *data, size_t n);
2075                 SMB_OFF_T (*lseek)(struct vfs_handle_struct *handle, 
2076                         struct files_struct *fsp, int fd, 
2077                         SMB_OFF_T offset, int whence);
2078                 ssize_t (*sendfile)(struct vfs_handle_struct *handle, 
2079                         int tofd, files_struct *fsp, int fromfd, 
2080                         const DATA_BLOB *header, SMB_OFF_T offset, size_t count);
2081
2082                 ...
2083         } ops;
2084         
2085         struct vfs_handles_pointers {
2086                 ...
2087                 
2088                 /* File operations */
2089                 
2090                 struct vfs_handle_struct *open;
2091                 struct vfs_handle_struct *close;
2092                 struct vfs_handle_struct *read;
2093                 struct vfs_handle_struct *write;
2094                 struct vfs_handle_struct *lseek;
2095                 struct vfs_handle_struct *sendfile;
2096                 
2097                 ...
2098         } handles;
2099 };
2100 </pre><p>
2101 This macros SHOULD be used to call any vfs operation.
2102 DO NOT ACCESS conn-&gt;vfs.ops.* directly !!!
2103 </p><pre class="programlisting">
2104 ...
2105         
2106 /* File operations */
2107 #define SMB_VFS_OPEN(conn, fname, flags, mode) \
2108         ((conn)-&gt;vfs.ops.open((conn)-&gt;vfs.handles.open,\
2109          (conn), (fname), (flags), (mode)))
2110 #define SMB_VFS_CLOSE(fsp, fd) \
2111         ((fsp)-&gt;conn-&gt;vfs.ops.close(\
2112         (fsp)-&gt;conn-&gt;vfs.handles.close, (fsp), (fd)))
2113 #define SMB_VFS_READ(fsp, fd, data, n) \
2114         ((fsp)-&gt;conn-&gt;vfs.ops.read(\
2115         (fsp)-&gt;conn-&gt;vfs.handles.read,\
2116          (fsp), (fd), (data), (n)))
2117 #define SMB_VFS_WRITE(fsp, fd, data, n) \
2118         ((fsp)-&gt;conn-&gt;vfs.ops.write(\
2119         (fsp)-&gt;conn-&gt;vfs.handles.write,\
2120          (fsp), (fd), (data), (n)))
2121 #define SMB_VFS_LSEEK(fsp, fd, offset, whence) \
2122         ((fsp)-&gt;conn-&gt;vfs.ops.lseek(\
2123         (fsp)-&gt;conn-&gt;vfs.handles.lseek,\
2124          (fsp), (fd), (offset), (whence)))
2125 #define SMB_VFS_SENDFILE(tofd, fsp, fromfd, header, offset, count) \
2126         ((fsp)-&gt;conn-&gt;vfs.ops.sendfile(\
2127         (fsp)-&gt;conn-&gt;vfs.handles.sendfile,\
2128          (tofd), (fsp), (fromfd), (header), (offset), (count)))
2129
2130 ...
2131 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2879448"></a>Possible VFS operation layers</h3></div></div><div></div></div><p>
2132 These values are used by the VFS subsystem when building the conn-&gt;vfs 
2133 and conn-&gt;vfs_opaque structs for a connection with multiple VFS modules. 
2134 Internally, Samba differentiates only opaque and transparent layers at this process.
2135 Other types are used for providing better diagnosing facilities.
2136 </p><p>
2137 Most modules will provide transparent layers. Opaque layer is for modules
2138 which implement actual file system calls (like DB-based VFS). For example,
2139 default POSIX VFS which is built in into Samba is an opaque VFS module.
2140 </p><p>    
2141 Other layer types (logger, splitter, scanner) were designed to provide different 
2142 degree of transparency and for diagnosing VFS module behaviour.
2143 </p><p>
2144 Each module can implement several layers at the same time provided that only
2145 one layer is used per each operation.
2146 </p><pre class="programlisting">
2147 typedef enum _vfs_op_layer {
2148         SMB_VFS_LAYER_NOOP = -1,        /* - For using in VFS module to indicate end of array */
2149                                         /*   of operations description */
2150         SMB_VFS_LAYER_OPAQUE = 0,       /* - Final level, does not call anything beyond itself */
2151         SMB_VFS_LAYER_TRANSPARENT,      /* - Normal operation, calls underlying layer after */
2152                                         /*   possibly changing passed data */
2153         SMB_VFS_LAYER_LOGGER,           /* - Logs data, calls underlying layer, logging may not */
2154                                         /*   use Samba VFS */
2155         SMB_VFS_LAYER_SPLITTER,         /* - Splits operation, calls underlying layer _and_ own facility, */
2156                                         /*   then combines result */
2157         SMB_VFS_LAYER_SCANNER           /* - Checks data and possibly initiates additional */
2158                                         /*   file activity like logging to files _inside_ samba VFS */
2159 } vfs_op_layer;
2160 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2879520"></a>The Interaction between the Samba VFS subsystem and the modules</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2879528"></a>Initialization and registration</h3></div></div><div></div></div><p>
2161 As each Samba module a VFS module should have a 
2162 </p><pre class="programlisting">NTSTATUS vfs_example_init(void);</pre><p> function if it's staticly linked to samba or
2163 </p><pre class="programlisting">NTSTATUS init_module(void);</pre><p> function if it's a shared module.
2164 </p><p>
2165 This should be the only non static function inside the module.
2166 Global variables should also be static!
2167 </p><p>
2168 The module should register its functions via the
2169 </p><pre class="programlisting">
2170 NTSTATUS smb_register_vfs(int version, const char *name, vfs_op_tuple *vfs_op_tuples);
2171 </pre><p> function.
2172 </p><div class="variablelist"><dl><dt><span class="term">version</span></dt><dd><p>should be filled with SMB_VFS_INTERFACE_VERSION</p></dd><dt><span class="term">name</span></dt><dd><p>this is the name witch can be listed in the 
2173 <b class="command">vfs objects</b> parameter to use this module.</p></dd><dt><span class="term">vfs_op_tuples</span></dt><dd><p>
2174 this is an array of vfs_op_tuple's.
2175 (vfs_op_tuples is descripted in details below.)
2176 </p></dd></dl></div><p>
2177 For each operation the module wants to provide it has a entry in the 
2178 vfs_op_tuple array.
2179 </p><pre class="programlisting">
2180 typedef struct _vfs_op_tuple {
2181         void* op;
2182         vfs_op_type type;
2183         vfs_op_layer layer;
2184 } vfs_op_tuple;
2185 </pre><div class="variablelist"><dl><dt><span class="term">op</span></dt><dd><p>the function pointer to the specified function.</p></dd><dt><span class="term">type</span></dt><dd><p>the vfs_op_type of the function to specified witch operation the function provides.</p></dd><dt><span class="term">layer</span></dt><dd><p>the vfs_op_layer in whitch the function operates.</p></dd></dl></div><p>A simple example:</p><pre class="programlisting">
2186 static vfs_op_tuple example_op_tuples[] = {     
2187         {SMB_VFS_OP(example_connect),   SMB_VFS_OP_CONNECT,     SMB_VFS_LAYER_TRANSPARENT},
2188         {SMB_VFS_OP(example_disconnect),        SMB_VFS_OP_DISCONNECT,  SMB_VFS_LAYER_TRANSPARENT},
2189
2190         {SMB_VFS_OP(example_rename),    SMB_VFS_OP_RENAME,      SMB_VFS_LAYER_OPAQUE},
2191
2192         /* This indicates the end of the array */
2193         {SMB_VFS_OP(NULL),                              SMB_VFS_OP_NOOP,        SMB_VFS_LAYER_NOOP}
2194 };
2195
2196 NTSTATUS init_module(void)
2197 {
2198         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION, &quot;example&quot;, example_op_tuples);
2199 }
2200 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2879720"></a>How the Modules handle per connection data</h3></div></div><div></div></div><p>Each VFS function has as first parameter a pointer to the modules vfs_handle_struct.
2201 </p><pre class="programlisting">
2202 typedef struct vfs_handle_struct {
2203         struct vfs_handle_struct  *next, *prev;
2204         const char *param;
2205         struct vfs_ops vfs_next;
2206         struct connection_struct *conn;
2207         void *data;
2208         void (*free_data)(void **data);
2209 } vfs_handle_struct;
2210 </pre><div class="variablelist"><dl><dt><span class="term">param</span></dt><dd><p>this is the module parameter specified in the <b class="command">vfs objects</b> parameter.</p><p>e.g. for 'vfs objects = example:test' param would be &quot;test&quot;.</p></dd><dt><span class="term">vfs_next</span></dt><dd><p>This vfs_ops struct contains the information for calling the next module operations.
2211 Use the SMB_VFS_NEXT_* macros to call a next module operations and
2212 don't access handle-&gt;vfs_next.ops.* directly!</p></dd><dt><span class="term">conn</span></dt><dd><p>This is a pointer back to the connection_struct to witch the handle belongs.</p></dd><dt><span class="term">data</span></dt><dd><p>This is a pointer for holding module private data.
2213 You can alloc data with connection life time on the handle-&gt;conn-&gt;mem_ctx TALLOC_CTX.
2214 But you can also manage the memory allocation yourself.</p></dd><dt><span class="term">free_data</span></dt><dd><p>This is a function pointer to a function that free's the module private data.
2215 If you talloc your private data on the TALLOC_CTX handle-&gt;conn-&gt;mem_ctx,
2216 you can set this function pointer to NULL.</p></dd></dl></div><p>Some useful MACROS for handle private data.
2217 </p><pre class="programlisting">
2218 #define SMB_VFS_HANDLE_GET_DATA(handle, datap, type, ret) { \
2219         if (!(handle)||((datap=(type *)(handle)-&gt;data)==NULL)) { \
2220                 DEBUG(0,(&quot;%s() failed to get vfs_handle-&gt;data!\n&quot;,FUNCTION_MACRO)); \
2221                 ret; \
2222         } \
2223 }
2224
2225 #define SMB_VFS_HANDLE_SET_DATA(handle, datap, free_fn, type, ret) { \
2226         if (!(handle)) { \
2227                 DEBUG(0,(&quot;%s() failed to set handle-&gt;data!\n&quot;,FUNCTION_MACRO)); \
2228                 ret; \
2229         } else { \
2230                 if ((handle)-&gt;free_data) { \
2231                         (handle)-&gt;free_data(&amp;(handle)-&gt;data); \
2232                 } \
2233                 (handle)-&gt;data = (void *)datap; \
2234                 (handle)-&gt;free_data = free_fn; \
2235         } \
2236 }
2237
2238 #define SMB_VFS_HANDLE_FREE_DATA(handle) { \
2239         if ((handle) &amp;&amp; (handle)-&gt;free_data) { \
2240                 (handle)-&gt;free_data(&amp;(handle)-&gt;data); \
2241         } \
2242 }
2243 </pre><p>How SMB_VFS_LAYER_TRANSPARENT functions can call the SMB_VFS_LAYER_OPAQUE functions.</p><p>The easiest way to do this is to use the SMB_VFS_OPAQUE_* macros.
2244 </p><pre class="programlisting">
2245 ...
2246 /* File operations */
2247 #define SMB_VFS_OPAQUE_OPEN(conn, fname, flags, mode) \
2248         ((conn)-&gt;vfs_opaque.ops.open(\
2249         (conn)-&gt;vfs_opaque.handles.open,\
2250          (conn), (fname), (flags), (mode)))
2251 #define SMB_VFS_OPAQUE_CLOSE(fsp, fd) \
2252         ((fsp)-&gt;conn-&gt;vfs_opaque.ops.close(\
2253         (fsp)-&gt;conn-&gt;vfs_opaque.handles.close,\
2254          (fsp), (fd)))
2255 #define SMB_VFS_OPAQUE_READ(fsp, fd, data, n) \
2256         ((fsp)-&gt;conn-&gt;vfs_opaque.ops.read(\
2257         (fsp)-&gt;conn-&gt;vfs_opaque.handles.read,\
2258          (fsp), (fd), (data), (n)))
2259 #define SMB_VFS_OPAQUE_WRITE(fsp, fd, data, n) \
2260         ((fsp)-&gt;conn-&gt;vfs_opaque.ops.write(\
2261         (fsp)-&gt;conn-&gt;vfs_opaque.handles.write,\
2262          (fsp), (fd), (data), (n)))
2263 #define SMB_VFS_OPAQUE_LSEEK(fsp, fd, offset, whence) \
2264         ((fsp)-&gt;conn-&gt;vfs_opaque.ops.lseek(\
2265         (fsp)-&gt;conn-&gt;vfs_opaque.handles.lseek,\
2266          (fsp), (fd), (offset), (whence)))
2267 #define SMB_VFS_OPAQUE_SENDFILE(tofd, fsp, fromfd, header, offset, count) \
2268         ((fsp)-&gt;conn-&gt;vfs_opaque.ops.sendfile(\
2269         (fsp)-&gt;conn-&gt;vfs_opaque.handles.sendfile,\
2270          (tofd), (fsp), (fromfd), (header), (offset), (count)))
2271 ...
2272 </pre><p>How SMB_VFS_LAYER_TRANSPARENT functions can call the next modules functions.</p><p>The easiest way to do this is to use the SMB_VFS_NEXT_* macros.
2273 </p><pre class="programlisting">
2274 ...
2275 /* File operations */
2276 #define SMB_VFS_NEXT_OPEN(handle, conn, fname, flags, mode) \
2277         ((handle)-&gt;vfs_next.ops.open(\
2278         (handle)-&gt;vfs_next.handles.open,\
2279          (conn), (fname), (flags), (mode)))
2280 #define SMB_VFS_NEXT_CLOSE(handle, fsp, fd) \
2281         ((handle)-&gt;vfs_next.ops.close(\
2282         (handle)-&gt;vfs_next.handles.close,\
2283          (fsp), (fd)))
2284 #define SMB_VFS_NEXT_READ(handle, fsp, fd, data, n) \
2285         ((handle)-&gt;vfs_next.ops.read(\
2286         (handle)-&gt;vfs_next.handles.read,\
2287          (fsp), (fd), (data), (n)))
2288 #define SMB_VFS_NEXT_WRITE(handle, fsp, fd, data, n) \
2289         ((handle)-&gt;vfs_next.ops.write(\
2290         (handle)-&gt;vfs_next.handles.write,\
2291          (fsp), (fd), (data), (n)))
2292 #define SMB_VFS_NEXT_LSEEK(handle, fsp, fd, offset, whence) \
2293         ((handle)-&gt;vfs_next.ops.lseek(\
2294         (handle)-&gt;vfs_next.handles.lseek,\
2295          (fsp), (fd), (offset), (whence)))
2296 #define SMB_VFS_NEXT_SENDFILE(handle, tofd, fsp, fromfd, header, offset, count) \
2297         ((handle)-&gt;vfs_next.ops.sendfile(\
2298         (handle)-&gt;vfs_next.handles.sendfile,\
2299          (tofd), (fsp), (fromfd), (header), (offset), (count)))
2300 ...
2301 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2879963"></a>Upgrading to the New VFS Interface</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2879970"></a>Upgrading from 2.2.* and 3.0aplha modules</h3></div></div><div></div></div><div class="orderedlist"><ol type="1"><li><p>
2302 Add &quot;vfs_handle_struct *handle, &quot; as first parameter to all vfs operation functions.
2303 e.g. example_connect(connection_struct *conn, const char *service, const char *user);
2304 -&gt;   example_connect(vfs_handle_struct *handle, connection_struct *conn, const char *service, const char *user);
2305 </p></li><li><p>
2306 Replace &quot;default_vfs_ops.&quot; with &quot;smb_vfs_next_&quot;.
2307 e.g. default_vfs_ops.connect(conn, service, user);
2308 -&gt;   smb_vfs_next_connect(conn, service, user);
2309 </p></li><li><p>
2310 Uppercase all &quot;smb_vfs_next_*&quot; functions.
2311 e.g. smb_vfs_next_connect(conn, service, user);
2312 -&gt;   SMB_VFS_NEXT_CONNECT(conn, service, user);
2313 </p></li><li><p>
2314 Add &quot;handle, &quot; as first parameter to all SMB_VFS_NEXT_*() calls.
2315 e.g. SMB_VFS_NEXT_CONNECT(conn, service, user);
2316 -&gt;   SMB_VFS_NEXT_CONNECT(handle, conn, service, user);
2317 </p></li><li><p>
2318 (Only for 2.2.* modules) 
2319 Convert the old struct vfs_ops example_ops to 
2320 a vfs_op_tuple example_op_tuples[] array.
2321 e.g.
2322 </p><pre class="programlisting">
2323 struct vfs_ops example_ops = {
2324         /* Disk operations */
2325         example_connect,                /* connect */
2326         example_disconnect,             /* disconnect */
2327         NULL,                           /* disk free *
2328         /* Directory operations */
2329         NULL,                           /* opendir */
2330         NULL,                           /* readdir */
2331         NULL,                           /* mkdir */
2332         NULL,                           /* rmdir */
2333         NULL,                           /* closedir */
2334         /* File operations */
2335         NULL,                           /* open */
2336         NULL,                           /* close */
2337         NULL,                           /* read  */
2338         NULL,                           /* write */
2339         NULL,                           /* lseek */
2340         NULL,                           /* sendfile */
2341         NULL,                           /* rename */
2342         NULL,                           /* fsync */
2343         example_stat,                   /* stat  */
2344         example_fstat,                  /* fstat */
2345         example_lstat,                  /* lstat */
2346         NULL,                           /* unlink */
2347         NULL,                           /* chmod */
2348         NULL,                           /* fchmod */
2349         NULL,                           /* chown */
2350         NULL,                           /* fchown */
2351         NULL,                           /* chdir */
2352         NULL,                           /* getwd */
2353         NULL,                           /* utime */
2354         NULL,                           /* ftruncate */
2355         NULL,                           /* lock */
2356         NULL,                           /* symlink */
2357         NULL,                           /* readlink */
2358         NULL,                           /* link */
2359         NULL,                           /* mknod */
2360         NULL,                           /* realpath */
2361         NULL,                           /* fget_nt_acl */
2362         NULL,                           /* get_nt_acl */
2363         NULL,                           /* fset_nt_acl */
2364         NULL,                           /* set_nt_acl */
2365
2366         NULL,                           /* chmod_acl */
2367         NULL,                           /* fchmod_acl */
2368
2369         NULL,                           /* sys_acl_get_entry */
2370         NULL,                           /* sys_acl_get_tag_type */
2371         NULL,                           /* sys_acl_get_permset */
2372         NULL,                           /* sys_acl_get_qualifier */
2373         NULL,                           /* sys_acl_get_file */
2374         NULL,                           /* sys_acl_get_fd */
2375         NULL,                           /* sys_acl_clear_perms */
2376         NULL,                           /* sys_acl_add_perm */
2377         NULL,                           /* sys_acl_to_text */
2378         NULL,                           /* sys_acl_init */
2379         NULL,                           /* sys_acl_create_entry */
2380         NULL,                           /* sys_acl_set_tag_type */
2381         NULL,                           /* sys_acl_set_qualifier */
2382         NULL,                           /* sys_acl_set_permset */
2383         NULL,                           /* sys_acl_valid */
2384         NULL,                           /* sys_acl_set_file */
2385         NULL,                           /* sys_acl_set_fd */
2386         NULL,                           /* sys_acl_delete_def_file */
2387         NULL,                           /* sys_acl_get_perm */
2388         NULL,                           /* sys_acl_free_text */
2389         NULL,                           /* sys_acl_free_acl */
2390         NULL                            /* sys_acl_free_qualifier */
2391 };
2392 </pre><p>
2393 -&gt;
2394 </p><pre class="programlisting"> 
2395 static vfs_op_tuple example_op_tuples[] = {
2396         {SMB_VFS_OP(example_connect),   SMB_VFS_OP_CONNECT,     SMB_VFS_LAYER_TRANSPARENT},
2397         {SMB_VFS_OP(example_disconnect),        SMB_VFS_OP_DISCONNECT,  SMB_VFS_LAYER_TRANSPARENT},
2398         
2399         {SMB_VFS_OP(example_fstat),     SMB_VFS_OP_FSTAT,       SMB_VFS_LAYER_TRANSPARENT},
2400         {SMB_VFS_OP(example_stat),              SMB_VFS_OP_STAT,        SMB_VFS_LAYER_TRANSPARENT},
2401         {SMB_VFS_OP(example_lstat),     SMB_VFS_OP_LSTAT,       SMB_VFS_LAYER_TRANSPARENT},
2402
2403         {SMB_VFS_OP(NULL),                              SMB_VFS_OP_NOOP,        SMB_VFS_LAYER_NOOP}
2404 };
2405 </pre><p>
2406 </p></li><li><p>
2407 Move the example_op_tuples[] array to the end of the file. 
2408 </p></li><li><p>
2409 Add the init_module() function at the end of the file.
2410 e.g.
2411 </p><pre class="programlisting">
2412 NTSTATUS init_module(void)
2413 {
2414         return smb_register_vfs(SMB_VFS_INTERFACE_VERSION,&quot;example&quot;,example_op_tuples);
2415 }
2416 </pre><p>
2417 </p></li><li><p>
2418 Check if your vfs_init() function does more then just prepare the vfs_ops structs or
2419 remember the struct smb_vfs_handle_struct.
2420 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>If NOT you can remove the vfs_init() function.</td></tr><tr><td>If YES decide if you want to move the code to the example_connect() operation or to the init_module(). And then remove vfs_init().
2421   e.g. a debug class registration should go into init_module() and the allocation of private data should go to example_connect().</td></tr></table><p>
2422 </p></li><li><p>
2423 (Only for 3.0alpha* modules) 
2424 Check if your vfs_done() function contains needed code.
2425 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>If NOT you can remove the vfs_done() function.</td></tr><tr><td>If YES decide if you can move the code to the example_disconnect() operation. Otherwise register a SMB_EXIT_EVENT with smb_register_exit_event(); (Described in the <a href="#modules" title="Chapter 15. Modules">modules section</a>) And then remove vfs_done(). e.g. the freeing of private data should go to example_disconnect().
2426 </td></tr></table><p>
2427 </p></li><li><p>
2428 Check if you have any global variables left.
2429 Decide if it wouldn't be better to have this data on a connection basis.
2430 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>If NOT leave them as they are. (e.g. this could be the variable for the private debug class.)</td></tr><tr><td>If YES pack all this data into a struct. You can use handle-&gt;data to point to such a struct on a per connection basis.</td></tr></table><p>
2431
2432   e.g. if you have such a struct:
2433 </p><pre class="programlisting">    
2434 struct example_privates {
2435         char *some_string;
2436         int db_connection;
2437 };
2438 </pre><p>       
2439 first way of doing it:
2440 </p><pre class="programlisting">
2441 static int example_connect(vfs_handle_struct *handle,
2442         connection_struct *conn, const char *service, 
2443         const char* user)
2444 {
2445         struct example_privates *data = NULL;
2446
2447         /* alloc our private data */
2448         data = (struct example_privates *)talloc_zero(conn-&gt;mem_ctx, sizeof(struct example_privates));
2449         if (!data) {
2450                 DEBUG(0,(&quot;talloc_zero() failed\n&quot;));
2451                 return -1;
2452         }
2453
2454         /* init out private data */
2455         data-&gt;some_string = talloc_strdup(conn-&gt;mem_ctx,&quot;test&quot;);
2456         if (!data-&gt;some_string) {
2457                 DEBUG(0,(&quot;talloc_strdup() failed\n&quot;));
2458                 return -1;
2459         }
2460
2461         data-&gt;db_connection = open_db_conn();
2462
2463         /* and now store the private data pointer in handle-&gt;data
2464          * we don't need to specify a free_function here because
2465          * we use the connection TALLOC context.
2466          * (return -1 if something failed.)
2467          */
2468         VFS_HANDLE_SET_DATA(handle, data, NULL, struct example_privates, return -1);
2469
2470         return SMB_VFS_NEXT_CONNECT(handle,conn,service,user);
2471 }
2472
2473 static int example_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
2474 {
2475         struct example_privates *data = NULL;
2476         
2477         /* get the pointer to our private data
2478          * return -1 if something failed
2479          */
2480         SMB_VFS_HANDLE_GET_DATA(handle, data, struct example_privates, return -1);
2481         
2482         /* do something here...*/
2483         DEBUG(0,(&quot;some_string: %s\n&quot;,data-&gt;some_string));
2484         
2485         return SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
2486 }
2487 </pre><p>
2488 second way of doing it:
2489 </p><pre class="programlisting">
2490 static void free_example_privates(void **datap)
2491 {
2492         struct example_privates *data = (struct example_privates *)*datap;
2493         
2494         SAFE_FREE(data-&gt;some_string);
2495         SAFE_FREE(data);
2496         
2497         *datap = NULL;
2498         
2499         return;
2500 }
2501
2502 static int example_connect(vfs_handle_struct *handle, 
2503         connection_struct *conn, const char *service, 
2504         const char* user)
2505 {
2506         struct example_privates *data = NULL;
2507
2508         /* alloc our private data */
2509         data = (struct example_privates *)malloc(sizeof(struct example_privates));
2510         if (!data) {
2511                 DEBUG(0,(&quot;malloc() failed\n&quot;));
2512                 return -1;
2513         }
2514
2515         /* init out private data */
2516         data-&gt;some_string = strdup(&quot;test&quot;);
2517         if (!data-&gt;some_string) {
2518                 DEBUG(0,(&quot;strdup() failed\n&quot;));
2519                 return -1;
2520         }
2521
2522         data-&gt;db_connection = open_db_conn();
2523
2524         /* and now store the private data pointer in handle-&gt;data
2525          * we need to specify a free_function because we used malloc() and strdup().
2526          * (return -1 if something failed.)
2527          */
2528         SMB_VFS_HANDLE_SET_DATA(handle, data, free_example_privates, struct example_privates, return -1);
2529
2530         return SMB_VFS_NEXT_CONNECT(handle,conn,service,user);
2531 }
2532
2533 static int example_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
2534 {
2535         struct example_privates *data = NULL;
2536         
2537         /* get the pointer to our private data
2538          * return -1 if something failed
2539          */
2540         SMB_VFS_HANDLE_GET_DATA(handle, data, struct example_privates, return -1);
2541         
2542         /* do something here...*/
2543         DEBUG(0,(&quot;some_string: %s\n&quot;,data-&gt;some_string));
2544         
2545         return SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
2546 }
2547 </pre><p>
2548 </p></li><li><p>
2549 To make it easy to build 3rd party modules it would be usefull to provide
2550 configure.in, (configure), install.sh and Makefile.in with the module.
2551 (Take a look at the example in <tt class="filename">examples/VFS</tt>.)
2552 </p><p>
2553 The configure script accepts <tt class="option">--with-samba-source</tt> to specify 
2554 the path to the samba source tree.
2555 It also accept <tt class="option">--enable-developer</tt> which lets the compiler 
2556 give you more warnings.  
2557 </p><p>
2558 The idea is that you can extend this 
2559 <tt class="filename">configure.in</tt> and <tt class="filename">Makefile.in</tt> scripts
2560 for your module.
2561 </p></li><li><p>
2562 Compiling &amp; Testing...
2563 </p><table class="simplelist" border="0" summary="Simple list"><tr><td><b class="userinput"><tt>./configure <tt class="option">--enable-developer</tt></tt></b> ...</td></tr><tr><td><b class="userinput"><tt>make</tt></b></td></tr><tr><td>Try to fix all compiler warnings</td></tr><tr><td><b class="userinput"><tt>make</tt></b></td></tr><tr><td>Testing, Testing, Testing ...</td></tr></table><p>
2564 </p></li></ol></div></div></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2880501"></a>Some Notes</h2></div></div><div></div></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2880508"></a>Implement TRANSPARENT functions</h3></div></div><div></div></div><p>
2565 Avoid writing functions like this:
2566
2567 </p><pre class="programlisting">
2568 static int example_close(vfs_handle_struct *handle, files_struct *fsp, int fd)
2569 {
2570         return SMB_VFS_NEXT_CLOSE(handle, fsp, fd);
2571 }
2572 </pre><p>
2573
2574 Overload only the functions you really need to!
2575 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><div><h3 class="title"><a name="id2880533"></a>Implement OPAQUE functions</h3></div></div><div></div></div><p>
2576 If you want to just implement a better version of a 
2577 default samba opaque function
2578 (e.g. like a disk_free() function for a special filesystem) 
2579 it's ok to just overload that specific function.
2580 </p><p>
2581 If you want to implement a database filesystem or
2582 something different from a posix filesystem.
2583 Make sure that you overload every vfs operation!!!
2584 </p><p>
2585 Functions your FS does not support should be overloaded by something like this:
2586 e.g. for a readonly filesystem.
2587 </p><pre class="programlisting">
2588 static int example_rename(vfs_handle_struct *handle, connection_struct *conn,
2589                         char *oldname, char *newname)
2590 {
2591         DEBUG(10,(&quot;function rename() not allowed on vfs 'example'\n&quot;));
2592         errno = ENOSYS;
2593         return -1;
2594 }
2595 </pre></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="Packaging"></a>Chapter 18. Notes to packagers</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Jelmer</span> <span class="surname">Vernooij</span></h3></div></div></div><div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2880600">Versioning</a></dt><dt><a href="#id2880635">Modules</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2880600"></a>Versioning</h2></div></div><div></div></div><p>Please, please update the version number in 
2596 <tt class="filename">source/include/version.h</tt> to include the versioning of your package. This makes it easier to distinguish standard samba builds
2597 from custom-build samba builds (distributions often patch packages). For 
2598 example, a good version would be: </p><pre class="programlisting">
2599 Version 2.999+3.0.alpha21-5 for Debian
2600 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a name="id2880635"></a>Modules</h2></div></div><div></div></div><p>Samba now has support for building parts of samba as plugins. This 
2601 makes it possible to, for example, put ldap or mysql support in a seperate 
2602 package, thus making it possible to have a normal samba package not 
2603 depending on ldap or mysql. To build as much parts of samba 
2604 as a plugin, run: </p><pre class="programlisting">
2605 ./configure --with-shared-modules=rpc,vfs,auth,pdb,charset
2606 </pre></div></div><div class="chapter" lang="en"><div class="titlepage"><div><div><h2 class="title"><a name="contributing"></a>Chapter 19. Contributing code</h2></div><div><div class="author"><h3 class="author"><span class="firstname">Jelmer</span> <span class="othername">R.</span> <span class="surname">Vernooij</span></h3><div class="affiliation"><span class="orgname">The Samba Team<br></span><div class="address"><p><tt class="email">&lt;<a href="mailto:jelmer@samba.org">jelmer@samba.org</a>&gt;</tt></p></div></div></div></div></div><div></div></div><p>Here are a few tips and notes that might be useful if you are 
2607         interested in modifying samba source code and getting it into 
2608         samba's main branch.</p><div class="variablelist"><dl><dt><span class="term">Retrieving the source</span></dt><dd><p>In order to contribute code to samba, make sure you have the 
2609                         latest source. Retrieving the samba source code from CVS is 
2610                         documented in the appendix of the Samba HOWTO Collection.
2611                 </p></dd><dt><span class="term">Discuss large modifications with team members</span></dt><dd><p>Please discuss large modifications you are going to make 
2612                 with members of the samba team. Some parts of the samba code 
2613                 have one or more 'owners' - samba developers who wrote most 
2614                 of the code and maintain it. 
2615                 </p><p>This way you can avoid spending your time and effort on 
2616                 something that is not going to make it into the main samba branch 
2617                 because someone else was working on the same thing or because your 
2618                 implementation is not the correct one.
2619                 </p></dd><dt><span class="term">Patch format</span></dt><dd><p>Patches to the samba tree should be in unified diff format, 
2620                         e.g. files generated by <b class="userinput"><tt>diff -u</tt></b>. 
2621                 </p><p>If you are modifying a copy of samba you retrieved from CVS, 
2622                 you can easily generate a diff file of these changes by running 
2623                 <b class="userinput"><tt>cvs diff -u</tt></b>.</p></dd><dt><span class="term">Points of attention when modifying samba source code</span></dt><dd><p>
2624                 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>Don't simply copy code from other places and modify it until it
2625                 works. Code needs to be clean and logical. Duplicate 
2626                 code is to be avoided.</td></tr><tr><td>Test your patch. It might take a while before one of us looks 
2627                 at your patch so it will take longer before your patch when your patch 
2628                 needs to go thru the review cycle again.</td></tr><tr><td>Don't put seperate patches in one large diff file. This makes 
2629                 it harder to read, understand and test the patch. You might 
2630                 also risk not getting a good patch committed because you mixed it 
2631                 with one that had issues. </td></tr><tr><td>Make sure your patch complies to the samba coding style as 
2632                 suggested in the coding-suggestions chapter. </td></tr></table><p>
2633                 </p></dd><dt><span class="term">Sending in bugfixes</span></dt><dd><p>Bugfixes to bugs in samba should be submitted to samba's
2634                 <a href="https://bugzilla.samba.org/" target="_top">bugzilla system</a>, 
2635                 along with a description of the bug.
2636                 </p></dd><dt><span class="term">Sending in feature patches</span></dt><dd><p>Send feature patches along with a description of what the 
2637                 patch is supposed to do to the 
2638                 <a href="mailto:samba-technical@samba.org" target="_top">Samba-technical mailinglist</a> and possibly to a samba team member who is (one of the) 'owners'
2639                 of the code you made modifications to. We are all busy people 
2640                 so everybody tends to 'let one of the others handle it'. If nobody 
2641                 responded to your patch for a week, try to send it again until you 
2642                 get a response from one of us.
2643                 </p></dd><dt><span class="term">Feedback on your patch</span></dt><dd><p>One of the team members will look at your patch and either 
2644                 commit your patch or give comments why he won't apply it. In the 
2645                 latter case you can fix your patch and re-send it until 
2646                 your patch is approved.</p></dd></dl></div></div></div></body></html>