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"
29 #include "smbd/globals.h"
33 #define DBGC_CLASS DBGC_MSDFS
35 /* This function does not return a WERROR or NTSTATUS code but rather 1 if
36 dfs exists, or 0 otherwise. */
38 void _dfs_GetManagerVersion(struct pipes_struct
*p
, struct dfs_GetManagerVersion
*r
)
40 if (lp_host_msdfs()) {
41 *r
->out
.version
= DFS_MANAGER_VERSION_NT4
;
43 *r
->out
.version
= (enum dfs_ManagerVersion
)0;
47 WERROR
_dfs_Add(struct pipes_struct
*p
, struct dfs_Add
*r
)
49 struct junction_map
*jn
= NULL
;
50 struct referral
*old_referral_list
= NULL
;
51 bool self_ref
= False
;
55 TALLOC_CTX
*ctx
= talloc_tos();
57 if (p
->session_info
->unix_token
->uid
!= sec_initial_uid()) {
58 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
59 return WERR_ACCESS_DENIED
;
62 jn
= talloc_zero(ctx
, struct junction_map
);
67 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
68 r
->in
.path
, r
->in
.server
, r
->in
.share
));
70 altpath
= talloc_asprintf(ctx
, "%s\\%s",
77 /* The following call can change the cwd. */
78 status
= get_referred_path(ctx
, r
->in
.path
,
79 true, /*allow_broken_path */
80 jn
, &consumedcnt
, &self_ref
);
81 if(!NT_STATUS_IS_OK(status
)) {
82 return ntstatus_to_werror(status
);
85 jn
->referral_count
+= 1;
86 old_referral_list
= jn
->referral_list
;
88 if (jn
->referral_count
< 1) {
92 jn
->referral_list
= talloc_array(ctx
, struct referral
, jn
->referral_count
);
93 if(jn
->referral_list
== NULL
) {
94 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
95 return WERR_DFS_INTERNAL_ERROR
;
98 if(old_referral_list
&& jn
->referral_list
) {
99 memcpy(jn
->referral_list
, old_referral_list
,
100 sizeof(struct referral
)*jn
->referral_count
-1);
103 jn
->referral_list
[jn
->referral_count
-1].proximity
= 0;
104 jn
->referral_list
[jn
->referral_count
-1].ttl
= REFERRAL_TTL
;
105 jn
->referral_list
[jn
->referral_count
-1].alternate_path
= altpath
;
107 if(!create_msdfs_link(jn
)) {
108 return WERR_DFS_CANT_CREATE_JUNCT
;
114 WERROR
_dfs_Remove(struct pipes_struct
*p
, struct dfs_Remove
*r
)
116 struct junction_map
*jn
= NULL
;
117 bool self_ref
= False
;
120 TALLOC_CTX
*ctx
= talloc_tos();
121 char *altpath
= NULL
;
124 if (p
->session_info
->unix_token
->uid
!= sec_initial_uid()) {
125 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
126 return WERR_ACCESS_DENIED
;
129 jn
= talloc_zero(ctx
, struct junction_map
);
134 if (r
->in
.servername
&& r
->in
.sharename
) {
135 altpath
= talloc_asprintf(ctx
, "%s\\%s",
142 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
143 r
->in
.dfs_entry_path
, r
->in
.servername
, r
->in
.sharename
));
146 status
= get_referred_path(ctx
, r
->in
.dfs_entry_path
,
147 true, /*allow_broken_path */
148 jn
, &consumedcnt
, &self_ref
);
149 if(!NT_STATUS_IS_OK(status
)) {
150 return WERR_DFS_NO_SUCH_VOL
;
153 /* if no server-share pair given, remove the msdfs link completely */
154 if(!r
->in
.servername
&& !r
->in
.sharename
) {
155 if(!remove_msdfs_link(jn
)) {
156 return WERR_DFS_NO_SUCH_VOL
;
160 /* compare each referral in the list with the one to remove */
161 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath
, jn
->referral_count
));
162 for(i
=0;i
<jn
->referral_count
;i
++) {
163 char *refpath
= talloc_strdup(ctx
,
164 jn
->referral_list
[i
].alternate_path
);
168 trim_char(refpath
, '\\', '\\');
169 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath
));
170 if(strequal(refpath
, altpath
)) {
171 *(jn
->referral_list
[i
].alternate_path
)='\0';
172 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
179 return WERR_DFS_NO_SUCH_SHARE
;
182 /* Only one referral, remove it */
183 if(jn
->referral_count
== 1) {
184 if(!remove_msdfs_link(jn
)) {
185 return WERR_DFS_NO_SUCH_VOL
;
188 if(!create_msdfs_link(jn
)) {
189 return WERR_DFS_CANT_CREATE_JUNCT
;
197 static bool init_reply_dfs_info_1(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
,struct dfs_Info1
* dfs1
)
199 dfs1
->path
= talloc_asprintf(mem_ctx
,
200 "\\\\%s\\%s\\%s", lp_netbios_name(),
201 j
->service_name
, j
->volume_name
);
202 if (dfs1
->path
== NULL
)
205 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1
->path
));
209 static bool init_reply_dfs_info_2(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info2
* dfs2
)
211 dfs2
->path
= talloc_asprintf(mem_ctx
,
212 "\\\\%s\\%s\\%s", lp_netbios_name(), j
->service_name
, j
->volume_name
);
213 if (dfs2
->path
== NULL
)
215 dfs2
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
216 dfs2
->state
= 1; /* set up state of dfs junction as OK */
217 dfs2
->num_stores
= j
->referral_count
;
221 static bool init_reply_dfs_info_3(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info3
* dfs3
)
224 if (j
->volume_name
[0] == '\0')
225 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
226 lp_netbios_name(), j
->service_name
);
228 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s\\%s", lp_netbios_name(),
229 j
->service_name
, j
->volume_name
);
231 if (dfs3
->path
== NULL
)
234 dfs3
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
236 dfs3
->num_stores
= j
->referral_count
;
238 /* also enumerate the stores */
239 if (j
->referral_count
) {
240 dfs3
->stores
= talloc_array(mem_ctx
, struct dfs_StorageInfo
, j
->referral_count
);
243 memset(dfs3
->stores
, '\0', j
->referral_count
* sizeof(struct dfs_StorageInfo
));
248 for(ii
=0;ii
<j
->referral_count
;ii
++) {
251 struct dfs_StorageInfo
* stor
= &(dfs3
->stores
[ii
]);
252 struct referral
* ref
= &(j
->referral_list
[ii
]);
254 path
= talloc_strdup(mem_ctx
, ref
->alternate_path
);
258 trim_char(path
,'\\','\0');
259 p
= strrchr_m(path
,'\\');
261 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path
));
265 DEBUG(5,("storage %d: %s.%s\n",ii
,path
,p
+1));
266 stor
->state
= 2; /* set all stores as ONLINE */
267 stor
->server
= talloc_strdup(mem_ctx
, path
);
268 stor
->share
= talloc_strdup(mem_ctx
, p
+1);
273 static bool init_reply_dfs_info_100(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info100
* dfs100
)
275 dfs100
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
279 WERROR
_dfs_Enum(struct pipes_struct
*p
, struct dfs_Enum
*r
)
281 struct junction_map
*jn
= NULL
;
284 TALLOC_CTX
*ctx
= talloc_tos();
286 jn
= enum_msdfs_links(ctx
, &num_jn
);
287 if (!jn
|| num_jn
== 0) {
292 DEBUG(5,("_dfs_Enum: %u junctions found in Dfs, doing level %d\n",
293 (unsigned int)num_jn
, r
->in
.level
));
295 *r
->out
.total
= num_jn
;
297 /* Create the return array */
298 switch (r
->in
.level
) {
301 if ((r
->out
.info
->e
.info1
->s
= talloc_array(ctx
, struct dfs_Info1
, num_jn
)) == NULL
) {
305 r
->out
.info
->e
.info1
->s
= NULL
;
307 r
->out
.info
->e
.info1
->count
= num_jn
;
311 if ((r
->out
.info
->e
.info2
->s
= talloc_array(ctx
, struct dfs_Info2
, num_jn
)) == NULL
) {
315 r
->out
.info
->e
.info2
->s
= NULL
;
317 r
->out
.info
->e
.info2
->count
= num_jn
;
321 if ((r
->out
.info
->e
.info3
->s
= talloc_array(ctx
, struct dfs_Info3
, num_jn
)) == NULL
) {
325 r
->out
.info
->e
.info3
->s
= NULL
;
327 r
->out
.info
->e
.info3
->count
= num_jn
;
330 return WERR_INVALID_PARAM
;
333 for (i
= 0; i
< num_jn
; i
++) {
334 switch (r
->in
.level
) {
336 init_reply_dfs_info_1(ctx
, &jn
[i
], &r
->out
.info
->e
.info1
->s
[i
]);
339 init_reply_dfs_info_2(ctx
, &jn
[i
], &r
->out
.info
->e
.info2
->s
[i
]);
342 init_reply_dfs_info_3(ctx
, &jn
[i
], &r
->out
.info
->e
.info3
->s
[i
]);
345 return WERR_INVALID_PARAM
;
352 WERROR
_dfs_GetInfo(struct pipes_struct
*p
, struct dfs_GetInfo
*r
)
354 int consumedcnt
= strlen(r
->in
.dfs_entry_path
);
355 struct junction_map
*jn
= NULL
;
356 bool self_ref
= False
;
357 TALLOC_CTX
*ctx
= talloc_tos();
361 jn
= talloc_zero(ctx
, struct junction_map
);
366 ret
= create_junction(ctx
, r
->in
.dfs_entry_path
,
367 true, /* allow broken_path */
370 return WERR_DFS_NO_SUCH_SERVER
;
373 /* The following call can change the cwd. */
374 status
= get_referred_path(ctx
, r
->in
.dfs_entry_path
,
375 true, /*allow_broken_path */
376 jn
, &consumedcnt
, &self_ref
);
377 if(!NT_STATUS_IS_OK(status
) ||
378 consumedcnt
< strlen(r
->in
.dfs_entry_path
)) {
379 return WERR_DFS_NO_SUCH_VOL
;
382 switch (r
->in
.level
) {
384 r
->out
.info
->info1
= talloc_zero(ctx
,struct dfs_Info1
);
385 if (!r
->out
.info
->info1
) {
388 ret
= init_reply_dfs_info_1(ctx
, jn
, r
->out
.info
->info1
);
391 r
->out
.info
->info2
= talloc_zero(ctx
,struct dfs_Info2
);
392 if (!r
->out
.info
->info2
) {
395 ret
= init_reply_dfs_info_2(ctx
, jn
, r
->out
.info
->info2
);
398 r
->out
.info
->info3
= talloc_zero(ctx
,struct dfs_Info3
);
399 if (!r
->out
.info
->info3
) {
402 ret
= init_reply_dfs_info_3(ctx
, jn
, r
->out
.info
->info3
);
405 r
->out
.info
->info100
= talloc_zero(ctx
,struct dfs_Info100
);
406 if (!r
->out
.info
->info100
) {
409 ret
= init_reply_dfs_info_100(ctx
, jn
, r
->out
.info
->info100
);
412 r
->out
.info
->info1
= NULL
;
413 return WERR_INVALID_PARAM
;
417 return WERR_INVALID_PARAM
;
422 WERROR
_dfs_SetInfo(struct pipes_struct
*p
, struct dfs_SetInfo
*r
)
424 /* FIXME: Implement your code here */
425 p
->rng_fault_state
= True
;
426 return WERR_NOT_SUPPORTED
;
429 WERROR
_dfs_Rename(struct pipes_struct
*p
, struct dfs_Rename
*r
)
431 /* FIXME: Implement your code here */
432 p
->rng_fault_state
= True
;
433 return WERR_NOT_SUPPORTED
;
436 WERROR
_dfs_Move(struct pipes_struct
*p
, struct dfs_Move
*r
)
438 /* FIXME: Implement your code here */
439 p
->rng_fault_state
= True
;
440 return WERR_NOT_SUPPORTED
;
443 WERROR
_dfs_ManagerGetConfigInfo(struct pipes_struct
*p
, struct dfs_ManagerGetConfigInfo
*r
)
445 /* FIXME: Implement your code here */
446 p
->rng_fault_state
= True
;
447 return WERR_NOT_SUPPORTED
;
450 WERROR
_dfs_ManagerSendSiteInfo(struct pipes_struct
*p
, struct dfs_ManagerSendSiteInfo
*r
)
452 /* FIXME: Implement your code here */
453 p
->rng_fault_state
= True
;
454 return WERR_NOT_SUPPORTED
;
457 WERROR
_dfs_AddFtRoot(struct pipes_struct
*p
, struct dfs_AddFtRoot
*r
)
459 /* FIXME: Implement your code here */
460 p
->rng_fault_state
= True
;
461 return WERR_NOT_SUPPORTED
;
464 WERROR
_dfs_RemoveFtRoot(struct pipes_struct
*p
, struct dfs_RemoveFtRoot
*r
)
466 /* FIXME: Implement your code here */
467 p
->rng_fault_state
= True
;
468 return WERR_NOT_SUPPORTED
;
471 WERROR
_dfs_AddStdRoot(struct pipes_struct
*p
, struct dfs_AddStdRoot
*r
)
473 /* FIXME: Implement your code here */
474 p
->rng_fault_state
= True
;
475 return WERR_NOT_SUPPORTED
;
478 WERROR
_dfs_RemoveStdRoot(struct pipes_struct
*p
, struct dfs_RemoveStdRoot
*r
)
480 /* FIXME: Implement your code here */
481 p
->rng_fault_state
= True
;
482 return WERR_NOT_SUPPORTED
;
485 WERROR
_dfs_ManagerInitialize(struct pipes_struct
*p
, struct dfs_ManagerInitialize
*r
)
487 /* FIXME: Implement your code here */
488 p
->rng_fault_state
= True
;
489 return WERR_NOT_SUPPORTED
;
492 WERROR
_dfs_AddStdRootForced(struct pipes_struct
*p
, struct dfs_AddStdRootForced
*r
)
494 /* FIXME: Implement your code here */
495 p
->rng_fault_state
= True
;
496 return WERR_NOT_SUPPORTED
;
499 WERROR
_dfs_GetDcAddress(struct pipes_struct
*p
, struct dfs_GetDcAddress
*r
)
501 /* FIXME: Implement your code here */
502 p
->rng_fault_state
= True
;
503 return WERR_NOT_SUPPORTED
;
506 WERROR
_dfs_SetDcAddress(struct pipes_struct
*p
, struct dfs_SetDcAddress
*r
)
508 /* FIXME: Implement your code here */
509 p
->rng_fault_state
= True
;
510 return WERR_NOT_SUPPORTED
;
513 WERROR
_dfs_FlushFtTable(struct pipes_struct
*p
, struct dfs_FlushFtTable
*r
)
515 /* FIXME: Implement your code here */
516 p
->rng_fault_state
= True
;
517 return WERR_NOT_SUPPORTED
;
520 WERROR
_dfs_Add2(struct pipes_struct
*p
, struct dfs_Add2
*r
)
522 /* FIXME: Implement your code here */
523 p
->rng_fault_state
= True
;
524 return WERR_NOT_SUPPORTED
;
527 WERROR
_dfs_Remove2(struct pipes_struct
*p
, struct dfs_Remove2
*r
)
529 /* FIXME: Implement your code here */
530 p
->rng_fault_state
= True
;
531 return WERR_NOT_SUPPORTED
;
534 WERROR
_dfs_EnumEx(struct pipes_struct
*p
, struct dfs_EnumEx
*r
)
536 /* FIXME: Implement your code here */
537 p
->rng_fault_state
= True
;
538 return WERR_NOT_SUPPORTED
;
541 WERROR
_dfs_SetInfo2(struct pipes_struct
*p
, struct dfs_SetInfo2
*r
)
543 /* FIXME: Implement your code here */
544 p
->rng_fault_state
= True
;
545 return WERR_NOT_SUPPORTED
;