s3:smbd: convert aio to use tevent_signal
[metze/samba/wip.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
23 #if defined(WITH_AIO)
24 struct aio_extra *aio_list_head = NULL;
25 struct tevent_signal *aio_signal_event = NULL;
26 int aio_pending_size = 0;
27 int outstanding_aio_calls = 0;
28 #endif
29
30 /* dlink list we store pending lock records on. */
31 struct blocking_lock_record *blocking_lock_queue = NULL;
32
33 /* dlink list we move cancelled lock records onto. */
34 struct blocking_lock_record *blocking_lock_cancelled_queue = NULL;
35
36 /* The event that makes us process our blocking lock queue */
37 struct timed_event *brl_timeout = NULL;
38
39 bool blocking_lock_unlock_state = false;
40 bool blocking_lock_cancel_state = false;
41
42 #ifdef USE_DMAPI
43 struct smbd_dmapi_context *dmapi_ctx = NULL;
44 #endif
45
46 connection_struct *Connections = NULL;
47 /* number of open connections */
48 struct bitmap *bmap = 0;
49 int num_open = 0;
50
51
52 bool dfree_broken = false;
53
54 struct bitmap *dptr_bmap = NULL;
55 struct dptr_struct *dirptrs = NULL;
56 int dirhandles_open = 0;
57
58 /* how many write cache buffers have been allocated */
59 unsigned int allocated_write_caches = 0;
60
61 int real_max_open_files = 0;
62 struct bitmap *file_bmap = NULL;
63 files_struct *Files = NULL;
64 int files_used = 0;
65 struct fsp_singleton_cache fsp_fi_cache = {
66         .fsp = NULL,
67         .id = {
68                 .devid = 0,
69                 .inode = 0
70         }
71 };
72 unsigned long file_gen_counter = 0;
73 int first_file = 0;
74
75 const struct mangle_fns *mangle_fns = NULL;
76
77 unsigned char *chartest = NULL;
78 TDB_CONTEXT *tdb_mangled_cache = NULL;
79
80 /* these tables are used to provide fast tests for characters */
81 unsigned char char_flags[256];
82 /*
83   this determines how many characters are used from the original filename
84   in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
85   The largest possible value is 6.
86 */
87 unsigned mangle_prefix = 0;
88 unsigned char base_reverse[256];
89
90 char *last_from = NULL;
91 char *last_to = NULL;
92
93 struct msg_state *smbd_msg_state = NULL;
94
95 bool global_encrypted_passwords_negotiated = false;
96 bool global_spnego_negotiated = false;
97 struct auth_context *negprot_global_auth_context = NULL;
98 bool done_negprot = false;
99
100 bool logged_ioctl_message = false;
101
102 /* users from session setup */
103 char *session_userlist = NULL;
104 /* workgroup from session setup. */
105 char *session_workgroup = NULL;
106 /* this holds info on user ids that are already validated for this VC */
107 user_struct *validated_users = NULL;
108 uint16_t next_vuid = VUID_OFFSET;
109 int num_validated_vuids = 0;
110 #ifdef HAVE_NETGROUP
111 char *my_yp_domain = NULL;
112 #endif
113
114 bool already_got_session = false;
115
116 /*
117  * Size of data we can send to client. Set
118  *  by the client for all protocols above CORE.
119  *  Set by us for CORE protocol.
120  */
121 int max_send = BUFFER_SIZE;
122 /*
123  * Size of the data we can receive. Set by us.
124  * Can be modified by the max xmit parameter.
125  */
126 int max_recv = BUFFER_SIZE;
127 uint16 last_session_tag = UID_FIELD_INVALID;
128 int trans_num = 0;
129 char *orig_inbuf = NULL;
130 pid_t mypid = 0;
131 time_t last_smb_conf_reload_time = 0;
132 time_t last_printer_reload_time = 0;
133 /****************************************************************************
134  structure to hold a linked list of queued messages.
135  for processing.
136 ****************************************************************************/
137 struct pending_message_list *deferred_open_queue = NULL;
138 uint32_t common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES;
139
140 struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx = NULL;
141 struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx = NULL;
142
143 /* A stack of security contexts.  We include the current context as being
144    the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
145 struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1];
146 int sec_ctx_stack_ndx = 0;
147 bool become_uid_done = false;
148 bool become_gid_done = false;
149
150 connection_struct *last_conn = NULL;
151 uint16_t last_flags = 0;
152
153 struct db_context *session_db_ctx_ptr = NULL;
154
155 uint32_t global_client_caps = 0;
156 bool done_sesssetup = false;
157 /****************************************************************************
158  List to store partial SPNEGO auth fragments.
159 ****************************************************************************/
160 struct pending_auth_data *pd_list = NULL;
161
162 uint16_t fnf_handle = 257;
163
164 /* A stack of current_user connection contexts. */
165 struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH];
166 int conn_ctx_stack_ndx = 0;
167
168 struct vfs_init_function_entry *backends = NULL;
169 char *sparse_buf = NULL;
170 char *LastDir = NULL;
171
172 #if HAVE_KERNEL_OPLOCKS_LINUX
173 SIG_ATOMIC_T oplock_signals_received = 0;
174 SIG_ATOMIC_T fd_pending_array[FD_PENDING_SIZE];
175 #endif
176
177 /* Current number of oplocks we have outstanding. */
178 int32_t exclusive_oplocks_open = 0;
179 int32_t level_II_oplocks_open = 0;
180 bool global_client_failed_oplock_break = false;
181 struct kernel_oplocks *koplocks = NULL;
182
183 struct notify_mid_map *notify_changes_by_mid = NULL;
184
185 int am_parent = 1;
186 int server_fd = -1;
187 struct event_context *smbd_event_ctx = NULL;
188 struct messaging_context *smbd_msg_ctx = NULL;
189 struct memcache *smbd_memcache_ctx = NULL;
190 bool exit_firsttime = true;
191 struct child_pid *children = 0;
192 int num_children = 0;
193
194 struct smbd_server_connection *smbd_server_conn = NULL;
195
196 void smbd_init_globals(void)
197 {
198         ZERO_STRUCT(char_flags);
199         ZERO_STRUCT(base_reverse);
200
201         ZERO_STRUCT(conn_ctx_stack);
202
203         ZERO_STRUCT(sec_ctx_stack);
204
205 #if HAVE_KERNEL_OPLOCKS_LINUX
206         ZERO_STRUCT(fd_pending_array);
207 #endif
208 }