1<HTML> 2<HEAD> 3<TITLE> 4[Chapter 3] 3.3 An Introduction to SMB/CIFS</title><META NAME="DC.title" CONTENT=""><META NAME="DC.creator" CONTENT=""><META NAME="DC.publisher" CONTENT="O'Reilly & Associates, Inc."><META NAME="DC.date" CONTENT="1999-11-05T21:31:30Z"><META NAME="DC.type" CONTENT="Text.Monograph"><META NAME="DC.format" CONTENT="text/html" SCHEME="MIME"><META NAME="DC.source" CONTENT="" SCHEME="ISBN"><META NAME="DC.language" CONTENT="en-US"><META NAME="generator" CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"></head> 5<BODY BGCOLOR="#FFFFFF" TEXT="#000000" link="#990000" vlink="#0000CC"> 6<table BORDER="0" CELLPADDING="0" CELLSPACING="0" width="90%"> 7<tr> 8<td width="25%" valign="TOP"> 9<img hspace=10 vspace=10 src="gifs/samba.s.gif" 10alt="Using Samba" align=left valign=top border=0> 11</td> 12<td height="105" valign="TOP"> 13<br> 14<H2>Using Samba</H2> 15<font size="-1"> 16Robert Eckstein, David Collier-Brown, Peter Kelly 17<br>1st Edition November 1999 18<br>1-56592-449-5, Order Number: 4495 19<br>416 pages, $34.95 20</font> 21<p> <a href="http://www.oreilly.com/catalog/samba/">Buy the hardcopy</a> 22<p><a href="index.html">Table of Contents</a> 23</td> 24</tr> 25</table> 26<hr size=1 noshade> 27<!--sample chapter begins --> 28 29<center> 30<DIV CLASS="htmlnav"> 31<TABLE WIDTH="515" BORDER="0" CELLSPACING="0" CELLPADDING="0"> 32<TR> 33<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="172"> 34<A CLASS="sect1" HREF="ch03_02.html" TITLE="3.2 Setting Up Windows NT 4.0 Computers"> 35<IMG SRC="gifs/txtpreva.gif" ALT="Previous: 3.2 Setting Up Windows NT 4.0 Computers" BORDER="0"></a></td><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="171"> 36<B> 37<FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1"> 38<A CLASS="chapter" REL="up" HREF="ch03_01.html" TITLE="3. Configuring Windows Clients"> 39Chapter 3<br> 40Configuring Windows Clients</a></font></b></td><TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="172"> 41<A CLASS="chapter" HREF="ch04_01.html" TITLE="4. Disk Shares "> 42<IMG SRC="gifs/txtnexta.gif" ALT="Next: 4. Disk Shares " BORDER="0"></a></td></tr></table> <hr noshade size=1></center> 43</div> 44<blockquote> 45<div> 46<H2 CLASS="sect1"> 47<A CLASS="title" NAME="ch03-64069"> 483.3 An Introduction to SMB/CIFS</a></h2><P CLASS="para">We'll wrap up this chapter with a short tutorial on SMB/CIFS. SMB/CIFS is the protocol that Windows 95/98 and NT machines use to communicate with the Samba server and each other. At a high level, the SMB protocol suite is relatively simple. It includes commands for all of the file and print operations that you might do on a local disk or printer, such as:</p><UL CLASS="itemizedlist"> 49<LI CLASS="listitem"> 50<P CLASS="para"> 51<A CLASS="listitem" NAME="ch03-pgfId-942445"> 52</a> Opening and closing a file</p></li><LI CLASS="listitem"> 53<P CLASS="para"> 54<A CLASS="listitem" NAME="ch03-pgfId-942446"> 55</a> Creating and deleting files and directories</p></li><LI CLASS="listitem"> 56<P CLASS="para"> 57<A CLASS="listitem" NAME="ch03-pgfId-942447"> 58</a> Reading and writing a file</p></li><LI CLASS="listitem"> 59<P CLASS="para"> 60<A CLASS="listitem" NAME="ch03-pgfId-942853"> 61</a> Searching for files</p></li><LI CLASS="listitem"> 62<P CLASS="para"> 63<A CLASS="listitem" NAME="ch03-pgfId-942448"> 64</a> Queueing and dequeueing files to a print spool</p></li></ul><P CLASS="para"> 65Each of these operations can be encoded into an SMB message and transmitted to and from a server. The original name SMB comes from their data format: these are versions of the standard DOS system-call data structures, or <I CLASS="firstterm"> 66Server Message Blocks</i>, redesigned for transmitting to another machine across a network.</p><DIV CLASS="sect2"> 67<H3 CLASS="sect2"> 68<A CLASS="title" NAME="ch03-pgfId-942451"> 693.3.1 SMB Format</a></h3><P CLASS="para">Richard Sharpe of the Samba team defines SMB as a "request-response" protocol.[<A CLASS="footnote" HREF="#ch03-pgfId-942928">4</a>] In effect, this means that a client sends an SMB request to a server, and the server sends an SMB response back to the client. Rarely does a server send a message that is not in response to a client.</p><BLOCKQUOTE CLASS="footnote"> 70<DIV CLASS="footnote"> 71<P CLASS="para"> 72<A CLASS="footnote" NAME="ch03-pgfId-942928">[4]</a> See <I CLASS="filename"> 73<a href="http://anu.samba.org/cifs/docs/what-is-smb.html">http://anu.samba.org/cifs/docs/what-is-smb.html</i></a> for Richard's excellent summary of SMB.</p></div></blockquote><P CLASS="para"> 74An SMB message is not as complex as you might think. Let's take a closer look at the internal structure of such a message. It can be broken down into two parts: the <I CLASS="firstterm"> 75header</i>, which is a fixed size, and the <I CLASS="firstterm"> 76command string</i>, whose size can vary dramatically based on the contents of the message.</p><DIV CLASS="sect3"> 77<H4 CLASS="sect3"> 78<A CLASS="title" NAME="ch03-pgfId-942453"> 793.3.1.1 SMB header format</a></h4><P CLASS="para"> 80<A CLASS="xref" HREF="ch03_03.html#ch03-31015"> 81Table 3.1</a> shows the format of an SMB header. SMB commands are not required to use all the fields in the SMB header. For example, when a client first attempts to connect to a server, it does not yet have a tree identifier (TID) value - one is assigned after it successfully connects - so a null TID (0xFFFF) is placed in its header field. Other fields may be padded with zeros when not used. </p><P CLASS="para"> 82The fields of the SMB header are listed in <A CLASS="xref" HREF="ch03_03.html#ch03-31015"> 83Table 3.1</a>. </p><br> 84<TABLE CLASS="table" BORDER="1" CELLPADDING="3"> 85<CAPTION CLASS="table"> 86<A CLASS="title" NAME="ch03-31015"> 87Table 3.1: SMB Header Fields </a></caption><THEAD CLASS="thead"> 88<TR CLASS="row" VALIGN="TOP"> 89<TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 90<P CLASS="para"> 91Field</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 92<P CLASS="para"> 93Size (bytes)</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 94<P CLASS="para"> 95Description</p></th></tr></thead><TBODY CLASS="tbody"> 96<TR CLASS="row" VALIGN="TOP"> 97<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 98<P CLASS="para"> 99<CODE CLASS="literal"> 1000xFF 'SMB'</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 101<P CLASS="para"> 102<CODE CLASS="literal"> 1031</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 104<P CLASS="para">Protocol identifier</p></td></tr><TR CLASS="row" VALIGN="TOP"> 105<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 106<P CLASS="para"> 107<CODE CLASS="literal"> 108COM</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 109<P CLASS="para"> 110<CODE CLASS="literal"> 1111</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 112<P CLASS="para"> 113Command code, from 0x00 to 0xFF</p></td></tr><TR CLASS="row" VALIGN="TOP"> 114<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 115<P CLASS="para"> 116<CODE CLASS="literal"> 117RCLS</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 118<P CLASS="para"> 119<CODE CLASS="literal"> 1201</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 121<P CLASS="para"> 122Error class</p></td></tr><TR CLASS="row" VALIGN="TOP"> 123<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 124<P CLASS="para"> 125<CODE CLASS="literal"> 126REH</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 127<P CLASS="para"> 128<CODE CLASS="literal"> 1291</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 130<P CLASS="para"> 131Reserved</p></td></tr><TR CLASS="row" VALIGN="TOP"> 132<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 133<P CLASS="para"> 134<CODE CLASS="literal"> 135ERR</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 136<P CLASS="para"> 137<CODE CLASS="literal"> 1382</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 139<P CLASS="para"> 140Error code</p></td></tr><TR CLASS="row" VALIGN="TOP"> 141<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 142<P CLASS="para"> 143<CODE CLASS="literal"> 144REB</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 145<P CLASS="para"> 146<CODE CLASS="literal"> 1471</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 148<P CLASS="para"> 149Reserved</p></td></tr><TR CLASS="row" VALIGN="TOP"> 150<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 151<P CLASS="para"> 152<CODE CLASS="literal"> 153RES</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 154<P CLASS="para"> 155<CODE CLASS="literal"> 15614</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 157<P CLASS="para"> 158Reserved</p></td></tr><TR CLASS="row" VALIGN="TOP"> 159<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 160<P CLASS="para"> 161<CODE CLASS="literal"> 162TID</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 163<P CLASS="para"> 164<CODE CLASS="literal"> 1652</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 166<P CLASS="para"> 167Tree identifier; a unique ID for a resource in use by client</p></td></tr><TR CLASS="row" VALIGN="TOP"> 168<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 169<P CLASS="para"> 170<CODE CLASS="literal"> 171PID</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 172<P CLASS="para"> 173<CODE CLASS="literal"> 1742</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 175<P CLASS="para"> 176Caller process ID</p></td></tr><TR CLASS="row" VALIGN="TOP"> 177<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 178<P CLASS="para"> 179<CODE CLASS="literal"> 180UID</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 181<P CLASS="para"> 182<CODE CLASS="literal"> 1832</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 184<P CLASS="para"> 185User identifier</p></td></tr><TR CLASS="row" VALIGN="TOP"> 186<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 187<P CLASS="para"> 188<CODE CLASS="literal"> 189MID</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 190<P CLASS="para"> 191<CODE CLASS="literal"> 1922</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 193<P CLASS="para"> 194Multiplex identifier; used to route requests inside a process</p></td></tr></tbody></table></div><DIV CLASS="sect3"> 195<H4 CLASS="sect3"> 196<A CLASS="title" NAME="ch03-pgfId-942527"> 1973.3.1.2 SMB command format</a></h4><P CLASS="para"> 198<I CLASS="firstterm"> 199</i>Immediately after the header is a variable number of bytes that constitute an SMB command or reply. Each command, such as Open File (COM field identifier: <CODE CLASS="literal">SMBopen</code>) or Get Print Queue (<CODE CLASS="literal">SMBsplretq</code>), has its own set of parameters and data. Like the SMB header fields, not all of the command fields need to be filled, depending on the specific command. For example, the Get Server Attributes (<CODE CLASS="literal">SMBdskattr</code>) command sets the WCT and BCC fields to zero. The fields of the command segment are shown in <A CLASS="xref" HREF="ch03_03.html#ch03-38178"> 200Table 3.2</a>. </p><br> 201<TABLE CLASS="table" BORDER="1" CELLPADDING="3"> 202<CAPTION CLASS="table"> 203<A CLASS="title" NAME="ch03-38178"> 204Table 3.2: SMB Command Contents </a></caption><THEAD CLASS="thead"> 205<TR CLASS="row" VALIGN="TOP"> 206<TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 207<P CLASS="para"> 208Field</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 209<P CLASS="para"> 210Size in Bytes</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 211<P CLASS="para"> 212Description</p></th></tr></thead><TBODY CLASS="tbody"> 213<TR CLASS="row" VALIGN="TOP"> 214<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 215<P CLASS="para"> 216<CODE CLASS="literal"> 217WCT</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 218<P CLASS="para"> 219<CODE CLASS="literal"> 2201</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 221<P CLASS="para"> 222<I CLASS="firstterm"> 223</i>Word count</p></td></tr><TR CLASS="row" VALIGN="TOP"> 224<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 225<P CLASS="para"> 226<CODE CLASS="literal"> 227VWV</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 228<P CLASS="para"> 229Variable</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 230<P CLASS="para"> 231Parameter words (size given by WCT)</p></td></tr><TR CLASS="row" VALIGN="TOP"> 232<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 233<P CLASS="para"> 234<CODE CLASS="literal"> 235BCC</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 236<P CLASS="para"> 237<CODE CLASS="literal"> 2382</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 239<P CLASS="para"> 240Parameter byte count</p></td></tr><TR CLASS="row" VALIGN="TOP"> 241<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 242<P CLASS="para"> 243<CODE CLASS="literal"> 244DATA</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 245<P CLASS="para"> 246Variable</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 247<P CLASS="para"> 248Data (size given by BCC)</p></td></tr></tbody></table><P CLASS="para"> 249Don't worry if you don't understand each of these fields; they are not necessary for using Samba at an administrator level. However, they do come in handy when debugging system messages. We will show you some of the more common SMB messages that clients and servers send using a modified version of <I CLASS="filename"> 250tcpdump</i> later in this section. (If you would like an SMB sniffer with a graphical interface, try "ethereal," which uses the GTK libraries; see the Samba homepage for more information on this tool.)</p><P CLASS="para"> 251If you would like more information on each of the commands for the SMB protocol, see the SMB/CIFS documentation at <a href="ftp://ftp.microsoft.com/developr/drg/CIFS/"><I CLASS="filename">ftp://ftp.microsoft.com/developr/drg/CIFS/</i></a>.</p></div><DIV CLASS="sect3"> 252<H4 CLASS="sect3"> 253<A CLASS="title" NAME="ch03-pgfId-942573"> 2543.3.1.3 SMB variations</a></h4><P CLASS="para"> 255The SMB protocol has been extended with new commands several times since its inception. Each new version is backwards compatible with the previous versions. This makes it quite possible for a LAN to have various clients and servers running different versions of the SMB protocol at once.</p><P CLASS="para"> 256<A CLASS="xref" HREF="ch03_03.html#ch03-67366"> 257Table 3.3</a> outlines the major versions of the SMB protocol. Within each "dialect" of SMB are many sub-versions that include commands supporting particular releases of major operating systems. The ID string is used by clients and servers to determine what level of the protocol they will speak to each other. </p><br> 258<TABLE CLASS="table" BORDER="1" CELLPADDING="3"> 259<CAPTION CLASS="table"> 260<A CLASS="title" NAME="ch03-67366"> 261Table 3.3: SMB Protocol Dialects </a></caption><THEAD CLASS="thead"> 262<TR CLASS="row" VALIGN="TOP"> 263<TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 264<P CLASS="para"> 265Protocol Name</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 266<P CLASS="para"> 267ID String</p></th><TH CLASS="entry" ALIGN="LEFT" ROWSPAN="1" COLSPAN="1"> 268<P CLASS="para"> 269Used By</p></th></tr></thead><TBODY CLASS="tbody"> 270<TR CLASS="row" VALIGN="TOP"> 271<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 272<P CLASS="para"> 273Core</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 274<P CLASS="para"> 275<CODE CLASS="literal"> 276PC NETWORK PROGRAM 1.0</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 277<P CLASS="para"> 278</p></td></tr><TR CLASS="row" VALIGN="TOP"> 279<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 280<P CLASS="para"> 281Core Plus </p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 282<P CLASS="para"> 283<CODE CLASS="literal"> 284MICROSOFT NETWORKS 1.03 </code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 285<P CLASS="para"> 286</p></td></tr><TR CLASS="row" VALIGN="TOP"> 287<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 288<P CLASS="para"> 289LAN Manager 1.0 </p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 290<P CLASS="para"> 291<CODE CLASS="literal"> 292LANMAN1.0</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 293<P CLASS="para"> 294</p></td></tr><TR CLASS="row" VALIGN="TOP"> 295<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 296<P CLASS="para"> 297LAN Manager 2.0 </p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 298<P CLASS="para"> 299<CODE CLASS="literal"> 300LM1.2X002</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 301<P CLASS="para"> 302</p></td></tr><TR CLASS="row" VALIGN="TOP"> 303<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 304<P CLASS="para"> 305LAN Manager 2.1 </p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 306<P CLASS="para"> 307<CODE CLASS="literal"> 308LANMAN2.1</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 309<P CLASS="para"> 310</p></td></tr><TR CLASS="row" VALIGN="TOP"> 311<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 312<P CLASS="para"> 313NT LAN Manager 1.0</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 314<P CLASS="para"> 315<CODE CLASS="literal"> 316NT LM 0.12</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 317<P CLASS="para"> 318Windows NT 4.0</p></td></tr><TR CLASS="row" VALIGN="TOP"> 319<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 320<P CLASS="para"> 321Samba's NT LM 0.12</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 322<P CLASS="para"> 323<CODE CLASS="literal"> 324Samba</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 325<P CLASS="para"> 326Samba</p></td></tr><TR CLASS="row" VALIGN="TOP"> 327<TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 328<P CLASS="para"> 329Common Internet File System</p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 330<P CLASS="para"> 331<CODE CLASS="literal"> 332CIFS 1.0</code></p></td><TD CLASS="entry" ROWSPAN="1" COLSPAN="1"> 333<P CLASS="para"> 334Windows 2000</p></td></tr></tbody></table><P CLASS="para"> 335Samba implements the <CODE CLASS="literal"> 336NT</code> <CODE CLASS="literal"> 337LM</code> <CODE CLASS="literal"> 3380.12</code> specification for NT LAN Manager 1.0. It is backwards compatible with all of the other SMB variants. The CIFS specification is, in reality, LAN Manager 0.12 with a few specific additions.</p></div></div><DIV CLASS="sect2"> 339<H3 CLASS="sect2"> 340<A CLASS="title" NAME="ch03-pgfId-942627"> 3413.3.2 SMB Clients and Servers</a></h3><P CLASS="para"> 342As mentioned earlier, SMB is a client/server protocol. In the purest sense, this means that a client sends a request to a server, which acts on the request and returns a reply. However, the client/server roles can often be reversed, sometimes within the context of a single SMB session. For example, consider the two Windows 95/98 computers in <A CLASS="xref" HREF="ch03_03.html#ch03-69480"> 343Figure 3.28</a>. The computer named WIZZIN shares a printer to the network, and the computer named ESCRIME shares a disk directory. WIZZIN is in the client role when accessing ESCRIME's network drive, and in the server role when printing a job for ESCRIME. </p><H4 CLASS="figure"> 344<A CLASS="title" NAME="ch03-69480"> 345Figure 3.28: Two computers that both have resources to share</a></h4><IMG CLASS="graphic" SRC="figs/sam.0328.gif" ALT="Figure 3.28"><P CLASS="para"> 346This brings out an important point in Samba terminology:</p><UL CLASS="itemizedlist"> 347<LI CLASS="listitem"> 348<P CLASS="para"> 349<A CLASS="listitem" NAME="ch03-server-defined-in-Samba-terminology"> 350</a>A <I CLASS="firstterm"> 351server</i> is a machine with a resource to share.</p></li><LI CLASS="listitem"> 352<P CLASS="para"> 353<A CLASS="listitem" NAME="ch03-client-defined-in-Samba-terminology"> 354</a>A <I CLASS="firstterm"> 355client</i> is a machine that wishes to use that resource.</p></li><LI CLASS="listitem"> 356<P CLASS="para"> 357<A CLASS="listitem" NAME="ch03-pgfId-943256"> 358</a>A server can be a client (of another computer's resource) at any given time.</p></li></ul><P CLASS="para"> 359Note that there are no implications as to the amount of resources that make up a server, or whether it has a large disk space or fast processor. A server could be an old 486 with a printer attached to it, or it could be an UltraSparc station with a 10 gigabyte disk service.</p><P CLASS="para"> 360Microsoft Windows products have both the SMB client and server built in to the operating system. Wndows NT 4.0 uses a newer SMB protocol than Windows for Workgroups, and it offers an enhanced form of network security which will be discussed in <a href="ch06_01.html"><b>Chapter 6</b></a>. In addition, there are a large number of commercial SMB server products available from companies such as Sun, Compaq, SCO, Hewlett-Packard, Syntax, and IBM. Unfortunately, on the client side there are far fewer offerings, limited mainly to Digital Equipment's Pathworks product, and of course, Samba.</p></div><DIV CLASS="sect2"> 361<H3 CLASS="sect2"> 362<A CLASS="title" NAME="ch03-pgfId-942638"> 3633.3.3 A Simple SMB Connection</a></h3><P CLASS="para">Before we close this chapter, let's take a look at a simple SMB connection. This is some pretty technical data - which isn't really necessary to administer Samba - so you can skip over it if you like. We present this information largely as a way to help you get familiar with how the SMB protocol negotiates connections with other computers on the network. </p><P CLASS="para"> 364There are four steps that the client and server must complete in order to establish a connection to a resource:</p><OL CLASS="orderedlist"> 365<LI CLASS="listitem"> 366<P CLASS="para"> 367<A CLASS="listitem" NAME="ch03-pgfId-942687"> 368</a> Establish a virtual connection.</p></li><LI CLASS="listitem"> 369<P CLASS="para"> 370<A CLASS="listitem" NAME="ch03-pgfId-942688"> 371</a> Negotiate the protocol variant to speak.</p></li><LI CLASS="listitem"> 372<P CLASS="para"> 373<A CLASS="listitem" NAME="ch03-pgfId-942689"> 374</a> Set session parameters.</p></li><LI CLASS="listitem"> 375<P CLASS="para"> 376<A CLASS="listitem" NAME="ch03-pgfId-942690"> 377</a> Make a tree connection to a resource.</p></li></ol><P CLASS="para"> 378We will examine each of these steps through the eyes of a useful tool that we mentioned earlier: the modified <I CLASS="filename"> 379tcpdump</i> that is available from the Samba web site.</p><P CLASS="para"> 380You can download this program at <I CLASS="filename"> 381samba.org</i> in the <I CLASS="filename"> 382samba/ftp/tcpdump-smb</i> directory; the latest version as of this writing is 3.4-5. Use this program as you would use the standard <I CLASS="filename"> 383tcpdump</i> application, but add the <CODE CLASS="literal"> 384-s 1500</code> switch to ensure that you get the whole packet and not just the first few bytes.</p><DIV CLASS="sect3"> 385<H4 CLASS="sect3"> 386<A CLASS="title" NAME="ch03-pgfId-942691"> 3873.3.3.1 Establishing a virtual connection</a></h4><P CLASS="para">When a user first makes a request to access a network disk or send a print job to a remote printer, NetBIOS takes care of making a connection at the session layer. The result is a bidirectional virtual channel between the client and server. In reality, there are only two messages that the client and server need to establish this connection. This is shown in the following example session request and response, as captured by <I CLASS="filename"> 388tcpdump</i> :</p><PRE CLASS="programlisting"> 389>>> NBT Packet 390NBT Session Request 391Flags=0x81000044 392Destination=ESCRIME NameType=0x20 (Server) 393Source=WIZZIN NameType=0x00 (Workstation) 394 395>>> NBT Packet 396NBT Session Granted 397Flags=0x82000000</pre></div></div><DIV CLASS="sect2"> 398<H3 CLASS="sect2"> 399<A CLASS="title" NAME="ch03-pgfId-942713"> 4003.3.4 Negotiating the Protocol Variant</a></h3><P CLASS="para">At this point, there is an open channel between the client and server. Next, the client sends a message to the server to negotiate an SMB protocol. As mentioned earlier, the client sets its tree identifier (TID) field to zero, since it does not yet know what TID to use. A <EM CLASS="emphasis"> 401tree identifier</em> is a number that represents a connection to a share on a server.</p><P CLASS="para"> 402The command in the message is <CODE CLASS="literal"> 403SMBnegprot</code>, a request to negotiate a protocol variant that will be used for the entire session. Note that the client sends to the server a list of all of the variants that it can speak, not vice versa.</p><P CLASS="para"> 404The server responds to the <CODE CLASS="literal"> 405SMBnegprot</code> request with an index into the list of variants that the client offered, starting with index 0, or with the value 0xFF if none of the protocol variants are acceptable. Continuing this example, the server responds with the value 5, which indicates that the <CODE CLASS="literal"> 406NT</code> <CODE CLASS="literal"> 407LM</code> <CODE CLASS="literal"> 4080.12</code> dialect will be used for the remainder of the session:</p><PRE CLASS="programlisting"> 409>>> NBT Packet 410NBT Session Packet 411Flags=0x0 412Length=154 413 414SMB PACKET: SMBnegprot (REQUEST) 415SMB Command = 0x72 416Error class = 0x0 417Error code = 0 418Flags1 = 0x0 419Flags2 = 0x0 420Tree ID = 0 421Proc ID = 5371 422UID = 0 423MID = 385 424Word Count = 0 425Dialect=PC NETWORK PROGRAM 1.0 426Dialect=MICROSOFT NETWORKS 3.0 427Dialect=DOS LM1.2X002 428Dialect=DOS LANMAN2.1 429Dialect=Windows for Workgroups 3.1a 430Dialect=NT LM 0.12 431 432>>> NBT Packet 433NBT Session Packet 434Flags=0x0 435Length=69 436 437SMB PACKET: SMBnegprot (REPLY) 438SMB Command = 0x72 439Error class = 0x0 440Error code = 0 441Flags1 = 0x0 442Flags2 = 0x1 443Tree ID = 0 444Proc ID = 5371 445UID = 0 446MID = 385 447Word Count = 02 448[000] 05 00</pre></div><DIV CLASS="sect2"> 449<H3 CLASS="sect2"> 450<A CLASS="title" NAME="ch03-pgfId-942762"> 4513.3.5 Set Session and Login Parameters</a></h3><P CLASS="para">The next step is to transmit session and login parameters for the session. This includes the account name and password (if there is one), the workgroup name, the maximum size of data that can be transferred, and the number of pending requests that may be in the queue at any one time.</p><P CLASS="para"> 452In the following example, the Session Setup command presented allows for an additional SMB command to be piggybacked onto it. The letter X at the end of the command name indicates this, and the hexadecimal code of the second command is given in the <CODE CLASS="literal"> 453Com2</code> field. In this case the command is <CODE CLASS="literal"> 4540x75</code>, which is the Tree Connect and X command. The <CODE CLASS="literal"> 455SMBtconX</code> message looks for the name of the resource in the <KBD CLASS="command"> 456smb_buf</kbd> buffer. (This is the last field listed in the following request.) In this example, <KBD CLASS="command"> 457smb_buf</kbd> contains the string <CODE CLASS="literal"> 458\\ESCRIME\PUBLIC</code>, which is the full pathname to a shared directory on node ESCRIME. Using the "and X" commands like this speeds up each transaction, since the server doesn't have to wait on the client to make a second request.</p><P CLASS="para"> 459Note that the TID is still zero. The server will provide a TID to the client once the session has been established and a connection has been made to the requested resource. In addition, note that the password is sent in the open. We can change this later using encrypted passwords:</p><PRE CLASS="programlisting"> 460>>> NBT Packet 461NBT Session Packet 462Flags=0x0 463Length=139 464 465SMB PACKET: SMBsesssetupX (REQUEST) 466SMB Command = 0x73 467Error class = 0x0 468Error code = 0 469Flags1 = 0x10 470Flags2 = 0x0 471Tree ID = 0 472Proc ID = 5371 473UID = 1 474MID = 385 475Word Count = 13 476Com2=0x75 477Res1=0x0 478Off2=106 479MaxBuffer=2920 480MaxMpx=2 481VcNumber=0 482SessionKey=0x1FF2 483CaseInsensitivePasswordLength=1 484CaseSensitivePasswordLength=1 485Res=0x0 486Capabilities=0x1 487Pass1&Pass2&Account&Domain&OS&LanMan= 488 KRISTIN PARKSTR Windows 4.0 Windows 4.0 489PassLen=2 490Passwd&Path&Device= 491smb_bcc=22 492smb_buf[]=\\ESCRIME\PUBLIC</pre></div><DIV CLASS="sect2"> 493<H3 CLASS="sect2"> 494<A CLASS="title" NAME="ch03-pgfId-942801"> 4953.3.6 Making Connection to a Resource</a></h3><P CLASS="para">For the final step, the server returns a TID to the client, indicating that the user has been authorized access and that the resource is ready to be used. It also sets the <KBD CLASS="command"> 496ServiceType</kbd> field to "A" to indicate that this is a file service. Available service types are:</p><UL CLASS="itemizedlist"> 497<LI CLASS="listitem"> 498<P CLASS="para"> 499<A CLASS="listitem" NAME="ch03-pgfId-942803"> 500</a> "A" for a disk or file</p></li><LI CLASS="listitem"> 501<P CLASS="para"> 502<A CLASS="listitem" NAME="ch03-pgfId-942804"> 503</a> "LPT1" for a spooled output</p></li><LI CLASS="listitem"> 504<P CLASS="para"> 505<A CLASS="listitem" NAME="ch03-pgfId-942805"> 506</a> "COMM" for a direct-connect printer or modem</p></li><LI CLASS="listitem"> 507<P CLASS="para"> 508<A CLASS="listitem" NAME="ch03-pgfId-942806"> 509</a> "IPC" for a named pipe</p></li></ul><P CLASS="para"> 510The output is:</p><PRE CLASS="programlisting"> 511>>> NBT Packet 512NBT Session Packet 513Flags=0x0 514Length=78 515 516SMB PACKET: SMBsesssetupX (REPLY) 517SMB Command = 0x73 518Error class = 0x0 519Error code = 0 520Flags1 = 0x80 521Flags2 = 0x1 522Tree ID = 121 523Proc ID = 5371 524UID = 1 525MID = 385 526Word Count = 3 527Com2=0x75 528Off2=68 529Action=0x1 530[000] Unix Samba 1.9.1 531[010] PARKSTR 532 533SMB PACKET: SMBtconX (REPLY) (CHAINED) 534smbvwv[]= 535Com2=0xFF 536Off2=78 537smbbuf[]= 538ServiceType=A:</pre><P CLASS="para"> 539Now that a TID has been assigned, the client may issue any sort of command that it would use on a local disk drive. It can open files, read and write to them, delete them, create new files, search for filenames, and so on. </p></div></div></blockquote> 540<div> 541<center> 542<hr noshade size=1><TABLE WIDTH="515" BORDER="0" CELLSPACING="0" CELLPADDING="0"> 543<TR> 544<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="172"> 545<A CLASS="sect1" HREF="ch03_02.html" TITLE="3.2 Setting Up Windows NT 4.0 Computers"> 546<IMG SRC="gifs/txtpreva.gif" ALT="Previous: 3.2 Setting Up Windows NT 4.0 Computers" BORDER="0"></a></td><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="171"> 547<A CLASS="book" HREF="index.html" TITLE=""> 548<IMG SRC="gifs/txthome.gif" ALT="" BORDER="0"></a></td><TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="172"> 549<A CLASS="chapter" HREF="ch04_01.html" TITLE="4. Disk Shares "> 550<IMG SRC="gifs/txtnexta.gif" ALT="Next: 4. Disk Shares " BORDER="0"></a></td></tr><TR> 551<TD ALIGN="LEFT" VALIGN="TOP" WIDTH="172"> 5523.2 Setting Up Windows NT 4.0 Computers</td><TD ALIGN="CENTER" VALIGN="TOP" WIDTH="171"> 553<A CLASS="index" HREF="inx.html" TITLE="Book Index"> 554<IMG SRC="gifs/index.gif" ALT="Book Index" BORDER="0"></a></td><TD ALIGN="RIGHT" VALIGN="TOP" WIDTH="172"> 5554. Disk Shares </td></tr></table><hr noshade size=1></center> 556</div> 557 558<!-- End of sample chapter --> 559<CENTER> 560<FONT SIZE="1" FACE="Verdana, Arial, Helvetica"> 561<A HREF="http://www.oreilly.com/"> 562<B>O'Reilly Home</B></A> <B> | </B> 563<A HREF="http://www.oreilly.com/sales/bookstores"> 564<B>O'Reilly Bookstores</B></A> <B> | </B> 565<A HREF="http://www.oreilly.com/order_new/"> 566<B>How to Order</B></A> <B> | </B> 567<A HREF="http://www.oreilly.com/oreilly/contact.html"> 568<B>O'Reilly Contacts<BR></B></A> 569<A HREF="http://www.oreilly.com/international/"> 570<B>International</B></A> <B> | </B> 571<A HREF="http://www.oreilly.com/oreilly/about.html"> 572<B>About O'Reilly</B></A> <B> | </B> 573<A HREF="http://www.oreilly.com/affiliates.html"> 574<B>Affiliated Companies</B></A><p> 575<EM>© 1999, O'Reilly & Associates, Inc.</EM> 576</FONT> 577</CENTER> 578</BODY> 579</html> 580