diff options
Diffstat (limited to 'source3')
39 files changed, 554 insertions, 306 deletions
diff --git a/source3/Makefile.in b/source3/Makefile.in index 1625e6595c..fdddf365ce 100644 --- a/source3/Makefile.in +++ b/source3/Makefile.in @@ -698,7 +698,7 @@ SMBD_OBJ_SRV = smbd/files.o smbd/chgpasswd.o smbd/connection.o \ $(AFS_SETTOKEN_OBJ) smbd/aio.o smbd/statvfs.o \ smbd/dmapi.o \ smbd/file_access.o \ - smbd/dnsregister.o \ + smbd/dnsregister.o smbd/globals.o \ $(MANGLE_OBJ) @VFS_STATIC@ SMBD_OBJ_BASE = $(PARAM_WITHOUT_REG_OBJ) $(SMBD_OBJ_SRV) $(LIBSMB_OBJ) \ diff --git a/source3/smbd/aio.c b/source3/smbd/aio.c index 8beed0744c..54ae45a789 100644 --- a/source3/smbd/aio.c +++ b/source3/smbd/aio.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "smbd/globals.h" #if defined(WITH_AIO) @@ -53,8 +54,6 @@ struct aio_extra { static int handle_aio_read_complete(struct aio_extra *aio_ex); static int handle_aio_write_complete(struct aio_extra *aio_ex); -static struct aio_extra *aio_list_head; - static int aio_extra_destructor(struct aio_extra *aio_ex) { DLIST_REMOVE(aio_list_head, aio_ex); @@ -109,20 +108,15 @@ static struct aio_extra *find_aio_ex(uint16 mid) We can have these many aio buffers in flight. *****************************************************************************/ -static int aio_pending_size; -static sig_atomic_t signals_received; -static int outstanding_aio_calls; -static uint16 *aio_pending_array; - /**************************************************************************** Signal handler when an aio request completes. *****************************************************************************/ void aio_request_done(uint16_t mid) { - if (signals_received < aio_pending_size) { - aio_pending_array[signals_received] = mid; - signals_received++; + if (aio_signals_received < aio_pending_size) { + aio_pending_array[aio_signals_received] = mid; + aio_signals_received++; } /* Else signal is lost. */ } @@ -139,7 +133,7 @@ static void signal_handler(int sig, siginfo_t *info, void *unused) bool aio_finished(void) { - return (signals_received != 0); + return (aio_signals_received != 0); } /**************************************************************************** @@ -587,17 +581,17 @@ int process_aio_queue(void) BlockSignals(True, RT_SIGNAL_AIO); DEBUG(10,("process_aio_queue: signals_received = %d\n", - (int)signals_received)); + (int)aio_signals_received)); DEBUG(10,("process_aio_queue: outstanding_aio_calls = %d\n", outstanding_aio_calls)); - if (!signals_received) { + if (!aio_signals_received) { BlockSignals(False, RT_SIGNAL_AIO); return 0; } /* Drain all the complete aio_reads. */ - for (i = 0; i < signals_received; i++) { + for (i = 0; i < aio_signals_received; i++) { uint16 mid = aio_pending_array[i]; files_struct *fsp = NULL; struct aio_extra *aio_ex = find_aio_ex(mid); @@ -626,8 +620,8 @@ int process_aio_queue(void) TALLOC_FREE(aio_ex); } - outstanding_aio_calls -= signals_received; - signals_received = 0; + outstanding_aio_calls -= aio_signals_received; + aio_signals_received = 0; BlockSignals(False, RT_SIGNAL_AIO); return ret; } diff --git a/source3/smbd/blocking.c b/source3/smbd/blocking.c index 2b90d24c87..cccc5ce727 100644 --- a/source3/smbd/blocking.c +++ b/source3/smbd/blocking.c @@ -18,6 +18,8 @@ */ #include "includes.h" +#include "smbd/globals.h" + #undef DBGC_CLASS #define DBGC_CLASS DBGC_LOCKING @@ -41,15 +43,6 @@ typedef struct blocking_lock_record { struct smb_request *req; } blocking_lock_record; -/* dlink list we store pending lock records on. */ -static blocking_lock_record *blocking_lock_queue; - -/* dlink list we move cancelled lock records onto. */ -static blocking_lock_record *blocking_lock_cancelled_queue; - -/* The event that makes us process our blocking lock queue */ -static struct timed_event *brl_timeout; - /**************************************************************************** Determine if this is a secondary element of a chained SMB. **************************************************************************/ @@ -148,7 +141,6 @@ bool push_blocking_lock_request( struct byte_range_lock *br_lck, uint64_t count, uint32_t blocking_pid) { - static bool set_lock_msg; blocking_lock_record *blr; NTSTATUS status; @@ -211,10 +203,10 @@ bool push_blocking_lock_request( struct byte_range_lock *br_lck, recalc_brl_timeout(); /* Ensure we'll receive messages when this is unlocked. */ - if (!set_lock_msg) { + if (!blocking_lock_unlock_state) { messaging_register(smbd_messaging_context(), NULL, MSG_SMB_UNLOCK, received_unlock_msg); - set_lock_msg = True; + blocking_lock_unlock_state = true; } DEBUG(3,("push_blocking_lock_request: lock request blocked with " @@ -784,17 +776,16 @@ bool blocking_lock_cancel(files_struct *fsp, unsigned char locktype, NTSTATUS err) { - static bool initialized; char msg[MSG_BLOCKING_LOCK_CANCEL_SIZE]; blocking_lock_record *blr; - if (!initialized) { + if (!blocking_lock_cancel_state) { /* Register our message. */ messaging_register(smbd_messaging_context(), NULL, MSG_SMB_BLOCKING_LOCK_CANCEL, process_blocking_lock_cancel_message); - initialized = True; + blocking_lock_cancel_state = True; } for (blr = blocking_lock_queue; blr; blr = blr->next) { diff --git a/source3/smbd/conn.c b/source3/smbd/conn.c index 7f34d2b8e2..4b467b0312 100644 --- a/source3/smbd/conn.c +++ b/source3/smbd/conn.c @@ -19,6 +19,7 @@ */ #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 @@ -26,12 +27,6 @@ */ #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 ****************************************************************************/ diff --git a/source3/smbd/dfree.c b/source3/smbd/dfree.c index cd09d73923..dc5719a4a5 100644 --- a/source3/smbd/dfree.c +++ b/source3/smbd/dfree.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "smbd/globals.h" /**************************************************************************** Normalise for DOS usage. @@ -150,10 +151,9 @@ uint64_t sys_disk_free(connection_struct *conn, const char *path, bool small_que } if ((*dsize)<1) { - static bool done = false; - if (!done) { + if (!dfree_broken) { DEBUG(0,("WARNING: dfree is broken on this system\n")); - done=true; + dfree_broken=true; } *dsize = 20*1024*1024/(*bsize); *dfree = MAX(1,*dfree); diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index c2735c032a..2b996a41cf 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "smbd/globals.h" /* This module implements directory related functions for Samba. @@ -61,9 +62,6 @@ struct dptr_struct { bool did_stat; /* Optimisation for non-wcard searches. */ }; -static struct bitmap *dptr_bmap; -static struct dptr_struct *dirptrs; -static int dirhandles_open = 0; #define INVALID_DPTR_KEY (-3) @@ -119,17 +117,13 @@ bool make_dir_struct(TALLOC_CTX *ctx, void init_dptrs(void) { - static bool dptrs_init=False; - - if (dptrs_init) + if (dptr_bmap) return; dptr_bmap = bitmap_allocate(MAX_DIRECTORY_HANDLES); if (!dptr_bmap) exit_server("out of memory in init_dptrs"); - - dptrs_init = True; } /**************************************************************************** diff --git a/source3/smbd/dmapi.c b/source3/smbd/dmapi.c index 4b40c16ebd..dbb799fd5b 100644 --- a/source3/smbd/dmapi.c +++ b/source3/smbd/dmapi.c @@ -19,6 +19,7 @@ */ #include "includes.h" +#include "smbd/globals.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_DMAPI diff --git a/source3/smbd/error.c b/source3/smbd/error.c index de2de088ec..ce22f86414 100644 --- a/source3/smbd/error.c +++ b/source3/smbd/error.c @@ -18,12 +18,11 @@ */ #include "includes.h" +#include "smbd/globals.h" /* From lib/error.c */ extern struct unix_error_map unix_dos_nt_errmap[]; -extern uint32 global_client_caps; - bool use_nt_status(void) { return lp_nt_status_support() && (global_client_caps & CAP_STATUS32); diff --git a/source3/smbd/fileio.c b/source3/smbd/fileio.c index 30253d4466..3e3f0943b3 100644 --- a/source3/smbd/fileio.c +++ b/source3/smbd/fileio.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "smbd/globals.h" static bool setup_write_cache(files_struct *, SMB_OFF_T); @@ -109,9 +110,6 @@ tryagain: return(ret); } -/* how many write cache buffers have been allocated */ -static unsigned int allocated_write_caches; - /**************************************************************************** *Really* write to a file. ****************************************************************************/ diff --git a/source3/smbd/files.c b/source3/smbd/files.c index 1a3a997e59..efaadffc06 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -18,33 +18,18 @@ */ #include "includes.h" - -static int real_max_open_files; +#include "smbd/globals.h" #define VALID_FNUM(fnum) (((fnum) >= 0) && ((fnum) < real_max_open_files)) #define FILE_HANDLE_OFFSET 0x1000 -static struct bitmap *file_bmap; - -static files_struct *Files; - -static int files_used; - -/* A singleton cache to speed up searching by dev/inode. */ -static struct fsp_singleton_cache { - files_struct *fsp; - struct file_id id; -} fsp_fi_cache; - /**************************************************************************** Return a unique number identifying this fsp over the life of this pid. ****************************************************************************/ static unsigned long get_gen_count(void) { - static unsigned long file_gen_counter; - if ((++file_gen_counter) == 0) return ++file_gen_counter; return file_gen_counter; @@ -58,7 +43,6 @@ NTSTATUS file_new(struct smb_request *req, connection_struct *conn, files_struct **result) { int i; - static int first_file; files_struct *fsp; /* we want to give out file handles differently on each new diff --git a/source3/smbd/globals.c b/source3/smbd/globals.c new file mode 100644 index 0000000000..ad017f5a23 --- /dev/null +++ b/source3/smbd/globals.c @@ -0,0 +1,221 @@ +/* + Unix SMB/Netbios implementation. + smbd globals + Copyright (C) Stefan Metzmacher 2009 + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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, see <http://www.gnu.org/licenses/>. +*/ + +#include "includes.h" +#include "smbd/globals.h" + +#if defined(WITH_AIO) +struct aio_extra *aio_list_head = NULL; +int aio_pending_size = 0; +sig_atomic_t aio_signals_received = 0; +int outstanding_aio_calls = 0; +uint16 *aio_pending_array = NULL; +#endif + +/* dlink list we store pending lock records on. */ +struct blocking_lock_record *blocking_lock_queue = NULL; + +/* dlink list we move cancelled lock records onto. */ +struct blocking_lock_record *blocking_lock_cancelled_queue = NULL; + +/* The event that makes us process our blocking lock queue */ +struct timed_event *brl_timeout = NULL; + +bool blocking_lock_unlock_state = false; +bool blocking_lock_cancel_state = false; + +#ifdef USE_DMAPI +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; + +struct bitmap *dptr_bmap = NULL; +struct dptr_struct *dirptrs = NULL; +int dirhandles_open = 0; + +/* how many write cache buffers have been allocated */ +unsigned int allocated_write_caches = 0; + +int real_max_open_files = 0; +struct bitmap *file_bmap = NULL; +files_struct *Files = NULL; +int files_used = 0; +struct fsp_singleton_cache fsp_fi_cache = { + .fsp = NULL, + .id = { + .devid = 0, + .inode = 0 + } +}; +unsigned long file_gen_counter = 0; +int first_file = 0; + +const struct mangle_fns *mangle_fns = NULL; + +unsigned char *chartest = NULL; +TDB_CONTEXT *tdb_mangled_cache = NULL; + +/* these tables are used to provide fast tests for characters */ +unsigned char char_flags[256]; +/* + this determines how many characters are used from the original filename + in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions. + The largest possible value is 6. +*/ +unsigned mangle_prefix = 0; +unsigned char base_reverse[256]; + +char *last_from = NULL; +char *last_to = NULL; + +struct msg_state *smbd_msg_state = NULL; + +bool global_encrypted_passwords_negotiated = false; +bool global_spnego_negotiated = false; +struct auth_context *negprot_global_auth_context = NULL; +bool done_negprot = false; + +bool logged_ioctl_message = false; + +/* users from session setup */ +char *session_userlist = NULL; +/* workgroup from session setup. */ +char *session_workgroup = NULL; +/* this holds info on user ids that are already validated for this VC */ +user_struct *validated_users = NULL; +uint16_t next_vuid = VUID_OFFSET; +int num_validated_vuids = 0; +#ifdef HAVE_NETGROUP +char *my_yp_domain = NULL; +#endif + +bool already_got_session = false; + +/* + * Size of data we can send to client. Set + * by the client for all protocols above CORE. + * Set by us for CORE protocol. + */ +int max_send = BUFFER_SIZE; +/* + * Size of the data we can receive. Set by us. + * Can be modified by the max xmit parameter. + */ +int max_recv = BUFFER_SIZE; +SIG_ATOMIC_T reload_after_sighup = 0; +SIG_ATOMIC_T got_sig_term = 0; +uint16 last_session_tag = UID_FIELD_INVALID; +int trans_num = 0; +char *orig_inbuf = NULL; +pid_t mypid = 0; +time_t last_smb_conf_reload_time = 0; +time_t last_printer_reload_time = 0; +/**************************************************************************** + structure to hold a linked list of queued messages. + for processing. +****************************************************************************/ +struct pending_message_list *deferred_open_queue = NULL; +uint32_t common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES; + +struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx = NULL; +struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx = NULL; + +/* A stack of security contexts. We include the current context as being + the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */ +struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1]; +int sec_ctx_stack_ndx = 0; +bool become_uid_done = false; +bool become_gid_done = false; + +connection_struct *last_conn = NULL; +uint16_t last_flags = 0; + +struct db_context *session_db_ctx_ptr = NULL; + +uint32_t global_client_caps = 0; +bool done_sesssetup = false; +/**************************************************************************** + List to store partial SPNEGO auth fragments. +****************************************************************************/ +struct pending_auth_data *pd_list = NULL; + +uint16_t fnf_handle = 257; + +/* A stack of current_user connection contexts. */ +struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH]; +int conn_ctx_stack_ndx = 0; + +struct vfs_init_function_entry *backends = NULL; +char *sparse_buf = NULL; +char *LastDir = NULL; + +#if HAVE_KERNEL_OPLOCKS_LINUX +SIG_ATOMIC_T oplock_signals_received = 0; +SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE]; +struct kernel_oplocks linux_koplocks; +#endif + +#if HAVE_KERNEL_OPLOCKS_IRIX +int oplock_pipe_write = -1; +int oplock_pipe_read = -1; +struct kernel_oplocks irix_koplocks; +#endif + +/* Current number of oplocks we have outstanding. */ +int32_t exclusive_oplocks_open = 0; +int32_t level_II_oplocks_open = 0; +bool global_client_failed_oplock_break = false; +const struct kernel_oplocks *koplocks = NULL; + +struct notify_mid_map *notify_changes_by_mid = NULL; + +int am_parent = 1; +SIG_ATOMIC_T got_sig_cld = 0; +int server_fd = -1; +struct event_context *smbd_event_ctx = NULL; +struct messaging_context *smbd_msg_ctx = NULL; +struct memcache *smbd_memcache_ctx = NULL; +bool exit_firsttime = true; +struct child_pid *children = 0; +int num_children = 0; + +void smbd_init_globals(void) +{ + ZERO_STRUCT(char_flags); + ZERO_STRUCT(base_reverse); + + ZERO_STRUCT(conn_ctx_stack); + + ZERO_STRUCT(sec_ctx_stack); + +#if HAVE_KERNEL_OPLOCKS_LINUX + ZERO_STRUCT(fd_pending_array); + ZERO_STRUCT(linux_koplocks); +#endif +#if HAVE_KERNEL_OPLOCKS_IRIX + ZERO_STRUCT(irix_koplocks); +#endif +} diff --git a/source3/smbd/globals.h b/source3/smbd/globals.h new file mode 100644 index 0000000000..178263ba2c --- /dev/null +++ b/source3/smbd/globals.h @@ -0,0 +1,219 @@ +/* + Unix SMB/Netbios implementation. + smbd globals + Copyright (C) Stefan Metzmacher 2009 + + 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 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + 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, see <http://www.gnu.org/licenses/>. +*/ + +#if defined(WITH_AIO) +struct aio_extra; +extern struct aio_extra *aio_list_head; +extern int aio_pending_size; +extern sig_atomic_t aio_signals_received; +extern int outstanding_aio_calls; +extern uint16_t *aio_pending_array; +#endif + +/* dlink list we store pending lock records on. */ +extern struct blocking_lock_record *blocking_lock_queue; + +/* dlink list we move cancelled lock records onto. */ +extern struct blocking_lock_record *blocking_lock_cancelled_queue; + +/* The event that makes us process our blocking lock queue */ +extern struct timed_event *brl_timeout; + +extern bool blocking_lock_unlock_state; +extern bool blocking_lock_cancel_state; + +#ifdef USE_DMAPI +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; +//struct dptr_struct; +extern struct dptr_struct *dirptrs; +extern int dirhandles_open; + +/* how many write cache buffers have been allocated */ +extern unsigned int allocated_write_caches; + +extern int real_max_open_files; +extern struct bitmap *file_bmap; +extern files_struct *Files; +extern int files_used; +/* A singleton cache to speed up searching by dev/inode. */ +struct fsp_singleton_cache { + files_struct *fsp; + struct file_id id; +}; +extern struct fsp_singleton_cache fsp_fi_cache; +extern unsigned long file_gen_counter; +extern int first_file; + +extern const struct mangle_fns *mangle_fns; + +extern unsigned char *chartest; +extern TDB_CONTEXT *tdb_mangled_cache; + +/* these tables are used to provide fast tests for characters */ +extern unsigned char char_flags[256]; +/* + this determines how many characters are used from the original filename + in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions. + The largest possible value is 6. +*/ +extern unsigned mangle_prefix; +extern unsigned char base_reverse[256]; + +extern char *last_from; +extern char *last_to; + +struct msg_state; +extern struct msg_state *smbd_msg_state; + +extern bool global_encrypted_passwords_negotiated; +extern bool global_spnego_negotiated; +extern struct auth_context *negprot_global_auth_context; +extern bool done_negprot; + +extern bool logged_ioctl_message; + +/* users from session setup */ +extern char *session_userlist; +/* workgroup from session setup. */ +extern char *session_workgroup; +/* this holds info on user ids that are already validated for this VC */ +extern user_struct *validated_users; +extern uint16_t next_vuid; +extern int num_validated_vuids; +#ifdef HAVE_NETGROUP +extern char *my_yp_domain; +#endif + +extern bool already_got_session; + +/* + * Size of data we can send to client. Set + * by the client for all protocols above CORE. + * Set by us for CORE protocol. + */ +extern int max_send; +/* + * Size of the data we can receive. Set by us. + * Can be modified by the max xmit parameter. + */ +extern int max_recv; +extern SIG_ATOMIC_T reload_after_sighup; +extern SIG_ATOMIC_T got_sig_term; +extern uint16 last_session_tag; +extern int trans_num; +extern char *orig_inbuf; + +extern pid_t mypid; +extern time_t last_smb_conf_reload_time; +extern time_t last_printer_reload_time; +/**************************************************************************** + structure to hold a linked list of queued messages. + for processing. +****************************************************************************/ +struct pending_message_list; +extern struct pending_message_list *deferred_open_queue; +extern uint32_t common_flags2; + +struct smb_srv_trans_enc_ctx; +extern struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx; +extern struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx; + +struct sec_ctx { + UNIX_USER_TOKEN ut; + NT_USER_TOKEN *token; +}; +/* A stack of security contexts. We include the current context as being + the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */ +extern struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1]; +extern int sec_ctx_stack_ndx; +extern bool become_uid_done; +extern bool become_gid_done; + +extern connection_struct *last_conn; +extern uint16_t last_flags; + +extern struct db_context *session_db_ctx_ptr; + +extern uint32_t global_client_caps; +extern bool done_sesssetup; +/**************************************************************************** + List to store partial SPNEGO auth fragments. +****************************************************************************/ +struct pending_auth_data; +extern struct pending_auth_data *pd_list; + +extern uint16_t fnf_handle; + +struct conn_ctx { + connection_struct *conn; + uint16 vuid; +}; +/* A stack of current_user connection contexts. */ +extern struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH]; +extern int conn_ctx_stack_ndx; + +struct vfs_init_function_entry; +extern struct vfs_init_function_entry *backends; +extern char *sparse_buf; +extern char *LastDir; + +#if HAVE_KERNEL_OPLOCKS_LINUX +extern SIG_ATOMIC_T oplock_signals_received; +#define FD_PENDING_SIZE 100 +extern SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE]; +extern struct kernel_oplocks linux_koplocks; +#endif + +#if HAVE_KERNEL_OPLOCKS_IRIX +extern int oplock_pipe_write; +extern int oplock_pipe_read; +extern struct kernel_oplocks irix_koplocks; +#endif + +/* Current number of oplocks we have outstanding. */ +extern int32_t exclusive_oplocks_open; +extern int32_t level_II_oplocks_open; +extern bool global_client_failed_oplock_break; +extern const struct kernel_oplocks *koplocks; + +extern struct notify_mid_map *notify_changes_by_mid; + +extern int am_parent; +extern SIG_ATOMIC_T got_sig_cld; +extern int server_fd; +extern struct event_context *smbd_event_ctx; +extern struct messaging_context *smbd_msg_ctx; +extern struct memcache *smbd_memcache_ctx; +extern bool exit_firsttime; +struct child_pid; +extern struct child_pid *children; +extern int num_children; + +void smbd_init_globals(void); diff --git a/source3/smbd/ipc.c b/source3/smbd/ipc.c index 649ead4682..fabc8393ce 100644 --- a/source3/smbd/ipc.c +++ b/source3/smbd/ipc.c @@ -25,8 +25,7 @@ */ #include "includes.h" - -extern int max_send; +#include "smbd/globals.h" #define NERR_notsupported 50 diff --git a/source3/smbd/mangle.c b/source3/smbd/mangle.c index e47ea7ed49..d5608ab0bf 100644 --- a/source3/smbd/mangle.c +++ b/source3/smbd/mangle.c @@ -18,8 +18,7 @@ */ #include "includes.h" - -static const struct mangle_fns *mangle_fns; +#include "smbd/globals.h" /* this allows us to add more mangling backends */ static const struct { diff --git a/source3/smbd/mangle_hash.c b/source3/smbd/mangle_hash.c index 9b40d717ce..ebd93ff5d0 100644 --- a/source3/smbd/mangle_hash.c +++ b/source3/smbd/mangle_hash.c @@ -21,6 +21,7 @@ */ #include "includes.h" +#include "smbd/globals.h" /* -------------------------------------------------------------------------- ** * Other stuff... @@ -55,14 +56,10 @@ static const char basechars[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_-!@#$%"; #define MANGLE_BASE (sizeof(basechars)/sizeof(char)-1) -static unsigned char *chartest; - #define mangle(V) ((char)(basechars[(V) % MANGLE_BASE])) #define BASECHAR_MASK 0xf0 #define isbasechar(C) ( (chartest[ ((C) & 0xff) ]) & BASECHAR_MASK ) -static TDB_CONTEXT *tdb_mangled_cache; - /* -------------------------------------------------------------------- */ static NTSTATUS has_valid_83_chars(const smb_ucs2_t *s, bool allow_wildcards) diff --git a/source3/smbd/mangle_hash2.c b/source3/smbd/mangle_hash2.c index 8431a7ffe9..859e5e7227 100644 --- a/source3/smbd/mangle_hash2.c +++ b/source3/smbd/mangle_hash2.c @@ -51,6 +51,7 @@ #include "includes.h" +#include "smbd/globals.h" #if 1 #define M_DEBUG(level, x) DEBUG(level, x) @@ -81,21 +82,10 @@ /*the following number is a fnv1 of the string: idra@samba.org 2002 */ #define FNV1_INIT 0xa6b93095 -/* these tables are used to provide fast tests for characters */ -static unsigned char char_flags[256]; - #define FLAG_CHECK(c, flag) (char_flags[(unsigned char)(c)] & (flag)) -/* - this determines how many characters are used from the original filename - in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions. - The largest possible value is 6. -*/ -static unsigned mangle_prefix; - /* these are the characters we use in the 8.3 hash. Must be 36 chars long */ static const char * const basechars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -static unsigned char base_reverse[256]; #define base_forward(v) basechars[v] /* the list of reserved dos names - all of these are illegal */ diff --git a/source3/smbd/map_username.c b/source3/smbd/map_username.c index f549f0c9f3..fde2a3c4d3 100644 --- a/source3/smbd/map_username.c +++ b/source3/smbd/map_username.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "smbd/globals.h" /******************************************************************* Map a username from a dos name to a unix name by looking in the username @@ -32,8 +33,6 @@ Returns True if username was changed, false otherwise. ********************************************************************/ -static char *last_from, *last_to; - static const char *get_last_from(void) { if (!last_from) { diff --git a/source3/smbd/message.c b/source3/smbd/message.c index 65eaeca777..dbc833f091 100644 --- a/source3/smbd/message.c +++ b/source3/smbd/message.c @@ -23,6 +23,7 @@ #include "includes.h" +#include "smbd/globals.h" extern userdom_struct current_user_info; @@ -32,8 +33,6 @@ struct msg_state { char *msg; }; -static struct msg_state *smbd_msg_state; - /**************************************************************************** Deliver the message. ****************************************************************************/ diff --git a/source3/smbd/msdfs.c b/source3/smbd/msdfs.c index d46be64262..adeaf96bd2 100644 --- a/source3/smbd/msdfs.c +++ b/source3/smbd/msdfs.c @@ -22,8 +22,7 @@ #define DBGC_CLASS DBGC_MSDFS #include "includes.h" - -extern uint32 global_client_caps; +#include "smbd/globals.h" /********************************************************************** Parse a DFS pathname of the form \hostname\service\reqpath diff --git a/source3/smbd/negprot.c b/source3/smbd/negprot.c index 43fdc1d608..729d144ea1 100644 --- a/source3/smbd/negprot.c +++ b/source3/smbd/negprot.c @@ -19,14 +19,10 @@ */ #include "includes.h" +#include "smbd/globals.h" extern fstring remote_proto; extern enum protocol_types Protocol; -extern int max_recv; - -bool global_encrypted_passwords_negotiated = False; -bool global_spnego_negotiated = False; -struct auth_context *negprot_global_auth_context = NULL; static void get_challenge(uint8 buff[8]) { @@ -516,8 +512,6 @@ void reply_negprot(struct smb_request *req) int i; size_t converted_size; - static bool done_negprot = False; - START_PROFILE(SMBnegprot); if (done_negprot) { diff --git a/source3/smbd/notify.c b/source3/smbd/notify.c index 2d0811bc1c..7ffe62058c 100644 --- a/source3/smbd/notify.c +++ b/source3/smbd/notify.c @@ -20,6 +20,7 @@ */ #include "includes.h" +#include "smbd/globals.h" struct notify_change_request { struct notify_change_request *prev, *next; @@ -33,8 +34,6 @@ struct notify_change_request { static void notify_fsp(files_struct *fsp, uint32 action, const char *name); -static struct notify_mid_map *notify_changes_by_mid; - /* * For NTCancel, we need to find the notify_change_request indexed by * mid. Separate list here. diff --git a/source3/smbd/nttrans.c b/source3/smbd/nttrans.c index db92e28610..f1423c028e 100644 --- a/source3/smbd/nttrans.c +++ b/source3/smbd/nttrans.c @@ -19,8 +19,8 @@ */ #include "includes.h" +#include "smbd/globals.h" -extern int max_send; extern enum protocol_types Protocol; extern const struct generic_mapping file_generic_mapping; @@ -1770,7 +1770,6 @@ static void call_nt_transact_ioctl(connection_struct *conn, files_struct *fsp; uint8 isFSctl; uint8 compfilter; - static bool logged_message; char *pdata = *ppdata; if (setup_count != 8) { @@ -2030,8 +2029,8 @@ static void call_nt_transact_ioctl(connection_struct *conn, return; } default: - if (!logged_message) { - logged_message = True; /* Only print this once... */ + if (!logged_ioctl_message) { + logged_ioctl_message = true; /* Only print this once... */ DEBUG(0,("call_nt_transact_ioctl(0x%x): Currently not implemented.\n", function)); } diff --git a/source3/smbd/open.c b/source3/smbd/open.c index 05b131efaf..52e31dfc23 100644 --- a/source3/smbd/open.c +++ b/source3/smbd/open.c @@ -20,10 +20,9 @@ */ #include "includes.h" +#include "smbd/globals.h" extern const struct generic_mapping file_generic_mapping; -extern bool global_client_failed_oplock_break; -extern uint32 global_client_caps; struct deferred_open_record { bool delayed_for_oplocks; diff --git a/source3/smbd/oplock.c b/source3/smbd/oplock.c index 6efa3dcfc6..3fd5afef22 100644 --- a/source3/smbd/oplock.c +++ b/source3/smbd/oplock.c @@ -21,15 +21,7 @@ #define DBGC_CLASS DBGC_LOCKING #include "includes.h" - -/* Current number of oplocks we have outstanding. */ -static int32 exclusive_oplocks_open = 0; -static int32 level_II_oplocks_open = 0; -bool global_client_failed_oplock_break = False; - -extern uint32 global_client_caps; - -static struct kernel_oplocks *koplocks; +#include "smbd/globals.h" /**************************************************************************** Get the number of current exclusive oplocks. diff --git a/source3/smbd/oplock_irix.c b/source3/smbd/oplock_irix.c index 8c287c9836..496b0b72ea 100644 --- a/source3/smbd/oplock_irix.c +++ b/source3/smbd/oplock_irix.c @@ -19,12 +19,10 @@ #define DBGC_CLASS DBGC_LOCKING #include "includes.h" +#include "smbd/globals.h" #if HAVE_KERNEL_OPLOCKS_IRIX -static int oplock_pipe_write = -1; -static int oplock_pipe_read = -1; - /**************************************************************************** Test to see if IRIX kernel oplocks work. ****************************************************************************/ @@ -273,7 +271,6 @@ static bool irix_oplock_msg_waiting(fd_set *fds) struct kernel_oplocks *irix_init_kernel_oplocks(void) { int pfd[2]; - static struct kernel_oplocks koplocks; if (!irix_oplocks_available()) return NULL; @@ -287,13 +284,13 @@ struct kernel_oplocks *irix_init_kernel_oplocks(void) oplock_pipe_read = pfd[0]; oplock_pipe_write = pfd[1]; - koplocks.receive_message = irix_oplock_receive_message; - koplocks.set_oplock = irix_set_kernel_oplock; - koplocks.release_oplock = irix_release_kernel_oplock; - koplocks.msg_waiting = irix_oplock_msg_waiting; - koplocks.notification_fd = oplock_pipe_read; + irix_koplocks.receive_message = irix_oplock_receive_message; + irix_koplocks.set_oplock = irix_set_kernel_oplock; + irix_koplocks.release_oplock = irix_release_kernel_oplock; + irix_koplocks.msg_waiting = irix_oplock_msg_waiting; + irix_koplocks.notification_fd = oplock_pipe_read; - return &koplocks; + return &irix_koplocks; } #else void oplock_irix_dummy(void); diff --git a/source3/smbd/oplock_linux.c b/source3/smbd/oplock_linux.c index 08df228f8f..cb37a81fb9 100644 --- a/source3/smbd/oplock_linux.c +++ b/source3/smbd/oplock_linux.c @@ -19,13 +19,10 @@ #define DBGC_CLASS DBGC_LOCKING #include "includes.h" +#include "smbd/globals.h" #if HAVE_KERNEL_OPLOCKS_LINUX -static SIG_ATOMIC_T signals_received; -#define FD_PENDING_SIZE 100 -static SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE]; - #ifndef F_SETLEASE #define F_SETLEASE 1024 #endif @@ -52,9 +49,9 @@ static SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE]; static void signal_handler(int sig, siginfo_t *info, void *unused) { - if (signals_received < FD_PENDING_SIZE - 1) { - fd_pending_array[signals_received] = (SIG_ATOMIC_T)info->si_fd; - signals_received++; + if (oplock_signals_received < FD_PENDING_SIZE - 1) { + fd_pending_array[oplock_signals_received] = (SIG_ATOMIC_T)info->si_fd; + oplock_signals_received++; } /* Else signal is lost. */ sys_select_signal(RT_SIGNAL_LEASE); } @@ -113,11 +110,11 @@ static files_struct *linux_oplock_receive_message(fd_set *fds) fd = fd_pending_array[0]; fsp = file_find_fd(fd); fd_pending_array[0] = (SIG_ATOMIC_T)-1; - if (signals_received > 1) + if (oplock_signals_received > 1) memmove(CONST_DISCARD(void *, &fd_pending_array[0]), CONST_DISCARD(void *, &fd_pending_array[1]), - sizeof(SIG_ATOMIC_T)*(signals_received-1)); - signals_received--; + sizeof(SIG_ATOMIC_T)*(oplock_signals_received-1)); + oplock_signals_received--; /* now we can receive more signals */ BlockSignals(False, RT_SIGNAL_LEASE); @@ -186,7 +183,7 @@ static void linux_release_kernel_oplock(files_struct *fsp) static bool linux_oplock_msg_waiting(fd_set *fds) { - return signals_received != 0; + return oplock_signals_received != 0; } /**************************************************************************** @@ -210,7 +207,6 @@ static bool linux_oplocks_available(void) struct kernel_oplocks *linux_init_kernel_oplocks(void) { - static struct kernel_oplocks koplocks; struct sigaction act; if (!linux_oplocks_available()) { @@ -229,18 +225,18 @@ struct kernel_oplocks *linux_init_kernel_oplocks(void) return NULL; } - koplocks.receive_message = linux_oplock_receive_message; - koplocks.set_oplock = linux_set_kernel_oplock; - koplocks.release_oplock = linux_release_kernel_oplock; - koplocks.msg_waiting = linux_oplock_msg_waiting; - koplocks.notification_fd = -1; + linux_koplocks.receive_message = linux_oplock_receive_message; + linux_koplocks.set_oplock = linux_set_kernel_oplock; + linux_koplocks.release_oplock = linux_release_kernel_oplock; + linux_koplocks.msg_waiting = linux_oplock_msg_waiting; + linux_koplocks.notification_fd = -1; /* the signal can start off blocked due to a bug in bash */ BlockSignals(False, RT_SIGNAL_LEASE); DEBUG(3,("Linux kernel oplocks enabled\n")); - return &koplocks; + return &linux_koplocks; } #else void oplock_linux_dummy(void); diff --git a/source3/smbd/password.c b/source3/smbd/password.c index 005d92bd88..293ba85852 100644 --- a/source3/smbd/password.c +++ b/source3/smbd/password.c @@ -19,16 +19,7 @@ */ #include "includes.h" - -/* users from session setup */ -static char *session_userlist = NULL; -/* workgroup from session setup. */ -static char *session_workgroup = NULL; - -/* this holds info on user ids that are already validated for this VC */ -static user_struct *validated_users; -static uint16_t next_vuid = VUID_OFFSET; -static int num_validated_vuids; +#include "smbd/globals.h" enum server_allocated_state { SERVER_ALLOCATED_REQUIRED_YES, SERVER_ALLOCATED_REQUIRED_NO, @@ -403,21 +394,20 @@ const char *get_session_workgroup(void) bool user_in_netgroup(const char *user, const char *ngname) { #ifdef HAVE_NETGROUP - static char *mydomain = NULL; fstring lowercase_user; - if (mydomain == NULL) - yp_get_default_domain(&mydomain); + if (my_yp_domain == NULL) + yp_get_default_domain(&my_yp_domain); - if(mydomain == NULL) { + if(my_yp_domain == NULL) { DEBUG(5,("Unable to get default yp domain, " "let's try without specifying it\n")); } DEBUG(5,("looking for user %s of domain %s in netgroup %s\n", - user, mydomain?mydomain:"(ANY)", ngname)); + user, my_yp_domain?my_yp_domain:"(ANY)", ngname)); - if (innetgr(ngname, NULL, user, mydomain)) { + if (innetgr(ngname, NULL, user, my_yp_domain)) { DEBUG(5,("user_in_netgroup: Found\n")); return (True); } else { @@ -431,9 +421,9 @@ bool user_in_netgroup(const char *user, const char *ngname) strlower_m(lowercase_user); DEBUG(5,("looking for user %s of domain %s in netgroup %s\n", - lowercase_user, mydomain?mydomain:"(ANY)", ngname)); + lowercase_user, my_yp_domain?my_yp_domain:"(ANY)", ngname)); - if (innetgr(ngname, NULL, lowercase_user, mydomain)) { + if (innetgr(ngname, NULL, lowercase_user, my_yp_domain)) { DEBUG(5,("user_in_netgroup: Found\n")); return (True); } diff --git a/source3/smbd/process.c b/source3/smbd/process.c index cd9eaa6b1e..6f0a10da4a 100644 --- a/source3/smbd/process.c +++ b/source3/smbd/process.c @@ -19,23 +19,9 @@ */ #include "includes.h" +#include "smbd/globals.h" -/* - * Size of data we can send to client. Set - * by the client for all protocols above CORE. - * Set by us for CORE protocol. - */ -int max_send = BUFFER_SIZE; -/* - * Size of the data we can receive. Set by us. - * Can be modified by the max xmit parameter. - */ -int max_recv = BUFFER_SIZE; - -SIG_ATOMIC_T reload_after_sighup = 0; -SIG_ATOMIC_T got_sig_term = 0; extern bool global_machine_password_needs_changing; -extern int max_send; static void construct_reply_common(struct smb_request *req, const char *inbuf, char *outbuf); @@ -406,12 +392,6 @@ void init_smb_request(struct smb_request *req, req->outbuf = NULL; } -/**************************************************************************** - structure to hold a linked list of queued messages. - for processing. -****************************************************************************/ - -static struct pending_message_list *deferred_open_queue; /**************************************************************************** Function to push a message onto the tail of a linked list of smb messages ready @@ -1351,8 +1331,6 @@ static connection_struct *switch_message(uint8 type, struct smb_request *req, in uint16 session_tag; connection_struct *conn = NULL; - static uint16 last_session_tag = UID_FIELD_INVALID; - errno = 0; /* Make sure this is an SMB packet. smb_size contains NetBIOS header @@ -1543,7 +1521,6 @@ static void construct_reply(char *inbuf, int size, size_t unread_bytes, bool enc static void process_smb(char *inbuf, size_t nread, size_t unread_bytes, bool encrypted) { - static int trans_num; int msg_type = CVAL(inbuf,0); DO_PROFILE_INC(smb_count); @@ -1587,8 +1564,6 @@ const char *smb_fn_name(int type) Helper functions for contruct_reply. ****************************************************************************/ -static uint32 common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES; - void add_to_common_flags2(uint32 v) { common_flags2 |= v; @@ -1629,8 +1604,6 @@ void construct_reply_common_req(struct smb_request *req, char *outbuf) void chain_reply(struct smb_request *req) { - static char *orig_inbuf; - /* * Dirty little const_discard: We mess with req->inbuf, which is * declared as const. If maybe at some point this routine gets @@ -1839,9 +1812,6 @@ void chain_reply(struct smb_request *req) void check_reload(time_t t) { - static pid_t mypid = 0; - static time_t last_smb_conf_reload_time = 0; - static time_t last_printer_reload_time = 0; time_t printcap_cache_time = (time_t)lp_printcap_cache_time(); if(last_smb_conf_reload_time == 0) { diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 593558e399..24f6cd30bd 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -25,13 +25,9 @@ */ #include "includes.h" +#include "smbd/globals.h" -/* look in server.c for some explanation of these variables */ extern enum protocol_types Protocol; -extern int max_recv; -extern uint32 global_client_caps; - -extern bool global_encrypted_passwords_negotiated; /**************************************************************************** Ensure we check the path in *exactly* the same way as W2K for a findfirst/findnext @@ -424,8 +420,6 @@ void reply_special(char *inbuf) */ char outbuf[smb_size]; - static bool already_got_session = False; - *name1 = *name2 = 0; memset(outbuf, '\0', sizeof(outbuf)); diff --git a/source3/smbd/seal.c b/source3/smbd/seal.c index bd4d853885..0d5415b5f4 100644 --- a/source3/smbd/seal.c +++ b/source3/smbd/seal.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "smbd/globals.h" /****************************************************************************** Server side encryption. @@ -32,9 +33,6 @@ struct smb_srv_trans_enc_ctx { AUTH_NTLMSSP_STATE *auth_ntlmssp_state; /* Must be kept in sync with pointer in ec->ntlmssp_state. */ }; -static struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx; -static struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx; - /****************************************************************************** Return global enc context - this must change if we ever do multiple contexts. ******************************************************************************/ diff --git a/source3/smbd/sec_ctx.c b/source3/smbd/sec_ctx.c index a618f06e6b..4b9e5d4727 100644 --- a/source3/smbd/sec_ctx.c +++ b/source3/smbd/sec_ctx.c @@ -18,20 +18,10 @@ */ #include "includes.h" +#include "smbd/globals.h" extern struct current_user current_user; -struct sec_ctx { - UNIX_USER_TOKEN ut; - NT_USER_TOKEN *token; -}; - -/* A stack of security contexts. We include the current context as being - the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */ - -static struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1]; -static int sec_ctx_stack_ndx; - /**************************************************************************** Are two UNIX tokens equal ? ****************************************************************************/ @@ -59,12 +49,10 @@ static bool become_uid(uid_t uid) if (uid == (uid_t)-1 || ((sizeof(uid_t) == 2) && (uid == (uid_t)65535))) { - static int done; - - if (!done) { + if (!become_uid_done) { DEBUG(1,("WARNING: using uid %d is a security risk\n", (int)uid)); - done = 1; + become_uid_done = true; } } @@ -86,12 +74,10 @@ static bool become_gid(gid_t gid) if (gid == (gid_t)-1 || ((sizeof(gid_t) == 2) && (gid == (gid_t)65535))) { - static int done; - - if (!done) { + if (!become_gid_done) { DEBUG(1,("WARNING: using gid %d is a security risk\n", (int)gid)); - done = 1; + become_gid_done = true; } } diff --git a/source3/smbd/server.c b/source3/smbd/server.c index 26c9b62dce..6be8e9b83e 100644 --- a/source3/smbd/server.c +++ b/source3/smbd/server.c @@ -22,28 +22,14 @@ */ #include "includes.h" +#include "smbd/globals.h" static_decl_rpc; -static int am_parent = 1; - -extern struct auth_context *negprot_global_auth_context; -extern SIG_ATOMIC_T got_sig_term; -extern SIG_ATOMIC_T reload_after_sighup; -static SIG_ATOMIC_T got_sig_cld; - #ifdef WITH_DFS extern int dcelogin_atmost_once; #endif /* WITH_DFS */ -/* really we should have a top level context structure that has the - client file descriptor as an element. That would require a major rewrite :( - - the following 2 functions are an alternative - they make the file - descriptor private to smbd - */ -static int server_fd = -1; - int smbd_server_fd(void) { return server_fd; @@ -81,39 +67,39 @@ static int client_get_tcp_info(struct sockaddr_storage *server, struct event_context *smbd_event_context(void) { - static struct event_context *ctx; - - if (!ctx && !(ctx = event_context_init(talloc_autofree_context()))) { + if (!smbd_event_ctx) { + smbd_event_ctx = event_context_init(talloc_autofree_context()); + } + if (!smbd_event_ctx) { smb_panic("Could not init smbd event context"); } - return ctx; + return smbd_event_ctx; } struct messaging_context *smbd_messaging_context(void) { - static struct messaging_context *ctx; - - if (ctx == NULL) { - ctx = messaging_init(talloc_autofree_context(), server_id_self(), - smbd_event_context()); + if (smbd_msg_ctx == NULL) { + smbd_msg_ctx = messaging_init(talloc_autofree_context(), + server_id_self(), + smbd_event_context()); } - if (ctx == NULL) { + if (smbd_msg_ctx == NULL) { DEBUG(0, ("Could not init smbd messaging context.\n")); } - return ctx; + return smbd_msg_ctx; } struct memcache *smbd_memcache(void) { - static struct memcache *cache; - - if (!cache - && !(cache = memcache_init(talloc_autofree_context(), - lp_max_stat_cache_size()*1024))) { - + if (!smbd_memcache_ctx) { + smbd_memcache_ctx = memcache_init(talloc_autofree_context(), + lp_max_stat_cache_size()*1024); + } + if (!smbd_memcache_ctx) { smb_panic("Could not init smbd memcache"); } - return cache; + + return smbd_memcache_ctx; } /******************************************************************* @@ -269,9 +255,6 @@ struct child_pid { pid_t pid; }; -static struct child_pid *children; -static int num_children; - static void add_child_pid(pid_t pid) { struct child_pid *child; @@ -891,12 +874,11 @@ static void exit_server_common(enum server_exit_reason how, static void exit_server_common(enum server_exit_reason how, const char *const reason) { - static int firsttime=1; bool had_open_conn; - if (!firsttime) + if (!exit_firsttime) exit(0); - firsttime = 0; + exit_firsttime = false; change_to_root_user(); @@ -1136,6 +1118,8 @@ extern void build_options(bool screen); }; TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */ + smbd_init_globals(); + TimeInit(); #ifdef HAVE_SET_AUTH_PARAMETERS diff --git a/source3/smbd/service.c b/source3/smbd/service.c index e90098fed0..dcdd69f997 100644 --- a/source3/smbd/service.c +++ b/source3/smbd/service.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "smbd/globals.h" extern userdom_struct current_user_info; @@ -167,8 +168,6 @@ bool set_conn_connectpath(connection_struct *conn, const char *connectpath) bool set_current_service(connection_struct *conn, uint16 flags, bool do_chdir) { - static connection_struct *last_conn; - static uint16 last_flags; int snum; if (!conn) { diff --git a/source3/smbd/session.c b/source3/smbd/session.c index 8163eb30af..ebfffb7d57 100644 --- a/source3/smbd/session.c +++ b/source3/smbd/session.c @@ -27,21 +27,20 @@ */ #include "includes.h" +#include "smbd/globals.h" /******************************************************************** ********************************************************************/ static struct db_context *session_db_ctx(void) { - static struct db_context *ctx; + if (session_db_ctx_ptr) + return session_db_ctx_ptr; - if (ctx) - return ctx; - - ctx = db_open(NULL, lock_path("sessionid.tdb"), 0, - TDB_CLEAR_IF_FIRST|TDB_DEFAULT, - O_RDWR | O_CREAT, 0644); - return ctx; + session_db_ctx_ptr = db_open(NULL, lock_path("sessionid.tdb"), 0, + TDB_CLEAR_IF_FIRST|TDB_DEFAULT, + O_RDWR | O_CREAT, 0644); + return session_db_ctx_ptr; } bool session_init(void) diff --git a/source3/smbd/sesssetup.c b/source3/smbd/sesssetup.c index 73948eca32..b8e0c86833 100644 --- a/source3/smbd/sesssetup.c +++ b/source3/smbd/sesssetup.c @@ -23,14 +23,9 @@ */ #include "includes.h" +#include "smbd/globals.h" -extern struct auth_context *negprot_global_auth_context; -extern bool global_encrypted_passwords_negotiated; -extern bool global_spnego_negotiated; extern enum protocol_types Protocol; -extern int max_send; - -uint32 global_client_caps = 0; /* on a logon error possibly map the error to success if "map to guest" @@ -953,12 +948,6 @@ static void reply_spnego_auth(struct smb_request *req, } /**************************************************************************** - List to store partial SPNEGO auth fragments. -****************************************************************************/ - -static struct pending_auth_data *pd_list; - -/**************************************************************************** Delete an entry on the list. ****************************************************************************/ @@ -1406,7 +1395,6 @@ void reply_sesssetup_and_X(struct smb_request *req) const char *native_os; const char *native_lanman; const char *primary_domain; - static bool done_sesssetup = False; auth_usersupplied_info *user_info = NULL; auth_serversupplied_info *server_info = NULL; uint16 smb_flag2 = req->flags2; diff --git a/source3/smbd/srvstr.c b/source3/smbd/srvstr.c index bae77d5d4b..62b0fe1617 100644 --- a/source3/smbd/srvstr.c +++ b/source3/smbd/srvstr.c @@ -19,7 +19,7 @@ */ #include "includes.h" -extern int max_send; +#include "smbd/globals.h" /* Make sure we can't write a string past the end of the buffer */ diff --git a/source3/smbd/trans2.c b/source3/smbd/trans2.c index 0c449f4ee9..9644e3d1ad 100644 --- a/source3/smbd/trans2.c +++ b/source3/smbd/trans2.c @@ -24,10 +24,9 @@ */ #include "includes.h" +#include "smbd/globals.h" -extern int max_send; extern enum protocol_types Protocol; -extern uint32 global_client_caps; #define get_file_size(sbuf) ((sbuf).st_size) #define DIR_ENTRY_SAFETY_MARGIN 4096 @@ -7220,7 +7219,6 @@ static void call_trans2findnotifyfirst(connection_struct *conn, char **ppdata, int total_data, unsigned int max_data_bytes) { - static uint16 fnf_handle = 257; char *params = *pparams; uint16 info_level; diff --git a/source3/smbd/uid.c b/source3/smbd/uid.c index 82204e97e9..4f059bdb59 100644 --- a/source3/smbd/uid.c +++ b/source3/smbd/uid.c @@ -18,6 +18,7 @@ */ #include "includes.h" +#include "smbd/globals.h" /* what user is current? */ extern struct current_user current_user; @@ -349,16 +350,6 @@ bool unbecome_authenticated_pipe_user(void) Utility functions used by become_xxx/unbecome_xxx. ****************************************************************************/ -struct conn_ctx { - connection_struct *conn; - uint16 vuid; -}; - -/* A stack of current_user connection contexts. */ - -static struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH]; -static int conn_ctx_stack_ndx; - static void push_conn_ctx(void) { struct conn_ctx *ctx_p; diff --git a/source3/smbd/vfs.c b/source3/smbd/vfs.c index 011f31dd24..df5a39eea2 100644 --- a/source3/smbd/vfs.c +++ b/source3/smbd/vfs.c @@ -23,6 +23,7 @@ */ #include "includes.h" +#include "smbd/globals.h" #undef DBGC_CLASS #define DBGC_CLASS DBGC_VFS @@ -35,8 +36,6 @@ struct vfs_init_function_entry { struct vfs_init_function_entry *prev, *next; }; -static struct vfs_init_function_entry *backends = NULL; - /**************************************************************************** maintain the list of available backends ****************************************************************************/ @@ -597,7 +596,6 @@ int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len) Returns 0 on success, -1 on failure. ****************************************************************************/ -static char *sparse_buf; #define SPARSE_BUF_WRITE_SIZE (32*1024) int vfs_fill_sparse(files_struct *fsp, SMB_OFF_T len) @@ -718,7 +716,6 @@ char *vfs_readdirname(connection_struct *conn, void *p) int vfs_ChDir(connection_struct *conn, const char *path) { int res; - static char *LastDir = NULL; if (!LastDir) { LastDir = SMB_STRDUP(""); |