[GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch.
[samba.git] / source / smbd / conn.c
index 0b0da589e4d0a0df510c40f22605a188b87fc138..50a71edf9d304f8337e6c5555c5a4378dd292870 100644 (file)
@@ -6,7 +6,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,
@@ -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"
@@ -148,7 +147,7 @@ find_again:
 
        if (!(conn=TALLOC_ZERO_P(mem_ctx, connection_struct)) ||
            !(conn->params = TALLOC_P(mem_ctx, struct share_params))) {
-               DEBUG(0,("talloc_zero() failed!\n"));
+               DEBUG(0,("TALLOC_ZERO() failed!\n"));
                TALLOC_FREE(mem_ctx);
                return NULL;
        }
@@ -187,14 +186,18 @@ void conn_close_all(void)
  Idle inactive connections.
 ****************************************************************************/
 
-BOOL conn_idle_all(time_t t, int deadtime)
+BOOL conn_idle_all(time_t t)
 {
+       int deadtime = lp_deadtime()*60;
        pipes_struct *plist = NULL;
-       BOOL allidle = True;
-       connection_struct *conn, *next;
+       connection_struct *conn;
 
-       for (conn=Connections;conn;conn=next) {
-               next=conn->next;
+       if (deadtime <= 0)
+               deadtime = DEFAULT_SMBD_TIMEOUT;
+
+       for (conn=Connections;conn;conn=conn->next) {
+
+               time_t age = t - conn->lastused;
 
                /* Update if connection wasn't idle. */
                if (conn->lastused != conn->lastused_count) {
@@ -203,12 +206,12 @@ BOOL conn_idle_all(time_t t, int deadtime)
                }
 
                /* close dirptrs on connections that are idle */
-               if ((t-conn->lastused) > DPTR_IDLE_TIMEOUT) {
+               if (age > DPTR_IDLE_TIMEOUT) {
                        dptr_idlecnum(conn);
                }
 
-               if (conn->num_files_open > 0 || (t-conn->lastused)<deadtime) {
-                       allidle = False;
+               if (conn->num_files_open > 0 || age < deadtime) {
+                       return False;
                }
        }
 
@@ -217,11 +220,14 @@ BOOL conn_idle_all(time_t t, int deadtime)
         * idle with a handle open.
         */
 
-       for (plist = get_first_internal_pipe(); plist; plist = get_next_internal_pipe(plist))
-               if (plist->pipe_handles && plist->pipe_handles->count)
-                       allidle = False;
+       for (plist = get_first_internal_pipe(); plist;
+            plist = get_next_internal_pipe(plist)) {
+               if (plist->pipe_handles && plist->pipe_handles->count) {
+                       return False;
+               }
+       }
        
-       return allidle;
+       return True;
 }
 
 /****************************************************************************
@@ -257,6 +263,7 @@ 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;
@@ -268,13 +275,11 @@ void conn_free_internal(connection_struct *conn)
                handle = thandle;
        }
 
-       if (conn->ngroups && conn->groups) {
-               SAFE_FREE(conn->groups);
-               conn->ngroups = 0;
-       }
-
-       if (conn->nt_user_token) {
-               TALLOC_FREE(conn->nt_user_token);
+       /* Free any pending transactions stored on this conn. */
+       for (state = conn->pending_trans; state; state = state->next) {
+               /* state->setup is a talloc child of state. */
+               SAFE_FREE(state->param);
+               SAFE_FREE(state->data);
        }
 
        free_namearray(conn->veto_list);
@@ -301,6 +306,8 @@ void conn_free(connection_struct *conn)
        DLIST_REMOVE(Connections, conn);
 
        bitmap_clear(bmap, conn->cnum);
+
+       SMB_ASSERT(num_open > 0);
        num_open--;
 
        conn_free_internal(conn);
@@ -312,12 +319,16 @@ the message contains just a share name and all instances of that
 share are unmounted
 the special sharename '*' forces unmount of all shares
 ****************************************************************************/
-void msg_force_tdis(int msg_type, struct process_id pid, void *buf, size_t len)
+void msg_force_tdis(struct messaging_context *msg,
+                   void *private_data,
+                   uint32_t msg_type,
+                   struct server_id server_id,
+                   DATA_BLOB *data)
 {
        connection_struct *conn, *next;
        fstring sharename;
 
-       fstrcpy(sharename, (const char *)buf);
+       fstrcpy(sharename, (const char *)data->data);
 
        if (strcmp(sharename, "*") == 0) {
                DEBUG(1,("Forcing close of all shares\n"));