r14736: - the ntvfs subsystem should not know about smb_server.h
[jra/samba/.git] / source4 / ntvfs / simple / vfs_simple.c
index be9a680d5b2f60b3033f38f4086ce42ff23c19dd..2347f31bde118d511190318e1d64d23af4a04d3a 100644 (file)
@@ -32,7 +32,6 @@
 #include "svfs.h"
 #include "system/time.h"
 #include "dlinklist.h"
-#include "smb_server/smb_server.h"
 #include "ntvfs/ntvfs.h"
 #include "ntvfs/simple/proto.h"
 
@@ -40,7 +39,7 @@
 #define O_DIRECTORY 0
 #endif
 
-#define CHECK_READ_ONLY(req) do { if (lp_readonly(req->tcon->service)) return NT_STATUS_ACCESS_DENIED; } while (0)
+#define CHECK_READ_ONLY(req) do { if (lp_readonly(ntvfs->ctx->config.snum)) return NT_STATUS_ACCESS_DENIED; } while (0)
 
 /*
   connect to a share - used when a tree_connect operation comes
@@ -52,13 +51,13 @@ static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs,
                             struct ntvfs_request *req, const char *sharename)
 {
        struct stat st;
-       struct smbsrv_tcon *tcon = req->tcon;
        struct svfs_private *private;
+       int snum = ntvfs->ctx->config.snum;
 
        private = talloc(ntvfs, struct svfs_private);
 
        private->next_search_handle = 0;
-       private->connectpath = talloc_strdup(private, lp_pathname(tcon->service));
+       private->connectpath = talloc_strdup(private, lp_pathname(snum));
        private->open_files = NULL;
        private->search = NULL;
 
@@ -69,8 +68,10 @@ static NTSTATUS svfs_connect(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_BAD_NETWORK_NAME;
        }
 
-       tcon->fs_type = talloc_strdup(tcon, "NTFS");
-       tcon->dev_type = talloc_strdup(tcon, "A:");
+       ntvfs->ctx->fs_type = talloc_strdup(ntvfs->ctx, "NTFS");
+       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->fs_type);
+       ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
+       NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
 
        ntvfs->private_data = private;
 
@@ -106,13 +107,14 @@ static struct svfs_file *find_fd(struct svfs_private *private, int fd)
   The name can contain CIFS wildcards, but rarely does (except with OS/2 clients)
 */
 static NTSTATUS svfs_unlink(struct ntvfs_module_context *ntvfs,
-                           struct ntvfs_request *req, struct smb_unlink *unl)
+                           struct ntvfs_request *req,
+                           union smb_unlink *unl)
 {
        char *unix_path;
 
        CHECK_READ_ONLY(req);
 
-       unix_path = svfs_unix_path(ntvfs, req, unl->in.pattern);
+       unix_path = svfs_unix_path(ntvfs, req, unl->unlink.in.pattern);
 
        /* ignoring wildcards ... */
        if (unlink(unix_path) == -1) {
@@ -136,12 +138,13 @@ static NTSTATUS svfs_ioctl(struct ntvfs_module_context *ntvfs,
   check if a directory exists
 */
 static NTSTATUS svfs_chkpath(struct ntvfs_module_context *ntvfs,
-                            struct ntvfs_request *req, struct smb_chkpath *cp)
+                            struct ntvfs_request *req,
+                            union smb_chkpath *cp)
 {
        char *unix_path;
        struct stat st;
 
-       unix_path = svfs_unix_path(ntvfs, req, cp->in.path);
+       unix_path = svfs_unix_path(ntvfs, req, cp->chkpath.in.path);
 
        if (stat(unix_path, &st) == -1) {
                return map_nt_error_from_unix(errno);
@@ -250,12 +253,12 @@ static NTSTATUS svfs_qpathinfo(struct ntvfs_module_context *ntvfs,
        char *unix_path;
        struct stat st;
 
-       DEBUG(19,("svfs_qpathinfo: file %s level 0x%x\n", info->generic.in.fname, info->generic.level));
+       DEBUG(19,("svfs_qpathinfo: file %s level 0x%x\n", info->generic.in.file.path, info->generic.level));
        if (info->generic.level != RAW_FILEINFO_GENERIC) {
                return ntvfs_map_qpathinfo(ntvfs, req, info);
        }
        
-       unix_path = svfs_unix_path(ntvfs, req, info->generic.in.fname);
+       unix_path = svfs_unix_path(ntvfs, req, info->generic.in.file.path);
        DEBUG(19,("svfs_qpathinfo: file %s\n", unix_path));
        if (stat(unix_path, &st) == -1) {
                DEBUG(19,("svfs_qpathinfo: file %s errno=%d\n", unix_path, errno));
@@ -279,12 +282,12 @@ static NTSTATUS svfs_qfileinfo(struct ntvfs_module_context *ntvfs,
                return ntvfs_map_qfileinfo(ntvfs, req, info);
        }
 
-       f = find_fd(private, info->generic.in.fnum);
+       f = find_fd(private, info->generic.in.file.fnum);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
        
-       if (fstat(info->generic.in.fnum, &st) == -1) {
+       if (fstat(info->generic.in.file.fnum, &st) == -1) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -304,12 +307,14 @@ static NTSTATUS svfs_open(struct ntvfs_module_context *ntvfs,
        int fd, flags;
        struct svfs_file *f;
        int create_flags, rdwr_flags;
+       BOOL readonly;
        
        if (io->generic.level != RAW_OPEN_GENERIC) {
                return ntvfs_map_open(ntvfs, req, io);
        }
 
-       if (lp_readonly(req->tcon->service)) {
+       readonly = lp_readonly(ntvfs->ctx->config.snum);
+       if (readonly) {
                create_flags = 0;
                rdwr_flags = O_RDONLY;
        } else {
@@ -343,7 +348,7 @@ static NTSTATUS svfs_open(struct ntvfs_module_context *ntvfs,
 
        if (io->generic.in.create_options & NTCREATEX_OPTIONS_DIRECTORY) {
                flags = O_RDONLY | O_DIRECTORY;
-               if (lp_readonly(req->tcon->service)) {
+               if (readonly) {
                        goto do_open;
                }
                switch (io->generic.in.open_disposition) {
@@ -374,9 +379,11 @@ do_open:
                return map_nt_error_from_unix(errno);
        }
 
-       f = talloc(req->tcon, struct svfs_file);
+       f = talloc(ntvfs, struct svfs_file);
+       NT_STATUS_HAVE_NO_MEMORY(f);
        f->fd = fd;
-       f->name = talloc_strdup(req->tcon, unix_path);
+       f->name = talloc_strdup(f, unix_path);
+       NT_STATUS_HAVE_NO_MEMORY(f->name);
 
        DLIST_ADD(private->open_files, f);
 
@@ -386,7 +393,7 @@ do_open:
        unix_to_nt_time(&io->generic.out.access_time, st.st_atime);
        unix_to_nt_time(&io->generic.out.write_time,  st.st_mtime);
        unix_to_nt_time(&io->generic.out.change_time, st.st_mtime);
-       io->generic.out.fnum = fd;
+       io->generic.out.file.fnum = fd;
        io->generic.out.alloc_size = st.st_size;
        io->generic.out.size = st.st_size;
        io->generic.out.attrib = svfs_unix_to_dos_attrib(st.st_mode);
@@ -482,7 +489,7 @@ static NTSTATUS svfs_read(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       ret = pread(rd->readx.in.fnum, 
+       ret = pread(rd->readx.in.file.fnum, 
                    rd->readx.out.data, 
                    rd->readx.in.maxcnt,
                    rd->readx.in.offset);
@@ -511,7 +518,7 @@ static NTSTATUS svfs_write(struct ntvfs_module_context *ntvfs,
 
        CHECK_READ_ONLY(req);
 
-       ret = pwrite(wr->writex.in.fnum, 
+       ret = pwrite(wr->writex.in.file.fnum, 
                     wr->writex.in.data, 
                     wr->writex.in.count,
                     wr->writex.in.offset);
@@ -529,7 +536,8 @@ static NTSTATUS svfs_write(struct ntvfs_module_context *ntvfs,
   seek in a file
 */
 static NTSTATUS svfs_seek(struct ntvfs_module_context *ntvfs,
-                         struct ntvfs_request *req, struct smb_seek *io)
+                         struct ntvfs_request *req,
+                         union smb_seek *io)
 {
        return NT_STATUS_NOT_SUPPORTED;
 }
@@ -538,9 +546,10 @@ static NTSTATUS svfs_seek(struct ntvfs_module_context *ntvfs,
   flush a file
 */
 static NTSTATUS svfs_flush(struct ntvfs_module_context *ntvfs,
-                          struct ntvfs_request *req, struct smb_flush *io)
+                          struct ntvfs_request *req,
+                          union smb_flush *io)
 {
-       fsync(io->in.fnum);
+       fsync(io->flush.in.file.fnum);
        return NT_STATUS_OK;
 }
 
@@ -548,7 +557,8 @@ static NTSTATUS svfs_flush(struct ntvfs_module_context *ntvfs,
   close a file
 */
 static NTSTATUS svfs_close(struct ntvfs_module_context *ntvfs,
-                          struct ntvfs_request *req, union smb_close *io)
+                          struct ntvfs_request *req,
+                          union smb_close *io)
 {
        struct svfs_private *private = ntvfs->private_data;
        struct svfs_file *f;
@@ -558,12 +568,12 @@ static NTSTATUS svfs_close(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_INVALID_LEVEL;
        }
 
-       f = find_fd(private, io->close.in.fnum);
+       f = find_fd(private, io->close.in.file.fnum);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
 
-       if (close(io->close.in.fnum) == -1) {
+       if (close(io->close.in.file.fnum) == -1) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -646,7 +656,7 @@ static NTSTATUS svfs_setfileinfo(struct ntvfs_module_context *ntvfs,
        switch (info->generic.level) {
        case RAW_SFILEINFO_END_OF_FILE_INFO:
        case RAW_SFILEINFO_END_OF_FILE_INFORMATION:
-               if (ftruncate(info->end_of_file_info.file.fnum, 
+               if (ftruncate(info->end_of_file_info.in.file.fnum, 
                              info->end_of_file_info.in.size) == -1) {
                        return map_nt_error_from_unix(errno);
                }
@@ -654,7 +664,7 @@ static NTSTATUS svfs_setfileinfo(struct ntvfs_module_context *ntvfs,
        case RAW_SFILEINFO_SETATTRE:
                unix_times.actime = info->setattre.in.access_time;
                unix_times.modtime = info->setattre.in.write_time;
-               fd = info->setattre.file.fnum;
+               fd = info->setattre.in.file.fnum;
        
                if (unix_times.actime == 0 && unix_times.modtime == 0) {
                        break;
@@ -714,8 +724,8 @@ static NTSTATUS svfs_fsinfo(struct ntvfs_module_context *ntvfs,
        fs->generic.out.quota_soft = 0;
        fs->generic.out.quota_hard = 0;
        fs->generic.out.quota_flags = 0;
-       fs->generic.out.volume_name = talloc_strdup(req, lp_servicename(req->tcon->service));
-       fs->generic.out.fs_type = req->tcon->fs_type;
+       fs->generic.out.volume_name = talloc_strdup(req, lp_servicename(ntvfs->ctx->config.snum));
+       fs->generic.out.fs_type = ntvfs->ctx->fs_type;
 
        return NT_STATUS_OK;
 }