The branch, master has been updated via b5e9ece s3:smbd: remove global 'smbd_server_conn' !!! via 288a75d s3:smbd: only call file_init_global() in the parent smbd via 9e45885 s3:smbd/files: split file_init_global() out of file_init() via 48e62f2 s3:smbd: remove unused var in smbXsrv_connection_init_tables() via 0beede3 s4:smb_server/smb: fix talloc_free() bug from b452fb3 waf: for MIT krb5 build require kerberos version above 1.9
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit b5e9ece1f3936d2221480169713042019e34a276 Author: Stefan Metzmacher <me...@samba.org> Date: Thu May 24 13:46:11 2012 +0200 s3:smbd: remove global 'smbd_server_conn' !!! For now we still use a global 'global_smbXsrv_connection' in order to pass the connection state to exit_server*(). metze Autobuild-User: Stefan Metzmacher <me...@samba.org> Autobuild-Date: Thu May 24 20:07:20 CEST 2012 on sn-devel-104 commit 288a75d8dc4b17c92da22e0e04f622c593bd5df7 Author: Stefan Metzmacher <me...@samba.org> Date: Thu May 24 12:26:46 2012 +0200 s3:smbd: only call file_init_global() in the parent smbd metze commit 9e45885fcc54fa16e947b5b6370f171c2c7bfaf2 Author: Stefan Metzmacher <me...@samba.org> Date: Thu May 24 12:20:30 2012 +0200 s3:smbd/files: split file_init_global() out of file_init() metze commit 48e62f2d46a39b09ac0bcad84493b12381bb5a05 Author: Stefan Metzmacher <me...@samba.org> Date: Thu May 24 12:41:20 2012 +0200 s3:smbd: remove unused var in smbXsrv_connection_init_tables() metze commit 0beede33a7034d63912bed301e3e7340f8d2ea86 Author: Stefan Metzmacher <me...@samba.org> Date: Thu May 24 11:57:02 2012 +0200 s4:smb_server/smb: fix talloc_free() bug ERROR: talloc_free with references at ../source4/smb_server/smb/receive.c:637 reference at ../source4/ntvfs/posix/pvfs_wait.c:86 metze ----------------------------------------------------------------------- Summary of changes: source3/smbd/files.c | 47 +++++++++++++++++++++++--------- source3/smbd/globals.c | 11 +------- source3/smbd/globals.h | 2 +- source3/smbd/process.c | 55 ++++++++++++++++++++++++++++++++----- source3/smbd/proto.h | 5 +++- source3/smbd/server.c | 33 ++++++---------------- source3/smbd/server_exit.c | 10 +++++- source4/smb_server/smb/receive.c | 2 +- 8 files changed, 105 insertions(+), 60 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/smbd/files.c b/source3/smbd/files.c index ae34006..fcdd740 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -189,38 +189,59 @@ void file_close_pid(struct smbd_server_connection *sconn, uint16 smbpid, Initialise file structures. ****************************************************************************/ -bool file_init(struct smbd_server_connection *sconn) +static int files_max_open_fds; + +bool file_init_global(void) { - int request_max_open_files = lp_max_open_files(); + int request_max = lp_max_open_files(); int real_lim; + int real_max; + + if (files_max_open_fds != 0) { + return true; + } /* * Set the max_open files to be the requested * max plus a fudgefactor to allow for the extra * fd's we need such as log files etc... */ - real_lim = set_maxfiles(request_max_open_files + MAX_OPEN_FUDGEFACTOR); + real_lim = set_maxfiles(request_max + MAX_OPEN_FUDGEFACTOR); - sconn->real_max_open_files = real_lim - MAX_OPEN_FUDGEFACTOR; + real_max = real_lim - MAX_OPEN_FUDGEFACTOR; - if (sconn->real_max_open_files + FILE_HANDLE_OFFSET + MAX_OPEN_PIPES - > 65536) - sconn->real_max_open_files = - 65536 - FILE_HANDLE_OFFSET - MAX_OPEN_PIPES; + if (real_max + FILE_HANDLE_OFFSET + MAX_OPEN_PIPES > 65536) { + real_max = 65536 - FILE_HANDLE_OFFSET - MAX_OPEN_PIPES; + } - if(sconn->real_max_open_files != request_max_open_files) { - DEBUG(1, ("file_init: Information only: requested %d " + if (real_max != request_max) { + DEBUG(1, ("file_init_global: Information only: requested %d " "open files, %d are available.\n", - request_max_open_files, sconn->real_max_open_files)); + request_max, real_max)); } - SMB_ASSERT(sconn->real_max_open_files > 100); + SMB_ASSERT(real_max > 100); - sconn->file_bmap = bitmap_talloc(sconn, sconn->real_max_open_files); + files_max_open_fds = real_max; + return true; +} +bool file_init(struct smbd_server_connection *sconn) +{ + bool ok; + + ok = file_init_global(); + if (!ok) { + return false; + } + + sconn->real_max_open_files = files_max_open_fds; + + sconn->file_bmap = bitmap_talloc(sconn, sconn->real_max_open_files); if (!sconn->file_bmap) { return false; } + return true; } diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c index ff8c51b..196b643 100644 --- a/source3/smbd/globals.c +++ b/source3/smbd/globals.c @@ -102,7 +102,7 @@ struct smbd_parent_context *am_parent = NULL; struct memcache *smbd_memcache_ctx = NULL; bool exit_firsttime = true; -struct smbd_server_connection *smbd_server_conn = NULL; +struct smbXsrv_connection *global_smbXsrv_connection = NULL; struct memcache *smbd_memcache(void) { @@ -142,13 +142,4 @@ void smbd_init_globals(void) ZERO_STRUCT(conn_ctx_stack); ZERO_STRUCT(sec_ctx_stack); - - smbd_server_conn = talloc_zero(server_event_context(), struct smbd_server_connection); - if (!smbd_server_conn) { - exit_server("failed to create smbd_server_connection"); - } - - smbd_server_conn->ev_ctx = server_event_context(); - smbd_server_conn->smb1.echo_handler.trusted_fd = -1; - smbd_server_conn->smb1.echo_handler.socket_lock_fd = -1; } diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h index 0a57013..24c21ff 100644 --- a/source3/smbd/globals.h +++ b/source3/smbd/globals.h @@ -638,6 +638,6 @@ struct smbd_server_connection { struct smbXsrv_connection *conn; }; -extern struct smbd_server_connection *smbd_server_conn; +extern struct smbXsrv_connection *global_smbXsrv_connection; void smbd_init_globals(void); diff --git a/source3/smbd/process.c b/source3/smbd/process.c index 0873262..f955959 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -39,6 +39,7 @@ #include "../libcli/security/dom_sid.h" #include "../libcli/security/security_token.h" #include "lib/id_cache.h" +#include "serverid.h" extern bool global_machine_password_needs_changing; @@ -3152,8 +3153,6 @@ static void smbd_id_cache_kill(struct messaging_context *msg_ctx, NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn, enum protocol_types protocol) { - NTSTATUS status; - set_Protocol(protocol); conn->protocol = protocol; @@ -3165,9 +3164,13 @@ NTSTATUS smbXsrv_connection_init_tables(struct smbXsrv_connection *conn, ****************************************************************************/ void smbd_process(struct tevent_context *ev_ctx, - struct smbd_server_connection *sconn) + struct messaging_context *msg_ctx, + int sock_fd, + bool interactive) { TALLOC_CTX *frame = talloc_stackframe(); + struct smbXsrv_connection *conn; + struct smbd_server_connection *sconn; struct sockaddr_storage ss; struct sockaddr *sa = NULL; socklen_t sa_socklen; @@ -3178,12 +3181,47 @@ void smbd_process(struct tevent_context *ev_ctx, char *rhost; int ret; - sconn->conn = talloc_zero(sconn, struct smbXsrv_connection); - if (sconn->conn == NULL) { + conn = talloc_zero(ev_ctx, struct smbXsrv_connection); + if (conn == NULL) { DEBUG(0,("talloc_zero(struct smbXsrv_connection)\n")); exit_server_cleanly("talloc_zero(struct smbXsrv_connection).\n"); } + conn->ev_ctx = ev_ctx; + conn->msg_ctx = msg_ctx; + + sconn = talloc_zero(conn, struct smbd_server_connection); + if (!sconn) { + exit_server("failed to create smbd_server_connection"); + } + + conn->sconn = sconn; + sconn->conn = conn; + + /* + * TODO: remove this...:-) + */ + global_smbXsrv_connection = conn; + + sconn->ev_ctx = ev_ctx; + sconn->msg_ctx = msg_ctx; + sconn->sock = sock_fd; + sconn->smb1.echo_handler.trusted_fd = -1; + sconn->smb1.echo_handler.socket_lock_fd = -1; + + if (!interactive) { + smbd_setup_sig_term_handler(sconn); + smbd_setup_sig_hup_handler(sconn); + + if (!serverid_register(messaging_server_id(msg_ctx), + FLAG_MSG_GENERAL|FLAG_MSG_SMBD + |FLAG_MSG_DBWRAP + |FLAG_MSG_PRINT_GENERAL)) { + exit_server_cleanly("Could not register myself in " + "serverid.tdb"); + } + } + if (lp_srv_maxprotocol() >= PROTOCOL_SMB2_02) { /* * We're not making the decision here, @@ -3339,6 +3377,10 @@ void smbd_process(struct tevent_context *ev_ctx, exit_server("Failed to init smb_signing"); } + if (!file_init(sconn)) { + exit_server("file_init() failed"); + } + /* Setup oplocks */ if (!init_oplocks(sconn)) exit_server("Failed to init oplocks"); @@ -3447,9 +3489,6 @@ void smbd_process(struct tevent_context *ev_ctx, exit_server("failed to create smbd_server_connection fde"); } - sconn->conn->sconn = sconn; - sconn->conn->ev_ctx = sconn->ev_ctx; - sconn->conn->msg_ctx = sconn->msg_ctx; sconn->conn->local_address = sconn->local_address; sconn->conn->remote_address = sconn->remote_address; sconn->conn->remote_hostname = sconn->remote_hostname; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 60f9a7d..311072a 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -369,6 +369,7 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn, void file_close_conn(connection_struct *conn); void file_close_pid(struct smbd_server_connection *sconn, uint16 smbpid, int vuid); +bool file_init_global(void); bool file_init(struct smbd_server_connection *sconn); void file_close_user(struct smbd_server_connection *sconn, int vuid); struct files_struct *files_forall( @@ -801,7 +802,9 @@ bool smb1_parse_chain(TALLOC_CTX *mem_ctx, const uint8_t *buf, struct smb_request ***reqs, unsigned *num_reqs); bool req_is_in_chain(struct smb_request *req); void smbd_process(struct tevent_context *ev_ctx, - struct smbd_server_connection *sconn); + struct messaging_context *msg_ctx, + int sock_fd, + bool interactive); bool fork_echo_handler(struct smbd_server_connection *sconn); /* The following definitions come from smbd/quotas.c */ diff --git a/source3/smbd/server.c b/source3/smbd/server.c index d6c7874..ab4e971 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -534,7 +534,6 @@ static void smbd_accept_connection(struct tevent_context *ev, struct smbd_open_socket *s = talloc_get_type_abort(private_data, struct smbd_open_socket); struct messaging_context *msg_ctx = s->parent->msg_ctx; - struct smbd_server_connection *sconn = smbd_server_conn; struct sockaddr_storage addr; socklen_t in_addrlen = sizeof(addr); int fd; @@ -542,7 +541,6 @@ static void smbd_accept_connection(struct tevent_context *ev, uint64_t unique_id; fd = accept(s->fd, (struct sockaddr *)(void *)&addr,&in_addrlen); - sconn->sock = fd; if (fd == -1 && errno == EINTR) return; @@ -553,15 +551,14 @@ static void smbd_accept_connection(struct tevent_context *ev, } if (s->parent->interactive) { - reinit_after_fork(msg_ctx, sconn->ev_ctx, true); - smbd_process(ev, sconn); + reinit_after_fork(msg_ctx, ev, true); + smbd_process(ev, msg_ctx, fd, true); exit_server_cleanly("end of interactive mode"); return; } if (!allowable_number_of_smbd_processes(s->parent)) { close(fd); - sconn->sock = -1; return; } @@ -614,18 +611,7 @@ static void smbd_accept_connection(struct tevent_context *ev, smb_panic("reinit_after_fork() failed"); } - smbd_setup_sig_term_handler(sconn); - smbd_setup_sig_hup_handler(sconn); - - if (!serverid_register(messaging_server_id(msg_ctx), - FLAG_MSG_GENERAL|FLAG_MSG_SMBD - |FLAG_MSG_DBWRAP - |FLAG_MSG_PRINT_GENERAL)) { - exit_server_cleanly("Could not register myself in " - "serverid.tdb"); - } - - smbd_process(ev, sconn); + smbd_process(ev, msg_ctx, fd, false); exit: exit_server_cleanly("end of child"); return; @@ -646,7 +632,6 @@ static void smbd_accept_connection(struct tevent_context *ev, getpeername failure if we reopen the logs and use %I in the filename. */ - sconn->sock = -1; if (pid != 0) { add_child_pid(s->parent, pid); @@ -1329,8 +1314,6 @@ extern void build_options(bool screen); } } - smbd_server_conn->msg_ctx = msg_ctx; - parent = talloc_zero(ev_ctx, struct smbd_parent_context); if (!parent) { exit_server("talloc(struct smbd_parent_context) failed"); @@ -1436,8 +1419,8 @@ extern void build_options(bool screen); return -1; } - if (!file_init(smbd_server_conn)) { - DEBUG(0, ("ERROR: file_init failed\n")); + if (!file_init_global()) { + DEBUG(0, ("ERROR: file_init_global() failed\n")); return -1; } @@ -1497,13 +1480,15 @@ extern void build_options(bool screen); } if (!is_daemon) { + int sock; + /* inetd mode */ TALLOC_FREE(frame); /* Started from inetd. fd 0 is the socket. */ /* We will abort gracefully when the client or remote system goes away */ - smbd_server_conn->sock = dup(0); + sock = dup(0); /* close stdin, stdout (if not logging to it), but not stderr */ close_low_fds(true, !debug_get_output_is_stdout(), false); @@ -1515,7 +1500,7 @@ extern void build_options(bool screen); /* Stop zombies */ smbd_setup_sig_chld_handler(parent); - smbd_process(ev_ctx, smbd_server_conn); + smbd_process(ev_ctx, msg_ctx, sock, true); exit_server_cleanly(NULL); return(0); diff --git a/source3/smbd/server_exit.c b/source3/smbd/server_exit.c index 4e10a09..20f7b4d 100644 --- a/source3/smbd/server_exit.c +++ b/source3/smbd/server_exit.c @@ -85,7 +85,12 @@ static void exit_server_common(enum server_exit_reason how, const char *const reason) { bool had_open_conn = false; - struct smbd_server_connection *sconn = smbd_server_conn; + struct smbXsrv_connection *conn = global_smbXsrv_connection; + struct smbd_server_connection *sconn = NULL; + + if (conn != NULL) { + sconn = conn->sconn; + } if (!exit_firsttime) exit(0); @@ -158,7 +163,8 @@ static void exit_server_common(enum server_exit_reason how, * because smbd_msg_ctx is not a talloc child of smbd_server_conn. */ sconn = NULL; - TALLOC_FREE(smbd_server_conn); + conn = NULL; + TALLOC_FREE(global_smbXsrv_connection); server_messaging_context_free(); server_event_context_free(); TALLOC_FREE(smbd_memcache_ctx); diff --git a/source4/smb_server/smb/receive.c b/source4/smb_server/smb/receive.c index b100757..3443834 100644 --- a/source4/smb_server/smb/receive.c +++ b/source4/smb_server/smb/receive.c @@ -634,7 +634,7 @@ void smbsrv_chain_reply(struct smbsrv_request *req) /* cleanup somestuff for the next request */ DLIST_REMOVE(req->smb_conn->requests, req); - talloc_free(req->ntvfs); + talloc_unlink(req, req->ntvfs); req->ntvfs = NULL; talloc_free(req->io_ptr); req->io_ptr = NULL; -- Samba Shared Repository