diff options
author | Shirish Kalele <kalele@samba.org> | 2000-03-08 22:14:30 +0000 |
---|---|---|
committer | Shirish Kalele <kalele@samba.org> | 2000-03-08 22:14:30 +0000 |
commit | 952799d9afe028d822181831715b85521c89a7ef (patch) | |
tree | cb4884e78037baa26ae2a0985b337a8dc0944558 /source3/msdfs | |
parent | 3958c3910658e99fe1cfd737e0cfc126dffc75da (diff) | |
download | samba-952799d9afe028d822181831715b85521c89a7ef.tar.gz samba-952799d9afe028d822181831715b85521c89a7ef.tar.bz2 samba-952799d9afe028d822181831715b85521c89a7ef.zip |
dded Microsoft Dfs services.
* added a new msdfs/ directory under source/
* added msdfs sources under this directory.
* modified configure setup to add a --with-msdfs configure time option
Modified Files:
Makefile.in acconfig.h configure configure.in
include/config.h.in include/includes.h include/proto.h
include/smb.h include/smb_macros.h param/loadparm.c
smbd/negprot.c smbd/nttrans.c smbd/process.c smbd/reply.c
smbd/server.c smbd/trans2.c
Added Files:
include/msdfs.h msdfs/README msdfs/msdfs.c msdfs/msdfs_tdb.c
msdfs/parse_dfs_map.c
----------------------------------------------------------------------
(This used to be commit 4684b4a188b54493dbe7f0de2909a8d3c5c3ebf9)
Diffstat (limited to 'source3/msdfs')
-rw-r--r-- | source3/msdfs/README | 27 | ||||
-rw-r--r-- | source3/msdfs/msdfs.c | 466 | ||||
-rw-r--r-- | source3/msdfs/msdfs_tdb.c | 264 | ||||
-rw-r--r-- | source3/msdfs/parse_dfs_map.c | 261 |
4 files changed, 1018 insertions, 0 deletions
diff --git a/source3/msdfs/README b/source3/msdfs/README new file mode 100644 index 0000000000..62fded3f55 --- /dev/null +++ b/source3/msdfs/README @@ -0,0 +1,27 @@ +Setting up MS Dfs in Samba +kalele@veritas.com March 2000 + +Currently, MS Dfs support is a configure time parameter (--with-msdfs). Can be changed later to always compile it in.. + +To have a server announce itself as a Dfs server, add a "host msdfs=yes" entry to smb.conf. + +To make a share a Dfs root, add a "dfs map" entry to the share definition in the smb.conf file. +e.g. +[pub] + dfs map = /usr/local/samba/lib/pub_dfs_map + +The pub_dfs_map file would contain a list of junction points and their referral paths. + +In our example, if you have a directory pub_dir1/ in the pub share and want to make it a dfs junction point to \\machineX\pub, you can have an entry in the pub_dfs_map file as: + +pub_dir1 +\\machineX\pub:0:600 + +where: 0 is the proximity of the server. If you have multiple referred servers for one junction point, you can set up preferences among these using this field. +& 600 is the number of seconds the client must cache the referral. After this time period, the smb client supposedly should contact the server again for a fresh referral. + +NOTE: You can have multiple referral paths for one junction point. Currently, the parser code depends on the leading \ to determine if the line is a referral or a new junction point. + +Shares with no "dfs map" entries are served as normal shares and the client stops talking Dfs with Samba after a tconX. + +TODO: Dynamically showing junction points to dfs clients alone,probably in the findfirst reply. Currently, you need to have directories on the samba server as token junction points. diff --git a/source3/msdfs/msdfs.c b/source3/msdfs/msdfs.c new file mode 100644 index 0000000000..ce1a94ee00 --- /dev/null +++ b/source3/msdfs/msdfs.c @@ -0,0 +1,466 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + MSDfs services for Samba + Copyright (C) Shirish Kalele 2000 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; +extern pstring global_myname; +extern global_client_caps; + +#ifdef MS_DFS + +#define VERSION2_REFERRAL_SIZE 0x16 +#define VERSION3_REFERRAL_SIZE 0x22 +#define REFERRAL_HEADER_SIZE 0x08 + +struct dfs_path +{ + pstring hostname; + pstring servicename; + pstring volumename; + pstring restofthepath; +}; + +void create_nondfs_path(char* pathname, struct dfs_path* pdp) +{ + pstrcpy(pathname,pdp->volumename); + pstrcat(pathname,"\\"); + pstrcat(pathname,pdp->restofthepath); +} + +/* Parse the pathname of the form \hostname\service\volume\restofthepath + into the dfs_path structure */ +BOOL parse_dfs_path(char* pathname, struct dfs_path* pdp) +{ + pstring pathname_local; + char* p,*temp; + + pstrcpy(pathname_local,pathname); + p = temp = pathname_local; + + ZERO_STRUCTP(pdp); + + /* strip off all \'s from the beginning */ + /* while(*temp=='\\') temp++; + + DEBUG(10,("temp in parse_dfs_path : .%s.\n",temp)); + + remove any trailing \'s + if(temp[strlen(temp)-1] == '\\') temp[strlen(temp)-1]='\0'; +*/ + + trim_string(temp,"\\","\\"); + DEBUG(10,("temp in parse_dfs_path: .%s. after trimming \'s\n",temp)); + + /* now tokenize */ + /* parse out hostname */ + p = strchr(temp,'\\'); + if(p == NULL) + return False; + *p = '\0'; + pstrcpy(pdp->hostname,temp); + DEBUG(10,("hostname: %s\n",pdp->hostname)); + + /* parse out servicename */ + temp = p+1; + p = strchr(temp,'\\'); + if(p == NULL) + { + pstrcpy(pdp->servicename,temp); + return True; + } + *p = '\0'; + pstrcpy(pdp->servicename,temp); + DEBUG(10,("servicename: %s\n",pdp->servicename)); + + /* parse out volumename */ + temp = p+1; + p = strchr(temp,'\\'); + if(p == NULL) + { + pstrcpy(pdp->volumename,temp); + return True; + } + *p = '\0'; + pstrcpy(pdp->volumename,temp); + DEBUG(10,("volumename: %s\n",pdp->volumename)); + + /* remaining path .. */ + pstrcpy(pdp->restofthepath,p+1); + DEBUG(10,("rest of the path: %s\n",pdp->restofthepath)); + return True; +} + + +/************************************************************** +Decides if given pathname is Dfs and if it should be redirected +Converts pathname to non-dfs format if Dfs redirection not required +**************************************************************/ +BOOL dfs_redirect(char* pathname, connection_struct* conn) +{ + struct dfs_path dp; + pstring temp; + + pstrcpy(temp,pathname); + + if(lp_dfsmap(SNUM(conn))==NULL || *lp_dfsmap(SNUM(conn))=='\0') + return False; + + parse_dfs_path(pathname,&dp); + + if(global_myname && (strcasecmp(global_myname,dp.hostname)!=0)) + return False; + + /* check if need to redirect */ + if(isDfsShare(dp.servicename,dp.volumename)) + { + DEBUG(4,("dfs_redirect: Redirecting %s\n",temp)); + return True; + } + else + { + create_nondfs_path(pathname,&dp); + DEBUG(4,("dfs_redirect: Not redirecting %s. Converted to non-dfs pathname \'%s\'\n", + temp,pathname)); + return False; + } +} + +/* + Special DFS redirect call for findfirst's. + If the findfirst is for the dfs junction, then no redirection, + if it is for the underlying directory contents, redirect. + */ +BOOL dfs_findfirst_redirect(char* pathname, connection_struct* conn) +{ + struct dfs_path dp; + + pstring temp; + + pstrcpy(temp,pathname); + + /* Is the path Dfs-redirectable? */ + if(!dfs_redirect(temp,conn)) + { + pstrcpy(pathname,temp); + return False; + } + + parse_dfs_path(pathname,&dp); + DEBUG(8,("dfs_findfirst_redirect: path %s is in Dfs. dp.restofthepath=.%s.\n",pathname,dp.restofthepath)); + if(*(dp.restofthepath)) + return True; + else + { + create_nondfs_path(pathname,&dp); + return False; + } +} + +/****************************************************************** + * Set up the Dfs referral for the dfs pathname + ******************************************************************/ +int setup_dfs_referral(char* pathname, int max_referral_level, + char** ppdata) +{ + struct dfs_path dp; + + struct junction_map junction; + + BOOL self_referral; + + char* pdata = *ppdata; + int reply_size = 0; + + ZERO_STRUCT(junction); + + parse_dfs_path(pathname,&dp); + + /* check if path is dfs : check hostname is the first token */ + if(global_myname && (strcasecmp(global_myname,dp.hostname)!=0)) + { + DEBUG(4,("Invalid DFS referral request for %s\n",pathname)); + return -1; + } + + /* Check for a non-DFS share */ + { + char* map = lp_dfsmap(lp_servicenumber(dp.servicename)); + DEBUG(10,("lp_dfsmap in setup dfs referral: .%s.\n",map )); + + if(map == NULL | *map == '\0') + return -1; + } + + pstrcpy(junction.service_name,dp.servicename); + pstrcpy(junction.volume_name,dp.volumename); + + /* get the junction entry */ + if(!get_junction_entry(&junction)) + { + + /* refer the same pathname, create a standard referral struct */ + struct referral* ref; + self_referral = True; + junction.referral_count = 1; + if((ref = (struct referral*) malloc(sizeof(struct referral))) == NULL) + { + DEBUG(0,("malloc failed for referral\n")); + return -1; + } + + pstrcpy(ref->alternate_path,pathname); + ref->proximity = 0; + ref->ttl = REFERRAL_TTL; + junction.referral_list = ref; + } + else + { + self_referral = False; + if( DEBUGLVL( 3 ) ) + { + int i=0; + dbgtext("setup_dfs_referral: Referring client request for %s to alternate path(s):",pathname); + for(i=0;i<junction.referral_count;i++) + dbgtext(" %s",junction.referral_list[i].alternate_path); + dbgtext(".\n"); + } + } + + /* create the referral depeding on version */ + DEBUG(10,("MAX_REFERRAL_LEVEL :%d\n",max_referral_level)); + if(max_referral_level<2 || max_referral_level>3) max_referral_level = 2; + + switch(max_referral_level) + { + case 2: + { + unsigned char uni_requestedpath[1024]; + unsigned char uni_altpath[1024]; + int uni_reqpathoffset1,uni_reqpathoffset2; + int uni_curroffset; + int requestedpathlen=0; + int offset; + int i=0; + + DEBUG(10,("setting up version2 referral\nRequested path:\n")); + + requestedpathlen = (dos_struni2(uni_requestedpath,pathname,512)+1)*2; + + dump_data(10,uni_requestedpath,requestedpathlen); + + DEBUG(10,("ref count = %u\n",junction.referral_count)); + + uni_reqpathoffset1 = REFERRAL_HEADER_SIZE + + VERSION2_REFERRAL_SIZE * junction.referral_count; + + uni_reqpathoffset2 = uni_reqpathoffset1 + requestedpathlen; + + uni_curroffset = uni_reqpathoffset2 + requestedpathlen; + + reply_size = REFERRAL_HEADER_SIZE + VERSION2_REFERRAL_SIZE*junction.referral_count + + 2 * requestedpathlen; + DEBUG(10,("reply_size: %u\n",reply_size)); + + /* add up the unicode lengths of all the referral paths */ + for(i=0;i<junction.referral_count;i++) + { + DEBUG(10,("referral %u : %s\n",i,junction.referral_list[i].alternate_path)); + reply_size += (strlen(junction.referral_list[i].alternate_path)+1)*2; + } + + DEBUG(10,("reply_size = %u\n",reply_size)); + /* add the unexplained 0x16 bytes */ + reply_size += 0x16; + + pdata = *ppdata = Realloc(pdata,reply_size); + if(pdata == NULL) + { + DEBUG(0,("malloc failed for Realloc!\n")); + return -1; + } + + /* copy in the dfs requested paths.. required for offset calculations */ + memcpy(pdata+uni_reqpathoffset1,uni_requestedpath,requestedpathlen); + memcpy(pdata+uni_reqpathoffset2,uni_requestedpath,requestedpathlen); + + + /* create the header */ + SSVAL(pdata,0,requestedpathlen-2); /* path consumed */ + SSVAL(pdata,2,junction.referral_count); /* number of referral in this pkt */ + if(self_referral) + SIVAL(pdata,4,DFSREF_REFERRAL_SERVER | DFSREF_STORAGE_SERVER); + else + SIVAL(pdata,4,DFSREF_STORAGE_SERVER); + + offset = 8; + /* add the referral elements */ + for(i=0;i<junction.referral_count;i++) + { + struct referral* ref = &(junction.referral_list[i]); + int unilen; + + SSVAL(pdata,offset,2); /* version 2 */ + SSVAL(pdata,offset+2,VERSION2_REFERRAL_SIZE); + if(self_referral) + SSVAL(pdata,offset+4,1); + else + SSVAL(pdata,offset+4,0); + SSVAL(pdata,offset+6,0); /* ref_flags :use path_consumed bytes? */ + SIVAL(pdata,offset+8,ref->proximity); + SIVAL(pdata,offset+12,ref->ttl); + + SSVAL(pdata,offset+16,uni_reqpathoffset1-offset); + SSVAL(pdata,offset+18,uni_reqpathoffset2-offset); + /* copy referred path into current offset */ + unilen = (dos_struni2(pdata+uni_curroffset,ref->alternate_path,512) + +1)*2; + SSVAL(pdata,offset+20,uni_curroffset-offset); + + uni_curroffset += unilen; + offset += VERSION2_REFERRAL_SIZE; + } + /* add in the unexplained 22 (0x16) bytes at the end */ + memset(pdata+uni_curroffset,'\0',0x16); + free(junction.referral_list); + break; + } + + case 3: + { + unsigned char uni_reqpath[1024]; + unsigned char uni_altpath[1024]; + int uni_reqpathoffset1, uni_reqpathoffset2; + int uni_curroffset; + + int reqpathlen = 0; + int offset,i=0; + + DEBUG(10,("setting up version3 referral\n")); + + reqpathlen = (dos_struni2(uni_reqpath,pathname,512)+1)*2; + + dump_data(10,uni_reqpath,reqpathlen); + + uni_reqpathoffset1 = REFERRAL_HEADER_SIZE + VERSION3_REFERRAL_SIZE * + junction.referral_count; + uni_reqpathoffset2 = uni_reqpathoffset1 + reqpathlen; + reply_size = uni_curroffset = uni_reqpathoffset2 + reqpathlen; + + for(i=0;i<junction.referral_count;i++) + { + DEBUG(10,("referral %u : %s\n",i,junction.referral_list[i].alternate_path)); + reply_size += (strlen(junction.referral_list[i].alternate_path)+1)*2; + } + + pdata = *ppdata = Realloc(pdata,reply_size); + if(pdata == NULL) + { + DEBUG(0,("version3 referral setup: malloc failed for Realloc!\n")); + return -1; + } + + /* create the header */ + SSVAL(pdata,0,reqpathlen-2); /* path consumed */ + SSVAL(pdata,2,junction.referral_count); /* number of referral in this pkt */ + if(self_referral) + SIVAL(pdata,4,DFSREF_REFERRAL_SERVER | DFSREF_STORAGE_SERVER); + else + SIVAL(pdata,4,DFSREF_STORAGE_SERVER); + + /* copy in the reqpaths */ + memcpy(pdata+uni_reqpathoffset1,uni_reqpath,reqpathlen); + memcpy(pdata+uni_reqpathoffset2,uni_reqpath,reqpathlen); + + offset = 8; + for(i=0;i<junction.referral_count;i++) + { + struct referral* ref = &(junction.referral_list[i]); + int unilen; + + SSVAL(pdata,offset,3); /* version 3 */ + SSVAL(pdata,offset+2,VERSION3_REFERRAL_SIZE); + if(self_referral) + SSVAL(pdata,offset+4,1); + else + SSVAL(pdata,offset+4,0); + + SSVAL(pdata,offset+6,0); /* ref_flags :use path_consumed bytes? */ + SIVAL(pdata,offset+8,ref->ttl); + + SSVAL(pdata,offset+12,uni_reqpathoffset1-offset); + SSVAL(pdata,offset+14,uni_reqpathoffset2-offset); + /* copy referred path into current offset */ + unilen = (dos_struni2(pdata+uni_curroffset,ref->alternate_path,512) + +1)*2; + SSVAL(pdata,offset+16,uni_curroffset-offset); + /* copy 0x10 bytes of 00's in the ServiceSite GUID */ + memset(pdata+offset+18,'\0',16); + + uni_curroffset += unilen; + offset += VERSION3_REFERRAL_SIZE; + } + free(junction.referral_list); + break; + } + } + DEBUG(10,("DFS Referral pdata:\n")); + dump_data(10,pdata,reply_size); + return reply_size; +} + +int dfs_path_error(char* inbuf, char* outbuf) +{ + enum remote_arch_types ra_type = get_remote_arch(); + BOOL NT_arch = ((ra_type==RA_WINNT) || (ra_type == RA_WIN2K)); + if(NT_arch && (global_client_caps & (CAP_NT_SMBS | CAP_STATUS32)) ) + { + SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES); + return(ERROR(0,0xc0000000|NT_STATUS_PATH_NOT_COVERED)); + } + return(ERROR(ERRSRV,ERRbadpath)); +} + +#else +/* Stub functions if MS_DFS not defined */ +int setup_dfs_referral(char* pathname, int max_referral_level, + char** ppdata) +{ + return -1; +} + +#endif + +/* Trivial fn that chops off upper bytes to convert unicode to dos */ +int unistr_to_dos(char* dst,uint16* src) +{ + pstring s; + int i=0; + + for(i=0;SVAL(src,i*2) && i<1024;i++) + { + s[i]= SVAL(src,i*2) & 0xff; + } + s[i]=0; + + safe_strcpy(dst,s,1024); + DEBUG(10,("converted unistring to %s\n",s)); +} diff --git a/source3/msdfs/msdfs_tdb.c b/source3/msdfs/msdfs_tdb.c new file mode 100644 index 0000000000..1d7841bfea --- /dev/null +++ b/source3/msdfs/msdfs_tdb.c @@ -0,0 +1,264 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + MSDfs services for Samba + Copyright (C) Shirish Kalele 2000 + Copyright (C) Samba Team 2000 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +#ifdef MS_DFS + +#define MSDFS_TDB "msdfs.tdb" + +/* structures for msdfs.tdb */ +struct tdb_junction_key +{ + pstring service_name; + pstring volume_name; +}; + +struct tdb_junction_data +{ + int referral_count; + struct referral first_referral; +}; + +static TDB_CONTEXT* msdfs_map = NULL; + +/* + * Open the msdfs tdb map. Called once for update when parsing the dfsmap file + * and then subsequently at tconX for reading + */ +BOOL msdfs_open(BOOL update) +{ + pstring fname; + int oflags = (update)?O_RDWR|O_CREAT:O_RDONLY; + + /* close any open TDB contexts before opening */ + if(msdfs_map != NULL) + { + DEBUG(10,("msdfs_open: Closing existing TDB_CONTEXT msdfs_map: name: %s, fd: %d\n", + msdfs_map->name,msdfs_map->fd)); + tdb_close(msdfs_map); + } + + pstrcpy(fname,lock_path(MSDFS_TDB)); + DEBUG(10,("opening msdfs tdb : .%s.\n",fname)); + if((msdfs_map = tdb_open(fname,0,0,oflags,0644)) == NULL) + { + DEBUG(1,("Couldn't open Dfs tdb map %s %s.\nError was %s\n",fname, + (update?"for update":"for reading"),strerror(errno) )); + return False; + } + DEBUG(10,("TDB_CONTEXT msdfs_map opened: name: %s, fd: %d\n",msdfs_map->name,msdfs_map->fd)); + + return True; +} + +BOOL add_junction_entry(struct junction_map* junction) +{ + struct tdb_junction_key* tlk; + struct tdb_junction_data* tld; + + TDB_DATA key,data; + uint16 data_size; + + int i=0; + + if(msdfs_map == NULL) + { + DEBUG(4,("Attempt to add junction entry to unopened %s\n",MSDFS_TDB)); + return False; + } + + /* create the key */ + if((tlk = (struct tdb_junction_key*) malloc(sizeof(struct tdb_junction_key))) == NULL) + { + DEBUG(0,("malloc failed for tdb junction key\n")); + return False; + } + + ZERO_STRUCTP(tlk); + + pstrcpy(tlk->service_name,junction->service_name); + pstrcpy(tlk->volume_name,junction->volume_name); + strupper(tlk->service_name); + strupper(tlk->volume_name); + + key.dptr = (char*) tlk; + key.dsize = sizeof(struct tdb_junction_key); + + + /* create the data */ + data_size = sizeof(struct tdb_junction_data) + + ((junction->referral_count-1)*sizeof(struct referral)); + + if( (tld = (struct tdb_junction_data*) malloc(data_size)) == NULL) + { + DEBUG(0,("malloc failed for tdb junction data\n")); + return False; + } + + tld->referral_count = junction->referral_count; + memcpy(&tld->first_referral,junction->referral_list,junction->referral_count * sizeof(struct referral)); + + data.dptr = (char*) tld; + data.dsize = data_size; + + DEBUG(10,("Storing key: .%s:%s.\n",tlk->service_name,tlk->volume_name)); + DEBUG(10,("Data: referral_count : %u\n",tld->referral_count)); + for(i=0;i<tld->referral_count;i++) + DEBUG(10,("Path %d: %s, proximity: %u, ttl: %u\n",junction->referral_list[i].alternate_path)); + + if( tdb_store(msdfs_map,key,data,TDB_REPLACE) != 0) + { + DEBUG(10,("Could not store referral for %s:%s \n", + junction->service_name, junction->volume_name)); + free(key.dptr); + free(data.dptr); + return False; + } + + free(key.dptr); + free(data.dptr); + return True; +} + +BOOL get_junction_entry(struct junction_map* junction) +{ + struct tdb_junction_key* tlk; + struct tdb_junction_data* tld; + + uint16 reflistsize=0; + + TDB_DATA key,data; + + if(msdfs_map == NULL) + { + DEBUG(4,("Attempt to get junction entry from unopened %s\n",MSDFS_TDB)); + return False; + } + + if( (tlk=(struct tdb_junction_key*) malloc(sizeof(struct tdb_junction_key))) == NULL) + { + DEBUG(0,("couldn't malloc for tdb junction key\n")); + return False; + } + + ZERO_STRUCTP(tlk); + + pstrcpy(tlk->service_name,junction->service_name); + pstrcpy(tlk->volume_name,junction->volume_name); + strupper(tlk->service_name); + strupper(tlk->volume_name); + + key.dptr = (char*) tlk; + key.dsize = sizeof(struct tdb_junction_key); + + data = tdb_fetch(msdfs_map,key); + + if(data.dptr == NULL) + { + DEBUG(8,("No data found for key %s:%s\n",junction->service_name,junction->volume_name)); + DEBUG(8,("Error was %s\n",strerror(errno))); + free(key.dptr); + return False; + } + + tld = (struct tdb_junction_data*) data.dptr; + + junction->referral_count = tld->referral_count; + reflistsize = junction->referral_count * sizeof(struct referral); + + if((junction->referral_list = (struct referral*) malloc(reflistsize) ) == NULL) + { + DEBUG(0,("malloc failed for referral list\n")); + free(key.dptr); + free(data.dptr); + return False; + } + + memcpy(junction->referral_list,&(tld->first_referral),reflistsize); + free(key.dptr); + free(data.dptr); + + return True; +} + +BOOL isDfsShare(char* svc,char* vol) +{ + TDB_DATA key; + struct tdb_junction_key tlk; + + ZERO_STRUCT(tlk); + + if(msdfs_map == NULL) + { + DEBUG(4,("Attempt to check junction existence in unopened %s\n",MSDFS_TDB)); + return False; + } + + pstrcpy(tlk.service_name,svc); + pstrcpy(tlk.volume_name,vol); + + strupper(tlk.service_name); + strupper(tlk.volume_name); + + key.dptr = (char*) &tlk; + key.dsize = sizeof(struct tdb_junction_key); + + DEBUG(10,("tdb_exists for key %s:%s returns %d\n",tlk.service_name,tlk.volume_name, + tdb_exists(msdfs_map,key))); + + if(tdb_exists(msdfs_map,key)) + return True; + else + { + DEBUG(10,("error was %s\n",strerror(errno))); + return False; + } + +} + +void msdfs_close() +{ + if(msdfs_map != NULL) + tdb_close(msdfs_map); + + msdfs_map = NULL; +} + +void msdfs_end() +{ + pstring fname; + msdfs_close(); + + /* pstrcpy(fname,lock_path(MSDFS_TDB)); + unlink(fname); */ +} +#endif + + + + + + + diff --git a/source3/msdfs/parse_dfs_map.c b/source3/msdfs/parse_dfs_map.c new file mode 100644 index 0000000000..8caa4399d0 --- /dev/null +++ b/source3/msdfs/parse_dfs_map.c @@ -0,0 +1,261 @@ +/* + Unix SMB/Netbios implementation. + Version 3.0 + MSDfs services for Samba + Copyright (C) Shirish Kalele 2000 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +/*********************************************************************** + * Parses the per-service Dfs map file which is of the form: + * junction_point1 + * alternate_path1:proximity:ttl + * alternate_path2:proximity:ttl + * junction_point2 + * ... + * + * Junction points are directories in the service (upon encountering which + * Samba redirects the client to the servers hosting the underlying share) + * + * Alternate paths are of the form: \\smbserver\share + * Currently, the parser detects alternate paths by the leading \'s + * + ***********************************************************************/ + +#include "includes.h" + +#ifdef MS_DFS + +#define MAX_ALTERNATE_PATHS 256 + +extern int DEBUGLEVEL; + +static char* Dfs_Crop_Whitespace(char* line) +{ + int i=0; + int len = strlen(line); + + if(line[0]=='#' || line[0]==';') return NULL; + + for(i=0;i<PSTRING_LEN && line[i]==' ';i++); + + if(i>=PSTRING_LEN) return NULL; + + line = &line[i]; + + /* crop off the newline at the end, if present */ + /* if(line[len-1]=='\n') line[len-1]='\0'; */ + + /* remove white sace from the end */ + for(i=strlen(line)-1;i>=0 && isspace(line[i]);i--); + + if(i<0) return NULL; + + line[i]='\0'; + + if(line[0] == '\0') return NULL; + + return line; +} + +BOOL parse_referral(char* s, struct referral* ref) +{ +#define MAXTOK_IN_REFERRAL 3 + char *tok[MAXTOK_IN_REFERRAL+1]; + int count=0; + int i=0; + + if(s[1]=='\\') s = &s[1]; /* skip one backslash + if there are two */ + + tok[count++] = strtok(s,":"); + + while( ((tok[count]=strtok(NULL,":")) != NULL) && count<MAXTOK_IN_REFERRAL) + count++; + + DEBUG(10,("parse_referral: Tokens\n")); + for(i=0;i<count;i++) + DEBUG(10,("\t%s\n",tok[i])); + + if(count > 0) + pstrcpy(ref->alternate_path,tok[0]); + else + { + DEBUG(6,("Invalid referral line: %s\n",s)); + return False; + } + + if(count > 1) + ref->proximity = atoi(tok[1]); + else + ref->proximity = 0; + + if(count > 2) + ref->ttl = atoi(tok[1]); + else + ref->ttl = REFERRAL_TTL; + + return True; +} + +void load_dfsmaps() +{ + int i=0; + if(!lp_host_msdfs()) + return; + + for(i=0;*lp_servicename(i) && *lp_dfsmap(i) + && !lp_dfsmap_loaded(i);i++) + { + char* dfsmapfile = lp_dfsmap(i); + DEBUG(4,("loading dfsmap for servicename: %s\n",lp_servicename(i))); + if(load_dfsmap(dfsmapfile,i)) + { + set_dfsmap_loaded(i,True); + } + else + { + DEBUG(0,("handle_dfsmap: Unable to load Dfs map file %s.\nService %s not using MS Dfs",dfsmapfile,lp_servicename(i))); + set_dfsmap_loaded(i,False); + } + + } +} + +BOOL load_dfsmap(char* fname, int snum) +{ + struct junction_map* junction = NULL; + struct referral tmp_ref_array[MAX_ALTERNATE_PATHS]; + int ref_count = 0; + FILE* fp; + + if(lp_dfsmap_loaded(snum)) + return True; + + if((fp = sys_fopen(fname,"r")) == NULL) + { + DEBUG(1,("can't open dfs map file %s for service [%s]\nError was %s",fname, + lp_servicename(snum), strerror(errno))); + return False; + } + + if(!msdfs_open(True)) + return False; + + while(!feof(fp)) + { + pstring rawline; + char* line; + int i; + + struct referral* curr_referral_list = NULL; + + if(!fgets(rawline,PSTRING_LEN,fp)) + continue; + + if((line = Dfs_Crop_Whitespace(rawline)) == NULL) + continue; + + DEBUG(6,("load_dfsmap: Cropped line: %s\n",line)); + + /* the line contains a new junction or + an alternate path to current junction */ + + if(line[0]!='\\') + { + /* a junction encountered. add the current junction first */ + if(junction) + { + junction->referral_count = ref_count; + junction->referral_list = tmp_ref_array; + DEBUG(4,("Adding Dfs junction: %s\\%s Referrals: %u First referral path: %s\n", + junction->service_name,junction->volume_name, + junction->referral_count, junction->referral_list[0].alternate_path)); + + if(!add_junction_entry(junction)) + { + DEBUG(6,("Unable to add junction entry %s:%s after parsing\n", + junction->service_name,junction->volume_name)); + } + free(junction); + } + + /* then, create a new junction_map node */ + if((junction = (struct junction_map*) malloc(sizeof(struct junction_map))) == NULL) + { + DEBUG(0,("Couldn't malloc for Dfs junction_map node\n")); + return; + } + pstrcpy(junction->service_name,lp_servicename(snum)); + pstrcpy(junction->volume_name,line); + ref_count = 0; + } + else + { + /* referral encountered. add to current junction */ + int j=0; + char* tok; + + if(!junction) + { + DEBUG(4,("Invalid entry in Dfs map file.\nAlternate path defined outside of a junction in line:\n%s\n",line)); + return; + } + + /* parse the referral */ + if(!parse_referral(line,&tmp_ref_array[ref_count])) + continue; + ref_count++; + + } + } + + /* End of file. Add the current junction and return */ + if(junction) + { + junction->referral_count = ref_count; + junction->referral_list = tmp_ref_array; + DEBUG(4,("Adding Dfs junction: %s\%s Referrals: %u First referral path: %s\n", + junction->service_name,junction->volume_name, + junction->referral_count, junction->referral_list[0].alternate_path)); + if(!add_junction_entry(junction)) + { + DEBUG(6,("Unable to add junction entry %s:%s after parsing\n", + junction->service_name,junction->volume_name)); + } + free(junction); + } + + fclose(fp); + msdfs_close(); + return True; +} + +#else +/* Stub function if MS_DFS is not defined */ + +void load_dfsmaps() +{} + +#endif + + + + + + + + |