Line data Source code
1 : /*
2 : Unix SMB/CIFS implementation.
3 :
4 : srvsvc pipe ntvfs helper functions
5 :
6 : Copyright (C) Stefan (metze) Metzmacher 2006
7 :
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.
12 :
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.
17 :
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/>.
20 : */
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"
26 :
27 : struct srvsvc_ntvfs_ctx {
28 : struct ntvfs_context *ntvfs;
29 : };
30 :
31 0 : static int srvsvc_ntvfs_ctx_destructor(struct srvsvc_ntvfs_ctx *c)
32 : {
33 0 : ntvfs_disconnect(c->ntvfs);
34 0 : return 0;
35 : }
36 :
37 0 : 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)
41 : {
42 0 : struct auth_session_info *session_info =
43 0 : dcesrv_call_session_info(dce_call);
44 0 : struct imessaging_context *imsg_ctx =
45 0 : dcesrv_imessaging_context(dce_call->conn);
46 0 : struct server_id server_id = dcesrv_server_id(dce_call->conn);
47 0 : NTSTATUS status;
48 0 : struct srvsvc_ntvfs_ctx *c;
49 0 : struct ntvfs_request *ntvfs_req;
50 0 : enum ntvfs_type type;
51 0 : struct share_context *sctx;
52 0 : struct share_config *scfg;
53 0 : char *sharetype;
54 0 : union smb_tcon tcon;
55 0 : const struct tsocket_address *local_address;
56 0 : const struct tsocket_address *remote_address;
57 :
58 0 : status = share_get_context(mem_ctx, dce_call->conn->dce_ctx->lp_ctx, &sctx);
59 0 : if (!NT_STATUS_IS_OK(status)) {
60 0 : return status;
61 : }
62 :
63 0 : status = share_get_config(mem_ctx, sctx, share, &scfg);
64 0 : if (!NT_STATUS_IS_OK(status)) {
65 0 : DEBUG(0,("srvsvc_create_ntvfs_context: couldn't find service %s\n", share));
66 0 : return status;
67 : }
68 :
69 : #if 0 /* TODO: fix access checking */
70 : if (!socket_check_access(dce_call->connection->socket,
71 : scfg->name,
72 : share_string_list_option(scfg, SHARE_HOSTS_ALLOW),
73 : share_string_list_option(scfg, SHARE_HOSTS_DENY))) {
74 : return NT_STATUS_ACCESS_DENIED;
75 : }
76 : #endif
77 :
78 : /* work out what sort of connection this is */
79 0 : sharetype = share_string_option(mem_ctx, scfg, SHARE_TYPE, SHARE_TYPE_DEFAULT);
80 0 : if (sharetype && strcmp(sharetype, "IPC") == 0) {
81 0 : type = NTVFS_IPC;
82 0 : } else if (sharetype && strcmp(sharetype, "PRINTER")) {
83 0 : type = NTVFS_PRINT;
84 : } else {
85 0 : type = NTVFS_DISK;
86 : }
87 :
88 0 : TALLOC_FREE(sharetype);
89 :
90 0 : c = talloc(mem_ctx, struct srvsvc_ntvfs_ctx);
91 0 : NT_STATUS_HAVE_NO_MEMORY(c);
92 :
93 : /* init ntvfs function pointers */
94 0 : status = ntvfs_init_connection(c, scfg, type,
95 : PROTOCOL_NT1,
96 : 0,/* ntvfs_client_caps */
97 : dce_call->event_ctx,
98 : imsg_ctx,
99 0 : dce_call->conn->dce_ctx->lp_ctx,
100 : server_id,
101 : &c->ntvfs);
102 0 : if (!NT_STATUS_IS_OK(status)) {
103 0 : DEBUG(0, ("srvsvc_create_ntvfs_context: ntvfs_init_connection failed for service %s\n",
104 : scfg->name));
105 0 : return status;
106 : }
107 0 : talloc_set_destructor(c, srvsvc_ntvfs_ctx_destructor);
108 :
109 : /*
110 : * NOTE: we only set the addr callbacks as we're not interested in oplocks or in getting file handles
111 : */
112 0 : local_address = dcesrv_connection_get_local_address(dce_call->conn);
113 0 : remote_address = dcesrv_connection_get_remote_address(dce_call->conn);
114 0 : status = ntvfs_set_addresses(c->ntvfs, local_address, remote_address);
115 0 : if (!NT_STATUS_IS_OK(status)) {
116 0 : DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS failed to set the addr callbacks!\n"));
117 0 : return status;
118 : }
119 :
120 0 : ntvfs_req = ntvfs_request_create(c->ntvfs, mem_ctx,
121 : session_info,
122 : 0, /* TODO: fill in PID */
123 : dce_call->time,
124 : NULL, NULL, 0);
125 0 : NT_STATUS_HAVE_NO_MEMORY(ntvfs_req);
126 :
127 : /* Invoke NTVFS connection hook */
128 0 : tcon.tcon.level = RAW_TCON_TCON;
129 0 : ZERO_STRUCT(tcon.tcon.in);
130 0 : tcon.tcon.in.service = scfg->name;
131 0 : status = ntvfs_connect(ntvfs_req, &tcon);
132 0 : if (!NT_STATUS_IS_OK(status)) {
133 0 : DEBUG(0,("srvsvc_create_ntvfs_context: NTVFS ntvfs_connect() failed!\n"));
134 0 : return status;
135 : }
136 :
137 0 : *_ntvfs = c->ntvfs;
138 0 : return NT_STATUS_OK;
139 : }
|