s3:smbd: move all globals and static variables in globals.[ch]
authorStefan Metzmacher <metze@samba.org>
Thu, 8 Jan 2009 11:03:45 +0000 (12:03 +0100)
committerStefan Metzmacher <metze@samba.org>
Thu, 8 Jan 2009 11:22:21 +0000 (12:22 +0100)
The goal is to move all this variables into a big context structure.

metze

39 files changed:
source3/Makefile.in
source3/smbd/aio.c
source3/smbd/blocking.c
source3/smbd/conn.c
source3/smbd/dfree.c
source3/smbd/dir.c
source3/smbd/dmapi.c
source3/smbd/error.c
source3/smbd/fileio.c
source3/smbd/files.c
source3/smbd/globals.c [new file with mode: 0644]
source3/smbd/globals.h [new file with mode: 0644]
source3/smbd/ipc.c
source3/smbd/mangle.c
source3/smbd/mangle_hash.c
source3/smbd/mangle_hash2.c
source3/smbd/map_username.c
source3/smbd/message.c
source3/smbd/msdfs.c
source3/smbd/negprot.c
source3/smbd/notify.c
source3/smbd/nttrans.c
source3/smbd/open.c
source3/smbd/oplock.c
source3/smbd/oplock_irix.c
source3/smbd/oplock_linux.c
source3/smbd/password.c
source3/smbd/process.c
source3/smbd/reply.c
source3/smbd/seal.c
source3/smbd/sec_ctx.c
source3/smbd/server.c
source3/smbd/service.c
source3/smbd/session.c
source3/smbd/sesssetup.c
source3/smbd/srvstr.c
source3/smbd/trans2.c
source3/smbd/uid.c
source3/smbd/vfs.c

index 1625e6595cbd7325a2b3c19c0dfbc5417ab835d9..fdddf365cece89c22a47a95a2f4b65f41296881c 100644 (file)
@@ -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) \
index 8beed0744c17e106194236dd426a42c47331a0e8..54ae45a7892bc150282c28af80cd78ac1458d234 100644 (file)
@@ -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;
 }
index 2b90d24c878ec1e328e184cc58c296d4703c92ad..cccc5ce727af6c477ef517ed5ee3b50a175b33ee 100644 (file)
@@ -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) {
index 7f34d2b8e2b3e9d1971c2bd9cb9a9e5057b1c32c..4b467b0312a5209863e3293ad20a9877ed34ec5f 100644 (file)
@@ -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
  */
 #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
 ****************************************************************************/
index cd09d739236c2aaa39ecde1557c249773a757729..dc5719a4a504f66c9c43ee5bbbb48415998cd822 100644 (file)
@@ -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);
index c2735c032a7527a1729fbc757d476ed2b64e1ed1..2b996a41cfd8edaf960c6dc1c3c59fd1874aee6d 100644 (file)
@@ -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;
 }
 
 /****************************************************************************
index 4b40c16ebd0b3266360dc0464301a561e981f5d1..dbb799fd5baa26132e0333689a5543f9388a6553 100644 (file)
@@ -19,6 +19,7 @@
 */
 
 #include "includes.h"
+#include "smbd/globals.h"
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_DMAPI
index de2de088ec222f30d0c7328bf628217173b49a77..ce22f86414b385b7ff6faa0630e04aa21b83f137 100644 (file)
 */
 
 #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);
index 30253d44664af9a9ed65382bfb67c87e2dcba75a..3e3f0943b3db5dd1519581aef8dec46db01dff85 100644 (file)
@@ -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.
 ****************************************************************************/
index 1a3a997e590a0196cf298b8d7a0d1878d5a0f3f3..efaadffc061cda7569db49ce9186d0af951f76d1 100644 (file)
 */
 
 #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 (file)
index 0000000..ad017f5
--- /dev/null
@@ -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 (file)
index 0000000..178263b
--- /dev/null
@@ -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);
index 649ead468281e545656823f068025d053a5abbc9..fabc8393ce31fce4ff9b0f8d9edda012dc26edeb 100644 (file)
@@ -25,8 +25,7 @@
    */
 
 #include "includes.h"
-
-extern int max_send;
+#include "smbd/globals.h"
 
 #define NERR_notsupported 50
 
