Print this page
NEX-15069 smtorture smb2.create.blob is failed
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-15069 smtorture smb2.create.blob is failed
Reviewed by: Matt Barden <matt.barden@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
NEX-1643 dtrace provider for smbsrv
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Reviewed by: Matt Barden <matt.barden@nexenta.com>
SMB-11 SMB2 message parse & dispatch
SMB-12 SMB2 Negotiate Protocol
SMB-13 SMB2 Session Setup
SMB-14 SMB2 Logoff
SMB-15 SMB2 Tree Connect
SMB-16 SMB2 Tree Disconnect
SMB-17 SMB2 Create
SMB-18 SMB2 Close
SMB-19 SMB2 Flush
SMB-20 SMB2 Read
SMB-21 SMB2 Write
SMB-22 SMB2 Lock/Unlock
SMB-23 SMB2 Ioctl
SMB-24 SMB2 Cancel
SMB-25 SMB2 Echo
SMB-26 SMB2 Query Dir
SMB-27 SMB2 Change Notify
SMB-28 SMB2 Query Info
SMB-29 SMB2 Set Info
SMB-30 SMB2 Oplocks
SMB-53 SMB2 Create Context options
(SMB2 code review cleanup 1, 2, 3)
SMB-63 taskq_create_proc ... TQ_DYNAMIC puts tasks in p0
re #11974 CIFS Share - Tree connect fails from Windows 7 Clients
re #10733 Windows 7 directory listing keeps restarting
| Split |
Close |
| Expand all |
| Collapse all |
--- old/usr/src/uts/common/fs/smbsrv/smb_find.c
+++ new/usr/src/uts/common/fs/smbsrv/smb_find.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
|
↓ open down ↓ |
12 lines elided |
↑ open up ↑ |
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved.
23 - * Copyright 2013 Nexenta Systems, Inc. All rights reserved.
23 + * Copyright 2017 Nexenta Systems, Inc. All rights reserved.
24 24 */
25 25
26 26 #include <smbsrv/smb_kproto.h>
27 27
28 28 /*
29 29 * smb_com_search
30 30 * smb_com_find, smb_com_find_close
31 31 * smb_find_unique
32 32 *
33 33 * These commands are used for directory searching. They share the same
34 34 * message formats, defined below:
35 35 *
36 36 * Client Request Description
37 37 * ---------------------------------- ---------------------------------
38 38 *
39 39 * UCHAR WordCount; Count of parameter words = 2
40 40 * USHORT MaxCount; Number of dir. entries to return
41 41 * USHORT SearchAttributes;
42 42 * USHORT ByteCount; Count of data bytes; min = 5
43 43 * UCHAR BufferFormat1; 0x04 -- ASCII
44 44 * UCHAR FileName[]; File name, may be null
45 45 * UCHAR BufferFormat2; 0x05 -- Variable block
46 46 * USHORT ResumeKeyLength; Length of resume key, may be 0
47 47 * UCHAR ResumeKey[]; Resume key
48 48 *
49 49 * FileName specifies the file to be sought. SearchAttributes indicates
50 50 * the attributes that the file must have. If SearchAttributes is
51 51 * zero then only normal files are returned. If the system file, hidden or
52 52 * directory attributes are specified then the search is inclusive - both the
53 53 * specified type(s) of files and normal files are returned. If the volume
54 54 * label attribute is specified then the search is exclusive, and only the
55 55 * volume label entry is returned.
56 56 *
57 57 * MaxCount specifies the number of directory entries to be returned.
58 58 *
59 59 * Server Response Description
60 60 * ---------------------------------- ---------------------------------
61 61 *
62 62 * UCHAR WordCount; Count of parameter words = 1
63 63 * USHORT Count; Number of entries returned
64 64 * USHORT ByteCount; Count of data bytes; min = 3
65 65 * UCHAR BufferFormat; 0x05 -- Variable block
66 66 * USHORT DataLength; Length of data
67 67 * UCHAR DirectoryInformationData[]; Data
68 68 *
69 69 * The response will contain one or more directory entries as determined by
70 70 * the Count field. No more than MaxCount entries will be returned. Only
71 71 * entries that match the sought FileName and SearchAttributes combination
72 72 * will be returned.
73 73 *
74 74 * ResumeKey must be null (length = 0) on the initial search request.
75 75 * Subsequent search requests intended to continue a search must contain
76 76 * the ResumeKey field extracted from the last directory entry of the
77 77 * previous response. ResumeKey is self-contained, for calls containing
78 78 * a non-zero ResumeKey neither the SearchAttributes or FileName fields
79 79 * will be valid in the request. ResumeKey has the following format:
80 80 *
81 81 * Resume Key Field Description
82 82 * ---------------------------------- ---------------------------------
83 83 *
84 84 * UCHAR Reserved; bit 7 - consumer use
85 85 * bits 5,6 - system use (must preserve)
86 86 * bits 0-4 - server use (must preserve)
87 87 * UCHAR FileName[11]; Name of the returned file
88 88 * UCHAR ReservedForServer[5]; Client must not modify
89 89 * byte 0 - uniquely identifies find
90 90 * through find_close
91 91 * bytes 1-4 - available for server use
92 92 * (must be non-zero)
93 93 * UCHAR ReservedForConsumer[4]; Server must not modify
94 94 *
95 95 * FileName is 8.3 format, with the three character extension left
96 96 * justified into FileName[9-11].
97 97 *
98 98 * There may be multiple matching entries in response to a single request
99 99 * as wildcards are supported in the last component of FileName of the
100 100 * initial request.
101 101 *
102 102 * Returned directory entries in the DirectoryInformationData field of the
103 103 * response each have the following format:
104 104 *
105 105 * Directory Information Field Description
106 106 * ---------------------------------- ---------------------------------
107 107 *
108 108 * SMB_RESUME_KEY ResumeKey; Described above
109 109 * UCHAR FileAttributes; Attributes of the found file
110 110 * SMB_TIME LastWriteTime; Time file was last written
111 111 * SMB_DATE LastWriteDate; Date file was last written
112 112 * ULONG FileSize; Size of the file
113 113 * UCHAR FileName[13]; ASCII, space-filled null terminated
114 114 *
115 115 * FileName must conform to 8.3 rules, and is padded after the extension
116 116 * with 0x20 characters if necessary.
117 117 *
118 118 * As can be seen from the above structure, these commands cannot return
119 119 * long filenames, and cannot return UNICODE filenames.
120 120 *
121 121 * Files which have a size greater than 2^32 bytes should have the least
122 122 * significant 32 bits of their size returned in FileSize.
123 123 *
124 124 * smb_com_search
125 125 * --------------
126 126 *
127 127 * If the client is prior to the LANMAN1.0 dialect, the returned FileName
128 128 * should be uppercased.
129 129 * If the client has negotiated a dialect prior to the LANMAN1.0 dialect,
130 130 * or if bit0 of the Flags2 SMB header field of the request is clear,
131 131 * the returned FileName should be uppercased.
132 132 *
133 133 * SMB_COM_SEARCH terminates when either the requested maximum number of
134 134 * entries that match the named file are found, or the end of directory is
135 135 * reached without the maximum number of matches being found. A response
136 136 * containing no entries indicates that no matching entries were found
137 137 * between the starting point of the search and the end of directory.
138 138 *
139 139 *
140 140 * The find, find_close and find_unique protocols may be used in place of
141 141 * the core "search" protocol when LANMAN 1.0 dialect has been negotiated.
142 142 *
143 143 * smb_com_find
144 144 * ------------
145 145 *
146 146 * The find protocol is used to match the find OS/2 system call.
147 147 *
148 148 * The format of the find protocol is the same as the core "search" protocol.
149 149 * The difference is that the directory is logically Opened with a find protocol
150 150 * and logically closed with the find close protocol.
151 151 * As is true of a failing open, if a find request (find "first" request where
152 152 * resume_key is null) fails (no entries are found), no find close protocol is
153 153 * expected.
154 154 *
155 155 * If no global characters are present, a "find unique" protocol should be used
156 156 * (only one entry is expected and find close need not be sent).
157 157 *
158 158 * A find request will terminate when either the requested maximum number of
159 159 * entries that match the named file are found, or the end of directory is
160 160 * reached without the maximum number of matches being found. A response
161 161 * containing no entries indicates that no matching entries were found between
162 162 * the starting point of the search and the end of directory.
163 163 *
164 164 * If a find requests more data than can be placed in a message of the
165 165 * max-xmit-size for the TID specified, the server will return only the number
166 166 * of entries which will fit.
167 167 *
168 168 *
169 169 * smb_com_find_close
170 170 * ------------------
171 171 *
172 172 * The find close protocol is used to match the find close OS/2 system call.
173 173 *
174 174 * Whereas the first find protocol logically opens the directory, subsequent
175 175 * find protocols presenting a resume_key further "read" the directory, the
176 176 * find close protocol "closes" the directory allowing the server to free any
177 177 * resources held in support of the directory search.
178 178 *
179 179 * In our implementation this translates to closing the odir.
180 180 *
181 181 *
182 182 * smb_com_find_unique
183 183 * -------------------
184 184 *
185 185 * The format of the find unique protocol is the same as the core "search"
186 186 * protocol. The difference is that the directory is logically opened, any
187 187 * matching entries returned, and then the directory is logically closed.
188 188 *
189 189 * The resume search key key will be returned as in the find protocol and
190 190 * search protocol however it may NOT be returned to continue the search.
191 191 * Only one buffer of entries is expected and find close need not be sent.
192 192 *
193 193 * If a find unique requests more data than can be placed in a message of the
194 194 * max-xmit-size for the TID specified, the server will abort the virtual
195 195 * circuit to the consumer.
|
↓ open down ↓ |
162 lines elided |
↑ open up ↑ |
196 196 */
197 197
198 198 #define SMB_NAME83_BUFLEN 12
199 199 static void smb_name83(const char *, char *, size_t);
200 200
201 201 /* *** smb_com_search *** */
202 202
203 203 smb_sdrc_t
204 204 smb_pre_search(smb_request_t *sr)
205 205 {
206 - DTRACE_SMB_1(op__Search__start, smb_request_t *, sr);
206 + DTRACE_SMB_START(op__Search, smb_request_t *, sr);
207 207 return (SDRC_SUCCESS);
208 208 }
209 209
210 210 void
211 211 smb_post_search(smb_request_t *sr)
212 212 {
213 - DTRACE_SMB_1(op__Search__done, smb_request_t *, sr);
213 + DTRACE_SMB_DONE(op__Search, smb_request_t *, sr);
214 214 }
215 215
216 216 smb_sdrc_t
217 217 smb_com_search(smb_request_t *sr)
218 218 {
219 219 int rc;
220 220 uint16_t count, maxcount, index;
221 221 uint16_t sattr, odid;
222 222 uint16_t key_len;
223 223 uint32_t client_key;
224 224 char name[SMB_SHORTNAMELEN];
225 225 char name83[SMB_SHORTNAMELEN];
226 226 smb_pathname_t *pn;
227 227 unsigned char resume_char;
228 228 unsigned char type;
229 229 boolean_t find_first, to_upper;
230 230 smb_tree_t *tree;
231 231 smb_odir_t *od;
232 232 smb_fileinfo_t fileinfo;
233 233 smb_odir_resume_t odir_resume;
234 234 uint32_t status;
235 235 uint16_t eos;
236 236
237 237 to_upper = B_FALSE;
238 238 if ((sr->session->dialect <= LANMAN1_0) ||
239 239 ((sr->smb_flg2 & SMB_FLAGS2_KNOWS_LONG_NAMES) == 0)) {
240 240 to_upper = B_TRUE;
241 241 }
242 242
243 243 /* We only handle 8.3 name here */
244 244 sr->smb_flg2 &= ~SMB_FLAGS2_KNOWS_LONG_NAMES;
245 245 sr->smb_flg &= ~SMB_FLAGS_CASE_INSENSITIVE;
246 246
247 247 if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
248 248 return (SDRC_ERROR);
249 249
250 250 pn = &sr->arg.dirop.fqi.fq_path;
251 251 rc = smbsr_decode_data(sr, "%Abw", sr, &pn->pn_path, &type, &key_len);
252 252 if ((rc != 0) || (type != 0x05))
253 253 return (SDRC_ERROR);
254 254
255 255 smb_pathname_init(sr, pn, pn->pn_path);
256 256 if (!smb_pathname_validate(sr, pn) ||
257 257 smb_is_stream_name(pn->pn_path)) {
258 258 smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
259 259 ERRDOS, ERROR_NO_MORE_FILES);
260 260 return (SDRC_ERROR);
261 261 }
262 262
263 263 tree = sr->tid_tree;
264 264
265 265 /* Volume information only */
266 266 if ((sattr == FILE_ATTRIBUTE_VOLUME) && (key_len != 21)) {
267 267 (void) memset(name, ' ', sizeof (name));
268 268 (void) strncpy(name, tree->t_volume, sizeof (name));
269 269
270 270 if (key_len >= 21) {
271 271 (void) smb_mbc_decodef(&sr->smb_data, "17.l",
272 272 &client_key);
273 273 } else {
274 274 client_key = 0;
275 275 }
276 276
277 277 (void) smb_mbc_encodef(&sr->reply, "bwwbwb11c5.lb8.13c",
278 278 1, 0, VAR_BCC, 5, 0, 0, pn->pn_path+1,
279 279 client_key, sattr, name);
280 280
281 281 rc = (sr->reply.chain_offset - sr->cur_reply_offset) - 8;
282 282 (void) smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw",
283 283 1, 1, rc+3, 5, rc);
284 284
285 285 return (SDRC_SUCCESS);
286 286 }
287 287
288 288 if ((key_len != 0) && (key_len != 21))
289 289 return (SDRC_ERROR);
290 290
291 291 find_first = (key_len == 0);
292 292 resume_char = 0;
|
↓ open down ↓ |
69 lines elided |
↑ open up ↑ |
293 293 client_key = 0;
294 294
295 295 if (find_first) {
296 296 status = smb_odir_openpath(sr, pn->pn_path, sattr, 0, &od);
297 297 if (status != 0) {
298 298 if (status == NT_STATUS_ACCESS_DENIED)
299 299 smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
300 300 ERRDOS, ERROR_NO_MORE_FILES);
301 301 return (SDRC_ERROR);
302 302 }
303 + odid = od->d_odid;
303 304 } else {
304 305 if (smb_mbc_decodef(&sr->smb_data, "b12.wwl",
305 306 &resume_char, &index, &odid, &client_key) != 0) {
306 307 return (SDRC_ERROR);
307 308 }
308 309 od = smb_tree_lookup_odir(sr, odid);
309 310 }
310 311
311 312 if (od == NULL) {
312 313 smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
313 314 ERRDOS, ERROR_INVALID_HANDLE);
314 315 return (SDRC_ERROR);
315 316 }
316 317
317 318 if (!find_first) {
318 319 if ((od->d_flags & SMB_ODIR_FLAG_WILDCARDS) == 0) {
319 320 od->d_eof = B_TRUE;
320 321 } else {
321 322 odir_resume.or_type = SMB_ODIR_RESUME_IDX;
322 323 odir_resume.or_idx = index;
323 324 smb_odir_resume_at(od, &odir_resume);
324 325 }
325 326 }
326 327
327 328 (void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0);
328 329
329 330 rc = 0;
330 331 index = 0;
331 332 count = 0;
332 333 if (maxcount > SMB_MAX_SEARCH)
333 334 maxcount = SMB_MAX_SEARCH;
334 335
335 336 while (count < maxcount) {
336 337 rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos);
337 338 if (rc != 0 || eos != 0)
338 339 break;
339 340
340 341 if (*fileinfo.fi_shortname == '\0') {
341 342 if (smb_needs_mangled(fileinfo.fi_name))
342 343 continue;
343 344 (void) strlcpy(fileinfo.fi_shortname, fileinfo.fi_name,
344 345 SMB_SHORTNAMELEN - 1);
345 346 if (to_upper)
346 347 (void) smb_strupr(fileinfo.fi_shortname);
347 348 }
348 349 smb_name83(fileinfo.fi_shortname, name83, SMB_SHORTNAMELEN);
349 350
350 351 (void) smb_mbc_encodef(&sr->reply, "b11c.wwlbYl13c",
351 352 resume_char, name83, index, odid, client_key,
352 353 fileinfo.fi_dosattr & 0xff,
353 354 smb_time_gmt_to_local(sr, fileinfo.fi_mtime.tv_sec),
354 355 (int32_t)fileinfo.fi_size,
355 356 fileinfo.fi_shortname);
356 357
357 358 smb_odir_save_cookie(od, index, fileinfo.fi_cookie);
358 359
359 360 count++;
360 361 index++;
361 362 }
362 363 if (eos && rc == ENOENT)
363 364 rc = 0;
364 365
365 366 if (rc != 0) {
366 367 smb_odir_close(od);
367 368 smb_odir_release(od);
368 369 return (SDRC_ERROR);
369 370 }
370 371
371 372 if (count == 0 && find_first) {
372 373 smb_odir_close(od);
373 374 smb_odir_release(od);
374 375 smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
375 376 ERRDOS, ERROR_NO_MORE_FILES);
376 377 return (SDRC_ERROR);
377 378 }
378 379
379 380 rc = (sr->reply.chain_offset - sr->cur_reply_offset) - 8;
380 381 if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw",
381 382 1, count, rc+3, 5, rc) < 0) {
382 383 smb_odir_close(od);
383 384 smb_odir_release(od);
384 385 return (SDRC_ERROR);
385 386 }
386 387
|
↓ open down ↓ |
74 lines elided |
↑ open up ↑ |
387 388 smb_odir_release(od);
388 389 return (SDRC_SUCCESS);
389 390 }
390 391
391 392
392 393 /* *** smb_com_find *** */
393 394
394 395 smb_sdrc_t
395 396 smb_pre_find(smb_request_t *sr)
396 397 {
397 - DTRACE_SMB_1(op__Find__start, smb_request_t *, sr);
398 + DTRACE_SMB_START(op__Find, smb_request_t *, sr);
398 399 return (SDRC_SUCCESS);
399 400 }
400 401
401 402 void
402 403 smb_post_find(smb_request_t *sr)
403 404 {
404 - DTRACE_SMB_1(op__Find__done, smb_request_t *, sr);
405 + DTRACE_SMB_DONE(op__Find, smb_request_t *, sr);
405 406 }
406 407
407 408 smb_sdrc_t
408 409 smb_com_find(smb_request_t *sr)
409 410 {
410 411 int rc;
411 412 uint16_t count, maxcount, index;
412 413 uint16_t sattr, odid;
413 414 uint16_t key_len;
414 415 uint32_t client_key;
415 416 char name83[SMB_SHORTNAMELEN];
416 417 smb_odir_t *od;
417 418 smb_fileinfo_t fileinfo;
418 419 uint32_t status;
419 420 uint16_t eos;
420 421
421 422 smb_pathname_t *pn;
422 423 unsigned char resume_char;
423 424 unsigned char type;
424 425 boolean_t find_first = B_TRUE;
425 426 smb_odir_resume_t odir_resume;
426 427
427 428 if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
428 429 return (SDRC_ERROR);
429 430
430 431 pn = &sr->arg.dirop.fqi.fq_path;
431 432 rc = smbsr_decode_data(sr, "%Abw", sr, &pn->pn_path, &type, &key_len);
432 433 if ((rc != 0) || (type != 0x05))
433 434 return (SDRC_ERROR);
434 435
435 436 if ((key_len != 0) && (key_len != 21))
436 437 return (SDRC_ERROR);
437 438
438 439 smb_pathname_init(sr, pn, pn->pn_path);
439 440 if (!smb_pathname_validate(sr, pn))
440 441 return (SDRC_ERROR);
441 442
442 443 if (smb_is_stream_name(pn->pn_path)) {
443 444 smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
444 445 ERRDOS, ERROR_INVALID_NAME);
445 446 return (SDRC_ERROR);
446 447 }
447 448
|
↓ open down ↓ |
33 lines elided |
↑ open up ↑ |
448 449 find_first = (key_len == 0);
449 450 resume_char = 0;
450 451 client_key = 0;
451 452
452 453 if (find_first) {
453 454 status = smb_odir_openpath(sr, pn->pn_path, sattr, 0, &od);
454 455 if (status != 0) {
455 456 smbsr_error(sr, status, 0, 0);
456 457 return (SDRC_ERROR);
457 458 }
459 + odid = od->d_odid;
458 460 } else {
459 461 if (smb_mbc_decodef(&sr->smb_data, "b12.wwl",
460 462 &resume_char, &index, &odid, &client_key) != 0) {
461 463 return (SDRC_ERROR);
462 464 }
463 465 od = smb_tree_lookup_odir(sr, odid);
464 466 }
465 467
466 468 if (od == NULL) {
467 469 smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
468 470 ERRDOS, ERROR_INVALID_HANDLE);
469 471 return (SDRC_ERROR);
470 472 }
471 473
472 474 if (!find_first) {
473 475 if ((od->d_flags & SMB_ODIR_FLAG_WILDCARDS) == 0) {
474 476 od->d_eof = B_TRUE;
475 477 } else {
476 478 odir_resume.or_type = SMB_ODIR_RESUME_IDX;
477 479 odir_resume.or_idx = index;
478 480 smb_odir_resume_at(od, &odir_resume);
479 481 }
480 482 }
481 483
482 484 (void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0);
483 485
484 486 rc = 0;
485 487 index = 0;
486 488 count = 0;
487 489 if (maxcount > SMB_MAX_SEARCH)
488 490 maxcount = SMB_MAX_SEARCH;
489 491
490 492 while (count < maxcount) {
491 493 rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos);
492 494 if (rc != 0 || eos != 0)
493 495 break;
494 496
495 497 if (*fileinfo.fi_shortname == '\0') {
496 498 if (smb_needs_mangled(fileinfo.fi_name))
497 499 continue;
498 500 (void) strlcpy(fileinfo.fi_shortname, fileinfo.fi_name,
499 501 SMB_SHORTNAMELEN - 1);
500 502 }
501 503 smb_name83(fileinfo.fi_shortname, name83, SMB_SHORTNAMELEN);
502 504
503 505 (void) smb_mbc_encodef(&sr->reply, "b11c.wwlbYl13c",
504 506 resume_char, name83, index, odid, client_key,
505 507 fileinfo.fi_dosattr & 0xff,
506 508 smb_time_gmt_to_local(sr, fileinfo.fi_mtime.tv_sec),
507 509 (int32_t)fileinfo.fi_size,
508 510 fileinfo.fi_shortname);
509 511
510 512 smb_odir_save_cookie(od, index, fileinfo.fi_cookie);
511 513
512 514 count++;
513 515 index++;
514 516 }
515 517 if (eos && rc == ENOENT)
516 518 rc = 0;
517 519
518 520 if (rc != 0) {
519 521 smb_odir_close(od);
520 522 smb_odir_release(od);
521 523 return (SDRC_ERROR);
522 524 }
523 525
524 526 if (count == 0 && find_first) {
525 527 smb_odir_close(od);
526 528 smb_odir_release(od);
527 529 smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
528 530 ERRDOS, ERROR_NO_MORE_FILES);
529 531 return (SDRC_ERROR);
530 532 }
531 533
532 534 rc = (MBC_LENGTH(&sr->reply) - sr->cur_reply_offset) - 8;
533 535 if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw",
534 536 1, count, rc+3, 5, rc) < 0) {
535 537 smb_odir_close(od);
536 538 smb_odir_release(od);
537 539 return (SDRC_ERROR);
538 540 }
539 541
|
↓ open down ↓ |
72 lines elided |
↑ open up ↑ |
540 542 smb_odir_release(od);
541 543 return (SDRC_SUCCESS);
542 544 }
543 545
544 546
545 547 /* *** smb_com_find_close *** */
546 548
547 549 smb_sdrc_t
548 550 smb_pre_find_close(smb_request_t *sr)
549 551 {
550 - DTRACE_SMB_1(op__FindClose__start, smb_request_t *, sr);
552 + DTRACE_SMB_START(op__FindClose, smb_request_t *, sr);
551 553 return (SDRC_SUCCESS);
552 554 }
553 555
554 556 void
555 557 smb_post_find_close(smb_request_t *sr)
556 558 {
557 - DTRACE_SMB_1(op__FindClose__done, smb_request_t *, sr);
559 + DTRACE_SMB_DONE(op__FindClose, smb_request_t *, sr);
558 560 }
559 561
560 562 smb_sdrc_t
561 563 smb_com_find_close(smb_request_t *sr)
562 564 {
563 565 int rc;
564 566 uint16_t maxcount, index;
565 567 uint16_t sattr, odid;
566 568 uint16_t key_len;
567 569 uint32_t client_key;
568 570 char *path;
569 571 unsigned char resume_char;
570 572 unsigned char type;
571 573 smb_odir_t *od;
572 574
573 575 if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
574 576 return (SDRC_ERROR);
575 577
576 578 rc = smbsr_decode_data(sr, "%Abw", sr, &path, &type, &key_len);
577 579 if ((rc != 0) || (type != 0x05))
578 580 return (SDRC_ERROR);
579 581
580 582 if (key_len == 0) {
581 583 smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
582 584 ERRDOS, ERROR_INVALID_HANDLE);
583 585 return (SDRC_ERROR);
584 586 } else if (key_len != 21) {
585 587 return (SDRC_ERROR);
586 588 }
587 589
588 590 odid = 0;
589 591 if (smb_mbc_decodef(&sr->smb_data, "b12.wwl",
590 592 &resume_char, &index, &odid, &client_key) != 0) {
591 593 return (SDRC_ERROR);
592 594 }
593 595
594 596 od = smb_tree_lookup_odir(sr, odid);
595 597 if (od == NULL) {
596 598 smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
597 599 ERRDOS, ERROR_INVALID_HANDLE);
598 600 return (SDRC_ERROR);
599 601 }
600 602
601 603 smb_odir_close(od);
602 604 smb_odir_release(od);
603 605
604 606 if (smbsr_encode_result(sr, 1, 3, "bwwbw", 1, 0, 3, 5, 0))
605 607 return (SDRC_ERROR);
|
↓ open down ↓ |
38 lines elided |
↑ open up ↑ |
606 608
607 609 return (SDRC_SUCCESS);
608 610 }
609 611
610 612
611 613 /* *** smb_com_find_unique *** */
612 614
613 615 smb_sdrc_t
614 616 smb_pre_find_unique(smb_request_t *sr)
615 617 {
616 - DTRACE_SMB_1(op__FindUnique__start, smb_request_t *, sr);
618 + DTRACE_SMB_START(op__FindUnique, smb_request_t *, sr);
617 619 return (SDRC_SUCCESS);
618 620 }
619 621
620 622 void
621 623 smb_post_find_unique(smb_request_t *sr)
622 624 {
623 - DTRACE_SMB_1(op__FindUnique__done, smb_request_t *, sr);
625 + DTRACE_SMB_DONE(op__FindUnique, smb_request_t *, sr);
624 626 }
625 627
626 628 smb_sdrc_t
627 629 smb_com_find_unique(struct smb_request *sr)
628 630 {
629 631 int rc;
630 632 uint16_t count, maxcount, index;
631 633 uint16_t sattr;
632 634 smb_pathname_t *pn;
633 635 unsigned char resume_char = '\0';
634 636 uint32_t client_key = 0;
635 637 char name83[SMB_SHORTNAMELEN];
636 638 smb_odir_t *od;
637 639 smb_fileinfo_t fileinfo;
638 640 uint32_t status;
639 641 uint16_t eos;
640 642 smb_vdb_t *vdb;
641 643
642 644 if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
643 645 return (SDRC_ERROR);
644 646
645 647 pn = &sr->arg.dirop.fqi.fq_path;
646 648 vdb = kmem_alloc(sizeof (smb_vdb_t), KM_SLEEP);
647 649 if ((smbsr_decode_data(sr, "%AV", sr, &pn->pn_path, vdb) != 0) ||
648 650 (vdb->vdb_len != 0)) {
649 651 kmem_free(vdb, sizeof (smb_vdb_t));
650 652 return (SDRC_ERROR);
651 653 }
652 654 kmem_free(vdb, sizeof (smb_vdb_t));
653 655
654 656 smb_pathname_init(sr, pn, pn->pn_path);
655 657 if (!smb_pathname_validate(sr, pn))
656 658 return (SDRC_ERROR);
657 659
658 660 if (smb_is_stream_name(pn->pn_path)) {
659 661 smbsr_error(sr, NT_STATUS_OBJECT_NAME_INVALID,
660 662 ERRDOS, ERROR_INVALID_NAME);
661 663 return (SDRC_ERROR);
662 664 }
663 665
664 666 (void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0);
665 667
666 668 status = smb_odir_openpath(sr, pn->pn_path, sattr, 0, &od);
667 669 if (status != 0) {
668 670 smbsr_error(sr, status, 0, 0);
669 671 return (SDRC_ERROR);
670 672 }
671 673 if (od == NULL)
672 674 return (SDRC_ERROR);
673 675
674 676 rc = 0;
675 677 count = 0;
676 678 index = 0;
677 679 if (maxcount > SMB_MAX_SEARCH)
678 680 maxcount = SMB_MAX_SEARCH;
679 681
680 682 while (count < maxcount) {
681 683 rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos);
682 684 if (rc != 0 || eos != 0)
683 685 break;
|
↓ open down ↓ |
50 lines elided |
↑ open up ↑ |
684 686
685 687 if (*fileinfo.fi_shortname == '\0') {
686 688 if (smb_needs_mangled(fileinfo.fi_name))
687 689 continue;
688 690 (void) strlcpy(fileinfo.fi_shortname, fileinfo.fi_name,
689 691 SMB_SHORTNAMELEN - 1);
690 692 }
691 693 smb_name83(fileinfo.fi_shortname, name83, SMB_SHORTNAMELEN);
692 694
693 695 (void) smb_mbc_encodef(&sr->reply, "b11c.wwlbYl13c",
694 - resume_char, name83, index, od->d_odid,
695 - client_key, fileinfo.fi_dosattr & 0xff,
696 + resume_char, name83, index, od->d_odid, client_key,
697 + fileinfo.fi_dosattr & 0xff,
696 698 smb_time_gmt_to_local(sr, fileinfo.fi_mtime.tv_sec),
697 699 (int32_t)fileinfo.fi_size,
698 700 fileinfo.fi_shortname);
699 701
700 702 count++;
701 703 index++;
702 704 }
703 705 if (eos && rc == ENOENT)
704 706 rc = 0;
705 707
706 708 smb_odir_close(od);
707 709 smb_odir_release(od);
708 710
709 711 if (rc != 0)
710 712 return (SDRC_ERROR);
711 713
712 714 if (count == 0) {
713 715 smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
714 716 ERRDOS, ERROR_NO_MORE_FILES);
715 717 return (SDRC_ERROR);
716 718 }
717 719
718 720 rc = (MBC_LENGTH(&sr->reply) - sr->cur_reply_offset) - 8;
719 721 if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset,
720 722 "bwwbw", 1, count, rc+3, 5, rc) < 0) {
721 723 return (SDRC_ERROR);
722 724 }
723 725
724 726 return (SDRC_SUCCESS);
725 727 }
726 728
727 729 /*
728 730 * smb_name83
729 731 *
730 732 * Format the filename for inclusion in the resume key. The filename
731 733 * returned in the resume key is 11 bytes:
732 734 * - up to 8 bytes of filename, space padded to 8 bytes
733 735 * - up to 3 bytes of ext, space padded to 3 bytes
734 736 *
735 737 * The name passed to smb_name83 should be a shortname or a name that
736 738 * doesn't require mangling.
737 739 *
738 740 * Examples:
739 741 * "fname.txt" -> "FNAME TXT"
740 742 * "fname.tx" -> "FNAME TX "
741 743 * "filename" -> "FILENAME "
742 744 * "filename.txt" -> "FILENAMETXT"
743 745 * "FILE~1.TXT" -> "FILE~1 TXT"
744 746 */
745 747 static void
746 748 smb_name83(const char *name, char *buf, size_t buflen)
747 749 {
748 750 const char *p;
749 751 char *pbuf;
750 752 int i;
751 753
752 754 ASSERT(name && buf && (buflen >= SMB_NAME83_BUFLEN));
753 755
754 756 (void) strlcpy(buf, " ", SMB_NAME83_BUFLEN);
755 757
756 758 /* Process "." and ".." up front */
757 759 if ((strcmp(name, ".") == 0) || (strcmp(name, "..") == 0)) {
758 760 (void) strncpy(buf, name, strlen(name));
759 761 return;
760 762 }
761 763
762 764 ASSERT(smb_needs_mangled(name) == B_FALSE);
763 765
764 766 /* Process basename */
765 767 for (i = 0, p = name, pbuf = buf;
766 768 (i < SMB_NAME83_BASELEN) && (*p != '\0') && (*p != '.'); ++i)
767 769 *pbuf++ = *p++;
768 770
769 771 /* Process the extension from the last dot in name */
770 772 if ((p = strchr(name, '.')) != NULL) {
771 773 ++p;
772 774 pbuf = &buf[SMB_NAME83_BASELEN];
773 775 for (i = 0; (i < SMB_NAME83_EXTLEN) && (*p != '\0'); ++i)
774 776 *pbuf++ = *p++;
775 777 }
776 778
777 779 (void) smb_strupr(buf);
778 780 }
|
↓ open down ↓ |
73 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX