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
;
50 TALLOC_CTX
*ctx
= talloc_tos();
52 if (p
->pipe_user
.ut
.uid
!= 0) {
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
);
80 jn
->referral_count
+= 1;
81 old_referral_list
= jn
->referral_list
;
83 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
85 if (jn
->referral_count
< 1) {
89 jn
->referral_list
= TALLOC_ARRAY(ctx
, struct referral
, jn
->referral_count
);
90 if(jn
->referral_list
== NULL
) {
91 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
92 return WERR_DFS_INTERNAL_ERROR
;
95 if(old_referral_list
&& jn
->referral_list
) {
96 memcpy(jn
->referral_list
, old_referral_list
,
97 sizeof(struct referral
)*jn
->referral_count
-1);
100 jn
->referral_list
[jn
->referral_count
-1].proximity
= 0;
101 jn
->referral_list
[jn
->referral_count
-1].ttl
= REFERRAL_TTL
;
102 jn
->referral_list
[jn
->referral_count
-1].alternate_path
= altpath
;
104 if(!create_msdfs_link(jn
, exists
)) {
105 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
106 return WERR_DFS_CANT_CREATE_JUNCT
;
108 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
113 WERROR
_dfs_Remove(pipes_struct
*p
, struct dfs_Remove
*r
)
115 struct junction_map
*jn
= NULL
;
116 bool self_ref
= False
;
119 TALLOC_CTX
*ctx
= talloc_tos();
120 char *altpath
= NULL
;
122 if (p
->pipe_user
.ut
.uid
!= 0) {
123 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
124 return WERR_ACCESS_DENIED
;
127 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
132 if (r
->in
.servername
&& r
->in
.sharename
) {
133 altpath
= talloc_asprintf(ctx
, "%s\\%s",
140 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
141 r
->in
.dfs_entry_path
, r
->in
.servername
, r
->in
.sharename
));
144 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
, jn
,
145 &consumedcnt
, &self_ref
))) {
146 return WERR_DFS_NO_SUCH_VOL
;
149 /* if no server-share pair given, remove the msdfs link completely */
150 if(!r
->in
.servername
&& !r
->in
.sharename
) {
151 if(!remove_msdfs_link(jn
)) {
152 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
153 return WERR_DFS_NO_SUCH_VOL
;
155 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
158 /* compare each referral in the list with the one to remove */
159 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath
, jn
->referral_count
));
160 for(i
=0;i
<jn
->referral_count
;i
++) {
161 char *refpath
= talloc_strdup(ctx
,
162 jn
->referral_list
[i
].alternate_path
);
166 trim_char(refpath
, '\\', '\\');
167 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath
));
168 if(strequal(refpath
, altpath
)) {
169 *(jn
->referral_list
[i
].alternate_path
)='\0';
170 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
177 return WERR_DFS_NO_SUCH_SHARE
;
180 /* Only one referral, remove it */
181 if(jn
->referral_count
== 1) {
182 if(!remove_msdfs_link(jn
)) {
183 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
184 return WERR_DFS_NO_SUCH_VOL
;
187 if(!create_msdfs_link(jn
, True
)) {
188 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
189 return WERR_DFS_CANT_CREATE_JUNCT
;
192 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
198 static bool init_reply_dfs_info_1(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
,struct dfs_Info1
* dfs1
)
200 dfs1
->path
= talloc_asprintf(mem_ctx
,
201 "\\\\%s\\%s\\%s", global_myname(),
202 j
->service_name
, j
->volume_name
);
203 if (dfs1
->path
== NULL
)
206 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1
->path
));
210 static bool init_reply_dfs_info_2(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info2
* dfs2
)
212 dfs2
->path
= talloc_asprintf(mem_ctx
,
213 "\\\\%s\\%s\\%s", global_myname(), j
->service_name
, j
->volume_name
);
214 if (dfs2
->path
== NULL
)
216 dfs2
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
217 dfs2
->state
= 1; /* set up state of dfs junction as OK */
218 dfs2
->num_stores
= j
->referral_count
;
222 static bool init_reply_dfs_info_3(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info3
* dfs3
)
225 if (j
->volume_name
[0] == '\0')
226 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s",
227 global_myname(), j
->service_name
);
229 dfs3
->path
= talloc_asprintf(mem_ctx
, "\\\\%s\\%s\\%s", global_myname(),
230 j
->service_name
, j
->volume_name
);
232 if (dfs3
->path
== NULL
)
235 dfs3
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
237 dfs3
->num_stores
= j
->referral_count
;
239 /* also enumerate the stores */
240 if (j
->referral_count
) {
241 dfs3
->stores
= TALLOC_ARRAY(mem_ctx
, struct dfs_StorageInfo
, j
->referral_count
);
244 memset(dfs3
->stores
, '\0', j
->referral_count
* sizeof(struct dfs_StorageInfo
));
249 for(ii
=0;ii
<j
->referral_count
;ii
++) {
252 struct dfs_StorageInfo
* stor
= &(dfs3
->stores
[ii
]);
253 struct referral
* ref
= &(j
->referral_list
[ii
]);
255 path
= talloc_strdup(mem_ctx
, ref
->alternate_path
);
259 trim_char(path
,'\\','\0');
260 p
= strrchr_m(path
,'\\');
262 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path
));
266 DEBUG(5,("storage %d: %s.%s\n",ii
,path
,p
+1));
267 stor
->state
= 2; /* set all stores as ONLINE */
268 stor
->server
= talloc_strdup(mem_ctx
, path
);
269 stor
->share
= talloc_strdup(mem_ctx
, p
+1);
274 static bool init_reply_dfs_info_100(TALLOC_CTX
*mem_ctx
, struct junction_map
* j
, struct dfs_Info100
* dfs100
)
276 dfs100
->comment
= talloc_strdup(mem_ctx
, j
->comment
);
280 WERROR
_dfs_Enum(pipes_struct
*p
, struct dfs_Enum
*r
)
282 struct junction_map
*jn
= NULL
;
285 TALLOC_CTX
*ctx
= talloc_tos();
287 jn
= enum_msdfs_links(ctx
, &num_jn
);
288 if (!jn
|| num_jn
== 0) {
292 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
294 DEBUG(5,("_dfs_Enum: %u junctions found in Dfs, doing level %d\n",
295 (unsigned int)num_jn
, r
->in
.level
));
297 *r
->out
.total
= num_jn
;
299 /* Create the return array */
300 switch (r
->in
.level
) {
303 if ((r
->out
.info
->e
.info1
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info1
, num_jn
)) == NULL
) {
307 r
->out
.info
->e
.info1
->s
= NULL
;
309 r
->out
.info
->e
.info1
->count
= num_jn
;
313 if ((r
->out
.info
->e
.info2
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info2
, num_jn
)) == NULL
) {
317 r
->out
.info
->e
.info2
->s
= NULL
;
319 r
->out
.info
->e
.info2
->count
= num_jn
;
323 if ((r
->out
.info
->e
.info3
->s
= TALLOC_ARRAY(ctx
, struct dfs_Info3
, num_jn
)) == NULL
) {
327 r
->out
.info
->e
.info3
->s
= NULL
;
329 r
->out
.info
->e
.info3
->count
= num_jn
;
332 return WERR_INVALID_PARAM
;
335 for (i
= 0; i
< num_jn
; i
++) {
336 switch (r
->in
.level
) {
338 init_reply_dfs_info_1(ctx
, &jn
[i
], &r
->out
.info
->e
.info1
->s
[i
]);
341 init_reply_dfs_info_2(ctx
, &jn
[i
], &r
->out
.info
->e
.info2
->s
[i
]);
344 init_reply_dfs_info_3(ctx
, &jn
[i
], &r
->out
.info
->e
.info3
->s
[i
]);
347 return WERR_INVALID_PARAM
;
354 WERROR
_dfs_GetInfo(pipes_struct
*p
, struct dfs_GetInfo
*r
)
356 int consumedcnt
= strlen(r
->in
.dfs_entry_path
);
357 struct junction_map
*jn
= NULL
;
358 bool self_ref
= False
;
359 TALLOC_CTX
*ctx
= talloc_tos();
362 jn
= TALLOC_ZERO_P(ctx
, struct junction_map
);
367 if(!create_junction(ctx
, r
->in
.dfs_entry_path
, jn
)) {
368 return WERR_DFS_NO_SUCH_SERVER
;
371 /* The following call can change the cwd. */
372 if(!NT_STATUS_IS_OK(get_referred_path(ctx
, r
->in
.dfs_entry_path
,
373 jn
, &consumedcnt
, &self_ref
)) ||
374 consumedcnt
< strlen(r
->in
.dfs_entry_path
)) {
375 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
376 return WERR_DFS_NO_SUCH_VOL
;
379 vfs_ChDir(p
->conn
,p
->conn
->connectpath
);
381 switch (r
->in
.level
) {
383 r
->out
.info
->info1
= TALLOC_ZERO_P(ctx
,struct dfs_Info1
);
384 if (!r
->out
.info
->info1
) {
387 ret
= init_reply_dfs_info_1(ctx
, jn
, r
->out
.info
->info1
);
390 r
->out
.info
->info2
= TALLOC_ZERO_P(ctx
,struct dfs_Info2
);
391 if (!r
->out
.info
->info2
) {
394 ret
= init_reply_dfs_info_2(ctx
, jn
, r
->out
.info
->info2
);
397 r
->out
.info
->info3
= TALLOC_ZERO_P(ctx
,struct dfs_Info3
);
398 if (!r
->out
.info
->info3
) {
401 ret
= init_reply_dfs_info_3(ctx
, jn
, r
->out
.info
->info3
);
404 r
->out
.info
->info100
= TALLOC_ZERO_P(ctx
,struct dfs_Info100
);
405 if (!r
->out
.info
->info100
) {
408 ret
= init_reply_dfs_info_100(ctx
, jn
, r
->out
.info
->info100
);
411 r
->out
.info
->info1
= NULL
;
412 return WERR_INVALID_PARAM
;
416 return WERR_INVALID_PARAM
;
421 WERROR
_dfs_SetInfo(pipes_struct
*p
, struct dfs_SetInfo
*r
)
423 /* FIXME: Implement your code here */
424 p
->rng_fault_state
= True
;
425 return WERR_NOT_SUPPORTED
;
428 WERROR
_dfs_Rename(pipes_struct
*p
, struct dfs_Rename
*r
)
430 /* FIXME: Implement your code here */
431 p
->rng_fault_state
= True
;
432 return WERR_NOT_SUPPORTED
;
435 WERROR
_dfs_Move(pipes_struct
*p
, struct dfs_Move
*r
)
437 /* FIXME: Implement your code here */
438 p
->rng_fault_state
= True
;
439 return WERR_NOT_SUPPORTED
;
442 WERROR
_dfs_ManagerGetConfigInfo(pipes_struct
*p
, struct dfs_ManagerGetConfigInfo
*r
)
444 /* FIXME: Implement your code here */
445 p
->rng_fault_state
= True
;
446 return WERR_NOT_SUPPORTED
;
449 WERROR
_dfs_ManagerSendSiteInfo(pipes_struct
*p
, struct dfs_ManagerSendSiteInfo
*r
)
451 /* FIXME: Implement your code here */
452 p
->rng_fault_state
= True
;
453 return WERR_NOT_SUPPORTED
;
456 WERROR
_dfs_AddFtRoot(pipes_struct
*p
, struct dfs_AddFtRoot
*r
)
458 /* FIXME: Implement your code here */
459 p
->rng_fault_state
= True
;
460 return WERR_NOT_SUPPORTED
;
463 WERROR
_dfs_RemoveFtRoot(pipes_struct
*p
, struct dfs_RemoveFtRoot
*r
)
465 /* FIXME: Implement your code here */
466 p
->rng_fault_state
= True
;
467 return WERR_NOT_SUPPORTED
;
470 WERROR
_dfs_AddStdRoot(pipes_struct
*p
, struct dfs_AddStdRoot
*r
)
472 /* FIXME: Implement your code here */
473 p
->rng_fault_state
= True
;
474 return WERR_NOT_SUPPORTED
;
477 WERROR
_dfs_RemoveStdRoot(pipes_struct
*p
, struct dfs_RemoveStdRoot
*r
)
479 /* FIXME: Implement your code here */
480 p
->rng_fault_state
= True
;
481 return WERR_NOT_SUPPORTED
;
484 WERROR
_dfs_ManagerInitialize(pipes_struct
*p
, struct dfs_ManagerInitialize
*r
)
486 /* FIXME: Implement your code here */
487 p
->rng_fault_state
= True
;
488 return WERR_NOT_SUPPORTED
;
491 WERROR
_dfs_AddStdRootForced(pipes_struct
*p
, struct dfs_AddStdRootForced
*r
)
493 /* FIXME: Implement your code here */
494 p
->rng_fault_state
= True
;
495 return WERR_NOT_SUPPORTED
;
498 WERROR
_dfs_GetDcAddress(pipes_struct
*p
, struct dfs_GetDcAddress
*r
)
500 /* FIXME: Implement your code here */
501 p
->rng_fault_state
= True
;
502 return WERR_NOT_SUPPORTED
;
505 WERROR
_dfs_SetDcAddress(pipes_struct
*p
, struct dfs_SetDcAddress
*r
)
507 /* FIXME: Implement your code here */
508 p
->rng_fault_state
= True
;
509 return WERR_NOT_SUPPORTED
;
512 WERROR
_dfs_FlushFtTable(pipes_struct
*p
, struct dfs_FlushFtTable
*r
)
514 /* FIXME: Implement your code here */
515 p
->rng_fault_state
= True
;
516 return WERR_NOT_SUPPORTED
;
519 WERROR
_dfs_Add2(pipes_struct
*p
, struct dfs_Add2
*r
)
521 /* FIXME: Implement your code here */
522 p
->rng_fault_state
= True
;
523 return WERR_NOT_SUPPORTED
;
526 WERROR
_dfs_Remove2(pipes_struct
*p
, struct dfs_Remove2
*r
)
528 /* FIXME: Implement your code here */
529 p
->rng_fault_state
= True
;
530 return WERR_NOT_SUPPORTED
;
533 WERROR
_dfs_EnumEx(pipes_struct
*p
, struct dfs_EnumEx
*r
)
535 /* FIXME: Implement your code here */
536 p
->rng_fault_state
= True
;
537 return WERR_NOT_SUPPORTED
;
540 WERROR
_dfs_SetInfo2(pipes_struct
*p
, struct dfs_SetInfo2
*r
)
542 /* FIXME: Implement your code here */
543 p
->rng_fault_state
= True
;
544 return WERR_NOT_SUPPORTED
;