2 Unix SMB/CIFS implementation.
3 Manage connections_struct structures
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Alexander Bokovoy 2002
6 Copyright (C) Jeremy Allison 2010
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "rpc_server/rpc_pipes.h"
27 /****************************************************************************
28 Update last used timestamps.
29 ****************************************************************************/
31 static void conn_lastused_update(struct smbd_server_connection
*sconn
,time_t t
)
33 struct connection_struct
*conn
;
35 for (conn
=sconn
->connections
; conn
; conn
=conn
->next
) {
36 /* Update if connection wasn't idle. */
37 if (conn
->lastused
!= conn
->lastused_count
) {
39 conn
->lastused_count
= t
;
44 /****************************************************************************
45 Idle inactive connections.
46 ****************************************************************************/
48 bool conn_idle_all(struct smbd_server_connection
*sconn
, time_t t
)
50 int deadtime
= lp_deadtime()*60;
51 struct connection_struct
*conn
;
53 conn_lastused_update(sconn
, t
);
56 deadtime
= DEFAULT_SMBD_TIMEOUT
;
59 for (conn
=sconn
->connections
;conn
;conn
=conn
->next
) {
60 time_t age
= t
- conn
->lastused
;
62 /* close dirptrs on connections that are idle */
63 if (age
> DPTR_IDLE_TIMEOUT
) {
67 if (conn
->num_files_open
> 0 || age
< deadtime
) {
73 * Check all pipes for any open handles. We cannot
74 * idle with a handle open.
76 if (check_open_pipes()) {
83 /****************************************************************************
84 Forcibly unmount a share.
85 All instances of the parameter 'sharename' share are unmounted.
86 The special sharename '*' forces unmount of all shares.
87 ****************************************************************************/
89 void conn_force_tdis(struct smbd_server_connection
*sconn
, const char *sharename
)
91 connection_struct
*conn
, *next
;
92 bool close_all
= false;
94 if (strcmp(sharename
, "*") == 0) {
96 DEBUG(1, ("conn_force_tdis: Forcing close of all shares\n"));
100 for (conn
= sconn
->connections
; conn
; conn
= next
) {
101 struct smbXsrv_tcon
*tcon
;
102 bool do_close
= false;
104 uint64_t vuid
= UID_FIELD_INVALID
;
108 if (conn
->tcon
== NULL
) {
115 } else if (strequal(lp_servicename(talloc_tos(), SNUM(conn
)),
117 DEBUG(1, ("conn_force_tdis: Forcing close of "
118 "share '%s' (wire_id=0x%08x)\n",
119 tcon
->global
->share_name
,
120 tcon
->global
->tcon_wire_id
));
128 if (sconn
->using_smb2
) {
133 status
= smbXsrv_tcon_disconnect(tcon
, vuid
);
134 if (!NT_STATUS_IS_OK(status
)) {
135 DEBUG(0, ("conn_force_tdis: "
136 "smbXsrv_tcon_disconnect() of share '%s' "
137 "(wire_id=0x%08x) failed: %s\n",
138 tcon
->global
->share_name
,
139 tcon
->global
->tcon_wire_id
,