#include "includes.h"
-static bool scan_directory(connection_struct *conn, const char *path,
- char *name, char **found_name);
static NTSTATUS build_stream_path(TALLOC_CTX *mem_ctx,
connection_struct *conn,
const char *orig_path,
SMB processing whilst resolving.
If the saved_last_component != 0, then the unmodified last component
-of the pathname is returned there. This is used in an exceptional
-case in reply_mv (so far). If saved_last_component == 0 then nothing
+of the pathname is returned there. If saved_last_component == 0 then nothing
is returned there.
If last_component_wcard is true then a MS wildcard was detected and
char *stream = NULL;
bool component_was_mangled = False;
bool name_has_wildcard = False;
+ bool posix_pathnames = false;
NTSTATUS result;
+ int ret = -1;
SET_STAT_INVALID(*pst);
*pp_conv_path = NULL;
return result;
}
- /*
- * Ensure saved_last_component is valid even if file exists.
- */
-
- if(pp_saved_last_component) {
- end = strrchr_m(orig_path, '/');
- if (end) {
- *pp_saved_last_component = talloc_strdup(ctx, end + 1);
- } else {
- *pp_saved_last_component = talloc_strdup(ctx,
- orig_path);
- }
- }
-
if (!(name = talloc_strdup(ctx, orig_path))) {
DEBUG(0, ("talloc_strdup failed\n"));
return NT_STATUS_NO_MEMORY;
}
- stream = strchr_m(name, ':');
-
- if (stream != NULL) {
- char *tmp = talloc_strdup(ctx, stream);
- if (tmp == NULL) {
- TALLOC_FREE(name);
- return NT_STATUS_NO_MEMORY;
- }
- *stream = '\0';
- stream = tmp;
- }
-
/*
* Large directory fix normalization. If we're case sensitive, and
* the case preserving parameters are set to "no", normalize the case of
strnorm(name, lp_defaultcase(SNUM(conn)));
}
+ /*
+ * Ensure saved_last_component is valid even if file exists.
+ */
+
+ if(pp_saved_last_component) {
+ end = strrchr_m(name, '/');
+ if (end) {
+ *pp_saved_last_component = talloc_strdup(ctx, end + 1);
+ } else {
+ *pp_saved_last_component = talloc_strdup(ctx,
+ name);
+ }
+ }
+
+ posix_pathnames = lp_posix_pathnames();
+
+ if (!posix_pathnames) {
+ stream = strchr_m(name, ':');
+
+ if (stream != NULL) {
+ char *tmp = talloc_strdup(ctx, stream);
+ if (tmp == NULL) {
+ TALLOC_FREE(name);
+ return NT_STATUS_NO_MEMORY;
+ }
+ *stream = '\0';
+ stream = tmp;
+ }
+ }
+
start = name;
/* If we're providing case insentive semantics or
* stat the name - if it exists then we are all done!
*/
- if (SMB_VFS_STAT(conn,name,&st) == 0) {
+ if (posix_pathnames) {
+ ret = SMB_VFS_LSTAT(conn,name,&st);
+ } else {
+ ret = SMB_VFS_STAT(conn,name,&st);
+ }
+
+ if (ret == 0) {
/* Ensure we catch all names with in "/."
this is disallowed under Windows. */
const char *p = strstr(name, "/."); /* mb safe. */
* Check if the name exists up to this point.
*/
- if (SMB_VFS_STAT(conn,name, &st) == 0) {
+ if (posix_pathnames) {
+ ret = SMB_VFS_LSTAT(conn,name, &st);
+ } else {
+ ret = SMB_VFS_STAT(conn,name, &st);
+ }
+
+ if (ret == 0) {
/*
* It exists. it must either be a directory or this must
* be the last part of the path for it to be OK.
*/
if (name_has_wildcard ||
- !scan_directory(conn, dirpath,
- start, &found_name)) {
+ (get_real_filename(conn, dirpath, start,
+ talloc_tos(),
+ &found_name) == -1)) {
char *unmangled;
if (end) {
}
/* ENOENT is the only valid error here. */
- if (errno != ENOENT) {
+ if ((errno != 0) && (errno != ENOENT)) {
/*
* ENOTDIR and ELOOP both map to
* NT_STATUS_OBJECT_PATH_NOT_FOUND
* if it exists. JRA.
*/
- if (SMB_VFS_STAT(conn,name, &st) == 0) {
+ if (posix_pathnames) {
+ ret = SMB_VFS_LSTAT(conn,name, &st);
+ } else {
+ ret = SMB_VFS_STAT(conn,name, &st);
+ }
+
+ if (ret == 0) {
*pst = st;
} else {
SET_STAT_INVALID(st);
} /* end else */
#ifdef DEVELOPER
- if (VALID_STAT(st) &&
- get_delete_on_close_flag(vfs_file_id_from_sbuf(conn,
- &st))) {
- result = NT_STATUS_DELETE_PENDING;
- goto fail;
+ /*
+ * This sucks!
+ * We should never provide different behaviors
+ * depending on DEVELOPER!!!
+ */
+ if (VALID_STAT(st)) {
+ bool delete_pending;
+ get_file_infos(vfs_file_id_from_sbuf(conn, &st),
+ &delete_pending, NULL);
+ if (delete_pending) {
+ result = NT_STATUS_DELETE_PENDING;
+ goto fail;
+ }
}
#endif
If the name looks like a mangled name then try via the mangling functions
****************************************************************************/
-static bool scan_directory(connection_struct *conn, const char *path,
- char *name, char **found_name)
+static int get_real_filename_full_scan(connection_struct *conn,
+ const char *path, const char *name,
+ bool mangled,
+ TALLOC_CTX *mem_ctx, char **found_name)
{
struct smb_Dir *cur_dir;
const char *dname;
- bool mangled;
char *unmangled_name = NULL;
long curpos;
- TALLOC_CTX *ctx = talloc_tos();
-
- mangled = mangle_is_mangled(name, conn->params);
/* handle null paths */
if ((path == NULL) || (*path == 0)) {
*/
if (!mangled && !(conn->fs_capabilities & FILE_CASE_SENSITIVE_SEARCH)) {
errno = ENOENT;
- return False;
+ return -1;
}
/*
*/
if (mangled && !conn->case_sensitive) {
- mangled = !mangle_lookup_name_from_8_3(ctx,
- name,
- &unmangled_name,
- conn->params);
+ mangled = !mangle_lookup_name_from_8_3(talloc_tos(), name,
+ &unmangled_name,
+ conn->params);
if (!mangled) {
/* Name is now unmangled. */
name = unmangled_name;
if (!(cur_dir = OpenDir(talloc_tos(), conn, path, NULL, 0))) {
DEBUG(3,("scan dir didn't open dir [%s]\n",path));
TALLOC_FREE(unmangled_name);
- return(False);
+ return -1;
}
/* now scan for matching names */
curpos = 0;
- while ((dname = ReadDirName(cur_dir, &curpos))) {
+ while ((dname = ReadDirName(cur_dir, &curpos, NULL))) {
/* Is it dot or dot dot. */
if (ISDOT(dname) || ISDOTDOT(dname)) {
if ((mangled && mangled_equal(name,dname,conn->params)) ||
fname_equal(name, dname, conn->case_sensitive)) {
/* we've found the file, change it's name and return */
- *found_name = talloc_strdup(ctx,dname);
+ *found_name = talloc_strdup(mem_ctx, dname);
TALLOC_FREE(unmangled_name);
TALLOC_FREE(cur_dir);
if (!*found_name) {
errno = ENOMEM;
- return False;
+ return -1;
}
- return(True);
+ return 0;
}
}
TALLOC_FREE(unmangled_name);
TALLOC_FREE(cur_dir);
errno = ENOENT;
- return False;
+ return -1;
+}
+
+/****************************************************************************
+ Wrapper around the vfs get_real_filename and the full directory scan
+ fallback.
+****************************************************************************/
+
+int get_real_filename(connection_struct *conn, const char *path,
+ const char *name, TALLOC_CTX *mem_ctx,
+ char **found_name)
+{
+ int ret;
+ bool mangled;
+
+ mangled = mangle_is_mangled(name, conn->params);
+
+ if (mangled) {
+ return get_real_filename_full_scan(conn, path, name, mangled,
+ mem_ctx, found_name);
+ }
+
+ /* Try the vfs first to take advantage of case-insensitive stat. */
+ ret = SMB_VFS_GET_REAL_FILENAME(conn, path, name, mem_ctx, found_name);
+
+ /*
+ * If the case-insensitive stat was successful, or returned an error
+ * other than EOPNOTSUPP then there is no need to fall back on the
+ * full directory scan.
+ */
+ if (ret == 0 || (ret == -1 && errno != EOPNOTSUPP)) {
+ return ret;
+ }
+
+ return get_real_filename_full_scan(conn, path, name, mangled, mem_ctx,
+ found_name);
}
static NTSTATUS build_stream_path(TALLOC_CTX *mem_ctx,