2 * VFS module to alter the algorithm to calculate
3 * the struct file_id used as key for the share mode
4 * and byte range locking db's.
6 * Copyright (C) 2007, Stefan Metzmacher
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "smbd/smbd.h"
24 #include "smbd/globals.h"
25 #include "system/filesys.h"
26 #include "source3/include/msdfs.h"
27 #include "librpc/gen_ndr/ndr_dfsblobs.h"
28 #include "source4/lib/events/events.h"
29 #include "source4/auth/session.h"
30 #include "lib/param/param.h"
31 #include "source4/dsdb/samdb/samdb.h"
32 #include "dfs_server/dfs_server_ad.h"
34 static int vfs_dfs_samba4_debug_level
= DBGC_VFS
;
37 #define DBGC_CLASS vfs_dfs_samba4_debug_level
39 struct dfs_samba4_handle_data
{
40 struct tevent_context
*ev
;
41 struct loadparm_context
*lp_ctx
;
42 struct ldb_context
*sam_ctx
;
45 static int dfs_samba4_connect(struct vfs_handle_struct
*handle
,
46 const char *service
, const char *user
)
48 struct dfs_samba4_handle_data
*data
;
49 int ret
= SMB_VFS_NEXT_CONNECT(handle
, service
, user
);
55 data
= talloc_zero(handle
->conn
, struct dfs_samba4_handle_data
);
57 DEBUG(0, ("talloc_zero() failed\n"));
58 SMB_VFS_NEXT_DISCONNECT(handle
);
62 data
->ev
= s4_event_context_init(data
);
64 DEBUG(0, ("s4_event_context_init failed\n"));
65 SMB_VFS_NEXT_DISCONNECT(handle
);
69 data
->lp_ctx
= loadparm_init_s3(data
, loadparm_s3_helpers());
70 if (data
->lp_ctx
== NULL
) {
71 DEBUG(0, ("loadparm_init_s3 failed\n"));
72 SMB_VFS_NEXT_DISCONNECT(handle
);
76 data
->sam_ctx
= samdb_connect(data
,
79 system_session(data
->lp_ctx
),
83 DEBUG(0, ("samdb_connect failed\n"));
84 SMB_VFS_NEXT_DISCONNECT(handle
);
88 SMB_VFS_HANDLE_SET_DATA(handle
, data
, NULL
,
89 struct dfs_samba4_handle_data
,
92 DEBUG(10,("dfs_samba4: connect to service[%s]\n",
98 static void dfs_samba4_disconnect(struct vfs_handle_struct
*handle
)
100 const struct loadparm_substitution
*lp_sub
=
101 loadparm_s3_global_substitution();
103 DEBUG(10,("dfs_samba4_disconnect() connect to service[%s].\n",
104 lp_servicename(talloc_tos(), lp_sub
, SNUM(handle
->conn
))));
106 SMB_VFS_NEXT_DISCONNECT(handle
);
109 static NTSTATUS
dfs_samba4_get_referrals(struct vfs_handle_struct
*handle
,
110 struct dfs_GetDFSReferral
*r
)
112 struct dfs_samba4_handle_data
*data
;
115 SMB_VFS_HANDLE_GET_DATA(handle
, data
,
116 struct dfs_samba4_handle_data
,
117 return NT_STATUS_INTERNAL_ERROR
);
119 DEBUG(8, ("dfs_samba4: Requested DFS name: %s utf16-length: %u\n",
120 r
->in
.req
.servername
,
121 (unsigned int)strlen_m(r
->in
.req
.servername
)*2));
123 status
= dfs_server_ad_get_referrals(data
->lp_ctx
,
125 handle
->conn
->sconn
->remote_address
,
127 if (NT_STATUS_EQUAL(status
, NT_STATUS_NOT_FOUND
)) {
128 return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle
, r
);
130 if (!NT_STATUS_IS_OK(status
)) {
137 static struct vfs_fn_pointers vfs_dfs_samba4_fns
= {
138 .connect_fn
= dfs_samba4_connect
,
139 .disconnect_fn
= dfs_samba4_disconnect
,
140 .get_dfs_referrals_fn
= dfs_samba4_get_referrals
,
144 NTSTATUS
vfs_dfs_samba4_init(TALLOC_CTX
*ctx
)
148 ret
= smb_register_vfs(SMB_VFS_INTERFACE_VERSION
, "dfs_samba4",
149 &vfs_dfs_samba4_fns
);
150 if (!NT_STATUS_IS_OK(ret
)) {
154 vfs_dfs_samba4_debug_level
= debug_add_class("dfs_samba4");
155 if (vfs_dfs_samba4_debug_level
== -1) {
156 vfs_dfs_samba4_debug_level
= DBGC_VFS
;
157 DEBUG(0, ("vfs_dfs_samba4: Couldn't register custom debugging class!\n"));
159 DEBUG(10, ("vfs_dfs_samba4: Debug class number of 'fileid': %d\n",
160 vfs_dfs_samba4_debug_level
));