summaryrefslogtreecommitdiffstats
path: root/source/rpc_client/cli_dfs.c
blob: ddebebbdc8c76a5fb4f3a48455abb62506f6ec4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/* 
   Unix SMB/Netbios implementation.
   Version 3.0
   MSDfs RPC calls
   Copyright (C) Andrew Tridgell 1992-2000
   Copyright (C) Luke Kenneth Casson Leighton 1996 - 2000
   Copyright (C) Shirish Kalele 2000

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
   
   This program is distributed in the hope that it will be useful, 
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.
   
   You should have received a copy of the GNU General Public License
   along with this program; if not, write to the Free Software
   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#ifdef SYSLOG
#undef SYSLOG
#endif

#include "includes.h"
#include "rpc_parse.h"
#include "nterr.h"

extern int DEBUGLEVEL;  

/* Called by all dfs operations to verify if a dfs_root exists at server */
static BOOL _dfs_exist(struct cli_connection *con)
{
  prs_struct buf;
  prs_struct rbuf;
  DFS_R_DFS_EXIST q_d;
  
  prs_init(&buf, 0, 4, False);
  prs_init(&rbuf, 0 ,4, True);
  
  /* make a null request */
  if(!rpc_con_pipe_req(con, DFS_EXIST, &buf, &rbuf))
    {
      DEBUG(5,("Null request unsuccessful!\n"));
      prs_free_data(&rbuf);
      cli_connection_unlink(con);
      return False;
    }
  if(!dfs_io_r_dfs_exist("", &q_d, &rbuf, 0))
    return False;

  prs_free_data(&rbuf);
  return q_d.dfs_exist_flag;
}

BOOL dfs_remove(char *srv_name, char *dfs_entrypath, char *dfs_servername, 
		char *dfs_sharename)
{
  prs_struct rbuf;
  prs_struct buf;
  BOOL valid_cfg= False;
  DFS_Q_DFS_REMOVE q_d;
  struct cli_connection *con=NULL;

  prs_init(&buf, 0, 4, False);
  prs_init(&rbuf, 0 ,4, True);
  if (!cli_connection_init(srv_name, PIPE_NETDFS, &con))
    return False;

  /* check if server is a dfs server */
  if(!_dfs_exist(con))
    {
      DEBUG(5,("dfs_remove: No Dfs root at \\\\%s\n",srv_name));
      return False;
    }

  /* store the parameters */
  make_dfs_q_dfs_remove(&q_d, dfs_entrypath, dfs_servername, dfs_sharename);

  /* turn parameters into data stream */
  if(dfs_io_q_dfs_remove("", &q_d, &buf, 0) &&
     rpc_con_pipe_req(con, DFS_REMOVE, &buf, &rbuf))
    {
      DFS_R_DFS_REMOVE r_d;
      BOOL p;
      ZERO_STRUCT(r_d);
      
      dfs_io_r_dfs_remove("", &r_d, &rbuf, 0);
      p = (rbuf.offset != 0);
      
      if(p && r_d.status!=0)
	{
	  DEBUG(1,("DFS_REMOVE: %s\n",get_nt_error_msg(r_d.status)));
	  p = False;
	}
      
      if(p)
	valid_cfg = True;
    }
  prs_free_data(&rbuf);
  prs_free_data(&buf);
  cli_connection_unlink(con);
  return valid_cfg;
}

BOOL dfs_add(char *srv_name, char* entrypath, char* servername, char* sharename, char* comment)
{
  prs_struct rbuf;
  prs_struct buf;
  BOOL valid_cfg= False;
  DFS_Q_DFS_ADD q_d;
  struct cli_connection *con=NULL;

  prs_init(&buf, 0, 4, False);
  prs_init(&rbuf, 0 ,4, True);
  if (!cli_connection_init(srv_name, PIPE_NETDFS, &con))
    return False;

  if(!_dfs_exist(con))
    {
      DEBUG(5,("dfs_add: No Dfs root at \\\\%s\n",srv_name));
     return False;
    }

  /* store the parameters */
  make_dfs_q_dfs_add(&q_d, entrypath, servername, sharename, comment, 
		     DFSFLAG_ADD_VOLUME);

  /* turn parameters into data stream */
  if(dfs_io_q_dfs_add("", &q_d, &buf, 0) &&
     rpc_con_pipe_req(con, DFS_ADD, &buf, &rbuf))
    {
      DFS_R_DFS_ADD r_d;
      BOOL p;
      ZERO_STRUCT(r_d);
      
      dfs_io_r_dfs_add("", &r_d, &rbuf, 0);
      p = (rbuf.offset != 0);
      
      if(p && r_d.status!=0)
	{
	  DEBUG(1,("DFS_ADD: %s\n",get_nt_error_msg(r_d.status)));
	  p = False;
	}
      
      if(p)
	valid_cfg = True;
    }
  prs_free_data(&rbuf);
  prs_free_data(&buf);
  cli_connection_unlink(con);
  return valid_cfg;
}
	    
uint32 dfs_enum(char *srv_name, uint32 level, DFS_INFO_CTR *ctr)
{
  prs_struct rbuf;
  prs_struct buf;
  BOOL valid_cfg= False;
  DFS_Q_DFS_ENUM q_d;
  uint32 res = NT_STATUS_UNSUCCESSFUL;

  struct cli_connection *con=NULL;

  prs_init(&buf, 0, 4, False);
  prs_init(&rbuf, 0 ,4, True);
  if (!cli_connection_init(srv_name, PIPE_NETDFS, &con))
    return NT_STATUS_PIPE_NOT_AVAILABLE;

  if(!_dfs_exist(con))
    {
      DEBUG(5,("dfs_add: No Dfs root at \\\\%s\n",srv_name));
     return NT_STATUS_OBJECT_PATH_NOT_FOUND;
    }

  /* store the parameters */
  make_dfs_q_dfs_enum(&q_d, level, ctr);
 
  /* turn parameters into data stream */
  if(dfs_io_q_dfs_enum("", &q_d, &buf, 0) &&
     rpc_con_pipe_req(con, DFS_ENUM, &buf, &rbuf))
    {
      DFS_R_DFS_ENUM r_d;
      BOOL p;
      ZERO_STRUCT(r_d);
      
      r_d.ctr = ctr;
      dfs_io_r_dfs_enum("", &r_d, &rbuf, 0);
      p = (rbuf.offset != 0);
      
      if(p && r_d.status!=0)
	{
	  DEBUG(1,("DFS_ENUM: %s\n",get_nt_error_msg(r_d.status)));
	  res = r_d.status;
	  p = False;
	}
      
      if(p)
	valid_cfg = True;
    }
  prs_free_data(&rbuf);
  prs_free_data(&buf);
  cli_connection_unlink(con);
  if(valid_cfg)
    return 0;
  else
    return res;
}