r23792: convert Samba4 to GPLv3
[kai/samba-autobuild/.git] / source4 / ntvfs / unixuid / vfs_unixuid.c
index d724e7ceb2be9ec64bf4947206bc52875bd3d22c..74bc6309c18380be137e598004ffbb61e2dd5b08 100644 (file)
@@ -8,7 +8,7 @@
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "system/filesys.h"
 #include "system/passwd.h"
 #include "auth/auth.h"
-#include "libcli/security/security.h"
-#include "smb_server/smb_server.h"
+#include "ntvfs/ntvfs.h"
+#include "dsdb/samdb/samdb.h"
 
 struct unixuid_private {
        struct sidmap_context *sidmap;
@@ -96,7 +95,7 @@ static NTSTATUS set_unix_security(struct unix_sec_ctx *sec)
   form a unix_sec_ctx from the current security_token
 */
 static NTSTATUS nt_token_to_unix_security(struct ntvfs_module_context *ntvfs,
-                                         struct smbsrv_request *req,
+                                         struct ntvfs_request *req,
                                          struct security_token *token,
                                          struct unix_sec_ctx **sec)
 {
@@ -143,47 +142,46 @@ static NTSTATUS nt_token_to_unix_security(struct ntvfs_module_context *ntvfs,
   setup our unix security context according to the session authentication info
 */
 static NTSTATUS unixuid_setup_security(struct ntvfs_module_context *ntvfs,
-                                      struct smbsrv_request *req, struct unix_sec_ctx **sec)
+                                      struct ntvfs_request *req, struct unix_sec_ctx **sec)
 {
        struct unixuid_private *private = ntvfs->private_data;
-       struct security_token *token = req->session->session_info->security_token;
-       void *ctx = talloc_new(req);
+       struct security_token *token;
        struct unix_sec_ctx *newsec;
        NTSTATUS status;
 
-       if (req->session == NULL) {
+       if (req->session_info == NULL) {
                return NT_STATUS_ACCESS_DENIED;
        }
 
-       *sec = save_unix_security(req);
+       token = req->session_info->security_token;
+
+       *sec = save_unix_security(ntvfs);
        if (*sec == NULL) {
                return NT_STATUS_NO_MEMORY;
        }
 
-       if (req->session->session_info->security_token == private->last_token) {
+       if (token == private->last_token) {
                newsec = private->last_sec_ctx;
        } else {
                status = nt_token_to_unix_security(ntvfs, req, token, &newsec);
                if (!NT_STATUS_IS_OK(status)) {
-                       talloc_free(ctx);
+                       talloc_free(*sec);
                        return status;
                }
                if (private->last_sec_ctx) {
                        talloc_free(private->last_sec_ctx);
                }
                private->last_sec_ctx = newsec;
-               private->last_token = req->session->session_info->security_token;
+               private->last_token = token;
                talloc_steal(private, newsec);
        }
 
        status = set_unix_security(newsec);
        if (!NT_STATUS_IS_OK(status)) {
-               talloc_free(ctx);
+               talloc_free(*sec);
                return status;
        }
 
-       talloc_free(ctx);
-
        return NT_STATUS_OK;
 }
 
@@ -194,8 +192,10 @@ static NTSTATUS unixuid_setup_security(struct ntvfs_module_context *ntvfs,
        NTSTATUS status2; \
        struct unix_sec_ctx *sec; \
        status = unixuid_setup_security(ntvfs, req, &sec); \
-       if (NT_STATUS_IS_OK(status)) status = ntvfs_next_##op args; \
+       NT_STATUS_NOT_OK_RETURN(status); \
+       status = ntvfs_next_##op args; \
        status2 = set_unix_security(sec); \
+       talloc_free(sec); \
        if (!NT_STATUS_IS_OK(status2)) smb_panic("Unable to reset security context"); \
 } while (0)
 
@@ -205,12 +205,12 @@ static NTSTATUS unixuid_setup_security(struct ntvfs_module_context *ntvfs,
   connect to a share - used when a tree_connect operation comes in.
 */
 static NTSTATUS unixuid_connect(struct ntvfs_module_context *ntvfs,
-                               struct smbsrv_request *req, const char *sharename)
+                               struct ntvfs_request *req, const char *sharename)
 {
        struct unixuid_private *private;
        NTSTATUS status;
 
-       private = talloc(req->tcon, struct unixuid_private);
+       private = talloc(ntvfs, struct unixuid_private);
        if (!private) {
                return NT_STATUS_NO_MEMORY;
        }
@@ -235,15 +235,15 @@ static NTSTATUS unixuid_connect(struct ntvfs_module_context *ntvfs,
 /*
   disconnect from a share
 */
-static NTSTATUS unixuid_disconnect(struct ntvfs_module_context *ntvfs,
-                                  struct smbsrv_tcon *tcon)
+static NTSTATUS unixuid_disconnect(struct ntvfs_module_context *ntvfs)
 {
        struct unixuid_private *private = ntvfs->private_data;
        NTSTATUS status;
 
        talloc_free(private);
+       ntvfs->private_data = NULL;
 
-       status = ntvfs_next_disconnect(ntvfs, tcon);
+       status = ntvfs_next_disconnect(ntvfs);
  
        return status;
 }
@@ -253,7 +253,8 @@ static NTSTATUS unixuid_disconnect(struct ntvfs_module_context *ntvfs,
   delete a file
 */
 static NTSTATUS unixuid_unlink(struct ntvfs_module_context *ntvfs,
-                             struct smbsrv_request *req, struct smb_unlink *unl)
+                             struct ntvfs_request *req,
+                             union smb_unlink *unl)
 {
        NTSTATUS status;
 
@@ -266,7 +267,7 @@ static NTSTATUS unixuid_unlink(struct ntvfs_module_context *ntvfs,
   ioctl interface
 */
 static NTSTATUS unixuid_ioctl(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, union smb_ioctl *io)
+                            struct ntvfs_request *req, union smb_ioctl *io)
 {
        NTSTATUS status;
 
@@ -279,7 +280,8 @@ static NTSTATUS unixuid_ioctl(struct ntvfs_module_context *ntvfs,
   check if a directory exists
 */
 static NTSTATUS unixuid_chkpath(struct ntvfs_module_context *ntvfs,
-                              struct smbsrv_request *req, struct smb_chkpath *cp)
+                               struct ntvfs_request *req,
+                               union smb_chkpath *cp)
 {
        NTSTATUS status;
 
@@ -292,7 +294,7 @@ static NTSTATUS unixuid_chkpath(struct ntvfs_module_context *ntvfs,
   return info on a pathname
 */
 static NTSTATUS unixuid_qpathinfo(struct ntvfs_module_context *ntvfs,
-                                struct smbsrv_request *req, union smb_fileinfo *info)
+                                struct ntvfs_request *req, union smb_fileinfo *info)
 {
        NTSTATUS status;
 
@@ -305,7 +307,7 @@ static NTSTATUS unixuid_qpathinfo(struct ntvfs_module_context *ntvfs,
   query info on a open file
 */
 static NTSTATUS unixuid_qfileinfo(struct ntvfs_module_context *ntvfs,
-                                struct smbsrv_request *req, union smb_fileinfo *info)
+                                struct ntvfs_request *req, union smb_fileinfo *info)
 {
        NTSTATUS status;
 
@@ -319,7 +321,7 @@ static NTSTATUS unixuid_qfileinfo(struct ntvfs_module_context *ntvfs,
   set info on a pathname
 */
 static NTSTATUS unixuid_setpathinfo(struct ntvfs_module_context *ntvfs,
-                                  struct smbsrv_request *req, union smb_setfileinfo *st)
+                                  struct ntvfs_request *req, union smb_setfileinfo *st)
 {
        NTSTATUS status;
 
@@ -331,12 +333,12 @@ static NTSTATUS unixuid_setpathinfo(struct ntvfs_module_context *ntvfs,
 /*
   open a file
 */
-static NTSTATUS unixuid_openfile(struct ntvfs_module_context *ntvfs,
-                                struct smbsrv_request *req, union smb_open *io)
+static NTSTATUS unixuid_open(struct ntvfs_module_context *ntvfs,
+                            struct ntvfs_request *req, union smb_open *io)
 {
        NTSTATUS status;
 
-       PASS_THRU_REQ(ntvfs, req, openfile, (ntvfs, req, io));
+       PASS_THRU_REQ(ntvfs, req, open, (ntvfs, req, io));
 
        return status;
 }
@@ -345,7 +347,7 @@ static NTSTATUS unixuid_openfile(struct ntvfs_module_context *ntvfs,
   create a directory
 */
 static NTSTATUS unixuid_mkdir(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, union smb_mkdir *md)
+                            struct ntvfs_request *req, union smb_mkdir *md)
 {
        NTSTATUS status;
 
@@ -358,7 +360,7 @@ static NTSTATUS unixuid_mkdir(struct ntvfs_module_context *ntvfs,
   remove a directory
 */
 static NTSTATUS unixuid_rmdir(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, struct smb_rmdir *rd)
+                            struct ntvfs_request *req, struct smb_rmdir *rd)
 {
        NTSTATUS status;
 
@@ -371,7 +373,7 @@ static NTSTATUS unixuid_rmdir(struct ntvfs_module_context *ntvfs,
   rename a set of files
 */
 static NTSTATUS unixuid_rename(struct ntvfs_module_context *ntvfs,
-                             struct smbsrv_request *req, union smb_rename *ren)
+                             struct ntvfs_request *req, union smb_rename *ren)
 {
        NTSTATUS status;
 
@@ -384,7 +386,7 @@ static NTSTATUS unixuid_rename(struct ntvfs_module_context *ntvfs,
   copy a set of files
 */
 static NTSTATUS unixuid_copy(struct ntvfs_module_context *ntvfs,
-                           struct smbsrv_request *req, struct smb_copy *cp)
+                           struct ntvfs_request *req, struct smb_copy *cp)
 {
        NTSTATUS status;
 
@@ -397,7 +399,7 @@ static NTSTATUS unixuid_copy(struct ntvfs_module_context *ntvfs,
   read from a file
 */
 static NTSTATUS unixuid_read(struct ntvfs_module_context *ntvfs,
-                           struct smbsrv_request *req, union smb_read *rd)
+                           struct ntvfs_request *req, union smb_read *rd)
 {
        NTSTATUS status;
 
@@ -410,7 +412,7 @@ static NTSTATUS unixuid_read(struct ntvfs_module_context *ntvfs,
   write to a file
 */
 static NTSTATUS unixuid_write(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, union smb_write *wr)
+                            struct ntvfs_request *req, union smb_write *wr)
 {
        NTSTATUS status;
 
@@ -423,7 +425,8 @@ static NTSTATUS unixuid_write(struct ntvfs_module_context *ntvfs,
   seek in a file
 */
 static NTSTATUS unixuid_seek(struct ntvfs_module_context *ntvfs,
-                           struct smbsrv_request *req, struct smb_seek *io)
+                            struct ntvfs_request *req,
+                            union smb_seek *io)
 {
        NTSTATUS status;
 
@@ -436,7 +439,8 @@ static NTSTATUS unixuid_seek(struct ntvfs_module_context *ntvfs,
   flush a file
 */
 static NTSTATUS unixuid_flush(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, struct smb_flush *io)
+                             struct ntvfs_request *req,
+                             union smb_flush *io)
 {
        NTSTATUS status;
 
@@ -449,7 +453,7 @@ static NTSTATUS unixuid_flush(struct ntvfs_module_context *ntvfs,
   close a file
 */
 static NTSTATUS unixuid_close(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, union smb_close *io)
+                            struct ntvfs_request *req, union smb_close *io)
 {
        NTSTATUS status;
 
@@ -462,7 +466,7 @@ static NTSTATUS unixuid_close(struct ntvfs_module_context *ntvfs,
   exit - closing files
 */
 static NTSTATUS unixuid_exit(struct ntvfs_module_context *ntvfs,
-                           struct smbsrv_request *req)
+                           struct ntvfs_request *req)
 {
        NTSTATUS status;
 
@@ -475,7 +479,7 @@ static NTSTATUS unixuid_exit(struct ntvfs_module_context *ntvfs,
   logoff - closing files
 */
 static NTSTATUS unixuid_logoff(struct ntvfs_module_context *ntvfs,
-                             struct smbsrv_request *req)
+                             struct ntvfs_request *req)
 {
        struct unixuid_private *private = ntvfs->private_data;
        NTSTATUS status;
@@ -491,7 +495,7 @@ static NTSTATUS unixuid_logoff(struct ntvfs_module_context *ntvfs,
   async setup
 */
 static NTSTATUS unixuid_async_setup(struct ntvfs_module_context *ntvfs,
-                                   struct smbsrv_request *req, 
+                                   struct ntvfs_request *req, 
                                    void *private)
 {
        NTSTATUS status;
@@ -505,7 +509,7 @@ static NTSTATUS unixuid_async_setup(struct ntvfs_module_context *ntvfs,
   cancel an async request
 */
 static NTSTATUS unixuid_cancel(struct ntvfs_module_context *ntvfs,
-                              struct smbsrv_request *req)
+                              struct ntvfs_request *req)
 {
        NTSTATUS status;
 
@@ -514,11 +518,24 @@ static NTSTATUS unixuid_cancel(struct ntvfs_module_context *ntvfs,
        return status;
 }
 
+/*
+  change notify
+*/
+static NTSTATUS unixuid_notify(struct ntvfs_module_context *ntvfs,
+                              struct ntvfs_request *req, union smb_notify *info)
+{
+       NTSTATUS status;
+
+       PASS_THRU_REQ(ntvfs, req, notify, (ntvfs, req, info));
+
+       return status;
+}
+
 /*
   lock a byte range
 */
 static NTSTATUS unixuid_lock(struct ntvfs_module_context *ntvfs,
-                           struct smbsrv_request *req, union smb_lock *lck)
+                           struct ntvfs_request *req, union smb_lock *lck)
 {
        NTSTATUS status;
 
@@ -531,7 +548,7 @@ static NTSTATUS unixuid_lock(struct ntvfs_module_context *ntvfs,
   set info on a open file
 */
 static NTSTATUS unixuid_setfileinfo(struct ntvfs_module_context *ntvfs,
-                                  struct smbsrv_request *req, 
+                                  struct ntvfs_request *req, 
                                   union smb_setfileinfo *info)
 {
        NTSTATUS status;
@@ -546,7 +563,7 @@ static NTSTATUS unixuid_setfileinfo(struct ntvfs_module_context *ntvfs,
   return filesystem space info
 */
 static NTSTATUS unixuid_fsinfo(struct ntvfs_module_context *ntvfs,
-                             struct smbsrv_request *req, union smb_fsinfo *fs)
+                             struct ntvfs_request *req, union smb_fsinfo *fs)
 {
        NTSTATUS status;
 
@@ -559,7 +576,7 @@ static NTSTATUS unixuid_fsinfo(struct ntvfs_module_context *ntvfs,
   return print queue info
 */
 static NTSTATUS unixuid_lpq(struct ntvfs_module_context *ntvfs,
-                          struct smbsrv_request *req, union smb_lpq *lpq)
+                          struct ntvfs_request *req, union smb_lpq *lpq)
 {
        NTSTATUS status;
 
@@ -572,9 +589,9 @@ static NTSTATUS unixuid_lpq(struct ntvfs_module_context *ntvfs,
    list files in a directory matching a wildcard pattern
 */
 static NTSTATUS unixuid_search_first(struct ntvfs_module_context *ntvfs,
-                                   struct smbsrv_request *req, union smb_search_first *io, 
+                                   struct ntvfs_request *req, union smb_search_first *io, 
                                    void *search_private, 
-                                   BOOL (*callback)(void *, union smb_search_data *))
+                                   BOOL (*callback)(void *, const union smb_search_data *))
 {
        NTSTATUS status;
 
@@ -585,9 +602,9 @@ static NTSTATUS unixuid_search_first(struct ntvfs_module_context *ntvfs,
 
 /* continue a search */
 static NTSTATUS unixuid_search_next(struct ntvfs_module_context *ntvfs,
-                                  struct smbsrv_request *req, union smb_search_next *io, 
+                                  struct ntvfs_request *req, union smb_search_next *io, 
                                   void *search_private, 
-                                  BOOL (*callback)(void *, union smb_search_data *))
+                                  BOOL (*callback)(void *, const union smb_search_data *))
 {
        NTSTATUS status;
 
@@ -598,7 +615,7 @@ static NTSTATUS unixuid_search_next(struct ntvfs_module_context *ntvfs,
 
 /* close a search */
 static NTSTATUS unixuid_search_close(struct ntvfs_module_context *ntvfs,
-                                   struct smbsrv_request *req, union smb_search_close *io)
+                                   struct ntvfs_request *req, union smb_search_close *io)
 {
        NTSTATUS status;
 
@@ -609,7 +626,7 @@ static NTSTATUS unixuid_search_close(struct ntvfs_module_context *ntvfs,
 
 /* SMBtrans - not used on file shares */
 static NTSTATUS unixuid_trans(struct ntvfs_module_context *ntvfs,
-                            struct smbsrv_request *req, struct smb_trans2 *trans2)
+                            struct ntvfs_request *req, struct smb_trans2 *trans2)
 {
        NTSTATUS status;
 
@@ -625,6 +642,7 @@ NTSTATUS ntvfs_unixuid_init(void)
 {
        NTSTATUS ret;
        struct ntvfs_ops ops;
+       NTVFS_CURRENT_CRITICAL_SIZES(vers);
 
        ZERO_STRUCT(ops);
 
@@ -635,7 +653,7 @@ NTSTATUS ntvfs_unixuid_init(void)
        ops.chkpath = unixuid_chkpath;
        ops.qpathinfo = unixuid_qpathinfo;
        ops.setpathinfo = unixuid_setpathinfo;
-       ops.openfile = unixuid_openfile;
+       ops.open = unixuid_open;
        ops.mkdir = unixuid_mkdir;
        ops.rmdir = unixuid_rmdir;
        ops.rename = unixuid_rename;
@@ -659,20 +677,21 @@ NTSTATUS ntvfs_unixuid_init(void)
        ops.logoff = unixuid_logoff;
        ops.async_setup = unixuid_async_setup;
        ops.cancel = unixuid_cancel;
+       ops.notify = unixuid_notify;
 
        ops.name = "unixuid";
 
        /* we register under all 3 backend types, as we are not type specific */
        ops.type = NTVFS_DISK;  
-       ret = ntvfs_register(&ops);
+       ret = ntvfs_register(&ops, &vers);
        if (!NT_STATUS_IS_OK(ret)) goto failed;
 
        ops.type = NTVFS_PRINT; 
-       ret = ntvfs_register(&ops);
+       ret = ntvfs_register(&ops, &vers);
        if (!NT_STATUS_IS_OK(ret)) goto failed;
 
        ops.type = NTVFS_IPC;   
-       ret = ntvfs_register(&ops);
+       ret = ntvfs_register(&ops, &vers);
        if (!NT_STATUS_IS_OK(ret)) goto failed;
        
 failed: