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.
29 static NTSTATUS build_stream_path(TALLOC_CTX *mem_ctx,
30 connection_struct *conn,
31 const char *orig_path,
32 struct smb_filename *smb_fname);
34 /****************************************************************************
35 Mangle the 2nd name and check if it is then equal to the first name.
36 ****************************************************************************/
38 static bool mangled_equal(const char *name1,
40 const struct share_params *p)
44 if (!name_to_8_3(name2, mname, False, p)) {
47 return strequal(name1, mname);
50 /****************************************************************************
51 Cope with the differing wildcard and non-wildcard error cases.
52 ****************************************************************************/
54 static NTSTATUS determine_path_error(const char *name,
55 bool allow_wcard_last_component)
59 if (!allow_wcard_last_component) {
60 /* Error code within a pathname. */
61 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
64 /* We're terminating here so we
65 * can be a little slower and get
66 * the error code right. Windows
67 * treats the last part of the pathname
68 * separately I think, so if the last
69 * component is a wildcard then we treat
70 * this ./ as "end of component" */
72 p = strchr(name, '/');
74 if (!p && (ms_has_wild(name) || ISDOT(name))) {
75 /* Error code at the end of a pathname. */
76 return NT_STATUS_OBJECT_NAME_INVALID;
78 /* Error code within a pathname. */
79 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
83 /****************************************************************************
84 This routine is called to convert names from the dos namespace to unix
85 namespace. It needs to handle any case conversions, mangling, format changes,
88 We assume that we have already done a chdir() to the right "root" directory
91 The function will return an NTSTATUS error if some part of the name except for
92 the last part cannot be resolved, else NT_STATUS_OK.
94 Note NT_STATUS_OK doesn't mean the name exists or is valid, just that we
95 didn't get any fatal errors that should immediately terminate the calling SMB
96 processing whilst resolving.
98 If the UCF_SAVE_LCOMP flag is passed in, then the unmodified last component
99 of the pathname is set in smb_filename->original_lcomp.
101 If UCF_ALWAYS_ALLOW_WCARD_LCOMP is passed in, then a MS wildcard was detected
102 and should be allowed in the last component of the path only.
104 If the orig_path was a stream, smb_filename->base_name will point to the base
105 filename, and smb_filename->stream_name will point to the stream name. If
106 orig_path was not a stream, then smb_filename->stream_name will be NULL.
108 On exit from unix_convert, the smb_filename->st stat struct will be populated
109 if the file exists and was found, if not this stat struct will be filled with
110 zeros (and this can be detected by checking for nlinks = 0, which can never be
112 ****************************************************************************/
114 NTSTATUS unix_convert(TALLOC_CTX *ctx,
115 connection_struct *conn,
116 const char *orig_path,
117 struct smb_filename **smb_fname_out,
120 struct smb_filename *smb_fname = NULL;
122 char *dirpath = NULL;
124 bool component_was_mangled = False;
125 bool name_has_wildcard = False;
126 bool posix_pathnames = false;
127 bool allow_wcard_last_component =
128 (ucf_flags & UCF_ALWAYS_ALLOW_WCARD_LCOMP);
129 bool save_last_component = ucf_flags & UCF_SAVE_LCOMP;
133 *smb_fname_out = NULL;
135 smb_fname = talloc_zero(ctx, struct smb_filename);
136 if (smb_fname == NULL) {
137 return NT_STATUS_NO_MEMORY;
141 /* we don't ever use the filenames on a printer share as a
142 filename - so don't convert them */
143 if (!(smb_fname->base_name = talloc_strdup(smb_fname,
145 status = NT_STATUS_NO_MEMORY;
151 DEBUG(5, ("unix_convert called on file \"%s\"\n", orig_path));
154 * Conversion to basic unix format is already done in
155 * check_path_syntax().
159 * Names must be relative to the root of the service - any leading /.
160 * and trailing /'s should have been trimmed by check_path_syntax().
164 SMB_ASSERT(*orig_path != '/');
168 * If we trimmed down to a single '\0' character
169 * then we should use the "." directory to avoid
170 * searching the cache, but not if we are in a
172 * As we know this is valid we can return true here.
176 if (!(smb_fname->base_name = talloc_strdup(smb_fname, "."))) {
177 status = NT_STATUS_NO_MEMORY;
180 if (SMB_VFS_STAT(conn, smb_fname) != 0) {
181 status = map_nt_error_from_unix(errno);
184 DEBUG(5, ("conversion finished \"\" -> %s\n",
185 smb_fname->base_name));
189 if (orig_path[0] == '.' && (orig_path[1] == '/' ||
190 orig_path[1] == '\0')) {
191 /* Start of pathname can't be "." only. */
192 if (orig_path[1] == '\0' || orig_path[2] == '\0') {
193 status = NT_STATUS_OBJECT_NAME_INVALID;
195 status =determine_path_error(&orig_path[2],
196 allow_wcard_last_component);
201 /* Start with the full orig_path as given by the caller. */
202 if (!(smb_fname->base_name = talloc_strdup(smb_fname, orig_path))) {
203 DEBUG(0, ("talloc_strdup failed\n"));
204 status = NT_STATUS_NO_MEMORY;
209 * Large directory fix normalization. If we're case sensitive, and
210 * the case preserving parameters are set to "no", normalize the case of
211 * the incoming filename from the client WHETHER IT EXISTS OR NOT !
212 * This is in conflict with the current (3.0.20) man page, but is
213 * what people expect from the "large directory howto". I'll update
214 * the man page. Thanks to jht@samba.org for finding this. JRA.
217 if (conn->case_sensitive && !conn->case_preserve &&
218 !conn->short_case_preserve) {
219 strnorm(smb_fname->base_name, lp_defaultcase(SNUM(conn)));
223 * Ensure saved_last_component is valid even if file exists.
226 if(save_last_component) {
227 end = strrchr_m(smb_fname->base_name, '/');
229 smb_fname->original_lcomp = talloc_strdup(smb_fname,
232 smb_fname->original_lcomp =
233 talloc_strdup(smb_fname, smb_fname->base_name);
235 if (smb_fname->original_lcomp == NULL) {
236 status = NT_STATUS_NO_MEMORY;
241 posix_pathnames = (lp_posix_pathnames() ||
242 (ucf_flags & UCF_POSIX_PATHNAMES));
245 * Strip off the stream, and add it back when we're done with the
248 if (!posix_pathnames) {
249 stream = strchr_m(smb_fname->base_name, ':');
251 if (stream != NULL) {
252 char *tmp = talloc_strdup(smb_fname, stream);
254 status = NT_STATUS_NO_MEMORY;
258 * Since this is actually pointing into
259 * smb_fname->base_name this truncates base_name.
266 start = smb_fname->base_name;
269 * If we're providing case insentive semantics or
270 * the underlying filesystem is case insensitive,
271 * then a case-normalized hit in the stat-cache is
272 * authoratitive. JRA.
274 * Note: We're only checking base_name. The stream_name will be
275 * added and verified in build_stream_path().
278 if((!conn->case_sensitive || !(conn->fs_capabilities &
279 FILE_CASE_SENSITIVE_SEARCH)) &&
280 stat_cache_lookup(conn, &smb_fname->base_name, &dirpath, &start,
286 * Make sure "dirpath" is an allocated string, we use this for
287 * building the directories with asprintf and free it.
290 if ((dirpath == NULL) && (!(dirpath = talloc_strdup(ctx,"")))) {
291 DEBUG(0, ("talloc_strdup failed\n"));
292 status = NT_STATUS_NO_MEMORY;
297 * stat the name - if it exists then we can add the stream back (if
298 * there was one) and be done!
301 if (posix_pathnames) {
302 ret = SMB_VFS_LSTAT(conn, smb_fname);
304 ret = SMB_VFS_STAT(conn, smb_fname);
308 /* Ensure we catch all names with in "/."
309 this is disallowed under Windows. */
310 const char *p = strstr(smb_fname->base_name, "/."); /*mb safe*/
313 /* Error code within a pathname. */
314 status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
316 } else if (p[2] == '\0') {
317 /* Error code at the end of a pathname. */
318 status = NT_STATUS_OBJECT_NAME_INVALID;
322 /* Add the path (not including the stream) to the cache. */
323 stat_cache_add(orig_path, smb_fname->base_name,
324 conn->case_sensitive);
325 DEBUG(5,("conversion of base_name finished %s -> %s\n",
326 orig_path, smb_fname->base_name));
330 DEBUG(5,("unix_convert begin: name = %s, dirpath = %s, start = %s\n",
331 smb_fname->base_name, dirpath, start));
334 * A special case - if we don't have any mangling chars and are case
335 * sensitive or the underlying filesystem is case insentive then searching
339 if ((conn->case_sensitive || !(conn->fs_capabilities &
340 FILE_CASE_SENSITIVE_SEARCH)) &&
341 !mangle_is_mangled(smb_fname->base_name, conn->params)) {
346 * is_mangled() was changed to look at an entire pathname, not
347 * just a component. JRA.
350 if (mangle_is_mangled(start, conn->params)) {
351 component_was_mangled = True;
355 * Now we need to recursively match the name against the real
356 * directory structure.
360 * Match each part of the path name separately, trying the names
361 * as is first, then trying to scan the directory for matching names.
364 for (; start ; start = (end?end+1:(char *)NULL)) {
366 * Pinpoint the end of this section of the filename.
368 /* mb safe. '/' can't be in any encoded char. */
369 end = strchr(start, '/');
372 * Chop the name at this point.
378 if (save_last_component) {
379 TALLOC_FREE(smb_fname->original_lcomp);
380 smb_fname->original_lcomp = talloc_strdup(smb_fname,
381 end ? end + 1 : start);
382 if (!smb_fname->original_lcomp) {
383 DEBUG(0, ("talloc failed\n"));
384 status = NT_STATUS_NO_MEMORY;
389 /* The name cannot have a component of "." */
393 /* Error code at the end of a pathname. */
394 status = NT_STATUS_OBJECT_NAME_INVALID;
396 status = determine_path_error(end+1,
397 allow_wcard_last_component);
402 /* The name cannot have a wildcard if it's not
403 the last component. */
405 name_has_wildcard = ms_has_wild(start);
407 /* Wildcard not valid anywhere. */
408 if (name_has_wildcard && !allow_wcard_last_component) {
409 status = NT_STATUS_OBJECT_NAME_INVALID;
413 /* Wildcards never valid within a pathname. */
414 if (name_has_wildcard && end) {
415 status = NT_STATUS_OBJECT_NAME_INVALID;
420 * Check if the name exists up to this point.
423 if (posix_pathnames) {
424 ret = SMB_VFS_LSTAT(conn, smb_fname);
426 ret = SMB_VFS_STAT(conn, smb_fname);
431 * It exists. it must either be a directory or this must
432 * be the last part of the path for it to be OK.
434 if (end && !S_ISDIR(smb_fname->st.st_ex_mode)) {
436 * An intermediate part of the name isn't
439 DEBUG(5,("Not a dir %s\n",start));
442 * We need to return the fact that the
443 * intermediate name resolution failed. This
444 * is used to return an error of ERRbadpath
445 * rather than ERRbadfile. Some Windows
446 * applications depend on the difference between
449 status = NT_STATUS_OBJECT_PATH_NOT_FOUND;
454 char *found_name = NULL;
456 /* Stat failed - ensure we don't use it. */
457 SET_STAT_INVALID(smb_fname->st);
460 * Reset errno so we can detect
461 * directory open errors.
466 * Try to find this part of the path in the directory.
469 if (name_has_wildcard ||
470 (get_real_filename(conn, dirpath, start,
472 &found_name) == -1)) {
477 * An intermediate part of the name
480 DEBUG(5,("Intermediate not found %s\n",
485 * We need to return the fact that the
486 * intermediate name resolution failed.
487 * This is used to return an error of
488 * ERRbadpath rather than ERRbadfile.
489 * Some Windows applications depend on
490 * the difference between these two
495 * ENOENT, ENOTDIR and ELOOP all map
496 * to NT_STATUS_OBJECT_PATH_NOT_FOUND
497 * in the filename walk.
500 if (errno == ENOENT ||
504 NT_STATUS_OBJECT_PATH_NOT_FOUND;
508 map_nt_error_from_unix(errno);
514 * ENOENT/EACCESS are the only valid errors
515 * here. EACCESS needs handling here for
516 * "dropboxes", i.e. directories where users
517 * can only put stuff with permission -wx.
519 if ((errno != 0) && (errno != ENOENT)
520 && (errno != EACCES)) {
522 * ENOTDIR and ELOOP both map to
523 * NT_STATUS_OBJECT_PATH_NOT_FOUND
524 * in the filename walk.
526 if (errno == ENOTDIR ||
529 NT_STATUS_OBJECT_PATH_NOT_FOUND;
532 map_nt_error_from_unix(errno);
538 * Just the last part of the name doesn't exist.
539 * We need to strupper() or strlower() it as
540 * this conversion may be used for file creation
541 * purposes. Fix inspired by
542 * Thomas Neumann <t.neumann@iku-ag.de>.
544 if (!conn->case_preserve ||
545 (mangle_is_8_3(start, False,
547 !conn->short_case_preserve)) {
549 lp_defaultcase(SNUM(conn)));
553 * check on the mangled stack to see if we can
554 * recover the base of the filename.
557 if (mangle_is_mangled(start, conn->params)
558 && mangle_lookup_name_from_8_3(ctx,
564 start - smb_fname->base_name;
566 if (*dirpath != '\0') {
567 tmp = talloc_asprintf(
570 TALLOC_FREE(unmangled);
576 DEBUG(0, ("talloc failed\n"));
577 status = NT_STATUS_NO_MEMORY;
580 TALLOC_FREE(smb_fname->base_name);
581 smb_fname->base_name = tmp;
583 smb_fname->base_name + start_ofs;
584 end = start + strlen(start);
587 DEBUG(5,("New file %s\n",start));
593 * Restore the rest of the string. If the string was
594 * mangled the size may have changed.
599 start - smb_fname->base_name;
601 if (*dirpath != '\0') {
602 tmp = talloc_asprintf(smb_fname,
607 tmp = talloc_asprintf(smb_fname,
612 DEBUG(0, ("talloc_asprintf failed\n"));
613 status = NT_STATUS_NO_MEMORY;
616 TALLOC_FREE(smb_fname->base_name);
617 smb_fname->base_name = tmp;
618 start = smb_fname->base_name + start_ofs;
619 end = start + strlen(found_name);
624 start - smb_fname->base_name;
626 if (*dirpath != '\0') {
627 tmp = talloc_asprintf(smb_fname,
631 tmp = talloc_strdup(smb_fname,
635 DEBUG(0, ("talloc failed\n"));
636 status = NT_STATUS_NO_MEMORY;
639 TALLOC_FREE(smb_fname->base_name);
640 smb_fname->base_name = tmp;
641 start = smb_fname->base_name + start_ofs;
644 * We just scanned for, and found the end of
645 * the path. We must return a valid stat struct
649 if (posix_pathnames) {
650 ret = SMB_VFS_LSTAT(conn, smb_fname);
652 ret = SMB_VFS_STAT(conn, smb_fname);
656 SET_STAT_INVALID(smb_fname->st);
660 TALLOC_FREE(found_name);
666 * We should never provide different behaviors
667 * depending on DEVELOPER!!!
669 if (VALID_STAT(smb_fname->st)) {
671 get_file_infos(vfs_file_id_from_sbuf(conn,
673 &delete_pending, NULL);
674 if (delete_pending) {
675 status = NT_STATUS_DELETE_PENDING;
682 * Add to the dirpath that we have resolved so far.
685 if (*dirpath != '\0') {
686 char *tmp = talloc_asprintf(ctx,
687 "%s/%s", dirpath, start);
689 DEBUG(0, ("talloc_asprintf failed\n"));
690 status = NT_STATUS_NO_MEMORY;
693 TALLOC_FREE(dirpath);
697 TALLOC_FREE(dirpath);
698 if (!(dirpath = talloc_strdup(ctx,start))) {
699 DEBUG(0, ("talloc_strdup failed\n"));
700 status = NT_STATUS_NO_MEMORY;
706 * Cache the dirpath thus far. Don't cache a name with mangled
707 * or wildcard components as this can change the size.
709 if(!component_was_mangled && !name_has_wildcard) {
710 stat_cache_add(orig_path, dirpath,
711 conn->case_sensitive);
715 * Restore the / that we wiped out earlier.
723 * Cache the full path. Don't cache a name with mangled or wildcard
724 * components as this can change the size.
727 if(!component_was_mangled && !name_has_wildcard) {
728 stat_cache_add(orig_path, smb_fname->base_name,
729 conn->case_sensitive);
733 * The name has been resolved.
736 DEBUG(5,("conversion finished %s -> %s\n", orig_path,
737 smb_fname->base_name));
740 /* Add back the stream if one was stripped off originally. */
741 if (stream != NULL) {
742 smb_fname->stream_name = stream;
744 /* Check path now that the base_name has been converted. */
745 status = build_stream_path(ctx, conn, orig_path, smb_fname);
746 if (!NT_STATUS_IS_OK(status)) {
750 TALLOC_FREE(dirpath);
751 *smb_fname_out = smb_fname;
754 DEBUG(10, ("dirpath = [%s] start = [%s]\n", dirpath, start));
755 if (*dirpath != '\0') {
756 smb_fname->base_name = talloc_asprintf(smb_fname, "%s/%s",
759 smb_fname->base_name = talloc_strdup(smb_fname, start);
761 if (!smb_fname->base_name) {
762 DEBUG(0, ("talloc_asprintf failed\n"));
763 status = NT_STATUS_NO_MEMORY;
767 *smb_fname_out = smb_fname;
768 TALLOC_FREE(dirpath);
771 TALLOC_FREE(smb_fname);
775 /****************************************************************************
776 Check a filename - possibly calling check_reduced_name.
777 This is called by every routine before it allows an operation on a filename.
778 It does any final confirmation necessary to ensure that the filename is
779 a valid one for the user to access.
780 ****************************************************************************/
782 NTSTATUS check_name(connection_struct *conn, const char *name)
784 if (IS_VETO_PATH(conn, name)) {
785 /* Is it not dot or dot dot. */
786 if (!((name[0] == '.') && (!name[1] ||
787 (name[1] == '.' && !name[2])))) {
788 DEBUG(5,("check_name: file path name %s vetoed\n",
790 return map_nt_error_from_unix(ENOENT);
794 if (!lp_widelinks(SNUM(conn)) || !lp_symlinks(SNUM(conn)) ||
795 conn->case_sensitive) {
796 NTSTATUS status = check_reduced_name(conn,name);
797 if (!NT_STATUS_IS_OK(status)) {
798 DEBUG(5,("check_name: name %s failed with %s\n",name,
807 /****************************************************************************
808 Check if two filenames are equal.
809 This needs to be careful about whether we are case sensitive.
810 ****************************************************************************/
812 static bool fname_equal(const char *name1, const char *name2,
815 /* Normal filename handling */
816 if (case_sensitive) {
817 return(strcmp(name1,name2) == 0);
820 return(strequal(name1,name2));
823 /****************************************************************************
824 Scan a directory to find a filename, matching without case sensitivity.
825 If the name looks like a mangled name then try via the mangling functions
826 ****************************************************************************/
828 static int get_real_filename_full_scan(connection_struct *conn,
829 const char *path, const char *name,
831 TALLOC_CTX *mem_ctx, char **found_name)
833 struct smb_Dir *cur_dir;
834 const char *dname = NULL;
835 char *talloced = NULL;
836 char *unmangled_name = NULL;
839 /* handle null paths */
840 if ((path == NULL) || (*path == 0)) {
844 /* If we have a case-sensitive filesystem, it doesn't do us any
845 * good to search for a name. If a case variation of the name was
846 * there, then the original stat(2) would have found it.
848 if (!mangled && !(conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH)) {
854 * The incoming name can be mangled, and if we de-mangle it
855 * here it will not compare correctly against the filename (name2)
856 * read from the directory and then mangled by the name_to_8_3()
857 * call. We need to mangle both names or neither.
860 * Fix for bug found by Dina Fine. If in case sensitive mode then
861 * the mangle cache is no good (3 letter extension could be wrong
862 * case - so don't demangle in this case - leave as mangled and
863 * allow the mangling of the directory entry read (which is done
864 * case insensitively) to match instead. This will lead to more
865 * false positive matches but we fail completely without it. JRA.
868 if (mangled && !conn->case_sensitive) {
869 mangled = !mangle_lookup_name_from_8_3(talloc_tos(), name,
873 /* Name is now unmangled. */
874 name = unmangled_name;
878 /* open the directory */
879 if (!(cur_dir = OpenDir(talloc_tos(), conn, path, NULL, 0))) {
880 DEBUG(3,("scan dir didn't open dir [%s]\n",path));
881 TALLOC_FREE(unmangled_name);
885 /* now scan for matching names */
887 while ((dname = ReadDirName(cur_dir, &curpos, NULL, &talloced))) {
889 /* Is it dot or dot dot. */
890 if (ISDOT(dname) || ISDOTDOT(dname)) {
891 TALLOC_FREE(talloced);
896 * At this point dname is the unmangled name.
897 * name is either mangled or not, depending on the state
898 * of the "mangled" variable. JRA.
902 * Check mangled name against mangled name, or unmangled name
903 * against unmangled name.
906 if ((mangled && mangled_equal(name,dname,conn->params)) ||
907 fname_equal(name, dname, conn->case_sensitive)) {
908 /* we've found the file, change it's name and return */
909 *found_name = talloc_strdup(mem_ctx, dname);
910 TALLOC_FREE(unmangled_name);
911 TALLOC_FREE(cur_dir);
914 TALLOC_FREE(talloced);
917 TALLOC_FREE(talloced);
920 TALLOC_FREE(talloced);
923 TALLOC_FREE(unmangled_name);
924 TALLOC_FREE(cur_dir);
929 /****************************************************************************
930 Wrapper around the vfs get_real_filename and the full directory scan
932 ****************************************************************************/
934 int get_real_filename(connection_struct *conn, const char *path,
935 const char *name, TALLOC_CTX *mem_ctx,
941 mangled = mangle_is_mangled(name, conn->params);
944 return get_real_filename_full_scan(conn, path, name, mangled,
945 mem_ctx, found_name);
948 /* Try the vfs first to take advantage of case-insensitive stat. */
949 ret = SMB_VFS_GET_REAL_FILENAME(conn, path, name, mem_ctx, found_name);
952 * If the case-insensitive stat was successful, or returned an error
953 * other than EOPNOTSUPP then there is no need to fall back on the
954 * full directory scan.
956 if (ret == 0 || (ret == -1 && errno != EOPNOTSUPP)) {
960 return get_real_filename_full_scan(conn, path, name, mangled, mem_ctx,
964 static NTSTATUS build_stream_path(TALLOC_CTX *mem_ctx,
965 connection_struct *conn,
966 const char *orig_path,
967 struct smb_filename *smb_fname)
970 unsigned int i, num_streams;
971 struct stream_struct *streams = NULL;
973 if (SMB_VFS_STAT(conn, smb_fname) == 0) {
974 DEBUG(10, ("'%s' exists\n", smb_fname_str_dbg(smb_fname)));
978 if (errno != ENOENT) {
979 DEBUG(10, ("vfs_stat failed: %s\n", strerror(errno)));
980 status = map_nt_error_from_unix(errno);
984 /* Fall back to a case-insensitive scan of all streams on the file. */
985 status = SMB_VFS_STREAMINFO(conn, NULL, smb_fname->base_name, mem_ctx,
986 &num_streams, &streams);
988 if (NT_STATUS_EQUAL(status, NT_STATUS_OBJECT_NAME_NOT_FOUND)) {
989 SET_STAT_INVALID(smb_fname->st);
993 if (!NT_STATUS_IS_OK(status)) {
994 DEBUG(10, ("vfs_streaminfo failed: %s\n", nt_errstr(status)));
998 for (i=0; i<num_streams; i++) {
999 DEBUG(10, ("comparing [%s] and [%s]: ",
1000 smb_fname->stream_name, streams[i].name));
1001 if (fname_equal(smb_fname->stream_name, streams[i].name,
1002 conn->case_sensitive)) {
1003 DEBUGADD(10, ("equal\n"));
1006 DEBUGADD(10, ("not equal\n"));
1009 /* Couldn't find the stream. */
1010 if (i == num_streams) {
1011 SET_STAT_INVALID(smb_fname->st);
1012 TALLOC_FREE(streams);
1013 return NT_STATUS_OK;
1016 DEBUG(10, ("case insensitive stream. requested: %s, actual: %s\n",
1017 smb_fname->stream_name, streams[i].name));
1020 TALLOC_FREE(smb_fname->stream_name);
1021 smb_fname->stream_name = talloc_strdup(smb_fname, streams[i].name);
1022 if (smb_fname->stream_name == NULL) {
1023 status = NT_STATUS_NO_MEMORY;
1027 SET_STAT_INVALID(smb_fname->st);
1029 if (SMB_VFS_STAT(conn, smb_fname) == 0) {
1030 DEBUG(10, ("'%s' exists\n", smb_fname_str_dbg(smb_fname)));
1032 status = NT_STATUS_OK;
1034 TALLOC_FREE(streams);
1039 * Go through all the steps to validate a filename.
1041 * @param ctx talloc_ctx to allocate memory with.
1042 * @param conn connection struct for vfs calls.
1043 * @param dfs_path Whether this path requires dfs resolution.
1044 * @param name_in The unconverted name.
1045 * @param ucf_flags flags to pass through to unix_convert().
1046 * UCF_ALWAYS_ALLOW_WCARD_LCOMP will be OR'd in if
1047 * p_cont_wcard != NULL and is true and
1048 * UCF_COND_ALLOW_WCARD_LCOMP.
1049 * @param p_cont_wcard If not NULL, will be set to true if the dfs path
1050 * resolution detects a wildcard.
1051 * @param pp_smb_fname The final converted name will be allocated if the
1052 * return is NT_STATUS_OK.
1054 * @return NT_STATUS_OK if all operations completed succesfully, appropriate
1057 NTSTATUS filename_convert(TALLOC_CTX *ctx,
1058 connection_struct *conn,
1060 const char *name_in,
1062 bool *ppath_contains_wcard,
1063 struct smb_filename **pp_smb_fname)
1068 *pp_smb_fname = NULL;
1070 status = resolve_dfspath_wcard(ctx, conn,
1074 ppath_contains_wcard);
1075 if (!NT_STATUS_IS_OK(status)) {
1076 DEBUG(10,("filename_convert: resolve_dfspath failed "
1077 "for name %s with %s\n",
1079 nt_errstr(status) ));
1083 if (is_fake_file_path(name_in)) {
1087 status = create_synthetic_smb_fname_split(ctx,
1095 * If the caller conditionally allows wildcard lookups, only add the
1096 * always allow if the path actually does contain a wildcard.
1098 if (ucf_flags & UCF_COND_ALLOW_WCARD_LCOMP &&
1099 ppath_contains_wcard != NULL && *ppath_contains_wcard) {
1100 ucf_flags |= UCF_ALWAYS_ALLOW_WCARD_LCOMP;
1103 status = unix_convert(ctx, conn, fname, pp_smb_fname, ucf_flags);
1104 if (!NT_STATUS_IS_OK(status)) {
1105 DEBUG(10,("filename_convert: unix_convert failed "
1106 "for name %s with %s\n",
1108 nt_errstr(status) ));
1112 status = check_name(conn, (*pp_smb_fname)->base_name);
1113 if (!NT_STATUS_IS_OK(status)) {
1114 DEBUG(3,("filename_convert: check_name failed "
1115 "for name %s with %s\n",
1116 smb_fname_str_dbg(*pp_smb_fname),
1117 nt_errstr(status) ));
1118 TALLOC_FREE(*pp_smb_fname);