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. */
26 #include "../librpc/gen_ndr/srv_dfs.h"
28 #include "smbd/smbd.h"
32 #define DBGC_CLASS DBGC_MSDFS
34 /* This function does not return a WERROR or NTSTATUS code but rather 1 if
35 dfs exists, or 0 otherwise. */
37 void _dfs_GetManagerVersion(struct pipes_struct
*p
, struct dfs_GetManagerVersion
*r
)
39 if (lp_host_msdfs()) {
40 *r
->out
.version
= DFS_MANAGER_VERSION_NT4
;
42 *r
->out
.version
= (enum dfs_ManagerVersion
)0;
46 WERROR
_dfs_Add(struct pipes_struct
*p
, struct dfs_Add
*r
)
48 struct junction_map
*jn
= NULL
;
49 struct referral
*old_referral_list
= NULL
;
50 bool self_ref
= False
;
54 TALLOC_CTX
*ctx
= talloc_tos();
56 if (p
->session_info
->utok
.uid
!= sec_initial_uid()) {
57 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
58 return WERR_ACCESS_DENIED
;
61 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
66 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
67 r
->in
.path
, r
->in
.server
, r
->in
.share
));
69 altpath
= talloc_asprintf(ctx
, "%s\\%s",
76 /* The following call can change the cwd. */
77 status
= get_referred_path(ctx
, r
->in
.path
, jn
,
78 &consumedcnt
, &self_ref
);
79 if(!NT_STATUS_IS_OK(status
)) {
80 return ntstatus_to_werror(status
);
83 jn
->referral_count
+= 1;
84 old_referral_list
= jn
->referral_list
;
86 if (jn
->referral_count
< 1) {
90 jn
->referral_list
= TALLOC_ARRAY(ctx
, struct referral
, jn
->referral_count
);
91 if(jn
->referral_list
== NULL
) {
92 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
93 return WERR_DFS_INTERNAL_ERROR
;
96 if(old_referral_list
&& jn
->referral_list
) {
97 memcpy(jn
->referral_list
, old_referral_list
,
98 sizeof(struct referral
)*jn
->referral_count
-1);
101 jn
->referral_list
[jn
->referral_count
-1].proximity
= 0;
102 jn
->referral_list
[jn
->referral_count
-1].ttl
= REFERRAL_TTL
;
103 jn
->referral_list
[jn
->referral_count
-1].alternate_path
= altpath
;
105 if(!create_msdfs_link(jn
)) {
106 return WERR_DFS_CANT_CREATE_JUNCT
;
112 WERROR
_dfs_Remove(struct pipes_struct
*p
, struct dfs_Remove
*r
)
114 struct junction_map
*jn
= NULL
;
115 bool self_ref
= False
;
118 TALLOC_CTX
*ctx
= talloc_tos();
119 char *altpath
= NULL
;
121 if (p
->session_info
->utok
.uid
!= sec_initial_uid()) {
122 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
123 return WERR_ACCESS_DENIED
;
126 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
131 if (r
->in
.servername
&& r
->in
.sharename
) {
132 altpath
= talloc_asprintf(ctx
, "%s\\%s",
139 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
140 r
->in
.dfs_entry_path
, r
->in
.servername
, r
->in
.sharename
));
143 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
, jn
,
144 &consumedcnt
, &self_ref
))) {
145 return WERR_DFS_NO_SUCH_VOL
;
148 /* if no server-share pair given, remove the msdfs link completely */
149 if(!r
->in
.servername
&& !r
->in
.sharename
) {
150 if(!remove_msdfs_link(jn
)) {
151 return WERR_DFS_NO_SUCH_VOL
;
155 /* compare each referral in the list with the one to remove */
156 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath
, jn
->referral_count
));
157 for(i
=0;i
<jn
->referral_count
;i
++) {
158 char *refpath
= talloc_strdup(ctx
,
159 jn
->referral_list
[i
].alternate_path
);
163 trim_char(refpath
, '\\', '\\');
164 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath
));
165 if(strequal(refpath
, altpath
)) {
166 *(jn
->referral_list
[i
].alternate_path
)='\0';
167 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
174 return WERR_DFS_NO_SUCH_SHARE
;
177 /* Only one referral, remove it */
178 if(jn
->referral_count
== 1) {
179 if(!remove_msdfs_link(jn
)) {
180 return WERR_DFS_NO_SUCH_VOL
;
183 if(!create_msdfs_link(jn
)) {
184 return WERR_DFS_CANT_CREATE_JUNCT
;
192 static bool init_reply_dfs_info_1(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
,struct dfs_Info1
* dfs1
)
194 dfs1
->path
= talloc_asprintf(mem_ctx
,
195 "\\\\%s\\%s\\%s", global_myname(),
196 j
->service_name
, j
->volume_name
);
197 if (dfs1
->path
== NULL
)
200 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1
->path
));
204 static bool init_reply_dfs_info_2(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info2
* dfs2
)
206 dfs2
->path
= talloc_asprintf(mem_ctx
,
207 "\\\\%s\\%s\\%s", global_myname(), j
->service_name
, j
->volume_name
);
208 if (dfs2
->path
== NULL
)
210 dfs2
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
211 dfs2
->state
= 1; /* set up state of dfs junction as OK */
212 dfs2
->num_stores
= j
->referral_count
;
216 static bool init_reply_dfs_info_3(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info3
* dfs3
)
219 if (j
->volume_name
[0] == '\0')
220 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
221 global_myname(), j
->service_name
);
223 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s\\%s", global_myname(),
224 j
->service_name
, j
->volume_name
);
226 if (dfs3
->path
== NULL
)
229 dfs3
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
231 dfs3
->num_stores
= j
->referral_count
;
233 /* also enumerate the stores */
234 if (j
->referral_count
) {
235 dfs3
->stores
= TALLOC_ARRAY(mem_ctx
, struct dfs_StorageInfo
, j
->referral_count
);
238 memset(dfs3
->stores
, '\0', j
->referral_count
* sizeof(struct dfs_StorageInfo
));
243 for(ii
=0;ii
<j
->referral_count
;ii
++) {
246 struct dfs_StorageInfo
* stor
= &(dfs3
->stores
[ii
]);
247 struct referral
* ref
= &(j
->referral_list
[ii
]);
249 path
= talloc_strdup(mem_ctx
, ref
->alternate_path
);
253 trim_char(path
,'\\','\0');
254 p
= strrchr_m(path
,'\\');
256 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path
));
260 DEBUG(5,("storage %d: %s.%s\n",ii
,path
,p
+1));
261 stor
->state
= 2; /* set all stores as ONLINE */
262 stor
->server
= talloc_strdup(mem_ctx
, path
);
263 stor
->share
= talloc_strdup(mem_ctx
, p
+1);
268 static bool init_reply_dfs_info_100(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info100
* dfs100
)
270 dfs100
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
274 WERROR
_dfs_Enum(struct pipes_struct
*p
, struct dfs_Enum
*r
)
276 struct junction_map
*jn
= NULL
;
279 TALLOC_CTX
*ctx
= talloc_tos();
281 jn
= enum_msdfs_links(ctx
, &num_jn
);
282 if (!jn
|| num_jn
== 0) {
287 DEBUG(5,("_dfs_Enum: %u junctions found in Dfs, doing level %d\n",
288 (unsigned int)num_jn
, r
->in
.level
));
290 *r
->out
.total
= num_jn
;
292 /* Create the return array */
293 switch (r
->in
.level
) {
296 if ((r
->out
.info
->e
.info1
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info1
, num_jn
)) == NULL
) {
300 r
->out
.info
->e
.info1
->s
= NULL
;
302 r
->out
.info
->e
.info1
->count
= num_jn
;
306 if ((r
->out
.info
->e
.info2
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info2
, num_jn
)) == NULL
) {
310 r
->out
.info
->e
.info2
->s
= NULL
;
312 r
->out
.info
->e
.info2
->count
= num_jn
;
316 if ((r
->out
.info
->e
.info3
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info3
, num_jn
)) == NULL
) {
320 r
->out
.info
->e
.info3
->s
= NULL
;
322 r
->out
.info
->e
.info3
->count
= num_jn
;
325 return WERR_INVALID_PARAM
;
328 for (i
= 0; i
< num_jn
; i
++) {
329 switch (r
->in
.level
) {
331 init_reply_dfs_info_1(ctx
, &jn
[i
], &r
->out
.info
->e
.info1
->s
[i
]);
334 init_reply_dfs_info_2(ctx
, &jn
[i
], &r
->out
.info
->e
.info2
->s
[i
]);
337 init_reply_dfs_info_3(ctx
, &jn
[i
], &r
->out
.info
->e
.info3
->s
[i
]);
340 return WERR_INVALID_PARAM
;
347 WERROR
_dfs_GetInfo(struct pipes_struct
*p
, struct dfs_GetInfo
*r
)
349 int consumedcnt
= strlen(r
->in
.dfs_entry_path
);
350 struct junction_map
*jn
= NULL
;
351 bool self_ref
= False
;
352 TALLOC_CTX
*ctx
= talloc_tos();
355 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
360 if(!create_junction(ctx
, r
->in
.dfs_entry_path
, jn
)) {
361 return WERR_DFS_NO_SUCH_SERVER
;
364 /* The following call can change the cwd. */
365 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
,
366 jn
, &consumedcnt
, &self_ref
)) ||
367 consumedcnt
< strlen(r
->in
.dfs_entry_path
)) {
368 return WERR_DFS_NO_SUCH_VOL
;
371 switch (r
->in
.level
) {
373 r
->out
.info
->info1
= TALLOC_ZERO_P(ctx
,struct dfs_Info1
);
374 if (!r
->out
.info
->info1
) {
377 ret
= init_reply_dfs_info_1(ctx
, jn
, r
->out
.info
->info1
);
380 r
->out
.info
->info2
= TALLOC_ZERO_P(ctx
,struct dfs_Info2
);
381 if (!r
->out
.info
->info2
) {
384 ret
= init_reply_dfs_info_2(ctx
, jn
, r
->out
.info
->info2
);
387 r
->out
.info
->info3
= TALLOC_ZERO_P(ctx
,struct dfs_Info3
);
388 if (!r
->out
.info
->info3
) {
391 ret
= init_reply_dfs_info_3(ctx
, jn
, r
->out
.info
->info3
);
394 r
->out
.info
->info100
= TALLOC_ZERO_P(ctx
,struct dfs_Info100
);
395 if (!r
->out
.info
->info100
) {
398 ret
= init_reply_dfs_info_100(ctx
, jn
, r
->out
.info
->info100
);
401 r
->out
.info
->info1
= NULL
;
402 return WERR_INVALID_PARAM
;
406 return WERR_INVALID_PARAM
;
411 WERROR
_dfs_SetInfo(struct pipes_struct
*p
, struct dfs_SetInfo
*r
)
413 /* FIXME: Implement your code here */
414 p
->rng_fault_state
= True
;
415 return WERR_NOT_SUPPORTED
;
418 WERROR
_dfs_Rename(struct pipes_struct
*p
, struct dfs_Rename
*r
)
420 /* FIXME: Implement your code here */
421 p
->rng_fault_state
= True
;
422 return WERR_NOT_SUPPORTED
;
425 WERROR
_dfs_Move(struct pipes_struct
*p
, struct dfs_Move
*r
)
427 /* FIXME: Implement your code here */
428 p
->rng_fault_state
= True
;
429 return WERR_NOT_SUPPORTED
;
432 WERROR
_dfs_ManagerGetConfigInfo(struct pipes_struct
*p
, struct dfs_ManagerGetConfigInfo
*r
)
434 /* FIXME: Implement your code here */
435 p
->rng_fault_state
= True
;
436 return WERR_NOT_SUPPORTED
;
439 WERROR
_dfs_ManagerSendSiteInfo(struct pipes_struct
*p
, struct dfs_ManagerSendSiteInfo
*r
)
441 /* FIXME: Implement your code here */
442 p
->rng_fault_state
= True
;
443 return WERR_NOT_SUPPORTED
;
446 WERROR
_dfs_AddFtRoot(struct pipes_struct
*p
, struct dfs_AddFtRoot
*r
)
448 /* FIXME: Implement your code here */
449 p
->rng_fault_state
= True
;
450 return WERR_NOT_SUPPORTED
;
453 WERROR
_dfs_RemoveFtRoot(struct pipes_struct
*p
, struct dfs_RemoveFtRoot
*r
)
455 /* FIXME: Implement your code here */
456 p
->rng_fault_state
= True
;
457 return WERR_NOT_SUPPORTED
;
460 WERROR
_dfs_AddStdRoot(struct pipes_struct
*p
, struct dfs_AddStdRoot
*r
)
462 /* FIXME: Implement your code here */
463 p
->rng_fault_state
= True
;
464 return WERR_NOT_SUPPORTED
;
467 WERROR
_dfs_RemoveStdRoot(struct pipes_struct
*p
, struct dfs_RemoveStdRoot
*r
)
469 /* FIXME: Implement your code here */
470 p
->rng_fault_state
= True
;
471 return WERR_NOT_SUPPORTED
;
474 WERROR
_dfs_ManagerInitialize(struct pipes_struct
*p
, struct dfs_ManagerInitialize
*r
)
476 /* FIXME: Implement your code here */
477 p
->rng_fault_state
= True
;
478 return WERR_NOT_SUPPORTED
;
481 WERROR
_dfs_AddStdRootForced(struct pipes_struct
*p
, struct dfs_AddStdRootForced
*r
)
483 /* FIXME: Implement your code here */
484 p
->rng_fault_state
= True
;
485 return WERR_NOT_SUPPORTED
;
488 WERROR
_dfs_GetDcAddress(struct pipes_struct
*p
, struct dfs_GetDcAddress
*r
)
490 /* FIXME: Implement your code here */
491 p
->rng_fault_state
= True
;
492 return WERR_NOT_SUPPORTED
;
495 WERROR
_dfs_SetDcAddress(struct pipes_struct
*p
, struct dfs_SetDcAddress
*r
)
497 /* FIXME: Implement your code here */
498 p
->rng_fault_state
= True
;
499 return WERR_NOT_SUPPORTED
;
502 WERROR
_dfs_FlushFtTable(struct pipes_struct
*p
, struct dfs_FlushFtTable
*r
)
504 /* FIXME: Implement your code here */
505 p
->rng_fault_state
= True
;
506 return WERR_NOT_SUPPORTED
;
509 WERROR
_dfs_Add2(struct pipes_struct
*p
, struct dfs_Add2
*r
)
511 /* FIXME: Implement your code here */
512 p
->rng_fault_state
= True
;
513 return WERR_NOT_SUPPORTED
;
516 WERROR
_dfs_Remove2(struct pipes_struct
*p
, struct dfs_Remove2
*r
)
518 /* FIXME: Implement your code here */
519 p
->rng_fault_state
= True
;
520 return WERR_NOT_SUPPORTED
;
523 WERROR
_dfs_EnumEx(struct pipes_struct
*p
, struct dfs_EnumEx
*r
)
525 /* FIXME: Implement your code here */
526 p
->rng_fault_state
= True
;
527 return WERR_NOT_SUPPORTED
;
530 WERROR
_dfs_SetInfo2(struct pipes_struct
*p
, struct dfs_SetInfo2
*r
)
532 /* FIXME: Implement your code here */
533 p
->rng_fault_state
= True
;
534 return WERR_NOT_SUPPORTED
;