selftest:Samba4: report when samba is started and ready
[Samba.git] / source3 / modules / vfs_dfs_samba4.c
blob1c7b50e99c6441d0c93b8776fe8b9b5566a25174
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),
80 NULL,
81 0);
82 if (!data->sam_ctx) {
83 DEBUG(0, ("samdb_connect failed\n"));
84 SMB_VFS_NEXT_DISCONNECT(handle);
85 return -1;
88 SMB_VFS_HANDLE_SET_DATA(handle, data, NULL,
89 struct dfs_samba4_handle_data,
90 return -1);
92 DEBUG(10,("dfs_samba4: connect to service[%s]\n",
93 service));
95 return 0;
98 static void dfs_samba4_disconnect(struct vfs_handle_struct *handle)
100 DEBUG(10,("dfs_samba4_disconnect() connect to service[%s].\n",
101 lp_servicename(talloc_tos(), SNUM(handle->conn))));
103 SMB_VFS_NEXT_DISCONNECT(handle);
106 static NTSTATUS dfs_samba4_get_referrals(struct vfs_handle_struct *handle,
107 struct dfs_GetDFSReferral *r)
109 struct dfs_samba4_handle_data *data;
110 NTSTATUS status;
112 SMB_VFS_HANDLE_GET_DATA(handle, data,
113 struct dfs_samba4_handle_data,
114 return NT_STATUS_INTERNAL_ERROR);
116 DEBUG(8, ("dfs_samba4: Requested DFS name: %s utf16-length: %u\n",
117 r->in.req.servername,
118 (unsigned int)strlen_m(r->in.req.servername)*2));
120 status = dfs_server_ad_get_referrals(data->lp_ctx,
121 data->sam_ctx,
122 handle->conn->sconn->remote_address,
124 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_FOUND)) {
125 return SMB_VFS_NEXT_GET_DFS_REFERRALS(handle, r);
127 if (!NT_STATUS_IS_OK(status)) {
128 return status;
131 return NT_STATUS_OK;
134 static struct vfs_fn_pointers vfs_dfs_samba4_fns = {
135 .connect_fn = dfs_samba4_connect,
136 .disconnect_fn = dfs_samba4_disconnect,
137 .get_dfs_referrals_fn = dfs_samba4_get_referrals,
140 static_decl_vfs;
141 NTSTATUS vfs_dfs_samba4_init(TALLOC_CTX *ctx)
143 NTSTATUS ret;
145 ret = smb_register_vfs(SMB_VFS_INTERFACE_VERSION, "dfs_samba4",
146 &vfs_dfs_samba4_fns);
147 if (!NT_STATUS_IS_OK(ret)) {
148 return ret;
151 vfs_dfs_samba4_debug_level = debug_add_class("dfs_samba4");
152 if (vfs_dfs_samba4_debug_level == -1) {
153 vfs_dfs_samba4_debug_level = DBGC_VFS;
154 DEBUG(0, ("vfs_dfs_samba4: Couldn't register custom debugging class!\n"));
155 } else {
156 DEBUG(10, ("vfs_dfs_samba4: Debug class number of 'fileid': %d\n",
157 vfs_dfs_samba4_debug_level));
160 return ret;