index e47ea7ed499cb29c708c3f9b0645c404c2b3a2d1..d5608ab0bf51223b3a25f582bfcc143330598561 100644 (file)
@@ -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 {
index 9b40d717ce01fcf9dd8e02b71f21f5cf16a67e74..ebd93ff5d0d0e9d880e1137eb45fa6b69e4451f3 100644 (file)
@@ -21,6 +21,7 @@
 */
 
 #include "includes.h"
+#include "smbd/globals.h"
 
 /* -------------------------------------------------------------------------- **
  * Other stuff...
 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)
index 8431a7ffe972c39f21de425b474258f2d2a7871e..859e5e72272a996b1372bb92693db5aaa159148c 100644 (file)
@@ -51,6 +51,7 @@
 
 
 #include "includes.h"
+#include "smbd/globals.h"
 
 #if 1
 #define M_DEBUG(level, x) DEBUG(level, x)
 /*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 */
index f549f0c9f301dcbecfc98bf7989928092785add6..fde2a3c4d3a1da770d360cfa5ed0736ffdddf7e1 100644 (file)
@@ -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) {
index 65eaeca777bc76493014bc7c3ab8352793354db4..dbc833f091f09a1c397a5565e77d6263ae26271f 100644 (file)
@@ -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.
 ****************************************************************************/
index d46be6426252343701c7ac48643533fd40bcfbe8..adeaf96bd2d78e7793614cd36dfcd1a9254f7576 100644 (file)
@@ -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
index 43fdc1d60861403bfa0046871457e2180d88dda0..729d144ea1bae4e81d9637a62befb802be282a54 100644 (file)
 */
 
 #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) {
index 2d0811bc1c0a47e8e7cfa6e627d653d3c5486c62..7ffe62058c36be78a51557ba8ac5922de92650ec 100644 (file)
@@ -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.
index db92e28610c9e007fd0ab064792b6572a01ff7e7..f1423c028e1b3cf08507ba922714e0b64b8a0ac8 100644 (file)
@@ -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));
                }
index 05b131efaffa3d0fd4e91ea57379d426b51cb60b..52e31dfc231cbca8b02ef981ca0ff460a07ec810 100644 (file)
 */
 
 #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;
index 6efa3dcfc62e08d76a79e6f774c853e639581d9e..3fd5afef22f2352149917d76cd108050bc7ba35d 100644 (file)
 
 #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.
index 8c287c9836ebad8878f1b3694985952777afc2f8..496b0b72ea845d976762dd94dee1e27ebdc53b36 100644 (file)
 
 #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);
index 08df228f8fd6d4c604591d400aa7235ba848e142..cb37a81fb926a87162b28e2c899088e1e4d8bbcf 100644 (file)
 
 #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);
index 005d92bd88d7acc8d26086b2c955b00e0dc08005..293ba85852dadd8221910f279dbcf2c9e0deac8d 100644 (file)
 */
 
 #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);
                }
index cd9eaa6b1ed87915b3059e1abcf24e8b37ef2869..6f0a10da4ae576a2d2b5b591642cb61b693770da 100644 (file)
 */
 
 #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) {
index 593558e3992aea0a4f87d679dc56cd646669d435..24f6cd30bd26d341efcd5d20d7a84656dc711133 100644 (file)
 */
 
 #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));
index bd4d85388541d84c1d74751ba547ec7905687a08..0d5415b5f48fc455fcb75afc363032637f2aeb45 100644 (file)
@@ -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.
 ******************************************************************************/
index a618f06e6b2b00ff6b1b9ca82749f9a7367ec6a2..4b9e5d47276ca36ea27e286fe0d3a8d0441e0a3f 100644 (file)
 */
 
 #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;
                }
        }
   
index 26c9b62dce90ae0b4266901ea6a748270585e0a8..6be8e9b83e7ed3aae2be574db5ae45b9440b9f23 100644 (file)
 */
 
 #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
index e90098fed066b5f7ecdfa3a3428c7d5b7a9e6ea7..dcdd69f997cea0861ec7c539751ab31740331384 100644 (file)
@@ -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)  {
index 8163eb30af63b4522767587d1ab50f6eef070d8b..ebfffb7d57ead87d83843ff787d8088c406f1dc3 100644 (file)
 */
 
 #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)
index 73948eca32be04cd84e5cb1b2be7a26b6e869792..b8e0c86833e7e65fb01665be54402c4fe42d31d9 100644 (file)
 */
 
 #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"
@@ -952,12 +947,6 @@ static void reply_spnego_auth(struct smb_request *req,
        return;
 }
 
-/****************************************************************************
- 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;
index bae77d5d4bb5c542c928aa98a70dce92ef6f48a6..62b0fe1617e932540177abd7d8b6e1a3690d18b7 100644 (file)
@@ -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 */
 
index 0c449f4ee96271684b53a2568997b7f8d58749dc..9644e3d1ad0d38d744d07a8f3ac2bcb1633d0b76 100644 (file)
 */
 
 #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;
 
index 82204e97e972c3ae7c1d64812c7f49244065ee3e..4f059bdb59894f9efd00ce94e3b9dc2a4f7c786d 100644 (file)
@@ -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;
index 011f31dd24c531d698ede308bea6ee90c1a040d7..df5a39eea2e064c2d2ce2f546f077930014df784 100644 (file)
@@ -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("");