2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines for Dfs
4 * Copyright (C) Shirish Kalele 2000.
5 * Copyright (C) Jeremy Allison 2001.
6 * Copyright (C) Jelmer Vernooij 2005-2006.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* This is the implementation of the dfs pipe. */
28 #define DBGC_CLASS DBGC_MSDFS
30 /* This function does not return a WERROR or NTSTATUS code but rather 1 if
31 dfs exists, or 0 otherwise. */
33 void _dfs_GetManagerVersion(pipes_struct *p, struct dfs_GetManagerVersion *r)
36 *r->out.exist_flag = 1;
38 *r->out.exist_flag = 0;
41 WERROR _dfs_Add(pipes_struct *p, struct dfs_Add *r)
43 struct junction_map jn;
44 struct referral* old_referral_list = NULL;
45 BOOL self_ref = False;
51 if (p->pipe_user.ut.uid != 0) {
52 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
53 return WERR_ACCESS_DENIED;
56 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
57 r->in.path, r->in.server, r->in.share));
59 pstrcpy(altpath, r->in.server);
60 pstrcat(altpath, "\\");
61 pstrcat(altpath, r->in.share);
63 /* The following call can change the cwd. */
64 if(get_referred_path(p->mem_ctx, r->in.path, &jn, &consumedcnt, &self_ref)) {
66 jn.referral_count += 1;
67 old_referral_list = jn.referral_list;
69 jn.referral_count = 1;
72 vfs_ChDir(p->conn,p->conn->connectpath);
74 jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count);
75 if(jn.referral_list == NULL) {
76 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
77 return WERR_DFS_INTERNAL_ERROR;
80 if(old_referral_list) {
81 memcpy(jn.referral_list, old_referral_list, sizeof(struct referral)*jn.referral_count-1);
84 jn.referral_list[jn.referral_count-1].proximity = 0;
85 jn.referral_list[jn.referral_count-1].ttl = REFERRAL_TTL;
87 pstrcpy(jn.referral_list[jn.referral_count-1].alternate_path, altpath);
89 if(!create_msdfs_link(&jn, exists)) {
90 vfs_ChDir(p->conn,p->conn->connectpath);
91 return WERR_DFS_CANT_CREATE_JUNCT;
93 vfs_ChDir(p->conn,p->conn->connectpath);
98 WERROR _dfs_Remove(pipes_struct *p, struct dfs_Remove *r)
100 struct junction_map jn;
101 BOOL self_ref = False;
107 if (p->pipe_user.ut.uid != 0) {
108 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
109 return WERR_ACCESS_DENIED;
112 if (r->in.server && r->in.share) {
113 pstrcpy(altpath, r->in.server);
114 pstrcat(altpath, "\\");
115 pstrcat(altpath, r->in.share);
119 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
120 r->in.path, r->in.server, r->in.share));
122 if(!get_referred_path(p->mem_ctx, r->in.path, &jn, &consumedcnt, &self_ref)) {
123 return WERR_DFS_NO_SUCH_VOL;
126 /* if no server-share pair given, remove the msdfs link completely */
127 if(!r->in.server && !r->in.share) {
128 if(!remove_msdfs_link(&jn)) {
129 vfs_ChDir(p->conn,p->conn->connectpath);
130 return WERR_DFS_NO_SUCH_VOL;
132 vfs_ChDir(p->conn,p->conn->connectpath);
135 /* compare each referral in the list with the one to remove */
136 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath, jn.referral_count));
137 for(i=0;i<jn.referral_count;i++) {
139 pstrcpy(refpath,jn.referral_list[i].alternate_path);
140 trim_char(refpath, '\\', '\\');
141 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath));
142 if(strequal(refpath, altpath)) {
143 *(jn.referral_list[i].alternate_path)='\0';
144 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
151 return WERR_DFS_NO_SUCH_SHARE;
154 /* Only one referral, remove it */
155 if(jn.referral_count == 1) {
156 if(!remove_msdfs_link(&jn)) {
157 vfs_ChDir(p->conn,p->conn->connectpath);
158 return WERR_DFS_NO_SUCH_VOL;
161 if(!create_msdfs_link(&jn, True)) {
162 vfs_ChDir(p->conn,p->conn->connectpath);
163 return WERR_DFS_CANT_CREATE_JUNCT;
166 vfs_ChDir(p->conn,p->conn->connectpath);
172 static BOOL init_reply_dfs_info_1(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info1* dfs1)
174 dfs1->path = talloc_asprintf(mem_ctx,
175 "\\\\%s\\%s\\%s", global_myname(),
176 j->service_name, j->volume_name);
177 if (dfs1->path == NULL)
180 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1->path));
184 static BOOL init_reply_dfs_info_2(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info2* dfs2)
186 dfs2->path = talloc_asprintf(mem_ctx,
187 "\\\\%s\\%s\\%s", global_myname(), j->service_name, j->volume_name);
188 if (dfs2->path == NULL)
190 dfs2->comment = talloc_strdup(mem_ctx, j->comment);
191 dfs2->state = 1; /* set up state of dfs junction as OK */
192 dfs2->num_stores = j->referral_count;
196 static BOOL init_reply_dfs_info_3(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info3* dfs3)
199 if (j->volume_name[0] == '\0')
200 dfs3->path = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
201 global_myname(), j->service_name);
203 dfs3->path = talloc_asprintf(mem_ctx, "\\\\%s\\%s\\%s", global_myname(),
204 j->service_name, j->volume_name);
206 if (dfs3->path == NULL)
209 dfs3->comment = talloc_strdup(mem_ctx, j->comment);
211 dfs3->num_stores = j->referral_count;
213 /* also enumerate the stores */
214 dfs3->stores = TALLOC_ARRAY(mem_ctx, struct dfs_StorageInfo, j->referral_count);
218 memset(dfs3->stores, '\0', j->referral_count * sizeof(struct dfs_StorageInfo));
220 for(ii=0;ii<j->referral_count;ii++) {
223 struct dfs_StorageInfo* stor = &(dfs3->stores[ii]);
224 struct referral* ref = &(j->referral_list[ii]);
226 pstrcpy(path, ref->alternate_path);
227 trim_char(path,'\\','\0');
228 p = strrchr_m(path,'\\');
230 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path));
234 DEBUG(5,("storage %d: %s.%s\n",ii,path,p+1));
235 stor->state = 2; /* set all stores as ONLINE */
236 stor->server = talloc_strdup(mem_ctx, path);
237 stor->share = talloc_strdup(mem_ctx, p+1);
242 static BOOL init_reply_dfs_info_100(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info100* dfs100)
244 dfs100->comment = talloc_strdup(mem_ctx, j->comment);
249 WERROR _dfs_Enum(pipes_struct *p, struct dfs_Enum *r)
251 struct junction_map jn[MAX_MSDFS_JUNCTIONS];
255 num_jn = enum_msdfs_links(p->mem_ctx, jn, ARRAY_SIZE(jn));
256 vfs_ChDir(p->conn,p->conn->connectpath);
258 DEBUG(5,("_dfs_Enum: %d junctions found in Dfs, doing level %d\n", num_jn, r->in.level));
260 *r->out.total = num_jn;
262 /* Create the return array */
263 switch (r->in.level) {
265 if ((r->out.info->e.info1->s = TALLOC_ARRAY(p->mem_ctx, struct dfs_Info1, num_jn)) == NULL) {
268 r->out.info->e.info1->count = num_jn;
271 if ((r->out.info->e.info2->s = TALLOC_ARRAY(p->mem_ctx, struct dfs_Info2, num_jn)) == NULL) {
274 r->out.info->e.info2->count = num_jn;
277 if ((r->out.info->e.info3->s = TALLOC_ARRAY(p->mem_ctx, struct dfs_Info3, num_jn)) == NULL) {
280 r->out.info->e.info3->count = num_jn;
283 return WERR_INVALID_PARAM;
286 for (i = 0; i < num_jn; i++) {
287 switch (r->in.level) {
289 init_reply_dfs_info_1(p->mem_ctx, &jn[i], &r->out.info->e.info1->s[i]);
292 init_reply_dfs_info_2(p->mem_ctx, &jn[i], &r->out.info->e.info2->s[i]);
295 init_reply_dfs_info_3(p->mem_ctx, &jn[i], &r->out.info->e.info3->s[i]);
298 return WERR_INVALID_PARAM;
305 WERROR _dfs_GetInfo(pipes_struct *p, struct dfs_GetInfo *r)
307 int consumedcnt = sizeof(pstring);
308 struct junction_map jn;
309 BOOL self_ref = False;
312 if(!create_junction(r->in.path, &jn))
313 return WERR_DFS_NO_SUCH_SERVER;
315 /* The following call can change the cwd. */
316 if(!get_referred_path(p->mem_ctx, r->in.path, &jn, &consumedcnt, &self_ref) || consumedcnt < strlen(r->in.path)) {
317 vfs_ChDir(p->conn,p->conn->connectpath);
318 return WERR_DFS_NO_SUCH_VOL;
321 vfs_ChDir(p->conn,p->conn->connectpath);
323 switch (r->in.level) {
324 case 1: ret = init_reply_dfs_info_1(p->mem_ctx, &jn, r->out.info->info1); break;
325 case 2: ret = init_reply_dfs_info_2(p->mem_ctx, &jn, r->out.info->info2); break;
326 case 3: ret = init_reply_dfs_info_3(p->mem_ctx, &jn, r->out.info->info3); break;
327 case 100: ret = init_reply_dfs_info_100(p->mem_ctx, &jn, r->out.info->info100); break;
329 r->out.info->info1 = NULL;
330 return WERR_INVALID_PARAM;
334 return WERR_INVALID_PARAM;
339 WERROR _dfs_SetInfo(pipes_struct *p, struct dfs_SetInfo *r)
341 /* FIXME: Implement your code here */
342 p->rng_fault_state = True;
343 return WERR_NOT_SUPPORTED;
346 WERROR _dfs_Rename(pipes_struct *p, struct dfs_Rename *r)
348 /* FIXME: Implement your code here */
349 p->rng_fault_state = True;
350 return WERR_NOT_SUPPORTED;
353 WERROR _dfs_Move(pipes_struct *p, struct dfs_Move *r)
355 /* FIXME: Implement your code here */
356 p->rng_fault_state = True;
357 return WERR_NOT_SUPPORTED;
360 WERROR _dfs_ManagerGetConfigInfo(pipes_struct *p, struct dfs_ManagerGetConfigInfo *r)
362 /* FIXME: Implement your code here */
363 p->rng_fault_state = True;
364 return WERR_NOT_SUPPORTED;
367 WERROR _dfs_ManagerSendSiteInfo(pipes_struct *p, struct dfs_ManagerSendSiteInfo *r)
369 /* FIXME: Implement your code here */
370 p->rng_fault_state = True;
371 return WERR_NOT_SUPPORTED;
374 WERROR _dfs_AddFtRoot(pipes_struct *p, struct dfs_AddFtRoot *r)
376 /* FIXME: Implement your code here */
377 p->rng_fault_state = True;
378 return WERR_NOT_SUPPORTED;
381 WERROR _dfs_RemoveFtRoot(pipes_struct *p, struct dfs_RemoveFtRoot *r)
383 /* FIXME: Implement your code here */
384 p->rng_fault_state = True;
385 return WERR_NOT_SUPPORTED;
388 WERROR _dfs_AddStdRoot(pipes_struct *p, struct dfs_AddStdRoot *r)
390 /* FIXME: Implement your code here */
391 p->rng_fault_state = True;
392 return WERR_NOT_SUPPORTED;
395 WERROR _dfs_RemoveStdRoot(pipes_struct *p, struct dfs_RemoveStdRoot *r)
397 /* FIXME: Implement your code here */
398 p->rng_fault_state = True;
399 return WERR_NOT_SUPPORTED;
402 WERROR _dfs_ManagerInitialize(pipes_struct *p, struct dfs_ManagerInitialize *r)
404 /* FIXME: Implement your code here */
405 p->rng_fault_state = True;
406 return WERR_NOT_SUPPORTED;
409 WERROR _dfs_AddStdRootForced(pipes_struct *p, struct dfs_AddStdRootForced *r)
411 /* FIXME: Implement your code here */
412 p->rng_fault_state = True;
413 return WERR_NOT_SUPPORTED;
416 WERROR _dfs_GetDcAddress(pipes_struct *p, struct dfs_GetDcAddress *r)
418 /* FIXME: Implement your code here */
419 p->rng_fault_state = True;
420 return WERR_NOT_SUPPORTED;
423 WERROR _dfs_SetDcAddress(pipes_struct *p, struct dfs_SetDcAddress *r)
425 /* FIXME: Implement your code here */
426 p->rng_fault_state = True;
427 return WERR_NOT_SUPPORTED;
430 WERROR _dfs_FlushFtTable(pipes_struct *p, struct dfs_FlushFtTable *r)
432 /* FIXME: Implement your code here */
433 p->rng_fault_state = True;
434 return WERR_NOT_SUPPORTED;
437 WERROR _dfs_Add2(pipes_struct *p, struct dfs_Add2 *r)
439 /* FIXME: Implement your code here */
440 p->rng_fault_state = True;
441 return WERR_NOT_SUPPORTED;
444 WERROR _dfs_Remove2(pipes_struct *p, struct dfs_Remove2 *r)
446 /* FIXME: Implement your code here */
447 p->rng_fault_state = True;
448 return WERR_NOT_SUPPORTED;
451 WERROR _dfs_EnumEx(pipes_struct *p, struct dfs_EnumEx *r)
453 /* FIXME: Implement your code here */
454 p->rng_fault_state = True;
455 return WERR_NOT_SUPPORTED;
458 WERROR _dfs_SetInfo2(pipes_struct *p, struct dfs_SetInfo2 *r)
460 /* FIXME: Implement your code here */
461 p->rng_fault_state = True;
462 return WERR_NOT_SUPPORTED;