2 Unix SMB/Netbios implementation.
4 Copyright (C) Stefan Metzmacher 2009
5 Copyright (C) Jeremy Allison 2010
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 extern struct aio_extra *aio_list_head;
24 extern struct tevent_signal *aio_signal_event;
25 extern int aio_pending_size;
26 extern int outstanding_aio_calls;
29 /* dlink list we store pending lock records on. */
30 extern struct blocking_lock_record *blocking_lock_queue;
32 /* dlink list we move cancelled lock records onto. */
33 extern struct blocking_lock_record *blocking_lock_cancelled_queue;
35 /* The event that makes us process our blocking lock queue */
36 extern struct timed_event *brl_timeout;
38 extern bool blocking_lock_unlock_state;
39 extern bool blocking_lock_cancel_state;
42 struct smbd_dmapi_context;
43 extern struct smbd_dmapi_context *dmapi_ctx;
46 extern bool dfree_broken;
48 /* how many write cache buffers have been allocated */
49 extern unsigned int allocated_write_caches;
51 extern int real_max_open_files;
52 extern struct bitmap *file_bmap;
53 extern files_struct *Files;
54 extern int files_used;
55 /* A singleton cache to speed up searching by dev/inode. */
56 struct fsp_singleton_cache {
60 extern struct fsp_singleton_cache fsp_fi_cache;
61 extern unsigned long file_gen_counter;
62 extern int first_file;
64 extern const struct mangle_fns *mangle_fns;
66 extern unsigned char *chartest;
67 extern TDB_CONTEXT *tdb_mangled_cache;
69 /* these tables are used to provide fast tests for characters */
70 extern unsigned char char_flags[256];
72 this determines how many characters are used from the original filename
73 in the 8.3 mangled name. A larger value leads to a weaker hash and more collisions.
74 The largest possible value is 6.
76 extern unsigned mangle_prefix;
77 extern unsigned char base_reverse[256];
79 extern char *last_from;
83 extern struct msg_state *smbd_msg_state;
85 extern bool logged_ioctl_message;
90 extern time_t last_smb_conf_reload_time;
91 extern time_t last_printer_reload_time;
92 /****************************************************************************
93 structure to hold a linked list of queued messages.
95 ****************************************************************************/
96 struct pending_message_list;
97 extern struct pending_message_list *deferred_open_queue;
98 extern uint32_t common_flags2;
100 struct smb_srv_trans_enc_ctx;
101 extern struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx;
102 extern struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx;
106 NT_USER_TOKEN *token;
108 /* A stack of security contexts. We include the current context as being
109 the first one, so there is room for another MAX_SEC_CTX_DEPTH more. */
110 extern struct sec_ctx sec_ctx_stack[MAX_SEC_CTX_DEPTH + 1];
111 extern int sec_ctx_stack_ndx;
112 extern bool become_uid_done;
113 extern bool become_gid_done;
115 extern connection_struct *last_conn;
116 extern uint16_t last_flags;
118 extern uint32_t global_client_caps;
120 extern uint16_t fnf_handle;
123 connection_struct *conn;
126 /* A stack of current_user connection contexts. */
127 extern struct conn_ctx conn_ctx_stack[MAX_SEC_CTX_DEPTH];
128 extern int conn_ctx_stack_ndx;
130 struct vfs_init_function_entry;
131 extern struct vfs_init_function_entry *backends;
132 extern char *sparse_buf;
134 /* Current number of oplocks we have outstanding. */
135 extern int32_t exclusive_oplocks_open;
136 extern int32_t level_II_oplocks_open;
137 extern bool global_client_failed_oplock_break;
138 extern struct kernel_oplocks *koplocks;
140 extern int am_parent;
141 extern int server_fd;
142 extern struct event_context *smbd_event_ctx;
143 extern struct messaging_context *smbd_msg_ctx;
144 extern struct memcache *smbd_memcache_ctx;
145 extern bool exit_firsttime;
147 extern struct child_pid *children;
148 extern int num_children;
150 struct tstream_context;
151 struct smbd_smb2_request;
152 struct smbd_smb2_session;
153 struct smbd_smb2_tcon;
155 DATA_BLOB negprot_spnego(void);
157 void smbd_lock_socket(struct smbd_server_connection *sconn);
158 void smbd_unlock_socket(struct smbd_server_connection *sconn);
160 NTSTATUS smb2_signing_sign_pdu(DATA_BLOB session_key,
161 struct iovec *vector,
163 NTSTATUS smb2_signing_check_pdu(DATA_BLOB session_key,
164 const struct iovec *vector,
167 struct smbd_lock_element {
169 enum brl_type brltype;
174 NTSTATUS smbd_do_locking(struct smb_request *req,
179 struct smbd_lock_element *ulocks,
181 struct smbd_lock_element *locks,
184 NTSTATUS smbd_do_qfilepathinfo(connection_struct *conn,
188 struct smb_filename *smb_fname,
190 struct timespec write_time_ts,
191 struct ea_list *ea_list,
195 unsigned int max_data_bytes,
197 unsigned int *pdata_size);
199 NTSTATUS smbd_do_setfilepathinfo(connection_struct *conn,
200 struct smb_request *req,
204 struct smb_filename *smb_fname,
205 char **ppdata, int total_data,
208 NTSTATUS smbd_do_qfsinfo(connection_struct *conn,
212 unsigned int max_data_bytes,
216 bool smbd_dirptr_get_entry(TALLOC_CTX *ctx,
217 struct dptr_struct *dirptr,
222 bool (*match_fn)(TALLOC_CTX *ctx,
227 bool (*mode_fn)(TALLOC_CTX *ctx,
229 struct smb_filename *smb_fname,
233 struct smb_filename **_smb_fname,
237 bool smbd_dirptr_lanman2_entry(TALLOC_CTX *ctx,
238 connection_struct *conn,
239 struct dptr_struct *dirptr,
241 const char *path_mask,
244 int requires_resume_key,
254 bool *got_exact_match,
255 int *_last_entry_off,
256 struct ea_list *name_list);
258 NTSTATUS smbd_check_open_rights(struct connection_struct *conn,
259 const struct smb_filename *smb_fname,
260 uint32_t access_mask,
261 uint32_t *access_granted);
263 void smbd_notify_cancel_by_smbreq(struct smbd_server_connection *sconn,
264 const struct smb_request *smbreq);
266 void smbd_server_connection_terminate_ex(struct smbd_server_connection *sconn,
268 const char *location);
269 #define smbd_server_connection_terminate(sconn, reason) \
270 smbd_server_connection_terminate_ex(sconn, reason, __location__)
272 bool smbd_is_smb2_header(const uint8_t *inbuf, size_t size);
274 void reply_smb2002(struct smb_request *req, uint16_t choice);
275 void smbd_smb2_first_negprot(struct smbd_server_connection *sconn,
276 const uint8_t *inbuf, size_t size);
278 NTSTATUS smbd_smb2_request_error_ex(struct smbd_smb2_request *req,
281 const char *location);
282 #define smbd_smb2_request_error(req, status) \
283 smbd_smb2_request_error_ex(req, status, NULL, __location__)
284 NTSTATUS smbd_smb2_request_done_ex(struct smbd_smb2_request *req,
286 DATA_BLOB body, DATA_BLOB *dyn,
287 const char *location);
288 #define smbd_smb2_request_done(req, body, dyn) \
289 smbd_smb2_request_done_ex(req, NT_STATUS_OK, body, dyn, __location__)
291 NTSTATUS smbd_smb2_send_oplock_break(struct smbd_server_connection *sconn,
292 uint64_t file_id_volatile,
293 uint8_t oplock_level);
295 NTSTATUS smbd_smb2_request_pending_queue(struct smbd_smb2_request *req,
296 struct tevent_req *subreq);
298 NTSTATUS smbd_smb2_request_check_session(struct smbd_smb2_request *req);
299 NTSTATUS smbd_smb2_request_check_tcon(struct smbd_smb2_request *req);
301 struct smb_request *smbd_smb2_fake_smb_request(struct smbd_smb2_request *req);
303 NTSTATUS smbd_smb2_request_process_negprot(struct smbd_smb2_request *req);
304 NTSTATUS smbd_smb2_request_process_sesssetup(struct smbd_smb2_request *req);
305 NTSTATUS smbd_smb2_request_process_logoff(struct smbd_smb2_request *req);
306 NTSTATUS smbd_smb2_request_process_tcon(struct smbd_smb2_request *req);
307 NTSTATUS smbd_smb2_request_process_tdis(struct smbd_smb2_request *req);
308 NTSTATUS smbd_smb2_request_process_create(struct smbd_smb2_request *req);
309 NTSTATUS smbd_smb2_request_process_close(struct smbd_smb2_request *req);
310 NTSTATUS smbd_smb2_request_process_flush(struct smbd_smb2_request *req);
311 NTSTATUS smbd_smb2_request_process_read(struct smbd_smb2_request *req);
312 NTSTATUS smbd_smb2_request_process_write(struct smbd_smb2_request *req);
313 NTSTATUS smbd_smb2_request_process_lock(struct smbd_smb2_request *req);
314 NTSTATUS smbd_smb2_request_process_ioctl(struct smbd_smb2_request *req);
315 NTSTATUS smbd_smb2_request_process_keepalive(struct smbd_smb2_request *req);
316 NTSTATUS smbd_smb2_request_process_find(struct smbd_smb2_request *req);
317 NTSTATUS smbd_smb2_request_process_notify(struct smbd_smb2_request *req);
318 NTSTATUS smbd_smb2_request_process_getinfo(struct smbd_smb2_request *req);
319 NTSTATUS smbd_smb2_request_process_setinfo(struct smbd_smb2_request *req);
320 NTSTATUS smbd_smb2_request_process_break(struct smbd_smb2_request *req);
321 NTSTATUS smbd_smb2_request_dispatch(struct smbd_smb2_request *req);
322 void smbd_smb2_request_dispatch_immediate(struct tevent_context *ctx,
323 struct tevent_immediate *im,
326 /* SMB1 -> SMB2 glue. */
327 void send_break_message_smb2(files_struct *fsp, int level);
328 bool push_blocking_lock_request_smb2( struct byte_range_lock *br_lck,
329 struct smb_request *req,
334 enum brl_type lock_type,
335 enum brl_flavour lock_flav,
338 uint32_t blocking_pid);
339 /* From smbd/smb2_create.c */
340 int map_smb2_oplock_levels_to_samba(uint8_t in_oplock_level);
341 uint8_t map_samba_oplock_levels_to_smb2(int oplock_type);
342 bool get_deferred_open_message_state_smb2(struct smbd_smb2_request *smb2req,
343 struct timeval *p_request_time,
345 bool open_was_deferred_smb2(uint64_t mid);
346 void remove_deferred_open_message_smb2(uint64_t mid);
347 void schedule_deferred_open_message_smb2(uint64_t mid);
348 bool push_deferred_open_message_smb2(struct smbd_smb2_request *smb2req,
349 struct timeval request_time,
350 struct timeval timeout,
355 struct smbd_smb2_request {
356 struct smbd_smb2_request *prev, *next;
358 TALLOC_CTX *mem_pool;
359 struct smbd_smb2_request **parent;
361 struct smbd_server_connection *sconn;
363 /* the session the request operates on, maybe NULL */
364 struct smbd_smb2_session *session;
366 /* the tcon the request operates on, maybe NULL */
367 struct smbd_smb2_tcon *tcon;
374 struct files_struct *compat_chain_fsp;
376 NTSTATUS next_status;
379 * The sub request for async backend calls.
380 * This is used for SMB2 Cancel.
382 struct tevent_req *subreq;
385 /* the NBT header is not allocated */
391 * vector[2] fixed body
392 * vector[3] dynamic body
397 * vector[5] fixed body
398 * vector[6] dynamic body
403 struct iovec *vector;
407 /* the NBT header is not allocated */
413 * vector[2] fixed body
414 * vector[3] dynamic body
419 * vector[5] fixed body
420 * vector[6] dynamic body
425 struct iovec *vector;
430 struct smbd_server_connection;
432 struct smbd_smb2_session {
433 struct smbd_smb2_session *prev, *next;
434 struct smbd_server_connection *sconn;
437 AUTH_NTLMSSP_STATE *auth_ntlmssp_state;
438 struct auth_serversupplied_info *server_info;
439 DATA_BLOB session_key;
442 user_struct *compat_vuser;
445 /* an id tree used to allocate tids */
446 struct idr_context *idtree;
448 /* this is the limit of tid values for this connection */
451 struct smbd_smb2_tcon *list;
455 struct smbd_smb2_tcon {
456 struct smbd_smb2_tcon *prev, *next;
457 struct smbd_smb2_session *session;
460 connection_struct *compat_conn;
463 struct pending_auth_data;
465 struct smbd_server_connection {
466 const struct tsocket_address *local_address;
467 const struct tsocket_address *remote_address;
473 struct fd_event *fde;
477 * fd for the fcntl lock mutexing access to smbd_server_fd
482 * fd for the trusted pipe from
488 * fde for the trusted_fd
490 struct fd_event *trusted_fde;
493 * Reference count for the fcntl lock to
494 * allow recursive locks.
499 uint64_t num_requests;
501 bool encrypted_passwords;
503 struct auth_context *auth_context;
506 * Size of the data we can receive. Set by us.
507 * Can be modified by the max xmit parameter.
515 * Size of data we can send to client. Set
516 * by the client for all protocols above CORE.
517 * Set by us for CORE protocol.
520 uint16_t last_session_tag;
522 /* users from session setup */
523 char *session_userlist;
524 /* workgroup from session setup. */
525 char *session_workgroup;
527 * this holds info on user ids that are already
528 * validated for this VC
530 user_struct *validated_users;
532 int num_validated_vuids;
538 connection_struct *Connections;
539 /* number of open connections */
543 struct smb_signing_state *signing_state;
544 /* List to store partial SPNEGO auth fragments. */
545 struct pending_auth_data *pd_list;
547 struct notify_mid_map *notify_mid_maps;
550 struct bitmap *dptr_bmap;
551 struct dptr_struct *dirptrs;
556 struct tevent_context *event_ctx;
557 struct tevent_queue *recv_queue;
558 struct tevent_queue *send_queue;
559 struct tstream_context *stream;
561 /* an id tree used to allocate vuids */
562 /* this holds info on session vuids that are already
563 * validated for this VC */
564 struct idr_context *idtree;
566 /* this is the limit of vuid values for this connection */
569 struct smbd_smb2_session *list;
571 struct smbd_smb2_request *requests;
575 extern struct smbd_server_connection *smbd_server_conn;
577 void smbd_init_globals(void);