2 Unix SMB/CIFS implementation.
4 POSIX NTVFS backend - directory search functions
6 Copyright (C) Andrew Tridgell 2004
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "vfs_posix.h"
25 #include "system/time.h"
26 #include "librpc/gen_ndr/security.h"
27 #include "smbd/service_stream.h"
28 #include "lib/events/events.h"
29 #include "lib/util/dlinklist.h"
31 /* place a reasonable limit on old-style searches as clients tend to
32 not send search close requests */
33 #define MAX_OLD_SEARCHES 2000
34 #define MAX_SEARCH_HANDLES (UINT16_MAX - 1)
35 #define INVALID_SEARCH_HANDLE UINT16_MAX
38 destroy an open search
40 static int pvfs_search_destructor(struct pvfs_search_state *search)
42 DLIST_REMOVE(search->pvfs->search.list, search);
43 idr_remove(search->pvfs->search.idtree, search->handle);
48 called when a search timer goes off
50 static void pvfs_search_timer(struct event_context *ev, struct timed_event *te,
51 struct timeval t, void *ptr)
53 struct pvfs_search_state *search = talloc_get_type(ptr, struct pvfs_search_state);
58 setup a timer to destroy a open search after a inactivity period
60 static void pvfs_search_setup_timer(struct pvfs_search_state *search)
62 struct event_context *ev = search->pvfs->ntvfs->ctx->event_ctx;
63 if (search->handle == INVALID_SEARCH_HANDLE) return;
64 talloc_free(search->te);
65 search->te = event_add_timed(ev, search,
66 timeval_current_ofs(search->pvfs->search.inactivity_time, 0),
67 pvfs_search_timer, search);
71 fill in a single search result for a given info level
73 static NTSTATUS fill_search_info(struct pvfs_state *pvfs,
74 enum smb_search_data_level level,
75 const char *unix_path,
77 struct pvfs_search_state *search,
79 union smb_search_data *file)
81 struct pvfs_filename *name;
83 const char *shortname;
85 status = pvfs_resolve_partial(pvfs, file, unix_path, fname, &name);
86 if (!NT_STATUS_IS_OK(status)) {
90 status = pvfs_match_attrib(pvfs, name, search->search_attrib, search->must_attrib);
91 if (!NT_STATUS_IS_OK(status)) {
96 case RAW_SEARCH_DATA_SEARCH:
97 shortname = pvfs_short_name(pvfs, name, name);
98 file->search.attrib = name->dos.attrib;
99 file->search.write_time = nt_time_to_unix(name->dos.write_time);
100 file->search.size = name->st.st_size;
101 file->search.name = shortname;
102 file->search.id.reserved = search->handle >> 8;
103 memset(file->search.id.name, ' ', sizeof(file->search.id.name));
104 memcpy(file->search.id.name, shortname,
105 MIN(strlen(shortname)+1, sizeof(file->search.id.name)));
106 file->search.id.handle = search->handle & 0xFF;
107 file->search.id.server_cookie = dir_index;
108 file->search.id.client_cookie = 0;
111 case RAW_SEARCH_DATA_STANDARD:
112 file->standard.resume_key = dir_index;
113 file->standard.create_time = nt_time_to_unix(name->dos.create_time);
114 file->standard.access_time = nt_time_to_unix(name->dos.access_time);
115 file->standard.write_time = nt_time_to_unix(name->dos.write_time);
116 file->standard.size = name->st.st_size;
117 file->standard.alloc_size = name->dos.alloc_size;
118 file->standard.attrib = name->dos.attrib;
119 file->standard.name.s = fname;
122 case RAW_SEARCH_DATA_EA_SIZE:
123 file->ea_size.resume_key = dir_index;
124 file->ea_size.create_time = nt_time_to_unix(name->dos.create_time);
125 file->ea_size.access_time = nt_time_to_unix(name->dos.access_time);
126 file->ea_size.write_time = nt_time_to_unix(name->dos.write_time);
127 file->ea_size.size = name->st.st_size;
128 file->ea_size.alloc_size = name->dos.alloc_size;
129 file->ea_size.attrib = name->dos.attrib;
130 file->ea_size.ea_size = name->dos.ea_size;
131 file->ea_size.name.s = fname;
134 case RAW_SEARCH_DATA_EA_LIST:
135 file->ea_list.resume_key = dir_index;
136 file->ea_list.create_time = nt_time_to_unix(name->dos.create_time);
137 file->ea_list.access_time = nt_time_to_unix(name->dos.access_time);
138 file->ea_list.write_time = nt_time_to_unix(name->dos.write_time);
139 file->ea_list.size = name->st.st_size;
140 file->ea_list.alloc_size = name->dos.alloc_size;
141 file->ea_list.attrib = name->dos.attrib;
142 file->ea_list.name.s = fname;
143 return pvfs_query_ea_list(pvfs, file, name, -1,
144 search->num_ea_names,
148 case RAW_SEARCH_DATA_DIRECTORY_INFO:
149 file->directory_info.file_index = dir_index;
150 file->directory_info.create_time = name->dos.create_time;
151 file->directory_info.access_time = name->dos.access_time;
152 file->directory_info.write_time = name->dos.write_time;
153 file->directory_info.change_time = name->dos.change_time;
154 file->directory_info.size = name->st.st_size;
155 file->directory_info.alloc_size = name->dos.alloc_size;
156 file->directory_info.attrib = name->dos.attrib;
157 file->directory_info.name.s = fname;
160 case RAW_SEARCH_DATA_FULL_DIRECTORY_INFO:
161 file->full_directory_info.file_index = dir_index;
162 file->full_directory_info.create_time = name->dos.create_time;
163 file->full_directory_info.access_time = name->dos.access_time;
164 file->full_directory_info.write_time = name->dos.write_time;
165 file->full_directory_info.change_time = name->dos.change_time;
166 file->full_directory_info.size = name->st.st_size;
167 file->full_directory_info.alloc_size = name->dos.alloc_size;
168 file->full_directory_info.attrib = name->dos.attrib;
169 file->full_directory_info.ea_size = name->dos.ea_size;
170 file->full_directory_info.name.s = fname;
173 case RAW_SEARCH_DATA_NAME_INFO:
174 file->name_info.file_index = dir_index;
175 file->name_info.name.s = fname;
178 case RAW_SEARCH_DATA_BOTH_DIRECTORY_INFO:
179 file->both_directory_info.file_index = dir_index;
180 file->both_directory_info.create_time = name->dos.create_time;
181 file->both_directory_info.access_time = name->dos.access_time;
182 file->both_directory_info.write_time = name->dos.write_time;
183 file->both_directory_info.change_time = name->dos.change_time;
184 file->both_directory_info.size = name->st.st_size;
185 file->both_directory_info.alloc_size = name->dos.alloc_size;
186 file->both_directory_info.attrib = name->dos.attrib;
187 file->both_directory_info.ea_size = name->dos.ea_size;
188 file->both_directory_info.short_name.s = pvfs_short_name(pvfs, file, name);
189 file->both_directory_info.name.s = fname;
192 case RAW_SEARCH_DATA_ID_FULL_DIRECTORY_INFO:
193 file->id_full_directory_info.file_index = dir_index;
194 file->id_full_directory_info.create_time = name->dos.create_time;
195 file->id_full_directory_info.access_time = name->dos.access_time;
196 file->id_full_directory_info.write_time = name->dos.write_time;
197 file->id_full_directory_info.change_time = name->dos.change_time;
198 file->id_full_directory_info.size = name->st.st_size;
199 file->id_full_directory_info.alloc_size = name->dos.alloc_size;
200 file->id_full_directory_info.attrib = name->dos.attrib;
201 file->id_full_directory_info.ea_size = name->dos.ea_size;
202 file->id_full_directory_info.file_id = name->dos.file_id;
203 file->id_full_directory_info.name.s = fname;
206 case RAW_SEARCH_DATA_ID_BOTH_DIRECTORY_INFO:
207 file->id_both_directory_info.file_index = dir_index;
208 file->id_both_directory_info.create_time = name->dos.create_time;
209 file->id_both_directory_info.access_time = name->dos.access_time;
210 file->id_both_directory_info.write_time = name->dos.write_time;
211 file->id_both_directory_info.change_time = name->dos.change_time;
212 file->id_both_directory_info.size = name->st.st_size;
213 file->id_both_directory_info.alloc_size = name->dos.alloc_size;
214 file->id_both_directory_info.attrib = name->dos.attrib;
215 file->id_both_directory_info.ea_size = name->dos.ea_size;
216 file->id_both_directory_info.file_id = name->dos.file_id;
217 file->id_both_directory_info.short_name.s = pvfs_short_name(pvfs, file, name);
218 file->id_both_directory_info.name.s = fname;
221 case RAW_SEARCH_DATA_GENERIC:
225 return NT_STATUS_INVALID_LEVEL;
232 static NTSTATUS pvfs_search_fill(struct pvfs_state *pvfs, TALLOC_CTX *mem_ctx,
234 struct pvfs_search_state *search,
235 enum smb_search_data_level level,
237 void *search_private,
238 BOOL (*callback)(void *, union smb_search_data *))
240 struct pvfs_dir *dir = search->dir;
245 if (max_count == 0) {
249 while ((*reply_count) < max_count) {
250 union smb_search_data *file;
252 uint_t ofs = search->current_index;
254 name = pvfs_list_next(dir, &search->current_index);
255 if (name == NULL) break;
257 file = talloc(mem_ctx, union smb_search_data);
259 return NT_STATUS_NO_MEMORY;
262 status = fill_search_info(pvfs, level,
263 pvfs_list_unix_path(dir), name,
264 search, search->current_index, file);
265 if (!NT_STATUS_IS_OK(status)) {
270 if (!callback(search_private, file)) {
272 search->current_index = ofs;
280 pvfs_search_setup_timer(search);
286 we've run out of search handles - cleanup those that the client forgot
289 static void pvfs_search_cleanup(struct pvfs_state *pvfs)
292 time_t t = time(NULL);
294 for (i=0;i<MAX_OLD_SEARCHES;i++) {
295 struct pvfs_search_state *search = idr_find(pvfs->search.idtree, i);
296 if (search == NULL) return;
297 if (pvfs_list_eos(search->dir, search->current_index) &&
298 search->last_used != 0 &&
299 t > search->last_used + 30) {
300 /* its almost certainly been forgotten
309 list files in a directory matching a wildcard pattern - old SMBsearch interface
311 static NTSTATUS pvfs_search_first_old(struct ntvfs_module_context *ntvfs,
312 struct ntvfs_request *req, union smb_search_first *io,
313 void *search_private,
314 BOOL (*callback)(void *, union smb_search_data *))
316 struct pvfs_dir *dir;
317 struct pvfs_state *pvfs = ntvfs->private_data;
318 struct pvfs_search_state *search;
320 uint16_t search_attrib;
323 struct pvfs_filename *name;
326 search_attrib = io->search_first.in.search_attrib;
327 pattern = io->search_first.in.pattern;
329 /* resolve the cifs name to a posix name */
330 status = pvfs_resolve_name(pvfs, req, pattern, PVFS_RESOLVE_WILDCARD, &name);
331 if (!NT_STATUS_IS_OK(status)) {
335 if (!name->has_wildcard && !name->exists) {
336 return STATUS_NO_MORE_FILES;
339 status = pvfs_access_check_parent(pvfs, req, name, SEC_DIR_TRAVERSE | SEC_DIR_LIST);
340 if (!NT_STATUS_IS_OK(status)) {
344 /* we initially make search a child of the request, then if we
345 need to keep it long term we steal it for the private
347 search = talloc(req, struct pvfs_search_state);
349 return NT_STATUS_NO_MEMORY;
352 /* do the actual directory listing */
353 status = pvfs_list_start(pvfs, name, search, &dir);
354 if (!NT_STATUS_IS_OK(status)) {
358 /* we need to give a handle back to the client so it
359 can continue a search */
360 id = idr_get_new(pvfs->search.idtree, search, MAX_OLD_SEARCHES);
362 pvfs_search_cleanup(pvfs);
363 id = idr_get_new(pvfs->search.idtree, search, MAX_OLD_SEARCHES);
366 return NT_STATUS_INSUFFICIENT_RESOURCES;
372 search->current_index = 0;
373 search->search_attrib = search_attrib & 0xFF;
374 search->must_attrib = (search_attrib>>8) & 0xFF;
375 search->last_used = time(NULL);
378 DLIST_ADD(pvfs->search.list, search);
380 talloc_set_destructor(search, pvfs_search_destructor);
382 status = pvfs_search_fill(pvfs, req, io->search_first.in.max_count, search, io->generic.data_level,
383 &reply_count, search_private, callback);
384 if (!NT_STATUS_IS_OK(status)) {
388 io->search_first.out.count = reply_count;
390 /* not matching any entries is an error */
391 if (reply_count == 0) {
392 return STATUS_NO_MORE_FILES;
395 talloc_steal(pvfs, search);
400 /* continue a old style search */
401 static NTSTATUS pvfs_search_next_old(struct ntvfs_module_context *ntvfs,
402 struct ntvfs_request *req, union smb_search_next *io,
403 void *search_private,
404 BOOL (*callback)(void *, union smb_search_data *))
406 struct pvfs_state *pvfs = ntvfs->private_data;
407 struct pvfs_search_state *search;
408 struct pvfs_dir *dir;
409 uint_t reply_count, max_count;
413 handle = io->search_next.in.id.handle | (io->search_next.in.id.reserved<<8);
414 max_count = io->search_next.in.max_count;
416 search = idr_find(pvfs->search.idtree, handle);
417 if (search == NULL) {
418 /* we didn't find the search handle */
419 return NT_STATUS_INVALID_HANDLE;
422 search->current_index = io->search_next.in.id.server_cookie;
423 search->last_used = time(NULL);
426 status = pvfs_search_fill(pvfs, req, max_count, search, io->generic.data_level,
427 &reply_count, search_private, callback);
428 if (!NT_STATUS_IS_OK(status)) {
432 io->search_next.out.count = reply_count;
434 /* not matching any entries means end of search */
435 if (reply_count == 0) {
443 list files in a directory matching a wildcard pattern
445 static NTSTATUS pvfs_search_first_trans2(struct ntvfs_module_context *ntvfs,
446 struct ntvfs_request *req, union smb_search_first *io,
447 void *search_private,
448 BOOL (*callback)(void *, union smb_search_data *))
450 struct pvfs_dir *dir;
451 struct pvfs_state *pvfs = ntvfs->private_data;
452 struct pvfs_search_state *search;
454 uint16_t search_attrib, max_count;
457 struct pvfs_filename *name;
460 search_attrib = io->t2ffirst.in.search_attrib;
461 pattern = io->t2ffirst.in.pattern;
462 max_count = io->t2ffirst.in.max_count;
464 /* resolve the cifs name to a posix name */
465 status = pvfs_resolve_name(pvfs, req, pattern, PVFS_RESOLVE_WILDCARD, &name);
466 if (!NT_STATUS_IS_OK(status)) {
470 if (!name->has_wildcard && !name->exists) {
471 return NT_STATUS_NO_SUCH_FILE;
474 status = pvfs_access_check_parent(pvfs, req, name, SEC_DIR_TRAVERSE | SEC_DIR_LIST);
475 if (!NT_STATUS_IS_OK(status)) {
479 /* we initially make search a child of the request, then if we
480 need to keep it long term we steal it for the private
482 search = talloc(req, struct pvfs_search_state);
484 return NT_STATUS_NO_MEMORY;
487 /* do the actual directory listing */
488 status = pvfs_list_start(pvfs, name, search, &dir);
489 if (!NT_STATUS_IS_OK(status)) {
493 id = idr_get_new(pvfs->search.idtree, search, MAX_SEARCH_HANDLES);
495 return NT_STATUS_INSUFFICIENT_RESOURCES;
501 search->current_index = 0;
502 search->search_attrib = search_attrib;
503 search->must_attrib = 0;
504 search->last_used = 0;
505 search->num_ea_names = io->t2ffirst.in.num_names;
506 search->ea_names = io->t2ffirst.in.ea_names;
509 DLIST_ADD(pvfs->search.list, search);
510 talloc_set_destructor(search, pvfs_search_destructor);
512 status = pvfs_search_fill(pvfs, req, max_count, search, io->generic.data_level,
513 &reply_count, search_private, callback);
514 if (!NT_STATUS_IS_OK(status)) {
518 /* not matching any entries is an error */
519 if (reply_count == 0) {
520 return NT_STATUS_NO_SUCH_FILE;
523 io->t2ffirst.out.count = reply_count;
524 io->t2ffirst.out.handle = search->handle;
525 io->t2ffirst.out.end_of_search = pvfs_list_eos(dir, search->current_index) ? 1 : 0;
527 /* work out if we are going to keep the search state
528 and allow for a search continue */
529 if ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
530 ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) &&
531 io->t2ffirst.out.end_of_search)) {
534 talloc_steal(pvfs, search);
540 /* continue a search */
541 static NTSTATUS pvfs_search_next_trans2(struct ntvfs_module_context *ntvfs,
542 struct ntvfs_request *req, union smb_search_next *io,
543 void *search_private,
544 BOOL (*callback)(void *, union smb_search_data *))
546 struct pvfs_state *pvfs = ntvfs->private_data;
547 struct pvfs_search_state *search;
548 struct pvfs_dir *dir;
553 handle = io->t2fnext.in.handle;
555 search = idr_find(pvfs->search.idtree, handle);
556 if (search == NULL) {
557 /* we didn't find the search handle */
558 return NT_STATUS_INVALID_HANDLE;
563 /* work out what type of continuation is being used */
564 if (io->t2fnext.in.last_name && *io->t2fnext.in.last_name) {
565 status = pvfs_list_seek(dir, io->t2fnext.in.last_name, &search->current_index);
566 if (!NT_STATUS_IS_OK(status)) {
567 if (io->t2fnext.in.resume_key) {
568 search->current_index = io->t2fnext.in.resume_key;
573 } else if (io->t2fnext.in.flags & FLAG_TRANS2_FIND_CONTINUE) {
574 /* plain continue - nothing to do */
576 search->current_index = io->t2fnext.in.resume_key;
579 search->num_ea_names = io->t2fnext.in.num_names;
580 search->ea_names = io->t2fnext.in.ea_names;
582 status = pvfs_search_fill(pvfs, req, io->t2fnext.in.max_count, search, io->generic.data_level,
583 &reply_count, search_private, callback);
584 if (!NT_STATUS_IS_OK(status)) {
588 io->t2fnext.out.count = reply_count;
589 io->t2fnext.out.end_of_search = pvfs_list_eos(dir, search->current_index) ? 1 : 0;
591 /* work out if we are going to keep the search state */
592 if ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
593 ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) &&
594 io->t2fnext.out.end_of_search)) {
601 static NTSTATUS pvfs_search_first_smb2(struct ntvfs_module_context *ntvfs,
602 struct ntvfs_request *req, const struct smb2_find *io,
603 void *search_private,
604 BOOL (*callback)(void *, union smb_search_data *))
606 struct pvfs_dir *dir;
607 struct pvfs_state *pvfs = ntvfs->private_data;
608 struct pvfs_search_state *search;
613 struct pvfs_filename *name;
616 f = pvfs_find_fd(pvfs, req, io->in.file.ntvfs);
618 return NT_STATUS_FILE_CLOSED;
621 /* its only valid for directories */
622 if (f->handle->fd != -1) {
623 return NT_STATUS_INVALID_PARAMETER;
626 if (!(f->access_mask & SEC_DIR_LIST)) {
627 return NT_STATUS_ACCESS_DENIED;
631 talloc_free(f->search);
635 if (strequal(io->in.pattern, "")) {
636 return NT_STATUS_OBJECT_NAME_INVALID;
638 if (strchr_m(io->in.pattern, '\\')) {
639 return NT_STATUS_OBJECT_NAME_INVALID;
641 if (strchr_m(io->in.pattern, '/')) {
642 return NT_STATUS_OBJECT_NAME_INVALID;
645 if (strequal("", f->handle->name->original_name)) {
646 pattern = talloc_asprintf(req, "\\%s", io->in.pattern);
647 NT_STATUS_HAVE_NO_MEMORY(pattern);
649 pattern = talloc_asprintf(req, "\\%s\\%s",
650 f->handle->name->original_name,
652 NT_STATUS_HAVE_NO_MEMORY(pattern);
655 /* resolve the cifs name to a posix name */
656 status = pvfs_resolve_name(pvfs, req, pattern, PVFS_RESOLVE_WILDCARD, &name);
657 NT_STATUS_NOT_OK_RETURN(status);
659 if (!name->has_wildcard && !name->exists) {
660 return NT_STATUS_NO_SUCH_FILE;
663 /* we initially make search a child of the request, then if we
664 need to keep it long term we steal it for the private
666 search = talloc(req, struct pvfs_search_state);
667 NT_STATUS_HAVE_NO_MEMORY(search);
669 /* do the actual directory listing */
670 status = pvfs_list_start(pvfs, name, search, &dir);
671 NT_STATUS_NOT_OK_RETURN(status);
674 search->handle = INVALID_SEARCH_HANDLE;
676 search->current_index = 0;
677 search->search_attrib = 0;
678 search->must_attrib = 0;
679 search->last_used = 0;
680 search->num_ea_names = 0;
681 search->ea_names = NULL;
684 if (io->in.continue_flags & SMB2_CONTINUE_FLAG_SINGLE) {
687 max_count = UINT16_MAX;
690 status = pvfs_search_fill(pvfs, req, max_count, search, io->data_level,
691 &reply_count, search_private, callback);
692 NT_STATUS_NOT_OK_RETURN(status);
694 /* not matching any entries is an error */
695 if (reply_count == 0) {
696 return NT_STATUS_NO_SUCH_FILE;
699 f->search = talloc_steal(f, search);
704 static NTSTATUS pvfs_search_next_smb2(struct ntvfs_module_context *ntvfs,
705 struct ntvfs_request *req, const struct smb2_find *io,
706 void *search_private,
707 BOOL (*callback)(void *, union smb_search_data *))
709 struct pvfs_state *pvfs = ntvfs->private_data;
710 struct pvfs_search_state *search;
716 f = pvfs_find_fd(pvfs, req, io->in.file.ntvfs);
718 return NT_STATUS_FILE_CLOSED;
721 /* its only valid for directories */
722 if (f->handle->fd != -1) {
723 return NT_STATUS_INVALID_PARAMETER;
726 /* if there's no search started on the dir handle, it's like a search_first */
729 return pvfs_search_first_smb2(ntvfs, req, io, search_private, callback);
732 if (io->in.continue_flags & SMB2_CONTINUE_FLAG_RESTART) {
733 search->current_index = 0;
736 if (io->in.continue_flags & SMB2_CONTINUE_FLAG_SINGLE) {
739 max_count = UINT16_MAX;
742 status = pvfs_search_fill(pvfs, req, max_count, search, io->data_level,
743 &reply_count, search_private, callback);
744 NT_STATUS_NOT_OK_RETURN(status);
746 /* not matching any entries is an error */
747 if (reply_count == 0) {
748 return STATUS_NO_MORE_FILES;
755 list files in a directory matching a wildcard pattern
757 NTSTATUS pvfs_search_first(struct ntvfs_module_context *ntvfs,
758 struct ntvfs_request *req, union smb_search_first *io,
759 void *search_private,
760 BOOL (*callback)(void *, union smb_search_data *))
762 switch (io->generic.level) {
763 case RAW_SEARCH_SEARCH:
764 case RAW_SEARCH_FFIRST:
765 case RAW_SEARCH_FUNIQUE:
766 return pvfs_search_first_old(ntvfs, req, io, search_private, callback);
768 case RAW_SEARCH_TRANS2:
769 return pvfs_search_first_trans2(ntvfs, req, io, search_private, callback);
771 case RAW_SEARCH_SMB2:
772 return pvfs_search_first_smb2(ntvfs, req, &io->smb2, search_private, callback);
775 return NT_STATUS_INVALID_LEVEL;
778 /* continue a search */
779 NTSTATUS pvfs_search_next(struct ntvfs_module_context *ntvfs,
780 struct ntvfs_request *req, union smb_search_next *io,
781 void *search_private,
782 BOOL (*callback)(void *, union smb_search_data *))
784 switch (io->generic.level) {
785 case RAW_SEARCH_SEARCH:
786 case RAW_SEARCH_FFIRST:
787 return pvfs_search_next_old(ntvfs, req, io, search_private, callback);
789 case RAW_SEARCH_FUNIQUE:
790 return NT_STATUS_INVALID_LEVEL;
792 case RAW_SEARCH_TRANS2:
793 return pvfs_search_next_trans2(ntvfs, req, io, search_private, callback);
795 case RAW_SEARCH_SMB2:
796 return pvfs_search_next_smb2(ntvfs, req, &io->smb2, search_private, callback);
799 return NT_STATUS_INVALID_LEVEL;
804 NTSTATUS pvfs_search_close(struct ntvfs_module_context *ntvfs,
805 struct ntvfs_request *req, union smb_search_close *io)
807 struct pvfs_state *pvfs = ntvfs->private_data;
808 struct pvfs_search_state *search;
809 uint16_t handle = INVALID_SEARCH_HANDLE;
811 switch (io->generic.level) {
812 case RAW_FINDCLOSE_GENERIC:
813 return NT_STATUS_INVALID_LEVEL;
815 case RAW_FINDCLOSE_FCLOSE:
816 handle = io->fclose.in.id.handle;
819 case RAW_FINDCLOSE_FINDCLOSE:
820 handle = io->findclose.in.handle;
824 search = idr_find(pvfs->search.idtree, handle);
825 if (search == NULL) {
826 /* we didn't find the search handle */
827 return NT_STATUS_INVALID_HANDLE;