s3:net_idmap_dump add missing braces
[Samba/gebeck_regimport.git] / source3 / modules / vfs_dfs_samba4.c
blobe77a993331734442fcb750dd6129bf1b54182969
1 /*
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/>.
22 #include "includes.h"
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;
36 #undef DBGC_CLASS
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);
51 if (ret < 0) {
52 return ret;
55 data = talloc_zero(handle->conn, struct dfs_samba4_handle_data);
56 if (!data) {
57 DEBUG(0, ("talloc_zero() failed\n"));
58 SMB_VFS_NEXT_DISCONNECT(handle);
59 return -1;
62 data->ev = s4_event_context_init(data);
63 if (!data->ev) {
64 DEBUG(0, ("s4_event_context_init failed\n"));
65 SMB_VFS_NEXT_DISCONNECT(handle);
66 return -1;
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);
73 return -1;
76 data->sam_ctx = samdb_connect(data,
77 data->ev,
78 data->lp_ctx,
79 system_session(data->lp_ctx), 0);
80 if (!data->sam_ctx) {
81 DEBUG(0, ("samdb_connect failed\n"));
82 SMB_VFS_NEXT_DISCONNECT(handle);
83 return -1;
86 SMB_VFS_HANDLE_SET_DATA(handle, data, NULL,
87 struct dfs_samba4_handle_data,
88 return -1);
90 DEBUG(10,("dfs_samba4: connect to service[%s]\n",
91 service));
93 return 0;
96 static void dfs_samba4_disconnect(struct vfs_handle_struct *handle)
98 DEBUG(10,("dfs_samba4_disconnect() connect to service[%s].\n",
99 lp_servicename(talloc_tos(), SNUM(handle->conn))));
101 SMB_VFS_NEXT_DISCONNECT(handle);
104 static NTSTATUS dfs_samba4_get_referrals(struct vfs_handle_struct *handle,
105 struct dfs_GetDFSReferral *r)
107 struct dfs_samba4_handle_data *data;
108 NTSTATUS status;
110 SMB_VFS_HANDLE_GET_DATA(handle, data,
111 struct dfs_samba4_handle_data,
112 return NT_STATUS_INTERNAL_ERROR);
114 DEBUG(8, ("dfs_samba4: Requested DFS name: %s utf16-length: %u\n",
115 r->in.req.servername,
116 (unsigned int)strlen_m(r->in.req.servername)*2));
118 status = dfs_server_ad_get_referrals(data->lp_ctx,
119 data->sam_ctx,
120 handle->conn->sconn->remote_address,
122 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
123 return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
125 if (!NT_STATUS_IS_OK(status)) {
126 return status;
129 return NT_STATUS_OK;
132 static struct vfs_fn_pointers vfs_dfs_samba4_fns = {
133 .connect_fn = dfs_samba4_connect,
134 .disconnect_fn = dfs_samba4_disconnect,
135 .get_dfs_referrals_fn = dfs_samba4_get_referrals,
138 NTSTATUS vfs_dfs_samba4_init(void);
139 NTSTATUS vfs_dfs_samba4_init(void)
141 NTSTATUS ret;
143 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "dfs_samba4",
144 &vfs_dfs_samba4_fns);
145 if (!NT_STATUS_IS_OK(ret)) {
146 return ret;
149 vfs_dfs_samba4_debug_level = debug_add_class("dfs_samba4");
150 if (vfs_dfs_samba4_debug_level == -1) {
151 vfs_dfs_samba4_debug_level = DBGC_VFS;
152 DEBUG(0, ("vfs_dfs_samba4: Couldn't register custom debugging class!\n"));
153 } else {
154 DEBUG(10, ("vfs_dfs_samba4: Debug class number of 'fileid': %d\n",
155 vfs_dfs_samba4_debug_level));
158 return ret;