preparing for release of alpha-2.6
[Samba/gbeck.git] / source / rpc_client / cli_dfs.c
blob59209264f3766da40de09ef81d1b2afe14ea54bd
1 /*
2 Unix SMB/Netbios implementation.
3 Version 3.0
4 MSDfs RPC calls
5 Copyright (C) Andrew Tridgell 1992-2000
6 Copyright (C) Luke Kenneth Casson Leighton 1996 - 2000
7 Copyright (C) Shirish Kalele 2000
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include "includes.h"
25 #include "rpc_parse.h"
26 #include "rpc_client.h"
27 #include "nterr.h"
29 extern int DEBUGLEVEL;
31 /* Called by all dfs operations to verify if a dfs_root exists at server */
32 static BOOL _dfs_exist(struct cli_connection *con)
34 prs_struct buf;
35 prs_struct rbuf;
36 DFS_R_DFS_EXIST q_d;
38 prs_init(&buf, 0, 4, False);
39 prs_init(&rbuf, 0 ,4, True);
41 /* make a null request */
42 if(!rpc_con_pipe_req(con, DFS_EXIST, &buf, &rbuf))
44 DEBUG(5,("Null request unsuccessful!\n"));
45 prs_free_data(&rbuf);
46 cli_connection_unlink(con);
47 return False;
49 if(!dfs_io_r_dfs_exist("", &q_d, &rbuf, 0))
50 return False;
52 prs_free_data(&rbuf);
53 return q_d.dfs_exist_flag;
56 BOOL dfs_remove(char *srv_name, char *dfs_entrypath, char *dfs_servername,
57 char *dfs_sharename)
59 prs_struct rbuf;
60 prs_struct buf;
61 BOOL valid_cfg= False;
62 DFS_Q_DFS_REMOVE q_d;
63 struct cli_connection *con=NULL;
65 prs_init(&buf, 0, 4, False);
66 prs_init(&rbuf, 0 ,4, True);
67 if (!cli_connection_init(srv_name, PIPE_NETDFS, &con))
68 return False;
70 /* check if server is a dfs server */
71 if(!_dfs_exist(con))
73 DEBUG(5,("dfs_remove: No Dfs root at \\\\%s\n",srv_name));
74 return False;
77 /* store the parameters */
78 make_dfs_q_dfs_remove(&q_d, dfs_entrypath, dfs_servername, dfs_sharename);
80 /* turn parameters into data stream */
81 if(dfs_io_q_dfs_remove("", &q_d, &buf, 0) &&
82 rpc_con_pipe_req(con, DFS_REMOVE, &buf, &rbuf))
84 DFS_R_DFS_REMOVE r_d;
85 BOOL p;
86 ZERO_STRUCT(r_d);
88 dfs_io_r_dfs_remove("", &r_d, &rbuf, 0);
89 p = (rbuf.offset != 0);
91 if(p && r_d.status!=0)
93 DEBUG(1,("DFS_REMOVE: %s\n",get_nt_error_msg(r_d.status)));
94 p = False;
97 if(p)
98 valid_cfg = True;
100 prs_free_data(&rbuf);
101 prs_free_data(&buf);
102 cli_connection_unlink(con);
103 return valid_cfg;
106 BOOL dfs_add(char *srv_name, char* entrypath, char* servername, char* sharename, char* comment)
108 prs_struct rbuf;
109 prs_struct buf;
110 BOOL valid_cfg= False;
111 DFS_Q_DFS_ADD q_d;
112 struct cli_connection *con=NULL;
114 prs_init(&buf, 0, 4, False);
115 prs_init(&rbuf, 0 ,4, True);
116 if (!cli_connection_init(srv_name, PIPE_NETDFS, &con))
117 return False;
119 if(!_dfs_exist(con))
121 DEBUG(5,("dfs_add: No Dfs root at \\\\%s\n",srv_name));
122 return False;
125 /* store the parameters */
126 make_dfs_q_dfs_add(&q_d, entrypath, servername, sharename, comment,
127 DFSFLAG_ADD_VOLUME);
129 /* turn parameters into data stream */
130 if(dfs_io_q_dfs_add("", &q_d, &buf, 0) &&
131 rpc_con_pipe_req(con, DFS_ADD, &buf, &rbuf))
133 DFS_R_DFS_ADD r_d;
134 BOOL p;
135 ZERO_STRUCT(r_d);
137 dfs_io_r_dfs_add("", &r_d, &rbuf, 0);
138 p = (rbuf.offset != 0);
140 if(p && r_d.status!=0)
142 DEBUG(1,("DFS_ADD: %s\n",get_nt_error_msg(r_d.status)));
143 p = False;
146 if(p)
147 valid_cfg = True;
149 prs_free_data(&rbuf);
150 prs_free_data(&buf);
151 cli_connection_unlink(con);
152 return valid_cfg;
155 uint32 dfs_enum(char *srv_name, uint32 level, DFS_INFO_CTR *ctr)
157 prs_struct rbuf;
158 prs_struct buf;
159 BOOL valid_cfg= False;
160 DFS_Q_DFS_ENUM q_d;
161 uint32 res = NT_STATUS_UNSUCCESSFUL;
163 struct cli_connection *con=NULL;
165 prs_init(&buf, 0, 4, False);
166 prs_init(&rbuf, 0 ,4, True);
167 if (!cli_connection_init(srv_name, PIPE_NETDFS, &con))
168 return NT_STATUS_PIPE_NOT_AVAILABLE;
170 if(!_dfs_exist(con))
172 DEBUG(5,("dfs_add: No Dfs root at \\\\%s\n",srv_name));
173 return NT_STATUS_OBJECT_PATH_NOT_FOUND;
176 /* store the parameters */
177 make_dfs_q_dfs_enum(&q_d, level, ctr);
179 /* turn parameters into data stream */
180 if(dfs_io_q_dfs_enum("", &q_d, &buf, 0) &&
181 rpc_con_pipe_req(con, DFS_ENUM, &buf, &rbuf))
183 DFS_R_DFS_ENUM r_d;
184 BOOL p;
185 ZERO_STRUCT(r_d);
187 r_d.ctr = ctr;
188 dfs_io_r_dfs_enum("", &r_d, &rbuf, 0);
189 p = (rbuf.offset != 0);
191 if(p && r_d.status!=0)
193 DEBUG(1,("DFS_ENUM: %s\n",get_nt_error_msg(r_d.status)));
194 res = r_d.status;
195 p = False;
198 if(p)
199 valid_cfg = True;
201 prs_free_data(&rbuf);
202 prs_free_data(&buf);
203 cli_connection_unlink(con);
204 if(valid_cfg)
205 return 0;
206 else
207 return res;