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