r9152: fix a crash bug
[Samba/aatanasov.git] / source / libnet / libnet_share.c
blob4b473436e123f79fed2eeb3de9a83809cad7a043
1 /*
2 Unix SMB/CIFS implementation.
4 Copyright (C) Grégory LEOCADIE <gleocadie@idealx.com>
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "includes.h"
22 #include "libnet/libnet.h"
23 #include "librpc/gen_ndr/ndr_srvsvc.h"
26 NTSTATUS libnet_ListShares(struct libnet_context *ctx,
27 TALLOC_CTX *mem_ctx, struct libnet_ListShares *r)
29 NTSTATUS status;
30 struct libnet_RpcConnect c;
31 struct srvsvc_NetShareEnumAll s;
32 uint32_t resume_handle;
33 struct srvsvc_NetShareCtr0 ctr0;
35 c.level = LIBNET_RPC_CONNECT_SERVER;
36 c.in.domain_name = r->in.server_name;
37 c.in.dcerpc_iface_name = DCERPC_SRVSVC_NAME;
38 c.in.dcerpc_iface_uuid = DCERPC_SRVSVC_UUID;
39 c.in.dcerpc_iface_version = DCERPC_SRVSVC_VERSION;
41 status = libnet_RpcConnect(ctx, mem_ctx, &c);
42 if (!NT_STATUS_IS_OK(status)) {
43 r->out.error_string = talloc_asprintf(mem_ctx,
44 "Connection to SRVSVC pipe of server %s "
45 "failed: %s\n",
46 r->in.server_name,
47 nt_errstr(status));
48 return status;
51 s.in.level = r->in.level;
52 s.in.ctr.ctr0 = &ctr0;
53 s.in.max_buffer = ~0;
54 s.in.resume_handle = &resume_handle;
56 ZERO_STRUCT(ctr0);
58 status = dcerpc_srvsvc_NetShareEnumAll(c.out.dcerpc_pipe, mem_ctx, &s);
60 if (!NT_STATUS_IS_OK(status)) {
61 r->out.error_string = talloc_asprintf(mem_ctx,
62 "srvsvc_NetShareEnumAll on server '%s' failed"
63 ": %s\n",
64 r->in.server_name, nt_errstr(status));
65 goto disconnect;
68 if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
69 goto disconnect;
72 r->out.ctr = s.out.ctr;
74 disconnect:
75 talloc_free(c.out.dcerpc_pipe);
77 return status;
81 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
82 TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
84 NTSTATUS status;
85 struct libnet_RpcConnect c;
86 struct srvsvc_NetShareAdd s;
88 c.level = LIBNET_RPC_CONNECT_SERVER;
89 c.in.domain_name = r->in.server_name;
90 c.in.dcerpc_iface_name = DCERPC_SRVSVC_NAME;
91 c.in.dcerpc_iface_uuid = DCERPC_SRVSVC_UUID;
92 c.in.dcerpc_iface_version = DCERPC_SRVSVC_VERSION;
94 status = libnet_RpcConnect(ctx, mem_ctx, &c);
95 if (!NT_STATUS_IS_OK(status)) {
96 r->out.error_string = talloc_asprintf(mem_ctx,
97 "Connection to SRVSVC pipe of server %s "
98 "failed: %s\n",
99 r->in.server_name, nt_errstr(status));
100 return status;
103 s.in.level = r->in.level;
104 s.in.info.info2 = &r->in.share;
105 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
107 status = dcerpc_srvsvc_NetShareAdd(c.out.dcerpc_pipe, mem_ctx,&s);
109 if (!NT_STATUS_IS_OK(status)) {
110 r->out.error_string = talloc_asprintf(mem_ctx,
111 "srvsvc_NetShareAdd on server '%s' failed"
112 ": %s\n",
113 r->in.server_name, nt_errstr(status));
116 talloc_free(c.out.dcerpc_pipe);
118 return status;
122 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
123 TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
125 NTSTATUS status;
126 struct libnet_RpcConnect c;
127 struct srvsvc_NetShareDel s;
129 c.level = LIBNET_RPC_CONNECT_SERVER;
130 c.in.domain_name = r->in.server_name;
131 c.in.dcerpc_iface_name = DCERPC_SRVSVC_NAME;
132 c.in.dcerpc_iface_uuid = DCERPC_SRVSVC_UUID;
133 c.in.dcerpc_iface_version = DCERPC_SRVSVC_VERSION;
135 status = libnet_RpcConnect(ctx, mem_ctx, &c);
136 if (!NT_STATUS_IS_OK(status)) {
137 r->out.error_string = talloc_asprintf(mem_ctx,
138 "Connection to SRVSVC pipe of server %s "
139 "failed: %s\n",
140 r->in.server_name, nt_errstr(status));
141 return status;
144 s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
145 s.in.share_name = r->in.share_name;
147 status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
148 if (!NT_STATUS_IS_OK(status)) {
149 r->out.error_string = talloc_asprintf(mem_ctx,
150 "srvsvc_NetShareDel on server '%s' failed"
151 ": %s\n",
152 r->in.server_name, nt_errstr(status));
155 talloc_free(c.out.dcerpc_pipe);
157 return status;