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. */
27 #define DBGC_CLASS DBGC_MSDFS
29 /* This function does not return a WERROR or NTSTATUS code but rather 1 if
30 dfs exists, or 0 otherwise. */
32 void _dfs_GetManagerVersion(pipes_struct
*p
, struct dfs_GetManagerVersion
*r
)
34 if (lp_host_msdfs()) {
35 *r
->out
.version
= DFS_MANAGER_VERSION_NT4
;
37 *r
->out
.version
= (enum dfs_ManagerVersion
)0;
41 WERROR
_dfs_Add(pipes_struct
*p
, struct dfs_Add
*r
)
43 struct junction_map
*jn
= NULL
;
44 struct referral
*old_referral_list
= NULL
;
45 bool self_ref
= False
;
49 TALLOC_CTX
*ctx
= talloc_tos();
51 if (p
->pipe_user
.ut
.uid
!= sec_initial_uid()) {
52 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
53 return WERR_ACCESS_DENIED
;
56 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
61 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
62 r
->in
.path
, r
->in
.server
, r
->in
.share
));
64 altpath
= talloc_asprintf(ctx
, "%s\\%s",
71 /* The following call can change the cwd. */
72 status
= get_referred_path(ctx
, r
->in
.path
, jn
,
73 &consumedcnt
, &self_ref
);
74 if(!NT_STATUS_IS_OK(status
)) {
75 return ntstatus_to_werror(status
);
78 jn
->referral_count
+= 1;
79 old_referral_list
= jn
->referral_list
;
81 if (jn
->referral_count
< 1) {
85 jn
->referral_list
= TALLOC_ARRAY(ctx
, struct referral
, jn
->referral_count
);
86 if(jn
->referral_list
== NULL
) {
87 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
88 return WERR_DFS_INTERNAL_ERROR
;
91 if(old_referral_list
&& jn
->referral_list
) {
92 memcpy(jn
->referral_list
, old_referral_list
,
93 sizeof(struct referral
)*jn
->referral_count
-1);
96 jn
->referral_list
[jn
->referral_count
-1].proximity
= 0;
97 jn
->referral_list
[jn
->referral_count
-1].ttl
= REFERRAL_TTL
;
98 jn
->referral_list
[jn
->referral_count
-1].alternate_path
= altpath
;
100 if(!create_msdfs_link(jn
)) {
101 return WERR_DFS_CANT_CREATE_JUNCT
;
107 WERROR
_dfs_Remove(pipes_struct
*p
, struct dfs_Remove
*r
)
109 struct junction_map
*jn
= NULL
;
110 bool self_ref
= False
;
113 TALLOC_CTX
*ctx
= talloc_tos();
114 char *altpath
= NULL
;
116 if (p
->pipe_user
.ut
.uid
!= sec_initial_uid()) {
117 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
118 return WERR_ACCESS_DENIED
;
121 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
126 if (r
->in
.servername
&& r
->in
.sharename
) {
127 altpath
= talloc_asprintf(ctx
, "%s\\%s",
134 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
135 r
->in
.dfs_entry_path
, r
->in
.servername
, r
->in
.sharename
));
138 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
, jn
,
139 &consumedcnt
, &self_ref
))) {
140 return WERR_DFS_NO_SUCH_VOL
;
143 /* if no server-share pair given, remove the msdfs link completely */
144 if(!r
->in
.servername
&& !r
->in
.sharename
) {
145 if(!remove_msdfs_link(jn
)) {
146 return WERR_DFS_NO_SUCH_VOL
;
150 /* compare each referral in the list with the one to remove */
151 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath
, jn
->referral_count
));
152 for(i
=0;i
<jn
->referral_count
;i
++) {
153 char *refpath
= talloc_strdup(ctx
,
154 jn
->referral_list
[i
].alternate_path
);
158 trim_char(refpath
, '\\', '\\');
159 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath
));
160 if(strequal(refpath
, altpath
)) {
161 *(jn
->referral_list
[i
].alternate_path
)='\0';
162 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
169 return WERR_DFS_NO_SUCH_SHARE
;
172 /* Only one referral, remove it */
173 if(jn
->referral_count
== 1) {
174 if(!remove_msdfs_link(jn
)) {
175 return WERR_DFS_NO_SUCH_VOL
;
178 if(!create_msdfs_link(jn
)) {
179 return WERR_DFS_CANT_CREATE_JUNCT
;
187 static bool init_reply_dfs_info_1(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
,struct dfs_Info1
* dfs1
)
189 dfs1
->path
= talloc_asprintf(mem_ctx
,
190 "\\\\%s\\%s\\%s", global_myname(),
191 j
->service_name
, j
->volume_name
);
192 if (dfs1
->path
== NULL
)
195 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1
->path
));
199 static bool init_reply_dfs_info_2(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info2
* dfs2
)
201 dfs2
->path
= talloc_asprintf(mem_ctx
,
202 "\\\\%s\\%s\\%s", global_myname(), j
->service_name
, j
->volume_name
);
203 if (dfs2
->path
== NULL
)
205 dfs2
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
206 dfs2
->state
= 1; /* set up state of dfs junction as OK */
207 dfs2
->num_stores
= j
->referral_count
;
211 static bool init_reply_dfs_info_3(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info3
* dfs3
)
214 if (j
->volume_name
[0] == '\0')
215 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
216 global_myname(), j
->service_name
);
218 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s\\%s", global_myname(),
219 j
->service_name
, j
->volume_name
);
221 if (dfs3
->path
== NULL
)
224 dfs3
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
226 dfs3
->num_stores
= j
->referral_count
;
228 /* also enumerate the stores */
229 if (j
->referral_count
) {
230 dfs3
->stores
= TALLOC_ARRAY(mem_ctx
, struct dfs_StorageInfo
, j
->referral_count
);
233 memset(dfs3
->stores
, '\0', j
->referral_count
* sizeof(struct dfs_StorageInfo
));
238 for(ii
=0;ii
<j
->referral_count
;ii
++) {
241 struct dfs_StorageInfo
* stor
= &(dfs3
->stores
[ii
]);
242 struct referral
* ref
= &(j
->referral_list
[ii
]);
244 path
= talloc_strdup(mem_ctx
, ref
->alternate_path
);
248 trim_char(path
,'\\','\0');
249 p
= strrchr_m(path
,'\\');
251 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path
));
255 DEBUG(5,("storage %d: %s.%s\n",ii
,path
,p
+1));
256 stor
->state
= 2; /* set all stores as ONLINE */
257 stor
->server
= talloc_strdup(mem_ctx
, path
);
258 stor
->share
= talloc_strdup(mem_ctx
, p
+1);
263 static bool init_reply_dfs_info_100(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info100
* dfs100
)
265 dfs100
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
269 WERROR
_dfs_Enum(pipes_struct
*p
, struct dfs_Enum
*r
)
271 struct junction_map
*jn
= NULL
;
274 TALLOC_CTX
*ctx
= talloc_tos();
276 jn
= enum_msdfs_links(ctx
, &num_jn
);
277 if (!jn
|| num_jn
== 0) {
282 DEBUG(5,("_dfs_Enum: %u junctions found in Dfs, doing level %d\n",
283 (unsigned int)num_jn
, r
->in
.level
));
285 *r
->out
.total
= num_jn
;
287 /* Create the return array */
288 switch (r
->in
.level
) {
291 if ((r
->out
.info
->e
.info1
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info1
, num_jn
)) == NULL
) {
295 r
->out
.info
->e
.info1
->s
= NULL
;
297 r
->out
.info
->e
.info1
->count
= num_jn
;
301 if ((r
->out
.info
->e
.info2
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info2
, num_jn
)) == NULL
) {
305 r
->out
.info
->e
.info2
->s
= NULL
;
307 r
->out
.info
->e
.info2
->count
= num_jn
;
311 if ((r
->out
.info
->e
.info3
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info3
, num_jn
)) == NULL
) {
315 r
->out
.info
->e
.info3
->s
= NULL
;
317 r
->out
.info
->e
.info3
->count
= num_jn
;
320 return WERR_INVALID_PARAM
;
323 for (i
= 0; i
< num_jn
; i
++) {
324 switch (r
->in
.level
) {
326 init_reply_dfs_info_1(ctx
, &jn
[i
], &r
->out
.info
->e
.info1
->s
[i
]);
329 init_reply_dfs_info_2(ctx
, &jn
[i
], &r
->out
.info
->e
.info2
->s
[i
]);
332 init_reply_dfs_info_3(ctx
, &jn
[i
], &r
->out
.info
->e
.info3
->s
[i
]);
335 return WERR_INVALID_PARAM
;
342 WERROR
_dfs_GetInfo(pipes_struct
*p
, struct dfs_GetInfo
*r
)
344 int consumedcnt
= strlen(r
->in
.dfs_entry_path
);
345 struct junction_map
*jn
= NULL
;
346 bool self_ref
= False
;
347 TALLOC_CTX
*ctx
= talloc_tos();
350 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
355 if(!create_junction(ctx
, r
->in
.dfs_entry_path
, jn
)) {
356 return WERR_DFS_NO_SUCH_SERVER
;
359 /* The following call can change the cwd. */
360 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
,
361 jn
, &consumedcnt
, &self_ref
)) ||
362 consumedcnt
< strlen(r
->in
.dfs_entry_path
)) {
363 return WERR_DFS_NO_SUCH_VOL
;
366 switch (r
->in
.level
) {
368 r
->out
.info
->info1
= TALLOC_ZERO_P(ctx
,struct dfs_Info1
);
369 if (!r
->out
.info
->info1
) {
372 ret
= init_reply_dfs_info_1(ctx
, jn
, r
->out
.info
->info1
);
375 r
->out
.info
->info2
= TALLOC_ZERO_P(ctx
,struct dfs_Info2
);
376 if (!r
->out
.info
->info2
) {
379 ret
= init_reply_dfs_info_2(ctx
, jn
, r
->out
.info
->info2
);
382 r
->out
.info
->info3
= TALLOC_ZERO_P(ctx
,struct dfs_Info3
);
383 if (!r
->out
.info
->info3
) {
386 ret
= init_reply_dfs_info_3(ctx
, jn
, r
->out
.info
->info3
);
389 r
->out
.info
->info100
= TALLOC_ZERO_P(ctx
,struct dfs_Info100
);
390 if (!r
->out
.info
->info100
) {
393 ret
= init_reply_dfs_info_100(ctx
, jn
, r
->out
.info
->info100
);
396 r
->out
.info
->info1
= NULL
;
397 return WERR_INVALID_PARAM
;
401 return WERR_INVALID_PARAM
;
406 WERROR
_dfs_SetInfo(pipes_struct
*p
, struct dfs_SetInfo
*r
)
408 /* FIXME: Implement your code here */
409 p
->rng_fault_state
= True
;
410 return WERR_NOT_SUPPORTED
;
413 WERROR
_dfs_Rename(pipes_struct
*p
, struct dfs_Rename
*r
)
415 /* FIXME: Implement your code here */
416 p
->rng_fault_state
= True
;
417 return WERR_NOT_SUPPORTED
;
420 WERROR
_dfs_Move(pipes_struct
*p
, struct dfs_Move
*r
)
422 /* FIXME: Implement your code here */
423 p
->rng_fault_state
= True
;
424 return WERR_NOT_SUPPORTED
;
427 WERROR
_dfs_ManagerGetConfigInfo(pipes_struct
*p
, struct dfs_ManagerGetConfigInfo
*r
)
429 /* FIXME: Implement your code here */
430 p
->rng_fault_state
= True
;
431 return WERR_NOT_SUPPORTED
;
434 WERROR
_dfs_ManagerSendSiteInfo(pipes_struct
*p
, struct dfs_ManagerSendSiteInfo
*r
)
436 /* FIXME: Implement your code here */
437 p
->rng_fault_state
= True
;
438 return WERR_NOT_SUPPORTED
;
441 WERROR
_dfs_AddFtRoot(pipes_struct
*p
, struct dfs_AddFtRoot
*r
)
443 /* FIXME: Implement your code here */
444 p
->rng_fault_state
= True
;
445 return WERR_NOT_SUPPORTED
;
448 WERROR
_dfs_RemoveFtRoot(pipes_struct
*p
, struct dfs_RemoveFtRoot
*r
)
450 /* FIXME: Implement your code here */
451 p
->rng_fault_state
= True
;
452 return WERR_NOT_SUPPORTED
;
455 WERROR
_dfs_AddStdRoot(pipes_struct
*p
, struct dfs_AddStdRoot
*r
)
457 /* FIXME: Implement your code here */
458 p
->rng_fault_state
= True
;
459 return WERR_NOT_SUPPORTED
;
462 WERROR
_dfs_RemoveStdRoot(pipes_struct
*p
, struct dfs_RemoveStdRoot
*r
)
464 /* FIXME: Implement your code here */
465 p
->rng_fault_state
= True
;
466 return WERR_NOT_SUPPORTED
;
469 WERROR
_dfs_ManagerInitialize(pipes_struct
*p
, struct dfs_ManagerInitialize
*r
)
471 /* FIXME: Implement your code here */
472 p
->rng_fault_state
= True
;
473 return WERR_NOT_SUPPORTED
;
476 WERROR
_dfs_AddStdRootForced(pipes_struct
*p
, struct dfs_AddStdRootForced
*r
)
478 /* FIXME: Implement your code here */
479 p
->rng_fault_state
= True
;
480 return WERR_NOT_SUPPORTED
;
483 WERROR
_dfs_GetDcAddress(pipes_struct
*p
, struct dfs_GetDcAddress
*r
)
485 /* FIXME: Implement your code here */
486 p
->rng_fault_state
= True
;
487 return WERR_NOT_SUPPORTED
;
490 WERROR
_dfs_SetDcAddress(pipes_struct
*p
, struct dfs_SetDcAddress
*r
)
492 /* FIXME: Implement your code here */
493 p
->rng_fault_state
= True
;
494 return WERR_NOT_SUPPORTED
;
497 WERROR
_dfs_FlushFtTable(pipes_struct
*p
, struct dfs_FlushFtTable
*r
)
499 /* FIXME: Implement your code here */
500 p
->rng_fault_state
= True
;
501 return WERR_NOT_SUPPORTED
;
504 WERROR
_dfs_Add2(pipes_struct
*p
, struct dfs_Add2
*r
)
506 /* FIXME: Implement your code here */
507 p
->rng_fault_state
= True
;
508 return WERR_NOT_SUPPORTED
;
511 WERROR
_dfs_Remove2(pipes_struct
*p
, struct dfs_Remove2
*r
)
513 /* FIXME: Implement your code here */
514 p
->rng_fault_state
= True
;
515 return WERR_NOT_SUPPORTED
;
518 WERROR
_dfs_EnumEx(pipes_struct
*p
, struct dfs_EnumEx
*r
)
520 /* FIXME: Implement your code here */
521 p
->rng_fault_state
= True
;
522 return WERR_NOT_SUPPORTED
;
525 WERROR
_dfs_SetInfo2(pipes_struct
*p
, struct dfs_SetInfo2
*r
)
527 /* FIXME: Implement your code here */
528 p
->rng_fault_state
= True
;
529 return WERR_NOT_SUPPORTED
;