6 dfs_internal dfs_struct
;
7 extern pstring global_myname
;
9 /****************************************************************************
10 read a line and split it
11 ****************************************************************************/
12 static BOOL
parse_dfs_text_entry(char *line
, dfs_internal_table
*buf
)
18 tok
[count
] = strtok(line
,":");
20 /* strip the comment lines */
21 if (tok
[0][0] == '#') return (False
);
24 while ( ((tok
[count
] = strtok(NULL
,":")) != NULL
) && count
< MAXTOK
)
29 DEBUG(7,("Found [%d] tokens\n", count
));
32 StrnCpy(buf
->localpath
, tok
[0], sizeof(buf
->localpath
)-1);
33 StrnCpy(buf
->sharename
, tok
[1], sizeof(buf
->sharename
)-1);
35 strupper(buf->localpath);
36 strupper(buf->sharename);
38 buf
->localpath_length
= strlen(buf
->localpath
);
39 buf
->sharename_length
= strlen(buf
->sharename
);
45 buf
->proximity
= atoi(tok
[2]);
50 buf
->type
= atoi(tok
[3]);
54 DEBUGADD(7,("localpath: [%s]\n", buf
->localpath
));
55 DEBUGADD(7,("sharename: [%s]\n", buf
->sharename
));
59 /****************************************************************************
60 mangle the localpath and store it.
61 ****************************************************************************/
62 static void mangle_dfs_path(dfs_internal_table
*buf
)
72 mp
= buf
->mangledpath
;
73 mlen
= sizeof(buf
->mangledpath
);
76 DEBUG(2, ("DFS name is: [%s]\n", buf
->localpath
));
78 /* copy the head: \server-name\ */
79 q
= strchr(p
+ 1, '\\');
80 safe_strcpy(mp
, p
, mlen
);
87 safe_strcpy(temp
, p
, sizeof(temp
));
89 if (!is_8_3(temp
, True
))
94 safe_strcat(mp
, temp
, mlen
);
98 safe_strcat(mp
, "\\", mlen
);
106 buf
->mangledpath_length
= strlen(mp
);
107 DEBUGADD(2, ("DFS mangled name is: [%s]\n", mp
));
110 /****************************************************************************
111 initialisation de la table dfs en memoire au demarrage de samba
112 ****************************************************************************/
113 BOOL
init_dfs_table(void)
115 char *file
= lp_dfs_map();
122 dfs_internal_table
*entry
;
125 dfs_struct
.ready
= False
;
128 DEBUG(0,("No DFS map, Samba is running in NON DFS mode\n"));
132 f
= sys_fopen(file
, "r");
134 DEBUG(0,("No DFS map file, Samba is running in NON DFS mode\n"));
138 while ( fgets(line
, sizeof(pstring
), f
) )
140 entry
= Realloc(entry
,sizeof(dfs_internal_table
)*(total
+1));
147 if ( parse_dfs_text_entry(line
, &(entry
[total
]) ) )
153 dfs_struct
.size
= total
;
154 dfs_struct
.table
= entry
;
157 /* we have the file in memory */
158 /* now initialise the mangled names */
159 for (i
= 0; i
< total
; i
++)
161 mangle_dfs_path(&(entry
[i
]));
164 dfs_struct
.ready
= True
;
165 DEBUG(0,("Samba is DFS aware now!\n"));
169 static BOOL
check_dfs_path(int search_len
, const char *search_path
,
170 int path_len
, const char* fullpath
,
171 const char* sharename
,
172 const char* share_path
, size_t share_len
,
173 char *localpath
, size_t local_plen
)
175 if (StrnCaseCmp(search_path
, fullpath
, search_len
) != 0)
180 DEBUG(2,("found one linked to [%s]. share_path: %s\n",
181 sharename
, share_path
));
183 if (StrnCaseCmp(fullpath
, share_path
, share_len
) == 0)
185 safe_strcpy(localpath
, fullpath
+ share_len
, local_plen
);
195 /****************************************************************************
196 check if a path name is a DFS branch
197 ****************************************************************************/
198 int under_dfs(connection_struct
*conn
, const char *path
,
199 char *local_path
, size_t local_plen
)
209 dfs_internal_table
*list
= dfs_struct
.table
;
212 snprintf(share_path
, sizeof(share_path
), "\\%s\\%s",
213 global_myname
, lp_servicename(snum
));
214 share_len
= strlen(share_path
);
218 snprintf(fullpath
, sizeof(fullpath
), "%s\\%s",
223 safe_strcpy(fullpath
, path
, sizeof(fullpath
));
226 path_len
= strlen(fullpath
);
228 DEBUG(2,("DFS looking for: [%s]\n", fullpath
));
230 for (i
= 0; i
< dfs_struct
.size
; i
++)
232 DEBUG(6,("checking against [%s][%d]\n", list
[i
].localpath
,i
));
234 if (check_dfs_path(list
[i
].localpath_length
,
238 share_path
, share_len
,
239 local_path
, local_plen
))
244 if (check_dfs_path(list
[i
].mangledpath_length
,
248 share_path
, share_len
,
249 local_path
, local_plen
))