summaryrefslogtreecommitdiffstats
path: root/source/rpc_client/cli_dfs.c
blob: c6ef69190af668f2939124faf44d367867b00cd1 (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
#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;
  prs_struct *ps = &rbuf;
  DFS_R_DFS_EXIST q_d;
  uint32 dfs_exist_flag = 0;
  
  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;
}