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.
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;
41 WERROR _dfs_Add(pipes_struct *p, struct dfs_Add *r)
43 struct junction_map jn;
44 struct referral* old_referral_list = NULL;
45 BOOL self_ref = False;
51 if (p->pipe_user.ut.uid != 0) {
52 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
53 return WERR_ACCESS_DENIED;
56 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
57 r->in.path, r->in.server, r->in.share));
59 pstrcpy(altpath, r->in.server);
60 pstrcat(altpath, "\\");
61 pstrcat(altpath, r->in.share);
63 /* The following call can change the cwd. */
64 if(NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, r->in.path, &jn, &consumedcnt, &self_ref))) {
66 jn.referral_count += 1;
67 old_referral_list = jn.referral_list;
69 jn.referral_count = 1;
72 vfs_ChDir(p->conn,p->conn->connectpath);
74 jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count);
75 if(jn.referral_list == NULL) {
76 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
77 return WERR_DFS_INTERNAL_ERROR;
80 if(old_referral_list) {
81 memcpy(jn.referral_list, old_referral_list, sizeof(struct referral)*jn.referral_count-1);
84 jn.referral_list[jn.referral_count-1].proximity = 0;
85 jn.referral_list[jn.referral_count-1].ttl = REFERRAL_TTL;
87 pstrcpy(jn.referral_list[jn.referral_count-1].alternate_path, altpath);
89 if(!create_msdfs_link(&jn, exists)) {
90 vfs_ChDir(p->conn,p->conn->connectpath);
91 return WERR_DFS_CANT_CREATE_JUNCT;
93 vfs_ChDir(p->conn,p->conn->connectpath);
98 WERROR _dfs_Remove(pipes_struct *p, struct dfs_Remove *r)
100 struct junction_map jn;
101 BOOL self_ref = False;
107 if (p->pipe_user.ut.uid != 0) {
108 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
109 return WERR_ACCESS_DENIED;
112 if (r->in.servername && r->in.sharename) {
113 pstrcpy(altpath, r->in.servername);
114 pstrcat(altpath, "\\");
115 pstrcat(altpath, r->in.sharename);
119 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
120 r->in.dfs_entry_path, r->in.servername, r->in.sharename));
122 if(!NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, r->in.dfs_entry_path, &jn, &consumedcnt, &self_ref))) {
123 return WERR_DFS_NO_SUCH_VOL;
126 /* if no server-share pair given, remove the msdfs link completely */
127 if(!r->in.servername && !r->in.sharename) {
128 if(!remove_msdfs_link(&jn)) {
129 vfs_ChDir(p->conn,p->conn->connectpath);
130 return WERR_DFS_NO_SUCH_VOL;
132 vfs_ChDir(p->conn,p->conn->connectpath);
135 /* compare each referral in the list with the one to remove */
136 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath, jn.referral_count));
137 for(i=0;i<jn.referral_count;i++) {
139 pstrcpy(refpath,jn.referral_list[i].alternate_path);
140 trim_char(refpath, '\\', '\\');
141 DEBUG(10,("_dfs_remove: refpath: .%s.\n", refpath));
142 if(strequal(refpath, altpath)) {
143 *(jn.referral_list[i].alternate_path)='\0';
144 DEBUG(10,("_dfs_remove: Removal request matches referral %s\n",
151 return WERR_DFS_NO_SUCH_SHARE;
154 /* Only one referral, remove it */
155 if(jn.referral_count == 1) {
156 if(!remove_msdfs_link(&jn)) {
157 vfs_ChDir(p->conn,p->conn->connectpath);
158 return WERR_DFS_NO_SUCH_VOL;
161 if(!create_msdfs_link(&jn, True)) {
162 vfs_ChDir(p->conn,p->conn->connectpath);
163 return WERR_DFS_CANT_CREATE_JUNCT;
166 vfs_ChDir(p->conn,p->conn->connectpath);
172 static BOOL init_reply_dfs_info_1(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info1* dfs1)
174 dfs1->path = talloc_asprintf(mem_ctx,
175 "\\\\%s\\%s\\%s", global_myname(),
176 j->service_name, j->volume_name);
177 if (dfs1->path == NULL)
180 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",dfs1->path));
184 static BOOL init_reply_dfs_info_2(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info2* dfs2)
186 dfs2->path = talloc_asprintf(mem_ctx,
187 "\\\\%s\\%s\\%s", global_myname(), j->service_name, j->volume_name);
188 if (dfs2->path == NULL)
190 dfs2->comment = talloc_strdup(mem_ctx, j->comment);
191 dfs2->state = 1; /* set up state of dfs junction as OK */
192 dfs2->num_stores = j->referral_count;
196 static BOOL init_reply_dfs_info_3(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info3* dfs3)
199 if (j->volume_name[0] == '\0')
200 dfs3->path = talloc_asprintf(mem_ctx, "\\\\%s\\%s",
201 global_myname(), j->service_name);
203 dfs3->path = talloc_asprintf(mem_ctx, "\\\\%s\\%s\\%s", global_myname(),
204 j->service_name, j->volume_name);
206 if (dfs3->path == NULL)
209 dfs3->comment = talloc_strdup(mem_ctx, j->comment);
211 dfs3->num_stores = j->referral_count;
213 /* also enumerate the stores */
214 if (j->referral_count) {
215 dfs3->stores = TALLOC_ARRAY(mem_ctx, struct dfs_StorageInfo, j->referral_count);
218 memset(dfs3->stores, '\0', j->referral_count * sizeof(struct dfs_StorageInfo));
223 for(ii=0;ii<j->referral_count;ii++) {
226 struct dfs_StorageInfo* stor = &(dfs3->stores[ii]);
227 struct referral* ref = &(j->referral_list[ii]);
229 pstrcpy(path, ref->alternate_path);
230 trim_char(path,'\\','\0');
231 p = strrchr_m(path,'\\');
233 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path));
237 DEBUG(5,("storage %d: %s.%s\n",ii,path,p+1));
238 stor->state = 2; /* set all stores as ONLINE */
239 stor->server = talloc_strdup(mem_ctx, path);
240 stor->share = talloc_strdup(mem_ctx, p+1);
245 static BOOL init_reply_dfs_info_100(TALLOC_CTX *mem_ctx, struct junction_map* j, struct dfs_Info100* dfs100)
247 dfs100->comment = talloc_strdup(mem_ctx, j->comment);
252 WERROR _dfs_Enum(pipes_struct *p, struct dfs_Enum *r)
254 struct junction_map jn[MAX_MSDFS_JUNCTIONS];
258 num_jn = enum_msdfs_links(p->mem_ctx, jn, ARRAY_SIZE(jn));
259 vfs_ChDir(p->conn,p->conn->connectpath);
261 DEBUG(5,("_dfs_Enum: %d junctions found in Dfs, doing level %d\n", num_jn, r->in.level));
263 *r->out.total = num_jn;
265 /* Create the return array */
266 switch (r->in.level) {
269 if ((r->out.info->e.info1->s = TALLOC_ARRAY(p->mem_ctx, struct dfs_Info1, num_jn)) == NULL) {
273 r->out.info->e.info1->s = NULL;
275 r->out.info->e.info1->count = num_jn;
279 if ((r->out.info->e.info2->s = TALLOC_ARRAY(p->mem_ctx, struct dfs_Info2, num_jn)) == NULL) {
283 r->out.info->e.info2->s = NULL;
285 r->out.info->e.info2->count = num_jn;
289 if ((r->out.info->e.info3->s = TALLOC_ARRAY(p->mem_ctx, struct dfs_Info3, num_jn)) == NULL) {
293 r->out.info->e.info3->s = NULL;
295 r->out.info->e.info3->count = num_jn;
298 return WERR_INVALID_PARAM;
301 for (i = 0; i < num_jn; i++) {
302 switch (r->in.level) {
304 init_reply_dfs_info_1(p->mem_ctx, &jn[i], &r->out.info->e.info1->s[i]);
307 init_reply_dfs_info_2(p->mem_ctx, &jn[i], &r->out.info->e.info2->s[i]);
310 init_reply_dfs_info_3(p->mem_ctx, &jn[i], &r->out.info->e.info3->s[i]);
313 return WERR_INVALID_PARAM;
320 WERROR _dfs_GetInfo(pipes_struct *p, struct dfs_GetInfo *r)
322 int consumedcnt = sizeof(pstring);
323 struct junction_map jn;
324 BOOL self_ref = False;
327 if(!create_junction(r->in.dfs_entry_path, &jn))
328 return WERR_DFS_NO_SUCH_SERVER;
330 /* The following call can change the cwd. */
331 if(!NT_STATUS_IS_OK(get_referred_path(p->mem_ctx, r->in.dfs_entry_path, &jn, &consumedcnt, &self_ref)) || consumedcnt < strlen(r->in.dfs_entry_path)) {
332 vfs_ChDir(p->conn,p->conn->connectpath);
333 return WERR_DFS_NO_SUCH_VOL;
336 vfs_ChDir(p->conn,p->conn->connectpath);
338 switch (r->in.level) {
339 case 1: ret = init_reply_dfs_info_1(p->mem_ctx, &jn, r->out.info->info1); break;
340 case 2: ret = init_reply_dfs_info_2(p->mem_ctx, &jn, r->out.info->info2); break;
341 case 3: ret = init_reply_dfs_info_3(p->mem_ctx, &jn, r->out.info->info3); break;
342 case 100: ret = init_reply_dfs_info_100(p->mem_ctx, &jn, r->out.info->info100); break;
344 r->out.info->info1 = NULL;
345 return WERR_INVALID_PARAM;
349 return WERR_INVALID_PARAM;
354 WERROR _dfs_SetInfo(pipes_struct *p, struct dfs_SetInfo *r)
356 /* FIXME: Implement your code here */
357 p->rng_fault_state = True;
358 return WERR_NOT_SUPPORTED;
361 WERROR _dfs_Rename(pipes_struct *p, struct dfs_Rename *r)
363 /* FIXME: Implement your code here */
364 p->rng_fault_state = True;
365 return WERR_NOT_SUPPORTED;
368 WERROR _dfs_Move(pipes_struct *p, struct dfs_Move *r)
370 /* FIXME: Implement your code here */
371 p->rng_fault_state = True;
372 return WERR_NOT_SUPPORTED;
375 WERROR _dfs_ManagerGetConfigInfo(pipes_struct *p, struct dfs_ManagerGetConfigInfo *r)
377 /* FIXME: Implement your code here */
378 p->rng_fault_state = True;
379 return WERR_NOT_SUPPORTED;
382 WERROR _dfs_ManagerSendSiteInfo(pipes_struct *p, struct dfs_ManagerSendSiteInfo *r)
384 /* FIXME: Implement your code here */
385 p->rng_fault_state = True;
386 return WERR_NOT_SUPPORTED;
389 WERROR _dfs_AddFtRoot(pipes_struct *p, struct dfs_AddFtRoot *r)
391 /* FIXME: Implement your code here */
392 p->rng_fault_state = True;
393 return WERR_NOT_SUPPORTED;
396 WERROR _dfs_RemoveFtRoot(pipes_struct *p, struct dfs_RemoveFtRoot *r)
398 /* FIXME: Implement your code here */
399 p->rng_fault_state = True;
400 return WERR_NOT_SUPPORTED;
403 WERROR _dfs_AddStdRoot(pipes_struct *p, struct dfs_AddStdRoot *r)
405 /* FIXME: Implement your code here */
406 p->rng_fault_state = True;
407 return WERR_NOT_SUPPORTED;
410 WERROR _dfs_RemoveStdRoot(pipes_struct *p, struct dfs_RemoveStdRoot *r)
412 /* FIXME: Implement your code here */
413 p->rng_fault_state = True;
414 return WERR_NOT_SUPPORTED;
417 WERROR _dfs_ManagerInitialize(pipes_struct *p, struct dfs_ManagerInitialize *r)
419 /* FIXME: Implement your code here */
420 p->rng_fault_state = True;
421 return WERR_NOT_SUPPORTED;
424 WERROR _dfs_AddStdRootForced(pipes_struct *p, struct dfs_AddStdRootForced *r)
426 /* FIXME: Implement your code here */
427 p->rng_fault_state = True;
428 return WERR_NOT_SUPPORTED;
431 WERROR _dfs_GetDcAddress(pipes_struct *p, struct dfs_GetDcAddress *r)
433 /* FIXME: Implement your code here */
434 p->rng_fault_state = True;
435 return WERR_NOT_SUPPORTED;
438 WERROR _dfs_SetDcAddress(pipes_struct *p, struct dfs_SetDcAddress *r)
440 /* FIXME: Implement your code here */
441 p->rng_fault_state = True;
442 return WERR_NOT_SUPPORTED;
445 WERROR _dfs_FlushFtTable(pipes_struct *p, struct dfs_FlushFtTable *r)
447 /* FIXME: Implement your code here */
448 p->rng_fault_state = True;
449 return WERR_NOT_SUPPORTED;
452 WERROR _dfs_Add2(pipes_struct *p, struct dfs_Add2 *r)
454 /* FIXME: Implement your code here */
455 p->rng_fault_state = True;
456 return WERR_NOT_SUPPORTED;
459 WERROR _dfs_Remove2(pipes_struct *p, struct dfs_Remove2 *r)
461 /* FIXME: Implement your code here */
462 p->rng_fault_state = True;
463 return WERR_NOT_SUPPORTED;
466 WERROR _dfs_EnumEx(pipes_struct *p, struct dfs_EnumEx *r)
468 /* FIXME: Implement your code here */
469 p->rng_fault_state = True;
470 return WERR_NOT_SUPPORTED;
473 WERROR _dfs_SetInfo2(pipes_struct *p, struct dfs_SetInfo2 *r)
475 /* FIXME: Implement your code here */
476 p->rng_fault_state = True;
477 return WERR_NOT_SUPPORTED;