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
, p
->server_info
, 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
, p
->server_info
,
140 r
->in
.dfs_entry_path
, jn
,
141 &consumedcnt
, &self_ref
))) {
142 return WERR_DFS_NO_SUCH_VOL
;
145 /* if no server-share pair given, remove the msdfs link completely */
146 if(!r
->in
.servername
&& !r
->in
.sharename
) {
147 if(!remove_msdfs_link(jn
)) {
148 return WERR_DFS_NO_SUCH_VOL
;
152 /* compare each referral in the list with the one to remove */
153 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath
, jn
->referral_count
));
154 for(i
=0;i
<jn
->referral_count
;i
++) {
155 char *refpath
= talloc_strdup(ctx
,
156 jn
->referral_list
[i
].alternate_path
);
160 trim_char(refpath
, '\\', '\\');
161 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath
));
162 if(strequal(refpath
, altpath
)) {
163 *(jn
->referral_list
[i
].alternate_path
)='\0';
164 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
171 return WERR_DFS_NO_SUCH_SHARE
;
174 /* Only one referral, remove it */
175 if(jn
->referral_count
== 1) {
176 if(!remove_msdfs_link(jn
)) {
177 return WERR_DFS_NO_SUCH_VOL
;
180 if(!create_msdfs_link(jn
)) {
181 return WERR_DFS_CANT_CREATE_JUNCT
;
189 static bool init_reply_dfs_info_1(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
,struct dfs_Info1
* dfs1
)
191 dfs1
->path
= talloc_asprintf(mem_ctx
,
192 "\\\\%s\\%s\\%s", global_myname(),
193 j
->service_name
, j
->volume_name
);
194 if (dfs1
->path
== NULL
)
197 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1
->path
));
201 static bool init_reply_dfs_info_2(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info2
* dfs2
)
203 dfs2
->path
= talloc_asprintf(mem_ctx
,
204 "\\\\%s\\%s\\%s", global_myname(), j
->service_name
, j
->volume_name
);
205 if (dfs2
->path
== NULL
)
207 dfs2
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
208 dfs2
->state
= 1; /* set up state of dfs junction as OK */
209 dfs2
->num_stores
= j
->referral_count
;
213 static bool init_reply_dfs_info_3(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info3
* dfs3
)
216 if (j
->volume_name
[0] == '\0')
217 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
218 global_myname(), j
->service_name
);
220 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s\\%s", global_myname(),
221 j
->service_name
, j
->volume_name
);
223 if (dfs3
->path
== NULL
)
226 dfs3
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
228 dfs3
->num_stores
= j
->referral_count
;
230 /* also enumerate the stores */
231 if (j
->referral_count
) {
232 dfs3
->stores
= TALLOC_ARRAY(mem_ctx
, struct dfs_StorageInfo
, j
->referral_count
);
235 memset(dfs3
->stores
, '\0', j
->referral_count
* sizeof(struct dfs_StorageInfo
));
240 for(ii
=0;ii
<j
->referral_count
;ii
++) {
243 struct dfs_StorageInfo
* stor
= &(dfs3
->stores
[ii
]);
244 struct referral
* ref
= &(j
->referral_list
[ii
]);
246 path
= talloc_strdup(mem_ctx
, ref
->alternate_path
);
250 trim_char(path
,'\\','\0');
251 p
= strrchr_m(path
,'\\');
253 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path
));
257 DEBUG(5,("storage %d: %s.%s\n",ii
,path
,p
+1));
258 stor
->state
= 2; /* set all stores as ONLINE */
259 stor
->server
= talloc_strdup(mem_ctx
, path
);
260 stor
->share
= talloc_strdup(mem_ctx
, p
+1);
265 static bool init_reply_dfs_info_100(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info100
* dfs100
)
267 dfs100
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
271 WERROR
_dfs_Enum(pipes_struct
*p
, struct dfs_Enum
*r
)
273 struct junction_map
*jn
= NULL
;
276 TALLOC_CTX
*ctx
= talloc_tos();
278 jn
= enum_msdfs_links(ctx
, &num_jn
);
279 if (!jn
|| num_jn
== 0) {
284 DEBUG(5,("_dfs_Enum: %u junctions found in Dfs, doing level %d\n",
285 (unsigned int)num_jn
, r
->in
.level
));
287 *r
->out
.total
= num_jn
;
289 /* Create the return array */
290 switch (r
->in
.level
) {
293 if ((r
->out
.info
->e
.info1
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info1
, num_jn
)) == NULL
) {
297 r
->out
.info
->e
.info1
->s
= NULL
;
299 r
->out
.info
->e
.info1
->count
= num_jn
;
303 if ((r
->out
.info
->e
.info2
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info2
, num_jn
)) == NULL
) {
307 r
->out
.info
->e
.info2
->s
= NULL
;
309 r
->out
.info
->e
.info2
->count
= num_jn
;
313 if ((r
->out
.info
->e
.info3
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info3
, num_jn
)) == NULL
) {
317 r
->out
.info
->e
.info3
->s
= NULL
;
319 r
->out
.info
->e
.info3
->count
= num_jn
;
322 return WERR_INVALID_PARAM
;
325 for (i
= 0; i
< num_jn
; i
++) {
326 switch (r
->in
.level
) {
328 init_reply_dfs_info_1(ctx
, &jn
[i
], &r
->out
.info
->e
.info1
->s
[i
]);
331 init_reply_dfs_info_2(ctx
, &jn
[i
], &r
->out
.info
->e
.info2
->s
[i
]);
334 init_reply_dfs_info_3(ctx
, &jn
[i
], &r
->out
.info
->e
.info3
->s
[i
]);
337 return WERR_INVALID_PARAM
;
344 WERROR
_dfs_GetInfo(pipes_struct
*p
, struct dfs_GetInfo
*r
)
346 int consumedcnt
= strlen(r
->in
.dfs_entry_path
);
347 struct junction_map
*jn
= NULL
;
348 bool self_ref
= False
;
349 TALLOC_CTX
*ctx
= talloc_tos();
352 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
357 if(!create_junction(ctx
, r
->in
.dfs_entry_path
, jn
)) {
358 return WERR_DFS_NO_SUCH_SERVER
;
361 /* The following call can change the cwd. */
362 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, p
->server_info
,
363 r
->in
.dfs_entry_path
,
364 jn
, &consumedcnt
, &self_ref
)) ||
365 consumedcnt
< strlen(r
->in
.dfs_entry_path
)) {
366 return WERR_DFS_NO_SUCH_VOL
;
369 switch (r
->in
.level
) {
371 r
->out
.info
->info1
= TALLOC_ZERO_P(ctx
,struct dfs_Info1
);
372 if (!r
->out
.info
->info1
) {
375 ret
= init_reply_dfs_info_1(ctx
, jn
, r
->out
.info
->info1
);
378 r
->out
.info
->info2
= TALLOC_ZERO_P(ctx
,struct dfs_Info2
);
379 if (!r
->out
.info
->info2
) {
382 ret
= init_reply_dfs_info_2(ctx
, jn
, r
->out
.info
->info2
);
385 r
->out
.info
->info3
= TALLOC_ZERO_P(ctx
,struct dfs_Info3
);
386 if (!r
->out
.info
->info3
) {
389 ret
= init_reply_dfs_info_3(ctx
, jn
, r
->out
.info
->info3
);
392 r
->out
.info
->info100
= TALLOC_ZERO_P(ctx
,struct dfs_Info100
);
393 if (!r
->out
.info
->info100
) {
396 ret
= init_reply_dfs_info_100(ctx
, jn
, r
->out
.info
->info100
);
399 r
->out
.info
->info1
= NULL
;
400 return WERR_INVALID_PARAM
;
404 return WERR_INVALID_PARAM
;
409 WERROR
_dfs_SetInfo(pipes_struct
*p
, struct dfs_SetInfo
*r
)
411 /* FIXME: Implement your code here */
412 p
->rng_fault_state
= True
;
413 return WERR_NOT_SUPPORTED
;
416 WERROR
_dfs_Rename(pipes_struct
*p
, struct dfs_Rename
*r
)
418 /* FIXME: Implement your code here */
419 p
->rng_fault_state
= True
;
420 return WERR_NOT_SUPPORTED
;
423 WERROR
_dfs_Move(pipes_struct
*p
, struct dfs_Move
*r
)
425 /* FIXME: Implement your code here */
426 p
->rng_fault_state
= True
;
427 return WERR_NOT_SUPPORTED
;
430 WERROR
_dfs_ManagerGetConfigInfo(pipes_struct
*p
, struct dfs_ManagerGetConfigInfo
*r
)
432 /* FIXME: Implement your code here */
433 p
->rng_fault_state
= True
;
434 return WERR_NOT_SUPPORTED
;
437 WERROR
_dfs_ManagerSendSiteInfo(pipes_struct
*p
, struct dfs_ManagerSendSiteInfo
*r
)
439 /* FIXME: Implement your code here */
440 p
->rng_fault_state
= True
;
441 return WERR_NOT_SUPPORTED
;
444 WERROR
_dfs_AddFtRoot(pipes_struct
*p
, struct dfs_AddFtRoot
*r
)
446 /* FIXME: Implement your code here */
447 p
->rng_fault_state
= True
;
448 return WERR_NOT_SUPPORTED
;
451 WERROR
_dfs_RemoveFtRoot(pipes_struct
*p
, struct dfs_RemoveFtRoot
*r
)
453 /* FIXME: Implement your code here */
454 p
->rng_fault_state
= True
;
455 return WERR_NOT_SUPPORTED
;
458 WERROR
_dfs_AddStdRoot(pipes_struct
*p
, struct dfs_AddStdRoot
*r
)
460 /* FIXME: Implement your code here */
461 p
->rng_fault_state
= True
;
462 return WERR_NOT_SUPPORTED
;
465 WERROR
_dfs_RemoveStdRoot(pipes_struct
*p
, struct dfs_RemoveStdRoot
*r
)
467 /* FIXME: Implement your code here */
468 p
->rng_fault_state
= True
;
469 return WERR_NOT_SUPPORTED
;
472 WERROR
_dfs_ManagerInitialize(pipes_struct
*p
, struct dfs_ManagerInitialize
*r
)
474 /* FIXME: Implement your code here */
475 p
->rng_fault_state
= True
;
476 return WERR_NOT_SUPPORTED
;
479 WERROR
_dfs_AddStdRootForced(pipes_struct
*p
, struct dfs_AddStdRootForced
*r
)
481 /* FIXME: Implement your code here */
482 p
->rng_fault_state
= True
;
483 return WERR_NOT_SUPPORTED
;
486 WERROR
_dfs_GetDcAddress(pipes_struct
*p
, struct dfs_GetDcAddress
*r
)
488 /* FIXME: Implement your code here */
489 p
->rng_fault_state
= True
;
490 return WERR_NOT_SUPPORTED
;
493 WERROR
_dfs_SetDcAddress(pipes_struct
*p
, struct dfs_SetDcAddress
*r
)
495 /* FIXME: Implement your code here */
496 p
->rng_fault_state
= True
;
497 return WERR_NOT_SUPPORTED
;
500 WERROR
_dfs_FlushFtTable(pipes_struct
*p
, struct dfs_FlushFtTable
*r
)
502 /* FIXME: Implement your code here */
503 p
->rng_fault_state
= True
;
504 return WERR_NOT_SUPPORTED
;
507 WERROR
_dfs_Add2(pipes_struct
*p
, struct dfs_Add2
*r
)
509 /* FIXME: Implement your code here */
510 p
->rng_fault_state
= True
;
511 return WERR_NOT_SUPPORTED
;
514 WERROR
_dfs_Remove2(pipes_struct
*p
, struct dfs_Remove2
*r
)
516 /* FIXME: Implement your code here */
517 p
->rng_fault_state
= True
;
518 return WERR_NOT_SUPPORTED
;
521 WERROR
_dfs_EnumEx(pipes_struct
*p
, struct dfs_EnumEx
*r
)
523 /* FIXME: Implement your code here */
524 p
->rng_fault_state
= True
;
525 return WERR_NOT_SUPPORTED
;
528 WERROR
_dfs_SetInfo2(pipes_struct
*p
, struct dfs_SetInfo2
*r
)
530 /* FIXME: Implement your code here */
531 p
->rng_fault_state
= True
;
532 return WERR_NOT_SUPPORTED
;