b1a0d7eb19bfddba98e638a29bbe2bb36f411cc1
[samba.git] / source3 / smbd / globals.c
1 /*
2    Unix SMB/Netbios implementation.
3    smbd globals
4    Copyright (C) Stefan Metzmacher 2009
5
6    This program is free software; you can redistribute it and/or modify
7    it under the terms of the GNU General Public License as published by
8    the Free Software Foundation; either version 3 of the License, or
9    (at your option) any later version.
10
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15
16    You should have received a copy of the GNU General Public License
17    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "includes.h"
21 #include "smbd/globals.h"
22 #include "memcache.h"
23
24 #if defined(WITH_AIO)
25 struct aio_extra *aio_list_head = NULL;
26 struct tevent_signal *aio_signal_event = NULL;
27 int aio_pending_size = 0;
28 int outstanding_aio_calls = 0;
29 #endif
30
31 #ifdef USE_DMAPI
32 struct smbd_dmapi_context *dmapi_ctx = NULL;
33 #endif
34
35
36 bool dfree_broken = false;
37
38 /* how many write cache buffers have been allocated */
39 unsigned int allocated_write_caches = 0;
40
41 const struct mangle_fns *mangle_fns = NULL;
42
43 unsigned char *chartest = NULL;
44 TDB_CONTEXT *tdb_mangled_cache = NULL;
45
46 /*
47   this determines how many characters are used from the original filename
48   in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
49   The largest possible value is 6.
50 */
51 unsigned mangle_prefix = 0;
52
53 struct msg_state *smbd_msg_state = NULL;
54
55 bool logged_ioctl_message = false;
56
57 time_t last_smb_conf_reload_time = 0;
58 time_t last_printer_reload_time = 0;
59 /****************************************************************************
60  structure to hold a linked list of queued messages.
61  for processing.
62 ****************************************************************************/
63 struct pending_message_list *deferred_open_queue = NULL;
64 uint32_t common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES|FLAGS2_EXTENDED_ATTRIBUTES;
65
66 struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx = NULL;
67 struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx = NULL;
68
69 /* A stack of security contexts.  We include the current context as being
70    the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
71 struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1];
72 int sec_ctx_stack_ndx = 0;
73 bool become_uid_done = false;
74 bool become_gid_done = false;
75
76 connection_struct *last_conn = NULL;
77 uint16_t last_flags = 0;
78
79 uint32_t global_client_caps = 0;
80
81 uint16_t fnf_handle = 257;
82
83 /* A stack of current_user connection contexts. */
84 struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH];
85 int conn_ctx_stack_ndx = 0;
86
87 struct vfs_init_function_entry *backends = NULL;
88 char *sparse_buf = NULL;
89 char *LastDir = NULL;
90
91 /* Current number of oplocks we have outstanding. */
92 int32_t exclusive_oplocks_open = 0;
93 int32_t level_II_oplocks_open = 0;
94 struct kernel_oplocks *koplocks = NULL;
95
96 int am_parent = 1;
97 struct memcache *smbd_memcache_ctx = NULL;
98 bool exit_firsttime = true;
99 struct child_pid *children = 0;
100 int num_children = 0;
101
102 struct smbd_server_connection *smbd_server_conn = NULL;
103
104 struct smbd_server_connection *msg_ctx_to_sconn(struct messaging_context *msg_ctx)
105 {
106         struct server_id my_id, msg_id;
107
108         my_id = messaging_server_id(smbd_server_conn->msg_ctx);
109         msg_id = messaging_server_id(msg_ctx);
110
111         if (!procid_equal(&my_id, &msg_id)) {
112                 return NULL;
113         }
114         return smbd_server_conn;
115 }
116
117 struct messaging_context *smbd_messaging_context(void)
118 {
119         struct messaging_context *msg_ctx = server_messaging_context();
120         if (likely(msg_ctx != NULL)) {
121                 return msg_ctx;
122         }
123         smb_panic("Could not init smbd's messaging context.\n");
124         return NULL;
125 }
126
127 struct memcache *smbd_memcache(void)
128 {
129         if (!smbd_memcache_ctx) {
130                 /*
131                  * Note we MUST use the NULL context here, not the
132                  * autofree context, to avoid side effects in forked
133                  * children exiting.
134                  */
135                 smbd_memcache_ctx = memcache_init(NULL,
136                                                   lp_max_stat_cache_size()*1024);
137         }
138         if (!smbd_memcache_ctx) {
139                 smb_panic("Could not init smbd memcache");
140         }
141
142         return smbd_memcache_ctx;
143 }
144
145
146 void smbd_init_globals(void)
147 {
148         ZERO_STRUCT(conn_ctx_stack);
149
150         ZERO_STRUCT(sec_ctx_stack);
151
152         smbd_server_conn = talloc_zero(smbd_event_context(), struct smbd_server_connection);
153         if (!smbd_server_conn) {
154                 exit_server("failed to create smbd_server_connection");
155         }
156
157         smbd_server_conn->smb1.echo_handler.trusted_fd = -1;
158         smbd_server_conn->smb1.echo_handler.socket_lock_fd = -1;
159 }