Change uint_t to unsigned int in source4
[garming/samba-autobuild/.git] / source4 / ntvfs / cifs_posix_cli / vfs_cifs_posix.c
index 34a26b06b48a528c11001007a618606e3b076ea2..6ee69616101a17d026d7517565d21538e2bab1c9 100644 (file)
   that comes later)
 */
 static NTSTATUS cifspsx_connect(struct ntvfs_module_context *ntvfs,
-                            struct ntvfs_request *req, const char *sharename)
+                               struct ntvfs_request *req,
+                               union smb_tcon* tcon)
 {
        struct stat st;
-       struct cifspsx_private *private;
+       struct cifspsx_private *p;
        struct share_config *scfg = ntvfs->ctx->config;
+       const char *sharename;
 
-       private = talloc(ntvfs, struct cifspsx_private);
-       NT_STATUS_HAVE_NO_MEMORY(private);
-       private->ntvfs = ntvfs;
-       private->next_search_handle = 0;
-       private->connectpath = talloc_strdup(private, share_string_option(scfg, SHARE_PATH, ""));
-       private->open_files = NULL;
-       private->search = NULL;
+       switch (tcon->generic.level) {
+       case RAW_TCON_TCON:
+               sharename = tcon->tcon.in.service;
+               break;
+       case RAW_TCON_TCONX:
+               sharename = tcon->tconx.in.path;
+               break;
+       case RAW_TCON_SMB2:
+               sharename = tcon->smb2.in.path;
+               break;
+       default:
+               return NT_STATUS_INVALID_LEVEL;
+       }
+
+       if (strncmp(sharename, "\\\\", 2) == 0) {
+               char *str = strchr(sharename+2, '\\');
+               if (str) {
+                       sharename = str + 1;
+               }
+       }
+
+       p = talloc(ntvfs, struct cifspsx_private);
+       NT_STATUS_HAVE_NO_MEMORY(p);
+       p->ntvfs = ntvfs;
+       p->next_search_handle = 0;
+       p->connectpath = talloc_strdup(p, share_string_option(scfg, SHARE_PATH, ""));
+       p->open_files = NULL;
+       p->search = NULL;
 
        /* the directory must exist */
-       if (stat(private->connectpath, &st) != 0 || !S_ISDIR(st.st_mode)) {
+       if (stat(p->connectpath, &st) != 0 || !S_ISDIR(st.st_mode)) {
                DEBUG(0,("'%s' is not a directory, when connecting to [%s]\n", 
-                        private->connectpath, sharename));
+                        p->connectpath, sharename));
                return NT_STATUS_BAD_NETWORK_NAME;
        }
 
