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-2007.
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 3 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, see <http://www.gnu.org/licenses/>.
22 /* This is the implementation of the dfs pipe. */
25 #include "../librpc/gen_ndr/srv_dfs.h"
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
)
35 if (lp_host_msdfs()) {
36 *r
->out
.version
= DFS_MANAGER_VERSION_NT4
;
38 *r
->out
.version
= (enum dfs_ManagerVersion
)0;
42 WERROR
_dfs_Add(pipes_struct
*p
, struct dfs_Add
*r
)
44 struct junction_map
*jn
= NULL
;
45 struct referral
*old_referral_list
= NULL
;
46 bool self_ref
= False
;
50 TALLOC_CTX
*ctx
= talloc_tos();
52 if (p
->server_info
->utok
.uid
!= sec_initial_uid()) {
53 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
54 return WERR_ACCESS_DENIED
;
57 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
62 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
63 r
->in
.path
, r
->in
.server
, r
->in
.share
));
65 altpath
= talloc_asprintf(ctx
, "%s\\%s",
72 /* The following call can change the cwd. */
73 status
= get_referred_path(ctx
, r
->in
.path
, jn
,
74 &consumedcnt
, &self_ref
);
75 if(!NT_STATUS_IS_OK(status
)) {
76 return ntstatus_to_werror(status
);
79 jn
->referral_count
+= 1;
80 old_referral_list
= jn
->referral_list
;
82 if (jn
->referral_count
< 1) {
86 jn
->referral_list
= TALLOC_ARRAY(ctx
, struct referral
, jn
->referral_count
);
87 if(jn
->referral_list
== NULL
) {
88 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
89 return WERR_DFS_INTERNAL_ERROR
;
92 if(old_referral_list
&& jn
->referral_list
) {
93 memcpy(jn
->referral_list
, old_referral_list
,
94 sizeof(struct referral
)*jn
->referral_count
-1);
97 jn
->referral_list
[jn
->referral_count
-1].proximity
= 0;
98 jn
->referral_list
[jn
->referral_count
-1].ttl
= REFERRAL_TTL
;
99 jn
->referral_list
[jn
->referral_count
-1].alternate_path
= altpath
;
101 if(!create_msdfs_link(jn
)) {
102 return WERR_DFS_CANT_CREATE_JUNCT
;
108 WERROR
_dfs_Remove(pipes_struct
*p
, struct dfs_Remove
*r
)
110 struct junction_map
*jn
= NULL
;
111 bool self_ref
= False
;
114 TALLOC_CTX
*ctx
= talloc_tos();
115 char *altpath
= NULL
;
117 if (p
->server_info
->utok
.uid
!= sec_initial_uid()) {
118 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
119 return WERR_ACCESS_DENIED
;
122 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
127 if (r
->in
.servername
&& r
->in
.sharename
) {
128 altpath
= talloc_asprintf(ctx
, "%s\\%s",
135 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
136 r
->in
.dfs_entry_path
, r
->in
.servername
, r
->in
.sharename
));
139 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
, jn
,
140 &consumedcnt
, &self_ref
))) {
141 return WERR_DFS_NO_SUCH_VOL
;
144 /* if no server-share pair given, remove the msdfs link completely */
145 if(!r
->in
.servername
&& !r
->in
.sharename
) {
146 if(!remove_msdfs_link(jn
)) {
147 return WERR_DFS_NO_SUCH_VOL
;
151 /* compare each referral in the list with the one to remove */
152 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath
, jn
->referral_count
));
153 for(i
=0;i
<jn
->referral_count
;i
++) {
154 char *refpath
= talloc_strdup(ctx
,
155 jn
->referral_list
[i
].alternate_path
);
159 trim_char(refpath
, '\\', '\\');
160 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath
));
161 if(strequal(refpath
, altpath
)) {
162 *(jn
->referral_list
[i
].alternate_path
)='\0';
163 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
170 return WERR_DFS_NO_SUCH_SHARE
;
173 /* Only one referral, remove it */
174 if(jn
->referral_count
== 1) {
175 if(!remove_msdfs_link(jn
)) {
176 return WERR_DFS_NO_SUCH_VOL
;
179 if(!create_msdfs_link(jn
)) {
180 return WERR_DFS_CANT_CREATE_JUNCT
;
188 static bool init_reply_dfs_info_1(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
,struct dfs_Info1
* dfs1
)
190 dfs1
->path
= talloc_asprintf(mem_ctx
,
191 "\\\\%s\\%s\\%s", global_myname(),
192 j
->service_name
, j
->volume_name
);
193 if (dfs1
->path
== NULL
)
196 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1
->path
));
200 static bool init_reply_dfs_info_2(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info2
* dfs2
)
202 dfs2
->path
= talloc_asprintf(mem_ctx
,
203 "\\\\%s\\%s\\%s", global_myname(), j
->service_name
, j
->volume_name
);
204 if (dfs2
->path
== NULL
)
206 dfs2
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
207 dfs2
->state
= 1; /* set up state of dfs junction as OK */
208 dfs2
->num_stores
= j
->referral_count
;
212 static bool init_reply_dfs_info_3(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info3
* dfs3
)
215 if (j
->volume_name
[0] == '\0')
216 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
217 global_myname(), j
->service_name
);
219 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s\\%s", global_myname(),
220 j
->service_name
, j
->volume_name
);
222 if (dfs3
->path
== NULL
)
225 dfs3
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
227 dfs3
->num_stores
= j
->referral_count
;
229 /* also enumerate the stores */
230 if (j
->referral_count
) {
231 dfs3
->stores
= TALLOC_ARRAY(mem_ctx
, struct dfs_StorageInfo
, j
->referral_count
);
234 memset(dfs3
->stores
, '\0', j
->referral_count
* sizeof(struct dfs_StorageInfo
));
239 for(ii
=0;ii
<j
->referral_count
;ii
++) {
242 struct dfs_StorageInfo
* stor
= &(dfs3
->stores
[ii
]);
243 struct referral
* ref
= &(j
->referral_list
[ii
]);
245 path
= talloc_strdup(mem_ctx
, ref
->alternate_path
);
249 trim_char(path
,'\\','\0');
250 p
= strrchr_m(path
,'\\');
252 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path
));
256 DEBUG(5,("storage %d: %s.%s\n",ii
,path
,p
+1));
257 stor
->state
= 2; /* set all stores as ONLINE */
258 stor
->server
= talloc_strdup(mem_ctx
, path
);
259 stor
->share
= talloc_strdup(mem_ctx
, p
+1);
264 static bool init_reply_dfs_info_100(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info100
* dfs100
)
266 dfs100
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
270 WERROR
_dfs_Enum(pipes_struct
*p
, struct dfs_Enum
*r
)
272 struct junction_map
*jn
= NULL
;
275 TALLOC_CTX
*ctx
= talloc_tos();
277 jn
= enum_msdfs_links(ctx
, &num_jn
);
278 if (!jn
|| num_jn
== 0) {
283 DEBUG(5,("_dfs_Enum: %u junctions found in Dfs, doing level %d\n",
284 (unsigned int)num_jn
, r
->in
.level
));
286 *r
->out
.total
= num_jn
;
288 /* Create the return array */
289 switch (r
->in
.level
) {
292 if ((r
->out
.info
->e
.info1
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info1
, num_jn
)) == NULL
) {
296 r
->out
.info
->e
.info1
->s
= NULL
;
298 r
->out
.info
->e
.info1
->count
= num_jn
;
302 if ((r
->out
.info
->e
.info2
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info2
, num_jn
)) == NULL
) {
306 r
->out
.info
->e
.info2
->s
= NULL
;
308 r
->out
.info
->e
.info2
->count
= num_jn
;
312 if ((r
->out
.info
->e
.info3
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info3
, num_jn
)) == NULL
) {
316 r
->out
.info
->e
.info3
->s
= NULL
;
318 r
->out
.info
->e
.info3
->count
= num_jn
;
321 return WERR_INVALID_PARAM
;
324 for (i
= 0; i
< num_jn
; i
++) {
325 switch (r
->in
.level
) {
327 init_reply_dfs_info_1(ctx
, &jn
[i
], &r
->out
.info
->e
.info1
->s
[i
]);
330 init_reply_dfs_info_2(ctx
, &jn
[i
], &r
->out
.info
->e
.info2
->s
[i
]);
333 init_reply_dfs_info_3(ctx
, &jn
[i
], &r
->out
.info
->e
.info3
->s
[i
]);
336 return WERR_INVALID_PARAM
;
343 WERROR
_dfs_GetInfo(pipes_struct
*p
, struct dfs_GetInfo
*r
)
345 int consumedcnt
= strlen(r
->in
.dfs_entry_path
);
346 struct junction_map
*jn
= NULL
;
347 bool self_ref
= False
;
348 TALLOC_CTX
*ctx
= talloc_tos();
351 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
356 if(!create_junction(ctx
, r
->in
.dfs_entry_path
, jn
)) {
357 return WERR_DFS_NO_SUCH_SERVER
;
360 /* The following call can change the cwd. */
361 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
,
362 jn
, &consumedcnt
, &self_ref
)) ||
363 consumedcnt
< strlen(r
->in
.dfs_entry_path
)) {
364 return WERR_DFS_NO_SUCH_VOL
;
367 switch (r
->in
.level
) {
369 r
->out
.info
->info1
= TALLOC_ZERO_P(ctx
,struct dfs_Info1
);
370 if (!r
->out
.info
->info1
) {
373 ret
= init_reply_dfs_info_1(ctx
, jn
, r
->out
.info
->info1
);
376 r
->out
.info
->info2
= TALLOC_ZERO_P(ctx
,struct dfs_Info2
);
377 if (!r
->out
.info
->info2
) {
380 ret
= init_reply_dfs_info_2(ctx
, jn
, r
->out
.info
->info2
);
383 r
->out
.info
->info3
= TALLOC_ZERO_P(ctx
,struct dfs_Info3
);
384 if (!r
->out
.info
->info3
) {
387 ret
= init_reply_dfs_info_3(ctx
, jn
, r
->out
.info
->info3
);
390 r
->out
.info
->info100
= TALLOC_ZERO_P(ctx
,struct dfs_Info100
);
391 if (!r
->out
.info
->info100
) {
394 ret
= init_reply_dfs_info_100(ctx
, jn
, r
->out
.info
->info100
);
397 r
->out
.info
->info1
= NULL
;
398 return WERR_INVALID_PARAM
;
402 return WERR_INVALID_PARAM
;
407 WERROR
_dfs_SetInfo(pipes_struct
*p
, struct dfs_SetInfo
*r
)
409 /* FIXME: Implement your code here */
410 p
->rng_fault_state
= True
;
411 return WERR_NOT_SUPPORTED
;
414 WERROR
_dfs_Rename(pipes_struct
*p
, struct dfs_Rename
*r
)
416 /* FIXME: Implement your code here */
417 p
->rng_fault_state
= True
;
418 return WERR_NOT_SUPPORTED
;
421 WERROR
_dfs_Move(pipes_struct
*p
, struct dfs_Move
*r
)
423 /* FIXME: Implement your code here */
424 p
->rng_fault_state
= True
;
425 return WERR_NOT_SUPPORTED
;
428 WERROR
_dfs_ManagerGetConfigInfo(pipes_struct
*p
, struct dfs_ManagerGetConfigInfo
*r
)
430 /* FIXME: Implement your code here */
431 p
->rng_fault_state
= True
;
432 return WERR_NOT_SUPPORTED
;
435 WERROR
_dfs_ManagerSendSiteInfo(pipes_struct
*p
, struct dfs_ManagerSendSiteInfo
*r
)
437 /* FIXME: Implement your code here */
438 p
->rng_fault_state
= True
;
439 return WERR_NOT_SUPPORTED
;
442 WERROR
_dfs_AddFtRoot(pipes_struct
*p
, struct dfs_AddFtRoot
*r
)
444 /* FIXME: Implement your code here */
445 p
->rng_fault_state
= True
;
446 return WERR_NOT_SUPPORTED
;
449 WERROR
_dfs_RemoveFtRoot(pipes_struct
*p
, struct dfs_RemoveFtRoot
*r
)
451 /* FIXME: Implement your code here */
452 p
->rng_fault_state
= True
;
453 return WERR_NOT_SUPPORTED
;
456 WERROR
_dfs_AddStdRoot(pipes_struct
*p
, struct dfs_AddStdRoot
*r
)
458 /* FIXME: Implement your code here */
459 p
->rng_fault_state
= True
;
460 return WERR_NOT_SUPPORTED
;
463 WERROR
_dfs_RemoveStdRoot(pipes_struct
*p
, struct dfs_RemoveStdRoot
*r
)
465 /* FIXME: Implement your code here */
466 p
->rng_fault_state
= True
;
467 return WERR_NOT_SUPPORTED
;
470 WERROR
_dfs_ManagerInitialize(pipes_struct
*p
, struct dfs_ManagerInitialize
*r
)
472 /* FIXME: Implement your code here */
473 p
->rng_fault_state
= True
;
474 return WERR_NOT_SUPPORTED
;
477 WERROR
_dfs_AddStdRootForced(pipes_struct
*p
, struct dfs_AddStdRootForced
*r
)
479 /* FIXME: Implement your code here */
480 p
->rng_fault_state
= True
;
481 return WERR_NOT_SUPPORTED
;
484 WERROR
_dfs_GetDcAddress(pipes_struct
*p
, struct dfs_GetDcAddress
*r
)
486 /* FIXME: Implement your code here */
487 p
->rng_fault_state
= True
;
488 return WERR_NOT_SUPPORTED
;
491 WERROR
_dfs_SetDcAddress(pipes_struct
*p
, struct dfs_SetDcAddress
*r
)
493 /* FIXME: Implement your code here */
494 p
->rng_fault_state
= True
;
495 return WERR_NOT_SUPPORTED
;
498 WERROR
_dfs_FlushFtTable(pipes_struct
*p
, struct dfs_FlushFtTable
*r
)
500 /* FIXME: Implement your code here */
501 p
->rng_fault_state
= True
;
502 return WERR_NOT_SUPPORTED
;
505 WERROR
_dfs_Add2(pipes_struct
*p
, struct dfs_Add2
*r
)
507 /* FIXME: Implement your code here */
508 p
->rng_fault_state
= True
;
509 return WERR_NOT_SUPPORTED
;
512 WERROR
_dfs_Remove2(pipes_struct
*p
, struct dfs_Remove2
*r
)
514 /* FIXME: Implement your code here */
515 p
->rng_fault_state
= True
;
516 return WERR_NOT_SUPPORTED
;
519 WERROR
_dfs_EnumEx(pipes_struct
*p
, struct dfs_EnumEx
*r
)
521 /* FIXME: Implement your code here */
522 p
->rng_fault_state
= True
;
523 return WERR_NOT_SUPPORTED
;
526 WERROR
_dfs_SetInfo2(pipes_struct
*p
, struct dfs_SetInfo2
*r
)
528 /* FIXME: Implement your code here */
529 p
->rng_fault_state
= True
;
530 return WERR_NOT_SUPPORTED
;