s4:drsuapi: make use of LDB_TYPESAFE_QSORT() and pass getnc_state
[Samba/gebeck_regimport.git] / source4 / rpc_server / srvsvc / srvsvc_ntvfs.c
blob49beb50d869d5e053b59542b29bfd5325806419d
1 /*
2 Unix SMB/CIFS implementation.
4 srvsvc pipe ntvfs helper functions
6 Copyright (C) Stefan (metze) Metzmacher 2006
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/>.
21 #include "includes.h"
22 #include "ntvfs/ntvfs.h"
23 #include "rpc_server/dcerpc_server.h"
24 #include "param/param.h"
25 #include "rpc_server/srvsvc/proto.h"
27 struct srvsvc_ntvfs_ctx {
28 struct ntvfs_context *ntvfs;
31 static int srvsvc_ntvfs_ctx_destructor(struct srvsvc_ntvfs_ctx *c)
33 ntvfs_disconnect(c->ntvfs);
34 return 0;
37 NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
38 TALLOC_CTX *mem_ctx,
39 const char *share,
40 struct ntvfs_context **_ntvfs)
42 NTSTATUS status;
43 struct srvsvc_ntvfs_ctx *c;
44 struct ntvfs_request *ntvfs_req;
45 enum ntvfs_type type;
46 struct share_context *sctx;
47 struct share_config *scfg;
48 const char *sharetype;
49 union smb_tcon tcon;
50 const struct tsocket_address *local_address;
51 const struct tsocket_address *remote_address;
53 status = share_get_context_by_name(mem_ctx, lpcfg_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, &sctx);
54 if (!NT_STATUS_IS_OK(status)) {
55 return status;
58 status = share_get_config(mem_ctx, sctx, share, &scfg);
59 if (!NT_STATUS_IS_OK(status)) {
60 DEBUG(0,("srvsvc_create_ntvfs_context: couldn't find service %s\n", share));
61 return status;
64 #if 0 /* TODO: fix access cecking */
65 if (!socket_check_access(dce_call->connection->socket,
66 scfg->name,
67 share_string_list_option(scfg, SHARE_HOSTS_ALLOW),
68 share_string_list_option(scfg, SHARE_HOSTS_DENY))) {
69 return NT_STATUS_ACCESS_DENIED;
71 #endif
73 /* work out what sort of connection this is */
74 sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
75 if (sharetype && strcmp(sharetype, "IPC") == 0) {
76 type = NTVFS_IPC;
77 } else if (sharetype && strcmp(sharetype, "PRINTER")) {
78 type = NTVFS_PRINT;
79 } else {
80 type = NTVFS_DISK;
83 c = talloc(mem_ctx, struct srvsvc_ntvfs_ctx);
84 NT_STATUS_HAVE_NO_MEMORY(c);
86 /* init ntvfs function pointers */
87 status = ntvfs_init_connection(c, scfg, type,
88 PROTOCOL_NT1,
89 0,/* ntvfs_client_caps */
90 dce_call->event_ctx,
91 dce_call->conn->msg_ctx,
92 dce_call->conn->dce_ctx->lp_ctx,
93 dce_call->conn->server_id,
94 &c->ntvfs);
95 if (!NT_STATUS_IS_OK(status)) {
96 DEBUG(0, ("srvsvc_create_ntvfs_context: ntvfs_init_connection failed for service %s\n",
97 scfg->name));
98 return status;
100 talloc_set_destructor(c, srvsvc_ntvfs_ctx_destructor);
103 * NOTE: we only set the addr callbacks as we're not interesseted in oplocks or in getting file handles
105 local_address = dcesrv_connection_get_local_address(dce_call->conn);
106 remote_address = dcesrv_connection_get_remote_address(dce_call->conn);
107 status = ntvfs_set_addresses(c->ntvfs, local_address, remote_address);
108 if (!NT_STATUS_IS_OK(status)) {
109 DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS failed to set the addr callbacks!\n"));
110 return status;
113 ntvfs_req = ntvfs_request_create(c->ntvfs, mem_ctx,
114 dce_call->conn->auth_state.session_info,
115 0, /* TODO: fill in PID */
116 dce_call->time,
117 NULL, NULL, 0);
118 NT_STATUS_HAVE_NO_MEMORY(ntvfs_req);
120 /* Invoke NTVFS connection hook */
121 tcon.tcon.level = RAW_TCON_TCON;
122 ZERO_STRUCT(tcon.tcon.in);
123 tcon.tcon.in.service = scfg->name;
124 status = ntvfs_connect(ntvfs_req, &tcon);
125 if (!NT_STATUS_IS_OK(status)) {
126 DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS ntvfs_connect() failed!\n"));
127 return status;
130 *_ntvfs = c->ntvfs;
131 return NT_STATUS_OK;