Replace entities with xi:include
[Samba.git] / docs / devel / unix-smb.xml
blob80a6b6764914f99c260bf4844ff45e4772db05f5
1 <?xml version="1.0" encoding="iso-8859-1"?>
2 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.2//EN"
3                 "http://www.oasis-open.org/docbook/xml/4.2/docbookx.dtd" [
4   <!ENTITY % global_entities SYSTEM '../entities/global.entities'>
5   %global_entities;
6 ]>
7 <chapter id="unix-smb">
8 <chapterinfo>
9         <author>
10                 <firstname>Andrew</firstname><surname>Tridgell</surname>
11         </author>
12         <pubdate>April 1995</pubdate>
13 </chapterinfo>
15 <title>NetBIOS in a Unix World</title>
17 <sect1>
18 <title>Introduction</title>
19 <para>
20 This is a short document that describes some of the issues that
21 confront a SMB implementation on unix, and how Samba copes with
22 them. They may help people who are looking at unix&lt;-&gt;PC
23 interoperability.
24 </para>
26 <para>
27 It was written to help out a person who was writing a paper on unix to
28 PC connectivity.
29 </para>
31 </sect1>
33 <sect1>
34 <title>Usernames</title>
35 <para>
36 The SMB protocol has only a loose username concept. Early SMB
37 protocols (such as CORE and COREPLUS) have no username concept at
38 all. Even in later protocols clients often attempt operations
39 (particularly printer operations) without first validating a username
40 on the server.
41 </para>
43 <para>
44 Unix security is based around username/password pairs. A unix box
45 should not allow clients to do any substantive operation without some
46 sort of validation. 
47 </para>
49 <para>
50 The problem mostly manifests itself when the unix server is in "share
51 level" security mode. This is the default mode as the alternative
52 "user level" security mode usually forces a client to connect to the
53 server as the same user for each connected share, which is
54 inconvenient in many sites.
55 </para>
57 <para>
58 In "share level" security the client normally gives a username in the
59 "session setup" protocol, but does not supply an accompanying
60 password. The client then connects to resources using the "tree
61 connect" protocol, and supplies a password. The problem is that the
62 user on the PC types the username and the password in different
63 contexts, unaware that they need to go together to give access to the
64 server. The username is normally the one the user typed in when they
65 "logged onto" the PC (this assumes Windows for Workgroups). The
66 password is the one they chose when connecting to the disk or printer.
67 </para>
69 <para>
70 The user often chooses a totally different username for their login as
71 for the drive connection. Often they also want to access different
72 drives as different usernames. The unix server needs some way of
73 divining the correct username to combine with each password.
74 </para>
76 <para>
77 Samba tries to avoid this problem using several methods. These succeed
78 in the vast majority of cases. The methods include username maps, the
79 service%user syntax, the saving of session setup usernames for later
80 validation and the derivation of the username from the service name
81 (either directly or via the user= option).
82 </para>
84 </sect1>
86 <sect1>
87 <title>File Ownership</title>
89 <para>
90 The commonly used SMB protocols have no way of saying "you can't do
91 that because you don't own the file". They have, in fact, no concept
92 of file ownership at all.
93 </para>
95 <para>
96 This brings up all sorts of interesting problems. For example, when
97 you copy a file to a unix drive, and the file is world writeable but
98 owned by another user the file will transfer correctly but will
99 receive the wrong date. This is because the utime() call under unix
100 only succeeds for the owner of the file, or root, even if the file is
101 world writeable. For security reasons Samba does all file operations
102 as the validated user, not root, so the utime() fails. This can stuff
103 up shared development diectories as programs like "make" will not get
104 file time comparisons right.
105 </para>
107 <para>
108 There are several possible solutions to this problem, including
109 username mapping, and forcing a specific username for particular
110 shares.
111 </para>
113 </sect1>
115 <sect1>
116 <title>Passwords</title>
118 <para>
119 Many SMB clients uppercase passwords before sending them. I have no
120 idea why they do this. Interestingly WfWg uppercases the password only
121 if the server is running a protocol greater than COREPLUS, so
122 obviously it isn't just the data entry routines that are to blame.
123 </para>
125 <para>
126 Unix passwords are case sensitive. So if users use mixed case
127 passwords they are in trouble.
128 </para>
130 <para>
131 Samba can try to cope with this by either using the "password level"
132 option which causes Samba to try the offered password with up to the
133 specified number of case changes, or by using the "password server"
134 option which allows Samba to do its validation via another machine
135 (typically a WinNT server).
136 </para>
138 <para>
139 Samba supports the password encryption method used by SMB
140 clients. Note that the use of password encryption in Microsoft
141 networking leads to password hashes that are "plain text equivalent".
142 This means that it is *VERY* important to ensure that the Samba
143 smbpasswd file containing these password hashes is only readable
144 by the root user. See the documentation ENCRYPTION.txt for more
145 details.
146 </para>
148 </sect1>
150 <sect1>
151 <title>Locking</title>
152 <para>
153 Since samba 2.2, samba supports other types of locking as well. This 
154 section is outdated.
155 </para>
157 <para>
158 The locking calls available under a DOS/Windows environment are much
159 richer than those available in unix. This means a unix server (like
160 Samba) choosing to use the standard fcntl() based unix locking calls
161 to implement SMB locking has to improvise a bit.
162 </para>
164 <para>
165 One major problem is that dos locks can be in a 32 bit (unsigned)
166 range. Unix locking calls are 32 bits, but are signed, giving only a 31
167 bit range. Unfortunately OLE2 clients use the top bit to select a
168 locking range used for OLE semaphores.
169 </para>
171 <para>
172 To work around this problem Samba compresses the 32 bit range into 31
173 bits by appropriate bit shifting. This seems to work but is not
174 ideal. In a future version a separate SMB lockd may be added to cope
175 with the problem.
176 </para>
178 <para>
179 It also doesn't help that many unix lockd daemons are very buggy and
180 crash at the slightest provocation. They normally go mostly unused in
181 a unix environment because few unix programs use byte range
182 locking. The stress of huge numbers of lock requests from dos/windows
183 clients can kill the daemon on some systems.
184 </para>
186 <para>
187 The second major problem is the "opportunistic locking" requested by
188 some clients. If a client requests opportunistic locking then it is
189 asking the server to notify it if anyone else tries to do something on
190 the same file, at which time the client will say if it is willing to
191 give up its lock. Unix has no simple way of implementing
192 opportunistic locking, and currently Samba has no support for it.
193 </para>
195 </sect1>
197 <sect1>
198 <title>Deny Modes</title>
200 <para>
201 When a SMB client opens a file it asks for a particular "deny mode" to
202 be placed on the file. These modes (DENY_NONE, DENY_READ, DENY_WRITE,
203 DENY_ALL, DENY_FCB and DENY_DOS) specify what actions should be
204 allowed by anyone else who tries to use the file at the same time. If
205 DENY_READ is placed on the file, for example, then any attempt to open
206 the file for reading should fail.
207 </para>
209 <para>
210 Unix has no equivalent notion. To implement this Samba uses either lock
211 files based on the files inode and placed in a separate lock
212 directory or a shared memory implementation. The lock file method 
213 is clumsy and consumes processing and file resources,
214 the shared memory implementation is vastly prefered and is turned on
215 by default for those systems that support it.
216 </para>
218 </sect1>
220 <sect1>
221 <title>Trapdoor UIDs</title>
222 <para>
223 A SMB session can run with several uids on the one socket. This
224 happens when a user connects to two shares with different
225 usernames. To cope with this the unix server needs to switch uids
226 within the one process. On some unixes (such as SCO) this is not
227 possible. This means that on those unixes the client is restricted to
228 a single uid.
229 </para>
231 <para>
232 Note that you can also get the "trapdoor uid" message for other
233 reasons. Please see the FAQ for details.
234 </para>
236 </sect1>
238 <sect1>
239 <title>Port numbers</title>
240 <para>
241 There is a convention that clients on sockets use high "unprivilaged"
242 port numbers (>1000) and connect to servers on low "privilaged" port
243 numbers. This is enforced in Unix as non-root users can't open a
244 socket for listening on port numbers less than 1000.
245 </para>
247 <para>
248 Most PC based SMB clients (such as WfWg and WinNT) don't follow this
249 convention completely. The main culprit is the netbios nameserving on
250 udp port 137. Name query requests come from a source port of 137. This
251 is a problem when you combine it with the common firewalling technique
252 of not allowing incoming packets on low port numbers. This means that
253 these clients can't query a netbios nameserver on the other side of a
254 low port based firewall.
255 </para>
257 <para>
258 The problem is more severe with netbios node status queries. I've
259 found that WfWg, Win95 and WinNT3.5 all respond to netbios node status
260 queries on port 137 no matter what the source port was in the
261 request. This works between machines that are both using port 137, but
262 it means it's not possible for a unix user to do a node status request
263 to any of these OSes unless they are running as root. The answer comes
264 back, but it goes to port 137 which the unix user can't listen
265 on. Interestingly WinNT3.1 got this right - it sends node status
266 responses back to the source port in the request.
267 </para>
269 </sect1>
271 <sect1>
272 <title>Protocol Complexity</title>
273 <para>
274 There are many "protocol levels" in the SMB protocol. It seems that
275 each time new functionality was added to a Microsoft operating system,
276 they added the equivalent functions in a new protocol level of the SMB
277 protocol to "externalise" the new capabilities.
278 </para>
280 <para>
281 This means the protocol is very "rich", offering many ways of doing
282 each file operation. This means SMB servers need to be complex and
283 large. It also means it is very difficult to make them bug free. It is
284 not just Samba that suffers from this problem, other servers such as
285 WinNT don't support every variation of every call and it has almost
286 certainly been a headache for MS developers to support the myriad of
287 SMB calls that are available.
288 </para>
290 <para>
291 There are about 65 "top level" operations in the SMB protocol (things
292 like SMBread and SMBwrite). Some of these include hundreds of
293 sub-functions (SMBtrans has at least 120 sub-functions, like
294 DosPrintQAdd and NetSessionEnum). All of them take several options
295 that can change the way they work. Many take dozens of possible
296 "information levels" that change the structures that need to be
297 returned. Samba supports all but 2 of the "top level" functions. It
298 supports only 8 (so far) of the SMBtrans sub-functions. Even NT
299 doesn't support them all.
300 </para>
302 <para>
303 Samba currently supports up to the "NT LM 0.12" protocol, which is the
304 one preferred by Win95 and WinNT3.5. Luckily this protocol level has a
305 "capabilities" field which specifies which super-duper new-fangled
306 options the server suports. This helps to make the implementation of
307 this protocol level much easier.
308 </para>
310 <para>
311 There is also a problem with the SMB specications. SMB is a X/Open
312 spec, but the X/Open book is far from ideal, and fails to cover many
313 important issues, leaving much to the imagination. Microsoft recently
314 renamed the SMB protocol CIFS (Common Internet File System) and have 
315 published new specifications. These are far superior to the old 
316 X/Open documents but there are still undocumented calls and features. 
317 This specification is actively being worked on by a CIFS developers 
318 mailing list hosted by Microsft.
319 </para>
320 </sect1>
321 </chapter>