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