Fix error code when smbclient puts a file over an existing directory
[kai/samba.git] / source3 / smbd / conn.c
index 9e322ab1cce4c624d71a5808660e8ae3ae29b30d..7f34d2b8e2b3e9d1971c2bd9cb9a9e5057b1c32c 100644 (file)
@@ -15,8 +15,7 @@
    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"
@@ -53,7 +52,7 @@ int conn_num_open(void)
 /****************************************************************************
 check if a snum is in use
 ****************************************************************************/
-BOOL conn_snum_used(int snum)
+bool conn_snum_used(int snum)
 {
        connection_struct *conn;
        for (conn=Connections;conn;conn=conn->next) {
@@ -64,10 +63,10 @@ BOOL conn_snum_used(int snum)
        return(False);
 }
 
-
 /****************************************************************************
-find a conn given a cnum
+ Find a conn given a cnum.
 ****************************************************************************/
+
 connection_struct *conn_find(unsigned cnum)
 {
        int count=0;
@@ -85,7 +84,6 @@ connection_struct *conn_find(unsigned cnum)
        return NULL;
 }
 
-
 /****************************************************************************
   find first available connection slot, starting from a random position.
 The randomisation stops problems with the server dieing and clients
@@ -93,7 +91,6 @@ thinking the server is still available.
 ****************************************************************************/
 connection_struct *conn_new(void)
 {
-       TALLOC_CTX *mem_ctx;
        connection_struct *conn;
        int i;
         int find_offset = 1;
@@ -141,25 +138,18 @@ find_again:
                return NULL;
        }
 
-       if ((mem_ctx=talloc_init("connection_struct"))==NULL) {
-               DEBUG(0,("talloc_init(connection_struct) failed!\n"));
-               return NULL;
-       }
-
-       if (!(conn=TALLOC_ZERO_P(mem_ctx, connection_struct)) ||
-           !(conn->params = TALLOC_P(mem_ctx, struct share_params))) {
+       if (!(conn=TALLOC_ZERO_P(NULL, connection_struct)) ||
+           !(conn->params = TALLOC_P(conn, struct share_params))) {
                DEBUG(0,("TALLOC_ZERO() failed!\n"));
-               TALLOC_FREE(mem_ctx);
+               TALLOC_FREE(conn);
                return NULL;
        }
-       conn->mem_ctx = mem_ctx;
        conn->cnum = i;
 
        bitmap_set(bmap, i);
 
        num_open++;
 
-       string_set(&conn->user,"");
        string_set(&conn->dirpath,"");
        string_set(&conn->connectpath,"");
        string_set(&conn->origpath,"");
@@ -171,23 +161,26 @@ find_again:
 
 /****************************************************************************
  Close all conn structures.
+return true if any were closed
 ****************************************************************************/
-
-void conn_close_all(void)
+bool conn_close_all(void)
 {
        connection_struct *conn, *next;
+       bool ret = false;
        for (conn=Connections;conn;conn=next) {
                next=conn->next;
                set_current_service(conn, 0, True);
                close_cnum(conn, conn->vuid);
+               ret = true;
        }
+       return ret;
 }
 
 /****************************************************************************
  Idle inactive connections.
 ****************************************************************************/
 
-BOOL conn_idle_all(time_t t)
+bool conn_idle_all(time_t t)
 {
        int deadtime = lp_deadtime()*60;
        pipes_struct *plist = NULL;
@@ -235,24 +228,15 @@ BOOL conn_idle_all(time_t t)
  Clear a vuid out of the validity cache, and as the 'owner' of a connection.
 ****************************************************************************/
 
-void conn_clear_vuid_cache(uint16 vuid)
+void conn_clear_vuid_caches(uint16_t vuid)
 {
        connection_struct *conn;
-       unsigned int i;
 
        for (conn=Connections;conn;conn=conn->next) {
                if (conn->vuid == vuid) {
                        conn->vuid = UID_FIELD_INVALID;
                }
-
-               for (i=0;i<conn->vuid_cache.entries && i< VUID_CACHE_SIZE;i++) {
-                       if (conn->vuid_cache.array[i].vuid == vuid) {
-                               struct vuid_cache_entry *ent = &conn->vuid_cache.array[i];
-                               ent->vuid = UID_FIELD_INVALID;
-                               ent->read_only = False;
-                               ent->admin_user = False;
-                       }
-               }
+               conn_clear_vuid_cache(conn, vuid);
        }
 }
 
@@ -263,14 +247,13 @@ void conn_clear_vuid_cache(uint16 vuid)
 void conn_free_internal(connection_struct *conn)
 {
        vfs_handle_struct *handle = NULL, *thandle = NULL;
-       TALLOC_CTX *mem_ctx = NULL;
        struct trans_state *state = NULL;
 
        /* Free vfs_connection_struct */
        handle = conn->vfs_handles;
        while(handle) {
-               DLIST_REMOVE(conn->vfs_handles, handle);
                thandle = handle->next;
+               DLIST_REMOVE(conn->vfs_handles, handle);
                if (handle->free_data)
                        handle->free_data(&handle->data);
                handle = thandle;
@@ -286,15 +269,14 @@ void conn_free_internal(connection_struct *conn)
        free_namearray(conn->veto_list);
        free_namearray(conn->hide_list);
        free_namearray(conn->veto_oplock_list);
+       free_namearray(conn->aio_write_behind_list);
        
-       string_free(&conn->user);
        string_free(&conn->dirpath);
        string_free(&conn->connectpath);
        string_free(&conn->origpath);
 
-       mem_ctx = conn->mem_ctx;
        ZERO_STRUCTP(conn);
-       talloc_destroy(mem_ctx);
+       talloc_destroy(conn);
 }
 
 /****************************************************************************