@@ -74,7 +97,12 @@ static NTSTATUS cifspsx_connect(struct ntvfs_module_context *ntvfs,
        ntvfs->ctx->dev_type = talloc_strdup(ntvfs->ctx, "A:");
        NT_STATUS_HAVE_NO_MEMORY(ntvfs->ctx->dev_type);
 
-       ntvfs->private_data = private;
+       if (tcon->generic.level == RAW_TCON_TCONX) {
+               tcon->tconx.out.fs_type = ntvfs->ctx->fs_type;
+               tcon->tconx.out.dev_type = ntvfs->ctx->dev_type;
+       }
+
+       ntvfs->private_data = p;
 
        DEBUG(0,("WARNING: ntvfs cifs posix: connect to share [%s] with ROOT privileges!!!\n",sharename));
 
@@ -92,12 +120,12 @@ static NTSTATUS cifspsx_disconnect(struct ntvfs_module_context *ntvfs)
 /*
   find open file handle given fd
 */
-static struct cifspsx_file *find_fd(struct cifspsx_private *private, struct ntvfs_handle *handle)
+static struct cifspsx_file *find_fd(struct cifspsx_private *cp, struct ntvfs_handle *handle)
 {
        struct cifspsx_file *f;
        void *p;
 
-       p = ntvfs_handle_get_backend_data(handle, private->ntvfs);
+       p = ntvfs_handle_get_backend_data(handle, cp->ntvfs);
        if (!p) return NULL;
 
        f = talloc_get_type(p, struct cifspsx_file);
@@ -278,7 +306,7 @@ static NTSTATUS cifspsx_qpathinfo(struct ntvfs_module_context *ntvfs,
 static NTSTATUS cifspsx_qfileinfo(struct ntvfs_module_context *ntvfs,
                               struct ntvfs_request *req, union smb_fileinfo *info)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct cifspsx_file *f;
        struct stat st;
 
@@ -286,7 +314,7 @@ static NTSTATUS cifspsx_qfileinfo(struct ntvfs_module_context *ntvfs,
                return ntvfs_map_qfileinfo(ntvfs, req, info);
        }
 
-       f = find_fd(private, info->generic.in.file.ntvfs);
+       f = find_fd(p, info->generic.in.file.ntvfs);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
@@ -305,7 +333,7 @@ static NTSTATUS cifspsx_qfileinfo(struct ntvfs_module_context *ntvfs,
 static NTSTATUS cifspsx_open(struct ntvfs_module_context *ntvfs,
                          struct ntvfs_request *req, union smb_open *io)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        char *unix_path;
        struct stat st;
        int fd, flags;
@@ -394,7 +422,7 @@ do_open:
        f->name = talloc_strdup(f, unix_path);
        NT_STATUS_HAVE_NO_MEMORY(f->name);
 
-       DLIST_ADD(private->open_files, f);
+       DLIST_ADD(p->open_files, f);
 
        status = ntvfs_handle_set_backend_data(handle, ntvfs, f);
        NT_STATUS_NOT_OK_RETURN(status);
@@ -495,7 +523,7 @@ static NTSTATUS cifspsx_copy(struct ntvfs_module_context *ntvfs,
 static NTSTATUS cifspsx_read(struct ntvfs_module_context *ntvfs,
                          struct ntvfs_request *req, union smb_read *rd)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct cifspsx_file *f;
        ssize_t ret;
 
@@ -503,7 +531,7 @@ static NTSTATUS cifspsx_read(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       f = find_fd(private, rd->readx.in.file.ntvfs);
+       f = find_fd(p, rd->readx.in.file.ntvfs);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
@@ -529,7 +557,7 @@ static NTSTATUS cifspsx_read(struct ntvfs_module_context *ntvfs,
 static NTSTATUS cifspsx_write(struct ntvfs_module_context *ntvfs,
                           struct ntvfs_request *req, union smb_write *wr)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct cifspsx_file *f;
        ssize_t ret;
 
@@ -539,7 +567,7 @@ static NTSTATUS cifspsx_write(struct ntvfs_module_context *ntvfs,
 
        CHECK_READ_ONLY(req);
 
-       f = find_fd(private, wr->writex.in.file.ntvfs);
+       f = find_fd(p, wr->writex.in.file.ntvfs);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
@@ -575,14 +603,14 @@ static NTSTATUS cifspsx_flush(struct ntvfs_module_context *ntvfs,
                           struct ntvfs_request *req,
                           union smb_flush *io)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct cifspsx_file *f;
 
        switch (io->generic.level) {
        case RAW_FLUSH_FLUSH:
        case RAW_FLUSH_SMB2:
                /* ignore the additional unknown option in SMB2 */
-               f = find_fd(private, io->generic.in.file.ntvfs);
+               f = find_fd(p, io->generic.in.file.ntvfs);
                if (!f) {
                        return NT_STATUS_INVALID_HANDLE;
                }
@@ -590,7 +618,7 @@ static NTSTATUS cifspsx_flush(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_OK;
 
        case RAW_FLUSH_ALL:
-               for (f=private->open_files;f;f=f->next) {
+               for (f=p->open_files;f;f=f->next) {
                        fsync(f->fd);
                }
                return NT_STATUS_OK;
@@ -606,7 +634,7 @@ static NTSTATUS cifspsx_close(struct ntvfs_module_context *ntvfs,
                           struct ntvfs_request *req,
                           union smb_close *io)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct cifspsx_file *f;
 
        if (io->generic.level != RAW_CLOSE_CLOSE) {
@@ -614,7 +642,7 @@ static NTSTATUS cifspsx_close(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_INVALID_LEVEL;
        }
 
-       f = find_fd(private, io->close.in.file.ntvfs);
+       f = find_fd(p, io->close.in.file.ntvfs);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
@@ -623,7 +651,7 @@ static NTSTATUS cifspsx_close(struct ntvfs_module_context *ntvfs,
                return map_nt_error_from_unix(errno);
        }
 
-       DLIST_REMOVE(private->open_files, f);
+       DLIST_REMOVE(p->open_files, f);
        talloc_free(f->name);
        talloc_free(f);
 
@@ -653,7 +681,7 @@ static NTSTATUS cifspsx_logoff(struct ntvfs_module_context *ntvfs,
 */
 static NTSTATUS cifspsx_async_setup(struct ntvfs_module_context *ntvfs,
                                 struct ntvfs_request *req, 
-                                void *private)
+                                void *private_data)
 {
        return NT_STATUS_OK;
 }
@@ -694,13 +722,13 @@ static NTSTATUS cifspsx_setfileinfo(struct ntvfs_module_context *ntvfs,
                                 struct ntvfs_request *req, 
                                 union smb_setfileinfo *info)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct cifspsx_file *f;
        struct utimbuf unix_times;
 
        CHECK_READ_ONLY(req);
 
-       f = find_fd(private, info->generic.in.file.ntvfs);
+       f = find_fd(p, info->generic.in.file.ntvfs);
        if (!f) {
                return NT_STATUS_INVALID_HANDLE;
        }
@@ -746,14 +774,14 @@ static NTSTATUS cifspsx_setfileinfo(struct ntvfs_module_context *ntvfs,
 static NTSTATUS cifspsx_fsinfo(struct ntvfs_module_context *ntvfs,
                            struct ntvfs_request *req, union smb_fsinfo *fs)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct stat st;
 
        if (fs->generic.level != RAW_QFS_GENERIC) {
                return ntvfs_map_fsinfo(ntvfs, req, fs);
        }
 
-       if (sys_fsusage(private->connectpath, 
+       if (sys_fsusage(p->connectpath,
                        &fs->generic.out.blocks_free, 
                        &fs->generic.out.blocks_total) == -1) {
                return map_nt_error_from_unix(errno);
@@ -761,7 +789,7 @@ static NTSTATUS cifspsx_fsinfo(struct ntvfs_module_context *ntvfs,
 
        fs->generic.out.block_size = 512;
 
-       if (stat(private->connectpath, &st) != 0) {
+       if (stat(p->connectpath, &st) != 0) {
                return NT_STATUS_DISK_CORRUPT_ERROR;
        }
        
@@ -789,13 +817,13 @@ static NTSTATUS cifspsx_fsattr(struct ntvfs_module_context *ntvfs,
                            struct ntvfs_request *req, union smb_fsattr *fs)
 {
        struct stat st;
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
 
        if (fs->generic.level != RAW_FSATTR_GENERIC) {
                return ntvfs_map_fsattr(ntvfs, req, fs);
        }
 
-       if (stat(private->connectpath, &st) == -1) {
+       if (stat(p->connectpath, &st) == -1) {
                return map_nt_error_from_unix(errno);
        }
 
@@ -833,10 +861,10 @@ static NTSTATUS cifspsx_search_first(struct ntvfs_module_context *ntvfs,
 {
        struct cifspsx_dir *dir;
        int i;
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct search_state *search;
        union smb_search_data file;
-       uint_t max_count;
+       unsigned int max_count;
 
        if (io->generic.level != RAW_SEARCH_TRANS2) {
                return NT_STATUS_NOT_SUPPORTED;
@@ -846,7 +874,7 @@ static NTSTATUS cifspsx_search_first(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       search = talloc_zero(private, struct search_state);
+       search = talloc_zero(p, struct search_state);
        if (!search) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -858,7 +886,7 @@ static NTSTATUS cifspsx_search_first(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_FOOBAR;
        }
 
-       search->handle = private->next_search_handle;
+       search->handle = p->next_search_handle;
        search->dir = dir;
 
        if (dir->count < max_count) {
@@ -892,8 +920,8 @@ static NTSTATUS cifspsx_search_first(struct ntvfs_module_context *ntvfs,
            ((io->t2ffirst.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && (i == dir->count))) {
                talloc_free(search);
        } else {
-               private->next_search_handle++;
-               DLIST_ADD(private->search, search);
+               p->next_search_handle++;
+               DLIST_ADD(p->search, search);
        }
 
        return NT_STATUS_OK;
@@ -907,10 +935,10 @@ static NTSTATUS cifspsx_search_next(struct ntvfs_module_context *ntvfs,
 {
        struct cifspsx_dir *dir;
        int i;
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct search_state *search;
        union smb_search_data file;
-       uint_t max_count;
+       unsigned int max_count;
 
        if (io->generic.level != RAW_SEARCH_TRANS2) {
                return NT_STATUS_NOT_SUPPORTED;
@@ -920,7 +948,7 @@ static NTSTATUS cifspsx_search_next(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_NOT_SUPPORTED;
        }
 
-       for (search=private->search; search; search = search->next) {
+       for (search=p->search; search; search = search->next) {
                if (search->handle == io->t2fnext.in.handle) break;
        }
        
@@ -984,7 +1012,7 @@ found:
        /* work out if we are going to keep the search state */
        if ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE) ||
            ((io->t2fnext.in.flags & FLAG_TRANS2_FIND_CLOSE_IF_END) && (i == dir->count))) {
-               DLIST_REMOVE(private->search, search);
+               DLIST_REMOVE(p->search, search);
                talloc_free(search);
        }
 
@@ -995,10 +1023,10 @@ found:
 static NTSTATUS cifspsx_search_close(struct ntvfs_module_context *ntvfs,
                                  struct ntvfs_request *req, union smb_search_close *io)
 {
-       struct cifspsx_private *private = ntvfs->private_data;
+       struct cifspsx_private *p = ntvfs->private_data;
        struct search_state *search;
 
-       for (search=private->search; search; search = search->next) {
+       for (search=p->search; search; search = search->next) {
                if (search->handle == io->findclose.in.handle) break;
        }
        
@@ -1007,7 +1035,7 @@ static NTSTATUS cifspsx_search_close(struct ntvfs_module_context *ntvfs,
                return NT_STATUS_FOOBAR;
        }
 
-       DLIST_REMOVE(private->search, search);
+       DLIST_REMOVE(p->search, search);
        talloc_free(search);
 
        return NT_STATUS_OK;