2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Guenther Deschner 2008
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.
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.
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/>.
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/ndr_srvsvc_c.h"
28 /****************************************************************
29 ****************************************************************/
31 WERROR NetFileClose_r(struct libnetapi_ctx *ctx,
32 struct NetFileClose *r)
36 struct dcerpc_binding_handle *b;
38 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
39 &ndr_table_srvsvc.syntax_id,
41 if (!W_ERROR_IS_OK(werr)) {
45 status = dcerpc_srvsvc_NetFileClose(b, talloc_tos(),
49 if (!NT_STATUS_IS_OK(status)) {
50 werr = ntstatus_to_werror(status);
58 /****************************************************************
59 ****************************************************************/
61 WERROR NetFileClose_l(struct libnetapi_ctx *ctx,
62 struct NetFileClose *r)
64 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileClose);
67 /****************************************************************
68 ****************************************************************/
70 static NTSTATUS map_srvsvc_FileInfo_to_FILE_INFO_buffer(TALLOC_CTX *mem_ctx,
72 union srvsvc_NetFileInfo *info,
74 uint32_t *num_entries)
76 struct FILE_INFO_2 i2;
77 struct FILE_INFO_3 i3;
81 i2.fi2_id = info->info2->fid;
83 ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_2, i2,
84 (struct FILE_INFO_2 **)buffer,
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);
94 NT_STATUS_HAVE_NO_MEMORY(i3.fi3_pathname);
95 NT_STATUS_HAVE_NO_MEMORY(i3.fi3_username);
97 ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_3, i3,
98 (struct FILE_INFO_3 **)buffer,
102 return NT_STATUS_INVALID_INFO_CLASS;
108 /****************************************************************
109 ****************************************************************/
111 WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx,
112 struct NetFileGetInfo *r)
116 union srvsvc_NetFileInfo info;
117 uint32_t num_entries = 0;
118 struct dcerpc_binding_handle *b;
120 if (!r->out.buffer) {
121 return WERR_INVALID_PARAM;
124 switch (r->in.level) {
129 return WERR_UNKNOWN_LEVEL;
132 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
133 &ndr_table_srvsvc.syntax_id,
135 if (!W_ERROR_IS_OK(werr)) {
139 status = dcerpc_srvsvc_NetFileGetInfo(b, talloc_tos(),
145 if (!NT_STATUS_IS_OK(status)) {
146 werr = ntstatus_to_werror(status);
150 if (!W_ERROR_IS_OK(werr)) {
154 status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx,
159 if (!NT_STATUS_IS_OK(status)) {
160 werr = ntstatus_to_werror(status);
167 /****************************************************************
168 ****************************************************************/
170 WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx,
171 struct NetFileGetInfo *r)
173 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileGetInfo);
176 /****************************************************************
177 ****************************************************************/
179 WERROR NetFileEnum_r(struct libnetapi_ctx *ctx,
180 struct NetFileEnum *r)
184 struct srvsvc_NetFileInfoCtr info_ctr;
185 struct srvsvc_NetFileCtr2 ctr2;
186 struct srvsvc_NetFileCtr3 ctr3;
187 uint32_t num_entries = 0;
189 struct dcerpc_binding_handle *b;
191 if (!r->out.buffer) {
192 return WERR_INVALID_PARAM;
195 switch (r->in.level) {
200 return WERR_UNKNOWN_LEVEL;
203 werr = libnetapi_get_binding_handle(ctx, r->in.server_name,
204 &ndr_table_srvsvc.syntax_id,
206 if (!W_ERROR_IS_OK(werr)) {
210 ZERO_STRUCT(info_ctr);
212 info_ctr.level = r->in.level;
213 switch (r->in.level) {
216 info_ctr.ctr.ctr2 = &ctr2;
220 info_ctr.ctr.ctr3 = &ctr3;
224 status = dcerpc_srvsvc_NetFileEnum(b, talloc_tos(),
230 r->out.total_entries,
231 r->out.resume_handle,
233 if (!NT_STATUS_IS_OK(status)) {
234 werr = ntstatus_to_werror(status);
238 if (!W_ERROR_IS_OK(werr) && !W_ERROR_EQUAL(werr, WERR_MORE_DATA)) {
242 for (i=0; i < info_ctr.ctr.ctr2->count; i++) {
243 union srvsvc_NetFileInfo _i;
244 switch (r->in.level) {
246 _i.info2 = &info_ctr.ctr.ctr2->array[i];
249 _i.info3 = &info_ctr.ctr.ctr3->array[i];
253 status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx,
258 if (!NT_STATUS_IS_OK(status)) {
259 werr = ntstatus_to_werror(status);
264 if (r->out.entries_read) {
265 *r->out.entries_read = num_entries;
268 if (r->out.total_entries) {
269 *r->out.total_entries = num_entries;
276 /****************************************************************
277 ****************************************************************/
279 WERROR NetFileEnum_l(struct libnetapi_ctx *ctx,
280 struct NetFileEnum *r)
282 LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileEnum);