Restructure the connect function code to always call
authorJeremy Allison <jra@samba.org>
Mon, 30 Nov 2009 23:53:04 +0000 (15:53 -0800)
committerJeremy Allison <jra@samba.org>
Mon, 30 Nov 2009 23:53:04 +0000 (15:53 -0800)
down to NEXT-> before initializing. This allows us to
do cleanup (by calling DISCONNECT) if initialization
fails. Also fix vfs_acl_xattr which was failing to
call the NEXT connect function.
Jeremy.

16 files changed:
source3/modules/vfs_acl_tdb.c
source3/modules/vfs_acl_xattr.c
source3/modules/vfs_afsacl.c
source3/modules/vfs_audit.c
source3/modules/vfs_cacheprime.c
source3/modules/vfs_commit.c
source3/modules/vfs_extd_audit.c
source3/modules/vfs_fileid.c
source3/modules/vfs_full_audit.c
source3/modules/vfs_onefs.c
source3/modules/vfs_prealloc.c
source3/modules/vfs_readahead.c
source3/modules/vfs_readonly.c
source3/modules/vfs_recycle.c
source3/modules/vfs_smb_traffic_analyzer.c
source3/modules/vfs_tsmsm.c

index db3881e1e738029982bc6730120e0f84da2afd6b..e9d0f9027a70836cf1ef3c4e82e0198bf5c25d93 100644 (file)
@@ -367,12 +367,11 @@ static int connect_acl_tdb(struct vfs_handle_struct *handle,
                                const char *user)
 {
        struct db_context *db;
-       int res;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
 
-        res = SMB_VFS_NEXT_CONNECT(handle, service, user);
-        if (res < 0) {
-                return res;
-        }
+       if (ret < 0) {
+               return ret;
+       }
 
        if (!acl_tdb_init(&db)) {
                SMB_VFS_NEXT_DISCONNECT(handle);
index 962d1b7b09dc954b10adaf1da3ce7dbbeca99596..5e51a688750ffeee7d2e044959508793f9e1f4d9 100644 (file)
@@ -212,6 +212,12 @@ static int connect_acl_xattr(struct vfs_handle_struct *handle,
                                const char *service,
                                const char *user)
 {
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
+
        /* Ensure we have "inherit acls = yes" if we're
         * using this module. */
        DEBUG(2,("connect_acl_xattr: setting 'inherit acls = true' "
index 4666be2aa31a5a25c9084586f0417ca71aee8e3a..82c1799129b947dc071ef86857593c2ecda7765d 100644 (file)
@@ -1065,14 +1065,19 @@ static int afsacl_connect(vfs_handle_struct *handle,
                          const char *service, 
                          const char *user)
 {
-                       const char *spc;
+       const char *spc;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
 
        spc = lp_parm_const_string(SNUM(handle->conn), "afsacl", "space", "%");
 
        if (spc != NULL)
                space_replacement = spc[0];
-       
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       return 0;
 }
 
 static struct vfs_fn_pointers vfs_afsacl_fns = {
index 258246e42db2178db08b0091945c86bdc8283a31..d256c2f7da32aaf37aa4c52405ccbe22bbe3a313 100644 (file)
@@ -78,15 +78,18 @@ static int audit_syslog_priority(vfs_handle_struct *handle)
 static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user)
 {
        int result;
-       
+
+       result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
+       if (result < 0) {
+               return result;
+       }
+
        openlog("smbd_audit", LOG_PID, audit_syslog_facility(handle));
 
        syslog(audit_syslog_priority(handle), "connect to service %s by user %s\n", 
               svc, user);
 
-       result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
-
-       return result;
+       return 0;
 }
 
 static void audit_disconnect(vfs_handle_struct *handle)
index d107c5fc960d92d7a587fbb8c73a0f2f487c44fb..02cffbb703d0e5035a965ed5b0269989a741b31c 100644 (file)
@@ -89,6 +89,8 @@ static int cprime_connect(
                 const char *                service,
                 const char *                user)
 {
+       int ret;
+
         module_debug = lp_parm_int(SNUM(handle->conn), MODULE, "debug", 100);
         if (g_readbuf) {
                 /* Only allocate g_readbuf once. If the config changes and
@@ -98,6 +100,11 @@ static int cprime_connect(
                 return SMB_VFS_NEXT_CONNECT(handle, service, user);
         }
 
+       ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+       if (ret < 0) {
+               return ret;
+       }
+
         g_readsz = conv_str_size(lp_parm_const_string(SNUM(handle->conn),
                                         MODULE, "rsize", NULL));
 
@@ -118,7 +125,7 @@ static int cprime_connect(
                 g_readsz = 0;
         }
 
-        return SMB_VFS_NEXT_CONNECT(handle, service, user);
+        return 0;
 }
 
 static ssize_t cprime_sendfile(
index b92611220361cc03acfa1cffda399a171197bf79..1d099494e935d8bfd6efcc873540330898d3b81f 100644 (file)
@@ -162,8 +162,14 @@ static int commit_connect(
         const char *                service,
         const char *                user)
 {
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
+
         module_debug = lp_parm_int(SNUM(handle->conn), MODULE, "debug", 100);
-        return SMB_VFS_NEXT_CONNECT(handle, service, user);
+        return 0;
 }
 
 static int commit_open(
index c4a20f0bddcd66351cbd338bcb787e7ad291b659..80dece7eddceca2250c535df47d9f3e103708709 100644 (file)
@@ -80,7 +80,11 @@ static int audit_syslog_priority(vfs_handle_struct *handle)
 
 static int audit_connect(vfs_handle_struct *handle, const char *svc, const char *user)
 {
-       int result;
+       int result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
+
+       if (result < 0) {
+               return result;
+       }
 
        openlog("smbd_audit", LOG_PID, audit_syslog_facility(handle));
 
@@ -92,9 +96,7 @@ static int audit_connect(vfs_handle_struct *handle, const char *svc, const char
        DEBUG(10, ("Connected to service %s as user %s\n",
               svc, user));
 
-       result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
-
-       return result;
+       return 0;
 }
 
 static void audit_disconnect(vfs_handle_struct *handle)
index 133ad09cc3aaab5cda0cb936746924a8df4306e2..559b520d1cd0d7473155c103e057fd980cf2cc15 100644 (file)
@@ -181,9 +181,15 @@ static int fileid_connect(struct vfs_handle_struct *handle,
 {
        struct fileid_handle_data *data;
        const char *algorithm;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
 
        data = talloc_zero(handle->conn, struct fileid_handle_data);
        if (!data) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0, ("talloc_zero() failed\n"));
                return -1;
        }
@@ -203,6 +209,7 @@ static int fileid_connect(struct vfs_handle_struct *handle,
        } else if (strcmp("fsid", algorithm) == 0) {
                data->device_mapping_fn = fileid_device_mapping_fsid;
        } else {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0,("fileid_connect(): unknown algorithm[%s]\n", algorithm));
                return -1;
        }
@@ -214,7 +221,7 @@ static int fileid_connect(struct vfs_handle_struct *handle,
        DEBUG(10, ("fileid_connect(): connect to service[%s] with algorithm[%s]\n",
                service, algorithm));
 
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 static void fileid_disconnect(struct vfs_handle_struct *handle)
index d9d12a1d285257fc6318c2bb2093900b46ea5fcd..19ac7adaed3bd42ef7e9f98877a6a0b3bf5101bf 100644 (file)
@@ -606,12 +606,14 @@ static int smb_full_audit_connect(vfs_handle_struct *handle,
        const char *none[] = { NULL };
        const char *all [] = { "all" };
 
-       if (!handle) {
-               return -1;
+       result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
+       if (result < 0) {
+               return result;
        }
 
        pd = SMB_MALLOC_P(struct vfs_full_audit_private_data);
        if (!pd) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                return -1;
        }
        ZERO_STRUCTP(pd);
@@ -631,12 +633,10 @@ static int smb_full_audit_connect(vfs_handle_struct *handle,
        SMB_VFS_HANDLE_SET_DATA(handle, pd, free_private_data,
                                struct vfs_full_audit_private_data, return -1);
 
-       result = SMB_VFS_NEXT_CONNECT(handle, svc, user);
-
        do_log(SMB_VFS_OP_CONNECT, True, handle,
               "%s", svc);
 
-       return result;
+       return 0;
 }
 
 static void smb_full_audit_disconnect(vfs_handle_struct *handle)
index 865eccdbf5d968e324b10b714997746a343e7cf5..5f1b99292b79c1f7cc87e721a10ffb34898383a0 100644 (file)
 static int onefs_connect(struct vfs_handle_struct *handle, const char *service,
                         const char *user)
 {
-       int ret;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
 
        ret = onefs_load_config(handle->conn);
        if (ret) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(3, ("Load config failed: %s\n", strerror(errno)));
                return ret;
        }
 
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 static int onefs_mkdir(vfs_handle_struct *handle, const char *path,
index c6333be23b8bcdcdce746c1013a0bc0d314b958e..386de2907143c7ef0fc25ee94aa811190a3f6710 100644 (file)
@@ -101,10 +101,16 @@ static int prealloc_connect(
                 const char *                service,
                 const char *                user)
 {
-           module_debug = lp_parm_int(SNUM(handle->conn),
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
+
+       module_debug = lp_parm_int(SNUM(handle->conn),
                                        MODULE, "debug", 100);
 
-           return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 static int prealloc_open(vfs_handle_struct* handle,
index 124230811dd75c371d9697f9ccb05fb594d7fbd4..e7a7dd305ccecb7ee933639f837332910024a0f4 100644 (file)
@@ -127,8 +127,15 @@ static int readahead_connect(struct vfs_handle_struct *handle,
                                const char *service,
                                const char *user)
 {
-       struct readahead_data *rhd = SMB_MALLOC_P(struct readahead_data);
+       struct readahead_data *rhd;
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
+       rhd = SMB_MALLOC_P(struct readahead_data);
        if (!rhd) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0,("readahead_connect: out of memory\n"));
                return -1;
        }
@@ -152,7 +159,7 @@ static int readahead_connect(struct vfs_handle_struct *handle,
 
        handle->data = (void *)rhd;
        handle->free_data = free_readahead_data;
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 static struct vfs_fn_pointers vfs_readahead_fns = {
index f73602816887581a71c25ebf1831ec947c3c44ed..afb167f045d5749b1ead3f44dddd19f8f1f1a3f9 100644 (file)
@@ -62,6 +62,11 @@ static int readonly_connect(vfs_handle_struct *handle,
   const char **period = lp_parm_string_list(SNUM(handle->conn),
                                             (handle->param ? handle->param : MODULE_NAME),
                                             "period", period_def); 
+  int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+  if (ret < 0) {
+    return ret;
+  }
 
   if (period && period[0] && period[1]) {
     int i;
@@ -85,11 +90,11 @@ static int readonly_connect(vfs_handle_struct *handle,
       conn->vuid_cache.next_entry = 0;
     }
 
-    return SMB_VFS_NEXT_CONNECT(handle, service, user);
+    return 0;
 
   } else {
     
-    return 1;
+    return 0;
     
   }
 }
index 0c019dbd702d0971ff0c2e4c15fc75d1ca71851c..667442732ea4aed2b38c16bba41861cbbf02ee13 100644 (file)
@@ -38,10 +38,16 @@ static int recycle_unlink(vfs_handle_struct *handle,
 
 static int recycle_connect(vfs_handle_struct *handle, const char *service, const char *user)
 {
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
+
        DEBUG(10,("recycle_connect() connect to service[%s] as user[%s].\n",
                service,user));
 
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 static void recycle_disconnect(vfs_handle_struct *handle)
index 08389f5d90cdfbf21eacf91e349834b72e114fa9..1eb02a2581c6c498e80a458505eb59c834717e4d 100644 (file)
@@ -277,6 +277,11 @@ static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
        uint16_t port = (st == UNIX_DOMAIN_SOCKET) ? 0 :
                                atoi( lp_parm_const_string(SNUM(conn),
                                "smb_traffic_analyzer", "port", "9430"));
+       int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
 
        /* Are we already connected ? */
        for (rf_sock = sock_list; rf_sock; rf_sock = rf_sock->next) {
@@ -294,11 +299,13 @@ static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
                /* New connection. */
                rf_sock = TALLOC_ZERO_P(NULL, struct refcounted_sock);
                if (rf_sock == NULL) {
+                       SMB_VFS_NEXT_DISCONNECT(handle);
                        errno = ENOMEM;
                        return -1;
                }
                rf_sock->name = talloc_strdup(rf_sock, name);
                if (rf_sock->name == NULL) {
+                       SMB_VFS_NEXT_DISCONNECT(handle);
                        TALLOC_FREE(rf_sock);
                        errno = ENOMEM;
                        return -1;
@@ -316,6 +323,7 @@ static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
                                                        port);
                }
                if (rf_sock->sock == -1) {
+                       SMB_VFS_NEXT_DISCONNECT(handle);
                        TALLOC_FREE(rf_sock);
                        return -1;
                }
@@ -325,7 +333,7 @@ static int smb_traffic_analyzer_connect(struct vfs_handle_struct *handle,
        /* Store the private data. */
        SMB_VFS_HANDLE_SET_DATA(handle, rf_sock, smb_traffic_analyzer_free_data,
                                struct refcounted_sock, return -1);
-       return SMB_VFS_NEXT_CONNECT(handle, service, user);
+       return 0;
 }
 
 /* VFS Functions: write, read, pread, pwrite for now */
index 7c63b8c20e837e5c5df2262f6d0f92c776758a47..12f79ff71e86ae0029f68ea1dc4b2df893c72751 100644 (file)
@@ -87,16 +87,24 @@ static void tsmsm_free_data(void **pptr) {
 static int tsmsm_connect(struct vfs_handle_struct *handle,
                         const char *service,
                         const char *user) {
-       struct tsmsm_struct *tsmd = TALLOC_ZERO_P(handle, struct tsmsm_struct);
+       struct tsmsm_struct *tsmd;
        const char *fres;
        const char *tsmname;
-       
+        int ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
+
+       if (ret < 0) {
+               return ret;
+       }
+
+       tsmd = TALLOC_ZERO_P(handle, struct tsmsm_struct);
        if (!tsmd) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0,("tsmsm_connect: out of memory!\n"));
                return -1;
        }
 
        if (!dmapi_have_session()) {
+               SMB_VFS_NEXT_DISCONNECT(handle);
                DEBUG(0,("tsmsm_connect: no DMAPI session for Samba is available!\n"));
                TALLOC_FREE(tsmd);
                return -1;
@@ -134,7 +142,7 @@ static int tsmsm_connect(struct vfs_handle_struct *handle,
         /* Store the private data. */
         SMB_VFS_HANDLE_SET_DATA(handle, tsmd, tsmsm_free_data,
                                 struct tsmsm_struct, return -1);
-        return SMB_VFS_NEXT_CONNECT(handle, service, user); 
+        return 0;
 }
 
 static bool tsmsm_is_offline(struct vfs_handle_struct *handle,