VFS: Modify chmod to take a const struct smb_filename * instead of const char *
[kai/samba-autobuild/.git] / source3 / modules / vfs_shadow_copy.c
index cf911d7a7082dfff093bd8e469675eb10a1ee3b9..77dc1636c91f8dd8835c34ddb7ec803a261e78b2 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "includes.h"
 #include "smbd/smbd.h"
+#include "ntioctl.h"
 
 /*
     Please read the VFS module Samba-HowTo-Collection.
@@ -59,7 +60,7 @@ static int vfs_shadow_copy_debug_level = DBGC_VFS;
 typedef struct {
        int pos;
        int num;
-       SMB_STRUCT_DIRENT *dirs;
+       struct dirent *dirs;
 } shadow_copy_Dir;
 
 static bool shadow_copy_match_name(const char *name)
@@ -72,13 +73,18 @@ static bool shadow_copy_match_name(const char *name)
        return False;
 }
 
-static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char *fname, const char *mask, uint32 attr)
+static DIR *shadow_copy_opendir(vfs_handle_struct *handle,
+                       const struct smb_filename *smb_fname,
+                       const char *mask,
+                       uint32_t attr)
 {
        shadow_copy_Dir *dirp;
-       SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fname,mask,attr);
+       DIR *p = SMB_VFS_NEXT_OPENDIR(handle,smb_fname,mask,attr);
 
        if (!p) {
-               DEBUG(0,("shadow_copy_opendir: SMB_VFS_NEXT_OPENDIR() failed for [%s]\n",fname));
+               DEBUG(0,("shadow_copy_opendir: SMB_VFS_NEXT_OPENDIR() "
+                       "failed for [%s]\n",
+                       smb_fname->base_name));
                return NULL;
        }
 
@@ -92,7 +98,7 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char
        ZERO_STRUCTP(dirp);
 
        while (True) {
-               SMB_STRUCT_DIRENT *d;
+               struct dirent *d;
 
                d = SMB_VFS_NEXT_READDIR(handle, p, NULL);
                if (d == NULL) {
@@ -106,7 +112,7 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char
 
                DEBUG(10,("shadow_copy_opendir: not hide [%s]\n",d->d_name));
 
-               dirp->dirs = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1);
+               dirp->dirs = SMB_REALLOC_ARRAY(dirp->dirs,struct dirent, dirp->num+1);
                if (!dirp->dirs) {
                        DEBUG(0,("shadow_copy_opendir: Out of memory\n"));
                        break;
@@ -116,13 +122,13 @@ static SMB_STRUCT_DIR *shadow_copy_opendir(vfs_handle_struct *handle, const char
        }
 
        SMB_VFS_NEXT_CLOSEDIR(handle,p);
-       return((SMB_STRUCT_DIR *)dirp);
+       return((DIR *)dirp);
 }
 
-static SMB_STRUCT_DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32 attr)
+static DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_struct *fsp, const char *mask, uint32_t attr)
 {
        shadow_copy_Dir *dirp;
-       SMB_STRUCT_DIR *p = SMB_VFS_NEXT_FDOPENDIR(handle,fsp,mask,attr);
+       DIR *p = SMB_VFS_NEXT_FDOPENDIR(handle,fsp,mask,attr);
 
        if (!p) {
                DEBUG(10,("shadow_copy_opendir: SMB_VFS_NEXT_FDOPENDIR() failed for [%s]\n",
@@ -142,7 +148,7 @@ static SMB_STRUCT_DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_st
        ZERO_STRUCTP(dirp);
 
        while (True) {
-               SMB_STRUCT_DIRENT *d;
+               struct dirent *d;
 
                d = SMB_VFS_NEXT_READDIR(handle, p, NULL);
                if (d == NULL) {
@@ -156,7 +162,7 @@ static SMB_STRUCT_DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_st
 
                DEBUG(10,("shadow_copy_fdopendir: not hide [%s]\n",d->d_name));
 
-               dirp->dirs = SMB_REALLOC_ARRAY(dirp->dirs,SMB_STRUCT_DIRENT, dirp->num+1);
+               dirp->dirs = SMB_REALLOC_ARRAY(dirp->dirs,struct dirent, dirp->num+1);
                if (!dirp->dirs) {
                        DEBUG(0,("shadow_copy_fdopendir: Out of memory\n"));
                        break;
@@ -168,11 +174,11 @@ static SMB_STRUCT_DIR *shadow_copy_fdopendir(vfs_handle_struct *handle, files_st
        SMB_VFS_NEXT_CLOSEDIR(handle,p);
        /* We have now closed the fd in fsp. */
        fsp->fh->fd = -1;
-       return((SMB_STRUCT_DIR *)dirp);
+       return((DIR *)dirp);
 }
 
-static SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle,
-                                             SMB_STRUCT_DIR *_dirp,
+static struct dirent *shadow_copy_readdir(vfs_handle_struct *handle,
+                                             DIR *_dirp,
                                              SMB_STRUCT_STAT *sbuf)
 {
        shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp;
@@ -184,7 +190,7 @@ static SMB_STRUCT_DIRENT *shadow_copy_readdir(vfs_handle_struct *handle,
        return NULL;
 }
 
-static void shadow_copy_seekdir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp, long offset)
+static void shadow_copy_seekdir(struct vfs_handle_struct *handle, DIR *_dirp, long offset)
 {
        shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp;
 
@@ -193,19 +199,19 @@ static void shadow_copy_seekdir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR
        }
 }
 
-static long shadow_copy_telldir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp)
+static long shadow_copy_telldir(struct vfs_handle_struct *handle, DIR *_dirp)
 {
        shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp;
        return( dirp->pos ) ;
 }
 
-static void shadow_copy_rewinddir(struct vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp)
+static void shadow_copy_rewinddir(struct vfs_handle_struct *handle, DIR *_dirp)
 {
        shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp;
        dirp->pos = 0 ;
 }
 
-static int shadow_copy_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp)
+static int shadow_copy_closedir(vfs_handle_struct *handle, DIR *_dirp)
 {
        shadow_copy_Dir *dirp = (shadow_copy_Dir *)_dirp;
 
@@ -215,9 +221,24 @@ static int shadow_copy_closedir(vfs_handle_struct *handle, SMB_STRUCT_DIR *_dirp
        return 0;       
 }
 
-static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_struct *fsp, SHADOW_COPY_DATA *shadow_copy_data, bool labels)
+static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle,
+                                           files_struct *fsp,
+                                           struct shadow_copy_data *shadow_copy_data,
+                                           bool labels)
 {
-       SMB_STRUCT_DIR *p = SMB_VFS_NEXT_OPENDIR(handle,fsp->conn->connectpath,NULL,0);
+       DIR *p = NULL;
+       struct smb_filename *smb_fname = synthetic_smb_fname(talloc_tos(),
+                                               fsp->conn->connectpath,
+                                               NULL,
+                                               NULL);
+       if (smb_fname == NULL) {
+               errno = ENOMEM;
+               return -1;
+       }
+
+       p = SMB_VFS_NEXT_OPENDIR(handle,smb_fname,NULL,0);
+
+       TALLOC_FREE(smb_fname);
 
        shadow_copy_data->num_volumes = 0;
        shadow_copy_data->labels = NULL;
@@ -229,7 +250,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str
 
        while (True) {
                SHADOW_COPY_LABEL *tlabels;
-               SMB_STRUCT_DIRENT *d;
+               struct dirent *d;
 
                d = SMB_VFS_NEXT_READDIR(handle, p, NULL);
                if (d == NULL) {
@@ -249,7 +270,7 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str
                        continue;
                }
 
-               tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data->mem_ctx,
+               tlabels = (SHADOW_COPY_LABEL *)TALLOC_REALLOC(shadow_copy_data,
                                                                        shadow_copy_data->labels,
                                                                        (shadow_copy_data->num_volumes+1)*sizeof(SHADOW_COPY_LABEL));
                if (tlabels == NULL) {
@@ -268,14 +289,14 @@ static int shadow_copy_get_shadow_copy_data(vfs_handle_struct *handle, files_str
 }
 
 static struct vfs_fn_pointers vfs_shadow_copy_fns = {
-       .opendir = shadow_copy_opendir,
-       .fdopendir = shadow_copy_fdopendir,
-       .readdir = shadow_copy_readdir,
-       .seekdir = shadow_copy_seekdir,
-       .telldir = shadow_copy_telldir,
-       .rewind_dir = shadow_copy_rewinddir,
-       .closedir = shadow_copy_closedir,
-       .get_shadow_copy_data = shadow_copy_get_shadow_copy_data,
+       .opendir_fn = shadow_copy_opendir,
+       .fdopendir_fn = shadow_copy_fdopendir,
+       .readdir_fn = shadow_copy_readdir,
+       .seekdir_fn = shadow_copy_seekdir,
+       .telldir_fn = shadow_copy_telldir,
+       .rewind_dir_fn = shadow_copy_rewinddir,
+       .closedir_fn = shadow_copy_closedir,
+       .get_shadow_copy_data_fn = shadow_copy_get_shadow_copy_data,
 };
 
 NTSTATUS vfs_shadow_copy_init(void);