Fix the overwriting of errno before use in a DEBUG statement and use the return value...
[samba.git] / source3 / modules / onefs_streams.c
index 66eda57a34fd52dcc4c89d57d79235ca7539ea18..0a1d98c809a9e2e53eb4e13cea1dbed1e7c7a24c 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "includes.h"
+#include "smbd/smbd.h"
 #include "onefs.h"
 #include "onefs_config.h"
 
@@ -55,6 +56,9 @@ NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
                /* Strip off the :$DATA if one exists. */
                str_tmp = strrchr_m(stream_name, ':');
                if (str_tmp) {
+                       if (strcasecmp_m(str_tmp, ":$DATA") != 0) {
+                               return NT_STATUS_INVALID_PARAMETER;
+                       }
                        str_tmp[0] = '\0';
                }
        }
@@ -68,6 +72,13 @@ NTSTATUS onefs_stream_prep_smb_fname(TALLOC_CTX *ctx,
                                            stream_name, &smb_fname_in->st,
                                            smb_fname_out);
        TALLOC_FREE(stream_name);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(5, ("Failed to prep stream name for %s: %s\n",
+                         *smb_fname_out ?
+                         smb_fname_str_dbg(*smb_fname_out) : "NULL",
+                         nt_errstr(status)));
+       }
        return status;
 }
 
@@ -93,6 +104,9 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
        int dir_fd;
        int saved_errno;
 
+       DEBUG(10, ("Getting stream directory fd: %s (%d)\n", base,
+                  base_fdp ? *base_fdp : -1));
+
        /* If a valid base_fdp was given, use it. */
        if (base_fdp && *base_fdp >= 0) {
                base_fd = *base_fdp;
@@ -112,6 +126,8 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
                                                0,
                                                NULL);
                if (base_fd < 0) {
+                       DEBUG(5, ("Failed getting base fd: %s\n",
+                                 strerror(errno)));
                        return -1;
                }
        }
@@ -144,6 +160,11 @@ static int get_stream_dir_fd(connection_struct *conn, const char *base,
                *base_fdp = base_fd;
        }
 
+       if (dir_fd < 0) {
+               DEBUG(5, ("Failed getting stream directory fd: %s\n",
+                         strerror(errno)));
+       }
+
        return dir_fd;
 }
 
@@ -170,6 +191,9 @@ int onefs_rename(vfs_handle_struct *handle,
        /* For now don't allow renames from or to the default stream. */
        if (is_ntfs_default_stream_smb_fname(smb_fname_src) ||
            is_ntfs_default_stream_smb_fname(smb_fname_dst)) {
+               DEBUG(3, ("Unable to rename to/from a default stream: %s -> "
+                         "%s\n", smb_fname_str_dbg(smb_fname_src),
+                         smb_fname_str_dbg(smb_fname_dst)));
                errno = ENOSYS;
                goto done;
        }
@@ -308,6 +332,9 @@ static int stat_stream(struct connection_struct *conn, const char *base,
        /* Stat the stream. */
        ret = onefs_sys_fstat_at(dir_fd, stream, sbuf, flags);
        if (ret != -1) {
+               DEBUG(10, ("stat of stream '%s' failed: %s\n", stream,
+                          strerror(errno)));
+       } else {
                /* Now stat the base file and merge the results. */
                ret = onefs_sys_fstat(base_fd, &base_sbuf);
                if (ret != -1) {
@@ -520,12 +547,12 @@ struct streaminfo_state {
 
 static bool add_one_stream(TALLOC_CTX *mem_ctx, unsigned int *num_streams,
                           struct stream_struct **streams,
-                          const char *name, SMB_OFF_T size,
-                          SMB_OFF_T alloc_size)
+                          const char *name, off_t size,
+                          off_t alloc_size)
 {
        struct stream_struct *tmp;
 
-       tmp = TALLOC_REALLOC_ARRAY(mem_ctx, *streams, struct stream_struct,
+       tmp = talloc_realloc(mem_ctx, *streams, struct stream_struct,
                                   (*num_streams)+1);
        if (tmp == NULL) {
                return false;
@@ -556,8 +583,8 @@ static NTSTATUS walk_onefs_streams(connection_struct *conn, files_struct *fsp,
        int dir_fd = -1;
        int stream_fd = -1;
        int ret;
-       SMB_STRUCT_DIR *dirp = NULL;
-       SMB_STRUCT_DIRENT *dp = NULL;
+       DIR *dirp = NULL;
+       struct dirent *dp = NULL;
        files_struct fake_fs;
        struct fd_handle fake_fh;
        SMB_STRUCT_STAT stream_sbuf;
@@ -709,25 +736,14 @@ NTSTATUS onefs_streaminfo(vfs_handle_struct *handle,
                return map_nt_error_from_unix(errno);
        }
 
-       state.streams = NULL;
-       state.num_streams = 0;
+       state.streams = *pstreams;
+       state.num_streams = *pnum_streams;
 
        if (lp_parm_bool(SNUM(handle->conn), PARM_ONEFS_TYPE,
                PARM_IGNORE_STREAMS, PARM_IGNORE_STREAMS_DEFAULT)) {
                goto out;
        }
 
-       /* Add the default stream. */
-       if (S_ISREG(sbuf.st_ex_mode)) {
-               if (!add_one_stream(mem_ctx,
-                                   &state.num_streams, &state.streams,
-                                   "", sbuf.st_ex_size,
-                                   SMB_VFS_GET_ALLOC_SIZE(handle->conn, fsp,
-                                                          &sbuf))) {
-                       return NT_STATUS_NO_MEMORY;
-               }
-       }
-
        state.mem_ctx = mem_ctx;
        state.handle = handle;
        state.status = NT_STATUS_OK;
@@ -751,5 +767,5 @@ NTSTATUS onefs_streaminfo(vfs_handle_struct *handle,
  out:
        *num_streams = state.num_streams;
        *streams = state.streams;
-       return NT_STATUS_OK;
+       return SMB_VFS_NEXT_STREAMINFO(handle, fsp, fname, mem_ctx, pnum_streams, pstreams);
 }