2 Unix SMB/Netbios implementation.
4 MSDfs services for Samba
5 Copyright (C) Shirish Kalele 2000
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 extern fstring local_machine
;
26 extern uint32 global_client_caps
;
30 /**********************************************************************
31 Parse the pathname of the form \hostname\service\reqpath
32 into the dfs_path structure
33 **********************************************************************/
35 static BOOL
parse_dfs_path(char* pathname
, struct dfs_path
* pdp
)
37 pstring pathname_local
;
40 pstrcpy(pathname_local
,pathname
);
41 p
= temp
= pathname_local
;
45 trim_string(temp
,"\\","\\");
46 DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \\'s\n",temp
));
49 /* parse out hostname */
50 p
= strchr(temp
,'\\');
54 pstrcpy(pdp
->hostname
,temp
);
55 DEBUG(10,("hostname: %s\n",pdp
->hostname
));
57 /* parse out servicename */
59 p
= strchr(temp
,'\\');
61 pstrcpy(pdp
->servicename
,temp
);
62 pdp
->reqpath
[0] = '\0';
66 pstrcpy(pdp
->servicename
,temp
);
67 DEBUG(10,("servicename: %s\n",pdp
->servicename
));
70 pstrcpy(pdp
->reqpath
, p
+1);
73 if (*p
== '\\') *p
= '/';
77 DEBUG(10,("rest of the path: %s\n",pdp
->reqpath
));
81 /********************************************************
82 Fake up a connection struct for the VFS layer.
83 *********************************************************/
85 static BOOL
create_conn_struct( connection_struct
*conn
, int snum
)
90 conn
->connectpath
= lp_pathname(snum
);
91 pstring_sub(conn
->connectpath
, "%S", lp_servicename(snum
));
93 if (!smbd_vfs_init(conn
)) {
94 DEBUG(0,("create_conn_struct: smbd_vfs_init failed.\n"));
101 /**********************************************************************
102 Parse the contents of a symlink to verify if it is an msdfs referral
103 A valid referral is of the form: msdfs:server1\share1,server2\share2
104 **********************************************************************/
105 static BOOL
parse_symlink(char* buf
,struct referral
** preflist
,
110 char* alt_path
[MAX_REFERRAL_COUNT
];
112 struct referral
* reflist
;
116 prot
= strtok(temp
,":");
118 if (!strequal(prot
, "msdfs"))
121 /* No referral list requested. Just yes/no. */
125 /* parse out the alternate paths */
126 while(((alt_path
[count
] = strtok(NULL
,",")) != NULL
) && count
<MAX_REFERRAL_COUNT
)
129 DEBUG(10,("parse_symlink: count=%d\n", count
));
131 reflist
= *preflist
= (struct referral
*) malloc(count
* sizeof(struct referral
));
132 if(reflist
== NULL
) {
133 DEBUG(0,("parse_symlink: Malloc failed!\n"));
137 for(i
=0;i
<count
;i
++) {
138 /* replace / in the alternate path by a \ */
139 char* p
= strchr(alt_path
[i
],'/');
143 pstrcpy(reflist
[i
].alternate_path
, "\\");
144 pstrcat(reflist
[i
].alternate_path
, alt_path
[i
]);
145 reflist
[i
].proximity
= 0;
146 reflist
[i
].ttl
= REFERRAL_TTL
;
147 DEBUG(10, ("parse_symlink: Created alt path: %s\n", reflist
[i
].alternate_path
));
156 /**********************************************************************
157 Returns true if the unix path is a valid msdfs symlink
158 **********************************************************************/
159 BOOL
is_msdfs_link(connection_struct
* conn
, char* path
,
160 struct referral
** reflistp
, int* refcnt
,
161 SMB_STRUCT_STAT
*sbufp
)
165 int referral_len
= 0;
175 if (conn
->vfs_ops
.lstat(conn
,dos_to_unix_static(path
), sbufp
) != 0) {
176 DEBUG(5,("is_msdfs_link: %s does not exist.\n",path
));
180 if (S_ISLNK(sbufp
->st_mode
)) {
181 /* open the link and read it */
182 referral_len
= conn
->vfs_ops
.readlink(conn
, path
, referral
,
184 if (referral_len
== -1) {
185 DEBUG(0,("is_msdfs_link: Error reading msdfs link %s: %s\n", path
, strerror(errno
)));
189 referral
[referral_len
] = '\0';
190 DEBUG(5,("is_msdfs_link: %s -> %s\n",path
,referral
));
191 if (parse_symlink(referral
, reflistp
, refcnt
))
197 /*****************************************************************
198 Used by other functions to decide if a dfs path is remote,
199 and to get the list of referred locations for that remote path.
201 findfirst_flag: For findfirsts, dfs links themselves are not
202 redirected, but paths beyond the links are. For normal smb calls,
203 even dfs links need to be redirected.
205 self_referralp: clients expect a dfs referral for the same share when
206 they request referrals for dfs roots on a server.
208 consumedcntp: how much of the dfs path is being redirected. the client
209 should try the remaining path on the redirected server.
210 *****************************************************************/
211 static BOOL
resolve_dfs_path(char* dfspath
, struct dfs_path
* dp
,
212 connection_struct
* conn
,
214 struct referral
** reflistpp
, int* refcntp
,
215 BOOL
* self_referralp
, int* consumedcntp
)
223 DEBUG(1,("resolve_dfs_path: NULL dfs_path* or NULL connection_struct*!\n"));
227 if (dp
->reqpath
[0] == '\0') {
228 if (self_referralp
) {
229 DEBUG(6,("resolve_dfs_path: self-referral. returning False\n"));
230 *self_referralp
= True
;
235 /* check if need to redirect */
236 fstrcpy(localpath
, conn
->connectpath
);
237 fstrcat(localpath
, "/");
238 fstrcat(localpath
, dp
->reqpath
);
239 if (is_msdfs_link(conn
, localpath
, reflistpp
, refcntp
, NULL
)) {
240 if (findfirst_flag
) {
241 DEBUG(6,("resolve_dfs_path (FindFirst) No redirection "
242 "for dfs link %s.\n", dfspath
));
245 DEBUG(6,("resolve_dfs_path: %s resolves to a valid Dfs link.\n",
248 *consumedcntp
= strlen(dfspath
);
253 /* also redirect if the parent directory is a dfs link */
254 fstrcpy(reqpath
, dp
->reqpath
);
255 p
= strrchr(reqpath
, '/');
258 fstrcpy(localpath
, conn
->connectpath
);
259 fstrcat(localpath
, "/");
260 fstrcat(localpath
, reqpath
);
261 if (is_msdfs_link(conn
, localpath
, reflistpp
, refcntp
, NULL
)) {
262 DEBUG(4, ("resolve_dfs_path: Redirecting %s because parent %s is dfs link\n", dfspath
, localpath
));
264 /* To find the path consumed, we truncate the original
265 DFS pathname passed to use to remove the last
266 component. The length of the resulting string is
272 safe_strcpy(buf
, dfspath
, sizeof(buf
));
273 trim_string(buf
, NULL
, "\\");
274 q
= strrchr(buf
, '\\');
277 *consumedcntp
= strlen(buf
);
278 DEBUG(10, ("resolve_dfs_path: Path consumed: %d\n", *consumedcntp
));
288 /*****************************************************************
289 Decides if a dfs pathname should be redirected or not.
290 If not, the pathname is converted to a tcon-relative local unix path
291 *****************************************************************/
292 BOOL
dfs_redirect(char* pathname
, connection_struct
* conn
,
297 if (!conn
|| !pathname
)
300 parse_dfs_path(pathname
, &dp
);
302 /* if dfs pathname for a non-dfs share, convert to tcon-relative
303 path and return false */
304 if (!lp_msdfs_root(SNUM(conn
))) {
305 fstrcpy(pathname
, dp
.reqpath
);
309 if (strcasecmp(dp
.servicename
, lp_servicename(SNUM(conn
)) ) != 0)
312 if (resolve_dfs_path(pathname
, &dp
, conn
, findfirst_flag
,
313 NULL
, NULL
, NULL
, NULL
)) {
314 DEBUG(3,("dfs_redirect: Redirecting %s\n", pathname
));
317 DEBUG(3,("dfs_redirect: Not redirecting %s.\n", pathname
));
319 /* Form non-dfs tcon-relative path */
320 fstrcpy(pathname
, dp
.reqpath
);
321 DEBUG(3,("dfs_redirect: Path converted to non-dfs path %s\n",
329 /**********************************************************************
330 Gets valid referrals for a dfs path and fills up the
331 junction_map structure
332 **********************************************************************/
333 BOOL
get_referred_path(char *pathname
, struct junction_map
* jn
,
334 int* consumedcntp
, BOOL
* self_referralp
)
338 struct connection_struct conns
;
339 struct connection_struct
* conn
= &conns
;
342 BOOL self_referral
= False
;
344 if (!pathname
|| !jn
)
348 *self_referralp
= False
;
350 self_referralp
= &self_referral
;
352 parse_dfs_path(pathname
, &dp
);
354 /* Verify hostname in path */
355 if (local_machine
&& (strcasecmp(local_machine
, dp
.hostname
) != 0)) {
357 /* Hostname mismatch, check if one of our IP addresses */
358 if (!ismyip(*interpret_addr2(dp
.hostname
))) {
360 DEBUG(3, ("get_referred_path: Invalid hostname %s in path %s\n",
361 dp
.hostname
, pathname
));
366 pstrcpy(jn
->service_name
, dp
.servicename
);
367 pstrcpy(jn
->volume_name
, dp
.reqpath
);
369 /* Verify the share is a dfs root */
370 snum
= lp_servicenumber(jn
->service_name
);
372 if ((snum
= find_service(jn
->service_name
)) < 0)
376 if (!create_conn_struct(conn
, snum
))
379 if (!lp_msdfs_root(SNUM(conn
))) {
380 DEBUG(3,("get_referred_path: .%s. in dfs path %s is not a dfs root.\n",
381 dp
.servicename
, pathname
));
385 /* If not remote & not a self referral, return False */
386 if (!resolve_dfs_path(pathname
, &dp
, conn
, False
,
387 &jn
->referral_list
, &jn
->referral_count
,
388 self_referralp
, consumedcntp
)) {
389 if (!*self_referralp
) {
390 DEBUG(3,("get_referred_path: No valid referrals for path %s\n", pathname
));
395 /* if self_referral, fill up the junction map */
396 if (*self_referralp
) {
397 struct referral
* ref
;
398 jn
->referral_count
= 1;
399 if((ref
= (struct referral
*) malloc(sizeof(struct referral
)))
401 DEBUG(0,("malloc failed for referral\n"));
405 pstrcpy(ref
->alternate_path
,pathname
);
407 ref
->ttl
= REFERRAL_TTL
;
408 jn
->referral_list
= ref
;
410 *consumedcntp
= strlen(pathname
);
416 static int setup_ver2_dfs_referral(char* pathname
, char** ppdata
,
417 struct junction_map
* junction
,
421 char* pdata
= *ppdata
;
423 unsigned char uni_requestedpath
[1024];
424 int uni_reqpathoffset1
,uni_reqpathoffset2
;
426 int requestedpathlen
=0;
431 DEBUG(10,("setting up version2 referral\nRequested path:\n"));
433 requestedpathlen
= (dos_struni2((char *)uni_requestedpath
,pathname
,512) + 1) * 2;
435 dump_data(10, (char *) uni_requestedpath
,requestedpathlen
);
437 DEBUG(10,("ref count = %u\n",junction
->referral_count
));
439 uni_reqpathoffset1
= REFERRAL_HEADER_SIZE
+
440 VERSION2_REFERRAL_SIZE
* junction
->referral_count
;
442 uni_reqpathoffset2
= uni_reqpathoffset1
+ requestedpathlen
;
444 uni_curroffset
= uni_reqpathoffset2
+ requestedpathlen
;
446 reply_size
= REFERRAL_HEADER_SIZE
+ VERSION2_REFERRAL_SIZE
*junction
->referral_count
+
447 2 * requestedpathlen
;
448 DEBUG(10,("reply_size: %u\n",reply_size
));
450 /* add up the unicode lengths of all the referral paths */
451 for(i
=0;i
<junction
->referral_count
;i
++) {
452 DEBUG(10,("referral %u : %s\n",i
,junction
->referral_list
[i
].alternate_path
));
453 reply_size
+= (strlen(junction
->referral_list
[i
].alternate_path
)+1)*2;
456 DEBUG(10,("reply_size = %u\n",reply_size
));
457 /* add the unexplained 0x16 bytes */
460 pdata
= Realloc(pdata
,reply_size
);
462 DEBUG(0,("malloc failed for Realloc!\n"));
467 /* copy in the dfs requested paths.. required for offset calculations */
468 memcpy(pdata
+uni_reqpathoffset1
,uni_requestedpath
,requestedpathlen
);
469 memcpy(pdata
+uni_reqpathoffset2
,uni_requestedpath
,requestedpathlen
);
471 /* create the header */
472 SSVAL(pdata
,0,consumedcnt
* 2); /* path consumed */
473 SSVAL(pdata
,2,junction
->referral_count
); /* number of referral in this pkt */
475 SIVAL(pdata
,4,DFSREF_REFERRAL_SERVER
| DFSREF_STORAGE_SERVER
);
477 SIVAL(pdata
,4,DFSREF_STORAGE_SERVER
);
480 /* add the referral elements */
481 for(i
=0;i
<junction
->referral_count
;i
++) {
482 struct referral
* ref
= &(junction
->referral_list
[i
]);
485 SSVAL(pdata
,offset
,2); /* version 2 */
486 SSVAL(pdata
,offset
+2,VERSION2_REFERRAL_SIZE
);
488 SSVAL(pdata
,offset
+4,1);
490 SSVAL(pdata
,offset
+4,0);
491 SSVAL(pdata
,offset
+6,0); /* ref_flags :use path_consumed bytes? */
492 SIVAL(pdata
,offset
+8,ref
->proximity
);
493 SIVAL(pdata
,offset
+12,ref
->ttl
);
495 SSVAL(pdata
,offset
+16,uni_reqpathoffset1
-offset
);
496 SSVAL(pdata
,offset
+18,uni_reqpathoffset2
-offset
);
497 /* copy referred path into current offset */
498 unilen
= (dos_struni2(pdata
+uni_curroffset
,ref
->alternate_path
,512) +1)*2;
499 SSVAL(pdata
,offset
+20,uni_curroffset
-offset
);
501 uni_curroffset
+= unilen
;
502 offset
+= VERSION2_REFERRAL_SIZE
;
504 /* add in the unexplained 22 (0x16) bytes at the end */
505 memset(pdata
+uni_curroffset
,'\0',0x16);
509 static int setup_ver3_dfs_referral(char* pathname
, char** ppdata
,
510 struct junction_map
* junction
,
514 char* pdata
= *ppdata
;
516 unsigned char uni_reqpath
[1024];
517 int uni_reqpathoffset1
, uni_reqpathoffset2
;
524 DEBUG(10,("setting up version3 referral\n"));
526 reqpathlen
= (dos_struni2((char *) uni_reqpath
,pathname
,512)+1)*2;
528 dump_data(10, (char *) uni_reqpath
,reqpathlen
);
530 uni_reqpathoffset1
= REFERRAL_HEADER_SIZE
+ VERSION3_REFERRAL_SIZE
* junction
->referral_count
;
531 uni_reqpathoffset2
= uni_reqpathoffset1
+ reqpathlen
;
532 reply_size
= uni_curroffset
= uni_reqpathoffset2
+ reqpathlen
;
534 for(i
=0;i
<junction
->referral_count
;i
++) {
535 DEBUG(10,("referral %u : %s\n",i
,junction
->referral_list
[i
].alternate_path
));
536 reply_size
+= (strlen(junction
->referral_list
[i
].alternate_path
)+1)*2;
539 pdata
= Realloc(pdata
,reply_size
);
541 DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
546 /* create the header */
547 SSVAL(pdata
,0,consumedcnt
* 2); /* path consumed */
548 SSVAL(pdata
,2,junction
->referral_count
); /* number of referral */
550 SIVAL(pdata
,4,DFSREF_REFERRAL_SERVER
| DFSREF_STORAGE_SERVER
);
552 SIVAL(pdata
,4,DFSREF_STORAGE_SERVER
);
554 /* copy in the reqpaths */
555 memcpy(pdata
+uni_reqpathoffset1
,uni_reqpath
,reqpathlen
);
556 memcpy(pdata
+uni_reqpathoffset2
,uni_reqpath
,reqpathlen
);
559 for(i
=0;i
<junction
->referral_count
;i
++) {
560 struct referral
* ref
= &(junction
->referral_list
[i
]);
563 SSVAL(pdata
,offset
,3); /* version 3 */
564 SSVAL(pdata
,offset
+2,VERSION3_REFERRAL_SIZE
);
566 SSVAL(pdata
,offset
+4,1);
568 SSVAL(pdata
,offset
+4,0);
570 SSVAL(pdata
,offset
+6,0); /* ref_flags :use path_consumed bytes? */
571 SIVAL(pdata
,offset
+8,ref
->ttl
);
573 SSVAL(pdata
,offset
+12,uni_reqpathoffset1
-offset
);
574 SSVAL(pdata
,offset
+14,uni_reqpathoffset2
-offset
);
575 /* copy referred path into current offset */
576 unilen
= (dos_struni2(pdata
+uni_curroffset
,ref
->alternate_path
,512) +1)*2;
577 SSVAL(pdata
,offset
+16,uni_curroffset
-offset
);
578 /* copy 0x10 bytes of 00's in the ServiceSite GUID */
579 memset(pdata
+offset
+18,'\0',16);
581 uni_curroffset
+= unilen
;
582 offset
+= VERSION3_REFERRAL_SIZE
;
587 /******************************************************************
588 * Set up the Dfs referral for the dfs pathname
589 ******************************************************************/
591 int setup_dfs_referral(char* pathname
, int max_referral_level
, char** ppdata
)
593 struct junction_map junction
;
595 BOOL self_referral
= False
;
598 char *pathnamep
= pathname
;
600 ZERO_STRUCT(junction
);
602 /* get the junction entry */
606 /* Trim pathname sent by client so it begins with only one backslash.
607 Two backslashes confuse some dfs clients
609 while (strlen(pathnamep
) > 1 && pathnamep
[0] == '\\'
610 && pathnamep
[1] == '\\')
613 safe_strcpy(buf
, pathnamep
, sizeof(buf
));
614 if (!get_referred_path(buf
, &junction
, &consumedcnt
,
620 pathnamep
[consumedcnt
] = '\0';
622 if( DEBUGLVL( 3 ) ) {
624 dbgtext("setup_dfs_referral: Path %s to alternate path(s):",pathnamep
);
625 for(i
=0;i
<junction
.referral_count
;i
++)
626 dbgtext(" %s",junction
.referral_list
[i
].alternate_path
);
631 /* create the referral depeding on version */
632 DEBUG(10,("max_referral_level :%d\n",max_referral_level
));
633 if(max_referral_level
<2 || max_referral_level
>3)
634 max_referral_level
= 2;
636 switch(max_referral_level
) {
639 reply_size
= setup_ver2_dfs_referral(pathnamep
, ppdata
, &junction
,
640 consumedcnt
, self_referral
);
641 SAFE_FREE(junction
.referral_list
);
646 reply_size
= setup_ver3_dfs_referral(pathnamep
, ppdata
, &junction
,
647 consumedcnt
, self_referral
);
648 SAFE_FREE(junction
.referral_list
);
653 DEBUG(0,("setup_dfs_referral: Invalid dfs referral version: %d\n", max_referral_level
));
658 DEBUG(10,("DFS Referral pdata:\n"));
659 dump_data(10,*ppdata
,reply_size
);
663 int dfs_path_error(char* inbuf
, char* outbuf
)
665 return ERROR_BOTH(NT_STATUS_PATH_NOT_COVERED
, ERRSRV
, ERRbadpath
);
668 /**********************************************************************
669 The following functions are called by the NETDFS RPC pipe functions
670 **********************************************************************/
672 /**********************************************************************
673 Creates a junction structure from a Dfs pathname
674 **********************************************************************/
675 BOOL
create_junction(char* pathname
, struct junction_map
* jn
)
679 parse_dfs_path(pathname
,&dp
);
681 /* check if path is dfs : validate first token */
682 if (local_machine
&& (strcasecmp(local_machine
,dp
.hostname
)!=0)) {
684 /* Hostname mismatch, check if one of our IP addresses */
685 if (!ismyip(*interpret_addr2(dp
.hostname
))) {
686 DEBUG(4,("create_junction: Invalid hostname %s in dfs path %s\n",
687 dp
.hostname
, pathname
));
692 /* Check for a non-DFS share */
693 if(!lp_msdfs_root(lp_servicenumber(dp
.servicename
))) {
694 DEBUG(4,("create_junction: %s is not an msdfs root.\n",
699 pstrcpy(jn
->service_name
,dp
.servicename
);
700 pstrcpy(jn
->volume_name
,dp
.reqpath
);
704 /**********************************************************************
705 Forms a valid Unix pathname from the junction
706 **********************************************************************/
707 static BOOL
junction_to_local_path(struct junction_map
* jn
, char* path
,
708 int max_pathlen
, connection_struct
*conn
)
715 snum
= lp_servicenumber(jn
->service_name
);
719 safe_strcpy(path
, lp_pathname(snum
), max_pathlen
-1);
720 safe_strcat(path
, "/", max_pathlen
-1);
721 strlower(jn
->volume_name
);
722 safe_strcat(path
, jn
->volume_name
, max_pathlen
-1);
724 if (!create_conn_struct(conn
, snum
))
730 BOOL
create_msdfs_link(struct junction_map
* jn
, BOOL exists
)
734 connection_struct conns
;
735 connection_struct
*conn
= &conns
;
737 BOOL insert_comma
= False
;
739 if(!junction_to_local_path(jn
, path
, sizeof(path
), conn
))
742 /* form the msdfs_link contents */
743 pstrcpy(msdfs_link
, "msdfs:");
744 for(i
=0; i
<jn
->referral_count
; i
++) {
745 char* refpath
= jn
->referral_list
[i
].alternate_path
;
747 trim_string(refpath
, "\\", "\\");
748 if(*refpath
== '\0') {
750 insert_comma
= False
;
753 if (i
> 0 && insert_comma
)
754 pstrcat(msdfs_link
, ",");
756 pstrcat(msdfs_link
, refpath
);
762 DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n", path
, msdfs_link
));
765 if(conn
->vfs_ops
.unlink(conn
,path
)!=0)
768 if(conn
->vfs_ops
.symlink(conn
, msdfs_link
, path
) < 0) {
769 DEBUG(1,("create_msdfs_link: symlink failed %s -> %s\nError: %s\n",
770 path
, msdfs_link
, strerror(errno
)));
776 BOOL
remove_msdfs_link(struct junction_map
* jn
)
779 connection_struct conns
;
780 connection_struct
*conn
= &conns
;
782 if(!junction_to_local_path(jn
, path
, sizeof(path
), conn
))
785 if(conn
->vfs_ops
.unlink(conn
, path
)!=0)
791 static BOOL
form_junctions(int snum
, struct junction_map
* jn
, int* jn_count
)
796 pstring connect_path
;
797 char* service_name
= lp_servicename(snum
);
798 connection_struct conns
;
799 connection_struct
*conn
= &conns
;
801 pstrcpy(connect_path
,lp_pathname(snum
));
803 if(*connect_path
== '\0')
807 * Fake up a connection struct for the VFS layer.
810 if (!create_conn_struct(conn
, snum
))
814 /* form a junction for the msdfs root - convention
815 DO NOT REMOVE THIS: NT clients will not work with us
816 if this is not present
818 struct referral
*ref
= NULL
;
820 pstrcpy(jn
[cnt
].service_name
, service_name
);
821 jn
[cnt
].volume_name
[0] = '\0';
822 jn
[cnt
].referral_count
= 1;
824 slprintf(alt_path
,sizeof(alt_path
)-1,"\\\\%s\\%s",
825 local_machine
, service_name
);
826 ref
= jn
[cnt
].referral_list
= (struct referral
*) malloc(sizeof(struct referral
));
827 if (jn
[cnt
].referral_list
== NULL
) {
828 DEBUG(0, ("Malloc failed!\n"));
832 safe_strcpy(ref
->alternate_path
, alt_path
, sizeof(pstring
));
834 ref
->ttl
= REFERRAL_TTL
;
838 dirp
= conn
->vfs_ops
.opendir(conn
, dos_to_unix_static(connect_path
));
842 while((dname
= vfs_readdirname(conn
, dirp
)) != NULL
) {
845 pstrcpy(pathreal
, connect_path
);
846 pstrcat(pathreal
, "/");
847 pstrcat(pathreal
, dname
);
849 if (is_msdfs_link(conn
, pathreal
, &(jn
[cnt
].referral_list
),
850 &(jn
[cnt
].referral_count
), NULL
)) {
851 pstrcpy(jn
[cnt
].service_name
, service_name
);
852 pstrcpy(jn
[cnt
].volume_name
, dname
);
857 conn
->vfs_ops
.closedir(conn
,dirp
);
862 int enum_msdfs_links(struct junction_map
* jn
)
870 for(i
=0;*lp_servicename(i
);i
++) {
872 form_junctions(i
,jn
,&jn_count
);
879 /* Stub functions if WITH_MSDFS not defined */
880 int setup_dfs_referral(char* pathname
, int max_referral_level
, char** ppdata
)
885 BOOL
is_msdfs_link(connection_struct
* conn
, char* path
,
886 struct referral
** reflistpp
, int* refcntp
,
887 SMB_STRUCT_STAT
*sbufp
)