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.
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 2 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, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* This is the implementation of the dfs pipe. */
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 uint32 _dfs_GetManagerVersion(pipes_struct *p, NETDFS_Q_DFS_GETMANAGERVERSION *q_u, NETDFS_R_DFS_GETMANAGERVERSION *r_u)
41 WERROR _dfs_Add(pipes_struct *p, NETDFS_Q_DFS_ADD* q_u, NETDFS_R_DFS_ADD *r_u)
43 struct current_user user;
44 struct junction_map jn;
45 struct referral* old_referral_list = NULL;
48 pstring dfspath, servername, sharename;
51 get_current_user(&user,p);
53 if (user.ut.uid != 0) {
54 DEBUG(10,("_dfs_add: uid != 0. Access denied.\n"));
55 return WERR_ACCESS_DENIED;
58 unistr2_to_ascii(dfspath, &q_u->path, sizeof(dfspath)-1);
59 unistr2_to_ascii(servername, &q_u->server, sizeof(servername)-1);
60 unistr2_to_ascii(sharename, &q_u->share, sizeof(sharename)-1);
62 DEBUG(5,("init_reply_dfs_add: Request to add %s -> %s\\%s.\n",
63 dfspath, servername, sharename));
65 pstrcpy(altpath, servername);
66 pstrcat(altpath, "\\");
67 pstrcat(altpath, sharename);
69 /* The following call can change the cwd. */
70 if(get_referred_path(p->mem_ctx, dfspath, &jn, NULL, NULL)) {
72 jn.referral_count += 1;
73 old_referral_list = jn.referral_list;
75 jn.referral_count = 1;
78 vfs_ChDir(p->conn,p->conn->connectpath);
80 jn.referral_list = TALLOC_ARRAY(p->mem_ctx, struct referral, jn.referral_count);
81 if(jn.referral_list == NULL) {
82 DEBUG(0,("init_reply_dfs_add: talloc failed for referral list!\n"));
83 return WERR_DFS_INTERNAL_ERROR;
86 if(old_referral_list) {
87 memcpy(jn.referral_list, old_referral_list, sizeof(struct referral)*jn.referral_count-1);
90 jn.referral_list[jn.referral_count-1].proximity = 0;
91 jn.referral_list[jn.referral_count-1].ttl = REFERRAL_TTL;
93 pstrcpy(jn.referral_list[jn.referral_count-1].alternate_path, altpath);
95 if(!create_msdfs_link(&jn, exists)) {
96 vfs_ChDir(p->conn,p->conn->connectpath);
97 return WERR_DFS_CANT_CREATE_JUNCT;
99 vfs_ChDir(p->conn,p->conn->connectpath);
104 WERROR _dfs_Remove(pipes_struct *p, NETDFS_Q_DFS_REMOVE *q_u,
105 NETDFS_R_DFS_REMOVE *r_u)
107 struct current_user user;
108 struct junction_map jn;
111 pstring dfspath, servername, sharename;
114 get_current_user(&user,p);
116 if (user.ut.uid != 0) {
117 DEBUG(10,("_dfs_remove: uid != 0. Access denied.\n"));
118 return WERR_ACCESS_DENIED;
121 unistr2_to_ascii(dfspath, &q_u->path, sizeof(dfspath)-1);
122 if(q_u->ptr0_server) {
123 unistr2_to_ascii(servername, &q_u->server, sizeof(servername)-1);
126 if(q_u->ptr0_share) {
127 unistr2_to_ascii(sharename, &q_u->share, sizeof(sharename)-1);
130 if(q_u->ptr0_server && q_u->ptr0_share) {
131 pstrcpy(altpath, servername);
132 pstrcat(altpath, "\\");
133 pstrcat(altpath, sharename);
137 DEBUG(5,("init_reply_dfs_remove: Request to remove %s -> %s\\%s.\n",
138 dfspath, servername, sharename));
140 if(!get_referred_path(p->mem_ctx, dfspath, &jn, NULL, NULL)) {
141 return WERR_DFS_NO_SUCH_VOL;
144 /* if no server-share pair given, remove the msdfs link completely */
145 if(!q_u->ptr0_server && !q_u->ptr0_share) {
146 if(!remove_msdfs_link(&jn)) {
147 vfs_ChDir(p->conn,p->conn->connectpath);
148 return WERR_DFS_NO_SUCH_VOL;
150 vfs_ChDir(p->conn,p->conn->connectpath);
153 /* compare each referral in the list with the one to remove */
154 DEBUG(10,("altpath: .%s. refcnt: %d\n", altpath, jn.referral_count));
155 for(i=0;i<jn.referral_count;i++) {
157 pstrcpy(refpath,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 vfs_ChDir(p->conn,p->conn->connectpath);
176 return WERR_DFS_NO_SUCH_VOL;
179 if(!create_msdfs_link(&jn, True)) {
180 vfs_ChDir(p->conn,p->conn->connectpath);
181 return WERR_DFS_CANT_CREATE_JUNCT;
184 vfs_ChDir(p->conn,p->conn->connectpath);
190 static BOOL init_reply_dfs_info_1(struct junction_map* j, NETDFS_DFS_INFO1* dfs1)
194 slprintf(str, sizeof(pstring)-1, "\\\\%s\\%s\\%s", global_myname(),
195 j->service_name, j->volume_name);
196 DEBUG(5,("init_reply_dfs_info_1: initing entrypath: %s\n",str));
197 init_unistr2(&dfs1->path,str,UNI_STR_TERMINATE);
201 static BOOL init_reply_dfs_info_2(struct junction_map* j, NETDFS_DFS_INFO2* dfs2)
205 slprintf(str, sizeof(pstring)-1, "\\\\%s\\%s\\%s", global_myname(),
206 j->service_name, j->volume_name);
207 init_unistr2(&dfs2->path, str, UNI_STR_TERMINATE);
208 dfs2->ptr0_comment = 0;
209 dfs2->state = 1; /* set up state of dfs junction as OK */
210 dfs2->num_stores = j->referral_count;
214 static BOOL init_reply_dfs_info_3(TALLOC_CTX *ctx, struct junction_map* j, NETDFS_DFS_INFO3* dfs3)
219 if (j->volume_name[0] == '\0')
220 slprintf(str, sizeof(pstring)-1, "\\\\%s\\%s",
221 global_myname(), j->service_name);
223 slprintf(str, sizeof(pstring)-1, "\\\\%s\\%s\\%s", global_myname(),
224 j->service_name, j->volume_name);
226 init_unistr2(&dfs3->path, str, UNI_STR_TERMINATE);
227 dfs3->ptr0_comment = 1;
228 init_unistr2(&dfs3->comment, "", UNI_STR_TERMINATE);
230 dfs3->num_stores = dfs3->size_stores = j->referral_count;
231 dfs3->ptr0_stores = 1;
233 /* also enumerate the stores */
234 dfs3->stores = TALLOC_ARRAY(ctx, NETDFS_DFS_STORAGEINFO, j->referral_count);
238 memset(dfs3->stores, '\0', j->referral_count * sizeof(NETDFS_DFS_STORAGEINFO));
240 for(ii=0;ii<j->referral_count;ii++) {
243 NETDFS_DFS_STORAGEINFO* stor = &(dfs3->stores[ii]);
244 struct referral* ref = &(j->referral_list[ii]);
246 pstrcpy(path, ref->alternate_path);
247 trim_char(path,'\\','\0');
248 p = strrchr_m(path,'\\');
250 DEBUG(4,("init_reply_dfs_info_3: invalid path: no \\ found in %s\n",path));
254 DEBUG(5,("storage %d: %s.%s\n",ii,path,p+1));
255 stor->state = 2; /* set all stores as ONLINE */
256 init_unistr2(&stor->server, path, UNI_STR_TERMINATE);
257 init_unistr2(&stor->share, p+1, UNI_STR_TERMINATE);
258 stor->ptr0_server = stor->ptr0_share = 1;
263 WERROR _dfs_Enum(pipes_struct *p, NETDFS_Q_DFS_ENUM *q_u, NETDFS_R_DFS_ENUM *r_u)
265 uint32 level = q_u->level;
266 struct junction_map jn[MAX_MSDFS_JUNCTIONS];
270 num_jn = enum_msdfs_links(p->mem_ctx, jn, ARRAY_SIZE(jn));
271 vfs_ChDir(p->conn,p->conn->connectpath);
273 DEBUG(5,("make_reply_dfs_enum: %d junctions found in Dfs, doing level %d\n", num_jn, level));
275 r_u->ptr0_info = q_u->ptr0_info;
276 r_u->ptr0_total = q_u->ptr0_total;
279 r_u->info = q_u->info;
281 /* Create the return array */
284 if ((r_u->info.e.u.info1.s = TALLOC_ARRAY(p->mem_ctx, NETDFS_DFS_INFO1, num_jn)) == NULL) {
287 r_u->info.e.u.info1.count = num_jn;
288 r_u->info.e.u.info1.ptr0_s = 1;
289 r_u->info.e.u.info1.size_s = num_jn;
292 if ((r_u->info.e.u.info2.s = TALLOC_ARRAY(p->mem_ctx, NETDFS_DFS_INFO2, num_jn)) == NULL) {
295 r_u->info.e.u.info2.count = num_jn;
296 r_u->info.e.u.info2.ptr0_s = 1;
297 r_u->info.e.u.info2.size_s = num_jn;
300 if ((r_u->info.e.u.info3.s = TALLOC_ARRAY(p->mem_ctx, NETDFS_DFS_INFO3, num_jn)) == NULL) {
303 r_u->info.e.u.info3.count = num_jn;
304 r_u->info.e.u.info3.ptr0_s = 1;
305 r_u->info.e.u.info3.size_s = num_jn;
308 return WERR_INVALID_PARAM;
311 for (i = 0; i < num_jn; i++) {
314 init_reply_dfs_info_1(&jn[i], &r_u->info.e.u.info1.s[i]);
317 init_reply_dfs_info_2(&jn[i], &r_u->info.e.u.info2.s[i]);
320 init_reply_dfs_info_3(p->mem_ctx, &jn[i], &r_u->info.e.u.info3.s[i]);
323 return WERR_INVALID_PARAM;
327 r_u->status = WERR_OK;
332 WERROR _dfs_GetInfo(pipes_struct *p, NETDFS_Q_DFS_GETINFO *q_u,
333 NETDFS_R_DFS_GETINFO *r_u)
335 UNISTR2* uni_path = &q_u->path;
336 uint32 level = q_u->level;
337 int consumedcnt = sizeof(pstring);
340 struct junction_map jn;
342 unistr2_to_ascii(path, uni_path, sizeof(path)-1);
343 if(!create_junction(path, &jn))
344 return WERR_DFS_NO_SUCH_SERVER;
346 /* The following call can change the cwd. */
347 if(!get_referred_path(p->mem_ctx, path, &jn, &consumedcnt, NULL) || consumedcnt < strlen(path)) {
348 vfs_ChDir(p->conn,p->conn->connectpath);
349 return WERR_DFS_NO_SUCH_VOL;
352 vfs_ChDir(p->conn,p->conn->connectpath);
353 r_u->info.switch_value = level;
355 r_u->status = WERR_OK;
358 case 1: ret = init_reply_dfs_info_1(&jn, &r_u->info.u.info1); break;
359 case 2: ret = init_reply_dfs_info_2(&jn, &r_u->info.u.info2); break;
360 case 3: ret = init_reply_dfs_info_3(p->mem_ctx, &jn, &r_u->info.u.info3); break;
367 r_u->status = WERR_INVALID_PARAM;
372 WERROR _dfs_SetInfo(pipes_struct *p, NETDFS_Q_DFS_SETINFO *q_u, NETDFS_R_DFS_SETINFO *r_u)
374 /* FIXME: Implement your code here */
375 return WERR_NOT_SUPPORTED;
378 WERROR _dfs_Rename(pipes_struct *p, NETDFS_Q_DFS_RENAME *q_u, NETDFS_R_DFS_RENAME *r_u)
380 /* FIXME: Implement your code here */
381 return WERR_NOT_SUPPORTED;
384 WERROR _dfs_Move(pipes_struct *p, NETDFS_Q_DFS_MOVE *q_u, NETDFS_R_DFS_MOVE *r_u)
386 /* FIXME: Implement your code here */
387 return WERR_NOT_SUPPORTED;
390 WERROR _dfs_ManagerGetConfigInfo(pipes_struct *p, NETDFS_Q_DFS_MANAGERGETCONFIGINFO *q_u, NETDFS_R_DFS_MANAGERGETCONFIGINFO *r_u)
392 /* FIXME: Implement your code here */
393 return WERR_NOT_SUPPORTED;
396 WERROR _dfs_ManagerSendSiteInfo(pipes_struct *p, NETDFS_Q_DFS_MANAGERSENDSITEINFO *q_u, NETDFS_R_DFS_MANAGERSENDSITEINFO *r_u)
398 /* FIXME: Implement your code here */
399 return WERR_NOT_SUPPORTED;
402 WERROR _dfs_AddFtRoot(pipes_struct *p, NETDFS_Q_DFS_ADDFTROOT *q_u, NETDFS_R_DFS_ADDFTROOT *r_u)
404 /* FIXME: Implement your code here */
405 return WERR_NOT_SUPPORTED;
408 WERROR _dfs_RemoveFtRoot(pipes_struct *p, NETDFS_Q_DFS_REMOVEFTROOT *q_u, NETDFS_R_DFS_REMOVEFTROOT *r_u)
410 /* FIXME: Implement your code here */
411 return WERR_NOT_SUPPORTED;
414 WERROR _dfs_AddStdRoot(pipes_struct *p, NETDFS_Q_DFS_ADDSTDROOT *q_u, NETDFS_R_DFS_ADDSTDROOT *r_u)
416 /* FIXME: Implement your code here */
417 return WERR_NOT_SUPPORTED;
420 WERROR _dfs_RemoveStdRoot(pipes_struct *p, NETDFS_Q_DFS_REMOVESTDROOT *q_u, NETDFS_R_DFS_REMOVESTDROOT *r_u)
422 /* FIXME: Implement your code here */
423 return WERR_NOT_SUPPORTED;
426 WERROR _dfs_ManagerInitialize(pipes_struct *p, NETDFS_Q_DFS_MANAGERINITIALIZE *q_u, NETDFS_R_DFS_MANAGERINITIALIZE *r_u)
428 /* FIXME: Implement your code here */
429 return WERR_NOT_SUPPORTED;
432 WERROR _dfs_AddStdRootForced(pipes_struct *p, NETDFS_Q_DFS_ADDSTDROOTFORCED *q_u, NETDFS_R_DFS_ADDSTDROOTFORCED *r_u)
434 /* FIXME: Implement your code here */
435 return WERR_NOT_SUPPORTED;
438 WERROR _dfs_GetDcAddress(pipes_struct *p, NETDFS_Q_DFS_GETDCADDRESS *q_u, NETDFS_R_DFS_GETDCADDRESS *r_u)
440 /* FIXME: Implement your code here */
441 return WERR_NOT_SUPPORTED;
444 WERROR _dfs_SetDcAddress(pipes_struct *p, NETDFS_Q_DFS_SETDCADDRESS *q_u, NETDFS_R_DFS_SETDCADDRESS *r_u)
446 /* FIXME: Implement your code here */
447 return WERR_NOT_SUPPORTED;
450 WERROR _dfs_FlushFtTable(pipes_struct *p, NETDFS_Q_DFS_FLUSHFTTABLE *q_u, NETDFS_R_DFS_FLUSHFTTABLE *r_u)
452 /* FIXME: Implement your code here */
453 return WERR_NOT_SUPPORTED;
456 WERROR _dfs_Add2(pipes_struct *p, NETDFS_Q_DFS_ADD2 *q_u, NETDFS_R_DFS_ADD2 *r_u)
458 /* FIXME: Implement your code here */
459 return WERR_NOT_SUPPORTED;
462 WERROR _dfs_Remove2(pipes_struct *p, NETDFS_Q_DFS_REMOVE2 *q_u, NETDFS_R_DFS_REMOVE2 *r_u)
464 /* FIXME: Implement your code here */
465 return WERR_NOT_SUPPORTED;
468 WERROR _dfs_EnumEx(pipes_struct *p, NETDFS_Q_DFS_ENUMEX *q_u, NETDFS_R_DFS_ENUMEX *r_u)
470 /* FIXME: Implement your code here */
471 return WERR_NOT_SUPPORTED;
474 WERROR _dfs_SetInfo2(pipes_struct *p, NETDFS_Q_DFS_SETINFO2 *q_u, NETDFS_R_DFS_SETINFO2 *r_u)
476 /* FIXME: Implement your code here */
477 return WERR_NOT_SUPPORTED;