diff options
author | Stefan Metzmacher <metze@samba.org> | 2009-05-27 11:15:44 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2009-06-03 17:54:38 +0200 |
commit | c8620180083c2bff2e54bb90bcbf89a3d5008fbd (patch) | |
tree | e4abbffa3b9a184b0fdbef2252880ee9bec34388 | |
parent | 75d03970b78538346308c612ca6be15559e15b5b (diff) | |
download | samba-c8620180083c2bff2e54bb90bcbf89a3d5008fbd.tar.gz samba-c8620180083c2bff2e54bb90bcbf89a3d5008fbd.tar.bz2 samba-c8620180083c2bff2e54bb90bcbf89a3d5008fbd.zip |
s3:smbd: move tcon specific globals to struct smbd_server_connection
metze
-rw-r--r-- | source3/include/proto.h | 21 | ||||
-rw-r--r-- | source3/smbd/conn.c | 72 | ||||
-rw-r--r-- | source3/smbd/globals.c | 5 | ||||
-rw-r--r-- | source3/smbd/globals.h | 11 | ||||
-rw-r--r-- | source3/smbd/ipc.c | 3 | ||||
-rw-r--r-- | source3/smbd/password.c | 2 | ||||
-rw-r--r-- | source3/smbd/process.c | 10 | ||||
-rw-r--r-- | source3/smbd/reply.c | 8 | ||||
-rw-r--r-- | source3/smbd/server.c | 7 | ||||
-rw-r--r-- | source3/smbd/service.c | 37 | ||||
-rw-r--r-- | source3/torture/vfstest.c | 6 |
11 files changed, 96 insertions, 86 deletions
diff --git a/source3/include/proto.h b/source3/include/proto.h index 22659339a9..7875c38a8a 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -6156,16 +6156,18 @@ NTSTATUS delete_all_streams(connection_struct *conn, const char *fname); /* The following definitions come from smbd/conn.c */ -void conn_init(void); -int conn_num_open(void); +void conn_init(struct smbd_server_connection *sconn); +int conn_num_open(struct smbd_server_connection *sconn); bool conn_snum_used(int snum); -connection_struct *conn_find(unsigned cnum); -connection_struct *conn_new(void); -bool conn_close_all(void); -bool conn_idle_all(time_t t); -void conn_clear_vuid_caches(uint16 vuid); +connection_struct *conn_find(struct smbd_server_connection *sconn, + unsigned cnum); +connection_struct *conn_new(struct smbd_server_connection *sconn); +bool conn_close_all(struct smbd_server_connection *sconn); +bool conn_idle_all(struct smbd_server_connection *sconn, time_t t); +void conn_clear_vuid_caches(struct smbd_server_connection *sconn, uint16 vuid); void conn_free_internal(connection_struct *conn); -void conn_free(connection_struct *conn); +void conn_free(struct smbd_server_connection *sconn, + connection_struct *conn); void msg_force_tdis(struct messaging_context *msg, void *private_data, uint32_t msg_type, @@ -6961,7 +6963,8 @@ connection_struct *make_connection(struct smbd_server_connection *sconn, const char *service_in, DATA_BLOB password, const char *pdev, uint16 vuid, NTSTATUS *status); -void close_cnum(connection_struct *conn, uint16 vuid); +void close_cnum(struct smbd_server_connection *sconn, + connection_struct *conn, uint16 vuid); /* The following definitions come from smbd/session.c */ diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c index 3800643769..607329de77 100644 --- a/source3/smbd/conn.c +++ b/source3/smbd/conn.c @@ -30,17 +30,19 @@ /**************************************************************************** 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; } @@ -49,8 +51,9 @@ check if a snum is in use ****************************************************************************/ 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); } @@ -62,15 +65,16 @@ bool conn_snum_used(int snum) 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; } @@ -84,19 +88,20 @@ connection_struct *conn_find(unsigned cnum) 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) { connection_struct *conn; int i; int find_offset = 1; 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) { @@ -114,10 +119,10 @@ find_again: 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; @@ -142,15 +147,15 @@ find_again: 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->dirpath,""); string_set(&conn->connectpath,""); string_set(&conn->origpath,""); - DLIST_ADD(Connections, conn); + DLIST_ADD(sconn->smb1.tcons.Connections, conn); return conn; } @@ -159,14 +164,14 @@ find_again: Close all conn structures. return true if any were closed ****************************************************************************/ -bool conn_close_all(void) +bool conn_close_all(struct smbd_server_connection *sconn) { connection_struct *conn, *next; bool ret = false; - for (conn=Connections;conn;conn=next) { + for (conn=sconn->smb1.tcons.Connections;conn;conn=next) { next=conn->next; set_current_service(conn, 0, True); - close_cnum(conn, conn->vuid); + close_cnum(sconn, conn, conn->vuid); ret = true; } return ret; @@ -176,7 +181,7 @@ bool conn_close_all(void) 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; @@ -185,7 +190,7 @@ bool conn_idle_all(time_t t) 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; @@ -224,11 +229,11 @@ 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_caches(uint16_t vuid) +void conn_clear_vuid_caches(struct smbd_server_connection *sconn,uint16_t vuid) { connection_struct *conn; - 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; } @@ -279,14 +284,14 @@ void conn_free_internal(connection_struct *conn) Free a conn structure. ****************************************************************************/ -void conn_free(connection_struct *conn) +void conn_free(struct smbd_server_connection *sconn, connection_struct *conn) { - DLIST_REMOVE(Connections, conn); + DLIST_REMOVE(sconn->smb1.tcons.Connections, conn); - bitmap_clear(bmap, conn->cnum); + bitmap_clear(sconn->smb1.tcons.bmap, conn->cnum); - SMB_ASSERT(num_open > 0); - num_open--; + SMB_ASSERT(sconn->smb1.tcons.num_open > 0); + sconn->smb1.tcons.num_open--; conn_free_internal(conn); } @@ -303,6 +308,7 @@ void msg_force_tdis(struct messaging_context *msg, struct server_id server_id, DATA_BLOB *data) { + struct smbd_server_connection *sconn = smbd_server_conn; connection_struct *conn, *next; fstring sharename; @@ -310,16 +316,16 @@ void msg_force_tdis(struct messaging_context *msg, 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", sharename, conn->cnum)); - close_cnum(conn, (uint16)-1); + close_cnum(sconn, conn, (uint16)-1); } } } diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c index 4796823e30..2e1b5c8593 100644 --- a/source3/smbd/globals.c +++ b/source3/smbd/globals.c @@ -43,11 +43,6 @@ bool blocking_lock_cancel_state = false; struct smbd_dmapi_context *dmapi_ctx = NULL; #endif -connection_struct *Connections = NULL; -/* number of open connections */ -struct bitmap *bmap = 0; -int num_open = 0; - bool dfree_broken = false; diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index 8ddf17c595..5bd75e767c 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -42,11 +42,6 @@ struct smbd_dmapi_context; extern struct smbd_dmapi_context *dmapi_ctx; #endif -extern connection_struct *Connections; -/* number of open connections */ -extern struct bitmap *bmap; -extern int num_open; - extern bool dfree_broken; extern struct bitmap *dptr_bmap; @@ -338,6 +333,12 @@ struct smbd_server_connection { char *my_yp_domain; #endif } sessions; + struct { + connection_struct *Connections; + /* number of open connections */ + struct bitmap *bmap; + int num_open; + } tcons; struct smb_signing_state *signing_state; /* List to store partial SPNEGO auth fragments. */ struct pending_auth_data *pd_list; diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c index a93fdd5ae0..1067dab074 100644 --- a/source3/smbd/ipc.c +++ b/source3/smbd/ipc.c @@ -534,6 +534,7 @@ static void named_pipe(connection_struct *conn, uint16 vuid, static void handle_trans(connection_struct *conn, struct smb_request *req, struct trans_state *state) { + struct smbd_server_connection *sconn = smbd_server_conn; char *local_machine_name; int name_offset = 0; @@ -584,7 +585,7 @@ static void handle_trans(connection_struct *conn, struct smb_request *req, state->max_param_return); if (state->close_on_completion) { - close_cnum(conn,state->vuid); + close_cnum(sconn, conn,state->vuid); req->conn = NULL; } diff --git a/source3/smbd/password.c b/source3/smbd/password.c index abe348e02b..928ef0169e 100644 --- a/source3/smbd/password.c +++ b/source3/smbd/password.c @@ -116,7 +116,7 @@ void invalidate_vuid(struct smbd_server_connection *sconn, uint16 vuid) /* clear the vuid from the 'cache' on each connection, and from the vuid 'owner' of connections */ - conn_clear_vuid_caches(vuid); + conn_clear_vuid_caches(sconn, vuid); TALLOC_FREE(vuser); sconn->smb1.sessions.num_validated_vuids--; diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 8061f1908f..0a3777afe0 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -357,6 +357,7 @@ void init_smb_request(struct smb_request *req, size_t unread_bytes, bool encrypted) { + struct smbd_server_connection *sconn = smbd_server_conn; size_t req_size = smb_len(inbuf) + 4; /* Ensure we have at least smb_size bytes. */ if (req_size < smb_size) { @@ -377,7 +378,7 @@ void init_smb_request(struct smb_request *req, req->buf = (const uint8_t *)smb_buf(inbuf); req->unread_bytes = unread_bytes; req->encrypted = encrypted; - req->conn = conn_find(req->tid); + req->conn = conn_find(sconn,req->tid); req->chain_fsp = NULL; req->chain_outbuf = NULL; smb_init_perfcount_data(&req->pcd); @@ -1968,8 +1969,9 @@ static bool keepalive_fn(const struct timeval *now, void *private_data) */ static bool deadtime_fn(const struct timeval *now, void *private_data) { - if ((conn_num_open() == 0) - || (conn_idle_all(now->tv_sec))) { + struct smbd_server_connection *sconn = smbd_server_conn; + if ((conn_num_open(sconn) == 0) + || (conn_idle_all(sconn, now->tv_sec))) { DEBUG( 2, ( "Closing idle connection\n" ) ); messaging_send(smbd_messaging_context(), procid_self(), MSG_SHUTDOWN, &data_blob_null); @@ -2177,6 +2179,8 @@ void smbd_process(void) smbd_server_conn->smb1.sessions.my_yp_domain = NULL; #endif + conn_init(smbd_server_conn); + smbd_server_conn->smb1.fde = event_add_fd(smbd_event_context(), smbd_server_conn, smbd_server_fd(), diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 095585a276..0c0d647f71 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -703,7 +703,7 @@ void reply_tcon_and_X(struct smb_request *req) /* we might have to close an old one */ if ((tcon_flags & 0x1) && conn) { - close_cnum(conn,req->vuid); + close_cnum(sconn, conn,req->vuid); req->conn = NULL; conn = NULL; } @@ -4140,6 +4140,7 @@ bool is_valid_writeX_buffer(const uint8_t *inbuf) connection_struct *conn = NULL; unsigned int doff = 0; size_t len = smb_len_large(inbuf); + struct smbd_server_connection *sconn = smbd_server_conn; if (is_encrypted_packet(inbuf)) { /* Can't do this on encrypted @@ -4158,7 +4159,7 @@ bool is_valid_writeX_buffer(const uint8_t *inbuf) return false; } - conn = conn_find(SVAL(inbuf, smb_tid)); + conn = conn_find(sconn, SVAL(inbuf, smb_tid)); if (conn == NULL) { DEBUG(10,("is_valid_writeX_buffer: bad tid\n")); return false; @@ -4829,6 +4830,7 @@ void reply_unlock(struct smb_request *req) void reply_tdis(struct smb_request *req) { + struct smbd_server_connection *sconn = smbd_server_conn; connection_struct *conn = req->conn; START_PROFILE(SMBtdis); @@ -4841,7 +4843,7 @@ void reply_tdis(struct smb_request *req) conn->used = False; - close_cnum(conn,req->vuid); + close_cnum(sconn, conn,req->vuid); req->conn = NULL; reply_outbuf(req, 0, 0); diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 32b200b392..77e487ac68 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -784,7 +784,7 @@ static void exit_server_common(enum server_exit_reason how, static void exit_server_common(enum server_exit_reason how, const char *const reason) { - bool had_open_conn; + bool had_open_conn = false; struct smbd_server_connection *sconn = smbd_server_conn; if (!exit_firsttime) @@ -798,9 +798,8 @@ static void exit_server_common(enum server_exit_reason how, a->free(&sconn->smb1.negprot.auth_context); } - had_open_conn = conn_close_all(); - if (sconn) { + had_open_conn = conn_close_all(sconn); invalidate_all_vuids(sconn); } @@ -888,8 +887,6 @@ static bool init_structs(void ) if (!init_names()) return False; - conn_init(); - file_init(); init_dptrs(); diff --git a/source3/smbd/service.c b/source3/smbd/service.c index 898e4290e6..5ade8270d5 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -658,7 +658,7 @@ static connection_struct *make_connection_snum( return NULL; } - conn = conn_new(); + conn = conn_new(sconn); if (!conn) { DEBUG(0,("Couldn't find free connection.\n")); *pstatus = NT_STATUS_INSUFFICIENT_RESOURCES; @@ -675,7 +675,7 @@ static connection_struct *make_connection_snum( DEBUG(1, ("create_connection_server_info failed: %s\n", nt_errstr(status))); *pstatus = status; - conn_free(conn); + conn_free(sconn, conn); return NULL; } @@ -732,7 +732,7 @@ static connection_struct *make_connection_snum( fuser = talloc_string_sub(conn, lp_force_user(snum), "%S", lp_servicename(snum)); if (fuser == NULL) { - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_NO_MEMORY; return NULL; } @@ -741,7 +741,7 @@ static connection_struct *make_connection_snum( conn, fuser, conn->server_info->guest, &forced_serverinfo); if (!NT_STATUS_IS_OK(status)) { - conn_free(conn); + conn_free(sconn, conn); *pstatus = status; return NULL; } @@ -766,7 +766,7 @@ static connection_struct *make_connection_snum( &conn->server_info->utok.gid); if (!NT_STATUS_IS_OK(status)) { - conn_free(conn); + conn_free(sconn, conn); *pstatus = status; return NULL; } @@ -792,14 +792,14 @@ static connection_struct *make_connection_snum( pdb_get_domain(conn->server_info->sam_account), lp_pathname(snum)); if (!s) { - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_NO_MEMORY; return NULL; } if (!set_conn_connectpath(conn,s)) { TALLOC_FREE(s); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_NO_MEMORY; return NULL; } @@ -831,7 +831,7 @@ static connection_struct *make_connection_snum( "denied due to security " "descriptor.\n", lp_servicename(snum))); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_ACCESS_DENIED; return NULL; } else { @@ -844,7 +844,7 @@ static connection_struct *make_connection_snum( if (!smbd_vfs_init(conn)) { DEBUG(0, ("vfs_init failed for service %s\n", lp_servicename(snum))); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_BAD_NETWORK_NAME; return NULL; } @@ -862,7 +862,7 @@ static connection_struct *make_connection_snum( "for service %s, path %s\n", lp_servicename(snum), conn->connectpath)); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_BAD_NETWORK_NAME; return NULL; } @@ -886,7 +886,7 @@ static connection_struct *make_connection_snum( DEBUG(1, ("Max connections (%d) exceeded for %s\n", lp_max_connections(snum), lp_servicename(snum))); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_INSUFFICIENT_RESOURCES; return NULL; } @@ -896,7 +896,7 @@ static connection_struct *make_connection_snum( */ if (!claim_connection(conn, lp_servicename(snum), 0)) { DEBUG(1, ("Could not store connections entry\n")); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_INTERNAL_DB_ERROR; return NULL; } @@ -920,7 +920,7 @@ static connection_struct *make_connection_snum( DEBUG(1,("root preexec gave %d - failing " "connection\n", ret)); yield_connection(conn, lp_servicename(snum)); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_ACCESS_DENIED; return NULL; } @@ -931,7 +931,7 @@ static connection_struct *make_connection_snum( /* No point continuing if they fail the basic checks */ DEBUG(0,("Can't become connected user!\n")); yield_connection(conn, lp_servicename(snum)); - conn_free(conn); + conn_free(sconn, conn); *pstatus = NT_STATUS_LOGON_FAILURE; return NULL; } @@ -1067,7 +1067,7 @@ static connection_struct *make_connection_snum( SMB_VFS_DISCONNECT(conn); } yield_connection(conn, lp_servicename(snum)); - conn_free(conn); + conn_free(sconn, conn); return NULL; } @@ -1099,7 +1099,7 @@ connection_struct *make_connection(struct smbd_server_connection *sconn, smb_panic("make_connection: PANIC ERROR. Called as nonroot\n"); } - if (conn_num_open() > 2047) { + if (conn_num_open(sconn) > 2047) { *status = NT_STATUS_INSUFF_SERVER_RESOURCES; return NULL; } @@ -1214,7 +1214,8 @@ connection_struct *make_connection(struct smbd_server_connection *sconn, Close a cnum. ****************************************************************************/ -void close_cnum(connection_struct *conn, uint16 vuid) +void close_cnum(struct smbd_server_connection *sconn, + connection_struct *conn, uint16 vuid) { file_close_conn(conn); @@ -1268,5 +1269,5 @@ void close_cnum(connection_struct *conn, uint16 vuid) TALLOC_FREE(cmd); } - conn_free(conn); + conn_free(sconn, conn); } diff --git a/source3/torture/vfstest.c b/source3/torture/vfstest.c index bb4dc35d2b..de68a0b3c5 100644 --- a/source3/torture/vfstest.c +++ b/source3/torture/vfstest.c @@ -561,8 +561,8 @@ int main(int argc, char *argv[]) /* some basic initialization stuff */ sec_init(); - conn_init(); - vfs.conn = conn_new(); + vfs.conn = TALLOC_ZERO_P(NULL, connection_struct); + vfs.conn->params = TALLOC_P(vfs.conn, struct share_params); for (i=0; i < 1024; i++) vfs.files[i] = NULL; @@ -605,7 +605,7 @@ int main(int argc, char *argv[]) SAFE_FREE(line); } - conn_free(vfs.conn); + TALLOC_FREE(vfs.conn); TALLOC_FREE(frame); return 0; } |