xref: /titanic_51/usr/src/uts/common/fs/smbsrv/smb_find.c (revision 7ff836697c120cb94bd30d5c2204eb9b74718e4c)
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, 0);
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 
353 	if (rc != 0) {
354 		smb_odir_close(od);
355 		smb_odir_release(od);
356 		return (SDRC_ERROR);
357 	}
358 
359 	if (count == 0 && find_first) {
360 		smb_odir_close(od);
361 		smb_odir_release(od);
362 		smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
363 		    ERRDOS, ERROR_NO_MORE_FILES);
364 		return (SDRC_ERROR);
365 	}
366 
367 	rc = (sr->reply.chain_offset - sr->cur_reply_offset) - 8;
368 	if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw",
369 	    1, count, rc+3, 5, rc) < 0) {
370 		smb_odir_close(od);
371 		smb_odir_release(od);
372 		return (SDRC_ERROR);
373 	}
374 
375 	smb_odir_release(od);
376 	return (SDRC_SUCCESS);
377 }
378 
379 
380 /* *** smb_com_find *** */
381 
382 smb_sdrc_t
383 smb_pre_find(smb_request_t *sr)
384 {
385 	DTRACE_SMB_1(op__Find__start, smb_request_t *, sr);
386 	return (SDRC_SUCCESS);
387 }
388 
389 void
390 smb_post_find(smb_request_t *sr)
391 {
392 	DTRACE_SMB_1(op__Find__done, smb_request_t *, sr);
393 }
394 
395 smb_sdrc_t
396 smb_com_find(smb_request_t *sr)
397 {
398 	int			rc;
399 	uint16_t		count, maxcount, index;
400 	uint16_t		sattr, odid;
401 	uint16_t		key_len;
402 	uint32_t		client_key;
403 	char			name[SMB_SHORTNAMELEN];
404 	smb_odir_t		*od;
405 	smb_fileinfo_t		fileinfo;
406 	boolean_t		eos;
407 
408 	char			*path;
409 	unsigned char		resume_char;
410 	unsigned char		type;
411 	boolean_t		find_first = B_TRUE;
412 	smb_odir_resume_t	odir_resume;
413 
414 	if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
415 		return (SDRC_ERROR);
416 
417 	rc = smbsr_decode_data(sr, "%Abw", sr, &path, &type, &key_len);
418 	if ((rc != 0) || (type != 0x05))
419 		return (SDRC_ERROR);
420 
421 	if ((key_len != 0) && (key_len != 21))
422 		return (SDRC_ERROR);
423 
424 	find_first = (key_len == 0);
425 	resume_char = 0;
426 	client_key = 0;
427 
428 	if (find_first) {
429 		odid = smb_odir_open(sr, path, sattr, 0);
430 		if (odid == 0)
431 			return (SDRC_ERROR);
432 	} else {
433 		if (smb_mbc_decodef(&sr->smb_data, "b12.wwl",
434 		    &resume_char, &index, &odid, &client_key) != 0) {
435 			return (SDRC_ERROR);
436 		}
437 	}
438 
439 	od = smb_tree_lookup_odir(sr->tid_tree, odid);
440 	if (od == NULL) {
441 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
442 		    ERRDOS, ERROR_INVALID_HANDLE);
443 		return (SDRC_ERROR);
444 	}
445 
446 	if (!find_first) {
447 		odir_resume.or_type = SMB_ODIR_RESUME_IDX;
448 		odir_resume.or_idx = index;
449 		smb_odir_resume_at(od, &odir_resume);
450 	}
451 
452 	(void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0);
453 
454 	rc = 0;
455 	index = 0;
456 	count = 0;
457 	if (maxcount > SMB_MAX_SEARCH)
458 		maxcount = SMB_MAX_SEARCH;
459 
460 	while (count < maxcount) {
461 		rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos);
462 		if ((rc != 0 || (eos == B_TRUE)))
463 			break;
464 
465 		(void) memset(name, ' ', sizeof (name));
466 		if (*fileinfo.fi_shortname == '\0') {
467 			(void) strlcpy(name, fileinfo.fi_name,
468 			    SMB_SHORTNAMELEN - 1);
469 		} else {
470 			(void) strlcpy(name, fileinfo.fi_shortname,
471 			    SMB_SHORTNAMELEN - 1);
472 		}
473 
474 		(void) smb_mbc_encodef(&sr->reply, "b8c3c.wwlbYl13c",
475 		    resume_char,
476 		    fileinfo.fi_name83, fileinfo.fi_name83+9,
477 		    index, odid, client_key,
478 		    fileinfo.fi_dosattr & 0xff,
479 		    smb_gmt2local(sr, fileinfo.fi_mtime.tv_sec),
480 		    (int32_t)fileinfo.fi_size,
481 		    name);
482 
483 		smb_odir_save_cookie(od, index, fileinfo.fi_cookie);
484 
485 		count++;
486 		index++;
487 	}
488 
489 	if (rc != 0) {
490 		smb_odir_close(od);
491 		smb_odir_release(od);
492 		return (SDRC_ERROR);
493 	}
494 
495 	if (count == 0 && find_first) {
496 		smb_odir_close(od);
497 		smb_odir_release(od);
498 		smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
499 		    ERRDOS, ERROR_NO_MORE_FILES);
500 		return (SDRC_ERROR);
501 	}
502 
503 	rc = (MBC_LENGTH(&sr->reply) - sr->cur_reply_offset) - 8;
504 	if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset, "bwwbw",
505 	    1, count, rc+3, 5, rc) < 0) {
506 		smb_odir_close(od);
507 		smb_odir_release(od);
508 		return (SDRC_ERROR);
509 	}
510 
511 	smb_odir_release(od);
512 	return (SDRC_SUCCESS);
513 }
514 
515 
516 /* *** smb_com_find_close *** */
517 
518 smb_sdrc_t
519 smb_pre_find_close(smb_request_t *sr)
520 {
521 	DTRACE_SMB_1(op__FindClose__start, smb_request_t *, sr);
522 	return (SDRC_SUCCESS);
523 }
524 
525 void
526 smb_post_find_close(smb_request_t *sr)
527 {
528 	DTRACE_SMB_1(op__FindClose__done, smb_request_t *, sr);
529 }
530 
531 smb_sdrc_t
532 smb_com_find_close(smb_request_t *sr)
533 {
534 	int		rc;
535 	uint16_t	maxcount, index;
536 	uint16_t	sattr, odid;
537 	uint16_t	key_len;
538 	uint32_t	client_key;
539 	char		*path;
540 	unsigned char	resume_char;
541 	unsigned char	type;
542 	smb_odir_t	*od;
543 
544 	if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
545 		return (SDRC_ERROR);
546 
547 	rc = smbsr_decode_data(sr, "%Abw", sr, &path, &type, &key_len);
548 	if ((rc != 0) || (type != 0x05))
549 		return (SDRC_ERROR);
550 
551 	if (key_len == 0) {
552 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
553 		    ERRDOS, ERROR_INVALID_HANDLE);
554 		return (SDRC_ERROR);
555 	} else if (key_len != 21) {
556 		return (SDRC_ERROR);
557 	}
558 
559 	odid = 0;
560 	if (smb_mbc_decodef(&sr->smb_data, "b12.wwl",
561 	    &resume_char, &index, &odid, &client_key) != 0) {
562 		return (SDRC_ERROR);
563 	}
564 
565 	od = smb_tree_lookup_odir(sr->tid_tree, odid);
566 	if (od == NULL) {
567 		smbsr_error(sr, NT_STATUS_INVALID_HANDLE,
568 		    ERRDOS, ERROR_INVALID_HANDLE);
569 		return (SDRC_ERROR);
570 	}
571 
572 	smb_odir_close(od);
573 	smb_odir_release(od);
574 
575 	if (smbsr_encode_result(sr, 1, 3, "bwwbw", 1, 0, 3, 5, 0))
576 		return (SDRC_ERROR);
577 
578 	return (SDRC_SUCCESS);
579 }
580 
581 
582 /* *** smb_com_find_unique *** */
583 
584 smb_sdrc_t
585 smb_pre_find_unique(smb_request_t *sr)
586 {
587 	DTRACE_SMB_1(op__FindUnique__start, smb_request_t *, sr);
588 	return (SDRC_SUCCESS);
589 }
590 
591 void
592 smb_post_find_unique(smb_request_t *sr)
593 {
594 	DTRACE_SMB_1(op__FindUnique__done, smb_request_t *, sr);
595 }
596 
597 smb_sdrc_t
598 smb_com_find_unique(struct smb_request *sr)
599 {
600 	int			rc;
601 	uint16_t		count, maxcount, index;
602 	uint16_t		sattr, odid;
603 	char			*path;
604 	unsigned char		resume_char = '\0';
605 	uint32_t		client_key = 0;
606 	char			name[SMB_SHORTNAMELEN];
607 	smb_odir_t		*od;
608 	smb_fileinfo_t		fileinfo;
609 	boolean_t		eos;
610 	smb_vdb_t		*vdb;
611 
612 	if (smbsr_decode_vwv(sr, "ww", &maxcount, &sattr) != 0)
613 		return (SDRC_ERROR);
614 
615 	vdb = kmem_alloc(sizeof (smb_vdb_t), KM_SLEEP);
616 	if ((smbsr_decode_data(sr, "%AV", sr, &path, vdb) != 0) ||
617 	    (vdb->vdb_len != 0)) {
618 		kmem_free(vdb, sizeof (smb_vdb_t));
619 		return (SDRC_ERROR);
620 	}
621 	kmem_free(vdb, sizeof (smb_vdb_t));
622 
623 	(void) smb_mbc_encodef(&sr->reply, "bwwbw", 1, 0, VAR_BCC, 5, 0);
624 
625 	odid = smb_odir_open(sr, path, sattr, 0);
626 	if (odid == 0)
627 		return (SDRC_ERROR);
628 	od = smb_tree_lookup_odir(sr->tid_tree, odid);
629 	if (od == NULL)
630 		return (SDRC_ERROR);
631 
632 	rc = 0;
633 	count = 0;
634 	index = 0;
635 	if (maxcount > SMB_MAX_SEARCH)
636 		maxcount = SMB_MAX_SEARCH;
637 
638 	while (count < maxcount) {
639 		rc = smb_odir_read_fileinfo(sr, od, &fileinfo, &eos);
640 		if ((rc != 0 || (eos == B_TRUE)))
641 			break;
642 
643 		(void) memset(name, ' ', sizeof (name));
644 		if (*fileinfo.fi_shortname == '\0') {
645 			(void) strlcpy(name, fileinfo.fi_name,
646 			    SMB_SHORTNAMELEN - 1);
647 		} else {
648 			(void) strlcpy(name, fileinfo.fi_shortname,
649 			    SMB_SHORTNAMELEN - 1);
650 		}
651 
652 		(void) smb_mbc_encodef(&sr->reply, "b8c3c.wwlbYl13c",
653 		    resume_char,
654 		    fileinfo.fi_name83, fileinfo.fi_name83+9,
655 		    index, odid, client_key,
656 		    fileinfo.fi_dosattr & 0xff,
657 		    smb_gmt2local(sr, fileinfo.fi_mtime.tv_sec),
658 		    (int32_t)fileinfo.fi_size,
659 		    name);
660 
661 		count++;
662 		index++;
663 	}
664 
665 	smb_odir_close(od);
666 	smb_odir_release(od);
667 
668 	if (rc != 0)
669 		return (SDRC_ERROR);
670 
671 	if (count == 0) {
672 		smbsr_warn(sr, NT_STATUS_NO_MORE_FILES,
673 		    ERRDOS, ERROR_NO_MORE_FILES);
674 		return (SDRC_ERROR);
675 	}
676 
677 	rc = (MBC_LENGTH(&sr->reply) - sr->cur_reply_offset) - 8;
678 	if (smb_mbc_poke(&sr->reply, sr->cur_reply_offset,
679 	    "bwwbw", 1, count, rc+3, 5, rc) < 0) {
680 		return (SDRC_ERROR);
681 	}
682 
683 	return (SDRC_SUCCESS);
684 }
685