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,
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"
+#include "smbd/globals.h"
/* The connections bitmap is expanded in increments of BITMAP_BLOCK_SZ. The
* maximum size of the bitmap is the largest positive integer, but you will hit
*/
#define BITMAP_BLOCK_SZ 128
-static connection_struct *Connections;
-
-/* number of open connections */
-static struct bitmap *bmap;
-static int num_open;
-
/****************************************************************************
init the conn structures
****************************************************************************/
-void conn_init(void)
+void conn_init(struct smbd_server_connection *sconn)
{
- bmap = bitmap_allocate(BITMAP_BLOCK_SZ);
+ sconn->smb1.tcons.Connections = NULL;
+ sconn->smb1.tcons.num_open = 0;
+ sconn->smb1.tcons.bmap = bitmap_allocate(BITMAP_BLOCK_SZ);
}
/****************************************************************************
return the number of open connections
****************************************************************************/
-int conn_num_open(void)
+int conn_num_open(struct smbd_server_connection *sconn)
{
- return num_open;
+ return sconn->smb1.tcons.num_open;
}
/****************************************************************************
check if a snum is in use
****************************************************************************/
-BOOL conn_snum_used(int snum)
+bool conn_snum_used(int snum)
{
+ struct smbd_server_connection *sconn = smbd_server_conn;
connection_struct *conn;
- for (conn=Connections;conn;conn=conn->next) {
+ for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next) {
if (conn->params->service == snum) {
return(True);
}
return(False);
}
-
/****************************************************************************
-find a conn given a cnum
+ Find a conn given a cnum.
****************************************************************************/
-connection_struct *conn_find(unsigned cnum)
+
+connection_struct *conn_find(struct smbd_server_connection *sconn,unsigned cnum)
{
int count=0;
connection_struct *conn;
- for (conn=Connections;conn;conn=conn->next,count++) {
+ for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next,count++) {
if (conn->cnum == cnum) {
if (count > 10) {
- DLIST_PROMOTE(Connections, conn);
+ DLIST_PROMOTE(sconn->smb1.tcons.Connections,
+ conn);
}
return conn;
}
return NULL;
}
-
/****************************************************************************
find first available connection slot, starting from a random position.
The randomisation stops problems with the server dieing and clients
thinking the server is still available.
****************************************************************************/
-connection_struct *conn_new(void)
+connection_struct *conn_new(struct smbd_server_connection *sconn)
{
- TALLOC_CTX *mem_ctx;
connection_struct *conn;
int i;
int find_offset = 1;
+ if (sconn->allow_smb2) {
+ if (!(conn=TALLOC_ZERO_P(NULL, connection_struct)) ||
+ !(conn->params = TALLOC_P(conn, struct share_params))) {
+ DEBUG(0,("TALLOC_ZERO() failed!\n"));
+ TALLOC_FREE(conn);
+ return NULL;
+ }
+ conn->sconn = sconn;
+ return conn;
+ }
+
find_again:
- i = bitmap_find(bmap, find_offset);
+ i = bitmap_find(sconn->smb1.tcons.bmap, find_offset);
if (i == -1) {
/* Expand the connections bitmap. */
- int oldsz = bmap->n;
- int newsz = bmap->n + BITMAP_BLOCK_SZ;
+ int oldsz = sconn->smb1.tcons.bmap->n;
+ int newsz = sconn->smb1.tcons.bmap->n +
+ BITMAP_BLOCK_SZ;
struct bitmap * nbmap;
if (newsz <= oldsz) {
return NULL;
}
- bitmap_copy(nbmap, bmap);
- bitmap_free(bmap);
+ bitmap_copy(nbmap, sconn->smb1.tcons.bmap);
+ bitmap_free(sconn->smb1.tcons.bmap);
- bmap = nbmap;
+ sconn->smb1.tcons.bmap = nbmap;
find_offset = oldsz; /* Start next search in the new portion. */
goto 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->sconn = sconn;
conn->cnum = i;
+ conn->force_group_gid = (gid_t)-1;
- bitmap_set(bmap, i);
+ bitmap_set(sconn->smb1.tcons.bmap, i);
- num_open++;
+ sconn->smb1.tcons.num_open++;
- string_set(&conn->user,"");
- string_set(&conn->dirpath,"");
string_set(&conn->connectpath,"");
string_set(&conn->origpath,"");
- DLIST_ADD(Connections, conn);
+ DLIST_ADD(sconn->smb1.tcons.Connections, conn);
return conn;
}
/****************************************************************************
Close all conn structures.
+return true if any were closed
****************************************************************************/
-
-void conn_close_all(void)
+bool conn_close_all(struct smbd_server_connection *sconn)
{
connection_struct *conn, *next;
- for (conn=Connections;conn;conn=next) {
+ bool ret = false;
+ for (conn=sconn->smb1.tcons.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(struct smbd_server_connection *sconn,time_t t)
{
int deadtime = lp_deadtime()*60;
pipes_struct *plist = NULL;
if (deadtime <= 0)
deadtime = DEFAULT_SMBD_TIMEOUT;
- for (conn=Connections;conn;conn=conn->next) {
+ for (conn=sconn->smb1.tcons.Connections;conn;conn=conn->next) {
time_t age = t - conn->lastused;
for (plist = get_first_internal_pipe(); plist;
plist = get_next_internal_pipe(plist)) {
- if (plist->pipe_handles && plist->pipe_handles->count) {
+ if (num_pipe_handles(plist->pipe_handles) != 0) {
return False;
}
}
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(struct smbd_server_connection *sconn,uint16_t vuid)
{
connection_struct *conn;
- unsigned int i;
- for (conn=Connections;conn;conn=conn->next) {
+ for (conn=sconn->smb1.tcons.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);
}
}
Free a conn structure - internal part.
****************************************************************************/
-void conn_free_internal(connection_struct *conn)
+static void conn_free_internal(connection_struct *conn)
{
- vfs_handle_struct *handle = NULL, *thandle = NULL;
- TALLOC_CTX *mem_ctx = NULL;
+ vfs_handle_struct *handle = NULL, *thandle = 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;
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);
}
/****************************************************************************
void conn_free(connection_struct *conn)
{
- DLIST_REMOVE(Connections, conn);
+ if (conn->sconn == NULL) {
+ conn_free_internal(conn);
+ return;
+ }
+
+ if (conn->sconn->allow_smb2) {
+ conn_free_internal(conn);
+ return;
+ }
+
+ DLIST_REMOVE(conn->sconn->smb1.tcons.Connections, conn);
- bitmap_clear(bmap, conn->cnum);
+ bitmap_clear(conn->sconn->smb1.tcons.bmap, conn->cnum);
- SMB_ASSERT(num_open > 0);
- num_open--;
+ SMB_ASSERT(conn->sconn->smb1.tcons.num_open > 0);
+ conn->sconn->smb1.tcons.num_open--;
conn_free_internal(conn);
}
struct server_id server_id,
DATA_BLOB *data)
{
+ struct smbd_server_connection *sconn = smbd_server_conn;
connection_struct *conn, *next;
fstring sharename;
if (strcmp(sharename, "*") == 0) {
DEBUG(1,("Forcing close of all shares\n"));
- conn_close_all();
+ conn_close_all(sconn);
return;
}
- for (conn=Connections;conn;conn=next) {
+ for (conn=sconn->smb1.tcons.Connections;conn;conn=next) {
next=conn->next;
if (strequal(lp_servicename(SNUM(conn)), sharename)) {
DEBUG(1,("Forcing close of share %s cnum=%d\n",