*/
#include "includes.h"
+#include "smbd/smbd.h"
#include "smbd/globals.h"
+#include "lib/smbd_shim.h"
+#include "memcache.h"
+#include "messages.h"
+#include "tdb_compat.h"
#if defined(WITH_AIO)
struct aio_extra *aio_list_head = NULL;
+struct tevent_signal *aio_signal_event = 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;
-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;
+pid_t background_lpq_updater_pid = -1;
+
/****************************************************************************
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;
+uint32_t common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES|FLAGS2_EXTENDED_ATTRIBUTES;
-struct smb_srv_trans_enc_ctx *partial_srv_trans_enc_ctx = NULL;
-struct smb_srv_trans_enc_ctx *srv_trans_enc_ctx = NULL;
+struct smb_trans_enc_state *partial_srv_trans_enc_ctx = NULL;
+struct smb_trans_enc_state *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. */
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;
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];
-#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;
struct kernel_oplocks *koplocks = NULL;
-struct notify_mid_map *notify_changes_by_mid = NULL;
-
int am_parent = 1;
-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;
struct smbd_server_connection *smbd_server_conn = NULL;
+struct smbd_server_connection *msg_ctx_to_sconn(struct messaging_context *msg_ctx)
+{
+ struct server_id my_id, msg_id;
+
+ my_id = messaging_server_id(smbd_server_conn->msg_ctx);
+ msg_id = messaging_server_id(msg_ctx);
+
+ if (!procid_equal(&my_id, &msg_id)) {
+ return NULL;
+ }
+ return smbd_server_conn;
+}
+
+struct messaging_context *smbd_messaging_context(void)
+{
+ struct messaging_context *msg_ctx = server_messaging_context();
+ if (likely(msg_ctx != NULL)) {
+ return msg_ctx;
+ }
+ smb_panic("Could not init smbd's messaging context.\n");
+ return NULL;
+}
+
+struct memcache *smbd_memcache(void)
+{
+ if (!smbd_memcache_ctx) {
+ /*
+ * Note we MUST use the NULL context here, not the
+ * autofree context, to avoid side effects in forked
+ * children exiting.
+ */
+ smbd_memcache_ctx = memcache_init(NULL,
+ lp_max_stat_cache_size()*1024);
+ }
+ if (!smbd_memcache_ctx) {
+ smb_panic("Could not init smbd memcache");
+ }
+
+ return smbd_memcache_ctx;
+}
+
+static const struct smbd_shim smbd_shim_fns =
+{
+ .cancel_pending_lock_requests_by_fid = smbd_cancel_pending_lock_requests_by_fid,
+ .send_stat_cache_delete_message = smbd_send_stat_cache_delete_message,
+ .can_delete_directory = smbd_can_delete_directory,
+ .change_to_root_user = smbd_change_to_root_user,
+
+ .contend_level2_oplocks_begin = smbd_contend_level2_oplocks_begin,
+ .contend_level2_oplocks_end = smbd_contend_level2_oplocks_end,
+
+ .become_root = smbd_become_root,
+ .unbecome_root = smbd_unbecome_root
+};
+
void smbd_init_globals(void)
{
- ZERO_STRUCT(char_flags);
- ZERO_STRUCT(base_reverse);
+ set_smbd_shim(&smbd_shim_fns);
ZERO_STRUCT(conn_ctx_stack);
ZERO_STRUCT(sec_ctx_stack);
-#if HAVE_KERNEL_OPLOCKS_LINUX
- ZERO_STRUCT(fd_pending_array);
-#endif
+ smbd_server_conn = talloc_zero(server_event_context(), struct smbd_server_connection);
+ if (!smbd_server_conn) {
+ exit_server("failed to create smbd_server_connection");
+ }
+
+ smbd_server_conn->smb1.echo_handler.trusted_fd = -1;
+ smbd_server_conn->smb1.echo_handler.socket_lock_fd = -1;
}