summaryrefslogtreecommitdiff
path: root/source3/smbd/globals.c
blob: 80f6a6642773f50c22c7bee14288defaaada68d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
/*
   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/smbd.h"
#include "smbd/globals.h"
#include "lib/smbd_shim.h"
#include "memcache.h"
#include "messages.h"
#include "tdb_compat.h"

int aio_pending_size = 100;	/* tevent supports 100 signals SA_SIGINFO */
int outstanding_aio_calls = 0;

#ifdef USE_DMAPI
struct smbd_dmapi_context *dmapi_ctx = NULL;
#endif


bool dfree_broken = false;

/* how many write cache buffers have been allocated */
unsigned int allocated_write_caches = 0;

const struct mangle_fns *mangle_fns = NULL;

unsigned char *chartest = NULL;
TDB_CONTEXT *tdb_mangled_cache = NULL;

/*
  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;

bool logged_ioctl_message = false;

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.
****************************************************************************/
uint32_t common_flags2 = FLAGS2_LONG_PATH_COMPONENTS|FLAGS2_32_BIT_ERROR_CODES|FLAGS2_EXTENDED_ATTRIBUTES;

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. */
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;

uint32_t global_client_caps = 0;

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;

struct smbd_parent_context *am_parent = NULL;
struct memcache *smbd_memcache_ctx = NULL;
bool exit_firsttime = true;

struct smbXsrv_connection *global_smbXsrv_connection = 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,
	.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)
{
	set_smbd_shim(&smbd_shim_fns);

	ZERO_STRUCT(conn_ctx_stack);

	ZERO_STRUCT(sec_ctx_stack);
}