Rebuild docs
[Samba.git] / docs / htmldocs / Samba-Developers-Guide.html
blobcc12fe60f8a013931515b4560e31623580645297
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.59.1"></head><body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"><div class="book" lang="en"><div class="titlepage"><div><h1 class="title"><a name="Samba-Developers-Guide"></a>SAMBA Developers Guide</h1></div><div><div class="author"><h3 class="author">SAMBA Team</h3></div></div><hr></div><div class="dedication" lang="en"><div class="titlepage"><div><h2 class="title"><a name="id2791718"></a>Abstract</h2></div></div><p>
2 <span class="emphasis"><em>Last Update</em></span> : Mon Sep 30 15:23:53 CDT 2002
3 </p><p>
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 <a href="http://devel.samba.org/" target="_top">http://devel.samba.org/</a>.
10 Please send updates to <a href="mailto:jelmer@samba.org" target="_top">Jelmer Veenrooij</a>.
11 </p><p>
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 <a href="http://www.fsf.org/licenses/gpl.txt" target="_top">http://www.fsf.org/licenses/gpl.txt</a>
15 </p></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt>1. <a href="#netbios">Definition of NetBIOS Protocol and Name Resolution Modes</a></dt><dd><dl><dt><a href="#id2791176">NETBIOS</a></dt><dt><a href="#id2791260">BROADCAST NetBIOS</a></dt><dt><a href="#id2791291">NBNS NetBIOS</a></dt></dl></dd><dt>2. <a href="#architecture">Samba Architecture</a></dt><dd><dl><dt><a href="#id2795118">Introduction</a></dt><dt><a href="#id2795170">Multithreading and Samba</a></dt><dt><a href="#id2790937">Threading smbd</a></dt><dt><a href="#id2843423">Threading nmbd</a></dt><dt><a href="#id2791332">nbmd Design</a></dt></dl></dd><dt>3. <a href="#debug">The samba DEBUG system</a></dt><dd><dl><dt><a href="#id2790677">New Output Syntax</a></dt><dt><a href="#id2791433">The DEBUG() Macro</a></dt><dt><a href="#id2791102">The DEBUGADD() Macro</a></dt><dt><a href="#id2790705">The DEBUGLVL() Macro</a></dt><dt><a href="#id2790812">New Functions</a></dt><dd><dl><dt><a href="#id2790819">dbgtext()</a></dt><dt><a href="#id2790839">dbghdr()</a></dt><dt><a href="#id2790862">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="#id2857490">Character Handling</a></dt><dt><a href="#id2857515">The new functions</a></dt><dt><a href="#id2857977">Macros in byteorder.h</a></dt><dd><dl><dt><a href="#id2857991">CVAL(buf,pos)</a></dt><dt><a href="#id2858005">PVAL(buf,pos)</a></dt><dt><a href="#id2858019">SCVAL(buf,pos,val)</a></dt><dt><a href="#id2858032">SVAL(buf,pos)</a></dt><dt><a href="#id2858048">IVAL(buf,pos)</a></dt><dt><a href="#id2858062">SVALS(buf,pos)</a></dt><dt><a href="#id2858077">IVALS(buf,pos)</a></dt><dt><a href="#id2858091">SSVAL(buf,pos,val)</a></dt><dt><a href="#id2858106">SIVAL(buf,pos,val)</a></dt><dt><a href="#id2858120">SSVALS(buf,pos,val)</a></dt><dt><a href="#id2858134">SIVALS(buf,pos,val)</a></dt><dt><a href="#id2858149">RSVAL(buf,pos)</a></dt><dt><a href="#id2858163">RIVAL(buf,pos)</a></dt><dt><a href="#id2858177">RSSVAL(buf,pos,val)</a></dt><dt><a href="#id2858192">RSIVAL(buf,pos,val)</a></dt></dl></dd><dt><a href="#id2858208">LAN Manager Samba API</a></dt><dd><dl><dt><a href="#id2858243">Parameters</a></dt><dt><a href="#id2858395">Return value</a></dt></dl></dd><dt><a href="#id2858481">Code character table</a></dt></dl></dd><dt>6. <a href="#parsing">The smb.conf file</a></dt><dd><dl><dt><a href="#id2857849">Lexical Analysis</a></dt><dd><dl><dt><a href="#id2857787">Handling of Whitespace</a></dt><dt><a href="#id2858749">Handling of Line Continuation</a></dt><dt><a href="#id2858813">Line Continuation Quirks</a></dt></dl></dd><dt><a href="#id2858913">Syntax</a></dt><dd><dl><dt><a href="#id2858982">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="#id2858682">Introduction</a></dt><dt><a href="#id2858703">Usernames</a></dt><dt><a href="#id2858620">File Ownership</a></dt><dt><a href="#id2858644">Passwords</a></dt><dt><a href="#id2859208">Locking</a></dt><dt><a href="#id2859270">Deny Modes</a></dt><dt><a href="#id2859300">Trapdoor UIDs</a></dt><dt><a href="#id2859325">Port numbers</a></dt><dt><a href="#id2859371">Protocol Complexity</a></dt></dl></dd><dt>8. <a href="#tracing">Tracing samba system calls</a></dt><dt>9. <a href="#ntdomain">NT Domain RPC's</a></dt><dd><dl><dt><a href="#id2859563">Introduction</a></dt><dd><dl><dt><a href="#id2859980">Sources</a></dt><dt><a href="#id2860014">Credits</a></dt></dl></dd><dt><a href="#id2860053">Notes and Structures</a></dt><dd><dl><dt><a href="#id2860060">Notes</a></dt><dt><a href="#id2860137">Enumerations</a></dt><dt><a href="#id2860350">Structures</a></dt></dl></dd><dt><a href="#id2863307">MSRPC over Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2863320">MSRPC Pipes</a></dt><dt><a href="#id2863422">Header</a></dt><dt><a href="#id2864296">Tail</a></dt><dt><a href="#id2864342">RPC Bind / Bind Ack</a></dt><dt><a href="#id2864522">NTLSA Transact Named Pipe</a></dt><dt><a href="#id2864687">LSA Open Policy</a></dt><dt><a href="#id2864813">LSA Query Info Policy</a></dt><dt><a href="#id2864921">LSA Enumerate Trusted Domains</a></dt><dt><a href="#id2865012">LSA Open Secret</a></dt><dt><a href="#id2865122">LSA Close</a></dt><dt><a href="#id2865188">LSA Lookup SIDS</a></dt><dt><a href="#id2865399">LSA Lookup Names</a></dt></dl></dd><dt><a href="#id2865625">NETLOGON rpc Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2865786">LSA Request Challenge</a></dt><dt><a href="#id2865921">LSA Authenticate 2</a></dt><dt><a href="#id2866069">LSA Server Password Set</a></dt><dt><a href="#id2866185">LSA SAM Logon</a></dt><dt><a href="#id2866299">LSA SAM Logoff</a></dt></dl></dd><dt><a href="#id2866391">\\MAILSLOT\NET\NTLOGON</a></dt><dd><dl><dt><a href="#id2866408">Query for PDC</a></dt><dt><a href="#id2866670">SAM Logon</a></dt></dl></dd><dt><a href="#id2866996">SRVSVC Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2867041">Net Share Enum</a></dt><dt><a href="#id2867261">Net Server Get Info</a></dt></dl></dd><dt><a href="#id2867378">Cryptographic side of NT Domain Authentication</a></dt><dd><dl><dt><a href="#id2867386">Definitions</a></dt><dt><a href="#id2867548">Protocol</a></dt><dt><a href="#id2867629">Comments</a></dt></dl></dd><dt><a href="#id2867679">SIDs and RIDs</a></dt><dd><dl><dt><a href="#id2867719">Well-known SIDs</a></dt><dt><a href="#id2868034">Well-known RIDS</a></dt></dl></dd></dl></dd><dt>10. <a href="#printing">Samba Printing Internals</a></dt><dd><dl><dt><a href="#id2859754">Abstract</a></dt><dt><a href="#id2859770">
16 Printing Interface to Various Back ends
17 </a></dt><dt><a href="#id2859712">
18 Print Queue TDB's
19 </a></dt><dt><a href="#id2868639">
20 ChangeID and Client Caching of Printer Information
21 </a></dt><dt><a href="#id2868653">
22 Windows NT/2K Printer Change Notify
23 </a></dt></dl></dd><dt>11. <a href="#wins">Samba WINS Internals</a></dt><dd><dl><dt><a href="#id2868400">WINS Failover</a></dt></dl></dd><dt>12. <a href="#sam">The Upcoming SAM System</a></dt><dd><dl><dt><a href="#id2869126">Security in the 'new SAM'</a></dt><dt><a href="#id2869257">Standalone from UNIX</a></dt><dt><a href="#id2869292">Handles and Races in the new SAM</a></dt><dt><a href="#id2869361">Layers</a></dt><dd><dl><dt><a href="#id2869368">Application</a></dt><dt><a href="#id2869384">SAM Interface</a></dt><dt><a href="#id2869412">SAM Modules</a></dt></dl></dd><dt><a href="#id2869434">SAM Modules</a></dt><dd><dl><dt><a href="#id2869441">Special Module: sam_passdb</a></dt><dt><a href="#id2869459">sam_ads</a></dt></dl></dd><dt><a href="#id2869498">Memory Management</a></dt><dt><a href="#id2869589">Testing</a></dt></dl></dd><dt>13. <a href="#pwencrypt">LanMan and NT Password Encryption</a></dt><dd><dl><dt><a href="#id2869092">Introduction</a></dt><dt><a href="#id2868961">How does it work?</a></dt><dt><a href="#id2869678">The smbpasswd file</a></dt></dl></dd><dt>14. <a href="#modules">Modules</a></dt><dd><dl><dt><a href="#id2870133">Advantages</a></dt><dt><a href="#id2869868">Loading modules</a></dt><dd><dl><dt><a href="#id2869901">Static modules</a></dt><dt><a href="#id2870337">Shared modules</a></dt></dl></dd><dt><a href="#id2870365">Writing modules</a></dt><dd><dl><dt><a href="#id2870425">Static/Shared selection in configure.in</a></dt></dl></dd></dl></dd><dt>15. <a href="#rpc-plugin">RPC Pluggable Modules</a></dt><dd><dl><dt><a href="#id2869935">About</a></dt><dt><a href="#id2869954">General Overview</a></dt></dl></dd><dt>16. <a href="#Packaging">Notes to packagers</a></dt><dd><dl><dt><a href="#id2870644">Versioning</a></dt><dt><a href="#id2870677">Modules</a></dt></dl></dd></dl></div><div class="chapter" lang="en"><div class="titlepage"><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">Luke Leighton</h3></div></div><div><p class="pubdate">12 June 1997</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2791176">NETBIOS</a></dt><dt><a href="#id2791260">BROADCAST NetBIOS</a></dt><dt><a href="#id2791291">NBNS NetBIOS</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2791176"></a>NETBIOS</h2></div></div><p>
24 NetBIOS runs over the following tranports: TCP/IP; NetBEUI and IPX/SPX.
25 Samba only uses NetBIOS over TCP/IP. For details on the TCP/IP NetBIOS
26 Session Service NetBIOS Datagram Service, and NetBIOS Names, see
27 rfc1001.txt and rfc1002.txt.
28 </p><p>
29 NetBEUI is a raw NetBIOS frame protocol implementation that allows NetBIOS
30 datagrams to be sent out over the 'wire' embedded within LLC frames.
31 NetBEUI is not required when using NetBIOS over TCP/IP protocols and it
32 is preferable NOT to install NetBEUI if it can be avoided.
33 </p><p>
34 IPX/SPX is also not required when using NetBIOS over TCP/IP, and it is
35 preferable NOT to install the IPX/SPX transport unless you are using Novell
36 servers. At the very least, it is recommended that you do not install
37 'NetBIOS over IPX/SPX'.
38 </p><p>
39 [When installing Windows 95, you will find that NetBEUI and IPX/SPX are
40 installed as the default protocols. This is because they are the simplest
41 to manage: no Windows 95 user-configuration is required].
42 </p><p>
43 NetBIOS applications (such as samba) offer their services (for example,
44 SMB file and print sharing) on a NetBIOS name. They must claim this name
45 on the network before doing so. The NetBIOS session service will then
46 accept connections on the application's behalf (on the NetBIOS name
47 claimed by the application). A NetBIOS session between the application
48 and the client can then commence.
49 </p><p>
50 NetBIOS names consist of 15 characters plus a 'type' character. This is
51 similar, in concept, to an IP address and a TCP port number, respectively.
52 A NetBIOS-aware application on a host will offer different services under
53 different NetBIOS name types, just as a host will offer different TCP/IP
54 services on different port numbers.
55 </p><p>
56 NetBIOS names must be claimed on a network, and must be defended. The use
57 of NetBIOS names is most suitable on a single subnet; a Local Area Network
58 or a Wide Area Network.
59 </p><p>
60 NetBIOS names are either UNIQUE or GROUP. Only one application can claim a
61 UNIQUE NetBIOS name on a network.
62 </p><p>
63 There are two kinds of NetBIOS Name resolution: Broadcast and Point-to-Point.
64 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2791260"></a>BROADCAST NetBIOS</h2></div></div><p>
65 Clients can claim names, and therefore offer services on successfully claimed
66 names, on their broadcast-isolated subnet. One way to get NetBIOS services
67 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
68 SMB file/print sharing: see cifs4.txt) working on a LAN or WAN is to make
69 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.
70 </p><p>
71 This, however, is not recommended. If you have a large LAN or WAN, you will
72 find that some of your hosts spend 95 percent of their time dealing with
73 broadcast traffic. [If you have IPX/SPX on your LAN or WAN, you will find
74 that this is already happening: a packet analyzer will show, roughly
75 every twelve minutes, great swathes of broadcast traffic!].
76 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2791291"></a>NBNS NetBIOS</h2></div></div><p>
77 rfc1001.txt describes, amongst other things, the implementation and use
78 of, a 'NetBIOS Name Service'. NT/AS offers 'Windows Internet Name Service'
79 which is fully rfc1001/2 compliant, but has had to take specific action
80 with certain NetBIOS names in order to make it useful. (for example, it
81 deals with the registration of &lt;1c&gt; &lt;1d&gt; &lt;1e&gt; names all in different ways.
82 I recommend the reading of the Microsoft WINS Server Help files for full
83 details).
84 </p><p>
85 The use of a WINS server cuts down on broadcast network traffic for
86 NetBIOS name resolution. It has the effect of pulling all the broadcast
87 isolated subnets together into a single NetBIOS scope, across your LAN
88 or WAN, while avoiding the use of TCP/IP broadcast packets.
89 </p><p>
90 When you have a WINS server on your LAN, WINS clients will be able to
91 contact the WINS server to resolve NetBIOS names. Note that only those
92 WINS clients that have registered with the same WINS server will be
93 visible. The WINS server _can_ have static NetBIOS entries added to its
94 database (usually for security reasons you might want to consider putting
95 your domain controllers or other important servers as static entries,
96 but you should not rely on this as your sole means of security), but for
97 the most part, NetBIOS names are registered dynamically.
98 </p><p>
99 This provides some confusion for lots of people, and is worth mentioning
100 here: a Browse Server is NOT a WINS Server, even if these services are
101 implemented in the same application. A Browse Server _needs_ a WINS server
102 because a Browse Server is a WINS client, which is _not_ the same thing].
103 </p><p>
104 Clients can claim names, and therefore offer services on successfully claimed
105 names, on their broadcast-isolated subnet. One way to get NetBIOS services
106 (such as browsing: see ftp.microsoft.com/drg/developr/CIFS/browdiff.txt; and
107 SMB file/print sharing: see cifs6.txt) working on a LAN or WAN is to make
108 your routers forward all broadcast packets from TCP/IP ports 137, 138 and 139.
109 You will find, however, if you do this on a large LAN or a WAN, that your
110 network is completely swamped by NetBIOS and browsing packets, which is why
111 WINS was developed to minimise the necessity of broadcast traffic.
112 </p><p>
113 WINS Clients therefore claim names from the WINS server. If the WINS
114 server allows them to register a name, the client's NetBIOS session service
115 can then offer services on this name. Other WINS clients will then
116 contact the WINS server to resolve a NetBIOS name.
117 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="architecture"></a>Chapter 2. Samba Architecture</h2></div><div><div class="author"><h3 class="author">Dan Shearer</h3></div></div><div><p class="pubdate"> November 1997</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2795118">Introduction</a></dt><dt><a href="#id2795170">Multithreading and Samba</a></dt><dt><a href="#id2790937">Threading smbd</a></dt><dt><a href="#id2843423">Threading nmbd</a></dt><dt><a href="#id2791332">nbmd Design</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2795118"></a>Introduction</h2></div></div><p>
118 This document gives a general overview of how Samba works
119 internally. The Samba Team has tried to come up with a model which is
120 the best possible compromise between elegance, portability, security
121 and the constraints imposed by the very messy SMB and CIFS
122 protocol.
123 </p><p>
124 It also tries to answer some of the frequently asked questions such as:
125 </p><div class="orderedlist"><ol type="1"><li><p>
126 Is Samba secure when running on Unix? The xyz platform?
127 What about the root priveliges issue?
128 </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><h2 class="title" style="clear: both"><a name="id2795170"></a>Multithreading and Samba</h2></div></div><p>
129 People sometimes tout threads as a uniformly good thing. They are very
130 nice in their place but are quite inappropriate for smbd. nmbd is
131 another matter, and multi-threading it would be very nice.
132 </p><p>
133 The short version is that smbd is not multithreaded, and alternative
134 servers that take this approach under Unix (such as Syntax, at the
135 time of writing) suffer tremendous performance penalties and are less
136 robust. nmbd is not threaded either, but this is because it is not
137 possible to do it while keeping code consistent and portable across 35
138 or more platforms. (This drawback also applies to threading smbd.)
139 </p><p>
140 The longer versions is that there are very good reasons for not making
141 smbd multi-threaded. Multi-threading would actually make Samba much
142 slower, less scalable, less portable and much less robust. The fact
143 that we use a separate process for each connection is one of Samba's
144 biggest advantages.
145 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2790937"></a>Threading smbd</h2></div></div><p>
146 A few problems that would arise from a threaded smbd are:
147 </p><div class="orderedlist"><ol type="1"><li><p>
148 It's not only to create threads instead of processes, but you
149 must care about all variables if they have to be thread specific
150 (currently they would be global).
151 </p></li><li><p>
152 if one thread dies (eg. a seg fault) then all threads die. We can
153 immediately throw robustness out the window.
154 </p></li><li><p>
155 many of the system calls we make are blocking. Non-blocking
156 equivalents of many calls are either not available or are awkward (and
157 slow) to use. So while we block in one thread all clients are
158 waiting. Imagine if one share is a slow NFS filesystem and the others
159 are fast, we will end up slowing all clients to the speed of NFS.
160 </p></li><li><p>
161 you can't run as a different uid in different threads. This means
162 we would have to switch uid/gid on _every_ SMB packet. It would be
163 horrendously slow.
164 </p></li><li><p>
165 the per process file descriptor limit would mean that we could only
166 support a limited number of clients.
167 </p></li><li><p>
168 we couldn't use the system locking calls as the locking context of
169 fcntl() is a process, not a thread.
170 </p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2843423"></a>Threading nmbd</h2></div></div><p>
171 This would be ideal, but gets sunk by portability requirements.
172 </p><p>
173 Andrew tried to write a test threads library for nmbd that used only
174 ansi-C constructs (using setjmp and longjmp). Unfortunately some OSes
175 defeat this by restricting longjmp to calling addresses that are
176 shallower than the current address on the stack (apparently AIX does
177 this). This makes a truly portable threads library impossible. So to
178 support all our current platforms we would have to code nmbd both with
179 and without threads, and as the real aim of threads is to make the
180 code clearer we would not have gained anything. (it is a myth that
181 threads make things faster. threading is like recursion, it can make
182 things clear but the same thing can always be done faster by some
183 other method)
184 </p><p>
185 Chris tried to spec out a general design that would abstract threading
186 vs separate processes (vs other methods?) and make them accessible
187 through some general API. This doesn't work because of the data
188 sharing requirements of the protocol (packets in the future depending
189 on packets now, etc.) At least, the code would work but would be very
190 clumsy, and besides the fork() type model would never work on Unix. (Is there an OS that it would work on, for nmbd?)
191 </p><p>
192 A fork() is cheap, but not nearly cheap enough to do on every UDP
193 packet that arrives. Having a pool of processes is possible but is
194 nasty to program cleanly due to the enormous amount of shared data (in
195 complex structures) between the processes. We can't rely on each
196 platform having a shared memory system.
197 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2791332"></a>nbmd Design</h2></div></div><p>
198 Originally Andrew used recursion to simulate a multi-threaded
199 environment, which use the stack enormously and made for really
200 confusing debugging sessions. Luke Leighton rewrote it to use a
201 queuing system that keeps state information on each packet. The
202 first version used a single structure which was used by all the
203 pending states. As the initialisation of this structure was
204 done by adding arguments, as the functionality developed, it got
205 pretty messy. So, it was replaced with a higher-order function
206 and a pointer to a user-defined memory block. This suddenly
207 made things much simpler: large numbers of functions could be
208 made static, and modularised. This is the same principle as used
209 in NT's kernel, and achieves the same effect as threads, but in
210 a single process.
211 </p><p>
212 Then Jeremy rewrote nmbd. The packet data in nmbd isn't what's on the
213 wire. It's a nice format that is very amenable to processing but still
214 keeps the idea of a distinct packet. See &quot;struct packet_struct&quot; in
215 nameserv.h. It has all the detail but none of the on-the-wire
216 mess. This makes it ideal for using in disk or memory-based databases
217 for browsing and WINS support.
218 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="debug"></a>Chapter 3. The samba DEBUG system</h2></div><div><div class="author"><h3 class="author">Chris Hertel</h3></div></div><div><p class="pubdate">July 1998</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2790677">New Output Syntax</a></dt><dt><a href="#id2791433">The DEBUG() Macro</a></dt><dt><a href="#id2791102">The DEBUGADD() Macro</a></dt><dt><a href="#id2790705">The DEBUGLVL() Macro</a></dt><dt><a href="#id2790812">New Functions</a></dt><dd><dl><dt><a href="#id2790819">dbgtext()</a></dt><dt><a href="#id2790839">dbghdr()</a></dt><dt><a href="#id2790862">format_debug_text()</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2790677"></a>New Output Syntax</h2></div></div><p>
219 The syntax of a debugging log file is represented as:
220 </p><pre class="programlisting">
221 &gt;debugfile&lt; :== { &gt;debugmsg&lt; }
223 &gt;debugmsg&lt; :== &gt;debughdr&lt; '\n' &gt;debugtext&lt;
225 &gt;debughdr&lt; :== '[' TIME ',' LEVEL ']' FILE ':' [FUNCTION] '(' LINE ')'
227 &gt;debugtext&lt; :== { &gt;debugline&lt; }
229 &gt;debugline&lt; :== TEXT '\n'
230 </pre><p>
231 TEXT is a string of characters excluding the newline character.
232 </p><p>
233 LEVEL is the DEBUG level of the message (an integer in the range
234 0..10).
235 </p><p>
236 TIME is a timestamp.
237 </p><p>
238 FILE is the name of the file from which the debug message was
239 generated.
240 </p><p>
241 FUNCTION is the function from which the debug message was generated.
242 </p><p>
243 LINE is the line number of the debug statement that generated the
244 message.
245 </p><p>Basically, what that all means is:</p><div class="orderedlist"><ol type="1"><li><p>
246 A debugging log file is made up of debug messages.
247 </p></li><li><p>
248 Each debug message is made up of a header and text. The header is
249 separated from the text by a newline.
250 </p></li><li><p>
251 The header begins with the timestamp and debug level of the
252 message enclosed in brackets. The filename, function, and line
253 number at which the message was generated follow. The filename is
254 terminated by a colon, and the function name is terminated by the
255 parenthesis which contain the line number. Depending upon the
256 compiler, the function name may be missing (it is generated by the
257 __FUNCTION__ macro, which is not universally implemented, dangit).
258 </p></li><li><p>
259 The message text is made up of zero or more lines, each terminated
260 by a newline.
261 </p></li></ol></div><p>Here's some example output:</p><pre class="programlisting">
262 [1998/08/03 12:55:25, 1] nmbd.c:(659)
263 Netbios nameserver version 1.9.19-prealpha started.
264 Copyright Andrew Tridgell 1994-1997
265 [1998/08/03 12:55:25, 3] loadparm.c:(763)
266 Initializing global parameters
267 </pre><p>
268 Note that in the above example the function names are not listed on
269 the header line. That's because the example above was generated on an
270 SGI Indy, and the SGI compiler doesn't support the __FUNCTION__ macro.
271 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2791433"></a>The DEBUG() Macro</h2></div></div><p>
272 Use of the DEBUG() macro is unchanged. DEBUG() takes two parameters.
273 The first is the message level, the second is the body of a function
274 call to the Debug1() function.
275 </p><p>That's confusing.</p><p>Here's an example which may help a bit. If you would write</p><pre class="programlisting">
276 printf( &quot;This is a %s message.\n&quot;, &quot;debug&quot; );
277 </pre><p>
278 to send the output to stdout, then you would write
279 </p><pre class="programlisting">
280 DEBUG( 0, ( &quot;This is a %s message.\n&quot;, &quot;debug&quot; ) );
281 </pre><p>
282 to send the output to the debug file. All of the normal printf()
283 formatting escapes work.
284 </p><p>
285 Note that in the above example the DEBUG message level is set to 0.
286 Messages at level 0 always print. Basically, if the message level is
287 less than or equal to the global value DEBUGLEVEL, then the DEBUG
288 statement is processed.
289 </p><p>
290 The output of the above example would be something like:
291 </p><pre class="programlisting">
292 [1998/07/30 16:00:51, 0] file.c:function(128)
293 This is a debug message.
294 </pre><p>
295 Each call to DEBUG() creates a new header *unless* the output produced
296 by the previous call to DEBUG() did not end with a '\n'. Output to the
297 debug file is passed through a formatting buffer which is flushed
298 every time a newline is encountered. If the buffer is not empty when
299 DEBUG() is called, the new input is simply appended.
300 </p><p>
301 ...but that's really just a Kludge. It was put in place because
302 DEBUG() has been used to write partial lines. Here's a simple (dumb)
303 example of the kind of thing I'm talking about:
304 </p><pre class="programlisting">
305 DEBUG( 0, (&quot;The test returned &quot; ) );
306 if( test() )
307 DEBUG(0, (&quot;True&quot;) );
308 else
309 DEBUG(0, (&quot;False&quot;) );
310 DEBUG(0, (&quot;.\n&quot;) );
311 </pre><p>
312 Without the format buffer, the output (assuming test() returned true)
313 would look like this:
314 </p><pre class="programlisting">
315 [1998/07/30 16:00:51, 0] file.c:function(256)
316 The test returned
317 [1998/07/30 16:00:51, 0] file.c:function(258)
318 True
319 [1998/07/30 16:00:51, 0] file.c:function(261)
321 </pre><p>Which isn't much use. The format buffer kludge fixes this problem.
322 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2791102"></a>The DEBUGADD() Macro</h2></div></div><p>
323 In addition to the kludgey solution to the broken line problem
324 described above, there is a clean solution. The DEBUGADD() macro never
325 generates a header. It will append new text to the current debug
326 message even if the format buffer is empty. The syntax of the
327 DEBUGADD() macro is the same as that of the DEBUG() macro.
328 </p><pre class="programlisting">
329 DEBUG( 0, (&quot;This is the first line.\n&quot; ) );
330 DEBUGADD( 0, (&quot;This is the second line.\nThis is the third line.\n&quot; ) );
331 </pre><p>Produces</p><pre class="programlisting">
332 [1998/07/30 16:00:51, 0] file.c:function(512)
333 This is the first line.
334 This is the second line.
335 This is the third line.
336 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2790705"></a>The DEBUGLVL() Macro</h2></div></div><p>
337 One of the problems with the DEBUG() macro was that DEBUG() lines
338 tended to get a bit long. Consider this example from
339 nmbd_sendannounce.c:
340 </p><pre class="programlisting">
341 DEBUG(3,(&quot;send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n&quot;,
342 type, global_myname, subrec-&gt;subnet_name, work-&gt;work_group));
343 </pre><p>
344 One solution to this is to break it down using DEBUG() and DEBUGADD(),
345 as follows:
346 </p><pre class="programlisting">
347 DEBUG( 3, ( &quot;send_local_master_announcement: &quot; ) );
348 DEBUGADD( 3, ( &quot;type %x for name %s &quot;, type, global_myname ) );
349 DEBUGADD( 3, ( &quot;on subnet %s &quot;, subrec-&gt;subnet_name ) );
350 DEBUGADD( 3, ( &quot;for workgroup %s\n&quot;, work-&gt;work_group ) );
351 </pre><p>
352 A similar, but arguably nicer approach is to use the DEBUGLVL() macro.
353 This macro returns True if the message level is less than or equal to
354 the global DEBUGLEVEL value, so:
355 </p><pre class="programlisting">
356 if( DEBUGLVL( 3 ) )
358 dbgtext( &quot;send_local_master_announcement: &quot; );
359 dbgtext( &quot;type %x for name %s &quot;, type, global_myname );
360 dbgtext( &quot;on subnet %s &quot;, subrec-&gt;subnet_name );
361 dbgtext( &quot;for workgroup %s\n&quot;, work-&gt;work_group );
363 </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>
364 The test is performed only once.
365 </p></li><li><p>
366 You can allocate variables off of the stack that will only be used
367 within the DEBUGLVL() block.
368 </p></li><li><p>
369 Processing that is only relevant to debug output can be contained
370 within the DEBUGLVL() block.
371 </p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2790812"></a>New Functions</h2></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2790819"></a>dbgtext()</h3></div></div><p>
372 This function prints debug message text to the debug file (and
373 possibly to syslog) via the format buffer. The function uses a
374 variable argument list just like printf() or Debug1(). The
375 input is printed into a buffer using the vslprintf() function,
376 and then passed to format_debug_text().
378 If you use DEBUGLVL() you will probably print the body of the
379 message using dbgtext().
380 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2790839"></a>dbghdr()</h3></div></div><p>
381 This is the function that writes a debug message header.
382 Headers are not processed via the format buffer. Also note that
383 if the format buffer is not empty, a call to dbghdr() will not
384 produce any output. See the comments in dbghdr() for more info.
385 </p><p>
386 It is not likely that this function will be called directly. It
387 is used by DEBUG() and DEBUGADD().
388 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2790862"></a>format_debug_text()</h3></div></div><p>
389 This is a static function in debug.c. It stores the output text
390 for the body of the message in a buffer until it encounters a
391 newline. When the newline character is found, the buffer is
392 written to the debug file via the Debug1() function, and the
393 buffer is reset. This allows us to add the indentation at the
394 beginning of each line of the message body, and also ensures
395 that the output is written a line at a time (which cleans up
396 syslog output).
397 </p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="CodingSuggestions"></a>Chapter 4. Coding Suggestions</h2></div><div><div class="author"><h3 class="author">Steve French</h3></div></div><div><div class="author"><h3 class="author">Simo Sorce</h3></div></div><div><div class="author"><h3 class="author">Andrew Bartlett</h3></div></div><div><div class="author"><h3 class="author">Tim Potter</h3></div></div><div><div class="author"><h3 class="author">Martin Pool</h3></div></div></div><p>
398 So you want to add code to Samba ...
399 </p><p>
400 One of the daunting tasks facing a programmer attempting to write code for
401 Samba is understanding the various coding conventions used by those most
402 active in the project. These conventions were mostly unwritten and helped
403 improve either the portability, stability or consistency of the code. This
404 document will attempt to document a few of the more important coding
405 practices used at this time on the Samba project. The coding practices are
406 expected to change slightly over time, and even to grow as more is learned
407 about obscure portability considerations. Two existing documents
408 <tt>samba/source/internals.doc</tt> and
409 <tt>samba/source/architecture.doc</tt> provide
410 additional information.
411 </p><p>
412 The loosely related question of coding style is very personal and this
413 document does not attempt to address that subject, except to say that I
414 have observed that eight character tabs seem to be preferred in Samba
415 source. If you are interested in the topic of coding style, two oft-quoted
416 documents are:
417 </p><p>
418 <a href="http://lxr.linux.no/source/Documentation/CodingStyle" target="_top">http://lxr.linux.no/source/Documentation/CodingStyle</a>
419 </p><p>
420 <a href="http://www.fsf.org/prep/standards_toc.html" target="_top">http://www.fsf.org/prep/standards_toc.html</a>
421 </p><p>
422 But note that coding style in Samba varies due to the many different
423 programmers who have contributed.
424 </p><p>
425 Following are some considerations you should use when adding new code to
426 Samba. First and foremost remember that:
427 </p><p>
428 Portability is a primary consideration in adding function, as is network
429 compatability with de facto, existing, real world CIFS/SMB implementations.
430 There are lots of platforms that Samba builds on so use caution when adding
431 a call to a library function that is not invoked in existing Samba code.
432 Also note that there are many quite different SMB/CIFS clients that Samba
433 tries to support, not all of which follow the SNIA CIFS Technical Reference
434 (or the earlier Microsoft reference documents or the X/Open book on the SMB
435 Standard) perfectly.
436 </p><p>
437 Here are some other suggestions:
438 </p><div class="orderedlist"><ol type="1"><li><p>
439 use d_printf instead of printf for display text
440 reason: enable auto-substitution of translated language text
441 </p></li><li><p>
442 use SAFE_FREE instead of free
443 reason: reduce traps due to null pointers
444 </p></li><li><p>
445 don't use bzero use memset, or ZERO_STRUCT and ZERO_STRUCTP macros
446 reason: not POSIX
447 </p></li><li><p>
448 don't use strcpy and strlen (use safe_* equivalents)
449 reason: to avoid traps due to buffer overruns
450 </p></li><li><p>
451 don't use getopt_long, use popt functions instead
452 reason: portability
453 </p></li><li><p>
454 explicitly add const qualifiers on parm passing in functions where parm
455 is input only (somewhat controversial but const can be #defined away)
456 </p></li><li><p>
457 when passing a va_list as an arg, or assigning one to another
458 please use the VA_COPY() macro
459 reason: on some platforms, va_list is a struct that must be
460 initialized in each function...can SEGV if you don't.
461 </p></li><li><p>
462 discourage use of threads
463 reason: portability (also see architecture.doc)
464 </p></li><li><p>
465 don't explicitly include new header files in C files - new h files
466 should be included by adding them once to includes.h
467 reason: consistency
468 </p></li><li><p>
469 don't explicitly extern functions (they are autogenerated by
470 &quot;make proto&quot; into proto.h)
471 reason: consistency
472 </p></li><li><p>
473 use endian safe macros when unpacking SMBs (see byteorder.h and
474 internals.doc)
475 reason: not everyone uses Intel
476 </p></li><li><p>
477 Note Unicode implications of charset handling (see internals.doc). See
478 pull_* and push_* and convert_string functions.
479 reason: Internationalization
480 </p></li><li><p>
481 Don't assume English only
482 reason: See above
483 </p></li><li><p>
484 Try to avoid using in/out parameters (functions that return data which
485 overwrites input parameters)
486 reason: Can cause stability problems
487 </p></li><li><p>
488 Ensure copyright notices are correct, don't append Tridge's name to code
489 that he didn't write. If you did not write the code, make sure that it
490 can coexist with the rest of the Samba GPLed code.
491 </p></li><li><p>
492 Consider usage of DATA_BLOBs for length specified byte-data.
493 reason: stability
494 </p></li><li><p>
495 Take advantage of tdbs for database like function
496 reason: consistency
497 </p></li><li><p>
498 Don't access the SAM_ACCOUNT structure directly, they should be accessed
499 via pdb_get...() and pdb_set...() functions.
500 reason: stability, consistency
501 </p></li><li><p>
502 Don't check a password directly against the passdb, always use the
503 check_password() interface.
504 reason: long term pluggability
505 </p></li><li><p>
506 Try to use asprintf rather than pstrings and fstrings where possible
507 </p></li><li><p>
508 Use normal C comments / * instead of C++ comments // like
509 this. Although the C++ comment format is part of the C99
510 standard, some older vendor C compilers do not accept it.
511 </p></li><li><p>
512 Try to write documentation for API functions and structures
513 explaining the point of the code, the way it should be used, and
514 any special conditions or results. Mark these with a double-star
515 comment start / ** so that they can be picked up by Doxygen, as in
516 this file.
517 </p></li><li><p>
518 Keep the scope narrow. This means making functions/variables
519 static whenever possible. We don't want our namespace
520 polluted. Each module should have a minimal number of externally
521 visible functions or variables.
522 </p></li><li><p>
523 Use function pointers to keep knowledge about particular pieces of
524 code isolated in one place. We don't want a particular piece of
525 functionality to be spread out across lots of places - that makes
526 for fragile, hand to maintain code. Instead, design an interface
527 and use tables containing function pointers to implement specific
528 functionality. This is particularly important for command
529 interpreters.
530 </p></li><li><p>
531 Think carefully about what it will be like for someone else to add
532 to and maintain your code. If it would be hard for someone else to
533 maintain then do it another way.
534 </p></li></ol></div><p>
535 The suggestions above are simply that, suggestions, but the information may
536 help in reducing the routine rework done on new code. The preceeding list
537 is expected to change routinely as new support routines and macros are
538 added.
539 </p></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="internals"></a>Chapter 5. Samba Internals</h2></div><div><div class="author"><h3 class="author">David Chappell</h3><div class="affiliation"><div class="address"><p><tt>&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 class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2857490">Character Handling</a></dt><dt><a href="#id2857515">The new functions</a></dt><dt><a href="#id2857977">Macros in byteorder.h</a></dt><dd><dl><dt><a href="#id2857991">CVAL(buf,pos)</a></dt><dt><a href="#id2858005">PVAL(buf,pos)</a></dt><dt><a href="#id2858019">SCVAL(buf,pos,val)</a></dt><dt><a href="#id2858032">SVAL(buf,pos)</a></dt><dt><a href="#id2858048">IVAL(buf,pos)</a></dt><dt><a href="#id2858062">SVALS(buf,pos)</a></dt><dt><a href="#id2858077">IVALS(buf,pos)</a></dt><dt><a href="#id2858091">SSVAL(buf,pos,val)</a></dt><dt><a href="#id2858106">SIVAL(buf,pos,val)</a></dt><dt><a href="#id2858120">SSVALS(buf,pos,val)</a></dt><dt><a href="#id2858134">SIVALS(buf,pos,val)</a></dt><dt><a href="#id2858149">RSVAL(buf,pos)</a></dt><dt><a href="#id2858163">RIVAL(buf,pos)</a></dt><dt><a href="#id2858177">RSSVAL(buf,pos,val)</a></dt><dt><a href="#id2858192">RSIVAL(buf,pos,val)</a></dt></dl></dd><dt><a href="#id2858208">LAN Manager Samba API</a></dt><dd><dl><dt><a href="#id2858243">Parameters</a></dt><dt><a href="#id2858395">Return value</a></dt></dl></dd><dt><a href="#id2858481">Code character table</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2857490"></a>Character Handling</h2></div></div><p>
540 This section describes character set handling in Samba, as implemented in
541 Samba 3.0 and above
542 </p><p>
543 In the past Samba had very ad-hoc character set handling. Scattered
544 throughout the code were numerous calls which converted particular
545 strings to/from DOS codepages. The problem is that there was no way of
546 telling if a particular char* is in dos codepage or unix
547 codepage. This led to a nightmare of code that tried to cope with
548 particular cases without handlingt the general case.
549 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2857515"></a>The new functions</h2></div></div><p>
550 The new system works like this:
551 </p><div class="orderedlist"><ol type="1"><li><p>
552 all char* strings inside Samba are &quot;unix&quot; strings. These are
553 multi-byte strings that are in the charset defined by the &quot;unix
554 charset&quot; option in smb.conf.
555 </p></li><li><p>
556 there is no single fixed character set for unix strings, but any
557 character set that is used does need the following properties:
558 </p><div class="orderedlist"><ol type="a"><li><p>
559 must not contain NULLs except for termination
560 </p></li><li><p>
561 must be 7-bit compatible with C strings, so that a constant
562 string or character in C will be byte-for-byte identical to the
563 equivalent string in the chosen character set.
564 </p></li><li><p>
565 when you uppercase or lowercase a string it does not become
566 longer than the original string
567 </p></li><li><p>
568 must be able to correctly hold all characters that your client
569 will throw at it
570 </p></li></ol></div><p>
571 For example, UTF-8 is fine, and most multi-byte asian character sets
572 are fine, but UCS2 could not be used for unix strings as they
573 contain nulls.
574 </p></li><li><p>
575 when you need to put a string into a buffer that will be sent on the
576 wire, or you need a string in a character set format that is
577 compatible with the clients character set then you need to use a
578 pull_ or push_ function. The pull_ functions pull a string from a
579 wire buffer into a (multi-byte) unix string. The push_ functions
580 push a string out to a wire buffer.
581 </p></li><li><p>
582 the two main pull_ and push_ functions you need to understand are
583 pull_string and push_string. These functions take a base pointer
584 that should point at the start of the SMB packet that the string is
585 in. The functions will check the flags field in this packet to
586 automatically determine if the packet is marked as a unicode packet,
587 and they will choose whether to use unicode for this string based on
588 that flag. You may also force this decision using the STR_UNICODE or
589 STR_ASCII flags. For use in smbd/ and libsmb/ there are wrapper
590 functions clistr_ and srvstr_ that call the pull_/push_ functions
591 with the appropriate first argument.
592 </p><p>
593 You may also call the pull_ascii/pull_ucs2 or push_ascii/push_ucs2
594 functions if you know that a particular string is ascii or
595 unicode. There are also a number of other convenience functions in
596 charcnv.c that call the pull_/push_ functions with particularly
597 common arguments, such as pull_ascii_pstring()
598 </p></li><li><p>
599 The biggest thing to remember is that internal (unix) strings in Samba
600 may now contain multi-byte characters. This means you cannot assume
601 that characters are always 1 byte long. Often this means that you will
602 have to convert strings to ucs2 and back again in order to do some
603 (seemingly) simple task. For examples of how to do this see functions
604 like strchr_m(). I know this is very slow, and we will eventually
605 speed it up but right now we want this stuff correct not fast.
606 </p></li><li><p>
607 all lp_ functions now return unix strings. The magic &quot;DOS&quot; flag on
608 parameters is gone.
609 </p></li><li><p>
610 all vfs functions take unix strings. Don't convert when passing to them
611 </p></li></ol></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2857977"></a>Macros in byteorder.h</h2></div></div><p>
612 This section describes the macros defined in byteorder.h. These macros
613 are used extensively in the Samba code.
614 </p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2857991"></a>CVAL(buf,pos)</h3></div></div><p>
615 returns the byte at offset pos within buffer buf as an unsigned character.
616 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858005"></a>PVAL(buf,pos)</h3></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><h3 class="title"><a name="id2858019"></a>SCVAL(buf,pos,val)</h3></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><h3 class="title"><a name="id2858032"></a>SVAL(buf,pos)</h3></div></div><p>
617 returns the value of the unsigned short (16 bit) little-endian integer at
618 offset pos within buffer buf. An integer of this type is sometimes
619 refered to as &quot;USHORT&quot;.
620 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858048"></a>IVAL(buf,pos)</h3></div></div><p>returns the value of the unsigned 32 bit little-endian integer at offset
621 pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858062"></a>SVALS(buf,pos)</h3></div></div><p>returns the value of the signed short (16 bit) little-endian integer at
622 offset pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858077"></a>IVALS(buf,pos)</h3></div></div><p>returns the value of the signed 32 bit little-endian integer at offset pos
623 within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858091"></a>SSVAL(buf,pos,val)</h3></div></div><p>sets the unsigned short (16 bit) little-endian integer at offset pos within
624 buffer buf to value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858106"></a>SIVAL(buf,pos,val)</h3></div></div><p>sets the unsigned 32 bit little-endian integer at offset pos within buffer
625 buf to the value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858120"></a>SSVALS(buf,pos,val)</h3></div></div><p>sets the short (16 bit) signed little-endian integer at offset pos within
626 buffer buf to the value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858134"></a>SIVALS(buf,pos,val)</h3></div></div><p>sets the signed 32 bit little-endian integer at offset pos withing buffer
627 buf to the value val.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858149"></a>RSVAL(buf,pos)</h3></div></div><p>returns the value of the unsigned short (16 bit) big-endian integer at
628 offset pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858163"></a>RIVAL(buf,pos)</h3></div></div><p>returns the value of the unsigned 32 bit big-endian integer at offset
629 pos within buffer buf.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858177"></a>RSSVAL(buf,pos,val)</h3></div></div><p>sets the value of the unsigned short (16 bit) big-endian integer at
630 offset pos within buffer buf to value val.
631 refered to as &quot;USHORT&quot;.</p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858192"></a>RSIVAL(buf,pos,val)</h3></div></div><p>sets the value of the unsigned 32 bit big-endian integer at offset
632 pos within buffer buf to value val.</p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858208"></a>LAN Manager Samba API</h2></div></div><p>
633 This section describes the functions need to make a LAN Manager RPC call.
634 This information had been obtained by examining the Samba code and the LAN
635 Manager 2.0 API documentation. It should not be considered entirely
636 reliable.
637 </p><p>
638 </p><pre class="programlisting">
639 call_api(int prcnt, int drcnt, int mprcnt, int mdrcnt,
640 char *param, char *data, char **rparam, char **rdata);
641 </pre><p>
642 </p><p>
643 This function is defined in client.c. It uses an SMB transaction to call a
644 remote api.
645 </p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858243"></a>Parameters</h3></div></div><p>The parameters are as follows:</p><div class="orderedlist"><ol type="1"><li><p>
646 prcnt: the number of bytes of parameters begin sent.
647 </p></li><li><p>
648 drcnt: the number of bytes of data begin sent.
649 </p></li><li><p>
650 mprcnt: the maximum number of bytes of parameters which should be returned
651 </p></li><li><p>
652 mdrcnt: the maximum number of bytes of data which should be returned
653 </p></li><li><p>
654 param: a pointer to the parameters to be sent.
655 </p></li><li><p>
656 data: a pointer to the data to be sent.
657 </p></li><li><p>
658 rparam: a pointer to a pointer which will be set to point to the returned
659 paramters. The caller of call_api() must deallocate this memory.
660 </p></li><li><p>
661 rdata: a pointer to a pointer which will be set to point to the returned
662 data. The caller of call_api() must deallocate this memory.
663 </p></li></ol></div><p>
664 These are the parameters which you ought to send, in the order of their
665 appearance in the parameter block:
666 </p><div class="orderedlist"><ol type="1"><li><p>
667 An unsigned 16 bit integer API number. You should set this value with
668 SSVAL(). I do not know where these numbers are described.
669 </p></li><li><p>
670 An ASCIIZ string describing the parameters to the API function as defined
671 in the LAN Manager documentation. The first parameter, which is the server
672 name, is ommited. This string is based uppon the API function as described
673 in the manual, not the data which is actually passed.
674 </p></li><li><p>
675 An ASCIIZ string describing the data structure which ought to be returned.
676 </p></li><li><p>
677 Any parameters which appear in the function call, as defined in the LAN
678 Manager API documentation, after the &quot;Server&quot; and up to and including the
679 &quot;uLevel&quot; parameters.
680 </p></li><li><p>
681 An unsigned 16 bit integer which gives the size in bytes of the buffer we
682 will use to receive the returned array of data structures. Presumably this
683 should be the same as mdrcnt. This value should be set with SSVAL().
684 </p></li><li><p>
685 An ASCIIZ string describing substructures which should be returned. If no
686 substructures apply, this string is of zero length.
687 </p></li></ol></div><p>
688 The code in client.c always calls call_api() with no data. It is unclear
689 when a non-zero length data buffer would be sent.
690 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858395"></a>Return value</h3></div></div><p>
691 The returned parameters (pointed to by rparam), in their order of appearance
692 are:</p><div class="orderedlist"><ol type="1"><li><p>
693 An unsigned 16 bit integer which contains the API function's return code.
694 This value should be read with SVAL().
695 </p></li><li><p>
696 An adjustment which tells the amount by which pointers in the returned
697 data should be adjusted. This value should be read with SVAL(). Basically,
698 the address of the start of the returned data buffer should have the returned
699 pointer value added to it and then have this value subtracted from it in
700 order to obtain the currect offset into the returned data buffer.
701 </p></li><li><p>
702 A count of the number of elements in the array of structures returned.
703 It is also possible that this may sometimes be the number of bytes returned.
704 </p></li></ol></div><p>
705 When call_api() returns, rparam points to the returned parameters. The
706 first if these is the result code. It will be zero if the API call
707 suceeded. This value by be read with &quot;SVAL(rparam,0)&quot;.
708 </p><p>
709 The second parameter may be read as &quot;SVAL(rparam,2)&quot;. It is a 16 bit offset
710 which indicates what the base address of the returned data buffer was when
711 it was built on the server. It should be used to correct pointer before
712 use.
713 </p><p>
714 The returned data buffer contains the array of returned data structures.
715 Note that all pointers must be adjusted before use. The function
716 fix_char_ptr() in client.c can be used for this purpose.
717 </p><p>
718 The third parameter (which may be read as &quot;SVAL(rparam,4)&quot;) has something to
719 do with indicating the amount of data returned or possibly the amount of
720 data which can be returned if enough buffer space is allowed.
721 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858481"></a>Code character table</h2></div></div><p>
722 Certain data structures are described by means of ASCIIz strings containing
723 code characters. These are the code characters:
724 </p><div class="orderedlist"><ol type="1"><li><p>
725 W a type byte little-endian unsigned integer
726 </p></li><li><p>
727 N a count of substructures which follow
728 </p></li><li><p>
729 D a four byte little-endian unsigned integer
730 </p></li><li><p>
731 B a byte (with optional count expressed as trailing ASCII digits)
732 </p></li><li><p>
733 z a four byte offset to a NULL terminated string
734 </p></li><li><p>
735 l a four byte offset to non-string user data
736 </p></li><li><p>
737 b an offset to data (with count expressed as trailing ASCII digits)
738 </p></li><li><p>
739 r pointer to returned data buffer???
740 </p></li><li><p>
741 L length in bytes of returned data buffer???
742 </p></li><li><p>
743 h number of bytes of information available???
744 </p></li></ol></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="parsing"></a>Chapter 6. The smb.conf file</h2></div><div><div class="author"><h3 class="author">Chris Hertel</h3></div></div><div><p class="pubdate">November 1997</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2857849">Lexical Analysis</a></dt><dd><dl><dt><a href="#id2857787">Handling of Whitespace</a></dt><dt><a href="#id2858749">Handling of Line Continuation</a></dt><dt><a href="#id2858813">Line Continuation Quirks</a></dt></dl></dd><dt><a href="#id2858913">Syntax</a></dt><dd><dl><dt><a href="#id2858982">About params.c</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2857849"></a>Lexical Analysis</h2></div></div><p>
745 Basically, the file is processed on a line by line basis. There are
746 four types of lines that are recognized by the lexical analyzer
747 (params.c):
748 </p><div class="orderedlist"><ol type="1"><li><p>
749 Blank lines - Lines containing only whitespace.
750 </p></li><li><p>
751 Comment lines - Lines beginning with either a semi-colon or a
752 pound sign (';' or '#').
753 </p></li><li><p>
754 Section header lines - Lines beginning with an open square bracket ('[').
755 </p></li><li><p>
756 Parameter lines - Lines beginning with any other character.
757 (The default line type.)
758 </p></li></ol></div><p>
759 The first two are handled exclusively by the lexical analyzer, which
760 ignores them. The latter two line types are scanned for
761 </p><div class="orderedlist"><ol type="1"><li><p>
762 - Section names
763 </p></li><li><p>
764 - Parameter names
765 </p></li><li><p>
766 - Parameter values
767 </p></li></ol></div><p>
768 These are the only tokens passed to the parameter loader
769 (loadparm.c). Parameter names and values are divided from one
770 another by an equal sign: '='.
771 </p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2857787"></a>Handling of Whitespace</h3></div></div><p>
772 Whitespace is defined as all characters recognized by the isspace()
773 function (see ctype(3C)) except for the newline character ('\n')
774 The newline is excluded because it identifies the end of the line.
775 </p><div class="orderedlist"><ol type="1"><li><p>
776 The lexical analyzer scans past white space at the beginning of a line.
777 </p></li><li><p>
778 Section and parameter names may contain internal white space. All
779 whitespace within a name is compressed to a single space character.
780 </p></li><li><p>
781 Internal whitespace within a parameter value is kept verbatim with
782 the exception of carriage return characters ('\r'), all of which
783 are removed.
784 </p></li><li><p>
785 Leading and trailing whitespace is removed from names and values.
786 </p></li></ol></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858749"></a>Handling of Line Continuation</h3></div></div><p>
787 Long section header and parameter lines may be extended across
788 multiple lines by use of the backslash character ('\\'). Line
789 continuation is ignored for blank and comment lines.
790 </p><p>
791 If the last (non-whitespace) character within a section header or on
792 a parameter line is a backslash, then the next line will be
793 (logically) concatonated with the current line by the lexical
794 analyzer. For example:
795 </p><pre class="programlisting">
796 param name = parameter value string \
797 with line continuation.
798 </pre><p>Would be read as</p><pre class="programlisting">
799 param name = parameter value string with line continuation.
800 </pre><p>
801 Note that there are five spaces following the word 'string',
802 representing the one space between 'string' and '\\' in the top
803 line, plus the four preceeding the word 'with' in the second line.
804 (Yes, I'm counting the indentation.)
805 </p><p>
806 Line continuation characters are ignored on blank lines and at the end
807 of comments. They are *only* recognized within section and parameter
808 lines.
809 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858813"></a>Line Continuation Quirks</h3></div></div><p>Note the following example:</p><pre class="programlisting">
810 param name = parameter value string \
812 with line continuation.
813 </pre><p>
814 The middle line is *not* parsed as a blank line because it is first
815 concatonated with the top line. The result is
816 </p><pre class="programlisting">
817 param name = parameter value string with line continuation.
818 </pre><p>The same is true for comment lines.</p><pre class="programlisting">
819 param name = parameter value string \
820 ; comment \
821 with a comment.
822 </pre><p>This becomes:</p><pre class="programlisting">
823 param name = parameter value string ; comment with a comment.
824 </pre><p>
825 On a section header line, the closing bracket (']') is considered a
826 terminating character, and the rest of the line is ignored. The lines
827 </p><pre class="programlisting">
828 [ section name ] garbage \
829 param name = value
830 </pre><p>are read as</p><pre class="programlisting">
831 [section name]
832 param name = value
833 </pre></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858913"></a>Syntax</h2></div></div><p>The syntax of the smb.conf file is as follows:</p><pre class="programlisting">
834 &lt;file&gt; :== { &lt;section&gt; } EOF
835 &lt;section&gt; :== &lt;section header&gt; { &lt;parameter line&gt; }
836 &lt;section header&gt; :== '[' NAME ']'
837 &lt;parameter line&gt; :== NAME '=' VALUE NL
838 </pre><p>Basically, this means that</p><div class="orderedlist"><ol type="1"><li><p>
839 a file is made up of zero or more sections, and is terminated by
840 an EOF (we knew that).
841 </p></li><li><p>
842 A section is made up of a section header followed by zero or more
843 parameter lines.
844 </p></li><li><p>
845 A section header is identified by an opening bracket and
846 terminated by the closing bracket. The enclosed NAME identifies
847 the section.
848 </p></li><li><p>
849 A parameter line is divided into a NAME and a VALUE. The *first*
850 equal sign on the line separates the NAME from the VALUE. The
851 VALUE is terminated by a newline character (NL = '\n').
852 </p></li></ol></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2858982"></a>About params.c</h3></div></div><p>
853 The parsing of the config file is a bit unusual if you are used to
854 lex, yacc, bison, etc. Both lexical analysis (scanning) and parsing
855 are performed by params.c. Values are loaded via callbacks to
856 loadparm.c.
857 </p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><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">Andrew Tridgell</h3></div></div><div><p class="pubdate">April 1995</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2858682">Introduction</a></dt><dt><a href="#id2858703">Usernames</a></dt><dt><a href="#id2858620">File Ownership</a></dt><dt><a href="#id2858644">Passwords</a></dt><dt><a href="#id2859208">Locking</a></dt><dt><a href="#id2859270">Deny Modes</a></dt><dt><a href="#id2859300">Trapdoor UIDs</a></dt><dt><a href="#id2859325">Port numbers</a></dt><dt><a href="#id2859371">Protocol Complexity</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858682"></a>Introduction</h2></div></div><p>
858 This is a short document that describes some of the issues that
859 confront a SMB implementation on unix, and how Samba copes with
860 them. They may help people who are looking at unix&lt;-&gt;PC
861 interoperability.
862 </p><p>
863 It was written to help out a person who was writing a paper on unix to
864 PC connectivity.
865 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858703"></a>Usernames</h2></div></div><p>
866 The SMB protocol has only a loose username concept. Early SMB
867 protocols (such as CORE and COREPLUS) have no username concept at
868 all. Even in later protocols clients often attempt operations
869 (particularly printer operations) without first validating a username
870 on the server.
871 </p><p>
872 Unix security is based around username/password pairs. A unix box
873 should not allow clients to do any substantive operation without some
874 sort of validation.
875 </p><p>
876 The problem mostly manifests itself when the unix server is in &quot;share
877 level&quot; security mode. This is the default mode as the alternative
878 &quot;user level&quot; security mode usually forces a client to connect to the
879 server as the same user for each connected share, which is
880 inconvenient in many sites.
881 </p><p>
882 In &quot;share level&quot; security the client normally gives a username in the
883 &quot;session setup&quot; protocol, but does not supply an accompanying
884 password. The client then connects to resources using the &quot;tree
885 connect&quot; protocol, and supplies a password. The problem is that the
886 user on the PC types the username and the password in different
887 contexts, unaware that they need to go together to give access to the
888 server. The username is normally the one the user typed in when they
889 &quot;logged onto&quot; the PC (this assumes Windows for Workgroups). The
890 password is the one they chose when connecting to the disk or printer.
891 </p><p>
892 The user often chooses a totally different username for their login as
893 for the drive connection. Often they also want to access different
894 drives as different usernames. The unix server needs some way of
895 divining the correct username to combine with each password.
896 </p><p>
897 Samba tries to avoid this problem using several methods. These succeed
898 in the vast majority of cases. The methods include username maps, the
899 service%user syntax, the saving of session setup usernames for later
900 validation and the derivation of the username from the service name
901 (either directly or via the user= option).
902 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858620"></a>File Ownership</h2></div></div><p>
903 The commonly used SMB protocols have no way of saying &quot;you can't do
904 that because you don't own the file&quot;. They have, in fact, no concept
905 of file ownership at all.
906 </p><p>
907 This brings up all sorts of interesting problems. For example, when
908 you copy a file to a unix drive, and the file is world writeable but
909 owned by another user the file will transfer correctly but will
910 receive the wrong date. This is because the utime() call under unix
911 only succeeds for the owner of the file, or root, even if the file is
912 world writeable. For security reasons Samba does all file operations
913 as the validated user, not root, so the utime() fails. This can stuff
914 up shared development diectories as programs like &quot;make&quot; will not get
915 file time comparisons right.
916 </p><p>
917 There are several possible solutions to this problem, including
918 username mapping, and forcing a specific username for particular
919 shares.
920 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2858644"></a>Passwords</h2></div></div><p>
921 Many SMB clients uppercase passwords before sending them. I have no
922 idea why they do this. Interestingly WfWg uppercases the password only
923 if the server is running a protocol greater than COREPLUS, so
924 obviously it isn't just the data entry routines that are to blame.
925 </p><p>
926 Unix passwords are case sensitive. So if users use mixed case
927 passwords they are in trouble.
928 </p><p>
929 Samba can try to cope with this by either using the &quot;password level&quot;
930 option which causes Samba to try the offered password with up to the
931 specified number of case changes, or by using the &quot;password server&quot;
932 option which allows Samba to do its validation via another machine
933 (typically a WinNT server).
934 </p><p>
935 Samba supports the password encryption method used by SMB
936 clients. Note that the use of password encryption in Microsoft
937 networking leads to password hashes that are &quot;plain text equivalent&quot;.
938 This means that it is *VERY* important to ensure that the Samba
939 smbpasswd file containing these password hashes is only readable
940 by the root user. See the documentation ENCRYPTION.txt for more
941 details.
942 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859208"></a>Locking</h2></div></div><p>
943 Since samba 2.2, samba supports other types of locking as well. This
944 section is outdated.
945 </p><p>
946 The locking calls available under a DOS/Windows environment are much
947 richer than those available in unix. This means a unix server (like
948 Samba) choosing to use the standard fcntl() based unix locking calls
949 to implement SMB locking has to improvise a bit.
950 </p><p>
951 One major problem is that dos locks can be in a 32 bit (unsigned)
952 range. Unix locking calls are 32 bits, but are signed, giving only a 31
953 bit range. Unfortunately OLE2 clients use the top bit to select a
954 locking range used for OLE semaphores.
955 </p><p>
956 To work around this problem Samba compresses the 32 bit range into 31
957 bits by appropriate bit shifting. This seems to work but is not
958 ideal. In a future version a separate SMB lockd may be added to cope
959 with the problem.
960 </p><p>
961 It also doesn't help that many unix lockd daemons are very buggy and
962 crash at the slightest provocation. They normally go mostly unused in
963 a unix environment because few unix programs use byte range
964 locking. The stress of huge numbers of lock requests from dos/windows
965 clients can kill the daemon on some systems.
966 </p><p>
967 The second major problem is the &quot;opportunistic locking&quot; requested by
968 some clients. If a client requests opportunistic locking then it is
969 asking the server to notify it if anyone else tries to do something on
970 the same file, at which time the client will say if it is willing to
971 give up its lock. Unix has no simple way of implementing
972 opportunistic locking, and currently Samba has no support for it.
973 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859270"></a>Deny Modes</h2></div></div><p>
974 When a SMB client opens a file it asks for a particular &quot;deny mode&quot; to
975 be placed on the file. These modes (DENY_NONE, DENY_READ, DENY_WRITE,
976 DENY_ALL, DENY_FCB and DENY_DOS) specify what actions should be
977 allowed by anyone else who tries to use the file at the same time. If
978 DENY_READ is placed on the file, for example, then any attempt to open
979 the file for reading should fail.
980 </p><p>
981 Unix has no equivalent notion. To implement this Samba uses either lock
982 files based on the files inode and placed in a separate lock
983 directory or a shared memory implementation. The lock file method
984 is clumsy and consumes processing and file resources,
985 the shared memory implementation is vastly prefered and is turned on
986 by default for those systems that support it.
987 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859300"></a>Trapdoor UIDs</h2></div></div><p>
988 A SMB session can run with several uids on the one socket. This
989 happens when a user connects to two shares with different
990 usernames. To cope with this the unix server needs to switch uids
991 within the one process. On some unixes (such as SCO) this is not
992 possible. This means that on those unixes the client is restricted to
993 a single uid.
994 </p><p>
995 Note that you can also get the &quot;trapdoor uid&quot; message for other
996 reasons. Please see the FAQ for details.
997 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859325"></a>Port numbers</h2></div></div><p>
998 There is a convention that clients on sockets use high &quot;unprivilaged&quot;
999 port numbers (&gt;1000) and connect to servers on low &quot;privilaged&quot; port
1000 numbers. This is enforced in Unix as non-root users can't open a
1001 socket for listening on port numbers less than 1000.
1002 </p><p>
1003 Most PC based SMB clients (such as WfWg and WinNT) don't follow this
1004 convention completely. The main culprit is the netbios nameserving on
1005 udp port 137. Name query requests come from a source port of 137. This
1006 is a problem when you combine it with the common firewalling technique
1007 of not allowing incoming packets on low port numbers. This means that
1008 these clients can't query a netbios nameserver on the other side of a
1009 low port based firewall.
1010 </p><p>
1011 The problem is more severe with netbios node status queries. I've
1012 found that WfWg, Win95 and WinNT3.5 all respond to netbios node status
1013 queries on port 137 no matter what the source port was in the
1014 request. This works between machines that are both using port 137, but
1015 it means it's not possible for a unix user to do a node status request
1016 to any of these OSes unless they are running as root. The answer comes
1017 back, but it goes to port 137 which the unix user can't listen
1018 on. Interestingly WinNT3.1 got this right - it sends node status
1019 responses back to the source port in the request.
1020 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859371"></a>Protocol Complexity</h2></div></div><p>
1021 There are many &quot;protocol levels&quot; in the SMB protocol. It seems that
1022 each time new functionality was added to a Microsoft operating system,
1023 they added the equivalent functions in a new protocol level of the SMB
1024 protocol to &quot;externalise&quot; the new capabilities.
1025 </p><p>
1026 This means the protocol is very &quot;rich&quot;, offering many ways of doing
1027 each file operation. This means SMB servers need to be complex and
1028 large. It also means it is very difficult to make them bug free. It is
1029 not just Samba that suffers from this problem, other servers such as
1030 WinNT don't support every variation of every call and it has almost
1031 certainly been a headache for MS developers to support the myriad of
1032 SMB calls that are available.
1033 </p><p>
1034 There are about 65 &quot;top level&quot; operations in the SMB protocol (things
1035 like SMBread and SMBwrite). Some of these include hundreds of
1036 sub-functions (SMBtrans has at least 120 sub-functions, like
1037 DosPrintQAdd and NetSessionEnum). All of them take several options
1038 that can change the way they work. Many take dozens of possible
1039 &quot;information levels&quot; that change the structures that need to be
1040 returned. Samba supports all but 2 of the &quot;top level&quot; functions. It
1041 supports only 8 (so far) of the SMBtrans sub-functions. Even NT
1042 doesn't support them all.
1043 </p><p>
1044 Samba currently supports up to the &quot;NT LM 0.12&quot; protocol, which is the
1045 one preferred by Win95 and WinNT3.5. Luckily this protocol level has a
1046 &quot;capabilities&quot; field which specifies which super-duper new-fangled
1047 options the server suports. This helps to make the implementation of
1048 this protocol level much easier.
1049 </p><p>
1050 There is also a problem with the SMB specications. SMB is a X/Open
1051 spec, but the X/Open book is far from ideal, and fails to cover many
1052 important issues, leaving much to the imagination. Microsoft recently
1053 renamed the SMB protocol CIFS (Common Internet File System) and have
1054 published new specifications. These are far superior to the old
1055 X/Open documents but there are still undocumented calls and features.
1056 This specification is actively being worked on by a CIFS developers
1057 mailing list hosted by Microsft.
1058 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="tracing"></a>Chapter 8. Tracing samba system calls</h2></div><div><div class="author"><h3 class="author">Andrew Tridgell</h3><div class="affiliation"><span class="orgname">Samba Team<br></span></div></div></div></div><p>
1059 This file describes how to do a system call trace on Samba to work out
1060 what its doing wrong. This is not for the faint of heart, but if you
1061 are reading this then you are probably desperate.
1062 </p><p>
1063 Actually its not as bad as the the above makes it sound, just don't
1064 expect the output to be very pretty :-)
1065 </p><p>
1066 Ok, down to business. One of the big advantages of unix systems is
1067 that they nearly all come with a system trace utility that allows you
1068 to monitor all system calls that a program is making. This is
1069 extremely using for debugging and also helps when trying to work out
1070 why something is slower than you expect. You can use system tracing
1071 without any special compilation options.
1072 </p><p>
1073 The system trace utility is called different things on different
1074 systems. On Linux systems its called strace. Under SunOS 4 its called
1075 trace. Under SVR4 style systems (including solaris) its called
1076 truss. Under many BSD systems its called ktrace.
1077 </p><p>
1078 The first thing you should do is read the man page for your native
1079 system call tracer. In the discussion below I'll assume its called
1080 strace as strace is the only portable system tracer (its available for
1081 free for many unix types) and its also got some of the nicest
1082 features.
1083 </p><p>
1084 Next, try using strace on some simple commands. For example, <b>strace
1085 ls</b> or <b>strace echo hello</b>.
1086 </p><p>
1087 You'll notice that it produces a LOT of output. It is showing you the
1088 arguments to every system call that the program makes and the
1089 result. Very little happens in a program without a system call so you
1090 get lots of output. You'll also find that it produces a lot of
1091 &quot;preamble&quot; stuff showing the loading of shared libraries etc. Ignore
1092 this (unless its going wrong!)
1093 </p><p>
1094 For example, the only line that really matters in the <b>strace echo
1095 hello</b> output is:
1096 </p><pre class="programlisting">
1097 write(1, &quot;hello\n&quot;, 6) = 6
1098 </pre><p>all the rest is just setting up to run the program.</p><p>
1099 Ok, now you're familiar with strace. To use it on Samba you need to
1100 strace the running smbd daemon. The way I tend ot use it is to first
1101 login from my Windows PC to the Samba server, then use smbstatus to
1102 find which process ID that client is attached to, then as root I do
1103 <b>strace -p PID</b> to attach to that process. I normally redirect the
1104 stderr output from this command to a file for later perusal. For
1105 example, if I'm using a csh style shell:
1106 </p><p><b>strace -f -p 3872 &gt;&amp; strace.out</b></p><p>or with a sh style shell:</p><p><b>strace -f -p 3872 &gt; strace.out 2&gt;&amp;1</b></p><p>
1107 Note the &quot;-f&quot; option. This is only available on some systems, and
1108 allows you to trace not just the current process, but any children it
1109 forks. This is great for finding printing problems caused by the
1110 &quot;print command&quot; being wrong.
1111 </p><p>
1112 Once you are attached you then can do whatever it is on the client
1113 that is causing problems and you will capture all the system calls
1114 that smbd makes.
1115 </p><p>
1116 So how do you interpret the results? Generally I search through the
1117 output for strings that I know will appear when the problem
1118 happens. For example, if I am having touble with permissions on a file
1119 I would search for that files name in the strace output and look at
1120 the surrounding lines. Another trick is to match up file descriptor
1121 numbers and &quot;follow&quot; what happens to an open file until it is closed.
1122 </p><p>
1123 Beyond this you will have to use your initiative. To give you an idea
1124 of what you are looking for here is a piece of strace output that
1125 shows that <tt>/dev/null</tt> is not world writeable, which
1126 causes printing to fail with Samba:
1127 </p><pre class="programlisting">
1128 [pid 28268] open(&quot;/dev/null&quot;, O_RDWR) = -1 EACCES (Permission denied)
1129 [pid 28268] open(&quot;/dev/null&quot;, O_WRONLY) = -1 EACCES (Permission denied)
1130 </pre><p>
1131 The process is trying to first open <tt>/dev/null</tt> read-write
1132 then read-only. Both fail. This means <tt>/dev/null</tt> has
1133 incorrect permissions.
1134 </p></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="ntdomain"></a>Chapter 9. NT Domain RPC's</h2></div><div><div class="author"><h3 class="author">Luke Leighton</h3><div class="affiliation"><div class="address"><p><tt>&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">Paul Ashton</h3><div class="affiliation"><div class="address"><p><tt>&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">Duncan Stansfield</h3><div class="affiliation"><div class="address"><p><tt>&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 class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2859563">Introduction</a></dt><dd><dl><dt><a href="#id2859980">Sources</a></dt><dt><a href="#id2860014">Credits</a></dt></dl></dd><dt><a href="#id2860053">Notes and Structures</a></dt><dd><dl><dt><a href="#id2860060">Notes</a></dt><dt><a href="#id2860137">Enumerations</a></dt><dt><a href="#id2860350">Structures</a></dt></dl></dd><dt><a href="#id2863307">MSRPC over Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2863320">MSRPC Pipes</a></dt><dt><a href="#id2863422">Header</a></dt><dt><a href="#id2864296">Tail</a></dt><dt><a href="#id2864342">RPC Bind / Bind Ack</a></dt><dt><a href="#id2864522">NTLSA Transact Named Pipe</a></dt><dt><a href="#id2864687">LSA Open Policy</a></dt><dt><a href="#id2864813">LSA Query Info Policy</a></dt><dt><a href="#id2864921">LSA Enumerate Trusted Domains</a></dt><dt><a href="#id2865012">LSA Open Secret</a></dt><dt><a href="#id2865122">LSA Close</a></dt><dt><a href="#id2865188">LSA Lookup SIDS</a></dt><dt><a href="#id2865399">LSA Lookup Names</a></dt></dl></dd><dt><a href="#id2865625">NETLOGON rpc Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2865786">LSA Request Challenge</a></dt><dt><a href="#id2865921">LSA Authenticate 2</a></dt><dt><a href="#id2866069">LSA Server Password Set</a></dt><dt><a href="#id2866185">LSA SAM Logon</a></dt><dt><a href="#id2866299">LSA SAM Logoff</a></dt></dl></dd><dt><a href="#id2866391">\\MAILSLOT\NET\NTLOGON</a></dt><dd><dl><dt><a href="#id2866408">Query for PDC</a></dt><dt><a href="#id2866670">SAM Logon</a></dt></dl></dd><dt><a href="#id2866996">SRVSVC Transact Named Pipe</a></dt><dd><dl><dt><a href="#id2867041">Net Share Enum</a></dt><dt><a href="#id2867261">Net Server Get Info</a></dt></dl></dd><dt><a href="#id2867378">Cryptographic side of NT Domain Authentication</a></dt><dd><dl><dt><a href="#id2867386">Definitions</a></dt><dt><a href="#id2867548">Protocol</a></dt><dt><a href="#id2867629">Comments</a></dt></dl></dd><dt><a href="#id2867679">SIDs and RIDs</a></dt><dd><dl><dt><a href="#id2867719">Well-known SIDs</a></dt><dt><a href="#id2868034">Well-known RIDS</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859563"></a>Introduction</h2></div></div><p>
1135 This document contains information to provide an NT workstation with login
1136 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.
1137 </p><p>
1138 It should be possible to select a domain instead of a workgroup (in the NT
1139 workstation's TCP/IP settings) and after the obligatory reboot, type in a
1140 username, password, select a domain and successfully log in. I would
1141 appreciate any feedback on your experiences with this process, and any
1142 comments, corrections and additions to this document.
1143 </p><p>
1144 The packets described here can be easily derived from (and are probably
1145 better understood using) Netmon.exe. You will need to use the version
1146 of Netmon that matches your system, in order to correctly decode the
1147 NETLOGON, lsarpc and srvsvc Transact pipes. This document is derived from
1148 NT Service Pack 1 and its corresponding version of Netmon. It is intended
1149 that an annotated packet trace be produced, which will likely be more
1150 instructive than this document.
1151 </p><p>
1152 Also needed, to fully implement NT Domain Login Services, is the
1153 document describing the cryptographic part of the NT authentication.
1154 This document is available from comp.protocols.smb; from the ntsecurity.net
1155 digest and from the samba digest, amongst other sources.
1156 </p><p>
1157 A copy is available from:
1158 </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>
1159 A c-code implementation, provided by <a href="mailto:linus@incolumitas.se" target="_top">Linus Nordberg</a>
1160 of this protocol is available from:
1161 </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>
1162 Also used to provide debugging information is the Check Build version of
1163 NT workstation, and enabling full debugging in NETLOGON. This is
1164 achieved by setting the following REG_SZ registry key to 0x1ffffff:
1165 </p><p><tt>HKLM\SYSTEM\CurrentControlSet\Services\Netlogon\Parameters</tt></p><p><span class="emphasis"><em>Incorrect direct editing of the registry can cause your
1166 machine to fail. Then again, so can incorrect implementation of this
1167 protocol. See &quot;Liability:&quot; above.</em></span></p><p>
1168 Bear in mind that each packet over-the-wire will have its origin in an
1169 API call. Therefore, there are likely to be structures, enumerations
1170 and defines that are usefully documented elsewhere.
1171 </p><p>
1172 This document is by no means complete or authoritative. Missing sections
1173 include, but are not limited to:
1174 </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
1175 workstation becomes a member of a domain (to be described later).
1176 Failure to return this error code will make the workstation report
1177 that it is already a member of the domain.</p></li><li><p>the cryptographic side of the NetrServerPasswordSet command,
1178 which would allow the workstation to change its password. This password is
1179 used to generate the long-term session key. [It is possible to reject this
1180 command, and keep the default workstation password].</p></li></ol></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2859980"></a>Sources</h3></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><h3 class="title"><a name="id2860014"></a>Credits</h3></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><h2 class="title" style="clear: both"><a name="id2860053"></a>Notes and Structures</h2></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2860060"></a>Notes</h3></div></div><div class="orderedlist"><ol type="1"><li><p>
1181 In the SMB Transact pipes, some &quot;Structures&quot;, described here, appear to be
1182 4-byte aligned with the SMB header, at their start. Exactly which
1183 &quot;Structures&quot; need aligning is not precisely known or documented.
1184 </p></li><li><p>
1185 In the UDP NTLOGON Mailslots, some &quot;Structures&quot;, described here, appear to be
1186 2-byte aligned with the start of the mailslot, at their start.
1187 </p></li><li><p>
1188 Domain SID is of the format S-revision-version-auth1-auth2...authN.
1189 e.g S-1-5-123-456-789-123-456. the 5 could be a sub-revision.
1190 </p></li><li><p>
1191 any undocumented buffer pointers must be non-zero if the string buffer it
1192 refers to contains characters. exactly what value they should be is unknown.
1193 0x0000 0002 seems to do the trick to indicate that the buffer exists. a
1194 NULL buffer pointer indicates that the string buffer is of zero length.
1195 If the buffer pointer is NULL, then it is suspected that the structure it
1196 refers to is NOT put into (or taken out of) the SMB data stream. This is
1197 empirically derived from, for example, the LSA SAM Logon response packet,
1198 where if the buffer pointer is NULL, the user information is not inserted
1199 into the data stream. Exactly what happens with an array of buffer pointers
1200 is not known, although an educated guess can be made.
1201 </p></li><li><p>
1202 an array of structures (a container) appears to have a count and a pointer.
1203 if the count is zero, the pointer is also zero. no further data is put
1204 into or taken out of the SMB data stream. if the count is non-zero, then
1205 the pointer is also non-zero. immediately following the pointer is the
1206 count again, followed by an array of container sub-structures. the count
1207 appears a third time after the last sub-structure.
1208 </p></li></ol></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2860137"></a>Enumerations</h3></div></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2860144"></a>MSRPC Header type</h4></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><h4 class="title"><a name="id2860218"></a>MSRPC Packet info</h4></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><h3 class="title"><a name="id2860350"></a>Structures</h3></div></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2860357"></a>VOID *</h4></div></div><p>sizeof VOID* is 32 bits.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2860368"></a>char</h4></div></div><p>sizeof char is 8 bits.</p></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2860380"></a>UTIME</h4></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><h4 class="title"><a name="id2860393"></a>NTTIME</h4></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><h4 class="title"><a name="id2860405"></a>DOM_SID (domain SID structure)</h4></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>
1209 </p></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2860499"></a>STR (string)</h4></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><h4 class="title"><a name="id2860513"></a>UNIHDR (unicode string header) </h4></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><h4 class="title"><a name="id2860569"></a>UNIHDR2 (unicode string header plus buffer pointer)</h4></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><h4 class="title"><a name="id2860611"></a>UNISTR (unicode string)</h4></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><h4 class="title"><a name="id2860639"></a>NAME (length-indicated unicode string)</h4></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><h4 class="title"><a name="id2860682"></a>UNISTR2 (aligned unicode string)</h4></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><h4 class="title"><a name="id2860768"></a>OBJ_ATTR (object attributes)</h4></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><h4 class="title"><a name="id2860861"></a>POL_HND (LSA policy handle)</h4></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><h4 class="title"><a name="id2860889"></a>DOM_SID2 (domain SID structure, SIDS stored in unicode)</h4></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><h4 class="title"><a name="id2860976"></a>DOM_RID (domain RID structure)</h4></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><h4 class="title"><a name="id2861045"></a>LOG_INFO (server, account, client structure)</h4></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><h4 class="title"><a name="id2861145"></a>CLNT_SRV (server, client names structure)</h4></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><h4 class="title"><a name="id2861223"></a>CREDS (credentials + time stamp)</h4></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><h4 class="title"><a name="id2861264"></a>CLNT_INFO2 (server, client structure, client credentials)</h4></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
1210 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><h4 class="title"><a name="id2861347"></a>CLNT_INFO (server, account, client structure, client credentials)</h4></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><h4 class="title"><a name="id2861400"></a>ID_INFO_1 (id info structure, auth level 1)</h4></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><h4 class="title"><a name="id2861570"></a>SAM_INFO (sam logon/logoff id info structure)</h4></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">
1211 switch (switch_value)
1212 case 1:
1214 ID_INFO_1 id_info_1;
1216 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2861675"></a>GID (group id info)</h4></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><h4 class="title"><a name="id2861713"></a>DOM_REF (domain reference info)</h4></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><h4 class="title"><a name="id2861857"></a>DOM_INFO (domain info, levels 3 and 5 are the same))</h4></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><h4 class="title"><a name="id2861970"></a>USER_INFO (user logon info)</h4></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><h4 class="title"><a name="id2862534"></a>SH_INFO_1_PTR (pointers to level 1 share info strings)</h4></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><h4 class="title"><a name="id2862629"></a>SH_INFO_1_STR (level 1 share info strings)</h4></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><h4 class="title"><a name="id2862671"></a>SHARE_INFO_1_CTR</h4></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><h4 class="title"><a name="id2862841"></a>SERVER_INFO_101</h4></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><h2 class="title" style="clear: both"><a name="id2863307"></a>MSRPC over Transact Named Pipe</h2></div></div><p>For details on the SMB Transact Named Pipe, see cifs6.txt</p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2863320"></a>MSRPC Pipes</h3></div></div><p>
1217 The MSRPC is conducted over an SMB Transact Pipe with a name of
1218 <tt>\PIPE\</tt>. You must first obtain a 16 bit file handle, by
1219 sending a SMBopenX with the pipe name <tt>\PIPE\srvsvc</tt> for
1220 example. You can then perform an SMB Trans,
1221 and must carry out an SMBclose on the file handle once you are finished.
1222 </p><p>
1223 Trans Requests must be sent with two setup UINT16s, no UINT16 params (none
1224 known about), and UINT8 data parameters sufficient to contain the MSRPC
1225 header, and MSRPC data. The first UINT16 setup parameter must be either
1226 0x0026 to indicate an RPC, or 0x0001 to indicate Set Named Pipe Handle
1227 state. The second UINT16 parameter must be the file handle for the pipe,
1228 obtained above.
1229 </p><p>
1230 The Data section for an API Command of 0x0026 (RPC pipe) in the Trans
1231 Request is the RPC Header, followed by the RPC Data. The Data section for
1232 an API Command of 0x0001 (Set Named Pipe Handle state) is two bytes. The
1233 only value seen for these two bytes is 0x00 0x43.
1234 </p><p>
1235 MSRPC Responses are sent as response data inside standard SMB Trans
1236 responses, with the MSRPC Header, MSRPC Data and MSRPC tail.
1237 </p><p>
1238 It is suspected that the Trans Requests will need to be at least 2-byte
1239 aligned (probably 4-byte). This is standard practice for SMBs. It is also
1240 independent of the observed 4-byte alignments with the start of the MSRPC
1241 header, including the 4-byte alignment between the MSRPC header and the
1242 MSRPC data.
1243 </p><p>
1244 First, an SMBtconX connection is made to the IPC$ share. The connection
1245 must be made using encrypted passwords, not clear-text. Then, an SMBopenX
1246 is made on the pipe. Then, a Set Named Pipe Handle State must be sent,
1247 after which the pipe is ready to accept API commands. Lastly, and SMBclose
1248 is sent.
1249 </p><p>
1250 To be resolved:
1251 </p><p>
1252 lkcl/01nov97 there appear to be two additional bytes after the null-terminated \PIPE\ name for the RPC pipe. Values seen so far are
1253 listed below:</p><pre class="programlisting">
1254 initial SMBopenX request: RPC API command 0x26 params:
1255 &quot;\\PIPE\\lsarpc&quot; 0x65 0x63; 0x72 0x70; 0x44 0x65;
1256 &quot;\\PIPE\\srvsvc&quot; 0x73 0x76; 0x4E 0x00; 0x5C 0x43;
1257 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2863422"></a>Header</h3></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
1258 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><h4 class="title"><a name="id2863612"></a>RPC_Packet for request, response, bind and bind acknowledgement</h4></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><h4 class="title"><a name="id2863746"></a>Interface identification</h4></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">
1259 abstract (0x4B324FC8, 0x01D31670, 0x475A7812, 0x88E16EBF, 0x00000003)
1260 transfer (0x8A885D04, 0x11C91CEB, 0x0008E89F, 0x6048102B, 0x00000002)
1261 </pre></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2863772"></a>RPC_Iface RW</h4></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><h4 class="title"><a name="id2863811"></a>RPC_ReqBind RW</h4></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><h4 class="title"><a name="id2863952"></a>RPC_Address RW</h4></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><h4 class="title"><a name="id2863992"></a>RPC_ResBind RW</h4></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><h4 class="title"><a name="id2864143"></a>RPC_ReqNorm RW</h4></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><h4 class="title"><a name="id2864215"></a>RPC_ResNorm RW</h4></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><h3 class="title"><a name="id2864296"></a>Tail</h3></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><h3 class="title"><a name="id2864342"></a>RPC Bind / Bind Ack</h3></div></div><p>
1262 RPC Binds are the process of associating an RPC pipe (e.g \PIPE\lsarpc)
1263 with a &quot;transfer syntax&quot; (see RPC_Iface structure). The purpose for doing
1264 this is unknown.
1265 </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
1266 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
1267 RPC_ResBind member transfersyntax is the same in the response as
1268 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
1269 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><h3 class="title"><a name="id2864522"></a>NTLSA Transact Named Pipe</h3></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><h3 class="title"><a name="id2864687"></a>LSA Open Policy</h3></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><h4 class="title"><a name="id2864701"></a>Request</h4></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><h4 class="title"><a name="id2864771"></a>Response</h4></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><h3 class="title"><a name="id2864813"></a>LSA Query Info Policy</h3></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><h4 class="title"><a name="id2864828"></a>Request</h4></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><h4 class="title"><a name="id2864866"></a>Response</h4></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">
1270 switch (info class)
1271 case 3:
1272 case 5:
1274 DOM_INFO domain info, levels 3 and 5 (are the same).
1277 return 0 - indicates success
1278 </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2864921"></a>LSA Enumerate Trusted Domains</h3></div></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2864928"></a>Request</h4></div></div><p>no extra data</p></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2864941"></a>Response</h4></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><h3 class="title"><a name="id2865012"></a>LSA Open Secret</h3></div></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2865020"></a>Request</h4></div></div><p>no extra data</p></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2865032"></a>Response</h4></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><h3 class="title"><a name="id2865122"></a>LSA Close</h3></div></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2865129"></a>Request</h4></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><h4 class="title"><a name="id2865157"></a>Response</h4></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><h3 class="title"><a name="id2865188"></a>LSA Lookup SIDS</h3></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><h4 class="title"><a name="id2865203"></a>Request</h4></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.
1279 </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><h4 class="title"><a name="id2865302"></a>Response</h4></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><h3 class="title"><a name="id2865399"></a>LSA Lookup Names</h3></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><h4 class="title"><a name="id2865413"></a>Request</h4></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><h4 class="title"><a name="id2865527"></a>Response</h4></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><h2 class="title" style="clear: both"><a name="id2865625"></a>NETLOGON rpc Transact Named Pipe</h2></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><h3 class="title"><a name="id2865786"></a>LSA Request Challenge</h3></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><h4 class="title"><a name="id2865818"></a>Request</h4></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><h4 class="title"><a name="id2865888"></a>Response</h4></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><h3 class="title"><a name="id2865921"></a>LSA Authenticate 2</h3></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><h4 class="title"><a name="id2865952"></a>Request</h4></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><h4 class="title"><a name="id2866021"></a>Response</h4></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><h3 class="title"><a name="id2866069"></a>LSA Server Password Set</h3></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><h4 class="title"><a name="id2866109"></a>Request</h4></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><h4 class="title"><a name="id2866151"></a>Response</h4></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><h3 class="title"><a name="id2866185"></a>LSA SAM Logon</h3></div></div><p><span class="emphasis"><em>
1280 Note: valid_user is True iff the username and password hash are valid for
1281 the requested domain.
1282 </em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2866200"></a>Request</h4></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><h4 class="title"><a name="id2866227"></a>Response</h4></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">
1283 if (valid_user)
1285 UINT16 3 - switch value indicating USER_INFO structure.
1286 VOID* non-zero - pointer to USER_INFO structure
1287 USER_INFO user logon information
1289 UINT32 1 - Authoritative response; 0 - Non-Auth?
1291 return 0 - indicates success
1293 else
1295 UINT16 0 - switch value. value to indicate no user presumed.
1296 VOID* 0x0000 0000 - indicates no USER_INFO structure.
1298 UINT32 1 - Authoritative response; 0 - Non-Auth?
1300 return 0xC000 0064 - NT_STATUS_NO_SUCH_USER.
1302 </pre></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2866299"></a>LSA SAM Logoff</h3></div></div><p><span class="emphasis"><em>
1303 Note: presumably, the SAM_INFO structure is validated, and a (currently
1304 undocumented) error code returned if the Logoff is invalid.
1305 </em></span></p><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2866314"></a>Request</h4></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><h4 class="title"><a name="id2866341"></a>Response</h4></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><h2 class="title" style="clear: both"><a name="id2866391"></a>\\MAILSLOT\NET\NTLOGON</h2></div></div><p><span class="emphasis"><em>
1306 Note: mailslots will contain a response mailslot, to which the response
1307 should be sent. the target NetBIOS name is REQUEST_NAME&lt;20&gt;, where
1308 REQUEST_NAME is the name of the machine that sent the request.
1309 </em></span></p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2866408"></a>Query for PDC</h3></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><h4 class="title"><a name="id2866422"></a>Request</h4></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><h4 class="title"><a name="id2866549"></a>Response</h4></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><h3 class="title"><a name="id2866670"></a>SAM Logon</h3></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><h4 class="title"><a name="id2866698"></a>Request</h4></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><h4 class="title"><a name="id2866881"></a>Response</h4></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><h2 class="title" style="clear: both"><a name="id2866996"></a>SRVSVC Transact Named Pipe</h2></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><h3 class="title"><a name="id2867041"></a>Net Share Enum</h3></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><h4 class="title"><a name="id2867062"></a>Request</h4></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><h4 class="title"><a name="id2867188"></a>Response</h4></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><h3 class="title"><a name="id2867261"></a>Net Server Get Info</h3></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><h4 class="title"><a name="id2867275"></a>Request</h4></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><h4 class="title"><a name="id2867316"></a>Response</h4></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><h2 class="title" style="clear: both"><a name="id2867378"></a>Cryptographic side of NT Domain Authentication</h2></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2867386"></a>Definitions</h3></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) ==
1310 pwdump(machine$) (initially) == md4(lmowf(unicode(machine)))
1311 </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><h3 class="title"><a name="id2867548"></a>Protocol</h3></div></div><pre class="programlisting">
1312 C-&gt;S ReqChal,Cc
1313 S-&gt;C Cs
1314 </pre><pre class="programlisting">
1315 C &amp; S compute session key Ks = E(PW[9..15],E(PW[0..6],Add(Cc,Cs)))
1316 </pre><pre class="programlisting">
1317 C: Rc = Cred(Ks,Cc)
1318 C-&gt;S Authenticate,Rc
1319 S: Rs = Cred(Ks,Cs), assert(Rc == Cred(Ks,Cc))
1320 S-&gt;C Rs
1321 C: assert(Rs == Cred(Ks,Cs))
1322 </pre><p>
1323 On joining the domain the client will optionally attempt to change its
1324 password and the domain controller may refuse to update it depending
1325 on registry settings. This will also occur weekly afterwards.
1326 </p><pre class="programlisting">
1327 C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc)
1328 C-&gt;S ServerPasswordSet,Rc',Tc,arc4(Ks[0..7,16],lmowf(randompassword())
1329 C: Rc = Cred(Ks,Rc+Tc+1)
1330 S: assert(Rc' == Cred(Ks,Rc+Tc)), Ts = Time()
1331 S: Rs' = Cred(Ks,Rs+Tc+1)
1332 S-&gt;C Rs',Ts
1333 C: assert(Rs' == Cred(Ks,Rs+Tc+1))
1334 S: Rs = Rs'
1335 </pre><p>
1336 User: U with password P wishes to login to the domain (incidental data
1337 such as workstation and domain omitted)
1338 </p><pre class="programlisting">
1339 C: Tc = Time(), Rc' = Cred(Ks,Rc+Tc)
1340 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)
1341 S: assert(Rc' == Cred(Ks,Rc+Tc)) assert(passwords match those in SAM)
1342 S: Ts = Time()
1343 </pre><pre class="programlisting">
1344 S-&gt;C Cred(Ks,Cred(Ks,Rc+Tc+1)),userinfo(logon script,UID,SIDs,etc)
1345 C: assert(Rs == Cred(Ks,Cred(Rc+Tc+1))
1346 C: Rc = Cred(Ks,Rc+Tc+1)
1347 </pre></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2867629"></a>Comments</h3></div></div><p>
1348 On first joining the domain the session key could be computed by
1349 anyone listening in on the network as the machine password has a well
1350 known value. Until the machine is rebooted it will use this session
1351 key to encrypt NT and LM one way functions of passwords which are
1352 password equivalents. Any user who logs in before the machine has been
1353 rebooted a second time will have their password equivalent exposed. Of
1354 course the new machine password is exposed at this time anyway.
1355 </p><p>
1356 None of the returned user info such as logon script, profile path and
1357 SIDs *appear* to be protected by anything other than the TCP checksum.
1358 </p><p>
1359 The server time stamps appear to be ignored.
1360 </p><p>
1361 The client sends a ReturnAuthenticator in the SamLogon request which I
1362 can't find a use for. However its time is used as the timestamp
1363 returned by the server.
1364 </p><p>
1365 The password OWFs should NOT be sent over the network reversibly
1366 encrypted. They should be sent using ARC4(Ks,md4(owf)) with the server
1367 computing the same function using the owf values in the SAM.
1368 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2867679"></a>SIDs and RIDs</h2></div></div><p>
1369 SIDs and RIDs are well documented elsewhere.
1370 </p><p>
1371 A SID is an NT Security ID (see DOM_SID structure). They are of the form:
1372 </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>
1373 currently, the SID revision is 1.
1374 The Sub-Authorities are known as Relative IDs (RIDs).
1375 </p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2867719"></a>Well-known SIDs</h3></div></div><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2867726"></a>Universal well-known SIDs</h4></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><h4 class="title"><a name="id2867852"></a>NT well-known SIDs</h4></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><h3 class="title"><a name="id2868034"></a>Well-known RIDS</h3></div></div><p>
1376 A RID is a sub-authority value, as part of either a SID, or in the case
1377 of Group RIDs, part of the DOM_GID structure, in the USER_INFO_1
1378 structure, in the LSA SAM Logon response.
1379 </p><div class="sect3" lang="en"><div class="titlepage"><div><h4 class="title"><a name="id2868049"></a>Well-known RID users</h4></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><h4 class="title"><a name="id2868097"></a>Well-known RID groups</h4></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><h4 class="title"><a name="id2868157"></a>Well-known RID aliases</h4></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><h2 class="title"><a name="printing"></a>Chapter 10. Samba Printing Internals</h2></div><div><div class="author"><h3 class="author">Gerald Carter</h3></div></div><div><p class="pubdate">October 2002</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2859754">Abstract</a></dt><dt><a href="#id2859770">
1380 Printing Interface to Various Back ends
1381 </a></dt><dt><a href="#id2859712">
1382 Print Queue TDB's
1383 </a></dt><dt><a href="#id2868639">
1384 ChangeID and Client Caching of Printer Information
1385 </a></dt><dt><a href="#id2868653">
1386 Windows NT/2K Printer Change Notify
1387 </a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859754"></a>Abstract</h2></div></div><p>
1388 The purpose of this document is to provide some insight into
1389 Samba's printing functionality and also to describe the semantics
1390 of certain features of Windows client printing.
1391 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859770"></a>
1392 Printing Interface to Various Back ends
1393 </h2></div></div><p>
1394 Samba uses a table of function pointers to seven functions. The
1395 function prototypes are defined in the <tt>printif</tt> structure declared
1396 in <tt>printing.h</tt>.
1397 </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>
1398 Currently there are only two printing back end implementations
1399 defined.
1400 </p><div class="itemizedlist"><ul type="disc"><li><p>a generic set of functions for working with standard UNIX
1401 printing subsystems</p></li><li><p>a set of CUPS specific functions (this is only enabled if
1402 the CUPS libraries were located at compile time).</p></li></ul></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2859712"></a>
1403 Print Queue TDB's
1404 </h2></div></div><p>
1405 Samba provides periodic caching of the output from the &quot;lpq command&quot;
1406 for performance reasons. This cache time is configurable in seconds.
1407 Obviously the longer the cache time the less often smbd will be
1408 required to exec a copy of lpq. However, the accuracy of the print
1409 queue contents displayed to clients will be diminished as well.
1410 </p><p>
1411 The list of currently opened print queue TDB's can be found
1412 be examining the list of tdb_print_db structures ( see print_db_head
1413 in printing.c ). A queue TDB is opened using the wrapper function
1414 printing.c:get_print_db_byname(). The function ensures that smbd
1415 does not open more than MAX_PRINT_DBS_OPEN in an effort to prevent
1416 a large print server from exhausting all available file descriptors.
1417 If the number of open queue TDB's exceeds the MAX_PRINT_DBS_OPEN
1418 limit, smbd falls back to a most recently used algorithm for maintaining
1419 a list of open TDB's.
1420 </p><p>
1421 There are two ways in which a a print job can be entered into
1422 a print queue's TDB. The first is to submit the job from a Windows
1423 client which will insert the job information directly into the TDB.
1424 The second method is to have the print job picked up by executing the
1425 &quot;lpq command&quot;.
1426 </p><pre class="programlisting">
1427 /* included from printing.h */
1428 struct printjob {
1429 pid_t pid; /* which process launched the job */
1430 int sysjob; /* the system (lp) job number */
1431 int fd; /* file descriptor of open file if open */
1432 time_t starttime; /* when the job started spooling */
1433 int status; /* the status of this job */
1434 size_t size; /* the size of the job so far */
1435 int page_count; /* then number of pages so far */
1436 BOOL spooled; /* has it been sent to the spooler yet? */
1437 BOOL smbjob; /* set if the job is a SMB job */
1438 fstring filename; /* the filename used to spool the file */
1439 fstring jobname; /* the job name given to us by the client */
1440 fstring user; /* the user who started the job */
1441 fstring queuename; /* service number of printer for this job */
1442 NT_DEVICEMODE *nt_devmode;
1444 </pre><p>
1445 The current manifestation of the printjob structure contains a field
1446 for the UNIX job id returned from the &quot;lpq command&quot; and a Windows job
1447 ID (32-bit bounded by PRINT_MAX_JOBID). When a print job is returned
1448 by the &quot;lpq command&quot; that does not match an existing job in the queue's
1449 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
1450 the id reported by lpq.
1451 </p><p>
1452 In order to match a 32-bit Windows jobid onto a 16-bit lanman print job
1453 id, smbd uses an in memory TDB to match the former to a number appropriate
1454 for old lanman clients.
1455 </p><p>
1456 When updating a print queue, smbd will perform the following
1457 steps ( refer to <tt>print.c:print_queue_update()</tt> ):
1458 </p><div class="orderedlist"><ol type="1"><li><p>Check to see if another smbd is currently in
1459 the process of updating the queue contents by checking the pid
1460 stored in <tt>LOCK/<i><tt>printer_name</tt></i></tt>.
1461 If so, then do not update the TDB.</p></li><li><p>Lock the mutex entry in the TDB and store our own pid.
1462 Check that this succeeded, else fail.</p></li><li><p>Store the updated time stamp for the new cache
1463 listing</p></li><li><p>Retrieve the queue listing via &quot;lpq command&quot;</p></li><li><pre class="programlisting">
1464 foreach job in the queue
1466 if the job is a UNIX job, create a new entry;
1467 if the job has a Windows based jobid, then
1469 Lookup the record by the jobid;
1470 if the lookup failed, then
1471 treat it as a UNIX job;
1472 else
1473 update the job status only
1475 }</pre></li><li><p>Delete any jobs in the TDB that are not
1476 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>
1477 Note that it is the contents of this TDB that is returned to Windows
1478 clients and not the actual listing from the &quot;lpq command&quot;.
1479 </p><p>
1480 The NT_DEVICEMODE stored as part of the printjob structure is used to
1481 store a pointer to a non-default DeviceMode associated with the print
1482 job. The pointer will be non-null when the client included a Device
1483 Mode in the OpenPrinterEx() call and subsequently submitted a job for
1484 printing on that same handle. If the client did not include a Device
1485 Mode in the OpenPrinterEx() request, the nt_devmode field is NULL
1486 and the job has the printer's device mode associated with it by default.
1487 </p><p>
1488 Only non-default Device Mode are stored with print jobs in the print
1489 queue TDB. Otherwise, the Device Mode is obtained from the printer
1490 object when the client issues a GetJob(level == 2) request.
1491 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2868639"></a>
1492 ChangeID and Client Caching of Printer Information
1493 </h2></div></div><p>
1494 [To be filled in later]
1495 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2868653"></a>
1496 Windows NT/2K Printer Change Notify
1497 </h2></div></div><p>
1498 When working with Windows NT+ clients, it is possible for a
1499 print server to use RPC to send asynchronous change notification
1500 events to clients for certain printer and print job attributes.
1501 This can be useful when the client needs to know that a new
1502 job has been added to the queue for a given printer or that the
1503 driver for a printer has been changed. Note that this is done
1504 entirely orthogonal to cache updates based on a new ChangeID for
1505 a printer object.
1506 </p><p>
1507 The basic set of RPC's used to implement change notification are
1508 </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>
1509 One additional RPC is available to a server, but is never used by the
1510 Windows spooler service:
1511 </p><div class="itemizedlist"><ul type="disc"><li><p>RouteReplyPrinter()</p></li></ul></div><p>
1512 The opnum for all of these RPC's are defined in include/rpc_spoolss.h
1513 </p><p>
1514 Windows NT print servers use a bizarre method of sending print
1515 notification event to clients. The process of registering a new change
1516 notification handle is as follows. The 'C' is for client and the
1517 'S' is for server. All error conditions have been eliminated.
1518 </p><pre class="programlisting">
1519 C: Obtain handle to printer or to the printer
1520 server via the standard OpenPrinterEx() call.
1521 S: Respond with a valid handle to object
1523 C: Send a RFFPCN request with the previously obtained
1524 handle with either (a) set of flags for change events
1525 to monitor, or (b) a PRINTER_NOTIFY_OPTIONS structure
1526 containing the event information to monitor. The windows
1527 spooler has only been observed to use (b).
1528 S: The &lt;* another missing word*&gt; opens a new TCP session to the client (thus requiring
1529 all print clients to be CIFS servers as well) and sends
1530 a ReplyOpenPrinter() request to the client.
1531 C: The client responds with a printer handle that can be used to
1532 send event notification messages.
1533 S: The server replies success to the RFFPCN request.
1535 C: The windows spooler follows the RFFPCN with a RFNPCN
1536 request to fetch the current values of all monitored
1537 attributes.
1538 S: The server replies with an array SPOOL_NOTIFY_INFO_DATA
1539 structures (contained in a SPOOL_NOTIFY_INFO structure).
1541 C: If the change notification handle is ever released by the
1542 client via a FCPCN request, the server sends a ReplyClosePrinter()
1543 request back to the client first. However a request of this
1544 nature from the client is often an indication that the previous
1545 notification event was not marshalled correctly by the server
1546 or a piece of data was wrong.
1547 S: The server closes the internal change notification handle
1548 (POLICY_HND) and does not send any further change notification
1549 events to the client for that printer or job.
1550 </pre><p>
1551 The current list of notification events supported by Samba can be
1552 found by examining the internal tables in srv_spoolss_nt.c
1553 </p><div class="itemizedlist"><ul type="disc"><li><p>printer_notify_table[]</p></li><li><p>job_notify_table[]</p></li></ul></div><p>
1554 When an event occurs that could be monitored, smbd sends a message
1555 to itself about the change. The list of events to be transmitted
1556 are queued by the smbd process sending the message to prevent an
1557 overload of TDB usage and the internal message is sent during smbd's
1558 idle loop (refer to printing/notify.c and the functions
1559 send_spoolss_notify2_msg() and print_notify_send_messages() ).
1560 </p><p>
1561 The decision of whether or not the change is to be sent to connected
1562 clients is made by the routine which actually sends the notification.
1563 ( refer to srv_spoolss_nt.c:recieve_notify2_message() ).
1564 </p><p>
1565 Because it possible to receive a listing of multiple changes for
1566 multiple printers, the notification events must be split into
1567 categories by the printer name. This makes it possible to group
1568 multiple change events to be sent in a single RPC according to the
1569 printer handle obtained via a ReplyOpenPrinter().
1570 </p><p>
1571 The actual change notification is performed using the RRPCN request
1572 RPC. This packet contains
1573 </p><div class="itemizedlist"><ul type="disc"><li><p>the printer handle registered with the
1574 client's spooler on which the change occurred</p></li><li><p>The change_low value which was sent as part
1575 of the last RFNPCN request from the client</p></li><li><p>The SPOOL_NOTIFY_INFO container with the event
1576 information</p></li></ul></div><p>
1577 A <tt>SPOOL_NOTIFY_INFO</tt> contains:
1578 </p><div class="itemizedlist"><ul type="disc"><li><p>the version and flags field are predefined
1579 and should not be changed</p></li><li><p>The count field is the number of entries
1580 in the SPOOL_NOTIFY_INFO_DATA array</p></li></ul></div><p>
1581 The <tt>SPOOL_NOTIFY_INFO_DATA</tt> entries contain:
1582 </p><div class="itemizedlist"><ul type="disc"><li><p>The type defines whether or not this event
1583 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
1584 attribute</p></li><li><p>The enc_type defines the size of the structure for marshalling
1585 and unmarshalling</p></li><li><p>(a) the id must be 0 for a printer event on a printer handle.
1586 (b) the id must be the job id for an event on a printer job
1587 (c) the id must be the matching number of the printer index used
1588 in the response packet to the RFNPCN when using a print server
1589 handle for notification. Samba currently uses the snum of
1590 the printer for this which can break if the list of services
1591 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,
1592 (b) the size in bytes of the security descriptor, or (c) 0 for
1593 data values.</p></li></ul></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="wins"></a>Chapter 11. Samba WINS Internals</h2></div><div><div class="author"><h3 class="author">Gerald Carter</h3></div></div><div><p class="pubdate">October 2002</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2868400">WINS Failover</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2868400"></a>WINS Failover</h2></div></div><p>
1594 The current Samba codebase possesses the capability to use groups of WINS
1595 servers that share a common namespace for NetBIOS name registration and
1596 resolution. The formal parameter syntax is
1597 </p><pre class="programlisting">
1598 WINS_SERVER_PARAM = SERVER [ SEPARATOR SERVER_LIST ]
1599 WINS_SERVER_PARAM = &quot;wins server&quot;
1600 SERVER = ADDR[:TAG]
1601 ADDR = ip_addr | fqdn
1602 TAG = string
1603 SEPARATOR = comma | \s+
1604 SERVER_LIST = SERVER [ SEPARATOR SERVER_LIST ]
1605 </pre><p>
1606 A simple example of a valid wins server setting is
1607 </p><pre class="programlisting">
1608 [global]
1609 wins server = 192.168.1.2 192.168.1.3
1610 </pre><p>
1611 In the event that no TAG is defined in for a SERVER in the list, smbd assigns a default
1612 TAG of &quot;*&quot;. A TAG is used to group servers of a shared NetBIOS namespace together. Upon
1613 startup, nmbd will attempt to register the netbios name value with one server in each
1614 tagged group.
1615 </p><p>
1616 An example using tags to group WINS servers together is show here. Note that the use of
1617 interface names in the tags is only by convention and is not a technical requirement.
1618 </p><pre class="programlisting">
1619 [global]
1620 wins server = 192.168.1.2:eth0 192.168.1.3:eth0 192.168.2.2:eth1
1621 </pre><p>
1622 Using this configuration, nmbd would attempt to register the server's NetBIOS name
1623 with one WINS server in each group. Because the &quot;eth0&quot; group has two servers, the
1624 second server would only be used when a registration (or resolution) request to
1625 the first server in that group timed out.
1626 </p><p>
1627 NetBIOS name resolution follows a similar pattern as name registration. When resolving
1628 a NetBIOS name via WINS, smbd and other Samba programs will attempt to query a single WINS
1629 server in a tagged group until either a positive response is obtained at least once or
1630 until a server from every tagged group has responded negatively to the name query request.
1631 If a timeout occurs when querying a specific WINS server, that server is marked as down to
1632 prevent further timeouts and the next server in the WINS group is contacted. Once marked as
1633 dead, Samba will not attempt to contact that server for name registration/resolution queries
1634 for a period of 10 minutes.
1635 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="sam"></a>Chapter 12. The Upcoming SAM System</h2></div><div><div class="author"><h3 class="author">Andrew Bartlett</h3></div></div><div><p class="pubdate">1 October 2002</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2869126">Security in the 'new SAM'</a></dt><dt><a href="#id2869257">Standalone from UNIX</a></dt><dt><a href="#id2869292">Handles and Races in the new SAM</a></dt><dt><a href="#id2869361">Layers</a></dt><dd><dl><dt><a href="#id2869368">Application</a></dt><dt><a href="#id2869384">SAM Interface</a></dt><dt><a href="#id2869412">SAM Modules</a></dt></dl></dd><dt><a href="#id2869434">SAM Modules</a></dt><dd><dl><dt><a href="#id2869441">Special Module: sam_passdb</a></dt><dt><a href="#id2869459">sam_ads</a></dt></dl></dd><dt><a href="#id2869498">Memory Management</a></dt><dt><a href="#id2869589">Testing</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869126"></a>Security in the 'new SAM'</h2></div></div><p>One of the biggest problems with passdb is it's implementation of
1636 'security'. Access control is on a 'are you root at the moment' basis,
1637 and it has no concept of NT ACLs. Things like ldapsam had to add
1638 'magic' 'are you root' checks.</p><p>We took this very seriously when we started work, and the new structure
1639 is designed with this in mind, from the ground up. Each call to the SAM
1640 has a NT_TOKEN and (if relevant) an 'access desired'. This is either
1641 provided as a parameter, or implicitly supplied by the object being
1642 accessed.</p><p>
1643 For example, when you call
1644 </p><pre class="programlisting">
1645 NTSTATUS sam_get_account_by_name(const SAM_CONTEXT *context, const
1646 NT_USER_TOKEN *access_token, uint32 access_desired, const char *domain,
1647 const char *name, SAM_ACCOUNT_HANDLE **account)
1648 </pre><p>
1649 The context can be NULL (and is used to allow import/export by setting
1650 up 2 contexts, and allowing calls on both simultaneously)
1651 </p><p>
1652 The access token *must* be specified. Normally the user's token out of
1653 current_user, this can also be a global 'system' context.
1654 </p><p>
1655 The access desired is as per the ACL, for passing to the seaccess stuff.
1656 </p><p>
1657 The domain/username are standard. Even if we only have one domain,
1658 keeping this ensures that we don't get 'unqualified' usernames (same
1659 problem as we had with unqualified SIDs).
1660 </p><p>
1661 We return a 'handle'. This is opaque to the rest of Samba, but is
1662 operated on by get/set routines, all of which return NTSTATUS.
1663 </p><p>
1664 The access checking is done by the SAM module. The reason it is not
1665 done 'above' the interface is to ensure a 'choke point'. I put a lot of
1666 effort into the auth subsystem to ensure we never 'accidentally' forgot
1667 to check for null passwords, missed a restriction etc. I intend the SAM
1668 to be written with the same caution.
1669 </p><p>
1670 The reason the access checking is not handled by the interface itself is
1671 due to the different implementations it make take on. For example, on
1672 ADS, you cannot set a password over a non-SSL connection. Other
1673 backends may have similar requirements - we need to leave this policy up
1674 to the modules. They will naturally have access to 'helper' procedures
1675 and good examples to avoid mishaps.
1676 </p><p>
1677 (Furthermore, some backends my actually chose to push the whole ACL
1678 issue to the remote server, and - assuming ldap for this example - bind
1679 as the user directly)
1680 </p><p>
1681 Each returned handle has an internal 'access permitted', which allows
1682 the 'get' and 'set' routines to return 'ACCESS_DENIED' for things that
1683 were not able to be retrieved from the backend. This removes the need
1684 to specify the NT_TOKEN on every operation, and allows for 'object not
1685 present' to be easily distinguished from 'access denied'.
1686 </p><p>
1687 When you 'set' an object (calling sam_update_account) the internal
1688 details are again used. Each change that has been made to the object
1689 has been flagged, so as to avoid race conditions (on unmodified
1690 components) and to avoid violating any extra ACL requirements on the
1691 actual data store (like the LDAP server).
1692 </p><p>
1693 Finally, we have generic get_sec_desc() and set_sec_desc() routines to
1694 allow external ACL manipulation. These do lookups based on SID.
1695 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869257"></a>Standalone from UNIX</h2></div></div><p>
1696 One of the primary tenants of the 'new SAM' is that it would not attempt
1697 to deal with 'what unix id for that'. This would be left to the 'SMS'
1698 (Sid Mapping System') or SID farm, and probably administered via
1699 winbind. We have had constructive discussion on how 'basic' unix
1700 accounts like 'root' would be handled, and we think this can work.
1701 Accounts not preexisting in unix would be served up via winbind.
1702 </p><p>
1703 This is an *optional* part, and my preferred end-game. We have a fare
1704 way to go before things like winbind up to it however.
1705 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869292"></a>Handles and Races in the new SAM</h2></div></div><p>
1706 One of the things that the 'new SAM' work has tried to face is both
1707 compatibility with existing code, and a closer alignment to the SAMR
1708 interface. I consider SAMR to be a 'primary customer' to the this work,
1709 because if we get alignment with that wrong, things get more, rather
1710 than less complex. Also, most other parts of Samba are much more
1711 flexible with what they can allow.
1712 </p><p>
1713 In any case, that was a decision taken as to how the general design
1714 would progress. BTW, my understanding of SAMR may be completely flawed.
1715 </p><p>
1716 One of the most race-prone areas of the new code is the conflicting
1717 update problem. We have taken two approaches:
1718 </p><div class="itemizedlist"><ul type="disc"><li><p>'Not conflicting' conflicts. Due to the way usrmgr operates, it will
1719 open a user, display all the properties and *save* them all, even if you
1720 don't change any.
1721 </p><p>
1722 For this, see what I've done in rpc_server/srv_samr_util.c. I intend
1723 to take this one step further, and operate on the 'handle' that the
1724 values were read from. This should mean that we only update things that
1725 have *really* changed.
1726 </p></li><li><p>
1727 'conflicting' updates: Currently we don't deal with this (in passdb
1728 or the new sam stuff), but the design is sufficiently flexible to 'deny'
1729 a second update. I don't foresee locking records however.
1730 </p></li></ul></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869361"></a>Layers</h2></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2869368"></a>Application</h3></div></div><p>
1731 This is where smbd, samtest and whatever end-user replacement we have
1732 for pdbedit sits. They use only the SAM interface, and do not get
1733 'special knowledge' of what is below them.
1734 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2869384"></a>SAM Interface</h3></div></div><p>
1735 This level 'owns' the various handle structures, the get/set routines on
1736 those structures and provides the public interface. The application
1737 layer may initialize a 'context' to be passed to all interface routines,
1738 else a default, self-initialising context will be supplied. This layser
1739 finds the appropriate backend module for the task, and tries very hard
1740 not to need to much 'knowledge'. It should just provide the required
1741 abstraction to the modules below, and arrange for their initial loading.
1742 </p><p>
1743 We could possibly add ACL checking at this layer, to avoid discrepancies
1744 in implementation modules.
1745 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2869412"></a>SAM Modules</h3></div></div><p>
1746 These do not communicate with the application directly, only by setting
1747 values in the handles, and receiving requests from the interface. These
1748 modules are responsible for translating values from the handle's
1749 .private into (say) an LDAP modification list. The module is expected
1750 to 'know' things like it's own domain SID, domain name, and any other
1751 state attached to the SAM. Simpler modules may call back to some helper
1752 routine.
1753 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869434"></a>SAM Modules</h2></div></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2869441"></a>Special Module: sam_passdb</h3></div></div><p>
1754 In order for there to be a smooth transition, kai is writing a module
1755 that reads existing passdb backends, and translates them into SAM
1756 replies. (Also pulling data from the account policy DB etc). We also
1757 intend to write a module that does the reverse - gives the SAM a passdb
1758 interface.
1759 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2869459"></a>sam_ads</h3></div></div><p>
1760 This is the first of the SAM modules to be committed to the tree -
1761 mainly because I needed to coordinate work with metze (who authored most
1762 of it). This module aims to use Samba's libads code to provide an
1763 Active Directory LDAP client, suitable for use on a mixed-mode DC.
1764 While it is currently being tested against Win2k servers (with a
1765 password in the smb.conf file) it is expected to eventually use a
1766 (possibly modified) OpenLDAP server. We hope that this will assist in
1767 the construction of an Samba AD DC.
1768 </p><p>
1769 We also intend to construct a Samba 2.2/3.0 compatible ldap module,
1770 again using libads code.
1771 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869498"></a>Memory Management</h2></div></div><p>
1772 The 'new SAM' development effort also concerned itself with getting a
1773 sane implementation of memory management. It was decided that we would
1774 be (as much as possible) talloc based, using an 'internal talloc
1775 context' on many objects. That is, the creation of an object would
1776 initiate it's own internal talloc context, and this would be used for
1777 all operations on that object. Much of this is already implemented in
1778 passdb. Also, like passdb, it will be possible to specify that some
1779 object actually be created on a specified context.
1780 </p><p>
1781 Memory management is important here because the APIs in the 'new SAM' do
1782 not use 'pdb_init()' or an equivalent. They always allocate new
1783 objects. Enumeration's are slightly different, and occur on a supplied
1784 context that 'owns' the entire list, rather than per-element. (the
1785 enumeration functions return an array of all elements - not full handles
1786 just basic (and public) info) Likewise for things that fill in a char
1788 </p><p>For example:</p><pre class="programlisting">
1789 NTSTATUS sam_lookup_sid(const SAM_CONTEXT *context, const NT_USER_TOKEN
1790 *access_token, TALLOC_CTX *mem_ctx, const DOM_SID *sid, char **name,
1791 uint32 *type)
1792 </pre><p>Takes a context to allocate the 'name' on, while:</p><pre class="programlisting">
1793 NTSTATUS sam_get_account_by_sid(const SAM_CONTEXT *context, const
1794 NT_USER_TOKEN *access_token, uint32 access_desired, const DOM_SID
1795 *accountsid, SAM_ACCOUNT_HANDLE **account)
1796 </pre><p>Allocates a handle and stores the allocation context on that handle.</p><p>I think that the following:</p><pre class="programlisting">
1797 NTSTATUS sam_enum_accounts(const SAM_CONTEXT *context, const
1798 NT_USER_TOKEN *access_token, const DOM_SID *domainsid, uint16 acct_ctrl,
1799 int32 *account_count, SAM_ACCOUNT_ENUM **accounts)
1800 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869589"></a>Testing</h2></div></div><p>
1801 Testing is vital in any piece of software, and Samba is certainly no
1802 exception. In designing this new subsystem, we have taken care to ensure
1803 it is easily tested, independent of outside protocols.
1804 </p><p>
1805 To this end, Jelmer has constructed 'samtest'.
1806 </p><p>
1807 This utility (see torture/samtest.c) is structured like rpcclient, but
1808 instead operates on the SAM subsystem. It creates a 'custom' SAM
1809 context, that may be distinct from the default values used by the rest
1810 of the system, and can load a separate configuration file.
1811 </p><p>
1812 A small number of commands are currently implemented, but these have
1813 already proved vital in testing. I expect SAM module authors will find
1814 it particularly valuable.
1815 </p><p>Example useage:</p><p><tt>$</tt> <b>bin/samtest</b></p><pre class="programlisting">
1816 &gt; context ads:ldap://192.168.1.96
1817 </pre><p>
1818 (this loads a new context, using the new ADS module. The parameter is
1819 the 'location' of the ldap server)
1820 </p><pre class="programlisting">
1821 &gt; lookup_name DOMAIN abartlet
1822 </pre><p>
1823 (returns a sid).
1824 </p><p>
1825 Because the 'new SAM' is NT ACL based, there will be a command to
1826 specify an arbitrary NT ACL, but for now it uses 'system' by default.
1827 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="pwencrypt"></a>Chapter 13. LanMan and NT Password Encryption</h2></div><div><div class="author"><h3 class="author">Jeremy Allison</h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><br>
1828 <tt>&lt;<a href="mailto:samba@samba.org">samba@samba.org</a>&gt;</tt><br>
1829 </p></div></div></div></div><div><p class="pubdate">19 Apr 1999</p></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2869092">Introduction</a></dt><dt><a href="#id2868961">How does it work?</a></dt><dt><a href="#id2869678">The smbpasswd file</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869092"></a>Introduction</h2></div></div><p>With the development of LanManager and Windows NT
1830 compatible password encryption for Samba, it is now able
1831 to validate user connections in exactly the same way as
1832 a LanManager or Windows NT server.</p><p>This document describes how the SMB password encryption
1833 algorithm works and what issues there are in choosing whether
1834 you want to use it. You should read it carefully, especially
1835 the part about security and the &quot;PROS and CONS&quot; section.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2868961"></a>How does it work?</h2></div></div><p>LanManager encryption is somewhat similar to UNIX
1836 password encryption. The server uses a file containing a
1837 hashed value of a user's password. This is created by taking
1838 the user's plaintext password, capitalising it, and either
1839 truncating to 14 bytes or padding to 14 bytes with null bytes.
1840 This 14 byte value is used as two 56 bit DES keys to encrypt
1841 a 'magic' eight byte value, forming a 16 byte value which is
1842 stored by the server and client. Let this value be known as
1843 the &quot;hashed password&quot;.</p><p>Windows NT encryption is a higher quality mechanism,
1844 consisting of doing an MD4 hash on a Unicode version of the user's
1845 password. This also produces a 16 byte hash value that is
1846 non-reversible.</p><p>When a client (LanManager, Windows for WorkGroups, Windows
1847 95 or Windows NT) wishes to mount a Samba drive (or use a Samba
1848 resource), it first requests a connection and negotiates the
1849 protocol that the client and server will use. In the reply to this
1850 request the Samba server generates and appends an 8 byte, random
1851 value - this is stored in the Samba server after the reply is sent
1852 and is known as the &quot;challenge&quot;. The challenge is different for
1853 every client connection.</p><p>The client then uses the hashed password (16 byte values
1854 described above), appended with 5 null bytes, as three 56 bit
1855 DES keys, each of which is used to encrypt the challenge 8 byte
1856 value, forming a 24 byte value known as the &quot;response&quot;.</p><p>In the SMB call SMBsessionsetupX (when user level security
1857 is selected) or the call SMBtconX (when share level security is
1858 selected), the 24 byte response is returned by the client to the
1859 Samba server. For Windows NT protocol levels the above calculation
1860 is done on both hashes of the user's password and both responses are
1861 returned in the SMB call, giving two 24 byte values.</p><p>The Samba server then reproduces the above calculation, using
1862 its own stored value of the 16 byte hashed password (read from the
1863 <tt>smbpasswd</tt> file - described later) and the challenge
1864 value that it kept from the negotiate protocol reply. It then checks
1865 to see if the 24 byte value it calculates matches the 24 byte value
1866 returned to it from the client.</p><p>If these values match exactly, then the client knew the
1867 correct password (or the 16 byte hashed value - see security note
1868 below) and is thus allowed access. If not, then the client did not
1869 know the correct password and is denied access.</p><p>Note that the Samba server never knows or stores the cleartext
1870 of the user's password - just the 16 byte hashed values derived from
1871 it. Also note that the cleartext password or 16 byte hashed values
1872 are never transmitted over the network - thus increasing security.</p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869678"></a>The smbpasswd file</h2></div></div><a name="SMBPASSWDFILEFORMAT"></a><p>In order for Samba to participate in the above protocol
1873 it must be able to look up the 16 byte hashed values given a user name.
1874 Unfortunately, as the UNIX password value is also a one way hash
1875 function (ie. it is impossible to retrieve the cleartext of the user's
1876 password given the UNIX hash of it), a separate password file
1877 containing this 16 byte value must be kept. To minimise problems with
1878 these two password files, getting out of sync, the UNIX <tt>
1879 /etc/passwd</tt> and the <tt>smbpasswd</tt> file,
1880 a utility, <b>mksmbpasswd.sh</b>, is provided to generate
1881 a smbpasswd file from a UNIX <tt>/etc/passwd</tt> file.
1882 </p><p>To generate the smbpasswd file from your <tt>/etc/passwd
1883 </tt> file use the following command:</p><p><tt>$ </tt><b><tt>cat /etc/passwd | mksmbpasswd.sh
1884 &gt; /usr/local/samba/private/smbpasswd</tt></b></p><p>If you are running on a system that uses NIS, use</p><p><tt>$ </tt><b><tt>ypcat passwd | mksmbpasswd.sh
1885 &gt; /usr/local/samba/private/smbpasswd</tt></b></p><p>The <b>mksmbpasswd.sh</b> program is found in
1886 the Samba source directory. By default, the smbpasswd file is
1887 stored in :</p><p><tt>/usr/local/samba/private/smbpasswd</tt></p><p>The owner of the <tt>/usr/local/samba/private/</tt>
1888 directory should be set to root, and the permissions on it should
1889 be set to 0500 (<b>chmod 500 /usr/local/samba/private</b>).
1890 </p><p>Likewise, the smbpasswd file inside the private directory should
1891 be owned by root and the permissions on is should be set to 0600
1892 (<b>chmod 600 smbpasswd</b>).</p><p>The format of the smbpasswd file is (The line has been
1893 wrapped here. It should appear as one entry per line in
1894 your smbpasswd file.)</p><pre class="programlisting">
1895 username:uid:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
1896 [Account type]:LCT-&lt;last-change-time&gt;:Long name
1897 </pre><p>Although only the <i><tt>username</tt></i>,
1898 <i><tt>uid</tt></i>, <i><tt>
1899 XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX</tt></i>,
1900 [<i><tt>Account type</tt></i>] and <i><tt>
1901 last-change-time</tt></i> sections are significant
1902 and are looked at in the Samba code.</p><p>It is <span class="emphasis"><em>VITALLY</em></span> important that there by 32
1903 'X' characters between the two ':' characters in the XXX sections -
1904 the smbpasswd and Samba code will fail to validate any entries that
1905 do not have 32 characters between ':' characters. The first XXX
1906 section is for the Lanman password hash, the second is for the
1907 Windows NT version.</p><p>When the password file is created all users have password entries
1908 consisting of 32 'X' characters. By default this disallows any access
1909 as this user. When a user has a password set, the 'X' characters change
1910 to 32 ascii hexadecimal digits (0-9, A-F). These are an ascii
1911 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
1912 using vi, and replace the first 11 characters with the ascii text
1913 <tt>&quot;NO PASSWORD&quot;</tt> (minus the quotes).</p><p>For example, to clear the password for user bob, his smbpasswd file
1914 entry would look like :</p><pre class="programlisting">
1915 bob:100:NO PASSWORDXXXXXXXXXXXXXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:
1916 [U ]:LCT-00000000:Bob's full name:/bobhome:/bobshell
1917 </pre><p>If you are allowing users to use the smbpasswd command to set
1918 their own passwords, you may want to give users NO PASSWORD initially
1919 so they do not have to enter a previous password when changing to their
1920 new password (not recommended). In order for you to allow this the
1921 <b>smbpasswd</b> program must be able to connect to the
1922 <b>smbd</b> daemon as that user with no password. Enable this
1923 by adding the line :</p><p><b>null passwords = yes</b></p><p>to the [global] section of the smb.conf file (this is why
1924 the above scenario is not recommended). Preferably, allocate your
1925 users a default password to begin with, so you do not have
1926 to enable this on your server.</p><p><span class="emphasis"><em>Note : </em></span>This file should be protected very
1927 carefully. Anyone with access to this file can (with enough knowledge of
1928 the protocols) gain access to your SMB server. The file is thus more
1929 sensitive than a normal unix <tt>/etc/passwd</tt> file.</p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="modules"></a>Chapter 14. Modules</h2></div><div><div class="author"><h3 class="author">Jelmer Vernooij</h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt>&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 class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2870133">Advantages</a></dt><dt><a href="#id2869868">Loading modules</a></dt><dd><dl><dt><a href="#id2869901">Static modules</a></dt><dt><a href="#id2870337">Shared modules</a></dt></dl></dd><dt><a href="#id2870365">Writing modules</a></dt><dd><dl><dt><a href="#id2870425">Static/Shared selection in configure.in</a></dt></dl></dd></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2870133"></a>Advantages</h2></div></div><p>
1930 The new modules system has the following advantages:
1931 </p><table class="simplelist" border="0" summary="Simple list"><tr><td>Transparent loading of static and shared modules (no need
1932 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><h2 class="title" style="clear: both"><a name="id2869868"></a>Loading modules</h2></div></div><p>
1933 Some subsystems in samba use different backends. These backends can be
1934 either statically linked in to samba or available as a plugin. A subsystem
1935 should have a function that allows a module to register itself. For example,
1936 the passdb subsystem has:
1937 </p><pre class="programlisting">
1938 BOOL smb_register_passdb(const char *name, pdb_init_function init, int version);
1939 </pre><p>
1940 This function will be called by the initialisation function of the module to
1941 register itself.
1942 </p><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2869901"></a>Static modules</h3></div></div><p>
1943 The modules system compiles a list of initialisation functions for the
1944 static modules of each subsystem. This is a define. For example,
1945 it is here currently (from <tt>include/config.h</tt>):
1946 </p><pre class="programlisting">
1947 /* Static init functions */
1948 #define static_init_pdb { pdb_mysql_init(); pdb_ldap_init(); pdb_smbpasswd_init(); pdb_tdbsam_init(); pdb_guest_init();}
1949 </pre><p>
1950 These functions should be called before the subsystem is used. That
1951 should be done when the subsystem is initialised or first used.
1952 </p></div><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2870337"></a>Shared modules</h3></div></div><p>
1953 If a subsystem needs a certain backend, it should check if it has
1954 already been registered. If the backend hasn't been registered already,
1955 the subsystem should call smb_probe_module(char *subsystem, char *backend).
1956 This function tries to load the correct module from a certain path
1957 ($LIBDIR/subsystem/backend.so). If the first character in 'backend'
1958 is a slash, smb_probe_module() tries to load the module from the
1959 absolute path specified in 'backend'.
1960 </p><p>After smb_probe_module() has been executed, the subsystem
1961 should check again if the module has been registered.
1962 </p></div></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2870365"></a>Writing modules</h2></div></div><p>
1963 Each module has an initialisation function. For modules that are
1964 included with samba this name is '<i><tt>subsystem</tt></i>_<i><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()).
1965 The prototype for these functions is:
1966 </p><pre class="programlisting">
1967 int init_module(void);
1968 </pre><p>This function should call one or more
1969 registration functions. The function should return non-zero on success and zero on
1970 failure.</p><p>For example, pdb_ldap_init() contains: </p><pre class="programlisting">
1971 int pdb_ldap_init(void)
1973 smb_register_passdb(&quot;ldapsam&quot;, pdb_init_ldapsam, PASSDB_INTERFACE_VERSION);
1974 smb_register_passdb(&quot;ldapsam_nua&quot;, pdb_init_ldapsam_nua, PASSDB_INTERFACE_VERSION);
1975 return TRUE;
1977 </pre><div class="sect2" lang="en"><div class="titlepage"><div><h3 class="title"><a name="id2870425"></a>Static/Shared selection in configure.in</h3></div></div><p>
1978 Some macros in configure.in generate the various defines and substs that
1979 are necessary for the system to work correct. All modules that should
1980 be built by default have to be added to the variable 'default_modules'.
1981 For example, if ldap is found, pdb_ldap is added to this variable.
1982 </p><p>
1983 On the bottom of configure.in, SMB_MODULE() should be called
1984 for each module and SMB_SUBSYSTEM() for each subsystem.
1985 </p><p>Syntax:</p><pre class="programlisting">
1986 SMB_MODULE(<i><tt>subsystem</tt></i>_<i><tt>backend</tt></i>, <i><tt>object files</tt></i>, <i><tt>plugin name</tt></i>, <i><tt>subsystem name</tt></i>, <i><tt>static_action</tt></i>, <i><tt>shared_action</tt></i>)
1987 SMB_SUBSYSTEM(<i><tt>subsystem</tt></i>)
1988 </pre><p>Also, make sure to add the correct directives to
1989 <tt>Makefile.in</tt>. <i><tt>@SUBSYSTEM_STATIC@</tt></i>
1990 will be replaced with a list of objects files of the modules that need to
1991 be linked in statically. <i><tt>@SUBSYSTEM_MODULES@</tt></i> will
1992 be replaced with the names of the plugins to build.
1993 </p><p>You must make sure all .c files that contain defines that can
1994 be changed by ./configure are rebuilded in the 'modules_clean' make target.
1995 Practically, this means all c files that contain <b>static_init_subsystem;</b> calls need to be rebuilded.
1996 </p></div></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="rpc-plugin"></a>Chapter 15. RPC Pluggable Modules</h2></div><div><div class="author"><h3 class="author">Anthony Liguori</h3><div class="affiliation"><span class="orgname">IBM<br></span><div class="address"><p><tt>&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">Jelmer Vernooij</h3><div class="affiliation"><span class="orgname">Samba Team<br></span><div class="address"><p><tt>&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 class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2869935">About</a></dt><dt><a href="#id2869954">General Overview</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869935"></a>About</h2></div></div><p>
1997 This document describes how to make use the new RPC Pluggable Modules features
1998 of Samba 3.0. This architecture was added to increase the maintainability of
1999 Samba allowing RPC Pipes to be worked on separately from the main CVS branch.
2000 The RPM architecture will also allow third-party vendors to add functionality
2001 to Samba through plug-ins.
2002 </p></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2869954"></a>General Overview</h2></div></div><p>
2003 When an RPC call is sent to smbd, smbd tries to load a shared library by the
2004 name <tt>librpc_&lt;pipename&gt;.so</tt> to handle the call if
2005 it doesn't know how to handle the call internally. For instance, LSA calls
2006 are handled by <tt>librpc_lsass.so</tt>..
2007 These shared libraries should be located in the <tt>&lt;sambaroot&gt;/lib/rpc</tt>. smbd then attempts to call the init_module function within
2008 the shared library. Check the chapter on modules for more information.
2009 </p><p>
2010 In the init_module function, the library should call
2011 rpc_pipe_register_commands(). This function takes the following arguments:
2012 </p><pre class="programlisting">
2013 int rpc_pipe_register_commands(const char *clnt, const char *srv,
2014 const struct api_struct *cmds, int size);
2015 </pre><div class="variablelist"><dl><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>
2016 See rpc_server/srv_reg.c and rpc_server/srv_reg_nt.c for a small example of
2017 how to use this library.
2018 </p></div></div><div class="chapter" lang="en"><div class="titlepage"><div><h2 class="title"><a name="Packaging"></a>Chapter 16. Notes to packagers</h2></div><div><div class="author"><h3 class="author">Jelmer Vernooij</h3></div></div></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><a href="#id2870644">Versioning</a></dt><dt><a href="#id2870677">Modules</a></dt></dl></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2870644"></a>Versioning</h2></div></div><p>Please, please update the version number in
2019 <tt>source/include/version.h</tt> to include the versioning of your package. This makes it easier to distinguish standard samba builds
2020 from custom-build samba builds (distributions often patch packages). For
2021 example, a good version would be: </p><pre class="programlisting">
2022 Version 2.999+3.0.alpha21-5 for Debian
2023 </pre></div><div class="sect1" lang="en"><div class="titlepage"><div><h2 class="title" style="clear: both"><a name="id2870677"></a>Modules</h2></div></div><p>Samba now has support for building parts of samba as plugins. This
2024 makes it possible to, for example, put ldap or mysql support in a seperate
2025 package, thus making it possible to have a normal samba package not
2026 depending on ldap or mysql. To build as much parts of samba
2027 as a plugin, run: </p><pre class="programlisting">
2028 ./configure --with-shared-modules=rpc,vfs,auth,pdb,charset
2029 </pre></div></div></div></body></html>