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;
28 static uint32 dfs_referral_tries = 0;
31 /**********************************************************************
32 Parse the pathname of the form \hostname\service\reqpath
33 into the dfs_path structure
34 **********************************************************************/
36 static BOOL parse_dfs_path(const char *pathname, struct dfs_path* pdp)
38 pstring pathname_local;
41 pstrcpy(pathname_local,pathname);
42 p = temp = pathname_local;
46 trim_string(temp,"\\","\\");
47 DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \\'s\n",temp));
50 /* parse out hostname */
51 p = strchr(temp,'\\');
55 pstrcpy(pdp->hostname,temp);
56 DEBUG(10,("hostname: %s\n",pdp->hostname));
58 /* parse out servicename */
60 p = strchr(temp,'\\');
62 pstrcpy(pdp->servicename,temp);
63 pdp->reqpath[0] = '\0';
67 pstrcpy(pdp->servicename,temp);
68 DEBUG(10,("servicename: %s\n",pdp->servicename));
71 pstrcpy(pdp->reqpath, p+1);
74 if (*p == '\\') *p = '/';
78 DEBUG(10,("rest of the path: %s\n",pdp->reqpath));
82 /********************************************************
83 Fake up a connection struct for the VFS layer.
84 *********************************************************/
86 static BOOL create_conn_struct( struct tcon_context *conn, int snum, char *path)
90 conn->connectpath = path;
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],'/');
142 // used for testing splitting files between servers
144 (dfs_referral_tries & 0xfffffffe) // this will reverse the order of the list
146 dfs_referral_tries++;
151 pstrcpy(reflist[j].alternate_path, "\\");
152 pstrcat(reflist[j].alternate_path, alt_path[i]);
153 reflist[j].proximity = 0;
154 reflist[j].ttl = REFERRAL_TTL;
155 DEBUG(10, ("parse_symlink: Created alt path: %s\n", reflist[j].alternate_path));
164 /**********************************************************************
165 Returns true if the unix path is a valid msdfs symlink
166 **********************************************************************/
167 BOOL is_msdfs_link(struct tcon_context *conn, char* path,
168 struct referral** reflistp, int* refcnt,
169 SMB_STRUCT_STAT *sbufp)
173 int referral_len = 0;
183 if (conn->vfs_ops.lstat(conn, path, sbufp) != 0) {
184 DEBUG(5,("is_msdfs_link: %s does not exist.\n",path));
188 if (S_ISLNK(sbufp->st_mode)) {
189 /* open the link and read it */
190 referral_len = conn->vfs_ops.readlink(conn, path, referral,
192 if (referral_len == -1) {
193 DEBUG(0,("is_msdfs_link: Error reading msdfs link %s: %s\n", path, strerror(errno)));
197 referral[referral_len] = '\0';
198 DEBUG(5,("is_msdfs_link: %s -> %s\n",path,referral));
199 if (parse_symlink(referral, reflistp, refcnt))
205 /*****************************************************************
206 Used by other functions to decide if a dfs path is remote,
207 and to get the list of referred locations for that remote path.
209 findfirst_flag: For findfirsts, dfs links themselves are not
210 redirected, but paths beyond the links are. For normal smb calls,
211 even dfs links need to be redirected.
213 self_referralp: clients expect a dfs referral for the same share when
214 they request referrals for dfs roots on a server.
216 consumedcntp: how much of the dfs path is being redirected. the client
217 should try the remaining path on the redirected server.
218 *****************************************************************/
219 static BOOL resolve_dfs_path(char* dfspath, struct dfs_path* dp,
220 struct tcon_context *conn,
222 struct referral** reflistpp, int* refcntp,
223 BOOL* self_referralp, int* consumedcntp)
231 DEBUG(1,("resolve_dfs_path: NULL dfs_path* or NULL tcon_context!\n"));
235 if (dp->reqpath[0] == '\0') {
236 if (self_referralp) {
237 DEBUG(6,("resolve_dfs_path: self-referral. returning False\n"));
238 *self_referralp = True;
243 /* check if need to redirect */
244 fstrcpy(localpath, conn->connectpath);
245 fstrcat(localpath, "/");
246 fstrcat(localpath, dp->reqpath);
247 if (is_msdfs_link(conn, localpath, reflistpp, refcntp, NULL))
249 if (findfirst_flag) {
250 DEBUG(6,("resolve_dfs_path (FindFirst) No redirection "
251 "for dfs link %s.\n", dfspath));
254 DEBUG(6,("resolve_dfs_path: %s resolves to a valid Dfs link.\n",
257 *consumedcntp = strlen(dfspath);
262 /* also redirect if the parent directory is a dfs link */
263 fstrcpy(reqpath, dp->reqpath);
264 p = strrchr(reqpath, '/');
267 fstrcpy(localpath, conn->connectpath);
268 fstrcat(localpath, "/");
269 fstrcat(localpath, reqpath);
270 if (is_msdfs_link(conn, localpath, reflistpp, refcntp, NULL)) {
271 DEBUG(4, ("resolve_dfs_path: Redirecting %s because parent %s is dfs link\n", dfspath, localpath));
273 /* To find the path consumed, we truncate the original
274 DFS pathname passed to use to remove the last
275 component. The length of the resulting string is
281 pstrcpy(buf, dfspath);
282 trim_string(buf, NULL, "\\");
283 q = strrchr(buf, '\\');
286 *consumedcntp = strlen(buf);
287 DEBUG(10, ("resolve_dfs_path: Path consumed: %d\n", *consumedcntp));
297 /*****************************************************************
298 Decides if a dfs pathname should be redirected or not.
299 If not, the pathname is converted to a tcon-relative local unix path
300 *****************************************************************/
301 BOOL dfs_redirect(const char *pathname, struct tcon_context *conn,
306 if (!conn || !pathname)
309 parse_dfs_path(pathname, &dp);
311 /* if dfs pathname for a non-dfs share, convert to tcon-relative
312 path and return false */
313 if (!lp_msdfs_root(SNUM(conn))) {
314 fstrcpy(pathname, dp.reqpath);
318 if (strcasecmp(dp.servicename, lp_servicename(SNUM(conn)) ) != 0)
321 if (resolve_dfs_path(pathname, &dp, conn, findfirst_flag,
322 NULL, NULL, NULL, NULL)) {
323 DEBUG(3,("dfs_redirect: Redirecting %s\n", pathname));
326 DEBUG(3,("dfs_redirect: Not redirecting %s.\n", pathname));
328 /* Form non-dfs tcon-relative path */
329 fstrcpy(pathname, dp.reqpath);
330 DEBUG(3,("dfs_redirect: Path converted to non-dfs path %s\n",
338 /**********************************************************************
339 Gets valid referrals for a dfs path and fills up the
340 junction_map structure
341 **********************************************************************/
342 BOOL get_referred_path(char *pathname, struct junction_map* jn,
343 int* consumedcntp, BOOL* self_referralp)
347 struct tcon_context conns;
348 struct tcon_context *conn = &conns;
352 BOOL self_referral = False;
354 if (!pathname || !jn)
358 *self_referralp = False;
360 self_referralp = &self_referral;
362 parse_dfs_path(pathname, &dp);
364 /* Verify hostname in path */
365 if (local_machine && (strcasecmp(local_machine, dp.hostname) != 0)) {
367 /* Hostname mismatch, check if one of our IP addresses */
368 if (!ismyip(*interpret_addr2(dp.hostname))) {
370 DEBUG(3, ("get_referred_path: Invalid hostname %s in path %s\n",
371 dp.hostname, pathname));
376 pstrcpy(jn->service_name, dp.servicename);
377 pstrcpy(jn->volume_name, dp.reqpath);
379 /* Verify the share is a dfs root */
380 snum = lp_servicenumber(jn->service_name);
382 if ((snum = find_service(jn->service_name)) < 0)
386 pstrcpy(conn_path, lp_pathname(snum));
387 if (!create_conn_struct(conn, snum, conn_path))
390 if (!lp_msdfs_root(SNUM(conn))) {
391 DEBUG(3,("get_referred_path: .%s. in dfs path %s is not a dfs root.\n",
392 dp.servicename, pathname));
396 if (*lp_msdfs_proxy(snum) != '\0') {
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, lp_msdfs_proxy(snum));
406 if (dp.reqpath[0] != '\0')
407 pstrcat(ref->alternate_path, dp.reqpath);
409 ref->ttl = REFERRAL_TTL;
410 jn->referral_list = ref;
412 *consumedcntp = strlen(pathname);
416 /* If not remote & not a self referral, return False */
417 if (!resolve_dfs_path(pathname, &dp, conn, False,
418 &jn->referral_list, &jn->referral_count,
419 self_referralp, consumedcntp)) {
420 if (!*self_referralp) {
421 DEBUG(3,("get_referred_path: No valid referrals for path %s\n", pathname));
426 /* if self_referral, fill up the junction map */
427 if (*self_referralp) {
428 struct referral* ref;
429 jn->referral_count = 1;
430 if((ref = (struct referral*) malloc(sizeof(struct referral)))
432 DEBUG(0,("malloc failed for referral\n"));
436 pstrcpy(ref->alternate_path,pathname);
438 ref->ttl = REFERRAL_TTL;
439 jn->referral_list = ref;
441 *consumedcntp = strlen(pathname);
447 static int setup_ver2_dfs_referral(char* pathname, char** ppdata,
448 struct junction_map* junction,
452 char* pdata = *ppdata;
454 unsigned char uni_requestedpath[1024];
455 int uni_reqpathoffset1,uni_reqpathoffset2;
457 int requestedpathlen=0;
462 DEBUG(10,("setting up version2 referral\nRequested path:\n"));
464 requestedpathlen = rpcstr_push(uni_requestedpath, pathname, -1,
467 dump_data(10, (const char *) uni_requestedpath,requestedpathlen);
469 DEBUG(10,("ref count = %u\n",junction->referral_count));
471 uni_reqpathoffset1 = REFERRAL_HEADER_SIZE +
472 VERSION2_REFERRAL_SIZE * junction->referral_count;
474 uni_reqpathoffset2 = uni_reqpathoffset1 + requestedpathlen;
476 uni_curroffset = uni_reqpathoffset2 + requestedpathlen;
478 reply_size = REFERRAL_HEADER_SIZE + VERSION2_REFERRAL_SIZE*junction->referral_count +
479 2 * requestedpathlen;
480 DEBUG(10,("reply_size: %u\n",reply_size));
482 /* add up the unicode lengths of all the referral paths */
483 for(i=0;i<junction->referral_count;i++) {
484 DEBUG(10,("referral %u : %s\n",i,junction->referral_list[i].alternate_path));
485 reply_size += (strlen(junction->referral_list[i].alternate_path)+1)*2;
488 DEBUG(10,("reply_size = %u\n",reply_size));
489 /* add the unexplained 0x16 bytes */
492 pdata = Realloc(pdata,reply_size);
494 DEBUG(0,("malloc failed for Realloc!\n"));
499 /* copy in the dfs requested paths.. required for offset calculations */
500 memcpy(pdata+uni_reqpathoffset1,uni_requestedpath,requestedpathlen);
501 memcpy(pdata+uni_reqpathoffset2,uni_requestedpath,requestedpathlen);
503 /* create the header */
504 SSVAL(pdata,0,consumedcnt * 2); /* path consumed */
505 SSVAL(pdata,2,junction->referral_count); /* number of referral in this pkt */
507 SIVAL(pdata,4,DFSREF_REFERRAL_SERVER | DFSREF_STORAGE_SERVER);
509 SIVAL(pdata,4,DFSREF_STORAGE_SERVER);
512 /* add the referral elements */
513 for(i=0;i<junction->referral_count;i++) {
514 struct referral* ref = &(junction->referral_list[i]);
517 SSVAL(pdata,offset,2); /* version 2 */
518 SSVAL(pdata,offset+2,VERSION2_REFERRAL_SIZE);
520 SSVAL(pdata,offset+4,1);
522 SSVAL(pdata,offset+4,0);
523 SSVAL(pdata,offset+6,0); /* ref_flags :use path_consumed bytes? */
524 SIVAL(pdata,offset+8,ref->proximity);
525 SIVAL(pdata,offset+12,ref->ttl);
527 SSVAL(pdata,offset+16,uni_reqpathoffset1-offset);
528 SSVAL(pdata,offset+18,uni_reqpathoffset2-offset);
529 /* copy referred path into current offset */
530 unilen = rpcstr_push(pdata+uni_curroffset, ref->alternate_path,
533 SSVAL(pdata,offset+20,uni_curroffset-offset);
535 uni_curroffset += unilen;
536 offset += VERSION2_REFERRAL_SIZE;
538 /* add in the unexplained 22 (0x16) bytes at the end */
539 memset(pdata+uni_curroffset,'\0',0x16);
543 static int setup_ver3_dfs_referral(char* pathname, char** ppdata,
544 struct junction_map* junction,
548 char* pdata = *ppdata;
550 unsigned char uni_reqpath[1024];
551 int uni_reqpathoffset1, uni_reqpathoffset2;
558 DEBUG(10,("setting up version3 referral\n"));
560 reqpathlen = rpcstr_push(uni_reqpath, pathname, -1, STR_TERMINATE);
562 dump_data(10, (char *) uni_reqpath,reqpathlen);
564 uni_reqpathoffset1 = REFERRAL_HEADER_SIZE + VERSION3_REFERRAL_SIZE * junction->referral_count;
565 uni_reqpathoffset2 = uni_reqpathoffset1 + reqpathlen;
566 reply_size = uni_curroffset = uni_reqpathoffset2 + reqpathlen;
568 for(i=0;i<junction->referral_count;i++) {
569 DEBUG(10,("referral %u : %s\n",i,junction->referral_list[i].alternate_path));
570 reply_size += (strlen(junction->referral_list[i].alternate_path)+1)*2;
573 pdata = Realloc(pdata,reply_size);
575 DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n"));
580 /* create the header */
581 SSVAL(pdata,0,consumedcnt * 2); /* path consumed */
582 SSVAL(pdata,2,junction->referral_count); /* number of referral */
584 SIVAL(pdata,4,DFSREF_REFERRAL_SERVER | DFSREF_STORAGE_SERVER);
586 SIVAL(pdata,4,DFSREF_STORAGE_SERVER);
588 /* copy in the reqpaths */
589 memcpy(pdata+uni_reqpathoffset1,uni_reqpath,reqpathlen);
590 memcpy(pdata+uni_reqpathoffset2,uni_reqpath,reqpathlen);
593 for(i=0;i<junction->referral_count;i++) {
594 struct referral* ref = &(junction->referral_list[i]);
597 SSVAL(pdata,offset,3); /* version 3 */
598 SSVAL(pdata,offset+2,VERSION3_REFERRAL_SIZE);
600 SSVAL(pdata,offset+4,1);
602 SSVAL(pdata,offset+4,0);
604 SSVAL(pdata,offset+6,0); /* ref_flags :use path_consumed bytes? */
605 SIVAL(pdata,offset+8,ref->ttl);
607 SSVAL(pdata,offset+12,uni_reqpathoffset1-offset);
608 SSVAL(pdata,offset+14,uni_reqpathoffset2-offset);
609 /* copy referred path into current offset */
610 unilen = rpcstr_push(pdata+uni_curroffset,ref->alternate_path,
611 -1, STR_UNICODE | STR_TERMINATE);
612 SSVAL(pdata,offset+16,uni_curroffset-offset);
613 /* copy 0x10 bytes of 00's in the ServiceSite GUID */
614 memset(pdata+offset+18,'\0',16);
616 uni_curroffset += unilen;
617 offset += VERSION3_REFERRAL_SIZE;
622 /******************************************************************
623 * Set up the Dfs referral for the dfs pathname
624 ******************************************************************/
626 int setup_dfs_referral(char* pathname, int max_referral_level, char** ppdata)
628 struct junction_map junction;
630 BOOL self_referral = False;
633 char *pathnamep = pathname;
635 ZERO_STRUCT(junction);
637 /* get the junction entry */
641 /* Trim pathname sent by client so it begins with only one backslash.
642 Two backslashes confuse some dfs clients
644 while (strlen(pathnamep) > 1 && pathnamep[0] == '\\'
645 && pathnamep[1] == '\\')
648 pstrcpy(buf, pathnamep);
649 if (!get_referred_path(buf, &junction, &consumedcnt,
655 pathnamep[consumedcnt] = '\0';
657 if( DEBUGLVL( 3 ) ) {
659 dbgtext("setup_dfs_referral: Path %s to alternate path(s):",pathnamep);
660 for(i=0;i<junction.referral_count;i++)
661 dbgtext(" %s",junction.referral_list[i].alternate_path);
666 /* create the referral depeding on version */
667 DEBUG(10,("max_referral_level :%d\n",max_referral_level));
668 if(max_referral_level<2 || max_referral_level>3)
669 max_referral_level = 2;
671 switch(max_referral_level) {
674 reply_size = setup_ver2_dfs_referral(pathnamep, ppdata, &junction,
675 consumedcnt, self_referral);
676 SAFE_FREE(junction.referral_list);
681 reply_size = setup_ver3_dfs_referral(pathnamep, ppdata, &junction,
682 consumedcnt, self_referral);
683 SAFE_FREE(junction.referral_list);
688 DEBUG(0,("setup_dfs_referral: Invalid dfs referral version: %d\n", max_referral_level));
693 DEBUG(10,("DFS Referral pdata:\n"));
694 dump_data(10,*ppdata,reply_size);
698 /**********************************************************************
699 The following functions are called by the NETDFS RPC pipe functions
700 **********************************************************************/
702 /**********************************************************************
703 Creates a junction structure from a Dfs pathname
704 **********************************************************************/
705 BOOL create_junction(char* pathname, struct junction_map* jn)
709 parse_dfs_path(pathname,&dp);
711 /* check if path is dfs : validate first token */
712 if (local_machine && (strcasecmp(local_machine,dp.hostname)!=0)) {
714 /* Hostname mismatch, check if one of our IP addresses */
715 if (!ismyip(*interpret_addr2(dp.hostname))) {
716 DEBUG(4,("create_junction: Invalid hostname %s in dfs path %s\n",
717 dp.hostname, pathname));
722 /* Check for a non-DFS share */
723 if(!lp_msdfs_root(lp_servicenumber(dp.servicename))) {
724 DEBUG(4,("create_junction: %s is not an msdfs root.\n",
729 pstrcpy(jn->service_name,dp.servicename);
730 pstrcpy(jn->volume_name,dp.reqpath);
734 /**********************************************************************
735 Forms a valid Unix pathname from the junction
736 **********************************************************************/
738 static BOOL junction_to_local_path(struct junction_map* jn, char* path,
739 int max_pathlen, struct tcon_context *conn)
747 snum = lp_servicenumber(jn->service_name);
751 safe_strcpy(path, lp_pathname(snum), max_pathlen-1);
752 safe_strcat(path, "/", max_pathlen-1);
753 strlower(jn->volume_name);
754 safe_strcat(path, jn->volume_name, max_pathlen-1);
756 pstrcpy(conn_path, lp_pathname(snum));
757 if (!create_conn_struct(conn, snum, conn_path))
763 BOOL create_msdfs_link(struct junction_map* jn, BOOL exists)
767 struct tcon_context conns;
768 struct tcon_context *conn = &conns;
770 BOOL insert_comma = False;
772 if(!junction_to_local_path(jn, path, sizeof(path), conn))
775 /* form the msdfs_link contents */
776 pstrcpy(msdfs_link, "msdfs:");
777 for(i=0; i<jn->referral_count; i++) {
778 char* refpath = jn->referral_list[i].alternate_path;
780 trim_string(refpath, "\\", "\\");
781 if(*refpath == '\0') {
783 insert_comma = False;
786 if (i > 0 && insert_comma)
787 pstrcat(msdfs_link, ",");
789 pstrcat(msdfs_link, refpath);
795 DEBUG(5,("create_msdfs_link: Creating new msdfs link: %s -> %s\n", path, msdfs_link));
798 if(conn->vfs_ops.unlink(conn,path)!=0)
801 if(conn->vfs_ops.symlink(conn, msdfs_link, path) < 0) {
802 DEBUG(1,("create_msdfs_link: symlink failed %s -> %s\nError: %s\n",
803 path, msdfs_link, strerror(errno)));
809 BOOL remove_msdfs_link(struct junction_map* jn)
812 struct tcon_context conns;
813 struct tcon_context *conn = &conns;
815 if(!junction_to_local_path(jn, path, sizeof(path), conn))
818 if(conn->vfs_ops.unlink(conn, path)!=0)
824 static BOOL form_junctions(int snum, struct junction_map* jn, int* jn_count)
829 pstring connect_path;
830 char* service_name = lp_servicename(snum);
831 struct tcon_context conns;
832 struct tcon_context *conn = &conns;
833 struct referral *ref = NULL;
835 pstrcpy(connect_path,lp_pathname(snum));
837 if(*connect_path == '\0')
841 * Fake up a connection struct for the VFS layer.
844 if (!create_conn_struct(conn, snum, connect_path))
847 /* form a junction for the msdfs root - convention
848 DO NOT REMOVE THIS: NT clients will not work with us
849 if this is not present
851 pstrcpy(jn[cnt].service_name, service_name);
852 jn[cnt].volume_name[0] = '\0';
853 jn[cnt].referral_count = 1;
855 ref = jn[cnt].referral_list
856 = (struct referral*) malloc(sizeof(struct referral));
857 if (jn[cnt].referral_list == NULL) {
858 DEBUG(0, ("Malloc failed!\n"));
863 ref->ttl = REFERRAL_TTL;
864 if (*lp_msdfs_proxy(snum) != '\0') {
865 pstrcpy(ref->alternate_path, lp_msdfs_proxy(snum));
870 slprintf(ref->alternate_path, sizeof(pstring)-1,
871 "\\\\%s\\%s", local_machine, service_name);
874 /* Now enumerate all dfs links */
875 dirp = conn->vfs_ops.opendir(conn, connect_path);
879 while((dname = vfs_readdirname(conn, dirp)) != NULL) {
882 pstrcpy(pathreal, connect_path);
883 pstrcat(pathreal, "/");
884 pstrcat(pathreal, dname);
886 if (is_msdfs_link(conn, pathreal, &(jn[cnt].referral_list),
887 &(jn[cnt].referral_count), NULL)) {
888 pstrcpy(jn[cnt].service_name, service_name);
889 pstrcpy(jn[cnt].volume_name, dname);
894 conn->vfs_ops.closedir(conn,dirp);
899 int enum_msdfs_links(struct junction_map* jn)
907 for(i=0;*lp_servicename(i);i++) {
909 form_junctions(i,jn,&jn_count);