s3:registry: add an extra check for dsize==0 to regdb_fetch_keys_internal()
[Samba/fernandojvsilva.git] / source4 / rpc_server / srvsvc / srvsvc_ntvfs.c
blob7b337063af1fc709cadfa2eab13ba5eb27ad8c71
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"
26 struct socket_address *srvsvc_get_my_addr(void *p, TALLOC_CTX *mem_ctx)
28 struct dcesrv_connection *conn = talloc_get_type(p, struct dcesrv_connection);
29 return dcesrv_connection_get_my_addr(conn, mem_ctx);
32 struct socket_address *srvsvc_get_peer_addr(void *p, TALLOC_CTX *mem_ctx)
34 struct dcesrv_connection *conn = talloc_get_type(p, struct dcesrv_connection);
35 return dcesrv_connection_get_peer_addr(conn, mem_ctx);
38 struct srvsvc_ntvfs_ctx {
39 struct ntvfs_context *ntvfs;
42 static int srvsvc_ntvfs_ctx_destructor(struct srvsvc_ntvfs_ctx *c)
44 ntvfs_disconnect(c->ntvfs);
45 return 0;
48 NTSTATUS srvsvc_create_ntvfs_context(struct dcesrv_call_state *dce_call,
49 TALLOC_CTX *mem_ctx,
50 const char *share,
51 struct ntvfs_context **_ntvfs)
53 NTSTATUS status;
54 struct srvsvc_ntvfs_ctx *c;
55 struct ntvfs_request *ntvfs_req;
56 enum ntvfs_type type;
57 struct share_context *sctx;
58 struct share_config *scfg;
59 const char *sharetype;
61 status = share_get_context_by_name(mem_ctx, lp_share_backend(dce_call->conn->dce_ctx->lp_ctx), dce_call->event_ctx, dce_call->conn->dce_ctx->lp_ctx, &sctx);
62 if (!NT_STATUS_IS_OK(status)) {
63 return status;
66 status = share_get_config(mem_ctx, sctx, share, &scfg);
67 if (!NT_STATUS_IS_OK(status)) {
68 DEBUG(0,("srvsvc_create_ntvfs_context: couldn't find service %s\n", share));
69 return status;
72 #if 0 /* TODO: fix access cecking */
73 if (!socket_check_access(dce_call->connection->socket,
74 scfg->name,
75 share_string_list_option(scfg, SHARE_HOSTS_ALLOW),
76 share_string_list_option(scfg, SHARE_HOSTS_DENY))) {
77 return NT_STATUS_ACCESS_DENIED;
79 #endif
81 /* work out what sort of connection this is */
82 sharetype = share_string_option(scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
83 if (sharetype && strcmp(sharetype, "IPC") == 0) {
84 type = NTVFS_IPC;
85 } else if (sharetype && strcmp(sharetype, "PRINTER")) {
86 type = NTVFS_PRINT;
87 } else {
88 type = NTVFS_DISK;
91 c = talloc(mem_ctx, struct srvsvc_ntvfs_ctx);
92 NT_STATUS_HAVE_NO_MEMORY(c);
94 /* init ntvfs function pointers */
95 status = ntvfs_init_connection(c, scfg, type,
96 PROTOCOL_NT1,
97 0,/* ntvfs_client_caps */
98 dce_call->event_ctx,
99 dce_call->conn->msg_ctx,
100 dce_call->conn->dce_ctx->lp_ctx,
101 dce_call->conn->server_id,
102 &c->ntvfs);
103 if (!NT_STATUS_IS_OK(status)) {
104 DEBUG(0, ("srvsvc_create_ntvfs_context: ntvfs_init_connection failed for service %s\n",
105 scfg->name));
106 return status;
108 talloc_set_destructor(c, srvsvc_ntvfs_ctx_destructor);
111 * NOTE: we only set the addr callbacks as we're not interesseted in oplocks or in getting file handles
113 status = ntvfs_set_addr_callbacks(c->ntvfs, srvsvc_get_my_addr, srvsvc_get_peer_addr, dce_call->conn);
114 if (!NT_STATUS_IS_OK(status)) {
115 DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS failed to set the addr callbacks!\n"));
116 return status;
119 ntvfs_req = ntvfs_request_create(c->ntvfs, mem_ctx,
120 dce_call->conn->auth_state.session_info,
121 0, /* TODO: fill in PID */
122 dce_call->time,
123 NULL, NULL, 0);
124 NT_STATUS_HAVE_NO_MEMORY(ntvfs_req);
126 /* Invoke NTVFS connection hook */
127 /* FIXME: Here is the right parameter missing!
128 * status = ntvfs_connect(ntvfs_req, <TODO>); */
129 status = NT_STATUS_UNSUCCESSFUL; /* return this for now */
130 if (!NT_STATUS_IS_OK(status)) {
131 DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS ntvfs_connect() failed!\n"));
132 return status;
135 *_ntvfs = c->ntvfs;
136 return NT_STATUS_OK;