r12608: Remove some unused #include lines.
[abartlet/samba.git/.git] / source4 / libnet / libnet_share.c
1 /* 
2    Unix SMB/CIFS implementation.
3    
4    Copyright (C) GrĂ©gory LEOCADIE <gleocadie@idealx.com>
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 2 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, write to the Free Software
18    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20
21 #include "includes.h"
22 #include "libnet/libnet.h"
23
24
25 NTSTATUS libnet_ListShares(struct libnet_context *ctx, 
26                            TALLOC_CTX *mem_ctx, struct libnet_ListShares *r)
27 {
28         NTSTATUS status;
29         struct libnet_RpcConnect c;
30         struct srvsvc_NetShareEnumAll s;
31         uint32_t resume_handle;
32         struct srvsvc_NetShareCtr0 ctr0;
33
34         c.level                      = LIBNET_RPC_CONNECT_SERVER;
35         c.in.domain_name             = r->in.server_name;
36         c.in.dcerpc_iface                = &dcerpc_table_srvsvc;
37
38         status = libnet_RpcConnect(ctx, mem_ctx, &c);
39         if (!NT_STATUS_IS_OK(status)) {
40                 r->out.error_string = talloc_asprintf(mem_ctx,
41                                                       "Connection to SRVSVC pipe of server %s "
42                                                       "failed: %s\n",
43                                                       r->in.server_name,
44                                                       nt_errstr(status));
45                 return status;
46         }
47
48         s.in.level = r->in.level;
49         s.in.ctr.ctr0 = &ctr0;
50         s.in.max_buffer = ~0;
51         s.in.resume_handle = &resume_handle;
52
53         ZERO_STRUCT(ctr0);
54
55         status = dcerpc_srvsvc_NetShareEnumAll(c.out.dcerpc_pipe, mem_ctx, &s);
56         
57         if (!NT_STATUS_IS_OK(status)) {
58                 r->out.error_string = talloc_asprintf(mem_ctx,
59                                                       "srvsvc_NetShareEnumAll on server '%s' failed"
60                                                       ": %s\n",
61                                                       r->in.server_name, nt_errstr(status));
62                 goto disconnect;
63         }
64
65         if (!W_ERROR_IS_OK(s.out.result) && !W_ERROR_EQUAL(s.out.result, WERR_MORE_DATA)) {
66                 goto disconnect;
67         }
68
69         r->out.ctr = s.out.ctr;
70
71 disconnect:
72         talloc_free(c.out.dcerpc_pipe);
73
74         return status;  
75 }
76
77
78 NTSTATUS libnet_AddShare(struct libnet_context *ctx,
79                          TALLOC_CTX *mem_ctx, struct libnet_AddShare *r)
80 {
81         NTSTATUS status;
82         struct libnet_RpcConnect c;
83         struct srvsvc_NetShareAdd s;
84
85         c.level                     = LIBNET_RPC_CONNECT_SERVER;
86         c.in.domain_name            = r->in.server_name;
87         c.in.dcerpc_iface               = &dcerpc_table_srvsvc;
88
89         status = libnet_RpcConnect(ctx, mem_ctx, &c);
90         if (!NT_STATUS_IS_OK(status)) {
91                 r->out.error_string = talloc_asprintf(mem_ctx,
92                                                       "Connection to SRVSVC pipe of server %s "
93                                                       "failed: %s\n",
94                                                       r->in.server_name, nt_errstr(status));
95                 return status;
96         }
97
98         s.in.level              = r->in.level;
99         s.in.info.info2         = &r->in.share;
100         s.in.server_unc         = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
101  
102         status = dcerpc_srvsvc_NetShareAdd(c.out.dcerpc_pipe, mem_ctx,&s);      
103
104         if (!NT_STATUS_IS_OK(status)) {
105                 r->out.error_string = talloc_asprintf(mem_ctx,
106                                                       "srvsvc_NetShareAdd on server '%s' failed"
107                                                       ": %s\n",
108                                                       r->in.server_name, nt_errstr(status));
109         }
110
111         talloc_free(c.out.dcerpc_pipe);
112         
113         return status;
114 }
115
116
117 NTSTATUS libnet_DelShare(struct libnet_context *ctx,
118                          TALLOC_CTX *mem_ctx, struct libnet_DelShare *r)
119 {
120         NTSTATUS status;
121         struct libnet_RpcConnect c;
122         struct srvsvc_NetShareDel s;
123
124         c.level                      = LIBNET_RPC_CONNECT_SERVER;
125         c.in.domain_name             = r->in.server_name;
126         c.in.dcerpc_iface                = &dcerpc_table_srvsvc;
127
128         status = libnet_RpcConnect(ctx, mem_ctx, &c);
129         if (!NT_STATUS_IS_OK(status)) {
130                 r->out.error_string = talloc_asprintf(mem_ctx,
131                                                       "Connection to SRVSVC pipe of server %s "
132                                                       "failed: %s\n",
133                                                       r->in.server_name, nt_errstr(status));
134                 return status;
135         } 
136                 
137         s.in.server_unc = talloc_asprintf(mem_ctx, "\\\\%s", r->in.server_name);
138         s.in.share_name = r->in.share_name;
139
140         status = dcerpc_srvsvc_NetShareDel(c.out.dcerpc_pipe, mem_ctx, &s);
141         if (!NT_STATUS_IS_OK(status)) {
142                 r->out.error_string = talloc_asprintf(mem_ctx,
143                                                       "srvsvc_NetShareDel on server '%s' failed"
144                                                       ": %s\n",
145                                                       r->in.server_name, nt_errstr(status));
146         }
147
148         talloc_free(c.out.dcerpc_pipe);
149
150         return status;
151 }