2 Unix SMB/CIFS implementation.
3 Manage smbsrv_tcon structures
4 Copyright (C) Andrew Tridgell 1998
5 Copyright (C) Alexander Bokovoy 2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 /* set these to define the limits of the server. NOTE These are on a
25 per-client basis. Thus any one machine can't connect to more than
26 MAX_CONNECTIONS services, but any number of machines may connect at
28 #define MAX_CONNECTIONS 128
30 /****************************************************************************
31 init the tcon structures
32 ****************************************************************************/
33 void conn_init(struct smbsrv_connection *smb_conn)
35 smb_conn->tree.bmap = bitmap_allocate(MAX_CONNECTIONS);
38 /****************************************************************************
39 check if a snum is in use
40 ****************************************************************************/
41 BOOL conn_snum_used(struct smbsrv_connection *smb_conn, int snum)
43 struct smbsrv_tcon *tcon;
44 for (tcon=smb_conn->tree.tcons;tcon;tcon=tcon->next) {
45 if (tcon->service == snum) {
53 /****************************************************************************
54 find a tcon given a cnum
55 ****************************************************************************/
56 struct smbsrv_tcon *conn_find(struct smbsrv_connection *smb_conn, uint_t cnum)
59 struct smbsrv_tcon *tcon;
61 for (tcon=smb_conn->tree.tcons;tcon;tcon=tcon->next,count++) {
62 if (tcon->cnum == cnum) {
64 DLIST_PROMOTE(smb_conn->tree.tcons, tcon);
74 /****************************************************************************
75 find first available connection slot, starting from a random position.
76 The randomisation stops problems with the server dieing and clients
77 thinking the server is still available.
78 ****************************************************************************/
79 struct smbsrv_tcon *conn_new(struct smbsrv_connection *smb_conn)
81 struct smbsrv_tcon *tcon;
84 i = bitmap_find(smb_conn->tree.bmap, 1);
87 DEBUG(1,("ERROR! Out of connection structures\n"));
91 tcon = talloc_p(smb_conn, struct smbsrv_tcon);
92 if (!tcon) return NULL;
97 tcon->smb_conn = smb_conn;
99 bitmap_set(smb_conn->tree.bmap, i);
101 smb_conn->tree.num_open++;
103 DLIST_ADD(smb_conn->tree.tcons, tcon);
108 /****************************************************************************
109 close all tcon structures
110 ****************************************************************************/
111 void conn_close_all(struct smbsrv_connection *smb_conn)
113 struct smbsrv_tcon *tcon, *next;
114 for (tcon=smb_conn->tree.tcons;tcon;tcon=next) {
122 /****************************************************************************
123 clear a vuid out of the validity cache, and as the 'owner' of a connection.
124 ****************************************************************************/
125 void conn_clear_vuid_cache(struct smbsrv_connection *smb_conn, uint16_t vuid)
127 struct smbsrv_tcon *tcon;
130 for (tcon=smb_conn->tree.tcons;tcon;tcon=tcon->next) {
131 for (i=0;i<tcon->vuid_cache.entries && i< VUID_CACHE_SIZE;i++) {
132 if (tcon->vuid_cache.list[i] == vuid) {
133 tcon->vuid_cache.list[i] = UID_FIELD_INVALID;
140 /****************************************************************************
141 Free a tcon structure.
142 ****************************************************************************/
144 void conn_free(struct smbsrv_connection *smb_conn, struct smbsrv_tcon *tcon)
146 DLIST_REMOVE(smb_conn->tree.tcons, tcon);
148 bitmap_clear(smb_conn->tree.bmap, tcon->cnum);
149 smb_conn->tree.num_open--;
151 talloc_destroy(tcon);