Add streams support
[Samba.git] / source / smbd / filename.c
blob1d44c7498e951e3ae9d422d9692f4e93788b74fc
1 /*
2 Unix SMB/CIFS implementation.
3 filename handling routines
4 Copyright (C) Andrew Tridgell 1992-1998
5 Copyright (C) Jeremy Allison 1999-2007
6 Copyright (C) Ying Chen 2000
7 Copyright (C) Volker Lendecke 2007
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 * New hash table stat cache code added by Ying Chen.
27 #include "includes.h"
29 static bool scan_directory(connection_struct *conn, const char *path,
30 char *name, char **found_name);
31 static NTSTATUS build_stream_path(TALLOC_CTX *mem_ctx,
32 connection_struct *conn,
33 const char *orig_path,
34 const char *basepath,
35 const char *streamname,
36 SMB_STRUCT_STAT *pst,
37 char **path);
39 /****************************************************************************
40 Mangle the 2nd name and check if it is then equal to the first name.
41 ****************************************************************************/
43 static bool mangled_equal(const char *name1,
44 const char *name2,
45 const struct share_params *p)
47 char mname[13];
49 if (!name_to_8_3(name2, mname, False, p)) {
50 return False;
52 return strequal(name1, mname);
55 /****************************************************************************
56 Cope with the differing wildcard and non-wildcard error cases.
57 ****************************************************************************/
59 static NTSTATUS determine_path_error(const char *name,
60 bool allow_wcard_last_component)
62 const char *p;
64 if (!allow_wcard_last_component) {
65 /* Error code within a pathname. */
66 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
69 /* We're terminating here so we
70 * can be a little slower and get
71 * the error code right. Windows
72 * treats the last part of the pathname
73 * separately I think, so if the last
74 * component is a wildcard then we treat
75 * this ./ as "end of component" */
77 p = strchr(name, '/');
79 if (!p && (ms_has_wild(name) || ISDOT(name))) {
80 /* Error code at the end of a pathname. */
81 return NT_STATUS_OBJECT_NAME_INVALID;
82 } else {
83 /* Error code within a pathname. */
84 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
88 /****************************************************************************
89 This routine is called to convert names from the dos namespace to unix
90 namespace. It needs to handle any case conversions, mangling, format
91 changes etc.
93 We assume that we have already done a chdir() to the right "root" directory
94 for this service.
96 The function will return an NTSTATUS error if some part of the name except for
97 the last part cannot be resolved, else NT_STATUS_OK.
99 Note NT_STATUS_OK doesn't mean the name exists or is valid, just that we didn't
100 get any fatal errors that should immediately terminate the calling
101 SMB processing whilst resolving.
103 If the saved_last_component != 0, then the unmodified last component
104 of the pathname is returned there. This is used in an exceptional
105 case in reply_mv (so far). If saved_last_component == 0 then nothing
106 is returned there.
108 If last_component_wcard is true then a MS wildcard was detected and
109 should be allowed in the last component of the path only.
111 On exit from unix_convert, if *pst was not null, then the file stat
112 struct will be returned if the file exists and was found, if not this
113 stat struct will be filled with zeros (and this can be detected by checking
114 for nlinks = 0, which can never be true for any file).
115 ****************************************************************************/
117 NTSTATUS unix_convert(TALLOC_CTX *ctx,
118 connection_struct *conn,
119 const char *orig_path,
120 bool allow_wcard_last_component,
121 char **pp_conv_path,
122 char **pp_saved_last_component,
123 SMB_STRUCT_STAT *pst)
125 SMB_STRUCT_STAT st;
126 char *start, *end;
127 char *dirpath = NULL;
128 char *name = NULL;
129 char *stream = NULL;
130 bool component_was_mangled = False;
131 bool name_has_wildcard = False;
132 NTSTATUS result;
134 SET_STAT_INVALID(*pst);
135 *pp_conv_path = NULL;
136 if(pp_saved_last_component) {
137 *pp_saved_last_component = NULL;
140 if (conn->printer) {
141 /* we don't ever use the filenames on a printer share as a
142 filename - so don't convert them */
143 if (!(*pp_conv_path = talloc_strdup(ctx,orig_path))) {
144 return NT_STATUS_NO_MEMORY;
146 return NT_STATUS_OK;
149 DEBUG(5, ("unix_convert called on file \"%s\"\n", orig_path));
152 * Conversion to basic unix format is already done in
153 * check_path_syntax().
157 * Names must be relative to the root of the service - any leading /.
158 * and trailing /'s should have been trimmed by check_path_syntax().
161 #ifdef DEVELOPER
162 SMB_ASSERT(*orig_path != '/');
163 #endif
166 * If we trimmed down to a single '\0' character
167 * then we should use the "." directory to avoid
168 * searching the cache, but not if we are in a
169 * printing share.
170 * As we know this is valid we can return true here.
173 if (!*orig_path) {
174 if (!(name = talloc_strdup(ctx,"."))) {
175 return NT_STATUS_NO_MEMORY;
177 if (SMB_VFS_STAT(conn,name,&st) == 0) {
178 *pst = st;
179 } else {
180 return map_nt_error_from_unix(errno);
182 DEBUG(5,("conversion finished \"\" -> %s\n",name));
183 goto done;
186 if (orig_path[0] == '.' && (orig_path[1] == '/' ||
187 orig_path[1] == '\0')) {
188 /* Start of pathname can't be "." only. */
189 if (orig_path[1] == '\0' || orig_path[2] == '\0') {
190 result = NT_STATUS_OBJECT_NAME_INVALID;
191 } else {
192 result =determine_path_error(
193 &orig_path[2], allow_wcard_last_component);
195 return result;
199 * Ensure saved_last_component is valid even if file exists.
202 if(pp_saved_last_component) {
203 end = strrchr_m(orig_path, '/');
204 if (end) {
205 *pp_saved_last_component = talloc_strdup(ctx, end + 1);
206 } else {
207 *pp_saved_last_component = talloc_strdup(ctx,
208 orig_path);
212 if (!(name = talloc_strdup(ctx, orig_path))) {
213 DEBUG(0, ("talloc_strdup failed\n"));
214 return NT_STATUS_NO_MEMORY;
217 stream = strchr_m(name, ':');
219 if (stream != NULL) {
220 char *tmp = talloc_strdup(ctx, stream);
221 if (tmp == NULL) {
222 TALLOC_FREE(name);
223 return NT_STATUS_NO_MEMORY;
225 *stream = '\0';
226 stream = tmp;
230 * Large directory fix normalization. If we're case sensitive, and
231 * the case preserving parameters are set to "no", normalize the case of
232 * the incoming filename from the client WHETHER IT EXISTS OR NOT !
233 * This is in conflict with the current (3.0.20) man page, but is
234 * what people expect from the "large directory howto". I'll update
235 * the man page. Thanks to jht@samba.org for finding this. JRA.
238 if (conn->case_sensitive && !conn->case_preserve &&
239 !conn->short_case_preserve) {
240 strnorm(name, lp_defaultcase(SNUM(conn)));
243 start = name;
245 /* If we're providing case insentive semantics or
246 * the underlying filesystem is case insensitive,
247 * then a case-normalized hit in the stat-cache is
248 * authoratitive. JRA.
251 if((!conn->case_sensitive || !(conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH)) &&
252 stat_cache_lookup(conn, &name, &dirpath, &start, &st)) {
253 *pst = st;
254 goto done;
258 * Make sure "dirpath" is an allocated string, we use this for
259 * building the directories with asprintf and free it.
262 if ((dirpath == NULL) && (!(dirpath = talloc_strdup(ctx,"")))) {
263 DEBUG(0, ("talloc_strdup failed\n"));
264 TALLOC_FREE(name);
265 return NT_STATUS_NO_MEMORY;
269 * stat the name - if it exists then we are all done!
272 if (SMB_VFS_STAT(conn,name,&st) == 0) {
273 /* Ensure we catch all names with in "/."
274 this is disallowed under Windows. */
275 const char *p = strstr(name, "/."); /* mb safe. */
276 if (p) {
277 if (p[2] == '/') {
278 /* Error code within a pathname. */
279 result = NT_STATUS_OBJECT_PATH_NOT_FOUND;
280 goto fail;
281 } else if (p[2] == '\0') {
282 /* Error code at the end of a pathname. */
283 result = NT_STATUS_OBJECT_NAME_INVALID;
284 goto fail;
287 stat_cache_add(orig_path, name, conn->case_sensitive);
288 DEBUG(5,("conversion finished %s -> %s\n",orig_path, name));
289 *pst = st;
290 goto done;
293 DEBUG(5,("unix_convert begin: name = %s, dirpath = %s, start = %s\n",
294 name, dirpath, start));
297 * A special case - if we don't have any mangling chars and are case
298 * sensitive or the underlying filesystem is case insentive then searching
299 * won't help.
302 if ((conn->case_sensitive || !(conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH)) &&
303 !mangle_is_mangled(name, conn->params)) {
304 goto done;
308 * is_mangled() was changed to look at an entire pathname, not
309 * just a component. JRA.
312 if (mangle_is_mangled(start, conn->params)) {
313 component_was_mangled = True;
317 * Now we need to recursively match the name against the real
318 * directory structure.
322 * Match each part of the path name separately, trying the names
323 * as is first, then trying to scan the directory for matching names.
326 for (; start ; start = (end?end+1:(char *)NULL)) {
328 * Pinpoint the end of this section of the filename.
330 /* mb safe. '/' can't be in any encoded char. */
331 end = strchr(start, '/');
334 * Chop the name at this point.
336 if (end) {
337 *end = 0;
340 if (pp_saved_last_component) {
341 TALLOC_FREE(*pp_saved_last_component);
342 *pp_saved_last_component = talloc_strdup(ctx,
343 end ? end + 1 : start);
344 if (!*pp_saved_last_component) {
345 DEBUG(0, ("talloc failed\n"));
346 return NT_STATUS_NO_MEMORY;
350 /* The name cannot have a component of "." */
352 if (ISDOT(start)) {
353 if (!end) {
354 /* Error code at the end of a pathname. */
355 result = NT_STATUS_OBJECT_NAME_INVALID;
356 } else {
357 result = determine_path_error(end+1,
358 allow_wcard_last_component);
360 goto fail;
363 /* The name cannot have a wildcard if it's not
364 the last component. */
366 name_has_wildcard = ms_has_wild(start);
368 /* Wildcard not valid anywhere. */
369 if (name_has_wildcard && !allow_wcard_last_component) {
370 result = NT_STATUS_OBJECT_NAME_INVALID;
371 goto fail;
374 /* Wildcards never valid within a pathname. */
375 if (name_has_wildcard && end) {
376 result = NT_STATUS_OBJECT_NAME_INVALID;
377 goto fail;
381 * Check if the name exists up to this point.
384 if (SMB_VFS_STAT(conn,name, &st) == 0) {
386 * It exists. it must either be a directory or this must
387 * be the last part of the path for it to be OK.
389 if (end && !(st.st_mode & S_IFDIR)) {
391 * An intermediate part of the name isn't
392 * a directory.
394 DEBUG(5,("Not a dir %s\n",start));
395 *end = '/';
397 * We need to return the fact that the
398 * intermediate name resolution failed. This
399 * is used to return an error of ERRbadpath
400 * rather than ERRbadfile. Some Windows
401 * applications depend on the difference between
402 * these two errors.
404 result = NT_STATUS_OBJECT_PATH_NOT_FOUND;
405 goto fail;
408 if (!end) {
410 * We just scanned for, and found the end of
411 * the path. We must return the valid stat
412 * struct. JRA.
415 *pst = st;
418 } else {
419 char *found_name = NULL;
421 /* Stat failed - ensure we don't use it. */
422 SET_STAT_INVALID(st);
425 * Reset errno so we can detect
426 * directory open errors.
428 errno = 0;
431 * Try to find this part of the path in the directory.
434 if (name_has_wildcard ||
435 !scan_directory(conn, dirpath,
436 start, &found_name)) {
437 char *unmangled;
439 if (end) {
441 * An intermediate part of the name
442 * can't be found.
444 DEBUG(5,("Intermediate not found %s\n",
445 start));
446 *end = '/';
449 * We need to return the fact that the
450 * intermediate name resolution failed.
451 * This is used to return an error of
452 * ERRbadpath rather than ERRbadfile.
453 * Some Windows applications depend on
454 * the difference between these two
455 * errors.
459 * ENOENT, ENOTDIR and ELOOP all map
460 * to NT_STATUS_OBJECT_PATH_NOT_FOUND
461 * in the filename walk.
464 if (errno == ENOENT ||
465 errno == ENOTDIR ||
466 errno == ELOOP) {
467 result =
468 NT_STATUS_OBJECT_PATH_NOT_FOUND;
470 else {
471 result =
472 map_nt_error_from_unix(errno);
474 goto fail;
477 /* ENOENT is the only valid error here. */
478 if (errno != ENOENT) {
480 * ENOTDIR and ELOOP both map to
481 * NT_STATUS_OBJECT_PATH_NOT_FOUND
482 * in the filename walk.
484 if (errno == ENOTDIR ||
485 errno == ELOOP) {
486 result =
487 NT_STATUS_OBJECT_PATH_NOT_FOUND;
489 else {
490 result =
491 map_nt_error_from_unix(errno);
493 goto fail;
497 * Just the last part of the name doesn't exist.
498 * We need to strupper() or strlower() it as
499 * this conversion may be used for file creation
500 * purposes. Fix inspired by
501 * Thomas Neumann <t.neumann@iku-ag.de>.
503 if (!conn->case_preserve ||
504 (mangle_is_8_3(start, False,
505 conn->params) &&
506 !conn->short_case_preserve)) {
507 strnorm(start,
508 lp_defaultcase(SNUM(conn)));
512 * check on the mangled stack to see if we can
513 * recover the base of the filename.
516 if (mangle_is_mangled(start, conn->params)
517 && mangle_lookup_name_from_8_3(ctx,
518 start,
519 &unmangled,
520 conn->params)) {
521 char *tmp;
522 size_t start_ofs = start - name;
524 if (*dirpath != '\0') {
525 tmp = talloc_asprintf(ctx,
526 "%s/%s", dirpath,
527 unmangled);
528 TALLOC_FREE(unmangled);
530 else {
531 tmp = unmangled;
533 if (tmp == NULL) {
534 DEBUG(0, ("talloc failed\n"));
535 return NT_STATUS_NO_MEMORY;
537 TALLOC_FREE(name);
538 name = tmp;
539 start = name + start_ofs;
540 end = start + strlen(start);
543 DEBUG(5,("New file %s\n",start));
544 goto done;
549 * Restore the rest of the string. If the string was
550 * mangled the size may have changed.
552 if (end) {
553 char *tmp;
554 size_t start_ofs = start - name;
556 if (*dirpath != '\0') {
557 tmp = talloc_asprintf(ctx,
558 "%s/%s/%s", dirpath,
559 found_name, end+1);
561 else {
562 tmp = talloc_asprintf(ctx,
563 "%s/%s", found_name,
564 end+1);
566 if (tmp == NULL) {
567 DEBUG(0, ("talloc_asprintf failed\n"));
568 return NT_STATUS_NO_MEMORY;
570 TALLOC_FREE(name);
571 name = tmp;
572 start = name + start_ofs;
573 end = start + strlen(found_name);
574 *end = '\0';
575 } else {
576 char *tmp;
577 size_t start_ofs = start - name;
579 if (*dirpath != '\0') {
580 tmp = talloc_asprintf(ctx,
581 "%s/%s", dirpath,
582 found_name);
583 } else {
584 tmp = talloc_strdup(ctx,
585 found_name);
587 if (tmp == NULL) {
588 DEBUG(0, ("talloc failed\n"));
589 return NT_STATUS_NO_MEMORY;
591 TALLOC_FREE(name);
592 name = tmp;
593 start = name + start_ofs;
596 * We just scanned for, and found the end of
597 * the path. We must return a valid stat struct
598 * if it exists. JRA.
601 if (SMB_VFS_STAT(conn,name, &st) == 0) {
602 *pst = st;
603 } else {
604 SET_STAT_INVALID(st);
608 TALLOC_FREE(found_name);
609 } /* end else */
611 #ifdef DEVELOPER
612 if (VALID_STAT(st) &&
613 get_delete_on_close_flag(vfs_file_id_from_sbuf(conn,
614 &st))) {
615 result = NT_STATUS_DELETE_PENDING;
616 goto fail;
618 #endif
621 * Add to the dirpath that we have resolved so far.
624 if (*dirpath != '\0') {
625 char *tmp = talloc_asprintf(ctx,
626 "%s/%s", dirpath, start);
627 if (!tmp) {
628 DEBUG(0, ("talloc_asprintf failed\n"));
629 return NT_STATUS_NO_MEMORY;
631 TALLOC_FREE(dirpath);
632 dirpath = tmp;
634 else {
635 TALLOC_FREE(dirpath);
636 if (!(dirpath = talloc_strdup(ctx,start))) {
637 DEBUG(0, ("talloc_strdup failed\n"));
638 return NT_STATUS_NO_MEMORY;
643 * Don't cache a name with mangled or wildcard components
644 * as this can change the size.
647 if(!component_was_mangled && !name_has_wildcard) {
648 stat_cache_add(orig_path, dirpath,
649 conn->case_sensitive);
653 * Restore the / that we wiped out earlier.
655 if (end) {
656 *end = '/';
661 * Don't cache a name with mangled or wildcard components
662 * as this can change the size.
665 if(!component_was_mangled && !name_has_wildcard) {
666 stat_cache_add(orig_path, name, conn->case_sensitive);
670 * The name has been resolved.
673 DEBUG(5,("conversion finished %s -> %s\n",orig_path, name));
675 done:
676 if (stream != NULL) {
677 char *tmp = NULL;
679 result = build_stream_path(ctx, conn, orig_path, name, stream,
680 pst, &tmp);
681 if (!NT_STATUS_IS_OK(result)) {
682 goto fail;
685 DEBUG(10, ("build_stream_path returned %s\n", tmp));
687 TALLOC_FREE(name);
688 name = tmp;
690 *pp_conv_path = name;
691 TALLOC_FREE(dirpath);
692 return NT_STATUS_OK;
693 fail:
694 DEBUG(10, ("dirpath = [%s] start = [%s]\n", dirpath, start));
695 if (*dirpath != '\0') {
696 *pp_conv_path = talloc_asprintf(ctx,
697 "%s/%s", dirpath, start);
698 } else {
699 *pp_conv_path = talloc_strdup(ctx, start);
701 if (!*pp_conv_path) {
702 DEBUG(0, ("talloc_asprintf failed\n"));
703 return NT_STATUS_NO_MEMORY;
705 TALLOC_FREE(name);
706 TALLOC_FREE(dirpath);
707 return result;
710 /****************************************************************************
711 Check a filename - possibly calling check_reduced_name.
712 This is called by every routine before it allows an operation on a filename.
713 It does any final confirmation necessary to ensure that the filename is
714 a valid one for the user to access.
715 ****************************************************************************/
717 NTSTATUS check_name(connection_struct *conn, const char *name)
719 if (IS_VETO_PATH(conn, name)) {
720 /* Is it not dot or dot dot. */
721 if (!((name[0] == '.') && (!name[1] ||
722 (name[1] == '.' && !name[2])))) {
723 DEBUG(5,("check_name: file path name %s vetoed\n",
724 name));
725 return map_nt_error_from_unix(ENOENT);
729 if (!lp_widelinks(SNUM(conn)) || !lp_symlinks(SNUM(conn))) {
730 NTSTATUS status = check_reduced_name(conn,name);
731 if (!NT_STATUS_IS_OK(status)) {
732 DEBUG(5,("check_name: name %s failed with %s\n",name,
733 nt_errstr(status)));
734 return status;
738 return NT_STATUS_OK;
741 /****************************************************************************
742 Check if two filenames are equal.
743 This needs to be careful about whether we are case sensitive.
744 ****************************************************************************/
746 static bool fname_equal(const char *name1, const char *name2,
747 bool case_sensitive)
749 /* Normal filename handling */
750 if (case_sensitive) {
751 return(strcmp(name1,name2) == 0);
754 return(strequal(name1,name2));
757 /****************************************************************************
758 Scan a directory to find a filename, matching without case sensitivity.
759 If the name looks like a mangled name then try via the mangling functions
760 ****************************************************************************/
762 static bool scan_directory(connection_struct *conn, const char *path,
763 char *name, char **found_name)
765 struct smb_Dir *cur_dir;
766 const char *dname;
767 bool mangled;
768 char *unmangled_name = NULL;
769 long curpos;
770 TALLOC_CTX *ctx = talloc_tos();
772 mangled = mangle_is_mangled(name, conn->params);
774 /* handle null paths */
775 if ((path == NULL) || (*path == 0)) {
776 path = ".";
779 /* If we have a case-sensitive filesystem, it doesn't do us any
780 * good to search for a name. If a case variation of the name was
781 * there, then the original stat(2) would have found it.
783 if (!mangled && !(conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH)) {
784 errno = ENOENT;
785 return False;
789 * The incoming name can be mangled, and if we de-mangle it
790 * here it will not compare correctly against the filename (name2)
791 * read from the directory and then mangled by the name_to_8_3()
792 * call. We need to mangle both names or neither.
793 * (JRA).
795 * Fix for bug found by Dina Fine. If in case sensitive mode then
796 * the mangle cache is no good (3 letter extension could be wrong
797 * case - so don't demangle in this case - leave as mangled and
798 * allow the mangling of the directory entry read (which is done
799 * case insensitively) to match instead. This will lead to more
800 * false positive matches but we fail completely without it. JRA.
803 if (mangled && !conn->case_sensitive) {
804 mangled = !mangle_lookup_name_from_8_3(ctx,
805 name,
806 &unmangled_name,
807 conn->params);
808 if (!mangled) {
809 /* Name is now unmangled. */
810 name = unmangled_name;
814 /* open the directory */
815 if (!(cur_dir = OpenDir(talloc_tos(), conn, path, NULL, 0))) {
816 DEBUG(3,("scan dir didn't open dir [%s]\n",path));
817 TALLOC_FREE(unmangled_name);
818 return(False);
821 /* now scan for matching names */
822 curpos = 0;
823 while ((dname = ReadDirName(cur_dir, &curpos))) {
825 /* Is it dot or dot dot. */
826 if (ISDOT(dname) || ISDOTDOT(dname)) {
827 continue;
831 * At this point dname is the unmangled name.
832 * name is either mangled or not, depending on the state
833 * of the "mangled" variable. JRA.
837 * Check mangled name against mangled name, or unmangled name
838 * against unmangled name.
841 if ((mangled && mangled_equal(name,dname,conn->params)) ||
842 fname_equal(name, dname, conn->case_sensitive)) {
843 /* we've found the file, change it's name and return */
844 *found_name = talloc_strdup(ctx,dname);
845 TALLOC_FREE(unmangled_name);
846 TALLOC_FREE(cur_dir);
847 if (!*found_name) {
848 errno = ENOMEM;
849 return False;
851 return(True);
855 TALLOC_FREE(unmangled_name);
856 TALLOC_FREE(cur_dir);
857 errno = ENOENT;
858 return False;
861 static NTSTATUS build_stream_path(TALLOC_CTX *mem_ctx,
862 connection_struct *conn,
863 const char *orig_path,
864 const char *basepath,
865 const char *streamname,
866 SMB_STRUCT_STAT *pst,
867 char **path)
869 SMB_STRUCT_STAT st;
870 char *result = NULL;
871 NTSTATUS status;
872 unsigned int i, num_streams;
873 struct stream_struct *streams = NULL;
875 result = talloc_asprintf(mem_ctx, "%s%s", basepath, streamname);
876 if (result == NULL) {
877 return NT_STATUS_NO_MEMORY;
880 if (SMB_VFS_STAT(conn, result, &st) == 0) {
881 *pst = st;
882 *path = result;
883 return NT_STATUS_OK;
886 if (errno != ENOENT) {
887 status = map_nt_error_from_unix(errno);
888 DEBUG(10, ("vfs_stat failed: %s\n", nt_errstr(status)));
889 goto fail;
892 status = SMB_VFS_STREAMINFO(conn, NULL, basepath, mem_ctx,
893 &num_streams, &streams);
895 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
896 SET_STAT_INVALID(*pst);
897 *path = result;
898 return NT_STATUS_OK;
901 if (!NT_STATUS_IS_OK(status)) {
902 DEBUG(10, ("vfs_streaminfo failed: %s\n", nt_errstr(status)));
903 goto fail;
906 for (i=0; i<num_streams; i++) {
907 DEBUG(10, ("comparing [%s] and [%s]: ",
908 streamname, streams[i].name));
909 if (fname_equal(streamname, streams[i].name,
910 conn->case_sensitive)) {
911 DEBUGADD(10, ("equal\n"));
912 break;
914 DEBUGADD(10, ("not equal\n"));
917 if (i == num_streams) {
918 SET_STAT_INVALID(*pst);
919 *path = result;
920 TALLOC_FREE(streams);
921 return NT_STATUS_OK;
924 TALLOC_FREE(result);
926 result = talloc_asprintf(mem_ctx, "%s%s", basepath, streams[i].name);
927 if (result == NULL) {
928 status = NT_STATUS_NO_MEMORY;
929 goto fail;
932 SET_STAT_INVALID(*pst);
934 if (SMB_VFS_STAT(conn, result, pst) == 0) {
935 stat_cache_add(orig_path, result, conn->case_sensitive);
938 *path = result;
939 TALLOC_FREE(streams);
940 return NT_STATUS_OK;
942 fail:
943 TALLOC_FREE(result);
944 TALLOC_FREE(streams);
945 return status;