1 | /*
|
---|
2 | * Unix SMB/CIFS implementation.
|
---|
3 | * NetApi File Support
|
---|
4 | * Copyright (C) Guenther Deschner 2008
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 3 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, see <http://www.gnu.org/licenses/>.
|
---|
18 | */
|
---|
19 |
|
---|
20 | #include "includes.h"
|
---|
21 |
|
---|
22 | #include "librpc/gen_ndr/libnetapi.h"
|
---|
23 | #include "lib/netapi/netapi.h"
|
---|
24 | #include "lib/netapi/netapi_private.h"
|
---|
25 | #include "lib/netapi/libnetapi.h"
|
---|
26 | #include "../librpc/gen_ndr/cli_srvsvc.h"
|
---|
27 |
|
---|
28 | /****************************************************************
|
---|
29 | ****************************************************************/
|
---|
30 |
|
---|
31 | WERROR NetFileClose_r(struct libnetapi_ctx *ctx,
|
---|
32 | struct NetFileClose *r)
|
---|
33 | {
|
---|
34 | WERROR werr;
|
---|
35 | NTSTATUS status;
|
---|
36 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
37 |
|
---|
38 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
39 | &ndr_table_srvsvc.syntax_id,
|
---|
40 | &pipe_cli);
|
---|
41 | if (!W_ERROR_IS_OK(werr)) {
|
---|
42 | goto done;
|
---|
43 | }
|
---|
44 |
|
---|
45 | status = rpccli_srvsvc_NetFileClose(pipe_cli, talloc_tos(),
|
---|
46 | r->in.server_name,
|
---|
47 | r->in.fileid,
|
---|
48 | &werr);
|
---|
49 | if (!NT_STATUS_IS_OK(status)) {
|
---|
50 | werr = ntstatus_to_werror(status);
|
---|
51 | goto done;
|
---|
52 | }
|
---|
53 |
|
---|
54 | done:
|
---|
55 | return werr;
|
---|
56 | }
|
---|
57 |
|
---|
58 | /****************************************************************
|
---|
59 | ****************************************************************/
|
---|
60 |
|
---|
61 | WERROR NetFileClose_l(struct libnetapi_ctx *ctx,
|
---|
62 | struct NetFileClose *r)
|
---|
63 | {
|
---|
64 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileClose);
|
---|
65 | }
|
---|
66 |
|
---|
67 | /****************************************************************
|
---|
68 | ****************************************************************/
|
---|
69 |
|
---|
70 | static NTSTATUS map_srvsvc_FileInfo_to_FILE_INFO_buffer(TALLOC_CTX *mem_ctx,
|
---|
71 | uint32_t level,
|
---|
72 | union srvsvc_NetFileInfo *info,
|
---|
73 | uint8_t **buffer,
|
---|
74 | uint32_t *num_entries)
|
---|
75 | {
|
---|
76 | struct FILE_INFO_2 i2;
|
---|
77 | struct FILE_INFO_3 i3;
|
---|
78 |
|
---|
79 | switch (level) {
|
---|
80 | case 2:
|
---|
81 | i2.fi2_id = info->info2->fid;
|
---|
82 |
|
---|
83 | ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_2, i2,
|
---|
84 | (struct FILE_INFO_2 **)buffer,
|
---|
85 | num_entries);
|
---|
86 | break;
|
---|
87 | case 3:
|
---|
88 | i3.fi3_id = info->info3->fid;
|
---|
89 | i3.fi3_permissions = info->info3->permissions;
|
---|
90 | i3.fi3_num_locks = info->info3->num_locks;
|
---|
91 | i3.fi3_pathname = talloc_strdup(mem_ctx, info->info3->path);
|
---|
92 | i3.fi3_username = talloc_strdup(mem_ctx, info->info3->user);
|
---|
93 |
|
---|
94 | NT_STATUS_HAVE_NO_MEMORY(i3.fi3_pathname);
|
---|
95 | NT_STATUS_HAVE_NO_MEMORY(i3.fi3_username);
|
---|
96 |
|
---|
97 | ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_3, i3,
|
---|
98 | (struct FILE_INFO_3 **)buffer,
|
---|
99 | num_entries);
|
---|
100 | break;
|
---|
101 | default:
|
---|
102 | return NT_STATUS_INVALID_INFO_CLASS;
|
---|
103 | }
|
---|
104 |
|
---|
105 | return NT_STATUS_OK;
|
---|
106 | }
|
---|
107 |
|
---|
108 | /****************************************************************
|
---|
109 | ****************************************************************/
|
---|
110 |
|
---|
111 | WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx,
|
---|
112 | struct NetFileGetInfo *r)
|
---|
113 | {
|
---|
114 | WERROR werr;
|
---|
115 | NTSTATUS status;
|
---|
116 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
117 | union srvsvc_NetFileInfo info;
|
---|
118 | uint32_t num_entries = 0;
|
---|
119 |
|
---|
120 | if (!r->out.buffer) {
|
---|
121 | return WERR_INVALID_PARAM;
|
---|
122 | }
|
---|
123 |
|
---|
124 | switch (r->in.level) {
|
---|
125 | case 2:
|
---|
126 | case 3:
|
---|
127 | break;
|
---|
128 | default:
|
---|
129 | return WERR_UNKNOWN_LEVEL;
|
---|
130 | }
|
---|
131 |
|
---|
132 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
133 | &ndr_table_srvsvc.syntax_id,
|
---|
134 | &pipe_cli);
|
---|
135 | if (!W_ERROR_IS_OK(werr)) {
|
---|
136 | goto done;
|
---|
137 | }
|
---|
138 |
|
---|
139 | status = rpccli_srvsvc_NetFileGetInfo(pipe_cli, talloc_tos(),
|
---|
140 | r->in.server_name,
|
---|
141 | r->in.fileid,
|
---|
142 | r->in.level,
|
---|
143 | &info,
|
---|
144 | &werr);
|
---|
145 | if (!W_ERROR_IS_OK(werr)) {
|
---|
146 | goto done;
|
---|
147 | }
|
---|
148 |
|
---|
149 | status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx,
|
---|
150 | r->in.level,
|
---|
151 | &info,
|
---|
152 | r->out.buffer,
|
---|
153 | &num_entries);
|
---|
154 | if (!NT_STATUS_IS_OK(status)) {
|
---|
155 | werr = ntstatus_to_werror(status);
|
---|
156 | goto done;
|
---|
157 | }
|
---|
158 | done:
|
---|
159 | return werr;
|
---|
160 | }
|
---|
161 |
|
---|
162 | /****************************************************************
|
---|
163 | ****************************************************************/
|
---|
164 |
|
---|
165 | WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx,
|
---|
166 | struct NetFileGetInfo *r)
|
---|
167 | {
|
---|
168 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileGetInfo);
|
---|
169 | }
|
---|
170 |
|
---|
171 | /****************************************************************
|
---|
172 | ****************************************************************/
|
---|
173 |
|
---|
174 | WERROR NetFileEnum_r(struct libnetapi_ctx *ctx,
|
---|
175 | struct NetFileEnum *r)
|
---|
176 | {
|
---|
177 | WERROR werr;
|
---|
178 | NTSTATUS status;
|
---|
179 | struct rpc_pipe_client *pipe_cli = NULL;
|
---|
180 | struct srvsvc_NetFileInfoCtr info_ctr;
|
---|
181 | struct srvsvc_NetFileCtr2 ctr2;
|
---|
182 | struct srvsvc_NetFileCtr3 ctr3;
|
---|
183 | uint32_t num_entries = 0;
|
---|
184 | uint32_t i;
|
---|
185 |
|
---|
186 | if (!r->out.buffer) {
|
---|
187 | return WERR_INVALID_PARAM;
|
---|
188 | }
|
---|
189 |
|
---|
190 | switch (r->in.level) {
|
---|
191 | case 2:
|
---|
192 | case 3:
|
---|
193 | break;
|
---|
194 | default:
|
---|
195 | return WERR_UNKNOWN_LEVEL;
|
---|
196 | }
|
---|
197 |
|
---|
198 | werr = libnetapi_open_pipe(ctx, r->in.server_name,
|
---|
199 | &ndr_table_srvsvc.syntax_id,
|
---|
200 | &pipe_cli);
|
---|
201 | if (!W_ERROR_IS_OK(werr)) {
|
---|
202 | goto done;
|
---|
203 | }
|
---|
204 |
|
---|
205 | ZERO_STRUCT(info_ctr);
|
---|
206 |
|
---|
207 | info_ctr.level = r->in.level;
|
---|
208 | switch (r->in.level) {
|
---|
209 | case 2:
|
---|
210 | ZERO_STRUCT(ctr2);
|
---|
211 | info_ctr.ctr.ctr2 = &ctr2;
|
---|
212 | break;
|
---|
213 | case 3:
|
---|
214 | ZERO_STRUCT(ctr3);
|
---|
215 | info_ctr.ctr.ctr3 = &ctr3;
|
---|
216 | break;
|
---|
217 | }
|
---|
218 |
|
---|
219 | status = rpccli_srvsvc_NetFileEnum(pipe_cli, talloc_tos(),
|
---|
220 | r->in.server_name,
|
---|
221 | r->in.base_path,
|
---|
222 | r->in.user_name,
|
---|
223 | &info_ctr,
|
---|
224 | r->in.prefmaxlen,
|
---|
225 | r->out.total_entries,
|
---|
226 | r->out.resume_handle,
|
---|
227 | &werr);
|
---|
228 | if (NT_STATUS_IS_ERR(status)) {
|
---|
229 | goto done;
|
---|
230 | }
|
---|
231 |
|
---|
232 | for (i=0; i < info_ctr.ctr.ctr2->count; i++) {
|
---|
233 | union srvsvc_NetFileInfo _i;
|
---|
234 | switch (r->in.level) {
|
---|
235 | case 2:
|
---|
236 | _i.info2 = &info_ctr.ctr.ctr2->array[i];
|
---|
237 | break;
|
---|
238 | case 3:
|
---|
239 | _i.info3 = &info_ctr.ctr.ctr3->array[i];
|
---|
240 | break;
|
---|
241 | }
|
---|
242 |
|
---|
243 | status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx,
|
---|
244 | r->in.level,
|
---|
245 | &_i,
|
---|
246 | r->out.buffer,
|
---|
247 | &num_entries);
|
---|
248 | if (!NT_STATUS_IS_OK(status)) {
|
---|
249 | werr = ntstatus_to_werror(status);
|
---|
250 | goto done;
|
---|
251 | }
|
---|
252 | }
|
---|
253 |
|
---|
254 | if (r->out.entries_read) {
|
---|
255 | *r->out.entries_read = num_entries;
|
---|
256 | }
|
---|
257 |
|
---|
258 | if (r->out.total_entries) {
|
---|
259 | *r->out.total_entries = num_entries;
|
---|
260 | }
|
---|
261 |
|
---|
262 | done:
|
---|
263 | return werr;
|
---|
264 | }
|
---|
265 |
|
---|
266 | /****************************************************************
|
---|
267 | ****************************************************************/
|
---|
268 |
|
---|
269 | WERROR NetFileEnum_l(struct libnetapi_ctx *ctx,
|
---|
270 | struct NetFileEnum *r)
|
---|
271 | {
|
---|
272 | LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileEnum);
|
---|
273 | }
|
---|